@alexpeng/dsh-custom-plugin 0.6.0 → 0.7.1

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/lib/client.js CHANGED
@@ -50,9 +50,6 @@ window.__ModuleLoader__.load({
50
50
  glass: true,
51
51
  glassMode: "frost",
52
52
  globalGlass: true,
53
- timeline: true,
54
- timelineLeft: false,
55
- starsOnly: false,
56
53
  quote: true,
57
54
  antiScroll: false,
58
55
  mermaid: true,
@@ -151,14 +148,16 @@ window.__ModuleLoader__.load({
151
148
  /** Official source used for the built-in estimate and shown in the panel. */
152
149
  const DEEPSEEK_PRICING_SOURCE_URL = "https://api-docs.deepseek.com/zh-cn/quick_start/pricing/";
153
150
  /** Date on which the built-in rule was checked against the official page. */
154
- const DEEPSEEK_PRICING_CHECKED_ON = "2026-08-26";
151
+ const DEEPSEEK_PRICING_CHECKED_ON = "2026-09-30";
155
152
  const FLASH_PRICE = {
156
- input: 3,
157
- cacheHit: .1,
158
- output: 9
153
+ input: 2,
154
+ cacheHit: .04,
155
+ output: 8
159
156
  };
160
- /** Current official peak prices, in CNY per 1M tokens. */
157
+ /** Current official peak prices, in CNY per 1M tokens. Off-peak is exactly
158
+ * half of peak per the official page (weekday 9-12 / 14-18 Beijing time). */
161
159
  const PEAK_PRICES = {
160
+ "deepseek-flash": FLASH_PRICE,
162
161
  "deepseek-v4-flash": FLASH_PRICE,
163
162
  "deepseek-v4-flash-vision-exp": FLASH_PRICE,
164
163
  "deepseek-v4-pro": {
@@ -195,6 +194,217 @@ window.__ModuleLoader__.load({
195
194
  totalCostCny: (peakCost + offPeakCost / 2) / 1e6
196
195
  };
197
196
  }
197
+ /** Estimate one row's total CNY cost. */
198
+ function estimateUsageCostCny(row, model) {
199
+ return usageCostBreakdown(row, model).totalCostCny;
200
+ }
201
+ //#endregion
202
+ //#region src/client/palette.ts
203
+ /**
204
+ * Background palette and the dark-mode derivation shared by the appearance
205
+ * panel and the body/token painting.
206
+ *
207
+ * The 20 families are tuned as light pastels. Dark mode reuses the same hue
208
+ * family instead of disabling them: {@link toDarkRamp} keeps hue and
209
+ * saturation and drops lightness onto a dark-ramp target, so 雾蓝 reads as a
210
+ * dark blue-gray, 裸桃 as a warm dark gray, and so on — the canvas stays
211
+ * readable while the palette's character survives.
212
+ * @module @alexpeng/dsh-custom-plugin/client/palette
213
+ */
214
+ /** Palette of 20 muted low-saturation backgrounds (with matching tab colors).
215
+ * 天青灰 leads the list: it is the install default and renders first among
216
+ * the palette swatches, right after 无颜色. */
217
+ const PALETTE = [
218
+ [
219
+ "天青灰",
220
+ "#E9EBEE",
221
+ "#D6DADF"
222
+ ],
223
+ [
224
+ "暖象牙",
225
+ "#F5F0E8",
226
+ "#E8E0D4"
227
+ ],
228
+ [
229
+ "雾灰绿",
230
+ "#E9EDE6",
231
+ "#D7DED3"
232
+ ],
233
+ [
234
+ "烟熏玫瑰",
235
+ "#F2EAEC",
236
+ "#E5D6DA"
237
+ ],
238
+ [
239
+ "雾蓝",
240
+ "#E8EDF2",
241
+ "#D4DDE6"
242
+ ],
243
+ [
244
+ "薰衣草灰",
245
+ "#EFEDF4",
246
+ "#E0DCEB"
247
+ ],
248
+ [
249
+ "燕麦米",
250
+ "#F3EEE6",
251
+ "#E5DED3"
252
+ ],
253
+ [
254
+ "薄荷雾",
255
+ "#EAF0ED",
256
+ "#D7E3DC"
257
+ ],
258
+ [
259
+ "裸桃",
260
+ "#F5EDE8",
261
+ "#E8DCD4"
262
+ ],
263
+ [
264
+ "石板蓝",
265
+ "#E6EDF1",
266
+ "#D2DBE3"
267
+ ],
268
+ [
269
+ "紫藤灰",
270
+ "#EEEBF2",
271
+ "#E1DAE8"
272
+ ],
273
+ [
274
+ "奶油黄",
275
+ "#F4F0E6",
276
+ "#E6E1D5"
277
+ ],
278
+ [
279
+ "鼠尾草",
280
+ "#EAEDE5",
281
+ "#D7DED1"
282
+ ],
283
+ [
284
+ "腮红粉",
285
+ "#F3EAEC",
286
+ "#E6D6DA"
287
+ ],
288
+ [
289
+ "香草白",
290
+ "#F3F0E6",
291
+ "#E5E0D4"
292
+ ],
293
+ [
294
+ "青灰",
295
+ "#E7F0F0",
296
+ "#D3E1E1"
297
+ ],
298
+ [
299
+ "杏仁白",
300
+ "#F0ECE8",
301
+ "#E2DAD3"
302
+ ],
303
+ [
304
+ "尤加利",
305
+ "#EAF0ED",
306
+ "#D7E3DB"
307
+ ],
308
+ [
309
+ "珍珠灰",
310
+ "#EDEDEE",
311
+ "#DCDCDD"
312
+ ],
313
+ [
314
+ "淡金",
315
+ "#F4F1E4",
316
+ "#E6E1D0"
317
+ ]
318
+ ];
319
+ /** Parse a #rrggbb (or bare rrggbb) hex color; malformed input yields the
320
+ * palette's neutral gray rather than throwing. */
321
+ function hexToRgb(hex) {
322
+ const match = /^#?([0-9a-f]{6})$/i.exec(String(hex ?? "").trim());
323
+ if (match === null) return [
324
+ 235,
325
+ 238,
326
+ 242
327
+ ];
328
+ const value = parseInt(match[1], 16);
329
+ return [
330
+ value >> 16 & 255,
331
+ value >> 8 & 255,
332
+ value & 255
333
+ ];
334
+ }
335
+ function rgbToHsl(rgb) {
336
+ const [r0, g0, b0] = rgb.map((v) => v / 255);
337
+ const max = Math.max(r0, g0, b0);
338
+ const min = Math.min(r0, g0, b0);
339
+ const l = (max + min) / 2;
340
+ if (max === min) return [
341
+ 0,
342
+ 0,
343
+ l
344
+ ];
345
+ const d = max - min;
346
+ const s = l > .5 ? d / (2 - max - min) : d / (max + min);
347
+ let h;
348
+ if (max === r0) h = ((g0 - b0) / d + (g0 < b0 ? 6 : 0)) / 6;
349
+ else if (max === g0) h = ((b0 - r0) / d + 2) / 6;
350
+ else h = ((r0 - g0) / d + 4) / 6;
351
+ return [
352
+ h,
353
+ s,
354
+ l
355
+ ];
356
+ }
357
+ function hslToRgb(h, s, l) {
358
+ if (s === 0) {
359
+ const v = Math.round(l * 255);
360
+ return [
361
+ v,
362
+ v,
363
+ v
364
+ ];
365
+ }
366
+ const q = l < .5 ? l * (1 + s) : l + s - l * s;
367
+ const p = 2 * l - q;
368
+ const channel = (t0) => {
369
+ let t = t0;
370
+ if (t < 0) t += 1;
371
+ if (t > 1) t -= 1;
372
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
373
+ if (t < 1 / 2) return q;
374
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
375
+ return p;
376
+ };
377
+ return [
378
+ Math.round(channel(h + 1 / 3) * 255),
379
+ Math.round(channel(h) * 255),
380
+ Math.round(channel(h - 1 / 3) * 255)
381
+ ];
382
+ }
383
+ /**
384
+ * Map a palette color onto the dark ramp: hue is kept, saturation is
385
+ * compressed by {@link DARK_SATURATION_SCALE}, and lightness is clamped to
386
+ * `lightness`. The compression is not optional polish: HSL saturation at dark
387
+ * lightness reads far stronger for warm hues (gold / rose / peach) than for
388
+ * blue-grays on a dark canvas, so the raw values made most families glare.
389
+ * Invalid input degrades to a neutral gray at the same lightness.
390
+ */
391
+ function toDarkRamp(hex, lightness) {
392
+ const l = Math.max(0, Math.min(1, lightness));
393
+ const [h, s] = rgbToHsl(hexToRgb(hex));
394
+ const [r, g, b] = hslToRgb(h, Math.max(0, Math.min(1, s * DARK_SATURATION_SCALE)), l);
395
+ return "#" + [
396
+ r,
397
+ g,
398
+ b
399
+ ].map((v) => v.toString(16).padStart(2, "0")).join("");
400
+ }
401
+ /** Body-canvas lightness for the dark variant of a palette family. */
402
+ const DARK_CANVAS_LIGHTNESS = .12;
403
+ /** How much of a family's HSL saturation survives on the dark ramp. 0.55
404
+ * keeps the families clearly distinguishable while pulling the warm hues
405
+ * (gold / rose / peach) down from "eye-catching" to "ambient" on the dark
406
+ * canvas; 0.4 turned them into mud, 0.7 still glared. */
407
+ const DARK_SATURATION_SCALE = .55;
198
408
  //#endregion
199
409
  //#region src/client/api.ts
200
410
  /**
@@ -316,6 +526,13 @@ window.__ModuleLoader__.load({
316
526
  }
317
527
  //#endregion
318
528
  //#region src/productivity.ts
529
+ function budgetState(summary, budgetCny, warningPercent = 80) {
530
+ if (!Number.isFinite(budgetCny) || budgetCny <= 0) return "disabled";
531
+ if (!summary.exact) return "unknown";
532
+ const ratio = summary.costCny / budgetCny * 100;
533
+ if (ratio >= 100) return "over";
534
+ return ratio >= Math.max(1, Math.min(100, warningPercent)) ? "warning" : "ok";
535
+ }
319
536
  function summarizeUsage(usage, days) {
320
537
  const out = {
321
538
  tokens: 0,
@@ -607,7 +824,7 @@ window.__ModuleLoader__.load({
607
824
  const STATIC_CSS = `/* dsh-custom-plugin static styles. Every rule is global by design: the UI
608
825
  * mounts into product slots and overlays, so class names are prefixed vx-
609
826
  * and must not be scoped by CSS Modules. Dynamic rules (body background,
610
- * aurora gradient, global-glass blur) are managed at runtime by a style
827
+ * global-glass blur) are managed at runtime by a style
611
828
  * element in custom.tsx and do not live here. */
612
829
  .vx-root {
613
830
  position: fixed;
@@ -670,16 +887,70 @@ window.__ModuleLoader__.load({
670
887
  color: #eef1f7;
671
888
  }
672
889
  }
890
+ /* The GUI theme can disagree with the OS scheme (dsh selects light/dark
891
+ independently — dark GUI on a light OS left these surfaces frosted
892
+ light), so the frost fills and panel text colors key on the mirrored
893
+ root classes, not the OS alone. The media queries above remain the
894
+ pre-boot fallback, before the client has applied the classes; the liquid
895
+ rules below out-rank these by specificity, not by order. */
896
+ :root.vx-light .vx-glass {
897
+ background: rgba(255, 255, 255, .64);
898
+ color: inherit;
899
+ }
900
+ :root.vx-dark .vx-glass {
901
+ background: rgba(13, 17, 25, .62);
902
+ color: #eef1f7;
903
+ }
904
+ :root.vx-light .vx-panel,
905
+ :root.vx-light .vx-modal,
906
+ :root.vx-light .vx-folders {
907
+ color: #20242e;
908
+ }
909
+ :root.vx-dark .vx-panel,
910
+ :root.vx-dark .vx-modal,
911
+ :root.vx-dark .vx-folders {
912
+ color: #e8ebf2;
913
+ }
914
+ :root.vx-light .vx-balance-hover {
915
+ color: #20242e;
916
+ }
917
+ :root.vx-dark .vx-balance-hover {
918
+ color: #e8ebf2;
919
+ }
920
+ /* Liquid glass: the SVG displacement filter bends the backdrop at the
921
+ surface's edges; the chained blur+saturate keeps text over the middle of
922
+ large panels readable (pure displacement leaves the mid-area untouched,
923
+ which read as "nothing happened"). Chromium runs this chain; engines
924
+ without SVG-referencing backdrop filters fall back to frost below. */
673
925
  .vx-liquid .vx-glass {
674
- background: rgba(255, 255, 255, .06);
675
- backdrop-filter: url(#vx-lg);
676
- -webkit-backdrop-filter: url(#vx-lg);
926
+ background: rgba(255, 255, 255, .1);
927
+ backdrop-filter: url(#vx-lg) blur(2.5px) saturate(1.12);
928
+ -webkit-backdrop-filter: url(#vx-lg) blur(2.5px) saturate(1.12);
677
929
  }
678
930
  @media (prefers-color-scheme: dark) {
679
931
  .vx-liquid .vx-glass {
680
- background: rgba(0, 0, 0, .06);
932
+ background: rgba(0, 0, 0, .1);
681
933
  }
682
934
  }
935
+ /* The GUI theme classes are mirrored onto <html> by the client, so the
936
+ liquid fill has to out-rank the theme frost fills *inside* .vx-root as
937
+ well. The previous ".vx-root.* .vx-liquid .vx-glass" rules never matched
938
+ anything — vx-liquid lives on <html>, an ANCESTOR of .vx-root, not a
939
+ descendant — which left the big panels at the 64% frost fill while the
940
+ balance hover (mounted outside .vx-root) sat at 10%: the "panel is not
941
+ liquid, the balance card is" report, verbatim. */
942
+ :root.vx-liquid.vx-dark .vx-glass {
943
+ background: rgba(0, 0, 0, .1);
944
+ }
945
+ :root.vx-liquid.vx-light .vx-glass {
946
+ background: rgba(255, 255, 255, .1);
947
+ }
948
+ :root.vx-liquid .vx-root.vx-dark .vx-glass {
949
+ background: rgba(0, 0, 0, .1);
950
+ }
951
+ :root.vx-liquid .vx-root.vx-light .vx-glass {
952
+ background: rgba(255, 255, 255, .1);
953
+ }
683
954
  @supports not (backdrop-filter: url(#vx-lg)) {
684
955
  .vx-liquid .vx-glass {
685
956
  background: rgba(255, 255, 255, .64);
@@ -692,158 +963,6 @@ window.__ModuleLoader__.load({
692
963
  }
693
964
  }
694
965
  }
695
- .vx-liquid .vx-pattern {
696
- background-image: radial-gradient(rgba(150, 150, 160, .5) 3px, transparent 3px);
697
- background-size: 24px 24px;
698
- -webkit-mask-image: radial-gradient(ellipse at top, transparent 20%, black);
699
- mask-image: radial-gradient(ellipse at top, transparent 20%, black);
700
- animation: vx-pattern-move 25000ms linear infinite;
701
- }
702
- @media (prefers-color-scheme: dark) {
703
- .vx-liquid .vx-pattern {
704
- background-image: radial-gradient(rgba(110, 110, 128, .5) 3px, transparent 3px);
705
- }
706
- }
707
- .vx-pattern {
708
- position: absolute;
709
- inset: 0;
710
- pointer-events: none;
711
- z-index: -1;
712
- background-image: radial-gradient(rgba(150, 150, 160, .42) 1px, transparent 1px);
713
- background-size: 24px 24px;
714
- -webkit-mask-image: radial-gradient(ellipse at center, transparent 30%, black 100%);
715
- mask-image: radial-gradient(ellipse at center, transparent 30%, black 100%);
716
- animation: vx-pattern-move 10000ms linear infinite;
717
- }
718
- @media (prefers-color-scheme: dark) {
719
- .vx-pattern {
720
- background-image: radial-gradient(rgba(100, 100, 116, .5) 1px, transparent 1px);
721
- }
722
- }
723
- @keyframes vx-pattern-move {
724
- from {
725
- background-position: 0 0;
726
- }
727
- to {
728
- background-position: 0 24px;
729
- }
730
- }
731
- @keyframes vx-aurora {
732
- 0% {
733
- background-position: 0% 50%;
734
- }
735
- 50% {
736
- background-position: 100% 50%;
737
- }
738
- 100% {
739
- background-position: 0% 50%;
740
- }
741
- }
742
- .vx-rail {
743
- position: absolute;
744
- width: 12px;
745
- border-radius: 8px;
746
- background: rgba(120, 130, 150, .18);
747
- border: 1px solid rgba(120, 130, 150, .25);
748
- pointer-events: auto;
749
- touch-action: none;
750
- box-sizing: border-box;
751
- }
752
- .vx-rail.right {
753
- right: 4px;
754
- }
755
- .vx-rail.left {
756
- left: 56px;
757
- }
758
- /* When the rail is active it substitutes the native scrollbar: the scrollport
759
- carrying the vx-rail-scroller class (added by the client when it resolves
760
- the chat scrollport) hides its own bar so only one scroll affordance
761
- remains. scrollbar-gutter: stable on the shell keeps the layout width. */
762
- .vx-rail-scroller {
763
- scrollbar-width: none;
764
- }
765
- .vx-rail-scroller::-webkit-scrollbar {
766
- display: none;
767
- }
768
- .vx-thumb {
769
- position: absolute;
770
- left: 1px;
771
- right: 1px;
772
- border-radius: 8px;
773
- background: rgba(90, 105, 135, .5);
774
- border: 1px solid rgba(255, 255, 255, .35);
775
- box-sizing: border-box;
776
- }
777
- .vx-thumb:hover {
778
- background: rgba(90, 105, 135, .7);
779
- }
780
- .vx-dot {
781
- position: absolute;
782
- left: 50%;
783
- transform: translate(-50%, -50%);
784
- width: 10px;
785
- height: 10px;
786
- border-radius: 50%;
787
- background: rgba(70, 85, 110, .92);
788
- border: 2px solid rgba(255, 255, 255, .92);
789
- box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
790
- pointer-events: auto;
791
- cursor: pointer;
792
- transition: transform .12s;
793
- padding: 0;
794
- }
795
- .vx-dot:hover {
796
- transform: translate(-50%, -50%) scale(1.35);
797
- }
798
- .vx-dot.star {
799
- background: #c9a24b;
800
- border-color: #f3e3bd;
801
- }
802
- @media (prefers-color-scheme: dark) {
803
- .vx-dot {
804
- background: rgba(205, 215, 230, .95);
805
- border-color: rgba(28, 34, 46, .9);
806
- }
807
- .vx-thumb {
808
- background: rgba(165, 180, 205, .45);
809
- }
810
- }
811
- .vx-rail-pop {
812
- position: absolute;
813
- pointer-events: auto;
814
- padding: 10px 12px;
815
- width: 300px;
816
- font-size: 12px;
817
- line-height: 1.55;
818
- z-index: 5;
819
- }
820
- /* Class = which side the rail sits on; the card must open toward the page
821
- content. It is a child of the 12px-wide rail, so right:20px puts it left
822
- of the rail and left:20px puts it right (20px = rail width + 8px gap). */
823
- .vx-rail-pop.right {
824
- right: 20px;
825
- }
826
- .vx-rail-pop.left {
827
- left: 20px;
828
- }
829
- .vx-pop-time {
830
- color: #6d7689;
831
- font-size: 11px;
832
- margin-bottom: 4px;
833
- }
834
- .vx-pop-text {
835
- white-space: pre-wrap;
836
- word-break: break-word;
837
- max-height: 150px;
838
- overflow: hidden;
839
- margin-bottom: 8px;
840
- }
841
- .vx-pop-row {
842
- display: flex;
843
- gap: 5px;
844
- flex-wrap: wrap;
845
- align-items: center;
846
- }
847
966
  .vx-balance-wrap {
848
967
  display: inline-flex;
849
968
  align-items: center;
@@ -865,17 +984,10 @@ window.__ModuleLoader__.load({
865
984
  .vx-balance-text:hover {
866
985
  background: rgba(127, 164, 224, .28);
867
986
  }
868
- .vx-balance-text.vx-balance-pinned {
987
+ .vx-balance-text.vx-balance-open {
869
988
  background: rgba(127, 164, 224, .36);
870
989
  border-color: rgba(127, 164, 224, .8);
871
990
  }
872
- .vx-balance-head {
873
- display: flex;
874
- align-items: center;
875
- justify-content: space-between;
876
- gap: 8px;
877
- margin-bottom: 8px;
878
- }
879
991
  .vx-balance-today {
880
992
  opacity: .75;
881
993
  font-size: 11.5px;
@@ -1053,10 +1165,6 @@ window.__ModuleLoader__.load({
1053
1165
  border-color: #7fa4e0;
1054
1166
  box-shadow: 0 0 0 2px rgba(127, 164, 224, .35);
1055
1167
  }
1056
- .vx-swatch:disabled {
1057
- opacity: .35;
1058
- cursor: not-allowed;
1059
- }
1060
1168
  .vx-swatch-label {
1061
1169
  font-size: 10px;
1062
1170
  opacity: .85;
@@ -1107,16 +1215,6 @@ window.__ModuleLoader__.load({
1107
1215
  padding: 6px 10px;
1108
1216
  font-size: 12px;
1109
1217
  }
1110
- .vx-textarea {
1111
- border: 1px solid rgba(128, 140, 160, .4);
1112
- background: rgba(255, 255, 255, .16);
1113
- color: inherit;
1114
- border-radius: 9px;
1115
- padding: 6px 10px;
1116
- font-size: 12px;
1117
- resize: vertical;
1118
- font-family: inherit;
1119
- }
1120
1218
  .vx-toggle-row {
1121
1219
  display: flex;
1122
1220
  gap: 8px;
@@ -1501,22 +1599,6 @@ window.__ModuleLoader__.load({
1501
1599
  background: rgba(13, 17, 25, .62);
1502
1600
  color: #eef1f7;
1503
1601
  }
1504
- .vx-root.vx-dark .vx-liquid .vx-glass {
1505
- background: rgba(0, 0, 0, .06);
1506
- }
1507
- .vx-root.vx-dark .vx-liquid .vx-pattern {
1508
- background-image: radial-gradient(rgba(110, 110, 128, .5) 3px, transparent 3px);
1509
- }
1510
- .vx-root.vx-dark .vx-pattern {
1511
- background-image: radial-gradient(rgba(100, 100, 116, .5) 1px, transparent 1px);
1512
- }
1513
- .vx-root.vx-dark .vx-dot {
1514
- background: rgba(205, 215, 230, .95);
1515
- border-color: rgba(28, 34, 46, .9);
1516
- }
1517
- .vx-root.vx-dark .vx-thumb {
1518
- background: rgba(165, 180, 205, .45);
1519
- }
1520
1602
  .vx-root.vx-dark .vx-balance-hover,
1521
1603
  .vx-root.vx-dark .vx-panel,
1522
1604
  .vx-root.vx-dark .vx-modal,
@@ -1531,22 +1613,6 @@ window.__ModuleLoader__.load({
1531
1613
  background: rgba(255, 255, 255, .64);
1532
1614
  color: #20242e;
1533
1615
  }
1534
- .vx-root.vx-light .vx-liquid .vx-glass {
1535
- background: rgba(255, 255, 255, .06);
1536
- }
1537
- .vx-root.vx-light .vx-liquid .vx-pattern {
1538
- background-image: radial-gradient(rgba(150, 150, 160, .5) 3px, transparent 3px);
1539
- }
1540
- .vx-root.vx-light .vx-pattern {
1541
- background-image: radial-gradient(rgba(150, 150, 160, .42) 1px, transparent 1px);
1542
- }
1543
- .vx-root.vx-light .vx-dot {
1544
- background: rgba(70, 85, 110, .92);
1545
- border-color: rgba(255, 255, 255, .92);
1546
- }
1547
- .vx-root.vx-light .vx-thumb {
1548
- background: rgba(90, 105, 135, .5);
1549
- }
1550
1616
  .vx-root.vx-light .vx-balance-hover,
1551
1617
  .vx-root.vx-light .vx-panel,
1552
1618
  .vx-root.vx-light .vx-modal,
@@ -1556,7 +1622,7 @@ window.__ModuleLoader__.load({
1556
1622
  .vx-root.vx-light .vx-toast {
1557
1623
  background: rgba(26, 32, 44, .92);
1558
1624
  }
1559
- }`;
1625
+ `;
1560
1626
  //#endregion
1561
1627
  //#region src/client/custom.tsx
1562
1628
  /**
@@ -1566,7 +1632,7 @@ window.__ModuleLoader__.load({
1566
1632
  * listener set; components re-render on `setS`. The file ports the earlier
1567
1633
  * dynamic-plugin implementation: React is a platform import, static styles
1568
1634
  * are injected through one owned style element (styles.ts), dynamic body
1569
- * styles (background / aurora / global glass) extend it, and host calls go
1635
+ * styles (background / global glass) extend it, and host calls go
1570
1636
  * over `/api/custom-plugin` fetch routes.
1571
1637
  * @module @alexpeng/dsh-custom-plugin/client/custom
1572
1638
  */
@@ -1576,119 +1642,9 @@ window.__ModuleLoader__.load({
1576
1642
  * still works instead of leaving a bare error that reads as a broken palette.
1577
1643
  */
1578
1644
  const CROSS_SEARCH_UNAVAILABLE = "跨会话全文搜索不可用;下方结果仍按标题匹配会话与工作区。";
1579
- function fmtClock(time) {
1580
- const d = new Date(time);
1581
- const pad = (n) => String(n).padStart(2, "0");
1582
- return `${pad(d.getHours())}:${pad(d.getMinutes())}`;
1583
- }
1584
1645
  function formatTokenCount(value) {
1585
1646
  return Math.round(value).toLocaleString("zh-CN");
1586
1647
  }
1587
- /** Palette of 20 muted low-saturation backgrounds (with matching tab colors).
1588
- * 天青灰 leads the list: it is the install default and renders first among
1589
- * the palette swatches, right after 无颜色 / 极光. */
1590
- const PALETTE = [
1591
- [
1592
- "天青灰",
1593
- "#E9EBEE",
1594
- "#D6DADF"
1595
- ],
1596
- [
1597
- "暖象牙",
1598
- "#F5F0E8",
1599
- "#E8E0D4"
1600
- ],
1601
- [
1602
- "雾灰绿",
1603
- "#E9EDE6",
1604
- "#D7DED3"
1605
- ],
1606
- [
1607
- "烟熏玫瑰",
1608
- "#F2EAEC",
1609
- "#E5D6DA"
1610
- ],
1611
- [
1612
- "雾蓝",
1613
- "#E8EDF2",
1614
- "#D4DDE6"
1615
- ],
1616
- [
1617
- "薰衣草灰",
1618
- "#EFEDF4",
1619
- "#E0DCEB"
1620
- ],
1621
- [
1622
- "燕麦米",
1623
- "#F3EEE6",
1624
- "#E5DED3"
1625
- ],
1626
- [
1627
- "薄荷雾",
1628
- "#EAF0ED",
1629
- "#D7E3DC"
1630
- ],
1631
- [
1632
- "裸桃",
1633
- "#F5EDE8",
1634
- "#E8DCD4"
1635
- ],
1636
- [
1637
- "石板蓝",
1638
- "#E6EDF1",
1639
- "#D2DBE3"
1640
- ],
1641
- [
1642
- "紫藤灰",
1643
- "#EEEBF2",
1644
- "#E1DAE8"
1645
- ],
1646
- [
1647
- "奶油黄",
1648
- "#F4F0E6",
1649
- "#E6E1D5"
1650
- ],
1651
- [
1652
- "鼠尾草",
1653
- "#EAEDE5",
1654
- "#D7DED1"
1655
- ],
1656
- [
1657
- "腮红粉",
1658
- "#F3EAEC",
1659
- "#E6D6DA"
1660
- ],
1661
- [
1662
- "香草白",
1663
- "#F3F0E6",
1664
- "#E5E0D4"
1665
- ],
1666
- [
1667
- "青灰",
1668
- "#E7F0F0",
1669
- "#D3E1E1"
1670
- ],
1671
- [
1672
- "杏仁白",
1673
- "#F0ECE8",
1674
- "#E2DAD3"
1675
- ],
1676
- [
1677
- "尤加利",
1678
- "#EAF0ED",
1679
- "#D7E3DB"
1680
- ],
1681
- [
1682
- "珍珠灰",
1683
- "#EDEDEE",
1684
- "#DCDCDD"
1685
- ],
1686
- [
1687
- "淡金",
1688
- "#F4F1E4",
1689
- "#E6E1D0"
1690
- ]
1691
- ];
1692
1648
  /** Neutral glass tokens used when no palette color is active. */
1693
1649
  const NEUTRAL_TOKENS = {
1694
1650
  "--dsw-alias-bg-base": {
@@ -1762,21 +1718,8 @@ window.__ModuleLoader__.load({
1762
1718
  usage: {},
1763
1719
  sessionId: null,
1764
1720
  turns: null,
1721
+ turnsBySeq: null,
1765
1722
  anchors: /* @__PURE__ */ new Map(),
1766
- seqAnchor: /* @__PURE__ */ new Map(),
1767
- railPositions: [],
1768
- railSig: "",
1769
- railHover: null,
1770
- railHoverTimer: null,
1771
- railBox: {
1772
- top: 64,
1773
- height: 600
1774
- },
1775
- railRight: 4,
1776
- railLeft: 56,
1777
- thumbTop: 0,
1778
- thumbH: 26,
1779
- scrollerEl: null,
1780
1723
  panelOpen: false,
1781
1724
  panelTab: "look",
1782
1725
  panelPos: null,
@@ -1787,6 +1730,7 @@ window.__ModuleLoader__.load({
1787
1730
  dropHint: null,
1788
1731
  promptOpen: null,
1789
1732
  promptQuery: "",
1733
+ balanceOpen: false,
1790
1734
  batchModal: false,
1791
1735
  mermaidModal: null,
1792
1736
  quoteSel: null,
@@ -1860,13 +1804,10 @@ window.__ModuleLoader__.load({
1860
1804
  sessionScopeHolders++;
1861
1805
  if (S.sessionId !== id) {
1862
1806
  S.anchors.clear();
1863
- S.seqAnchor.clear();
1864
1807
  setS({
1865
1808
  sessionId: id,
1866
1809
  turns: null,
1867
- railPositions: [],
1868
- railSig: "",
1869
- railHover: null
1810
+ turnsBySeq: null
1870
1811
  });
1871
1812
  fetchTurns(id);
1872
1813
  }
@@ -1874,13 +1815,10 @@ window.__ModuleLoader__.load({
1874
1815
  sessionScopeHolders--;
1875
1816
  if (sessionScopeHolders === 0 && S.sessionId === id) {
1876
1817
  S.anchors.clear();
1877
- S.seqAnchor.clear();
1878
1818
  setS({
1879
1819
  sessionId: null,
1880
1820
  turns: null,
1881
- railPositions: [],
1882
- railSig: "",
1883
- railHover: null
1821
+ turnsBySeq: null
1884
1822
  });
1885
1823
  }
1886
1824
  };
@@ -1960,11 +1898,6 @@ window.__ModuleLoader__.load({
1960
1898
  }]
1961
1899
  ],
1962
1900
  zap: [["path", { d: "M13 2 3 14h9l-1 8 10-12h-9l1-8z" }]],
1963
- clock: [["circle", {
1964
- cx: 12,
1965
- cy: 12,
1966
- r: 10
1967
- }], ["polyline", { points: "12 6 12 12 16 14" }]],
1968
1901
  download: [
1969
1902
  ["path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" }],
1970
1903
  ["polyline", { points: "7 10 12 15 17 10" }],
@@ -2031,25 +1964,6 @@ window.__ModuleLoader__.load({
2031
1964
  y2: 18
2032
1965
  }]],
2033
1966
  star: [["path", { d: "M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z" }]],
2034
- fork: [
2035
- ["line", {
2036
- x1: 6,
2037
- y1: 3,
2038
- x2: 6,
2039
- y2: 15
2040
- }],
2041
- ["circle", {
2042
- cx: 18,
2043
- cy: 6,
2044
- r: 3
2045
- }],
2046
- ["circle", {
2047
- cx: 6,
2048
- cy: 18,
2049
- r: 3
2050
- }],
2051
- ["path", { d: "M18 9a9 9 0 0 1-9 9" }]
2052
- ],
2053
1967
  copy: [["rect", {
2054
1968
  x: 9,
2055
1969
  y: 9,
@@ -2172,88 +2086,30 @@ window.__ModuleLoader__.load({
2172
2086
  r: 2.1
2173
2087
  }],
2174
2088
  ["circle", {
2175
- cx: 8,
2176
- cy: 15.7,
2177
- r: 2.1
2178
- }],
2179
- ["circle", {
2180
- cx: 5.5,
2181
- cy: 8.3,
2182
- r: 2.1
2183
- }]
2184
- ],
2185
- arrowUp: [["polyline", { points: "18 15 12 9 6 15" }]],
2186
- arrowDown: [["polyline", { points: "6 9 12 15 18 9" }]],
2187
- minimize: [
2188
- ["polyline", { points: "4 14 10 14 10 20" }],
2189
- ["polyline", { points: "20 10 14 10 14 4" }],
2190
- ["line", {
2191
- x1: 14,
2192
- y1: 10,
2193
- x2: 21,
2194
- y2: 3
2195
- }],
2196
- ["line", {
2197
- x1: 3,
2198
- y1: 21,
2199
- x2: 10,
2200
- y2: 14
2201
- }]
2202
- ],
2203
- moon: [["path", { d: "M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" }]],
2204
- sun: [
2205
- ["circle", {
2206
- cx: 12,
2207
- cy: 12,
2208
- r: 4
2209
- }],
2210
- ["line", {
2211
- x1: 12,
2212
- y1: 2,
2213
- x2: 12,
2214
- y2: 5
2215
- }],
2216
- ["line", {
2217
- x1: 12,
2218
- y1: 19,
2219
- x2: 12,
2220
- y2: 22
2221
- }],
2222
- ["line", {
2223
- x1: 2,
2224
- y1: 12,
2225
- x2: 5,
2226
- y2: 12
2227
- }],
2228
- ["line", {
2229
- x1: 19,
2230
- y1: 12,
2231
- x2: 22,
2232
- y2: 12
2233
- }],
2234
- ["line", {
2235
- x1: 4.93,
2236
- y1: 4.93,
2237
- x2: 7.07,
2238
- y2: 7.07
2239
- }],
2240
- ["line", {
2241
- x1: 16.93,
2242
- y1: 16.93,
2243
- x2: 19.07,
2244
- y2: 19.07
2089
+ cx: 8,
2090
+ cy: 15.7,
2091
+ r: 2.1
2245
2092
  }],
2093
+ ["circle", {
2094
+ cx: 5.5,
2095
+ cy: 8.3,
2096
+ r: 2.1
2097
+ }]
2098
+ ],
2099
+ minimize: [
2100
+ ["polyline", { points: "4 14 10 14 10 20" }],
2101
+ ["polyline", { points: "20 10 14 10 14 4" }],
2246
2102
  ["line", {
2247
- x1: 4.93,
2248
- y1: 19.07,
2249
- x2: 7.07,
2250
- y2: 16.93
2103
+ x1: 14,
2104
+ y1: 10,
2105
+ x2: 21,
2106
+ y2: 3
2251
2107
  }],
2252
2108
  ["line", {
2253
- x1: 16.93,
2254
- y1: 7.07,
2255
- x2: 19.07,
2256
- y2: 4.93
2109
+ x1: 3,
2110
+ y1: 21,
2111
+ x2: 10,
2112
+ y2: 14
2257
2113
  }]
2258
2114
  ],
2259
2115
  list: [
@@ -2363,20 +2219,6 @@ window.__ModuleLoader__.load({
2363
2219
  cb
2364
2220
  } });
2365
2221
  }
2366
- function hexToRgb(hex) {
2367
- const match = /^#?([0-9a-f]{6})$/i.exec(String(hex ?? "").trim());
2368
- if (match === null) return [
2369
- 235,
2370
- 238,
2371
- 242
2372
- ];
2373
- const value = parseInt(match[1], 16);
2374
- return [
2375
- value >> 16 & 255,
2376
- value >> 8 & 255,
2377
- value & 255
2378
- ];
2379
- }
2380
2222
  function rgbaOf(hex, alpha) {
2381
2223
  const c = hexToRgb(hex);
2382
2224
  return `rgba(${c[0]},${c[1]},${c[2]},${alpha})`;
@@ -2405,14 +2247,14 @@ window.__ModuleLoader__.load({
2405
2247
  tokenDisposer = null;
2406
2248
  }
2407
2249
  if (theme !== void 0 && typeof theme.overrideTokens === "function") {
2408
- if (cfg.bg !== void 0 && cfg.bg !== "default" && cfg.bg !== "aurora") {
2250
+ if (cfg.bg !== void 0 && cfg.bg !== "default") {
2409
2251
  const entry = PALETTE.find((p) => p[0] === cfg.bg) ?? PALETTE[0];
2410
2252
  const base = entry[1];
2411
2253
  const tab = entry[2] ?? shade(base, .94);
2412
2254
  const glassOn = cfg.glass === true;
2413
2255
  const mk = (c, a) => glassOn ? rgbaOf(c, a) : c;
2414
- const darkBase = shade(base, .78);
2415
- const darkTab = shade(tab, .78);
2256
+ const darkBase = toDarkRamp(base, .14);
2257
+ const darkTab = toDarkRamp(tab, .18);
2416
2258
  tokenDisposer = theme.overrideTokens("custom-plugin-appearance", {
2417
2259
  "--dsw-alias-bg-base": {
2418
2260
  light: mk(base, .5),
@@ -2435,18 +2277,18 @@ window.__ModuleLoader__.load({
2435
2277
  dark: mk(darkTab, .62)
2436
2278
  }
2437
2279
  });
2438
- } else if (cfg.glass === true || cfg.bg === "aurora") tokenDisposer = theme.overrideTokens("custom-plugin-appearance", NEUTRAL_TOKENS);
2280
+ } else if (cfg.glass === true) tokenDisposer = theme.overrideTokens("custom-plugin-appearance", NEUTRAL_TOKENS);
2439
2281
  }
2440
2282
  let dyn = "";
2441
- if (cfg.bg === "aurora") {
2442
- dyn += "@keyframes vx-aurora { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }";
2443
- dyn += " body { background: linear-gradient(120deg, #8fa8d8, #b59fd8, #8fc4b4, #d8a8c0) !important; background-size: 320% 320% !important; animation: vx-aurora 26s ease infinite !important; }";
2444
- dyn += " body[data-ds-dark-theme] [data-conversation-scroll] > :has([data-conversation-composer-overlay]) { background: transparent !important; }";
2445
- } else if (cfg.bg !== void 0 && cfg.bg !== "default") {
2283
+ if (cfg.bg !== void 0 && cfg.bg !== "default") {
2446
2284
  const base = (PALETTE.find((p) => p[0] === cfg.bg) ?? PALETTE[0])[1];
2447
- dyn += ` body { background-color: ${base} !important; }`;
2285
+ const surface = S.dark === true ? toDarkRamp(base, DARK_CANVAS_LIGHTNESS) : base;
2286
+ dyn += ` body { background-color: ${surface} !important; }`;
2287
+ }
2288
+ if (cfg.globalGlass === true) {
2289
+ const filter = cfg.glass === true && cfg.glassMode === "liquid" && typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("backdrop-filter", "url(#vx-lg)") ? "url(#vx-lg) blur(2.5px) saturate(1.12)" : "blur(8px) saturate(1.2)";
2290
+ dyn += ` [role='dialog'], [role='menu'], [role='tooltip'], [role='listbox'], [data-radix-popper-content-wrapper] { backdrop-filter: ${filter} !important; -webkit-backdrop-filter: ${filter} !important; }`;
2448
2291
  }
2449
- if (cfg.globalGlass === true) dyn += " [role='dialog'], [role='menu'], [role='tooltip'], [role='listbox'], [data-radix-popper-content-wrapper] { backdrop-filter: blur(8px) saturate(1.2) !important; -webkit-backdrop-filter: blur(8px) saturate(1.2) !important; }";
2450
2292
  setDynCss(dyn);
2451
2293
  }
2452
2294
  function syncAntiScroll(on) {
@@ -2468,7 +2310,15 @@ window.__ModuleLoader__.load({
2468
2310
  }
2469
2311
  } catch {}
2470
2312
  }
2313
+ const LOAD_RETRY_DELAYS = [
2314
+ 1500,
2315
+ 3e3,
2316
+ 6e3
2317
+ ];
2318
+ let loadCfgAttempt = 0;
2319
+ let cfgLoaded = false;
2471
2320
  async function loadCfg() {
2321
+ let failure = null;
2472
2322
  try {
2473
2323
  const result = await apiStateGet();
2474
2324
  if (result.ok === true && result.data !== void 0) {
@@ -2480,6 +2330,10 @@ window.__ModuleLoader__.load({
2480
2330
  };
2481
2331
  delete cfg.clouds;
2482
2332
  delete cfg.wind;
2333
+ delete cfg.timeline;
2334
+ delete cfg.timelineLeft;
2335
+ delete cfg.starsOnly;
2336
+ if (cfg.bg === "aurora") cfg.bg = "default";
2483
2337
  S.cfg = cfg;
2484
2338
  }
2485
2339
  if (Array.isArray(data.folders)) S.folders = data.folders;
@@ -2488,16 +2342,36 @@ window.__ModuleLoader__.load({
2488
2342
  if (typeof data.apiKeyConfigured === "boolean") S.apiKeyConfigured = data.apiKeyConfigured;
2489
2343
  if (data.credentialStorage === "system" || data.credentialStorage === "legacy-state" || data.credentialStorage === "environment" || data.credentialStorage === "dsh" || data.credentialStorage === "none") S.credentialStorage = data.credentialStorage;
2490
2344
  if (data.usage !== void 0 && data.usage !== null && typeof data.usage === "object") S.usage = data.usage;
2491
- }
2492
- } catch {}
2345
+ loadCfgAttempt = 0;
2346
+ cfgLoaded = true;
2347
+ } else if (result.ok !== true) failure = result.error ?? "状态读取失败";
2348
+ } catch (error) {
2349
+ failure = String(error?.message ?? error);
2350
+ }
2351
+ if (failure !== null) {
2352
+ apiDiagReport("loadCfg: " + failure);
2353
+ if (loadCfgAttempt < LOAD_RETRY_DELAYS.length) {
2354
+ const delay = LOAD_RETRY_DELAYS[loadCfgAttempt];
2355
+ loadCfgAttempt++;
2356
+ setTimeout(() => {
2357
+ loadCfg();
2358
+ }, delay);
2359
+ } else if (S.booted) toast("配置读取失败:" + failure, "error");
2360
+ }
2493
2361
  S.booted = true;
2494
2362
  setS({});
2495
2363
  if (!S.greeted) {
2496
2364
  S.greeted = true;
2497
- new Promise((resolve) => setTimeout(resolve, 1200)).then(() => toast("Custom 便利套件已就绪", "info")).catch(() => {});
2365
+ new Promise((resolve) => setTimeout(resolve, 1200)).then(() => toast(failure !== null ? "Custom 便利套件加载失败:" + failure : "Custom 便利套件已就绪", failure !== null ? "error" : "info")).catch(() => {});
2498
2366
  }
2499
2367
  }
2500
2368
  function saveCfg() {
2369
+ if (!cfgLoaded) {
2370
+ toast("配置尚未读取完成,已重新加载,请重试", "error");
2371
+ loadCfgAttempt = 0;
2372
+ loadCfg();
2373
+ return;
2374
+ }
2501
2375
  const cfg = { ...S.cfg };
2502
2376
  delete cfg.clouds;
2503
2377
  delete cfg.wind;
@@ -2511,7 +2385,9 @@ window.__ModuleLoader__.load({
2511
2385
  };
2512
2386
  apiStateSave(edit).then((result) => {
2513
2387
  if (result.ok !== true) {
2514
- if (keyDirty) toast(result.error ?? "Key 保存失败", "error");
2388
+ const message = result.error ?? "设置保存失败";
2389
+ apiDiagReport("saveCfg: " + message);
2390
+ toast(message, "error");
2515
2391
  return;
2516
2392
  }
2517
2393
  if (keyDirty && S.apiKeyDirty && S.apiKey === (edit.apiKey ?? "")) setS({
@@ -2519,8 +2395,10 @@ window.__ModuleLoader__.load({
2519
2395
  apiKeyConfigured: result.apiKeyConfigured ?? S.apiKey.trim() !== "",
2520
2396
  credentialStorage: result.credentialStorage ?? S.credentialStorage
2521
2397
  });
2522
- }).catch(() => {
2523
- if (keyDirty) toast("Key 保存失败", "error");
2398
+ }).catch((error) => {
2399
+ const message = String(error?.message ?? error);
2400
+ apiDiagReport("saveCfg: " + message);
2401
+ toast("设置保存失败:" + message, "error");
2524
2402
  });
2525
2403
  }
2526
2404
  const FX = {
@@ -2849,13 +2727,12 @@ window.__ModuleLoader__.load({
2849
2727
  function FxCanvas() {
2850
2728
  const s = useS();
2851
2729
  const ref = react.useRef(null);
2852
- /** 粒子配色跟随背景亮度:浅色主题(以及任何主题下的高饱和极光)
2853
- * 需要更深的粒子颜色才可辨识。ref 让 RAF 循环每帧读到最新值,
2854
- * 主题/背景切换时无需重建粒子场。 */
2855
- const lightRef = react.useRef(!(s.dark === true) || s.cfg.bg === "aurora");
2730
+ /** 粒子配色跟随背景亮度:浅色主题需要更深的粒子颜色才可辨识。
2731
+ * ref 让 RAF 循环每帧读到最新值,主题/背景切换时无需重建粒子场。 */
2732
+ const lightRef = react.useRef(!(s.dark === true));
2856
2733
  react.useEffect(() => {
2857
- lightRef.current = !(s.dark === true) || s.cfg.bg === "aurora";
2858
- }, [s.dark, s.cfg.bg]);
2734
+ lightRef.current = !(s.dark === true);
2735
+ }, [s.dark]);
2859
2736
  react.useEffect(() => {
2860
2737
  const cvs = ref.current;
2861
2738
  if (cvs === null) return;
@@ -2889,9 +2766,7 @@ window.__ModuleLoader__.load({
2889
2766
  className: "vx-fx"
2890
2767
  });
2891
2768
  }
2892
- let lastRefetchAt = 0;
2893
2769
  let turnsRequestSerial = 0;
2894
- let railRefetchRows = -1;
2895
2770
  const diagAtByKey = /* @__PURE__ */ new Map();
2896
2771
  function diagThrottled(message) {
2897
2772
  const key = message.slice(0, 24);
@@ -2901,25 +2776,25 @@ window.__ModuleLoader__.load({
2901
2776
  diagAtByKey.set(key, now);
2902
2777
  reportDiag(message);
2903
2778
  }
2904
- function scheduleTurnsRefetch() {
2905
- const now = Date.now();
2906
- if (now - lastRefetchAt < 2e3) return;
2907
- lastRefetchAt = now;
2908
- fetchTurns(S.sessionId);
2909
- }
2910
2779
  async function fetchTurns(sessionId) {
2911
2780
  const requestSerial = ++turnsRequestSerial;
2912
2781
  try {
2913
2782
  const result = await apiTimelineGet(sessionId);
2914
2783
  if (sessionId !== S.sessionId || requestSerial !== turnsRequestSerial) return;
2915
2784
  if (result.ok === true) {
2785
+ const items = result.items ?? [];
2786
+ const bySeq = /* @__PURE__ */ new Map();
2787
+ for (const item of items) bySeq.set(item.seq, item);
2916
2788
  S.turns = {
2917
2789
  sessionId,
2918
- items: result.items ?? []
2790
+ items
2919
2791
  };
2920
- setS({ turns: S.turns });
2921
- updateRailPositions();
2922
- diagThrottled("timeline " + (result.items?.length ?? 0) + " items " + sessionId.slice(0, 24));
2792
+ S.turnsBySeq = bySeq;
2793
+ setS({
2794
+ turns: S.turns,
2795
+ turnsBySeq: bySeq
2796
+ });
2797
+ diagThrottled("timeline " + items.length + " items " + sessionId.slice(0, 24));
2923
2798
  } else diagThrottled("timeline failed: " + String(result.error ?? "unknown"));
2924
2799
  } catch (error) {
2925
2800
  diagThrottled("timeline fetch error: " + String(error?.message ?? error));
@@ -2961,130 +2836,19 @@ window.__ModuleLoader__.load({
2961
2836
  }
2962
2837
  return null;
2963
2838
  }
2964
- /** All rendered user-message rows inside the scrollport, in document order
2965
- * (steering messages render through the same UserMessageNodeView). */
2966
- function queryUserRows(scroller) {
2967
- try {
2968
- return Array.from(scroller.querySelectorAll("[data-chat-flow-kind=\"user\"], [data-chat-flow-kind=\"steering\"]"));
2969
- } catch {
2970
- return [];
2971
- }
2972
- }
2973
- /** Keep the rail-scroller class on exactly the current scrollport so the
2974
- * native scrollbar hides only for the column the rail substitutes. */
2975
- function syncRailScrollerClass(scroller) {
2976
- const previous = S.scrollerEl;
2977
- if (previous !== null && previous !== scroller) try {
2978
- previous.classList.remove("vx-rail-scroller");
2979
- } catch {}
2980
- if (scroller !== null && scroller !== previous) try {
2981
- scroller.classList.add("vx-rail-scroller");
2982
- } catch {}
2983
- }
2984
- function updateRailPositions() {
2985
- if (S.cfg.timeline !== true || S.sessionId === null) {
2986
- syncRailScrollerClass(null);
2987
- if (S.railPositions.length > 0 || S.thumbTop !== 0 || S.thumbH !== 26) setS({
2988
- railPositions: [],
2989
- railSig: "",
2990
- railBox: {
2991
- top: 64,
2992
- height: 600
2993
- },
2994
- railRight: 4,
2995
- railLeft: 56,
2996
- thumbTop: 0,
2997
- thumbH: 26,
2998
- scrollerEl: null
2999
- });
3000
- return;
3001
- }
3002
- const w = typeof window !== "undefined" ? window : null;
3003
- if (w === null) return;
3004
- if (S.turns === null || S.turns.sessionId !== S.sessionId) {
3005
- railRefetchRows = -1;
3006
- scheduleTurnsRefetch();
3007
- }
3008
- const items = S.turns !== null && Array.isArray(S.turns.items) ? S.turns.items : [];
3009
- let scroller = S.scrollerEl;
3010
- if (scroller === null || !scroller.isConnected) scroller = resolveScroller();
3011
- syncRailScrollerClass(scroller);
3012
- const vh = w.innerHeight || 800;
3013
- let top = 64;
3014
- let height = vh - 64 - 120;
3015
- let scrollH = Math.max(1, height);
3016
- let scrollTop = 0;
3017
- let viewH = height;
3018
- let railRight = 4;
3019
- let railLeft = 56;
3020
- let scrollerRect = null;
3021
- if (scroller !== null) try {
3022
- const r = scroller.getBoundingClientRect();
3023
- scrollerRect = r;
3024
- top = Math.max(0, r.top);
3025
- height = Math.max(60, r.height);
3026
- viewH = Math.max(1, scroller.clientHeight || r.height);
3027
- scrollH = Math.max(viewH, scroller.scrollHeight || viewH);
3028
- scrollTop = Math.max(0, scroller.scrollTop || 0);
3029
- railRight = Math.max(2, Math.round(w.innerWidth - r.right + 4));
3030
- railLeft = Math.max(2, Math.round(r.left + 4));
3031
- } catch {}
3032
- const trackH = height;
3033
- const pos = [];
3034
- const seqAnchor = /* @__PURE__ */ new Map();
3035
- if (scroller !== null && scrollerRect !== null) {
3036
- const rows = queryUserRows(scroller);
3037
- const offset = items.length - rows.length;
3038
- if (rows.length > items.length && railRefetchRows < rows.length) {
3039
- railRefetchRows = rows.length;
3040
- scheduleTurnsRefetch();
3041
- }
3042
- for (let i = 0; i < rows.length; i++) {
3043
- const item = offset + i >= 0 ? items[offset + i] : void 0;
3044
- if (item === void 0) continue;
3045
- try {
3046
- const r = rows[i].getBoundingClientRect();
3047
- const pct = Math.max(0, Math.min(1, (r.top + r.height / 2 - scrollerRect.top + scrollTop) / Math.max(1, scroller.scrollHeight || 1)));
3048
- const starred = S.stars[S.sessionId]?.[item.seq] === true;
3049
- seqAnchor.set(item.seq, rows[i]);
3050
- pos.push({
3051
- seq: item.seq,
3052
- y: Math.round(pct * trackH),
3053
- st: starred
3054
- });
3055
- } catch {}
3056
- }
3057
- }
3058
- const thumbH = Math.max(26, Math.round(trackH * (viewH / scrollH)));
3059
- const thumbTop = scrollTop / Math.max(1, scrollH - viewH) * (trackH - thumbH);
3060
- const sig = JSON.stringify(pos) + "|" + thumbTop + "|" + thumbH + "|" + top + "|" + height + "|" + railRight + "|" + railLeft;
3061
- S.seqAnchor = seqAnchor;
3062
- if (sig !== S.railSig) {
3063
- setS({
3064
- railPositions: pos,
3065
- railSig: sig,
3066
- railBox: {
3067
- top,
3068
- height
3069
- },
3070
- railRight,
3071
- railLeft,
3072
- thumbTop: Math.round(thumbTop),
3073
- thumbH,
3074
- scrollerEl: scroller
3075
- });
3076
- diagThrottled("rail " + pos.length + " dots / anchors " + S.anchors.size + " / turns " + items.length + " / scroller " + (scroller === null ? "none" : scroller.tagName.toLowerCase() + "." + String(scroller.className ?? "").slice(0, 60)));
3077
- }
3078
- }
2839
+ /** Scroll the rendered message row for `seq` to the viewport center. The
2840
+ * element comes from the turnTail anchor map (our own chips register it);
2841
+ * the scrollport is resolved at call time from the shell's semantic
2842
+ * attribute, with scrollIntoView as the fallback. */
3079
2843
  function scrollToSeq(seq) {
3080
- const el = S.seqAnchor.get(seq) ?? S.anchors.get(seq)?.el ?? null;
3081
- if (el === void 0 || el === null) {
2844
+ const el = S.anchors.get(seq)?.el ?? null;
2845
+ if (el === null) {
3082
2846
  toast("该消息尚未渲染,请稍后重试", "error");
3083
2847
  return;
3084
2848
  }
3085
- const scroller = S.scrollerEl;
2849
+ const scroller = resolveScroller();
3086
2850
  let done = false;
3087
- if (scroller !== null && scroller.isConnected) try {
2851
+ if (scroller !== null) try {
3088
2852
  const er = el.getBoundingClientRect();
3089
2853
  const sr = scroller.getBoundingClientRect();
3090
2854
  const floor = Math.max(0, (scroller.scrollHeight ?? 0) - (scroller.clientHeight ?? 0));
@@ -3102,43 +2866,6 @@ window.__ModuleLoader__.load({
3102
2866
  el.scrollIntoView(true);
3103
2867
  } catch {}
3104
2868
  }
3105
- setS({ railHover: null });
3106
- }
3107
- function toggleStar(seq) {
3108
- const sid = S.sessionId;
3109
- if (sid === null) return;
3110
- const next = { ...S.stars[sid] ?? {} };
3111
- if (next[seq] === true) delete next[seq];
3112
- else next[seq] = true;
3113
- const stars = { ...S.stars };
3114
- stars[sid] = next;
3115
- setS({ stars });
3116
- saveCfg();
3117
- updateRailPositions();
3118
- }
3119
- async function forkAt(seq) {
3120
- const remote = sessionRemote();
3121
- if (remote === void 0) {
3122
- toast("分支不可用:会话 Remote 服务缺失", "error");
3123
- return;
3124
- }
3125
- try {
3126
- const result = await remote.fork({
3127
- sessionId: S.sessionId,
3128
- atSeq: seq
3129
- });
3130
- if (!result.ok) {
3131
- toast("创建分支失败: " + remoteErrorMessage(result.error, "未知错误"), "error");
3132
- return;
3133
- }
3134
- const childId = result.value.sessionId;
3135
- toast("分支会话已创建", "info", {
3136
- label: "打开分支",
3137
- run: () => openSessionItem(childId)
3138
- });
3139
- } catch (error) {
3140
- toast("创建分支失败: " + String(error?.message ?? error), "error");
3141
- }
3142
2869
  }
3143
2870
  function extractLatex(text) {
3144
2871
  const out = [];
@@ -3235,6 +2962,17 @@ window.__ModuleLoader__.load({
3235
2962
  return mermaidState.status === "ready";
3236
2963
  }
3237
2964
  mermaidState = { status: "loading" };
2965
+ const d0 = typeof document !== "undefined" ? document : null;
2966
+ const watchdog = setTimeout(() => {
2967
+ if (mermaidState.status !== "loading") return;
2968
+ mermaidState = {
2969
+ status: "failed",
2970
+ error: "脚本加载超时"
2971
+ };
2972
+ try {
2973
+ if (d0 !== null) for (const el of d0.querySelectorAll(`script[src="${MERMAID_SCRIPT_PATH}"]`)) el.remove();
2974
+ } catch {}
2975
+ }, 3e4);
3238
2976
  try {
3239
2977
  const result = await apiMermaidFetch();
3240
2978
  if (result.ok === true) {
@@ -3264,6 +3002,8 @@ window.__ModuleLoader__.load({
3264
3002
  error: String(error?.message ?? error)
3265
3003
  };
3266
3004
  return false;
3005
+ } finally {
3006
+ clearTimeout(watchdog);
3267
3007
  }
3268
3008
  }
3269
3009
  async function renderMermaid(code, dark = false) {
@@ -3441,11 +3181,18 @@ window.__ModuleLoader__.load({
3441
3181
  delete block.dataset.vxMmdFail;
3442
3182
  }
3443
3183
  }
3184
+ let balanceRetryTimer = null;
3185
+ let balanceRetries = 0;
3444
3186
  async function refreshBalance() {
3187
+ if (balanceRetryTimer !== null) {
3188
+ clearTimeout(balanceRetryTimer);
3189
+ balanceRetryTimer = null;
3190
+ }
3445
3191
  try {
3446
3192
  const result = await apiBalanceGet();
3447
3193
  S.balance = result;
3448
3194
  S.apiKeyConfigured = result.keyConfigured === true;
3195
+ balanceRetries = 0;
3449
3196
  const usageToday = result.usageToday;
3450
3197
  if (usageToday !== void 0 && usageToday !== null && typeof usageToday === "object") {
3451
3198
  S.usage = { ...S.usage };
@@ -3462,10 +3209,20 @@ window.__ModuleLoader__.load({
3462
3209
  } catch (error) {
3463
3210
  S.balance = {
3464
3211
  ok: false,
3212
+ keyConfigured: S.apiKeyConfigured === true,
3465
3213
  error: String(error?.message ?? error)
3466
3214
  };
3467
3215
  setS({ balance: S.balance });
3468
3216
  }
3217
+ const failed = S.balance.ok === false;
3218
+ const keyPresent = S.balance.keyConfigured === true;
3219
+ if (failed && keyPresent && balanceRetries < 3) {
3220
+ balanceRetries++;
3221
+ balanceRetryTimer = setTimeout(() => {
3222
+ balanceRetryTimer = null;
3223
+ refreshBalance();
3224
+ }, balanceRetries === 1 ? 8e3 : 3e4);
3225
+ }
3469
3226
  }
3470
3227
  async function refreshUsageScan() {
3471
3228
  try {
@@ -3631,7 +3388,9 @@ window.__ModuleLoader__.load({
3631
3388
  title: "项目文件夹",
3632
3389
  onClick: () => setS({
3633
3390
  foldersOpen: !S.foldersOpen,
3634
- panelOpen: false
3391
+ panelOpen: false,
3392
+ promptOpen: null,
3393
+ balanceOpen: false
3635
3394
  })
3636
3395
  }, react.createElement(Icon, {
3637
3396
  n: "folder",
@@ -3645,7 +3404,9 @@ window.__ModuleLoader__.load({
3645
3404
  title: "个性化中心",
3646
3405
  onClick: () => setS({
3647
3406
  panelOpen: !S.panelOpen,
3648
- foldersOpen: false
3407
+ foldersOpen: false,
3408
+ promptOpen: null,
3409
+ balanceOpen: false
3649
3410
  })
3650
3411
  }, react.createElement(Icon, {
3651
3412
  n: "sliders",
@@ -3658,13 +3419,17 @@ window.__ModuleLoader__.load({
3658
3419
  className: "vx-header-btn",
3659
3420
  title: "快速调用提示词",
3660
3421
  onClick: (e) => {
3422
+ const open = S.promptOpen !== null;
3661
3423
  const r = e.currentTarget.getBoundingClientRect();
3662
3424
  setS({
3663
- promptOpen: {
3425
+ promptOpen: open ? null : {
3664
3426
  x: Math.max(8, r.left),
3665
3427
  y: r.bottom + 6
3666
3428
  },
3667
- promptQuery: ""
3429
+ promptQuery: "",
3430
+ panelOpen: false,
3431
+ foldersOpen: false,
3432
+ balanceOpen: false
3668
3433
  });
3669
3434
  }
3670
3435
  }, react.createElement(Icon, {
@@ -3684,7 +3449,7 @@ window.__ModuleLoader__.load({
3684
3449
  left: p.x,
3685
3450
  top: p.y
3686
3451
  }
3687
- }, react.createElement("div", { className: "vx-pattern" }), react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, "提示词库"), react.createElement("button", {
3452
+ }, react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, "提示词库"), react.createElement("button", {
3688
3453
  className: "vx-chip",
3689
3454
  title: "关闭",
3690
3455
  onClick: () => setS({ promptOpen: null })
@@ -3710,8 +3475,6 @@ window.__ModuleLoader__.load({
3710
3475
  useViewedSession(props);
3711
3476
  const s = useS();
3712
3477
  const b = s.balance;
3713
- const [hover, setHover] = react.useState(false);
3714
- const [pinned, setPinned] = react.useState(false);
3715
3478
  react.useEffect(() => {
3716
3479
  if (S.balance === null) refreshBalance();
3717
3480
  const timer = setInterval(() => {
@@ -3723,27 +3486,27 @@ window.__ModuleLoader__.load({
3723
3486
  }, []);
3724
3487
  const usageToday = s.usage[dayKey()] ?? {};
3725
3488
  const calls = Object.keys(usageToday).reduce((n, k) => n + (usageToday[k].calls ?? 0), 0);
3489
+ const estimate = Object.entries(usageToday).reduce((sum, [model, row]) => sum + estimateUsageCostCny(row, model), 0);
3726
3490
  const bal = b?.ok === true && b.balance !== null && b.balance !== void 0 ? b.balance : null;
3727
- const balance = bal !== null ? (bal.currency ?? "CNY") === "CNY" ? "¥" + (bal.total ?? "") : `${bal.total ?? ""} ${bal.currency ?? ""}` : b?.ok === false ? b.keyConfigured === true ? "额度?" : "未配置密钥" : "额度…";
3728
- const open = hover || pinned;
3729
- return react.createElement("span", {
3730
- className: "vx-balance-wrap",
3731
- onMouseEnter: () => setHover(true),
3732
- onMouseLeave: () => setHover(false)
3733
- }, react.createElement("span", {
3734
- className: "vx-balance-text" + (pinned ? " vx-balance-pinned" : ""),
3735
- title: pinned ? "再次点击取消固定" : "点击固定密钥面板",
3736
- onClick: () => setPinned(!pinned)
3491
+ const keyConfigured = b?.ok === false && b.keyConfigured === true;
3492
+ const balance = bal !== null ? (bal.currency ?? "CNY") === "CNY" ? "¥" + (bal.total ?? "") : `${bal.total ?? ""} ${bal.currency ?? ""}` : keyConfigured ? "额度" : b === null ? "额度…" : `≈¥${estimate.toFixed(2)}`;
3493
+ const estimateTitle = `按本机 token 用量与官方价目表折算的估算值(${DEEPSEEK_PRICING_CHECKED_ON} 核对),非账号账单;配置 API Key 后显示真实余额`;
3494
+ const balanceError = keyConfigured && b?.ok === false ? String(b.error ?? "未知错误") : null;
3495
+ const pillTitle = bal !== null ? void 0 : balanceError !== null ? `余额查询失败:${balanceError}(失败后会自动重试,也可在面板中手动刷新)` : b === null ? void 0 : estimateTitle;
3496
+ const open = s.balanceOpen === true;
3497
+ return react.createElement("span", { className: "vx-balance-wrap" }, react.createElement("span", {
3498
+ className: "vx-balance-text" + (open ? " vx-balance-open" : ""),
3499
+ title: open ? "再次点击收起面板" : "点击打开面板",
3500
+ onClick: () => setS({
3501
+ balanceOpen: !open,
3502
+ panelOpen: false,
3503
+ promptOpen: null,
3504
+ foldersOpen: false
3505
+ })
3737
3506
  }, react.createElement(Icon, {
3738
3507
  n: "wallet",
3739
3508
  size: 13
3740
- }), react.createElement("span", null, balance), calls > 0 ? react.createElement("span", { className: "vx-balance-today" }, `今日 ${calls} 次`) : null), open ? react.createElement("div", { className: "vx-glass vx-balance-hover" }, react.createElement("div", { className: "vx-pattern" }), pinned ? react.createElement("div", { className: "vx-balance-head" }, react.createElement("span", { className: "vx-muted" }, "已固定 · 再次点击「额度」或下方按钮取消"), react.createElement("button", {
3741
- className: "vx-btn vx-btn-sm",
3742
- onClick: () => setPinned(false)
3743
- }, react.createElement(Icon, {
3744
- n: "x",
3745
- size: 12
3746
- }), " 取消固定")) : null, react.createElement(BalancePanelContent, { onInteract: () => setPinned(true) })) : null);
3509
+ }), react.createElement("span", { title: pillTitle }, balance), calls > 0 ? react.createElement("span", { className: "vx-balance-today" }, `今日 ${calls} 次`) : null), open ? react.createElement("div", { className: "vx-glass vx-balance-hover" }, react.createElement(BalancePanelContent, null)) : null);
3747
3510
  }
3748
3511
  function UsageTable() {
3749
3512
  const day = useS().usage[dayKey()] ?? {};
@@ -3774,23 +3537,32 @@ window.__ModuleLoader__.load({
3774
3537
  }
3775
3538
  function UsageHistory() {
3776
3539
  const s = useS();
3777
- const keys = recentDayKeys(s.usageRange);
3778
- const selected = new Set(keys);
3779
- const summary = summarizeUsage(s.usage, selected);
3780
- const daily = keys.map((day) => ({
3781
- day,
3782
- ...summarizeUsage(s.usage, /* @__PURE__ */ new Set([day]))
3783
- }));
3784
- const maxTokens = Math.max(1, ...daily.map((row) => row.tokens));
3785
- const byModel = Object.create(null);
3786
- for (const day of keys) for (const [model, row] of Object.entries(s.usage[day] ?? {})) mergeUsageRow(byModel[model] ?? (byModel[model] = createUsageRow()), row);
3787
- const monthPrefix = dayKey().slice(0, 7) + "-";
3788
- const monthDays = new Set(Object.keys(s.usage).filter((day) => day.startsWith(monthPrefix)));
3789
- const month = summarizeUsage(s.usage, monthDays);
3540
+ const { summary, daily, maxTokens, byModel, month } = react.useMemo(() => {
3541
+ const keys = recentDayKeys(s.usageRange);
3542
+ const selected = new Set(keys);
3543
+ const summary = summarizeUsage(s.usage, selected);
3544
+ const daily = keys.map((day) => ({
3545
+ day,
3546
+ ...summarizeUsage(s.usage, /* @__PURE__ */ new Set([day]))
3547
+ }));
3548
+ const maxTokens = Math.max(1, ...daily.map((row) => row.tokens));
3549
+ const byModel = Object.create(null);
3550
+ for (const day of keys) for (const [model, row] of Object.entries(s.usage[day] ?? {})) mergeUsageRow(byModel[model] ?? (byModel[model] = createUsageRow()), row);
3551
+ const monthPrefix = dayKey().slice(0, 7) + "-";
3552
+ const monthDays = new Set(Object.keys(s.usage).filter((day) => day.startsWith(monthPrefix)));
3553
+ return {
3554
+ summary,
3555
+ daily,
3556
+ maxTokens,
3557
+ byModel,
3558
+ month: summarizeUsage(s.usage, monthDays)
3559
+ };
3560
+ }, [s.usage, s.usageRange]);
3790
3561
  const budget = Math.max(0, Number(s.cfg.monthlyBudgetCny ?? 0));
3791
3562
  const warning = Math.max(1, Math.min(100, Number(s.cfg.budgetWarningPercent ?? 80)));
3792
3563
  const ratio = budget > 0 && month.exact ? month.costCny / budget * 100 : 0;
3793
- const budgetText = budget <= 0 ? "预算提醒已关闭" : !month.exact ? "历史峰闲数据不完整,无法判断预算" : ratio >= 100 ? `已超出月预算(${ratio.toFixed(0)}%)` : ratio >= warning ? `已达到月预算 ${ratio.toFixed(0)}%` : `本月预算使用 ${ratio.toFixed(0)}%`;
3564
+ const state = budgetState(month, budget, warning);
3565
+ const budgetText = state === "disabled" ? "预算提醒已关闭" : state === "unknown" ? "历史峰闲数据不完整,无法判断预算" : state === "over" ? `已超出月预算(${ratio.toFixed(0)}%)` : state === "warning" ? `已达到月预算 ${ratio.toFixed(0)}%` : `本月预算使用 ${ratio.toFixed(0)}%`;
3794
3566
  return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-row wrap" }, [
3795
3567
  7,
3796
3568
  30,
@@ -3830,7 +3602,7 @@ window.__ModuleLoader__.load({
3830
3602
  } })))), Object.keys(byModel).length > 0 ? react.createElement("table", { className: "vx-table" }, react.createElement("thead", null, react.createElement("tr", null, react.createElement("th", null, "模型"), react.createElement("th", null, "Token"), react.createElement("th", null, "调用"), react.createElement("th", null, "费用 ¥"))), react.createElement("tbody", null, Object.entries(byModel).map(([model, row]) => {
3831
3603
  const cost = usageCostBreakdown(row, model);
3832
3604
  return react.createElement("tr", { key: model }, react.createElement("td", null, model), react.createElement("td", null, formatTokenCount(row.in + row.out + row.cacheIn + row.cacheW)), react.createElement("td", null, row.calls), react.createElement("td", null, cost.exact ? cost.totalCostCny.toFixed(4) : "—"));
3833
- }))) : null, react.createElement("div", { className: ratio >= 100 ? "vx-error" : "vx-muted" }, budgetText), react.createElement("div", { className: "vx-row wrap" }, react.createElement("label", { className: "vx-muted" }, "月预算 ¥ ", react.createElement("input", {
3605
+ }))) : null, react.createElement("div", { className: state === "over" ? "vx-error" : "vx-muted" }, budgetText), react.createElement("div", { className: "vx-row wrap" }, react.createElement("label", { className: "vx-muted" }, "月预算 ¥ ", react.createElement("input", {
3834
3606
  className: "vx-input",
3835
3607
  style: { width: 100 },
3836
3608
  type: "number",
@@ -3856,17 +3628,31 @@ window.__ModuleLoader__.load({
3856
3628
  onBlur: saveCfg
3857
3629
  }), " %")));
3858
3630
  }
3859
- function BalancePanelContent(props) {
3631
+ function BalancePanelContent() {
3860
3632
  const s = useS();
3861
3633
  const b = s.balance;
3862
- return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-row" }, react.createElement("input", {
3634
+ const configured = s.apiKeyConfigured === true;
3635
+ const [balanceOpen, setBalanceOpen] = react.useState(configured);
3636
+ const keyConfigured = b?.ok === false && b.keyConfigured === true;
3637
+ return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-muted" }, "以下用量与费用全部来自本机会话记录,不需要 API Key;费用为按官方价目表折算的估算值,可能与账号账单有差异。"), react.createElement("div", { className: "vx-section-title" }, "用量趋势与预算"), react.createElement(UsageHistory, null), react.createElement("div", { className: "vx-section-title" }, "今日模型明细"), react.createElement(UsageTable, null), react.createElement("button", {
3638
+ className: "vx-btn",
3639
+ onClick: () => {
3640
+ refreshUsageScan();
3641
+ }
3642
+ }, react.createElement(Icon, {
3643
+ n: "list",
3644
+ size: 13
3645
+ }), " 扫描今日会话日志更新用量"), react.createElement("div", { className: "vx-row" }, react.createElement("button", {
3646
+ className: "vx-chip",
3647
+ onClick: () => setBalanceOpen(!balanceOpen)
3648
+ }, react.createElement(Icon, {
3649
+ n: balanceOpen ? "chevronDown" : "chevronRight",
3650
+ size: 11
3651
+ }), balanceOpen ? " 收起余额查询" : " 余额查询(可选,需要 API Key)")), balanceOpen ? react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-row" }, react.createElement("input", {
3863
3652
  className: "vx-input",
3864
3653
  type: "password",
3865
- placeholder: s.apiKeyConfigured ? "已配置 Key;输入新 Key 覆盖" : "DeepSeek API Key (sk-…)",
3654
+ placeholder: configured ? "已配置 Key;输入新 Key 覆盖" : "DeepSeek API Key (sk-…)",
3866
3655
  value: s.apiKey,
3867
- onFocus: () => {
3868
- props.onInteract?.();
3869
- },
3870
3656
  onChange: (e) => {
3871
3657
  setS({
3872
3658
  apiKey: e.target.value,
@@ -3889,19 +3675,11 @@ window.__ModuleLoader__.load({
3889
3675
  }, react.createElement(Icon, {
3890
3676
  n: "refresh",
3891
3677
  size: 13
3892
- }), " 刷新")), react.createElement("div", { className: "vx-muted" }, `Key 不回传浏览器;当前来源:${s.credentialStorage === "system" ? "系统凭据" : s.credentialStorage === "legacy-state" ? "旧状态文件(待迁移)" : s.credentialStorage === "environment" ? "环境变量" : s.credentialStorage === "dsh" ? "DSH 凭据" : "未配置"}。留空后保存可清除插件自定义 Key。`), b !== null && b.ok === true && b.balance !== null && b.balance !== void 0 ? (() => {
3678
+ }), " 刷新")), react.createElement("div", { className: "vx-muted" }, configured ? `Key 不回传浏览器;当前来源:${s.credentialStorage === "system" ? "系统凭据" : s.credentialStorage === "legacy-state" ? "旧状态文件(待迁移)" : s.credentialStorage === "environment" ? "环境变量" : s.credentialStorage === "dsh" ? "DSH 凭据" : "未配置"}。留空后保存可清除插件自定义 Key。` : "填写 sk- 开头的 DeepSeek API Key 即可查询官方余额;Key 不回传浏览器,留空保存可清除已存 Key。"), b !== null && b.ok === true && b.balance !== null && b.balance !== void 0 ? (() => {
3893
3679
  const info = b.balance;
3894
3680
  const sym = (info.currency ?? "CNY") === "CNY" ? "¥" : `${info.currency ?? ""} `;
3895
3681
  return react.createElement("div", { className: "vx-balance-lines" }, react.createElement("div", null, `可用额度: ${sym}${info.total ?? ""}`), react.createElement("div", { className: "vx-muted" }, `赠送 ${sym}${info.granted ?? ""} · 充值 ${sym}${info.toppedUp ?? ""}${b.available === false ? " · 余额不足不可用" : ""}`));
3896
- })() : null, b !== null && b.ok === false ? react.createElement("div", { className: "vx-error" }, String(b.error ?? "未知错误")) : null, react.createElement("div", { className: "vx-section-title" }, "用量趋势与预算"), react.createElement(UsageHistory, null), react.createElement("div", { className: "vx-section-title" }, "今日模型明细"), react.createElement(UsageTable, null), react.createElement("button", {
3897
- className: "vx-btn",
3898
- onClick: () => {
3899
- refreshUsageScan();
3900
- }
3901
- }, react.createElement(Icon, {
3902
- n: "list",
3903
- size: 13
3904
- }), " 扫描今日会话日志更新用量"));
3682
+ })() : null, keyConfigured && b !== null && b.ok === false ? react.createElement("div", { className: "vx-error" }, String(b.error ?? "未知错误")) : null) : null);
3905
3683
  }
3906
3684
  function QuoteDock(props) {
3907
3685
  useViewedSession(props);
@@ -3960,11 +3738,14 @@ window.__ModuleLoader__.load({
3960
3738
  const node = sel.anchorNode;
3961
3739
  if (node !== null && node.nodeType === 1 && /TEXTAREA|INPUT/.test(node.nodeName)) return;
3962
3740
  const r = range.getBoundingClientRect();
3963
- setS({ quoteSel: {
3741
+ const next = {
3964
3742
  text: text.slice(0, 8e3),
3965
3743
  x: r.left + r.width / 2,
3966
3744
  y: r.top - 6
3967
- } });
3745
+ };
3746
+ const prev = S.quoteSel;
3747
+ if (prev !== null && prev.text === next.text && Math.abs(prev.x - next.x) < 1 && Math.abs(prev.y - next.y) < 1) return;
3748
+ setS({ quoteSel: next });
3968
3749
  } catch {}
3969
3750
  };
3970
3751
  d.addEventListener("selectionchange", onSel);
@@ -4004,7 +3785,7 @@ window.__ModuleLoader__.load({
4004
3785
  const turn = props.turn;
4005
3786
  const s = useS();
4006
3787
  let registered = null;
4007
- const item = seq !== null && s.turns !== null && s.turns.sessionId === S.sessionId ? s.turns.items.find((t) => t.seq === seq) ?? null : null;
3788
+ const item = seq !== null && s.turns !== null && s.turns.sessionId === S.sessionId ? s.turnsBySeq?.get(seq) ?? null : null;
4008
3789
  const btns = [];
4009
3790
  if (item !== null && s.cfg.formula === true) {
4010
3791
  if (item.hasLatex === true) btns.push(react.createElement("button", {
@@ -4052,177 +3833,6 @@ window.__ModuleLoader__.load({
4052
3833
  }
4053
3834
  }, btns.length > 0 ? react.createElement("span", { className: "vx-turn-actions" }, btns) : null);
4054
3835
  }
4055
- function RailPopover() {
4056
- const s = useS();
4057
- const h = s.railHover;
4058
- const popRef = react.useRef(null);
4059
- react.useLayoutEffect(() => {
4060
- const el = popRef.current;
4061
- if (el === null || h === null) return;
4062
- const rail = el.parentElement;
4063
- if (rail === null) return;
4064
- const base = Math.max(8, h.y - 90);
4065
- el.style.top = base + "px";
4066
- const over = el.offsetTop + el.offsetHeight - rail.clientHeight;
4067
- if (over > 0) el.style.top = Math.max(8, base - over) + "px";
4068
- }, [h?.seq, h?.y]);
4069
- if (h === null) return null;
4070
- const item = s.turns !== null && Array.isArray(s.turns.items) ? s.turns.items.find((x) => x.seq === h.seq) ?? null : null;
4071
- if (item === null) return null;
4072
- const starred = S.sessionId !== null && s.stars[S.sessionId]?.[h.seq] === true;
4073
- const side = s.cfg.timelineLeft === true ? "left" : "right";
4074
- return react.createElement("div", {
4075
- ref: (el) => {
4076
- popRef.current = el;
4077
- },
4078
- className: `vx-glass vx-rail-pop ${side}`,
4079
- style: { top: Math.max(8, h.y - 90) },
4080
- onMouseEnter: () => {
4081
- if (S.railHoverTimer !== null) {
4082
- clearTimeout(S.railHoverTimer);
4083
- S.railHoverTimer = null;
4084
- }
4085
- },
4086
- onMouseLeave: () => {
4087
- S.railHoverTimer = setTimeout(() => setS({ railHover: null }), 350);
4088
- }
4089
- }, react.createElement("div", { className: "vx-pattern" }), react.createElement("div", { className: "vx-pop-time" }, `${fmtClock(item.time)} · 第 ${item.turn ?? "?"} 轮${item.imageCount > 0 ? ` · ${item.imageCount} 张图片` : ""}`), react.createElement("div", { className: "vx-pop-text" }, item.text.slice(0, 220) + (item.text.length > 220 ? "…" : "")), react.createElement("div", { className: "vx-pop-row" }, react.createElement("button", {
4090
- className: "vx-chip",
4091
- onClick: () => scrollToSeq(h.seq)
4092
- }, react.createElement(Icon, {
4093
- n: "arrowDown",
4094
- size: 11
4095
- }), " 跳转"), react.createElement("button", {
4096
- className: "vx-chip",
4097
- onClick: () => toggleStar(h.seq)
4098
- }, react.createElement(Icon, {
4099
- n: "star",
4100
- size: 11,
4101
- filled: starred
4102
- }), starred ? " 已星标" : " 星标"), react.createElement("button", {
4103
- className: "vx-chip",
4104
- onClick: () => void forkAt(h.seq)
4105
- }, react.createElement(Icon, {
4106
- n: "fork",
4107
- size: 11
4108
- }), " 分支"), react.createElement("button", {
4109
- className: "vx-chip",
4110
- onClick: () => void copyText(item.text).then((ok) => toast(ok ? "已复制全文" : "复制失败", ok ? "info" : "error"))
4111
- }, react.createElement(Icon, {
4112
- n: "copy",
4113
- size: 11
4114
- }), " 全文")), item.hasLatex === true || item.hasMathml === true || item.hasMermaid === true ? react.createElement("div", { className: "vx-pop-row" }, item.hasLatex === true ? react.createElement("button", {
4115
- className: "vx-chip",
4116
- onClick: () => void copyLatexOf(item)
4117
- }, "LaTeX") : null, item.hasMathml === true ? react.createElement("button", {
4118
- className: "vx-chip",
4119
- onClick: () => void copyMathmlOf(item)
4120
- }, "MathML") : null, item.hasMermaid === true ? react.createElement("button", {
4121
- className: "vx-chip",
4122
- onClick: () => openMermaidOf(item)
4123
- }, "Mermaid") : null) : null);
4124
- }
4125
- function TimelineRail(props) {
4126
- const s = useS();
4127
- const sessions = useSessionsSafe(props);
4128
- const summary = sessions !== null && s.sessionId !== null ? sessions.byId[s.sessionId] : null;
4129
- const trackRef = react.useRef(null);
4130
- react.useEffect(() => {
4131
- if (s.cfg.timeline !== true || S.sessionId === null) return;
4132
- const running = summary?.running === true;
4133
- const handle = setInterval(() => {
4134
- if (running) fetchTurns(S.sessionId);
4135
- }, 3e3);
4136
- return () => clearInterval(handle);
4137
- }, [
4138
- s.cfg.timeline,
4139
- s.sessionId,
4140
- summary?.running
4141
- ]);
4142
- react.useEffect(() => {
4143
- if (s.cfg.timeline !== true || S.sessionId === null) return;
4144
- const el = trackRef.current;
4145
- if (el === null) return;
4146
- const fromPopover = (e) => e.target instanceof Element && e.target.closest(".vx-rail-pop") !== null;
4147
- const down = (e) => {
4148
- const scroller = S.scrollerEl;
4149
- if (scroller === null || !scroller.isConnected) return;
4150
- if (fromPopover(e)) return;
4151
- e.preventDefault();
4152
- const rect = el.getBoundingClientRect();
4153
- const startY = e.clientY;
4154
- const startScroll = scroller.scrollTop ?? 0;
4155
- const scrollH = Math.max(1, (scroller.scrollHeight ?? 1) - (scroller.clientHeight ?? rect.height));
4156
- const onMove = (ev) => {
4157
- const delta = (ev.clientY - startY) / Math.max(1, rect.height) * scrollH;
4158
- scroller.scrollTop = Math.max(0, Math.min(scrollH, startScroll + delta));
4159
- };
4160
- const onUp = () => {
4161
- const w = typeof window !== "undefined" ? window : null;
4162
- if (w !== null) {
4163
- w.removeEventListener("pointermove", onMove);
4164
- w.removeEventListener("pointerup", onUp);
4165
- }
4166
- };
4167
- const w = typeof window !== "undefined" ? window : null;
4168
- if (w !== null) {
4169
- w.addEventListener("pointermove", onMove);
4170
- w.addEventListener("pointerup", onUp);
4171
- }
4172
- };
4173
- el.addEventListener("pointerdown", down);
4174
- const onWheel = (e) => {
4175
- const scroller = S.scrollerEl;
4176
- if (scroller === null || !scroller.isConnected) return;
4177
- if (fromPopover(e)) return;
4178
- e.preventDefault();
4179
- const floor = Math.max(0, (scroller.scrollHeight ?? 1) - (scroller.clientHeight ?? 0));
4180
- scroller.scrollTop = Math.max(0, Math.min(floor, (scroller.scrollTop ?? 0) + (e.deltaY || 0)));
4181
- };
4182
- el.addEventListener("wheel", onWheel, { passive: false });
4183
- return () => {
4184
- el.removeEventListener("pointerdown", down);
4185
- el.removeEventListener("wheel", onWheel);
4186
- };
4187
- }, [
4188
- s.cfg.timeline,
4189
- s.sessionId,
4190
- s.scrollerEl
4191
- ]);
4192
- if (s.cfg.timeline !== true || S.sessionId === null) return null;
4193
- const right = s.cfg.timelineLeft !== true;
4194
- const dots = s.railPositions.filter((p) => s.cfg.starsOnly !== true || p.st);
4195
- return react.createElement("div", {
4196
- ref: trackRef,
4197
- className: `vx-rail ${right ? "right" : "left"}`,
4198
- style: {
4199
- top: s.railBox.top,
4200
- height: s.railBox.height,
4201
- ...right ? { right: s.railRight } : { left: s.railLeft }
4202
- }
4203
- }, react.createElement("div", {
4204
- className: "vx-thumb",
4205
- style: {
4206
- top: s.thumbTop,
4207
- height: s.thumbH
4208
- }
4209
- }), dots.map((p) => react.createElement("button", {
4210
- key: p.seq,
4211
- className: "vx-dot" + (p.st ? " star" : ""),
4212
- style: { top: p.y },
4213
- onMouseEnter: () => {
4214
- if (S.railHoverTimer !== null) clearTimeout(S.railHoverTimer);
4215
- setS({ railHover: {
4216
- seq: p.seq,
4217
- y: p.y
4218
- } });
4219
- },
4220
- onMouseLeave: () => {
4221
- S.railHoverTimer = setTimeout(() => setS({ railHover: null }), 350);
4222
- },
4223
- onClick: () => scrollToSeq(p.seq)
4224
- })), react.createElement(RailPopover, null));
4225
- }
4226
3836
  function AppearanceTab() {
4227
3837
  const s = useS();
4228
3838
  const dark = s.dark === true;
@@ -4233,7 +3843,7 @@ window.__ModuleLoader__.load({
4233
3843
  } });
4234
3844
  saveCfg();
4235
3845
  };
4236
- return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-muted" }, "主题背景、天气特效与玻璃质感,选择后即时生效。"), react.createElement("div", { className: "vx-section-title" }, "背景颜色"), react.createElement("div", { className: "vx-muted" }, "20 组低饱和色板;深色模式下仅可用「无颜色」与「极光」。"), react.createElement("div", { className: "vx-swatches" }, react.createElement("button", {
3846
+ return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-muted" }, "主题背景、天气特效与玻璃质感,选择后即时生效。"), react.createElement("div", { className: "vx-section-title" }, "背景颜色"), react.createElement("div", { className: "vx-muted" }, "20 组低饱和色板,深浅色模式均可用;深色下自动使用同色系的深色变体(预览即实际效果)。"), react.createElement("div", { className: "vx-swatches" }, react.createElement("button", {
4237
3847
  key: "default",
4238
3848
  className: "vx-swatch" + (s.cfg.bg === "default" ? " on" : ""),
4239
3849
  onClick: () => set("bg", "default"),
@@ -4241,24 +3851,18 @@ window.__ModuleLoader__.load({
4241
3851
  }, react.createElement("span", {
4242
3852
  className: "vx-swatch-box",
4243
3853
  style: { background: "repeating-conic-gradient(#ccc 0 25%, #eee 0 50%) 0 0/10px 10px" }
4244
- }), react.createElement("span", { className: "vx-swatch-label" }, "无颜色")), react.createElement("button", {
4245
- key: "aurora",
4246
- className: "vx-swatch" + (s.cfg.bg === "aurora" ? " on" : ""),
4247
- onClick: () => set("bg", "aurora"),
4248
- title: "极光渐变(保留高饱和)"
4249
- }, react.createElement("span", {
4250
- className: "vx-swatch-box",
4251
- style: { background: "linear-gradient(135deg,#8fa8d8,#b59fd8,#8fc4b4,#d8a8c0)" }
4252
- }), react.createElement("span", { className: "vx-swatch-label" }, "极光")), PALETTE.map((p) => react.createElement("button", {
4253
- key: p[0],
4254
- disabled: dark,
4255
- className: "vx-swatch" + (s.cfg.bg === p[0] ? " on" : ""),
4256
- onClick: () => set("bg", p[0]),
4257
- title: p[0] + " " + p[1] + (dark ? "(深色模式禁用)" : "")
4258
- }, react.createElement("span", {
4259
- className: "vx-swatch-box",
4260
- style: { background: p[1] }
4261
- }), react.createElement("span", { className: "vx-swatch-label" }, p[0])))), react.createElement("div", { className: "vx-section-title" }, "天气特效"), react.createElement("div", { className: "vx-row wrap" }, [
3854
+ }), react.createElement("span", { className: "vx-swatch-label" }, "无颜色")), PALETTE.map((p) => {
3855
+ const preview = dark ? toDarkRamp(p[1], DARK_CANVAS_LIGHTNESS) : p[1];
3856
+ return react.createElement("button", {
3857
+ key: p[0],
3858
+ className: "vx-swatch" + (s.cfg.bg === p[0] ? " on" : ""),
3859
+ onClick: () => set("bg", p[0]),
3860
+ title: p[0] + " " + p[1]
3861
+ }, react.createElement("span", {
3862
+ className: "vx-swatch-box",
3863
+ style: { background: preview }
3864
+ }), react.createElement("span", { className: "vx-swatch-label" }, p[0]));
3865
+ })), react.createElement("div", { className: "vx-section-title" }, "天气特效"), react.createElement("div", { className: "vx-row wrap" }, [
4262
3866
  "none",
4263
3867
  "snow",
4264
3868
  "rain",
@@ -4292,11 +3896,11 @@ window.__ModuleLoader__.load({
4292
3896
  }, "毛玻璃"), react.createElement("button", {
4293
3897
  className: "vx-btn" + (s.cfg.glassMode === "liquid" ? " on" : ""),
4294
3898
  onClick: () => set("glassMode", "liquid")
4295
- }, "液态玻璃")), react.createElement("div", { className: "vx-muted" }, "在 Chromium 启用液态玻璃,Safari/Firefox 自动回退毛玻璃。"), react.createElement(Toggle, {
3899
+ }, "液态玻璃")), react.createElement(Toggle, {
4296
3900
  label: "全局浮层玻璃",
4297
3901
  checked: s.cfg.globalGlass === true,
4298
3902
  onChange: (v) => set("globalGlass", v),
4299
- hint: "对弹窗/菜单等浮层应用模糊,不改变圆角与边框"
3903
+ hint: "对弹窗/菜单等浮层应用玻璃质感;液态玻璃模式下浮层同样位移折射"
4300
3904
  }));
4301
3905
  }
4302
3906
  function FolderNode(props) {
@@ -4776,29 +4380,6 @@ window.__ModuleLoader__.load({
4776
4380
  }
4777
4381
  }))));
4778
4382
  }
4779
- function TimelineTab() {
4780
- const s = useS();
4781
- const set = (k, v) => {
4782
- setS({ cfg: {
4783
- ...s.cfg,
4784
- [k]: v
4785
- } });
4786
- saveCfg();
4787
- };
4788
- return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-muted" }, "为每条用户消息生成导航节点:悬停预览、点击跳转,支持星标与分支。"), react.createElement(Toggle, {
4789
- label: "显示时间线",
4790
- checked: s.cfg.timeline === true,
4791
- onChange: (v) => set("timeline", v)
4792
- }), react.createElement(Toggle, {
4793
- label: "时间线在左侧",
4794
- checked: s.cfg.timelineLeft === true,
4795
- onChange: (v) => set("timelineLeft", v)
4796
- }), react.createElement(Toggle, {
4797
- label: "仅显示星标",
4798
- checked: s.cfg.starsOnly === true,
4799
- onChange: (v) => set("starsOnly", v)
4800
- }));
4801
- }
4802
4383
  function BackupControls() {
4803
4384
  const [mode, setMode] = react.useState("merge");
4804
4385
  const exportBackup = async () => {
@@ -4883,7 +4464,7 @@ window.__ModuleLoader__.load({
4883
4464
  toast("目标会话不可用", "error");
4884
4465
  return;
4885
4466
  }
4886
- const rendered = () => S.seqAnchor.get(item.anchorSeq) !== void 0 || S.anchors.get(item.anchorSeq)?.el !== void 0;
4467
+ const rendered = () => S.anchors.get(item.anchorSeq)?.el !== void 0;
4887
4468
  for (let page = 0; !rendered() && face.getSnapshot().hasMore && page < 20; page++) {
4888
4469
  if (S.sessionId !== expectedSessionId) {
4889
4470
  toast("会话已切换,搜索结果已失效", "error");
@@ -4891,7 +4472,6 @@ window.__ModuleLoader__.load({
4891
4472
  }
4892
4473
  await face.loadOlder();
4893
4474
  await new Promise((resolve) => setTimeout(resolve, 60));
4894
- updateRailPositions();
4895
4475
  }
4896
4476
  if (S.sessionId !== expectedSessionId) {
4897
4477
  toast("会话已切换,搜索结果已失效", "error");
@@ -5104,7 +4684,7 @@ window.__ModuleLoader__.load({
5104
4684
  react.useEffect(() => {
5105
4685
  loadInfo();
5106
4686
  }, []);
5107
- return react.createElement("div", { className: "vx-col vx-pad" }, react.createElement("div", null, "Custom 便利套件"), react.createElement("div", { className: "vx-muted" }, "外观与天气特效 · 时间线导航 · 项目文件夹 · 提示词 · 会话导出 · Mermaid 渲染 · 额度面板"), info !== null && info.ok === true ? react.createElement("pre", { className: "vx-pre" }, `状态文件: ${String(info.statePath ?? "")}\n今日: ${String(info.today ?? "")}\nMermaid: ${String(info.mermaidBytes ?? 0)} bytes\n今日用量: ${JSON.stringify(info.usageToday ?? {})}\n客户端诊断: ${Array.isArray(info.diagReports) ? `${String(info.diagReports.length)} 条` : "0 条"}`) : null, react.createElement("button", {
4687
+ return react.createElement("div", { className: "vx-col vx-pad" }, react.createElement("div", null, "Custom 便利套件"), react.createElement("div", { className: "vx-muted" }, "外观与天气特效 · 项目文件夹 · 提示词 · 会话导出 · Mermaid 渲染 · 额度面板"), info !== null && info.ok === true ? react.createElement("pre", { className: "vx-pre" }, `状态文件: ${String(info.statePath ?? "")}\n今日: ${String(info.today ?? "")}\nMermaid: ${String(info.mermaidBytes ?? 0)} bytes\n今日用量: ${JSON.stringify(info.usageToday ?? {})}\n客户端诊断: ${Array.isArray(info.diagReports) ? `${String(info.diagReports.length)} 条` : "0 条"}`) : null, react.createElement("button", {
5108
4688
  className: "vx-btn",
5109
4689
  onClick: () => void loadInfo()
5110
4690
  }, react.createElement(Icon, {
@@ -5132,7 +4712,7 @@ window.__ModuleLoader__.load({
5132
4712
  className: "vx-glass vx-modal",
5133
4713
  style: { width: "min(360px, 92vw)" },
5134
4714
  onClick: (e) => e.stopPropagation()
5135
- }, react.createElement("div", { className: "vx-pattern" }), react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, ask.title)), react.createElement("input", {
4715
+ }, react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, ask.title)), react.createElement("input", {
5136
4716
  className: "vx-input",
5137
4717
  value: val,
5138
4718
  autoFocus: true,
@@ -5164,7 +4744,7 @@ window.__ModuleLoader__.load({
5164
4744
  className: "vx-glass vx-modal",
5165
4745
  style: { width: "min(380px, 92vw)" },
5166
4746
  onClick: (e) => e.stopPropagation()
5167
- }, react.createElement("div", { className: "vx-pattern" }), react.createElement("div", { className: "vx-pad" }, c.message), react.createElement("div", { className: "vx-row vx-pad-sm" }, react.createElement("button", {
4747
+ }, react.createElement("div", { className: "vx-pad" }, c.message), react.createElement("div", { className: "vx-row vx-pad-sm" }, react.createElement("button", {
5168
4748
  className: "vx-btn vx-btn-danger",
5169
4749
  onClick: () => answer(true)
5170
4750
  }, "确定"), react.createElement("button", {
@@ -5210,7 +4790,7 @@ window.__ModuleLoader__.load({
5210
4790
  className: "vx-glass vx-modal",
5211
4791
  style: { width: "min(440px, 92vw)" },
5212
4792
  onClick: (e) => e.stopPropagation()
5213
- }, react.createElement("div", { className: "vx-pattern" }), react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, `填写变量 · ${prompt.name}`)), names.map((name) => react.createElement("label", {
4793
+ }, react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, `填写变量 · ${prompt.name}`)), names.map((name) => react.createElement("label", {
5214
4794
  key: name,
5215
4795
  className: "vx-col"
5216
4796
  }, react.createElement("span", { className: "vx-muted" }, name), react.createElement("input", {
@@ -5312,7 +4892,7 @@ window.__ModuleLoader__.load({
5312
4892
  }, react.createElement("div", {
5313
4893
  className: "vx-glass vx-modal",
5314
4894
  onClick: (e) => e.stopPropagation()
5315
- }, react.createElement("div", { className: "vx-pattern" }), react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, `${mm.title} (${mm.index + 1}/${mm.codes.length})`), react.createElement("span", { className: "vx-row" }, mm.codes.length > 1 ? react.createElement("button", {
4895
+ }, react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, `${mm.title} (${mm.index + 1}/${mm.codes.length})`), react.createElement("span", { className: "vx-row" }, mm.codes.length > 1 ? react.createElement("button", {
5316
4896
  className: "vx-chip",
5317
4897
  title: "上一个",
5318
4898
  onClick: () => setS({ mermaidModal: {
@@ -5424,21 +5004,6 @@ window.__ModuleLoader__.load({
5424
5004
  runExport("markdown");
5425
5005
  }
5426
5006
  },
5427
- {
5428
- key: "timeline",
5429
- label: `${S.cfg.timeline ? "关闭" : "开启"}时间线`,
5430
- detail: "功能开关",
5431
- run: () => {
5432
- setS({
5433
- commandOpen: false,
5434
- cfg: {
5435
- ...S.cfg,
5436
- timeline: !S.cfg.timeline
5437
- }
5438
- });
5439
- saveCfg();
5440
- }
5441
- },
5442
5007
  {
5443
5008
  key: "search-current",
5444
5009
  label: "搜索当前会话",
@@ -5609,7 +5174,7 @@ window.__ModuleLoader__.load({
5609
5174
  className: "vx-glass vx-modal",
5610
5175
  style: { width: "min(560px, 92vw)" },
5611
5176
  onClick: (e) => e.stopPropagation()
5612
- }, react.createElement("div", { className: "vx-pattern" }), react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, "批量归档会话"), react.createElement("button", {
5177
+ }, react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, "批量归档会话"), react.createElement("button", {
5613
5178
  className: "vx-chip",
5614
5179
  title: "关闭",
5615
5180
  onClick: () => setS({ batchModal: false })
@@ -5673,7 +5238,6 @@ window.__ModuleLoader__.load({
5673
5238
  useWorkspaces: props.useWorkspaces
5674
5239
  });
5675
5240
  if (s.panelTab === "prompt") return react.createElement(PromptsTab, null);
5676
- if (s.panelTab === "timeline") return react.createElement(TimelineTab, null);
5677
5241
  if (s.panelTab === "search") return react.createElement(SearchTab, null);
5678
5242
  if (s.panelTab === "export") return react.createElement(ExportTab, null);
5679
5243
  if (s.panelTab === "mermaid") return react.createElement(MermaidTab, null);
@@ -5700,11 +5264,6 @@ window.__ModuleLoader__.load({
5700
5264
  "zap",
5701
5265
  "提示词"
5702
5266
  ],
5703
- [
5704
- "timeline",
5705
- "clock",
5706
- "时间线"
5707
- ],
5708
5267
  [
5709
5268
  "search",
5710
5269
  "search",
@@ -5750,13 +5309,20 @@ window.__ModuleLoader__.load({
5750
5309
  };
5751
5310
  const d = typeof document !== "undefined" ? document : null;
5752
5311
  if (d === null) return;
5753
- const move = (ev) => setS({ panelPos: {
5754
- x: start.x + ev.clientX - start.mx,
5755
- y: start.y + ev.clientY - start.my
5756
- } });
5312
+ let final = null;
5313
+ const move = (ev) => {
5314
+ final = {
5315
+ x: start.x + ev.clientX - start.mx,
5316
+ y: start.y + ev.clientY - start.my
5317
+ };
5318
+ el.style.left = `${final.x}px`;
5319
+ el.style.top = `${final.y}px`;
5320
+ el.style.right = "auto";
5321
+ };
5757
5322
  const up = () => {
5758
5323
  d.removeEventListener("mousemove", move);
5759
5324
  d.removeEventListener("mouseup", up);
5325
+ if (final !== null) setS({ panelPos: final });
5760
5326
  };
5761
5327
  d.addEventListener("mousemove", move);
5762
5328
  d.addEventListener("mouseup", up);
@@ -5775,7 +5341,7 @@ window.__ModuleLoader__.load({
5775
5341
  ref,
5776
5342
  className: "vx-glass vx-panel",
5777
5343
  style
5778
- }, react.createElement("div", { className: "vx-pattern" }), react.createElement("div", {
5344
+ }, react.createElement("div", {
5779
5345
  className: "vx-panel-head",
5780
5346
  onMouseDown: onHeadDown
5781
5347
  }, react.createElement(Icon, {
@@ -5802,7 +5368,7 @@ window.__ModuleLoader__.load({
5802
5368
  }
5803
5369
  function SidebarFoldersPanel(props) {
5804
5370
  if (useS().foldersOpen !== true) return null;
5805
- return react.createElement("div", { className: "vx-glass vx-folders" }, react.createElement("div", { className: "vx-pattern" }), react.createElement("div", { className: "vx-pop-head" }, react.createElement(Icon, {
5371
+ return react.createElement("div", { className: "vx-glass vx-folders" }, react.createElement("div", { className: "vx-pop-head" }, react.createElement(Icon, {
5806
5372
  n: "folder",
5807
5373
  size: 14
5808
5374
  }), react.createElement("span", null, "项目文件夹"), react.createElement("span", { className: "vx-flex1" }), react.createElement("button", {
@@ -5839,7 +5405,7 @@ window.__ModuleLoader__.load({
5839
5405
  }))));
5840
5406
  }
5841
5407
  function SettingsPage() {
5842
- return react.createElement("div", { className: "vx-settings-page" }, react.createElement(AppearanceTab, null), react.createElement("div", { className: "vx-section-title" }, "功能开关"), react.createElement(TimelineTab, null), react.createElement(ToolsTab, null), react.createElement(MermaidTab, null));
5408
+ return react.createElement("div", { className: "vx-settings-page" }, react.createElement(AppearanceTab, null), react.createElement("div", { className: "vx-section-title" }, "功能开关"), react.createElement(ToolsTab, null), react.createElement(MermaidTab, null));
5843
5409
  }
5844
5410
  function Toasts() {
5845
5411
  const s = useS();
@@ -5900,7 +5466,8 @@ window.__ModuleLoader__.load({
5900
5466
  s.cfg.bg,
5901
5467
  s.cfg.glass,
5902
5468
  s.cfg.glassMode,
5903
- s.cfg.globalGlass
5469
+ s.cfg.globalGlass,
5470
+ s.dark
5904
5471
  ]);
5905
5472
  react.useEffect(() => {
5906
5473
  syncAntiScroll(s.cfg.antiScroll === true);
@@ -5910,13 +5477,6 @@ window.__ModuleLoader__.load({
5910
5477
  const d = typeof document !== "undefined" ? document : null;
5911
5478
  const applyDark = (dark) => {
5912
5479
  S.dark = dark;
5913
- if (dark && S.booted && S.cfg.bg !== "default" && S.cfg.bg !== "aurora") {
5914
- S.cfg = {
5915
- ...S.cfg,
5916
- bg: "default"
5917
- };
5918
- saveCfg();
5919
- }
5920
5480
  setS({ dark });
5921
5481
  };
5922
5482
  applyDark(readDark());
@@ -5954,67 +5514,26 @@ window.__ModuleLoader__.load({
5954
5514
  react.useEffect(() => {
5955
5515
  const dark = readDark();
5956
5516
  S.dark = dark;
5957
- if (dark && S.booted && S.cfg.bg !== "default" && S.cfg.bg !== "aurora") {
5958
- S.cfg = {
5959
- ...S.cfg,
5960
- bg: "default"
5961
- };
5962
- setS({ cfg: S.cfg });
5963
- saveCfg();
5964
- } else setS({ dark });
5517
+ setS({ dark });
5965
5518
  }, [s.booted]);
5966
5519
  react.useEffect(() => {
5967
- const tick = () => {
5968
- const d = typeof document !== "undefined" ? document : null;
5969
- if (d !== null && d.visibilityState === "hidden") return;
5970
- updateRailPositions();
5971
- };
5972
- const stop = setInterval(tick, 450);
5973
5520
  const d = typeof document !== "undefined" ? document : null;
5974
- const w = typeof window !== "undefined" ? window : null;
5975
- const h = () => tick();
5976
- if (d !== null) {
5977
- d.addEventListener("scroll", h, true);
5978
- d.addEventListener("visibilitychange", h);
5979
- }
5980
- if (w !== null) w.addEventListener("resize", h);
5981
- return () => {
5982
- clearInterval(stop);
5983
- if (d !== null) {
5984
- d.removeEventListener("scroll", h, true);
5985
- d.removeEventListener("visibilitychange", h);
5986
- }
5987
- if (w !== null) w.removeEventListener("resize", h);
5988
- };
5989
- }, []);
5521
+ if (d === null) return;
5522
+ d.documentElement.classList.toggle("vx-dark", s.dark === true);
5523
+ d.documentElement.classList.toggle("vx-light", s.dark !== true);
5524
+ }, [s.dark]);
5525
+ const sessions = useSessionsSafe(props);
5526
+ const summary = sessions !== null && s.sessionId !== null ? sessions.byId[s.sessionId] : null;
5990
5527
  react.useEffect(() => {
5991
- const w = typeof window !== "undefined" ? window : null;
5992
- if (w === null || w.MutationObserver === void 0) return;
5993
- const scroller = s.scrollerEl;
5994
- if (scroller === null || !scroller.isConnected) return;
5995
- let timer = null;
5996
- const observer = new MutationObserver(() => {
5997
- if (timer !== null) clearTimeout(timer);
5998
- timer = setTimeout(() => {
5999
- updateRailPositions();
6000
- }, 120);
6001
- });
6002
- observer.observe(scroller, {
6003
- childList: true,
6004
- subtree: true
6005
- });
6006
- return () => {
6007
- observer.disconnect();
6008
- if (timer !== null) clearTimeout(timer);
6009
- };
6010
- }, [s.scrollerEl]);
5528
+ if (S.sessionId === null) return;
5529
+ const running = summary?.running === true;
5530
+ const handle = setInterval(() => {
5531
+ if (running && S.sessionId !== null) fetchTurns(S.sessionId);
5532
+ }, 3e3);
5533
+ return () => clearInterval(handle);
5534
+ }, [s.sessionId, summary?.running]);
6011
5535
  const children = [react.createElement(FxCanvas, { key: "fx" })];
6012
5536
  children.push(react.createElement(MermaidInPlace, { key: "mmd" }));
6013
- children.push(react.createElement(TimelineRail, {
6014
- key: "rail",
6015
- useSessions: props.useSessions,
6016
- useWorkspaces: props.useWorkspaces
6017
- }));
6018
5537
  if (s.panelOpen === true) children.push(react.createElement(PersonalizePanel, {
6019
5538
  key: "panel",
6020
5539
  useSessions: props.useSessions,
@@ -6126,6 +5645,29 @@ window.__ModuleLoader__.load({
6126
5645
  for (const unregister of unregisterAll.splice(0)) try {
6127
5646
  unregister();
6128
5647
  } catch {}
5648
+ if (tokenDisposer !== null) {
5649
+ try {
5650
+ tokenDisposer();
5651
+ } catch {}
5652
+ tokenDisposer = null;
5653
+ }
5654
+ if (balanceRetryTimer !== null) {
5655
+ clearTimeout(balanceRetryTimer);
5656
+ balanceRetryTimer = null;
5657
+ }
5658
+ const d = typeof document !== "undefined" ? document : null;
5659
+ if (d !== null) {
5660
+ for (const cls of [
5661
+ "vx-liquid",
5662
+ "vx-dark",
5663
+ "vx-light"
5664
+ ]) try {
5665
+ d.documentElement.classList.remove(cls);
5666
+ } catch {}
5667
+ try {
5668
+ d.getElementById("vx-lg-filter")?.remove();
5669
+ } catch {}
5670
+ }
6129
5671
  removeDynCss();
6130
5672
  };
6131
5673
  }