@prettier-ai/dsh-client-ui-workspace 0.1.2-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js ADDED
@@ -0,0 +1,2710 @@
1
+ window.__ModuleLoader__.load({
2
+ id: "@prettier-ai/dsh-client-ui-workspace",
3
+ factory: (require) => {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
+ let _prettier_ai_cordis = require("@prettier-ai/cordis");
8
+ let _prettier_ai_dsh_client_store = require("@prettier-ai/dsh-client-store");
9
+ let react_jsx_runtime = require("react/jsx-runtime");
10
+ let react = require("react");
11
+ let _prettier_ai_dsh_client_ui_primitives = require("@prettier-ai/dsh-client-ui-primitives");
12
+ //#region lib/types/client/navigation.js
13
+ /** Workspace archive and directory UI capability. */
14
+ /** Structured directory failure exposed to directory UI consumers. */
15
+ var DirectoryBrowseError = class extends Error {
16
+ rpcError;
17
+ name = "DirectoryBrowseError";
18
+ /** @param rpcError - Host directory business failure. */
19
+ constructor(rpcError) {
20
+ super(`directory browse failed: ${rpcError.code}: ${rpcError.message}`);
21
+ this.rpcError = rpcError;
22
+ }
23
+ };
24
+ /** Implements Workspace archive and directory UI operations. */
25
+ var UiWorkspaceService = class extends _prettier_ai_cordis.Service {
26
+ directoryPicker;
27
+ workspaces;
28
+ sessions;
29
+ connecting = /* @__PURE__ */ new Map();
30
+ /**
31
+ * @param ctx - Client root Context.
32
+ * @param directoryPicker - the directory-picking Remote namespace.
33
+ * @param workspaces - pure Workspace Controller.
34
+ * @param sessions - pure Session Controller.
35
+ */
36
+ constructor(ctx, directoryPicker, workspaces, sessions) {
37
+ super(ctx, "uiWorkspace");
38
+ this.directoryPicker = directoryPicker;
39
+ this.workspaces = workspaces;
40
+ this.sessions = sessions;
41
+ ctx.effect(() => this.watchNavigation(), "ui-workspace: Workspace navigation policy");
42
+ }
43
+ async connectWorkspace(workspaceId) {
44
+ const workspace = this.workspaces.list.getSnapshot().items.find((item) => item.workspaceId === workspaceId);
45
+ if (workspace === void 0) throw new Error(`uiWorkspace.connectWorkspace: unknown workspace ${workspaceId}`);
46
+ const inflight = this.connecting.get(workspaceId);
47
+ if (inflight !== void 0) return inflight;
48
+ const archived = this.workspaces.list.getSnapshot().archivedSessionIds;
49
+ const sessions = this.sessions.list.getSnapshot();
50
+ for (const id of sessions.ids) {
51
+ const summary = sessions.byId[id];
52
+ if (summary !== void 0 && summary.blank && summary.cwd === workspace.path && workspace.sessionIds.includes(summary.id) && !archived.includes(summary.id)) return summary.id;
53
+ }
54
+ const attempt = this.sessions.create({ workspaceId }).finally(() => {
55
+ this.connecting.delete(workspaceId);
56
+ });
57
+ this.connecting.set(workspaceId, attempt);
58
+ return attempt;
59
+ }
60
+ startSession(workspaceId) {
61
+ const workspace = this.workspaces.list.getSnapshot();
62
+ const sessions = this.sessions.list.getSnapshot();
63
+ const current = sessions.current;
64
+ const currentWorkspaceId = current === void 0 ? void 0 : workspace.items.find((item) => item.sessionIds.includes(current))?.workspaceId;
65
+ const recent = workspace.phase === "ready" && sessions.phase === "ready" ? recentWorkspace(workspace.items, sessions.byId) : void 0;
66
+ const target = workspaceId ?? currentWorkspaceId ?? recent;
67
+ if (target === void 0) {
68
+ this.sessions.clear();
69
+ return;
70
+ }
71
+ this.connectWorkspace(target).then((sessionId) => {
72
+ this.sessions.open(sessionId);
73
+ }, (reason) => {
74
+ console.warn("new session failed:", reason);
75
+ });
76
+ }
77
+ async archiveSession(sessionId) {
78
+ await this.workspaces.archiveSession(sessionId);
79
+ }
80
+ async pickDirectory() {
81
+ const result = await this.directoryPicker.pick();
82
+ if (!result.ok) throw new Error(`directory picker failed: ${result.error.message}`);
83
+ return result.value;
84
+ }
85
+ async listDirectory(path, signal) {
86
+ const result = await this.directoryPicker.list(path, signal);
87
+ if (!result.ok) throw new DirectoryBrowseError(result.error);
88
+ return result.value;
89
+ }
90
+ async createDirectory(path, name) {
91
+ const result = await this.directoryPicker.createDirectory(path, name);
92
+ if (!result.ok) throw new DirectoryBrowseError(result.error);
93
+ return result.value;
94
+ }
95
+ watchNavigation() {
96
+ let initial = "waiting";
97
+ let disposed = false;
98
+ const reconcile = () => {
99
+ if (disposed) return;
100
+ if (this.clearArchivedCurrent()) return;
101
+ if (initial !== "waiting") return;
102
+ const workspace = this.workspaces.list.getSnapshot();
103
+ const sessions = this.sessions.list.getSnapshot();
104
+ if (workspace.phase !== "ready" || sessions.phase !== "ready") return;
105
+ if (sessions.current !== void 0) {
106
+ initial = "done";
107
+ return;
108
+ }
109
+ const target = recentWorkspace(workspace.items, sessions.byId);
110
+ if (target === void 0) {
111
+ initial = "done";
112
+ return;
113
+ }
114
+ initial = "connecting";
115
+ this.connectWorkspace(target).then((sessionId) => {
116
+ if (disposed) return;
117
+ if (this.sessions.list.getSnapshot().current === void 0) this.sessions.open(sessionId);
118
+ initial = "done";
119
+ }, (reason) => {
120
+ if (disposed) return;
121
+ initial = "waiting";
122
+ console.warn("initial workspace selection failed:", reason);
123
+ });
124
+ };
125
+ const disposeWorkspaces = this.workspaces.list.subscribe(reconcile);
126
+ const disposeSessions = this.sessions.list.subscribe(reconcile);
127
+ reconcile();
128
+ return () => {
129
+ disposed = true;
130
+ disposeSessions();
131
+ disposeWorkspaces();
132
+ };
133
+ }
134
+ /** @returns true when an archived current selection was cleared. */
135
+ clearArchivedCurrent() {
136
+ const current = this.sessions.list.getSnapshot().current;
137
+ if (current === void 0 || !this.workspaces.list.getSnapshot().archivedSessionIds.includes(current)) return false;
138
+ this.sessions.clear();
139
+ return true;
140
+ }
141
+ };
142
+ /** Stable tie-breaking follows Host Workspace order. */
143
+ function recentWorkspace(workspaces, sessions) {
144
+ let selected;
145
+ let selectedTime = Number.NEGATIVE_INFINITY;
146
+ for (const workspace of workspaces) {
147
+ let latest = Number.NEGATIVE_INFINITY;
148
+ for (const sessionId of workspace.sessionIds) {
149
+ const session = sessions[sessionId];
150
+ if (session !== void 0) latest = Math.max(latest, session.updatedAt);
151
+ }
152
+ if (latest === Number.NEGATIVE_INFINITY) latest = Date.parse(workspace.createdAt);
153
+ if (selected === void 0 || latest > selectedTime) {
154
+ selected = workspace.workspaceId;
155
+ selectedTime = latest;
156
+ }
157
+ }
158
+ return selected;
159
+ }
160
+ //#endregion
161
+ //#region lib/types/client/stores.js
162
+ /**
163
+ * The workspace browser's viewing store: the session-list grouping mode,
164
+ * persisted across reloads. Module level exports the factory only (a
165
+ * module-level handle would pin the store identity across plugin reloads);
166
+ * register() receives the factory and the browser derives its PropsStore
167
+ * share from the return type.
168
+ */
169
+ /** Browser-local order account for the hierarchy-free flat Session list. */
170
+ const FLAT_SESSION_ORDER_KEY = "__flat_session_order__";
171
+ /**
172
+ * Create the workspace browser viewing store handle.
173
+ * @returns the store handle (spec + type + identity + factory in one).
174
+ */
175
+ function createWorkspaceViewStore() {
176
+ return (0, _prettier_ai_dsh_client_store.defineStore)({
177
+ init: () => ({
178
+ groupBy: "workspace",
179
+ orderBy: "updated",
180
+ groupExpansion: {},
181
+ sessionOrderByAccount: {},
182
+ sessionUpdatedAtByAccount: {}
183
+ }),
184
+ persist: "dsh.workspace.view.v5",
185
+ actions: {
186
+ setGroupBy: (d, mode) => {
187
+ d.groupBy = mode;
188
+ },
189
+ setOrderBy: (d, mode) => {
190
+ d.orderBy = mode;
191
+ },
192
+ setGroupExpanded: (d, key, expanded) => {
193
+ d.groupExpansion[key] = expanded;
194
+ },
195
+ retainAccountKeys: (d, workspaceKeys) => {
196
+ const retained = new Set(workspaceKeys);
197
+ d.groupExpansion = Object.fromEntries(Object.entries(d.groupExpansion).filter(([key]) => retained.has(key)));
198
+ d.sessionOrderByAccount = Object.fromEntries(Object.entries(d.sessionOrderByAccount).filter(([key]) => retained.has(key)));
199
+ d.sessionUpdatedAtByAccount = Object.fromEntries(Object.entries(d.sessionUpdatedAtByAccount).filter(([key]) => retained.has(key)));
200
+ },
201
+ syncSessionOrderAccount: (d, accountKey, order, updatedAt) => {
202
+ d.sessionOrderByAccount[accountKey] = order;
203
+ d.sessionUpdatedAtByAccount[accountKey] = updatedAt;
204
+ },
205
+ setSessionOrder: (d, accountKey, order) => {
206
+ d.sessionOrderByAccount[accountKey] = order;
207
+ }
208
+ }
209
+ });
210
+ }
211
+ //#endregion
212
+ //#region ../../../node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs
213
+ function r(e) {
214
+ var t, f, n = "";
215
+ if ("string" == typeof e || "number" == typeof e) n += e;
216
+ else if ("object" == typeof e) if (Array.isArray(e)) {
217
+ var o = e.length;
218
+ for (t = 0; t < o; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
219
+ } else for (f in e) e[f] && (n && (n += " "), n += f);
220
+ return n;
221
+ }
222
+ function clsx() {
223
+ for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++) (e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
224
+ return n;
225
+ }
226
+ //#endregion
227
+ //#region ../../util/workspace-path/src/index.ts
228
+ /**
229
+ * Browser-safe Workspace path and display helpers.
230
+ * @module @prettier-ai/dsh-util-workspace-path
231
+ */
232
+ /** Whether a path uses a Windows drive or UNC prefix. */
233
+ function isWindowsStylePath(value) {
234
+ return /^[A-Za-z]:[/\\]/.test(value) || value.startsWith("\\\\");
235
+ }
236
+ /**
237
+ * Abbreviate a POSIX home directory for display.
238
+ * @param path - Absolute or already-short display path.
239
+ * @param home - Host account home; absent skips abbreviation.
240
+ * @returns `~` or `~/…` for the POSIX home and its descendants, otherwise `path`.
241
+ */
242
+ function abbreviateHomePath(path, home) {
243
+ if (home === void 0 || home === "") return path;
244
+ if (isWindowsStylePath(path) || isWindowsStylePath(home)) return path;
245
+ const root = home.replace(/\/+$/, "");
246
+ if (root === "" || root === "/") return path;
247
+ if (path.replace(/\/+$/, "") === root) return "~";
248
+ if (path.startsWith(`${root}/`)) return `~${path.slice(root.length)}`;
249
+ return path;
250
+ }
251
+ /**
252
+ * Read the final non-empty segment of a Workspace path for display.
253
+ * Workspace-label surfaces use this helper instead of deriving another basename.
254
+ * @param path - Workspace directory path using POSIX or Windows separators.
255
+ * @returns the final segment, or an empty string for a separator-only path.
256
+ */
257
+ function workspaceTitleOf(path) {
258
+ const trimmed = path.replace(/[/\\]+$/, "");
259
+ const separator = Math.max(trimmed.lastIndexOf("/"), trimmed.lastIndexOf("\\"));
260
+ return trimmed.slice(separator + 1);
261
+ }
262
+ //#endregion
263
+ //#region lib/types/client/subagent-lineage.js
264
+ /** UI Workspace-owned projection of descendant counts from Session summaries. */
265
+ /**
266
+ * Index uninterrupted subagent descendants under each ancestor.
267
+ * @param summaries - Session summaries keyed by id.
268
+ * @returns descendant totals keyed by possible parent id.
269
+ */
270
+ function indexSubagentDescendants(summaries) {
271
+ const indexed = /* @__PURE__ */ new Map();
272
+ for (const descendant of Object.values(summaries)) {
273
+ if (descendant.origin !== "subagent") continue;
274
+ const seen = /* @__PURE__ */ new Set();
275
+ let current = descendant;
276
+ while (current?.origin === "subagent" && current.parentId !== void 0 && !seen.has(current.id)) {
277
+ seen.add(current.id);
278
+ const aggregate = indexed.get(current.parentId);
279
+ if (aggregate === void 0) indexed.set(current.parentId, {
280
+ count: 1,
281
+ runningCount: descendant.running ? 1 : 0
282
+ });
283
+ else {
284
+ aggregate.count += 1;
285
+ if (descendant.running) aggregate.runningCount += 1;
286
+ }
287
+ current = summaries[current.parentId];
288
+ }
289
+ }
290
+ return indexed;
291
+ }
292
+ /**
293
+ * Directory display label: basename of the path (both separators accepted).
294
+ * Ungrouped-bucket fallback for surfaces without a workspace title.
295
+ * @param cwd - directory path, or undefined for the ungrouped bucket.
296
+ * @returns basename, the raw cwd when it has no basename, or an empty ungrouped marker.
297
+ */
298
+ function workspaceLabel(cwd) {
299
+ if (cwd === void 0 || cwd === "") return "";
300
+ const base = workspaceTitleOf(cwd);
301
+ return base !== "" ? base : cwd;
302
+ }
303
+ /** Recency comparator: newest first, id as the deterministic tiebreak (ids are unique per group). */
304
+ function byRecency(a, b) {
305
+ if (b.updatedAt !== a.updatedAt) return b.updatedAt - a.updatedAt;
306
+ return a.id < b.id ? -1 : 1;
307
+ }
308
+ /**
309
+ * Ordinary sessions are visible; among blank sessions, only the current one
310
+ * is visible. Subagent children use their parent header catalog; archived
311
+ * sessions are visible nowhere, while their accounting slots remain so
312
+ * unarchiving restores position.
313
+ */
314
+ function sessionVisible(session, current, archived) {
315
+ return session.origin !== "subagent" && !archived.has(session.id) && (!session.blank || session.id === current);
316
+ }
317
+ /**
318
+ * A blank session is the selected Workspace's provisional New Session row;
319
+ * its canonical title never enters search (blank rows are query-excluded)
320
+ * and the renderer localizes its display label.
321
+ */
322
+ function sessionTitle(session) {
323
+ return session.blank ? "" : session.displayTitle;
324
+ }
325
+ /** Build one group without projecting session lineage into presentation. */
326
+ function buildGroup(key, workspaceId, cwd, createdAt, label, members, order) {
327
+ const sessions = [...members];
328
+ if (order === "recency") sessions.sort(byRecency);
329
+ return {
330
+ key,
331
+ workspaceId,
332
+ cwd,
333
+ createdAt,
334
+ label,
335
+ sessions
336
+ };
337
+ }
338
+ /** Apply a stored Ungrouped order and append newly loose Sessions by recency. */
339
+ function orderedUngrouped(members, stored) {
340
+ const byId = new Map(members.map((session) => [session.id, session]));
341
+ const included = /* @__PURE__ */ new Set();
342
+ const ordered = [];
343
+ for (const key of stored) {
344
+ const session = byId.get(key);
345
+ if (session === void 0 || included.has(key)) continue;
346
+ ordered.push(session);
347
+ included.add(key);
348
+ }
349
+ for (const session of [...members].sort(byRecency)) {
350
+ if (included.has(session.id)) continue;
351
+ ordered.push(session);
352
+ }
353
+ return ordered;
354
+ }
355
+ /**
356
+ * Group Sessions by Host Workspace: one group per entity in stable Host
357
+ * order, with members resolved from sessionIds in their stored order. Sessions
358
+ * outside every Workspace trail in the browser-local Ungrouped order, which
359
+ * falls back to recency before that order is initialized.
360
+ */
361
+ function groupByWorkspace(list, workspaces, archived, ungroupedOrder) {
362
+ const groups = [];
363
+ const accounted = /* @__PURE__ */ new Set();
364
+ for (const workspace of workspaces) {
365
+ const members = [];
366
+ for (const id of workspace.sessionIds) {
367
+ const summary = list.byId[id];
368
+ if (summary === void 0) continue;
369
+ accounted.add(id);
370
+ if (!sessionVisible(summary, list.current, archived)) continue;
371
+ members.push(summary);
372
+ }
373
+ groups.push(buildGroup(workspace.workspaceId, workspace.workspaceId, workspace.path, Date.parse(workspace.createdAt), workspace.title, members, "account"));
374
+ }
375
+ const stray = list.ids.map((id) => list.byId[id]).filter((s) => s !== void 0 && !accounted.has(s.id) && sessionVisible(s, list.current, archived));
376
+ if (stray.length > 0) groups.push(buildGroup("", void 0, void 0, void 0, "", ungroupedOrder === void 0 ? stray : orderedUngrouped(stray, ungroupedOrder), ungroupedOrder === void 0 ? "recency" : "account"));
377
+ return groups;
378
+ }
379
+ /** Keep navigation presentation independent from domain-owned interaction objects. */
380
+ function visiblePendingKind(kind) {
381
+ switch (kind) {
382
+ case "approval":
383
+ case "plan-review":
384
+ case "question": return kind;
385
+ default: return;
386
+ }
387
+ }
388
+ function sessionNode(s, descendants, pendingInteractions) {
389
+ const pendingInteraction = visiblePendingKind(pendingInteractions.get(s.id)?.kind);
390
+ return {
391
+ id: s.id,
392
+ title: sessionTitle(s),
393
+ blank: s.blank,
394
+ running: s.running,
395
+ runningSubagentCount: descendants.get(s.id)?.runningCount ?? 0,
396
+ completed: s.completed === true,
397
+ updatedAt: s.updatedAt,
398
+ ...pendingInteraction === void 0 ? {} : { pendingInteraction }
399
+ };
400
+ }
401
+ /**
402
+ * Derive the workspace browser groups with every session as a top-level row.
403
+ *
404
+ * Every group shows; sessions populate under expanded groups in the selected
405
+ * local order. Blank sessions are excluded except for the selected
406
+ * provisional New Session row; archived sessions are excluded everywhere.
407
+ * Content search lives outside this derivation
408
+ * (see {@link deriveSearchResults}).
409
+ * @param list - sessions list snapshot (`current` feeds containsCurrent).
410
+ * @param workspaces - real workspaces in stable Host order.
411
+ * @param archivedSessionIds - registry-global archive set.
412
+ * @param pendingInteractions - pending UI interactions by Session.
413
+ * @param view - local expansion arrays.
414
+ * @returns group sections in render order.
415
+ */
416
+ function deriveGroups(list, workspaces, archivedSessionIds, pendingInteractions, view) {
417
+ const archived = new Set(archivedSessionIds);
418
+ const expandedGroups = new Set(view.expandedGroups);
419
+ const descendants = indexSubagentDescendants(list.byId);
420
+ const currentGroup = list.current === void 0 ? void 0 : workspaces.find((w) => w.sessionIds.includes(list.current))?.workspaceId ?? "";
421
+ const groups = [];
422
+ for (const g of groupByWorkspace(list, workspaces, archived, view.ungroupedOrder)) {
423
+ const expanded = expandedGroups.has(g.key);
424
+ groups.push({
425
+ key: g.key,
426
+ workspaceId: g.workspaceId,
427
+ cwd: g.cwd,
428
+ createdAt: g.createdAt,
429
+ label: g.label,
430
+ sessionCount: g.sessions.length,
431
+ expanded,
432
+ containsCurrent: g.key === currentGroup,
433
+ sessions: expanded ? g.sessions.map((session) => sessionNode(session, descendants, pendingInteractions)) : []
434
+ });
435
+ }
436
+ return groups;
437
+ }
438
+ /**
439
+ * Derive the flat session list ("In one list" mode): every session — fork
440
+ * children included — as a top-level row, strictly newest-first. No grouping,
441
+ * no parent/child adjacency. Content search lives outside this derivation
442
+ * (see {@link deriveSearchResults}).
443
+ * @param list - sessions list snapshot.
444
+ * @param archivedSessionIds - registry-global archive set.
445
+ * @param pendingInteractions - pending UI interactions by Session.
446
+ * @returns flat rows in render order.
447
+ */
448
+ function deriveFlat(list, archivedSessionIds, pendingInteractions) {
449
+ const archived = new Set(archivedSessionIds);
450
+ const descendants = indexSubagentDescendants(list.byId);
451
+ const rows = [];
452
+ for (const id of list.ids) {
453
+ const s = list.byId[id];
454
+ if (s === void 0 || !sessionVisible(s, list.current, archived)) continue;
455
+ rows.push(s);
456
+ }
457
+ rows.sort(byRecency);
458
+ return rows.map((session) => sessionNode(session, descendants, pendingInteractions));
459
+ }
460
+ /**
461
+ * Merge immediate title/Workspace substring matches with ranked Host content
462
+ * matches. Local rows lead newest-first, content-only rows retain backend
463
+ * order, and duplicate sessions receive the backend snippet in place.
464
+ * @param list - session metadata authority.
465
+ * @param workspaces - Workspace membership and display labels.
466
+ * @param query - caller text; surrounding whitespace is ignored.
467
+ * @param archivedSessionIds - registry-global archive set (members never match).
468
+ * @param pendingInteractions - pending UI interactions by Session.
469
+ * @param content - ranked Host content-search page.
470
+ * @param limit - protocol-owned maximum merged row count.
471
+ * @returns bounded deduplicated flat rows and a refine-query hint bit.
472
+ */
473
+ function deriveSearchResults(list, workspaces, query, archivedSessionIds, pendingInteractions, content, limit) {
474
+ const q = query.trim().toLowerCase();
475
+ if (q === "") return {
476
+ items: [],
477
+ hasMore: false
478
+ };
479
+ const archived = new Set(archivedSessionIds);
480
+ const descendants = indexSubagentDescendants(list.byId);
481
+ const workspaceBySession = /* @__PURE__ */ new Map();
482
+ for (const workspace of workspaces) for (const sessionId of workspace.sessionIds) if (!workspaceBySession.has(sessionId)) workspaceBySession.set(sessionId, workspace.title);
483
+ const labelOf = (summary) => workspaceBySession.get(summary.id) ?? workspaceLabel(summary.cwd);
484
+ const contentBySession = /* @__PURE__ */ new Map();
485
+ for (const item of content.items) if (!contentBySession.has(item.sessionId)) contentBySession.set(item.sessionId, item);
486
+ const local = [];
487
+ for (const id of list.ids) {
488
+ const summary = list.byId[id];
489
+ if (summary === void 0 || summary.blank || !sessionVisible(summary, list.current, archived)) continue;
490
+ if (sessionTitle(summary).toLowerCase().includes(q) || labelOf(summary).toLowerCase().includes(q)) local.push(summary);
491
+ }
492
+ local.sort(byRecency);
493
+ const ordered = [];
494
+ const included = /* @__PURE__ */ new Set();
495
+ const include = (summary) => {
496
+ if (included.has(summary.id)) return;
497
+ included.add(summary.id);
498
+ ordered.push(summary);
499
+ };
500
+ for (const summary of local) include(summary);
501
+ for (const item of content.items) {
502
+ const summary = list.byId[item.sessionId];
503
+ if (summary !== void 0 && !summary.blank && sessionVisible(summary, list.current, archived)) include(summary);
504
+ }
505
+ return {
506
+ items: ordered.slice(0, limit).map((summary) => {
507
+ const match = contentBySession.get(summary.id);
508
+ const pendingInteraction = visiblePendingKind(pendingInteractions.get(summary.id)?.kind);
509
+ return {
510
+ id: summary.id,
511
+ title: sessionTitle(summary),
512
+ workspace: labelOf(summary),
513
+ running: summary.running,
514
+ runningSubagentCount: descendants.get(summary.id)?.runningCount ?? 0,
515
+ ...pendingInteraction === void 0 ? {} : { pendingInteraction },
516
+ completed: summary.completed === true,
517
+ ...match === void 0 ? {} : { snippet: match.snippet }
518
+ };
519
+ }),
520
+ hasMore: content.hasMore || ordered.length > limit
521
+ };
522
+ }
523
+ //#endregion
524
+ //#region \0dsh-css:/home/runner/work/dsh-publisher/dsh-publisher/upstream/packages/client/ui-workspace/src/client/rows/Rows.module.css.mjs
525
+ const css$2 = ".CQRkna_projectRow,.CQRkna_sessionRow{cursor:pointer;user-select:none;color:var(--dsw-alias-label-primary);border-radius:8px;align-items:center;gap:6px;padding:0 8px;display:flex}.CQRkna_projectRow:hover,.CQRkna_sessionRow:hover,.CQRkna_sessionRow.CQRkna_selected{background:var(--dsw-alias-interactive-bg-hover)}.CQRkna_searchResultRow{box-sizing:border-box;cursor:pointer;text-align:left;width:100%;min-height:48px;color:var(--dsw-alias-label-primary);background:0 0;border:none;border-radius:8px;flex-direction:column;align-items:stretch;padding:4px 8px;display:flex}.CQRkna_searchResultRow:hover,.CQRkna_searchResultRow.CQRkna_selected{background:var(--dsw-alias-interactive-bg-hover)}.CQRkna_searchResultHeading{align-items:center;min-width:0;display:flex}.CQRkna_searchResultTitle{text-overflow:ellipsis;white-space:nowrap;min-width:0;margin-left:4px;font-size:14px;line-height:20px;overflow:hidden}.CQRkna_searchResultMeta{align-items:center;gap:6px;min-width:0;margin-left:20px;display:flex}.CQRkna_searchResultWorkspace,.CQRkna_searchResultSnippet{text-overflow:ellipsis;white-space:nowrap;font-size:12px;line-height:17px;overflow:hidden}.CQRkna_searchResultWorkspace{max-width:40%;color:var(--dsw-alias-label-tertiary);flex:none}.CQRkna_searchResultSnippet{min-width:0;color:var(--dsw-alias-label-secondary);flex:1}.CQRkna_projectRow{box-sizing:border-box;align-items:center;height:34px}.CQRkna_projectRow .CQRkna_rowActions{height:20px}.CQRkna_sessionRow{height:32px;animation:CQRkna_row-in .15s var(--ds-ease-in-out);gap:0}.CQRkna_sessionRow .CQRkna_title{margin:0 6px 0 4px}.CQRkna_flatSessionRowWithoutStatus .CQRkna_title{margin-left:0}@keyframes CQRkna_row-in{0%{opacity:0}}.CQRkna_slot{width:16px;height:20px;color:var(--dsw-alias-label-tertiary);flex:none;justify-content:center;align-items:center;display:inline-flex}.CQRkna_visuallyHidden{clip:rect(0 0 0 0);white-space:nowrap;width:1px;height:1px;position:absolute;overflow:hidden}.CQRkna_folderActive{color:var(--dsw-alias-state-business-primary)}.CQRkna_projectRow .CQRkna_chevron{display:none}.CQRkna_projectRow:hover .CQRkna_chevron{display:inline-flex}.CQRkna_projectRow:hover .CQRkna_folder{display:none}.CQRkna_arrow{transition:transform .15s var(--ds-ease-in-out)}.CQRkna_arrowOpen{transform:rotate(90deg)}.CQRkna_projectText{flex-direction:column;flex:1;gap:2px;min-width:0;display:flex}.CQRkna_title{text-overflow:ellipsis;white-space:nowrap;min-width:0;font-size:14px;line-height:20px;overflow:hidden}.CQRkna_renameInput{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-button-elevated-fill);min-width:0;color:inherit;border-radius:4px;outline:none;padding:0 2px;font-size:14px;line-height:20px}.CQRkna_sessionRow .CQRkna_title{flex:1}.CQRkna_meta{text-overflow:ellipsis;white-space:nowrap;color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:20px;overflow:hidden}.CQRkna_time{color:var(--dsw-alias-label-tertiary);flex:none;font-size:12px;line-height:20px}.CQRkna_dot{flex:none}.CQRkna_rowActions{flex:none;align-items:center;gap:12px;display:none}.CQRkna_projectRow:hover .CQRkna_rowActions,.CQRkna_sessionRow:hover .CQRkna_rowActions,.CQRkna_projectRow.CQRkna_menuOpen .CQRkna_rowActions,.CQRkna_sessionRow.CQRkna_menuOpen .CQRkna_rowActions{display:inline-flex}.CQRkna_sessionRow:hover .CQRkna_time,.CQRkna_sessionRow.CQRkna_menuOpen .CQRkna_time{display:none}.CQRkna_projectRow.CQRkna_menuOpen,.CQRkna_sessionRow.CQRkna_menuOpen{background:var(--dsw-alias-interactive-bg-hover)}.CQRkna_sessionRow.CQRkna_dropBefore,.CQRkna_sessionRow.CQRkna_dropAfter{position:relative}.CQRkna_sessionRow.CQRkna_dropBefore:before,.CQRkna_sessionRow.CQRkna_dropAfter:after{content:\"\";z-index:1;background:linear-gradient(55deg, transparent calc(50% - 1px), var(--dsw-alias-state-business-primary) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)) 0 0 / 5px 7px no-repeat, linear-gradient(125deg, transparent calc(50% - 1px), var(--dsw-alias-state-business-primary) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)) 0 5px / 5px 7px no-repeat, linear-gradient(var(--dsw-alias-state-business-primary) 0 0) 4px 5px / calc(100% - 4px) 2px no-repeat;pointer-events:none;height:12px;position:absolute;left:0;right:4px}.CQRkna_sessionRow.CQRkna_dropBefore:before{top:-7px}.CQRkna_sessionRow.CQRkna_dropAfter:after{bottom:-7px}.CQRkna_hoverContent{flex-direction:column;gap:8px;display:flex}.CQRkna_hoverTitle{color:#fff;overflow-wrap:break-word;font-size:14px;line-height:20px}.CQRkna_hoverPath{color:#cfd3d6;word-break:break-all;font-size:12px;line-height:16px}.CQRkna_hoverTime{color:#cfd3d6;font-size:12px;line-height:16px}.CQRkna_hoverStatus{color:#adb2b8;align-items:center;gap:8px;font-size:12px;line-height:20px;display:flex}.CQRkna_iconButton{cursor:pointer;width:16px;height:16px;color:var(--dsw-alias-label-tertiary);background:0 0;border:none;border-radius:4px;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex}.CQRkna_iconButton:hover{color:var(--dsw-alias-label-primary)}.CQRkna_chevron{color:var(--dsw-alias-label-caption)}@media (prefers-reduced-motion:reduce){.CQRkna_sessionRow,.CQRkna_arrow{transition:none;animation:none}}";
526
+ const tagId$2 = "@prettier-ai/dsh-client-ui-workspace/Rows.module.css";
527
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$2) + "]") === null) {
528
+ const tag = document.createElement("style");
529
+ tag.dataset.plugin = "@prettier-ai/dsh-client-ui-workspace";
530
+ tag.dataset.pluginCss = tagId$2;
531
+ tag.textContent = css$2;
532
+ document.head.appendChild(tag);
533
+ }
534
+ var Rows_module_css_default = {
535
+ "arrow": "CQRkna_arrow",
536
+ "arrowOpen": "CQRkna_arrowOpen",
537
+ "chevron": "CQRkna_chevron",
538
+ "dot": "CQRkna_dot",
539
+ "dropAfter": "CQRkna_dropAfter",
540
+ "dropBefore": "CQRkna_dropBefore",
541
+ "flatSessionRowWithoutStatus": "CQRkna_flatSessionRowWithoutStatus",
542
+ "folder": "CQRkna_folder",
543
+ "folderActive": "CQRkna_folderActive",
544
+ "hoverContent": "CQRkna_hoverContent",
545
+ "hoverPath": "CQRkna_hoverPath",
546
+ "hoverStatus": "CQRkna_hoverStatus",
547
+ "hoverTime": "CQRkna_hoverTime",
548
+ "hoverTitle": "CQRkna_hoverTitle",
549
+ "iconButton": "CQRkna_iconButton",
550
+ "menuOpen": "CQRkna_menuOpen",
551
+ "meta": "CQRkna_meta",
552
+ "projectRow": "CQRkna_projectRow",
553
+ "projectText": "CQRkna_projectText",
554
+ "renameInput": "CQRkna_renameInput",
555
+ "row-in": "CQRkna_row-in",
556
+ "rowActions": "CQRkna_rowActions",
557
+ "searchResultHeading": "CQRkna_searchResultHeading",
558
+ "searchResultMeta": "CQRkna_searchResultMeta",
559
+ "searchResultRow": "CQRkna_searchResultRow",
560
+ "searchResultSnippet": "CQRkna_searchResultSnippet",
561
+ "searchResultTitle": "CQRkna_searchResultTitle",
562
+ "searchResultWorkspace": "CQRkna_searchResultWorkspace",
563
+ "selected": "CQRkna_selected",
564
+ "sessionRow": "CQRkna_sessionRow",
565
+ "slot": "CQRkna_slot",
566
+ "time": "CQRkna_time",
567
+ "title": "CQRkna_title",
568
+ "visuallyHidden": "CQRkna_visuallyHidden"
569
+ };
570
+ //#endregion
571
+ //#region lib/types/client/rows/Rows.js
572
+ /**
573
+ * Workspace browser tree row components (figma Cell set 14:3080): pure presentational —
574
+ * all data and callbacks arrive via props. Hover swaps (folder->chevron,
575
+ * time->ellipsis, action buttons) are CSS-only. Row ... menus are visual-only
576
+ * except workspace Rename/Delete and session Rename/Fork/Archive; the session
577
+ * and workspace hover cards are suppressed while a menu is open.
578
+ */
579
+ /** Row display title: blank rows show the localized New Session label. */
580
+ function displayTitle(node, t) {
581
+ return node.blank ? t("session.new") : node.title;
582
+ }
583
+ /** Localized compact relative time ("刚刚"/"5分钟" in zh, "now"/"5min" in en). */
584
+ function timeLabel(updatedAt, now, t) {
585
+ const { unit, n } = (0, _prettier_ai_dsh_client_ui_primitives.relativeTime)(updatedAt, now);
586
+ return unit === "now" ? t("time.now") : t(`time.${unit}`, { n });
587
+ }
588
+ /** Hover-card variant: distances wrap in the ago template; the now bucket stays bare (no "now ago"). */
589
+ function hoverTimeLabel(updatedAt, now, t) {
590
+ const { unit, n } = (0, _prettier_ai_dsh_client_ui_primitives.relativeTime)(updatedAt, now);
591
+ return unit === "now" ? t("time.now") : t("time.ago", { t: t(`time.${unit}`, { n }) });
592
+ }
593
+ /**
594
+ * Absolute creation time through the dictionary's date template (the message
595
+ * clock pattern): `toLocaleString` would follow the browser language, not the
596
+ * app locale, and produce mixed-language text after a switch.
597
+ */
598
+ function createdLabel(createdAt, t) {
599
+ const d = new Date(createdAt);
600
+ const pad2 = (v) => String(v).padStart(2, "0");
601
+ return t("hover.created", { time: `${t("date.ymd", {
602
+ y: d.getFullYear(),
603
+ m: d.getMonth() + 1,
604
+ d: d.getDate()
605
+ })} ${pad2(d.getHours())}:${pad2(d.getMinutes())}` });
606
+ }
607
+ /** Hover-card body: workspace title, display directory path, absolute creation time. */
608
+ function WorkspaceHoverContent({ label, cwd, createdAt, t }) {
609
+ return (0, react_jsx_runtime.jsxs)("div", {
610
+ className: Rows_module_css_default.hoverContent,
611
+ children: [
612
+ (0, react_jsx_runtime.jsx)("div", {
613
+ className: Rows_module_css_default.hoverTitle,
614
+ children: label
615
+ }),
616
+ (0, react_jsx_runtime.jsx)("div", {
617
+ className: Rows_module_css_default.hoverPath,
618
+ children: cwd
619
+ }),
620
+ (0, react_jsx_runtime.jsx)("div", {
621
+ className: Rows_module_css_default.hoverTime,
622
+ children: createdLabel(createdAt, t)
623
+ })
624
+ ]
625
+ });
626
+ }
627
+ /** Pointer-position half of a row (insert line above or below). */
628
+ function rowHalf(e) {
629
+ const rect = e.currentTarget.getBoundingClientRect();
630
+ return e.clientY < rect.top + rect.height / 2 ? "before" : "after";
631
+ }
632
+ /**
633
+ * Project (workspace) header row: folder + title;
634
+ * hover reveals the chevron and create button, and dwelling on a real
635
+ * Workspace shows its hover card (the ungrouped bucket has none).
636
+ * `containsCurrent` arrives on the node (derivation fact, no renderer scan).
637
+ * @param props.group - derived group node.
638
+ * @param props.onToggle - expand/collapse the group.
639
+ * @param props.onCreate - start a frontend Session inside this Workspace.
640
+ * @param props.drag - optional workspace-row drag wiring.
641
+ * @param props.home - host account home for POSIX hover-path abbreviation.
642
+ * @param props.t - the browser root's locale seat.
643
+ * @returns the row element.
644
+ */
645
+ function ProjectRowItem({ group, onToggle, onCreate, actions, drag, home, t }) {
646
+ const row = group;
647
+ const label = row.workspaceId === void 0 ? t("group.ungrouped") : row.label;
648
+ const active = group.expanded && group.containsCurrent;
649
+ const [menuOpen, setMenuOpen] = (0, react.useState)(false);
650
+ const workspaceMenuItems = [{
651
+ id: "rename",
652
+ label: t("rename"),
653
+ icon: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconEditOutline16, {})
654
+ }, {
655
+ id: "delete",
656
+ label: t("delete.workspace"),
657
+ icon: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconTrashOutline16, {}),
658
+ danger: true
659
+ }];
660
+ const ownRow = (0, react_jsx_runtime.jsxs)("div", {
661
+ className: clsx(Rows_module_css_default.projectRow, menuOpen && Rows_module_css_default.menuOpen),
662
+ role: "treeitem",
663
+ "aria-expanded": row.expanded,
664
+ onClick: onToggle,
665
+ draggable: drag !== void 0,
666
+ onDragStart: drag === void 0 ? void 0 : (e) => {
667
+ e.dataTransfer.effectAllowed = "move";
668
+ e.dataTransfer.setData("text/plain", row.key);
669
+ drag.start();
670
+ },
671
+ onDragEnd: drag?.end,
672
+ children: [
673
+ (0, react_jsx_runtime.jsx)("span", {
674
+ className: clsx(Rows_module_css_default.slot, Rows_module_css_default.folder, active && Rows_module_css_default.folderActive),
675
+ children: row.expanded ? (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconFolderOpen16, {}) : (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconFolderClose16, {})
676
+ }),
677
+ (0, react_jsx_runtime.jsx)("span", {
678
+ className: clsx(Rows_module_css_default.slot, Rows_module_css_default.chevron),
679
+ children: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconTriangleRightFill14, { className: clsx(Rows_module_css_default.arrow, row.expanded && Rows_module_css_default.arrowOpen) })
680
+ }),
681
+ (0, react_jsx_runtime.jsx)("span", {
682
+ className: Rows_module_css_default.projectText,
683
+ children: (0, react_jsx_runtime.jsx)("span", {
684
+ className: Rows_module_css_default.title,
685
+ children: label
686
+ })
687
+ }),
688
+ (0, react_jsx_runtime.jsxs)("span", {
689
+ className: Rows_module_css_default.rowActions,
690
+ children: [actions !== void 0 && (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Menu, {
691
+ open: menuOpen,
692
+ onClose: () => {
693
+ setMenuOpen(false);
694
+ },
695
+ items: workspaceMenuItems,
696
+ onSelect: (id) => {
697
+ setMenuOpen(false);
698
+ /* v8 ignore next -- Menu can emit only the rename and delete rows supplied above. */
699
+ if (id !== "rename" && id !== "delete") return;
700
+ if (id === "rename") actions.rename();
701
+ else actions.delete();
702
+ },
703
+ portal: true,
704
+ closeOnPointerLeave: true,
705
+ anchor: (0, react_jsx_runtime.jsx)("button", {
706
+ type: "button",
707
+ className: Rows_module_css_default.iconButton,
708
+ "aria-label": t("actions.workspace.aria", { name: label }),
709
+ onClick: (e) => {
710
+ e.stopPropagation();
711
+ setMenuOpen((v) => !v);
712
+ },
713
+ children: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconEllipsisOutline16, {})
714
+ })
715
+ }), (0, react_jsx_runtime.jsx)("button", {
716
+ type: "button",
717
+ className: Rows_module_css_default.iconButton,
718
+ "aria-label": t("actions.newSession.aria", { name: label }),
719
+ onClick: (e) => {
720
+ e.stopPropagation();
721
+ onCreate();
722
+ },
723
+ children: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconPlusOutline16, {})
724
+ })]
725
+ })
726
+ ]
727
+ });
728
+ if (row.createdAt === void 0) return ownRow;
729
+ return (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.HoverCard, {
730
+ anchor: ownRow,
731
+ content: (0, react_jsx_runtime.jsx)(WorkspaceHoverContent, {
732
+ label: row.label,
733
+ cwd: row.cwd === void 0 ? void 0 : abbreviateHomePath(row.cwd, home),
734
+ createdAt: row.createdAt,
735
+ t
736
+ }),
737
+ disabled: menuOpen,
738
+ copyText: row.cwd,
739
+ copyLabel: t("copy"),
740
+ copiedLabel: t("hover.copied")
741
+ });
742
+ }
743
+ /* v8 ignore next 3 -- closed-union backstop; only reached if the status is forged */
744
+ function assertNever(value) {
745
+ throw new Error(`unknown pending interaction: ${String(value)}`);
746
+ }
747
+ /**
748
+ * Session status presentation; pending interaction is primary and live activity
749
+ * outranks completion reminders.
750
+ */
751
+ function sessionStatuses(node, t) {
752
+ const subagents = node.runningSubagentCount === 0 ? void 0 : {
753
+ state: "ongoing",
754
+ label: t(node.runningSubagentCount === 1 ? "status.subagentsRunning.one" : "status.subagentsRunning.other", { n: node.runningSubagentCount })
755
+ };
756
+ let pending;
757
+ switch (node.pendingInteraction) {
758
+ case "approval":
759
+ pending = {
760
+ state: "warning",
761
+ label: t("status.waitingApproval")
762
+ };
763
+ break;
764
+ case "plan-review":
765
+ pending = {
766
+ state: "warning",
767
+ label: t("status.planReview")
768
+ };
769
+ break;
770
+ case "question":
771
+ pending = {
772
+ state: "warning",
773
+ label: t("status.waitingAnswer")
774
+ };
775
+ break;
776
+ case void 0: break;
777
+ /* v8 ignore next -- closed PendingInteractionStatus union */
778
+ default: return assertNever(node.pendingInteraction);
779
+ }
780
+ if (pending !== void 0) return subagents === void 0 ? [pending] : [pending, subagents];
781
+ if (node.running) {
782
+ const primary = {
783
+ state: "ongoing",
784
+ label: t("status.running")
785
+ };
786
+ return subagents === void 0 ? [primary] : [primary, subagents];
787
+ }
788
+ if (subagents !== void 0) return [subagents];
789
+ if (node.completed) return [{
790
+ state: "done",
791
+ label: t("status.completed")
792
+ }];
793
+ return [{
794
+ state: "done",
795
+ label: t("status.idle")
796
+ }];
797
+ }
798
+ /** Primary status dot plus every status's screen-reader label, shared by the search and session rows. */
799
+ function SessionStatusDots({ statuses }) {
800
+ return (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.StateDot, { state: statuses[0].state }), statuses.map((status) => (0, react_jsx_runtime.jsx)("span", {
801
+ className: Rows_module_css_default.visuallyHidden,
802
+ children: status.label
803
+ }, status.label))] });
804
+ }
805
+ /** Hover-card body: full title, relative time, and every relevant live status. */
806
+ function SessionHoverContent({ node, now, t }) {
807
+ const statuses = sessionStatuses(node, t);
808
+ return (0, react_jsx_runtime.jsxs)("div", {
809
+ className: Rows_module_css_default.hoverContent,
810
+ children: [
811
+ (0, react_jsx_runtime.jsx)("div", {
812
+ className: Rows_module_css_default.hoverTitle,
813
+ children: displayTitle(node, t)
814
+ }),
815
+ !node.blank && (0, react_jsx_runtime.jsx)("div", {
816
+ className: Rows_module_css_default.hoverTime,
817
+ children: hoverTimeLabel(node.updatedAt, now, t)
818
+ }),
819
+ statuses.map((status) => (0, react_jsx_runtime.jsxs)("div", {
820
+ className: Rows_module_css_default.hoverStatus,
821
+ children: [(0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.StateDot, { state: status.state }), (0, react_jsx_runtime.jsx)("span", { children: status.label })]
822
+ }, status.label))
823
+ ]
824
+ });
825
+ }
826
+ /**
827
+ * One flat search result: title, Workspace context, and optional content
828
+ * excerpt. Search navigation opens the session only; it does not address an
829
+ * event inside the conversation.
830
+ * @param props.result - merged local/content search row.
831
+ * @param props.currentId - selected session id.
832
+ * @param props.onOpen - open the selected session.
833
+ * @param props.t - Workspace-browser translation seat.
834
+ * @returns the result button.
835
+ */
836
+ function SearchResultItem({ result, currentId, onOpen, t }) {
837
+ const selected = result.id === currentId;
838
+ const statuses = sessionStatuses(result, t);
839
+ const primaryStatus = statuses[0];
840
+ return (0, react_jsx_runtime.jsxs)("button", {
841
+ type: "button",
842
+ className: clsx(Rows_module_css_default.searchResultRow, selected && Rows_module_css_default.selected),
843
+ role: "treeitem",
844
+ "aria-selected": selected,
845
+ onClick: () => {
846
+ onOpen(result.id);
847
+ },
848
+ children: [(0, react_jsx_runtime.jsxs)("span", {
849
+ className: Rows_module_css_default.searchResultHeading,
850
+ children: [(0, react_jsx_runtime.jsx)("span", {
851
+ className: Rows_module_css_default.slot,
852
+ children: (primaryStatus.state !== "done" || result.completed) && (0, react_jsx_runtime.jsx)(SessionStatusDots, { statuses })
853
+ }), (0, react_jsx_runtime.jsx)("span", {
854
+ className: Rows_module_css_default.searchResultTitle,
855
+ children: result.title
856
+ })]
857
+ }), (0, react_jsx_runtime.jsxs)("span", {
858
+ className: Rows_module_css_default.searchResultMeta,
859
+ children: [(0, react_jsx_runtime.jsx)("span", {
860
+ className: Rows_module_css_default.searchResultWorkspace,
861
+ children: result.workspace || t("group.ungrouped")
862
+ }), result.snippet !== void 0 && (0, react_jsx_runtime.jsx)("span", {
863
+ className: Rows_module_css_default.searchResultSnippet,
864
+ children: result.snippet
865
+ })]
866
+ })]
867
+ });
868
+ }
869
+ /**
870
+ * One top-level 34px session row: status dot (pending user interaction outranks
871
+ * own or descendant activity), title, relative time, and the row actions menu.
872
+ * @param props.node - derived session node.
873
+ * @param props.currentId - selected session id (row highlight).
874
+ * @param props.now - epoch ms for relative-time formatting.
875
+ * @param props.onOpen - open a session by id.
876
+ * @param props.onRename - open the session rename dialog (id + current title).
877
+ * @param props.onFork - fork a session at its last completed turn.
878
+ * @param props.onArchive - archive a session by id.
879
+ * @param props.drag - optional draggable-row wiring.
880
+ * @param props.flat - omit the empty status slot in the hierarchy-free flat list.
881
+ * @param props.t - the browser root's locale seat.
882
+ * @returns the session row.
883
+ */
884
+ function SessionNodeItem({ node, currentId, now, onOpen, onRename, onFork, onArchive, drag, flat = false, t }) {
885
+ const row = node;
886
+ const title = displayTitle(node, t);
887
+ const selected = node.id === currentId;
888
+ const statuses = sessionStatuses(node, t);
889
+ const showStatus = statuses[0].state !== "done" || row.completed;
890
+ const [menuOpen, setMenuOpen] = (0, react.useState)(false);
891
+ const sessionMenuItems = [
892
+ {
893
+ id: "rename",
894
+ label: t("rename"),
895
+ icon: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconEditOutline16, {})
896
+ },
897
+ {
898
+ id: "fork",
899
+ label: t("menu.fork"),
900
+ icon: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconBranchOutline16, {})
901
+ },
902
+ {
903
+ id: "archive",
904
+ label: t("menu.archiveSession"),
905
+ icon: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconArchiveOutline20, { size: 16 })
906
+ }
907
+ ];
908
+ return (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.HoverCard, {
909
+ anchor: (0, react_jsx_runtime.jsxs)("div", {
910
+ className: clsx(Rows_module_css_default.sessionRow, selected && Rows_module_css_default.selected, menuOpen && Rows_module_css_default.menuOpen, flat && !showStatus && Rows_module_css_default.flatSessionRowWithoutStatus, drag?.marker === "before" && Rows_module_css_default.dropBefore, drag?.marker === "after" && Rows_module_css_default.dropAfter),
911
+ role: "treeitem",
912
+ "aria-selected": selected,
913
+ onClick: () => {
914
+ onOpen(node.id);
915
+ },
916
+ draggable: drag !== void 0,
917
+ onDragStart: drag === void 0 ? void 0 : (e) => {
918
+ e.dataTransfer.effectAllowed = "move";
919
+ e.dataTransfer.setData("text/plain", node.id);
920
+ drag.start();
921
+ },
922
+ onDragEnd: drag?.end,
923
+ onDragOver: drag === void 0 ? void 0 : (e) => {
924
+ if (!drag.active) return;
925
+ e.preventDefault();
926
+ e.dataTransfer.dropEffect = "move";
927
+ drag.hover(rowHalf(e));
928
+ },
929
+ onDrop: drag === void 0 ? void 0 : (e) => {
930
+ if (!drag.active) return;
931
+ e.preventDefault();
932
+ drag.drop(rowHalf(e));
933
+ },
934
+ children: [
935
+ (!flat || showStatus) && (0, react_jsx_runtime.jsx)("span", {
936
+ className: Rows_module_css_default.slot,
937
+ children: showStatus && (0, react_jsx_runtime.jsx)(SessionStatusDots, { statuses })
938
+ }),
939
+ (0, react_jsx_runtime.jsx)("span", {
940
+ className: Rows_module_css_default.title,
941
+ children: title
942
+ }),
943
+ !row.blank && (0, react_jsx_runtime.jsx)("span", {
944
+ className: Rows_module_css_default.time,
945
+ children: timeLabel(row.updatedAt, now, t)
946
+ }),
947
+ !row.blank && (0, react_jsx_runtime.jsx)("span", {
948
+ className: Rows_module_css_default.rowActions,
949
+ children: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Menu, {
950
+ open: menuOpen,
951
+ onClose: () => {
952
+ setMenuOpen(false);
953
+ },
954
+ items: sessionMenuItems,
955
+ onSelect: (id) => {
956
+ setMenuOpen(false);
957
+ if (id === "rename") onRename(node.id, row.title);
958
+ if (id === "fork") onFork(node.id);
959
+ if (id === "archive") onArchive(node.id);
960
+ },
961
+ portal: true,
962
+ closeOnPointerLeave: true,
963
+ anchor: (0, react_jsx_runtime.jsx)("button", {
964
+ type: "button",
965
+ className: Rows_module_css_default.iconButton,
966
+ "aria-label": t("actions.session.aria", { name: title }),
967
+ onClick: (e) => {
968
+ e.stopPropagation();
969
+ setMenuOpen((v) => !v);
970
+ },
971
+ children: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconEllipsisOutline16, {})
972
+ })
973
+ })
974
+ })
975
+ ]
976
+ }),
977
+ content: (0, react_jsx_runtime.jsx)(SessionHoverContent, {
978
+ node,
979
+ now,
980
+ t
981
+ }),
982
+ disabled: menuOpen || drag?.active === true,
983
+ copyText: row.blank ? void 0 : row.title,
984
+ copyLabel: t("copy"),
985
+ copiedLabel: t("hover.copied")
986
+ });
987
+ }
988
+ //#endregion
989
+ //#region \0dsh-css:/home/runner/work/dsh-publisher/dsh-publisher/upstream/packages/client/ui-workspace/src/client/WorkspacePicker.module.css.mjs
990
+ const css$1 = ".eAspXG_modalAction{min-width:72px}.eAspXG_modalError,.eAspXG_menuStatus{margin-top:8px;font-size:12px;line-height:18px}.eAspXG_modalError{color:var(--dsw-alias-state-error-primary)}.eAspXG_menuStatus{color:var(--dsw-alias-label-secondary)}";
991
+ const tagId$1 = "@prettier-ai/dsh-client-ui-workspace/WorkspacePicker.module.css";
992
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) {
993
+ const tag = document.createElement("style");
994
+ tag.dataset.plugin = "@prettier-ai/dsh-client-ui-workspace";
995
+ tag.dataset.pluginCss = tagId$1;
996
+ tag.textContent = css$1;
997
+ document.head.appendChild(tag);
998
+ }
999
+ var WorkspacePicker_module_css_default = {
1000
+ "menuStatus": "eAspXG_menuStatus",
1001
+ "modalAction": "eAspXG_modalAction",
1002
+ "modalError": "eAspXG_modalError"
1003
+ };
1004
+ //#endregion
1005
+ //#region lib/types/client/WorkspacePicker.js
1006
+ const ADD_WORKSPACE = "::add-workspace";
1007
+ /**
1008
+ * Render the pick menu plus the adoption error dialog.
1009
+ * @param props - owner-controlled flow props.
1010
+ * @returns menu + dialog elements.
1011
+ */
1012
+ function WorkspacePickFlow({ t, open, anchorRef, useWorkspaces, createWorkspace, useDirectoryFlow, renderDirectoryFlow, onPick, onClose, addOnly = false, side = "bottom", selectedId }) {
1013
+ const workspaceSnapshot = useWorkspaces((state) => state);
1014
+ const workspaces = workspaceSnapshot.items;
1015
+ const getAnchorRect = (0, react.useCallback)(() => anchorRef?.current?.getBoundingClientRect() ?? null, [anchorRef]);
1016
+ const [errorOpen, setErrorOpen] = (0, react.useState)(false);
1017
+ const [modalError, setModalError] = (0, react.useState)(null);
1018
+ const [flowOpen, setFlowOpen] = (0, react.useState)(false);
1019
+ const [pickingFolder, setPickingFolder] = (0, react.useState)(false);
1020
+ const flowBusy = flowOpen || pickingFolder;
1021
+ const flowAvailable = useDirectoryFlow((occupied) => occupied);
1022
+ (0, react.useEffect)(() => {
1023
+ if (flowOpen && !flowAvailable) setFlowOpen(false);
1024
+ }, [flowOpen, flowAvailable]);
1025
+ const addEntries = flowAvailable ? [{
1026
+ id: ADD_WORKSPACE,
1027
+ label: t("menu.addWorkspace"),
1028
+ icon: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconPlusOutline16, { size: 16 }),
1029
+ disabled: flowBusy
1030
+ }] : [];
1031
+ const pinAdd = !addOnly && workspaces.length > 0;
1032
+ const items = pinAdd ? workspaces.map((workspace) => ({
1033
+ id: workspace.workspaceId,
1034
+ label: workspace.title,
1035
+ icon: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconFolderClose16, { size: 16 }),
1036
+ disabled: flowBusy
1037
+ })) : addEntries;
1038
+ const menuIsEmpty = items.length === 0;
1039
+ const closeModal = () => {
1040
+ setErrorOpen(false);
1041
+ setModalError(null);
1042
+ };
1043
+ /** Adopt a picked directory; failures land in the folder-error dialog (Choose again reopens the flow). */
1044
+ const adoptDirectory = (path) => createWorkspace({ path }).then((workspace) => {
1045
+ setFlowOpen(false);
1046
+ onPick(workspace.workspaceId);
1047
+ }).catch((reason) => {
1048
+ setModalError(reason instanceof Error ? reason.message : String(reason));
1049
+ setFlowOpen(false);
1050
+ setErrorOpen(true);
1051
+ });
1052
+ const openDirectoryFlow = (0, react.useCallback)(() => {
1053
+ onClose();
1054
+ setErrorOpen(false);
1055
+ setModalError(null);
1056
+ setFlowOpen(true);
1057
+ }, [onClose]);
1058
+ const listSettled = addOnly || workspaceSnapshot.phase === "ready";
1059
+ const addIsTheOnlyEntry = !pinAdd && listSettled && addEntries.length === 1;
1060
+ (0, react.useEffect)(() => {
1061
+ if (open && addIsTheOnlyEntry && !flowBusy) openDirectoryFlow();
1062
+ }, [
1063
+ open,
1064
+ addIsTheOnlyEntry,
1065
+ flowBusy,
1066
+ openDirectoryFlow
1067
+ ]);
1068
+ /** Owner side of the flow conversation: adopt keeps the flow open (busy) until the Host answers. */
1069
+ const flowOwner = {
1070
+ open: flowOpen,
1071
+ busy: pickingFolder,
1072
+ onPicked: (path) => {
1073
+ setPickingFolder(true);
1074
+ adoptDirectory(path).finally(() => {
1075
+ setPickingFolder(false);
1076
+ });
1077
+ },
1078
+ onCancel: () => {
1079
+ setFlowOpen(false);
1080
+ },
1081
+ onError: (message) => {
1082
+ setFlowOpen(false);
1083
+ setModalError(message);
1084
+ setErrorOpen(true);
1085
+ }
1086
+ };
1087
+ const handleSelect = (id) => {
1088
+ if (id === ADD_WORKSPACE) {
1089
+ openDirectoryFlow();
1090
+ return;
1091
+ }
1092
+ onPick(id);
1093
+ };
1094
+ return (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1095
+ (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Menu, {
1096
+ open: open && !addIsTheOnlyEntry && !menuIsEmpty,
1097
+ anchor: null,
1098
+ items,
1099
+ ...pinAdd ? { footer: addEntries } : {},
1100
+ selectedId,
1101
+ onSelect: handleSelect,
1102
+ onClose,
1103
+ side,
1104
+ portal: true,
1105
+ getAnchorRect
1106
+ }),
1107
+ open && !addIsTheOnlyEntry && !menuIsEmpty && workspaceSnapshot.phase === "pending" && (0, react_jsx_runtime.jsx)("div", {
1108
+ className: WorkspacePicker_module_css_default.menuStatus,
1109
+ role: "status",
1110
+ children: t("picker.loading")
1111
+ }),
1112
+ renderDirectoryFlow(flowOwner),
1113
+ (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Modal, {
1114
+ open: errorOpen,
1115
+ onClose: closeModal,
1116
+ closeLabel: t("close"),
1117
+ title: t("folderError.title"),
1118
+ footer: (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Button, {
1119
+ variant: "outline",
1120
+ className: WorkspacePicker_module_css_default.modalAction,
1121
+ onClick: closeModal,
1122
+ children: t("cancel")
1123
+ }), (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Button, {
1124
+ variant: "primary",
1125
+ className: WorkspacePicker_module_css_default.modalAction,
1126
+ disabled: !flowAvailable,
1127
+ onClick: openDirectoryFlow,
1128
+ children: t("folderError.retry")
1129
+ })] }),
1130
+ children: (0, react_jsx_runtime.jsx)("div", {
1131
+ className: WorkspacePicker_module_css_default.modalError,
1132
+ role: "alert",
1133
+ children: modalError
1134
+ })
1135
+ })
1136
+ ] });
1137
+ }
1138
+ /**
1139
+ * The conversation empty-state registration: adapts the owner share to the
1140
+ * core flow (all state and semantics live in the flow / the owner).
1141
+ * @param props - empty-state slot props (owner share + injected creation callback).
1142
+ * @returns the flow element.
1143
+ */
1144
+ function WorkspacePicker({ open, anchorRef, useWorkspaces, selectedId, onPick, onClose, createWorkspace, useDirectoryFlow, renderSlot, t }) {
1145
+ return (0, react_jsx_runtime.jsx)(WorkspacePickFlow, {
1146
+ t,
1147
+ open,
1148
+ anchorRef,
1149
+ useWorkspaces,
1150
+ createWorkspace,
1151
+ useDirectoryFlow,
1152
+ renderDirectoryFlow: (owner) => renderSlot("conversation.hero.workspace.directoryFlow", owner),
1153
+ selectedId,
1154
+ onPick,
1155
+ onClose
1156
+ });
1157
+ }
1158
+ //#endregion
1159
+ //#region \0dsh-css:/home/runner/work/dsh-publisher/dsh-publisher/upstream/packages/client/ui-workspace/src/client/rows/WorkspaceBrowser.module.css.mjs
1160
+ const css = ".XUKtvW_root{--dsh-session-list-edge-inset:var(--dsh-sidebar-inline-padding);--dsh-session-list-scrollbar-width:8px;--dsh-session-list-scrollbar-offset:2px;box-sizing:border-box;min-height:0;padding-right:var(--dsh-session-list-edge-inset);flex-direction:column;flex:1;display:flex}.XUKtvW_root.XUKtvW_rail{padding-right:0}.XUKtvW_iconButton{cursor:pointer;width:28px;height:28px;color:var(--dsw-alias-label-secondary);background:0 0;border:none;border-radius:50%;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex}.XUKtvW_iconButton:hover{background:var(--dsw-alias-interactive-bg-hover)}.XUKtvW_sectionHeader{box-sizing:border-box;height:36px;color:var(--dsw-alias-label-tertiary);border-radius:12px;flex:none;justify-content:flex-end;align-items:center;gap:4px;margin-bottom:4px;padding-left:4px;display:flex;overflow:hidden}.XUKtvW_root:not(.XUKtvW_rail) .XUKtvW_sectionHeader{margin-top:2px;margin-right:-4px}.XUKtvW_sectionLabel{white-space:nowrap;opacity:1;visibility:visible;min-width:0;max-width:45%;transition:max-width .18s var(--ds-ease-in-out), margin-right .18s var(--ds-ease-in-out), opacity .12s var(--ds-ease-in-out), transform .18s var(--ds-ease-in-out), visibility 0s linear;flex:none;line-height:20px;overflow:hidden}.XUKtvW_sectionLabelHidden{opacity:0;visibility:hidden;max-width:0;margin-right:-4px;transition-delay:0s,0s,0s,0s,.18s;transform:translate(-4px)}.XUKtvW_searchSlot{box-sizing:border-box;min-width:0;max-width:28px;transition:max-width .18s var(--ds-ease-in-out), padding-left .18s var(--ds-ease-in-out);flex:1;align-items:center;margin-left:auto;padding-left:0;display:flex}.XUKtvW_searchSlotExpanded{max-width:100%;padding-left:0}.XUKtvW_headerActions{opacity:1;visibility:visible;max-width:60px;transition:max-width .18s var(--ds-ease-in-out), opacity .12s var(--ds-ease-in-out), transform .18s var(--ds-ease-in-out), visibility 0s linear;flex:none;align-items:center;gap:4px;display:flex;overflow:hidden}.XUKtvW_headerActionsHidden{opacity:0;visibility:hidden;pointer-events:none;max-width:0;transition-delay:0s,0s,0s,.18s;transform:translate(4px)}.XUKtvW_search{box-sizing:border-box;cursor:text;width:100%;height:28px;color:var(--dsw-alias-label-secondary);transition:width .18s var(--ds-ease-in-out), padding .18s var(--ds-ease-in-out), border-color .18s var(--ds-ease-in-out), background-color .18s var(--ds-ease-in-out);background:0 0;border:none;border-radius:50%;flex:none;align-items:center;gap:0;margin:0;padding:0;display:flex;overflow:hidden}.XUKtvW_searchExpanded{border:1px solid var(--dsw-alias-border-l2);width:calc(100% + 4px);height:30px;color:var(--dsw-alias-label-caption);background:0 0;border-radius:10px;margin-inline:-2px;padding:0 4px 0 0}.XUKtvW_searchButton{cursor:pointer;width:28px;height:28px;color:inherit;background:0 0;border:none;border-radius:50%;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex}.XUKtvW_searchExpanded .XUKtvW_searchButton{width:28px;height:30px}.XUKtvW_searchButton:hover{background:var(--dsw-alias-interactive-bg-hover)}.XUKtvW_searchExpanded .XUKtvW_searchButton:hover{background:0 0}.XUKtvW_searchInput{opacity:0;pointer-events:none;width:0;min-width:0;color:var(--dsw-alias-label-primary);transition:opacity .12s var(--ds-ease-in-out);background:0 0;border:none;outline:none;flex:1;font-size:13px;line-height:18px}.XUKtvW_searchExpanded .XUKtvW_searchInput{opacity:1;pointer-events:auto;margin-left:-2px}.XUKtvW_searchInput::placeholder{color:var(--dsw-alias-label-tertiary)}.XUKtvW_clearButton{cursor:pointer;width:24px;height:24px;color:var(--dsw-alias-label-secondary);background:0 0;border:none;border-radius:50%;flex:none;justify-content:center;align-items:center;padding:0;display:inline-flex}.XUKtvW_clearButton:hover{background:var(--dsw-alias-interactive-bg-hover)}.XUKtvW_rail .XUKtvW_sectionHeader{justify-content:flex-start;gap:0;margin-bottom:12px;padding-left:0}.XUKtvW_rail .XUKtvW_headerActions{max-width:none}.XUKtvW_rail .XUKtvW_iconButton{width:36px;height:36px;color:var(--dsw-alias-label-primary)}.XUKtvW_rail .XUKtvW_search{background:0 0;border-color:#0000;gap:0;width:36px;height:36px;margin:0 0 12px;padding:0}.XUKtvW_rail .XUKtvW_searchButton{width:36px;height:36px;color:var(--dsw-alias-label-primary)}.XUKtvW_rail .XUKtvW_searchButton:hover{background:var(--dsw-alias-interactive-bg-hover)}.XUKtvW_listArea{min-height:0;margin-left:-4px;margin-right:calc(-1 * var(--dsh-session-list-edge-inset));flex-direction:column;flex:1;padding-left:4px;display:flex;overflow:visible}.XUKtvW_rail .XUKtvW_listArea{margin-left:0;margin-right:0;padding-left:0}.XUKtvW_treeBody{flex-direction:column;flex:1;min-height:0;display:flex;position:relative}.XUKtvW_fade{left:0;right:var(--dsh-session-list-edge-inset);background:linear-gradient(to bottom, transparent, var(--dsw-specific-sidebar-fill));pointer-events:none;height:24px;position:absolute;bottom:0}.XUKtvW_wide{animation:XUKtvW_wide-in .2s var(--ds-ease-in-out)}@keyframes XUKtvW_wide-in{0%{opacity:0}}.XUKtvW_list{min-height:0;margin-left:-4px;margin-right:var(--dsh-session-list-scrollbar-offset);padding-left:4px;padding-right:calc(var(--dsh-session-list-edge-inset) - var(--dsh-session-list-scrollbar-width) - var(--dsh-session-list-scrollbar-offset));scrollbar-gutter:stable;flex:1;padding-bottom:16px;overflow-y:auto}.XUKtvW_flatList>*+*,.XUKtvW_searchTree>[role=treeitem]+[role=treeitem],.XUKtvW_groupSection>*+*{margin-top:2px}.XUKtvW_searchStatus,.XUKtvW_searchWarning{color:var(--dsw-alias-label-tertiary);padding:10px 12px;font-size:12px;line-height:18px}.XUKtvW_searchWarning{color:var(--dsw-alias-label-secondary)}.XUKtvW_groupSection{position:relative}.XUKtvW_groupSection+.XUKtvW_groupSection{margin-top:4px}.XUKtvW_listTopDropIndicator,.XUKtvW_workspaceDropBefore:before,.XUKtvW_workspaceDropAfter:after{content:\"\";z-index:1;background:linear-gradient(55deg, transparent calc(50% - 1px), var(--dsw-alias-state-business-primary) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)) 0 0 / 5px 7px no-repeat, linear-gradient(125deg, transparent calc(50% - 1px), var(--dsw-alias-state-business-primary) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)) 0 5px / 5px 7px no-repeat, linear-gradient(var(--dsw-alias-state-business-primary) 0 0) 4px 5px / calc(100% - 4px) 2px no-repeat;pointer-events:none;height:12px;position:absolute;left:0;right:0}.XUKtvW_listTopDropIndicator{top:-8px;left:0;right:var(--dsh-session-list-edge-inset)}.XUKtvW_listTopDropActive>.XUKtvW_workspaceDropBefore:first-child:before{display:none}.XUKtvW_workspaceDropBefore:before{top:-8px}.XUKtvW_workspaceDropAfter:after{bottom:-8px}.XUKtvW_sessionOverflowButton{cursor:pointer;text-align:left;width:100%;height:28px;color:var(--dsw-alias-label-tertiary);background:0 0;border:none;border-radius:8px;padding:0 12px 0 28px;font-size:12px}.XUKtvW_groupSection>.XUKtvW_sessionOverflowButton{margin-top:0}.XUKtvW_sessionOverflowButton:hover{color:var(--dsw-alias-label-secondary);background:0 0}.XUKtvW_empty{color:var(--dsw-alias-label-tertiary);padding:16px 12px;font-size:13px}.XUKtvW_renameInput{box-sizing:border-box;border:1px solid var(--dsw-alias-border-l2);width:100%;height:44px;color:var(--dsw-alias-label-primary);background:0 0;border-radius:22px;outline:none;padding:7px 14px;font-size:14px;font-weight:400;line-height:22px}.XUKtvW_renameInput:disabled{color:var(--dsw-alias-label-dimmed)}.XUKtvW_renameError{color:var(--dsw-alias-state-error-primary);margin-top:8px;font-size:12px;line-height:18px}.XUKtvW_deleteAction:not(:disabled){color:var(--dsw-alias-state-error-primary)}.XUKtvW_deleteStatus{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px}@media (prefers-reduced-motion:reduce){.XUKtvW_wide{animation:none}.XUKtvW_search,.XUKtvW_sectionLabel,.XUKtvW_searchSlot,.XUKtvW_searchInput,.XUKtvW_headerActions{transition:none}}";
1161
+ const tagId = "@prettier-ai/dsh-client-ui-workspace/WorkspaceBrowser.module.css";
1162
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
1163
+ const tag = document.createElement("style");
1164
+ tag.dataset.plugin = "@prettier-ai/dsh-client-ui-workspace";
1165
+ tag.dataset.pluginCss = tagId;
1166
+ tag.textContent = css;
1167
+ document.head.appendChild(tag);
1168
+ }
1169
+ var WorkspaceBrowser_module_css_default = {
1170
+ "clearButton": "XUKtvW_clearButton",
1171
+ "deleteAction": "XUKtvW_deleteAction",
1172
+ "deleteStatus": "XUKtvW_deleteStatus",
1173
+ "empty": "XUKtvW_empty",
1174
+ "fade": "XUKtvW_fade",
1175
+ "flatList": "XUKtvW_flatList",
1176
+ "groupSection": "XUKtvW_groupSection",
1177
+ "headerActions": "XUKtvW_headerActions",
1178
+ "headerActionsHidden": "XUKtvW_headerActionsHidden",
1179
+ "iconButton": "XUKtvW_iconButton",
1180
+ "list": "XUKtvW_list",
1181
+ "listArea": "XUKtvW_listArea",
1182
+ "listTopDropActive": "XUKtvW_listTopDropActive",
1183
+ "listTopDropIndicator": "XUKtvW_listTopDropIndicator",
1184
+ "rail": "XUKtvW_rail",
1185
+ "renameError": "XUKtvW_renameError",
1186
+ "renameInput": "XUKtvW_renameInput",
1187
+ "root": "XUKtvW_root",
1188
+ "search": "XUKtvW_search",
1189
+ "searchButton": "XUKtvW_searchButton",
1190
+ "searchExpanded": "XUKtvW_searchExpanded",
1191
+ "searchInput": "XUKtvW_searchInput",
1192
+ "searchSlot": "XUKtvW_searchSlot",
1193
+ "searchSlotExpanded": "XUKtvW_searchSlotExpanded",
1194
+ "searchStatus": "XUKtvW_searchStatus",
1195
+ "searchTree": "XUKtvW_searchTree",
1196
+ "searchWarning": "XUKtvW_searchWarning",
1197
+ "sectionHeader": "XUKtvW_sectionHeader",
1198
+ "sectionLabel": "XUKtvW_sectionLabel",
1199
+ "sectionLabelHidden": "XUKtvW_sectionLabelHidden",
1200
+ "sessionOverflowButton": "XUKtvW_sessionOverflowButton",
1201
+ "treeBody": "XUKtvW_treeBody",
1202
+ "wide": "XUKtvW_wide",
1203
+ "wide-in": "XUKtvW_wide-in",
1204
+ "workspaceDropAfter": "XUKtvW_workspaceDropAfter",
1205
+ "workspaceDropBefore": "XUKtvW_workspaceDropBefore"
1206
+ };
1207
+ //#endregion
1208
+ //#region lib/types/client/rows/WorkspaceBrowser.js
1209
+ /**
1210
+ * The workspace/session browsing region filling the sidebar shell's
1211
+ * `sidebar.workspaces` hole: section header (title + view options + add
1212
+ * workspace), search, the grouped tree or flat list, and the workspace
1213
+ * dialogs. Wide state renders the full browser; rail state renders the two
1214
+ * region icons (search / add workspace) as 36px controls on the shell's shared
1215
+ * rail entry path, each requesting expansion through the owner share. Adding
1216
+ * is the header button's one action, so it raises the directory flow with no
1217
+ * menu in between; the flow and its error dialog live in WorkspacePicker
1218
+ * (same package — direct composition, no slot between them).
1219
+ */
1220
+ /**
1221
+ * Column slide length (--ds-transition-duration-slow): rail-search focus waits it out —
1222
+ * focus() forces a synchronous layout and would jank the slide.
1223
+ */
1224
+ const EXPAND_SLIDE_MS = 300;
1225
+ /** Pause between the latest keystroke and a Host content-search request. */
1226
+ const SEARCH_DEBOUNCE_MS = 250;
1227
+ /** `session.search` wire bound, measured in JavaScript UTF-16 code units. */
1228
+ const SEARCH_QUERY_MAX_CODE_UNITS = 500;
1229
+ /** Session rows visible per Workspace before the local overflow control. */
1230
+ const COLLAPSED_SESSION_LIMIT = 5;
1231
+ /** Fold one Workspace without charging its provisional New Session against the ordinary-row limit. */
1232
+ function collapsedSessionRows(sessions) {
1233
+ let ordinaryCount = 0;
1234
+ const rows = sessions.filter((session) => {
1235
+ if (session.blank) return true;
1236
+ if (ordinaryCount >= COLLAPSED_SESSION_LIMIT) return false;
1237
+ ordinaryCount += 1;
1238
+ return true;
1239
+ });
1240
+ return {
1241
+ rows,
1242
+ hiddenCount: sessions.length - rows.length
1243
+ };
1244
+ }
1245
+ /** Keep controlled input and RPC payload inside the session.search wire contract. */
1246
+ function sanitizeSearchQuery(value) {
1247
+ const withoutNul = value.replaceAll("\0", "");
1248
+ if (withoutNul.length <= SEARCH_QUERY_MAX_CODE_UNITS) return withoutNul;
1249
+ let end = SEARCH_QUERY_MAX_CODE_UNITS;
1250
+ const last = withoutNul.charCodeAt(end - 1);
1251
+ const next = withoutNul.charCodeAt(end);
1252
+ if (last >= 55296 && last <= 56319 && next >= 56320 && next <= 57343) end--;
1253
+ return withoutNul.slice(0, end);
1254
+ }
1255
+ /** Immutable membership toggle for the local expand-all array. */
1256
+ function toggled(list, key) {
1257
+ return list.includes(key) ? list.filter((k) => k !== key) : [...list, key];
1258
+ }
1259
+ /**
1260
+ * Accept the native drag at document level while a row drag is active: row
1261
+ * hover still owns the insertion marker, and releasing outside the list must
1262
+ * not be rendered as a rejected drop before dragend commits that last marker.
1263
+ */
1264
+ function useNativeDragAcceptance(active) {
1265
+ (0, react.useEffect)(() => {
1266
+ if (!active) return;
1267
+ const acceptDrag = (event) => {
1268
+ event.preventDefault();
1269
+ if (event.dataTransfer !== null) event.dataTransfer.dropEffect = "move";
1270
+ };
1271
+ const acceptDrop = (event) => {
1272
+ event.preventDefault();
1273
+ };
1274
+ document.addEventListener("dragover", acceptDrag);
1275
+ document.addEventListener("drop", acceptDrop);
1276
+ return () => {
1277
+ document.removeEventListener("dragover", acceptDrag);
1278
+ document.removeEventListener("drop", acceptDrop);
1279
+ };
1280
+ }, [active]);
1281
+ }
1282
+ /** Reconcile a stored view order with the Workspace's current session account. */
1283
+ function reconciledSessionOrder(sessionIds, stored) {
1284
+ if (stored === void 0) return [...sessionIds];
1285
+ const byId = new Map(sessionIds.map((id) => [id, id]));
1286
+ const ordered = [];
1287
+ const included = /* @__PURE__ */ new Set();
1288
+ for (const key of stored) {
1289
+ const id = byId.get(key);
1290
+ if (id === void 0 || included.has(key)) continue;
1291
+ ordered.push(id);
1292
+ included.add(key);
1293
+ }
1294
+ for (const id of sessionIds) {
1295
+ if (included.has(id)) continue;
1296
+ ordered.push(id);
1297
+ }
1298
+ return ordered;
1299
+ }
1300
+ /** Newest update first with stable Session identity as the tie-break. */
1301
+ function compareSessionRecency(a, b, byId) {
1302
+ const aUpdatedAt = byId[a]?.updatedAt ?? Number.NEGATIVE_INFINITY;
1303
+ const bUpdatedAt = byId[b]?.updatedAt ?? Number.NEGATIVE_INFINITY;
1304
+ if (aUpdatedAt !== bUpdatedAt) return bUpdatedAt - aUpdatedAt;
1305
+ return a < b ? -1 : 1;
1306
+ }
1307
+ /** Reconcile one editable order account and apply its activity-promotion policy. */
1308
+ function nextSessionOrderAccount({ sessionIds, previousOrder, previousUpdatedAt, list, orderBy, sortByRecency }) {
1309
+ let order = reconciledSessionOrder(sessionIds, previousOrder);
1310
+ if (sortByRecency) order.sort((a, b) => compareSessionRecency(a, b, list.byId));
1311
+ else if (orderBy === "updated") {
1312
+ const promoted = sessionIds.filter((id) => {
1313
+ const session = list.byId[id];
1314
+ return session !== void 0 && (previousUpdatedAt[id] === void 0 || session.updatedAt > previousUpdatedAt[id]);
1315
+ }).sort((a, b) => compareSessionRecency(a, b, list.byId));
1316
+ if (promoted.length > 0) {
1317
+ const promotedIds = new Set(promoted);
1318
+ order = [...promoted, ...order.filter((id) => !promotedIds.has(id))];
1319
+ }
1320
+ }
1321
+ const updatedAt = {};
1322
+ for (const id of sessionIds) {
1323
+ const session = list.byId[id];
1324
+ if (session !== void 0) updatedAt[id] = session.updatedAt;
1325
+ }
1326
+ const orderChanged = previousOrder === void 0 || order.length !== previousOrder.length || order.some((id, index) => id !== previousOrder[index]);
1327
+ const timestampsChanged = Object.keys(updatedAt).length !== Object.keys(previousUpdatedAt).length || Object.entries(updatedAt).some(([id, timestamp]) => previousUpdatedAt[id] !== timestamp);
1328
+ return {
1329
+ order,
1330
+ updatedAt,
1331
+ changed: orderChanged || timestampsChanged
1332
+ };
1333
+ }
1334
+ /** Grouping and ordering menu; own open state so it resets with the wide chrome. */
1335
+ function ViewOptionsMenu({ groupBy, orderBy, onGroupPick, onOrderPick, t }) {
1336
+ const [open, setOpen] = (0, react.useState)(false);
1337
+ return (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Menu, {
1338
+ open,
1339
+ onClose: () => {
1340
+ setOpen(false);
1341
+ },
1342
+ items: [
1343
+ {
1344
+ type: "label",
1345
+ id: "group-by",
1346
+ text: t("groupBy.label")
1347
+ },
1348
+ {
1349
+ id: "workspace",
1350
+ label: t("groupBy.workspace")
1351
+ },
1352
+ {
1353
+ id: "flat",
1354
+ label: t("groupBy.flat")
1355
+ },
1356
+ {
1357
+ type: "separator",
1358
+ id: "order-by-separator"
1359
+ },
1360
+ {
1361
+ type: "label",
1362
+ id: "order-by",
1363
+ text: t("orderBy.label")
1364
+ },
1365
+ {
1366
+ id: "manual",
1367
+ label: t("orderBy.manual")
1368
+ },
1369
+ {
1370
+ id: "updated",
1371
+ label: t("orderBy.updated")
1372
+ }
1373
+ ],
1374
+ selectedIds: [groupBy, orderBy],
1375
+ onSelect: (id) => {
1376
+ if (id === "workspace" || id === "flat") onGroupPick(id);
1377
+ else if (id === "manual" || id === "updated") onOrderPick(id);
1378
+ setOpen(false);
1379
+ },
1380
+ align: "end",
1381
+ dense: true,
1382
+ portal: true,
1383
+ anchor: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Tooltip, {
1384
+ label: t("viewOptions.label"),
1385
+ side: "bottom",
1386
+ delayMs: 500,
1387
+ children: (0, react_jsx_runtime.jsx)("button", {
1388
+ type: "button",
1389
+ className: clsx(WorkspaceBrowser_module_css_default.iconButton, WorkspaceBrowser_module_css_default.wide),
1390
+ "aria-label": t("viewOptions.label"),
1391
+ onClick: () => {
1392
+ setOpen((v) => !v);
1393
+ },
1394
+ children: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconPersonalizationOutline16, {})
1395
+ })
1396
+ })
1397
+ });
1398
+ }
1399
+ /** Resolve an insertion side from the full rendered workspace group. */
1400
+ function workspaceGroupHalf(e) {
1401
+ const rect = e.currentTarget.getBoundingClientRect();
1402
+ return e.clientY < rect.top + rect.height / 2 ? "before" : "after";
1403
+ }
1404
+ /** The scrolling session tree; unmounting drops the sessions subscription and expand-all state. */
1405
+ function SessionTree({ useSessions, useSessionPendingInteraction, startSession, open, forkSession, workspaces, archivedSessionIds, onRenameRequest, onDeleteRequest, onSessionRename, onSessionArchive, insertWorkspaceBefore, insertSessionBefore, orderBy, groupExpansion, setGroupExpanded, sessionOrderByAccount, sessionUpdatedAtByAccount, syncSessionOrderAccount, setSessionOrder, home, t }) {
1406
+ const list = useSessions((s) => s);
1407
+ const pendingInteractions = useSessionPendingInteraction((s) => s);
1408
+ const current = list.current;
1409
+ const [expandedSessionGroups, setExpandedSessionGroups] = (0, react.useState)([]);
1410
+ const [drag, setDrag] = (0, react.useState)(null);
1411
+ const sessionDropCommitted = (0, react.useRef)(false);
1412
+ const [workspaceDrag, setWorkspaceDrag] = (0, react.useState)(null);
1413
+ const workspaceDropCommitted = (0, react.useRef)(false);
1414
+ const previousOrderBy = (0, react.useRef)(orderBy);
1415
+ useNativeDragAcceptance(drag !== null || workspaceDrag !== null);
1416
+ const currentGroup = current === void 0 ? void 0 : workspaces.find((w) => w.sessionIds.includes(current))?.workspaceId ?? "";
1417
+ (0, react.useEffect)(() => {
1418
+ if (current === void 0 || currentGroup === void 0 || Object.hasOwn(groupExpansion, currentGroup)) return;
1419
+ setGroupExpanded(currentGroup, true);
1420
+ }, [
1421
+ current,
1422
+ currentGroup,
1423
+ setGroupExpanded,
1424
+ groupExpansion
1425
+ ]);
1426
+ const expandedGroups = (0, react.useMemo)(() => Object.entries(groupExpansion).filter(([, expanded]) => expanded).map(([key]) => key), [groupExpansion]);
1427
+ const ungroupedSessionIds = (0, react.useMemo)(() => {
1428
+ const accounted = new Set(workspaces.flatMap((workspace) => workspace.sessionIds));
1429
+ return list.ids.filter((id) => list.byId[id] !== void 0 && !accounted.has(id));
1430
+ }, [list, workspaces]);
1431
+ (0, react.useEffect)(() => {
1432
+ if (list.phase !== "ready") return;
1433
+ const switchedToUpdated = previousOrderBy.current !== "updated" && orderBy === "updated";
1434
+ previousOrderBy.current = orderBy;
1435
+ const accounts = [...workspaces.map((workspace) => ({
1436
+ key: workspace.workspaceId,
1437
+ sessionIds: workspace.sessionIds.filter((id) => list.byId[id] !== void 0)
1438
+ })), {
1439
+ key: "",
1440
+ sessionIds: ungroupedSessionIds
1441
+ }];
1442
+ for (const { key, sessionIds } of accounts) {
1443
+ const previousOrder = sessionOrderByAccount[key];
1444
+ const next = nextSessionOrderAccount({
1445
+ sessionIds,
1446
+ previousOrder,
1447
+ previousUpdatedAt: sessionUpdatedAtByAccount[key] ?? {},
1448
+ list,
1449
+ orderBy,
1450
+ sortByRecency: orderBy === "updated" && (previousOrder === void 0 || switchedToUpdated)
1451
+ });
1452
+ if (next.changed) syncSessionOrderAccount(key, next.order.map((id) => id), next.updatedAt);
1453
+ }
1454
+ }, [
1455
+ list,
1456
+ orderBy,
1457
+ sessionOrderByAccount,
1458
+ sessionUpdatedAtByAccount,
1459
+ syncSessionOrderAccount,
1460
+ ungroupedSessionIds,
1461
+ workspaces
1462
+ ]);
1463
+ const orderedWorkspaces = (0, react.useMemo)(() => {
1464
+ return workspaces.map((workspace) => {
1465
+ const stored = sessionOrderByAccount[workspace.workspaceId];
1466
+ const sessionIds = reconciledSessionOrder(workspace.sessionIds, stored);
1467
+ return {
1468
+ ...workspace,
1469
+ sessionIds
1470
+ };
1471
+ });
1472
+ }, [sessionOrderByAccount, workspaces]);
1473
+ const orderedUngroupedSessionIds = (0, react.useMemo)(() => reconciledSessionOrder(ungroupedSessionIds, sessionOrderByAccount[""]), [sessionOrderByAccount, ungroupedSessionIds]);
1474
+ const groups = (0, react.useMemo)(() => deriveGroups(list, orderedWorkspaces, archivedSessionIds, pendingInteractions, {
1475
+ expandedGroups,
1476
+ ...sessionOrderByAccount[""] === void 0 ? {} : { ungroupedOrder: sessionOrderByAccount[""] }
1477
+ }), [
1478
+ list,
1479
+ orderedWorkspaces,
1480
+ archivedSessionIds,
1481
+ pendingInteractions,
1482
+ expandedGroups,
1483
+ sessionOrderByAccount
1484
+ ]);
1485
+ const now = Date.now();
1486
+ const commitSessionDrag = (activeDrag, over) => {
1487
+ if (sessionDropCommitted.current) return;
1488
+ sessionDropCommitted.current = true;
1489
+ setDrag(null);
1490
+ const group = groups.find((candidate) => candidate.key === activeDrag.accountKey);
1491
+ if (group === void 0) return;
1492
+ const sessionsExpanded = expandedSessionGroups.includes(group.key);
1493
+ const renderedSessions = sessionsExpanded ? group.sessions : collapsedSessionRows(group.sessions).rows;
1494
+ const targetIndex = renderedSessions.findIndex((session) => session.id === over.id);
1495
+ if (targetIndex === -1) return;
1496
+ const sourceIndex = renderedSessions.findIndex((session) => session.id === activeDrag.sessionId);
1497
+ if (over.id === activeDrag.sessionId) return;
1498
+ const withoutSource = renderedSessions.filter((session) => session.id !== activeDrag.sessionId);
1499
+ const targetWithoutSourceIndex = withoutSource.findIndex((session) => session.id === over.id);
1500
+ if (targetWithoutSourceIndex === -1) return;
1501
+ const visibleInsertAt = over.half === "before" ? targetWithoutSourceIndex : targetWithoutSourceIndex + 1;
1502
+ if (sourceIndex !== -1 && visibleInsertAt === sourceIndex) return;
1503
+ const accountSessionIds = activeDrag.accountKey === "" ? orderedUngroupedSessionIds : orderedWorkspaces.find((workspace) => workspace.workspaceId === activeDrag.accountKey)?.sessionIds;
1504
+ if (accountSessionIds === void 0) return;
1505
+ const nextOrder = accountSessionIds.filter((id) => id !== activeDrag.sessionId);
1506
+ let anchor;
1507
+ if (sessionsExpanded) anchor = over.half === "before" ? over.id : renderedSessions[targetIndex + 1]?.id;
1508
+ else {
1509
+ const previousVisible = withoutSource[visibleInsertAt - 1]?.id;
1510
+ if (previousVisible === void 0) anchor = nextOrder[0];
1511
+ else {
1512
+ const previousIndex = nextOrder.indexOf(previousVisible);
1513
+ if (previousIndex === -1) return;
1514
+ anchor = nextOrder[previousIndex + 1];
1515
+ }
1516
+ }
1517
+ const insertAt = anchor === void 0 ? nextOrder.length : nextOrder.indexOf(anchor);
1518
+ nextOrder.splice(insertAt === -1 ? nextOrder.length : insertAt, 0, activeDrag.sessionId);
1519
+ if (!sessionsExpanded && sourceIndex !== -1) {
1520
+ const nodes = new Map(group.sessions.map((node) => [node.id, node]));
1521
+ if (!collapsedSessionRows(nextOrder.flatMap((id) => {
1522
+ const node = nodes.get(id);
1523
+ return node === void 0 ? [] : [node];
1524
+ })).rows.some((node) => node.id === activeDrag.sessionId)) return;
1525
+ }
1526
+ setSessionOrder(activeDrag.accountKey, nextOrder.map((id) => id));
1527
+ if (orderBy === "updated" || activeDrag.accountKey === "") return;
1528
+ insertSessionBefore(activeDrag.accountKey, activeDrag.sessionId, anchor).catch((reason) => {
1529
+ console.warn("session reorder rejected:", reason);
1530
+ });
1531
+ };
1532
+ const commitWorkspaceDrag = (activeDrag, over) => {
1533
+ if (workspaceDropCommitted.current) return;
1534
+ workspaceDropCommitted.current = true;
1535
+ setWorkspaceDrag(null);
1536
+ const rowIndex = workspaces.findIndex((workspace) => workspace.workspaceId === over.id);
1537
+ if (rowIndex === -1) return;
1538
+ const anchor = over.half === "before" ? over.id : workspaces[rowIndex + 1]?.workspaceId;
1539
+ if (anchor === activeDrag.workspaceId) return;
1540
+ const sourceIndex = workspaces.findIndex((workspace) => workspace.workspaceId === activeDrag.workspaceId);
1541
+ const anchorIndex = anchor === void 0 ? workspaces.length : workspaces.findIndex((workspace) => workspace.workspaceId === anchor);
1542
+ if (sourceIndex !== -1 && (anchorIndex === sourceIndex || anchorIndex === sourceIndex + 1)) return;
1543
+ insertWorkspaceBefore(activeDrag.workspaceId, anchor).catch((reason) => {
1544
+ console.warn("workspace reorder rejected:", reason);
1545
+ });
1546
+ };
1547
+ const workspaceDropAtListStart = groups[0]?.workspaceId !== void 0 && workspaceDrag?.over?.id === groups[0].workspaceId && workspaceDrag.over.half === "before";
1548
+ return (0, react_jsx_runtime.jsxs)("div", {
1549
+ className: clsx(WorkspaceBrowser_module_css_default.treeBody, WorkspaceBrowser_module_css_default.wide),
1550
+ children: [
1551
+ workspaceDropAtListStart && (0, react_jsx_runtime.jsx)("span", {
1552
+ className: WorkspaceBrowser_module_css_default.listTopDropIndicator,
1553
+ "aria-hidden": "true"
1554
+ }),
1555
+ (0, react_jsx_runtime.jsxs)("div", {
1556
+ className: clsx(WorkspaceBrowser_module_css_default.list, workspaceDropAtListStart && WorkspaceBrowser_module_css_default.listTopDropActive),
1557
+ role: "tree",
1558
+ "aria-label": t("section.sessions"),
1559
+ children: [groups.length === 0 && (0, react_jsx_runtime.jsx)("div", {
1560
+ className: WorkspaceBrowser_module_css_default.empty,
1561
+ children: t("empty.none")
1562
+ }), groups.map((group) => {
1563
+ const workspaceId = group.workspaceId;
1564
+ const collapsed = collapsedSessionRows(group.sessions);
1565
+ const sessionsExpanded = expandedSessionGroups.includes(group.key);
1566
+ const workspaceMarker = workspaceId !== void 0 && workspaceDrag?.over?.id === workspaceId ? workspaceDrag.over.half : null;
1567
+ const workspaceDragProps = workspaceId === void 0 ? void 0 : {
1568
+ start: () => {
1569
+ workspaceDropCommitted.current = false;
1570
+ setWorkspaceDrag({
1571
+ workspaceId,
1572
+ over: null
1573
+ });
1574
+ },
1575
+ end: () => {
1576
+ if (workspaceDrag?.over !== null && workspaceDrag?.over !== void 0) commitWorkspaceDrag(workspaceDrag, workspaceDrag.over);
1577
+ else setWorkspaceDrag(null);
1578
+ workspaceDropCommitted.current = false;
1579
+ }
1580
+ };
1581
+ const hoverWorkspace = workspaceId === void 0 ? void 0 : (half) => {
1582
+ setWorkspaceDrag((active) => active === null ? active : {
1583
+ ...active,
1584
+ over: {
1585
+ id: workspaceId,
1586
+ half
1587
+ }
1588
+ });
1589
+ };
1590
+ const dropWorkspace = workspaceId === void 0 ? void 0 : (half) => {
1591
+ if (workspaceDrag === null) return;
1592
+ commitWorkspaceDrag(workspaceDrag, {
1593
+ id: workspaceId,
1594
+ half
1595
+ });
1596
+ };
1597
+ return (0, react_jsx_runtime.jsxs)("div", {
1598
+ className: clsx(WorkspaceBrowser_module_css_default.groupSection, workspaceMarker === "before" && WorkspaceBrowser_module_css_default.workspaceDropBefore, workspaceMarker === "after" && WorkspaceBrowser_module_css_default.workspaceDropAfter),
1599
+ onDragOver: workspaceDrag === null || hoverWorkspace === void 0 ? void 0 : (e) => {
1600
+ e.preventDefault();
1601
+ e.dataTransfer.dropEffect = "move";
1602
+ hoverWorkspace(workspaceGroupHalf(e));
1603
+ },
1604
+ onDrop: workspaceDrag === null || dropWorkspace === void 0 ? void 0 : (e) => {
1605
+ e.preventDefault();
1606
+ dropWorkspace(workspaceGroupHalf(e));
1607
+ },
1608
+ children: [
1609
+ (0, react_jsx_runtime.jsx)(ProjectRowItem, {
1610
+ group,
1611
+ home,
1612
+ t,
1613
+ onToggle: () => {
1614
+ if (group.expanded) setExpandedSessionGroups((keys) => keys.filter((key) => key !== group.key));
1615
+ setGroupExpanded(group.key, !group.expanded);
1616
+ },
1617
+ onCreate: () => {
1618
+ if (group.workspaceId !== void 0) {
1619
+ setGroupExpanded(group.key, true);
1620
+ startSession(group.workspaceId);
1621
+ }
1622
+ },
1623
+ drag: workspaceDragProps,
1624
+ actions: group.workspaceId === void 0 ? void 0 : {
1625
+ rename: () => {
1626
+ /* v8 ignore next -- narrowing guard: the actions object exists only for real-workspace groups. */
1627
+ if (group.workspaceId !== void 0) onRenameRequest(group.workspaceId, group.label);
1628
+ },
1629
+ delete: () => {
1630
+ /* v8 ignore next -- narrowing guard: the actions object exists only for real-workspace groups. */
1631
+ if (group.workspaceId !== void 0) onDeleteRequest(group.workspaceId, group.label);
1632
+ }
1633
+ }
1634
+ }),
1635
+ (sessionsExpanded ? group.sessions : collapsed.rows).map((node) => {
1636
+ const sameGroupDrag = drag !== null && drag.accountKey === group.key;
1637
+ return (0, react_jsx_runtime.jsx)(SessionNodeItem, {
1638
+ node,
1639
+ currentId: current,
1640
+ now,
1641
+ onOpen: open,
1642
+ onRename: onSessionRename,
1643
+ onFork: forkSession,
1644
+ onArchive: onSessionArchive,
1645
+ drag: {
1646
+ start: () => {
1647
+ sessionDropCommitted.current = false;
1648
+ setDrag({
1649
+ accountKey: group.key,
1650
+ sessionId: node.id,
1651
+ over: null
1652
+ });
1653
+ },
1654
+ active: sameGroupDrag,
1655
+ marker: sameGroupDrag && drag.over?.id === node.id ? drag.over.half : null,
1656
+ hover: (half) => {
1657
+ /* v8 ignore next -- narrowing guard: Rows gates hover on `active`, which is false while the drag state is null. */
1658
+ setDrag((d) => d === null ? d : {
1659
+ ...d,
1660
+ over: {
1661
+ id: node.id,
1662
+ half
1663
+ }
1664
+ });
1665
+ },
1666
+ drop: (half) => {
1667
+ /* v8 ignore next -- narrowing guard: Rows gates drop on `active`, which is false while the drag state is null. */
1668
+ if (drag === null) return;
1669
+ commitSessionDrag(drag, {
1670
+ id: node.id,
1671
+ half
1672
+ });
1673
+ },
1674
+ end: () => {
1675
+ if (drag?.over !== null && drag?.over !== void 0) commitSessionDrag(drag, drag.over);
1676
+ else setDrag(null);
1677
+ sessionDropCommitted.current = false;
1678
+ }
1679
+ },
1680
+ t
1681
+ }, node.id);
1682
+ }),
1683
+ collapsed.hiddenCount > 0 && (0, react_jsx_runtime.jsx)("button", {
1684
+ type: "button",
1685
+ className: WorkspaceBrowser_module_css_default.sessionOverflowButton,
1686
+ "aria-expanded": sessionsExpanded,
1687
+ onClick: () => {
1688
+ setExpandedSessionGroups((keys) => toggled(keys, group.key));
1689
+ },
1690
+ children: sessionsExpanded ? t("sessions.collapse") : t("sessions.expand", { n: collapsed.hiddenCount })
1691
+ })
1692
+ ]
1693
+ }, group.key);
1694
+ })]
1695
+ }),
1696
+ (0, react_jsx_runtime.jsx)("span", { className: WorkspaceBrowser_module_css_default.fade })
1697
+ ]
1698
+ });
1699
+ }
1700
+ /** The flat "In one list" body: every session is one draggable top-level row. */
1701
+ function FlatList({ useSessions, useSessionPendingInteraction, open, forkSession, onSessionRename, onSessionArchive, archivedSessionIds, orderBy, sessionOrderByAccount, sessionUpdatedAtByAccount, syncSessionOrderAccount, setSessionOrder, t }) {
1702
+ const list = useSessions((s) => s);
1703
+ const pendingInteractions = useSessionPendingInteraction((s) => s);
1704
+ const baseRows = (0, react.useMemo)(() => deriveFlat(list, archivedSessionIds, pendingInteractions), [
1705
+ list,
1706
+ archivedSessionIds,
1707
+ pendingInteractions
1708
+ ]);
1709
+ const sessionIds = (0, react.useMemo)(() => baseRows.map((row) => row.id), [baseRows]);
1710
+ const previousOrderBy = (0, react.useRef)(orderBy);
1711
+ (0, react.useEffect)(() => {
1712
+ if (list.phase !== "ready") return;
1713
+ const previousOrder = sessionOrderByAccount[FLAT_SESSION_ORDER_KEY];
1714
+ const previousUpdatedAt = sessionUpdatedAtByAccount["__flat_session_order__"] ?? {};
1715
+ const switchedToUpdated = previousOrderBy.current !== "updated" && orderBy === "updated";
1716
+ previousOrderBy.current = orderBy;
1717
+ const next = nextSessionOrderAccount({
1718
+ sessionIds,
1719
+ previousOrder,
1720
+ previousUpdatedAt,
1721
+ list,
1722
+ orderBy,
1723
+ sortByRecency: orderBy === "updated" && (previousOrder === void 0 || switchedToUpdated)
1724
+ });
1725
+ if (next.changed) syncSessionOrderAccount(FLAT_SESSION_ORDER_KEY, next.order.map((id) => id), next.updatedAt);
1726
+ }, [
1727
+ list,
1728
+ orderBy,
1729
+ sessionOrderByAccount,
1730
+ sessionUpdatedAtByAccount,
1731
+ sessionIds,
1732
+ syncSessionOrderAccount
1733
+ ]);
1734
+ const rows = (0, react.useMemo)(() => {
1735
+ const byId = new Map(baseRows.map((row) => [row.id, row]));
1736
+ return reconciledSessionOrder(sessionIds, sessionOrderByAccount[FLAT_SESSION_ORDER_KEY]).flatMap((id) => {
1737
+ const row = byId.get(id);
1738
+ return row === void 0 ? [] : [row];
1739
+ });
1740
+ }, [
1741
+ baseRows,
1742
+ sessionOrderByAccount,
1743
+ sessionIds
1744
+ ]);
1745
+ const [drag, setDrag] = (0, react.useState)(null);
1746
+ const dropCommitted = (0, react.useRef)(false);
1747
+ useNativeDragAcceptance(drag !== null);
1748
+ const commitDrag = (activeDrag, over) => {
1749
+ if (dropCommitted.current) return;
1750
+ dropCommitted.current = true;
1751
+ setDrag(null);
1752
+ const targetIndex = rows.findIndex((row) => row.id === over.id);
1753
+ if (targetIndex === -1) return;
1754
+ const anchor = over.half === "before" ? over.id : rows[targetIndex + 1]?.id;
1755
+ if (anchor === activeDrag.sessionId) return;
1756
+ const sourceIndex = rows.findIndex((row) => row.id === activeDrag.sessionId);
1757
+ const anchorIndex = anchor === void 0 ? rows.length : rows.findIndex((row) => row.id === anchor);
1758
+ if (sourceIndex !== -1 && (anchorIndex === sourceIndex || anchorIndex === sourceIndex + 1)) return;
1759
+ const nextOrder = rows.map((row) => row.id).filter((id) => id !== activeDrag.sessionId);
1760
+ const insertAt = anchor === void 0 ? nextOrder.length : nextOrder.indexOf(anchor);
1761
+ nextOrder.splice(insertAt === -1 ? nextOrder.length : insertAt, 0, activeDrag.sessionId);
1762
+ setSessionOrder(FLAT_SESSION_ORDER_KEY, nextOrder.map((id) => id));
1763
+ };
1764
+ const now = Date.now();
1765
+ return (0, react_jsx_runtime.jsxs)("div", {
1766
+ className: clsx(WorkspaceBrowser_module_css_default.treeBody, WorkspaceBrowser_module_css_default.wide),
1767
+ children: [(0, react_jsx_runtime.jsxs)("div", {
1768
+ className: clsx(WorkspaceBrowser_module_css_default.list, WorkspaceBrowser_module_css_default.flatList),
1769
+ role: "tree",
1770
+ "aria-label": t("section.sessions"),
1771
+ children: [rows.length === 0 && (0, react_jsx_runtime.jsx)("div", {
1772
+ className: WorkspaceBrowser_module_css_default.empty,
1773
+ children: t("empty.none")
1774
+ }), rows.map((node) => {
1775
+ const active = drag !== null;
1776
+ return (0, react_jsx_runtime.jsx)(SessionNodeItem, {
1777
+ node,
1778
+ currentId: list.current,
1779
+ now,
1780
+ onOpen: open,
1781
+ onRename: onSessionRename,
1782
+ onFork: forkSession,
1783
+ onArchive: onSessionArchive,
1784
+ flat: true,
1785
+ drag: {
1786
+ start: () => {
1787
+ dropCommitted.current = false;
1788
+ setDrag({
1789
+ accountKey: FLAT_SESSION_ORDER_KEY,
1790
+ sessionId: node.id,
1791
+ over: null
1792
+ });
1793
+ },
1794
+ active,
1795
+ marker: active && drag.over?.id === node.id ? drag.over.half : null,
1796
+ hover: (half) => {
1797
+ setDrag((current) => current === null ? current : {
1798
+ ...current,
1799
+ over: {
1800
+ id: node.id,
1801
+ half
1802
+ }
1803
+ });
1804
+ },
1805
+ drop: (half) => {
1806
+ if (drag !== null) commitDrag(drag, {
1807
+ id: node.id,
1808
+ half
1809
+ });
1810
+ },
1811
+ end: () => {
1812
+ if (drag?.over !== null && drag?.over !== void 0) commitDrag(drag, drag.over);
1813
+ else setDrag(null);
1814
+ dropCommitted.current = false;
1815
+ }
1816
+ },
1817
+ t
1818
+ }, node.id);
1819
+ })]
1820
+ }), (0, react_jsx_runtime.jsx)("span", { className: WorkspaceBrowser_module_css_default.fade })]
1821
+ });
1822
+ }
1823
+ /** Flat search body: local metadata matches plus the current Host result page. */
1824
+ function SearchResults({ useSessions, useSessionPendingInteraction, open, workspaces, archivedSessionIds, query, remote, resultLimit, t }) {
1825
+ const list = useSessions((s) => s);
1826
+ const pendingInteractions = useSessionPendingInteraction((s) => s);
1827
+ const currentRemote = remote.query === query ? remote : {
1828
+ query,
1829
+ status: "loading",
1830
+ items: [],
1831
+ hasMore: false
1832
+ };
1833
+ const results = (0, react.useMemo)(() => deriveSearchResults(list, workspaces, query, archivedSessionIds, pendingInteractions, currentRemote, resultLimit), [
1834
+ list,
1835
+ workspaces,
1836
+ query,
1837
+ archivedSessionIds,
1838
+ pendingInteractions,
1839
+ currentRemote,
1840
+ resultLimit
1841
+ ]);
1842
+ const pending = currentRemote.status === "loading";
1843
+ const failed = currentRemote.status === "error";
1844
+ return (0, react_jsx_runtime.jsxs)("div", {
1845
+ className: clsx(WorkspaceBrowser_module_css_default.treeBody, WorkspaceBrowser_module_css_default.wide),
1846
+ children: [(0, react_jsx_runtime.jsxs)("div", {
1847
+ className: WorkspaceBrowser_module_css_default.list,
1848
+ children: [
1849
+ (0, react_jsx_runtime.jsx)("div", {
1850
+ className: WorkspaceBrowser_module_css_default.searchTree,
1851
+ role: "tree",
1852
+ "aria-label": t("search.results.aria"),
1853
+ children: results.items.map((result) => (0, react_jsx_runtime.jsx)(SearchResultItem, {
1854
+ result,
1855
+ currentId: list.current,
1856
+ onOpen: open,
1857
+ t
1858
+ }, result.id))
1859
+ }),
1860
+ pending && (0, react_jsx_runtime.jsx)("div", {
1861
+ className: WorkspaceBrowser_module_css_default.searchStatus,
1862
+ role: "status",
1863
+ children: t("search.pending")
1864
+ }),
1865
+ failed && (0, react_jsx_runtime.jsx)("div", {
1866
+ className: WorkspaceBrowser_module_css_default.searchWarning,
1867
+ role: "status",
1868
+ children: t("search.unavailable")
1869
+ }),
1870
+ !pending && results.items.length === 0 && (0, react_jsx_runtime.jsx)("div", {
1871
+ className: WorkspaceBrowser_module_css_default.empty,
1872
+ children: t("search.noMatches")
1873
+ }),
1874
+ results.hasMore && (0, react_jsx_runtime.jsx)("div", {
1875
+ className: WorkspaceBrowser_module_css_default.searchStatus,
1876
+ children: t("search.hasMore", { n: resultLimit })
1877
+ })
1878
+ ]
1879
+ }), (0, react_jsx_runtime.jsx)("span", { className: WorkspaceBrowser_module_css_default.fade })]
1880
+ });
1881
+ }
1882
+ /**
1883
+ * Render the browsing region.
1884
+ * @param props - composed slot props (shell owner share + store + injected actions).
1885
+ * @returns the region element tree.
1886
+ */
1887
+ function WorkspaceBrowser({ wide, expandSidebar, useSessions, useSessionPendingInteraction, useWorkspaces, useStore, actions, startSession, open, renameSession, forkSession, renameWorkspace, deleteWorkspace, insertWorkspaceBefore, archiveSession, insertSessionBefore, createWorkspace, searchSessions, searchResultLimit, useDirectoryFlow, useConnectionGeneration, renderSlot, t }) {
1888
+ const home = useConnectionGeneration((generation) => generation?.host.home);
1889
+ const workspaces = useWorkspaces((state) => state.items);
1890
+ const workspacePhase = useWorkspaces((state) => state.phase);
1891
+ const archivedSessionIds = useWorkspaces((state) => state.archivedSessionIds);
1892
+ const directoryFlowAvailable = useDirectoryFlow((occupied) => occupied);
1893
+ const groupBy = useStore((s) => s.groupBy);
1894
+ const orderBy = useStore((s) => s.orderBy);
1895
+ const groupExpansion = useStore((s) => s.groupExpansion);
1896
+ const sessionOrderByAccount = useStore((s) => s.sessionOrderByAccount);
1897
+ const sessionUpdatedAtByAccount = useStore((s) => s.sessionUpdatedAtByAccount);
1898
+ const currentBlankSessionId = useSessions((state) => {
1899
+ const current = state.current;
1900
+ return current !== void 0 && state.byId[current]?.blank === true ? current : void 0;
1901
+ });
1902
+ const currentBlankAccount = currentBlankSessionId === void 0 ? void 0 : workspaces.find((workspace) => workspace.sessionIds.includes(currentBlankSessionId))?.workspaceId ?? "";
1903
+ const promotedBlank = (0, react.useRef)(void 0);
1904
+ (0, react.useEffect)(() => {
1905
+ if (currentBlankSessionId === void 0 || currentBlankAccount === void 0) {
1906
+ promotedBlank.current = void 0;
1907
+ return;
1908
+ }
1909
+ const promoted = promotedBlank.current;
1910
+ if (promoted !== void 0 && promoted.sessionId === currentBlankSessionId && promoted.accountKey === currentBlankAccount) return;
1911
+ promotedBlank.current = {
1912
+ sessionId: currentBlankSessionId,
1913
+ accountKey: currentBlankAccount
1914
+ };
1915
+ for (const accountKey of new Set([currentBlankAccount, FLAT_SESSION_ORDER_KEY])) {
1916
+ const previous = sessionOrderByAccount[accountKey] ?? [];
1917
+ actions.setSessionOrder(accountKey, [currentBlankSessionId, ...previous.filter((id) => id !== currentBlankSessionId)]);
1918
+ }
1919
+ }, [
1920
+ actions.setSessionOrder,
1921
+ currentBlankAccount,
1922
+ currentBlankSessionId,
1923
+ sessionOrderByAccount
1924
+ ]);
1925
+ (0, react.useEffect)(() => {
1926
+ if (workspacePhase !== "ready") return;
1927
+ actions.retainAccountKeys([
1928
+ "",
1929
+ FLAT_SESSION_ORDER_KEY,
1930
+ ...workspaces.map((workspace) => workspace.workspaceId)
1931
+ ]);
1932
+ }, [
1933
+ actions.retainAccountKeys,
1934
+ workspacePhase,
1935
+ workspaces
1936
+ ]);
1937
+ const [query, setQuery] = (0, react.useState)("");
1938
+ const [searchExpanded, setSearchExpanded] = (0, react.useState)(false);
1939
+ const normalizedQuery = sanitizeSearchQuery(query).trim();
1940
+ const [remoteSearch, setRemoteSearch] = (0, react.useState)({
1941
+ query: "",
1942
+ status: "idle",
1943
+ items: [],
1944
+ hasMore: false
1945
+ });
1946
+ const searchRoot = (0, react.useRef)(null);
1947
+ const searchInput = (0, react.useRef)(null);
1948
+ const [wsPickerOpen, setWsPickerOpen] = (0, react.useState)(false);
1949
+ const wsPlusRef = (0, react.useRef)(null);
1950
+ const composingRef = (0, react.useRef)(false);
1951
+ const [searchOnExpand, setSearchOnExpand] = (0, react.useState)(false);
1952
+ (0, react.useEffect)(() => {
1953
+ if (wide && searchOnExpand) {
1954
+ const timer = window.setTimeout(() => {
1955
+ searchInput.current?.focus({ preventScroll: true });
1956
+ setSearchOnExpand(false);
1957
+ }, EXPAND_SLIDE_MS);
1958
+ return () => {
1959
+ window.clearTimeout(timer);
1960
+ };
1961
+ }
1962
+ }, [wide, searchOnExpand]);
1963
+ (0, react.useEffect)(() => {
1964
+ if (!wide || !searchExpanded || searchOnExpand) return;
1965
+ searchInput.current?.focus({ preventScroll: true });
1966
+ }, [
1967
+ wide,
1968
+ searchExpanded,
1969
+ searchOnExpand
1970
+ ]);
1971
+ (0, react.useEffect)(() => {
1972
+ if (!wide || !searchExpanded || searchOnExpand) return;
1973
+ const onClick = (event) => {
1974
+ if (!(event.target instanceof Node) || searchRoot.current?.contains(event.target) === true) return;
1975
+ searchInput.current?.blur();
1976
+ if (normalizedQuery !== "") return;
1977
+ setSearchExpanded(false);
1978
+ };
1979
+ document.addEventListener("click", onClick);
1980
+ return () => {
1981
+ document.removeEventListener("click", onClick);
1982
+ };
1983
+ }, [
1984
+ normalizedQuery,
1985
+ wide,
1986
+ searchExpanded,
1987
+ searchOnExpand
1988
+ ]);
1989
+ (0, react.useEffect)(() => {
1990
+ if (normalizedQuery === "") {
1991
+ setRemoteSearch({
1992
+ query: "",
1993
+ status: "idle",
1994
+ items: [],
1995
+ hasMore: false
1996
+ });
1997
+ return;
1998
+ }
1999
+ const controller = new AbortController();
2000
+ setRemoteSearch({
2001
+ query: normalizedQuery,
2002
+ status: "loading",
2003
+ items: [],
2004
+ hasMore: false
2005
+ });
2006
+ const timer = window.setTimeout(() => {
2007
+ searchSessions(normalizedQuery, controller.signal).then((result) => {
2008
+ if (controller.signal.aborted) return;
2009
+ setRemoteSearch({
2010
+ query: normalizedQuery,
2011
+ status: "ready",
2012
+ items: result.items,
2013
+ hasMore: result.hasMore
2014
+ });
2015
+ }).catch(() => {
2016
+ if (controller.signal.aborted) return;
2017
+ setRemoteSearch({
2018
+ query: normalizedQuery,
2019
+ status: "error",
2020
+ items: [],
2021
+ hasMore: false
2022
+ });
2023
+ });
2024
+ }, SEARCH_DEBOUNCE_MS);
2025
+ return () => {
2026
+ window.clearTimeout(timer);
2027
+ controller.abort();
2028
+ };
2029
+ }, [normalizedQuery, searchSessions]);
2030
+ const [renameTarget, setRenameTarget] = (0, react.useState)(null);
2031
+ const [renameDraft, setRenameDraft] = (0, react.useState)("");
2032
+ const [renaming, setRenaming] = (0, react.useState)(false);
2033
+ const [renameError, setRenameError] = (0, react.useState)(null);
2034
+ const renameTrimmed = renameDraft.trim();
2035
+ const renameDuplicate = renameTarget !== null && renameTrimmed !== "" && renameTrimmed !== renameTarget.currentTitle && workspaces.some((w) => w.title === renameTrimmed);
2036
+ const renameBlocked = renaming || renameTrimmed === "" || renameTarget === null || renameTrimmed === renameTarget.currentTitle || renameDuplicate;
2037
+ const closeRename = () => {
2038
+ if (renaming) return;
2039
+ setRenameTarget(null);
2040
+ setRenameError(null);
2041
+ };
2042
+ const confirmRename = () => {
2043
+ if (renameBlocked) return;
2044
+ setRenaming(true);
2045
+ setRenameError(null);
2046
+ renameWorkspace(renameTarget.workspaceId, renameTrimmed).then(() => {
2047
+ setRenaming(false);
2048
+ setRenameTarget(null);
2049
+ }).catch((reason) => {
2050
+ setRenaming(false);
2051
+ setRenameError(reason instanceof Error ? reason.message : String(reason));
2052
+ });
2053
+ };
2054
+ const [sessionRenameTarget, setSessionRenameTarget] = (0, react.useState)(null);
2055
+ const [sessionRenameDraft, setSessionRenameDraft] = (0, react.useState)("");
2056
+ const [sessionRenaming, setSessionRenaming] = (0, react.useState)(false);
2057
+ const [sessionRenameError, setSessionRenameError] = (0, react.useState)(null);
2058
+ const sessionRenameTrimmed = sessionRenameDraft.trim();
2059
+ const sessionRenameBlocked = sessionRenaming || sessionRenameTrimmed === "" || sessionRenameTarget === null;
2060
+ const closeSessionRename = () => {
2061
+ if (sessionRenaming) return;
2062
+ setSessionRenameTarget(null);
2063
+ setSessionRenameError(null);
2064
+ };
2065
+ const confirmSessionRename = () => {
2066
+ if (sessionRenameBlocked) return;
2067
+ setSessionRenaming(true);
2068
+ setSessionRenameError(null);
2069
+ renameSession(sessionRenameTarget.sessionId, sessionRenameTrimmed).then(() => {
2070
+ setSessionRenaming(false);
2071
+ setSessionRenameTarget(null);
2072
+ }).catch((reason) => {
2073
+ setSessionRenaming(false);
2074
+ setSessionRenameError(reason instanceof Error ? reason.message : String(reason));
2075
+ });
2076
+ };
2077
+ const onSessionRename = (sessionId, currentTitle) => {
2078
+ setSessionRenameTarget({
2079
+ sessionId,
2080
+ currentTitle
2081
+ });
2082
+ setSessionRenameDraft(currentTitle);
2083
+ setSessionRenameError(null);
2084
+ };
2085
+ const onSessionArchive = (sessionId) => {
2086
+ archiveSession(sessionId).catch((reason) => {
2087
+ console.warn("session archive rejected:", reason);
2088
+ });
2089
+ };
2090
+ const [deleteTarget, setDeleteTarget] = (0, react.useState)(null);
2091
+ const [deleting, setDeleting] = (0, react.useState)(false);
2092
+ const [deleteCommittedId, setDeleteCommittedId] = (0, react.useState)(null);
2093
+ const [deleteError, setDeleteError] = (0, react.useState)(null);
2094
+ (0, react.useEffect)(() => {
2095
+ if (deleteCommittedId === null || workspaces.some((workspace) => workspace.workspaceId === deleteCommittedId)) return;
2096
+ setDeleting(false);
2097
+ setDeleteCommittedId(null);
2098
+ setDeleteTarget(null);
2099
+ }, [deleteCommittedId, workspaces]);
2100
+ const closeDelete = () => {
2101
+ if (deleting) return;
2102
+ setDeleteTarget(null);
2103
+ setDeleteError(null);
2104
+ };
2105
+ const confirmDelete = () => {
2106
+ /* v8 ignore next -- the Modal is absent without a target and its button is disabled while deleting. */
2107
+ if (deleting || deleteTarget === null) return;
2108
+ setDeleting(true);
2109
+ setDeleteCommittedId(null);
2110
+ setDeleteError(null);
2111
+ deleteWorkspace(deleteTarget.workspaceId).then(() => {
2112
+ setDeleteCommittedId(deleteTarget.workspaceId);
2113
+ }).catch((reason) => {
2114
+ setDeleting(false);
2115
+ setDeleteError(reason instanceof Error ? reason.message : String(reason));
2116
+ });
2117
+ };
2118
+ return (0, react_jsx_runtime.jsxs)("div", {
2119
+ className: clsx(WorkspaceBrowser_module_css_default.root, !wide && WorkspaceBrowser_module_css_default.rail),
2120
+ children: [
2121
+ (0, react_jsx_runtime.jsxs)("div", {
2122
+ className: WorkspaceBrowser_module_css_default.sectionHeader,
2123
+ children: [
2124
+ wide && (0, react_jsx_runtime.jsx)("span", {
2125
+ className: clsx(WorkspaceBrowser_module_css_default.sectionLabel, WorkspaceBrowser_module_css_default.wide, searchExpanded && WorkspaceBrowser_module_css_default.sectionLabelHidden),
2126
+ children: groupBy === "flat" ? t("section.sessions") : t("section.workspaces")
2127
+ }),
2128
+ wide && (0, react_jsx_runtime.jsx)("div", {
2129
+ className: clsx(WorkspaceBrowser_module_css_default.searchSlot, searchExpanded && WorkspaceBrowser_module_css_default.searchSlotExpanded),
2130
+ children: (0, react_jsx_runtime.jsxs)("div", {
2131
+ ref: searchRoot,
2132
+ className: clsx(WorkspaceBrowser_module_css_default.search, searchExpanded && WorkspaceBrowser_module_css_default.searchExpanded),
2133
+ onClick: () => {
2134
+ setWsPickerOpen(false);
2135
+ setSearchExpanded(true);
2136
+ searchInput.current?.focus();
2137
+ },
2138
+ children: [
2139
+ (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Tooltip, {
2140
+ label: t("search"),
2141
+ side: "bottom",
2142
+ delayMs: 500,
2143
+ disabled: searchExpanded,
2144
+ children: (0, react_jsx_runtime.jsx)("button", {
2145
+ type: "button",
2146
+ className: WorkspaceBrowser_module_css_default.searchButton,
2147
+ "aria-label": t("search.sessions.aria"),
2148
+ "aria-expanded": searchExpanded,
2149
+ onClick: () => {
2150
+ setWsPickerOpen(false);
2151
+ setSearchExpanded(true);
2152
+ },
2153
+ children: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconSearchOutline16, { size: searchExpanded ? 11 : 14 })
2154
+ })
2155
+ }),
2156
+ (0, react_jsx_runtime.jsx)("input", {
2157
+ ref: searchInput,
2158
+ className: WorkspaceBrowser_module_css_default.searchInput,
2159
+ type: "text",
2160
+ placeholder: t("search.placeholder"),
2161
+ maxLength: SEARCH_QUERY_MAX_CODE_UNITS,
2162
+ value: query,
2163
+ tabIndex: searchExpanded ? 0 : -1,
2164
+ onChange: (e) => {
2165
+ setQuery(sanitizeSearchQuery(e.target.value));
2166
+ },
2167
+ onKeyDown: (e) => {
2168
+ if (e.key !== "Escape") return;
2169
+ setQuery("");
2170
+ setSearchExpanded(false);
2171
+ }
2172
+ }),
2173
+ searchExpanded && (0, react_jsx_runtime.jsx)("button", {
2174
+ type: "button",
2175
+ className: WorkspaceBrowser_module_css_default.clearButton,
2176
+ "aria-label": t("search.clear"),
2177
+ onClick: (e) => {
2178
+ e.stopPropagation();
2179
+ setQuery("");
2180
+ setSearchExpanded(false);
2181
+ },
2182
+ children: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconCloseFill14, {})
2183
+ })
2184
+ ]
2185
+ })
2186
+ }),
2187
+ (0, react_jsx_runtime.jsxs)("div", {
2188
+ className: clsx(WorkspaceBrowser_module_css_default.headerActions, wide && searchExpanded && WorkspaceBrowser_module_css_default.headerActionsHidden),
2189
+ children: [wide && (0, react_jsx_runtime.jsx)(ViewOptionsMenu, {
2190
+ groupBy,
2191
+ orderBy,
2192
+ onGroupPick: (mode) => {
2193
+ actions.setGroupBy(mode);
2194
+ },
2195
+ onOrderPick: (mode) => {
2196
+ actions.setOrderBy(mode);
2197
+ },
2198
+ t
2199
+ }), directoryFlowAvailable && (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Tooltip, {
2200
+ label: t("workspace.add"),
2201
+ side: "bottom",
2202
+ delayMs: 500,
2203
+ children: (0, react_jsx_runtime.jsx)("button", {
2204
+ ref: wsPlusRef,
2205
+ type: "button",
2206
+ className: WorkspaceBrowser_module_css_default.iconButton,
2207
+ "aria-label": t("workspace.add"),
2208
+ onClick: () => {
2209
+ setWsPickerOpen((v) => !v);
2210
+ },
2211
+ children: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconProjectAddOutline16, { size: wide ? 16 : 18 })
2212
+ })
2213
+ })]
2214
+ }),
2215
+ (0, react_jsx_runtime.jsx)(WorkspacePickFlow, {
2216
+ t,
2217
+ open: wsPickerOpen,
2218
+ anchorRef: wsPlusRef,
2219
+ useWorkspaces,
2220
+ createWorkspace,
2221
+ useDirectoryFlow,
2222
+ renderDirectoryFlow: (owner) => renderSlot("sidebar.workspaces.directoryFlow", owner),
2223
+ addOnly: true,
2224
+ side: "right",
2225
+ onPick: (workspaceId) => {
2226
+ setWsPickerOpen(false);
2227
+ startSession(workspaceId);
2228
+ },
2229
+ onClose: () => {
2230
+ setWsPickerOpen(false);
2231
+ }
2232
+ })
2233
+ ]
2234
+ }),
2235
+ !wide && (0, react_jsx_runtime.jsx)("div", {
2236
+ className: WorkspaceBrowser_module_css_default.search,
2237
+ children: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Tooltip, {
2238
+ label: t("search"),
2239
+ children: (0, react_jsx_runtime.jsx)("button", {
2240
+ type: "button",
2241
+ className: WorkspaceBrowser_module_css_default.searchButton,
2242
+ "aria-label": t("search.sessions.aria"),
2243
+ onClick: () => {
2244
+ setSearchExpanded(true);
2245
+ setSearchOnExpand(true);
2246
+ expandSidebar();
2247
+ },
2248
+ children: (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.IconSearchOutline16, { size: 18 })
2249
+ })
2250
+ })
2251
+ }),
2252
+ (0, react_jsx_runtime.jsx)("div", {
2253
+ className: WorkspaceBrowser_module_css_default.listArea,
2254
+ children: wide && (normalizedQuery !== "" ? (0, react_jsx_runtime.jsx)(SearchResults, {
2255
+ useSessions,
2256
+ useSessionPendingInteraction,
2257
+ open,
2258
+ workspaces,
2259
+ archivedSessionIds,
2260
+ query: normalizedQuery,
2261
+ remote: remoteSearch,
2262
+ resultLimit: searchResultLimit,
2263
+ t
2264
+ }) : groupBy === "flat" ? (0, react_jsx_runtime.jsx)(FlatList, {
2265
+ useSessions,
2266
+ useSessionPendingInteraction,
2267
+ open,
2268
+ forkSession,
2269
+ onSessionRename,
2270
+ onSessionArchive,
2271
+ archivedSessionIds,
2272
+ orderBy,
2273
+ sessionOrderByAccount,
2274
+ sessionUpdatedAtByAccount,
2275
+ syncSessionOrderAccount: actions.syncSessionOrderAccount,
2276
+ setSessionOrder: actions.setSessionOrder,
2277
+ t
2278
+ }) : (0, react_jsx_runtime.jsx)(SessionTree, {
2279
+ useSessions,
2280
+ useSessionPendingInteraction,
2281
+ onSessionRename,
2282
+ onSessionArchive,
2283
+ forkSession,
2284
+ workspaces,
2285
+ groupExpansion,
2286
+ setGroupExpanded: actions.setGroupExpanded,
2287
+ sessionOrderByAccount,
2288
+ sessionUpdatedAtByAccount,
2289
+ syncSessionOrderAccount: actions.syncSessionOrderAccount,
2290
+ setSessionOrder: actions.setSessionOrder,
2291
+ archivedSessionIds,
2292
+ startSession,
2293
+ open,
2294
+ insertWorkspaceBefore,
2295
+ insertSessionBefore,
2296
+ orderBy,
2297
+ home,
2298
+ t,
2299
+ onRenameRequest: (workspaceId, currentTitle) => {
2300
+ setRenameTarget({
2301
+ workspaceId,
2302
+ currentTitle
2303
+ });
2304
+ setRenameDraft(currentTitle);
2305
+ setRenameError(null);
2306
+ },
2307
+ onDeleteRequest: (workspaceId, title) => {
2308
+ setDeleteTarget({
2309
+ workspaceId,
2310
+ title
2311
+ });
2312
+ setDeleteError(null);
2313
+ }
2314
+ }))
2315
+ }),
2316
+ (0, react_jsx_runtime.jsxs)(_prettier_ai_dsh_client_ui_primitives.Modal, {
2317
+ open: renameTarget !== null,
2318
+ onClose: closeRename,
2319
+ closeLabel: t("close"),
2320
+ title: t("rename.workspace.title"),
2321
+ footer: (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Button, {
2322
+ variant: "outline",
2323
+ disabled: renaming,
2324
+ onClick: closeRename,
2325
+ children: t("cancel")
2326
+ }), (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Button, {
2327
+ variant: "primary",
2328
+ disabled: renameBlocked,
2329
+ onClick: confirmRename,
2330
+ children: t("rename")
2331
+ })] }),
2332
+ children: [
2333
+ (0, react_jsx_runtime.jsx)("input", {
2334
+ className: WorkspaceBrowser_module_css_default.renameInput,
2335
+ value: renameDraft,
2336
+ "aria-label": t("field.workspaceName"),
2337
+ autoFocus: true,
2338
+ disabled: renaming,
2339
+ onFocus: (e) => {
2340
+ e.target.select();
2341
+ },
2342
+ onChange: (e) => {
2343
+ setRenameDraft(e.target.value);
2344
+ setRenameError(null);
2345
+ },
2346
+ onCompositionStart: () => {
2347
+ composingRef.current = true;
2348
+ },
2349
+ onCompositionEnd: () => {
2350
+ composingRef.current = false;
2351
+ },
2352
+ onKeyDown: (e) => {
2353
+ if (e.key === "Enter" && !composingRef.current) {
2354
+ e.preventDefault();
2355
+ confirmRename();
2356
+ }
2357
+ }
2358
+ }),
2359
+ renameDuplicate && (0, react_jsx_runtime.jsx)("div", {
2360
+ className: WorkspaceBrowser_module_css_default.renameError,
2361
+ role: "alert",
2362
+ children: t("conflict.named", { name: renameTrimmed })
2363
+ }),
2364
+ renameError !== null && (0, react_jsx_runtime.jsx)("div", {
2365
+ className: WorkspaceBrowser_module_css_default.renameError,
2366
+ role: "alert",
2367
+ children: renameError
2368
+ })
2369
+ ]
2370
+ }),
2371
+ (0, react_jsx_runtime.jsxs)(_prettier_ai_dsh_client_ui_primitives.Modal, {
2372
+ open: sessionRenameTarget !== null,
2373
+ onClose: closeSessionRename,
2374
+ closeLabel: t("close"),
2375
+ title: t("rename.session.title"),
2376
+ footer: (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Button, {
2377
+ variant: "outline",
2378
+ disabled: sessionRenaming,
2379
+ onClick: closeSessionRename,
2380
+ children: t("cancel")
2381
+ }), (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Button, {
2382
+ variant: "primary",
2383
+ disabled: sessionRenameBlocked,
2384
+ onClick: confirmSessionRename,
2385
+ children: t("rename")
2386
+ })] }),
2387
+ children: [(0, react_jsx_runtime.jsx)("input", {
2388
+ className: WorkspaceBrowser_module_css_default.renameInput,
2389
+ value: sessionRenameDraft,
2390
+ "aria-label": t("field.sessionName"),
2391
+ autoFocus: true,
2392
+ disabled: sessionRenaming,
2393
+ onFocus: (e) => {
2394
+ e.target.select();
2395
+ },
2396
+ onChange: (e) => {
2397
+ setSessionRenameDraft(e.target.value);
2398
+ setSessionRenameError(null);
2399
+ },
2400
+ onCompositionStart: () => {
2401
+ composingRef.current = true;
2402
+ },
2403
+ onCompositionEnd: () => {
2404
+ composingRef.current = false;
2405
+ },
2406
+ onKeyDown: (e) => {
2407
+ if (e.key === "Enter" && !composingRef.current) {
2408
+ e.preventDefault();
2409
+ confirmSessionRename();
2410
+ }
2411
+ }
2412
+ }), sessionRenameError !== null && (0, react_jsx_runtime.jsx)("div", {
2413
+ className: WorkspaceBrowser_module_css_default.renameError,
2414
+ role: "alert",
2415
+ children: sessionRenameError
2416
+ })]
2417
+ }),
2418
+ (0, react_jsx_runtime.jsxs)(_prettier_ai_dsh_client_ui_primitives.Modal, {
2419
+ open: deleteTarget !== null,
2420
+ onClose: closeDelete,
2421
+ closeLabel: t("close"),
2422
+ title: t("delete.workspace"),
2423
+ ...deleteTarget === null ? {} : { description: t("delete.desc", { name: deleteTarget.title }) },
2424
+ footer: (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Button, {
2425
+ variant: "outline",
2426
+ disabled: deleting,
2427
+ onClick: closeDelete,
2428
+ children: t("cancel")
2429
+ }), (0, react_jsx_runtime.jsx)(_prettier_ai_dsh_client_ui_primitives.Button, {
2430
+ variant: "outline",
2431
+ className: WorkspaceBrowser_module_css_default.deleteAction,
2432
+ disabled: deleting,
2433
+ onClick: confirmDelete,
2434
+ children: t("delete.workspace")
2435
+ })] }),
2436
+ children: [deleting && (0, react_jsx_runtime.jsx)("div", {
2437
+ className: WorkspaceBrowser_module_css_default.deleteStatus,
2438
+ role: "status",
2439
+ children: t("delete.pending")
2440
+ }), deleteError !== null && (0, react_jsx_runtime.jsx)("div", {
2441
+ className: WorkspaceBrowser_module_css_default.renameError,
2442
+ role: "alert",
2443
+ children: deleteError
2444
+ })]
2445
+ })
2446
+ ]
2447
+ });
2448
+ }
2449
+ //#endregion
2450
+ //#region lib/types/client/locales.js
2451
+ /**
2452
+ * `workspace` namespace dictionaries: the browsing region (section header,
2453
+ * search, tree rows, dialogs) and the pick/add flow. Runtime failure
2454
+ * messages (wire error strings) pass through untranslated by policy.
2455
+ */
2456
+ /** Simplified Chinese dictionary (the key-set source of truth). */
2457
+ const zh = {
2458
+ "group.ungrouped": "未分组",
2459
+ "session.new": "新会话",
2460
+ "section.workspaces": "工作区",
2461
+ "section.sessions": "会话",
2462
+ "viewOptions.label": "视图选项",
2463
+ "groupBy.label": "分组方式",
2464
+ "groupBy.workspace": "按工作区",
2465
+ "groupBy.flat": "单列表",
2466
+ "orderBy.label": "排序方式",
2467
+ "orderBy.manual": "手动排序",
2468
+ "orderBy.updated": "最近更新",
2469
+ "sessions.expand": "展开其余 {n} 个会话",
2470
+ "sessions.collapse": "收起",
2471
+ "empty.none": "暂无会话",
2472
+ "empty.noMatches": "无匹配结果",
2473
+ "workspace.add": "添加工作区",
2474
+ "search.sessions.aria": "搜索会话",
2475
+ "search.placeholder": "搜索会话…",
2476
+ "search.clear": "清除搜索",
2477
+ "search.results.aria": "搜索结果",
2478
+ "search.pending": "正在搜索会话历史…",
2479
+ "search.unavailable": "内容搜索暂不可用,仅显示名称匹配。",
2480
+ "search.noMatches": "无匹配会话",
2481
+ "search.hasMore": "仅显示前 {n} 条结果,请缩小搜索范围。",
2482
+ "menu.addWorkspace": "添加工作区…",
2483
+ "picker.loading": "正在加载工作区…",
2484
+ "conflict.named": "已存在名为“{name}”的工作区。",
2485
+ "folderError.title": "无法打开文件夹",
2486
+ "folderError.retry": "重新选择",
2487
+ "rename": "重命名",
2488
+ "rename.workspace.title": "重命名工作区",
2489
+ "rename.session.title": "重命名会话",
2490
+ "field.workspaceName": "工作区名称",
2491
+ "field.sessionName": "会话名称",
2492
+ "delete.workspace": "删除工作区",
2493
+ "delete.desc": "将把“{name}”从工作区列表中移除。文件夹与会话记录会保留,其会话将显示在“未分组”下。",
2494
+ "delete.pending": "正在删除工作区…",
2495
+ "menu.fork": "分叉会话",
2496
+ "menu.archiveSession": "归档会话",
2497
+ "sessions.count.one": "{n} 个会话",
2498
+ "sessions.count.other": "{n} 个会话",
2499
+ "actions.workspace.aria": "工作区“{name}”的操作",
2500
+ "actions.session.aria": "会话“{name}”的操作",
2501
+ "actions.newSession.aria": "在“{name}”中新建会话",
2502
+ "status.running": "进行中",
2503
+ "status.subagentsRunning.one": "{n} 个子代理运行中",
2504
+ "status.subagentsRunning.other": "{n} 个子代理运行中",
2505
+ "status.idle": "空闲",
2506
+ "status.waitingApproval": "等待审批",
2507
+ "status.planReview": "计划待审",
2508
+ "status.waitingAnswer": "等待回答",
2509
+ "status.completed": "已完成",
2510
+ "hover.created": "创建于 {time}",
2511
+ "hover.copied": "已复制",
2512
+ "date.ymd": "{y}年{m}月{d}日",
2513
+ "time.now": "刚刚",
2514
+ "time.minutes": "{n}分钟",
2515
+ "time.hours": "{n}小时",
2516
+ "time.days": "{n}天",
2517
+ "time.months": "{n}个月",
2518
+ "time.years": "{n}年",
2519
+ "time.ago": "{t}前"
2520
+ };
2521
+ /** English dictionary, checked complete against the zh key set. */
2522
+ const en = {
2523
+ "group.ungrouped": "Ungrouped",
2524
+ "session.new": "New Session",
2525
+ "section.workspaces": "Workspaces",
2526
+ "section.sessions": "Sessions",
2527
+ "viewOptions.label": "View options",
2528
+ "groupBy.label": "Group by",
2529
+ "groupBy.workspace": "WorkSpace",
2530
+ "groupBy.flat": "In one list",
2531
+ "orderBy.label": "Order by",
2532
+ "orderBy.manual": "Manual",
2533
+ "orderBy.updated": "Last updated",
2534
+ "sessions.expand": "Show {n} more sessions",
2535
+ "sessions.collapse": "Show less",
2536
+ "empty.none": "No sessions yet",
2537
+ "empty.noMatches": "No matches",
2538
+ "workspace.add": "Add workspace",
2539
+ "search.sessions.aria": "Search sessions",
2540
+ "search.placeholder": "Search sessions...",
2541
+ "search.clear": "Clear search",
2542
+ "search.results.aria": "Search results",
2543
+ "search.pending": "Searching session history…",
2544
+ "search.unavailable": "Content search is temporarily unavailable. Showing name matches.",
2545
+ "search.noMatches": "No matching sessions",
2546
+ "search.hasMore": "Showing the first {n} results. Narrow your search.",
2547
+ "menu.addWorkspace": "Add workspace…",
2548
+ "picker.loading": "Loading workspaces…",
2549
+ "conflict.named": "A workspace named “{name}” already exists.",
2550
+ "folderError.title": "Couldn’t open folder",
2551
+ "folderError.retry": "Choose again",
2552
+ "rename": "Rename",
2553
+ "rename.workspace.title": "Rename workspace",
2554
+ "rename.session.title": "Rename session",
2555
+ "field.workspaceName": "Workspace name",
2556
+ "field.sessionName": "Session name",
2557
+ "delete.workspace": "Delete workspace",
2558
+ "delete.desc": "This removes “{name}” from the workspace list. The folder and session logs will be kept. Its sessions will appear under Ungrouped.",
2559
+ "delete.pending": "Deleting workspace…",
2560
+ "menu.fork": "Fork session",
2561
+ "menu.archiveSession": "Archive session",
2562
+ "sessions.count.one": "{n} session",
2563
+ "sessions.count.other": "{n} sessions",
2564
+ "actions.workspace.aria": "Workspace actions for {name}",
2565
+ "actions.session.aria": "Session actions for {name}",
2566
+ "actions.newSession.aria": "New session in {name}",
2567
+ "status.running": "Running",
2568
+ "status.subagentsRunning.one": "{n} subagent running",
2569
+ "status.subagentsRunning.other": "{n} subagents running",
2570
+ "status.idle": "Idle",
2571
+ "status.waitingApproval": "Waiting for approval",
2572
+ "status.planReview": "Plan awaiting review",
2573
+ "status.waitingAnswer": "Waiting for answer",
2574
+ "status.completed": "Completed",
2575
+ "hover.created": "Created {time}",
2576
+ "hover.copied": "Copied",
2577
+ "date.ymd": "{y}-{m}-{d}",
2578
+ "time.now": "now",
2579
+ "time.minutes": "{n}min",
2580
+ "time.hours": "{n}h",
2581
+ "time.days": "{n}d",
2582
+ "time.months": "{n}mo",
2583
+ "time.years": "{n}y",
2584
+ "time.ago": "{t} ago"
2585
+ };
2586
+ //#endregion
2587
+ //#region lib/types/client/index.js
2588
+ /** Dictionary namespace owned by this plugin. */
2589
+ const NS = "workspace";
2590
+ /**
2591
+ * Required services (cordis fiber inject). The target slots are declared by
2592
+ * the ui-sidebar / ui-conversation applies, whose activation order relative
2593
+ * to this one is NOT constrained: dsh.client.inject edges are informational
2594
+ * (loading/prefetch metadata, never apply sequencing) and neither owner
2595
+ * provides a waitable service. apply therefore depends on each slot
2596
+ * declaration through `slots.inject()` instead of assuming order.
2597
+ */
2598
+ const inject = [
2599
+ "slots",
2600
+ "sessions",
2601
+ "workspaces",
2602
+ "locale",
2603
+ "connection",
2604
+ "remote",
2605
+ "remote.directoryPicker"
2606
+ ];
2607
+ /**
2608
+ * Register the browser and picker once their slot declarations are on the
2609
+ * ledger. Inject factories return plain callbacks; data reads use the
2610
+ * framework's global hooks.
2611
+ * @param ctx - client root context.
2612
+ */
2613
+ function apply(ctx) {
2614
+ const connection = ctx.get("connection");
2615
+ const sessions = ctx.get("sessions");
2616
+ const workspaces = ctx.get("workspaces");
2617
+ const connectionGeneration = connection.generation;
2618
+ const uiWorkspace = new UiWorkspaceService(ctx, ctx.remote.directoryPicker, workspaces, sessions);
2619
+ ctx.slots.provideRoot({ hooks: { workspaces: workspaces.list } });
2620
+ ctx.effect(() => ctx.locale.register(NS, {
2621
+ zh,
2622
+ en
2623
+ }), "ui-workspace: dictionaries");
2624
+ const searchSessions = async (query, signal) => {
2625
+ const result = await sessions.search(query, signal);
2626
+ if (!result.ok) throw new Error(result.error.message);
2627
+ return result.value;
2628
+ };
2629
+ const flowSource = (hole) => ({
2630
+ getSnapshot: () => ctx.slots.entries(hole).length > 0,
2631
+ subscribe: (listener) => ctx.slots.subscribe(hole, listener)
2632
+ });
2633
+ const browserFlowSource = flowSource("sidebar.workspaces.directoryFlow");
2634
+ const pickerFlowSource = flowSource("conversation.hero.workspace.directoryFlow");
2635
+ const browserInjected = () => ({
2636
+ startSession: (workspaceId) => {
2637
+ uiWorkspace.startSession(workspaceId);
2638
+ },
2639
+ open: (sessionId) => {
2640
+ sessions.open(sessionId);
2641
+ },
2642
+ searchSessions,
2643
+ searchResultLimit: sessions.searchResultLimit,
2644
+ renameSession: async (sessionId, title) => {
2645
+ const session = sessions.binding(sessionId)?.session;
2646
+ if (session === void 0) throw new Error(`unknown session "${sessionId}"`);
2647
+ const result = await session.rename(title);
2648
+ if (!result.ok) throw new Error(result.error.message);
2649
+ },
2650
+ forkSession: (sessionId) => {
2651
+ sessions.fork({
2652
+ sessionId,
2653
+ increaseTitle: true
2654
+ }).then((childId) => {
2655
+ sessions.open(childId);
2656
+ }).catch(() => {});
2657
+ },
2658
+ renameWorkspace: async (workspaceId, title) => {
2659
+ await workspaces.rename(workspaceId, title);
2660
+ },
2661
+ deleteWorkspace: async (workspaceId) => {
2662
+ await workspaces.delete(workspaceId);
2663
+ },
2664
+ insertWorkspaceBefore: async (workspaceId, beforeWorkspaceId) => {
2665
+ await workspaces.insertBefore(workspaceId, beforeWorkspaceId);
2666
+ },
2667
+ archiveSession: async (sessionId) => {
2668
+ await uiWorkspace.archiveSession(sessionId);
2669
+ },
2670
+ insertSessionBefore: async (workspaceId, sessionId, beforeSessionId) => {
2671
+ await workspaces.insertSessionBefore(workspaceId, sessionId, beforeSessionId);
2672
+ },
2673
+ createWorkspace: (input) => workspaces.create(input),
2674
+ hooks: {
2675
+ directoryFlow: browserFlowSource,
2676
+ connectionGeneration
2677
+ }
2678
+ });
2679
+ const pickerInjected = () => ({
2680
+ createWorkspace: (input) => workspaces.create(input),
2681
+ hooks: { directoryFlow: pickerFlowSource }
2682
+ });
2683
+ ctx.slots.inject("sidebar.workspaces", () => ctx.slots.register({
2684
+ name: "sidebar.workspaces",
2685
+ children: { "sidebar.workspaces.directoryFlow": {
2686
+ kind: "single",
2687
+ scope: "root"
2688
+ } },
2689
+ store: createWorkspaceViewStore(),
2690
+ inject: browserInjected,
2691
+ locale: NS
2692
+ }, WorkspaceBrowser));
2693
+ ctx.slots.inject("conversation.hero.workspace", () => ctx.slots.register({
2694
+ name: "conversation.hero.workspace",
2695
+ children: { "conversation.hero.workspace.directoryFlow": {
2696
+ kind: "single",
2697
+ scope: "root"
2698
+ } },
2699
+ inject: pickerInjected,
2700
+ locale: NS
2701
+ }, WorkspacePicker));
2702
+ }
2703
+ //#endregion
2704
+ exports.apply = apply;
2705
+ exports.inject = inject;
2706
+ return module.exports;
2707
+ }
2708
+ });
2709
+
2710
+ //# sourceMappingURL=client.js.map