前言¶
在 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:
- L5 直配:
exactModelRules(providerId + modelId)、templateModelRules(模板 + modelId)。 - L2 模型族:
modelRules正则(如 GLM、DeepSeek、Claude、Kimi 等)。 - L3 协议:
modelApiRules,区分anthropic-messages、openai-chat-completions、openai-responses。 - L4 站点:
providerSiteRules,按baseUrl与apiType识别供应商或中转(README 举例含 OpenCode、阿里云百炼、智谱等)。 - L1 全局:
modelRules: .*提供缺省上限与上下文底座。
Exact 规则若为 manual-provider-model 则仅用手动配置、断开推荐;若为 provider-model 则继承推荐并叠加个人覆写。
字段级智能差分继承¶
开启智能配置后,用户未改动的字段跟随云端/官方推荐迭代;手动改过的单项固化为覆写,其余仍动态继承。
能力守卫与请求参数转译¶
- 不支持 Tool Calling 时拦截并去掉
tools,避免 400。 - 校验多模态(图像/视频/PDF)能力并提示。
- 将通用
reasoning_effort映射到各模型请求结构(如 Claudethinking.type、DeepSeekenable_thinking、OpenAIreasoning_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 目录页。