DSH HUB
HomePlugin StorePlugin PacksCommunityRankingsResourcesPublish Guide
Plugin source
Back to catalog

wjj-8283 /

wjj-8283/dsh-opencode-go-proxy

Verified

适用于OpenCode Go的反代插件,用来解决OpenCode Go需要请求头不能直接访问的问题

★ 0 Stars0 Forks0 IssuesN/A Community rating0 Confirmed installs
View on GitHub
READMESource: main@e3f200f2

@wjj-8283/dsh-opencode-go-proxy

DSH 插件:本机 OpenCode Go 反代理。dsh 启动时自动把反代理挂到 DSH 自己的 webserver 上(与 DSH 共用端口),转发到 OpenCode Go 上游(默认 https://opencode.ai), 并在发包前注入 OpenCode 要求的会话/请求头(x-opencode-session / x-opencode-request / x-opencode-client / x-opencode-project / User-Agent)。

由仓库下的 opencode-go-proxy-win 脚本改造而来:

原脚本 本插件
opencode-go-proxy.mjs(顶层启动) proxy.js(导出 createForwarder / createProxy)
opencode-go-proxy-start-minimal.bat 插件 apply 在 dsh 启动时自动拉起
手动 Ctrl+C 停止 随 dsh 应用卸载自动关闭

布局

opencode-go-proxy-plugin/
  package.json       name + dsh.bundle.patch + exports
  cordis.patch.yml   把本插件插入宿主 Loader 条目(自动加载)
  index.js           插件 apply:挂到 webserver + settings + 状态路由
  proxy.js           核心反代理逻辑(从 .mjs 移植为可导入模块)

安装 & 生效

插件是一个 bundle(dsh.bundle.patch),装进某个 profile 后它会进入 dsh.profile.bundles,下次 dsh --profile <name> 启动时自动加载:

dsh plugin --profile web add /Users/wjj/repos/dsh/opencode-go-proxy-plugin
dsh plugin --profile qq  add /Users/wjj/repos/dsh/opencode-go-proxy-plugin

使用(默认,与 DSH 共用端口)

默认 mode=webserver:把反代理挂到该 profile 的 webserver 的前缀路径下。 客户端 baseURL 指向该路径即可:

  • web profile:http://127.0.0.1:3080/api/opencode-proxy/v1
  • qq profile:http://127.0.0.1:3220/api/opencode-proxy/v1 (端口取各 profile 的 webserver 端口,即 dsh web 的默认 3080、qq 默认 3220)

反代理把挂载前缀 /api/opencode-proxy/v1 之后的路径映射回上游的真实 API 根: 默认 upstreamBasePath=/zen/go/v1,因此 .../api/opencode-proxy/v1/responses 会转发成 https://opencode.ai/zen/go/v1/responses。若剥离后的路径已带 upstreamBasePath 前缀则不重复叠加(幂等)。

接入 DSH 模型设置

DSH 的模型设置(llm-pi-ai.providers)里把某个 provider 的 baseURL 指向本代理即可 (把原来直连 https://opencode.ai/zen/go/v1 换成代理地址)。例如现有 oc-go(OpenCode Go): 直连:

oc-go:
  displayName: OpenCode Go
  apiKeyEnv: OC_GO_API_KEY
  api: openai-responses
  baseURL: https://opencode.ai/zen/go/v1   # 原来是直连
  reasoning: high
  models: [...]

走代理(以 web profile 为例):

oc-go:
  displayName: OpenCode Go
  apiKeyEnv: OC_GO_API_KEY
  api: openai-responses
  baseURL: http://127.0.0.1:3080/api/opencode-proxy/v1   # 改成代理地址
  reasoning: high
  models: [...]
  • 该改动只影响 oc-go,不影响当前默认模型(agent-default-model 还是 deepseek-official)。
  • 想让某个会话用 opencode,把会话/全局的默认模型设为 oc-go + 某个 model(如 muse-spark-1.2-contributor)。
  • API Key 仍走 OC_GO_API_KEY 环境变量:代理会原样转发 Authorization 头,并在发包前注入 x-opencode-session/request/client/project、把 User-Agent 换成 opencode/...。
  • 代理需先在该 profile 的 webserver 上跑起来:web 改了插件源码后要重启 dsh web 才会从“旧独立 8787”切到“3080/api/opencode-proxy/v1”。

可选:standalone 模式

若某个 profile 没有 webserver,或你想让代理跑在独立端口上,把 settings 的 mode 设为 standalone,则用 port(默认 8787)起一个独立 server: http://127.0.0.1:8787。此时客户端 baseURL 用 http://127.0.0.1:8787。

配置(settings 命名空间 dsh-opencode-go-proxy)

  • enabled(默认 true):启动即拉起
  • mode(默认 webserver):webserver(挂 DSH webserver 前缀) | standalone(独立端口)
  • mountPath(默认 /api/opencode-proxy/v1):webserver 模式下的挂载前缀
  • upstreamBasePath(默认 /zen/go/v1):映射回上游的真实 API 根(幂等叠加)
  • port(默认 8787):standalone 模式下的监听端口
  • upstreamHost(默认 opencode.ai)、upstreamProto(默认 https)
  • opencodeUa(默认 opencode/1.18.29 cli)

环境变量兜底:PROXY_PORT / UPSTREAM_HOST / UPSTREAM_PROTO / UPSTREAM_PORT / OPENCODE_UA,仅在 settings 未设置时生效。

  • 状态检查:GET /api/opencode-proxy/status(经 profile 的 webserver)。
—/ 5

No ratings yet

Verified DSH bundle

Commit e3f200f27ad3

Community comments

No comments yet. Be the first to write one.

DSH HUB

A community index for DSH plugins. Not an official GitHub or DeepSeek AI product.

CommunityResourcesAPIAbout