Fix error status

This commit is contained in:
Siddharth Ganesan
2026-03-09 14:30:46 -07:00
parent 2788c68e45
commit 7c0cd36936
2 changed files with 19 additions and 11 deletions

View File

@@ -113,7 +113,7 @@ function inferToolSuccess(data: Record<string, unknown> | undefined): {
const explicitSuccess = data?.success ?? resultObj.success
const hasResultData = data?.result !== undefined || data?.data !== undefined
const hasError = !!data?.error || !!resultObj.error
const success = hasExplicitSuccess ? !!explicitSuccess : hasResultData && !hasError
const success = hasExplicitSuccess ? !!explicitSuccess : !hasError
return { success, hasResultData, hasError }
}

View File

@@ -180,14 +180,22 @@ export async function runStreamLoop(
* Build a ToolCallSummary array from the streaming context.
*/
export function buildToolCallSummaries(context: StreamingContext): ToolCallSummary[] {
return Array.from(context.toolCalls.values()).map((toolCall) => ({
id: toolCall.id,
name: toolCall.name,
status: toolCall.status,
params: toolCall.params,
result: toolCall.result?.output,
error: toolCall.error,
durationMs:
toolCall.endTime && toolCall.startTime ? toolCall.endTime - toolCall.startTime : undefined,
}))
return Array.from(context.toolCalls.values()).map((toolCall) => {
let status = toolCall.status
if (toolCall.result && toolCall.result.success !== undefined) {
status = toolCall.result.success ? 'success' : 'error'
} else if (status === 'pending' || status === 'executing') {
status = toolCall.error ? 'error' : 'success'
}
return {
id: toolCall.id,
name: toolCall.name,
status,
params: toolCall.params,
result: toolCall.result?.output,
error: toolCall.error,
durationMs:
toolCall.endTime && toolCall.startTime ? toolCall.endTime - toolCall.startTime : undefined,
}
})
}