Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/messages/prune.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,18 @@ const pruneToolInputs = (
continue
}

if (part.state.input?.content !== undefined) {
// Write tool has content field, edit tool has oldString/newString fields
if (part.tool === 'write' && part.state.input?.content !== undefined) {
part.state.input.content = PRUNED_TOOL_INPUT_REPLACEMENT
}
if (part.tool === 'edit') {
if (part.state.input?.oldString !== undefined) {
part.state.input.oldString = PRUNED_TOOL_INPUT_REPLACEMENT
}
if (part.state.input?.newString !== undefined) {
part.state.input.newString = PRUNED_TOOL_INPUT_REPLACEMENT
}
}
}
}
}
13 changes: 12 additions & 1 deletion lib/strategies/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,25 @@ export const calculateTokensSaved = (
}
// For write and edit tools, count input content as that is all we prune for these tools
// (input is present in both completed and error states)
if (part.tool === "write" || part.tool === "edit") {
if (part.tool === "write") {
const inputContent = part.state.input?.content
const content = typeof inputContent === 'string'
? inputContent
: JSON.stringify(inputContent ?? '')
contents.push(content)
continue
}
if (part.tool === "edit") {
const oldString = part.state.input?.oldString
const newString = part.state.input?.newString
if (typeof oldString === 'string') {
contents.push(oldString)
}
if (typeof newString === 'string') {
contents.push(newString)
}
continue
}
// For other tools, count output or error based on status
if (part.state.status === "completed") {
const content = typeof part.state.output === 'string'
Expand Down