Skip to content

fix(v2): 服务端入口通过 V2 校验 + 余额自动复用 auth.json 凭据 - #38

Merged
Hotakus merged 1 commit into
Hotakus:masterfrom
aiev:fix/v2-server-entry
Sep 22, 2026
Merged

Hotakus merged 1 commit into
Hotakus:masterfrom
aiev:fix/v2-server-entry

Conversation

@aiev

@aiev aiev commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

背景

修复 opencode 2.x(V2)下的两个问题,关联 #37。

改动

  1. src/server.ts:默认导出补充空 setup(保留 V1 的 server 字段),使模块通过 V2 的 PluginModule 校验。本插件没有服务端能力,空 setup 无副作用;否则 V2 服务端解析 ./server 时会报 Plugin must export a default definition with an id and an effect or setup function,插件不激活,TUI 面板不显示。
  2. src/v2/commands.ts:readOpenAIOAuthToken() 泛化为 readAuthCredential(providerID),支持 oauth → access 与 api → key;findOpencodeKeyV2() 在 provider list 拿不到凭据时回退读取 auth.json。V2 的 Provider.Info 不包含 key 字段,这一步让 DeepSeek 等 API key 提供商也能自动复用 OpenCode 已认证的凭据(此前仅 OpenAI 特判)。

验证

  • npm run typecheck、npm run build 均通过(Node 25)。
  • opencode 2.0.14 + 该分支的本地构建:服务端不再出现 failed to load plugin,侧边栏面板正常渲染。
  • 余额数据实测:DeepSeek https://api.deepseek.com/user/balance(api.key)与 OpenAI Codex https://chatgpt.com/backend-api/wham/usage(oauth.access)均能取到数据并在余额区展示。

Fixes #37


补充说明:#33(未合并)曾尝试整体迁移 V2 并删除 src/server.ts;本 PR 保留现有双入口架构,只补 setup,不破坏 V1 的 server 字段检测。#31 仅调整了 oc2 发布脚本的 server 入口,未解决 1.7.x 主线包在 V2 服务端的 schema 校验问题。

- src/server.ts: 默认导出补充空 setup,避免 V2 服务端因缺少 setup/effect
  而通过不了 PluginModule 校验,导致 cli.json 中的插件未激活、面板不显示
- src/v2/commands.ts: readOpenAIOAuthToken 泛化为 readAuthCredential,
  同时支持 oauth(access) 与 api(key);V2 的 Provider.Info 不含凭据,
  provider list 拿不到 key 时回退读取 auth.json,修复 DeepSeek 等
  提供商在 V2 下显示「API Key not set」的问题
@Hotakus

Hotakus commented Sep 22, 2026

Copy link
Copy Markdown
Owner

感谢你的修复,代码合并后,我会尽快发布新版本,感谢你的支持

@Hotakus
Hotakus merged commit ff415d3 into Hotakus:master Sep 22, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

V2 (opencode 2.x) 下插件未激活(server 入口 schema 校验失败)且 DeepSeek 余额不自动复用 auth.json

2 participants