@y1x1n/dsh-prompt-optimizer 0.3.16 → 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
@@ -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,17 +262,18 @@ 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) {
@@ -276,15 +287,15 @@ function createOptimizeButton(controller) {
276
287
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { display: "inline-flex" }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
277
288
  "button",
278
289
  {
279
- className: "dsh-po-btn",
290
+ className: "dsh-po-btn dsh-po-opt",
280
291
  type: "button",
281
292
  style: { ...buttonStyle, ...empty || loading ? { opacity: 0.45, cursor: "not-allowed" } : {} },
282
293
  disabled: empty || loading,
283
- title: empty ? t("button.titleEmpty") : t("button.title"),
294
+ title: loading ? t("button.optimizing") : empty ? t("button.titleEmpty") : t("button.title"),
284
295
  onClick: () => void controller.optimize(draft, p.sessionId),
285
296
  children: [
286
297
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SparkleIcon, { spinning: loading }),
287
- loading ? t("button.optimizing") : t("button.optimize")
298
+ t("button.optimize")
288
299
  ]
289
300
  }
290
301
  ) });
@@ -294,6 +305,20 @@ function createOptimizeButton(controller) {
294
305
  // src/client/ResultDock.tsx
295
306
  var import_react3 = require("react");
296
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
+
297
322
  // src/prompt.ts
298
323
  var MARKERS = {
299
324
  analysis: "<<<ANALYSIS>>>",
@@ -301,18 +326,18 @@ var MARKERS = {
301
326
  end: "<<<END>>>"
302
327
  };
303
328
  var FORMAT_FULL_ZH = `# \u8F93\u51FA\u683C\u5F0F(\u4E25\u683C\u9075\u5B88,\u6807\u8BB0\u884C\u5355\u72EC\u6210\u884C)
304
- ${MARKERS.analysis}
305
- \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
329
  ${MARKERS.optimized}
307
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
308
333
  ${MARKERS.end}
309
334
 
310
335
  \u9664\u4E0A\u8FF0\u6807\u8BB0\u5305\u88F9\u7684\u5185\u5BB9\u5916,\u4E0D\u8981\u8F93\u51FA\u4EFB\u4F55\u5176\u4ED6\u6587\u5B57\u3002`;
311
336
  var FORMAT_FULL_EN = `# Output format (strictly follow; markers on their own lines)
312
- ${MARKERS.analysis}
313
- One finding per line: "dimension | issue | suggestion". If a dimension is fine: "dimension | no issue | -".
314
337
  ${MARKERS.optimized}
315
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 | -".
316
341
  ${MARKERS.end}
317
342
 
318
343
  Do not output anything outside these markers.`;
@@ -355,27 +380,70 @@ function findMarker(text, word, fromIndex = 0) {
355
380
  const match = re.exec(text);
356
381
  return match ? { index: match.index, length: match[0].length } : null;
357
382
  }
358
- function parsePartialOptimizerOutput(raw) {
359
- const a = findMarker(raw, "ANALYSIS");
360
- const o = findMarker(raw, "OPTIMIZED");
361
- let analysis = "";
362
- let optimized = "";
363
- if (a && (!o || a.index < o.index)) {
364
- 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 };
365
389
  }
366
- if (o) {
367
- const e = findMarker(raw, "END", o.index + o.length);
368
- 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);
369
419
  }
370
- 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
+ };
371
429
  }
372
430
  function compactPartialBuffer(raw) {
373
- const o = findMarker(raw, "OPTIMIZED");
374
- if (!o) return { compacted: null, analysis: "" };
375
- const a = findMarker(raw, "ANALYSIS");
376
- const analysis = a && a.index < o.index ? raw.slice(a.index + a.length, o.index).trim() : "";
377
- return { compacted: `${MARKERS.optimized}
378
- ${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: "" };
379
447
  }
380
448
 
381
449
  // src/client/controller.ts
@@ -388,6 +456,9 @@ function splitCommandPrefix(text) {
388
456
  if (!match[2] || !match[2].trim()) return { body: trimmed, commandOnly: true };
389
457
  return { prefix: match[1], body: match[2].trim() };
390
458
  }
459
+ function joinLast(last) {
460
+ return last.prefix ? `${last.prefix} ${last.text}` : last.text;
461
+ }
391
462
  function shouldAutoClose(input) {
392
463
  if (!input.open || input.status === "loading") return false;
393
464
  return !input.draft.trim() || !input.prevRunning && input.running || input.queued > input.prevQueued;
@@ -428,6 +499,7 @@ function createOptimizerController(ctx, opts = {}) {
428
499
  let abort = null;
429
500
  let liveRaw = "";
430
501
  let frozenAnalysis = "";
502
+ let frozenOptimized = "";
431
503
  let liveTimer = null;
432
504
  const clearLiveTimer = () => {
433
505
  if (liveTimer) {
@@ -458,6 +530,7 @@ function createOptimizerController(ctx, opts = {}) {
458
530
  clearLiveTimer();
459
531
  liveRaw = "";
460
532
  frozenAnalysis = "";
533
+ frozenOptimized = "";
461
534
  const controller = new AbortController();
462
535
  abort = controller;
463
536
  const watchdogMs = Math.max(1e3, opts.getWatchdogMs?.() ?? 125e3);
@@ -472,7 +545,7 @@ function createOptimizerController(ctx, opts = {}) {
472
545
  set({
473
546
  status: "error",
474
547
  live: null,
475
- 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`
476
549
  });
477
550
  };
478
551
  const startedAt = Date.now();
@@ -482,12 +555,17 @@ function createOptimizerController(ctx, opts = {}) {
482
555
  (async () => {
483
556
  if (opts.isModelPinned?.()) return void 0;
484
557
  try {
485
- const resp2 = await ctx.connection.api.sessions.models({ sessionId }, controller.signal);
486
- if (resp2.result.ok) {
487
- 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) {
488
566
  return { provider: current.provider, model: current.model, reasoningEffort: current.reasoningEffort };
489
567
  }
490
- 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);
491
569
  } catch (cause) {
492
570
  console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u6A21\u578B\u67E5\u8BE2\u5931\u8D25,\u6539\u7528 Host \u56DE\u9000:", cause);
493
571
  }
@@ -496,12 +574,17 @@ function createOptimizerController(ctx, opts = {}) {
496
574
  (async () => {
497
575
  if (!(opts.isContextEnabled?.() ?? true)) return void 0;
498
576
  try {
499
- const resp2 = await ctx.connection.api.sessions.history({ sessionId, maxMessages: 24 }, controller.signal);
500
- if (resp2.result.ok) {
501
- 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 ?? []);
502
585
  return turns.length ? turns : void 0;
503
586
  }
504
- 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);
505
588
  } catch (cause) {
506
589
  console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u5386\u53F2\u67E5\u8BE2\u5931\u8D25,\u6309\u65E0\u4E0A\u4E0B\u6587\u4F18\u5316:", cause);
507
590
  }
@@ -511,7 +594,10 @@ function createOptimizerController(ctx, opts = {}) {
511
594
  const resp = await fetch(ROUTE, {
512
595
  method: "POST",
513
596
  headers: { "content-type": "application/json" },
514
- 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 }),
515
601
  signal: controller.signal
516
602
  });
517
603
  if (!resp.ok || !(resp.headers.get("content-type") ?? "").includes("text/event-stream")) {
@@ -536,7 +622,13 @@ function createOptimizerController(ctx, opts = {}) {
536
622
  buffer = buffer.slice(sep + 2);
537
623
  const line = frame.split("\n").find((l) => l.startsWith("data:"));
538
624
  if (!line) continue;
539
- 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
+ }
540
632
  if (event.type === "delta") {
541
633
  liveRaw += String(event.text ?? "");
542
634
  if (!liveTimer) {
@@ -545,11 +637,12 @@ function createOptimizerController(ctx, opts = {}) {
545
637
  if (state.status === "loading" && abort === controller) {
546
638
  const comp = compactPartialBuffer(liveRaw);
547
639
  if (comp.compacted !== null) {
548
- frozenAnalysis = comp.analysis;
640
+ if (comp.analysis) frozenAnalysis = comp.analysis;
641
+ if (comp.optimized) frozenOptimized = comp.optimized;
549
642
  liveRaw = comp.compacted;
550
643
  }
551
644
  const partial = parsePartialOptimizerOutput(liveRaw);
552
- const live = { analysis: partial.analysis || frozenAnalysis, optimized: partial.optimized };
645
+ const live = { analysis: partial.analysis || frozenAnalysis, optimized: partial.optimized || frozenOptimized };
553
646
  if (opts.isFastMode?.() && !live.analysis && !live.optimized && liveRaw.trim() && !liveRaw.includes("<<<")) {
554
647
  live.optimized = liveRaw.trim();
555
648
  }
@@ -608,7 +701,7 @@ function createOptimizerController(ctx, opts = {}) {
608
701
  getSnapshot: () => state,
609
702
  optimize,
610
703
  retry() {
611
- if (state.last) void optimize(state.last.text, state.last.sessionId);
704
+ if (state.last) void optimize(joinLast(state.last), state.last.sessionId);
612
705
  },
613
706
  markApplied(applied) {
614
707
  set({ applied });
@@ -662,12 +755,14 @@ async function copyText(text) {
662
755
  var styles = {
663
756
  panel: {
664
757
  marginBottom: 6,
665
- borderRadius: 10,
758
+ borderRadius: 12,
666
759
  border: "1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.3))",
667
- background: "var(--dsw-alias-bg-layer-2, #202226)",
760
+ background: "var(--dsw-alias-bg-layer-2, #fff)",
668
761
  color: "var(--dsw-alias-label-primary, inherit)",
669
- boxShadow: "0 4px 16px rgba(0, 0, 0, 0.12)",
670
- 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",
671
766
  fontSize: 12.5,
672
767
  lineHeight: 1.5,
673
768
  fontFamily: "var(--dsw-font-family, inherit)"
@@ -692,12 +787,14 @@ var styles = {
692
787
  // U5:分析与优化各自独立滚动区(原先单容器 maxHeight 嵌套出现双滚动条),
693
788
  // 长内容不再互相挤压;外层 body 不限高,滚动归属到各段内部。
694
789
  body: { paddingRight: 4 },
695
- analysisBody: { maxHeight: "16vh", overflowY: "auto", marginTop: 2 },
790
+ analysisBody: { maxHeight: "14vh", overflowY: "auto", marginTop: 2 },
696
791
  optimizedBox: {
697
- background: "var(--dsw-alias-bg-layer-3, rgba(128,128,128,0.08))",
698
- borderRadius: 6,
699
- padding: "6px 8px",
700
- 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",
701
798
  overflowY: "auto",
702
799
  marginTop: 2
703
800
  },
@@ -709,7 +806,7 @@ var styles = {
709
806
  fontSize: 11,
710
807
  fontWeight: 600,
711
808
  color: "var(--dsw-alias-label-primary-dimmed, rgba(128,128,128,0.9))",
712
- margin: "6px 0 2px",
809
+ margin: "5px 0 2px",
713
810
  padding: 0,
714
811
  border: "none",
715
812
  background: "none",
@@ -719,15 +816,17 @@ var styles = {
719
816
  },
720
817
  chevron: { fontSize: 9, transition: "transform 0.15s ease" },
721
818
  pre: { margin: 0, whiteSpace: "pre-wrap", wordBreak: "break-word", fontFamily: "inherit" },
722
- actions: { display: "flex", gap: 8, marginTop: 8 },
819
+ actions: { display: "flex", gap: 8, marginTop: 6 },
723
820
  actionBtn: {
724
821
  display: "inline-flex",
725
822
  alignItems: "center",
726
- padding: "4px 12px",
823
+ padding: "3px 10px",
727
824
  fontSize: 12,
728
825
  borderRadius: 6,
729
826
  border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.4))",
730
- background: "var(--dsw-alias-button-tool-bar-fill, transparent)",
827
+ // 幽灵按钮:button-tool-bar-fill 在当前主题是 50% 灰(#54555780),整排灰块
828
+ // 是面板显灰的主因,改为透明底 + 细描边,与输入卡的工具按钮同语言。
829
+ background: "transparent",
731
830
  color: "var(--dsw-alias-label-primary, inherit)",
732
831
  cursor: "pointer"
733
832
  },
@@ -869,88 +968,92 @@ function createResultDock(controller) {
869
968
  controller.clearApplied();
870
969
  setUndoneFlash(true);
871
970
  };
872
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.panel, role: "dialog", "aria-label": t("panel.aria"), children: [
873
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.header, children: [
874
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SparkleIcon, { size: 15 }),
875
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: styles.title, children: t("panel.title") }),
876
- result && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
877
- "span",
878
- {
879
- style: styles.modelBadge,
880
- title: result.fallbackUsed && result.fallbackReason ? `${t("panel.fallback")}: ${result.fallbackReason}` : void 0,
881
- children: [
882
- result.provider,
883
- " / ",
884
- result.model,
885
- result.fallbackUsed ? ` \xB7 ${t("panel.fallback")}` : "",
886
- typeof result.durationMs === "number" ? ` \xB7 ${t("panel.duration")} ${(result.durationMs / 1e3).toFixed(1)}s` : ""
887
- ]
888
- }
889
- ),
890
- applied && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: styles.statusChip, children: t("panel.appliedShort") }),
891
- !applied && undoneFlash && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: styles.statusChip, children: t("panel.undoneShort") }),
892
- /* @__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" })
893
- ] }),
894
- state.status === "loading" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
895
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.loading, children: [
896
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SparkleIcon, { spinning: true }),
897
- stage,
898
- "\u2026(",
899
- elapsed,
900
- "s,",
901
- t("panel.escCancel"),
902
- ")"
903
- ] }),
904
- liveBody
905
- ] }),
906
- state.status === "cancelled" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
907
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.cancelledHint, children: t("panel.cancelled") }),
908
- liveBody,
909
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.actions, children: [
910
- /* @__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") }),
911
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: () => controller.close(), children: t("panel.close") })
912
- ] })
913
- ] }),
914
- state.status === "error" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
915
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.sectionTitle, children: t("panel.error") }),
916
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.errorText, children: state.error }),
917
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.actions, children: [
918
- /* @__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") }),
919
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: () => controller.close(), children: t("panel.close") })
920
- ] })
921
- ] }),
922
- state.status === "done" && result && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
923
- !result.wellFormed && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { ...styles.warnBanner, marginTop: 0, marginBottom: 8 }, children: [
924
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "aria-hidden": true, children: "\u26A0" }),
925
- /* @__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" })
926
995
  ] }),
927
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.body, children: [
928
- result.analysis && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
929
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("button", { className: "dsh-po-btn", type: "button", style: styles.sectionTitle, onClick: () => setAnalysisOpen((v) => !v), "aria-expanded": analysisOpen, children: [
930
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { ...styles.chevron, transform: analysisOpen ? "rotate(90deg)" : "none" }, children: "\u25B8" }),
931
- t("panel.analysis")
932
- ] }),
933
- 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
+ ")"
934
1005
  ] }),
935
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { ...styles.sectionTitle, cursor: "default" }, children: t("panel.optimized") }),
936
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.optimizedBox, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("pre", { style: styles.pre, children: result.optimized }) }),
937
- result.truncated && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.warnBanner, children: [
938
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "aria-hidden": true, children: "\u26A0" }),
939
- /* @__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") })
1014
+ ] })
1015
+ ] }),
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") })
940
1022
  ] })
941
1023
  ] }),
942
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.actions, children: applied ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
943
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: { ...styles.actionBtn, ...styles.primaryBtn }, onClick: onUndo, children: t("panel.undo") }),
944
- /* @__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") }),
945
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: () => controller.close(), children: t("panel.close") })
946
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
947
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: { ...styles.actionBtn, ...styles.primaryBtn }, onClick: onReplace, children: t("panel.replace") }),
948
- /* @__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") }),
949
- /* @__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") }),
950
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: () => controller.close(), children: t("panel.close") })
951
- ] }) })
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
+ ] })
952
1055
  ] })
953
- ] });
1056
+ );
954
1057
  };
955
1058
  }
956
1059
 
@@ -978,91 +1081,102 @@ function GitHubIcon(props) {
978
1081
  // src/client/SettingsCard.tsx
979
1082
  var import_jsx_runtime5 = require("react/jsx-runtime");
980
1083
  var REPO_URL = "https://github.com/Y1X1n/dsh-prompt-optimizer";
981
- var FOLLOW_SESSION = "";
982
- var styles2 = {
983
- card: {
984
- border: "1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.3))",
985
- borderRadius: 10,
986
- padding: "14px 16px",
987
- fontSize: 13,
988
- lineHeight: 1.6,
989
- color: "var(--dsw-alias-label-primary, inherit)",
990
- fontFamily: "var(--dsw-font-family, inherit)"
991
- },
992
- title: { fontSize: 14, fontWeight: 600 },
993
- desc: { color: "var(--dsw-alias-label-primary-dimmed, rgba(128,128,128,0.9))", marginBottom: 12 },
994
- headerBtn: {
995
- display: "flex",
996
- alignItems: "center",
997
- gap: 6,
998
- width: "100%",
999
- padding: 0,
1000
- border: "none",
1001
- background: "none",
1002
- color: "inherit",
1003
- font: "inherit",
1004
- cursor: "pointer",
1005
- textAlign: "left"
1006
- },
1007
- chevron: {
1008
- fontSize: 11,
1009
- color: "var(--dsw-alias-label-primary-dimmed, rgba(128,128,128,0.9))",
1010
- transition: "transform 0.15s ease"
1011
- },
1012
- headerDesc: {
1013
- marginLeft: "auto",
1014
- fontSize: 12,
1015
- fontWeight: 400,
1016
- color: "var(--dsw-alias-label-primary-dimmed, rgba(128,128,128,0.9))"
1017
- },
1018
- body: { marginTop: 12 },
1019
- row: { display: "flex", alignItems: "center", gap: 10, marginBottom: 10 },
1020
- label: { width: 110, flexShrink: 0, color: "var(--dsw-alias-label-primary, inherit)" },
1021
- input: {
1022
- flex: 1,
1023
- maxWidth: 320,
1024
- padding: "4px 8px",
1025
- fontSize: 13,
1026
- borderRadius: 6,
1027
- border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.4))",
1028
- background: "var(--dsw-alias-bg-layer-1, transparent)",
1029
- color: "var(--dsw-alias-label-primary, inherit)"
1030
- },
1031
- hint: { color: "var(--dsw-alias-label-primary-dimmed, rgba(128,128,128,0.9))", fontSize: 12 },
1032
- // U13:分组小标题(模型 / 调用参数 / 上下文),带浅分隔线。
1033
- groupTitle: {
1034
- margin: "14px 0 8px",
1035
- paddingTop: 8,
1036
- borderTop: "1px solid var(--dsw-alias-border-l3, rgba(128,128,128,0.18))",
1037
- fontSize: 11,
1038
- fontWeight: 600,
1039
- color: "var(--dsw-alias-label-primary-dimmed, rgba(128,128,128,0.9))"
1040
- },
1041
- fieldError: { color: "var(--dsw-alias-state-error-primary, #e5534b)", fontSize: 12 },
1042
- refreshBtn: {
1043
- flexShrink: 0,
1044
- padding: "4px 10px",
1045
- fontSize: 12,
1046
- borderRadius: 6,
1047
- border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.4))",
1048
- background: "var(--dsw-alias-button-tool-bar-fill, transparent)",
1049
- color: "var(--dsw-alias-label-primary, inherit)",
1050
- cursor: "pointer"
1051
- },
1052
- // 标题右侧的 GitHub 仓库入口:点击在新标签打开仓库主页。
1053
- repoLink: {
1054
- display: "inline-flex",
1055
- alignItems: "center",
1056
- marginLeft: 8,
1057
- padding: 4,
1058
- color: "var(--dsw-alias-label-primary-dimmed, rgba(128,128,128,0.9))",
1059
- background: "none",
1060
- border: "none",
1061
- borderRadius: 6,
1062
- cursor: "pointer",
1063
- textDecoration: "none"
1064
- }
1065
- };
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
+ }
1066
1180
  function TextField(props) {
1067
1181
  const [text, setText] = (0, import_react4.useState)(props.value);
1068
1182
  const [error, setError] = (0, import_react4.useState)(null);
@@ -1080,15 +1194,17 @@ function TextField(props) {
1080
1194
  setError(null);
1081
1195
  props.onCommit(text);
1082
1196
  };
1083
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1084
- /* @__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: [
1085
1198
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1086
1199
  "input",
1087
1200
  {
1088
- className: "dsh-po-btn",
1089
- 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,
1090
1204
  value: text,
1091
1205
  placeholder: props.placeholder,
1206
+ "aria-label": props.label,
1207
+ title: props.labelTitle,
1092
1208
  onChange: (e) => {
1093
1209
  setText(e.target.value);
1094
1210
  setError(null);
@@ -1099,17 +1215,48 @@ function TextField(props) {
1099
1215
  }
1100
1216
  }
1101
1217
  ),
1102
- 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 })
1103
1244
  ] });
1104
1245
  }
1105
- 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();
1106
1252
  return function PromptOptimizerSettingsCard() {
1107
1253
  const snap = (0, import_react4.useSyncExternalStore)(
1108
- (callback) => scope.subscribe(callback),
1109
- () => scope.getSnapshot()
1254
+ (callback) => face2.subscribe(callback),
1255
+ () => face2.getSnapshot()
1110
1256
  );
1111
1257
  const t = useT();
1112
1258
  const value = snap.value ?? {};
1259
+ const writable = snap.writable !== false;
1113
1260
  const SETTING_KEYS = [
1114
1261
  "language",
1115
1262
  "model",
@@ -1128,7 +1275,8 @@ function createSettingsCard(ctx, scope) {
1128
1275
  fallbackModel: "",
1129
1276
  maxTokens: 8192,
1130
1277
  timeoutSeconds: 120,
1131
- mode: "full",
1278
+ // 与 Host 侧 Config 默认口径一致(0.5.0 起默认快速模式)。
1279
+ mode: "fast",
1132
1280
  reasoningEffort: "lowest",
1133
1281
  temperature: 0.2,
1134
1282
  autoMaxTokens: true,
@@ -1143,7 +1291,7 @@ function createSettingsCard(ctx, scope) {
1143
1291
  if (undoStack.current.length > 20) undoStack.current.shift();
1144
1292
  setCanUndo(true);
1145
1293
  }
1146
- void scope.set(key, v);
1294
+ void face2.set(key, v);
1147
1295
  };
1148
1296
  const undoLastChange = () => {
1149
1297
  const prev = undoStack.current.pop();
@@ -1154,7 +1302,7 @@ function createSettingsCard(ctx, scope) {
1154
1302
  for (const k of SETTING_KEYS) {
1155
1303
  const target = prev[k] ?? SETTING_DEFAULTS[k];
1156
1304
  if (value[k] !== target) {
1157
- void scope.set(k, target);
1305
+ void face2.set(k, target);
1158
1306
  }
1159
1307
  }
1160
1308
  } finally {
@@ -1163,17 +1311,26 @@ function createSettingsCard(ctx, scope) {
1163
1311
  };
1164
1312
  const [groups, setGroups] = (0, import_react4.useState)(null);
1165
1313
  const [catalogState, setCatalogState] = (0, import_react4.useState)("loading");
1314
+ const [catalogHint, setCatalogHint] = (0, import_react4.useState)(null);
1166
1315
  const loadCatalog = async () => {
1167
1316
  setCatalogState("loading");
1317
+ setCatalogHint(null);
1168
1318
  try {
1169
- const resp = await ctx.connection.api.llm.models({});
1170
- if (resp.result.ok) {
1171
- setGroups(resp.result.value.groups);
1319
+ const result = await sessionCatalog(ctx.connection);
1320
+ if (result.ok) {
1321
+ setGroups(result.value.groups);
1172
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
+ }
1173
1327
  } else {
1328
+ const message = typeof result.error === "string" ? result.error : result.error?.message;
1329
+ setCatalogHint(message ?? null);
1174
1330
  setCatalogState("error");
1175
1331
  }
1176
- } catch {
1332
+ } catch (cause) {
1333
+ setCatalogHint(cause instanceof Error ? cause.message : String(cause));
1177
1334
  setCatalogState("error");
1178
1335
  }
1179
1336
  };
@@ -1199,262 +1356,265 @@ function createSettingsCard(ctx, scope) {
1199
1356
  setTest({ status: "fail", message: cause instanceof Error ? cause.message : String(cause) });
1200
1357
  }
1201
1358
  };
1202
- const EXPAND_KEY = "dsh-prompt-optimizer.settings-expanded";
1203
- const [expanded, setExpanded] = (0, import_react4.useState)(() => {
1204
- try {
1205
- return localStorage.getItem(EXPAND_KEY) === "1";
1206
- } catch {
1207
- return false;
1208
- }
1209
- });
1210
- const toggle = () => setExpanded((v) => {
1211
- const next = !v;
1212
- try {
1213
- localStorage.setItem(EXPAND_KEY, next ? "1" : "0");
1214
- } catch {
1215
- }
1216
- return next;
1217
- });
1218
- const pinnedModel = value.model?.trim();
1219
- let modelShort = pinnedModel;
1220
- if (!pinnedModel) {
1221
- modelShort = t("settings.model.follow");
1222
- } else if (groups) {
1223
- const slash = pinnedModel.indexOf("/");
1224
- const g = slash > 0 ? groups.find((x) => x.id === pinnedModel.slice(0, slash)) : void 0;
1225
- const m = g?.models.find((mm) => mm.id === pinnedModel.slice(slash + 1));
1226
- if (m) modelShort = m.name;
1227
- }
1228
- 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")}`;
1229
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { style: styles2.card, children: [
1230
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "flex", alignItems: "center" }, children: [
1231
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { className: "dsh-po-btn", type: "button", style: { ...styles2.headerBtn, flex: 1 }, onClick: toggle, "aria-expanded": expanded, children: [
1232
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { ...styles2.chevron, transform: expanded ? "rotate(90deg)" : "none" }, children: "\u25B8" }),
1233
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.title, children: t("panel.title") }),
1234
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.headerDesc, children: expanded ? t("settings.desc") : summaryText })
1235
- ] }),
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 }),
1236
1395
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1237
- "a",
1396
+ "button",
1238
1397
  {
1239
- className: "dsh-po-btn dsh-po-repo-link",
1240
- href: REPO_URL,
1241
- target: "_blank",
1242
- rel: "noopener noreferrer",
1243
- style: styles2.repoLink,
1244
- title: t("settings.repoTitle"),
1245
- "aria-label": t("settings.repoTitle"),
1246
- onClick: (e) => e.stopPropagation(),
1247
- 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")
1248
1403
  }
1249
1404
  )
1250
- ] }),
1251
- expanded && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.body, children: [
1252
- snap.status === "loading" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles2.hint, children: t("settings.loading") }),
1253
- snap.status === "unavailable" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles2.hint, children: t("settings.unavailable") }),
1254
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles2.groupTitle, children: t("settings.group.model") }),
1255
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1256
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, children: t("settings.model") }),
1257
- 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)(
1258
- "select",
1259
- {
1260
- style: styles2.input,
1261
- value: value.model ?? FOLLOW_SESSION,
1262
- onChange: (e) => void setValue("model", e.target.value),
1263
- children: [
1264
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: FOLLOW_SESSION, children: t("settings.model.follow") }),
1265
- 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))
1266
- ]
1267
- }
1268
- ),
1269
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1270
- "button",
1271
- {
1272
- className: "dsh-po-btn",
1273
- type: "button",
1274
- style: { ...styles2.refreshBtn, ...catalogState === "loading" ? { opacity: 0.45, cursor: "default" } : {} },
1275
- disabled: catalogState === "loading",
1276
- title: t("settings.refreshTitle"),
1277
- onClick: () => void loadCatalog(),
1278
- children: t("settings.refresh")
1279
- }
1280
- )
1281
- ] }),
1282
- groups !== null && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1283
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, children: t("settings.fallbackModel") }),
1284
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1285
- "select",
1286
- {
1287
- style: styles2.input,
1288
- value: value.fallbackModel ?? "",
1289
- onChange: (e) => void setValue("fallbackModel", e.target.value),
1290
- children: [
1291
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "", children: t("settings.fallbackModel.none") }),
1292
- 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))
1293
- ]
1294
- }
1295
- )
1296
- ] }),
1297
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1298
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, children: t("settings.test") }),
1299
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1300
- "button",
1301
- {
1302
- className: "dsh-po-btn",
1303
- type: "button",
1304
- style: { ...styles2.refreshBtn, ...test.status === "testing" ? { opacity: 0.45, cursor: "default" } : {} },
1305
- disabled: test.status === "testing",
1306
- onClick: () => void runTest(),
1307
- children: test.status === "testing" ? t("settings.test.running") : t("settings.test.run")
1308
- }
1309
- ),
1310
- test.message && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: test.status === "fail" ? styles2.fieldError : styles2.hint, children: test.message })
1311
- ] }),
1312
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles2.groupTitle, children: t("settings.group.params") }),
1313
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1314
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, children: t("settings.language") }),
1315
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1316
- "select",
1317
- {
1318
- style: { ...styles2.input, maxWidth: 160 },
1319
- value: value.language ?? "zh",
1320
- onChange: (e) => void setValue("language", e.target.value),
1321
- children: [
1322
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "zh", children: "\u4E2D\u6587" }),
1323
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "en", children: "English" })
1324
- ]
1325
- }
1326
- )
1327
- ] }),
1328
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1329
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, children: t("settings.mode") }),
1330
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1331
- "select",
1332
- {
1333
- style: { ...styles2.input, maxWidth: 260 },
1334
- value: value.mode ?? "full",
1335
- onChange: (e) => void setValue("mode", e.target.value),
1336
- children: [
1337
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "full", children: t("settings.mode.full") }),
1338
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "fast", children: t("settings.mode.fast") })
1339
- ]
1340
- }
1341
- )
1342
- ] }),
1343
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1344
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, children: t("settings.effort") }),
1345
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1346
- "select",
1347
- {
1348
- style: { ...styles2.input, maxWidth: 260 },
1349
- value: value.reasoningEffort ?? "lowest",
1350
- onChange: (e) => void setValue("reasoningEffort", e.target.value),
1351
- children: [
1352
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "lowest", children: t("settings.effort.lowest") }),
1353
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "session", children: t("settings.effort.session") })
1354
- ]
1355
- }
1356
- )
1357
- ] }),
1358
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles2.groupTitle, children: t("settings.group.context") }),
1359
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1360
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, children: t("settings.includeContext") }),
1361
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1362
- "select",
1363
- {
1364
- style: { ...styles2.input, maxWidth: 260 },
1365
- value: value.includeContext === false ? "off" : "on",
1366
- onChange: (e) => void setValue("includeContext", e.target.value === "on"),
1367
- children: [
1368
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "on", children: t("settings.includeContext.on") }),
1369
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "off", children: t("settings.includeContext.off") })
1370
- ]
1371
- }
1372
- )
1373
- ] }),
1374
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1375
- TextField,
1376
- {
1377
- label: t("settings.maxTokens"),
1378
- value: String(value.maxTokens ?? 8192),
1379
- placeholder: "8192",
1380
- validate: (v) => {
1381
- const n = Number.parseInt(v, 10);
1382
- return Number.isFinite(n) && n >= 1024 && n <= 32768 ? null : t("settings.validate.maxTokens");
1383
- },
1384
- onCommit: (v) => void setValue("maxTokens", Number.parseInt(v, 10))
1385
- }
1386
- ),
1387
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1388
- TextField,
1389
- {
1390
- label: t("settings.timeout"),
1391
- value: String(value.timeoutSeconds ?? 120),
1392
- placeholder: "120",
1393
- validate: (v) => {
1394
- const n = Number.parseInt(v, 10);
1395
- return Number.isFinite(n) && n >= 10 && n <= 600 ? null : t("settings.validate.timeout");
1396
- },
1397
- onCommit: (v) => void setValue("timeoutSeconds", Number.parseInt(v, 10))
1398
- }
1399
- ),
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: [
1400
1502
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1401
- TextField,
1402
- {
1403
- label: t("settings.temperature"),
1404
- labelTitle: t("settings.temperatureTitle"),
1405
- value: String(value.temperature ?? 0.2),
1406
- placeholder: "0.2",
1407
- validate: (v) => {
1408
- const n = Number.parseFloat(v);
1409
- return Number.isFinite(n) && n >= 0 && n <= 2 ? null : t("settings.validate.temperature");
1410
- },
1411
- onCommit: (v) => void setValue("temperature", Number.parseFloat(v))
1412
- }
1413
- ),
1414
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: styles2.row, children: [
1415
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.label, children: t("settings.autoMaxTokens") }),
1416
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1417
- "select",
1418
- {
1419
- style: { ...styles2.input, maxWidth: 260 },
1420
- value: value.autoMaxTokens === false ? "off" : "on",
1421
- onChange: (e) => void setValue("autoMaxTokens", e.target.value === "on"),
1422
- children: [
1423
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "on", children: t("settings.autoMaxTokens.on") }),
1424
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "off", children: t("settings.autoMaxTokens.off") })
1425
- ]
1426
- }
1427
- )
1428
- ] }),
1429
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles2.row, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1430
1503
  "button",
1431
1504
  {
1432
- className: "dsh-po-btn",
1505
+ className: "dsh-po-btn2 dsh-po-btn",
1433
1506
  type: "button",
1434
- style: { ...styles2.refreshBtn, ...!canUndo ? { opacity: 0.45, cursor: "default" } : {} },
1435
1507
  disabled: !canUndo,
1436
1508
  title: t("settings.undoTitle"),
1437
1509
  onClick: undoLastChange,
1438
1510
  children: t("settings.undo")
1439
1511
  }
1440
- ) }),
1441
- !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
+ )
1442
1537
  ] })
1443
1538
  ] });
1444
1539
  };
1445
1540
  }
1446
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
+
1447
1606
  // src/client/index.tsx
1448
1607
  var name = "dsh-prompt-optimizer-client";
1449
- var inject = ["slots", "connection", "remote", "settingsScope"];
1608
+ var inject = ["slots", "connection", "remote"];
1450
1609
  var BUTTON_CLASS = "dsh-po-btn";
1610
+ var SETTINGS_ENTRY_ID = "prompt-optimizer";
1451
1611
  function ensureFocusStyles() {
1452
1612
  if (typeof document === "undefined") return;
1453
1613
  const ID = "dsh-prompt-optimizer-focus-styles";
1454
1614
  if (document.getElementById(ID)) return;
1455
1615
  const style = document.createElement("style");
1456
1616
  style.id = ID;
1457
- 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));}";
1458
1618
  document.head.appendChild(style);
1459
1619
  }
1460
1620
  function apply(ctx) {
@@ -1462,7 +1622,20 @@ function apply(ctx) {
1462
1622
  ctx.inject(["locale"], (lctx) => {
1463
1623
  installLocaleFace(lctx.locale ?? null);
1464
1624
  });
1465
- 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() };
1466
1639
  const controller = createOptimizerController(ctx, {
1467
1640
  // 与 Host 侧「空字符串视为未设置」的口径一致。
1468
1641
  isModelPinned: () => Boolean(scope.getSnapshot().value?.model?.trim()),
@@ -1471,9 +1644,11 @@ function apply(ctx) {
1471
1644
  // 与 Host 侧「仅 mode==='fast' 为快速」的归一化口径一致。
1472
1645
  isFastMode: () => scope.getSnapshot().value?.mode === "fast",
1473
1646
  // R21:看门狗 = 设置超时秒数 + 5s 余量(正常时 Host 的超时错误先到达,文案更友好)。
1474
- getWatchdogMs: () => ((scope.getSnapshot().value?.timeoutSeconds ?? 120) + 5) * 1e3
1647
+ getWatchdogMs: () => ((scope.getSnapshot().value?.timeoutSeconds ?? 120) + 5) * 1e3,
1648
+ // 「跟随会话」的模型来源(见上);点击时读取,服务缺席走 Host 回退。
1649
+ getSessionModelDirectories: () => modelDirectories
1475
1650
  });
1476
- ctx.inject(["slots", "connection", "remote", "settingsScope"], (scopeCtx) => {
1651
+ ctx.inject(["slots", "connection", "remote"], (scopeCtx) => {
1477
1652
  scopeCtx.slots.inject(
1478
1653
  "conversation.input.right",
1479
1654
  () => scopeCtx.slots.register(
@@ -1499,13 +1674,33 @@ function apply(ctx) {
1499
1674
  )
1500
1675
  );
1501
1676
  });
1502
- ctx.slots.inject(
1503
- "settings.plugin.item",
1504
- () => ctx.slots.register(
1505
- { name: "settings.plugin.item", key: "prompt-optimizer" },
1506
- createSettingsCard(ctx, scope)
1507
- )
1508
- );
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));
1509
1704
  }
1510
1705
  return module.exports;
1511
1706
  }