@klarkxy/dsh-session-manager 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1819 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
3
+ let react = require("react");
4
+ let react_jsx_runtime = require("react/jsx-runtime");
5
+ //#region src/contracts.ts
6
+ const COPY_THREAD_MENU_ID = "@klarkxy/dsh-session-manager.copy-thread-id";
7
+ const COPY_THREAD_SHORTCUT_ID = "session-manager.copy-thread-id";
8
+ const TEMP_WORKSPACE_CHANNEL = "/dsh-session-manager";
9
+ const TEMP_WORKSPACE_FLOW_SLOT = "session-manager.workspace.directoryFlow";
10
+ const USER_ACTIONS_SLOT = "conversation.chat.user-actions";
11
+ const USER_ACTIONS_ID = "@klarkxy/dsh-session-manager.user-actions";
12
+ const DELETE_DIALOG_ID = "@klarkxy/dsh-session-manager.delete-chat";
13
+ //#endregion
14
+ //#region src/copy-action.ts
15
+ const COPY_THREAD_LABEL = {
16
+ zh: "复制线程 ID",
17
+ en: "Copy thread ID"
18
+ };
19
+ const COPY_THREAD_FAILED = {
20
+ zh: "无法复制线程 ID",
21
+ en: "Could not copy the thread ID"
22
+ };
23
+ const COPY_THREAD_COPIED = {
24
+ zh: "已复制线程 ID",
25
+ en: "Thread ID copied"
26
+ };
27
+ const COPY_THREAD_NO_SESSION = {
28
+ zh: "请先打开一个会话",
29
+ en: "Open a session first"
30
+ };
31
+ function copyLocale(active) {
32
+ return active?.toLowerCase().startsWith("zh") ? "zh" : "en";
33
+ }
34
+ /** Copy one session id. Rejection stays with the caller so the menu can show it. */
35
+ async function copyThreadId(sessionId, writeText) {
36
+ await writeText(sessionId);
37
+ }
38
+ //#endregion
39
+ //#region src/copy-shortcut.tsx
40
+ async function writeClipboard(value) {
41
+ const clipboard = globalThis.navigator?.clipboard;
42
+ if (clipboard === void 0) throw new Error("clipboard unavailable");
43
+ await clipboard.writeText(value);
44
+ }
45
+ /** Uses the same mainView reference as ui-workspace/src/client/shortcuts.ts.
46
+ * The host registry owns key dispatch, remapping, conflicts, IME and repeat guards.
47
+ */
48
+ function CopyThreadShortcutNotice({ shortcuts, list, locale, currentLocale, writeText = writeClipboard }) {
49
+ const [notice, setNotice] = (0, react.useState)(null);
50
+ const sequence = (0, react.useRef)(0);
51
+ (0, react.useEffect)(() => {
52
+ if (shortcuts === void 0) return;
53
+ let active = true;
54
+ const notify = (copied) => {
55
+ if (active) setNotice({
56
+ copied,
57
+ seq: ++sequence.current
58
+ });
59
+ };
60
+ const binding = {
61
+ code: "KeyC",
62
+ modifiers: ["primary", "alt"]
63
+ };
64
+ const stop = shortcuts.register({
65
+ id: COPY_THREAD_SHORTCUT_ID,
66
+ label: () => COPY_THREAD_LABEL[copyLocale(currentLocale())],
67
+ aliases: [
68
+ "copy thread id",
69
+ "copy session id",
70
+ "复制线程 ID"
71
+ ],
72
+ defaults: {
73
+ "desktop:windows": binding,
74
+ "desktop:macos": binding,
75
+ "web:windows": binding,
76
+ "web:macos": binding
77
+ },
78
+ regions: ["page", "editable"],
79
+ modals: [],
80
+ resolve(context) {
81
+ const target = Object.values(list?.getSnapshot().byId ?? {}).find((row) => (row?.retainedBy?.mainView ?? 0) > 0);
82
+ if (target === void 0 || context.modal !== null || context.region === "terminal") return {
83
+ status: "blocked",
84
+ reason: COPY_THREAD_NO_SESSION[copyLocale(currentLocale())]
85
+ };
86
+ return {
87
+ status: "handled",
88
+ run() {
89
+ copyThreadId(target.id, writeText).then(() => notify(true), () => notify(false));
90
+ }
91
+ };
92
+ }
93
+ });
94
+ return () => {
95
+ active = false;
96
+ stop();
97
+ };
98
+ }, [
99
+ shortcuts,
100
+ list,
101
+ currentLocale,
102
+ writeText
103
+ ]);
104
+ return notice === null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Toast, {
105
+ text: (notice.copied ? COPY_THREAD_COPIED : COPY_THREAD_FAILED)[locale],
106
+ tone: notice.copied ? "success" : void 0,
107
+ onDone: () => setNotice(null)
108
+ }, notice.seq);
109
+ }
110
+ //#endregion
111
+ //#region src/context-menu.ts
112
+ /**
113
+ * Right-click forwarding for the sidebar browser: a `contextmenu` gesture on a
114
+ * session or workspace row clicks that row's native "..." trigger, so the
115
+ * host's own menu — including every `sidebar.workspaces.session.menu.item`
116
+ * slot contribution, this plugin's rows included — opens exactly as a
117
+ * left-click on the trigger would. The host owns the menu; this module only
118
+ * relays the gesture. No host code registers a contextmenu listener, so the
119
+ * capture-phase relay does not fight an existing handler.
120
+ *
121
+ * DOM contract (dsh-client-ui-workspace 0.2.0-rc.2, lib/client.js):
122
+ * - Rows are `div[role="treeitem"][data-row-key="session:<id>"]` or
123
+ * `data-row-key="workspace:<id>"` inside `div[role="tree"]`. Overflow and
124
+ * empty rows carry other prefixes, search rows carry no `data-row-key`, and
125
+ * AnimatedRows exit clones have the attribute removed — all are ignored by
126
+ * the prefix match. (client.js:1287, 1590-1596, 1729, 1842-1846)
127
+ * - The trigger is the first `button[type="button"]` inside the row's trailing
128
+ * `span` whose CSS-module class ends in `_rowActions`. It stays mounted —
129
+ * CSS `display:none` until hover or menu-open — so a programmatic click
130
+ * toggles the menu. Blank new-session rows and the ungrouped bucket render
131
+ * no trigger; right-click does nothing there. (client.js:1061, 1314-1340,
132
+ * 1640-1660)
133
+ * - Class names carry a per-build hash prefix and the trigger's aria-label is
134
+ * localized; only `data-row-key` and the structural suffix are stable.
135
+ * - The opened menu portals to `document.body`, outside the tree, so a
136
+ * right-click on a menu row never re-enters this relay.
137
+ */
138
+ const ROW_SELECTOR = "[data-row-key^=\"session:\"], [data-row-key^=\"workspace:\"]";
139
+ const TRIGGER_SELECTOR = "span[class*=\"rowActions\"] button[type=\"button\"]";
140
+ /** Resolve the native "..." trigger of the row containing `target`, if any. */
141
+ function findRowMenuTrigger(target) {
142
+ if (typeof target.closest !== "function") return null;
143
+ const row = target.closest(ROW_SELECTOR);
144
+ if (row === null || row.closest("[role=\"tree\"]") === null) return null;
145
+ const trigger = row.querySelector(TRIGGER_SELECTOR);
146
+ if (trigger === null || typeof trigger.click !== "function") return null;
147
+ return trigger;
148
+ }
149
+ /**
150
+ * Forward one `contextmenu` event to the row's native menu trigger.
151
+ * Returns true when the gesture was relayed (and the default suppressed).
152
+ */
153
+ function forwardContextMenu(event) {
154
+ const target = event.target;
155
+ if (target === null || typeof target.closest !== "function") return false;
156
+ const trigger = findRowMenuTrigger(target);
157
+ if (trigger === null) return false;
158
+ event.preventDefault();
159
+ trigger.click();
160
+ return true;
161
+ }
162
+ /** Capture-phase relay on the document; the returned disposer uninstalls it. */
163
+ function installContextMenuForwarding(doc) {
164
+ const listener = (event) => {
165
+ forwardContextMenu(event);
166
+ };
167
+ doc.addEventListener("contextmenu", listener, true);
168
+ return () => {
169
+ doc.removeEventListener("contextmenu", listener, true);
170
+ };
171
+ }
172
+ Object.values({
173
+ /** Surfaces, from the page up to the topmost nested card. */
174
+ surface: [
175
+ "--dsw-alias-bg-base",
176
+ "--dsw-alias-bg-layer-1",
177
+ "--dsw-alias-bg-layer-2",
178
+ "--dsw-alias-bg-layer-3",
179
+ "--dsw-alias-bg-layer-4",
180
+ "--dsw-alias-bg-module-platform",
181
+ "--dsw-alias-bg-overlay"
182
+ ],
183
+ /** Hairlines. l1 is near-invisible on a menu surface, so menus use l2+. */
184
+ border: [
185
+ "--dsw-alias-border-l1",
186
+ "--dsw-alias-border-l2",
187
+ "--dsw-alias-border-l3",
188
+ "--dsw-alias-border-l4"
189
+ ],
190
+ /** Text. `caption` is menu shortcut text, `dimmed` is placeholder text. */
191
+ label: [
192
+ "--dsw-alias-label-primary",
193
+ "--dsw-alias-label-secondary",
194
+ "--dsw-alias-label-tertiary",
195
+ "--dsw-alias-label-caption",
196
+ "--dsw-alias-label-dimmed",
197
+ "--dsw-alias-label-error",
198
+ "--dsw-alias-label-primary-foreground"
199
+ ],
200
+ /** Interactive fills. The `-danger` hover belongs to destructive rows. */
201
+ interactive: [
202
+ "--dsw-alias-interactive-bg-hover",
203
+ "--dsw-alias-interactive-bg-active",
204
+ "--dsw-alias-interactive-bg-hover-danger"
205
+ ],
206
+ /** Accent and status. `business` is the focus ring's default colour. */
207
+ accent: [
208
+ "--dsw-alias-brand-primary",
209
+ "--dsw-alias-button-primary-fill",
210
+ "--dsw-alias-button-primary-hover",
211
+ "--dsw-alias-button-tool-bar-fill",
212
+ "--dsw-alias-button-tool-bar-hover",
213
+ "--dsw-alias-button-ghost-active-fill",
214
+ "--dsw-alias-button-ghost-active-border"
215
+ ],
216
+ state: [
217
+ "--dsw-alias-state-business-primary",
218
+ "--dsw-alias-state-success-primary",
219
+ "--dsw-alias-state-warn-primary",
220
+ "--dsw-alias-state-error-primary",
221
+ "--dsw-alias-state-idle-primary"
222
+ ],
223
+ /** Corner scale: sm 8, md 12, lg the large card, panel the modal. */
224
+ radius: [
225
+ "--dsw-radius-sm",
226
+ "--dsw-radius-md",
227
+ "--dsw-radius-lg",
228
+ "--dsw-radius-panel"
229
+ ],
230
+ /** An elevated surface draws its edge in the shadow, so it keeps border: 0. */
231
+ elevation: [
232
+ "--dsw-elevation-soft",
233
+ "--dsw-elevation-stroke",
234
+ "--dsw-elevation-stroke-color",
235
+ "--dsw-elevation-panel",
236
+ "--dsw-elevation-prominent"
237
+ ],
238
+ /** Floats, masks and scrollbars. */
239
+ overlay: [
240
+ "--dsw-menu-surface-fill",
241
+ "--dsw-menu-backdrop-filter",
242
+ "--dsw-mask-blur",
243
+ "--dsw-alias-bg-mask-1",
244
+ "--dsw-alias-menu-icon",
245
+ "--dsw-alias-scrollbar-bg-l2",
246
+ "--dsw-alias-scrollbar-hover-l2",
247
+ "--dsw-shadow-lv3"
248
+ ],
249
+ /** Motion, focus and type axis, published by the host rather than by a component. */
250
+ system: [
251
+ "--dsw-focus-ring-width",
252
+ "--dsw-focus-ring-color",
253
+ "--dsw-font-markdown-code-font-family",
254
+ "--ds-transition-duration",
255
+ "--ds-ease-in-out",
256
+ "--ds-font-family-code",
257
+ "--dsh-scrollbar-thumb",
258
+ "--dsh-scrollbar-thumb-hover",
259
+ "--dsh-content-font-size-secondary",
260
+ "--dsh-content-font-delta",
261
+ "--dsh-frame-top-clearance"
262
+ ]
263
+ }).flat();
264
+ /**
265
+ * The host's focus ring shorthand, verbatim. Writing this per control is how
266
+ * rings drift apart; a stylesheet that draws its own focus style should use
267
+ * {@link officialFocus} instead. The colour fallback is the host's own default.
268
+ */
269
+ const OFFICIAL_FOCUS_RING = "var(--dsw-focus-ring-width) solid var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary))";
270
+ /**
271
+ * A complete `outline` declaration at the official geometry. `offset` defaults
272
+ * to the 2px the native controls use; the host's inline field rules sit at 1px
273
+ * and a segmented tab pulls the ring inside itself at -2px.
274
+ */
275
+ function officialFocus(offset = "2px") {
276
+ return `outline: ${OFFICIAL_FOCUS_RING}; outline-offset: ${offset}`;
277
+ }
278
+ /**
279
+ * An elevated surface. The host draws a raised surface's edge inside its
280
+ * shadow rather than as a border, so a card sets `border: 0` and takes the edge
281
+ * from the elevation — which is also why its border stays off the alias-border
282
+ * set that a flat, non-elevated rule would use.
283
+ */
284
+ function officialElevation(level) {
285
+ return `border: 0; box-shadow: var(--dsw-elevation-${level})`;
286
+ }
287
+ /**
288
+ * The shared stylesheet for a plugin UI, scoped under that plugin's root class.
289
+ *
290
+ * Scoping is what keeps this safe to always-bundle into every client: the rules
291
+ * can only match inside the plugin's own subtree, so two plugins can both mount
292
+ * `dsh-ui-card` without either styling the other's markup.
293
+ *
294
+ * Each recipe matches the root element *and* its descendants, because the
295
+ * commonest arrangement is one element that is both — a surface that carries
296
+ * the root class and `dsh-ui-card`, or a portaled dialog that is the root and
297
+ * the `dsh-ui-surface`. A descendant-only scope would silently leave those
298
+ * unstyled, with no error anywhere.
299
+ *
300
+ * A caveat worth knowing: `Modal` and `Menu` portal to `document.body`, so their
301
+ * content leaves the plugin's subtree entirely. A portaled surface therefore
302
+ * needs its own root class on an element inside the portal.
303
+ *
304
+ * Only patterns that primitives do not provide live here. If a control appears
305
+ * below that `Button`/`Input`/`Switch`/`Tag`/`Menu` already covers, that is a
306
+ * bug in this file: use the primitive and delete the recipe.
307
+ */
308
+ function officialUiCss(roots) {
309
+ const scope = (typeof roots === "string" ? [roots] : roots).map((root) => `.${root}`).join(", ");
310
+ return `
311
+ /* Official DSH Web UI contract. Generated by @klarkxy/dsh-plugin-kit/official-ui.
312
+ * Do not hand-edit the copy inside a plugin: change this module so every plugin
313
+ * moves together. Scope: ${scope} */
314
+ /* The scope rule below stays open for the whole sheet: every rule after it
315
+ * nests with the parent selector, so one stylesheet can cover several unrelated
316
+ * roots without leaking into a neighbouring plugin. Its closing brace is last. */
317
+ ${scope} {
318
+ color: var(--dsw-alias-label-primary);
319
+ font-family: inherit;
320
+ font-size: 14px;
321
+ line-height: 22px;
322
+ min-width: 0;
323
+
324
+ & *, & *::before, & *::after { box-sizing: border-box; }
325
+ & h1, & h2, & h3, & h4, & p, & figure { margin: 0; }
326
+ /* Keyboard focus only: pointer input keeps the native resting appearance. The
327
+ * ring needs no radius of its own — the outline already follows the control's
328
+ * own border-radius, and overriding it here would flatten every control. */
329
+ & :focus-visible { ${officialFocus()}; }
330
+ & [hidden] { display: none !important; }
331
+
332
+ /* --- Type tiers. The same 14/22 and 13/20 steps the primitives use. --- */
333
+ & .dsh-ui-title { font-size: 16px; line-height: 24px; font-weight: 500; color: var(--dsw-alias-label-primary); }
334
+ & .dsh-ui-heading { font-size: 14px; line-height: 22px; font-weight: 500; color: var(--dsw-alias-label-primary); }
335
+ & .dsh-ui-compact { font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-primary); }
336
+ & .dsh-ui-meta { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-secondary); }
337
+ & .dsh-ui-hint { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); }
338
+ & .dsh-ui-error { font-size: 12px; line-height: 18px; color: var(--dsw-alias-state-error-primary); }
339
+ & .dsh-ui-warn { color: var(--dsw-alias-state-warn-primary); }
340
+ & .dsh-ui-success { color: var(--dsw-alias-state-success-primary); }
341
+ & .dsh-ui-muted { color: var(--dsw-alias-label-tertiary); }
342
+ & .dsh-ui-truncate { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
343
+ & .dsh-ui-wrap { min-width: 0; overflow-wrap: anywhere; }
344
+
345
+ /* --- Layout scaffolding. --- */
346
+ & .dsh-ui-stack { display: flex; flex-direction: column; gap: 12px; }
347
+ & .dsh-ui-stack-lg { display: flex; flex-direction: column; gap: 20px; }
348
+ & .dsh-ui-row { display: flex; align-items: center; gap: 8px; min-width: 0; }
349
+ & .dsh-ui-row-wrap { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
350
+ & .dsh-ui-spacer { flex: 1; min-width: 0; }
351
+ /* A 0.5px l2 rule is the host's section divider; reserve the same rhythm. */
352
+ & .dsh-ui-divider { height: 0.5px; background: var(--dsw-alias-border-l2); }
353
+ & .dsh-ui-section { display: flex; flex-direction: column; gap: 12px; padding-top: 16px; border-top: 0.5px solid var(--dsw-alias-border-l2); }
354
+
355
+ /* --- Card: a raised surface whose edge lives in the shadow. --- */
356
+ & .dsh-ui-card {
357
+ ${officialElevation("stroke")}
358
+ display: flex;
359
+ flex-direction: column;
360
+ gap: 12px;
361
+ padding: 16px;
362
+ border-radius: var(--dsw-radius-lg);
363
+ background: var(--dsw-alias-bg-layer-1);
364
+ color: var(--dsw-alias-label-primary);
365
+ min-width: 0;
366
+ }
367
+ & .dsh-ui-card--flat { border: 0.5px solid var(--dsw-alias-border-l3); box-shadow: none; }
368
+ & .dsh-ui-card--nested { background: var(--dsw-alias-bg-layer-2); }
369
+ & .dsh-ui-card--plain { background: none; }
370
+
371
+ /* --- Field: label, control, help, error. The control itself is an
372
+ * official primitive, so this only owns the vertical rhythm. --- */
373
+ & .dsh-ui-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
374
+ & .dsh-ui-field + .dsh-ui-field { border-top: 0.5px solid var(--dsw-alias-border-l2); padding-top: 12px; }
375
+ & .dsh-ui-label { display: flex; align-items: center; gap: 6px; font-size: 13px; line-height: 20px; font-weight: 500; color: var(--dsw-alias-label-primary); }
376
+ & .dsh-ui-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
377
+ & .dsh-ui-help { font-size: 12px; line-height: 1.6; color: var(--dsw-alias-label-secondary); }
378
+ & .dsh-ui-help p { margin: 0; }
379
+ & .dsh-ui-help p + p { margin-top: 8px; }
380
+ & .dsh-ui-required { color: var(--dsw-alias-state-error-primary); }
381
+ & .dsh-ui-control { width: 100%; min-width: 0; }
382
+ /* An invalid control is marked on the control, not only in the message. */
383
+ & .dsh-ui-control[aria-invalid='true'] { border-color: var(--dsw-alias-state-error-primary); }
384
+ & .dsh-ui-readonly { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
385
+ & .dsh-ui-readonly > dt { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); }
386
+ & .dsh-ui-readonly > dd { margin: 0; font-size: 13px; line-height: 20px; overflow-wrap: anywhere; }
387
+
388
+ /* --- Buttons row. A no-op container: it exists so actions line up on the
389
+ * trailing edge the way every native panel does. --- */
390
+ & .dsh-ui-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 4px; }
391
+ & .dsh-ui-actions-end { justify-content: flex-end; }
392
+
393
+ /* --- Banners. A banner is a left-rail notice, the shape used for warnings,
394
+ * deprecations and blocking instructions. --- */
395
+ & .dsh-ui-banner {
396
+ display: flex;
397
+ flex-direction: column;
398
+ gap: 8px;
399
+ padding: 10px 14px;
400
+ border: 0.5px solid var(--dsw-alias-border-l3);
401
+ border-left: 3px solid var(--dsw-alias-state-warn-primary);
402
+ border-radius: var(--dsw-radius-md);
403
+ background: var(--dsw-alias-bg-layer-1);
404
+ font-size: 13px;
405
+ line-height: 20px;
406
+ color: var(--dsw-alias-label-secondary);
407
+ }
408
+ & .dsh-ui-banner-title { font-weight: 500; color: var(--dsw-alias-state-warn-primary); }
409
+ & .dsh-ui-banner--info { border-left-color: var(--dsw-alias-state-business-primary); }
410
+ & .dsh-ui-banner--danger { border-left-color: var(--dsw-alias-state-error-primary); }
411
+ & .dsh-ui-banner--success { border-left-color: var(--dsw-alias-state-success-primary); }
412
+ & .dsh-ui-banner p { margin: 0; }
413
+
414
+ /* --- Inline notice: a transient confirmation with no chrome of its own. --- */
415
+ & .dsh-ui-notice { display: flex; align-items: center; gap: 6px; font-size: 12px; line-height: 18px; color: var(--dsw-alias-state-success-primary); }
416
+ & .dsh-ui-notice--error { color: var(--dsw-alias-state-error-primary); }
417
+
418
+ /* --- Empty and loading states. Both sit in a dashed well so an empty panel
419
+ * reads as "nothing here yet" rather than as a broken layout. --- */
420
+ & .dsh-ui-empty {
421
+ display: flex;
422
+ flex-direction: column;
423
+ align-items: flex-start;
424
+ gap: 6px;
425
+ padding: 20px 16px;
426
+ border: 0.5px dashed var(--dsw-alias-border-l3);
427
+ border-radius: var(--dsw-radius-md);
428
+ font-size: 13px;
429
+ line-height: 20px;
430
+ color: var(--dsw-alias-label-secondary);
431
+ }
432
+ & .dsh-ui-loading { display: flex; align-items: center; gap: 8px; padding: 20px 0; font-size: 13px; line-height: 20px; color: var(--dsw-alias-label-secondary); }
433
+
434
+ /* --- Selectable list. A row is a button-sized target with a hover fill and
435
+ * a selected fill; the name carries the weight, the description does not. --- */
436
+ & .dsh-ui-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
437
+ & .dsh-ui-list-scroll { max-height: min(66vh, 760px); overflow-y: auto; overflow-x: hidden; }
438
+ & .dsh-ui-list-row { border-radius: var(--dsw-radius-md); }
439
+ & .dsh-ui-list-row:hover { background: var(--dsw-alias-interactive-bg-hover); }
440
+ & .dsh-ui-list-row[aria-selected='true'], & .dsh-ui-list-row[data-selected] { background: var(--dsw-alias-interactive-bg-active); }
441
+ & .dsh-ui-list-item {
442
+ display: flex;
443
+ flex-direction: column;
444
+ align-items: flex-start;
445
+ gap: 4px;
446
+ width: 100%;
447
+ min-width: 0;
448
+ padding: 10px 12px;
449
+ border: 0;
450
+ border-radius: var(--dsw-radius-md);
451
+ background: none;
452
+ font: inherit;
453
+ color: inherit;
454
+ text-align: start;
455
+ cursor: pointer;
456
+ }
457
+ & .dsh-ui-list-item:disabled { cursor: default; }
458
+ & .dsh-ui-list-item:disabled:hover { background: none; }
459
+ & .dsh-ui-list-name { font-size: 14px; line-height: 22px; font-weight: 500; color: var(--dsw-alias-label-primary); overflow-wrap: anywhere; }
460
+ & .dsh-ui-list-desc { font-size: 12px; line-height: 18px; color: var(--dsw-alias-label-tertiary); }
461
+
462
+ /* --- Code and structured output. Wraps rather than scrolls, because a
463
+ * feature panel is read rather than scanned. --- */
464
+ & .dsh-ui-code {
465
+ padding: 10px 12px;
466
+ border: 0.5px solid var(--dsw-alias-border-l3);
467
+ border-radius: var(--dsw-radius-md);
468
+ background: var(--dsw-alias-bg-layer-1);
469
+ font-family: var(--ds-font-family-code);
470
+ font-size: 12px;
471
+ line-height: 20px;
472
+ color: var(--dsw-alias-label-secondary);
473
+ overflow-wrap: anywhere;
474
+ white-space: pre-wrap;
475
+ }
476
+ & .dsh-ui-scroll { max-height: 60vh; overflow: auto; overscroll-behavior: contain; }
477
+
478
+ /* --- A toggle row: label on the left, switch on the trailing edge. This is
479
+ * layout only; the switch itself is the official primitive. --- */
480
+ & .dsh-ui-toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-width: 0; padding: 12px 0; }
481
+ & .dsh-ui-toggle-row + .dsh-ui-toggle-row { border-top: 0.5px solid var(--dsw-alias-border-l2); }
482
+ & .dsh-ui-toggle-text { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
483
+ & .dsh-ui-toggle-label { font-size: 14px; line-height: 22px; font-weight: 500; color: var(--dsw-alias-label-primary); }
484
+
485
+ /* --- Floating surface: a panel anchored to a trigger. This is the material
486
+ * a menu card is made of — the translucent fill plus its backdrop blur, with
487
+ * the edge riding inside the prominent elevation. A plugin that hand-rolls this
488
+ * is how tokens like --dsw-specific-menu get invented; use this instead. --- */
489
+ & .dsh-ui-surface {
490
+ --dsw-elevation-stroke-color: var(--dsw-alias-border-l1);
491
+ --dsh-scrollbar-thumb: var(--dsw-alias-scrollbar-bg-l2);
492
+ --dsh-scrollbar-thumb-hover: var(--dsw-alias-scrollbar-hover-l2);
493
+ position: relative;
494
+ display: flex;
495
+ flex-direction: column;
496
+ border: 0;
497
+ border-radius: var(--dsw-radius-lg);
498
+ background: var(--dsw-menu-surface-fill);
499
+ backdrop-filter: var(--dsw-menu-backdrop-filter);
500
+ box-shadow: var(--dsw-elevation-prominent);
501
+ color: var(--dsw-alias-label-primary);
502
+ font-size: 13px;
503
+ line-height: 20px;
504
+ min-width: 0;
505
+ }
506
+ & .dsh-ui-surface-body { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px 14px; overflow-y: auto; }
507
+ & .dsh-ui-surface-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
508
+ & .dsh-ui-surface-title { font-size: 14px; line-height: 22px; font-weight: 500; color: var(--dsw-alias-label-primary); }
509
+
510
+ /* --- Native select. The primitives ship no select, so a plugin that offers a
511
+ * closed list of choices keeps the platform control and matches the official
512
+ * settings field geometry exactly (34px, 0.5px l4, radius-md, layer-3). A
513
+ * SegmentedControl is the primitive to reach for when the choices are few
514
+ * enough to show at once. --- */
515
+ & .dsh-ui-select {
516
+ box-sizing: border-box;
517
+ width: 100%;
518
+ min-width: 0;
519
+ height: 34px;
520
+ padding: 0 12px;
521
+ border: 0.5px solid var(--dsw-alias-border-l4);
522
+ border-radius: var(--dsw-radius-md);
523
+ background: var(--dsw-alias-bg-layer-3);
524
+ font: inherit;
525
+ font-size: 13px;
526
+ line-height: 1.5;
527
+ color: var(--dsw-alias-label-primary);
528
+ cursor: pointer;
529
+ }
530
+ & .dsh-ui-select:focus-visible { outline: none; border-color: var(--dsw-alias-state-business-primary); }
531
+ & .dsh-ui-select:disabled { color: var(--dsw-alias-label-tertiary); cursor: default; }
532
+ & .dsh-ui-select[aria-invalid='true'] { border-color: var(--dsw-alias-state-error-primary); }
533
+
534
+ /* Long panels scroll inside themselves instead of growing the host page. */
535
+ & .dsh-ui-panel { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
536
+ & .dsh-ui-panel-wide { max-width: 100%; }
537
+
538
+ @media (prefers-reduced-motion: reduce) {
539
+ & *, & *::before, & *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
540
+ }
541
+ }
542
+ `.replace(/^& (\.dsh-ui-[a-z0-9-]+)(?![+>~])/gm, (_match, className) => `&${className}, & ${className}`);
543
+ }
544
+ //#endregion
545
+ //#region src/styles.ts
546
+ const FREE_CHAT_ROOT = "dsh-free-chat";
547
+ /** Host tokens and official scaffolding. Only the edit draft, the inline action row,
548
+ * and the alert line survive the panel removal; the modals reuse the root class. */
549
+ const freeChatCss = `${officialUiCss(FREE_CHAT_ROOT)}
550
+ .${FREE_CHAT_ROOT} .dsh-free-draft {
551
+ box-sizing: border-box;
552
+ width: 100%;
553
+ min-height: 8em;
554
+ padding: 8px 12px;
555
+ border: 0.5px solid var(--dsw-alias-border-l4);
556
+ border-radius: var(--dsw-radius-md);
557
+ background: var(--dsw-alias-bg-layer-3);
558
+ color: var(--dsw-alias-label-primary);
559
+ font: inherit;
560
+ font-size: 14px;
561
+ line-height: 22px;
562
+ resize: vertical;
563
+ }
564
+ .${FREE_CHAT_ROOT} .dsh-free-actions {
565
+ display: inline-flex;
566
+ align-items: center;
567
+ gap: 4px;
568
+ min-width: 0;
569
+ }
570
+ .${FREE_CHAT_ROOT} .dsh-free-alert { margin: 0; }
571
+ `;
572
+ //#endregion
573
+ //#region src/ui-copy.ts
574
+ const reasons = {
575
+ zh: {
576
+ modified: "后续操作可能涉及修改,暂时不能重试。",
577
+ unknown: "无法确认这个操作的结果。",
578
+ pending: "这条消息还在等待处理。",
579
+ stale: "这个聊天已经更新,请再试一次。",
580
+ running: "这个聊天仍在运行。请等待当前工作结束后再试。",
581
+ cleanup: "清理没有完成。",
582
+ unsupported: "当前版本不能完成这个操作。"
583
+ },
584
+ en: {
585
+ modified: "Later operations may have made changes. Retry is unavailable.",
586
+ unknown: "This action's result could not be confirmed.",
587
+ pending: "This message is still pending.",
588
+ stale: "This chat has changed. Try again.",
589
+ running: "This chat is still running. Wait for the current work to finish, then try again.",
590
+ cleanup: "Cleanup did not finish.",
591
+ unsupported: "This runtime cannot complete that action."
592
+ }
593
+ };
594
+ const text = {
595
+ zh: {
596
+ tempWorkspace: "临时工作区",
597
+ createFailed: "无法创建临时工作区",
598
+ retryList: "重试",
599
+ deleteChat: "删除聊天",
600
+ deleting: "正在删除",
601
+ deleteFree: "将删除这个聊天及其拥有的文件。",
602
+ deleteOrdinary: "将删除这个聊天。项目文件会保留。",
603
+ cancel: "取消",
604
+ close: "关闭",
605
+ retry: "重试",
606
+ edit: "编辑并重发",
607
+ send: "发送",
608
+ editTitle: "编辑并重发",
609
+ draft: "消息文本"
610
+ },
611
+ en: {
612
+ tempWorkspace: "Temporary Workspace",
613
+ createFailed: "Could not create the temporary workspace",
614
+ retryList: "Retry",
615
+ deleteChat: "Delete chat",
616
+ deleting: "Deleting",
617
+ deleteFree: "This deletes this chat and its owned files.",
618
+ deleteOrdinary: "This deletes this chat. Project files remain.",
619
+ cancel: "Cancel",
620
+ close: "Close",
621
+ retry: "Retry",
622
+ edit: "Edit and resend",
623
+ send: "Send",
624
+ editTitle: "Edit and resend",
625
+ draft: "Message text"
626
+ }
627
+ };
628
+ function uiText(locale, key) {
629
+ return text[locale][key];
630
+ }
631
+ function failureReason(failure) {
632
+ if (failure.code === "session/lifecycle-unavailable" || failure.code === "session/fork-unavailable") return "unsupported";
633
+ if (failure.code === "session/retry-revision" || failure.code === "session/branch-moved" || failure.code === "session/retry-input" || failure.code === "session/retry-conflict") return "stale";
634
+ if (failure.code === "session/delete-pending") return "cleanup";
635
+ if (failure.code === "session/agent-busy" && failure.reason === "free-session-work-active") return "running";
636
+ if (failure.reason === "modified" || failure.reason === "pending" || failure.reason === "running" || failure.reason === "stale") return failure.reason;
637
+ if (failure.reason === "stop-failed" || failure.reason === "not-quiet") return "running";
638
+ if (failure.reason === "not-human-prompt" || failure.reason === "missing-evidence") return "unknown";
639
+ return "unknown";
640
+ }
641
+ function failureText(locale, failure) {
642
+ return reasons[locale][failureReason(failure)];
643
+ }
644
+ function deleteBody(locale, classification) {
645
+ return classification === "free" ? text[locale].deleteFree : text[locale].deleteOrdinary;
646
+ }
647
+ //#endregion
648
+ //#region src/free-panel.tsx
649
+ function FreeChatIcon({ size }) {
650
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("svg", {
651
+ width: size,
652
+ height: size,
653
+ viewBox: "0 0 16 16",
654
+ "aria-hidden": "true",
655
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("path", {
656
+ d: "M2.5 3.5h11v7.5h-4.2L6 13.5V11H2.5z",
657
+ fill: "none",
658
+ stroke: "currentColor",
659
+ strokeWidth: "1.2"
660
+ })
661
+ });
662
+ }
663
+ /** Create failures used to surface inside the standalone panel. The panel is gone,
664
+ * so they get a small overlay instead; closing it dismisses the stored notice. */
665
+ function CreateNoticeDialog(props) {
666
+ const notice = (0, react.useSyncExternalStore)(props.model.subscribe, props.model.getSnapshot, props.model.getSnapshot).notice;
667
+ if (notice === void 0) return null;
668
+ const copy = (key) => uiText(props.locale, key);
669
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
670
+ open: true,
671
+ className: FREE_CHAT_ROOT,
672
+ title: copy("createFailed"),
673
+ closeLabel: copy("close"),
674
+ onClose: () => {
675
+ props.model.dismissNotice();
676
+ },
677
+ footer: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
678
+ variant: "primary",
679
+ "data-modal-autofocus": true,
680
+ onClick: () => {
681
+ props.model.dismissNotice();
682
+ },
683
+ children: copy("close")
684
+ }),
685
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
686
+ className: "dsh-ui-error dsh-free-alert",
687
+ role: "alert",
688
+ children: failureText(props.locale, notice)
689
+ })
690
+ });
691
+ }
692
+ function DeleteChatDialog(props) {
693
+ const request = (0, react.useSyncExternalStore)(props.model.subscribe, props.model.getSnapshot, props.model.getSnapshot).deleteRequest;
694
+ const confirmRef = (0, react.useRef)(null);
695
+ (0, react.useEffect)(() => {
696
+ if (request?.failure) confirmRef.current?.focus();
697
+ }, [request?.failure]);
698
+ if (request === void 0) return null;
699
+ const copy = (key) => uiText(props.locale, key);
700
+ const label = request.busy ? copy("deleting") : request.failure ? copy("retryList") : copy("deleteChat");
701
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
702
+ open: true,
703
+ className: FREE_CHAT_ROOT,
704
+ title: copy("deleteChat"),
705
+ closeLabel: copy("close"),
706
+ description: deleteBody(props.locale, request.classification),
707
+ onClose: () => {
708
+ props.model.cancelDelete();
709
+ },
710
+ footer: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
711
+ variant: "ghost",
712
+ disabled: request.busy,
713
+ onClick: () => {
714
+ props.model.cancelDelete();
715
+ },
716
+ children: copy("cancel")
717
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
718
+ ref: confirmRef,
719
+ variant: "primary",
720
+ "data-modal-autofocus": true,
721
+ disabled: request.busy,
722
+ onClick: () => {
723
+ props.model.confirmDelete();
724
+ },
725
+ children: label
726
+ })] }),
727
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: request.title }), request.failure ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
728
+ className: "dsh-ui-error dsh-free-alert",
729
+ role: "alert",
730
+ children: failureText(props.locale, request.failure)
731
+ }) : null]
732
+ });
733
+ }
734
+ //#endregion
735
+ //#region src/temporary-picker.tsx
736
+ const PICKER_SLOT = "conversation.hero.workspace";
737
+ const DIRECTORY_SLOT = "conversation.hero.workspace.directoryFlow";
738
+ /** Keep the host's native/web picker implementation and its injected capabilities.
739
+ * Standard rc.2 offers no exported directory-flow factory. Only its simple root
740
+ * registration can be mirrored; more complex future registrations restore the host picker.
741
+ * Original entries and their ownership ledger are never changed.
742
+ */
743
+ function installTemporaryWorkspacePicker(slots, model, createWorkspace, locale) {
744
+ if (typeof slots.entriesOfSlot !== "function" || typeof slots.spec !== "function" || typeof slots.subscribe !== "function") {
745
+ model.reportFailure(copyLocale(locale?.getSnapshot().active) === "zh" ? "当前版本无法扩展工作区菜单,已保留原菜单。" : "Could not extend the workspace menu. The original menu has been preserved.");
746
+ return () => {};
747
+ }
748
+ return slots.inject(PICKER_SLOT, () => {
749
+ let mirror, stopMirror = () => {}, restored = false;
750
+ const failureMessage = () => copyLocale(locale?.getSnapshot().active) === "zh" ? "当前版本无法扩展工作区菜单,已保留原菜单。" : "Could not extend the workspace menu. The original menu has been preserved.";
751
+ const renderPicker = (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TemporaryWorkspacePicker, {
752
+ ...props,
753
+ model,
754
+ createWorkspace,
755
+ locale,
756
+ getDirectoryFlow: () => mirror,
757
+ subscribeFlow: (listener) => slots.subscribe(DIRECTORY_SLOT, listener)
758
+ });
759
+ const stopPicker = slots.register({
760
+ name: PICKER_SLOT,
761
+ priority: -10,
762
+ locale: "workspace",
763
+ children: { [TEMP_WORKSPACE_FLOW_SLOT]: {
764
+ kind: "single",
765
+ scope: "root"
766
+ } }
767
+ }, renderPicker);
768
+ const stopErrors = slots.onEntryError?.((key, entry) => {
769
+ if (restored || key !== "session-manager.workspace.directoryFlow" && !(key === PICKER_SLOT && entry.component === renderPicker)) return;
770
+ restored = true;
771
+ stopMirror();
772
+ mirror = void 0;
773
+ stopPicker();
774
+ model.reportFailure(failureMessage());
775
+ }) ?? (() => {});
776
+ const sync = () => {
777
+ if (restored) return;
778
+ const next = slots.entriesOfSlot(DIRECTORY_SLOT)[0];
779
+ if (next === mirror) return;
780
+ stopMirror();
781
+ stopMirror = () => {};
782
+ mirror = void 0;
783
+ if (next === void 0) return;
784
+ const spec = slots.spec(DIRECTORY_SLOT);
785
+ if (spec?.kind !== "single" || spec.scope !== "root" || typeof next.component !== "function" || next.children !== void 0 || next.store !== void 0 || next.locale !== void 0 || next.select !== void 0) {
786
+ restored = true;
787
+ stopPicker();
788
+ model.reportFailure(failureMessage());
789
+ return;
790
+ }
791
+ try {
792
+ stopMirror = slots.register({
793
+ name: TEMP_WORKSPACE_FLOW_SLOT,
794
+ ...next.inject ? { inject: next.inject } : {}
795
+ }, next.component);
796
+ mirror = next;
797
+ } catch (error) {
798
+ restored = true;
799
+ stopPicker();
800
+ model.reportFailure(error instanceof Error ? error.message : "Could not extend the workspace picker");
801
+ }
802
+ };
803
+ const stopSource = slots.subscribe(DIRECTORY_SLOT, sync);
804
+ sync();
805
+ return () => {
806
+ restored = true;
807
+ stopErrors();
808
+ stopSource();
809
+ stopMirror();
810
+ stopPicker();
811
+ };
812
+ });
813
+ }
814
+ function TemporaryWorkspacePicker(props) {
815
+ const workspaces = props.useWorkspaces((snapshot) => snapshot);
816
+ const state = (0, react.useSyncExternalStore)(props.model.subscribe, props.model.getSnapshot, props.model.getSnapshot);
817
+ const source = (0, react.useSyncExternalStore)(props.subscribeFlow, props.getDirectoryFlow, props.getDirectoryFlow);
818
+ const available = source !== void 0;
819
+ const locale = copyLocale((0, react.useSyncExternalStore)((listener) => props.locale?.subscribe(listener) ?? (() => {}), () => props.locale?.getSnapshot().active ?? "en", () => "en"));
820
+ const [flowOpen, setFlowOpen] = (0, react.useState)(false), [adopting, setAdopting] = (0, react.useState)(false);
821
+ const [failure, setFailure] = (0, react.useState)();
822
+ const epoch = (0, react.useRef)(0);
823
+ (0, react.useEffect)(() => () => {
824
+ epoch.current++;
825
+ }, []);
826
+ (0, react.useEffect)(() => {
827
+ epoch.current++;
828
+ setFlowOpen(false);
829
+ setAdopting(false);
830
+ }, [source]);
831
+ const busy = flowOpen || adopting || state.creating;
832
+ const getAnchorRect = (0, react.useCallback)(() => props.anchorRef?.current?.getBoundingClientRect() ?? null, [props.anchorRef]);
833
+ const openDirectory = () => {
834
+ props.onClose();
835
+ setFailure(void 0);
836
+ setFlowOpen(true);
837
+ };
838
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
839
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Menu, {
840
+ open: props.open,
841
+ anchor: null,
842
+ portal: true,
843
+ getAnchorRect,
844
+ selectedId: props.selectedId,
845
+ onClose: props.onClose,
846
+ items: workspaces.items.map((workspace) => ({
847
+ id: workspace.workspaceId,
848
+ label: workspace.title === "default-workspace" ? props.t("workspace.defaultName") : workspace.title,
849
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconFolderCloseRegular, { size: 16 }),
850
+ disabled: busy
851
+ })),
852
+ footer: [...available ? [{
853
+ id: "::add-workspace",
854
+ label: props.t("menu.addWorkspace"),
855
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconPlusOutlineRegular, { size: 16 }),
856
+ disabled: busy
857
+ }] : [], {
858
+ id: "::temporary-workspace",
859
+ label: uiText(locale, "tempWorkspace"),
860
+ icon: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FreeChatIcon, { size: 16 }),
861
+ disabled: busy
862
+ }],
863
+ onSelect: (id) => {
864
+ if (id === "::add-workspace") openDirectory();
865
+ else if (id === "::temporary-workspace") {
866
+ props.onClose();
867
+ props.model.create();
868
+ } else props.onPick(id);
869
+ }
870
+ }),
871
+ props.open && workspaces.phase === "pending" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
872
+ role: "status",
873
+ children: props.t("picker.loading")
874
+ }),
875
+ props.renderSlot(TEMP_WORKSPACE_FLOW_SLOT, {
876
+ open: flowOpen,
877
+ busy: adopting,
878
+ onCancel: () => {
879
+ epoch.current++;
880
+ setFlowOpen(false);
881
+ setAdopting(false);
882
+ },
883
+ onError: (message) => {
884
+ epoch.current++;
885
+ setFlowOpen(false);
886
+ setAdopting(false);
887
+ setFailure(message);
888
+ },
889
+ onPicked: (path) => {
890
+ if (adopting) return;
891
+ const ticket = ++epoch.current;
892
+ setAdopting(true);
893
+ props.createWorkspace(path).then((workspace) => {
894
+ if (ticket !== epoch.current) return;
895
+ setFlowOpen(false);
896
+ props.onPick(workspace.workspaceId);
897
+ }, (error) => {
898
+ if (ticket !== epoch.current) return;
899
+ setFlowOpen(false);
900
+ setFailure(error instanceof Error ? error.message : String(error));
901
+ }).finally(() => {
902
+ if (ticket === epoch.current) setAdopting(false);
903
+ });
904
+ }
905
+ }),
906
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
907
+ open: failure !== void 0,
908
+ title: props.t("folderError.title"),
909
+ closeLabel: props.t("close"),
910
+ onClose: () => setFailure(void 0),
911
+ footer: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
912
+ variant: "outline",
913
+ onClick: () => setFailure(void 0),
914
+ children: props.t("cancel")
915
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
916
+ variant: "primary",
917
+ disabled: !available,
918
+ onClick: openDirectory,
919
+ children: props.t("folderError.retry")
920
+ })] }),
921
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
922
+ role: "alert",
923
+ children: failure
924
+ })
925
+ })
926
+ ] });
927
+ }
928
+ function TemporaryWorkspaceNotice({ model, locale }) {
929
+ const state = (0, react.useSyncExternalStore)(model.subscribe, model.getSnapshot, model.getSnapshot);
930
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
931
+ open: state.failure !== void 0,
932
+ title: uiText(locale, "createFailed"),
933
+ closeLabel: uiText(locale, "close"),
934
+ onClose: model.dismissFailure,
935
+ footer: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
936
+ variant: "outline",
937
+ onClick: model.dismissFailure,
938
+ children: uiText(locale, "close")
939
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
940
+ variant: "primary",
941
+ disabled: state.creating,
942
+ onClick: () => {
943
+ model.create();
944
+ },
945
+ children: uiText(locale, "retry")
946
+ })] }),
947
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
948
+ role: "alert",
949
+ children: state.failure
950
+ })
951
+ });
952
+ }
953
+ //#endregion
954
+ //#region src/temporary-workspace.ts
955
+ function createTemporaryWorkspaceModel(host, ids = () => crypto.randomUUID(), label = () => "Temporary Workspace") {
956
+ const lifetime = new AbortController(), listeners = /* @__PURE__ */ new Set();
957
+ let snapshot = { creating: false };
958
+ let pending;
959
+ const publish = (next) => {
960
+ if (lifetime.signal.aborted) return;
961
+ snapshot = next;
962
+ for (const listener of listeners) listener();
963
+ };
964
+ return {
965
+ getSnapshot: () => snapshot,
966
+ subscribe(listener) {
967
+ listeners.add(listener);
968
+ return () => {
969
+ listeners.delete(listener);
970
+ };
971
+ },
972
+ dismissFailure() {
973
+ publish({ creating: snapshot.creating });
974
+ },
975
+ reportFailure(failure) {
976
+ publish({
977
+ ...snapshot,
978
+ failure
979
+ });
980
+ },
981
+ async create() {
982
+ if (snapshot.creating || lifetime.signal.aborted) return;
983
+ const signal = AbortSignal.any([host.beginNavigation(), lifetime.signal]);
984
+ const action = pending ??= {
985
+ requestId: ids(),
986
+ title: label()
987
+ };
988
+ let opening = false;
989
+ publish({ creating: true });
990
+ try {
991
+ signal.throwIfAborted();
992
+ if (action.path === void 0) {
993
+ const allocated = await host.allocate(action.requestId, signal);
994
+ if (allocated.requestId !== action.requestId || !allocated.path) throw new Error("Invalid temporary workspace response");
995
+ action.path = allocated.path;
996
+ }
997
+ signal.throwIfAborted();
998
+ if (action.workspaceId === void 0) action.workspaceId = (await host.createWorkspace(action.path)).workspaceId;
999
+ signal.throwIfAborted();
1000
+ if (!action.named) {
1001
+ await host.renameWorkspace(action.workspaceId, `${action.title} ${action.requestId.slice(0, 8)}`);
1002
+ action.named = true;
1003
+ }
1004
+ signal.throwIfAborted();
1005
+ opening = true;
1006
+ await host.openWorkspace(action.workspaceId, () => lifetime.signal.throwIfAborted());
1007
+ if (!lifetime.signal.aborted) pending = void 0;
1008
+ } catch (error) {
1009
+ if (!lifetime.signal.aborted && (opening ? !(error instanceof Error && error.name === "AbortError") : !signal.aborted)) publish({
1010
+ creating: false,
1011
+ failure: error instanceof Error ? error.message : "Could not create the temporary workspace"
1012
+ });
1013
+ } finally {
1014
+ publish({
1015
+ ...snapshot,
1016
+ creating: false
1017
+ });
1018
+ }
1019
+ },
1020
+ cancel() {
1021
+ lifetime.abort();
1022
+ listeners.clear();
1023
+ }
1024
+ };
1025
+ }
1026
+ function bindTemporaryWorkspaceHost(ctx) {
1027
+ return {
1028
+ beginNavigation: () => ctx.layout.beginNavigation(),
1029
+ async allocate(requestId, signal) {
1030
+ const response = await ctx.connection.rpc.call(TEMP_WORKSPACE_CHANNEL, "temporary.allocate", { requestId }, signal);
1031
+ if (response?.ok !== true || typeof response.value?.path !== "string" || typeof response.value.requestId !== "string") throw new Error(response?.error?.message ?? "Could not allocate the temporary workspace");
1032
+ return response.value;
1033
+ },
1034
+ createWorkspace: (path) => ctx.workspaces.create({ path }),
1035
+ renameWorkspace: (workspaceId, title) => ctx.workspaces.rename(workspaceId, title),
1036
+ openWorkspace: (workspaceId, beforeOpen) => ctx.uiWorkspace.openWorkspace(workspaceId, beforeOpen)
1037
+ };
1038
+ }
1039
+ //#endregion
1040
+ //#region src/session-actions.ts
1041
+ const UNSUPPORTED_CAPABILITIES = {
1042
+ retry: false,
1043
+ freeSession: false,
1044
+ deleteSession: false
1045
+ };
1046
+ function isRecoverable(failure) {
1047
+ return failure.code === "transport" || failure.code === "session/delete-pending";
1048
+ }
1049
+ function readFailure(error) {
1050
+ if (isFailure(error)) return {
1051
+ code: error.code,
1052
+ ...error.reason === void 0 ? {} : { reason: error.reason }
1053
+ };
1054
+ if (typeof error === "object" && error !== null) {
1055
+ const record = error;
1056
+ const rpc = record.rpcError;
1057
+ if (typeof rpc?.code === "string") return {
1058
+ code: rpc.code,
1059
+ ...reasonOf(rpc) === void 0 ? {} : { reason: reasonOf(rpc) }
1060
+ };
1061
+ if (typeof record.code === "string") {
1062
+ const reason = typeof record.reason === "string" ? record.reason : void 0;
1063
+ return {
1064
+ code: record.code,
1065
+ ...reason === void 0 ? {} : { reason }
1066
+ };
1067
+ }
1068
+ }
1069
+ return {
1070
+ code: "transport",
1071
+ reason: "unknown"
1072
+ };
1073
+ }
1074
+ function isFailure(error) {
1075
+ return typeof error === "object" && error !== null && "code" in error && typeof error.code === "string" && error.name === "HostOperationError";
1076
+ }
1077
+ var HostOperationError = class extends Error {
1078
+ code;
1079
+ name = "HostOperationError";
1080
+ reason;
1081
+ constructor(code, reason) {
1082
+ super(code);
1083
+ this.code = code;
1084
+ if (reason !== void 0) this.reason = reason;
1085
+ }
1086
+ };
1087
+ function reasonOf(error) {
1088
+ return typeof error?.details?.reason === "string" ? error.details.reason : void 0;
1089
+ }
1090
+ function isRemoteResult(value) {
1091
+ if (typeof value !== "object" || value === null || !("ok" in value)) return false;
1092
+ return typeof value.ok === "boolean" && ("value" in value || "error" in value);
1093
+ }
1094
+ async function unwrap(value) {
1095
+ const resolved = await value;
1096
+ if (!isRemoteResult(resolved)) return resolved;
1097
+ if (!resolved.ok) throw new HostOperationError(resolved.error?.code ?? "transport", reasonOf(resolved.error));
1098
+ return resolved.value;
1099
+ }
1100
+ async function readCapabilities(host) {
1101
+ if (typeof host.capabilities !== "function") return UNSUPPORTED_CAPABILITIES;
1102
+ try {
1103
+ const value = await unwrap(host.capabilities());
1104
+ if (typeof value !== "object" || value === null) return UNSUPPORTED_CAPABILITIES;
1105
+ const record = value;
1106
+ return {
1107
+ retry: record.retry === true,
1108
+ freeSession: record.freeSession === true,
1109
+ deleteSession: record.deleteSession === true
1110
+ };
1111
+ } catch {
1112
+ return UNSUPPORTED_CAPABILITIES;
1113
+ }
1114
+ }
1115
+ function controlsFor(capabilities, ready, host) {
1116
+ return {
1117
+ create: ready && capabilities.freeSession && typeof host.create === "function",
1118
+ delete: ready && capabilities.deleteSession && typeof host.deleteSession === "function",
1119
+ retry: ready && capabilities.retry && typeof host.previewRetry === "function" && typeof host.retry === "function"
1120
+ };
1121
+ }
1122
+ function sessionIdOf(value) {
1123
+ if (typeof value === "string" && value !== "") return value;
1124
+ if (typeof value === "object" && value !== null && typeof value.sessionId === "string") return value.sessionId;
1125
+ throw new HostOperationError("session/lifecycle-unavailable");
1126
+ }
1127
+ /** Pass only `{ kind: 'free' }`. A cwd or workspace is rejected by free create, and must not be invented. */
1128
+ async function createFreeSession(host) {
1129
+ if (typeof host.create !== "function") throw new HostOperationError("session/lifecycle-unavailable");
1130
+ return sessionIdOf(await unwrap(host.create({ kind: "free" })));
1131
+ }
1132
+ async function deleteOwnedSession(host, sessionId, requestId) {
1133
+ if (typeof host.deleteSession !== "function") throw new HostOperationError("session/lifecycle-unavailable");
1134
+ const value = await unwrap(host.deleteSession(sessionId, requestId));
1135
+ if (typeof value !== "object" || value === null) throw new HostOperationError("session/delete-pending", "missing-outcome");
1136
+ const phase = value.phase;
1137
+ if (phase !== "deleted" && phase !== "cleanup-pending") throw new HostOperationError("session/delete-pending", "missing-outcome");
1138
+ return { phase };
1139
+ }
1140
+ function directRetryRequest(input) {
1141
+ return {
1142
+ sessionId: input.sessionId,
1143
+ messageId: input.messageId,
1144
+ expectedRevision: input.expectedRevision,
1145
+ expectedInputRevision: input.expectedInputRevision,
1146
+ requestId: input.requestId
1147
+ };
1148
+ }
1149
+ function editRetryRequest(input) {
1150
+ return {
1151
+ ...directRetryRequest(input),
1152
+ text: input.text
1153
+ };
1154
+ }
1155
+ var SubmissionLedger = class {
1156
+ active = false;
1157
+ unresolved;
1158
+ get busy() {
1159
+ return this.active;
1160
+ }
1161
+ pending() {
1162
+ return this.unresolved;
1163
+ }
1164
+ /** Resend the stored body. A non-recoverable result drops it; a lost reply keeps it. */
1165
+ async replay(execute) {
1166
+ const body = this.unresolved;
1167
+ if (body === void 0) return;
1168
+ if (this.active) throw new HostOperationError("busy", "running");
1169
+ this.active = true;
1170
+ try {
1171
+ await execute(body);
1172
+ this.unresolved = void 0;
1173
+ } catch (error) {
1174
+ const failure = readFailure(error);
1175
+ if (!isRecoverable(failure) && failure.reason !== "aborted") this.unresolved = void 0;
1176
+ throw error instanceof HostOperationError ? error : new HostOperationError(failure.code, failure.reason);
1177
+ } finally {
1178
+ this.active = false;
1179
+ }
1180
+ }
1181
+ /** First submission of a body built from the current preview. */
1182
+ async submit(body, execute) {
1183
+ if (this.active || this.unresolved !== void 0) throw new HostOperationError("busy", "running");
1184
+ this.active = true;
1185
+ try {
1186
+ await execute();
1187
+ this.unresolved = void 0;
1188
+ } catch (error) {
1189
+ const failure = readFailure(error);
1190
+ this.unresolved = isRecoverable(failure) ? body : void 0;
1191
+ throw error instanceof HostOperationError ? error : new HostOperationError(failure.code, failure.reason);
1192
+ } finally {
1193
+ this.active = false;
1194
+ }
1195
+ }
1196
+ };
1197
+ function store() {
1198
+ const listeners = /* @__PURE__ */ new Set();
1199
+ return {
1200
+ subscribe(listener) {
1201
+ listeners.add(listener);
1202
+ return () => {
1203
+ listeners.delete(listener);
1204
+ };
1205
+ },
1206
+ emit() {
1207
+ for (const listener of listeners) listener();
1208
+ }
1209
+ };
1210
+ }
1211
+ function createFreeChatModel(host, ids = () => crypto.randomUUID()) {
1212
+ const events = store();
1213
+ let capabilities = UNSUPPORTED_CAPABILITIES;
1214
+ let capabilitiesReady = false;
1215
+ let creating = false;
1216
+ let notice;
1217
+ let deleteRequest;
1218
+ let generation = 0;
1219
+ let snapshot = build();
1220
+ function build() {
1221
+ return {
1222
+ controls: controlsFor(capabilities, capabilitiesReady, host),
1223
+ capabilitiesReady,
1224
+ creating,
1225
+ ...notice === void 0 ? {} : { notice },
1226
+ ...deleteRequest === void 0 ? {} : { deleteRequest }
1227
+ };
1228
+ }
1229
+ function publish() {
1230
+ snapshot = build();
1231
+ events.emit();
1232
+ }
1233
+ return {
1234
+ subscribe: events.subscribe,
1235
+ getSnapshot: () => snapshot,
1236
+ async reloadCapabilities() {
1237
+ capabilities = await readCapabilities(host);
1238
+ capabilitiesReady = true;
1239
+ publish();
1240
+ },
1241
+ async create() {
1242
+ if (!controlsFor(capabilities, capabilitiesReady, host).create || creating) return;
1243
+ const ticket = generation;
1244
+ creating = true;
1245
+ notice = void 0;
1246
+ publish();
1247
+ try {
1248
+ const id = await createFreeSession(host);
1249
+ if (ticket !== generation) return;
1250
+ if (typeof host.openSession !== "function") throw new HostOperationError("session/lifecycle-unavailable", "open-session");
1251
+ host.openSession(id);
1252
+ } catch (error) {
1253
+ if (ticket !== generation) return;
1254
+ notice = readFailure(error);
1255
+ } finally {
1256
+ if (ticket === generation) {
1257
+ creating = false;
1258
+ publish();
1259
+ }
1260
+ }
1261
+ },
1262
+ dismissNotice() {
1263
+ if (notice === void 0) return;
1264
+ notice = void 0;
1265
+ publish();
1266
+ },
1267
+ requestDelete(sessionId) {
1268
+ if (!controlsFor(capabilities, capabilitiesReady, host).delete) return;
1269
+ const row = host.list.getSnapshot().byId[sessionId];
1270
+ deleteRequest = {
1271
+ sessionId,
1272
+ title: row?.displayTitle ?? row?.title ?? sessionId,
1273
+ classification: row?.classification === "free" ? "free" : "ordinary",
1274
+ requestId: ids(),
1275
+ busy: false
1276
+ };
1277
+ publish();
1278
+ },
1279
+ cancelDelete() {
1280
+ if (deleteRequest?.busy) return;
1281
+ deleteRequest = void 0;
1282
+ publish();
1283
+ },
1284
+ async confirmDelete() {
1285
+ const current = deleteRequest;
1286
+ if (current === void 0 || current.busy) return;
1287
+ const ticket = generation;
1288
+ deleteRequest = {
1289
+ ...current,
1290
+ busy: true,
1291
+ failure: void 0
1292
+ };
1293
+ publish();
1294
+ try {
1295
+ const outcome = await deleteOwnedSession(host, current.sessionId, current.requestId);
1296
+ if (ticket !== generation) return;
1297
+ if (outcome.phase !== "deleted") {
1298
+ deleteRequest = {
1299
+ ...current,
1300
+ busy: false,
1301
+ failure: {
1302
+ code: "session/delete-pending",
1303
+ reason: "pending"
1304
+ }
1305
+ };
1306
+ publish();
1307
+ return;
1308
+ }
1309
+ deleteRequest = void 0;
1310
+ } catch (error) {
1311
+ if (ticket !== generation) return;
1312
+ const failure = readFailure(error);
1313
+ deleteRequest = {
1314
+ ...current,
1315
+ busy: false,
1316
+ failure
1317
+ };
1318
+ }
1319
+ if (ticket === generation) publish();
1320
+ },
1321
+ cancel() {
1322
+ generation += 1;
1323
+ creating = false;
1324
+ notice = void 0;
1325
+ deleteRequest = void 0;
1326
+ publish();
1327
+ }
1328
+ };
1329
+ }
1330
+ function createRetryModel(host, ids = () => crypto.randomUUID()) {
1331
+ const events = store();
1332
+ const ledger = new SubmissionLedger();
1333
+ let capabilities = UNSUPPORTED_CAPABILITIES;
1334
+ let ready = false;
1335
+ let busy = false;
1336
+ let editing = false;
1337
+ let draft = "";
1338
+ let failure;
1339
+ let expectedRevision = 0;
1340
+ let expectedInputRevision = "";
1341
+ let ownerSession = "";
1342
+ let ownerMessage = "";
1343
+ let call = 0;
1344
+ let snapshot = build();
1345
+ function build() {
1346
+ return {
1347
+ controlsRetry: controlsFor(capabilities, ready, host).retry,
1348
+ busy,
1349
+ editing,
1350
+ draft,
1351
+ sessionId: ownerSession,
1352
+ messageId: ownerMessage,
1353
+ ...failure === void 0 ? {} : { failure }
1354
+ };
1355
+ }
1356
+ function publish() {
1357
+ snapshot = build();
1358
+ events.emit();
1359
+ }
1360
+ function readPreview(value) {
1361
+ if (typeof value !== "object" || value === null || typeof value.branchRevision !== "number") throw new HostOperationError("session/lifecycle-unavailable");
1362
+ const record = value;
1363
+ const inputRevision = typeof record.inputRevision === "string" ? record.inputRevision : "";
1364
+ const eligible = record.eligible === true;
1365
+ if (eligible && inputRevision === "") throw new HostOperationError("session/lifecycle-unavailable", "input-revision");
1366
+ return {
1367
+ branchRevision: record.branchRevision,
1368
+ inputRevision,
1369
+ eligible,
1370
+ ...typeof record.reason === "string" ? { reason: record.reason } : {}
1371
+ };
1372
+ }
1373
+ async function preview(sessionId, id, signal, ticket) {
1374
+ if (ticket !== call || signal.aborted) return void 0;
1375
+ if (typeof host.previewRetry !== "function") throw new HostOperationError("session/lifecycle-unavailable");
1376
+ const value = await unwrap(host.previewRetry({
1377
+ sessionId,
1378
+ messageId: id
1379
+ }));
1380
+ if (ticket !== call || signal.aborted) return void 0;
1381
+ return readPreview(value);
1382
+ }
1383
+ async function callRetry(body, signal, ticket) {
1384
+ if (signal.aborted || ticket !== call) throw new HostOperationError("busy", "aborted");
1385
+ if (typeof host.retry !== "function") throw new HostOperationError("session/lifecycle-unavailable");
1386
+ await unwrap(host.retry(body));
1387
+ }
1388
+ function settle() {
1389
+ if (!ledger.busy) busy = false;
1390
+ publish();
1391
+ }
1392
+ async function replaySame(signal) {
1393
+ if (signal.aborted) return;
1394
+ const pending = ledger.pending();
1395
+ const ticket = ++call;
1396
+ busy = true;
1397
+ failure = void 0;
1398
+ publish();
1399
+ try {
1400
+ await ledger.replay(async (body) => {
1401
+ await callRetry(body, signal, ticket);
1402
+ });
1403
+ if (pending !== void 0 && ticket === call && !signal.aborted && ownerSession === pending.sessionId && ownerMessage === pending.messageId) editing = false;
1404
+ } catch (error) {
1405
+ if (ticket === call && !signal.aborted) failure = readFailure(error);
1406
+ } finally {
1407
+ settle();
1408
+ }
1409
+ }
1410
+ function samePending(sessionId, id) {
1411
+ const pending = ledger.pending();
1412
+ return pending !== void 0 && pending.sessionId === sessionId && pending.messageId === id;
1413
+ }
1414
+ return {
1415
+ subscribe: events.subscribe,
1416
+ getSnapshot: () => snapshot,
1417
+ async load() {
1418
+ capabilities = await readCapabilities(host);
1419
+ ready = true;
1420
+ publish();
1421
+ },
1422
+ async retry(sessionId, id, signal) {
1423
+ if (busy || !controlsFor(capabilities, ready, host).retry || signal.aborted) return;
1424
+ if (ledger.pending() !== void 0) {
1425
+ if (!samePending(sessionId, id)) return;
1426
+ await replaySame(signal);
1427
+ return;
1428
+ }
1429
+ const ticket = ++call;
1430
+ busy = true;
1431
+ failure = void 0;
1432
+ editing = false;
1433
+ ownerSession = sessionId;
1434
+ ownerMessage = id;
1435
+ publish();
1436
+ try {
1437
+ const seen = await preview(sessionId, id, signal, ticket);
1438
+ if (seen === void 0) return;
1439
+ if (!seen.eligible) {
1440
+ failure = {
1441
+ code: "session/retry-blocked",
1442
+ reason: seen.reason ?? "unknown"
1443
+ };
1444
+ return;
1445
+ }
1446
+ if (signal.aborted || ticket !== call) return;
1447
+ expectedRevision = seen.branchRevision;
1448
+ expectedInputRevision = seen.inputRevision;
1449
+ const body = directRetryRequest({
1450
+ sessionId,
1451
+ messageId: id,
1452
+ expectedRevision: seen.branchRevision,
1453
+ expectedInputRevision: seen.inputRevision,
1454
+ requestId: ids()
1455
+ });
1456
+ await ledger.submit(body, () => callRetry(body, signal, ticket));
1457
+ } catch (error) {
1458
+ if (ticket === call && !signal.aborted) failure = readFailure(error);
1459
+ } finally {
1460
+ settle();
1461
+ }
1462
+ },
1463
+ async beginEdit(sessionId, id, text, signal) {
1464
+ if (busy || !controlsFor(capabilities, ready, host).retry || signal.aborted) return;
1465
+ if (ledger.pending() !== void 0) {
1466
+ if (!samePending(sessionId, id)) return;
1467
+ await replaySame(signal);
1468
+ return;
1469
+ }
1470
+ const ticket = ++call;
1471
+ busy = true;
1472
+ failure = void 0;
1473
+ ownerSession = sessionId;
1474
+ ownerMessage = id;
1475
+ publish();
1476
+ try {
1477
+ const seen = await preview(sessionId, id, signal, ticket);
1478
+ if (seen === void 0) return;
1479
+ if (!seen.eligible) {
1480
+ failure = {
1481
+ code: "session/retry-blocked",
1482
+ reason: seen.reason ?? "unknown"
1483
+ };
1484
+ return;
1485
+ }
1486
+ if (signal.aborted || ticket !== call) return;
1487
+ expectedRevision = seen.branchRevision;
1488
+ expectedInputRevision = seen.inputRevision;
1489
+ draft = text;
1490
+ editing = true;
1491
+ } catch (error) {
1492
+ if (ticket === call && !signal.aborted) failure = readFailure(error);
1493
+ } finally {
1494
+ settle();
1495
+ }
1496
+ },
1497
+ setDraft(text) {
1498
+ if (!editing || ownerSession === "" || ownerMessage === "") return;
1499
+ draft = text;
1500
+ publish();
1501
+ },
1502
+ cancelEdit() {
1503
+ if (busy) return;
1504
+ editing = false;
1505
+ publish();
1506
+ },
1507
+ async sendEdit(sessionId, id, signal) {
1508
+ if (signal.aborted || busy || !controlsFor(capabilities, ready, host).retry) return;
1509
+ if (!editing || ownerSession !== sessionId || ownerMessage !== id) return;
1510
+ if (ledger.pending() !== void 0) {
1511
+ if (!samePending(sessionId, id)) return;
1512
+ await replaySame(signal);
1513
+ return;
1514
+ }
1515
+ const ticket = ++call;
1516
+ busy = true;
1517
+ failure = void 0;
1518
+ const text = draft;
1519
+ publish();
1520
+ try {
1521
+ if (signal.aborted || ticket !== call) return;
1522
+ const body = editRetryRequest({
1523
+ sessionId,
1524
+ messageId: id,
1525
+ expectedRevision,
1526
+ expectedInputRevision,
1527
+ requestId: ids(),
1528
+ text
1529
+ });
1530
+ await ledger.submit(body, () => callRetry(body, signal, ticket));
1531
+ if (ticket === call && !signal.aborted) editing = false;
1532
+ } catch (error) {
1533
+ if (ticket === call && !signal.aborted) failure = readFailure(error);
1534
+ } finally {
1535
+ settle();
1536
+ }
1537
+ },
1538
+ retire(sessionId, messageId) {
1539
+ if (ownerSession !== sessionId || ownerMessage !== messageId) return;
1540
+ call += 1;
1541
+ editing = false;
1542
+ failure = void 0;
1543
+ draft = "";
1544
+ if (!ledger.busy) busy = false;
1545
+ publish();
1546
+ },
1547
+ cancel() {
1548
+ call += 1;
1549
+ editing = false;
1550
+ failure = void 0;
1551
+ if (!ledger.busy) busy = false;
1552
+ publish();
1553
+ }
1554
+ };
1555
+ }
1556
+ function bindHost(ctx) {
1557
+ const sessions = ctx.sessions;
1558
+ const workspace = ctx.uiWorkspace;
1559
+ return {
1560
+ list: sessions?.list ?? {
1561
+ getSnapshot: () => ({
1562
+ ids: [],
1563
+ byId: {},
1564
+ phase: "ready"
1565
+ }),
1566
+ subscribe: () => () => {}
1567
+ },
1568
+ ...typeof sessions?.capabilities === "function" ? { capabilities: () => sessions.capabilities() } : {},
1569
+ ...typeof sessions?.create === "function" ? { create: (opts) => sessions.create(opts) } : {},
1570
+ ...typeof sessions?.previewRetry === "function" ? { previewRetry: (request) => sessions.previewRetry(request) } : {},
1571
+ ...typeof sessions?.retry === "function" ? { retry: (request) => sessions.retry(request) } : {},
1572
+ ...typeof workspace?.openSession === "function" ? { openSession: (sessionId) => workspace.openSession(sessionId) } : {},
1573
+ ...typeof workspace?.deleteSession === "function" ? { deleteSession: (sessionId, requestId) => workspace.deleteSession(sessionId, requestId) } : {}
1574
+ };
1575
+ }
1576
+ //#endregion
1577
+ //#region src/user-actions.tsx
1578
+ function UserMessageActions(props) {
1579
+ const snapshot = (0, react.useSyncExternalStore)(props.model.subscribe, props.model.getSnapshot, props.model.getSnapshot);
1580
+ const signal = (0, react.useRef)(new AbortController());
1581
+ (0, react.useEffect)(() => {
1582
+ const controller = new AbortController();
1583
+ signal.current = controller;
1584
+ return () => {
1585
+ controller.abort();
1586
+ props.model.retire(props.sessionId, props.messageId);
1587
+ };
1588
+ }, [
1589
+ props.model,
1590
+ props.sessionId,
1591
+ props.messageId
1592
+ ]);
1593
+ if (props.sessionId === "" || !snapshot.controlsRetry) return null;
1594
+ const mine = snapshot.sessionId === props.sessionId && snapshot.messageId === props.messageId;
1595
+ const copy = (key) => uiText(props.locale, key);
1596
+ const failure = mine ? snapshot.failure : void 0;
1597
+ const editing = mine && snapshot.editing;
1598
+ const draft = mine ? snapshot.draft : props.text;
1599
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1600
+ className: `${FREE_CHAT_ROOT} dsh-free-actions`,
1601
+ children: [
1602
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tooltip, {
1603
+ label: copy("retry"),
1604
+ side: "bottom",
1605
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
1606
+ size: "sm",
1607
+ variant: "ghost",
1608
+ "aria-label": copy("retry"),
1609
+ disabled: snapshot.busy,
1610
+ onClick: () => {
1611
+ props.model.retry(props.sessionId, props.messageId, signal.current.signal);
1612
+ },
1613
+ children: copy("retry")
1614
+ })
1615
+ }),
1616
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tooltip, {
1617
+ label: copy("edit"),
1618
+ side: "bottom",
1619
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
1620
+ size: "sm",
1621
+ variant: "ghost",
1622
+ "aria-label": copy("edit"),
1623
+ disabled: snapshot.busy,
1624
+ onClick: () => {
1625
+ props.model.beginEdit(props.sessionId, props.messageId, props.text, signal.current.signal);
1626
+ },
1627
+ children: copy("edit")
1628
+ })
1629
+ }),
1630
+ failure ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1631
+ className: "dsh-ui-error dsh-free-alert",
1632
+ role: "alert",
1633
+ children: failureText(props.locale, failure)
1634
+ }) : null,
1635
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Modal, {
1636
+ open: editing,
1637
+ className: FREE_CHAT_ROOT,
1638
+ title: copy("editTitle"),
1639
+ closeLabel: copy("close"),
1640
+ onClose: () => {
1641
+ props.model.cancelEdit();
1642
+ },
1643
+ footer: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
1644
+ variant: "ghost",
1645
+ disabled: snapshot.busy,
1646
+ onClick: () => {
1647
+ props.model.cancelEdit();
1648
+ },
1649
+ children: copy("cancel")
1650
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
1651
+ variant: "primary",
1652
+ "data-modal-autofocus": true,
1653
+ disabled: snapshot.busy,
1654
+ onClick: () => {
1655
+ props.model.sendEdit(props.sessionId, props.messageId, signal.current.signal);
1656
+ },
1657
+ children: copy("send")
1658
+ })] }),
1659
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
1660
+ className: "dsh-free-draft",
1661
+ "aria-label": copy("draft"),
1662
+ value: draft,
1663
+ onChange: (event) => {
1664
+ props.model.setDraft(event.target.value);
1665
+ }
1666
+ })
1667
+ })
1668
+ ]
1669
+ });
1670
+ }
1671
+ //#endregion
1672
+ //#region src/client.tsx
1673
+ const name = "dsh-session-manager-client";
1674
+ const inject = [
1675
+ "slots",
1676
+ "locale",
1677
+ "sessions",
1678
+ "uiWorkspace",
1679
+ "shortcuts",
1680
+ "connection",
1681
+ "workspaces",
1682
+ "layout"
1683
+ ];
1684
+ function CopyThreadMenuItem(props) {
1685
+ const [failed, setFailed] = (0, react.useState)(false);
1686
+ const [, setMenuOpen] = props.useMenuOpenState();
1687
+ const label = failed ? COPY_THREAD_FAILED[props.locale] : COPY_THREAD_LABEL[props.locale];
1688
+ const onSelect = () => copyThreadId(props.sessionId, props.writeText ?? writeClipboard).then(() => {
1689
+ setFailed(false);
1690
+ setMenuOpen(false);
1691
+ }, () => {
1692
+ setFailed(true);
1693
+ });
1694
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.MenuItemButton, {
1695
+ separatorBefore: true,
1696
+ shortcut: props.shortcut,
1697
+ onSelect,
1698
+ children: label
1699
+ });
1700
+ }
1701
+ function apply(ctx) {
1702
+ const client = ctx;
1703
+ const host = bindHost(client);
1704
+ const chats = createFreeChatModel(host);
1705
+ const retries = createRetryModel(host);
1706
+ const temporaryHost = bindTemporaryWorkspaceHost(client);
1707
+ const temporary = createTemporaryWorkspaceModel(temporaryHost, void 0, () => uiText(copyLocale(client.locale?.getSnapshot().active), "tempWorkspace"));
1708
+ const currentLocale = () => client.locale?.getSnapshot().active;
1709
+ client.effect(() => {
1710
+ const stops = [];
1711
+ if (typeof document !== "undefined") stops.push(installContextMenuForwarding(document));
1712
+ stops.push(client.slots.inject("sidebar.workspaces.session.menu.item", () => client.slots.register({
1713
+ name: "sidebar.workspaces.session.menu.item",
1714
+ id: COPY_THREAD_MENU_ID,
1715
+ order: 500
1716
+ }, (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopyThreadSlot, {
1717
+ locale: client.locale,
1718
+ shortcuts: client.shortcuts,
1719
+ ...props
1720
+ }))));
1721
+ stops.push(client.slots.inject("sidebar.workspaces.session.menu.item", () => client.slots.register({
1722
+ name: "sidebar.workspaces.session.menu.item",
1723
+ id: DELETE_DIALOG_ID,
1724
+ order: 510
1725
+ }, (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DeleteMenuItem, {
1726
+ locale: client.locale,
1727
+ model: chats,
1728
+ ...props
1729
+ }))));
1730
+ stops.push(installTemporaryWorkspacePicker(client.slots, temporary, temporaryHost.createWorkspace, client.locale));
1731
+ stops.push(client.slots.inject(USER_ACTIONS_SLOT, () => client.slots.register({
1732
+ name: USER_ACTIONS_SLOT,
1733
+ id: USER_ACTIONS_ID,
1734
+ order: 10,
1735
+ inject: (sessionId) => ({ sessionId })
1736
+ }, (props) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(UserMessageActions, {
1737
+ messageId: props.messageId,
1738
+ text: props.text,
1739
+ sessionId: props.sessionId ?? "",
1740
+ locale: useLiveLocale(client.locale),
1741
+ model: retries
1742
+ }))));
1743
+ stops.push(client.slots.inject("shell.overlay", () => client.slots.register({
1744
+ name: "shell.overlay",
1745
+ id: DELETE_DIALOG_ID,
1746
+ order: 40
1747
+ }, () => {
1748
+ const locale = useLiveLocale(client.locale);
1749
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
1750
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: freeChatCss }),
1751
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopyThreadShortcutNotice, {
1752
+ shortcuts: client.shortcuts,
1753
+ list: client.sessions?.list,
1754
+ locale,
1755
+ currentLocale
1756
+ }),
1757
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TemporaryWorkspaceNotice, {
1758
+ model: temporary,
1759
+ locale
1760
+ }),
1761
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DeleteChatDialog, {
1762
+ model: chats,
1763
+ locale
1764
+ }),
1765
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CreateNoticeDialog, {
1766
+ model: chats,
1767
+ locale
1768
+ })
1769
+ ] });
1770
+ })));
1771
+ const reset = client.on?.("connection/reset", () => {
1772
+ chats.reloadCapabilities();
1773
+ retries.load();
1774
+ });
1775
+ if (typeof reset === "function") stops.push(reset);
1776
+ chats.reloadCapabilities();
1777
+ retries.load();
1778
+ return () => {
1779
+ chats.cancel();
1780
+ retries.cancel();
1781
+ temporary.cancel();
1782
+ for (const stop of stops) stop();
1783
+ };
1784
+ });
1785
+ }
1786
+ const EMPTY_SHORTCUTS = [];
1787
+ function CopyThreadSlot(props) {
1788
+ const locale = useLiveLocale(props.locale);
1789
+ const shortcuts = (0, react.useSyncExternalStore)((listener) => props.shortcuts?.catalog.subscribe(listener) ?? (() => {}), () => props.shortcuts?.catalog.getSnapshot() ?? EMPTY_SHORTCUTS, () => EMPTY_SHORTCUTS);
1790
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopyThreadMenuItem, {
1791
+ sessionId: props.sessionId,
1792
+ useMenuOpenState: props.useMenuOpenState,
1793
+ locale,
1794
+ shortcut: shortcuts.find((row) => row.id === COPY_THREAD_SHORTCUT_ID)
1795
+ });
1796
+ }
1797
+ function DeleteMenuItem(props) {
1798
+ const locale = useLiveLocale(props.locale);
1799
+ const snapshot = (0, react.useSyncExternalStore)(props.model.subscribe, props.model.getSnapshot, props.model.getSnapshot);
1800
+ const [, setMenuOpen] = props.useMenuOpenState();
1801
+ if (!snapshot.controls.delete) return null;
1802
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.MenuItemButton, {
1803
+ onSelect: () => {
1804
+ props.model.requestDelete(props.sessionId);
1805
+ setMenuOpen(false);
1806
+ },
1807
+ children: uiText(locale, "deleteChat")
1808
+ });
1809
+ }
1810
+ function useLiveLocale(locale) {
1811
+ return copyLocale((0, react.useSyncExternalStore)((listener) => locale?.subscribe(listener) ?? (() => {}), () => locale?.getSnapshot().active ?? "en", () => locale?.getSnapshot().active ?? "en"));
1812
+ }
1813
+ //#endregion
1814
+ exports.CopyThreadMenuItem = CopyThreadMenuItem;
1815
+ exports.apply = apply;
1816
+ exports.inject = inject;
1817
+ exports.name = name;
1818
+
1819
+ //# sourceMappingURL=client.inner.cjs.map