@forwardimpact/libmemory
Advanced tools
+31
-7
| #!/usr/bin/env node | ||
| import { readFileSync } from "node:fs"; | ||
| import { createCli } from "@forwardimpact/libcli"; | ||
| import { createServiceConfig } from "@forwardimpact/libconfig"; | ||
@@ -6,18 +8,39 @@ import { createClient, createTracer } from "@forwardimpact/librpc"; | ||
| const { version: VERSION } = JSON.parse( | ||
| readFileSync(new URL("../package.json", import.meta.url), "utf8"), | ||
| ); | ||
| const definition = { | ||
| name: "fit-window", | ||
| version: VERSION, | ||
| description: "Fetch the memory window for a conversation as JSON", | ||
| usage: "fit-window <resource_id> [model]", | ||
| options: { | ||
| help: { type: "boolean", short: "h", description: "Show this help" }, | ||
| version: { type: "boolean", description: "Show version" }, | ||
| json: { type: "boolean", description: "Output help as JSON" }, | ||
| }, | ||
| examples: ["fit-window common.Conversation.abc123"], | ||
| }; | ||
| const cli = createCli(definition); | ||
| const logger = createLogger("cli"); | ||
| /** | ||
| * Fetches the memory window for a conversation as JSON | ||
| * Usage: fit-window <resource_id> [model] | ||
| * @returns {Promise<void>} | ||
| */ | ||
| async function main() { | ||
| const resourceId = process.argv[2]; | ||
| const parsed = cli.parse(process.argv.slice(2)); | ||
| if (!parsed) process.exit(0); | ||
| const resourceId = parsed.positionals[0]; | ||
| if (!resourceId) { | ||
| console.error("Usage: fit-window <resource_id> [model]"); | ||
| process.exit(1); | ||
| cli.usageError("expected argument: <resource_id>"); | ||
| process.exit(2); | ||
| } | ||
| const agentConfig = await createServiceConfig("agent"); | ||
| const model = process.argv[3] || agentConfig.model; | ||
| const model = parsed.positionals[1] || agentConfig.model; | ||
| const config = await createServiceConfig("memory"); | ||
| const logger = createLogger("cli"); | ||
| const tracer = await createTracer("cli"); | ||
@@ -36,4 +59,5 @@ const client = await createClient("memory", logger, tracer); | ||
| main().catch((error) => { | ||
| console.error(error.message); | ||
| logger.exception("main", error); | ||
| cli.error(error.message); | ||
| process.exit(1); | ||
| }); |
+2
-1
| { | ||
| "name": "@forwardimpact/libmemory", | ||
| "version": "0.1.41", | ||
| "version": "0.1.43", | ||
| "description": "Memory management library for Guide", | ||
@@ -24,2 +24,3 @@ "license": "Apache-2.0", | ||
| "dependencies": { | ||
| "@forwardimpact/libcli": "^0.1.0", | ||
| "@forwardimpact/libindex": "^0.1.27" | ||
@@ -26,0 +27,0 @@ }, |
49290
1.68%1050
1.94%2
100%+ Added