Skip to content

Commit 0e77c68

Browse files
Sync public snapshot from freebuff-private
1 parent 88af45e commit 0e77c68

11 files changed

Lines changed: 61 additions & 57 deletions

File tree

‎bun.lock‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/agent-runtime/src/main-prompt.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export async function callMainPrompt(
172172

173173
if (validationErrors.length > 0) {
174174
const message = `Invalid agent config: ${validationErrors.map((err) => err.message).join('\n')}`
175-
sendAction({
175+
await sendAction({
176176
action: {
177177
type: 'prompt-error',
178178
message,
@@ -188,7 +188,7 @@ export async function callMainPrompt(
188188
}
189189
}
190190

191-
sendAction({
191+
await sendAction({
192192
action: {
193193
type: 'response-chunk',
194194
userInputId: promptId,
@@ -204,9 +204,9 @@ export async function callMainPrompt(
204204
const result = await mainPrompt({
205205
...params,
206206
localAgentTemplates,
207-
onResponseChunk: (chunk) => {
207+
onResponseChunk: async (chunk) => {
208208
if (!params.signal.aborted) {
209-
sendAction({
209+
await sendAction({
210210
action: {
211211
type: 'response-chunk',
212212
userInputId: promptId,
@@ -219,7 +219,7 @@ export async function callMainPrompt(
219219

220220
const { sessionState, output } = result
221221

222-
sendAction({
222+
await sendAction({
223223
action: {
224224
type: 'response-chunk',
225225
userInputId: promptId,
@@ -232,7 +232,7 @@ export async function callMainPrompt(
232232
})
233233

234234
// Send prompt data back
235-
sendAction({
235+
await sendAction({
236236
action: {
237237
type: 'prompt-response',
238238
promptId,

‎packages/agent-runtime/src/run-agent-step.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1738,7 +1738,7 @@ export async function loopAgentSteps(
17381738
) {
17391739
completionCheckpoint = undefined
17401740
}
1741-
params.onResponseChunk(chunk)
1741+
return params.onResponseChunk(chunk)
17421742
},
17431743
}).catch((error: unknown) => {
17441744
const { statusCode, errorCode } = extractApiErrorDetails(error)

‎packages/agent-runtime/src/run-programmatic-step.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,9 @@ async function executeSingleToolCall(
557557
toolCallsToAddToMessageHistory: [],
558558
toolResultsToAddToMessageHistory,
559559

560-
onResponseChunk: (chunk: string | PrintModeEvent) => {
560+
onResponseChunk: async (chunk: string | PrintModeEvent) => {
561561
if (typeof chunk === 'string') {
562-
onResponseChunk(chunk)
562+
await onResponseChunk(chunk)
563563
return
564564
}
565565

@@ -572,7 +572,7 @@ async function executeSingleToolCall(
572572
case 'subagent_start':
573573
case 'subagent_finish':
574574
if (!chunk.parentAgentId) {
575-
onResponseChunk({
575+
await onResponseChunk({
576576
...chunk,
577577
parentAgentId,
578578
})
@@ -582,7 +582,7 @@ async function executeSingleToolCall(
582582
case 'tool_call':
583583
case 'tool_result': {
584584
if (!chunk.parentAgentId) {
585-
onResponseChunk({
585+
await onResponseChunk({
586586
...chunk,
587587
parentAgentId,
588588
})
@@ -596,7 +596,7 @@ async function executeSingleToolCall(
596596
}
597597

598598
// For other events or top-level spawns, send as-is
599-
onResponseChunk(chunk)
599+
await onResponseChunk(chunk)
600600
},
601601
})
602602

‎packages/agent-runtime/src/tool-stream-parser.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ export async function* processStreamWithTools(params: {
8282
await processor.onTagEnd(toolName, input, providerOptions)
8383
}
8484

85-
function flush() {
85+
async function flush() {
8686
if (buffer) {
87-
onResponseChunk({
87+
await onResponseChunk({
8888
type: 'text',
8989
text: buffer,
9090
})
@@ -96,7 +96,7 @@ export async function* processStreamWithTools(params: {
9696
chunk: StreamChunk | undefined,
9797
): AsyncGenerator<StreamChunk> {
9898
if (chunk === undefined) {
99-
flush()
99+
await flush()
100100
streamCompleted = true
101101
return
102102
}
@@ -118,7 +118,7 @@ export async function* processStreamWithTools(params: {
118118

119119
// Flush buffer before yielding tool calls so text event is sent first
120120
if (toolCalls.length > 0) {
121-
flush()
121+
await flush()
122122
}
123123

124124
// Then process and yield any XML tool calls found
@@ -135,7 +135,7 @@ export async function* processStreamWithTools(params: {
135135
}
136136
return
137137
} else {
138-
flush()
138+
await flush()
139139
}
140140

141141
if (chunk.type === 'tool-call') {
@@ -166,7 +166,7 @@ export async function* processStreamWithTools(params: {
166166
// Flush any remaining buffered text so it reaches onResponseChunk even on
167167
// abort. Without this, text streamed after the last tool call would be lost
168168
// from the message history.
169-
flush()
169+
await flush()
170170
}
171171
return result
172172
}

‎packages/agent-runtime/src/tools/handlers/tool/spawn-agent-inline.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ export const handleSpawnAgentInline = (async (
139139
fingerprintId,
140140
parentSystemPrompt: system,
141141
parentTools,
142-
onResponseChunk: (chunk) => {
142+
onResponseChunk: async (chunk) => {
143143
// Context pruning is internal and its raw summary would be noisy in the
144144
// client, but lifecycle events still need to flow so the UI can explain
145145
// the otherwise silent pause.
146146
if (typeof chunk === 'string') {
147147
if (agentType !== 'context-pruner') {
148-
sendSubagentChunk({
148+
await sendSubagentChunk({
149149
userInputId,
150150
agentId: childAgentState.agentId,
151151
agentType,
@@ -160,7 +160,7 @@ export const handleSpawnAgentInline = (async (
160160
if (agentType === 'context-pruner' && !isLifecycleEvent) return
161161
if (chunk.type === 'text') {
162162
if (chunk.text) {
163-
sendSubagentChunk({
163+
await sendSubagentChunk({
164164
userInputId,
165165
agentId: childAgentState.agentId,
166166
agentType,
@@ -170,7 +170,7 @@ export const handleSpawnAgentInline = (async (
170170
}
171171
return
172172
}
173-
writeToClient(chunk)
173+
await writeToClient(chunk)
174174
},
175175
clearUserPromptMessagesAfterResponse: false,
176176
})

‎packages/agent-runtime/src/tools/handlers/tool/spawn-agents.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ export const handleSpawnAgents = (async (
240240
parentTools: agentTemplate.inheritParentSystemPrompt
241241
? parentTools
242242
: undefined,
243-
onResponseChunk: (chunk: string | PrintModeEvent) => {
243+
onResponseChunk: async (chunk: string | PrintModeEvent) => {
244244
if (typeof chunk === 'string') {
245-
sendSubagentChunk({
245+
await sendSubagentChunk({
246246
userInputId,
247247
agentId: subAgentState.agentId,
248248
agentType,
@@ -254,7 +254,7 @@ export const handleSpawnAgents = (async (
254254

255255
if (chunk.type === 'text') {
256256
if (chunk.text) {
257-
writeToClient({
257+
await writeToClient({
258258
type: 'text' as const,
259259
agentId: subAgentState.agentId,
260260
text: chunk.text,
@@ -292,15 +292,15 @@ export const handleSpawnAgents = (async (
292292
chunk.type === 'tool_call' ||
293293
chunk.type === 'tool_result')
294294
) {
295-
writeToClient({ ...chunk, parentAgentId })
295+
await writeToClient({ ...chunk, parentAgentId })
296296
return
297297
}
298298

299299
const eventWithAgent = {
300300
...chunk,
301301
agentId: subAgentState.agentId,
302302
}
303-
writeToClient(eventWithAgent)
303+
await writeToClient(eventWithAgent)
304304
},
305305
})
306306
return { ...result, agentType, agentName: agentTemplate.displayName }

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ export async function processStream(
237237
const thinkTagStream = new ThinkTagStream({
238238
implicitOpen: historyLeaksThinkTags(agentState.messageHistory),
239239
})
240-
const emitThinkSegments = (segments: ThinkStreamSegment[]): void => {
240+
const emitThinkSegments = async (segments: ThinkStreamSegment[]) => {
241241
for (const segment of segments) {
242242
if (segment.type === 'text') {
243-
onResponseChunk(segment.text)
243+
await onResponseChunk(segment.text)
244244
} else {
245-
onResponseChunk({
245+
await onResponseChunk({
246246
type: 'reasoning_delta',
247247
text: segment.text,
248248
ancestorRunIds,
@@ -595,8 +595,8 @@ export async function processStream(
595595
// A lane that populates the native reasoning field is by definition
596596
// not putting the thought in `content`, so this step is not leaking
597597
// and anything held on speculation is the answer.
598-
emitThinkSegments(thinkTagStream.disarmImplicitOpen())
599-
onResponseChunk({
598+
await emitThinkSegments(thinkTagStream.disarmImplicitOpen())
599+
await onResponseChunk({
600600
type: 'reasoning_delta',
601601
text: chunk.text,
602602
ancestorRunIds,
@@ -609,10 +609,10 @@ export async function processStream(
609609
// isThinkOnlyResponse reads it to keep a thinking-only step from ending
610610
// the turn, and historyLeaksThinkTags reads it to arm the next step.
611611
// Stripping it here would erase both signals.
612-
emitThinkSegments(thinkTagStream.push(chunk.text))
612+
await emitThinkSegments(thinkTagStream.push(chunk.text))
613613
fullResponseChunks.push(chunk.text)
614614
} else if (chunk.type === 'error') {
615-
onResponseChunk(chunk)
615+
await onResponseChunk(chunk)
616616
if (chunk.source) {
617617
const recovery = RECOVERY_BY_SOURCE[chunk.source]
618618
sawStreamRecovery = true
@@ -708,7 +708,7 @@ export async function processStream(
708708
// recovery, so it is checked here. A step that called a tool is not
709709
// replying yet, so its open block stays a thought.
710710
const finishReason = streamFinishReason?.()
711-
emitThinkSegments(
711+
await emitThinkSegments(
712712
thinkTagStream.flush({
713713
stepCompleted:
714714
!signal.aborted &&
@@ -761,7 +761,7 @@ export async function processStream(
761761
// Release anything the think-tag split is still holding — a partial tag
762762
// that never completed, or a head held for an orphan `</think>` that never
763763
// came. Runs on the abort paths too, so speculation can never lose text.
764-
emitThinkSegments(thinkTagStream.flush())
764+
await emitThinkSegments(thinkTagStream.flush())
765765

766766
// Trigger cleanup of the processStreamWithTools generator so it flushes any
767767
// remaining buffered text to assistantMessages before we build the history.

0 commit comments

Comments
 (0)