Skip to content

feat(provider): add DeepSeek native web search - #2093

Merged
zerob13 merged 14 commits into
devfrom
feat/deepseek-web-search
Aug 6, 2026
Merged

feat(provider): add DeepSeek native web search#2093
zerob13 merged 14 commits into
devfrom
feat/deepseek-web-search

Conversation

@yyhhyyyyyy

@yyhhyyyyyy yyhhyyyyyy commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Add provider-native Web Search for DeepSeek V4 Flash through the official Responses API.
  • Route only search and compatible replay requests through Responses; ordinary requests retain the configured Chat Completions transport and endpoint.
  • Add a per-turn search toggle with visible search activity and clickable source links.
  • Support stateless multi-turn replay of DeepSeek search results.
  • Upgrade all existing AI SDK packages to their latest stable versions.

Implementation

  • Reuse the existing OpenAI Responses transport without adding a direct @ai-sdk/deepseek dependency.
  • Isolate DeepSeek protocol handling in a request-scoped replay adapter.
  • Preserve raw web_search_call payloads for replay and normalized search blocks for UI and export.
  • Force store: false and reject unresolved replay markers before sending requests.
  • Keep malformed persisted replay out of both history and in-flight tool rounds while retaining fail-closed wire validation for accepted markers.
  • Store versioned replay envelopes in existing assistant block metadata without database migrations.
  • Strip opaque replay payloads from streaming snapshots and paginated client reads while keeping durable storage intact.
  • Recover resume search intent from the closest persisted user record, including turns containing multiple assistant records.
  • Include replay payloads in context budgeting and trim replay-bearing turns atomically when required.
  • Send search: true only when explicitly enabled, preserving the existing payload shape otherwise.
  • Keep legacy MCP search blocks separate from provider-native search activity.
  • Open result links through the existing safe external-link path.

Validation

  • Format, i18n, lint, node typecheck, and web typecheck.
  • Full main suite: 6301 passed, 349 skipped.
  • Focused routing, replay, session projection, dispatch, and resume suite: 446 passed.
  • Local two-round conformance verifies raw web_search_call replay, store: false, no item_reference, and no continuation fields.
  • Real-key native-search canary confirms completed search and open_page items.
  • Blocking merge gate: run a real-key second independent user turn and confirm DeepSeek accepts the replayed web_search_call while retaining the first turn's searched context.

UI

Before:

Composer:  [+] [Mic] [Send]
Response:  Assistant text only

After:

Composer:  [+] [Web Search] [Mic] [Send]
Response:  Search activity
           Sources
           - Clickable source title
           - Clickable source title

Summary by CodeRabbit

  • New Features
    • Added native web search for supported DeepSeek V4 Flash models.
    • Added a capability-aware search toggle in chat.
    • Search activity displays status, actions, citations, and up to six source pages.
    • Search intent persists across queued, resumed, and multi-turn conversations.
  • Bug Fixes
    • Improved citation handling, URL safety, replay continuity, and context preservation.
  • Documentation
    • Added implementation plans, specifications, acceptance criteria, and task tracking.
  • Tests
    • Expanded coverage for routing, rendering, persistence, replay handling, and malformed data.

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds DeepSeek V4 Flash native web search through the OpenAI Responses transport. The change propagates search intent, normalizes streamed results, persists replay data, restores replay context across turns, adds capability-gated UI controls, and expands runtime and renderer coverage.

Changes

DeepSeek native search

Layer / File(s) Summary
Search contracts and input propagation
src/shared/*, src/main/session/data/*, src/main/agent/shared/*
Adds search input fields, provider search events, replay metadata, capability fields, and search preservation across send, queue, steer, and session flows.
Provider routing and stream projection
src/main/provider/deepseekResponsesAdapter.ts, src/main/provider/aiSdk/*, src/main/provider/providers/aiSdkProvider.ts
Routes eligible DeepSeek V4 Flash requests through OpenAI Responses. The adapter validates routes, rewrites replay requests, normalizes search output, and suppresses provider-owned tool events.
Runtime replay and persistence
src/main/agent/deepchat/runtime/*, src/main/session/*
Carries replay envelopes through turn execution, assistant dispatch, context construction, compaction, truncation, persistence, and resumed turns. Client projections remove opaque replay data from renderer messages.
Session search state and rendering
src/renderer/src/features/chat-page/*, src/renderer/src/pages/NewThreadPage.vue, src/renderer/src/components/*, src/renderer/src/stores/ui/*
Resolves provider search capability, stores session intent, preserves it during recovery, adds the toolbar toggle, and renders normalized search blocks and safe source links.
Validation and documentation
docs/features/deepseek-native-web-search/*, test/main/*, test/renderer/*
Adds the implementation plan, specification, task checklist, fixtures, and coverage for routing, replay, persistence, streaming, context fitting, input propagation, and rendering.
SDK versions
package.json
Updates AI SDK package ranges and upgrades ai from ^7.0.37 to ^7.0.54.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant ChatComposer
  participant DeepChatRuntime
  participant DeepSeekResponses
  participant SearchRenderer
  User->>ChatComposer: enable provider search
  ChatComposer->>DeepChatRuntime: submit search intent
  DeepChatRuntime->>DeepSeekResponses: send Responses request with web search
  DeepSeekResponses-->>DeepChatRuntime: return search events and replay data
  DeepChatRuntime-->>SearchRenderer: render normalized search block
  DeepChatRuntime->>DeepSeekResponses: replay retained search items on a later turn
Loading

Possibly related PRs

Suggested reviewers: zerob13

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 6.32% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding DeepSeek provider-native web search.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/deepseek-web-search

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/features/chat-page/composables/useComposerSubmit.ts (1)

403-416: 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Bind search intent to the submission target.

The code captures search before asynchronous work, but it does not retain the provider/model identity that enabled it. A provider or model change during attachment preparation, queued dispatch, or retry can send search: true to an unsupported target.

  • src/renderer/src/features/chat-page/composables/useComposerSubmit.ts#L403-L416: Emit search: true only after the active submission target matches the capability identity.
  • src/renderer/src/features/chat-page/composables/useComposerSubmit.ts#L520-L527: Store the capability provider and model identity with the submission seed.
  • src/renderer/src/features/chat-page/composables/useComposerSubmit.ts#L1100-L1105: Revalidate restored blocked-attempt payloads before retry.
  • src/renderer/src/pages/NewThreadPage.vue#L934-L942: Capture the selected model identity with the search intent.
  • src/renderer/src/pages/NewThreadPage.vue#L976-L983: Apply the same identity capture for command submission.
  • src/renderer/src/pages/NewThreadPage.vue#L1033-L1039: Resolve the final submission model before deciding whether to include search.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/renderer/src/features/chat-page/composables/useComposerSubmit.ts` around
lines 403 - 416, Bind search intent to the provider/model capability identity
throughout submission creation and retry. In
src/renderer/src/features/chat-page/composables/useComposerSubmit.ts:403-416,
include search only when the current submission target matches the captured
identity; at 520-527, store that provider and model identity in the submission
seed; and at 1100-1105, revalidate restored blocked-attempt payloads before
retry. In src/renderer/src/pages/NewThreadPage.vue:934-942 and 976-983, capture
the selected model identity with search intent, and at 1033-1039 resolve the
final submission model before deciding whether search is included.
🧹 Nitpick comments (2)
test/renderer/components/NewThreadPage.test.ts (1)

604-613: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Make the refresh assertion prove the flip came from resolveRefresh.

mockReturnValueOnce(refresh) covers only the next getCapabilities call. If the provider-change handler issues more than one capability request, the extra call falls back to the default mock, which returns { supportsAudioInput: true } and no supportsSearch. The waitFor at Line 613 can then observe false from the fallback response instead of from resolveRefresh. The test would still pass, and a regression in the in-flight refresh path would go undetected.

Pin the call count after the flip so the source of the change is unambiguous.

♻️ Proposed hardening
     resolveRefresh({ supportsAudioInput: false, supportsSearch: false })
     await vi.waitFor(() => expect((wrapper.vm as any).isSearchAvailable).toBe(false))
+    expect(modelClient.getCapabilities).toHaveBeenCalledTimes(previousRequestCount + 1)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/renderer/components/NewThreadPage.test.ts` around lines 604 - 613,
Strengthen the refresh assertions around emitProvidersChanged and resolveRefresh
so the test records the capability-request count after isSearchAvailable becomes
true, then verifies that resolving the in-flight refresh changes it to false
without any additional getCapabilities calls. Keep the existing provider-change
request-count assertion and ensure the final state transition is attributable
specifically to resolveRefresh.
test/main/provider/providerModelCapabilityMapping.test.ts (1)

441-447: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Assert supportsSearch for the relay route.

The relay case only checks that searchExecution is absent. Add an assertion for relaySnapshot.supportsSearch so the relay search toggle state is explicitly covered.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/main/provider/providerModelCapabilityMapping.test.ts` around lines 441 -
447, Update the relay-route test around getCapabilitySnapshot to store the
returned snapshot as relaySnapshot, then explicitly assert
relaySnapshot.supportsSearch matches the expected relay search-toggle state
while retaining the existing searchExecution absence assertion.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/main/agent/shared/agentSessionNormalization.ts`:
- Line 73: Update the string and invalid-input fallback returns in the
normalization function containing the `search: content.search === true` mapping
to include `search: false`, ensuring every normalized input exposes a boolean
`search` field consistent with object inputs.

---

Outside diff comments:
In `@src/renderer/src/features/chat-page/composables/useComposerSubmit.ts`:
- Around line 403-416: Bind search intent to the provider/model capability
identity throughout submission creation and retry. In
src/renderer/src/features/chat-page/composables/useComposerSubmit.ts:403-416,
include search only when the current submission target matches the captured
identity; at 520-527, store that provider and model identity in the submission
seed; and at 1100-1105, revalidate restored blocked-attempt payloads before
retry. In src/renderer/src/pages/NewThreadPage.vue:934-942 and 976-983, capture
the selected model identity with search intent, and at 1033-1039 resolve the
final submission model before deciding whether search is included.

---

Nitpick comments:
In `@test/main/provider/providerModelCapabilityMapping.test.ts`:
- Around line 441-447: Update the relay-route test around getCapabilitySnapshot
to store the returned snapshot as relaySnapshot, then explicitly assert
relaySnapshot.supportsSearch matches the expected relay search-toggle state
while retaining the existing searchExecution absence assertion.

In `@test/renderer/components/NewThreadPage.test.ts`:
- Around line 604-613: Strengthen the refresh assertions around
emitProvidersChanged and resolveRefresh so the test records the
capability-request count after isSearchAvailable becomes true, then verifies
that resolving the in-flight refresh changes it to false without any additional
getCapabilities calls. Keep the existing provider-change request-count assertion
and ensure the final state transition is attributable specifically to
resolveRefresh.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fbe381a3-e1b0-45a9-a1f0-7bce139ee45f

📥 Commits

Reviewing files that changed from the base of the PR and between 4b7b03b and 8663001.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (72)
  • docs/features/deepseek-native-web-search/plan.md
  • docs/features/deepseek-native-web-search/spec.md
  • docs/features/deepseek-native-web-search/tasks.md
  • package.json
  • src/main/agent/deepchat/runtime/accumulator.ts
  • src/main/agent/deepchat/runtime/compactionService.ts
  • src/main/agent/deepchat/runtime/contextBudget.ts
  • src/main/agent/deepchat/runtime/contextBuilder.ts
  • src/main/agent/deepchat/runtime/deepChatLoopRunner.ts
  • src/main/agent/deepchat/runtime/dispatch.ts
  • src/main/agent/deepchat/runtime/echo.ts
  • src/main/agent/deepchat/runtime/process.ts
  • src/main/agent/deepchat/runtime/providerReplaySegments.ts
  • src/main/agent/deepchat/runtime/turnCoordinator.ts
  • src/main/agent/shared/agentSessionNormalization.ts
  • src/main/provider/aiSdk/messageMapper.ts
  • src/main/provider/aiSdk/providerFactory.ts
  • src/main/provider/aiSdk/runtime.ts
  • src/main/provider/aiSdk/streamAdapter.ts
  • src/main/provider/deepseekResponsesAdapter.ts
  • src/main/provider/providers/aiSdkProvider.ts
  • src/main/provider/settings.ts
  • src/main/session/data/pendingInputStore.ts
  • src/main/session/data/pendingInputs.ts
  • src/main/session/data/userMessageContent.ts
  • src/renderer/src/components/chat/ChatInputToolbar.vue
  • src/renderer/src/components/message/MessageBlockActivityGroup.vue
  • src/renderer/src/components/message/MessageBlockSearch.vue
  • src/renderer/src/components/message/MessageItemAssistant.vue
  • src/renderer/src/components/message/messageActivityGroups.ts
  • src/renderer/src/features/chat-page/ChatPage.vue
  • src/renderer/src/features/chat-page/composables/useComposerSubmit.ts
  • src/renderer/src/features/chat-page/composables/usePendingInputActions.ts
  • src/renderer/src/pages/NewThreadPage.vue
  • src/renderer/src/stores/ui/message.ts
  • src/renderer/src/stores/ui/session.ts
  • src/shared/contracts/common.ts
  • src/shared/contracts/domainSchemas.ts
  • src/shared/contracts/routes/sessions.routes.ts
  • src/shared/types/agent-interface.d.ts
  • src/shared/types/core/chat-message.ts
  • src/shared/types/core/llm-events.ts
  • src/shared/types/model-capabilities.ts
  • src/shared/types/provider.ts
  • src/shared/utils/messageTokens.ts
  • test/fixtures/deepseekResponses.ts
  • test/main/agent/deepchat/harness/deepChatAgentHarness.test.ts
  • test/main/agent/deepchat/runtime/accumulator.test.ts
  • test/main/agent/deepchat/runtime/compactionService.test.ts
  • test/main/agent/deepchat/runtime/contextBudget.test.ts
  • test/main/agent/deepchat/runtime/contextBuilder.test.ts
  • test/main/agent/deepchat/runtime/echo.test.ts
  • test/main/agent/deepchat/runtime/process.test.ts
  • test/main/provider/aiSdkStreamAdapter.test.ts
  • test/main/provider/deepseekResponsesAdapter.test.ts
  • test/main/provider/openAIResponsesProvider.test.ts
  • test/main/provider/providerModelCapabilityMapping.test.ts
  • test/main/routes/modelCapabilitiesContract.test.ts
  • test/main/session/data/pendingInputStore.test.ts
  • test/main/session/data/tables/deepchatAssistantBlocks.test.ts
  • test/main/session/lifecycle.test.ts
  • test/renderer/components/ChatInputToolbar.test.ts
  • test/renderer/components/ChatPage.test.ts
  • test/renderer/components/NewThreadPage.test.ts
  • test/renderer/components/message/MessageBlockActivityGroup.test.ts
  • test/renderer/components/message/MessageBlockSearch.test.ts
  • test/renderer/components/message/MessageItemAssistant.test.ts
  • test/renderer/components/message/messageActivityGroups.test.ts
  • test/renderer/features/chat-page/composables/useComposerSubmit.test.ts
  • test/renderer/features/chat-page/composables/usePendingInputActions.test.ts
  • test/renderer/stores/messageStore.test.ts
  • test/renderer/stores/sessionStore.test.ts

Comment thread src/main/agent/shared/agentSessionNormalization.ts Outdated

@zhangmo8 zhangmo8 left a comment

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.

整体印象:设计克制(协议细节全部收在 deepseekResponsesAdapter 一个 adapter 里,runtime 只暴露窄 hook),测试覆盖面很扎实(路由矩阵、replay 隔离、SQLite 往返、两回合 conformance、renderer 分组都有),文档(plan/spec/tasks)写得非常完整,质量高于平均水平。

主要担心按优先级:

  1. 传输强制切换(aiSdkProvider 路由):所有官方端点上的 deepseek-v4-flash 请求都会被切到 /responses,与 search 开关无关,需确认兼容性与文档准确性;
  2. 发布门禁未关:spec 自认 real-key 二回合 replay canary pending,建议通过后再合;
  3. opaque envelope 会随消息加载下发到 renderer(echo 只剥流式快照),超大 payload 往返 IPC 值得处理;
  4. 若干健壮性/边界小问题(dispatch 损坏数据处理不一致、resume intent 推断边界、ChatPage 无关修复混入)。

详见行内评论。

Comment thread src/main/provider/providers/aiSdkProvider.ts
Comment thread docs/features/deepseek-native-web-search/spec.md
Comment thread src/main/agent/deepchat/runtime/echo.ts Outdated
Comment thread src/main/agent/deepchat/runtime/dispatch.ts Outdated
Comment thread src/main/agent/deepchat/runtime/turnCoordinator.ts Outdated
Comment thread src/main/agent/deepchat/runtime/contextBuilder.ts
Comment thread src/renderer/src/features/chat-page/ChatPage.vue

@zerob13 zerob13 left a comment

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.

Requesting changes before merge:

  • Complete the explicitly blocking real-key second-turn replay canary.
  • Make client projection fail closed for malformed or non-array assistant content containing opaque replay.
  • Remove call-arity-driven tuple mutation; tests should not dictate internal argument count.
  • Resolve the search-vs-tool-call count semantic.

Scope: split the unrelated Bedrock, Anthropic, Azure, Google, Vertex, and OpenAI-compatible package bumps unless version lockstep is required and documented. Keep the durable spec and protocol-boundary tests; after the canary, plan.md and tasks.md can be cleaned as implementation artifacts.

The latest commit correctly keeps ordinary V4 Flash traffic on Chat Completions and fixes valid replay redaction and in-flight replay projection.

Comment thread docs/features/deepseek-native-web-search/tasks.md
Comment thread src/main/session/clientMessageProjection.ts Outdated
Comment thread src/main/provider/providers/aiSdkProvider.ts Outdated
Comment thread src/renderer/src/components/message/messageActivityGroups.ts Outdated
Comment thread src/main/agent/deepchat/runtime/echo.ts Outdated
@yyhhyyyyyy
yyhhyyyyyy requested a review from zerob13 August 6, 2026 12:33
@zerob13
zerob13 merged commit d7c06db into dev Aug 6, 2026
15 checks passed
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.

3 participants