@surfishs/dsh-prompt-enhance 0.0.7 → 0.0.9
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/README.en.md +24 -18
- package/README.md +24 -18
- package/cordis.patch.yml +1 -1
- package/icon.svg +14 -0
- package/lib/client.js +343 -383
- package/lib/index.js +67 -56
- package/lib/index.js.map +3 -3
- package/package.json +26 -16
- package/src/client/ActionIcons.tsx +4 -17
- package/src/client/EnhanceButton.tsx +52 -48
- package/src/client/ResultDock.tsx +22 -9
- package/src/client/ResultPanel.tsx +83 -52
- package/src/client/SparkleFishIcon.tsx +25 -20
- package/src/client/UndoBar.tsx +11 -6
- package/src/client/enhance-client.ts +44 -40
- package/src/client/index.tsx +3 -12
- package/src/client/llm-catalog.ts +14 -16
- package/src/client/locales.ts +18 -4
- package/src/client/reasoning-options.ts +7 -15
- package/src/client/settings-page-controls.tsx +449 -0
- package/src/client/settings-page-copy.ts +112 -0
- package/src/client/settings-page-spec.ts +330 -0
- package/src/client/settings-page-styles.ts +161 -0
- package/src/client/settings-page.tsx +113 -1110
- package/src/client/settings-source.ts +41 -31
- package/src/client/settings.ts +17 -12
- package/src/client/shortcut.ts +7 -6
- package/src/client/useDockAlignment.ts +5 -15
- package/src/config.ts +84 -27
- package/src/context.ts +1 -5
- package/src/enhance-routes.ts +8 -8
- package/src/enhancer.ts +43 -34
- package/src/orchestrate.ts +19 -23
- package/src/prompts.ts +4 -4
- package/src/provider-catalog.ts +1 -1
- package/src/reasoning-cache.ts +4 -4
- package/src/reasoning-efforts.ts +4 -9
- package/src/settings-source.ts +37 -23
- package/src/shared/limits.ts +38 -0
- package/src/shared/normalize.ts +4 -1
- package/src/shared/protocol.ts +27 -23
- package/src/shared/reasoning.ts +1 -7
- package/src/shared/stream-text.ts +0 -6
- package/src/shared/validate.ts +3 -9
- package/docs/code-review-2026-09.md +0 -211
- package/docs/handoff-settings-page.md +0 -195
- package/docs/release-0.2.3.md +0 -47
- package/docs/release-0.2.4.md +0 -20
- package/docs/release-0.2.5.md +0 -28
- package/docs/release-0.2.6.md +0 -33
- package/docs/release-0.2.7.md +0 -22
- package/docs/release-0.3.0.md +0 -36
- package/docs/release-0.3.1.md +0 -50
- package/docs/release-0.3.2.md +0 -41
- package/docs/release-0.3.3.md +0 -53
- package/docs/release-0.3.4.md +0 -43
- package/src/client/SparkleIcon.tsx +0 -33
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",
|
|
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",
|
|
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",
|
|
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",
|
|
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",
|
|
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",
|
|
192
|
+
throw new EnhanceClientError({ code: "internal", params: { reason: "cancelled" } });
|
|
208
193
|
}
|
|
209
194
|
void error;
|
|
210
|
-
throw new EnhanceClientError({ code: "internal",
|
|
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",
|
|
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",
|
|
240
|
+
throw new EnhanceClientError({ code: "internal", params: { reason: "cancelled" } });
|
|
256
241
|
}
|
|
257
242
|
void error;
|
|
258
|
-
throw new EnhanceClientError({ code: "internal",
|
|
243
|
+
throw new EnhanceClientError({ code: "internal", params: { reason: "unreachable" } });
|
|
259
244
|
}
|
|
260
245
|
return readEnvelope(response);
|
|
261
246
|
}
|
|
@@ -264,25 +249,15 @@ async function requestEnhance(body, signal) {
|
|
|
264
249
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
265
250
|
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
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";
|
|
252
|
+
var FISH_TRANSFORM = "translate(6.4976 4.3528) scale(0.78502)";
|
|
253
|
+
var STAR_TRANSFORM = "translate(1.1944 0.7969) scale(0.60097)";
|
|
267
254
|
function SparkleFishIcon(props) {
|
|
268
255
|
const size = props.size ?? 15;
|
|
269
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
270
|
-
"
|
|
271
|
-
{
|
|
272
|
-
|
|
273
|
-
|
|
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
|
-
);
|
|
256
|
+
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: [
|
|
257
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("g", { transform: FISH_TRANSFORM, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: FISH_PATH, fill: "currentColor" }) }),
|
|
258
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: STAR_PATH, transform: STAR_TRANSFORM, fill: "currentColor" }),
|
|
259
|
+
props.spinning === true ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("animate", { attributeName: "opacity", values: "1;0.35;1", dur: "1.1s", repeatCount: "indefinite" }) : null
|
|
260
|
+
] });
|
|
286
261
|
}
|
|
287
262
|
|
|
288
263
|
// src/client/undo-stack.ts
|
|
@@ -460,12 +435,34 @@ function shortcutTarget() {
|
|
|
460
435
|
return fallback === void 0 ? void 0 : () => fallback.run();
|
|
461
436
|
}
|
|
462
437
|
|
|
463
|
-
// src/
|
|
464
|
-
var
|
|
438
|
+
// src/shared/defaults.ts
|
|
439
|
+
var DEFAULT_VALUES = {
|
|
465
440
|
enabled: true,
|
|
441
|
+
temperature: 0.3,
|
|
442
|
+
// A rewrite does not need deep reasoning, and the route default is expensive
|
|
443
|
+
// (measured: 2897 output tokens at `high` vs 252 at `off` for the same draft).
|
|
444
|
+
// Sent explicitly, because omitting the field inherits that route default.
|
|
445
|
+
reasoningEffort: "off",
|
|
446
|
+
maxOutputTokens: 8192,
|
|
466
447
|
maxInputChars: 12e3,
|
|
448
|
+
timeoutMs: 6e4,
|
|
449
|
+
systemPrompt: "",
|
|
450
|
+
strategyMode: "replace-default",
|
|
467
451
|
shortcut: "",
|
|
468
|
-
|
|
452
|
+
maxConcurrent: 2,
|
|
453
|
+
rateLimitPerMinute: 10,
|
|
454
|
+
streaming: true,
|
|
455
|
+
contextAware: true,
|
|
456
|
+
contextMaxMessages: 8,
|
|
457
|
+
contextMaxChars: 4e3
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
// src/client/settings.ts
|
|
461
|
+
var DEFAULT_CLIENT_SETTINGS = {
|
|
462
|
+
enabled: DEFAULT_VALUES.enabled,
|
|
463
|
+
maxInputChars: DEFAULT_VALUES.maxInputChars,
|
|
464
|
+
shortcut: DEFAULT_VALUES.shortcut,
|
|
465
|
+
streaming: DEFAULT_VALUES.streaming
|
|
469
466
|
};
|
|
470
467
|
var listeners2 = /* @__PURE__ */ new Set();
|
|
471
468
|
var current = DEFAULT_CLIENT_SETTINGS;
|
|
@@ -537,46 +534,52 @@ function EnhanceButton(props) {
|
|
|
537
534
|
const anyBusy = panel !== void 0 && panel.phase === "loading";
|
|
538
535
|
const otherBusy = anyBusy && !busy;
|
|
539
536
|
const empty = draft.trim() === "";
|
|
540
|
-
const start = (0, import_react2.useCallback)(
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
const
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
537
|
+
const start = (0, import_react2.useCallback)(
|
|
538
|
+
(overrideText) => {
|
|
539
|
+
const source = overrideText ?? draft;
|
|
540
|
+
if (anyBusy || source.trim() === "") return;
|
|
541
|
+
if (!settings.enabled) {
|
|
542
|
+
const disabled = t("error.disabled");
|
|
543
|
+
openError(uiKey, draft, { code: "rejected", localized: disabled });
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
const check = checkInputText(source, settings.maxInputChars);
|
|
547
|
+
if (!check.ok) {
|
|
548
|
+
const message = check.code === "empty" ? t("error.empty") : t("error.tooLong", { count: check.count, max: check.max });
|
|
549
|
+
openError(uiKey, source, { code: "rejected", localized: message });
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
if (occurrenceCount > 0) {
|
|
553
|
+
const occurrences = t("error.occurrences");
|
|
554
|
+
openError(uiKey, source, { code: "rejected", localized: occurrences });
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
if (phase !== "plain") {
|
|
558
|
+
const busyPhase = t("error.phase");
|
|
559
|
+
openError(uiKey, source, { code: "rejected", localized: busyPhase });
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
const controller = new AbortController();
|
|
563
|
+
openLoading({ sessionId: uiKey, original: source, abort: () => controller.abort() });
|
|
564
|
+
const settle = (result) => settleResult(uiKey, result);
|
|
565
|
+
const fail = (error) => {
|
|
566
|
+
const detail = error instanceof EnhanceClientError ? error.detail : { code: "internal", message: error instanceof Error ? error.message : String(error) };
|
|
567
|
+
settleError(uiKey, detail);
|
|
568
|
+
};
|
|
569
|
+
if (settings.streaming) {
|
|
570
|
+
requestEnhanceStream(
|
|
571
|
+
{ sessionId: wireId, text: source },
|
|
572
|
+
{
|
|
573
|
+
signal: controller.signal,
|
|
574
|
+
onDelta: (delta) => appendDelta(uiKey, delta)
|
|
575
|
+
}
|
|
576
|
+
).then(settle, fail);
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
requestEnhance({ sessionId: wireId, text: source }, controller.signal).then(settle, fail);
|
|
580
|
+
},
|
|
581
|
+
[anyBusy, draft, occurrenceCount, phase, settings, uiKey, wireId, t]
|
|
582
|
+
);
|
|
580
583
|
const runRef = (0, import_react2.useRef)(start);
|
|
581
584
|
(0, import_react2.useEffect)(() => {
|
|
582
585
|
runRef.current = start;
|
|
@@ -637,29 +640,16 @@ function icon(paths) {
|
|
|
637
640
|
);
|
|
638
641
|
}
|
|
639
642
|
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
|
-
]);
|
|
643
|
+
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
644
|
}
|
|
645
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
|
-
]);
|
|
646
|
+
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
647
|
}
|
|
651
648
|
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
|
-
]);
|
|
649
|
+
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
650
|
}
|
|
658
651
|
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
|
-
]);
|
|
652
|
+
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
653
|
}
|
|
664
654
|
|
|
665
655
|
// src/client/ResultPanel.tsx
|
|
@@ -675,6 +665,16 @@ var UPSTREAM_ERROR_KEYS = {
|
|
|
675
665
|
"tool-call": "error.upstream.toolCall",
|
|
676
666
|
"max-tokens": "error.upstream.maxTokens"
|
|
677
667
|
};
|
|
668
|
+
var CLIENT_ERROR_KEYS = {
|
|
669
|
+
unreachable: "error.client.unreachable",
|
|
670
|
+
malformed: "error.client.malformed",
|
|
671
|
+
refused: "error.client.refused",
|
|
672
|
+
"stream-closed": "error.client.streamClosed",
|
|
673
|
+
cancelled: "error.client.cancelled"
|
|
674
|
+
};
|
|
675
|
+
function isClientFailureReason(value) {
|
|
676
|
+
return typeof value === "string" && Object.hasOwn(CLIENT_ERROR_KEYS, value);
|
|
677
|
+
}
|
|
678
678
|
function localizedErrorMessage(t, code, params) {
|
|
679
679
|
if (code === "rejected" && typeof params?.count === "number" && typeof params?.max === "number") {
|
|
680
680
|
return t("error.tooLong", { count: params.count, max: params.max });
|
|
@@ -683,6 +683,9 @@ function localizedErrorMessage(t, code, params) {
|
|
|
683
683
|
const specific = UPSTREAM_ERROR_KEYS[params.reason];
|
|
684
684
|
if (specific !== void 0) return t(specific);
|
|
685
685
|
}
|
|
686
|
+
if (code === "internal" && isClientFailureReason(params?.reason)) {
|
|
687
|
+
return t(CLIENT_ERROR_KEYS[params.reason], params);
|
|
688
|
+
}
|
|
686
689
|
switch (code) {
|
|
687
690
|
case "rejected":
|
|
688
691
|
return t("error.rejected");
|
|
@@ -736,17 +739,17 @@ function ResultPanel(props) {
|
|
|
736
739
|
if (ok) setTimeout(() => setCopied("idle"), 2500);
|
|
737
740
|
};
|
|
738
741
|
if (navigator.clipboard !== void 0) {
|
|
739
|
-
navigator.clipboard.writeText(text).then(
|
|
742
|
+
navigator.clipboard.writeText(text).then(
|
|
743
|
+
() => done(true),
|
|
744
|
+
() => done(fallbackCopy(text))
|
|
745
|
+
);
|
|
740
746
|
return;
|
|
741
747
|
}
|
|
742
748
|
done(fallbackCopy(text));
|
|
743
749
|
}, [state.result]);
|
|
744
750
|
const formatMs = (ms) => ms < 1e3 ? `${ms}ms` : `${(ms / 1e3).toFixed(1)}s`;
|
|
745
751
|
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
|
-
];
|
|
752
|
+
const parts = [t("panel.tokens.input", { count: formatTokens(usage.inputTokens) }), t("panel.tokens.output", { count: formatTokens(usage.outputTokens) })];
|
|
750
753
|
if ((usage.cacheReadTokens ?? 0) > 0) {
|
|
751
754
|
parts.push(t("panel.tokens.cacheRead", { count: formatTokens(usage.cacheReadTokens ?? 0) }));
|
|
752
755
|
}
|
|
@@ -837,7 +840,6 @@ function useDockAlignment(active) {
|
|
|
837
840
|
const parent = root.parentElement;
|
|
838
841
|
if (parent === null) return;
|
|
839
842
|
root.style.transform = "";
|
|
840
|
-
const previousMargin = parseFloat(root.style.marginLeft) || 0;
|
|
841
843
|
const rootRect = root.getBoundingClientRect();
|
|
842
844
|
const editors = Array.from(document.querySelectorAll('textarea, [contenteditable="true"], [role="textbox"]'));
|
|
843
845
|
const editor = editors.find((node2) => {
|
|
@@ -910,8 +912,14 @@ function ResultDock(props) {
|
|
|
910
912
|
return typeof value === "string" ? value : "";
|
|
911
913
|
});
|
|
912
914
|
const useSession = props.useSession;
|
|
913
|
-
const sessionRunning = useSession === void 0 ? false :
|
|
914
|
-
|
|
915
|
+
const sessionRunning = useSession === void 0 ? false : (
|
|
916
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
917
|
+
Boolean(useSession((state) => state.running))
|
|
918
|
+
);
|
|
919
|
+
const sessionQueued = useSession === void 0 ? 0 : (
|
|
920
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
921
|
+
Number(useSession((state) => state.queue?.length ?? 0))
|
|
922
|
+
);
|
|
915
923
|
const entry = peekUndo(uiKey);
|
|
916
924
|
const applied = entry !== void 0 && entry.applied === draft;
|
|
917
925
|
const prevSession = (0, import_react5.useRef)({ running: sessionRunning, queued: sessionQueued });
|
|
@@ -1087,6 +1095,11 @@ var zh = {
|
|
|
1087
1095
|
"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
1096
|
"error.upstream": "\u6A21\u578B\u670D\u52A1\u8FD4\u56DE\u9519\u8BEF\uFF0C\u8BF7\u91CD\u8BD5\uFF1B\u539F\u8F93\u5165\u672A\u6539\u52A8\u3002",
|
|
1089
1097
|
"error.internal": "\u589E\u5F3A\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\uFF1B\u539F\u8F93\u5165\u672A\u6539\u52A8\u3002",
|
|
1098
|
+
"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",
|
|
1099
|
+
"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",
|
|
1100
|
+
"error.client.refused": "\u5BBF\u4E3B\u670D\u52A1\u62D2\u7EDD\u4E86\u8BF7\u6C42\uFF08HTTP {status}\uFF09\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002",
|
|
1101
|
+
"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",
|
|
1102
|
+
"error.client.cancelled": "\u5DF2\u53D6\u6D88\u589E\u5F3A\uFF1B\u539F\u8F93\u5165\u672A\u6539\u52A8\u3002",
|
|
1090
1103
|
"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
1104
|
"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
1105
|
"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",
|
|
@@ -1228,6 +1241,11 @@ var en = {
|
|
|
1228
1241
|
"error.effortUnsupported": 'This model does not support the selected reasoning effort "{effort}". Choose another tier, or use "follow provider default".',
|
|
1229
1242
|
"error.upstream": "The model provider returned an error. Retry; your draft is untouched.",
|
|
1230
1243
|
"error.internal": "Enhancement failed. Retry; your draft is untouched.",
|
|
1244
|
+
"error.client.unreachable": "Cannot reach the host service \u2014 make sure dsh web is running, then retry.",
|
|
1245
|
+
"error.client.malformed": "The host returned data that could not be parsed. Retry; your draft is untouched.",
|
|
1246
|
+
"error.client.refused": "The host refused the request (HTTP {status}). Retry later.",
|
|
1247
|
+
"error.client.streamClosed": "The host closed the enhance stream early. Retry; your draft is untouched.",
|
|
1248
|
+
"error.client.cancelled": "The enhancement was cancelled; your draft is untouched.",
|
|
1231
1249
|
"error.rateLimit": "Too many requests \u2014 at most {limit} enhancements per minute; retry in {retryAfterSeconds} seconds.",
|
|
1232
1250
|
"error.concurrencyLimit": "{max} enhancements are already running \u2014 wait for one to finish, then retry.",
|
|
1233
1251
|
"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.",
|
|
@@ -1797,21 +1815,27 @@ function installClientSettingsSource(ctx, options) {
|
|
|
1797
1815
|
}
|
|
1798
1816
|
};
|
|
1799
1817
|
bind();
|
|
1800
|
-
ctx.effect(
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1818
|
+
ctx.effect(
|
|
1819
|
+
() => () => {
|
|
1820
|
+
try {
|
|
1821
|
+
unsubscribeForm?.();
|
|
1822
|
+
} catch {
|
|
1823
|
+
}
|
|
1824
|
+
},
|
|
1825
|
+
"dsh-prompt-enhance: settings form mirror"
|
|
1826
|
+
);
|
|
1806
1827
|
try {
|
|
1807
1828
|
const watch = forms.describe?.()?.subscribe?.(() => bind());
|
|
1808
1829
|
if (typeof watch === "function") {
|
|
1809
|
-
ctx.effect(
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1830
|
+
ctx.effect(
|
|
1831
|
+
() => () => {
|
|
1832
|
+
try {
|
|
1833
|
+
watch();
|
|
1834
|
+
} catch {
|
|
1835
|
+
}
|
|
1836
|
+
},
|
|
1837
|
+
"dsh-prompt-enhance: settings namespace watch"
|
|
1838
|
+
);
|
|
1815
1839
|
}
|
|
1816
1840
|
} catch {
|
|
1817
1841
|
}
|
|
@@ -1836,12 +1860,15 @@ function installClientSettingsSource(ctx, options) {
|
|
|
1836
1860
|
} catch {
|
|
1837
1861
|
unsubscribe = void 0;
|
|
1838
1862
|
}
|
|
1839
|
-
ctx.effect(
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1863
|
+
ctx.effect(
|
|
1864
|
+
() => () => {
|
|
1865
|
+
try {
|
|
1866
|
+
unsubscribe?.();
|
|
1867
|
+
} catch {
|
|
1868
|
+
}
|
|
1869
|
+
},
|
|
1870
|
+
"dsh-prompt-enhance: settings binder mirror"
|
|
1871
|
+
);
|
|
1845
1872
|
});
|
|
1846
1873
|
ctx.inject(["settingsScope"], (scopeCtx) => {
|
|
1847
1874
|
const scopeCtxLike = scopeCtx;
|
|
@@ -1860,88 +1887,20 @@ function installClientSettingsSource(ctx, options) {
|
|
|
1860
1887
|
} catch {
|
|
1861
1888
|
unsubscribe = void 0;
|
|
1862
1889
|
}
|
|
1863
|
-
ctx.effect(
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1890
|
+
ctx.effect(
|
|
1891
|
+
() => () => {
|
|
1892
|
+
try {
|
|
1893
|
+
unsubscribe?.();
|
|
1894
|
+
} catch {
|
|
1895
|
+
}
|
|
1896
|
+
},
|
|
1897
|
+
"dsh-prompt-enhance: settings scope mirror"
|
|
1898
|
+
);
|
|
1869
1899
|
});
|
|
1870
1900
|
}
|
|
1871
1901
|
|
|
1872
1902
|
// src/client/settings-page.tsx
|
|
1873
|
-
var
|
|
1874
|
-
|
|
1875
|
-
// src/shared/defaults.ts
|
|
1876
|
-
var DEFAULT_VALUES = {
|
|
1877
|
-
enabled: true,
|
|
1878
|
-
temperature: 0.3,
|
|
1879
|
-
// A rewrite does not need deep reasoning, and the route default is expensive
|
|
1880
|
-
// (measured: 2897 output tokens at `high` vs 252 at `off` for the same draft).
|
|
1881
|
-
// Sent explicitly, because omitting the field inherits that route default.
|
|
1882
|
-
reasoningEffort: "off",
|
|
1883
|
-
maxOutputTokens: 8192,
|
|
1884
|
-
maxInputChars: 12e3,
|
|
1885
|
-
timeoutMs: 6e4,
|
|
1886
|
-
systemPrompt: "",
|
|
1887
|
-
strategyMode: "replace-default",
|
|
1888
|
-
shortcut: "",
|
|
1889
|
-
maxConcurrent: 2,
|
|
1890
|
-
rateLimitPerMinute: 10,
|
|
1891
|
-
streaming: true,
|
|
1892
|
-
contextAware: true,
|
|
1893
|
-
contextMaxMessages: 8,
|
|
1894
|
-
contextMaxChars: 4e3
|
|
1895
|
-
};
|
|
1896
|
-
|
|
1897
|
-
// src/shared/reasoning.ts
|
|
1898
|
-
var REASONING_EFFORTS_ENDPOINT = "/dsh-prompt-enhance/reasoning-efforts";
|
|
1899
|
-
|
|
1900
|
-
// src/client/reasoning-options.ts
|
|
1901
|
-
function effortOf(value) {
|
|
1902
|
-
if (value === null || typeof value !== "object") return void 0;
|
|
1903
|
-
const record = value;
|
|
1904
|
-
if (typeof record.id !== "string" || record.id === "" || typeof record.name !== "string" || record.name === "") return void 0;
|
|
1905
|
-
return {
|
|
1906
|
-
id: record.id,
|
|
1907
|
-
name: record.name,
|
|
1908
|
-
...typeof record.description === "string" && record.description !== "" ? { description: record.description } : {}
|
|
1909
|
-
};
|
|
1910
|
-
}
|
|
1911
|
-
function capabilitiesOf(value) {
|
|
1912
|
-
if (value === null || typeof value !== "object") return { efforts: [], source: "unavailable", reason: "resolve-failed" };
|
|
1913
|
-
const record = value;
|
|
1914
|
-
const source = record.source === "resolved" || record.source === "default" || record.source === "unavailable" ? record.source : "unavailable";
|
|
1915
|
-
const efforts = Array.isArray(record.efforts) ? record.efforts.map(effortOf).filter((effort) => effort !== void 0) : [];
|
|
1916
|
-
const reason = typeof record.reason === "string" ? record.reason : void 0;
|
|
1917
|
-
if (source !== "unavailable" && efforts.length === 0) return { efforts: [], source: "unavailable", reason: "no-efforts" };
|
|
1918
|
-
return {
|
|
1919
|
-
efforts,
|
|
1920
|
-
source,
|
|
1921
|
-
...typeof record.defaultEffort === "string" && record.defaultEffort !== "" ? { defaultEffort: record.defaultEffort } : {},
|
|
1922
|
-
...reason === void 0 ? {} : { reason }
|
|
1923
|
-
};
|
|
1924
|
-
}
|
|
1925
|
-
async function fetchReasoningCapabilities(provider, model, options = {}) {
|
|
1926
|
-
const url = new URL(REASONING_EFFORTS_ENDPOINT, globalThis.location?.origin ?? "http://127.0.0.1");
|
|
1927
|
-
if (provider !== void 0 && model !== void 0) {
|
|
1928
|
-
url.searchParams.set("provider", provider);
|
|
1929
|
-
url.searchParams.set("model", model);
|
|
1930
|
-
}
|
|
1931
|
-
if (options.refresh === true) url.searchParams.set("refresh", "1");
|
|
1932
|
-
try {
|
|
1933
|
-
const response = await fetch(url, { signal: options.signal, headers: { accept: "application/json" } });
|
|
1934
|
-
if (!response.ok) return { efforts: [], source: "unavailable", reason: "resolve-failed" };
|
|
1935
|
-
const body = await response.json();
|
|
1936
|
-
const envelope = body;
|
|
1937
|
-
if (envelope === null || envelope === void 0 || envelope.ok !== true) {
|
|
1938
|
-
return { efforts: [], source: "unavailable", reason: "resolve-failed" };
|
|
1939
|
-
}
|
|
1940
|
-
return capabilitiesOf(envelope.value);
|
|
1941
|
-
} catch {
|
|
1942
|
-
return { efforts: [], source: "unavailable", reason: "resolve-failed" };
|
|
1943
|
-
}
|
|
1944
|
-
}
|
|
1903
|
+
var import_react9 = require("react");
|
|
1945
1904
|
|
|
1946
1905
|
// src/client/llm-catalog.ts
|
|
1947
1906
|
var import_react7 = require("react");
|
|
@@ -1972,12 +1931,16 @@ function endpoint(path, params = {}) {
|
|
|
1972
1931
|
async function fetchProviders(signal) {
|
|
1973
1932
|
const value = await getJson(endpoint(LLM_PROVIDERS_ENDPOINT), signal);
|
|
1974
1933
|
if (value === void 0 || !Array.isArray(value.providers)) return void 0;
|
|
1975
|
-
return value.providers.filter(
|
|
1934
|
+
return value.providers.filter(
|
|
1935
|
+
(entry) => entry !== null && typeof entry === "object" && typeof entry.id === "string" && entry.id !== "" && typeof entry.name === "string" && entry.name !== "" && typeof entry.registered === "boolean"
|
|
1936
|
+
);
|
|
1976
1937
|
}
|
|
1977
1938
|
async function fetchModels(provider, signal) {
|
|
1978
1939
|
const value = await getJson(endpoint(LLM_MODELS_ENDPOINT, { provider }), signal);
|
|
1979
1940
|
if (value === void 0 || !Array.isArray(value.models)) return void 0;
|
|
1980
|
-
const models = value.models.filter(
|
|
1941
|
+
const models = value.models.filter(
|
|
1942
|
+
(entry) => entry !== null && typeof entry === "object" && typeof entry.id === "string" && entry.id !== "" && typeof entry.name === "string" && entry.name !== ""
|
|
1943
|
+
).map((entry) => ({
|
|
1981
1944
|
id: entry.id,
|
|
1982
1945
|
name: entry.name,
|
|
1983
1946
|
...typeof entry.description === "string" && entry.description !== "" ? { description: entry.description } : {}
|
|
@@ -2077,21 +2040,12 @@ function useLlmRouting(provider, model) {
|
|
|
2077
2040
|
};
|
|
2078
2041
|
}
|
|
2079
2042
|
|
|
2080
|
-
// src/client/settings-page.
|
|
2043
|
+
// src/client/settings-page-spec.ts
|
|
2081
2044
|
var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
2082
|
-
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
2083
2045
|
var SETTINGS_SECTION_SLOT = "settings.section";
|
|
2084
2046
|
var SETTINGS_SECTION_ID = "dsh-prompt-enhance";
|
|
2085
2047
|
var SETTINGS_SECTION_ORDER = 70;
|
|
2086
2048
|
var SETTINGS_SECTION_LABEL = "\u63D0\u793A\u8BCD\u589E\u5F3A";
|
|
2087
|
-
function sectionTitle(getLocale) {
|
|
2088
|
-
try {
|
|
2089
|
-
const t = getLocale?.()?.bind(NS);
|
|
2090
|
-
return t === void 0 ? SETTINGS_SECTION_LABEL : t("settings.title");
|
|
2091
|
-
} catch {
|
|
2092
|
-
return SETTINGS_SECTION_LABEL;
|
|
2093
|
-
}
|
|
2094
|
-
}
|
|
2095
2049
|
var SETTINGS_ROW_CONFIG_SLOT = "plugins.row.config";
|
|
2096
2050
|
var SETTINGS_NAMESPACE = "dsh-prompt-enhance";
|
|
2097
2051
|
var SETTINGS_BUNDLE = "@surfishs/dsh-prompt-enhance";
|
|
@@ -2154,7 +2108,10 @@ function descriptorOf(row) {
|
|
|
2154
2108
|
case "boolean":
|
|
2155
2109
|
return settingsBooleanField(row.key);
|
|
2156
2110
|
case "strategy":
|
|
2157
|
-
return settingsEnumField(
|
|
2111
|
+
return settingsEnumField(
|
|
2112
|
+
row.key,
|
|
2113
|
+
STRATEGY_OPTIONS.map((option) => option.value)
|
|
2114
|
+
);
|
|
2158
2115
|
case "reasoning":
|
|
2159
2116
|
return (0, import_dsh_client_ui_primitives.settingsTextField)(row.key);
|
|
2160
2117
|
default:
|
|
@@ -2165,6 +2122,38 @@ var FIELD_SPECS = ROWS.map((row) => descriptorOf(row));
|
|
|
2165
2122
|
function createSettingsForm(scope) {
|
|
2166
2123
|
return new import_dsh_client_ui_primitives.SettingsFormModel(scope, FIELD_SPECS);
|
|
2167
2124
|
}
|
|
2125
|
+
function viewOf(snapshot, key) {
|
|
2126
|
+
const value = snapshot[key];
|
|
2127
|
+
if (value === null || typeof value !== "object") return { text: "", overridden: false, invalid: false };
|
|
2128
|
+
const field = value;
|
|
2129
|
+
return {
|
|
2130
|
+
text: typeof field.text === "string" ? field.text : "",
|
|
2131
|
+
overridden: field.overridden === true,
|
|
2132
|
+
invalid: field.invalid === true
|
|
2133
|
+
};
|
|
2134
|
+
}
|
|
2135
|
+
function defaultTextOf(key) {
|
|
2136
|
+
const descriptor = FIELD_SPECS.find((item) => item.field === key);
|
|
2137
|
+
const fallback = DEFAULT_VALUES[key];
|
|
2138
|
+
if (descriptor === void 0 || fallback === void 0) return "";
|
|
2139
|
+
try {
|
|
2140
|
+
return descriptor.format(fallback);
|
|
2141
|
+
} catch {
|
|
2142
|
+
return "";
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
function atDefaultValue(key, text) {
|
|
2146
|
+
const fallback = DEFAULT_VALUES[key];
|
|
2147
|
+
if (fallback === void 0) return text.trim() === "";
|
|
2148
|
+
if (typeof fallback === "boolean") return text.trim() === String(fallback);
|
|
2149
|
+
if (typeof fallback === "number") {
|
|
2150
|
+
const parsed = Number(text.trim());
|
|
2151
|
+
return Number.isFinite(parsed) && parsed === fallback;
|
|
2152
|
+
}
|
|
2153
|
+
return text.trim() === String(fallback);
|
|
2154
|
+
}
|
|
2155
|
+
|
|
2156
|
+
// src/client/settings-page-copy.ts
|
|
2168
2157
|
var ZH_COPY = zh;
|
|
2169
2158
|
function translator(t) {
|
|
2170
2159
|
if (typeof t === "function") return t;
|
|
@@ -2218,6 +2207,61 @@ function pageCopy(t) {
|
|
|
2218
2207
|
interpolate: (key, params) => t(key, params)
|
|
2219
2208
|
};
|
|
2220
2209
|
}
|
|
2210
|
+
|
|
2211
|
+
// src/client/settings-page-controls.tsx
|
|
2212
|
+
var import_react8 = require("react");
|
|
2213
|
+
var import_dsh_client_ui_primitives2 = require("@deepseek-ai/dsh-client-ui-primitives");
|
|
2214
|
+
|
|
2215
|
+
// src/shared/reasoning.ts
|
|
2216
|
+
var REASONING_EFFORTS_ENDPOINT = "/dsh-prompt-enhance/reasoning-efforts";
|
|
2217
|
+
|
|
2218
|
+
// src/client/reasoning-options.ts
|
|
2219
|
+
function effortOf(value) {
|
|
2220
|
+
if (value === null || typeof value !== "object") return void 0;
|
|
2221
|
+
const record = value;
|
|
2222
|
+
if (typeof record.id !== "string" || record.id === "" || typeof record.name !== "string" || record.name === "") return void 0;
|
|
2223
|
+
return {
|
|
2224
|
+
id: record.id,
|
|
2225
|
+
name: record.name,
|
|
2226
|
+
...typeof record.description === "string" && record.description !== "" ? { description: record.description } : {}
|
|
2227
|
+
};
|
|
2228
|
+
}
|
|
2229
|
+
function capabilitiesOf(value) {
|
|
2230
|
+
if (value === null || typeof value !== "object") return { efforts: [], source: "unavailable", reason: "resolve-failed" };
|
|
2231
|
+
const record = value;
|
|
2232
|
+
const source = record.source === "resolved" || record.source === "default" || record.source === "unavailable" ? record.source : "unavailable";
|
|
2233
|
+
const efforts = Array.isArray(record.efforts) ? record.efforts.map(effortOf).filter((effort) => effort !== void 0) : [];
|
|
2234
|
+
const reason = typeof record.reason === "string" ? record.reason : void 0;
|
|
2235
|
+
if (source !== "unavailable" && efforts.length === 0) return { efforts: [], source: "unavailable", reason: "no-efforts" };
|
|
2236
|
+
return {
|
|
2237
|
+
efforts,
|
|
2238
|
+
source,
|
|
2239
|
+
...typeof record.defaultEffort === "string" && record.defaultEffort !== "" ? { defaultEffort: record.defaultEffort } : {},
|
|
2240
|
+
...reason === void 0 ? {} : { reason }
|
|
2241
|
+
};
|
|
2242
|
+
}
|
|
2243
|
+
async function fetchReasoningCapabilities(provider, model, options = {}) {
|
|
2244
|
+
const url = new URL(REASONING_EFFORTS_ENDPOINT, globalThis.location?.origin ?? "http://127.0.0.1");
|
|
2245
|
+
if (provider !== void 0 && model !== void 0) {
|
|
2246
|
+
url.searchParams.set("provider", provider);
|
|
2247
|
+
url.searchParams.set("model", model);
|
|
2248
|
+
}
|
|
2249
|
+
if (options.refresh === true) url.searchParams.set("refresh", "1");
|
|
2250
|
+
try {
|
|
2251
|
+
const response = await fetch(url, { signal: options.signal, headers: { accept: "application/json" } });
|
|
2252
|
+
if (!response.ok) return { efforts: [], source: "unavailable", reason: "resolve-failed" };
|
|
2253
|
+
const body = await response.json();
|
|
2254
|
+
const envelope = body;
|
|
2255
|
+
if (envelope === null || envelope === void 0 || envelope.ok !== true) {
|
|
2256
|
+
return { efforts: [], source: "unavailable", reason: "resolve-failed" };
|
|
2257
|
+
}
|
|
2258
|
+
return capabilitiesOf(envelope.value);
|
|
2259
|
+
} catch {
|
|
2260
|
+
return { efforts: [], source: "unavailable", reason: "resolve-failed" };
|
|
2261
|
+
}
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
// src/client/settings-page-styles.ts
|
|
2221
2265
|
var ROW_STYLE = { display: "flex", flexDirection: "column", gap: 6, padding: "12px 0" };
|
|
2222
2266
|
var HEAD_STYLE = { display: "flex", alignItems: "center", gap: 8 };
|
|
2223
2267
|
var LABEL_STYLE = {
|
|
@@ -2296,7 +2340,7 @@ var REPOSITORY_URL = "https://github.com/surfishs/dsh-prompt-enhance";
|
|
|
2296
2340
|
var NPM_URL = "https://www.npmjs.com/package/@surfishs/dsh-prompt-enhance";
|
|
2297
2341
|
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";
|
|
2298
2342
|
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";
|
|
2299
|
-
var PLUGIN_VERSION = true ? "0.0.
|
|
2343
|
+
var PLUGIN_VERSION = true ? "0.0.9" : "0.0.0";
|
|
2300
2344
|
var HEADER_STYLE = { display: "flex", flexDirection: "column", gap: 12, padding: "2px 0" };
|
|
2301
2345
|
var HEADER_ROW_STYLE = { display: "flex", alignItems: "center", gap: 10, flexWrap: "wrap" };
|
|
2302
2346
|
var HEADER_TITLE_STYLE = {
|
|
@@ -2341,83 +2385,18 @@ var HEADER_DESCRIPTION_STYLE = {
|
|
|
2341
2385
|
textWrap: "pretty",
|
|
2342
2386
|
maxWidth: "72ch"
|
|
2343
2387
|
};
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: HEADER_TITLE_STYLE, children: props.title }),
|
|
2348
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("a", { href: REPOSITORY_URL, target: "_blank", rel: "noreferrer", style: HEADER_LINK_STYLE, children: [
|
|
2349
|
-
/* @__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 }) }),
|
|
2350
|
-
"GitHub"
|
|
2351
|
-
] }),
|
|
2352
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("a", { href: NPM_URL, target: "_blank", rel: "noreferrer", style: HEADER_LINK_STYLE, children: [
|
|
2353
|
-
/* @__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 }) }),
|
|
2354
|
-
"npm"
|
|
2355
|
-
] }),
|
|
2356
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { style: HEADER_VERSION_STYLE, children: [
|
|
2357
|
-
"v",
|
|
2358
|
-
props.version
|
|
2359
|
-
] })
|
|
2360
|
-
] }),
|
|
2361
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: HEADER_DESCRIPTION_STYLE, children: props.description })
|
|
2362
|
-
] });
|
|
2363
|
-
}
|
|
2364
|
-
function viewOf(snapshot, key) {
|
|
2365
|
-
const value = snapshot[key];
|
|
2366
|
-
if (value === null || typeof value !== "object") return { text: "", overridden: false, invalid: false };
|
|
2367
|
-
const field = value;
|
|
2368
|
-
return {
|
|
2369
|
-
text: typeof field.text === "string" ? field.text : "",
|
|
2370
|
-
overridden: field.overridden === true,
|
|
2371
|
-
invalid: field.invalid === true
|
|
2372
|
-
};
|
|
2373
|
-
}
|
|
2374
|
-
function defaultTextOf(key) {
|
|
2375
|
-
const descriptor = FIELD_SPECS.find((item) => item.field === key);
|
|
2376
|
-
const fallback = DEFAULT_VALUES[key];
|
|
2377
|
-
if (descriptor === void 0 || fallback === void 0) return "";
|
|
2378
|
-
try {
|
|
2379
|
-
return descriptor.format(fallback);
|
|
2380
|
-
} catch {
|
|
2381
|
-
return "";
|
|
2382
|
-
}
|
|
2383
|
-
}
|
|
2384
|
-
function atDefaultValue(key, text) {
|
|
2385
|
-
const fallback = DEFAULT_VALUES[key];
|
|
2386
|
-
if (fallback === void 0) return text.trim() === "";
|
|
2387
|
-
if (typeof fallback === "boolean") return text.trim() === String(fallback);
|
|
2388
|
-
if (typeof fallback === "number") {
|
|
2389
|
-
const parsed = Number(text.trim());
|
|
2390
|
-
return Number.isFinite(parsed) && parsed === fallback;
|
|
2391
|
-
}
|
|
2392
|
-
return text.trim() === String(fallback);
|
|
2393
|
-
}
|
|
2388
|
+
|
|
2389
|
+
// src/client/settings-page-controls.tsx
|
|
2390
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
2394
2391
|
function OverrideActions(props) {
|
|
2395
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2396
|
-
"button",
|
|
2397
|
-
{
|
|
2398
|
-
type: "button",
|
|
2399
|
-
className: "dsh-pe-chip-reset",
|
|
2400
|
-
style: { ...RESET_STYLE, ...props.disabled ? { opacity: 0.5, cursor: "default" } : {} },
|
|
2401
|
-
disabled: props.disabled,
|
|
2402
|
-
onClick: props.onReset,
|
|
2403
|
-
children: props.copy.labels.reset
|
|
2404
|
-
}
|
|
2405
|
-
);
|
|
2392
|
+
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 });
|
|
2406
2393
|
}
|
|
2407
2394
|
function BooleanRow(props) {
|
|
2408
2395
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: ROW_STYLE, children: [
|
|
2409
2396
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: HEAD_STYLE, children: [
|
|
2410
2397
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: LABEL_STYLE, children: props.label }),
|
|
2411
2398
|
props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null,
|
|
2412
|
-
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2413
|
-
import_dsh_client_ui_primitives.Switch,
|
|
2414
|
-
{
|
|
2415
|
-
checked: props.view.text === "true",
|
|
2416
|
-
disabled: props.disabled,
|
|
2417
|
-
label: props.label,
|
|
2418
|
-
onChange: (next) => props.onEdit(next ? "true" : "false")
|
|
2419
|
-
}
|
|
2420
|
-
)
|
|
2399
|
+
/* @__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") })
|
|
2421
2400
|
] }),
|
|
2422
2401
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: HINT_STYLE, children: props.hint })
|
|
2423
2402
|
] });
|
|
@@ -2429,7 +2408,7 @@ function ChoiceRow(props) {
|
|
|
2429
2408
|
props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null
|
|
2430
2409
|
] }),
|
|
2431
2410
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2432
|
-
|
|
2411
|
+
import_dsh_client_ui_primitives2.SegmentedControl,
|
|
2433
2412
|
{
|
|
2434
2413
|
id: props.id,
|
|
2435
2414
|
className: "dsh-pe-segmented-labels",
|
|
@@ -2470,11 +2449,7 @@ function ReasoningRow(props) {
|
|
|
2470
2449
|
feedbackTimer.current = void 0;
|
|
2471
2450
|
}, 3e3);
|
|
2472
2451
|
};
|
|
2473
|
-
fetchReasoningCapabilities(
|
|
2474
|
-
props.provider === "" ? void 0 : props.provider,
|
|
2475
|
-
props.model === "" ? void 0 : props.model,
|
|
2476
|
-
{ refresh: force, signal: controller.signal }
|
|
2477
|
-
).then((answer) => {
|
|
2452
|
+
fetchReasoningCapabilities(props.provider === "" ? void 0 : props.provider, props.model === "" ? void 0 : props.model, { refresh: force, signal: controller.signal }).then((answer) => {
|
|
2478
2453
|
if (controller.signal.aborted) return;
|
|
2479
2454
|
setCapabilities(answer);
|
|
2480
2455
|
setPhase("ready");
|
|
@@ -2527,21 +2502,11 @@ function ReasoningRow(props) {
|
|
|
2527
2502
|
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: ROW_STYLE, children: [
|
|
2528
2503
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { style: HEAD_STYLE, children: [
|
|
2529
2504
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: LABEL_STYLE, children: props.label }),
|
|
2530
|
-
phase === "ready" || refreshing ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2531
|
-
"button",
|
|
2532
|
-
{
|
|
2533
|
-
type: "button",
|
|
2534
|
-
className: "dsh-pe-chip-refresh",
|
|
2535
|
-
style: { ...REFRESH_STYLE, opacity: props.disabled || refreshing ? 0.5 : 1 },
|
|
2536
|
-
disabled: props.disabled || refreshing,
|
|
2537
|
-
onClick: refresh,
|
|
2538
|
-
children: props.copy.choice(refreshing ? "settings.reasoning.refreshing" : "settings.reasoning.refresh")
|
|
2539
|
-
}
|
|
2540
|
-
) : null,
|
|
2505
|
+
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,
|
|
2541
2506
|
props.view.overridden ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(OverrideActions, { copy: props.copy, disabled: props.disabled, onReset: props.onReset }) : null
|
|
2542
2507
|
] }),
|
|
2543
2508
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2544
|
-
|
|
2509
|
+
import_dsh_client_ui_primitives2.SegmentedControl,
|
|
2545
2510
|
{
|
|
2546
2511
|
id: props.id,
|
|
2547
2512
|
className: "dsh-pe-segmented-labels",
|
|
@@ -2638,15 +2603,7 @@ function ModelRow(props) {
|
|
|
2638
2603
|
]
|
|
2639
2604
|
}
|
|
2640
2605
|
),
|
|
2641
|
-
showCustom ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
2642
|
-
TextControl,
|
|
2643
|
-
{
|
|
2644
|
-
value: current2,
|
|
2645
|
-
placeholder: props.copy.choice("settings.routing.customPlaceholder"),
|
|
2646
|
-
disabled: props.disabled,
|
|
2647
|
-
onChange: props.onEdit
|
|
2648
|
-
}
|
|
2649
|
-
) : null,
|
|
2606
|
+
showCustom ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(TextControl, { value: current2, placeholder: props.copy.choice("settings.routing.customPlaceholder"), disabled: props.disabled, onChange: props.onEdit }) : null,
|
|
2650
2607
|
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: HINT_STYLE, children: props.hint }),
|
|
2651
2608
|
props.routing.models.loading ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: STATUS_STYLE, children: props.copy.choice("settings.routing.modelsLoading") }) : null,
|
|
2652
2609
|
props.routing.models.failed && !showCustom ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: STATUS_STYLE, children: props.copy.choice("settings.routing.modelsFailed") }) : null,
|
|
@@ -2717,6 +2674,37 @@ function ValueRow(props) {
|
|
|
2717
2674
|
invalid ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { style: INVALID_STYLE, children: props.copy.labels.invalidNumber }) : null
|
|
2718
2675
|
] });
|
|
2719
2676
|
}
|
|
2677
|
+
|
|
2678
|
+
// src/client/settings-page.tsx
|
|
2679
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
2680
|
+
function sectionTitle(getLocale) {
|
|
2681
|
+
try {
|
|
2682
|
+
const t = getLocale?.()?.bind(NS);
|
|
2683
|
+
return t === void 0 ? SETTINGS_SECTION_LABEL : t("settings.title");
|
|
2684
|
+
} catch {
|
|
2685
|
+
return SETTINGS_SECTION_LABEL;
|
|
2686
|
+
}
|
|
2687
|
+
}
|
|
2688
|
+
function PageHeader(props) {
|
|
2689
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { style: HEADER_STYLE, children: [
|
|
2690
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { style: HEADER_ROW_STYLE, children: [
|
|
2691
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { style: HEADER_TITLE_STYLE, children: props.title }),
|
|
2692
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("a", { href: REPOSITORY_URL, target: "_blank", rel: "noreferrer", style: HEADER_LINK_STYLE, children: [
|
|
2693
|
+
/* @__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 }) }),
|
|
2694
|
+
"GitHub"
|
|
2695
|
+
] }),
|
|
2696
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("a", { href: NPM_URL, target: "_blank", rel: "noreferrer", style: HEADER_LINK_STYLE, children: [
|
|
2697
|
+
/* @__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 }) }),
|
|
2698
|
+
"npm"
|
|
2699
|
+
] }),
|
|
2700
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { style: HEADER_VERSION_STYLE, children: [
|
|
2701
|
+
"v",
|
|
2702
|
+
props.version
|
|
2703
|
+
] })
|
|
2704
|
+
] }),
|
|
2705
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { style: HEADER_DESCRIPTION_STYLE, children: props.description })
|
|
2706
|
+
] });
|
|
2707
|
+
}
|
|
2720
2708
|
function SettingsRow(props) {
|
|
2721
2709
|
const shared = {
|
|
2722
2710
|
id: `dsh-prompt-enhance-${props.row.key}`,
|
|
@@ -2731,29 +2719,29 @@ function SettingsRow(props) {
|
|
|
2731
2719
|
};
|
|
2732
2720
|
switch (props.row.kind) {
|
|
2733
2721
|
case "boolean":
|
|
2734
|
-
return /* @__PURE__ */ (0,
|
|
2722
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(BooleanRow, { ...shared });
|
|
2735
2723
|
case "strategy":
|
|
2736
|
-
return /* @__PURE__ */ (0,
|
|
2724
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ChoiceRow, { ...shared, options: STRATEGY_OPTIONS.map((option) => ({ value: option.value, label: props.copy.choice(option.label) })) });
|
|
2737
2725
|
case "reasoning":
|
|
2738
|
-
return /* @__PURE__ */ (0,
|
|
2726
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ReasoningRow, { ...shared, provider: props.reasoningPair.provider, model: props.reasoningPair.model });
|
|
2739
2727
|
case "provider":
|
|
2740
|
-
return /* @__PURE__ */ (0,
|
|
2728
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ProviderRow, { ...shared, routing: props.routing });
|
|
2741
2729
|
case "model":
|
|
2742
|
-
return /* @__PURE__ */ (0,
|
|
2730
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ModelRow, { ...shared, routing: props.routing, providerValue: props.providerValue });
|
|
2743
2731
|
default:
|
|
2744
|
-
return /* @__PURE__ */ (0,
|
|
2732
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ValueRow, { ...shared, numeric: props.row.kind === "number", placeholder: props.copy.placeholder(props.row) });
|
|
2745
2733
|
}
|
|
2746
2734
|
}
|
|
2747
2735
|
function SettingsRows(props) {
|
|
2748
2736
|
const provider = viewOf(props.state, "provider").text.trim();
|
|
2749
2737
|
const model = viewOf(props.state, "model").text.trim();
|
|
2750
2738
|
const routing = useLlmRouting(provider, model);
|
|
2751
|
-
const [saveState, setSaveState] = (0,
|
|
2752
|
-
const timers = (0,
|
|
2753
|
-
const savedTimer = (0,
|
|
2754
|
-
const savedValues = (0,
|
|
2755
|
-
const sequence = (0,
|
|
2756
|
-
(0,
|
|
2739
|
+
const [saveState, setSaveState] = (0, import_react9.useState)("idle");
|
|
2740
|
+
const timers = (0, import_react9.useRef)(/* @__PURE__ */ new Map());
|
|
2741
|
+
const savedTimer = (0, import_react9.useRef)(void 0);
|
|
2742
|
+
const savedValues = (0, import_react9.useRef)(/* @__PURE__ */ new Map());
|
|
2743
|
+
const sequence = (0, import_react9.useRef)(0);
|
|
2744
|
+
(0, import_react9.useEffect)(() => {
|
|
2757
2745
|
for (const row of ROWS) {
|
|
2758
2746
|
if (!savedValues.current.has(row.key)) {
|
|
2759
2747
|
savedValues.current.set(row.key, viewOf(props.state, row.key).text);
|
|
@@ -2863,16 +2851,19 @@ function SettingsRows(props) {
|
|
|
2863
2851
|
}
|
|
2864
2852
|
void runSave(key, text ?? viewOf(props.state, key).text);
|
|
2865
2853
|
};
|
|
2866
|
-
(0,
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2854
|
+
(0, import_react9.useEffect)(
|
|
2855
|
+
() => () => {
|
|
2856
|
+
for (const timer of timers.current.values()) clearTimeout(timer);
|
|
2857
|
+
timers.current.clear();
|
|
2858
|
+
if (savedTimer.current !== void 0) clearTimeout(savedTimer.current);
|
|
2859
|
+
},
|
|
2860
|
+
[]
|
|
2861
|
+
);
|
|
2871
2862
|
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 : "";
|
|
2872
2863
|
const renderRow = (row, index) => {
|
|
2873
2864
|
const raw = viewOf(props.state, row.key);
|
|
2874
2865
|
const view = raw.overridden && atDefaultValue(row.key, raw.text) ? { ...raw, overridden: false } : raw;
|
|
2875
|
-
return /* @__PURE__ */ (0,
|
|
2866
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { style: index === 0 ? void 0 : SEPARATOR_STYLE, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2876
2867
|
SettingsRow,
|
|
2877
2868
|
{
|
|
2878
2869
|
row,
|
|
@@ -2888,15 +2879,15 @@ function SettingsRows(props) {
|
|
|
2888
2879
|
}
|
|
2889
2880
|
) }, row.key);
|
|
2890
2881
|
};
|
|
2891
|
-
return /* @__PURE__ */ (0,
|
|
2882
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "dsh-pe-form", children: [
|
|
2892
2883
|
BASIC_ROWS.map(renderRow),
|
|
2893
|
-
/* @__PURE__ */ (0,
|
|
2894
|
-
/* @__PURE__ */ (0,
|
|
2884
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("details", { className: "dsh-pe-advanced", children: [
|
|
2885
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("summary", { children: props.copy.labels.advanced }),
|
|
2895
2886
|
ADVANCED_ROWS.map(renderRow)
|
|
2896
2887
|
] }),
|
|
2897
|
-
/* @__PURE__ */ (0,
|
|
2898
|
-
statusText === "" ? null : /* @__PURE__ */ (0,
|
|
2899
|
-
/* @__PURE__ */ (0,
|
|
2888
|
+
/* @__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: [
|
|
2889
|
+
statusText === "" ? null : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "dsh-pe-save-status", role: "status", "aria-live": "polite", children: statusText }),
|
|
2890
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2900
2891
|
"button",
|
|
2901
2892
|
{
|
|
2902
2893
|
type: "button",
|
|
@@ -2919,26 +2910,15 @@ function SettingsSection(props) {
|
|
|
2919
2910
|
const t = translator(props.translate);
|
|
2920
2911
|
const chinese = (locale?.active ?? "zh").toLowerCase().startsWith("zh");
|
|
2921
2912
|
if (state === void 0) {
|
|
2922
|
-
return /* @__PURE__ */ (0,
|
|
2913
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { style: { margin: 0, fontSize: 12, lineHeight: 1.6 }, children: t("settings.disconnected") });
|
|
2923
2914
|
}
|
|
2924
2915
|
const edit = props.edit ?? (() => {
|
|
2925
2916
|
});
|
|
2926
2917
|
const resetField = props.resetField ?? (() => {
|
|
2927
2918
|
});
|
|
2928
|
-
return /* @__PURE__ */ (0,
|
|
2929
|
-
/* @__PURE__ */ (0,
|
|
2930
|
-
/* @__PURE__ */ (0,
|
|
2931
|
-
SettingsRows,
|
|
2932
|
-
{
|
|
2933
|
-
copy: sectionCopy(t, chinese),
|
|
2934
|
-
state,
|
|
2935
|
-
edit,
|
|
2936
|
-
resetField,
|
|
2937
|
-
save: props.save,
|
|
2938
|
-
discard: props.discard,
|
|
2939
|
-
writeField: props.writeField
|
|
2940
|
-
}
|
|
2941
|
-
)
|
|
2919
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 12 }, children: [
|
|
2920
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(PageHeader, { title: t("settings.title"), description: t("settings.description"), version: PLUGIN_VERSION }),
|
|
2921
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SettingsRows, { copy: sectionCopy(t, chinese), state, edit, resetField, save: props.save, discard: props.discard, writeField: props.writeField })
|
|
2942
2922
|
] });
|
|
2943
2923
|
}
|
|
2944
2924
|
function SettingsPage(props) {
|
|
@@ -2947,24 +2927,13 @@ function SettingsPage(props) {
|
|
|
2947
2927
|
const state = read === void 0 ? void 0 : read((snapshot) => snapshot);
|
|
2948
2928
|
if (props.view === "summary") return t("settings.summary");
|
|
2949
2929
|
if (state === void 0) {
|
|
2950
|
-
return /* @__PURE__ */ (0,
|
|
2930
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("p", { style: { margin: 0, fontSize: 12, lineHeight: 1.6 }, children: t("settings.disconnected") });
|
|
2951
2931
|
}
|
|
2952
2932
|
const edit = props.edit ?? (() => {
|
|
2953
2933
|
});
|
|
2954
2934
|
const resetField = props.resetField ?? (() => {
|
|
2955
2935
|
});
|
|
2956
|
-
return /* @__PURE__ */ (0,
|
|
2957
|
-
SettingsRows,
|
|
2958
|
-
{
|
|
2959
|
-
copy: pageCopy(t),
|
|
2960
|
-
state,
|
|
2961
|
-
edit,
|
|
2962
|
-
resetField,
|
|
2963
|
-
save: props.save,
|
|
2964
|
-
discard: props.discard,
|
|
2965
|
-
writeField: props.writeField
|
|
2966
|
-
}
|
|
2967
|
-
);
|
|
2936
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(SettingsRows, { copy: pageCopy(t), state, edit, resetField, save: props.save, discard: props.discard, writeField: props.writeField });
|
|
2968
2937
|
}
|
|
2969
2938
|
var SettingsPageController = class {
|
|
2970
2939
|
/**
|
|
@@ -3126,10 +3095,7 @@ function apply(ctx) {
|
|
|
3126
3095
|
if (slots === void 0) return;
|
|
3127
3096
|
return slots.inject("conversation.input.right", () => {
|
|
3128
3097
|
try {
|
|
3129
|
-
return slots.register(
|
|
3130
|
-
{ name: "conversation.input.right", id: "dsh-prompt-enhance", order: 60, locale: NS },
|
|
3131
|
-
EnhanceButton
|
|
3132
|
-
);
|
|
3098
|
+
return slots.register({ name: "conversation.input.right", id: "dsh-prompt-enhance", order: 60, locale: NS }, EnhanceButton);
|
|
3133
3099
|
} catch (error) {
|
|
3134
3100
|
return report("composer enhance button slot", error);
|
|
3135
3101
|
}
|
|
@@ -3140,10 +3106,7 @@ function apply(ctx) {
|
|
|
3140
3106
|
if (slots === void 0) return;
|
|
3141
3107
|
return slots.inject("conversation.input.dock", () => {
|
|
3142
3108
|
try {
|
|
3143
|
-
return slots.register(
|
|
3144
|
-
{ name: "conversation.input.dock", id: "dsh-prompt-enhance-result", order: 30, locale: NS },
|
|
3145
|
-
ResultDock
|
|
3146
|
-
);
|
|
3109
|
+
return slots.register({ name: "conversation.input.dock", id: "dsh-prompt-enhance-result", order: 30, locale: NS }, ResultDock);
|
|
3147
3110
|
} catch (error) {
|
|
3148
3111
|
return report("result dock slot", error);
|
|
3149
3112
|
}
|
|
@@ -3154,10 +3117,7 @@ function apply(ctx) {
|
|
|
3154
3117
|
if (slots === void 0) return;
|
|
3155
3118
|
return slots.inject("conversation.input.dock", () => {
|
|
3156
3119
|
try {
|
|
3157
|
-
return slots.register(
|
|
3158
|
-
{ name: "conversation.input.dock", id: "dsh-prompt-enhance-undo", order: 90, locale: NS },
|
|
3159
|
-
UndoBar
|
|
3160
|
-
);
|
|
3120
|
+
return slots.register({ name: "conversation.input.dock", id: "dsh-prompt-enhance-undo", order: 90, locale: NS }, UndoBar);
|
|
3161
3121
|
} catch (error) {
|
|
3162
3122
|
return report("undo bar slot", error);
|
|
3163
3123
|
}
|