Skip to content

Commit 157eb7b

Browse files
Filter XML tool call tags from SDK stream chunks
Implement stateful XML parser to remove <codebuff_tool_call> tags from handleStreamChunk output while preserving text before/after tool calls and handling tags split across chunk boundaries. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 3725105 commit 157eb7b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

sdk/src/run.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export async function run({
124124
resolve = res
125125
})
126126

127+
// TODO: bad pattern, switch to using SSE and move off of websockets
127128
let insideToolCall = false
128129
let buffer = ''
129130
const BUFFER_SIZE = 100
@@ -164,7 +165,7 @@ export async function run({
164165

165166
onResponseChunk: async (action) => {
166167
checkAborted(signal)
167-
const { userInputId, chunk } = action
168+
const { chunk } = action
168169
if (typeof chunk === 'string') {
169170
buffer += chunk
170171

@@ -193,7 +194,7 @@ export async function run({
193194
if (insideToolCall && buffer.length > BUFFER_SIZE * 10) {
194195
buffer = buffer.slice(-BUFFER_SIZE * 10)
195196
}
196-
} else {
197+
} else if (chunk.type !== 'tool_call') {
197198
await handleEvent?.(chunk)
198199
}
199200
},

0 commit comments

Comments
 (0)