forked from AtomicBot-ai/atomic-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes-forget.ts
More file actions
51 lines (49 loc) · 1.56 KB
/
Copy pathnotes-forget.ts
File metadata and controls
51 lines (49 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { compressToolResult } from "../../compressor/result-compressor.js";
import {
MemoryStore,
MemoryValidationError,
} from "../../memory/memory-store.js";
import type { ToolDefinition } from "../tool-registry.js";
export interface NotesForgetToolOptions {
store: MemoryStore;
}
/**
* `memory.notes.forget { id }` — delete a stored note by id (as
* returned from `memory.notes.recall`). Returns `removed: false` (not an
* error) when the id was already absent so the LLM can distinguish
* missing-row from validation failure.
*/
export function buildNotesForgetTool(
options: NotesForgetToolOptions,
): ToolDefinition {
return {
name: "memory.notes.forget",
description:
"Delete a stored note by id returned from memory.notes.recall or memory.notes.list.",
readonly: false,
async run(rawArgs) {
const id = rawArgs.id;
try {
const removed = options.store.remove(
typeof id === "number" ? id : Number.NaN,
);
return compressToolResult({
tool: "memory.notes.forget",
status: "ok",
output: removed ? `removed #${id}` : `no such id: ${id}`,
details: { id, removed },
});
} catch (error) {
if (error instanceof MemoryValidationError) {
return compressToolResult({
tool: "memory.notes.forget",
status: "error",
output: `validation: ${error.field}: ${error.message}`,
details: { field: error.field, reason: error.message },
});
}
throw error;
}
},
};
}