dsh-plugin-smart-config:DSH 下的模型智能配置與參數適配

前言

在 DeepSeek Harness(dsh)裏接多家模型時,上下文窗口、工具調用、推理檔位、協議差異往往要手工查文檔再寫進 provider 配置。模型一換、中轉站一改,就容易出現 400 或能力與請求體不一致。dsh-plugin-smart-config 把自 ZCode 逆向並移植的「推薦配置引擎」做成標準 Cordis 插件,用分層規則匹配和字段級繼承,把能力寫進 llm-pi-ai 檔案,由 pi-ai 在發請求前讀取,而不是在運行中改已凍結的 Agent 請求體。

這是什麼

維護者 TACONailoong 在 GitHub 發佈 dsh-plugin-smart-config(npm 包名同:dsh-plugin-smart-config,當前版本 1.1.1,MIT)。社區目錄分類爲「模型推理」,簡介爲:DeepSeek Harness plugin for model smart configuration and parameter adaptation ported from ZCode。

插件面向 dsh >=0.2.0-rc.2 <0.2.1-0;裝好後通過 cordis.patch.yml 掛上 bundle 名 smart-config。

核心功能

五層級聯推薦匹配

規則從精確到兜底依次疊加,最終得到 effectiveConfig:

  1. L5 直配:exactModelRules(providerId + modelId)、templateModelRules(模板 + modelId)。
  2. L2 模型族:modelRules 正則(如 GLM、DeepSeek、Claude、Kimi 等)。
  3. L3 協議:modelApiRules,區分 anthropic-messages、openai-chat-completions、openai-responses。
  4. L4 站點:providerSiteRules,按 baseUrl 與 apiType 識別供應商或中轉(README 舉例含 OpenCode、阿里雲百鍊、智譜等)。
  5. L1 全局:modelRules: .* 提供缺省上限與上下文底座。

Exact 規則若爲 manual-provider-model 則僅用手動配置、斷開推薦;若爲 provider-model 則繼承推薦併疊加個人覆寫。

字段級智能差分繼承

開啓智能配置後,用戶未改動的字段跟隨雲端/官方推薦迭代;手動改過的單項固化爲覆寫,其餘仍動態繼承。

能力守衛與請求參數轉譯

  • 不支持 Tool Calling 時攔截並去掉 tools,避免 400。
  • 校驗多模態(圖像/視頻/PDF)能力並提示。
  • 將通用 reasoning_effort 映射到各模型請求結構(如 Claude thinking.type、DeepSeek enable_thinking、OpenAI reasoning_effort 等)。編程式轉譯在 adapter.ts;dsh 0.2 的 Agent 請求凍結,插件不改運行中請求體。

離線規則庫與雲端同步

內置 Revision 30 本地規則(README 稱約 20+ 模板、84+ 模型規則、72+ 協議規則、52+ 站點規則),並支持後臺輪詢服務端、租約機制拉取更新。

寫回 dsh 0.2.0-rc.2 的 llm-pi-ai

  • 只補 llm-pi-ai 裏已有模型的缺失字段:contextWindow、input、reasoningEfforts(經 settings.mutate);不寫 maxTokens(0.2.0-rc.2 中該字段表示每次請求默認輸出上限)。
  • models 省略或爲空時不改動,繼續用安裝包內 pi-ai 模型目錄。
  • 宿主上的 openai-completions 會先映射爲規則庫中的 openai-chat-completions,以便 OpenCode 等站點規則命中。
  • 思考檔位僅使用 0.2 接受的 off、minimal、low、medium、high、xhigh、max;thinkingFormat 隨規則映射(reasoning_effort → openai,enable_thinking → deepseek)。
  • 已有值的字段(含用戶修改與目錄自帶)保持不變。

OpenCode 請求頭

在對應 provider 的 headers 寫入 User-Agent: opencode/1.0.0、x-opencode-client: opencode;不改 globalThis.fetch。

安裝與啓用

作爲 npm 包開發或獨立使用

npm install dsh-plugin-smart-config

(README 亦給出 pnpm add、yarn add 等價命令。)

裝進 DeepSeek Harness

在目標 profile(示例爲 web)下添加插件:

dsh plugin --profile web add dsh-plugin-smart-config

本地開發可 link(路徑按本機替換):

dsh plugin --profile web add "link:D:/path/to/dsh-plugin-smart-config"

安裝前請確認 dsh 版本落在 peer 依賴區間;插件以當前 dsh 進程權限運行,安裝前應自行查看源碼與 MIT 許可證。

典型用法

本地測試與演示(Node.js 22+)

先構建再跑測試或交互 demo:

npm test
npm run demo
npm run demo -- glm-5.3-flash openai-chat-completions https://opencode.ai/zen/go/v1

編程式解析推薦配置

不掛 dsh 時也可在 Node/TS 中調用 SmartConfigService:

import { SmartConfigService } from 'dsh-plugin-smart-config';

const service = new SmartConfigService();

const result = service.resolve({
  modelId: 'deepseek-chat',
  apiType: 'openai-chat-completions',
});

console.log(result.effectiveConfig);

返回結構含 properties(如 contextWindow、supportsToolCall、inputFormat)與 optionSpecs(如 maxOutputTokens、reasoningLevel 等約束)。

適用場景與注意

適合:在 dsh 0.2.0-rc.2 線路上維護多 provider、多模型,希望減少手工查規格、統一推理檔位與協議差異的開發者;需要與 ZCode 同源推薦邏輯、並希望在 DSH 內通過 pi-ai 檔案生效的團隊。

注意:

  • 模型須先出現在該 provider 的 models 列表中才會被檔案補丁;列表爲空則依賴 pi-ai 自帶目錄。
  • 0.2.1-alpha 不在同一 peer 線,勿假設兼容。
  • 社區插件目錄 SkillHub 條目 爲獨立站點,與 DeepSeek / 幻方無官方從屬關係。

結尾

dsh-plugin-smart-config 把 ZCode 側的五層規則、字段繼承與能力守衛移植到 DSH Cordis 生態,重點是把模型能力同步進 llm-pi-ai,而不是篡改凍結請求。進一步細節見 GitHub 倉庫 與 SkillHub 目錄頁。

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

小夜