@vibedev-si/dsh-vibedev 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client/client.js CHANGED
@@ -7,6 +7,7 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
7
7
  let react_jsx_runtime = require("react/jsx-runtime");
8
8
  //#region src/client/account-store.ts
9
9
  const ACCOUNT_ROUTE = "/api/dsh-vibedev/account";
10
+ const LATENCY_ROUTE = "/api/dsh-vibedev/latency";
10
11
  const PENDING_POLL_MS = 2e3;
11
12
  const IDLE_POLL_MS = 6e4;
12
13
  /** After a failed long poll, the next one waits this long (the Host may be restarting). */
@@ -15,12 +16,6 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
15
16
  function displayName(view) {
16
17
  return view?.user?.nickname ?? view?.user?.email;
17
18
  }
18
- /** The balance as text, e.g. `¥12.50`. */
19
- function balanceText(view) {
20
- const balance = view?.balance;
21
- if (balance === void 0) return void 0;
22
- return `${balance.currency === "CNY" ? "¥" : balance.currency === "USD" ? "$" : `${balance.currency} `}${balance.amount}`;
23
- }
24
19
  /** The account store. */
25
20
  var AccountStore = class {
26
21
  options;
@@ -28,21 +23,30 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
28
23
  view: void 0,
29
24
  loadFailed: false,
30
25
  busy: void 0,
31
- actionError: void 0
26
+ actionError: void 0,
27
+ refreshing: false,
28
+ latency: { measuring: false }
32
29
  };
33
30
  listeners = /* @__PURE__ */ new Set();
34
31
  timer;
35
32
  reading;
33
+ /** The running read asks the Host to read the balance again. */
34
+ readingFresh = false;
35
+ /** A fresh read asked for while a plain one ran: it starts when that one ends. */
36
+ queuedFresh;
37
+ measuring;
36
38
  stopped = true;
37
39
  unsubscribeFocus;
38
40
  /** The open long poll, when one is. */
39
41
  watching;
40
42
  /**
41
- * @param options - fetch, timers, window opening and focus (test seams).
43
+ * @param options - fetch, timers, window opening, focus and the clock (test seams).
42
44
  */
43
45
  constructor(options = {}) {
44
46
  this.options = options;
45
47
  }
48
+ /** The store's clock (epoch ms), which the card's "N 秒前" reads as well. */
49
+ now = () => (this.options.now ?? Date.now)();
46
50
  /** Subscribe for useSyncExternalStore. */
47
51
  subscribe = (listener) => {
48
52
  this.listeners.add(listener);
@@ -143,26 +147,101 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
143
147
  })();
144
148
  }
145
149
  /**
146
- * Read the account now.
150
+ * Read the account now. One read runs at a time: a second call shares it, and a fresh read asked for while a
151
+ * plain one runs starts as soon as that one ends (so the balance is still read again).
147
152
  * @param fresh - ask the Host to read the balance again.
148
153
  */
149
154
  refresh(fresh = false) {
150
- this.reading ??= (async () => {
151
- try {
152
- const response = await this.fetch(fresh ? `${ACCOUNT_ROUTE}?fresh=1` : ACCOUNT_ROUTE);
153
- if (!response.ok) throw new Error(`HTTP ${response.status}`);
154
- this.set({
155
- view: await response.json(),
156
- loadFailed: false
157
- });
158
- } catch {
159
- this.set({ loadFailed: true });
160
- } finally {
161
- this.reading = void 0;
162
- this.schedule();
163
- }
164
- })();
165
- return this.reading;
155
+ const running = this.reading;
156
+ if (running !== void 0) {
157
+ if (!fresh || this.readingFresh) return running;
158
+ if (!this.state.refreshing) this.set({ refreshing: true });
159
+ this.queuedFresh ??= running.then(() => {
160
+ this.queuedFresh = void 0;
161
+ return this.refresh(true);
162
+ });
163
+ return this.queuedFresh;
164
+ }
165
+ this.readingFresh = fresh;
166
+ if (fresh && !this.state.refreshing) this.set({ refreshing: true });
167
+ const reading = this.read(fresh).finally(() => {
168
+ this.reading = void 0;
169
+ this.readingFresh = false;
170
+ this.schedule();
171
+ });
172
+ this.reading = reading;
173
+ return reading;
174
+ }
175
+ async read(fresh) {
176
+ try {
177
+ const response = await this.fetch(fresh ? `${ACCOUNT_ROUTE}?fresh=1` : ACCOUNT_ROUTE);
178
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
179
+ this.set({
180
+ view: await response.json(),
181
+ loadFailed: false,
182
+ ...fresh ? { refreshing: false } : {}
183
+ });
184
+ } catch {
185
+ this.set({
186
+ loadFailed: true,
187
+ ...fresh ? { refreshing: false } : {}
188
+ });
189
+ }
190
+ }
191
+ /**
192
+ * Read the balance again when the one shown was read more than {@link FRESH_READ_AFTER_MS} ago (or never), for
193
+ * the balance card and the account menu; a recent one is kept, and nothing is read while nobody is signed in.
194
+ * @returns once the read (if any) ended.
195
+ */
196
+ refreshIfStale() {
197
+ const view = this.state.view;
198
+ if (view === void 0 || view.source === "none") return Promise.resolve();
199
+ if (view.readAt !== void 0 && this.now() - view.readAt <= 1e4) return Promise.resolve();
200
+ return this.refresh(true);
201
+ }
202
+ /**
203
+ * Measure the network latency to the gateway (the Host times `GET /health`). One measurement runs at a time.
204
+ * @param fresh - measure again even when the Host measured within the last minute (重新测速).
205
+ * @returns once the measurement ended.
206
+ */
207
+ measureLatency(fresh = false) {
208
+ if (this.measuring !== void 0) return this.measuring;
209
+ const measuring = this.measure(fresh).finally(() => {
210
+ this.measuring = void 0;
211
+ });
212
+ this.measuring = measuring;
213
+ return measuring;
214
+ }
215
+ async measure(fresh) {
216
+ this.set({ latency: {
217
+ ...this.state.latency,
218
+ measuring: true
219
+ } });
220
+ try {
221
+ const response = await this.fetch(fresh ? `${LATENCY_ROUTE}?fresh=1` : LATENCY_ROUTE, { method: "POST" });
222
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
223
+ const result = await response.json();
224
+ if (typeof result.measuredAt !== "number" || !Array.isArray(result.samplesMs)) throw new Error("not a latency result");
225
+ this.set({ latency: {
226
+ measuring: false,
227
+ result
228
+ } });
229
+ } catch {
230
+ this.set({ latency: {
231
+ ...this.state.latency,
232
+ measuring: false,
233
+ requestFailed: true
234
+ } });
235
+ }
236
+ }
237
+ /**
238
+ * The balance card opened: a fresh balance when the one shown is more than 10 s old, and a latency measurement
239
+ * when the last one is more than a minute old (or there is none).
240
+ */
241
+ openedCard() {
242
+ this.refreshIfStale();
243
+ const last = this.state.latency.result;
244
+ if (this.measuring === void 0 && (last === void 0 || this.now() - last.measuredAt > 6e4)) this.measureLatency();
166
245
  }
167
246
  /** Start a sign-in: the Host opens the system browser; when it could not, the page opens the link. */
168
247
  async signIn() {
@@ -227,6 +306,133 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
227
306
  }
228
307
  };
229
308
  //#endregion
309
+ //#region src/client/balance-format.ts
310
+ /**
311
+ * The unit words of the page's language, as its dictionary names them (`numberStyle`).
312
+ * @param t - the plugin's dictionary.
313
+ * @returns `en` for the English dictionary, else `zh`.
314
+ */
315
+ function numberStyleOf(t) {
316
+ return t("numberStyle") === "en" ? "en" : "zh";
317
+ }
318
+ /**
319
+ * The amount as the console writes it: `Number(value).toFixed(2)`, read back as exact cents.
320
+ * @param value - decimal text or a number.
321
+ * @returns the cents and the sign, or undefined for anything that is not a finite number.
322
+ */
323
+ function centsOf(value) {
324
+ const number = typeof value === "number" ? value : value.trim() === "" ? NaN : Number(value);
325
+ if (!Number.isFinite(number)) return void 0;
326
+ const fixed = Math.abs(number) < 1e21 ? number.toFixed(2) : `${BigInt(number)}.00`;
327
+ const match = /^(-?)(\d+)\.(\d{2})$/.exec(fixed);
328
+ if (match === null) return void 0;
329
+ const cents = BigInt(`${match[2]}${match[3]}`);
330
+ return {
331
+ negative: match[1] === "-" && cents !== 0n,
332
+ cents
333
+ };
334
+ }
335
+ const grouped = (digits) => digits.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
336
+ /**
337
+ * What goes before the digits.
338
+ * @param currency - the currency code.
339
+ * @returns `¥` for CNY, `$` for USD, else the code and a space.
340
+ */
341
+ function currencyPrefix(currency) {
342
+ return currency === "CNY" ? "¥" : currency === "USD" ? "$" : `${currency} `;
343
+ }
344
+ function full({ negative, cents }, currency) {
345
+ const digits = cents.toString().padStart(3, "0");
346
+ return `${negative ? "-" : ""}${currencyPrefix(currency)}${grouped(digits.slice(0, -2))}.${digits.slice(-2)}`;
347
+ }
348
+ /** From which amount (in yuan) each unit is used, and how many yuan it stands for, largest first. */
349
+ const SCALES = {
350
+ zh: [{
351
+ from: 100000000n,
352
+ unit: 100000000n,
353
+ suffix: "亿"
354
+ }, {
355
+ from: 10000n,
356
+ unit: 10000n,
357
+ suffix: "万"
358
+ }],
359
+ en: [
360
+ {
361
+ from: 1000000000n,
362
+ unit: 1000000000n,
363
+ suffix: "B"
364
+ },
365
+ {
366
+ from: 1000000n,
367
+ unit: 1000000n,
368
+ suffix: "M"
369
+ },
370
+ {
371
+ from: 10000n,
372
+ unit: 1000n,
373
+ suffix: "K"
374
+ }
375
+ ]
376
+ };
377
+ /**
378
+ * The full form: two decimals as the console writes them, with thousands separators.
379
+ * @param amount - decimal text or a number; undefined when unknown.
380
+ * @param currency - the currency code.
381
+ * @returns e.g. `¥99,976,091.91`, `-¥3.50`, `$12.00`; undefined when there is no finite amount.
382
+ */
383
+ function formatMoney(amount, currency) {
384
+ const value = amount === void 0 ? void 0 : centsOf(amount);
385
+ return value === void 0 ? void 0 : full(value, currency);
386
+ }
387
+ /**
388
+ * The compact form for the sidebar row.
389
+ * @param amount - decimal text or a number; undefined when unknown.
390
+ * @param currency - the currency code.
391
+ * @param style - 万 / 亿 (zh) or K / M / B (en).
392
+ * @returns e.g. `¥9,997.6万`, `¥99.97M`, `¥8,000.50`; undefined when there is no finite amount.
393
+ */
394
+ function formatMoneyCompact(amount, currency, style) {
395
+ const value = amount === void 0 ? void 0 : centsOf(amount);
396
+ if (value === void 0) return void 0;
397
+ const scale = SCALES[style].find((item) => value.cents >= item.from * 100n);
398
+ if (scale === void 0) return full(value, currency);
399
+ const hundredths = value.cents / scale.unit;
400
+ const fraction = (hundredths % 100n).toString().padStart(2, "0").replace(/0+$/, "");
401
+ return `${value.negative ? "-" : ""}${currencyPrefix(currency)}${grouped((hundredths / 100n).toString())}${fraction === "" ? "" : `.${fraction}`}${scale.suffix}`;
402
+ }
403
+ /**
404
+ * Whether an amount reads as more than zero at two decimals (a hold of 0.001 is not worth a line).
405
+ * @param amount - decimal text, or undefined.
406
+ * @returns true for a positive amount.
407
+ */
408
+ function isPositiveAmount(amount) {
409
+ const value = amount === void 0 ? void 0 : centsOf(amount);
410
+ return value !== void 0 && !value.negative && value.cents > 0n;
411
+ }
412
+ /**
413
+ * The total of what can be spent and what is held, added the way the console adds them (as numbers).
414
+ * @param amount - the available amount.
415
+ * @param frozen - the held amount, when known.
416
+ * @returns the sum, or undefined when the available amount is not a number.
417
+ */
418
+ function totalAmount(amount, frozen) {
419
+ const available = Number(amount);
420
+ const held = frozen === void 0 ? 0 : Number(frozen);
421
+ if (amount.trim() === "" || !Number.isFinite(available)) return void 0;
422
+ return Number.isFinite(held) ? available + held : available;
423
+ }
424
+ /**
425
+ * The balance in one of the two forms.
426
+ * @param balance - the balance, when known.
427
+ * @param form - `full` for details, `compact` for the sidebar row.
428
+ * @param style - unit words for the compact form.
429
+ * @returns the text, or undefined without a usable balance.
430
+ */
431
+ function balanceText(balance, form = "full", style = "zh") {
432
+ if (balance === void 0) return void 0;
433
+ return form === "full" ? formatMoney(balance.amount, balance.currency) : formatMoneyCompact(balance.amount, balance.currency, style);
434
+ }
435
+ //#endregion
230
436
  //#region src/client/sign-in-presentation.ts
231
437
  /** @param attempt - latest safe Host snapshot. @returns a locale key for a terminal login failure. */
232
438
  function failureKey(attempt) {
@@ -372,7 +578,36 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
372
578
  sidebarMenu: "VibeDev 账号",
373
579
  sidebarIntro: "登录后可用 VibeDev 的模型和媒体生成",
374
580
  settings: "设置",
375
- accountMenu: "VibeDev 账号菜单"
581
+ accountMenu: "VibeDev 账号菜单",
582
+ numberStyle: "zh",
583
+ balanceFrozen: "冻结中:{amount},任务结束后结算",
584
+ cardTitle: "VibeDev 余额",
585
+ cardAvailable: "可用",
586
+ cardFrozen: "冻结中",
587
+ cardFrozenNote: "视频等任务提交时预扣,结束后结算",
588
+ cardTotal: "合计",
589
+ cardUpdated: "{ago}更新",
590
+ cardReading: "更新中…",
591
+ cardReadFailed: "读取失败,显示的是 {ago}的余额",
592
+ cardReadFailedNow: "读取失败,显示的是刚才读到的余额",
593
+ cardReadFailedNone: "余额读取失败",
594
+ agoNow: "刚刚",
595
+ agoSeconds: "{n} 秒前",
596
+ agoMinutes: "{n} 分钟前",
597
+ agoHours: "{n} 小时前",
598
+ cardLatency: "网络延迟",
599
+ cardLatencyNote: "到 VibeDev 网关的网络,非模型速度",
600
+ cardMeasuring: "测速中…",
601
+ cardRemeasure: "重新测速",
602
+ cardMeasureFailed: "测速没有完成",
603
+ latencyFast: "很快",
604
+ latencyNormal: "正常",
605
+ latencySlow: "较慢",
606
+ latencyVerySlow: "很慢",
607
+ latencyUnreachable: "无法连接",
608
+ latencyTimeout: "超时",
609
+ latencyNetwork: "网络错误",
610
+ latencyHttp: "HTTP {status}"
376
611
  };
377
612
  const en = {
378
613
  spending: "Spending",
@@ -448,7 +683,36 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
448
683
  sidebarMenu: "VibeDev account",
449
684
  sidebarIntro: "Sign in to use the VibeDev models and media generation",
450
685
  settings: "Settings",
451
- accountMenu: "VibeDev account menu"
686
+ accountMenu: "VibeDev account menu",
687
+ numberStyle: "en",
688
+ balanceFrozen: "On hold: {amount}, settled when the tasks end",
689
+ cardTitle: "VibeDev balance",
690
+ cardAvailable: "Available",
691
+ cardFrozen: "On hold",
692
+ cardFrozenNote: "Held when a video task starts, settled when it ends",
693
+ cardTotal: "Total",
694
+ cardUpdated: "Updated {ago}",
695
+ cardReading: "Updating…",
696
+ cardReadFailed: "Could not read it; this is the balance from {ago}",
697
+ cardReadFailedNow: "Could not read it; this is the balance read moments ago",
698
+ cardReadFailedNone: "The balance could not be read",
699
+ agoNow: "just now",
700
+ agoSeconds: "{n} s ago",
701
+ agoMinutes: "{n} min ago",
702
+ agoHours: "{n} h ago",
703
+ cardLatency: "Latency",
704
+ cardLatencyNote: "Round trip to the VibeDev gateway, not model speed",
705
+ cardMeasuring: "measuring…",
706
+ cardRemeasure: "Test again",
707
+ cardMeasureFailed: "could not be measured",
708
+ latencyFast: "Fast",
709
+ latencyNormal: "Normal",
710
+ latencySlow: "Slow",
711
+ latencyVerySlow: "Very slow",
712
+ latencyUnreachable: "Unreachable",
713
+ latencyTimeout: "timed out",
714
+ latencyNetwork: "network error",
715
+ latencyHttp: "HTTP {status}"
452
716
  };
453
717
  /**
454
718
  * Fill `{name}` placeholders.
@@ -466,7 +730,7 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
466
730
  * balance and how many VibeDev models the pickers list, top up, sign out.
467
731
  * The DeepSeek account keeps its own section; this one never touches it.
468
732
  */
469
- const styles$1 = {
733
+ const styles$2 = {
470
734
  page: {
471
735
  display: "flex",
472
736
  flexDirection: "column",
@@ -547,7 +811,7 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
547
811
  }
548
812
  function ExternalLink(props) {
549
813
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
550
- style: styles$1.link,
814
+ style: styles$2.link,
551
815
  href: props.href,
552
816
  target: "_blank",
553
817
  rel: "noreferrer",
@@ -560,13 +824,14 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
560
824
  * @returns the section content.
561
825
  */
562
826
  function AccountSection({ t, store, routeName }) {
563
- const state = (0, react.useSyncExternalStore)(store.subscribe, store.getSnapshot);
827
+ const state = (0, react.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
564
828
  (0, react.useEffect)(() => {
565
829
  store.refresh(true);
566
830
  }, [store]);
567
831
  const view = state.view;
568
832
  const who = displayName(view);
569
- const balance = balanceText(view);
833
+ const balance = balanceText(view?.balance, "full");
834
+ const held = view?.balance !== void 0 && isPositiveAmount(view.balance.frozen) ? formatMoney(view.balance.frozen, view.balance.currency) : void 0;
570
835
  let status;
571
836
  let details = null;
572
837
  let actions = null;
@@ -574,11 +839,11 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
574
839
  else if (view.pending !== void 0) {
575
840
  status = view.attempt?.phase === "committing" ? t("signInCommitting") : view.attempt?.phase === "exchanging" ? t("signInExchanging") : t("signingIn");
576
841
  details = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: view.attempt === void 0 || view.attempt.phase === "waiting-browser" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
577
- style: styles$1.line,
842
+ style: styles$2.line,
578
843
  children: t("pendingStatus")
579
844
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
580
845
  type: "button",
581
- style: styles$1.link,
846
+ style: styles$2.link,
582
847
  onClick: () => {
583
848
  store.openPending();
584
849
  },
@@ -605,7 +870,7 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
605
870
  children: state.busy === "sign-in" ? t("signingIn") : t("signIn")
606
871
  });
607
872
  details = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
608
- style: styles$1.quiet,
873
+ style: styles$2.quiet,
609
874
  children: [
610
875
  t("registerHint"),
611
876
  " ",
@@ -619,18 +884,22 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
619
884
  status = view.source === "host" ? fill(t("hostStatus"), { who: who === void 0 ? "" : `:${who}` }) : view.source === "key" ? t("keyStatus") : who === void 0 ? t("signedInPlugin") : fill(t("signedInAs"), { who });
620
885
  details = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
621
886
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
622
- style: styles$1.line,
887
+ style: styles$2.line,
623
888
  children: balance === void 0 ? t("balanceUnknown") : fill(t("balance"), { amount: balance })
624
889
  }),
890
+ held === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
891
+ style: styles$2.quiet,
892
+ children: fill(t("balanceFrozen"), { amount: held })
893
+ }),
625
894
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
626
- style: styles$1.line,
895
+ style: styles$2.line,
627
896
  children: view.models.hidden === "host-account" ? t("modelsHost") : fill(t("modelsListed"), {
628
897
  name: routeName,
629
898
  count: view.models.count
630
899
  })
631
900
  }),
632
901
  view.source === "host" ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
633
- style: styles$1.quiet,
902
+ style: styles$2.quiet,
634
903
  children: t("hostHint")
635
904
  }) : null
636
905
  ] });
@@ -674,22 +943,22 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
674
943
  const loginFailure = view?.source === "none" ? failureKey(view.attempt) : void 0;
675
944
  const supportDetails = loginFailure === void 0 ? void 0 : safeSupportDetails(view?.attempt);
676
945
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
677
- style: styles$1.page,
946
+ style: styles$2.page,
678
947
  "data-dsh-vibedev-account": true,
679
948
  children: [
680
949
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
681
- style: styles$1.title,
950
+ style: styles$2.title,
682
951
  children: t("accountTitle")
683
952
  }),
684
953
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
685
- style: styles$1.intro,
954
+ style: styles$2.intro,
686
955
  children: fill(t("accountIntro"), { name: routeName })
687
956
  }),
688
957
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
689
- style: styles$1.card,
958
+ style: styles$2.card,
690
959
  children: [
691
960
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
692
- style: styles$1.statusRow,
961
+ style: styles$2.statusRow,
693
962
  role: "status",
694
963
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.StateDot, {
695
964
  state: statusDot(state),
@@ -698,21 +967,21 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
698
967
  }),
699
968
  details,
700
969
  actions === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
701
- style: styles$1.actions,
970
+ style: styles$2.actions,
702
971
  children: actions
703
972
  }),
704
973
  error === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
705
- style: styles$1.error,
974
+ style: styles$2.error,
706
975
  role: "alert",
707
976
  children: error
708
977
  }),
709
978
  loginFailure === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
710
- style: styles$1.error,
979
+ style: styles$2.error,
711
980
  role: "alert",
712
981
  children: t(loginFailure)
713
982
  }),
714
983
  supportDetails === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
715
- style: styles$1.quiet,
984
+ style: styles$2.quiet,
716
985
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("summary", { children: t("signInDiagnostic") }), supportDetails]
717
986
  })
718
987
  ]
@@ -789,7 +1058,7 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
789
1058
  * output folder, the pinned models, and how the account works. Edits are
790
1059
  * staged and written together by the save, like every settings page there.
791
1060
  */
792
- const styles = {
1061
+ const styles$1 = {
793
1062
  section: {
794
1063
  padding: "12px 0",
795
1064
  borderTop: "0.5px solid var(--dsw-alias-border-l2)"
@@ -849,14 +1118,14 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
849
1118
  };
850
1119
  function Section(props) {
851
1120
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
852
- style: props.first === true ? styles.firstSection : styles.section,
1121
+ style: props.first === true ? styles$1.firstSection : styles$1.section,
853
1122
  children: [
854
1123
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", {
855
- style: styles.sectionTitle,
1124
+ style: styles$1.sectionTitle,
856
1125
  children: props.title
857
1126
  }),
858
1127
  props.hint === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
859
- style: styles.sectionHint,
1128
+ style: styles$1.sectionHint,
860
1129
  children: props.hint
861
1130
  }),
862
1131
  props.children
@@ -872,7 +1141,7 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
872
1141
  const state = (0, react.useSyncExternalStore)(store.subscribe, store.getSnapshot);
873
1142
  const site = (0, react.useSyncExternalStore)(account.subscribe, account.getSnapshot).view?.links.register;
874
1143
  if (state.status === "loading") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
875
- style: styles.quiet,
1144
+ style: styles$1.quiet,
876
1145
  role: "status",
877
1146
  children: t("loading")
878
1147
  });
@@ -908,14 +1177,14 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
908
1177
  first: true,
909
1178
  title: t("spending"),
910
1179
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
911
- style: styles.switchRow,
1180
+ style: styles$1.switchRow,
912
1181
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
913
- style: styles.switchText,
1182
+ style: styles$1.switchText,
914
1183
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
915
- style: styles.label,
1184
+ style: styles$1.label,
916
1185
  children: t("confirmSpending")
917
1186
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
918
- style: styles.hint,
1187
+ style: styles$1.hint,
919
1188
  children: t("confirmSpendingHint")
920
1189
  })]
921
1190
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Switch, {
@@ -951,10 +1220,10 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
951
1220
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(Section, {
952
1221
  title: t("account"),
953
1222
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
954
- style: styles.hint,
1223
+ style: styles$1.hint,
955
1224
  children: t("accountHint")
956
1225
  }), site === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
957
- style: styles.link,
1226
+ style: styles$1.link,
958
1227
  href: site,
959
1228
  target: "_blank",
960
1229
  rel: "noreferrer",
@@ -965,21 +1234,380 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
965
1234
  });
966
1235
  }
967
1236
  //#endregion
1237
+ //#region src/client/BalanceCard.tsx
1238
+ /**
1239
+ * The balance card: resting the pointer on the sidebar's VibeDev row shows
1240
+ * what can be spent, what running tasks hold (only while they hold something)
1241
+ * and the total — each written in full, as the gateway's console writes them —
1242
+ * then how fresh that is, with 刷新, and the network latency to the gateway,
1243
+ * with 重新测速.
1244
+ *
1245
+ * Opening it reads the balance again when the one shown is more than 10 s old,
1246
+ * and measures the latency when the last measurement is more than a minute old
1247
+ * (account-store.ts). A balance that could not be read again is never passed
1248
+ * off as fresh: the card says the read failed and how old the balance shown is.
1249
+ *
1250
+ * It is the content of the DSH primitives' compact HoverCard, whose surface is
1251
+ * dark in both themes, so it takes the fixed light-on-dark steps DSH's own
1252
+ * hover cards use (the static theme tokens, with their values as fallbacks).
1253
+ */
1254
+ /** DSH's hover-card text steps on its always-dark surface (white title, then two greys). */
1255
+ const TEXT = "var(--dsw-static-neutral-bluish-00, #ffffff)";
1256
+ const SECONDARY = "var(--dsw-static-neutral-bluish-300, #cfd3d6)";
1257
+ const TERTIARY = "var(--dsw-static-neutral-bluish-400, #adb2b8)";
1258
+ /** The action color DSH gives text buttons on its always-dark surfaces (the toast's action). */
1259
+ const ACTION = "var(--dsw-static-deepseek-400, #7aaaff)";
1260
+ const WARN = "var(--dsw-alias-state-warn-primary, #f59e0b)";
1261
+ const RULE = "color-mix(in srgb, var(--dsw-static-neutral-bluish-00, #ffffff) 12%, transparent)";
1262
+ /** A layout effect in the browser; where nothing is laid out (rendering to markup) a plain effect, which never runs. */
1263
+ const useBrowserLayoutEffect = typeof window === "undefined" ? react.useEffect : react.useLayoutEffect;
1264
+ const styles = {
1265
+ card: {
1266
+ display: "flex",
1267
+ flexDirection: "column",
1268
+ gap: 8,
1269
+ fontSize: 12,
1270
+ lineHeight: "16px",
1271
+ color: SECONDARY
1272
+ },
1273
+ title: {
1274
+ fontSize: 14,
1275
+ lineHeight: "20px",
1276
+ fontWeight: 500,
1277
+ color: TEXT
1278
+ },
1279
+ who: {
1280
+ marginTop: -6,
1281
+ overflow: "hidden",
1282
+ textOverflow: "ellipsis",
1283
+ whiteSpace: "nowrap"
1284
+ },
1285
+ amounts: {
1286
+ display: "flex",
1287
+ flexDirection: "column",
1288
+ gap: 4
1289
+ },
1290
+ row: {
1291
+ display: "flex",
1292
+ alignItems: "baseline",
1293
+ justifyContent: "space-between",
1294
+ gap: 12
1295
+ },
1296
+ value: {
1297
+ fontSize: 13,
1298
+ lineHeight: "18px",
1299
+ color: TEXT,
1300
+ fontVariantNumeric: "tabular-nums",
1301
+ whiteSpace: "nowrap"
1302
+ },
1303
+ note: { color: TERTIARY },
1304
+ rule: {
1305
+ height: 0,
1306
+ borderTop: `0.5px solid ${RULE}`
1307
+ },
1308
+ line: {
1309
+ display: "flex",
1310
+ flexWrap: "wrap",
1311
+ alignItems: "flex-start",
1312
+ justifyContent: "space-between",
1313
+ columnGap: 8,
1314
+ rowGap: 2
1315
+ },
1316
+ lineText: {
1317
+ display: "flex",
1318
+ alignItems: "center",
1319
+ gap: 6,
1320
+ minWidth: 0
1321
+ },
1322
+ dot: {
1323
+ display: "inline-flex",
1324
+ ["--dsw-alias-label-tertiary"]: TERTIARY
1325
+ },
1326
+ warn: { color: WARN },
1327
+ action: {
1328
+ flex: "none",
1329
+ marginLeft: "auto",
1330
+ padding: 0,
1331
+ border: "none",
1332
+ background: "none",
1333
+ font: "inherit",
1334
+ lineHeight: "inherit",
1335
+ color: ACTION,
1336
+ cursor: "pointer"
1337
+ }
1338
+ };
1339
+ /**
1340
+ * How long ago, in the dictionary's words.
1341
+ * @param t - the dictionary.
1342
+ * @param ms - the age in milliseconds.
1343
+ * @returns e.g. 刚刚, 12 秒前, 3 分钟前, 2 小时前.
1344
+ */
1345
+ function agoText(t, ms) {
1346
+ const seconds = Math.max(0, Math.floor(ms / 1e3));
1347
+ if (seconds < 5) return t("agoNow");
1348
+ if (seconds < 60) return fill(t("agoSeconds"), { n: seconds });
1349
+ const minutes = Math.floor(seconds / 60);
1350
+ if (minutes < 60) return fill(t("agoMinutes"), { n: minutes });
1351
+ return fill(t("agoHours"), { n: Math.floor(minutes / 60) });
1352
+ }
1353
+ /**
1354
+ * @param result - one measurement.
1355
+ * @returns its grade.
1356
+ */
1357
+ function latencyGrade(result) {
1358
+ const ms = result.medianMs;
1359
+ if (result.error !== void 0 || ms === void 0) return "unreachable";
1360
+ return ms < 150 ? "fast" : ms < 300 ? "normal" : ms < 800 ? "slow" : "very-slow";
1361
+ }
1362
+ const GRADE_KEYS = {
1363
+ fast: "latencyFast",
1364
+ normal: "latencyNormal",
1365
+ slow: "latencySlow",
1366
+ "very-slow": "latencyVerySlow",
1367
+ unreachable: "latencyUnreachable"
1368
+ };
1369
+ /**
1370
+ * The card's freshness line.
1371
+ * @param t - the dictionary.
1372
+ * @param state - the account state.
1373
+ * @param now - the store's clock.
1374
+ * @returns the text, whether it reports a failure, and whether a read is running.
1375
+ */
1376
+ function freshnessLine(t, state, now) {
1377
+ if (state.refreshing) return {
1378
+ text: t("cardReading"),
1379
+ failed: false,
1380
+ reading: true
1381
+ };
1382
+ const view = state.view;
1383
+ const readAt = view?.readAt;
1384
+ if (state.loadFailed || view?.readFailedAt !== void 0) {
1385
+ if (readAt === void 0 || view?.balance === void 0) return {
1386
+ text: t("cardReadFailedNone"),
1387
+ failed: true,
1388
+ reading: false
1389
+ };
1390
+ const age = now - readAt;
1391
+ return {
1392
+ text: age < 5e3 ? t("cardReadFailedNow") : fill(t("cardReadFailed"), { ago: agoText(t, age) }),
1393
+ failed: true,
1394
+ reading: false
1395
+ };
1396
+ }
1397
+ return {
1398
+ text: readAt === void 0 ? "" : fill(t("cardUpdated"), { ago: agoText(t, now - readAt) }),
1399
+ failed: false,
1400
+ reading: false
1401
+ };
1402
+ }
1403
+ /**
1404
+ * The card's latency line.
1405
+ * @param t - the dictionary.
1406
+ * @param latency - the latency state.
1407
+ * @returns the dot and the text, e.g. 网络延迟 162 ms · 正常.
1408
+ */
1409
+ function latencyLine(t, latency) {
1410
+ const label = t("cardLatency");
1411
+ if (latency.measuring) return {
1412
+ dot: "ongoing",
1413
+ text: `${label} ${t("cardMeasuring")}`
1414
+ };
1415
+ if (latency.requestFailed === true) return {
1416
+ dot: "idle",
1417
+ text: `${label} ${t("cardMeasureFailed")}`
1418
+ };
1419
+ const result = latency.result;
1420
+ if (result === void 0) return {
1421
+ dot: "idle",
1422
+ text: label
1423
+ };
1424
+ const grade = latencyGrade(result);
1425
+ if (grade === "unreachable") {
1426
+ const error = result.error;
1427
+ const reason = error?.kind === "http" ? fill(t("latencyHttp"), { status: error.status ?? "" }) : error?.kind === "timeout" ? t("latencyTimeout") : t("latencyNetwork");
1428
+ return {
1429
+ dot: "error",
1430
+ text: `${label} ${t("latencyUnreachable")} · ${reason}`
1431
+ };
1432
+ }
1433
+ return {
1434
+ dot: grade === "fast" || grade === "normal" ? "done" : "warning",
1435
+ text: `${label} ${result.medianMs} ms · ${t(GRADE_KEYS[grade])}`
1436
+ };
1437
+ }
1438
+ function Amount({ label, value }) {
1439
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1440
+ style: styles.row,
1441
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: label }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1442
+ style: styles.value,
1443
+ children: value
1444
+ })]
1445
+ });
1446
+ }
1447
+ /**
1448
+ * The card's content.
1449
+ * @param props - the dictionary, the shared account store, and who is signed in when the row itself does not say
1450
+ * (the collapsed sidebar).
1451
+ * @returns the content (the HoverCard mounts it only while the card is open).
1452
+ */
1453
+ function BalanceCard({ t, store, who }) {
1454
+ const state = (0, react.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
1455
+ (0, react.useEffect)(() => {
1456
+ store.openedCard();
1457
+ }, [store]);
1458
+ const [, setTick] = (0, react.useState)(0);
1459
+ (0, react.useEffect)(() => {
1460
+ const timer = setInterval(() => {
1461
+ setTick((tick) => tick + 1);
1462
+ }, 1e3);
1463
+ return () => {
1464
+ clearInterval(timer);
1465
+ };
1466
+ }, []);
1467
+ const body = (0, react.useRef)(null);
1468
+ const height = (0, react.useRef)(void 0);
1469
+ useBrowserLayoutEffect(() => {
1470
+ const next = body.current?.offsetHeight;
1471
+ if (height.current !== void 0 && next !== height.current) window.dispatchEvent(new Event("scroll"));
1472
+ height.current = next;
1473
+ });
1474
+ const balance = state.view?.balance;
1475
+ const available = balance === void 0 ? void 0 : formatMoney(balance.amount, balance.currency);
1476
+ const held = balance !== void 0 && isPositiveAmount(balance.frozen) ? formatMoney(balance.frozen, balance.currency) : void 0;
1477
+ const total = balance === void 0 ? void 0 : formatMoney(totalAmount(balance.amount, balance.frozen), balance.currency);
1478
+ const freshness = freshnessLine(t, state, store.now());
1479
+ const latency = latencyLine(t, state.latency);
1480
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1481
+ ref: body,
1482
+ style: styles.card,
1483
+ "data-dsh-vibedev-balance-card": true,
1484
+ children: [
1485
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1486
+ style: styles.title,
1487
+ children: t("cardTitle")
1488
+ }),
1489
+ who === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1490
+ style: styles.who,
1491
+ children: who
1492
+ }),
1493
+ available === void 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: t("balanceUnknown") }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1494
+ style: styles.amounts,
1495
+ children: [
1496
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Amount, {
1497
+ label: t("cardAvailable"),
1498
+ value: available
1499
+ }),
1500
+ held === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Amount, {
1501
+ label: t("cardFrozen"),
1502
+ value: held
1503
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1504
+ style: styles.note,
1505
+ children: t("cardFrozenNote")
1506
+ })] }),
1507
+ total === void 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Amount, {
1508
+ label: t("cardTotal"),
1509
+ value: total
1510
+ })
1511
+ ]
1512
+ }),
1513
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: styles.rule }),
1514
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1515
+ style: styles.line,
1516
+ role: "status",
1517
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1518
+ style: freshness.failed ? styles.warn : void 0,
1519
+ children: freshness.text
1520
+ }), freshness.reading ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1521
+ type: "button",
1522
+ style: styles.action,
1523
+ onClick: () => {
1524
+ store.refresh(true);
1525
+ },
1526
+ children: t("refresh")
1527
+ })]
1528
+ }),
1529
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: styles.rule }),
1530
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1531
+ style: styles.line,
1532
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1533
+ style: styles.lineText,
1534
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1535
+ style: styles.dot,
1536
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.StateDot, {
1537
+ state: latency.dot,
1538
+ size: 10
1539
+ })
1540
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: latency.text })]
1541
+ }), state.latency.measuring ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1542
+ type: "button",
1543
+ style: styles.action,
1544
+ onClick: () => {
1545
+ store.measureLatency(true);
1546
+ },
1547
+ children: t("cardRemeasure")
1548
+ })]
1549
+ }),
1550
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1551
+ style: styles.note,
1552
+ children: t("cardLatencyNote")
1553
+ })
1554
+ ]
1555
+ });
1556
+ }
1557
+ /**
1558
+ * The row takes the foot's free width, like the account launcher it stands in for: the card then opens beside the
1559
+ * sidebar, and a long name ends in an ellipsis. The grid stretches the menu's (inline) anchor wrapper to that width.
1560
+ */
1561
+ const rowArea = {
1562
+ flex: 1,
1563
+ minWidth: 0
1564
+ };
1565
+ const rowFill = {
1566
+ display: "grid",
1567
+ gridTemplateColumns: "minmax(0, 1fr)"
1568
+ };
1569
+ /**
1570
+ * A sidebar account row with the balance card beside it (after the primitives' usual half-second rest).
1571
+ * @param props - the dictionary, the shared store, whether the card may open (not while the row's menu is open,
1572
+ * which holds the pointer and the same facts; not while signed out), who is signed in when the row does not show it,
1573
+ * and the row with its menu.
1574
+ * @returns the row.
1575
+ */
1576
+ function BalanceHover({ t, store, disabled, who, children }) {
1577
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1578
+ style: rowArea,
1579
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.HoverCard, {
1580
+ disabled,
1581
+ anchor: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1582
+ style: rowFill,
1583
+ children
1584
+ }),
1585
+ content: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BalanceCard, {
1586
+ t,
1587
+ store,
1588
+ who
1589
+ })
1590
+ })
1591
+ });
1592
+ }
1593
+ //#endregion
968
1594
  //#region src/client/PrimaryLauncher.tsx
969
1595
  /**
970
1596
  * The VibeDev account as the app's main account (`settings.launcher`, the row
971
1597
  * at the very foot of the sidebar), used where the VibeDev account leads (the
972
1598
  * VibeDev app, `primary: true`). Signed in: the person's initial, name and
973
- * balance, with a menu for Settings, top-up, usage and sign-out. Signed out:
974
- * "登录 VibeDev". It opens Settings the way the launcher it replaces does.
975
- * Inside DeepSeek Harness the plugin keeps to its smaller sidebar entry
976
- * (SidebarAccount.tsx) and this is not registered.
1599
+ * balance (short: `¥9,997.6万`), with a menu for Settings, top-up, usage and
1600
+ * sign-out, and the balance card (BalanceCard.tsx) when the pointer rests on
1601
+ * it. Signed out: "登录 VibeDev". It opens Settings the way the launcher it
1602
+ * replaces does. Inside DeepSeek Harness the plugin keeps to its smaller
1603
+ * sidebar entry (SidebarAccount.tsx) and this is not registered.
977
1604
  */
978
1605
  const row = {
979
1606
  display: "flex",
980
1607
  alignItems: "center",
981
1608
  gap: 10,
982
1609
  width: "100%",
1610
+ minWidth: 0,
983
1611
  padding: "6px 10px",
984
1612
  border: "none",
985
1613
  borderRadius: 10,
@@ -1014,7 +1642,7 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1014
1642
  height: 28,
1015
1643
  borderRadius: "50%",
1016
1644
  background: "var(--dsw-alias-brand-primary, #3b82f6)",
1017
- color: "#fff",
1645
+ color: "var(--dsw-alias-label-primary-foreground, #fff)",
1018
1646
  fontSize: 13,
1019
1647
  fontWeight: 600,
1020
1648
  lineHeight: 1
@@ -1055,7 +1683,7 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1055
1683
  * @returns the row with its menu.
1056
1684
  */
1057
1685
  function PrimaryLauncher({ t, store, owner }) {
1058
- const state = (0, react.useSyncExternalStore)(store.subscribe, store.getSnapshot);
1686
+ const state = (0, react.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
1059
1687
  const [open, setOpen] = (0, react.useState)(false);
1060
1688
  const wide = owner.wide !== false;
1061
1689
  const settingsWasOpen = (0, react.useRef)(false);
@@ -1067,7 +1695,8 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1067
1695
  const signedIn = view !== void 0 && view.source !== "none";
1068
1696
  const pending = !signedIn && view?.pending !== void 0;
1069
1697
  const who = displayName(view);
1070
- const balance = balanceText(view);
1698
+ const balance = balanceText(view?.balance, "full");
1699
+ const short = balanceText(view?.balance, "compact", numberStyleOf(t));
1071
1700
  const title = signedIn ? who ?? t("sidebarSignedIn") : pending ? t("sidebarPending") : t("signIn");
1072
1701
  const settings = {
1073
1702
  id: "settings",
@@ -1155,7 +1784,7 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1155
1784
  "aria-hidden": "true",
1156
1785
  children: initialOf(who)
1157
1786
  }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconUserOutlineMedium, { size: 16 });
1158
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
1787
+ const menu = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
1159
1788
  open,
1160
1789
  side: "top",
1161
1790
  align: "start",
@@ -1165,12 +1794,13 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1165
1794
  type: "button",
1166
1795
  style: !wide ? railRow : signedIn ? signedInRow : signedOutRow,
1167
1796
  "aria-label": wide ? t("accountMenu") : title,
1168
- title: wide ? void 0 : title,
1797
+ title: wide || signedIn ? void 0 : title,
1169
1798
  "aria-haspopup": "menu",
1170
1799
  "aria-expanded": open,
1171
1800
  "data-dsh-vibedev-launcher": true,
1172
1801
  "data-signed-in": signedIn,
1173
1802
  onClick: () => {
1803
+ if (!open && signedIn) store.refreshIfStale();
1174
1804
  setOpen((value) => !value);
1175
1805
  },
1176
1806
  children: [face, wide ? signedIn ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
@@ -1180,7 +1810,7 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1180
1810
  children: who ?? t("sidebarSignedIn")
1181
1811
  }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1182
1812
  style: subText,
1183
- children: balance === void 0 ? "VibeDev" : `VibeDev · ${balance}`
1813
+ children: short === void 0 ? "VibeDev" : `VibeDev · ${short}`
1184
1814
  })]
1185
1815
  }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1186
1816
  style: ellipsis,
@@ -1204,13 +1834,21 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1204
1834
  else if (id === "register") store.openLink(view.links.register);
1205
1835
  }
1206
1836
  });
1837
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BalanceHover, {
1838
+ t,
1839
+ store,
1840
+ disabled: open || !signedIn,
1841
+ who: wide ? void 0 : title,
1842
+ children: menu
1843
+ });
1207
1844
  }
1208
1845
  //#endregion
1209
1846
  //#region src/client/SidebarAccount.tsx
1210
1847
  /**
1211
1848
  * The sidebar foot's VibeDev status (`sidebar.footer.action`): "登录 VibeDev",
1212
- * "正在登录 VibeDev…" or "VibeDev 已登录", with a menu for the account. The
1213
- * Harness's own account entry (the DeepSeek account) stays where it is; in
1849
+ * "正在登录 VibeDev…" or "VibeDev 已登录", with a menu for the account, and,
1850
+ * signed in, the balance card (BalanceCard.tsx) when the pointer rests on it.
1851
+ * The Harness's own account entry (the DeepSeek account) stays where it is; in
1214
1852
  * the VibeDev app, whose account entry already is the VibeDev account, this
1215
1853
  * shows nothing.
1216
1854
  */
@@ -1219,6 +1857,7 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1219
1857
  alignItems: "center",
1220
1858
  gap: 8,
1221
1859
  width: "100%",
1860
+ minWidth: 0,
1222
1861
  minHeight: 32,
1223
1862
  padding: "0 10px",
1224
1863
  border: "none",
@@ -1247,7 +1886,7 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1247
1886
  * @returns the entry, or nothing until the account is known and inside the VibeDev app.
1248
1887
  */
1249
1888
  function SidebarAccount({ t, store, wide }) {
1250
- const state = (0, react.useSyncExternalStore)(store.subscribe, store.getSnapshot);
1889
+ const state = (0, react.useSyncExternalStore)(store.subscribe, store.getSnapshot, store.getSnapshot);
1251
1890
  const [open, setOpen] = (0, react.useState)(false);
1252
1891
  const view = state.view;
1253
1892
  if (view === void 0 || view.source === "host") return null;
@@ -1255,7 +1894,7 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1255
1894
  const pending = !signedIn && view.pending !== void 0;
1256
1895
  const text = pending ? t("sidebarPending") : signedIn ? t("sidebarSignedIn") : t("sidebarSignedOut");
1257
1896
  const who = displayName(view);
1258
- const balance = balanceText(view);
1897
+ const balance = balanceText(view.balance, "full");
1259
1898
  const items = signedIn ? [
1260
1899
  {
1261
1900
  type: "label",
@@ -1316,7 +1955,7 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1316
1955
  label: `${t("registerHint")} ${t("registerLink")}`
1317
1956
  }
1318
1957
  ];
1319
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
1958
+ const menu = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
1320
1959
  open,
1321
1960
  side: "top",
1322
1961
  align: "start",
@@ -1326,11 +1965,12 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1326
1965
  type: "button",
1327
1966
  style: wide ? trigger : railTrigger,
1328
1967
  "aria-label": wide ? void 0 : text,
1329
- title: wide ? void 0 : text,
1968
+ title: wide || signedIn ? void 0 : text,
1330
1969
  "aria-haspopup": "menu",
1331
1970
  "aria-expanded": open,
1332
1971
  "data-dsh-vibedev-sidebar": true,
1333
1972
  onClick: () => {
1973
+ if (!open && signedIn) store.refreshIfStale();
1334
1974
  setOpen((value) => !value);
1335
1975
  },
1336
1976
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.StateDot, {
@@ -1356,6 +1996,13 @@ window.__ModuleLoader__.load({ id: "@vibedev-si/dsh-vibedev", factory: (require)
1356
1996
  else if (id === "register") store.openLink(view.links.register);
1357
1997
  }
1358
1998
  });
1999
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BalanceHover, {
2000
+ t,
2001
+ store,
2002
+ disabled: open || !signedIn,
2003
+ who: wide ? void 0 : who === void 0 ? text : fill(t("signedInAs"), { who }),
2004
+ children: menu
2005
+ });
1359
2006
  }
1360
2007
  //#endregion
1361
2008
  //#region src/client/index.ts