MCPcopy Index your code
hub / github.com/simstudioai/sim / handleCompleteEvent

Function handleCompleteEvent

apps/sim/lib/copilot/request/handlers/complete.ts:4–28  ·  view source on GitHub ↗
(event, context)

Source from the content-addressed store, hash-verified

2import { flushSubagentThinkingBlock, flushThinkingBlock } from './types'
3
4export 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}

Callers

nothing calls this directly

Calls 2

flushThinkingBlockFunction · 0.90

Tested by

no test coverage detected