( result: OrchestratorResult, publisher: StreamWriter, runId: string, requestId: string )
| 73 | } |
| 74 | |
| 75 | async function handleAborted( |
| 76 | result: OrchestratorResult, |
| 77 | publisher: StreamWriter, |
| 78 | runId: string, |
| 79 | requestId: string |
| 80 | ): Promise<void> { |
| 81 | const partialContentLen = result.content?.length ?? 0 |
| 82 | const toolCallCount = result.toolCalls?.length ?? 0 |
| 83 | const blockCount = result.contentBlocks?.length ?? 0 |
| 84 | logger.info(`[${requestId}] Stream aborted by explicit stop`, { |
| 85 | partialContentLen, |
| 86 | toolCallCount, |
| 87 | blockCount, |
| 88 | }) |
| 89 | if (!publisher.sawComplete) { |
| 90 | const partialContent = result.content || undefined |
| 91 | await publisher.publish({ |
| 92 | type: MothershipStreamV1EventType.complete, |
| 93 | payload: { |
| 94 | status: MothershipStreamV1CompletionStatus.cancelled, |
| 95 | ...(partialContent ? { partialContent } : {}), |
| 96 | ...(partialContentLen ? { partialContentLen } : {}), |
| 97 | ...(toolCallCount ? { toolCallCount } : {}), |
| 98 | }, |
| 99 | }) |
| 100 | } |
| 101 | await publisher.flush() |
| 102 | await loggedRunStatusUpdate(runId, MothershipStreamV1CompletionStatus.cancelled, requestId, { |
| 103 | completedAt: new Date(), |
| 104 | }) |
| 105 | } |
| 106 | |
| 107 | async function handleError( |
| 108 | result: OrchestratorResult, |
no test coverage detected