Skip to content

Commit f276388

Browse files
authored
Merge pull request #102 from Tarquinen/fix/anthropic-nudge-injection-placement
Fix nudge injection placement in Anthropic format
2 parents 05d5d8d + 193b4e1 commit f276388

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Automatically reduces token usage in OpenCode by removing obsolete tool outputs from conversation history.
66

7-
![DCP in action](dcp-demo.png)
7+
![DCP in action](dcp-demo3.png)
88

99
## Installation
1010

lib/fetch-wrapper/formats/anthropic.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ export const anthropicFormat: FormatDescriptor = {
4242
if (msg.role === 'assistant') {
4343
// Append to existing content array
4444
if (Array.isArray(msg.content)) {
45-
msg.content.push({ type: 'text', text: injection })
45+
const firstToolUseIndex = msg.content.findIndex((block: any) => block.type === 'tool_use')
46+
if (firstToolUseIndex !== -1) {
47+
msg.content.splice(firstToolUseIndex, 0, { type: 'text', text: injection })
48+
} else {
49+
msg.content.push({ type: 'text', text: injection })
50+
}
4651
} else if (typeof msg.content === 'string') {
4752
// Convert string content to array format
4853
msg.content = [

0 commit comments

Comments
 (0)