From cf1503669519382519602b91b73cf5bcaddbdc64 Mon Sep 17 00:00:00 2001 From: Rohit Ghumare Date: Mon, 27 Apr 2026 00:48:13 +0100 Subject: [PATCH] feat(api): add GET /agentmemory/memories/:id endpoint The route was simply not registered. POST /remember writes to \`KV.memories\` keyed by the generated id; GET /memories lists from the same scope. There was no by-id retrieval handler at all, so any \`save then fetch-by-ID\` round-trip (including the MCP tool chain's memory verification step) returned 404 even though the data was in storage. Adds \`api::memory-by-id\` with path-param \`:id\`. Returns 200 \`{ memory }\` on hit, 404 \`{ error }\` on miss, 400 if id is empty. Auth gate matches the rest of the protected endpoints. Thanks @Axialon for the precise repro and root-cause guess (which was correct: it was a missing handler, not a scope mismatch). Closes #196 --- src/triggers/api.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/triggers/api.ts b/src/triggers/api.ts index 3c993f5..d4bd5f9 100644 --- a/src/triggers/api.ts +++ b/src/triggers/api.ts @@ -1323,7 +1323,7 @@ export function registerApiTriggers( config: { api_path: "/agentmemory/snapshot/restore", http_method: "POST" }, }); - sdk.registerFunction("api::memories", + sdk.registerFunction("api::memories", async (req: ApiRequest): Promise => { const authErr = checkAuth(req, secret); if (authErr) return authErr; @@ -1339,6 +1339,27 @@ export function registerApiTriggers( config: { api_path: "/agentmemory/memories", http_method: "GET" }, }); + sdk.registerFunction("api::memory-by-id", + async (req: ApiRequest): Promise => { + const authErr = checkAuth(req, secret); + if (authErr) return authErr; + const id = req.path_params?.["id"]; + if (!id || typeof id !== "string") { + return { status_code: 400, body: { error: "id path parameter is required" } }; + } + const memory = await kv.get(KV.memories, id); + if (!memory) { + return { status_code: 404, body: { error: `memory not found: ${id}` } }; + } + return { status_code: 200, body: { memory } }; + }, + ); + sdk.registerTrigger({ + type: "http", + function_id: "api::memory-by-id", + config: { api_path: "/agentmemory/memories/:id", http_method: "GET" }, + }); + sdk.registerFunction("api::semantic-list", async (req: ApiRequest): Promise => { const authErr = checkAuth(req, secret);