@alexpeng/dsh-custom-plugin 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -1570,6 +1570,12 @@ window.__ModuleLoader__.load({
1570
1570
  * over `/api/custom-plugin` fetch routes.
1571
1571
  * @module @alexpeng/dsh-custom-plugin/client/custom
1572
1572
  */
1573
+ /**
1574
+ * dsh's shipped web profile configures the session index with `openAt: never`,
1575
+ * so cross-session full-text search can legitimately be unavailable. Say what
1576
+ * still works instead of leaving a bare error that reads as a broken palette.
1577
+ */
1578
+ const CROSS_SEARCH_UNAVAILABLE = "跨会话全文搜索不可用;下方结果仍按标题匹配会话与工作区。";
1573
1579
  function fmtClock(time) {
1574
1580
  const d = new Date(time);
1575
1581
  const pad = (n) => String(n).padStart(2, "0");
@@ -1829,6 +1835,57 @@ window.__ModuleLoader__.load({
1829
1835
  return null;
1830
1836
  }
1831
1837
  }
1838
+ /**
1839
+ * Follow the Session the conversation is showing. The 0.1.7 session list
1840
+ * snapshot dropped its `current` field — view selection moved to the
1841
+ * Workspace browser — so the plugin reads the identity off the standard
1842
+ * `sessionId` prop that every session-scoped slot entry receives.
1843
+ *
1844
+ * Several entries carry it at once (two header actions, the utilities entry,
1845
+ * the quote dock, and one tail entry per turn), and a turn-level entry can
1846
+ * unmount while the same Session stays open. Only the LAST mounted holder may
1847
+ * clear the identity, otherwise the rail would go blank under the surviving
1848
+ * entries, whose props never change and so never re-run their effect.
1849
+ *
1850
+ * A holder that reports no session id claims nothing at all: it must not
1851
+ * count toward the holders, because one entry flipping to null while the
1852
+ * others still carry the session would otherwise wipe the identity they are
1853
+ * still rendering — and their effects never re-run to restore it.
1854
+ */
1855
+ let sessionScopeHolders = 0;
1856
+ function useViewedSession(props) {
1857
+ const id = typeof props.sessionId === "string" && props.sessionId !== "" ? props.sessionId : null;
1858
+ react.useEffect(() => {
1859
+ if (id === null) return;
1860
+ sessionScopeHolders++;
1861
+ if (S.sessionId !== id) {
1862
+ S.anchors.clear();
1863
+ S.seqAnchor.clear();
1864
+ setS({
1865
+ sessionId: id,
1866
+ turns: null,
1867
+ railPositions: [],
1868
+ railSig: "",
1869
+ railHover: null
1870
+ });
1871
+ fetchTurns(id);
1872
+ }
1873
+ return () => {
1874
+ sessionScopeHolders--;
1875
+ if (sessionScopeHolders === 0 && S.sessionId === id) {
1876
+ S.anchors.clear();
1877
+ S.seqAnchor.clear();
1878
+ setS({
1879
+ sessionId: null,
1880
+ turns: null,
1881
+ railPositions: [],
1882
+ railSig: "",
1883
+ railHover: null
1884
+ });
1885
+ }
1886
+ };
1887
+ }, [id]);
1888
+ }
1832
1889
  const ICONS = {
1833
1890
  sliders: [
1834
1891
  ["line", {
@@ -2482,8 +2539,20 @@ window.__ModuleLoader__.load({
2482
2539
  "hsla(352, 55%, 93%, 0.8)",
2483
2540
  "hsla(348, 40%, 88%, 0.8)"
2484
2541
  ];
2485
- const SAKURA_SPRITES = [];
2542
+ /** 浅色背景变体:90% 亮度的淡粉在近白的调色板背景上会消失,
2543
+ * 换成更深的玫瑰粉保持可辨识度。 */
2544
+ const SAKURA_PALETTE_LIGHT = [
2545
+ "hsla(340, 60%, 72%, 0.9)",
2546
+ "hsla(342, 64%, 70%, 0.9)",
2547
+ "hsla(344, 66%, 68%, 0.9)",
2548
+ "hsla(346, 68%, 66%, 0.9)",
2549
+ "hsla(348, 70%, 64%, 0.9)",
2550
+ "hsla(350, 66%, 66%, 0.9)",
2551
+ "hsla(352, 60%, 68%, 0.9)",
2552
+ "hsla(348, 52%, 70%, 0.9)"
2553
+ ];
2486
2554
  const SAKURA_IMAGES = [];
2555
+ const SAKURA_IMAGES_LIGHT = [];
2487
2556
  function rand(a, b) {
2488
2557
  return a + Math.random() * (b - a);
2489
2558
  }
@@ -2499,32 +2568,30 @@ window.__ModuleLoader__.load({
2499
2568
  g.closePath();
2500
2569
  g.restore();
2501
2570
  }
2502
- function buildSakuraSprites() {
2503
- if (SAKURA_SPRITES.length > 0) return;
2571
+ function buildSakuraSpriteSet(palette, target) {
2572
+ if (target.length > 0) return;
2504
2573
  const cvs = (typeof document !== "undefined" ? document : null)?.createElement("canvas");
2505
2574
  if (cvs === void 0 || cvs === null) return;
2506
2575
  cvs.width = 48;
2507
2576
  cvs.height = 48;
2508
2577
  const g = cvs.getContext("2d");
2509
2578
  if (g === null) return;
2510
- for (let i = 0; i < SAKURA_PALETTE.length; i++) {
2579
+ for (const color of palette) {
2511
2580
  g.clearRect(0, 0, 48, 48);
2512
- g.fillStyle = SAKURA_PALETTE[i];
2581
+ g.fillStyle = color;
2513
2582
  tracePetal(g, 24, 24, 10, 0);
2514
2583
  g.fill();
2515
2584
  try {
2516
- SAKURA_SPRITES.push(cvs.toDataURL());
2517
- } catch {
2518
- SAKURA_SPRITES.push(null);
2519
- }
2520
- }
2521
- for (const sprite of SAKURA_SPRITES) {
2522
- if (sprite === null) continue;
2523
- const image = new Image();
2524
- image.src = sprite;
2525
- SAKURA_IMAGES.push(image);
2585
+ const image = new Image();
2586
+ image.src = cvs.toDataURL();
2587
+ target.push(image);
2588
+ } catch {}
2526
2589
  }
2527
2590
  }
2591
+ function buildSakuraSprites() {
2592
+ buildSakuraSpriteSet(SAKURA_PALETTE, SAKURA_IMAGES);
2593
+ buildSakuraSpriteSet(SAKURA_PALETTE_LIGHT, SAKURA_IMAGES_LIGHT);
2594
+ }
2528
2595
  function initFx(weather, w, h) {
2529
2596
  FX.snow = [];
2530
2597
  FX.rain = [];
@@ -2661,7 +2728,7 @@ window.__ModuleLoader__.load({
2661
2728
  h: rand(.4, 1.1)
2662
2729
  });
2663
2730
  }
2664
- function fxFrame(g, cvs, weather, time) {
2731
+ function fxFrame(g, cvs, weather, time, light) {
2665
2732
  const w = cvs.clientWidth || 0;
2666
2733
  const h = cvs.clientHeight || 0;
2667
2734
  if (w === 0 || h === 0) return;
@@ -2682,10 +2749,10 @@ window.__ModuleLoader__.load({
2682
2749
  }
2683
2750
  if (f.x > w + f.radius) f.x = -f.radius;
2684
2751
  else if (f.x < -f.radius) f.x = w + f.radius;
2685
- const q = Math.round(f.opacity * 50) / 50;
2752
+ const q = Math.round((light ? Math.min(.9, f.opacity + .15) : f.opacity) * 50) / 50;
2686
2753
  if (q !== currentOpacity) {
2687
2754
  currentOpacity = q;
2688
- g.fillStyle = `rgba(255,255,255,${q})`;
2755
+ g.fillStyle = light ? `rgba(125,146,170,${q})` : `rgba(255,255,255,${q})`;
2689
2756
  }
2690
2757
  g.beginPath();
2691
2758
  g.arc(f.x, f.y, f.radius, 0, Math.PI * 2);
@@ -2708,10 +2775,10 @@ window.__ModuleLoader__.load({
2708
2775
  d.x = Math.random() * (w + 100) - 50;
2709
2776
  }
2710
2777
  if (d.x > w + 50) d.x = -50;
2711
- const qo = Math.round(d.opacity * 30) / 30;
2778
+ const qo = Math.round((light ? Math.min(.5, d.opacity + .08) : d.opacity) * 30) / 30;
2712
2779
  if (qo !== currentOpacity) {
2713
2780
  currentOpacity = qo;
2714
- g.strokeStyle = `rgba(180,200,220,${qo})`;
2781
+ g.strokeStyle = light ? `rgba(104,130,156,${qo})` : `rgba(180,200,220,${qo})`;
2715
2782
  }
2716
2783
  const qw = Math.round(d.lineWidth * 4) / 4;
2717
2784
  if (qw !== currentWidth) {
@@ -2735,48 +2802,60 @@ window.__ModuleLoader__.load({
2735
2802
  }
2736
2803
  g.save();
2737
2804
  g.globalAlpha = Math.max(0, sp.life);
2738
- g.strokeStyle = "rgba(180,200,220,0.8)";
2805
+ g.strokeStyle = light ? "rgba(104,130,156,0.8)" : "rgba(180,200,220,0.8)";
2739
2806
  g.lineWidth = .8;
2740
2807
  g.beginPath();
2741
2808
  g.ellipse(sp.x, sp.y, sp.w, sp.h, 0, 0, Math.PI * 2);
2742
2809
  g.stroke();
2743
2810
  g.restore();
2744
2811
  }
2745
- } else if (weather === "sakura") for (const f of FX.sakura) {
2746
- f.y += f.speedY;
2747
- f.x += Math.sin(f.phase + time * f.swayFreq) * f.drift;
2748
- if (f.y > h + f.size) {
2749
- f.y = -f.size;
2750
- f.x = Math.random() * w;
2751
- }
2752
- if (f.x > w + f.size) f.x = -f.size;
2753
- else if (f.x < -f.size) f.x = w + f.size;
2754
- const rot = Math.sin(f.phase + time * f.swayFreq * 1.7) * .9 + time * f.spin;
2755
- const wob = 1 + .12 * Math.sin(f.phase * 2 + time * f.swayFreq * 2.3);
2756
- if (f.spriteIndex >= 0 && SAKURA_IMAGES[f.spriteIndex] !== void 0) {
2757
- g.save();
2758
- g.globalAlpha = f.opacity;
2759
- g.translate(f.x, f.y);
2760
- g.rotate(rot);
2761
- g.scale(f.size * f.wobble * wob / 18, f.size * f.wobble / 18);
2762
- g.drawImage(SAKURA_IMAGES[f.spriteIndex], -18, -18, 36, 36);
2763
- g.restore();
2764
- } else {
2765
- g.save();
2766
- g.globalAlpha = f.opacity;
2767
- g.translate(f.x, f.y);
2768
- g.rotate(rot);
2769
- g.scale(f.size * f.wobble * wob / 10, f.size * f.wobble / 10);
2770
- g.fillStyle = SAKURA_PALETTE[0];
2771
- tracePetal(g, 0, 0, 1, 0);
2772
- g.fill();
2773
- g.restore();
2812
+ } else if (weather === "sakura") {
2813
+ const imgs = light ? SAKURA_IMAGES_LIGHT : SAKURA_IMAGES;
2814
+ const alpha = (f) => light ? Math.min(1, f.opacity + .2) : f.opacity;
2815
+ for (const f of FX.sakura) {
2816
+ f.y += f.speedY;
2817
+ f.x += Math.sin(f.phase + time * f.swayFreq) * f.drift;
2818
+ if (f.y > h + f.size) {
2819
+ f.y = -f.size;
2820
+ f.x = Math.random() * w;
2821
+ }
2822
+ if (f.x > w + f.size) f.x = -f.size;
2823
+ else if (f.x < -f.size) f.x = w + f.size;
2824
+ const rot = Math.sin(f.phase + time * f.swayFreq * 1.7) * .9 + time * f.spin;
2825
+ const wob = 1 + .12 * Math.sin(f.phase * 2 + time * f.swayFreq * 2.3);
2826
+ const img = f.spriteIndex >= 0 ? imgs[f.spriteIndex] : void 0;
2827
+ if (img !== void 0) {
2828
+ g.save();
2829
+ g.globalAlpha = alpha(f);
2830
+ g.translate(f.x, f.y);
2831
+ g.rotate(rot);
2832
+ g.scale(f.size * f.wobble * wob / 18, f.size * f.wobble / 18);
2833
+ g.drawImage(img, -18, -18, 36, 36);
2834
+ g.restore();
2835
+ } else {
2836
+ g.save();
2837
+ g.globalAlpha = alpha(f);
2838
+ g.translate(f.x, f.y);
2839
+ g.rotate(rot);
2840
+ g.scale(f.size * f.wobble * wob / 10, f.size * f.wobble / 10);
2841
+ g.fillStyle = light ? SAKURA_PALETTE_LIGHT[0] : SAKURA_PALETTE[0];
2842
+ tracePetal(g, 0, 0, 1, 0);
2843
+ g.fill();
2844
+ g.restore();
2845
+ }
2774
2846
  }
2775
2847
  }
2776
2848
  }
2777
2849
  function FxCanvas() {
2778
2850
  const s = useS();
2779
2851
  const ref = react.useRef(null);
2852
+ /** 粒子配色跟随背景亮度:浅色主题(以及任何主题下的高饱和极光)
2853
+ * 需要更深的粒子颜色才可辨识。ref 让 RAF 循环每帧读到最新值,
2854
+ * 主题/背景切换时无需重建粒子场。 */
2855
+ const lightRef = react.useRef(!(s.dark === true) || s.cfg.bg === "aurora");
2856
+ react.useEffect(() => {
2857
+ lightRef.current = !(s.dark === true) || s.cfg.bg === "aurora";
2858
+ }, [s.dark, s.cfg.bg]);
2780
2859
  react.useEffect(() => {
2781
2860
  const cvs = ref.current;
2782
2861
  if (cvs === null) return;
@@ -2796,7 +2875,7 @@ window.__ModuleLoader__.load({
2796
2875
  return;
2797
2876
  }
2798
2877
  raf = requestAnimationFrame(loop);
2799
- fxFrame(g, cvs, weather, Date.now() - t0);
2878
+ fxFrame(g, cvs, weather, Date.now() - t0, lightRef.current);
2800
2879
  };
2801
2880
  loop();
2802
2881
  return () => {
@@ -2813,11 +2892,13 @@ window.__ModuleLoader__.load({
2813
2892
  let lastRefetchAt = 0;
2814
2893
  let turnsRequestSerial = 0;
2815
2894
  let railRefetchRows = -1;
2816
- let lastDiagAt = 0;
2895
+ const diagAtByKey = /* @__PURE__ */ new Map();
2817
2896
  function diagThrottled(message) {
2897
+ const key = message.slice(0, 24);
2818
2898
  const now = Date.now();
2819
- if (now - lastDiagAt < 5e3) return;
2820
- lastDiagAt = now;
2899
+ const at = diagAtByKey.get(key);
2900
+ if (at !== void 0 && now - at < 5e3) return;
2901
+ diagAtByKey.set(key, now);
2821
2902
  reportDiag(message);
2822
2903
  }
2823
2904
  function scheduleTurnsRefetch() {
@@ -3036,20 +3117,24 @@ window.__ModuleLoader__.load({
3036
3117
  updateRailPositions();
3037
3118
  }
3038
3119
  async function forkAt(seq) {
3039
- const sessions = C.get("sessions");
3040
- if (sessions === void 0) return;
3120
+ const remote = sessionRemote();
3121
+ if (remote === void 0) {
3122
+ toast("分支不可用:会话 Remote 服务缺失", "error");
3123
+ return;
3124
+ }
3041
3125
  try {
3042
- const childId = await sessions.fork({
3126
+ const result = await remote.fork({
3043
3127
  sessionId: S.sessionId,
3044
3128
  atSeq: seq
3045
3129
  });
3130
+ if (!result.ok) {
3131
+ toast("创建分支失败: " + remoteErrorMessage(result.error, "未知错误"), "error");
3132
+ return;
3133
+ }
3134
+ const childId = result.value.sessionId;
3046
3135
  toast("分支会话已创建", "info", {
3047
3136
  label: "打开分支",
3048
- run: () => {
3049
- try {
3050
- sessions.open(childId);
3051
- } catch {}
3052
- }
3137
+ run: () => openSessionItem(childId)
3053
3138
  });
3054
3139
  } catch (error) {
3055
3140
  toast("创建分支失败: " + String(error?.message ?? error), "error");
@@ -3472,29 +3557,56 @@ window.__ModuleLoader__.load({
3472
3557
  for (const child of node.children ?? []) n += folderCount(child);
3473
3558
  return n;
3474
3559
  }
3560
+ /**
3561
+ * The `ctx.remote` namespaces this plugin calls, read fail-soft so a profile
3562
+ * without the Session Remote degrades to a toast instead of throwing.
3563
+ */
3564
+ function sessionRemote() {
3565
+ const session = C.get("remote")?.session;
3566
+ if (session === void 0) return void 0;
3567
+ if (typeof session.fork !== "function" || typeof session.search !== "function") return void 0;
3568
+ return session;
3569
+ }
3570
+ /** Render a Remote failure envelope as one readable line. */
3571
+ function remoteErrorMessage(error, fallback) {
3572
+ if (typeof error === "string") return error;
3573
+ if (error !== null && typeof error === "object") {
3574
+ const joined = [String(error.code ?? ""), String(error.message ?? "")].filter((part) => part !== "").join(": ");
3575
+ if (joined !== "") return joined;
3576
+ }
3577
+ return fallback;
3578
+ }
3579
+ /**
3580
+ * Navigation moved to the Workspace browser's `uiWorkspace` service: the
3581
+ * Session Controller no longer opens or selects a Session for a caller.
3582
+ */
3583
+ function workspaceNav() {
3584
+ const nav = C.get("uiWorkspace");
3585
+ if (nav === void 0 || typeof nav.openSession !== "function" || typeof nav.connectWorkspace !== "function") return void 0;
3586
+ return nav;
3587
+ }
3475
3588
  async function openWorkspaceItem(id) {
3476
- const workspaces = C.get("workspaces");
3477
- const sessions = C.get("sessions");
3478
- if (workspaces === void 0 || sessions === void 0) {
3479
- toast("工作区服务不可用", "error");
3589
+ const nav = workspaceNav();
3590
+ if (nav === void 0) {
3591
+ toast("工作区导航服务不可用", "error");
3480
3592
  return;
3481
3593
  }
3482
3594
  try {
3483
- const sid = await workspaces.connectWorkspace(id);
3484
- sessions.open(sid);
3595
+ const sid = await nav.connectWorkspace(id);
3596
+ nav.openSession(sid);
3485
3597
  toast("已打开项目", "info");
3486
3598
  } catch (error) {
3487
3599
  toast("打开项目失败: " + String(error?.message ?? error), "error");
3488
3600
  }
3489
3601
  }
3490
3602
  function openSessionItem(id) {
3491
- const sessions = C.get("sessions");
3492
- if (sessions === void 0) {
3493
- toast("会话服务不可用", "error");
3603
+ const nav = workspaceNav();
3604
+ if (nav === void 0) {
3605
+ toast("会话导航服务不可用", "error");
3494
3606
  return;
3495
3607
  }
3496
3608
  try {
3497
- sessions.open(id);
3609
+ nav.openSession(id);
3498
3610
  } catch (error) {
3499
3611
  toast("打开会话失败: " + String(error?.message ?? error), "error");
3500
3612
  }
@@ -3509,7 +3621,11 @@ window.__ModuleLoader__.load({
3509
3621
  }
3510
3622
  }), props.hint !== void 0 ? react.createElement("span", { className: "vx-muted" }, props.hint) : null);
3511
3623
  }
3512
- function FolderSidebarButton() {
3624
+ /** `sidebar.footer.action` hands the column state down. In the 56px rail the
3625
+ * two-character label wrapped into a vertical stack beside the icon, so the
3626
+ * text renders only while the sidebar is wide; a host that passes no `wide`
3627
+ * keeps the label. */
3628
+ function FolderSidebarButton(props) {
3513
3629
  return react.createElement("button", {
3514
3630
  className: "vx-foot-btn",
3515
3631
  title: "项目文件夹",
@@ -3520,9 +3636,10 @@ window.__ModuleLoader__.load({
3520
3636
  }, react.createElement(Icon, {
3521
3637
  n: "folder",
3522
3638
  size: 15
3523
- }), react.createElement("span", { className: "vx-foot-label" }, "项目"));
3639
+ }), props.wide === false ? null : react.createElement("span", { className: "vx-foot-label" }, "项目"));
3524
3640
  }
3525
- function HeaderPanelButton() {
3641
+ function HeaderPanelButton(props) {
3642
+ useViewedSession(props);
3526
3643
  return react.createElement("button", {
3527
3644
  className: "vx-header-btn",
3528
3645
  title: "个性化中心",
@@ -3535,7 +3652,8 @@ window.__ModuleLoader__.load({
3535
3652
  size: 13
3536
3653
  }), react.createElement("span", null, "个性化"));
3537
3654
  }
3538
- function PromptQuickButton() {
3655
+ function PromptQuickButton(props) {
3656
+ useViewedSession(props);
3539
3657
  return react.createElement("button", {
3540
3658
  className: "vx-header-btn",
3541
3659
  title: "快速调用提示词",
@@ -3588,7 +3706,8 @@ window.__ModuleLoader__.load({
3588
3706
  onClick: () => insertPrompt(x)
3589
3707
  }, react.createElement("div", { className: "vx-prompt-title" }, x.name), react.createElement("div", { className: "vx-prompt-body" }, x.text))) : react.createElement("div", { className: "vx-muted vx-pad-sm" }, "暂无匹配提示词")));
3590
3708
  }
3591
- function HeaderBalance() {
3709
+ function HeaderBalance(props) {
3710
+ useViewedSession(props);
3592
3711
  const s = useS();
3593
3712
  const b = s.balance;
3594
3713
  const [hover, setHover] = react.useState(false);
@@ -3785,6 +3904,7 @@ window.__ModuleLoader__.load({
3785
3904
  }), " 扫描今日会话日志更新用量"));
3786
3905
  }
3787
3906
  function QuoteDock(props) {
3907
+ useViewedSession(props);
3788
3908
  const s = useS();
3789
3909
  const inputRef = react.useRef(props.input);
3790
3910
  inputRef.current = props.input;
@@ -3879,7 +3999,8 @@ window.__ModuleLoader__.load({
3879
3999
  }), react.createElement("span", null, "引用回复"));
3880
4000
  }
3881
4001
  function TurnTailEntry(props) {
3882
- const seq = props.matched !== void 0 && props.matched !== null ? props.matched : typeof props.seq === "number" ? props.seq : null;
4002
+ useViewedSession(props);
4003
+ const seq = typeof props.seq === "number" ? props.seq : null;
3883
4004
  const turn = props.turn;
3884
4005
  const s = useS();
3885
4006
  let registered = null;
@@ -4004,33 +4125,8 @@ window.__ModuleLoader__.load({
4004
4125
  function TimelineRail(props) {
4005
4126
  const s = useS();
4006
4127
  const sessions = useSessionsSafe(props);
4007
- const current = sessions !== null ? sessions.current ?? null : null;
4008
- const summary = current !== null ? sessions.byId[current] : null;
4128
+ const summary = sessions !== null && s.sessionId !== null ? sessions.byId[s.sessionId] : null;
4009
4129
  const trackRef = react.useRef(null);
4010
- react.useEffect(() => {
4011
- if (current !== null && current !== S.sessionId) {
4012
- S.anchors.clear();
4013
- S.seqAnchor.clear();
4014
- setS({
4015
- sessionId: current,
4016
- turns: null,
4017
- railPositions: [],
4018
- railSig: "",
4019
- railHover: null
4020
- });
4021
- fetchTurns(String(current));
4022
- } else if (current === null && S.sessionId !== null) {
4023
- S.anchors.clear();
4024
- S.seqAnchor.clear();
4025
- setS({
4026
- sessionId: null,
4027
- turns: null,
4028
- railPositions: [],
4029
- railSig: "",
4030
- railHover: null
4031
- });
4032
- }
4033
- }, [current]);
4034
4130
  react.useEffect(() => {
4035
4131
  if (s.cfg.timeline !== true || S.sessionId === null) return;
4036
4132
  const running = summary?.running === true;
@@ -4040,7 +4136,7 @@ window.__ModuleLoader__.load({
4040
4136
  return () => clearInterval(handle);
4041
4137
  }, [
4042
4138
  s.cfg.timeline,
4043
- current,
4139
+ s.sessionId,
4044
4140
  summary?.running
4045
4141
  ]);
4046
4142
  react.useEffect(() => {
@@ -4826,11 +4922,13 @@ window.__ModuleLoader__.load({
4826
4922
  const [items, setItems] = react.useState([]);
4827
4923
  const [status, setStatus] = react.useState("");
4828
4924
  const [hasMore, setHasMore] = react.useState(false);
4925
+ const [scanned, setScanned] = react.useState(false);
4829
4926
  react.useEffect(() => {
4830
4927
  if (query.trim() === "" || S.sessionId === null) {
4831
4928
  setItems([]);
4832
4929
  setStatus("");
4833
4930
  setHasMore(false);
4931
+ setScanned(false);
4834
4932
  return;
4835
4933
  }
4836
4934
  const controller = new AbortController();
@@ -4845,6 +4943,7 @@ window.__ModuleLoader__.load({
4845
4943
  }
4846
4944
  setItems(result.items);
4847
4945
  setHasMore(result.hasMore);
4946
+ setScanned(result.source === "scan");
4848
4947
  setStatus(result.items.length === 0 ? "没有匹配结果" : "");
4849
4948
  });
4850
4949
  }, 250);
@@ -4863,7 +4962,7 @@ window.__ModuleLoader__.load({
4863
4962
  assistant: "助手",
4864
4963
  tool: "工具"
4865
4964
  };
4866
- return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-muted" }, "搜索当前会话的索引内容;结果只在本次请求中使用。"), react.createElement("input", {
4965
+ return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-muted" }, "搜索当前会话的消息与工具记录;结果只在本次请求中使用。"), scanned ? react.createElement("div", { className: "vx-muted" }, "本部署未开启 dsh 的事件全文索引,已改为直接扫描会话日志(结果按出现顺序,最多 100 条)。") : null, react.createElement("input", {
4867
4966
  className: "vx-input",
4868
4967
  autoFocus: true,
4869
4968
  placeholder: "输入搜索词…",
@@ -4893,7 +4992,7 @@ window.__ModuleLoader__.load({
4893
4992
  }
4894
4993
  function ExportTab() {
4895
4994
  const s = useS();
4896
- return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-muted" }, "将当前会话导出为文件:JSON 可导入其他工具,Markdown 便于阅读分享,PDF 内嵌图片(打印时另存为 PDF)。"), react.createElement("div", { className: "vx-row wrap" }, react.createElement("button", {
4995
+ return react.createElement("div", { className: "vx-col" }, react.createElement("div", { className: "vx-muted" }, "将当前会话导出为文件:JSON 可导入其他工具,Markdown 便于阅读分享,HTML 内嵌图片(导出 .html 文件,浏览器打开后打印即可另存为 PDF)。"), react.createElement("div", { className: "vx-row wrap" }, react.createElement("button", {
4897
4996
  className: "vx-btn big",
4898
4997
  disabled: s.exporting === true,
4899
4998
  onClick: () => runExport("json")
@@ -4914,7 +5013,7 @@ window.__ModuleLoader__.load({
4914
5013
  }, react.createElement(Icon, {
4915
5014
  n: "download",
4916
5015
  size: 14
4917
- }), " PDF(含图片)")), s.exporting === true ? react.createElement("div", { className: "vx-muted vx-pad-sm" }, "导出中…") : null, react.createElement(BackupControls, null));
5016
+ }), " HTML(含图片)")), s.exporting === true ? react.createElement("div", { className: "vx-muted vx-pad-sm" }, "导出中…") : null, react.createElement(BackupControls, null));
4918
5017
  }
4919
5018
  function MermaidTab() {
4920
5019
  const [engine, setEngine] = react.useState(mermaidState.status);
@@ -5269,34 +5368,32 @@ window.__ModuleLoader__.load({
5269
5368
  }
5270
5369
  const controller = new AbortController();
5271
5370
  const timer = setTimeout(() => {
5272
- const sessions = C.get("sessions");
5273
- if (sessions === void 0 || typeof sessions.search !== "function") {
5274
- setRemoteStatus("跨会话搜索不可用");
5371
+ const sessionSearch = sessionRemote();
5372
+ if (sessionSearch === void 0) {
5373
+ setRemoteStatus(CROSS_SEARCH_UNAVAILABLE);
5275
5374
  return;
5276
5375
  }
5277
5376
  setRemoteStatus("跨会话搜索中…");
5278
5377
  try {
5279
- sessions.search(query.trim(), controller.signal).then((result) => {
5378
+ sessionSearch.search({ query: query.trim() }, controller.signal).then((result) => {
5280
5379
  if (controller.signal.aborted) return;
5281
5380
  if (result.ok) {
5282
5381
  setRemote(result.value.items);
5283
5382
  setRemoteStatus("");
5284
5383
  } else {
5285
- const error = result.error;
5286
- const message = typeof error === "string" ? error : error !== null && typeof error === "object" ? [String(error.code ?? ""), String(error.message ?? "")].filter((part) => part !== "").join(": ") || "跨会话搜索不可用" : "跨会话搜索不可用";
5287
5384
  setRemote([]);
5288
- setRemoteStatus(message);
5385
+ setRemoteStatus(remoteErrorMessage(result.error, CROSS_SEARCH_UNAVAILABLE));
5289
5386
  }
5290
5387
  }).catch(() => {
5291
5388
  if (!controller.signal.aborted) {
5292
5389
  setRemote([]);
5293
- setRemoteStatus("跨会话搜索不可用");
5390
+ setRemoteStatus(CROSS_SEARCH_UNAVAILABLE);
5294
5391
  }
5295
5392
  });
5296
5393
  } catch {
5297
5394
  if (!controller.signal.aborted) {
5298
5395
  setRemote([]);
5299
- setRemoteStatus("跨会话搜索不可用");
5396
+ setRemoteStatus(CROSS_SEARCH_UNAVAILABLE);
5300
5397
  }
5301
5398
  }
5302
5399
  }, 250);
@@ -5959,23 +6056,30 @@ window.__ModuleLoader__.load({
5959
6056
  return () => {};
5960
6057
  }
5961
6058
  const unregisterAll = [];
6059
+ const injectedKeys = /* @__PURE__ */ new Set();
6060
+ let injectedCount = 0;
5962
6061
  const injectOne = (key, id, options, comp) => {
5963
6062
  try {
5964
6063
  slots.inject(key, () => {
5965
- const unregister = slots.register({
5966
- name: key,
5967
- ...options
5968
- }, comp);
5969
- unregisterAll.push(unregister);
5970
- return unregister;
6064
+ try {
6065
+ const unregister = slots.register({
6066
+ name: key,
6067
+ ...options
6068
+ }, comp);
6069
+ unregisterAll.push(unregister);
6070
+ return unregister;
6071
+ } catch (error) {
6072
+ reportDiag("register " + key + " (" + id + "): " + String(error?.message ?? error));
6073
+ return () => {};
6074
+ }
5971
6075
  });
5972
6076
  reportDiag("ok " + key + " (" + id + ")");
5973
- return true;
6077
+ injectedCount++;
6078
+ injectedKeys.add(key);
5974
6079
  } catch (error) {
5975
6080
  const message = "inject " + key + " (" + id + "): " + String(error?.message ?? error);
5976
6081
  console.error("[custom-plugin] " + message);
5977
6082
  reportDiag(message);
5978
- return false;
5979
6083
  }
5980
6084
  };
5981
6085
  injectOne("sidebar.footer.action", "custom-plugin-folders", {
@@ -5993,7 +6097,10 @@ window.__ModuleLoader__.load({
5993
6097
  order: 30,
5994
6098
  label: "引用回复"
5995
6099
  }, QuoteDock);
5996
- injectOne("conversation.chat.turnTail", "custom-plugin-turn-tail", { select: (o) => o !== null && typeof o.seq === "number" ? o.seq : null }, TurnTailEntry);
6100
+ injectOne("conversation.chat.turnTail", "custom-plugin-turn-tail", {
6101
+ id: "custom-plugin-turn-tail",
6102
+ order: 10
6103
+ }, TurnTailEntry);
5997
6104
  injectOne("settings.section", "custom-plugin-appearance", {
5998
6105
  id: "custom-plugin-appearance",
5999
6106
  order: 30,
@@ -6014,7 +6121,7 @@ window.__ModuleLoader__.load({
6014
6121
  order: -5,
6015
6122
  label: "额度"
6016
6123
  }, HeaderBalance);
6017
- reportDiag("client registered: 8 injections / 7 slots");
6124
+ reportDiag(`client installed: ${injectedCount} injection requests / ${injectedKeys.size} slots`);
6018
6125
  return () => {
6019
6126
  for (const unregister of unregisterAll.splice(0)) try {
6020
6127
  unregister();