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

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 +1080 -681
  2. package/package.json +2 -1
@@ -1108,40 +1108,142 @@ 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**,把同排的官方 pill(tok/s / 缓存命中)挤出可视区。
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
+ * 文字与图标全部隐藏 —— 此时 composer dock 行让位给官方 pill 与输入框。 */
1175
+ /* ⚠️ flex: 0 1 auto(而非 none):胶囊自身也要能收缩。它是 flex: none 时
1176
+ 宽度只由 max-width 兜底,而 max-width 只在**内容超标**时生效 —— 容器更窄时
1177
+ 它会把同排的官方 pill 一起挤出可视区。允许收缩后,空间不足时同排一起让位,
1178
+ 且胶囊内部退化是有序的(先名字出省略号,数字最后才动)。 */
1179
+ .dim-jh-badge { position: relative; display: flex; align-items: center; flex: 0 1 auto; min-width: 0; font-size: calc(var(--dsh-content-font-size-secondary, 13px) - 1px); line-height: calc(20px + var(--dsh-content-font-delta-secondary, 0px)); }
1180
+ /* ⚠️ 上面两条是宿主 StatsPills.module.css 的 anchor 字号口径(2026-11-01 迁居
1181
+ composer dock 行后与官方 tok/s / 缓存命中 pill 同排):字号 = 内容字号 −1px、
1182
+ 行高 20px + 字号偏移。逐字照抄,别「就地取整」—— 宿主改变量时这里要跟着走。 */
1183
+ /* ⚠️ box-sizing 是**显式写出**的,不是修复:button 的 UA 默认样式表本就是
1184
+ border-box(实测 offsetWidth 与 max-width 相等)。写上它只为在元素类型被改
1185
+ (span/div 默认是 content-box)时语义不悄悄漂移 —— 那种情况下 max-width 会从
1186
+ 「占位宽度」变成「内容宽度」,胶囊会突然变宽 19px 而这行代码看着毫无变化。 */
1187
+ /* 几何口径 = 宿主 StatsPills.module.css 的 .pill 规则(2026-11-01 用户要求
1188
+ 「样式要和 Pill 状态条其他元素一样」,逐字对齐):无底无框、radius-sm、
1189
+ 内边距 1px 8px、gap 6px、tertiary 色、tabular-nums、行高继承 anchor。
1190
+ 与 pill 的差别只有两处,都是**功能性**的:cursor:pointer(本 pill 可点开浮层,
1191
+ 官方 DialogPill 也有指针);max-width 216px 收敛上限(见下一段)。 */
1192
+ .dim-jh-badgeBtn { box-sizing: border-box; display: inline-flex; align-items: center; gap: 6px; max-width: 216px; min-width: 0; padding: 1px 8px; border: none; border-radius: var(--dsw-radius-sm, 6px); background: 0 0; color: var(--dsw-alias-label-tertiary); font: inherit; line-height: inherit; cursor: pointer; white-space: nowrap; font-variant-numeric: tabular-nums; transition: color .15s ease; }
1193
+ .dim-jh-badgeBtn:hover, .dim-jh-badgeBtn[aria-expanded="true"] { color: var(--dsw-alias-label-primary); }
1194
+ /* pill 图标(叠币):与官方 pill 图标同规格(16px、currentColor 1px 描边)。
1195
+ flex: none —— 图标被压缩会先于文字变形,宁可让文字先让位。 */
1196
+ .dim-jh-badgeIcon { flex: none; }
1197
+ /* 聚合「待首次请求」占位胶囊(用户报障 2026-10-08:「也没胶囊了?」)。
1198
+ ⚠️ 刻意与 .dim-jh-badgeBtn **外观一致但不共用类名**:那个类名带 cursor:pointer
1199
+ 与 :hover 反馈,而这里没有任何可点的东西(无历史 ⇒ 没有余额可展开)。
1200
+ 给一个点了没反应的按钮比没有按钮更糟。
1201
+ ⚠️ 宽度口径与 .dim-jh-badgeBtn 同步(gap 6px / padding 1px 8px / anchor 字号):
1202
+ 两者会在同一位置交替出现(首次请求成功后换成真胶囊),尺寸不一致会看到跳动。 */
1203
+ .dim-jh-badgePending { display: inline-flex; align-items: center; gap: 6px; max-width: 216px; min-width: 0; padding: 1px 8px; border-radius: var(--dsw-radius-sm, 6px); background: 0 0; color: var(--dsw-alias-label-tertiary); line-height: inherit; white-space: nowrap; font-variant-numeric: tabular-nums; }
1204
+ .dim-jh-badgePending > span:last-child { overflow: hidden; text-overflow: ellipsis; }
1205
+ /* 三段式文本容器:渠道名 + 分隔符 + 读数。
1206
+ ⚠️ 必须是 flex 容器,两个文本子项才能各自独立收缩(这正是「数字不被截」的前提)。 */
1207
+ .dim-jh-badgeText { display: flex; align-items: center; min-width: 0; }
1208
+ /* ⚠️ 让位顺序:中段说明(999) → 渠道名(99) → 读数(none,**不参与收缩**)。
1209
+ 收缩量按 flex-shrink × flex-basis 加权分配,999 与 99 相差一个数量级,
1210
+ 故「包名先走、渠道名其次」,读数一个字都不会少。
1211
+ flex-grow 一律为 0:胶囊是内容自适应宽度,任何 grow 都只会让它在宽容器里虚胖。
1212
+ min-width:0 是省略号生效的前提(flex 子项默认 min-width:auto,会撑破 max-width)。 */
1213
+ .dim-jh-badgeName { flex: 0 99 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1214
+ /* 分隔符「•」:定宽不收缩,两侧间距由 margin 给。
1215
+ ⚠️ 这里的 3px **不能**换成前后空格:flex 容器把 span 之间只含空白的文本节点
1216
+ 渲染成**零宽**(实测 gap=0,节点还在但看不见),空格会静默消失。
1217
+ 带空格的那份写法(BADGE_SEP = ' • ')只用于 title / aria-label 那句整文。 */
1218
+ .dim-jh-badgeSep { flex: none; margin: 0 3px; }
1219
+ /* 中段说明(只有套餐模式有值,如包名 Free Plan Subscription)。
1220
+ ⚠️ 收缩权重**最大**(999):它比渠道名更该让位 —— 包名多为样板字、且长,
1221
+ 而用户认得出自己选的渠道。
1222
+ ⚠️ 它被压到 0 宽时(内容过长)该节点仍在,会留下一个「悬空的分隔符」;
1223
+ 这在胶囊这一行是可接受的(完整文案在 title 与弹窗里),故不额外做条件渲染。 */
1224
+ .dim-jh-badgeDetail { flex: 0 999 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
1225
+ /* ⚠️⚠️ 读数必须 flex: none(**完全不收缩**),不能写 flex: 0 1 auto。
1226
+ 这是第二处、也是更隐蔽的一处「数字被截」成因,**靠截图才发现**:
1227
+
1228
+ 收缩量按 flex-shrink × flex-basis 加权分配,读数那一份虽小却**不为零** ——
1229
+ 实测读数被分到 0.77px 的收缩(getBoundingClientRect 宽 78.23 / 内容宽 79)。
1230
+ 而 text-overflow: ellipsis 的触发条件是 scrollWidth > clientWidth,
1231
+ **亚像素级的收缩就足以命中** ⇒ 最后一个字被换成「…」,
1232
+ 视觉上和「整段被截」一样严重。
1233
+
1234
+ ⚠️ 更坑的是**量不出来**:clientWidth 取整,53.97 报成 54,
1235
+ 于是 scrollWidth > clientWidth 判为 false —— 我用它写的「数字是否完整」
1236
+ 断言一路全绿,而截图里明明白白写着「347.87积…」。
1237
+ 教训:判断省略号要看**截图**或用小数宽度(getBoundingClientRect),
1238
+ 不能用取整后的 clientWidth。
1239
+
1240
+ ⚠️ 类名刻意**不叫 .dim-jh-badgeValue**:那个名字已被弹窗读数占用,且那条规则
1241
+ (font-weight:600)排在样式表更后面 —— 同名会让胶囊数字被静默加粗。
1242
+
1243
+ ⇒ 读数恒定完整;全部收缩由 .dim-jh-badgeDetail(999) 与 .dim-jh-badgeName(99)
1244
+ 承担,两者最坏缩到 0 也放得下(读数最宽约 97px + 分隔符与内边距 ≈ 131px
1245
+ < 186px 上限)。 */
1246
+ .dim-jh-badgeReading { flex: none; min-width: 0; white-space: nowrap; }
1145
1247
  /* 「这个读数不完整」的标记(合计少算了账号时才出现),排在读数**之后**。
1146
1248
  ⚠️ 必须与读数同级 flex: none:它是**补语**,被省略号吃掉就等于没标 —— 而它要
1147
1249
  提醒的恰恰是「别把这个数字当真」,看不见比不标更糟。
@@ -1150,10 +1252,22 @@ var STYLES = `
1150
1252
  字号小一档并压紧行高,让它读起来像角标而不是读数的一部分。 */
1151
1253
  .dim-jh-badgeWarn { flex: none; font-size: 10px; line-height: 1; color: var(--dsw-alias-state-warn-primary); cursor: help; }
1152
1254
 
1255
+ /* ② 窄屏收敛:只留状态点,文字与图标让位给同排官方 pill 与输入框。
1256
+ * 阈值 720px 是实测桌面版在 100% 缩放下「徽标 216px + 官方 pill ≥ 240px」的临界值。
1257
+ * ⚠️⚠️ 本段的**位置**是功能性的,不要为了排版把它挪到 .dim-jh-badgeText 之前:
1258
+ * 它与 ".dim-jh-badgeText { display: flex }" 特异性相同(都是单个类),
1259
+ * 靠**源顺序**决定胜负 —— 一旦被排到前面,窄屏下 display:none 会被
1260
+ * 后面的 display:flex 覆盖,文字重新出现并挤压同排官方 pill(静默回归)。 */
1261
+ @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: 1px 6px; } }
1153
1262
  .dim-jh-badgeDot { width: 5px; height: 5px; flex: none; border-radius: 999px; background: var(--dsw-alias-state-success-primary); }
1154
1263
  .dim-jh-badgeDot[data-tone="warn"] { background: var(--dsw-alias-state-warn-primary); }
1155
1264
  .dim-jh-badgeDot[data-tone="error"] { background: var(--dsw-alias-state-error-primary); }
1156
1265
  .dim-jh-badgeDot[data-tone="muted"] { background: var(--dsw-alias-label-tertiary); }
1266
+ .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; }
1267
+ /* 窄屏时徽标只留状态点,弹窗也随之收窄(否则它会盖住模型选择器)。
1268
+ * 宽度写 min() 而非媒体查询覆盖:弹窗是 absolute,媒体查询命中时按钮虽已
1269
+ * 收窄,但弹窗仍按 280px 渲染会显得与触发点不匹配。 */
1270
+ @media (max-width: 720px) { .dim-jh-badgePop { width: 220px; max-width: min(220px, 76vw); } }
1157
1271
  .dim-jh-badgeHead { display: flex; align-items: center; gap: 5px; padding-bottom: 7px; }
1158
1272
  .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
1273
  .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 +1368,7 @@ var STYLES = `
1254
1368
  /* 「展开其余 N 个账号」/「收起」:纯文字按钮,左对齐、不占满宽。
1255
1369
  ⚠️ 刻意**不复用** .dim-jh-badgeAction:那条规则是 flex:1 的实心按钮(用于签到),
1256
1370
  放在明细列表下面会抢走视觉焦点 —— 用户要的是「明细可以收起来」,不是一个主操作。
1257
- align-self: flex-start 是因为父容器(.dim-jh-usageCard)是 flex 列(默认 stretch)。 */
1371
+ align-self: flex-start 是因为父容器 .dim-jh-badgePop 是 flex 列(默认 stretch)。 */
1258
1372
  .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
1373
  .dim-jh-badgeMore:hover { color: var(--dsw-alias-brand-primary); text-decoration: underline; }
1260
1374
 
@@ -1398,6 +1512,85 @@ var STYLES = `
1398
1512
  .dim-jh-panel { padding: 14px 12px; }
1399
1513
  }
1400
1514
 
1515
+ /* ── 窄屏:用量浮层(聊天输入区那枚徽标展开的面板)──
1516
+ POC(2026-10-17,报障「对话框的这里 ui 也需要适配」,附窄屏截图)。
1517
+ ⚠️ 2026-10-20 审计整改:本块的**根因描述与 z-index 论证都被推翻重写**,
1518
+ 下面每一段都标了「已订正」。原描述保留在末尾的「历史」段里供追溯。
1519
+
1520
+ ## 已订正 ①:真正的失效机制不是「左边缘被裁」
1521
+ 原描述说窄屏下浮层左边缘越出视口 89px。按宿主**真实** composer 布局复刻
1522
+ PRE-PR 形态实测:徽标在 .uV2eYG_trailing 里(该行有 margin-left: auto)
1523
+ ⇒ 徽标靠**右**(VW=492 时 L=334 R=468),浮层向左展开 220px 得
1524
+ popL=248 ⇒ **完全没有越界**。原描述里 badge=134~151(靠左)在宿主布局中
1525
+ 不成立。⇒ 本块的真实收益是「浮层改为视口锚定、不再跟着徽标跑,且更宽」,
1526
+ 不是「修裁切」。
1527
+
1528
+ ## 已订正 ②:真正需要 CSS 兜底的是**旧内核的 containing block 偏差**
1529
+ 宿主 composer 工具行 .uV2eYG_row 带 container-type: inline-size,而徽标
1530
+ 是它的后代。实测两引擎行为不同:
1531
+ - Chromium 154:inline-size containment 只含 inline 轴,**不**创建 fixed
1532
+ 的 containing block ⇒ fixed 仍按视口锚定(符合规范);
1533
+ - Edge 122:把它当 layout containment ⇒ fixed 改为**相对该祖先**定位
1534
+ ⇒ left/right/bottom 全变成「相对 composer 行」的坐标,浮层跟着 composer
1535
+ 跑、宽度被压缩(实测 popLeft 24→124、width 476→344)。
1536
+ ⇒ 只靠 CSS 无法在旧内核上做视口锚定,故窄屏浮层改由 usage-badge.js
1537
+ **portal 到 document.body**(body 之上无 containment 祖先,两引擎都按视口
1538
+ 锚定)。本块仍保留全部承重声明作**兜底**:内联样式一旦被改坏,这里还能挡住。
1539
+
1540
+ ## 已订正 ③:bottom 必须用宿主的 composer 高度变量,不能硬编码
1541
+ 宿主用 ResizeObserver 把真实 composer 高度写进 --dsh-composer-height
1542
+ (dsh-client-ui-conversation 的 ConversationContent),其 CSS fallback 是
1543
+ **152px**(宿主三处都写 var(--dsh-composer-height,152px))。
1544
+ 原实现硬编码 88px —— 实测 composer=152px 时浮层**压住输入区 64px**,并
1545
+ **盖住「用量」徽标按钮**(命中测试点到的不是按钮,是浮层内的 DIV)
1546
+ ⇒ 用户点不到。改用变量后 gap=0、徽标可点(两引擎、多档 composer 高度均实测)。
1547
+ ⚠️ 该变量能被浮层继承:CSS 变量沿 **DOM 祖先链**继承,与定位方式无关;
1548
+ portal 到 body 后 body 仍在 scroller 的**兄弟**位置?—— 不是,body 是共同祖先,
1549
+ 故变量照样继承得到(已实测 popover 侧 getComputedStyle 读到 152px/220px)。
1550
+
1551
+ ## 已订正 ④:z-index 的区间是 (1101, 3000),不是 (250, 1000)
1552
+ 原论证的下限 250 只考虑了**外部外壳**(dsh-mobile),漏了**宿主自己**:
1553
+ - 宿主 79 处 z-index 里有 **6 处 1100**(chat 的 bRhRbq_panel、
1554
+ conversation 的 JObwrW_panel【composer 里的 ContextMeter,与徽标同一行】、
1555
+ model-selection 的 _7KE1Ra_menu【与徽标同一行的模型选择菜单】、
1556
+ plugin-manager、schedule ×2);
1557
+ - 另有 **3 处全屏 overlay**:attachment 1000、settings-general 1000、
1558
+ settings-account 1001(还有 onboarding 900)。
1559
+ 浮层若取 300,上述任一出现就把浮层整块盖住。
1560
+ 原上限 1000 的锚点 .dim-jh-loginOverlay 是**死规则**:全仓 className 用法
1561
+ 0 命中、git 历史从未渲染过(只剩一条 CSS + 注释);且它与浮层**不在同一
1562
+ stacking context**(分属 settings 页树与 composer 树,两树中间的
1563
+ .dim-jh-page/.dim-jh-layout/.dim-jh-rail/.dim-jh-panel 全无 z-index)
1564
+ ⇒ z-index 本就不可比。
1565
+ ⇒ 改为按**真正同族**的 .dim-jh-modalOverlay(3000) 定上限,按宿主最高
1566
+ overlay(1001) 与 ContextMeter(1100) 定下限 ⇒ 取 **1200**((1101, 3000) 内)。
1567
+ 另注:dsh-mobile 的 [data-shell-overlay] 恰好是 z-index:300(带 !important),
1568
+ 原取值与它**完全相等** ⇒ 同层级时后出现的 DOM 胜出,不可预测;1200 也消除了这点。
1569
+
1570
+ ⚠️ 本注释内**不得出现反引号**:本文件整体是模板字符串,反引号会提前闭合它
1571
+ (AGENTS.md 红线;本文件的 usage-badge-client.spec.ts 有专条用例逐块扫描注释)。
1572
+
1573
+ ## 历史(已推翻,勿据此改回)
1574
+ 原描述:根因是「VW=492 badge=134~151 pop=-89~151 L_OVER=true」;取 300 的
1575
+ 理由是「下限 > 250 压过 dsh-mobile details、上限 < 1000 因为
1576
+ .dim-jh-loginOverlay 是 1000」;bottom 硬编码 88px。上述三处均已订正。 */
1577
+ @media (max-width: 720px) {
1578
+ .dim-jh-badgePop {
1579
+ position: fixed !important;
1580
+ left: 8px !important;
1581
+ right: 8px !important;
1582
+ top: auto !important;
1583
+ bottom: calc(env(safe-area-inset-bottom, 0px) + var(--dsh-composer-height, 152px)) !important;
1584
+ width: auto !important;
1585
+ max-width: none !important;
1586
+ /* ⚠️ 100dvh 而不是 100vh:移动端地址栏收放会让 100vh 与真实可视高度脱节。
1587
+ 外加 max(120px, ...) 下限 —— 原写法在 vh<=140 时算出 0 或负值,实测
1588
+ vh=120 时 max-height 被压成 0px(浮层完全不可见却仍占位)、
1589
+ vh=60 时整块飞出屏幕上方。 */
1590
+ max-height: max(120px, calc(100dvh - 160px)) !important;
1591
+ z-index: 1200 !important;
1592
+ }
1593
+ }
1401
1594
 
1402
1595
  /* ── 插件详情页(plugins.bundle.config)的自有设置卡片 ──
1403
1596
 
@@ -13307,423 +13500,108 @@ function startCarrierContribution(options = {}) {
13307
13500
  };
13308
13501
  }
13309
13502
 
13310
- // plugin-src/client/panel-entry.js
13311
- var React7 = __toESM(require("react"), 1);
13312
-
13313
- // plugin-src/client/error-boundary.js
13503
+ // plugin-src/client/usage-badge.js
13314
13504
  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
- }
13505
+ var import_react_dom = require("react-dom");
13395
13506
 
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";
13507
+ // plugin-src/client/badge-model.js
13508
+ var BADGE_PREFERENCES = Object.freeze(["auto", "subscription", "credits"]);
13509
+ var DEFAULT_BADGE_PREFERENCE = "auto";
13510
+ var AGGREGATE_PROVIDER_ID = "aggregate";
13511
+ var AUTO_PROVIDER_ID = "jet-hub-auto";
13512
+ function resolveBadgeProvider(provider, active) {
13513
+ if (typeof provider !== "string" || provider.length === 0) return null;
13514
+ if (provider !== AGGREGATE_PROVIDER_ID) return provider;
13515
+ const resolved = typeof active === "object" && active !== null ? active.provider : null;
13516
+ if (typeof resolved !== "string" || resolved.length === 0) return null;
13517
+ if (resolved === AGGREGATE_PROVIDER_ID) return null;
13518
+ return resolved;
13420
13519
  }
13421
- function panelEntryShowsSettings() {
13422
- return entry === "settings";
13520
+ var BADGE_SEP = " • ";
13521
+ var HOST_STALE_HINT = "插件宿主未加载最新版本,请重启 DSH 后重试";
13522
+ function describeBadgeError(error, fallback = "") {
13523
+ const message = typeof error?.message === "string" ? error.message : "";
13524
+ if (message.includes("unknown method")) return HOST_STALE_HINT;
13525
+ if (message.includes("unsupported provider")) return HOST_STALE_HINT;
13526
+ return message.length > 0 ? message : fallback;
13423
13527
  }
13424
- function panelEntryReadFailed() {
13425
- return readFailed;
13528
+ var BADGE_PREFERENCE_LABELS = Object.freeze({
13529
+ auto: "自动",
13530
+ subscription: "优先订阅",
13531
+ credits: "只看积分"
13532
+ });
13533
+ function normalizeBadgePreference(value) {
13534
+ return BADGE_PREFERENCES.includes(value) ? value : DEFAULT_BADGE_PREFERENCE;
13426
13535
  }
13427
- function subscribePanelEntry(listener) {
13428
- listeners.add(listener);
13429
- return () => {
13430
- listeners.delete(listener);
13431
- };
13536
+ function windowPreview(windows, limit = 2) {
13537
+ const list = Array.isArray(windows) ? windows : [];
13538
+ return quotaWindowsOf(list).slice(0, limit).map(([type, label, win]) => ({ type, label, percent: quotaPercentValue(win?.percentUsed) }));
13432
13539
  }
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);
13540
+ function creditGroupsOf(accounts) {
13541
+ const rows = Array.isArray(accounts) ? accounts : [];
13542
+ const byUnit = /* @__PURE__ */ new Map();
13543
+ let failedCount = 0;
13544
+ let okCount = 0;
13545
+ for (const row of rows) {
13546
+ const balance = row?.balance;
13547
+ if (!balance || typeof balance.total !== "number" || !Number.isFinite(balance.total)) {
13548
+ failedCount += 1;
13549
+ continue;
13550
+ }
13551
+ okCount += 1;
13552
+ const rawUnit = firstUnitOf(balance.packages) ?? "";
13553
+ const unit = rawUnit === QUOTA_UNIT ? QUOTA_UNIT : normalizeUnit(rawUnit);
13554
+ const group = byUnit.get(unit) ?? { unit, label: unitLabel(unit), total: 0, accountCount: 0 };
13555
+ group.total += balance.total;
13556
+ group.accountCount += 1;
13557
+ if (unit === QUOTA_UNIT) {
13558
+ const line = formatQuotaLine(balance.packages, unit);
13559
+ group.quotaLines = group.quotaLines ?? [];
13560
+ group.quotaRemainings = group.quotaRemainings ?? [];
13561
+ group.quotaWindows = group.quotaWindows ?? /* @__PURE__ */ new Map();
13562
+ if (line !== null) group.quotaLines.push(line);
13563
+ for (const pkg of Array.isArray(balance.packages) ? balance.packages : []) {
13564
+ if (!pkg) continue;
13565
+ const remaining = pkg.remaining;
13566
+ if (typeof remaining !== "number" || !Number.isFinite(remaining)) continue;
13567
+ group.quotaRemainings.push(remaining);
13568
+ const name2 = pkg.name || "未命名";
13569
+ const prev = group.quotaWindows.get(name2);
13570
+ if (prev === void 0 || remaining < prev) group.quotaWindows.set(name2, remaining);
13571
+ }
13442
13572
  }
13573
+ byUnit.set(unit, group);
13443
13574
  }
13575
+ const groups = [...byUnit.values()].sort((a, b) => a.unit < b.unit ? -1 : a.unit > b.unit ? 1 : 0);
13576
+ return { groups, failedCount, okCount };
13444
13577
  }
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();
13578
+ function planGroupsOf(rows) {
13579
+ const list = Array.isArray(rows) ? rows : [];
13580
+ const byKey = /* @__PURE__ */ new Map();
13581
+ for (const row of list) {
13582
+ const plan = row?.plan;
13583
+ if (!plan) continue;
13584
+ const unit = normalizeUnit(typeof plan.unit === "string" ? plan.unit : "");
13585
+ const key = `${String(plan.name)}\0${unit}`;
13586
+ const group = byKey.get(key) ?? {
13587
+ name: String(plan.name),
13588
+ unit,
13589
+ label: unitLabel(unit),
13590
+ remaining: 0,
13591
+ total: 0,
13592
+ accountCount: 0,
13593
+ deductionEndTime: void 0
13594
+ };
13595
+ group.remaining += Number(plan.remaining) || 0;
13596
+ group.total += Number(plan.total) || 0;
13597
+ group.accountCount += 1;
13598
+ const end = typeof plan.deductionEndTime === "number" && Number.isFinite(plan.deductionEndTime) ? plan.deductionEndTime : void 0;
13599
+ if (end !== void 0 && (group.deductionEndTime === void 0 || end < group.deductionEndTime)) {
13600
+ group.deductionEndTime = end;
13601
+ }
13602
+ byKey.set(key, group);
13454
13603
  }
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);
13604
+ return [...byKey.values()].sort((a, b) => b.remaining - a.remaining);
13727
13605
  }
13728
13606
  function badgeView(input) {
13729
13607
  const providerLabel2 = String(input?.providerLabel ?? "Jet Hub");
@@ -13898,40 +13776,225 @@ function formatUpdatedAt(ms) {
13898
13776
  }
13899
13777
 
13900
13778
  // plugin-src/client/usage-badge.js
13779
+ var POPOVER_ANCHOR_STYLE = Object.freeze({
13780
+ position: "absolute",
13781
+ right: 0,
13782
+ bottom: "calc(100% + 8px)",
13783
+ maxHeight: "58vh",
13784
+ overflowY: "auto",
13785
+ zIndex: 40
13786
+ });
13787
+ var NARROW_BREAKPOINT_PX = 720;
13788
+ function isNarrowViewport() {
13789
+ if (typeof window === "undefined" || typeof window.matchMedia !== "function") return false;
13790
+ return window.matchMedia(`(max-width: ${NARROW_BREAKPOINT_PX}px)`).matches;
13791
+ }
13792
+ var NARROW_POPOVER_STYLE = Object.freeze({
13793
+ position: "fixed",
13794
+ left: 8,
13795
+ right: 8,
13796
+ top: "auto",
13797
+ bottom: "calc(env(safe-area-inset-bottom, 0px) + var(--dsh-composer-height, 152px))",
13798
+ width: "auto",
13799
+ maxWidth: "none",
13800
+ maxHeight: "max(120px, calc(100dvh - 160px))",
13801
+ overflowY: "auto",
13802
+ zIndex: 1200
13803
+ });
13804
+ var COMPOSER_HEIGHT_FALLBACK_PX = 152;
13805
+ function readComposerHeightPx(anchor) {
13806
+ if (typeof window === "undefined" || typeof window.getComputedStyle !== "function") {
13807
+ return COMPOSER_HEIGHT_FALLBACK_PX;
13808
+ }
13809
+ let node = anchor;
13810
+ while (node !== null && node !== void 0) {
13811
+ const raw = window.getComputedStyle(node).getPropertyValue("--dsh-composer-height").trim();
13812
+ if (raw !== "") {
13813
+ const parsed = Number.parseFloat(raw);
13814
+ if (Number.isFinite(parsed) && parsed > 0) return parsed;
13815
+ }
13816
+ node = node.parentElement;
13817
+ }
13818
+ return COMPOSER_HEIGHT_FALLBACK_PX;
13819
+ }
13901
13820
  var BADGE_POLL_MS = 6e4;
13821
+ var ACTIVE_PROVIDER_POLL_MS = 5e3;
13902
13822
  var CLAIM_NOTICE_MS = 8e3;
13903
13823
  var CLAIM_NOTICE_WARN_MS = 2e4;
13904
13824
  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 });
13825
+ var RESOLVE_RETRY_DELAYS = [300, 700, 1500, 2e3];
13826
+ function BadgePillIcon({ className }) {
13827
+ return React6.createElement("svg", {
13828
+ width: 16,
13829
+ height: 16,
13830
+ viewBox: "0 0 16 16",
13831
+ fill: "none",
13832
+ xmlns: "http://www.w3.org/2000/svg",
13833
+ className,
13834
+ "aria-hidden": "true",
13835
+ strokeWidth: 1
13836
+ }, [
13837
+ React6.createElement("ellipse", { key: "top", cx: 8, cy: 4.4, rx: 5.2, ry: 2.5, stroke: "currentColor" }),
13838
+ React6.createElement("path", {
13839
+ key: "mid",
13840
+ d: "M2.8 4.4v3.4c0 1.38 2.33 2.5 5.2 2.5s5.2-1.12 5.2-2.5V4.4",
13841
+ stroke: "currentColor",
13842
+ strokeLinecap: "round"
13843
+ }),
13844
+ React6.createElement("path", {
13845
+ key: "bot",
13846
+ d: "M2.8 7.8v3.4c0 1.38 2.33 2.5 5.2 2.5s5.2-1.12 5.2-2.5V7.8",
13847
+ stroke: "currentColor",
13848
+ strokeLinecap: "round"
13849
+ })
13850
+ ]);
13851
+ }
13852
+ function UsageBadge(props) {
13853
+ const resolveDirectory = props.resolveDirectory;
13854
+ const [directory, setDirectory] = React6.useState(null);
13855
+ const resolvedRef = React6.useRef(false);
13856
+ const snapshotErrorRef = React6.useRef(false);
13857
+ React6.useEffect(() => {
13858
+ if (typeof resolveDirectory !== "function") return void 0;
13859
+ if (resolvedRef.current) return void 0;
13860
+ let alive = true;
13861
+ const timers = [];
13862
+ let attempt = 0;
13863
+ const tryResolve = () => {
13864
+ if (!alive || resolvedRef.current) return;
13865
+ let resolved = null;
13866
+ try {
13867
+ resolved = resolveDirectory();
13868
+ } catch {
13869
+ resolved = null;
13870
+ }
13871
+ if (!alive) return;
13872
+ if (resolved !== null && resolved !== void 0 && resolved.store !== void 0) {
13873
+ resolvedRef.current = true;
13874
+ const store = resolved.store;
13875
+ setDirectory(store);
13876
+ if (typeof resolved.load === "function") {
13877
+ Promise.resolve(resolved.load()).catch((error) => {
13878
+ console.warn("[jet-hub usage] 目录 load() 失败,徽标将不显示:", error);
13879
+ });
13880
+ }
13881
+ return;
13882
+ }
13883
+ attempt += 1;
13884
+ if (attempt >= RESOLVE_RETRY_DELAYS.length) {
13885
+ console.warn("[jet-hub usage] 目录解析最终失败,徽标不显示");
13886
+ return;
13887
+ }
13888
+ timers.push(setTimeout(tryResolve, RESOLVE_RETRY_DELAYS[attempt - 1]));
13889
+ };
13890
+ tryResolve();
13891
+ return () => {
13892
+ alive = false;
13893
+ for (const timer of timers) clearTimeout(timer);
13894
+ };
13895
+ }, [resolveDirectory]);
13896
+ const safe = (fn) => () => {
13897
+ try {
13898
+ return directory ? fn(directory) : void 0;
13899
+ } catch (error) {
13900
+ if (!snapshotErrorRef.current) {
13901
+ snapshotErrorRef.current = true;
13902
+ console.warn("[jet-hub usage] 读目录快照失败(store 上应有 getSnapshot):", error);
13903
+ }
13904
+ return void 0;
13905
+ }
13906
+ };
13907
+ const state = React6.useSyncExternalStore(
13908
+ // ⚠️ 订阅要**真的转发 onChange**(用户切模型时徽标跟着更新);
13909
+ // try/catch 只为把「订阅时才发现抛错」这一类也收进徽标内部。
13910
+ (onChange) => {
13911
+ if (!directory) return () => {
13912
+ };
13913
+ try {
13914
+ return directory.subscribe(onChange);
13915
+ } catch {
13916
+ return () => {
13917
+ };
13918
+ }
13919
+ },
13920
+ safe((d) => d.getSnapshot()),
13921
+ safe((d) => d.getSnapshot())
13922
+ );
13923
+ let provider = state?.current?.provider;
13924
+ const modelId = state?.current?.model;
13925
+ const readActiveProvider = props.readActiveProvider;
13926
+ const [activeProvider, setActiveProvider] = React6.useState(null);
13927
+ const isAggregate = provider === AGGREGATE_PROVIDER_ID;
13928
+ React6.useEffect(() => {
13929
+ if (!isAggregate || typeof readActiveProvider !== "function") return void 0;
13930
+ let alive = true;
13931
+ let timer = null;
13932
+ const refresh = () => {
13933
+ Promise.resolve().then(() => readActiveProvider(modelId)).then((value) => {
13934
+ if (!alive) return;
13935
+ setActiveProvider(value?.provider ?? null);
13936
+ }).catch(() => {
13937
+ if (alive) setActiveProvider(null);
13938
+ });
13939
+ };
13940
+ refresh();
13941
+ timer = setInterval(refresh, ACTIVE_PROVIDER_POLL_MS);
13942
+ return () => {
13943
+ alive = false;
13944
+ if (timer !== null) clearInterval(timer);
13945
+ };
13946
+ }, [isAggregate, readActiveProvider, modelId]);
13947
+ if (isAggregate) {
13948
+ provider = resolveBadgeProvider(provider, activeProvider === null ? null : { provider: activeProvider });
13949
+ }
13950
+ if (isAggregate && provider === null) {
13951
+ return React6.createElement("span", {
13952
+ className: "dim-jh-badgePending",
13953
+ role: "status",
13954
+ title: "聚合(跨渠道):尚未发出过请求,还不知道会走哪个渠道。发送一条消息后这里会显示实际使用的渠道与积分。"
13955
+ }, [
13956
+ React6.createElement("span", { key: "dot", className: "dim-jh-badgeDot", "data-tone": "muted" }),
13957
+ React6.createElement("span", { key: "text" }, "聚合 · 待首次请求")
13958
+ ]);
13959
+ }
13960
+ if (typeof provider !== "string" || provider.length === 0) return null;
13961
+ if (provider === AUTO_PROVIDER_ID) {
13962
+ return React6.createElement(UsageBadgeActive, { ...props, provider });
13910
13963
  }
13911
13964
  if (!supportsCreditBalance(provider)) return null;
13912
- return React8.createElement(UsageBadgeActive, { ...props, provider });
13965
+ return React6.createElement(UsageBadgeActive, { ...props, provider });
13913
13966
  }
13914
13967
  function UsageBadgeActive(props) {
13915
13968
  const { provider, providerLabel: providerLabel2, readBadge, writePreference, setAutoCheckin, dismissAutoCheckin, claimCredits } = props;
13916
13969
  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(() => {
13970
+ const [snapshot, setSnapshot] = React6.useState(null);
13971
+ const [failed, setFailed] = React6.useState(false);
13972
+ const [readError, setReadError] = React6.useState("");
13973
+ const [busy, setBusy] = React6.useState(false);
13974
+ const [open, setOpen] = React6.useState(false);
13975
+ const [preference, setPreference] = React6.useState(null);
13976
+ const [prefError, setPrefError] = React6.useState("");
13977
+ const [autoError, setAutoError] = React6.useState("");
13978
+ const [claiming, setClaiming] = React6.useState(null);
13979
+ const [claimProgress, setClaimProgress] = React6.useState(null);
13980
+ const [claimNotice, setClaimNotice] = React6.useState(null);
13981
+ const [creditsExpanded, setCreditsExpanded] = React6.useState(false);
13982
+ const root = React6.useRef(null);
13983
+ const popRef = React6.useRef(null);
13984
+ const read = React6.useRef(() => {
13929
13985
  });
13930
- const claimInFlightRef = React8.useRef(false);
13931
- React8.useEffect(() => {
13986
+ const claimInFlightRef = React6.useRef(false);
13987
+ React6.useEffect(() => {
13932
13988
  ensureJetHubStyles();
13933
- }, []);
13934
- React8.useEffect(() => {
13989
+ if (!open) return;
13990
+ const element = popRef.current;
13991
+ if (element === null) return;
13992
+ const position = window.getComputedStyle(element).position;
13993
+ if (position !== "absolute" && position !== "fixed") {
13994
+ console.warn(`[jet-hub] 浮层定位异常(position=${position}):会撑高输入区(检查 POPOVER_ANCHOR_STYLE / NARROW_POPOVER_STYLE 是否被改坏)`);
13995
+ }
13996
+ }, [open]);
13997
+ React6.useEffect(() => {
13935
13998
  setSnapshot(null);
13936
13999
  setFailed(false);
13937
14000
  setClaimNotice(null);
@@ -13939,7 +14002,7 @@ function UsageBadgeActive(props) {
13939
14002
  setAutoError("");
13940
14003
  setCreditsExpanded(false);
13941
14004
  }, [provider]);
13942
- React8.useEffect(() => {
14005
+ React6.useEffect(() => {
13943
14006
  let alive = true;
13944
14007
  let inFlight = false;
13945
14008
  const load = async (options = {}) => {
@@ -13984,7 +14047,25 @@ function UsageBadgeActive(props) {
13984
14047
  document.removeEventListener("visibilitychange", onVisible);
13985
14048
  };
13986
14049
  }, [provider, readBadge]);
13987
- React8.useEffect(() => {
14050
+ React6.useEffect(() => {
14051
+ if (!open) return void 0;
14052
+ const onDown = (event) => {
14053
+ if (!(event.target instanceof Node)) return;
14054
+ const insideRoot = root.current !== null && root.current.contains(event.target);
14055
+ const insidePop = popRef.current !== null && popRef.current.contains(event.target);
14056
+ if (!insideRoot && !insidePop) setOpen(false);
14057
+ };
14058
+ const onKey = (event) => {
14059
+ if (event.key === "Escape") setOpen(false);
14060
+ };
14061
+ document.addEventListener("mousedown", onDown);
14062
+ document.addEventListener("keydown", onKey);
14063
+ return () => {
14064
+ document.removeEventListener("mousedown", onDown);
14065
+ document.removeEventListener("keydown", onKey);
14066
+ };
14067
+ }, [open]);
14068
+ React6.useEffect(() => {
13988
14069
  if (claimNotice === null) return void 0;
13989
14070
  const ms = claimNotice.tone === "warn" ? CLAIM_NOTICE_WARN_MS : CLAIM_NOTICE_MS;
13990
14071
  const timer = setTimeout(() => setClaimNotice(null), ms);
@@ -14144,23 +14225,69 @@ function UsageBadgeActive(props) {
14144
14225
  const tone = failed && snapshot === null ? "error" : view.tone;
14145
14226
  const title = [view.text, view.incompleteNote, view.failureReason].filter((part) => part !== "").join("\n");
14146
14227
  const ariaLabel = `${label} 用量:${view.text}${view.incompleteNote === "" ? "" : `(${view.incompleteNote})`}`;
14147
- return React8.createElement("div", { className: "dim-jh-usageCard" }, renderCardBody());
14148
- function renderCardBody() {
14228
+ const collapsed = React6.createElement("span", { key: "text", className: "dim-jh-badgeText" }, [
14229
+ React6.createElement("span", { key: "name", className: "dim-jh-badgeName" }, view.name),
14230
+ React6.createElement("span", { key: "sep", className: "dim-jh-badgeSep" }, "•"),
14231
+ // 空串时**不渲染**该节点:留一个空 span 会白吃一个 6px 的 gap
14232
+ //(.dim-jh-badgeText 用的是 .dim-jh-badgeBtn 的 gap)。只有套餐模式有中段。
14233
+ view.detail === "" ? null : React6.createElement("span", { key: "detail", className: "dim-jh-badgeDetail" }, view.detail),
14234
+ // ⚠️ 类名是 Reading 而**不是** Value:.dim-jh-badgeValue 已被弹窗里的读数占用
14235
+ //(那条规则带 font-weight:600,且排在样式表更后面 —— 同名会让胶囊里的数字
14236
+ // 被静默加粗、并拿到 flex:none 而无法收缩)。
14237
+ React6.createElement("span", { key: "value", className: "dim-jh-badgeReading" }, view.reading),
14238
+ /**
14239
+ * 「这个数字不完整」的标记(用户 2026-10-03 要求)。
14240
+ *
14241
+ * 合计少算了几个账号时,数字本身**看不出任何异常**,故必须有个可见标记 ——
14242
+ * 但它是**补语而不是读数**,故:
14243
+ * - 单独成 span,`flex: none`(与读数同级):被省略号吃掉就等于没标;
14244
+ * - 排在读数**之后**:不干扰「先看数字」的阅读顺序;
14245
+ * - 不参与 `view.text`:那句话是 `title` / `aria-label` 用的纯读数。
14246
+ *
14247
+ * ⚠️ `aria-hidden` 是**故意**的:同一句话已经并进按钮的 `aria-label`,
14248
+ * 不隐藏会被读屏念两遍。鼠标用户的解释走 `title`。
14249
+ */
14250
+ view.incompleteNote === "" ? null : React6.createElement("span", {
14251
+ key: "incomplete",
14252
+ className: "dim-jh-badgeWarn",
14253
+ title: view.incompleteNote,
14254
+ "aria-hidden": "true"
14255
+ }, "⚠")
14256
+ ]);
14257
+ return React6.createElement("div", {
14258
+ className: "dim-jh-badge",
14259
+ ref: root,
14260
+ // 与同排官方 pill 相同的数据标记(StatsPills 的 anchor 带 data-composer-stat)
14261
+ // —— 便于在 DOM 里把这一排 pill 当一个整体查找/测试。
14262
+ "data-composer-stat": "jet-hub-usage"
14263
+ }, [
14264
+ React6.createElement("button", {
14265
+ key: "btn",
14266
+ type: "button",
14267
+ className: "dim-jh-badgeBtn",
14268
+ "aria-expanded": open,
14269
+ "aria-label": ariaLabel,
14270
+ title,
14271
+ onClick: () => setOpen((was) => !was)
14272
+ }, [
14273
+ React6.createElement("span", { key: "dot", className: "dim-jh-badgeDot", "data-tone": tone }),
14274
+ React6.createElement(BadgePillIcon, { key: "icon", className: "dim-jh-badgeIcon" }),
14275
+ collapsed
14276
+ ]),
14277
+ open ? renderPopover() : null
14278
+ ]);
14279
+ function renderPopover() {
14149
14280
  const stamp = snapshot === null ? "" : formatUpdatedAt(value?.generatedAt ?? snapshot.at);
14150
14281
  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(
14282
+ React6.createElement("div", { key: "head", className: "dim-jh-badgeHead" }, [
14283
+ React6.createElement("span", { key: "dot", className: "dim-jh-badgeDot", "data-tone": tone }),
14284
+ React6.createElement("span", { key: "title", className: "dim-jh-badgeTitle" }, label),
14285
+ React6.createElement(
14159
14286
  "span",
14160
14287
  { key: "at", className: "dim-jh-badgeAt" },
14161
14288
  snapshot === null ? "读取中…" : `${stamp === "" ? "已读取" : stamp}${value?.cached === true ? " · 缓存" : ""}`
14162
14289
  ),
14163
- React8.createElement("button", {
14290
+ React6.createElement("button", {
14164
14291
  key: "auto",
14165
14292
  type: "button",
14166
14293
  className: "dim-jh-badgeAuto",
@@ -14172,8 +14299,8 @@ function UsageBadgeActive(props) {
14172
14299
  onClick: () => {
14173
14300
  void onToggleAutoCheckin();
14174
14301
  }
14175
- }, auto?.running === true ? "…" : React8.createElement("span", { className: "dim-jh-badgeAutoDot" })),
14176
- React8.createElement("button", {
14302
+ }, auto?.running === true ? "…" : React6.createElement("span", { className: "dim-jh-badgeAutoDot" })),
14303
+ React6.createElement("button", {
14177
14304
  key: "refresh",
14178
14305
  type: "button",
14179
14306
  className: "dim-jh-badgeRefresh",
@@ -14185,55 +14312,57 @@ function UsageBadgeActive(props) {
14185
14312
  ]),
14186
14313
  // 开关写入失败时单独一行说明:它属于设置写入,混进偏好那行会让人以为
14187
14314
  // 是「显示偏好」没保存。
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
- ]),
14315
+ autoError === "" ? null : React6.createElement("div", { key: "autoErr", className: "dim-jh-badgeFail", role: "alert" }, autoError),
14211
14316
  renderPreference()
14212
14317
  ];
14213
14318
  if (snapshot === null) {
14214
- children.push(React8.createElement("div", {
14319
+ children.push(React6.createElement("div", {
14215
14320
  key: "placeholder",
14216
14321
  className: failed ? "dim-jh-badgeFail" : "dim-jh-badgeNote",
14217
14322
  role: failed ? "alert" : void 0
14218
14323
  }, failed ? readError === "" ? "用量不可用,可点右上角 ↻ 重试" : `${readError}(可点右上角 ↻ 重试)` : "正在读取用量…(首次要逐账号查询,可能要几秒)"));
14219
14324
  children.push(renderClaim());
14220
- return children;
14325
+ return wrapPopover(children);
14221
14326
  }
14222
14327
  children.push(renderSubscription());
14223
14328
  children.push(renderCredits());
14224
14329
  children.push(renderClaim());
14225
14330
  children.push(renderFoot());
14226
- return children;
14331
+ return wrapPopover(children);
14332
+ }
14333
+ function wrapPopover(children) {
14334
+ const narrow = isNarrowViewport();
14335
+ if (!narrow) {
14336
+ return React6.createElement("div", {
14337
+ className: "dim-jh-badgePop",
14338
+ style: POPOVER_ANCHOR_STYLE,
14339
+ ref: popRef
14340
+ }, children);
14341
+ }
14342
+ const composerHeight = readComposerHeightPx(root.current);
14343
+ const style = {
14344
+ ...NARROW_POPOVER_STYLE,
14345
+ // ⚠️ React 的内联样式对自定义属性(`--x`)是原样下发的,故这里可以
14346
+ // 直接用 CSS 变量名作 key。
14347
+ "--dsh-composer-height": `${composerHeight}px`
14348
+ };
14349
+ const node = React6.createElement("div", {
14350
+ className: "dim-jh-badgePop",
14351
+ style,
14352
+ ref: popRef
14353
+ }, children);
14354
+ if (typeof document === "undefined" || document.body === null || document.body === void 0) return node;
14355
+ return (0, import_react_dom.createPortal)(node, document.body, "jet-hub-badge-pop");
14227
14356
  }
14228
14357
  function renderPreference() {
14229
- return React8.createElement("div", {
14358
+ return React6.createElement("div", {
14230
14359
  key: "pref",
14231
14360
  className: "dim-jh-badgePref",
14232
14361
  // ⚠️ 三档的差别必须写清:auto 与 credits 在**有订阅时**表现不同
14233
14362
  //(auto 会回落,credits 不回落到订阅)—— 只说「优先显示哪个」会让人以为两档一样。
14234
14363
  title: "显示偏好:「自动」= 优先显示一共能用的余额(没有余额读数才显示订阅窗口/套餐);「优先订阅」= 只看窗口与套餐;「只看积分」= 强制只显示余额,也是套餐判定不准时的兜底"
14235
14364
  }, [
14236
- ...BADGE_PREFERENCES.map((item) => React8.createElement("button", {
14365
+ ...BADGE_PREFERENCES.map((item) => React6.createElement("button", {
14237
14366
  key: item,
14238
14367
  type: "button",
14239
14368
  className: "dim-jh-badgePrefBtn",
@@ -14242,7 +14371,7 @@ function UsageBadgeActive(props) {
14242
14371
  void onPickPreference(item);
14243
14372
  }
14244
14373
  }, BADGE_PREFERENCE_LABELS[item])),
14245
- prefError === "" ? null : React8.createElement("span", { key: "err", className: "dim-jh-badgeFail" }, prefError)
14374
+ prefError === "" ? null : React6.createElement("span", { key: "err", className: "dim-jh-badgeFail" }, prefError)
14246
14375
  ]);
14247
14376
  }
14248
14377
  function renderSubscription() {
@@ -14252,47 +14381,47 @@ function UsageBadgeActive(props) {
14252
14381
  const rows = Array.isArray(subscription.accounts) ? subscription.accounts : [];
14253
14382
  const account = rows.find((row) => row?.ok === true) ?? rows[0];
14254
14383
  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(
14384
+ return React6.createElement("div", { key: "sub", className: "dim-jh-badgeSection" }, [
14385
+ React6.createElement("div", { key: "title", className: "dim-jh-badgeSectionTitle" }, "订阅额度"),
14386
+ ...windows.length === 0 ? [React6.createElement(
14258
14387
  "div",
14259
14388
  { key: "empty", className: "dim-jh-badgeNote" },
14260
14389
  account?.ok === true ? "该账号没有额度窗口" : account?.error || "订阅额度不可用"
14261
- )] : [React8.createElement(
14390
+ )] : [React6.createElement(
14262
14391
  "div",
14263
14392
  { key: "wins", className: "dim-jh-badgeWins" },
14264
14393
  windows.map(([type, windowLabel, win]) => {
14265
14394
  const percent = quotaPercentValue(win?.percentUsed);
14266
14395
  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(
14396
+ return React6.createElement("div", { key: type, className: "dim-jh-badgeWin" }, [
14397
+ React6.createElement("span", { key: "l", className: "dim-jh-badgeWinLabel" }, windowLabel),
14398
+ React6.createElement(
14270
14399
  "div",
14271
14400
  { key: "bar", className: "dim-jh-quotaBar" },
14272
- React8.createElement("div", {
14401
+ React6.createElement("div", {
14273
14402
  key: "fill",
14274
14403
  className: "dim-jh-quotaBarFill",
14275
14404
  "data-tone": quotaTone(percent),
14276
14405
  style: { width: `${percent}%` }
14277
14406
  })
14278
14407
  ),
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)
14408
+ React6.createElement("span", { key: "v", className: "dim-jh-badgeValue" }, formatQuotaPercent(percent)),
14409
+ left === "" ? null : React6.createElement("span", { key: "r", className: "dim-jh-badgeWinReset", title: left }, left)
14281
14410
  ]);
14282
14411
  })
14283
14412
  )]
14284
14413
  ]);
14285
14414
  }
14286
14415
  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", {
14416
+ return React6.createElement("div", { key: "sub", className: "dim-jh-badgeSection" }, [
14417
+ React6.createElement("div", { key: "title", className: "dim-jh-badgeSectionTitle" }, "订阅套餐"),
14418
+ ...groups.length === 0 ? [React6.createElement("div", { key: "empty", className: "dim-jh-badgeNote" }, "没有可用的套餐包")] : groups.map((group) => React6.createElement("div", {
14290
14419
  key: `${group.name}\0${group.unit}`,
14291
14420
  className: "dim-jh-badgeRow"
14292
14421
  }, [
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(
14422
+ React6.createElement("div", { key: "head", className: "dim-jh-badgeRowHead" }, [
14423
+ React6.createElement("span", { key: "l", className: "dim-jh-badgeRowName", title: group.name }, group.name),
14424
+ React6.createElement(
14296
14425
  "span",
14297
14426
  { key: "v", className: "dim-jh-badgeValue" },
14298
14427
  // ⚠️ 数值与单位之间**不留空格**(`100.00M / 200.00MToken`):
@@ -14305,7 +14434,7 @@ function UsageBadgeActive(props) {
14305
14434
  `${formatUnits(group.remaining, group.unit) ?? "?"} / ${formatUnits(group.total, group.unit) ?? "?"}${group.label}`
14306
14435
  )
14307
14436
  ]),
14308
- React8.createElement(
14437
+ React6.createElement(
14309
14438
  "div",
14310
14439
  { key: "note", className: "dim-jh-badgeRowNote" },
14311
14440
  [
@@ -14325,17 +14454,17 @@ function UsageBadgeActive(props) {
14325
14454
  limit: CREDITS_COLLAPSED_LIMIT,
14326
14455
  expanded: creditsExpanded
14327
14456
  });
14328
- return React8.createElement("div", { key: "credits", className: "dim-jh-badgeSection" }, [
14457
+ return React6.createElement("div", { key: "credits", className: "dim-jh-badgeSection" }, [
14329
14458
  // 合计放进节标题右侧,省掉一整行
14330
- React8.createElement("div", { key: "title", className: "dim-jh-badgeSectionTitle" }, [
14459
+ React6.createElement("div", { key: "title", className: "dim-jh-badgeSectionTitle" }, [
14331
14460
  // ⚠️ 节标题的单位标签走**纯函数**(`creditSectionLabel`),不在这里写三元:
14332
14461
  // 原写法是 `quotaGroup === undefined ? '积分' : unitLabel(...)` —— 那个
14333
14462
  // 兜底分支把 **ZCode 的 token** 冒充成了积分(真实缺陷,2026-10-05 复审
14334
14463
  // PR !56 时发现),渲染成「积分 … 94.54MToken」自相矛盾的一屏。
14335
14464
  // 判据收进 `badge-model.js` 是为了能被单测锁死(组件里没法测 —— 本仓库
14336
14465
  // node_modules 没有 react)。
14337
- React8.createElement("span", { key: "l" }, creditSectionLabel(view.groups)),
14338
- accounts.length === 0 || sum === "" ? null : React8.createElement(
14466
+ React6.createElement("span", { key: "l" }, creditSectionLabel(view.groups)),
14467
+ accounts.length === 0 || sum === "" ? null : React6.createElement(
14339
14468
  "span",
14340
14469
  { key: "sum", className: "dim-jh-badgeSectionSum" },
14341
14470
  // ⚠️ 「合计」二字只对**可累加的余额**成立。配额窗口是并行百分比,
@@ -14344,18 +14473,18 @@ function UsageBadgeActive(props) {
14344
14473
  quotaGroup === void 0 ? `合计 ${sum}` : sum
14345
14474
  )
14346
14475
  ]),
14347
- ...accounts.length === 0 ? [React8.createElement(
14476
+ ...accounts.length === 0 ? [React6.createElement(
14348
14477
  "div",
14349
14478
  { key: "empty", className: "dim-jh-badgeNote" },
14350
14479
  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", {
14480
+ )] : shown.map((row) => React6.createElement("div", { key: row.accountId, className: "dim-jh-badgeRow" }, [
14481
+ React6.createElement("div", { key: "head", className: "dim-jh-badgeRowHead" }, [
14482
+ React6.createElement("span", {
14354
14483
  key: "l",
14355
14484
  className: "dim-jh-badgeRowName",
14356
14485
  title: row.nickname || row.accountId
14357
14486
  }, row.nickname || row.accountId),
14358
- React8.createElement("span", {
14487
+ React6.createElement("span", {
14359
14488
  key: "v",
14360
14489
  className: "dim-jh-badgeValue",
14361
14490
  "data-tone": row.balance === null ? "warn" : "ok",
@@ -14366,7 +14495,7 @@ function UsageBadgeActive(props) {
14366
14495
  // 存在时才占一行。用户 2026-10-12 明确要求三档分色。
14367
14496
  row.balance === null ? null : renderSplitNote(splitParts(row.balance, windowDays, provider))
14368
14497
  ])),
14369
- hidden === 0 ? null : React8.createElement("button", {
14498
+ hidden === 0 ? null : React6.createElement("button", {
14370
14499
  key: "more",
14371
14500
  type: "button",
14372
14501
  className: "dim-jh-badgeMore",
@@ -14377,14 +14506,14 @@ function UsageBadgeActive(props) {
14377
14506
  }
14378
14507
  function renderNote(text) {
14379
14508
  if (typeof text !== "string" || text.length === 0) return null;
14380
- return React8.createElement("div", { key: "note", className: "dim-jh-badgeRowNote" }, text);
14509
+ return React6.createElement("div", { key: "note", className: "dim-jh-badgeRowNote" }, text);
14381
14510
  }
14382
14511
  function renderSplitNote(parts) {
14383
14512
  if (!Array.isArray(parts) || parts.length === 0) return null;
14384
14513
  const children = [];
14385
14514
  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", {
14515
+ if (index > 0) children.push(React6.createElement("span", { key: `sep-${part.key}`, className: "dim-jh-badgeNoteSep" }, " · "));
14516
+ children.push(React6.createElement("span", {
14388
14517
  key: part.key,
14389
14518
  className: "dim-jh-badgeNotePart",
14390
14519
  "data-tone": part.tone,
@@ -14404,14 +14533,14 @@ function UsageBadgeActive(props) {
14404
14533
  ...part.countdown === void 0 ? {} : { title: `最早作废:${part.countdown}` }
14405
14534
  }, part.countdown === void 0 ? part.text : `${part.text}(${part.countdown})`));
14406
14535
  });
14407
- return React8.createElement("div", { key: "note", className: "dim-jh-badgeRowNote" }, children);
14536
+ return React6.createElement("div", { key: "note", className: "dim-jh-badgeRowNote" }, children);
14408
14537
  }
14409
14538
  function renderClaim() {
14410
14539
  const canClaimCurrent = supportsDailyCheckin(provider);
14411
14540
  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", {
14541
+ return React6.createElement("div", { key: "claim", className: "dim-jh-badgeSection dim-jh-badgeClaim" }, [
14542
+ React6.createElement("div", { key: "row", className: "dim-jh-badgeClaimRow" }, [
14543
+ canClaimCurrent ? React6.createElement("button", {
14415
14544
  key: "cur",
14416
14545
  type: "button",
14417
14546
  className: "dim-jh-badgeAction",
@@ -14426,7 +14555,7 @@ function UsageBadgeActive(props) {
14426
14555
  void onClaim();
14427
14556
  }
14428
14557
  }, claiming === "current" ? "领取中…" : "签到(本渠道)") : null,
14429
- React8.createElement("button", {
14558
+ React6.createElement("button", {
14430
14559
  key: "all",
14431
14560
  type: "button",
14432
14561
  className: "dim-jh-badgeAction",
@@ -14451,19 +14580,19 @@ function UsageBadgeActive(props) {
14451
14580
  * 「全部渠道签到」,以为按钮丢了。真相是能力表里 `dailyCheckin: false`
14452
14581
  * (WorkBuddy 国际版 / Cline 等后端没有签到接口)。少了这一句,用户只能靠猜。
14453
14582
  */
14454
- canClaimCurrent ? null : React8.createElement(
14583
+ canClaimCurrent ? null : React6.createElement(
14455
14584
  "div",
14456
14585
  { key: "nocount", className: "dim-jh-badgeNote" },
14457
14586
  "该渠道没有签到接口,签到请用「全部渠道签到」"
14458
14587
  ),
14459
- claimNotice === null ? null : React8.createElement("div", {
14588
+ claimNotice === null ? null : React6.createElement("div", {
14460
14589
  key: "notice",
14461
14590
  className: "dim-jh-badgeNotice",
14462
14591
  "data-tone": claimNotice.tone
14463
14592
  }, claimNotice.text),
14464
14593
  // 「需要用户操作」的提示单独列出(后端显式字段 actionRequired),
14465
14594
  // 混进计数行会被读漏,而它的价值就在于被看到。
14466
- ...(claimNotice?.notes || []).map((message, index) => React8.createElement("div", {
14595
+ ...(claimNotice?.notes || []).map((message, index) => React6.createElement("div", {
14467
14596
  key: `note-${index}`,
14468
14597
  className: "dim-jh-badgeNotice",
14469
14598
  "data-tone": "warn"
@@ -14477,12 +14606,12 @@ function UsageBadgeActive(props) {
14477
14606
  const running = auto.running === true;
14478
14607
  if (!running && channels.length === 0) return null;
14479
14608
  const stamp = running ? "" : formatUpdatedAt(auto.lastAt);
14480
- return React8.createElement("div", { key: "autostatus", className: "dim-jh-badgeAutoStatus" }, [
14609
+ return React6.createElement("div", { key: "autostatus", className: "dim-jh-badgeAutoStatus" }, [
14481
14610
  // 小关闭按钮在**文字上方**(用户:「在文字上方放个小按钮,点击直接关闭」)。
14482
- React8.createElement(
14611
+ React6.createElement(
14483
14612
  "div",
14484
14613
  { key: "closerow", className: "dim-jh-badgeAutoCloseRow" },
14485
- React8.createElement("button", {
14614
+ React6.createElement("button", {
14486
14615
  key: "close",
14487
14616
  type: "button",
14488
14617
  className: "dim-jh-badgeAutoClose",
@@ -14493,15 +14622,15 @@ function UsageBadgeActive(props) {
14493
14622
  }
14494
14623
  }, "×")
14495
14624
  ),
14496
- React8.createElement(
14625
+ React6.createElement(
14497
14626
  "div",
14498
14627
  { key: "head", className: "dim-jh-badgeAutoStatusHead" },
14499
14628
  running ? "自动签到 · 进行中…" : `自动签到${stamp === "" ? "" : ` · ${stamp}`}:${auto.lastResult}`
14500
14629
  ),
14501
- channels.length === 0 ? null : React8.createElement(
14630
+ channels.length === 0 ? null : React6.createElement(
14502
14631
  "div",
14503
14632
  { key: "channels", className: "dim-jh-badgeAutoChannels" },
14504
- channels.map((entry2, index) => React8.createElement("span", {
14633
+ channels.map((entry2, index) => React6.createElement("span", {
14505
14634
  key: `${entry2.provider}-${index}`,
14506
14635
  className: "dim-jh-badgeAutoChannel"
14507
14636
  }, `${providerLabel2(entry2.provider)} ${entry2.text}`))
@@ -14514,7 +14643,7 @@ function UsageBadgeActive(props) {
14514
14643
  if (view.failedCount > 0) parts.push(view.incompleteNote === "" ? `${view.failedCount} 个账号读取失败` : view.incompleteNote);
14515
14644
  if (failed && snapshot !== null) parts.push("本次刷新失败,显示的是上一次读数");
14516
14645
  if (parts.length === 0) return null;
14517
- return React8.createElement("div", { key: "foot", className: "dim-jh-badgeFoot" }, parts.join(" · "));
14646
+ return React6.createElement("div", { key: "foot", className: "dim-jh-badgeFoot" }, parts.join(" · "));
14518
14647
  }
14519
14648
  }
14520
14649
  function balanceLine(balance) {
@@ -14572,131 +14701,330 @@ function summarizeClaim(result) {
14572
14701
  };
14573
14702
  }
14574
14703
 
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
- ];
14704
+ // plugin-src/client/panel-entry.js
14705
+ var React8 = __toESM(require("react"), 1);
14706
+
14707
+ // plugin-src/client/error-boundary.js
14708
+ var React7 = __toESM(require("react"), 1);
14709
+ var NO_ERROR = Symbol("jet-hub:no-error");
14710
+ function describeThrown(error) {
14711
+ try {
14712
+ if (error !== null && error !== void 0 && typeof error.message === "string" && error.message.length > 0) {
14713
+ return error.message;
14714
+ }
14715
+ } catch {
14716
+ }
14717
+ try {
14718
+ return String(error);
14719
+ } catch {
14720
+ return "(抛出值无法转为文本,请查看控制台)";
14721
+ }
14584
14722
  }
14585
- function UsageSidebarIcon({ size }) {
14723
+ function withErrorBoundary(Inner, options) {
14724
+ const label = options !== null && typeof options === "object" && typeof options.label === "string" && options.label.length > 0 ? options.label : "这个面板";
14725
+ class PanelErrorBoundary extends React7.Component {
14726
+ constructor(props) {
14727
+ super(props);
14728
+ this.state = { error: NO_ERROR };
14729
+ }
14730
+ static getDerivedStateFromError(error) {
14731
+ return { error };
14732
+ }
14733
+ componentDidCatch(error, info) {
14734
+ console.error(`[jet-hub] ${label}渲染失败,已拦住(页面其余部分继续可用):`, error, info?.componentStack);
14735
+ }
14736
+ render() {
14737
+ const error = this.state.error;
14738
+ if (error === NO_ERROR) return React7.createElement(Inner, this.props);
14739
+ const message = describeThrown(error);
14740
+ return React7.createElement(
14741
+ "div",
14742
+ {
14743
+ className: "dim-jh-probeNotice",
14744
+ "data-tone": "error",
14745
+ role: "alert",
14746
+ style: { margin: "16px" }
14747
+ },
14748
+ React7.createElement("div", null, `${label}渲染失败,已拦住 —— 其余页面仍可正常使用,不必重启。`),
14749
+ React7.createElement("div", { style: { marginTop: "6px", fontFamily: "monospace", fontSize: "12px" } }, message),
14750
+ // ⚠️ **必须给出可自我恢复的出路**(2026-10-25 审计 A3-2)。
14751
+ //
14752
+ // 本 fallback 是**粘性**的:没有 `key`、也没有 `componentDidUpdate`
14753
+ // 重置 ⇒ 同一实例一旦进 error 就永远显示 fallback(数据恢复了也不回来)。
14754
+ // 审计实测:数据恢复后仍显示 fallback,只有**新建实例**才恢复。
14755
+ //
14756
+ // 而用户其实**不必重启**:宿主 `SettingsPanel` 在 `open === false` 时整棵
14757
+ // 不挂载、`main` 是 keyed 槽 ⇒「关掉设置再打开」/「切走再切回」都能恢复。
14758
+ // 但**这条路径不可发现** —— 用户看到一块报错,不知道关掉再打开就能好。
14759
+ //
14760
+ // ⇒ 两件事:①给一个**就地重试**(`setState` 回 `NO_ERROR`,子树随即重挂载,
14761
+ // 比让用户摸索「关掉再打开」快得多);②把那条路径**写出来**当兜底。
14762
+ React7.createElement(
14763
+ "div",
14764
+ { style: { marginTop: "8px" } },
14765
+ React7.createElement("button", {
14766
+ type: "button",
14767
+ className: "dim-jh-btn",
14768
+ onClick: () => {
14769
+ this.setState({ error: NO_ERROR });
14770
+ }
14771
+ }, "重试"),
14772
+ React7.createElement(
14773
+ "span",
14774
+ { style: { marginLeft: "8px", opacity: 0.75 } },
14775
+ "也可以关掉这一节再重新打开(或切到别的页面再切回来)来恢复。"
14776
+ )
14777
+ ),
14778
+ React7.createElement(
14779
+ "div",
14780
+ { style: { marginTop: "6px" } },
14781
+ "这是插件的缺陷,不是你操作错了。把上面这行报错连同「当时点了什么」一起反馈即可。"
14782
+ )
14783
+ );
14784
+ }
14785
+ }
14786
+ PanelErrorBoundary.displayName = `withErrorBoundary(${Inner.displayName || Inner.name || "Component"})`;
14787
+ return PanelErrorBoundary;
14788
+ }
14789
+
14790
+ // plugin-src/client/panel-entry-store.js
14791
+ var VALID_ENTRIES = ["sidebar", "settings"];
14792
+ var FALLBACK_ENTRY = "sidebar";
14793
+ var JET_HUB_PANEL_KEY = "jet-hub";
14794
+ var JET_HUB_SIDEBAR_ORDER = 20;
14795
+ var PANEL_ENTRY_READ_TIMEOUT_MS = 5e3;
14796
+ var PANEL_ENTRY_READ_ATTEMPTS = 3;
14797
+ var PANEL_ENTRY_RETRY_DELAY_MS = 200;
14798
+ function delay(ms) {
14799
+ return new Promise((resolve) => setTimeout(resolve, ms));
14800
+ }
14801
+ var entry = null;
14802
+ var readFailed = false;
14803
+ var inflight = null;
14804
+ var writeSeq = 0;
14805
+ var listeners = /* @__PURE__ */ new Set();
14806
+ function normalize(raw) {
14807
+ return typeof raw === "string" && VALID_ENTRIES.includes(raw) ? raw : null;
14808
+ }
14809
+ function panelEntry() {
14810
+ return entry;
14811
+ }
14812
+ function panelEntryShowsSidebar() {
14813
+ return entry !== "settings";
14814
+ }
14815
+ function panelEntryShowsSettings() {
14816
+ return entry === "settings";
14817
+ }
14818
+ function panelEntryReadFailed() {
14819
+ return readFailed;
14820
+ }
14821
+ function subscribePanelEntry(listener) {
14822
+ listeners.add(listener);
14823
+ return () => {
14824
+ listeners.delete(listener);
14825
+ };
14826
+ }
14827
+ function publish(nextEntry, nextFailed) {
14828
+ if (entry === nextEntry && readFailed === nextFailed) return;
14829
+ entry = nextEntry;
14830
+ readFailed = nextFailed;
14831
+ for (const listener of [...listeners]) {
14832
+ try {
14833
+ listener();
14834
+ } catch (caught) {
14835
+ console.error("[jet-hub] 面板入口监听器抛错", caught);
14836
+ }
14837
+ }
14838
+ }
14839
+ function readSignal() {
14840
+ if (typeof AbortSignal !== "undefined" && typeof AbortSignal.timeout === "function") {
14841
+ return AbortSignal.timeout(PANEL_ENTRY_READ_TIMEOUT_MS);
14842
+ }
14843
+ if (typeof AbortController !== "function") return void 0;
14844
+ const controller = new AbortController();
14845
+ const timer = setTimeout(() => controller.abort(), PANEL_ENTRY_READ_TIMEOUT_MS);
14846
+ if (typeof timer === "object" && timer !== null && typeof timer.unref === "function") {
14847
+ timer.unref();
14848
+ }
14849
+ controller.signal?.addEventListener?.("abort", () => clearTimeout(timer), { once: true });
14850
+ return controller.signal;
14851
+ }
14852
+ function loadPanelEntry(rpcCall) {
14853
+ if (inflight !== null) return inflight;
14854
+ const seqAtStart = writeSeq;
14855
+ const task = (async () => {
14856
+ let lastError;
14857
+ for (let attempt = 1; attempt <= PANEL_ENTRY_READ_ATTEMPTS; attempt += 1) {
14858
+ try {
14859
+ const result = await rpcCall("panelEntry.get", {}, readSignal());
14860
+ if (writeSeq !== seqAtStart) return entry ?? FALLBACK_ENTRY;
14861
+ const next = normalize(result?.entry);
14862
+ if (next !== null) {
14863
+ publish(next, false);
14864
+ } else {
14865
+ publish(entry ?? FALLBACK_ENTRY, true);
14866
+ }
14867
+ return entry ?? FALLBACK_ENTRY;
14868
+ } catch (caught) {
14869
+ lastError = caught;
14870
+ if (writeSeq !== seqAtStart) return entry ?? FALLBACK_ENTRY;
14871
+ if (attempt >= PANEL_ENTRY_READ_ATTEMPTS) break;
14872
+ await delay(PANEL_ENTRY_RETRY_DELAY_MS * attempt);
14873
+ if (writeSeq !== seqAtStart) return entry ?? FALLBACK_ENTRY;
14874
+ }
14875
+ }
14876
+ console.warn(
14877
+ `[jet-hub] 读取面板入口偏好失败,按仅侧栏处理(已重试 ${PANEL_ENTRY_READ_ATTEMPTS - 1} 次)`,
14878
+ lastError
14879
+ );
14880
+ if (writeSeq === seqAtStart) publish(entry ?? FALLBACK_ENTRY, true);
14881
+ return entry ?? FALLBACK_ENTRY;
14882
+ })();
14883
+ inflight = task;
14884
+ const clear = () => {
14885
+ if (inflight === task) inflight = null;
14886
+ };
14887
+ void task.then(clear, clear);
14888
+ return task;
14889
+ }
14890
+ async function setPanelEntry(rpcCall, next) {
14891
+ const result = await rpcCall("panelEntry.set", { entry: next });
14892
+ const confirmed = normalize(result?.entry);
14893
+ if (confirmed === null) {
14894
+ throw new Error("面板入口偏好没有返回合法 entry");
14895
+ }
14896
+ writeSeq += 1;
14897
+ publish(confirmed, false);
14898
+ return confirmed;
14899
+ }
14900
+
14901
+ // plugin-src/client/panel-entry.js
14902
+ var JetHubPageForSettings = withErrorBoundary(JetHubPage, { label: "Jet Hub 设置页" });
14903
+ var JetHubPageForMain = withErrorBoundary(JetHubPage, { label: "Jet Hub 面板" });
14904
+ function JetHubSidebarIcon({ size }) {
14586
14905
  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",
14906
+ return React8.createElement(
14907
+ "svg",
14908
+ {
14909
+ width: px,
14910
+ height: px,
14911
+ viewBox: "0 0 16 16",
14912
+ fill: "none",
14913
+ xmlns: "http://www.w3.org/2000/svg",
14914
+ "aria-hidden": "true"
14915
+ },
14916
+ React8.createElement("path", {
14917
+ d: "M8 1.7 13.5 4.85v6.3L8 14.3 2.5 11.15v-6.3z",
14606
14918
  stroke: "currentColor",
14607
14919
  strokeWidth: 1.35,
14608
- strokeLinecap: "round"
14920
+ strokeLinejoin: "round"
14609
14921
  }),
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
- ]);
14922
+ React8.createElement("circle", { cx: 8, cy: 8, r: 1.7, fill: "currentColor" })
14923
+ );
14618
14924
  }
14619
- var UsagePanelPageForMain = withErrorBoundary(UsagePanelPage, { label: "积分用量面板" });
14620
- function UsagePanelMain({ rpcCall }) {
14925
+ function JetHubMainPanel({ rpcCall }) {
14621
14926
  if (typeof rpcCall !== "function") return null;
14622
- return React9.createElement(
14927
+ return React8.createElement(
14623
14928
  "div",
14624
- { className: "dim-jh-panelHost dim-jh-usageHost", "data-plugin": "@xixka/dsh-hub" },
14625
- React9.createElement(UsagePanelPageForMain, { rpcCall })
14929
+ { className: "dim-jh-panelHost", "data-plugin": "@xixka/dsh-hub" },
14930
+ React8.createElement(JetHubPageForMain, { rpcCall })
14626
14931
  );
14627
14932
  }
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) {
14933
+ function registerJetHubPanelEntries(ctx, rpcCall) {
14685
14934
  ctx.slots.inject("main", () => ctx.slots.register({
14686
14935
  name: "main",
14687
- key: USAGE_PANEL_KEY,
14936
+ key: JET_HUB_PANEL_KEY,
14688
14937
  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));
14938
+ }, JetHubMainPanel));
14939
+ let layout;
14940
+ ctx.inject(["layout"], (scoped) => {
14941
+ layout = scoped.layout;
14942
+ return () => {
14943
+ layout = void 0;
14944
+ };
14945
+ });
14946
+ const deselectIfActive = () => {
14947
+ try {
14948
+ if (layout?.panelInfo?.getSnapshot?.()?.activePanelId !== JET_HUB_PANEL_KEY) return;
14949
+ layout.selectPanel(null);
14950
+ } catch (caught) {
14951
+ console.warn("[jet-hub] 撤销侧栏入口时取消选中失败", caught);
14952
+ }
14953
+ };
14954
+ ctx.slots.inject("sidebar.panellist", () => {
14955
+ let stopRow;
14956
+ const sync = (visible) => {
14957
+ if (visible && stopRow === void 0) {
14958
+ stopRow = ctx.slots.register({
14959
+ name: "sidebar.panellist",
14960
+ id: JET_HUB_PANEL_KEY,
14961
+ order: JET_HUB_SIDEBAR_ORDER,
14962
+ label: () => "Jet Hub"
14963
+ }, JetHubSidebarIcon);
14964
+ return;
14965
+ }
14966
+ if (!visible && stopRow !== void 0) {
14967
+ const stop = stopRow;
14968
+ stopRow = void 0;
14969
+ stop();
14970
+ deselectIfActive();
14971
+ }
14972
+ };
14973
+ const unsubscribe = subscribePanelEntry(() => sync(panelEntryShowsSidebar()));
14974
+ sync(panelEntryShowsSidebar());
14975
+ let disposed = false;
14976
+ void loadPanelEntry(rpcCall).then(() => {
14977
+ if (!disposed) sync(panelEntryShowsSidebar());
14978
+ });
14979
+ return () => {
14980
+ disposed = true;
14981
+ unsubscribe();
14982
+ if (stopRow !== void 0) {
14983
+ const stop = stopRow;
14984
+ stopRow = void 0;
14985
+ stop();
14986
+ }
14987
+ };
14988
+ });
14989
+ ctx.slots.inject("settings.section", () => {
14990
+ let stopSection;
14991
+ const sync = (visible) => {
14992
+ if (visible && stopSection === void 0) {
14993
+ stopSection = ctx.slots.register({
14994
+ name: "settings.section",
14995
+ id: JET_HUB_PANEL_KEY,
14996
+ order: 50,
14997
+ label: () => "Jet Hub",
14998
+ inject: () => ({ rpcCall })
14999
+ }, JetHubPageForSettings);
15000
+ return;
15001
+ }
15002
+ if (!visible && stopSection !== void 0) {
15003
+ const stop = stopSection;
15004
+ stopSection = void 0;
15005
+ stop();
15006
+ }
15007
+ };
15008
+ const unsubscribe = subscribePanelEntry(() => sync(panelEntryShowsSettings()));
15009
+ sync(panelEntryShowsSettings());
15010
+ let disposed = false;
15011
+ void loadPanelEntry(rpcCall).then(() => {
15012
+ if (!disposed) sync(panelEntryShowsSettings());
15013
+ });
15014
+ return () => {
15015
+ disposed = true;
15016
+ unsubscribe();
15017
+ if (stopSection !== void 0) {
15018
+ const stop = stopSection;
15019
+ stopSection = void 0;
15020
+ stop();
15021
+ }
15022
+ };
15023
+ });
14696
15024
  }
14697
15025
 
14698
15026
  // plugin-src/client/settings-card.js
14699
- var React10 = __toESM(require("react"), 1);
15027
+ var React9 = __toESM(require("react"), 1);
14700
15028
  var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
14701
15029
  var OPTIONS = [
14702
15030
  { id: "sidebar", label: "仅侧栏" },
@@ -14710,17 +15038,17 @@ function currentEntry() {
14710
15038
  return panelEntry() ?? "sidebar";
14711
15039
  }
14712
15040
  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(() => {
15041
+ const [entry2, setEntry] = React9.useState(currentEntry);
15042
+ const [open, setOpen] = React9.useState(false);
15043
+ const [busy, setBusy] = React9.useState(false);
15044
+ const [readFailed2, setReadFailed] = React9.useState(() => panelEntryReadFailed());
15045
+ const [writeFailed, setWriteFailed] = React9.useState(false);
15046
+ const busyRef = React9.useRef(false);
15047
+ React9.useEffect(() => subscribePanelEntry(() => {
14720
15048
  setEntry(currentEntry());
14721
15049
  setReadFailed(panelEntryReadFailed());
14722
15050
  }), []);
14723
- React10.useEffect(() => {
15051
+ React9.useEffect(() => {
14724
15052
  if (typeof rpcCall !== "function") return;
14725
15053
  void loadPanelEntry(rpcCall).then(() => {
14726
15054
  setEntry(currentEntry());
@@ -14728,7 +15056,7 @@ function JetHubPanelEntryCard({ rpcCall }) {
14728
15056
  });
14729
15057
  }, [rpcCall]);
14730
15058
  const selectedLabel = OPTIONS.find((option) => option.id === entry2)?.label ?? OPTIONS[0].label;
14731
- const choose = React10.useCallback(async (next) => {
15059
+ const choose = React9.useCallback(async (next) => {
14732
15060
  if (typeof rpcCall !== "function") return;
14733
15061
  if (busyRef.current) return;
14734
15062
  busyRef.current = true;
@@ -14745,24 +15073,24 @@ function JetHubPanelEntryCard({ rpcCall }) {
14745
15073
  setBusy(false);
14746
15074
  }
14747
15075
  }, [rpcCall]);
14748
- return React10.createElement(
15076
+ return React9.createElement(
14749
15077
  "div",
14750
15078
  { className: "dim-jh-cardStack" },
14751
- React10.createElement(
15079
+ React9.createElement(
14752
15080
  "div",
14753
15081
  { className: "dim-jh-cardRow" },
14754
- React10.createElement(
15082
+ React9.createElement(
14755
15083
  "div",
14756
15084
  { className: "dim-jh-cardRowText" },
14757
- React10.createElement("div", { className: "dim-jh-cardTitle" }, CARD_TITLE),
14758
- React10.createElement(
15085
+ React9.createElement("div", { className: "dim-jh-cardTitle" }, CARD_TITLE),
15086
+ React9.createElement(
14759
15087
  "div",
14760
15088
  { className: "dim-jh-cardDesc" },
14761
15089
  // 两种失败各有各的说法:读失败说「读到的是默认值」,写失败说「刚才那次没存上」。
14762
15090
  writeFailed ? CARD_DESC_WRITE_FAILED : readFailed2 ? CARD_DESC_READ_FAILED : CARD_DESC
14763
15091
  )
14764
15092
  ),
14765
- React10.createElement(import_dsh_client_ui_primitives.Menu, {
15093
+ React9.createElement(import_dsh_client_ui_primitives.Menu, {
14766
15094
  open,
14767
15095
  onClose: () => setOpen(false),
14768
15096
  items: OPTIONS.map((option) => ({ id: option.id, label: option.label })),
@@ -14775,7 +15103,7 @@ function JetHubPanelEntryCard({ rpcCall }) {
14775
15103
  // ⚠️ **必须开**:卡片在插件页的滚动 detail 列里,就地展开的列表会被
14776
15104
  // overflow 裁剪(两个参考实现都踩过并留了这条注释)。
14777
15105
  portal: true,
14778
- anchor: React10.createElement(
15106
+ anchor: React9.createElement(
14779
15107
  "button",
14780
15108
  {
14781
15109
  type: "button",
@@ -14786,7 +15114,7 @@ function JetHubPanelEntryCard({ rpcCall }) {
14786
15114
  onClick: () => setOpen((value) => !value)
14787
15115
  },
14788
15116
  selectedLabel,
14789
- React10.createElement(import_dsh_client_ui_primitives.IconChevronDownOutlineRegular, { className: "dim-jh-cardChevron" })
15117
+ React9.createElement(import_dsh_client_ui_primitives.IconChevronDownOutlineRegular, { className: "dim-jh-cardChevron" })
14790
15118
  )
14791
15119
  })
14792
15120
  )
@@ -14795,8 +15123,9 @@ function JetHubPanelEntryCard({ rpcCall }) {
14795
15123
 
14796
15124
  // plugin-src/client/index.js
14797
15125
  var name = "jet-hub-client";
14798
- var inject = ["slots", "connection"];
15126
+ var inject = ["slots", "connection", "modelDirectories", "sessions", "remote", "remote.session"];
14799
15127
  var JetHubPanelEntryCardGuarded = withErrorBoundary(JetHubPanelEntryCard, { label: "插件详情页卡片" });
15128
+ var UsageBadgeGuarded = withErrorBoundary(UsageBadge, { label: "用量徽标" });
14800
15129
  function apply(ctx) {
14801
15130
  ctx.effect(() => installJetHubStyles(), "jet-hub: install styles");
14802
15131
  const rpcCall = async (endpoint, payload, signal) => {
@@ -14810,7 +15139,77 @@ function apply(ctx) {
14810
15139
  key: "@xixka/dsh-hub",
14811
15140
  inject: () => ({ rpcCall })
14812
15141
  }, JetHubPanelEntryCardGuarded));
14813
- registerUsagePanelEntries(ctx, rpcCall);
15142
+ ctx.slots.inject("conversation.composer.dock", () => ctx.slots.register({
15143
+ name: "conversation.composer.dock",
15144
+ id: "jet-hub-usage",
15145
+ order: -10,
15146
+ inject: (sessionId) => ({
15147
+ // ⚠️⚠️ **必须惰性取目录,不能在 inject 里取**(真机事故 2026-10-02)。
15148
+ //
15149
+ // 原写法 `directory: ctx.modelDirectories.directoryFor(sessionId).store`
15150
+ // 有两个问题:
15151
+ // 1. `directoryFor` 是**惰性 getter** —— 写 `directoryFor(sessionId).store`
15152
+ // 里的 `.store` 才触发求值,而求值发生在**槽位 inject 期**(即会话
15153
+ // 输入区渲染的同步路径上)。桌面版此时它内部要访问未注入的
15154
+ // `remote.session`,直接抛 `cannot get property "remote.session"
15155
+ // without inject`(Web 版不走那条分支,故只在 desktop 复现)。
15156
+ // 2. 该异常发生在渲染关键路径上,**会让整个会话输入区渲染中断** ——
15157
+ // 表现为模型选择器点不动(用户报障),远不止「徽标不显示」。
15158
+ //
15159
+ // ⇒ 改为交出一个**取值函数** `resolveDirectory()`,由组件在自己的
15160
+ // effect 里调用:失败被组件自身的 try/catch 兜住,影响面收敛到
15161
+ // 「徽标不显示」,绝不影响模型选择器。
15162
+ //
15163
+ // ⚠️⚠️ **必须同时交出 `store` 与 `load`(真机事故 2026-10-02 的真正根因)
15164
+ //
15165
+ // 读 `dsh-client-ui-model-selection` 的 `ModelDirectory` 源码得到两个事实:
15166
+ // ① 它的**公开方法是 `load()` / `syncInputs()`,没有 `getSnapshot()` /
15167
+ // `subscribe()`** —— 那两个在 `this.store` 上。我第一版只交出实例,
15168
+ // 组件调 `directory.getSnapshot()` 得到 `undefined` → TypeError →
15169
+ // 被 safe() 吞掉 → `provider` 恒为空 → **徽标永不显示**。
15170
+ // ② `store` 的初值是 `{ current: null, status: 'idle' }`,**只有
15171
+ // `await load()` 之后** `syncInputs()` 才把真实 `current` 填进去。
15172
+ // 徽标自己不发模型目录请求(`usage.badge` 按 provider 查),
15173
+ // 所以必须由它调 `load()`,否则 `current` 永远是 null。
15174
+ //
15175
+ // 两者缺一不可:只给 store 不 load → current 为 null;
15176
+ // 只给实例不 load 也不 store → getSnapshot 不存在。
15177
+ resolveDirectory: () => {
15178
+ const directory = ctx.modelDirectories.directoryFor(sessionId);
15179
+ return {
15180
+ store: directory.store,
15181
+ load: () => directory.load()
15182
+ };
15183
+ },
15184
+ providerLabel,
15185
+ readBadge: (provider, options) => rpcCall("usage.badge", { provider, ...options }),
15186
+ /**
15187
+ * 聚合 provider「上次**实际**转发成功的渠道」(P3)。
15188
+ *
15189
+ * ⚠️ 宿主侧该端点是**纯内存读**(零网络零余额查询)—— 徽标在**门控阶段**
15190
+ * 就要用它把 `aggregate` 重定向成真实渠道,而门控是同步渲染路径。
15191
+ * ⚠️ 返回 `{ provider: null }` 表示无历史 ⇒ 徽标**不渲染**。
15192
+ */
15193
+ readActiveProvider: (canonicalId) => rpcCall("aggregate.activeProvider", canonicalId === void 0 ? {} : { canonicalId }),
15194
+ // ⚠️ **这里曾有一个 `readExpiryOrder` prop,已删除**(真实死代码,审计实测指出):
15195
+ // 它在 `c12b3ab` 上就已**零消费者** —— `AggregatePanel` 自己直接
15196
+ // `rpcCall('aggregate.expiryOrder', {})`(`jet-hub.js`),从不经过本 prop。
15197
+ // 本仓库把死代码视为缺陷(会让人以为「面板是通过 prop 取数的」而找错地方)。
15198
+ // ⚠️ 端点本身仍在(`aggregate.expiryOrder`)—— 删的只是这个没人用的转发 prop。
15199
+ writePreference: (preference) => rpcCall("usage.badgePreference", { preference }),
15200
+ // 自动签到开关(全局一个,不分渠道):宿主在「打开」时会立刻跑一轮。
15201
+ setAutoCheckin: (enabled) => rpcCall("usage.autoCheckin", { enabled }),
15202
+ // 关闭那行**常驻**的自动签到状态文字(只关当前这一轮,下一轮会重新出现)。
15203
+ dismissAutoCheckin: () => rpcCall("usage.autoCheckin", { dismiss: true }),
15204
+ // 一键领取:每日签到 + (buddy / workbuddy 的)成长中心任务。
15205
+ //
15206
+ // ⚠️ runTasks 缺省**必须为 false** —— 同一个方法也是「每日首次启动自动签到」
15207
+ // 的执行体(宿主 auto-checkin 的 claim 回调)。成长一轮单账号 90~270s、
15208
+ // 全串行,默认开启等于每次开机自动打几十个上游请求。
15209
+ // budgetMs 缺省由宿主取 10 分钟;传 0 或负数表示不限时。
15210
+ claimCredits: (provider, runTasks, budgetMs) => rpcCall("credits.claimAll", { provider, runTasks, budgetMs })
15211
+ })
15212
+ }, UsageBadgeGuarded));
14814
15213
  }
14815
15214
 
14816
15215
  return module.exports;