@aksolab/recall
Version:
A memory management package for AI SDK memory functionality
100 lines (99 loc) • 4.06 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createTools = createTools;
const zod_1 = require("zod");
const ai_1 = require("ai");
async function createTools(memoryManager) {
return {
coreMemoryAppend: (0, ai_1.tool)({
description: 'Append content to a specific core memory block',
parameters: zod_1.z.object({
block: zod_1.z.string().describe('The core block to append to'),
content: zod_1.z.string().describe('The content to append'),
}),
execute: async ({ block, content }) => {
try {
const coreBlock = await memoryManager.getCoreMemory();
if (!coreBlock) {
return `No core memory found`;
}
const blockConfig = coreBlock[block];
const newContent = `${blockConfig?.content || ''}\n${content}`;
await memoryManager.updateCoreMemory(block, newContent);
return `Updated ${block} block with: ${content}`;
}
catch (error) {
if (error instanceof Error) {
return `Failed to update ${block} block: ${error.message}`;
}
return `Failed to update ${block} block: Unknown error`;
}
},
}),
coreMemoryReplace: (0, ai_1.tool)({
description: 'Update the content of a specific core memory block',
parameters: zod_1.z.object({
block: zod_1.z.string().describe('The core block to update'),
content: zod_1.z.string().describe('The new content for the block'),
}),
execute: async ({ block, content }) => {
try {
await memoryManager.updateCoreMemory(block, content);
return {
status: 'success',
message: `Updated ${block} block with: ${content}`
};
}
catch (error) {
return {
status: 'error',
message: `Failed to update ${block} block: ${error instanceof Error ? error.message : 'Unknown error'}`
};
}
},
}),
archivalMemorySearch: (0, ai_1.tool)({
description: 'Search archive memory for relevant information',
parameters: zod_1.z.object({
query: zod_1.z.string().describe('The query to search archive memory'),
}),
execute: async ({ query }) => {
try {
const memories = await memoryManager.searchArchiveMemory(query);
return {
status: 'success',
data: memories
};
}
catch (error) {
return {
status: 'error',
error: error
};
}
}
}),
archivalMemoryInsert: (0, ai_1.tool)({
description: 'Add new information to archive memory',
parameters: zod_1.z.object({
name: zod_1.z.string().describe('The name of the memory'),
content: zod_1.z.string().describe('The information to archive'),
}),
execute: async ({ name, content }) => {
try {
const result = await memoryManager.addToArchiveMemory({ name, content });
return {
status: 'success',
data: result
};
}
catch (error) {
return {
status: 'error',
error: error
};
}
},
}),
};
}