Skip to content

Commit 033722f

Browse files
committed
Revert npm-app and agent-runtime changes from 9026052
1 parent 75123e7 commit 033722f

File tree

3 files changed

+34
-100
lines changed

3 files changed

+34
-100
lines changed

npm-app/src/__tests__/tool-handlers.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export interface TestInterface {
9797

9898
const result = await handleCodeSearch(parameters, 'test-id')
9999

100-
expect(result[0].value).toHaveProperty('message')
100+
expect(result[0].value).toContainKey('message')
101101
})
102102

103103
test('finds specific content in test file', async () => {

npm-app/src/client.ts

Lines changed: 32 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,6 @@ export class Client {
209209
private responseComplete: boolean = false
210210
private userInputId: string | undefined
211211
private currentOnChunk: ((chunk: string | PrintModeEvent) => void) | undefined
212-
private onlyChildAgents: Set<string> = new Set()
213-
private emitPromptChunkToParser:
214-
| ((textChunk: string) => boolean)
215-
| undefined
216212

217213
public usageData: UsageData = {
218214
usage: 0,
@@ -956,25 +952,11 @@ export class Client {
956952
})
957953
// Handle subagent streaming messages
958954
this.webSocket.subscribe('subagent-response-chunk', (action) => {
959-
const {
960-
agentId,
961-
agentType,
962-
chunk,
963-
prompt,
964-
forwardToPrompt,
965-
} = action
955+
const { agentId, agentType, chunk, prompt } = action
966956

967957
// Store the chunk locally
968958
storeSubagentChunk({ agentId, agentType, chunk, prompt })
969959

970-
if (
971-
forwardToPrompt !== false &&
972-
this.onlyChildAgents.has(agentId) &&
973-
this.emitPromptChunkToParser
974-
) {
975-
this.emitPromptChunkToParser(chunk)
976-
}
977-
978960
// Refresh display if we're currently viewing this agent
979961
refreshSubagentDisplay(agentId)
980962
})
@@ -1358,44 +1340,6 @@ export class Client {
13581340

13591341
this.userInputId = userInputId
13601342
this.currentOnChunk = onChunk
1361-
this.onlyChildAgents.clear()
1362-
1363-
const emitChunkToParser = (textChunk: string) => {
1364-
rawChunkBuffer.push(textChunk)
1365-
1366-
const trimmed = textChunk.trim()
1367-
for (const tag of ONE_TIME_TAGS) {
1368-
if (trimmed.startsWith(`<${tag}>`) && trimmed.endsWith(closeXml(tag))) {
1369-
if (this.oneTimeFlags[tag]) {
1370-
return true
1371-
}
1372-
Spinner.get().stop()
1373-
const warningMessage = trimmed
1374-
.replace(`<${tag}>`, '')
1375-
.replace(closeXml(tag), '')
1376-
process.stdout.write(yellow(`\n\n${warningMessage}\n\n`))
1377-
this.oneTimeFlags[tag as (typeof ONE_TIME_LABELS)[number]] = true
1378-
return true
1379-
}
1380-
}
1381-
1382-
try {
1383-
xmlStreamParser.write(textChunk, 'utf8')
1384-
} catch (e) {
1385-
logger.error(
1386-
{
1387-
errorMessage: e instanceof Error ? e.message : String(e),
1388-
errorStack: e instanceof Error ? e.stack : undefined,
1389-
chunk: textChunk,
1390-
},
1391-
'Error writing chunk to XML stream parser',
1392-
)
1393-
}
1394-
1395-
return false
1396-
}
1397-
1398-
this.emitPromptChunkToParser = emitChunkToParser
13991343

14001344
const stopResponse = () => {
14011345
responseStopped = true
@@ -1405,8 +1349,6 @@ export class Client {
14051349
this.currentOnChunk = undefined
14061350

14071351
xmlStreamParser.destroy()
1408-
this.emitPromptChunkToParser = undefined
1409-
this.onlyChildAgents.clear()
14101352

14111353
const additionalMessages = prompt
14121354
? [
@@ -1452,50 +1394,45 @@ export class Client {
14521394

14531395
unsubscribeChunks = this.webSocket.subscribe('response-chunk', (a) => {
14541396
if (a.userInputId !== userInputId) return
1455-
const incomingChunk = a.chunk
1397+
if (typeof a.chunk === 'string') {
1398+
const { chunk } = a
1399+
1400+
rawChunkBuffer.push(chunk)
14561401

1457-
const updateOnlyChildAgents = (event: PrintModeEvent) => {
1458-
if ('agentId' in event && event.agentId) {
1402+
const trimmed = chunk.trim()
1403+
for (const tag of ONE_TIME_TAGS) {
14591404
if (
1460-
event.type === 'subagent_start' &&
1461-
'onlyChild' in event &&
1462-
event.onlyChild
1405+
trimmed.startsWith(`<${tag}>`) &&
1406+
trimmed.endsWith(closeXml(tag))
14631407
) {
1464-
this.onlyChildAgents.add(event.agentId)
1465-
} else if (event.type === 'subagent_finish') {
1466-
this.onlyChildAgents.delete(event.agentId)
1408+
if (this.oneTimeFlags[tag]) {
1409+
return
1410+
}
1411+
Spinner.get().stop()
1412+
const warningMessage = trimmed
1413+
.replace(`<${tag}>`, '')
1414+
.replace(closeXml(tag), '')
1415+
process.stdout.write(yellow(`\n\n${warningMessage}\n\n`))
1416+
this.oneTimeFlags[tag as (typeof ONE_TIME_LABELS)[number]] = true
1417+
return
14671418
}
14681419
}
1469-
}
1470-
1471-
if (typeof incomingChunk === 'string') {
1472-
emitChunkToParser(incomingChunk)
1473-
return
1474-
}
1475-
1476-
if (incomingChunk.type === 'text') {
1477-
printModeLog(incomingChunk)
1478-
// Skip nested subagent text from streaming output
1479-
if (incomingChunk.agentId) return
1480-
emitChunkToParser(incomingChunk.text)
1481-
return
1482-
}
14831420

1484-
if (incomingChunk.type === 'error') {
1485-
const errorText = `${yellow(incomingChunk.message)}\n`
1486-
const handler = this.currentOnChunk
1487-
if (handler) {
1488-
handler(errorText)
1489-
} else {
1490-
Spinner.get().stop()
1491-
DiffManager.receivedResponse()
1492-
process.stdout.write(errorText)
1421+
try {
1422+
xmlStreamParser.write(chunk, 'utf8')
1423+
} catch (e) {
1424+
logger.error(
1425+
{
1426+
errorMessage: e instanceof Error ? e.message : String(e),
1427+
errorStack: e instanceof Error ? e.stack : undefined,
1428+
chunk,
1429+
},
1430+
'Error writing chunk to XML stream parser',
1431+
)
14931432
}
1433+
} else {
1434+
onChunk(a.chunk)
14941435
}
1495-
1496-
updateOnlyChildAgents(incomingChunk)
1497-
1498-
onChunk(incomingChunk)
14991436
})
15001437

15011438
let stepsCount = 0
@@ -1508,8 +1445,6 @@ export class Client {
15081445

15091446
if (action.promptId !== userInputId) return
15101447
this.responseComplete = true
1511-
this.emitPromptChunkToParser = undefined
1512-
this.onlyChildAgents.clear()
15131448

15141449
Spinner.get().stop()
15151450

@@ -1617,7 +1552,6 @@ Go to https://www.codebuff.com/config for more information.`) +
16171552

16181553
unsubscribeChunks()
16191554
unsubscribeComplete()
1620-
this.onlyChildAgents.clear()
16211555

16221556
// Clear the onChunk callback when response is complete
16231557
this.currentOnChunk = undefined

packages/agent-runtime/src/tools/stream-parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export async function processStreamWithTools(
202202
reasoning = false
203203
onResponseChunk(`"\n}${endToolTag}\n\n`)
204204
}
205-
onResponseChunk(chunk)
205+
onResponseChunk(chunk.text)
206206
fullResponseChunks.push(chunk.text)
207207
} else if (chunk.type === 'error') {
208208
onResponseChunk(chunk)

0 commit comments

Comments
 (0)