Skip to content

@tanstack/ai-gemini@0.38.0

Choose a tag to compare

@github-actions github-actions released this 13 Oct 17:48
· 165 commits to main since this release
Immutable release. Only release title and notes can be modified.
293aea9

Minor Changes

  • #1739 a0150c2 - Text adapters now set one stable code on RUN_ERROR when the input does not fit in the model's context window: code: 'context_overflow'. @tanstack/ai exports it as CONTEXT_OVERFLOW_CODE. The provider's own text stays in message.

    if (chunk.type === 'RUN_ERROR' && chunk.code === CONTEXT_OVERFLOW_CODE) {
      // shorten the messages, then call chat() again
    }

    These adapters set it: OpenAI and the other OpenAI-compatible adapters (from code: 'context_length_exceeded'), Anthropic, Gemini, Bedrock (Converse, Chat Completions, and Responses), OpenRouter, Grok, Cloudflare Workers AI, and BytePlus.

    Changes to code that reads the old values:

    • OpenAI-compatible adapters gave code: 'context_length_exceeded'. They now give 'context_overflow'. rawEvent still has the provider's code.
    • Anthropic, Grok, OpenRouter, and BytePlus gave the HTTP status or a general bad-request code for this error. Gemini and Bedrock Converse gave no code.
    • The Anthropic adapter now sends RUN_ERROR with this code when the model stops with stop_reason: 'model_context_window_exceeded'. Before, it sent RUN_FINISHED with finishReason: 'stop', so a cut-off answer looked complete.
  • #1692 7532b2b - Set thinking with chat({ reasoning }).

    • Gemini 3 models get thinkingLevel.
    • Gemini 2.5 models get thinkingBudget, from budgetTokens or a per-model table. off sends thinkingBudget: 0.
    • summary sets includeThoughts.
    • The experimental Interactions adapter sends thinking_level and thinking_summaries.
    • Each chat model has its reasoning data in model-meta.ts. GeminiModelReasoningByName and GEMINI_MODEL_REASONING come from it.

    Breaking: thinkingConfig is no longer in the chat modelOptions, and GeminiThinkingOptions is removed. The Interactions adapter no longer takes generation_config.thinking_level or thinking_summaries. Image generation keeps its own thinkingConfig.

    // Before
    chat({
      adapter: geminiText('gemini-3.5-flash'),
      messages,
      modelOptions: {
        thinkingConfig: { includeThoughts: true, thinkingLevel: 'HIGH' },
      },
    })
    
    // After
    chat({
      adapter: geminiText('gemini-3.5-flash'),
      messages,
      reasoning: 'high',
    })

Patch Changes

  • #1732 eb4eea0 - Keep a schema property or a tool argument named __proto__. Before this fix, code that copied it with out[key] = value went to the __proto__ setter instead, so the key was lost.

    • @tanstack/ai-utils: transformNullsToUndefined and undoNullWidening keep the key.
    • @tanstack/openai-base: the strict schema and its null-widening map keep the key.
    • @tanstack/ai-mistral: the null-widening map keeps the key.
    • @tanstack/ai-openrouter: the Responses tool input normalizer keeps the key.
    • @tanstack/ai-gemini: the Interactions adapter keeps the key in tool parameters.
    • @tanstack/ai-bedrock: the Converse adapter puts the tool schemas and tool inputs back into the request body after the AWS SDK serializes it, because the SDK drops the key.
  • #1698 1bfcee3 - Keep a conversation valid when the next request goes to a different model.

    • Each assistant message records metadata.tanstack.source ({ provider, api, model }), and responseId and the resolved model when the provider sends them. A failed or aborted answer gets stopReason: 'error' or 'aborted'. RUN_FINISHED has a new responseId field. TextAdapter has new optional provider and api fields.
    • When the next request goes to a different source, the adapter removes signatures and redacted thinking, turns readable thinking into text, and rewrites tool call IDs to the shape the target API accepts. Each call stays paired with its result.
    • Every request drops failed and aborted assistant batches and adds a No result provided result for an unanswered tool call. The saved history does not change.
    • RUN_FINISHED and RUN_ERROR metadata now merge onto the assistant messages of that model call in StreamProcessor.
    • Anthropic: the new allowEmptySignature option (default false) replays unsigned thinking from the same source, for gateways. The new provider option names a gateway.
    • Azure OpenAI reports the azure-openai-responses API.
    • Gemini, Mistral, and Bedrock Converse send same-source thinking back to the model, in block order.
    • withPersistence writes the source and the stop reason onto streaming snapshot rows.
    • Adapter authors get transformMessagesForReplay() and hashToolCallId() from @tanstack/ai/adapter-internals.
  • #1692 7532b2b - Send chat({ toolChoice }) to each provider.

    • Anthropic and Bedrock Converse. Claude Fable 5.1, Mythos 5.1, Opus 5.5, and Sonnet 5.5 reject a forced tool, and every Claude model rejects one while thinking is on. On those, 'required' and a named tool fall back to auto.
    • Bedrock Converse has no none. 'none' sends no tool config. Bedrock refuses tool calls in the history without a tool config, so the history goes out as text.
    • Gemini maps the choice to functionCallingConfig (AUTO, NONE, ANY, and allowedFunctionNames). With only provider tools, such as Google Search, it sends no tool config.
    • OpenAI and Azure OpenAI (Responses), Grok, Mistral, and OpenRouter (Chat Completions and Responses) send their own tool_choice shape.
  • Updated dependencies [1bfcee3, 412b0fe, a0150c2, b881627, fac0555, 6774e80, 5bd27f2, c20f7b0, cef1911, 51f72fb, 6f1e559, eb4eea0, cef1911, 7532b2b, 1bfcee3, 78edeb2, 44e3a0a, 7532b2b, 7a5c0d6, b881627]:

    • @tanstack/ai@0.69.0
    • @tanstack/ai-utils@0.4.2