@inchankang/zettel-memory
Version:
Local-first persistent memory MCP server with PARA + Zettelkasten + SQLite FTS5
52 lines • 2.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEFAULT_EXECUTION_POLICY = void 0;
exports.withExecutionPolicy = withExecutionPolicy;
const zettel_memory_common_1 = require("@inchankang/zettel-memory-common");
exports.DEFAULT_EXECUTION_POLICY = {
maxRetries: 2,
timeoutMs: 5_000,
};
async function withTimeout(operation, timeoutMs) {
if (timeoutMs <= 0) {
return operation();
}
let timeoutHandle;
try {
const timeoutPromise = new Promise((_, reject) => {
timeoutHandle = setTimeout(() => {
reject(new zettel_memory_common_1.MemoryMcpError(zettel_memory_common_1.ErrorCode.TIMEOUT_ERROR, `툴 실행이 ${timeoutMs}ms 제한을 초과했습니다.`));
}, timeoutMs);
});
return await Promise.race([operation(), timeoutPromise]);
}
finally {
if (timeoutHandle) {
clearTimeout(timeoutHandle);
}
}
}
async function withExecutionPolicy(operation, options) {
const { maxRetries, timeoutMs, onRetry } = options;
const totalAttempts = Math.max(0, maxRetries) + 1;
let lastError;
for (let attempt = 1; attempt <= totalAttempts; attempt += 1) {
try {
return await withTimeout(operation, timeoutMs);
}
catch (error) {
lastError = error;
if (attempt >= totalAttempts) {
if (error instanceof zettel_memory_common_1.MemoryMcpError) {
throw error;
}
throw new zettel_memory_common_1.MemoryMcpError(zettel_memory_common_1.ErrorCode.MCP_TOOL_ERROR, '툴 실행 중 예기치 못한 오류가 발생했습니다.', {
cause: error instanceof Error ? error.message : String(error),
});
}
onRetry?.({ attempt, error });
}
}
throw new zettel_memory_common_1.MemoryMcpError(zettel_memory_common_1.ErrorCode.INTERNAL_ERROR, '툴 실행 정책을 적용하는 동안 알 수 없는 오류가 발생했습니다.', { lastError });
}
//# sourceMappingURL=execution-policy.js.map