@dsh-mobile/mobile-remote 3.2.4 → 3.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/CHANGELOG.md +267 -0
  2. package/CONTRIBUTING.md +3 -1
  3. package/FAQ.md +4 -0
  4. package/README.md +25 -18
  5. package/cordis.patch.yml +10 -2
  6. package/docs/00-/345/274/200/345/217/221/346/200/273/347/272/262.md +413 -102
  7. package/docs/01-PRD.md +4 -4
  8. package/docs/02-architecture.md +2 -2
  9. package/docs/03-api.md +49 -1
  10. package/docs/04-security.md +2 -1
  11. package/docs/05-test-cases.md +7 -7
  12. package/docs/06-install-run.md +16 -3
  13. package/docs/07-user-manual.md +23 -1
  14. package/docs/08-/346/211/251/345/261/225/345/274/200/345/217/221/346/214/207/345/215/227.md +2 -2
  15. package/docs/09-compatibility.md +3 -3
  16. package/docs/11-remote-relay-guide.md +85 -0
  17. package/docs/APP-ENCRYPTION-DESCRIPTION.md +50 -0
  18. package/docs/APP-ENCRYPTION-DESCRIPTION.pdf +0 -0
  19. package/docs/APP-REVIEW-NOTES.md +135 -0
  20. package/docs/BRAND-ASSETS.md +142 -0
  21. package/docs/PRIVACY-POLICY.en.md +165 -0
  22. package/docs/PRIVACY-POLICY.md +133 -33
  23. package/docs/STORE-LAUNCH.md +196 -21
  24. package/docs/STORE-LISTING.md +150 -0
  25. package/docs/SUPPORT.md +4 -3
  26. package/docs/TERMS-OF-SERVICE.en.md +102 -0
  27. package/docs/TERMS-OF-SERVICE.md +102 -0
  28. package/lib/account-usage-query.js +278 -0
  29. package/lib/api-helpers.js +333 -0
  30. package/lib/client.js +283 -1
  31. package/lib/config.js +213 -0
  32. package/lib/host-compat.js +133 -0
  33. package/lib/http-util.js +69 -0
  34. package/lib/index.js +249 -2023
  35. package/lib/push.js +73 -0
  36. package/lib/rate-limit.js +46 -0
  37. package/lib/relay/connector.js +300 -0
  38. package/lib/relay/crypto.js +117 -0
  39. package/lib/relay/devices.js +138 -0
  40. package/lib/relay/identity.js +60 -0
  41. package/lib/relay/mux.js +419 -0
  42. package/lib/relay/noise.js +178 -0
  43. package/lib/relay/pairing.js +64 -0
  44. package/lib/relay/phone.js +114 -0
  45. package/lib/relay/serve.js +105 -0
  46. package/lib/rpc-adapter.js +88 -0
  47. package/lib/session-list.js +77 -0
  48. package/lib/timeline.js +492 -0
  49. package/lib/turn-outline.js +289 -0
  50. package/package.json +7 -1
  51. package/docs/ARCHITECTURE-CURRENT.md +0 -229
  52. package/docs/BUILD-ENVIRONMENT.md +0 -169
  53. package/docs/FEATURE-PARITY.md +0 -195
  54. package/docs/REA-UNDERSTANDING.md +0 -246
  55. package/docs/screenshots/01-home.png +0 -0
  56. package/docs/screenshots/02-notifications.png +0 -0
  57. package/docs/screenshots/03-sessions.png +0 -0
  58. package/docs/screenshots/04-chat.png +0 -0
  59. package/docs/screenshots/05-settings.png +0 -0
  60. package/docs/screenshots/06-new-session.png +0 -0
  61. package/docs/screenshots/pgy-appstore.jpg +0 -0
  62. package/docs/screenshots/pgy-mobile-app.jpg +0 -0
  63. package/docs/screenshots/pgy-pc-client.jpg +0 -0
@@ -0,0 +1,102 @@
1
+ # DSH Mobile - DeepSeek Harness 服务条款
2
+
3
+ > 生效日期:2026-11-02 · 最近更新:2026-11-16
4
+ > 发布者:Digital Bang Intelligence LLC.,30 N Gould St Ste R, Sheridan, WY 82801, USA · support@claud.ing
5
+
6
+ ## 1. 协议
7
+
8
+ 本条款是你与 Digital Bang Intelligence LLC.(以下称“我们”)之间,关于你使用 DSH Mobile - DeepSeek Harness(以下称“DSH Mobile”或“本应用”)、网站 dsh.claud.ing 以及我们提供的云端账号、订阅和公开网络中继服务的协议。安装或使用本应用,即表示你同意本条款;如果不同意,请不要使用。我们如何处理信息,见[隐私政策](/privacy/)。
9
+
10
+ ## 2. 本应用与云端服务
11
+
12
+ DSH Mobile 是 DeepSeek Harness 的独立移动伴侣,与 DeepSeek 没有隶属或背书关系。它连接到你在自己电脑上安装并运行的 DeepSeek Harness 服务,让你查看和继续会话、查看任务、回答问询、审批工具动作、浏览工作区文件和接收提醒。使用前,你的电脑上需要有 DeepSeek Harness 和 DSH Mobile 插件。
13
+
14
+ 我们提供两种连接方式:
15
+
16
+ - **局域网直连(免费)。** 手机与电脑在同一可信局域网,或通过你自己搭建的虚拟组网互通。此方式不需要我们的账号,内容不经过我们的服务器。
17
+ - **公开网络中继(收费订阅)。** 手机与电脑不在同一网络时,双方主动连接我们运营的中继服务器,由中继转发端到端加密后的密文。此方式需要有效订阅。
18
+
19
+ “DeepSeek”及相关名称归其所有者所有,在这里只用于说明本应用配合使用的对象。
20
+
21
+ ## 3. 账号
22
+
23
+ 云端账号是可选的,只有使用公开网络中继或订阅时才需要。你可以通过 Google 或 Apple 的一键登录创建账号;我们没有自有密码体系。
24
+
25
+ 你应对自己账号下的活动负责,并应妥善保管设备与商店账号。如果你发现账号被他人使用,请立即联系我们。我们可以暂停或终止被用于滥用、欺诈或违反本条款的账号。
26
+
27
+ ## 4. 许可
28
+
29
+ 我们授予你一项个人的、非独占的、不可转让的、可撤销的许可:在你拥有或控制的设备上,为你自己使用而安装和使用本应用,并遵守本条款。你不得复制、出售、出租或转授权本应用,不得用它违反法律或侵害他人权利,不得干扰它的运行,也不得尝试访问你无权访问的系统。
30
+
31
+ 本项目的源代码以及本应用使用的开源组件,各自适用其自己的许可(本项目自己的源代码采用 MIT 许可)。本条款不限制这些许可赋予你的权利。
32
+
33
+ ## 5. 订阅与付款
34
+
35
+ - **购买渠道。** 公开网络中继的订阅通过 Apple App Store(iOS)或 Google Play(Android)购买。价格、周期和任何优惠以购买时商店页面展示的为准。
36
+ - **自动续期。** 订阅默认自动续期,直到你在商店中取消。商店会在每个周期结束前按当时有效的价格扣款;价格变更由商店按其规则提前通知。
37
+ - **取消。** 你可以在商店的“订阅”页面随时取消;取消后,已付费的当期通常仍可使用到期,具体以商店规则为准。
38
+ - **退款。** 退款由 Apple 或 Google 按其政策处理,我们不直接经手付款,也无法绕过商店替你退款。
39
+ - **恢复购买。** 你可以用同一商店账号在应用内恢复购买。
40
+ - **删除账号不等于取消订阅。** 删除云端账号不会自动取消商店订阅;请先在商店取消,否则商店可能继续扣款。
41
+ - **免费功能。** 局域网直连不因订阅状态而失效。
42
+
43
+ ## 6. 公开网络中继的使用规则
44
+
45
+ 公开网络中继按“合理使用”提供,用于让你从外部网络访问自己的电脑,而不是作为通用代理、VPN 或内容分发网络。
46
+
47
+ 你不得:
48
+
49
+ - 转售、出租或转授权中继访问,或把中继票据提供给他人;
50
+ - 用中继传输违法内容、攻击他人系统、规避访问控制或从事欺诈;
51
+ - 绕过速率限制、配额或计费机制,或尝试探测、扫描、压测中继基础设施;
52
+ - 以自动化方式大量建立连接,影响其他用户。
53
+
54
+ 我们可以为保护服务、遵守法律或防止滥用而限流、暂停或终止中继访问。中继依赖第三方网络与云服务,可能维护、限流或中断;我们会尽合理努力维持可用,但不承诺不间断运行。
55
+
56
+ ## 7. 你的责任
57
+
58
+ - **你的电脑和网络。** 应用连接的是你自己运行的服务。你要对那台电脑、谁能访问它、以及访问口令和二维码的保密负责。请只在可信网络中使用连接。
59
+ - **审批工具动作。** 当 AI 智能体请求运行命令或修改文件,而你在应用里批准后,这个动作会以你的权限在你的电脑上执行。请看清楚再批准。你批准的动作,我们不承担责任。
60
+ - **AI 输出。** 通过 DeepSeek Harness 及其模型提供商生成的回复可能有错、不完整或不安全。在依赖它们或运行它们建议的内容之前,请先自己核对。
61
+ - **其他服务。** DeepSeek Harness、模型提供商、推送通道和你自己搭建的虚拟组网由他人或你按各自的条款和费用提供,你使用它们时适用这些条款。
62
+
63
+ ## 8. 隐私
64
+
65
+ 默认的局域网直连不经过我们的服务器。登录云端账号后,我们会处理账号标识、订阅记录和中继连接元数据;公开中继只转发密文。应用首页会展示一条由第三方广告网络提供的广告,广告请求不含你的会话内容。详情见[隐私政策](/privacy/)。
66
+
67
+ ## 9. 知识产权
68
+
69
+ 除第 4 节所述的开源许可外,本应用的名称、标志和美术作品归我们或我们的许可方所有。你对自己的内容(包括会话、文件和图片)保留全部权利;我们不会收到这些内容,也不主张任何权利。
70
+
71
+ ## 10. 免责声明
72
+
73
+ 在法律允许的最大范围内,本应用与云端服务按“现状”和“可用”状态提供,不附带任何明示或暗示的保证,包括适销性、特定用途适用性、不侵权,以及不间断或无错误运行。我们不保证本应用能配合每个版本的 DeepSeek Harness、每种网络、每台设备或每个地区的网络环境使用。公开中继不保证你所在网络环境一定允许连接成功。
74
+
75
+ ## 11. 责任限制
76
+
77
+ 在法律允许的最大范围内,对于因你使用本应用、云端服务或通过它批准的动作而产生的任何间接、附带、特殊、后果性或惩罚性损害,以及数据、利润或业务的损失,我们不承担责任。我们就与本应用或云端服务有关的任何索赔承担的全部责任,以索赔前 12 个月内你为我们支付的金额与 50 美元中较高者为限。部分地区不允许某些限制;在这种情况下,上述限制在法律允许的范围内适用,你依法享有的强制性消费者权利不受影响。
78
+
79
+ ## 12. 终止
80
+
81
+ 你可以随时卸载本应用以停止使用,并在应用内删除云端账号。如果你违反本条款,或我们不再提供本应用或云端服务,我们可以暂停或终止你的使用。你已支付的订阅退款仍按第 5 节和商店规则处理。依其性质应在终止后继续有效的条款,在终止后继续有效。
82
+
83
+ ## 13. Apple App Store 与 Google Play
84
+
85
+ **Apple App Store。** 如果你从 Apple App Store 下载本应用,Apple 的标准《授权应用程序最终用户许可协议》同样适用;在 iOS 特有的事项上,如与本条款冲突,以 Apple 的条款为准。本条款只在你与我们之间成立,Apple 不是一方。本应用、支持服务以及与本应用有关的任何索赔,由我们而不是 Apple 负责。Apple 及其子公司是本条款的第三方受益人,可以向你执行本条款。
86
+
87
+ **Google Play。** 如果你从 Google Play 下载本应用,Google Play 的服务条款同样适用于你的下载与购买;在 Google Play 特有的事项上,如与本条款冲突,以 Google 的条款为准。
88
+
89
+ ## 14. 条款更新
90
+
91
+ 我们可能不时更新本条款。更新时,我们会修改本页顶部的日期,并在 dsh.claud.ing/terms/ 发布新文本。变更生效后你继续使用本应用,即表示接受更新后的条款;如果你不同意,请停止使用并在商店取消订阅。
92
+
93
+ ## 15. 适用法律
94
+
95
+ 本条款适用美国怀俄明州法律,不考虑其法律冲突规则。任何争议将在位于怀俄明州的州法院或联邦法院提起;但如果你所在地的强制性法律赋予你在别处起诉的权利,则从其规定。
96
+
97
+ ## 16. 联系我们
98
+
99
+ - 公司:Digital Bang Intelligence LLC.
100
+ - 地址:30 N Gould St Ste R, Sheridan, WY 82801, USA
101
+ - 邮箱:support@claud.ing
102
+ - 网站:[dsh.claud.ing](https://dsh.claud.ing)
@@ -0,0 +1,278 @@
1
+ /**
2
+ * 账户用量与额度的上游查询(DeepSeek 余额 / Codex / OpenCode Go)。归一化纯函数在 account-usage.js。
3
+ * 从 lib/index.js 原样拆出(行为不变)。
4
+ */
5
+ import { credentialRef } from "@deepseek-ai/dsh-credentials";
6
+ import { createRequire } from "node:module";
7
+ import { homedir } from "node:os";
8
+ import { join } from "node:path";
9
+ import { pathToFileURL } from "node:url";
10
+ import { normalizeCodexUsage, normalizeDeepSeekBalance, normalizeOpenCodeUsage } from "./account-usage.js";
11
+ import { safeFailureReason } from "./api-helpers.js";
12
+ import { readSettingsSection, readSettingsSectionStrict } from "./host-compat.js";
13
+
14
+ /** 与 PC 端设置页一致的凭据引用派生规则(v2.6):路由 id 大写 → `<ID>_API_KEY`。 */
15
+ export function deriveKeyRef(provider) {
16
+ return `${String(provider).toUpperCase().replace(/[^A-Z0-9]+/g, "_")}_API_KEY`;
17
+ }
18
+
19
+ async function resolveCredentialValue(ctx, ref) {
20
+ let value;
21
+ try {
22
+ const credentials = ctx.get("credentials");
23
+ if (credentials?.resolve) value = (await credentials.resolve(credentialRef(ref)))?.value;
24
+ } catch {
25
+ // 环境变量兜底;不把凭据服务异常暴露给手机端。
26
+ }
27
+ if ((!value || typeof value !== "string") && typeof process.env[ref] === "string") value = process.env[ref];
28
+ return typeof value === "string" && value.trim() !== "" ? value : undefined;
29
+ }
30
+
31
+ async function resolveOpenCodeCredential(ctx, profileRef) {
32
+ const validRef = (value) => typeof value === "string"
33
+ && value !== "DEEPSEEK_API_KEY"
34
+ && /^[A-Za-z_][A-Za-z0-9_]*$/.test(value);
35
+ if (validRef(profileRef)) {
36
+ const explicit = await resolveCredentialValue(ctx, profileRef);
37
+ if (explicit) return explicit;
38
+ }
39
+ try {
40
+ const credentials = ctx?.get?.("credentials");
41
+ const record = typeof credentials?.readRecord === "function"
42
+ ? await credentials.readRecord("llm-pi-ai/opencode-go")
43
+ : undefined;
44
+ if (record?.kind === "api-key" && typeof record.key === "string" && record.key.trim() !== "") return record.key;
45
+ } catch {
46
+ // 旧版 credentials 服务没有 readRecord 时继续走引用/环境变量回退。
47
+ }
48
+ for (const ref of ["OPENCODE_GO_API_KEY", "OPENCODE_API_KEY"]) {
49
+ const fallback = await resolveCredentialValue(ctx, ref);
50
+ if (fallback) return fallback;
51
+ }
52
+ return undefined;
53
+ }
54
+
55
+ async function loadCodexConnect() {
56
+ let bareError;
57
+ try {
58
+ return await import("dsh-codex-connect");
59
+ } catch (error) {
60
+ bareError = error;
61
+ }
62
+ const dshHome = typeof process.env.DSH_HOME === "string" && process.env.DSH_HOME.trim() !== ""
63
+ ? process.env.DSH_HOME
64
+ : join(homedir(), ".dsh");
65
+ for (const profile of ["web", "desktop", "cli"]) {
66
+ try {
67
+ const profileRequire = createRequire(join(dshHome, "profiles", profile, "package.json"));
68
+ const entry = profileRequire.resolve("dsh-codex-connect");
69
+ return await import(pathToFileURL(entry).href);
70
+ } catch {
71
+ // 继续尝试其他 DSH profile;缺失时最终按“未安装”处理。
72
+ }
73
+ }
74
+ throw bareError;
75
+ }
76
+
77
+ async function queryDeepSeekUsage(ctx) {
78
+ const key = await resolveCredentialValue(ctx, "DEEPSEEK_API_KEY");
79
+ if (!key) return { configured: false };
80
+ try {
81
+ const response = await fetch("https://api.deepseek.com/user/balance", {
82
+ headers: { authorization: `Bearer ${key}`, "content-type": "application/json" },
83
+ signal: AbortSignal.timeout(15_000),
84
+ });
85
+ if (!response.ok) {
86
+ await response.body?.cancel();
87
+ return { configured: true, failed: true, failedId: "deepseek", failedReason: `HTTP ${response.status}` };
88
+ }
89
+ const data = await response.json();
90
+ const balance = normalizeDeepSeekBalance(data);
91
+ return {
92
+ configured: true,
93
+ source: {
94
+ id: "deepseek",
95
+ title: "DeepSeek",
96
+ kind: "balance",
97
+ ...balance,
98
+ },
99
+ };
100
+ } catch (err) {
101
+ return { configured: true, failed: true, failedId: "deepseek", failedReason: safeFailureReason(err) };
102
+ }
103
+ }
104
+
105
+ /**
106
+ * 读取 Codex 代理配置(导出以便单测:issue #21 的回归点正在这里)。
107
+ *
108
+ * 返回值三态,**必须区分**:
109
+ * - `{ enabled: false }` —— 设置读得到,但用户没开代理(走直连是正确的);
110
+ * - `{ enabled: true, url }` —— 代理已启用且地址有效;
111
+ * - `{ enabled: true, url: undefined, unreadable: true }` —— **读不到宿主设置**。
112
+ * 这是插件与宿主的接口问题,不是用户的选择;原实现把它误判为"代理未启用",
113
+ * 于是静默改走直连、最终以"Codex 余额消失"的形式暴露,根因完全不可见。
114
+ */
115
+ export function codexProxyUrl(ctx, mod) {
116
+ const namespace = mod.OPENAI_CODEX_SETTINGS_NAMESPACE ?? "llm-openai-codex";
117
+ let settingsSvc;
118
+ try {
119
+ settingsSvc = ctx?.get?.("settings");
120
+ } catch {
121
+ settingsSvc = undefined;
122
+ }
123
+ // issue #21:原实现用 `settings.get()` 读该命名空间,而宿主 0.2.0 **移除了该方法**
124
+ // (同一处破坏在 issue #19 已修过另两个调用点,这一处因是可选链写法 `?.get?.(` 被漏掉)。
125
+ // 更要紧的是**语义**:读不到配置 ≠ 代理未启用。原实现把前者当作后者 → 返回 enabled:false
126
+ // → 插件静默改走直连 chatgpt.com → 连接超时 → 表现为"手机看不到 Codex 余额",
127
+ // 而配置本身(enableProxy:true + proxyUrl)一直好好的,用户完全看不出根因。
128
+ //
129
+ // 评审 WARNING 3 的补充:仅判断"读取方法存在"不够——`get()` 抛错、`describe()` 抛错、
130
+ // 或 describe 返回形状不合法时,宽松读取会把它们一律折叠成 undefined,再由 `?? {}`
131
+ // 伪装成"命名空间不存在"。故此处用**严格读取**,只有"读取成功且命名空间确实不存在"
132
+ // 才允许判定为"用户没开代理"。
133
+ const read = readSettingsSectionStrict(settingsSvc, namespace);
134
+ if (!read.ok) return { enabled: true, url: undefined, unreadable: true, reason: read.reason };
135
+ const settings = read.value ?? {};
136
+ try {
137
+ const resolved = typeof mod.resolveOpenAICodexSettings === "function"
138
+ ? mod.resolveOpenAICodexSettings(settings)
139
+ : settings;
140
+ const enabled = resolved?.enableProxy === true || settings?.enableProxy === true;
141
+ // 命名空间确实不存在 ⇒ 用户没开代理,走直连是正确行为(区别于上面的"读不了")
142
+ if (!enabled) return { enabled: false, url: undefined };
143
+ const url = typeof mod.resolveOpenAICodexProxyUrl === "function"
144
+ ? mod.resolveOpenAICodexProxyUrl(resolved)
145
+ : resolved?.proxyUrl;
146
+ return { enabled: true, url: typeof url === "string" && url.trim() !== "" ? url : undefined };
147
+ } catch {
148
+ return { enabled: true, url: undefined, unreadable: true, reason: "settings-resolve-threw" };
149
+ }
150
+ }
151
+
152
+ async function queryCodexUsage(ctx) {
153
+ let mod;
154
+ try {
155
+ mod = await loadCodexConnect();
156
+ } catch {
157
+ return { configured: false };
158
+ }
159
+ if (typeof mod?.OpenAICodexCredentialStore !== "function"
160
+ || typeof mod?.openAICodexAuthStatus !== "function"
161
+ || typeof mod?.readOpenAICodexRateLimits !== "function") return { configured: false };
162
+ let store;
163
+ let captured;
164
+ let proxyManager;
165
+ try {
166
+ store = new mod.OpenAICodexCredentialStore();
167
+ // 新版返回同一账户快照;旧版没有该方法时仍可读取额度,但账户标签降级为可选。
168
+ captured = typeof store.captureActiveAccount === "function" ? await store.captureActiveAccount() : store;
169
+ if (!captured) return { configured: false };
170
+ const status = await mod.openAICodexAuthStatus(captured);
171
+ if (status?.authenticated !== true) return { configured: false };
172
+ const proxy = codexProxyUrl(ctx, mod);
173
+ if (proxy.enabled && (!proxy.url || typeof mod.OpenAICodexProxyManager !== "function")) {
174
+ // v3.1.6(issue #21):**必须区分**「读不到宿主配置」与「用户没开代理」。
175
+ // 前者是插件与宿主的接口问题,后者是用户的选择;原实现把两者都归为 failed,
176
+ // 于是 Codex 余额整块消失而原因无法归因(见 failedReason 的两种措辞)。
177
+ return {
178
+ configured: true, failed: true, failedId: "codex",
179
+ failedReason: proxy.unreadable
180
+ ? "读不到宿主设置(settings 服务没有可用的读取方法),无法判断 Codex 代理配置"
181
+ : (proxy.url ? "宿主未提供代理管理器" : "代理已启用但未配置代理地址"),
182
+ };
183
+ }
184
+ proxyManager = proxy.enabled ? new mod.OpenAICodexProxyManager() : undefined;
185
+ const readUsage = () => mod.readOpenAICodexRateLimits(captured);
186
+ const usage = normalizeCodexUsage(proxyManager ? await proxyManager.run(proxy.url, readUsage) : await readUsage());
187
+ let active;
188
+ try {
189
+ const accounts = typeof captured.accounts === "function" ? await captured.accounts() : [];
190
+ active = Array.isArray(accounts) ? accounts.find((account) => account?.active === true) : undefined;
191
+ } catch {
192
+ // 账户标签是可选展示信息;额度投影成功时不因标签读取失败而隐藏来源。
193
+ }
194
+ return {
195
+ configured: true,
196
+ source: {
197
+ id: "codex",
198
+ title: "Codex",
199
+ kind: "quota",
200
+ ...usage,
201
+ ...(active && (active.displayName || active.maskedEmail) ? {
202
+ account: {
203
+ ...(typeof active.displayName === "string" && active.displayName !== "" ? { displayName: active.displayName } : {}),
204
+ ...(typeof active.maskedEmail === "string" && active.maskedEmail !== "" ? { maskedEmail: active.maskedEmail } : {}),
205
+ },
206
+ } : {}),
207
+ },
208
+ };
209
+ } catch (err) {
210
+ // v3.1.6(issue #21):失败原因要能对上号(此前只记 failed,用户无从判断是网络、
211
+ // 凭据还是插件读不到宿主配置)。detail 走脱敏。
212
+ return { configured: true, failed: true, failedId: "codex", failedReason: safeFailureReason(err) };
213
+ } finally {
214
+ try {
215
+ await proxyManager?.dispose?.();
216
+ } catch {
217
+ // 代理池释放失败不应掩盖已拿到的额度快照。
218
+ }
219
+ }
220
+ }
221
+
222
+ async function queryOpenCodeUsage(ctx) {
223
+ let profile;
224
+ try {
225
+ // issue #21:与 codexProxyUrl 同一种写法(可选链),同样受"0.2.0 移除 settings.get()"影响。
226
+ // 此处目前**碰巧仍有数据**(额度走的是凭据解析路径,profile 只用于取 apiKeyEnv),
227
+ // 但同一形式的读取必须一并改为跨代版本——否则换个宿主版本就会静默失效。
228
+ const settingsSvc = ctx?.get?.("settings");
229
+ const section = readSettingsSection(settingsSvc, "llm-pi-ai");
230
+ profile = section?.providers?.["opencode-go"];
231
+ } catch {
232
+ profile = undefined;
233
+ }
234
+ const key = await resolveOpenCodeCredential(ctx, profile?.apiKeyEnv);
235
+ if (!key) return { configured: false };
236
+ // 不接受设置页可配置的 baseURL,避免把套餐密钥发送到非官方/内网地址。
237
+ const url = "https://opencode.ai/zen/go/v1/usage";
238
+ try {
239
+ const response = await fetch(url, {
240
+ headers: { authorization: `Bearer ${key}`, accept: "application/json" },
241
+ signal: AbortSignal.timeout(15_000),
242
+ });
243
+ if (!response.ok) {
244
+ await response.body?.cancel();
245
+ return { configured: true, failed: true, failedId: "opencode-go", failedReason: `HTTP ${response.status}` };
246
+ }
247
+ const source = normalizeOpenCodeUsage(await response.json());
248
+ return { configured: true, source: { id: "opencode-go", title: "OpenCode Go", kind: "quota", ...source } };
249
+ } catch (err) {
250
+ return { configured: true, failed: true, failedId: "opencode-go", failedReason: safeFailureReason(err) };
251
+ }
252
+ }
253
+
254
+ export async function queryAccountUsage(ctx) {
255
+ const results = await Promise.all([
256
+ queryDeepSeekUsage(ctx),
257
+ queryCodexUsage(ctx),
258
+ queryOpenCodeUsage(ctx),
259
+ ]);
260
+ const sources = results.filter((result) => result?.source).map((result) => result.source);
261
+ const failures = results.filter((result) => result?.configured === true && result?.failed === true);
262
+ return {
263
+ ok: true,
264
+ fetchedAt: new Date().toISOString(),
265
+ sources,
266
+ availableCount: sources.length,
267
+ failedCount: failures.length,
268
+ // v3.1.6(issue #21):此前只给 failedCount。用户看到的是「Codex 整块消失」,
269
+ // 却无法判断是凭据没配、网络不通、还是插件读不到宿主配置——定位只能靠猜。
270
+ // 现在把**哪个来源失败、为什么失败**一并给出(无失败时省略该字段,保持响应稳定)。
271
+ ...(failures.length > 0 ? {
272
+ failures: failures.map((result) => ({
273
+ id: result.failedId ?? "unknown",
274
+ reason: result.failedReason ?? "未提供原因",
275
+ })),
276
+ } : {}),
277
+ };
278
+ }