Skip to content

fix: upgrade xAI web search from deprecated Live Search to Responses API#12812

Merged
kangfenmao merged 11 commits intoCherryHQ:mainfrom
PhoenixCPH:main
Mar 12, 2026
Merged

fix: upgrade xAI web search from deprecated Live Search to Responses API#12812
kangfenmao merged 11 commits intoCherryHQ:mainfrom
PhoenixCPH:main

Conversation

@PhoenixCPH
Copy link
Copy Markdown
Contributor

@PhoenixCPH PhoenixCPH commented Feb 8, 2026

What this PR does

Upgrades @ai-sdk/xai from 2.0.36 to 2.0.56 and migrates xAI web search from the deprecated Live Search (provider options) approach to the Responses API with tool-based web search (xai.tools.webSearch() + xai.tools.xSearch()).

Before this PR:

  • xAI web search used the deprecated Live Search approach via searchParameters provider options
  • No support for xSearch (X/Twitter post search)
  • X.com citation links showed raw URLs with no tweet content preview

After this PR:

  • xAI provider uses xai.responses(modelId) with xai.tools.webSearch() and xai.tools.xSearch()
  • X/Twitter post search results are displayed in the chat UI via x_search tool rendering
  • Citation tooltips and the citation panel show tweet content via oEmbed API (publish.x.com/oembed)
  • isXPostUrl handles all hostname variants (x.com, www.x.com, twitter.com, www.twitter.com)

Why we need it and why it was done in this way

xAI deprecated the Live Search approach in favor of the Responses API with explicit tool calls. This migration:

  • Adopts the new xai.responses() + xai.tools.webSearch() / xai.tools.xSearch() pattern
  • Simplifies web search config to use only excludedDomains (max 5)
  • Adds proper citation rendering for X/Twitter posts using the oEmbed API, consistent between CitationTooltip.tsx and CitationsList.tsx

The following tradeoffs were made:

  • oEmbed data is fetched via a separate useQuery (cache key ['xOembed', url]) shared across components to avoid duplicate requests while keeping the author display title reliable (no string parsing from truncated content)

Breaking changes

None. The migration is transparent to users — web search continues to work with the same UI, now with richer X/Twitter citation support.

Special notes for your reviewer

  • The webSearchSource detection was updated to handle xAI's Responses API behavior where providerMetadata may be empty — falls back to providerId
  • normalizeCitationMarks now handles the [[N]](url) format from GROK
  • GROK citation formatting falls back to hostname when title is just a number

Checklist

Release note

Upgrade xAI web search to Responses API with xSearch support and rich X/Twitter citation previews

Upgrade @ai-sdk/xai from 2.0.36 to 2.0.56 and switch xAI provider to use the Responses API with tool-based web search instead of the deprecated Live Search approach using provider options.

Changes:
- Upgrade @ai-sdk/xai to 2.0.56 (ai-v5 compatible)
- Switch xAI provider to use xai.responses(modelId) by default
- Change web search plugin from searchParameters to xai.tools.webSearch()
- Simplify xAI web search config to use only excludedDomains (max 5)
- Remove unused createXaiOptions function
- Update tests to match new config format

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@PhoenixCPH
Copy link
Copy Markdown
Contributor Author

Hi maintainers, this PR is ready for review. Could someone please take a look

Copy link
Copy Markdown
Collaborator

@GeorgeDong32 GeorgeDong32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ PR Review Comments

This PR correctly implements the migration from deprecated xAI Live Search API to the new Responses API. The code quality is excellent with reduced complexity and better performance.

However, there are two documentation issues that should be addressed before merging:


1. Breaking changes not fully documented

The PR introduces breaking changes (default configuration changes), but the "Breaking changes" section in the PR description is empty.

Suggestion: Add the following to the PR description:

### Breaking changes

- xAI web search default configuration changed from using `searchParameters` to `xai.tools.webSearch()`
- Previous default settings (returnCitations, maxSources, sources) are no longer applied by default
- Users requiring custom xAI search behavior should update their web search configuration

2. Release Note missing

The PR description has an empty Release Note, but this is a user-visible feature change.

Suggestion: Add a Release Note:

```release-note
Upgraded xAI provider to use the new Responses API with tool-based web search.
The deprecated Live Search approach has been removed.
xAI web search now uses `xai.tools.webSearch()` with simplified configuration.

---

**Overall**: The code changes are good and ready to merge. Please update the PR description with the missing documentation sections.

@GeorgeDong32 GeorgeDong32 requested review from DeJeune and EurFelux and removed request for EurFelux February 8, 2026 15:58
Comment thread src/renderer/src/aiCore/utils/websearch.ts
Copy link
Copy Markdown
Collaborator

@EurFelux EurFelux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

整体来看,这个 PR 将 xAI web search 从已弃用的 Live Search (provider options 方式) 迁移到 Responses API (tool-based 方式),方向正确,代码质量良好。

👍 做得好的地方

  • 类型系统升级: XAISearchConfigProviderOptionsMap['xai']['searchParameters'] 改为 Parameters<typeof xai.tools.webSearch>[0],直接从 SDK 推导类型,更安全也更易维护
  • 一致性: xAI 现在和 OpenAI、Anthropic、Google 一样使用 applyToolBasedSearch,而不是走 applyProviderOptionsSearch 的特殊路径
  • 清理干净: createXaiOptions 删除后无残留引用,ProviderOptionsMap 的导入也一并清理
  • 测试更新: 测试用例完整覆盖了新的配置格式(空配置、有 excludeDomains、超过 5 个域名截断)
  • 符合 API 文档: xAI Responses API 的 web_search tool 确实只支持 excludedDomains / allowedDomains(最多 5 个),代码实现与官方文档一致

⚠️ 需要关注的点

  1. 所有 xAI 模型默认走 Responses APIschemas.ts 中将 languageModel 重定向到 provider.responses(modelId),这是一个全局行为变更,需要确认所有 xAI 模型都支持 Responses API
  2. maxResults 对 xAI 不再生效 — 用户之前配置的搜索结果数量限制会被静默忽略,建议在代码中加个注释说明原因
  3. PR 描述的 Breaking Changes 和 Release Note 部分为空 — 同意 @GeorgeDong32 的建议,应补充这些信息

📝 Minor

  • excludeDomains.slice(0, 5) 比之前的 excludeDomains.slice(0, Math.min(excludeDomains.length, 5)) 更简洁 👌

Comment thread packages/aiCore/src/core/providers/schemas.ts Outdated
maxSearchResults: 5,
sources: [{ type: 'web' }, { type: 'x' }, { type: 'news' }]
},
xai: {},
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observation: Default xAI web search config is now empty

The old default config had explicit settings:

xai: {
  mode: 'on',
  returnCitations: true,
  maxSearchResults: 5,
  sources: [{ type: 'web' }, { type: 'x' }, { type: 'news' }]
}

Now it's just xai: {}. This delegates all behavior to xAI's server-side defaults for the Responses API web_search tool, which is cleaner — but it means users lose the ability to control maxSearchResults and source types (web, x, news) that were previously configurable.

Is this intentional? The xAI Responses API web_search tool currently only supports excludedDomains and allowedDomains as parameters, so this simplification aligns with the new API surface. Just flagging the behavioral difference.

Comment thread src/renderer/src/aiCore/utils/websearch.ts Outdated
@PhoenixCPH
Copy link
Copy Markdown
Contributor Author

PhoenixCPH commented Feb 9, 2026

Note

This comment was translated by Claude.

Hey friends, could a real person please review my PR? Why are all the reviews from AI?


Original Content

朋友们,有没有真人review一下我的pr,怎么都是AI在review

@DeJeune
Copy link
Copy Markdown
Collaborator

DeJeune commented Feb 9, 2026

Note

This comment was translated by Claude.

After upgrading to the response API, the xAI provider type needs to be modified.


Original Content

升级成response api之后,需要修改xai的provider 类型

@DeJeune
Copy link
Copy Markdown
Collaborator

DeJeune commented Feb 9, 2026

Note

This comment was translated by Claude.

It still shows chat/completion here.


Original Content

这里还显示的是 chat/completion

@DeJeune DeJeune self-assigned this Feb 16, 2026
DeJeune and others added 4 commits March 3, 2026 13:50
Resolve @ai-sdk/* package version conflicts by adopting main's v3/v4
versions while preserving the PR's xAI Responses API wrapper.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Register both webSearch and xSearch tools when xAI provider is used,
enabling X/Twitter post search alongside web search. Update config
types and tests accordingly.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add x_search (and non-prefixed web_search) to the tool renderer
so xAI provider search results are visible in the message view.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Fix webSearchSource falling back to 'ai-sdk' for xAI by passing
  providerId to AiSdkToChunkAdapter as fallback when providerMetadata
  is empty (xAI responses API behavior)
- Add 'xai' -> GROK mapping in sourceMap for provider identification
- Split GROK and OPENROUTER citation formatting in messageBlock.ts;
  GROK now falls back to hostname when title is just a number
- Add GROK case in normalizeCitationMarks to handle [[N]](url) format
- Add X oEmbed API integration (publish.x.com/oembed) for fetching
  tweet content in citation tooltips and citation panel
- Enrich CitationTooltip with lazy oEmbed loading for x.com post URLs

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@DeJeune DeJeune requested a review from 0xfullex as a code owner March 9, 2026 19:36
@DeJeune DeJeune requested a review from EurFelux March 10, 2026 04:13
Copy link
Copy Markdown
Collaborator

@GeorgeDong32 GeorgeDong32 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Summary

This PR correctly implements the migration from deprecated xAI Live Search API to the new Responses API with tool-based web search. The code quality is excellent.

Strengths

  • Type system upgrade: Uses SDK-derived types instead of manual type definitions
  • API consistency: xAI now uses applyToolBasedSearch like other providers
  • Clean removal: createXaiOptions deleted without residual references
  • Complete tests: New config format fully covered
  • Good fallback handling: providerId fallback in AiSdkToChunkAdapter
  • User experience: X oEmbed API integration for tweet content display

Minor Fix Needed

One small issue: The migration log says "migrate 199 error" but should say "migrate 200 error" in src/renderer/src/store/migrate.ts:3267. This doesn't affect functionality.

Verdict

Approved - Ready to merge.

Comment thread src/renderer/src/store/migrate.ts Outdated
Copy link
Copy Markdown
Collaborator

@EurFelux EurFelux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow-up Review

在之前几位 reviewer 的基础上补充一些发现喵~

整体评价

PR 的核心变更(从 Live Search 迁移到 Responses API)是正确的方向,代码质量良好。同意 @GeorgeDong32@DeJeune 的 approval。

新发现

  1. CitationsList.tsx 中的 displayTitle 逻辑有隐患 — 用 fetchedContent.split(':')[0] 从已拼接+截断的字符串中反向提取 author 不够可靠。建议参考 CitationTooltip.tsx 的做法,直接用 oembedData 获取 author。

  2. isXPostUrl 缺少 www.twitter.com — 小问题但会导致部分旧 Twitter 链接不被识别。

  3. migrate.ts 的 typo — 同意 @GeorgeDong32 的发现,'migrate 199 error' 应该改为 'migrate 200 error'

已确认没有问题的点

  • customProvider...provider spread 保留了 textEmbeddingModelimageModel 等方法
  • AiSdkToChunkAdapterproviderId 参数位置正确(第 7 个参数)
  • ✅ web search tool 的 applyToolBasedSearch 调用方式与 OpenAI/Anthropic/Google 一致
  • ✅ Citation 格式化中 GROK case 与 OPENROUTER case 正确分离
  • ✅ Grok citation mark 格式 [[N]](url) 的正则处理正确
  • ✅ 测试覆盖完整

Comment thread src/renderer/src/pages/home/Messages/CitationsList.tsx Outdated
Comment thread src/renderer/src/utils/fetch.ts Outdated
Comment thread packages/aiCore/src/core/providers/schemas.ts
DeJeune and others added 2 commits March 11, 2026 02:02
Avoid reverse-parsing author from concatenated+truncated fetchedContent
string via split(':'), which breaks if author name or tweet text contains
colons. Use a dedicated oEmbed query (matching CitationTooltip.tsx pattern)
to derive displayTitle reliably.

Also handle www.twitter.com in isXPostUrl by stripping the www prefix.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: suyao <[email protected]>
@DeJeune DeJeune requested a review from EurFelux March 10, 2026 18:04
@DeJeune DeJeune added this to the v1.7.25 milestone Mar 10, 2026
CitationTooltip now uses useQuery for oEmbed data, so tests need
a QueryClientProvider wrapper to avoid "No QueryClient set" errors.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Signed-off-by: suyao <[email protected]>
@DeJeune DeJeune added the ready-to-merge This PR has sufficient reviewer approvals but is awaiting code owner approval. label Mar 10, 2026
@EurFelux
Copy link
Copy Markdown
Collaborator

test failed

@kangfenmao kangfenmao merged commit 2bbf09b into CherryHQ:main Mar 12, 2026
7 checks passed
@kangfenmao kangfenmao mentioned this pull request Mar 13, 2026
6 tasks
kangfenmao added a commit that referenced this pull request Mar 13, 2026
### What this PR does

Before this PR:
- Version is 1.7.24

After this PR:
- Version is 1.7.25
- Release notes updated in `electron-builder.yml`

### Why we need it and why it was done in this way

Standard release workflow: collect commits since v1.7.24, generate
bilingual release notes, bump version.

The following tradeoffs were made:
N/A

The following alternatives were considered:
N/A

### Breaking changes

**Action Required**: The built-in filesystem MCP server now requires
manual approval for write/edit/delete operations by default.

### Special notes for your reviewer

**Included commits since v1.7.24:**

✨ New Features:
- feat(websearch): add Querit search provider (#13050)
- feat(minapp,provider): add MiniMax Agent, IMA mini apps and MiniMax
Global, Z.ai providers (#13099)
- feat(provider): add agent support filter for provider list (#11932)
- feat(agent): add custom environment variables to agent configuration
(#13357)
- feat: add GPT-5.4 support (#13293)
- feat(gemini): add thought signature persistence (#13100)

🐛 Bug Fixes:
- fix: secure built-in filesystem MCP root handling (#13294)
- fix: check underlying tool permissions for hub invoke/exec (#13282)
- fix: remove approval countdown timers and add system notifications
(#13281)
- fix: agent tool status not stopping on abort (#13111)
- fix: resolve spawn ENOENT on Windows for Code Tools (#13405)
- fix: Use default assistant for topic auto-renaming (#13387)
- fix(backup): defer auto backup during streaming response (#13307)
- fix(ui): fix Move To submenu overflow (#13399)
- fix: render xml fenced svg blocks as svg previews (#13431)
- fix: correct Gemini reasoning params (#13388)
- fix: improve Qwen 3.5 reasoning model detection (#13235)
- fix: upgrade xAI web search to Responses API (#12812)
- fix(api-server): relax chat completion validation (#13279)
- fix: install or uninstall button state issues (#13114)
- fix: improve update dialog behavior (#13363)
- fix: auto-convert reasoning_effort to reasoningEffort (#12831)

### Checklist

- [x] PR: The PR description is expressive enough and will help future
contributors
- [x] Code: Write code that humans can understand and Keep it simple
- [x] Refactor: You have left the code cleaner than you found it (Boy
Scout Rule)
- [x] Upgrade: Impact of this change on upgrade flows was considered and
addressed if required
- [x] Documentation: A user-guide update was considered and is present
(link) or not required.
- [x] Self-review: I have reviewed my own code before requesting review
from others

### Release note

```release-note
See release notes in electron-builder.yml
```

---------

Signed-off-by: kangfenmao <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge This PR has sufficient reviewer approvals but is awaiting code owner approval.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants