@dungsil/dsh-plugin-ui-sidebar-inbox 0.2.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.de.md +109 -0
- package/README.en.md +109 -0
- package/README.es.md +109 -0
- package/README.fr.md +109 -0
- package/README.ja.md +109 -0
- package/README.md +74 -54
- package/README.pt.md +109 -0
- package/README.ru.md +109 -0
- package/README.zh.md +109 -0
- package/dist/client.js +1200 -52
- package/locale/de.json +20 -0
- package/locale/es.json +20 -0
- package/locale/fr.json +20 -0
- package/locale/ja.json +20 -0
- package/locale/pt.json +20 -0
- package/locale/ru.json +20 -0
- package/package.json +28 -15
- package/assets/sidebar-preview-dark.webp +0 -0
- package/assets/sidebar-preview.webp +0 -0
package/dist/client.js
CHANGED
|
@@ -9,7 +9,7 @@ let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-
|
|
|
9
9
|
* reply, so this projection only reads it: an archived session keeps the Archived
|
|
10
10
|
* slot until the user unarchives it in the native menu.
|
|
11
11
|
*/
|
|
12
|
-
function placeSessions(list, statuses, pinned, archived) {
|
|
12
|
+
function placeSessions(list, statuses, pinned, archived, worktreeActive = /* @__PURE__ */ new Set(), snoozed = /* @__PURE__ */ new Set(), automation = /* @__PURE__ */ new Set()) {
|
|
13
13
|
const pins = new Set(pinned);
|
|
14
14
|
const archives = new Set(archived);
|
|
15
15
|
const placements = /* @__PURE__ */ new Map();
|
|
@@ -18,8 +18,9 @@ function placeSessions(list, statuses, pinned, archived) {
|
|
|
18
18
|
const status = statuses.get(id);
|
|
19
19
|
const pending = status?.pendingInteraction !== void 0;
|
|
20
20
|
const children = list.projectionsBySession[id]?.values.subagentCatalog ?? [];
|
|
21
|
-
const running = (status?.running ?? row.running) || children.some((child) => statuses.get(child.id)?.running ?? list.byId[child.id]?.running);
|
|
22
|
-
const
|
|
21
|
+
const running = (status?.running ?? row.running) || worktreeActive.has(id) || children.some((child) => statuses.get(child.id)?.running ?? list.byId[child.id]?.running);
|
|
22
|
+
const automationIdle = automation.has(id) && !running && !pending && status?.completionUnread === false;
|
|
23
|
+
const section = archives.has(id) ? "Archived" : pins.has(id) ? "Pinned" : !row.blank && (snoozed.has(id) || automationIdle) ? "Snoozed" : pending ? "Inbox" : running ? "Working" : "Inbox";
|
|
23
24
|
placements.set(id, {
|
|
24
25
|
section,
|
|
25
26
|
blank: row.blank
|
|
@@ -29,7 +30,8 @@ function placeSessions(list, statuses, pinned, archived) {
|
|
|
29
30
|
Pinned: 0,
|
|
30
31
|
Inbox: 1,
|
|
31
32
|
Working: 2,
|
|
32
|
-
Archived: 3
|
|
33
|
+
Archived: 3,
|
|
34
|
+
Snoozed: 4
|
|
33
35
|
};
|
|
34
36
|
return {
|
|
35
37
|
order: list.ids.filter((id) => {
|
|
@@ -43,6 +45,62 @@ function placeSessions(list, statuses, pinned, archived) {
|
|
|
43
45
|
placements
|
|
44
46
|
};
|
|
45
47
|
}
|
|
48
|
+
// ../../tools/ui/src/count.ts
|
|
49
|
+
/** Compact display and exact value for non-negative counts. */
|
|
50
|
+
function countParts(count, language) {
|
|
51
|
+
const locale = language.replaceAll("_", "-");
|
|
52
|
+
const exact = new Intl.NumberFormat("en").format(count);
|
|
53
|
+
let compact;
|
|
54
|
+
if (/^ko(?:-|$)/i.test(locale)) try {
|
|
55
|
+
compact = new Intl.NumberFormat(locale, {
|
|
56
|
+
notation: count < 1e4 ? "standard" : "compact",
|
|
57
|
+
maximumFractionDigits: count < 1e4 ? 0 : 1
|
|
58
|
+
}).format(count);
|
|
59
|
+
} catch {
|
|
60
|
+
compact = exact;
|
|
61
|
+
}
|
|
62
|
+
else if (count < 1e3) compact = String(count);
|
|
63
|
+
else {
|
|
64
|
+
const divisor = count < 1e6 ? 1e3 : 1e6;
|
|
65
|
+
const scaled = count / divisor;
|
|
66
|
+
compact = `${scaled >= 100 ? Math.round(scaled) : Math.round(scaled * 10) / 10}${divisor === 1e3 ? "K" : "M"}`;
|
|
67
|
+
}
|
|
68
|
+
return compact === exact ? { compact } : {
|
|
69
|
+
compact,
|
|
70
|
+
exact
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// src/footer-counts.ts
|
|
74
|
+
/** Count only the native rows actually present in each footer. */
|
|
75
|
+
function countFooterSections(sections) {
|
|
76
|
+
const counts = {
|
|
77
|
+
Working: 0,
|
|
78
|
+
Archived: 0,
|
|
79
|
+
Snoozed: 0
|
|
80
|
+
};
|
|
81
|
+
for (const section of sections) counts[section]++;
|
|
82
|
+
return counts;
|
|
83
|
+
}
|
|
84
|
+
// src/footer-sizing.ts
|
|
85
|
+
/** Compute a stable footer budget from the native container, not its content-sized tree. */
|
|
86
|
+
function footerLimit(tree, viewportHeight) {
|
|
87
|
+
const treeTop = tree.getBoundingClientRect().top;
|
|
88
|
+
let scrollOffset = 0;
|
|
89
|
+
for (let ancestor = tree.parentElement; ancestor; ancestor = ancestor.parentElement) {
|
|
90
|
+
scrollOffset += ancestor.scrollTop;
|
|
91
|
+
const maxHeight = getComputedStyle(ancestor).maxHeight;
|
|
92
|
+
if (!maxHeight.endsWith("px")) continue;
|
|
93
|
+
const pixels = Number.parseFloat(maxHeight);
|
|
94
|
+
if (!Number.isFinite(pixels) || pixels <= 0) continue;
|
|
95
|
+
const offset = treeTop - ancestor.getBoundingClientRect().top + scrollOffset;
|
|
96
|
+
return Math.max(0, pixels - Math.max(0, offset)) / 2;
|
|
97
|
+
}
|
|
98
|
+
return Math.max(0, viewportHeight - Math.max(0, treeTop)) / 2;
|
|
99
|
+
}
|
|
100
|
+
/** Watch each native ancestor because its constraint can change independently of the tree. */
|
|
101
|
+
function observeFooterAncestors(observer, tree) {
|
|
102
|
+
for (let element = tree; element; element = element.parentElement) observer.observe(element);
|
|
103
|
+
}
|
|
46
104
|
// src/headings.ts
|
|
47
105
|
/**
|
|
48
106
|
* Add labels without moving, cloning or replacing any React-owned row.
|
|
@@ -65,10 +123,20 @@ function installHeadings(placements, labels, archivedCollapsible, active = () =>
|
|
|
65
123
|
/** Each footer opens independently; a reload resets to these defaults. */
|
|
66
124
|
const open = {
|
|
67
125
|
Working: true,
|
|
68
|
-
Archived: false
|
|
126
|
+
Archived: false,
|
|
127
|
+
Snoozed: false
|
|
69
128
|
};
|
|
70
129
|
const style = document.createElement("style");
|
|
71
130
|
style.textContent = `
|
|
131
|
+
/* The native wide sidebar sizes its final grid row to content. While we
|
|
132
|
+
split the list into panes, let that row and its list fill the viewport. */
|
|
133
|
+
[data-sidebar-scrollport]:has([data-dsh-inbox-tree]) {
|
|
134
|
+
grid-template-rows: 8px max-content 2px minmax(0, 1fr);
|
|
135
|
+
}
|
|
136
|
+
[data-sidebar-scrollport] :has(> [data-sidebar-list-area] [data-dsh-inbox-tree]) { flex: 1; }
|
|
137
|
+
[data-sidebar-scrollport] [data-sidebar-list-area]:has([data-dsh-inbox-tree]) { display: flex; }
|
|
138
|
+
/* The native viewport fade must not cover the independently scrolling footer. */
|
|
139
|
+
[data-sidebar-scrollport]:has([data-dsh-inbox-tree]) + span[aria-hidden="true"] { display: none; }
|
|
72
140
|
[data-dsh-inbox-tree] {
|
|
73
141
|
display: flex; flex-direction: column; padding-bottom: 0;
|
|
74
142
|
overflow: hidden; scrollbar-gutter: auto; interpolate-size: allow-keywords;
|
|
@@ -106,6 +174,8 @@ function installHeadings(placements, labels, archivedCollapsible, active = () =>
|
|
|
106
174
|
color: inherit; font: inherit; text-align: start; cursor: pointer;
|
|
107
175
|
}
|
|
108
176
|
[data-dsh-inbox-heading] button > span:first-child { display: flex; flex: 0 0 16px; }
|
|
177
|
+
[data-dsh-inbox-count] { margin-inline-start: auto; white-space: nowrap; }
|
|
178
|
+
[data-dsh-inbox-count] small { font-size: .9em; font-weight: 400; }
|
|
109
179
|
`;
|
|
110
180
|
document.head.append(style);
|
|
111
181
|
const clearWrapper = (wrapper) => {
|
|
@@ -193,7 +263,7 @@ function installHeadings(placements, labels, archivedCollapsible, active = () =>
|
|
|
193
263
|
});
|
|
194
264
|
};
|
|
195
265
|
const sizeFooters = () => {
|
|
196
|
-
for (const [tree, { footer }] of panes) footer.style.maxBlockSize = `${tree.clientHeight / 2}px`;
|
|
266
|
+
for (const [tree, { footer }] of panes) footer.style.maxBlockSize = `${Math.min(tree.clientHeight / 2, footerLimit(tree, window.innerHeight))}px`;
|
|
197
267
|
};
|
|
198
268
|
const animateArchive = (tree, from) => {
|
|
199
269
|
archiveAnimations.get(tree)?.();
|
|
@@ -206,7 +276,7 @@ function installHeadings(placements, labels, archivedCollapsible, active = () =>
|
|
|
206
276
|
const margins = getComputedStyle(wrapper);
|
|
207
277
|
naturalHeight += (headings.get(wrapper)?.offsetHeight ?? 0) + (wrapper.hasAttribute("data-dsh-inbox-closed") ? 0 : row?.scrollHeight ?? 0) + (Number.parseFloat(margins.marginTop) || 0) + (Number.parseFloat(margins.marginBottom) || 0);
|
|
208
278
|
}
|
|
209
|
-
const target = Math.min(naturalHeight, tree.clientHeight / 2);
|
|
279
|
+
const target = Math.min(naturalHeight, tree.clientHeight / 2, footerLimit(tree, window.innerHeight));
|
|
210
280
|
if (Math.abs(target - from) < .5) return;
|
|
211
281
|
const duration = open.Archived ? 480 : 260;
|
|
212
282
|
footer.style.transition = "none";
|
|
@@ -229,6 +299,7 @@ function installHeadings(placements, labels, archivedCollapsible, active = () =>
|
|
|
229
299
|
archiveAnimations.set(tree, finish);
|
|
230
300
|
};
|
|
231
301
|
const resize = new ResizeObserver(sizeFooters);
|
|
302
|
+
window.addEventListener("resize", sizeFooters);
|
|
232
303
|
let scheduled = false;
|
|
233
304
|
let disposed = false;
|
|
234
305
|
const refresh = () => {
|
|
@@ -238,6 +309,7 @@ function installHeadings(placements, labels, archivedCollapsible, active = () =>
|
|
|
238
309
|
scheduled = false;
|
|
239
310
|
if (disposed) return;
|
|
240
311
|
const wanted = /* @__PURE__ */ new Map();
|
|
312
|
+
const countsByTree = /* @__PURE__ */ new Map();
|
|
241
313
|
const foldable = archivedCollapsible();
|
|
242
314
|
resize.disconnect();
|
|
243
315
|
for (const tree of trees) delete tree.dataset.dshInboxTree;
|
|
@@ -260,13 +332,15 @@ function installHeadings(placements, labels, archivedCollapsible, active = () =>
|
|
|
260
332
|
if ([...tree.children].some((child) => child.getAttribute("slot"))) continue;
|
|
261
333
|
let previous;
|
|
262
334
|
let firstFooter = true;
|
|
335
|
+
const footerSections = [];
|
|
263
336
|
for (const row of tree.querySelectorAll("[data-row-key^=\"session:\"]")) {
|
|
264
337
|
const placement = placements().get(row.dataset.rowKey.slice(8));
|
|
265
338
|
if (placement?.blank) continue;
|
|
266
339
|
const section = placement?.section;
|
|
267
340
|
const wrapper = row.parentElement;
|
|
268
341
|
if (!section || !wrapper || wrapper.parentElement !== tree) continue;
|
|
269
|
-
if (section !== "Working" && !(section === "Archived" && foldable)) continue;
|
|
342
|
+
if (section !== "Working" && section !== "Snoozed" && !(section === "Archived" && foldable)) continue;
|
|
343
|
+
footerSections.push(section);
|
|
270
344
|
trees.add(tree);
|
|
271
345
|
tree.dataset.dshInboxTree = "";
|
|
272
346
|
wrappers.add(wrapper);
|
|
@@ -280,8 +354,9 @@ function installHeadings(placements, labels, archivedCollapsible, active = () =>
|
|
|
280
354
|
previous = section;
|
|
281
355
|
}
|
|
282
356
|
if (trees.has(tree)) {
|
|
357
|
+
countsByTree.set(tree, countFooterSections(footerSections));
|
|
283
358
|
installPane(tree);
|
|
284
|
-
resize
|
|
359
|
+
observeFooterAncestors(resize, tree);
|
|
285
360
|
}
|
|
286
361
|
}
|
|
287
362
|
for (const tree of panes.keys()) if (!trees.has(tree)) releasePane(tree);
|
|
@@ -313,11 +388,15 @@ function installHeadings(placements, labels, archivedCollapsible, active = () =>
|
|
|
313
388
|
const icon = document.createElement("span");
|
|
314
389
|
icon.setAttribute("aria-hidden", "true");
|
|
315
390
|
icons.set(heading, (0, react_dom_client.createRoot)(icon));
|
|
316
|
-
|
|
391
|
+
const label = document.createElement("span");
|
|
392
|
+
const count = document.createElement("span");
|
|
393
|
+
count.dataset.dshInboxCount = "";
|
|
394
|
+
count.append(document.createElement("span"), document.createElement("small"));
|
|
395
|
+
button.append(icon, label, count);
|
|
317
396
|
button.onclick = (event) => {
|
|
318
397
|
event.stopPropagation();
|
|
319
398
|
const current = heading.dataset.dshInboxSection;
|
|
320
|
-
if (current !== "Working" && current !== "Archived") return;
|
|
399
|
+
if (current !== "Working" && current !== "Archived" && current !== "Snoozed") return;
|
|
321
400
|
const tree = wrapper.parentElement;
|
|
322
401
|
const from = (panes.get(tree)?.footer)?.getBoundingClientRect().height ?? 0;
|
|
323
402
|
const animate = current === "Archived" || archiveAnimations.has(tree);
|
|
@@ -329,10 +408,17 @@ function installHeadings(placements, labels, archivedCollapsible, active = () =>
|
|
|
329
408
|
};
|
|
330
409
|
heading.append(button);
|
|
331
410
|
}
|
|
332
|
-
const text = section === "Archived" ? labels().archived : labels().working;
|
|
333
|
-
const label = button.
|
|
411
|
+
const text = section === "Archived" ? labels().archived : section === "Snoozed" ? labels().snoozed : labels().working;
|
|
412
|
+
const label = button.children[1];
|
|
334
413
|
if (label.textContent !== text) label.textContent = text;
|
|
335
|
-
|
|
414
|
+
const count = countsByTree.get(wrapper.parentElement)[section];
|
|
415
|
+
const parts = countParts(count, labels().language);
|
|
416
|
+
const countElement = button.children[2];
|
|
417
|
+
if (countElement.children[0].textContent !== parts.compact) countElement.children[0].textContent = parts.compact;
|
|
418
|
+
const exact = parts.exact ? ` (${parts.exact})` : "";
|
|
419
|
+
if (countElement.children[1].textContent !== exact) countElement.children[1].textContent = exact;
|
|
420
|
+
const ariaLabel = `${text} ${parts.exact ?? parts.compact}`;
|
|
421
|
+
if (button.getAttribute("aria-label") !== ariaLabel) button.setAttribute("aria-label", ariaLabel);
|
|
336
422
|
const expanded = String(open[section]);
|
|
337
423
|
if (button.getAttribute("aria-expanded") !== expanded) {
|
|
338
424
|
button.setAttribute("aria-expanded", expanded);
|
|
@@ -360,6 +446,7 @@ function installHeadings(placements, labels, archivedCollapsible, active = () =>
|
|
|
360
446
|
disposed = true;
|
|
361
447
|
observer.disconnect();
|
|
362
448
|
resize.disconnect();
|
|
449
|
+
window.removeEventListener("resize", sizeFooters);
|
|
363
450
|
for (const root of icons.values()) root.unmount();
|
|
364
451
|
icons.clear();
|
|
365
452
|
for (const heading of headings.values()) heading.remove();
|
|
@@ -560,21 +647,965 @@ function installSortOption(options) {
|
|
|
560
647
|
}
|
|
561
648
|
};
|
|
562
649
|
}
|
|
650
|
+
// locale/ja.json
|
|
651
|
+
var ui$5 = {
|
|
652
|
+
"heading.working": "作業中",
|
|
653
|
+
"heading.archived": "アーカイブ済み",
|
|
654
|
+
"sort.agentActivity": "エージェントの活動",
|
|
655
|
+
"heading.snoozed": "一時的に非表示",
|
|
656
|
+
"snooze.30m": "30分間",
|
|
657
|
+
"snooze.1h": "1時間",
|
|
658
|
+
"snooze.3h": "3時間",
|
|
659
|
+
"snooze.tomorrow": "明日の朝まで",
|
|
660
|
+
"snooze.action": "一時的に非表示",
|
|
661
|
+
"snooze.agent": "エージェントに任せる",
|
|
662
|
+
"snooze.agentFailure": "エージェントにこの会話の予定を依頼できませんでした。",
|
|
663
|
+
"snooze.wake": "表示に戻す"
|
|
664
|
+
};
|
|
665
|
+
// locale/es.json
|
|
666
|
+
var ui$4 = {
|
|
667
|
+
"heading.working": "En curso",
|
|
668
|
+
"heading.archived": "Archivadas",
|
|
669
|
+
"sort.agentActivity": "Actividad del agente",
|
|
670
|
+
"heading.snoozed": "Ocultas temporalmente",
|
|
671
|
+
"snooze.30m": "30 minutos",
|
|
672
|
+
"snooze.1h": "1 hora",
|
|
673
|
+
"snooze.3h": "3 horas",
|
|
674
|
+
"snooze.tomorrow": "Hasta mañana por la mañana",
|
|
675
|
+
"snooze.action": "Ocultar temporalmente",
|
|
676
|
+
"snooze.agent": "Que decida el agente",
|
|
677
|
+
"snooze.agentFailure": "No se pudo pedir al agente que programe esta conversación.",
|
|
678
|
+
"snooze.wake": "Mostrar de nuevo"
|
|
679
|
+
};
|
|
680
|
+
// locale/fr.json
|
|
681
|
+
var ui$3 = {
|
|
682
|
+
"heading.working": "En cours",
|
|
683
|
+
"heading.archived": "Archivées",
|
|
684
|
+
"sort.agentActivity": "Activité de l’agent",
|
|
685
|
+
"heading.snoozed": "Masquées temporairement",
|
|
686
|
+
"snooze.30m": "30 minutes",
|
|
687
|
+
"snooze.1h": "1 heure",
|
|
688
|
+
"snooze.3h": "3 heures",
|
|
689
|
+
"snooze.tomorrow": "Jusqu’à demain matin",
|
|
690
|
+
"snooze.action": "Masquer temporairement",
|
|
691
|
+
"snooze.agent": "Laisser l’agent décider",
|
|
692
|
+
"snooze.agentFailure": "Impossible de demander à l’agent de planifier cette conversation.",
|
|
693
|
+
"snooze.wake": "Réafficher"
|
|
694
|
+
};
|
|
695
|
+
// locale/de.json
|
|
696
|
+
var ui$2 = {
|
|
697
|
+
"heading.working": "In Arbeit",
|
|
698
|
+
"heading.archived": "Archiviert",
|
|
699
|
+
"sort.agentActivity": "Agentenaktivität",
|
|
700
|
+
"heading.snoozed": "Vorübergehend ausgeblendet",
|
|
701
|
+
"snooze.30m": "30 Minuten",
|
|
702
|
+
"snooze.1h": "1 Stunde",
|
|
703
|
+
"snooze.3h": "3 Stunden",
|
|
704
|
+
"snooze.tomorrow": "Bis morgen früh",
|
|
705
|
+
"snooze.action": "Vorübergehend ausblenden",
|
|
706
|
+
"snooze.agent": "Agent entscheiden lassen",
|
|
707
|
+
"snooze.agentFailure": "Der Agent konnte nicht gebeten werden, diese Unterhaltung zu planen.",
|
|
708
|
+
"snooze.wake": "Wieder einblenden"
|
|
709
|
+
};
|
|
710
|
+
// locale/ru.json
|
|
711
|
+
var ui$1 = {
|
|
712
|
+
"heading.working": "В работе",
|
|
713
|
+
"heading.archived": "Архивные",
|
|
714
|
+
"sort.agentActivity": "Активность агента",
|
|
715
|
+
"heading.snoozed": "Временно скрытые",
|
|
716
|
+
"snooze.30m": "30 минут",
|
|
717
|
+
"snooze.1h": "1 час",
|
|
718
|
+
"snooze.3h": "3 часа",
|
|
719
|
+
"snooze.tomorrow": "До завтрашнего утра",
|
|
720
|
+
"snooze.action": "Скрыть временно",
|
|
721
|
+
"snooze.agent": "Пусть решит агент",
|
|
722
|
+
"snooze.agentFailure": "Не удалось попросить агента запланировать этот разговор.",
|
|
723
|
+
"snooze.wake": "Показать снова"
|
|
724
|
+
};
|
|
725
|
+
// locale/pt.json
|
|
726
|
+
var ui = {
|
|
727
|
+
"heading.working": "Em andamento",
|
|
728
|
+
"heading.archived": "Arquivadas",
|
|
729
|
+
"sort.agentActivity": "Atividade do agente",
|
|
730
|
+
"heading.snoozed": "Ocultadas temporariamente",
|
|
731
|
+
"snooze.30m": "30 minutos",
|
|
732
|
+
"snooze.1h": "1 hora",
|
|
733
|
+
"snooze.3h": "3 horas",
|
|
734
|
+
"snooze.tomorrow": "Até amanhã de manhã",
|
|
735
|
+
"snooze.action": "Ocultar temporariamente",
|
|
736
|
+
"snooze.agent": "Deixar o agente decidir",
|
|
737
|
+
"snooze.agentFailure": "Não foi possível pedir ao agente que agende esta conversa.",
|
|
738
|
+
"snooze.wake": "Mostrar novamente"
|
|
739
|
+
};
|
|
563
740
|
// src/locale.ts
|
|
564
741
|
/** Dictionary namespace owned by this plugin, registered into the DSH locale service. */
|
|
565
742
|
const NS = "dungsil-sidebar-inbox";
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
743
|
+
const dictionaries = {
|
|
744
|
+
en: {
|
|
745
|
+
"heading.working": "Working",
|
|
746
|
+
"heading.archived": "Archived",
|
|
747
|
+
"sort.agentActivity": "Agent activity",
|
|
748
|
+
"heading.snoozed": "Snoozed",
|
|
749
|
+
"snooze.action": "Snooze",
|
|
750
|
+
"snooze.agent": "Let the agent decide",
|
|
751
|
+
"snooze.agentFailure": "Could not ask the agent to schedule this conversation.",
|
|
752
|
+
"snooze.wake": "Unsnooze",
|
|
753
|
+
"snooze.30m": "30 minutes",
|
|
754
|
+
"snooze.1h": "1 hour",
|
|
755
|
+
"snooze.3h": "3 hours",
|
|
756
|
+
"snooze.tomorrow": "Until tomorrow morning"
|
|
757
|
+
},
|
|
758
|
+
ko: {
|
|
759
|
+
"heading.working": "작업 중",
|
|
760
|
+
"heading.archived": "보관됨",
|
|
761
|
+
"sort.agentActivity": "에이전트 활동",
|
|
762
|
+
"heading.snoozed": "잠시 숨김",
|
|
763
|
+
"snooze.action": "잠시 숨기기",
|
|
764
|
+
"snooze.agent": "에이전트가 정하기",
|
|
765
|
+
"snooze.agentFailure": "에이전트에게 이 대화의 일정을 요청하지 못했습니다.",
|
|
766
|
+
"snooze.wake": "다시 표시",
|
|
767
|
+
"snooze.30m": "30분 동안",
|
|
768
|
+
"snooze.1h": "1시간 동안",
|
|
769
|
+
"snooze.3h": "3시간 동안",
|
|
770
|
+
"snooze.tomorrow": "내일 아침까지"
|
|
771
|
+
},
|
|
772
|
+
zh: {
|
|
773
|
+
"heading.working": "进行中",
|
|
774
|
+
"heading.archived": "已归档",
|
|
775
|
+
"heading.snoozed": "已暂时隐藏",
|
|
776
|
+
"sort.agentActivity": "智能体活动",
|
|
777
|
+
"snooze.action": "暂时隐藏",
|
|
778
|
+
"snooze.agent": "由智能体决定",
|
|
779
|
+
"snooze.agentFailure": "无法请求智能体安排此对话。",
|
|
780
|
+
"snooze.wake": "重新显示",
|
|
781
|
+
"snooze.30m": "30分钟",
|
|
782
|
+
"snooze.1h": "1小时",
|
|
783
|
+
"snooze.3h": "3小时",
|
|
784
|
+
"snooze.tomorrow": "直到明天早上"
|
|
785
|
+
},
|
|
786
|
+
ja: ui$5,
|
|
787
|
+
es: ui$4,
|
|
788
|
+
fr: ui$3,
|
|
789
|
+
de: ui$2,
|
|
790
|
+
ru: ui$1,
|
|
791
|
+
pt: ui
|
|
571
792
|
};
|
|
572
|
-
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
793
|
+
// src/worktree-activity.ts
|
|
794
|
+
const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
795
|
+
/** Only a directly submitted human message can begin first-turn worktree creation. */
|
|
796
|
+
const hasPendingHumanInput = (inbox) => {
|
|
797
|
+
if (!isRecord(inbox)) return false;
|
|
798
|
+
return ["next-turn", "next-step"].some((target) => {
|
|
799
|
+
const messages = inbox[target];
|
|
800
|
+
return Array.isArray(messages) && messages.some((message) => {
|
|
801
|
+
if (!isRecord(message) || message.role !== "user" || !isRecord(message.source) || message.source.kind !== "user" || !Array.isArray(message.content)) return false;
|
|
802
|
+
return message.content.some((block) => isRecord(block) && (block.type === "image" || block.type === "file" || block.type === "text" && typeof block.text === "string" && block.text.replaceAll(/[\p{Cc}\p{Cf}\s]/gu, "").length > 0));
|
|
803
|
+
});
|
|
804
|
+
});
|
|
577
805
|
};
|
|
806
|
+
const WORKTREE_INJECT = ["remote", "remote.forgePanel"];
|
|
807
|
+
/** 세션을 보유하지 않고 실제 생성 중인 행만 추적한다. 종료된 구독은 연결 재설정 때만 재개한다. */
|
|
808
|
+
const createWorktreeActivity = (changed) => {
|
|
809
|
+
const active = /* @__PURE__ */ new Set();
|
|
810
|
+
const watches = /* @__PURE__ */ new Map();
|
|
811
|
+
let follow = null;
|
|
812
|
+
let candidates = /* @__PURE__ */ new Set();
|
|
813
|
+
let disposed = false;
|
|
814
|
+
const publish = (id, running) => {
|
|
815
|
+
if (active.has(id) === running) return;
|
|
816
|
+
if (running) active.add(id);
|
|
817
|
+
else active.delete(id);
|
|
818
|
+
changed();
|
|
819
|
+
};
|
|
820
|
+
const release = (watch) => {
|
|
821
|
+
const { stream } = watch;
|
|
822
|
+
watch.stream = null;
|
|
823
|
+
try {
|
|
824
|
+
stream?.dispose();
|
|
825
|
+
} catch {}
|
|
826
|
+
};
|
|
827
|
+
const observe = async (id, watch) => {
|
|
828
|
+
try {
|
|
829
|
+
const stream = follow?.(id, watch.controller.signal);
|
|
830
|
+
if (stream === void 0) return;
|
|
831
|
+
watch.stream = stream;
|
|
832
|
+
for await (const panel of stream) {
|
|
833
|
+
if (watch.controller.signal.aborted || watches.get(id) !== watch) break;
|
|
834
|
+
publish(id, panel.worktree.creation !== null);
|
|
835
|
+
}
|
|
836
|
+
} catch {} finally {
|
|
837
|
+
release(watch);
|
|
838
|
+
if (watches.get(id) === watch) publish(id, false);
|
|
839
|
+
}
|
|
840
|
+
};
|
|
841
|
+
const stop = (id) => {
|
|
842
|
+
const watch = watches.get(id);
|
|
843
|
+
watches.delete(id);
|
|
844
|
+
watch?.controller.abort();
|
|
845
|
+
if (watch !== void 0) release(watch);
|
|
846
|
+
return active.delete(id);
|
|
847
|
+
};
|
|
848
|
+
const sync = () => {
|
|
849
|
+
let cleared = false;
|
|
850
|
+
for (const id of watches.keys()) if (!candidates.has(id) || follow === null) cleared = stop(id) || cleared;
|
|
851
|
+
if (follow !== null) {
|
|
852
|
+
for (const id of candidates) if (!watches.has(id)) {
|
|
853
|
+
const watch = {
|
|
854
|
+
controller: new AbortController(),
|
|
855
|
+
stream: null
|
|
856
|
+
};
|
|
857
|
+
watches.set(id, watch);
|
|
858
|
+
observe(id, watch);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
return cleared;
|
|
862
|
+
};
|
|
863
|
+
const reset = () => {
|
|
864
|
+
let cleared = false;
|
|
865
|
+
for (const id of watches.keys()) cleared = stop(id) || cleared;
|
|
866
|
+
sync();
|
|
867
|
+
if (cleared) changed();
|
|
868
|
+
};
|
|
869
|
+
return {
|
|
870
|
+
active,
|
|
871
|
+
attach: (child) => {
|
|
872
|
+
if (disposed) return () => {};
|
|
873
|
+
const scoped = child;
|
|
874
|
+
follow = (id, signal) => scoped.remote.forgePanel.follow(id, signal);
|
|
875
|
+
const unsubscribe = scoped.on("connection/reset", reset);
|
|
876
|
+
sync();
|
|
877
|
+
return () => {
|
|
878
|
+
follow = null;
|
|
879
|
+
unsubscribe();
|
|
880
|
+
if (sync()) changed();
|
|
881
|
+
};
|
|
882
|
+
},
|
|
883
|
+
dispose: () => {
|
|
884
|
+
disposed = true;
|
|
885
|
+
candidates.clear();
|
|
886
|
+
follow = null;
|
|
887
|
+
sync();
|
|
888
|
+
},
|
|
889
|
+
reconcile: (list, statuses) => {
|
|
890
|
+
if (disposed) return;
|
|
891
|
+
candidates = new Set(list.ids.filter((id) => {
|
|
892
|
+
const row = list.byId[id];
|
|
893
|
+
if (row === void 0 || row.blank || row.origin === "subagent" || (statuses.get(id)?.running ?? row.running)) return false;
|
|
894
|
+
const values = list.projectionsBySession[id]?.values ?? {};
|
|
895
|
+
const projections = values;
|
|
896
|
+
if (isRecord(projections.forgeWorktree) || values.sessionListMetadata?.blank === false) return false;
|
|
897
|
+
return hasPendingHumanInput(projections.inbox);
|
|
898
|
+
}));
|
|
899
|
+
sync();
|
|
900
|
+
}
|
|
901
|
+
};
|
|
902
|
+
};
|
|
903
|
+
// src/snooze.ts
|
|
904
|
+
/** Storage key of the snooze state: a JSON object from session id to entry. */
|
|
905
|
+
const SNOOZE_KEY = "dungsil.sidebar-inbox.snooze.v1";
|
|
906
|
+
/** Fixed durations listed in the menu. Only `tomorrow` resolves to the next morning. */
|
|
907
|
+
const SNOOZE_CHOICES = [
|
|
908
|
+
"30m",
|
|
909
|
+
"1h",
|
|
910
|
+
"3h",
|
|
911
|
+
"tomorrow"
|
|
912
|
+
];
|
|
913
|
+
/** Choice id that lets the agent decide when the session should come back. */
|
|
914
|
+
const AGENT_CHOICE = "agent";
|
|
915
|
+
const MINUTE = 6e4;
|
|
916
|
+
/** Local hour that `tomorrow` points at. */
|
|
917
|
+
const MORNING_HOUR = 9;
|
|
918
|
+
/** Largest setTimeout delay. A later expiry is checked again after this long. */
|
|
919
|
+
const MAX_TIMEOUT = 2147483647;
|
|
920
|
+
/** Slack added so a timer that fires just before the deadline still reads as expired. */
|
|
921
|
+
const EXPIRY_GRACE_MS = 50;
|
|
922
|
+
const MINUTES = {
|
|
923
|
+
"1h": 60,
|
|
924
|
+
"30m": 30,
|
|
925
|
+
"3h": 180
|
|
926
|
+
};
|
|
927
|
+
const HOLD = { wake: false };
|
|
928
|
+
/** Expiry time of the chosen duration. `tomorrow` is 09:00 local time on the next day. */
|
|
929
|
+
function snoozeDeadline(choice, now) {
|
|
930
|
+
if (choice === "tomorrow") {
|
|
931
|
+
const date = new Date(now);
|
|
932
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1, MORNING_HOUR).getTime();
|
|
933
|
+
}
|
|
934
|
+
return now + MINUTES[choice] * MINUTE;
|
|
935
|
+
}
|
|
936
|
+
/** Wait until a fixed time. Wake once it has passed. */
|
|
937
|
+
function untilVerdict(until, now) {
|
|
938
|
+
return until > now ? {
|
|
939
|
+
recheckAt: until,
|
|
940
|
+
wake: false
|
|
941
|
+
} : { wake: true };
|
|
942
|
+
}
|
|
943
|
+
function isAgentSnooze(value) {
|
|
944
|
+
if (typeof value !== "object" || value === null || !("agent" in value)) return false;
|
|
945
|
+
return typeof value.agent === "number" && Number.isFinite(value.agent);
|
|
946
|
+
}
|
|
947
|
+
/** Read stored text into a map of valid entries. Broken values and fixed times already past are dropped. */
|
|
948
|
+
function parseSnooze(raw, now) {
|
|
949
|
+
const active = /* @__PURE__ */ new Map();
|
|
950
|
+
if (raw === null) return active;
|
|
951
|
+
let stored;
|
|
952
|
+
try {
|
|
953
|
+
stored = JSON.parse(raw);
|
|
954
|
+
} catch {
|
|
955
|
+
return active;
|
|
956
|
+
}
|
|
957
|
+
if (stored === null || typeof stored !== "object" || Array.isArray(stored)) return active;
|
|
958
|
+
for (const [id, value] of Object.entries(stored)) {
|
|
959
|
+
if (id === "") continue;
|
|
960
|
+
if (typeof value === "number" && Number.isFinite(value) && value > now) active.set(id, value);
|
|
961
|
+
else if (isAgentSnooze(value)) active.set(id, { agent: value.agent });
|
|
962
|
+
}
|
|
963
|
+
return active;
|
|
964
|
+
}
|
|
965
|
+
/** Convert to the stored form. */
|
|
966
|
+
function serializeSnooze(entries) {
|
|
967
|
+
return JSON.stringify(Object.fromEntries(entries));
|
|
968
|
+
}
|
|
969
|
+
/** Judge one entry at the given time. */
|
|
970
|
+
function judgeSnooze(id, entry, now, judgeAgent) {
|
|
971
|
+
return typeof entry === "number" ? untilVerdict(entry, now) : judgeAgent?.(id, entry.agent, now) ?? HOLD;
|
|
972
|
+
}
|
|
973
|
+
/** Drop the entries that should wake. Returns the same map when nothing changed. */
|
|
974
|
+
function pruneSnooze(entries, now, judgeAgent) {
|
|
975
|
+
let next;
|
|
976
|
+
for (const [id, entry] of entries) {
|
|
977
|
+
if (!judgeSnooze(id, entry, now, judgeAgent).wake) continue;
|
|
978
|
+
next ??= new Map(entries);
|
|
979
|
+
next.delete(id);
|
|
980
|
+
}
|
|
981
|
+
return next ?? entries;
|
|
982
|
+
}
|
|
983
|
+
/** Timer delay until the next check, or undefined when nothing needs a recheck. */
|
|
984
|
+
function snoozeDelay(entries, now, judgeAgent) {
|
|
985
|
+
let earliest = Number.POSITIVE_INFINITY;
|
|
986
|
+
for (const [id, entry] of entries) {
|
|
987
|
+
const verdict = judgeSnooze(id, entry, now, judgeAgent);
|
|
988
|
+
earliest = Math.min(earliest, verdict.wake ? now : verdict.recheckAt ?? Number.POSITIVE_INFINITY);
|
|
989
|
+
}
|
|
990
|
+
if (!Number.isFinite(earliest)) return void 0;
|
|
991
|
+
return Math.min(Math.max(earliest - now, 0) + EXPIRY_GRACE_MS, MAX_TIMEOUT);
|
|
992
|
+
}
|
|
993
|
+
// src/snooze-state.ts
|
|
994
|
+
/**
|
|
995
|
+
* Owns the per-session snooze entries and their expiry timer. The clock, storage
|
|
996
|
+
* and timer are injected so the same paths run without a browser; placing rows
|
|
997
|
+
* is left to the caller.
|
|
998
|
+
*/
|
|
999
|
+
function createSnoozeState({ now, storage, schedule, onChange, judgeAgent }) {
|
|
1000
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1001
|
+
const read = () => {
|
|
1002
|
+
try {
|
|
1003
|
+
return parseSnooze(storage.read(), now());
|
|
1004
|
+
} catch {
|
|
1005
|
+
return /* @__PURE__ */ new Map();
|
|
1006
|
+
}
|
|
1007
|
+
};
|
|
1008
|
+
let entries = read();
|
|
1009
|
+
let cancel = null;
|
|
1010
|
+
let disposed = false;
|
|
1011
|
+
/** Expiry callback. It and the due check call each other, so it is filled in below. */
|
|
1012
|
+
const pending = { expire: () => void 0 };
|
|
1013
|
+
const notify = () => {
|
|
1014
|
+
for (const listener of listeners) listener();
|
|
1015
|
+
};
|
|
1016
|
+
const persist = () => {
|
|
1017
|
+
try {
|
|
1018
|
+
storage.write(serializeSnooze(entries));
|
|
1019
|
+
} catch {}
|
|
1020
|
+
};
|
|
1021
|
+
/** Re-arm the timer for the next check. Without one, only clear the old timer. */
|
|
1022
|
+
const arm = () => {
|
|
1023
|
+
cancel?.();
|
|
1024
|
+
cancel = null;
|
|
1025
|
+
if (disposed) return;
|
|
1026
|
+
const delay = snoozeDelay(entries, now(), judgeAgent);
|
|
1027
|
+
if (delay !== void 0) cancel = schedule(pending.expire, delay);
|
|
1028
|
+
};
|
|
1029
|
+
/** Drop the entries that should wake, then arm the next check. */
|
|
1030
|
+
const pruneDue = () => {
|
|
1031
|
+
const active = pruneSnooze(entries, now(), judgeAgent);
|
|
1032
|
+
if (active !== entries) {
|
|
1033
|
+
entries = active;
|
|
1034
|
+
persist();
|
|
1035
|
+
notify();
|
|
1036
|
+
}
|
|
1037
|
+
arm();
|
|
1038
|
+
};
|
|
1039
|
+
const commit = (next) => {
|
|
1040
|
+
entries = next;
|
|
1041
|
+
persist();
|
|
1042
|
+
notify();
|
|
1043
|
+
arm();
|
|
1044
|
+
if (!disposed) onChange();
|
|
1045
|
+
};
|
|
1046
|
+
const put = (sessionId, entry) => {
|
|
1047
|
+
commit(new Map([...entries, [sessionId, entry]]));
|
|
1048
|
+
};
|
|
1049
|
+
pending.expire = () => {
|
|
1050
|
+
cancel = null;
|
|
1051
|
+
pruneDue();
|
|
1052
|
+
onChange();
|
|
1053
|
+
};
|
|
1054
|
+
arm();
|
|
1055
|
+
return {
|
|
1056
|
+
dispose: () => {
|
|
1057
|
+
disposed = true;
|
|
1058
|
+
cancel?.();
|
|
1059
|
+
cancel = null;
|
|
1060
|
+
listeners.clear();
|
|
1061
|
+
},
|
|
1062
|
+
getSnapshot: () => entries,
|
|
1063
|
+
prune: pruneDue,
|
|
1064
|
+
snooze: (sessionId, choice) => {
|
|
1065
|
+
put(sessionId, snoozeDeadline(choice, now()));
|
|
1066
|
+
},
|
|
1067
|
+
snoozeAgent: (sessionId) => {
|
|
1068
|
+
put(sessionId, { agent: now() });
|
|
1069
|
+
},
|
|
1070
|
+
subscribe: (listener) => {
|
|
1071
|
+
listeners.add(listener);
|
|
1072
|
+
return () => {
|
|
1073
|
+
listeners.delete(listener);
|
|
1074
|
+
};
|
|
1075
|
+
},
|
|
1076
|
+
wake: (sessionId) => {
|
|
1077
|
+
if (!entries.has(sessionId)) return;
|
|
1078
|
+
commit(new Map([...entries].filter(([id]) => id !== sessionId)));
|
|
1079
|
+
}
|
|
1080
|
+
};
|
|
1081
|
+
}
|
|
1082
|
+
// src/agent-wake.ts
|
|
1083
|
+
/** How long to wait after a request for the agent turn to start. Without a turn by then, it counts as over. */
|
|
1084
|
+
const AGENT_START_GRACE_MS = 6e4;
|
|
1085
|
+
/** How long to wait after a turn ends for the automation list refresh to arrive. */
|
|
1086
|
+
const AGENT_SETTLE_MS = 5e3;
|
|
1087
|
+
/** The request sent to the agent. A model-facing instruction, so it stays in English. */
|
|
1088
|
+
const AGENT_PROMPT = [
|
|
1089
|
+
"[Sidebar snooze] I snoozed this conversation in the sidebar. Decide when it should come back to my attention.",
|
|
1090
|
+
"Choose the time from the state of the work in this conversation, for example when a running job should be finished or a follow-up is due.",
|
|
1091
|
+
"Create exactly one one-time scheduled task that is delivered to this session at that time (schedule_create with target this_session). Its prompt must say what to check or continue then.",
|
|
1092
|
+
"Do not start other work now. Reply with one short sentence in the language of this conversation that states the chosen time."
|
|
1093
|
+
].join("\n");
|
|
1094
|
+
/**
|
|
1095
|
+
* Menu action for the agent choice. If a task already delivers to this session, its time
|
|
1096
|
+
* is followed; otherwise the agent is asked to decide. A refused request undoes the snooze,
|
|
1097
|
+
* unless the user picked another duration for the entry in the meantime.
|
|
1098
|
+
*/
|
|
1099
|
+
function createAgentChoice({ hasPlan, request, state }) {
|
|
1100
|
+
return async (sessionId) => {
|
|
1101
|
+
state.snoozeAgent(sessionId);
|
|
1102
|
+
if (hasPlan(sessionId)) return;
|
|
1103
|
+
const entry = state.getSnapshot().get(sessionId);
|
|
1104
|
+
if (!await request(sessionId, AGENT_PROMPT)) {
|
|
1105
|
+
if (state.getSnapshot().get(sessionId) === entry) state.wake(sessionId);
|
|
1106
|
+
throw new Error("Agent snooze request was not accepted");
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
/** Earliest run time among the active tasks delivered to this session. */
|
|
1111
|
+
function nextWake(tasks, sessionId) {
|
|
1112
|
+
let earliest;
|
|
1113
|
+
for (const task of tasks) if (task.sessionId === sessionId && task.active) earliest = earliest === void 0 ? task.scheduledAt : Math.min(earliest, task.scheduledAt);
|
|
1114
|
+
return earliest;
|
|
1115
|
+
}
|
|
1116
|
+
/**
|
|
1117
|
+
* Decides when an agent snooze ends. The wake time is the next run of an automation
|
|
1118
|
+
* task delivered to the session, and one delivery after the request wakes it at once;
|
|
1119
|
+
* a recurring task moves to its next time after delivery, so ignoring delivery records
|
|
1120
|
+
* would hide the row again. With no task, it waits for the agent turn to end and then
|
|
1121
|
+
* wakes, so a row the agent never scheduled is not lost.
|
|
1122
|
+
*/
|
|
1123
|
+
function createAgentWake({ busy, schedule }) {
|
|
1124
|
+
/**
|
|
1125
|
+
* Sessions whose turn was seen running after the request. `idleAt` is when the turn was first
|
|
1126
|
+
* seen ended, or null while running. Keyed with the request time so a request made after
|
|
1127
|
+
* showing the row again does not read the earlier turn.
|
|
1128
|
+
*/
|
|
1129
|
+
const turns = /* @__PURE__ */ new Map();
|
|
1130
|
+
const wake = (sessionId) => {
|
|
1131
|
+
turns.delete(sessionId);
|
|
1132
|
+
return { wake: true };
|
|
1133
|
+
};
|
|
1134
|
+
return {
|
|
1135
|
+
hasPlan: (sessionId) => {
|
|
1136
|
+
const { settled, tasks } = schedule();
|
|
1137
|
+
return settled && nextWake(tasks, sessionId) !== void 0;
|
|
1138
|
+
},
|
|
1139
|
+
judge: (sessionId, requestedAt, now) => {
|
|
1140
|
+
const { settled, tasks } = schedule();
|
|
1141
|
+
if (!settled) return { wake: false };
|
|
1142
|
+
if (tasks.some((task) => task.sessionId === sessionId && task.deliveredAt !== void 0 && task.deliveredAt >= requestedAt)) return wake(sessionId);
|
|
1143
|
+
const next = nextWake(tasks, sessionId);
|
|
1144
|
+
if (next !== void 0) {
|
|
1145
|
+
const verdict = untilVerdict(next, now);
|
|
1146
|
+
return verdict.wake ? wake(sessionId) : verdict;
|
|
1147
|
+
}
|
|
1148
|
+
if (busy(sessionId)) {
|
|
1149
|
+
turns.set(sessionId, {
|
|
1150
|
+
idleAt: null,
|
|
1151
|
+
requestedAt
|
|
1152
|
+
});
|
|
1153
|
+
return { wake: false };
|
|
1154
|
+
}
|
|
1155
|
+
const turn = turns.get(sessionId);
|
|
1156
|
+
const idleAt = turn?.requestedAt === requestedAt ? turn.idleAt : void 0;
|
|
1157
|
+
if (idleAt === null) {
|
|
1158
|
+
turns.set(sessionId, {
|
|
1159
|
+
idleAt: now,
|
|
1160
|
+
requestedAt
|
|
1161
|
+
});
|
|
1162
|
+
return {
|
|
1163
|
+
recheckAt: now + AGENT_SETTLE_MS,
|
|
1164
|
+
wake: false
|
|
1165
|
+
};
|
|
1166
|
+
}
|
|
1167
|
+
const deadline = idleAt === void 0 ? requestedAt + AGENT_START_GRACE_MS : idleAt + AGENT_SETTLE_MS;
|
|
1168
|
+
return now >= deadline ? wake(sessionId) : {
|
|
1169
|
+
recheckAt: deadline,
|
|
1170
|
+
wake: false
|
|
1171
|
+
};
|
|
1172
|
+
}
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1175
|
+
// src/schedule-link.ts
|
|
1176
|
+
const DETACHED = {
|
|
1177
|
+
available: false,
|
|
1178
|
+
sessionIds: /* @__PURE__ */ new Set(),
|
|
1179
|
+
settled: false,
|
|
1180
|
+
tasks: []
|
|
1181
|
+
};
|
|
1182
|
+
/** Classify scheduled new-session targets and the last actual delivery too, leaving manual wake tasks unchanged. */
|
|
1183
|
+
function automationSessionIds(entries) {
|
|
1184
|
+
const ids = /* @__PURE__ */ new Set();
|
|
1185
|
+
for (const entry of entries) {
|
|
1186
|
+
for (const id of entry.deliveredSessionIds ?? []) ids.add(id);
|
|
1187
|
+
if ((entry.target.kind === "session" || entry.target.kind === "new_once") && entry.target.sessionId !== void 0) ids.add(entry.target.sessionId);
|
|
1188
|
+
if (entry.lastDelivery?.targetSessionId !== void 0) ids.add(entry.lastDelivery.targetSessionId);
|
|
1189
|
+
}
|
|
1190
|
+
return ids;
|
|
1191
|
+
}
|
|
1192
|
+
function parseTime(value) {
|
|
1193
|
+
if (value === void 0) return void 0;
|
|
1194
|
+
const time = Date.parse(value);
|
|
1195
|
+
return Number.isFinite(time) ? time : void 0;
|
|
1196
|
+
}
|
|
1197
|
+
/** Keep only tasks delivered to an existing session. A task that creates a new session never wakes this row. */
|
|
1198
|
+
function toWakeTasks(entries) {
|
|
1199
|
+
const tasks = [];
|
|
1200
|
+
for (const entry of entries) {
|
|
1201
|
+
const { sessionId } = entry.target;
|
|
1202
|
+
const scheduledAt = parseTime(entry.scheduledAt);
|
|
1203
|
+
if (entry.target.kind !== "session" || sessionId === void 0 || scheduledAt === void 0) continue;
|
|
1204
|
+
const deliveredAt = parseTime(entry.lastDelivery?.deliveredAt);
|
|
1205
|
+
tasks.push({
|
|
1206
|
+
active: entry.status === "active",
|
|
1207
|
+
...deliveredAt === void 0 ? {} : { deliveredAt },
|
|
1208
|
+
scheduledAt,
|
|
1209
|
+
sessionId
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
return tasks;
|
|
1213
|
+
}
|
|
1214
|
+
/**
|
|
1215
|
+
* Turns the automation catalog into a snapshot the sidebar can subscribe to. The
|
|
1216
|
+
* service is an optional dependency with its own mount and lifetime, so the link
|
|
1217
|
+
* answers "unavailable" before attaching and after detaching. A late earlier read
|
|
1218
|
+
* is dropped, and a failed read keeps the last successful result.
|
|
1219
|
+
*/
|
|
1220
|
+
function createScheduleLink() {
|
|
1221
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1222
|
+
let snapshot = DETACHED;
|
|
1223
|
+
let current = null;
|
|
1224
|
+
let generation = 0;
|
|
1225
|
+
const publish = (next) => {
|
|
1226
|
+
snapshot = next;
|
|
1227
|
+
for (const listener of listeners) listener();
|
|
1228
|
+
};
|
|
1229
|
+
const read = async (deps) => {
|
|
1230
|
+
generation += 1;
|
|
1231
|
+
const ticket = generation;
|
|
1232
|
+
let result;
|
|
1233
|
+
try {
|
|
1234
|
+
result = await deps.list();
|
|
1235
|
+
} catch {
|
|
1236
|
+
return;
|
|
1237
|
+
}
|
|
1238
|
+
if (current !== deps || ticket !== generation || !result.ok) return;
|
|
1239
|
+
publish({
|
|
1240
|
+
available: true,
|
|
1241
|
+
sessionIds: automationSessionIds(result.value),
|
|
1242
|
+
settled: true,
|
|
1243
|
+
tasks: toWakeTasks(result.value)
|
|
1244
|
+
});
|
|
1245
|
+
};
|
|
1246
|
+
return {
|
|
1247
|
+
attach: (deps) => {
|
|
1248
|
+
current = deps;
|
|
1249
|
+
publish({
|
|
1250
|
+
...DETACHED,
|
|
1251
|
+
available: true
|
|
1252
|
+
});
|
|
1253
|
+
const refresh = () => {
|
|
1254
|
+
read(deps);
|
|
1255
|
+
};
|
|
1256
|
+
const stops = [deps.subscribeChanged(refresh), deps.subscribeReset(refresh)];
|
|
1257
|
+
refresh();
|
|
1258
|
+
return () => {
|
|
1259
|
+
for (const stop of stops) stop();
|
|
1260
|
+
if (current === deps) {
|
|
1261
|
+
current = null;
|
|
1262
|
+
publish(DETACHED);
|
|
1263
|
+
}
|
|
1264
|
+
};
|
|
1265
|
+
},
|
|
1266
|
+
getSnapshot: () => snapshot,
|
|
1267
|
+
request: async (sessionId, text) => {
|
|
1268
|
+
if (current === null) return false;
|
|
1269
|
+
try {
|
|
1270
|
+
return (await current.prompt(sessionId, text)).ok;
|
|
1271
|
+
} catch {
|
|
1272
|
+
return false;
|
|
1273
|
+
}
|
|
1274
|
+
},
|
|
1275
|
+
subscribe: (listener) => {
|
|
1276
|
+
listeners.add(listener);
|
|
1277
|
+
return () => {
|
|
1278
|
+
listeners.delete(listener);
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
};
|
|
1282
|
+
}
|
|
1283
|
+
// src/schedule-catalog.ts
|
|
1284
|
+
function collect(page, ids, previousHead) {
|
|
1285
|
+
const previousIndex = previousHead === void 0 ? -1 : page.records.findIndex((record) => record.messageId === previousHead);
|
|
1286
|
+
const records = previousIndex === -1 ? page.records : page.records.slice(0, previousIndex + 1);
|
|
1287
|
+
for (const record of records) ids.add(record.targetSessionId);
|
|
1288
|
+
return previousIndex === -1 ? page.nextBefore : void 0;
|
|
1289
|
+
}
|
|
1290
|
+
function isPage(result) {
|
|
1291
|
+
return result?.ok === true && "records" in result.value;
|
|
1292
|
+
}
|
|
1293
|
+
/**
|
|
1294
|
+
* Enriches catalog entries with the sessions their deliveries went to. History is only
|
|
1295
|
+
* evidence of a target, so it is filled in separately and a slow read never blocks the
|
|
1296
|
+
* wake judgment.
|
|
1297
|
+
*/
|
|
1298
|
+
function createCatalogReader(remote, historyAvailable = () => true) {
|
|
1299
|
+
const cached = /* @__PURE__ */ new Map();
|
|
1300
|
+
const pending = /* @__PURE__ */ new Map();
|
|
1301
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1302
|
+
let generation = 0;
|
|
1303
|
+
let disposed = false;
|
|
1304
|
+
const notify = () => {
|
|
1305
|
+
for (const listener of listeners) listener();
|
|
1306
|
+
};
|
|
1307
|
+
const deliveries = async (id, delivery) => {
|
|
1308
|
+
const ticket = generation;
|
|
1309
|
+
const previous = cached.get(id);
|
|
1310
|
+
const ids = new Set(previous?.ids);
|
|
1311
|
+
const cursors = /* @__PURE__ */ new Set();
|
|
1312
|
+
let before;
|
|
1313
|
+
let head = previous?.head;
|
|
1314
|
+
let complete = true;
|
|
1315
|
+
let more = true;
|
|
1316
|
+
try {
|
|
1317
|
+
while (more) {
|
|
1318
|
+
const result = await remote.history?.({
|
|
1319
|
+
...before === void 0 ? {} : { before },
|
|
1320
|
+
id,
|
|
1321
|
+
limit: 100
|
|
1322
|
+
});
|
|
1323
|
+
if (disposed || ticket !== generation) return;
|
|
1324
|
+
if (isPage(result)) {
|
|
1325
|
+
if (before === void 0) head = result.value.records[0]?.messageId;
|
|
1326
|
+
before = collect(result.value, ids, previous?.head);
|
|
1327
|
+
if (before === void 0) more = false;
|
|
1328
|
+
else if (cursors.has(before)) {
|
|
1329
|
+
complete = false;
|
|
1330
|
+
more = false;
|
|
1331
|
+
} else cursors.add(before);
|
|
1332
|
+
} else {
|
|
1333
|
+
complete = false;
|
|
1334
|
+
more = false;
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
} catch {
|
|
1338
|
+
complete = false;
|
|
1339
|
+
}
|
|
1340
|
+
if (disposed || ticket !== generation) return;
|
|
1341
|
+
const anchor = complete ? head : previous?.head;
|
|
1342
|
+
cached.set(id, {
|
|
1343
|
+
delivery,
|
|
1344
|
+
...anchor === void 0 ? {} : { head: anchor },
|
|
1345
|
+
ids: [...ids]
|
|
1346
|
+
});
|
|
1347
|
+
pending.delete(id);
|
|
1348
|
+
notify();
|
|
1349
|
+
};
|
|
1350
|
+
const enrich = (entry) => {
|
|
1351
|
+
const { id, lastDelivery } = entry;
|
|
1352
|
+
const previous = id === void 0 ? void 0 : cached.get(id);
|
|
1353
|
+
if (id !== void 0 && lastDelivery !== void 0 && remote.history !== void 0 && historyAvailable()) {
|
|
1354
|
+
if (previous?.delivery !== lastDelivery.deliveredAt && !pending.has(id)) {
|
|
1355
|
+
pending.set(id, lastDelivery.deliveredAt);
|
|
1356
|
+
deliveries(id, lastDelivery.deliveredAt);
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
return previous === void 0 ? entry : {
|
|
1360
|
+
...entry,
|
|
1361
|
+
deliveredSessionIds: previous.ids
|
|
1362
|
+
};
|
|
1363
|
+
};
|
|
1364
|
+
return {
|
|
1365
|
+
dispose: () => {
|
|
1366
|
+
disposed = true;
|
|
1367
|
+
generation += 1;
|
|
1368
|
+
pending.clear();
|
|
1369
|
+
cached.clear();
|
|
1370
|
+
listeners.clear();
|
|
1371
|
+
},
|
|
1372
|
+
read: async () => {
|
|
1373
|
+
const result = await remote.catalog();
|
|
1374
|
+
if (!result.ok || disposed) return result;
|
|
1375
|
+
return {
|
|
1376
|
+
ok: true,
|
|
1377
|
+
value: result.value.map(enrich)
|
|
1378
|
+
};
|
|
1379
|
+
},
|
|
1380
|
+
reset: () => {
|
|
1381
|
+
generation += 1;
|
|
1382
|
+
pending.clear();
|
|
1383
|
+
for (const [id, entry] of cached) cached.set(id, {
|
|
1384
|
+
...entry.head === void 0 ? {} : { head: entry.head },
|
|
1385
|
+
ids: entry.ids
|
|
1386
|
+
});
|
|
1387
|
+
notify();
|
|
1388
|
+
},
|
|
1389
|
+
subscribe: (listener) => {
|
|
1390
|
+
listeners.add(listener);
|
|
1391
|
+
return () => {
|
|
1392
|
+
listeners.delete(listener);
|
|
1393
|
+
};
|
|
1394
|
+
}
|
|
1395
|
+
};
|
|
1396
|
+
}
|
|
1397
|
+
// src/schedule-remote.ts
|
|
1398
|
+
/** Services injected together into the child context. If any is missing, the link is not attached. */
|
|
1399
|
+
const SCHEDULE_INJECT = [
|
|
1400
|
+
"remote",
|
|
1401
|
+
"remote.schedule",
|
|
1402
|
+
"remote.session",
|
|
1403
|
+
"remoteAccess"
|
|
1404
|
+
];
|
|
1405
|
+
/** UUID v4. `crypto.randomUUID` only exists in secure contexts, so there is a fallback for plain-HTTP tailnet access. */
|
|
1406
|
+
function newRequestId() {
|
|
1407
|
+
if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
|
|
1408
|
+
const hex = [...crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16))].map((byte, index) => {
|
|
1409
|
+
if (index === 6) return byte % 16 + 64;
|
|
1410
|
+
return index === 8 ? byte % 64 + 128 : byte;
|
|
1411
|
+
}).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1412
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
1413
|
+
}
|
|
1414
|
+
function timeZone() {
|
|
1415
|
+
try {
|
|
1416
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
1417
|
+
} catch {
|
|
1418
|
+
return;
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
/**
|
|
1422
|
+
* Attach the link while read access to the automation catalog is held. This is the only
|
|
1423
|
+
* place that uses Remote. The prompt carries the browser time zone so the agent can pick
|
|
1424
|
+
* a local time such as "tomorrow morning".
|
|
1425
|
+
*/
|
|
1426
|
+
function connectSchedule(child, link) {
|
|
1427
|
+
const scoped = child;
|
|
1428
|
+
const { remote } = scoped;
|
|
1429
|
+
return scoped.remoteAccess.whenAccess("schedule/catalog", () => {
|
|
1430
|
+
let historyAvailable = false;
|
|
1431
|
+
const reader = createCatalogReader(remote.schedule, () => historyAvailable);
|
|
1432
|
+
const stopHistory = scoped.remoteAccess.whenAccess("schedule/history", () => {
|
|
1433
|
+
historyAvailable = true;
|
|
1434
|
+
reader.reset();
|
|
1435
|
+
return () => {
|
|
1436
|
+
historyAvailable = false;
|
|
1437
|
+
reader.reset();
|
|
1438
|
+
};
|
|
1439
|
+
});
|
|
1440
|
+
const detach = link.attach({
|
|
1441
|
+
list: reader.read,
|
|
1442
|
+
prompt: async (sessionId, text) => {
|
|
1443
|
+
const zone = timeZone();
|
|
1444
|
+
return await remote.session.prompt({
|
|
1445
|
+
...zone === void 0 ? {} : { clientTimeZone: zone },
|
|
1446
|
+
content: [{
|
|
1447
|
+
text,
|
|
1448
|
+
type: "text"
|
|
1449
|
+
}],
|
|
1450
|
+
mode: "queue",
|
|
1451
|
+
requestId: newRequestId(),
|
|
1452
|
+
sessionId
|
|
1453
|
+
});
|
|
1454
|
+
},
|
|
1455
|
+
subscribeChanged: (listener) => {
|
|
1456
|
+
const stops = [remote.$on("schedule/changed", listener), reader.subscribe(listener)];
|
|
1457
|
+
return () => {
|
|
1458
|
+
for (const stop of stops) stop();
|
|
1459
|
+
};
|
|
1460
|
+
},
|
|
1461
|
+
subscribeReset: (listener) => scoped.on("connection/reset", () => {
|
|
1462
|
+
reader.reset();
|
|
1463
|
+
listener();
|
|
1464
|
+
})
|
|
1465
|
+
});
|
|
1466
|
+
return () => {
|
|
1467
|
+
detach();
|
|
1468
|
+
stopHistory();
|
|
1469
|
+
reader.dispose();
|
|
1470
|
+
};
|
|
1471
|
+
});
|
|
1472
|
+
}
|
|
1473
|
+
// src/automation-visibility.ts
|
|
1474
|
+
/** Storage key of the automation targets the user kept visible: a JSON array of session ids. */
|
|
1475
|
+
const AUTOMATION_VISIBLE_KEY = "dungsil.sidebar-inbox.automation-visible.v1";
|
|
1476
|
+
/**
|
|
1477
|
+
* Tracks which automation destinations are hidden by default and which the user chose to
|
|
1478
|
+
* keep. Waking an automation target keeps it visible; snoozing it again hides it again.
|
|
1479
|
+
*/
|
|
1480
|
+
function createAutomationVisibility({ storage, snooze, automation, placement, onChange }) {
|
|
1481
|
+
const read = () => {
|
|
1482
|
+
try {
|
|
1483
|
+
const raw = storage.read();
|
|
1484
|
+
const value = raw === null ? null : JSON.parse(raw);
|
|
1485
|
+
return new Set(Array.isArray(value) ? value.filter((id) => typeof id === "string" && id !== "") : []);
|
|
1486
|
+
} catch {
|
|
1487
|
+
return /* @__PURE__ */ new Set();
|
|
1488
|
+
}
|
|
1489
|
+
};
|
|
1490
|
+
const visible = read();
|
|
1491
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1492
|
+
const save = () => {
|
|
1493
|
+
try {
|
|
1494
|
+
storage.write(JSON.stringify([...visible]));
|
|
1495
|
+
} catch {}
|
|
1496
|
+
};
|
|
1497
|
+
const notify = () => {
|
|
1498
|
+
for (const listener of listeners) listener();
|
|
1499
|
+
onChange();
|
|
1500
|
+
};
|
|
1501
|
+
const addVisible = (id) => {
|
|
1502
|
+
if (id === "" || visible.has(id)) return false;
|
|
1503
|
+
visible.add(id);
|
|
1504
|
+
save();
|
|
1505
|
+
return true;
|
|
1506
|
+
};
|
|
1507
|
+
const getAutomationIds = () => new Set([...automation.getSnapshot().sessionIds].filter((id) => !visible.has(id)));
|
|
1508
|
+
return {
|
|
1509
|
+
getAutomationIds,
|
|
1510
|
+
keepVisible: (id) => {
|
|
1511
|
+
if (addVisible(id)) notify();
|
|
1512
|
+
},
|
|
1513
|
+
menuState: {
|
|
1514
|
+
getSnapshot: () => {
|
|
1515
|
+
const entries = new Map(snooze.getSnapshot());
|
|
1516
|
+
for (const id of getAutomationIds()) if (!entries.has(id) && placement.isSnoozed(id)) entries.set(id, Number.POSITIVE_INFINITY);
|
|
1517
|
+
return entries;
|
|
1518
|
+
},
|
|
1519
|
+
snooze: (id, choice) => {
|
|
1520
|
+
const changed = visible.delete(id);
|
|
1521
|
+
if (changed) save();
|
|
1522
|
+
snooze.snooze(id, choice);
|
|
1523
|
+
if (changed) notify();
|
|
1524
|
+
},
|
|
1525
|
+
subscribe: (listener) => {
|
|
1526
|
+
listeners.add(listener);
|
|
1527
|
+
const stopSnooze = snooze.subscribe(listener);
|
|
1528
|
+
const stopAutomation = automation.subscribe(listener);
|
|
1529
|
+
const stopPlacement = placement.subscribe(listener);
|
|
1530
|
+
return () => {
|
|
1531
|
+
listeners.delete(listener);
|
|
1532
|
+
stopSnooze();
|
|
1533
|
+
stopAutomation();
|
|
1534
|
+
stopPlacement();
|
|
1535
|
+
};
|
|
1536
|
+
},
|
|
1537
|
+
wake: (id) => {
|
|
1538
|
+
const changed = automation.getSnapshot().sessionIds.has(id) && addVisible(id);
|
|
1539
|
+
snooze.wake(id);
|
|
1540
|
+
if (changed) notify();
|
|
1541
|
+
}
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
}
|
|
1545
|
+
// src/snooze-menu.ts
|
|
1546
|
+
/** Register against the native session context-menu source, not React-owned rows. */
|
|
1547
|
+
function installSnoozeMenu(options) {
|
|
1548
|
+
const { contextMenus, sessions, workspaces, state, agent, locale, isActive, isFlat, translate } = options;
|
|
1549
|
+
return contextMenus.register({
|
|
1550
|
+
id: "dungsil.sidebar-snooze",
|
|
1551
|
+
order: 400,
|
|
1552
|
+
target: "session",
|
|
1553
|
+
observe: () => [
|
|
1554
|
+
state,
|
|
1555
|
+
locale,
|
|
1556
|
+
sessions.list,
|
|
1557
|
+
workspaces.list,
|
|
1558
|
+
{
|
|
1559
|
+
getSnapshot: () => agent.available(),
|
|
1560
|
+
subscribe: (listener) => agent.subscribe(listener)
|
|
1561
|
+
}
|
|
1562
|
+
],
|
|
1563
|
+
resolve: ({ sessionId }) => {
|
|
1564
|
+
const list = sessions.list.getSnapshot();
|
|
1565
|
+
const key = list.ids.find((id) => id === sessionId);
|
|
1566
|
+
const row = key === void 0 ? void 0 : list.byId[key];
|
|
1567
|
+
const workspace = workspaces.list.getSnapshot();
|
|
1568
|
+
if (!isActive() || !isFlat() || !row || row.blank || row.origin === "subagent" || workspace.pinnedSessionIds.includes(sessionId) || workspace.archivedSessionIds.includes(sessionId)) return [];
|
|
1569
|
+
if (state.getSnapshot().has(sessionId)) return [{
|
|
1570
|
+
id: "wake",
|
|
1571
|
+
label: translate("snooze.wake"),
|
|
1572
|
+
icon: { key: "sidebar-inbox.wake" },
|
|
1573
|
+
run: () => state.wake(sessionId)
|
|
1574
|
+
}];
|
|
1575
|
+
const children = SNOOZE_CHOICES.map((choice) => ({
|
|
1576
|
+
id: choice,
|
|
1577
|
+
label: translate(`snooze.${choice}`),
|
|
1578
|
+
run: () => state.snooze(sessionId, choice)
|
|
1579
|
+
}));
|
|
1580
|
+
if (agent.available()) children.push({
|
|
1581
|
+
id: AGENT_CHOICE,
|
|
1582
|
+
label: translate("snooze.agent"),
|
|
1583
|
+
failureLabel: translate("snooze.agentFailure"),
|
|
1584
|
+
run: () => agent.choose(sessionId)
|
|
1585
|
+
});
|
|
1586
|
+
return [{
|
|
1587
|
+
id: "snooze",
|
|
1588
|
+
label: translate("snooze.action"),
|
|
1589
|
+
icon: { key: "sidebar-inbox.snooze" },
|
|
1590
|
+
children
|
|
1591
|
+
}];
|
|
1592
|
+
}
|
|
1593
|
+
});
|
|
1594
|
+
}
|
|
1595
|
+
// src/snooze-icons.ts
|
|
1596
|
+
/** Install keyed native context-menu icons for the lifetime of the menu service. */
|
|
1597
|
+
function installSnoozeIcons(slots) {
|
|
1598
|
+
slots.inject("contextMenu.icon", function* () {
|
|
1599
|
+
yield slots.register({
|
|
1600
|
+
name: "contextMenu.icon",
|
|
1601
|
+
key: "sidebar-inbox.snooze"
|
|
1602
|
+
}, _deepseek_ai_dsh_client_ui_primitives.IconClockOutlineRegular);
|
|
1603
|
+
yield slots.register({
|
|
1604
|
+
name: "contextMenu.icon",
|
|
1605
|
+
key: "sidebar-inbox.wake"
|
|
1606
|
+
}, _deepseek_ai_dsh_client_ui_primitives.IconPlayOutlineRegular);
|
|
1607
|
+
});
|
|
1608
|
+
}
|
|
578
1609
|
// src/client.ts
|
|
579
1610
|
const name = "dungsil-sidebar-inbox";
|
|
580
1611
|
const inject = [
|
|
@@ -592,8 +1623,10 @@ const FLAT_ORDER = "__flat_session_order__";
|
|
|
592
1623
|
* order is what the sidebar renders while this mode is selected.
|
|
593
1624
|
*/
|
|
594
1625
|
const AGENT_ACTIVITY = "agent-activity";
|
|
595
|
-
/**
|
|
1626
|
+
/** Native fallback used while the plugin is unavailable. */
|
|
596
1627
|
const PREVIOUS_SORT_KEY = "dungsil.sidebar-inbox.sort.v1";
|
|
1628
|
+
/** Separate from the fallback: teardown must not overwrite the user's choice. */
|
|
1629
|
+
const SELECTED_SORT_KEY = "dungsil.sidebar-inbox.selected-sort.v1";
|
|
597
1630
|
function isAgentActivity(orderBy) {
|
|
598
1631
|
return String(orderBy) === AGENT_ACTIVITY;
|
|
599
1632
|
}
|
|
@@ -612,24 +1645,86 @@ function writePreviousSort(mode) {
|
|
|
612
1645
|
}
|
|
613
1646
|
/** Keep native React rows, search, menus, selection and keyboard order intact. */
|
|
614
1647
|
function apply(ctx) {
|
|
615
|
-
ctx.effect(() => ctx.locale.register(NS,
|
|
616
|
-
|
|
617
|
-
const translate =
|
|
1648
|
+
for (const [language, dictionary] of Object.entries(dictionaries)) ctx.effect(() => ctx.locale.register(NS, language, dictionary), `sidebar-inbox: ${language} copy`);
|
|
1649
|
+
const bound = ctx.locale.bind(NS);
|
|
1650
|
+
const translate = (key) => {
|
|
1651
|
+
const base = ctx.locale.getSnapshot().active.toLowerCase().split(/[-_]/)[0];
|
|
1652
|
+
return Object.hasOwn(dictionaries, base) ? dictionaries[base][key] : bound(key);
|
|
1653
|
+
};
|
|
618
1654
|
let placements = /* @__PURE__ */ new Map();
|
|
619
1655
|
let view;
|
|
620
1656
|
let refreshHeadings = () => {};
|
|
621
1657
|
let refreshSortOption = () => {};
|
|
1658
|
+
let previousSort = "manual";
|
|
622
1659
|
const isActive = () => view !== void 0 && isAgentActivity(view.getSnapshot().orderBy);
|
|
623
1660
|
/** The agent-activity order only fits the hierarchy-free single list. */
|
|
624
1661
|
const isFlat = () => view !== void 0 && view.getSnapshot().groupBy === "flat";
|
|
1662
|
+
const pending = { reconcile: () => void 0 };
|
|
1663
|
+
const worktree = createWorktreeActivity(() => pending.reconcile());
|
|
1664
|
+
ctx.inject(WORKTREE_INJECT, (child) => worktree.attach(child));
|
|
1665
|
+
ctx.effect(() => () => worktree.dispose(), "sidebar-inbox: worktree activity");
|
|
1666
|
+
const scheduleLink = createScheduleLink();
|
|
1667
|
+
ctx.inject(SCHEDULE_INJECT, (child) => connectSchedule(child, scheduleLink));
|
|
1668
|
+
const agentWake = createAgentWake({
|
|
1669
|
+
schedule: () => scheduleLink.getSnapshot(),
|
|
1670
|
+
busy: (id) => {
|
|
1671
|
+
const list = ctx.sessions.list.getSnapshot();
|
|
1672
|
+
const key = list.ids.find((candidate) => candidate === id);
|
|
1673
|
+
return key !== void 0 && (ctx.uiSession.sessionStatus.getSnapshot().get(key)?.running ?? list.byId[key]?.running ?? false);
|
|
1674
|
+
}
|
|
1675
|
+
});
|
|
1676
|
+
const state = createSnoozeState({
|
|
1677
|
+
now: Date.now,
|
|
1678
|
+
storage: {
|
|
1679
|
+
read: () => localStorage.getItem(SNOOZE_KEY),
|
|
1680
|
+
write: (raw) => localStorage.setItem(SNOOZE_KEY, raw)
|
|
1681
|
+
},
|
|
1682
|
+
schedule: (callback, delay) => {
|
|
1683
|
+
const timer = setTimeout(callback, delay);
|
|
1684
|
+
return () => clearTimeout(timer);
|
|
1685
|
+
},
|
|
1686
|
+
onChange: () => pending.reconcile(),
|
|
1687
|
+
judgeAgent: agentWake.judge
|
|
1688
|
+
});
|
|
1689
|
+
ctx.effect(() => () => state.dispose(), "sidebar-inbox: snooze state");
|
|
1690
|
+
const placementListeners = /* @__PURE__ */ new Set();
|
|
1691
|
+
const automationVisibility = createAutomationVisibility({
|
|
1692
|
+
storage: {
|
|
1693
|
+
read: () => localStorage.getItem(AUTOMATION_VISIBLE_KEY),
|
|
1694
|
+
write: (raw) => localStorage.setItem(AUTOMATION_VISIBLE_KEY, raw)
|
|
1695
|
+
},
|
|
1696
|
+
snooze: state,
|
|
1697
|
+
automation: scheduleLink,
|
|
1698
|
+
placement: {
|
|
1699
|
+
isSnoozed: (id) => placements.get(id)?.section === "Snoozed",
|
|
1700
|
+
subscribe: (listener) => {
|
|
1701
|
+
placementListeners.add(listener);
|
|
1702
|
+
return () => {
|
|
1703
|
+
placementListeners.delete(listener);
|
|
1704
|
+
};
|
|
1705
|
+
}
|
|
1706
|
+
},
|
|
1707
|
+
onChange: () => pending.reconcile()
|
|
1708
|
+
});
|
|
1709
|
+
const chooseAgent = createAgentChoice({
|
|
1710
|
+
state,
|
|
1711
|
+
hasPlan: agentWake.hasPlan,
|
|
1712
|
+
request: scheduleLink.request
|
|
1713
|
+
});
|
|
625
1714
|
const reconcile = () => {
|
|
1715
|
+
state.prune();
|
|
626
1716
|
const list = ctx.sessions.list.getSnapshot();
|
|
627
1717
|
const workspace = ctx.workspaces.list.getSnapshot();
|
|
628
|
-
const
|
|
1718
|
+
const statuses = ctx.uiSession.sessionStatus.getSnapshot();
|
|
1719
|
+
worktree.reconcile(list, statuses);
|
|
1720
|
+
const result = placeSessions(list, statuses, workspace.pinnedSessionIds, workspace.archivedSessionIds, worktree.active, new Set(state.getSnapshot().keys()), automationVisibility.getAutomationIds());
|
|
629
1721
|
if (placements.size !== result.placements.size || [...result.placements].some(([id, value]) => {
|
|
630
1722
|
const previous = placements.get(id);
|
|
631
1723
|
return previous?.section !== value.section || previous.blank !== value.blank;
|
|
632
|
-
}))
|
|
1724
|
+
})) {
|
|
1725
|
+
placements = result.placements;
|
|
1726
|
+
for (const listener of placementListeners) listener();
|
|
1727
|
+
}
|
|
633
1728
|
if (view !== void 0 && list.phase === "ready" && workspace.phase === "ready" && isActive() && isFlat()) {
|
|
634
1729
|
const current = view.getSnapshot();
|
|
635
1730
|
const previous = current.sessionOrderByAccount[FLAT_ORDER] ?? [];
|
|
@@ -644,17 +1739,40 @@ function apply(ctx) {
|
|
|
644
1739
|
refreshHeadings();
|
|
645
1740
|
refreshSortOption();
|
|
646
1741
|
};
|
|
1742
|
+
pending.reconcile = reconcile;
|
|
1743
|
+
ctx.effect(() => scheduleLink.subscribe(reconcile), "sidebar-inbox: schedule updates");
|
|
1744
|
+
ctx.inject(["contextMenus"], (child) => {
|
|
1745
|
+
installSnoozeIcons(child.slots);
|
|
1746
|
+
const contextMenus = child.contextMenus;
|
|
1747
|
+
return installSnoozeMenu({
|
|
1748
|
+
contextMenus,
|
|
1749
|
+
sessions: ctx.sessions,
|
|
1750
|
+
workspaces: ctx.workspaces,
|
|
1751
|
+
state: automationVisibility.menuState,
|
|
1752
|
+
locale: ctx.locale,
|
|
1753
|
+
agent: {
|
|
1754
|
+
available: () => {
|
|
1755
|
+
const snapshot = scheduleLink.getSnapshot();
|
|
1756
|
+
return snapshot.available && snapshot.settled;
|
|
1757
|
+
},
|
|
1758
|
+
subscribe: scheduleLink.subscribe,
|
|
1759
|
+
choose: (id) => {
|
|
1760
|
+
automationVisibility.keepVisible(id);
|
|
1761
|
+
return chooseAgent(id);
|
|
1762
|
+
}
|
|
1763
|
+
},
|
|
1764
|
+
isActive,
|
|
1765
|
+
isFlat,
|
|
1766
|
+
translate
|
|
1767
|
+
});
|
|
1768
|
+
});
|
|
647
1769
|
const toggleSort = () => {
|
|
648
|
-
if (view === void 0 || !isFlat()) return;
|
|
1770
|
+
if (view === void 0 || !isFlat() || isActive()) return;
|
|
649
1771
|
const current = view.getSnapshot();
|
|
650
|
-
if (
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
orderBy: readPreviousSort()
|
|
654
|
-
});
|
|
655
|
-
return;
|
|
1772
|
+
if (current.orderBy === "manual" || current.orderBy === "updated") {
|
|
1773
|
+
previousSort = current.orderBy;
|
|
1774
|
+
writePreviousSort(previousSort);
|
|
656
1775
|
}
|
|
657
|
-
if (current.orderBy === "manual" || current.orderBy === "updated") writePreviousSort(current.orderBy);
|
|
658
1776
|
view.store.set({
|
|
659
1777
|
...current,
|
|
660
1778
|
orderBy: AGENT_ACTIVITY
|
|
@@ -664,22 +1782,42 @@ function apply(ctx) {
|
|
|
664
1782
|
const entry = ctx.slots.entries("sidebar.workspaces").find((candidate) => candidate.registrant === "@deepseek-ai/dsh-client-ui-workspace") ?? ctx.slots.entries("sidebar.workspaces").find((candidate) => (candidate.options.priority ?? 0) === 0);
|
|
665
1783
|
if (!entry?.store || typeof entry.store === "function") throw new Error("Sidebar Inbox requires the DSH 0.2.1 workspace view store");
|
|
666
1784
|
view = entry.store.create();
|
|
1785
|
+
const current = view.getSnapshot();
|
|
1786
|
+
previousSort = current.orderBy === "manual" || current.orderBy === "updated" ? current.orderBy : readPreviousSort();
|
|
1787
|
+
const initialGroupBy = current.groupBy;
|
|
1788
|
+
let pluginGrouped = false;
|
|
1789
|
+
let seenGroupBy;
|
|
1790
|
+
let selectedSort = null;
|
|
1791
|
+
let hasPreviousSort = false;
|
|
667
1792
|
try {
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
if (current.orderBy === "manual" || current.orderBy === "updated") {
|
|
671
|
-
localStorage.setItem(PREVIOUS_SORT_KEY, current.orderBy);
|
|
672
|
-
view.store.set({
|
|
673
|
-
...current,
|
|
674
|
-
groupBy: "flat",
|
|
675
|
-
orderBy: AGENT_ACTIVITY
|
|
676
|
-
});
|
|
677
|
-
}
|
|
678
|
-
}
|
|
1793
|
+
selectedSort = localStorage.getItem(SELECTED_SORT_KEY);
|
|
1794
|
+
hasPreviousSort = localStorage.getItem(PREVIOUS_SORT_KEY) !== null;
|
|
679
1795
|
} catch {}
|
|
1796
|
+
const initialSort = selectedSort === AGENT_ACTIVITY || selectedSort === "manual" || selectedSort === "updated" ? selectedSort : isAgentActivity(current.orderBy) || !hasPreviousSort ? AGENT_ACTIVITY : current.orderBy;
|
|
1797
|
+
if (initialSort === AGENT_ACTIVITY && !isAgentActivity(current.orderBy)) {
|
|
1798
|
+
if (current.orderBy === "manual" || current.orderBy === "updated") writePreviousSort(current.orderBy);
|
|
1799
|
+
}
|
|
1800
|
+
const rememberSelection = () => {
|
|
1801
|
+
const mode = String(view.getSnapshot().orderBy);
|
|
1802
|
+
if (mode === selectedSort) return;
|
|
1803
|
+
try {
|
|
1804
|
+
localStorage.setItem(SELECTED_SORT_KEY, mode);
|
|
1805
|
+
selectedSort = mode;
|
|
1806
|
+
} catch {}
|
|
1807
|
+
};
|
|
1808
|
+
view.store.set({
|
|
1809
|
+
...current,
|
|
1810
|
+
...initialSort === AGENT_ACTIVITY ? { groupBy: "flat" } : {},
|
|
1811
|
+
orderBy: initialSort
|
|
1812
|
+
});
|
|
1813
|
+
pluginGrouped = view.getSnapshot().groupBy === "flat" && initialGroupBy !== "flat";
|
|
1814
|
+
seenGroupBy = view.getSnapshot().groupBy;
|
|
1815
|
+
rememberSelection();
|
|
680
1816
|
const headings = installHeadings(() => placements, () => ({
|
|
681
1817
|
working: translate("heading.working"),
|
|
682
|
-
archived: translate("heading.archived")
|
|
1818
|
+
archived: translate("heading.archived"),
|
|
1819
|
+
snoozed: translate("heading.snoozed"),
|
|
1820
|
+
language: ctx.locale.getSnapshot().active
|
|
683
1821
|
}), () => (view?.getSnapshot().archivedFilter ?? "default") === "show", isActive);
|
|
684
1822
|
refreshHeadings = () => headings.refresh();
|
|
685
1823
|
const sortOption = installSortOption({
|
|
@@ -692,8 +1830,14 @@ function apply(ctx) {
|
|
|
692
1830
|
const sync = () => {
|
|
693
1831
|
if (view !== void 0 && isActive() && !isFlat()) view.store.set({
|
|
694
1832
|
...view.getSnapshot(),
|
|
695
|
-
orderBy:
|
|
1833
|
+
orderBy: previousSort
|
|
696
1834
|
});
|
|
1835
|
+
if (view !== void 0) {
|
|
1836
|
+
const groupBy = view.getSnapshot().groupBy;
|
|
1837
|
+
if (seenGroupBy !== void 0 && groupBy !== seenGroupBy) pluginGrouped = false;
|
|
1838
|
+
seenGroupBy = groupBy;
|
|
1839
|
+
}
|
|
1840
|
+
rememberSelection();
|
|
697
1841
|
reconcile();
|
|
698
1842
|
};
|
|
699
1843
|
const disposers = [
|
|
@@ -717,9 +1861,13 @@ function apply(ctx) {
|
|
|
717
1861
|
const current = view.getSnapshot();
|
|
718
1862
|
view.store.set({
|
|
719
1863
|
...current,
|
|
720
|
-
orderBy:
|
|
1864
|
+
orderBy: previousSort
|
|
721
1865
|
});
|
|
722
1866
|
}
|
|
1867
|
+
if (view !== void 0 && pluginGrouped && view.getSnapshot().groupBy !== initialGroupBy) view.store.set({
|
|
1868
|
+
...view.getSnapshot(),
|
|
1869
|
+
groupBy: initialGroupBy
|
|
1870
|
+
});
|
|
723
1871
|
view = void 0;
|
|
724
1872
|
};
|
|
725
1873
|
});
|