@dsh-teamwork/dsh-teamwork 0.7.0 → 0.8.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.
Files changed (56) hide show
  1. package/README.md +108 -2
  2. package/icon.svg +4 -0
  3. package/lib/aes-gcm.js +22 -0
  4. package/lib/aes-gcm.js.map +1 -0
  5. package/lib/assistant-tools.js +421 -0
  6. package/lib/assistant-tools.js.map +1 -0
  7. package/lib/bridge.js +127 -8
  8. package/lib/bridge.js.map +1 -1
  9. package/lib/client.js +185 -8
  10. package/lib/client.js.map +1 -1
  11. package/lib/index.js +149 -38
  12. package/lib/index.js.map +1 -1
  13. package/lib/local-share.js +87 -0
  14. package/lib/local-share.js.map +1 -0
  15. package/lib/panel.js +9 -0
  16. package/lib/panel.js.map +1 -1
  17. package/lib/phone-security.js +283 -0
  18. package/lib/phone-security.js.map +1 -0
  19. package/lib/phone-session.js +20 -0
  20. package/lib/phone-session.js.map +1 -0
  21. package/lib/phone-uploads.js +136 -0
  22. package/lib/phone-uploads.js.map +1 -0
  23. package/lib/preset-context.js +1 -1
  24. package/lib/preset-context.js.map +1 -1
  25. package/lib/relay.js +9 -4
  26. package/lib/relay.js.map +1 -1
  27. package/lib/secure-channel.js +398 -0
  28. package/lib/secure-channel.js.map +1 -0
  29. package/lib/types/aes-gcm.d.ts +3 -0
  30. package/lib/types/aes-gcm.d.ts.map +1 -0
  31. package/lib/types/assistant-tools.d.ts +7 -0
  32. package/lib/types/assistant-tools.d.ts.map +1 -0
  33. package/lib/types/bridge.d.ts +5 -0
  34. package/lib/types/bridge.d.ts.map +1 -1
  35. package/lib/types/client.d.ts +126 -0
  36. package/lib/types/client.d.ts.map +1 -1
  37. package/lib/types/index.d.ts.map +1 -1
  38. package/lib/types/local-share.d.ts +11 -0
  39. package/lib/types/local-share.d.ts.map +1 -0
  40. package/lib/types/panel.d.ts +27 -0
  41. package/lib/types/panel.d.ts.map +1 -1
  42. package/lib/types/phone-security.d.ts +59 -0
  43. package/lib/types/phone-security.d.ts.map +1 -0
  44. package/lib/types/phone-session.d.ts +52 -0
  45. package/lib/types/phone-session.d.ts.map +1 -0
  46. package/lib/types/phone-uploads.d.ts +75 -0
  47. package/lib/types/phone-uploads.d.ts.map +1 -0
  48. package/lib/types/preset-context.d.ts +2 -0
  49. package/lib/types/preset-context.d.ts.map +1 -1
  50. package/lib/types/preset-session.d.ts +1 -1
  51. package/lib/types/relay.d.ts +10 -2
  52. package/lib/types/relay.d.ts.map +1 -1
  53. package/lib/types/secure-channel.d.ts +79 -0
  54. package/lib/types/secure-channel.d.ts.map +1 -0
  55. package/lib/web/client.js +849 -278
  56. package/package.json +11 -2
package/lib/web/client.js CHANGED
@@ -38,7 +38,7 @@ function currentSessionTracker(list) {
38
38
  }
39
39
 
40
40
  // src/web/TeamworkPanel.tsx
41
- var import_react3 = require("react");
41
+ var import_react4 = require("react");
42
42
 
43
43
  // ui/src/root.tsx
44
44
  var import_react = require("react");
@@ -268,14 +268,90 @@ var css = String.raw`
268
268
  .twui-panel { height: 100%; min-height: 0; display: flex; flex-direction: column; background: var(--twui-bg); container-type: inline-size; }
269
269
  .twui-panel-header, .twui-panel-nav { background: var(--twui-surface); }
270
270
  .twui-panel-header { border-bottom: 1px solid var(--twui-border); }
271
+ .twui-panel-header, .twui-panel-nav, .twui-panel-footer { flex: none; }
271
272
  .twui-panel-column { max-width: 1008px; margin: 0 auto; padding: 0 24px; }
272
- .twui-panel-header > .twui-panel-column { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; padding-top: 16px; padding-bottom: 16px; }
273
+ .twui-panel-header > .twui-panel-column { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding-top: 12px; padding-bottom: 12px; }
273
274
  .twui-panel-nav .twui-tabs { border-bottom: 0; }
274
275
  .twui-panel-nav { border-bottom: 1px solid var(--twui-border); }
275
276
  .twui-panel-body { flex: 1; min-height: 0; overflow-y: auto; }
276
277
  .twui-panel-content { display: grid; gap: 12px; align-content: start; padding-top: 20px; padding-bottom: 32px; }
277
278
  .twui-panel[data-centered] .twui-panel-body { display: grid; place-items: center; }
278
279
  .twui-panel[data-centered] .twui-panel-content { width: 100%; }
280
+
281
+ /* Custom selects: the popup stays in the theme root and flips near the viewport edge. */
282
+ .twui-select { position: relative; min-width: 0; max-width: 100%; }
283
+ .twui-select-trigger { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 36px; padding: 7px 11px; border: 1px solid var(--twui-border); border-radius: var(--twui-radius-md); font: inherit; color: var(--twui-fg); background: var(--twui-fill); cursor: pointer; }
284
+ .twui-select-trigger > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
285
+ .twui-select-trigger:hover:not(:disabled), .twui-select-trigger[aria-expanded="true"] { background: var(--twui-fill-strong); }
286
+ .twui-select-trigger:disabled { opacity: .5; cursor: not-allowed; }
287
+ .twui-select[data-split] { display: inline-flex; align-items: stretch; border: 1px solid transparent; border-radius: var(--twui-radius-md); background: transparent; }
288
+ .twui-select[data-split]:hover, .twui-select[data-split]:focus-within { border-color: var(--twui-border); background: var(--twui-fill); }
289
+ .twui-select-primary { display: flex; align-items: center; min-width: 0; min-height: 34px; padding: 7px 12px; border: 0; border-radius: calc(var(--twui-radius-md) - 1px) 0 0 calc(var(--twui-radius-md) - 1px); background: transparent; color: var(--twui-fg); font: inherit; cursor: pointer; }
290
+ .twui-select-primary > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
291
+ .twui-select-primary:hover:not(:disabled) { background: var(--twui-fill-strong); }
292
+ .twui-select-primary:disabled { opacity: .5; cursor: not-allowed; }
293
+ .twui-select[data-split] > .twui-select-trigger { width: 34px; flex: none; justify-content: center; padding: 0; border: 0; border-left: 1px solid transparent; border-radius: 0 calc(var(--twui-radius-md) - 1px) calc(var(--twui-radius-md) - 1px) 0; background: transparent; }
294
+ .twui-select[data-split]:hover > .twui-select-trigger, .twui-select[data-split]:focus-within > .twui-select-trigger { border-left-color: var(--twui-border); }
295
+ .twui-select[data-split] > .twui-select-trigger:hover:not(:disabled), .twui-select[data-split] > .twui-select-trigger[aria-expanded="true"] { background: var(--twui-fill-strong); }
296
+ .twui-select-menu { position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; min-width: 100%; width: max-content; max-width: min(300px, 80cqw); max-height: min(288px, 45vh); overflow-y: auto; padding: 5px; border: 1px solid var(--twui-border-strong); border-radius: var(--twui-radius-md); background: var(--twui-surface); color: var(--twui-fg); box-shadow: 0 8px 28px color-mix(in srgb, var(--twui-fg) 15%, transparent); }
297
+ .twui-select-menu[data-side="top"] { top: auto; bottom: calc(100% + 6px); }
298
+ .twui-select-option { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 9px 10px; border-radius: var(--twui-radius-sm); cursor: pointer; overflow-wrap: anywhere; }
299
+ .twui-select-option > span { display: grid; gap: 2px; }
300
+ .twui-select-option small { font-size: 12px; color: var(--twui-fg-muted); }
301
+ .twui-select-option[data-active] { background: var(--twui-hover); }
302
+ .twui-select-option[aria-selected="true"] { color: var(--twui-accent); }
303
+ .twui-select-option[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
304
+
305
+ /* Screen composition */
306
+ .twui-brand-lockup { display: flex; align-items: center; gap: 12px; }
307
+ .twui-brand-lockup { min-width: 0; }
308
+ .twui-brand-home { display: inline-flex; flex: none; padding: 0; background: transparent; border: 0; border-radius: var(--twui-radius-sm); cursor: pointer; }
309
+ .twui-header-actions { margin-left: auto; gap: 4px; }
310
+ .twui-header-actions .twui-btn[aria-current="page"] { color: var(--twui-fg); background: var(--twui-fill); }
311
+ .twui-panel-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 2px 16px; min-height: 32px; padding: 2px 12px; border-top: 1px solid var(--twui-border); background: var(--twui-surface); color: var(--twui-fg-muted); font-size: 11px; }
312
+ .twui-footer-identity { display: flex; align-items: center; gap: 12px; min-width: 0; }
313
+ .twui-footer-name { font-weight: 500; }
314
+ .twui-footer-service { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
315
+ .twui-footer-actions { margin-left: auto; gap: 4px; }
316
+ .twui-footer-actions .twui-badge { background: transparent; font-size: 11px; height: 20px; padding: 0 4px; }
317
+ .twui-footer-actions .twui-btn { font-size: 11px; height: 24px; padding-inline: 6px; }
318
+ .twui-page-title { font-size: 22px; font-weight: 600; letter-spacing: -.025em; }
319
+ .twui-team-scope { gap: 4px; color: var(--twui-fg-muted); min-width: 0; }
320
+ .twui-team-scope .twui-select { max-width: min(280px, 60cqw); }
321
+ .twui-resource-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; justify-content: space-between; }
322
+ .twui-resource-toolbar .twui-input { flex: 0 1 240px; }
323
+ .twui-resource-toolbar .twui-tabs { border: 0; gap: 4px; }
324
+ .twui-resource-toolbar .twui-tab { padding: 7px 14px; margin: 0; border: 0; border-radius: var(--twui-radius-sm); }
325
+ .twui-resource-toolbar .twui-tab[aria-selected="true"] { background: var(--twui-fill); }
326
+ .twui-resource-list .twui-item { border: 0; border-bottom: 1px solid var(--twui-border); border-radius: 0; box-shadow: none; background: transparent; }
327
+ .twui-resource-list .twui-item-main { padding: 24px 2px; align-items: center; }
328
+ .twui-resource-list .twui-tile { width: 42px; height: 42px; color: var(--twui-accent); align-self: start; }
329
+ .twui-resource-list .twui-item-subtitle { font: inherit; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--twui-fill); color: var(--twui-fg-muted); }
330
+ .twui-resource-list .twui-item-tags { margin-top: 8px; }
331
+ .twui-resource-list .twui-item-title { font-size: 15px; font-weight: 500; }
332
+ .twui-account-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 48px; margin-top: 12px; align-items: start; }
333
+ .twui-account-grid > section { gap: 20px; min-width: 0; }
334
+ .twui-account-grid h3 { font-size: 15px; font-weight: 500; }
335
+ .twui-account-grid .twui-input { width: 100%; }
336
+ .twui-panel-content { gap: 16px; padding-top: 28px; }
337
+ @container (max-width: 680px) {
338
+ .twui-account-grid { grid-template-columns: minmax(0, 1fr); gap: 32px; }
339
+ .twui-header-actions { width: 100%; justify-content: flex-end; }
340
+ .twui-panel-column { padding-inline: 16px; }
341
+ .twui-resource-toolbar .twui-input { flex: 1 1 180px; }
342
+ }
343
+ @container (max-width: 380px) {
344
+ .twui-header-actions { gap: 0; }
345
+ .twui-header-actions .twui-btn { padding-inline: 7px; font-size: 12px; }
346
+ .twui-brand-lockup { gap: 8px; }
347
+ .twui-team-scope .twui-btn { padding-inline: 6px; }
348
+ .twui-team-scope .twui-select { max-width: 42cqw; }
349
+ }
350
+ @media (pointer: coarse) {
351
+ .twui-select-trigger, .twui-select-primary, .twui-select-option, .twui-btn { min-height: 44px; height: auto; }
352
+ .twui-select[data-split] > .twui-select-trigger { width: 44px; }
353
+ .twui-input { min-height: 44px; font-size: 16px; }
354
+ }
279
355
  `;
280
356
 
281
357
  // ui/src/root.tsx
@@ -431,14 +507,19 @@ function Tabs({ items, value, onChange, label }) {
431
507
  item.id
432
508
  )) });
433
509
  }
510
+ function Monogram({ text, size = 32 }) {
511
+ const letters = Array.from(text.trim()).slice(0, 2).join("").toUpperCase() || "?";
512
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "twui-monogram", "aria-hidden": "true", style: { width: size, height: size, fontSize: Math.round(size * 0.4) }, children: letters });
513
+ }
434
514
 
435
515
  // ui/src/layout.tsx
436
516
  var import_jsx_runtime5 = require("react/jsx-runtime");
437
- function Panel({ header, nav, children, label, centered = false }) {
517
+ function Panel({ header, nav, footer, children, label, centered = false }) {
438
518
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(UIRoot, { className: "twui-panel", role: "region", "aria-label": label, "data-centered": centered || void 0, children: [
439
519
  header && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("header", { className: "twui-panel-header", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "twui-panel-column", children: header }) }),
440
520
  nav && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "twui-panel-nav", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "twui-panel-column", children: nav }) }),
441
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "twui-panel-body", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "twui-panel-column twui-panel-content", children }) })
521
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "twui-panel-body", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "twui-panel-column twui-panel-content", children }) }),
522
+ footer && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("footer", { className: "twui-panel-footer", children: footer })
442
523
  ] });
443
524
  }
444
525
  function Card({ children, padding = 20 }) {
@@ -514,6 +595,179 @@ function Toast({ tone = "neutral", children }) {
514
595
  ] });
515
596
  }
516
597
 
598
+ // ui/src/select.tsx
599
+ var import_react3 = require("react");
600
+ var import_jsx_runtime6 = require("react/jsx-runtime");
601
+ function Select({ id, label, value, options, onChange, onActivate, disabled = false }) {
602
+ const generated = (0, import_react3.useId)();
603
+ const listId = `${id ?? generated}-options`;
604
+ const root = (0, import_react3.useRef)(null);
605
+ const trigger = (0, import_react3.useRef)(null);
606
+ const list = (0, import_react3.useRef)(null);
607
+ const [open, setOpen] = (0, import_react3.useState)(false);
608
+ const [active, setActive] = (0, import_react3.useState)(0);
609
+ const [side, setSide] = (0, import_react3.useState)("bottom");
610
+ const [height, setHeight] = (0, import_react3.useState)(288);
611
+ const search = (0, import_react3.useRef)({ text: "", at: 0 });
612
+ const selected = options.findIndex((o) => o.value === value);
613
+ const close = (focus = false) => {
614
+ setOpen(false);
615
+ if (focus) trigger.current?.focus();
616
+ };
617
+ const move = (from, direction) => {
618
+ for (let step = 1; step <= options.length; step++) {
619
+ const next = (from + step * direction + options.length) % options.length;
620
+ if (!options[next].disabled) {
621
+ setActive(next);
622
+ return;
623
+ }
624
+ }
625
+ };
626
+ const show = (edge) => {
627
+ if (disabled || !options.some((o) => !o.disabled)) return;
628
+ const first = options.findIndex((o) => !o.disabled), last = options.map((o) => !o.disabled).lastIndexOf(true);
629
+ const next = edge === "first" ? first : edge === "last" ? last : selected >= 0 && !options[selected].disabled ? selected : first;
630
+ setActive(next);
631
+ setOpen(true);
632
+ };
633
+ (0, import_react3.useEffect)(() => {
634
+ if (!open) return;
635
+ const rect = root.current?.getBoundingClientRect();
636
+ if (rect) {
637
+ const below = window.innerHeight - rect.bottom, above = rect.top;
638
+ const top = below < 250 && above > below;
639
+ setSide(top ? "top" : "bottom");
640
+ setHeight(Math.max(48, Math.min(288, (top ? above : below) - 12)));
641
+ }
642
+ list.current?.focus();
643
+ const outside = (event) => {
644
+ if (!root.current?.contains(event.target)) setOpen(false);
645
+ };
646
+ document.addEventListener("pointerdown", outside);
647
+ return () => document.removeEventListener("pointerdown", outside);
648
+ }, [open]);
649
+ (0, import_react3.useEffect)(() => {
650
+ if (open) list.current?.querySelector(`[data-index="${active}"]`)?.scrollIntoView?.({ block: "nearest" });
651
+ }, [active, open]);
652
+ (0, import_react3.useEffect)(() => {
653
+ if (disabled) setOpen(false);
654
+ }, [disabled]);
655
+ (0, import_react3.useEffect)(() => {
656
+ if (!open || options[active] && !options[active].disabled) return;
657
+ const next = selected >= 0 && !options[selected].disabled ? selected : options.findIndex((o) => !o.disabled);
658
+ if (next < 0) close(true);
659
+ else setActive(next);
660
+ }, [options, selected, active, open]);
661
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "twui-select", "data-split": !!onActivate || void 0, role: onActivate ? "group" : void 0, "aria-label": onActivate ? label : void 0, ref: root, onBlur: (e) => {
662
+ if (!e.currentTarget.contains(e.relatedTarget)) close();
663
+ }, children: [
664
+ onActivate && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "twui-select-primary", disabled: disabled || selected < 0 || options[selected]?.disabled, onClick: () => {
665
+ close();
666
+ onActivate();
667
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: options[selected]?.label ?? label }) }),
668
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
669
+ "button",
670
+ {
671
+ ref: trigger,
672
+ id,
673
+ type: "button",
674
+ className: "twui-select-trigger",
675
+ "aria-label": `${label}:${options[selected]?.label ?? ""}`,
676
+ "aria-haspopup": "listbox",
677
+ "aria-expanded": open,
678
+ "aria-controls": open ? listId : void 0,
679
+ disabled,
680
+ onClick: () => open ? close(true) : show(),
681
+ onKeyDown: (e) => {
682
+ if (["ArrowDown", "ArrowUp", "Home", "End"].includes(e.key)) {
683
+ e.preventDefault();
684
+ show(e.key === "Home" ? "first" : e.key === "End" ? "last" : void 0);
685
+ }
686
+ },
687
+ children: [
688
+ !onActivate && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: options[selected]?.label ?? label }),
689
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "chevronDown", size: 14 })
690
+ ]
691
+ }
692
+ ),
693
+ open && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
694
+ "div",
695
+ {
696
+ ref: list,
697
+ id: listId,
698
+ role: "listbox",
699
+ "aria-label": label,
700
+ tabIndex: -1,
701
+ className: "twui-select-menu",
702
+ "data-side": side,
703
+ style: { maxHeight: height },
704
+ "aria-activedescendant": `${listId}-${active}`,
705
+ onKeyDown: (e) => {
706
+ if (e.key === "Tab") {
707
+ close(true);
708
+ return;
709
+ }
710
+ if (e.key === "Escape") {
711
+ e.preventDefault();
712
+ e.stopPropagation();
713
+ close(true);
714
+ return;
715
+ }
716
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
717
+ e.preventDefault();
718
+ move(active, e.key === "ArrowDown" ? 1 : -1);
719
+ } else if (e.key === "Home" || e.key === "End") {
720
+ e.preventDefault();
721
+ move(e.key === "Home" ? options.length - 1 : 0, e.key === "Home" ? 1 : -1);
722
+ } else if (e.key === "Enter" || e.key === " ") {
723
+ e.preventDefault();
724
+ const option = options[active];
725
+ if (option && !option.disabled) {
726
+ onChange(option.value);
727
+ close(true);
728
+ }
729
+ } else if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
730
+ const text = (Date.now() - search.current.at < 700 ? search.current.text : "") + e.key.toLocaleLowerCase();
731
+ search.current = { text, at: Date.now() };
732
+ const next = options.findIndex((o) => !o.disabled && o.label.toLocaleLowerCase().startsWith(text));
733
+ if (next >= 0) setActive(next);
734
+ }
735
+ },
736
+ children: options.map((option, index) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
737
+ "div",
738
+ {
739
+ id: `${listId}-${index}`,
740
+ role: "option",
741
+ "aria-selected": option.value === value,
742
+ "aria-disabled": option.disabled || void 0,
743
+ "data-index": index,
744
+ "data-active": index === active || void 0,
745
+ className: "twui-select-option",
746
+ onPointerMove: () => {
747
+ if (!option.disabled) setActive(index);
748
+ },
749
+ onMouseDown: (e) => e.preventDefault(),
750
+ onClick: () => {
751
+ if (!option.disabled) {
752
+ onChange(option.value);
753
+ close(true);
754
+ }
755
+ },
756
+ children: [
757
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
758
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: option.label }),
759
+ option.description && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("small", { children: option.description })
760
+ ] }),
761
+ option.value === value && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "check", size: 14 })
762
+ ]
763
+ },
764
+ option.value
765
+ ))
766
+ }
767
+ )
768
+ ] });
769
+ }
770
+
517
771
  // node_modules/.pnpm/qrcode-generator@2.0.4/node_modules/qrcode-generator/dist/qrcode.mjs
518
772
  var qrcode = function(typeNumber, errorCorrectionLevel) {
519
773
  const PAD0 = 236;
@@ -2173,6 +2427,9 @@ async function call(route, payload = {}) {
2173
2427
  return data;
2174
2428
  }
2175
2429
  var api = {
2430
+ quota: (teamId) => call("quota", { teamId }),
2431
+ profile: () => call("profile"),
2432
+ updateProfile: (input) => call("update-profile", input),
2176
2433
  state: (sessionId) => call("state", { sessionId }),
2177
2434
  login: () => call("login"),
2178
2435
  authorize: (code) => call("authorize", { code }),
@@ -2187,8 +2444,10 @@ var api = {
2187
2444
  };
2188
2445
 
2189
2446
  // src/web/TeamworkPanel.tsx
2190
- var import_jsx_runtime6 = require("react/jsx-runtime");
2447
+ var import_jsx_runtime7 = require("react/jsx-runtime");
2191
2448
  var REFRESH_MS = 5e3;
2449
+ var views = /* @__PURE__ */ new Map();
2450
+ var profileDrafts = /* @__PURE__ */ new Map();
2192
2451
  var pluginText = {
2193
2452
  ready: ["已启用", "success"],
2194
2453
  missing: ["未安装", "warning"],
@@ -2216,33 +2475,145 @@ function synced(iso) {
2216
2475
  return `${new Date(iso).toLocaleTimeString()} 同步`;
2217
2476
  }
2218
2477
  function TeamworkPanel({ host: dsh }) {
2219
- const currentSession = (0, import_react3.useRef)(currentSessionTracker(dsh.sessions.list)).current;
2220
- const sessionId = (0, import_react3.useSyncExternalStore)(dsh.sessions.list.subscribe, currentSession);
2221
- const [state, setState] = (0, import_react3.useState)();
2222
- const [loadError, setLoadError] = (0, import_react3.useState)();
2223
- const [tab, setTab] = (0, import_react3.useState)("presets");
2224
- const [toast, setToast] = (0, import_react3.useState)();
2225
- const toastTimer = (0, import_react3.useRef)();
2226
- const refresh = (0, import_react3.useCallback)(async () => {
2227
- try {
2228
- setState(await api.state(sessionId));
2229
- setLoadError(void 0);
2230
- } catch (error) {
2231
- setLoadError(error.message);
2478
+ const currentSession = (0, import_react4.useRef)(dsh.currentSession ?? currentSessionTracker(dsh.sessions.list)).current;
2479
+ const sessionId = (0, import_react4.useSyncExternalStore)(dsh.sessions.list.subscribe, currentSession);
2480
+ const [snapshot, setState] = (0, import_react4.useState)();
2481
+ const [loadedSession, setLoadedSession] = (0, import_react4.useState)();
2482
+ const state = snapshot && (loadedSession === sessionId ? snapshot : { ...snapshot, session: null });
2483
+ const [loadError, setLoadError] = (0, import_react4.useState)();
2484
+ const [tab, setTab] = (0, import_react4.useState)("presets");
2485
+ const [page, setPage] = (0, import_react4.useState)("resources");
2486
+ const [team, setTeam] = (0, import_react4.useState)("all");
2487
+ const [query, setQuery] = (0, import_react4.useState)("");
2488
+ const [profile, setProfile] = (0, import_react4.useState)();
2489
+ const [profileError, setProfileError] = (0, import_react4.useState)();
2490
+ const [profileAttempt, setProfileAttempt] = (0, import_react4.useState)(0);
2491
+ const identity = (0, import_react4.useRef)();
2492
+ const touched = (0, import_react4.useRef)(false);
2493
+ const browsing = (0, import_react4.useRef)({ team, tab, query });
2494
+ browsing.current = { team, tab, query };
2495
+ const latest = (0, import_react4.useRef)(state);
2496
+ latest.current = state;
2497
+ const request = (0, import_react4.useRef)();
2498
+ const context = (0, import_react4.useRef)(sessionId);
2499
+ context.current = sessionId;
2500
+ const [toast, setToast] = (0, import_react4.useState)();
2501
+ const toastTimer = (0, import_react4.useRef)();
2502
+ const refresh = (0, import_react4.useCallback)(() => {
2503
+ if (request.current) return request.current;
2504
+ const session = context.current;
2505
+ request.current = (async () => {
2506
+ try {
2507
+ const next = await api.state(session);
2508
+ if (context.current === session) {
2509
+ setLoadedSession(session);
2510
+ setState(next);
2511
+ setLoadError(void 0);
2512
+ }
2513
+ } catch (error) {
2514
+ setLoadError(error.message);
2515
+ } finally {
2516
+ request.current = void 0;
2517
+ }
2518
+ })();
2519
+ return request.current;
2520
+ }, []);
2521
+ (0, import_react4.useEffect)(() => {
2522
+ let disposed = false;
2523
+ let timer;
2524
+ const poll = async () => {
2525
+ await request.current;
2526
+ if (disposed) return;
2527
+ await refresh();
2528
+ if (!disposed) timer = setTimeout(poll, REFRESH_MS);
2529
+ };
2530
+ void poll();
2531
+ return () => {
2532
+ disposed = true;
2533
+ clearTimeout(timer);
2534
+ };
2535
+ }, [refresh, sessionId]);
2536
+ const authenticated = state?.authenticated, server = state?.server;
2537
+ (0, import_react4.useEffect)(() => {
2538
+ identity.current = void 0;
2539
+ touched.current = false;
2540
+ setProfile(void 0);
2541
+ setPage("resources");
2542
+ setTeam("all");
2543
+ setQuery("");
2544
+ }, [authenticated, server]);
2545
+ (0, import_react4.useEffect)(() => {
2546
+ setProfileError(void 0);
2547
+ if (!authenticated) return;
2548
+ let cancelled = false;
2549
+ void api.profile().then((next) => {
2550
+ if (cancelled) return;
2551
+ setProfile(next);
2552
+ const key = `teamwork:team:${server}:${next.id}`;
2553
+ if (identity.current === key) return;
2554
+ identity.current = key;
2555
+ if (touched.current) {
2556
+ try {
2557
+ localStorage.setItem(key, browsing.current.team);
2558
+ } catch {
2559
+ }
2560
+ return;
2561
+ }
2562
+ const view = views.get(key);
2563
+ setTab(view?.tab ?? "presets");
2564
+ setQuery(view?.query ?? "");
2565
+ let saved = null;
2566
+ try {
2567
+ saved = localStorage.getItem(key);
2568
+ } catch {
2569
+ }
2570
+ saved ?? (saved = view?.team ?? null);
2571
+ const teams = latest.current?.teams ?? [];
2572
+ const selected = saved && (saved === "all" || teams.some((t) => t.id === saved)) ? saved : teams.length === 1 ? teams[0].id : "all";
2573
+ setTeam(selected);
2574
+ if (saved === null && teams.length > 1) setPage("choose");
2575
+ }).catch((error) => {
2576
+ if (!cancelled) setProfileError(error.message);
2577
+ });
2578
+ return () => {
2579
+ cancelled = true;
2580
+ };
2581
+ }, [authenticated, server, profileAttempt]);
2582
+ (0, import_react4.useEffect)(() => {
2583
+ if (profile && identity.current) views.set(identity.current, { team, tab, query });
2584
+ }, [profile, team, tab, query]);
2585
+ const navigate = (next) => {
2586
+ touched.current = true;
2587
+ setPage(next);
2588
+ };
2589
+ const selectTeam = (id) => {
2590
+ touched.current = true;
2591
+ setTeam(id);
2592
+ setPage("resources");
2593
+ setQuery("");
2594
+ if (profile) try {
2595
+ localStorage.setItem(`teamwork:team:${server}:${profile.id}`, id);
2596
+ } catch {
2597
+ }
2598
+ };
2599
+ (0, import_react4.useEffect)(() => {
2600
+ if (state && team !== "all" && !state.teams.some((t) => t.id === team)) {
2601
+ setTeam("all");
2602
+ setQuery("");
2603
+ if (profile) try {
2604
+ localStorage.setItem(`teamwork:team:${server}:${profile.id}`, "all");
2605
+ } catch {
2606
+ }
2607
+ notify("当前团队已不可用,浏览范围已切换为全部团队。");
2232
2608
  }
2233
- }, [sessionId]);
2234
- (0, import_react3.useEffect)(() => {
2235
- void refresh();
2236
- const timer = setInterval(() => void refresh(), REFRESH_MS);
2237
- return () => clearInterval(timer);
2238
- }, [refresh]);
2239
- const notify = (0, import_react3.useCallback)((message, tone = "neutral") => {
2609
+ }, [state?.teams, team]);
2610
+ const notify = (0, import_react4.useCallback)((message, tone = "neutral") => {
2240
2611
  clearTimeout(toastTimer.current);
2241
2612
  setToast({ message, tone });
2242
2613
  toastTimer.current = setTimeout(() => setToast(void 0), tone === "danger" ? 6e3 : 3e3);
2243
2614
  }, []);
2244
- (0, import_react3.useEffect)(() => () => clearTimeout(toastTimer.current), []);
2245
- const run = (0, import_react3.useCallback)(async (action, done) => {
2615
+ (0, import_react4.useEffect)(() => () => clearTimeout(toastTimer.current), []);
2616
+ const run = (0, import_react4.useCallback)(async (action, done) => {
2246
2617
  try {
2247
2618
  const result = await action();
2248
2619
  const message = typeof done === "function" ? done(result) : done;
@@ -2252,55 +2623,216 @@ function TeamworkPanel({ host: dsh }) {
2252
2623
  notify(error.message, "danger");
2253
2624
  return false;
2254
2625
  } finally {
2626
+ await request.current;
2255
2627
  await refresh();
2256
2628
  }
2257
2629
  }, [notify, refresh]);
2258
- const toastNode = toast && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Toast, { tone: toast.tone, children: toast.message });
2630
+ const toastNode = toast && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Toast, { tone: toast.tone, children: toast.message });
2259
2631
  if (!state) {
2260
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Panel, { label: "Teamwork", header: loadError ? void 0 : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(HeaderSkeleton, {}), children: loadError ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Banner, { tone: "danger", title: "无法读取团队状态", action: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { size: "sm", icon: "refresh", onClick: () => void refresh(), children: "重试" }), children: loadError }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ListSkeleton, {}) });
2632
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Panel, { label: "Teamwork", header: loadError ? void 0 : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HeaderSkeleton, {}), children: loadError ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Banner, { tone: "danger", title: "无法读取团队状态", action: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { size: "sm", icon: "refresh", onClick: () => void refresh(), children: "重试" }), children: loadError }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ListSkeleton, {}) });
2261
2633
  }
2262
2634
  if (!state.authenticated) {
2263
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Panel, { label: "Teamwork", centered: true, children: [
2264
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SignIn, { state, run }),
2635
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Panel, { label: "Teamwork", centered: true, children: [
2636
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SignIn, { state, run }),
2265
2637
  toastNode
2266
2638
  ] });
2267
2639
  }
2268
- const tabs = [
2269
- { id: "presets", label: "预设", count: state.presets.length },
2270
- { id: "models", label: "团队模型", count: state.models.length },
2271
- { id: "plugins", label: "团队插件", count: state.plugins.length },
2272
- { id: "phones", label: "手机", count: state.phones.length }
2273
- ];
2274
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Panel, { label: "Teamwork", header: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Header, { state, run }), nav: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Tabs, { label: "团队配置", items: tabs, value: tab, onChange: setTab }), children: [
2275
- loadError && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Banner, { tone: "danger", title: "状态没有刷新", action: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { size: "sm", icon: "refresh", onClick: () => void refresh(), children: "重试" }), children: loadError }),
2276
- state.sync.lastError && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Banner, { tone: "warning", title: "同步失败,正在使用上次同步的配置", action: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { size: "sm", icon: "refresh", onClick: () => run(() => api.sync(), "团队配置已同步"), children: "重试" }), children: state.sync.lastError }),
2277
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SessionStrip, { state }),
2278
- tab === "presets" && (state.presets.length ? state.presets.map((p) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PresetItem, { preset: p, state, dsh, run, onInstall: () => setTab("plugins") }, p.id)) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Card, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(EmptyState, { icon: "layers", title: "团队还没有发布预设", children: "管理员在网页控制台发布预设后,下次同步就会出现在这里。" }) })),
2279
- tab === "models" && (state.models.length ? state.models.map((m) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ModelItem, { model: m, state, run }, m.id)) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Card, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(EmptyState, { icon: "cpu", title: "团队还没有发布模型", children: "团队模型由服务器代为调用,provider 密钥不会下发到这台电脑。" }) })),
2280
- tab === "plugins" && (state.plugins.length ? state.plugins.map((p) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PluginItem, { plugin: p, run }, p.id)) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Card, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(EmptyState, { icon: "puzzle", title: "团队没有固定插件版本", children: "固定的插件版本会出现在这里,由你确认后安装。" }) })),
2281
- tab === "phones" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Phones, { state, run }),
2640
+ const inTeam = (item) => team === "all" || item.teamId === team;
2641
+ const matches = (item) => `${item.name} ${item.description ?? ""}`.toLocaleLowerCase().includes(query.toLocaleLowerCase());
2642
+ const presets = state.presets.filter(inTeam), models = state.models.filter(inTeam), plugins = state.plugins.filter(inTeam);
2643
+ const tabs = [{ id: "presets", label: "预设", count: presets.length }, { id: "models", label: "模型", count: models.length }, { id: "plugins", label: "插件", count: plugins.length }];
2644
+ const choosing = page === "choose" && state.teams.length > 1;
2645
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Panel, { label: "Teamwork", header: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Header, { state, page, team, selectTeam, navigate }), footer: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Footer, { state, team, run }), children: [
2646
+ loadError && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Banner, { tone: "danger", title: "状态没有刷新", action: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { size: "sm", icon: "refresh", onClick: () => void refresh(), children: "重试" }), children: loadError }),
2647
+ state.sync.lastError && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Banner, { tone: "warning", title: "同步失败,正在使用上次同步的配置", action: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { size: "sm", icon: "refresh", onClick: () => run(() => api.sync(), "团队配置已同步"), children: "重试" }), children: state.sync.lastError }),
2648
+ page !== "resources" && !choosing && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "ghost", size: "sm", onClick: () => navigate("resources"), children: "返回团队资源" }) }),
2649
+ choosing ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TeamChooser, { state, select: selectTeam }) : (page === "resources" || page === "choose") && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: !state.teams.length ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(EmptyState, { icon: "layers", title: "账号已连接,接下来加入团队", action: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-row", children: [
2650
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { trailingIcon: "external", onClick: () => window.open(`${state.server}/teams`, "_blank", "noopener"), children: "加入或创建团队" }),
2651
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { icon: "refresh", onClick: () => run(() => api.sync(), "团队列表已刷新"), children: "我已加入,刷新团队" })
2652
+ ] }), children: "在网页中接受邀请或创建团队,完成后回来刷新。" }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
2653
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-resource-toolbar", children: [
2654
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Tabs, { label: "资源类型", items: tabs, value: tab, onChange: setTab }),
2655
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Input, { "aria-label": "搜索团队资源", placeholder: "搜索名称或用途", value: query, onChange: (e) => setQuery(e.target.value) })
2656
+ ] }),
2657
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-resource-list", children: [
2658
+ tab === "presets" && presets.filter(matches).map((p) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PresetItem, { preset: p, state, dsh, run, onInstall: () => setTab("plugins") }, p.id)),
2659
+ tab === "models" && models.filter(matches).map((m) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ModelItem, { model: m, state, run }, m.id)),
2660
+ tab === "plugins" && plugins.filter(matches).map((p) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PluginItem, { plugin: p, run }, p.id)),
2661
+ !(tab === "presets" ? presets : tab === "models" ? models : plugins).filter(matches).length && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(EmptyState, { icon: "layers", title: query ? "没有匹配的资源" : "这里还没有资源", children: query ? "试试其他关键词或切换团队。" : "管理员在网页发布后,资源会同步到这里。" })
2662
+ ] }, `${team}:${tab}`)
2663
+ ] }) }),
2664
+ page === "devices" && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
2665
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PageTitle, { title: "手机连接", children: "手机连接的是这台电脑上的 DSH,与当前浏览的团队无关。" }),
2666
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Phones, { state, run })
2667
+ ] }),
2668
+ page === "teams" && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
2669
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PageTitle, { title: "我的团队", children: "浏览范围不会改变已有会话或手机配对。" }),
2670
+ state.teams.map((t) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Item, { icon: "layers", title: t.name, tags: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Badge, { children: t.role === "admin" ? "管理员" : "成员" }), actions: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
2671
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { onClick: () => selectTeam(t.id), children: "浏览资源" }),
2672
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "ghost", trailingIcon: "external", onClick: () => window.open(t.consoleUrl, "_blank", "noopener"), children: t.role === "admin" ? "管理团队" : "查看团队" })
2673
+ ] }) }, t.id)),
2674
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { trailingIcon: "external", onClick: () => window.open(`${state.server}/teams`, "_blank", "noopener"), children: "加入或创建团队" }) })
2675
+ ] }),
2676
+ page === "profile" && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Account, { state, profile, error: profileError, retry: () => setProfileAttempt((n) => n + 1), updated: (next) => {
2677
+ if (identity.current === `teamwork:team:${state.server}:${next.id}`) setProfile(next);
2678
+ }, run }),
2282
2679
  toastNode
2283
2680
  ] });
2284
2681
  }
2682
+ function PageTitle({ title, children }) {
2683
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-stack", children: [
2684
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h2", { className: "twui-page-title", children: title }),
2685
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "twui-muted", children })
2686
+ ] });
2687
+ }
2688
+ function TeamChooser({ state, select }) {
2689
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
2690
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PageTitle, { title: "先从哪个团队开始?", children: "选择资源的浏览范围;你也可以随时在页面顶部切换。" }),
2691
+ state.teams.map((t) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Item, { icon: "layers", title: t.name, tags: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Badge, { children: t.role === "admin" ? "管理员" : "成员" }), actions: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { onClick: () => select(t.id), children: "选择团队" }) }, t.id)),
2692
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "primary", onClick: () => select("all"), children: "查看全部团队资源" }) })
2693
+ ] });
2694
+ }
2695
+ function Account({ state, profile, error, retry, updated, run }) {
2696
+ const [name, setName] = (0, import_react4.useState)("");
2697
+ const [locale, setLocale] = (0, import_react4.useState)("zh-CN");
2698
+ const [busy, setBusy] = (0, import_react4.useState)(false);
2699
+ const [logoutConfirm, setLogoutConfirm] = (0, import_react4.useState)(false);
2700
+ const [saveError, setSaveError] = (0, import_react4.useState)();
2701
+ const saving = (0, import_react4.useRef)(false);
2702
+ const key = profile ? `${state.server}:${profile.id}` : void 0;
2703
+ const dirty = !!profile && (name.trim() !== (profile.name ?? "") || locale !== (profile.locale ?? "zh-CN"));
2704
+ (0, import_react4.useEffect)(() => {
2705
+ const draft = key ? profileDrafts.get(key) : void 0;
2706
+ setName(draft?.name ?? profile?.name ?? "");
2707
+ setLocale(draft?.locale ?? profile?.locale ?? "zh-CN");
2708
+ }, [key, profile?.name, profile?.locale]);
2709
+ const edit = (nextName, nextLocale) => {
2710
+ setName(nextName);
2711
+ setLocale(nextLocale);
2712
+ setSaveError(void 0);
2713
+ if (key) profileDrafts.set(key, { name: nextName, locale: nextLocale });
2714
+ };
2715
+ const save = async () => {
2716
+ if (!profile || !key || saving.current || !dirty) return;
2717
+ saving.current = true;
2718
+ setBusy(true);
2719
+ setSaveError(void 0);
2720
+ await run(async () => {
2721
+ try {
2722
+ const next = await api.updateProfile({ name: name.trim() || null, locale });
2723
+ profileDrafts.delete(key);
2724
+ updated(next);
2725
+ } catch (error2) {
2726
+ setSaveError(error2.message);
2727
+ throw error2;
2728
+ }
2729
+ }, "个人资料已保存");
2730
+ saving.current = false;
2731
+ setBusy(false);
2732
+ };
2733
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
2734
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PageTitle, { title: "我的账号", children: "管理你的 Teamwork 个人资料和这台 DSH 的连接。" }),
2735
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-account-grid", children: [
2736
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("section", { className: "twui-stack", "aria-label": "个人资料", children: error ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Banner, { tone: "warning", title: "暂时无法读取个人资料", action: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { onClick: retry, children: "重试" }), children: error }) : !profile ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ListSkeleton, {}) : /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
2737
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-row", style: { gap: 14 }, children: [
2738
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Monogram, { text: profile.name || profile.email || "T", size: 44 }),
2739
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { children: [
2740
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h3", { children: profile.name || "Teamwork 用户" }),
2741
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "twui-muted", children: profile.email || "未设置邮箱" })
2742
+ ] })
2743
+ ] }),
2744
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("form", { className: "twui-stack", onSubmit: (e) => {
2745
+ e.preventDefault();
2746
+ void save();
2747
+ }, children: [
2748
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Field, { label: "显示名称", htmlFor: "teamwork-name", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Input, { id: "teamwork-name", value: name, maxLength: 80, disabled: busy, onChange: (e) => edit(e.target.value, locale), autoComplete: "name" }) }),
2749
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Field, { label: "账号语言", htmlFor: "teamwork-locale", hint: "用于 Teamwork 网页和手机端;DSH 插件当前使用中文。", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Select, { id: "teamwork-locale", label: "账号语言", value: locale, disabled: busy, onChange: (value) => edit(name, value), options: [{ value: "zh-CN", label: "简体中文" }, { value: "en", label: "English" }] }) }),
2750
+ dirty && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "twui-subtle", children: "有未保存的修改,切换页面时会保留草稿。" }),
2751
+ saveError && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Notice, { tone: "danger", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { role: "alert", children: saveError }) }),
2752
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-row", children: [
2753
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { type: "submit", variant: "primary", busy, disabled: !dirty, children: "保存资料" }),
2754
+ dirty && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "ghost", disabled: busy, onClick: () => {
2755
+ if (key) profileDrafts.delete(key);
2756
+ setName(profile.name ?? "");
2757
+ setLocale(profile.locale ?? "zh-CN");
2758
+ setSaveError(void 0);
2759
+ }, children: "撤销修改" })
2760
+ ] })
2761
+ ] })
2762
+ ] }) }),
2763
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("section", { className: "twui-stack", "aria-label": "账号连接", children: [
2764
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h3", { children: "账号与连接" }),
2765
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ServerSetting, { state, run }),
2766
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "twui-muted", children: "重启 DSH 后需要重新授权。退出会移除当前团队配置并断开手机中转;本地会话与已安装插件保留。" }),
2767
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "ghost", icon: "logout", onClick: () => setLogoutConfirm(true), children: "退出此 DSH 的 Teamwork" }) }),
2768
+ logoutConfirm && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Confirm, { title: "退出 Teamwork?", description: "运行中的团队模型请求可能受影响。手机将无法通过当前连接访问此 DSH。", confirmLabel: "确认退出", cancelLabel: "取消", busy, onCancel: () => setLogoutConfirm(false), onConfirm: async () => {
2769
+ setBusy(true);
2770
+ await run(() => api.logout(), "已退出 Teamwork");
2771
+ setBusy(false);
2772
+ } })
2773
+ ] })
2774
+ ] })
2775
+ ] });
2776
+ }
2285
2777
  function SignIn({ state, run }) {
2286
- const [opened, setOpened] = (0, import_react3.useState)(null);
2287
- const [code, setCode] = (0, import_react3.useState)("");
2288
- const [busy, setBusy] = (0, import_react3.useState)(false);
2289
- const open = () => run(async () => {
2290
- const { url, automatic } = await api.login();
2291
- window.open(url, "_blank", "noopener");
2292
- setOpened({ automatic });
2293
- });
2778
+ const [opened, setOpened] = (0, import_react4.useState)(null);
2779
+ const [code, setCode] = (0, import_react4.useState)("");
2780
+ const [busy, setBusy] = (0, import_react4.useState)(false);
2781
+ const [error, setError] = (0, import_react4.useState)();
2782
+ const [expired, setExpired] = (0, import_react4.useState)(false);
2783
+ const locked = (0, import_react4.useRef)(false);
2784
+ (0, import_react4.useEffect)(() => {
2785
+ if (!opened) return;
2786
+ const timer = setTimeout(() => setExpired(true), Math.max(0, opened.expiresAt - Date.now()));
2787
+ return () => clearTimeout(timer);
2788
+ }, [opened]);
2789
+ const open = async () => {
2790
+ if (locked.current) return;
2791
+ locked.current = true;
2792
+ setBusy(true);
2793
+ setError(void 0);
2794
+ try {
2795
+ await run(async () => {
2796
+ try {
2797
+ const { url, automatic } = await api.login();
2798
+ setOpened({ automatic, url, expiresAt: Date.now() + 10 * 60 * 1e3 });
2799
+ setExpired(false);
2800
+ setCode("");
2801
+ window.open(url, "_blank", "noopener");
2802
+ } catch (failure) {
2803
+ setError(failure.message);
2804
+ throw failure;
2805
+ }
2806
+ });
2807
+ } finally {
2808
+ locked.current = false;
2809
+ setBusy(false);
2810
+ }
2811
+ };
2294
2812
  const authorize = async () => {
2813
+ if (locked.current) return;
2814
+ locked.current = true;
2815
+ setError(void 0);
2295
2816
  setBusy(true);
2296
- await run(() => api.authorize(code.trim()), "已授权,团队配置已同步");
2297
- setBusy(false);
2817
+ try {
2818
+ await run(async () => {
2819
+ try {
2820
+ await api.authorize(code.trim());
2821
+ } catch (failure) {
2822
+ setError(failure.message);
2823
+ throw failure;
2824
+ }
2825
+ }, "已授权,团队配置已同步");
2826
+ } finally {
2827
+ locked.current = false;
2828
+ setBusy(false);
2829
+ }
2298
2830
  };
2299
- const pasteForm = /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("form", { style: { display: "grid", gap: 12 }, onSubmit: (e) => {
2831
+ const pasteForm = /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("form", { style: { display: "grid", gap: 12 }, onSubmit: (e) => {
2300
2832
  e.preventDefault();
2301
2833
  if (code.trim()) void authorize();
2302
2834
  }, children: [
2303
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Field, { label: opened?.automatic ? "没有自动完成?粘贴网页上显示的那一行" : "网页上显示的那一行", htmlFor: "teamwork-code", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2835
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Field, { label: opened?.automatic ? "没有自动完成?粘贴网页上显示的那一行" : "网页上显示的那一行", htmlFor: "teamwork-code", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2304
2836
  Input,
2305
2837
  {
2306
2838
  id: "teamwork-code",
@@ -2314,39 +2846,44 @@ function SignIn({ state, run }) {
2314
2846
  autoFocus: !opened?.automatic
2315
2847
  }
2316
2848
  ) }),
2317
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { type: "submit", variant: opened?.automatic ? "secondary" : "primary", size: "lg", block: true, busy, disabled: !code.trim(), children: "完成授权" }),
2318
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("p", { className: "twui-subtle", style: { textAlign: "center" }, children: [
2319
- "没看到登录页?",
2320
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "twui-link", onClick: open, children: "重新打开" })
2321
- ] })
2849
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { type: "submit", variant: opened?.automatic ? "secondary" : "primary", size: "lg", block: true, busy, disabled: !code.trim() || expired, children: "完成授权" })
2322
2850
  ] });
2323
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { width: "100%", maxWidth: 440, margin: "0 auto", display: "grid", gap: 24, padding: "24px 0" }, children: [
2324
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { display: "grid", justifyItems: "center", gap: 12, textAlign: "center" }, children: [
2325
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(BrandMark, { size: 56, title: "DSH Teamwork" }),
2326
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { display: "grid", gap: 6 }, children: [
2327
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h1", { style: { fontSize: 20, fontWeight: 650, letterSpacing: "-0.01em" }, children: state.teams.length === 1 ? `重新登录 ${state.teams[0].name}` : state.teams.length ? "重新登录 DSH Teamwork" : "登录 DSH Teamwork" }),
2328
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "twui-muted", children: "团队的模型、预设和插件版本,一处发布,每位成员的 DSH 自动保持一致。" })
2851
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { width: "100%", maxWidth: 440, margin: "0 auto", display: "grid", gap: 24, padding: "24px 0" }, children: [
2852
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { display: "grid", justifyItems: "center", gap: 12, textAlign: "center" }, children: [
2853
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(BrandMark, { size: 56, title: "DSH Teamwork" }),
2854
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { display: "grid", gap: 6 }, children: [
2855
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h1", { style: { fontSize: 20, fontWeight: 650, letterSpacing: "-0.01em" }, children: state.teams.length ? "重新连接 Teamwork" : "登录 Teamwork" }),
2856
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "twui-muted", children: "团队的模型、预设和插件版本,一处发布,每位成员的 DSH 自动保持一致。" })
2329
2857
  ] })
2330
2858
  ] }),
2331
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Card, { padding: 20, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { display: "grid", gap: 16 }, children: [
2332
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("ol", { style: { listStyle: "none", margin: 0, padding: 0, display: "grid", gap: 10 }, children: [
2333
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Step, { n: 1, state: opened ? "done" : "active", children: "在浏览器中登录" }),
2334
- opened?.automatic === false ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Step, { n: 2, state: "active", children: "确认授权,把网页上显示的那一行粘贴到下方(两分钟内有效)" }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Step, { n: 2, state: opened ? "active" : "todo", children: "确认授权,这里会自动完成登录" })
2859
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Card, { padding: 20, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { display: "grid", gap: 16 }, children: [
2860
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("ol", { style: { listStyle: "none", margin: 0, padding: 0, display: "grid", gap: 10 }, children: [
2861
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Step, { n: 1, state: opened ? "done" : "active", children: "在浏览器中登录" }),
2862
+ opened?.automatic === false ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Step, { n: 2, state: "active", children: "确认授权,把网页上显示的那一行粘贴到下方(两分钟内有效)" }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Step, { n: 2, state: opened ? "active" : "todo", children: "确认授权,这里会自动完成登录" })
2335
2863
  ] }),
2336
- opened ? pasteForm : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { variant: "primary", size: "lg", block: true, trailingIcon: "external", onClick: open, children: "在浏览器中登录" })
2864
+ error && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Notice, { tone: "danger", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { role: "alert", children: error }) }),
2865
+ expired ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Banner, { tone: "warning", title: "本次登录等待已超时", action: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { busy, onClick: () => void open(), children: "重新开始登录" }), children: "请重新打开授权页面,旧页面的授权码不能用于新的登录请求。" }) : opened ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
2866
+ opened.automatic && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { role: "status", className: "twui-muted", children: "等待浏览器确认授权,完成后这里会自动进入团队资源。" }),
2867
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("a", { className: "twui-link", href: opened.url, target: "_blank", rel: "noopener noreferrer", children: "打开授权页面" }),
2868
+ opened.automatic ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("details", { children: [
2869
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("summary", { className: "twui-link", children: "没有自动完成?使用授权码" }),
2870
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { style: { paddingTop: 12 }, children: pasteForm })
2871
+ ] }) : pasteForm,
2872
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "ghost", size: "sm", busy, onClick: () => void open(), children: "重新开始登录" })
2873
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "primary", size: "lg", block: true, trailingIcon: "external", busy, onClick: () => void open(), children: "在浏览器中登录" })
2337
2874
  ] }) }),
2338
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("ul", { style: { listStyle: "none", margin: 0, padding: 0, display: "grid", gap: 12 }, children: [
2339
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Point, { icon: "shield", title: "密钥留在服务器", children: "团队模型由服务器代为调用,provider 密钥不会下发到这台电脑。" }),
2340
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Point, { icon: "layers", title: "与本地配置并存", children: "团队配置作为独立条目加入,不覆盖你自己的模型和预设。" }),
2341
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Point, { icon: "sync", title: "自动保持最新", children: "每分钟同步一次;被移出团队后,下一次请求即失效。" })
2875
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("ul", { style: { listStyle: "none", margin: 0, padding: 0, display: "grid", gap: 12 }, children: [
2876
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Point, { icon: "shield", title: "密钥留在服务器", children: "团队模型由服务器代为调用,provider 密钥不会下发到这台电脑。" }),
2877
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Point, { icon: "layers", title: "与本地配置并存", children: "团队配置作为独立条目加入,不覆盖你自己的模型和预设。" }),
2878
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Point, { icon: "sync", title: "自动保持最新", children: "每分钟同步一次;被移出团队后,下一次请求即失效。" })
2342
2879
  ] }),
2343
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ServerSetting, { state, run })
2880
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ServerSetting, { state, run })
2344
2881
  ] });
2345
2882
  }
2346
2883
  function Step({ n, state, children }) {
2347
2884
  const done = state === "done";
2348
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { style: { display: "flex", alignItems: "center", gap: 10, color: state === "todo" ? "var(--twui-fg-subtle)" : "var(--twui-fg)" }, children: [
2349
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { "aria-hidden": "true", style: {
2885
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("li", { style: { display: "flex", alignItems: "center", gap: 10, color: state === "todo" ? "var(--twui-fg-subtle)" : "var(--twui-fg)" }, children: [
2886
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { "aria-hidden": "true", style: {
2350
2887
  width: 22,
2351
2888
  height: 22,
2352
2889
  borderRadius: "50%",
@@ -2358,24 +2895,24 @@ function Step({ n, state, children }) {
2358
2895
  border: `1px solid ${state === "todo" ? "var(--twui-border-strong)" : "transparent"}`,
2359
2896
  background: done ? "var(--twui-success)" : state === "active" ? "var(--twui-primary)" : "transparent",
2360
2897
  color: done || state === "active" ? "var(--twui-primary-fg)" : "inherit"
2361
- }, children: done ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "check", size: 13 }) : n }),
2362
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children })
2898
+ }, children: done ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "check", size: 13 }) : n }),
2899
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children })
2363
2900
  ] });
2364
2901
  }
2365
2902
  function Point({ icon, title, children }) {
2366
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("li", { style: { display: "flex", gap: 12, alignItems: "flex-start" }, children: [
2367
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "twui-tile", style: { width: 32, height: 32 }, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: icon, size: 16 }) }),
2368
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { display: "grid", gap: 2 }, children: [
2369
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("strong", { style: { fontWeight: 600 }, children: title }),
2370
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "twui-muted", children })
2903
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("li", { style: { display: "flex", gap: 12, alignItems: "flex-start" }, children: [
2904
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "twui-tile", style: { width: 32, height: 32 }, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: icon, size: 16 }) }),
2905
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { display: "grid", gap: 2 }, children: [
2906
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("strong", { style: { fontWeight: 600 }, children: title }),
2907
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "twui-muted", children })
2371
2908
  ] })
2372
2909
  ] });
2373
2910
  }
2374
2911
  function ServerSetting({ state, run }) {
2375
- const [editing, setEditing] = (0, import_react3.useState)(false);
2376
- const [value, setValue] = (0, import_react3.useState)(state.server);
2377
- const [error, setError] = (0, import_react3.useState)();
2378
- const [busy, setBusy] = (0, import_react3.useState)(false);
2912
+ const [editing, setEditing] = (0, import_react4.useState)(false);
2913
+ const [value, setValue] = (0, import_react4.useState)(state.server);
2914
+ const [error, setError] = (0, import_react4.useState)();
2915
+ const [busy, setBusy] = (0, import_react4.useState)(false);
2379
2916
  const isDefault = state.server === state.defaultServer;
2380
2917
  const save = async (server) => {
2381
2918
  setBusy(true);
@@ -2391,22 +2928,22 @@ function ServerSetting({ state, run }) {
2391
2928
  }
2392
2929
  };
2393
2930
  if (!editing) {
2394
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "twui-card", style: { display: "flex", alignItems: "center", gap: 12, padding: "12px 16px", boxShadow: "none" }, children: [
2395
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { style: { color: "var(--twui-fg-subtle)" }, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "server", size: 16 }) }),
2396
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { flex: 1, minWidth: 0, display: "grid" }, children: [
2397
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "twui-subtle", children: "服务器" }),
2398
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "twui-row", style: { gap: 6 }, children: [
2399
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "twui-mono", style: { overflowWrap: "anywhere" }, children: host(state.server) }),
2400
- isDefault && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { tone: "accent", children: "官方服务" })
2931
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-card", style: { display: "flex", alignItems: "center", gap: 12, padding: "12px 16px", boxShadow: "none" }, children: [
2932
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: { color: "var(--twui-fg-subtle)" }, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "server", size: 16 }) }),
2933
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { flex: 1, minWidth: 0, display: "grid" }, children: [
2934
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "twui-subtle", children: "服务器" }),
2935
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "twui-row", style: { gap: 6 }, children: [
2936
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "twui-mono", style: { overflowWrap: "anywhere" }, children: host(state.server) }),
2937
+ isDefault && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Badge, { tone: "accent", children: "官方服务" })
2401
2938
  ] })
2402
2939
  ] }),
2403
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { size: "sm", onClick: () => {
2940
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { size: "sm", onClick: () => {
2404
2941
  setValue(state.server);
2405
2942
  setEditing(true);
2406
2943
  }, children: "更改" })
2407
2944
  ] });
2408
2945
  }
2409
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
2946
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
2410
2947
  "form",
2411
2948
  {
2412
2949
  className: "twui-card",
@@ -2416,14 +2953,14 @@ function ServerSetting({ state, run }) {
2416
2953
  void save(value);
2417
2954
  },
2418
2955
  children: [
2419
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2956
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2420
2957
  Field,
2421
2958
  {
2422
2959
  label: "服务器地址",
2423
2960
  htmlFor: "teamwork-server",
2424
2961
  error,
2425
2962
  hint: "自建团队或本地开发时填写你的 DSH Teamwork 地址,例如 http://localhost:3800。更改后需要重新登录。",
2426
- children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2963
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2427
2964
  Input,
2428
2965
  {
2429
2966
  id: "teamwork-server",
@@ -2438,13 +2975,13 @@ function ServerSetting({ state, run }) {
2438
2975
  )
2439
2976
  }
2440
2977
  ),
2441
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "twui-row", children: [
2442
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { type: "submit", variant: "primary", size: "sm", busy, disabled: !value.trim(), children: "保存" }),
2443
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { variant: "ghost", size: "sm", disabled: busy, onClick: () => {
2978
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-row", children: [
2979
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { type: "submit", variant: "primary", size: "sm", busy, disabled: !value.trim() || value.trim() === state.server, children: state.authenticated ? "退出并更换服务器" : "保存" }),
2980
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "ghost", size: "sm", disabled: busy, onClick: () => {
2444
2981
  setEditing(false);
2445
2982
  setError(void 0);
2446
2983
  }, children: "取消" }),
2447
- !isDefault && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("button", { type: "button", className: "twui-link", style: { marginLeft: "auto", fontSize: 12 }, disabled: busy, onClick: () => void save(null), children: [
2984
+ !isDefault && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("button", { type: "button", className: "twui-link", style: { marginLeft: "auto", fontSize: 12 }, disabled: busy, onClick: () => void save(null), children: [
2448
2985
  "恢复为 ",
2449
2986
  host(state.defaultServer)
2450
2987
  ] })
@@ -2453,117 +2990,118 @@ function ServerSetting({ state, run }) {
2453
2990
  }
2454
2991
  );
2455
2992
  }
2456
- function Header({ state, run }) {
2457
- const { teams, sync } = state;
2458
- const only = teams.length === 1 ? teams[0] : void 0;
2459
- const admin = teams.filter((t) => t.role === "admin");
2460
- const manageUrl = admin.length === 1 ? admin[0].consoleUrl : admin.length ? `${state.server}/teams` : void 0;
2461
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2462
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: 12, minWidth: 0, flex: "1 1 260px" }, children: [
2463
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(BrandMark, { size: 36, title: "DSH Teamwork" }),
2464
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { minWidth: 0, display: "grid", gap: 2 }, children: [
2465
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "twui-row", style: { gap: 8 }, children: [
2466
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2467
- "h1",
2468
- {
2469
- style: { fontSize: 15, fontWeight: 650, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" },
2470
- title: teams.map((t) => t.name).join("、") || void 0,
2471
- children: only?.name ?? (teams.length ? `${teams.length} 个团队` : "尚未同步团队")
2472
- }
2473
- ),
2474
- only && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { outline: true, children: only.role === "admin" ? "管理员" : "成员" })
2475
- ] }),
2476
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "twui-subtle twui-row", style: { gap: 4 }, title: "退出后可以更改服务器", children: [
2477
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "server", size: 12 }),
2478
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "twui-mono", children: host(state.server) })
2993
+ function Header({ state, page, team, selectTeam, navigate }) {
2994
+ const pending = state.phones.filter((p) => p.status === "pending").length;
2995
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
2996
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-brand-lockup", children: [
2997
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", className: "twui-brand-home", "aria-label": "返回团队资源", onClick: () => navigate("resources"), children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(BrandMark, { size: 32, title: "DSH Teamwork" }) }),
2998
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-row twui-team-scope", children: [
2999
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "ghost", onClick: () => navigate("teams"), children: "我的团队" }),
3000
+ !!state.teams.length && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
3001
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "chevronRight", size: 14 }),
3002
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Select, { label: "选择团队", value: team, onActivate: () => navigate("resources"), onChange: selectTeam, options: [{ value: "all", label: "全部团队" }, ...state.teams.map((t) => ({ value: t.id, label: t.name, description: t.role === "admin" ? "管理员" : "成员" }))] })
2479
3003
  ] })
2480
3004
  ] })
2481
3005
  ] }),
2482
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "twui-row", style: { marginLeft: "auto" }, children: [
2483
- state.relay === "connected" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { tone: "success", dot: true, title: "手机可以通过 DSH Teamwork App 连到这台电脑", children: "手机可连接" }),
2484
- state.relay === "refused" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { tone: "warning", dot: true, title: "中转服务拒绝了这台电脑的连接:重新登录后会再试", children: "手机连接被拒绝" }),
2485
- sync.running ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { children: "正在同步…" }) : sync.lastError ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { tone: "warning", dot: true, children: "同步失败" }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { tone: "success", dot: true, children: synced(sync.lastSuccess) }),
2486
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
2487
- Button,
2488
- {
2489
- size: "sm",
2490
- icon: "refresh",
2491
- "aria-label": "立即同步",
2492
- title: "立即同步",
2493
- busy: sync.running,
2494
- onClick: () => run(() => api.sync(), "团队配置已同步,本地配置保持不变")
2495
- }
2496
- ),
2497
- manageUrl && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { size: "sm", trailingIcon: "external", onClick: () => window.open(manageUrl, "_blank", "noopener"), children: "管理团队" }),
2498
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { size: "sm", variant: "ghost", icon: "logout", onClick: () => run(() => api.logout(), "已退出,团队配置已从这台 DSH 移除"), children: "退出" })
3006
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-row twui-header-actions", children: [
3007
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Button, { variant: "ghost", icon: "smartphone", "aria-current": page === "devices" ? "page" : void 0, onClick: () => navigate("devices"), children: [
3008
+ "手机连接",
3009
+ pending ? ` · ${pending}` : ""
3010
+ ] }),
3011
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "ghost", icon: "settings", "aria-current": page === "profile" ? "page" : void 0, onClick: () => navigate("profile"), children: "我的账号" })
2499
3012
  ] })
2500
3013
  ] });
2501
3014
  }
2502
- function SessionStrip({ state }) {
2503
- const s = state.session;
2504
- if (!s) return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Banner, { title: "还没有打开会话", children: "打开一个会话后,可以把团队的预设或模型用到这个会话里。" });
2505
- const teamModel = (id) => state.models.find((m) => m.id === id)?.name ?? state.presets.find((p) => p.id === id)?.model ?? id;
2506
- const model = s.model ? s.model.team ? teamModel(s.model.model) : `${s.model.provider}/${s.model.model}` : "未选择";
2507
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "twui-card", style: { display: "flex", flexWrap: "wrap", alignItems: "center", gap: "8px 20px", padding: "12px 16px", boxShadow: "none", background: "var(--twui-fill)" }, children: [
2508
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "twui-row", style: { gap: 6, fontWeight: 600 }, children: [
2509
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "session", size: 15 }),
2510
- "当前会话"
2511
- ] }),
2512
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Meta, { label: "模型", value: model }),
2513
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Meta, { label: "预设", value: s.preset ? `${s.preset.name} · v${s.preset.version}` : "无团队预设" }),
2514
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { style: { marginLeft: "auto" }, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { tone: s.started ? "neutral" : "accent", dot: true, children: s.started ? "已开始对话" : "尚未开始对话" }) })
2515
- ] });
3015
+ function Quota({ team }) {
3016
+ const [label, setLabel] = (0, import_react4.useState)("预算加载中…");
3017
+ (0, import_react4.useEffect)(() => {
3018
+ let active = true;
3019
+ let timer;
3020
+ const load = async () => {
3021
+ let next = "预算暂不可用";
3022
+ try {
3023
+ const q = await api.quota(team);
3024
+ next = q.exhausted ? "预算已用尽" : q.state === "unconfirmed" ? "预算待核实" : q.state === "known" && q.remaining !== null ? `预算剩余 ${q.remaining} 积分` : q.tokenLimited ? "已设 Token 上限" : "未设预算上限";
3025
+ } catch {
3026
+ }
3027
+ if (active) {
3028
+ setLabel(next);
3029
+ timer = setTimeout(load, 3e4);
3030
+ }
3031
+ };
3032
+ void load();
3033
+ return () => {
3034
+ active = false;
3035
+ clearTimeout(timer);
3036
+ };
3037
+ }, [team]);
3038
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "twui-footer-service", role: "status", title: "所选团队中我的预算;模型或上游仍可能有其他限制。切换资源团队不改变当前会话。", children: label });
2516
3039
  }
2517
- function Meta({ label, value }) {
2518
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "twui-row", style: { gap: 6, minWidth: 0 }, children: [
2519
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "twui-subtle", children: label }),
2520
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { style: { fontWeight: 500, overflowWrap: "anywhere" }, children: value })
3040
+ function Footer({ state, team, run }) {
3041
+ const [busy, setBusy] = (0, import_react4.useState)(false);
3042
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
3043
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-footer-identity", children: [
3044
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "twui-footer-name", children: "Teamwork" }),
3045
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "twui-footer-service", title: state.server, children: [
3046
+ state.server === state.defaultServer ? "官方服务" : host(state.server),
3047
+ " · 本机 DSH"
3048
+ ] })
3049
+ ] }),
3050
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-row twui-footer-actions", children: [
3051
+ state.authenticated && state.teams.some((t) => t.id === team) && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Quota, { team }, `${state.server}:${state.authRevision}:${team}`),
3052
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { role: "status", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Badge, { tone: state.sync.lastError ? "warning" : "success", dot: true, children: state.sync.running ? "正在同步…" : state.sync.lastError ? "同步失败" : synced(state.sync.lastSuccess) }) }),
3053
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "ghost", size: "sm", icon: "refresh", busy: busy || state.sync.running, onClick: async () => {
3054
+ setBusy(true);
3055
+ await run(() => api.sync(), "团队配置已同步");
3056
+ setBusy(false);
3057
+ }, children: "刷新" })
3058
+ ] })
2521
3059
  ] });
2522
3060
  }
2523
3061
  function PresetItem({ preset, state, dsh, run, onInstall }) {
2524
- const [open, setOpen] = (0, import_react3.useState)(false);
3062
+ const [open, setOpen] = (0, import_react4.useState)(false);
2525
3063
  const missing = missingTools(preset);
2526
3064
  const plugins = pluginsNotReady(preset);
2527
3065
  const active = state.session?.preset?.id === preset.id;
2528
3066
  const blocked = !preset.modelAvailable ? "预设引用的团队模型已不可用,请联系管理员。" : plugins.length ? `依赖插件 ${plugins.map((p) => p.name).join("、")} 尚未就绪。` : missing.length && state.session ? `缺少必需工具 ${missing.map((t) => t.name).join("、")},请在 DSH 插件管理器中安装或启用。` : void 0;
2529
- const useBlocked = blocked ?? (!state.session ? "" : state.session.started && !active ? "当前会话已开始对话,预设只能用在新会话里。" : void 0);
3067
+ const useBlocked = blocked ?? (state.session?.started && !active ? "当前会话已开始对话,预设只能用在新会话里。" : void 0);
2530
3068
  const ready = !blocked;
2531
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3069
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2532
3070
  Item,
2533
3071
  {
2534
3072
  icon: "layers",
2535
3073
  title: preset.name,
2536
- subtitle: state.teams.length > 1 ? `${preset.teamName} · ${preset.id} · v${preset.version}` : `${preset.id} · v${preset.version}`,
3074
+ subtitle: preset.teamName,
2537
3075
  description: preset.description || void 0,
2538
- tags: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2539
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Badge, { children: [
2540
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { name: "cpu", size: 12 }),
3076
+ tags: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
3077
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Badge, { children: [
3078
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Icon, { name: "cpu", size: 12 }),
2541
3079
  preset.model
2542
3080
  ] }),
2543
- active ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { tone: "accent", dot: true, children: "本会话正在使用" }) : ready ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { tone: "success", dot: true, children: "可以使用" }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { tone: "warning", dot: true, children: "未就绪" })
3081
+ active ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Badge, { tone: "accent", dot: true, children: "本会话正在使用" }) : ready ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Badge, { tone: !state.session && missing.length ? "neutral" : "success", dot: true, children: !state.session && missing.length ? "启动时检查工具" : "可以使用" }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Badge, { tone: "warning", dot: true, children: "未就绪" })
2544
3082
  ] }),
2545
- actions: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2546
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { variant: "ghost", size: "sm", trailingIcon: open ? "chevronDown" : "chevronRight", "aria-expanded": open, onClick: () => setOpen(!open), children: "详情" }),
2547
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { size: "sm", icon: "plus", disabled: !ready, onClick: () => {
3083
+ actions: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
3084
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "ghost", size: "sm", trailingIcon: open ? "chevronDown" : "chevronRight", "aria-expanded": open, onClick: () => setOpen(!open), children: "详情" }),
3085
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { size: "sm", variant: !state.session || state.session.started ? "primary" : "secondary", icon: "plus", disabled: !ready, onClick: () => {
2548
3086
  dsh.uiWorkspace.startSession(void 0, { agentPreset: `team:${preset.teamId}:${preset.id}` });
2549
3087
  dsh.layout.selectPanel(null);
2550
3088
  }, children: "新建会话" }),
2551
- !active && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { variant: "primary", size: "sm", disabled: useBlocked !== void 0, onClick: () => run(() => api.use(state.session.id, preset.id), (r) => r.message), children: "用于当前会话" })
3089
+ !active && state.session && !state.session.started && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "primary", size: "sm", disabled: useBlocked !== void 0, onClick: () => run(() => api.use(state.session.id, preset.id), (r) => r.message), children: "用于当前空白会话" })
2552
3090
  ] }),
2553
- notice: useBlocked && !active ? /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "twui-row", style: { gap: 6 }, children: [
2554
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Notice, { tone: blocked ? "warning" : "neutral", children: useBlocked }),
2555
- plugins.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "twui-link", style: { fontSize: 12 }, onClick: onInstall, children: "前往安装" })
3091
+ notice: useBlocked && !active ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-row", style: { gap: 6 }, children: [
3092
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Notice, { tone: blocked ? "warning" : "neutral", children: useBlocked }),
3093
+ plugins.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", className: "twui-link", style: { fontSize: 12 }, onClick: onInstall, children: "前往安装" })
2556
3094
  ] }) : void 0,
2557
- children: open && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(ItemBody, { children: [
2558
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(DefinitionList, { items: [
3095
+ children: open && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(ItemBody, { children: [
3096
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(DefinitionList, { items: [
2559
3097
  ["模型", preset.model],
2560
- ["工具", preset.tools.length ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "twui-row", style: { gap: 6 }, children: preset.tools.map((t) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Badge, { tone: toolText[t.state][1], title: t.required ? "必需" : "可选", children: [
2561
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "twui-mono", children: t.name }),
3098
+ ["工具", preset.tools.length ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "twui-row", style: { gap: 6 }, children: preset.tools.map((t) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Badge, { tone: toolText[t.state][1], title: t.required ? "必需" : "可选", children: [
3099
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "twui-mono", children: t.name }),
2562
3100
  t.required ? "" : " · 可选",
2563
3101
  " · ",
2564
3102
  toolText[t.state][0]
2565
3103
  ] }, t.name)) }) : "无要求"],
2566
- ["依赖插件", preset.plugins.length ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "twui-row", style: { gap: 6 }, children: preset.plugins.map((p) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Badge, { tone: pluginText[p.state][1], children: [
3104
+ ["依赖插件", preset.plugins.length ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "twui-row", style: { gap: 6 }, children: preset.plugins.map((p) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Badge, { tone: pluginText[p.state][1], children: [
2567
3105
  p.name,
2568
3106
  " @",
2569
3107
  p.version,
@@ -2572,7 +3110,7 @@ function PresetItem({ preset, state, dsh, run, onInstall }) {
2572
3110
  ] }, p.id)) }) : "无"],
2573
3111
  ["版本", `v${preset.version},管理员发布新版本后下次同步生效`]
2574
3112
  ] }),
2575
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "twui-subtle", children: "工具按当前会话检查;切换会话后和每次请求前都会重新检查。" })
3113
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "twui-subtle", children: "工具按当前会话检查;切换会话后和每次请求前都会重新检查。" })
2576
3114
  ] })
2577
3115
  }
2578
3116
  );
@@ -2580,39 +3118,41 @@ function PresetItem({ preset, state, dsh, run, onInstall }) {
2580
3118
  function ModelItem({ model, state, run }) {
2581
3119
  const s = state.session;
2582
3120
  const active = !!s?.model?.team && s.model.model === model.id;
2583
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3121
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2584
3122
  Item,
2585
3123
  {
2586
3124
  icon: "cpu",
2587
3125
  title: model.name,
2588
- subtitle: state.teams.length > 1 ? `${model.teamName} · ${model.id} · v${model.version}` : `${model.id} · v${model.version}`,
3126
+ subtitle: model.teamName,
2589
3127
  description: "由团队服务器代为调用,provider 密钥留在服务器上。只改当前会话,不改本地默认模型。",
2590
- tags: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "twui-mono", children: model.upstream }) }),
2591
- actions: active ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { tone: "accent", dot: true, children: "本会话正在使用" }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { variant: "primary", size: "sm", disabled: !s, onClick: () => run(() => api.use(s.id, model.id), (r) => r.message), children: "用于当前会话" })
3128
+ tags: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Badge, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "twui-mono", children: model.upstream }) }),
3129
+ actions: active ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Badge, { tone: "accent", dot: true, children: "本会话正在使用" }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "primary", size: "sm", disabled: !s, onClick: () => run(() => api.use(s.id, model.id), (r) => r.message), children: "用于当前会话" }),
3130
+ notice: !s ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Notice, { children: "先在 DSH 新建或打开一个会话,再选择模型。" }) : void 0
2592
3131
  }
2593
3132
  );
2594
3133
  }
2595
3134
  function PluginItem({ plugin, run }) {
2596
- const [confirming, setConfirming] = (0, import_react3.useState)(false);
2597
- const [busy, setBusy] = (0, import_react3.useState)(false);
3135
+ const [confirming, setConfirming] = (0, import_react4.useState)(false);
3136
+ const [busy, setBusy] = (0, import_react4.useState)(false);
2598
3137
  const [label, tone] = pluginText[plugin.state];
2599
3138
  const spec = `${plugin.package ?? plugin.name}@${plugin.version}`;
2600
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3139
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2601
3140
  Item,
2602
3141
  {
2603
3142
  icon: "puzzle",
2604
3143
  title: plugin.name,
2605
- subtitle: spec,
3144
+ subtitle: plugin.teamName,
2606
3145
  description: plugin.description || void 0,
2607
- tags: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2608
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { tone, dot: true, children: label }),
2609
- plugin.localVersion && plugin.localVersion !== plugin.version && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(Badge, { children: [
3146
+ tags: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
3147
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "twui-subtle twui-mono", children: spec }),
3148
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Badge, { tone, dot: true, children: label }),
3149
+ plugin.localVersion && plugin.localVersion !== plugin.version && /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(Badge, { children: [
2610
3150
  "本地 ",
2611
3151
  plugin.localVersion
2612
3152
  ] })
2613
3153
  ] }),
2614
- actions: plugin.state === "missing" ? !confirming && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { variant: "primary", size: "sm", onClick: () => setConfirming(true), children: "安装" }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "twui-subtle", children: "在 DSH 插件管理器中管理" }),
2615
- children: confirming && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3154
+ actions: plugin.state === "missing" ? !confirming && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { variant: "primary", size: "sm", onClick: () => setConfirming(true), children: "安装" }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "twui-subtle", children: "在 DSH 插件管理器中管理" }),
3155
+ children: confirming && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2616
3156
  Confirm,
2617
3157
  {
2618
3158
  title: `安装并启用 ${spec}?`,
@@ -2633,124 +3173,167 @@ function PluginItem({ plugin, run }) {
2633
3173
  );
2634
3174
  }
2635
3175
  function HeaderSkeleton() {
2636
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "twui-row", style: { gap: 12 }, children: [
2637
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Skeleton, { width: 36, height: 36 }),
2638
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { display: "grid", gap: 6 }, children: [
2639
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Skeleton, { width: 140, height: 14 }),
2640
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Skeleton, { width: 100, height: 10 })
3176
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-row", style: { gap: 12 }, children: [
3177
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Skeleton, { width: 36, height: 36 }),
3178
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { display: "grid", gap: 6 }, children: [
3179
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Skeleton, { width: 140, height: 14 }),
3180
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Skeleton, { width: 100, height: 10 })
2641
3181
  ] })
2642
3182
  ] });
2643
3183
  }
2644
3184
  function ListSkeleton() {
2645
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_jsx_runtime6.Fragment, { children: [0, 1, 2].map((i) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "twui-item", style: { padding: 16, display: "flex", gap: 14 }, children: [
2646
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Skeleton, { width: 36, height: 36 }),
2647
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { flex: 1, display: "grid", gap: 8 }, children: [
2648
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Skeleton, { width: "40%" }),
2649
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Skeleton, { width: "75%", height: 12 }),
2650
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Skeleton, { width: 120, height: 20 })
3185
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: [0, 1, 2].map((i) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "twui-item", style: { padding: 16, display: "flex", gap: 14 }, children: [
3186
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Skeleton, { width: 36, height: 36 }),
3187
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { flex: 1, display: "grid", gap: 8 }, children: [
3188
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Skeleton, { width: "40%" }),
3189
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Skeleton, { width: "75%", height: 12 }),
3190
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Skeleton, { width: 120, height: 20 })
2651
3191
  ] })
2652
3192
  ] }, i)) });
2653
3193
  }
2654
3194
  var relayText = {
2655
- off: ["服务器没有开启手机接入", "只有提供中转服务的服务器(如官方服务 www.dshteamwork.com)才能让手机连到这台电脑。"],
3195
+ off: ["手机连接尚未开启", "请确认服务器提供手机中转服务,并且当前账号已加入团队。"],
2656
3196
  connecting: ["正在连接中转服务…", "连上之后就可以在这里配对手机。"],
2657
3197
  refused: ["中转服务拒绝了这台电脑", "登录可能已失效,或另一个 DSH 正以这台电脑的身份连接。退出后重新登录即可重试。"]
2658
3198
  };
2659
3199
  var shortTime = (iso) => new Date(iso).toLocaleString("zh-CN", { month: "numeric", day: "numeric", hour: "2-digit", minute: "2-digit" });
2660
3200
  function Phones({ state, run }) {
2661
- const [offer, setOffer] = (0, import_react3.useState)();
2662
- const [revoking, setRevoking] = (0, import_react3.useState)();
3201
+ const [offer, setOffer] = (0, import_react4.useState)();
3202
+ const [revoking, setRevoking] = (0, import_react4.useState)();
3203
+ const [busy, setBusy] = (0, import_react4.useState)();
3204
+ const [error, setError] = (0, import_react4.useState)();
3205
+ const [expired, setExpired] = (0, import_react4.useState)(false);
3206
+ const locked = (0, import_react4.useRef)(false);
2663
3207
  const pending = state.phones.filter((p) => p.status === "pending");
2664
3208
  const paired = state.phones.filter((p) => p.status === "confirmed");
2665
- const seen = (0, import_react3.useRef)(pending.length);
2666
- (0, import_react3.useEffect)(() => {
2667
- if (pending.length > seen.current) setOffer(void 0);
2668
- seen.current = pending.length;
2669
- }, [pending.length]);
3209
+ const seen = (0, import_react4.useRef)(new Set(pending.map((p) => p.id)));
3210
+ (0, import_react4.useEffect)(() => {
3211
+ if (pending.some((p) => !seen.current.has(p.id))) {
3212
+ setOffer(void 0);
3213
+ setExpired(false);
3214
+ }
3215
+ seen.current = new Set(pending.map((p) => p.id));
3216
+ }, [state.phones]);
3217
+ (0, import_react4.useEffect)(() => {
3218
+ if (state.relay !== "connected") {
3219
+ setOffer(void 0);
3220
+ setExpired(false);
3221
+ }
3222
+ }, [state.relay]);
3223
+ const perform = async (key, action, done) => {
3224
+ if (locked.current) return false;
3225
+ locked.current = true;
3226
+ setBusy(key);
3227
+ setError(void 0);
3228
+ try {
3229
+ return await run(async () => {
3230
+ try {
3231
+ return await action();
3232
+ } catch (failure) {
3233
+ setError(failure.message);
3234
+ throw failure;
3235
+ }
3236
+ }, done);
3237
+ } finally {
3238
+ locked.current = false;
3239
+ setBusy(void 0);
3240
+ }
3241
+ };
3242
+ const pair = () => perform("pair", async () => {
3243
+ setOffer(await api.pairPhone());
3244
+ setExpired(false);
3245
+ });
2670
3246
  if (state.relay !== "connected") {
2671
3247
  const [title, body] = relayText[state.relay];
2672
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Card, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(EmptyState, { icon: "smartphone", title, children: body }) });
3248
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Card, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(EmptyState, { icon: "smartphone", title, children: body }) });
2673
3249
  }
2674
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2675
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Card, { children: offer ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(PairingCode, { offer, onDone: () => setOffer(void 0) }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3250
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
3251
+ error && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Banner, { tone: "warning", title: "手机操作未完成", children: error }),
3252
+ expired && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Banner, { tone: "warning", title: "配对码已过期", action: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { busy: busy === "pair", disabled: !!busy, onClick: () => void pair(), children: "重新生成配对码" }), children: "配对码只能使用一次。重新生成后,请在手机上扫描新码。" }),
3253
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Card, { children: offer ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PairingCode, { offer, onDone: () => setOffer(void 0), onExpire: () => {
3254
+ setOffer(void 0);
3255
+ setExpired(true);
3256
+ } }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2676
3257
  EmptyState,
2677
3258
  {
2678
3259
  icon: "smartphone",
2679
3260
  title: "在手机上操作这台电脑的 DSH",
2680
- action: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { icon: "plus", onClick: () => run(async () => setOffer(await api.pairPhone())), children: "配对新手机" }),
2681
- children: "用 DSH Teamwork App 扫描这里显示的二维码,再在这台电脑上确认,手机就能查看会话、发送消息和处理审批。"
3261
+ action: !expired && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { icon: "plus", busy: busy === "pair", disabled: !!busy, onClick: () => void pair(), children: "配对新手机" }),
3262
+ children: "手机和电脑须登录同一个 Teamwork 账号。配对后可访问本机 DSH 有权限的个人与各团队会话,目前不能只授权一个团队;配对不会增加团队权限,任一端都可解除。"
2682
3263
  }
2683
3264
  ) }),
2684
- pending.map((phone) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3265
+ pending.map((phone) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2685
3266
  Item,
2686
3267
  {
2687
3268
  icon: "smartphone",
2688
3269
  title: phone.deviceName,
2689
3270
  subtitle: `${shortTime(phone.createdAt)} 申请配对`,
2690
- tags: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { tone: "warning", dot: true, children: "等待你确认" }),
2691
- description: "确认后,这台手机可以查看这台电脑上的会话、发送消息、回答 Agent 的提问和处理审批。不是你本人的手机请拒绝。",
2692
- actions: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
2693
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { size: "sm", variant: "ghost", onClick: () => run(() => api.decidePhone(phone.id, false), "已拒绝"), children: "拒绝" }),
2694
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { size: "sm", onClick: () => run(() => api.decidePhone(phone.id, true), `${phone.deviceName} 已配对`), children: "确认配对" })
3271
+ tags: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Badge, { tone: "warning", dot: true, children: "等待你确认" }),
3272
+ description: `${phone.safetyCode ? `安全码:${phone.safetyCode}。请核对手机上的安全码一致,并在手机上确认。` : "等待手机完成加密握手,暂时无法确认。"} 确认后,手机可查看本机 DSH 可访问的个人与各团队会话,发送消息、回答 Agent 提问和处理审批。目前不能只授权一个团队;配对不会增加团队权限,任一端都可解除。手机与电脑须登录同一账号。`,
3273
+ actions: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
3274
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { size: "sm", variant: "ghost", busy: busy === `reject:${phone.id}`, disabled: !!busy, onClick: () => void perform(`reject:${phone.id}`, () => api.decidePhone(phone.id, false), "已拒绝"), children: "拒绝" }),
3275
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { size: "sm", busy: busy === `accept:${phone.id}`, disabled: !!busy || !phone.safetyCode || !phone.phoneConfirmed, onClick: () => void perform(`accept:${phone.id}`, () => api.decidePhone(phone.id, true), `${phone.deviceName} 已配对`), children: "安全码一致,确认配对" })
2695
3276
  ] })
2696
3277
  },
2697
3278
  phone.id
2698
3279
  )),
2699
- paired.map((phone) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3280
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h3", { style: { fontSize: 15, fontWeight: 500 }, children: "已配对手机" }),
3281
+ !paired.length && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { className: "twui-muted", children: "尚无已配对手机。配对是可选功能,不影响团队资源的使用。" }),
3282
+ paired.map((phone) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2700
3283
  Item,
2701
3284
  {
2702
3285
  icon: "smartphone",
2703
3286
  title: phone.deviceName,
2704
3287
  subtitle: phone.lastUsedAt ? `最近使用 ${shortTime(phone.lastUsedAt)}` : `配对于 ${shortTime(phone.createdAt)}`,
2705
- tags: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Badge, { tone: "success", dot: true, children: "已配对" }),
2706
- actions: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { size: "sm", variant: "ghost", onClick: () => setRevoking(phone), children: "解除配对" })
3288
+ tags: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Badge, { tone: phone.verified ? "success" : "warning", dot: true, children: phone.verified ? "已验证加密设备" : "需要重新配对" }),
3289
+ actions: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { size: "sm", variant: "ghost", disabled: !!busy, onClick: () => setRevoking(phone), children: "解除配对" })
2707
3290
  },
2708
3291
  phone.id
2709
3292
  )),
2710
- revoking && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
3293
+ revoking && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2711
3294
  Confirm,
2712
3295
  {
2713
3296
  title: `解除与 ${revoking.deviceName} 的配对?`,
2714
3297
  description: "这台手机会立即断开,之后需要重新扫码配对才能再连到这台电脑。",
2715
3298
  confirmLabel: "解除配对",
2716
3299
  cancelLabel: "取消",
3300
+ busy: !!busy,
2717
3301
  onCancel: () => setRevoking(void 0),
2718
- onConfirm: () => {
2719
- const phone = revoking;
2720
- setRevoking(void 0);
2721
- void run(() => api.revokePhone(phone.id), "已解除配对");
3302
+ onConfirm: async () => {
3303
+ if (await perform(`revoke:${revoking.id}`, () => api.revokePhone(revoking.id), "已解除配对")) setRevoking(void 0);
2722
3304
  }
2723
3305
  }
2724
3306
  )
2725
3307
  ] });
2726
3308
  }
2727
- function PairingCode({ offer, onDone }) {
2728
- const [now, setNow] = (0, import_react3.useState)(Date.now());
2729
- (0, import_react3.useEffect)(() => {
3309
+ function PairingCode({ offer, onDone, onExpire }) {
3310
+ const [now, setNow] = (0, import_react4.useState)(Date.now());
3311
+ (0, import_react4.useEffect)(() => {
2730
3312
  const timer = setInterval(() => setNow(Date.now()), 1e3);
2731
3313
  return () => clearInterval(timer);
2732
3314
  }, []);
2733
3315
  const left = Math.max(0, Math.round((Date.parse(offer.expiresAt) - now) / 1e3));
2734
- (0, import_react3.useEffect)(() => {
2735
- if (left === 0) onDone();
2736
- }, [left, onDone]);
2737
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { display: "flex", gap: 20, alignItems: "center", flexWrap: "wrap" }, children: [
2738
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(QrCode, { value: offer.link, size: 168 }),
2739
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { style: { display: "grid", gap: 8, minWidth: 200, flex: "1 1 200px" }, children: [
2740
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("h2", { style: { fontSize: 15, fontWeight: 650 }, children: "用 DSH Teamwork App 扫码" }),
2741
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "twui-subtle", children: "也可以在 App 里手动输入配对码:" }),
2742
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "twui-mono", style: { fontSize: 20, letterSpacing: "0.12em" }, children: [
2743
- offer.code.slice(0, 4),
3316
+ (0, import_react4.useEffect)(() => {
3317
+ if (left === 0) onExpire();
3318
+ }, [left, onExpire]);
3319
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { display: "flex", gap: 20, alignItems: "center", flexWrap: "wrap" }, children: [
3320
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(QrCode, { value: offer.link, size: 168 }),
3321
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { display: "grid", gap: 8, minWidth: 200, flex: "1 1 200px" }, children: [
3322
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("h2", { style: { fontSize: 15, fontWeight: 650 }, children: "用 DSH Teamwork App 扫码" }),
3323
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "twui-subtle", children: "也可以在 App 里手动输入配对码:" }),
3324
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "twui-mono", style: { fontSize: 20, letterSpacing: "0.12em" }, children: [
3325
+ offer.code.slice(0, 3),
2744
3326
  " ",
2745
- offer.code.slice(4)
3327
+ offer.code.slice(3)
2746
3328
  ] }),
2747
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "twui-subtle", children: [
3329
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "twui-subtle", children: [
2748
3330
  Math.floor(left / 60),
2749
3331
  ":",
2750
3332
  String(left % 60).padStart(2, "0"),
2751
3333
  " 后失效,只能使用一次。扫码后请回到这里确认。"
2752
3334
  ] }),
2753
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Button, { size: "sm", variant: "ghost", onClick: onDone, children: "取消" }) })
3335
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "twui-subtle", children: "收起后,配对码在到期前仍然有效;手机提交后需在本机确认。" }),
3336
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Button, { size: "sm", variant: "ghost", onClick: onDone, children: "收起配对码" }) })
2754
3337
  ] })
2755
3338
  ] });
2756
3339
  }
@@ -2762,17 +3345,23 @@ function QrCode({ value, size }) {
2762
3345
  let d = "";
2763
3346
  for (let row = 0; row < count; row++) for (let col = 0; col < count; col++) if (qr.isDark(row, col)) d += `M${col + 4} ${row + 4}h1v1h-1z`;
2764
3347
  const extent = count + 8;
2765
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("svg", { role: "img", "aria-label": "配对二维码", width: size, height: size, viewBox: `0 0 ${extent} ${extent}`, shapeRendering: "crispEdges", style: { borderRadius: 8, flex: "none" }, children: [
2766
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("rect", { width: extent, height: extent, fill: "#ffffff" }),
2767
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", { d, fill: "#000000" })
3348
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("svg", { role: "img", "aria-label": "配对二维码", width: size, height: size, viewBox: `0 0 ${extent} ${extent}`, shapeRendering: "crispEdges", style: { borderRadius: 8, flex: "none" }, children: [
3349
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("rect", { width: extent, height: extent, fill: "#ffffff" }),
3350
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { d, fill: "#000000" })
2768
3351
  ] });
2769
3352
  }
2770
3353
 
2771
3354
  // src/web/index.tsx
2772
- var import_jsx_runtime7 = require("react/jsx-runtime");
3355
+ var import_jsx_runtime8 = require("react/jsx-runtime");
2773
3356
  var inject = ["slots", "sessions", "layout", "uiWorkspace"];
2774
3357
  function apply(ctx) {
3358
+ const trackSession = currentSessionTracker(ctx.sessions.list);
3359
+ trackSession();
3360
+ ctx.effect(() => ctx.sessions.list.subscribe(() => {
3361
+ trackSession();
3362
+ }));
2775
3363
  const host2 = {
3364
+ currentSession: trackSession,
2776
3365
  get sessions() {
2777
3366
  return ctx.sessions;
2778
3367
  },
@@ -2785,30 +3374,12 @@ function apply(ctx) {
2785
3374
  };
2786
3375
  ctx.slots.inject(
2787
3376
  "sidebar.panellist",
2788
- () => ctx.slots.register({ name: "sidebar.panellist", id: PANEL_ID, order: 60, label: "Teamwork" }, (owner) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TeamIcon, { size: owner?.size || 16, active: !!owner?.active }))
3377
+ () => ctx.slots.register({ name: "sidebar.panellist", id: PANEL_ID, order: 60, label: "Teamwork" }, (owner) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(TeamIcon, { size: owner?.size || 16, active: !!owner?.active }))
2789
3378
  );
2790
- ctx.slots.inject("main", () => ctx.slots.register({ name: "main", key: PANEL_ID }, () => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TeamworkPanel, { host: host2 })));
3379
+ ctx.slots.inject("main", () => ctx.slots.register({ name: "main", key: PANEL_ID }, () => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(TeamworkPanel, { host: host2 })));
2791
3380
  }
3381
+ var BRAND_MARK = "M206.84 178.37L203.20 176.51L197.50 174.07L191.54 172.04L185.35 170.41L178.93 169.17L172.31 168.32L165.50 167.86L158.53 167.77L151.41 168.06L144.16 168.72L136.80 169.75L129.35 171.13L121.82 172.87L114.23 174.96L109.15 176.54L98.77 180.09L95.30 181.17L90.18 182.60L86.83 183.42L81.88 184.48L77.03 185.31L72.29 185.93L67.65 186.34L61.63 186.57L57.23 186.50L51.52 186.10L47.35 185.57L41.96 184.58L36.75 183.26L31.71 181.62L34.49 185.76L37.47 189.81L40.64 193.76L44.00 197.60L47.54 201.33L51.26 204.95L55.15 208.44L59.21 211.81L63.44 215.04L67.84 218.14L72.39 221.10L77.09 223.91L81.95 226.57L86.95 229.08L94.72 232.53L102.79 235.59L111.15 238.26L119.80 240.51L125.70 241.78L134.78 243.30L140.96 244.06L144.09 244.36L173.55 246.46L180.99 247.20L187.94 248.12L194.39 249.29L200.32 250.79L203.07 251.68L205.68 252.68L209.32 254.39L212.63 256.39L215.59 258.72L218.18 261.38L219.71 263.37L223.20 305.34L228.75 306.83L233.12 307.74L237.50 308.33L241.25 308.55L245.00 308.50L249.38 308.10L253.75 307.35L258.75 306.16L268.56 303.21L246.40 256.22L246.73 253.74L247.28 251.31L248.06 248.95L249.61 245.50L250.90 243.25L252.39 241.04L254.06 238.85L255.91 236.70L257.94 234.56L260.13 232.43L264.98 228.19L270.41 223.93L277.92 218.50L302.38 201.94L304.94 200.12L309.92 196.37L317.01 190.52L321.49 186.47L327.85 180.20L333.75 173.71L339.20 167.02L344.20 160.15L347.28 155.48L350.15 150.75L352.81 145.96L355.27 141.12L357.52 136.24L359.57 131.33L361.40 126.38L363.02 121.41L364.43 116.42L365.63 111.42L366.61 106.41L367.38 101.41L367.94 96.41L368.27 91.43L364.74 95.37L360.88 99.12L356.71 102.68L353.38 105.22L348.64 108.41L344.87 110.67L339.54 113.49L335.33 115.45L330.91 117.29L326.31 118.98L321.50 120.54L318.18 121.50L313.04 122.82L309.49 123.63L298.73 125.74L293.54 126.91L285.93 128.90L278.54 131.16L271.39 133.69L264.50 136.48L257.89 139.53L253.65 141.71L249.55 144.00L245.59 146.40L239.93 150.20L236.35 152.87L232.93 155.65L228.12 160.01L225.13 163.04L222.32 166.18L218.46 171.06L215.04 176.17L212.07 181.49ZM0.00 299.31L6.29 300.81L19.95 304.97L27.09 306.81L30.85 307.55L34.71 308.11L38.64 308.45L42.44 308.56L45.78 308.48L49.55 308.17L52.80 307.74L56.57 307.06L60.13 306.25L63.75 305.29L76.43 301.42L80.87 300.19L85.96 299.11L90.20 298.63L92.48 298.57L95.22 298.67L97.56 298.92L100.48 299.40L106.29 300.81L119.95 304.97L126.98 306.78L130.85 307.55L134.55 308.09L137.85 308.40L141.64 308.56L145.61 308.49L149.55 308.17L153.42 307.64L157.20 306.93L160.85 306.07L164.44 305.10L179.80 300.47L183.48 299.58L186.92 298.96L190.65 298.61L194.30 298.61L198.04 298.98L202.57 299.84L194.87 271.11L192.61 271.07L189.26 271.14L185.49 271.44L182.24 271.86L178.58 272.51L174.89 273.34L171.27 274.29L157.98 278.34L153.04 279.67L149.99 280.33L147.56 280.72L144.76 280.99L142.48 281.06L140.20 281.00L137.40 280.73L134.98 280.35L131.93 279.70L127.00 278.38L113.68 274.32L109.51 273.23L105.83 272.42L102.03 271.77L98.93 271.39L95.61 271.14L92.44 271.07L88.64 271.18L84.71 271.52L80.85 272.08L77.09 272.82L69.95 274.66L55.73 278.98L49.99 280.33L47.09 280.78L44.76 280.99L42.48 281.06L39.73 280.97L35.96 280.52L31.93 279.70L27.57 278.54L16.42 275.11L10.94 273.58L5.08 272.28L0.00 271.51ZM284.83 299.31L289.73 298.66L292.48 298.57L295.69 298.71L299.01 299.13L302.00 299.72L305.73 300.65L319.95 304.97L327.09 306.81L330.85 307.55L334.71 308.11L338.64 308.45L342.44 308.56L345.78 308.48L349.71 308.16L353.42 307.64L357.31 306.90L364.44 305.10L379.25 300.61L382.97 299.69L385.96 299.11L389.73 298.66L392.93 298.57L396.15 298.75L400.00 299.31L400.00 271.51L395.61 271.14L390.85 271.08L386.27 271.36L381.47 271.98L377.09 272.82L372.66 273.91L367.92 275.26L357.41 278.50L352.52 279.80L347.56 280.72L345.22 280.96L342.93 281.06L340.65 281.02L338.34 280.84L335.96 280.52L332.97 279.94L327.57 278.54L316.46 275.13L311.57 273.75L306.45 272.55L301.11 271.64L297.98 271.30L294.99 271.12L289.43 271.13L283.78 271.64L277.70 272.69Z";
2792
3382
  function TeamIcon({ size, active }) {
2793
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
2794
- "svg",
2795
- {
2796
- width: size,
2797
- height: size,
2798
- viewBox: "0 0 24 24",
2799
- fill: "none",
2800
- stroke: "currentColor",
2801
- strokeWidth: "2",
2802
- strokeLinecap: "round",
2803
- strokeLinejoin: "round",
2804
- "aria-hidden": "true",
2805
- style: { color: active ? "var(--dsw-alias-state-business-primary)" : "inherit" },
2806
- children: [
2807
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { d: "M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2" }),
2808
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("circle", { cx: "9", cy: "7", r: "4" }),
2809
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { d: "M22 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75" })
2810
- ]
2811
- }
2812
- );
3383
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("svg", { width: size, height: size, viewBox: "0 0 400 400", role: "img", "aria-label": "DSH Teamwork", style: { flex: "none", display: "block", color: active ? "var(--dsw-alias-state-business-primary)" : "inherit" }, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { fill: "currentColor", d: BRAND_MARK }) });
2813
3384
  }
2814
3385
  return module.exports; } });