MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / processToolCalls

Method processToolCalls

src/api/providers/openai.ts:470–501  ·  view source on GitHub ↗

* Helper generator to process tool calls from a stream chunk. * Tracks active tool call IDs and yields tool_call_partial and tool_call_end events. * @param delta - The delta object from the stream chunk * @param finishReason - The finish_reason from the stream chunk * @param activeToolCallId

(
		delta: OpenAI.Chat.Completions.ChatCompletionChunk.Choice.Delta | undefined,
		finishReason: string | null | undefined,
		activeToolCallIds: Set<string>,
	)

Source from the content-addressed store, hash-verified

468 * @param activeToolCallIds - Set to track active tool call IDs (mutated in place)
469 */
470 protected *processToolCalls(
471 delta: OpenAI.Chat.Completions.ChatCompletionChunk.Choice.Delta | undefined,
472 finishReason: string | null | undefined,
473 activeToolCallIds: Set<string>,
474 ): Generator<
475 | { type: "tool_call_partial"; index: number; id?: string; name?: string; arguments?: string }
476 | { type: "tool_call_end"; id: string }
477 > {
478 if (delta?.tool_calls) {
479 for (const toolCall of delta.tool_calls) {
480 if (toolCall.id) {
481 activeToolCallIds.add(toolCall.id)
482 }
483 yield {
484 type: "tool_call_partial",
485 index: toolCall.index,
486 id: toolCall.id,
487 name: toolCall.function?.name,
488 arguments: toolCall.function?.arguments,
489 }
490 }
491 }
492
493 // Emit tool_call_end events when finish_reason is "tool_calls"
494 // This ensures tool calls are finalized even if the stream doesn't properly close
495 if (finishReason === "tool_calls" && activeToolCallIds.size > 0) {
496 for (const id of activeToolCallIds) {
497 yield { type: "tool_call_end", id }
498 }
499 activeToolCallIds.clear()
500 }
501 }
502
503 protected _getUrlHost(baseUrl?: string): string {
504 try {

Callers 3

createMessageMethod · 0.95
handleStreamResponseMethod · 0.95
createMessageMethod · 0.80

Calls 1

clearMethod · 0.65

Tested by

no test coverage detected