34 lines
1.5 KiB
JavaScript
34 lines
1.5 KiB
JavaScript
"use strict";
|
|
// =============================================================================
|
|
// Pure memory API. The in-process agent-runner collects memory updates into an
|
|
// array on the ToolContext (ctx.memoryUpdates) so the supervisor loop can
|
|
// persist them at end-of-turn. MCP clients don't share that array, so the MCP
|
|
// server keeps its own module-level store keyed by an optional sessionKey.
|
|
// =============================================================================
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.toEntry = toEntry;
|
|
exports.saveMemoryToStore = saveMemoryToStore;
|
|
exports.listMemoryFromStore = listMemoryFromStore;
|
|
exports.clearMemoryStore = clearMemoryStore;
|
|
function toEntry(input) {
|
|
return { key: input.key, type: input.type, value: input.value };
|
|
}
|
|
// -------------------------------------------------------------------
|
|
// In-memory store used by the MCP server path (the in-process path
|
|
// appends directly to ctx.memoryUpdates and ignores this store).
|
|
// -------------------------------------------------------------------
|
|
const memoryStore = new Map();
|
|
function saveMemoryToStore(sessionKey, input) {
|
|
const entry = toEntry(input);
|
|
const list = memoryStore.get(sessionKey) ?? [];
|
|
list.push(entry);
|
|
memoryStore.set(sessionKey, list);
|
|
return { saved: true, entry };
|
|
}
|
|
function listMemoryFromStore(sessionKey) {
|
|
return [...(memoryStore.get(sessionKey) ?? [])];
|
|
}
|
|
function clearMemoryStore(sessionKey) {
|
|
memoryStore.delete(sessionKey);
|
|
}
|