为 OpenCode / OpenCode Go 提供商请求自动附加每个会话稳定的 x-opencode-session 请求头,修复 400 MissingSessionID 错误,同时保持会话亲和与提示缓存路由。
安装
# npm 包(预构建)
dsh plugin --profile web add dsh-opencode-session
# GitHub 源码(首次需按提示配置 allowBuilds 构建授权后重试)
dsh plugin --profile web add github:nobu121/dsh-opencode-session
装任何插件都等于在你的机器上跑第三方代码,权限和你本人一样大——能读你的文件、用你的凭据、访问网络,工具审批管不到它。GitHub 来源的插件还会在安装时执行构建脚本——pnpm 默认拦截,所以安装可能停在 ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED 或 ERR_PNPM_IGNORED_BUILDS;dsh 会打印出需要添加的确切键名,把它加进该 profile 的 pnpm-workspace.yaml 的 allowBuilds 下,重跑一次即可装上。放行构建本身就是一次信任判断:请只安装可信来源,并尽量锁定 commit(github:owner/repo#sha)。
README
该插件的 README 只有英文版本。
A DeepSeek Harness (DSH)
plugin that automatically sends the x-opencode-session request header on
model calls routed to OpenCode / OpenCode Go providers — one stable
session id per DSH conversation.
Why
Since 2026-09-05 OpenCode's relay requires an x-opencode-session header on
API requests (tracked upstream in
deepseek-harness discussion #5495);
without it, requests fail with 400 MissingSessionID-style errors. Requests
that share the same header value are pinned to the same upstream backend,
which is also what keeps OpenCode's prompt cache warm across the turns of one
conversation.
This plugin:
- fixes the 400 by always attaching the header to OpenCode(Go) requests,
- keeps the cache/affinity benefit by using a value that is unique per
conversation and stable across that conversation's turns (by default the
DSH session id itself, the same identity the official DeepSeek adapter
already sends as
x-deepseek-harness-session-id), - leaves every other provider, and every request that already carries the header, untouched.
Install
From the npm registry (once published):
dsh plugin --profile web add dsh-opencode-session
From a local checkout:
dsh plugin --profile web add ./path/to/dsh-opencode-session
Then fully restart your dsh profile (bundle layers are read at startup). The startup log shows:
[opencode-go-session-header] active for providers [opencode, opencode-go] with mode session-id
If you run DSH from a source checkout instead, load it as an overlay:
pnpm dsh web --patch ./cordis.patch.yml.
Configuration
The plugin row lives in the bundle's cordis.patch.yml; all keys are optional:
- insert:
- id: opencode-go-session-header
name: dsh-opencode-session
config:
providers: [opencode, opencode-go] # route keys to attach the header to
mode: session-id # 'session-id' | 'uuid'
debug: false
debugFile: null # optional absolute path
providers— provider route keys whose requests get the header. The defaults cover the pi-ai catalog idsopencodeandopencode-go; add your own route key when you serve OpenCode through a custom provider name.modesession-id(default) — header value = the DSH session id of the model call. Unique per conversation, stable across turns, compaction, retries and process restarts.uuid— a random UUID derived once per DSH session id (opaque; kept in memory, so it resets when the process restarts).
debug— log every streamed call that receives the header viactx.logger(the dsh process console).debugFile— optional absolute path. When set, every streamed call that receives the header appends one JSON line ({"ts","provider","model","session","header","value"}) to that file — handy when the dsh console is not visible.
To override configuration in a profile without editing the package, add a
row with the same id in the profile's own cordis.patch.yml (it replaces the
whole config, so restate every key).
How it works
- Listens on the
llm/streamwaterfall. A call whoseoptions.providernames a configured OpenCode route and which carries asessionIdis driven through anAsyncLocalStoragestore holding the header value. globalThis.fetchis patched once. While such a store is active, the outgoing request receivesx-opencode-session: <value>(unless it already carries the header — an existing value always wins).- Both registrations are fiber-scoped ctx effects: stopping / updating /
unloading the plugin restores the original
fetchand removes the listener.
Non-OpenCode providers, requests without a sessionId (some auxiliary
hand-built calls), and model discovery requests pass through untouched.
Notes / limitations
- The header is attached to chat/streaming requests inside an
llm/streamcall. The one-shot model listing used by the Models page (GET <baseURL>/models) is a separate flow and does not receive the header; if your OpenCode endpoint also rejects that listing, open an issue. - The plugin relies on DSH outbound LLM requests going through the Node
global
fetch. If a future DSH version swaps its network stack, the plugin stops injecting (symptom: the 400 comes back) — uninstall then.
Development
node --check lib/index.js
npm test # local behavior tests against an echo server
Publishing (for maintainers)
The package is plain ESM JavaScript with zero dependencies; npm test runs
automatically via prepublishOnly.
npm login # once, with your npm account
npm pack --dry-run # preview exactly what lands in the tarball
npm publish # files = lib/, cordis.patch.yml, README.md
Before publishing, double-check the name is free on the npm registry and fill
in author, homepage, and repository in package.json if you like.
License
MIT
链接
同类插件
Ebony-Vinyl/dsh-our-free-model★ 51127
为 dsh 接入免费模型车道(含 DeepSeek V4.1 Flash、Kimi K3 等),无需登录、注册或填写 API Key,并提供本地 OpenAI 兼容网关、降级路由与用量看板。
dingminhua/dsh-connect-workbuddy★ 870
将本机登录的 WorkBuddy 模型(国内版与国际版)接入 DSH,每次刷新按上游目录读取每个模型的积分倍率,支持逐模型图片输入开关、带自动换号的账号池、手动每日签到,以及卡片与输入框里的只读积分胶囊读数。
V1ki/dsh-plugin-subscriptions★ 532
把 ChatGPT(Codex)、Claude、Grok 订阅当作 DeepSeek Harness 的 LLM 提供方:设置页登录、模型目录、用量展示,以及 image_generate、video_generate 与 x_search 工具。
Alice-Marx/dsh-model-router★ 471
为 DeepSeek Harness 规划有依赖的工作包,将其分配给已配置的模型 API 或支持的厂商 CLI,并提供费用预览。
Mars-Sea/dsh-commandcode-provider★ 443
非官方 Command Code 模型接入插件:注册 `commandcode` 路由,带实时模型目录与推理强度支持。
FishBottle7/opencode2dsh★ 379
将 OpenCode Zen 免费模型接入 DeepSeek Harness,无需 API Key。
社区评论
评论公开保存在 GitHub Discussions。加载评论会连接 GitHub 和 Giscus;发表内容需要 GitHub 账号。