dsh-opencode-session:为 opencode / opencode-go 补上 x-opencode-session 头

前言

在 DeepSeek Harness(dsh)里走 opencode 或 opencode-go 模型时,若 Console Go 网关已要求会话头,常见报错是 400 MissingSessionID:请求缺少 x-opencode-session,网关无法把流量路由到持有该会话缓存的节点。pi 编码代理在 provider 层会带上该头;dsh 经 @earendil-works/pi-ai 访问同一路由时,库侧尚未实现该头,因此问题往往只出现在 dsh 侧。下面介绍社区插件 dsh-opencode-session(维护者 BrackRat,分类:联网工具),在 dsh 进程内为相关请求自动补全会话头,恢复与 pi 侧相近的行为。

这是什么

dsh-opencode-session 是 dsh 的兼容型插件 bundle:不改动磁盘上的凭证或配置文件,在内存里通过 llm/stream 中间件包装 pi-ai 的 Models 原型,对命中 opencode 路由的请求注入 x-opencode-session 与 x-opencode-client: dsh。包版本为 0.1.0,许可证 MIT,要求 dsh >= 0.1.5-rc.1、Node >= 18。README 在 dsh 0.1.5-rc.1 与 @earendil-works/pi-ai 0.85.1 上做过验证(含 opencode-go、openai-completions 协议)。

核心功能

  1. 消除 MissingSessionID:针对 opencode.ai 网关返回的 400 及 MissingSessionID 类错误,在 dsh 发起的 opencode / opencode-go(以及 base URL 托管在 opencode.ai 的模型)请求上补全 x-opencode-session。
  2. 头优先级:若你在 provider 或 model 上已配置 x-opencode-session,以你的配置为准;插件仅在缺失时填充。
  3. 范围可控:DeepSeek 官方、Anthropic、OpenAI 等其它 provider 不受影响。
  4. 进程内、可卸载:正常插件安装进 profile;卸载后无残留。每次启动会重新安装内存包装,dsh 升级一般无需额外操作;若未来 pi-ai 自带该头,插件可视为 no-op 并移除。
  5. 失败安全:内部结构变化时插件记录 warning 并退避,不阻断请求。

安装与启用

从 GitHub 安装(README 给出的当前可用方式):

dsh plugin --profile web add github:BrackRat/dsh-opencode-session

npm 发布后可用:

dsh plugin --profile web add dsh-opencode-session

本地目录或 tarball:

dsh plugin --profile web add /path/to/dsh-opencode
dsh plugin --profile web add ./dsh-opencode-session-0.1.0.tgz

包声明了 dsh.bundle,dsh plugin add 会把 bundle 写入 dsh.profile.bundles,通常不必手改 profile。安装完成后重启提供 UI 的 dsh 进程(例如 dsh web)。

典型用法与验证

确认插件已进组合配置:

dsh --profile web --dump-config | grep -A 2 opencode-session-header

输出中应能看到插件条目。随后在 Web 里对 opencode-go 模型发起对话,应能正常回复,而不是再出现 MissingSessionID。

卸载:

dsh plugin --profile web remove dsh-opencode-session

适用场景与注意

  • 适合:在 dsh web profile 下使用 opencode / opencode-go,且被网关会话头要求挡住的开发者。
  • 权限与安全:插件与当前 dsh 进程同权,仅在内存中挂钩模型流;安装前建议阅读 GitHub 仓库 源码与 MIT 许可证,确认符合你的合规要求。
  • 生态说明:DSH 社区插件目录(如 SkillHub 条目)为独立站点,与 DeepSeek / 幻方无官方从属关系;本文事实以仓库 README 为准。

结尾

dsh-opencode-session 用一条安装命令、进程内中间件的方式,补上 dsh 经 pi-ai 访问 opencode.ai 时缺的 x-opencode-session,针对 400 MissingSessionID 场景可直接试用。目录页:https://www.skillhub.cn/plugins/BrackRat/dsh-opencode-session;源码与 FAQ:https://github.com/BrackRat/dsh-opencode-session。

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

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

小夜