Streamed tool-call deltas are typed as complete tool calls (ToolChoice), so documented deltas don't type-check

Abierto Apto para principiantes
#264 0 comentarios 0 reacciones 0 asignados Ver en GitHub

@Kinfe123 ya está trabajando en esto.

Desde el 1/12/2026.

  • #265 de @Kinfe123 — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
typescript

Línea de trabajo

Empieza con el esquema OpenAPI en https://docs.together.ai/openapi.yaml, sigue ChatCompletionChunk hasta delta.tool_calls y su referencia a ToolChoice; después, comprueba cómo este repositorio genera tipos TypeScript a partir de la especificación. Actualiza el tipo de delta transmitido para que los deltas parciales documentados pasen la comprobación de tipos y los campos que no aparecen en deltas posteriores sean opcionales. El trabajo estará terminado cuando la reproducción compile con el comando TypeScript indicado y ToolChoice para respuestas no transmitidas permanezca sin cambios.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

In [email protected], streamed tool-call deltas are typed as ToolChoice, the complete tool call. ChatCompletionChunk.Choice.Delta.tool_calls is Array<ToolChoice>, and ToolChoice requires id, type, index, function.name and function.arguments.

Only the first delta of a call has all of those. Together's own streaming example (https://docs.together.ai/docs/inference/function-calling/single-call, "delta 2") sends later deltas as { index, function: { arguments } }. So:

  • the documented delta doesn't type-check, and
  • delta.tool_calls[0].id is typed string but is undefined for every delta after the first, so code that relies on it compiles and then breaks at runtime.
Reproduction

npm i [email protected] typescript, then npx tsc --noEmit --strict --module nodenext --moduleResolution nodenext --skipLibCheck repro.ts (TypeScript 7.0.2):

import type { ChatCompletionChunk } from "together-ai/resources/chat/completions";

type ToolCallDelta = NonNullable<ChatCompletionChunk.Choice.Delta["tool_calls"]>[number];

// The two deltas from the "Streaming" example in
// https://docs.together.ai/docs/inference/function-calling/single-call
const delta1: ToolCallDelta = {
  index: 0,
  id: "call_fwbx4e156wigo9ayq7tszngh",
  type: "function",
  function: { name: "get_weather", arguments: "" },
};
const delta2: ToolCallDelta = {
  index: 0,
  function: { arguments: '{"location":"New York City, USA"}' },
};

// Adding a name moves the error to `id` and `type`.
const delta2WithName: ToolCallDelta = {
  index: 0,
  function: { name: "get_weather", arguments: '{"location":"New York City, USA"}' },
};

// This compiles, but for delta 2 the value is undefined at runtime.
declare const chunk: ChatCompletionChunk;
const id: string = chunk.choices[0]!.delta.tool_calls![0]!.id;

export { delta1, delta2, delta2WithName, id };

Output:

repro.ts(15,3): error TS2741: Property 'name' is missing in type '{ arguments: string; }' but required in type 'Function'.
repro.ts(19,7): error TS2739: Type '{ index: number; function: { name: string; arguments: string; }; }' is missing the following properties from type 'ToolChoice': id, type
Cause

The types come from the OpenAPI spec (https://docs.together.ai/openapi.yaml). ChatCompletionChunk → delta.tool_calls → $ref: '#/components/schemas/ToolChoice', which has required: [id, type, function, index] and function.required: [name, arguments]. The spec even has # TODO: is this the right place for index? on that schema.

Suggested fix

Give stream deltas their own schema, the way the OpenAI SDK does with ChatCompletionChunk.Choice.Delta.ToolCall: index required, and id, type, function.name and function.arguments optional. ToolChoice can stay as is for non-streamed responses.

I checked this repo's issues for "ToolChoice", "tool_calls delta" and "stream tool_calls id" and didn't find an existing report.

Lenguaje dominante
TypeScript
Estrellas
73
Forks
12
Merge medio
10 d 21 h
PR fusionados (30 d)
2

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de togethercomputer/together-typescript

Todos los issues de togethercomputer/together-typescript

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.