Skip to content

迁移 DeepSeek 集成到 V4 模型#219

Open
StevenZhu2003 wants to merge 2 commits into
Bistutu:mainfrom
StevenZhu2003:codex/deepseek-v4-migration
Open

迁移 DeepSeek 集成到 V4 模型#219
StevenZhu2003 wants to merge 2 commits into
Bistutu:mainfrom
StevenZhu2003:codex/deepseek-v4-migration

Conversation

@StevenZhu2003

@StevenZhu2003 StevenZhu2003 commented Jun 20, 2026

Copy link
Copy Markdown

概要

本 PR 将 DeepSeek 翻译集成迁移到 DeepSeek V4 模型命名,并修复当前仓库的 TypeScript 编译问题,便于后续手动测试与发布验证。

变更内容

  • 将 DeepSeek 模型选项更新为 deepseek-v4-flashdeepseek-v4-pro,保留自定义模型支持。
  • 为旧配置保留兼容映射:
    • deepseek-chat -> deepseek-v4-flash + 关闭 thinking
    • deepseek-reasoner -> deepseek-v4-pro + 开启 thinking
  • 按 DeepSeek 当前 Chat Completion / Thinking Mode 文档使用 thinking: { type: "enabled" | "disabled" }
  • DeepSeek 响应解析只渲染 choices[0].message.content,忽略 reasoning_content 等推理字段。
  • 统一过滤 <think>...</think> 内容,避免推理过程泄露到网页。
  • 添加 @types/chrome,修复 chrome 全局类型缺失。
  • 将直接依赖的 vite 对齐到 5.4.19,与 WXT 使用的 Vite 版本一致,修复 wxt.config.ts 插件类型不匹配。
  • 更新 DeepSeek 配置文档中的推荐模型名称。

验证

  • corepack pnpm compile:通过
  • corepack pnpm build:通过,生成 Chrome MV3 扩展,WXT 报告总大小约 1.97 MB
  • corepack pnpm lint:未通过,原因是仓库当前没有定义 lint script,也没有可执行的 lint 命令;本 PR 未新增或修改 lint 配置

Manifest 检查

  • manifest_version 为 3
  • 权限保持为 storagecontextMenusoffscreen
  • 未新增 host_permissions
  • 包含 background service worker 与 content script

兼容性说明

旧的 DeepSeek 模型名仅保留在迁移兼容逻辑中。新配置入口使用 V4 模型名,并继续支持自定义模型,避免未来 DeepSeek 新模型发布时阻塞用户配置。

Summary by Sourcery

Migrate the DeepSeek translation integration to the V4 chat/thinking model API while aligning build tooling and documentation.

New Features:

  • Support DeepSeek V4 models with explicit thinking mode configuration and reasoning effort in request payloads.

Bug Fixes:

  • Ensure DeepSeek responses only render final message content and consistently strip reasoning tags from translated output to avoid leaking internal reasoning.
  • Fix missing Chrome extension type definitions and Vite type mismatches to restore successful TypeScript compilation.

Enhancements:

  • Normalize legacy DeepSeek model names to their V4 equivalents to keep existing user configurations working without behavior changes.

Build:

  • Align the direct Vite dependency version with WXT to resolve configuration type compatibility issues.

Documentation:

  • Update DeepSeek translation engine documentation to recommend the new V4 model names.

@sourcery-ai

sourcery-ai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Reviewer's Guide

Migrates the DeepSeek translation integration to the V4 model family with explicit thinking mode handling, tightens DeepSeek response sanitization, and fixes TypeScript/build issues by adding Chrome types and aligning Vite versions, plus updates docs to recommend the new models.

File-Level Changes

Change Details Files
Update DeepSeek request payload construction to support V4 models and explicit thinking mode while preserving backward compatibility with legacy model names.
  • Introduce DeepSeekThinkingMode and DeepSeekModelConfig types to describe model and thinking mode together.
  • Normalize configured DeepSeek model names (strip Chinese brackets, map deepseek-chat to deepseek-v4-flash with thinking disabled, and deepseek-reasoner to deepseek-v4-pro with thinking enabled).
  • Build DeepSeek payloads using the normalized model plus top-level thinking: { type: 'enabled'
'disabled' } per current API docs.
  • Conditionally set reasoning_effort for thinking-enabled requests and temperature for non-thinking requests.
  • Harden DeepSeek response handling so only final content is rendered and model reasoning markup is always stripped from page output.
    • Replace direct access to result.choices[0].message.content with an extractDeepSeekContent helper that validates the response shape before processing.
    • Update contentPostHandler to remove all ... blocks case-insensitively and trim surrounding whitespace, ensuring no reasoning traces are shown.
    • Clarify in comments that DeepSeek reasoning fields (e.g., reasoning_content) are intentionally ignored and must not reach the page.
    entrypoints/service/deepseek.ts
    entrypoints/utils/check.ts
    Refresh DeepSeek-related configuration and documentation to use V4 model names while keeping custom model support.
    • Change DeepSeek model list for the service to deepseek-v4-flash and deepseek-v4-pro plus the custom-model sentinel.
    • Update translation engine docs to recommend deepseek-v4-flash as the default DeepSeek model.
    entrypoints/utils/option.ts
    docs/config/translation-engines.md
    Fix TypeScript/WebExtension build issues by adding Chrome type definitions and aligning Vite to the version used by WXT.
    • Add @types/chrome as a devDependency so the global chrome object is properly typed.
    • Bump Vite devDependency from 5.4.11 to 5.4.19 to match WXT and eliminate wxt.config.ts plugin type mismatches.
    • Regenerate pnpm-lock.yaml to reflect the new devDependency versions.
    package.json
    pnpm-lock.yaml

    Tips and commands

    Interacting with Sourcery

    • Trigger a new review: Comment @sourcery-ai review on the pull request.
    • Continue discussions: Reply directly to Sourcery's review comments.
    • Generate a GitHub issue from a review comment: Ask Sourcery to create an
      issue from a review comment by replying to it. You can also reply to a
      review comment with @sourcery-ai issue to create an issue from it.
    • Generate a pull request title: Write @sourcery-ai anywhere in the pull
      request title to generate a title at any time. You can also comment
      @sourcery-ai title on the pull request to (re-)generate the title at any time.
    • Generate a pull request summary: Write @sourcery-ai summary anywhere in
      the pull request body to generate a PR summary at any time exactly where you
      want it. You can also comment @sourcery-ai summary on the pull request to
      (re-)generate the summary at any time.
    • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
      request to (re-)generate the reviewer's guide at any time.
    • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
      pull request to resolve all Sourcery comments. Useful if you've already
      addressed all the comments and don't want to see them anymore.
    • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
      request to dismiss all existing Sourcery reviews. Especially useful if you
      want to start fresh with a new review - don't forget to comment
      @sourcery-ai review to trigger a new review!

    Customizing Your Experience

    Access your dashboard to:

    • Enable or disable review features such as the Sourcery-generated pull request
      summary, the reviewer's guide, and others.
    • Change the review language.
    • Add, remove or edit custom review instructions.
    • Adjust other review settings.

    Getting Help

    @sourcery-ai sourcery-ai Bot left a comment

    Copy link
    Copy Markdown

    Choose a reason for hiding this comment

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

    Hey - I've found 1 issue, and left some high level feedback:

    • In deepseekMsgTemplate and extractDeepSeekContent, consider replacing the any payload/response types with a minimal typed interface for the DeepSeek request/response shape so that future changes to the API are caught at compile time rather than runtime.
    • The comments that reference specific future dates (e.g., DeepSeek docs checked on 2026-06-20 and deprecation scheduled for 2026-07-24) may age quickly; it would be more maintainable to either reference the relevant documentation URL or describe behavior in a timeless way and leave deprecation timing to release notes.
    Prompt for AI Agents
    Please address the comments from this code review:
    
    ## Overall Comments
    - In `deepseekMsgTemplate` and `extractDeepSeekContent`, consider replacing the `any` payload/response types with a minimal typed interface for the DeepSeek request/response shape so that future changes to the API are caught at compile time rather than runtime.
    - The comments that reference specific future dates (e.g., DeepSeek docs checked on 2026-06-20 and deprecation scheduled for 2026-07-24) may age quickly; it would be more maintainable to either reference the relevant documentation URL or describe behavior in a timeless way and leave deprecation timing to release notes.
    
    ## Individual Comments
    
    ### Comment 1
    <location path="entrypoints/utils/check.ts" line_range="101-102" />
    <code_context>
    -    return content;
    -}
    \ No newline at end of file
    +    // Never render model reasoning tags in translated page content.
    +    return text.replace(/<think>[\s\S]*?<\/think>/gi, "").trim();
    +}
    </code_context>
    <issue_to_address>
    **suggestion (bug_risk):** The added `trim()` may unintentionally alter intentional leading/trailing whitespace or layout.
    
    The previous handler only removed the `<think>...</think>` block and preserved surrounding whitespace. Now you both globally replace and call `trim()`. The global replace seems fine, but `trim()` changes output semantics (e.g., stripping final newlines or leading spaces important for markdown/preformatted text). If that formatting is user-visible, consider dropping `trim()` or limiting whitespace cleanup to the reasoning tags only.
    </issue_to_address>

    Sourcery is free for open source - if you like our reviews please consider sharing them ✨
    Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

    Comment on lines +101 to +102
    // Never render model reasoning tags in translated page content.
    return text.replace(/<think>[\s\S]*?<\/think>/gi, "").trim();

    Copy link
    Copy Markdown

    Choose a reason for hiding this comment

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

    suggestion (bug_risk): The added trim() may unintentionally alter intentional leading/trailing whitespace or layout.

    The previous handler only removed the <think>...</think> block and preserved surrounding whitespace. Now you both globally replace and call trim(). The global replace seems fine, but trim() changes output semantics (e.g., stripping final newlines or leading spaces important for markdown/preformatted text). If that formatting is user-visible, consider dropping trim() or limiting whitespace cleanup to the reasoning tags only.

    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