dsh-thinking-lang 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/DEVELOPMENT.md CHANGED
@@ -12,7 +12,7 @@
12
12
  |---|---|---|
13
13
  | 由谁生成 | [`sectionText`](src/core.ts) | [`reminderText`](src/core.ts) |
14
14
  | 内容 | 完整规则句 | 一句短提醒 |
15
- | 注入形态 | 系统提示词的一段 | 一条 user 消息,追加在请求末尾 |
15
+ | 注入形态 | 系统提示词的一段 | 批次开头的一条插件消息,可在技能目录或批次末尾加一条额外提醒 |
16
16
  | 频率 | 每会话组装一次(文本变化时提交) | 每轮第一步,且距上次 ≥ 提醒间隔(默认 30 分钟) |
17
17
  | 顺序 | `order: 1`,紧跟 persona | `prepend` 注册,晚于其它 pre-step 注入 |
18
18
 
@@ -22,13 +22,13 @@
22
22
 
23
23
  | 语言 | section(规则句) | reminder(批次开头) | tail(请求末尾) |
24
24
  |---|---|---|---|
25
- | 简体中文 | 推理规则:思考、推理与规划一律使用简体中文。回复用户时使用用户所用的语言。 | 注意:思考、推理与规划用简体中文,即使上文不是 | 下文请使用简体中文思考 |
26
- | 繁體中文 | 推理規則:思考、推理與規劃一律使用繁體中文。回覆使用者時使用使用者所用的語言。 | 注意:思考、推理與規劃用繁體中文,即使上文不是 | 下文請使用繁體中文思考 |
27
- | English | Reasoning rules: think, reason, and plan in English. Reply to the user in the language they use. | Note: think, reason, and plan in English, even if the text above is not | Think in English from here on |
25
+ | 简体中文 | 推理规则:思考、推理与规划一律使用简体中文。 | 注意:思考、推理与规划用简体中文,即使上文不是 | 下文请使用简体中文思考 |
26
+ | 繁體中文 | 推理規則:思考、推理與規劃一律使用繁體中文。 | 注意:思考、推理與規劃用繁體中文,即使上文不是 | 下文請使用繁體中文思考 |
27
+ | English | Reasoning rules: think, reason, and plan in English. | Note: think, reason, and plan in English, even if the text above is not | Think in English from here on |
28
28
 
29
29
  改文本改 `CATALOGUE`,再 `npm run build`。
30
30
 
31
- section 的 `order: 1` 紧跟 persona。提醒分两处:一条独立消息插在批次最前,另一条折进 `skill-catalog` 块的 `content` 首部。`agent/pre-step` 监听器在 `agent/created` 时重新 `prepend`,所以它排在监听链最外层,能看到其余注入追加完再动手。
31
+ section 的 `order: 1` 紧跟 persona。前置提醒作为一条插件消息插在批次最前。`agent/pre-step` 监听器在 `agent/created` 时重新 `prepend`,从而在其他监听器追加消息后处理完整批次。
32
32
 
33
33
  ### 提醒间隔
34
34
 
@@ -44,7 +44,7 @@ section 的 `order: 1` 紧跟 persona。提醒分两处:一条独立消息插
44
44
 
45
45
  ### 额外提醒注入
46
46
 
47
- 存储字段是 `extraInjection`(布尔,默认 `true`)。开启时把 `skill-catalog` 块的 `content[0]` 换成「下文请使用简体中文思考」(按所选语言书写),模型因此在那段上下文里先读到规则、再读技能列表。
47
+ 存储字段是 `extraInjection`(布尔,默认 `true`)。如果本批次包含 `skill-catalog`,插件把额外提醒加到目录正文之前。如果目录缺席,插件在批次末尾追加一条独立消息,并在会话日志中标记为插件来源。
48
48
 
49
49
  它跟着提醒间隔联动:`reminderMinutes` 为负数时,整个 `agent/pre-step` 监听器提前返回,两处注入一起停;客户端对应地把这一行置灰。
50
50
 
@@ -56,9 +56,9 @@ section 的 `order: 1` 紧跟 persona。提醒分两处:一条独立消息插
56
56
 
57
57
  | 语言 | section(每会话一次) | 前置提醒(每提醒轮次) | 额外提醒(每提醒轮次) |
58
58
  |---|---|---|---|
59
- | 简体中文 | 21 | 14 | 6 |
60
- | 繁體中文 | 22 | 14 | 6 |
61
- | English | 23 | 18 | 6 |
59
+ | 简体中文 | 13 | 14 | 6 |
60
+ | 繁體中文 | 13 | 14 | 6 |
61
+ | English | 13 | 18 | 6 |
62
62
 
63
63
  前置提醒是一条独立的用户消息,额外提醒只改 `skill-catalog` 的 `content[0]`、不新增消息,所以后者便宜。按默认 30 分钟间隔、100 轮算,一个会话约 50 次提醒、合计约 1000–1300 token。**换语言对每轮开销几乎没有影响**。
64
64
 
@@ -86,7 +86,7 @@ DeepSeek 的上下文缓存自动生效、无需改代码,但它**只认从第
86
86
  - **支持 in-history 的模型**(DeepSeek 官方模型声明 `systemPromptUpdate: 'in-history'`):新 system prompt 作为一条消息追加到历史尾部,旧前缀仍可命中;
87
87
  - **其它模型**:宿主替换开头那条 system message,从那里往后的 Token 全部重算。
88
88
 
89
- reminder 每轮追加在请求末尾,只新增尾部 Token,不会让已有前缀失效。
89
+ 提醒随当前步的新消息批次追加,因此此前请求已有的前缀仍可复用。
90
90
 
91
91
  差价是 **50 倍**(`deepseek-flash` 空闲时段:命中 0.02 元 / 百万 token,未命中 1 元 / 百万 token;高峰时段同样 50 倍。见[模型 & 价格](https://api-docs.deepseek.com/zh-cn/quick_start/pricing/))。切换的代价仍是一次性的,从下一轮起恢复命中。
92
92
 
@@ -160,7 +160,7 @@ dsh plugin --profile desktop add "$PWD"
160
160
 
161
161
  标签先被清洗成 BCP-47(`_`→`-`,去掉 `.UTF-8`、`@latin` 这类 POSIX 修饰),再交给平台自带的 `Intl.Locale` 拆成语言/文字/地区三段,**不手写标签文法**。查找从最具体到最一般:完整标签 → 带文字的 → 带地区的 → 裸主标签,所以 `en-GB` 会落到 `en`。
162
162
 
163
- 中文是唯一的例外——两个条目共用 `zh` 这个主标签,决定简繁的是**文字**而不是地区。这部分交给 CLDR:`maximize()` 会把短标签省略的文字补出来,`Hant` 判为繁體、其余判为简体。于是 `zh-TW`/`zh-HK`/`zh-MO`/`zh-Hant` 都是繁體,`zh`/`zh-SG`/`zh-Hans` 都是简体,两张对照表都不需要。
163
+ 中文优先使用显式文字标签,只有标签省略文字时才调用 `maximize()` 根据 CLDR 数据推断。`Hant` 判为繁体,其余判为简体。`zh-Hant-CN`、`zh-TW`、`zh-HK` 和 `zh-MO` 会得到繁体,`zh-Hans-TW`、`zh` 和 `zh-SG` 会得到简体。
164
164
 
165
165
  ---
166
166
 
@@ -174,4 +174,3 @@ dsh plugin --profile desktop add "$PWD"
174
174
  - **`auto` 依赖运行时能报出系统语言**:Linux/macOS 走环境变量,Windows 走 `Intl`。两者都拿不到时会静默落到界面语言,再不行才是 `zh-CN`。
175
175
  - **插件 id 与设置命名空间**:两者都是 `ay-dsh-tk-lang`,占的是一套自有命名;包名 `dsh-thinking-lang` 与 `dsh-thinking-language` 这类仍然相似,注意区分。功能重复的插件同时装上时,设置页会各插一行、各自注入提示词。
176
176
  - **注入只提高概率,不保证结果**:用户消息首行不是所选语言(英文开场、纯图片或附件)时,实测约 30%(仅前置提醒)/ 70%(含额外注入)按所选语言思考。需要稳定拿到目标语言的思考内容,请改用官方思考过程翻译插件。
177
- - **额外注入依赖 `skill-catalog` 块**:会话里没有技能目录时,规则改插在最后一条注入消息的 `content` 首部,位置与效果都可能不同。
package/README.md CHANGED
@@ -18,7 +18,7 @@
18
18
  |--------|------|------|
19
19
  | **思考语言** | 自动 / 简体中文 / 繁體中文 / English | 内部推理与规划所用的语言 |
20
20
  | **提醒间隔** | 关闭 / 每轮 / 10 / 30 / 60 分钟 / 自定义 1–1440 | 两次「用该语言思考」提醒之间的最小间隔,默认 **30 分钟** |
21
- | **额外提醒注入** | 开启 / 关闭 | 开启时把提醒同时并入技能目录那段上下文;提醒间隔为「关闭」时此项一并停用。默认开启 |
21
+ | **额外提醒注入** | 开启 / 关闭 | 开启时把额外提醒并入本轮技能目录,没有新目录时独立发送。提醒间隔为「关闭」时此项一并停用。默认开启 |
22
22
 
23
23
  「关闭」停止全部注入,只保留系统提示里的规则;「每轮」是每个对话轮次的第一步都提醒一次。
24
24
 
@@ -36,10 +36,10 @@
36
36
 
37
37
  | 做法 | 按所选语言思考的比例 |
38
38
  |---|---|
39
- | 系统提示 + 前置提醒(默认) | 约 **30%** |
39
+ | 系统提示 + 前置提醒 | 约 **30%** |
40
40
  | 再开启「额外提醒注入」 | 约 **70%** |
41
41
 
42
- 额外注入本身多花约 6 token(简体中文),换来请求尾部一次强提醒。
42
+ 额外提醒的简体中文正文约 6 token。独立发送时还会计入消息格式的开销。
43
43
 
44
44
  **如果目标是稳定拿到目标语言的思考内容**,用官方的思考过程翻译插件更合适:它把思考内容翻译后显示,代价是每次都要多付一遍翻译的 token。本插件只在「直接改思考语言、并接受大多数时候是它」这个场景下更省。
45
45
 
package/client/client.js CHANGED
@@ -22,21 +22,21 @@ window.__ModuleLoader__.load({
22
22
  {
23
23
  tag: "zh-CN",
24
24
  nativeName: "简体中文",
25
- section: "推理规则:思考、推理与规划一律使用简体中文。回复用户时使用用户所用的语言。",
25
+ section: "推理规则:思考、推理与规划一律使用简体中文。",
26
26
  reminder: "注意:思考、推理与规划用简体中文,即使上文不是",
27
27
  tail: "下文请使用简体中文思考"
28
28
  },
29
29
  {
30
30
  tag: "zh-TW",
31
31
  nativeName: "繁體中文",
32
- section: "推理規則:思考、推理與規劃一律使用繁體中文。回覆使用者時使用使用者所用的語言。",
32
+ section: "推理規則:思考、推理與規劃一律使用繁體中文。",
33
33
  reminder: "注意:思考、推理與規劃用繁體中文,即使上文不是",
34
34
  tail: "下文請使用繁體中文思考"
35
35
  },
36
36
  {
37
37
  tag: "en",
38
38
  nativeName: "English",
39
- section: "Reasoning rules: think, reason, and plan in English. Reply to the user in the language they use.",
39
+ section: "Reasoning rules: think, reason, and plan in English.",
40
40
  reminder: "Note: think, reason, and plan in English, even if the text above is not",
41
41
  tail: "Think in English from here on"
42
42
  }
@@ -85,9 +85,8 @@ window.__ModuleLoader__.load({
85
85
  function normalizeReminder(raw) {
86
86
  const numeric = typeof raw === "number" ? raw : typeof raw === "string" && raw.trim() !== "" ? Number(raw) : NaN;
87
87
  if (!Number.isFinite(numeric)) return 30;
88
- const rounded = Math.round(numeric);
89
- if (rounded < 0) return -1;
90
- return rounded > 1440 ? MAX_REMINDER_MINUTES : rounded;
88
+ if (numeric < 0) return -1;
89
+ return Math.max(0, Math.min(MAX_REMINDER_MINUTES, Math.round(numeric)));
91
90
  }
92
91
  /** Coerce one untrusted extra-injection value; only an explicit false turns it off. / 把不可信的额外注入值收敛为布尔;只有明确的 false 视为关闭。 */
93
92
  function normalizeExtra(raw) {
@@ -116,9 +115,10 @@ window.__ModuleLoader__.load({
116
115
  reminderUnit: "分钟",
117
116
  reminderCustomHint: "1–1440 分钟",
118
117
  extraHeading: "额外提醒注入",
119
- extraDescription: "开启后把提醒同时并入技能目录;提醒间隔为「关闭」时,此项也一并关闭。",
118
+ extraDescription: "把额外提醒放进本轮技能目录,没有新目录时独立发送。提醒间隔为「关闭」时停用。",
120
119
  extraOn: "开启",
121
- extraOff: "关闭"
120
+ extraOff: "关闭",
121
+ saveError: "设置未能保存,请重试。"
122
122
  },
123
123
  en: {
124
124
  heading: "Thinking language",
@@ -132,9 +132,10 @@ window.__ModuleLoader__.load({
132
132
  reminderUnit: "min",
133
133
  reminderCustomHint: "1–1440 minutes",
134
134
  extraHeading: "Extra reminder injection",
135
- extraDescription: "Also folds the reminder into the skill catalogue. Switching the reminder interval off turns this off too.",
135
+ extraDescription: "Adds a reminder to the skill catalogue, or sends it separately if no catalogue is sent. Turning reminders off also turns this off.",
136
136
  extraOn: "On",
137
- extraOff: "Off"
137
+ extraOff: "Off",
138
+ saveError: "Could not save this setting. Try again."
138
139
  }
139
140
  };
140
141
  //#endregion
@@ -168,14 +169,37 @@ window.__ModuleLoader__.load({
168
169
  }
169
170
  }
170
171
  /**
171
- * Write one field back, swallowing a refusal so a read-only host cannot break the UI.
172
- * 回写单个字段,并吞掉拒绝异常,使只读宿主不会让控件崩溃。
172
+ * Show the result of the latest write for a field.
173
+ * 显示该字段最近一次写入的结果。
173
174
  */
174
- function writeField(doc, field, value) {
175
- try {
176
- const outcome = doc.set(field, value);
177
- if (typeof outcome?.then === "function") outcome.then(void 0, () => {});
178
- } catch {}
175
+ function useSettingWriter(doc, field) {
176
+ const [failed, setFailed] = (0, react.useState)(false);
177
+ const generation = (0, react.useRef)(0);
178
+ (0, react.useEffect)(() => {
179
+ setFailed(false);
180
+ return () => {
181
+ generation.current += 1;
182
+ };
183
+ }, [doc]);
184
+ async function save(value) {
185
+ const attempted = ++generation.current;
186
+ setFailed(false);
187
+ let accepted = false;
188
+ try {
189
+ accepted = await doc.set(field, value);
190
+ } catch {}
191
+ if (attempted === generation.current) setFailed(!accepted);
192
+ }
193
+ return {
194
+ failed,
195
+ save
196
+ };
197
+ }
198
+ function pickerWithError(control, failed, t) {
199
+ return (0, react.createElement)("div", { className: "dsh_desk_lang_field" }, control, failed ? (0, react.createElement)("div", {
200
+ className: "dsh_desk_lang_desc",
201
+ role: "alert"
202
+ }, t("saveError")) : null);
179
203
  }
180
204
  /** Subscribe one component to the document and re-read it on every revision. / 订阅设置文档,并在每次修订时重新读取。 */
181
205
  function useSettings(doc) {
@@ -197,6 +221,7 @@ window.__ModuleLoader__.load({
197
221
  return function LanguagePicker(props) {
198
222
  const { doc, t, settings } = props;
199
223
  const [open, setOpen] = (0, react.useState)(false);
224
+ const { failed, save } = useSettingWriter(doc, FIELD_LANGUAGE);
200
225
  const items = [{
201
226
  id: AUTO,
202
227
  label: t("autoLabel")
@@ -207,7 +232,7 @@ window.__ModuleLoader__.load({
207
232
  const activeLabel = settings.language === "auto" ? t("autoLabel") : nativeNameFor(settings.language) ?? settings.language;
208
233
  const close = () => setOpen(false);
209
234
  const choose = (id) => {
210
- writeField(doc, FIELD_LANGUAGE, id);
235
+ save(id);
211
236
  close();
212
237
  };
213
238
  const picker = (0, react.createElement)("button", {
@@ -217,8 +242,7 @@ window.__ModuleLoader__.load({
217
242
  "aria-expanded": open,
218
243
  onClick: () => setOpen((value) => !value)
219
244
  }, activeLabel, Chevron === void 0 ? null : (0, react.createElement)(Chevron, { className: "dsh_desk_lang_chevron" }));
220
- if (!Menu) return picker;
221
- return (0, react.createElement)(Menu, {
245
+ return pickerWithError(Menu ? (0, react.createElement)(Menu, {
222
246
  open,
223
247
  anchor: picker,
224
248
  items,
@@ -227,7 +251,7 @@ window.__ModuleLoader__.load({
227
251
  portal: true,
228
252
  onClose: close,
229
253
  onSelect: choose
230
- });
254
+ }) : picker, failed, t);
231
255
  };
232
256
  }
233
257
  /** Map a stored minute count onto the picker id it should show. / 把存储的分钟数映射成选择器应显示的选项 id。 */
@@ -251,17 +275,21 @@ window.__ModuleLoader__.load({
251
275
  const Chevron = primitives?.IconChevronDownOutlineRegular ?? primitives?.IconChevronDownOutline14 ?? primitives?.IconChevronDownOutlineMedium;
252
276
  return function ReminderPicker(props) {
253
277
  const { doc, t, settings } = props;
254
- const derived = derivedPreset(settings.reminderMinutes);
255
- const current = settings.reminderMinutes > 0 ? settings.reminderMinutes : 30;
256
- const [selected, setSelected] = (0, react.useState)(derived);
278
+ const minutes = settings.reminderMinutes;
279
+ const selected = derivedPreset(minutes);
280
+ const current = minutes > 0 ? minutes : DEFAULTS.reminderMinutes;
281
+ const [editingCustom, setEditingCustom] = (0, react.useState)(false);
257
282
  const [open, setOpen] = (0, react.useState)(false);
258
283
  const [draft, setDraft] = (0, react.useState)(String(current));
259
- (0, react.useEffect)(() => {
260
- setSelected(derived);
261
- }, [derived]);
284
+ const { failed, save } = useSettingWriter(doc, FIELD_REMINDER);
262
285
  (0, react.useEffect)(() => {
263
286
  setDraft(String(current));
264
- }, [current]);
287
+ setEditingCustom(false);
288
+ }, [
289
+ current,
290
+ doc,
291
+ minutes
292
+ ]);
265
293
  const labelOf = (id) => {
266
294
  if (id === "off") return t("reminderOff");
267
295
  if (id === "turn") return t("reminderTurn");
@@ -279,20 +307,22 @@ window.__ModuleLoader__.load({
279
307
  }));
280
308
  const choose = (id) => {
281
309
  setOpen(false);
282
- setSelected(id);
283
- if (id === "off") writeField(doc, FIELD_REMINDER, -1);
284
- else if (id === "turn") writeField(doc, FIELD_REMINDER, 0);
285
- else if (id !== "custom") writeField(doc, FIELD_REMINDER, Number(id));
310
+ setDraft(String(current));
311
+ setEditingCustom(id === "custom");
312
+ if (id === "custom") return;
313
+ const value = id === "off" ? -1 : id === "turn" ? 0 : Number(id);
314
+ save(value);
286
315
  };
287
316
  const commit = () => {
288
- const minutes = Math.round(Number(draft));
289
- if (!Number.isFinite(minutes) || draft.trim() === "") {
317
+ const parsed = Math.round(Number(draft));
318
+ if (!Number.isFinite(parsed) || draft.trim() === "") {
290
319
  setDraft(String(current));
291
320
  return;
292
321
  }
293
- const clamped = Math.min(MAX_REMINDER_MINUTES, Math.max(1, minutes));
294
- writeField(doc, FIELD_REMINDER, clamped);
322
+ const clamped = Math.min(MAX_REMINDER_MINUTES, Math.max(1, parsed));
295
323
  setDraft(String(clamped));
324
+ if (clamped === minutes) setEditingCustom(false);
325
+ save(clamped);
296
326
  };
297
327
  const picker = (0, react.createElement)("button", {
298
328
  type: "button",
@@ -311,20 +341,24 @@ window.__ModuleLoader__.load({
311
341
  onClose: () => setOpen(false),
312
342
  onSelect: choose
313
343
  }) : picker;
314
- if (selected !== "custom") return control;
315
- return (0, react.createElement)("div", { className: "dsh_desk_lang_control" }, control, (0, react.createElement)("input", {
344
+ if (!editingCustom && selected !== "custom") return pickerWithError(control, failed, t);
345
+ return pickerWithError((0, react.createElement)("div", { className: "dsh_desk_lang_control" }, control, (0, react.createElement)("input", {
316
346
  type: "number",
317
347
  className: "dsh_desk_lang_input",
318
348
  min: 1,
319
349
  max: MAX_REMINDER_MINUTES,
320
- placeholder: String(settings.reminderMinutes > 0 ? settings.reminderMinutes : 30),
350
+ "aria-label": t("reminderHeading"),
351
+ placeholder: String(current),
321
352
  value: draft,
322
353
  onChange: (event) => setDraft(event.currentTarget.value),
323
354
  onBlur: commit,
324
355
  onKeyDown: (event) => {
325
- if (event.key === "Enter") commit();
356
+ if (event.key === "Enter") {
357
+ event.preventDefault();
358
+ event.currentTarget.blur();
359
+ }
326
360
  }
327
- }), (0, react.createElement)("span", { className: "dsh_desk_lang_hint" }, t("reminderCustomHint")));
361
+ }), (0, react.createElement)("span", { className: "dsh_desk_lang_hint" }, t("reminderCustomHint"))), failed, t);
328
362
  };
329
363
  }
330
364
  /**
@@ -340,6 +374,7 @@ window.__ModuleLoader__.load({
340
374
  return function ExtraPicker(props) {
341
375
  const { doc, t, settings, disabled = false } = props;
342
376
  const [open, setOpen] = (0, react.useState)(false);
377
+ const { failed, save } = useSettingWriter(doc, FIELD_EXTRA);
343
378
  const items = [{
344
379
  id: "on",
345
380
  label: t("extraOn")
@@ -349,7 +384,7 @@ window.__ModuleLoader__.load({
349
384
  }];
350
385
  const close = () => setOpen(false);
351
386
  const choose = (id) => {
352
- writeField(doc, FIELD_EXTRA, id === "on");
387
+ if (!disabled) save(id === "on");
353
388
  close();
354
389
  };
355
390
  const picker = (0, react.createElement)("button", {
@@ -360,9 +395,8 @@ window.__ModuleLoader__.load({
360
395
  disabled,
361
396
  onClick: () => setOpen((value) => !value)
362
397
  }, settings.extraInjection ? t("extraOn") : t("extraOff"), Chevron === void 0 ? null : (0, react.createElement)(Chevron, { className: "dsh_desk_lang_chevron" }));
363
- if (!Menu) return picker;
364
- return (0, react.createElement)(Menu, {
365
- open,
398
+ return pickerWithError(Menu ? (0, react.createElement)(Menu, {
399
+ open: open && !disabled,
366
400
  anchor: picker,
367
401
  items,
368
402
  selectedId: settings.extraInjection ? "on" : "off",
@@ -370,7 +404,7 @@ window.__ModuleLoader__.load({
370
404
  portal: true,
371
405
  onClose: close,
372
406
  onSelect: choose
373
- });
407
+ }) : picker, failed, t);
374
408
  };
375
409
  }
376
410
  /**
@@ -425,6 +459,7 @@ window.__ModuleLoader__.load({
425
459
  ".dsh_desk_lang_picker{border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-module-platform);height:36px;font:inherit;color:var(--dsw-alias-label-primary);cursor:pointer;border:none;align-items:center;gap:12px;padding:0 14px;font-size:14px;line-height:22px;display:inline-flex;flex:none}",
426
460
  ".dsh_desk_lang_picker:hover{background:var(--dsw-alias-interactive-bg-hover)}",
427
461
  ".dsh_desk_lang_chevron{flex:none}",
462
+ ".dsh_desk_lang_field{display:flex;flex-direction:column;align-items:flex-end;gap:4px}",
428
463
  ".dsh_desk_lang_control{align-items:center;gap:8px;display:flex;flex:none}",
429
464
  ".dsh_desk_lang_input{border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-module-platform);height:36px;width:88px;font:inherit;color:var(--dsw-alias-label-primary);border:none;padding:0 12px;font-size:14px}",
430
465
  ".dsh_desk_lang_hint{color:var(--dsw-alias-label-tertiary);font-size:12px;white-space:nowrap}"
@@ -17,21 +17,21 @@ const CATALOGUE = [
17
17
  {
18
18
  tag: "zh-CN",
19
19
  nativeName: "简体中文",
20
- section: "推理规则:思考、推理与规划一律使用简体中文。回复用户时使用用户所用的语言。",
20
+ section: "推理规则:思考、推理与规划一律使用简体中文。",
21
21
  reminder: "注意:思考、推理与规划用简体中文,即使上文不是",
22
22
  tail: "下文请使用简体中文思考"
23
23
  },
24
24
  {
25
25
  tag: "zh-TW",
26
26
  nativeName: "繁體中文",
27
- section: "推理規則:思考、推理與規劃一律使用繁體中文。回覆使用者時使用使用者所用的語言。",
27
+ section: "推理規則:思考、推理與規劃一律使用繁體中文。",
28
28
  reminder: "注意:思考、推理與規劃用繁體中文,即使上文不是",
29
29
  tail: "下文請使用繁體中文思考"
30
30
  },
31
31
  {
32
32
  tag: "en",
33
33
  nativeName: "English",
34
- section: "Reasoning rules: think, reason, and plan in English. Reply to the user in the language they use.",
34
+ section: "Reasoning rules: think, reason, and plan in English.",
35
35
  reminder: "Note: think, reason, and plan in English, even if the text above is not",
36
36
  tail: "Think in English from here on"
37
37
  }
@@ -80,9 +80,8 @@ function nativeNameFor(tag) {
80
80
  function normalizeReminder(raw) {
81
81
  const numeric = typeof raw === "number" ? raw : typeof raw === "string" && raw.trim() !== "" ? Number(raw) : NaN;
82
82
  if (!Number.isFinite(numeric)) return 30;
83
- const rounded = Math.round(numeric);
84
- if (rounded < 0) return -1;
85
- return rounded > 1440 ? MAX_REMINDER_MINUTES : rounded;
83
+ if (numeric < 0) return -1;
84
+ return Math.max(0, Math.min(MAX_REMINDER_MINUTES, Math.round(numeric)));
86
85
  }
87
86
  /** Coerce one untrusted extra-injection value; only an explicit false turns it off. / 把不可信的额外注入值收敛为布尔;只有明确的 false 视为关闭。 */
88
87
  function normalizeExtra(raw) {
@@ -111,9 +110,10 @@ const dictionaries = {
111
110
  reminderUnit: "分钟",
112
111
  reminderCustomHint: "1–1440 分钟",
113
112
  extraHeading: "额外提醒注入",
114
- extraDescription: "开启后把提醒同时并入技能目录;提醒间隔为「关闭」时,此项也一并关闭。",
113
+ extraDescription: "把额外提醒放进本轮技能目录,没有新目录时独立发送。提醒间隔为「关闭」时停用。",
115
114
  extraOn: "开启",
116
- extraOff: "关闭"
115
+ extraOff: "关闭",
116
+ saveError: "设置未能保存,请重试。"
117
117
  },
118
118
  en: {
119
119
  heading: "Thinking language",
@@ -127,9 +127,10 @@ const dictionaries = {
127
127
  reminderUnit: "min",
128
128
  reminderCustomHint: "1–1440 minutes",
129
129
  extraHeading: "Extra reminder injection",
130
- extraDescription: "Also folds the reminder into the skill catalogue. Switching the reminder interval off turns this off too.",
130
+ extraDescription: "Adds a reminder to the skill catalogue, or sends it separately if no catalogue is sent. Turning reminders off also turns this off.",
131
131
  extraOn: "On",
132
- extraOff: "Off"
132
+ extraOff: "Off",
133
+ saveError: "Could not save this setting. Try again."
133
134
  }
134
135
  };
135
136
  //#endregion
@@ -163,14 +164,37 @@ function readSettings(doc) {
163
164
  }
164
165
  }
165
166
  /**
166
- * Write one field back, swallowing a refusal so a read-only host cannot break the UI.
167
- * 回写单个字段,并吞掉拒绝异常,使只读宿主不会让控件崩溃。
167
+ * Show the result of the latest write for a field.
168
+ * 显示该字段最近一次写入的结果。
168
169
  */
169
- function writeField(doc, field, value) {
170
- try {
171
- const outcome = doc.set(field, value);
172
- if (typeof outcome?.then === "function") outcome.then(void 0, () => {});
173
- } catch {}
170
+ function useSettingWriter(doc, field) {
171
+ const [failed, setFailed] = (0, react.useState)(false);
172
+ const generation = (0, react.useRef)(0);
173
+ (0, react.useEffect)(() => {
174
+ setFailed(false);
175
+ return () => {
176
+ generation.current += 1;
177
+ };
178
+ }, [doc]);
179
+ async function save(value) {
180
+ const attempted = ++generation.current;
181
+ setFailed(false);
182
+ let accepted = false;
183
+ try {
184
+ accepted = await doc.set(field, value);
185
+ } catch {}
186
+ if (attempted === generation.current) setFailed(!accepted);
187
+ }
188
+ return {
189
+ failed,
190
+ save
191
+ };
192
+ }
193
+ function pickerWithError(control, failed, t) {
194
+ return (0, react.createElement)("div", { className: "dsh_desk_lang_field" }, control, failed ? (0, react.createElement)("div", {
195
+ className: "dsh_desk_lang_desc",
196
+ role: "alert"
197
+ }, t("saveError")) : null);
174
198
  }
175
199
  /** Subscribe one component to the document and re-read it on every revision. / 订阅设置文档,并在每次修订时重新读取。 */
176
200
  function useSettings(doc) {
@@ -192,6 +216,7 @@ function createLanguagePicker(primitives) {
192
216
  return function LanguagePicker(props) {
193
217
  const { doc, t, settings } = props;
194
218
  const [open, setOpen] = (0, react.useState)(false);
219
+ const { failed, save } = useSettingWriter(doc, FIELD_LANGUAGE);
195
220
  const items = [{
196
221
  id: AUTO,
197
222
  label: t("autoLabel")
@@ -202,7 +227,7 @@ function createLanguagePicker(primitives) {
202
227
  const activeLabel = settings.language === "auto" ? t("autoLabel") : nativeNameFor(settings.language) ?? settings.language;
203
228
  const close = () => setOpen(false);
204
229
  const choose = (id) => {
205
- writeField(doc, FIELD_LANGUAGE, id);
230
+ save(id);
206
231
  close();
207
232
  };
208
233
  const picker = (0, react.createElement)("button", {
@@ -212,8 +237,7 @@ function createLanguagePicker(primitives) {
212
237
  "aria-expanded": open,
213
238
  onClick: () => setOpen((value) => !value)
214
239
  }, activeLabel, Chevron === void 0 ? null : (0, react.createElement)(Chevron, { className: "dsh_desk_lang_chevron" }));
215
- if (!Menu) return picker;
216
- return (0, react.createElement)(Menu, {
240
+ return pickerWithError(Menu ? (0, react.createElement)(Menu, {
217
241
  open,
218
242
  anchor: picker,
219
243
  items,
@@ -222,7 +246,7 @@ function createLanguagePicker(primitives) {
222
246
  portal: true,
223
247
  onClose: close,
224
248
  onSelect: choose
225
- });
249
+ }) : picker, failed, t);
226
250
  };
227
251
  }
228
252
  /** Map a stored minute count onto the picker id it should show. / 把存储的分钟数映射成选择器应显示的选项 id。 */
@@ -246,17 +270,21 @@ function createReminderPicker(primitives) {
246
270
  const Chevron = primitives?.IconChevronDownOutlineRegular ?? primitives?.IconChevronDownOutline14 ?? primitives?.IconChevronDownOutlineMedium;
247
271
  return function ReminderPicker(props) {
248
272
  const { doc, t, settings } = props;
249
- const derived = derivedPreset(settings.reminderMinutes);
250
- const current = settings.reminderMinutes > 0 ? settings.reminderMinutes : 30;
251
- const [selected, setSelected] = (0, react.useState)(derived);
273
+ const minutes = settings.reminderMinutes;
274
+ const selected = derivedPreset(minutes);
275
+ const current = minutes > 0 ? minutes : DEFAULTS.reminderMinutes;
276
+ const [editingCustom, setEditingCustom] = (0, react.useState)(false);
252
277
  const [open, setOpen] = (0, react.useState)(false);
253
278
  const [draft, setDraft] = (0, react.useState)(String(current));
254
- (0, react.useEffect)(() => {
255
- setSelected(derived);
256
- }, [derived]);
279
+ const { failed, save } = useSettingWriter(doc, FIELD_REMINDER);
257
280
  (0, react.useEffect)(() => {
258
281
  setDraft(String(current));
259
- }, [current]);
282
+ setEditingCustom(false);
283
+ }, [
284
+ current,
285
+ doc,
286
+ minutes
287
+ ]);
260
288
  const labelOf = (id) => {
261
289
  if (id === "off") return t("reminderOff");
262
290
  if (id === "turn") return t("reminderTurn");
@@ -274,20 +302,22 @@ function createReminderPicker(primitives) {
274
302
  }));
275
303
  const choose = (id) => {
276
304
  setOpen(false);
277
- setSelected(id);
278
- if (id === "off") writeField(doc, FIELD_REMINDER, -1);
279
- else if (id === "turn") writeField(doc, FIELD_REMINDER, 0);
280
- else if (id !== "custom") writeField(doc, FIELD_REMINDER, Number(id));
305
+ setDraft(String(current));
306
+ setEditingCustom(id === "custom");
307
+ if (id === "custom") return;
308
+ const value = id === "off" ? -1 : id === "turn" ? 0 : Number(id);
309
+ save(value);
281
310
  };
282
311
  const commit = () => {
283
- const minutes = Math.round(Number(draft));
284
- if (!Number.isFinite(minutes) || draft.trim() === "") {
312
+ const parsed = Math.round(Number(draft));
313
+ if (!Number.isFinite(parsed) || draft.trim() === "") {
285
314
  setDraft(String(current));
286
315
  return;
287
316
  }
288
- const clamped = Math.min(MAX_REMINDER_MINUTES, Math.max(1, minutes));
289
- writeField(doc, FIELD_REMINDER, clamped);
317
+ const clamped = Math.min(MAX_REMINDER_MINUTES, Math.max(1, parsed));
290
318
  setDraft(String(clamped));
319
+ if (clamped === minutes) setEditingCustom(false);
320
+ save(clamped);
291
321
  };
292
322
  const picker = (0, react.createElement)("button", {
293
323
  type: "button",
@@ -306,20 +336,24 @@ function createReminderPicker(primitives) {
306
336
  onClose: () => setOpen(false),
307
337
  onSelect: choose
308
338
  }) : picker;
309
- if (selected !== "custom") return control;
310
- return (0, react.createElement)("div", { className: "dsh_desk_lang_control" }, control, (0, react.createElement)("input", {
339
+ if (!editingCustom && selected !== "custom") return pickerWithError(control, failed, t);
340
+ return pickerWithError((0, react.createElement)("div", { className: "dsh_desk_lang_control" }, control, (0, react.createElement)("input", {
311
341
  type: "number",
312
342
  className: "dsh_desk_lang_input",
313
343
  min: 1,
314
344
  max: MAX_REMINDER_MINUTES,
315
- placeholder: String(settings.reminderMinutes > 0 ? settings.reminderMinutes : 30),
345
+ "aria-label": t("reminderHeading"),
346
+ placeholder: String(current),
316
347
  value: draft,
317
348
  onChange: (event) => setDraft(event.currentTarget.value),
318
349
  onBlur: commit,
319
350
  onKeyDown: (event) => {
320
- if (event.key === "Enter") commit();
351
+ if (event.key === "Enter") {
352
+ event.preventDefault();
353
+ event.currentTarget.blur();
354
+ }
321
355
  }
322
- }), (0, react.createElement)("span", { className: "dsh_desk_lang_hint" }, t("reminderCustomHint")));
356
+ }), (0, react.createElement)("span", { className: "dsh_desk_lang_hint" }, t("reminderCustomHint"))), failed, t);
323
357
  };
324
358
  }
325
359
  /**
@@ -335,6 +369,7 @@ function createExtraPicker(primitives) {
335
369
  return function ExtraPicker(props) {
336
370
  const { doc, t, settings, disabled = false } = props;
337
371
  const [open, setOpen] = (0, react.useState)(false);
372
+ const { failed, save } = useSettingWriter(doc, FIELD_EXTRA);
338
373
  const items = [{
339
374
  id: "on",
340
375
  label: t("extraOn")
@@ -344,7 +379,7 @@ function createExtraPicker(primitives) {
344
379
  }];
345
380
  const close = () => setOpen(false);
346
381
  const choose = (id) => {
347
- writeField(doc, FIELD_EXTRA, id === "on");
382
+ if (!disabled) save(id === "on");
348
383
  close();
349
384
  };
350
385
  const picker = (0, react.createElement)("button", {
@@ -355,9 +390,8 @@ function createExtraPicker(primitives) {
355
390
  disabled,
356
391
  onClick: () => setOpen((value) => !value)
357
392
  }, settings.extraInjection ? t("extraOn") : t("extraOff"), Chevron === void 0 ? null : (0, react.createElement)(Chevron, { className: "dsh_desk_lang_chevron" }));
358
- if (!Menu) return picker;
359
- return (0, react.createElement)(Menu, {
360
- open,
393
+ return pickerWithError(Menu ? (0, react.createElement)(Menu, {
394
+ open: open && !disabled,
361
395
  anchor: picker,
362
396
  items,
363
397
  selectedId: settings.extraInjection ? "on" : "off",
@@ -365,7 +399,7 @@ function createExtraPicker(primitives) {
365
399
  portal: true,
366
400
  onClose: close,
367
401
  onSelect: choose
368
- });
402
+ }) : picker, failed, t);
369
403
  };
370
404
  }
371
405
  /**
@@ -420,6 +454,7 @@ const rowCss = [
420
454
  ".dsh_desk_lang_picker{border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-module-platform);height:36px;font:inherit;color:var(--dsw-alias-label-primary);cursor:pointer;border:none;align-items:center;gap:12px;padding:0 14px;font-size:14px;line-height:22px;display:inline-flex;flex:none}",
421
455
  ".dsh_desk_lang_picker:hover{background:var(--dsw-alias-interactive-bg-hover)}",
422
456
  ".dsh_desk_lang_chevron{flex:none}",
457
+ ".dsh_desk_lang_field{display:flex;flex-direction:column;align-items:flex-end;gap:4px}",
423
458
  ".dsh_desk_lang_control{align-items:center;gap:8px;display:flex;flex:none}",
424
459
  ".dsh_desk_lang_input{border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-module-platform);height:36px;width:88px;font:inherit;color:var(--dsw-alias-label-primary);border:none;padding:0 12px;font-size:14px}",
425
460
  ".dsh_desk_lang_hint{color:var(--dsw-alias-label-tertiary);font-size:12px;white-space:nowrap}"