diff --git a/packages/tools/test/claude-memory-real-example.ts b/packages/tools/test/claude-memory-real-example.ts index 1124faa8e..bb6070d48 100644 --- a/packages/tools/test/claude-memory-real-example.ts +++ b/packages/tools/test/claude-memory-real-example.ts @@ -119,25 +119,25 @@ export async function realClaudeMemoryExample() { const toolResults = [] if (responseData.content) { - for (const block of responseData.content) { - if (block.type === "tool_use" && block.name === "memory") { - console.log("\\n🔧 Processing memory tool call:") + const memoryToolCalls = responseData.content.filter( + (block: any): block is { type: 'tool_use'; id: string; name: 'memory'; input: { command: MemoryCommand; path: string } } => + block.type === "tool_use" && block.name === "memory", + ) + + const results = await Promise.all( + memoryToolCalls.map((block: any) => { + console.log("\n🔧 Processing memory tool call:") console.log(`Command: ${block.input.command}`) console.log(`Path: ${block.input.path}`) - // Handle the memory tool call - const toolResult = await handleClaudeMemoryToolCall( - block, - SUPERMEMORY_API_KEY, - { - projectId: "python-scraper-help", - memoryContainerTag: "claude_memory_debug", - }, - ) - - toolResults.push(toolResult) - } - } + return handleClaudeMemoryToolCall(block, SUPERMEMORY_API_KEY, { + projectId: "python-scraper-help", + memoryContainerTag: "claude_memory_debug", + }) + }), + ) + + toolResults.push(...results) } // Step 3: Send tool results back to Claude if there were any @@ -196,16 +196,18 @@ export async function processClaudeResponse( const toolResults = [] if (claudeResponseData.content) { - for (const block of claudeResponseData.content) { - if (block.type === "tool_use" && block.name === "memory") { - const toolResult = await handleClaudeMemoryToolCall( - block, - supermemoryApiKey, - config, - ) - toolResults.push(toolResult) - } - } + const memoryToolCalls = claudeResponseData.content.filter( + (block: any): block is { type: 'tool_use'; id: string; name: 'memory'; input: { command: MemoryCommand; path: string } } => + block.type === "tool_use" && block.name === "memory", + ) + + const results = await Promise.all( + memoryToolCalls.map((block: any) => + handleClaudeMemoryToolCall(block, supermemoryApiKey, config), + ), + ) + + toolResults.push(...results) } return toolResults