Files
flynn/src/tools/builtin/memory-read.ts
T
William Valentin 9f81c01603 feat(session): persist model tier overrides per session
Store per-session config in SQLite and route /model and /reset through command fast-paths so channel sessions keep independent model selection across reconnects and restarts.
2026-02-13 01:04:26 -08:00

55 lines
1.8 KiB
TypeScript

import type { Tool, ToolResult } from '../types.js';
import type { MemoryStore } from '../../memory/store.js';
interface MemoryReadArgs {
namespace: string;
}
/**
* Creates a memory.read tool bound to the given MemoryStore instance.
* Reads the full contents of a persistent memory namespace.
*/
export function createMemoryReadTool(store: MemoryStore): Tool {
return {
name: 'memory.read',
description:
'Read a persistent memory file by namespace. Available namespaces include "user" (user preferences and facts), "global" (cross-session knowledge), and session-specific namespaces. Supports structured categories by appending /facts, /preferences, /decisions, or /projects (for example: "user/facts"). Returns the full contents of the memory file.',
inputSchema: {
type: 'object',
properties: {
namespace: {
type: 'string',
description: 'Memory namespace to read (e.g. "user", "global", "sessions/abc123")',
},
},
required: ['namespace'],
},
execute: async (rawArgs: unknown): Promise<ToolResult> => {
const args = rawArgs as MemoryReadArgs;
try {
const content = store.read(args.namespace);
if (!content) {
const namespaces = store.listNamespaces();
const available = namespaces.length > 0
? `Available namespaces: ${namespaces.join(', ')}`
: 'No namespaces exist yet.';
return {
success: true,
output: `Namespace "${args.namespace}" is empty or does not exist.\n${available}`,
};
}
return { success: true, output: content };
} catch (error) {
return {
success: false,
output: '',
error: error instanceof Error ? error.message : String(error),
};
}
},
};
}