@michengai/dsh-codex-ui 2.0.11 → 2.0.13

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
@@ -69,13 +69,18 @@ window.__ModuleLoader__.load({
69
69
  //#endregion
70
70
  //#region src/business-api.ts
71
71
  const CODEX_UI_API_BASE = "/api/michengai/dsh-codex-ui";
72
+ /** 请求重启时携带一次性令牌的请求头(客户端与 Host 共用)。 */
73
+ const CODEX_UI_RESTART_HEADER = "x-dcu-restart-key";
72
74
  const CODEX_UI_API_ENDPOINTS = Object.freeze({
73
75
  dependencies: `${CODEX_UI_API_BASE}/dependencies`,
74
76
  settingsSkin: `${CODEX_UI_API_BASE}/settings-skin`,
75
77
  composer: `${CODEX_UI_API_BASE}/composer`,
78
+ composerPrediction: `${CODEX_UI_API_BASE}/composer/prediction`,
79
+ composerPredictionStream: `${CODEX_UI_API_BASE}/composer/prediction/stream`,
76
80
  sidebar: `${CODEX_UI_API_BASE}/sidebar`,
77
81
  sections: `${CODEX_UI_API_BASE}/sections`,
78
- theme: `${CODEX_UI_API_BASE}/theme`
82
+ theme: `${CODEX_UI_API_BASE}/theme`,
83
+ desktopMenu: `${CODEX_UI_API_BASE}/desktop-menu`
79
84
  });
80
85
  //#endregion
81
86
  //#region src/dependencies.ts
@@ -2575,6 +2580,11 @@ html[data-dsh-glass] body:not([data-ds-dark-theme]) .dcu-section-card {
2575
2580
  nameKey: "about.feature.theme.name",
2576
2581
  descKey: "about.feature.theme"
2577
2582
  },
2583
+ {
2584
+ id: "desktop-menu",
2585
+ nameKey: "about.feature.desktopMenu.name",
2586
+ descKey: "about.feature.desktopMenu"
2587
+ },
2578
2588
  {
2579
2589
  id: "dependencies",
2580
2590
  nameKey: "about.feature.dependencies.name",
@@ -3097,6 +3107,9 @@ html[data-dsh-glass] body:not([data-ds-dark-theme]) .dcu-section-card{background
3097
3107
  "settings.records": "记录与应用",
3098
3108
  "settings.noResults": "没有匹配的设置分类",
3099
3109
  "input.historyHint": "↑↓ 翻历史",
3110
+ "input.prediction.tab": "Tab 采纳",
3111
+ "input.prediction.more": "Alt+↓ 切换",
3112
+ "input.prediction.dismiss": "Esc 忽略",
3100
3113
  "about.nav": "Codex UI",
3101
3114
  "sections.pinned": "置顶",
3102
3115
  "sections.default": "项目",
@@ -3115,7 +3128,7 @@ html[data-dsh-glass] body:not([data-ds-dark-theme]) .dcu-section-card{background
3115
3128
  "about.feedback": "问题反馈",
3116
3129
  "about.checkUpdate": "检查更新",
3117
3130
  "about.checking": "正在检查更新…",
3118
- "about.description": "输入框增强、全屏设置工作台美化与生态插件管理。",
3131
+ "about.description": "输入框增强、全屏设置工作台美化、桌面窗口菜单与生态插件管理。",
3119
3132
  "about.features": "包含子插件与功能",
3120
3133
  "about.feature.composer.name": "输入框增强 (Composer)",
3121
3134
  "about.feature.composer": "终端风格输入历史(↑/↓)快捷召回、自适应宽度调节与会话建议卡片",
@@ -3129,6 +3142,23 @@ html[data-dsh-glass] body:not([data-ds-dark-theme]) .dcu-section-card{background
3129
3142
  "about.feature.theme": "内置 Codex 经典黑白与 Catppuccin 色盘,支持悬浮云母磨砂质感",
3130
3143
  "about.feature.dependencies.name": "配套生态管理 (Dependencies)",
3131
3144
  "about.feature.dependencies": "深度集成 DSH 官方与第三方生态插件集中管理与一键批量更新",
3145
+ "about.feature.desktopMenu.name": "桌面窗口菜单 (Desktop Menus)",
3146
+ "about.feature.desktopMenu": "在系统原生菜单栏追加帮助入口,并提供页面刷新与重启",
3147
+ "desktopMenu.help": "帮助",
3148
+ "desktopMenu.help.reloadPage": "刷新页面",
3149
+ "desktopMenu.help.restartAppHost": "重启应用与 Host",
3150
+ "desktopMenu.help.restartConfirm": "将退出并重新打开 DeepSeek Harness,正在运行的任务会被中断。继续?",
3151
+ "desktopMenu.restart.quitting": "正在退出并重新打开 DeepSeek Harness…",
3152
+ "desktopMenu.restart.relaunched": "已重新启动。",
3153
+ "desktopMenu.restart.cancelled": "应用没有退出,本次重启已取消。",
3154
+ "desktopMenu.restart.launchFailed": "应用已退出,但没能自动重新打开,请手动启动。",
3155
+ "desktopMenu.restart.timeout": "没有在预期时间内完成重启,请确认应用是否还在。",
3156
+ "desktopMenu.restart.busy": "已有重启正在进行中,请稍候。",
3157
+ "desktopMenu.restart.failed": "重启失败",
3158
+ "desktopMenu.restart.unreachable": "连不上宿主,重启通道不可用。",
3159
+ "desktopMenu.restart.unsupportedDesktopOnly": "当前不是桌面版,无法重启应用。",
3160
+ "desktopMenu.restart.unsupportedMissingApp": "找不到 DeepSeek Harness 的可执行文件,无法重启。",
3161
+ "desktopMenu.restart.close": "关闭",
3132
3162
  "about.dependencies": "配套管理插件",
3133
3163
  "about.dependenciesDescription": "每个配套插件均支持独立按需安装与一键批量同步升级。",
3134
3164
  "about.loading": "正在读取依赖安装状态…",
@@ -3266,6 +3296,9 @@ html[data-dsh-glass] body:not([data-ds-dark-theme]) .dcu-section-card{background
3266
3296
  "settings.records": "Records and app",
3267
3297
  "settings.noResults": "No matching settings categories",
3268
3298
  "input.historyHint": "↑↓ History",
3299
+ "input.prediction.tab": "Tab accept",
3300
+ "input.prediction.more": "Alt+↓ cycle",
3301
+ "input.prediction.dismiss": "Esc dismiss",
3269
3302
  "about.nav": "Codex UI",
3270
3303
  "sections.pinned": "Pinned",
3271
3304
  "sections.default": "Projects",
@@ -3284,7 +3317,7 @@ html[data-dsh-glass] body:not([data-ds-dark-theme]) .dcu-section-card{background
3284
3317
  "about.feedback": "Issues",
3285
3318
  "about.checkUpdate": "Check for updates",
3286
3319
  "about.checking": "Checking…",
3287
- "about.description": "Input enhancement, fullscreen settings workbench skin, and ecosystem plugin management.",
3320
+ "about.description": "Input enhancement, fullscreen settings workbench skin, desktop titlebar menu, and ecosystem plugin management.",
3288
3321
  "about.features": "Built-in Sub-plugins & Capabilities",
3289
3322
  "about.feature.composer.name": "Composer Enhancements",
3290
3323
  "about.feature.composer": "Terminal-style input history (↑/↓), adaptive width resizing, and starter suggestions",
@@ -3298,6 +3331,23 @@ html[data-dsh-glass] body:not([data-ds-dark-theme]) .dcu-section-card{background
3298
3331
  "about.feature.theme": "Built-in Codex dark/light & Catppuccin palettes with floating mica glassmorphism",
3299
3332
  "about.feature.dependencies.name": "Companion Dependencies",
3300
3333
  "about.feature.dependencies": "Integrated management, live healthcheck, and one-click updates for DSH plugins",
3334
+ "about.feature.desktopMenu.name": "Desktop Window Menus",
3335
+ "about.feature.desktopMenu": "Adds a Help entry to the native menubar with page reload and restart",
3336
+ "desktopMenu.help": "Help",
3337
+ "desktopMenu.help.reloadPage": "Reload Page",
3338
+ "desktopMenu.help.restartAppHost": "Restart App and Host",
3339
+ "desktopMenu.help.restartConfirm": "DeepSeek Harness will close and reopen; running tasks will be interrupted. Continue?",
3340
+ "desktopMenu.restart.quitting": "Closing and reopening DeepSeek Harness…",
3341
+ "desktopMenu.restart.relaunched": "Restarted.",
3342
+ "desktopMenu.restart.cancelled": "The app did not exit; this restart was cancelled.",
3343
+ "desktopMenu.restart.launchFailed": "The app exited but could not be reopened automatically.",
3344
+ "desktopMenu.restart.timeout": "The restart did not finish in time; please check the app.",
3345
+ "desktopMenu.restart.busy": "A restart is already in progress. Please wait.",
3346
+ "desktopMenu.restart.failed": "Restart failed",
3347
+ "desktopMenu.restart.unreachable": "Cannot reach the Host; the restart channel is unavailable.",
3348
+ "desktopMenu.restart.unsupportedDesktopOnly": "This is not the desktop app, so it cannot be restarted.",
3349
+ "desktopMenu.restart.unsupportedMissingApp": "Cannot locate the DeepSeek Harness executable, so it cannot be restarted.",
3350
+ "desktopMenu.restart.close": "Close",
3301
3351
  "about.dependencies": "Companion management plugins",
3302
3352
  "about.dependenciesDescription": "Install or update each companion plugin individually, or synchronize all versions in one click.",
3303
3353
  "about.loading": "Loading dependency status…",
@@ -5757,7 +5807,7 @@ html[data-dsh-glass-float] [data-shortcut-modal="settings"][data-sidebar-collaps
5757
5807
  */
5758
5808
  const CODEX_UI_NAV_MARKER = "data-dcu-nav-icon";
5759
5809
  const NAV_ROW_SELECTOR = "[role=\"dialog\"] nav button, [data-shortcut-modal=\"settings\"] nav button";
5760
- const STYLE_ID$1 = "dcu-settings-nav-icon-style";
5810
+ const STYLE_ID$3 = "dcu-settings-nav-icon-style";
5761
5811
  const ICON_MASK_URL = `url("data:image/svg+xml,${encodeURIComponent("<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 16\"><rect x=\"1.5\" y=\"2\" width=\"13\" height=\"12\" rx=\"2\" stroke=\"black\" stroke-width=\"1.3\" fill=\"none\"/><line x1=\"5.5\" y1=\"2\" x2=\"5.5\" y2=\"14\" stroke=\"black\" stroke-width=\"1.3\"/><line x1=\"5.5\" y1=\"5.5\" x2=\"14.5\" y2=\"5.5\" stroke=\"black\" stroke-width=\"1.3\"/></svg>")}")`;
5762
5812
  const NAV_ICON_CSS = `
5763
5813
  [${CODEX_UI_NAV_MARKER}="codex-ui"] > svg { display: none !important; }
@@ -5778,9 +5828,9 @@ html[data-dsh-glass-float] [data-shortcut-modal="settings"][data-sidebar-collaps
5778
5828
  }
5779
5829
  `;
5780
5830
  function ensureStyle(doc) {
5781
- if (doc.getElementById(STYLE_ID$1) !== null) return;
5831
+ if (doc.getElementById(STYLE_ID$3) !== null) return;
5782
5832
  const style = doc.createElement("style");
5783
- style.id = STYLE_ID$1;
5833
+ style.id = STYLE_ID$3;
5784
5834
  style.textContent = NAV_ICON_CSS;
5785
5835
  (doc.head ?? doc.documentElement).appendChild(style);
5786
5836
  }
@@ -5828,7 +5878,7 @@ html[data-dsh-glass-float] [data-shortcut-modal="settings"][data-sidebar-collaps
5828
5878
  doc.querySelectorAll(`[${CODEX_UI_NAV_MARKER}="codex-ui"]`).forEach((btn) => {
5829
5879
  btn.removeAttribute(CODEX_UI_NAV_MARKER);
5830
5880
  });
5831
- doc.getElementById(STYLE_ID$1)?.remove();
5881
+ doc.getElementById(STYLE_ID$3)?.remove();
5832
5882
  };
5833
5883
  }
5834
5884
  //#endregion
@@ -6374,6 +6424,686 @@ html[data-dsh-glass-float] [data-shortcut-modal="settings"][data-sidebar-collaps
6374
6424
  });
6375
6425
  }
6376
6426
  //#endregion
6427
+ //#region src/client/composer/ComposerPredictionOverlay.tsx
6428
+ /**
6429
+ * Browser half of composer predictions (1:1 完整无损移植自 dsh-composer-predictions 1.2.8 原版源码)
6430
+ * 具备经真机验证的局部坐标测量、ResizeObserver / selectionchange 监听、流式 SSE 消费器与 Tab/Alt 按键拦截
6431
+ */
6432
+ const h = react.default.createElement;
6433
+ const ENDPOINT = CODEX_UI_API_ENDPOINTS.composerPredictionStream;
6434
+ /** Wait for the settled UI before asking, so a fresh turn is fully committed. */
6435
+ const SETTLE_MS = 600;
6436
+ /** Wait for a typing pause before asking for a continuation. */
6437
+ const TYPE_PAUSE_MS = 500;
6438
+ /** A continuation needs enough text to continue from. */
6439
+ const CONTINUE_MIN_CHARS = 3;
6440
+ /** Ignore the first characters of a streaming answer to avoid flicker. */
6441
+ const STREAM_MIN_CHARS = 3;
6442
+ /** Editor text insets from the resident composer styles. */
6443
+ const EDITOR_INSET_TOP = 4;
6444
+ const EDITOR_INSET_LEFT = 14;
6445
+ const EDITOR_INSET_RIGHT = 8;
6446
+ /** The editable scroll container's right margin, outside the text column. */
6447
+ const EDITOR_SCROLL_MARGIN = 4;
6448
+ const FALLBACK_LINE_HEIGHT = 24;
6449
+ const NO_GHOST = {
6450
+ mode: "next",
6451
+ items: [],
6452
+ index: 0,
6453
+ stream: "",
6454
+ active: false
6455
+ };
6456
+ const NEXT_GHOST_STYLE = {
6457
+ position: "absolute",
6458
+ display: "flex",
6459
+ alignItems: "center",
6460
+ gap: "8px",
6461
+ boxSizing: "border-box",
6462
+ fontFamily: "inherit",
6463
+ fontSize: "inherit",
6464
+ lineHeight: "inherit",
6465
+ color: "var(--dsw-alias-label-caption)",
6466
+ background: "var(--dsw-specific-input-major)",
6467
+ overflow: "hidden",
6468
+ whiteSpace: "nowrap",
6469
+ pointerEvents: "none",
6470
+ userSelect: "none",
6471
+ zIndex: 2
6472
+ };
6473
+ /** The continuation ghost hugs its text and sits where the caret is. */
6474
+ const CONTINUE_GHOST_STYLE = {
6475
+ ...NEXT_GHOST_STYLE,
6476
+ gap: "6px",
6477
+ padding: "0 4px",
6478
+ borderRadius: "4px",
6479
+ zIndex: 3
6480
+ };
6481
+ const TEXT_STYLE = {
6482
+ flex: "1 1 auto",
6483
+ minWidth: 0,
6484
+ overflow: "hidden",
6485
+ textOverflow: "ellipsis",
6486
+ whiteSpace: "nowrap",
6487
+ opacity: .9
6488
+ };
6489
+ const CONTINUE_TEXT_STYLE = {
6490
+ ...TEXT_STYLE,
6491
+ flex: "0 1 auto"
6492
+ };
6493
+ const KEYCAP_STYLE = {
6494
+ flex: "none",
6495
+ fontSize: "11px",
6496
+ lineHeight: "16px",
6497
+ padding: "0 5px",
6498
+ borderRadius: "4px",
6499
+ border: "1px solid var(--dsw-alias-border-l2)",
6500
+ color: "var(--dsw-alias-label-tertiary)",
6501
+ background: "transparent"
6502
+ };
6503
+ const BADGE_STYLE = {
6504
+ flex: "none",
6505
+ fontSize: "10px",
6506
+ lineHeight: "14px",
6507
+ color: "var(--dsw-alias-label-tertiary)",
6508
+ opacity: .8
6509
+ };
6510
+ /**
6511
+ * Locate the composer card this overlay actually belongs to.
6512
+ *
6513
+ * The seat is rendered inside the resident composer card, so the anchor node
6514
+ * is an ancestor-scoped key: a global `querySelector` would pick whichever
6515
+ * card happens to be first in the document and paint that conversation's
6516
+ * ghost over another one.
6517
+ */
6518
+ function composerElementsNear(anchor) {
6519
+ if (typeof document === "undefined") return null;
6520
+ if (anchor === null || anchor === void 0 || !anchor.isConnected) return null;
6521
+ const card = anchor.closest("[data-composer-card]");
6522
+ if (card === null) return null;
6523
+ const editor = card.querySelector("[contenteditable=\"true\"]") || card.querySelector("[role=\"textbox\"]");
6524
+ return editor === null ? null : {
6525
+ card,
6526
+ editor
6527
+ };
6528
+ }
6529
+ /** The collapsed selection inside the editor, when it is there at all. */
6530
+ function readCaret(editor) {
6531
+ if (typeof window === "undefined" || typeof document === "undefined") return null;
6532
+ const selection = window.getSelection();
6533
+ if (selection === null || selection.rangeCount === 0) return null;
6534
+ const range = selection.getRangeAt(0);
6535
+ if (range === null || !range.collapsed) return null;
6536
+ if (!editor.contains(range.startContainer)) return null;
6537
+ const prefixRange = document.createRange();
6538
+ prefixRange.selectNodeContents(editor);
6539
+ prefixRange.setEnd(range.startContainer, range.startOffset);
6540
+ const prefix = prefixRange.toString();
6541
+ const rect = caretRect(range);
6542
+ if (rect === null) return null;
6543
+ return {
6544
+ prefix,
6545
+ left: rect.left,
6546
+ top: rect.top,
6547
+ height: rect.height
6548
+ };
6549
+ }
6550
+ function caretRect(range) {
6551
+ let rect = range.getBoundingClientRect();
6552
+ if (rect.width === 0 && rect.height === 0) {
6553
+ const rects = range.getClientRects();
6554
+ if (rects.length > 0) rect = rects[0];
6555
+ }
6556
+ if (rect.width === 0 && rect.height === 0 || rect.top === 0 && rect.left === 0) {
6557
+ const fallback = rectBeforeCaret(range);
6558
+ if (fallback !== null) return fallback;
6559
+ }
6560
+ if (rect.width === 0 && rect.height === 0) return null;
6561
+ return {
6562
+ left: rect.left,
6563
+ top: rect.top,
6564
+ height: rect.height
6565
+ };
6566
+ }
6567
+ /** Measure the character before the caret when the collapsed range is empty. */
6568
+ function rectBeforeCaret(range) {
6569
+ const node = range.startContainer;
6570
+ const offset = range.startOffset;
6571
+ if (typeof Node === "undefined" || node === null || node.nodeType !== Node.TEXT_NODE || offset <= 0) return null;
6572
+ const probe = document.createRange();
6573
+ probe.setStart(node, offset - 1);
6574
+ probe.setEnd(node, offset);
6575
+ const rect = probe.getBoundingClientRect();
6576
+ if (rect.width === 0 && rect.height === 0) return null;
6577
+ return {
6578
+ left: rect.right,
6579
+ top: rect.top,
6580
+ height: rect.height
6581
+ };
6582
+ }
6583
+ /** Whether the caret is at the effective end of the draft. */
6584
+ function caretAtEnd(editor, draft) {
6585
+ const caret = readCaret(editor);
6586
+ if (caret === null) return null;
6587
+ const draftText = collapse(draft.trimEnd());
6588
+ const prefix = collapse(caret.prefix.trimEnd());
6589
+ if (prefix === "") return null;
6590
+ return draftText === prefix ? caret : null;
6591
+ }
6592
+ function collapse(text) {
6593
+ return text.replace(/\s+/gu, " ").trim();
6594
+ }
6595
+ /** A half-typed `/command` or `@reference` is not a message continuation. */
6596
+ function isTriggerToken(draft) {
6597
+ return /(?:^|\s)\/[^\s]*$/u.test(draft) || /(?:^|\s)@"?[^\s]*$/u.test(draft);
6598
+ }
6599
+ /** Show the model's first line while it is still streaming. */
6600
+ function streamingCandidate(stream) {
6601
+ if (stream.trim().length < STREAM_MIN_CHARS) return "";
6602
+ for (const raw of stream.split(/\r?\n/u)) {
6603
+ let line = raw.trim();
6604
+ if (line === "") continue;
6605
+ if (/^none$/iu.test(line)) return "";
6606
+ line = cleanLine(line);
6607
+ if (line === "") continue;
6608
+ return line.length > 240 ? line.slice(0, 240) : line;
6609
+ }
6610
+ return "";
6611
+ }
6612
+ function cleanLine(line) {
6613
+ return line.replace(/^(?:[-*•]|\d+[.)])\s+/u, "").replace(/^["'`\u201c\u201d]+|["'`\u201c\u201d]+$/gu, "").replace(/\s+/gu, " ").trim();
6614
+ }
6615
+ /**
6616
+ * Join a continuation onto the draft without gluing words together.
6617
+ * Avoid repeating a separator already present in the exact draft.
6618
+ */
6619
+ function joinContinuation(draft, value) {
6620
+ if (draft === "" || value === "") return value;
6621
+ if (/\s$/u.test(draft)) return value.replace(/^\s+/u, "");
6622
+ if (/^\s/u.test(value)) return value;
6623
+ const last = draft.slice(-1);
6624
+ const first = value.slice(0, 1);
6625
+ if (isCjk(last) || isCjk(first)) return value;
6626
+ if (/[([{/\-—"'`]$/u.test(last)) return value;
6627
+ if (/^[,.;:!?)\]}%]/u.test(first)) return value;
6628
+ return ` ${value}`;
6629
+ }
6630
+ function isCjk(character) {
6631
+ return /[\u3040-\u30ff\u3400-\u9fff\uac00-\ud7af]/u.test(character);
6632
+ }
6633
+ function sameBox(left, right) {
6634
+ return left !== null && left !== void 0 && left.top === right.top && left.left === right.left && left.height === right.height && left.right === right.right && left.maxWidth === right.maxWidth;
6635
+ }
6636
+ /** Parse a fully buffered SSE body, for shells that cannot stream fetch bodies. */
6637
+ function parseSseText(text) {
6638
+ const events = [];
6639
+ for (const frame of text.split("\n\n")) for (const line of frame.split("\n")) {
6640
+ if (!line.startsWith("data:")) continue;
6641
+ const payload = line.slice(5).trim();
6642
+ if (payload === "") continue;
6643
+ try {
6644
+ events.push(JSON.parse(payload));
6645
+ } catch {}
6646
+ }
6647
+ return events;
6648
+ }
6649
+ /** Read one SSE body and hand every `data:` payload to the callback. */
6650
+ async function consumeStream(body, signal, onEvent) {
6651
+ const reader = body.getReader();
6652
+ const decoder = new TextDecoder();
6653
+ let buffer = "";
6654
+ let terminal = false;
6655
+ try {
6656
+ for (;;) {
6657
+ const { done, value } = await reader.read();
6658
+ if (done) break;
6659
+ if (signal.aborted) break;
6660
+ buffer += decoder.decode(value, { stream: true });
6661
+ let boundary = buffer.indexOf("\n\n");
6662
+ while (boundary >= 0) {
6663
+ const frame = buffer.slice(0, boundary);
6664
+ buffer = buffer.slice(boundary + 2);
6665
+ for (const line of frame.split("\n")) {
6666
+ if (!line.startsWith("data:")) continue;
6667
+ const payload = line.slice(5).trim();
6668
+ if (payload === "") continue;
6669
+ try {
6670
+ const event = JSON.parse(payload);
6671
+ if (event.type === "done" || event.type === "error") terminal = true;
6672
+ onEvent(event);
6673
+ } catch {}
6674
+ }
6675
+ boundary = buffer.indexOf("\n\n");
6676
+ }
6677
+ }
6678
+ return terminal;
6679
+ } finally {
6680
+ if (signal.aborted) try {
6681
+ await reader.cancel();
6682
+ } catch {}
6683
+ reader.releaseLock();
6684
+ }
6685
+ }
6686
+ function ComposerPredictionOverlay(props) {
6687
+ const { sessionId, useSession, useInput, inputActions, enabled = true, t } = props;
6688
+ const predictionsEnabled = enabled !== false;
6689
+ const draft = useInput ? useInput((state) => state === void 0 ? "" : state.draft || "") : "";
6690
+ const running = useSession ? useSession((state) => state?.running === true) : false;
6691
+ const [ghost, setGhost] = react.default.useState(NO_GHOST);
6692
+ const [box, setBox] = react.default.useState(null);
6693
+ const [compositionEnd, setCompositionEnd] = react.default.useState(0);
6694
+ const anchorRef = react.default.useRef(null);
6695
+ const elements = () => composerElementsNear(anchorRef.current);
6696
+ const abortRef = react.default.useRef(null);
6697
+ const composingRef = react.default.useRef(false);
6698
+ const dismissedRef = react.default.useRef(null);
6699
+ const acceptRef = react.default.useRef(null);
6700
+ const cycleRef = react.default.useRef(null);
6701
+ const currentRef = react.default.useRef("");
6702
+ const request = react.default.useCallback(async (mode, draftText) => {
6703
+ if (sessionId === void 0 || sessionId === null) return;
6704
+ if (typeof document !== "undefined" && document.hidden) return;
6705
+ abortRef.current?.abort();
6706
+ const controller = new AbortController();
6707
+ abortRef.current = controller;
6708
+ setGhost({
6709
+ mode,
6710
+ items: [],
6711
+ index: 0,
6712
+ stream: "",
6713
+ active: true
6714
+ });
6715
+ const settle = (items) => {
6716
+ if (controller.signal.aborted) return;
6717
+ setGhost((previous) => {
6718
+ if (previous.mode !== mode) return previous;
6719
+ if (items.length === 0) return NO_GHOST;
6720
+ return {
6721
+ mode,
6722
+ items,
6723
+ index: 0,
6724
+ stream: "",
6725
+ active: false
6726
+ };
6727
+ });
6728
+ };
6729
+ try {
6730
+ const response = await fetch(ENDPOINT, {
6731
+ method: "POST",
6732
+ headers: {
6733
+ "content-type": "application/json",
6734
+ accept: "text/event-stream"
6735
+ },
6736
+ body: JSON.stringify({
6737
+ sessionId,
6738
+ mode,
6739
+ draft: draftText
6740
+ }),
6741
+ signal: controller.signal
6742
+ });
6743
+ if (!response.ok || controller.signal.aborted) {
6744
+ settle([]);
6745
+ return;
6746
+ }
6747
+ if (!(response.headers.get("content-type") || "").includes("text/event-stream")) {
6748
+ const payload = await response.json().catch(() => null);
6749
+ settle(Array.isArray(payload?.suggestions) ? payload.suggestions.filter((item) => typeof item === "string" && item !== "") : typeof payload?.suggestion === "string" && payload.suggestion !== "" ? [payload.suggestion] : []);
6750
+ return;
6751
+ }
6752
+ if (response.body === null) {
6753
+ const done = parseSseText(await response.text().catch(() => "")).find((event) => event.type === "done");
6754
+ settle(Array.isArray(done?.items) ? done.items.filter((item) => typeof item === "string" && item !== "") : []);
6755
+ return;
6756
+ }
6757
+ if (!await consumeStream(response.body, controller.signal, (event) => {
6758
+ if (controller.signal.aborted) return;
6759
+ if (event.type === "delta" && typeof event.text === "string") setGhost((previous) => previous.active && previous.mode === mode ? {
6760
+ ...previous,
6761
+ stream: previous.stream + event.text
6762
+ } : previous);
6763
+ else if (event.type === "done") {
6764
+ const items = Array.isArray(event.items) ? event.items.filter((item) => typeof item === "string" && item !== "") : [];
6765
+ settle(items);
6766
+ } else if (event.type === "error") settle([]);
6767
+ })) settle([]);
6768
+ } catch {
6769
+ if (!controller.signal.aborted) settle([]);
6770
+ }
6771
+ }, [sessionId]);
6772
+ react.default.useEffect(() => {
6773
+ if (predictionsEnabled) return;
6774
+ abortRef.current?.abort();
6775
+ setGhost(NO_GHOST);
6776
+ setBox(null);
6777
+ }, [predictionsEnabled]);
6778
+ react.default.useEffect(() => {
6779
+ const onCompositionStart = () => {
6780
+ composingRef.current = true;
6781
+ abortRef.current?.abort();
6782
+ setGhost(NO_GHOST);
6783
+ setBox(null);
6784
+ };
6785
+ const onCompositionEnd = () => {
6786
+ composingRef.current = false;
6787
+ setCompositionEnd((value) => value + 1);
6788
+ };
6789
+ document.addEventListener("compositionstart", onCompositionStart, true);
6790
+ document.addEventListener("compositionend", onCompositionEnd, true);
6791
+ return () => {
6792
+ document.removeEventListener("compositionstart", onCompositionStart, true);
6793
+ document.removeEventListener("compositionend", onCompositionEnd, true);
6794
+ };
6795
+ }, []);
6796
+ react.default.useEffect(() => {
6797
+ dismissedRef.current = null;
6798
+ abortRef.current?.abort();
6799
+ setGhost(NO_GHOST);
6800
+ setBox(null);
6801
+ return () => abortRef.current?.abort();
6802
+ }, [sessionId]);
6803
+ react.default.useEffect(() => {
6804
+ abortRef.current?.abort();
6805
+ setGhost(NO_GHOST);
6806
+ if (dismissedRef.current !== null && dismissedRef.current.draft !== draft) dismissedRef.current = null;
6807
+ }, [draft]);
6808
+ react.default.useEffect(() => {
6809
+ if (!running) return;
6810
+ abortRef.current?.abort();
6811
+ setGhost(NO_GHOST);
6812
+ dismissedRef.current = null;
6813
+ }, [running]);
6814
+ react.default.useEffect(() => {
6815
+ if (sessionId === void 0 || sessionId === null) return void 0;
6816
+ if (!predictionsEnabled || running || draft !== "") return void 0;
6817
+ if (dismissedRef.current !== null && dismissedRef.current.draft === draft) return void 0;
6818
+ const timer = setTimeout(() => {
6819
+ if (composingRef.current) return;
6820
+ request("next", "");
6821
+ }, SETTLE_MS);
6822
+ return () => clearTimeout(timer);
6823
+ }, [
6824
+ sessionId,
6825
+ running,
6826
+ draft,
6827
+ request,
6828
+ predictionsEnabled,
6829
+ compositionEnd
6830
+ ]);
6831
+ react.default.useEffect(() => {
6832
+ if (sessionId === void 0 || sessionId === null) return void 0;
6833
+ if (!predictionsEnabled || draft.trim() === "" || draft.length < CONTINUE_MIN_CHARS) return void 0;
6834
+ if (isTriggerToken(draft)) return void 0;
6835
+ if (dismissedRef.current !== null && dismissedRef.current.draft === draft) return void 0;
6836
+ const timer = setTimeout(() => {
6837
+ if (composingRef.current) return;
6838
+ const found = elements();
6839
+ if (found === null) return;
6840
+ if (caretAtEnd(found.editor, draft) === null) return;
6841
+ request("continue", draft.slice(-4e3));
6842
+ }, TYPE_PAUSE_MS);
6843
+ return () => clearTimeout(timer);
6844
+ }, [
6845
+ sessionId,
6846
+ draft,
6847
+ request,
6848
+ predictionsEnabled,
6849
+ compositionEnd
6850
+ ]);
6851
+ react.default.useEffect(() => {
6852
+ const onVisibility = () => {
6853
+ if (!predictionsEnabled || document.hidden) return;
6854
+ if (draft !== "" || running) return;
6855
+ if (currentRef.current !== "" || dismissedRef.current !== null) return;
6856
+ if (sessionId === void 0 || sessionId === null) return;
6857
+ request("next", "");
6858
+ };
6859
+ document.addEventListener("visibilitychange", onVisibility);
6860
+ return () => document.removeEventListener("visibilitychange", onVisibility);
6861
+ }, [
6862
+ draft,
6863
+ running,
6864
+ sessionId,
6865
+ request,
6866
+ predictionsEnabled
6867
+ ]);
6868
+ const rawCandidate = ghost.items.length > 0 ? ghost.items[Math.min(ghost.index, ghost.items.length - 1)] ?? "" : streamingCandidate(ghost.stream);
6869
+ const current = ghost.mode === "continue" ? joinContinuation(draft, rawCandidate) : rawCandidate;
6870
+ currentRef.current = current;
6871
+ const hasCandidate = current !== "";
6872
+ const visible = predictionsEnabled && current !== "" && box !== null && (ghost.mode === "next" ? draft === "" && !running : draft.trim() !== "" && !isTriggerToken(draft));
6873
+ react.default.useLayoutEffect(() => {
6874
+ if (ghost.mode !== "next") return void 0;
6875
+ const measure = () => {
6876
+ const found = elements();
6877
+ if (found === null) {
6878
+ setBox((previous) => previous === null ? previous : null);
6879
+ return;
6880
+ }
6881
+ const cardRect = found.card.getBoundingClientRect();
6882
+ const editorRect = found.editor.getBoundingClientRect();
6883
+ if (editorRect.width <= 0 || editorRect.height <= 0) {
6884
+ setBox((previous) => previous === null ? previous : null);
6885
+ return;
6886
+ }
6887
+ const computed = window.getComputedStyle(found.editor);
6888
+ const lineHeight = Number.parseFloat(computed.lineHeight);
6889
+ const paddingTop = Number.parseFloat(computed.paddingTop);
6890
+ const paddingLeft = Number.parseFloat(computed.paddingLeft);
6891
+ const topInset = Number.isFinite(paddingTop) ? paddingTop : EDITOR_INSET_TOP;
6892
+ const leftInset = Number.isFinite(paddingLeft) ? paddingLeft : EDITOR_INSET_LEFT;
6893
+ const next = {
6894
+ top: Math.max(0, Math.round(editorRect.top - cardRect.top + topInset)),
6895
+ left: Math.max(0, Math.round(editorRect.left - cardRect.left + leftInset)),
6896
+ right: Math.max(EDITOR_INSET_RIGHT, Math.round(cardRect.right - editorRect.right + EDITOR_SCROLL_MARGIN)),
6897
+ height: Number.isFinite(lineHeight) && lineHeight > 0 ? Math.round(lineHeight) : FALLBACK_LINE_HEIGHT
6898
+ };
6899
+ setBox((previous) => sameBox(previous, next) ? previous : next);
6900
+ };
6901
+ measure();
6902
+ const found = elements();
6903
+ let observer;
6904
+ if (found !== null && typeof ResizeObserver === "function") {
6905
+ observer = new ResizeObserver(measure);
6906
+ observer.observe(found.card);
6907
+ observer.observe(found.editor);
6908
+ }
6909
+ window.addEventListener("resize", measure);
6910
+ return () => {
6911
+ observer?.disconnect();
6912
+ window.removeEventListener("resize", measure);
6913
+ };
6914
+ }, [
6915
+ ghost.mode,
6916
+ draft,
6917
+ sessionId,
6918
+ running,
6919
+ hasCandidate
6920
+ ]);
6921
+ react.default.useLayoutEffect(() => {
6922
+ if (ghost.mode !== "continue") return void 0;
6923
+ let frame = 0;
6924
+ const measure = () => {
6925
+ frame = 0;
6926
+ const found = elements();
6927
+ if (found === null) {
6928
+ setBox((previous) => previous === null ? previous : null);
6929
+ return;
6930
+ }
6931
+ const caret = caretAtEnd(found.editor, draft);
6932
+ if (caret === null) {
6933
+ setBox((previous) => previous === null ? previous : null);
6934
+ return;
6935
+ }
6936
+ const editorRect = found.editor.getBoundingClientRect();
6937
+ if (editorRect.width <= 0 || editorRect.height <= 0) {
6938
+ setBox((previous) => previous === null ? previous : null);
6939
+ return;
6940
+ }
6941
+ const cardRect = found.card.getBoundingClientRect();
6942
+ const computed = window.getComputedStyle(found.editor);
6943
+ const lineHeight = Number.parseFloat(computed.lineHeight);
6944
+ const height = Number.isFinite(caret.height) && caret.height > 0 ? Math.round(caret.height) : Number.isFinite(lineHeight) && lineHeight > 0 ? Math.round(lineHeight) : FALLBACK_LINE_HEIGHT;
6945
+ const desired = caret.left - cardRect.left;
6946
+ const left = Math.max(0, desired);
6947
+ const maxWidth = cardRect.right - (cardRect.left + left) - 16;
6948
+ if (maxWidth < 48) {
6949
+ setBox((previous) => previous === null ? previous : null);
6950
+ return;
6951
+ }
6952
+ const top = caret.top - cardRect.top;
6953
+ if (top < 0 || top > cardRect.height - 8) {
6954
+ setBox((previous) => previous === null ? previous : null);
6955
+ return;
6956
+ }
6957
+ const next = {
6958
+ top: Math.round(top),
6959
+ left: Math.round(left),
6960
+ maxWidth: Math.round(maxWidth),
6961
+ height
6962
+ };
6963
+ setBox((previous) => sameBox(previous, next) ? previous : next);
6964
+ };
6965
+ const schedule = () => {
6966
+ if (frame === 0) frame = requestAnimationFrame(measure);
6967
+ };
6968
+ measure();
6969
+ document.addEventListener("selectionchange", schedule);
6970
+ document.addEventListener("scroll", schedule, true);
6971
+ const found = elements();
6972
+ window.addEventListener("resize", schedule);
6973
+ let observer;
6974
+ if (found !== null && typeof ResizeObserver === "function") {
6975
+ observer = new ResizeObserver(schedule);
6976
+ observer.observe(found.card);
6977
+ observer.observe(found.editor);
6978
+ }
6979
+ return () => {
6980
+ if (frame !== 0) cancelAnimationFrame(frame);
6981
+ document.removeEventListener("selectionchange", schedule);
6982
+ document.removeEventListener("scroll", schedule, true);
6983
+ window.removeEventListener("resize", schedule);
6984
+ observer?.disconnect();
6985
+ };
6986
+ }, [
6987
+ ghost.mode,
6988
+ draft,
6989
+ sessionId,
6990
+ running,
6991
+ hasCandidate
6992
+ ]);
6993
+ const accept = () => {
6994
+ const value = currentRef.current;
6995
+ if (value === "" || ghost.active) return;
6996
+ const expected = ghost.mode === "continue" ? draft + value : value;
6997
+ dismissedRef.current = { draft: expected };
6998
+ abortRef.current?.abort();
6999
+ setGhost(NO_GHOST);
7000
+ setBox(null);
7001
+ try {
7002
+ if (inputActions.insertText(value, inputActions.captureInsertion()) !== true) return;
7003
+ } catch {
7004
+ return;
7005
+ }
7006
+ try {
7007
+ const found = elements();
7008
+ if (found !== null && !found.card.contains(document.activeElement)) found.editor.focus();
7009
+ } catch {}
7010
+ };
7011
+ acceptRef.current = accept;
7012
+ const cycle = (delta) => {
7013
+ setGhost((previous) => {
7014
+ if (previous.items.length <= 1) return previous;
7015
+ const index = (previous.index + delta + previous.items.length) % previous.items.length;
7016
+ return {
7017
+ ...previous,
7018
+ index
7019
+ };
7020
+ });
7021
+ };
7022
+ cycleRef.current = cycle;
7023
+ react.default.useEffect(() => {
7024
+ if (!visible) return void 0;
7025
+ const onKeyDown = (event) => {
7026
+ if (event.defaultPrevented) return;
7027
+ if (event.isComposing === true || event.keyCode === 229) return;
7028
+ const found = elements();
7029
+ if (found === null) return;
7030
+ const target = typeof Node !== "undefined" && event.target instanceof Node ? event.target : null;
7031
+ const inEditor = found.editor.contains(document.activeElement);
7032
+ if (!(found.card.contains(document.activeElement) || target !== null && found.card.contains(target))) return;
7033
+ if (event.key === "Escape") {
7034
+ event.preventDefault();
7035
+ event.stopPropagation();
7036
+ dismissedRef.current = { draft };
7037
+ abortRef.current?.abort();
7038
+ setGhost(NO_GHOST);
7039
+ setBox(null);
7040
+ return;
7041
+ }
7042
+ if (event.altKey && (event.key === "ArrowDown" || event.key === "ArrowUp")) {
7043
+ if (ghost.items.length <= 1) return;
7044
+ event.preventDefault();
7045
+ event.stopPropagation();
7046
+ cycleRef.current?.(event.key === "ArrowDown" ? 1 : -1);
7047
+ return;
7048
+ }
7049
+ if (event.key !== "Tab" || event.shiftKey || event.ctrlKey || event.altKey || event.metaKey) return;
7050
+ if (!inEditor || ghost.active) return;
7051
+ if (ghost.mode === "continue" && caretAtEnd(found.editor, draft) === null) return;
7052
+ event.preventDefault();
7053
+ event.stopPropagation();
7054
+ acceptRef.current?.();
7055
+ };
7056
+ document.addEventListener("keydown", onKeyDown, true);
7057
+ return () => document.removeEventListener("keydown", onKeyDown, true);
7058
+ }, [
7059
+ visible,
7060
+ draft,
7061
+ ghost.items.length,
7062
+ ghost.active,
7063
+ ghost.mode
7064
+ ]);
7065
+ const anchor = h("span", {
7066
+ ref: anchorRef,
7067
+ "data-composer-prediction-anchor": "",
7068
+ "aria-hidden": "true",
7069
+ style: { display: "none" }
7070
+ });
7071
+ if (!visible || box === null) return anchor;
7072
+ const continuation = ghost.mode === "continue";
7073
+ const style = continuation ? CONTINUE_GHOST_STYLE : NEXT_GHOST_STYLE;
7074
+ const showKeycap = !ghost.active && (!continuation || (box.maxWidth ?? 0) >= 96);
7075
+ const showBadge = ghost.items.length > 1;
7076
+ return h(react.default.Fragment, null, h("span", {
7077
+ role: "status",
7078
+ "aria-live": "polite",
7079
+ "aria-atomic": "true",
7080
+ style: {
7081
+ position: "absolute",
7082
+ width: 1,
7083
+ height: 1,
7084
+ padding: 0,
7085
+ margin: -1,
7086
+ overflow: "hidden",
7087
+ clipPath: "inset(50%)",
7088
+ whiteSpace: "nowrap"
7089
+ }
7090
+ }, ghost.active ? "" : t("input.prediction.dismiss") || current), h("div", {
7091
+ style: {
7092
+ ...style,
7093
+ ...box
7094
+ },
7095
+ "aria-hidden": "true",
7096
+ "data-composer-prediction": ghost.mode,
7097
+ title: current
7098
+ }, h("span", { style: continuation ? CONTINUE_TEXT_STYLE : TEXT_STYLE }, current), showBadge ? h("span", {
7099
+ style: BADGE_STYLE,
7100
+ title: t("input.prediction.more")
7101
+ }, `${ghost.index + 1}/${ghost.items.length}`) : null, showKeycap ? h("kbd", {
7102
+ style: KEYCAP_STYLE,
7103
+ title: t("input.prediction.tab")
7104
+ }, "Tab") : null), anchor);
7105
+ }
7106
+ //#endregion
6377
7107
  //#region src/client/composer/new-conversation-style.ts
6378
7108
  /** 新建页底部输入布局;保留宿主节点、插槽与 active 会话底部信息。 */
6379
7109
  const NEW_CONVERSATION_STYLE = `
@@ -6509,6 +7239,20 @@ html[data-dsh-glass-float] [data-shortcut-modal="settings"][data-sidebar-collaps
6509
7239
  locale: NS
6510
7240
  }, SuggestionsDock));
6511
7241
  cleaners.push(unregisterSuggestions);
7242
+ function PredictionSlot(props) {
7243
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ComposerPredictionOverlay, {
7244
+ ...props,
7245
+ ctx,
7246
+ t
7247
+ });
7248
+ }
7249
+ const unregisterPrediction = ctx.slots.inject("conversation.input.overlay", () => ctx.slots.register({
7250
+ name: "conversation.input.overlay",
7251
+ id: "codex-ui-composer-prediction",
7252
+ order: 50,
7253
+ locale: NS
7254
+ }, PredictionSlot));
7255
+ cleaners.push(unregisterPrediction);
6512
7256
  return () => {
6513
7257
  for (const clean of cleaners.reverse()) try {
6514
7258
  clean();
@@ -8193,7 +8937,7 @@ html[data-dsh-glass-float] [data-shortcut-modal="settings"][data-sidebar-collaps
8193
8937
  /** 追加在项目行菜单里的入口标记。 */
8194
8938
  const MENU_ITEM_ATTR = "data-dcu-ws-section-item";
8195
8939
  const HEADER_CLASS = "dcu-ws-section";
8196
- const STYLE_ID = "michengai-codex-ui-sections-styles";
8940
+ const STYLE_ID$2 = "michengai-codex-ui-sections-styles";
8197
8941
  /** 各分区的折叠状态(与本文件的分区数据分键存放)。 */
8198
8942
  const COLLAPSED_STORAGE_KEY = "michengai.codex-ui.workspace-sections-collapsed.v1";
8199
8943
  /**
@@ -8239,9 +8983,9 @@ body[data-dcu-drag-blocked='true'] [class*="dropAfter"]::after{display:none !imp
8239
8983
  `;
8240
8984
  /** 注入分区样式;已存在时复用(样式与组件生命周期解耦,卸载不摘除)。 */
8241
8985
  function injectStyles() {
8242
- if (document.getElementById(STYLE_ID) !== null) return;
8986
+ if (document.getElementById(STYLE_ID$2) !== null) return;
8243
8987
  const style = document.createElement("style");
8244
- style.id = STYLE_ID;
8988
+ style.id = STYLE_ID$2;
8245
8989
  style.textContent = SECTIONS_CSS;
8246
8990
  document.head.appendChild(style);
8247
8991
  }
@@ -9538,6 +10282,572 @@ body[data-dcu-drag-blocked='true'] [class*="dropAfter"]::after{display:none !imp
9538
10282
  return dispose;
9539
10283
  }
9540
10284
  //#endregion
10285
+ //#region src/client/desktop-menu/restart-client.ts
10286
+ /**
10287
+ * 「重启应用与 Host」的客户端通道与进度卡片。
10288
+ *
10289
+ * 页面只做三件事:问 Host 能不能重启(status,拿到一次性令牌)→ 带着令牌 POST →
10290
+ * 轮询阶段把实情显示出来。真正的退出与重开由 Host 侧生成的助手脚本完成。
10291
+ *
10292
+ * 为什么不在这里直接 location.reload:重载只换页面,插件宿主进程还在,装了新插件
10293
+ * 也不生效;真重启必须让整个应用退出再起来。
10294
+ */
10295
+ /** 与 checkDesktopMenuEnabled 相同的方式拼出端点地址(兼容 dsh-app:// 协议)。 */
10296
+ function endpointUrl(search) {
10297
+ const base = typeof document !== "undefined" && document.baseURI ? document.baseURI : "http://localhost";
10298
+ const normalizedBase = base.endsWith("/") ? base : `${base}/`;
10299
+ const path = CODEX_UI_API_ENDPOINTS.desktopMenu.startsWith("/") ? CODEX_UI_API_ENDPOINTS.desktopMenu.slice(1) : CODEX_UI_API_ENDPOINTS.desktopMenu;
10300
+ return `${new URL(path, normalizedBase).href}${search}`;
10301
+ }
10302
+ /** 读一次重启状态;网络/协议不可用时返回 null(调用方据此报「通道不可用」)。 */
10303
+ async function fetchRestartStatus() {
10304
+ try {
10305
+ const response = await fetch(endpointUrl("?action=status"), {
10306
+ method: "GET",
10307
+ cache: "no-store",
10308
+ headers: { accept: "application/json" }
10309
+ });
10310
+ if (!response.ok) return null;
10311
+ const payload = await response.json();
10312
+ if (typeof payload?.token !== "string") return null;
10313
+ return payload;
10314
+ } catch {
10315
+ return null;
10316
+ }
10317
+ }
10318
+ /** 带着令牌请求重启。 */
10319
+ async function requestRestart(token) {
10320
+ try {
10321
+ const response = await fetch(endpointUrl("?action=restart"), {
10322
+ method: "POST",
10323
+ cache: "no-store",
10324
+ headers: {
10325
+ accept: "application/json",
10326
+ [CODEX_UI_RESTART_HEADER]: token
10327
+ }
10328
+ });
10329
+ const payload = await response.json().catch(() => ({}));
10330
+ if (response.ok && payload.ok === true) return { ok: true };
10331
+ return {
10332
+ ok: false,
10333
+ error: payload.error ?? `http-${response.status}`,
10334
+ detail: payload.detail,
10335
+ reason: payload.reason
10336
+ };
10337
+ } catch (error) {
10338
+ return {
10339
+ ok: false,
10340
+ error: error instanceof Error ? error.message : String(error)
10341
+ };
10342
+ }
10343
+ }
10344
+ const STYLE_ID$1 = "dcu-desktop-restart-style";
10345
+ const STYLES$1 = `
10346
+ .dcu-restart-toast {
10347
+ position: fixed;
10348
+ z-index: 10001;
10349
+ right: 20px;
10350
+ bottom: 20px;
10351
+ width: min(380px, calc(100vw - 40px));
10352
+ padding: 14px 16px;
10353
+ display: flex;
10354
+ flex-direction: column;
10355
+ gap: 8px;
10356
+ border-radius: var(--dsw-radius-md, 10px);
10357
+ border: 1px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.1));
10358
+ background: var(--dsw-menu-surface-fill, var(--dsw-alias-surface-overlay, #1e1e22));
10359
+ backdrop-filter: var(--dsw-menu-backdrop-filter, blur(40px) saturate(150%));
10360
+ -webkit-backdrop-filter: var(--dsw-menu-backdrop-filter, blur(40px) saturate(150%));
10361
+ box-shadow: var(--dsw-elevation-prominent, 0 14px 34px rgba(0, 0, 0, 0.36));
10362
+ color: var(--dsw-alias-label-primary, #fff);
10363
+ font-family: var(--dsw-font-family, sans-serif);
10364
+ font-size: 13px;
10365
+ line-height: 19px;
10366
+ animation: dcu-restart-in 120ms ease-out;
10367
+ }
10368
+
10369
+ @keyframes dcu-restart-in {
10370
+ from { opacity: 0; transform: translateY(6px); }
10371
+ to { opacity: 1; transform: translateY(0); }
10372
+ }
10373
+
10374
+ .dcu-restart-toast[data-tone="error"] {
10375
+ border-color: var(--dsw-alias-state-error-primary, #ff6b6b);
10376
+ }
10377
+
10378
+ .dcu-restart-toast-title {
10379
+ font-weight: 600;
10380
+ }
10381
+
10382
+ .dcu-restart-toast-body {
10383
+ color: var(--dsw-alias-label-secondary, #a1a1a6);
10384
+ overflow-wrap: anywhere;
10385
+ }
10386
+
10387
+ .dcu-restart-toast-action {
10388
+ align-self: flex-end;
10389
+ height: 26px;
10390
+ padding: 0 10px;
10391
+ border-radius: var(--dsw-radius-sm, 6px);
10392
+ border: 1px solid var(--dsw-alias-border-l2, rgba(255, 255, 255, 0.14));
10393
+ background: transparent;
10394
+ color: inherit;
10395
+ font: inherit;
10396
+ font-size: 12px;
10397
+ cursor: pointer;
10398
+ }
10399
+
10400
+ .dcu-restart-toast-action:hover {
10401
+ background: var(--dsw-alias-interactive-bg-hover, rgba(255, 255, 255, 0.08));
10402
+ }
10403
+ `;
10404
+ function ensureStyles$1() {
10405
+ if (document.getElementById(STYLE_ID$1) !== null) return;
10406
+ const style = document.createElement("style");
10407
+ style.id = STYLE_ID$1;
10408
+ style.textContent = STYLES$1;
10409
+ document.head.append(style);
10410
+ }
10411
+ /**
10412
+ * 显示重启提示卡。
10413
+ * @param copy - 当前语言文案。
10414
+ */
10415
+ function showRestartToast(copy) {
10416
+ ensureStyles$1();
10417
+ const card = document.createElement("div");
10418
+ card.className = "dcu-restart-toast";
10419
+ card.setAttribute("role", "status");
10420
+ card.setAttribute("aria-live", "polite");
10421
+ const title = document.createElement("div");
10422
+ title.className = "dcu-restart-toast-title";
10423
+ const body = document.createElement("div");
10424
+ body.className = "dcu-restart-toast-body";
10425
+ const action = document.createElement("button");
10426
+ action.type = "button";
10427
+ action.className = "dcu-restart-toast-action";
10428
+ action.textContent = copy.close;
10429
+ action.hidden = true;
10430
+ action.addEventListener("click", () => {
10431
+ card.remove();
10432
+ });
10433
+ card.append(title, body, action);
10434
+ document.body.append(card);
10435
+ return { set(nextTitle, nextBody, tone = "info") {
10436
+ title.textContent = nextTitle;
10437
+ body.textContent = nextBody ?? "";
10438
+ body.hidden = nextBody === void 0 || nextBody === "";
10439
+ card.dataset.tone = tone;
10440
+ action.hidden = tone !== "error";
10441
+ } };
10442
+ }
10443
+ /**
10444
+ * 重启后盯住阶段:页面通常会在应用退出时被带走,所以这里只是尽量把结果说清楚。
10445
+ * @param toast - 提示卡。
10446
+ * @param copy - 文案。
10447
+ * @param pollMs - 轮询间隔。
10448
+ * @param limitMs - 最长观察时间。
10449
+ */
10450
+ function watchRestart(toast, copy, pollMs = 700, limitMs = 9e4) {
10451
+ const startedAt = Date.now();
10452
+ let timer;
10453
+ let stopped = false;
10454
+ const stop = () => {
10455
+ stopped = true;
10456
+ if (timer !== void 0) window.clearInterval(timer);
10457
+ };
10458
+ const tick = async () => {
10459
+ if (stopped) return;
10460
+ if (Date.now() - startedAt > limitMs) {
10461
+ stop();
10462
+ toast.set(copy.timeout, void 0, "error");
10463
+ return;
10464
+ }
10465
+ const status = await fetchRestartStatus();
10466
+ if (stopped) return;
10467
+ if (status === null) return;
10468
+ const phase = status.phase;
10469
+ if (phase === "quitting" || phase === "starting") {
10470
+ toast.set(copy.quitting);
10471
+ return;
10472
+ }
10473
+ if (phase === "relaunched") {
10474
+ stop();
10475
+ toast.set(copy.relaunched);
10476
+ return;
10477
+ }
10478
+ if (phase === "cancelled") {
10479
+ stop();
10480
+ toast.set(copy.cancelled, status.detail, "error");
10481
+ return;
10482
+ }
10483
+ if (phase === "launch-failed") {
10484
+ stop();
10485
+ toast.set(copy.launchFailed, status.detail, "error");
10486
+ }
10487
+ };
10488
+ timer = window.setInterval(() => {
10489
+ tick();
10490
+ }, pollMs);
10491
+ return stop;
10492
+ }
10493
+ //#endregion
10494
+ //#region src/client/desktop-menu/index.ts
10495
+ /** 「重启应用与 Host」的文案:全部来自本插件的词典,不在代码里写死语言。 */
10496
+ function restartCopy(translate) {
10497
+ return {
10498
+ quitting: translate("desktopMenu.restart.quitting", "Closing and reopening DeepSeek Harness…"),
10499
+ relaunched: translate("desktopMenu.restart.relaunched", "Restarted."),
10500
+ cancelled: translate("desktopMenu.restart.cancelled", "The app did not exit; this restart was cancelled."),
10501
+ launchFailed: translate("desktopMenu.restart.launchFailed", "The app exited but could not be reopened automatically."),
10502
+ timeout: translate("desktopMenu.restart.timeout", "The restart did not finish in time; please check the app."),
10503
+ close: translate("desktopMenu.restart.close", "Close"),
10504
+ failed: translate("desktopMenu.restart.failed", "Restart failed"),
10505
+ busy: translate("desktopMenu.restart.busy", "A restart is already in progress. Please wait.")
10506
+ };
10507
+ }
10508
+ /** 不可重启的原因代码 → 本地文案。 */
10509
+ function unsupportedText(translate, reason) {
10510
+ if (reason === "desktop-only") return translate("desktopMenu.restart.unsupportedDesktopOnly", "This is not the desktop app, so it cannot be restarted.");
10511
+ return translate("desktopMenu.restart.unsupportedMissingApp", "Cannot locate the DeepSeek Harness executable, so it cannot be restarted.");
10512
+ }
10513
+ const MENU_HOST_CLASS = "dcu-desktop-menu-popover";
10514
+ const STYLE_ID = "dcu-desktop-menu-style";
10515
+ const STYLES = `
10516
+ .${MENU_HOST_CLASS} {
10517
+ position: fixed;
10518
+ z-index: 10000;
10519
+ min-width: 200px;
10520
+ max-width: 320px;
10521
+ padding: 4px;
10522
+ display: flex;
10523
+ flex-direction: column;
10524
+ gap: 2px;
10525
+ border-radius: var(--dsw-radius-md, 8px);
10526
+ background: var(--dsw-menu-surface-fill, var(--dsw-alias-surface-overlay, #1e1e22));
10527
+ backdrop-filter: var(--dsw-menu-backdrop-filter, blur(40px) saturate(150%));
10528
+ -webkit-backdrop-filter: var(--dsw-menu-backdrop-filter, blur(40px) saturate(150%));
10529
+ box-shadow: var(--dsw-elevation-prominent, 0 14px 34px rgba(0,0,0,0.36), 0 2px 8px rgba(0,0,0,0.24));
10530
+ border: 1px solid var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.08));
10531
+ color: var(--dsw-alias-label-primary, #ffffff);
10532
+ font-family: var(--dsw-font-family, sans-serif);
10533
+ animation: dcu-menu-fade-in 100ms ease-out;
10534
+ outline: none;
10535
+ -webkit-app-region: no-drag;
10536
+ }
10537
+
10538
+ @keyframes dcu-menu-fade-in {
10539
+ from { opacity: 0; transform: translateY(-4px); }
10540
+ to { opacity: 1; transform: translateY(0); }
10541
+ }
10542
+
10543
+ .${MENU_HOST_CLASS} .dcu-menu-separator {
10544
+ height: 1px;
10545
+ margin: 4px 6px;
10546
+ background: var(--dsw-alias-border-l1, rgba(255, 255, 255, 0.08));
10547
+ }
10548
+
10549
+ .${MENU_HOST_CLASS} button.dcu-menu-item {
10550
+ display: flex;
10551
+ align-items: center;
10552
+ justify-content: space-between;
10553
+ gap: 12px;
10554
+ width: 100%;
10555
+ min-height: 28px;
10556
+ padding: 5px 8px;
10557
+ text-align: left;
10558
+ border: 0;
10559
+ border-radius: var(--dsw-radius-sm, 6px);
10560
+ background: transparent;
10561
+ color: inherit;
10562
+ font: inherit;
10563
+ font-size: 13px;
10564
+ line-height: 18px;
10565
+ cursor: pointer;
10566
+ outline: none;
10567
+ transition: background-color 100ms ease;
10568
+ user-select: none;
10569
+ -webkit-user-select: none;
10570
+ -webkit-app-region: no-drag;
10571
+ }
10572
+
10573
+ .${MENU_HOST_CLASS} button.dcu-menu-item:hover,
10574
+ .${MENU_HOST_CLASS} button.dcu-menu-item:focus-visible {
10575
+ background: var(--dsw-alias-interactive-bg-hover, rgba(255, 255, 255, 0.08));
10576
+ }
10577
+
10578
+ .${MENU_HOST_CLASS} .dcu-menu-label {
10579
+ flex: 1 1 auto;
10580
+ white-space: nowrap;
10581
+ overflow: hidden;
10582
+ text-overflow: ellipsis;
10583
+ }
10584
+ `;
10585
+ function ensureStyles() {
10586
+ if (document.getElementById(STYLE_ID) !== null) return;
10587
+ const style = document.createElement("style");
10588
+ style.id = STYLE_ID;
10589
+ style.textContent = STYLES;
10590
+ document.head.append(style);
10591
+ }
10592
+ let activePopover = null;
10593
+ let activeAnchor = null;
10594
+ function closeActiveMenu(restoreFocus = false) {
10595
+ const anchor = activeAnchor;
10596
+ if (activePopover !== null) {
10597
+ activePopover.remove();
10598
+ activePopover = null;
10599
+ }
10600
+ if (activeAnchor !== null) {
10601
+ activeAnchor.setAttribute("aria-expanded", "false");
10602
+ activeAnchor = null;
10603
+ }
10604
+ if (restoreFocus && anchor && anchor.isConnected) anchor.focus();
10605
+ }
10606
+ function openDropdown(anchor, items, options = {}) {
10607
+ if (activeAnchor === anchor && activePopover !== null) {
10608
+ closeActiveMenu();
10609
+ return;
10610
+ }
10611
+ closeActiveMenu();
10612
+ ensureStyles();
10613
+ const rect = anchor.getBoundingClientRect();
10614
+ const popover = document.createElement("div");
10615
+ popover.className = MENU_HOST_CLASS;
10616
+ popover.setAttribute("role", "menu");
10617
+ popover.tabIndex = -1;
10618
+ for (const item of items) {
10619
+ if (item.separatorBefore) {
10620
+ const sep = document.createElement("div");
10621
+ sep.className = "dcu-menu-separator";
10622
+ sep.setAttribute("role", "separator");
10623
+ popover.append(sep);
10624
+ }
10625
+ const btn = document.createElement("button");
10626
+ btn.type = "button";
10627
+ btn.className = "dcu-menu-item";
10628
+ btn.setAttribute("role", "menuitem");
10629
+ const labelSpan = document.createElement("span");
10630
+ labelSpan.className = "dcu-menu-label";
10631
+ labelSpan.textContent = item.label;
10632
+ btn.append(labelSpan);
10633
+ btn.addEventListener("pointerdown", (e) => {
10634
+ e.stopPropagation();
10635
+ });
10636
+ btn.addEventListener("mousedown", (e) => {
10637
+ e.stopPropagation();
10638
+ });
10639
+ btn.addEventListener("click", (e) => {
10640
+ e.preventDefault();
10641
+ e.stopPropagation();
10642
+ closeActiveMenu();
10643
+ setTimeout(() => {
10644
+ try {
10645
+ Promise.resolve(item.action?.()).catch((err) => {
10646
+ console.error("Menu action error:", err);
10647
+ });
10648
+ } catch (err) {
10649
+ console.error("Menu action error:", err);
10650
+ }
10651
+ }, 10);
10652
+ });
10653
+ popover.append(btn);
10654
+ }
10655
+ document.body.append(popover);
10656
+ const popoverRect = popover.getBoundingClientRect();
10657
+ let left = rect.left;
10658
+ let top = rect.bottom + 2;
10659
+ if (left + popoverRect.width > window.innerWidth - 8) left = window.innerWidth - popoverRect.width - 8;
10660
+ if (left < 8) left = 8;
10661
+ if (top + popoverRect.height > window.innerHeight - 8) top = rect.top - popoverRect.height - 2;
10662
+ popover.style.left = `${Math.round(left)}px`;
10663
+ popover.style.top = `${Math.round(top)}px`;
10664
+ anchor.setAttribute("aria-expanded", "true");
10665
+ activePopover = popover;
10666
+ activeAnchor = anchor;
10667
+ const menuItems = Array.from(popover.querySelectorAll("button.dcu-menu-item"));
10668
+ const focusAt = (index) => {
10669
+ if (menuItems.length === 0) return;
10670
+ const clamped = Math.max(0, Math.min(index, menuItems.length - 1));
10671
+ menuItems[clamped].focus();
10672
+ };
10673
+ popover.addEventListener("keydown", (event) => {
10674
+ const current = menuItems.indexOf(document.activeElement);
10675
+ if (event.key === "ArrowDown") {
10676
+ event.preventDefault();
10677
+ focusAt(current < 0 ? 0 : current + 1);
10678
+ } else if (event.key === "ArrowUp") {
10679
+ event.preventDefault();
10680
+ focusAt(current < 0 ? menuItems.length - 1 : current - 1);
10681
+ } else if (event.key === "Home") {
10682
+ event.preventDefault();
10683
+ focusAt(0);
10684
+ } else if (event.key === "End") {
10685
+ event.preventDefault();
10686
+ focusAt(menuItems.length - 1);
10687
+ }
10688
+ });
10689
+ if (options.focusFirst === true && menuItems.length > 0) menuItems[0].focus();
10690
+ else popover.focus();
10691
+ }
10692
+ /**
10693
+ * 监听全局事件以支持点击外部或按 Esc 关闭菜单
10694
+ */
10695
+ let globalListenersInstalled = false;
10696
+ function ensureGlobalListeners() {
10697
+ if (globalListenersInstalled) return;
10698
+ globalListenersInstalled = true;
10699
+ document.addEventListener("pointerdown", (e) => {
10700
+ if (activePopover === null) return;
10701
+ const path = e.composedPath ? e.composedPath() : [];
10702
+ if (path.length > 0) {
10703
+ if (activePopover && path.includes(activePopover)) return;
10704
+ if (activeAnchor && path.includes(activeAnchor)) return;
10705
+ } else {
10706
+ const target = e.target;
10707
+ if (target && (activePopover.contains(target) || activeAnchor?.contains(target))) return;
10708
+ }
10709
+ closeActiveMenu();
10710
+ }, true);
10711
+ window.addEventListener("keydown", (e) => {
10712
+ if (e.key === "Escape" && activePopover !== null) closeActiveMenu(true);
10713
+ }, true);
10714
+ }
10715
+ /**
10716
+ * 检查桌面端窗口菜单子插件在 Host 侧是否启用
10717
+ */
10718
+ async function checkDesktopMenuEnabled() {
10719
+ try {
10720
+ const base = typeof document !== "undefined" && document.baseURI ? document.baseURI : "http://localhost";
10721
+ const normalizedBase = base.endsWith("/") ? base : `${base}/`;
10722
+ const path = CODEX_UI_API_ENDPOINTS.desktopMenu.startsWith("/") ? CODEX_UI_API_ENDPOINTS.desktopMenu.slice(1) : CODEX_UI_API_ENDPOINTS.desktopMenu;
10723
+ const url = new URL(path, normalizedBase).href;
10724
+ const res = await fetch(url, { method: "GET" });
10725
+ if (!res.ok) return true;
10726
+ return (await res.json()).enabled !== false;
10727
+ } catch {
10728
+ return true;
10729
+ }
10730
+ }
10731
+ /**
10732
+ * 观察并在 Windows 桌面端的 data-windows-menu 宿主上注入【帮助】菜单。
10733
+ * 只追加一个入口,官方【应用】【编辑】保持原样。
10734
+ */
10735
+ function observeDesktopTitlebarMenus(translate = (_k, fallback) => fallback ?? "") {
10736
+ ensureGlobalListeners();
10737
+ let cleanedUp = false;
10738
+ let injectedHelpBtn = null;
10739
+ const getHelpItems = () => {
10740
+ const zh = document.documentElement.lang?.toLowerCase().startsWith("zh") ?? true;
10741
+ return [{
10742
+ id: "reload-page",
10743
+ label: translate("desktopMenu.help.reloadPage", zh ? "刷新页面" : "Reload Page"),
10744
+ action: () => {
10745
+ window.location.reload();
10746
+ }
10747
+ }, {
10748
+ id: "restart-host",
10749
+ label: translate("desktopMenu.help.restartAppHost", zh ? "重启应用与 Host" : "Restart App and Host"),
10750
+ action: async () => {
10751
+ const copy = restartCopy(translate);
10752
+ const status = await fetchRestartStatus();
10753
+ if (status === null) {
10754
+ showRestartToast(copy).set(copy.failed, translate("desktopMenu.restart.unreachable", "Cannot reach the Host; the restart channel is unavailable."), "error");
10755
+ return;
10756
+ }
10757
+ if (!status.canRestart) {
10758
+ showRestartToast(copy).set(copy.failed, unsupportedText(translate, status.reason), "error");
10759
+ return;
10760
+ }
10761
+ const confirmMsg = translate("desktopMenu.help.restartConfirm", "DeepSeek Harness will close and reopen; running tasks will be interrupted. Continue?");
10762
+ if (!window.confirm(confirmMsg)) return;
10763
+ const toast = showRestartToast(copy);
10764
+ toast.set(copy.quitting);
10765
+ const outcome = await requestRestart(status.token);
10766
+ if (!outcome.ok) {
10767
+ const detailText = outcome.error === "busy" ? copy.busy : outcome.reason ? unsupportedText(translate, outcome.reason) : outcome.detail ?? outcome.error ?? "unknown";
10768
+ toast.set(copy.failed, detailText, "error");
10769
+ return;
10770
+ }
10771
+ watchRestart(toast, copy);
10772
+ }
10773
+ }];
10774
+ };
10775
+ const mountMenus = () => {
10776
+ if (cleanedUp || typeof document === "undefined") return;
10777
+ const host = document.querySelector("[data-windows-menu]");
10778
+ if (!host || !host.shadowRoot) return;
10779
+ const shadow = host.shadowRoot;
10780
+ const bar = shadow.querySelector("[role=\"menubar\"]");
10781
+ if (!bar) return;
10782
+ if (Array.from(bar.querySelectorAll("button")).length === 0) return;
10783
+ if (!shadow.getElementById("dcu-desktop-menu-help")) {
10784
+ const helpBtn = document.createElement("button");
10785
+ helpBtn.type = "button";
10786
+ helpBtn.id = "dcu-desktop-menu-help";
10787
+ helpBtn.setAttribute("role", "menuitem");
10788
+ helpBtn.setAttribute("aria-haspopup", "menu");
10789
+ helpBtn.setAttribute("aria-expanded", "false");
10790
+ const setRovingFocus = (target) => {
10791
+ bar.querySelectorAll("button").forEach((btn) => {
10792
+ btn.tabIndex = btn === target ? 0 : -1;
10793
+ });
10794
+ target.focus();
10795
+ };
10796
+ helpBtn.tabIndex = -1;
10797
+ helpBtn.textContent = translate("desktopMenu.help", "帮助");
10798
+ helpBtn.addEventListener("click", (e) => {
10799
+ e.preventDefault();
10800
+ e.stopPropagation();
10801
+ openDropdown(helpBtn, getHelpItems());
10802
+ });
10803
+ helpBtn.addEventListener("keydown", (e) => {
10804
+ if (e.key === "ArrowDown" || e.key === "Enter" || e.key === " ") {
10805
+ e.preventDefault();
10806
+ e.stopPropagation();
10807
+ openDropdown(helpBtn, getHelpItems(), { focusFirst: true });
10808
+ return;
10809
+ }
10810
+ if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
10811
+ e.preventDefault();
10812
+ e.stopPropagation();
10813
+ const official = Array.from(bar.querySelectorAll("button:not(#dcu-desktop-menu-help)"));
10814
+ const target = e.key === "ArrowLeft" ? official[official.length - 1] ?? official[0] : official[0];
10815
+ if (target) setRovingFocus(target);
10816
+ }
10817
+ });
10818
+ bar.addEventListener("keydown", (e) => {
10819
+ const target = e.target;
10820
+ if (!target || target === helpBtn) return;
10821
+ const official = Array.from(bar.querySelectorAll("button:not(#dcu-desktop-menu-help)"));
10822
+ if (official.length === 0) return;
10823
+ if (e.key === "ArrowRight" && target === official[official.length - 1]) {
10824
+ e.preventDefault();
10825
+ e.stopImmediatePropagation();
10826
+ setRovingFocus(helpBtn);
10827
+ } else if (e.key === "ArrowLeft" && target === official[0]) {
10828
+ e.preventDefault();
10829
+ e.stopImmediatePropagation();
10830
+ setRovingFocus(helpBtn);
10831
+ }
10832
+ }, true);
10833
+ bar.append(helpBtn);
10834
+ injectedHelpBtn = helpBtn;
10835
+ }
10836
+ };
10837
+ mountMenus();
10838
+ const observer = new MutationObserver(() => {
10839
+ mountMenus();
10840
+ });
10841
+ observer.observe(document.body, { childList: true });
10842
+ return () => {
10843
+ cleanedUp = true;
10844
+ observer.disconnect();
10845
+ closeActiveMenu();
10846
+ injectedHelpBtn?.remove();
10847
+ document.getElementById(STYLE_ID)?.remove();
10848
+ };
10849
+ }
10850
+ //#endregion
9541
10851
  //#region src/client/index.ts
9542
10852
  const inject = [
9543
10853
  "slots",
@@ -9546,7 +10856,8 @@ body[data-dcu-drag-blocked='true'] [class*="dropAfter"]::after{display:none !imp
9546
10856
  "conversation",
9547
10857
  "inputTriggers",
9548
10858
  "layout",
9549
- "uiWorkspace"
10859
+ "uiWorkspace",
10860
+ "workspaces"
9550
10861
  ];
9551
10862
  /** 浏览器客户端插件入口;保留官方原生侧边栏与工作区树,提供输入框增强、设置美化与生态关于页。 */
9552
10863
  function apply(ctx) {
@@ -9557,6 +10868,26 @@ body[data-dcu-drag-blocked='true'] [class*="dropAfter"]::after{display:none !imp
9557
10868
  const t = ctx.locale.bind(NS);
9558
10869
  ctx.effect(() => observeTheme(ctx), "michengai-codex-ui: theme & appearance");
9559
10870
  ctx.effect(() => observeSidebarNav(ctx), "michengai-codex-ui: sidebar navigation");
10871
+ ctx.effect(() => {
10872
+ let stop;
10873
+ let cancelled = false;
10874
+ checkDesktopMenuEnabled().then((enabled) => {
10875
+ if (cancelled || !enabled) return;
10876
+ const translate = (key, fallback) => {
10877
+ try {
10878
+ const value = t(key);
10879
+ return typeof value === "string" && value !== "" && value !== key ? value : fallback ?? key;
10880
+ } catch {
10881
+ return fallback ?? key;
10882
+ }
10883
+ };
10884
+ stop = observeDesktopTitlebarMenus(translate);
10885
+ });
10886
+ return () => {
10887
+ cancelled = true;
10888
+ stop?.();
10889
+ };
10890
+ }, "michengai-codex-ui: desktop titlebar menus");
9560
10891
  ctx.effect(() => {
9561
10892
  let stop;
9562
10893
  let cancelled = false;