(event, context)
| 9 | const logger = createLogger('CopilotRunHandler') |
| 10 | |
| 11 | export 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', |
nothing calls this directly
no test coverage detected