MCPcopy Index your code
hub / github.com/TanStack/ai / handleToolPart

Function handleToolPart

packages/ai-opencode/src/stream/translate.ts:308–331  ·  view source on GitHub ↗
(
    part: Extract<OpencodePart, { type: 'tool' }>,
  )

Source from the content-addressed store, hash-verified

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') {

Callers 1

handleEventFunction · 0.85

Calls 6

hasMethod · 0.80
closeTextFunction · 0.70
closeReasoningFunction · 0.70
openToolCallFunction · 0.70
nowFunction · 0.70
deleteMethod · 0.65

Tested by

no test coverage detected