dsh-agent-sdk-bridge 1.1.6 → 1.1.8

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.
package/DEVELOPMENT.md CHANGED
@@ -9,6 +9,17 @@
9
9
  没装时只有对应页面报错,插件照常加载。
10
10
  - **品牌隔离**:各 provider 的 CLI 查找、模型目录缓存、会话池、账户读取、模型开关全部按 brand
11
11
  分开。`QODERCLI_PATH` 若指向另一 Qoder 版本,对应版本会明确报错而不是借用那个 CLI 的账号。
12
+ - **Qoder 的声明窗口必须稳定**:Qoder 的 `context_usage_ratio` 是「按 CLI 实际运行的窗口」算的,
13
+ 而 DSH 又用适配器上报的 `contextWindow` 当分母。两者一变,环就会跳。实测目录里 `dfmodel`
14
+ 等模型声明 `availableContextWindows: [200000, 400000, 1000000]`、默认 200000,用户选 1M 是
15
+ 上游真支持的档位。旧代码在目录短暂读不到时退回静态 `DEFAULT_CONTEXT_WINDOW`(200000),
16
+ 于是同一会话会在 1M 与 200K 之间翻转:分母变了,DSH 的压缩预算 `contextWindow - maxTokens
17
+ - headroom` 也一起从 800K 掉到约 102K,一个才 10% 的会话就被自动压缩(历史里 t18 在
18
+ 99,747 token 时压缩、随后掉到 37,699,正是这种「小幅跳变」)。现在 `declaredWindow()` 记住
19
+ 每个路由上一次成功解析的窗口与可选项,目录缺席时复用它而不是退回 200K;
20
+ `resolveDeclaredWindow()` 只在模型确实声明了该档位时才采用用户覆盖(`auto` 只声明
21
+ `[200000]`,存了 1M 也会被忽略),`/models` 对单档模型回传
22
+ `contextWindowSelectable: false`,页面显示「上游固定」。
12
23
  - **CodeBuddy**:`src/codebuddy.ts` 自成一体会话(`unstable_v2_createSession` + 流式消息),
13
24
  模型目录取自 `getAvailableModelsRaw()`,账户取自一次性 `query().accountInfo()`;登录走
14
25
  `unstable_v2_authenticate`,`global`/`cn` 分别映射为 SDK 的 `external`/`internal`。
@@ -34,6 +45,19 @@
34
45
  仍会丢弃任何非宿主前缀的 tool_use,防止模型臆造工具名。CodeBuddy 会把 MCP server 名里的
35
46
  非字母数字字符规范成 `_`(`dsh-host` → `mcp__dsh_host__<tool>`),Qoder CLI 保留连字符,
36
47
  因此 `isHostTool()` / `hostToolName()` 同时接受两种拼写。
48
+ - **切换模型读缓存**:`resolveModel` 与 `capture()` 走 `cachedModels()`
49
+ (`src/model-cache.ts`):有快照就先返回快照,刷新在后台跑;只有从未读到过目录时才等待。
50
+ 三家的目录获取都很贵(Qoder 冷启动 CLI,最长等于 fetch 超时;CodeBuddy 要启进程;MiniMax
51
+ 走 ACP 探测),而宿主在每次切模型、切思考档位时都会重新解析一次,所以以前 TTL 一过期就会
52
+ 卡住菜单。三家 catalog 都新增了 `snapshot()`(只读内存,不发网络)供这里使用。
53
+ 同步探测(`regionBlocked`、额度)不受影响,它们仍走各自的正常读取。
54
+ - **默认思考档位取最强的一档**:`reasoningInfo()` 的第二个参数是**用户配置**的档位,不再是上游
55
+ 声明的 `defaultEffort`;留空时由 `strongestEffort()` 按 `none < minimal < low < medium <
56
+ high < xhigh < max` 取该模型支持的最强档(三家词表不同:Qoder `low|medium|high|max`、
57
+ MiniMax `low|high`、CodeBuddy 由目录声明)。宿主在请求未带档位时会应用我们声明的
58
+ `defaultEffort`(`requested ?? reasoning.defaultEffort`),所以这里选什么,实际就跑什么;
59
+ 上游自己的默认值会偏低(CodeBuddy 的 `high` 在可选 `max` 时就不再直接采用)。配置的档位若
60
+ 模型不支持,会退回最强档,而不是把这一轮判成 `UNSUPPORTED_REASONING_EFFORT`。
37
61
  - **CodeBuddy 模型选择按区域**:`codebuddyGlobalDisabledModels` /
38
62
  `codebuddyCnDisabledModels` 与 `codebuddyGlobalModelContextWindows` /
39
63
  `codebuddyCnModelContextWindows` 是四个独立字段,`CodeBuddyAdapter` 按 region 读取,
@@ -49,15 +73,29 @@
49
73
  `CODEBUDDY_AUTH_TOKEN` + 该目录启动。页面在切区域时用 `fresh=1` 绕开宿主缓存,并校验
50
74
  `/models` 回显的 `region`。设置页的所有分支都渲染相同的 h2 / intro / 卡片前缀,避免切区时
51
75
  卡片因子节点下标变化被重建、把下拉框弹回配置里的旧区域。
52
- - **CodeBuddy 的上下文窗口不可设**:目录里的 `contextWindow.supportedLengths` 才是可选项,
53
- `maxInputTokens` 只是模型物理上限。实测当前目录**所有模型**都报 `supportedLengths: null`,
54
- 此时 `set_config{contextWindow}` 会被 CLI 拒绝:
55
- `Invalid context_window value: "200000". Allowed: <none>`。因此 `contextWindows` 只收集
56
- `supportedLengths`,`contextWindowFor()` 在模型不支持时返回 `undefined`(旧的按区域保存的
57
- 覆盖值也随之失效),`/models` 回传 `contextWindowSelectable`,页面把这类模型显示为
58
- 「上游固定」而不是给一个无效下拉框。上游真的声明多档时,菜单与覆盖值会自动恢复。
59
- 另注:`CBC_SESSION_CONFIG_SYNC=1` 时 `result._meta` 才带 `codebuddy.ai/contextWindow`,
60
- 它反映的是模型物理窗口(如 1000000),不是用户选择。
76
+ - **CodeBuddy 的上下文窗口必须真正下发**:`contextWindow.supportedLengths` 才是可选项,
77
+ `maxInputTokens` 只是物理上限。两套目录实测不同:国内站所有模型 `supportedLengths: null`
78
+ (`set_config{contextWindow}` 被拒,`Allowed: <none>`);国际站如 `deepseek-v4.1-flash` 是
79
+ `[300K, 1M]`、`defaultLength` 300K。CLI 按「会话 override > defaultLength > 最小档 > 物理
80
+ 上限」解析有效预算,并据此设压缩阈值(92%)与网关限额。只把窗口告诉 DSH 而不下发时,宿主按
81
+ 1M 算、会话按 300K 跑:历史一过 276K 就被紧急压缩(日志 `Compact … trigger=blocking_limit`),
82
+ 上下文环从几十 % 塌到 2–3 %,下一轮补齐再涨回,正是「每轮被重置」的现象。实现:
83
+ `contextWindows` 只收集 `supportedLengths`,`contextWindowFor()` 对不支持档位的模型返回
84
+ `undefined`(旧覆盖值也随之失效);`windowOption()` 对支持档位的模型始终返回一个值——用户选
85
+ 的档位,或模型默认(CLI 拒绝 `null` 清空:`contextWindow must be a positive safe integer`);
86
+ `CodeBuddySession.applyContextWindow()` 在 `setModel` 之后按 model+window 去重发送。
87
+ `/models` 回传 `contextWindowSelectable`,页面把固定窗口模型显示为「上游固定」。
88
+ 另注:`CBC_SESSION_CONFIG_SYNC=1` 时 `result._meta` 的 `codebuddy.ai/contextWindow` 是模型
89
+ 物理窗口(如 1000000),不是用户选择。
90
+ - **图片要同时给像素和路径**:DSH 原生适配器除了图片块,还会附一句
91
+ `requestImageHandleText()`——附件名、像素尺寸、**只读归一化副本的宿主路径**,以及「编辑前先复制成
92
+ 可写 `.png`」的指示。桥接此前只发像素:模型能看懂图,但用户说「取反色保存」时它去工作区找一个
93
+ 从未存在过的文件(Qoder 的原话是「图片没有保存在工作目录中」),而 DeepSeek 官方因为有路径能直接
94
+ 处理。现在 `render.ts` 的 `imageRefText()` 复用同一文案,`ImagePathResolver` 由
95
+ `ctx.attachments.imageHostPath()` 取宿主路径、再经 `ctx.fs.processPathFromHostPath()` 映射到工具
96
+ 执行世界;Qoder / CodeBuddy / MiniMax 在图片块前插入这条句柄,历史图片(rebuild 时按文本重放、
97
+ 不发像素)同样带路径。另外三个适配器都会记住每个路由上一次验证过的 `vision` 能力:目录某次读不到
98
+ 时不再谎报 text-only——那会让 DSH 在适配器之前就把像素剥成占位符。
61
99
  - **CodeBuddy 额度**:SDK 没有额度方法,`readQuotaWithToken()` 用登录 token 调
62
100
  `POST /v2/billing/meter/get-user-resource`(国内与国际同协议),按积分包汇总实时余额;
63
101
  额度读取优先用保存的 token,缺失时才静默 `authenticate`,不会拉起浏览器。卡片里的积分包
package/FAQ.md CHANGED
@@ -44,14 +44,29 @@ bearer token,只留在本机,请不要分享或提交到仓库。从旧版
44
44
  `tools: []` 禁用 CLI 内置工具,只保留宿主通过 MCP 挂入的工具;CodeBuddy 把 MCP server 名
45
45
  规范成 `dsh_host` 的写法也已兼容。升级后重启 DSH Web 即可。
46
46
 
47
- **给 CodeBuddy 设了 1M 上下文,为什么对话里上下文环还是忽大忽小、有时突然变小?** 因为那个窗口
48
- 设置**从未作用于上游**。CodeBuddy 只接受模型自己声明的档位(`contextWindow.supportedLengths`),
49
- 而当前目录里所有模型都报 `null`;插件把物理上限(`maxInputTokens`)也塞进了可选档位,于是设置页
50
- 出现了 200K / 1M 开关,实际下发时被 CLI 拒绝:
51
- `Invalid context_window value: "200000". Allowed: <none>`。上游仍按模型物理窗口运行,而 DSH 却按
52
- 你选的窗口算百分比,两者不一致,环就会跳。现在可选档位只来自 `supportedLengths`;模型没有档位时
53
- 页面显示「上游固定 · 1M」而不给下拉框,已保存的无效覆盖值也不再生效。上游将来真提供多档时,
54
- 选择器会自动出现。
47
+ **Qoder 的上下文环为什么也会小幅跳一下(比如从 60% 掉到 20% 又涨回来)?** 因为分母曾经会
48
+ 短暂变成 200K。Qoder 的 `context_usage_ratio` 按「CLI 实际运行的窗口」算,DSH 又用适配器上报的
49
+ 窗口当分母;目录里 `dfmodel` 等模型其实声明了 `[200K, 400K, 1M]`,你选 1M 是上游支持的。旧代码
50
+ 在目录某一刻没读到时退回静态 200K,同一会话的窗口就在 1M 与 200K 之间翻转:分母变小,压缩预算
51
+ 也从 80 万掉到约 10 万,于是一个才 10% 的会话被自动压缩,环从 60% 掉到 20% 再随历史增长爬回来。
52
+ 现在插件会记住每个模型上一次解析到的真实窗口,目录暂时读不到时继续用它;只有模型确实声明过的
53
+ 档位才会被采用(例如 `auto` 只支持 200K,存了 1M 也不会再按 1M 算)。
54
+
55
+ **给 CodeBuddy 设了 1M 上下文,为什么对话里上下文环会突然变得很小、过一阵又变大?** 因为窗口
56
+ 设置过去只告诉了 DSH,没告诉 CodeBuddy 的会话。CodeBuddy 只接受模型自己声明的档位
57
+ (`contextWindow.supportedLengths`):国际站目录里 `deepseek-v4.1-flash` 是 `[300K, 1M]`、
58
+ 默认 **300K**,而插件按物理上限 1M 上报给 DSH。内层会话按 300K 运行,历史一旦越过 276K(92%)
59
+ 就被 CLI 紧急压缩成摘要,上下文环从几十 % 掉到 2–3 %;下一轮历史重新补齐又涨回去,看起来就像
60
+ 「每轮被重置」。现在插件会把 DSH 显示的那个窗口用 `set_config{contextWindow}` 真正下发给内层
61
+ 会话,两边分母一致;改回「默认」时会显式下发模型默认值(CLI 拒绝清空),不支持档位的模型
62
+ (国内站全部报 `null`)页面显示「上游固定」,不再给无效下拉框。
63
+
64
+ **为什么 DeepSeek 官方能让模型改图,Qoder / CodeBuddy 只会说「找不到这张图片」?** 因为像素和路径
65
+ 是两件事。图片块让模型**看见**内容,但「取反色后保存」还需要知道文件在哪;DSH 原生适配器会在图片旁
66
+ 附上只读副本的路径并提示「编辑前先复制成可写 `.png`」,桥接此前只发了像素,模型只能去工作区里瞎找。
67
+ 现在 Qoder、CodeBuddy、MiniMax 都会带上同一句路径句柄(历史上传过的图片在重建上下文时也保留),
68
+ 模型可以直接复制、处理并保存。顺带修好另一个隐患:目录某一刻读不到时,不再把视觉模型临时当成
69
+ text-only,否则 DSH 会在适配器之前就把像素换成占位文本。
55
70
 
56
71
  **点了「登录」却没有弹出浏览器,或者弹出了两个?** CodeBuddy 的 CLI 在登录流程里会自己打开
57
72
  浏览器,插件只把登录链接显示在卡片上作为兜底,不再额外打开,所以一次登录只会有一个标签页。
@@ -86,6 +101,17 @@ SQLite 依赖就在这些脚本里,普通 `npm i -g` 装出来的 `mcode` 一
86
101
  时使用该区域自己的登录态;要换站请先在原站点点「退出登录」。两个区域的模型开关与上下文窗口
87
102
  仍然分别保存,切回已登录的区域会直接恢复选择。
88
103
 
104
+ **切模型时默认选哪一档思考强度?** 选该模型支持的最强档(有 `max` 就选 `max`,否则取它声明的
105
+ 最高档;只有 `low` / `high` 的模型取 `high`)。以前沿用上游自己的默认值,而它常常偏低:
106
+ CodeBuddy 的 `GLM-5.3` 在可选 `max` 时仍声明默认 `high`。在高级设置里填了
107
+ `defaultReasoningEffort` 时以它为准;该档位模型不支持时退回最强档。
108
+
109
+ **切换模型或思考档位时会卡一下?** 宿主每次切换都会重新解析一次模型元数据(档位、上下文窗口、
110
+ 读图能力),而这三个 provider 的模型目录都要拉起各自的 CLI 或 ACP 进程才能读到。以前这次解析会
111
+ 等待目录刷新,缓存一过期就要等一次完整读取(Qoder 冷启动最久)。现在解析先用上一次成功读到的
112
+ 目录立刻返回,刷新在后台进行;只有从未读到过目录的第一次解析才会等待。目录自身的 TTL 与失败
113
+ 回退规则不变。
114
+
89
115
  **切到 MiniMax 国际站后提示「本机 IP 不在服务区域」?** 这不是登录过期,而是网络位置被拒。
90
116
  MiniMax 的边缘节点在收到跨区请求时会返回 `307`,把 `.io` 重定向到 `.minimaxi.com`(反向亦然)。
91
117
  两个域名是不同 origin,浏览器/Node 跟随重定向时 `Authorization` 头会被丢弃,于是账号接口变成空的
package/client.js CHANGED
@@ -101,8 +101,7 @@ window.__ModuleLoader__.load({
101
101
  usagePlan: '套餐',
102
102
  usageUsed: '已用',
103
103
  usageRemaining: '剩余',
104
- usageOf: '/',
105
- usageCredits: 'credits',
104
+ usageCredits: '积分',
106
105
  usagePlanQuota: '套餐额度',
107
106
  usageAddOn: '加量包',
108
107
  usageOrgPackage: '组织资源包',
@@ -291,7 +290,6 @@ window.__ModuleLoader__.load({
291
290
  usagePlan: 'Plan',
292
291
  usageUsed: 'Used',
293
292
  usageRemaining: 'Remaining',
294
- usageOf: '/',
295
293
  usageCredits: 'credits',
296
294
  usagePlanQuota: 'Plan quota',
297
295
  usageAddOn: 'Add-on package',
@@ -562,10 +560,18 @@ window.__ModuleLoader__.load({
562
560
  log: { margin: '0', maxHeight: '240px', overflowY: 'auto', padding: '8px 10px', borderRadius: '8px', border: '1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.25))', background: 'var(--dsw-alias-bg-base, rgba(128,128,128,0.05))', fontFamily: 'ui-monospace, monospace', fontSize: '0.76em', lineHeight: 1.5, whiteSpace: 'pre-wrap', wordBreak: 'break-word' },
563
561
  usageCard: { display: 'flex', flexDirection: 'column', gap: '10px', padding: '14px 16px', borderRadius: '10px', border: '1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.25))', background: 'var(--dsw-alias-bg-base, rgba(128,128,128,0.03))' },
564
562
  usageHead: { display: 'flex', alignItems: 'baseline', gap: '10px', flexWrap: 'wrap' },
565
- usagePct: { marginLeft: 'auto', fontSize: '0.9em', fontWeight: 600 },
566
563
  progressOuter: { height: '8px', borderRadius: '999px', background: 'var(--dsw-alias-border-l2, rgba(128,128,128,0.22))', overflow: 'hidden' },
567
564
  progressInner: { height: '100%', borderRadius: '999px', background: 'var(--dsw-alias-brand-primary, #4c6ef5)', transition: 'width .25s ease' },
568
565
  progressDanger: { background: 'var(--dsw-alias-label-danger, #e03131)' },
566
+ creditStack: { display: 'flex', flexDirection: 'column', gap: '14px' },
567
+ creditMeter: { display: 'flex', flexDirection: 'column', gap: '6px' },
568
+ creditName: { fontSize: '0.8em', opacity: 0.55 },
569
+ creditRow: { display: 'flex', alignItems: 'baseline', gap: '10px', flexWrap: 'wrap', fontSize: '0.9em' },
570
+ creditLabel: { opacity: 0.62, minWidth: '56px' },
571
+ creditAmount: { fontWeight: 600, fontSize: '1.04em', fontVariantNumeric: 'tabular-nums' },
572
+ creditPct: { marginLeft: 'auto', opacity: 0.62, fontVariantNumeric: 'tabular-nums' },
573
+ creditBar: { height: '6px', borderRadius: '999px', background: 'var(--dsw-alias-border-l2, rgba(128,128,128,0.22))', overflow: 'hidden' },
574
+ creditBarFill: { height: '100%', borderRadius: '999px', background: 'var(--dsw-alias-brand-primary, #4c6ef5)', transition: 'width .25s ease' },
569
575
  usageLine: { display: 'flex', alignItems: 'baseline', gap: '8px', flexWrap: 'wrap', fontSize: '0.86em' },
570
576
  usageLabel: { opacity: 0.62, minWidth: '72px' },
571
577
  usageValue: { fontWeight: 500 },
@@ -765,32 +771,80 @@ window.__ModuleLoader__.load({
765
771
  return t('minimaxTokenRemainingHours').replace('{n}', String(Math.floor(minutes / 60)))
766
772
  }
767
773
 
774
+ /** A finite number, or undefined for anything else. */
775
+ function countOf(value) {
776
+ return typeof value === 'number' && Number.isFinite(value) ? value : undefined
777
+ }
778
+
779
+ /**
780
+ * The used/total reading one credit bucket is rendered from.
781
+ *
782
+ * Upstream quotes a bucket either as `used` + `total` or as `remaining` +
783
+ * `total` (Qoder's organization package calls the total `cap`). Both shapes
784
+ * are normalized here, and the percentage is computed from the same numbers
785
+ * the row prints: an upstream percentage that disagreed with them would
786
+ * make the bar contradict its own label.
787
+ */
788
+ function creditReading(bucket) {
789
+ if (bucket === null || typeof bucket !== 'object') return undefined
790
+ const total = countOf(bucket.total) ?? countOf(bucket.cap)
791
+ const remaining = countOf(bucket.remaining)
792
+ const used = countOf(bucket.used) ?? (total !== undefined && remaining !== undefined ? Math.max(0, total - remaining) : undefined)
793
+ const measured = total !== undefined && total > 0 && used !== undefined
794
+ ? Math.max(0, Math.min(100, (used / total) * 100))
795
+ : undefined
796
+ const pct = measured ?? percentOf(bucket.percentage)
797
+ // Some plans report only a percentage: it still fills the bar even though
798
+ // the row has no counts to print.
799
+ if (used === undefined && total === undefined && remaining === undefined) {
800
+ return pct === undefined ? undefined : { pct }
801
+ }
802
+ return { used, total, remaining, pct }
803
+ }
804
+
805
+ /** A bucket's unit, localized when upstream says the generic "credits". */
806
+ function creditUnit(t, bucket) {
807
+ const unit = typeof bucket?.unit === 'string' ? bucket.unit.trim() : ''
808
+ if (unit === '') return t('usageCredits')
809
+ return /^credits?$/i.test(unit) ? t('usageCredits') : unit
810
+ }
811
+
768
812
  /**
769
- * One quota bucket as a line: label, `remaining / total`, percentage.
813
+ * One credit bucket in the shape both account cards use: `used / total`
814
+ * with the percentage on the right and a bar underneath.
770
815
  *
771
- * Both editions quote the same shape (`userQuota`, `addOnQuota`,
772
- * `orgResourcePackage`), so the three render through one function; a bucket
773
- * the account does not have is simply not passed in.
816
+ * A bucket the account does not have reports no numbers at all, so it
817
+ * renders nothing rather than an empty bar.
774
818
  */
775
- function QuotaLine({ t, label, bucket, fallbackUnit }) {
776
- if (bucket === undefined || bucket === null) return null
777
- const total = bucket.total ?? bucket.cap
778
- const remaining = bucket.remaining
779
- const used = bucket.used
780
- // A plan bucket the account does not have is reported as all zeros; an
781
- // empty line describes nothing, so it is omitted rather than rendered.
782
- if ((total === undefined || total === 0) && remaining === undefined) return null
783
- const pct = percentOf(bucket.percentage)
784
- const unit = bucket.unit ?? fallbackUnit ?? t('usageCredits')
785
- const amount = remaining !== undefined && total !== undefined
786
- ? `${t('usageRemaining')} ${creditsOf(remaining)} ${t('usageOf')} ${creditsOf(total)} ${unit}`
787
- : total !== undefined
788
- ? `${t('usageUsed')} ${creditsOf(used)} ${t('usageOf')} ${creditsOf(total)} ${unit}`
789
- : '—'
790
- return h('div', { style: css.usageLine },
791
- h('span', { style: css.usageLabel }, label),
792
- h('span', { style: css.usageValue }, amount),
793
- pct === undefined ? null : h('span', { style: { opacity: 0.55 } }, `${Number(pct.toFixed(1))}%`),
819
+ function CreditMeter({ t, label, bucket, danger }) {
820
+ const reading = creditReading(bucket)
821
+ if (reading === undefined) return null
822
+ const { used, total, remaining, pct } = reading
823
+ const amount = total !== undefined && used !== undefined
824
+ ? `${creditsOf(used)} / ${creditsOf(total)} ${creditUnit(t, bucket)}`
825
+ : total !== undefined && remaining !== undefined
826
+ ? `${creditsOf(remaining)} / ${creditsOf(total)} ${creditUnit(t, bucket)}`
827
+ : used !== undefined
828
+ ? `${creditsOf(used)} ${creditUnit(t, bucket)}`
829
+ : remaining !== undefined
830
+ ? `${creditsOf(remaining)} ${creditUnit(t, bucket)}`
831
+ : undefined
832
+ return h('div', { style: css.creditMeter },
833
+ label === undefined ? null : h('div', { style: css.creditName }, label),
834
+ h('div', { style: css.creditRow },
835
+ amount === undefined ? null : h('span', { style: css.creditLabel }, used !== undefined ? t('usageUsed') : t('usageRemaining')),
836
+ amount === undefined ? null : h('span', { style: css.creditAmount }, amount),
837
+ pct === undefined ? null : h('span', { style: css.creditPct }, `${Number(pct.toFixed(1))}%`),
838
+ ),
839
+ pct === undefined ? null : h('div', { style: css.creditBar },
840
+ h('div', {
841
+ style: {
842
+ ...css.creditBarFill,
843
+ width: `${pct}%`,
844
+ ...(danger === true || pct >= 100 ? css.progressDanger : {}),
845
+ },
846
+ }),
847
+ ),
794
848
  )
795
849
  }
796
850
 
@@ -838,7 +892,6 @@ window.__ModuleLoader__.load({
838
892
  const usage = snapshot?.usage
839
893
  const account = snapshot?.account
840
894
  const error = failure ?? (snapshot?.usage === undefined && snapshot?.error !== undefined ? String(snapshot.error) : undefined)
841
- const pct = percentOf(usage?.totalUsagePercentage)
842
895
  const plan = account?.subscriptionType ?? usage?.userType ?? t('usageUnknownPlan')
843
896
  const identity = account?.name ?? account?.email ?? usage?.userId
844
897
  const exceeded = usage?.isQuotaExceeded === true
@@ -876,16 +929,31 @@ window.__ModuleLoader__.load({
876
929
  h('span', { style: css.usageLabel }, t('usagePlan')),
877
930
  h('span', { style: css.usageValue }, plan),
878
931
  exceeded ? h('span', { style: { ...css.err, fontWeight: 600 } }, t('usageExceeded')) : null,
879
- pct === undefined ? null : h('span', { style: css.usagePct }, `${Number(pct.toFixed(1))}%`),
880
932
  ),
881
- pct === undefined ? null : h('div', { style: css.progressOuter },
882
- h('div', {
883
- style: { ...css.progressInner, width: `${pct}%`, ...(exceeded ? css.progressDanger : {}) },
884
- }),
933
+ h('div', { style: css.creditStack },
934
+ (() => {
935
+ const buckets = [
936
+ [t('usagePlanQuota'), usage?.userQuota],
937
+ [t('usageAddOn'), usage?.addOnQuota],
938
+ [t('usageOrgPackage'), usage?.orgResourcePackage],
939
+ ]
940
+ // Some accounts report only the overall percentage; a card with no
941
+ // meter at all would hide the one number the endpoint did give.
942
+ if (buckets.some(([, bucket]) => creditReading(bucket) !== undefined)) {
943
+ return buckets.map(([label, bucket]) => h(CreditMeter, {
944
+ key: label, t, label, bucket, danger: exceeded,
945
+ }))
946
+ }
947
+ return percentOf(usage?.totalUsagePercentage) === undefined
948
+ ? null
949
+ : h(CreditMeter, {
950
+ t,
951
+ label: t('usagePlanQuota'),
952
+ bucket: { percentage: usage.totalUsagePercentage },
953
+ danger: exceeded,
954
+ })
955
+ })(),
885
956
  ),
886
- h(QuotaLine, { t, label: t('usagePlanQuota'), bucket: usage?.userQuota }),
887
- h(QuotaLine, { t, label: t('usageAddOn'), bucket: usage?.addOnQuota }),
888
- h(QuotaLine, { t, label: t('usageOrgPackage'), bucket: usage?.orgResourcePackage }),
889
957
  h('div', { style: css.usageFoot },
890
958
  expiry === undefined || neverExpires(expiry)
891
959
  ? h('span', null, `${t('usageExpires')} ${t('usageNever')}`)
@@ -1110,9 +1178,6 @@ window.__ModuleLoader__.load({
1110
1178
  .filter(part => typeof part === 'string' && part.length > 0)
1111
1179
  .join(' · ')
1112
1180
  const quota = account?.quota
1113
- const quotaPct = quota !== undefined && quota.total > 0
1114
- ? Math.max(0, Math.min(100, (quota.used / quota.total) * 100))
1115
- : undefined
1116
1181
  // Every package is kept: the collapsed row carries the count and the
1117
1182
  // combined total, so nothing disappears behind an invisible cut.
1118
1183
  const packages = Array.isArray(quota?.packages)
@@ -1167,15 +1232,12 @@ window.__ModuleLoader__.load({
1167
1232
  ? h('div', { style: css.err }, `${t('codebuddyQuotaFailed')}:${account.quotaError}`)
1168
1233
  : h('div', { style: css.note }, t('codebuddyNoQuota')))
1169
1234
  : h('div', { style: { display: 'flex', flexDirection: 'column', gap: '10px' } },
1170
- h('div', { style: css.usageLine },
1171
- h('span', { style: css.usageLabel }, t('codebuddyQuotaTitle')),
1172
- h('span', { style: css.usageValue },
1173
- `${t('usageRemaining')} ${creditsOf(quota.remaining)} ${t('usageOf')} ${creditsOf(quota.total)} ${t('usageCredits')}`),
1174
- quotaPct === undefined ? null : h('span', { style: css.usagePct }, `${quotaPct.toFixed(1)}%`),
1175
- ),
1176
- quotaPct === undefined ? null : h('div', { style: css.progressOuter },
1177
- h('div', { style: { ...css.progressInner, width: `${quotaPct}%` } }),
1178
- ),
1235
+ h(CreditMeter, {
1236
+ t,
1237
+ label: t('codebuddyQuotaTitle'),
1238
+ bucket: quota,
1239
+ danger: quota.total > 0 && quota.used >= quota.total,
1240
+ }),
1179
1241
  packages.length === 0 ? null : (() => {
1180
1242
  // Same rule as the other adapters: collapsed is one summary
1181
1243
  // row (count, combined total, nearest expiry), expanded is
@@ -2144,6 +2206,9 @@ window.__ModuleLoader__.load({
2144
2206
  // CLI rejects every other value, so a dropdown here would be a control
2145
2207
  // that never reaches the upstream. Show the value instead.
2146
2208
  const fixedWindow = m.contextWindowSelectable === false || choices.length === 0
2209
+ // The default window has its own entry; repeating it in the list reads
2210
+ // as two identical choices. A stored override equal to it still shows.
2211
+ const offered = choices.filter(n => n !== m.defaultContextWindow || n === m.override)
2147
2212
  return h('div', {
2148
2213
  key: m.id,
2149
2214
  style: { ...css.row, ...(index === 0 ? css.rowFirst : {}), ...(m.enabled ? {} : css.rowOff) },
@@ -2182,7 +2247,7 @@ window.__ModuleLoader__.load({
2182
2247
  },
2183
2248
  },
2184
2249
  h('option', { key: 'default', value: '' }, `${t('windowDefault')} · ${windowLabel(m.defaultContextWindow)}`),
2185
- choices.map(n => h('option', { key: String(n), value: String(n) }, windowLabel(n))),
2250
+ offered.map(n => h('option', { key: String(n), value: String(n) }, windowLabel(n))),
2186
2251
  ),
2187
2252
  )
2188
2253
  })
@@ -2513,7 +2578,7 @@ window.__ModuleLoader__.load({
2513
2578
  exports.name = 'dsh-agent-sdk-bridge'
2514
2579
  exports.__test = {
2515
2580
  windowLabel, priceSuffix, ADVANCED, BRANDS, zh, en,
2516
- SettingsPage, BundleSettings, UsageCard, CodeBuddyCard, QuotaLine, creditsOf, neverExpires,
2581
+ SettingsPage, BundleSettings, UsageCard, CodeBuddyCard, CreditMeter, creditReading, creditUnit, creditsOf, neverExpires,
2517
2582
  dateLabel, tokenExpiryText, packageSummary,
2518
2583
  readCache, writeCache,
2519
2584
  }