diff --git a/README.md b/README.md index 937207c..69e3431 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Automatically reduces token usage in OpenCode by removing obsolete tool outputs from conversation history. -![DCP in action](dcp-demo.png) +![DCP in action](dcp-demo3.png) ## Installation diff --git a/lib/fetch-wrapper/formats/anthropic.ts b/lib/fetch-wrapper/formats/anthropic.ts index dab215e..c1a99d8 100644 --- a/lib/fetch-wrapper/formats/anthropic.ts +++ b/lib/fetch-wrapper/formats/anthropic.ts @@ -42,7 +42,12 @@ export const anthropicFormat: FormatDescriptor = { if (msg.role === 'assistant') { // Append to existing content array if (Array.isArray(msg.content)) { - msg.content.push({ type: 'text', text: injection }) + const firstToolUseIndex = msg.content.findIndex((block: any) => block.type === 'tool_use') + if (firstToolUseIndex !== -1) { + msg.content.splice(firstToolUseIndex, 0, { type: 'text', text: injection }) + } else { + msg.content.push({ type: 'text', text: injection }) + } } else if (typeof msg.content === 'string') { // Convert string content to array format msg.content = [