MCPcopy Create free account
hub / github.com/simstudioai/sim / handleRunEvent

Function handleRunEvent

apps/sim/lib/copilot/request/handlers/run.ts:11–73  ·  view source on GitHub ↗
(event, context)

Source from the content-addressed store, hash-verified

9const logger = createLogger('CopilotRunHandler')
10
11export const handleRunEvent: StreamHandler = (event, context) => {
12 if (event.type !== 'run') {
13 return
14 }
15
16 if (event.payload.kind === MothershipStreamV1RunKind.checkpoint_pause) {
17 const frames = (event.payload.frames ?? []).map((frame) => ({
18 parentToolCallId: frame.parentToolCallId,
19 parentToolName: frame.parentToolName,
20 pendingToolIds: frame.pendingToolIds,
21 // Carried through for the per-subagent resume fan-out; undefined under the
22 // legacy bundled-frame model (all frames share the top-level checkpointId).
23 ...(frame.checkpointId ? { checkpointId: frame.checkpointId } : {}),
24 }))
25
26 context.awaitingAsyncContinuation = {
27 checkpointId: event.payload.checkpointId,
28 executionId: event.payload.executionId || context.executionId,
29 runId: event.payload.runId || context.runId,
30 pendingToolCallIds: event.payload.pendingToolCallIds,
31 frames: frames.length > 0 ? frames : undefined,
32 }
33 logger.info('Received checkpoint pause', {
34 checkpointId: context.awaitingAsyncContinuation.checkpointId,
35 executionId: context.awaitingAsyncContinuation.executionId,
36 runId: context.awaitingAsyncContinuation.runId,
37 pendingToolCallIds: context.awaitingAsyncContinuation.pendingToolCallIds,
38 frameCount: frames.length,
39 })
40 context.streamComplete = true
41 return
42 }
43
44 if (event.payload.kind === MothershipStreamV1RunKind.compaction_start) {
45 addContentBlock(context, {
46 type: 'tool_call',
47 toolCall: {
48 id: `compaction-${Date.now()}`,
49 name: 'context_compaction',
50 status: 'executing',
51 },
52 })
53 return
54 }
55
56 if (event.payload.kind === MothershipStreamV1RunKind.resumed) {
57 context.awaitingAsyncContinuation = undefined
58 context.streamComplete = false
59 logger.info('Received run resumed event')
60 return
61 }
62
63 if (event.payload.kind === MothershipStreamV1RunKind.compaction_done) {
64 addContentBlock(context, {
65 type: 'tool_call',
66 toolCall: {
67 id: `compaction-${Date.now()}`,
68 name: 'context_compaction',

Callers

nothing calls this directly

Calls 2

addContentBlockFunction · 0.90
infoMethod · 0.80

Tested by

no test coverage detected