WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@syjcnss
Copy link

@syjcnss syjcnss commented Nov 29, 2025

Background

The PR #10523 missed two stream events: custom_tool_call_input.delta and custom_tool_call_input.done.

The following testcase will trigger an error:

import { xai } from '@ai-sdk/xai';
import { streamText } from 'ai';

const { fullStream, usage: usagePromise } = streamText({
  model: xai.responses('grok-4-1-fast-reasoning'),
  system: 'You are a news reporter.',
  tools: {
    x_search: xai.tools.xSearch(),
  },
  prompt: 'search for the latest news in x',
});

const sources = new Set<string>();
let lastToolName = '';

for await (const event of fullStream) {
  switch (event.type) {
    case 'tool-call':
      lastToolName = event.toolName;
      if (event.providerExecuted) {
        console.log(`[Calling ${event.toolName} on server...]`);
      }
      break;

    case 'tool-result':
      console.log(`[${lastToolName} completed]`);
      break;

    case 'text-delta':
      process.stdout.write(event.text);
      break;

    case 'source':
      if (event.sourceType === 'url') {
        sources.add(event.url);
      }
      break;
  }
}

const usage = await usagePromise;
console.log(`\nSources used: ${sources.size}`);
console.log(`Token usage: ${usage.inputTokens} input, ${usage.outputTokens} output`);
_TypeValidationError [AI_TypeValidationError]: Type validation failed: Value: {"sequence_number":3,"type":"response.custom_tool_call_input.delta","item_id":"ctc_aa40f122-e87a-c188-7593-50d15babb0a0_xs_call_31945317","output_index":0,"delta":"{\"query\":\"filter:news\",\"limit\":20,\"mode\":\"Latest\"}"}.

Summary

Fixed the error by adding the missed events.

Manual Verification

Ran the above test case again and saw it pass.

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

#10523

@syjcnss
Copy link
Author

syjcnss commented Dec 2, 2025

Closing it because #10765 does the samething.

@syjcnss syjcnss closed this Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant