@y1x1n/dsh-prompt-optimizer 0.3.15 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/client.js CHANGED
@@ -1,5 +1,5 @@
1
1
  window.__ModuleLoader__.load({
2
- id: "dsh-prompt-optimizer",
2
+ id: "@y1x1n/dsh-prompt-optimizer",
3
3
  factory: (require) => {
4
4
  var module = { exports: {} };
5
5
  var exports = module.exports;
@@ -100,14 +100,12 @@ var dict = {
100
100
  "panel.reoptimize": "\u91CD\u65B0\u4F18\u5316",
101
101
  "panel.reoptimizeTitle": "\u91CD\u65B0\u8FD0\u884C\u4F18\u5316:\u82E5\u8349\u7A3F\u76F8\u5BF9\u4E0A\u4E00\u8F6E\u7ED3\u679C\u6709\u6539\u52A8,\u4F1A\u643A\u5E26\u4E0A\u8F6E\u7ED3\u679C\u7EED\u6539;\u5426\u5219\u5168\u65B0\u751F\u6210",
102
102
  "panel.undo": "\u64A4\u56DE",
103
- "panel.applied": "\u5DF2\u66FF\u6362\u5230\u8F93\u5165\u6846 \u2713",
104
103
  "panel.appliedShort": "\u5DF2\u66FF\u6362 \u2713",
105
104
  "panel.undoneShort": "\u5DF2\u64A4\u56DE \u2713",
106
105
  "panel.fallback": "\u5DF2\u56DE\u9000",
107
106
  "panel.duration": "\u7528\u65F6",
108
- "panel.truncated": "\u8F93\u51FA\u8FBE\u5230 Token \u4E0A\u9650\u88AB\u622A\u65AD\u3002\u53EF\u5728 \u8BBE\u7F6E \u2192 \u63D2\u4EF6\u914D\u7F6E \u2192 \u63D0\u793A\u8BCD\u4F18\u5316 \u4E2D\u8C03\u9AD8\u300C\u6700\u5927\u8F93\u51FA Token\u300D\u3002",
107
+ "panel.truncated": "\u8F93\u51FA\u8FBE\u5230 Token \u4E0A\u9650\u88AB\u622A\u65AD\u3002\u53EF\u5728\u8BBE\u7F6E\u7684\u63D2\u4EF6\u9875\u300C\u63D0\u793A\u8BCD\u4F18\u5316\u300D\u4E2D\u8C03\u9AD8\u300C\u6700\u5927\u8F93\u51FA Token\u300D\u3002",
109
108
  "panel.notWellFormed": "\u6A21\u578B\u672A\u5B8C\u5168\u9075\u5B88\u8F93\u51FA\u683C\u5F0F,\u4EE5\u4E0A\u5185\u5BB9\u53EF\u80FD\u6DF7\u5165\u591A\u4F59\u6587\u5B57,\u66FF\u6362\u524D\u8BF7\u626B\u4E00\u773C\u3002",
110
- "settings.desc": "\u53D1\u9001\u680F\u300C\u4F18\u5316\u300D\u6309\u94AE(\u2728 \u56FE\u6807)\u7684\u884C\u4E3A\u914D\u7F6E",
111
109
  "settings.loading": "\u8BBE\u7F6E\u52A0\u8F7D\u4E2D\u2026",
112
110
  "settings.unavailable": "\u5F53\u524D\u8FDE\u63A5\u4E0D\u53EF\u5199\u8BBE\u7F6E(\u8FDC\u7A0B\u9875\u9762\u4E3A\u5185\u5B58\u6A21\u5F0F),\u6539\u52A8\u4EC5\u5728\u672C\u6B21\u4F1A\u8BDD\u751F\u6548\u3002",
113
111
  "settings.memoryOnly": "\u5F53\u524D\u4E3A\u5185\u5B58\u6A21\u5F0F:\u8BBE\u7F6E\u4E0D\u4F1A\u6301\u4E45\u5316\u3002",
@@ -116,39 +114,44 @@ var dict = {
116
114
  "settings.group.model": "\u6A21\u578B",
117
115
  "settings.group.params": "\u8C03\u7528\u53C2\u6570",
118
116
  "settings.group.context": "\u4E0A\u4E0B\u6587",
119
- "settings.summary.model": "\u6A21\u578B",
120
- "settings.summary.mode": "\u6A21\u5F0F",
121
117
  "settings.model": "\u4F18\u5316\u7528\u6A21\u578B",
122
118
  "settings.model.follow": "\u8DDF\u968F\u5F53\u524D\u4F1A\u8BDD(\u9ED8\u8BA4)",
123
- "settings.catalog.loading": "\u6A21\u578B\u76EE\u5F55\u52A0\u8F7D\u4E2D\u2026",
124
- "settings.catalog.error": "\u6A21\u578B\u76EE\u5F55\u52A0\u8F7D\u5931\u8D25,\u70B9\u53F3\u4FA7\u6309\u94AE\u91CD\u8BD5\u3002",
119
+ "settings.model.desc": "\u7559\u7A7A\u8DDF\u968F\u4F1A\u8BDD;\u56FA\u5B9A\u540E\u6240\u6709\u4F18\u5316\u90FD\u7528\u8FD9\u4E2A\u6A21\u578B",
125
120
  "settings.refresh": "\u21BB \u5237\u65B0",
126
121
  "settings.refreshTitle": "\u91CD\u65B0\u62C9\u53D6\u6A21\u578B\u76EE\u5F55(\u65B0\u589E\u63D0\u4F9B\u65B9/\u6A21\u578B\u540E\u4F7F\u7528)",
127
122
  "settings.fallbackModel": "\u56DE\u9000\u6A21\u578B",
128
123
  "settings.fallbackModel.none": "\u65E0(\u9ED8\u8BA4)",
124
+ "settings.fallbackModel.desc": "\u4E3B\u8DEF\u7531\u672A\u4EA7\u51FA\u5185\u5BB9\u5373\u5931\u8D25\u65F6\u81EA\u52A8\u6362\u7528",
129
125
  "settings.test": "\u6A21\u578B\u8FDE\u901A\u6027",
126
+ "settings.test.desc": "\u6309\u540C\u4E00\u8DEF\u7531\u53D1\u4E00\u4E2A\u5C0F\u63A2\u6D3B\u8C03\u7528",
130
127
  "settings.test.run": "\u6D4B\u8BD5\u8FDE\u63A5",
131
128
  "settings.test.running": "\u6D4B\u8BD5\u4E2D\u2026",
132
129
  "settings.test.ok": "\u8FDE\u63A5\u6B63\u5E38:{provider} / {model}({latencyMs}ms)",
133
130
  "settings.language": "\u8F93\u51FA\u8BED\u8A00",
131
+ "settings.language.desc": "\u4F18\u5316\u7ED3\u679C\u4F7F\u7528\u7684\u8BED\u8A00",
134
132
  "settings.mode": "\u4F18\u5316\u6A21\u5F0F",
133
+ "settings.mode.desc": "\u5FEB\u901F\u6A21\u5F0F\u8F93\u51FA\u4E0E\u7B49\u5F85\u7EA6\u51CF\u534A;\u5B8C\u6574\u6A21\u5F0F\u591A\u4E00\u6BB5\u5206\u6790\u8BCA\u65AD",
135
134
  "settings.mode.full": "\u5B8C\u6574(\u5206\u6790\u8BCA\u65AD + \u4F18\u5316)",
136
135
  "settings.mode.fast": "\u5FEB\u901F(\u4EC5\u4F18\u5316,\u7B49\u5F85\u7EA6\u51CF\u534A)",
137
136
  "settings.mode.full.short": "\u5B8C\u6574",
138
137
  "settings.mode.fast.short": "\u5FEB\u901F",
139
138
  "settings.effort": "\u63A8\u7406\u5F3A\u5EA6",
139
+ "settings.effort.desc": "\u63A8\u7406\u6A21\u578B\u4E0A,\u6700\u4F4E\u6863\u663E\u8457\u7F29\u77ED\u7B49\u5F85",
140
140
  "settings.effort.lowest": "\u964D\u5230\u6700\u4F4E\u6863(\u9ED8\u8BA4,\u63A8\u7406\u6A21\u578B\u66F4\u5FEB)",
141
141
  "settings.effort.session": "\u8DDF\u968F\u5F53\u524D\u4F1A\u8BDD",
142
+ "settings.effort.lowest.short": "\u6700\u4F4E\u6863",
143
+ "settings.effort.session.short": "\u8DDF\u968F\u4F1A\u8BDD",
142
144
  "settings.maxTokens": "\u6700\u5927\u8F93\u51FA Token",
145
+ "settings.maxTokens.desc": "\u5355\u6B21\u4F18\u5316\u8C03\u7528\u7684\u8F93\u51FA\u4E0A\u9650",
143
146
  "settings.timeout": "\u8D85\u65F6\u65F6\u95F4(\u79D2)",
147
+ "settings.timeout.desc": "\u8D85\u65F6\u540E\u4E2D\u6B62\u8C03\u7528\u5E76\u7ED9\u51FA\u63D0\u793A",
144
148
  "settings.temperature": "\u91C7\u6837\u6E29\u5EA6",
145
149
  "settings.temperatureTitle": "\u4F18\u5316\u662F\u683C\u5F0F\u5316\u4EFB\u52A1,\u4F4E\u6E29\u8F93\u51FA\u66F4\u7A33\u5B9A;\u9ED8\u8BA4 0.2,\u4E00\u822C\u65E0\u9700\u8C03\u6574",
150
+ "settings.temperature.desc": "\u4F4E\u6E29\u8F93\u51FA\u66F4\u7A33\u5B9A(\u9ED8\u8BA4 0.2)",
146
151
  "settings.autoMaxTokens": "\u8F93\u51FA\u4E0A\u9650\u81EA\u9002\u5E94",
147
- "settings.autoMaxTokens.on": "\u5F00:\u957F\u8349\u7A3F\u81EA\u52A8\u63D0\u9AD8\u8F93\u51FA\u4E0A\u9650(\u9ED8\u8BA4)",
148
- "settings.autoMaxTokens.off": "\u5173:\u56FA\u5B9A\u7528\u4E0A\u9762\u7684\u6700\u5927\u8F93\u51FA Token",
152
+ "settings.autoMaxTokens.desc": "\u957F\u8349\u7A3F\u81EA\u52A8\u63D0\u9AD8\u4E0A\u9650,\u907F\u514D\u622A\u65AD",
149
153
  "settings.includeContext": "\u643A\u5E26\u4E0A\u4E0B\u6587",
150
- "settings.includeContext.on": "\u5F00:\u53C2\u8003\u6700\u8FD1\u5BF9\u8BDD,\u4F18\u5316\u65B9\u5411\u66F4\u8D34\u5408(\u9ED8\u8BA4)",
151
- "settings.includeContext.off": "\u5173:\u4EC5\u770B\u8349\u7A3F\u672C\u8EAB",
154
+ "settings.includeContext.desc": "\u53C2\u8003\u6700\u8FD1\u5BF9\u8BDD,\u4F18\u5316\u65B9\u5411\u66F4\u8D34\u5408",
152
155
  "settings.validate.maxTokens": "\u8BF7\u8F93\u5165 1024\u201332768 \u4E4B\u95F4\u7684\u6570\u5B57",
153
156
  "settings.validate.timeout": "\u8BF7\u8F93\u5165 10\u2013600 \u4E4B\u95F4\u7684\u6570\u5B57",
154
157
  "settings.validate.temperature": "\u8BF7\u8F93\u5165 0\u20132 \u4E4B\u95F4\u7684\u6570\u5B57",
@@ -178,14 +181,12 @@ var dict = {
178
181
  "panel.reoptimize": "Re-optimize",
179
182
  "panel.reoptimizeTitle": "Re-runs optimization: carries the previous result only if the draft changed since then; otherwise regenerates fresh",
180
183
  "panel.undo": "Undo",
181
- "panel.applied": "Replaced into the input box \u2713",
182
184
  "panel.appliedShort": "Applied \u2713",
183
185
  "panel.undoneShort": "Undone \u2713",
184
186
  "panel.fallback": "fallback",
185
187
  "panel.duration": "took",
186
- "panel.truncated": 'Output hit the token cap and was truncated. Raise "Max output tokens" under Settings \u2192 Plugins \u2192 Prompt Optimizer.',
188
+ "panel.truncated": 'Output hit the token cap and was truncated. Raise "Max output tokens" in the "Prompt Optimizer" tab of the plugins settings page.',
187
189
  "panel.notWellFormed": "The model did not fully follow the output format; the content above may contain extra text \u2014 review before replacing.",
188
- "settings.desc": "Behavior of the composer \u2728 Optimize button",
189
190
  "settings.loading": "Loading settings\u2026",
190
191
  "settings.unavailable": "This connection cannot write settings (remote page is in-memory); changes apply to this session only.",
191
192
  "settings.memoryOnly": "In-memory mode: settings will not persist.",
@@ -194,45 +195,54 @@ var dict = {
194
195
  "settings.group.model": "Model",
195
196
  "settings.group.params": "Generation parameters",
196
197
  "settings.group.context": "Context",
197
- "settings.summary.model": "Model",
198
- "settings.summary.mode": "Mode",
199
198
  "settings.model": "Optimizer model",
200
199
  "settings.model.follow": "Follow current session (default)",
201
- "settings.catalog.loading": "Loading model catalog\u2026",
202
- "settings.catalog.error": "Failed to load the model catalog \u2014 use the button to retry.",
200
+ "settings.model.desc": "Leave empty to follow the session; pin one to always optimize with it",
203
201
  "settings.refresh": "\u21BB Refresh",
204
202
  "settings.refreshTitle": "Reload the model catalog (after adding providers/models)",
205
203
  "settings.fallbackModel": "Fallback model",
206
204
  "settings.fallbackModel.none": "None (default)",
205
+ "settings.fallbackModel.desc": "Switched to automatically when the main route fails before producing output",
207
206
  "settings.test": "Connectivity",
207
+ "settings.test.desc": "Sends a tiny probe call through the same routing",
208
208
  "settings.test.run": "Test connection",
209
209
  "settings.test.running": "Testing\u2026",
210
210
  "settings.test.ok": "Connected: {provider} / {model} ({latencyMs}ms)",
211
211
  "settings.language": "Output language",
212
+ "settings.language.desc": "Language of the optimized result",
212
213
  "settings.mode": "Mode",
214
+ "settings.mode.desc": "Fast halves the output tokens and the wait; full adds an analysis pass",
213
215
  "settings.mode.full": "Full (analysis + rewrite)",
214
216
  "settings.mode.fast": "Fast (rewrite only, ~half the wait)",
215
217
  "settings.mode.full.short": "Full",
216
218
  "settings.mode.fast.short": "Fast",
217
219
  "settings.effort": "Reasoning effort",
220
+ "settings.effort.desc": "On reasoning models the lowest tier shortens the wait significantly",
218
221
  "settings.effort.lowest": "Clamp to lowest tier (default, faster on reasoning models)",
219
222
  "settings.effort.session": "Follow current session",
223
+ "settings.effort.lowest.short": "Lowest",
224
+ "settings.effort.session.short": "Follow session",
220
225
  "settings.maxTokens": "Max output tokens",
226
+ "settings.maxTokens.desc": "Output cap per optimization call",
221
227
  "settings.timeout": "Timeout (seconds)",
228
+ "settings.timeout.desc": "The call is aborted and reported after this many seconds",
222
229
  "settings.temperature": "Temperature",
223
230
  "settings.temperatureTitle": "Optimization is a formatting task \u2014 low temperature gives stabler output; default 0.2, usually no need to change",
231
+ "settings.temperature.desc": "Low temperature gives stabler output (default 0.2)",
224
232
  "settings.autoMaxTokens": "Adaptive output cap",
225
- "settings.autoMaxTokens.on": "On: long drafts raise the output cap (default)",
226
- "settings.autoMaxTokens.off": "Off: always use the max output tokens above",
233
+ "settings.autoMaxTokens.desc": "Raise the cap for long drafts instead of truncating them",
227
234
  "settings.includeContext": "Include context",
228
- "settings.includeContext.on": "On: read recent conversation for a better-aligned rewrite (default)",
229
- "settings.includeContext.off": "Off: only look at the draft itself",
235
+ "settings.includeContext.desc": "Read recent conversation so the rewrite matches your intent",
230
236
  "settings.validate.maxTokens": "Enter a number between 1024 and 32768",
231
237
  "settings.validate.timeout": "Enter a number between 10 and 600",
232
238
  "settings.validate.temperature": "Enter a number between 0 and 2",
233
239
  "settings.repoTitle": "View source / report issues on GitHub"
234
240
  }
235
241
  };
242
+ function translate(key, params) {
243
+ const active = face?.getSnapshot().active === "en" ? "en" : "zh";
244
+ return interpolate(dict[active][key] ?? dict.zh[key], params);
245
+ }
236
246
  function interpolate(text, params) {
237
247
  if (!params) return text;
238
248
  return text.replace(/\{(\w+)\}/g, (m, name2) => params[name2] !== void 0 ? String(params[name2]) : m);
@@ -252,37 +262,40 @@ var buttonStyle = {
252
262
  display: "inline-flex",
253
263
  alignItems: "center",
254
264
  gap: 4,
255
- padding: "4px 10px",
265
+ padding: "4px 12px",
256
266
  fontSize: 12,
257
267
  lineHeight: "18px",
258
- borderRadius: 6,
259
- border: "1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.35))",
260
- background: "var(--dsw-alias-button-tool-bar-fill, transparent)",
268
+ borderRadius: 999,
269
+ border: "none",
261
270
  color: "var(--dsw-alias-label-primary, inherit)",
262
271
  cursor: "pointer",
263
- whiteSpace: "nowrap",
264
- // U4:预留最宽文案(「优化中…」/「Optimizing…」)的宽度,状态切换不引起工具栏抖动。
265
- minWidth: 92
272
+ whiteSpace: "nowrap"
273
+ // 宽度贴住内容,不预留「优化中…」的空位(用户反馈空闲态「优化」右侧空白);
274
+ // 加载态文案不变、仅图标旋转,宽度恒定,工具行不抖动(U4 原目标改由
275
+ // 恒定文案达成,minWidth 随之移除)。
276
+ // 底色与 hover 态走注入样式表的 .dsh-po-opt 规则(inline 会盖过 :hover)。
266
277
  };
267
278
  function createOptimizeButton(controller) {
268
279
  return function OptimizeButton(props) {
269
280
  const state = (0, import_react2.useSyncExternalStore)(controller.subscribe, controller.getSnapshot);
270
281
  const t = useT();
271
- const draft = props.input.draft;
282
+ const p = props;
283
+ const input = p.useInput ? p.useInput((s) => s) : p.input;
284
+ const draft = input?.draft ?? "";
272
285
  const empty = !draft.trim();
273
286
  const loading = state.status === "loading";
274
287
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { display: "inline-flex" }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
275
288
  "button",
276
289
  {
277
- className: "dsh-po-btn",
290
+ className: "dsh-po-btn dsh-po-opt",
278
291
  type: "button",
279
292
  style: { ...buttonStyle, ...empty || loading ? { opacity: 0.45, cursor: "not-allowed" } : {} },
280
293
  disabled: empty || loading,
281
- title: empty ? t("button.titleEmpty") : t("button.title"),
282
- onClick: () => void controller.optimize(draft, props.sessionId),
294
+ title: loading ? t("button.optimizing") : empty ? t("button.titleEmpty") : t("button.title"),
295
+ onClick: () => void controller.optimize(draft, p.sessionId),
283
296
  children: [
284
297
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SparkleIcon, { spinning: loading }),
285
- loading ? t("button.optimizing") : t("button.optimize")
298
+ t("button.optimize")
286
299
  ]
287
300
  }
288
301
  ) });
@@ -292,6 +305,20 @@ function createOptimizeButton(controller) {
292
305
  // src/client/ResultDock.tsx
293
306
  var import_react3 = require("react");
294
307
 
308
+ // src/client/host-faces.ts
309
+ async function sessionCatalog(connection, signal) {
310
+ const call = connection?.rpc?.call;
311
+ if (!call) return { ok: false, error: "\u8FDE\u63A5\u5C42 RPC \u901A\u9053\u5728\u5F53\u524D dsh \u7248\u672C\u7F3A\u5E2D" };
312
+ const result = await call("/api", "session/modelCatalog", { args: {} }, signal);
313
+ if (!result.ok) {
314
+ return { ok: false, error: result.error };
315
+ }
316
+ return { ok: true, value: { groups: result.value.groups ?? [], failures: result.value.failures } };
317
+ }
318
+ function legacyQueryFace(connection) {
319
+ return connection?.api;
320
+ }
321
+
295
322
  // src/prompt.ts
296
323
  var MARKERS = {
297
324
  analysis: "<<<ANALYSIS>>>",
@@ -299,18 +326,18 @@ var MARKERS = {
299
326
  end: "<<<END>>>"
300
327
  };
301
328
  var FORMAT_FULL_ZH = `# \u8F93\u51FA\u683C\u5F0F(\u4E25\u683C\u9075\u5B88,\u6807\u8BB0\u884C\u5355\u72EC\u6210\u884C)
302
- ${MARKERS.analysis}
303
- \u6309\u7EF4\u5EA6\u9010\u6761\u8F93\u51FA\u8BCA\u65AD,\u6BCF\u6761\u4E00\u884C,\u683C\u5F0F:\u300C\u7EF4\u5EA6 | \u95EE\u9898 | \u5EFA\u8BAE\u300D\u3002\u67D0\u7EF4\u5EA6\u65E0\u660E\u663E\u95EE\u9898\u65F6\u5199:\u300C\u7EF4\u5EA6 | \u65E0\u660E\u663E\u95EE\u9898 | -\u300D\u3002
304
329
  ${MARKERS.optimized}
305
330
  \u8F93\u51FA\u4F18\u5316\u540E\u7684\u5B8C\u6574\u63D0\u793A\u8BCD\u5168\u6587
331
+ ${MARKERS.analysis}
332
+ \u6309\u7EF4\u5EA6\u9010\u6761\u8F93\u51FA\u8BCA\u65AD,\u6BCF\u6761\u4E00\u884C,\u683C\u5F0F:\u300C\u7EF4\u5EA6 | \u95EE\u9898 | \u5EFA\u8BAE\u300D\u3002\u67D0\u7EF4\u5EA6\u65E0\u660E\u663E\u95EE\u9898\u65F6\u5199:\u300C\u7EF4\u5EA6 | \u65E0\u660E\u663E\u95EE\u9898 | -\u300D\u3002
306
333
  ${MARKERS.end}
307
334
 
308
335
  \u9664\u4E0A\u8FF0\u6807\u8BB0\u5305\u88F9\u7684\u5185\u5BB9\u5916,\u4E0D\u8981\u8F93\u51FA\u4EFB\u4F55\u5176\u4ED6\u6587\u5B57\u3002`;
309
336
  var FORMAT_FULL_EN = `# Output format (strictly follow; markers on their own lines)
310
- ${MARKERS.analysis}
311
- One finding per line: "dimension | issue | suggestion". If a dimension is fine: "dimension | no issue | -".
312
337
  ${MARKERS.optimized}
313
338
  The full optimized prompt text
339
+ ${MARKERS.analysis}
340
+ One finding per line: "dimension | issue | suggestion". If a dimension is fine: "dimension | no issue | -".
314
341
  ${MARKERS.end}
315
342
 
316
343
  Do not output anything outside these markers.`;
@@ -353,27 +380,70 @@ function findMarker(text, word, fromIndex = 0) {
353
380
  const match = re.exec(text);
354
381
  return match ? { index: match.index, length: match[0].length } : null;
355
382
  }
356
- function parsePartialOptimizerOutput(raw) {
357
- const a = findMarker(raw, "ANALYSIS");
358
- const o = findMarker(raw, "OPTIMIZED");
359
- let analysis = "";
360
- let optimized = "";
361
- if (a && (!o || a.index < o.index)) {
362
- analysis = raw.slice(a.index + a.length, o ? o.index : raw.length).trim();
383
+ function findLastMarker(text, word, beforeIndex = text.length) {
384
+ const re = new RegExp(`<<<\\s*${word}\\s*>>>`, "g");
385
+ let last = null;
386
+ for (const match of text.matchAll(re)) {
387
+ if (match.index >= beforeIndex) break;
388
+ last = { index: match.index, length: match[0].length };
363
389
  }
364
- if (o) {
365
- const e = findMarker(raw, "END", o.index + o.length);
366
- optimized = raw.slice(o.index + o.length, e ? e.index : raw.length).trim();
390
+ return last;
391
+ }
392
+ function findNextMarker(text, fromIndex) {
393
+ const re = /<<<\s*(?:ANALYSIS|OPTIMIZED|END)\s*>>>/g;
394
+ re.lastIndex = fromIndex;
395
+ const match = re.exec(text);
396
+ return match ? { index: match.index, length: match[0].length } : null;
397
+ }
398
+ function segmentAfter(text, marker) {
399
+ const firstEnd = findMarker(text, "END");
400
+ if (firstEnd && marker.index > firstEnd.index) return "";
401
+ const start = marker.index + marker.length;
402
+ const next = findNextMarker(text, start);
403
+ let end = next ? next.index : text.length;
404
+ if (firstEnd && firstEnd.index > start && firstEnd.index < end) end = firstEnd.index;
405
+ return text.slice(start, end).trim();
406
+ }
407
+ var THINK_OPEN = "<think>";
408
+ var THINK_CLOSE = "</think>";
409
+ function stripThinkBlocks(text) {
410
+ let out = "";
411
+ let rest = text;
412
+ for (; ; ) {
413
+ const open = rest.indexOf(THINK_OPEN);
414
+ if (open === -1) return out + rest;
415
+ out += rest.slice(0, open);
416
+ const close = rest.indexOf(THINK_CLOSE, open + THINK_OPEN.length);
417
+ if (close === -1) return out;
418
+ rest = rest.slice(close + THINK_CLOSE.length);
367
419
  }
368
- return { analysis, optimized };
420
+ }
421
+ function parsePartialOptimizerOutput(raw) {
422
+ const text = stripThinkBlocks(raw);
423
+ const o = findLastMarker(text, "OPTIMIZED");
424
+ const a = findLastMarker(text, "ANALYSIS");
425
+ return {
426
+ analysis: a ? segmentAfter(text, a) : "",
427
+ optimized: o ? segmentAfter(text, o) : ""
428
+ };
369
429
  }
370
430
  function compactPartialBuffer(raw) {
371
- const o = findMarker(raw, "OPTIMIZED");
372
- if (!o) return { compacted: null, analysis: "" };
373
- const a = findMarker(raw, "ANALYSIS");
374
- const analysis = a && a.index < o.index ? raw.slice(a.index + a.length, o.index).trim() : "";
375
- return { compacted: `${MARKERS.optimized}
376
- ${raw.slice(o.index + o.length)}`, analysis };
431
+ const o = findLastMarker(raw, "OPTIMIZED");
432
+ const a = findLastMarker(raw, "ANALYSIS");
433
+ if (o && a && o.index < a.index) {
434
+ return {
435
+ compacted: `${MARKERS.analysis}
436
+ ${raw.slice(a.index + a.length)}`,
437
+ analysis: "",
438
+ optimized: raw.slice(o.index + o.length, a.index).trim()
439
+ };
440
+ }
441
+ if (o) {
442
+ const analysis = a && a.index < o.index ? raw.slice(a.index + a.length, o.index).trim() : "";
443
+ return { compacted: `${MARKERS.optimized}
444
+ ${raw.slice(o.index + o.length)}`, analysis, optimized: "" };
445
+ }
446
+ return { compacted: null, analysis: "", optimized: "" };
377
447
  }
378
448
 
379
449
  // src/client/controller.ts
@@ -386,6 +456,9 @@ function splitCommandPrefix(text) {
386
456
  if (!match[2] || !match[2].trim()) return { body: trimmed, commandOnly: true };
387
457
  return { prefix: match[1], body: match[2].trim() };
388
458
  }
459
+ function joinLast(last) {
460
+ return last.prefix ? `${last.prefix} ${last.text}` : last.text;
461
+ }
389
462
  function shouldAutoClose(input) {
390
463
  if (!input.open || input.status === "loading") return false;
391
464
  return !input.draft.trim() || !input.prevRunning && input.running || input.queued > input.prevQueued;
@@ -426,6 +499,7 @@ function createOptimizerController(ctx, opts = {}) {
426
499
  let abort = null;
427
500
  let liveRaw = "";
428
501
  let frozenAnalysis = "";
502
+ let frozenOptimized = "";
429
503
  let liveTimer = null;
430
504
  const clearLiveTimer = () => {
431
505
  if (liveTimer) {
@@ -456,6 +530,7 @@ function createOptimizerController(ctx, opts = {}) {
456
530
  clearLiveTimer();
457
531
  liveRaw = "";
458
532
  frozenAnalysis = "";
533
+ frozenOptimized = "";
459
534
  const controller = new AbortController();
460
535
  abort = controller;
461
536
  const watchdogMs = Math.max(1e3, opts.getWatchdogMs?.() ?? 125e3);
@@ -470,7 +545,7 @@ function createOptimizerController(ctx, opts = {}) {
470
545
  set({
471
546
  status: "error",
472
547
  live: null,
473
- error: `\u8BF7\u6C42\u8D85\u65F6(\u5BA2\u6237\u7AEF ${seconds} \u79D2\u65E0\u54CD\u5E94,Host \u53EF\u80FD\u672A\u8FD0\u884C)\u3002\u53EF\u5728 \u8BBE\u7F6E \u2192 \u63D2\u4EF6\u914D\u7F6E \u2192 \u63D0\u793A\u8BCD\u4F18\u5316 \u4E2D\u8C03\u9AD8\u300C\u8D85\u65F6\u65F6\u95F4\u300D\u3002`
548
+ error: `\u8BF7\u6C42\u8D85\u65F6(\u5BA2\u6237\u7AEF ${seconds} \u79D2\u65E0\u54CD\u5E94,Host \u53EF\u80FD\u672A\u8FD0\u884C)\u3002\u53EF\u5728 \u8BBE\u7F6E\u7684\u63D2\u4EF6\u9875\u300C\u63D0\u793A\u8BCD\u4F18\u5316\u300D \u4E2D\u8C03\u9AD8\u300C\u8D85\u65F6\u65F6\u95F4\u300D\u3002`
474
549
  });
475
550
  };
476
551
  const startedAt = Date.now();
@@ -480,12 +555,17 @@ function createOptimizerController(ctx, opts = {}) {
480
555
  (async () => {
481
556
  if (opts.isModelPinned?.()) return void 0;
482
557
  try {
483
- const resp2 = await ctx.connection.api.sessions.models({ sessionId }, controller.signal);
484
- if (resp2.result.ok) {
485
- const current = resp2.result.value.current;
558
+ const directories = opts.getSessionModelDirectories?.();
559
+ if (!directories) {
560
+ console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u6A21\u578B\u76EE\u5F55\u670D\u52A1\u5728\u5F53\u524D dsh \u7248\u672C\u7F3A\u5E2D,\u6539\u7528 Host \u56DE\u9000");
561
+ return void 0;
562
+ }
563
+ const state2 = await directories.directoryFor(sessionId).load();
564
+ const current = state2.current;
565
+ if (current?.provider && current.model) {
486
566
  return { provider: current.provider, model: current.model, reasoningEffort: current.reasoningEffort };
487
567
  }
488
- console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u6A21\u578B\u67E5\u8BE2\u88AB\u62D2\u7EDD,\u6539\u7528 Host \u56DE\u9000:", resp2.result.error);
568
+ console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u6CA1\u6709\u53EF\u7528\u7684\u6A21\u578B\u9009\u62E9,\u6539\u7528 Host \u56DE\u9000:", state2.error ?? current);
489
569
  } catch (cause) {
490
570
  console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u6A21\u578B\u67E5\u8BE2\u5931\u8D25,\u6539\u7528 Host \u56DE\u9000:", cause);
491
571
  }
@@ -494,12 +574,17 @@ function createOptimizerController(ctx, opts = {}) {
494
574
  (async () => {
495
575
  if (!(opts.isContextEnabled?.() ?? true)) return void 0;
496
576
  try {
497
- const resp2 = await ctx.connection.api.sessions.history({ sessionId, maxMessages: 24 }, controller.signal);
498
- if (resp2.result.ok) {
499
- const turns = extractContextTurns(resp2.result.value.events);
577
+ const history = legacyQueryFace(ctx.connection)?.sessions?.history;
578
+ if (!history) {
579
+ console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u5386\u53F2\u67E5\u8BE2\u9762\u5728\u5F53\u524D dsh \u7248\u672C\u7F3A\u5E2D,\u6309\u65E0\u4E0A\u4E0B\u6587\u4F18\u5316");
580
+ return void 0;
581
+ }
582
+ const result = await history({ sessionId, maxMessages: 24 }, controller.signal);
583
+ if (result.ok) {
584
+ const turns = extractContextTurns(result.value.events ?? []);
500
585
  return turns.length ? turns : void 0;
501
586
  }
502
- console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u5386\u53F2\u67E5\u8BE2\u88AB\u62D2\u7EDD,\u6309\u65E0\u4E0A\u4E0B\u6587\u4F18\u5316:", resp2.result.error);
587
+ console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u5386\u53F2\u67E5\u8BE2\u88AB\u62D2\u7EDD,\u6309\u65E0\u4E0A\u4E0B\u6587\u4F18\u5316:", result.error);
503
588
  } catch (cause) {
504
589
  console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u5386\u53F2\u67E5\u8BE2\u5931\u8D25,\u6309\u65E0\u4E0A\u4E0B\u6587\u4F18\u5316:", cause);
505
590
  }
@@ -509,7 +594,10 @@ function createOptimizerController(ctx, opts = {}) {
509
594
  const resp = await fetch(ROUTE, {
510
595
  method: "POST",
511
596
  headers: { "content-type": "application/json" },
512
- body: JSON.stringify({ text: draft, provider: selection?.provider, model: selection?.model, reasoningEffort: selection?.reasoningEffort, context, previous }),
597
+ // sessionId 随请求带给 Host:Host 把它标注到 llm 调用上,要求会话头
598
+ // 的提供方(如 opencode 的 x-opencode-session)才能路由成功,同时
599
+ // 会话级计量会把这次调用归属到当前会话。
600
+ body: JSON.stringify({ text: draft, sessionId, provider: selection?.provider, model: selection?.model, reasoningEffort: selection?.reasoningEffort, context, previous }),
513
601
  signal: controller.signal
514
602
  });
515
603
  if (!resp.ok || !(resp.headers.get("content-type") ?? "").includes("text/event-stream")) {
@@ -534,7 +622,13 @@ function createOptimizerController(ctx, opts = {}) {
534
622
  buffer = buffer.slice(sep + 2);
535
623
  const line = frame.split("\n").find((l) => l.startsWith("data:"));
536
624
  if (!line) continue;
537
- const event = JSON.parse(line.slice(5).trim());
625
+ let event;
626
+ try {
627
+ event = JSON.parse(line.slice(5).trim());
628
+ } catch {
629
+ console.warn("[dsh-prompt-optimizer] \u8DF3\u8FC7\u65E0\u6CD5\u89E3\u6790\u7684 SSE \u5E27:", line.slice(0, 120));
630
+ continue;
631
+ }
538
632
  if (event.type === "delta") {
539
633
  liveRaw += String(event.text ?? "");
540
634
  if (!liveTimer) {
@@ -543,11 +637,12 @@ function createOptimizerController(ctx, opts = {}) {
543
637
  if (state.status === "loading" && abort === controller) {
544
638
  const comp = compactPartialBuffer(liveRaw);
545
639
  if (comp.compacted !== null) {
546
- frozenAnalysis = comp.analysis;
640
+ if (comp.analysis) frozenAnalysis = comp.analysis;
641
+ if (comp.optimized) frozenOptimized = comp.optimized;
547
642
  liveRaw = comp.compacted;
548
643
  }
549
644
  const partial = parsePartialOptimizerOutput(liveRaw);
550
- const live = { analysis: partial.analysis || frozenAnalysis, optimized: partial.optimized };
645
+ const live = { analysis: partial.analysis || frozenAnalysis, optimized: partial.optimized || frozenOptimized };
551
646
  if (opts.isFastMode?.() && !live.analysis && !live.optimized && liveRaw.trim() && !liveRaw.includes("<<<")) {
552
647
  live.optimized = liveRaw.trim();
553
648
  }
@@ -606,7 +701,7 @@ function createOptimizerController(ctx, opts = {}) {
606
701
  getSnapshot: () => state,
607
702
  optimize,
608
703
  retry() {
609
- if (state.last) void optimize(state.last.text, state.last.sessionId);
704
+ if (state.last) void optimize(joinLast(state.last), state.last.sessionId);
610
705
  },
611
706
  markApplied(applied) {
612
707
  set({ applied });
@@ -660,12 +755,14 @@ async function copyText(text) {
660
755
  var styles = {
661
756
  panel: {
662
757
  marginBottom: 6,
663
- borderRadius: 10,
758
+ borderRadius: 12,
664
759
  border: "1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.3))",
665
- background: "var(--dsw-alias-bg-layer-2, #202226)",
760
+ background: "var(--dsw-alias-bg-layer-2, #fff)",
666
761
  color: "var(--dsw-alias-label-primary, inherit)",
667
- boxShadow: "0 4px 16px rgba(0, 0, 0, 0.12)",
668
- padding: "10px 12px",
762
+ // 阴影从 0.12 降到与官方输入卡同档的极淡弥散(0.03~0.05):
763
+ // 之前的重投影在白底上晕出一圈灰,是面板「显灰显大」的另一来源。
764
+ boxShadow: "0 1px 2px rgba(0, 0, 0, 0.03), 0 4px 14px rgba(0, 0, 0, 0.05)",
765
+ padding: "8px 10px",
669
766
  fontSize: 12.5,
670
767
  lineHeight: 1.5,
671
768
  fontFamily: "var(--dsw-font-family, inherit)"
@@ -690,12 +787,14 @@ var styles = {
690
787
  // U5:分析与优化各自独立滚动区(原先单容器 maxHeight 嵌套出现双滚动条),
691
788
  // 长内容不再互相挤压;外层 body 不限高,滚动归属到各段内部。
692
789
  body: { paddingRight: 4 },
693
- analysisBody: { maxHeight: "16vh", overflowY: "auto", marginTop: 2 },
790
+ analysisBody: { maxHeight: "14vh", overflowY: "auto", marginTop: 2 },
694
791
  optimizedBox: {
695
- background: "var(--dsw-alias-bg-layer-3, rgba(128,128,128,0.08))",
696
- borderRadius: 6,
697
- padding: "6px 8px",
698
- maxHeight: "26vh",
792
+ // 层面令牌在浅色主题下是纯白,填充不可见,用细描边给出容器感(不引入灰底)。
793
+ background: "var(--dsw-alias-bg-layer-3, transparent)",
794
+ border: "1px solid var(--dsw-alias-border-l3, rgba(128,128,128,0.2))",
795
+ borderRadius: 8,
796
+ padding: "5px 8px",
797
+ maxHeight: "22vh",
699
798
  overflowY: "auto",
700
799
  marginTop: 2
701
800
  },
@@ -707,7 +806,7 @@ var styles = {
707
806
  fontSize: 11,
708
807
  fontWeight: 600,
709
808
  color: "var(--dsw-alias-label-primary-dimmed, rgba(128,128,128,0.9))",
710
- margin: "6px 0 2px",
809
+ margin: "5px 0 2px",
711
810
  padding: 0,
712
811
  border: "none",
713
812
  background: "none",
@@ -717,15 +816,17 @@ var styles = {
717
816
  },
718
817
  chevron: { fontSize: 9, transition: "transform 0.15s ease" },
719
818
  pre: { margin: 0, whiteSpace: "pre-wrap", wordBreak: "break-word", fontFamily: "inherit" },
720
- actions: { display: "flex", gap: 8, marginTop: 8 },
819
+ actions: { display: "flex", gap: 8, marginTop: 6 },
721
820
  actionBtn: {
722
821
  display: "inline-flex",
723
822
  alignItems: "center",
724
- padding: "4px 12px",
823
+ padding: "3px 10px",
725
824
  fontSize: 12,
726
825
  borderRadius: 6,
727
826
  border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.4))",
728
- background: "var(--dsw-alias-button-tool-bar-fill, transparent)",
827
+ // 幽灵按钮:button-tool-bar-fill 在当前主题是 50% 灰(#54555780),整排灰块
828
+ // 是面板显灰的主因,改为透明底 + 细描边,与输入卡的工具按钮同语言。
829
+ background: "transparent",
729
830
  color: "var(--dsw-alias-label-primary, inherit)",
730
831
  cursor: "pointer"
731
832
  },
@@ -779,7 +880,11 @@ function createResultDock(controller) {
779
880
  const [copied, setCopied] = (0, import_react3.useState)(false);
780
881
  const [analysisOpen, setAnalysisOpen] = (0, import_react3.useState)(true);
781
882
  const [undoneFlash, setUndoneFlash] = (0, import_react3.useState)(false);
782
- const owns = state.open && state.last?.sessionId === props.sessionId;
883
+ const p = props;
884
+ const input = (p.useInput ? p.useInput((s) => s) : p.input) ?? {};
885
+ const session = (p.useSession ? p.useSession((s) => s) : p.session) ?? {};
886
+ const inputActions = p.inputActions;
887
+ const owns = state.open && state.last?.sessionId === p.sessionId;
783
888
  (0, import_react3.useEffect)(() => {
784
889
  if (!owns) return;
785
890
  const onKey = (event) => {
@@ -791,9 +896,9 @@ function createResultDock(controller) {
791
896
  return () => document.removeEventListener("keydown", onKey);
792
897
  }, [owns]);
793
898
  const applied = state.applied;
794
- const draft = props.input.draft;
795
- const running = Boolean(props.session?.running);
796
- const queued = props.session?.queue?.length ?? 0;
899
+ const draft = input.draft ?? "";
900
+ const running = Boolean(session.running);
901
+ const queued = session.queue?.length ?? 0;
797
902
  const prevRef = (0, import_react3.useRef)({ running, queued });
798
903
  (0, import_react3.useEffect)(() => {
799
904
  const prev = prevRef.current;
@@ -854,97 +959,101 @@ function createResultDock(controller) {
854
959
  const onReplace = () => {
855
960
  if (!result) return;
856
961
  const nextDraft = state.last?.prefix ? `${state.last.prefix} ${result.optimized}` : result.optimized;
857
- controller.markApplied({ backup: props.input.draft, text: nextDraft });
858
- props.inputActions.setDraft(nextDraft);
962
+ controller.markApplied({ backup: input.draft ?? "", text: nextDraft });
963
+ inputActions?.setDraft(nextDraft);
859
964
  };
860
965
  const onUndo = () => {
861
966
  if (!applied) return;
862
- props.inputActions.setDraft(applied.backup);
967
+ inputActions?.setDraft(applied.backup);
863
968
  controller.clearApplied();
864
969
  setUndoneFlash(true);
865
970
  };
866
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.panel, role: "dialog", "aria-label": t("panel.aria"), children: [
867
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.header, children: [
868
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SparkleIcon, { size: 15 }),
869
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: styles.title, children: t("panel.title") }),
870
- result && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
871
- "span",
872
- {
873
- style: styles.modelBadge,
874
- title: result.fallbackUsed && result.fallbackReason ? `${t("panel.fallback")}: ${result.fallbackReason}` : void 0,
875
- children: [
876
- result.provider,
877
- " / ",
878
- result.model,
879
- result.fallbackUsed ? ` \xB7 ${t("panel.fallback")}` : "",
880
- typeof result.durationMs === "number" ? ` \xB7 ${t("panel.duration")} ${(result.durationMs / 1e3).toFixed(1)}s` : ""
881
- ]
882
- }
883
- ),
884
- applied && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: styles.statusChip, children: t("panel.appliedShort") }),
885
- !applied && undoneFlash && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: styles.statusChip, children: t("panel.undoneShort") }),
886
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.close, title: t("panel.closeTitle"), onClick: () => controller.close(), children: "\u2715" })
887
- ] }),
888
- state.status === "loading" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
889
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.loading, children: [
890
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SparkleIcon, { spinning: true }),
891
- stage,
892
- "\u2026(",
893
- elapsed,
894
- "s,",
895
- t("panel.escCancel"),
896
- ")"
897
- ] }),
898
- liveBody
899
- ] }),
900
- state.status === "cancelled" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
901
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.cancelledHint, children: t("panel.cancelled") }),
902
- liveBody,
903
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.actions, children: [
904
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: { ...styles.actionBtn, ...styles.primaryBtn }, title: t("panel.reoptimizeTitle"), onClick: () => controller.retry(), children: t("panel.reoptimize") }),
905
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: () => controller.close(), children: t("panel.close") })
906
- ] })
907
- ] }),
908
- state.status === "error" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
909
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.sectionTitle, children: t("panel.error") }),
910
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.errorText, children: state.error }),
911
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.actions, children: [
912
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, title: t("panel.reoptimizeTitle"), onClick: () => controller.retry(), children: t("panel.retry") }),
913
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: () => controller.close(), children: t("panel.close") })
914
- ] })
915
- ] }),
916
- state.status === "done" && result && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
917
- !result.wellFormed && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { ...styles.warnBanner, marginTop: 0, marginBottom: 8 }, children: [
918
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "aria-hidden": true, children: "\u26A0" }),
919
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: t("panel.notWellFormed") })
971
+ return (
972
+ // 非模态 dock(不抢焦点、无焦点陷阱),用 region 而非 dialog:
973
+ // dialog 会让读屏用户期待焦点管理,而这里并没有。
974
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.panel, role: "region", "aria-label": t("panel.aria"), children: [
975
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.header, children: [
976
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SparkleIcon, { size: 15 }),
977
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: styles.title, children: t("panel.title") }),
978
+ result && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
979
+ "span",
980
+ {
981
+ style: styles.modelBadge,
982
+ title: result.fallbackUsed && result.fallbackReason ? `${t("panel.fallback")}: ${result.fallbackReason}` : void 0,
983
+ children: [
984
+ result.provider,
985
+ " / ",
986
+ result.model,
987
+ result.fallbackUsed ? ` \xB7 ${t("panel.fallback")}` : "",
988
+ typeof result.durationMs === "number" ? ` \xB7 ${t("panel.duration")} ${(result.durationMs / 1e3).toFixed(1)}s` : ""
989
+ ]
990
+ }
991
+ ),
992
+ applied && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: styles.statusChip, children: t("panel.appliedShort") }),
993
+ !applied && undoneFlash && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: styles.statusChip, children: t("panel.undoneShort") }),
994
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.close, title: t("panel.closeTitle"), onClick: () => controller.close(), children: "\u2715" })
920
995
  ] }),
921
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.body, children: [
922
- result.analysis && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
923
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("button", { className: "dsh-po-btn", type: "button", style: styles.sectionTitle, onClick: () => setAnalysisOpen((v) => !v), "aria-expanded": analysisOpen, children: [
924
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { ...styles.chevron, transform: analysisOpen ? "rotate(90deg)" : "none" }, children: "\u25B8" }),
925
- t("panel.analysis")
926
- ] }),
927
- analysisOpen && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.analysisBody, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("pre", { style: styles.pre, children: result.analysis }) })
996
+ state.status === "loading" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
997
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.loading, children: [
998
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SparkleIcon, { spinning: true }),
999
+ stage,
1000
+ "\u2026(",
1001
+ elapsed,
1002
+ "s,",
1003
+ t("panel.escCancel"),
1004
+ ")"
928
1005
  ] }),
929
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { ...styles.sectionTitle, cursor: "default" }, children: t("panel.optimized") }),
930
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.optimizedBox, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("pre", { style: styles.pre, children: result.optimized }) }),
931
- result.truncated && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.warnBanner, children: [
932
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "aria-hidden": true, children: "\u26A0" }),
933
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: t("panel.truncated") })
1006
+ liveBody
1007
+ ] }),
1008
+ state.status === "cancelled" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1009
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.cancelledHint, children: t("panel.cancelled") }),
1010
+ liveBody,
1011
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.actions, children: [
1012
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: { ...styles.actionBtn, ...styles.primaryBtn }, title: t("panel.reoptimizeTitle"), onClick: () => controller.retry(), children: t("panel.reoptimize") }),
1013
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: () => controller.close(), children: t("panel.close") })
934
1014
  ] })
935
1015
  ] }),
936
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.actions, children: applied ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
937
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: { ...styles.actionBtn, ...styles.primaryBtn }, onClick: onUndo, children: t("panel.undo") }),
938
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, title: t("panel.reoptimizeTitle"), onClick: () => controller.retry(), children: t("panel.reoptimize") }),
939
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: () => controller.close(), children: t("panel.close") })
940
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
941
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: { ...styles.actionBtn, ...styles.primaryBtn }, onClick: onReplace, children: t("panel.replace") }),
942
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: onCopy, children: copied ? t("panel.copied") : t("panel.copy") }),
943
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, title: t("panel.reoptimizeTitle"), onClick: () => controller.retry(), children: t("panel.reoptimize") }),
944
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: () => controller.close(), children: t("panel.close") })
945
- ] }) })
1016
+ state.status === "error" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1017
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.sectionTitle, children: t("panel.error") }),
1018
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.errorText, children: state.error }),
1019
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.actions, children: [
1020
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, title: t("panel.reoptimizeTitle"), onClick: () => controller.retry(), children: t("panel.retry") }),
1021
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: () => controller.close(), children: t("panel.close") })
1022
+ ] })
1023
+ ] }),
1024
+ state.status === "done" && result && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1025
+ !result.wellFormed && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { ...styles.warnBanner, marginTop: 0, marginBottom: 8 }, children: [
1026
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "aria-hidden": true, children: "\u26A0" }),
1027
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: t("panel.notWellFormed") })
1028
+ ] }),
1029
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.body, children: [
1030
+ result.analysis && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1031
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("button", { className: "dsh-po-btn", type: "button", style: styles.sectionTitle, onClick: () => setAnalysisOpen((v) => !v), "aria-expanded": analysisOpen, children: [
1032
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { ...styles.chevron, transform: analysisOpen ? "rotate(90deg)" : "none" }, children: "\u25B8" }),
1033
+ t("panel.analysis")
1034
+ ] }),
1035
+ analysisOpen && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.analysisBody, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("pre", { style: styles.pre, children: result.analysis }) })
1036
+ ] }),
1037
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { ...styles.sectionTitle, cursor: "default" }, children: t("panel.optimized") }),
1038
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.optimizedBox, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("pre", { style: styles.pre, children: result.optimized }) }),
1039
+ result.truncated && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.warnBanner, children: [
1040
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "aria-hidden": true, children: "\u26A0" }),
1041
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: t("panel.truncated") })
1042
+ ] })
1043
+ ] }),
1044
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.actions, children: applied ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1045
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: { ...styles.actionBtn, ...styles.primaryBtn }, onClick: onUndo, children: t("panel.undo") }),
1046
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, title: t("panel.reoptimizeTitle"), onClick: () => controller.retry(), children: t("panel.reoptimize") }),
1047
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: () => controller.close(), children: t("panel.close") })
1048
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1049
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: { ...styles.actionBtn, ...styles.primaryBtn }, onClick: onReplace, children: t("panel.replace") }),
1050
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: onCopy, children: copied ? t("panel.copied") : t("panel.copy") }),
1051
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, title: t("panel.reoptimizeTitle"), onClick: () => controller.retry(), children: t("panel.reoptimize") }),
1052
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: () => controller.close(), children: t("panel.close") })
1053
+ ] }) })
1054
+ ] })
946
1055
  ] })
947
- ] });
1056
+ );
948
1057
  };
949
1058
  }
950
1059
 
@@ -972,91 +1081,102 @@ function GitHubIcon(props) {
972
1081
  // src/client/SettingsCard.tsx
973
1082
  var import_jsx_runtime5 = require("react/jsx-runtime");
974
1083
  var REPO_URL = "https://github.com/Y1X1n/dsh-prompt-optimizer";
975
- var FOLLOW_SESSION = "";
976
- var styles2 = {
977
- card: {
978
- border: "1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.3))",
979
- borderRadius: 10,
980
- padding: "14px 16px",
981
- fontSize: 13,
982
- lineHeight: 1.6,
983
- color: "var(--dsw-alias-label-primary, inherit)",
984
- fontFamily: "var(--dsw-font-family, inherit)"
985
- },
986
- title: { fontSize: 14, fontWeight: 600 },
987
- desc: { color: "var(--dsw-alias-label-primary-dimmed, rgba(128,128,128,0.9))", marginBottom: 12 },
988
- headerBtn: {
989
- display: "flex",
990
- alignItems: "center",
991
- gap: 6,
992
- width: "100%",
993
- padding: 0,
994
- border: "none",
995
- background: "none",
996
- color: "inherit",
997
- font: "inherit",
998
- cursor: "pointer",
999
- textAlign: "left"
1000
- },
1001
- chevron: {
1002
- fontSize: 11,
1003
- color: "var(--dsw-alias-label-primary-dimmed, rgba(128,128,128,0.9))",
1004
- transition: "transform 0.15s ease"
1005
- },
1006
- headerDesc: {
1007
- marginLeft: "auto",
1008
- fontSize: 12,
1009
- fontWeight: 400,
1010
- color: "var(--dsw-alias-label-primary-dimmed, rgba(128,128,128,0.9))"
1011
- },
1012
- body: { marginTop: 12 },
1013
- row: { display: "flex", alignItems: "center", gap: 10, marginBottom: 10 },
1014
- label: { width: 110, flexShrink: 0, color: "var(--dsw-alias-label-primary, inherit)" },
1015
- input: {
1016
- flex: 1,
1017
- maxWidth: 320,
1018
- padding: "4px 8px",
1019
- fontSize: 13,
1020
- borderRadius: 6,
1021
- border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.4))",
1022
- background: "var(--dsw-alias-bg-layer-1, transparent)",
1023
- color: "var(--dsw-alias-label-primary, inherit)"
1024
- },
1025
- hint: { color: "var(--dsw-alias-label-primary-dimmed, rgba(128,128,128,0.9))", fontSize: 12 },
1026
- // U13:分组小标题(模型 / 调用参数 / 上下文),带浅分隔线。
1027
- groupTitle: {
1028
- margin: "14px 0 8px",
1029
- paddingTop: 8,
1030
- borderTop: "1px solid var(--dsw-alias-border-l3, rgba(128,128,128,0.18))",
1031
- fontSize: 11,
1032
- fontWeight: 600,
1033
- color: "var(--dsw-alias-label-primary-dimmed, rgba(128,128,128,0.9))"
1034
- },
1035
- fieldError: { color: "var(--dsw-alias-state-error-primary, #e5534b)", fontSize: 12 },
1036
- refreshBtn: {
1037
- flexShrink: 0,
1038
- padding: "4px 10px",
1039
- fontSize: 12,
1040
- borderRadius: 6,
1041
- border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.4))",
1042
- background: "var(--dsw-alias-button-tool-bar-fill, transparent)",
1043
- color: "var(--dsw-alias-label-primary, inherit)",
1044
- cursor: "pointer"
1045
- },
1046
- // 标题右侧的 GitHub 仓库入口:点击在新标签打开仓库主页。
1047
- repoLink: {
1048
- display: "inline-flex",
1049
- alignItems: "center",
1050
- marginLeft: 8,
1051
- padding: 4,
1052
- color: "var(--dsw-alias-label-primary-dimmed, rgba(128,128,128,0.9))",
1053
- background: "none",
1054
- border: "none",
1055
- borderRadius: 6,
1056
- cursor: "pointer",
1057
- textDecoration: "none"
1058
- }
1059
- };
1084
+ var STYLES_ID = "dsh-prompt-optimizer-settings-styles";
1085
+ function ensureStyles() {
1086
+ if (typeof document === "undefined") return;
1087
+ if (document.getElementById(STYLES_ID)) return;
1088
+ const style = document.createElement("style");
1089
+ style.id = STYLES_ID;
1090
+ style.textContent = `
1091
+ .dsh-po-sec{display:flex;flex-direction:column;width:100%;color:var(--dsw-alias-label-primary)}
1092
+ .dsh-po-group{margin:14px 0 2px;padding:0;font-size:12px;font-weight:600;line-height:18px;color:var(--dsw-alias-label-secondary)}
1093
+ .dsh-po-row{display:flex;justify-content:space-between;align-items:center;gap:24px;padding:14px 0;border-bottom:0.5px solid var(--dsw-alias-border-l2)}
1094
+ .dsh-po-row:last-child{border-bottom:none}
1095
+ .dsh-po-rowText{min-width:0}
1096
+ .dsh-po-rowTitle{font-size:14px;line-height:20px}
1097
+ .dsh-po-rowDesc{margin-top:4px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}
1098
+ .dsh-po-hint{padding:10px 0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}
1099
+ .dsh-po-status{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}
1100
+ /* \u5206\u6BB5\u63A7\u4EF6(\u5B98\u65B9 SegmentedControl \u540C\u6B3E):\u6D45\u5E95\u8F68\u9053 + \u9009\u4E2D\u767D\u80F6\u56CA\u6ED1\u52A8\u6307\u793A\u3002 */
1101
+ .dsh-po-seg{position:relative;display:inline-grid;grid-auto-flow:column;grid-auto-columns:1fr;gap:2px;padding:4px;border-radius:var(--dsw-radius-md,8px);background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,0.14));flex:none}
1102
+ .dsh-po-segIndicator{position:absolute;top:4px;left:4px;width:calc((100% - 8px - 2px*(var(--dsh-segment-count) - 1))/var(--dsh-segment-count));height:calc(100% - 8px);border:0;border-radius:var(--dsw-radius-sm,6px);background:var(--dsw-alias-bg-layer-1,#fff);box-shadow:var(--dsw-elevation-soft,0 1px 2px rgba(0,0,0,0.12));transform:translateX(calc(var(--dsh-segment-index)*(100% + 2px)));transition:transform 160ms ease;pointer-events:none}
1103
+ .dsh-po-segTab{box-sizing:border-box;position:relative;z-index:1;height:28px;padding:0 16px;border:0;border-radius:var(--dsw-radius-sm,6px);background:transparent;color:var(--dsw-alias-label-secondary,inherit);font:inherit;font-size:13px;line-height:20px;font-weight:500;white-space:nowrap;cursor:pointer;transition:color 120ms ease}
1104
+ .dsh-po-segTab:hover:not(:disabled),.dsh-po-segTab[aria-selected='true']{color:var(--dsw-alias-label-primary,inherit)}
1105
+ .dsh-po-segTab:disabled{cursor:default;opacity:0.4}
1106
+ /* \u5F00\u5173(\u5B98\u65B9 Switch \u540C\u6B3E):36\xD720 \u80F6\u56CA\u8F68\u9053 + 16px \u5706\u5F62\u6ED1\u5757\u3002 */
1107
+ .dsh-po-switch{box-sizing:border-box;position:relative;flex:0 0 auto;width:36px;height:20px;padding:2px;border:0;border-radius:999px;background:var(--dsw-alias-border-l3,rgba(128,128,128,0.4));cursor:pointer}
1108
+ .dsh-po-switch[aria-checked='true']{background:var(--dsw-alias-brand-primary,#4f7cf7)}
1109
+ .dsh-po-switch:disabled{cursor:default;opacity:0.5}
1110
+ .dsh-po-switchThumb{display:block;width:16px;height:16px;border-radius:50%;background:var(--dsw-alias-label-primary-foreground,#fff);transition:transform 120ms ease}
1111
+ .dsh-po-switch[aria-checked='false'] .dsh-po-switchThumb{background:var(--dsw-alias-switch-thumb,#fff)}
1112
+ .dsh-po-switch[aria-checked='true'] .dsh-po-switchThumb{transform:translateX(16px)}
1113
+ /* \u884C\u5185\u63A7\u4EF6:select / input / \u6B21\u7EA7\u6309\u94AE\u3002 */
1114
+ .dsh-po-select{flex:none;max-width:280px;padding:5px 28px 5px 10px;font:inherit;font-size:13px;line-height:20px;border-radius:var(--dsw-radius-md,8px);border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,0.35));background:var(--dsw-alias-bg-layer-1,transparent) no-repeat right 10px center/10px;appearance:none;color:var(--dsw-alias-label-primary,inherit);cursor:pointer}
1115
+ .dsh-po-input{flex:none;width:150px;padding:5px 10px;font:inherit;font-size:13px;line-height:20px;border-radius:var(--dsw-radius-md,8px);border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,0.35));background:var(--dsw-alias-bg-layer-1,transparent);color:var(--dsw-alias-label-primary,inherit)}
1116
+ .dsh-po-input:focus-visible,.dsh-po-select:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary,#4f7cf7));outline-offset:1px}
1117
+ .dsh-po-btn2{flex:none;padding:5px 14px;font:inherit;font-size:13px;line-height:20px;border-radius:var(--dsw-radius-md,8px);border:1px solid var(--dsw-alias-border-l2,rgba(128,128,128,0.35));background:transparent;color:var(--dsw-alias-label-primary,inherit);cursor:pointer;white-space:nowrap;transition:background-color 120ms ease}
1118
+ .dsh-po-btn2:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,0.14))}
1119
+ .dsh-po-btn2:disabled{opacity:0.45;cursor:default}
1120
+ .dsh-po-fieldError{font-size:12px;line-height:18px;color:var(--dsw-alias-state-error-primary,#e5534b)}
1121
+ /* \u9009\u4E2D\u884C\u63A7\u4EF6\u7684\u8868\u5355\u9519\u8BEF\u6001(\u6587\u672C\u8F93\u5165\u6821\u9A8C\u5931\u8D25)\u3002 */
1122
+ .dsh-po-input[data-invalid='true']{border-color:var(--dsw-alias-state-error-primary,#e5534b)}
1123
+ `;
1124
+ document.head.appendChild(style);
1125
+ }
1126
+ function Row({ title, desc, children }) {
1127
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsh-po-row", children: [
1128
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsh-po-rowText", children: [
1129
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-rowTitle", children: title }),
1130
+ desc && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-rowDesc", children: desc })
1131
+ ] }),
1132
+ children
1133
+ ] });
1134
+ }
1135
+ function Segmented(props) {
1136
+ const selected = props.options.findIndex((o) => o.value === props.value);
1137
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1138
+ "span",
1139
+ {
1140
+ className: "dsh-po-seg",
1141
+ role: "tablist",
1142
+ "aria-label": props.label,
1143
+ style: { "--dsh-segment-count": props.options.length, "--dsh-segment-index": selected < 0 ? 0 : selected },
1144
+ children: [
1145
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "dsh-po-segIndicator", "aria-hidden": "true" }),
1146
+ props.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1147
+ "button",
1148
+ {
1149
+ type: "button",
1150
+ role: "tab",
1151
+ className: "dsh-po-segTab dsh-po-btn",
1152
+ "aria-selected": option.value === props.value,
1153
+ title: option.title,
1154
+ onClick: () => {
1155
+ if (option.value !== props.value) props.onChange(option.value);
1156
+ },
1157
+ children: option.label
1158
+ },
1159
+ option.value
1160
+ ))
1161
+ ]
1162
+ }
1163
+ );
1164
+ }
1165
+ function Toggle(props) {
1166
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1167
+ "button",
1168
+ {
1169
+ type: "button",
1170
+ role: "switch",
1171
+ className: "dsh-po-switch dsh-po-btn",
1172
+ "aria-checked": props.checked,
1173
+ "aria-label": props.label,
1174
+ disabled: props.disabled,
1175
+ onClick: () => props.onChange(!props.checked),
1176
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "dsh-po-switchThumb" })
1177
+ }
1178
+ );
1179
+ }
1060
1180
  function TextField(props) {
1061
1181
  const [text, setText] = (0, import_react4.useState)(props.value);
1062
1182
  const [error, setError] = (0, import_react4.useState)(null);
@@ -1074,15 +1194,17 @@ function TextField(props) {
1074
1194
  setError(null);
1075
1195
  props.onCommit(text);
1076
1196
  };
1077
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1078
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, title: props.labelTitle, children: props.label }),
1197
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "flex", flexDirection: "column", alignItems: "flex-end", gap: 2, flex: "none" }, children: [
1079
1198
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1080
1199
  "input",
1081
1200
  {
1082
- className: "dsh-po-btn",
1083
- style: { ...styles2.input, ...error ? { borderColor: "var(--dsw-alias-state-error-primary, #e5534b)" } : {} },
1201
+ className: "dsh-po-input dsh-po-btn",
1202
+ "data-invalid": error ? "true" : void 0,
1203
+ style: props.width ? { width: props.width } : void 0,
1084
1204
  value: text,
1085
1205
  placeholder: props.placeholder,
1206
+ "aria-label": props.label,
1207
+ title: props.labelTitle,
1086
1208
  onChange: (e) => {
1087
1209
  setText(e.target.value);
1088
1210
  setError(null);
@@ -1093,17 +1215,48 @@ function TextField(props) {
1093
1215
  }
1094
1216
  }
1095
1217
  ),
1096
- error && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.fieldError, children: error })
1218
+ error && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "dsh-po-fieldError", children: error })
1219
+ ] });
1220
+ }
1221
+ function ModelSelect(props) {
1222
+ if (props.groups === null) {
1223
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "dsh-po-status", style: { flex: "none", maxWidth: 300, textAlign: "right" }, children: [
1224
+ props.catalogState === "error" ? "\u2014" : "\u2026",
1225
+ props.catalogHint ? `(${props.catalogHint})` : ""
1226
+ ] });
1227
+ }
1228
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { style: { display: "inline-flex", alignItems: "center", gap: 8, flex: "none" }, children: [
1229
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1230
+ "select",
1231
+ {
1232
+ className: "dsh-po-select dsh-po-btn",
1233
+ style: { backgroundImage: catalogChevron() },
1234
+ value: props.value,
1235
+ "aria-label": props.label,
1236
+ onChange: (e) => props.onChange(e.target.value),
1237
+ children: [
1238
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "", children: props.noneLabel }),
1239
+ props.groups.map((g) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("optgroup", { label: g.name, children: g.models.map((m) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: `${g.id}/${m.id}`, children: m.name }, `${g.id}/${m.id}`)) }, g.id))
1240
+ ]
1241
+ }
1242
+ ),
1243
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { className: "dsh-po-btn2 dsh-po-btn", type: "button", title: props.refreshTitle, onClick: props.onRefresh, children: props.refreshLabel })
1097
1244
  ] });
1098
1245
  }
1099
- function createSettingsCard(ctx, scope) {
1246
+ function catalogChevron() {
1247
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="10" height="6" viewBox="0 0 10 6"><path d="M1 1l4 4 4-4" fill="none" stroke="%23888" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
1248
+ return `url("data:image/svg+xml,${svg.replace(/"/g, "'")}")`;
1249
+ }
1250
+ function createSettingsCard(ctx, face2) {
1251
+ ensureStyles();
1100
1252
  return function PromptOptimizerSettingsCard() {
1101
1253
  const snap = (0, import_react4.useSyncExternalStore)(
1102
- (callback) => scope.subscribe(callback),
1103
- () => scope.getSnapshot()
1254
+ (callback) => face2.subscribe(callback),
1255
+ () => face2.getSnapshot()
1104
1256
  );
1105
1257
  const t = useT();
1106
1258
  const value = snap.value ?? {};
1259
+ const writable = snap.writable !== false;
1107
1260
  const SETTING_KEYS = [
1108
1261
  "language",
1109
1262
  "model",
@@ -1122,7 +1275,8 @@ function createSettingsCard(ctx, scope) {
1122
1275
  fallbackModel: "",
1123
1276
  maxTokens: 8192,
1124
1277
  timeoutSeconds: 120,
1125
- mode: "full",
1278
+ // 与 Host 侧 Config 默认口径一致(0.5.0 起默认快速模式)。
1279
+ mode: "fast",
1126
1280
  reasoningEffort: "lowest",
1127
1281
  temperature: 0.2,
1128
1282
  autoMaxTokens: true,
@@ -1137,7 +1291,7 @@ function createSettingsCard(ctx, scope) {
1137
1291
  if (undoStack.current.length > 20) undoStack.current.shift();
1138
1292
  setCanUndo(true);
1139
1293
  }
1140
- void scope.set(key, v);
1294
+ void face2.set(key, v);
1141
1295
  };
1142
1296
  const undoLastChange = () => {
1143
1297
  const prev = undoStack.current.pop();
@@ -1148,7 +1302,7 @@ function createSettingsCard(ctx, scope) {
1148
1302
  for (const k of SETTING_KEYS) {
1149
1303
  const target = prev[k] ?? SETTING_DEFAULTS[k];
1150
1304
  if (value[k] !== target) {
1151
- void scope.set(k, target);
1305
+ void face2.set(k, target);
1152
1306
  }
1153
1307
  }
1154
1308
  } finally {
@@ -1157,17 +1311,26 @@ function createSettingsCard(ctx, scope) {
1157
1311
  };
1158
1312
  const [groups, setGroups] = (0, import_react4.useState)(null);
1159
1313
  const [catalogState, setCatalogState] = (0, import_react4.useState)("loading");
1314
+ const [catalogHint, setCatalogHint] = (0, import_react4.useState)(null);
1160
1315
  const loadCatalog = async () => {
1161
1316
  setCatalogState("loading");
1317
+ setCatalogHint(null);
1162
1318
  try {
1163
- const resp = await ctx.connection.api.llm.models({});
1164
- if (resp.result.ok) {
1165
- setGroups(resp.result.value.groups);
1319
+ const result = await sessionCatalog(ctx.connection);
1320
+ if (result.ok) {
1321
+ setGroups(result.value.groups);
1166
1322
  setCatalogState("ready");
1323
+ const failures = result.value.failures ?? [];
1324
+ if (failures.length) {
1325
+ setCatalogHint(failures.map((f) => `${f.name || f.id}: ${f.message}`).join("; "));
1326
+ }
1167
1327
  } else {
1328
+ const message = typeof result.error === "string" ? result.error : result.error?.message;
1329
+ setCatalogHint(message ?? null);
1168
1330
  setCatalogState("error");
1169
1331
  }
1170
- } catch {
1332
+ } catch (cause) {
1333
+ setCatalogHint(cause instanceof Error ? cause.message : String(cause));
1171
1334
  setCatalogState("error");
1172
1335
  }
1173
1336
  };
@@ -1193,262 +1356,265 @@ function createSettingsCard(ctx, scope) {
1193
1356
  setTest({ status: "fail", message: cause instanceof Error ? cause.message : String(cause) });
1194
1357
  }
1195
1358
  };
1196
- const EXPAND_KEY = "dsh-prompt-optimizer.settings-expanded";
1197
- const [expanded, setExpanded] = (0, import_react4.useState)(() => {
1198
- try {
1199
- return localStorage.getItem(EXPAND_KEY) === "1";
1200
- } catch {
1201
- return false;
1202
- }
1203
- });
1204
- const toggle = () => setExpanded((v) => {
1205
- const next = !v;
1206
- try {
1207
- localStorage.setItem(EXPAND_KEY, next ? "1" : "0");
1208
- } catch {
1209
- }
1210
- return next;
1211
- });
1212
- const pinnedModel = value.model?.trim();
1213
- let modelShort = pinnedModel;
1214
- if (!pinnedModel) {
1215
- modelShort = t("settings.model.follow");
1216
- } else if (groups) {
1217
- const slash = pinnedModel.indexOf("/");
1218
- const g = slash > 0 ? groups.find((x) => x.id === pinnedModel.slice(0, slash)) : void 0;
1219
- const m = g?.models.find((mm) => mm.id === pinnedModel.slice(slash + 1));
1220
- if (m) modelShort = m.name;
1221
- }
1222
- const summaryText = `${t("settings.summary.model")}: ${modelShort} \xB7 ${t("settings.summary.mode")}: ${value.mode === "fast" ? t("settings.mode.fast.short") : t("settings.mode.full.short")}`;
1223
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { style: styles2.card, children: [
1224
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "flex", alignItems: "center" }, children: [
1225
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { className: "dsh-po-btn", type: "button", style: { ...styles2.headerBtn, flex: 1 }, onClick: toggle, "aria-expanded": expanded, children: [
1226
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { ...styles2.chevron, transform: expanded ? "rotate(90deg)" : "none" }, children: "\u25B8" }),
1227
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.title, children: t("panel.title") }),
1228
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.headerDesc, children: expanded ? t("settings.desc") : summaryText })
1229
- ] }),
1359
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: "dsh-po-sec", children: [
1360
+ snap.status === "loading" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-hint", children: t("settings.loading") }),
1361
+ snap.status === "unavailable" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-hint", children: t("settings.unavailable") }),
1362
+ !writable && snap.status === "ready" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-hint", children: t("settings.memoryOnly") }),
1363
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-group", children: t("settings.group.model") }),
1364
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.model"), desc: t("settings.model.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1365
+ ModelSelect,
1366
+ {
1367
+ label: t("settings.model"),
1368
+ value: value.model ?? "",
1369
+ groups,
1370
+ catalogState,
1371
+ catalogHint,
1372
+ noneLabel: t("settings.model.follow"),
1373
+ onChange: (v) => setValue("model", v),
1374
+ onRefresh: () => void loadCatalog(),
1375
+ refreshTitle: t("settings.refreshTitle"),
1376
+ refreshLabel: t("settings.refresh")
1377
+ }
1378
+ ) }),
1379
+ groups !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.fallbackModel"), desc: t("settings.fallbackModel.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1380
+ "select",
1381
+ {
1382
+ className: "dsh-po-select dsh-po-btn",
1383
+ style: { backgroundImage: catalogChevron() },
1384
+ value: value.fallbackModel ?? "",
1385
+ "aria-label": t("settings.fallbackModel"),
1386
+ onChange: (e) => setValue("fallbackModel", e.target.value),
1387
+ children: [
1388
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "", children: t("settings.fallbackModel.none") }),
1389
+ groups.map((g) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("optgroup", { label: g.name, children: g.models.map((m) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: `${g.id}/${m.id}`, children: m.name }, `${g.id}/${m.id}`)) }, g.id))
1390
+ ]
1391
+ }
1392
+ ) }),
1393
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.test"), desc: t("settings.test.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { style: { display: "inline-flex", alignItems: "center", gap: 8, flex: "none" }, children: [
1394
+ test.message && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "dsh-po-status", style: { maxWidth: 280, color: test.status === "fail" ? "var(--dsw-alias-state-error-primary,#e5534b)" : void 0 }, children: test.message }),
1230
1395
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1231
- "a",
1396
+ "button",
1232
1397
  {
1233
- className: "dsh-po-btn dsh-po-repo-link",
1234
- href: REPO_URL,
1235
- target: "_blank",
1236
- rel: "noopener noreferrer",
1237
- style: styles2.repoLink,
1238
- title: t("settings.repoTitle"),
1239
- "aria-label": t("settings.repoTitle"),
1240
- onClick: (e) => e.stopPropagation(),
1241
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(GitHubIcon, { size: 16 })
1398
+ className: "dsh-po-btn2 dsh-po-btn",
1399
+ type: "button",
1400
+ disabled: test.status === "testing",
1401
+ onClick: () => void runTest(),
1402
+ children: test.status === "testing" ? t("settings.test.running") : t("settings.test.run")
1242
1403
  }
1243
1404
  )
1244
- ] }),
1245
- expanded && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.body, children: [
1246
- snap.status === "loading" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles2.hint, children: t("settings.loading") }),
1247
- snap.status === "unavailable" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles2.hint, children: t("settings.unavailable") }),
1248
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles2.groupTitle, children: t("settings.group.model") }),
1249
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1250
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, children: t("settings.model") }),
1251
- groups === null ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.hint, children: catalogState === "error" ? t("settings.catalog.error") : t("settings.catalog.loading") }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1252
- "select",
1253
- {
1254
- style: styles2.input,
1255
- value: value.model ?? FOLLOW_SESSION,
1256
- onChange: (e) => void setValue("model", e.target.value),
1257
- children: [
1258
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: FOLLOW_SESSION, children: t("settings.model.follow") }),
1259
- groups.map((g) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("optgroup", { label: g.name, children: g.models.map((m) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: `${g.id}/${m.id}`, children: m.name }, m.id)) }, g.id))
1260
- ]
1261
- }
1262
- ),
1263
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1264
- "button",
1265
- {
1266
- className: "dsh-po-btn",
1267
- type: "button",
1268
- style: { ...styles2.refreshBtn, ...catalogState === "loading" ? { opacity: 0.45, cursor: "default" } : {} },
1269
- disabled: catalogState === "loading",
1270
- title: t("settings.refreshTitle"),
1271
- onClick: () => void loadCatalog(),
1272
- children: t("settings.refresh")
1273
- }
1274
- )
1275
- ] }),
1276
- groups !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1277
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, children: t("settings.fallbackModel") }),
1278
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1279
- "select",
1280
- {
1281
- style: styles2.input,
1282
- value: value.fallbackModel ?? "",
1283
- onChange: (e) => void setValue("fallbackModel", e.target.value),
1284
- children: [
1285
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "", children: t("settings.fallbackModel.none") }),
1286
- groups.map((g) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("optgroup", { label: g.name, children: g.models.map((m) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: `${g.id}/${m.id}`, children: m.name }, m.id)) }, g.id))
1287
- ]
1288
- }
1289
- )
1290
- ] }),
1291
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1292
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, children: t("settings.test") }),
1293
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1294
- "button",
1295
- {
1296
- className: "dsh-po-btn",
1297
- type: "button",
1298
- style: { ...styles2.refreshBtn, ...test.status === "testing" ? { opacity: 0.45, cursor: "default" } : {} },
1299
- disabled: test.status === "testing",
1300
- onClick: () => void runTest(),
1301
- children: test.status === "testing" ? t("settings.test.running") : t("settings.test.run")
1302
- }
1303
- ),
1304
- test.message && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: test.status === "fail" ? styles2.fieldError : styles2.hint, children: test.message })
1305
- ] }),
1306
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles2.groupTitle, children: t("settings.group.params") }),
1307
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1308
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, children: t("settings.language") }),
1309
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1310
- "select",
1311
- {
1312
- style: { ...styles2.input, maxWidth: 160 },
1313
- value: value.language ?? "zh",
1314
- onChange: (e) => void setValue("language", e.target.value),
1315
- children: [
1316
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "zh", children: "\u4E2D\u6587" }),
1317
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "en", children: "English" })
1318
- ]
1319
- }
1320
- )
1321
- ] }),
1322
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1323
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, children: t("settings.mode") }),
1324
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1325
- "select",
1326
- {
1327
- style: { ...styles2.input, maxWidth: 260 },
1328
- value: value.mode ?? "full",
1329
- onChange: (e) => void setValue("mode", e.target.value),
1330
- children: [
1331
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "full", children: t("settings.mode.full") }),
1332
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "fast", children: t("settings.mode.fast") })
1333
- ]
1334
- }
1335
- )
1336
- ] }),
1337
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1338
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, children: t("settings.effort") }),
1339
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1340
- "select",
1341
- {
1342
- style: { ...styles2.input, maxWidth: 260 },
1343
- value: value.reasoningEffort ?? "lowest",
1344
- onChange: (e) => void setValue("reasoningEffort", e.target.value),
1345
- children: [
1346
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "lowest", children: t("settings.effort.lowest") }),
1347
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "session", children: t("settings.effort.session") })
1348
- ]
1349
- }
1350
- )
1351
- ] }),
1352
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles2.groupTitle, children: t("settings.group.context") }),
1353
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1354
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, children: t("settings.includeContext") }),
1355
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1356
- "select",
1357
- {
1358
- style: { ...styles2.input, maxWidth: 260 },
1359
- value: value.includeContext === false ? "off" : "on",
1360
- onChange: (e) => void setValue("includeContext", e.target.value === "on"),
1361
- children: [
1362
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "on", children: t("settings.includeContext.on") }),
1363
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "off", children: t("settings.includeContext.off") })
1364
- ]
1365
- }
1366
- )
1367
- ] }),
1368
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1369
- TextField,
1370
- {
1371
- label: t("settings.maxTokens"),
1372
- value: String(value.maxTokens ?? 8192),
1373
- placeholder: "8192",
1374
- validate: (v) => {
1375
- const n = Number.parseInt(v, 10);
1376
- return Number.isFinite(n) && n >= 1024 && n <= 32768 ? null : t("settings.validate.maxTokens");
1377
- },
1378
- onCommit: (v) => void setValue("maxTokens", Number.parseInt(v, 10))
1379
- }
1380
- ),
1381
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1382
- TextField,
1383
- {
1384
- label: t("settings.timeout"),
1385
- value: String(value.timeoutSeconds ?? 120),
1386
- placeholder: "120",
1387
- validate: (v) => {
1388
- const n = Number.parseInt(v, 10);
1389
- return Number.isFinite(n) && n >= 10 && n <= 600 ? null : t("settings.validate.timeout");
1390
- },
1391
- onCommit: (v) => void setValue("timeoutSeconds", Number.parseInt(v, 10))
1392
- }
1393
- ),
1405
+ ] }) }),
1406
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-group", children: t("settings.group.params") }),
1407
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.language"), desc: t("settings.language.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1408
+ Segmented,
1409
+ {
1410
+ label: t("settings.language"),
1411
+ value: value.language ?? "zh",
1412
+ options: [
1413
+ { value: "zh", label: "\u4E2D\u6587" },
1414
+ { value: "en", label: "English" }
1415
+ ],
1416
+ onChange: (v) => setValue("language", v)
1417
+ }
1418
+ ) }),
1419
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.mode"), desc: t("settings.mode.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1420
+ Segmented,
1421
+ {
1422
+ label: t("settings.mode"),
1423
+ value: value.mode ?? "fast",
1424
+ options: [
1425
+ { value: "full", label: t("settings.mode.full.short"), title: t("settings.mode.full") },
1426
+ { value: "fast", label: t("settings.mode.fast.short"), title: t("settings.mode.fast") }
1427
+ ],
1428
+ onChange: (v) => setValue("mode", v)
1429
+ }
1430
+ ) }),
1431
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.effort"), desc: t("settings.effort.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1432
+ Segmented,
1433
+ {
1434
+ label: t("settings.effort"),
1435
+ value: value.reasoningEffort ?? "lowest",
1436
+ options: [
1437
+ { value: "lowest", label: t("settings.effort.lowest.short"), title: t("settings.effort.lowest") },
1438
+ { value: "session", label: t("settings.effort.session.short"), title: t("settings.effort.session") }
1439
+ ],
1440
+ onChange: (v) => setValue("reasoningEffort", v)
1441
+ }
1442
+ ) }),
1443
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.maxTokens"), desc: t("settings.maxTokens.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1444
+ TextField,
1445
+ {
1446
+ label: t("settings.maxTokens"),
1447
+ value: String(value.maxTokens ?? 8192),
1448
+ placeholder: "8192",
1449
+ validate: (v) => {
1450
+ const n = Number.parseInt(v, 10);
1451
+ return Number.isFinite(n) && n >= 1024 && n <= 32768 ? null : t("settings.validate.maxTokens");
1452
+ },
1453
+ onCommit: (v) => setValue("maxTokens", Number.parseInt(v, 10))
1454
+ }
1455
+ ) }),
1456
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.timeout"), desc: t("settings.timeout.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1457
+ TextField,
1458
+ {
1459
+ label: t("settings.timeout"),
1460
+ value: String(value.timeoutSeconds ?? 120),
1461
+ placeholder: "120",
1462
+ validate: (v) => {
1463
+ const n = Number.parseInt(v, 10);
1464
+ return Number.isFinite(n) && n >= 10 && n <= 600 ? null : t("settings.validate.timeout");
1465
+ },
1466
+ onCommit: (v) => setValue("timeoutSeconds", Number.parseInt(v, 10))
1467
+ }
1468
+ ) }),
1469
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.temperature"), desc: t("settings.temperature.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1470
+ TextField,
1471
+ {
1472
+ label: t("settings.temperature"),
1473
+ labelTitle: t("settings.temperatureTitle"),
1474
+ value: String(value.temperature ?? 0.2),
1475
+ placeholder: "0.2",
1476
+ width: 100,
1477
+ validate: (v) => {
1478
+ const n = Number.parseFloat(v);
1479
+ return Number.isFinite(n) && n >= 0 && n <= 2 ? null : t("settings.validate.temperature");
1480
+ },
1481
+ onCommit: (v) => setValue("temperature", Number.parseFloat(v))
1482
+ }
1483
+ ) }),
1484
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-group", children: t("settings.group.context") }),
1485
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.includeContext"), desc: t("settings.includeContext.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1486
+ Toggle,
1487
+ {
1488
+ label: t("settings.includeContext"),
1489
+ checked: value.includeContext !== false,
1490
+ onChange: (next) => setValue("includeContext", next)
1491
+ }
1492
+ ) }),
1493
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.autoMaxTokens"), desc: t("settings.autoMaxTokens.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1494
+ Toggle,
1495
+ {
1496
+ label: t("settings.autoMaxTokens"),
1497
+ checked: value.autoMaxTokens !== false,
1498
+ onChange: (next) => setValue("autoMaxTokens", next)
1499
+ }
1500
+ ) }),
1501
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsh-po-row", style: { paddingBottom: 4, gap: 12 }, children: [
1394
1502
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1395
- TextField,
1396
- {
1397
- label: t("settings.temperature"),
1398
- labelTitle: t("settings.temperatureTitle"),
1399
- value: String(value.temperature ?? 0.2),
1400
- placeholder: "0.2",
1401
- validate: (v) => {
1402
- const n = Number.parseFloat(v);
1403
- return Number.isFinite(n) && n >= 0 && n <= 2 ? null : t("settings.validate.temperature");
1404
- },
1405
- onCommit: (v) => void setValue("temperature", Number.parseFloat(v))
1406
- }
1407
- ),
1408
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1409
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, children: t("settings.autoMaxTokens") }),
1410
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1411
- "select",
1412
- {
1413
- style: { ...styles2.input, maxWidth: 260 },
1414
- value: value.autoMaxTokens === false ? "off" : "on",
1415
- onChange: (e) => void setValue("autoMaxTokens", e.target.value === "on"),
1416
- children: [
1417
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "on", children: t("settings.autoMaxTokens.on") }),
1418
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "off", children: t("settings.autoMaxTokens.off") })
1419
- ]
1420
- }
1421
- )
1422
- ] }),
1423
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles2.row, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1424
1503
  "button",
1425
1504
  {
1426
- className: "dsh-po-btn",
1505
+ className: "dsh-po-btn2 dsh-po-btn",
1427
1506
  type: "button",
1428
- style: { ...styles2.refreshBtn, ...!canUndo ? { opacity: 0.45, cursor: "default" } : {} },
1429
1507
  disabled: !canUndo,
1430
1508
  title: t("settings.undoTitle"),
1431
1509
  onClick: undoLastChange,
1432
1510
  children: t("settings.undo")
1433
1511
  }
1434
- ) }),
1435
- !snap.writable && snap.status === "ready" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles2.hint, children: t("settings.memoryOnly") })
1512
+ ),
1513
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1514
+ "a",
1515
+ {
1516
+ className: "dsh-po-repo-link dsh-po-btn",
1517
+ href: REPO_URL,
1518
+ target: "_blank",
1519
+ rel: "noreferrer noopener",
1520
+ title: t("settings.repoTitle"),
1521
+ style: {
1522
+ display: "inline-flex",
1523
+ alignItems: "center",
1524
+ gap: 6,
1525
+ padding: "4px 10px",
1526
+ fontSize: 12,
1527
+ borderRadius: 6,
1528
+ color: "var(--dsw-alias-label-secondary, inherit)",
1529
+ textDecoration: "none"
1530
+ },
1531
+ children: [
1532
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(GitHubIcon, { size: 14 }),
1533
+ "GitHub"
1534
+ ]
1535
+ }
1536
+ )
1436
1537
  ] })
1437
1538
  ] });
1438
1539
  };
1439
1540
  }
1440
1541
 
1542
+ // src/client/settings-face.ts
1543
+ function createSettingsFace() {
1544
+ let backend = null;
1545
+ let offBackend = null;
1546
+ const listeners = /* @__PURE__ */ new Set();
1547
+ let loadingSnapshot = null;
1548
+ let cachedSnapshot = null;
1549
+ const notify = () => {
1550
+ cachedSnapshot = null;
1551
+ for (const listener of listeners) listener();
1552
+ };
1553
+ function use(next) {
1554
+ if (backend?.via === "forms" && next.via === "legacy") return;
1555
+ if (backend === next) return;
1556
+ offBackend?.();
1557
+ backend = next;
1558
+ offBackend = next.subscribeRaw(notify);
1559
+ notify();
1560
+ }
1561
+ const face2 = {
1562
+ subscribe(fn) {
1563
+ listeners.add(fn);
1564
+ return () => {
1565
+ listeners.delete(fn);
1566
+ };
1567
+ },
1568
+ getSnapshot() {
1569
+ if (!backend) {
1570
+ loadingSnapshot ?? (loadingSnapshot = { status: "loading" });
1571
+ return loadingSnapshot;
1572
+ }
1573
+ cachedSnapshot ?? (cachedSnapshot = (() => {
1574
+ const snap = backend.getSnapshot();
1575
+ const status = snap.status === "ready" || snap.status === "unavailable" ? snap.status : "loading";
1576
+ return { status, value: snap.value, writable: snap.writable };
1577
+ })());
1578
+ return cachedSnapshot;
1579
+ },
1580
+ set(key, value) {
1581
+ return backend ? backend.set(key, value) : Promise.reject(new Error("\u8BBE\u7F6E\u670D\u52A1\u5C1A\u672A\u5C31\u7EEA"));
1582
+ }
1583
+ };
1584
+ return {
1585
+ face: face2,
1586
+ attachLegacy(scope) {
1587
+ use({
1588
+ via: "legacy",
1589
+ subscribeRaw: (fn) => scope.subscribe(fn),
1590
+ getSnapshot: () => scope.getSnapshot(),
1591
+ set: (key, value) => scope.set(key, value)
1592
+ });
1593
+ },
1594
+ attachForms(forms, entryId) {
1595
+ const form = forms.get(entryId);
1596
+ use({
1597
+ via: "forms",
1598
+ subscribeRaw: (fn) => form.subscribe(fn),
1599
+ getSnapshot: () => form.getSnapshot(),
1600
+ set: (field, value) => form.set(field, value)
1601
+ });
1602
+ }
1603
+ };
1604
+ }
1605
+
1441
1606
  // src/client/index.tsx
1442
1607
  var name = "dsh-prompt-optimizer-client";
1443
- var inject = ["slots", "connection", "remote", "settingsScope"];
1608
+ var inject = ["slots", "connection", "remote"];
1444
1609
  var BUTTON_CLASS = "dsh-po-btn";
1610
+ var SETTINGS_ENTRY_ID = "prompt-optimizer";
1445
1611
  function ensureFocusStyles() {
1446
1612
  if (typeof document === "undefined") return;
1447
1613
  const ID = "dsh-prompt-optimizer-focus-styles";
1448
1614
  if (document.getElementById(ID)) return;
1449
1615
  const style = document.createElement("style");
1450
1616
  style.id = ID;
1451
- style.textContent = ".dsh-po-btn:focus-visible{outline:2px solid var(--dsw-alias-state-focus-ring, #4f7cf7);outline-offset:2px;border-radius:4px;}.dsh-po-repo-link{transition:color 0.15s ease,background-color 0.15s ease;}.dsh-po-repo-link:hover{color:var(--dsw-alias-label-primary, inherit);background-color:var(--dsw-alias-fill-secondary, rgba(128,128,128,0.12));}";
1617
+ style.textContent = ".dsh-po-btn:focus-visible{outline:2px solid var(--dsw-alias-state-focus-ring, #4f7cf7);outline-offset:2px;border-radius:4px;}.dsh-po-opt{background:color-mix(in srgb, var(--dsw-alias-label-primary, #0f1115) 5%, transparent);}.dsh-po-opt:hover:not(:disabled){background:color-mix(in srgb, var(--dsw-alias-label-primary, #0f1115) 9%, transparent);}.dsh-po-repo-link{transition:color 0.15s ease,background-color 0.15s ease;}.dsh-po-repo-link:hover{color:var(--dsw-alias-label-primary, inherit);background-color:var(--dsw-alias-fill-secondary, rgba(128,128,128,0.12));}";
1452
1618
  document.head.appendChild(style);
1453
1619
  }
1454
1620
  function apply(ctx) {
@@ -1456,7 +1622,20 @@ function apply(ctx) {
1456
1622
  ctx.inject(["locale"], (lctx) => {
1457
1623
  installLocaleFace(lctx.locale ?? null);
1458
1624
  });
1459
- const scope = ctx.settingsScope.bind({ namespace: "prompt-optimizer" });
1625
+ let modelDirectories;
1626
+ ctx.inject(["modelDirectories"], (mctx) => {
1627
+ modelDirectories = mctx.modelDirectories;
1628
+ });
1629
+ const settings = createSettingsFace();
1630
+ ctx.inject(["configForms"], (cctx) => {
1631
+ const forms = cctx.configForms;
1632
+ if (forms) settings.attachForms(forms, SETTINGS_ENTRY_ID);
1633
+ });
1634
+ ctx.inject(["settingsScope"], (sctx) => {
1635
+ const binder = sctx.settingsScope;
1636
+ if (binder) settings.attachLegacy(binder.bind({ namespace: SETTINGS_ENTRY_ID }));
1637
+ });
1638
+ const scope = { getSnapshot: () => settings.face.getSnapshot() };
1460
1639
  const controller = createOptimizerController(ctx, {
1461
1640
  // 与 Host 侧「空字符串视为未设置」的口径一致。
1462
1641
  isModelPinned: () => Boolean(scope.getSnapshot().value?.model?.trim()),
@@ -1465,29 +1644,63 @@ function apply(ctx) {
1465
1644
  // 与 Host 侧「仅 mode==='fast' 为快速」的归一化口径一致。
1466
1645
  isFastMode: () => scope.getSnapshot().value?.mode === "fast",
1467
1646
  // R21:看门狗 = 设置超时秒数 + 5s 余量(正常时 Host 的超时错误先到达,文案更友好)。
1468
- getWatchdogMs: () => ((scope.getSnapshot().value?.timeoutSeconds ?? 120) + 5) * 1e3
1647
+ getWatchdogMs: () => ((scope.getSnapshot().value?.timeoutSeconds ?? 120) + 5) * 1e3,
1648
+ // 「跟随会话」的模型来源(见上);点击时读取,服务缺席走 Host 回退。
1649
+ getSessionModelDirectories: () => modelDirectories
1469
1650
  });
1470
- ctx.slots.inject(
1471
- "conversation.input.right",
1472
- () => ctx.slots.register(
1473
- { name: "conversation.input.right", id: "prompt-optimizer", order: 30 },
1474
- createOptimizeButton(controller)
1475
- )
1476
- );
1477
- ctx.slots.inject(
1478
- "conversation.input.dock",
1479
- () => ctx.slots.register(
1480
- { name: "conversation.input.dock", id: "prompt-optimizer", order: 30 },
1481
- createResultDock(controller)
1482
- )
1483
- );
1484
- ctx.slots.inject(
1485
- "settings.plugin.item",
1486
- () => ctx.slots.register(
1487
- { name: "settings.plugin.item", key: "prompt-optimizer" },
1488
- createSettingsCard(ctx, scope)
1489
- )
1490
- );
1651
+ ctx.inject(["slots", "connection", "remote"], (scopeCtx) => {
1652
+ scopeCtx.slots.inject(
1653
+ "conversation.input.right",
1654
+ () => scopeCtx.slots.register(
1655
+ {
1656
+ name: "conversation.input.right",
1657
+ id: "prompt-optimizer",
1658
+ order: 30,
1659
+ inject: () => ({})
1660
+ },
1661
+ createOptimizeButton(controller)
1662
+ )
1663
+ );
1664
+ scopeCtx.slots.inject(
1665
+ "conversation.input.dock",
1666
+ () => scopeCtx.slots.register(
1667
+ {
1668
+ name: "conversation.input.dock",
1669
+ id: "prompt-optimizer",
1670
+ order: 30,
1671
+ inject: () => ({})
1672
+ },
1673
+ createResultDock(controller)
1674
+ )
1675
+ );
1676
+ });
1677
+ let settingsDisposers = null;
1678
+ const mountSettingsCard = (slotCtx) => {
1679
+ const unmount = () => {
1680
+ for (const dispose of settingsDisposers ?? []) dispose();
1681
+ settingsDisposers = null;
1682
+ };
1683
+ if (settingsDisposers) return unmount;
1684
+ const card = createSettingsCard(slotCtx, settings.face);
1685
+ const slots = slotCtx.slots;
1686
+ settingsDisposers = [
1687
+ slots.register(
1688
+ {
1689
+ name: "settings.plugins.tab",
1690
+ id: SETTINGS_ENTRY_ID,
1691
+ order: 30,
1692
+ label: () => translate("panel.title"),
1693
+ inject: () => ({})
1694
+ },
1695
+ card
1696
+ ),
1697
+ slots.register({ name: "settings.plugin.item", key: SETTINGS_ENTRY_ID }, card)
1698
+ ];
1699
+ return unmount;
1700
+ };
1701
+ const slotsAny = ctx.slots;
1702
+ slotsAny.inject("settings.plugin.item", () => mountSettingsCard(ctx));
1703
+ slotsAny.inject("settings.plugins.tab", () => mountSettingsCard(ctx));
1491
1704
  }
1492
1705
  return module.exports;
1493
1706
  }