(event, context)
| 2 | import { flushSubagentThinkingBlock, flushThinkingBlock } from './types' |
| 3 | |
| 4 | export const handleCompleteEvent: StreamHandler = (event, context) => { |
| 5 | flushSubagentThinkingBlock(context) |
| 6 | flushThinkingBlock(context) |
| 7 | if (event.type !== 'complete') { |
| 8 | context.streamComplete = true |
| 9 | return |
| 10 | } |
| 11 | |
| 12 | if (event.payload.usage) { |
| 13 | context.usage = { |
| 14 | prompt: (context.usage?.prompt || 0) + (event.payload.usage.input_tokens || 0), |
| 15 | completion: (context.usage?.completion || 0) + (event.payload.usage.output_tokens || 0), |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | if (event.payload.cost) { |
| 20 | context.cost = { |
| 21 | input: (context.cost?.input || 0) + (event.payload.cost.input || 0), |
| 22 | output: (context.cost?.output || 0) + (event.payload.cost.output || 0), |
| 23 | total: (context.cost?.total || 0) + (event.payload.cost.total || 0), |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | context.streamComplete = true |
| 28 | } |
nothing calls this directly
no test coverage detected