@surfishs/dsh-prompt-enhance 0.0.2 → 0.0.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.
package/lib/client.js CHANGED
@@ -36,8 +36,7 @@ __export(index_exports, {
36
36
  module.exports = __toCommonJS(index_exports);
37
37
 
38
38
  // src/client/EnhanceButton.tsx
39
- var import_react3 = require("react");
40
- var import_react_dom = require("react-dom");
39
+ var import_react2 = require("react");
41
40
 
42
41
  // src/shared/validate.ts
43
42
  function isInvisibleCodePoint(cp) {
@@ -261,217 +260,29 @@ async function requestEnhance(body, signal) {
261
260
  return readEnvelope(response);
262
261
  }
263
262
 
264
- // src/client/ResultPanel.tsx
265
- var import_react = require("react");
263
+ // src/client/SparkleFishIcon.tsx
266
264
  var import_jsx_runtime = require("react/jsx-runtime");
267
- var retryable = (code) => code === "upstream" || code === "timeout" || code === "internal";
268
- var UPSTREAM_ERROR_KEYS = {
269
- auth: "error.upstream.auth",
270
- "invalid-credential": "error.upstream.invalidCredential",
271
- "rate-limit": "error.upstream.rateLimit",
272
- quota: "error.upstream.quota",
273
- empty: "error.upstream.empty",
274
- "context-window": "error.upstream.contextWindow",
275
- "tool-call": "error.upstream.toolCall",
276
- "max-tokens": "error.upstream.maxTokens"
277
- };
278
- function localizedErrorMessage(t, code, params) {
279
- if (code === "rejected" && typeof params?.count === "number" && typeof params?.max === "number") {
280
- return t("error.tooLong", { count: params.count, max: params.max });
281
- }
282
- if (code === "upstream" && typeof params?.reason === "string") {
283
- const specific = UPSTREAM_ERROR_KEYS[params.reason];
284
- if (specific !== void 0) return t(specific);
285
- }
286
- switch (code) {
287
- case "rejected":
288
- return t("error.rejected");
289
- case "rate-limit":
290
- return t("error.rateLimit", params);
291
- case "concurrency-limit":
292
- return t("error.concurrencyLimit", params);
293
- case "cooldown":
294
- return t("error.cooldown", params);
295
- case "timeout":
296
- return t("error.timeout", params);
297
- case "unconfigured":
298
- return t("error.unconfigured");
299
- case "effort-unsupported":
300
- return t("error.effortUnsupported", params);
301
- case "upstream":
302
- return t("error.upstream");
303
- default:
304
- return t("error.internal");
305
- }
306
- }
307
- function fallbackCopy(text) {
308
- try {
309
- const textarea = document.createElement("textarea");
310
- textarea.value = text;
311
- textarea.style.position = "fixed";
312
- textarea.style.opacity = "0";
313
- document.body.appendChild(textarea);
314
- textarea.select();
315
- const ok = document.execCommand("copy");
316
- textarea.remove();
317
- return ok;
318
- } catch {
319
- return false;
320
- }
321
- }
322
- function ResultPanel(props) {
323
- const { state, t, onApply, onCancel, onRetry } = props;
324
- const [copied, setCopied] = (0, import_react.useState)("idle");
325
- const panelRef = (0, import_react.useRef)(null);
326
- (0, import_react.useEffect)(() => {
327
- const onKeyDown = (event) => {
328
- if (event.isComposing) return;
329
- if (event.key === "Escape" && !event.defaultPrevented) {
330
- event.preventDefault();
331
- onCancel();
332
- return;
333
- }
334
- if (event.key === "Tab") {
335
- const panel = panelRef.current;
336
- if (panel === null) return;
337
- const focusables = panel.querySelectorAll('button:not([disabled]), [href], input, [tabindex]:not([tabindex="-1"])');
338
- const first = focusables[0];
339
- const last = focusables[focusables.length - 1];
340
- if (first === void 0 || last === void 0) return;
341
- const active = document.activeElement;
342
- const atRoot = active === panel;
343
- if (event.shiftKey && (active === first || atRoot)) {
344
- event.preventDefault();
345
- last.focus();
346
- } else if (!event.shiftKey && active === last) {
347
- event.preventDefault();
348
- first.focus();
349
- }
350
- }
351
- };
352
- document.addEventListener("keydown", onKeyDown);
353
- return () => document.removeEventListener("keydown", onKeyDown);
354
- }, [onCancel]);
355
- const openerRef = (0, import_react.useRef)(null);
356
- (0, import_react.useEffect)(() => {
357
- openerRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
358
- panelRef.current?.focus();
359
- return () => {
360
- const opener = openerRef.current;
361
- openerRef.current = null;
362
- if (opener === null || !opener.isConnected) return;
363
- const active = document.activeElement;
364
- if (active === null || active === document.body) opener.focus();
365
- };
366
- }, []);
367
- const copy = (0, import_react.useCallback)(() => {
368
- if (state.result === void 0) return;
369
- const text = state.result.text;
370
- const done = (ok) => setCopied(ok ? "ok" : "failed");
371
- if (navigator.clipboard !== void 0) {
372
- navigator.clipboard.writeText(text).then(() => done(true), () => done(fallbackCopy(text)));
373
- return;
374
- }
375
- done(fallbackCopy(text));
376
- }, [state.result]);
377
- const formatMs = (ms) => ms < 1e3 ? `${ms}ms` : `${(ms / 1e3).toFixed(1)}s`;
378
- const formatTokens = (tokens) => tokens.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
379
- const totalTokensOf = (usage) => usage.totalTokens ?? usage.inputTokens + usage.outputTokens + (usage.cacheReadTokens ?? 0) + (usage.cacheWriteTokens ?? 0);
380
- const tokenDetail = (usage) => {
381
- const parts = [
382
- t("panel.tokens.input", { count: formatTokens(usage.inputTokens) }),
383
- t("panel.tokens.output", { count: formatTokens(usage.outputTokens) })
384
- ];
385
- if ((usage.cacheReadTokens ?? 0) > 0) {
386
- parts.push(t("panel.tokens.cacheRead", { count: formatTokens(usage.cacheReadTokens ?? 0) }));
387
- }
388
- if ((usage.cacheWriteTokens ?? 0) > 0) {
389
- parts.push(t("panel.tokens.cacheWrite", { count: formatTokens(usage.cacheWriteTokens ?? 0) }));
390
- }
391
- return parts.join(" \xB7 ");
392
- };
393
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-pe-overlay", onMouseDown: (event) => {
394
- if (event.target === event.currentTarget) onCancel();
395
- }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
396
- "section",
265
+ var FISH_PATH = "M22.9168 1.43018C22.6713 1.31018 22.5658 1.53918 22.4223 1.65519C22.3733 1.69269 22.3318 1.74169 22.2903 1.78669C21.9317 2.1697 21.5127 2.42121 20.9657 2.39121C20.1657 2.34621 19.4827 2.59771 18.8787 3.20973C18.7502 2.45521 18.3236 2.0047 17.6746 1.71569C17.3351 1.56568 16.9916 1.41518 16.7536 1.08867C16.5876 0.856163 16.5421 0.597155 16.4591 0.341647C16.4061 0.187643 16.3536 0.0301382 16.1761 0.00363739C15.9836 -0.0263635 15.9081 0.135141 15.8326 0.270145C15.5306 0.822162 15.4136 1.43018 15.4251 2.0462C15.4516 3.43174 16.0366 4.53527 17.1991 5.3203C17.3311 5.4103 17.3651 5.5003 17.3236 5.63181C17.2441 5.90231 17.1501 6.16482 17.0671 6.43533C17.0141 6.60784 16.9351 6.64584 16.7501 6.57033C16.1121 6.30383 15.5611 5.90931 15.074 5.4328C14.2475 4.63328 13.5 3.75075 12.568 3.05973C12.349 2.89822 12.13 2.74822 11.9034 2.60522C10.9524 1.68169 12.028 0.923165 12.277 0.833162C12.5375 0.739159 12.3675 0.41615 11.5259 0.42015C10.6844 0.42365 9.91439 0.705658 8.93286 1.08117C8.78935 1.13767 8.63835 1.17867 8.48384 1.21267C7.59332 1.04367 6.66829 1.00617 5.70226 1.11517C3.88321 1.31768 2.43016 2.1777 1.36213 3.64575C0.0790928 5.4103 -0.222916 7.41536 0.146595 9.50642C0.535106 11.7105 1.66014 13.535 3.38869 14.9616C5.18125 16.4406 7.24581 17.1657 9.60138 17.0266C11.0319 16.9441 12.6245 16.7526 14.421 15.2321C14.874 15.4576 15.3496 15.5476 16.1381 15.6151C16.7456 15.6716 17.3306 15.5851 17.7836 15.4911C18.4931 15.3411 18.4441 14.6841 18.1876 14.5636C16.1081 13.595 16.5646 13.9891 16.1496 13.67C17.2061 12.42 18.8202 10.1979 19.3182 7.17235C19.3672 6.83834 19.4297 6.36783 19.4222 6.09732C19.4182 5.93231 19.4562 5.86831 19.6447 5.84931C20.1657 5.78931 20.6712 5.64681 21.1357 5.3913C22.4833 4.65528 23.0268 3.44624 23.1548 1.9972C23.1738 1.77569 23.1508 1.54668 22.9168 1.43018ZM11.1749 14.4736C9.15936 12.889 8.18184 12.3675 7.77832 12.39C7.40081 12.4125 7.46881 12.8445 7.55182 13.126C7.63882 13.404 7.75182 13.5955 7.91033 13.8396C8.01983 14.0011 8.09533 14.2411 7.80083 14.4216C7.15181 14.8231 6.02327 14.2866 5.97027 14.2601C4.65673 13.4865 3.5587 12.4655 2.78467 11.069C2.03715 9.72493 1.60314 8.28289 1.53164 6.74384C1.51264 6.37233 1.62214 6.24082 1.99215 6.17332C2.47916 6.08332 2.98118 6.06432 3.46769 6.13582C5.52476 6.43633 7.27581 7.35586 8.74385 8.8129C9.58188 9.64243 10.2159 10.634 10.8689 11.6025C11.5634 12.631 12.3105 13.611 13.262 14.4146C13.598 14.6961 13.866 14.9101 14.1225 15.0681C13.349 15.1546 12.058 15.1731 11.1749 14.4746L11.1749 14.4736ZM12.141 8.25988C12.141 8.09488 12.273 7.96338 12.439 7.96338C12.4765 7.96338 12.5105 7.97088 12.541 7.98188C12.5825 7.99688 12.6205 8.01938 12.6505 8.05338C12.7035 8.10588 12.7335 8.18088 12.7335 8.25988C12.7335 8.42489 12.6015 8.55639 12.4355 8.55639C12.2695 8.55639 12.141 8.42489 12.141 8.25988ZM15.1415 9.79893C14.949 9.87793 14.7565 9.94544 14.5715 9.95294C14.2845 9.96794 13.9715 9.85143 13.8015 9.70893C13.5375 9.48742 13.3485 9.36342 13.2695 8.97691C13.2355 8.8119 13.2545 8.55639 13.2845 8.40989C13.3525 8.09438 13.277 7.89187 13.0545 7.70787C12.8735 7.55786 12.643 7.51636 12.39 7.51636C12.2955 7.51636 12.209 7.47486 12.1445 7.44136C12.039 7.38886 11.9519 7.25735 12.035 7.09585C12.0615 7.04335 12.19 6.91584 12.22 6.89334C12.5635 6.69784 12.9595 6.76184 13.326 6.90834C13.6655 7.04735 13.9225 7.30236 14.292 7.66287C14.6695 8.09838 14.7375 8.21838 14.9525 8.54539C15.1225 8.8009 15.277 9.06341 15.3831 9.36392C15.4471 9.55142 15.3641 9.70493 15.1415 9.79893Z";
266
+ var STAR_PATH = "M5.715 0 L7.2 4.2 L11.43 5.715 L7.2 7.2 L5.715 11.43 L4.2 7.2 L0 5.715 L4.2 4.2 Z";
267
+ function SparkleFishIcon(props) {
268
+ const size = props.size ?? 15;
269
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
270
+ "svg",
397
271
  {
398
- ref: panelRef,
399
- className: "dsh-pe-panel",
400
- role: "dialog",
401
- "aria-modal": "true",
402
- "aria-label": t("panel.title"),
403
- tabIndex: -1,
272
+ width: size * 1.3,
273
+ height: size,
274
+ viewBox: "0 0 26 20",
275
+ fill: "none",
276
+ "aria-hidden": "true",
277
+ focusable: "false",
278
+ style: { display: "block", flexShrink: 0 },
404
279
  children: [
405
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("header", { className: "dsh-pe-head", children: [
406
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: [
407
- "\u2728 ",
408
- t("panel.title")
409
- ] }),
410
- state.phase === "result" && state.result !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "dsh-pe-meta", children: [
411
- t("panel.model", { provider: state.result.provider, model: state.result.model }),
412
- " \xB7 ",
413
- t("panel.elapsed", { ms: formatMs(state.result.elapsedMs) }),
414
- state.result.usage === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
415
- " \xB7 ",
416
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
417
- "span",
418
- {
419
- title: tokenDetail(state.result.usage),
420
- children: t("panel.tokens", { total: formatTokens(totalTokensOf(state.result.usage)) })
421
- }
422
- )
423
- ] })
424
- ] }),
425
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "dsh-pe-close", "aria-label": t("panel.close"), onClick: onCancel, children: "\u2715" })
426
- ] }),
427
- state.phase === "loading" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-pe-loading", children: state.streaming === void 0 || state.streaming === "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
428
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-pe-spin", "aria-hidden": true }),
429
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: t("panel.loading") }),
430
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-pe-hint", children: t("panel.loading.hint") })
431
- ] }) : (
432
- // Incremental view: the text already generated, replaced by the
433
- // normalized full body the moment the call settles.
434
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-pe-stream", children: [
435
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-pe-col-title", children: [
436
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dsh-pe-spin small", "aria-hidden": true }),
437
- t("panel.streaming")
438
- ] }),
439
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "dsh-pe-col-text", children: state.streaming })
440
- ] })
441
- ) }),
442
- state.phase === "error" && state.error !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-pe-error", children: state.error.localized !== void 0 ? (
443
- // Client-side guard failures carry their own pre-localized copy.
444
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: state.error.localized })
445
- ) : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
446
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: localizedErrorMessage(t, state.error.code, state.error.params) }),
447
- state.error.message !== void 0 && state.error.message !== "" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-pe-error-detail", children: state.error.message })
448
- ] }) }),
449
- state.phase === "result" && state.result !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-pe-body", children: [
450
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-pe-col", children: [
451
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-pe-col-title", children: t("panel.original") }),
452
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "dsh-pe-col-text", children: state.original })
453
- ] }),
454
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-pe-col", children: [
455
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsh-pe-col-title", children: t("panel.enhanced") }),
456
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("pre", { className: "dsh-pe-col-text", children: state.result.text })
457
- ] })
458
- ] }),
459
- state.phase === "result" && state.stale && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsh-pe-stale", children: [
460
- "\u26A0 ",
461
- t("panel.stale.warn")
462
- ] }),
463
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("footer", { className: "dsh-pe-foot", children: [
464
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "dsh-pe-grow" }),
465
- state.phase === "error" && retryable(state.error?.code) && onRetry !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "dsh-pe-btn-action plain", onClick: onRetry, children: t("panel.retry") }),
466
- state.phase === "result" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
467
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "dsh-pe-btn-action plain", onClick: copy, children: copied === "ok" ? t("panel.copied") : copied === "failed" ? t("panel.copyFailed") : t("panel.copy") }),
468
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "dsh-pe-btn-action primary", onClick: onApply, children: t("panel.apply") })
469
- ] }),
470
- state.phase !== "result" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", className: "dsh-pe-btn-action plain", onClick: onCancel, children: state.phase === "loading" ? t("panel.cancel") : t("panel.close") })
471
- ] })
280
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { transform: "translate(5,3) scale(0.85)", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: FISH_PATH, fill: "currentColor" }) }),
281
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: STAR_PATH, transform: "translate(1.2,0.8) scale(0.55)", fill: "currentColor" }),
282
+ props.spinning === true ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("animate", { attributeName: "opacity", values: "1;0.35;1", dur: "1.1s", repeatCount: "indefinite" }) : null
472
283
  ]
473
284
  }
474
- ) });
285
+ );
475
286
  }
476
287
 
477
288
  // src/client/undo-stack.ts
@@ -612,6 +423,9 @@ function closePanel() {
612
423
  panelState = void 0;
613
424
  notify();
614
425
  }
426
+ function runSession(sessionId, text) {
427
+ sessions.get(sessionId)?.run(text);
428
+ }
615
429
  function registerSession(sessionId, entry) {
616
430
  sessions.set(sessionId, entry);
617
431
  lastMountedSession = sessionId;
@@ -680,7 +494,7 @@ function decodeClientSettings(section) {
680
494
  }
681
495
 
682
496
  // src/client/session-key.ts
683
- var import_react2 = require("react");
497
+ var import_react = require("react");
684
498
  var fallbackSeq = 0;
685
499
  var zoneKeys = /* @__PURE__ */ new WeakMap();
686
500
  function fallbackKeyOf(share) {
@@ -692,7 +506,7 @@ function fallbackKeyOf(share) {
692
506
  return minted;
693
507
  }
694
508
  function useSessionKey(maybeSessionId, share) {
695
- const fallback = (0, import_react2.useRef)(void 0);
509
+ const fallback = (0, import_react.useRef)(void 0);
696
510
  if (maybeSessionId !== void 0 && maybeSessionId !== "") return maybeSessionId;
697
511
  if (fallback.current === void 0) fallback.current = fallbackKeyOf(share);
698
512
  return fallback.current;
@@ -716,117 +530,473 @@ function EnhanceButton(props) {
716
530
  const draft = useInput((state) => stringOf(state.draft));
717
531
  const phase = useInput((state) => state.phase);
718
532
  const occurrenceCount = useInput((state) => countOf(state.occurrences));
719
- const attachmentCount = useInput((state) => {
720
- const record = state;
721
- return countOf(record.attachmentIds) + countOf(record.imageIds);
722
- });
723
- const settings = (0, import_react3.useSyncExternalStore)(subscribeClientSettings, getClientSettings);
724
- const panel = (0, import_react3.useSyncExternalStore)(subscribe, getPanel);
725
- const rootRef = (0, import_react3.useRef)(null);
533
+ const settings = (0, import_react2.useSyncExternalStore)(subscribeClientSettings, getClientSettings);
534
+ const panel = (0, import_react2.useSyncExternalStore)(subscribe, getPanel);
535
+ const rootRef = (0, import_react2.useRef)(null);
726
536
  const busy = panel !== void 0 && panel.sessionId === uiKey && panel.phase === "loading";
727
537
  const anyBusy = panel !== void 0 && panel.phase === "loading";
728
538
  const otherBusy = anyBusy && !busy;
729
- const start = (0, import_react3.useCallback)(() => {
730
- if (anyBusy) return;
539
+ const empty = draft.trim() === "";
540
+ const start = (0, import_react2.useCallback)((overrideText) => {
541
+ const source = overrideText ?? draft;
542
+ if (anyBusy || source.trim() === "") return;
731
543
  if (!settings.enabled) {
732
544
  const disabled = t("error.disabled");
733
545
  openError(uiKey, draft, { code: "rejected", localized: disabled });
734
546
  return;
735
547
  }
736
- if (attachmentCount > 0 && draft.trim() === "") {
737
- const attachmentsOnly = t("error.attachmentsOnly");
738
- openError(uiKey, draft, { code: "rejected", localized: attachmentsOnly });
739
- return;
740
- }
741
- const check = checkInputText(draft, settings.maxInputChars);
548
+ const check = checkInputText(source, settings.maxInputChars);
742
549
  if (!check.ok) {
743
550
  const message = check.code === "empty" ? t("error.empty") : t("error.tooLong", { count: check.count, max: check.max });
744
- openError(uiKey, draft, { code: "rejected", localized: message });
551
+ openError(uiKey, source, { code: "rejected", localized: message });
745
552
  return;
746
553
  }
747
554
  if (occurrenceCount > 0) {
748
555
  const occurrences = t("error.occurrences");
749
- openError(uiKey, draft, { code: "rejected", localized: occurrences });
556
+ openError(uiKey, source, { code: "rejected", localized: occurrences });
750
557
  return;
751
558
  }
752
559
  if (phase !== "plain") {
753
560
  const busyPhase = t("error.phase");
754
- openError(uiKey, draft, { code: "rejected", localized: busyPhase });
561
+ openError(uiKey, source, { code: "rejected", localized: busyPhase });
755
562
  return;
756
563
  }
757
564
  const controller = new AbortController();
758
- openLoading({ sessionId: uiKey, original: draft, abort: () => controller.abort() });
565
+ openLoading({ sessionId: uiKey, original: source, abort: () => controller.abort() });
759
566
  const settle = (result) => settleResult(uiKey, result);
760
567
  const fail = (error) => {
761
568
  const detail = error instanceof EnhanceClientError ? error.detail : { code: "internal", message: error instanceof Error ? error.message : String(error) };
762
569
  settleError(uiKey, detail);
763
570
  };
764
571
  if (settings.streaming) {
765
- requestEnhanceStream({ sessionId: wireId, text: draft }, {
572
+ requestEnhanceStream({ sessionId: wireId, text: source }, {
766
573
  signal: controller.signal,
767
574
  onDelta: (delta) => appendDelta(uiKey, delta)
768
575
  }).then(settle, fail);
769
576
  return;
770
577
  }
771
- requestEnhance({ sessionId: wireId, text: draft }, controller.signal).then(settle, fail);
772
- }, [anyBusy, draft, attachmentCount, occurrenceCount, phase, settings, uiKey, wireId, t]);
773
- const runRef = (0, import_react3.useRef)(start);
774
- (0, import_react3.useEffect)(() => {
578
+ requestEnhance({ sessionId: wireId, text: source }, controller.signal).then(settle, fail);
579
+ }, [anyBusy, draft, occurrenceCount, phase, settings, uiKey, wireId, t]);
580
+ const runRef = (0, import_react2.useRef)(start);
581
+ (0, import_react2.useEffect)(() => {
775
582
  runRef.current = start;
776
583
  });
777
- (0, import_react3.useEffect)(() => {
584
+ (0, import_react2.useEffect)(() => {
778
585
  const entry = {
779
586
  root: rootRef.current,
780
- run: () => runRef.current()
587
+ run: (text) => runRef.current(text)
781
588
  };
782
589
  return registerSession(uiKey, entry);
783
590
  }, [uiKey]);
784
- (0, import_react3.useEffect)(() => {
591
+ (0, import_react2.useEffect)(() => {
785
592
  if (panel !== void 0 && panel.sessionId === uiKey && panel.phase === "result") {
786
593
  setStale(uiKey, draft !== panel.original);
787
594
  }
788
595
  }, [draft, panel, uiKey]);
789
- const apply2 = (0, import_react3.useCallback)(() => {
790
- if (panel === void 0 || panel.phase !== "result" || panel.result === void 0) return;
791
- pushUndo(uiKey, { original: draft, applied: panel.result.text });
792
- inputActions.setDraft(panel.result.text);
793
- closePanel();
794
- }, [draft, inputActions, panel, uiKey]);
795
596
  if (!settings.enabled) return null;
796
- const owned = panel !== void 0 && panel.sessionId === uiKey ? panel : void 0;
797
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
798
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
799
- "button",
800
- {
801
- ref: rootRef,
802
- type: "button",
803
- className: `dsh-pe-btn${busy ? " is-busy" : ""}`,
804
- title: busy ? t("button.busy") : otherBusy ? t("button.otherBusy") : t("button.title"),
805
- "aria-label": otherBusy ? t("button.otherBusy") : t("button.title"),
806
- "aria-disabled": otherBusy || void 0,
807
- onClick: start,
808
- children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dsh-pe-btn-icon", "aria-hidden": true, children: busy ? "\u25CC" : "\u2728" })
597
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
598
+ "button",
599
+ {
600
+ ref: rootRef,
601
+ type: "button",
602
+ className: `dsh-pe-btn${busy ? " is-busy" : ""}${otherBusy && !empty ? " is-blocked" : ""}${empty && !busy ? " is-empty" : ""}`,
603
+ title: busy ? t("button.busy") : otherBusy ? t("button.otherBusy") : empty ? t("button.emptyTitle") : t("button.title"),
604
+ "aria-label": busy ? t("button.busy") : otherBusy ? t("button.otherBusy") : empty ? t("button.emptyTitle") : t("button.title"),
605
+ "aria-disabled": empty || otherBusy || void 0,
606
+ onClick: () => start(),
607
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "dsh-pe-btn-icon", "aria-hidden": true, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SparkleFishIcon, { size: 15, spinning: busy }) })
608
+ }
609
+ ) });
610
+ }
611
+
612
+ // src/client/ResultDock.tsx
613
+ var import_react4 = require("react");
614
+
615
+ // src/client/ResultPanel.tsx
616
+ var import_react3 = require("react");
617
+
618
+ // src/client/ActionIcons.tsx
619
+ var import_jsx_runtime3 = require("react/jsx-runtime");
620
+ function icon(paths) {
621
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
622
+ "svg",
623
+ {
624
+ width: 14,
625
+ height: 14,
626
+ viewBox: "0 0 24 24",
627
+ fill: "none",
628
+ stroke: "currentColor",
629
+ strokeWidth: 2,
630
+ strokeLinecap: "round",
631
+ strokeLinejoin: "round",
632
+ "aria-hidden": "true",
633
+ focusable: "false",
634
+ style: { display: "block", flexShrink: 0 },
635
+ children: paths
636
+ }
637
+ );
638
+ }
639
+ function RegenerateIcon() {
640
+ return icon([
641
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M21 12a9 9 0 1 1-3-6.7L21 8" }, "arc"),
642
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M21 3v5h-5" }, "head")
643
+ ]);
644
+ }
645
+ function CopyIcon() {
646
+ return icon([
647
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2" }, "front"),
648
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" }, "back")
649
+ ]);
650
+ }
651
+ function FillIcon() {
652
+ return icon([
653
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M12 3v12" }, "stem"),
654
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m7 10 5 5 5-5" }, "head"),
655
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M5 21h14" }, "tray")
656
+ ]);
657
+ }
658
+ function UndoIcon() {
659
+ return icon([
660
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M9 14 4 9l5-5" }, "head"),
661
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M4 9h10.5a5.5 5.5 0 0 1 0 11H8" }, "curve")
662
+ ]);
663
+ }
664
+
665
+ // src/client/ResultPanel.tsx
666
+ var import_jsx_runtime4 = require("react/jsx-runtime");
667
+ var retryable = (code) => code === "upstream" || code === "timeout" || code === "internal";
668
+ var UPSTREAM_ERROR_KEYS = {
669
+ auth: "error.upstream.auth",
670
+ "invalid-credential": "error.upstream.invalidCredential",
671
+ "rate-limit": "error.upstream.rateLimit",
672
+ quota: "error.upstream.quota",
673
+ empty: "error.upstream.empty",
674
+ "context-window": "error.upstream.contextWindow",
675
+ "tool-call": "error.upstream.toolCall",
676
+ "max-tokens": "error.upstream.maxTokens"
677
+ };
678
+ function localizedErrorMessage(t, code, params) {
679
+ if (code === "rejected" && typeof params?.count === "number" && typeof params?.max === "number") {
680
+ return t("error.tooLong", { count: params.count, max: params.max });
681
+ }
682
+ if (code === "upstream" && typeof params?.reason === "string") {
683
+ const specific = UPSTREAM_ERROR_KEYS[params.reason];
684
+ if (specific !== void 0) return t(specific);
685
+ }
686
+ switch (code) {
687
+ case "rejected":
688
+ return t("error.rejected");
689
+ case "rate-limit":
690
+ return t("error.rateLimit", params);
691
+ case "concurrency-limit":
692
+ return t("error.concurrencyLimit", params);
693
+ case "cooldown":
694
+ return t("error.cooldown", params);
695
+ case "timeout":
696
+ return t("error.timeout", params);
697
+ case "unconfigured":
698
+ return t("error.unconfigured");
699
+ case "effort-unsupported":
700
+ return t("error.effortUnsupported", params);
701
+ case "upstream":
702
+ return t("error.upstream");
703
+ default:
704
+ return t("error.internal");
705
+ }
706
+ }
707
+ function fallbackCopy(text) {
708
+ try {
709
+ const textarea = document.createElement("textarea");
710
+ textarea.value = text;
711
+ textarea.style.position = "fixed";
712
+ textarea.style.opacity = "0";
713
+ document.body.appendChild(textarea);
714
+ textarea.select();
715
+ const ok = document.execCommand("copy");
716
+ textarea.remove();
717
+ return ok;
718
+ } catch {
719
+ return false;
720
+ }
721
+ }
722
+ function formatTokens(tokens) {
723
+ return tokens.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
724
+ }
725
+ function totalTokensOf(usage) {
726
+ return usage.totalTokens ?? usage.inputTokens + usage.outputTokens + (usage.cacheReadTokens ?? 0) + (usage.cacheWriteTokens ?? 0);
727
+ }
728
+ function ResultPanel(props) {
729
+ const { state, t, onApply, onCancel, onRetry, applied = false, onUndo, onRegenerate, undone = false, regenerated = false } = props;
730
+ const [copied, setCopied] = (0, import_react3.useState)("idle");
731
+ const copy = (0, import_react3.useCallback)(() => {
732
+ if (state.result === void 0) return;
733
+ const text = state.result.text;
734
+ const done = (ok) => {
735
+ setCopied(ok ? "ok" : "failed");
736
+ if (ok) setTimeout(() => setCopied("idle"), 2500);
737
+ };
738
+ if (navigator.clipboard !== void 0) {
739
+ navigator.clipboard.writeText(text).then(() => done(true), () => done(fallbackCopy(text)));
740
+ return;
741
+ }
742
+ done(fallbackCopy(text));
743
+ }, [state.result]);
744
+ const formatMs = (ms) => ms < 1e3 ? `${ms}ms` : `${(ms / 1e3).toFixed(1)}s`;
745
+ const tokenDetail = (usage) => {
746
+ const parts = [
747
+ t("panel.tokens.input", { count: formatTokens(usage.inputTokens) }),
748
+ t("panel.tokens.output", { count: formatTokens(usage.outputTokens) })
749
+ ];
750
+ if ((usage.cacheReadTokens ?? 0) > 0) {
751
+ parts.push(t("panel.tokens.cacheRead", { count: formatTokens(usage.cacheReadTokens ?? 0) }));
752
+ }
753
+ if ((usage.cacheWriteTokens ?? 0) > 0) {
754
+ parts.push(t("panel.tokens.cacheWrite", { count: formatTokens(usage.cacheWriteTokens ?? 0) }));
755
+ }
756
+ return parts.join(" \xB7 ");
757
+ };
758
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: "dsh-pe-panel", role: "region", "aria-label": t("panel.title"), children: [
759
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("header", { className: "dsh-pe-head", children: [
760
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "dsh-pe-title", children: [
761
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SparkleFishIcon, { size: 15 }),
762
+ t("panel.title")
763
+ ] }),
764
+ state.phase === "result" && state.result !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "dsh-pe-badge", children: [
765
+ t("panel.model", { provider: state.result.provider, model: state.result.model }),
766
+ " \xB7 ",
767
+ t("panel.elapsed", { ms: formatMs(state.result.elapsedMs) }),
768
+ state.result.usage === void 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
769
+ " \xB7 ",
770
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { title: tokenDetail(state.result.usage), children: t("panel.tokens", { total: formatTokens(totalTokensOf(state.result.usage)) }) })
771
+ ] })
772
+ ] }),
773
+ copied === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "dsh-pe-applied", children: t("panel.copiedShort") }) : regenerated ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "dsh-pe-applied", children: t("panel.regeneratedShort") }) : applied ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "dsh-pe-applied", children: t("panel.appliedShort") }) : undone ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "dsh-pe-applied", children: t("panel.undoneShort") }) : null,
774
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "dsh-pe-close", "aria-label": t("panel.close"), onClick: onCancel, children: "\u2715" })
775
+ ] }),
776
+ state.phase === "loading" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "dsh-pe-loading", children: state.streaming === void 0 || state.streaming === "" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
777
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "dsh-pe-spin", "aria-hidden": true }),
778
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { children: t("panel.loading") }),
779
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "dsh-pe-hint", children: t("panel.loading.hint") })
780
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "dsh-pe-stream", children: [
781
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "dsh-pe-col-title", children: [
782
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "dsh-pe-spin small", "aria-hidden": true }),
783
+ t("panel.streaming")
784
+ ] }),
785
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("pre", { className: "dsh-pe-result-text", children: state.streaming })
786
+ ] }) }),
787
+ state.phase === "error" && state.error !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "dsh-pe-error", children: state.error.localized !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { children: state.error.localized }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
788
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { children: localizedErrorMessage(t, state.error.code, state.error.params) }),
789
+ state.error.message !== void 0 && state.error.message !== "" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "dsh-pe-error-detail", children: state.error.message })
790
+ ] }) }),
791
+ state.phase === "result" && state.result !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "dsh-pe-result", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("pre", { className: "dsh-pe-result-text", children: state.result.text }) }),
792
+ state.phase === "result" && state.result?.truncated === true && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "dsh-pe-stale", children: [
793
+ "\u26A0 ",
794
+ t("panel.truncated")
795
+ ] }),
796
+ state.phase === "result" && state.stale && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "dsh-pe-stale", children: [
797
+ "\u26A0 ",
798
+ t("panel.stale.warn")
799
+ ] }),
800
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("footer", { className: "dsh-pe-foot", children: [
801
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "dsh-pe-grow" }),
802
+ state.phase === "result" && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { type: "button", className: "dsh-pe-btn-action plain", onClick: onRegenerate, disabled: onRegenerate === void 0, children: [
803
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(RegenerateIcon, {}),
804
+ t("panel.regenerate")
805
+ ] }),
806
+ state.phase === "error" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: retryable(state.error?.code) && onRetry !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "dsh-pe-btn-action plain", onClick: onRetry, children: t("panel.retry") }) }),
807
+ state.phase === "loading" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "dsh-pe-btn-action plain", onClick: onCancel, children: t("panel.cancel") }),
808
+ state.phase === "result" && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
809
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { type: "button", className: "dsh-pe-btn-action plain dsh-pe-copy", onClick: copy, children: [
810
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopyIcon, {}),
811
+ copied === "ok" ? t("panel.copied") : copied === "failed" ? t("panel.copyFailed") : t("panel.copy")
812
+ ] }),
813
+ applied ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { type: "button", className: "dsh-pe-btn-action primary", onClick: onUndo, disabled: onUndo === void 0, children: [
814
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(UndoIcon, {}),
815
+ t("undo.undo")
816
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { type: "button", className: "dsh-pe-btn-action primary", onClick: onApply, children: [
817
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(FillIcon, {}),
818
+ t("panel.apply")
819
+ ] })
820
+ ] })
821
+ ] })
822
+ ] });
823
+ }
824
+
825
+ // src/client/ResultDock.tsx
826
+ var import_jsx_runtime5 = require("react/jsx-runtime");
827
+ function ResultDock(props) {
828
+ const { t, sessionId, useInput, inputActions } = props;
829
+ const uiKey = useSessionKey(sessionId, inputActions);
830
+ const rootRef = (0, import_react4.useRef)(null);
831
+ const [undone, setUndone] = (0, import_react4.useState)(false);
832
+ const [regenerated, setRegenerated] = (0, import_react4.useState)(false);
833
+ const [pendingRegenerate, setPendingRegenerate] = (0, import_react4.useState)(false);
834
+ const previousResultRef = (0, import_react4.useRef)(void 0);
835
+ const panel = (0, import_react4.useSyncExternalStore)(subscribe, getPanel);
836
+ const draft = useInput((state) => {
837
+ const value = state.draft;
838
+ return typeof value === "string" ? value : "";
839
+ });
840
+ const phase = useInput((state) => {
841
+ const value = state.phase;
842
+ return typeof value === "string" ? value : "";
843
+ });
844
+ const useSession = props.useSession;
845
+ const sessionRunning = useSession === void 0 ? false : Boolean(useSession((state) => state.running));
846
+ const sessionQueued = useSession === void 0 ? 0 : Number(useSession((state) => state.queue?.length ?? 0));
847
+ const entry = peekUndo(uiKey);
848
+ const applied = entry !== void 0 && entry.applied === draft;
849
+ const prevSession = (0, import_react4.useRef)({ running: sessionRunning, queued: sessionQueued });
850
+ (0, import_react4.useEffect)(() => {
851
+ const prev = prevSession.current;
852
+ prevSession.current = { running: sessionRunning, queued: sessionQueued };
853
+ if (panel === void 0 || panel.sessionId !== uiKey) return;
854
+ if (phase === "sending" || sessionRunning && !prev.running || sessionQueued > prev.queued) {
855
+ closePanel();
856
+ }
857
+ }, [phase, sessionRunning, sessionQueued, panel, uiKey]);
858
+ (0, import_react4.useEffect)(() => {
859
+ if (panel === void 0 || panel.sessionId !== uiKey) return;
860
+ const onKeyDown = (event) => {
861
+ if (event.defaultPrevented || event.isComposing || event.key !== "Escape") return;
862
+ event.preventDefault();
863
+ closePanel();
864
+ };
865
+ document.addEventListener("keydown", onKeyDown);
866
+ return () => document.removeEventListener("keydown", onKeyDown);
867
+ }, [panel, uiKey]);
868
+ (0, import_react4.useEffect)(() => {
869
+ if (!undone) return;
870
+ const timer = setTimeout(() => setUndone(false), 2500);
871
+ return () => clearTimeout(timer);
872
+ }, [undone]);
873
+ (0, import_react4.useEffect)(() => {
874
+ if (!pendingRegenerate) return;
875
+ if (panel === void 0 || panel.sessionId !== uiKey) {
876
+ setPendingRegenerate(false);
877
+ return;
878
+ }
879
+ if (panel.phase === "error") {
880
+ setPendingRegenerate(false);
881
+ return;
882
+ }
883
+ if (panel.phase === "result" && panel.result !== previousResultRef.current) {
884
+ setPendingRegenerate(false);
885
+ setRegenerated(true);
886
+ }
887
+ }, [panel, pendingRegenerate, uiKey]);
888
+ (0, import_react4.useEffect)(() => {
889
+ if (!regenerated) return;
890
+ const timer = setTimeout(() => setRegenerated(false), 2500);
891
+ return () => clearTimeout(timer);
892
+ }, [regenerated]);
893
+ (0, import_react4.useEffect)(() => {
894
+ if (!pendingRegenerate) return;
895
+ const timer = setTimeout(() => setPendingRegenerate(false), 15e3);
896
+ return () => clearTimeout(timer);
897
+ }, [pendingRegenerate]);
898
+ (0, import_react4.useEffect)(() => {
899
+ if (panel === void 0 || panel.sessionId !== uiKey) return;
900
+ const root = rootRef.current;
901
+ if (root === null) return;
902
+ let frame = 0;
903
+ const align = () => {
904
+ const parent = root.parentElement;
905
+ if (parent === null) return;
906
+ root.style.transform = "";
907
+ const previousMargin = parseFloat(root.style.marginLeft) || 0;
908
+ const rootRect = root.getBoundingClientRect();
909
+ const baseLeft = rootRect.left - previousMargin;
910
+ const editors = Array.from(document.querySelectorAll('textarea, [contenteditable="true"], [role="textbox"]'));
911
+ const editor = editors.find((node2) => {
912
+ const rect = node2.getBoundingClientRect();
913
+ return rect.width > 0 && rect.height > 0 && rect.top >= rootRect.bottom - 4;
914
+ });
915
+ if (editor === void 0) {
916
+ root.style.width = "";
917
+ root.style.marginLeft = "";
918
+ root.style.transform = "";
919
+ return;
809
920
  }
810
- ),
811
- owned !== void 0 && (0, import_react_dom.createPortal)(
812
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
813
- ResultPanel,
814
- {
815
- state: owned,
816
- t,
817
- onApply: apply2,
818
- onCancel: () => closePanel(),
819
- onRetry: owned.phase === "error" ? start : void 0
921
+ const editorRect = editor.getBoundingClientRect();
922
+ const candidates = [];
923
+ let node = editor;
924
+ for (let depth = 0; depth < 12 && node !== null; depth++) {
925
+ const rect = node.getBoundingClientRect();
926
+ const style = getComputedStyle(node);
927
+ if (rect.width >= editorRect.width && rect.width > 360 && rect.height > 48 && (parseFloat(style.borderTopLeftRadius) || 0) >= 4 && style.backgroundColor !== "rgba(0, 0, 0, 0)") {
928
+ candidates.push({ node, rect });
820
929
  }
821
- ),
822
- document.body
823
- )
824
- ] });
930
+ node = node.parentElement;
931
+ }
932
+ const editorCenter = editorRect.left + editorRect.width / 2;
933
+ const cardEntry = candidates.filter((candidate) => candidate.rect.width <= window.innerWidth * 0.8 && Math.abs(candidate.rect.left + candidate.rect.width / 2 - editorCenter) < 40).sort((a, b) => b.rect.width - a.rect.width)[0] ?? candidates.sort((a, b) => b.rect.width - a.rect.width)[0];
934
+ if (cardEntry === void 0) return;
935
+ const cardRect = cardEntry.rect;
936
+ const width = `${cardRect.width}px`;
937
+ if (root.style.width !== width) root.style.width = width;
938
+ const afterWidth = root.getBoundingClientRect();
939
+ const currentMargin = parseFloat(root.style.marginLeft) || 0;
940
+ const marginLeft = `${cardRect.left - (afterWidth.left - currentMargin)}px`;
941
+ if (root.style.marginLeft !== marginLeft) root.style.marginLeft = marginLeft;
942
+ };
943
+ const schedule = () => {
944
+ cancelAnimationFrame(frame);
945
+ frame = requestAnimationFrame(align);
946
+ };
947
+ schedule();
948
+ schedule();
949
+ window.addEventListener("resize", schedule);
950
+ const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(schedule);
951
+ observer?.observe(document.documentElement);
952
+ return () => {
953
+ cancelAnimationFrame(frame);
954
+ window.removeEventListener("resize", schedule);
955
+ observer?.disconnect();
956
+ };
957
+ }, [panel, uiKey]);
958
+ if (panel === void 0 || panel.sessionId !== uiKey) return null;
959
+ const apply2 = () => {
960
+ if (panel.phase !== "result" || panel.result === void 0) return;
961
+ pushUndo(uiKey, { original: draft, applied: panel.result.text });
962
+ inputActions.setDraft(panel.result.text);
963
+ setUndone(false);
964
+ setRegenerated(false);
965
+ };
966
+ const undo = () => {
967
+ if (entry === void 0) return;
968
+ inputActions.setDraft(entry.original);
969
+ popUndo(uiKey);
970
+ setUndone(true);
971
+ setRegenerated(false);
972
+ };
973
+ const regenerate = () => {
974
+ if (panel.phase !== "result") return;
975
+ previousResultRef.current = panel.result;
976
+ setRegenerated(false);
977
+ setPendingRegenerate(true);
978
+ runSession(uiKey);
979
+ };
980
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { ref: rootRef, className: "dsh-pe-dock", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
981
+ ResultPanel,
982
+ {
983
+ state: panel,
984
+ t,
985
+ applied,
986
+ undone,
987
+ regenerated,
988
+ onApply: apply2,
989
+ onUndo: undo,
990
+ onRegenerate: regenerate,
991
+ onCancel: () => closePanel(),
992
+ onRetry: panel.phase === "error" ? () => runSession(uiKey) : void 0
993
+ }
994
+ ) });
825
995
  }
826
996
 
827
997
  // src/client/UndoBar.tsx
828
- var import_react4 = require("react");
829
- var import_jsx_runtime3 = require("react/jsx-runtime");
998
+ var import_react5 = require("react");
999
+ var import_jsx_runtime6 = require("react/jsx-runtime");
830
1000
  function UndoBar(props) {
831
1001
  const { t, sessionId, useInput, inputActions } = props;
832
1002
  const uiKey = useSessionKey(sessionId, inputActions);
@@ -834,11 +1004,13 @@ function UndoBar(props) {
834
1004
  const value = state.draft;
835
1005
  return typeof value === "string" ? value : "";
836
1006
  });
837
- (0, import_react4.useSyncExternalStore)(subscribe, getVersion);
1007
+ (0, import_react5.useSyncExternalStore)(subscribe, getVersion);
838
1008
  const entry = peekUndo(uiKey);
839
- (0, import_react4.useEffect)(() => {
1009
+ (0, import_react5.useEffect)(() => {
840
1010
  if (entry !== void 0 && entry.applied !== draft) popUndo(uiKey);
841
1011
  }, [draft, entry, uiKey]);
1012
+ const panel = getPanel();
1013
+ if (panel !== void 0 && panel.sessionId === uiKey) return null;
842
1014
  if (entry === void 0 || entry.applied !== draft) return null;
843
1015
  const undo = () => {
844
1016
  inputActions.setDraft(entry.original);
@@ -847,11 +1019,11 @@ function UndoBar(props) {
847
1019
  const dismiss = () => {
848
1020
  popUndo(uiKey);
849
1021
  };
850
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsh-pe-undo", children: [
851
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "dsh-pe-undo-check", "aria-hidden": true, children: "\u2713" }),
852
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: t("undo.applied") }),
853
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: "dsh-pe-undo-link", onClick: undo, children: t("undo.undo") }),
854
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { type: "button", className: "dsh-pe-undo-x", "aria-label": t("undo.dismiss"), onClick: dismiss, children: "\u2715" })
1022
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "dsh-pe-undo", children: [
1023
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "dsh-pe-undo-check", "aria-hidden": true, children: "\u2713" }),
1024
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: t("undo.applied") }),
1025
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "dsh-pe-undo-link", onClick: undo, children: t("undo.undo") }),
1026
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "dsh-pe-undo-x", "aria-label": t("undo.dismiss"), onClick: dismiss, children: "\u2715" })
855
1027
  ] });
856
1028
  }
857
1029
 
@@ -860,20 +1032,27 @@ var zh = {
860
1032
  "button.title": "\u63D0\u793A\u8BCD\u589E\u5F3A",
861
1033
  "button.busy": "\u6B63\u5728\u589E\u5F3A\u2026",
862
1034
  "button.otherBusy": "\u53E6\u4E00\u4E2A\u4F1A\u8BDD\u6B63\u5728\u589E\u5F3A\u4E2D\uFF1B\u8BF7\u7B49\u5B83\u5B8C\u6210\u6216\u5148\u5173\u95ED\u5176\u7ED3\u679C\u9762\u677F\u3002",
1035
+ "button.emptyTitle": "\u63D0\u793A\u8BCD\u589E\u5F3A\uFF08\u5F53\u524D\u8F93\u5165\u533A\u4E3A\u7A7A\uFF0C\u8BF7\u5148\u8F93\u5165\u6587\u5B57\uFF09",
863
1036
  "panel.title": "\u63D0\u793A\u8BCD\u589E\u5F3A",
864
1037
  "panel.loading": "\u6B63\u5728\u589E\u5F3A\uFF0C\u7A0D\u5019\u2026",
865
- "panel.streaming": "\u6B63\u5728\u751F\u6210\uFF08\u8FB9\u5199\u8FB9\u663E\u793A\uFF09\u2026",
1038
+ "panel.streaming": "\u6B63\u5728\u751F\u6210\u2026",
866
1039
  "panel.loading.hint": "\u539F\u6587\u4FDD\u7559\u5728\u8F93\u5165\u6846\u4E2D\uFF0C\u4E0D\u4F1A\u88AB\u52A8\u4FEE\u6539\u3002",
867
1040
  "panel.cancel": "\u53D6\u6D88",
868
1041
  "panel.original": "\u539F\u59CB\u63D0\u793A\u8BCD",
869
1042
  "panel.enhanced": "\u589E\u5F3A\u7ED3\u679C",
870
1043
  "panel.apply": "\u56DE\u586B\u5230\u8F93\u5165\u6846",
1044
+ "panel.regenerate": "\u91CD\u65B0\u751F\u6210",
1045
+ "panel.appliedShort": "\u5DF2\u66FF\u6362 \u2713",
1046
+ "panel.undoneShort": "\u5DF2\u64A4\u9500 \u2713",
1047
+ "panel.regeneratedShort": "\u5DF2\u91CD\u65B0\u751F\u6210 \u2713",
1048
+ "panel.copiedShort": "\u5DF2\u590D\u5236 \u2713",
871
1049
  "panel.copy": "\u590D\u5236\u7ED3\u679C",
872
1050
  "panel.copied": "\u5DF2\u590D\u5236",
873
1051
  "panel.copyFailed": "\u590D\u5236\u5931\u8D25",
874
1052
  "panel.close": "\u5173\u95ED",
875
1053
  "panel.retry": "\u91CD\u8BD5",
876
- "panel.stale.warn": "\u8349\u7A3F\u5728\u589E\u5F3A\u671F\u95F4\u6709\u6539\u52A8\u2014\u2014\u589E\u5F3A\u7ED3\u679C\u57FA\u4E8E\u589E\u5F3A\u524D\u7684\u6587\u672C\u3002\u56DE\u586B\u5C06\u8986\u76D6\u4F60\u7684\u6700\u65B0\u7F16\u8F91(\u64A4\u9500\u53EF\u6062\u590D\u56DE\u586B\u524D\u7684\u8349\u7A3F)\u3002",
1054
+ "panel.stale.warn": "\u8349\u7A3F\u5DF2\u6539\u52A8\uFF0C\u5F53\u524D\u7ED3\u679C\u57FA\u4E8E\u6539\u52A8\u524D\u7684\u6587\u672C\uFF1B\u56DE\u586B\u4F1A\u8986\u76D6\u5F53\u524D\u8F93\u5165\uFF08\u53EF\u64A4\u9500\uFF09\u3002",
1055
+ "panel.truncated": "\u8F93\u51FA\u8FBE\u5230 Token \u4E0A\u9650\uFF0C\u7ED3\u679C\u53EF\u80FD\u4E0D\u5B8C\u6574\u3002\u53EF\u5728\u8BBE\u7F6E\u4E2D\u8C03\u9AD8\u300C\u6700\u5927\u8F93\u51FA Token\u300D\u3002",
877
1056
  "panel.model": "\u6A21\u578B\uFF1A{provider} / {model}",
878
1057
  "panel.elapsed": "\u8017\u65F6 {ms}",
879
1058
  "panel.tokens": "{total} tokens",
@@ -991,20 +1170,27 @@ var en = {
991
1170
  "button.title": "Enhance prompt",
992
1171
  "button.busy": "Enhancing\u2026",
993
1172
  "button.otherBusy": "Another session is enhancing right now \u2014 wait for it, or close its result panel first.",
1173
+ "button.emptyTitle": "Enhance prompt (the input is empty \u2014 type something first)",
994
1174
  "panel.title": "Prompt Enhance",
995
1175
  "panel.loading": "Enhancing, please wait\u2026",
996
- "panel.streaming": "Generating (shown as it is written)\u2026",
1176
+ "panel.streaming": "Generating\u2026",
997
1177
  "panel.loading.hint": "Your draft stays untouched until you apply the result.",
998
1178
  "panel.cancel": "Cancel",
999
1179
  "panel.original": "Original prompt",
1000
1180
  "panel.enhanced": "Enhanced result",
1001
1181
  "panel.apply": "Fill into input box",
1182
+ "panel.regenerate": "Regenerate",
1183
+ "panel.appliedShort": "Replaced \u2713",
1184
+ "panel.undoneShort": "Undone \u2713",
1185
+ "panel.regeneratedShort": "Regenerated \u2713",
1186
+ "panel.copiedShort": "Copied \u2713",
1002
1187
  "panel.copy": "Copy result",
1003
1188
  "panel.copied": "Copied",
1004
1189
  "panel.copyFailed": "Copy failed",
1005
1190
  "panel.close": "Close",
1006
1191
  "panel.retry": "Retry",
1007
- "panel.stale.warn": "The draft changed while enhancing \u2014 the result is based on the pre-enhance text. Applying will overwrite your latest edits (undo restores the draft as it was before applying).",
1192
+ "panel.stale.warn": "Draft changed \u2014 this result uses the earlier text; Apply overwrites the current input (undoable).",
1193
+ "panel.truncated": 'Output hit the token cap and may be incomplete. Raise "Max output tokens" in the settings.',
1008
1194
  "panel.model": "Model: {provider} / {model}",
1009
1195
  "panel.elapsed": "{ms} elapsed",
1010
1196
  "panel.tokens": "{total} tokens",
@@ -1124,17 +1310,9 @@ var NS = "dsh-prompt-enhance";
1124
1310
  // src/client/styles.ts
1125
1311
  var STYLE_ID = "dsh-prompt-enhance-styles";
1126
1312
  var CSS = `
1127
- .dsh-pe-overlay {
1128
- position: fixed;
1129
- inset: 0;
1130
- z-index: var(--dsh-pe-z-index, 1000);
1131
- display: flex;
1132
- align-items: flex-end;
1133
- justify-content: center;
1134
- background: rgba(0, 0, 0, 0.32);
1135
- padding: 24px 16px;
1136
- }
1313
+ .dsh-pe-dock { width: 100%; }
1137
1314
  .dsh-pe-panel {
1315
+ box-sizing: border-box;
1138
1316
  --pe-bg: #1f2127;
1139
1317
  --pe-fg: #e6e8ee;
1140
1318
  --pe-fg-dim: rgba(230, 232, 238, 0.55);
@@ -1147,15 +1325,14 @@ var CSS = `
1147
1325
  --pe-warn-bg: rgba(230, 158, 60, 0.12);
1148
1326
  display: flex;
1149
1327
  flex-direction: column;
1150
- width: min(880px, 100%);
1151
- max-height: min(70vh, 640px);
1328
+ width: 100%;
1329
+ margin-bottom: 6px;
1152
1330
  border-radius: 12px;
1153
1331
  border: 1px solid var(--pe-border);
1154
1332
  background: var(--pe-bg);
1155
1333
  color: var(--pe-fg);
1156
- box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
1334
+ box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03), 0 4px 14px rgba(0, 0, 0, 0.05);
1157
1335
  overflow: hidden;
1158
- outline: none;
1159
1336
  }
1160
1337
  @media (prefers-color-scheme: light) {
1161
1338
  .dsh-pe-panel {
@@ -1175,45 +1352,58 @@ var CSS = `
1175
1352
  display: flex;
1176
1353
  align-items: center;
1177
1354
  gap: 8px;
1178
- padding: 10px 14px;
1355
+ padding: 8px 10px;
1179
1356
  border-bottom: 1px solid var(--pe-separator);
1180
- font-size: 13px;
1357
+ font-size: 12.5px;
1181
1358
  font-weight: 600;
1182
1359
  }
1183
- .dsh-pe-head .dsh-pe-meta { margin-left: auto; font-weight: 400; font-size: 11px; opacity: 0.6; }
1360
+ .dsh-pe-head .dsh-pe-title { display: inline-flex; align-items: center; gap: 6px; }
1361
+ .dsh-pe-head .dsh-pe-badge {
1362
+ margin-left: auto;
1363
+ border: 1px solid var(--pe-border);
1364
+ border-radius: 999px;
1365
+ padding: 1px 8px;
1366
+ font-weight: 400;
1367
+ font-size: 11px;
1368
+ opacity: 0.72;
1369
+ white-space: nowrap;
1370
+ }
1371
+ .dsh-pe-applied {
1372
+ font-size: 10.5px;
1373
+ font-weight: 500;
1374
+ line-height: 1;
1375
+ padding: 3px 7px;
1376
+ border-radius: 999px;
1377
+ color: var(--dsw-alias-state-success-primary, #2da44e);
1378
+ border: 1px solid currentColor;
1379
+ white-space: nowrap;
1380
+ }
1184
1381
  .dsh-pe-close {
1185
1382
  border: none; background: transparent; color: inherit; opacity: 0.6;
1186
1383
  font-size: 15px; cursor: pointer; padding: 2px 6px; border-radius: 4px;
1187
1384
  }
1188
1385
  .dsh-pe-close:hover { opacity: 1; background: var(--pe-hover); }
1189
- .dsh-pe-body { display: flex; flex: 1; min-height: 0; }
1190
- .dsh-pe-col {
1191
- flex: 1 1 0;
1192
- min-width: 0;
1193
- display: flex;
1194
- flex-direction: column;
1195
- }
1196
- .dsh-pe-col + .dsh-pe-col { border-left: 1px solid var(--pe-separator); }
1197
- .dsh-pe-col-title {
1198
- padding: 8px 14px 6px;
1199
- font-size: 11px;
1200
- letter-spacing: 0.04em;
1201
- opacity: 0.55;
1202
- }
1203
- .dsh-pe-col-text {
1204
- flex: 1;
1386
+ .dsh-pe-result { padding: 2px 10px 6px; }
1387
+ .dsh-pe-result-text {
1205
1388
  margin: 0;
1206
- padding: 0 14px 12px;
1389
+ max-height: 30vh;
1207
1390
  overflow: auto;
1208
1391
  white-space: pre-wrap;
1209
1392
  word-break: break-word;
1393
+ overflow-wrap: anywhere;
1210
1394
  font-family: inherit;
1211
- font-size: 13px;
1395
+ font-size: 12.5px;
1212
1396
  line-height: 1.6;
1213
1397
  }
1398
+ .dsh-pe-col-title {
1399
+ padding: 4px 10px 2px;
1400
+ font-size: 11px;
1401
+ letter-spacing: 0.04em;
1402
+ opacity: 0.55;
1403
+ }
1214
1404
  .dsh-pe-error {
1215
- padding: 20px 16px;
1216
- font-size: 13px;
1405
+ padding: 10px;
1406
+ font-size: 12.5px;
1217
1407
  line-height: 1.6;
1218
1408
  color: var(--pe-danger);
1219
1409
  white-space: pre-wrap;
@@ -1227,7 +1417,7 @@ var CSS = `
1227
1417
  .dsh-pe-loading {
1228
1418
  display: flex; flex-direction: column; gap: 8px;
1229
1419
  align-items: center; justify-content: center;
1230
- flex: 1; padding: 28px 16px; font-size: 13px;
1420
+ flex: 1; padding: 14px 10px; font-size: 12.5px;
1231
1421
  }
1232
1422
  .dsh-pe-loading .dsh-pe-hint { font-size: 11px; opacity: 0.55; }
1233
1423
  /* Incremental view: the streamed text takes the whole body, left-aligned. */
@@ -1248,22 +1438,42 @@ var CSS = `
1248
1438
  .dsh-pe-foot {
1249
1439
  display: flex;
1250
1440
  align-items: center;
1251
- gap: 8px;
1252
- padding: 10px 14px;
1441
+ gap: 6px;
1442
+ padding: 8px 10px;
1253
1443
  border-top: 1px solid var(--pe-separator);
1254
1444
  }
1255
1445
  .dsh-pe-foot .dsh-pe-grow { flex: 1; }
1256
1446
  .dsh-pe-btn-action {
1257
- border: none; border-radius: 6px; padding: 6px 14px;
1258
- font-size: 12px; cursor: pointer; line-height: 1;
1447
+ box-sizing: border-box;
1448
+ display: inline-flex;
1449
+ align-items: center;
1450
+ justify-content: center;
1451
+ gap: 6px;
1452
+ height: 28px;
1453
+ padding: 0 10px;
1454
+ border: 1px solid var(--pe-border);
1455
+ border-radius: 6px;
1456
+ background: transparent;
1457
+ color: inherit;
1458
+ font-size: 12px;
1459
+ line-height: 1;
1460
+ white-space: nowrap;
1461
+ cursor: pointer;
1462
+ }
1463
+ .dsh-pe-btn-action.primary {
1464
+ min-width: 112px;
1465
+ border-color: transparent;
1466
+ background: #3f76e1;
1467
+ color: #fff;
1259
1468
  }
1260
- .dsh-pe-btn-action.primary { background: #3f76e1; color: #fff; }
1261
1469
  .dsh-pe-btn-action.primary:hover { background: #4d82ec; }
1262
- .dsh-pe-btn-action.plain { background: var(--pe-hover); color: inherit; }
1263
- .dsh-pe-btn-action.plain:hover { background: rgba(127, 127, 127, 0.3); }
1470
+ .dsh-pe-btn-action.plain { background: transparent; color: inherit; }
1471
+ .dsh-pe-btn-action.plain:hover { background: var(--pe-hover); }
1472
+ .dsh-pe-btn-action.dsh-pe-copy { min-width: 96px; }
1473
+ .dsh-pe-btn-action:disabled { opacity: 0.45; cursor: default; }
1264
1474
 
1265
1475
  .dsh-pe-stale {
1266
- padding: 8px 14px;
1476
+ padding: 6px 10px;
1267
1477
  font-size: 12px;
1268
1478
  line-height: 1.5;
1269
1479
  border-top: 1px solid var(--pe-warn-border);
@@ -1288,9 +1498,12 @@ var CSS = `
1288
1498
  white-space: nowrap;
1289
1499
  }
1290
1500
  .dsh-pe-btn:hover:not(:disabled) { opacity: 1; background: var(--pe-hover); }
1501
+ .dsh-pe-btn.is-busy { cursor: progress; }
1502
+ .dsh-pe-btn.is-blocked { cursor: progress; }
1503
+ .dsh-pe-btn.is-empty { opacity: 0.4; cursor: not-allowed; }
1504
+ .dsh-pe-btn.is-empty:hover { opacity: 0.4; background: transparent; }
1291
1505
  .dsh-pe-btn:disabled { opacity: 0.45; cursor: default; }
1292
- .dsh-pe-btn .dsh-pe-btn-icon { font-size: 14px; }
1293
- .dsh-pe-btn.is-busy .dsh-pe-btn-icon { animation: dsh-pe-spin 1s linear infinite; }
1506
+ .dsh-pe-btn .dsh-pe-btn-icon { display: inline-flex; align-items: center; }
1294
1507
  @keyframes dsh-pe-spin { to { transform: rotate(360deg); } }
1295
1508
 
1296
1509
  .dsh-pe-undo {
@@ -1503,7 +1716,7 @@ function installClientSettingsSource(ctx, options) {
1503
1716
  }
1504
1717
 
1505
1718
  // src/client/settings-page.tsx
1506
- var import_react6 = require("react");
1719
+ var import_react7 = require("react");
1507
1720
 
1508
1721
  // src/shared/defaults.ts
1509
1722
  var DEFAULT_VALUES = {
@@ -1577,7 +1790,7 @@ async function fetchReasoningCapabilities(provider, model, options = {}) {
1577
1790
  }
1578
1791
 
1579
1792
  // src/client/llm-catalog.ts
1580
- var import_react5 = require("react");
1793
+ var import_react6 = require("react");
1581
1794
 
1582
1795
  // src/shared/catalog.ts
1583
1796
  var LLM_PROVIDERS_ENDPOINT = "/dsh-prompt-enhance/llm-providers";
@@ -1623,17 +1836,17 @@ async function fetchRouteCheck(provider, model, signal) {
1623
1836
  return value;
1624
1837
  }
1625
1838
  function useLlmRouting(provider, model) {
1626
- const [providers, setProviders] = (0, import_react5.useState)([]);
1627
- const [providersLoading, setProvidersLoading] = (0, import_react5.useState)(true);
1628
- const [providersFailed, setProvidersFailed] = (0, import_react5.useState)(false);
1629
- const [providersToken, setProvidersToken] = (0, import_react5.useState)(0);
1630
- const [models, setModels] = (0, import_react5.useState)([]);
1631
- const [modelsLoading, setModelsLoading] = (0, import_react5.useState)(false);
1632
- const [modelsFailed, setModelsFailed] = (0, import_react5.useState)(false);
1633
- const [modelsToken, setModelsToken] = (0, import_react5.useState)(0);
1634
- const [routeChecking, setRouteChecking] = (0, import_react5.useState)(false);
1635
- const [routeAvailable, setRouteAvailable] = (0, import_react5.useState)(void 0);
1636
- (0, import_react5.useEffect)(() => {
1839
+ const [providers, setProviders] = (0, import_react6.useState)([]);
1840
+ const [providersLoading, setProvidersLoading] = (0, import_react6.useState)(true);
1841
+ const [providersFailed, setProvidersFailed] = (0, import_react6.useState)(false);
1842
+ const [providersToken, setProvidersToken] = (0, import_react6.useState)(0);
1843
+ const [models, setModels] = (0, import_react6.useState)([]);
1844
+ const [modelsLoading, setModelsLoading] = (0, import_react6.useState)(false);
1845
+ const [modelsFailed, setModelsFailed] = (0, import_react6.useState)(false);
1846
+ const [modelsToken, setModelsToken] = (0, import_react6.useState)(0);
1847
+ const [routeChecking, setRouteChecking] = (0, import_react6.useState)(false);
1848
+ const [routeAvailable, setRouteAvailable] = (0, import_react6.useState)(void 0);
1849
+ (0, import_react6.useEffect)(() => {
1637
1850
  const controller = new AbortController();
1638
1851
  setProvidersLoading(true);
1639
1852
  setProvidersFailed(false);
@@ -1649,7 +1862,7 @@ function useLlmRouting(provider, model) {
1649
1862
  });
1650
1863
  return () => controller.abort();
1651
1864
  }, [providersToken]);
1652
- (0, import_react5.useEffect)(() => {
1865
+ (0, import_react6.useEffect)(() => {
1653
1866
  if (provider === "") {
1654
1867
  setModels([]);
1655
1868
  setModelsLoading(false);
@@ -1672,7 +1885,7 @@ function useLlmRouting(provider, model) {
1672
1885
  });
1673
1886
  return () => controller.abort();
1674
1887
  }, [provider, modelsToken]);
1675
- (0, import_react5.useEffect)(() => {
1888
+ (0, import_react6.useEffect)(() => {
1676
1889
  if (provider === "" || model === "") {
1677
1890
  setRouteChecking(false);
1678
1891
  setRouteAvailable(void 0);
@@ -1712,7 +1925,7 @@ function useLlmRouting(provider, model) {
1712
1925
 
1713
1926
  // src/client/settings-page.tsx
1714
1927
  var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
1715
- var import_jsx_runtime4 = require("react/jsx-runtime");
1928
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1716
1929
  var SETTINGS_SECTION_SLOT = "settings.section";
1717
1930
  var SETTINGS_SECTION_ID = "dsh-prompt-enhance";
1718
1931
  var SETTINGS_SECTION_ORDER = 70;
@@ -1920,7 +2133,7 @@ var REPOSITORY_URL = "https://github.com/surfishs/dsh-prompt-enhance";
1920
2133
  var NPM_URL = "https://www.npmjs.com/package/@surfishs/dsh-prompt-enhance";
1921
2134
  var GITHUB_MARK = "M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82a7.6 7.6 0 0 1 2-.27c.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z";
1922
2135
  var NPM_MARK = "M1.763 0C.786 0 0 .786 0 1.763v20.474C0 23.214.786 24 1.763 24h20.474c.977 0 1.763-.786 1.763-1.763V1.763C24 .786 23.214 0 22.237 0zM5.13 5.323l13.837.019-.009 13.836h-3.464l.01-10.382h-3.456L12.04 19.17H5.113z";
1923
- var PLUGIN_VERSION = true ? "0.0.2" : "0.0.0";
2136
+ var PLUGIN_VERSION = true ? "0.0.3" : "0.0.0";
1924
2137
  var HEADER_STYLE = { display: "flex", flexDirection: "column", gap: 12, padding: "2px 0" };
1925
2138
  var HEADER_ROW_STYLE = { display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" };
1926
2139
  var HEADER_TITLE_STYLE = {
@@ -1966,23 +2179,23 @@ var HEADER_DESCRIPTION_STYLE = {
1966
2179
  maxWidth: "72ch"
1967
2180
  };
1968
2181
  function PageHeader(props) {
1969
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: HEADER_STYLE, children: [
1970
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: HEADER_ROW_STYLE, children: [
1971
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: HEADER_TITLE_STYLE, children: props.title }),
1972
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("a", { href: REPOSITORY_URL, target: "_blank", rel: "noreferrer", style: HEADER_LINK_STYLE, children: [
1973
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: 11, height: 11, viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { fill: "currentColor", d: GITHUB_MARK }) }),
2182
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: HEADER_STYLE, children: [
2183
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: HEADER_ROW_STYLE, children: [
2184
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: HEADER_TITLE_STYLE, children: props.title }),
2185
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("a", { href: REPOSITORY_URL, target: "_blank", rel: "noreferrer", style: HEADER_LINK_STYLE, children: [
2186
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("svg", { width: 11, height: 11, viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { fill: "currentColor", d: GITHUB_MARK }) }),
1974
2187
  "GitHub"
1975
2188
  ] }),
1976
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("a", { href: NPM_URL, target: "_blank", rel: "noreferrer", style: HEADER_LINK_STYLE, children: [
1977
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { width: 11, height: 11, viewBox: "0 0 24 24", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { fill: "currentColor", d: NPM_MARK }) }),
2189
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("a", { href: NPM_URL, target: "_blank", rel: "noreferrer", style: HEADER_LINK_STYLE, children: [
2190
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("svg", { width: 11, height: 11, viewBox: "0 0 24 24", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { fill: "currentColor", d: NPM_MARK }) }),
1978
2191
  "npm"
1979
2192
  ] }),
1980
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { style: HEADER_VERSION_STYLE, children: [
2193
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { style: HEADER_VERSION_STYLE, children: [
1981
2194
  "v",
1982
2195
  props.version
1983
2196
  ] })
1984
2197
  ] }),
1985
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: HEADER_DESCRIPTION_STYLE, children: props.description })
2198
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: HEADER_DESCRIPTION_STYLE, children: props.description })
1986
2199
  ] });
1987
2200
  }
1988
2201
  function viewOf(snapshot, key) {
@@ -2006,7 +2219,7 @@ function atDefaultValue(key, text) {
2006
2219
  return text.trim() === String(fallback);
2007
2220
  }
2008
2221
  function OverrideActions(props) {
2009
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2222
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2010
2223
  "button",
2011
2224
  {
2012
2225
  type: "button",
@@ -2018,11 +2231,11 @@ function OverrideActions(props) {
2018
2231
  );
2019
2232
  }
2020
2233
  function BooleanRow(props) {
2021
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: ROW_STYLE, children: [
2022
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: HEAD_STYLE, children: [
2023
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: LABEL_STYLE, children: props.label }),
2024
- props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null,
2025
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2234
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: ROW_STYLE, children: [
2235
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: HEAD_STYLE, children: [
2236
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: LABEL_STYLE, children: props.label }),
2237
+ props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null,
2238
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2026
2239
  import_dsh_client_ui_primitives.Switch,
2027
2240
  {
2028
2241
  checked: props.view.text === "true",
@@ -2032,16 +2245,16 @@ function BooleanRow(props) {
2032
2245
  }
2033
2246
  )
2034
2247
  ] }),
2035
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: HINT_STYLE, children: props.hint })
2248
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: HINT_STYLE, children: props.hint })
2036
2249
  ] });
2037
2250
  }
2038
2251
  function ChoiceRow(props) {
2039
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: ROW_STYLE, children: [
2040
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: HEAD_STYLE, children: [
2041
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: LABEL_STYLE, children: props.label }),
2042
- props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null
2252
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: ROW_STYLE, children: [
2253
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: HEAD_STYLE, children: [
2254
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: LABEL_STYLE, children: props.label }),
2255
+ props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null
2043
2256
  ] }),
2044
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2257
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2045
2258
  import_dsh_client_ui_primitives.SegmentedControl,
2046
2259
  {
2047
2260
  id: props.id,
@@ -2052,18 +2265,18 @@ function ChoiceRow(props) {
2052
2265
  onChange: (next) => props.onEdit(next)
2053
2266
  }
2054
2267
  ),
2055
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: HINT_STYLE, children: props.hint })
2268
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: HINT_STYLE, children: props.hint })
2056
2269
  ] });
2057
2270
  }
2058
2271
  function ReasoningRow(props) {
2059
2272
  const pair = props.provider !== "" && props.model !== "" ? `${props.provider}/${props.model}` : "";
2060
- const [phase, setPhase] = (0, import_react6.useState)("loading");
2061
- const [capabilities, setCapabilities] = (0, import_react6.useState)(void 0);
2062
- const [refreshToken, setRefreshToken] = (0, import_react6.useState)(0);
2063
- const [feedback, setFeedback] = (0, import_react6.useState)("idle");
2064
- const forceRef = (0, import_react6.useRef)(false);
2065
- const feedbackTimer = (0, import_react6.useRef)(void 0);
2066
- (0, import_react6.useEffect)(() => {
2273
+ const [phase, setPhase] = (0, import_react7.useState)("loading");
2274
+ const [capabilities, setCapabilities] = (0, import_react7.useState)(void 0);
2275
+ const [refreshToken, setRefreshToken] = (0, import_react7.useState)(0);
2276
+ const [feedback, setFeedback] = (0, import_react7.useState)("idle");
2277
+ const forceRef = (0, import_react7.useRef)(false);
2278
+ const feedbackTimer = (0, import_react7.useRef)(void 0);
2279
+ (0, import_react7.useEffect)(() => {
2067
2280
  const controller = new AbortController();
2068
2281
  const force = forceRef.current;
2069
2282
  forceRef.current = false;
@@ -2132,10 +2345,10 @@ function ReasoningRow(props) {
2132
2345
  forceRef.current = true;
2133
2346
  setRefreshToken((token) => token + 1);
2134
2347
  };
2135
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: ROW_STYLE, children: [
2136
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: HEAD_STYLE, children: [
2137
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { style: LABEL_STYLE, children: props.label }),
2138
- phase === "ready" || refreshing ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2348
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: ROW_STYLE, children: [
2349
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: HEAD_STYLE, children: [
2350
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: LABEL_STYLE, children: props.label }),
2351
+ phase === "ready" || refreshing ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2139
2352
  "button",
2140
2353
  {
2141
2354
  type: "button",
@@ -2145,9 +2358,9 @@ function ReasoningRow(props) {
2145
2358
  children: props.copy.choice(refreshing ? "settings.reasoning.refreshing" : "settings.reasoning.refresh")
2146
2359
  }
2147
2360
  ) : null,
2148
- props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null
2361
+ props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null
2149
2362
  ] }),
2150
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2363
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2151
2364
  import_dsh_client_ui_primitives.SegmentedControl,
2152
2365
  {
2153
2366
  id: props.id,
@@ -2158,17 +2371,17 @@ function ReasoningRow(props) {
2158
2371
  onChange: (next) => props.onEdit(next)
2159
2372
  }
2160
2373
  ),
2161
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: HINT_STYLE, children: props.hint }),
2162
- phase === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: STATUS_STYLE, children: props.copy.choice("settings.reasoning.loading") }) : null,
2163
- phase === "ready" && capabilities?.source === "unavailable" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: STATUS_STYLE, children: props.copy.choice(noTiers ? "settings.reasoning.noTiers" : "settings.reasoning.unavailable") }) : null,
2164
- unsupported ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: STATUS_STYLE, children: props.copy.interpolate("settings.reasoning.unsupported", { effort: props.view.text }) }) : null,
2165
- feedback === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: STATUS_STYLE, "aria-live": "polite", children: props.copy.choice("settings.reasoning.refreshOk") }) : null,
2166
- feedback === "failed" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: STATUS_STYLE, "aria-live": "polite", children: props.copy.choice("settings.reasoning.refreshFailed") }) : null
2374
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: HINT_STYLE, children: props.hint }),
2375
+ phase === "loading" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: STATUS_STYLE, children: props.copy.choice("settings.reasoning.loading") }) : null,
2376
+ phase === "ready" && capabilities?.source === "unavailable" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: STATUS_STYLE, children: props.copy.choice(noTiers ? "settings.reasoning.noTiers" : "settings.reasoning.unavailable") }) : null,
2377
+ unsupported ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: STATUS_STYLE, children: props.copy.interpolate("settings.reasoning.unsupported", { effort: props.view.text }) }) : null,
2378
+ feedback === "ok" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: STATUS_STYLE, "aria-live": "polite", children: props.copy.choice("settings.reasoning.refreshOk") }) : null,
2379
+ feedback === "failed" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: STATUS_STYLE, "aria-live": "polite", children: props.copy.choice("settings.reasoning.refreshFailed") }) : null
2167
2380
  ] });
2168
2381
  }
2169
2382
  function SelectControl(props) {
2170
- const [focused, setFocused] = (0, import_react6.useState)(false);
2171
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2383
+ const [focused, setFocused] = (0, import_react7.useState)(false);
2384
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2172
2385
  "select",
2173
2386
  {
2174
2387
  id: props.id,
@@ -2187,42 +2400,42 @@ function ProviderRow(props) {
2187
2400
  const known = props.routing.providers.entries.find((entry) => entry.id === current2);
2188
2401
  const missing = current2 !== "" && known === void 0;
2189
2402
  const unconfigured = known !== void 0 && !known.registered;
2190
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: ROW_STYLE, children: [
2191
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: HEAD_STYLE, children: [
2192
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { htmlFor: props.id, style: LABEL_STYLE, children: props.label }),
2193
- props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null
2403
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: ROW_STYLE, children: [
2404
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: HEAD_STYLE, children: [
2405
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("label", { htmlFor: props.id, style: LABEL_STYLE, children: props.label }),
2406
+ props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null
2194
2407
  ] }),
2195
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(SelectControl, { id: props.id, value: current2, disabled: props.disabled, onChange: (value) => props.onEdit(value), children: [
2196
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: "", children: props.copy.choice("settings.routing.followSession") }),
2197
- missing ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: current2, title: current2, children: props.copy.interpolate("settings.routing.currentProvider", { value: current2 }) }) : null,
2198
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("optgroup", { label: props.copy.choice("settings.routing.groupRegistered"), children: props.routing.providers.entries.filter((entry) => entry.registered).map((entry) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: entry.id, title: entry.id, children: entry.name }, entry.id)) }),
2199
- props.routing.providers.entries.some((entry) => !entry.registered) ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("optgroup", { label: props.copy.choice("settings.routing.groupDormant"), children: props.routing.providers.entries.filter((entry) => !entry.registered).map((entry) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("option", { value: entry.id, disabled: true, title: props.copy.choice("settings.routing.unconfiguredTitle"), children: [
2408
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(SelectControl, { id: props.id, value: current2, disabled: props.disabled, onChange: (value) => props.onEdit(value), children: [
2409
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: "", children: props.copy.choice("settings.routing.followSession") }),
2410
+ missing ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: current2, title: current2, children: props.copy.interpolate("settings.routing.currentProvider", { value: current2 }) }) : null,
2411
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("optgroup", { label: props.copy.choice("settings.routing.groupRegistered"), children: props.routing.providers.entries.filter((entry) => entry.registered).map((entry) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: entry.id, title: entry.id, children: entry.name }, entry.id)) }),
2412
+ props.routing.providers.entries.some((entry) => !entry.registered) ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("optgroup", { label: props.copy.choice("settings.routing.groupDormant"), children: props.routing.providers.entries.filter((entry) => !entry.registered).map((entry) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("option", { value: entry.id, disabled: true, title: props.copy.choice("settings.routing.unconfiguredTitle"), children: [
2200
2413
  entry.name,
2201
2414
  props.copy.choice("settings.routing.unconfiguredSuffix")
2202
2415
  ] }, entry.id)) }) : null
2203
2416
  ] }),
2204
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: HINT_STYLE, children: props.hint }),
2205
- props.routing.providers.loading ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: STATUS_STYLE, children: props.copy.choice("settings.routing.providersLoading") }) : null,
2206
- props.routing.providers.failed ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: STATUS_STYLE, children: props.copy.choice("settings.routing.providersFailed") }) : null,
2207
- props.routing.providers.failed ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", style: REFRESH_STYLE, onClick: props.routing.providers.reload, children: props.copy.choice("settings.routing.retry") }) : null,
2208
- missing ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: WARN_STYLE, children: props.copy.interpolate("settings.routing.providerMissing", { value: current2 }) }) : null,
2209
- unconfigured ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: WARN_STYLE, children: props.copy.interpolate("settings.routing.providerUnconfigured", { name: known.name }) }) : null
2417
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: HINT_STYLE, children: props.hint }),
2418
+ props.routing.providers.loading ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: STATUS_STYLE, children: props.copy.choice("settings.routing.providersLoading") }) : null,
2419
+ props.routing.providers.failed ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: STATUS_STYLE, children: props.copy.choice("settings.routing.providersFailed") }) : null,
2420
+ props.routing.providers.failed ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", style: REFRESH_STYLE, onClick: props.routing.providers.reload, children: props.copy.choice("settings.routing.retry") }) : null,
2421
+ missing ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: WARN_STYLE, children: props.copy.interpolate("settings.routing.providerMissing", { value: current2 }) }) : null,
2422
+ unconfigured ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: WARN_STYLE, children: props.copy.interpolate("settings.routing.providerUnconfigured", { name: known.name }) }) : null
2210
2423
  ] });
2211
2424
  }
2212
2425
  function ModelRow(props) {
2213
2426
  const current2 = props.view.text;
2214
2427
  const provider = props.providerValue;
2215
- const [customMode, setCustomMode] = (0, import_react6.useState)(false);
2428
+ const [customMode, setCustomMode] = (0, import_react7.useState)(false);
2216
2429
  const known = props.routing.models.entries.some((entry) => entry.id === current2);
2217
2430
  const showCustom = provider !== "" && (customMode || current2 !== "" && !known);
2218
2431
  const pairIncomplete = provider !== "" && current2 === "";
2219
2432
  const routeUnavailable = provider !== "" && current2 !== "" && props.routing.route.available === false;
2220
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: ROW_STYLE, children: [
2221
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: HEAD_STYLE, children: [
2222
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { htmlFor: props.id, style: LABEL_STYLE, children: props.label }),
2223
- props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null
2433
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: ROW_STYLE, children: [
2434
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: HEAD_STYLE, children: [
2435
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("label", { htmlFor: props.id, style: LABEL_STYLE, children: props.label }),
2436
+ props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null
2224
2437
  ] }),
2225
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
2438
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
2226
2439
  SelectControl,
2227
2440
  {
2228
2441
  id: props.id,
@@ -2237,14 +2450,14 @@ function ModelRow(props) {
2237
2450
  props.onEdit(value);
2238
2451
  },
2239
2452
  children: [
2240
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: "", children: provider === "" ? props.copy.choice("settings.routing.followSession") : props.copy.choice("settings.routing.selectModel") }),
2241
- props.routing.models.entries.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: entry.id, title: entry.id, children: entry.name }, entry.id)),
2242
- provider !== "" && current2 !== "" && !known ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: current2, title: current2, children: props.copy.interpolate("settings.routing.currentModel", { value: current2 }) }) : null,
2243
- provider !== "" ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("option", { value: "__custom__", children: props.copy.choice("settings.routing.custom") }) : null
2453
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: "", children: provider === "" ? props.copy.choice("settings.routing.followSession") : props.copy.choice("settings.routing.selectModel") }),
2454
+ props.routing.models.entries.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: entry.id, title: entry.id, children: entry.name }, entry.id)),
2455
+ provider !== "" && current2 !== "" && !known ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: current2, title: current2, children: props.copy.interpolate("settings.routing.currentModel", { value: current2 }) }) : null,
2456
+ provider !== "" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("option", { value: "__custom__", children: props.copy.choice("settings.routing.custom") }) : null
2244
2457
  ]
2245
2458
  }
2246
2459
  ),
2247
- showCustom ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2460
+ showCustom ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2248
2461
  TextControl,
2249
2462
  {
2250
2463
  value: current2,
@@ -2253,17 +2466,17 @@ function ModelRow(props) {
2253
2466
  onChange: props.onEdit
2254
2467
  }
2255
2468
  ) : null,
2256
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: HINT_STYLE, children: props.hint }),
2257
- props.routing.models.loading ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: STATUS_STYLE, children: props.copy.choice("settings.routing.modelsLoading") }) : null,
2258
- props.routing.models.failed && !showCustom ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: STATUS_STYLE, children: props.copy.choice("settings.routing.modelsFailed") }) : null,
2259
- pairIncomplete ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: WARN_STYLE, children: props.copy.choice("settings.routing.pairIncomplete") }) : null,
2260
- routeUnavailable ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: WARN_STYLE, children: props.copy.choice("settings.routing.routeUnavailable") }) : null
2469
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: HINT_STYLE, children: props.hint }),
2470
+ props.routing.models.loading ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: STATUS_STYLE, children: props.copy.choice("settings.routing.modelsLoading") }) : null,
2471
+ props.routing.models.failed && !showCustom ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: STATUS_STYLE, children: props.copy.choice("settings.routing.modelsFailed") }) : null,
2472
+ pairIncomplete ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: WARN_STYLE, children: props.copy.choice("settings.routing.pairIncomplete") }) : null,
2473
+ routeUnavailable ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: WARN_STYLE, children: props.copy.choice("settings.routing.routeUnavailable") }) : null
2261
2474
  ] });
2262
2475
  }
2263
2476
  function TextControl(props) {
2264
- const [focused, setFocused] = (0, import_react6.useState)(false);
2477
+ const [focused, setFocused] = (0, import_react7.useState)(false);
2265
2478
  const borderColor = props.invalid === true ? "var(--dsw-alias-state-error-primary, #f85149)" : focused ? "var(--dsw-alias-state-business-primary, #4f8cff)" : void 0;
2266
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2479
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2267
2480
  "input",
2268
2481
  {
2269
2482
  id: props.id,
@@ -2286,12 +2499,12 @@ function TextControl(props) {
2286
2499
  }
2287
2500
  function ValueRow(props) {
2288
2501
  const invalid = props.view.invalid;
2289
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: ROW_STYLE, children: [
2290
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: HEAD_STYLE, children: [
2291
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { htmlFor: props.id, style: LABEL_STYLE, children: props.label }),
2292
- props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null
2502
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: ROW_STYLE, children: [
2503
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: HEAD_STYLE, children: [
2504
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("label", { htmlFor: props.id, style: LABEL_STYLE, children: props.label }),
2505
+ props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null
2293
2506
  ] }),
2294
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2507
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2295
2508
  TextControl,
2296
2509
  {
2297
2510
  id: props.id,
@@ -2303,8 +2516,8 @@ function ValueRow(props) {
2303
2516
  onChange: props.onEdit
2304
2517
  }
2305
2518
  ),
2306
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: HINT_STYLE, children: props.hint }),
2307
- invalid ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: INVALID_STYLE, children: props.copy.labels.invalidNumber }) : null
2519
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: HINT_STYLE, children: props.hint }),
2520
+ invalid ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: INVALID_STYLE, children: props.copy.labels.invalidNumber }) : null
2308
2521
  ] });
2309
2522
  }
2310
2523
  function SettingsRow(props) {
@@ -2320,27 +2533,27 @@ function SettingsRow(props) {
2320
2533
  };
2321
2534
  switch (props.row.kind) {
2322
2535
  case "boolean":
2323
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(BooleanRow, { ...shared });
2536
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(BooleanRow, { ...shared });
2324
2537
  case "strategy":
2325
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ChoiceRow, { ...shared, options: STRATEGY_OPTIONS.map((option) => ({ value: option.value, label: props.copy.choice(option.label) })) });
2538
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ChoiceRow, { ...shared, options: STRATEGY_OPTIONS.map((option) => ({ value: option.value, label: props.copy.choice(option.label) })) });
2326
2539
  case "reasoning":
2327
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ReasoningRow, { ...shared, provider: props.reasoningPair.provider, model: props.reasoningPair.model });
2540
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ReasoningRow, { ...shared, provider: props.reasoningPair.provider, model: props.reasoningPair.model });
2328
2541
  case "provider":
2329
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ProviderRow, { ...shared, routing: props.routing });
2542
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ProviderRow, { ...shared, routing: props.routing });
2330
2543
  case "model":
2331
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ModelRow, { ...shared, routing: props.routing, providerValue: props.providerValue });
2544
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ModelRow, { ...shared, routing: props.routing, providerValue: props.providerValue });
2332
2545
  default:
2333
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ValueRow, { ...shared, numeric: props.row.kind === "number", placeholder: props.copy.placeholder(props.row) });
2546
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ValueRow, { ...shared, numeric: props.row.kind === "number", placeholder: props.copy.placeholder(props.row) });
2334
2547
  }
2335
2548
  }
2336
2549
  function SettingsRows(props) {
2337
2550
  const provider = viewOf(props.state, "provider").text.trim();
2338
2551
  const model = viewOf(props.state, "model").text.trim();
2339
2552
  const routing = useLlmRouting(provider, model);
2340
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_dsh_client_ui_primitives.SettingsForm, { labels: props.copy.labels, state: props.state, onSave: props.save, onDiscard: props.discard, children: ROWS.map((row, index) => {
2553
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_dsh_client_ui_primitives.SettingsForm, { labels: props.copy.labels, state: props.state, onSave: props.save, onDiscard: props.discard, children: ROWS.map((row, index) => {
2341
2554
  const raw = viewOf(props.state, row.key);
2342
2555
  const view = raw.overridden && atDefaultValue(row.key, raw.text) ? { ...raw, overridden: false } : raw;
2343
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: index === 0 ? void 0 : SEPARATOR_STYLE, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2556
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { style: index === 0 ? void 0 : SEPARATOR_STYLE, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2344
2557
  SettingsRow,
2345
2558
  {
2346
2559
  row,
@@ -2364,15 +2577,15 @@ function SettingsSection(props) {
2364
2577
  const t = translator(props.translate);
2365
2578
  const chinese = (locale?.active ?? "zh").toLowerCase().startsWith("zh");
2366
2579
  if (state === void 0) {
2367
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: { margin: 0, fontSize: 12, lineHeight: 1.6 }, children: t("settings.disconnected") });
2580
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: { margin: 0, fontSize: 12, lineHeight: 1.6 }, children: t("settings.disconnected") });
2368
2581
  }
2369
2582
  const edit = props.edit ?? (() => {
2370
2583
  });
2371
2584
  const resetField = props.resetField ?? (() => {
2372
2585
  });
2373
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 12 }, children: [
2374
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(PageHeader, { title: t("settings.title"), description: t("settings.description"), version: PLUGIN_VERSION }),
2375
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2586
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 12 }, children: [
2587
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PageHeader, { title: t("settings.title"), description: t("settings.description"), version: PLUGIN_VERSION }),
2588
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2376
2589
  SettingsRows,
2377
2590
  {
2378
2591
  copy: sectionCopy(t, chinese),
@@ -2391,13 +2604,13 @@ function SettingsPage(props) {
2391
2604
  const state = read === void 0 ? void 0 : read((snapshot) => snapshot);
2392
2605
  if (props.view === "summary") return t("settings.summary");
2393
2606
  if (state === void 0) {
2394
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("p", { style: { margin: 0, fontSize: 12, lineHeight: 1.6 }, children: t("settings.disconnected") });
2607
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: { margin: 0, fontSize: 12, lineHeight: 1.6 }, children: t("settings.disconnected") });
2395
2608
  }
2396
2609
  const edit = props.edit ?? (() => {
2397
2610
  });
2398
2611
  const resetField = props.resetField ?? (() => {
2399
2612
  });
2400
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2613
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2401
2614
  SettingsRows,
2402
2615
  {
2403
2616
  copy: pageCopy(t),
@@ -2553,6 +2766,20 @@ function apply(ctx) {
2553
2766
  }
2554
2767
  });
2555
2768
  });
2769
+ ctx.inject(["slots"], (slotsCtx) => {
2770
+ const slots = slotsCtx.slots;
2771
+ if (slots === void 0) return;
2772
+ return slots.inject("conversation.input.dock", () => {
2773
+ try {
2774
+ return slots.register(
2775
+ { name: "conversation.input.dock", id: "dsh-prompt-enhance-result", order: 30, locale: NS },
2776
+ ResultDock
2777
+ );
2778
+ } catch (error) {
2779
+ return report("result dock slot", error);
2780
+ }
2781
+ });
2782
+ });
2556
2783
  ctx.inject(["slots"], (slotsCtx) => {
2557
2784
  const slots = slotsCtx.slots;
2558
2785
  if (slots === void 0) return;