( data: MothershipStreamV1ToolResultPayload, context: StreamingContext, parentToolCallId: string | undefined )
| 174 | } |
| 175 | |
| 176 | function handleResultPhase( |
| 177 | data: MothershipStreamV1ToolResultPayload, |
| 178 | context: StreamingContext, |
| 179 | parentToolCallId: string | undefined |
| 180 | ): void { |
| 181 | const { toolCallId, toolName } = data |
| 182 | const mainToolCall = ensureTerminalToolCallState(context, toolCallId, toolName) |
| 183 | const { success, hasResultData } = inferToolSuccess(data) |
| 184 | let status: MothershipStreamV1ToolOutcome |
| 185 | if (data.status === MothershipStreamV1ToolOutcome.cancelled) { |
| 186 | status = MothershipStreamV1ToolOutcome.cancelled |
| 187 | } else if (data.status === MothershipStreamV1ToolOutcome.skipped) { |
| 188 | status = MothershipStreamV1ToolOutcome.skipped |
| 189 | } else if (data.status === MothershipStreamV1ToolOutcome.rejected) { |
| 190 | status = MothershipStreamV1ToolOutcome.rejected |
| 191 | } else { |
| 192 | status = success ? MothershipStreamV1ToolOutcome.success : MothershipStreamV1ToolOutcome.error |
| 193 | } |
| 194 | const endTime = Date.now() |
| 195 | const errorMessage = |
| 196 | !success && status !== MothershipStreamV1ToolOutcome.skipped |
| 197 | ? getToolResultErrorMessage(data) || |
| 198 | (status === MothershipStreamV1ToolOutcome.cancelled |
| 199 | ? 'Tool cancelled' |
| 200 | : status === MothershipStreamV1ToolOutcome.rejected |
| 201 | ? 'Tool rejected' |
| 202 | : 'Tool failed') |
| 203 | : undefined |
| 204 | |
| 205 | if (parentToolCallId) { |
| 206 | const toolCalls = context.subAgentToolCalls[parentToolCallId] || [] |
| 207 | const subAgentToolCall = toolCalls.find((tc) => tc.id === toolCallId) |
| 208 | if (subAgentToolCall) { |
| 209 | setTerminalToolCallState(subAgentToolCall, { |
| 210 | status, |
| 211 | ...(hasResultData ? { output: data.output } : {}), |
| 212 | ...(errorMessage ? { error: errorMessage } : {}), |
| 213 | endTime, |
| 214 | }) |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | setTerminalToolCallState(mainToolCall, { |
| 219 | status, |
| 220 | ...(hasResultData ? { output: data.output } : {}), |
| 221 | ...(errorMessage ? { error: errorMessage } : {}), |
| 222 | endTime, |
| 223 | }) |
| 224 | stampToolCallBlockEnd(context, toolCallId, endTime) |
| 225 | markToolResultSeen(toolCallId) |
| 226 | } |
| 227 | |
| 228 | function stampToolCallBlockEnd( |
| 229 | context: StreamingContext, |
no test coverage detected