dsh-edge 0.19.0-alpha.2 → 0.19.3

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.
Files changed (31) hide show
  1. package/THIRD_PARTY_NOTICES.md +1991 -1741
  2. package/dist/assets/index-5SrrfWpU.js +127 -0
  3. package/dist/assets/index-BPHePDI_.css +1 -0
  4. package/dist/index.html +3 -3
  5. package/dist/plugins/@deepseek-ai/dsh-api-remotes/client.js +260 -20
  6. package/dist/plugins/@deepseek-ai/dsh-client-shortcuts/client.js +12 -7
  7. package/dist/plugins/@deepseek-ai/dsh-client-ui-agent-preset/client.js +9 -20
  8. package/dist/plugins/@deepseek-ai/dsh-client-ui-chat/client.js +90 -126
  9. package/dist/plugins/@deepseek-ai/dsh-client-ui-commands/client.js +111 -50
  10. package/dist/plugins/@deepseek-ai/dsh-client-ui-conversation/client.js +14 -1
  11. package/dist/plugins/@deepseek-ai/dsh-client-ui-deliverables/client.js +3 -3
  12. package/dist/plugins/@deepseek-ai/dsh-client-ui-model-selection/client.js +216 -63
  13. package/dist/plugins/@deepseek-ai/dsh-client-ui-open-in-app/client.js +37 -23
  14. package/dist/plugins/@deepseek-ai/dsh-client-ui-plan/client.js +4 -4
  15. package/dist/plugins/@deepseek-ai/dsh-client-ui-renderer/client.js +1 -1
  16. package/dist/plugins/@deepseek-ai/dsh-client-ui-settings-general/client.js +7 -7
  17. package/dist/plugins/@deepseek-ai/dsh-client-ui-shortcuts/client.js +1 -1
  18. package/dist/plugins/@deepseek-ai/dsh-client-ui-sidebar/client.js +10 -15
  19. package/dist/plugins/@deepseek-ai/dsh-client-ui-sidebar-files/client.js +9 -4
  20. package/dist/plugins/@deepseek-ai/dsh-client-ui-sidebar-right/client.js +183 -156
  21. package/dist/plugins/@deepseek-ai/dsh-client-ui-skill/client.js +1 -1
  22. package/dist/plugins/@deepseek-ai/dsh-client-ui-theme/client.js +6 -6
  23. package/dist/plugins/@deepseek-ai/dsh-client-ui-tool/client.js +304 -54
  24. package/dist/plugins/@deepseek-ai/dsh-client-ui-user-questions/client.js +1257 -218
  25. package/dist/plugins/@deepseek-ai/dsh-client-ui-workflow-run/client.js +1 -1
  26. package/dist/plugins/@deepseek-ai/dsh-client-ui-workspace/client.js +3 -2
  27. package/package.json +93 -93
  28. package/worker/direct/index.js +945 -891
  29. package/worker/isolated/index.js +809 -755
  30. package/dist/assets/index-Cq6ljTv2.css +0 -1
  31. package/dist/assets/index-Dy0OhsZ5.js +0 -127
@@ -8,6 +8,16 @@ window.__ModuleLoader__.load({
8
8
  let react_jsx_runtime = require("react/jsx-runtime");
9
9
  let react = require("react");
10
10
  let _deepseek_ai_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
11
+ //#region ../../util/brand/src/index.ts
12
+ /**
13
+ * Apply a compile-time string brand without changing the value.
14
+ * @param value - string admitted by the domain that owns the target brand.
15
+ * @returns the same string with the requested compile-time brand.
16
+ */
17
+ function brandString(value) {
18
+ return value;
19
+ }
20
+ //#endregion
11
21
  //#region lib/types/client/contract/slots.js
12
22
  function settlePendingComposer(settle, failureMessage) {
13
23
  try {
@@ -49,107 +59,366 @@ window.__ModuleLoader__.load({
49
59
  ...decline === void 0 ? {} : { decline }
50
60
  };
51
61
  }
62
+ /** Reload-unique prefix so an unnamed legacy card cannot reuse a persisted draft. */
63
+ const unnamedQuestionPrefix = Array.from(globalThis.crypto.getRandomValues(new Uint8Array(16)), (byte) => byte.toString(16).padStart(2, "0")).join("");
52
64
  let nextQuestionKey = 0;
65
+ const rejectionMessages = {
66
+ ASK_ABORTED: "ask_user_question was aborted before the user answered",
67
+ ASK_CANCELLED: "the user cancelled ask_user_question",
68
+ ASK_TIMED_OUT: "ask_user_question timed out before the user answered"
69
+ };
53
70
  /** Create a wire-preserved user-question rejection. */
54
- function questionError(message, code) {
55
- const error = new Error(message);
71
+ function questionError(code) {
72
+ const error = new Error(rejectionMessages[code]);
56
73
  error.name = "UserQuestionError";
57
74
  error.code = code;
58
75
  return error;
59
76
  }
60
- /** One answerable Client presentation of a pending Host waterfall. */
61
- var PendingQuestion = class {
62
- sessionId;
77
+ /**
78
+ * Create the deferred one Remote Event listener settles through a card.
79
+ * The request signal ends the channel with `ASK_ABORTED`; the Host ignores that
80
+ * outcome for an event it already finished, so a cancel frame loses nothing.
81
+ * @param deadline - Client-clock deadline in epoch milliseconds derived from the business claim's remaining duration.
82
+ * @param signal - Delivery lifetime of the forwarded request.
83
+ * @param onSettle - Called once with the channel when it settles or aborts.
84
+ * @returns The channel to attach and the promise the listener awaits.
85
+ */
86
+ function createWaterfallRequest(deadline, signal, onSettle) {
87
+ const completion = Promise.withResolvers();
88
+ const delegated = Symbol("pending question delegated");
89
+ let settled = false;
90
+ const finish = (settle) => {
91
+ if (settled) return;
92
+ settled = true;
93
+ signal?.removeEventListener("abort", onAbort);
94
+ settle();
95
+ onSettle(channel);
96
+ };
97
+ const onAbort = () => {
98
+ finish(() => {
99
+ completion.reject(questionError("ASK_ABORTED"));
100
+ });
101
+ };
102
+ const channel = {
103
+ deadline,
104
+ resolve: (answer) => {
105
+ finish(() => {
106
+ completion.resolve(answer);
107
+ });
108
+ },
109
+ reject: (code) => {
110
+ finish(() => {
111
+ completion.reject(questionError(code));
112
+ });
113
+ },
114
+ delegate: () => {
115
+ finish(() => {
116
+ completion.reject(delegated);
117
+ });
118
+ }
119
+ };
120
+ if (signal !== void 0) {
121
+ signal.addEventListener("abort", onAbort, { once: true });
122
+ if (signal.aborted) onAbort();
123
+ }
124
+ return {
125
+ channel,
126
+ result: completion.promise,
127
+ isDelegation: (reason) => reason === delegated
128
+ };
129
+ }
130
+ /**
131
+ * One answerable Client card. A card keyed by tool call is created by whichever
132
+ * source arrives first, the forwarded waterfall or the Session projection, and
133
+ * removed only when the projection no longer lists the call.
134
+ */
135
+ var PendingQuestion = class PendingQuestion {
63
136
  /** Presentation discriminator used by Session pending-interaction consumers. */
64
137
  kind;
65
- /** Opaque render identity and request key for the Session-scoped draft store. */
138
+ /** Render identity and request key for the Session-scoped draft store. */
66
139
  key;
140
+ /** Agent/Session identity owning the request. */
141
+ sessionId;
67
142
  /** The request's question list. */
68
143
  questions;
69
- /** Result returned by the Remote Event listener to the Host waterfall. */
70
- result;
71
- #resolve;
72
- #reject;
73
- #signal;
74
- #onAbort;
75
- #delegated = Symbol("pending question delegated");
76
- #settled = false;
144
+ /** Tool call identity; absent for a blocking request that carried no `wait`. */
145
+ callId;
77
146
  /**
78
- * @param sessionId - Agent/Session identity owning the scoped request.
147
+ * Recorded answers of a call that already settled. Present only on a
148
+ * read-only review card, which the tool call row builds from its own
149
+ * transcript so a finished question can be read back in the panel that
150
+ * asked it. Such a card has no answer channel and no countdown.
151
+ */
152
+ review;
153
+ /**
154
+ * What closing the panel does. A card keyed by tool call stays reachable
155
+ * from its tool call row, so closing only withdraws the panel (`hide`) and
156
+ * persists nothing. A card the Host never named has no way back, so closing
157
+ * it ends the request (`cancel`).
158
+ */
159
+ dismissal;
160
+ #state = "open";
161
+ #waterfall;
162
+ #rpc;
163
+ #seat;
164
+ #timedWait = false;
165
+ #timer;
166
+ #deadline;
167
+ #remainingMs;
168
+ #focused = false;
169
+ #engaged = false;
170
+ #held = false;
171
+ #closed = false;
172
+ #siblings;
173
+ #listeners = /* @__PURE__ */ new Set();
174
+ #snapshot;
175
+ /**
176
+ * @param sessionId - Agent/Session identity owning the request.
79
177
  * @param questions - complete question batch.
80
- * @param signal - Host request and delivery lifetime.
178
+ * @param callId - tool call identity when the Host named one.
179
+ * @param siblings - keys of every card currently registered for the Session, for draft pruning.
180
+ * @param review - recorded answers of a settled call, making this a read-only card.
81
181
  */
82
- constructor(sessionId, questions, signal) {
182
+ constructor(sessionId, questions, callId, siblings, review) {
83
183
  this.sessionId = sessionId;
84
- nextQuestionKey += 1;
85
- this.key = `question:${String(nextQuestionKey)}`;
86
184
  this.questions = questions;
87
185
  this.kind = planReviewOf(questions) === void 0 ? "question" : "plan-review";
88
- const completion = Promise.withResolvers();
89
- this.result = completion.promise;
90
- this.#resolve = completion.resolve;
91
- this.#reject = completion.reject;
92
- this.#signal = signal;
93
- if (signal === void 0) {
94
- this.#onAbort = void 0;
186
+ this.callId = callId;
187
+ this.review = review;
188
+ this.dismissal = callId === void 0 ? "cancel" : "hide";
189
+ this.#siblings = siblings;
190
+ if (callId === void 0) nextQuestionKey += 1;
191
+ this.key = callId === void 0 ? `question:${unnamedQuestionPrefix}:${String(nextQuestionKey)}` : PendingQuestion.keyOf(sessionId, callId);
192
+ this.#snapshot = this.createSnapshot();
193
+ }
194
+ /**
195
+ * Card key of a tool call, shared by every source that names one. The Host
196
+ * request and the Session projection carry the branded `ToolCallId`; a
197
+ * transcript row carries the same wire value as a plain string.
198
+ * @param sessionId - owning Session.
199
+ * @param callId - tool call identity, branded or as a transcript spells it.
200
+ * @returns the render identity and draft key.
201
+ */
202
+ static keyOf(sessionId, callId) {
203
+ return `question:${String(sessionId)}:${callId}`;
204
+ }
205
+ /**
206
+ * Draft keys that are still live in this Session, this card included.
207
+ * @returns keys the draft store must keep; everything else is stale.
208
+ */
209
+ liveKeys() {
210
+ return this.#siblings?.() ?? [this.key];
211
+ }
212
+ /** Subscribe to card state changes. */
213
+ subscribe = (listener) => {
214
+ this.#listeners.add(listener);
215
+ return () => {
216
+ this.#listeners.delete(listener);
217
+ };
218
+ };
219
+ /** Read the stable current card state. */
220
+ snapshot = () => this.#snapshot;
221
+ /** Observable snapshot read by the renderer's keyed Hook. */
222
+ getSnapshot = this.snapshot;
223
+ createSnapshot() {
224
+ const channel = this.#waterfall !== void 0 ? "waterfall" : this.#state === "continued" && this.#rpc !== void 0 ? "rpc" : "none";
225
+ const waitState = this.#state === "continued" ? "continued" : this.#held ? "waiting" : this.#engaged ? "editing" : this.#focused ? "focused" : "counting";
226
+ return {
227
+ state: this.#state,
228
+ waitState,
229
+ countdown: this.#timedWait ? {
230
+ remainingMs: this.#deadline === void 0 ? this.#remainingMs ?? 0 : Math.max(0, this.#deadline - Date.now()),
231
+ running: this.#deadline !== void 0
232
+ } : void 0,
233
+ channel,
234
+ closed: this.#closed
235
+ };
236
+ }
237
+ publish() {
238
+ this.#snapshot = this.createSnapshot();
239
+ this.#reschedule();
240
+ for (const listener of this.#listeners) listener();
241
+ }
242
+ /**
243
+ * Own the countdown here rather than in a mounted component: the panel can be
244
+ * hidden and remounted while the request stands, and a timer that died with
245
+ * the component would leave the tool call waiting past its deadline.
246
+ */
247
+ #reschedule() {
248
+ const wanted = this.#deadline !== void 0 && !this.#closed;
249
+ if (wanted === (this.#timer !== void 0)) return;
250
+ if (!wanted) {
251
+ clearInterval(this.#timer);
252
+ this.#timer = void 0;
95
253
  return;
96
254
  }
97
- const onAbort = () => {
98
- this.abort(questionError("ask_user_question was aborted before the user answered", "ASK_ABORTED"));
99
- };
100
- this.#onAbort = onAbort;
101
- signal.addEventListener("abort", onAbort, { once: true });
102
- if (signal.aborted) onAbort();
255
+ this.#timer = setInterval(() => {
256
+ this.#tick();
257
+ }, 1e3);
258
+ }
259
+ #tick() {
260
+ const deadline = this.#deadline;
261
+ /* v8 ignore next -- #reschedule clears the interval in the same publish that drops the deadline. */
262
+ if (deadline === void 0) return;
263
+ if (Date.now() >= deadline) {
264
+ this.timeout();
265
+ return;
266
+ }
267
+ this.publish();
103
268
  }
104
269
  /**
105
- * Resolve the Host waterfall with the whole answer batch.
106
- * @param answer - complete structured answer batch.
270
+ * Attach the live waterfall of a forwarded request.
271
+ * @param channel - request channel created by {@link createWaterfallRequest}.
107
272
  */
108
- answer(answer) {
109
- return settlePendingComposer(() => {
110
- this.finish(() => {
111
- this.#resolve(answer);
112
- });
113
- }, "pending question settlement failed");
273
+ attachWaterfall(channel) {
274
+ this.#waterfall = channel;
275
+ this.#timedWait = channel.deadline !== void 0;
276
+ if (!this.#held && !this.#engaged) {
277
+ this.#deadline = channel.deadline;
278
+ if (this.#focused && channel.deadline !== void 0) {
279
+ this.#remainingMs = Math.max(0, channel.deadline - Date.now());
280
+ this.#deadline = void 0;
281
+ }
282
+ }
283
+ this.publish();
114
284
  }
115
- /** Delegate an unanswered request to the next waterfall listener. */
116
- delegate() {
117
- if (this.#settled) return;
118
- this.finish(() => {
119
- this.#reject(this.#delegated);
120
- });
285
+ /**
286
+ * Drop a waterfall channel that settled or was cancelled; the card stays.
287
+ * @param channel - the channel that ended.
288
+ */
289
+ detachWaterfall(channel) {
290
+ if (this.#waterfall !== channel) return;
291
+ this.#waterfall = void 0;
292
+ this.#timedWait = false;
293
+ this.#deadline = void 0;
294
+ this.publish();
121
295
  }
122
296
  /**
123
- * Test whether a rejection requests waterfall delegation.
124
- * @param reason - rejection received from {@link PendingQuestion.result}.
125
- * @returns whether {@link PendingQuestion.delegate} produced it.
297
+ * Whether a live waterfall is attached.
298
+ * @returns whether the pending Host request still accepts settlement.
126
299
  */
127
- isDelegation(reason) {
128
- return reason === this.#delegated;
300
+ hasWaterfall() {
301
+ return this.#waterfall !== void 0;
129
302
  }
130
- /** Reject the Host waterfall because the user closed the question. */
131
- cancel() {
132
- return settlePendingComposer(() => {
133
- this.finish(() => {
134
- this.#reject(questionError("the user cancelled ask_user_question", "ASK_CANCELLED"));
135
- });
136
- }, "pending question cancellation failed");
303
+ /**
304
+ * Attach the Remote answer path used once the question is continued.
305
+ * @param channel - Remote calls bound to this Session and call.
306
+ */
307
+ attachRpc(channel) {
308
+ this.#rpc = channel;
309
+ this.publish();
310
+ }
311
+ /**
312
+ * Attach the composer seat this card is published into.
313
+ * @param seat - withdrawal of the published panel, owned by the card registry.
314
+ */
315
+ attachSeat(seat) {
316
+ this.#seat = seat;
317
+ }
318
+ /**
319
+ * Copy the projection row state.
320
+ * @param state - `open` or `continued`.
321
+ */
322
+ setState(state) {
323
+ if (this.#state === state) return;
324
+ this.#state = state;
325
+ this.publish();
326
+ }
327
+ /** Stop this Client's countdown indefinitely; the waterfall then waits like a blocking question. */
328
+ takeTime() {
329
+ if (this.#held) return;
330
+ this.#held = true;
331
+ this.#focused = false;
332
+ this.#remainingMs = void 0;
333
+ this.#deadline = void 0;
334
+ this.publish();
335
+ }
336
+ /**
337
+ * Record focus even before the request arrives, freezing a pristine countdown once attached.
338
+ * @param now - current Client epoch time.
339
+ */
340
+ holdFocus(now = Date.now()) {
341
+ if (this.#held || this.#engaged || this.#focused) return;
342
+ this.#remainingMs = this.#deadline === void 0 ? void 0 : Math.max(0, this.#deadline - now);
343
+ this.#deadline = void 0;
344
+ this.#focused = true;
345
+ this.publish();
137
346
  }
138
347
  /**
139
- * End an unanswered presentation when its transport, scope, or plugin lifetime ends.
140
- * @param reason - rejection exposed to the waiting Remote Event listener.
348
+ * Resume a pristine countdown after the answer surface loses focus.
349
+ * @param now - current Client epoch time.
141
350
  */
142
- abort(reason) {
143
- if (this.#settled) return;
144
- this.finish(() => {
145
- this.#reject(reason);
351
+ releaseFocus(now = Date.now()) {
352
+ if (!this.#focused) return;
353
+ this.#focused = false;
354
+ this.#deadline = this.#timedWait && this.#remainingMs !== void 0 ? now + this.#remainingMs : void 0;
355
+ this.#remainingMs = void 0;
356
+ this.publish();
357
+ }
358
+ /**
359
+ * Keep the first edited draft answerable without a foreground deadline.
360
+ * @param now - current Client epoch time used to preserve the remaining duration.
361
+ */
362
+ engage(now = Date.now()) {
363
+ if (this.#held || this.#engaged) return;
364
+ if (this.#remainingMs === void 0 && this.#deadline !== void 0) this.#remainingMs = Math.max(0, this.#deadline - now);
365
+ this.#engaged = true;
366
+ this.#focused = false;
367
+ this.#deadline = void 0;
368
+ this.publish();
369
+ }
370
+ /** Local countdown reached zero: settle the waterfall with `ASK_TIMED_OUT`, keep the card. */
371
+ timeout() {
372
+ if (this.#held || this.#engaged || this.#focused) return;
373
+ const channel = this.#waterfall;
374
+ if (channel === void 0) return;
375
+ this.#waterfall = void 0;
376
+ this.#timedWait = false;
377
+ this.#deadline = void 0;
378
+ channel.reject("ASK_TIMED_OUT");
379
+ this.publish();
380
+ }
381
+ /** Hand a live waterfall to the next listener when this presentation domain unloads. */
382
+ delegate() {
383
+ this.#waterfall?.delegate();
384
+ }
385
+ /** Mark the card removed from the registry; the mounted composer clears its draft. */
386
+ close() {
387
+ if (this.#closed) return;
388
+ this.#closed = true;
389
+ this.publish();
390
+ }
391
+ /**
392
+ * Submit the whole answer batch through the live waterfall, or through the
393
+ * Remote path once the question is continued.
394
+ * @param answer - complete structured answer batch.
395
+ */
396
+ answer(answer) {
397
+ const waterfall = this.#waterfall;
398
+ if (waterfall !== void 0) return settlePendingComposer(() => {
399
+ waterfall.resolve(answer);
400
+ }, "pending question settlement failed");
401
+ const rpc = this.#rpc;
402
+ if (this.#state === "continued" && rpc !== void 0) return rpc.answer(answer).then((accepted) => {
403
+ if (!accepted) throw new Error("this question is no longer answerable");
146
404
  });
405
+ return Promise.reject(/* @__PURE__ */ new Error("no channel accepts an answer yet"));
147
406
  }
148
- finish(settle) {
149
- if (this.#settled) throw new Error(`pending question ${this.key} is already settled`);
150
- this.#settled = true;
151
- if (this.#signal !== void 0 && this.#onAbort !== void 0) this.#signal.removeEventListener("abort", this.#onAbort);
152
- settle();
407
+ /**
408
+ * Close the panel. A tool-call-keyed card only leaves the composer seat: the
409
+ * request stands, the countdown keeps running here, and the tool call row
410
+ * reopens it. A card the Host never named ends its request instead, because
411
+ * nothing could bring it back.
412
+ */
413
+ dismiss() {
414
+ if (this.dismissal === "hide") return settlePendingComposer(() => {
415
+ this.#seat?.hide();
416
+ }, "pending question hide failed");
417
+ const waterfall = this.#waterfall;
418
+ if (waterfall === void 0) return Promise.reject(/* @__PURE__ */ new Error("no channel accepts a cancellation yet"));
419
+ return settlePendingComposer(() => {
420
+ waterfall.reject("ASK_CANCELLED");
421
+ }, "pending question cancellation failed");
153
422
  }
154
423
  };
155
424
  //#endregion
@@ -159,26 +428,25 @@ window.__ModuleLoader__.load({
159
428
  * registry owns store instances; this module exports only the factory so a
160
429
  * plugin reload cannot reuse a module-global handle.
161
430
  */
162
- const emptyProgress = () => ({
163
- index: 0,
164
- drafts: []
165
- });
166
431
  /**
167
- * Declare the question composer's transient Session store.
168
- * @returns a non-persisted store handle whose instance is owned by the Slot registry.
432
+ * Declare the question composer's Session store. Drafts persist per Session so
433
+ * leaving the Session or restarting the Client does not erase an unfinished answer.
434
+ * @returns a persisted store handle whose instance is owned by the Slot registry.
169
435
  */
170
436
  function createQuestionDraftStore() {
171
437
  return (0, _deepseek_ai_dsh_client_store.defineStore)({
172
- init: () => ({ progress: emptyProgress() }),
438
+ init: () => ({ progressByRequest: {} }),
439
+ persist: "dsh.user-questions.drafts.v1",
173
440
  actions: {
174
441
  replace: (draft, requestKey, progress) => {
175
- draft.requestKey = requestKey;
176
- draft.progress = progress;
442
+ draft.progressByRequest[requestKey] = progress;
177
443
  },
178
444
  clear: (draft, requestKey) => {
179
- if (draft.requestKey !== requestKey) return;
180
- delete draft.requestKey;
181
- draft.progress = emptyProgress();
445
+ draft.progressByRequest = Object.fromEntries(Object.entries(draft.progressByRequest).filter(([key]) => key !== requestKey));
446
+ },
447
+ prune: (draft, keep) => {
448
+ const live = new Set(keep);
449
+ draft.progressByRequest = Object.fromEntries(Object.entries(draft.progressByRequest).filter(([key]) => live.has(key)));
182
450
  }
183
451
  }
184
452
  });
@@ -200,13 +468,13 @@ window.__ModuleLoader__.load({
200
468
  }
201
469
  //#endregion
202
470
  //#region \0dsh-css:/home/runner/work/deepseek-harness/deepseek-harness/packages/client/ui-user-questions/src/client/PlanReviewPanel.module.css.mjs
203
- const css$1 = ".LVzXQa_frame{padding:6px calc(var(--dsh-composer-side-clearance) + 16px) 10px;justify-content:center;display:flex}.LVzXQa_card{width:100%;max-width:var(--dsh-chat-content-width);--dsw-elevation-stroke-color:var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-xl);background:var(--dsw-specific-input-major);box-shadow:var(--dsw-elevation-panel);color:var(--dsw-alias-label-primary);border:0;flex-direction:column;display:flex;overflow:hidden}.LVzXQa_card,.LVzXQa_card *{box-sizing:border-box}.LVzXQa_strip{background:var(--dsw-alias-state-warn-tertiary);color:var(--dsw-alias-state-warn-primary);flex-shrink:0;align-items:center;gap:8px;padding:12px 16px;font-size:14px;line-height:20px;display:flex}.LVzXQa_footer{flex-shrink:0;justify-content:space-between;align-items:center;gap:12px;padding:8px 16px 12px;display:flex}.LVzXQa_feedback{min-height:16px;color:var(--dsw-alias-state-error-primary);font-size:11px;line-height:16px}.LVzXQa_actions{flex-shrink:0;align-items:center;gap:8px;display:flex}.LVzXQa_summary{min-width:0;padding:14px 16px 12px}.LVzXQa_title{text-overflow:ellipsis;white-space:nowrap;margin:0;font-size:15px;font-weight:500;line-height:22px;overflow:hidden}.LVzXQa_description{-webkit-line-clamp:2;color:var(--dsw-alias-label-secondary);-webkit-box-orient:vertical;margin:8px 0 0;font-size:14px;line-height:24px;display:-webkit-box;overflow:hidden}.LVzXQa_discuss{gap:6px}@media (width<=720px){.LVzXQa_card{border-radius:var(--dsw-radius-xl)}.LVzXQa_footer{align-items:flex-end;padding:8px 12px 10px}}.LVzXQa_previewActions{align-items:center;margin-left:auto;display:flex}";
204
- const tagId$1 = "@deepseek-ai/dsh-client-ui-user-questions/PlanReviewPanel.module.css";
205
- if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) {
471
+ const css$2 = ".LVzXQa_frame{padding:6px calc(var(--dsh-composer-side-clearance) + 16px) 10px;justify-content:center;display:flex}.LVzXQa_card{width:100%;max-width:var(--dsh-chat-content-width);--dsw-elevation-stroke-color:var(--dsw-alias-border-l2);border-radius:var(--dsw-radius-xl);background:var(--dsw-specific-input-major);box-shadow:var(--dsw-elevation-panel);color:var(--dsw-alias-label-primary);border:0;flex-direction:column;display:flex;overflow:hidden}.LVzXQa_card,.LVzXQa_card *{box-sizing:border-box}.LVzXQa_strip{background:var(--dsw-alias-state-warn-tertiary);color:var(--dsw-alias-state-warn-primary);flex-shrink:0;align-items:center;gap:8px;padding:12px 16px;font-size:14px;line-height:20px;display:flex}.LVzXQa_footer{flex-shrink:0;justify-content:space-between;align-items:center;gap:12px;padding:8px 16px 12px;display:flex}.LVzXQa_feedback{min-height:16px;color:var(--dsw-alias-state-error-primary);font-size:11px;line-height:16px}.LVzXQa_actions{flex-shrink:0;align-items:center;gap:8px;display:flex}.LVzXQa_summary{min-width:0;padding:14px 16px 12px}.LVzXQa_title{text-overflow:ellipsis;white-space:nowrap;margin:0;font-size:15px;font-weight:500;line-height:22px;overflow:hidden}.LVzXQa_description{-webkit-line-clamp:2;color:var(--dsw-alias-label-secondary);-webkit-box-orient:vertical;margin:8px 0 0;font-size:14px;line-height:24px;display:-webkit-box;overflow:hidden}.LVzXQa_discuss{gap:6px}@media (width<=720px){.LVzXQa_card{border-radius:var(--dsw-radius-xl)}.LVzXQa_footer{align-items:flex-end;padding:8px 12px 10px}}.LVzXQa_previewActions{align-items:center;margin-left:auto;display:flex}";
472
+ const tagId$2 = "@deepseek-ai/dsh-client-ui-user-questions/PlanReviewPanel.module.css";
473
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$2) + "]") === null) {
206
474
  const tag = document.createElement("style");
207
475
  tag.dataset.plugin = "@deepseek-ai/dsh-client-ui-user-questions";
208
- tag.dataset.pluginCss = tagId$1;
209
- tag.textContent = css$1;
476
+ tag.dataset.pluginCss = tagId$2;
477
+ tag.textContent = css$2;
210
478
  document.head.appendChild(tag);
211
479
  }
212
480
  var PlanReviewPanel_module_css_default = {
@@ -243,10 +511,16 @@ window.__ModuleLoader__.load({
243
511
  function PlanReviewPanel({ pending, review, t, renderSlot }) {
244
512
  const [busy, setBusy] = (0, react.useState)(false);
245
513
  const [error, setError] = (0, react.useState)(null);
246
- const settle = (send) => {
514
+ const settle = (send, remote = false) => {
247
515
  setBusy(true);
248
516
  setError(null);
249
- send().catch((cause) => {
517
+ send().then(() => {
518
+ if (!remote) return;
519
+ setBusy(false);
520
+ pending.dismiss().catch(() => {
521
+ setError(t("status.sent"));
522
+ });
523
+ }).catch((cause) => {
250
524
  setBusy(false);
251
525
  setError(cause instanceof Error ? cause.message : String(cause));
252
526
  });
@@ -255,7 +529,7 @@ window.__ModuleLoader__.load({
255
529
  settle(() => pending.answer({ answers: [{
256
530
  id: review.id,
257
531
  selected: [label]
258
- }] }));
532
+ }] }), pending.snapshot().channel === "rpc");
259
533
  };
260
534
  const summary = (0, react.useMemo)(() => {
261
535
  const title = (0, _deepseek_ai_dsh_client_ui_primitives.extractMarkdownPlainText)(review.plan, { mode: "first-line" });
@@ -311,7 +585,7 @@ window.__ModuleLoader__.load({
311
585
  icon: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconEditOutlineRegular, { size: 14 }),
312
586
  disabled: busy,
313
587
  onClick: () => {
314
- settle(() => pending.cancel());
588
+ settle(() => pending.dismiss());
315
589
  },
316
590
  children: t("plan.discuss")
317
591
  }), (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
@@ -331,13 +605,13 @@ window.__ModuleLoader__.load({
331
605
  }
332
606
  //#endregion
333
607
  //#region \0dsh-css:/home/runner/work/deepseek-harness/deepseek-harness/packages/client/ui-user-questions/src/client/QuestionComposer.module.css.mjs
334
- const css = ".Mbwy4a_frame{padding:6px calc(var(--dsh-composer-side-clearance) + 16px) 10px;justify-content:center;display:flex}.Mbwy4a_card{width:100%;max-width:var(--dsh-chat-content-width);--dsw-elevation-stroke-color:var(--dsw-alias-border-l2-darkmode-thin);border-radius:var(--dsw-radius-xl);background:var(--dsw-specific-input-major);max-height:min(60vh,520px);box-shadow:var(--dsw-elevation-panel);color:var(--dsw-alias-label-primary);--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2);--dsh-scrollbar-thumb-hover:var(--dsw-alias-scrollbar-hover-l2);border:0;flex-direction:column;padding:0 0 10px;display:flex;overflow:hidden}.Mbwy4a_card,.Mbwy4a_card *{box-sizing:border-box}.Mbwy4a_cardMinimized{max-height:none}.Mbwy4a_cardMinimized .Mbwy4a_header{padding-bottom:14px}.Mbwy4a_headerActions{flex-shrink:0;align-items:center;gap:4px;display:flex}.Mbwy4a_header{flex-shrink:0;justify-content:space-between;align-items:flex-start;gap:16px;padding:20px 16px 0 24px;display:flex}.Mbwy4a_headingBlock{min-width:0}.Mbwy4a_eyebrow{color:var(--dsw-alias-label-tertiary);margin-bottom:5px;font-size:11px;line-height:16px}.Mbwy4a_title{margin:0;font-size:16px;font-weight:500;line-height:22px}.Mbwy4a_detail{margin:0 2px 8px}.Mbwy4a_footerActions{flex-shrink:0;align-items:center;gap:12px;display:flex}.Mbwy4a_pager{flex-shrink:0;align-items:center;gap:6px;display:flex}.Mbwy4a_progress{color:var(--dsw-alias-label-secondary);white-space:nowrap;word-spacing:-2px;padding:0 4px;font-size:14px;font-weight:500;line-height:24px}.Mbwy4a_iconButton{corner-shape:round;width:24px;height:24px;color:var(--dsw-alias-label-tertiary);cursor:pointer;background:0 0;border:none;border-radius:999px;place-items:center;padding:0;display:grid}.Mbwy4a_iconButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.Mbwy4a_iconButton:disabled{color:var(--dsw-alias-label-dimmed);cursor:default}.Mbwy4a_body{overscroll-behavior:contain;flex-direction:column;flex:auto;min-height:0;display:flex;overflow-y:auto}.Mbwy4a_options{flex-direction:column;gap:1px;margin:8px 0 0;padding:4px 12px;display:flex}.Mbwy4a_option{border-radius:var(--dsw-radius-md);width:100%;min-height:40px;color:inherit;text-align:left;cursor:pointer;background:0 0;border:1px solid #0000;flex-shrink:0;align-items:flex-start;gap:8px;padding:8px 12px 8px 8px;transition:background-color .12s,border-color .12s;display:flex}.Mbwy4a_option:hover:not(:disabled),.Mbwy4a_optionSelected{background:var(--dsw-alias-interactive-bg-hover)}.Mbwy4a_optionSelected{border-color:var(--dsw-alias-border-l2)}.Mbwy4a_option:disabled{cursor:default}.Mbwy4a_number{border-radius:var(--dsw-radius-xs);background:var(--dsw-alias-bg-overlay);width:20px;height:20px;color:var(--dsw-alias-label-secondary);flex:0 0 20px;place-items:center;margin-top:2px;font-size:12px;font-weight:500;line-height:18px;display:grid}.Mbwy4a_checkbox{flex:0 0 20px;place-items:center;width:20px;height:20px;margin-top:2px;display:grid}.Mbwy4a_checkbox:before{content:\"\";border:.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-xs);grid-area:1/1;width:14px;height:14px;transition:background-color .12s,border-color .12s}.Mbwy4a_checkbox>svg{grid-area:1/1}.Mbwy4a_checkboxChecked{color:var(--dsw-alias-label-primary-foreground)}.Mbwy4a_checkboxChecked:before{border-color:var(--dsw-alias-label-primary);background:var(--dsw-alias-label-primary)}.Mbwy4a_optionCopy{flex:1;min-width:0}.Mbwy4a_optionLine{flex-wrap:wrap;align-items:baseline;gap:2px 6px;display:flex}.Mbwy4a_optionLabel{font-size:14px;font-weight:500;line-height:24px}.Mbwy4a_badge{border-radius:var(--dsw-radius-xs);background:var(--dsw-specific-sidebar-nav-item-active-accent);color:var(--dsw-alias-button-info-fill);padding:0 4px;font-size:11px;font-weight:600;line-height:18px}.Mbwy4a_description{color:var(--dsw-alias-label-tertiary);font-size:14px;font-weight:400;line-height:24px}.Mbwy4a_customRow{border-radius:var(--dsw-radius-md);border:1px solid #0000;flex-shrink:0;align-items:flex-start;gap:8px;width:100%;min-height:40px;padding:8px 12px 8px 8px;transition:background-color .12s,border-color .12s;display:flex}.Mbwy4a_customRow:hover,.Mbwy4a_customRow:focus-within,.Mbwy4a_customRowActive{background:var(--dsw-alias-interactive-bg-hover)}.Mbwy4a_customRow:focus-within,.Mbwy4a_customRowActive{border-color:var(--dsw-alias-border-l2)}.Mbwy4a_field{--dsh-answer-field-padding:0;min-width:0;display:grid}.Mbwy4a_field>*{min-width:0;padding:var(--dsh-answer-field-padding);font:inherit;white-space:pre-wrap;word-break:break-word;overflow-wrap:anywhere;grid-area:1/1;font-size:14px;line-height:24px}.Mbwy4a_fieldMirror{box-sizing:content-box;visibility:hidden;max-height:144px;overflow:hidden}.Mbwy4a_fieldInput{resize:none;color:var(--dsw-alias-label-primary);caret-color:var(--dsw-alias-state-business-primary);background:0 0;border:none;outline:none;overflow-y:auto}.Mbwy4a_fieldInput::placeholder{color:var(--dsw-alias-label-caption)}.Mbwy4a_customInline{flex:1}.Mbwy4a_customBlock{border:.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-bg-module-platform);--dsh-answer-field-padding:8px 12px;flex-shrink:0;min-height:64px;margin:0 12px}.Mbwy4a_customBlock:focus-within{border-color:var(--dsw-alias-state-business-primary)}.Mbwy4a_footer{flex-shrink:0;justify-content:space-between;align-items:center;gap:12px;margin-top:12px;padding:0 10px 0 18px;display:flex}.Mbwy4a_feedback{min-height:16px;color:var(--dsw-alias-state-error-primary);text-align:right;flex:1;font-size:11px;line-height:16px}@media (width<=720px){.Mbwy4a_card{border-radius:var(--dsw-radius-xl)}.Mbwy4a_header{padding:10px 12px 0 18px}.Mbwy4a_options{padding:4px 8px}.Mbwy4a_title{font-size:15px;line-height:21px}.Mbwy4a_option,.Mbwy4a_customRow{padding:8px 6px}.Mbwy4a_footer{align-items:flex-end;padding:0 10px}.Mbwy4a_footerActions{flex-shrink:0}}@media (prefers-reduced-motion:reduce){.Mbwy4a_option,.Mbwy4a_customRow{transition:none}}";
335
- const tagId = "@deepseek-ai/dsh-client-ui-user-questions/QuestionComposer.module.css";
336
- if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
608
+ const css$1 = ".Mbwy4a_frame{padding:6px calc(var(--dsh-composer-side-clearance) + 16px) 10px;justify-content:center;display:flex}.Mbwy4a_card{width:100%;max-width:var(--dsh-chat-content-width);--dsw-elevation-stroke-color:var(--dsw-alias-border-l2-darkmode-thin);border-radius:var(--dsw-radius-xl);background:var(--dsw-specific-input-major);max-height:min(60vh,520px);box-shadow:var(--dsw-elevation-panel);color:var(--dsw-alias-label-primary);--dsh-scrollbar-thumb:var(--dsw-alias-scrollbar-bg-l2);--dsh-scrollbar-thumb-hover:var(--dsw-alias-scrollbar-hover-l2);border:0;flex-direction:column;padding:0 0 10px;display:flex;overflow:hidden}.Mbwy4a_card,.Mbwy4a_card *{box-sizing:border-box}.Mbwy4a_cardMinimized{max-height:none}.Mbwy4a_cardMinimized .Mbwy4a_header{padding-bottom:14px}.Mbwy4a_headerActions{flex-shrink:0;align-items:center;gap:4px;display:flex}.Mbwy4a_waitButton{white-space:nowrap}.Mbwy4a_waitStatus{color:var(--dsw-alias-label-secondary);white-space:nowrap;font-size:12px;line-height:24px}.Mbwy4a_header{flex-shrink:0;justify-content:space-between;align-items:flex-start;gap:16px;padding:20px 16px 0 24px;display:flex}.Mbwy4a_headingBlock{min-width:0}.Mbwy4a_eyebrow{color:var(--dsw-alias-label-tertiary);margin-bottom:5px;font-size:11px;line-height:16px}.Mbwy4a_title{margin:0;font-size:16px;font-weight:500;line-height:22px}.Mbwy4a_detail{margin:0 2px 8px}.Mbwy4a_footerActions{flex-shrink:0;align-items:center;gap:12px;display:flex}.Mbwy4a_pager{flex-shrink:0;align-items:center;gap:6px;display:flex}.Mbwy4a_progress{color:var(--dsw-alias-label-secondary);white-space:nowrap;word-spacing:-2px;padding:0 4px;font-size:14px;font-weight:500;line-height:24px}.Mbwy4a_iconButton{corner-shape:round;width:24px;height:24px;color:var(--dsw-alias-label-tertiary);cursor:pointer;background:0 0;border:none;border-radius:999px;place-items:center;padding:0;display:grid}.Mbwy4a_iconButton:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-primary)}.Mbwy4a_iconButton:disabled{color:var(--dsw-alias-label-dimmed);cursor:default}.Mbwy4a_body{overscroll-behavior:contain;flex-direction:column;flex:auto;min-height:0;display:flex;overflow-y:auto}.Mbwy4a_options{flex-direction:column;gap:1px;margin:8px 0 0;padding:4px 12px;display:flex}.Mbwy4a_option{border-radius:var(--dsw-radius-md);width:100%;min-height:40px;color:inherit;text-align:left;cursor:pointer;background:0 0;border:1px solid #0000;flex-shrink:0;align-items:flex-start;gap:8px;padding:8px 12px 8px 8px;transition:background-color .12s,border-color .12s;display:flex}.Mbwy4a_option:hover:not(:disabled),.Mbwy4a_optionSelected{background:var(--dsw-alias-interactive-bg-hover)}.Mbwy4a_optionSelected{border-color:var(--dsw-alias-border-l2)}.Mbwy4a_option:disabled{cursor:default}.Mbwy4a_number{border-radius:var(--dsw-radius-xs);background:var(--dsw-alias-bg-overlay);width:20px;height:20px;color:var(--dsw-alias-label-secondary);flex:0 0 20px;place-items:center;margin-top:2px;font-size:12px;font-weight:500;line-height:18px;display:grid}.Mbwy4a_checkbox{flex:0 0 20px;place-items:center;width:20px;height:20px;margin-top:2px;display:grid}.Mbwy4a_checkbox:before{content:\"\";border:.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-xs);grid-area:1/1;width:14px;height:14px;transition:background-color .12s,border-color .12s}.Mbwy4a_checkbox>svg{grid-area:1/1}.Mbwy4a_checkboxChecked{color:var(--dsw-alias-label-primary-foreground)}.Mbwy4a_checkboxChecked:before{border-color:var(--dsw-alias-label-primary);background:var(--dsw-alias-label-primary)}.Mbwy4a_optionCopy{flex:1;min-width:0}.Mbwy4a_optionLine{flex-wrap:wrap;align-items:baseline;gap:2px 6px;display:flex}.Mbwy4a_optionLabel{font-size:14px;font-weight:500;line-height:24px}.Mbwy4a_badge{border-radius:var(--dsw-radius-xs);background:var(--dsw-specific-sidebar-nav-item-active-accent);color:var(--dsw-alias-button-info-fill);padding:0 4px;font-size:11px;font-weight:600;line-height:18px}.Mbwy4a_description{color:var(--dsw-alias-label-tertiary);font-size:14px;font-weight:400;line-height:24px}.Mbwy4a_reviewNote{color:var(--dsw-alias-label-tertiary);margin:0;padding:8px 12px;font-size:14px;line-height:24px}.Mbwy4a_customRow{border-radius:var(--dsw-radius-md);border:1px solid #0000;flex-shrink:0;align-items:flex-start;gap:8px;width:100%;min-height:40px;padding:8px 12px 8px 8px;transition:background-color .12s,border-color .12s;display:flex}.Mbwy4a_customRow:hover,.Mbwy4a_customRow:focus-within,.Mbwy4a_customRowActive{background:var(--dsw-alias-interactive-bg-hover)}.Mbwy4a_customRow:focus-within,.Mbwy4a_customRowActive{border-color:var(--dsw-alias-border-l2)}.Mbwy4a_field{--dsh-answer-field-padding:0;min-width:0;display:grid}.Mbwy4a_field>*{min-width:0;padding:var(--dsh-answer-field-padding);font:inherit;white-space:pre-wrap;word-break:break-word;overflow-wrap:anywhere;grid-area:1/1;font-size:14px;line-height:24px}.Mbwy4a_fieldMirror{box-sizing:content-box;visibility:hidden;max-height:144px;overflow:hidden}.Mbwy4a_fieldInput{resize:none;color:var(--dsw-alias-label-primary);caret-color:var(--dsw-alias-state-business-primary);background:0 0;border:none;outline:none;overflow-y:auto}.Mbwy4a_fieldInput::placeholder{color:var(--dsw-alias-label-caption)}.Mbwy4a_customInline{flex:1}.Mbwy4a_customBlock{border:.5px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-lg);background:var(--dsw-alias-bg-module-platform);--dsh-answer-field-padding:8px 12px;flex-shrink:0;min-height:64px;margin:0 12px}.Mbwy4a_customBlock:focus-within{border-color:var(--dsw-alias-state-business-primary)}.Mbwy4a_footer{flex-shrink:0;justify-content:space-between;align-items:center;gap:12px;margin-top:12px;padding:0 10px 0 18px;display:flex}.Mbwy4a_feedback{min-height:16px;color:var(--dsw-alias-state-error-primary);text-align:right;flex:1;font-size:11px;line-height:16px}@media (width<=720px){.Mbwy4a_card{border-radius:var(--dsw-radius-xl)}.Mbwy4a_header{padding:10px 12px 0 18px}.Mbwy4a_options{padding:4px 8px}.Mbwy4a_title{font-size:15px;line-height:21px}.Mbwy4a_option,.Mbwy4a_customRow{padding:8px 6px}.Mbwy4a_footer{align-items:flex-end;padding:0 10px}.Mbwy4a_footerActions{flex-shrink:0}}@media (prefers-reduced-motion:reduce){.Mbwy4a_option,.Mbwy4a_customRow{transition:none}}";
609
+ const tagId$1 = "@deepseek-ai/dsh-client-ui-user-questions/QuestionComposer.module.css";
610
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId$1) + "]") === null) {
337
611
  const tag = document.createElement("style");
338
612
  tag.dataset.plugin = "@deepseek-ai/dsh-client-ui-user-questions";
339
- tag.dataset.pluginCss = tagId;
340
- tag.textContent = css;
613
+ tag.dataset.pluginCss = tagId$1;
614
+ tag.textContent = css$1;
341
615
  document.head.appendChild(tag);
342
616
  }
343
617
  var QuestionComposer_module_css_default = {
@@ -374,10 +648,21 @@ window.__ModuleLoader__.load({
374
648
  "options": "Mbwy4a_options",
375
649
  "pager": "Mbwy4a_pager",
376
650
  "progress": "Mbwy4a_progress",
377
- "title": "Mbwy4a_title"
651
+ "reviewNote": "Mbwy4a_reviewNote",
652
+ "title": "Mbwy4a_title",
653
+ "waitButton": "Mbwy4a_waitButton",
654
+ "waitStatus": "Mbwy4a_waitStatus"
378
655
  };
379
656
  //#endregion
380
657
  //#region lib/types/client/QuestionComposer.js
658
+ /** A removed card can remain mounted until the composer seat updates. */
659
+ const REMOVED_CARD = {
660
+ state: "open",
661
+ waitState: "counting",
662
+ countdown: void 0,
663
+ channel: "none",
664
+ closed: true
665
+ };
381
666
  /**
382
667
  * Split the conventional recommendation suffix without changing the answer value.
383
668
  * @param label - Original option label returned if selected.
@@ -393,6 +678,22 @@ window.__ModuleLoader__.load({
393
678
  recommended: false
394
679
  };
395
680
  }
681
+ /** Only a marked first choice is an implicit draft; the user still submits it. */
682
+ function recommendedFirstOption(question) {
683
+ const label = question.options?.[0]?.label;
684
+ return label !== void 0 && parseRecommendedLabel(label).recommended ? label : void 0;
685
+ }
686
+ /** Accept persisted progress only when it still describes this question batch. */
687
+ function isQuestionDraftProgress(value, questionCount) {
688
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
689
+ const progress = value;
690
+ if (typeof progress.index !== "number" || !Number.isInteger(progress.index) || progress.index < 0 || progress.index >= questionCount || !Array.isArray(progress.drafts) || progress.drafts.length !== questionCount || progress.wait !== void 0 && progress.wait !== "editing" && progress.wait !== "waiting") return false;
691
+ return progress.drafts.every((item) => {
692
+ if (typeof item !== "object" || item === null || Array.isArray(item)) return false;
693
+ const draft = item;
694
+ return Array.isArray(draft.selected) && draft.selected.every((label) => typeof label === "string") && typeof draft.custom === "string" && typeof draft.skipped === "boolean";
695
+ });
696
+ }
396
697
  /** Return whether a text-field key event belongs to an active IME composition. */
397
698
  function isComposing(event) {
398
699
  return event.nativeEvent.isComposing || Reflect.get(event.nativeEvent, "keyCode") === 229;
@@ -454,6 +755,7 @@ window.__ModuleLoader__.load({
454
755
  pending: question,
455
756
  t: props.t,
456
757
  useStore: props.useStore,
758
+ useQuestionCard: props.useQuestionCard,
457
759
  actions: props.actions
458
760
  }, question.key) : (0, react_jsx_runtime.jsx)(PlanReviewPanel, {
459
761
  pending: question,
@@ -462,8 +764,9 @@ window.__ModuleLoader__.load({
462
764
  renderSlot: props.renderSlot
463
765
  }, question.key);
464
766
  }
465
- function QuestionFlow({ pending, t, useStore, actions }) {
767
+ function QuestionFlow({ pending, t, useStore, useQuestionCard, actions }) {
466
768
  const questions = pending.questions;
769
+ const review = pending.review;
467
770
  const markdownLabels = (0, react.useMemo)(() => ({
468
771
  code: {
469
772
  copyLabel: t("copy"),
@@ -476,39 +779,127 @@ window.__ModuleLoader__.load({
476
779
  },
477
780
  footnotes: t("markdown.footnotes")
478
781
  }), [t]);
479
- const initialProgress = (0, react.useMemo)(() => ({
480
- index: 0,
481
- drafts: questions.map(() => ({
482
- selected: [],
483
- custom: "",
484
- skipped: false
485
- }))
486
- }), [questions]);
487
- const { index, drafts } = useStore((state) => state.requestKey === pending.key && state.progress.drafts.length === questions.length ? state.progress : void 0) ?? initialProgress;
782
+ const initialDrafts = (0, react.useMemo)(() => {
783
+ const recorded = new Map((review ?? []).map((answer) => [answer.id, answer]));
784
+ return questions.map((item) => {
785
+ const answer = recorded.get(item.id);
786
+ const custom = answer?.custom ?? "";
787
+ const recommended = review === void 0 ? recommendedFirstOption(item) : void 0;
788
+ return {
789
+ selected: answer === void 0 && recommended !== void 0 ? [recommended] : [...answer?.selected ?? []],
790
+ custom,
791
+ skipped: answer !== void 0 && answer.selected.length === 0 && custom === ""
792
+ };
793
+ });
794
+ }, [questions, review]);
795
+ const stored = useStore((state) => state.progressByRequest[pending.key]);
796
+ const validStored = isQuestionDraftProgress(stored, questions.length) ? stored : void 0;
797
+ const storedProgress = review === void 0 ? validStored : void 0;
798
+ const index = validStored?.index ?? 0;
799
+ const drafts = storedProgress?.drafts ?? initialDrafts;
800
+ const restoredWait = storedProgress?.wait ?? (storedProgress?.drafts.some((item, itemIndex) => item.selected.length !== initialDrafts[itemIndex]?.selected.length || item.selected.some((label, labelIndex) => label !== initialDrafts[itemIndex]?.selected[labelIndex]) || item.custom !== "" || item.skipped) === true ? "editing" : void 0);
488
801
  const [busy, setBusy] = (0, react.useState)(null);
489
802
  const [error, setError] = (0, react.useState)(null);
803
+ const card = useQuestionCard(pending.key, (snapshot) => snapshot ?? REMOVED_CARD);
804
+ const canSubmit = card.channel !== "none";
805
+ const locked = busy !== null || review !== void 0;
806
+ const sentVia = (0, react.useRef)(null);
807
+ (0, react.useEffect)(() => {
808
+ if (sentVia.current !== "waterfall" || card.state !== "continued") return;
809
+ sentVia.current = null;
810
+ setBusy(null);
811
+ setError({ key: "error.resubmit" });
812
+ }, [card.state]);
813
+ (0, react.useEffect)(() => {
814
+ if (card.closed) actions.clear(pending.key);
815
+ }, [
816
+ actions,
817
+ card.closed,
818
+ pending.key
819
+ ]);
820
+ (0, react.useEffect)(() => {
821
+ actions.prune(pending.liveKeys());
822
+ }, [actions, pending]);
823
+ const waitDisposition = (0, react.useRef)(restoredWait);
824
+ (0, react.useEffect)(() => {
825
+ if (waitDisposition.current === "waiting") pending.takeTime();
826
+ if (waitDisposition.current === "editing") pending.engage();
827
+ }, [pending]);
828
+ const countdown = card.countdown;
490
829
  const [minimized, setMinimized] = (0, react.useState)(false);
491
830
  const focusedQuestions = (0, react.useRef)(/* @__PURE__ */ new Set());
831
+ const answerSurface = (0, react.useRef)(null);
492
832
  const question = questions[index];
493
833
  const draft = drafts[index];
494
834
  const hasOptions = (question.options?.length ?? 0) > 0;
495
835
  const replaceProgress = (nextIndex, nextDrafts) => {
496
836
  actions.replace(pending.key, {
497
837
  index: nextIndex,
498
- drafts: nextDrafts
838
+ drafts: nextDrafts,
839
+ ...waitDisposition.current === void 0 ? {} : { wait: waitDisposition.current }
499
840
  });
500
841
  };
501
- const cancelFlow = () => {
842
+ const takeTime = () => {
843
+ waitDisposition.current = "waiting";
844
+ pending.takeTime();
845
+ replaceProgress(index, drafts);
846
+ };
847
+ const engage = () => {
848
+ if (waitDisposition.current !== void 0) return;
849
+ waitDisposition.current = "editing";
850
+ pending.engage();
851
+ };
852
+ const focusAnswerSurface = (event) => {
853
+ if (!event.currentTarget.contains(event.relatedTarget)) pending.holdFocus();
854
+ };
855
+ const blurAnswerSurface = (event) => {
856
+ if (!event.currentTarget.contains(event.relatedTarget)) pending.releaseFocus();
857
+ };
858
+ (0, react.useEffect)(() => {
859
+ const release = () => {
860
+ pending.releaseFocus();
861
+ };
862
+ const refocus = () => {
863
+ if (waitDisposition.current === "editing") {
864
+ pending.engage();
865
+ return;
866
+ }
867
+ if (answerSurface.current?.contains(document.activeElement) === true) pending.holdFocus();
868
+ };
869
+ const visibilityChanged = () => {
870
+ if (document.hidden) release();
871
+ else refocus();
872
+ };
873
+ window.addEventListener("blur", release);
874
+ window.addEventListener("focus", refocus);
875
+ document.addEventListener("visibilitychange", visibilityChanged);
876
+ return () => {
877
+ release();
878
+ window.removeEventListener("blur", release);
879
+ window.removeEventListener("focus", refocus);
880
+ document.removeEventListener("visibilitychange", visibilityChanged);
881
+ };
882
+ }, [pending]);
883
+ const dismissFlow = () => {
884
+ if (pending.dismissal === "hide") {
885
+ pending.dismiss();
886
+ return;
887
+ }
888
+ if (!canSubmit) {
889
+ setError({ key: "error.unavailable" });
890
+ return;
891
+ }
502
892
  setBusy("cancel");
503
893
  setError(null);
504
- pending.cancel().then(() => {
505
- actions.clear(pending.key);
506
- }).catch((cause) => {
894
+ sentVia.current = "waterfall";
895
+ pending.dismiss().catch((cause) => {
896
+ sentVia.current = null;
507
897
  setBusy(null);
508
898
  setError({ text: cause instanceof Error ? cause.message : String(cause) });
509
899
  });
510
900
  };
511
901
  const updateDraft = (update, nextIndex = index) => {
902
+ engage();
512
903
  replaceProgress(nextIndex, drafts.map((item, itemIndex) => itemIndex === index ? update(item) : item));
513
904
  setError(null);
514
905
  };
@@ -538,6 +929,10 @@ window.__ModuleLoader__.load({
538
929
  setError({ key: "error.incomplete" });
539
930
  return;
540
931
  }
932
+ if (!canSubmit) {
933
+ setError({ key: "error.unavailable" });
934
+ return;
935
+ }
541
936
  const answer = { answers: questions.map((item, itemIndex) => {
542
937
  const value = values[itemIndex];
543
938
  if (value.skipped) return {
@@ -553,9 +948,18 @@ window.__ModuleLoader__.load({
553
948
  }) };
554
949
  setBusy("answer");
555
950
  setError(null);
951
+ const channel = pending.snapshot().channel;
952
+ sentVia.current = channel === "waterfall" ? "waterfall" : null;
556
953
  pending.answer(answer).then(() => {
557
- actions.clear(pending.key);
954
+ if (channel !== "rpc") return;
955
+ sentVia.current = null;
956
+ setBusy(null);
957
+ setError(null);
958
+ pending.dismiss().catch(() => {
959
+ setError({ key: "status.sent" });
960
+ });
558
961
  }).catch((cause) => {
962
+ sentVia.current = null;
559
963
  setBusy(null);
560
964
  setError({ text: cause instanceof Error ? cause.message : String(cause) });
561
965
  });
@@ -587,6 +991,7 @@ window.__ModuleLoader__.load({
587
991
  continueFlow();
588
992
  };
589
993
  const skipQuestion = () => {
994
+ engage();
590
995
  const nextDrafts = drafts.map((item, itemIndex) => itemIndex === index ? {
591
996
  selected: [],
592
997
  custom: "",
@@ -617,30 +1022,58 @@ window.__ModuleLoader__.load({
617
1022
  })]
618
1023
  }), (0, react_jsx_runtime.jsxs)("div", {
619
1024
  className: QuestionComposer_module_css_default.headerActions,
620
- children: [(0, react_jsx_runtime.jsx)("button", {
621
- type: "button",
622
- className: QuestionComposer_module_css_default.iconButton,
623
- "aria-label": t(minimized ? "nav.maximize" : "nav.minimize"),
624
- title: t(minimized ? "nav.maximize" : "nav.minimize"),
625
- "aria-expanded": !minimized,
626
- disabled: busy !== null,
627
- onClick: () => {
628
- setMinimized((current) => !current);
629
- },
630
- children: minimized ? (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronUpOutlineRegular, {}) : (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineRegular, {})
631
- }), (0, react_jsx_runtime.jsx)("button", {
632
- type: "button",
633
- className: QuestionComposer_module_css_default.iconButton,
634
- "aria-label": t("nav.cancel"),
635
- title: t("nav.cancel"),
636
- disabled: busy !== null,
637
- onClick: cancelFlow,
638
- children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCloseOutlineRegular, {})
639
- })]
1025
+ children: [
1026
+ countdown !== void 0 && card.waitState !== "waiting" && card.waitState !== "editing" && card.waitState !== "continued" && (0, react_jsx_runtime.jsx)("span", {
1027
+ className: QuestionComposer_module_css_default.waitStatus,
1028
+ children: t(countdown.running ? "wait.countdown" : "wait.paused", { seconds: Math.ceil(countdown.remainingMs / 1e3) })
1029
+ }),
1030
+ countdown !== void 0 && card.waitState !== "waiting" && card.waitState !== "editing" && card.waitState !== "continued" && (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
1031
+ variant: "outline",
1032
+ className: QuestionComposer_module_css_default.waitButton,
1033
+ onClick: takeTime,
1034
+ children: t("wait.takeTime")
1035
+ }),
1036
+ card.state === "continued" && (0, react_jsx_runtime.jsx)("span", {
1037
+ className: QuestionComposer_module_css_default.waitStatus,
1038
+ children: t("wait.continued")
1039
+ }),
1040
+ countdown !== void 0 && (card.waitState === "waiting" || card.waitState === "editing") && (0, react_jsx_runtime.jsx)("span", {
1041
+ className: QuestionComposer_module_css_default.waitStatus,
1042
+ children: t("wait.held")
1043
+ }),
1044
+ review !== void 0 && (0, react_jsx_runtime.jsx)("span", {
1045
+ className: QuestionComposer_module_css_default.waitStatus,
1046
+ children: t("review.status")
1047
+ }),
1048
+ (0, react_jsx_runtime.jsx)("button", {
1049
+ type: "button",
1050
+ className: QuestionComposer_module_css_default.iconButton,
1051
+ "aria-label": t(minimized ? "nav.maximize" : "nav.minimize"),
1052
+ title: t(minimized ? "nav.maximize" : "nav.minimize"),
1053
+ "aria-expanded": !minimized,
1054
+ disabled: busy !== null,
1055
+ onClick: () => {
1056
+ setMinimized((current) => !current);
1057
+ },
1058
+ children: minimized ? (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronUpOutlineRegular, {}) : (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineRegular, {})
1059
+ }),
1060
+ (0, react_jsx_runtime.jsx)("button", {
1061
+ type: "button",
1062
+ className: QuestionComposer_module_css_default.iconButton,
1063
+ "aria-label": t(pending.dismissal === "hide" ? "nav.close" : "nav.cancel"),
1064
+ title: t(pending.dismissal === "hide" ? "nav.close" : "nav.cancel"),
1065
+ disabled: busy !== null,
1066
+ onClick: dismissFlow,
1067
+ children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCloseOutlineRegular, {})
1068
+ })
1069
+ ]
640
1070
  })]
641
1071
  }), !minimized && (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(0, react_jsx_runtime.jsxs)("div", {
1072
+ ref: answerSurface,
642
1073
  className: QuestionComposer_module_css_default.body,
643
1074
  "data-question-scroll": true,
1075
+ onFocusCapture: focusAnswerSurface,
1076
+ onBlurCapture: blurAnswerSurface,
644
1077
  children: [question.detail !== void 0 && (0, react_jsx_runtime.jsx)("div", {
645
1078
  className: QuestionComposer_module_css_default.detail,
646
1079
  children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.MarkdownText, {
@@ -650,82 +1083,89 @@ window.__ModuleLoader__.load({
650
1083
  }), (0, react_jsx_runtime.jsxs)("div", {
651
1084
  className: QuestionComposer_module_css_default.options,
652
1085
  role: question.multiSelect === true ? "group" : "radiogroup",
653
- children: [(question.options ?? []).map((option, optionIndex) => {
654
- const selected = draft.selected.includes(option.label);
655
- const display = parseRecommendedLabel(option.label);
656
- return (0, react_jsx_runtime.jsxs)("button", {
657
- type: "button",
658
- className: clsx(QuestionComposer_module_css_default.option, selected && question.multiSelect !== true && QuestionComposer_module_css_default.optionSelected),
659
- role: question.multiSelect === true ? "checkbox" : "radio",
660
- "aria-checked": selected,
661
- "aria-label": display.label,
662
- disabled: busy !== null,
663
- onClick: () => {
664
- choose(option.label);
665
- },
666
- onKeyDown: (event) => {
667
- if (event.key !== "Enter" || !drafts.every(completed)) return;
668
- event.preventDefault();
669
- submitDrafts(drafts);
670
- },
1086
+ children: [
1087
+ (question.options ?? []).map((option, optionIndex) => {
1088
+ const selected = draft.selected.includes(option.label);
1089
+ const display = parseRecommendedLabel(option.label);
1090
+ return (0, react_jsx_runtime.jsxs)("button", {
1091
+ type: "button",
1092
+ className: clsx(QuestionComposer_module_css_default.option, selected && question.multiSelect !== true && QuestionComposer_module_css_default.optionSelected),
1093
+ role: question.multiSelect === true ? "checkbox" : "radio",
1094
+ "aria-checked": selected,
1095
+ "aria-label": display.label,
1096
+ disabled: locked,
1097
+ onClick: () => {
1098
+ choose(option.label);
1099
+ },
1100
+ onKeyDown: (event) => {
1101
+ if (event.key !== "Enter") return;
1102
+ event.preventDefault();
1103
+ submitDrafts(drafts);
1104
+ },
1105
+ children: [question.multiSelect === true ? (0, react_jsx_runtime.jsx)("span", {
1106
+ className: clsx(QuestionComposer_module_css_default.checkbox, selected && QuestionComposer_module_css_default.checkboxChecked),
1107
+ "aria-hidden": "true",
1108
+ children: selected && (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCheckOutlineRegular, { size: 12 })
1109
+ }) : (0, react_jsx_runtime.jsx)("span", {
1110
+ className: QuestionComposer_module_css_default.number,
1111
+ children: optionIndex + 1
1112
+ }), (0, react_jsx_runtime.jsx)("span", {
1113
+ className: QuestionComposer_module_css_default.optionCopy,
1114
+ children: (0, react_jsx_runtime.jsxs)("span", {
1115
+ className: QuestionComposer_module_css_default.optionLine,
1116
+ children: [
1117
+ (0, react_jsx_runtime.jsx)("span", {
1118
+ className: QuestionComposer_module_css_default.optionLabel,
1119
+ children: display.label
1120
+ }),
1121
+ display.recommended && (0, react_jsx_runtime.jsx)("span", {
1122
+ className: QuestionComposer_module_css_default.badge,
1123
+ children: t("option.recommended")
1124
+ }),
1125
+ option.description !== void 0 && (0, react_jsx_runtime.jsx)("span", {
1126
+ className: QuestionComposer_module_css_default.description,
1127
+ children: option.description
1128
+ })
1129
+ ]
1130
+ })
1131
+ })]
1132
+ }, `${option.label}-${String(optionIndex)}`);
1133
+ }),
1134
+ review !== void 0 && draft.skipped && (0, react_jsx_runtime.jsx)("p", {
1135
+ className: QuestionComposer_module_css_default.reviewNote,
1136
+ children: t("review.skipped")
1137
+ }),
1138
+ (review === void 0 || draft.custom !== "") && (hasOptions ? (0, react_jsx_runtime.jsxs)("div", {
1139
+ className: clsx(QuestionComposer_module_css_default.customRow, draft.custom !== "" && QuestionComposer_module_css_default.customRowActive),
671
1140
  children: [question.multiSelect === true ? (0, react_jsx_runtime.jsx)("span", {
672
- className: clsx(QuestionComposer_module_css_default.checkbox, selected && QuestionComposer_module_css_default.checkboxChecked),
1141
+ className: clsx(QuestionComposer_module_css_default.checkbox, draft.custom !== "" && QuestionComposer_module_css_default.checkboxChecked),
673
1142
  "aria-hidden": "true",
674
- children: selected && (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCheckOutlineRegular, { size: 12 })
1143
+ children: draft.custom !== "" && (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCheckOutlineRegular, { size: 12 })
675
1144
  }) : (0, react_jsx_runtime.jsx)("span", {
676
1145
  className: QuestionComposer_module_css_default.number,
677
- children: optionIndex + 1
678
- }), (0, react_jsx_runtime.jsx)("span", {
679
- className: QuestionComposer_module_css_default.optionCopy,
680
- children: (0, react_jsx_runtime.jsxs)("span", {
681
- className: QuestionComposer_module_css_default.optionLine,
682
- children: [
683
- (0, react_jsx_runtime.jsx)("span", {
684
- className: QuestionComposer_module_css_default.optionLabel,
685
- children: display.label
686
- }),
687
- display.recommended && (0, react_jsx_runtime.jsx)("span", {
688
- className: QuestionComposer_module_css_default.badge,
689
- children: t("option.recommended")
690
- }),
691
- option.description !== void 0 && (0, react_jsx_runtime.jsx)("span", {
692
- className: QuestionComposer_module_css_default.description,
693
- children: option.description
694
- })
695
- ]
696
- })
1146
+ "aria-hidden": "true",
1147
+ children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconEditOutlineRegular, { size: 12 })
1148
+ }), (0, react_jsx_runtime.jsx)(AnswerField, {
1149
+ variant: "inline",
1150
+ value: draft.custom,
1151
+ disabled: locked,
1152
+ placeholder: t("custom.placeholder"),
1153
+ onChange: draftCustom,
1154
+ onKeyDown: continueFromCustom
697
1155
  })]
698
- }, `${option.label}-${String(optionIndex)}`);
699
- }), hasOptions ? (0, react_jsx_runtime.jsxs)("div", {
700
- className: clsx(QuestionComposer_module_css_default.customRow, draft.custom !== "" && QuestionComposer_module_css_default.customRowActive),
701
- children: [question.multiSelect === true ? (0, react_jsx_runtime.jsx)("span", {
702
- className: clsx(QuestionComposer_module_css_default.checkbox, draft.custom !== "" && QuestionComposer_module_css_default.checkboxChecked),
703
- "aria-hidden": "true",
704
- children: draft.custom !== "" && (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCheckOutlineRegular, { size: 12 })
705
- }) : (0, react_jsx_runtime.jsx)("span", {
706
- className: QuestionComposer_module_css_default.number,
707
- "aria-hidden": "true",
708
- children: (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconEditOutlineRegular, { size: 12 })
709
- }), (0, react_jsx_runtime.jsx)(AnswerField, {
710
- variant: "inline",
1156
+ }) : (0, react_jsx_runtime.jsx)(AnswerField, {
1157
+ autoFocus: canSubmit && countdown === void 0 && !locked && !focusedQuestions.current.has(index),
1158
+ variant: "block",
711
1159
  value: draft.custom,
712
- disabled: busy !== null,
1160
+ disabled: locked,
713
1161
  placeholder: t("custom.placeholder"),
1162
+ onFocus: () => {
1163
+ focusedQuestions.current.add(index);
1164
+ },
714
1165
  onChange: draftCustom,
715
1166
  onKeyDown: continueFromCustom
716
- })]
717
- }) : (0, react_jsx_runtime.jsx)(AnswerField, {
718
- autoFocus: !focusedQuestions.current.has(index),
719
- variant: "block",
720
- value: draft.custom,
721
- disabled: busy !== null,
722
- placeholder: t("custom.placeholder"),
723
- onFocus: () => {
724
- focusedQuestions.current.add(index);
725
- },
726
- onChange: draftCustom,
727
- onKeyDown: continueFromCustom
728
- })]
1167
+ }))
1168
+ ]
729
1169
  })]
730
1170
  }), (0, react_jsx_runtime.jsxs)("footer", {
731
1171
  className: QuestionComposer_module_css_default.footer,
@@ -770,7 +1210,7 @@ window.__ModuleLoader__.load({
770
1210
  role: "status",
771
1211
  children: error === null ? null : "key" in error ? t(error.key) : error.text
772
1212
  }),
773
- (0, react_jsx_runtime.jsxs)("div", {
1213
+ review === void 0 && (0, react_jsx_runtime.jsxs)("div", {
774
1214
  className: QuestionComposer_module_css_default.footerActions,
775
1215
  children: [(0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
776
1216
  variant: "outline",
@@ -779,7 +1219,7 @@ window.__ModuleLoader__.load({
779
1219
  children: t("action.skip")
780
1220
  }), (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Button, {
781
1221
  variant: "primary",
782
- disabled: busy !== null || !answered(draft),
1222
+ disabled: busy !== null || !answered(draft) || index === questions.length - 1 && !canSubmit,
783
1223
  onClick: continueFlow,
784
1224
  children: busy === "answer" ? t("submitting") : index === questions.length - 1 ? t("submit") : t("action.next")
785
1225
  })]
@@ -790,17 +1230,355 @@ window.__ModuleLoader__.load({
790
1230
  });
791
1231
  }
792
1232
  //#endregion
1233
+ //#region ../../core/session/src/surface.ts
1234
+ /** Runtime counterpart of the message-producing event union. */
1235
+ const SURFACE_EVENT_TYPES = new Set([
1236
+ "system/message",
1237
+ "developer/message",
1238
+ "user/message",
1239
+ "assistant/message",
1240
+ "tool/result"
1241
+ ]);
1242
+ /**
1243
+ * Narrow an event to a surface-eligible event carrying its required marker.
1244
+ * @param event - event to test.
1245
+ * @returns true when both the type and marker identify a surface event.
1246
+ */
1247
+ function isSurfaceEvent(event) {
1248
+ if (!SURFACE_EVENT_TYPES.has(event.type)) return false;
1249
+ return event.surfaceOp !== void 0;
1250
+ }
1251
+ /**
1252
+ * Narrow an event to an append-origin surface event: one that entered the
1253
+ * surface at its own log position and was never itself a replacement copy.
1254
+ *
1255
+ * The model-visible surface deliberately shadows replaced ranges, so it is the
1256
+ * wrong source for a human transcript — a landed replacement would erase
1257
+ * conversation the user already saw. Append-origin events are that transcript's
1258
+ * durable source material; replacement copies stay model-only.
1259
+ * @param event - event to test.
1260
+ * @returns true when the event appended to the surface tail.
1261
+ */
1262
+ function isAppendSurfaceEvent(event) {
1263
+ return isSurfaceEvent(event) && event.surfaceOp === "append";
1264
+ }
1265
+ //#endregion
1266
+ //#region lib/types/client/question-reply.js
1267
+ function isRecord(value) {
1268
+ return typeof value === "object" && value !== null && !Array.isArray(value);
1269
+ }
1270
+ /**
1271
+ * Read the question and answer pairs out of the reply text at the conversation boundary.
1272
+ * @param text - Model-facing JSON payload of the steered message.
1273
+ * @returns The pairs, or empty lists when the payload is unreadable.
1274
+ */
1275
+ function replyPairsOf(text) {
1276
+ let value;
1277
+ try {
1278
+ value = JSON.parse(text);
1279
+ } catch (error) {
1280
+ return {
1281
+ questions: [],
1282
+ answers: []
1283
+ };
1284
+ }
1285
+ if (!isRecord(value) || !Array.isArray(value.questions)) return {
1286
+ questions: [],
1287
+ answers: []
1288
+ };
1289
+ const questions = [];
1290
+ for (const question of value.questions) {
1291
+ if (!isRecord(question) || typeof question.id !== "string" || typeof question.question !== "string") continue;
1292
+ questions.push({
1293
+ id: question.id,
1294
+ question: question.question,
1295
+ ...typeof question.detail === "string" ? { detail: question.detail } : {},
1296
+ ...typeof question.header === "string" ? { header: question.header } : {},
1297
+ ...Array.isArray(question.options) ? { options: question.options.flatMap((option) => {
1298
+ if (!isRecord(option) || typeof option.label !== "string") return [];
1299
+ return [{
1300
+ label: option.label,
1301
+ ...typeof option.description === "string" ? { description: option.description } : {}
1302
+ }];
1303
+ }) } : {},
1304
+ ...typeof question.multiSelect === "boolean" ? { multiSelect: question.multiSelect } : {}
1305
+ });
1306
+ }
1307
+ const answers = [];
1308
+ for (const answer of Array.isArray(value.answers) ? value.answers : []) {
1309
+ if (!isRecord(answer) || typeof answer.id !== "string" || !Array.isArray(answer.selected)) continue;
1310
+ answers.push({
1311
+ id: answer.id,
1312
+ selected: answer.selected.filter((item) => typeof item === "string"),
1313
+ ...typeof answer.custom === "string" ? { custom: answer.custom } : {}
1314
+ });
1315
+ }
1316
+ return {
1317
+ questions,
1318
+ answers
1319
+ };
1320
+ }
1321
+ /**
1322
+ * Answer values of one question in display order: the selected option labels
1323
+ * followed by a non-blank custom answer.
1324
+ * @param data - Projected reply holding the recorded answers.
1325
+ * @param id - Question id to read.
1326
+ * @returns The values, empty when the user skipped that question.
1327
+ */
1328
+ function replyAnswerValues(data, id) {
1329
+ const answer = data.answers.find((item) => item.id === id);
1330
+ const custom = answer?.custom?.trim() ?? "";
1331
+ return [...answer?.selected ?? [], ...custom === "" ? [] : [custom]];
1332
+ }
1333
+ /**
1334
+ * Clipboard text of one late reply: every question with the answer the user
1335
+ * gave, in the layout the open bubble shows, without the options nobody chose.
1336
+ * The text does not depend on whether the bubble is open.
1337
+ * @param data - Projected reply to copy.
1338
+ * @param t - Bound `question` namespace translator owning the answer labels.
1339
+ * @returns One block per question, or the model-facing text when the payload was unreadable.
1340
+ */
1341
+ function replyClipboardText(data, t) {
1342
+ if (data.questions.length === 0) return data.text;
1343
+ return data.questions.map((question) => {
1344
+ const values = replyAnswerValues(data, question.id);
1345
+ return `${question.header && question.header !== question.question ? `${question.header} — ${question.question}` : question.question}\n${values.length === 0 ? t("reply.skipped") : `${t("reply.answerLabel")}${values.join(", ")}`}`;
1346
+ }).join("\n\n");
1347
+ }
1348
+ /** Validate a late reply source at the persisted conversation boundary. */
1349
+ function replySource(event) {
1350
+ const source = event.data.source;
1351
+ return isRecord(source) && source.kind === "user-question-reply" && typeof source.callId === "string" && source.outcome === "answered" ? {
1352
+ callId: source.callId,
1353
+ outcome: "answered"
1354
+ } : null;
1355
+ }
1356
+ /** Late-reply projection owned by the questions UI. */
1357
+ const questionReplyDefinition = {
1358
+ kind: "user-question-reply",
1359
+ target: "chat",
1360
+ match: (event) => {
1361
+ if (event.type !== "user/message" || !isAppendSurfaceEvent(event)) return null;
1362
+ return replySource(event) === null ? null : {
1363
+ id: String(event.data.id),
1364
+ role: "start"
1365
+ };
1366
+ },
1367
+ start: (_context, match) => {
1368
+ if (match.event.type !== "user/message") throw new Error("user-question-reply start requires user/message");
1369
+ const event = match.event;
1370
+ const text = event.data.content.find((item) => item.type === "text")?.text ?? "";
1371
+ const source = replySource(event);
1372
+ if (source === null) throw new Error("user-question-reply start requires a reply source");
1373
+ return {
1374
+ seq: event.seq,
1375
+ time: event.time,
1376
+ callId: source.callId,
1377
+ outcome: source.outcome,
1378
+ text,
1379
+ ...replyPairsOf(text)
1380
+ };
1381
+ },
1382
+ update: (context) => context.state,
1383
+ buildViewNode: (context) => {
1384
+ if (context.state === void 0) return null;
1385
+ const { seq, ...data } = context.state;
1386
+ return {
1387
+ key: context.key,
1388
+ kind: "question-reply",
1389
+ id: context.id,
1390
+ target: "chat",
1391
+ anchorSeq: seq,
1392
+ location: context.start?.location ?? { kind: "unresolved" },
1393
+ visibility: "visible",
1394
+ data
1395
+ };
1396
+ }
1397
+ };
1398
+ //#endregion
1399
+ //#region \0dsh-css:/home/runner/work/deepseek-harness/deepseek-harness/packages/client/ui-user-questions/src/client/QuestionReplyView.module.css.mjs
1400
+ const css = ".ROF66W_row{flex-direction:column;justify-content:flex-end;align-items:flex-end;gap:6px;padding:4px 0;display:flex}.ROF66W_bubble{border-radius:var(--dsw-radius-xl);background:var(--dsw-specific-bubble);max-width:72%;color:var(--dsw-alias-label-primary);cursor:pointer;font-size:var(--dsh-content-font-size,14px);line-height:calc(22px + var(--dsh-content-font-delta,0px));text-align:left;overflow-wrap:anywhere;white-space:pre-wrap;padding:10px 16px}.ROF66W_toggle{width:100%;color:inherit;cursor:pointer;font:inherit;text-align:left;background:0 0;border:0;padding:0}.ROF66W_toggle:focus-visible{outline:2px solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}.ROF66W_bubble:has(.ROF66W_toggle:focus-visible){box-shadow:0 0 0 2px var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary))}.ROF66W_labelRow{align-items:center;gap:3px;display:flex}.ROF66W_caret{color:var(--dsw-alias-label-secondary);display:inline-flex}.ROF66W_caret svg{width:12px;height:12px}.ROF66W_label{color:var(--dsw-alias-label-secondary);font-size:var(--dsh-content-font-size-secondary,13px);line-height:calc(18px + var(--dsh-content-font-delta-secondary,0px));display:block}.ROF66W_summary{color:var(--dsw-alias-label-primary);font-size:var(--dsh-content-font-size,14px);margin-top:3px;display:block}.ROF66W_text{margin:8px 0 0}.ROF66W_details{border-top:1px solid color-mix(in srgb, var(--dsw-alias-label-secondary) 24%, transparent);margin:8px 0 0;padding-top:8px}.ROF66W_details>div+div{margin-top:12px}.ROF66W_details dt{color:var(--dsw-alias-label-secondary);font-size:12px}.ROF66W_question{gap:3px;display:grid}.ROF66W_header,.ROF66W_detail,.ROF66W_options{color:var(--dsw-alias-label-secondary);font-size:11px}.ROF66W_questionText{color:var(--dsw-alias-label-primary)}.ROF66W_options{margin:0;padding-left:16px}.ROF66W_details dd{margin:4px 0 0}.ROF66W_answer{font-size:14px}.ROF66W_answerLabel{color:var(--dsw-alias-label-secondary);margin-right:4px;font-size:12px}.ROF66W_actions{height:28px;color:var(--dsw-alias-label-tertiary);align-items:center;gap:8px;padding-right:4px;display:flex}.ROF66W_time{white-space:nowrap;padding-right:4px;font-size:13px;line-height:24px}.ROF66W_action{border-radius:var(--dsw-radius-sm);width:28px;height:28px;color:inherit;cursor:pointer;background:0 0;border:none;justify-content:center;align-items:center;padding:6px;display:inline-flex}.ROF66W_action svg{width:15px;height:15px}.ROF66W_action:hover{background:var(--dsw-alias-interactive-bg-hover);color:var(--dsw-alias-label-secondary)}";
1401
+ const tagId = "@deepseek-ai/dsh-client-ui-user-questions/QuestionReplyView.module.css";
1402
+ if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
1403
+ const tag = document.createElement("style");
1404
+ tag.dataset.plugin = "@deepseek-ai/dsh-client-ui-user-questions";
1405
+ tag.dataset.pluginCss = tagId;
1406
+ tag.textContent = css;
1407
+ document.head.appendChild(tag);
1408
+ }
1409
+ var QuestionReplyView_module_css_default = {
1410
+ "action": "ROF66W_action",
1411
+ "actions": "ROF66W_actions",
1412
+ "answer": "ROF66W_answer",
1413
+ "answerLabel": "ROF66W_answerLabel",
1414
+ "bubble": "ROF66W_bubble",
1415
+ "caret": "ROF66W_caret",
1416
+ "detail": "ROF66W_detail",
1417
+ "details": "ROF66W_details",
1418
+ "header": "ROF66W_header",
1419
+ "label": "ROF66W_label",
1420
+ "labelRow": "ROF66W_labelRow",
1421
+ "options": "ROF66W_options",
1422
+ "question": "ROF66W_question",
1423
+ "questionText": "ROF66W_questionText",
1424
+ "row": "ROF66W_row",
1425
+ "summary": "ROF66W_summary",
1426
+ "text": "ROF66W_text",
1427
+ "time": "ROF66W_time",
1428
+ "toggle": "ROF66W_toggle"
1429
+ };
1430
+ //#endregion
1431
+ //#region lib/types/client/QuestionReplyView.js
1432
+ /**
1433
+ * Right-aligned late-reply bubble: a label naming the earlier pending
1434
+ * questions, then one question and answer pair per question. A payload the
1435
+ * Client cannot read falls back to the model-facing text.
1436
+ */
1437
+ const QuestionReplyView = (0, react.memo)(function QuestionReplyView({ node, t }) {
1438
+ return (0, react_jsx_runtime.jsx)(QuestionReplyBubble, {
1439
+ data: node.data,
1440
+ t
1441
+ });
1442
+ });
1443
+ /**
1444
+ * Render one settled question reply as a compact transcript bubble.
1445
+ * @param props - Reply data and the question locale translator.
1446
+ * @returns The expandable reply bubble.
1447
+ */
1448
+ function QuestionReplyBubble({ data, t }) {
1449
+ const label = t("reply.label");
1450
+ const [open, setOpen] = (0, react.useState)(false);
1451
+ const toggleLabel = t(open ? "reply.close" : "reply.open");
1452
+ const summary = data.questions.map((question) => replyAnswerValues(data, question.id)).flat().join(", ");
1453
+ const copyText = replyClipboardText(data, t);
1454
+ const [copied, setCopied] = (0, react.useState)(false);
1455
+ const onCopy = (0, react.useCallback)(() => {
1456
+ if (copied) return;
1457
+ (0, _deepseek_ai_dsh_client_ui_primitives.writeClipboard)(copyText).then((ok) => {
1458
+ if (!ok) return;
1459
+ setCopied(true);
1460
+ window.setTimeout(() => {
1461
+ setCopied(false);
1462
+ }, 1e3);
1463
+ });
1464
+ }, [copied, copyText]);
1465
+ return (0, react_jsx_runtime.jsxs)("div", {
1466
+ className: QuestionReplyView_module_css_default.row,
1467
+ "data-question-reply": data.callId,
1468
+ "data-reply-outcome": data.outcome,
1469
+ role: "group",
1470
+ "aria-label": label,
1471
+ children: [(0, react_jsx_runtime.jsxs)("div", {
1472
+ className: QuestionReplyView_module_css_default.bubble,
1473
+ children: [(0, react_jsx_runtime.jsxs)("button", {
1474
+ type: "button",
1475
+ className: QuestionReplyView_module_css_default.toggle,
1476
+ "aria-expanded": open,
1477
+ "aria-label": `${label} · ${toggleLabel}`,
1478
+ onClick: () => {
1479
+ setOpen((value) => !value);
1480
+ },
1481
+ children: [(0, react_jsx_runtime.jsxs)("span", {
1482
+ className: QuestionReplyView_module_css_default.labelRow,
1483
+ children: [(0, react_jsx_runtime.jsx)("span", {
1484
+ className: QuestionReplyView_module_css_default.caret,
1485
+ "aria-hidden": "true",
1486
+ children: open ? (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronDownOutlineRegular, {}) : (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconChevronRightOutlineRegular, {})
1487
+ }), (0, react_jsx_runtime.jsx)("span", {
1488
+ className: QuestionReplyView_module_css_default.label,
1489
+ children: label
1490
+ })]
1491
+ }), !open && (0, react_jsx_runtime.jsx)("span", {
1492
+ className: QuestionReplyView_module_css_default.summary,
1493
+ children: summary === "" ? t("reply.skipped") : summary
1494
+ })]
1495
+ }), open && (data.questions.length === 0 ? (0, react_jsx_runtime.jsx)("p", {
1496
+ className: QuestionReplyView_module_css_default.text,
1497
+ children: data.text
1498
+ }) : (0, react_jsx_runtime.jsx)("dl", {
1499
+ className: QuestionReplyView_module_css_default.details,
1500
+ children: data.questions.map((question) => {
1501
+ const values = replyAnswerValues(data, question.id);
1502
+ return (0, react_jsx_runtime.jsxs)("div", { children: [(0, react_jsx_runtime.jsxs)("dt", {
1503
+ className: QuestionReplyView_module_css_default.question,
1504
+ children: [
1505
+ question.header && question.header !== question.question && (0, react_jsx_runtime.jsx)("span", {
1506
+ className: QuestionReplyView_module_css_default.header,
1507
+ children: question.header
1508
+ }),
1509
+ (0, react_jsx_runtime.jsx)("span", {
1510
+ className: QuestionReplyView_module_css_default.questionText,
1511
+ children: question.question
1512
+ }),
1513
+ question.detail && (0, react_jsx_runtime.jsx)("span", {
1514
+ className: QuestionReplyView_module_css_default.detail,
1515
+ children: question.detail
1516
+ }),
1517
+ question.options && question.options.length > 0 && (0, react_jsx_runtime.jsx)("ul", {
1518
+ className: QuestionReplyView_module_css_default.options,
1519
+ children: question.options.map((option) => (0, react_jsx_runtime.jsxs)("li", { children: [option.label, option.description && ` — ${option.description}`] }, option.label))
1520
+ })
1521
+ ]
1522
+ }), (0, react_jsx_runtime.jsxs)("dd", {
1523
+ className: QuestionReplyView_module_css_default.answer,
1524
+ children: [(0, react_jsx_runtime.jsx)("span", {
1525
+ className: QuestionReplyView_module_css_default.answerLabel,
1526
+ children: t("reply.answerLabel")
1527
+ }), values.length === 0 ? t("reply.skipped") : values.join(", ")]
1528
+ })] }, question.id);
1529
+ })
1530
+ }))]
1531
+ }), (0, react_jsx_runtime.jsxs)("div", {
1532
+ className: QuestionReplyView_module_css_default.actions,
1533
+ children: [(0, react_jsx_runtime.jsx)("span", {
1534
+ className: QuestionReplyView_module_css_default.time,
1535
+ children: new Intl.DateTimeFormat(void 0, {
1536
+ hour: "2-digit",
1537
+ minute: "2-digit",
1538
+ hour12: false
1539
+ }).format(data.time)
1540
+ }), (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.Tooltip, {
1541
+ label: copied ? t("copied") : t("copy"),
1542
+ side: "bottom",
1543
+ children: (0, react_jsx_runtime.jsx)("button", {
1544
+ type: "button",
1545
+ className: QuestionReplyView_module_css_default.action,
1546
+ "aria-label": copied ? t("copied") : t("copy"),
1547
+ onClick: onCopy,
1548
+ children: copied ? (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCheckOutlineRegular, {}) : (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.IconCopyOutlineRegular, {})
1549
+ })
1550
+ })]
1551
+ })]
1552
+ });
1553
+ }
1554
+ //#endregion
793
1555
  //#region lib/types/client/locales.js
794
1556
  /** `question` namespace dictionaries. */
795
1557
  /** Simplified Chinese dictionary (the key-set source of truth). */
796
1558
  const zh = {
797
1559
  "error.incomplete": "请先完成这道问题。",
798
1560
  "error.unanswered": "请选择一个选项或填写自定义答案。",
1561
+ "error.unavailable": "当前无法提交,请稍候再试。",
1562
+ "error.resubmit": "回答未送达,工作已继续,请再提交一次。",
1563
+ "status.sent": "回答已发送;面板未能关闭。",
1564
+ "wait.takeTime": "慢慢回答",
1565
+ "wait.countdown": "{seconds} 秒后继续工作",
1566
+ "wait.paused": "已暂停 · 剩余 {seconds} 秒",
1567
+ "wait.held": "会一直等你回答",
1568
+ "wait.continued": "已继续工作,仍可回答",
1569
+ "review.status": "已回答",
1570
+ "review.skipped": "这道问题当时被跳过。",
1571
+ "reply.label": "回答先前等待中的问题",
1572
+ "reply.open": "展开问题详情",
1573
+ "reply.close": "收起问题详情",
1574
+ "reply.answerLabel": "回答:",
1575
+ "reply.skipped": "已跳过",
799
1576
  "nav.prev": "上一题",
800
1577
  "nav.next": "下一题",
801
1578
  "nav.minimize": "收起问题卡片",
802
1579
  "nav.maximize": "展开问题卡片",
803
1580
  "nav.cancel": "放弃整组问题",
1581
+ "nav.close": "收起问题面板,可从工具调用重新打开",
804
1582
  "option.recommended": "推荐",
805
1583
  "custom.placeholder": "输入你的答案",
806
1584
  "action.skip": "跳过",
@@ -814,11 +1592,27 @@ window.__ModuleLoader__.load({
814
1592
  const en = {
815
1593
  "error.incomplete": "Please complete this question first.",
816
1594
  "error.unanswered": "Please select an option or enter a custom answer.",
1595
+ "error.unavailable": "Cannot submit right now; try again in a moment.",
1596
+ "error.resubmit": "The answer did not arrive before work continued; submit it again.",
1597
+ "status.sent": "Reply sent; the panel could not close.",
1598
+ "wait.takeTime": "Take time",
1599
+ "wait.countdown": "Continuing in {seconds}s",
1600
+ "wait.paused": "Paused · {seconds}s remaining",
1601
+ "wait.held": "Waiting until you answer",
1602
+ "wait.continued": "Work continued — you can still answer",
1603
+ "review.status": "Answered",
1604
+ "review.skipped": "This question was skipped.",
1605
+ "reply.label": "Reply to earlier pending questions",
1606
+ "reply.open": "Open question details",
1607
+ "reply.close": "Close question details",
1608
+ "reply.answerLabel": "Answer: ",
1609
+ "reply.skipped": "Skipped",
817
1610
  "nav.prev": "Previous question",
818
1611
  "nav.next": "Next question",
819
1612
  "nav.minimize": "Collapse the question card",
820
1613
  "nav.maximize": "Expand the question card",
821
1614
  "nav.cancel": "Dismiss all questions",
1615
+ "nav.close": "Close the panel — reopen it from the tool call",
822
1616
  "option.recommended": "Recommended",
823
1617
  "custom.placeholder": "Type your answer",
824
1618
  "action.skip": "Skip",
@@ -832,40 +1626,269 @@ window.__ModuleLoader__.load({
832
1626
  //#region lib/types/client/index.js
833
1627
  /** Dictionary namespace owned by this plugin. */
834
1628
  const NS = "question";
835
- /** Required services: Agent scopes, Remote Events, Session UI, Slot registry, and copy. */
1629
+ /** Required services: Agent scopes, Remote Events, Session UI, Slot registry, conversation nodes, and copy. */
836
1630
  const inject = [
837
1631
  "sessions",
838
1632
  "remote",
1633
+ "remote.userQuestions",
839
1634
  "uiSession",
840
1635
  "slots",
841
- "locale"
1636
+ "locale",
1637
+ "uiConversation"
842
1638
  ];
843
- /** Present one request until the user answers, cancels, or its lifetime ends. */
844
- async function answerQuestion(ctx, owner, request, next, registerPendingInteraction) {
1639
+ /**
1640
+ * Cards published to the Session pending-interaction registry, keyed by
1641
+ * `PendingQuestion.key`. A tool-call-keyed card is shared by the forwarded
1642
+ * waterfall and the Session projection.
1643
+ *
1644
+ * A card outlives its seat. Closing the panel only unpublishes it, which keeps
1645
+ * the request answerable from its tool call row, so this registry — not the
1646
+ * pending-interaction registry — decides when a request is over.
1647
+ */
1648
+ var QuestionCards = class {
1649
+ publish;
1650
+ #cards = /* @__PURE__ */ new Map();
1651
+ constructor(publish) {
1652
+ this.publish = publish;
1653
+ }
1654
+ byCallId(sessionId, callId) {
1655
+ return this.#cards.get(PendingQuestion.keyOf(sessionId, callId));
1656
+ }
1657
+ /** Observable state for one card while the registry owns it. */
1658
+ source(key) {
1659
+ return this.#cards.get(key)?.pending;
1660
+ }
1661
+ values() {
1662
+ return [...this.#cards.values()];
1663
+ }
1664
+ /** Keys of every card registered for one Session. */
1665
+ keysFor(sessionId) {
1666
+ return this.values().filter((card) => card.pending.sessionId === sessionId).map((card) => card.pending.key);
1667
+ }
1668
+ /**
1669
+ * Return the card of a tool call, creating and publishing it when absent.
1670
+ * A request without a call id always gets a fresh card.
1671
+ */
1672
+ ensure(sessionId, questions, callId) {
1673
+ if (callId !== void 0) {
1674
+ const existing = this.byCallId(sessionId, callId);
1675
+ if (existing !== void 0) return existing;
1676
+ }
1677
+ return this.#create(new PendingQuestion(sessionId, questions, callId, () => this.keysFor(sessionId)));
1678
+ }
1679
+ /** Publish one carrier into the composer seat and register the card that owns it. */
1680
+ #create(pending) {
1681
+ const requests = /* @__PURE__ */ new Set();
1682
+ const delegate = async () => {
1683
+ pending.delegate();
1684
+ await Promise.all(requests);
1685
+ };
1686
+ let unpublish = this.publish(pending, delegate);
1687
+ const card = {
1688
+ pending,
1689
+ hide: () => {
1690
+ unpublish?.();
1691
+ unpublish = void 0;
1692
+ },
1693
+ reveal: () => {
1694
+ unpublish?.();
1695
+ unpublish = this.publish(pending, delegate);
1696
+ },
1697
+ remove: () => {
1698
+ /* v8 ignore next -- a card leaves the registry once; no caller holds a card the registry already replaced. */
1699
+ if (this.#cards.get(pending.key) !== card) return;
1700
+ this.#cards.delete(pending.key);
1701
+ pending.close();
1702
+ unpublish?.();
1703
+ unpublish = void 0;
1704
+ },
1705
+ trackRequest: (completion) => {
1706
+ requests.add(completion);
1707
+ return () => {
1708
+ requests.delete(completion);
1709
+ };
1710
+ },
1711
+ hasRequest: () => requests.size > 0
1712
+ };
1713
+ pending.attachSeat({ hide: pending.review === void 0 ? card.hide : card.remove });
1714
+ this.#cards.set(pending.key, card);
1715
+ return card;
1716
+ }
1717
+ /**
1718
+ * Show the panel of one answerable tool call.
1719
+ * @param sessionId - Session the tool call belongs to.
1720
+ * @param callId - `ask_user_question` call whose panel to show, as its
1721
+ * transcript row spells it.
1722
+ * @returns whether a card for that call is still answerable.
1723
+ */
1724
+ reveal(sessionId, callId) {
1725
+ const card = this.byCallId(sessionId, callId);
1726
+ if (card === void 0) return false;
1727
+ card.reveal();
1728
+ return true;
1729
+ }
1730
+ /**
1731
+ * Show one settled tool call's recorded answers as a read-only card. A call
1732
+ * that somehow still holds a card is shown as it stands, so a live request is
1733
+ * never replaced by a stale copy of itself.
1734
+ * @param sessionId - Session the tool call belongs to.
1735
+ * @param callId - `ask_user_question` call whose record to show, as its
1736
+ * transcript row spells it.
1737
+ * @param record - the call's questions and recorded answers.
1738
+ * @returns true; a record always produces a card.
1739
+ */
1740
+ review(sessionId, callId, record) {
1741
+ (this.byCallId(sessionId, callId) ?? this.#create(new PendingQuestion(sessionId, record.questions, brandString(callId), () => this.keysFor(sessionId), record.answers))).reveal();
1742
+ return true;
1743
+ }
1744
+ /**
1745
+ * Hand every live waterfall back at plugin teardown. The pending-interaction
1746
+ * registry only drains what it currently holds, and a hidden card is not in
1747
+ * it, so its Host request would wait for its own abort instead.
1748
+ */
1749
+ dispose() {
1750
+ for (const card of this.values()) {
1751
+ card.pending.delegate();
1752
+ card.remove();
1753
+ }
1754
+ }
1755
+ };
1756
+ /** Present one forwarded request through its card until the waterfall settles. */
1757
+ async function answerQuestion(ctx, owner, request, next, cards) {
845
1758
  const sessionId = ctx.sessions.scopeOf(owner);
846
1759
  if (sessionId === void 0) return next();
847
- const pending = new PendingQuestion(sessionId, request.questions, request.signal);
1760
+ const callId = request.wait?.callId;
1761
+ const card = cards.ensure(sessionId, request.questions, callId);
1762
+ const claimLifetime = new AbortController();
1763
+ const claimSignal = request.signal === void 0 ? claimLifetime.signal : AbortSignal.any([claimLifetime.signal, request.signal]);
1764
+ let claim;
1765
+ let claimEnded;
1766
+ let delegateRequest;
1767
+ const releaseClaim = request.wait?.timed === true && callId !== void 0 ? ctx.effect(() => {
1768
+ claim = ctx.remote.userQuestions.attachWait(sessionId, callId, claimSignal);
1769
+ return async () => {
1770
+ delegateRequest?.();
1771
+ claimLifetime.abort();
1772
+ claim?.dispose();
1773
+ if (claimEnded !== void 0) await Promise.allSettled([claimEnded]);
1774
+ };
1775
+ }, "ui-user-questions: foreground claim") : void 0;
848
1776
  const completed = Promise.withResolvers();
849
- const remove = registerPendingInteraction(pending, async () => {
850
- pending.delegate();
851
- await completed.promise;
852
- });
1777
+ const finishRequest = card.trackRequest(completed.promise);
853
1778
  try {
1779
+ const iterator = claim?.[Symbol.asyncIterator]();
1780
+ const opening = iterator === void 0 ? void 0 : await iterator.next();
1781
+ if (opening?.done === true) return await next();
1782
+ const waterfall = createWaterfallRequest(opening === void 0 ? void 0 : Date.now() + opening.value.remainingMs, claimSignal, (channel) => {
1783
+ card.pending.detachWaterfall(channel);
1784
+ });
1785
+ if (claimSignal.aborted) return await waterfall.result;
1786
+ delegateRequest = () => {
1787
+ waterfall.channel.delegate();
1788
+ };
1789
+ card.pending.attachWaterfall(waterfall.channel);
1790
+ if (iterator !== void 0) claimEnded = (async () => {
1791
+ await iterator.next();
1792
+ throw new Error("the foreground question wait ended");
1793
+ })();
854
1794
  try {
855
- return await pending.result;
1795
+ return await (claimEnded === void 0 ? waterfall.result : Promise.race([waterfall.result, claimEnded]));
856
1796
  } catch (error) {
857
- if (pending.isDelegation(error)) return await next();
1797
+ if (waterfall.isDelegation(error)) {
1798
+ await releaseClaim?.();
1799
+ return await next();
1800
+ }
858
1801
  throw error;
859
1802
  }
860
1803
  } finally {
861
- remove();
1804
+ if (releaseClaim === void 0) claimLifetime.abort();
1805
+ else if (claimEnded === void 0) await releaseClaim();
1806
+ else Promise.allSettled([claimEnded]).then(() => {
1807
+ releaseClaim();
1808
+ });
1809
+ if (callId === void 0) card.remove();
862
1810
  completed.resolve();
1811
+ finishRequest();
863
1812
  }
864
1813
  }
865
1814
  /**
866
- * Client plugin body: register the `question` dictionaries and the question
867
- * composer into the composer chain. Zero business face — data and verbs live
868
- * on the matched carrier; t rides the standard locale seat.
1815
+ * Mirror answerable calls onto cards. A submitted reply in the durable Inbox
1816
+ * removes the editable card until the reply is admitted or discarded.
1817
+ */
1818
+ function publishContinuedQuestions(ctx, cards) {
1819
+ const sessions = ctx.sessions;
1820
+ const stopProjections = /* @__PURE__ */ new Map();
1821
+ const unwrap = (result) => {
1822
+ if (!result.ok) throw new Error(result.error.message);
1823
+ return result.value;
1824
+ };
1825
+ const rpcFor = (sessionId, callId) => ({ answer: async (answer) => unwrap(await ctx.remote.userQuestions.answer(sessionId, callId, answer)) });
1826
+ const reconcile = () => {
1827
+ const snapshot = sessions.list.getSnapshot();
1828
+ const bound = new Map(Object.values(snapshot.byId).flatMap((summary) => {
1829
+ const binding = sessions.binding(summary.id);
1830
+ return binding === void 0 ? [] : [[summary.id, binding]];
1831
+ }));
1832
+ for (const [sessionId, stop] of stopProjections) {
1833
+ if (bound.has(sessionId)) continue;
1834
+ stop();
1835
+ stopProjections.delete(sessionId);
1836
+ }
1837
+ for (const [sessionId, binding] of bound) {
1838
+ if (stopProjections.has(sessionId)) continue;
1839
+ const stopQuestions = binding.session.projections.faceOf("userQuestions").subscribe(reconcile);
1840
+ const stopInbox = binding.session.projections.faceOf("inbox").subscribe(reconcile);
1841
+ stopProjections.set(sessionId, () => {
1842
+ stopQuestions();
1843
+ stopInbox();
1844
+ });
1845
+ }
1846
+ const rows = /* @__PURE__ */ new Map();
1847
+ for (const [sessionId, binding] of bound) {
1848
+ const projected = binding.session.projections.faceOf("userQuestions").getSnapshot();
1849
+ const inbox = binding.session.projections.faceOf("inbox").getSnapshot();
1850
+ const queued = /* @__PURE__ */ new Set();
1851
+ for (const message of [...inbox?.["next-step"] ?? [], ...inbox?.["next-turn"] ?? []]) {
1852
+ if (typeof message !== "object" || message === null || Array.isArray(message)) continue;
1853
+ const source = message.source;
1854
+ if (typeof source !== "object" || source === null || Array.isArray(source)) continue;
1855
+ if (source.kind === "user-question-reply" && typeof source.callId === "string") queued.add(source.callId);
1856
+ }
1857
+ for (const row of projected?.active ?? []) {
1858
+ if (row.state === "continued" && queued.has(row.callId)) continue;
1859
+ rows.set(PendingQuestion.keyOf(sessionId, row.callId), {
1860
+ sessionId,
1861
+ row
1862
+ });
1863
+ }
1864
+ }
1865
+ for (const { sessionId, row } of rows.values()) {
1866
+ if (row.state === "continued") {
1867
+ const card = cards.ensure(sessionId, row.questions, row.callId);
1868
+ card.pending.attachRpc(rpcFor(sessionId, row.callId));
1869
+ card.pending.setState("continued");
1870
+ continue;
1871
+ }
1872
+ cards.byCallId(sessionId, row.callId)?.pending.setState("open");
1873
+ }
1874
+ for (const card of cards.values()) {
1875
+ if (card.pending.callId === void 0 || card.pending.review !== void 0 || rows.has(card.pending.key) || card.hasRequest() || card.pending.hasWaterfall()) continue;
1876
+ card.remove();
1877
+ }
1878
+ };
1879
+ reconcile();
1880
+ const stopList = sessions.list.subscribe(reconcile);
1881
+ return () => {
1882
+ stopList();
1883
+ for (const stop of stopProjections.values()) stop();
1884
+ stopProjections.clear();
1885
+ };
1886
+ }
1887
+ /**
1888
+ * Client plugin body: register the `question` dictionaries, the question
1889
+ * composer into the composer chain, and the late-reply conversation node.
1890
+ * Zero business face — data and verbs live on the matched carrier; t rides
1891
+ * the standard locale seat.
869
1892
  * @param ctx - client root context.
870
1893
  */
871
1894
  function apply(ctx) {
@@ -874,19 +1897,35 @@ window.__ModuleLoader__.load({
874
1897
  en
875
1898
  }), "ui-user-questions: dictionaries");
876
1899
  const questionDraftStore = createQuestionDraftStore();
877
- const registerPendingInteraction = ctx.uiSession.registerPendingInteraction((pending) => pending.kind === "plan-review" ? 2 : 1);
1900
+ const cards = new QuestionCards(ctx.uiSession.registerPendingInteraction((pending) => pending.kind === "plan-review" ? 2 : 1));
1901
+ ctx.effect(() => () => {
1902
+ cards.dispose();
1903
+ }, "ui-user-questions: cards");
1904
+ const disposePanels = ctx.reflect.provide("userQuestionPanels", {
1905
+ reveal: (sessionId, callId) => cards.reveal(sessionId, callId),
1906
+ review: (sessionId, callId, record) => cards.review(sessionId, callId, record)
1907
+ });
1908
+ ctx.effect(() => disposePanels, "ui-user-questions: answer panels");
1909
+ ctx.effect(() => publishContinuedQuestions(ctx, cards), "ui-user-questions: continued questions");
878
1910
  ctx.slots.inject("conversation.composer", () => ctx.slots.register({
879
1911
  name: "conversation.composer",
880
1912
  select: ({ pendingInteraction }) => pendingInteraction instanceof PendingQuestion ? pendingInteraction : null,
881
1913
  locale: NS,
882
1914
  store: questionDraftStore,
1915
+ inject: () => ({ keyedHooks: { questionCard: (key) => cards.source(key) } }),
883
1916
  children: { "conversation.plan-review.actions": {
884
1917
  kind: "list",
885
1918
  scope: "session"
886
1919
  } }
887
1920
  }, QuestionComposer));
1921
+ ctx.uiConversation.events.register(questionReplyDefinition);
1922
+ ctx.slots.inject("conversation.chat.node", () => ctx.slots.register({
1923
+ name: "conversation.chat.node",
1924
+ key: "question-reply",
1925
+ locale: NS
1926
+ }, QuestionReplyView));
888
1927
  ctx.remote.$on("user-questions/request", function(request, next) {
889
- return answerQuestion(ctx, this, request, next, registerPendingInteraction);
1928
+ return answerQuestion(ctx, this, request, next, cards);
890
1929
  });
891
1930
  }
892
1931
  //#endregion