Skip to content

Commit c4efcd9

Browse files
committed
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 rohitg00#196
1 parent 8f44c3d commit c4efcd9

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

‎src/triggers/api.ts‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,7 @@ export function registerApiTriggers(
13231323
config: { api_path: "/agentmemory/snapshot/restore", http_method: "POST" },
13241324
});
13251325

1326-
sdk.registerFunction("api::memories",
1326+
sdk.registerFunction("api::memories",
13271327
async (req: ApiRequest): Promise<Response> => {
13281328
const authErr = checkAuth(req, secret);
13291329
if (authErr) return authErr;
@@ -1339,6 +1339,27 @@ export function registerApiTriggers(
13391339
config: { api_path: "/agentmemory/memories", http_method: "GET" },
13401340
});
13411341

1342+
sdk.registerFunction("api::memory-by-id",
1343+
async (req: ApiRequest): Promise<Response> => {
1344+
const authErr = checkAuth(req, secret);
1345+
if (authErr) return authErr;
1346+
const id = req.path_params?.["id"];
1347+
if (!id || typeof id !== "string") {
1348+
return { status_code: 400, body: { error: "id path parameter is required" } };
1349+
}
1350+
const memory = await kv.get<import("../types.js").Memory>(KV.memories, id);
1351+
if (!memory) {
1352+
return { status_code: 404, body: { error: `memory not found: ${id}` } };
1353+
}
1354+
return { status_code: 200, body: { memory } };
1355+
},
1356+
);
1357+
sdk.registerTrigger({
1358+
type: "http",
1359+
function_id: "api::memory-by-id",
1360+
config: { api_path: "/agentmemory/memories/:id", http_method: "GET" },
1361+
});
1362+
13421363
sdk.registerFunction("api::semantic-list",
13431364
async (req: ApiRequest): Promise<Response> => {
13441365
const authErr = checkAuth(req, secret);

0 commit comments

Comments
 (0)