@alexpeng/dsh-custom-plugin 0.1.0

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 ADDED
@@ -0,0 +1,4570 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "@alexpeng/dsh-custom-plugin",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ //#region \0rolldown/runtime.js
8
+ var __create = Object.create;
9
+ var __defProp = Object.defineProperty;
10
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
11
+ var __getOwnPropNames = Object.getOwnPropertyNames;
12
+ var __getProtoOf = Object.getPrototypeOf;
13
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
16
+ key = keys[i];
17
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
18
+ get: ((k) => from[k]).bind(null, key),
19
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
20
+ });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
25
+ value: mod,
26
+ enumerable: true
27
+ }) : target, mod));
28
+ //#endregion
29
+ let react = require("react");
30
+ react = __toESM(react, 1);
31
+ //#region src/protocol.ts
32
+ /**
33
+ * Wire protocol shared by the host routes and the browser transport.
34
+ *
35
+ * The browser talks to the host through plain same-origin fetch against
36
+ * {@link CUSTOM_PLUGIN_API_PREFIX}; every handler answers with the `{ ok }`
37
+ * envelope below so the client can surface host errors without coupling to
38
+ * route details. Types here are the JSON currency only — no Cordis or React
39
+ * objects cross this boundary.
40
+ * @module @alexpeng/dsh-custom-plugin/protocol
41
+ */
42
+ /** Prefix of every host route this plugin registers. */
43
+ const CUSTOM_PLUGIN_API_PREFIX = "/api/custom-plugin";
44
+ /** Path the host serves the fetched Mermaid engine at (script src). */
45
+ const MERMAID_SCRIPT_PATH = "/custom-plugin/mermaid.js";
46
+ //#endregion
47
+ //#region src/client/api.ts
48
+ /**
49
+ * Browser transport for dsh-custom-plugin: plain same-origin fetch against
50
+ * the host routes. Every call returns the `{ ok }` envelope the host writes;
51
+ * failures surface as `{ ok: false, error }` instead of throwing.
52
+ * @module @alexpeng/dsh-custom-plugin/client/api
53
+ */
54
+ const REQUEST_TIMEOUT_MS = 2e4;
55
+ async function request(path, init) {
56
+ const controller = new AbortController();
57
+ const timer = globalThis.setTimeout(() => {
58
+ controller.abort();
59
+ }, REQUEST_TIMEOUT_MS);
60
+ try {
61
+ const response = await fetch(`${CUSTOM_PLUGIN_API_PREFIX}${path}`, {
62
+ ...init,
63
+ signal: controller.signal
64
+ });
65
+ try {
66
+ return await response.json();
67
+ } catch {
68
+ return {
69
+ ok: false,
70
+ error: `HTTP ${String(response.status)} 非 JSON 响应`
71
+ };
72
+ }
73
+ } catch (error) {
74
+ return {
75
+ ok: false,
76
+ error: String(error?.message ?? error)
77
+ };
78
+ } finally {
79
+ globalThis.clearTimeout(timer);
80
+ }
81
+ }
82
+ function postJson(path, body) {
83
+ return request(path, {
84
+ method: "POST",
85
+ headers: { "content-type": "application/json" },
86
+ body: JSON.stringify(body)
87
+ });
88
+ }
89
+ /** Read the whole state document. */
90
+ async function apiStateGet() {
91
+ return await request("/state", { cache: "no-store" });
92
+ }
93
+ /** Persist a state edit. */
94
+ async function apiStateSave(edit) {
95
+ return await postJson("/state", edit);
96
+ }
97
+ /** Timeline nodes for one session. */
98
+ async function apiTimelineGet(sessionId, afterSeq = 0) {
99
+ return await request(`/timeline?sessionId=${encodeURIComponent(sessionId)}&afterSeq=${afterSeq}`, { cache: "no-store" });
100
+ }
101
+ /** Export one session in the given format. */
102
+ async function apiExportRun(sessionId, format) {
103
+ return await postJson("/export", {
104
+ sessionId,
105
+ format
106
+ });
107
+ }
108
+ /** DeepSeek balance. */
109
+ async function apiBalanceGet() {
110
+ return await request("/balance", { cache: "no-store" });
111
+ }
112
+ /** Re-scan today's session logs for usage. */
113
+ async function apiUsageScan() {
114
+ return await postJson("/usage-scan", {});
115
+ }
116
+ /** Fetch the Mermaid engine into the host cache. */
117
+ async function apiMermaidFetch() {
118
+ return await postJson("/mermaid", {});
119
+ }
120
+ /** Best-effort diagnostics report. */
121
+ function apiDiagReport(message) {
122
+ postJson("/diag", { msg: String(message).slice(0, 400) }).catch(() => {});
123
+ }
124
+ /** Host diagnostics for the About tab. */
125
+ async function apiDebugInfo() {
126
+ try {
127
+ return await request("/debug", { cache: "no-store" });
128
+ } catch {
129
+ return { ok: false };
130
+ }
131
+ }
132
+ //#endregion
133
+ //#region src/client/mermaid-url.ts
134
+ function bytesToBase64Url(bytes) {
135
+ let bin = "";
136
+ for (const byte of bytes) bin += String.fromCharCode(byte);
137
+ return btoa(bin).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
138
+ }
139
+ async function deflateZlibBase64Url(text) {
140
+ const Ctor = globalThis.CompressionStream;
141
+ if (typeof Ctor !== "function") return null;
142
+ try {
143
+ const stream = new Ctor("deflate");
144
+ const writer = stream.writable.getWriter();
145
+ writer.write(new TextEncoder().encode(text));
146
+ writer.close();
147
+ return bytesToBase64Url(new Uint8Array(await new Response(stream.readable).arrayBuffer()));
148
+ } catch {
149
+ return null;
150
+ }
151
+ }
152
+ /** Build the `https://mermaid.live/edit#pako:…` share link for one diagram. */
153
+ async function mermaidLiveUrl(code) {
154
+ const state = JSON.stringify({
155
+ code,
156
+ mermaid: { theme: "default" }
157
+ });
158
+ return "https://mermaid.live/edit#pako:" + (await deflateZlibBase64Url(state) ?? bytesToBase64Url(new TextEncoder().encode(state)));
159
+ }
160
+ //#endregion
161
+ //#region src/client/styles.ts
162
+ /**
163
+ * Static styles for the Custom suite, injected as one owned <style> tag at
164
+ * install time (removed by the disposer). Global class names are prefixed
165
+ * vx- and must not be scoped by CSS Modules.
166
+ * @module @alexpeng/dsh-custom-plugin/client/styles
167
+ */
168
+ const STATIC_CSS = `/* dsh-custom-plugin static styles. Every rule is global by design: the UI
169
+ * mounts into product slots and overlays, so class names are prefixed vx-
170
+ * and must not be scoped by CSS Modules. Dynamic rules (body background,
171
+ * aurora gradient, global-glass blur) are managed at runtime by a style
172
+ * element in custom.tsx and do not live here. */
173
+ .vx-root {
174
+ position: fixed;
175
+ inset: 0;
176
+ pointer-events: none;
177
+ z-index: 2147483000;
178
+ font-family: ui-sans-serif, system-ui, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
179
+ }
180
+ .vx-fx {
181
+ position: absolute;
182
+ inset: 0;
183
+ width: 100%;
184
+ height: 100%;
185
+ pointer-events: none;
186
+ }
187
+ .vx-anchor {
188
+ display: inline-block;
189
+ width: 0;
190
+ height: 1px;
191
+ vertical-align: bottom;
192
+ }
193
+ .vx-turn-actions {
194
+ display: inline-flex;
195
+ gap: 4px;
196
+ margin-left: 10px;
197
+ vertical-align: middle;
198
+ align-items: center;
199
+ }
200
+ .vx-chip {
201
+ pointer-events: auto;
202
+ border: 1px solid rgba(128, 140, 160, .4);
203
+ background: rgba(255, 255, 255, .16);
204
+ color: inherit;
205
+ border-radius: 8px;
206
+ padding: 2px 8px;
207
+ font-size: 11px;
208
+ cursor: pointer;
209
+ backdrop-filter: blur(6px);
210
+ text-decoration: none;
211
+ display: inline-flex;
212
+ align-items: center;
213
+ gap: 3px;
214
+ }
215
+ .vx-chip:hover {
216
+ background: rgba(255, 255, 255, .28);
217
+ }
218
+ .vx-link {
219
+ text-decoration: none;
220
+ }
221
+ .vx-glass {
222
+ border-radius: 16px;
223
+ background: rgba(255, 255, 255, .64);
224
+ -webkit-backdrop-filter: blur(9px) saturate(1.22);
225
+ backdrop-filter: blur(9px) saturate(1.22);
226
+ box-shadow: 0 0 1px 1px rgba(17, 17, 26, .07) inset, 0 1px 2px rgba(17, 17, 26, .05) inset, 0px 4px 16px rgba(17, 17, 26, .05), 0px 8px 24px rgba(17, 17, 26, .05), 0px 16px 56px rgba(17, 17, 26, .05);
227
+ }
228
+ @media (prefers-color-scheme: dark) {
229
+ .vx-glass {
230
+ background: rgba(13, 17, 25, .62);
231
+ color: #eef1f7;
232
+ }
233
+ }
234
+ .vx-liquid .vx-glass {
235
+ background: rgba(255, 255, 255, .06);
236
+ backdrop-filter: url(#vx-lg);
237
+ -webkit-backdrop-filter: url(#vx-lg);
238
+ }
239
+ @media (prefers-color-scheme: dark) {
240
+ .vx-liquid .vx-glass {
241
+ background: rgba(0, 0, 0, .06);
242
+ }
243
+ }
244
+ @supports not (backdrop-filter: url(#vx-lg)) {
245
+ .vx-liquid .vx-glass {
246
+ background: rgba(255, 255, 255, .64);
247
+ backdrop-filter: blur(9px) saturate(1.22);
248
+ -webkit-backdrop-filter: blur(9px) saturate(1.22);
249
+ }
250
+ @media (prefers-color-scheme: dark) {
251
+ .vx-liquid .vx-glass {
252
+ background: rgba(13, 17, 25, .62);
253
+ }
254
+ }
255
+ }
256
+ .vx-liquid .vx-pattern {
257
+ background-image: radial-gradient(rgba(150, 150, 160, .5) 3px, transparent 3px);
258
+ background-size: 24px 24px;
259
+ -webkit-mask-image: radial-gradient(ellipse at top, transparent 20%, black);
260
+ mask-image: radial-gradient(ellipse at top, transparent 20%, black);
261
+ animation: vx-pattern-move 25000ms linear infinite;
262
+ }
263
+ @media (prefers-color-scheme: dark) {
264
+ .vx-liquid .vx-pattern {
265
+ background-image: radial-gradient(rgba(110, 110, 128, .5) 3px, transparent 3px);
266
+ }
267
+ }
268
+ .vx-pattern {
269
+ position: absolute;
270
+ inset: 0;
271
+ pointer-events: none;
272
+ z-index: -1;
273
+ background-image: radial-gradient(rgba(150, 150, 160, .42) 1px, transparent 1px);
274
+ background-size: 24px 24px;
275
+ -webkit-mask-image: radial-gradient(ellipse at center, transparent 30%, black 100%);
276
+ mask-image: radial-gradient(ellipse at center, transparent 30%, black 100%);
277
+ animation: vx-pattern-move 10000ms linear infinite;
278
+ }
279
+ @media (prefers-color-scheme: dark) {
280
+ .vx-pattern {
281
+ background-image: radial-gradient(rgba(100, 100, 116, .5) 1px, transparent 1px);
282
+ }
283
+ }
284
+ @keyframes vx-pattern-move {
285
+ from {
286
+ background-position: 0 0;
287
+ }
288
+ to {
289
+ background-position: 0 24px;
290
+ }
291
+ }
292
+ @keyframes vx-aurora {
293
+ 0% {
294
+ background-position: 0% 50%;
295
+ }
296
+ 50% {
297
+ background-position: 100% 50%;
298
+ }
299
+ 100% {
300
+ background-position: 0% 50%;
301
+ }
302
+ }
303
+ .vx-rail {
304
+ position: absolute;
305
+ width: 12px;
306
+ border-radius: 8px;
307
+ background: rgba(120, 130, 150, .18);
308
+ border: 1px solid rgba(120, 130, 150, .25);
309
+ pointer-events: auto;
310
+ touch-action: none;
311
+ box-sizing: border-box;
312
+ }
313
+ .vx-rail.right {
314
+ right: 4px;
315
+ }
316
+ .vx-rail.left {
317
+ left: 56px;
318
+ }
319
+ /* When the rail is active it substitutes the native scrollbar: the scrollport
320
+ carrying the vx-rail-scroller class (added by the client when it resolves
321
+ the chat scrollport) hides its own bar so only one scroll affordance
322
+ remains. scrollbar-gutter: stable on the shell keeps the layout width. */
323
+ .vx-rail-scroller {
324
+ scrollbar-width: none;
325
+ }
326
+ .vx-rail-scroller::-webkit-scrollbar {
327
+ display: none;
328
+ }
329
+ .vx-thumb {
330
+ position: absolute;
331
+ left: 1px;
332
+ right: 1px;
333
+ border-radius: 8px;
334
+ background: rgba(90, 105, 135, .5);
335
+ border: 1px solid rgba(255, 255, 255, .35);
336
+ box-sizing: border-box;
337
+ }
338
+ .vx-thumb:hover {
339
+ background: rgba(90, 105, 135, .7);
340
+ }
341
+ .vx-dot {
342
+ position: absolute;
343
+ left: 50%;
344
+ transform: translate(-50%, -50%);
345
+ width: 10px;
346
+ height: 10px;
347
+ border-radius: 50%;
348
+ background: rgba(70, 85, 110, .92);
349
+ border: 2px solid rgba(255, 255, 255, .92);
350
+ box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
351
+ pointer-events: auto;
352
+ cursor: pointer;
353
+ transition: transform .12s;
354
+ padding: 0;
355
+ }
356
+ .vx-dot:hover {
357
+ transform: translate(-50%, -50%) scale(1.35);
358
+ }
359
+ .vx-dot.star {
360
+ background: #c9a24b;
361
+ border-color: #f3e3bd;
362
+ }
363
+ @media (prefers-color-scheme: dark) {
364
+ .vx-dot {
365
+ background: rgba(205, 215, 230, .95);
366
+ border-color: rgba(28, 34, 46, .9);
367
+ }
368
+ .vx-thumb {
369
+ background: rgba(165, 180, 205, .45);
370
+ }
371
+ }
372
+ .vx-rail-pop {
373
+ position: absolute;
374
+ pointer-events: auto;
375
+ padding: 10px 12px;
376
+ width: 300px;
377
+ font-size: 12px;
378
+ line-height: 1.55;
379
+ z-index: 5;
380
+ }
381
+ /* Class = which side the rail sits on; the card must open toward the page
382
+ content. It is a child of the 12px-wide rail, so right:20px puts it left
383
+ of the rail and left:20px puts it right (20px = rail width + 8px gap). */
384
+ .vx-rail-pop.right {
385
+ right: 20px;
386
+ }
387
+ .vx-rail-pop.left {
388
+ left: 20px;
389
+ }
390
+ .vx-pop-time {
391
+ color: #6d7689;
392
+ font-size: 11px;
393
+ margin-bottom: 4px;
394
+ }
395
+ .vx-pop-text {
396
+ white-space: pre-wrap;
397
+ word-break: break-word;
398
+ max-height: 150px;
399
+ overflow: hidden;
400
+ margin-bottom: 8px;
401
+ }
402
+ .vx-pop-row {
403
+ display: flex;
404
+ gap: 5px;
405
+ flex-wrap: wrap;
406
+ align-items: center;
407
+ }
408
+ .vx-balance-wrap {
409
+ display: inline-flex;
410
+ align-items: center;
411
+ position: relative;
412
+ }
413
+ .vx-balance-text {
414
+ display: inline-flex;
415
+ align-items: center;
416
+ gap: 6px;
417
+ padding: 3px 10px;
418
+ border-radius: 8px;
419
+ font-size: 12.5px;
420
+ color: inherit;
421
+ background: rgba(127, 164, 224, .16);
422
+ border: 1px solid rgba(127, 164, 224, .4);
423
+ cursor: default;
424
+ white-space: nowrap;
425
+ }
426
+ .vx-balance-text:hover {
427
+ background: rgba(127, 164, 224, .28);
428
+ }
429
+ .vx-balance-text.vx-balance-pinned {
430
+ background: rgba(127, 164, 224, .36);
431
+ border-color: rgba(127, 164, 224, .8);
432
+ }
433
+ .vx-balance-head {
434
+ display: flex;
435
+ align-items: center;
436
+ justify-content: space-between;
437
+ gap: 8px;
438
+ margin-bottom: 8px;
439
+ }
440
+ .vx-balance-today {
441
+ opacity: .75;
442
+ font-size: 11.5px;
443
+ }
444
+ .vx-balance-hover {
445
+ position: absolute;
446
+ top: calc(100% + 8px);
447
+ right: 0;
448
+ z-index: 70;
449
+ width: 360px;
450
+ max-height: 480px;
451
+ overflow: auto;
452
+ padding: 12px;
453
+ color: #20242e;
454
+ font-size: 12px;
455
+ pointer-events: auto;
456
+ }
457
+ @media (prefers-color-scheme: dark) {
458
+ .vx-balance-hover {
459
+ color: #e8ebf2;
460
+ }
461
+ }
462
+ .vx-balance-lines {
463
+ font-size: 13px;
464
+ margin: 6px 0;
465
+ }
466
+ .vx-header-btn {
467
+ display: inline-flex;
468
+ align-items: center;
469
+ gap: 5px;
470
+ padding: 4px 10px;
471
+ border-radius: 8px;
472
+ font-size: 12.5px;
473
+ color: inherit;
474
+ background: rgba(127, 164, 224, .16);
475
+ border: 1px solid rgba(127, 164, 224, .4);
476
+ cursor: pointer;
477
+ white-space: nowrap;
478
+ }
479
+ .vx-header-btn:hover {
480
+ background: rgba(127, 164, 224, .3);
481
+ }
482
+ .vx-quote-btn {
483
+ position: absolute;
484
+ transform: translate(-50%, -100%);
485
+ pointer-events: auto;
486
+ background: rgba(40, 48, 64, .96);
487
+ color: #eef1f7;
488
+ border: 1px solid rgba(255, 255, 255, .25);
489
+ padding: 5px 12px;
490
+ border-radius: 9px;
491
+ font-size: 12px;
492
+ cursor: pointer;
493
+ box-shadow: 0 6px 18px rgba(0, 0, 0, .28);
494
+ display: inline-flex;
495
+ align-items: center;
496
+ gap: 5px;
497
+ }
498
+ .vx-panel {
499
+ position: absolute;
500
+ width: 430px;
501
+ max-width: calc(100vw - 40px);
502
+ height: min(660px, calc(100vh - 110px));
503
+ display: flex;
504
+ flex-direction: column;
505
+ overflow: hidden;
506
+ pointer-events: auto;
507
+ color: #20242e;
508
+ }
509
+ @media (prefers-color-scheme: dark) {
510
+ .vx-panel, .vx-modal, .vx-folders {
511
+ color: #e8ebf2;
512
+ }
513
+ }
514
+ .vx-panel-head {
515
+ display: flex;
516
+ align-items: center;
517
+ gap: 8px;
518
+ padding: 10px 14px;
519
+ cursor: move;
520
+ user-select: none;
521
+ border-bottom: 1px solid rgba(150, 160, 180, .25);
522
+ position: relative;
523
+ z-index: 1;
524
+ }
525
+ .vx-panel-title {
526
+ font-weight: 600;
527
+ font-size: 13px;
528
+ }
529
+ .vx-panel-sub {
530
+ font-size: 11px;
531
+ opacity: .62;
532
+ white-space: nowrap;
533
+ }
534
+ .vx-tabs {
535
+ display: flex;
536
+ flex-wrap: wrap;
537
+ gap: 2px;
538
+ padding: 8px 10px 4px;
539
+ border-bottom: 1px solid rgba(150, 160, 180, .2);
540
+ position: relative;
541
+ z-index: 1;
542
+ }
543
+ .vx-tab {
544
+ border: none;
545
+ background: transparent;
546
+ color: inherit;
547
+ opacity: .75;
548
+ font-size: 12px;
549
+ padding: 5px 9px;
550
+ border-radius: 8px;
551
+ cursor: pointer;
552
+ display: inline-flex;
553
+ align-items: center;
554
+ gap: 4px;
555
+ }
556
+ .vx-tab.on {
557
+ opacity: 1;
558
+ background: rgba(255, 255, 255, .28);
559
+ box-shadow: inset 0 1px 0 rgba(255, 255, 255, .35);
560
+ }
561
+ .vx-panel-body {
562
+ flex: 1;
563
+ overflow: auto;
564
+ padding: 12px 14px;
565
+ position: relative;
566
+ z-index: 1;
567
+ }
568
+ .vx-col {
569
+ display: flex;
570
+ flex-direction: column;
571
+ gap: 10px;
572
+ }
573
+ .vx-row {
574
+ display: flex;
575
+ gap: 8px;
576
+ align-items: center;
577
+ }
578
+ .vx-row.wrap {
579
+ flex-wrap: wrap;
580
+ }
581
+ .vx-flex1 {
582
+ flex: 1;
583
+ }
584
+ .vx-section-title {
585
+ font-weight: 600;
586
+ font-size: 12.5px;
587
+ margin-top: 4px;
588
+ opacity: .9;
589
+ }
590
+ .vx-swatches {
591
+ display: grid;
592
+ grid-template-columns: repeat(5, 1fr);
593
+ gap: 6px;
594
+ }
595
+ .vx-swatch {
596
+ display: flex;
597
+ flex-direction: column;
598
+ align-items: center;
599
+ gap: 3px;
600
+ border: none;
601
+ background: transparent;
602
+ color: inherit;
603
+ cursor: pointer;
604
+ padding: 0;
605
+ }
606
+ .vx-swatch-box {
607
+ width: 34px;
608
+ height: 26px;
609
+ border-radius: 8px;
610
+ border: 2px solid rgba(120, 130, 150, .4);
611
+ box-sizing: border-box;
612
+ }
613
+ .vx-swatch.on .vx-swatch-box {
614
+ border-color: #7fa4e0;
615
+ box-shadow: 0 0 0 2px rgba(127, 164, 224, .35);
616
+ }
617
+ .vx-swatch:disabled {
618
+ opacity: .35;
619
+ cursor: not-allowed;
620
+ }
621
+ .vx-swatch-label {
622
+ font-size: 10px;
623
+ opacity: .85;
624
+ }
625
+ .vx-btn {
626
+ pointer-events: auto;
627
+ border: 1px solid rgba(128, 140, 160, .4);
628
+ background: rgba(255, 255, 255, .16);
629
+ color: inherit;
630
+ border-radius: 9px;
631
+ padding: 6px 12px;
632
+ font-size: 12px;
633
+ cursor: pointer;
634
+ display: inline-flex;
635
+ align-items: center;
636
+ gap: 5px;
637
+ }
638
+ .vx-btn:hover {
639
+ background: rgba(255, 255, 255, .28);
640
+ }
641
+ .vx-btn.on {
642
+ background: rgba(127, 164, 224, .35);
643
+ border-color: rgba(127, 164, 224, .8);
644
+ }
645
+ .vx-btn:disabled {
646
+ opacity: .5;
647
+ cursor: default;
648
+ }
649
+ .vx-btn-sm {
650
+ padding: 2px 8px;
651
+ font-size: 11px;
652
+ }
653
+ .vx-btn-danger {
654
+ background: rgba(214, 88, 88, .22);
655
+ border-color: rgba(214, 88, 88, .55);
656
+ }
657
+ .vx-btn.big {
658
+ padding: 10px 16px;
659
+ font-size: 13px;
660
+ }
661
+ .vx-input {
662
+ flex: 1;
663
+ min-width: 0;
664
+ border: 1px solid rgba(128, 140, 160, .4);
665
+ background: rgba(255, 255, 255, .16);
666
+ color: inherit;
667
+ border-radius: 9px;
668
+ padding: 6px 10px;
669
+ font-size: 12px;
670
+ }
671
+ .vx-textarea {
672
+ border: 1px solid rgba(128, 140, 160, .4);
673
+ background: rgba(255, 255, 255, .16);
674
+ color: inherit;
675
+ border-radius: 9px;
676
+ padding: 6px 10px;
677
+ font-size: 12px;
678
+ resize: vertical;
679
+ font-family: inherit;
680
+ }
681
+ .vx-toggle-row {
682
+ display: flex;
683
+ gap: 8px;
684
+ align-items: center;
685
+ font-size: 12.5px;
686
+ }
687
+ .vx-muted {
688
+ color: rgba(120, 128, 148, .95);
689
+ font-size: 11.5px;
690
+ }
691
+ .vx-error {
692
+ color: #d85858;
693
+ font-size: 12px;
694
+ }
695
+ .vx-pad {
696
+ padding: 12px;
697
+ }
698
+ .vx-pad-sm {
699
+ padding: 6px 2px;
700
+ }
701
+ .vx-list {
702
+ display: flex;
703
+ flex-direction: column;
704
+ gap: 4px;
705
+ max-height: 300px;
706
+ overflow: auto;
707
+ }
708
+ .vx-list-item {
709
+ text-align: left;
710
+ border: none;
711
+ background: rgba(255, 255, 255, .1);
712
+ color: inherit;
713
+ border-radius: 8px;
714
+ padding: 6px 10px;
715
+ font-size: 12px;
716
+ cursor: pointer;
717
+ }
718
+ .vx-list-item:hover {
719
+ background: rgba(255, 255, 255, .22);
720
+ }
721
+ .vx-check-row {
722
+ display: flex;
723
+ gap: 8px;
724
+ align-items: center;
725
+ font-size: 12.5px;
726
+ padding: 4px 2px;
727
+ }
728
+ .vx-check-title {
729
+ flex: 1;
730
+ overflow: hidden;
731
+ text-overflow: ellipsis;
732
+ white-space: nowrap;
733
+ }
734
+ .vx-badge {
735
+ background: rgba(127, 164, 224, .3);
736
+ border-radius: 8px;
737
+ padding: 0 6px;
738
+ font-size: 10px;
739
+ }
740
+ .vx-table {
741
+ width: 100%;
742
+ border-collapse: collapse;
743
+ font-size: 11.5px;
744
+ }
745
+ .vx-table th, .vx-table td {
746
+ border: 1px solid rgba(128, 140, 160, .3);
747
+ padding: 4px 6px;
748
+ text-align: right;
749
+ }
750
+ .vx-table th:first-child, .vx-table td:first-child {
751
+ text-align: left;
752
+ }
753
+ .vx-folder {
754
+ display: flex;
755
+ flex-direction: column;
756
+ }
757
+ .vx-folder-head {
758
+ display: flex;
759
+ gap: 5px;
760
+ align-items: center;
761
+ padding: 5px 4px;
762
+ border-radius: 9px;
763
+ cursor: grab;
764
+ }
765
+ .vx-folder-head:hover {
766
+ background: rgba(255, 255, 255, .14);
767
+ }
768
+ .vx-folder-head.drop-inside {
769
+ background: rgba(127, 164, 224, .3);
770
+ outline: 1px dashed rgba(127, 164, 224, .8);
771
+ }
772
+ .vx-folder-head.drop-before {
773
+ box-shadow: 0 -2px 0 0 rgba(127, 164, 224, .9);
774
+ }
775
+ .vx-folder-head.drop-after {
776
+ box-shadow: 0 2px 0 0 rgba(127, 164, 224, .9);
777
+ }
778
+ .vx-folder-name {
779
+ font-size: 12.5px;
780
+ font-weight: 600;
781
+ flex: 1;
782
+ overflow: hidden;
783
+ text-overflow: ellipsis;
784
+ white-space: nowrap;
785
+ }
786
+ .vx-folder-body {
787
+ border-left: 1px dashed rgba(128, 140, 160, .35);
788
+ margin-left: 14px;
789
+ padding-left: 6px;
790
+ display: flex;
791
+ flex-direction: column;
792
+ gap: 2px;
793
+ }
794
+ .vx-item-row {
795
+ display: flex;
796
+ gap: 5px;
797
+ align-items: center;
798
+ padding: 3px 4px;
799
+ border-radius: 8px;
800
+ }
801
+ .vx-item-row:hover {
802
+ background: rgba(255, 255, 255, .12);
803
+ }
804
+ .vx-item-name {
805
+ flex: 1;
806
+ text-align: left;
807
+ border: none;
808
+ background: transparent;
809
+ color: inherit;
810
+ font-size: 12px;
811
+ cursor: pointer;
812
+ overflow: hidden;
813
+ text-overflow: ellipsis;
814
+ white-space: nowrap;
815
+ padding: 0;
816
+ }
817
+ .vx-mini {
818
+ border: none;
819
+ background: transparent;
820
+ color: inherit;
821
+ opacity: .75;
822
+ cursor: pointer;
823
+ padding: 2px;
824
+ border-radius: 6px;
825
+ display: inline-flex;
826
+ align-items: center;
827
+ }
828
+ .vx-mini:hover {
829
+ opacity: 1;
830
+ background: rgba(255, 255, 255, .2);
831
+ }
832
+ .vx-form {
833
+ display: flex;
834
+ flex-direction: column;
835
+ gap: 6px;
836
+ border: 1px dashed rgba(128, 140, 160, .4);
837
+ border-radius: 10px;
838
+ padding: 8px;
839
+ }
840
+ .vx-prompt-card {
841
+ border: 1px solid rgba(128, 140, 160, .3);
842
+ background: rgba(255, 255, 255, .1);
843
+ border-radius: 10px;
844
+ padding: 8px 10px;
845
+ }
846
+ .vx-prompt-title {
847
+ font-weight: 600;
848
+ font-size: 12.5px;
849
+ }
850
+ .vx-prompt-body {
851
+ margin-top: 4px;
852
+ font-size: 11.5px;
853
+ opacity: .85;
854
+ white-space: pre-wrap;
855
+ word-break: break-word;
856
+ max-height: 72px;
857
+ overflow: hidden;
858
+ }
859
+ .vx-modal-mask {
860
+ position: absolute;
861
+ inset: 0;
862
+ pointer-events: auto;
863
+ background: rgba(8, 10, 16, .4);
864
+ display: flex;
865
+ align-items: center;
866
+ justify-content: center;
867
+ z-index: 60;
868
+ }
869
+ .vx-modal {
870
+ position: relative;
871
+ width: min(760px, 92vw);
872
+ max-height: 82vh;
873
+ overflow: auto;
874
+ padding: 16px;
875
+ color: #20242e;
876
+ pointer-events: auto;
877
+ }
878
+ .vx-pop-head {
879
+ display: flex;
880
+ gap: 8px;
881
+ align-items: center;
882
+ margin-bottom: 8px;
883
+ font-weight: 600;
884
+ font-size: 13px;
885
+ }
886
+ .vx-svgbox {
887
+ overflow: auto;
888
+ background: rgba(12, 14, 20, .6);
889
+ border-radius: 12px;
890
+ padding: 14px;
891
+ }
892
+ .vx-svgbox svg {
893
+ max-width: 100%;
894
+ height: auto;
895
+ }
896
+ .vx-pre {
897
+ white-space: pre-wrap;
898
+ word-break: break-all;
899
+ font-size: 10.5px;
900
+ opacity: .85;
901
+ }
902
+ .vx-toasts {
903
+ position: absolute;
904
+ left: 50%;
905
+ bottom: 26px;
906
+ transform: translateX(-50%);
907
+ display: flex;
908
+ flex-direction: column;
909
+ gap: 8px;
910
+ align-items: center;
911
+ pointer-events: auto;
912
+ z-index: 80;
913
+ }
914
+ .vx-toast {
915
+ display: flex;
916
+ gap: 10px;
917
+ align-items: center;
918
+ color: #f2f4f8;
919
+ background: rgba(26, 32, 44, .92);
920
+ border: 1px solid rgba(255, 255, 255, .12);
921
+ padding: 8px 14px;
922
+ border-radius: 12px;
923
+ font-size: 12.5px;
924
+ box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
925
+ max-width: 560px;
926
+ backdrop-filter: blur(9px);
927
+ -webkit-backdrop-filter: blur(9px);
928
+ }
929
+ @media (prefers-color-scheme: dark) {
930
+ .vx-toast {
931
+ background: rgba(18, 22, 30, .94);
932
+ }
933
+ }
934
+ .vx-foot-btn {
935
+ display: inline-flex;
936
+ align-items: center;
937
+ gap: 6px;
938
+ border: 1px solid rgba(127, 164, 224, .4);
939
+ background: rgba(127, 164, 224, .14);
940
+ color: inherit;
941
+ cursor: pointer;
942
+ padding: 4px 10px;
943
+ border-radius: 10px;
944
+ margin: 2px;
945
+ }
946
+ .vx-foot-btn:hover {
947
+ background: rgba(127, 164, 224, .3);
948
+ }
949
+ .vx-foot-label {
950
+ font-size: 12px;
951
+ }
952
+ .vx-folders {
953
+ position: fixed;
954
+ left: 12px;
955
+ bottom: 60px;
956
+ width: 272px;
957
+ max-height: min(560px, calc(100vh - 220px));
958
+ display: flex;
959
+ flex-direction: column;
960
+ overflow: hidden;
961
+ pointer-events: auto;
962
+ color: #20242e;
963
+ z-index: 55;
964
+ }
965
+ /* 头部行(图标 + 标题 + 按钮)下移并拉开与容器边缘的间距 */
966
+ .vx-folders .vx-pop-head {
967
+ padding: 14px 14px 0;
968
+ }
969
+ .vx-folders-body {
970
+ flex: 1;
971
+ overflow: auto;
972
+ padding: 4px 14px 12px;
973
+ position: relative;
974
+ z-index: 1;
975
+ }
976
+ .vx-prompt-pop {
977
+ position: fixed;
978
+ width: 320px;
979
+ max-height: 420px;
980
+ display: flex;
981
+ flex-direction: column;
982
+ overflow: hidden;
983
+ pointer-events: auto;
984
+ color: #20242e;
985
+ z-index: 65;
986
+ padding: 10px 12px;
987
+ }
988
+ .vx-settings-page {
989
+ display: flex;
990
+ flex-direction: column;
991
+ gap: 14px;
992
+ max-width: 720px;
993
+ }`;
994
+ //#endregion
995
+ //#region src/client/custom.tsx
996
+ /**
997
+ * Browser half of dsh-custom-plugin: the Custom convenience suite UI.
998
+ *
999
+ * A single mutable store (`S`) drives every surface through a lightweight
1000
+ * listener set; components re-render on `setS`. The file ports the earlier
1001
+ * dynamic-plugin implementation: React is a platform import, static styles
1002
+ * are injected through one owned style element (styles.ts), dynamic body
1003
+ * styles (background / aurora / global glass) extend it, and host calls go
1004
+ * over `/api/custom-plugin` fetch routes.
1005
+ * @module @alexpeng/dsh-custom-plugin/client/custom
1006
+ */
1007
+ /** Locale-independent date key (mirrors the host ledger). */
1008
+ function dayKey() {
1009
+ const d = /* @__PURE__ */ new Date();
1010
+ const pad = (n) => String(n).padStart(2, "0");
1011
+ return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
1012
+ }
1013
+ function fmtClock(time) {
1014
+ const d = new Date(time);
1015
+ const pad = (n) => String(n).padStart(2, "0");
1016
+ return `${pad(d.getHours())}:${pad(d.getMinutes())}`;
1017
+ }
1018
+ /** Palette of 20 muted low-saturation backgrounds (with matching tab colors).
1019
+ * 天青灰 leads the list: it is the install default and renders first among
1020
+ * the palette swatches, right after 无颜色 / 极光. */
1021
+ const PALETTE = [
1022
+ [
1023
+ "天青灰",
1024
+ "#E9EBEE",
1025
+ "#D6DADF"
1026
+ ],
1027
+ [
1028
+ "暖象牙",
1029
+ "#F5F0E8",
1030
+ "#E8E0D4"
1031
+ ],
1032
+ [
1033
+ "雾灰绿",
1034
+ "#E9EDE6",
1035
+ "#D7DED3"
1036
+ ],
1037
+ [
1038
+ "烟熏玫瑰",
1039
+ "#F2EAEC",
1040
+ "#E5D6DA"
1041
+ ],
1042
+ [
1043
+ "雾蓝",
1044
+ "#E8EDF2",
1045
+ "#D4DDE6"
1046
+ ],
1047
+ [
1048
+ "薰衣草灰",
1049
+ "#EFEDF4",
1050
+ "#E0DCEB"
1051
+ ],
1052
+ [
1053
+ "燕麦米",
1054
+ "#F3EEE6",
1055
+ "#E5DED3"
1056
+ ],
1057
+ [
1058
+ "薄荷雾",
1059
+ "#EAF0ED",
1060
+ "#D7E3DC"
1061
+ ],
1062
+ [
1063
+ "裸桃",
1064
+ "#F5EDE8",
1065
+ "#E8DCD4"
1066
+ ],
1067
+ [
1068
+ "石板蓝",
1069
+ "#E6EDF1",
1070
+ "#D2DBE3"
1071
+ ],
1072
+ [
1073
+ "紫藤灰",
1074
+ "#EEEBF2",
1075
+ "#E1DAE8"
1076
+ ],
1077
+ [
1078
+ "奶油黄",
1079
+ "#F4F0E6",
1080
+ "#E6E1D5"
1081
+ ],
1082
+ [
1083
+ "鼠尾草",
1084
+ "#EAEDE5",
1085
+ "#D7DED1"
1086
+ ],
1087
+ [
1088
+ "腮红粉",
1089
+ "#F3EAEC",
1090
+ "#E6D6DA"
1091
+ ],
1092
+ [
1093
+ "香草白",
1094
+ "#F3F0E6",
1095
+ "#E5E0D4"
1096
+ ],
1097
+ [
1098
+ "青灰",
1099
+ "#E7F0F0",
1100
+ "#D3E1E1"
1101
+ ],
1102
+ [
1103
+ "杏仁白",
1104
+ "#F0ECE8",
1105
+ "#E2DAD3"
1106
+ ],
1107
+ [
1108
+ "尤加利",
1109
+ "#EAF0ED",
1110
+ "#D7E3DB"
1111
+ ],
1112
+ [
1113
+ "珍珠灰",
1114
+ "#EDEDEE",
1115
+ "#DCDCDD"
1116
+ ],
1117
+ [
1118
+ "淡金",
1119
+ "#F4F1E4",
1120
+ "#E6E1D0"
1121
+ ]
1122
+ ];
1123
+ /** Neutral glass tokens used when no palette color is active. */
1124
+ const NEUTRAL_TOKENS = {
1125
+ "--dsw-alias-bg-base": {
1126
+ light: "rgba(248,249,251,.5)",
1127
+ dark: "rgba(15,17,23,.5)"
1128
+ },
1129
+ "--dsw-alias-bg-layer-1": {
1130
+ light: "rgba(255,255,255,.58)",
1131
+ dark: "rgba(22,25,32,.58)"
1132
+ },
1133
+ "--dsw-alias-bg-layer-2": {
1134
+ light: "rgba(242,244,247,.66)",
1135
+ dark: "rgba(28,31,40,.66)"
1136
+ },
1137
+ "--dsw-alias-bg-overlay": {
1138
+ light: "rgba(255,255,255,.78)",
1139
+ dark: "rgba(18,21,28,.78)"
1140
+ },
1141
+ "--dsw-specific-sidebar-fill": {
1142
+ light: "rgba(245,247,250,.56)",
1143
+ dark: "rgba(13,15,21,.56)"
1144
+ }
1145
+ };
1146
+ "" + encodeURIComponent("<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 100 100\"><defs><linearGradient id=\"r\" x1=\"100%\" y1=\"0%\" x2=\"0%\" y2=\"0%\"><stop offset=\"0%\" stop-color=\"#0000\"/><stop offset=\"100%\" stop-color=\"red\"/></linearGradient><linearGradient id=\"b\" x1=\"0%\" y1=\"0%\" x2=\"0%\" y2=\"100%\"><stop offset=\"0%\" stop-color=\"#0000\"/><stop offset=\"100%\" stop-color=\"blue\"/></linearGradient></defs><rect width=\"100\" height=\"100\" fill=\"black\"/><rect width=\"100\" height=\"100\" rx=\"16\" fill=\"url(#r)\"/><rect width=\"100\" height=\"100\" rx=\"16\" fill=\"url(#b)\" style=\"mix-blend-mode: difference\"/><rect x=\"3.5\" y=\"3.5\" width=\"93\" height=\"93\" rx=\"16\" fill=\"hsl(0 0% 50% / 0.93)\" style=\"filter: blur(11px)\"/></svg>");
1147
+ const LG_FILTER = "<filter id=\"vx-lg\" x=\"0\" y=\"0\" width=\"100%\" height=\"100%\" color-interpolation-filters=\"sRGB\"><feImage href=\"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20100%20100%22%3E%3Cdefs%3E%3ClinearGradient%20id%3D%22r%22%20x1%3D%22100%25%22%20y1%3D%220%25%22%20x2%3D%220%25%22%20y2%3D%220%25%22%3E%3Cstop%20offset%3D%220%25%22%20stop-color%3D%22%230000%22%2F%3E%3Cstop%20offset%3D%22100%25%22%20stop-color%3D%22red%22%2F%3E%3C%2FlinearGradient%3E%3ClinearGradient%20id%3D%22b%22%20x1%3D%220%25%22%20y1%3D%220%25%22%20x2%3D%220%25%22%20y2%3D%22100%25%22%3E%3Cstop%20offset%3D%220%25%22%20stop-color%3D%22%230000%22%2F%3E%3Cstop%20offset%3D%22100%25%22%20stop-color%3D%22blue%22%2F%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%3Crect%20width%3D%22100%22%20height%3D%22100%22%20fill%3D%22black%22%2F%3E%3Crect%20width%3D%22100%22%20height%3D%22100%22%20rx%3D%2216%22%20fill%3D%22url(%23r)%22%2F%3E%3Crect%20width%3D%22100%22%20height%3D%22100%22%20rx%3D%2216%22%20fill%3D%22url(%23b)%22%20style%3D%22mix-blend-mode%3A%20difference%22%2F%3E%3Crect%20x%3D%223.5%22%20y%3D%223.5%22%20width%3D%2293%22%20height%3D%2293%22%20rx%3D%2216%22%20fill%3D%22hsl(0%200%25%2050%25%20%2F%200.93)%22%20style%3D%22filter%3A%20blur(11px)%22%2F%3E%3C%2Fsvg%3E\" result=\"map\" x=\"0\" y=\"0\" width=\"100%\" height=\"100%\" preserveAspectRatio=\"none\"/><feDisplacementMap in=\"SourceGraphic\" in2=\"map\" xChannelSelector=\"R\" yChannelSelector=\"B\" scale=\"-180\" result=\"d\"/><feGaussianBlur in=\"d\" stdDeviation=\"4\"/></filter>";
1148
+ function ensureLiquidGlass() {
1149
+ const d = typeof document !== "undefined" ? document : null;
1150
+ if (d === null || d.getElementById("vx-lg-filter") !== null) return;
1151
+ try {
1152
+ const svg = d.createElementNS("http://www.w3.org/2000/svg", "svg");
1153
+ svg.setAttribute("id", "vx-lg-filter");
1154
+ svg.setAttribute("width", "0");
1155
+ svg.setAttribute("height", "0");
1156
+ svg.setAttribute("style", "position:absolute;width:0;height:0;overflow:hidden");
1157
+ svg.innerHTML = LG_FILTER;
1158
+ d.documentElement.appendChild(svg);
1159
+ } catch (error) {
1160
+ apiDiagReport("ensureLiquidGlass: " + String(error?.message ?? error));
1161
+ }
1162
+ }
1163
+ /** One owned style element carrying the static rules plus the dynamic body rules. */
1164
+ let dynStyle = null;
1165
+ function setDynCss(css) {
1166
+ const d = typeof document !== "undefined" ? document : null;
1167
+ if (d === null) return;
1168
+ if (dynStyle === null || !dynStyle.isConnected) {
1169
+ dynStyle = d.createElement("style");
1170
+ dynStyle.setAttribute("data-custom-plugin-css", "");
1171
+ d.head.appendChild(dynStyle);
1172
+ }
1173
+ dynStyle.textContent = STATIC_CSS + "\n" + css;
1174
+ }
1175
+ function removeDynCss() {
1176
+ if (dynStyle !== null && dynStyle.isConnected) try {
1177
+ dynStyle.remove();
1178
+ } catch {}
1179
+ dynStyle = null;
1180
+ }
1181
+ /** Install the whole Custom UI into the client context. Returns a disposer that unregisters every slot entry. */
1182
+ function installCustomPlugin(ctx, reportDiag) {
1183
+ const C = ctx;
1184
+ const S = {
1185
+ cfg: {
1186
+ bg: "天青灰",
1187
+ weather: "none",
1188
+ glass: true,
1189
+ glassMode: "frost",
1190
+ globalGlass: true,
1191
+ timeline: true,
1192
+ timelineLeft: false,
1193
+ starsOnly: false,
1194
+ quote: true,
1195
+ antiScroll: false,
1196
+ mermaid: true,
1197
+ formula: true
1198
+ },
1199
+ folders: [],
1200
+ prompts: [],
1201
+ stars: {},
1202
+ apiKey: "",
1203
+ usage: {},
1204
+ sessionId: null,
1205
+ turns: null,
1206
+ anchors: /* @__PURE__ */ new Map(),
1207
+ seqAnchor: /* @__PURE__ */ new Map(),
1208
+ railPositions: [],
1209
+ railSig: "",
1210
+ railHover: null,
1211
+ railHoverTimer: null,
1212
+ railBox: {
1213
+ top: 64,
1214
+ height: 600
1215
+ },
1216
+ railRight: 4,
1217
+ railLeft: 56,
1218
+ thumbTop: 0,
1219
+ thumbH: 26,
1220
+ scrollerEl: null,
1221
+ panelOpen: false,
1222
+ panelTab: "look",
1223
+ panelPos: null,
1224
+ foldersOpen: false,
1225
+ folderAdd: null,
1226
+ folderWsPick: null,
1227
+ dragFolder: null,
1228
+ dropHint: null,
1229
+ promptOpen: null,
1230
+ promptQuery: "",
1231
+ batchModal: false,
1232
+ mermaidModal: null,
1233
+ quoteSel: null,
1234
+ ask: null,
1235
+ confirmAsk: null,
1236
+ toasts: [],
1237
+ booted: false,
1238
+ dark: false,
1239
+ balance: null,
1240
+ exporting: false,
1241
+ insertDraft: null,
1242
+ quoteSetDraft: null,
1243
+ suppressUntil: 0,
1244
+ greeted: false
1245
+ };
1246
+ let listeners = [];
1247
+ function setS(patch) {
1248
+ Object.assign(S, patch);
1249
+ for (const listener of listeners) try {
1250
+ listener();
1251
+ } catch {}
1252
+ }
1253
+ function useS() {
1254
+ const [, force] = react.useReducer((x) => x + 1, 0);
1255
+ react.useEffect(() => {
1256
+ listeners.push(force);
1257
+ return () => {
1258
+ listeners = listeners.filter((l) => l !== force);
1259
+ };
1260
+ }, []);
1261
+ return S;
1262
+ }
1263
+ function useSessionsSafe(props) {
1264
+ try {
1265
+ return props.useSessions((st) => st);
1266
+ } catch {
1267
+ return null;
1268
+ }
1269
+ }
1270
+ function useWorkspacesSafe(props) {
1271
+ try {
1272
+ return props.useWorkspaces((st) => st);
1273
+ } catch {
1274
+ return null;
1275
+ }
1276
+ }
1277
+ const ICONS = {
1278
+ sliders: [
1279
+ ["line", {
1280
+ x1: 21,
1281
+ y1: 4,
1282
+ x2: 14,
1283
+ y2: 4
1284
+ }],
1285
+ ["line", {
1286
+ x1: 10,
1287
+ y1: 4,
1288
+ x2: 3,
1289
+ y2: 4
1290
+ }],
1291
+ ["line", {
1292
+ x1: 21,
1293
+ y1: 12,
1294
+ x2: 12,
1295
+ y2: 12
1296
+ }],
1297
+ ["line", {
1298
+ x1: 8,
1299
+ y1: 12,
1300
+ x2: 3,
1301
+ y2: 12
1302
+ }],
1303
+ ["line", {
1304
+ x1: 21,
1305
+ y1: 20,
1306
+ x2: 16,
1307
+ y2: 20
1308
+ }],
1309
+ ["line", {
1310
+ x1: 12,
1311
+ y1: 20,
1312
+ x2: 3,
1313
+ y2: 20
1314
+ }],
1315
+ ["line", {
1316
+ x1: 14,
1317
+ y1: 2,
1318
+ x2: 14,
1319
+ y2: 6
1320
+ }],
1321
+ ["line", {
1322
+ x1: 8,
1323
+ y1: 10,
1324
+ x2: 8,
1325
+ y2: 14
1326
+ }],
1327
+ ["line", {
1328
+ x1: 16,
1329
+ y1: 18,
1330
+ x2: 16,
1331
+ y2: 22
1332
+ }]
1333
+ ],
1334
+ folder: [["path", { d: "M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z" }]],
1335
+ folderPlus: [
1336
+ ["path", { d: "M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z" }],
1337
+ ["line", {
1338
+ x1: 12,
1339
+ y1: 10,
1340
+ x2: 12,
1341
+ y2: 16
1342
+ }],
1343
+ ["line", {
1344
+ x1: 9,
1345
+ y1: 13,
1346
+ x2: 15,
1347
+ y2: 13
1348
+ }]
1349
+ ],
1350
+ zap: [["path", { d: "M13 2 3 14h9l-1 8 10-12h-9l1-8z" }]],
1351
+ clock: [["circle", {
1352
+ cx: 12,
1353
+ cy: 12,
1354
+ r: 10
1355
+ }], ["polyline", { points: "12 6 12 12 16 14" }]],
1356
+ download: [
1357
+ ["path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4" }],
1358
+ ["polyline", { points: "7 10 12 15 17 10" }],
1359
+ ["line", {
1360
+ x1: 12,
1361
+ y1: 15,
1362
+ x2: 12,
1363
+ y2: 3
1364
+ }]
1365
+ ],
1366
+ gitBranch: [
1367
+ ["line", {
1368
+ x1: 6,
1369
+ y1: 3,
1370
+ x2: 6,
1371
+ y2: 15
1372
+ }],
1373
+ ["circle", {
1374
+ cx: 18,
1375
+ cy: 6,
1376
+ r: 3
1377
+ }],
1378
+ ["circle", {
1379
+ cx: 6,
1380
+ cy: 18,
1381
+ r: 3
1382
+ }],
1383
+ ["path", { d: "M18 9a9 9 0 0 1-9 9" }]
1384
+ ],
1385
+ wrench: [["path", { d: "M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z" }]],
1386
+ wallet: [
1387
+ ["path", { d: "M21 12V7H5a2 2 0 0 1 0-4h14v4" }],
1388
+ ["path", { d: "M3 5v14a2 2 0 0 0 2 2h16v-5" }],
1389
+ ["path", { d: "M18 12a2 2 0 0 0 0 4h4v-4Z" }]
1390
+ ],
1391
+ info: [
1392
+ ["circle", {
1393
+ cx: 12,
1394
+ cy: 12,
1395
+ r: 10
1396
+ }],
1397
+ ["line", {
1398
+ x1: 12,
1399
+ y1: 16,
1400
+ x2: 12,
1401
+ y2: 12
1402
+ }],
1403
+ ["line", {
1404
+ x1: 12,
1405
+ y1: 8,
1406
+ x2: 12.01,
1407
+ y2: 8
1408
+ }]
1409
+ ],
1410
+ x: [["line", {
1411
+ x1: 18,
1412
+ y1: 6,
1413
+ x2: 6,
1414
+ y2: 18
1415
+ }], ["line", {
1416
+ x1: 6,
1417
+ y1: 6,
1418
+ x2: 18,
1419
+ y2: 18
1420
+ }]],
1421
+ 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" }]],
1422
+ fork: [
1423
+ ["line", {
1424
+ x1: 6,
1425
+ y1: 3,
1426
+ x2: 6,
1427
+ y2: 15
1428
+ }],
1429
+ ["circle", {
1430
+ cx: 18,
1431
+ cy: 6,
1432
+ r: 3
1433
+ }],
1434
+ ["circle", {
1435
+ cx: 6,
1436
+ cy: 18,
1437
+ r: 3
1438
+ }],
1439
+ ["path", { d: "M18 9a9 9 0 0 1-9 9" }]
1440
+ ],
1441
+ copy: [["rect", {
1442
+ x: 9,
1443
+ y: 9,
1444
+ width: 13,
1445
+ height: 13,
1446
+ rx: 2
1447
+ }], ["path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" }]],
1448
+ check: [["polyline", { points: "20 6 9 17 4 12" }]],
1449
+ quote: [["path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }]],
1450
+ search: [["circle", {
1451
+ cx: 11,
1452
+ cy: 11,
1453
+ r: 8
1454
+ }], ["line", {
1455
+ x1: 21,
1456
+ y1: 21,
1457
+ x2: 16.65,
1458
+ y2: 16.65
1459
+ }]],
1460
+ trash: [
1461
+ ["polyline", { points: "3 6 5 6 21 6" }],
1462
+ ["path", { d: "M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2" }],
1463
+ ["line", {
1464
+ x1: 10,
1465
+ y1: 11,
1466
+ x2: 10,
1467
+ y2: 17
1468
+ }],
1469
+ ["line", {
1470
+ x1: 14,
1471
+ y1: 11,
1472
+ x2: 14,
1473
+ y2: 17
1474
+ }]
1475
+ ],
1476
+ plus: [["line", {
1477
+ x1: 12,
1478
+ y1: 5,
1479
+ x2: 12,
1480
+ y2: 19
1481
+ }], ["line", {
1482
+ x1: 5,
1483
+ y1: 12,
1484
+ x2: 19,
1485
+ y2: 12
1486
+ }]],
1487
+ chevronDown: [["polyline", { points: "6 9 12 15 18 9" }]],
1488
+ chevronRight: [["polyline", { points: "9 18 15 12 9 6" }]],
1489
+ refresh: [
1490
+ ["polyline", { points: "23 4 23 10 17 10" }],
1491
+ ["polyline", { points: "1 20 1 14 7 14" }],
1492
+ ["path", { d: "M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15" }]
1493
+ ],
1494
+ briefcase: [["rect", {
1495
+ x: 2,
1496
+ y: 7,
1497
+ width: 20,
1498
+ height: 14,
1499
+ rx: 2
1500
+ }], ["path", { d: "M16 21V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16" }]],
1501
+ message: [["path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" }]],
1502
+ snowflake: [
1503
+ ["line", {
1504
+ x1: 2,
1505
+ y1: 12,
1506
+ x2: 22,
1507
+ y2: 12
1508
+ }],
1509
+ ["line", {
1510
+ x1: 12,
1511
+ y1: 2,
1512
+ x2: 12,
1513
+ y2: 22
1514
+ }],
1515
+ ["path", { d: "m20 16-4-4 4-4" }],
1516
+ ["path", { d: "m4 8 4 4-4 4" }],
1517
+ ["path", { d: "m16 4-4 4-4-4" }],
1518
+ ["path", { d: "m8 20 4-4 4 4" }]
1519
+ ],
1520
+ cloudRain: [
1521
+ ["path", { d: "M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242" }],
1522
+ ["line", {
1523
+ x1: 16,
1524
+ y1: 14,
1525
+ x2: 16,
1526
+ y2: 20
1527
+ }],
1528
+ ["line", {
1529
+ x1: 8,
1530
+ y1: 14,
1531
+ x2: 8,
1532
+ y2: 20
1533
+ }],
1534
+ ["line", {
1535
+ x1: 12,
1536
+ y1: 16,
1537
+ x2: 12,
1538
+ y2: 22
1539
+ }]
1540
+ ],
1541
+ flower: [
1542
+ ["circle", {
1543
+ cx: 12,
1544
+ cy: 12,
1545
+ r: 3
1546
+ }],
1547
+ ["circle", {
1548
+ cx: 12,
1549
+ cy: 4.5,
1550
+ r: 2.1
1551
+ }],
1552
+ ["circle", {
1553
+ cx: 18.5,
1554
+ cy: 8.3,
1555
+ r: 2.1
1556
+ }],
1557
+ ["circle", {
1558
+ cx: 16,
1559
+ cy: 15.7,
1560
+ r: 2.1
1561
+ }],
1562
+ ["circle", {
1563
+ cx: 8,
1564
+ cy: 15.7,
1565
+ r: 2.1
1566
+ }],
1567
+ ["circle", {
1568
+ cx: 5.5,
1569
+ cy: 8.3,
1570
+ r: 2.1
1571
+ }]
1572
+ ],
1573
+ arrowUp: [["polyline", { points: "18 15 12 9 6 15" }]],
1574
+ arrowDown: [["polyline", { points: "6 9 12 15 18 9" }]],
1575
+ minimize: [
1576
+ ["polyline", { points: "4 14 10 14 10 20" }],
1577
+ ["polyline", { points: "20 10 14 10 14 4" }],
1578
+ ["line", {
1579
+ x1: 14,
1580
+ y1: 10,
1581
+ x2: 21,
1582
+ y2: 3
1583
+ }],
1584
+ ["line", {
1585
+ x1: 3,
1586
+ y1: 21,
1587
+ x2: 10,
1588
+ y2: 14
1589
+ }]
1590
+ ],
1591
+ moon: [["path", { d: "M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" }]],
1592
+ sun: [
1593
+ ["circle", {
1594
+ cx: 12,
1595
+ cy: 12,
1596
+ r: 4
1597
+ }],
1598
+ ["line", {
1599
+ x1: 12,
1600
+ y1: 2,
1601
+ x2: 12,
1602
+ y2: 5
1603
+ }],
1604
+ ["line", {
1605
+ x1: 12,
1606
+ y1: 19,
1607
+ x2: 12,
1608
+ y2: 22
1609
+ }],
1610
+ ["line", {
1611
+ x1: 2,
1612
+ y1: 12,
1613
+ x2: 5,
1614
+ y2: 12
1615
+ }],
1616
+ ["line", {
1617
+ x1: 19,
1618
+ y1: 12,
1619
+ x2: 22,
1620
+ y2: 12
1621
+ }],
1622
+ ["line", {
1623
+ x1: 4.93,
1624
+ y1: 4.93,
1625
+ x2: 7.07,
1626
+ y2: 7.07
1627
+ }],
1628
+ ["line", {
1629
+ x1: 16.93,
1630
+ y1: 16.93,
1631
+ x2: 19.07,
1632
+ y2: 19.07
1633
+ }],
1634
+ ["line", {
1635
+ x1: 4.93,
1636
+ y1: 19.07,
1637
+ x2: 7.07,
1638
+ y2: 16.93
1639
+ }],
1640
+ ["line", {
1641
+ x1: 16.93,
1642
+ y1: 7.07,
1643
+ x2: 19.07,
1644
+ y2: 4.93
1645
+ }]
1646
+ ],
1647
+ list: [
1648
+ ["line", {
1649
+ x1: 8,
1650
+ y1: 6,
1651
+ x2: 21,
1652
+ y2: 6
1653
+ }],
1654
+ ["line", {
1655
+ x1: 8,
1656
+ y1: 12,
1657
+ x2: 21,
1658
+ y2: 12
1659
+ }],
1660
+ ["line", {
1661
+ x1: 8,
1662
+ y1: 18,
1663
+ x2: 21,
1664
+ y2: 18
1665
+ }],
1666
+ ["line", {
1667
+ x1: 3,
1668
+ y1: 6,
1669
+ x2: 3.01,
1670
+ y2: 6
1671
+ }],
1672
+ ["line", {
1673
+ x1: 3,
1674
+ y1: 12,
1675
+ x2: 3.01,
1676
+ y2: 12
1677
+ }],
1678
+ ["line", {
1679
+ x1: 3,
1680
+ y1: 18,
1681
+ x2: 3.01,
1682
+ y2: 18
1683
+ }]
1684
+ ]
1685
+ };
1686
+ function Icon(props) {
1687
+ const defs = ICONS[props.n] ?? ICONS.info;
1688
+ const size = props.size ?? 14;
1689
+ return react.createElement("svg", {
1690
+ viewBox: "0 0 24 24",
1691
+ width: size,
1692
+ height: size,
1693
+ fill: props.filled === true ? "currentColor" : "none",
1694
+ stroke: props.filled === true ? "none" : "currentColor",
1695
+ strokeWidth: props.sw ?? 1.8,
1696
+ strokeLinecap: "round",
1697
+ strokeLinejoin: "round",
1698
+ className: props.cls ?? "",
1699
+ style: props.style ?? null
1700
+ }, defs.map((def, index) => {
1701
+ const tag = def[0];
1702
+ const attrs = def[1];
1703
+ if (tag === "circle") return react.createElement("circle", {
1704
+ key: index,
1705
+ ...attrs
1706
+ });
1707
+ if (tag === "line") return react.createElement("line", {
1708
+ key: index,
1709
+ ...attrs
1710
+ });
1711
+ if (tag === "rect") return react.createElement("rect", {
1712
+ key: index,
1713
+ ...attrs
1714
+ });
1715
+ if (tag === "polyline") return react.createElement("polyline", {
1716
+ key: index,
1717
+ ...attrs
1718
+ });
1719
+ return react.createElement("path", {
1720
+ key: index,
1721
+ ...attrs
1722
+ });
1723
+ }));
1724
+ }
1725
+ function toast(text, kind, action) {
1726
+ const id = Date.now() + Math.floor(Math.random() * 9999);
1727
+ const item = {
1728
+ id,
1729
+ text,
1730
+ kind: kind ?? "info",
1731
+ action: action ?? null
1732
+ };
1733
+ S.toasts = S.toasts.concat(item).slice(-4);
1734
+ setS({ toasts: S.toasts });
1735
+ new Promise((resolve) => setTimeout(resolve, kind === "error" ? 6e3 : 3800)).then(() => {
1736
+ S.toasts = S.toasts.filter((t) => t.id !== id);
1737
+ setS({ toasts: S.toasts });
1738
+ }).catch(() => {});
1739
+ }
1740
+ function askText(title, value, cb) {
1741
+ setS({ ask: {
1742
+ title,
1743
+ value: value ?? "",
1744
+ cb
1745
+ } });
1746
+ }
1747
+ function askConfirm(message, cb) {
1748
+ setS({ confirmAsk: {
1749
+ message,
1750
+ cb
1751
+ } });
1752
+ }
1753
+ function hexToRgb(hex) {
1754
+ const match = /^#?([0-9a-f]{6})$/i.exec(String(hex ?? "").trim());
1755
+ if (match === null) return [
1756
+ 235,
1757
+ 238,
1758
+ 242
1759
+ ];
1760
+ const value = parseInt(match[1], 16);
1761
+ return [
1762
+ value >> 16 & 255,
1763
+ value >> 8 & 255,
1764
+ value & 255
1765
+ ];
1766
+ }
1767
+ function rgbaOf(hex, alpha) {
1768
+ const c = hexToRgb(hex);
1769
+ return `rgba(${c[0]},${c[1]},${c[2]},${alpha})`;
1770
+ }
1771
+ function shade(hex, factor) {
1772
+ const c = hexToRgb(hex);
1773
+ const mix = (v) => Math.max(0, Math.min(255, Math.round(v * factor)));
1774
+ return "#" + [
1775
+ mix(c[0]),
1776
+ mix(c[1]),
1777
+ mix(c[2])
1778
+ ].map((v) => v.toString(16).padStart(2, "0")).join("");
1779
+ }
1780
+ let tokenDisposer = null;
1781
+ function applyAppearance() {
1782
+ const cfg = S.cfg;
1783
+ const dEl = typeof document !== "undefined" ? document.documentElement : null;
1784
+ if (dEl !== null) try {
1785
+ dEl.classList.toggle("vx-liquid", cfg.glass === true && cfg.glassMode === "liquid");
1786
+ } catch {}
1787
+ const theme = C.get("theme");
1788
+ if (tokenDisposer !== null) {
1789
+ try {
1790
+ tokenDisposer();
1791
+ } catch {}
1792
+ tokenDisposer = null;
1793
+ }
1794
+ if (theme !== void 0 && typeof theme.overrideTokens === "function") {
1795
+ if (cfg.bg !== void 0 && cfg.bg !== "default" && cfg.bg !== "aurora") {
1796
+ const entry = PALETTE.find((p) => p[0] === cfg.bg) ?? PALETTE[0];
1797
+ const base = entry[1];
1798
+ const tab = entry[2] ?? shade(base, .94);
1799
+ const glassOn = cfg.glass === true;
1800
+ const mk = (c, a) => glassOn ? rgbaOf(c, a) : c;
1801
+ const darkBase = shade(base, .78);
1802
+ const darkTab = shade(tab, .78);
1803
+ tokenDisposer = theme.overrideTokens("custom-plugin-appearance", {
1804
+ "--dsw-alias-bg-base": {
1805
+ light: mk(base, .5),
1806
+ dark: mk(darkBase, .5)
1807
+ },
1808
+ "--dsw-alias-bg-layer-1": {
1809
+ light: mk(tab, .6),
1810
+ dark: mk(darkTab, .6)
1811
+ },
1812
+ "--dsw-alias-bg-layer-2": {
1813
+ light: mk(shade(base, .96), .7),
1814
+ dark: mk(shade(darkBase, .94), .7)
1815
+ },
1816
+ "--dsw-alias-bg-overlay": {
1817
+ light: mk(shade(base, 1.04), .8),
1818
+ dark: mk(shade(darkBase, .86), .8)
1819
+ },
1820
+ "--dsw-specific-sidebar-fill": {
1821
+ light: mk(tab, .62),
1822
+ dark: mk(darkTab, .62)
1823
+ }
1824
+ });
1825
+ } else if (cfg.glass === true || cfg.bg === "aurora") tokenDisposer = theme.overrideTokens("custom-plugin-appearance", NEUTRAL_TOKENS);
1826
+ }
1827
+ let dyn = "";
1828
+ if (cfg.bg === "aurora") {
1829
+ dyn += "@keyframes vx-aurora { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }";
1830
+ dyn += " body { background: linear-gradient(120deg, #8fa8d8, #b59fd8, #8fc4b4, #d8a8c0) !important; background-size: 320% 320% !important; animation: vx-aurora 26s ease infinite !important; }";
1831
+ dyn += " body[data-ds-dark-theme] [data-conversation-scroll] > :has([data-conversation-composer-overlay]) { background: transparent !important; }";
1832
+ } else if (cfg.bg !== void 0 && cfg.bg !== "default") {
1833
+ const base = (PALETTE.find((p) => p[0] === cfg.bg) ?? PALETTE[0])[1];
1834
+ dyn += ` body { background-color: ${base} !important; }`;
1835
+ }
1836
+ 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; }";
1837
+ setDynCss(dyn);
1838
+ }
1839
+ function syncAntiScroll(on) {
1840
+ const d = typeof document !== "undefined" ? document : null;
1841
+ const w = typeof window !== "undefined" ? window : null;
1842
+ if (d === null) return;
1843
+ const scrollables = d.querySelectorAll("*");
1844
+ for (const el of scrollables) try {
1845
+ const cs = w !== null && w.getComputedStyle !== void 0 ? w.getComputedStyle(el) : null;
1846
+ if (cs === null) continue;
1847
+ if (cs.overflowY === "auto" || cs.overflowY === "scroll") {
1848
+ if (on) {
1849
+ el.setAttribute("data-vx-anti", el.style.scrollBehavior ?? "");
1850
+ el.style.scrollBehavior = "auto";
1851
+ } else if (el.hasAttribute("data-vx-anti")) {
1852
+ el.style.scrollBehavior = el.getAttribute("data-vx-anti") === "smooth" ? "smooth" : "";
1853
+ el.removeAttribute("data-vx-anti");
1854
+ }
1855
+ }
1856
+ } catch {}
1857
+ }
1858
+ async function loadCfg() {
1859
+ try {
1860
+ const result = await apiStateGet();
1861
+ if (result.ok === true && result.data !== void 0) {
1862
+ const data = result.data;
1863
+ if (data.cfg !== void 0 && data.cfg !== null) {
1864
+ const cfg = {
1865
+ ...S.cfg,
1866
+ ...data.cfg
1867
+ };
1868
+ delete cfg.clouds;
1869
+ delete cfg.wind;
1870
+ S.cfg = cfg;
1871
+ }
1872
+ if (Array.isArray(data.folders)) S.folders = data.folders;
1873
+ if (Array.isArray(data.prompts)) S.prompts = data.prompts;
1874
+ if (data.stars !== void 0 && data.stars !== null && typeof data.stars === "object") S.stars = data.stars;
1875
+ if (typeof data.apiKey === "string") S.apiKey = data.apiKey;
1876
+ if (data.usage !== void 0 && data.usage !== null && typeof data.usage === "object") S.usage = data.usage;
1877
+ }
1878
+ } catch {}
1879
+ S.booted = true;
1880
+ setS({});
1881
+ if (!S.greeted) {
1882
+ S.greeted = true;
1883
+ new Promise((resolve) => setTimeout(resolve, 1200)).then(() => toast("Custom 便利套件已就绪", "info")).catch(() => {});
1884
+ }
1885
+ }
1886
+ function saveCfg() {
1887
+ const cfg = { ...S.cfg };
1888
+ delete cfg.clouds;
1889
+ delete cfg.wind;
1890
+ apiStateSave({
1891
+ cfg,
1892
+ folders: S.folders,
1893
+ prompts: S.prompts,
1894
+ stars: S.stars,
1895
+ apiKey: S.apiKey
1896
+ }).catch(() => {});
1897
+ }
1898
+ const FX = {
1899
+ snow: [],
1900
+ rain: [],
1901
+ sakura: [],
1902
+ splashes: []
1903
+ };
1904
+ const SAKURA_PALETTE = [
1905
+ "hsla(340, 45%, 90%, 0.8)",
1906
+ "hsla(342, 50%, 91%, 0.8)",
1907
+ "hsla(344, 55%, 92%, 0.8)",
1908
+ "hsla(346, 60%, 93%, 0.8)",
1909
+ "hsla(348, 65%, 94%, 0.8)",
1910
+ "hsla(350, 60%, 95%, 0.8)",
1911
+ "hsla(352, 55%, 93%, 0.8)",
1912
+ "hsla(348, 40%, 88%, 0.8)"
1913
+ ];
1914
+ const SAKURA_SPRITES = [];
1915
+ const SAKURA_IMAGES = [];
1916
+ function rand(a, b) {
1917
+ return a + Math.random() * (b - a);
1918
+ }
1919
+ function tracePetal(g, x, y, s, rot) {
1920
+ g.save();
1921
+ g.translate(x, y);
1922
+ g.rotate(rot ?? 0);
1923
+ g.scale(s, s);
1924
+ g.beginPath();
1925
+ g.moveTo(0, -1);
1926
+ g.bezierCurveTo(.85, -.9, .8, .4, 0, .8);
1927
+ g.bezierCurveTo(-.8, .4, -.85, -.9, 0, -1);
1928
+ g.closePath();
1929
+ g.restore();
1930
+ }
1931
+ function buildSakuraSprites() {
1932
+ if (SAKURA_SPRITES.length > 0) return;
1933
+ const cvs = (typeof document !== "undefined" ? document : null)?.createElement("canvas");
1934
+ if (cvs === void 0 || cvs === null) return;
1935
+ cvs.width = 48;
1936
+ cvs.height = 48;
1937
+ const g = cvs.getContext("2d");
1938
+ if (g === null) return;
1939
+ for (let i = 0; i < SAKURA_PALETTE.length; i++) {
1940
+ g.clearRect(0, 0, 48, 48);
1941
+ g.fillStyle = SAKURA_PALETTE[i];
1942
+ tracePetal(g, 24, 24, 10, 0);
1943
+ g.fill();
1944
+ try {
1945
+ SAKURA_SPRITES.push(cvs.toDataURL());
1946
+ } catch {
1947
+ SAKURA_SPRITES.push(null);
1948
+ }
1949
+ }
1950
+ for (const sprite of SAKURA_SPRITES) {
1951
+ if (sprite === null) continue;
1952
+ const image = new Image();
1953
+ image.src = sprite;
1954
+ SAKURA_IMAGES.push(image);
1955
+ }
1956
+ }
1957
+ function initFx(weather, w, h) {
1958
+ FX.snow = [];
1959
+ FX.rain = [];
1960
+ FX.sakura = [];
1961
+ FX.splashes = [];
1962
+ if (weather === "snow") {
1963
+ for (const layer of [
1964
+ {
1965
+ count: 100,
1966
+ radius: [.15, .45],
1967
+ speed: [.15, .4],
1968
+ opacity: [.15, .35],
1969
+ drift: [.05, .2]
1970
+ },
1971
+ {
1972
+ count: 80,
1973
+ radius: [.5, 1],
1974
+ speed: [.4, 1],
1975
+ opacity: [.3, .6],
1976
+ drift: [.15, .45]
1977
+ },
1978
+ {
1979
+ count: 60,
1980
+ radius: [1.2, 2.5],
1981
+ speed: [.8, 1.6],
1982
+ opacity: [.5, .8],
1983
+ drift: [.25, .6]
1984
+ }
1985
+ ]) for (let i = 0; i < layer.count; i++) FX.snow.push({
1986
+ x: Math.random() * w,
1987
+ y: Math.random() * h,
1988
+ radius: rand(layer.radius[0], layer.radius[1]),
1989
+ opacity: rand(layer.opacity[0], layer.opacity[1]),
1990
+ speedY: rand(layer.speed[0], layer.speed[1]),
1991
+ drift: rand(layer.drift[0], layer.drift[1]),
1992
+ driftFreq: rand(3e-4, .0012),
1993
+ phase: Math.random() * Math.PI * 2
1994
+ });
1995
+ FX.snow.sort((a, b) => a.opacity - b.opacity);
1996
+ }
1997
+ if (weather === "rain") {
1998
+ FX.rainWind = {
1999
+ dx: Math.sin(.14),
2000
+ dy: Math.cos(.14)
2001
+ };
2002
+ const LAYERS = [
2003
+ {
2004
+ count: 80,
2005
+ length: [6, 14],
2006
+ speed: [3, 6],
2007
+ opacity: [.06, .14],
2008
+ width: [.3, .6]
2009
+ },
2010
+ {
2011
+ count: 60,
2012
+ length: [14, 28],
2013
+ speed: [7, 13],
2014
+ opacity: [.12, .25],
2015
+ width: [.5, 1]
2016
+ },
2017
+ {
2018
+ count: 30,
2019
+ length: [26, 48],
2020
+ speed: [12, 20],
2021
+ opacity: [.2, .38],
2022
+ width: [.8, 1.5]
2023
+ }
2024
+ ];
2025
+ for (let li = 0; li < LAYERS.length; li++) {
2026
+ const layer = LAYERS[li];
2027
+ const canSplash = li >= 1;
2028
+ for (let i = 0; i < layer.count; i++) FX.rain.push({
2029
+ x: Math.random() * (w + 100) - 50,
2030
+ y: Math.random() * h,
2031
+ length: rand(layer.length[0], layer.length[1]),
2032
+ speed: rand(layer.speed[0], layer.speed[1]),
2033
+ opacity: rand(layer.opacity[0], layer.opacity[1]),
2034
+ lineWidth: rand(layer.width[0], layer.width[1]),
2035
+ canSplash
2036
+ });
2037
+ }
2038
+ }
2039
+ if (weather === "sakura") {
2040
+ buildSakuraSprites();
2041
+ for (const layer of [
2042
+ {
2043
+ count: 40,
2044
+ size: [2.5, 4.5],
2045
+ speed: [.1, .3],
2046
+ opacity: [.1, .25],
2047
+ drift: [.15, .4]
2048
+ },
2049
+ {
2050
+ count: 32,
2051
+ size: [4.5, 7.5],
2052
+ speed: [.25, .55],
2053
+ opacity: [.25, .5],
2054
+ drift: [.35, .8]
2055
+ },
2056
+ {
2057
+ count: 16,
2058
+ size: [7.5, 11],
2059
+ speed: [.4, .75],
2060
+ opacity: [.4, .65],
2061
+ drift: [.5, 1]
2062
+ }
2063
+ ]) for (let i = 0; i < layer.count; i++) FX.sakura.push({
2064
+ x: Math.random() * w,
2065
+ y: Math.random() * h,
2066
+ size: rand(layer.size[0], layer.size[1]),
2067
+ opacity: rand(layer.opacity[0], layer.opacity[1]),
2068
+ speedY: rand(layer.speed[0], layer.speed[1]),
2069
+ drift: rand(layer.drift[0], layer.drift[1]),
2070
+ driftFreq: rand(3e-4, .001),
2071
+ swayFreq: rand(4e-4, .0014),
2072
+ phase: Math.random() * Math.PI * 2,
2073
+ spin: rand(-.004, .004),
2074
+ wobble: rand(.8, 1.2),
2075
+ spriteIndex: SAKURA_IMAGES.length > 0 ? Math.floor(Math.random() * SAKURA_IMAGES.length) : -1
2076
+ });
2077
+ }
2078
+ }
2079
+ function spawnSplash(x, y) {
2080
+ if (FX.splashes.length >= 24) return;
2081
+ const n = 2 + Math.floor(Math.random() * 4);
2082
+ for (let i = 0; i < n; i++) FX.splashes.push({
2083
+ x: x + rand(-5, 5),
2084
+ y: y - rand(0, 3),
2085
+ vx: rand(-.9, .9),
2086
+ vy: rand(-1.6, -.4),
2087
+ life: 1,
2088
+ decay: rand(.02, .05),
2089
+ w: rand(.6, 1.6),
2090
+ h: rand(.4, 1.1)
2091
+ });
2092
+ }
2093
+ function fxFrame(g, cvs, weather, time) {
2094
+ const w = cvs.clientWidth || 0;
2095
+ const h = cvs.clientHeight || 0;
2096
+ if (w === 0 || h === 0) return;
2097
+ if (cvs.width !== Math.round(w) || cvs.height !== Math.round(h)) {
2098
+ cvs.width = Math.round(w);
2099
+ cvs.height = Math.round(h);
2100
+ initFx(weather, w, h);
2101
+ }
2102
+ g.clearRect(0, 0, w, h);
2103
+ if (weather === "snow") {
2104
+ let currentOpacity = -1;
2105
+ for (const f of FX.snow) {
2106
+ f.y += f.speedY;
2107
+ f.x += Math.sin(f.phase + time * f.driftFreq) * f.drift;
2108
+ if (f.y > h + f.radius) {
2109
+ f.y = -f.radius;
2110
+ f.x = Math.random() * w;
2111
+ }
2112
+ if (f.x > w + f.radius) f.x = -f.radius;
2113
+ else if (f.x < -f.radius) f.x = w + f.radius;
2114
+ const q = Math.round(f.opacity * 50) / 50;
2115
+ if (q !== currentOpacity) {
2116
+ currentOpacity = q;
2117
+ g.fillStyle = `rgba(255,255,255,${q})`;
2118
+ }
2119
+ g.beginPath();
2120
+ g.arc(f.x, f.y, f.radius, 0, Math.PI * 2);
2121
+ g.fill();
2122
+ }
2123
+ } else if (weather === "rain") {
2124
+ const WIND = FX.rainWind ?? {
2125
+ dx: .14,
2126
+ dy: .99
2127
+ };
2128
+ g.lineCap = "round";
2129
+ let currentOpacity = -1;
2130
+ let currentWidth = -1;
2131
+ for (const d of FX.rain) {
2132
+ d.x += d.speed * WIND.dx;
2133
+ d.y += d.speed * WIND.dy;
2134
+ if (d.y > h + d.length) {
2135
+ if (d.canSplash && Math.random() < .35) spawnSplash(d.x, h - 1);
2136
+ d.y = -(d.length + Math.random() * h * .2);
2137
+ d.x = Math.random() * (w + 100) - 50;
2138
+ }
2139
+ if (d.x > w + 50) d.x = -50;
2140
+ const qo = Math.round(d.opacity * 30) / 30;
2141
+ if (qo !== currentOpacity) {
2142
+ currentOpacity = qo;
2143
+ g.strokeStyle = `rgba(180,200,220,${qo})`;
2144
+ }
2145
+ const qw = Math.round(d.lineWidth * 4) / 4;
2146
+ if (qw !== currentWidth) {
2147
+ currentWidth = qw;
2148
+ g.lineWidth = qw;
2149
+ }
2150
+ g.beginPath();
2151
+ g.moveTo(d.x, d.y);
2152
+ g.lineTo(d.x - d.length * WIND.dx, d.y - d.length * WIND.dy);
2153
+ g.stroke();
2154
+ }
2155
+ for (let i = FX.splashes.length - 1; i >= 0; i--) {
2156
+ const sp = FX.splashes[i];
2157
+ sp.x += sp.vx;
2158
+ sp.y += sp.vy;
2159
+ sp.vy += .06;
2160
+ sp.life -= sp.decay;
2161
+ if (sp.life <= 0) {
2162
+ FX.splashes.splice(i, 1);
2163
+ continue;
2164
+ }
2165
+ g.save();
2166
+ g.globalAlpha = Math.max(0, sp.life);
2167
+ g.strokeStyle = "rgba(180,200,220,0.8)";
2168
+ g.lineWidth = .8;
2169
+ g.beginPath();
2170
+ g.ellipse(sp.x, sp.y, sp.w, sp.h, 0, 0, Math.PI * 2);
2171
+ g.stroke();
2172
+ g.restore();
2173
+ }
2174
+ } else if (weather === "sakura") for (const f of FX.sakura) {
2175
+ f.y += f.speedY;
2176
+ f.x += Math.sin(f.phase + time * f.swayFreq) * f.drift;
2177
+ if (f.y > h + f.size) {
2178
+ f.y = -f.size;
2179
+ f.x = Math.random() * w;
2180
+ }
2181
+ if (f.x > w + f.size) f.x = -f.size;
2182
+ else if (f.x < -f.size) f.x = w + f.size;
2183
+ const rot = Math.sin(f.phase + time * f.swayFreq * 1.7) * .9 + time * f.spin;
2184
+ const wob = 1 + .12 * Math.sin(f.phase * 2 + time * f.swayFreq * 2.3);
2185
+ if (f.spriteIndex >= 0 && SAKURA_IMAGES[f.spriteIndex] !== void 0) {
2186
+ g.save();
2187
+ g.globalAlpha = f.opacity;
2188
+ g.translate(f.x, f.y);
2189
+ g.rotate(rot);
2190
+ g.scale(f.size * f.wobble * wob / 18, f.size * f.wobble / 18);
2191
+ g.drawImage(SAKURA_IMAGES[f.spriteIndex], -18, -18, 36, 36);
2192
+ g.restore();
2193
+ } else {
2194
+ g.save();
2195
+ g.globalAlpha = f.opacity;
2196
+ g.translate(f.x, f.y);
2197
+ g.rotate(rot);
2198
+ g.scale(f.size * f.wobble * wob / 10, f.size * f.wobble / 10);
2199
+ g.fillStyle = SAKURA_PALETTE[0];
2200
+ tracePetal(g, 0, 0, 1, 0);
2201
+ g.fill();
2202
+ g.restore();
2203
+ }
2204
+ }
2205
+ }
2206
+ function FxCanvas() {
2207
+ const s = useS();
2208
+ const ref = react.useRef(null);
2209
+ react.useEffect(() => {
2210
+ const cvs = ref.current;
2211
+ if (cvs === null) return;
2212
+ const g = cvs.getContext("2d");
2213
+ if (g === null) return;
2214
+ const w = cvs.clientWidth || 0;
2215
+ const h = cvs.clientHeight || 0;
2216
+ initFx(s.cfg.weather ?? "none", w, h);
2217
+ let raf = 0;
2218
+ const t0 = Date.now();
2219
+ const loop = () => {
2220
+ const weather = s.cfg.weather ?? "none";
2221
+ if (weather === "none") {
2222
+ try {
2223
+ g.clearRect(0, 0, cvs.width, cvs.height);
2224
+ } catch {}
2225
+ return;
2226
+ }
2227
+ raf = requestAnimationFrame(loop);
2228
+ fxFrame(g, cvs, weather, Date.now() - t0);
2229
+ };
2230
+ loop();
2231
+ return () => {
2232
+ try {
2233
+ cancelAnimationFrame(raf);
2234
+ } catch {}
2235
+ };
2236
+ }, [s.cfg.weather]);
2237
+ return react.createElement("canvas", {
2238
+ ref,
2239
+ className: "vx-fx"
2240
+ });
2241
+ }
2242
+ let lastRefetchAt = 0;
2243
+ let railRefetchRows = -1;
2244
+ let lastDiagAt = 0;
2245
+ function diagThrottled(message) {
2246
+ const now = Date.now();
2247
+ if (now - lastDiagAt < 5e3) return;
2248
+ lastDiagAt = now;
2249
+ reportDiag(message);
2250
+ }
2251
+ function scheduleTurnsRefetch() {
2252
+ const now = Date.now();
2253
+ if (now - lastRefetchAt < 2e3) return;
2254
+ lastRefetchAt = now;
2255
+ fetchTurns(S.sessionId);
2256
+ }
2257
+ async function fetchTurns(sessionId) {
2258
+ try {
2259
+ const result = await apiTimelineGet(sessionId);
2260
+ if (sessionId !== S.sessionId) return;
2261
+ if (result.ok === true) {
2262
+ S.turns = {
2263
+ sessionId,
2264
+ items: result.items ?? []
2265
+ };
2266
+ setS({ turns: S.turns });
2267
+ updateRailPositions();
2268
+ diagThrottled("timeline " + (result.items?.length ?? 0) + " items " + sessionId.slice(0, 24));
2269
+ } else diagThrottled("timeline failed: " + String(result.error ?? "unknown"));
2270
+ } catch (error) {
2271
+ diagThrottled("timeline fetch error: " + String(error?.message ?? error));
2272
+ }
2273
+ }
2274
+ function findScrollerFrom(el) {
2275
+ const w = typeof window !== "undefined" ? window : null;
2276
+ if (w === null) return null;
2277
+ let node = el.parentElement;
2278
+ while (node !== null) {
2279
+ try {
2280
+ const cs = w.getComputedStyle(node);
2281
+ if (cs.overflowY === "auto" || cs.overflowY === "scroll") return node;
2282
+ } catch {}
2283
+ node = node.parentElement;
2284
+ }
2285
+ return null;
2286
+ }
2287
+ /** Resolve the real chat scrollport: query the shell's
2288
+ * semantic attribute directly instead of walking up from turnTail anchors
2289
+ * (the turnTail chain seat may be taken by another plugin, leaving no
2290
+ * anchors at all). ChatView itself resolves the same attribute, so this is
2291
+ * the shell's stable contract; the anchor walk stays only as a fallback. */
2292
+ function resolveScroller() {
2293
+ const d = typeof document !== "undefined" ? document : null;
2294
+ if (d === null) return null;
2295
+ try {
2296
+ const host = d.querySelector("[data-conversation-scroll]");
2297
+ if (host instanceof HTMLElement && host.isConnected) return host;
2298
+ } catch {}
2299
+ for (const anchor of S.anchors.values()) {
2300
+ if (anchor === void 0 || anchor.el === void 0) continue;
2301
+ try {
2302
+ const host = anchor.el.closest("[data-conversation-scroll]");
2303
+ if (host !== null) return host;
2304
+ } catch {}
2305
+ const found = findScrollerFrom(anchor.el);
2306
+ if (found !== null) return found;
2307
+ }
2308
+ return null;
2309
+ }
2310
+ /** All rendered user-message rows inside the scrollport, in document order
2311
+ * (steering messages render through the same UserMessageNodeView). */
2312
+ function queryUserRows(scroller) {
2313
+ try {
2314
+ return Array.from(scroller.querySelectorAll("[data-chat-flow-kind=\"user\"], [data-chat-flow-kind=\"steering\"]"));
2315
+ } catch {
2316
+ return [];
2317
+ }
2318
+ }
2319
+ /** Keep the rail-scroller class on exactly the current scrollport so the
2320
+ * native scrollbar hides only for the column the rail substitutes. */
2321
+ function syncRailScrollerClass(scroller) {
2322
+ const previous = S.scrollerEl;
2323
+ if (previous !== null && previous !== scroller) try {
2324
+ previous.classList.remove("vx-rail-scroller");
2325
+ } catch {}
2326
+ if (scroller !== null && scroller !== previous) try {
2327
+ scroller.classList.add("vx-rail-scroller");
2328
+ } catch {}
2329
+ }
2330
+ function updateRailPositions() {
2331
+ if (S.cfg.timeline !== true || S.sessionId === null) {
2332
+ syncRailScrollerClass(null);
2333
+ if (S.railPositions.length > 0 || S.thumbTop !== 0 || S.thumbH !== 26) setS({
2334
+ railPositions: [],
2335
+ railSig: "",
2336
+ railBox: {
2337
+ top: 64,
2338
+ height: 600
2339
+ },
2340
+ railRight: 4,
2341
+ railLeft: 56,
2342
+ thumbTop: 0,
2343
+ thumbH: 26,
2344
+ scrollerEl: null
2345
+ });
2346
+ return;
2347
+ }
2348
+ const w = typeof window !== "undefined" ? window : null;
2349
+ if (w === null) return;
2350
+ if (S.turns === null || S.turns.sessionId !== S.sessionId) {
2351
+ railRefetchRows = -1;
2352
+ scheduleTurnsRefetch();
2353
+ }
2354
+ const items = S.turns !== null && Array.isArray(S.turns.items) ? S.turns.items : [];
2355
+ let scroller = S.scrollerEl;
2356
+ if (scroller === null || !scroller.isConnected) scroller = resolveScroller();
2357
+ syncRailScrollerClass(scroller);
2358
+ const vh = w.innerHeight || 800;
2359
+ let top = 64;
2360
+ let height = vh - 64 - 120;
2361
+ let scrollH = Math.max(1, height);
2362
+ let scrollTop = 0;
2363
+ let viewH = height;
2364
+ let railRight = 4;
2365
+ let railLeft = 56;
2366
+ if (scroller !== null) try {
2367
+ const r = scroller.getBoundingClientRect();
2368
+ top = Math.max(0, r.top);
2369
+ height = Math.max(60, r.height);
2370
+ viewH = Math.max(1, scroller.clientHeight || r.height);
2371
+ scrollH = Math.max(viewH, scroller.scrollHeight || viewH);
2372
+ scrollTop = Math.max(0, scroller.scrollTop || 0);
2373
+ railRight = Math.max(2, Math.round(w.innerWidth - r.right + 4));
2374
+ railLeft = Math.max(2, Math.round(r.left + 4));
2375
+ } catch {}
2376
+ const trackH = height;
2377
+ const pos = [];
2378
+ const seqAnchor = /* @__PURE__ */ new Map();
2379
+ if (scroller !== null) {
2380
+ const rows = queryUserRows(scroller);
2381
+ const offset = items.length - rows.length;
2382
+ if (rows.length > items.length && railRefetchRows < rows.length) {
2383
+ railRefetchRows = rows.length;
2384
+ scheduleTurnsRefetch();
2385
+ }
2386
+ for (let i = 0; i < rows.length; i++) {
2387
+ const item = offset + i >= 0 ? items[offset + i] : void 0;
2388
+ if (item === void 0) continue;
2389
+ try {
2390
+ const r = rows[i].getBoundingClientRect();
2391
+ const sr = scroller.getBoundingClientRect();
2392
+ const pct = Math.max(0, Math.min(1, (r.top + r.height / 2 - sr.top + scrollTop) / Math.max(1, scroller.scrollHeight || 1)));
2393
+ const starred = S.stars[S.sessionId]?.[item.seq] === true;
2394
+ seqAnchor.set(item.seq, rows[i]);
2395
+ pos.push({
2396
+ seq: item.seq,
2397
+ y: Math.round(pct * trackH),
2398
+ st: starred
2399
+ });
2400
+ } catch {}
2401
+ }
2402
+ }
2403
+ const thumbH = Math.max(26, Math.round(trackH * (viewH / scrollH)));
2404
+ const thumbTop = scrollTop / Math.max(1, scrollH - viewH) * (trackH - thumbH);
2405
+ const sig = JSON.stringify(pos) + "|" + thumbTop + "|" + thumbH + "|" + top + "|" + height + "|" + railRight + "|" + railLeft;
2406
+ S.seqAnchor = seqAnchor;
2407
+ if (sig !== S.railSig) {
2408
+ setS({
2409
+ railPositions: pos,
2410
+ railSig: sig,
2411
+ railBox: {
2412
+ top,
2413
+ height
2414
+ },
2415
+ railRight,
2416
+ railLeft,
2417
+ thumbTop: Math.round(thumbTop),
2418
+ thumbH,
2419
+ scrollerEl: scroller
2420
+ });
2421
+ 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)));
2422
+ }
2423
+ }
2424
+ function scrollToSeq(seq) {
2425
+ const el = S.seqAnchor.get(seq) ?? S.anchors.get(seq)?.el ?? null;
2426
+ if (el === void 0 || el === null) {
2427
+ toast("该消息尚未渲染,请稍后重试", "error");
2428
+ return;
2429
+ }
2430
+ S.suppressUntil = Date.now() + 400;
2431
+ const scroller = S.scrollerEl;
2432
+ let done = false;
2433
+ if (scroller !== null && scroller.isConnected) try {
2434
+ const er = el.getBoundingClientRect();
2435
+ const sr = scroller.getBoundingClientRect();
2436
+ const floor = Math.max(0, (scroller.scrollHeight ?? 0) - (scroller.clientHeight ?? 0));
2437
+ const target = (scroller.scrollTop ?? 0) + (er.top + er.height / 2) - (sr.top + sr.height / 2);
2438
+ scroller.scrollTop = Math.max(0, Math.min(floor, target));
2439
+ done = true;
2440
+ } catch {}
2441
+ if (!done) try {
2442
+ el.scrollIntoView({
2443
+ behavior: "auto",
2444
+ block: "center"
2445
+ });
2446
+ } catch {
2447
+ try {
2448
+ el.scrollIntoView(true);
2449
+ } catch {}
2450
+ }
2451
+ setS({ railHover: null });
2452
+ }
2453
+ function toggleStar(seq) {
2454
+ const sid = S.sessionId;
2455
+ if (sid === null) return;
2456
+ const next = { ...S.stars[sid] ?? {} };
2457
+ if (next[seq] === true) delete next[seq];
2458
+ else next[seq] = true;
2459
+ const stars = { ...S.stars };
2460
+ stars[sid] = next;
2461
+ setS({ stars });
2462
+ saveCfg();
2463
+ updateRailPositions();
2464
+ }
2465
+ async function forkAt(seq) {
2466
+ const sessions = C.get("sessions");
2467
+ if (sessions === void 0) return;
2468
+ try {
2469
+ const childId = await sessions.fork({
2470
+ sessionId: S.sessionId,
2471
+ atSeq: seq
2472
+ });
2473
+ toast("分支会话已创建", "info", {
2474
+ label: "打开分支",
2475
+ run: () => {
2476
+ try {
2477
+ sessions.open(childId);
2478
+ } catch {}
2479
+ }
2480
+ });
2481
+ } catch (error) {
2482
+ toast("创建分支失败: " + String(error?.message ?? error), "error");
2483
+ }
2484
+ }
2485
+ function extractLatex(text) {
2486
+ const out = [];
2487
+ let i = 0;
2488
+ const n = text.length;
2489
+ while (i < n) {
2490
+ const a = text.indexOf("\\[", i);
2491
+ const b = text.indexOf("\\(", i);
2492
+ const c = text.indexOf("$$", i);
2493
+ let start = -1;
2494
+ let endTok = "";
2495
+ if (a >= 0 && (b < 0 || a < b) && (c < 0 || a < c)) {
2496
+ start = a;
2497
+ endTok = "\\]";
2498
+ } else if (b >= 0 && (c < 0 || b < c)) {
2499
+ start = b;
2500
+ endTok = "\\)";
2501
+ } else if (c >= 0) {
2502
+ start = c;
2503
+ endTok = "$$";
2504
+ }
2505
+ if (start < 0) break;
2506
+ const end = text.indexOf(endTok, start + 2);
2507
+ if (end < 0) {
2508
+ i = start + 2;
2509
+ continue;
2510
+ }
2511
+ out.push(text.slice(start + 2, end).trim());
2512
+ i = end + endTok.length;
2513
+ }
2514
+ const re2 = /\$([^$\n]{1,600}?)\$/g;
2515
+ let m;
2516
+ while ((m = re2.exec(text)) !== null) out.push(m[1].trim());
2517
+ return out;
2518
+ }
2519
+ function extractMathml(text) {
2520
+ const out = [];
2521
+ const lower = text.toLowerCase();
2522
+ let i = 0;
2523
+ while (true) {
2524
+ const s = lower.indexOf("<math", i);
2525
+ if (s < 0) break;
2526
+ const e = lower.indexOf("</math>", s);
2527
+ if (e < 0) break;
2528
+ out.push(text.slice(s, e + 7));
2529
+ i = e + 7;
2530
+ }
2531
+ return out;
2532
+ }
2533
+ async function copyText(text) {
2534
+ try {
2535
+ const d = typeof document !== "undefined" ? document : null;
2536
+ if (d !== null && navigator.clipboard !== void 0 && typeof navigator.clipboard.writeText === "function") {
2537
+ await navigator.clipboard.writeText(text);
2538
+ return true;
2539
+ }
2540
+ if (d === null) return false;
2541
+ const ta = d.createElement("textarea");
2542
+ ta.value = text;
2543
+ ta.style.position = "fixed";
2544
+ ta.style.opacity = "0";
2545
+ d.body.appendChild(ta);
2546
+ ta.select();
2547
+ const ok = d.execCommand("copy");
2548
+ ta.remove();
2549
+ return ok;
2550
+ } catch {
2551
+ return false;
2552
+ }
2553
+ }
2554
+ async function copyLatexOf(item) {
2555
+ const codes = extractLatex(item.text);
2556
+ if (codes.length === 0) {
2557
+ toast("未找到 LaTeX 公式", "error");
2558
+ return;
2559
+ }
2560
+ const ok = await copyText(codes.join("\n\n"));
2561
+ toast(ok ? `已复制 ${codes.length} 个 LaTeX 公式` : "复制失败", ok ? "info" : "error");
2562
+ }
2563
+ async function copyMathmlOf(item) {
2564
+ const codes = extractMathml(item.text);
2565
+ if (codes.length === 0) {
2566
+ toast("未找到 MathML", "error");
2567
+ return;
2568
+ }
2569
+ const ok = await copyText(codes.join("\n\n"));
2570
+ toast(ok ? `已复制 ${codes.length} 个 MathML(可粘贴到 Word)` : "复制失败", ok ? "info" : "error");
2571
+ }
2572
+ let mermaidState = { status: "idle" };
2573
+ async function ensureMermaid() {
2574
+ if (mermaidState.status === "ready") return true;
2575
+ if (mermaidState.status === "loading") {
2576
+ while (mermaidState.status === "loading") await new Promise((resolve) => setTimeout(resolve, 120));
2577
+ return mermaidState.status === "ready";
2578
+ }
2579
+ mermaidState = { status: "loading" };
2580
+ try {
2581
+ const result = await apiMermaidFetch();
2582
+ if (result.ok === true) {
2583
+ await new Promise((resolve, reject) => {
2584
+ const d = typeof document !== "undefined" ? document : null;
2585
+ if (d === null) {
2586
+ reject(/* @__PURE__ */ new Error("no document"));
2587
+ return;
2588
+ }
2589
+ const script = d.createElement("script");
2590
+ script.src = MERMAID_SCRIPT_PATH;
2591
+ script.onload = () => resolve();
2592
+ script.onerror = () => reject(/* @__PURE__ */ new Error("script load failed"));
2593
+ d.head.appendChild(script);
2594
+ });
2595
+ mermaidState = { status: "ready" };
2596
+ return true;
2597
+ }
2598
+ mermaidState = {
2599
+ status: "failed",
2600
+ error: result.error ?? "unknown"
2601
+ };
2602
+ return false;
2603
+ } catch (error) {
2604
+ mermaidState = {
2605
+ status: "failed",
2606
+ error: String(error?.message ?? error)
2607
+ };
2608
+ return false;
2609
+ }
2610
+ }
2611
+ async function renderMermaid(code) {
2612
+ try {
2613
+ const mermaid = (typeof window !== "undefined" ? window : null).mermaid;
2614
+ if (mermaid === void 0) return {
2615
+ ok: false,
2616
+ error: "引擎未就绪"
2617
+ };
2618
+ mermaid.initialize({
2619
+ startOnLoad: false,
2620
+ theme: "default",
2621
+ securityLevel: "loose"
2622
+ });
2623
+ const id = "vx-mmd-" + Date.now() + Math.floor(Math.random() * 9999);
2624
+ const out = await mermaid.render(id, code);
2625
+ const svg = typeof out === "string" ? out : out?.svg ?? "";
2626
+ if (svg === "") return {
2627
+ ok: false,
2628
+ error: "引擎未返回 SVG"
2629
+ };
2630
+ return {
2631
+ ok: true,
2632
+ svg
2633
+ };
2634
+ } catch (error) {
2635
+ return {
2636
+ ok: false,
2637
+ error: String(error?.message ?? error)
2638
+ };
2639
+ }
2640
+ }
2641
+ function extractMermaid(text) {
2642
+ const out = [];
2643
+ const re = /```mermaid\s*\n([\s\S]*?)```/gi;
2644
+ let m;
2645
+ while ((m = re.exec(text)) !== null) out.push(m[1].trim());
2646
+ return out;
2647
+ }
2648
+ function openMermaidOf(item) {
2649
+ const codes = extractMermaid(item.text);
2650
+ if (codes.length === 0) {
2651
+ toast("未找到 Mermaid 代码块", "error");
2652
+ return;
2653
+ }
2654
+ setS({ mermaidModal: {
2655
+ title: item.text.slice(0, 40),
2656
+ codes,
2657
+ index: 0
2658
+ } });
2659
+ }
2660
+ /** Peak-hour CNY unit prices per 1M tokens (official peak/off-peak table
2661
+ * effective 2026-08-17); off-peak hours are exactly half. deepseek-chat and
2662
+ * deepseek-reasoner were deprecated 2026-07-24 and both map onto
2663
+ * deepseek-v4-flash pricing. */
2664
+ function priceOf(model) {
2665
+ const peak = {
2666
+ "deepseek-v4-flash": {
2667
+ in: 3,
2668
+ cache: .1,
2669
+ out: 9
2670
+ },
2671
+ "deepseek-v4-pro": {
2672
+ in: 9,
2673
+ cache: .3,
2674
+ out: 27
2675
+ },
2676
+ "deepseek-chat": {
2677
+ in: 3,
2678
+ cache: .1,
2679
+ out: 9
2680
+ },
2681
+ "deepseek-reasoner": {
2682
+ in: 3,
2683
+ cache: .1,
2684
+ out: 9
2685
+ }
2686
+ };
2687
+ return peak[model] ?? peak["deepseek-v4-flash"];
2688
+ }
2689
+ async function refreshBalance() {
2690
+ try {
2691
+ const result = await apiBalanceGet();
2692
+ S.balance = result;
2693
+ setS({ balance: S.balance });
2694
+ } catch (error) {
2695
+ S.balance = {
2696
+ ok: false,
2697
+ error: String(error?.message ?? error)
2698
+ };
2699
+ setS({ balance: S.balance });
2700
+ }
2701
+ }
2702
+ async function refreshUsageScan() {
2703
+ try {
2704
+ const result = await apiUsageScan();
2705
+ if (result.ok === true) {
2706
+ S.usage = { ...S.usage };
2707
+ S.usage[dayKey()] = result.usageToday;
2708
+ setS({ usage: S.usage });
2709
+ toast(`已扫描今日会话日志(${String(result.scannedSessions)} 个今日活跃会话)`, "info");
2710
+ } else toast(result.error ?? "扫描失败", "error");
2711
+ } catch (error) {
2712
+ toast("扫描失败: " + String(error?.message ?? error), "error");
2713
+ }
2714
+ }
2715
+ function runExport(format) {
2716
+ if (S.sessionId === null) {
2717
+ toast("当前没有打开的会话", "error");
2718
+ return;
2719
+ }
2720
+ setS({ exporting: true });
2721
+ apiExportRun(S.sessionId, format).then((result) => {
2722
+ if (result.ok !== true) {
2723
+ toast(result.error ?? "导出失败", "error");
2724
+ return;
2725
+ }
2726
+ try {
2727
+ const d = typeof document !== "undefined" ? document : null;
2728
+ if (d === null) throw new Error("no document");
2729
+ const blob = new Blob([result.content], { type: result.mime });
2730
+ const url = URL.createObjectURL(blob);
2731
+ const a = d.createElement("a");
2732
+ a.href = url;
2733
+ a.download = result.fileName;
2734
+ d.body.appendChild(a);
2735
+ a.click();
2736
+ a.remove();
2737
+ setTimeout(() => {
2738
+ try {
2739
+ URL.revokeObjectURL(url);
2740
+ } catch {}
2741
+ }, 3e4);
2742
+ toast("已导出 " + result.fileName, "info");
2743
+ } catch (error) {
2744
+ toast("导出失败: " + String(error?.message ?? error), "error");
2745
+ }
2746
+ }).catch((error) => toast("导出失败: " + String(error?.message ?? error), "error")).finally(() => setS({ exporting: false }));
2747
+ }
2748
+ function findFolder(arr, id) {
2749
+ for (const f of arr) {
2750
+ if (f.id === id) return f;
2751
+ const child = findFolder(f.children ?? [], id);
2752
+ if (child !== null) return child;
2753
+ }
2754
+ return null;
2755
+ }
2756
+ function folderCount(node) {
2757
+ let n = (node.sessionIds ?? []).length + (node.workspaceIds ?? []).length;
2758
+ for (const child of node.children ?? []) n += folderCount(child);
2759
+ return n;
2760
+ }
2761
+ async function openWorkspaceItem(id) {
2762
+ const workspaces = C.get("workspaces");
2763
+ const sessions = C.get("sessions");
2764
+ if (workspaces === void 0 || sessions === void 0) {
2765
+ toast("工作区服务不可用", "error");
2766
+ return;
2767
+ }
2768
+ try {
2769
+ const sid = await workspaces.connectWorkspace(id);
2770
+ sessions.open(sid);
2771
+ toast("已打开项目", "info");
2772
+ } catch (error) {
2773
+ toast("打开项目失败: " + String(error?.message ?? error), "error");
2774
+ }
2775
+ }
2776
+ function openSessionItem(id) {
2777
+ const sessions = C.get("sessions");
2778
+ if (sessions === void 0) {
2779
+ toast("会话服务不可用", "error");
2780
+ return;
2781
+ }
2782
+ try {
2783
+ sessions.open(id);
2784
+ } catch (error) {
2785
+ toast("打开会话失败: " + String(error?.message ?? error), "error");
2786
+ }
2787
+ }
2788
+ function Toggle(props) {
2789
+ return react.createElement("label", { className: "vx-toggle-row" }, react.createElement("span", null, props.label), react.createElement("input", {
2790
+ type: "checkbox",
2791
+ checked: props.checked === true,
2792
+ onChange: (e) => {
2793
+ props.onChange(e.target.checked);
2794
+ saveCfg();
2795
+ }
2796
+ }), props.hint !== void 0 ? react.createElement("span", { className: "vx-muted" }, props.hint) : null);
2797
+ }
2798
+ function FolderSidebarButton() {
2799
+ return react.createElement("button", {
2800
+ className: "vx-foot-btn",
2801
+ title: "项目文件夹",
2802
+ onClick: () => setS({
2803
+ foldersOpen: !S.foldersOpen,
2804
+ panelOpen: false
2805
+ })
2806
+ }, react.createElement(Icon, {
2807
+ n: "folder",
2808
+ size: 15
2809
+ }), react.createElement("span", { className: "vx-foot-label" }, "项目"));
2810
+ }
2811
+ function HeaderPanelButton() {
2812
+ return react.createElement("button", {
2813
+ className: "vx-header-btn",
2814
+ title: "个性化中心",
2815
+ onClick: () => setS({
2816
+ panelOpen: !S.panelOpen,
2817
+ foldersOpen: false
2818
+ })
2819
+ }, react.createElement(Icon, {
2820
+ n: "sliders",
2821
+ size: 13
2822
+ }), react.createElement("span", null, "个性化"));
2823
+ }
2824
+ function PromptQuickButton() {
2825
+ return react.createElement("button", {
2826
+ className: "vx-header-btn",
2827
+ title: "快速调用提示词",
2828
+ onClick: (e) => {
2829
+ const r = e.currentTarget.getBoundingClientRect();
2830
+ setS({
2831
+ promptOpen: {
2832
+ x: Math.max(8, r.left),
2833
+ y: r.bottom + 6
2834
+ },
2835
+ promptQuery: ""
2836
+ });
2837
+ }
2838
+ }, react.createElement(Icon, {
2839
+ n: "zap",
2840
+ size: 13
2841
+ }), react.createElement("span", null, "提示词"));
2842
+ }
2843
+ function PromptPopover() {
2844
+ const s = useS();
2845
+ if (s.promptOpen === null) return null;
2846
+ const p = s.promptOpen;
2847
+ const q = (s.promptQuery ?? "").toLowerCase();
2848
+ const list = s.prompts.filter((x) => q === "" || String(x.name ?? "").toLowerCase().includes(q) || String(x.text ?? "").toLowerCase().includes(q));
2849
+ return react.createElement("div", {
2850
+ className: "vx-glass vx-prompt-pop",
2851
+ style: {
2852
+ left: p.x,
2853
+ top: p.y
2854
+ }
2855
+ }, react.createElement("div", { className: "vx-pattern" }), react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, "提示词库"), react.createElement("button", {
2856
+ className: "vx-chip",
2857
+ title: "关闭",
2858
+ onClick: () => setS({ promptOpen: null })
2859
+ }, react.createElement(Icon, {
2860
+ n: "x",
2861
+ size: 12
2862
+ }))), react.createElement("div", { className: "vx-row vx-pad-sm" }, react.createElement(Icon, {
2863
+ n: "search",
2864
+ size: 13
2865
+ }), react.createElement("input", {
2866
+ className: "vx-input",
2867
+ placeholder: "搜索提示词…",
2868
+ value: s.promptQuery,
2869
+ onChange: (e) => setS({ promptQuery: e.target.value })
2870
+ })), react.createElement("div", { className: "vx-list" }, list.length > 0 ? list.map((x) => react.createElement("button", {
2871
+ key: x.id,
2872
+ className: "vx-list-item",
2873
+ title: x.text,
2874
+ onClick: () => {
2875
+ const ok = S.insertDraft !== null ? S.insertDraft(x.text, false) : false;
2876
+ setS({ promptOpen: null });
2877
+ if (ok) toast("已插入提示词: " + x.name, "info");
2878
+ else toast("请在会话输入框中重试", "error");
2879
+ }
2880
+ }, react.createElement("div", { className: "vx-prompt-title" }, x.name), react.createElement("div", { className: "vx-prompt-body" }, x.text))) : react.createElement("div", { className: "vx-muted vx-pad-sm" }, "暂无匹配提示词")));
2881
+ }
2882
+ function HeaderBalance() {
2883
+ const s = useS();
2884
+ const b = s.balance;
2885
+ const [hover, setHover] = react.useState(false);
2886
+ const [pinned, setPinned] = react.useState(false);
2887
+ react.useEffect(() => {
2888
+ if (b === null) refreshBalance();
2889
+ }, []);
2890
+ const usageToday = s.usage[dayKey()] ?? {};
2891
+ const calls = Object.keys(usageToday).reduce((n, k) => n + (usageToday[k].calls ?? 0), 0);
2892
+ const bal = b?.ok === true && b.balance !== null && b.balance !== void 0 ? b.balance : null;
2893
+ const balance = bal !== null ? (bal.currency ?? "CNY") === "CNY" ? "¥" + (bal.total ?? "") : `${bal.total ?? ""} ${bal.currency ?? ""}` : b?.ok === false ? b.keyConfigured === true ? "额度?" : "未配置密钥" : "额度…";
2894
+ const open = hover || pinned;
2895
+ return react.createElement("span", { className: "vx-balance-wrap" }, react.createElement("span", {
2896
+ className: "vx-balance-text" + (pinned ? " vx-balance-pinned" : ""),
2897
+ title: pinned ? "再次点击取消固定" : "点击固定密钥面板",
2898
+ onClick: () => setPinned(!pinned),
2899
+ onMouseEnter: () => setHover(true),
2900
+ onMouseLeave: () => setHover(false)
2901
+ }, react.createElement(Icon, {
2902
+ n: "wallet",
2903
+ size: 13
2904
+ }), react.createElement("span", null, balance), calls > 0 ? react.createElement("span", { className: "vx-balance-today" }, `今日 ${calls} 次`) : null), open ? react.createElement("div", {
2905
+ className: "vx-glass vx-balance-hover",
2906
+ onMouseEnter: () => setHover(true),
2907
+ onMouseLeave: () => setHover(false)
2908
+ }, react.createElement("div", { className: "vx-pattern" }), pinned ? react.createElement("div", { className: "vx-balance-head" }, react.createElement("span", { className: "vx-muted" }, "已固定 · 再次点击「额度」或下方按钮取消"), react.createElement("button", {
2909
+ className: "vx-btn vx-btn-sm",
2910
+ onClick: () => setPinned(false)
2911
+ }, react.createElement(Icon, {
2912
+ n: "x",
2913
+ size: 12
2914
+ }), " 取消固定")) : null, react.createElement(BalancePanelContent, { onInteract: () => setPinned(true) })) : null);
2915
+ }
2916
+ function UsageTable() {
2917
+ const day = useS().usage[dayKey()] ?? {};
2918
+ const models = Object.keys(day);
2919
+ if (models.length === 0) return react.createElement("div", { className: "vx-muted" }, "今日暂无 token 用量记录");
2920
+ return react.createElement("div", null, react.createElement("table", { className: "vx-table" }, react.createElement("thead", null, react.createElement("tr", null, react.createElement("th", null, "模型"), react.createElement("th", null, "输入"), react.createElement("th", null, "缓存"), react.createElement("th", null, "输出"), react.createElement("th", null, "调用"), react.createElement("th", null, "费用 ¥"))), react.createElement("tbody", null, models.map((model) => {
2921
+ const row = day[model];
2922
+ const p = priceOf(model);
2923
+ const pin = row.peakIn ?? 0;
2924
+ const pcacheIn = row.peakCacheIn ?? 0;
2925
+ const pcacheW = row.peakCacheW ?? 0;
2926
+ const pout = row.peakOut ?? 0;
2927
+ const cost = (pin * p.in + pcacheIn * p.cache + pcacheW * p.in + pout * p.out + (((row.in ?? 0) - pin) * p.in + ((row.cacheIn ?? 0) - pcacheIn) * p.cache + ((row.cacheW ?? 0) - pcacheW) * p.in + ((row.out ?? 0) - pout) * p.out) / 2) / 1e6;
2928
+ return react.createElement("tr", { key: model }, react.createElement("td", null, model), react.createElement("td", null, row.in ?? 0), react.createElement("td", null, row.cacheIn ?? 0), react.createElement("td", null, row.out ?? 0), react.createElement("td", null, row.calls ?? 0), react.createElement("td", null, cost.toFixed(4)));
2929
+ }))), react.createElement("div", { className: "vx-muted" }, "费用按 DeepSeek 官方峰谷单价估算(¥/百万 tokens,高峰时段 9-12/14-18 时,空闲时段半价),仅供参考"));
2930
+ }
2931
+ function BalancePanelContent(props) {
2932
+ const s = useS();
2933
+ const b = s.balance;
2934
+ return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-row" }, react.createElement("input", {
2935
+ className: "vx-input",
2936
+ type: "password",
2937
+ placeholder: "DeepSeek API Key (sk-…)",
2938
+ value: s.apiKey,
2939
+ onFocus: () => {
2940
+ props.onInteract?.();
2941
+ },
2942
+ onChange: (e) => {
2943
+ setS({ apiKey: e.target.value });
2944
+ saveCfg();
2945
+ }
2946
+ }), react.createElement("button", {
2947
+ className: "vx-btn",
2948
+ onClick: () => {
2949
+ refreshBalance();
2950
+ }
2951
+ }, react.createElement(Icon, {
2952
+ n: "refresh",
2953
+ size: 13
2954
+ }), " 刷新")), react.createElement("div", { className: "vx-muted" }, "Key 仅保存在本机状态文件;留空时自动读取 DSH 已配置的 DeepSeek 凭据。"), b !== null && b.ok === true && b.balance !== null && b.balance !== void 0 ? (() => {
2955
+ const info = b.balance;
2956
+ const sym = (info.currency ?? "CNY") === "CNY" ? "¥" : `${info.currency ?? ""} `;
2957
+ 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 ? " · 余额不足不可用" : ""}`));
2958
+ })() : null, b !== null && b.ok === false ? react.createElement("div", { className: "vx-error" }, String(b.error ?? "未知错误")) : null, react.createElement("div", { className: "vx-section-title" }, "今日消费与 Token"), react.createElement(UsageTable, null), react.createElement("button", {
2959
+ className: "vx-btn",
2960
+ onClick: () => {
2961
+ refreshUsageScan();
2962
+ }
2963
+ }, react.createElement(Icon, {
2964
+ n: "list",
2965
+ size: 13
2966
+ }), " 扫描今日会话日志更新用量"));
2967
+ }
2968
+ function QuoteDock(props) {
2969
+ const s = useS();
2970
+ const inputRef = react.useRef(props.input);
2971
+ inputRef.current = props.input;
2972
+ const actionsRef = react.useRef(props.inputActions);
2973
+ actionsRef.current = props.inputActions;
2974
+ react.useEffect(() => {
2975
+ S.insertDraft = (text, replace) => {
2976
+ const actions = actionsRef.current;
2977
+ if (actions === void 0 || typeof actions.setDraft !== "function") return false;
2978
+ try {
2979
+ const current = inputRef.current?.draft ?? "";
2980
+ actions.setDraft(replace ? text : current !== "" ? current + "\n\n" + text : text);
2981
+ return true;
2982
+ } catch (error) {
2983
+ console.error("[custom-plugin] insertDraft", error);
2984
+ return false;
2985
+ }
2986
+ };
2987
+ S.quoteSetDraft = (text) => S.insertDraft !== null ? S.insertDraft(text, false) : false;
2988
+ return () => {
2989
+ S.insertDraft = null;
2990
+ S.quoteSetDraft = null;
2991
+ };
2992
+ }, []);
2993
+ react.useEffect(() => {
2994
+ if (s.cfg.quote !== true) {
2995
+ if (S.quoteSel !== null) setS({ quoteSel: null });
2996
+ return;
2997
+ }
2998
+ const d = typeof document !== "undefined" ? document : null;
2999
+ if (d === null) return;
3000
+ const inVxRoot = (node) => {
3001
+ let n = node;
3002
+ while (n !== null && n.nodeType === 1) {
3003
+ if (n.classList !== void 0 && n.classList.contains("vx-root")) return true;
3004
+ n = n.parentNode;
3005
+ }
3006
+ return false;
3007
+ };
3008
+ const onSel = () => {
3009
+ try {
3010
+ const sel = d.getSelection?.() ?? null;
3011
+ if (sel === null || sel.isCollapsed) {
3012
+ if (S.quoteSel !== null) setS({ quoteSel: null });
3013
+ return;
3014
+ }
3015
+ const text = String(sel.toString() ?? "").trim();
3016
+ if (text === "") {
3017
+ if (S.quoteSel !== null) setS({ quoteSel: null });
3018
+ return;
3019
+ }
3020
+ if (sel.rangeCount === 0) return;
3021
+ const range = sel.getRangeAt(0);
3022
+ if (inVxRoot(range.commonAncestorContainer)) return;
3023
+ const node = sel.anchorNode;
3024
+ if (node !== null && node.nodeType === 1 && /TEXTAREA|INPUT/.test(node.nodeName)) return;
3025
+ const r = range.getBoundingClientRect();
3026
+ setS({ quoteSel: {
3027
+ text: text.slice(0, 8e3),
3028
+ x: r.left + r.width / 2,
3029
+ y: r.top - 6
3030
+ } });
3031
+ } catch {}
3032
+ };
3033
+ d.addEventListener("selectionchange", onSel);
3034
+ return () => d.removeEventListener("selectionchange", onSel);
3035
+ }, [s.cfg.quote]);
3036
+ return null;
3037
+ }
3038
+ function QuoteButton() {
3039
+ const s = useS();
3040
+ if (s.quoteSel === null) return null;
3041
+ const q = s.quoteSel;
3042
+ const fmt = q.text.split("\n").map((l) => "> " + l).join("\n");
3043
+ return react.createElement("button", {
3044
+ className: "vx-quote-btn",
3045
+ style: {
3046
+ left: q.x,
3047
+ top: q.y
3048
+ },
3049
+ onClick: () => {
3050
+ const text = fmt + "\n\n";
3051
+ const ok = S.insertDraft !== null ? S.insertDraft(text, false) : false;
3052
+ if (!ok) toast("输入框不可用(当前不在会话中)", "error");
3053
+ try {
3054
+ (typeof document !== "undefined" ? document : null)?.getSelection()?.removeAllRanges();
3055
+ } catch {}
3056
+ setS({ quoteSel: null });
3057
+ if (ok) toast("已引用到输入框", "info");
3058
+ }
3059
+ }, react.createElement(Icon, {
3060
+ n: "quote",
3061
+ size: 12
3062
+ }), react.createElement("span", null, "引用回复"));
3063
+ }
3064
+ function TurnTailEntry(props) {
3065
+ const seq = props.matched !== void 0 && props.matched !== null ? props.matched : typeof props.seq === "number" ? props.seq : null;
3066
+ const turn = props.turn;
3067
+ const s = useS();
3068
+ const item = seq !== null && s.turns !== null && s.turns.sessionId === S.sessionId ? s.turns.items.find((t) => t.seq === seq) ?? null : null;
3069
+ const btns = [];
3070
+ if (item !== null && s.cfg.formula === true) {
3071
+ if (item.hasLatex === true) btns.push(react.createElement("button", {
3072
+ key: "lx",
3073
+ className: "vx-chip",
3074
+ title: "复制 LaTeX 公式",
3075
+ onClick: () => void copyLatexOf(item)
3076
+ }, react.createElement(Icon, {
3077
+ n: "copy",
3078
+ size: 11
3079
+ }), " LaTeX"));
3080
+ if (item.hasMathml === true) btns.push(react.createElement("button", {
3081
+ key: "mm",
3082
+ className: "vx-chip",
3083
+ title: "复制 MathML(可粘贴到 Word)",
3084
+ onClick: () => void copyMathmlOf(item)
3085
+ }, react.createElement(Icon, {
3086
+ n: "copy",
3087
+ size: 11
3088
+ }), " MathML"));
3089
+ }
3090
+ if (item !== null && s.cfg.mermaid === true && item.hasMermaid === true) btns.push(react.createElement("button", {
3091
+ key: "md",
3092
+ className: "vx-chip",
3093
+ title: "渲染 Mermaid 图表",
3094
+ onClick: () => openMermaidOf(item)
3095
+ }, react.createElement(Icon, {
3096
+ n: "gitBranch",
3097
+ size: 11
3098
+ }), " Mermaid"));
3099
+ return react.createElement("span", {
3100
+ className: "vx-anchor",
3101
+ "data-vx-seq": seq === null ? "" : String(seq),
3102
+ ref: (el) => {
3103
+ if (el !== null && seq !== null) S.anchors.set(seq, {
3104
+ el,
3105
+ turn: turn ?? null
3106
+ });
3107
+ else if (el === null && seq !== null) S.anchors.delete(seq);
3108
+ }
3109
+ }, btns.length > 0 ? react.createElement("span", { className: "vx-turn-actions" }, btns) : null);
3110
+ }
3111
+ function RailPopover() {
3112
+ const s = useS();
3113
+ const h = s.railHover;
3114
+ const popRef = react.useRef(null);
3115
+ react.useLayoutEffect(() => {
3116
+ const el = popRef.current;
3117
+ if (el === null || h === null) return;
3118
+ const rail = el.parentElement;
3119
+ if (rail === null) return;
3120
+ const base = Math.max(8, h.y - 90);
3121
+ el.style.top = base + "px";
3122
+ const over = el.offsetTop + el.offsetHeight - rail.clientHeight;
3123
+ if (over > 0) el.style.top = Math.max(8, base - over) + "px";
3124
+ }, [h?.seq, h?.y]);
3125
+ if (h === null) return null;
3126
+ const item = s.turns !== null && Array.isArray(s.turns.items) ? s.turns.items.find((x) => x.seq === h.seq) ?? null : null;
3127
+ if (item === null) return null;
3128
+ const starred = S.sessionId !== null && s.stars[S.sessionId]?.[h.seq] === true;
3129
+ const side = s.cfg.timelineLeft === true ? "left" : "right";
3130
+ return react.createElement("div", {
3131
+ ref: (el) => {
3132
+ popRef.current = el;
3133
+ },
3134
+ className: `vx-glass vx-rail-pop ${side}`,
3135
+ style: { top: Math.max(8, h.y - 90) },
3136
+ onMouseEnter: () => {
3137
+ if (S.railHoverTimer !== null) {
3138
+ clearTimeout(S.railHoverTimer);
3139
+ S.railHoverTimer = null;
3140
+ }
3141
+ },
3142
+ onMouseLeave: () => {
3143
+ S.railHoverTimer = setTimeout(() => setS({ railHover: null }), 350);
3144
+ }
3145
+ }, 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", {
3146
+ className: "vx-chip",
3147
+ onClick: () => scrollToSeq(h.seq)
3148
+ }, react.createElement(Icon, {
3149
+ n: "arrowDown",
3150
+ size: 11
3151
+ }), " 跳转"), react.createElement("button", {
3152
+ className: "vx-chip",
3153
+ onClick: () => toggleStar(h.seq)
3154
+ }, react.createElement(Icon, {
3155
+ n: "star",
3156
+ size: 11,
3157
+ filled: starred
3158
+ }), starred ? " 已星标" : " 星标"), react.createElement("button", {
3159
+ className: "vx-chip",
3160
+ onClick: () => void forkAt(h.seq)
3161
+ }, react.createElement(Icon, {
3162
+ n: "fork",
3163
+ size: 11
3164
+ }), " 分支"), react.createElement("button", {
3165
+ className: "vx-chip",
3166
+ onClick: () => void copyText(item.text).then((ok) => toast(ok ? "已复制全文" : "复制失败", ok ? "info" : "error"))
3167
+ }, react.createElement(Icon, {
3168
+ n: "copy",
3169
+ size: 11
3170
+ }), " 全文")), item.hasLatex === true || item.hasMathml === true || item.hasMermaid === true ? react.createElement("div", { className: "vx-pop-row" }, item.hasLatex === true ? react.createElement("button", {
3171
+ className: "vx-chip",
3172
+ onClick: () => void copyLatexOf(item)
3173
+ }, "LaTeX") : null, item.hasMathml === true ? react.createElement("button", {
3174
+ className: "vx-chip",
3175
+ onClick: () => void copyMathmlOf(item)
3176
+ }, "MathML") : null, item.hasMermaid === true ? react.createElement("button", {
3177
+ className: "vx-chip",
3178
+ onClick: () => openMermaidOf(item)
3179
+ }, "Mermaid") : null) : null);
3180
+ }
3181
+ function TimelineRail(props) {
3182
+ const s = useS();
3183
+ const sessions = useSessionsSafe(props);
3184
+ const current = sessions !== null ? sessions.current ?? null : null;
3185
+ const summary = current !== null ? sessions.byId[current] : null;
3186
+ const trackRef = react.useRef(null);
3187
+ react.useEffect(() => {
3188
+ if (current !== null && current !== S.sessionId) {
3189
+ setS({
3190
+ sessionId: current,
3191
+ turns: null,
3192
+ railPositions: [],
3193
+ railSig: "",
3194
+ railHover: null
3195
+ });
3196
+ fetchTurns(String(current));
3197
+ } else if (current === null && S.sessionId !== null) setS({
3198
+ sessionId: null,
3199
+ turns: null,
3200
+ railPositions: [],
3201
+ railSig: "",
3202
+ railHover: null
3203
+ });
3204
+ }, [current]);
3205
+ react.useEffect(() => {
3206
+ if (s.cfg.timeline !== true || S.sessionId === null) return;
3207
+ const handle = setInterval(() => {
3208
+ if (summary !== null && summary.running === true) fetchTurns(S.sessionId);
3209
+ }, 3e3);
3210
+ return () => clearInterval(handle);
3211
+ }, [s.cfg.timeline, current]);
3212
+ react.useEffect(() => {
3213
+ if (s.cfg.timeline !== true || S.sessionId === null) return;
3214
+ const el = trackRef.current;
3215
+ if (el === null) return;
3216
+ const fromPopover = (e) => e.target instanceof Element && e.target.closest(".vx-rail-pop") !== null;
3217
+ const down = (e) => {
3218
+ const scroller = S.scrollerEl;
3219
+ if (scroller === null || !scroller.isConnected) return;
3220
+ if (fromPopover(e)) return;
3221
+ e.preventDefault();
3222
+ const rect = el.getBoundingClientRect();
3223
+ const startY = e.clientY;
3224
+ const startScroll = scroller.scrollTop ?? 0;
3225
+ const scrollH = Math.max(1, (scroller.scrollHeight ?? 1) - (scroller.clientHeight ?? rect.height));
3226
+ const onMove = (ev) => {
3227
+ const delta = (ev.clientY - startY) / Math.max(1, rect.height) * scrollH;
3228
+ scroller.scrollTop = Math.max(0, Math.min(scrollH, startScroll + delta));
3229
+ };
3230
+ const onUp = () => {
3231
+ const w = typeof window !== "undefined" ? window : null;
3232
+ if (w !== null) {
3233
+ w.removeEventListener("pointermove", onMove);
3234
+ w.removeEventListener("pointerup", onUp);
3235
+ }
3236
+ };
3237
+ const w = typeof window !== "undefined" ? window : null;
3238
+ if (w !== null) {
3239
+ w.addEventListener("pointermove", onMove);
3240
+ w.addEventListener("pointerup", onUp);
3241
+ }
3242
+ };
3243
+ el.addEventListener("pointerdown", down);
3244
+ const onWheel = (e) => {
3245
+ const scroller = S.scrollerEl;
3246
+ if (scroller === null || !scroller.isConnected) return;
3247
+ if (fromPopover(e)) return;
3248
+ e.preventDefault();
3249
+ const floor = Math.max(0, (scroller.scrollHeight ?? 1) - (scroller.clientHeight ?? 0));
3250
+ scroller.scrollTop = Math.max(0, Math.min(floor, (scroller.scrollTop ?? 0) + (e.deltaY || 0)));
3251
+ };
3252
+ el.addEventListener("wheel", onWheel, { passive: false });
3253
+ return () => {
3254
+ el.removeEventListener("pointerdown", down);
3255
+ el.removeEventListener("wheel", onWheel);
3256
+ };
3257
+ }, [
3258
+ s.cfg.timeline,
3259
+ s.sessionId,
3260
+ s.scrollerEl
3261
+ ]);
3262
+ if (s.cfg.timeline !== true || S.sessionId === null) return null;
3263
+ const right = s.cfg.timelineLeft !== true;
3264
+ const dots = s.railPositions.filter((p) => s.cfg.starsOnly !== true || p.st);
3265
+ return react.createElement("div", {
3266
+ ref: trackRef,
3267
+ className: `vx-rail ${right ? "right" : "left"}`,
3268
+ style: {
3269
+ top: s.railBox.top,
3270
+ height: s.railBox.height,
3271
+ ...right ? { right: s.railRight } : { left: s.railLeft }
3272
+ }
3273
+ }, react.createElement("div", {
3274
+ className: "vx-thumb",
3275
+ style: {
3276
+ top: s.thumbTop,
3277
+ height: s.thumbH
3278
+ }
3279
+ }), dots.map((p) => react.createElement("button", {
3280
+ key: p.seq,
3281
+ className: "vx-dot" + (p.st ? " star" : ""),
3282
+ style: { top: p.y },
3283
+ onMouseEnter: () => {
3284
+ if (S.railHoverTimer !== null) clearTimeout(S.railHoverTimer);
3285
+ setS({ railHover: {
3286
+ seq: p.seq,
3287
+ y: p.y
3288
+ } });
3289
+ },
3290
+ onMouseLeave: () => {
3291
+ S.railHoverTimer = setTimeout(() => setS({ railHover: null }), 350);
3292
+ },
3293
+ onClick: () => scrollToSeq(p.seq)
3294
+ })), react.createElement(RailPopover, null));
3295
+ }
3296
+ function AppearanceTab() {
3297
+ const s = useS();
3298
+ const dark = s.dark === true;
3299
+ const set = (k, v) => {
3300
+ setS({ cfg: {
3301
+ ...s.cfg,
3302
+ [k]: v
3303
+ } });
3304
+ saveCfg();
3305
+ };
3306
+ 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", {
3307
+ key: "default",
3308
+ className: "vx-swatch" + (s.cfg.bg === "default" ? " on" : ""),
3309
+ onClick: () => set("bg", "default"),
3310
+ title: "无颜色(默认主题)"
3311
+ }, react.createElement("span", {
3312
+ className: "vx-swatch-box",
3313
+ style: { background: "repeating-conic-gradient(#ccc 0 25%, #eee 0 50%) 0 0/10px 10px" }
3314
+ }), react.createElement("span", { className: "vx-swatch-label" }, "无颜色")), react.createElement("button", {
3315
+ key: "aurora",
3316
+ className: "vx-swatch" + (s.cfg.bg === "aurora" ? " on" : ""),
3317
+ onClick: () => set("bg", "aurora"),
3318
+ title: "极光渐变(保留高饱和)"
3319
+ }, react.createElement("span", {
3320
+ className: "vx-swatch-box",
3321
+ style: { background: "linear-gradient(135deg,#8fa8d8,#b59fd8,#8fc4b4,#d8a8c0)" }
3322
+ }), react.createElement("span", { className: "vx-swatch-label" }, "极光")), PALETTE.map((p) => react.createElement("button", {
3323
+ key: p[0],
3324
+ disabled: dark,
3325
+ className: "vx-swatch" + (s.cfg.bg === p[0] ? " on" : ""),
3326
+ onClick: () => set("bg", p[0]),
3327
+ title: p[0] + " " + p[1] + (dark ? "(深色模式禁用)" : "")
3328
+ }, react.createElement("span", {
3329
+ className: "vx-swatch-box",
3330
+ style: { background: p[1] }
3331
+ }), react.createElement("span", { className: "vx-swatch-label" }, p[0])))), react.createElement("div", { className: "vx-section-title" }, "天气特效"), react.createElement("div", { className: "vx-row wrap" }, [
3332
+ "none",
3333
+ "snow",
3334
+ "rain",
3335
+ "sakura"
3336
+ ].map((w) => {
3337
+ return react.createElement("button", {
3338
+ key: w,
3339
+ className: "vx-btn" + (s.cfg.weather === w ? " on" : ""),
3340
+ onClick: () => set("weather", w)
3341
+ }, react.createElement(Icon, {
3342
+ n: {
3343
+ none: "minimize",
3344
+ snow: "snowflake",
3345
+ rain: "cloudRain",
3346
+ sakura: "flower"
3347
+ }[w],
3348
+ size: 12
3349
+ }), " " + {
3350
+ none: "无",
3351
+ snow: "飘雪",
3352
+ rain: "电影感雨滴",
3353
+ sakura: "樱花飘落"
3354
+ }[w]);
3355
+ })), react.createElement("div", { className: "vx-section-title" }, "玻璃效果"), react.createElement(Toggle, {
3356
+ label: "启用玻璃",
3357
+ checked: s.cfg.glass === true,
3358
+ onChange: (v) => set("glass", v)
3359
+ }), react.createElement("div", { className: "vx-row wrap" }, react.createElement("button", {
3360
+ className: "vx-btn" + (s.cfg.glassMode !== "liquid" ? " on" : ""),
3361
+ onClick: () => set("glassMode", "frost")
3362
+ }, "毛玻璃"), react.createElement("button", {
3363
+ className: "vx-btn" + (s.cfg.glassMode === "liquid" ? " on" : ""),
3364
+ onClick: () => set("glassMode", "liquid")
3365
+ }, "液态玻璃")), react.createElement("div", { className: "vx-muted" }, "在 Chromium 启用液态玻璃,Safari/Firefox 自动回退毛玻璃。"), react.createElement(Toggle, {
3366
+ label: "全局浮层玻璃",
3367
+ checked: s.cfg.globalGlass === true,
3368
+ onChange: (v) => set("globalGlass", v),
3369
+ hint: "对弹窗/菜单等浮层应用模糊,不改变圆角与边框"
3370
+ }));
3371
+ }
3372
+ function FolderNode(props) {
3373
+ const s = useS();
3374
+ const node = props.node;
3375
+ const depth = props.depth ?? 0;
3376
+ const [open, setOpen] = react.useState(true);
3377
+ const sessions = useSessionsSafe(props);
3378
+ const byId = sessions !== null ? sessions.byId : {};
3379
+ const workspaces = useWorkspacesSafe(props);
3380
+ const wsItems = workspaces !== null && workspaces.items !== void 0 ? workspaces.items : [];
3381
+ const wsTitle = (w) => w.title || w.path || w.workspaceId;
3382
+ const addChildFolder = () => {
3383
+ askText("文件夹名称:", "", (name) => {
3384
+ const folders = JSON.parse(JSON.stringify(S.folders));
3385
+ const target = findFolder(folders, node.id);
3386
+ if (target === null) return;
3387
+ target.children = target.children ?? [];
3388
+ target.children.push({
3389
+ id: "f" + Date.now() + Math.floor(Math.random() * 9999),
3390
+ name,
3391
+ children: [],
3392
+ sessionIds: [],
3393
+ workspaceIds: [],
3394
+ prompts: []
3395
+ });
3396
+ setS({ folders });
3397
+ saveCfg();
3398
+ });
3399
+ };
3400
+ const renameFolder = () => {
3401
+ askText("重命名文件夹:", node.name, (name) => {
3402
+ const folders = JSON.parse(JSON.stringify(S.folders));
3403
+ const target = findFolder(folders, node.id);
3404
+ if (target !== null) target.name = name;
3405
+ setS({ folders });
3406
+ saveCfg();
3407
+ });
3408
+ };
3409
+ const delFolder = () => {
3410
+ askConfirm(`删除文件夹「${node.name}」及其子文件夹?(会话与提示词不会被删除)`, (ok) => {
3411
+ if (!ok) return;
3412
+ const folders = JSON.parse(JSON.stringify(S.folders));
3413
+ const cut = (arr) => {
3414
+ for (let i = 0; i < arr.length; i++) {
3415
+ if (arr[i].id === node.id) {
3416
+ arr.splice(i, 1);
3417
+ return true;
3418
+ }
3419
+ if (cut(arr[i].children ?? [])) return true;
3420
+ }
3421
+ return false;
3422
+ };
3423
+ cut(folders);
3424
+ setS({ folders });
3425
+ saveCfg();
3426
+ });
3427
+ };
3428
+ const removeRef = (kind, id) => {
3429
+ const folders = JSON.parse(JSON.stringify(S.folders));
3430
+ const target = findFolder(folders, node.id);
3431
+ if (target === null) return;
3432
+ if (kind === "session") target.sessionIds = (target.sessionIds ?? []).filter((x) => x !== id);
3433
+ else target.workspaceIds = (target.workspaceIds ?? []).filter((x) => x !== id);
3434
+ setS({ folders });
3435
+ saveCfg();
3436
+ };
3437
+ const moveNode = (srcId, targetId, mode) => {
3438
+ if (srcId === "" || srcId === targetId) return;
3439
+ const folders = JSON.parse(JSON.stringify(S.folders));
3440
+ let src = null;
3441
+ const take = (arr) => {
3442
+ for (let i = 0; i < arr.length; i++) {
3443
+ if (arr[i].id === srcId) {
3444
+ src = arr.splice(i, 1)[0];
3445
+ return true;
3446
+ }
3447
+ if (take(arr[i].children ?? [])) return true;
3448
+ }
3449
+ return false;
3450
+ };
3451
+ const place = (arr) => {
3452
+ for (const f of arr) {
3453
+ if (f.id === targetId) {
3454
+ if (mode === "inside") (f.children = f.children ?? []).push(src);
3455
+ else if (mode === "before") arr.splice(arr.indexOf(f), 0, src);
3456
+ else arr.splice(arr.indexOf(f) + 1, 0, src);
3457
+ return true;
3458
+ }
3459
+ if (place(f.children ?? [])) return true;
3460
+ }
3461
+ return false;
3462
+ };
3463
+ if (src !== null && take(folders) && place(folders)) {
3464
+ setS({ folders });
3465
+ saveCfg();
3466
+ }
3467
+ };
3468
+ const rowDrop = (e) => {
3469
+ e.preventDefault();
3470
+ e.stopPropagation();
3471
+ const srcId = S.dragFolder;
3472
+ const hint = S.dropHint;
3473
+ setS({
3474
+ dragFolder: null,
3475
+ dropHint: null
3476
+ });
3477
+ if (srcId !== null) moveNode(srcId, node.id, hint !== null && hint.zone !== null ? hint.zone : "inside");
3478
+ };
3479
+ const rowOver = (e) => {
3480
+ e.preventDefault();
3481
+ e.stopPropagation();
3482
+ const r = e.currentTarget.getBoundingClientRect();
3483
+ const y = e.clientY - r.top;
3484
+ const zone = y < r.height * .28 ? "before" : y > r.height * .72 ? "after" : "inside";
3485
+ if (S.dropHint === null || S.dropHint.id !== node.id || S.dropHint.zone !== zone) setS({ dropHint: {
3486
+ id: node.id,
3487
+ zone
3488
+ } });
3489
+ };
3490
+ const rowLeave = () => {
3491
+ if (S.dropHint !== null && S.dropHint.id === node.id) setS({ dropHint: null });
3492
+ };
3493
+ const adding = s.folderAdd === node.id;
3494
+ const pickingWs = s.folderWsPick === node.id;
3495
+ const hintZone = s.dropHint !== null && s.dropHint.id === node.id ? s.dropHint.zone : null;
3496
+ const children = node.children ?? [];
3497
+ const sessIds = node.sessionIds ?? [];
3498
+ const wsIds = node.workspaceIds ?? [];
3499
+ return react.createElement("div", { className: "vx-folder" }, react.createElement("div", {
3500
+ className: "vx-folder-head" + (hintZone === "inside" ? " drop-inside" : hintZone === "before" ? " drop-before" : hintZone === "after" ? " drop-after" : ""),
3501
+ draggable: true,
3502
+ onDragStart: (e) => {
3503
+ setS({ dragFolder: node.id });
3504
+ try {
3505
+ e.dataTransfer.setData("text/plain", node.id);
3506
+ } catch {}
3507
+ },
3508
+ onDragEnd: () => setS({
3509
+ dragFolder: null,
3510
+ dropHint: null
3511
+ }),
3512
+ onDragOver: rowOver,
3513
+ onDragLeave: rowLeave,
3514
+ onDrop: rowDrop
3515
+ }, react.createElement("button", {
3516
+ className: "vx-mini",
3517
+ title: open ? "折叠" : "展开",
3518
+ onClick: (e) => {
3519
+ e.stopPropagation();
3520
+ setOpen(!open);
3521
+ }
3522
+ }, react.createElement(Icon, {
3523
+ n: open ? "chevronDown" : "chevronRight",
3524
+ size: 12
3525
+ })), react.createElement(Icon, {
3526
+ n: "folder",
3527
+ size: 14
3528
+ }), react.createElement("span", {
3529
+ className: "vx-folder-name",
3530
+ title: node.name
3531
+ }, node.name), react.createElement("span", { className: "vx-badge" }, folderCount(node)), react.createElement("button", {
3532
+ className: "vx-mini",
3533
+ title: "重命名",
3534
+ onClick: (e) => {
3535
+ e.stopPropagation();
3536
+ renameFolder();
3537
+ }
3538
+ }, react.createElement(Icon, {
3539
+ n: "sliders",
3540
+ size: 11
3541
+ })), react.createElement("button", {
3542
+ className: "vx-mini",
3543
+ title: "删除",
3544
+ onClick: (e) => {
3545
+ e.stopPropagation();
3546
+ delFolder();
3547
+ }
3548
+ }, react.createElement(Icon, {
3549
+ n: "trash",
3550
+ size: 11
3551
+ }))), open ? react.createElement("div", { className: "vx-folder-body" }, children.map((c) => react.createElement(FolderNode, {
3552
+ key: c.id,
3553
+ node: c,
3554
+ depth: depth + 1,
3555
+ useSessions: props.useSessions,
3556
+ useWorkspaces: props.useWorkspaces
3557
+ })), wsIds.map((wid) => {
3558
+ const w = wsItems.find((x) => x.workspaceId === wid);
3559
+ if (w === void 0) return null;
3560
+ return react.createElement("div", {
3561
+ key: "w" + wid,
3562
+ className: "vx-item-row"
3563
+ }, react.createElement(Icon, {
3564
+ n: "briefcase",
3565
+ size: 12
3566
+ }), react.createElement("button", {
3567
+ className: "vx-item-name",
3568
+ title: wsTitle(w),
3569
+ onClick: () => void openWorkspaceItem(wid)
3570
+ }, wsTitle(w)), react.createElement("button", {
3571
+ className: "vx-mini",
3572
+ title: "移出",
3573
+ onClick: () => removeRef("workspace", wid)
3574
+ }, react.createElement(Icon, {
3575
+ n: "x",
3576
+ size: 10
3577
+ })));
3578
+ }), sessIds.map((sid) => {
3579
+ const sum = byId[sid];
3580
+ const name = sum !== void 0 ? sum.displayTitle || sum.title || sid : sid;
3581
+ return react.createElement("div", {
3582
+ key: "s" + sid,
3583
+ className: "vx-item-row"
3584
+ }, react.createElement(Icon, {
3585
+ n: "message",
3586
+ size: 12
3587
+ }), react.createElement("button", {
3588
+ className: "vx-item-name",
3589
+ title: name,
3590
+ onClick: () => openSessionItem(sid)
3591
+ }, name), react.createElement("button", {
3592
+ className: "vx-mini",
3593
+ title: "移出",
3594
+ onClick: () => removeRef("session", sid)
3595
+ }, react.createElement(Icon, {
3596
+ n: "x",
3597
+ size: 10
3598
+ })));
3599
+ }), react.createElement("div", { className: "vx-row vx-pad-sm" }, react.createElement("button", {
3600
+ className: "vx-btn vx-btn-sm",
3601
+ onClick: () => setS({
3602
+ folderAdd: adding ? null : node.id,
3603
+ folderWsPick: null
3604
+ })
3605
+ }, react.createElement(Icon, {
3606
+ n: "plus",
3607
+ size: 11
3608
+ }), " 添加"), adding ? react.createElement("button", {
3609
+ className: "vx-btn vx-btn-sm",
3610
+ onClick: () => setS({ folderWsPick: pickingWs ? null : node.id })
3611
+ }, react.createElement(Icon, {
3612
+ n: "briefcase",
3613
+ size: 11
3614
+ }), " 工作区") : null), adding ? react.createElement("div", { className: "vx-form" }, react.createElement("button", {
3615
+ className: "vx-btn vx-btn-sm",
3616
+ onClick: addChildFolder
3617
+ }, react.createElement(Icon, {
3618
+ n: "folderPlus",
3619
+ size: 11
3620
+ }), " 新建子文件夹"), S.sessionId !== null ? react.createElement("button", {
3621
+ className: "vx-btn vx-btn-sm",
3622
+ onClick: () => {
3623
+ const folders = JSON.parse(JSON.stringify(S.folders));
3624
+ const target = findFolder(folders, node.id);
3625
+ if (target !== null) {
3626
+ target.sessionIds = target.sessionIds ?? [];
3627
+ if (target.sessionIds.indexOf(S.sessionId) < 0) target.sessionIds.push(S.sessionId);
3628
+ }
3629
+ setS({
3630
+ folders,
3631
+ folderAdd: null
3632
+ });
3633
+ saveCfg();
3634
+ }
3635
+ }, react.createElement(Icon, {
3636
+ n: "message",
3637
+ size: 11
3638
+ }), " 添加当前会话") : null, pickingWs ? react.createElement("div", { className: "vx-list" }, wsItems.filter((w) => wsIds.indexOf(w.workspaceId) < 0).map((w) => react.createElement("button", {
3639
+ key: w.workspaceId,
3640
+ className: "vx-list-item",
3641
+ onClick: () => {
3642
+ const folders = JSON.parse(JSON.stringify(S.folders));
3643
+ const target = findFolder(folders, node.id);
3644
+ if (target !== null) {
3645
+ target.workspaceIds = target.workspaceIds ?? [];
3646
+ if (target.workspaceIds.indexOf(w.workspaceId) < 0) target.workspaceIds.push(w.workspaceId);
3647
+ }
3648
+ setS({
3649
+ folders,
3650
+ folderAdd: null,
3651
+ folderWsPick: null
3652
+ });
3653
+ saveCfg();
3654
+ }
3655
+ }, wsTitle(w)))) : null) : null) : null);
3656
+ }
3657
+ function FoldersTab(props) {
3658
+ const addRoot = () => {
3659
+ askText("文件夹名称:", "", (name) => {
3660
+ const folders = JSON.parse(JSON.stringify(S.folders));
3661
+ folders.push({
3662
+ id: "f" + Date.now() + Math.floor(Math.random() * 9999),
3663
+ name,
3664
+ children: [],
3665
+ sessionIds: [],
3666
+ workspaceIds: [],
3667
+ prompts: []
3668
+ });
3669
+ setS({ folders });
3670
+ saveCfg();
3671
+ });
3672
+ };
3673
+ return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-muted" }, "跨工作区共享的会话与工作区收藏夹,支持多级嵌套与拖拽排序;数据保存在本机状态文件。"), S.folders.length === 0 ? react.createElement("div", { className: "vx-muted vx-pad-sm" }, "暂无文件夹,点击下方按钮创建。") : null, S.folders.map((f) => react.createElement(FolderNode, {
3674
+ key: f.id,
3675
+ node: f,
3676
+ depth: 0,
3677
+ useSessions: props.useSessions,
3678
+ useWorkspaces: props.useWorkspaces
3679
+ })), react.createElement("div", { className: "vx-row vx-pad-sm" }, react.createElement("button", {
3680
+ className: "vx-btn",
3681
+ onClick: addRoot
3682
+ }, react.createElement(Icon, {
3683
+ n: "folderPlus",
3684
+ size: 13
3685
+ }), " 新建文件夹")));
3686
+ }
3687
+ function PromptsTab() {
3688
+ const addPrompt = () => {
3689
+ askText("提示词名称:", "", (name) => {
3690
+ askText("提示词内容:", "", (text) => {
3691
+ if (text.trim() === "") {
3692
+ toast("内容不能为空", "error");
3693
+ return;
3694
+ }
3695
+ S.prompts = S.prompts.concat({
3696
+ id: "p" + Date.now() + Math.floor(Math.random() * 9999),
3697
+ name: name || "未命名",
3698
+ text
3699
+ });
3700
+ setS({ prompts: S.prompts });
3701
+ saveCfg();
3702
+ });
3703
+ });
3704
+ };
3705
+ const delPrompt = (id) => {
3706
+ S.prompts = S.prompts.filter((x) => x.id !== id);
3707
+ setS({ prompts: S.prompts });
3708
+ saveCfg();
3709
+ };
3710
+ return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-muted" }, "常用提示词收藏;点击会话顶部的「提示词」按钮搜索插入,也可直接复制。"), S.prompts.map((p) => react.createElement("div", {
3711
+ key: p.id,
3712
+ className: "vx-prompt-card"
3713
+ }, react.createElement("div", { className: "vx-row" }, react.createElement("span", { className: "vx-prompt-title" }, p.name), react.createElement("span", { className: "vx-flex1" }), react.createElement("button", {
3714
+ className: "vx-mini",
3715
+ title: "复制",
3716
+ onClick: () => void copyText(p.text).then((ok) => toast(ok ? "已复制提示词" : "复制失败", ok ? "info" : "error"))
3717
+ }, react.createElement(Icon, {
3718
+ n: "copy",
3719
+ size: 11
3720
+ })), react.createElement("button", {
3721
+ className: "vx-mini",
3722
+ title: "删除",
3723
+ onClick: () => delPrompt(p.id)
3724
+ }, react.createElement(Icon, {
3725
+ n: "trash",
3726
+ size: 11
3727
+ }))), react.createElement("div", { className: "vx-prompt-body" }, p.text))), react.createElement("div", { className: "vx-row vx-pad-sm" }, react.createElement("button", {
3728
+ className: "vx-btn",
3729
+ onClick: addPrompt
3730
+ }, react.createElement(Icon, {
3731
+ n: "plus",
3732
+ size: 13
3733
+ }), " 新增提示词")));
3734
+ }
3735
+ function TimelineTab() {
3736
+ const s = useS();
3737
+ const set = (k, v) => {
3738
+ setS({ cfg: {
3739
+ ...s.cfg,
3740
+ [k]: v
3741
+ } });
3742
+ saveCfg();
3743
+ };
3744
+ return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-muted" }, "为每条用户消息生成导航节点:悬停预览、点击跳转,支持星标与分支。"), react.createElement(Toggle, {
3745
+ label: "显示时间线",
3746
+ checked: s.cfg.timeline === true,
3747
+ onChange: (v) => set("timeline", v)
3748
+ }), react.createElement(Toggle, {
3749
+ label: "时间线在左侧",
3750
+ checked: s.cfg.timelineLeft === true,
3751
+ onChange: (v) => set("timelineLeft", v)
3752
+ }), react.createElement(Toggle, {
3753
+ label: "仅显示星标",
3754
+ checked: s.cfg.starsOnly === true,
3755
+ onChange: (v) => set("starsOnly", v)
3756
+ }));
3757
+ }
3758
+ function ExportTab() {
3759
+ const s = useS();
3760
+ return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-muted" }, "将当前会话导出为文件:JSON 可导入其他工具,Markdown 便于阅读分享,PDF 内嵌图片(打印时另存为 PDF)。"), react.createElement("div", { className: "vx-row wrap" }, react.createElement("button", {
3761
+ className: "vx-btn big",
3762
+ disabled: s.exporting === true,
3763
+ onClick: () => runExport("json")
3764
+ }, react.createElement(Icon, {
3765
+ n: "download",
3766
+ size: 14
3767
+ }), " JSON"), react.createElement("button", {
3768
+ className: "vx-btn big",
3769
+ disabled: s.exporting === true,
3770
+ onClick: () => runExport("markdown")
3771
+ }, react.createElement(Icon, {
3772
+ n: "download",
3773
+ size: 14
3774
+ }), " Markdown"), react.createElement("button", {
3775
+ className: "vx-btn big",
3776
+ disabled: s.exporting === true,
3777
+ onClick: () => runExport("pdf")
3778
+ }, react.createElement(Icon, {
3779
+ n: "download",
3780
+ size: 14
3781
+ }), " PDF(含图片)")), s.exporting === true ? react.createElement("div", { className: "vx-muted vx-pad-sm" }, "导出中…") : null);
3782
+ }
3783
+ function MermaidTab() {
3784
+ const [engine, setEngine] = react.useState(mermaidState.status);
3785
+ const aliveRef = react.useRef(true);
3786
+ react.useEffect(() => {
3787
+ const t = new Promise((resolve) => setTimeout(resolve, 300)).then(() => {
3788
+ if (aliveRef.current) setEngine(mermaidState.status);
3789
+ }).catch(() => {});
3790
+ return () => {
3791
+ aliveRef.current = false;
3792
+ try {
3793
+ t.catch(() => {});
3794
+ } catch {}
3795
+ };
3796
+ }, []);
3797
+ const load = async () => {
3798
+ setEngine("loading");
3799
+ const ok = await ensureMermaid();
3800
+ if (!aliveRef.current) return;
3801
+ setEngine(ok ? "ready" : "failed");
3802
+ toast(ok ? "Mermaid 引擎已就绪" : "加载失败:可改用 mermaid.live 按钮", ok ? "info" : "error");
3803
+ };
3804
+ return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-muted vx-pad-sm" }, "消息中的 Mermaid 代码块可就地渲染为图表;渲染失败可一键跳转 mermaid.live 在线编辑。"), react.createElement(Toggle, {
3805
+ label: "显示 Mermaid 渲染按钮",
3806
+ checked: S.cfg.mermaid === true,
3807
+ onChange: (v) => {
3808
+ setS({ cfg: {
3809
+ ...S.cfg,
3810
+ mermaid: v
3811
+ } });
3812
+ saveCfg();
3813
+ }
3814
+ }), react.createElement("div", { className: "vx-row" }, react.createElement("button", {
3815
+ className: "vx-btn",
3816
+ onClick: () => void load()
3817
+ }, react.createElement(Icon, {
3818
+ n: "gitBranch",
3819
+ size: 12
3820
+ }), engine === "ready" ? " 引擎已就绪" : engine === "loading" ? " 加载中…" : " 预加载渲染引擎"), react.createElement("span", { className: "vx-muted" }, engine === "failed" ? "加载失败(可能需代理)" : "")));
3821
+ }
3822
+ function ToolsTab() {
3823
+ const s = useS();
3824
+ const set = (k, v) => {
3825
+ setS({ cfg: {
3826
+ ...s.cfg,
3827
+ [k]: v
3828
+ } });
3829
+ saveCfg();
3830
+ };
3831
+ return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-section-title" }, "效率工具"), react.createElement(Toggle, {
3832
+ label: "引用回复",
3833
+ checked: s.cfg.quote === true,
3834
+ onChange: (v) => set("quote", v),
3835
+ hint: "选中对话文本后出现引用按钮(个性化面板内不触发)"
3836
+ }), react.createElement(Toggle, {
3837
+ label: "防自动跳转",
3838
+ checked: s.cfg.antiScroll === true,
3839
+ onChange: (v) => set("antiScroll", v),
3840
+ hint: "拦截发送后强制滚动到底部"
3841
+ }), react.createElement(Toggle, {
3842
+ label: "公式复制",
3843
+ checked: s.cfg.formula === true,
3844
+ onChange: (v) => set("formula", v),
3845
+ hint: "消息下方显示 LaTeX/MathML 复制按钮"
3846
+ }), react.createElement("div", { className: "vx-row vx-pad-sm" }, react.createElement("button", {
3847
+ className: "vx-btn vx-btn-danger",
3848
+ onClick: () => setS({ batchModal: true })
3849
+ }, react.createElement(Icon, {
3850
+ n: "trash",
3851
+ size: 13
3852
+ }), " 批量归档会话")));
3853
+ }
3854
+ function AboutTab() {
3855
+ const [info, setInfo] = react.useState(null);
3856
+ const loadInfo = async () => {
3857
+ try {
3858
+ setInfo(await apiDebugInfo());
3859
+ } catch {
3860
+ setInfo({ ok: false });
3861
+ }
3862
+ };
3863
+ react.useEffect(() => {
3864
+ loadInfo();
3865
+ }, []);
3866
+ 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", {
3867
+ className: "vx-btn",
3868
+ onClick: () => void loadInfo()
3869
+ }, react.createElement(Icon, {
3870
+ n: "refresh",
3871
+ size: 12
3872
+ }), " 刷新调试信息"));
3873
+ }
3874
+ function AskModal() {
3875
+ const s = useS();
3876
+ const [val, setVal] = react.useState("");
3877
+ react.useEffect(() => {
3878
+ if (s.ask !== null) setVal(s.ask.value ?? "");
3879
+ }, [s.ask?.title]);
3880
+ const ask = s.ask;
3881
+ if (ask === null) return null;
3882
+ const submit = () => {
3883
+ const cb = ask.cb;
3884
+ setS({ ask: null });
3885
+ if (val.trim() !== "") cb(val.trim());
3886
+ };
3887
+ return react.createElement("div", {
3888
+ className: "vx-modal-mask",
3889
+ onClick: () => setS({ ask: null })
3890
+ }, react.createElement("div", {
3891
+ className: "vx-glass vx-modal",
3892
+ style: { width: "min(360px, 92vw)" },
3893
+ onClick: (e) => e.stopPropagation()
3894
+ }, react.createElement("div", { className: "vx-pattern" }), react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, ask.title)), react.createElement("input", {
3895
+ className: "vx-input",
3896
+ value: val,
3897
+ autoFocus: true,
3898
+ onChange: (e) => setVal(e.target.value),
3899
+ onKeyDown: (e) => {
3900
+ if (e.key === "Enter") submit();
3901
+ }
3902
+ }), react.createElement("div", { className: "vx-row vx-pad-sm" }, react.createElement("button", {
3903
+ className: "vx-btn",
3904
+ onClick: submit
3905
+ }, "确定"), react.createElement("button", {
3906
+ className: "vx-btn",
3907
+ onClick: () => setS({ ask: null })
3908
+ }, "取消"))));
3909
+ }
3910
+ function ConfirmModal() {
3911
+ const s = useS();
3912
+ if (s.confirmAsk === null) return null;
3913
+ const c = s.confirmAsk;
3914
+ const answer = (ok) => {
3915
+ const cb = c.cb;
3916
+ setS({ confirmAsk: null });
3917
+ cb(ok);
3918
+ };
3919
+ return react.createElement("div", {
3920
+ className: "vx-modal-mask",
3921
+ onClick: () => answer(false)
3922
+ }, react.createElement("div", {
3923
+ className: "vx-glass vx-modal",
3924
+ style: { width: "min(380px, 92vw)" },
3925
+ onClick: (e) => e.stopPropagation()
3926
+ }, 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", {
3927
+ className: "vx-btn vx-btn-danger",
3928
+ onClick: () => answer(true)
3929
+ }, "确定"), react.createElement("button", {
3930
+ className: "vx-btn",
3931
+ onClick: () => answer(false)
3932
+ }, "取消"))));
3933
+ }
3934
+ function MermaidModal() {
3935
+ const mm = useS().mermaidModal;
3936
+ const [svg, setSvg] = react.useState(null);
3937
+ const [err, setErr] = react.useState(null);
3938
+ const [loading, setLoading] = react.useState(false);
3939
+ const [liveUrl, setLiveUrl] = react.useState("#");
3940
+ react.useEffect(() => {
3941
+ if (mm === null) return;
3942
+ let alive = true;
3943
+ setSvg(null);
3944
+ setErr(null);
3945
+ setLoading(true);
3946
+ (async () => {
3947
+ const url = await mermaidLiveUrl(mm.codes[mm.index]);
3948
+ if (!alive) return;
3949
+ setLiveUrl(url);
3950
+ const ready = await ensureMermaid();
3951
+ if (!alive) return;
3952
+ if (!ready) {
3953
+ setErr("Mermaid 引擎加载失败(网络不可达?)。可点击下方按钮在 mermaid.live 打开");
3954
+ setLoading(false);
3955
+ return;
3956
+ }
3957
+ const r = await renderMermaid(mm.codes[mm.index]);
3958
+ if (!alive) return;
3959
+ if (r.ok === true) setSvg(r.svg);
3960
+ else setErr(r.error);
3961
+ setLoading(false);
3962
+ })();
3963
+ return () => {
3964
+ alive = false;
3965
+ };
3966
+ }, [mm?.index]);
3967
+ if (mm === null) return null;
3968
+ return react.createElement("div", {
3969
+ className: "vx-modal-mask",
3970
+ onClick: () => setS({ mermaidModal: null })
3971
+ }, react.createElement("div", {
3972
+ className: "vx-glass vx-modal",
3973
+ onClick: (e) => e.stopPropagation()
3974
+ }, 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", {
3975
+ className: "vx-chip",
3976
+ title: "上一个",
3977
+ onClick: () => setS({ mermaidModal: {
3978
+ ...mm,
3979
+ index: (mm.index + mm.codes.length - 1) % mm.codes.length
3980
+ } })
3981
+ }, react.createElement(Icon, {
3982
+ n: "chevronRight",
3983
+ size: 12,
3984
+ style: { transform: "rotate(180deg)" }
3985
+ })) : null, mm.codes.length > 1 ? react.createElement("button", {
3986
+ className: "vx-chip",
3987
+ title: "下一个",
3988
+ onClick: () => setS({ mermaidModal: {
3989
+ ...mm,
3990
+ index: (mm.index + 1) % mm.codes.length
3991
+ } })
3992
+ }, react.createElement(Icon, {
3993
+ n: "chevronRight",
3994
+ size: 12
3995
+ })) : null, react.createElement("a", {
3996
+ className: "vx-chip vx-link",
3997
+ href: liveUrl,
3998
+ target: "_blank",
3999
+ rel: "noopener noreferrer"
4000
+ }, "在 mermaid.live 打开"), react.createElement("button", {
4001
+ className: "vx-chip",
4002
+ title: "关闭",
4003
+ onClick: () => setS({ mermaidModal: null })
4004
+ }, react.createElement(Icon, {
4005
+ n: "x",
4006
+ size: 12
4007
+ })))), loading ? react.createElement("div", { className: "vx-muted vx-pad" }, "渲染中…") : null, err !== null ? react.createElement("div", { className: "vx-error vx-pad" }, err) : null, svg !== null ? react.createElement("div", {
4008
+ className: "vx-svgbox",
4009
+ dangerouslySetInnerHTML: { __html: svg }
4010
+ }) : null));
4011
+ }
4012
+ function BatchModal(props) {
4013
+ useS();
4014
+ const [sel, setSel] = react.useState({});
4015
+ const [q, setQ] = react.useState("");
4016
+ const sessions = useSessionsSafe(props);
4017
+ const ids = sessions !== null ? sessions.ids ?? [] : [];
4018
+ const byId = sessions !== null ? sessions.byId : {};
4019
+ const filtered = ids.filter((id) => {
4020
+ const sum = byId[id];
4021
+ if (sum === void 0) return false;
4022
+ if (q !== "") {
4023
+ if (!String(sum.displayTitle || sum.title || id).toLowerCase().includes(q.toLowerCase())) return false;
4024
+ }
4025
+ return true;
4026
+ });
4027
+ const selCount = Object.keys(sel).length;
4028
+ const batchArchive = (targetIds) => {
4029
+ const workspaces = C.get("workspaces");
4030
+ if (workspaces === void 0 || typeof workspaces.archiveSession !== "function") {
4031
+ toast("归档服务不可用", "error");
4032
+ return;
4033
+ }
4034
+ let done = 0;
4035
+ const run = () => {
4036
+ if (done >= targetIds.length) {
4037
+ toast(`已归档 ${targetIds.length} 个会话`, "info");
4038
+ setS({ batchModal: false });
4039
+ return;
4040
+ }
4041
+ const id = targetIds[done++];
4042
+ workspaces.archiveSession(id).then(run).catch(() => run());
4043
+ };
4044
+ run();
4045
+ };
4046
+ return react.createElement("div", {
4047
+ className: "vx-modal-mask",
4048
+ onClick: () => setS({ batchModal: false })
4049
+ }, react.createElement("div", {
4050
+ className: "vx-glass vx-modal",
4051
+ style: { width: "min(560px, 92vw)" },
4052
+ onClick: (e) => e.stopPropagation()
4053
+ }, react.createElement("div", { className: "vx-pattern" }), react.createElement("div", { className: "vx-pop-head" }, react.createElement("span", null, "批量归档会话"), react.createElement("button", {
4054
+ className: "vx-chip",
4055
+ title: "关闭",
4056
+ onClick: () => setS({ batchModal: false })
4057
+ }, react.createElement(Icon, {
4058
+ n: "x",
4059
+ size: 12
4060
+ }))), react.createElement("div", { className: "vx-muted vx-pad-sm" }, "将选中的会话归档(从会话列表移除,日志仍保留,可在存储中找回)"), react.createElement("div", { className: "vx-row vx-pad-sm" }, react.createElement(Icon, {
4061
+ n: "search",
4062
+ size: 13
4063
+ }), react.createElement("input", {
4064
+ className: "vx-input",
4065
+ placeholder: "搜索会话…",
4066
+ value: q,
4067
+ onChange: (e) => setQ(e.target.value)
4068
+ }), react.createElement("button", {
4069
+ className: "vx-btn",
4070
+ onClick: () => {
4071
+ const all = {};
4072
+ for (const id of filtered) all[id] = true;
4073
+ setSel(all);
4074
+ }
4075
+ }, "全选"), react.createElement("button", {
4076
+ className: "vx-btn",
4077
+ onClick: () => setSel({})
4078
+ }, "清空")), react.createElement("div", { className: "vx-list" }, filtered.map((id) => {
4079
+ const sum = byId[id];
4080
+ return react.createElement("label", {
4081
+ key: id,
4082
+ className: "vx-check-row"
4083
+ }, react.createElement("input", {
4084
+ type: "checkbox",
4085
+ checked: sel[id] === true,
4086
+ onChange: (e) => {
4087
+ const next = { ...sel };
4088
+ if (e.target.checked) next[id] = true;
4089
+ else delete next[id];
4090
+ setSel(next);
4091
+ }
4092
+ }), react.createElement("span", { className: "vx-check-title" }, sum !== void 0 ? sum.displayTitle || sum.title || id : id), sum !== void 0 && sum.running === true ? react.createElement("span", { className: "vx-badge" }, "运行中") : null);
4093
+ })), react.createElement("div", { className: "vx-row vx-pad-sm" }, react.createElement("button", {
4094
+ className: "vx-btn vx-btn-danger",
4095
+ disabled: selCount === 0,
4096
+ onClick: () => askConfirm(`确认归档选中的 ${selCount} 个会话?`, (ok) => {
4097
+ if (ok) batchArchive(Object.keys(sel));
4098
+ })
4099
+ }, react.createElement(Icon, {
4100
+ n: "trash",
4101
+ size: 12
4102
+ }), ` 归档选中 (${selCount})`), react.createElement("button", {
4103
+ className: "vx-btn",
4104
+ onClick: () => setS({ batchModal: false })
4105
+ }, "取消"))));
4106
+ }
4107
+ function PanelBody(props) {
4108
+ const s = useS();
4109
+ if (s.panelTab === "look") return react.createElement(AppearanceTab, null);
4110
+ if (s.panelTab === "folder") return react.createElement(FoldersTab, {
4111
+ useSessions: props.useSessions,
4112
+ useWorkspaces: props.useWorkspaces
4113
+ });
4114
+ if (s.panelTab === "prompt") return react.createElement(PromptsTab, null);
4115
+ if (s.panelTab === "timeline") return react.createElement(TimelineTab, null);
4116
+ if (s.panelTab === "export") return react.createElement(ExportTab, null);
4117
+ if (s.panelTab === "mermaid") return react.createElement(MermaidTab, null);
4118
+ if (s.panelTab === "tools") return react.createElement(ToolsTab, null);
4119
+ if (s.panelTab === "balance") return react.createElement(BalancePanelContent, null);
4120
+ return react.createElement(AboutTab, null);
4121
+ }
4122
+ function PersonalizePanel(props) {
4123
+ const s = useS();
4124
+ const ref = react.useRef(null);
4125
+ const TABS = [
4126
+ [
4127
+ "look",
4128
+ "sliders",
4129
+ "外观"
4130
+ ],
4131
+ [
4132
+ "folder",
4133
+ "folder",
4134
+ "项目"
4135
+ ],
4136
+ [
4137
+ "prompt",
4138
+ "zap",
4139
+ "提示词"
4140
+ ],
4141
+ [
4142
+ "timeline",
4143
+ "clock",
4144
+ "时间线"
4145
+ ],
4146
+ [
4147
+ "export",
4148
+ "download",
4149
+ "导出"
4150
+ ],
4151
+ [
4152
+ "mermaid",
4153
+ "gitBranch",
4154
+ "Mermaid"
4155
+ ],
4156
+ [
4157
+ "tools",
4158
+ "wrench",
4159
+ "效率"
4160
+ ],
4161
+ [
4162
+ "balance",
4163
+ "wallet",
4164
+ "额度"
4165
+ ],
4166
+ [
4167
+ "about",
4168
+ "info",
4169
+ "关于"
4170
+ ]
4171
+ ];
4172
+ const onHeadDown = (e) => {
4173
+ const target = e.target;
4174
+ if (target.tagName === "BUTTON" || target.tagName === "A" || target.tagName === "INPUT") return;
4175
+ const el = ref.current;
4176
+ if (el === null) return;
4177
+ const rect = el.getBoundingClientRect();
4178
+ const start = {
4179
+ mx: e.clientX,
4180
+ my: e.clientY,
4181
+ x: rect.left,
4182
+ y: rect.top
4183
+ };
4184
+ const d = typeof document !== "undefined" ? document : null;
4185
+ if (d === null) return;
4186
+ const move = (ev) => setS({ panelPos: {
4187
+ x: start.x + ev.clientX - start.mx,
4188
+ y: start.y + ev.clientY - start.my
4189
+ } });
4190
+ const up = () => {
4191
+ d.removeEventListener("mousemove", move);
4192
+ d.removeEventListener("mouseup", up);
4193
+ };
4194
+ d.addEventListener("mousemove", move);
4195
+ d.addEventListener("mouseup", up);
4196
+ };
4197
+ const style = {
4198
+ top: 74,
4199
+ left: void 0,
4200
+ right: void 0
4201
+ };
4202
+ if (s.panelPos !== null) {
4203
+ style.top = s.panelPos.y;
4204
+ style.left = s.panelPos.x;
4205
+ style.right = void 0;
4206
+ } else style.right = 76;
4207
+ return react.createElement("div", {
4208
+ ref,
4209
+ className: "vx-glass vx-panel",
4210
+ style
4211
+ }, react.createElement("div", { className: "vx-pattern" }), react.createElement("div", {
4212
+ className: "vx-panel-head",
4213
+ onMouseDown: onHeadDown
4214
+ }, react.createElement(Icon, {
4215
+ n: "sliders",
4216
+ size: 14
4217
+ }), react.createElement("span", { className: "vx-panel-title" }, "个性化中心"), react.createElement("span", { className: "vx-panel-sub" }, "外观 · 效率 · 额度"), react.createElement("span", { className: "vx-flex1" }), react.createElement("button", {
4218
+ className: "vx-chip",
4219
+ title: "关闭",
4220
+ onClick: () => setS({ panelOpen: false })
4221
+ }, react.createElement(Icon, {
4222
+ n: "x",
4223
+ size: 12
4224
+ }))), react.createElement("div", { className: "vx-tabs" }, TABS.map((t) => react.createElement("button", {
4225
+ key: t[0],
4226
+ className: "vx-tab" + (s.panelTab === t[0] ? " on" : ""),
4227
+ onClick: () => setS({ panelTab: t[0] })
4228
+ }, react.createElement(Icon, {
4229
+ n: t[1],
4230
+ size: 12
4231
+ }), " " + t[2]))), react.createElement("div", { className: "vx-panel-body" }, react.createElement(PanelBody, {
4232
+ useSessions: props.useSessions,
4233
+ useWorkspaces: props.useWorkspaces
4234
+ })));
4235
+ }
4236
+ function SidebarFoldersPanel(props) {
4237
+ if (useS().foldersOpen !== true) return null;
4238
+ 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, {
4239
+ n: "folder",
4240
+ size: 14
4241
+ }), react.createElement("span", null, "项目文件夹"), react.createElement("span", { className: "vx-flex1" }), react.createElement("button", {
4242
+ className: "vx-chip",
4243
+ title: "新建文件夹",
4244
+ onClick: () => askText("文件夹名称:", "", (name) => {
4245
+ if (name.trim() === "") return;
4246
+ S.folders = S.folders.concat({
4247
+ id: "f" + Date.now() + Math.floor(Math.random() * 9999),
4248
+ name,
4249
+ children: [],
4250
+ sessionIds: [],
4251
+ workspaceIds: [],
4252
+ prompts: []
4253
+ });
4254
+ setS({ folders: S.folders });
4255
+ saveCfg();
4256
+ })
4257
+ }, react.createElement(Icon, {
4258
+ n: "folderPlus",
4259
+ size: 12
4260
+ })), react.createElement("button", {
4261
+ className: "vx-chip",
4262
+ title: "关闭",
4263
+ onClick: () => setS({ foldersOpen: false })
4264
+ }, react.createElement(Icon, {
4265
+ n: "x",
4266
+ size: 12
4267
+ }))), react.createElement("div", { className: "vx-folders-body" }, S.folders.length === 0 ? react.createElement("div", { className: "vx-muted vx-pad-sm" }, "暂无文件夹。在个性化中心可管理,或点击右上角新建。") : null, S.folders.map((f) => react.createElement(FolderNode, {
4268
+ key: f.id,
4269
+ node: f,
4270
+ depth: 0,
4271
+ useSessions: props.useSessions,
4272
+ useWorkspaces: props.useWorkspaces
4273
+ }))));
4274
+ }
4275
+ function SettingsPage() {
4276
+ 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));
4277
+ }
4278
+ function Toasts() {
4279
+ const s = useS();
4280
+ return react.createElement("div", { className: "vx-toasts" }, s.toasts.map((t) => react.createElement("div", {
4281
+ key: t.id,
4282
+ className: "vx-toast" + (t.kind === "error" ? " err" : "")
4283
+ }, react.createElement(Icon, {
4284
+ n: t.kind === "error" ? "x" : t.kind === "success" ? "check" : "info",
4285
+ size: 13
4286
+ }), react.createElement("span", null, t.text), t.action !== null ? react.createElement("button", {
4287
+ className: "vx-chip",
4288
+ onClick: () => {
4289
+ try {
4290
+ t.action?.run();
4291
+ } catch {}
4292
+ }
4293
+ }, t.action.label) : null)));
4294
+ }
4295
+ function OverlayRoot(props) {
4296
+ const s = useS();
4297
+ /** 当前 GUI 实际配色。主题服务已解析的快照最权威(覆盖 GUI 内全局深色
4298
+ * 切换,与 OS 偏好无关);其次 body 上呈现器维护的 data-ds-dark-theme;
4299
+ * 最后兜底操作系统 prefers-color-scheme。 */
4300
+ const readDark = () => {
4301
+ try {
4302
+ const theme = C.get("theme");
4303
+ if (theme !== void 0) {
4304
+ const scheme = theme.getTheme()?.active?.colorScheme;
4305
+ if (scheme === "dark") return true;
4306
+ if (scheme === "light") return false;
4307
+ }
4308
+ } catch {}
4309
+ const d = typeof document !== "undefined" ? document : null;
4310
+ if (d !== null && d.body !== null && d.body.hasAttribute("data-ds-dark-theme")) return true;
4311
+ const w = typeof window !== "undefined" ? window : null;
4312
+ if (w !== null && w.matchMedia !== void 0 && w.matchMedia("(prefers-color-scheme: dark)").matches) return true;
4313
+ return false;
4314
+ };
4315
+ react.useEffect(() => {
4316
+ loadCfg();
4317
+ }, []);
4318
+ react.useEffect(() => {
4319
+ if (s.booted) applyAppearance();
4320
+ }, [
4321
+ s.booted,
4322
+ s.cfg.bg,
4323
+ s.cfg.glass,
4324
+ s.cfg.glassMode,
4325
+ s.cfg.globalGlass
4326
+ ]);
4327
+ react.useEffect(() => {
4328
+ syncAntiScroll(s.cfg.antiScroll === true);
4329
+ }, [s.cfg.antiScroll]);
4330
+ react.useEffect(() => {
4331
+ const w = typeof window !== "undefined" ? window : null;
4332
+ const d = typeof document !== "undefined" ? document : null;
4333
+ const applyDark = (dark) => {
4334
+ S.dark = dark;
4335
+ if (dark && S.booted && S.cfg.bg !== "default" && S.cfg.bg !== "aurora") {
4336
+ S.cfg = {
4337
+ ...S.cfg,
4338
+ bg: "default"
4339
+ };
4340
+ saveCfg();
4341
+ }
4342
+ setS({ dark });
4343
+ };
4344
+ applyDark(readDark());
4345
+ let offTheme;
4346
+ try {
4347
+ offTheme = C.on("theme/change", (snap) => applyDark(snap.active?.colorScheme === "dark"));
4348
+ } catch {}
4349
+ let mq;
4350
+ let onMq;
4351
+ if (w !== null && w.matchMedia !== void 0) {
4352
+ mq = w.matchMedia("(prefers-color-scheme: dark)");
4353
+ onMq = () => applyDark(readDark());
4354
+ if (typeof mq.addEventListener === "function") mq.addEventListener("change", onMq);
4355
+ else if (typeof mq.addListener === "function") mq.addListener(onMq);
4356
+ }
4357
+ let observer = null;
4358
+ if (d !== null && d.body !== null && typeof MutationObserver === "function") {
4359
+ observer = new MutationObserver(() => applyDark(readDark()));
4360
+ observer.observe(d.body, {
4361
+ attributes: true,
4362
+ attributeFilter: ["data-ds-dark-theme"]
4363
+ });
4364
+ }
4365
+ return () => {
4366
+ if (offTheme !== void 0) try {
4367
+ offTheme();
4368
+ } catch {}
4369
+ if (mq !== void 0 && onMq !== void 0) {
4370
+ if (typeof mq.removeEventListener === "function") mq.removeEventListener("change", onMq);
4371
+ else if (typeof mq.removeListener === "function") mq.removeListener(onMq);
4372
+ }
4373
+ if (observer !== null) observer.disconnect();
4374
+ };
4375
+ }, []);
4376
+ react.useEffect(() => {
4377
+ const dark = readDark();
4378
+ S.dark = dark;
4379
+ if (dark && S.booted && S.cfg.bg !== "default" && S.cfg.bg !== "aurora") {
4380
+ S.cfg = {
4381
+ ...S.cfg,
4382
+ bg: "default"
4383
+ };
4384
+ setS({ cfg: S.cfg });
4385
+ saveCfg();
4386
+ } else setS({ dark });
4387
+ }, [s.booted]);
4388
+ react.useEffect(() => {
4389
+ const tick = () => {
4390
+ const d = typeof document !== "undefined" ? document : null;
4391
+ if (d !== null && d.visibilityState === "hidden") return;
4392
+ updateRailPositions();
4393
+ };
4394
+ const stop = setInterval(tick, 450);
4395
+ const d = typeof document !== "undefined" ? document : null;
4396
+ const w = typeof window !== "undefined" ? window : null;
4397
+ const h = () => tick();
4398
+ if (d !== null) {
4399
+ d.addEventListener("scroll", h, true);
4400
+ d.addEventListener("visibilitychange", h);
4401
+ }
4402
+ if (w !== null) w.addEventListener("resize", h);
4403
+ return () => {
4404
+ clearInterval(stop);
4405
+ if (d !== null) {
4406
+ d.removeEventListener("scroll", h, true);
4407
+ d.removeEventListener("visibilitychange", h);
4408
+ }
4409
+ if (w !== null) w.removeEventListener("resize", h);
4410
+ };
4411
+ }, []);
4412
+ react.useEffect(() => {
4413
+ const w = typeof window !== "undefined" ? window : null;
4414
+ if (w === null || w.MutationObserver === void 0) return;
4415
+ const scroller = s.scrollerEl;
4416
+ if (scroller === null || !scroller.isConnected) return;
4417
+ let timer = null;
4418
+ const observer = new MutationObserver(() => {
4419
+ if (timer !== null) clearTimeout(timer);
4420
+ timer = setTimeout(() => {
4421
+ updateRailPositions();
4422
+ }, 120);
4423
+ });
4424
+ observer.observe(scroller, {
4425
+ childList: true,
4426
+ subtree: true
4427
+ });
4428
+ return () => {
4429
+ observer.disconnect();
4430
+ if (timer !== null) clearTimeout(timer);
4431
+ };
4432
+ }, [s.scrollerEl]);
4433
+ const children = [react.createElement(FxCanvas, { key: "fx" })];
4434
+ children.push(react.createElement(TimelineRail, {
4435
+ key: "rail",
4436
+ useSessions: props.useSessions,
4437
+ useWorkspaces: props.useWorkspaces
4438
+ }));
4439
+ if (s.panelOpen === true) children.push(react.createElement(PersonalizePanel, {
4440
+ key: "panel",
4441
+ useSessions: props.useSessions,
4442
+ useWorkspaces: props.useWorkspaces
4443
+ }));
4444
+ if (s.foldersOpen === true) children.push(react.createElement(SidebarFoldersPanel, {
4445
+ key: "folders",
4446
+ useSessions: props.useSessions,
4447
+ useWorkspaces: props.useWorkspaces
4448
+ }));
4449
+ if (s.promptOpen !== null) children.push(react.createElement(PromptPopover, { key: "prompt" }));
4450
+ if (s.mermaidModal !== null) children.push(react.createElement(MermaidModal, { key: "mermaid" }));
4451
+ if (s.batchModal === true) children.push(react.createElement(BatchModal, {
4452
+ key: "batch",
4453
+ useSessions: props.useSessions
4454
+ }));
4455
+ if (s.quoteSel !== null && s.cfg.quote === true) children.push(react.createElement(QuoteButton, { key: "quote" }));
4456
+ if (s.ask !== null) children.push(react.createElement(AskModal, { key: "ask" }));
4457
+ if (s.confirmAsk !== null) children.push(react.createElement(ConfirmModal, { key: "confirm" }));
4458
+ children.push(react.createElement(Toasts, { key: "toasts" }));
4459
+ return react.createElement("div", { className: "vx-root" }, children);
4460
+ }
4461
+ setDynCss("");
4462
+ try {
4463
+ ensureLiquidGlass();
4464
+ } catch (error) {
4465
+ reportDiag("ensureLiquidGlass: " + String(error?.message ?? error));
4466
+ }
4467
+ const slots = C.get("slots");
4468
+ if (slots === void 0) {
4469
+ console.error("[custom-plugin] slots service unavailable");
4470
+ reportDiag("slots service unavailable; surfaces skipped");
4471
+ return () => {};
4472
+ }
4473
+ const unregisterAll = [];
4474
+ const injectOne = (key, id, options, comp) => {
4475
+ try {
4476
+ slots.inject(key, () => {
4477
+ const unregister = slots.register({
4478
+ name: key,
4479
+ ...options
4480
+ }, comp);
4481
+ unregisterAll.push(unregister);
4482
+ return unregister;
4483
+ });
4484
+ reportDiag("ok " + key + " (" + id + ")");
4485
+ return true;
4486
+ } catch (error) {
4487
+ const message = "inject " + key + " (" + id + "): " + String(error?.message ?? error);
4488
+ console.error("[custom-plugin] " + message);
4489
+ reportDiag(message);
4490
+ return false;
4491
+ }
4492
+ };
4493
+ injectOne("sidebar.footer.action", "custom-plugin-folders", {
4494
+ id: "custom-plugin-folders",
4495
+ order: -100,
4496
+ label: "项目"
4497
+ }, FolderSidebarButton);
4498
+ injectOne("shell.overlay", "custom-plugin-overlay", {
4499
+ id: "custom-plugin-overlay",
4500
+ order: 10,
4501
+ label: "Custom 便利套件"
4502
+ }, OverlayRoot);
4503
+ injectOne("conversation.input.dock", "custom-plugin-quote", {
4504
+ id: "custom-plugin-quote",
4505
+ order: 30,
4506
+ label: "引用回复"
4507
+ }, QuoteDock);
4508
+ injectOne("conversation.chat.turnTail", "custom-plugin-turn-tail", { select: (o) => o !== null && typeof o.seq === "number" ? o.seq : null }, TurnTailEntry);
4509
+ injectOne("settings.section", "custom-plugin-appearance", {
4510
+ id: "custom-plugin-appearance",
4511
+ order: 30,
4512
+ label: "个性化"
4513
+ }, SettingsPage);
4514
+ injectOne("conversation.session.header.actions", "custom-plugin-panel-open", {
4515
+ id: "custom-plugin-panel-open",
4516
+ order: 5,
4517
+ label: "个性化"
4518
+ }, HeaderPanelButton);
4519
+ injectOne("conversation.session.header.actions", "custom-plugin-prompts", {
4520
+ id: "custom-plugin-prompts",
4521
+ order: 6,
4522
+ label: "提示词"
4523
+ }, PromptQuickButton);
4524
+ injectOne("conversation.session.header.utilities", "custom-plugin-balance", {
4525
+ id: "custom-plugin-balance",
4526
+ order: -5,
4527
+ label: "额度"
4528
+ }, HeaderBalance);
4529
+ console.log("[custom-plugin] client registered");
4530
+ return () => {
4531
+ for (const unregister of unregisterAll.splice(0)) try {
4532
+ unregister();
4533
+ } catch {}
4534
+ removeDynCss();
4535
+ };
4536
+ }
4537
+ //#endregion
4538
+ //#region src/client/index.ts
4539
+ /**
4540
+ * Required services. Deliberately empty: every surface is looked up lazily
4541
+ * (with a graceful no-op fallback), so this plugin can never sit "pending
4542
+ * (waiting for services)" — a fiber that waits on a service name the client
4543
+ * runtime never provides would block the whole web boot behind the
4544
+ * "Loading plugins…" gate forever.
4545
+ */
4546
+ const inject = [];
4547
+ /**
4548
+ * Mount the Custom suite.
4549
+ * @param ctx - client root context.
4550
+ */
4551
+ function apply(ctx) {
4552
+ ctx.effect(() => {
4553
+ try {
4554
+ return installCustomPlugin(ctx, apiDiagReport);
4555
+ } catch (error) {
4556
+ const message = `install failed: ${String(error?.message ?? error)}`;
4557
+ console.error(`[custom-plugin] ${message}`);
4558
+ apiDiagReport(message);
4559
+ return () => {};
4560
+ }
4561
+ }, "custom-plugin: surfaces");
4562
+ }
4563
+ //#endregion
4564
+ exports.apply = apply;
4565
+ exports.inject = inject;
4566
+ return module.exports;
4567
+ }
4568
+ });
4569
+
4570
+ //# sourceMappingURL=client.js.map