diff --git a/packages/tools/test-supermemory.ts b/packages/tools/test-supermemory.ts index b3863c7e..628968fe 100644 --- a/packages/tools/test-supermemory.ts +++ b/packages/tools/test-supermemory.ts @@ -10,7 +10,9 @@ const openai = new OpenAI({ }) // Wrap OpenAI client with supermemory -const openaiWithSupermemory = withSupermemory(openai, "test_user_123", { +const openaiWithSupermemory = withSupermemory(openai, { + containerTag: "test_user_123", + customId: "test_user_123_chat", verbose: true, // Enable logging to see what's happening mode: "full", // Search both profile and query memories addMemory: "always", // Auto-save conversations as memories diff --git a/packages/tools/test/anthropic-example.ts b/packages/tools/test/anthropic-example.ts index 2338cfda..fe7bec6f 100644 --- a/packages/tools/test/anthropic-example.ts +++ b/packages/tools/test/anthropic-example.ts @@ -5,7 +5,10 @@ */ import Anthropic from "@anthropic-ai/sdk" -import { createClaudeMemoryTool } from "./claude-memory" +import { + createClaudeMemoryTool, + type MemoryCommand, +} from "../src/claude-memory" import "dotenv/config" /** @@ -36,7 +39,7 @@ async function chatWithMemoryTool() { }) // Conversation messages - const messages: Anthropic.Messages.MessageParam[] = [ + const messages: Anthropic.Beta.Messages.BetaMessageParam[] = [ { role: "user", content: @@ -44,7 +47,7 @@ async function chatWithMemoryTool() { }, ] - console.log("šŸ’¬ User:", messages[0].content) + console.log("šŸ’¬ User:", messages[0]?.content) console.log("\nšŸ”„ Sending to Claude with memory tool...") try { @@ -65,20 +68,21 @@ async function chatWithMemoryTool() { console.log("šŸ“„ Claude responded:") // Process the response - const toolResults: Anthropic.Messages.ToolResultBlockParam[] = [] + const toolResults: Anthropic.Beta.Messages.BetaToolResultBlockParam[] = [] for (const block of response.content) { if (block.type === "text") { console.log("šŸ’­", block.text) } else if (block.type === "tool_use" && block.name === "memory") { + const command = block.input as MemoryCommand console.log("šŸ”§ Claude is using memory tool:") - console.log(" Command:", block.input.command) - console.log(" Path:", block.input.path) + console.log(" Command:", command.command) + console.log(" Path:", command.path) // Handle the memory tool call - const memoryResult = await memoryTool.handleCommand(block.input as any) + const memoryResult = await memoryTool.handleCommand(command) - const toolResult: Anthropic.Messages.ToolResultBlockParam = { + const toolResult: Anthropic.Beta.Messages.BetaToolResultBlockParam = { type: "tool_result", tool_use_id: block.id, content: memoryResult.success @@ -137,14 +141,13 @@ async function chatWithMemoryTool() { if (block.type === "text") { console.log("šŸ’­", block.text) } else if (block.type === "tool_use" && block.name === "memory") { + const command = block.input as MemoryCommand console.log("šŸ”§ Claude is using memory tool again:") - console.log(" Command:", block.input.command) - console.log(" Path:", block.input.path) + console.log(" Command:", command.command) + console.log(" Path:", command.path) // Handle additional memory tool calls - const memoryResult = await memoryTool.handleCommand( - block.input as any, - ) + const memoryResult = await memoryTool.handleCommand(command) console.log( "šŸ“Š Memory operation result:", memoryResult.success ? "āœ… Success" : "āŒ Failed", @@ -237,7 +240,7 @@ async function testMemoryOperations() { command: { command: "view" as const, path: "/memories/project-notes.txt", - view_range: [4, 8], + view_range: [4, 8] as [number, number], }, }, ] diff --git a/packages/tools/test/claude-memory-examples.ts b/packages/tools/test/claude-memory-examples.ts index 524899b6..b59bf3d2 100644 --- a/packages/tools/test/claude-memory-examples.ts +++ b/packages/tools/test/claude-memory-examples.ts @@ -6,7 +6,10 @@ * 2. Anthropic SDK integration */ -import { createClaudeMemoryTool, type MemoryCommand } from "./claude-memory" +import { + createClaudeMemoryTool, + type MemoryCommand, +} from "../src/claude-memory" // ===================================================== // Example 1: Direct TypeScript/fetch Integration @@ -66,8 +69,7 @@ export async function directFetchExample() { ] // Execute each command - for (let i = 0; i < commands.length; i++) { - const command = commands[i] + for (const [i, command] of commands.entries()) { console.log( `\nšŸ“ Step ${i + 1}: ${command.command.toUpperCase()} ${command.path}`, ) diff --git a/packages/tools/test/claude-memory-real-example.ts b/packages/tools/test/claude-memory-real-example.ts index ef8289e9..da105e15 100644 --- a/packages/tools/test/claude-memory-real-example.ts +++ b/packages/tools/test/claude-memory-real-example.ts @@ -4,7 +4,10 @@ * This shows actual tool call handling based on real Claude API responses */ -import { createClaudeMemoryTool, type MemoryCommand } from "./claude-memory" +import { + createClaudeMemoryTool, + type MemoryCommand, +} from "../src/claude-memory" // ===================================================== // Real Claude API Integration diff --git a/packages/tools/test/claude-memory.test.ts b/packages/tools/test/claude-memory.test.ts index 38d297dc..ef444bde 100644 --- a/packages/tools/test/claude-memory.test.ts +++ b/packages/tools/test/claude-memory.test.ts @@ -1,5 +1,8 @@ import { describe, it, expect, beforeEach } from "vitest" -import { createClaudeMemoryTool, type MemoryCommand } from "./claude-memory" +import { + createClaudeMemoryTool, + type MemoryCommand, +} from "../src/claude-memory" import "dotenv/config" // Test configuration @@ -9,6 +12,10 @@ const TEST_CONFIG = { namespace: "test-claude-memory", } +// Same gate the other integration suites use: these hit the live API, so they +// only run when a key is present. Without one every request comes back 401. +const shouldRunIntegration = !!process.env.SUPERMEMORY_API_KEY + describe("Claude Memory Tool", () => { let memoryTool: ReturnType @@ -60,7 +67,7 @@ describe("Claude Memory Tool", () => { }) }) - describe("File operations", () => { + describe.skipIf(!shouldRunIntegration)("File operations", () => { const testFilePath = "/memories/test-file.txt" const testContent = "Hello, World!\nThis is a test file.\nLine 3 here." @@ -217,7 +224,7 @@ describe("Claude Memory Tool", () => { }) }) - describe("Directory operations", () => { + describe.skipIf(!shouldRunIntegration)("Directory operations", () => { it("should list empty directory", async () => { const result = await memoryTool.handleCommand({ command: "view", @@ -261,7 +268,7 @@ describe("Claude Memory Tool", () => { }) }) - describe("Error handling", () => { + describe.skipIf(!shouldRunIntegration)("Error handling", () => { it("should handle missing file", async () => { const result = await memoryTool.handleCommand({ command: "view", diff --git a/packages/tools/test/mastra/integration.test.ts b/packages/tools/test/mastra/integration.test.ts index 0cd2d14f..4bd7878f 100644 --- a/packages/tools/test/mastra/integration.test.ts +++ b/packages/tools/test/mastra/integration.test.ts @@ -121,6 +121,7 @@ describe.skipIf(!shouldRunIntegration)( messageList, abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processInput(args) @@ -153,6 +154,7 @@ describe.skipIf(!shouldRunIntegration)( messageList, abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processInput(args) @@ -191,6 +193,7 @@ describe.skipIf(!shouldRunIntegration)( messageList, abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processInput(args) @@ -232,6 +235,7 @@ describe.skipIf(!shouldRunIntegration)( messageList: createIntegrationMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processInput(args1) @@ -245,6 +249,7 @@ describe.skipIf(!shouldRunIntegration)( messageList: createIntegrationMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processInput(args2) @@ -279,6 +284,7 @@ describe.skipIf(!shouldRunIntegration)( messageList, abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processInput(args) @@ -310,6 +316,7 @@ describe.skipIf(!shouldRunIntegration)( messageList: createIntegrationMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processOutputResult(args) @@ -342,6 +349,7 @@ describe.skipIf(!shouldRunIntegration)( messageList: createIntegrationMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processOutputResult(args) @@ -378,6 +386,7 @@ describe.skipIf(!shouldRunIntegration)( messageList: createIntegrationMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, requestContext, } @@ -411,6 +420,7 @@ describe.skipIf(!shouldRunIntegration)( messageList, abort: vi.fn() as never, retryCount: 0, + state: {}, } await input.processInput(inputArgs) @@ -424,6 +434,7 @@ describe.skipIf(!shouldRunIntegration)( messageList: createIntegrationMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await output.processOutputResult(outputArgs) @@ -464,6 +475,7 @@ describe.skipIf(!shouldRunIntegration)( messageList, abort: vi.fn() as never, retryCount: 0, + state: {}, } await inputProcessor.processInput(args) @@ -528,6 +540,7 @@ describe.skipIf(!shouldRunIntegration)( messageList, abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processInput(args) @@ -552,6 +565,7 @@ describe.skipIf(!shouldRunIntegration)( messageList: createIntegrationMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processInput(args) @@ -585,6 +599,7 @@ describe.skipIf(!shouldRunIntegration)( messageList, abort: vi.fn() as never, retryCount: 0, + state: {}, } const result = await processor.processInput(args) @@ -609,6 +624,7 @@ describe.skipIf(!shouldRunIntegration)( messageList: createIntegrationMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await expect(processor.processOutputResult(args)).resolves.toBeDefined() diff --git a/packages/tools/test/mastra/unit.test.ts b/packages/tools/test/mastra/unit.test.ts index 61eb69dd..b588311a 100644 --- a/packages/tools/test/mastra/unit.test.ts +++ b/packages/tools/test/mastra/unit.test.ts @@ -180,6 +180,7 @@ describe("SupermemoryInputProcessor", () => { messageList, abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processInput(args) @@ -214,6 +215,7 @@ describe("SupermemoryInputProcessor", () => { messageList: createMockMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processInput(args1) @@ -225,6 +227,7 @@ describe("SupermemoryInputProcessor", () => { messageList: createMockMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processInput(args2) @@ -255,6 +258,7 @@ describe("SupermemoryInputProcessor", () => { messageList: createMockMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processInput(args1) @@ -266,6 +270,7 @@ describe("SupermemoryInputProcessor", () => { messageList: createMockMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processInput(args2) @@ -287,6 +292,7 @@ describe("SupermemoryInputProcessor", () => { messageList, abort: vi.fn() as never, retryCount: 0, + state: {}, } const result = await processor.processInput(args) @@ -313,6 +319,7 @@ describe("SupermemoryInputProcessor", () => { messageList, abort: vi.fn() as never, retryCount: 0, + state: {}, } const result = await processor.processInput(args) @@ -339,6 +346,7 @@ describe("SupermemoryInputProcessor", () => { messageList: createMockMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processInput(args) @@ -367,6 +375,7 @@ describe("SupermemoryInputProcessor", () => { messageList: createMockMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, requestContext, } @@ -409,6 +418,7 @@ describe("SupermemoryInputProcessor", () => { messageList, abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processInput(args) @@ -475,6 +485,7 @@ describe("SupermemoryOutputProcessor", () => { messageList: createMockMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processOutputResult(args) @@ -509,6 +520,7 @@ describe("SupermemoryOutputProcessor", () => { messageList: createMockMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processOutputResult(args) @@ -536,6 +548,7 @@ describe("SupermemoryOutputProcessor", () => { messageList: createMockMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processOutputResult(args) @@ -568,6 +581,7 @@ describe("SupermemoryOutputProcessor", () => { messageList: createMockMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, requestContext, } @@ -599,6 +613,7 @@ describe("SupermemoryOutputProcessor", () => { messageList: createMockMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processOutputResult(args) @@ -632,6 +647,7 @@ describe("SupermemoryOutputProcessor", () => { messageList: createMockMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processOutputResult(args) @@ -682,6 +698,7 @@ describe("SupermemoryOutputProcessor", () => { messageList: createMockMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processOutputResult(args) @@ -708,6 +725,7 @@ describe("SupermemoryOutputProcessor", () => { messageList: createMockMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } // Should not throw @@ -727,6 +745,7 @@ describe("SupermemoryOutputProcessor", () => { messageList: createMockMessageList(), abort: vi.fn() as never, retryCount: 0, + state: {}, } await processor.processOutputResult(args) diff --git a/packages/tools/test/test-memory-tool.ts b/packages/tools/test/test-memory-tool.ts index b7799203..1e283ff9 100644 --- a/packages/tools/test/test-memory-tool.ts +++ b/packages/tools/test/test-memory-tool.ts @@ -4,7 +4,10 @@ * Run with: bun run src/test-memory-tool.ts */ -import { createClaudeMemoryTool, type MemoryCommand } from "./claude-memory" +import { + createClaudeMemoryTool, + type MemoryCommand, +} from "../src/claude-memory" import "dotenv/config" async function testMemoryTool() { @@ -139,8 +142,7 @@ async function testMemoryTool() { let passed = 0 let failed = 0 - for (let i = 0; i < testCases.length; i++) { - const testCase = testCases[i] + for (const [i, testCase] of testCases.entries()) { console.log(`\\nšŸ”„ Test ${i + 1}/${testCases.length}: ${testCase.name}`) try { diff --git a/packages/tools/test/with-supermemory/unit.test.ts b/packages/tools/test/with-supermemory/unit.test.ts index 7c05dd6a..8b1662a4 100644 --- a/packages/tools/test/with-supermemory/unit.test.ts +++ b/packages/tools/test/with-supermemory/unit.test.ts @@ -532,8 +532,8 @@ describe("Unit: withSupermemory", () => { usage: { inputTokens: 1, outputTokens: 1, + totalTokens: 2, }, - rawCall: { rawPrompt: [], rawSettings: {} }, warnings: [], }) @@ -592,8 +592,8 @@ describe("Unit: withSupermemory", () => { usage: { inputTokens: 1, outputTokens: 1, + totalTokens: 2, }, - rawCall: { rawPrompt: [], rawSettings: {} }, warnings: [], }) diff --git a/packages/tools/tsconfig.json b/packages/tools/tsconfig.json index d40ba072..61e121d9 100644 --- a/packages/tools/tsconfig.json +++ b/packages/tools/tsconfig.json @@ -1,5 +1,8 @@ { "extends": "@total-typescript/tsconfig/bundler/dom/library-monorepo", + // test/chatapp is a standalone Next.js demo with its own package.json, + // lockfile and tsconfig; it is not part of this package's program. + "exclude": ["node_modules", "test/chatapp"], "compilerOptions": { "baseUrl": ".", "paths": {