(
part: Extract<OpencodePart, { type: 'tool' }>,
)
| 306 | } |
| 307 | |
| 308 | function* handleToolPart( |
| 309 | part: Extract<OpencodePart, { type: 'tool' }>, |
| 310 | ): Generator<StreamChunk> { |
| 311 | yield* closeText() |
| 312 | yield* closeReasoning() |
| 313 | yield* openToolCall(part) |
| 314 | |
| 315 | const state = part.state |
| 316 | if (state.status !== 'completed' && state.status !== 'error') return |
| 317 | if (resolvedToolCalls.has(part.callID)) return |
| 318 | resolvedToolCalls.add(part.callID) |
| 319 | unresolvedToolCalls.delete(part.callID) |
| 320 | |
| 321 | const isError = state.status === 'error' |
| 322 | yield { |
| 323 | type: EventType.TOOL_CALL_RESULT, |
| 324 | toolCallId: part.callID, |
| 325 | messageId: genId(), |
| 326 | model, |
| 327 | timestamp: now(), |
| 328 | content: isError ? state.error : state.output, |
| 329 | ...(isError && { state: 'output-error' as const }), |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | function* handleEvent(event: OpencodeEvent): Generator<StreamChunk> { |
| 334 | if (event.type === 'message.part.updated') { |
no test coverage detected