Skip to content

feat(zai): add Web Search in Chat integration for Z.AI provider - #5

Closed
oldschoola wants to merge 0 commit into
mainfrom
feat/zai-web-search-in-chat
Closed

feat(zai): add Web Search in Chat integration for Z.AI provider#5
oldschoola wants to merge 0 commit into
mainfrom
feat/zai-web-search-in-chat

Conversation

@oldschoola

Copy link
Copy Markdown
Owner

Summary

Adds Z.AI's built-in Web Search in Chat feature to the Anthropic-compatible chat completions pipeline. When enabled, a web_search tool is injected into requests to Z.AI endpoints, allowing the model to search the web natively and return cited answers.

What it does

  • Injects web_search_20250305 built-in tool into requests when the model targets a Z.AI Anthropic-compatible endpoint and zai.webSearchInChat is enabled
  • Handles response blocks: server_tool_use (search tool calls), web_search_tool_result (Anthropic native), and tool_result (Z.AI's format for search results)
  • Parses search results from Z.AI's JSON content and formats them as readable links with titles
  • Settings: zai.webSearchInChat (enable/disable), zai.webSearchCount (1-50 results), zai.webSearchRecency (time range filter)

Files changed

File Change
packages/ai/src/providers/anthropic-wire.ts Added ServerToolUseBlockParam, WebSearchResultItem, WebSearchToolResultBlockParam types
packages/ai/src/providers/anthropic.ts Added ZaiWebSearchConfig type, tool injection in buildParams, stream handler for new block types
packages/ai/src/stream.ts Pass zaiWebSearch through mapOptionsForApi
packages/ai/src/types.ts Added zaiWebSearch to SimpleStreamOptions
packages/coding-agent/src/config/settings-schema.ts Added zai.webSearchInChat, zai.webSearchCount, zai.webSearchRecency settings
packages/coding-agent/src/sdk.ts Wired settings to streamFn options

Testing

Verified with Z.AI API key:

  • ✅ Direct Web Search REST API works
  • ✅ Anthropic-compatible endpoint accepts web_search_20250305 tool
  • ✅ Streaming returns text, server_tool_use, tool_result blocks
  • tool_result content is JSON with search results (title, link, content, refer)
  • ✅ TypeScript compiles with zero new errors
  • ✅ Biome formatting passes

Usage

Set in settings or via env:

zai.webSearchInChat: true
zai.webSearchCount: 5        # optional, default 5
zai.webSearchRecency: noLimit # optional, default noLimit

Requires ZAI_API_KEY to be set.

@oldschoola
oldschoola force-pushed the feat/zai-web-search-in-chat branch 3 times, most recently from 428bd23 to 26a23dc Compare June 4, 2026 04:49
@oldschoola oldschoola closed this Jun 4, 2026
@oldschoola
oldschoola force-pushed the feat/zai-web-search-in-chat branch from 26a23dc to 2b50e06 Compare June 4, 2026 05:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant