ad4m_delete_memory
Remove links from a Perspective by filtering source, predicate, or target URIs. Returns matched, removed, and failed counts.
Instructions
Remove links from a Perspective by source, predicate, and/or target filter. Returns matched/removed/failed counts.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| perspective_uuid | Yes | Perspective UUID to delete from | |
| source | No | Filter by source URI | |
| predicate | No | Filter by predicate URI | |
| target | No | Filter by target URI |
Implementation Reference
- src/index.ts:438-457 (handler)The deleteMemory handler function: queries links matching the filter, then removes each via removeLink(), returning matched/removed/failed counts.
async ({ perspective_uuid, source, predicate, target }) => { const query: Record<string, string> = {}; if (source) query.source = source; if (predicate) query.predicate = predicate; if (target) query.target = target; const data = await gql( `query Q($uuid: String!, $q: LinkQuery!) { perspectiveQueryLinks(uuid: $uuid, query: $q) { ${LINKS_WITH_PROOF} } }`, { uuid: perspective_uuid, q: query } ); const links = data.perspectiveQueryLinks as LinkExpr[]; let removed = 0, failed = 0; for (const link of links) { try { if (await removeLink(perspective_uuid, link)) removed++; else failed++; } catch { failed++; } } return ok({ matched: links.length, removed, failed }); } ); - src/index.ts:429-457 (registration)Tool registration via server.tool('ad4m_delete_memory', ...) with Zod schema for perspective_uuid (required), source/predicate/target (optional).
// 11. ad4m_delete_memory server.tool("ad4m_delete_memory", "Remove links from a Perspective by source, predicate, and/or target filter. Returns matched/removed/failed counts.", { perspective_uuid: z.string().describe("Perspective UUID to delete from"), source: z.string().optional().describe("Filter by source URI"), predicate: z.string().optional().describe("Filter by predicate URI"), target: z.string().optional().describe("Filter by target URI"), }, async ({ perspective_uuid, source, predicate, target }) => { const query: Record<string, string> = {}; if (source) query.source = source; if (predicate) query.predicate = predicate; if (target) query.target = target; const data = await gql( `query Q($uuid: String!, $q: LinkQuery!) { perspectiveQueryLinks(uuid: $uuid, query: $q) { ${LINKS_WITH_PROOF} } }`, { uuid: perspective_uuid, q: query } ); const links = data.perspectiveQueryLinks as LinkExpr[]; let removed = 0, failed = 0; for (const link of links) { try { if (await removeLink(perspective_uuid, link)) removed++; else failed++; } catch { failed++; } } return ok({ matched: links.length, removed, failed }); } ); - src/index.ts:432-437 (schema)Input schema using Zod: perspective_uuid (string, required), source, predicate, target (all optional strings).
{ perspective_uuid: z.string().describe("Perspective UUID to delete from"), source: z.string().optional().describe("Filter by source URI"), predicate: z.string().optional().describe("Filter by predicate URI"), target: z.string().optional().describe("Filter by target URI"), }, - src/index.ts:183-191 (helper)removeLink helper: sends a GraphQL perspectiveRemoveLink mutation to delete a specific link by author/timestamp/proof/data.
async function removeLink(uuid: string, link: LinkExpr): Promise<boolean> { const result = await gql( `mutation R($uuid: String!, $link: LinkExpressionInput!) { perspectiveRemoveLink(uuid: $uuid, link: $link) }`, { uuid, link: { author: link.author, timestamp: link.timestamp, proof: link.proof, data: link.data } } ); return !!(result.perspectiveRemoveLink); } - src/index.ts:164-168 (helper)LINKS_WITH_PROOF GraphQL fragment used to retrieve link expressions with proof fields.
const LINKS_WITH_PROOF = ` author timestamp proof { key signature valid invalid } data { source predicate target } `;