@michengai/dsh-im-connect 1.0.7 → 1.0.9
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/CHANGELOG.md +26 -0
- package/CHANGELOG.zh-CN.md +26 -0
- package/client.js +1042 -1298
- package/lib/client.js +1039 -1295
- package/lib/manager.d.ts +0 -1
- package/lib/manager.d.ts.map +1 -1
- package/lib/manager.js +0 -15
- package/lib/manager.js.map +1 -1
- package/package.json +1 -1
- package/src/manager.ts +0 -13
package/lib/client.js
CHANGED
|
@@ -328,7 +328,7 @@ function observePluginUpdate(options) {
|
|
|
328
328
|
var module = { exports: {} };
|
|
329
329
|
var exports = module.exports;
|
|
330
330
|
const React = require("react");
|
|
331
|
-
const { useState, useEffect, useLayoutEffect, useCallback, useRef, useSyncExternalStore } = React;
|
|
331
|
+
const { useState, useEffect, useLayoutEffect, useCallback, useMemo, useRef, useSyncExternalStore } = React;
|
|
332
332
|
const ReactDOM = require("react-dom");
|
|
333
333
|
const primitives = typeof require === "function" ? (function () { try { return require("@deepseek-ai/dsh-client-ui-primitives"); } catch { return {}; } })() : {};
|
|
334
334
|
const PrimitiveButton = primitives.Button;
|
|
@@ -349,64 +349,28 @@ function observePluginUpdate(options) {
|
|
|
349
349
|
}
|
|
350
350
|
return function MissingHostIcon() { return null; };
|
|
351
351
|
}
|
|
352
|
-
function hostOrFallback(icon, Fallback) {
|
|
353
|
-
return function HostOrFallback(props) {
|
|
354
|
-
const node = icon(props);
|
|
355
|
-
return node == null ? Fallback(props) : node;
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
// 0.1.7 的 Menu 会渲染 children。更早的 Menu 只认 items。样式和列表功能不再按宿主版本分叉。
|
|
359
|
-
function hostMenuRendersChildren() {
|
|
360
|
-
return typeof primitives.IconEllipsisOutlineRegular === "function";
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* 宿主 renderer 对「调用本 entry 未声明的子槽位」是直接抛 SlotOwnershipError 的,抛点在调用瞬间。
|
|
364
|
-
* sidebar.workspaces.session.menu.item 和 row.action 都是 0.1.7 才声明的子槽位,旧宿主
|
|
365
|
-
* (0.1.2 / 0.1.5)没有:一旦抛到宿主,宿主的槽位错误边界只会给这块画一个空的 crash div,
|
|
366
|
-
* 整块会话列表跟着消失(Issue #13)。这里统一兜住,失败只当该槽位没有内容。
|
|
367
|
-
*/
|
|
368
|
-
const skippedHostSlotKeys = new Set();
|
|
369
|
-
function renderHostSlot(renderSlot, key, slotProps, options) {
|
|
370
|
-
if (typeof renderSlot !== "function") return undefined;
|
|
371
|
-
try {
|
|
372
|
-
return renderSlot(key, slotProps, options);
|
|
373
|
-
} catch (error) {
|
|
374
|
-
if (!skippedHostSlotKeys.has(key)) {
|
|
375
|
-
skippedHostSlotKeys.add(key);
|
|
376
|
-
console.warn("[dsh-im-connect] 宿主未声明槽位 " + key + ",已跳过该槽位", error);
|
|
377
|
-
}
|
|
378
|
-
return undefined;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
const IconListPenOutline16 = pickHostIcon("IconListPenOutlineRegular", "IconListPenOutline16");
|
|
382
|
-
const IconEditOutline16 = pickHostIcon("IconEditOutlineRegular", "IconEditOutline16");
|
|
383
|
-
const IconBranchOutline16 = pickHostIcon("IconBranchOutlineRegular", "IconBranchOutline16");
|
|
384
|
-
const IconArchiveOutline20 = pickHostIcon("IconArchiveOutlineRegular", "IconArchiveOutline20");
|
|
385
|
-
const IconArchiveCheckHost = pickHostIcon("IconArchiveCheckOutlineRegular");
|
|
386
|
-
const IconTrashOutline16 = pickHostIcon("IconTrashOutlineRegular", "IconTrashOutline16");
|
|
387
|
-
const IconEllipsisOutline16 = pickHostIcon("IconEllipsisOutlineRegular", "IconEllipsisOutline16");
|
|
388
|
-
const IconSearchHost = pickHostIcon("IconSearchOutlineRegular", "IconSearchOutline16");
|
|
389
|
-
const IconCloseFillHost = pickHostIcon("IconCloseFillRegular", "IconCloseOutline16");
|
|
390
|
-
const IconSlidersHost = pickHostIcon("IconSlidersTwoOutlineRegular", "IconSlidersOutline16");
|
|
391
352
|
const IconFolderClose = pickHostIcon("IconFolderCloseRegular", "IconFolderClose16", "IconFolderClose");
|
|
392
353
|
const IconClockOutline = pickHostIcon("IconClockOutlineRegular", "IconClockOutline16");
|
|
393
|
-
const
|
|
354
|
+
const IconQueueOutline = pickHostIcon("IconQueueOutlineRegular");
|
|
355
|
+
const IconCheckOutline = pickHostIcon("IconCheckOutlineRegular");
|
|
356
|
+
const IconCheckCircleOutline = pickHostIcon("IconCheckCircleOutlineRegular");
|
|
357
|
+
const IconCloseCircleFill = pickHostIcon("IconCloseCircleFillRegular");
|
|
358
|
+
const IconInfoOutline = pickHostIcon("IconInfoOutlineRegular");
|
|
359
|
+
const IconWarningOutline = pickHostIcon("IconWarningOutlineRegular");
|
|
360
|
+
const IconCloseFill = pickHostIcon("IconCloseFillRegular");
|
|
361
|
+
const IconChevronDownOutline = pickHostIcon("IconChevronDownOutlineRegular");
|
|
362
|
+
const IconChevronRightOutline = pickHostIcon("IconChevronRightOutlineRegular");
|
|
363
|
+
const IconPlusOutline = pickHostIcon("IconPlusOutlineRegular");
|
|
364
|
+
const IconEditOutline = pickHostIcon("IconEditOutlineRegular");
|
|
365
|
+
const IconRefreshOutline = pickHostIcon("IconRefreshOutlineRegular");
|
|
366
|
+
const IconDownloadOutline = pickHostIcon("IconDownloadOutlineRegular");
|
|
367
|
+
const IconCopyOutline = pickHostIcon("IconCopyOutlineRegular");
|
|
368
|
+
const IconLoadingOutline = pickHostIcon("IconLoadingOutlineRegular");
|
|
394
369
|
function alertIcon(type) {
|
|
395
|
-
if (type === "success") {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
}
|
|
400
|
-
if (type === "error") {
|
|
401
|
-
return React.createElement("svg", { viewBox: "0 0 16 16", width: 14, height: 14, fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", strokeLinejoin: "round" },
|
|
402
|
-
React.createElement("circle", { cx: 8, cy: 8, r: 6 }),
|
|
403
|
-
React.createElement("path", { d: "m8 5v3.5M8 11.5h.01" })
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
return React.createElement("svg", { viewBox: "0 0 16 16", width: 14, height: 14, fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", strokeLinejoin: "round" },
|
|
407
|
-
React.createElement("circle", { cx: 8, cy: 8, r: 6 }),
|
|
408
|
-
React.createElement("path", { d: "M8 7.5v3.5M8 5h.01" })
|
|
409
|
-
);
|
|
370
|
+
if (type === "success") return h(IconCheckCircleOutline, { size: 14 });
|
|
371
|
+
if (type === "warning") return h(IconWarningOutline, { size: 14 });
|
|
372
|
+
if (type === "error") return h(IconCloseCircleFill, { size: 14 });
|
|
373
|
+
return h(IconInfoOutline, { size: 14 });
|
|
410
374
|
}
|
|
411
375
|
function NoticeBar({ type = "info", icon, children, className, role, showIcon }) {
|
|
412
376
|
const iconNode = icon !== undefined ? icon : (showIcon !== false ? alertIcon(type) : null);
|
|
@@ -538,9 +502,7 @@ function observePluginUpdate(options) {
|
|
|
538
502
|
React.createElement("div", { className: "ima-modal-header" },
|
|
539
503
|
React.createElement("div", { className: "ima-modal-title" }, title),
|
|
540
504
|
React.createElement("button", { type: "button", className: "ima-modal-close", "aria-label": closeLabel || "Close", onClick: handleClose },
|
|
541
|
-
|
|
542
|
-
React.createElement("path", { d: "m4 4 8 8M12 4 4 12" })
|
|
543
|
-
)
|
|
505
|
+
h(IconCloseFill, { size: 14 })
|
|
544
506
|
)
|
|
545
507
|
),
|
|
546
508
|
React.createElement("div", { className: "ima-modal-body" },
|
|
@@ -701,18 +663,11 @@ function observePluginUpdate(options) {
|
|
|
701
663
|
onClick: () => { if (!props.disabled) setOpen((prev) => !prev); },
|
|
702
664
|
},
|
|
703
665
|
React.createElement("span", { className: "ima-menu-select-label" }, currentText),
|
|
704
|
-
|
|
666
|
+
h(IconChevronDownOutline, {
|
|
667
|
+
size: 12,
|
|
705
668
|
className: "ima-menu-select-arrow",
|
|
706
|
-
viewBox: "0 0 16 16",
|
|
707
|
-
width: 12,
|
|
708
|
-
height: 12,
|
|
709
|
-
fill: "none",
|
|
710
|
-
stroke: "currentColor",
|
|
711
|
-
strokeWidth: 1.8,
|
|
712
|
-
strokeLinecap: "round",
|
|
713
|
-
strokeLinejoin: "round",
|
|
714
669
|
style: { marginLeft: 4, transition: "transform 150ms ease", transform: open ? "rotate(180deg)" : "none" },
|
|
715
|
-
}
|
|
670
|
+
})
|
|
716
671
|
),
|
|
717
672
|
items: items,
|
|
718
673
|
...(footer ? { footer } : {}),
|
|
@@ -720,18 +675,11 @@ function observePluginUpdate(options) {
|
|
|
720
675
|
);
|
|
721
676
|
}
|
|
722
677
|
function createSpinner() {
|
|
723
|
-
return
|
|
678
|
+
return h(IconLoadingOutline, {
|
|
679
|
+
size: 14,
|
|
724
680
|
className: "ima-btn-spinner",
|
|
725
|
-
viewBox: "0 0 16 16",
|
|
726
|
-
width: 14,
|
|
727
|
-
height: 14,
|
|
728
|
-
fill: "none",
|
|
729
|
-
stroke: "currentColor",
|
|
730
|
-
strokeWidth: 2,
|
|
731
|
-
strokeLinecap: "round",
|
|
732
681
|
style: { marginRight: 6, display: "inline-block", verticalAlign: "-2px", animation: "ima-spin 0.8s linear infinite" },
|
|
733
|
-
|
|
734
|
-
}, React.createElement("path", { d: "M8 1.5a6.5 6.5 0 1 0 6.5 6.5" }));
|
|
682
|
+
});
|
|
735
683
|
}
|
|
736
684
|
function Button({ variant, type, danger, loading, block, size, shape, className, children, href, target, rel, icon, ...props }) {
|
|
737
685
|
let mappedVariant = variant ?? "outline";
|
|
@@ -788,187 +736,8 @@ function observePluginUpdate(options) {
|
|
|
788
736
|
disabled: props.disabled || loading,
|
|
789
737
|
}), content);
|
|
790
738
|
}
|
|
791
|
-
|
|
792
|
-
const StateDot = primitives.StateDot;
|
|
739
|
+
|
|
793
740
|
const IconSettingsOutline16 = pickHostIcon("IconSettingsOutlineRegular", "IconSettingsOutline16");
|
|
794
|
-
const ARCHIVE_MANAGER_PLUGIN = "@michengai/dsh-archive-manager";
|
|
795
|
-
function hasArchiveManagerPlugin(root) {
|
|
796
|
-
return !!(root && typeof root.querySelector === "function" && root.querySelector('[data-plugin="' + ARCHIVE_MANAGER_PLUGIN + '"]'));
|
|
797
|
-
}
|
|
798
|
-
function canDeleteChannelSession(archiveManagerInstalled, deleteSession) {
|
|
799
|
-
return archiveManagerInstalled && typeof deleteSession === "function";
|
|
800
|
-
}
|
|
801
|
-
function canArchiveChannelGroup(archiveManagerInstalled, archiveSession) {
|
|
802
|
-
return archiveManagerInstalled && typeof archiveSession === "function";
|
|
803
|
-
}
|
|
804
|
-
function folderPath(path) {
|
|
805
|
-
return String(path || "").replace(/\\/g, "/").replace(/\/+$/, "");
|
|
806
|
-
}
|
|
807
|
-
function owningParentFolder(path, candidates) {
|
|
808
|
-
const child = folderPath(path);
|
|
809
|
-
let owner;
|
|
810
|
-
let length = -1;
|
|
811
|
-
for (const parent of candidates) {
|
|
812
|
-
const root = folderPath(parent);
|
|
813
|
-
if (root.length > length && child !== root && child.startsWith(root + "/")) {
|
|
814
|
-
owner = parent;
|
|
815
|
-
length = root.length;
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
return owner;
|
|
819
|
-
}
|
|
820
|
-
function workspaceKey(workspace) {
|
|
821
|
-
return workspace.workspaceId || workspace.id || workspace.path || "";
|
|
822
|
-
}
|
|
823
|
-
/** 0.1.7 宿主的按工作区树:子目录挂到路径最长的已打开工作区下面。 */
|
|
824
|
-
function groupChannelSessionsByWorkspaceTree(sessions, workspaces, ungroupedLabel) {
|
|
825
|
-
const bySession = new Map();
|
|
826
|
-
for (const workspace of workspaces || []) {
|
|
827
|
-
for (const sessionId of workspace.sessionIds || []) bySession.set(sessionId, workspace);
|
|
828
|
-
}
|
|
829
|
-
const buckets = new Map();
|
|
830
|
-
const ungrouped = [];
|
|
831
|
-
for (const session of sessions) {
|
|
832
|
-
const workspace = bySession.get(session.sessionId);
|
|
833
|
-
const key = workspace ? workspaceKey(workspace) : "";
|
|
834
|
-
if (!workspace || !key) { ungrouped.push(session); continue; }
|
|
835
|
-
const bucket = buckets.get(key) || [];
|
|
836
|
-
bucket.push(session);
|
|
837
|
-
buckets.set(key, bucket);
|
|
838
|
-
}
|
|
839
|
-
const byPath = new Map();
|
|
840
|
-
for (const workspace of workspaces || []) {
|
|
841
|
-
if (workspace.path) byPath.set(folderPath(workspace.path), workspace);
|
|
842
|
-
}
|
|
843
|
-
const included = new Map();
|
|
844
|
-
for (const workspace of workspaces || []) {
|
|
845
|
-
const key = workspaceKey(workspace);
|
|
846
|
-
if (!key || !buckets.has(key)) continue;
|
|
847
|
-
included.set(key, workspace);
|
|
848
|
-
let path = workspace.path;
|
|
849
|
-
const seen = new Set();
|
|
850
|
-
while (path && !seen.has(path)) {
|
|
851
|
-
seen.add(path);
|
|
852
|
-
const parentPath = owningParentFolder(path, [...byPath.keys()]);
|
|
853
|
-
if (!parentPath) break;
|
|
854
|
-
const parent = byPath.get(folderPath(parentPath));
|
|
855
|
-
const parentKey = parent ? workspaceKey(parent) : "";
|
|
856
|
-
if (!parent || !parentKey) break;
|
|
857
|
-
included.set(parentKey, parent);
|
|
858
|
-
path = parent.path;
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
const present = [...included.values()];
|
|
862
|
-
const paths = present.map((workspace) => workspace.path).filter(Boolean);
|
|
863
|
-
const children = new Map();
|
|
864
|
-
const roots = [];
|
|
865
|
-
for (const workspace of present) {
|
|
866
|
-
const parentPath = workspace.path ? owningParentFolder(workspace.path, paths) : undefined;
|
|
867
|
-
const parent = parentPath ? present.find((item) => item.path && folderPath(item.path) === folderPath(parentPath)) : undefined;
|
|
868
|
-
const parentKey = parent ? workspaceKey(parent) : "";
|
|
869
|
-
if (!parent || !parentKey) roots.push(workspace);
|
|
870
|
-
else {
|
|
871
|
-
const list = children.get(parentKey) || [];
|
|
872
|
-
list.push(workspace);
|
|
873
|
-
children.set(parentKey, list);
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
const byName = (left, right) => String(left.title || left.path || "").localeCompare(String(right.title || right.path || ""));
|
|
877
|
-
const groups = [];
|
|
878
|
-
const walk = (workspace, depth) => {
|
|
879
|
-
const key = workspaceKey(workspace);
|
|
880
|
-
const sessionsInWorkspace = buckets.get(key) || [];
|
|
881
|
-
const channelIds = [...new Set(sessionsInWorkspace.map((session) => session.channelId).filter(Boolean))];
|
|
882
|
-
groups.push({
|
|
883
|
-
id: key,
|
|
884
|
-
label: workspace.title || workspace.path || ungroupedLabel,
|
|
885
|
-
depth,
|
|
886
|
-
keep: sessionsInWorkspace.length === 0,
|
|
887
|
-
channelId: channelIds.length === 1 ? channelIds[0] : "",
|
|
888
|
-
sessions: sessionsInWorkspace,
|
|
889
|
-
});
|
|
890
|
-
for (const child of (children.get(key) || []).slice().sort(byName)) walk(child, depth + 1);
|
|
891
|
-
};
|
|
892
|
-
for (const root of roots.slice().sort(byName)) walk(root, 0);
|
|
893
|
-
if (ungrouped.length) groups.push({ id: "", label: ungroupedLabel, depth: 0, channelId: "", sessions: ungrouped });
|
|
894
|
-
return groups;
|
|
895
|
-
}
|
|
896
|
-
function channelSessionHoverStatuses(input, t) {
|
|
897
|
-
const count = input.runningSubagentCount || 0;
|
|
898
|
-
const subagents = count === 0 ? undefined : { state: "ongoing", label: t("rail.subagents", { n: count, count }) };
|
|
899
|
-
let pending;
|
|
900
|
-
if (input.pendingKind === "approval") pending = { state: "warning", label: t("rail.waitingApproval"), trailing: t("rail.compactApproval") };
|
|
901
|
-
else if (input.pendingKind === "plan-review") pending = { state: "warning", label: t("rail.planReview"), trailing: t("rail.compactPlan") };
|
|
902
|
-
else if (input.pendingKind === "question") pending = { state: "warning", label: t("rail.waitingAnswer"), trailing: t("rail.compactAnswer") };
|
|
903
|
-
let statuses;
|
|
904
|
-
if (pending) statuses = subagents ? [pending, subagents] : [pending];
|
|
905
|
-
else if (input.running) statuses = subagents ? [{ state: "ongoing", label: t("rail.running") }, subagents] : [{ state: "ongoing", label: t("rail.running") }];
|
|
906
|
-
else if (subagents) statuses = [subagents];
|
|
907
|
-
else if (input.completed) statuses = [{ state: "done", label: t("rail.completed") }];
|
|
908
|
-
else statuses = [{ state: "idle", label: t("rail.idle") }];
|
|
909
|
-
const visible = statuses.filter((status) => !(input.archived && (status.state === "done" || status.state === "idle")));
|
|
910
|
-
if (input.archived) visible.push({ state: "archived", label: t("rail.archived") });
|
|
911
|
-
return visible;
|
|
912
|
-
}
|
|
913
|
-
function placeSessionTitle(title, left, range) {
|
|
914
|
-
title.scrollLeft = left;
|
|
915
|
-
if (left > 0) title.dataset.scrolled = "";
|
|
916
|
-
else delete title.dataset.scrolled;
|
|
917
|
-
if (left < range) title.dataset.clipped = "";
|
|
918
|
-
else delete title.dataset.clipped;
|
|
919
|
-
}
|
|
920
|
-
function restSessionTitle(title) {
|
|
921
|
-
title.scrollLeft = 0;
|
|
922
|
-
delete title.dataset.scrolled;
|
|
923
|
-
delete title.dataset.clipped;
|
|
924
|
-
}
|
|
925
|
-
function startSessionTitleMarquee(title, frame) {
|
|
926
|
-
if (!title) return;
|
|
927
|
-
const range = title.scrollWidth - title.clientWidth;
|
|
928
|
-
if (range <= 8) return;
|
|
929
|
-
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
930
|
-
placeSessionTitle(title, range, range);
|
|
931
|
-
return;
|
|
932
|
-
}
|
|
933
|
-
cancelAnimationFrame(frame.id);
|
|
934
|
-
let previous;
|
|
935
|
-
let position = 0;
|
|
936
|
-
const step = (now) => {
|
|
937
|
-
position += previous === undefined ? 0 : (now - previous) * 0.03;
|
|
938
|
-
previous = now;
|
|
939
|
-
placeSessionTitle(title, Math.min(position, range), range);
|
|
940
|
-
if (position < range) frame.id = requestAnimationFrame(step);
|
|
941
|
-
};
|
|
942
|
-
frame.id = requestAnimationFrame(step);
|
|
943
|
-
}
|
|
944
|
-
function stopSessionTitleMarquee(title, frame) {
|
|
945
|
-
cancelAnimationFrame(frame.id);
|
|
946
|
-
if (title) restSessionTitle(title);
|
|
947
|
-
}
|
|
948
|
-
function channelSessionVisible(sessionId, archived, filter) {
|
|
949
|
-
if (!sessionId) return false;
|
|
950
|
-
const isArchived = archived.has(sessionId);
|
|
951
|
-
if (filter === "only") return isArchived;
|
|
952
|
-
if (filter === "show") return true;
|
|
953
|
-
return !isArchived;
|
|
954
|
-
}
|
|
955
|
-
async function archiveChannelGroup(sessionIds, archiveSession, options) {
|
|
956
|
-
for (const sessionId of sessionIds) await archiveSession(sessionId, options);
|
|
957
|
-
}
|
|
958
|
-
function openStopArchive(error, target, open) {
|
|
959
|
-
if (typeof open !== "function" || !activeSessionRefusal(error)) return false;
|
|
960
|
-
open(target);
|
|
961
|
-
return true;
|
|
962
|
-
}
|
|
963
|
-
async function finishStopArchive(target, archiveSession) {
|
|
964
|
-
if (!target || typeof archiveSession !== "function") return "unavailable";
|
|
965
|
-
if (target.sessionIds) {
|
|
966
|
-
await archiveChannelGroup(target.sessionIds, archiveSession, { stopActivity: true });
|
|
967
|
-
return "group";
|
|
968
|
-
}
|
|
969
|
-
await archiveSession(target.id, { stopActivity: true });
|
|
970
|
-
return "session";
|
|
971
|
-
}
|
|
972
741
|
const CHANNEL_SETTINGS_EVENT = "dsh-im-connect:open-channel-settings";
|
|
973
742
|
const CHANNEL_SETTINGS_STORAGE_KEY = "dsh-im-connect:pending-channel-settings";
|
|
974
743
|
const SETTINGS_CODEX_TRIGGER_SELECTOR = "[data-dcu-settings-trigger]";
|
|
@@ -1007,10 +776,19 @@ function observePluginUpdate(options) {
|
|
|
1007
776
|
return { channelId: channel.id, accountId: accounts.length === 1 ? accounts[0].id : undefined };
|
|
1008
777
|
}
|
|
1009
778
|
function pickSettingsSectionButton(buttons, labels) {
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
779
|
+
const normalize = (value) => String(value || "").replace(/\s+/g, "").trim().toLowerCase();
|
|
780
|
+
const labelOf = (button) => normalize(button.textContent) || normalize(button.getAttribute && button.getAttribute("aria-label"));
|
|
781
|
+
const targets = labels.map(normalize).filter(Boolean);
|
|
782
|
+
for (const target of targets) {
|
|
783
|
+
const match = buttons.find((button) => labelOf(button) === target);
|
|
784
|
+
if (match) return match;
|
|
785
|
+
}
|
|
786
|
+
// 宿主可能在标签旁加计数或徽标;退一步做包含匹配。
|
|
787
|
+
for (const target of targets) {
|
|
788
|
+
const match = buttons.find((button) => {
|
|
789
|
+
const text = labelOf(button);
|
|
790
|
+
return text !== "" && (text.includes(target) || target.includes(text));
|
|
791
|
+
});
|
|
1014
792
|
if (match) return match;
|
|
1015
793
|
}
|
|
1016
794
|
return undefined;
|
|
@@ -1022,12 +800,33 @@ function observePluginUpdate(options) {
|
|
|
1022
800
|
});
|
|
1023
801
|
return named || (buttons.length === 1 ? buttons[0] : undefined);
|
|
1024
802
|
}
|
|
803
|
+
function findAccountMenuTrigger() {
|
|
804
|
+
const exact = [
|
|
805
|
+
'button[aria-label="账号菜单"]',
|
|
806
|
+
'button[aria-label="Account menu"]',
|
|
807
|
+
];
|
|
808
|
+
for (const selector of exact) {
|
|
809
|
+
const found = document.querySelector(selector);
|
|
810
|
+
if (found) return found;
|
|
811
|
+
}
|
|
812
|
+
return [...document.querySelectorAll('button[aria-haspopup="menu"]')].find((button) => {
|
|
813
|
+
const label = `${typeof button.getAttribute === "function" ? button.getAttribute("aria-label") || "" : ""} ${button.textContent || ""}`.trim();
|
|
814
|
+
return /账号|account/i.test(label);
|
|
815
|
+
});
|
|
816
|
+
}
|
|
1025
817
|
function requestCodexSettingsSection(labels) {
|
|
1026
818
|
const trigger = typeof document !== "undefined" && document.querySelector(SETTINGS_CODEX_TRIGGER_SELECTOR);
|
|
1027
819
|
if (!trigger) return false;
|
|
1028
820
|
const request = new CustomEvent(SETTINGS_OPEN_SECTION_EVENT, { detail: { labels: [...labels] }, cancelable: true });
|
|
1029
821
|
return !trigger.dispatchEvent(request);
|
|
1030
822
|
}
|
|
823
|
+
function openImSettingsPage(t) {
|
|
824
|
+
openSettingsSection(
|
|
825
|
+
[t("settings.label"), IM_LOCALES.en["settings.label"], IM_LOCALES.zh["settings.label"]],
|
|
826
|
+
() => {},
|
|
827
|
+
() => console.warn("[dsh-im-connect] 无法打开 IM 助理设置页"),
|
|
828
|
+
);
|
|
829
|
+
}
|
|
1031
830
|
function openSettingsSection(labels, onSelected, onMissing) {
|
|
1032
831
|
if (typeof document === "undefined" || typeof window === "undefined") {
|
|
1033
832
|
if (onMissing) onMissing();
|
|
@@ -1037,18 +836,27 @@ function observePluginUpdate(options) {
|
|
|
1037
836
|
if (onSelected) onSelected();
|
|
1038
837
|
return;
|
|
1039
838
|
}
|
|
1040
|
-
const launchers = [...document.querySelectorAll('button[aria-haspopup="dialog"]')];
|
|
1041
|
-
const
|
|
839
|
+
const launchers = [...document.querySelectorAll('button[aria-haspopup="dialog"], button[aria-label*="设置"], button[aria-label*="Settings"], [data-dcu-settings-trigger]')];
|
|
840
|
+
const namedSettingsButton = [...document.querySelectorAll("button")].find((button) => /^(设置|settings)$/i.test((button.getAttribute("aria-label") || "").trim()));
|
|
841
|
+
const launcher = namedSettingsButton || pickSettingsLauncher(launchers);
|
|
1042
842
|
const pageTrigger = document.querySelector(SETTINGS_CODEX_TRIGGER_SELECTOR);
|
|
1043
843
|
const dialogOpen = document.querySelector('[role="dialog"]') !== null;
|
|
1044
844
|
const pageOpen = document.querySelector(SETTINGS_CODEX_PAGE_SELECTOR) !== null;
|
|
845
|
+
let menuTrigger;
|
|
1045
846
|
if (!dialogOpen && !pageOpen && !launcher && !pageTrigger) {
|
|
1046
|
-
|
|
1047
|
-
|
|
847
|
+
menuTrigger = findAccountMenuTrigger();
|
|
848
|
+
if (!menuTrigger) {
|
|
849
|
+
if (onMissing) onMissing();
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
menuTrigger.click();
|
|
853
|
+
} else if (!dialogOpen && !pageOpen) {
|
|
854
|
+
(pageTrigger || launcher).click();
|
|
1048
855
|
}
|
|
1049
|
-
if (!dialogOpen && !pageOpen) (pageTrigger || launcher).click();
|
|
1050
856
|
let frame;
|
|
1051
857
|
let finished = false;
|
|
858
|
+
let menuActivated = false;
|
|
859
|
+
let timeout;
|
|
1052
860
|
const observer = new MutationObserver(() => { schedule(); });
|
|
1053
861
|
const cleanup = () => {
|
|
1054
862
|
if (finished) return;
|
|
@@ -1057,10 +865,29 @@ function observePluginUpdate(options) {
|
|
|
1057
865
|
window.clearTimeout(timeout);
|
|
1058
866
|
if (frame !== undefined) window.cancelAnimationFrame(frame);
|
|
1059
867
|
};
|
|
868
|
+
const wait = () => {
|
|
869
|
+
timeout = window.setTimeout(() => {
|
|
870
|
+
if (select()) return;
|
|
871
|
+
cleanup();
|
|
872
|
+
if (onMissing) onMissing();
|
|
873
|
+
}, 5000);
|
|
874
|
+
};
|
|
1060
875
|
const select = () => {
|
|
876
|
+
if (menuTrigger !== undefined && !menuActivated) {
|
|
877
|
+
const items = [...document.querySelectorAll('[role="menuitem"], [role="menu"] button')];
|
|
878
|
+
const entry = pickSettingsSectionButton(items, ["设置", "Settings"]);
|
|
879
|
+
if (!entry) return false;
|
|
880
|
+
menuActivated = true;
|
|
881
|
+
window.clearTimeout(timeout);
|
|
882
|
+
wait();
|
|
883
|
+
entry.click();
|
|
884
|
+
schedule();
|
|
885
|
+
return true;
|
|
886
|
+
}
|
|
1061
887
|
const buttons = [
|
|
1062
|
-
...document.querySelectorAll('[role="dialog"] nav button'),
|
|
888
|
+
...document.querySelectorAll('[role="dialog"] nav button, [role="dialog"] button'),
|
|
1063
889
|
...document.querySelectorAll(SETTINGS_CODEX_PAGE_SELECTOR + " nav button"),
|
|
890
|
+
...document.querySelectorAll("nav button, button"),
|
|
1064
891
|
];
|
|
1065
892
|
const target = pickSettingsSectionButton(buttons, labels);
|
|
1066
893
|
if (!target) return false;
|
|
@@ -1073,44 +900,25 @@ function observePluginUpdate(options) {
|
|
|
1073
900
|
if (finished || frame !== undefined) return;
|
|
1074
901
|
frame = window.requestAnimationFrame(() => { frame = undefined; select(); });
|
|
1075
902
|
};
|
|
1076
|
-
|
|
1077
|
-
if (select()) return;
|
|
1078
|
-
cleanup();
|
|
1079
|
-
if (onMissing) onMissing();
|
|
1080
|
-
}, 1500);
|
|
903
|
+
wait();
|
|
1081
904
|
observer.observe(document.body, { childList: true, subtree: true });
|
|
1082
905
|
schedule();
|
|
1083
906
|
}
|
|
1084
907
|
const EMPTY_EXTRA_TABS = [];
|
|
1085
908
|
const inject = ["slots", "sessions", "workspaces", "locale"];
|
|
1086
909
|
const API_BASE = "/api/dsh-im-connect";
|
|
1087
|
-
const TAB_KEY = "dsh-
|
|
910
|
+
const TAB_KEY = "dsh-native-sidebar.tab";
|
|
1088
911
|
const ACCOUNT_SELECTION_KEY = "dsh-im-connect.settings.selected-account";
|
|
1089
912
|
const IM_LOCALE_NS = "im-connect";
|
|
1090
|
-
const
|
|
1091
|
-
refresh:
|
|
1092
|
-
download:
|
|
1093
|
-
copy:
|
|
1094
|
-
close:
|
|
913
|
+
const UPDATE_ICONS = {
|
|
914
|
+
refresh: IconRefreshOutline,
|
|
915
|
+
download: IconDownloadOutline,
|
|
916
|
+
copy: IconCopyOutline,
|
|
917
|
+
close: IconCloseFill,
|
|
1095
918
|
};
|
|
1096
919
|
function createPluginUpdateIcon(name) {
|
|
1097
920
|
const element = document.createElement("span");
|
|
1098
|
-
|
|
1099
|
-
svg.setAttribute("viewBox", "0 0 16 16");
|
|
1100
|
-
svg.setAttribute("width", "16");
|
|
1101
|
-
svg.setAttribute("height", "16");
|
|
1102
|
-
svg.setAttribute("fill", "none");
|
|
1103
|
-
svg.setAttribute("stroke", "currentColor");
|
|
1104
|
-
svg.setAttribute("stroke-width", "1.5");
|
|
1105
|
-
svg.setAttribute("stroke-linecap", "round");
|
|
1106
|
-
svg.setAttribute("stroke-linejoin", "round");
|
|
1107
|
-
svg.setAttribute("aria-hidden", "true");
|
|
1108
|
-
UPDATE_ICON_PATHS[name].forEach((d) => {
|
|
1109
|
-
const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
|
|
1110
|
-
path.setAttribute("d", d);
|
|
1111
|
-
svg.append(path);
|
|
1112
|
-
});
|
|
1113
|
-
element.append(svg);
|
|
921
|
+
element.innerHTML = channelMarkup(h(UPDATE_ICONS[name] || IconRefreshOutline, { size: 16 }));
|
|
1114
922
|
return element;
|
|
1115
923
|
}
|
|
1116
924
|
const IM_LOCALES = {
|
|
@@ -1135,9 +943,9 @@ function observePluginUpdate(options) {
|
|
|
1135
943
|
"qr.weixin": "请使用微信扫描二维码完成绑定", "qr.feishu": "请使用飞书扫描二维码,将自动创建机器人", "qr.lark": "请使用 Lark 扫描二维码完成配对", "qr.wecom": "请使用企业微信扫描二维码,快捷绑定机器人", "qr.dingtalk": "请使用钉钉扫描二维码,自动创建机器人", "qr.qq": "请使用手机 QQ 扫描二维码,创建开放平台机器人", "qr.default": "请使用对应 App 扫描二维码",
|
|
1136
944
|
"status.connected": "已连接", "action.more": "{channel} 更多",
|
|
1137
945
|
"error.loadAssistant": "无法加载账号配置", "error.noModels": "当前 Host 还没有可用模型,请先在网页里配置提供商", "error.save": "保存失败", "error.chooseWorkspace": "请选择工作区目录", "error.workspaceUnavailable": "当前 Host 无法新增工作区", "error.addWorkspace": "新增工作区失败", "error.load": "加载失败", "error.connection": "无法连接本机 IM 助理接口", "error.request": "请求失败", "error.action": "操作失败", "error.qr": "无法生成二维码", "error.detailsInLog": "操作失败,请查看服务器日志。",
|
|
1138
|
-
"composer.noWorkspaces": "暂无工作区", "composer.addWorkspace": "添加工作区…", "composer.workspaceRequired": "请先添加工作区,否则无法保存", "composer.permission": "权限", "composer.noModels": "暂无模型", "action.cancel": "取消",
|
|
946
|
+
"composer.noWorkspaces": "暂无工作区", "composer.addWorkspace": "添加工作区…", "composer.workspaceRequired": "请先添加工作区,否则无法保存", "composer.permission": "权限", "composer.noModels": "暂无模型", "action.cancel": "取消",
|
|
1139
947
|
"permission.readOnly": "只读", "permission.workspaceWrite": "工作区写入", "permission.fullAccess": "完全访问",
|
|
1140
|
-
"rail.workspace": "工作区", "rail.sessions": "会话", "rail.search": "搜索", "rail.searchPlaceholder": "搜索会话...", "rail.clearSearch": "清除搜索", "rail.filter": "筛选", "rail.group": "分组方式", "rail.byWorkspace": "按工作区", "rail.list": "单列表", "rail.byWorkspaceTree": "按工作区树", "rail.sort": "排序方式", "rail.recent": "最近更新", "rail.showArchived": "显示已归档", "rail.onlyArchived": "仅显示已归档", "rail.running": "运行中", "rail.idle": "空闲", "rail.waitingApproval": "等待审批", "rail.planReview": "计划待审", "rail.waitingAnswer": "等待回答", "rail.subagents": "{n} 个子代理运行中", "rail.completed": "已完成", "rail.archived": "已归档", "rail.compactApproval": "待审批", "rail.compactPlan": "计划待审", "rail.compactAnswer": "待回答", "rail.renameAria": "重命名会话", "rail.rename": "重命名", "rail.fork": "分叉会话", "rail.archive": "归档会话", "rail.unarchive": "恢复会话", "rail.
|
|
948
|
+
"rail.workspace": "工作区", "rail.sessions": "会话", "rail.search": "搜索", "rail.searchPlaceholder": "搜索会话...", "rail.clearSearch": "清除搜索", "rail.filter": "筛选", "rail.group": "分组方式", "rail.byWorkspace": "按工作区", "rail.list": "单列表", "rail.byWorkspaceTree": "按工作区树", "rail.byChannel": "按频道", "rail.treeUnavailable": "当前宿主未提供官方任务树。", "rail.groupReadOnly": "频道分组不能在这里重命名或删除。", "rail.sort": "排序方式", "rail.recent": "最近更新", "rail.showArchived": "显示已归档", "rail.onlyArchived": "仅显示已归档", "rail.running": "运行中", "rail.idle": "空闲", "rail.waitingApproval": "等待审批", "rail.planReview": "计划待审", "rail.waitingAnswer": "等待回答", "rail.subagents": "{n} 个子代理运行中", "rail.completed": "已完成", "rail.archived": "已归档", "rail.compactApproval": "待审批", "rail.compactPlan": "计划待审", "rail.compactAnswer": "待回答", "rail.renameAria": "重命名会话", "rail.rename": "重命名", "rail.fork": "分叉会话", "rail.archive": "归档会话", "rail.unarchive": "恢复会话", "rail.deleteSession": "删除会话", "rail.deleteSessionConfirm": "删除会话", "rail.deleteSessionDescription": "将永久删除会话“{name}”及其子代理(含正在运行的)和全部记录(对话内容、统计、缓存),此操作不可恢复。", "rail.deleteSessionPending": "正在删除会话…", "rail.deleteSessionFailed": "删除会话失败:{message}", "rail.deleteSessionClose": "关闭", "rail.deleteSessionCancel": "取消", "rail.groupActions": "“{name}”的频道操作", "rail.channelSettings": "频道设置", "rail.addChannel": "添加频道", "rail.empty": "还没有频道会话。先在设置 → IM助理 里连接渠道,并给机器人发一条消息。", "rail.ungrouped": "未分组", "rail.tabsAria": "工作区分类", "rail.tasks": "任务", "rail.channels": "频道",
|
|
1141
949
|
"time.now": "刚刚", "time.minutes": "{n}分钟", "time.hours": "{n}小时", "time.days": "{n}天", "time.months": "{n}个月", "time.years": "{n}年", "time.ago": "{t}前",
|
|
1142
950
|
"copy": "复制", "hover.copied": "已复制",
|
|
1143
951
|
"server.unknownChannel": "未知渠道", "server.channelUnconfigured": "渠道未配置", "server.sessionMissing": "会话不存在", "server.accountMissing": "账号不存在", "server.accountConnectFailed": "账号连接失败,请查看本机日志", "server.accountReconnectFailed": "重新连接失败,请查看本机日志", "server.selectAccountSettings": "请选择提供商、模型、工作区或权限", "server.selectModel": "请选择提供商和模型", "server.selectWorkspace": "请选择工作区", "server.createWorkspace": "请先添加工作区", "server.selectPermission": "请选择权限", "server.missingCredentials": "凭据不足,无法启动渠道", "server.qrUnsupported": "该渠道不支持扫码绑定", "server.qrExpired": "二维码已过期", "server.qrIncomplete": "扫码未完成", "server.accessDenied": "未授权:请管理员在设置 → IM助理 中批准你的访问。", "server.remarkTooLong": "账号备注不能超过 40 个字符", "server.remarkControl": "账号备注不能包含换行或控制字符",
|
|
@@ -1164,9 +972,9 @@ function observePluginUpdate(options) {
|
|
|
1164
972
|
"qr.weixin": "Scan the QR code with WeChat to connect", "qr.feishu": "Scan with Feishu; a bot will be created automatically", "qr.lark": "Scan with Lark to pair", "qr.wecom": "Scan with WeCom to quickly connect a bot", "qr.dingtalk": "Scan with DingTalk; a bot will be created automatically", "qr.qq": "Scan with mobile QQ to create an Open Platform bot", "qr.default": "Scan the QR code with the corresponding app",
|
|
1165
973
|
"status.connected": "Connected", "action.more": "More options for {channel}",
|
|
1166
974
|
"error.loadAssistant": "Could not load account settings", "error.noModels": "No models are available in the Host. Configure a provider in the web app first.", "error.save": "Could not save", "error.chooseWorkspace": "Choose a workspace directory", "error.workspaceUnavailable": "This Host cannot create workspaces", "error.addWorkspace": "Could not add workspace", "error.load": "Could not load", "error.connection": "Could not connect to the local IM Assistant API", "error.request": "Request failed", "error.action": "Action failed", "error.qr": "Could not generate a QR code", "error.detailsInLog": "The operation failed. Check the server logs for details.",
|
|
1167
|
-
"composer.noWorkspaces": "No workspaces", "composer.addWorkspace": "Add workspace…", "composer.workspaceRequired": "Add a workspace before saving.", "composer.permission": "Permission", "composer.noModels": "No models", "action.cancel": "Cancel",
|
|
975
|
+
"composer.noWorkspaces": "No workspaces", "composer.addWorkspace": "Add workspace…", "composer.workspaceRequired": "Add a workspace before saving.", "composer.permission": "Permission", "composer.noModels": "No models", "action.cancel": "Cancel",
|
|
1168
976
|
"permission.readOnly": "Read Only", "permission.workspaceWrite": "Workspace Write", "permission.fullAccess": "Full access",
|
|
1169
|
-
"rail.workspace": "Workspaces", "rail.sessions": "Sessions", "rail.search": "Search", "rail.searchPlaceholder": "Search sessions...", "rail.clearSearch": "Clear search", "rail.filter": "Filter", "rail.group": "Group by", "rail.byWorkspace": "By workspace", "rail.list": "Single list", "rail.byWorkspaceTree": "Workspace Tree", "rail.sort": "Sort by", "rail.recent": "Recently updated", "rail.showArchived": "Show archived", "rail.onlyArchived": "Archived only", "rail.running": "Running", "rail.idle": "Idle", "rail.waitingApproval": "Waiting for approval", "rail.planReview": "Plan to review", "rail.waitingAnswer": "Waiting for an answer", "rail.subagents": "{n} subagents running", "rail.completed": "Completed", "rail.archived": "Archived", "rail.compactApproval": "Approval", "rail.compactPlan": "Plan review", "rail.compactAnswer": "Answer", "rail.renameAria": "Rename session", "rail.rename": "Rename", "rail.fork": "Fork session", "rail.archive": "Archive session", "rail.unarchive": "Restore session", "rail.
|
|
977
|
+
"rail.workspace": "Workspaces", "rail.sessions": "Sessions", "rail.search": "Search", "rail.searchPlaceholder": "Search sessions...", "rail.clearSearch": "Clear search", "rail.filter": "Filter", "rail.group": "Group by", "rail.byWorkspace": "By workspace", "rail.list": "Single list", "rail.byWorkspaceTree": "Workspace Tree", "rail.byChannel": "By channel", "rail.treeUnavailable": "The official tree is unavailable in this Host.", "rail.groupReadOnly": "Channel groups cannot be renamed or deleted here.", "rail.sort": "Sort by", "rail.recent": "Recently updated", "rail.showArchived": "Show archived", "rail.onlyArchived": "Archived only", "rail.running": "Running", "rail.idle": "Idle", "rail.waitingApproval": "Waiting for approval", "rail.planReview": "Plan to review", "rail.waitingAnswer": "Waiting for an answer", "rail.subagents": "{n} subagents running", "rail.completed": "Completed", "rail.archived": "Archived", "rail.compactApproval": "Approval", "rail.compactPlan": "Plan review", "rail.compactAnswer": "Answer", "rail.renameAria": "Rename session", "rail.rename": "Rename", "rail.fork": "Fork session", "rail.archive": "Archive session", "rail.unarchive": "Restore session", "rail.deleteSession": "Delete session", "rail.deleteSessionConfirm": "Delete session", "rail.deleteSessionDescription": "This permanently deletes session “{name}”, its child agents (including any that are still running), and all of its records (conversation, stats, cache). This cannot be undone.", "rail.deleteSessionPending": "Deleting session…", "rail.deleteSessionFailed": "Could not delete the session: {message}", "rail.deleteSessionClose": "Close", "rail.deleteSessionCancel": "Cancel", "rail.groupActions": "Actions for {name}", "rail.channelSettings": "Channel settings", "rail.addChannel": "Add channel", "rail.empty": "No channel sessions yet. Connect a channel in Settings → IM Assistant, then send the bot a message.", "rail.ungrouped": "Ungrouped", "rail.tabsAria": "Workspace categories", "rail.tasks": "Tasks", "rail.channels": "Channels",
|
|
1170
978
|
"time.now": "now", "time.minutes": "{n}min", "time.hours": "{n}h", "time.days": "{n}d", "time.months": "{n}mo", "time.years": "{n}y", "time.ago": "{t} ago",
|
|
1171
979
|
"copy": "Copy", "hover.copied": "Copied",
|
|
1172
980
|
"server.unknownChannel": "Unknown channel", "server.channelUnconfigured": "Channel is not configured", "server.sessionMissing": "Session does not exist", "server.accountMissing": "Account does not exist", "server.accountConnectFailed": "Could not connect the account. Check the local logs.", "server.accountReconnectFailed": "Could not reconnect the account. Check the local logs.", "server.selectAccountSettings": "Select a provider, model, workspace, or permission setting", "server.selectModel": "Select a provider and model", "server.selectWorkspace": "Select a workspace", "server.createWorkspace": "Add a workspace first.", "server.selectPermission": "Select a permission", "server.missingCredentials": "The channel cannot start because credentials are missing", "server.qrUnsupported": "This channel does not support QR setup", "server.qrExpired": "QR code has expired", "server.qrIncomplete": "QR setup was not completed", "server.accessDenied": "Access denied: ask an administrator to approve you in Settings → IM Assistant.", "server.remarkTooLong": "Account remark cannot exceed 40 characters", "server.remarkControl": "Account remark cannot contain line breaks or control characters",
|
|
@@ -1175,32 +983,6 @@ function observePluginUpdate(options) {
|
|
|
1175
983
|
};
|
|
1176
984
|
const fallbackT = (key) => key;
|
|
1177
985
|
const h = React.createElement;
|
|
1178
|
-
function currentUiLang() {
|
|
1179
|
-
try {
|
|
1180
|
-
if (typeof document !== "undefined" && document.documentElement && document.documentElement.lang) {
|
|
1181
|
-
if (/^en/i.test(document.documentElement.lang)) return "en";
|
|
1182
|
-
if (/^zh/i.test(document.documentElement.lang)) return "zh";
|
|
1183
|
-
}
|
|
1184
|
-
} catch { /* ignore */ }
|
|
1185
|
-
return "zh";
|
|
1186
|
-
}
|
|
1187
|
-
function hostIsDark() {
|
|
1188
|
-
if (typeof document === "undefined") return false;
|
|
1189
|
-
return document.documentElement.hasAttribute("data-ds-dark-theme")
|
|
1190
|
-
|| (document.body && document.body.hasAttribute("data-ds-dark-theme") === true);
|
|
1191
|
-
}
|
|
1192
|
-
function useHostDark() {
|
|
1193
|
-
const [dark, setDark] = useState(hostIsDark);
|
|
1194
|
-
useEffect(() => {
|
|
1195
|
-
const update = () => setDark(hostIsDark());
|
|
1196
|
-
update();
|
|
1197
|
-
const observer = new MutationObserver(update);
|
|
1198
|
-
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["data-ds-dark-theme"] });
|
|
1199
|
-
if (document.body) observer.observe(document.body, { attributes: true, attributeFilter: ["data-ds-dark-theme"] });
|
|
1200
|
-
return () => observer.disconnect();
|
|
1201
|
-
}, []);
|
|
1202
|
-
return dark;
|
|
1203
|
-
}
|
|
1204
986
|
function HostThemeProvider({ children }) {
|
|
1205
987
|
return children;
|
|
1206
988
|
}
|
|
@@ -1214,7 +996,7 @@ function observePluginUpdate(options) {
|
|
|
1214
996
|
.ima-title-links{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
|
|
1215
997
|
.ima-title-links>span[data-mpi-check]{display:inline-flex;align-items:center}
|
|
1216
998
|
[data-ima-nav-icon="assistant"]>svg{display:none!important}
|
|
1217
|
-
.ima-nav-icon-assistant{
|
|
999
|
+
.ima-nav-icon-assistant{display:inline-block;flex:none;width:16px;height:16px;background:currentColor;-webkit-mask:var(--ima-nav-icon-mask) center/contain no-repeat;mask:var(--ima-nav-icon-mask) center/contain no-repeat}
|
|
1218
1000
|
.ima-btn{display:inline-flex;align-items:center;justify-content:center;gap:4px;height:32px;padding:0 12px;border:0.5px solid var(--dsw-alias-border-l3,#555);border-radius:var(--dsw-radius-sm,8px);background:transparent;color:var(--dsw-alias-label-primary,#eee);font:inherit;font-size:13px;line-height:20px;cursor:pointer;user-select:none;box-sizing:border-box;text-decoration:none;transition:border-color 120ms ease,color 120ms ease,background 120ms ease}
|
|
1219
1001
|
.ima-btn:not(.is-primary):not(.ima-btn-danger){color:var(--dsw-alias-label-primary,#eee)!important}
|
|
1220
1002
|
.ima-btn:hover:not(:disabled):not(.ima-btn-danger){border-color:var(--dsw-alias-border-l3,#666)!important;color:var(--dsw-alias-label-primary,#fff)!important;background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06))!important}
|
|
@@ -1244,14 +1026,14 @@ function observePluginUpdate(options) {
|
|
|
1244
1026
|
.ima-feedback-title{font-weight:550;line-height:20px}
|
|
1245
1027
|
.ima-pending-list{display:flex;flex-direction:column;gap:6px;width:100%}
|
|
1246
1028
|
.ima-pending-row{display:flex;gap:8px;align-items:center;padding:4px 0}
|
|
1247
|
-
.ima-wrap{display:flex;flex-direction:column;min-height:0;flex:1;height:100%;overflow:hidden}.ima-official-tree{flex:1;min-height:0;display:flex;flex-direction:column;overflow:hidden}
|
|
1029
|
+
.ima-wrap{display:flex;flex-direction:column;min-height:0;flex:1;height:100%;overflow:hidden}.ima-official-tree{flex:1;min-height:0;display:flex;flex-direction:column;overflow:hidden}
|
|
1248
1030
|
.ima-tabs-wrap{display:flex;margin:2px var(--dsh-sidebar-inline-padding,12px) 8px 0;padding:0;width:auto}
|
|
1249
|
-
.ima-tabs-wrap .ima-segmented-tabs{width:100
|
|
1250
|
-
.ima-tabs-wrap .ima-segmented-tabs>span{inset:2px auto 2px 2px!important;width:calc((100% - 4px)/var(--ima-tab-count,2))!important;border-radius:6px!important;border:0.5px solid var(--dsw-alias-border-
|
|
1251
|
-
.ima-tabs-wrap .ima-segmented-tabs [role=tab]{display:inline-flex!important;align-items:center!important;justify-content:center!important;gap:
|
|
1031
|
+
.ima-tabs-wrap .ima-segmented-tabs{display:grid!important;width:100%!important;box-sizing:border-box!important;height:32px!important;min-height:32px!important;max-height:32px!important;padding:2px!important;border:0!important;border-radius:var(--dsw-radius-sm,8px)!important;box-shadow:inset 0 0 0 .5px var(--dsw-alias-border-l2,rgba(255,255,255,.08))!important;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.02))!important}
|
|
1032
|
+
.ima-tabs-wrap .ima-segmented-tabs>span{inset:2px auto 2px 2px!important;width:calc((100% - 4px)/var(--ima-tab-count,2))!important;border-radius:6px!important;border:0.5px solid var(--dsw-alias-border-l3,rgba(255,255,255,.12))!important;background:var(--dsw-alias-bg-layer-3,rgba(255,255,255,.08))!important;box-shadow:none!important}
|
|
1033
|
+
.ima-tabs-wrap .ima-segmented-tabs [role=tab]{display:inline-flex!important;align-items:center!important;justify-content:center!important;gap:6px!important;height:28px!important;padding:0 clamp(6px,calc(100% - 60px),12px)!important;font-size:13px!important;line-height:20px!important;border-radius:6px!important;color:var(--dsw-alias-label-secondary,#8b8f98)!important;text-align:center!important;white-space:nowrap!important;box-sizing:border-box!important;transition:color 150ms ease!important}
|
|
1252
1034
|
.ima-tabs-wrap .ima-segmented-tabs [role=tab]>*{display:inline-flex!important;align-items:center!important;justify-content:center!important}
|
|
1253
|
-
.ima-tabs-wrap .ima-segmented-tabs [role=tab]:hover{color:var(--dsw-alias-label-primary,inherit)}
|
|
1254
|
-
.ima-tabs-wrap .ima-segmented-tabs [role=tab][aria-selected=true]{color:var(--dsw-alias-label-primary,inherit)!important;font-weight:600}
|
|
1035
|
+
.ima-tabs-wrap .ima-segmented-tabs [role=tab]:hover{color:var(--dsw-alias-label-primary,inherit)!important}
|
|
1036
|
+
.ima-tabs-wrap .ima-segmented-tabs [role=tab][aria-selected=true]{color:var(--dsw-alias-label-primary,inherit)!important;font-weight:600!important}
|
|
1255
1037
|
.ima-bind-tabs-wrap{width:100%;margin:0 0 16px}
|
|
1256
1038
|
.ima-bind-tabs-wrap.is-disabled{opacity:.6;pointer-events:none}
|
|
1257
1039
|
.ima-bind-panel[hidden]{display:none!important}
|
|
@@ -1265,12 +1047,20 @@ function observePluginUpdate(options) {
|
|
|
1265
1047
|
.ima-tab{appearance:none;border:0;background:transparent;color:var(--ima-muted);padding:8px 0;font-size:13px;cursor:pointer}
|
|
1266
1048
|
.ima-tab.on{color:var(--ima-text);box-shadow:inset 0 -2px 0 currentColor}
|
|
1267
1049
|
.ima-tabs{flex:none}
|
|
1268
|
-
.ima-rail{flex:1 1 auto;min-height:180px;overflow:auto}
|
|
1269
|
-
.ima-rename{flex:1;min-width:0;min-height:28px;padding:2px 8px;border-radius:6px;border:1px solid var(--ima-line);background:var(--dsw-alias-bg-layer-3,var(--dsw-alias-button-elevated-fill,transparent));color:var(--ima-text);font-size:13px}
|
|
1270
1050
|
.ima-empty{color:var(--ima-muted);font-size:12px;padding:12px 8px}
|
|
1051
|
+
.ima-channel-official{display:flex;flex-direction:column;flex:1;min-width:0;min-height:0;overflow:hidden}
|
|
1052
|
+
.ima-channel-official>div{flex:1;min-width:0;min-height:0}
|
|
1053
|
+
.ima-channel-official>.ima-channel-error{flex:none}
|
|
1054
|
+
.ima-channel-official>.ima-channel-unavailable{flex:1}
|
|
1055
|
+
.ima-channel-error{padding:8px 12px;color:var(--dsw-alias-state-error-primary,#f85149);font-size:12px;line-height:18px}
|
|
1056
|
+
.ima-channel-unavailable{padding:16px 12px;color:var(--dsw-alias-label-tertiary,#8b8f98);font-size:13px;line-height:20px}
|
|
1057
|
+
.ima-session-channel-icon{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;flex:none}
|
|
1058
|
+
/* 频道页签复用官方工作区浏览器:分组头操作按模式裁剪。 */
|
|
1059
|
+
.ima-channel-official[data-mode="channel"] [data-row-key^="workspace:dsh-im-channel:"]>span:last-child>:last-child{display:none!important}
|
|
1060
|
+
.ima-channel-official[data-mode="workspace"] [data-row-key^="workspace:"]>span:last-child,
|
|
1061
|
+
.ima-channel-official[data-mode="workspace-tree"] [data-row-key^="workspace:"]>span:last-child{display:none!important}
|
|
1271
1062
|
.ima-logo{width:28px;height:28px;flex:none;display:block;line-height:0;background:transparent}
|
|
1272
1063
|
.ima-logo svg{width:28px;height:28px;display:block}
|
|
1273
|
-
.ima-logo img.ima-brand-file{width:100%;height:100%;display:block;object-fit:contain;pointer-events:none}
|
|
1274
1064
|
.ima-logo.sm{width:16px;height:16px;overflow:hidden;display:grid;place-items:center}
|
|
1275
1065
|
.ima-logo.sm svg{width:16px;height:16px;transform:none}
|
|
1276
1066
|
.ima-logo[data-brand="wecom"]{border-radius:6px;box-shadow:inset 0 0 0 1px rgba(15,23,42,.12);overflow:hidden;background:#fff}
|
|
@@ -1281,11 +1071,11 @@ function observePluginUpdate(options) {
|
|
|
1281
1071
|
.ima-hint{margin:0;color:var(--ima-muted);font-size:13px;text-align:center;line-height:1.6}
|
|
1282
1072
|
.ima-field{display:flex;flex-direction:column;gap:6px;margin-bottom:12px;font-size:13px}
|
|
1283
1073
|
.ima-field .ima-input,.ima-field input{width:100%}
|
|
1284
|
-
.ima-input,.ima-account-remark-input,.ima-field input
|
|
1074
|
+
.ima-input,.ima-account-remark-input,.ima-field input{box-sizing:border-box!important;height:36px!important;padding:0 12px!important;border:0.5px solid var(--dsw-alias-border-l2,#494949)!important;border-radius:var(--dsw-radius-sm,8px)!important;background:var(--dsw-alias-bg-layer-1,transparent)!important;color:var(--dsw-alias-label-primary,#eee)!important;font:inherit!important;font-size:13px!important;line-height:20px!important;transition:border-color 120ms ease,background 120ms ease!important}
|
|
1285
1075
|
.ima-textarea{height:auto!important;min-height:80px;padding:8px 12px!important;resize:vertical}
|
|
1286
|
-
.ima-input:hover:not(:disabled),.ima-account-remark-input:hover:not(:disabled),.ima-field input:hover:not(:disabled)
|
|
1287
|
-
.ima-input:focus,.ima-account-remark-input:focus,.ima-field input:focus
|
|
1288
|
-
.ima-input::placeholder,.ima-account-remark-input::placeholder,.ima-field input::placeholder
|
|
1076
|
+
.ima-input:hover:not(:disabled),.ima-account-remark-input:hover:not(:disabled),.ima-field input:hover:not(:disabled){border-color:var(--dsw-alias-border-l3,#666)!important}
|
|
1077
|
+
.ima-input:focus,.ima-account-remark-input:focus,.ima-field input:focus{border-color:var(--dsw-alias-brand-primary,#4b7cff)!important;outline:var(--dsw-focus-ring-width,1px) solid var(--dsw-focus-ring-color,var(--dsw-alias-brand-primary,#4b7cff))!important;outline-offset:0!important}
|
|
1078
|
+
.ima-input::placeholder,.ima-account-remark-input::placeholder,.ima-field input::placeholder{color:var(--dsw-alias-label-tertiary,#888)!important}
|
|
1289
1079
|
.ima-input:disabled,.ima-account-remark-input:disabled{opacity:.5!important;cursor:not-allowed!important}
|
|
1290
1080
|
.ima-checkbox-label{display:inline-flex;align-items:center;gap:8px;font-size:13px;color:var(--dsw-alias-label-primary,#eee);cursor:pointer;user-select:none}
|
|
1291
1081
|
.ima-checkbox-label.is-disabled{opacity:.5;cursor:not-allowed}
|
|
@@ -1309,7 +1099,7 @@ function observePluginUpdate(options) {
|
|
|
1309
1099
|
.ima-modal-footer-wrap{display:flex;justify-content:flex-end;margin-top:12px;padding-top:16px}
|
|
1310
1100
|
.ima-inspector-actions>button{flex:none;white-space:nowrap}
|
|
1311
1101
|
.ima-confirm-content{margin:8px 0 0;font-size:13px;line-height:22px;color:var(--dsw-alias-label-secondary,#b9b9b9)}
|
|
1312
|
-
.ima-page.ima-account-page{container-type:inline-size;min-width:0;
|
|
1102
|
+
.ima-page.ima-account-page{container-type:inline-size;min-width:0;width:100%;padding:0 0 32px}
|
|
1313
1103
|
.ima-account-shell,.ima-account-shell *{box-sizing:border-box}
|
|
1314
1104
|
.ima-account-shell{display:block;min-height:0;border:0;border-radius:0;overflow:visible;background:transparent}
|
|
1315
1105
|
.ima-platforms{display:flex;flex-direction:column;gap:12px;padding:0;border:0;background:transparent;min-width:0}
|
|
@@ -1390,15 +1180,45 @@ function observePluginUpdate(options) {
|
|
|
1390
1180
|
document.head.appendChild(styleEl);
|
|
1391
1181
|
};
|
|
1392
1182
|
|
|
1183
|
+
let requestHostSessionRefresh = () => {};
|
|
1393
1184
|
let channelSessionIds = new Set();
|
|
1185
|
+
let channelSessionChannels = new Map();
|
|
1394
1186
|
let channelMembershipRevision = 0;
|
|
1395
1187
|
const channelMembershipListeners = new Set();
|
|
1396
1188
|
function updateChannelMembership(groups) {
|
|
1397
|
-
const next = new Set(
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1189
|
+
const next = new Set();
|
|
1190
|
+
const channels = new Map();
|
|
1191
|
+
for (const group of groups) {
|
|
1192
|
+
for (const session of group.sessions || []) {
|
|
1193
|
+
next.add(session.sessionId);
|
|
1194
|
+
channels.set(String(session.sessionId), group.id);
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
let changed = next.size !== channelSessionIds.size || [...next].some(id => !channelSessionIds.has(id));
|
|
1198
|
+
if (!changed) {
|
|
1199
|
+
for (const [id, channel] of channels) {
|
|
1200
|
+
if (channelSessionChannels.get(id) !== channel) { changed = true; break; }
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
if (changed) {
|
|
1204
|
+
channelSessionIds = next;
|
|
1205
|
+
channelSessionChannels = channels;
|
|
1206
|
+
channelMembershipRevision += 1;
|
|
1207
|
+
for (const listener of channelMembershipListeners) listener();
|
|
1208
|
+
}
|
|
1209
|
+
try { requestHostSessionRefresh(changed); } catch { /* 下次频道轮询继续重试 */ }
|
|
1210
|
+
}
|
|
1211
|
+
/** IM 会话 ID 包含账号实例;接口映射兼容沿用普通 ID 的已接入会话。 */
|
|
1212
|
+
function channelIdOfSession(sessionId) {
|
|
1213
|
+
const value = String(sessionId || "");
|
|
1214
|
+
const mapped = channelSessionChannels.get(value);
|
|
1215
|
+
if (mapped) return mapped;
|
|
1216
|
+
if (!value.startsWith("im:")) return undefined;
|
|
1217
|
+
const rest = value.slice(3);
|
|
1218
|
+
const split = rest.indexOf(":");
|
|
1219
|
+
const instance = split > 0 ? rest.slice(0, split) : rest;
|
|
1220
|
+
const platform = instance.split("_", 1)[0];
|
|
1221
|
+
return platform || undefined;
|
|
1402
1222
|
}
|
|
1403
1223
|
const isChannelSession = (id) => String(id).startsWith("im:") || channelSessionIds.has(String(id));
|
|
1404
1224
|
const subscribeChannelMembership = (listener) => {
|
|
@@ -1411,8 +1231,9 @@ function observePluginUpdate(options) {
|
|
|
1411
1231
|
function sidebarTabForSession(currentId, extraTabs) {
|
|
1412
1232
|
if (typeof currentId !== "string" || currentId === "") return null;
|
|
1413
1233
|
const matched = (extraTabs || []).find((item) => item && item.matchSession && item.matchSession(currentId));
|
|
1414
|
-
if (matched && matched.id !== "schedule") return matched.id;
|
|
1415
|
-
|
|
1234
|
+
if (matched && matched.id !== "schedule" && matched.id !== "channels") return matched.id;
|
|
1235
|
+
// 频道会话同时存在于任务树和频道页签,不再自动改页签。
|
|
1236
|
+
if (isChannelSession(currentId)) return null;
|
|
1416
1237
|
if (matched) return null;
|
|
1417
1238
|
return "tasks";
|
|
1418
1239
|
}
|
|
@@ -1420,14 +1241,19 @@ function observePluginUpdate(options) {
|
|
|
1420
1241
|
function followSidebarTab(state, currentId, extraTabs) {
|
|
1421
1242
|
const ready = !!(state && state.ready);
|
|
1422
1243
|
const next = sidebarTabForSession(currentId, extraTabs);
|
|
1423
|
-
|
|
1244
|
+
// 首个有效主会话只建立基线,不覆盖用户恢复的页签;空快照继续等待。
|
|
1245
|
+
if (!ready) return { ready: typeof currentId === "string" && currentId !== "", previousId: currentId, tab: null };
|
|
1424
1246
|
if (typeof currentId !== "string" || currentId === "") return { ready: true, previousId: currentId, tab: null };
|
|
1425
|
-
if (currentId === state.previousId
|
|
1247
|
+
if (currentId === state.previousId) return { ready: true, previousId: currentId, tab: null };
|
|
1426
1248
|
return { ready: true, previousId: currentId, tab: next };
|
|
1427
1249
|
}
|
|
1428
1250
|
|
|
1251
|
+
function resolveSidebarTab(tab, extraTabs) {
|
|
1252
|
+
return tab === "tasks" || tab === "channels" || extraTabs.some((item) => item.id === tab) ? tab : "tasks";
|
|
1253
|
+
}
|
|
1254
|
+
|
|
1429
1255
|
function isHostNewSessionControl(label) {
|
|
1430
|
-
return
|
|
1256
|
+
return /^(新会话|新建任务|New chat|New session)(?:\s+(?:Ctrl|Alt|Shift|Meta)(?:\+[^\s+]+)*)?$/i.test(String(label || "").trim());
|
|
1431
1257
|
}
|
|
1432
1258
|
|
|
1433
1259
|
const api = (path, opts) => {
|
|
@@ -1709,15 +1535,7 @@ function observePluginUpdate(options) {
|
|
|
1709
1535
|
if (fromKey && String(fromKey).trim()) return String(fromKey).trim();
|
|
1710
1536
|
return sessionId;
|
|
1711
1537
|
}
|
|
1712
|
-
|
|
1713
|
-
if (!selectedId || !sessionId) return false;
|
|
1714
|
-
if (selectedId === sessionId) return true;
|
|
1715
|
-
const listed = sessionById && sessionById[sessionId];
|
|
1716
|
-
if (listed && (listed.id === selectedId || listed.sessionId === selectedId)) return true;
|
|
1717
|
-
const selected = sessionById && sessionById[selectedId];
|
|
1718
|
-
if (selected && (selected.id === sessionId || selected.sessionId === sessionId)) return true;
|
|
1719
|
-
return false;
|
|
1720
|
-
}
|
|
1538
|
+
|
|
1721
1539
|
function mainSessionModel(state) {
|
|
1722
1540
|
const id = currentSessionId(state);
|
|
1723
1541
|
const row = id && state && state.projectionsBySession && state.projectionsBySession[id];
|
|
@@ -1774,13 +1592,6 @@ function observePluginUpdate(options) {
|
|
|
1774
1592
|
error.code = "workspace/picker-unavailable";
|
|
1775
1593
|
return error;
|
|
1776
1594
|
}
|
|
1777
|
-
function activeSessionRefusal(error) {
|
|
1778
|
-
const reason = error && (error.reason || error);
|
|
1779
|
-
if (reason && reason.name === "WorkspaceArchiveError") return true;
|
|
1780
|
-
const rpc = error && (error.rpcError || error);
|
|
1781
|
-
if (rpc && (rpc.code === "workspace/session-active" || (rpc.details && rpc.details.activity))) return true;
|
|
1782
|
-
return /workspace\/session-active|WorkspaceArchiveError|still running|still active/i.test(String((error && error.message) || ""));
|
|
1783
|
-
}
|
|
1784
1595
|
function hostWorkspaceApi(ctx) {
|
|
1785
1596
|
return probeService(ctx, "uiWorkspace") || ctx.workspaces || {};
|
|
1786
1597
|
}
|
|
@@ -1858,7 +1669,6 @@ function observePluginUpdate(options) {
|
|
|
1858
1669
|
}
|
|
1859
1670
|
tryOpenListedSession(id, hostOpen);
|
|
1860
1671
|
};
|
|
1861
|
-
let channelSkin = "native";
|
|
1862
1672
|
|
|
1863
1673
|
function preferredAssistant(defaults, readModel) {
|
|
1864
1674
|
const main = typeof readModel === "function" ? readModel() : null;
|
|
@@ -2156,9 +1966,7 @@ function observePluginUpdate(options) {
|
|
|
2156
1966
|
return { name: preset.name || preset.id, description: preset.description };
|
|
2157
1967
|
}
|
|
2158
1968
|
function PlusIcon() {
|
|
2159
|
-
return h(
|
|
2160
|
-
h("path", { d: "M8 3v10M3 8h10", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" }),
|
|
2161
|
-
);
|
|
1969
|
+
return h(IconPlusOutline, { size: 14 });
|
|
2162
1970
|
}
|
|
2163
1971
|
|
|
2164
1972
|
function formatProviderLabel(provider, defaultLabel, modelT) {
|
|
@@ -2645,9 +2453,7 @@ function observePluginUpdate(options) {
|
|
|
2645
2453
|
);
|
|
2646
2454
|
}
|
|
2647
2455
|
function FeedbackIcon() {
|
|
2648
|
-
return h(
|
|
2649
|
-
h("path", { fill: "none", stroke: "currentColor", strokeWidth: 1.5, strokeLinecap: "round", strokeLinejoin: "round", d: "M9.5 2.5 13.5 6.5 6 14H2v-4z" }),
|
|
2650
|
-
);
|
|
2456
|
+
return h(IconEditOutline, { size: 16 });
|
|
2651
2457
|
}
|
|
2652
2458
|
|
|
2653
2459
|
function SettingsPage(props) {
|
|
@@ -2885,870 +2691,704 @@ function observePluginUpdate(options) {
|
|
|
2885
2691
|
}),
|
|
2886
2692
|
);
|
|
2887
2693
|
}
|
|
2888
|
-
|
|
2889
|
-
.dcu-wb-tree,.ima-native-tree{flex:1;min-height:0}
|
|
2890
|
-
.dcu-wb-project-head,.ima-native-head,.dcu-wb-session,.ima-native-session{display:flex;align-items:center;gap:6px;width:100%;border:0;border-radius:8px;padding:0 8px;background:transparent;color:inherit;cursor:pointer;font:inherit;text-align:left}
|
|
2891
|
-
.dcu-wb-project-head,.ima-native-head{height:34px}
|
|
2892
|
-
.dcu-wb-project-head:hover,.dcu-wb-session:hover,.dcu-wb-session.dcu-wb-selected,.ima-native-head:hover,.ima-native-session:hover,.ima-native-session.on{background:var(--dsw-alias-interactive-bg-hover,var(--dcu-sidebar-hover,rgba(255,255,255,.06)))}
|
|
2893
|
-
.dcu-wb-folder,.ima-native-folder{display:grid;place-items:center;flex:none;width:16px;height:20px}
|
|
2894
|
-
.dcu-wb-project-title,.dcu-wb-session-title,.ima-native-title,.ima-n-title{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:14px;line-height:20px;flex:1;font-weight:400}
|
|
2895
|
-
.dcu-wb-session-title,.ima-native-session .ima-native-title{font-weight:400}
|
|
2896
|
-
.dcu-wb-session,.ima-native-session{position:relative;min-height:32px;padding-left:32px}
|
|
2897
|
-
.dcu-wb-actions,.ima-native-actions{display:none;align-items:center;flex:none}
|
|
2898
|
-
.dcu-wb-session:hover .dcu-wb-actions,.dcu-wb-session.dcu-wb-menu-open .dcu-wb-actions,.ima-native-session:hover .ima-native-actions,.ima-native-session.menu-on .ima-native-actions{display:flex}
|
|
2899
|
-
.dcu-wb-more,.ima-native-more{display:grid;place-items:center;width:20px;height:20px;border:0;border-radius:4px;padding:0;background:transparent;color:var(--dsw-alias-label-secondary,var(--ima-muted));cursor:pointer}
|
|
2900
|
-
.dcu-wb-empty,.ima-native-empty{padding:16px 12px;color:var(--dsw-alias-label-tertiary,var(--ima-muted));font-size:13px}
|
|
2901
|
-
.ima-rename{flex:1;min-width:0;min-height:28px;padding:2px 8px;border-radius:6px;border:1px solid var(--dsw-alias-stroke-primary,var(--ima-line));background:transparent;color:inherit;font:inherit}
|
|
2902
|
-
.ima-n-row,.ima-n-sess{display:flex;align-items:center;max-width:100%;gap:6px;border-radius:8px;padding:0 8px;padding-inline-start:calc(8px + var(--dsh-workspace-indent,0px));cursor:pointer;user-select:none;width:100%;border:0;background:transparent;color:var(--dsw-alias-label-primary,var(--ima-text));font:14px/20px inherit;text-align:left;box-sizing:border-box}
|
|
2903
|
-
.ima-n-row{height:34px}
|
|
2904
|
-
.ima-n-sess{height:32px;gap:0;position:relative;appearance:none}
|
|
2905
|
-
.ima-n-row:hover,.ima-n-sess:hover,.ima-n-sess.on,.ima-n-sess.is-on,.ima-n-row.menu-on,.ima-n-row.is-menu,.ima-n-sess.menu-on,.ima-n-sess.is-menu{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06))}
|
|
2906
|
-
.ima-n-row.has-current-session .ima-n-folder{color:var(--dsw-alias-state-business-primary,#4c8dff)}
|
|
2907
|
-
.ima-n-project-text{flex-direction:column;flex:1;gap:2px;min-width:0;display:flex}
|
|
2908
|
-
.ima-n-row .ima-n-acts{height:20px}
|
|
2909
|
-
.ima-n-sess.is-flat-idle .ima-n-title{margin-left:0}
|
|
2910
|
-
.ima-n-sess:focus{outline:none}.ima-n-sess:focus-visible:not(.is-on){box-shadow:inset 0 0 0 2px var(--dsw-alias-state-business-primary,#4c8dff)}
|
|
2911
|
-
.ima-n-slot{flex:none;width:16px;min-width:16px;height:20px;display:inline-flex;align-items:center;justify-content:center;color:var(--dsw-alias-label-tertiary,#81858C)}
|
|
2912
|
-
.ima-n-folder{color:var(--dsw-alias-label-secondary,#9ca39f)}.ima-n-folder>.ima-logo,.dcu-wb-folder>.ima-logo{width:16px;height:16px;display:block;line-height:0}.ima-n-folder>.ima-logo svg{width:16px;height:16px;display:block}.ima-n-folder>.ima-logo svg,.dcu-wb-folder>.ima-logo svg{width:16px;height:16px;display:block}
|
|
2913
|
-
.ima-n-lead{color:var(--dsw-alias-label-tertiary,#81858C)}
|
|
2914
|
-
.ima-n-corner{color:var(--dsw-alias-label-caption,#ADB2B8);width:8px}
|
|
2915
|
-
.ima-n-hover{--dsw-hovercard-bg:#2C2C2E;position:fixed;z-index:100;box-sizing:border-box;width:244px;padding:12px 16px;border:0;border-radius:12px;background:var(--dsw-hovercard-bg);box-shadow:var(--dsw-shadow-lv3,0 8px 24px rgba(0,0,0,.36))}
|
|
2916
|
-
.ima-n-hover-content{display:flex;flex-direction:column;gap:8px;min-width:0}
|
|
2917
|
-
.ima-n-hover-title{color:#fff;font-size:14px;line-height:20px;font-weight:400;overflow-wrap:break-word}
|
|
2918
|
-
.ima-n-hover-time{margin:0;color:#cfd3d6;font-size:12px;line-height:16px}
|
|
2919
|
-
.ima-n-hover-state{display:flex;align-items:center;gap:8px;margin:0;font-size:12px;line-height:20px;color:#adb2b8}
|
|
2920
|
-
.ima-n-hover-dot{width:10px;height:10px;border-radius:50%;background:var(--dsw-alias-state-success-primary,#34c759);flex:none;position:relative}
|
|
2921
|
-
.ima-n-hover-dot.is-run{background:var(--dsw-static-deepseek-450,#4c8dff)}
|
|
2922
|
-
.ima-n-title{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:14px;line-height:20px;flex:1;font-weight:400}
|
|
2923
|
-
.ima-n-sess .ima-n-title{margin:0 6px 0 4px}
|
|
2924
|
-
.ima-n-sess .ima-n-title[data-scrolled]{mask-image:linear-gradient(90deg,#0000,#000 12px)}
|
|
2925
|
-
.ima-n-sess .ima-n-title[data-clipped]{mask-image:linear-gradient(270deg,#0000,#000 12px)}
|
|
2926
|
-
.ima-n-sess .ima-n-title[data-scrolled][data-clipped]{mask-image:linear-gradient(90deg,#0000,#000 12px calc(100% - 12px),#0000)}
|
|
2927
|
-
@media (hover:hover){.ima-n-sess:hover .ima-n-title,.ima-n-sess.is-menu .ima-n-title{text-overflow:clip}}
|
|
2928
|
-
.ima-n-sess.is-archived .ima-n-title,.ima-n-sess.is-archived .ima-n-time{color:var(--dsw-alias-label-caption,#ADB2B8)}
|
|
2929
|
-
.ima-n-time{flex:none;font-size:10px;line-height:16px;color:var(--dsw-alias-label-caption,#ADB2B8);white-space:nowrap}
|
|
2930
|
-
.ima-n-acts{flex:none;display:none;align-items:center;gap:10px}
|
|
2931
|
-
.ima-n-row:hover .ima-n-acts,.ima-n-sess:hover .ima-n-acts,.ima-n-row.menu-on .ima-n-acts,.ima-n-row.is-menu .ima-n-acts,.ima-n-sess.menu-on .ima-n-acts,.ima-n-sess.is-menu .ima-n-acts{display:inline-flex}
|
|
2932
|
-
.ima-n-sess:hover .ima-n-time,.ima-n-sess.menu-on .ima-n-time,.ima-n-sess.is-menu .ima-n-time{display:none}
|
|
2933
|
-
.ima-n-ico{display:inline-flex;align-items:center;justify-content:center;width:16px;height:16px;border:0;border-radius:4px;padding:0;background:transparent;cursor:pointer;color:var(--dsw-alias-label-tertiary,#81858C)}
|
|
2934
|
-
.ima-n-ico:hover{color:var(--dsw-alias-label-primary,var(--ima-text))}
|
|
2935
|
-
.ima-n-menu{position:fixed;right:auto;top:auto;z-index:4000;min-width:218px;max-width:360px;box-sizing:border-box;padding:4px;display:flex;flex-direction:column;border:1px solid var(--dsw-alias-border-inverted,rgba(255,255,255,.12));border-radius:12px;background:var(--dsw-specific-menu,var(--dsw-alias-bg-layer-2));box-shadow:var(--dsw-shadow-lv3,0 8px 24px rgba(0,0,0,.36))}
|
|
2936
|
-
.ima-n-menu button{display:flex;align-items:center;gap:8px;width:100%;min-height:40px;padding:8px 10px;border:0;border-radius:10px;background:transparent;cursor:pointer;font-size:14px;line-height:22px;color:var(--dsw-alias-label-primary,var(--ima-text));text-align:left}
|
|
2937
|
-
.ima-n-menu button:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.06))}
|
|
2938
|
-
.ima-n-mi{display:inline-flex;flex:none;width:16px;height:16px;align-items:center;justify-content:center;color:var(--dsw-alias-label-tertiary,#81858C)}
|
|
2939
|
-
.ima-n-menu button.danger{color:var(--dsw-alias-state-error-primary,#f85149)}
|
|
2940
|
-
.ima-n-menu button.danger .ima-n-mi{color:inherit}
|
|
2941
|
-
.ima-n-menu button.danger:hover{background:var(--dsw-alias-interactive-bg-hover-danger,rgba(248,81,73,.12))}
|
|
2942
|
-
.ima-n-rename{flex:1;min-width:0;margin:0 6px 0 4px;border:.5px solid var(--dsw-alias-border-l4);border-radius:4px;outline:none;background:var(--dsw-alias-button-elevated-fill,rgba(255,255,255,.04));color:inherit;padding:0 2px;font-size:14px;line-height:20px}
|
|
2943
|
-
.ima-n-dialog-actions{display:flex;justify-content:flex-end;gap:8px}
|
|
2944
|
-
.ima-n-dialog-status{margin-top:12px;color:var(--dsw-alias-label-secondary);font-size:13px;line-height:20px}
|
|
2945
|
-
.ima-n-dialog-error{margin-top:12px;color:var(--dsw-alias-state-error-primary,#f85149);font-size:13px;line-height:20px}
|
|
2946
|
-
.ima-n-restore{flex:none;border:0;background:transparent;color:var(--dsw-alias-label-secondary,#c9cdd4);font:12px/16px inherit;padding:2px 4px;cursor:pointer}`;
|
|
2947
|
-
|
|
2948
|
-
function NativeSvg(viewBox, size, children) {
|
|
2949
|
-
return h("svg", { viewBox, width: size, height: size, fill: "none", xmlns: "http://www.w3.org/2000/svg", "aria-hidden": "true" }, children);
|
|
2950
|
-
}
|
|
2951
|
-
function NativePath(d, extra) {
|
|
2952
|
-
return h("path", Object.assign({ d, fill: "currentColor" }, extra || {}));
|
|
2953
|
-
}
|
|
2694
|
+
|
|
2954
2695
|
function IconChevron() {
|
|
2955
|
-
return
|
|
2956
|
-
}
|
|
2957
|
-
function IconSearchFallback(props) {
|
|
2958
|
-
const size = props && props.size ? props.size : 16;
|
|
2959
|
-
return NativeSvg("0 0 16 16", size, [
|
|
2960
|
-
NativePath("M11.894845 6.647401C11.894845 3.725463 9.534486 1.356779 6.623219 1.35657C3.711786 1.35657 1.351635 3.725338 1.351635 6.647401C1.351843 9.569296 3.711911 11.938273 6.623219 11.938273C9.534361 11.938064 11.894637 9.569171 11.894845 6.647401ZM13.245462 6.647401C13.245254 10.317935 10.280401 13.293613 6.623219 13.293821C2.965871 13.293821 0.000204 10.31806 0 6.647401C0 2.976574 2.965746 0 6.623219 0C10.280526 0.000205 13.245462 2.9767 13.245462 6.647401Z"),
|
|
2961
|
-
NativePath("M16.000417 15.041079L15.044449 16.000433L11.530434 12.473588L12.486298 11.514234L16.000417 15.041079Z"),
|
|
2962
|
-
]);
|
|
2963
|
-
}
|
|
2964
|
-
function IconSlidersFallback() {
|
|
2965
|
-
return NativeSvg("0 0 16 16", 16, NativePath("M2.2 3.4h6.05a1.85 1.85 0 0 0 3.5 0H13.8v1.3H11.75a1.85 1.85 0 0 0-3.5 0H2.2V3.4Zm8.6 1.15A.75.75 0 1 1 10.05 4.55.75.75 0 0 1 10.8 4.55ZM2.2 7.35h2.35a1.85 1.85 0 0 0 3.5 0H13.8v1.3H8.05a1.85 1.85 0 0 0-3.5 0H2.2V7.35Zm4.1 1.15A.75.75 0 1 1 5.55 8.5a.75.75 0 0 1 .75-.75ZM2.2 11.3h7.35a1.85 1.85 0 0 0 3.5 0H13.8v1.3h-.75a1.85 1.85 0 0 0-3.5 0H2.2v-1.3Zm9.9 1.15a.75.75 0 1 1-.75-.75.75.75 0 0 1 .75.75Z"));
|
|
2696
|
+
return h(IconChevronRightOutline, { size: 14 });
|
|
2966
2697
|
}
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2698
|
+
|
|
2699
|
+
// ---------------------------------------------------------------------
|
|
2700
|
+
// 频道页签:直接复用官方 WorkspaceBrowser。
|
|
2701
|
+
// 自绘列表已删除;官方树不可用时只显示不可用提示。
|
|
2702
|
+
// ---------------------------------------------------------------------
|
|
2703
|
+
|
|
2704
|
+
const CHANNEL_WORKSPACE_PREFIX = "dsh-im-channel:";
|
|
2705
|
+
const CHANNEL_GROUP_IDS = ["weixin", "wecom", "qq", "feishu", "lark", "dingtalk", "telegram", "discord", "slack"];
|
|
2706
|
+
const EMPTY_SESSION_STATE = { ids: [], byId: {}, current: null };
|
|
2707
|
+
const EMPTY_WORKSPACE_STATE = { items: [], archivedSessionIds: [], pinnedSessionIds: [], state: "idle", phase: "ready", error: null };
|
|
2708
|
+
const CHANNEL_GROUP_OPTION_ATTR = "data-ima-channel-group-option";
|
|
2709
|
+
const CHANNEL_GROUP_MENU_ATTR = "data-ima-channel-group-menu";
|
|
2710
|
+
|
|
2711
|
+
function channelWorkspaceId(id) {
|
|
2712
|
+
return CHANNEL_WORKSPACE_PREFIX + String(id || "");
|
|
2976
2713
|
}
|
|
2977
|
-
|
|
2978
|
-
|
|
2714
|
+
|
|
2715
|
+
function channelIdFromWorkspaceId(workspaceId) {
|
|
2716
|
+
const value = String(workspaceId || "");
|
|
2717
|
+
return value.startsWith(CHANNEL_WORKSPACE_PREFIX) ? value.slice(CHANNEL_WORKSPACE_PREFIX.length) : undefined;
|
|
2979
2718
|
}
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
const IconWorkspaceTree = hostOrFallback(pickHostIcon("IconWorkspaceTreeOutlineRegular", "IconWorkspaceTreeOutline16"), function IconTreeFallback() {
|
|
2985
|
-
return NativeSvg("0 0 16 16", 16, NativePath("M3 3h4v3H3V3Zm6 1h4M3 10h4v3H3v-3Zm6 1.5h4M7 4.5h2M7 11.5h2", { fill: "none", stroke: "currentColor", strokeWidth: "1.4", strokeLinecap: "round" }));
|
|
2986
|
-
});
|
|
2987
|
-
const IconArchiveCheckOutline = hostOrFallback(IconArchiveCheckHost, IconArchiveCheckFallback);
|
|
2988
|
-
function ChannelWorkspaceHead({ query, sort, groupMode, archivedFilter, onQuery, onSort, onGroupMode, onArchivedFilterChange, t = fallbackT }) {
|
|
2989
|
-
const [searching, setSearching] = useState(!!query);
|
|
2990
|
-
const [filterOpen, setFilterOpen] = useState(false);
|
|
2991
|
-
const searchSize = searching ? 11 : 14;
|
|
2992
|
-
const items = [
|
|
2993
|
-
{ type: "label", id: "group-by", text: t("rail.group") },
|
|
2994
|
-
{ id: "workspace", label: t("rail.byWorkspace"), icon: h(IconFolderClose, { size: 16 }) },
|
|
2995
|
-
{ id: "workspace-tree", label: t("rail.byWorkspaceTree"), icon: h(IconWorkspaceTree, { size: 16 }) },
|
|
2996
|
-
{ id: "flat", label: t("rail.list"), icon: h(IconFlatList, { size: 16 }) },
|
|
2997
|
-
{ type: "separator", id: "order-by-separator" },
|
|
2998
|
-
{ type: "label", id: "order-by", text: t("rail.sort") },
|
|
2999
|
-
{ id: "updated", label: t("rail.recent"), icon: h(IconClockOutline, { size: 16 }) },
|
|
3000
|
-
{ type: "separator", id: "archived-filter-separator" },
|
|
3001
|
-
{ type: "label", id: "filter-by", text: t("rail.filter") },
|
|
3002
|
-
{ id: "show-archived", label: t("rail.showArchived"), icon: h(IconArchiveOutline20, { size: 16 }) },
|
|
3003
|
-
{ id: "only-archived", label: t("rail.onlyArchived"), icon: h(IconArchiveCheckOutline, { size: 16 }) },
|
|
3004
|
-
];
|
|
3005
|
-
const selectedIds = [
|
|
3006
|
-
groupMode === "list" ? "flat" : groupMode,
|
|
3007
|
-
"updated",
|
|
3008
|
-
...(archivedFilter === "show" ? ["show-archived"] : []),
|
|
3009
|
-
...(archivedFilter === "only" ? ["only-archived"] : []),
|
|
3010
|
-
];
|
|
3011
|
-
return h("div", { className: searching ? "ima-n-toolbar is-search" : "ima-n-toolbar" },
|
|
3012
|
-
h("span", { className: "ima-n-head-label" }, groupMode === "list" ? t("rail.sessions") : t("rail.workspace")),
|
|
3013
|
-
h("div", { className: "ima-n-search-slot" },
|
|
3014
|
-
h("div", { className: "ima-n-search", onClick: () => { setFilterOpen(false); setSearching(true); } },
|
|
3015
|
-
h("button", { type: "button", className: "ima-n-search-btn", "aria-label": t("rail.search"), "aria-expanded": searching, onClick: () => { setFilterOpen(false); setSearching(true); } }, h(IconSearchOutline, { size: searchSize })),
|
|
3016
|
-
h("input", { className: "ima-n-search-input", value: query, placeholder: t("rail.searchPlaceholder"), "aria-label": t("rail.search"), tabIndex: searching ? 0 : -1, "aria-hidden": !searching, onChange: (e) => onQuery(e.target.value), onKeyDown: (e) => { if (e.key === "Escape") { onQuery(""); setSearching(false); } } }),
|
|
3017
|
-
searching && h("button", { type: "button", className: "ima-n-search-clear", "aria-label": t("rail.clearSearch"), onClick: (e) => { e.stopPropagation(); onQuery(""); setSearching(false); } }, h(IconCloseFill, { size: 14 })),
|
|
3018
|
-
),
|
|
3019
|
-
),
|
|
3020
|
-
h("div", { className: "ima-n-head-acts" },
|
|
3021
|
-
h(HostMenu, {
|
|
3022
|
-
open: filterOpen,
|
|
3023
|
-
onClose: () => { setFilterOpen(false); },
|
|
3024
|
-
items,
|
|
3025
|
-
selectedIds,
|
|
3026
|
-
align: "end",
|
|
3027
|
-
dense: true,
|
|
3028
|
-
portal: true,
|
|
3029
|
-
onSelect: (id) => {
|
|
3030
|
-
if (id === "workspace" || id === "workspace-tree") onGroupMode(id);
|
|
3031
|
-
if (id === "flat") onGroupMode("list");
|
|
3032
|
-
if (id === "updated") onSort("time");
|
|
3033
|
-
if (id === "show-archived") onArchivedFilterChange(archivedFilter === "show" ? "default" : "show");
|
|
3034
|
-
if (id === "only-archived") onArchivedFilterChange(archivedFilter === "only" ? "default" : "only");
|
|
3035
|
-
setFilterOpen(false);
|
|
3036
|
-
},
|
|
3037
|
-
anchor: h("button", { type: "button", className: filterOpen ? "ima-n-head-btn is-on" : "ima-n-head-btn", "aria-label": t("rail.filter"), "aria-expanded": filterOpen, onClick: () => setFilterOpen((open) => !open) }, h(IconSlidersTwoOutline, { size: 16 })),
|
|
3038
|
-
}),
|
|
3039
|
-
),
|
|
3040
|
-
);
|
|
2719
|
+
|
|
2720
|
+
/** 频道页签把官方“添加工作区”按钮复用为“添加频道”。 */
|
|
2721
|
+
function channelAddFlow(select) {
|
|
2722
|
+
return select(true);
|
|
3041
2723
|
}
|
|
3042
|
-
|
|
3043
|
-
|
|
2724
|
+
|
|
2725
|
+
function noopChannelAction() {}
|
|
2726
|
+
|
|
2727
|
+
function copySessionOrders(orders) {
|
|
2728
|
+
return Object.fromEntries(Object.entries(orders || {}).map(([key, order]) => [key, [...order]]));
|
|
3044
2729
|
}
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
2730
|
+
|
|
2731
|
+
/** 频道页签使用独立视图状态,不污染上方任务树。 */
|
|
2732
|
+
function createChannelViewStore() {
|
|
2733
|
+
let state = {
|
|
2734
|
+
groupBy: "channel",
|
|
2735
|
+
orderBy: "updated",
|
|
2736
|
+
groupExpansion: {},
|
|
2737
|
+
sessionOrderByAccount: {},
|
|
2738
|
+
archivedFilter: "default",
|
|
2739
|
+
};
|
|
2740
|
+
const listeners = new Set();
|
|
2741
|
+
const publish = (next) => {
|
|
2742
|
+
state = next;
|
|
2743
|
+
for (const listener of listeners) listener();
|
|
2744
|
+
};
|
|
2745
|
+
const actions = {
|
|
2746
|
+
setGroupBy(mode) {
|
|
2747
|
+
if (mode !== state.groupBy) publish(Object.assign({}, state, { groupBy: mode }));
|
|
2748
|
+
},
|
|
2749
|
+
setOrderBy(mode, initialOrders) {
|
|
2750
|
+
if (mode === state.orderBy) return;
|
|
2751
|
+
publish(Object.assign({}, state, {
|
|
2752
|
+
orderBy: mode,
|
|
2753
|
+
sessionOrderByAccount: mode === "manual" ? copySessionOrders(initialOrders) : {},
|
|
2754
|
+
}));
|
|
2755
|
+
},
|
|
2756
|
+
setGroupExpanded(key, expanded) {
|
|
2757
|
+
if (state.groupExpansion[key] === expanded) return;
|
|
2758
|
+
publish(Object.assign({}, state, { groupExpansion: Object.assign({}, state.groupExpansion, { [key]: expanded }) }));
|
|
2759
|
+
},
|
|
2760
|
+
retainAccountKeys(workspaceKeys) {
|
|
2761
|
+
const retained = new Set(workspaceKeys || []);
|
|
2762
|
+
const groupExpansion = Object.fromEntries(Object.entries(state.groupExpansion).filter(([key]) => retained.has(key)));
|
|
2763
|
+
const sessionOrderByAccount = Object.fromEntries(Object.entries(state.sessionOrderByAccount).filter(([key]) => retained.has(key)));
|
|
2764
|
+
if (Object.keys(groupExpansion).length === Object.keys(state.groupExpansion).length
|
|
2765
|
+
&& Object.keys(sessionOrderByAccount).length === Object.keys(state.sessionOrderByAccount).length) return;
|
|
2766
|
+
publish(Object.assign({}, state, { groupExpansion, sessionOrderByAccount }));
|
|
2767
|
+
},
|
|
2768
|
+
setSessionOrder(accountKey, order, initialOrders) {
|
|
2769
|
+
const sessionOrderByAccount = state.orderBy === "manual"
|
|
2770
|
+
? Object.assign({}, state.sessionOrderByAccount, { [accountKey]: [...order] })
|
|
2771
|
+
: Object.assign(copySessionOrders(initialOrders), { [accountKey]: [...order] });
|
|
2772
|
+
publish(Object.assign({}, state, { orderBy: "manual", sessionOrderByAccount }));
|
|
2773
|
+
},
|
|
2774
|
+
syncSessionOrders(orders) {
|
|
2775
|
+
if (state.orderBy !== "manual") return;
|
|
2776
|
+
publish(Object.assign({}, state, { sessionOrderByAccount: Object.assign({}, state.sessionOrderByAccount, copySessionOrders(orders)) }));
|
|
2777
|
+
},
|
|
2778
|
+
pinSessionOrder(sessionId, accountKeys, source) {
|
|
2779
|
+
const selected = new Set(accountKeys || []);
|
|
2780
|
+
const sessionOrderByAccount = Object.fromEntries(Object.entries((source && source.members) || {}).map(([key, members]) => {
|
|
2781
|
+
const current = state.sessionOrderByAccount[key] || members;
|
|
2782
|
+
const order = selected.has(key) ? [sessionId, ...current.filter((id) => id !== sessionId)] : [...current];
|
|
2783
|
+
return [key, order];
|
|
2784
|
+
}));
|
|
2785
|
+
publish(Object.assign({}, state, { sessionOrderByAccount }));
|
|
2786
|
+
},
|
|
2787
|
+
setArchivedFilter(filter) {
|
|
2788
|
+
if (filter !== state.archivedFilter) publish(Object.assign({}, state, { archivedFilter: filter }));
|
|
2789
|
+
},
|
|
2790
|
+
ensureExpanded(keys) {
|
|
2791
|
+
let changed = false;
|
|
2792
|
+
const groupExpansion = Object.assign({}, state.groupExpansion);
|
|
2793
|
+
for (const key of keys || []) {
|
|
2794
|
+
if (key === "" || groupExpansion[key] !== undefined) continue;
|
|
2795
|
+
groupExpansion[key] = true;
|
|
2796
|
+
changed = true;
|
|
2797
|
+
}
|
|
2798
|
+
if (changed) publish(Object.assign({}, state, { groupExpansion }));
|
|
2799
|
+
},
|
|
2800
|
+
};
|
|
2801
|
+
return {
|
|
2802
|
+
getSnapshot: () => state,
|
|
2803
|
+
subscribe(listener) {
|
|
2804
|
+
listeners.add(listener);
|
|
2805
|
+
return () => listeners.delete(listener);
|
|
2806
|
+
},
|
|
2807
|
+
actions,
|
|
2808
|
+
};
|
|
3048
2809
|
}
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
rows.map((status) => h("div", { key: status.label, className: "ima-n-hover-state" },
|
|
3055
|
-
status.state === "archived"
|
|
3056
|
-
? h(IconArchiveOutline20, { size: 14 })
|
|
3057
|
-
: (typeof StateDot === "function"
|
|
3058
|
-
? h(StateDot, { state: status.state === "ongoing" ? "ongoing" : status.state === "warning" ? "warning" : status.state === "done" ? "done" : "idle", size: 10 })
|
|
3059
|
-
: h(SessionHoverStatusDot, { running: status.state === "ongoing" })),
|
|
3060
|
-
status.label,
|
|
3061
|
-
)),
|
|
3062
|
-
);
|
|
2810
|
+
|
|
2811
|
+
let sharedChannelViewStore;
|
|
2812
|
+
function getChannelViewStore() {
|
|
2813
|
+
sharedChannelViewStore = sharedChannelViewStore || createChannelViewStore();
|
|
2814
|
+
return sharedChannelViewStore;
|
|
3063
2815
|
}
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
2816
|
+
|
|
2817
|
+
const channelSessionStateCache = new WeakMap();
|
|
2818
|
+
const channelSyntheticWorkspaceCache = new WeakMap();
|
|
2819
|
+
const channelRealWorkspaceCache = new WeakMap();
|
|
2820
|
+
|
|
2821
|
+
/** 只保留 /channels 分组里的会话,避免官方树出现“未分组”桶。 */
|
|
2822
|
+
function channelMemberSessionState(state, memberIds) {
|
|
2823
|
+
const src = state || EMPTY_SESSION_STATE;
|
|
2824
|
+
const hit = channelSessionStateCache.get(src);
|
|
2825
|
+
if (hit && hit.ids === memberIds) return hit.result;
|
|
2826
|
+
const ids = (src.ids || []).filter((id) => memberIds.has(String(id)));
|
|
2827
|
+
const result = cacheFilteredSessions(src, ids);
|
|
2828
|
+
channelSessionStateCache.set(src, { ids: memberIds, result });
|
|
2829
|
+
return result;
|
|
3068
2830
|
}
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
const
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
:
|
|
3075
|
-
|
|
2831
|
+
|
|
2832
|
+
function channelGroupsFromSessionState(state, t) {
|
|
2833
|
+
const groups = new Map(CHANNEL_GROUP_IDS.map((id) => [id, {
|
|
2834
|
+
id,
|
|
2835
|
+
label: channelLabel({ id }, t),
|
|
2836
|
+
sessions: [],
|
|
2837
|
+
}]));
|
|
2838
|
+
const src = state || EMPTY_SESSION_STATE;
|
|
2839
|
+
for (const id of src.ids || []) {
|
|
2840
|
+
const group = groups.get(channelIdOfSession(id));
|
|
2841
|
+
const session = src.byId && src.byId[id];
|
|
2842
|
+
if (group && session) group.sessions.push({ sessionId: id, updatedAt: session.updatedAt });
|
|
2843
|
+
}
|
|
2844
|
+
return [...groups.values()].filter((group) => group.sessions.length > 0);
|
|
3076
2845
|
}
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
const
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
if (diff < HOUR) return { unit: "minutes", n: Math.floor(diff / MIN) };
|
|
3086
|
-
if (diff < DAY) return { unit: "hours", n: Math.floor(diff / HOUR) };
|
|
3087
|
-
if (diff < 30 * DAY) return { unit: "days", n: Math.floor(diff / DAY) };
|
|
3088
|
-
if (diff < 365 * DAY) return { unit: "months", n: Math.floor(diff / (30 * DAY)) };
|
|
3089
|
-
return { unit: "years", n: Math.floor(diff / (365 * DAY)) };
|
|
2846
|
+
|
|
2847
|
+
function channelGroupCreatedAt(group) {
|
|
2848
|
+
let earliest = Infinity;
|
|
2849
|
+
for (const session of group.sessions || []) {
|
|
2850
|
+
const timestamp = Date.parse(session.updatedAt || "");
|
|
2851
|
+
if (Number.isFinite(timestamp) && timestamp < earliest) earliest = timestamp;
|
|
2852
|
+
}
|
|
2853
|
+
return new Date(Number.isFinite(earliest) ? earliest : 0).toISOString();
|
|
3090
2854
|
}
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
2855
|
+
|
|
2856
|
+
/**
|
|
2857
|
+
* 按频道分组:每个频道合成一个官方 WorkspaceView。
|
|
2858
|
+
* 保留宿主的 phase/state/归档集合,官方浏览器才能正常渲染。
|
|
2859
|
+
*/
|
|
2860
|
+
function syntheticChannelWorkspaceState(state, groups, t) {
|
|
2861
|
+
const src = state || EMPTY_WORKSPACE_STATE;
|
|
2862
|
+
const key = groups.map((group) => [
|
|
2863
|
+
group.id,
|
|
2864
|
+
channelLabel(group, t),
|
|
2865
|
+
channelGroupCreatedAt(group),
|
|
2866
|
+
(group.sessions || []).map((session) => session.sessionId).join(","),
|
|
2867
|
+
].join("\0")).join("\0\0");
|
|
2868
|
+
const hit = channelSyntheticWorkspaceCache.get(src);
|
|
2869
|
+
if (hit && hit.key === key) return hit.result;
|
|
2870
|
+
const items = groups.filter((group) => (group.sessions || []).length > 0).map((group) => {
|
|
2871
|
+
const workspaceId = channelWorkspaceId(group.id);
|
|
2872
|
+
return {
|
|
2873
|
+
workspaceId,
|
|
2874
|
+
id: workspaceId,
|
|
2875
|
+
title: channelLabel(group, t),
|
|
2876
|
+
path: "",
|
|
2877
|
+
sessionIds: (group.sessions || []).map((session) => session.sessionId),
|
|
2878
|
+
createdAt: channelGroupCreatedAt(group),
|
|
2879
|
+
};
|
|
2880
|
+
});
|
|
2881
|
+
const result = Object.assign({}, src, { items, phase: "ready" });
|
|
2882
|
+
channelSyntheticWorkspaceCache.set(src, { key, result });
|
|
2883
|
+
return result;
|
|
3095
2884
|
}
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
2885
|
+
|
|
2886
|
+
/** 按工作区/工作区树:保留真实工作区,只过滤出频道会话。 */
|
|
2887
|
+
function channelRealWorkspaceState(state, memberIds) {
|
|
2888
|
+
const src = state || EMPTY_WORKSPACE_STATE;
|
|
2889
|
+
const hit = channelRealWorkspaceCache.get(src);
|
|
2890
|
+
if (hit && hit.ids === memberIds) return hit.result;
|
|
2891
|
+
const items = (src.items || []).map((workspace) => {
|
|
2892
|
+
const sessionIds = (workspace.sessionIds || []).filter((id) => memberIds.has(String(id)));
|
|
2893
|
+
return sessionIds.length === (workspace.sessionIds || []).length
|
|
2894
|
+
? workspace
|
|
2895
|
+
: Object.assign({}, workspace, { sessionIds });
|
|
2896
|
+
});
|
|
2897
|
+
const result = Object.assign({}, src, { items });
|
|
2898
|
+
channelRealWorkspaceCache.set(src, { ids: memberIds, result });
|
|
2899
|
+
return result;
|
|
3101
2900
|
}
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
const
|
|
3109
|
-
const
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
const [hoverOpen, setHoverOpen] = useState(false);
|
|
3114
|
-
const [hoverStyle, setHoverStyle] = useState({});
|
|
3115
|
-
const title = sess.title || sess.chatId;
|
|
3116
|
-
const native = skin !== "codex";
|
|
3117
|
-
const useOfficialHover = native && typeof HoverCard === "function";
|
|
3118
|
-
const archived = !!arguments[0].archived;
|
|
3119
|
-
const running = !!(sess.running || (sessionById && sessionById[sess.sessionId] && sessionById[sess.sessionId].running));
|
|
3120
|
-
const statuses = hoverStatuses || channelSessionHoverStatuses({ running, archived }, t);
|
|
3121
|
-
const primary = statuses.find((status) => status.state !== "archived");
|
|
3122
|
-
const showDot = !archived && primary && primary.state !== "idle";
|
|
3123
|
-
const trailing = primary && primary.trailing;
|
|
3124
|
-
const hoverTitle = (sessionById && sessionById[sess.sessionId] && (sessionById[sess.sessionId].displayTitle || sessionById[sess.sessionId].title)) || title;
|
|
3125
|
-
const showHover = () => {
|
|
3126
|
-
if (menu || !native) return;
|
|
3127
|
-
if (hoverTimer.current) window.clearTimeout(hoverTimer.current);
|
|
3128
|
-
hoverTimer.current = window.setTimeout(() => setHoverOpen(true), 500);
|
|
3129
|
-
};
|
|
3130
|
-
const hideHover = () => {
|
|
3131
|
-
if (hoverTimer.current) window.clearTimeout(hoverTimer.current);
|
|
3132
|
-
setHoverOpen(false);
|
|
3133
|
-
};
|
|
3134
|
-
useLayoutEffect(() => {
|
|
3135
|
-
if (!hoverOpen || menu || !rowRef.current) return;
|
|
3136
|
-
const card = hoverRef.current;
|
|
3137
|
-
const size = card ? { width: card.offsetWidth || 220, height: card.offsetHeight || 96 } : { width: 220, height: 96 };
|
|
3138
|
-
const update = () => {
|
|
3139
|
-
if (!rowRef.current) return;
|
|
3140
|
-
setHoverStyle(nativeSessionHoverStyle(rowRef.current.getBoundingClientRect(), {
|
|
3141
|
-
width: (hoverRef.current && hoverRef.current.offsetWidth) || size.width,
|
|
3142
|
-
height: (hoverRef.current && hoverRef.current.offsetHeight) || size.height,
|
|
3143
|
-
}, { width: window.innerWidth, height: window.innerHeight }));
|
|
3144
|
-
};
|
|
3145
|
-
update();
|
|
3146
|
-
window.addEventListener("resize", update);
|
|
3147
|
-
document.addEventListener("scroll", update, true);
|
|
3148
|
-
return () => {
|
|
3149
|
-
window.removeEventListener("resize", update);
|
|
3150
|
-
document.removeEventListener("scroll", update, true);
|
|
2901
|
+
|
|
2902
|
+
let channelIconCssValue;
|
|
2903
|
+
|
|
2904
|
+
/** 把 React 元素渲染成可直接注入官方 DOM 的 HTML。 */
|
|
2905
|
+
function channelMarkup(element) {
|
|
2906
|
+
if (typeof document === "undefined") return "";
|
|
2907
|
+
const hasCreateRoot = typeof ReactDOM.createRoot === "function";
|
|
2908
|
+
const createRoot = ReactDOM.createRoot || function createRootFallback(host) {
|
|
2909
|
+
return {
|
|
2910
|
+
render(node) { if (typeof ReactDOM.render === "function") ReactDOM.render(node, host); },
|
|
2911
|
+
unmount() { if (typeof ReactDOM.unmountComponentAtNode === "function") ReactDOM.unmountComponentAtNode(host); },
|
|
3151
2912
|
};
|
|
3152
|
-
}
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
setMenu(false);
|
|
3163
|
-
if (action === "copy-title") { try { navigator.clipboard.writeText(title); } catch { /* ignore */ } return; }
|
|
3164
|
-
if (action === "copy-id") { try { navigator.clipboard.writeText(sess.sessionId); } catch { /* ignore */ } return; }
|
|
3165
|
-
if (action === "copy-link") {
|
|
3166
|
-
try { navigator.clipboard.writeText(location.origin + "/?session=" + encodeURIComponent(sess.sessionId)); } catch { /* ignore */ }
|
|
3167
|
-
return;
|
|
2913
|
+
};
|
|
2914
|
+
try {
|
|
2915
|
+
const host = document.createElement("div");
|
|
2916
|
+
const root = createRoot(host);
|
|
2917
|
+
try {
|
|
2918
|
+
if (hasCreateRoot && typeof ReactDOM.flushSync === "function") ReactDOM.flushSync(() => root.render(element));
|
|
2919
|
+
else root.render(element);
|
|
2920
|
+
return host.innerHTML;
|
|
2921
|
+
} finally {
|
|
2922
|
+
try { root.unmount(); } catch { /* ignore */ }
|
|
3168
2923
|
}
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
2924
|
+
} catch {
|
|
2925
|
+
return "";
|
|
2926
|
+
}
|
|
2927
|
+
}
|
|
2928
|
+
|
|
2929
|
+
const channelLogoUrlCache = new Map();
|
|
2930
|
+
/** 频道品牌标 data URL,供分组头和会话行复用。 */
|
|
2931
|
+
function channelLogoUrl(id) {
|
|
2932
|
+
if (channelLogoUrlCache.has(id)) return channelLogoUrlCache.get(id);
|
|
2933
|
+
const markup = channelMarkup(h(BrandMark, { id, compact: true }));
|
|
2934
|
+
const url = markup ? `url("data:image/svg+xml,${encodeURIComponent(markup)}")` : "";
|
|
2935
|
+
channelLogoUrlCache.set(id, url);
|
|
2936
|
+
return url;
|
|
2937
|
+
}
|
|
2938
|
+
|
|
2939
|
+
/** 频道分组头图标:用品牌标覆盖官方文件夹图标,并保持悬停时可见。 */
|
|
2940
|
+
function channelIconCss() {
|
|
2941
|
+
if (channelIconCssValue !== undefined) return channelIconCssValue;
|
|
2942
|
+
if (typeof document === "undefined") {
|
|
2943
|
+
channelIconCssValue = "";
|
|
2944
|
+
return channelIconCssValue;
|
|
2945
|
+
}
|
|
2946
|
+
channelIconCssValue = CHANNEL_GROUP_IDS.map((id) => {
|
|
2947
|
+
const logo = channelLogoUrl(id);
|
|
2948
|
+
if (!logo) return "";
|
|
2949
|
+
const row = `[data-row-key="workspace:${channelWorkspaceId(id)}"]`;
|
|
2950
|
+
return `.ima-channel-official ${row}>span:first-child>svg{display:none!important}`
|
|
2951
|
+
+ `.ima-channel-official ${row}>span:first-child{display:inline-flex!important;background:${logo} center/contain no-repeat!important}`
|
|
2952
|
+
// 宿主在悬停时用 chevron 换掉文件夹;频道分组保持品牌图标可见。
|
|
2953
|
+
+ `.ima-channel-official ${row}:hover>span:first-child{display:inline-flex!important}`
|
|
2954
|
+
+ `.ima-channel-official ${row}:hover>span:nth-child(2){display:none!important}`;
|
|
2955
|
+
}).join("");
|
|
2956
|
+
return channelIconCssValue;
|
|
2957
|
+
}
|
|
2958
|
+
|
|
2959
|
+
let channelWorkspaceIconCache = { key: "", css: "" };
|
|
2960
|
+
/**
|
|
2961
|
+
* 按工作区/工作区树分组时,如果某个工作区的频道会话都来自同一个频道,
|
|
2962
|
+
* 用频道品牌标替换文件夹。混合频道的工作区保持官方文件夹图标。
|
|
2963
|
+
*/
|
|
2964
|
+
function channelWorkspaceIconCss(workspaces, memberIds) {
|
|
2965
|
+
const entries = [];
|
|
2966
|
+
for (const workspace of workspaces || []) {
|
|
2967
|
+
const workspaceId = workspace.workspaceId || workspace.id;
|
|
2968
|
+
if (!workspaceId) continue;
|
|
2969
|
+
const channels = new Set();
|
|
2970
|
+
for (const sessionId of workspace.sessionIds || []) {
|
|
2971
|
+
if (!memberIds.has(String(sessionId))) continue;
|
|
2972
|
+
const channelId = channelIdOfSession(sessionId);
|
|
2973
|
+
if (channelId) channels.add(channelId);
|
|
3178
2974
|
}
|
|
3179
|
-
if (
|
|
3180
|
-
|
|
3181
|
-
|
|
2975
|
+
if (channels.size !== 1) continue;
|
|
2976
|
+
const channelId = [...channels][0];
|
|
2977
|
+
if (!channelLogoUrl(channelId)) continue;
|
|
2978
|
+
entries.push([workspaceId, channelId]);
|
|
2979
|
+
}
|
|
2980
|
+
const key = entries.map(([workspaceId, channelId]) => `${workspaceId}\0${channelId}`).join("\0\0");
|
|
2981
|
+
if (channelWorkspaceIconCache.key === key) return channelWorkspaceIconCache.css;
|
|
2982
|
+
const css = entries.map(([workspaceId, channelId]) => {
|
|
2983
|
+
const logo = channelLogoUrl(channelId);
|
|
2984
|
+
const row = `[data-row-key=${JSON.stringify("workspace:" + workspaceId)}]`;
|
|
2985
|
+
const scope = `.ima-channel-official:not([data-mode="channel"])`;
|
|
2986
|
+
return `${scope} ${row}>span:first-child>svg{display:none!important}`
|
|
2987
|
+
+ `${scope} ${row}>span:first-child{display:inline-flex!important;background:${logo} center/contain no-repeat!important}`
|
|
2988
|
+
+ `${scope} ${row}:hover>span:first-child{display:inline-flex!important}`
|
|
2989
|
+
+ `${scope} ${row}:hover>span:nth-child(2){display:none!important}`;
|
|
2990
|
+
}).join("");
|
|
2991
|
+
channelWorkspaceIconCache = { key, css };
|
|
2992
|
+
return css;
|
|
2993
|
+
}
|
|
2994
|
+
|
|
2995
|
+
let settingsNavIconMaskValue;
|
|
2996
|
+
/** 设置导航图标:用宿主 IconQueueOutline 的几何生成 mask,保持皮肤安全。 */
|
|
2997
|
+
function settingsNavIconMask() {
|
|
2998
|
+
if (settingsNavIconMaskValue !== undefined) return settingsNavIconMaskValue;
|
|
2999
|
+
const markup = channelMarkup(h(IconQueueOutline, { size: 16 })).split("currentColor").join("#000");
|
|
3000
|
+
settingsNavIconMaskValue = `url("data:image/svg+xml,${encodeURIComponent(markup)}")`;
|
|
3001
|
+
return settingsNavIconMaskValue;
|
|
3002
|
+
}
|
|
3003
|
+
|
|
3004
|
+
/**
|
|
3005
|
+
* 官方视图选项菜单没有扩展位,注入第四个分组项「按频道」。
|
|
3006
|
+
* 只在频道页签挂载期间生效。
|
|
3007
|
+
*/
|
|
3008
|
+
function installChannelGroupOption(options) {
|
|
3009
|
+
if (typeof document === "undefined" || typeof MutationObserver === "undefined") return () => {};
|
|
3010
|
+
let frame;
|
|
3011
|
+
const closeMenu = () => document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true }));
|
|
3012
|
+
const inject = (menu) => {
|
|
3013
|
+
const text = menu.textContent || "";
|
|
3014
|
+
if (!options.groupLabel || !options.workspaceLabel
|
|
3015
|
+
|| !text.includes(options.groupLabel) || !text.includes(options.workspaceLabel)) return;
|
|
3016
|
+
if (menu.querySelector(`[${CHANNEL_GROUP_OPTION_ATTR}="true"]`) !== null) return;
|
|
3017
|
+
const items = [...menu.querySelectorAll('button[role="menuitem"]')];
|
|
3018
|
+
const first = items[0];
|
|
3019
|
+
if (!first) return;
|
|
3020
|
+
const wrapper = first.parentElement;
|
|
3021
|
+
if (!wrapper) return;
|
|
3022
|
+
const clone = wrapper.cloneNode(true);
|
|
3023
|
+
const button = clone.querySelector('button[role="menuitem"]');
|
|
3024
|
+
if (!button) return;
|
|
3025
|
+
button.setAttribute(CHANNEL_GROUP_OPTION_ATTR, "true");
|
|
3026
|
+
button.removeAttribute("aria-disabled");
|
|
3027
|
+
button.removeAttribute("disabled");
|
|
3028
|
+
button.disabled = false;
|
|
3029
|
+
button.classList.remove("danger");
|
|
3030
|
+
for (const svg of button.querySelectorAll(":scope > svg")) svg.remove();
|
|
3031
|
+
const spans = button.querySelectorAll("span");
|
|
3032
|
+
if (spans[0] !== undefined) spans[0].innerHTML = channelMarkup(h(IconQueueOutline, { size: 16 }));
|
|
3033
|
+
if (spans[1] !== undefined) spans[1].textContent = options.label;
|
|
3034
|
+
else button.textContent = options.label;
|
|
3035
|
+
if (options.checked) {
|
|
3036
|
+
const check = document.createElement("span");
|
|
3037
|
+
check.innerHTML = channelMarkup(h(IconCheckOutline, { size: 16 }));
|
|
3038
|
+
const svg = check.firstElementChild;
|
|
3039
|
+
if (svg !== null) {
|
|
3040
|
+
if (svg.style) svg.style.marginLeft = "auto";
|
|
3041
|
+
button.append(svg);
|
|
3182
3042
|
}
|
|
3183
|
-
return;
|
|
3184
3043
|
}
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
|
|
3190
|
-
|
|
3191
|
-
|
|
3192
|
-
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
-
|
|
3198
|
-
|
|
3199
|
-
|
|
3044
|
+
button.addEventListener("click", (event) => {
|
|
3045
|
+
event.preventDefault();
|
|
3046
|
+
event.stopPropagation();
|
|
3047
|
+
closeMenu();
|
|
3048
|
+
window.setTimeout(options.onSelect, 0);
|
|
3049
|
+
});
|
|
3050
|
+
wrapper.parentElement?.insertBefore(clone, wrapper);
|
|
3051
|
+
};
|
|
3052
|
+
const scan = () => {
|
|
3053
|
+
frame = undefined;
|
|
3054
|
+
for (const menu of document.querySelectorAll('[role="menu"]')) inject(menu);
|
|
3055
|
+
};
|
|
3056
|
+
const schedule = () => {
|
|
3057
|
+
if (frame !== undefined) return;
|
|
3058
|
+
frame = window.requestAnimationFrame(scan);
|
|
3059
|
+
};
|
|
3060
|
+
const observer = new MutationObserver(schedule);
|
|
3061
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
3062
|
+
schedule();
|
|
3063
|
+
return () => {
|
|
3064
|
+
if (frame !== undefined) window.cancelAnimationFrame(frame);
|
|
3065
|
+
observer.disconnect();
|
|
3066
|
+
for (const item of document.querySelectorAll(`[${CHANNEL_GROUP_OPTION_ATTR}="true"]`)) item.parentElement?.remove();
|
|
3067
|
+
};
|
|
3068
|
+
}
|
|
3069
|
+
|
|
3070
|
+
/**
|
|
3071
|
+
* 官方工作区分组菜单只有重命名/删除;频道组合成工作区需要「频道设置」,因此注入设置入口。
|
|
3072
|
+
*/
|
|
3073
|
+
function installChannelGroupMenu(options) {
|
|
3074
|
+
if (typeof document === "undefined" || typeof MutationObserver === "undefined") return () => {};
|
|
3075
|
+
let channelId;
|
|
3076
|
+
let rememberedAt = 0;
|
|
3077
|
+
let frame;
|
|
3078
|
+
const closeMenu = () => document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true }));
|
|
3079
|
+
const remember = (event) => {
|
|
3080
|
+
const target = event.target && typeof event.target.closest === "function" ? event.target : undefined;
|
|
3081
|
+
if (target === undefined) return;
|
|
3082
|
+
const row = target.closest(`[data-row-key^="workspace:${CHANNEL_WORKSPACE_PREFIX}"]`);
|
|
3083
|
+
if (row !== null) {
|
|
3084
|
+
const key = row.getAttribute("data-row-key") || "";
|
|
3085
|
+
channelId = channelIdFromWorkspaceId(key.slice("workspace:".length));
|
|
3086
|
+
rememberedAt = performance.now();
|
|
3200
3087
|
return;
|
|
3201
3088
|
}
|
|
3202
|
-
if ((
|
|
3203
|
-
|
|
3204
|
-
|
|
3089
|
+
if (target.closest('[role="menu"]') === null) channelId = undefined;
|
|
3090
|
+
};
|
|
3091
|
+
const hiddenItems = new Map();
|
|
3092
|
+
const hideOthers = (menu, ours) => {
|
|
3093
|
+
for (const item of menu.querySelectorAll('button[role="menuitem"]')) {
|
|
3094
|
+
if (ours.has(item)) continue;
|
|
3095
|
+
if (!hiddenItems.has(item)) {
|
|
3096
|
+
hiddenItems.set(item, {
|
|
3097
|
+
display: item.style.display,
|
|
3098
|
+
ariaHidden: item.getAttribute("aria-hidden"),
|
|
3099
|
+
});
|
|
3100
|
+
}
|
|
3101
|
+
item.style.display = "none";
|
|
3102
|
+
item.setAttribute("aria-hidden", "true");
|
|
3205
3103
|
}
|
|
3206
|
-
|
|
3207
|
-
|
|
3208
|
-
|
|
3104
|
+
};
|
|
3105
|
+
const inject = (menu) => {
|
|
3106
|
+
if (channelId === undefined || performance.now() - rememberedAt > 2000) return;
|
|
3107
|
+
if (menu.querySelector(`[${CHANNEL_GROUP_MENU_ATTR}="true"]`) !== null) return;
|
|
3108
|
+
const items = [...menu.querySelectorAll('button[role="menuitem"]')];
|
|
3109
|
+
if (items.length === 0) return;
|
|
3110
|
+
const menuText = items.map((item) => item.textContent || "").join(" ");
|
|
3111
|
+
if (!/(删除工作区|Delete workspace)/i.test(menuText)) return;
|
|
3112
|
+
const group = options.resolve(channelId);
|
|
3113
|
+
if (!group) return;
|
|
3114
|
+
const template = items.find((item) => /^(重命名|Rename)$/i.test((item.textContent || "").trim()))
|
|
3115
|
+
|| items.find((item) => !item.disabled && !/danger|删除|Delete/i.test(item.textContent || ""))
|
|
3116
|
+
|| items[0];
|
|
3117
|
+
const wrapper = template.parentElement;
|
|
3118
|
+
if (!wrapper) return;
|
|
3119
|
+
const build = (label, icon, onClick) => {
|
|
3120
|
+
const clone = wrapper.cloneNode(true);
|
|
3121
|
+
const button = clone.querySelector('button[role="menuitem"]');
|
|
3122
|
+
if (!button) return undefined;
|
|
3123
|
+
clone.removeAttribute(CHANNEL_GROUP_MENU_ATTR);
|
|
3124
|
+
button.removeAttribute(CHANNEL_GROUP_MENU_ATTR);
|
|
3125
|
+
button.removeAttribute("aria-disabled");
|
|
3126
|
+
button.removeAttribute("disabled");
|
|
3127
|
+
button.disabled = false;
|
|
3128
|
+
button.style.opacity = "";
|
|
3129
|
+
button.style.cursor = "";
|
|
3130
|
+
button.classList.remove("danger");
|
|
3131
|
+
button.setAttribute(CHANNEL_GROUP_MENU_ATTR, "true");
|
|
3132
|
+
const spans = button.querySelectorAll("span");
|
|
3133
|
+
if (spans[0] !== undefined) spans[0].innerHTML = icon;
|
|
3134
|
+
if (spans[1] !== undefined) spans[1].textContent = label;
|
|
3135
|
+
else button.textContent = label;
|
|
3136
|
+
let fired = false;
|
|
3137
|
+
const activate = (event) => {
|
|
3138
|
+
if (fired) return;
|
|
3139
|
+
fired = true;
|
|
3140
|
+
event.preventDefault();
|
|
3141
|
+
event.stopPropagation();
|
|
3142
|
+
if (typeof event.stopImmediatePropagation === "function") event.stopImmediatePropagation();
|
|
3143
|
+
closeMenu();
|
|
3144
|
+
// 等宿主菜单完成卸载后再打开设置,避免同一次点击被菜单的关闭逻辑吞掉。
|
|
3145
|
+
window.setTimeout(onClick, 50);
|
|
3146
|
+
};
|
|
3147
|
+
button.addEventListener("click", activate);
|
|
3148
|
+
button.addEventListener("pointerup", (event) => {
|
|
3149
|
+
if (event.button === 0) activate(event);
|
|
3150
|
+
});
|
|
3151
|
+
return clone;
|
|
3152
|
+
};
|
|
3153
|
+
const node = build(options.settingsLabel, channelMarkup(h(ChannelMenuSettingsIcon)), () => options.onSettings(group));
|
|
3154
|
+
if (node) wrapper.parentElement?.insertBefore(node, wrapper);
|
|
3155
|
+
const injected = new Set(menu.querySelectorAll(`[${CHANNEL_GROUP_MENU_ATTR}="true"]`));
|
|
3156
|
+
if (injected.size > 0) hideOthers(menu, injected);
|
|
3157
|
+
};
|
|
3158
|
+
const scan = () => {
|
|
3159
|
+
frame = undefined;
|
|
3160
|
+
for (const menu of document.querySelectorAll('[role="menu"]')) inject(menu);
|
|
3161
|
+
};
|
|
3162
|
+
const schedule = () => {
|
|
3163
|
+
if (frame !== undefined) return;
|
|
3164
|
+
frame = window.requestAnimationFrame(scan);
|
|
3165
|
+
};
|
|
3166
|
+
document.addEventListener("pointerdown", remember, true);
|
|
3167
|
+
document.addEventListener("click", remember, true);
|
|
3168
|
+
const observer = new MutationObserver(schedule);
|
|
3169
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
3170
|
+
schedule();
|
|
3171
|
+
return () => {
|
|
3172
|
+
if (frame !== undefined) window.cancelAnimationFrame(frame);
|
|
3173
|
+
observer.disconnect();
|
|
3174
|
+
document.removeEventListener("pointerdown", remember, true);
|
|
3175
|
+
document.removeEventListener("click", remember, true);
|
|
3176
|
+
for (const [item, previous] of hiddenItems) {
|
|
3177
|
+
item.style.display = previous.display;
|
|
3178
|
+
if (previous.ariaHidden === null) item.removeAttribute("aria-hidden");
|
|
3179
|
+
else item.setAttribute("aria-hidden", previous.ariaHidden);
|
|
3209
3180
|
}
|
|
3210
|
-
|
|
3211
|
-
|
|
3212
|
-
method: "POST",
|
|
3213
|
-
headers: { "content-type": "application/json" },
|
|
3214
|
-
body: JSON.stringify(Object.assign({ sessionId: sess.sessionId }, extra || {})),
|
|
3215
|
-
}).then((data) => { if (data.ok) syncList(data.groups); }).catch(() => undefined);
|
|
3181
|
+
hiddenItems.clear();
|
|
3182
|
+
for (const item of document.querySelectorAll(`[${CHANNEL_GROUP_MENU_ATTR}="true"]`)) item.parentElement?.remove();
|
|
3216
3183
|
};
|
|
3217
|
-
if (renaming) {
|
|
3218
|
-
return h("div", { className: rowClass, ref: rowRef },
|
|
3219
|
-
h("input", {
|
|
3220
|
-
className: native ? "ima-n-rename" : "ima-rename",
|
|
3221
|
-
value: draft,
|
|
3222
|
-
autoFocus: true,
|
|
3223
|
-
"aria-label": t("rail.renameAria"),
|
|
3224
|
-
onChange: (e) => setDraft(e.target.value),
|
|
3225
|
-
onClick: (e) => e.stopPropagation(),
|
|
3226
|
-
onKeyDown: (e) => {
|
|
3227
|
-
if (e.key === "Enter") { e.preventDefault(); setRenaming(false); run("rename", { title: draft.trim() || title }); }
|
|
3228
|
-
if (e.key === "Escape") { e.preventDefault(); setRenaming(false); setDraft(title); }
|
|
3229
|
-
},
|
|
3230
|
-
onBlur: () => { setRenaming(false); if (draft.trim() && draft.trim() !== title) run("rename", { title: draft.trim() }); },
|
|
3231
|
-
}),
|
|
3232
|
-
);
|
|
3233
|
-
}
|
|
3234
|
-
const displayTitle = String(hoverTitle || title).trim() || title;
|
|
3235
|
-
// 0.1.7 的 Menu 渲染 children。不请求 pin,频道会话不提供置顶。更早版本不渲染 children,仍用下面的 items。
|
|
3236
|
-
const menuSlotItems = hostMenuRendersChildren()
|
|
3237
|
-
? ["rename", "fork", "archive", "archive-manager.delete-session"].map((only) => renderHostSlot(renderSlot, "sidebar.workspaces.session.menu.item", {
|
|
3238
|
-
sessionId: sess.sessionId,
|
|
3239
|
-
displayTitle,
|
|
3240
|
-
}, { hookContext: [menu, (open) => onMenuChange(!!open)], only }))
|
|
3241
|
-
: undefined;
|
|
3242
|
-
// 宿主槽位被跳过时不能留下一个空菜单,退回本地 items。
|
|
3243
|
-
const menuSlot = menuSlotItems && menuSlotItems.some((node) => node != null) ? menuSlotItems : undefined;
|
|
3244
|
-
const menuItems = menuSlot !== undefined ? [] : (archived
|
|
3245
|
-
? [
|
|
3246
|
-
{ id: "unarchive", label: t("rail.unarchive"), icon: h(IconArchiveOutline20, { size: 16 }) },
|
|
3247
|
-
...(canDelete ? [{ id: "delete-session", label: t("rail.deleteSession"), icon: h(IconTrashOutline16), danger: true }] : []),
|
|
3248
|
-
]
|
|
3249
|
-
: [
|
|
3250
|
-
{ id: "rename", label: t("rail.rename"), icon: h(IconEditOutline16) },
|
|
3251
|
-
{ id: "fork", label: t("rail.fork"), icon: h(IconBranchOutline16) },
|
|
3252
|
-
{ id: "archive", label: t("rail.archive"), icon: h(IconArchiveOutline20, { size: 16 }) },
|
|
3253
|
-
...(canDelete ? [{ id: "delete-session", label: t("rail.deleteSession"), icon: h(IconTrashOutline16), danger: true }] : []),
|
|
3254
|
-
]);
|
|
3255
|
-
const row = h("div", {
|
|
3256
|
-
ref: rowRef,
|
|
3257
|
-
className: rowClass,
|
|
3258
|
-
role: "treeitem",
|
|
3259
|
-
tabIndex: 0,
|
|
3260
|
-
"aria-selected": selected,
|
|
3261
|
-
"data-n-menu-root": sess.sessionId,
|
|
3262
|
-
onClick: () => { setMenu(false); hideHover(); onOpen(sess.sessionId); },
|
|
3263
|
-
onMouseEnter: () => {
|
|
3264
|
-
startSessionTitleMarquee(titleRef.current, titleFrame.current);
|
|
3265
|
-
if (!useOfficialHover) showHover();
|
|
3266
|
-
},
|
|
3267
|
-
onMouseLeave: () => {
|
|
3268
|
-
stopSessionTitleMarquee(titleRef.current, titleFrame.current);
|
|
3269
|
-
if (!useOfficialHover) hideHover();
|
|
3270
|
-
},
|
|
3271
|
-
onKeyDown: (e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); setMenu(false); onOpen(sess.sessionId); } },
|
|
3272
|
-
onContextMenu: (e) => { e.preventDefault(); e.stopPropagation(); hideHover(); onMenuChange(true); },
|
|
3273
|
-
},
|
|
3274
|
-
native && h("span", { className: "ima-n-slot" }, showDot && typeof StateDot === "function" ? h(StateDot, { state: primary.state === "ongoing" ? "ongoing" : primary.state === "warning" ? "warning" : "done", size: 10 }) : null),
|
|
3275
|
-
h("span", {
|
|
3276
|
-
ref: native ? titleRef : undefined,
|
|
3277
|
-
className: native ? "ima-n-title" : "dcu-wb-session-title",
|
|
3278
|
-
onDoubleClick: (e) => {
|
|
3279
|
-
if (!sessionActions || typeof sessionActions.renameSession !== "function") return;
|
|
3280
|
-
e.stopPropagation();
|
|
3281
|
-
setRenaming(true);
|
|
3282
|
-
},
|
|
3283
|
-
}, title),
|
|
3284
|
-
native && h("span", { className: "ima-n-time", "aria-hidden": trailing ? true : undefined }, trailing || timeLabel(sess.updatedAt, t)),
|
|
3285
|
-
h("span", { className: native ? "ima-n-acts" : "dcu-wb-actions" },
|
|
3286
|
-
menuSlot === undefined && archived && h("button", {
|
|
3287
|
-
type: "button",
|
|
3288
|
-
className: "ima-n-restore",
|
|
3289
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
3290
|
-
onClick: (e) => { e.stopPropagation(); run("unarchive"); },
|
|
3291
|
-
}, t("rail.unarchive")),
|
|
3292
|
-
h(HostMenu, {
|
|
3293
|
-
open: menu,
|
|
3294
|
-
onClose: () => { onMenuChange(false); },
|
|
3295
|
-
items: menuItems,
|
|
3296
|
-
onSelect: (action) => {
|
|
3297
|
-
onMenuChange(false);
|
|
3298
|
-
if (action === "rename") setRenaming(true);
|
|
3299
|
-
if (action === "fork") run("fork");
|
|
3300
|
-
if (action === "archive") run("archive");
|
|
3301
|
-
if (action === "unarchive") run("unarchive");
|
|
3302
|
-
if (action === "delete-session") onDeleteSession && onDeleteSession();
|
|
3303
|
-
},
|
|
3304
|
-
portal: true,
|
|
3305
|
-
closeOnPointerLeave: true,
|
|
3306
|
-
anchor: h("button", {
|
|
3307
|
-
type: "button",
|
|
3308
|
-
className: native ? "ima-n-ico" : "dcu-wb-more",
|
|
3309
|
-
"data-ima-session-more": "",
|
|
3310
|
-
"aria-expanded": menu,
|
|
3311
|
-
"aria-label": t("action.more", { channel: title }),
|
|
3312
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
3313
|
-
onClick: (e) => { e.stopPropagation(); hideHover(); onMenuChange(!menu); },
|
|
3314
|
-
}, h(IconEllipsisOutline16, { size: 16 })),
|
|
3315
|
-
}, menuSlot),
|
|
3316
|
-
renderHostSlot(renderSlot, "sidebar.workspaces.session.row.action", { sessionId: sess.sessionId, displayTitle }, { only: "archive" }),
|
|
3317
|
-
),
|
|
3318
|
-
!useOfficialHover && hoverOpen && !menu && native && typeof document !== "undefined" && ReactDOM.createPortal(h(SessionHoverCard, {
|
|
3319
|
-
title: hoverTitle,
|
|
3320
|
-
time: hoverTimeLabel(sess.updatedAt, t),
|
|
3321
|
-
running,
|
|
3322
|
-
statuses,
|
|
3323
|
-
t,
|
|
3324
|
-
style: hoverStyle,
|
|
3325
|
-
cardRef: hoverRef,
|
|
3326
|
-
onMouseEnter: showHover,
|
|
3327
|
-
onMouseLeave: hideHover,
|
|
3328
|
-
}), document.body),
|
|
3329
|
-
);
|
|
3330
|
-
if (useOfficialHover) {
|
|
3331
|
-
return h(HoverCard, {
|
|
3332
|
-
anchor: row,
|
|
3333
|
-
content: h(SessionHoverContent, { title: hoverTitle, time: hoverTimeLabel(sess.updatedAt, t), running, statuses, t }),
|
|
3334
|
-
openDelayMs: 800,
|
|
3335
|
-
disabled: menu,
|
|
3336
|
-
copyText: displayTitle,
|
|
3337
|
-
copyLabel: t("copy"),
|
|
3338
|
-
copiedLabel: t("hover.copied"),
|
|
3339
|
-
});
|
|
3340
|
-
}
|
|
3341
|
-
return row;
|
|
3342
3184
|
}
|
|
3343
3185
|
|
|
3344
|
-
function
|
|
3345
|
-
|
|
3346
|
-
...(channelLogo ? [{ id: "channel-settings", label: t("rail.channelSettings"), icon: h(ChannelSettingsIcon) }] : []),
|
|
3347
|
-
...(canArchiveGroup ? [
|
|
3348
|
-
{ type: "separator", id: "archive-separator" },
|
|
3349
|
-
{ id: "archive-group", label: t("rail.archiveGroup"), icon: h(IconArchiveOutline20, { size: 16 }), danger: true },
|
|
3350
|
-
] : []),
|
|
3351
|
-
];
|
|
3352
|
-
const rowClass = "ima-n-row" + (hasCurrentSession ? " has-current-session" : "") + (menuOpen ? " is-menu" : "");
|
|
3353
|
-
return h("div", {
|
|
3354
|
-
className: rowClass,
|
|
3355
|
-
role: "treeitem",
|
|
3356
|
-
"aria-expanded": expanded,
|
|
3357
|
-
"data-n-group": id,
|
|
3358
|
-
onClick: onToggle,
|
|
3359
|
-
},
|
|
3360
|
-
h("span", { className: "ima-n-slot ima-n-folder" }, channelLogo ? h(Logo, { id, small: true }) : h(IconFolderClose, { size: 16 })),
|
|
3361
|
-
h("span", { className: "ima-n-project-text" }, h("span", { className: "ima-n-title" }, name)),
|
|
3362
|
-
h("span", { className: "ima-n-acts" },
|
|
3363
|
-
h(HostMenu, {
|
|
3364
|
-
open: menuOpen,
|
|
3365
|
-
onClose: () => { onMenuChange(false); },
|
|
3366
|
-
items,
|
|
3367
|
-
onSelect: (action) => {
|
|
3368
|
-
onMenuChange(false);
|
|
3369
|
-
if (action === "channel-settings") onChannelSettings && onChannelSettings();
|
|
3370
|
-
if (action === "archive-group") onArchiveGroup && onArchiveGroup();
|
|
3371
|
-
},
|
|
3372
|
-
portal: true,
|
|
3373
|
-
closeOnPointerLeave: true,
|
|
3374
|
-
anchor: h("button", {
|
|
3375
|
-
type: "button",
|
|
3376
|
-
className: "ima-n-ico",
|
|
3377
|
-
"aria-label": t("rail.groupActions", { name }),
|
|
3378
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
3379
|
-
onClick: (e) => { e.stopPropagation(); onMenuChange(!menuOpen); },
|
|
3380
|
-
}, h(IconEllipsisOutline16, { size: 16 })),
|
|
3381
|
-
}),
|
|
3382
|
-
),
|
|
3383
|
-
);
|
|
3186
|
+
function ChannelMenuSettingsIcon() {
|
|
3187
|
+
return h(IconSettingsOutline16, { size: 16 });
|
|
3384
3188
|
}
|
|
3385
3189
|
|
|
3386
|
-
function
|
|
3387
|
-
|
|
3388
|
-
return h(ChannelRailView, props);
|
|
3190
|
+
function ChannelUnavailable({ t }) {
|
|
3191
|
+
return h("div", { className: "ima-channel-unavailable" }, t("rail.treeUnavailable"));
|
|
3389
3192
|
}
|
|
3390
3193
|
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
:
|
|
3395
|
-
const archivedIds = typeof props.useWorkspaces === "function"
|
|
3396
|
-
? props.useWorkspaces((state) => (state && state.archivedSessionIds) || [])
|
|
3397
|
-
: (props.archivedIds || []);
|
|
3398
|
-
const sessionById = typeof props.useSessions === "function"
|
|
3399
|
-
? props.useSessions((state) => (state && state.byId) || {})
|
|
3400
|
-
: {};
|
|
3401
|
-
const workspaceItems = typeof props.useWorkspaces === "function"
|
|
3402
|
-
? props.useWorkspaces((state) => (state && state.items) || [])
|
|
3403
|
-
: (props.workspaceItems || []);
|
|
3404
|
-
const sessionStatuses = typeof props.useSessionStatus === "function"
|
|
3405
|
-
? props.useSessionStatus((state) => state)
|
|
3406
|
-
: props.sessionStatuses;
|
|
3407
|
-
const projections = typeof props.useSessions === "function"
|
|
3408
|
-
? props.useSessions((state) => (state && state.projectionsBySession) || {})
|
|
3409
|
-
: (props.projections || {});
|
|
3410
|
-
return h(ChannelRailView, Object.assign({}, props, {
|
|
3411
|
-
selectedId: selectedId || props.selectedId || null,
|
|
3412
|
-
archivedIds,
|
|
3413
|
-
sessionById,
|
|
3414
|
-
workspaceItems,
|
|
3415
|
-
sessionStatuses,
|
|
3416
|
-
projections,
|
|
3417
|
-
}));
|
|
3418
|
-
}
|
|
3419
|
-
|
|
3420
|
-
function ChannelRailView(props) {
|
|
3421
|
-
const t = props.t || fallbackT;
|
|
3422
|
-
const [groups, setGroups] = useState([]);
|
|
3423
|
-
const [folded, setFolded] = useState({});
|
|
3424
|
-
const [error, setError] = useState("");
|
|
3425
|
-
const [openMenu, setOpenMenu] = useState();
|
|
3426
|
-
const [openGroupMenu, setOpenGroupMenu] = useState();
|
|
3427
|
-
const [query, setQuery] = useState("");
|
|
3428
|
-
const [sort, setSort] = useState("time");
|
|
3429
|
-
const [groupMode, setGroupMode] = useState("workspace");
|
|
3430
|
-
const [archiveManagerInstalled, setArchiveManagerInstalled] = useState(() => typeof document !== "undefined" && hasArchiveManagerPlugin(document));
|
|
3431
|
-
const [deleteTarget, setDeleteTarget] = useState();
|
|
3432
|
-
const [deleteBusy, setDeleteBusy] = useState(false);
|
|
3433
|
-
const [deleteError, setDeleteError] = useState();
|
|
3434
|
-
const [archiveGroupTarget, setArchiveGroupTarget] = useState();
|
|
3435
|
-
const [archiveGroupBusy, setArchiveGroupBusy] = useState(false);
|
|
3436
|
-
const [archiveGroupError, setArchiveGroupError] = useState();
|
|
3437
|
-
const [archivedFilter, setArchivedFilter] = useState("default");
|
|
3438
|
-
const [stopArchiveTarget, setStopArchiveTarget] = useState();
|
|
3439
|
-
const [stopArchiveBusy, setStopArchiveBusy] = useState(false);
|
|
3440
|
-
const [stopArchiveError, setStopArchiveError] = useState();
|
|
3441
|
-
const selectedId = props.selectedId;
|
|
3442
|
-
const archived = new Set(props.archivedIds || []);
|
|
3443
|
-
const skin = props.skin || channelSkin;
|
|
3444
|
-
const native = skin !== "codex";
|
|
3445
|
-
const open = (id) => openListedSession(resolveHostSessionId(id, props.sessionById), props.openSession || props.open);
|
|
3446
|
-
const canDelete = canDeleteChannelSession(archiveManagerInstalled, props.deleteSession);
|
|
3447
|
-
const canArchiveGroup = canArchiveChannelGroup(archiveManagerInstalled, props.archiveSession);
|
|
3448
|
-
useEffect(() => {
|
|
3449
|
-
ensureStyle();
|
|
3450
|
-
return channelRefresh.subscribe((data, error) => {
|
|
3451
|
-
if (error) { setError(t("error.connection")); return; }
|
|
3452
|
-
if (data.ok) { setGroups(data.groups || []); setError(""); }
|
|
3453
|
-
else setError(serverText(data.error, t) || t("error.load"));
|
|
3454
|
-
});
|
|
3455
|
-
}, []);
|
|
3456
|
-
useEffect(() => {
|
|
3457
|
-
if (typeof document === "undefined" || typeof MutationObserver === "undefined") return undefined;
|
|
3458
|
-
const refresh = () => { setArchiveManagerInstalled(hasArchiveManagerPlugin(document)); };
|
|
3459
|
-
refresh();
|
|
3460
|
-
const observer = new MutationObserver(refresh);
|
|
3461
|
-
observer.observe(document.documentElement, { childList: true, subtree: true });
|
|
3462
|
-
return () => observer.disconnect();
|
|
3463
|
-
}, []);
|
|
3464
|
-
const confirmDelete = () => {
|
|
3465
|
-
if (!deleteTarget || typeof props.deleteSession !== "function" || deleteBusy) return;
|
|
3466
|
-
const target = deleteTarget;
|
|
3467
|
-
setDeleteBusy(true);
|
|
3468
|
-
setDeleteError(undefined);
|
|
3469
|
-
Promise.resolve(props.deleteSession(target.id))
|
|
3470
|
-
.then(() => api("/sessions/remove", {
|
|
3471
|
-
method: "POST",
|
|
3472
|
-
headers: { "content-type": "application/json" },
|
|
3473
|
-
body: JSON.stringify({ sessionId: target.id }),
|
|
3474
|
-
}).then((data) => { if (data.ok && data.groups) setGroups(data.groups); }).catch(() => undefined))
|
|
3475
|
-
.then(() => { setDeleteTarget(undefined); })
|
|
3476
|
-
.catch((caught) => { setDeleteError(caught instanceof Error ? caught.message : t("error.action")); })
|
|
3477
|
-
.finally(() => { setDeleteBusy(false); });
|
|
3478
|
-
};
|
|
3479
|
-
const confirmArchiveGroup = () => {
|
|
3480
|
-
if (!archiveGroupTarget || typeof props.archiveSession !== "function" || archiveGroupBusy) return;
|
|
3481
|
-
const target = archiveGroupTarget;
|
|
3482
|
-
setArchiveGroupBusy(true);
|
|
3483
|
-
setArchiveGroupError(undefined);
|
|
3484
|
-
archiveChannelGroup(target.sessionIds, props.archiveSession)
|
|
3485
|
-
.then(() => channelRefresh.invalidate().catch(() => undefined))
|
|
3486
|
-
.then(() => { setArchiveGroupTarget(undefined); })
|
|
3487
|
-
.catch((caught) => {
|
|
3488
|
-
if (openStopArchive(caught, { id: target.id, title: target.name, sessionIds: target.sessionIds, group: true }, (next) => {
|
|
3489
|
-
setArchiveGroupTarget(undefined);
|
|
3490
|
-
setStopArchiveError(undefined);
|
|
3491
|
-
setStopArchiveTarget(next);
|
|
3492
|
-
})) return;
|
|
3493
|
-
setArchiveGroupError(caught instanceof Error ? caught.message : t("error.action"));
|
|
3494
|
-
})
|
|
3495
|
-
.finally(() => { setArchiveGroupBusy(false); });
|
|
3496
|
-
};
|
|
3497
|
-
const confirmStopArchive = () => {
|
|
3498
|
-
if (!stopArchiveTarget || typeof props.archiveSession !== "function" || stopArchiveBusy) return;
|
|
3499
|
-
const target = stopArchiveTarget;
|
|
3500
|
-
setStopArchiveBusy(true);
|
|
3501
|
-
setStopArchiveError(undefined);
|
|
3502
|
-
const work = finishStopArchive(target, props.archiveSession).then((kind) => {
|
|
3503
|
-
if (kind === "group") return channelRefresh.invalidate().catch(() => undefined);
|
|
3504
|
-
if (kind !== "session") return;
|
|
3505
|
-
return api("/sessions/remove", {
|
|
3506
|
-
method: "POST",
|
|
3507
|
-
headers: { "content-type": "application/json" },
|
|
3508
|
-
body: JSON.stringify({ sessionId: target.id }),
|
|
3509
|
-
}).then((data) => { if (data.ok && data.groups) setGroups(data.groups); }).catch(() => undefined);
|
|
3510
|
-
});
|
|
3511
|
-
work
|
|
3512
|
-
.then(() => { setStopArchiveTarget(undefined); })
|
|
3513
|
-
.catch((caught) => { setStopArchiveError(caught instanceof Error ? caught.message : t("error.action")); })
|
|
3514
|
-
.finally(() => { setStopArchiveBusy(false); });
|
|
3515
|
-
};
|
|
3516
|
-
const needle = query.trim().toLowerCase();
|
|
3517
|
-
const visibleGroups = groups.map((g) => {
|
|
3518
|
-
const sessions = (g.sessions || []).map((sess) => {
|
|
3519
|
-
const host = props.sessionById && props.sessionById[sess.sessionId];
|
|
3520
|
-
// 手动标题及来源未知的旧名称,交给后端可靠标题事件同步。
|
|
3521
|
-
if (sess.titleSource === "user" || (!sess.titleSource && typeof sess.title === "string" && sess.title.trim())) return sess;
|
|
3522
|
-
return host && typeof host.title === "string" && host.title.trim()
|
|
3523
|
-
? Object.assign({}, sess, { title: host.title }) : sess;
|
|
3524
|
-
}).filter((sess) => channelSessionVisible(sess.sessionId, archived, archivedFilter)).map((sess) => Object.assign({}, sess, { channelId: g.id }));
|
|
3525
|
-
if (!needle) return Object.assign({}, g, { sessions });
|
|
3526
|
-
const nameHit = String(channelLabel(g, t)).toLowerCase().includes(needle);
|
|
3527
|
-
return Object.assign({}, g, { sessions: nameHit ? sessions : sessions.filter((sess) => String(sess.title || sess.chatId || "").toLowerCase().includes(needle)) });
|
|
3528
|
-
}).filter((g) => (g.sessions || []).length > 0);
|
|
3529
|
-
if (groupMode === "workspace-tree") {
|
|
3530
|
-
const flat = visibleGroups.flatMap((g) => g.sessions || []);
|
|
3531
|
-
visibleGroups.splice(0, visibleGroups.length, ...groupChannelSessionsByWorkspaceTree(flat, props.workspaceItems || [], t("rail.ungrouped")));
|
|
3532
|
-
} else if (sort === "time") {
|
|
3533
|
-
visibleGroups.sort((a, b) => {
|
|
3534
|
-
const latest = (g) => Math.max(0, ...(g.sessions || []).map((sess) => Date.parse(sess.updatedAt || "") || 0));
|
|
3535
|
-
return latest(b) - latest(a);
|
|
3536
|
-
});
|
|
3194
|
+
class ChannelTreeGuard extends React.Component {
|
|
3195
|
+
constructor(props) {
|
|
3196
|
+
super(props);
|
|
3197
|
+
this.state = { failed: false };
|
|
3537
3198
|
}
|
|
3538
|
-
|
|
3539
|
-
|
|
3540
|
-
|
|
3541
|
-
|
|
3542
|
-
|
|
3199
|
+
static getDerivedStateFromError() {
|
|
3200
|
+
return { failed: true };
|
|
3201
|
+
}
|
|
3202
|
+
componentDidCatch(error) {
|
|
3203
|
+
console.warn("[dsh-im-connect] 官方频道树渲染失败", error);
|
|
3204
|
+
}
|
|
3205
|
+
render() {
|
|
3206
|
+
return this.state.failed ? h(ChannelUnavailable, { t: this.props.t }) : this.props.children;
|
|
3543
3207
|
}
|
|
3544
|
-
return h("div", { className: native ? "ima-native ima-rail" : "dcu-wb ima-rail" },
|
|
3545
|
-
h("style", null, WB_CSS),
|
|
3546
|
-
h(ChannelWorkspaceHead, { query, sort, groupMode, archivedFilter, onQuery: setQuery, onSort: setSort, onGroupMode: setGroupMode, onArchivedFilterChange: setArchivedFilter, t }),
|
|
3547
|
-
h("div", { className: native ? "ima-n-list-area" : "dcu-wb-list-area" },
|
|
3548
|
-
h("div", { className: native ? "ima-native-tree" : "dcu-wb-tree", role: "tree" },
|
|
3549
|
-
error && h("div", { className: native ? "ima-native-empty" : "dcu-wb-empty" }, error),
|
|
3550
|
-
!error && visibleGroups.length === 0 && h("div", { className: native ? "ima-native-empty" : "dcu-wb-empty" }, t("rail.empty")),
|
|
3551
|
-
...visibleGroups.map((g) => {
|
|
3552
|
-
const visible = g.sessions || [];
|
|
3553
|
-
const expanded = !folded[g.id];
|
|
3554
|
-
const hasCurrentSession = typeof selectedId === "string" && visible.some((sess) => isCurrentListedSession(selectedId, sess.sessionId, props.sessionById));
|
|
3555
|
-
const depth = g.depth || 0;
|
|
3556
|
-
const channelLogo = groupMode !== "workspace-tree" || !!g.channelId;
|
|
3557
|
-
const groupStyle = depth > 0 ? { "--dsh-workspace-indent": (depth * 12) + "px" } : undefined;
|
|
3558
|
-
return h("div", { key: g.id || "ungrouped", className: native ? "ima-native-project" : "dcu-wb-project", style: groupStyle },
|
|
3559
|
-
groupMode !== "list" && (g.keep || visible.length > 0) && (native
|
|
3560
|
-
? h(ChannelGroupRow, {
|
|
3561
|
-
id: g.channelId || g.id,
|
|
3562
|
-
channelLogo,
|
|
3563
|
-
name: channelLabel(g, t),
|
|
3564
|
-
expanded,
|
|
3565
|
-
hasCurrentSession,
|
|
3566
|
-
menuOpen: openGroupMenu === g.id,
|
|
3567
|
-
canArchiveGroup,
|
|
3568
|
-
onToggle: () => setFolded({ ...folded, [g.id]: !folded[g.id] }),
|
|
3569
|
-
onMenuChange: (next) => {
|
|
3570
|
-
setOpenMenu(undefined);
|
|
3571
|
-
setOpenGroupMenu(next ? g.id : undefined);
|
|
3572
|
-
},
|
|
3573
|
-
onChannelSettings: () => {
|
|
3574
|
-
const channelId = g.channelId || g.id;
|
|
3575
|
-
if (typeof props.openChannelSettings === "function") props.openChannelSettings({ channelId, name: channelLabel({ id: channelId, label: g.label }, t) });
|
|
3576
|
-
},
|
|
3577
|
-
onArchiveGroup: () => {
|
|
3578
|
-
setArchiveGroupError(undefined);
|
|
3579
|
-
setArchiveGroupTarget({
|
|
3580
|
-
id: g.id,
|
|
3581
|
-
name: channelLabel(g, t),
|
|
3582
|
-
sessionIds: visible.map((sess) => sess.sessionId),
|
|
3583
|
-
});
|
|
3584
|
-
},
|
|
3585
|
-
t,
|
|
3586
|
-
})
|
|
3587
|
-
: h("button", {
|
|
3588
|
-
className: "dcu-wb-project-head",
|
|
3589
|
-
type: "button",
|
|
3590
|
-
role: "treeitem",
|
|
3591
|
-
"aria-expanded": expanded,
|
|
3592
|
-
onClick: () => setFolded({ ...folded, [g.id]: !folded[g.id] }),
|
|
3593
|
-
},
|
|
3594
|
-
h("span", { className: "dcu-wb-folder" }, h(Logo, { id: g.id, small: true })),
|
|
3595
|
-
h("span", { className: "dcu-wb-project-title" }, channelLabel(g, t)),
|
|
3596
|
-
)
|
|
3597
|
-
),
|
|
3598
|
-
(groupMode === "list" || !folded[g.id]) && visible.length > 0 && visible.map((sess) => h(ChannelSessionRow, {
|
|
3599
|
-
key: sess.sessionId,
|
|
3600
|
-
sess,
|
|
3601
|
-
flat: groupMode === "list",
|
|
3602
|
-
selected: isCurrentListedSession(selectedId, sess.sessionId, props.sessionById),
|
|
3603
|
-
sessionById: props.sessionById,
|
|
3604
|
-
menuOpen: openMenu === sess.sessionId,
|
|
3605
|
-
onMenuChange: (next) => {
|
|
3606
|
-
setOpenGroupMenu(undefined);
|
|
3607
|
-
setOpenMenu(next ? sess.sessionId : undefined);
|
|
3608
|
-
},
|
|
3609
|
-
onOpen: (id) => { setOpenMenu(undefined); open(id); },
|
|
3610
|
-
onChanged: (next) => setGroups(next),
|
|
3611
|
-
canDelete,
|
|
3612
|
-
onDeleteSession: () => {
|
|
3613
|
-
setDeleteError(undefined);
|
|
3614
|
-
setDeleteTarget({
|
|
3615
|
-
id: sess.sessionId,
|
|
3616
|
-
title: String((props.sessionById && props.sessionById[sess.sessionId] && (props.sessionById[sess.sessionId].displayTitle || props.sessionById[sess.sessionId].title)) || sess.title || sess.chatId || sess.sessionId),
|
|
3617
|
-
});
|
|
3618
|
-
},
|
|
3619
|
-
archived: archived.has(sess.sessionId),
|
|
3620
|
-
hoverStatuses: channelSessionHoverStatuses({
|
|
3621
|
-
running: !!(sess.running || (props.sessionById && props.sessionById[sess.sessionId] && props.sessionById[sess.sessionId].running) || (props.sessionStatuses && props.sessionStatuses.get && props.sessionStatuses.get(sess.sessionId) && props.sessionStatuses.get(sess.sessionId).running)),
|
|
3622
|
-
archived: archived.has(sess.sessionId),
|
|
3623
|
-
completed: !!(props.sessionStatuses && props.sessionStatuses.get && props.sessionStatuses.get(sess.sessionId) && props.sessionStatuses.get(sess.sessionId).completionUnread),
|
|
3624
|
-
pendingKind: props.sessionStatuses && props.sessionStatuses.get && props.sessionStatuses.get(sess.sessionId) && props.sessionStatuses.get(sess.sessionId).pendingInteraction && props.sessionStatuses.get(sess.sessionId).pendingInteraction.kind,
|
|
3625
|
-
runningSubagentCount: (((props.projections && props.projections[sess.sessionId] && props.projections[sess.sessionId].values && props.projections[sess.sessionId].values.subagentCatalog) || []).filter((child) => child && child.id && props.sessionStatuses && props.sessionStatuses.get && props.sessionStatuses.get(child.id) && props.sessionStatuses.get(child.id).running)).length,
|
|
3626
|
-
}, t),
|
|
3627
|
-
onStopArchive: (target) => { setStopArchiveError(undefined); setStopArchiveTarget(target); },
|
|
3628
|
-
renderSlot: props.renderSlot,
|
|
3629
|
-
skin,
|
|
3630
|
-
sessionActions: {
|
|
3631
|
-
renameSession: props.renameSession,
|
|
3632
|
-
archiveSession: props.archiveSession,
|
|
3633
|
-
unarchiveSession: props.unarchiveSession,
|
|
3634
|
-
deleteSession: props.deleteSession,
|
|
3635
|
-
forkSession: props.forkSession,
|
|
3636
|
-
openPath: props.openPath,
|
|
3637
|
-
},
|
|
3638
|
-
t,
|
|
3639
|
-
})),
|
|
3640
|
-
);
|
|
3641
|
-
}),
|
|
3642
|
-
),
|
|
3643
|
-
),
|
|
3644
|
-
h(Modal, {
|
|
3645
|
-
open: !!archiveGroupTarget,
|
|
3646
|
-
layerOwner: "sidebar-archive",
|
|
3647
|
-
onClose: () => { if (!archiveGroupBusy) { setArchiveGroupTarget(undefined); setArchiveGroupError(undefined); } },
|
|
3648
|
-
closeLabel: t("rail.archiveGroupClose"),
|
|
3649
|
-
title: t("rail.archiveGroup"),
|
|
3650
|
-
description: archiveGroupTarget ? t("rail.archiveGroupDescription", { name: archiveGroupTarget.name, count: archiveGroupTarget.sessionIds.length }) : "",
|
|
3651
|
-
footer: h(React.Fragment, null,
|
|
3652
|
-
hostModalButton(t("rail.archiveGroupCancel"), () => { setArchiveGroupTarget(undefined); setArchiveGroupError(undefined); }, "outline", { disabled: archiveGroupBusy }),
|
|
3653
|
-
hostModalButton(t("rail.archiveGroupConfirm"), confirmArchiveGroup, "primary", { disabled: archiveGroupBusy }),
|
|
3654
|
-
),
|
|
3655
|
-
},
|
|
3656
|
-
archiveGroupBusy && h("div", { className: "ima-n-dialog-status", role: "status" }, t("rail.archiveGroupPending")),
|
|
3657
|
-
archiveGroupError && h("div", { className: "ima-n-dialog-error", role: "alert" }, t("rail.archiveGroupFailed", { message: archiveGroupError })),
|
|
3658
|
-
),
|
|
3659
|
-
h(Modal, {
|
|
3660
|
-
open: !!stopArchiveTarget,
|
|
3661
|
-
layerOwner: "sidebar-stop",
|
|
3662
|
-
onClose: () => { if (!stopArchiveBusy) { setStopArchiveTarget(undefined); setStopArchiveError(undefined); } },
|
|
3663
|
-
closeLabel: t("action.cancel"),
|
|
3664
|
-
title: t("rail.stopArchive"),
|
|
3665
|
-
description: stopArchiveTarget ? t(stopArchiveTarget.group ? "rail.stopArchiveGroupDescription" : "rail.stopArchiveDescription", { name: stopArchiveTarget.title }) : "",
|
|
3666
|
-
footer: h(React.Fragment, null,
|
|
3667
|
-
hostModalButton(t("action.cancel"), () => { setStopArchiveTarget(undefined); setStopArchiveError(undefined); }, "outline", { disabled: stopArchiveBusy }),
|
|
3668
|
-
hostModalButton(t("rail.stopArchiveConfirm"), confirmStopArchive, "primary", { disabled: stopArchiveBusy }),
|
|
3669
|
-
),
|
|
3670
|
-
},
|
|
3671
|
-
stopArchiveBusy && h("div", { className: "ima-n-dialog-status", role: "status" }, t("rail.stopArchivePending")),
|
|
3672
|
-
stopArchiveError && h("div", { className: "ima-n-dialog-error", role: "alert" }, t("rail.archiveFailed")),
|
|
3673
|
-
),
|
|
3674
|
-
h(Modal, {
|
|
3675
|
-
open: !!deleteTarget,
|
|
3676
|
-
layerOwner: "sidebar-delete",
|
|
3677
|
-
onClose: () => { if (!deleteBusy) { setDeleteTarget(undefined); setDeleteError(undefined); } },
|
|
3678
|
-
closeLabel: t("rail.deleteSessionClose"),
|
|
3679
|
-
title: t("rail.deleteSession"),
|
|
3680
|
-
description: deleteTarget ? t("rail.deleteSessionDescription", { name: deleteTarget.title }) : "",
|
|
3681
|
-
footer: h(React.Fragment, null,
|
|
3682
|
-
hostModalButton(t("rail.deleteSessionCancel"), () => { setDeleteTarget(undefined); setDeleteError(undefined); }, "outline", { disabled: deleteBusy }),
|
|
3683
|
-
hostModalButton(t("rail.deleteSessionConfirm"), confirmDelete, "primary", { disabled: deleteBusy }),
|
|
3684
|
-
),
|
|
3685
|
-
},
|
|
3686
|
-
deleteBusy && h("div", { className: "ima-n-dialog-status", role: "status" }, t("rail.deleteSessionPending")),
|
|
3687
|
-
deleteError && h("div", { className: "ima-n-dialog-error", role: "alert" }, t("rail.deleteSessionFailed", { message: deleteError })),
|
|
3688
|
-
),
|
|
3689
|
-
);
|
|
3690
3208
|
}
|
|
3691
3209
|
|
|
3692
|
-
function
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3210
|
+
function ChannelOfficialView(props) {
|
|
3211
|
+
const t = props.t || fallbackT;
|
|
3212
|
+
const hostProps = props.hostProps || {};
|
|
3213
|
+
const Official = props.officialTree;
|
|
3214
|
+
const hostT = typeof props.hostT === "function"
|
|
3215
|
+
? props.hostT
|
|
3216
|
+
: (typeof hostProps.t === "function" ? hostProps.t : t);
|
|
3217
|
+
const rawUseSessions = hostProps.useSessions;
|
|
3218
|
+
const rawUseWorkspaces = hostProps.useWorkspaces;
|
|
3219
|
+
const store = getChannelViewStore();
|
|
3220
|
+
const membershipRevision = useSyncExternalStore(subscribeChannelMembership, channelMembershipSnapshot, channelMembershipSnapshot);
|
|
3221
|
+
const useChannelStore = useCallback((select) => {
|
|
3222
|
+
const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
3223
|
+
return select(snapshot);
|
|
3224
|
+
}, [store]);
|
|
3225
|
+
const groupBy = useChannelStore((state) => state.groupBy);
|
|
3226
|
+
const sessionSource = typeof rawUseSessions === "function"
|
|
3227
|
+
? rawUseSessions((state) => state)
|
|
3228
|
+
: EMPTY_SESSION_STATE;
|
|
3229
|
+
// 宿主 0.2.x 首个权威快照前 phase 为 pending,列表失败时也停在 pending;
|
|
3230
|
+
// 旧宿主快照可能不带 phase,此时按已就绪处理,由 renderable 判定能力缺失。
|
|
3231
|
+
const groupsReady = sessionSource.phase === undefined || sessionSource.phase === "ready";
|
|
3232
|
+
const groupsError = sessionSource.state === "error";
|
|
3233
|
+
const groups = useMemo(() => channelGroupsFromSessionState(sessionSource, t), [membershipRevision, sessionSource, t]);
|
|
3234
|
+
const groupsRef = useRef(groups);
|
|
3235
|
+
groupsRef.current = groups;
|
|
3236
|
+
const [channelIcons, setChannelIcons] = useState("");
|
|
3237
|
+
const [workspaceIcons, setWorkspaceIcons] = useState("");
|
|
3238
|
+
const open = props.openSession || hostProps.open || hostProps.openSession;
|
|
3239
|
+
const openChannelSettings = props.openChannelSettings || hostProps.openChannelSettings;
|
|
3240
|
+
const openImSettings = props.openImSettings || hostProps.openImSettings || (() => openImSettingsPage(t));
|
|
3698
3241
|
|
|
3699
|
-
|
|
3700
|
-
if (typeof props.useSessions === "function") return h(TaskListWithSessions, props);
|
|
3701
|
-
return h(TaskListView, { groups: [], current: null, openSession: props.openSession, t: props.t });
|
|
3702
|
-
}
|
|
3242
|
+
useEffect(() => { ensureStyle(); }, []);
|
|
3703
3243
|
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
const
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
const groups = [];
|
|
3714
|
-
for (const ws of workspaces.items || []) {
|
|
3715
|
-
const sessions = (ws.sessionIds || [])
|
|
3716
|
-
.map((id) => snap.byId[id])
|
|
3717
|
-
.filter((item) => isTaskSessionItem(item) && !archived.has(item.id));
|
|
3718
|
-
sessions.forEach((item) => assigned.add(item.id));
|
|
3719
|
-
if (sessions.length) {
|
|
3720
|
-
groups.push({ id: ws.workspaceId || ws.id, label: ws.title || ws.path || t("rail.workspace"), sessions });
|
|
3244
|
+
useEffect(() => {
|
|
3245
|
+
if (groupBy === "channel" && channelIcons === "") setChannelIcons(channelIconCss());
|
|
3246
|
+
}, [channelIcons, groupBy]);
|
|
3247
|
+
|
|
3248
|
+
const memberKey = groups.map((group) => group.id + ":" + (group.sessions || []).map((session) => session.sessionId).join(",")).join("|");
|
|
3249
|
+
const memberIds = useMemo(() => {
|
|
3250
|
+
const ids = new Set();
|
|
3251
|
+
for (const group of groups) {
|
|
3252
|
+
for (const session of group.sessions || []) ids.add(String(session.sessionId));
|
|
3721
3253
|
}
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3254
|
+
return ids;
|
|
3255
|
+
}, [memberKey]);
|
|
3256
|
+
|
|
3257
|
+
const useChannelSessions = useCallback((selector, equals) => {
|
|
3258
|
+
if (typeof rawUseSessions !== "function") return selector(EMPTY_SESSION_STATE);
|
|
3259
|
+
return rawUseSessions((state) => selector(channelMemberSessionState(state, memberIds)), equals);
|
|
3260
|
+
}, [memberIds, rawUseSessions]);
|
|
3261
|
+
|
|
3262
|
+
const useChannelWorkspaces = useCallback((selector, equals) => {
|
|
3263
|
+
if (typeof rawUseWorkspaces !== "function") return selector(EMPTY_WORKSPACE_STATE);
|
|
3264
|
+
return rawUseWorkspaces((state) => selector(
|
|
3265
|
+
groupBy === "channel"
|
|
3266
|
+
? syntheticChannelWorkspaceState(state, groups, t)
|
|
3267
|
+
: channelRealWorkspaceState(state, memberIds),
|
|
3268
|
+
), equals);
|
|
3269
|
+
}, [groupBy, groups, memberIds, rawUseWorkspaces, t]);
|
|
3270
|
+
|
|
3271
|
+
const workspaceSource = typeof rawUseWorkspaces === "function"
|
|
3272
|
+
? rawUseWorkspaces((state) => state)
|
|
3273
|
+
: undefined;
|
|
3274
|
+
useEffect(() => {
|
|
3275
|
+
if (groupBy === "channel") {
|
|
3276
|
+
if (workspaceIcons !== "") setWorkspaceIcons("");
|
|
3277
|
+
return;
|
|
3278
|
+
}
|
|
3279
|
+
const items = (workspaceSource && workspaceSource.items) || [];
|
|
3280
|
+
const css = channelWorkspaceIconCss(items, memberIds);
|
|
3281
|
+
if (css !== workspaceIcons) setWorkspaceIcons(css);
|
|
3282
|
+
}, [groupBy, memberIds, membershipRevision, workspaceIcons, workspaceSource]);
|
|
3283
|
+
const groupKeys = useMemo(() => {
|
|
3284
|
+
if (groupBy === "channel") {
|
|
3285
|
+
return groups.filter((group) => (group.sessions || []).length > 0).map((group) => channelWorkspaceId(group.id));
|
|
3286
|
+
}
|
|
3287
|
+
if (groupBy === "flat") return [];
|
|
3288
|
+
return ((workspaceSource && workspaceSource.items) || [])
|
|
3289
|
+
.map((workspace) => String(workspace.workspaceId || workspace.id || ""))
|
|
3290
|
+
.filter((key) => key !== "");
|
|
3291
|
+
}, [groupBy, groups, workspaceSource]);
|
|
3292
|
+
useEffect(() => {
|
|
3293
|
+
store.actions.ensureExpanded(groupKeys);
|
|
3294
|
+
}, [groupKeys, store]);
|
|
3295
|
+
|
|
3296
|
+
const text = useCallback((key, params) => {
|
|
3297
|
+
if (key === "section.workspaces" && groupBy === "channel") return t("rail.channels");
|
|
3298
|
+
if (key === "workspace.add" || key === "menu.addWorkspace") return t("rail.addChannel");
|
|
3299
|
+
return hostT(key, params);
|
|
3300
|
+
}, [groupBy, hostT, t]);
|
|
3301
|
+
|
|
3302
|
+
useEffect(() => installChannelGroupOption({
|
|
3303
|
+
label: t("rail.byChannel"),
|
|
3304
|
+
groupLabel: text("groupBy.label"),
|
|
3305
|
+
workspaceLabel: text("groupBy.workspace"),
|
|
3306
|
+
checked: groupBy === "channel",
|
|
3307
|
+
onSelect: () => store.actions.setGroupBy("channel"),
|
|
3308
|
+
}), [groupBy, store, t, text]);
|
|
3309
|
+
|
|
3310
|
+
useEffect(() => installChannelGroupMenu({
|
|
3311
|
+
settingsLabel: t("rail.channelSettings"),
|
|
3312
|
+
resolve: (channelId) => groupsRef.current.find((group) => group.id === channelId),
|
|
3313
|
+
onSettings: (group) => {
|
|
3314
|
+
if (typeof openChannelSettings === "function") {
|
|
3315
|
+
openChannelSettings({ channelId: group.id, name: channelLabel(group, t) });
|
|
3316
|
+
return;
|
|
3317
|
+
}
|
|
3318
|
+
openImSettings();
|
|
3319
|
+
},
|
|
3320
|
+
}), [openChannelSettings, openImSettings, t]);
|
|
3321
|
+
|
|
3322
|
+
const rawStartSession = hostProps.startSession;
|
|
3323
|
+
const rawRenameWorkspace = hostProps.renameWorkspace;
|
|
3324
|
+
const rawDeleteWorkspace = hostProps.deleteWorkspace;
|
|
3325
|
+
const rawInsertWorkspaceBefore = hostProps.insertWorkspaceBefore;
|
|
3326
|
+
const rawSearch = hostProps.searchSessions;
|
|
3327
|
+
const startChannelSession = useCallback((workspaceId, options) => {
|
|
3328
|
+
if (channelIdFromWorkspaceId(workspaceId) !== undefined) return;
|
|
3329
|
+
if (typeof rawStartSession === "function") rawStartSession(workspaceId, options);
|
|
3330
|
+
}, [rawStartSession]);
|
|
3331
|
+
const renameChannelWorkspace = useCallback(async (workspaceId, title) => {
|
|
3332
|
+
if (channelIdFromWorkspaceId(workspaceId) !== undefined) throw new Error(t("rail.groupReadOnly"));
|
|
3333
|
+
if (typeof rawRenameWorkspace === "function") await rawRenameWorkspace(workspaceId, title);
|
|
3334
|
+
}, [rawRenameWorkspace, t]);
|
|
3335
|
+
const deleteChannelWorkspace = useCallback(async (workspaceId) => {
|
|
3336
|
+
if (channelIdFromWorkspaceId(workspaceId) !== undefined) throw new Error(t("rail.groupReadOnly"));
|
|
3337
|
+
if (typeof rawDeleteWorkspace === "function") await rawDeleteWorkspace(workspaceId);
|
|
3338
|
+
}, [rawDeleteWorkspace, t]);
|
|
3339
|
+
const insertChannelWorkspaceBefore = useCallback(async (workspaceId, beforeWorkspaceId) => {
|
|
3340
|
+
if (channelIdFromWorkspaceId(workspaceId) !== undefined) return;
|
|
3341
|
+
if (typeof rawInsertWorkspaceBefore === "function") await rawInsertWorkspaceBefore(workspaceId, beforeWorkspaceId);
|
|
3342
|
+
}, [rawInsertWorkspaceBefore]);
|
|
3343
|
+
const searchChannelSessions = useCallback(async (query, signal) => {
|
|
3344
|
+
if (typeof rawSearch !== "function") return { items: [], hasMore: false };
|
|
3345
|
+
const result = await rawSearch(query, signal);
|
|
3346
|
+
return {
|
|
3347
|
+
items: (result.items || []).filter((item) => item && item.id !== undefined && memberIds.has(String(item.id))),
|
|
3348
|
+
hasMore: result.hasMore,
|
|
3349
|
+
};
|
|
3350
|
+
}, [memberIds, rawSearch]);
|
|
3351
|
+
const rawUseShortcuts = hostProps.useShortcuts;
|
|
3352
|
+
const useChannelShortcuts = useCallback((select, equals) => {
|
|
3353
|
+
if (typeof rawUseShortcuts !== "function") return select([]);
|
|
3354
|
+
return rawUseShortcuts((rows) => select((rows || []).filter((row) => row && row.id !== "workspace.add")), equals);
|
|
3355
|
+
}, [rawUseShortcuts]);
|
|
3356
|
+
|
|
3357
|
+
const officialProps = Object.assign({}, hostProps, {
|
|
3358
|
+
t: text,
|
|
3359
|
+
useStore: useChannelStore,
|
|
3360
|
+
actions: store.actions,
|
|
3361
|
+
useSessions: useChannelSessions,
|
|
3362
|
+
useWorkspaces: useChannelWorkspaces,
|
|
3363
|
+
open: typeof open === "function" ? open : noopChannelAction,
|
|
3364
|
+
useDirectoryFlow: channelAddFlow,
|
|
3365
|
+
requestAddWorkspace: typeof openImSettings === "function" ? openImSettings : noopChannelAction,
|
|
3366
|
+
startSession: startChannelSession,
|
|
3367
|
+
renameWorkspace: renameChannelWorkspace,
|
|
3368
|
+
deleteWorkspace: deleteChannelWorkspace,
|
|
3369
|
+
insertWorkspaceBefore: insertChannelWorkspaceBefore,
|
|
3370
|
+
});
|
|
3371
|
+
if (typeof rawSearch === "function") officialProps.searchSessions = searchChannelSessions;
|
|
3372
|
+
if (typeof rawUseShortcuts === "function") officialProps.useShortcuts = useChannelShortcuts;
|
|
3373
|
+
|
|
3374
|
+
const renderable = Official !== undefined && Official !== null
|
|
3375
|
+
&& typeof rawUseSessions === "function" && typeof rawUseWorkspaces === "function";
|
|
3376
|
+
// 官方树会清理不存在的分组,首个权威快照到达前不能传入空列表。
|
|
3377
|
+
const body = !groupsReady ? null : renderable
|
|
3378
|
+
? h(ChannelTreeGuard, { t }, h(Official, officialProps))
|
|
3379
|
+
: h(ChannelUnavailable, { t });
|
|
3380
|
+
|
|
3381
|
+
return h(React.Fragment, null,
|
|
3382
|
+
h("div", { className: "ima-channel-official", "data-mode": groupBy },
|
|
3383
|
+
groupBy === "channel" && channelIcons !== "" && h("style", null, channelIcons),
|
|
3384
|
+
groupBy !== "channel" && workspaceIcons !== "" && h("style", null, workspaceIcons),
|
|
3385
|
+
// 宿主列表失败时 phase 仍停在 pending,没有横幅就是整页空白。
|
|
3386
|
+
groupsError && h("div", { className: "ima-channel-error", role: "alert" }, t("error.load")),
|
|
3387
|
+
body,
|
|
3747
3388
|
),
|
|
3748
3389
|
);
|
|
3749
3390
|
}
|
|
3750
3391
|
|
|
3751
|
-
const imSessionFilterCache = new WeakMap();
|
|
3752
3392
|
const registryFilterCache = new WeakMap();
|
|
3753
3393
|
function cacheFilteredSessions(src, ids) {
|
|
3754
3394
|
if (ids.length === (src.ids || []).length) return src;
|
|
@@ -3758,44 +3398,43 @@ function observePluginUpdate(options) {
|
|
|
3758
3398
|
}
|
|
3759
3399
|
return Object.assign({}, src, { ids, byId });
|
|
3760
3400
|
}
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
const
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3401
|
+
|
|
3402
|
+
function openRegisteredSession(sessionId, registry, hostOpen) {
|
|
3403
|
+
const openers = registry && Array.isArray(registry.sessionOpeners) ? registry.sessionOpeners : [];
|
|
3404
|
+
const opener = openers
|
|
3405
|
+
.slice()
|
|
3406
|
+
.sort((a, b) => (a.order || 0) - (b.order || 0))
|
|
3407
|
+
.find((item) => item && typeof item.matchSession === "function" && item.matchSession(sessionId));
|
|
3408
|
+
if (!opener) {
|
|
3409
|
+
if (typeof hostOpen === "function") hostOpen(sessionId);
|
|
3410
|
+
return;
|
|
3767
3411
|
}
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
const bucket = previous && previous.revision === channelMembershipRevision ? previous : { revision: channelMembershipRevision };
|
|
3773
|
-
bucket[key] = result;
|
|
3774
|
-
imSessionFilterCache.set(src, bucket);
|
|
3412
|
+
try {
|
|
3413
|
+
opener.open(sessionId, hostOpen);
|
|
3414
|
+
} catch {
|
|
3415
|
+
if (typeof hostOpen === "function") hostOpen(sessionId);
|
|
3775
3416
|
}
|
|
3776
|
-
return result;
|
|
3777
|
-
}
|
|
3778
|
-
|
|
3779
|
-
function filterTaskSessions(state) {
|
|
3780
|
-
return filterSessionsByIm(state, false);
|
|
3781
|
-
}
|
|
3782
|
-
|
|
3783
|
-
function filterChannelSessions(state) {
|
|
3784
|
-
return filterSessionsByIm(state, true);
|
|
3785
3417
|
}
|
|
3786
3418
|
|
|
3787
3419
|
function createNativeTabRegistry(officialTree) {
|
|
3788
3420
|
const tabs = new Map();
|
|
3789
3421
|
const sessionFilters = [];
|
|
3422
|
+
const sessionOpeners = [];
|
|
3790
3423
|
const listeners = new Set();
|
|
3791
3424
|
let cachedTabs = [];
|
|
3425
|
+
let revision = 0;
|
|
3792
3426
|
const rebuild = () => { cachedTabs = [...tabs.values()].sort((a, b) => (a.order || 0) - (b.order || 0)); };
|
|
3793
|
-
const emit = () => {
|
|
3427
|
+
const emit = () => {
|
|
3428
|
+
revision += 1;
|
|
3429
|
+
for (const listener of listeners) listener();
|
|
3430
|
+
};
|
|
3794
3431
|
return {
|
|
3795
3432
|
version: 1,
|
|
3796
3433
|
officialTree,
|
|
3797
3434
|
sessionFilters,
|
|
3435
|
+
sessionOpeners,
|
|
3798
3436
|
getTabs() { return cachedTabs; },
|
|
3437
|
+
getRevision() { return revision; },
|
|
3799
3438
|
subscribe(listener) { listeners.add(listener); return () => listeners.delete(listener); },
|
|
3800
3439
|
insert(tab) {
|
|
3801
3440
|
if (!tab || !tab.id) return () => {};
|
|
@@ -3817,6 +3456,15 @@ function observePluginUpdate(options) {
|
|
|
3817
3456
|
emit();
|
|
3818
3457
|
};
|
|
3819
3458
|
},
|
|
3459
|
+
addSessionOpener(opener) {
|
|
3460
|
+
sessionOpeners.push(opener);
|
|
3461
|
+
emit();
|
|
3462
|
+
return () => {
|
|
3463
|
+
const index = sessionOpeners.indexOf(opener);
|
|
3464
|
+
if (index >= 0) sessionOpeners.splice(index, 1);
|
|
3465
|
+
emit();
|
|
3466
|
+
};
|
|
3467
|
+
},
|
|
3820
3468
|
};
|
|
3821
3469
|
}
|
|
3822
3470
|
|
|
@@ -3831,17 +3479,18 @@ function observePluginUpdate(options) {
|
|
|
3831
3479
|
return registry?.version === 1 && typeof registry.getTabs === "function" && typeof registry.subscribe === "function" && typeof registry.insert === "function" ? registry : null;
|
|
3832
3480
|
}
|
|
3833
3481
|
|
|
3834
|
-
function
|
|
3482
|
+
function applySessionFilters(state, registry) {
|
|
3835
3483
|
const src = state || { ids: [], byId: {}, current: null };
|
|
3836
3484
|
const filters = registry && registry.sessionFilters ? registry.sessionFilters : [];
|
|
3837
3485
|
if (!filters.length) return src;
|
|
3838
|
-
|
|
3486
|
+
const revision = registry && typeof registry.getRevision === "function" ? registry.getRevision() : null;
|
|
3487
|
+
if (revision !== null && src && typeof src === "object") {
|
|
3839
3488
|
const hit = registryFilterCache.get(src);
|
|
3840
|
-
if (hit && hit.
|
|
3489
|
+
if (hit && hit.registry === registry && hit.revision === revision) return hit.result;
|
|
3841
3490
|
}
|
|
3842
3491
|
const ids = (src.ids || []).filter((id) => filters.every((fn) => fn(String(id))));
|
|
3843
3492
|
const result = cacheFilteredSessions(src, ids);
|
|
3844
|
-
if (src && typeof src === "object") registryFilterCache.set(src, {
|
|
3493
|
+
if (revision !== null && src && typeof src === "object") registryFilterCache.set(src, { registry, revision, result });
|
|
3845
3494
|
return result;
|
|
3846
3495
|
}
|
|
3847
3496
|
|
|
@@ -3857,8 +3506,17 @@ function observePluginUpdate(options) {
|
|
|
3857
3506
|
() => (nativeTabs && nativeTabs.getTabs ? nativeTabs.getTabs() : EMPTY_EXTRA_TABS),
|
|
3858
3507
|
() => EMPTY_EXTRA_TABS,
|
|
3859
3508
|
);
|
|
3509
|
+
const registryRevision = useSyncExternalStore(
|
|
3510
|
+
(listener) => (nativeTabs && nativeTabs.subscribe ? nativeTabs.subscribe(listener) : () => {}),
|
|
3511
|
+
() => (nativeTabs && nativeTabs.getRevision ? nativeTabs.getRevision() : 0),
|
|
3512
|
+
() => 0,
|
|
3513
|
+
);
|
|
3860
3514
|
const [tab, setTab] = useState(() => {
|
|
3861
|
-
try {
|
|
3515
|
+
try {
|
|
3516
|
+
return localStorage.getItem(TAB_KEY)
|
|
3517
|
+
|| localStorage.getItem("dsh-im-connect.sidebar-tab")
|
|
3518
|
+
|| localStorage.getItem("dsh-automation.sidebar-tab") || "tasks";
|
|
3519
|
+
} catch { return "tasks"; }
|
|
3862
3520
|
});
|
|
3863
3521
|
const sessionSnap = typeof rawUseSessions === "function"
|
|
3864
3522
|
? rawUseSessions((state) => state)
|
|
@@ -3869,19 +3527,17 @@ function observePluginUpdate(options) {
|
|
|
3869
3527
|
const sessionById = (sessionSnap && sessionSnap.byId) || {};
|
|
3870
3528
|
const useTaskSessions = useCallback((selector, eq) => {
|
|
3871
3529
|
if (typeof rawUseSessions !== "function") return selector({ ids: [], byId: {}, current: null });
|
|
3872
|
-
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
if (typeof rawUseSessions !== "function") return selector({ ids: [], byId: {}, current: null });
|
|
3876
|
-
return rawUseSessions((state) => selector(filterChannelSessions(state)), eq);
|
|
3877
|
-
}, [rawUseSessions, membershipRevision]);
|
|
3530
|
+
// 频道会话也出现在官方任务树;频道页签只是同一批会话的过滤视图。
|
|
3531
|
+
return rawUseSessions((state) => selector(applySessionFilters(state, nativeTabs)), eq);
|
|
3532
|
+
}, [rawUseSessions, nativeTabs, registryRevision]);
|
|
3878
3533
|
useEffect(() => { ensureStyle(); }, []);
|
|
3879
3534
|
useEffect(() => { try { localStorage.setItem(TAB_KEY, tab); } catch { /* ignore */ } }, [tab]);
|
|
3880
3535
|
useEffect(() => {
|
|
3881
3536
|
const onClick = (event) => {
|
|
3882
3537
|
const target = event.target && event.target.closest ? event.target.closest("button") : null;
|
|
3883
3538
|
if (!target) return;
|
|
3884
|
-
|
|
3539
|
+
if (target.closest("[data-row-key]")) return;
|
|
3540
|
+
const label = target.getAttribute("aria-label") || target.innerText || target.textContent || "";
|
|
3885
3541
|
if (isHostNewSessionControl(label)) setTab("tasks");
|
|
3886
3542
|
};
|
|
3887
3543
|
document.addEventListener("click", onClick, true);
|
|
@@ -3899,32 +3555,34 @@ function observePluginUpdate(options) {
|
|
|
3899
3555
|
previousCurrentId.current = followed.previousId;
|
|
3900
3556
|
if (followed.tab) setTab(followed.tab);
|
|
3901
3557
|
}, [currentId, extraTabs, membershipRevision]);
|
|
3558
|
+
const hostOpen = props.openSession || props.open;
|
|
3559
|
+
const openListed = (id) => {
|
|
3560
|
+
openListedSession(resolveHostSessionId(id, sessionById), hostOpen);
|
|
3561
|
+
};
|
|
3902
3562
|
const openSession = (id) => {
|
|
3903
|
-
|
|
3563
|
+
if (nativeTabs && Array.isArray(nativeTabs.sessionOpeners)
|
|
3564
|
+
&& nativeTabs.sessionOpeners.some((item) => item && item.id === "im-connect")) {
|
|
3565
|
+
openRegisteredSession(id, nativeTabs, hostOpen);
|
|
3566
|
+
return;
|
|
3567
|
+
}
|
|
3568
|
+
openListed(id);
|
|
3904
3569
|
};
|
|
3905
3570
|
const officialProps = Object.assign({}, props, { useSessions: useTaskSessions, t: officialT, openSession, open: openSession });
|
|
3906
|
-
const
|
|
3571
|
+
const channelView = h(ChannelOfficialView, {
|
|
3572
|
+
officialTree: Official,
|
|
3573
|
+
hostProps: props,
|
|
3574
|
+
hostT: officialT,
|
|
3575
|
+
t,
|
|
3907
3576
|
openSession,
|
|
3908
|
-
open: openSession,
|
|
3909
|
-
useSessions: rawUseSessions,
|
|
3910
|
-
useWorkspaces: props.useWorkspaces,
|
|
3911
|
-
useSessionStatus: props.useSessionStatus,
|
|
3912
|
-
selectedId: currentId || props.selectedId || null,
|
|
3913
|
-
skin: "native",
|
|
3914
|
-
renameSession: props.renameSession,
|
|
3915
|
-
archiveSession: props.archiveSession,
|
|
3916
|
-
unarchiveSession: props.unarchiveSession,
|
|
3917
|
-
deleteSession: props.deleteSession,
|
|
3918
|
-
forkSession: props.forkSession,
|
|
3919
|
-
openPath: props.openPath,
|
|
3920
3577
|
openChannelSettings: props.openChannelSettings,
|
|
3921
|
-
|
|
3578
|
+
openImSettings: props.openImSettings,
|
|
3922
3579
|
});
|
|
3923
3580
|
if (props.wide === false) return Official ? h(Official, officialProps) : null;
|
|
3924
3581
|
const officialTree = Official
|
|
3925
3582
|
? h("div", { className: "ima-official-tree" }, h(Official, officialProps))
|
|
3926
3583
|
: null;
|
|
3927
|
-
const
|
|
3584
|
+
const visibleTab = resolveSidebarTab(tab, extraTabs);
|
|
3585
|
+
const extra = extraTabs.find((item) => item.id === visibleTab);
|
|
3928
3586
|
const hasChannelTab = extraTabs.some((item) => item.id === "channels");
|
|
3929
3587
|
const imTabItems = [
|
|
3930
3588
|
{
|
|
@@ -3943,20 +3601,23 @@ function observePluginUpdate(options) {
|
|
|
3943
3601
|
id: "ima-tab-channels",
|
|
3944
3602
|
panelId: "ima-panel-channels",
|
|
3945
3603
|
label: h("span", { style: { display: "inline-flex", alignItems: "center", gap: 5 } },
|
|
3946
|
-
h(
|
|
3947
|
-
h("path", { fill: "currentColor", d: "M2.15 2.9h11.7v8.2H6.42L2.15 13.85V2.9Zm1.4 1.4v6.62l1.78-1.12h7.12V4.3H3.55Z" }),
|
|
3948
|
-
),
|
|
3604
|
+
h(IconQueueOutline, { size: 14 }),
|
|
3949
3605
|
h("span", null, t("rail.channels")),
|
|
3950
3606
|
),
|
|
3951
3607
|
});
|
|
3952
3608
|
}
|
|
3953
3609
|
for (const item of extraTabs) {
|
|
3954
|
-
const itemLabel = item.id === "
|
|
3610
|
+
const itemLabel = item.id === "channels"
|
|
3955
3611
|
? h("span", { style: { display: "inline-flex", alignItems: "center", gap: 5 } },
|
|
3956
|
-
h(
|
|
3612
|
+
h(IconQueueOutline, { size: 14 }),
|
|
3957
3613
|
h("span", null, item.label),
|
|
3958
3614
|
)
|
|
3959
|
-
: item.
|
|
3615
|
+
: item.id === "schedule"
|
|
3616
|
+
? h("span", { style: { display: "inline-flex", alignItems: "center", gap: 5 } },
|
|
3617
|
+
h(IconClockOutline, { size: 14 }),
|
|
3618
|
+
h("span", null, item.label),
|
|
3619
|
+
)
|
|
3620
|
+
: item.label;
|
|
3960
3621
|
imTabItems.push({
|
|
3961
3622
|
value: item.id,
|
|
3962
3623
|
id: "ima-tab-" + item.id,
|
|
@@ -3971,28 +3632,28 @@ function observePluginUpdate(options) {
|
|
|
3971
3632
|
h(HostSegmentedTabs, {
|
|
3972
3633
|
className: "ima-segmented-tabs",
|
|
3973
3634
|
label: t("rail.tabsAria"),
|
|
3974
|
-
value:
|
|
3635
|
+
value: visibleTab,
|
|
3975
3636
|
onChange: (next) => setTab(next),
|
|
3976
3637
|
items: imTabItems,
|
|
3977
3638
|
}),
|
|
3978
3639
|
)
|
|
3979
3640
|
: h("div", { className: "ima-tabs", role: "tablist", "aria-label": t("rail.tabsAria") },
|
|
3980
|
-
h("button", { type: "button", role: "tab", "aria-selected":
|
|
3981
|
-
!hasChannelTab && h("button", { type: "button", role: "tab", "aria-selected":
|
|
3641
|
+
h("button", { type: "button", role: "tab", "aria-selected": visibleTab === "tasks", className: visibleTab === "tasks" ? "ima-tab on" : "ima-tab", onClick: () => setTab("tasks") }, t("rail.tasks")),
|
|
3642
|
+
!hasChannelTab && h("button", { type: "button", role: "tab", "aria-selected": visibleTab === "channels", className: visibleTab === "channels" ? "ima-tab on" : "ima-tab", onClick: () => setTab("channels") }, t("rail.channels")),
|
|
3982
3643
|
...extraTabs.map((item) => h("button", {
|
|
3983
3644
|
key: item.id,
|
|
3984
3645
|
type: "button",
|
|
3985
3646
|
role: "tab",
|
|
3986
|
-
"aria-selected":
|
|
3987
|
-
className:
|
|
3647
|
+
"aria-selected": visibleTab === item.id,
|
|
3648
|
+
className: visibleTab === item.id ? "ima-tab on" : "ima-tab",
|
|
3988
3649
|
onClick: () => setTab(item.id),
|
|
3989
3650
|
}, item.label)),
|
|
3990
3651
|
),
|
|
3991
|
-
|
|
3992
|
-
? (officialTree || h(
|
|
3652
|
+
visibleTab === "tasks"
|
|
3653
|
+
? (officialTree || h(ChannelUnavailable, { t }))
|
|
3993
3654
|
: extra
|
|
3994
|
-
? extra.render(Object.assign({}, props, { openSession, open: openSession }))
|
|
3995
|
-
:
|
|
3655
|
+
? extra.render(Object.assign({}, props, { t: officialT, openSession, open: openSession }))
|
|
3656
|
+
: channelView,
|
|
3996
3657
|
);
|
|
3997
3658
|
}
|
|
3998
3659
|
|
|
@@ -4054,22 +3715,51 @@ function observePluginUpdate(options) {
|
|
|
4054
3715
|
const entries = (read && read.call(ctx.slots, "sidebar.workspaces")) || [];
|
|
4055
3716
|
for (const item of entries) {
|
|
4056
3717
|
if (!item || !item.component) continue;
|
|
4057
|
-
if (item.component
|
|
4058
|
-
if (item.component.__imConnectOriginal) continue;
|
|
4059
|
-
if (item.component.__dshNativeTabHost) continue;
|
|
4060
|
-
if (item.component.__dshAutomationWrapped) continue;
|
|
3718
|
+
if (isWrappedWorkspaceComponent(item.component)) continue;
|
|
4061
3719
|
return item;
|
|
4062
3720
|
}
|
|
4063
3721
|
return null;
|
|
4064
3722
|
}
|
|
4065
3723
|
|
|
3724
|
+
function isWrappedWorkspaceComponent(component) {
|
|
3725
|
+
return !!component && (component.__dshNativeTabWrapped === true
|
|
3726
|
+
|| component.__dshNativeTabHost === true
|
|
3727
|
+
|| component.__imConnectWrapped === true
|
|
3728
|
+
|| component.__imConnectOriginal !== undefined
|
|
3729
|
+
|| component.__dshAutomationWrapped === true
|
|
3730
|
+
|| component.__dshAutomationOriginal !== undefined);
|
|
3731
|
+
}
|
|
3732
|
+
|
|
4066
3733
|
function apply(ctx) {
|
|
4067
3734
|
ensureStyle();
|
|
4068
3735
|
ctx.effect(() => {
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
3736
|
+
let pending = channelSessionIds.size > 0, flight = null, disposed = false;
|
|
3737
|
+
const refresh = (changed) => {
|
|
3738
|
+
pending = pending || changed;
|
|
3739
|
+
if (disposed || !pending || flight) return;
|
|
3740
|
+
const sessions = probeService(ctx, "sessions");
|
|
3741
|
+
if (!sessions || typeof sessions.refresh !== "function") return;
|
|
3742
|
+
const revision = channelMembershipRevision;
|
|
3743
|
+
flight = Promise.resolve().then(() => {
|
|
3744
|
+
if (disposed) return;
|
|
3745
|
+
return sessions.refresh();
|
|
3746
|
+
}).then(() => {
|
|
3747
|
+
if (disposed) return;
|
|
3748
|
+
const snapshot = sessions.list && typeof sessions.list.getSnapshot === "function" ? sessions.list.getSnapshot() : undefined;
|
|
3749
|
+
if (snapshot && snapshot.state === "error") return;
|
|
3750
|
+
if (revision === channelMembershipRevision) pending = false;
|
|
3751
|
+
}).catch(() => { /* 保留待处理状态,由下次渠道刷新重试 */ })
|
|
3752
|
+
.finally(() => { flight = null; });
|
|
3753
|
+
};
|
|
3754
|
+
requestHostSessionRefresh = refresh;
|
|
3755
|
+
return () => {
|
|
3756
|
+
disposed = true;
|
|
3757
|
+
if (requestHostSessionRefresh === refresh) requestHostSessionRefresh = () => {};
|
|
3758
|
+
};
|
|
3759
|
+
}, "im-connect: host session refresh");
|
|
3760
|
+
ctx.effect(() => channelRefresh.subscribe((data, error) => {
|
|
3761
|
+
if (error) console.warn("[dsh-im-connect] 无法刷新渠道会话归属", error);
|
|
3762
|
+
}), "im-connect: channel membership");
|
|
4073
3763
|
ctx.effect(() => ctx.locale.register(IM_LOCALE_NS, IM_LOCALES), "im-connect: dictionaries");
|
|
4074
3764
|
const t = ctx.locale.bind(IM_LOCALE_NS);
|
|
4075
3765
|
ctx.effect(() => observePluginUpdate({
|
|
@@ -4095,17 +3785,29 @@ function observePluginUpdate(options) {
|
|
|
4095
3785
|
() => { requestChannelSettings(next); },
|
|
4096
3786
|
);
|
|
4097
3787
|
};
|
|
4098
|
-
|
|
3788
|
+
const openImSettings = () => openImSettingsPage(t);
|
|
3789
|
+
// Codex UI 只把 sidebar.channels 当作页签占用信号,频道内容由它自己的
|
|
3790
|
+
// ChannelBrowser 渲染;这里保留占位,避免未来宿主直接渲染时空白。
|
|
3791
|
+
function LocalizedChannelRail() {
|
|
4099
3792
|
useSyncExternalStore(subscribeLocale, localeSnapshot, localeSnapshot);
|
|
4100
|
-
return h(
|
|
3793
|
+
return h(ChannelUnavailable, { t });
|
|
4101
3794
|
}
|
|
4102
3795
|
function LocalizedSessionSwitcher(props) {
|
|
4103
3796
|
useSyncExternalStore(subscribeLocale, localeSnapshot, localeSnapshot);
|
|
4104
|
-
|
|
3797
|
+
const archiveSession = props.archiveSession || ((sessionId, options) => archiveHostSession(ctx, sessionId, options));
|
|
3798
|
+
const unarchiveSession = props.unarchiveSession || ((sessionId) => unarchiveHostSession(ctx, sessionId));
|
|
3799
|
+
return h(SessionSwitcher, Object.assign({}, props, {
|
|
3800
|
+
t,
|
|
3801
|
+
officialT: props.t,
|
|
3802
|
+
openChannelSettings,
|
|
3803
|
+
openImSettings,
|
|
3804
|
+
archiveSession,
|
|
3805
|
+
unarchiveSession,
|
|
3806
|
+
}));
|
|
4105
3807
|
}
|
|
4106
3808
|
function LocalizedSettingsPage(props) {
|
|
4107
3809
|
useSyncExternalStore(subscribeLocale, localeSnapshot, localeSnapshot);
|
|
4108
|
-
return h(
|
|
3810
|
+
return h(SettingsPage, Object.assign({}, props, { t, permissionT, modelT, presetT, readMainSessionModel: () => readMainSessionModel(ctx) }));
|
|
4109
3811
|
}
|
|
4110
3812
|
openImSession = (id) => {
|
|
4111
3813
|
try {
|
|
@@ -4128,7 +3830,7 @@ function observePluginUpdate(options) {
|
|
|
4128
3830
|
|
|
4129
3831
|
function applySettingsNavIcon(button, wantedLabel) {
|
|
4130
3832
|
if (!isOwnNavRow(button.textContent, wantedLabel())) return false;
|
|
4131
|
-
if (!button.querySelector("svg")) return false;
|
|
3833
|
+
if (!button.querySelector(":scope > svg")) return false;
|
|
4132
3834
|
if (button.getAttribute(NAV_ICON_MARKER) === "assistant" && button.querySelector(`.${NAV_ICON_CLASS}`)) return false;
|
|
4133
3835
|
button.setAttribute(NAV_ICON_MARKER, "assistant");
|
|
4134
3836
|
let icon = button.querySelector(`.${NAV_ICON_CLASS}`);
|
|
@@ -4138,6 +3840,7 @@ function observePluginUpdate(options) {
|
|
|
4138
3840
|
icon = document.createElement("span");
|
|
4139
3841
|
icon.className = NAV_ICON_CLASS;
|
|
4140
3842
|
icon.setAttribute("aria-hidden", "true");
|
|
3843
|
+
icon.setAttribute("style", `--ima-nav-icon-mask:${settingsNavIconMask()}`);
|
|
4141
3844
|
button.prepend(icon);
|
|
4142
3845
|
}
|
|
4143
3846
|
return true;
|
|
@@ -4216,6 +3919,18 @@ function observePluginUpdate(options) {
|
|
|
4216
3919
|
}),
|
|
4217
3920
|
}, LocalizedChannelRail));
|
|
4218
3921
|
|
|
3922
|
+
// 频道会话行前显示所属频道品牌标,和定时任务的时钟图标同一套 leading 槽位。
|
|
3923
|
+
ctx.slots.inject("sidebar.session.row.leading", () => ctx.slots.register({
|
|
3924
|
+
name: "sidebar.session.row.leading",
|
|
3925
|
+
id: "im-connect-session-channel",
|
|
3926
|
+
order: 10,
|
|
3927
|
+
}, function ChannelSessionLeading({ sessionId }) {
|
|
3928
|
+
useSyncExternalStore(subscribeChannelMembership, channelMembershipSnapshot, channelMembershipSnapshot);
|
|
3929
|
+
const channelId = channelIdOfSession(sessionId);
|
|
3930
|
+
if (!channelId) return null;
|
|
3931
|
+
return h("span", { className: "ima-session-channel-icon", "aria-hidden": "true" }, h(Logo, { id: channelId, small: true }));
|
|
3932
|
+
}));
|
|
3933
|
+
|
|
4219
3934
|
// 只包一层官方任务树,绝不在通知回调里再 register,否则会把启动卡在 Loading plugins。
|
|
4220
3935
|
ctx.slots.inject("sidebar.workspaces", () => {
|
|
4221
3936
|
let wrappedEntry = null;
|
|
@@ -4223,16 +3938,34 @@ function observePluginUpdate(options) {
|
|
|
4223
3938
|
let ownedWrapper = null;
|
|
4224
3939
|
let ownedRegistry = null;
|
|
4225
3940
|
let removeInsertedTab = () => {};
|
|
3941
|
+
let removeInsertedOpener = () => {};
|
|
4226
3942
|
let stopInsertedTabLocale = () => {};
|
|
4227
3943
|
let insertedTabRegistry = null;
|
|
4228
3944
|
let syncing = false;
|
|
4229
3945
|
// 与定时插件共享通知,补足直接替换 component 不触发宿主插槽通知的情况。
|
|
4230
3946
|
const notifyPeers = () => { queueMicrotask(() => window.dispatchEvent(new Event("dsh-native-sidebar-change"))); };
|
|
3947
|
+
const installSessionOpener = (registry) => {
|
|
3948
|
+
if (!registry || typeof registry.addSessionOpener !== "function") return () => {};
|
|
3949
|
+
if (registry.sessionOpeners && registry.sessionOpeners.some((item) => item.id === "im-connect")) return () => {};
|
|
3950
|
+
return registry.addSessionOpener({
|
|
3951
|
+
id: "im-connect",
|
|
3952
|
+
order: 20,
|
|
3953
|
+
// 普通任务行也需要把宿主内部 key 解析成官方 session id;定时 opener 优先级更高。
|
|
3954
|
+
matchSession: (sessionId) => typeof sessionId === "string" && sessionId !== "",
|
|
3955
|
+
open: (sessionId, hostOpen) => {
|
|
3956
|
+
let byId;
|
|
3957
|
+
try { byId = ctx.sessions && ctx.sessions.list && ctx.sessions.list.getSnapshot ? ctx.sessions.list.getSnapshot().byId : undefined; } catch { byId = undefined; }
|
|
3958
|
+
openListedSession(resolveHostSessionId(sessionId, byId), hostOpen);
|
|
3959
|
+
},
|
|
3960
|
+
});
|
|
3961
|
+
};
|
|
4231
3962
|
const clearInsertedTab = () => {
|
|
4232
3963
|
stopInsertedTabLocale();
|
|
4233
3964
|
stopInsertedTabLocale = () => {};
|
|
4234
3965
|
removeInsertedTab();
|
|
4235
3966
|
removeInsertedTab = () => {};
|
|
3967
|
+
removeInsertedOpener();
|
|
3968
|
+
removeInsertedOpener = () => {};
|
|
4236
3969
|
insertedTabRegistry = null;
|
|
4237
3970
|
};
|
|
4238
3971
|
const unwrap = () => {
|
|
@@ -4250,20 +3983,28 @@ function observePluginUpdate(options) {
|
|
|
4250
3983
|
const insertChannelTab = (entry) => {
|
|
4251
3984
|
const registry = findNativeTabRegistry(entry);
|
|
4252
3985
|
if (!registry) return false;
|
|
4253
|
-
if (
|
|
4254
|
-
|
|
4255
|
-
|
|
3986
|
+
if (insertedTabRegistry !== registry) {
|
|
3987
|
+
clearInsertedTab();
|
|
3988
|
+
insertedTabRegistry = registry;
|
|
3989
|
+
removeInsertedOpener = installSessionOpener(registry);
|
|
4256
3990
|
}
|
|
4257
|
-
|
|
4258
|
-
insertedTabRegistry = registry;
|
|
3991
|
+
if (registry.getTabs().some((item) => item.id === "channels")) return true;
|
|
4259
3992
|
const refreshInsertedTab = () => {
|
|
4260
3993
|
removeInsertedTab = registry.insert({
|
|
4261
3994
|
id: "channels",
|
|
4262
3995
|
label: t("rail.channels"),
|
|
4263
3996
|
order: 20,
|
|
4264
3997
|
matchSession: isChannelSession,
|
|
4265
|
-
render: (props) => h(ImSidebarFallbackBoundary, {
|
|
4266
|
-
|
|
3998
|
+
render: (props) => h(ImSidebarFallbackBoundary, {
|
|
3999
|
+
officialTree: () => h(ChannelUnavailable, { t }),
|
|
4000
|
+
hostProps: props,
|
|
4001
|
+
}, h(ChannelOfficialView, Object.assign({}, props, {
|
|
4002
|
+
officialTree: registry.officialTree,
|
|
4003
|
+
hostProps: props,
|
|
4004
|
+
hostT: props.officialT || props.t,
|
|
4005
|
+
t,
|
|
4006
|
+
openChannelSettings,
|
|
4007
|
+
openImSettings,
|
|
4267
4008
|
archiveSession: props.archiveSession || ((id, options) => archiveHostSession(ctx, id, options)),
|
|
4268
4009
|
unarchiveSession: props.unarchiveSession || ((id) => unarchiveHostSession(ctx, id)),
|
|
4269
4010
|
}))),
|
|
@@ -4280,7 +4021,6 @@ function observePluginUpdate(options) {
|
|
|
4280
4021
|
syncing = true;
|
|
4281
4022
|
try {
|
|
4282
4023
|
const combo = hasDshCodexUiSidebar(ctx);
|
|
4283
|
-
channelSkin = combo ? "codex" : "native";
|
|
4284
4024
|
if (combo) {
|
|
4285
4025
|
unwrap();
|
|
4286
4026
|
return;
|
|
@@ -4291,28 +4031,32 @@ function observePluginUpdate(options) {
|
|
|
4291
4031
|
if (wrappedEntry && (occupant !== wrappedEntry || occupant.component !== ownedWrapper)) unwrap();
|
|
4292
4032
|
if (!occupant) { clearInsertedTab(); return; }
|
|
4293
4033
|
if (insertedTabRegistry && findNativeTabRegistry(occupant) !== insertedTabRegistry) clearInsertedTab();
|
|
4294
|
-
if (occupant && (occupant.component.__dshNativeTabHost || occupant.component.__dshAutomationWrapped || findNativeTabRegistry(occupant))) {
|
|
4034
|
+
if (occupant && (occupant.component.__dshNativeTabHost || occupant.component.__dshNativeTabWrapped || occupant.component.__dshAutomationWrapped || findNativeTabRegistry(occupant))) {
|
|
4295
4035
|
insertChannelTab(occupant);
|
|
4296
4036
|
return;
|
|
4297
4037
|
}
|
|
4298
4038
|
const official = pickOfficialWorkspaces(ctx);
|
|
4299
|
-
if (!official
|
|
4039
|
+
if (!official) return;
|
|
4300
4040
|
originalComp = official.component;
|
|
4301
4041
|
const registry = createNativeTabRegistry(originalComp);
|
|
4302
4042
|
ownedRegistry = registry;
|
|
4043
|
+
removeInsertedOpener = installSessionOpener(registry);
|
|
4303
4044
|
const tree = originalComp;
|
|
4304
4045
|
attachNativeTabRegistry(official, registry);
|
|
4305
|
-
function
|
|
4046
|
+
function DshNativeTabWorkspaceShell(innerProps) {
|
|
4306
4047
|
return h(ImSidebarFallbackBoundary, { officialTree: tree, hostProps: innerProps },
|
|
4307
4048
|
h(LocalizedSessionSwitcher, Object.assign({}, innerProps, { officialTree: tree, nativeTabs: registry })));
|
|
4308
4049
|
}
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4050
|
+
DshNativeTabWorkspaceShell.displayName = "DshNativeTabWorkspaceShell";
|
|
4051
|
+
DshNativeTabWorkspaceShell.__dshNativeTabHost = true;
|
|
4052
|
+
DshNativeTabWorkspaceShell.__dshNativeTabWrapped = true;
|
|
4053
|
+
DshNativeTabWorkspaceShell.__dshNativeTabOriginal = originalComp;
|
|
4054
|
+
DshNativeTabWorkspaceShell.__dshNativeTabOwner = "im-connect";
|
|
4055
|
+
DshNativeTabWorkspaceShell.__imConnectWrapped = true;
|
|
4056
|
+
DshNativeTabWorkspaceShell.__imConnectOriginal = originalComp;
|
|
4057
|
+
attachNativeTabRegistry(DshNativeTabWorkspaceShell, registry);
|
|
4058
|
+
official.component = DshNativeTabWorkspaceShell;
|
|
4059
|
+
ownedWrapper = DshNativeTabWorkspaceShell;
|
|
4316
4060
|
wrappedEntry = official;
|
|
4317
4061
|
notifyPeers();
|
|
4318
4062
|
} catch (error) {
|