@surfishs/dsh-prompt-enhance 0.0.6 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. package/README.en.md +3 -0
  2. package/README.md +3 -0
  3. package/cordis.patch.yml +1 -1
  4. package/lib/client.js +454 -397
  5. package/lib/index.js +67 -56
  6. package/lib/index.js.map +3 -3
  7. package/package.json +23 -15
  8. package/src/client/ActionIcons.tsx +4 -17
  9. package/src/client/EnhanceButton.tsx +52 -48
  10. package/src/client/ResultDock.tsx +22 -9
  11. package/src/client/ResultPanel.tsx +83 -52
  12. package/src/client/SparkleFishIcon.tsx +3 -13
  13. package/src/client/SparkleIcon.tsx +2 -12
  14. package/src/client/UndoBar.tsx +11 -6
  15. package/src/client/enhance-client.ts +44 -40
  16. package/src/client/index.tsx +3 -12
  17. package/src/client/llm-catalog.ts +14 -16
  18. package/src/client/locales.ts +20 -4
  19. package/src/client/reasoning-options.ts +7 -15
  20. package/src/client/settings-page-controls.tsx +449 -0
  21. package/src/client/settings-page-copy.ts +112 -0
  22. package/src/client/settings-page-spec.ts +330 -0
  23. package/src/client/settings-page-styles.ts +161 -0
  24. package/src/client/settings-page.tsx +166 -1109
  25. package/src/client/settings-source.ts +41 -31
  26. package/src/client/settings.ts +17 -12
  27. package/src/client/shortcut.ts +7 -6
  28. package/src/client/styles.ts +52 -0
  29. package/src/client/useDockAlignment.ts +5 -15
  30. package/src/config.ts +84 -27
  31. package/src/context.ts +1 -5
  32. package/src/enhance-routes.ts +8 -8
  33. package/src/enhancer.ts +43 -34
  34. package/src/orchestrate.ts +19 -23
  35. package/src/prompts.ts +4 -4
  36. package/src/provider-catalog.ts +1 -1
  37. package/src/reasoning-cache.ts +4 -4
  38. package/src/reasoning-efforts.ts +4 -9
  39. package/src/settings-source.ts +37 -23
  40. package/src/shared/limits.ts +38 -0
  41. package/src/shared/normalize.ts +4 -1
  42. package/src/shared/protocol.ts +27 -23
  43. package/src/shared/reasoning.ts +1 -7
  44. package/src/shared/stream-text.ts +0 -6
  45. package/src/shared/validate.ts +3 -9
  46. package/docs/code-review-2026-09.md +0 -211
  47. package/docs/handoff-settings-page.md +0 -195
  48. package/docs/release-0.2.3.md +0 -47
  49. package/docs/release-0.2.4.md +0 -20
  50. package/docs/release-0.2.5.md +0 -28
  51. package/docs/release-0.2.6.md +0 -33
  52. package/docs/release-0.2.7.md +0 -22
  53. package/docs/release-0.3.0.md +0 -36
  54. package/docs/release-0.3.1.md +0 -50
  55. package/docs/release-0.3.2.md +0 -41
  56. package/docs/release-0.3.3.md +0 -53
  57. package/docs/release-0.3.4.md +0 -43
package/lib/client.js CHANGED
@@ -66,12 +66,7 @@ function checkInputText(text, maxChars) {
66
66
  // src/shared/protocol.ts
67
67
  var ENHANCE_ENDPOINT = "/dsh-prompt-enhance/enhance";
68
68
  var ENHANCE_STREAM_ENDPOINT = "/dsh-prompt-enhance/enhance-stream";
69
- var PROMPT_ENHANCE_ROW_IDS = [
70
- "dsh-prompt-enhance",
71
- "prompt-enhance",
72
- "web-ui-dsh-prompt-enhance",
73
- "web-ui-prompt-enhance"
74
- ];
69
+ var PROMPT_ENHANCE_ROW_IDS = ["dsh-prompt-enhance", "prompt-enhance", "web-ui-dsh-prompt-enhance", "web-ui-prompt-enhance"];
75
70
 
76
71
  // src/client/enhance-client.ts
77
72
  var EnhanceClientError = class extends Error {
@@ -83,17 +78,7 @@ var EnhanceClientError = class extends Error {
83
78
  function jsonBody(body) {
84
79
  return new TextEncoder().encode(JSON.stringify(body));
85
80
  }
86
- var KNOWN_ERROR_CODES = /* @__PURE__ */ new Set([
87
- "rejected",
88
- "rate-limit",
89
- "concurrency-limit",
90
- "cooldown",
91
- "timeout",
92
- "upstream",
93
- "unconfigured",
94
- "internal",
95
- "effort-unsupported"
96
- ]);
81
+ var KNOWN_ERROR_CODES = /* @__PURE__ */ new Set(["rejected", "rate-limit", "concurrency-limit", "cooldown", "timeout", "upstream", "unconfigured", "internal", "effort-unsupported"]);
97
82
  function parseError(value) {
98
83
  const record = value;
99
84
  if (record !== null && typeof record === "object") {
@@ -102,7 +87,7 @@ function parseError(value) {
102
87
  const params = record.params !== null && typeof record.params === "object" ? record.params : void 0;
103
88
  return { code, ...message !== void 0 ? { message } : {}, ...params !== void 0 ? { params } : {} };
104
89
  }
105
- return { code: "internal", message: "\u5BBF\u4E3B\u670D\u52A1\u8FD4\u56DE\u5F02\u5E38\u3002" };
90
+ return { code: "internal", params: { reason: "malformed" } };
106
91
  }
107
92
  function tokenCount(value) {
108
93
  return typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : void 0;
@@ -136,14 +121,14 @@ function parseResult(value) {
136
121
  ...usage === void 0 ? {} : { usage }
137
122
  };
138
123
  }
139
- throw new EnhanceClientError({ code: "internal", message: "\u5BBF\u4E3B\u670D\u52A1\u8FD4\u56DE\u4E86\u65E0\u6CD5\u89E3\u6790\u7684\u7ED3\u679C\u3002" });
124
+ throw new EnhanceClientError({ code: "internal", params: { reason: "malformed" } });
140
125
  }
141
126
  async function readEnvelope(response) {
142
127
  let parsed;
143
128
  try {
144
129
  parsed = await response.json();
145
130
  } catch {
146
- throw new EnhanceClientError({ code: "internal", message: "\u5BBF\u4E3B\u670D\u52A1\u8FD4\u56DE\u4E86\u65E0\u6CD5\u89E3\u6790\u7684\u54CD\u5E94\u3002" });
131
+ throw new EnhanceClientError({ code: "internal", params: { reason: "malformed" } });
147
132
  }
148
133
  const envelope = parsed;
149
134
  if (envelope !== null && typeof envelope === "object" && envelope.ok === true) {
@@ -152,7 +137,7 @@ async function readEnvelope(response) {
152
137
  if (envelope !== null && typeof envelope === "object" && envelope.error !== void 0) {
153
138
  throw new EnhanceClientError(parseError(envelope.error));
154
139
  }
155
- throw new EnhanceClientError({ code: "internal", message: `\u5BBF\u4E3B\u670D\u52A1\u8FD4\u56DE\u5F02\u5E38\uFF08HTTP ${response.status}\uFF09\u3002` });
140
+ throw new EnhanceClientError({ code: "internal", params: { reason: "malformed", status: response.status } });
156
141
  }
157
142
  async function rejectionOf(response) {
158
143
  try {
@@ -162,7 +147,7 @@ async function rejectionOf(response) {
162
147
  }
163
148
  } catch {
164
149
  }
165
- return new EnhanceClientError({ code: "internal", message: `\u5BBF\u4E3B\u670D\u52A1\u62D2\u7EDD\u4E86\u8BF7\u6C42\uFF08HTTP ${response.status}\uFF09\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002` });
150
+ return new EnhanceClientError({ code: "internal", params: { reason: "refused", status: response.status } });
166
151
  }
167
152
  function takeFrames(buffer) {
168
153
  const frames = [];
@@ -204,10 +189,10 @@ async function requestEnhanceStream(body, options) {
204
189
  });
205
190
  } catch (error) {
206
191
  if (options.signal?.aborted) {
207
- throw new EnhanceClientError({ code: "internal", message: "\u5DF2\u53D6\u6D88\u589E\u5F3A\uFF1B\u539F\u8F93\u5165\u672A\u6539\u52A8\u3002" });
192
+ throw new EnhanceClientError({ code: "internal", params: { reason: "cancelled" } });
208
193
  }
209
194
  void error;
210
- throw new EnhanceClientError({ code: "internal", message: "\u65E0\u6CD5\u8FDE\u63A5\u5BBF\u4E3B\u670D\u52A1\uFF0C\u8BF7\u786E\u8BA4 dsh web \u6B63\u5728\u8FD0\u884C\u540E\u91CD\u8BD5\u3002" });
195
+ throw new EnhanceClientError({ code: "internal", params: { reason: "unreachable" } });
211
196
  }
212
197
  const contentType = String(response.headers.get("content-type") ?? "").toLowerCase();
213
198
  if (!response.ok) throw await rejectionOf(response);
@@ -239,7 +224,7 @@ async function requestEnhanceStream(body, options) {
239
224
  void Promise.resolve().then(() => reader.cancel()).catch(() => {
240
225
  });
241
226
  }
242
- throw new EnhanceClientError({ code: "internal", message: "\u5BBF\u4E3B\u670D\u52A1\u63D0\u524D\u5173\u95ED\u4E86\u589E\u5F3A\u6D41\uFF0C\u8BF7\u91CD\u8BD5\uFF1B\u539F\u8F93\u5165\u672A\u6539\u52A8\u3002" });
227
+ throw new EnhanceClientError({ code: "internal", params: { reason: "stream-closed" } });
243
228
  }
244
229
  async function requestEnhance(body, signal) {
245
230
  let response;
@@ -252,10 +237,10 @@ async function requestEnhance(body, signal) {
252
237
  });
253
238
  } catch (error) {
254
239
  if (signal?.aborted) {
255
- throw new EnhanceClientError({ code: "internal", message: "\u5DF2\u53D6\u6D88\u589E\u5F3A\uFF1B\u539F\u8F93\u5165\u672A\u6539\u52A8\u3002" });
240
+ throw new EnhanceClientError({ code: "internal", params: { reason: "cancelled" } });
256
241
  }
257
242
  void error;
258
- throw new EnhanceClientError({ code: "internal", message: "\u65E0\u6CD5\u8FDE\u63A5\u5BBF\u4E3B\u670D\u52A1\uFF0C\u8BF7\u786E\u8BA4 dsh web \u6B63\u5728\u8FD0\u884C\u540E\u91CD\u8BD5\u3002" });
243
+ throw new EnhanceClientError({ code: "internal", params: { reason: "unreachable" } });
259
244
  }
260
245
  return readEnvelope(response);
261
246
  }
@@ -266,23 +251,11 @@ var FISH_PATH = "M22.9168 1.43018C22.6713 1.31018 22.5658 1.53918 22.4223 1.6551
266
251
  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
252
  function SparkleFishIcon(props) {
268
253
  const size = props.size ?? 15;
269
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
270
- "svg",
271
- {
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 },
279
- children: [
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
283
- ]
284
- }
285
- );
254
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("svg", { width: size * 1.3, height: size, viewBox: "0 0 26 20", fill: "none", "aria-hidden": "true", focusable: "false", style: { display: "block", flexShrink: 0 }, children: [
255
+ /* @__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" }) }),
256
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: STAR_PATH, transform: "translate(1.2,0.8) scale(0.55)", fill: "currentColor" }),
257
+ props.spinning === true ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("animate", { attributeName: "opacity", values: "1;0.35;1", dur: "1.1s", repeatCount: "indefinite" }) : null
258
+ ] });
286
259
  }
287
260
 
288
261
  // src/client/undo-stack.ts
@@ -460,12 +433,34 @@ function shortcutTarget() {
460
433
  return fallback === void 0 ? void 0 : () => fallback.run();
461
434
  }
462
435
 
463
- // src/client/settings.ts
464
- var DEFAULT_CLIENT_SETTINGS = {
436
+ // src/shared/defaults.ts
437
+ var DEFAULT_VALUES = {
465
438
  enabled: true,
439
+ temperature: 0.3,
440
+ // A rewrite does not need deep reasoning, and the route default is expensive
441
+ // (measured: 2897 output tokens at `high` vs 252 at `off` for the same draft).
442
+ // Sent explicitly, because omitting the field inherits that route default.
443
+ reasoningEffort: "off",
444
+ maxOutputTokens: 8192,
466
445
  maxInputChars: 12e3,
446
+ timeoutMs: 6e4,
447
+ systemPrompt: "",
448
+ strategyMode: "replace-default",
467
449
  shortcut: "",
468
- streaming: true
450
+ maxConcurrent: 2,
451
+ rateLimitPerMinute: 10,
452
+ streaming: true,
453
+ contextAware: true,
454
+ contextMaxMessages: 8,
455
+ contextMaxChars: 4e3
456
+ };
457
+
458
+ // src/client/settings.ts
459
+ var DEFAULT_CLIENT_SETTINGS = {
460
+ enabled: DEFAULT_VALUES.enabled,
461
+ maxInputChars: DEFAULT_VALUES.maxInputChars,
462
+ shortcut: DEFAULT_VALUES.shortcut,
463
+ streaming: DEFAULT_VALUES.streaming
469
464
  };
470
465
  var listeners2 = /* @__PURE__ */ new Set();
471
466
  var current = DEFAULT_CLIENT_SETTINGS;
@@ -537,46 +532,52 @@ function EnhanceButton(props) {
537
532
  const anyBusy = panel !== void 0 && panel.phase === "loading";
538
533
  const otherBusy = anyBusy && !busy;
539
534
  const empty = draft.trim() === "";
540
- const start = (0, import_react2.useCallback)((overrideText) => {
541
- const source = overrideText ?? draft;
542
- if (anyBusy || source.trim() === "") return;
543
- if (!settings.enabled) {
544
- const disabled = t("error.disabled");
545
- openError(uiKey, draft, { code: "rejected", localized: disabled });
546
- return;
547
- }
548
- const check = checkInputText(source, settings.maxInputChars);
549
- if (!check.ok) {
550
- const message = check.code === "empty" ? t("error.empty") : t("error.tooLong", { count: check.count, max: check.max });
551
- openError(uiKey, source, { code: "rejected", localized: message });
552
- return;
553
- }
554
- if (occurrenceCount > 0) {
555
- const occurrences = t("error.occurrences");
556
- openError(uiKey, source, { code: "rejected", localized: occurrences });
557
- return;
558
- }
559
- if (phase !== "plain") {
560
- const busyPhase = t("error.phase");
561
- openError(uiKey, source, { code: "rejected", localized: busyPhase });
562
- return;
563
- }
564
- const controller = new AbortController();
565
- openLoading({ sessionId: uiKey, original: source, abort: () => controller.abort() });
566
- const settle = (result) => settleResult(uiKey, result);
567
- const fail = (error) => {
568
- const detail = error instanceof EnhanceClientError ? error.detail : { code: "internal", message: error instanceof Error ? error.message : String(error) };
569
- settleError(uiKey, detail);
570
- };
571
- if (settings.streaming) {
572
- requestEnhanceStream({ sessionId: wireId, text: source }, {
573
- signal: controller.signal,
574
- onDelta: (delta) => appendDelta(uiKey, delta)
575
- }).then(settle, fail);
576
- return;
577
- }
578
- requestEnhance({ sessionId: wireId, text: source }, controller.signal).then(settle, fail);
579
- }, [anyBusy, draft, occurrenceCount, phase, settings, uiKey, wireId, t]);
535
+ const start = (0, import_react2.useCallback)(
536
+ (overrideText) => {
537
+ const source = overrideText ?? draft;
538
+ if (anyBusy || source.trim() === "") return;
539
+ if (!settings.enabled) {
540
+ const disabled = t("error.disabled");
541
+ openError(uiKey, draft, { code: "rejected", localized: disabled });
542
+ return;
543
+ }
544
+ const check = checkInputText(source, settings.maxInputChars);
545
+ if (!check.ok) {
546
+ const message = check.code === "empty" ? t("error.empty") : t("error.tooLong", { count: check.count, max: check.max });
547
+ openError(uiKey, source, { code: "rejected", localized: message });
548
+ return;
549
+ }
550
+ if (occurrenceCount > 0) {
551
+ const occurrences = t("error.occurrences");
552
+ openError(uiKey, source, { code: "rejected", localized: occurrences });
553
+ return;
554
+ }
555
+ if (phase !== "plain") {
556
+ const busyPhase = t("error.phase");
557
+ openError(uiKey, source, { code: "rejected", localized: busyPhase });
558
+ return;
559
+ }
560
+ const controller = new AbortController();
561
+ openLoading({ sessionId: uiKey, original: source, abort: () => controller.abort() });
562
+ const settle = (result) => settleResult(uiKey, result);
563
+ const fail = (error) => {
564
+ const detail = error instanceof EnhanceClientError ? error.detail : { code: "internal", message: error instanceof Error ? error.message : String(error) };
565
+ settleError(uiKey, detail);
566
+ };
567
+ if (settings.streaming) {
568
+ requestEnhanceStream(
569
+ { sessionId: wireId, text: source },
570
+ {
571
+ signal: controller.signal,
572
+ onDelta: (delta) => appendDelta(uiKey, delta)
573
+ }
574
+ ).then(settle, fail);
575
+ return;
576
+ }
577
+ requestEnhance({ sessionId: wireId, text: source }, controller.signal).then(settle, fail);
578
+ },
579
+ [anyBusy, draft, occurrenceCount, phase, settings, uiKey, wireId, t]
580
+ );
580
581
  const runRef = (0, import_react2.useRef)(start);
581
582
  (0, import_react2.useEffect)(() => {
582
583
  runRef.current = start;
@@ -637,29 +638,16 @@ function icon(paths) {
637
638
  );
638
639
  }
639
640
  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
- ]);
641
+ return icon([/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M21 12a9 9 0 1 1-3-6.7L21 8" }, "arc"), /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M21 3v5h-5" }, "head")]);
644
642
  }
645
643
  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
- ]);
644
+ return icon([/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2" }, "front"), /* @__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")]);
650
645
  }
651
646
  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
- ]);
647
+ return icon([/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M12 3v12" }, "stem"), /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "m7 10 5 5 5-5" }, "head"), /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M5 21h14" }, "tray")]);
657
648
  }
658
649
  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
- ]);
650
+ return icon([/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M9 14 4 9l5-5" }, "head"), /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: "M4 9h10.5a5.5 5.5 0 0 1 0 11H8" }, "curve")]);
663
651
  }
664
652
 
665
653
  // src/client/ResultPanel.tsx
@@ -675,6 +663,16 @@ var UPSTREAM_ERROR_KEYS = {
675
663
  "tool-call": "error.upstream.toolCall",
676
664
  "max-tokens": "error.upstream.maxTokens"
677
665
  };
666
+ var CLIENT_ERROR_KEYS = {
667
+ unreachable: "error.client.unreachable",
668
+ malformed: "error.client.malformed",
669
+ refused: "error.client.refused",
670
+ "stream-closed": "error.client.streamClosed",
671
+ cancelled: "error.client.cancelled"
672
+ };
673
+ function isClientFailureReason(value) {
674
+ return typeof value === "string" && Object.hasOwn(CLIENT_ERROR_KEYS, value);
675
+ }
678
676
  function localizedErrorMessage(t, code, params) {
679
677
  if (code === "rejected" && typeof params?.count === "number" && typeof params?.max === "number") {
680
678
  return t("error.tooLong", { count: params.count, max: params.max });
@@ -683,6 +681,9 @@ function localizedErrorMessage(t, code, params) {
683
681
  const specific = UPSTREAM_ERROR_KEYS[params.reason];
684
682
  if (specific !== void 0) return t(specific);
685
683
  }
684
+ if (code === "internal" && isClientFailureReason(params?.reason)) {
685
+ return t(CLIENT_ERROR_KEYS[params.reason], params);
686
+ }
686
687
  switch (code) {
687
688
  case "rejected":
688
689
  return t("error.rejected");
@@ -736,17 +737,17 @@ function ResultPanel(props) {
736
737
  if (ok) setTimeout(() => setCopied("idle"), 2500);
737
738
  };
738
739
  if (navigator.clipboard !== void 0) {
739
- navigator.clipboard.writeText(text).then(() => done(true), () => done(fallbackCopy(text)));
740
+ navigator.clipboard.writeText(text).then(
741
+ () => done(true),
742
+ () => done(fallbackCopy(text))
743
+ );
740
744
  return;
741
745
  }
742
746
  done(fallbackCopy(text));
743
747
  }, [state.result]);
744
748
  const formatMs = (ms) => ms < 1e3 ? `${ms}ms` : `${(ms / 1e3).toFixed(1)}s`;
745
749
  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
+ const parts = [t("panel.tokens.input", { count: formatTokens(usage.inputTokens) }), t("panel.tokens.output", { count: formatTokens(usage.outputTokens) })];
750
751
  if ((usage.cacheReadTokens ?? 0) > 0) {
751
752
  parts.push(t("panel.tokens.cacheRead", { count: formatTokens(usage.cacheReadTokens ?? 0) }));
752
753
  }
@@ -837,7 +838,6 @@ function useDockAlignment(active) {
837
838
  const parent = root.parentElement;
838
839
  if (parent === null) return;
839
840
  root.style.transform = "";
840
- const previousMargin = parseFloat(root.style.marginLeft) || 0;
841
841
  const rootRect = root.getBoundingClientRect();
842
842
  const editors = Array.from(document.querySelectorAll('textarea, [contenteditable="true"], [role="textbox"]'));
843
843
  const editor = editors.find((node2) => {
@@ -910,8 +910,14 @@ function ResultDock(props) {
910
910
  return typeof value === "string" ? value : "";
911
911
  });
912
912
  const useSession = props.useSession;
913
- const sessionRunning = useSession === void 0 ? false : Boolean(useSession((state) => state.running));
914
- const sessionQueued = useSession === void 0 ? 0 : Number(useSession((state) => state.queue?.length ?? 0));
913
+ const sessionRunning = useSession === void 0 ? false : (
914
+ // eslint-disable-next-line react-hooks/rules-of-hooks
915
+ Boolean(useSession((state) => state.running))
916
+ );
917
+ const sessionQueued = useSession === void 0 ? 0 : (
918
+ // eslint-disable-next-line react-hooks/rules-of-hooks
919
+ Number(useSession((state) => state.queue?.length ?? 0))
920
+ );
915
921
  const entry = peekUndo(uiKey);
916
922
  const applied = entry !== void 0 && entry.applied === draft;
917
923
  const prevSession = (0, import_react5.useRef)({ running: sessionRunning, queued: sessionQueued });
@@ -1087,6 +1093,11 @@ var zh = {
1087
1093
  "error.effortUnsupported": "\u8BE5\u6A21\u578B\u4E0D\u652F\u6301\u6240\u9009\u63A8\u7406\u6863\u4F4D\u300C{effort}\u300D\uFF0C\u8BF7\u6539\u9009\u5176\u5B83\u6863\u4F4D\uFF0C\u6216\u6539\u7528\u300C\u8DDF\u968F\u63D0\u4F9B\u65B9\u9ED8\u8BA4\u300D\u3002",
1088
1094
  "error.upstream": "\u6A21\u578B\u670D\u52A1\u8FD4\u56DE\u9519\u8BEF\uFF0C\u8BF7\u91CD\u8BD5\uFF1B\u539F\u8F93\u5165\u672A\u6539\u52A8\u3002",
1089
1095
  "error.internal": "\u589E\u5F3A\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\uFF1B\u539F\u8F93\u5165\u672A\u6539\u52A8\u3002",
1096
+ "error.client.unreachable": "\u65E0\u6CD5\u8FDE\u63A5\u5BBF\u4E3B\u670D\u52A1\uFF0C\u8BF7\u786E\u8BA4 dsh web \u6B63\u5728\u8FD0\u884C\u540E\u91CD\u8BD5\u3002",
1097
+ "error.client.malformed": "\u5BBF\u4E3B\u670D\u52A1\u8FD4\u56DE\u4E86\u65E0\u6CD5\u89E3\u6790\u7684\u6570\u636E\uFF0C\u8BF7\u91CD\u8BD5\uFF1B\u539F\u8F93\u5165\u672A\u6539\u52A8\u3002",
1098
+ "error.client.refused": "\u5BBF\u4E3B\u670D\u52A1\u62D2\u7EDD\u4E86\u8BF7\u6C42\uFF08HTTP {status}\uFF09\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002",
1099
+ "error.client.streamClosed": "\u5BBF\u4E3B\u670D\u52A1\u63D0\u524D\u5173\u95ED\u4E86\u589E\u5F3A\u6D41\uFF0C\u8BF7\u91CD\u8BD5\uFF1B\u539F\u8F93\u5165\u672A\u6539\u52A8\u3002",
1100
+ "error.client.cancelled": "\u5DF2\u53D6\u6D88\u589E\u5F3A\uFF1B\u539F\u8F93\u5165\u672A\u6539\u52A8\u3002",
1090
1101
  "error.rateLimit": "\u8BF7\u6C42\u8FC7\u4E8E\u9891\u7E41\uFF1A\u6BCF\u5206\u949F\u6700\u591A {limit} \u6B21\u589E\u5F3A\uFF0C\u8BF7\u5728 {retryAfterSeconds} \u79D2\u540E\u518D\u8BD5\u3002",
1091
1102
  "error.concurrencyLimit": "\u5DF2\u6709 {max} \u4E2A\u589E\u5F3A\u6B63\u5728\u8FDB\u884C\uFF0C\u8BF7\u7B49\u5176\u4E2D\u4E00\u4E2A\u5B8C\u6210\u540E\u518D\u8BD5\u3002",
1092
1103
  "error.cooldown": "\u8FDE\u7EED {failures} \u6B21\u589E\u5F3A\u5931\u8D25\uFF0C\u5DF2\u6682\u505C\u8C03\u7528\u4EE5\u514D\u6301\u7EED\u51B2\u51FB\u6A21\u578B\u670D\u52A1\uFF1B\u8BF7 {retryAfterSeconds} \u79D2\u540E\u91CD\u8BD5\uFF0C\u6216\u5148\u68C0\u67E5\u8BBE\u7F6E\u91CC\u7684\u6A21\u578B\u914D\u7F6E\u3002",
@@ -1106,6 +1117,7 @@ var zh = {
1106
1117
  "settings.saved": "\u5DF2\u4FDD\u5B58",
1107
1118
  "settings.saveFailed": "\u672C\u90E8\u7F72\u6CA1\u6709\u63A5\u53D7\u8FD9\u4E9B\u503C\uFF0C\u5DF2\u4FDD\u7559\u4F9B\u4F60\u4FEE\u6539\u3002",
1108
1119
  "settings.saveFailedShort": "\u4FDD\u5B58\u5931\u8D25",
1120
+ "settings.advanced": "\u9AD8\u7EA7\u8BBE\u7F6E",
1109
1121
  "settings.readOnly": "\u672C\u90E8\u7F72\u7684\u8BBE\u7F6E\u4E3A\u53EA\u8BFB\u3002",
1110
1122
  "settings.unavailable": "\u8BE5\u63D2\u4EF6\u5F53\u524D\u672A\u52A0\u8F7D\uFF0C\u6682\u65F6\u65E0\u6CD5\u914D\u7F6E\u3002",
1111
1123
  "settings.reset": "\u6062\u590D\u9ED8\u8BA4",
@@ -1227,6 +1239,11 @@ var en = {
1227
1239
  "error.effortUnsupported": 'This model does not support the selected reasoning effort "{effort}". Choose another tier, or use "follow provider default".',
1228
1240
  "error.upstream": "The model provider returned an error. Retry; your draft is untouched.",
1229
1241
  "error.internal": "Enhancement failed. Retry; your draft is untouched.",
1242
+ "error.client.unreachable": "Cannot reach the host service \u2014 make sure dsh web is running, then retry.",
1243
+ "error.client.malformed": "The host returned data that could not be parsed. Retry; your draft is untouched.",
1244
+ "error.client.refused": "The host refused the request (HTTP {status}). Retry later.",
1245
+ "error.client.streamClosed": "The host closed the enhance stream early. Retry; your draft is untouched.",
1246
+ "error.client.cancelled": "The enhancement was cancelled; your draft is untouched.",
1230
1247
  "error.rateLimit": "Too many requests \u2014 at most {limit} enhancements per minute; retry in {retryAfterSeconds} seconds.",
1231
1248
  "error.concurrencyLimit": "{max} enhancements are already running \u2014 wait for one to finish, then retry.",
1232
1249
  "error.cooldown": "{failures} enhancements failed in a row; calls are paused to stop hammering the model service. Retry in {retryAfterSeconds}s, or check the model settings first.",
@@ -1246,6 +1263,7 @@ var en = {
1246
1263
  "settings.saved": "Saved",
1247
1264
  "settings.saveFailed": "The deployment did not accept these values; they were left for you to correct.",
1248
1265
  "settings.saveFailedShort": "Save failed",
1266
+ "settings.advanced": "Advanced",
1249
1267
  "settings.readOnly": "This deployment stores settings read-only.",
1250
1268
  "settings.unavailable": "This plugin is not loaded, so it cannot be configured right now.",
1251
1269
  "settings.reset": "Reset to default",
@@ -1586,6 +1604,58 @@ var CSS = `
1586
1604
  text-align: center;
1587
1605
  white-space: nowrap;
1588
1606
  }
1607
+ .dsh-pe-advanced {
1608
+ margin-top: 12px;
1609
+ border-top: 1px solid var(--dsw-alias-border-l3, rgba(128, 128, 128, 0.22));
1610
+ }
1611
+ .dsh-pe-advanced > summary {
1612
+ display: flex;
1613
+ align-items: center;
1614
+ gap: 8px;
1615
+ min-height: 40px;
1616
+ padding: 0 4px;
1617
+ list-style: none;
1618
+ font-size: 13px;
1619
+ font-weight: 500;
1620
+ color: var(--dsw-alias-label-secondary, inherit);
1621
+ cursor: pointer;
1622
+ user-select: none;
1623
+ }
1624
+ .dsh-pe-advanced > summary::-webkit-details-marker { display: none; }
1625
+ .dsh-pe-advanced > summary::marker { content: ''; }
1626
+ .dsh-pe-advanced > summary::before {
1627
+ content: '';
1628
+ flex: none;
1629
+ width: 0;
1630
+ height: 0;
1631
+ border-top: 4px solid transparent;
1632
+ border-bottom: 4px solid transparent;
1633
+ border-left: 5px solid currentColor;
1634
+ transition: transform 120ms ease;
1635
+ }
1636
+ .dsh-pe-advanced[open] > summary::before { transform: rotate(90deg); }
1637
+ .dsh-pe-advanced > summary:hover {
1638
+ color: var(--dsw-alias-label-primary, inherit);
1639
+ background: rgba(127, 127, 127, 0.08);
1640
+ border-radius: 6px;
1641
+ }
1642
+ .dsh-pe-advanced > summary:focus-visible {
1643
+ outline: 2px solid var(--dsw-alias-state-business-primary, #4f8cff);
1644
+ outline-offset: -2px;
1645
+ border-radius: 6px;
1646
+ }
1647
+ .dsh-pe-advanced[open] > summary { margin-bottom: 4px; }
1648
+ .dsh-pe-advanced + .dsh-pe-form-footer { margin-top: 0; }
1649
+ .dsh-pe-chip-reset:hover:not(:disabled),
1650
+ .dsh-pe-chip-refresh:hover:not(:disabled) {
1651
+ --pe-chip-bg: var(--dsw-alias-interactive-bg-hover, rgba(127, 127, 127, 0.18));
1652
+ --pe-chip-color: var(--dsw-alias-label-primary, inherit);
1653
+ }
1654
+ .dsh-pe-chip-reset:focus-visible,
1655
+ .dsh-pe-chip-refresh:focus-visible {
1656
+ outline: 2px solid var(--dsw-alias-state-business-primary, #4f8cff);
1657
+ outline-offset: 2px;
1658
+ }
1589
1659
  .dsh-pe-form-footer {
1590
1660
  display: flex;
1591
1661
  justify-content: flex-end;
@@ -1743,21 +1813,27 @@ function installClientSettingsSource(ctx, options) {
1743
1813
  }
1744
1814
  };
1745
1815
  bind();
1746
- ctx.effect(() => () => {
1747
- try {
1748
- unsubscribeForm?.();
1749
- } catch {
1750
- }
1751
- }, "dsh-prompt-enhance: settings form mirror");
1816
+ ctx.effect(
1817
+ () => () => {
1818
+ try {
1819
+ unsubscribeForm?.();
1820
+ } catch {
1821
+ }
1822
+ },
1823
+ "dsh-prompt-enhance: settings form mirror"
1824
+ );
1752
1825
  try {
1753
1826
  const watch = forms.describe?.()?.subscribe?.(() => bind());
1754
1827
  if (typeof watch === "function") {
1755
- ctx.effect(() => () => {
1756
- try {
1757
- watch();
1758
- } catch {
1759
- }
1760
- }, "dsh-prompt-enhance: settings namespace watch");
1828
+ ctx.effect(
1829
+ () => () => {
1830
+ try {
1831
+ watch();
1832
+ } catch {
1833
+ }
1834
+ },
1835
+ "dsh-prompt-enhance: settings namespace watch"
1836
+ );
1761
1837
  }
1762
1838
  } catch {
1763
1839
  }
@@ -1782,12 +1858,15 @@ function installClientSettingsSource(ctx, options) {
1782
1858
  } catch {
1783
1859
  unsubscribe = void 0;
1784
1860
  }
1785
- ctx.effect(() => () => {
1786
- try {
1787
- unsubscribe?.();
1788
- } catch {
1789
- }
1790
- }, "dsh-prompt-enhance: settings binder mirror");
1861
+ ctx.effect(
1862
+ () => () => {
1863
+ try {
1864
+ unsubscribe?.();
1865
+ } catch {
1866
+ }
1867
+ },
1868
+ "dsh-prompt-enhance: settings binder mirror"
1869
+ );
1791
1870
  });
1792
1871
  ctx.inject(["settingsScope"], (scopeCtx) => {
1793
1872
  const scopeCtxLike = scopeCtx;
@@ -1806,88 +1885,20 @@ function installClientSettingsSource(ctx, options) {
1806
1885
  } catch {
1807
1886
  unsubscribe = void 0;
1808
1887
  }
1809
- ctx.effect(() => () => {
1810
- try {
1811
- unsubscribe?.();
1812
- } catch {
1813
- }
1814
- }, "dsh-prompt-enhance: settings scope mirror");
1888
+ ctx.effect(
1889
+ () => () => {
1890
+ try {
1891
+ unsubscribe?.();
1892
+ } catch {
1893
+ }
1894
+ },
1895
+ "dsh-prompt-enhance: settings scope mirror"
1896
+ );
1815
1897
  });
1816
1898
  }
1817
1899
 
1818
1900
  // src/client/settings-page.tsx
1819
- var import_react8 = require("react");
1820
-
1821
- // src/shared/defaults.ts
1822
- var DEFAULT_VALUES = {
1823
- enabled: true,
1824
- temperature: 0.3,
1825
- // A rewrite does not need deep reasoning, and the route default is expensive
1826
- // (measured: 2897 output tokens at `high` vs 252 at `off` for the same draft).
1827
- // Sent explicitly, because omitting the field inherits that route default.
1828
- reasoningEffort: "off",
1829
- maxOutputTokens: 8192,
1830
- maxInputChars: 12e3,
1831
- timeoutMs: 6e4,
1832
- systemPrompt: "",
1833
- strategyMode: "replace-default",
1834
- shortcut: "",
1835
- maxConcurrent: 2,
1836
- rateLimitPerMinute: 10,
1837
- streaming: true,
1838
- contextAware: true,
1839
- contextMaxMessages: 8,
1840
- contextMaxChars: 4e3
1841
- };
1842
-
1843
- // src/shared/reasoning.ts
1844
- var REASONING_EFFORTS_ENDPOINT = "/dsh-prompt-enhance/reasoning-efforts";
1845
-
1846
- // src/client/reasoning-options.ts
1847
- function effortOf(value) {
1848
- if (value === null || typeof value !== "object") return void 0;
1849
- const record = value;
1850
- if (typeof record.id !== "string" || record.id === "" || typeof record.name !== "string" || record.name === "") return void 0;
1851
- return {
1852
- id: record.id,
1853
- name: record.name,
1854
- ...typeof record.description === "string" && record.description !== "" ? { description: record.description } : {}
1855
- };
1856
- }
1857
- function capabilitiesOf(value) {
1858
- if (value === null || typeof value !== "object") return { efforts: [], source: "unavailable", reason: "resolve-failed" };
1859
- const record = value;
1860
- const source = record.source === "resolved" || record.source === "default" || record.source === "unavailable" ? record.source : "unavailable";
1861
- const efforts = Array.isArray(record.efforts) ? record.efforts.map(effortOf).filter((effort) => effort !== void 0) : [];
1862
- const reason = typeof record.reason === "string" ? record.reason : void 0;
1863
- if (source !== "unavailable" && efforts.length === 0) return { efforts: [], source: "unavailable", reason: "no-efforts" };
1864
- return {
1865
- efforts,
1866
- source,
1867
- ...typeof record.defaultEffort === "string" && record.defaultEffort !== "" ? { defaultEffort: record.defaultEffort } : {},
1868
- ...reason === void 0 ? {} : { reason }
1869
- };
1870
- }
1871
- async function fetchReasoningCapabilities(provider, model, options = {}) {
1872
- const url = new URL(REASONING_EFFORTS_ENDPOINT, globalThis.location?.origin ?? "http://127.0.0.1");
1873
- if (provider !== void 0 && model !== void 0) {
1874
- url.searchParams.set("provider", provider);
1875
- url.searchParams.set("model", model);
1876
- }
1877
- if (options.refresh === true) url.searchParams.set("refresh", "1");
1878
- try {
1879
- const response = await fetch(url, { signal: options.signal, headers: { accept: "application/json" } });
1880
- if (!response.ok) return { efforts: [], source: "unavailable", reason: "resolve-failed" };
1881
- const body = await response.json();
1882
- const envelope = body;
1883
- if (envelope === null || envelope === void 0 || envelope.ok !== true) {
1884
- return { efforts: [], source: "unavailable", reason: "resolve-failed" };
1885
- }
1886
- return capabilitiesOf(envelope.value);
1887
- } catch {
1888
- return { efforts: [], source: "unavailable", reason: "resolve-failed" };
1889
- }
1890
- }
1901
+ var import_react9 = require("react");
1891
1902
 
1892
1903
  // src/client/llm-catalog.ts
1893
1904
  var import_react7 = require("react");
@@ -1918,12 +1929,16 @@ function endpoint(path, params = {}) {
1918
1929
  async function fetchProviders(signal) {
1919
1930
  const value = await getJson(endpoint(LLM_PROVIDERS_ENDPOINT), signal);
1920
1931
  if (value === void 0 || !Array.isArray(value.providers)) return void 0;
1921
- return value.providers.filter((entry) => entry !== null && typeof entry === "object" && typeof entry.id === "string" && entry.id !== "" && typeof entry.name === "string" && entry.name !== "" && typeof entry.registered === "boolean");
1932
+ return value.providers.filter(
1933
+ (entry) => entry !== null && typeof entry === "object" && typeof entry.id === "string" && entry.id !== "" && typeof entry.name === "string" && entry.name !== "" && typeof entry.registered === "boolean"
1934
+ );
1922
1935
  }
1923
1936
  async function fetchModels(provider, signal) {
1924
1937
  const value = await getJson(endpoint(LLM_MODELS_ENDPOINT, { provider }), signal);
1925
1938
  if (value === void 0 || !Array.isArray(value.models)) return void 0;
1926
- const models = value.models.filter((entry) => entry !== null && typeof entry === "object" && typeof entry.id === "string" && entry.id !== "" && typeof entry.name === "string" && entry.name !== "").map((entry) => ({
1939
+ const models = value.models.filter(
1940
+ (entry) => entry !== null && typeof entry === "object" && typeof entry.id === "string" && entry.id !== "" && typeof entry.name === "string" && entry.name !== ""
1941
+ ).map((entry) => ({
1927
1942
  id: entry.id,
1928
1943
  name: entry.name,
1929
1944
  ...typeof entry.description === "string" && entry.description !== "" ? { description: entry.description } : {}
@@ -2023,21 +2038,12 @@ function useLlmRouting(provider, model) {
2023
2038
  };
2024
2039
  }
2025
2040
 
2026
- // src/client/settings-page.tsx
2041
+ // src/client/settings-page-spec.ts
2027
2042
  var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
2028
- var import_jsx_runtime7 = require("react/jsx-runtime");
2029
2043
  var SETTINGS_SECTION_SLOT = "settings.section";
2030
2044
  var SETTINGS_SECTION_ID = "dsh-prompt-enhance";
2031
2045
  var SETTINGS_SECTION_ORDER = 70;
2032
2046
  var SETTINGS_SECTION_LABEL = "\u63D0\u793A\u8BCD\u589E\u5F3A";
2033
- function sectionTitle(getLocale) {
2034
- try {
2035
- const t = getLocale?.()?.bind(NS);
2036
- return t === void 0 ? SETTINGS_SECTION_LABEL : t("settings.title");
2037
- } catch {
2038
- return SETTINGS_SECTION_LABEL;
2039
- }
2040
- }
2041
2047
  var SETTINGS_ROW_CONFIG_SLOT = "plugins.row.config";
2042
2048
  var SETTINGS_NAMESPACE = "dsh-prompt-enhance";
2043
2049
  var SETTINGS_BUNDLE = "@surfishs/dsh-prompt-enhance";
@@ -2071,25 +2077,28 @@ var STRATEGY_OPTIONS = [
2071
2077
  { value: "replace-default", label: "settings.strategy.replace" },
2072
2078
  { value: "extend-default", label: "settings.strategy.extend" }
2073
2079
  ];
2074
- var ROWS = [
2080
+ var BASIC_ROWS = [
2075
2081
  { key: "enabled", kind: "boolean", label: "settings.row.enabled.label", hint: "settings.row.enabled.hint" },
2076
- { key: "contextAware", kind: "boolean", label: "settings.row.contextAware.label", hint: "settings.row.contextAware.hint" },
2077
- { key: "streaming", kind: "boolean", label: "settings.row.streaming.label", hint: "settings.row.streaming.hint" },
2078
2082
  { key: "provider", kind: "provider", label: "settings.row.provider.label", hint: "settings.row.provider.hint" },
2079
2083
  { key: "model", kind: "model", label: "settings.row.model.label", hint: "settings.row.model.hint" },
2080
2084
  { key: "reasoningEffort", kind: "reasoning", label: "settings.row.reasoningEffort.label", hint: "settings.row.reasoningEffort.hint" },
2081
2085
  { key: "temperature", kind: "number", label: "settings.row.temperature.label", hint: "settings.row.temperature.hint" },
2082
- { key: "maxOutputTokens", kind: "number", label: "settings.row.maxOutputTokens.label", hint: "settings.row.maxOutputTokens.hint" },
2086
+ { key: "contextAware", kind: "boolean", label: "settings.row.contextAware.label", hint: "settings.row.contextAware.hint" },
2087
+ { key: "streaming", kind: "boolean", label: "settings.row.streaming.label", hint: "settings.row.streaming.hint" },
2088
+ { key: "systemPrompt", kind: "text", label: "settings.row.systemPrompt.label", hint: "settings.row.systemPrompt.hint", placeholder: "settings.row.systemPrompt.placeholder" },
2089
+ { key: "shortcut", kind: "text", label: "settings.row.shortcut.label", hint: "settings.row.shortcut.hint", placeholder: "settings.row.shortcut.placeholder" }
2090
+ ];
2091
+ var ADVANCED_ROWS = [
2092
+ { key: "strategyMode", kind: "strategy", label: "settings.row.strategyMode.label", hint: "settings.row.strategyMode.hint" },
2083
2093
  { key: "maxInputChars", kind: "number", label: "settings.row.maxInputChars.label", hint: "settings.row.maxInputChars.hint" },
2094
+ { key: "maxOutputTokens", kind: "number", label: "settings.row.maxOutputTokens.label", hint: "settings.row.maxOutputTokens.hint" },
2084
2095
  { key: "timeoutMs", kind: "number", label: "settings.row.timeoutMs.label", hint: "settings.row.timeoutMs.hint" },
2085
- { key: "strategyMode", kind: "strategy", label: "settings.row.strategyMode.label", hint: "settings.row.strategyMode.hint" },
2086
- { key: "systemPrompt", kind: "text", label: "settings.row.systemPrompt.label", hint: "settings.row.systemPrompt.hint", placeholder: "settings.row.systemPrompt.placeholder" },
2087
2096
  { key: "contextMaxMessages", kind: "number", label: "settings.row.contextMaxMessages.label", hint: "settings.row.contextMaxMessages.hint" },
2088
2097
  { key: "contextMaxChars", kind: "number", label: "settings.row.contextMaxChars.label", hint: "settings.row.contextMaxChars.hint" },
2089
2098
  { key: "maxConcurrent", kind: "number", label: "settings.row.maxConcurrent.label", hint: "settings.row.maxConcurrent.hint" },
2090
- { key: "rateLimitPerMinute", kind: "number", label: "settings.row.rateLimitPerMinute.label", hint: "settings.row.rateLimitPerMinute.hint" },
2091
- { key: "shortcut", kind: "text", label: "settings.row.shortcut.label", hint: "settings.row.shortcut.hint", placeholder: "settings.row.shortcut.placeholder" }
2099
+ { key: "rateLimitPerMinute", kind: "number", label: "settings.row.rateLimitPerMinute.label", hint: "settings.row.rateLimitPerMinute.hint" }
2092
2100
  ];
2101
+ var ROWS = [...BASIC_ROWS, ...ADVANCED_ROWS];
2093
2102
  function descriptorOf(row) {
2094
2103
  switch (row.kind) {
2095
2104
  case "number":
@@ -2097,7 +2106,10 @@ function descriptorOf(row) {
2097
2106
  case "boolean":
2098
2107
  return settingsBooleanField(row.key);
2099
2108
  case "strategy":
2100
- return settingsEnumField(row.key, STRATEGY_OPTIONS.map((option) => option.value));
2109
+ return settingsEnumField(
2110
+ row.key,
2111
+ STRATEGY_OPTIONS.map((option) => option.value)
2112
+ );
2101
2113
  case "reasoning":
2102
2114
  return (0, import_dsh_client_ui_primitives.settingsTextField)(row.key);
2103
2115
  default:
@@ -2108,6 +2120,38 @@ var FIELD_SPECS = ROWS.map((row) => descriptorOf(row));
2108
2120
  function createSettingsForm(scope) {
2109
2121
  return new import_dsh_client_ui_primitives.SettingsFormModel(scope, FIELD_SPECS);
2110
2122
  }
2123
+ function viewOf(snapshot, key) {
2124
+ const value = snapshot[key];
2125
+ if (value === null || typeof value !== "object") return { text: "", overridden: false, invalid: false };
2126
+ const field = value;
2127
+ return {
2128
+ text: typeof field.text === "string" ? field.text : "",
2129
+ overridden: field.overridden === true,
2130
+ invalid: field.invalid === true
2131
+ };
2132
+ }
2133
+ function defaultTextOf(key) {
2134
+ const descriptor = FIELD_SPECS.find((item) => item.field === key);
2135
+ const fallback = DEFAULT_VALUES[key];
2136
+ if (descriptor === void 0 || fallback === void 0) return "";
2137
+ try {
2138
+ return descriptor.format(fallback);
2139
+ } catch {
2140
+ return "";
2141
+ }
2142
+ }
2143
+ function atDefaultValue(key, text) {
2144
+ const fallback = DEFAULT_VALUES[key];
2145
+ if (fallback === void 0) return text.trim() === "";
2146
+ if (typeof fallback === "boolean") return text.trim() === String(fallback);
2147
+ if (typeof fallback === "number") {
2148
+ const parsed = Number(text.trim());
2149
+ return Number.isFinite(parsed) && parsed === fallback;
2150
+ }
2151
+ return text.trim() === String(fallback);
2152
+ }
2153
+
2154
+ // src/client/settings-page-copy.ts
2111
2155
  var ZH_COPY = zh;
2112
2156
  function translator(t) {
2113
2157
  if (typeof t === "function") return t;
@@ -2129,6 +2173,7 @@ function sectionCopy(t, chinese) {
2129
2173
  save: t("settings.save"),
2130
2174
  saving: t("settings.saving"),
2131
2175
  saved: t("settings.saved"),
2176
+ advanced: t("settings.advanced"),
2132
2177
  reset: t("settings.reset"),
2133
2178
  invalidNumber: t("settings.invalidNumber")
2134
2179
  },
@@ -2149,6 +2194,7 @@ function pageCopy(t) {
2149
2194
  save: t("settings.save"),
2150
2195
  saving: t("settings.saving"),
2151
2196
  saved: t("settings.saved"),
2197
+ advanced: t("settings.advanced"),
2152
2198
  reset: t("settings.reset"),
2153
2199
  invalidNumber: t("settings.invalidNumber")
2154
2200
  },
@@ -2159,6 +2205,61 @@ function pageCopy(t) {
2159
2205
  interpolate: (key, params) => t(key, params)
2160
2206
  };
2161
2207
  }
2208
+
2209
+ // src/client/settings-page-controls.tsx
2210
+ var import_react8 = require("react");
2211
+ var import_dsh_client_ui_primitives2 = require("@deepseek-ai/dsh-client-ui-primitives");
2212
+
2213
+ // src/shared/reasoning.ts
2214
+ var REASONING_EFFORTS_ENDPOINT = "/dsh-prompt-enhance/reasoning-efforts";
2215
+
2216
+ // src/client/reasoning-options.ts
2217
+ function effortOf(value) {
2218
+ if (value === null || typeof value !== "object") return void 0;
2219
+ const record = value;
2220
+ if (typeof record.id !== "string" || record.id === "" || typeof record.name !== "string" || record.name === "") return void 0;
2221
+ return {
2222
+ id: record.id,
2223
+ name: record.name,
2224
+ ...typeof record.description === "string" && record.description !== "" ? { description: record.description } : {}
2225
+ };
2226
+ }
2227
+ function capabilitiesOf(value) {
2228
+ if (value === null || typeof value !== "object") return { efforts: [], source: "unavailable", reason: "resolve-failed" };
2229
+ const record = value;
2230
+ const source = record.source === "resolved" || record.source === "default" || record.source === "unavailable" ? record.source : "unavailable";
2231
+ const efforts = Array.isArray(record.efforts) ? record.efforts.map(effortOf).filter((effort) => effort !== void 0) : [];
2232
+ const reason = typeof record.reason === "string" ? record.reason : void 0;
2233
+ if (source !== "unavailable" && efforts.length === 0) return { efforts: [], source: "unavailable", reason: "no-efforts" };
2234
+ return {
2235
+ efforts,
2236
+ source,
2237
+ ...typeof record.defaultEffort === "string" && record.defaultEffort !== "" ? { defaultEffort: record.defaultEffort } : {},
2238
+ ...reason === void 0 ? {} : { reason }
2239
+ };
2240
+ }
2241
+ async function fetchReasoningCapabilities(provider, model, options = {}) {
2242
+ const url = new URL(REASONING_EFFORTS_ENDPOINT, globalThis.location?.origin ?? "http://127.0.0.1");
2243
+ if (provider !== void 0 && model !== void 0) {
2244
+ url.searchParams.set("provider", provider);
2245
+ url.searchParams.set("model", model);
2246
+ }
2247
+ if (options.refresh === true) url.searchParams.set("refresh", "1");
2248
+ try {
2249
+ const response = await fetch(url, { signal: options.signal, headers: { accept: "application/json" } });
2250
+ if (!response.ok) return { efforts: [], source: "unavailable", reason: "resolve-failed" };
2251
+ const body = await response.json();
2252
+ const envelope = body;
2253
+ if (envelope === null || envelope === void 0 || envelope.ok !== true) {
2254
+ return { efforts: [], source: "unavailable", reason: "resolve-failed" };
2255
+ }
2256
+ return capabilitiesOf(envelope.value);
2257
+ } catch {
2258
+ return { efforts: [], source: "unavailable", reason: "resolve-failed" };
2259
+ }
2260
+ }
2261
+
2262
+ // src/client/settings-page-styles.ts
2162
2263
  var ROW_STYLE = { display: "flex", flexDirection: "column", gap: 6, padding: "12px 0" };
2163
2264
  var HEAD_STYLE = { display: "flex", alignItems: "center", gap: 8 };
2164
2265
  var LABEL_STYLE = {
@@ -2187,12 +2288,12 @@ var CHIP_STYLE = {
2187
2288
  padding: "1px 8px",
2188
2289
  border: "none",
2189
2290
  borderRadius: 999,
2190
- background: "var(--dsw-alias-bg-module-platform, rgba(128, 128, 128, 0.12))",
2291
+ background: "var(--pe-chip-bg, var(--dsw-alias-bg-module-platform, rgba(128, 128, 128, 0.12)))",
2191
2292
  fontFamily: "inherit",
2192
2293
  fontSize: 11,
2193
2294
  fontWeight: 500,
2194
2295
  lineHeight: "17px",
2195
- color: "var(--dsw-alias-label-secondary, inherit)",
2296
+ color: "var(--pe-chip-color, var(--dsw-alias-label-secondary, inherit))",
2196
2297
  textDecoration: "underline",
2197
2298
  textUnderlineOffset: 2,
2198
2299
  cursor: "pointer"
@@ -2237,7 +2338,7 @@ var REPOSITORY_URL = "https://github.com/surfishs/dsh-prompt-enhance";
2237
2338
  var NPM_URL = "https://www.npmjs.com/package/@surfishs/dsh-prompt-enhance";
2238
2339
  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";
2239
2340
  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";
2240
- var PLUGIN_VERSION = true ? "0.0.6" : "0.0.0";
2341
+ var PLUGIN_VERSION = true ? "0.0.8" : "0.0.0";
2241
2342
  var HEADER_STYLE = { display: "flex", flexDirection: "column", gap: 12, padding: "2px 0" };
2242
2343
  var HEADER_ROW_STYLE = { display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" };
2243
2344
  var HEADER_TITLE_STYLE = {
@@ -2282,72 +2383,18 @@ var HEADER_DESCRIPTION_STYLE = {
2282
2383
  textWrap: "pretty",
2283
2384
  maxWidth: "72ch"
2284
2385
  };
2285
- function PageHeader(props) {
2286
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: HEADER_STYLE, children: [
2287
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: HEADER_ROW_STYLE, children: [
2288
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: HEADER_TITLE_STYLE, children: props.title }),
2289
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("a", { href: REPOSITORY_URL, target: "_blank", rel: "noreferrer", style: HEADER_LINK_STYLE, children: [
2290
- /* @__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 }) }),
2291
- "GitHub"
2292
- ] }),
2293
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("a", { href: NPM_URL, target: "_blank", rel: "noreferrer", style: HEADER_LINK_STYLE, children: [
2294
- /* @__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 }) }),
2295
- "npm"
2296
- ] }),
2297
- /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { style: HEADER_VERSION_STYLE, children: [
2298
- "v",
2299
- props.version
2300
- ] })
2301
- ] }),
2302
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: HEADER_DESCRIPTION_STYLE, children: props.description })
2303
- ] });
2304
- }
2305
- function viewOf(snapshot, key) {
2306
- const value = snapshot[key];
2307
- if (value === null || typeof value !== "object") return { text: "", overridden: false, invalid: false };
2308
- const field = value;
2309
- return {
2310
- text: typeof field.text === "string" ? field.text : "",
2311
- overridden: field.overridden === true,
2312
- invalid: field.invalid === true
2313
- };
2314
- }
2315
- function atDefaultValue(key, text) {
2316
- const fallback = DEFAULT_VALUES[key];
2317
- if (fallback === void 0) return text.trim() === "";
2318
- if (typeof fallback === "boolean") return text.trim() === String(fallback);
2319
- if (typeof fallback === "number") {
2320
- const parsed = Number(text.trim());
2321
- return Number.isFinite(parsed) && parsed === fallback;
2322
- }
2323
- return text.trim() === String(fallback);
2324
- }
2386
+
2387
+ // src/client/settings-page-controls.tsx
2388
+ var import_jsx_runtime7 = require("react/jsx-runtime");
2325
2389
  function OverrideActions(props) {
2326
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2327
- "button",
2328
- {
2329
- type: "button",
2330
- style: { ...RESET_STYLE, ...props.disabled ? { opacity: 0.5, cursor: "default" } : {} },
2331
- disabled: props.disabled,
2332
- onClick: props.onReset,
2333
- children: props.copy.labels.reset
2334
- }
2335
- );
2390
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", className: "dsh-pe-chip-reset", style: { ...RESET_STYLE, ...props.disabled ? { opacity: 0.5, cursor: "default" } : {} }, disabled: props.disabled, onClick: props.onReset, children: props.copy.labels.reset });
2336
2391
  }
2337
2392
  function BooleanRow(props) {
2338
2393
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: ROW_STYLE, children: [
2339
2394
  /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: HEAD_STYLE, children: [
2340
2395
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: LABEL_STYLE, children: props.label }),
2341
2396
  props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null,
2342
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2343
- import_dsh_client_ui_primitives.Switch,
2344
- {
2345
- checked: props.view.text === "true",
2346
- disabled: props.disabled,
2347
- label: props.label,
2348
- onChange: (next) => props.onEdit(next ? "true" : "false")
2349
- }
2350
- )
2397
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_dsh_client_ui_primitives2.Switch, { checked: props.view.text === "true", disabled: props.disabled, label: props.label, onChange: (next) => props.onEdit(next ? "true" : "false") })
2351
2398
  ] }),
2352
2399
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: HINT_STYLE, children: props.hint })
2353
2400
  ] });
@@ -2359,7 +2406,7 @@ function ChoiceRow(props) {
2359
2406
  props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null
2360
2407
  ] }),
2361
2408
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2362
- import_dsh_client_ui_primitives.SegmentedControl,
2409
+ import_dsh_client_ui_primitives2.SegmentedControl,
2363
2410
  {
2364
2411
  id: props.id,
2365
2412
  className: "dsh-pe-segmented-labels",
@@ -2400,11 +2447,7 @@ function ReasoningRow(props) {
2400
2447
  feedbackTimer.current = void 0;
2401
2448
  }, 3e3);
2402
2449
  };
2403
- fetchReasoningCapabilities(
2404
- props.provider === "" ? void 0 : props.provider,
2405
- props.model === "" ? void 0 : props.model,
2406
- { refresh: force, signal: controller.signal }
2407
- ).then((answer) => {
2450
+ fetchReasoningCapabilities(props.provider === "" ? void 0 : props.provider, props.model === "" ? void 0 : props.model, { refresh: force, signal: controller.signal }).then((answer) => {
2408
2451
  if (controller.signal.aborted) return;
2409
2452
  setCapabilities(answer);
2410
2453
  setPhase("ready");
@@ -2457,20 +2500,11 @@ function ReasoningRow(props) {
2457
2500
  return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: ROW_STYLE, children: [
2458
2501
  /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: HEAD_STYLE, children: [
2459
2502
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: LABEL_STYLE, children: props.label }),
2460
- phase === "ready" || refreshing ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2461
- "button",
2462
- {
2463
- type: "button",
2464
- style: { ...REFRESH_STYLE, opacity: props.disabled || refreshing ? 0.5 : 1 },
2465
- disabled: props.disabled || refreshing,
2466
- onClick: refresh,
2467
- children: props.copy.choice(refreshing ? "settings.reasoning.refreshing" : "settings.reasoning.refresh")
2468
- }
2469
- ) : null,
2503
+ phase === "ready" || refreshing ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", className: "dsh-pe-chip-refresh", style: { ...REFRESH_STYLE, opacity: props.disabled || refreshing ? 0.5 : 1 }, disabled: props.disabled || refreshing, onClick: refresh, children: props.copy.choice(refreshing ? "settings.reasoning.refreshing" : "settings.reasoning.refresh") }) : null,
2470
2504
  props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null
2471
2505
  ] }),
2472
2506
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2473
- import_dsh_client_ui_primitives.SegmentedControl,
2507
+ import_dsh_client_ui_primitives2.SegmentedControl,
2474
2508
  {
2475
2509
  id: props.id,
2476
2510
  className: "dsh-pe-segmented-labels",
@@ -2567,15 +2601,7 @@ function ModelRow(props) {
2567
2601
  ]
2568
2602
  }
2569
2603
  ),
2570
- showCustom ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2571
- TextControl,
2572
- {
2573
- value: current2,
2574
- placeholder: props.copy.choice("settings.routing.customPlaceholder"),
2575
- disabled: props.disabled,
2576
- onChange: props.onEdit
2577
- }
2578
- ) : null,
2604
+ showCustom ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TextControl, { value: current2, placeholder: props.copy.choice("settings.routing.customPlaceholder"), disabled: props.disabled, onChange: props.onEdit }) : null,
2579
2605
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: HINT_STYLE, children: props.hint }),
2580
2606
  props.routing.models.loading ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: STATUS_STYLE, children: props.copy.choice("settings.routing.modelsLoading") }) : null,
2581
2607
  props.routing.models.failed && !showCustom ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: STATUS_STYLE, children: props.copy.choice("settings.routing.modelsFailed") }) : null,
@@ -2646,6 +2672,37 @@ function ValueRow(props) {
2646
2672
  invalid ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: INVALID_STYLE, children: props.copy.labels.invalidNumber }) : null
2647
2673
  ] });
2648
2674
  }
2675
+
2676
+ // src/client/settings-page.tsx
2677
+ var import_jsx_runtime8 = require("react/jsx-runtime");
2678
+ function sectionTitle(getLocale) {
2679
+ try {
2680
+ const t = getLocale?.()?.bind(NS);
2681
+ return t === void 0 ? SETTINGS_SECTION_LABEL : t("settings.title");
2682
+ } catch {
2683
+ return SETTINGS_SECTION_LABEL;
2684
+ }
2685
+ }
2686
+ function PageHeader(props) {
2687
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { style: HEADER_STYLE, children: [
2688
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { style: HEADER_ROW_STYLE, children: [
2689
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { style: HEADER_TITLE_STYLE, children: props.title }),
2690
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("a", { href: REPOSITORY_URL, target: "_blank", rel: "noreferrer", style: HEADER_LINK_STYLE, children: [
2691
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("svg", { width: 11, height: 11, viewBox: "0 0 16 16", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { fill: "currentColor", d: GITHUB_MARK }) }),
2692
+ "GitHub"
2693
+ ] }),
2694
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("a", { href: NPM_URL, target: "_blank", rel: "noreferrer", style: HEADER_LINK_STYLE, children: [
2695
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("svg", { width: 11, height: 11, viewBox: "0 0 24 24", "aria-hidden": "true", focusable: "false", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("path", { fill: "currentColor", d: NPM_MARK }) }),
2696
+ "npm"
2697
+ ] }),
2698
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { style: HEADER_VERSION_STYLE, children: [
2699
+ "v",
2700
+ props.version
2701
+ ] })
2702
+ ] }),
2703
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { style: HEADER_DESCRIPTION_STYLE, children: props.description })
2704
+ ] });
2705
+ }
2649
2706
  function SettingsRow(props) {
2650
2707
  const shared = {
2651
2708
  id: `dsh-prompt-enhance-${props.row.key}`,
@@ -2660,29 +2717,29 @@ function SettingsRow(props) {
2660
2717
  };
2661
2718
  switch (props.row.kind) {
2662
2719
  case "boolean":
2663
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(BooleanRow, { ...shared });
2720
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(BooleanRow, { ...shared });
2664
2721
  case "strategy":
2665
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ChoiceRow, { ...shared, options: STRATEGY_OPTIONS.map((option) => ({ value: option.value, label: props.copy.choice(option.label) })) });
2722
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ChoiceRow, { ...shared, options: STRATEGY_OPTIONS.map((option) => ({ value: option.value, label: props.copy.choice(option.label) })) });
2666
2723
  case "reasoning":
2667
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ReasoningRow, { ...shared, provider: props.reasoningPair.provider, model: props.reasoningPair.model });
2724
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ReasoningRow, { ...shared, provider: props.reasoningPair.provider, model: props.reasoningPair.model });
2668
2725
  case "provider":
2669
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ProviderRow, { ...shared, routing: props.routing });
2726
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ProviderRow, { ...shared, routing: props.routing });
2670
2727
  case "model":
2671
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ModelRow, { ...shared, routing: props.routing, providerValue: props.providerValue });
2728
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ModelRow, { ...shared, routing: props.routing, providerValue: props.providerValue });
2672
2729
  default:
2673
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ValueRow, { ...shared, numeric: props.row.kind === "number", placeholder: props.copy.placeholder(props.row) });
2730
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ValueRow, { ...shared, numeric: props.row.kind === "number", placeholder: props.copy.placeholder(props.row) });
2674
2731
  }
2675
2732
  }
2676
2733
  function SettingsRows(props) {
2677
2734
  const provider = viewOf(props.state, "provider").text.trim();
2678
2735
  const model = viewOf(props.state, "model").text.trim();
2679
2736
  const routing = useLlmRouting(provider, model);
2680
- const [saveState, setSaveState] = (0, import_react8.useState)("idle");
2681
- const timers = (0, import_react8.useRef)(/* @__PURE__ */ new Map());
2682
- const savedTimer = (0, import_react8.useRef)(void 0);
2683
- const savedValues = (0, import_react8.useRef)(/* @__PURE__ */ new Map());
2684
- const sequence = (0, import_react8.useRef)(0);
2685
- (0, import_react8.useEffect)(() => {
2737
+ const [saveState, setSaveState] = (0, import_react9.useState)("idle");
2738
+ const timers = (0, import_react9.useRef)(/* @__PURE__ */ new Map());
2739
+ const savedTimer = (0, import_react9.useRef)(void 0);
2740
+ const savedValues = (0, import_react9.useRef)(/* @__PURE__ */ new Map());
2741
+ const sequence = (0, import_react9.useRef)(0);
2742
+ (0, import_react9.useEffect)(() => {
2686
2743
  for (const row of ROWS) {
2687
2744
  if (!savedValues.current.has(row.key)) {
2688
2745
  savedValues.current.set(row.key, viewOf(props.state, row.key).text);
@@ -2715,6 +2772,29 @@ function SettingsRows(props) {
2715
2772
  savedTimer.current = void 0;
2716
2773
  }, 2e3);
2717
2774
  };
2775
+ const runReset = async (key, fallback) => {
2776
+ if (props.writeField === void 0) return;
2777
+ const ticket = ++sequence.current;
2778
+ setSaveState("saving");
2779
+ const result = await props.writeField(key, "");
2780
+ if (ticket !== sequence.current) return;
2781
+ if (result === "failed") {
2782
+ setSaveState("failed");
2783
+ return;
2784
+ }
2785
+ if (result === "invalid") {
2786
+ setSaveState("idle");
2787
+ return;
2788
+ }
2789
+ savedValues.current.set(key, fallback);
2790
+ markSaved();
2791
+ };
2792
+ const resetAndSave = (key) => {
2793
+ props.resetField(key);
2794
+ const fallback = defaultTextOf(key);
2795
+ savedValues.current.set(key, fallback);
2796
+ void runReset(key, fallback);
2797
+ };
2718
2798
  const manualSave = async () => {
2719
2799
  if (props.writeField === void 0) {
2720
2800
  props.save?.();
@@ -2769,35 +2849,43 @@ function SettingsRows(props) {
2769
2849
  }
2770
2850
  void runSave(key, text ?? viewOf(props.state, key).text);
2771
2851
  };
2772
- (0, import_react8.useEffect)(() => () => {
2773
- for (const timer of timers.current.values()) clearTimeout(timer);
2774
- timers.current.clear();
2775
- if (savedTimer.current !== void 0) clearTimeout(savedTimer.current);
2776
- }, []);
2852
+ (0, import_react9.useEffect)(
2853
+ () => () => {
2854
+ for (const timer of timers.current.values()) clearTimeout(timer);
2855
+ timers.current.clear();
2856
+ if (savedTimer.current !== void 0) clearTimeout(savedTimer.current);
2857
+ },
2858
+ []
2859
+ );
2777
2860
  const statusText = props.state.writable === false ? props.copy.labels.readOnly : saveState === "saving" ? props.copy.labels.saving : saveState === "saved" ? props.copy.labels.saved : saveState === "failed" ? props.copy.labels.saveFailedShort : "";
2778
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsh-pe-form", children: [
2779
- ROWS.map((row, index) => {
2780
- const raw = viewOf(props.state, row.key);
2781
- const view = raw.overridden && atDefaultValue(row.key, raw.text) ? { ...raw, overridden: false } : raw;
2782
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { style: index === 0 ? void 0 : SEPARATOR_STYLE, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2783
- SettingsRow,
2784
- {
2785
- row,
2786
- copy: props.copy,
2787
- view,
2788
- disabled: !props.state.writable,
2789
- reasoningPair: { provider, model },
2790
- routing,
2791
- providerValue: provider,
2792
- onEdit: (text) => onEdit(row.key, text),
2793
- onReset: () => props.resetField(row.key),
2794
- onCommit: () => flushField(row.key, viewOf(props.state, row.key).text)
2795
- }
2796
- ) }, row.key);
2797
- }),
2798
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "dsh-pe-form-footer", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "dsh-pe-save-group", children: [
2799
- statusText === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "dsh-pe-save-status", role: "status", "aria-live": "polite", children: statusText }),
2800
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2861
+ const renderRow = (row, index) => {
2862
+ const raw = viewOf(props.state, row.key);
2863
+ const view = raw.overridden && atDefaultValue(row.key, raw.text) ? { ...raw, overridden: false } : raw;
2864
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { style: index === 0 ? void 0 : SEPARATOR_STYLE, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2865
+ SettingsRow,
2866
+ {
2867
+ row,
2868
+ copy: props.copy,
2869
+ view,
2870
+ disabled: !props.state.writable,
2871
+ reasoningPair: { provider, model },
2872
+ routing,
2873
+ providerValue: provider,
2874
+ onEdit: (text) => onEdit(row.key, text),
2875
+ onReset: () => resetAndSave(row.key),
2876
+ onCommit: () => flushField(row.key, viewOf(props.state, row.key).text)
2877
+ }
2878
+ ) }, row.key);
2879
+ };
2880
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "dsh-pe-form", children: [
2881
+ BASIC_ROWS.map(renderRow),
2882
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("details", { className: "dsh-pe-advanced", children: [
2883
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("summary", { children: props.copy.labels.advanced }),
2884
+ ADVANCED_ROWS.map(renderRow)
2885
+ ] }),
2886
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "dsh-pe-form-footer", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "dsh-pe-save-group", children: [
2887
+ statusText === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "dsh-pe-save-status", role: "status", "aria-live": "polite", children: statusText }),
2888
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
2801
2889
  "button",
2802
2890
  {
2803
2891
  type: "button",
@@ -2820,26 +2908,15 @@ function SettingsSection(props) {
2820
2908
  const t = translator(props.translate);
2821
2909
  const chinese = (locale?.active ?? "zh").toLowerCase().startsWith("zh");
2822
2910
  if (state === void 0) {
2823
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: { margin: 0, fontSize: 12, lineHeight: 1.6 }, children: t("settings.disconnected") });
2911
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { style: { margin: 0, fontSize: 12, lineHeight: 1.6 }, children: t("settings.disconnected") });
2824
2912
  }
2825
2913
  const edit = props.edit ?? (() => {
2826
2914
  });
2827
2915
  const resetField = props.resetField ?? (() => {
2828
2916
  });
2829
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 12 }, children: [
2830
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PageHeader, { title: t("settings.title"), description: t("settings.description"), version: PLUGIN_VERSION }),
2831
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2832
- SettingsRows,
2833
- {
2834
- copy: sectionCopy(t, chinese),
2835
- state,
2836
- edit,
2837
- resetField,
2838
- save: props.save,
2839
- discard: props.discard,
2840
- writeField: props.writeField
2841
- }
2842
- )
2917
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 12 }, children: [
2918
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(PageHeader, { title: t("settings.title"), description: t("settings.description"), version: PLUGIN_VERSION }),
2919
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SettingsRows, { copy: sectionCopy(t, chinese), state, edit, resetField, save: props.save, discard: props.discard, writeField: props.writeField })
2843
2920
  ] });
2844
2921
  }
2845
2922
  function SettingsPage(props) {
@@ -2848,24 +2925,13 @@ function SettingsPage(props) {
2848
2925
  const state = read === void 0 ? void 0 : read((snapshot) => snapshot);
2849
2926
  if (props.view === "summary") return t("settings.summary");
2850
2927
  if (state === void 0) {
2851
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: { margin: 0, fontSize: 12, lineHeight: 1.6 }, children: t("settings.disconnected") });
2928
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { style: { margin: 0, fontSize: 12, lineHeight: 1.6 }, children: t("settings.disconnected") });
2852
2929
  }
2853
2930
  const edit = props.edit ?? (() => {
2854
2931
  });
2855
2932
  const resetField = props.resetField ?? (() => {
2856
2933
  });
2857
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
2858
- SettingsRows,
2859
- {
2860
- copy: pageCopy(t),
2861
- state,
2862
- edit,
2863
- resetField,
2864
- save: props.save,
2865
- discard: props.discard,
2866
- writeField: props.writeField
2867
- }
2868
- );
2934
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SettingsRows, { copy: pageCopy(t), state, edit, resetField, save: props.save, discard: props.discard, writeField: props.writeField });
2869
2935
  }
2870
2936
  var SettingsPageController = class {
2871
2937
  /**
@@ -3027,10 +3093,7 @@ function apply(ctx) {
3027
3093
  if (slots === void 0) return;
3028
3094
  return slots.inject("conversation.input.right", () => {
3029
3095
  try {
3030
- return slots.register(
3031
- { name: "conversation.input.right", id: "dsh-prompt-enhance", order: 60, locale: NS },
3032
- EnhanceButton
3033
- );
3096
+ return slots.register({ name: "conversation.input.right", id: "dsh-prompt-enhance", order: 60, locale: NS }, EnhanceButton);
3034
3097
  } catch (error) {
3035
3098
  return report("composer enhance button slot", error);
3036
3099
  }
@@ -3041,10 +3104,7 @@ function apply(ctx) {
3041
3104
  if (slots === void 0) return;
3042
3105
  return slots.inject("conversation.input.dock", () => {
3043
3106
  try {
3044
- return slots.register(
3045
- { name: "conversation.input.dock", id: "dsh-prompt-enhance-result", order: 30, locale: NS },
3046
- ResultDock
3047
- );
3107
+ return slots.register({ name: "conversation.input.dock", id: "dsh-prompt-enhance-result", order: 30, locale: NS }, ResultDock);
3048
3108
  } catch (error) {
3049
3109
  return report("result dock slot", error);
3050
3110
  }
@@ -3055,10 +3115,7 @@ function apply(ctx) {
3055
3115
  if (slots === void 0) return;
3056
3116
  return slots.inject("conversation.input.dock", () => {
3057
3117
  try {
3058
- return slots.register(
3059
- { name: "conversation.input.dock", id: "dsh-prompt-enhance-undo", order: 90, locale: NS },
3060
- UndoBar
3061
- );
3118
+ return slots.register({ name: "conversation.input.dock", id: "dsh-prompt-enhance-undo", order: 90, locale: NS }, UndoBar);
3062
3119
  } catch (error) {
3063
3120
  return report("undo bar slot", error);
3064
3121
  }