@xixka/dsh-hub 0.2.1-rc.14 → 0.2.1-rc.15

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 (2) hide show
  1. package/lib/client/jet-hub.js +1037 -681
  2. package/package.json +2 -1
@@ -1108,40 +1108,132 @@ var STYLES = `
1108
1108
  .dim-jh-zcDialog .dim-jh-zcProvider { display: flex; align-items: center; gap: 8px; margin: 0 0 16px; font-size: 13px; }
1109
1109
  .dim-jh-zcDialogActions { display: flex; justify-content: flex-end; gap: 8px; }
1110
1110
 
1111
- /* ── 积分用量(侧边栏板块,2026-10-29 迁自会话输入区徽标) ────────────────
1112
- 板块结构(usage-panel.js):页面标题 → 渠道选择器(chips)→ 用量卡片
1113
- (usage-badge.js 的 .dim-jh-usageCard;卡片内部沿用原浮层的 .dim-jh-badge*
1114
- 系列与 .dim-jh-quotaBar 进度条,几何口径未动 —— 见下方各条)。
1115
- ⚠️ 原胶囊(.dim-jh-badge / .dim-jh-badgeBtn / .dim-jh-badgeText…)与浮层
1116
- (.dim-jh-badgePop 及其窄屏 fixed 块)已随会话徽标一并删除:卡片是普通
1117
- 文档流里的块,不存在「定位退化撑坏宿主布局」的那类风险。
1118
- ⚠️ 本段注释里**不能出现反引号**(本文件整体是 JS 模板字符串,会提前终止)。 */
1119
- .dim-jh-usagePanel { display: flex; flex-direction: column; gap: 14px; max-width: 560px; }
1120
- .dim-jh-usageHead { display: flex; flex-direction: column; gap: 0; }
1121
- .dim-jh-usageTitle { font-size: 15px; font-weight: 600; line-height: 22px; color: var(--dsw-alias-label-primary); }
1122
- .dim-jh-usageSub { margin-top: 4px; font-size: 11px; line-height: 16px; color: var(--dsw-alias-label-tertiary); }
1123
- /* 渠道选择器:换行排列的 chips。本仓库无 select 先例,按钮组 + aria-pressed
1124
- 与偏好分段控件(.dim-jh-badgePref)同款做法。 */
1125
- .dim-jh-usageRail { display: flex; flex-wrap: wrap; gap: 6px; }
1126
- .dim-jh-usageChip { box-sizing: border-box; padding: 3px 10px; border: .5px solid var(--dsw-alias-border-l2); border-radius: 999px; background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-secondary); font: inherit; font-size: 11px; line-height: 1.5; white-space: nowrap; cursor: pointer; transition: background .15s ease, color .15s ease, border-color .15s ease; }
1127
- .dim-jh-usageChip:hover { background: var(--dsw-alias-bg-layer-3); color: var(--dsw-alias-label-primary); }
1128
- .dim-jh-usageChip[aria-pressed="true"] { border-color: color-mix(in srgb, #1677ff 45%, var(--dsw-alias-border-l2)); background: color-mix(in srgb, #1677ff 10%, var(--dsw-alias-bg-layer-2)); color: var(--dsw-alias-brand-primary); font-weight: 600; }
1129
- /* 用量卡片:几何口径沿原浮层(宽 280px → 面板里放宽到 480px 上限,字号与
1130
- 节距不动)。flex 列无 gap —— 节与节之间的间距由 .dim-jh-badgeSection 的
1131
- margin-top 提供(与原 .dim-jh-badgePop 完全同款,不要在这里另加 gap)。 */
1132
- .dim-jh-usageCard { width: min(480px, 100%); display: flex; flex-direction: column; padding: 9px 12px 12px; border: .5px solid var(--dsw-alias-border-l2); border-radius: 11px; background: var(--dsw-alias-bg-layer-1); box-shadow: 0 1px 2px rgba(0, 0, 0, .06); text-align: left; white-space: normal; }
1133
- /* 卡片头的渠道名:.dim-jh-badgeTitle 的 max-width:118px 是给 280px 浮层头部
1134
- 量的;面板卡片放宽到 480px,且 auto 渠道名更长(含实际渠道/倍率/倒计时),
1135
- 故放宽上限并允许收缩出省略号(完整文案在 title 悬浮提示里)。 */
1136
- .dim-jh-usageCard .dim-jh-badgeTitle { flex: 0 1 auto; max-width: none; }
1137
- /* 读数行:原折叠胶囊的读数迁居后常驻在卡片头部下方(面板没有折叠态)。
1138
- 字号比正文大一档 + 半粗 —— 它是整张卡片的结论行。
1139
- data-tone 跟头部状态点是同一个值(badgeView 的 tone)。 */
1140
- .dim-jh-usageReading { display: flex; align-items: baseline; gap: 6px; margin: 2px 0 1px; }
1141
- .dim-jh-usageReadingValue { font-size: 15px; font-weight: 600; line-height: 22px; font-variant-numeric: tabular-nums; color: var(--dsw-alias-label-primary); }
1142
- .dim-jh-usageReadingValue[data-tone="warn"] { color: var(--dsw-alias-state-warn-primary); }
1143
- .dim-jh-usageReadingValue[data-tone="error"] { color: var(--dsw-alias-state-error-primary); }
1144
- .dim-jh-usageReadingValue[data-tone="muted"] { color: var(--dsw-alias-label-secondary); font-weight: 500; }
1111
+ /* ── 用量徽标(会话输入区,模型选择器旁) ────────────────────────────────
1112
+ 折叠态是一枚紧凑按钮,浮层用 position:absolute + bottom:calc(100% + 8px)
1113
+ 向上展开(贴着输入区上沿,不遮挡输入框)。
1114
+ ⚠ 输入区(RlGAzG_root / dock / trailing / standardControls)没有
1115
+ overflow:hidden(只有文本域 .RlGAzG_scroll 是 overflow-y:auto),故浮层
1116
+ 不会被裁剪 —— 若将来上游给这些容器加上裁剪,这里要改成固定定位 + 锚点换算。
1117
+
1118
+ 浮层尺寸口径(用户 2026-10-02:「小巧、美观,但信息不能缺失」→「不够小巧和精致」
1119
+ →「额度那块文字居中 + 浅色模式下按钮和线条太不明显」三轮迭代后定稿):
1120
+ - 宽 **280px**、正文字号 10–11px、节间距 7px、进度条 3px;
1121
+ - **每个订阅窗口只占一行**:名称 / 进度条 / 百分比 / 重置倒计时;
1122
+ - 订阅额度那块用 grid **整块水平居中**(justify-content: center),列仍对齐;
1123
+ - 按钮与分隔线一律用**主题描边**(--dsw-alias-border-l2,全不透明)——
1124
+ 试过「去线条」,浅色模式下按钮和分区线会看不见,用户明确反馈后撤回;
1125
+ - 阴影双层(近处极淡 + 远处扩散),比单层大阴影更精致。
1126
+ 信息项一项未减(渠道名、更新时间与缓存标记、偏好三态、窗口百分比与倒计时、
1127
+ 套餐名称与到期与账号数、逐账号余额与分桶、停用/失败计数、两个签到按钮)。 */
1128
+ /* ⚠️ 徽标宽度会**挤压右侧的模型选择器**(真机报障 2026-10-02)。
1129
+ *
1130
+ * ## 症状
1131
+ *
1132
+ * 徽标与模型选择器同在 composer 一行(徽标 order:100 在模型选择器左侧),
1133
+ * 而本元素是 flex: none —— 不参与收缩。原先 max-width: 280px 会把
1134
+ * 「图标 + 模型名 + ▾」的模型选择器压到只剩几十 px,**图标被挤没**,
1135
+ * 用户看到「只有放大到很大才能看到那个图标」。
1136
+ *
1137
+ * ## 为什么会暴露
1138
+ *
1139
+ * 早期徽标永不显示(store.current 恒为 null 的缺陷期),模型选择器独占
1140
+ * 整行所以一直正常;徽标修好后开始占位,才暴露出这个抢占。
1141
+ *
1142
+ * ## 两级收敛(用户定:1+2)
1143
+ *
1144
+ * ## 宽度:**内容自适应**,216px 只是上限(不是目标宽度)
1145
+ *
1146
+ * 胶囊本身是**内容自适应**的:宽度由实际文字撑开,短内容就短
1147
+ * (Cline • 5积分 仅 93px),不会有固定留白。下面的 max-width 只在
1148
+ * 内容**过长**时兜底,防止挤压右侧的模型选择器。
1149
+ *
1150
+ * ⚠️ 2026-10-03 上限从 150px 提到 **216px**(用户报障「供应商名字显示不完整」
1151
+ * 之后又提了一次)。两次报障、同一条链路的两个不同成因:
1152
+ * 1. **数字被截**(第一次):整句塞进一个 overflow:hidden 的 span,省略号从右往左
1153
+ * 吃掉了余额。修法是**结构**(拆成可独立收缩的 span,见 badge-model.js 的
1154
+ * readingOf 与 usage-badge.js 的三段式渲染);
1155
+ * 2. **渠道名被截**(第二次):结构修好后,186px 仍不够长渠道名 + 长余额,
1156
+ * 于是省略号落到**名字**上(用户截图:CodeArts (华为…)。216px 解决它。
1157
+ *
1158
+ * **216 是量出来的,不是拍的**:实测 13 个渠道展示名 × 10 种现实读数
1159
+ * (含 123456.78积分 / 9499.84积分 / 94.54MToken / 0积分)共 130 组,
1160
+ * 需要的最宽度是 **209.34px**(WorkBuddy (国际版) • 123456.78积分),
1161
+ * 216px 全部装得下且留 6.7px 余量(字体回退时字宽会变)。
1162
+ *
1163
+ * ⚠️ **上限不能再往上放**:实测把上限放到「无上限」时,极窄 composer(220px)
1164
+ * 下胶囊会**溢出容器 8.3px** —— 那正是 2026-10-02「模型选择器图标被挤没」
1165
+ * 的形态。内容自适应 + 合理上限,两者缺一不可。
1166
+ * 兜底退化顺序:超长时**渠道名**先出省略号,**余额一个字都不会少**
1167
+ * (.dim-jh-badgeReading 是 flex: none)。
1168
+ *
1169
+ * ⚠️ button 元素**本来就是 border-box**(UA 默认样式表),故下面的 box-sizing
1170
+ * 是**显式写出**(防止哪天元素换成 span/div 时语义悄悄变成内容盒),不是修复。
1171
+ * ⚠️⚠️ 本段注释里**不能出现反引号**(本文件整体是 JS 模板字符串,会提前终止)。
1172
+ * ② 容器再窄时(< 720px,媒体查询挂在**全局宽度**上:composer 宽度受
1173
+ * 侧栏影响,用容器查询无法表达「右侧还剩多少」)**只留状态点**,
1174
+ * 文字与 chevron 全部隐藏 —— 此时代理器优先级让给模型选择器。 */
1175
+ /* ⚠️ flex: 0 1 auto(而非 none):胶囊自身也要能收缩。它是 flex: none 时
1176
+ 宽度只由 max-width 兜底,而 max-width 只在**内容超标**时生效 —— 容器更窄时
1177
+ 它会连同右侧模型选择器一起溢出。允许收缩后,空间不足时胶囊与选择器一起让位,
1178
+ 且胶囊内部退化是有序的(先名字出省略号,数字最后才动)。 */
1179
+ .dim-jh-badge { position: relative; display: flex; align-items: center; flex: 0 1 auto; min-width: 0; }
1180
+ /* ⚠️ box-sizing 是**显式写出**的,不是修复:button 的 UA 默认样式表本就是
1181
+ border-box(实测 offsetWidth 与 max-width 相等)。写上它只为在元素类型被改
1182
+ (span/div 默认是 content-box)时语义不悄悄漂移 —— 那种情况下 max-width 会从
1183
+ 「占位宽度」变成「内容宽度」,胶囊会突然变宽 19px 而这行代码看着毫无变化。 */
1184
+ .dim-jh-badgeBtn { box-sizing: border-box; display: flex; align-items: center; gap: 5px; max-width: 216px; min-width: 0; padding: 2px 9px; border: .5px solid var(--dsw-alias-border-l2); border-radius: 999px; background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-secondary); font: inherit; font-size: 11px; line-height: 1.5; cursor: pointer; white-space: nowrap; font-variant-numeric: tabular-nums; transition: background .15s ease, color .15s ease, border-color .15s ease; }
1185
+ .dim-jh-badgeBtn:hover { background: var(--dsw-alias-bg-layer-3); color: var(--dsw-alias-label-primary); }
1186
+ .dim-jh-badgeBtn[aria-expanded="true"] { background: var(--dsw-alias-bg-layer-3); color: var(--dsw-alias-label-primary); border-color: color-mix(in srgb, #1677ff 45%, var(--dsw-alias-border-l2)); }
1187
+ /* 聚合「待首次请求」占位胶囊(用户报障 2026-10-08:「也没胶囊了?」)。
1188
+ ⚠️ 刻意与 .dim-jh-badgeBtn **外观一致但不共用类名**:那个类名带 cursor:pointer
1189
+ 与 :hover 反馈,而这里没有任何可点的东西(无历史 ⇒ 没有余额可展开)。
1190
+ 给一个点了没反应的按钮比没有按钮更糟。
1191
+ ⚠️ 宽度口径与 .dim-jh-badgeBtn 同步(gap 5px / padding 2px 9px / 字号 11px):
1192
+ 两者会在同一位置交替出现(首次请求成功后换成真胶囊),尺寸不一致会看到跳动。 */
1193
+ .dim-jh-badgePending { display: inline-flex; align-items: center; gap: 5px; max-width: 216px; min-width: 0; padding: 2px 9px; border: .5px solid var(--dsw-alias-border-l2); border-radius: 999px; background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-tertiary); font-size: 11px; line-height: 1.5; white-space: nowrap; }
1194
+ .dim-jh-badgePending > span:last-child { overflow: hidden; text-overflow: ellipsis; }
1195
+ /* 三段式文本容器:渠道名 + 分隔符 + 读数。
1196
+ ⚠️ 必须是 flex 容器,两个文本子项才能各自独立收缩(这正是「数字不被截」的前提)。 */
1197
+ .dim-jh-badgeText { display: flex; align-items: center; min-width: 0; }
1198
+ /* ⚠️ 让位顺序:中段说明(999) → 渠道名(99) → 读数(none,**不参与收缩**)。
1199
+ 收缩量按 flex-shrink × flex-basis 加权分配,999 与 99 相差一个数量级,
1200
+ 故「包名先走、渠道名其次」,读数一个字都不会少。
1201
+ flex-grow 一律为 0:胶囊是内容自适应宽度,任何 grow 都只会让它在宽容器里虚胖。
1202
+ min-width:0 是省略号生效的前提(flex 子项默认 min-width:auto,会撑破 max-width)。 */
1203
+ .dim-jh-badgeName { flex: 0 99 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1204
+ /* 分隔符「•」:定宽不收缩,两侧间距由 margin 给。
1205
+ ⚠️ 这里的 3px **不能**换成前后空格:flex 容器把 span 之间只含空白的文本节点
1206
+ 渲染成**零宽**(实测 gap=0,节点还在但看不见),空格会静默消失。
1207
+ 带空格的那份写法(BADGE_SEP = ' • ')只用于 title / aria-label 那句整文。 */
1208
+ .dim-jh-badgeSep { flex: none; margin: 0 3px; }
1209
+ /* 中段说明(只有套餐模式有值,如包名 Free Plan Subscription)。
1210
+ ⚠️ 收缩权重**最大**(999):它比渠道名更该让位 —— 包名多为样板字、且长,
1211
+ 而用户认得出自己选的渠道。
1212
+ ⚠️ 它被压到 0 宽时(内容过长)该节点仍在,会留下一个「悬空的分隔符」;
1213
+ 这在胶囊这一行是可接受的(完整文案在 title 与弹窗里),故不额外做条件渲染。 */
1214
+ .dim-jh-badgeDetail { flex: 0 999 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1215
+ /* ⚠️⚠️ 读数必须 flex: none(**完全不收缩**),不能写 flex: 0 1 auto。
1216
+ 这是第二处、也是更隐蔽的一处「数字被截」成因,**靠截图才发现**:
1217
+
1218
+ 收缩量按 flex-shrink × flex-basis 加权分配,读数那一份虽小却**不为零** ——
1219
+ 实测读数被分到 0.77px 的收缩(getBoundingClientRect 宽 78.23 / 内容宽 79)。
1220
+ 而 text-overflow: ellipsis 的触发条件是 scrollWidth > clientWidth,
1221
+ **亚像素级的收缩就足以命中** ⇒ 最后一个字被换成「…」,
1222
+ 视觉上和「整段被截」一样严重。
1223
+
1224
+ ⚠️ 更坑的是**量不出来**:clientWidth 取整,53.97 报成 54,
1225
+ 于是 scrollWidth > clientWidth 判为 false —— 我用它写的「数字是否完整」
1226
+ 断言一路全绿,而截图里明明白白写着「347.87积…」。
1227
+ 教训:判断省略号要看**截图**或用小数宽度(getBoundingClientRect),
1228
+ 不能用取整后的 clientWidth。
1229
+
1230
+ ⚠️ 类名刻意**不叫 .dim-jh-badgeValue**:那个名字已被弹窗读数占用,且那条规则
1231
+ (font-weight:600)排在样式表更后面 —— 同名会让胶囊数字被静默加粗。
1232
+
1233
+ ⇒ 读数恒定完整;全部收缩由 .dim-jh-badgeDetail(999) 与 .dim-jh-badgeName(99)
1234
+ 承担,两者最坏缩到 0 也放得下(读数最宽约 97px + 分隔符与内边距 ≈ 131px
1235
+ < 186px 上限)。 */
1236
+ .dim-jh-badgeReading { flex: none; min-width: 0; white-space: nowrap; }
1145
1237
  /* 「这个读数不完整」的标记(合计少算了账号时才出现),排在读数**之后**。
1146
1238
  ⚠️ 必须与读数同级 flex: none:它是**补语**,被省略号吃掉就等于没标 —— 而它要
1147
1239
  提醒的恰恰是「别把这个数字当真」,看不见比不标更糟。
@@ -1150,10 +1242,22 @@ var STYLES = `
1150
1242
  字号小一档并压紧行高,让它读起来像角标而不是读数的一部分。 */
1151
1243
  .dim-jh-badgeWarn { flex: none; font-size: 10px; line-height: 1; color: var(--dsw-alias-state-warn-primary); cursor: help; }
1152
1244
 
1245
+ /* ② 窄屏收敛:只留状态点,文字与 chevron 让位给模型选择器。
1246
+ * 阈值 720px 是实测桌面版在 100% 缩放下「徽标 216px + 模型选择器 ≥ 240px」的临界值。
1247
+ * ⚠️⚠️ 本段的**位置**是功能性的,不要为了排版把它挪到 .dim-jh-badgeText 之前:
1248
+ * 它与 ".dim-jh-badgeText { display: flex }" 特异性相同(都是单个类),
1249
+ * 靠**源顺序**决定胜负 —— 一旦被排到前面,窄屏下 display:none 会被
1250
+ * 后面的 display:flex 覆盖,文字重新出现并挤压模型选择器(静默回归)。 */
1251
+ @media (max-width: 720px) { .dim-jh-badgeText, .dim-jh-badgeBtn > svg, .dim-jh-badgeBtn > .dim-jh-badgeChevron { display: none; } .dim-jh-badgeBtn { max-width: none; padding: 2px 6px; } }
1153
1252
  .dim-jh-badgeDot { width: 5px; height: 5px; flex: none; border-radius: 999px; background: var(--dsw-alias-state-success-primary); }
1154
1253
  .dim-jh-badgeDot[data-tone="warn"] { background: var(--dsw-alias-state-warn-primary); }
1155
1254
  .dim-jh-badgeDot[data-tone="error"] { background: var(--dsw-alias-state-error-primary); }
1156
1255
  .dim-jh-badgeDot[data-tone="muted"] { background: var(--dsw-alias-label-tertiary); }
1256
+ .dim-jh-badgePop { position: absolute; bottom: calc(100% + 8px); right: 0; z-index: 40; width: 280px; max-width: min(280px, 86vw); max-height: 58vh; overflow-y: auto; display: flex; flex-direction: column; padding: 9px 10px 10px; border: .5px solid var(--dsw-alias-border-l2); border-radius: 11px; background: var(--dsw-alias-bg-layer-1); box-shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .14); text-align: left; white-space: normal; }
1257
+ /* 窄屏时徽标只留状态点,弹窗也随之收窄(否则它会盖住模型选择器)。
1258
+ * 宽度写 min() 而非媒体查询覆盖:弹窗是 absolute,媒体查询命中时按钮虽已
1259
+ * 收窄,但弹窗仍按 280px 渲染会显得与触发点不匹配。 */
1260
+ @media (max-width: 720px) { .dim-jh-badgePop { width: 220px; max-width: min(220px, 76vw); } }
1157
1261
  .dim-jh-badgeHead { display: flex; align-items: center; gap: 5px; padding-bottom: 7px; }
1158
1262
  .dim-jh-badgeTitle { flex: none; max-width: 118px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; font-weight: 600; color: var(--dsw-alias-label-primary); }
1159
1263
  .dim-jh-badgeAt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; color: var(--dsw-alias-label-tertiary); font-variant-numeric: tabular-nums; }
@@ -1254,7 +1358,7 @@ var STYLES = `
1254
1358
  /* 「展开其余 N 个账号」/「收起」:纯文字按钮,左对齐、不占满宽。
1255
1359
  ⚠️ 刻意**不复用** .dim-jh-badgeAction:那条规则是 flex:1 的实心按钮(用于签到),
1256
1360
  放在明细列表下面会抢走视觉焦点 —— 用户要的是「明细可以收起来」,不是一个主操作。
1257
- align-self: flex-start 是因为父容器(.dim-jh-usageCard)是 flex 列(默认 stretch)。 */
1361
+ align-self: flex-start 是因为父容器 .dim-jh-badgePop 是 flex 列(默认 stretch)。 */
1258
1362
  .dim-jh-badgeMore { align-self: flex-start; margin-top: 3px; padding: 1px 0; border: 0; background: none; font: inherit; font-size: 10px; line-height: 1.6; color: var(--dsw-alias-link); cursor: pointer; }
1259
1363
  .dim-jh-badgeMore:hover { color: var(--dsw-alias-brand-primary); text-decoration: underline; }
1260
1364
 
@@ -1398,6 +1502,85 @@ var STYLES = `
1398
1502
  .dim-jh-panel { padding: 14px 12px; }
1399
1503
  }
1400
1504
 
1505
+ /* ── 窄屏:用量浮层(聊天输入区那枚徽标展开的面板)──
1506
+ POC(2026-10-17,报障「对话框的这里 ui 也需要适配」,附窄屏截图)。
1507
+ ⚠️ 2026-10-20 审计整改:本块的**根因描述与 z-index 论证都被推翻重写**,
1508
+ 下面每一段都标了「已订正」。原描述保留在末尾的「历史」段里供追溯。
1509
+
1510
+ ## 已订正 ①:真正的失效机制不是「左边缘被裁」
1511
+ 原描述说窄屏下浮层左边缘越出视口 89px。按宿主**真实** composer 布局复刻
1512
+ PRE-PR 形态实测:徽标在 .uV2eYG_trailing 里(该行有 margin-left: auto)
1513
+ ⇒ 徽标靠**右**(VW=492 时 L=334 R=468),浮层向左展开 220px 得
1514
+ popL=248 ⇒ **完全没有越界**。原描述里 badge=134~151(靠左)在宿主布局中
1515
+ 不成立。⇒ 本块的真实收益是「浮层改为视口锚定、不再跟着徽标跑,且更宽」,
1516
+ 不是「修裁切」。
1517
+
1518
+ ## 已订正 ②:真正需要 CSS 兜底的是**旧内核的 containing block 偏差**
1519
+ 宿主 composer 工具行 .uV2eYG_row 带 container-type: inline-size,而徽标
1520
+ 是它的后代。实测两引擎行为不同:
1521
+ - Chromium 154:inline-size containment 只含 inline 轴,**不**创建 fixed
1522
+ 的 containing block ⇒ fixed 仍按视口锚定(符合规范);
1523
+ - Edge 122:把它当 layout containment ⇒ fixed 改为**相对该祖先**定位
1524
+ ⇒ left/right/bottom 全变成「相对 composer 行」的坐标,浮层跟着 composer
1525
+ 跑、宽度被压缩(实测 popLeft 24→124、width 476→344)。
1526
+ ⇒ 只靠 CSS 无法在旧内核上做视口锚定,故窄屏浮层改由 usage-badge.js
1527
+ **portal 到 document.body**(body 之上无 containment 祖先,两引擎都按视口
1528
+ 锚定)。本块仍保留全部承重声明作**兜底**:内联样式一旦被改坏,这里还能挡住。
1529
+
1530
+ ## 已订正 ③:bottom 必须用宿主的 composer 高度变量,不能硬编码
1531
+ 宿主用 ResizeObserver 把真实 composer 高度写进 --dsh-composer-height
1532
+ (dsh-client-ui-conversation 的 ConversationContent),其 CSS fallback 是
1533
+ **152px**(宿主三处都写 var(--dsh-composer-height,152px))。
1534
+ 原实现硬编码 88px —— 实测 composer=152px 时浮层**压住输入区 64px**,并
1535
+ **盖住「用量」徽标按钮**(命中测试点到的不是按钮,是浮层内的 DIV)
1536
+ ⇒ 用户点不到。改用变量后 gap=0、徽标可点(两引擎、多档 composer 高度均实测)。
1537
+ ⚠️ 该变量能被浮层继承:CSS 变量沿 **DOM 祖先链**继承,与定位方式无关;
1538
+ portal 到 body 后 body 仍在 scroller 的**兄弟**位置?—— 不是,body 是共同祖先,
1539
+ 故变量照样继承得到(已实测 popover 侧 getComputedStyle 读到 152px/220px)。
1540
+
1541
+ ## 已订正 ④:z-index 的区间是 (1101, 3000),不是 (250, 1000)
1542
+ 原论证的下限 250 只考虑了**外部外壳**(dsh-mobile),漏了**宿主自己**:
1543
+ - 宿主 79 处 z-index 里有 **6 处 1100**(chat 的 bRhRbq_panel、
1544
+ conversation 的 JObwrW_panel【composer 里的 ContextMeter,与徽标同一行】、
1545
+ model-selection 的 _7KE1Ra_menu【与徽标同一行的模型选择菜单】、
1546
+ plugin-manager、schedule ×2);
1547
+ - 另有 **3 处全屏 overlay**:attachment 1000、settings-general 1000、
1548
+ settings-account 1001(还有 onboarding 900)。
1549
+ 浮层若取 300,上述任一出现就把浮层整块盖住。
1550
+ 原上限 1000 的锚点 .dim-jh-loginOverlay 是**死规则**:全仓 className 用法
1551
+ 0 命中、git 历史从未渲染过(只剩一条 CSS + 注释);且它与浮层**不在同一
1552
+ stacking context**(分属 settings 页树与 composer 树,两树中间的
1553
+ .dim-jh-page/.dim-jh-layout/.dim-jh-rail/.dim-jh-panel 全无 z-index)
1554
+ ⇒ z-index 本就不可比。
1555
+ ⇒ 改为按**真正同族**的 .dim-jh-modalOverlay(3000) 定上限,按宿主最高
1556
+ overlay(1001) 与 ContextMeter(1100) 定下限 ⇒ 取 **1200**((1101, 3000) 内)。
1557
+ 另注:dsh-mobile 的 [data-shell-overlay] 恰好是 z-index:300(带 !important),
1558
+ 原取值与它**完全相等** ⇒ 同层级时后出现的 DOM 胜出,不可预测;1200 也消除了这点。
1559
+
1560
+ ⚠️ 本注释内**不得出现反引号**:本文件整体是模板字符串,反引号会提前闭合它
1561
+ (AGENTS.md 红线;本文件的 usage-badge-client.spec.ts 有专条用例逐块扫描注释)。
1562
+
1563
+ ## 历史(已推翻,勿据此改回)
1564
+ 原描述:根因是「VW=492 badge=134~151 pop=-89~151 L_OVER=true」;取 300 的
1565
+ 理由是「下限 > 250 压过 dsh-mobile details、上限 < 1000 因为
1566
+ .dim-jh-loginOverlay 是 1000」;bottom 硬编码 88px。上述三处均已订正。 */
1567
+ @media (max-width: 720px) {
1568
+ .dim-jh-badgePop {
1569
+ position: fixed !important;
1570
+ left: 8px !important;
1571
+ right: 8px !important;
1572
+ top: auto !important;
1573
+ bottom: calc(env(safe-area-inset-bottom, 0px) + var(--dsh-composer-height, 152px)) !important;
1574
+ width: auto !important;
1575
+ max-width: none !important;
1576
+ /* ⚠️ 100dvh 而不是 100vh:移动端地址栏收放会让 100vh 与真实可视高度脱节。
1577
+ 外加 max(120px, ...) 下限 —— 原写法在 vh<=140 时算出 0 或负值,实测
1578
+ vh=120 时 max-height 被压成 0px(浮层完全不可见却仍占位)、
1579
+ vh=60 时整块飞出屏幕上方。 */
1580
+ max-height: max(120px, calc(100dvh - 160px)) !important;
1581
+ z-index: 1200 !important;
1582
+ }
1583
+ }
1401
1584
 
1402
1585
  /* ── 插件详情页(plugins.bundle.config)的自有设置卡片 ──
1403
1586
 
@@ -13307,423 +13490,108 @@ function startCarrierContribution(options = {}) {
13307
13490
  };
13308
13491
  }
13309
13492
 
13310
- // plugin-src/client/panel-entry.js
13311
- var React7 = __toESM(require("react"), 1);
13312
-
13313
- // plugin-src/client/error-boundary.js
13493
+ // plugin-src/client/usage-badge.js
13314
13494
  var React6 = __toESM(require("react"), 1);
13315
- var NO_ERROR = Symbol("jet-hub:no-error");
13316
- function describeThrown(error) {
13317
- try {
13318
- if (error !== null && error !== void 0 && typeof error.message === "string" && error.message.length > 0) {
13319
- return error.message;
13320
- }
13321
- } catch {
13322
- }
13323
- try {
13324
- return String(error);
13325
- } catch {
13326
- return "(抛出值无法转为文本,请查看控制台)";
13327
- }
13328
- }
13329
- function withErrorBoundary(Inner, options) {
13330
- const label = options !== null && typeof options === "object" && typeof options.label === "string" && options.label.length > 0 ? options.label : "这个面板";
13331
- class PanelErrorBoundary extends React6.Component {
13332
- constructor(props) {
13333
- super(props);
13334
- this.state = { error: NO_ERROR };
13335
- }
13336
- static getDerivedStateFromError(error) {
13337
- return { error };
13338
- }
13339
- componentDidCatch(error, info) {
13340
- console.error(`[jet-hub] ${label}渲染失败,已拦住(页面其余部分继续可用):`, error, info?.componentStack);
13341
- }
13342
- render() {
13343
- const error = this.state.error;
13344
- if (error === NO_ERROR) return React6.createElement(Inner, this.props);
13345
- const message = describeThrown(error);
13346
- return React6.createElement(
13347
- "div",
13348
- {
13349
- className: "dim-jh-probeNotice",
13350
- "data-tone": "error",
13351
- role: "alert",
13352
- style: { margin: "16px" }
13353
- },
13354
- React6.createElement("div", null, `${label}渲染失败,已拦住 —— 其余页面仍可正常使用,不必重启。`),
13355
- React6.createElement("div", { style: { marginTop: "6px", fontFamily: "monospace", fontSize: "12px" } }, message),
13356
- // ⚠️ **必须给出可自我恢复的出路**(2026-10-25 审计 A3-2)。
13357
- //
13358
- // 本 fallback 是**粘性**的:没有 `key`、也没有 `componentDidUpdate`
13359
- // 重置 ⇒ 同一实例一旦进 error 就永远显示 fallback(数据恢复了也不回来)。
13360
- // 审计实测:数据恢复后仍显示 fallback,只有**新建实例**才恢复。
13361
- //
13362
- // 而用户其实**不必重启**:宿主 `SettingsPanel` 在 `open === false` 时整棵
13363
- // 不挂载、`main` 是 keyed 槽 ⇒「关掉设置再打开」/「切走再切回」都能恢复。
13364
- // 但**这条路径不可发现** —— 用户看到一块报错,不知道关掉再打开就能好。
13365
- //
13366
- // ⇒ 两件事:①给一个**就地重试**(`setState` 回 `NO_ERROR`,子树随即重挂载,
13367
- // 比让用户摸索「关掉再打开」快得多);②把那条路径**写出来**当兜底。
13368
- React6.createElement(
13369
- "div",
13370
- { style: { marginTop: "8px" } },
13371
- React6.createElement("button", {
13372
- type: "button",
13373
- className: "dim-jh-btn",
13374
- onClick: () => {
13375
- this.setState({ error: NO_ERROR });
13376
- }
13377
- }, "重试"),
13378
- React6.createElement(
13379
- "span",
13380
- { style: { marginLeft: "8px", opacity: 0.75 } },
13381
- "也可以关掉这一节再重新打开(或切到别的页面再切回来)来恢复。"
13382
- )
13383
- ),
13384
- React6.createElement(
13385
- "div",
13386
- { style: { marginTop: "6px" } },
13387
- "这是插件的缺陷,不是你操作错了。把上面这行报错连同「当时点了什么」一起反馈即可。"
13388
- )
13389
- );
13390
- }
13391
- }
13392
- PanelErrorBoundary.displayName = `withErrorBoundary(${Inner.displayName || Inner.name || "Component"})`;
13393
- return PanelErrorBoundary;
13394
- }
13495
+ var import_react_dom = require("react-dom");
13395
13496
 
13396
- // plugin-src/client/panel-entry-store.js
13397
- var VALID_ENTRIES = ["sidebar", "settings"];
13398
- var FALLBACK_ENTRY = "sidebar";
13399
- var JET_HUB_PANEL_KEY = "jet-hub";
13400
- var JET_HUB_SIDEBAR_ORDER = 20;
13401
- var PANEL_ENTRY_READ_TIMEOUT_MS = 5e3;
13402
- var PANEL_ENTRY_READ_ATTEMPTS = 3;
13403
- var PANEL_ENTRY_RETRY_DELAY_MS = 200;
13404
- function delay(ms) {
13405
- return new Promise((resolve) => setTimeout(resolve, ms));
13406
- }
13407
- var entry = null;
13408
- var readFailed = false;
13409
- var inflight = null;
13410
- var writeSeq = 0;
13411
- var listeners = /* @__PURE__ */ new Set();
13412
- function normalize(raw) {
13413
- return typeof raw === "string" && VALID_ENTRIES.includes(raw) ? raw : null;
13414
- }
13415
- function panelEntry() {
13416
- return entry;
13417
- }
13418
- function panelEntryShowsSidebar() {
13419
- return entry !== "settings";
13497
+ // plugin-src/client/badge-model.js
13498
+ var BADGE_PREFERENCES = Object.freeze(["auto", "subscription", "credits"]);
13499
+ var DEFAULT_BADGE_PREFERENCE = "auto";
13500
+ var AGGREGATE_PROVIDER_ID = "aggregate";
13501
+ var AUTO_PROVIDER_ID = "jet-hub-auto";
13502
+ function resolveBadgeProvider(provider, active) {
13503
+ if (typeof provider !== "string" || provider.length === 0) return null;
13504
+ if (provider !== AGGREGATE_PROVIDER_ID) return provider;
13505
+ const resolved = typeof active === "object" && active !== null ? active.provider : null;
13506
+ if (typeof resolved !== "string" || resolved.length === 0) return null;
13507
+ if (resolved === AGGREGATE_PROVIDER_ID) return null;
13508
+ return resolved;
13420
13509
  }
13421
- function panelEntryShowsSettings() {
13422
- return entry === "settings";
13510
+ var BADGE_SEP = " • ";
13511
+ var HOST_STALE_HINT = "插件宿主未加载最新版本,请重启 DSH 后重试";
13512
+ function describeBadgeError(error, fallback = "") {
13513
+ const message = typeof error?.message === "string" ? error.message : "";
13514
+ if (message.includes("unknown method")) return HOST_STALE_HINT;
13515
+ if (message.includes("unsupported provider")) return HOST_STALE_HINT;
13516
+ return message.length > 0 ? message : fallback;
13423
13517
  }
13424
- function panelEntryReadFailed() {
13425
- return readFailed;
13518
+ var BADGE_PREFERENCE_LABELS = Object.freeze({
13519
+ auto: "自动",
13520
+ subscription: "优先订阅",
13521
+ credits: "只看积分"
13522
+ });
13523
+ function normalizeBadgePreference(value) {
13524
+ return BADGE_PREFERENCES.includes(value) ? value : DEFAULT_BADGE_PREFERENCE;
13426
13525
  }
13427
- function subscribePanelEntry(listener) {
13428
- listeners.add(listener);
13429
- return () => {
13430
- listeners.delete(listener);
13431
- };
13526
+ function windowPreview(windows, limit = 2) {
13527
+ const list = Array.isArray(windows) ? windows : [];
13528
+ return quotaWindowsOf(list).slice(0, limit).map(([type, label, win]) => ({ type, label, percent: quotaPercentValue(win?.percentUsed) }));
13432
13529
  }
13433
- function publish(nextEntry, nextFailed) {
13434
- if (entry === nextEntry && readFailed === nextFailed) return;
13435
- entry = nextEntry;
13436
- readFailed = nextFailed;
13437
- for (const listener of [...listeners]) {
13438
- try {
13439
- listener();
13440
- } catch (caught) {
13441
- console.error("[jet-hub] 面板入口监听器抛错", caught);
13530
+ function creditGroupsOf(accounts) {
13531
+ const rows = Array.isArray(accounts) ? accounts : [];
13532
+ const byUnit = /* @__PURE__ */ new Map();
13533
+ let failedCount = 0;
13534
+ let okCount = 0;
13535
+ for (const row of rows) {
13536
+ const balance = row?.balance;
13537
+ if (!balance || typeof balance.total !== "number" || !Number.isFinite(balance.total)) {
13538
+ failedCount += 1;
13539
+ continue;
13540
+ }
13541
+ okCount += 1;
13542
+ const rawUnit = firstUnitOf(balance.packages) ?? "";
13543
+ const unit = rawUnit === QUOTA_UNIT ? QUOTA_UNIT : normalizeUnit(rawUnit);
13544
+ const group = byUnit.get(unit) ?? { unit, label: unitLabel(unit), total: 0, accountCount: 0 };
13545
+ group.total += balance.total;
13546
+ group.accountCount += 1;
13547
+ if (unit === QUOTA_UNIT) {
13548
+ const line = formatQuotaLine(balance.packages, unit);
13549
+ group.quotaLines = group.quotaLines ?? [];
13550
+ group.quotaRemainings = group.quotaRemainings ?? [];
13551
+ group.quotaWindows = group.quotaWindows ?? /* @__PURE__ */ new Map();
13552
+ if (line !== null) group.quotaLines.push(line);
13553
+ for (const pkg of Array.isArray(balance.packages) ? balance.packages : []) {
13554
+ if (!pkg) continue;
13555
+ const remaining = pkg.remaining;
13556
+ if (typeof remaining !== "number" || !Number.isFinite(remaining)) continue;
13557
+ group.quotaRemainings.push(remaining);
13558
+ const name2 = pkg.name || "未命名";
13559
+ const prev = group.quotaWindows.get(name2);
13560
+ if (prev === void 0 || remaining < prev) group.quotaWindows.set(name2, remaining);
13561
+ }
13442
13562
  }
13563
+ byUnit.set(unit, group);
13443
13564
  }
13565
+ const groups = [...byUnit.values()].sort((a, b) => a.unit < b.unit ? -1 : a.unit > b.unit ? 1 : 0);
13566
+ return { groups, failedCount, okCount };
13444
13567
  }
13445
- function readSignal() {
13446
- if (typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function") {
13447
- return AbortSignal.timeout(PANEL_ENTRY_READ_TIMEOUT_MS);
13448
- }
13449
- if (typeof AbortController !== "function") return void 0;
13450
- const controller = new AbortController();
13451
- const timer = setTimeout(() => controller.abort(), PANEL_ENTRY_READ_TIMEOUT_MS);
13452
- if (typeof timer === "object" && timer !== null && typeof timer.unref === "function") {
13453
- timer.unref();
13568
+ function planGroupsOf(rows) {
13569
+ const list = Array.isArray(rows) ? rows : [];
13570
+ const byKey = /* @__PURE__ */ new Map();
13571
+ for (const row of list) {
13572
+ const plan = row?.plan;
13573
+ if (!plan) continue;
13574
+ const unit = normalizeUnit(typeof plan.unit === "string" ? plan.unit : "");
13575
+ const key = `${String(plan.name)}\0${unit}`;
13576
+ const group = byKey.get(key) ?? {
13577
+ name: String(plan.name),
13578
+ unit,
13579
+ label: unitLabel(unit),
13580
+ remaining: 0,
13581
+ total: 0,
13582
+ accountCount: 0,
13583
+ deductionEndTime: void 0
13584
+ };
13585
+ group.remaining += Number(plan.remaining) || 0;
13586
+ group.total += Number(plan.total) || 0;
13587
+ group.accountCount += 1;
13588
+ const end = typeof plan.deductionEndTime === "number" && Number.isFinite(plan.deductionEndTime) ? plan.deductionEndTime : void 0;
13589
+ if (end !== void 0 && (group.deductionEndTime === void 0 || end < group.deductionEndTime)) {
13590
+ group.deductionEndTime = end;
13591
+ }
13592
+ byKey.set(key, group);
13454
13593
  }
13455
- controller.signal?.addEventListener?.("abort", () => clearTimeout(timer), { once: true });
13456
- return controller.signal;
13457
- }
13458
- function loadPanelEntry(rpcCall) {
13459
- if (inflight !== null) return inflight;
13460
- const seqAtStart = writeSeq;
13461
- const task = (async () => {
13462
- let lastError;
13463
- for (let attempt = 1; attempt <= PANEL_ENTRY_READ_ATTEMPTS; attempt += 1) {
13464
- try {
13465
- const result = await rpcCall("panelEntry.get", {}, readSignal());
13466
- if (writeSeq !== seqAtStart) return entry ?? FALLBACK_ENTRY;
13467
- const next = normalize(result?.entry);
13468
- if (next !== null) {
13469
- publish(next, false);
13470
- } else {
13471
- publish(entry ?? FALLBACK_ENTRY, true);
13472
- }
13473
- return entry ?? FALLBACK_ENTRY;
13474
- } catch (caught) {
13475
- lastError = caught;
13476
- if (writeSeq !== seqAtStart) return entry ?? FALLBACK_ENTRY;
13477
- if (attempt >= PANEL_ENTRY_READ_ATTEMPTS) break;
13478
- await delay(PANEL_ENTRY_RETRY_DELAY_MS * attempt);
13479
- if (writeSeq !== seqAtStart) return entry ?? FALLBACK_ENTRY;
13480
- }
13481
- }
13482
- console.warn(
13483
- `[jet-hub] 读取面板入口偏好失败,按仅侧栏处理(已重试 ${PANEL_ENTRY_READ_ATTEMPTS - 1} 次)`,
13484
- lastError
13485
- );
13486
- if (writeSeq === seqAtStart) publish(entry ?? FALLBACK_ENTRY, true);
13487
- return entry ?? FALLBACK_ENTRY;
13488
- })();
13489
- inflight = task;
13490
- const clear = () => {
13491
- if (inflight === task) inflight = null;
13492
- };
13493
- void task.then(clear, clear);
13494
- return task;
13495
- }
13496
- async function setPanelEntry(rpcCall, next) {
13497
- const result = await rpcCall("panelEntry.set", { entry: next });
13498
- const confirmed = normalize(result?.entry);
13499
- if (confirmed === null) {
13500
- throw new Error("面板入口偏好没有返回合法 entry");
13501
- }
13502
- writeSeq += 1;
13503
- publish(confirmed, false);
13504
- return confirmed;
13505
- }
13506
-
13507
- // plugin-src/client/panel-entry.js
13508
- var JetHubPageForSettings = withErrorBoundary(JetHubPage, { label: "Jet Hub 设置页" });
13509
- var JetHubPageForMain = withErrorBoundary(JetHubPage, { label: "Jet Hub 面板" });
13510
- function JetHubSidebarIcon({ size }) {
13511
- const px = typeof size === "number" && size > 0 ? size : 16;
13512
- return React7.createElement(
13513
- "svg",
13514
- {
13515
- width: px,
13516
- height: px,
13517
- viewBox: "0 0 16 16",
13518
- fill: "none",
13519
- xmlns: "http://www.w3.org/2000/svg",
13520
- "aria-hidden": "true"
13521
- },
13522
- React7.createElement("path", {
13523
- d: "M8 1.7 13.5 4.85v6.3L8 14.3 2.5 11.15v-6.3z",
13524
- stroke: "currentColor",
13525
- strokeWidth: 1.35,
13526
- strokeLinejoin: "round"
13527
- }),
13528
- React7.createElement("circle", { cx: 8, cy: 8, r: 1.7, fill: "currentColor" })
13529
- );
13530
- }
13531
- function JetHubMainPanel({ rpcCall }) {
13532
- if (typeof rpcCall !== "function") return null;
13533
- return React7.createElement(
13534
- "div",
13535
- { className: "dim-jh-panelHost", "data-plugin": "@xixka/dsh-hub" },
13536
- React7.createElement(JetHubPageForMain, { rpcCall })
13537
- );
13538
- }
13539
- function registerJetHubPanelEntries(ctx, rpcCall) {
13540
- ctx.slots.inject("main", () => ctx.slots.register({
13541
- name: "main",
13542
- key: JET_HUB_PANEL_KEY,
13543
- inject: () => ({ rpcCall })
13544
- }, JetHubMainPanel));
13545
- let layout;
13546
- ctx.inject(["layout"], (scoped) => {
13547
- layout = scoped.layout;
13548
- return () => {
13549
- layout = void 0;
13550
- };
13551
- });
13552
- const deselectIfActive = () => {
13553
- try {
13554
- if (layout?.panelInfo?.getSnapshot?.()?.activePanelId !== JET_HUB_PANEL_KEY) return;
13555
- layout.selectPanel(null);
13556
- } catch (caught) {
13557
- console.warn("[jet-hub] 撤销侧栏入口时取消选中失败", caught);
13558
- }
13559
- };
13560
- ctx.slots.inject("sidebar.panellist", () => {
13561
- let stopRow;
13562
- const sync = (visible) => {
13563
- if (visible && stopRow === void 0) {
13564
- stopRow = ctx.slots.register({
13565
- name: "sidebar.panellist",
13566
- id: JET_HUB_PANEL_KEY,
13567
- order: JET_HUB_SIDEBAR_ORDER,
13568
- label: () => "Jet Hub"
13569
- }, JetHubSidebarIcon);
13570
- return;
13571
- }
13572
- if (!visible && stopRow !== void 0) {
13573
- const stop = stopRow;
13574
- stopRow = void 0;
13575
- stop();
13576
- deselectIfActive();
13577
- }
13578
- };
13579
- const unsubscribe = subscribePanelEntry(() => sync(panelEntryShowsSidebar()));
13580
- sync(panelEntryShowsSidebar());
13581
- let disposed = false;
13582
- void loadPanelEntry(rpcCall).then(() => {
13583
- if (!disposed) sync(panelEntryShowsSidebar());
13584
- });
13585
- return () => {
13586
- disposed = true;
13587
- unsubscribe();
13588
- if (stopRow !== void 0) {
13589
- const stop = stopRow;
13590
- stopRow = void 0;
13591
- stop();
13592
- }
13593
- };
13594
- });
13595
- ctx.slots.inject("settings.section", () => {
13596
- let stopSection;
13597
- const sync = (visible) => {
13598
- if (visible && stopSection === void 0) {
13599
- stopSection = ctx.slots.register({
13600
- name: "settings.section",
13601
- id: JET_HUB_PANEL_KEY,
13602
- order: 50,
13603
- label: () => "Jet Hub",
13604
- inject: () => ({ rpcCall })
13605
- }, JetHubPageForSettings);
13606
- return;
13607
- }
13608
- if (!visible && stopSection !== void 0) {
13609
- const stop = stopSection;
13610
- stopSection = void 0;
13611
- stop();
13612
- }
13613
- };
13614
- const unsubscribe = subscribePanelEntry(() => sync(panelEntryShowsSettings()));
13615
- sync(panelEntryShowsSettings());
13616
- let disposed = false;
13617
- void loadPanelEntry(rpcCall).then(() => {
13618
- if (!disposed) sync(panelEntryShowsSettings());
13619
- });
13620
- return () => {
13621
- disposed = true;
13622
- unsubscribe();
13623
- if (stopSection !== void 0) {
13624
- const stop = stopSection;
13625
- stopSection = void 0;
13626
- stop();
13627
- }
13628
- };
13629
- });
13630
- }
13631
-
13632
- // plugin-src/client/usage-panel.js
13633
- var React9 = __toESM(require("react"), 1);
13634
-
13635
- // plugin-src/client/usage-badge.js
13636
- var React8 = __toESM(require("react"), 1);
13637
-
13638
- // plugin-src/client/badge-model.js
13639
- var BADGE_PREFERENCES = Object.freeze(["auto", "subscription", "credits"]);
13640
- var DEFAULT_BADGE_PREFERENCE = "auto";
13641
- var AUTO_PROVIDER_ID = "jet-hub-auto";
13642
- var BADGE_SEP = " • ";
13643
- var HOST_STALE_HINT = "插件宿主未加载最新版本,请重启 DSH 后重试";
13644
- function describeBadgeError(error, fallback = "") {
13645
- const message = typeof error?.message === "string" ? error.message : "";
13646
- if (message.includes("unknown method")) return HOST_STALE_HINT;
13647
- if (message.includes("unsupported provider")) return HOST_STALE_HINT;
13648
- return message.length > 0 ? message : fallback;
13649
- }
13650
- var BADGE_PREFERENCE_LABELS = Object.freeze({
13651
- auto: "自动",
13652
- subscription: "优先订阅",
13653
- credits: "只看积分"
13654
- });
13655
- function normalizeBadgePreference(value) {
13656
- return BADGE_PREFERENCES.includes(value) ? value : DEFAULT_BADGE_PREFERENCE;
13657
- }
13658
- function windowPreview(windows, limit = 2) {
13659
- const list = Array.isArray(windows) ? windows : [];
13660
- return quotaWindowsOf(list).slice(0, limit).map(([type, label, win]) => ({ type, label, percent: quotaPercentValue(win?.percentUsed) }));
13661
- }
13662
- function creditGroupsOf(accounts) {
13663
- const rows = Array.isArray(accounts) ? accounts : [];
13664
- const byUnit = /* @__PURE__ */ new Map();
13665
- let failedCount = 0;
13666
- let okCount = 0;
13667
- for (const row of rows) {
13668
- const balance = row?.balance;
13669
- if (!balance || typeof balance.total !== "number" || !Number.isFinite(balance.total)) {
13670
- failedCount += 1;
13671
- continue;
13672
- }
13673
- okCount += 1;
13674
- const rawUnit = firstUnitOf(balance.packages) ?? "";
13675
- const unit = rawUnit === QUOTA_UNIT ? QUOTA_UNIT : normalizeUnit(rawUnit);
13676
- const group = byUnit.get(unit) ?? { unit, label: unitLabel(unit), total: 0, accountCount: 0 };
13677
- group.total += balance.total;
13678
- group.accountCount += 1;
13679
- if (unit === QUOTA_UNIT) {
13680
- const line = formatQuotaLine(balance.packages, unit);
13681
- group.quotaLines = group.quotaLines ?? [];
13682
- group.quotaRemainings = group.quotaRemainings ?? [];
13683
- group.quotaWindows = group.quotaWindows ?? /* @__PURE__ */ new Map();
13684
- if (line !== null) group.quotaLines.push(line);
13685
- for (const pkg of Array.isArray(balance.packages) ? balance.packages : []) {
13686
- if (!pkg) continue;
13687
- const remaining = pkg.remaining;
13688
- if (typeof remaining !== "number" || !Number.isFinite(remaining)) continue;
13689
- group.quotaRemainings.push(remaining);
13690
- const name2 = pkg.name || "未命名";
13691
- const prev = group.quotaWindows.get(name2);
13692
- if (prev === void 0 || remaining < prev) group.quotaWindows.set(name2, remaining);
13693
- }
13694
- }
13695
- byUnit.set(unit, group);
13696
- }
13697
- const groups = [...byUnit.values()].sort((a, b) => a.unit < b.unit ? -1 : a.unit > b.unit ? 1 : 0);
13698
- return { groups, failedCount, okCount };
13699
- }
13700
- function planGroupsOf(rows) {
13701
- const list = Array.isArray(rows) ? rows : [];
13702
- const byKey = /* @__PURE__ */ new Map();
13703
- for (const row of list) {
13704
- const plan = row?.plan;
13705
- if (!plan) continue;
13706
- const unit = normalizeUnit(typeof plan.unit === "string" ? plan.unit : "");
13707
- const key = `${String(plan.name)}\0${unit}`;
13708
- const group = byKey.get(key) ?? {
13709
- name: String(plan.name),
13710
- unit,
13711
- label: unitLabel(unit),
13712
- remaining: 0,
13713
- total: 0,
13714
- accountCount: 0,
13715
- deductionEndTime: void 0
13716
- };
13717
- group.remaining += Number(plan.remaining) || 0;
13718
- group.total += Number(plan.total) || 0;
13719
- group.accountCount += 1;
13720
- const end = typeof plan.deductionEndTime === "number" && Number.isFinite(plan.deductionEndTime) ? plan.deductionEndTime : void 0;
13721
- if (end !== void 0 && (group.deductionEndTime === void 0 || end < group.deductionEndTime)) {
13722
- group.deductionEndTime = end;
13723
- }
13724
- byKey.set(key, group);
13725
- }
13726
- return [...byKey.values()].sort((a, b) => b.remaining - a.remaining);
13594
+ return [...byKey.values()].sort((a, b) => b.remaining - a.remaining);
13727
13595
  }
13728
13596
  function badgeView(input) {
13729
13597
  const providerLabel2 = String(input?.providerLabel ?? "Jet Hub");
@@ -13898,40 +13766,199 @@ function formatUpdatedAt(ms) {
13898
13766
  }
13899
13767
 
13900
13768
  // plugin-src/client/usage-badge.js
13769
+ var POPOVER_ANCHOR_STYLE = Object.freeze({
13770
+ position: "absolute",
13771
+ right: 0,
13772
+ bottom: "calc(100% + 8px)",
13773
+ maxHeight: "58vh",
13774
+ overflowY: "auto",
13775
+ zIndex: 40
13776
+ });
13777
+ var NARROW_BREAKPOINT_PX = 720;
13778
+ function isNarrowViewport() {
13779
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") return false;
13780
+ return window.matchMedia(`(max-width: ${NARROW_BREAKPOINT_PX}px)`).matches;
13781
+ }
13782
+ var NARROW_POPOVER_STYLE = Object.freeze({
13783
+ position: "fixed",
13784
+ left: 8,
13785
+ right: 8,
13786
+ top: "auto",
13787
+ bottom: "calc(env(safe-area-inset-bottom, 0px) + var(--dsh-composer-height, 152px))",
13788
+ width: "auto",
13789
+ maxWidth: "none",
13790
+ maxHeight: "max(120px, calc(100dvh - 160px))",
13791
+ overflowY: "auto",
13792
+ zIndex: 1200
13793
+ });
13794
+ var COMPOSER_HEIGHT_FALLBACK_PX = 152;
13795
+ function readComposerHeightPx(anchor) {
13796
+ if (typeof window === "undefined" || typeof window.getComputedStyle !== "function") {
13797
+ return COMPOSER_HEIGHT_FALLBACK_PX;
13798
+ }
13799
+ let node = anchor;
13800
+ while (node !== null && node !== void 0) {
13801
+ const raw = window.getComputedStyle(node).getPropertyValue("--dsh-composer-height").trim();
13802
+ if (raw !== "") {
13803
+ const parsed = Number.parseFloat(raw);
13804
+ if (Number.isFinite(parsed) && parsed > 0) return parsed;
13805
+ }
13806
+ node = node.parentElement;
13807
+ }
13808
+ return COMPOSER_HEIGHT_FALLBACK_PX;
13809
+ }
13901
13810
  var BADGE_POLL_MS = 6e4;
13811
+ var ACTIVE_PROVIDER_POLL_MS = 5e3;
13902
13812
  var CLAIM_NOTICE_MS = 8e3;
13903
13813
  var CLAIM_NOTICE_WARN_MS = 2e4;
13904
13814
  var CREDITS_COLLAPSED_LIMIT = 5;
13905
- function UsageBadgeCard(props) {
13906
- const provider = props.provider;
13907
- if (typeof provider !== "string" || provider.length === 0) return null;
13908
- if (provider === AUTO_PROVIDER_ID) {
13909
- return React8.createElement(UsageBadgeActive, { ...props, provider });
13815
+ var RESOLVE_RETRY_DELAYS = [300, 700, 1500, 2e3];
13816
+ function UsageBadge(props) {
13817
+ const resolveDirectory = props.resolveDirectory;
13818
+ const [directory, setDirectory] = React6.useState(null);
13819
+ const resolvedRef = React6.useRef(false);
13820
+ const snapshotErrorRef = React6.useRef(false);
13821
+ React6.useEffect(() => {
13822
+ if (typeof resolveDirectory !== "function") return void 0;
13823
+ if (resolvedRef.current) return void 0;
13824
+ let alive = true;
13825
+ const timers = [];
13826
+ let attempt = 0;
13827
+ const tryResolve = () => {
13828
+ if (!alive || resolvedRef.current) return;
13829
+ let resolved = null;
13830
+ try {
13831
+ resolved = resolveDirectory();
13832
+ } catch {
13833
+ resolved = null;
13834
+ }
13835
+ if (!alive) return;
13836
+ if (resolved !== null && resolved !== void 0 && resolved.store !== void 0) {
13837
+ resolvedRef.current = true;
13838
+ const store = resolved.store;
13839
+ setDirectory(store);
13840
+ if (typeof resolved.load === "function") {
13841
+ Promise.resolve(resolved.load()).catch((error) => {
13842
+ console.warn("[jet-hub usage] 目录 load() 失败,徽标将不显示:", error);
13843
+ });
13844
+ }
13845
+ return;
13846
+ }
13847
+ attempt += 1;
13848
+ if (attempt >= RESOLVE_RETRY_DELAYS.length) {
13849
+ console.warn("[jet-hub usage] 目录解析最终失败,徽标不显示");
13850
+ return;
13851
+ }
13852
+ timers.push(setTimeout(tryResolve, RESOLVE_RETRY_DELAYS[attempt - 1]));
13853
+ };
13854
+ tryResolve();
13855
+ return () => {
13856
+ alive = false;
13857
+ for (const timer of timers) clearTimeout(timer);
13858
+ };
13859
+ }, [resolveDirectory]);
13860
+ const safe = (fn) => () => {
13861
+ try {
13862
+ return directory ? fn(directory) : void 0;
13863
+ } catch (error) {
13864
+ if (!snapshotErrorRef.current) {
13865
+ snapshotErrorRef.current = true;
13866
+ console.warn("[jet-hub usage] 读目录快照失败(store 上应有 getSnapshot):", error);
13867
+ }
13868
+ return void 0;
13869
+ }
13870
+ };
13871
+ const state = React6.useSyncExternalStore(
13872
+ // ⚠️ 订阅要**真的转发 onChange**(用户切模型时徽标跟着更新);
13873
+ // try/catch 只为把「订阅时才发现抛错」这一类也收进徽标内部。
13874
+ (onChange) => {
13875
+ if (!directory) return () => {
13876
+ };
13877
+ try {
13878
+ return directory.subscribe(onChange);
13879
+ } catch {
13880
+ return () => {
13881
+ };
13882
+ }
13883
+ },
13884
+ safe((d) => d.getSnapshot()),
13885
+ safe((d) => d.getSnapshot())
13886
+ );
13887
+ let provider = state?.current?.provider;
13888
+ const modelId = state?.current?.model;
13889
+ const readActiveProvider = props.readActiveProvider;
13890
+ const [activeProvider, setActiveProvider] = React6.useState(null);
13891
+ const isAggregate = provider === AGGREGATE_PROVIDER_ID;
13892
+ React6.useEffect(() => {
13893
+ if (!isAggregate || typeof readActiveProvider !== "function") return void 0;
13894
+ let alive = true;
13895
+ let timer = null;
13896
+ const refresh = () => {
13897
+ Promise.resolve().then(() => readActiveProvider(modelId)).then((value) => {
13898
+ if (!alive) return;
13899
+ setActiveProvider(value?.provider ?? null);
13900
+ }).catch(() => {
13901
+ if (alive) setActiveProvider(null);
13902
+ });
13903
+ };
13904
+ refresh();
13905
+ timer = setInterval(refresh, ACTIVE_PROVIDER_POLL_MS);
13906
+ return () => {
13907
+ alive = false;
13908
+ if (timer !== null) clearInterval(timer);
13909
+ };
13910
+ }, [isAggregate, readActiveProvider, modelId]);
13911
+ if (isAggregate) {
13912
+ provider = resolveBadgeProvider(provider, activeProvider === null ? null : { provider: activeProvider });
13913
+ }
13914
+ if (isAggregate && provider === null) {
13915
+ return React6.createElement("span", {
13916
+ className: "dim-jh-badgePending",
13917
+ role: "status",
13918
+ title: "聚合(跨渠道):尚未发出过请求,还不知道会走哪个渠道。发送一条消息后这里会显示实际使用的渠道与积分。"
13919
+ }, [
13920
+ React6.createElement("span", { key: "dot", className: "dim-jh-badgeDot", "data-tone": "muted" }),
13921
+ React6.createElement("span", { key: "text" }, "聚合 · 待首次请求")
13922
+ ]);
13923
+ }
13924
+ if (typeof provider !== "string" || provider.length === 0) return null;
13925
+ if (provider === AUTO_PROVIDER_ID) {
13926
+ return React6.createElement(UsageBadgeActive, { ...props, provider });
13910
13927
  }
13911
13928
  if (!supportsCreditBalance(provider)) return null;
13912
- return React8.createElement(UsageBadgeActive, { ...props, provider });
13929
+ return React6.createElement(UsageBadgeActive, { ...props, provider });
13913
13930
  }
13914
13931
  function UsageBadgeActive(props) {
13915
13932
  const { provider, providerLabel: providerLabel2, readBadge, writePreference, setAutoCheckin, dismissAutoCheckin, claimCredits } = props;
13916
13933
  const label = providerLabel2(provider);
13917
- const [snapshot, setSnapshot] = React8.useState(null);
13918
- const [failed, setFailed] = React8.useState(false);
13919
- const [readError, setReadError] = React8.useState("");
13920
- const [busy, setBusy] = React8.useState(false);
13921
- const [preference, setPreference] = React8.useState(null);
13922
- const [prefError, setPrefError] = React8.useState("");
13923
- const [autoError, setAutoError] = React8.useState("");
13924
- const [claiming, setClaiming] = React8.useState(null);
13925
- const [claimProgress, setClaimProgress] = React8.useState(null);
13926
- const [claimNotice, setClaimNotice] = React8.useState(null);
13927
- const [creditsExpanded, setCreditsExpanded] = React8.useState(false);
13928
- const read = React8.useRef(() => {
13934
+ const [snapshot, setSnapshot] = React6.useState(null);
13935
+ const [failed, setFailed] = React6.useState(false);
13936
+ const [readError, setReadError] = React6.useState("");
13937
+ const [busy, setBusy] = React6.useState(false);
13938
+ const [open, setOpen] = React6.useState(false);
13939
+ const [preference, setPreference] = React6.useState(null);
13940
+ const [prefError, setPrefError] = React6.useState("");
13941
+ const [autoError, setAutoError] = React6.useState("");
13942
+ const [claiming, setClaiming] = React6.useState(null);
13943
+ const [claimProgress, setClaimProgress] = React6.useState(null);
13944
+ const [claimNotice, setClaimNotice] = React6.useState(null);
13945
+ const [creditsExpanded, setCreditsExpanded] = React6.useState(false);
13946
+ const root = React6.useRef(null);
13947
+ const popRef = React6.useRef(null);
13948
+ const read = React6.useRef(() => {
13929
13949
  });
13930
- const claimInFlightRef = React8.useRef(false);
13931
- React8.useEffect(() => {
13950
+ const claimInFlightRef = React6.useRef(false);
13951
+ React6.useEffect(() => {
13932
13952
  ensureJetHubStyles();
13933
- }, []);
13934
- React8.useEffect(() => {
13953
+ if (!open) return;
13954
+ const element = popRef.current;
13955
+ if (element === null) return;
13956
+ const position = window.getComputedStyle(element).position;
13957
+ if (position !== "absolute" && position !== "fixed") {
13958
+ console.warn(`[jet-hub] 浮层定位异常(position=${position}):会撑高输入区(检查 POPOVER_ANCHOR_STYLE / NARROW_POPOVER_STYLE 是否被改坏)`);
13959
+ }
13960
+ }, [open]);
13961
+ React6.useEffect(() => {
13935
13962
  setSnapshot(null);
13936
13963
  setFailed(false);
13937
13964
  setClaimNotice(null);
@@ -13939,7 +13966,7 @@ function UsageBadgeActive(props) {
13939
13966
  setAutoError("");
13940
13967
  setCreditsExpanded(false);
13941
13968
  }, [provider]);
13942
- React8.useEffect(() => {
13969
+ React6.useEffect(() => {
13943
13970
  let alive = true;
13944
13971
  let inFlight = false;
13945
13972
  const load = async (options = {}) => {
@@ -13984,7 +14011,25 @@ function UsageBadgeActive(props) {
13984
14011
  document.removeEventListener("visibilitychange", onVisible);
13985
14012
  };
13986
14013
  }, [provider, readBadge]);
13987
- React8.useEffect(() => {
14014
+ React6.useEffect(() => {
14015
+ if (!open) return void 0;
14016
+ const onDown = (event) => {
14017
+ if (!(event.target instanceof Node)) return;
14018
+ const insideRoot = root.current !== null && root.current.contains(event.target);
14019
+ const insidePop = popRef.current !== null && popRef.current.contains(event.target);
14020
+ if (!insideRoot && !insidePop) setOpen(false);
14021
+ };
14022
+ const onKey = (event) => {
14023
+ if (event.key === "Escape") setOpen(false);
14024
+ };
14025
+ document.addEventListener("mousedown", onDown);
14026
+ document.addEventListener("keydown", onKey);
14027
+ return () => {
14028
+ document.removeEventListener("mousedown", onDown);
14029
+ document.removeEventListener("keydown", onKey);
14030
+ };
14031
+ }, [open]);
14032
+ React6.useEffect(() => {
13988
14033
  if (claimNotice === null) return void 0;
13989
14034
  const ms = claimNotice.tone === "warn" ? CLAIM_NOTICE_WARN_MS : CLAIM_NOTICE_MS;
13990
14035
  const timer = setTimeout(() => setClaimNotice(null), ms);
@@ -14144,23 +14189,62 @@ function UsageBadgeActive(props) {
14144
14189
  const tone = failed && snapshot === null ? "error" : view.tone;
14145
14190
  const title = [view.text, view.incompleteNote, view.failureReason].filter((part) => part !== "").join("\n");
14146
14191
  const ariaLabel = `${label} 用量:${view.text}${view.incompleteNote === "" ? "" : `(${view.incompleteNote})`}`;
14147
- return React8.createElement("div", { className: "dim-jh-usageCard" }, renderCardBody());
14148
- function renderCardBody() {
14192
+ const collapsed = React6.createElement("span", { key: "text", className: "dim-jh-badgeText" }, [
14193
+ React6.createElement("span", { key: "name", className: "dim-jh-badgeName" }, view.name),
14194
+ React6.createElement("span", { key: "sep", className: "dim-jh-badgeSep" }, "•"),
14195
+ // 空串时**不渲染**该节点:留一个空 span 会白吃一个 5px 的 gap
14196
+ //(.dim-jh-badgeText 用的是 .dim-jh-badgeBtn 的 gap)。只有套餐模式有中段。
14197
+ view.detail === "" ? null : React6.createElement("span", { key: "detail", className: "dim-jh-badgeDetail" }, view.detail),
14198
+ // ⚠️ 类名是 Reading 而**不是** Value:.dim-jh-badgeValue 已被弹窗里的读数占用
14199
+ //(那条规则带 font-weight:600,且排在样式表更后面 —— 同名会让胶囊里的数字
14200
+ // 被静默加粗、并拿到 flex:none 而无法收缩)。
14201
+ React6.createElement("span", { key: "value", className: "dim-jh-badgeReading" }, view.reading),
14202
+ /**
14203
+ * 「这个数字不完整」的标记(用户 2026-10-03 要求)。
14204
+ *
14205
+ * 合计少算了几个账号时,数字本身**看不出任何异常**,故必须有个可见标记 ——
14206
+ * 但它是**补语而不是读数**,故:
14207
+ * - 单独成 span,`flex: none`(与读数同级):被省略号吃掉就等于没标;
14208
+ * - 排在读数**之后**:不干扰「先看数字」的阅读顺序;
14209
+ * - 不参与 `view.text`:那句话是 `title` / `aria-label` 用的纯读数。
14210
+ *
14211
+ * ⚠️ `aria-hidden` 是**故意**的:同一句话已经并进按钮的 `aria-label`,
14212
+ * 不隐藏会被读屏念两遍。鼠标用户的解释走 `title`。
14213
+ */
14214
+ view.incompleteNote === "" ? null : React6.createElement("span", {
14215
+ key: "incomplete",
14216
+ className: "dim-jh-badgeWarn",
14217
+ title: view.incompleteNote,
14218
+ "aria-hidden": "true"
14219
+ }, "⚠")
14220
+ ]);
14221
+ return React6.createElement("div", { className: "dim-jh-badge", ref: root }, [
14222
+ React6.createElement("button", {
14223
+ key: "btn",
14224
+ type: "button",
14225
+ className: "dim-jh-badgeBtn",
14226
+ "aria-expanded": open,
14227
+ "aria-label": ariaLabel,
14228
+ title,
14229
+ onClick: () => setOpen((was) => !was)
14230
+ }, [
14231
+ React6.createElement("span", { key: "dot", className: "dim-jh-badgeDot", "data-tone": tone }),
14232
+ collapsed
14233
+ ]),
14234
+ open ? renderPopover() : null
14235
+ ]);
14236
+ function renderPopover() {
14149
14237
  const stamp = snapshot === null ? "" : formatUpdatedAt(value?.generatedAt ?? snapshot.at);
14150
14238
  const children = [
14151
- React8.createElement("div", { key: "head", className: "dim-jh-badgeHead" }, [
14152
- React8.createElement("span", { key: "dot", className: "dim-jh-badgeDot", "data-tone": tone }),
14153
- // ⚠️ 渠道名用 `badgeName` 而不是 `label`:auto 渠道的 label 是裸 id
14154
- //(虚拟渠道不在 registry 里,providerLabel 只能原样返回),而 badgeName
14155
- // 已由 autoBadgeName 拼成「自动 → 实际渠道 · 倍率 · 倒计时」—— 那正是
14156
- // 用户要核对的信息;其余渠道两者相同(badgeName 的 fallback 就是 label)。
14157
- React8.createElement("span", { key: "title", className: "dim-jh-badgeTitle" }, badgeName),
14158
- React8.createElement(
14239
+ React6.createElement("div", { key: "head", className: "dim-jh-badgeHead" }, [
14240
+ React6.createElement("span", { key: "dot", className: "dim-jh-badgeDot", "data-tone": tone }),
14241
+ React6.createElement("span", { key: "title", className: "dim-jh-badgeTitle" }, label),
14242
+ React6.createElement(
14159
14243
  "span",
14160
14244
  { key: "at", className: "dim-jh-badgeAt" },
14161
14245
  snapshot === null ? "读取中…" : `${stamp === "" ? "已读取" : stamp}${value?.cached === true ? " · 缓存" : ""}`
14162
14246
  ),
14163
- React8.createElement("button", {
14247
+ React6.createElement("button", {
14164
14248
  key: "auto",
14165
14249
  type: "button",
14166
14250
  className: "dim-jh-badgeAuto",
@@ -14172,8 +14256,8 @@ function UsageBadgeActive(props) {
14172
14256
  onClick: () => {
14173
14257
  void onToggleAutoCheckin();
14174
14258
  }
14175
- }, auto?.running === true ? "…" : React8.createElement("span", { className: "dim-jh-badgeAutoDot" })),
14176
- React8.createElement("button", {
14259
+ }, auto?.running === true ? "…" : React6.createElement("span", { className: "dim-jh-badgeAutoDot" })),
14260
+ React6.createElement("button", {
14177
14261
  key: "refresh",
14178
14262
  type: "button",
14179
14263
  className: "dim-jh-badgeRefresh",
@@ -14185,55 +14269,57 @@ function UsageBadgeActive(props) {
14185
14269
  ]),
14186
14270
  // 开关写入失败时单独一行说明:它属于设置写入,混进偏好那行会让人以为
14187
14271
  // 是「显示偏好」没保存。
14188
- autoError === "" ? null : React8.createElement("div", { key: "autoErr", className: "dim-jh-badgeFail", role: "alert" }, autoError),
14189
- // 读数行:原折叠胶囊的「名字 • 读数」迁居后只保留**读数**(名字已在头部,
14190
- // auto 的实际渠道也在头部);「不完整」警示角标随行 —— 它是读数的补语。
14191
- React8.createElement("div", {
14192
- key: "reading",
14193
- className: "dim-jh-usageReading",
14194
- title,
14195
- "aria-label": ariaLabel
14196
- }, [
14197
- React8.createElement("span", {
14198
- key: "value",
14199
- className: "dim-jh-usageReadingValue",
14200
- "data-tone": tone
14201
- }, view.reading),
14202
- // ⚠️ aria-hidden 是**故意**的:同一句话已并入读数行的 aria-label,
14203
- // 不隐藏会被读屏念两遍;鼠标用户的解释走 title。
14204
- view.incompleteNote === "" ? null : React8.createElement("span", {
14205
- key: "incomplete",
14206
- className: "dim-jh-badgeWarn",
14207
- title: view.incompleteNote,
14208
- "aria-hidden": "true"
14209
- }, "⚠")
14210
- ]),
14272
+ autoError === "" ? null : React6.createElement("div", { key: "autoErr", className: "dim-jh-badgeFail", role: "alert" }, autoError),
14211
14273
  renderPreference()
14212
14274
  ];
14213
14275
  if (snapshot === null) {
14214
- children.push(React8.createElement("div", {
14276
+ children.push(React6.createElement("div", {
14215
14277
  key: "placeholder",
14216
14278
  className: failed ? "dim-jh-badgeFail" : "dim-jh-badgeNote",
14217
14279
  role: failed ? "alert" : void 0
14218
14280
  }, failed ? readError === "" ? "用量不可用,可点右上角 ↻ 重试" : `${readError}(可点右上角 ↻ 重试)` : "正在读取用量…(首次要逐账号查询,可能要几秒)"));
14219
14281
  children.push(renderClaim());
14220
- return children;
14282
+ return wrapPopover(children);
14221
14283
  }
14222
14284
  children.push(renderSubscription());
14223
14285
  children.push(renderCredits());
14224
14286
  children.push(renderClaim());
14225
14287
  children.push(renderFoot());
14226
- return children;
14288
+ return wrapPopover(children);
14289
+ }
14290
+ function wrapPopover(children) {
14291
+ const narrow = isNarrowViewport();
14292
+ if (!narrow) {
14293
+ return React6.createElement("div", {
14294
+ className: "dim-jh-badgePop",
14295
+ style: POPOVER_ANCHOR_STYLE,
14296
+ ref: popRef
14297
+ }, children);
14298
+ }
14299
+ const composerHeight = readComposerHeightPx(root.current);
14300
+ const style = {
14301
+ ...NARROW_POPOVER_STYLE,
14302
+ // ⚠️ React 的内联样式对自定义属性(`--x`)是原样下发的,故这里可以
14303
+ // 直接用 CSS 变量名作 key。
14304
+ "--dsh-composer-height": `${composerHeight}px`
14305
+ };
14306
+ const node = React6.createElement("div", {
14307
+ className: "dim-jh-badgePop",
14308
+ style,
14309
+ ref: popRef
14310
+ }, children);
14311
+ if (typeof document === "undefined" || document.body === null || document.body === void 0) return node;
14312
+ return (0, import_react_dom.createPortal)(node, document.body, "jet-hub-badge-pop");
14227
14313
  }
14228
14314
  function renderPreference() {
14229
- return React8.createElement("div", {
14315
+ return React6.createElement("div", {
14230
14316
  key: "pref",
14231
14317
  className: "dim-jh-badgePref",
14232
14318
  // ⚠️ 三档的差别必须写清:auto 与 credits 在**有订阅时**表现不同
14233
14319
  //(auto 会回落,credits 不回落到订阅)—— 只说「优先显示哪个」会让人以为两档一样。
14234
14320
  title: "显示偏好:「自动」= 优先显示一共能用的余额(没有余额读数才显示订阅窗口/套餐);「优先订阅」= 只看窗口与套餐;「只看积分」= 强制只显示余额,也是套餐判定不准时的兜底"
14235
14321
  }, [
14236
- ...BADGE_PREFERENCES.map((item) => React8.createElement("button", {
14322
+ ...BADGE_PREFERENCES.map((item) => React6.createElement("button", {
14237
14323
  key: item,
14238
14324
  type: "button",
14239
14325
  className: "dim-jh-badgePrefBtn",
@@ -14242,7 +14328,7 @@ function UsageBadgeActive(props) {
14242
14328
  void onPickPreference(item);
14243
14329
  }
14244
14330
  }, BADGE_PREFERENCE_LABELS[item])),
14245
- prefError === "" ? null : React8.createElement("span", { key: "err", className: "dim-jh-badgeFail" }, prefError)
14331
+ prefError === "" ? null : React6.createElement("span", { key: "err", className: "dim-jh-badgeFail" }, prefError)
14246
14332
  ]);
14247
14333
  }
14248
14334
  function renderSubscription() {
@@ -14252,47 +14338,47 @@ function UsageBadgeActive(props) {
14252
14338
  const rows = Array.isArray(subscription.accounts) ? subscription.accounts : [];
14253
14339
  const account = rows.find((row) => row?.ok === true) ?? rows[0];
14254
14340
  const windows = account === void 0 ? [] : quotaWindowsOf(account.windows ?? []);
14255
- return React8.createElement("div", { key: "sub", className: "dim-jh-badgeSection" }, [
14256
- React8.createElement("div", { key: "title", className: "dim-jh-badgeSectionTitle" }, "订阅额度"),
14257
- ...windows.length === 0 ? [React8.createElement(
14341
+ return React6.createElement("div", { key: "sub", className: "dim-jh-badgeSection" }, [
14342
+ React6.createElement("div", { key: "title", className: "dim-jh-badgeSectionTitle" }, "订阅额度"),
14343
+ ...windows.length === 0 ? [React6.createElement(
14258
14344
  "div",
14259
14345
  { key: "empty", className: "dim-jh-badgeNote" },
14260
14346
  account?.ok === true ? "该账号没有额度窗口" : account?.error || "订阅额度不可用"
14261
- )] : [React8.createElement(
14347
+ )] : [React6.createElement(
14262
14348
  "div",
14263
14349
  { key: "wins", className: "dim-jh-badgeWins" },
14264
14350
  windows.map(([type, windowLabel, win]) => {
14265
14351
  const percent = quotaPercentValue(win?.percentUsed);
14266
14352
  const left = quotaResetsIn(win?.resetsAt);
14267
- return React8.createElement("div", { key: type, className: "dim-jh-badgeWin" }, [
14268
- React8.createElement("span", { key: "l", className: "dim-jh-badgeWinLabel" }, windowLabel),
14269
- React8.createElement(
14353
+ return React6.createElement("div", { key: type, className: "dim-jh-badgeWin" }, [
14354
+ React6.createElement("span", { key: "l", className: "dim-jh-badgeWinLabel" }, windowLabel),
14355
+ React6.createElement(
14270
14356
  "div",
14271
14357
  { key: "bar", className: "dim-jh-quotaBar" },
14272
- React8.createElement("div", {
14358
+ React6.createElement("div", {
14273
14359
  key: "fill",
14274
14360
  className: "dim-jh-quotaBarFill",
14275
14361
  "data-tone": quotaTone(percent),
14276
14362
  style: { width: `${percent}%` }
14277
14363
  })
14278
14364
  ),
14279
- React8.createElement("span", { key: "v", className: "dim-jh-badgeValue" }, formatQuotaPercent(percent)),
14280
- left === "" ? null : React8.createElement("span", { key: "r", className: "dim-jh-badgeWinReset", title: left }, left)
14365
+ React6.createElement("span", { key: "v", className: "dim-jh-badgeValue" }, formatQuotaPercent(percent)),
14366
+ left === "" ? null : React6.createElement("span", { key: "r", className: "dim-jh-badgeWinReset", title: left }, left)
14281
14367
  ]);
14282
14368
  })
14283
14369
  )]
14284
14370
  ]);
14285
14371
  }
14286
14372
  const groups = view.planGroups;
14287
- return React8.createElement("div", { key: "sub", className: "dim-jh-badgeSection" }, [
14288
- React8.createElement("div", { key: "title", className: "dim-jh-badgeSectionTitle" }, "订阅套餐"),
14289
- ...groups.length === 0 ? [React8.createElement("div", { key: "empty", className: "dim-jh-badgeNote" }, "没有可用的套餐包")] : groups.map((group) => React8.createElement("div", {
14373
+ return React6.createElement("div", { key: "sub", className: "dim-jh-badgeSection" }, [
14374
+ React6.createElement("div", { key: "title", className: "dim-jh-badgeSectionTitle" }, "订阅套餐"),
14375
+ ...groups.length === 0 ? [React6.createElement("div", { key: "empty", className: "dim-jh-badgeNote" }, "没有可用的套餐包")] : groups.map((group) => React6.createElement("div", {
14290
14376
  key: `${group.name}\0${group.unit}`,
14291
14377
  className: "dim-jh-badgeRow"
14292
14378
  }, [
14293
- React8.createElement("div", { key: "head", className: "dim-jh-badgeRowHead" }, [
14294
- React8.createElement("span", { key: "l", className: "dim-jh-badgeRowName", title: group.name }, group.name),
14295
- React8.createElement(
14379
+ React6.createElement("div", { key: "head", className: "dim-jh-badgeRowHead" }, [
14380
+ React6.createElement("span", { key: "l", className: "dim-jh-badgeRowName", title: group.name }, group.name),
14381
+ React6.createElement(
14296
14382
  "span",
14297
14383
  { key: "v", className: "dim-jh-badgeValue" },
14298
14384
  // ⚠️ 数值与单位之间**不留空格**(`100.00M / 200.00MToken`):
@@ -14305,7 +14391,7 @@ function UsageBadgeActive(props) {
14305
14391
  `${formatUnits(group.remaining, group.unit) ?? "?"} / ${formatUnits(group.total, group.unit) ?? "?"}${group.label}`
14306
14392
  )
14307
14393
  ]),
14308
- React8.createElement(
14394
+ React6.createElement(
14309
14395
  "div",
14310
14396
  { key: "note", className: "dim-jh-badgeRowNote" },
14311
14397
  [
@@ -14325,17 +14411,17 @@ function UsageBadgeActive(props) {
14325
14411
  limit: CREDITS_COLLAPSED_LIMIT,
14326
14412
  expanded: creditsExpanded
14327
14413
  });
14328
- return React8.createElement("div", { key: "credits", className: "dim-jh-badgeSection" }, [
14414
+ return React6.createElement("div", { key: "credits", className: "dim-jh-badgeSection" }, [
14329
14415
  // 合计放进节标题右侧,省掉一整行
14330
- React8.createElement("div", { key: "title", className: "dim-jh-badgeSectionTitle" }, [
14416
+ React6.createElement("div", { key: "title", className: "dim-jh-badgeSectionTitle" }, [
14331
14417
  // ⚠️ 节标题的单位标签走**纯函数**(`creditSectionLabel`),不在这里写三元:
14332
14418
  // 原写法是 `quotaGroup === undefined ? '积分' : unitLabel(...)` —— 那个
14333
14419
  // 兜底分支把 **ZCode 的 token** 冒充成了积分(真实缺陷,2026-10-05 复审
14334
14420
  // PR !56 时发现),渲染成「积分 … 94.54MToken」自相矛盾的一屏。
14335
14421
  // 判据收进 `badge-model.js` 是为了能被单测锁死(组件里没法测 —— 本仓库
14336
14422
  // node_modules 没有 react)。
14337
- React8.createElement("span", { key: "l" }, creditSectionLabel(view.groups)),
14338
- accounts.length === 0 || sum === "" ? null : React8.createElement(
14423
+ React6.createElement("span", { key: "l" }, creditSectionLabel(view.groups)),
14424
+ accounts.length === 0 || sum === "" ? null : React6.createElement(
14339
14425
  "span",
14340
14426
  { key: "sum", className: "dim-jh-badgeSectionSum" },
14341
14427
  // ⚠️ 「合计」二字只对**可累加的余额**成立。配额窗口是并行百分比,
@@ -14344,18 +14430,18 @@ function UsageBadgeActive(props) {
14344
14430
  quotaGroup === void 0 ? `合计 ${sum}` : sum
14345
14431
  )
14346
14432
  ]),
14347
- ...accounts.length === 0 ? [React8.createElement(
14433
+ ...accounts.length === 0 ? [React6.createElement(
14348
14434
  "div",
14349
14435
  { key: "empty", className: "dim-jh-badgeNote" },
14350
14436
  value?.disabledCount > 0 ? "该渠道的账号全部已停用" : "该渠道还没有账号(可在 Jet Hub 设置页添加)"
14351
- )] : shown.map((row) => React8.createElement("div", { key: row.accountId, className: "dim-jh-badgeRow" }, [
14352
- React8.createElement("div", { key: "head", className: "dim-jh-badgeRowHead" }, [
14353
- React8.createElement("span", {
14437
+ )] : shown.map((row) => React6.createElement("div", { key: row.accountId, className: "dim-jh-badgeRow" }, [
14438
+ React6.createElement("div", { key: "head", className: "dim-jh-badgeRowHead" }, [
14439
+ React6.createElement("span", {
14354
14440
  key: "l",
14355
14441
  className: "dim-jh-badgeRowName",
14356
14442
  title: row.nickname || row.accountId
14357
14443
  }, row.nickname || row.accountId),
14358
- React8.createElement("span", {
14444
+ React6.createElement("span", {
14359
14445
  key: "v",
14360
14446
  className: "dim-jh-badgeValue",
14361
14447
  "data-tone": row.balance === null ? "warn" : "ok",
@@ -14366,7 +14452,7 @@ function UsageBadgeActive(props) {
14366
14452
  // 存在时才占一行。用户 2026-10-12 明确要求三档分色。
14367
14453
  row.balance === null ? null : renderSplitNote(splitParts(row.balance, windowDays, provider))
14368
14454
  ])),
14369
- hidden === 0 ? null : React8.createElement("button", {
14455
+ hidden === 0 ? null : React6.createElement("button", {
14370
14456
  key: "more",
14371
14457
  type: "button",
14372
14458
  className: "dim-jh-badgeMore",
@@ -14377,14 +14463,14 @@ function UsageBadgeActive(props) {
14377
14463
  }
14378
14464
  function renderNote(text) {
14379
14465
  if (typeof text !== "string" || text.length === 0) return null;
14380
- return React8.createElement("div", { key: "note", className: "dim-jh-badgeRowNote" }, text);
14466
+ return React6.createElement("div", { key: "note", className: "dim-jh-badgeRowNote" }, text);
14381
14467
  }
14382
14468
  function renderSplitNote(parts) {
14383
14469
  if (!Array.isArray(parts) || parts.length === 0) return null;
14384
14470
  const children = [];
14385
14471
  parts.forEach((part, index) => {
14386
- if (index > 0) children.push(React8.createElement("span", { key: `sep-${part.key}`, className: "dim-jh-badgeNoteSep" }, " · "));
14387
- children.push(React8.createElement("span", {
14472
+ if (index > 0) children.push(React6.createElement("span", { key: `sep-${part.key}`, className: "dim-jh-badgeNoteSep" }, " · "));
14473
+ children.push(React6.createElement("span", {
14388
14474
  key: part.key,
14389
14475
  className: "dim-jh-badgeNotePart",
14390
14476
  "data-tone": part.tone,
@@ -14404,14 +14490,14 @@ function UsageBadgeActive(props) {
14404
14490
  ...part.countdown === void 0 ? {} : { title: `最早作废:${part.countdown}` }
14405
14491
  }, part.countdown === void 0 ? part.text : `${part.text}(${part.countdown})`));
14406
14492
  });
14407
- return React8.createElement("div", { key: "note", className: "dim-jh-badgeRowNote" }, children);
14493
+ return React6.createElement("div", { key: "note", className: "dim-jh-badgeRowNote" }, children);
14408
14494
  }
14409
14495
  function renderClaim() {
14410
14496
  const canClaimCurrent = supportsDailyCheckin(provider);
14411
14497
  const allBusy = claiming === "all";
14412
- return React8.createElement("div", { key: "claim", className: "dim-jh-badgeSection dim-jh-badgeClaim" }, [
14413
- React8.createElement("div", { key: "row", className: "dim-jh-badgeClaimRow" }, [
14414
- canClaimCurrent ? React8.createElement("button", {
14498
+ return React6.createElement("div", { key: "claim", className: "dim-jh-badgeSection dim-jh-badgeClaim" }, [
14499
+ React6.createElement("div", { key: "row", className: "dim-jh-badgeClaimRow" }, [
14500
+ canClaimCurrent ? React6.createElement("button", {
14415
14501
  key: "cur",
14416
14502
  type: "button",
14417
14503
  className: "dim-jh-badgeAction",
@@ -14426,7 +14512,7 @@ function UsageBadgeActive(props) {
14426
14512
  void onClaim();
14427
14513
  }
14428
14514
  }, claiming === "current" ? "领取中…" : "签到(本渠道)") : null,
14429
- React8.createElement("button", {
14515
+ React6.createElement("button", {
14430
14516
  key: "all",
14431
14517
  type: "button",
14432
14518
  className: "dim-jh-badgeAction",
@@ -14451,19 +14537,19 @@ function UsageBadgeActive(props) {
14451
14537
  * 「全部渠道签到」,以为按钮丢了。真相是能力表里 `dailyCheckin: false`
14452
14538
  * (WorkBuddy 国际版 / Cline 等后端没有签到接口)。少了这一句,用户只能靠猜。
14453
14539
  */
14454
- canClaimCurrent ? null : React8.createElement(
14540
+ canClaimCurrent ? null : React6.createElement(
14455
14541
  "div",
14456
14542
  { key: "nocount", className: "dim-jh-badgeNote" },
14457
14543
  "该渠道没有签到接口,签到请用「全部渠道签到」"
14458
14544
  ),
14459
- claimNotice === null ? null : React8.createElement("div", {
14545
+ claimNotice === null ? null : React6.createElement("div", {
14460
14546
  key: "notice",
14461
14547
  className: "dim-jh-badgeNotice",
14462
14548
  "data-tone": claimNotice.tone
14463
14549
  }, claimNotice.text),
14464
14550
  // 「需要用户操作」的提示单独列出(后端显式字段 actionRequired),
14465
14551
  // 混进计数行会被读漏,而它的价值就在于被看到。
14466
- ...(claimNotice?.notes || []).map((message, index) => React8.createElement("div", {
14552
+ ...(claimNotice?.notes || []).map((message, index) => React6.createElement("div", {
14467
14553
  key: `note-${index}`,
14468
14554
  className: "dim-jh-badgeNotice",
14469
14555
  "data-tone": "warn"
@@ -14477,12 +14563,12 @@ function UsageBadgeActive(props) {
14477
14563
  const running = auto.running === true;
14478
14564
  if (!running && channels.length === 0) return null;
14479
14565
  const stamp = running ? "" : formatUpdatedAt(auto.lastAt);
14480
- return React8.createElement("div", { key: "autostatus", className: "dim-jh-badgeAutoStatus" }, [
14566
+ return React6.createElement("div", { key: "autostatus", className: "dim-jh-badgeAutoStatus" }, [
14481
14567
  // 小关闭按钮在**文字上方**(用户:「在文字上方放个小按钮,点击直接关闭」)。
14482
- React8.createElement(
14568
+ React6.createElement(
14483
14569
  "div",
14484
14570
  { key: "closerow", className: "dim-jh-badgeAutoCloseRow" },
14485
- React8.createElement("button", {
14571
+ React6.createElement("button", {
14486
14572
  key: "close",
14487
14573
  type: "button",
14488
14574
  className: "dim-jh-badgeAutoClose",
@@ -14493,15 +14579,15 @@ function UsageBadgeActive(props) {
14493
14579
  }
14494
14580
  }, "×")
14495
14581
  ),
14496
- React8.createElement(
14582
+ React6.createElement(
14497
14583
  "div",
14498
14584
  { key: "head", className: "dim-jh-badgeAutoStatusHead" },
14499
14585
  running ? "自动签到 · 进行中…" : `自动签到${stamp === "" ? "" : ` · ${stamp}`}:${auto.lastResult}`
14500
14586
  ),
14501
- channels.length === 0 ? null : React8.createElement(
14587
+ channels.length === 0 ? null : React6.createElement(
14502
14588
  "div",
14503
14589
  { key: "channels", className: "dim-jh-badgeAutoChannels" },
14504
- channels.map((entry2, index) => React8.createElement("span", {
14590
+ channels.map((entry2, index) => React6.createElement("span", {
14505
14591
  key: `${entry2.provider}-${index}`,
14506
14592
  className: "dim-jh-badgeAutoChannel"
14507
14593
  }, `${providerLabel2(entry2.provider)} ${entry2.text}`))
@@ -14514,7 +14600,7 @@ function UsageBadgeActive(props) {
14514
14600
  if (view.failedCount > 0) parts.push(view.incompleteNote === "" ? `${view.failedCount} 个账号读取失败` : view.incompleteNote);
14515
14601
  if (failed && snapshot !== null) parts.push("本次刷新失败,显示的是上一次读数");
14516
14602
  if (parts.length === 0) return null;
14517
- return React8.createElement("div", { key: "foot", className: "dim-jh-badgeFoot" }, parts.join(" · "));
14603
+ return React6.createElement("div", { key: "foot", className: "dim-jh-badgeFoot" }, parts.join(" · "));
14518
14604
  }
14519
14605
  }
14520
14606
  function balanceLine(balance) {
@@ -14572,131 +14658,330 @@ function summarizeClaim(result) {
14572
14658
  };
14573
14659
  }
14574
14660
 
14575
- // plugin-src/client/usage-panel.js
14576
- var USAGE_PANEL_KEY = "jet-hub-usage";
14577
- var USAGE_SIDEBAR_ORDER = 21;
14578
- var AUTO_ENTRY_LABEL = "自动 · 临期优先";
14579
- function usagePanelProviders() {
14580
- return [
14581
- { id: AUTO_PROVIDER_ID, label: AUTO_ENTRY_LABEL },
14582
- ...PROVIDER_REGISTRY.filter((d) => supportsCreditBalance(d.id)).map((d) => ({ id: d.id, label: d.label }))
14583
- ];
14661
+ // plugin-src/client/panel-entry.js
14662
+ var React8 = __toESM(require("react"), 1);
14663
+
14664
+ // plugin-src/client/error-boundary.js
14665
+ var React7 = __toESM(require("react"), 1);
14666
+ var NO_ERROR = Symbol("jet-hub:no-error");
14667
+ function describeThrown(error) {
14668
+ try {
14669
+ if (error !== null && error !== void 0 && typeof error.message === "string" && error.message.length > 0) {
14670
+ return error.message;
14671
+ }
14672
+ } catch {
14673
+ }
14674
+ try {
14675
+ return String(error);
14676
+ } catch {
14677
+ return "(抛出值无法转为文本,请查看控制台)";
14678
+ }
14679
+ }
14680
+ function withErrorBoundary(Inner, options) {
14681
+ const label = options !== null && typeof options === "object" && typeof options.label === "string" && options.label.length > 0 ? options.label : "这个面板";
14682
+ class PanelErrorBoundary extends React7.Component {
14683
+ constructor(props) {
14684
+ super(props);
14685
+ this.state = { error: NO_ERROR };
14686
+ }
14687
+ static getDerivedStateFromError(error) {
14688
+ return { error };
14689
+ }
14690
+ componentDidCatch(error, info) {
14691
+ console.error(`[jet-hub] ${label}渲染失败,已拦住(页面其余部分继续可用):`, error, info?.componentStack);
14692
+ }
14693
+ render() {
14694
+ const error = this.state.error;
14695
+ if (error === NO_ERROR) return React7.createElement(Inner, this.props);
14696
+ const message = describeThrown(error);
14697
+ return React7.createElement(
14698
+ "div",
14699
+ {
14700
+ className: "dim-jh-probeNotice",
14701
+ "data-tone": "error",
14702
+ role: "alert",
14703
+ style: { margin: "16px" }
14704
+ },
14705
+ React7.createElement("div", null, `${label}渲染失败,已拦住 —— 其余页面仍可正常使用,不必重启。`),
14706
+ React7.createElement("div", { style: { marginTop: "6px", fontFamily: "monospace", fontSize: "12px" } }, message),
14707
+ // ⚠️ **必须给出可自我恢复的出路**(2026-10-25 审计 A3-2)。
14708
+ //
14709
+ // 本 fallback 是**粘性**的:没有 `key`、也没有 `componentDidUpdate`
14710
+ // 重置 ⇒ 同一实例一旦进 error 就永远显示 fallback(数据恢复了也不回来)。
14711
+ // 审计实测:数据恢复后仍显示 fallback,只有**新建实例**才恢复。
14712
+ //
14713
+ // 而用户其实**不必重启**:宿主 `SettingsPanel` 在 `open === false` 时整棵
14714
+ // 不挂载、`main` 是 keyed 槽 ⇒「关掉设置再打开」/「切走再切回」都能恢复。
14715
+ // 但**这条路径不可发现** —— 用户看到一块报错,不知道关掉再打开就能好。
14716
+ //
14717
+ // ⇒ 两件事:①给一个**就地重试**(`setState` 回 `NO_ERROR`,子树随即重挂载,
14718
+ // 比让用户摸索「关掉再打开」快得多);②把那条路径**写出来**当兜底。
14719
+ React7.createElement(
14720
+ "div",
14721
+ { style: { marginTop: "8px" } },
14722
+ React7.createElement("button", {
14723
+ type: "button",
14724
+ className: "dim-jh-btn",
14725
+ onClick: () => {
14726
+ this.setState({ error: NO_ERROR });
14727
+ }
14728
+ }, "重试"),
14729
+ React7.createElement(
14730
+ "span",
14731
+ { style: { marginLeft: "8px", opacity: 0.75 } },
14732
+ "也可以关掉这一节再重新打开(或切到别的页面再切回来)来恢复。"
14733
+ )
14734
+ ),
14735
+ React7.createElement(
14736
+ "div",
14737
+ { style: { marginTop: "6px" } },
14738
+ "这是插件的缺陷,不是你操作错了。把上面这行报错连同「当时点了什么」一起反馈即可。"
14739
+ )
14740
+ );
14741
+ }
14742
+ }
14743
+ PanelErrorBoundary.displayName = `withErrorBoundary(${Inner.displayName || Inner.name || "Component"})`;
14744
+ return PanelErrorBoundary;
14745
+ }
14746
+
14747
+ // plugin-src/client/panel-entry-store.js
14748
+ var VALID_ENTRIES = ["sidebar", "settings"];
14749
+ var FALLBACK_ENTRY = "sidebar";
14750
+ var JET_HUB_PANEL_KEY = "jet-hub";
14751
+ var JET_HUB_SIDEBAR_ORDER = 20;
14752
+ var PANEL_ENTRY_READ_TIMEOUT_MS = 5e3;
14753
+ var PANEL_ENTRY_READ_ATTEMPTS = 3;
14754
+ var PANEL_ENTRY_RETRY_DELAY_MS = 200;
14755
+ function delay(ms) {
14756
+ return new Promise((resolve) => setTimeout(resolve, ms));
14757
+ }
14758
+ var entry = null;
14759
+ var readFailed = false;
14760
+ var inflight = null;
14761
+ var writeSeq = 0;
14762
+ var listeners = /* @__PURE__ */ new Set();
14763
+ function normalize(raw) {
14764
+ return typeof raw === "string" && VALID_ENTRIES.includes(raw) ? raw : null;
14765
+ }
14766
+ function panelEntry() {
14767
+ return entry;
14768
+ }
14769
+ function panelEntryShowsSidebar() {
14770
+ return entry !== "settings";
14771
+ }
14772
+ function panelEntryShowsSettings() {
14773
+ return entry === "settings";
14774
+ }
14775
+ function panelEntryReadFailed() {
14776
+ return readFailed;
14777
+ }
14778
+ function subscribePanelEntry(listener) {
14779
+ listeners.add(listener);
14780
+ return () => {
14781
+ listeners.delete(listener);
14782
+ };
14783
+ }
14784
+ function publish(nextEntry, nextFailed) {
14785
+ if (entry === nextEntry && readFailed === nextFailed) return;
14786
+ entry = nextEntry;
14787
+ readFailed = nextFailed;
14788
+ for (const listener of [...listeners]) {
14789
+ try {
14790
+ listener();
14791
+ } catch (caught) {
14792
+ console.error("[jet-hub] 面板入口监听器抛错", caught);
14793
+ }
14794
+ }
14795
+ }
14796
+ function readSignal() {
14797
+ if (typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function") {
14798
+ return AbortSignal.timeout(PANEL_ENTRY_READ_TIMEOUT_MS);
14799
+ }
14800
+ if (typeof AbortController !== "function") return void 0;
14801
+ const controller = new AbortController();
14802
+ const timer = setTimeout(() => controller.abort(), PANEL_ENTRY_READ_TIMEOUT_MS);
14803
+ if (typeof timer === "object" && timer !== null && typeof timer.unref === "function") {
14804
+ timer.unref();
14805
+ }
14806
+ controller.signal?.addEventListener?.("abort", () => clearTimeout(timer), { once: true });
14807
+ return controller.signal;
14808
+ }
14809
+ function loadPanelEntry(rpcCall) {
14810
+ if (inflight !== null) return inflight;
14811
+ const seqAtStart = writeSeq;
14812
+ const task = (async () => {
14813
+ let lastError;
14814
+ for (let attempt = 1; attempt <= PANEL_ENTRY_READ_ATTEMPTS; attempt += 1) {
14815
+ try {
14816
+ const result = await rpcCall("panelEntry.get", {}, readSignal());
14817
+ if (writeSeq !== seqAtStart) return entry ?? FALLBACK_ENTRY;
14818
+ const next = normalize(result?.entry);
14819
+ if (next !== null) {
14820
+ publish(next, false);
14821
+ } else {
14822
+ publish(entry ?? FALLBACK_ENTRY, true);
14823
+ }
14824
+ return entry ?? FALLBACK_ENTRY;
14825
+ } catch (caught) {
14826
+ lastError = caught;
14827
+ if (writeSeq !== seqAtStart) return entry ?? FALLBACK_ENTRY;
14828
+ if (attempt >= PANEL_ENTRY_READ_ATTEMPTS) break;
14829
+ await delay(PANEL_ENTRY_RETRY_DELAY_MS * attempt);
14830
+ if (writeSeq !== seqAtStart) return entry ?? FALLBACK_ENTRY;
14831
+ }
14832
+ }
14833
+ console.warn(
14834
+ `[jet-hub] 读取面板入口偏好失败,按仅侧栏处理(已重试 ${PANEL_ENTRY_READ_ATTEMPTS - 1} 次)`,
14835
+ lastError
14836
+ );
14837
+ if (writeSeq === seqAtStart) publish(entry ?? FALLBACK_ENTRY, true);
14838
+ return entry ?? FALLBACK_ENTRY;
14839
+ })();
14840
+ inflight = task;
14841
+ const clear = () => {
14842
+ if (inflight === task) inflight = null;
14843
+ };
14844
+ void task.then(clear, clear);
14845
+ return task;
14846
+ }
14847
+ async function setPanelEntry(rpcCall, next) {
14848
+ const result = await rpcCall("panelEntry.set", { entry: next });
14849
+ const confirmed = normalize(result?.entry);
14850
+ if (confirmed === null) {
14851
+ throw new Error("面板入口偏好没有返回合法 entry");
14852
+ }
14853
+ writeSeq += 1;
14854
+ publish(confirmed, false);
14855
+ return confirmed;
14584
14856
  }
14585
- function UsageSidebarIcon({ size }) {
14857
+
14858
+ // plugin-src/client/panel-entry.js
14859
+ var JetHubPageForSettings = withErrorBoundary(JetHubPage, { label: "Jet Hub 设置页" });
14860
+ var JetHubPageForMain = withErrorBoundary(JetHubPage, { label: "Jet Hub 面板" });
14861
+ function JetHubSidebarIcon({ size }) {
14586
14862
  const px = typeof size === "number" && size > 0 ? size : 16;
14587
- return React9.createElement("svg", {
14588
- width: px,
14589
- height: px,
14590
- viewBox: "0 0 16 16",
14591
- fill: "none",
14592
- "aria-hidden": "true"
14593
- }, [
14594
- React9.createElement("ellipse", {
14595
- key: "top",
14596
- cx: 8,
14597
- cy: 4.2,
14598
- rx: 5.2,
14599
- ry: 2.6,
14600
- stroke: "currentColor",
14601
- strokeWidth: 1.35
14602
- }),
14603
- React9.createElement("path", {
14604
- key: "mid",
14605
- d: "M2.8 4.2v3.3c0 1.44 2.33 2.6 5.2 2.6s5.2-1.16 5.2-2.6V4.2",
14863
+ return React8.createElement(
14864
+ "svg",
14865
+ {
14866
+ width: px,
14867
+ height: px,
14868
+ viewBox: "0 0 16 16",
14869
+ fill: "none",
14870
+ xmlns: "http://www.w3.org/2000/svg",
14871
+ "aria-hidden": "true"
14872
+ },
14873
+ React8.createElement("path", {
14874
+ d: "M8 1.7 13.5 4.85v6.3L8 14.3 2.5 11.15v-6.3z",
14606
14875
  stroke: "currentColor",
14607
14876
  strokeWidth: 1.35,
14608
- strokeLinecap: "round"
14877
+ strokeLinejoin: "round"
14609
14878
  }),
14610
- React9.createElement("path", {
14611
- key: "bot",
14612
- d: "M2.8 7.5v3.3c0 1.44 2.33 2.6 5.2 2.6s5.2-1.16 5.2-2.6V7.5",
14613
- stroke: "currentColor",
14614
- strokeWidth: 1.35,
14615
- strokeLinecap: "round"
14616
- })
14617
- ]);
14879
+ React8.createElement("circle", { cx: 8, cy: 8, r: 1.7, fill: "currentColor" })
14880
+ );
14618
14881
  }
14619
- var UsagePanelPageForMain = withErrorBoundary(UsagePanelPage, { label: "积分用量面板" });
14620
- function UsagePanelMain({ rpcCall }) {
14882
+ function JetHubMainPanel({ rpcCall }) {
14621
14883
  if (typeof rpcCall !== "function") return null;
14622
- return React9.createElement(
14884
+ return React8.createElement(
14623
14885
  "div",
14624
- { className: "dim-jh-panelHost dim-jh-usageHost", "data-plugin": "@xixka/dsh-hub" },
14625
- React9.createElement(UsagePanelPageForMain, { rpcCall })
14886
+ { className: "dim-jh-panelHost", "data-plugin": "@xixka/dsh-hub" },
14887
+ React8.createElement(JetHubPageForMain, { rpcCall })
14626
14888
  );
14627
14889
  }
14628
- function UsagePanelPage({ rpcCall }) {
14629
- const [provider, setProvider] = React9.useState(AUTO_PROVIDER_ID);
14630
- const entries = React9.useMemo(usagePanelProviders, []);
14631
- const api = React9.useMemo(() => ({
14632
- providerLabel,
14633
- readBadge: (target, options) => rpcCall("usage.badge", { provider: target, ...options }),
14634
- // 显示偏好(自动 / 优先订阅 / 只看积分):宿主回落语义见 usage-badge.js 的 renderPreference。
14635
- writePreference: (preference) => rpcCall("usage.badgePreference", { preference }),
14636
- // 自动签到开关(全局一个,不分渠道):宿主在「打开」时会立刻跑一轮。
14637
- setAutoCheckin: (enabled) => rpcCall("usage.autoCheckin", { enabled }),
14638
- // 关闭那行常驻的自动签到状态文字(只关当前这一轮,下一轮会重新出现)。
14639
- dismissAutoCheckin: () => rpcCall("usage.autoCheckin", { dismiss: true }),
14640
- // 一键领取:每日签到 + (buddy / workbuddy 的)成长中心任务。
14641
- //
14642
- // ⚠️ runTasks 缺省**必须为 false** —— 同一个方法也是「每日首次启动自动签到」
14643
- // 的执行体(宿主 auto-checkin 的 claim 回调)。成长一轮单账号 90~270s、
14644
- // 全串行,默认开启等于每次开机自动打几十个上游请求。
14645
- // budgetMs 缺省由宿主取 10 分钟;传 0 或负数表示不限时。
14646
- claimCredits: (target, runTasks, budgetMs) => rpcCall("credits.claimAll", { provider: target, runTasks, budgetMs })
14647
- }), [rpcCall]);
14648
- return React9.createElement("div", { className: "dim-jh-usagePanel" }, [
14649
- React9.createElement("div", { key: "head", className: "dim-jh-usageHead" }, [
14650
- React9.createElement("h2", { key: "title", className: "dim-jh-usageTitle" }, "积分用量"),
14651
- React9.createElement(
14652
- "div",
14653
- { key: "sub", className: "dim-jh-usageSub" },
14654
- "各渠道的余额、订阅与签到。账号的添加、启停与改名仍在 Jet Hub 设置页。"
14655
- )
14656
- ]),
14657
- /**
14658
- * 渠道选择器:按钮组 + `aria-pressed`(本仓库无 <select> 先例,偏好分段
14659
- * 控件同款做法)。chips 自动换行 —— 十几个渠道在窄面板里一行放不下。
14660
- */
14661
- React9.createElement("div", {
14662
- key: "rail",
14663
- className: "dim-jh-usageRail",
14664
- role: "group",
14665
- "aria-label": "选择要查看用量的渠道"
14666
- }, entries.map((entry2) => React9.createElement("button", {
14667
- key: entry2.id,
14668
- type: "button",
14669
- className: "dim-jh-usageChip",
14670
- "aria-pressed": provider === entry2.id,
14671
- "data-active": provider === entry2.id ? "true" : "false",
14672
- title: entry2.id === AUTO_PROVIDER_ID ? "自动路由(临期优先)当前实际使用的渠道的用量" : `${entry2.label} 的用量`,
14673
- onClick: () => {
14674
- setProvider(entry2.id);
14675
- }
14676
- }, entry2.label))),
14677
- React9.createElement(UsageBadgeCard, {
14678
- key: "card",
14679
- provider,
14680
- ...api
14681
- })
14682
- ]);
14683
- }
14684
- function registerUsagePanelEntries(ctx, rpcCall) {
14890
+ function registerJetHubPanelEntries(ctx, rpcCall) {
14685
14891
  ctx.slots.inject("main", () => ctx.slots.register({
14686
14892
  name: "main",
14687
- key: USAGE_PANEL_KEY,
14893
+ key: JET_HUB_PANEL_KEY,
14688
14894
  inject: () => ({ rpcCall })
14689
- }, UsagePanelMain));
14690
- ctx.slots.inject("sidebar.panellist", () => ctx.slots.register({
14691
- name: "sidebar.panellist",
14692
- id: USAGE_PANEL_KEY,
14693
- order: USAGE_SIDEBAR_ORDER,
14694
- label: () => "积分用量"
14695
- }, UsageSidebarIcon));
14895
+ }, JetHubMainPanel));
14896
+ let layout;
14897
+ ctx.inject(["layout"], (scoped) => {
14898
+ layout = scoped.layout;
14899
+ return () => {
14900
+ layout = void 0;
14901
+ };
14902
+ });
14903
+ const deselectIfActive = () => {
14904
+ try {
14905
+ if (layout?.panelInfo?.getSnapshot?.()?.activePanelId !== JET_HUB_PANEL_KEY) return;
14906
+ layout.selectPanel(null);
14907
+ } catch (caught) {
14908
+ console.warn("[jet-hub] 撤销侧栏入口时取消选中失败", caught);
14909
+ }
14910
+ };
14911
+ ctx.slots.inject("sidebar.panellist", () => {
14912
+ let stopRow;
14913
+ const sync = (visible) => {
14914
+ if (visible && stopRow === void 0) {
14915
+ stopRow = ctx.slots.register({
14916
+ name: "sidebar.panellist",
14917
+ id: JET_HUB_PANEL_KEY,
14918
+ order: JET_HUB_SIDEBAR_ORDER,
14919
+ label: () => "Jet Hub"
14920
+ }, JetHubSidebarIcon);
14921
+ return;
14922
+ }
14923
+ if (!visible && stopRow !== void 0) {
14924
+ const stop = stopRow;
14925
+ stopRow = void 0;
14926
+ stop();
14927
+ deselectIfActive();
14928
+ }
14929
+ };
14930
+ const unsubscribe = subscribePanelEntry(() => sync(panelEntryShowsSidebar()));
14931
+ sync(panelEntryShowsSidebar());
14932
+ let disposed = false;
14933
+ void loadPanelEntry(rpcCall).then(() => {
14934
+ if (!disposed) sync(panelEntryShowsSidebar());
14935
+ });
14936
+ return () => {
14937
+ disposed = true;
14938
+ unsubscribe();
14939
+ if (stopRow !== void 0) {
14940
+ const stop = stopRow;
14941
+ stopRow = void 0;
14942
+ stop();
14943
+ }
14944
+ };
14945
+ });
14946
+ ctx.slots.inject("settings.section", () => {
14947
+ let stopSection;
14948
+ const sync = (visible) => {
14949
+ if (visible && stopSection === void 0) {
14950
+ stopSection = ctx.slots.register({
14951
+ name: "settings.section",
14952
+ id: JET_HUB_PANEL_KEY,
14953
+ order: 50,
14954
+ label: () => "Jet Hub",
14955
+ inject: () => ({ rpcCall })
14956
+ }, JetHubPageForSettings);
14957
+ return;
14958
+ }
14959
+ if (!visible && stopSection !== void 0) {
14960
+ const stop = stopSection;
14961
+ stopSection = void 0;
14962
+ stop();
14963
+ }
14964
+ };
14965
+ const unsubscribe = subscribePanelEntry(() => sync(panelEntryShowsSettings()));
14966
+ sync(panelEntryShowsSettings());
14967
+ let disposed = false;
14968
+ void loadPanelEntry(rpcCall).then(() => {
14969
+ if (!disposed) sync(panelEntryShowsSettings());
14970
+ });
14971
+ return () => {
14972
+ disposed = true;
14973
+ unsubscribe();
14974
+ if (stopSection !== void 0) {
14975
+ const stop = stopSection;
14976
+ stopSection = void 0;
14977
+ stop();
14978
+ }
14979
+ };
14980
+ });
14696
14981
  }
14697
14982
 
14698
14983
  // plugin-src/client/settings-card.js
14699
- var React10 = __toESM(require("react"), 1);
14984
+ var React9 = __toESM(require("react"), 1);
14700
14985
  var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
14701
14986
  var OPTIONS = [
14702
14987
  { id: "sidebar", label: "仅侧栏" },
@@ -14710,17 +14995,17 @@ function currentEntry() {
14710
14995
  return panelEntry() ?? "sidebar";
14711
14996
  }
14712
14997
  function JetHubPanelEntryCard({ rpcCall }) {
14713
- const [entry2, setEntry] = React10.useState(currentEntry);
14714
- const [open, setOpen] = React10.useState(false);
14715
- const [busy, setBusy] = React10.useState(false);
14716
- const [readFailed2, setReadFailed] = React10.useState(() => panelEntryReadFailed());
14717
- const [writeFailed, setWriteFailed] = React10.useState(false);
14718
- const busyRef = React10.useRef(false);
14719
- React10.useEffect(() => subscribePanelEntry(() => {
14998
+ const [entry2, setEntry] = React9.useState(currentEntry);
14999
+ const [open, setOpen] = React9.useState(false);
15000
+ const [busy, setBusy] = React9.useState(false);
15001
+ const [readFailed2, setReadFailed] = React9.useState(() => panelEntryReadFailed());
15002
+ const [writeFailed, setWriteFailed] = React9.useState(false);
15003
+ const busyRef = React9.useRef(false);
15004
+ React9.useEffect(() => subscribePanelEntry(() => {
14720
15005
  setEntry(currentEntry());
14721
15006
  setReadFailed(panelEntryReadFailed());
14722
15007
  }), []);
14723
- React10.useEffect(() => {
15008
+ React9.useEffect(() => {
14724
15009
  if (typeof rpcCall !== "function") return;
14725
15010
  void loadPanelEntry(rpcCall).then(() => {
14726
15011
  setEntry(currentEntry());
@@ -14728,7 +15013,7 @@ function JetHubPanelEntryCard({ rpcCall }) {
14728
15013
  });
14729
15014
  }, [rpcCall]);
14730
15015
  const selectedLabel = OPTIONS.find((option) => option.id === entry2)?.label ?? OPTIONS[0].label;
14731
- const choose = React10.useCallback(async (next) => {
15016
+ const choose = React9.useCallback(async (next) => {
14732
15017
  if (typeof rpcCall !== "function") return;
14733
15018
  if (busyRef.current) return;
14734
15019
  busyRef.current = true;
@@ -14745,24 +15030,24 @@ function JetHubPanelEntryCard({ rpcCall }) {
14745
15030
  setBusy(false);
14746
15031
  }
14747
15032
  }, [rpcCall]);
14748
- return React10.createElement(
15033
+ return React9.createElement(
14749
15034
  "div",
14750
15035
  { className: "dim-jh-cardStack" },
14751
- React10.createElement(
15036
+ React9.createElement(
14752
15037
  "div",
14753
15038
  { className: "dim-jh-cardRow" },
14754
- React10.createElement(
15039
+ React9.createElement(
14755
15040
  "div",
14756
15041
  { className: "dim-jh-cardRowText" },
14757
- React10.createElement("div", { className: "dim-jh-cardTitle" }, CARD_TITLE),
14758
- React10.createElement(
15042
+ React9.createElement("div", { className: "dim-jh-cardTitle" }, CARD_TITLE),
15043
+ React9.createElement(
14759
15044
  "div",
14760
15045
  { className: "dim-jh-cardDesc" },
14761
15046
  // 两种失败各有各的说法:读失败说「读到的是默认值」,写失败说「刚才那次没存上」。
14762
15047
  writeFailed ? CARD_DESC_WRITE_FAILED : readFailed2 ? CARD_DESC_READ_FAILED : CARD_DESC
14763
15048
  )
14764
15049
  ),
14765
- React10.createElement(import_dsh_client_ui_primitives.Menu, {
15050
+ React9.createElement(import_dsh_client_ui_primitives.Menu, {
14766
15051
  open,
14767
15052
  onClose: () => setOpen(false),
14768
15053
  items: OPTIONS.map((option) => ({ id: option.id, label: option.label })),
@@ -14775,7 +15060,7 @@ function JetHubPanelEntryCard({ rpcCall }) {
14775
15060
  // ⚠️ **必须开**:卡片在插件页的滚动 detail 列里,就地展开的列表会被
14776
15061
  // overflow 裁剪(两个参考实现都踩过并留了这条注释)。
14777
15062
  portal: true,
14778
- anchor: React10.createElement(
15063
+ anchor: React9.createElement(
14779
15064
  "button",
14780
15065
  {
14781
15066
  type: "button",
@@ -14786,7 +15071,7 @@ function JetHubPanelEntryCard({ rpcCall }) {
14786
15071
  onClick: () => setOpen((value) => !value)
14787
15072
  },
14788
15073
  selectedLabel,
14789
- React10.createElement(import_dsh_client_ui_primitives.IconChevronDownOutlineRegular, { className: "dim-jh-cardChevron" })
15074
+ React9.createElement(import_dsh_client_ui_primitives.IconChevronDownOutlineRegular, { className: "dim-jh-cardChevron" })
14790
15075
  )
14791
15076
  })
14792
15077
  )
@@ -14795,8 +15080,9 @@ function JetHubPanelEntryCard({ rpcCall }) {
14795
15080
 
14796
15081
  // plugin-src/client/index.js
14797
15082
  var name = "jet-hub-client";
14798
- var inject = ["slots", "connection"];
15083
+ var inject = ["slots", "connection", "modelDirectories", "sessions", "remote", "remote.session"];
14799
15084
  var JetHubPanelEntryCardGuarded = withErrorBoundary(JetHubPanelEntryCard, { label: "插件详情页卡片" });
15085
+ var UsageBadgeGuarded = withErrorBoundary(UsageBadge, { label: "用量徽标" });
14800
15086
  function apply(ctx) {
14801
15087
  ctx.effect(() => installJetHubStyles(), "jet-hub: install styles");
14802
15088
  const rpcCall = async (endpoint, payload, signal) => {
@@ -14810,7 +15096,77 @@ function apply(ctx) {
14810
15096
  key: "@xixka/dsh-hub",
14811
15097
  inject: () => ({ rpcCall })
14812
15098
  }, JetHubPanelEntryCardGuarded));
14813
- registerUsagePanelEntries(ctx, rpcCall);
15099
+ ctx.slots.inject("conversation.input.right", () => ctx.slots.register({
15100
+ name: "conversation.input.right",
15101
+ id: "jet-hub-usage",
15102
+ order: 100,
15103
+ inject: (sessionId) => ({
15104
+ // ⚠️⚠️ **必须惰性取目录,不能在 inject 里取**(真机事故 2026-10-02)。
15105
+ //
15106
+ // 原写法 `directory: ctx.modelDirectories.directoryFor(sessionId).store`
15107
+ // 有两个问题:
15108
+ // 1. `directoryFor` 是**惰性 getter** —— 写 `directoryFor(sessionId).store`
15109
+ // 里的 `.store` 才触发求值,而求值发生在**槽位 inject 期**(即会话
15110
+ // 输入区渲染的同步路径上)。桌面版此时它内部要访问未注入的
15111
+ // `remote.session`,直接抛 `cannot get property "remote.session"
15112
+ // without inject`(Web 版不走那条分支,故只在 desktop 复现)。
15113
+ // 2. 该异常发生在渲染关键路径上,**会让整个会话输入区渲染中断** ——
15114
+ // 表现为模型选择器点不动(用户报障),远不止「徽标不显示」。
15115
+ //
15116
+ // ⇒ 改为交出一个**取值函数** `resolveDirectory()`,由组件在自己的
15117
+ // effect 里调用:失败被组件自身的 try/catch 兜住,影响面收敛到
15118
+ // 「徽标不显示」,绝不影响模型选择器。
15119
+ //
15120
+ // ⚠️⚠️ **必须同时交出 `store` 与 `load`(真机事故 2026-10-02 的真正根因)
15121
+ //
15122
+ // 读 `dsh-client-ui-model-selection` 的 `ModelDirectory` 源码得到两个事实:
15123
+ // ① 它的**公开方法是 `load()` / `syncInputs()`,没有 `getSnapshot()` /
15124
+ // `subscribe()`** —— 那两个在 `this.store` 上。我第一版只交出实例,
15125
+ // 组件调 `directory.getSnapshot()` 得到 `undefined` → TypeError →
15126
+ // 被 safe() 吞掉 → `provider` 恒为空 → **徽标永不显示**。
15127
+ // ② `store` 的初值是 `{ current: null, status: 'idle' }`,**只有
15128
+ // `await load()` 之后** `syncInputs()` 才把真实 `current` 填进去。
15129
+ // 徽标自己不发模型目录请求(`usage.badge` 按 provider 查),
15130
+ // 所以必须由它调 `load()`,否则 `current` 永远是 null。
15131
+ //
15132
+ // 两者缺一不可:只给 store 不 load → current 为 null;
15133
+ // 只给实例不 load 也不 store → getSnapshot 不存在。
15134
+ resolveDirectory: () => {
15135
+ const directory = ctx.modelDirectories.directoryFor(sessionId);
15136
+ return {
15137
+ store: directory.store,
15138
+ load: () => directory.load()
15139
+ };
15140
+ },
15141
+ providerLabel,
15142
+ readBadge: (provider, options) => rpcCall("usage.badge", { provider, ...options }),
15143
+ /**
15144
+ * 聚合 provider「上次**实际**转发成功的渠道」(P3)。
15145
+ *
15146
+ * ⚠️ 宿主侧该端点是**纯内存读**(零网络零余额查询)—— 徽标在**门控阶段**
15147
+ * 就要用它把 `aggregate` 重定向成真实渠道,而门控是同步渲染路径。
15148
+ * ⚠️ 返回 `{ provider: null }` 表示无历史 ⇒ 徽标**不渲染**。
15149
+ */
15150
+ readActiveProvider: (canonicalId) => rpcCall("aggregate.activeProvider", canonicalId === void 0 ? {} : { canonicalId }),
15151
+ // ⚠️ **这里曾有一个 `readExpiryOrder` prop,已删除**(真实死代码,审计实测指出):
15152
+ // 它在 `c12b3ab` 上就已**零消费者** —— `AggregatePanel` 自己直接
15153
+ // `rpcCall('aggregate.expiryOrder', {})`(`jet-hub.js`),从不经过本 prop。
15154
+ // 本仓库把死代码视为缺陷(会让人以为「面板是通过 prop 取数的」而找错地方)。
15155
+ // ⚠️ 端点本身仍在(`aggregate.expiryOrder`)—— 删的只是这个没人用的转发 prop。
15156
+ writePreference: (preference) => rpcCall("usage.badgePreference", { preference }),
15157
+ // 自动签到开关(全局一个,不分渠道):宿主在「打开」时会立刻跑一轮。
15158
+ setAutoCheckin: (enabled) => rpcCall("usage.autoCheckin", { enabled }),
15159
+ // 关闭那行**常驻**的自动签到状态文字(只关当前这一轮,下一轮会重新出现)。
15160
+ dismissAutoCheckin: () => rpcCall("usage.autoCheckin", { dismiss: true }),
15161
+ // 一键领取:每日签到 + (buddy / workbuddy 的)成长中心任务。
15162
+ //
15163
+ // ⚠️ runTasks 缺省**必须为 false** —— 同一个方法也是「每日首次启动自动签到」
15164
+ // 的执行体(宿主 auto-checkin 的 claim 回调)。成长一轮单账号 90~270s、
15165
+ // 全串行,默认开启等于每次开机自动打几十个上游请求。
15166
+ // budgetMs 缺省由宿主取 10 分钟;传 0 或负数表示不限时。
15167
+ claimCredits: (provider, runTasks, budgetMs) => rpcCall("credits.claimAll", { provider, runTasks, budgetMs })
15168
+ })
15169
+ }, UsageBadgeGuarded));
14814
15170
  }
14815
15171
 
14816
15172
  return module.exports;