@y1x1n/dsh-prompt-optimizer 0.3.16 → 0.6.4

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,55 +100,61 @@ 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
- "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
- "settings.memoryOnly": "\u5F53\u524D\u4E3A\u5185\u5B58\u6A21\u5F0F:\u8BBE\u7F6E\u4E0D\u4F1A\u6301\u4E45\u5316\u3002",
110
+ // 0.2.1-rc.2 删除了 ConfigFormSnapshot.mode('host' | 'memory'):设置只可能是
111
+ // 宿主持久化,不再有浏览器进程内内存模式。文案随之去掉「内存模式」措辞,
112
+ // 只保留「这份部署不对外提供该命名空间 / 当前只读」两种真实状态。
113
+ "settings.unavailable": "\u5F53\u524D\u5BBF\u4E3B\u672A\u5411\u6B64\u9875\u9762\u5F00\u653E\u672C\u63D2\u4EF6\u7684\u8BBE\u7F6E\u547D\u540D\u7A7A\u95F4;\u53EF\u7528\u7EC4\u5408\u5C42\u914D\u7F6E,\u6216\u5728 dsh \u8BBE\u7F6E\u4E2D\u68C0\u67E5\u63D2\u4EF6\u662F\u5426\u542F\u7528\u3002",
114
+ "settings.readOnly": "\u5F53\u524D\u8BBE\u7F6E\u53EA\u8BFB:\u5BBF\u4E3B\u62D2\u7EDD\u5199\u5165,\u6539\u52A8\u4E0D\u4F1A\u4FDD\u5B58\u3002",
114
115
  "settings.undo": "\u64A4\u9500\u4E0A\u4E00\u6B21\u4FEE\u6539",
115
116
  "settings.undoTitle": "\u6062\u590D\u8FD9\u6B21\u4FEE\u6539\u524D\u7684\u5168\u90E8\u8BBE\u7F6E(\u4EC5\u672C\u6B21\u9875\u9762\u4F1A\u8BDD\u5185\u53EF\u64A4\u9500)",
116
117
  "settings.group.model": "\u6A21\u578B",
117
118
  "settings.group.params": "\u8C03\u7528\u53C2\u6570",
118
119
  "settings.group.context": "\u4E0A\u4E0B\u6587",
119
- "settings.summary.model": "\u6A21\u578B",
120
- "settings.summary.mode": "\u6A21\u5F0F",
121
120
  "settings.model": "\u4F18\u5316\u7528\u6A21\u578B",
122
121
  "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",
122
+ "settings.model.desc": "\u7559\u7A7A\u8DDF\u968F\u4F1A\u8BDD;\u56FA\u5B9A\u540E\u6240\u6709\u4F18\u5316\u90FD\u7528\u8FD9\u4E2A\u6A21\u578B",
125
123
  "settings.refresh": "\u21BB \u5237\u65B0",
126
124
  "settings.refreshTitle": "\u91CD\u65B0\u62C9\u53D6\u6A21\u578B\u76EE\u5F55(\u65B0\u589E\u63D0\u4F9B\u65B9/\u6A21\u578B\u540E\u4F7F\u7528)",
127
125
  "settings.fallbackModel": "\u56DE\u9000\u6A21\u578B",
128
126
  "settings.fallbackModel.none": "\u65E0(\u9ED8\u8BA4)",
127
+ "settings.fallbackModel.desc": "\u4E3B\u8DEF\u7531\u672A\u4EA7\u51FA\u5185\u5BB9\u5373\u5931\u8D25\u65F6\u81EA\u52A8\u6362\u7528",
129
128
  "settings.test": "\u6A21\u578B\u8FDE\u901A\u6027",
129
+ "settings.test.desc": "\u6309\u540C\u4E00\u8DEF\u7531\u53D1\u4E00\u4E2A\u5C0F\u63A2\u6D3B\u8C03\u7528",
130
130
  "settings.test.run": "\u6D4B\u8BD5\u8FDE\u63A5",
131
131
  "settings.test.running": "\u6D4B\u8BD5\u4E2D\u2026",
132
132
  "settings.test.ok": "\u8FDE\u63A5\u6B63\u5E38:{provider} / {model}({latencyMs}ms)",
133
133
  "settings.language": "\u8F93\u51FA\u8BED\u8A00",
134
+ "settings.language.desc": "\u4F18\u5316\u7ED3\u679C\u4F7F\u7528\u7684\u8BED\u8A00",
134
135
  "settings.mode": "\u4F18\u5316\u6A21\u5F0F",
136
+ "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
137
  "settings.mode.full": "\u5B8C\u6574(\u5206\u6790\u8BCA\u65AD + \u4F18\u5316)",
136
138
  "settings.mode.fast": "\u5FEB\u901F(\u4EC5\u4F18\u5316,\u7B49\u5F85\u7EA6\u51CF\u534A)",
137
139
  "settings.mode.full.short": "\u5B8C\u6574",
138
140
  "settings.mode.fast.short": "\u5FEB\u901F",
139
141
  "settings.effort": "\u63A8\u7406\u5F3A\u5EA6",
142
+ "settings.effort.desc": "\u63A8\u7406\u6A21\u578B\u4E0A,\u6700\u4F4E\u6863\u663E\u8457\u7F29\u77ED\u7B49\u5F85",
140
143
  "settings.effort.lowest": "\u964D\u5230\u6700\u4F4E\u6863(\u9ED8\u8BA4,\u63A8\u7406\u6A21\u578B\u66F4\u5FEB)",
141
144
  "settings.effort.session": "\u8DDF\u968F\u5F53\u524D\u4F1A\u8BDD",
145
+ "settings.effort.lowest.short": "\u6700\u4F4E\u6863",
146
+ "settings.effort.session.short": "\u8DDF\u968F\u4F1A\u8BDD",
142
147
  "settings.maxTokens": "\u6700\u5927\u8F93\u51FA Token",
148
+ "settings.maxTokens.desc": "\u5355\u6B21\u4F18\u5316\u8C03\u7528\u7684\u8F93\u51FA\u4E0A\u9650",
143
149
  "settings.timeout": "\u8D85\u65F6\u65F6\u95F4(\u79D2)",
150
+ "settings.timeout.desc": "\u8D85\u65F6\u540E\u4E2D\u6B62\u8C03\u7528\u5E76\u7ED9\u51FA\u63D0\u793A",
144
151
  "settings.temperature": "\u91C7\u6837\u6E29\u5EA6",
145
152
  "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",
153
+ "settings.temperature.desc": "\u4F4E\u6E29\u8F93\u51FA\u66F4\u7A33\u5B9A(\u9ED8\u8BA4 0.2)",
146
154
  "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",
155
+ "settings.autoMaxTokens.desc": "\u957F\u8349\u7A3F\u81EA\u52A8\u63D0\u9AD8\u4E0A\u9650,\u907F\u514D\u622A\u65AD",
149
156
  "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",
157
+ "settings.includeContext.desc": "\u53C2\u8003\u6700\u8FD1\u5BF9\u8BDD,\u4F18\u5316\u65B9\u5411\u66F4\u8D34\u5408",
152
158
  "settings.validate.maxTokens": "\u8BF7\u8F93\u5165 1024\u201332768 \u4E4B\u95F4\u7684\u6570\u5B57",
153
159
  "settings.validate.timeout": "\u8BF7\u8F93\u5165 10\u2013600 \u4E4B\u95F4\u7684\u6570\u5B57",
154
160
  "settings.validate.temperature": "\u8BF7\u8F93\u5165 0\u20132 \u4E4B\u95F4\u7684\u6570\u5B57",
@@ -178,61 +184,70 @@ var dict = {
178
184
  "panel.reoptimize": "Re-optimize",
179
185
  "panel.reoptimizeTitle": "Re-runs optimization: carries the previous result only if the draft changed since then; otherwise regenerates fresh",
180
186
  "panel.undo": "Undo",
181
- "panel.applied": "Replaced into the input box \u2713",
182
187
  "panel.appliedShort": "Applied \u2713",
183
188
  "panel.undoneShort": "Undone \u2713",
184
189
  "panel.fallback": "fallback",
185
190
  "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.',
191
+ "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
192
  "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
193
  "settings.loading": "Loading settings\u2026",
190
- "settings.unavailable": "This connection cannot write settings (remote page is in-memory); changes apply to this session only.",
191
- "settings.memoryOnly": "In-memory mode: settings will not persist.",
194
+ // 0.2.1-rc.2 removed ConfigFormSnapshot.mode ('host' | 'memory'): settings are
195
+ // always Host-persisted now, there is no process-local memory mode.
196
+ "settings.unavailable": "This Host does not expose the plugin settings namespace to this page; use composition config, or check that the plugin is enabled.",
197
+ "settings.readOnly": "Settings are read-only: the Host refuses writes, so changes will not be saved.",
192
198
  "settings.undo": "Undo last change",
193
199
  "settings.undoTitle": "Restore all settings to before this change (undo is session-only)",
194
200
  "settings.group.model": "Model",
195
201
  "settings.group.params": "Generation parameters",
196
202
  "settings.group.context": "Context",
197
- "settings.summary.model": "Model",
198
- "settings.summary.mode": "Mode",
199
203
  "settings.model": "Optimizer model",
200
204
  "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.",
205
+ "settings.model.desc": "Leave empty to follow the session; pin one to always optimize with it",
203
206
  "settings.refresh": "\u21BB Refresh",
204
207
  "settings.refreshTitle": "Reload the model catalog (after adding providers/models)",
205
208
  "settings.fallbackModel": "Fallback model",
206
209
  "settings.fallbackModel.none": "None (default)",
210
+ "settings.fallbackModel.desc": "Switched to automatically when the main route fails before producing output",
207
211
  "settings.test": "Connectivity",
212
+ "settings.test.desc": "Sends a tiny probe call through the same routing",
208
213
  "settings.test.run": "Test connection",
209
214
  "settings.test.running": "Testing\u2026",
210
215
  "settings.test.ok": "Connected: {provider} / {model} ({latencyMs}ms)",
211
216
  "settings.language": "Output language",
217
+ "settings.language.desc": "Language of the optimized result",
212
218
  "settings.mode": "Mode",
219
+ "settings.mode.desc": "Fast halves the output tokens and the wait; full adds an analysis pass",
213
220
  "settings.mode.full": "Full (analysis + rewrite)",
214
221
  "settings.mode.fast": "Fast (rewrite only, ~half the wait)",
215
222
  "settings.mode.full.short": "Full",
216
223
  "settings.mode.fast.short": "Fast",
217
224
  "settings.effort": "Reasoning effort",
225
+ "settings.effort.desc": "On reasoning models the lowest tier shortens the wait significantly",
218
226
  "settings.effort.lowest": "Clamp to lowest tier (default, faster on reasoning models)",
219
227
  "settings.effort.session": "Follow current session",
228
+ "settings.effort.lowest.short": "Lowest",
229
+ "settings.effort.session.short": "Follow session",
220
230
  "settings.maxTokens": "Max output tokens",
231
+ "settings.maxTokens.desc": "Output cap per optimization call",
221
232
  "settings.timeout": "Timeout (seconds)",
233
+ "settings.timeout.desc": "The call is aborted and reported after this many seconds",
222
234
  "settings.temperature": "Temperature",
223
235
  "settings.temperatureTitle": "Optimization is a formatting task \u2014 low temperature gives stabler output; default 0.2, usually no need to change",
236
+ "settings.temperature.desc": "Low temperature gives stabler output (default 0.2)",
224
237
  "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",
238
+ "settings.autoMaxTokens.desc": "Raise the cap for long drafts instead of truncating them",
227
239
  "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",
240
+ "settings.includeContext.desc": "Read recent conversation so the rewrite matches your intent",
230
241
  "settings.validate.maxTokens": "Enter a number between 1024 and 32768",
231
242
  "settings.validate.timeout": "Enter a number between 10 and 600",
232
243
  "settings.validate.temperature": "Enter a number between 0 and 2",
233
244
  "settings.repoTitle": "View source / report issues on GitHub"
234
245
  }
235
246
  };
247
+ function translate(key, params) {
248
+ const active = face?.getSnapshot().active === "en" ? "en" : "zh";
249
+ return interpolate(dict[active][key] ?? dict.zh[key], params);
250
+ }
236
251
  function interpolate(text, params) {
237
252
  if (!params) return text;
238
253
  return text.replace(/\{(\w+)\}/g, (m, name2) => params[name2] !== void 0 ? String(params[name2]) : m);
@@ -252,17 +267,18 @@ var buttonStyle = {
252
267
  display: "inline-flex",
253
268
  alignItems: "center",
254
269
  gap: 4,
255
- padding: "4px 10px",
270
+ padding: "4px 12px",
256
271
  fontSize: 12,
257
272
  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)",
273
+ borderRadius: 999,
274
+ border: "none",
261
275
  color: "var(--dsw-alias-label-primary, inherit)",
262
276
  cursor: "pointer",
263
- whiteSpace: "nowrap",
264
- // U4:预留最宽文案(「优化中…」/「Optimizing…」)的宽度,状态切换不引起工具栏抖动。
265
- minWidth: 92
277
+ whiteSpace: "nowrap"
278
+ // 宽度贴住内容,不预留「优化中…」的空位(用户反馈空闲态「优化」右侧空白);
279
+ // 加载态文案不变、仅图标旋转,宽度恒定,工具行不抖动(U4 原目标改由
280
+ // 恒定文案达成,minWidth 随之移除)。
281
+ // 底色与 hover 态走注入样式表的 .dsh-po-opt 规则(inline 会盖过 :hover)。
266
282
  };
267
283
  function createOptimizeButton(controller) {
268
284
  return function OptimizeButton(props) {
@@ -276,15 +292,15 @@ function createOptimizeButton(controller) {
276
292
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: { display: "inline-flex" }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
277
293
  "button",
278
294
  {
279
- className: "dsh-po-btn",
295
+ className: "dsh-po-btn dsh-po-opt",
280
296
  type: "button",
281
297
  style: { ...buttonStyle, ...empty || loading ? { opacity: 0.45, cursor: "not-allowed" } : {} },
282
298
  disabled: empty || loading,
283
- title: empty ? t("button.titleEmpty") : t("button.title"),
299
+ title: loading ? t("button.optimizing") : empty ? t("button.titleEmpty") : t("button.title"),
284
300
  onClick: () => void controller.optimize(draft, p.sessionId),
285
301
  children: [
286
302
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SparkleIcon, { spinning: loading }),
287
- loading ? t("button.optimizing") : t("button.optimize")
303
+ t("button.optimize")
288
304
  ]
289
305
  }
290
306
  ) });
@@ -294,6 +310,25 @@ function createOptimizeButton(controller) {
294
310
  // src/client/ResultDock.tsx
295
311
  var import_react3 = require("react");
296
312
 
313
+ // src/client/host-faces.ts
314
+ async function sessionCatalog(connection, signal) {
315
+ const call = connection?.rpc?.call;
316
+ if (!call) return { ok: false, error: "\u8FDE\u63A5\u5C42 RPC \u901A\u9053\u5728\u5F53\u524D dsh \u7248\u672C\u7F3A\u5E2D" };
317
+ const result = await call("/api", "session/modelCatalog", { args: {} }, signal);
318
+ if (!result.ok) {
319
+ return { ok: false, error: result.error };
320
+ }
321
+ return { ok: true, value: { groups: result.value.groups ?? [], failures: result.value.failures } };
322
+ }
323
+ function legacyQueryFace(connection) {
324
+ return connection?.api;
325
+ }
326
+ function sessionEventEntries(sessions, sessionId) {
327
+ const binding = sessions?.binding?.(sessionId);
328
+ const window = binding?.eventSource?.getSnapshot();
329
+ return window?.entries;
330
+ }
331
+
297
332
  // src/prompt.ts
298
333
  var MARKERS = {
299
334
  analysis: "<<<ANALYSIS>>>",
@@ -301,18 +336,18 @@ var MARKERS = {
301
336
  end: "<<<END>>>"
302
337
  };
303
338
  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
339
  ${MARKERS.optimized}
307
340
  \u8F93\u51FA\u4F18\u5316\u540E\u7684\u5B8C\u6574\u63D0\u793A\u8BCD\u5168\u6587
341
+ ${MARKERS.analysis}
342
+ \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
343
  ${MARKERS.end}
309
344
 
310
345
  \u9664\u4E0A\u8FF0\u6807\u8BB0\u5305\u88F9\u7684\u5185\u5BB9\u5916,\u4E0D\u8981\u8F93\u51FA\u4EFB\u4F55\u5176\u4ED6\u6587\u5B57\u3002`;
311
346
  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
347
  ${MARKERS.optimized}
315
348
  The full optimized prompt text
349
+ ${MARKERS.analysis}
350
+ One finding per line: "dimension | issue | suggestion". If a dimension is fine: "dimension | no issue | -".
316
351
  ${MARKERS.end}
317
352
 
318
353
  Do not output anything outside these markers.`;
@@ -331,23 +366,44 @@ Do not output anything outside these markers.`;
331
366
  var CONTEXT_MAX_TURNS = 8;
332
367
  var CONTEXT_MAX_CHARS = 1600;
333
368
  var CONTEXT_TURN_MAX_CHARS = 600;
369
+ var CONTEXT_MIN_USER_TURNS = 1;
370
+ var CONTEXT_USER_BUDGET = 800;
334
371
  function capConversationContext(turns) {
335
372
  const recent = turns.filter((t) => t.text.trim()).slice(-CONTEXT_MAX_TURNS).map((t) => ({
336
373
  role: t.role,
337
374
  text: t.text.trim().length > CONTEXT_TURN_MAX_CHARS ? `${t.text.trim().slice(0, CONTEXT_TURN_MAX_CHARS)}\u2026` : t.text.trim()
338
375
  }));
376
+ if (recent.length === 0) return [];
377
+ const indexed = recent.map((turn, index) => ({ turn, index }));
378
+ const kept = /* @__PURE__ */ new Map();
339
379
  let budget = CONTEXT_MAX_CHARS;
340
- const kept = [];
341
- for (let i = recent.length - 1; i >= 0; i--) {
342
- const turn = recent[i];
343
- if (turn.text.length > budget) {
344
- if (kept.length === 0) kept.push({ role: turn.role, text: `${turn.text.slice(0, budget)}\u2026` });
345
- break;
380
+ const users = indexed.filter((x) => x.turn.role === "user");
381
+ let userBudget = Math.min(CONTEXT_USER_BUDGET, budget);
382
+ for (let i = users.length - 1; i >= 0; i--) {
383
+ const { turn, index } = users[i];
384
+ const keptUsers = users.length - i;
385
+ const mustKeep = keptUsers <= CONTEXT_MIN_USER_TURNS && ![...kept.values()].some((t) => t.role === "user");
386
+ if (turn.text.length <= userBudget) {
387
+ kept.set(index, turn);
388
+ userBudget -= turn.text.length;
389
+ budget -= turn.text.length;
390
+ } else if (mustKeep) {
391
+ const slice = userBudget > 16 ? userBudget : Math.min(16, budget);
392
+ if (slice > 0) {
393
+ kept.set(index, { role: turn.role, text: `${turn.text.slice(0, slice)}\u2026` });
394
+ userBudget -= slice;
395
+ budget -= slice;
396
+ }
346
397
  }
347
- kept.unshift(turn);
398
+ }
399
+ const assistants = indexed.filter((x) => x.turn.role === "assistant");
400
+ for (let i = assistants.length - 1; i >= 0; i--) {
401
+ const { turn, index } = assistants[i];
402
+ if (turn.text.length > budget) continue;
403
+ kept.set(index, turn);
348
404
  budget -= turn.text.length;
349
405
  }
350
- return kept;
406
+ return [...kept.entries()].sort(([a], [b]) => a - b).map(([, turn]) => turn);
351
407
  }
352
408
  function findMarker(text, word, fromIndex = 0) {
353
409
  const re = new RegExp(`<<<\\s*${word}\\s*>>>`, "g");
@@ -355,27 +411,70 @@ function findMarker(text, word, fromIndex = 0) {
355
411
  const match = re.exec(text);
356
412
  return match ? { index: match.index, length: match[0].length } : null;
357
413
  }
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();
414
+ function findLastMarker(text, word, beforeIndex = text.length) {
415
+ const re = new RegExp(`<<<\\s*${word}\\s*>>>`, "g");
416
+ let last = null;
417
+ for (const match of text.matchAll(re)) {
418
+ if (match.index >= beforeIndex) break;
419
+ last = { index: match.index, length: match[0].length };
365
420
  }
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();
421
+ return last;
422
+ }
423
+ function findNextMarker(text, fromIndex) {
424
+ const re = /<<<\s*(?:ANALYSIS|OPTIMIZED|END)\s*>>>/g;
425
+ re.lastIndex = fromIndex;
426
+ const match = re.exec(text);
427
+ return match ? { index: match.index, length: match[0].length } : null;
428
+ }
429
+ function segmentAfter(text, marker) {
430
+ const firstEnd = findMarker(text, "END");
431
+ if (firstEnd && marker.index > firstEnd.index) return "";
432
+ const start = marker.index + marker.length;
433
+ const next = findNextMarker(text, start);
434
+ let end = next ? next.index : text.length;
435
+ if (firstEnd && firstEnd.index > start && firstEnd.index < end) end = firstEnd.index;
436
+ return text.slice(start, end).trim();
437
+ }
438
+ var THINK_OPEN = "<think>";
439
+ var THINK_CLOSE = "</think>";
440
+ function stripThinkBlocks(text) {
441
+ let out = "";
442
+ let rest = text;
443
+ for (; ; ) {
444
+ const open = rest.indexOf(THINK_OPEN);
445
+ if (open === -1) return out + rest;
446
+ out += rest.slice(0, open);
447
+ const close = rest.indexOf(THINK_CLOSE, open + THINK_OPEN.length);
448
+ if (close === -1) return out;
449
+ rest = rest.slice(close + THINK_CLOSE.length);
369
450
  }
370
- return { analysis, optimized };
451
+ }
452
+ function parsePartialOptimizerOutput(raw) {
453
+ const text = stripThinkBlocks(raw);
454
+ const o = findLastMarker(text, "OPTIMIZED");
455
+ const a = findLastMarker(text, "ANALYSIS");
456
+ return {
457
+ analysis: a ? segmentAfter(text, a) : "",
458
+ optimized: o ? segmentAfter(text, o) : ""
459
+ };
371
460
  }
372
461
  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 };
462
+ const o = findLastMarker(raw, "OPTIMIZED");
463
+ const a = findLastMarker(raw, "ANALYSIS");
464
+ if (o && a && o.index < a.index) {
465
+ return {
466
+ compacted: `${MARKERS.analysis}
467
+ ${raw.slice(a.index + a.length)}`,
468
+ analysis: "",
469
+ optimized: raw.slice(o.index + o.length, a.index).trim()
470
+ };
471
+ }
472
+ if (o) {
473
+ const analysis = a && a.index < o.index ? raw.slice(a.index + a.length, o.index).trim() : "";
474
+ return { compacted: `${MARKERS.optimized}
475
+ ${raw.slice(o.index + o.length)}`, analysis, optimized: "" };
476
+ }
477
+ return { compacted: null, analysis: "", optimized: "" };
379
478
  }
380
479
 
381
480
  // src/client/controller.ts
@@ -388,9 +487,12 @@ function splitCommandPrefix(text) {
388
487
  if (!match[2] || !match[2].trim()) return { body: trimmed, commandOnly: true };
389
488
  return { prefix: match[1], body: match[2].trim() };
390
489
  }
490
+ function joinLast(last) {
491
+ return last.prefix ? `${last.prefix} ${last.text}` : last.text;
492
+ }
391
493
  function shouldAutoClose(input) {
392
494
  if (!input.open || input.status === "loading") return false;
393
- return !input.draft.trim() || !input.prevRunning && input.running || input.queued > input.prevQueued;
495
+ return input.phase === "sending" || !input.draft.trim() || !input.prevRunning && input.running || input.queued > input.prevQueued;
394
496
  }
395
497
  function flattenText(content) {
396
498
  if (!Array.isArray(content)) return "";
@@ -428,6 +530,7 @@ function createOptimizerController(ctx, opts = {}) {
428
530
  let abort = null;
429
531
  let liveRaw = "";
430
532
  let frozenAnalysis = "";
533
+ let frozenOptimized = "";
431
534
  let liveTimer = null;
432
535
  const clearLiveTimer = () => {
433
536
  if (liveTimer) {
@@ -458,6 +561,7 @@ function createOptimizerController(ctx, opts = {}) {
458
561
  clearLiveTimer();
459
562
  liveRaw = "";
460
563
  frozenAnalysis = "";
564
+ frozenOptimized = "";
461
565
  const controller = new AbortController();
462
566
  abort = controller;
463
567
  const watchdogMs = Math.max(1e3, opts.getWatchdogMs?.() ?? 125e3);
@@ -472,7 +576,7 @@ function createOptimizerController(ctx, opts = {}) {
472
576
  set({
473
577
  status: "error",
474
578
  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`
579
+ 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
580
  });
477
581
  };
478
582
  const startedAt = Date.now();
@@ -482,12 +586,17 @@ function createOptimizerController(ctx, opts = {}) {
482
586
  (async () => {
483
587
  if (opts.isModelPinned?.()) return void 0;
484
588
  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;
589
+ const directories = opts.getSessionModelDirectories?.();
590
+ if (!directories) {
591
+ 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");
592
+ return void 0;
593
+ }
594
+ const state2 = await directories.directoryFor(sessionId).load();
595
+ const current = state2.current;
596
+ if (current?.provider && current.model) {
488
597
  return { provider: current.provider, model: current.model, reasoningEffort: current.reasoningEffort };
489
598
  }
490
- console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u6A21\u578B\u67E5\u8BE2\u88AB\u62D2\u7EDD,\u6539\u7528 Host \u56DE\u9000:", resp2.result.error);
599
+ 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
600
  } catch (cause) {
492
601
  console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u6A21\u578B\u67E5\u8BE2\u5931\u8D25,\u6539\u7528 Host \u56DE\u9000:", cause);
493
602
  }
@@ -496,12 +605,29 @@ function createOptimizerController(ctx, opts = {}) {
496
605
  (async () => {
497
606
  if (!(opts.isContextEnabled?.() ?? true)) return void 0;
498
607
  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);
608
+ const entries = sessionEventEntries(opts.getSessions?.(), sessionId);
609
+ if (entries?.length) {
610
+ const turns = extractContextTurns(entries);
611
+ if (turns.length) return turns;
612
+ console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u4E8B\u4EF6\u7A97\u53E3\u91CC\u6CA1\u6709\u53EF\u7528\u7684\u5BF9\u8BDD,\u5C1D\u8BD5\u65E7\u67E5\u8BE2\u9762");
613
+ } else {
614
+ console.warn("[dsh-prompt-optimizer] \u5F53\u524D\u4F1A\u8BDD\u6CA1\u6709\u53EF\u8BFB\u7684\u4E8B\u4EF6\u7A97\u53E3,\u5C1D\u8BD5\u65E7\u67E5\u8BE2\u9762");
615
+ }
616
+ } catch (cause) {
617
+ console.warn("[dsh-prompt-optimizer] \u8BFB\u53D6\u4F1A\u8BDD\u4E8B\u4EF6\u7A97\u53E3\u5931\u8D25,\u5C1D\u8BD5\u65E7\u67E5\u8BE2\u9762:", cause);
618
+ }
619
+ try {
620
+ const history = legacyQueryFace(ctx.connection)?.sessions?.history;
621
+ if (!history) {
622
+ 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");
623
+ return void 0;
624
+ }
625
+ const result = await history({ sessionId, maxMessages: 24 }, controller.signal);
626
+ if (result.ok) {
627
+ const turns = extractContextTurns(result.value.events ?? []);
502
628
  return turns.length ? turns : void 0;
503
629
  }
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);
630
+ console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u5386\u53F2\u67E5\u8BE2\u88AB\u62D2\u7EDD,\u6309\u65E0\u4E0A\u4E0B\u6587\u4F18\u5316:", result.error);
505
631
  } catch (cause) {
506
632
  console.warn("[dsh-prompt-optimizer] \u4F1A\u8BDD\u5386\u53F2\u67E5\u8BE2\u5931\u8D25,\u6309\u65E0\u4E0A\u4E0B\u6587\u4F18\u5316:", cause);
507
633
  }
@@ -511,7 +637,10 @@ function createOptimizerController(ctx, opts = {}) {
511
637
  const resp = await fetch(ROUTE, {
512
638
  method: "POST",
513
639
  headers: { "content-type": "application/json" },
514
- body: JSON.stringify({ text: draft, provider: selection?.provider, model: selection?.model, reasoningEffort: selection?.reasoningEffort, context, previous }),
640
+ // sessionId 随请求带给 Host:Host 把它标注到 llm 调用上,要求会话头
641
+ // 的提供方(如 opencode 的 x-opencode-session)才能路由成功,同时
642
+ // 会话级计量会把这次调用归属到当前会话。
643
+ body: JSON.stringify({ text: draft, sessionId, provider: selection?.provider, model: selection?.model, reasoningEffort: selection?.reasoningEffort, context, previous }),
515
644
  signal: controller.signal
516
645
  });
517
646
  if (!resp.ok || !(resp.headers.get("content-type") ?? "").includes("text/event-stream")) {
@@ -536,7 +665,13 @@ function createOptimizerController(ctx, opts = {}) {
536
665
  buffer = buffer.slice(sep + 2);
537
666
  const line = frame.split("\n").find((l) => l.startsWith("data:"));
538
667
  if (!line) continue;
539
- const event = JSON.parse(line.slice(5).trim());
668
+ let event;
669
+ try {
670
+ event = JSON.parse(line.slice(5).trim());
671
+ } catch {
672
+ console.warn("[dsh-prompt-optimizer] \u8DF3\u8FC7\u65E0\u6CD5\u89E3\u6790\u7684 SSE \u5E27:", line.slice(0, 120));
673
+ continue;
674
+ }
540
675
  if (event.type === "delta") {
541
676
  liveRaw += String(event.text ?? "");
542
677
  if (!liveTimer) {
@@ -545,11 +680,12 @@ function createOptimizerController(ctx, opts = {}) {
545
680
  if (state.status === "loading" && abort === controller) {
546
681
  const comp = compactPartialBuffer(liveRaw);
547
682
  if (comp.compacted !== null) {
548
- frozenAnalysis = comp.analysis;
683
+ if (comp.analysis) frozenAnalysis = comp.analysis;
684
+ if (comp.optimized) frozenOptimized = comp.optimized;
549
685
  liveRaw = comp.compacted;
550
686
  }
551
687
  const partial = parsePartialOptimizerOutput(liveRaw);
552
- const live = { analysis: partial.analysis || frozenAnalysis, optimized: partial.optimized };
688
+ const live = { analysis: partial.analysis || frozenAnalysis, optimized: partial.optimized || frozenOptimized };
553
689
  if (opts.isFastMode?.() && !live.analysis && !live.optimized && liveRaw.trim() && !liveRaw.includes("<<<")) {
554
690
  live.optimized = liveRaw.trim();
555
691
  }
@@ -608,7 +744,7 @@ function createOptimizerController(ctx, opts = {}) {
608
744
  getSnapshot: () => state,
609
745
  optimize,
610
746
  retry() {
611
- if (state.last) void optimize(state.last.text, state.last.sessionId);
747
+ if (state.last) void optimize(joinLast(state.last), state.last.sessionId);
612
748
  },
613
749
  markApplied(applied) {
614
750
  set({ applied });
@@ -662,12 +798,14 @@ async function copyText(text) {
662
798
  var styles = {
663
799
  panel: {
664
800
  marginBottom: 6,
665
- borderRadius: 10,
801
+ borderRadius: 12,
666
802
  border: "1px solid var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.3))",
667
- background: "var(--dsw-alias-bg-layer-2, #202226)",
803
+ background: "var(--dsw-alias-bg-layer-2, #fff)",
668
804
  color: "var(--dsw-alias-label-primary, inherit)",
669
- boxShadow: "0 4px 16px rgba(0, 0, 0, 0.12)",
670
- padding: "10px 12px",
805
+ // 阴影从 0.12 降到与官方输入卡同档的极淡弥散(0.03~0.05):
806
+ // 之前的重投影在白底上晕出一圈灰,是面板「显灰显大」的另一来源。
807
+ boxShadow: "0 1px 2px rgba(0, 0, 0, 0.03), 0 4px 14px rgba(0, 0, 0, 0.05)",
808
+ padding: "8px 10px",
671
809
  fontSize: 12.5,
672
810
  lineHeight: 1.5,
673
811
  fontFamily: "var(--dsw-font-family, inherit)"
@@ -692,12 +830,14 @@ var styles = {
692
830
  // U5:分析与优化各自独立滚动区(原先单容器 maxHeight 嵌套出现双滚动条),
693
831
  // 长内容不再互相挤压;外层 body 不限高,滚动归属到各段内部。
694
832
  body: { paddingRight: 4 },
695
- analysisBody: { maxHeight: "16vh", overflowY: "auto", marginTop: 2 },
833
+ analysisBody: { maxHeight: "14vh", overflowY: "auto", marginTop: 2 },
696
834
  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",
835
+ // 层面令牌在浅色主题下是纯白,填充不可见,用细描边给出容器感(不引入灰底)。
836
+ background: "var(--dsw-alias-bg-layer-3, transparent)",
837
+ border: "1px solid var(--dsw-alias-border-l3, rgba(128,128,128,0.2))",
838
+ borderRadius: 8,
839
+ padding: "5px 8px",
840
+ maxHeight: "22vh",
701
841
  overflowY: "auto",
702
842
  marginTop: 2
703
843
  },
@@ -709,7 +849,7 @@ var styles = {
709
849
  fontSize: 11,
710
850
  fontWeight: 600,
711
851
  color: "var(--dsw-alias-label-primary-dimmed, rgba(128,128,128,0.9))",
712
- margin: "6px 0 2px",
852
+ margin: "5px 0 2px",
713
853
  padding: 0,
714
854
  border: "none",
715
855
  background: "none",
@@ -719,15 +859,17 @@ var styles = {
719
859
  },
720
860
  chevron: { fontSize: 9, transition: "transform 0.15s ease" },
721
861
  pre: { margin: 0, whiteSpace: "pre-wrap", wordBreak: "break-word", fontFamily: "inherit" },
722
- actions: { display: "flex", gap: 8, marginTop: 8 },
862
+ actions: { display: "flex", gap: 8, marginTop: 6 },
723
863
  actionBtn: {
724
864
  display: "inline-flex",
725
865
  alignItems: "center",
726
- padding: "4px 12px",
866
+ padding: "3px 10px",
727
867
  fontSize: 12,
728
868
  borderRadius: 6,
729
869
  border: "1px solid var(--dsw-alias-border-l2, rgba(128,128,128,0.4))",
730
- background: "var(--dsw-alias-button-tool-bar-fill, transparent)",
870
+ // 幽灵按钮:button-tool-bar-fill 在当前主题是 50% 灰(#54555780),整排灰块
871
+ // 是面板显灰的主因,改为透明底 + 细描边,与输入卡的工具按钮同语言。
872
+ background: "transparent",
731
873
  color: "var(--dsw-alias-label-primary, inherit)",
732
874
  cursor: "pointer"
733
875
  },
@@ -798,6 +940,7 @@ function createResultDock(controller) {
798
940
  }, [owns]);
799
941
  const applied = state.applied;
800
942
  const draft = input.draft ?? "";
943
+ const phase = input.phase;
801
944
  const running = Boolean(session.running);
802
945
  const queued = session.queue?.length ?? 0;
803
946
  const prevRef = (0, import_react3.useRef)({ running, queued });
@@ -805,12 +948,12 @@ function createResultDock(controller) {
805
948
  const prev = prevRef.current;
806
949
  prevRef.current = { running, queued };
807
950
  if (!owns) return;
808
- if (shouldAutoClose({ open: true, status: state.status, draft, prevRunning: prev.running, running, prevQueued: prev.queued, queued })) {
951
+ if (shouldAutoClose({ open: true, status: state.status, draft, phase, prevRunning: prev.running, running, prevQueued: prev.queued, queued })) {
809
952
  controller.close();
810
953
  return;
811
954
  }
812
955
  if (applied && draft !== applied.text) controller.clearApplied();
813
- }, [draft, applied, owns, state.status, running, queued]);
956
+ }, [draft, phase, applied, owns, state.status, running, queued]);
814
957
  const [elapsed, setElapsed] = (0, import_react3.useState)(0);
815
958
  (0, import_react3.useEffect)(() => {
816
959
  if (state.status !== "loading") return;
@@ -869,88 +1012,92 @@ function createResultDock(controller) {
869
1012
  controller.clearApplied();
870
1013
  setUndoneFlash(true);
871
1014
  };
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") })
1015
+ return (
1016
+ // 非模态 dock(不抢焦点、无焦点陷阱),用 region 而非 dialog:
1017
+ // dialog 会让读屏用户期待焦点管理,而这里并没有。
1018
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.panel, role: "region", "aria-label": t("panel.aria"), children: [
1019
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.header, children: [
1020
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SparkleIcon, { size: 15 }),
1021
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: styles.title, children: t("panel.title") }),
1022
+ result && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1023
+ "span",
1024
+ {
1025
+ style: styles.modelBadge,
1026
+ title: result.fallbackUsed && result.fallbackReason ? `${t("panel.fallback")}: ${result.fallbackReason}` : void 0,
1027
+ children: [
1028
+ result.provider,
1029
+ " / ",
1030
+ result.model,
1031
+ result.fallbackUsed ? ` \xB7 ${t("panel.fallback")}` : "",
1032
+ typeof result.durationMs === "number" ? ` \xB7 ${t("panel.duration")} ${(result.durationMs / 1e3).toFixed(1)}s` : ""
1033
+ ]
1034
+ }
1035
+ ),
1036
+ applied && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: styles.statusChip, children: t("panel.appliedShort") }),
1037
+ !applied && undoneFlash && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: styles.statusChip, children: t("panel.undoneShort") }),
1038
+ /* @__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
1039
  ] }),
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 }) })
1040
+ state.status === "loading" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1041
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.loading, children: [
1042
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SparkleIcon, { spinning: true }),
1043
+ stage,
1044
+ "\u2026(",
1045
+ elapsed,
1046
+ "s,",
1047
+ t("panel.escCancel"),
1048
+ ")"
934
1049
  ] }),
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") })
1050
+ liveBody
1051
+ ] }),
1052
+ state.status === "cancelled" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1053
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.cancelledHint, children: t("panel.cancelled") }),
1054
+ liveBody,
1055
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.actions, children: [
1056
+ /* @__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") }),
1057
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: () => controller.close(), children: t("panel.close") })
940
1058
  ] })
941
1059
  ] }),
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
- ] }) })
1060
+ state.status === "error" && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1061
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.sectionTitle, children: t("panel.error") }),
1062
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.errorText, children: state.error }),
1063
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.actions, children: [
1064
+ /* @__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") }),
1065
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: () => controller.close(), children: t("panel.close") })
1066
+ ] })
1067
+ ] }),
1068
+ state.status === "done" && result && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1069
+ !result.wellFormed && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { ...styles.warnBanner, marginTop: 0, marginBottom: 8 }, children: [
1070
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "aria-hidden": true, children: "\u26A0" }),
1071
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: t("panel.notWellFormed") })
1072
+ ] }),
1073
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.body, children: [
1074
+ result.analysis && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1075
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("button", { className: "dsh-po-btn", type: "button", style: styles.sectionTitle, onClick: () => setAnalysisOpen((v) => !v), "aria-expanded": analysisOpen, children: [
1076
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { ...styles.chevron, transform: analysisOpen ? "rotate(90deg)" : "none" }, children: "\u25B8" }),
1077
+ t("panel.analysis")
1078
+ ] }),
1079
+ 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 }) })
1080
+ ] }),
1081
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { ...styles.sectionTitle, cursor: "default" }, children: t("panel.optimized") }),
1082
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.optimizedBox, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("pre", { style: styles.pre, children: result.optimized }) }),
1083
+ result.truncated && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: styles.warnBanner, children: [
1084
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "aria-hidden": true, children: "\u26A0" }),
1085
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { children: t("panel.truncated") })
1086
+ ] })
1087
+ ] }),
1088
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: styles.actions, children: applied ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1089
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: { ...styles.actionBtn, ...styles.primaryBtn }, onClick: onUndo, children: t("panel.undo") }),
1090
+ /* @__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") }),
1091
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: () => controller.close(), children: t("panel.close") })
1092
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
1093
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: { ...styles.actionBtn, ...styles.primaryBtn }, onClick: onReplace, children: t("panel.replace") }),
1094
+ /* @__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") }),
1095
+ /* @__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") }),
1096
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "dsh-po-btn", type: "button", style: styles.actionBtn, onClick: () => controller.close(), children: t("panel.close") })
1097
+ ] }) })
1098
+ ] })
952
1099
  ] })
953
- ] });
1100
+ );
954
1101
  };
955
1102
  }
956
1103
 
@@ -978,91 +1125,102 @@ function GitHubIcon(props) {
978
1125
  // src/client/SettingsCard.tsx
979
1126
  var import_jsx_runtime5 = require("react/jsx-runtime");
980
1127
  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
- };
1128
+ var STYLES_ID = "dsh-prompt-optimizer-settings-styles";
1129
+ function ensureStyles() {
1130
+ if (typeof document === "undefined") return;
1131
+ if (document.getElementById(STYLES_ID)) return;
1132
+ const style = document.createElement("style");
1133
+ style.id = STYLES_ID;
1134
+ style.textContent = `
1135
+ .dsh-po-sec{display:flex;flex-direction:column;width:100%;color:var(--dsw-alias-label-primary)}
1136
+ .dsh-po-group{margin:14px 0 2px;padding:0;font-size:12px;font-weight:600;line-height:18px;color:var(--dsw-alias-label-secondary)}
1137
+ .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)}
1138
+ .dsh-po-row:last-child{border-bottom:none}
1139
+ .dsh-po-rowText{min-width:0}
1140
+ .dsh-po-rowTitle{font-size:14px;line-height:20px}
1141
+ .dsh-po-rowDesc{margin-top:4px;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}
1142
+ .dsh-po-hint{padding:10px 0;font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}
1143
+ .dsh-po-status{font-size:12px;line-height:18px;color:var(--dsw-alias-label-secondary)}
1144
+ /* \u5206\u6BB5\u63A7\u4EF6(\u5B98\u65B9 SegmentedControl \u540C\u6B3E):\u6D45\u5E95\u8F68\u9053 + \u9009\u4E2D\u767D\u80F6\u56CA\u6ED1\u52A8\u6307\u793A\u3002 */
1145
+ .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}
1146
+ .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}
1147
+ .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}
1148
+ .dsh-po-segTab:hover:not(:disabled),.dsh-po-segTab[aria-selected='true']{color:var(--dsw-alias-label-primary,inherit)}
1149
+ .dsh-po-segTab:disabled{cursor:default;opacity:0.4}
1150
+ /* \u5F00\u5173(\u5B98\u65B9 Switch \u540C\u6B3E):36\xD720 \u80F6\u56CA\u8F68\u9053 + 16px \u5706\u5F62\u6ED1\u5757\u3002 */
1151
+ .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}
1152
+ .dsh-po-switch[aria-checked='true']{background:var(--dsw-alias-brand-primary,#4f7cf7)}
1153
+ .dsh-po-switch:disabled{cursor:default;opacity:0.5}
1154
+ .dsh-po-switchThumb{display:block;width:16px;height:16px;border-radius:50%;background:var(--dsw-alias-label-primary-foreground,#fff);transition:transform 120ms ease}
1155
+ .dsh-po-switch[aria-checked='false'] .dsh-po-switchThumb{background:var(--dsw-alias-switch-thumb,#fff)}
1156
+ .dsh-po-switch[aria-checked='true'] .dsh-po-switchThumb{transform:translateX(16px)}
1157
+ /* \u884C\u5185\u63A7\u4EF6:select / input / \u6B21\u7EA7\u6309\u94AE\u3002 */
1158
+ .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}
1159
+ .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)}
1160
+ .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}
1161
+ .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}
1162
+ .dsh-po-btn2:hover:not(:disabled){background:var(--dsw-alias-interactive-bg-hover,rgba(128,128,128,0.14))}
1163
+ .dsh-po-btn2:disabled{opacity:0.45;cursor:default}
1164
+ .dsh-po-fieldError{font-size:12px;line-height:18px;color:var(--dsw-alias-state-error-primary,#e5534b)}
1165
+ /* \u9009\u4E2D\u884C\u63A7\u4EF6\u7684\u8868\u5355\u9519\u8BEF\u6001(\u6587\u672C\u8F93\u5165\u6821\u9A8C\u5931\u8D25)\u3002 */
1166
+ .dsh-po-input[data-invalid='true']{border-color:var(--dsw-alias-state-error-primary,#e5534b)}
1167
+ `;
1168
+ document.head.appendChild(style);
1169
+ }
1170
+ function Row({ title, desc, children }) {
1171
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsh-po-row", children: [
1172
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsh-po-rowText", children: [
1173
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-rowTitle", children: title }),
1174
+ desc && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-rowDesc", children: desc })
1175
+ ] }),
1176
+ children
1177
+ ] });
1178
+ }
1179
+ function Segmented(props) {
1180
+ const selected = props.options.findIndex((o) => o.value === props.value);
1181
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1182
+ "span",
1183
+ {
1184
+ className: "dsh-po-seg",
1185
+ role: "tablist",
1186
+ "aria-label": props.label,
1187
+ style: { "--dsh-segment-count": props.options.length, "--dsh-segment-index": selected < 0 ? 0 : selected },
1188
+ children: [
1189
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "dsh-po-segIndicator", "aria-hidden": "true" }),
1190
+ props.options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1191
+ "button",
1192
+ {
1193
+ type: "button",
1194
+ role: "tab",
1195
+ className: "dsh-po-segTab dsh-po-btn",
1196
+ "aria-selected": option.value === props.value,
1197
+ title: option.title,
1198
+ onClick: () => {
1199
+ if (option.value !== props.value) props.onChange(option.value);
1200
+ },
1201
+ children: option.label
1202
+ },
1203
+ option.value
1204
+ ))
1205
+ ]
1206
+ }
1207
+ );
1208
+ }
1209
+ function Toggle(props) {
1210
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1211
+ "button",
1212
+ {
1213
+ type: "button",
1214
+ role: "switch",
1215
+ className: "dsh-po-switch dsh-po-btn",
1216
+ "aria-checked": props.checked,
1217
+ "aria-label": props.label,
1218
+ disabled: props.disabled,
1219
+ onClick: () => props.onChange(!props.checked),
1220
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "dsh-po-switchThumb" })
1221
+ }
1222
+ );
1223
+ }
1066
1224
  function TextField(props) {
1067
1225
  const [text, setText] = (0, import_react4.useState)(props.value);
1068
1226
  const [error, setError] = (0, import_react4.useState)(null);
@@ -1080,15 +1238,17 @@ function TextField(props) {
1080
1238
  setError(null);
1081
1239
  props.onCommit(text);
1082
1240
  };
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 }),
1241
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "flex", flexDirection: "column", alignItems: "flex-end", gap: 2, flex: "none" }, children: [
1085
1242
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1086
1243
  "input",
1087
1244
  {
1088
- className: "dsh-po-btn",
1089
- style: { ...styles2.input, ...error ? { borderColor: "var(--dsw-alias-state-error-primary, #e5534b)" } : {} },
1245
+ className: "dsh-po-input dsh-po-btn",
1246
+ "data-invalid": error ? "true" : void 0,
1247
+ style: props.width ? { width: props.width } : void 0,
1090
1248
  value: text,
1091
1249
  placeholder: props.placeholder,
1250
+ "aria-label": props.label,
1251
+ title: props.labelTitle,
1092
1252
  onChange: (e) => {
1093
1253
  setText(e.target.value);
1094
1254
  setError(null);
@@ -1099,17 +1259,48 @@ function TextField(props) {
1099
1259
  }
1100
1260
  }
1101
1261
  ),
1102
- error && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: styles2.fieldError, children: error })
1262
+ error && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "dsh-po-fieldError", children: error })
1103
1263
  ] });
1104
1264
  }
1105
- function createSettingsCard(ctx, scope) {
1265
+ function ModelSelect(props) {
1266
+ if (props.groups === null) {
1267
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "dsh-po-status", style: { flex: "none", maxWidth: 300, textAlign: "right" }, children: [
1268
+ props.catalogState === "error" ? "\u2014" : "\u2026",
1269
+ props.catalogHint ? `(${props.catalogHint})` : ""
1270
+ ] });
1271
+ }
1272
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { style: { display: "inline-flex", alignItems: "center", gap: 8, flex: "none" }, children: [
1273
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1274
+ "select",
1275
+ {
1276
+ className: "dsh-po-select dsh-po-btn",
1277
+ style: { backgroundImage: catalogChevron() },
1278
+ value: props.value,
1279
+ "aria-label": props.label,
1280
+ onChange: (e) => props.onChange(e.target.value),
1281
+ children: [
1282
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "", children: props.noneLabel }),
1283
+ 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))
1284
+ ]
1285
+ }
1286
+ ),
1287
+ /* @__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 })
1288
+ ] });
1289
+ }
1290
+ function catalogChevron() {
1291
+ 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>`;
1292
+ return `url("data:image/svg+xml,${svg.replace(/"/g, "'")}")`;
1293
+ }
1294
+ function createSettingsCard(ctx, face2) {
1295
+ ensureStyles();
1106
1296
  return function PromptOptimizerSettingsCard() {
1107
1297
  const snap = (0, import_react4.useSyncExternalStore)(
1108
- (callback) => scope.subscribe(callback),
1109
- () => scope.getSnapshot()
1298
+ (callback) => face2.subscribe(callback),
1299
+ () => face2.getSnapshot()
1110
1300
  );
1111
1301
  const t = useT();
1112
1302
  const value = snap.value ?? {};
1303
+ const writable = snap.writable !== false;
1113
1304
  const SETTING_KEYS = [
1114
1305
  "language",
1115
1306
  "model",
@@ -1128,7 +1319,8 @@ function createSettingsCard(ctx, scope) {
1128
1319
  fallbackModel: "",
1129
1320
  maxTokens: 8192,
1130
1321
  timeoutSeconds: 120,
1131
- mode: "full",
1322
+ // 与 Host 侧 Config 默认口径一致(0.5.0 起默认快速模式)。
1323
+ mode: "fast",
1132
1324
  reasoningEffort: "lowest",
1133
1325
  temperature: 0.2,
1134
1326
  autoMaxTokens: true,
@@ -1143,7 +1335,7 @@ function createSettingsCard(ctx, scope) {
1143
1335
  if (undoStack.current.length > 20) undoStack.current.shift();
1144
1336
  setCanUndo(true);
1145
1337
  }
1146
- void scope.set(key, v);
1338
+ void face2.set(key, v);
1147
1339
  };
1148
1340
  const undoLastChange = () => {
1149
1341
  const prev = undoStack.current.pop();
@@ -1154,7 +1346,7 @@ function createSettingsCard(ctx, scope) {
1154
1346
  for (const k of SETTING_KEYS) {
1155
1347
  const target = prev[k] ?? SETTING_DEFAULTS[k];
1156
1348
  if (value[k] !== target) {
1157
- void scope.set(k, target);
1349
+ void face2.set(k, target);
1158
1350
  }
1159
1351
  }
1160
1352
  } finally {
@@ -1163,17 +1355,26 @@ function createSettingsCard(ctx, scope) {
1163
1355
  };
1164
1356
  const [groups, setGroups] = (0, import_react4.useState)(null);
1165
1357
  const [catalogState, setCatalogState] = (0, import_react4.useState)("loading");
1358
+ const [catalogHint, setCatalogHint] = (0, import_react4.useState)(null);
1166
1359
  const loadCatalog = async () => {
1167
1360
  setCatalogState("loading");
1361
+ setCatalogHint(null);
1168
1362
  try {
1169
- const resp = await ctx.connection.api.llm.models({});
1170
- if (resp.result.ok) {
1171
- setGroups(resp.result.value.groups);
1363
+ const result = await sessionCatalog(ctx.connection);
1364
+ if (result.ok) {
1365
+ setGroups(result.value.groups);
1172
1366
  setCatalogState("ready");
1367
+ const failures = result.value.failures ?? [];
1368
+ if (failures.length) {
1369
+ setCatalogHint(failures.map((f) => `${f.name || f.id}: ${f.message}`).join("; "));
1370
+ }
1173
1371
  } else {
1372
+ const message = typeof result.error === "string" ? result.error : result.error?.message;
1373
+ setCatalogHint(message ?? null);
1174
1374
  setCatalogState("error");
1175
1375
  }
1176
- } catch {
1376
+ } catch (cause) {
1377
+ setCatalogHint(cause instanceof Error ? cause.message : String(cause));
1177
1378
  setCatalogState("error");
1178
1379
  }
1179
1380
  };
@@ -1199,262 +1400,265 @@ function createSettingsCard(ctx, scope) {
1199
1400
  setTest({ status: "fail", message: cause instanceof Error ? cause.message : String(cause) });
1200
1401
  }
1201
1402
  };
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
- ] }),
1403
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: "dsh-po-sec", children: [
1404
+ snap.status === "loading" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-hint", children: t("settings.loading") }),
1405
+ snap.status === "unavailable" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-hint", children: t("settings.unavailable") }),
1406
+ !writable && snap.status === "ready" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-hint", children: t("settings.readOnly") }),
1407
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-group", children: t("settings.group.model") }),
1408
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.model"), desc: t("settings.model.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1409
+ ModelSelect,
1410
+ {
1411
+ label: t("settings.model"),
1412
+ value: value.model ?? "",
1413
+ groups,
1414
+ catalogState,
1415
+ catalogHint,
1416
+ noneLabel: t("settings.model.follow"),
1417
+ onChange: (v) => setValue("model", v),
1418
+ onRefresh: () => void loadCatalog(),
1419
+ refreshTitle: t("settings.refreshTitle"),
1420
+ refreshLabel: t("settings.refresh")
1421
+ }
1422
+ ) }),
1423
+ 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)(
1424
+ "select",
1425
+ {
1426
+ className: "dsh-po-select dsh-po-btn",
1427
+ style: { backgroundImage: catalogChevron() },
1428
+ value: value.fallbackModel ?? "",
1429
+ "aria-label": t("settings.fallbackModel"),
1430
+ onChange: (e) => setValue("fallbackModel", e.target.value),
1431
+ children: [
1432
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "", children: t("settings.fallbackModel.none") }),
1433
+ 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))
1434
+ ]
1435
+ }
1436
+ ) }),
1437
+ /* @__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: [
1438
+ 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
1439
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1237
- "a",
1440
+ "button",
1238
1441
  {
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 })
1442
+ className: "dsh-po-btn2 dsh-po-btn",
1443
+ type: "button",
1444
+ disabled: test.status === "testing",
1445
+ onClick: () => void runTest(),
1446
+ children: test.status === "testing" ? t("settings.test.running") : t("settings.test.run")
1248
1447
  }
1249
1448
  )
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
- ),
1449
+ ] }) }),
1450
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-group", children: t("settings.group.params") }),
1451
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.language"), desc: t("settings.language.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1452
+ Segmented,
1453
+ {
1454
+ label: t("settings.language"),
1455
+ value: value.language ?? "zh",
1456
+ options: [
1457
+ { value: "zh", label: "\u4E2D\u6587" },
1458
+ { value: "en", label: "English" }
1459
+ ],
1460
+ onChange: (v) => setValue("language", v)
1461
+ }
1462
+ ) }),
1463
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.mode"), desc: t("settings.mode.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1464
+ Segmented,
1465
+ {
1466
+ label: t("settings.mode"),
1467
+ value: value.mode ?? "fast",
1468
+ options: [
1469
+ { value: "full", label: t("settings.mode.full.short"), title: t("settings.mode.full") },
1470
+ { value: "fast", label: t("settings.mode.fast.short"), title: t("settings.mode.fast") }
1471
+ ],
1472
+ onChange: (v) => setValue("mode", v)
1473
+ }
1474
+ ) }),
1475
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.effort"), desc: t("settings.effort.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1476
+ Segmented,
1477
+ {
1478
+ label: t("settings.effort"),
1479
+ value: value.reasoningEffort ?? "lowest",
1480
+ options: [
1481
+ { value: "lowest", label: t("settings.effort.lowest.short"), title: t("settings.effort.lowest") },
1482
+ { value: "session", label: t("settings.effort.session.short"), title: t("settings.effort.session") }
1483
+ ],
1484
+ onChange: (v) => setValue("reasoningEffort", v)
1485
+ }
1486
+ ) }),
1487
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.maxTokens"), desc: t("settings.maxTokens.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1488
+ TextField,
1489
+ {
1490
+ label: t("settings.maxTokens"),
1491
+ value: String(value.maxTokens ?? 8192),
1492
+ placeholder: "8192",
1493
+ validate: (v) => {
1494
+ const n = Number.parseInt(v, 10);
1495
+ return Number.isFinite(n) && n >= 1024 && n <= 32768 ? null : t("settings.validate.maxTokens");
1496
+ },
1497
+ onCommit: (v) => setValue("maxTokens", Number.parseInt(v, 10))
1498
+ }
1499
+ ) }),
1500
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.timeout"), desc: t("settings.timeout.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1501
+ TextField,
1502
+ {
1503
+ label: t("settings.timeout"),
1504
+ value: String(value.timeoutSeconds ?? 120),
1505
+ placeholder: "120",
1506
+ validate: (v) => {
1507
+ const n = Number.parseInt(v, 10);
1508
+ return Number.isFinite(n) && n >= 10 && n <= 600 ? null : t("settings.validate.timeout");
1509
+ },
1510
+ onCommit: (v) => setValue("timeoutSeconds", Number.parseInt(v, 10))
1511
+ }
1512
+ ) }),
1513
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.temperature"), desc: t("settings.temperature.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1514
+ TextField,
1515
+ {
1516
+ label: t("settings.temperature"),
1517
+ labelTitle: t("settings.temperatureTitle"),
1518
+ value: String(value.temperature ?? 0.2),
1519
+ placeholder: "0.2",
1520
+ width: 100,
1521
+ validate: (v) => {
1522
+ const n = Number.parseFloat(v);
1523
+ return Number.isFinite(n) && n >= 0 && n <= 2 ? null : t("settings.validate.temperature");
1524
+ },
1525
+ onCommit: (v) => setValue("temperature", Number.parseFloat(v))
1526
+ }
1527
+ ) }),
1528
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "dsh-po-group", children: t("settings.group.context") }),
1529
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.includeContext"), desc: t("settings.includeContext.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1530
+ Toggle,
1531
+ {
1532
+ label: t("settings.includeContext"),
1533
+ checked: value.includeContext !== false,
1534
+ onChange: (next) => setValue("includeContext", next)
1535
+ }
1536
+ ) }),
1537
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { title: t("settings.autoMaxTokens"), desc: t("settings.autoMaxTokens.desc"), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1538
+ Toggle,
1539
+ {
1540
+ label: t("settings.autoMaxTokens"),
1541
+ checked: value.autoMaxTokens !== false,
1542
+ onChange: (next) => setValue("autoMaxTokens", next)
1543
+ }
1544
+ ) }),
1545
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "dsh-po-row", style: { paddingBottom: 4, gap: 12 }, children: [
1400
1546
  /* @__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
1547
  "button",
1431
1548
  {
1432
- className: "dsh-po-btn",
1549
+ className: "dsh-po-btn2 dsh-po-btn",
1433
1550
  type: "button",
1434
- style: { ...styles2.refreshBtn, ...!canUndo ? { opacity: 0.45, cursor: "default" } : {} },
1435
1551
  disabled: !canUndo,
1436
1552
  title: t("settings.undoTitle"),
1437
1553
  onClick: undoLastChange,
1438
1554
  children: t("settings.undo")
1439
1555
  }
1440
- ) }),
1441
- !snap.writable && snap.status === "ready" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: styles2.hint, children: t("settings.memoryOnly") })
1556
+ ),
1557
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1558
+ "a",
1559
+ {
1560
+ className: "dsh-po-repo-link dsh-po-btn",
1561
+ href: REPO_URL,
1562
+ target: "_blank",
1563
+ rel: "noreferrer noopener",
1564
+ title: t("settings.repoTitle"),
1565
+ style: {
1566
+ display: "inline-flex",
1567
+ alignItems: "center",
1568
+ gap: 6,
1569
+ padding: "4px 10px",
1570
+ fontSize: 12,
1571
+ borderRadius: 6,
1572
+ color: "var(--dsw-alias-label-secondary, inherit)",
1573
+ textDecoration: "none"
1574
+ },
1575
+ children: [
1576
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(GitHubIcon, { size: 14 }),
1577
+ "GitHub"
1578
+ ]
1579
+ }
1580
+ )
1442
1581
  ] })
1443
1582
  ] });
1444
1583
  };
1445
1584
  }
1446
1585
 
1586
+ // src/client/settings-face.ts
1587
+ function createSettingsFace() {
1588
+ let backend = null;
1589
+ let offBackend = null;
1590
+ const listeners = /* @__PURE__ */ new Set();
1591
+ let loadingSnapshot = null;
1592
+ let cachedSnapshot = null;
1593
+ const notify = () => {
1594
+ cachedSnapshot = null;
1595
+ for (const listener of listeners) listener();
1596
+ };
1597
+ function use(next) {
1598
+ if (backend?.via === "forms" && next.via === "legacy") return;
1599
+ if (backend === next) return;
1600
+ offBackend?.();
1601
+ backend = next;
1602
+ offBackend = next.subscribeRaw(notify);
1603
+ notify();
1604
+ }
1605
+ const face2 = {
1606
+ subscribe(fn) {
1607
+ listeners.add(fn);
1608
+ return () => {
1609
+ listeners.delete(fn);
1610
+ };
1611
+ },
1612
+ getSnapshot() {
1613
+ if (!backend) {
1614
+ loadingSnapshot ?? (loadingSnapshot = { status: "loading" });
1615
+ return loadingSnapshot;
1616
+ }
1617
+ cachedSnapshot ?? (cachedSnapshot = (() => {
1618
+ const snap = backend.getSnapshot();
1619
+ const status = snap.status === "ready" || snap.status === "unavailable" ? snap.status : "loading";
1620
+ return { status, value: snap.value, writable: snap.writable };
1621
+ })());
1622
+ return cachedSnapshot;
1623
+ },
1624
+ set(key, value) {
1625
+ return backend ? backend.set(key, value) : Promise.reject(new Error("\u8BBE\u7F6E\u670D\u52A1\u5C1A\u672A\u5C31\u7EEA"));
1626
+ }
1627
+ };
1628
+ return {
1629
+ face: face2,
1630
+ attachLegacy(scope) {
1631
+ use({
1632
+ via: "legacy",
1633
+ subscribeRaw: (fn) => scope.subscribe(fn),
1634
+ getSnapshot: () => scope.getSnapshot(),
1635
+ set: (key, value) => scope.set(key, value)
1636
+ });
1637
+ },
1638
+ attachForms(forms, entryId) {
1639
+ const form = forms.get(entryId);
1640
+ use({
1641
+ via: "forms",
1642
+ subscribeRaw: (fn) => form.subscribe(fn),
1643
+ getSnapshot: () => form.getSnapshot(),
1644
+ set: (field, value) => form.set(field, value)
1645
+ });
1646
+ }
1647
+ };
1648
+ }
1649
+
1447
1650
  // src/client/index.tsx
1448
1651
  var name = "dsh-prompt-optimizer-client";
1449
- var inject = ["slots", "connection", "remote", "settingsScope"];
1652
+ var inject = ["slots", "connection", "remote"];
1450
1653
  var BUTTON_CLASS = "dsh-po-btn";
1654
+ var SETTINGS_ENTRY_ID = "prompt-optimizer";
1451
1655
  function ensureFocusStyles() {
1452
1656
  if (typeof document === "undefined") return;
1453
1657
  const ID = "dsh-prompt-optimizer-focus-styles";
1454
1658
  if (document.getElementById(ID)) return;
1455
1659
  const style = document.createElement("style");
1456
1660
  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));}";
1661
+ 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
1662
  document.head.appendChild(style);
1459
1663
  }
1460
1664
  function apply(ctx) {
@@ -1462,7 +1666,24 @@ function apply(ctx) {
1462
1666
  ctx.inject(["locale"], (lctx) => {
1463
1667
  installLocaleFace(lctx.locale ?? null);
1464
1668
  });
1465
- const scope = ctx.settingsScope.bind({ namespace: "prompt-optimizer" });
1669
+ let modelDirectories;
1670
+ ctx.inject(["modelDirectories"], (mctx) => {
1671
+ modelDirectories = mctx.modelDirectories;
1672
+ });
1673
+ let sessions;
1674
+ ctx.inject(["sessions"], (sctx) => {
1675
+ sessions = sctx.sessions;
1676
+ });
1677
+ const settings = createSettingsFace();
1678
+ ctx.inject(["configForms"], (cctx) => {
1679
+ const forms = cctx.configForms;
1680
+ if (forms) settings.attachForms(forms, SETTINGS_ENTRY_ID);
1681
+ });
1682
+ ctx.inject(["settingsScope"], (sctx) => {
1683
+ const binder = sctx.settingsScope;
1684
+ if (binder) settings.attachLegacy(binder.bind({ namespace: SETTINGS_ENTRY_ID }));
1685
+ });
1686
+ const scope = { getSnapshot: () => settings.face.getSnapshot() };
1466
1687
  const controller = createOptimizerController(ctx, {
1467
1688
  // 与 Host 侧「空字符串视为未设置」的口径一致。
1468
1689
  isModelPinned: () => Boolean(scope.getSnapshot().value?.model?.trim()),
@@ -1471,9 +1692,13 @@ function apply(ctx) {
1471
1692
  // 与 Host 侧「仅 mode==='fast' 为快速」的归一化口径一致。
1472
1693
  isFastMode: () => scope.getSnapshot().value?.mode === "fast",
1473
1694
  // R21:看门狗 = 设置超时秒数 + 5s 余量(正常时 Host 的超时错误先到达,文案更友好)。
1474
- getWatchdogMs: () => ((scope.getSnapshot().value?.timeoutSeconds ?? 120) + 5) * 1e3
1695
+ getWatchdogMs: () => ((scope.getSnapshot().value?.timeoutSeconds ?? 120) + 5) * 1e3,
1696
+ // 「跟随会话」的模型来源(见上);点击时读取,服务缺席走 Host 回退。
1697
+ getSessionModelDirectories: () => modelDirectories,
1698
+ // 「携带上下文」的会话事件窗口来源(见上);点击时读取。
1699
+ getSessions: () => sessions
1475
1700
  });
1476
- ctx.inject(["slots", "connection", "remote", "settingsScope"], (scopeCtx) => {
1701
+ ctx.inject(["slots", "connection", "remote"], (scopeCtx) => {
1477
1702
  scopeCtx.slots.inject(
1478
1703
  "conversation.input.right",
1479
1704
  () => scopeCtx.slots.register(
@@ -1499,13 +1724,28 @@ function apply(ctx) {
1499
1724
  )
1500
1725
  );
1501
1726
  });
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
- );
1727
+ const slotsAny = ctx.slots;
1728
+ const registerSettingsTab = (slotCtx) => {
1729
+ const slots = slotCtx.slots;
1730
+ const card = createSettingsCard(slotCtx, settings.face);
1731
+ return slots.register(
1732
+ {
1733
+ name: "settings.plugins.tab",
1734
+ id: SETTINGS_ENTRY_ID,
1735
+ order: 30,
1736
+ label: () => translate("panel.title"),
1737
+ inject: () => ({})
1738
+ },
1739
+ card
1740
+ );
1741
+ };
1742
+ const registerSettingsItem = (slotCtx) => {
1743
+ const slots = slotCtx.slots;
1744
+ const card = createSettingsCard(slotCtx, settings.face);
1745
+ return slots.register({ name: "settings.plugin.item", key: SETTINGS_ENTRY_ID }, card);
1746
+ };
1747
+ slotsAny.inject("settings.plugins.tab", () => registerSettingsTab(ctx));
1748
+ slotsAny.inject("settings.plugin.item", () => registerSettingsItem(ctx));
1509
1749
  }
1510
1750
  return module.exports;
1511
1751
  }