dsh-thinking-lang 1.0.7 → 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.
@@ -17,20 +17,23 @@ const CATALOGUE = [
17
17
  {
18
18
  tag: "zh-CN",
19
19
  nativeName: "简体中文",
20
- section: "推理规则:思考、推理与规划一律使用简体中文。回复用户时使用用户所用的语言。",
21
- reminder: "继续用简体中文思考、推理与规划。"
20
+ section: "推理规则:思考、推理与规划一律使用简体中文。",
21
+ reminder: "注意:思考、推理与规划用简体中文,即使上文不是",
22
+ tail: "下文请使用简体中文思考"
22
23
  },
23
24
  {
24
25
  tag: "zh-TW",
25
26
  nativeName: "繁體中文",
26
- section: "推理規則:思考、推理與規劃一律使用繁體中文。回覆使用者時使用使用者所用的語言。",
27
- reminder: "繼續用繁體中文思考、推理與規劃。"
27
+ section: "推理規則:思考、推理與規劃一律使用繁體中文。",
28
+ reminder: "注意:思考、推理與規劃用繁體中文,即使上文不是",
29
+ tail: "下文請使用繁體中文思考"
28
30
  },
29
31
  {
30
32
  tag: "en",
31
33
  nativeName: "English",
32
- section: "Reasoning rules: think, reason, and plan in English. Reply to the user in the language they use.",
33
- reminder: "Keep thinking, reasoning, and planning in English."
34
+ section: "Reasoning rules: think, reason, and plan in English.",
35
+ reminder: "Note: think, reason, and plan in English, even if the text above is not",
36
+ tail: "Think in English from here on"
34
37
  }
35
38
  ];
36
39
  /** The sentinel meaning "follow the host locale". / 表示「跟随宿主语言」的哨兵值。 */
@@ -41,13 +44,16 @@ const SETTINGS_NAMESPACE = "ay-dsh-tk-lang";
41
44
  const FIELD_LANGUAGE = "language";
42
45
  /** The reminder field this plugin stores. / 本插件保存的提醒字段。 */
43
46
  const FIELD_REMINDER = "reminderMinutes";
47
+ /** The extra-injection field this plugin stores. / 本插件保存的额外注入字段。 */
48
+ const FIELD_EXTRA = "extraInjection";
44
49
  /** Largest accepted reminder interval. / 允许的最大提醒间隔(分钟)。 */
45
50
  const MAX_REMINDER_MINUTES = 1440;
46
51
  CATALOGUE.map((language) => language.tag);
47
52
  /** Configuration applied when the fields are absent. / 字段缺失时采用的配置。 */
48
53
  const DEFAULTS = {
49
54
  language: AUTO,
50
- reminderMinutes: 30
55
+ reminderMinutes: 30,
56
+ extraInjection: true
51
57
  };
52
58
  /** Catalogue lookup keyed by lower-cased tag. / 以小写标签为键的目录索引。 */
53
59
  const BY_TAG = new Map(CATALOGUE.map((language) => [language.tag.toLowerCase(), language]));
@@ -74,16 +80,20 @@ function nativeNameFor(tag) {
74
80
  function normalizeReminder(raw) {
75
81
  const numeric = typeof raw === "number" ? raw : typeof raw === "string" && raw.trim() !== "" ? Number(raw) : NaN;
76
82
  if (!Number.isFinite(numeric)) return 30;
77
- const rounded = Math.round(numeric);
78
- if (rounded < 0) return -1;
79
- 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)));
85
+ }
86
+ /** Coerce one untrusted extra-injection value; only an explicit false turns it off. / 把不可信的额外注入值收敛为布尔;只有明确的 false 视为关闭。 */
87
+ function normalizeExtra(raw) {
88
+ return raw !== false && raw !== "false";
80
89
  }
81
90
  function normalizeSettings(raw) {
82
91
  const section = raw !== null && typeof raw === "object" && !Array.isArray(raw) ? raw : void 0;
83
92
  const stored = section?.[FIELD_LANGUAGE];
84
93
  return {
85
94
  language: typeof stored === "string" && stored !== "" ? stored : DEFAULTS.language,
86
- reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER])
95
+ reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER]),
96
+ extraInjection: normalizeExtra(section?.[FIELD_EXTRA])
87
97
  };
88
98
  }
89
99
  /** Dictionaries keyed by UI locale, handed to the host locale service. / 以界面语言为键、交给宿主 locale 服务的字典。 */
@@ -98,7 +108,12 @@ const dictionaries = {
98
108
  reminderTurn: "每轮",
99
109
  reminderCustom: "自定义",
100
110
  reminderUnit: "分钟",
101
- reminderCustomHint: "1–1440 分钟"
111
+ reminderCustomHint: "1–1440 分钟",
112
+ extraHeading: "额外提醒注入",
113
+ extraDescription: "把额外提醒放进本轮技能目录,没有新目录时独立发送。提醒间隔为「关闭」时停用。",
114
+ extraOn: "开启",
115
+ extraOff: "关闭",
116
+ saveError: "设置未能保存,请重试。"
102
117
  },
103
118
  en: {
104
119
  heading: "Thinking language",
@@ -110,7 +125,12 @@ const dictionaries = {
110
125
  reminderTurn: "Every turn",
111
126
  reminderCustom: "Custom",
112
127
  reminderUnit: "min",
113
- reminderCustomHint: "1–1440 minutes"
128
+ reminderCustomHint: "1–1440 minutes",
129
+ extraHeading: "Extra reminder injection",
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
+ extraOn: "On",
132
+ extraOff: "Off",
133
+ saveError: "Could not save this setting. Try again."
114
134
  }
115
135
  };
116
136
  //#endregion
@@ -144,14 +164,37 @@ function readSettings(doc) {
144
164
  }
145
165
  }
146
166
  /**
147
- * Write one field back, swallowing a refusal so a read-only host cannot break the UI.
148
- * 回写单个字段,并吞掉拒绝异常,使只读宿主不会让控件崩溃。
167
+ * Show the result of the latest write for a field.
168
+ * 显示该字段最近一次写入的结果。
149
169
  */
150
- function writeField(doc, field, value) {
151
- try {
152
- const outcome = doc.set(field, value);
153
- if (typeof outcome?.then === "function") outcome.then(void 0, () => {});
154
- } 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);
155
198
  }
156
199
  /** Subscribe one component to the document and re-read it on every revision. / 订阅设置文档,并在每次修订时重新读取。 */
157
200
  function useSettings(doc) {
@@ -173,6 +216,7 @@ function createLanguagePicker(primitives) {
173
216
  return function LanguagePicker(props) {
174
217
  const { doc, t, settings } = props;
175
218
  const [open, setOpen] = (0, react.useState)(false);
219
+ const { failed, save } = useSettingWriter(doc, FIELD_LANGUAGE);
176
220
  const items = [{
177
221
  id: AUTO,
178
222
  label: t("autoLabel")
@@ -183,7 +227,7 @@ function createLanguagePicker(primitives) {
183
227
  const activeLabel = settings.language === "auto" ? t("autoLabel") : nativeNameFor(settings.language) ?? settings.language;
184
228
  const close = () => setOpen(false);
185
229
  const choose = (id) => {
186
- writeField(doc, FIELD_LANGUAGE, id);
230
+ save(id);
187
231
  close();
188
232
  };
189
233
  const picker = (0, react.createElement)("button", {
@@ -193,8 +237,7 @@ function createLanguagePicker(primitives) {
193
237
  "aria-expanded": open,
194
238
  onClick: () => setOpen((value) => !value)
195
239
  }, activeLabel, Chevron === void 0 ? null : (0, react.createElement)(Chevron, { className: "dsh_desk_lang_chevron" }));
196
- if (!Menu) return picker;
197
- return (0, react.createElement)(Menu, {
240
+ return pickerWithError(Menu ? (0, react.createElement)(Menu, {
198
241
  open,
199
242
  anchor: picker,
200
243
  items,
@@ -203,7 +246,7 @@ function createLanguagePicker(primitives) {
203
246
  portal: true,
204
247
  onClose: close,
205
248
  onSelect: choose
206
- });
249
+ }) : picker, failed, t);
207
250
  };
208
251
  }
209
252
  /** Map a stored minute count onto the picker id it should show. / 把存储的分钟数映射成选择器应显示的选项 id。 */
@@ -227,17 +270,21 @@ function createReminderPicker(primitives) {
227
270
  const Chevron = primitives?.IconChevronDownOutlineRegular ?? primitives?.IconChevronDownOutline14 ?? primitives?.IconChevronDownOutlineMedium;
228
271
  return function ReminderPicker(props) {
229
272
  const { doc, t, settings } = props;
230
- const derived = derivedPreset(settings.reminderMinutes);
231
- const current = settings.reminderMinutes > 0 ? settings.reminderMinutes : 30;
232
- 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);
233
277
  const [open, setOpen] = (0, react.useState)(false);
234
278
  const [draft, setDraft] = (0, react.useState)(String(current));
235
- (0, react.useEffect)(() => {
236
- setSelected(derived);
237
- }, [derived]);
279
+ const { failed, save } = useSettingWriter(doc, FIELD_REMINDER);
238
280
  (0, react.useEffect)(() => {
239
281
  setDraft(String(current));
240
- }, [current]);
282
+ setEditingCustom(false);
283
+ }, [
284
+ current,
285
+ doc,
286
+ minutes
287
+ ]);
241
288
  const labelOf = (id) => {
242
289
  if (id === "off") return t("reminderOff");
243
290
  if (id === "turn") return t("reminderTurn");
@@ -255,20 +302,22 @@ function createReminderPicker(primitives) {
255
302
  }));
256
303
  const choose = (id) => {
257
304
  setOpen(false);
258
- setSelected(id);
259
- if (id === "off") writeField(doc, FIELD_REMINDER, -1);
260
- else if (id === "turn") writeField(doc, FIELD_REMINDER, 0);
261
- 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);
262
310
  };
263
311
  const commit = () => {
264
- const minutes = Math.round(Number(draft));
265
- if (!Number.isFinite(minutes) || draft.trim() === "") {
312
+ const parsed = Math.round(Number(draft));
313
+ if (!Number.isFinite(parsed) || draft.trim() === "") {
266
314
  setDraft(String(current));
267
315
  return;
268
316
  }
269
- const clamped = Math.min(MAX_REMINDER_MINUTES, Math.max(1, minutes));
270
- writeField(doc, FIELD_REMINDER, clamped);
317
+ const clamped = Math.min(MAX_REMINDER_MINUTES, Math.max(1, parsed));
271
318
  setDraft(String(clamped));
319
+ if (clamped === minutes) setEditingCustom(false);
320
+ save(clamped);
272
321
  };
273
322
  const picker = (0, react.createElement)("button", {
274
323
  type: "button",
@@ -287,20 +336,70 @@ function createReminderPicker(primitives) {
287
336
  onClose: () => setOpen(false),
288
337
  onSelect: choose
289
338
  }) : picker;
290
- if (selected !== "custom") return control;
291
- 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", {
292
341
  type: "number",
293
342
  className: "dsh_desk_lang_input",
294
343
  min: 1,
295
344
  max: MAX_REMINDER_MINUTES,
296
- placeholder: String(settings.reminderMinutes > 0 ? settings.reminderMinutes : 30),
345
+ "aria-label": t("reminderHeading"),
346
+ placeholder: String(current),
297
347
  value: draft,
298
348
  onChange: (event) => setDraft(event.currentTarget.value),
299
349
  onBlur: commit,
300
350
  onKeyDown: (event) => {
301
- if (event.key === "Enter") commit();
351
+ if (event.key === "Enter") {
352
+ event.preventDefault();
353
+ event.currentTarget.blur();
354
+ }
302
355
  }
303
- }), (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);
357
+ };
358
+ }
359
+ /**
360
+ * Build the extra-injection picker: on or off.
361
+ * 构建额外注入选择器:开启或关闭。
362
+ *
363
+ * It shares the host Menu with the other controls, so the three read as one column.
364
+ * 与另外两个控件共用宿主 Menu,三者在视觉上成一列。
365
+ */
366
+ function createExtraPicker(primitives) {
367
+ const Menu = primitives?.Menu;
368
+ const Chevron = primitives?.IconChevronDownOutlineRegular ?? primitives?.IconChevronDownOutline14 ?? primitives?.IconChevronDownOutlineMedium;
369
+ return function ExtraPicker(props) {
370
+ const { doc, t, settings, disabled = false } = props;
371
+ const [open, setOpen] = (0, react.useState)(false);
372
+ const { failed, save } = useSettingWriter(doc, FIELD_EXTRA);
373
+ const items = [{
374
+ id: "on",
375
+ label: t("extraOn")
376
+ }, {
377
+ id: "off",
378
+ label: t("extraOff")
379
+ }];
380
+ const close = () => setOpen(false);
381
+ const choose = (id) => {
382
+ if (!disabled) save(id === "on");
383
+ close();
384
+ };
385
+ const picker = (0, react.createElement)("button", {
386
+ type: "button",
387
+ className: "dsh_desk_lang_picker",
388
+ "aria-haspopup": "menu",
389
+ "aria-expanded": open,
390
+ disabled,
391
+ onClick: () => setOpen((value) => !value)
392
+ }, settings.extraInjection ? t("extraOn") : t("extraOff"), Chevron === void 0 ? null : (0, react.createElement)(Chevron, { className: "dsh_desk_lang_chevron" }));
393
+ return pickerWithError(Menu ? (0, react.createElement)(Menu, {
394
+ open: open && !disabled,
395
+ anchor: picker,
396
+ items,
397
+ selectedId: settings.extraInjection ? "on" : "off",
398
+ align: "end",
399
+ portal: true,
400
+ onClose: close,
401
+ onSelect: choose
402
+ }) : picker, failed, t);
304
403
  };
305
404
  }
306
405
  /**
@@ -330,6 +429,7 @@ function createRow(primitives) {
330
429
  function createConfigCard(primitives) {
331
430
  const LanguagePicker = createLanguagePicker(primitives);
332
431
  const ReminderPicker = createReminderPicker(primitives);
432
+ const ExtraPicker = createExtraPicker(primitives);
333
433
  return function ThinkingLanguageCard(props) {
334
434
  const settings = useSettings(props.doc);
335
435
  if (props.view === "summary") return null;
@@ -338,17 +438,23 @@ function createConfigCard(primitives) {
338
438
  t: props.t,
339
439
  settings
340
440
  };
341
- return (0, react.createElement)("div", null, (0, react.createElement)("div", { className: "dsh_desk_lang_row" }, (0, react.createElement)("div", { className: "dsh_desk_lang_text" }, (0, react.createElement)("div", { className: "dsh_desk_lang_title" }, props.t("heading")), (0, react.createElement)("div", { className: "dsh_desk_lang_desc" }, props.t("description"))), (0, react.createElement)(LanguagePicker, binding)), (0, react.createElement)("div", { className: "dsh_desk_lang_row" }, (0, react.createElement)("div", { className: "dsh_desk_lang_text" }, (0, react.createElement)("div", { className: "dsh_desk_lang_title" }, props.t("reminderHeading")), (0, react.createElement)("div", { className: "dsh_desk_lang_desc" }, props.t("reminderDescription"))), (0, react.createElement)(ReminderPicker, binding)));
441
+ const reminderOff = settings.reminderMinutes < 0;
442
+ return (0, react.createElement)("div", null, (0, react.createElement)("div", { className: "dsh_desk_lang_row" }, (0, react.createElement)("div", { className: "dsh_desk_lang_text" }, (0, react.createElement)("div", { className: "dsh_desk_lang_title" }, props.t("heading")), (0, react.createElement)("div", { className: "dsh_desk_lang_desc" }, props.t("description"))), (0, react.createElement)(LanguagePicker, binding)), (0, react.createElement)("div", { className: "dsh_desk_lang_row" }, (0, react.createElement)("div", { className: "dsh_desk_lang_text" }, (0, react.createElement)("div", { className: "dsh_desk_lang_title" }, props.t("reminderHeading")), (0, react.createElement)("div", { className: "dsh_desk_lang_desc" }, props.t("reminderDescription"))), (0, react.createElement)(ReminderPicker, binding)), (0, react.createElement)("div", { className: reminderOff ? "dsh_desk_lang_row dsh_desk_lang_row_disabled" : "dsh_desk_lang_row" }, (0, react.createElement)("div", { className: "dsh_desk_lang_text" }, (0, react.createElement)("div", { className: "dsh_desk_lang_title" }, props.t("extraHeading")), (0, react.createElement)("div", { className: "dsh_desk_lang_desc" }, props.t("extraDescription"))), (0, react.createElement)(ExtraPicker, {
443
+ ...binding,
444
+ disabled: reminderOff
445
+ })));
342
446
  };
343
447
  }
344
448
  const rowCss = [
345
449
  ".dsh_desk_lang_row{border-bottom:.5px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}",
450
+ ".dsh_desk_lang_row_disabled{opacity:.45;pointer-events:none}",
346
451
  ".dsh_desk_lang_text{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}",
347
452
  ".dsh_desk_lang_title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}",
348
453
  ".dsh_desk_lang_desc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}",
349
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}",
350
455
  ".dsh_desk_lang_picker:hover{background:var(--dsw-alias-interactive-bg-hover)}",
351
456
  ".dsh_desk_lang_chevron{flex:none}",
457
+ ".dsh_desk_lang_field{display:flex;flex-direction:column;align-items:flex-end;gap:4px}",
352
458
  ".dsh_desk_lang_control{align-items:center;gap:8px;display:flex;flex:none}",
353
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}",
354
460
  ".dsh_desk_lang_hint{color:var(--dsw-alias-label-tertiary);font-size:12px;white-space:nowrap}"
package/lib/core.d.ts CHANGED
@@ -33,8 +33,10 @@ export interface Language {
33
33
  nativeName: string;
34
34
  /** The rule sentence written in this language. / 用本语言写成的规则句。 */
35
35
  section: string;
36
- /** The short per-turn reminder written in this language. / 用本语言写成的每轮短提醒。 */
36
+ /** The short reminder written in this language for the head of the batch. / 写在批次开头的短提醒。 */
37
37
  reminder: string;
38
+ /** The short reminder written for the last message of the request. / 写在请求末尾的短提醒。 */
39
+ tail: string;
38
40
  }
39
41
  /**
40
42
  * The catalogue, in picker order.
@@ -57,6 +59,8 @@ export declare const SETTINGS_NAMESPACE = "ay-dsh-tk-lang";
57
59
  export declare const FIELD_LANGUAGE = "language";
58
60
  /** The reminder field this plugin stores. / 本插件保存的提醒字段。 */
59
61
  export declare const FIELD_REMINDER = "reminderMinutes";
62
+ /** The extra-injection field this plugin stores. / 本插件保存的额外注入字段。 */
63
+ export declare const FIELD_EXTRA = "extraInjection";
60
64
  /** Reminder value that disables the per-turn reminder. / 关闭每轮提醒的取值。 */
61
65
  export declare const REMINDER_OFF = -1;
62
66
  /** Reminder value that injects on every turn. / 每轮都注入的取值。 */
@@ -78,6 +82,12 @@ export interface ThinkingSettings {
78
82
  * 注入,1–1440 为最小间隔。
79
83
  */
80
84
  reminderMinutes: number;
85
+ /**
86
+ * Whether the closing rule is also folded into the skill catalogue. It only
87
+ * applies while the reminder is on.
88
+ * 是否把收尾规则同时折进技能目录;仅在提醒开启时生效。
89
+ */
90
+ extraInjection: boolean;
81
91
  }
82
92
  /** Configuration applied when the fields are absent. / 字段缺失时采用的配置。 */
83
93
  export declare const DEFAULTS: ThinkingSettings;
@@ -128,3 +138,8 @@ export declare function sectionText(code: string): string;
128
138
  * 用所选语言生成每轮短提醒。
129
139
  */
130
140
  export declare function reminderText(code: string): string;
141
+ /**
142
+ * Build the closing reminder appended as the request's last message.
143
+ * 生成追加在请求最后一条消息里的收尾提醒。
144
+ */
145
+ export declare function tailText(code: string): string;
package/lib/core.js CHANGED
@@ -41,20 +41,23 @@ export const CATALOGUE = [
41
41
  {
42
42
  tag: "zh-CN",
43
43
  nativeName: "简体中文",
44
- section: "推理规则:思考、推理与规划一律使用简体中文。回复用户时使用用户所用的语言。",
45
- reminder: "继续用简体中文思考、推理与规划。"
44
+ section: "推理规则:思考、推理与规划一律使用简体中文。",
45
+ reminder: "注意:思考、推理与规划用简体中文,即使上文不是",
46
+ tail: "下文请使用简体中文思考"
46
47
  },
47
48
  {
48
49
  tag: "zh-TW",
49
50
  nativeName: "繁體中文",
50
- section: "推理規則:思考、推理與規劃一律使用繁體中文。回覆使用者時使用使用者所用的語言。",
51
- reminder: "繼續用繁體中文思考、推理與規劃。"
51
+ section: "推理規則:思考、推理與規劃一律使用繁體中文。",
52
+ reminder: "注意:思考、推理與規劃用繁體中文,即使上文不是",
53
+ tail: "下文請使用繁體中文思考"
52
54
  },
53
55
  {
54
56
  tag: "en",
55
57
  nativeName: "English",
56
- section: "Reasoning rules: think, reason, and plan in English. Reply to the user in the language they use.",
57
- reminder: "Keep thinking, reasoning, and planning in English."
58
+ section: "Reasoning rules: think, reason, and plan in English.",
59
+ reminder: "Note: think, reason, and plan in English, even if the text above is not",
60
+ tail: "Think in English from here on"
58
61
  }
59
62
  ];
60
63
  /** The sentinel meaning "follow the host locale". / 表示「跟随宿主语言」的哨兵值。 */
@@ -67,6 +70,8 @@ export const SETTINGS_NAMESPACE = "ay-dsh-tk-lang";
67
70
  export const FIELD_LANGUAGE = "language";
68
71
  /** The reminder field this plugin stores. / 本插件保存的提醒字段。 */
69
72
  export const FIELD_REMINDER = "reminderMinutes";
73
+ /** The extra-injection field this plugin stores. / 本插件保存的额外注入字段。 */
74
+ export const FIELD_EXTRA = "extraInjection";
70
75
  /** Reminder value that disables the per-turn reminder. / 关闭每轮提醒的取值。 */
71
76
  export const REMINDER_OFF = -1;
72
77
  /** Reminder value that injects on every turn. / 每轮都注入的取值。 */
@@ -78,7 +83,11 @@ export const MAX_REMINDER_MINUTES = 1440;
78
83
  /** Every value the picker offers besides {@link AUTO}. / 选择器在 {@link AUTO} 之外提供的全部取值。 */
79
84
  export const SELECTABLE_TAGS = CATALOGUE.map((language) => language.tag);
80
85
  /** Configuration applied when the fields are absent. / 字段缺失时采用的配置。 */
81
- export const DEFAULTS = { language: AUTO, reminderMinutes: DEFAULT_REMINDER_MINUTES };
86
+ export const DEFAULTS = {
87
+ language: AUTO,
88
+ reminderMinutes: DEFAULT_REMINDER_MINUTES,
89
+ extraInjection: true
90
+ };
82
91
  /** Catalogue lookup keyed by lower-cased tag. / 以小写标签为键的目录索引。 */
83
92
  const BY_TAG = new Map(CATALOGUE.map((language) => [language.tag.toLowerCase(), language]));
84
93
  /**
@@ -160,8 +169,8 @@ function candidatesOf(locale) {
160
169
  * 手写地区对照表。
161
170
  */
162
171
  function chineseTag(locale) {
163
- const maximized = typeof locale.maximize === "function" ? locale.maximize() : undefined;
164
- return maximized?.script === "Hant" ? CHINESE.traditional : CHINESE.simplified;
172
+ const script = locale.script ?? locale.maximize().script;
173
+ return script === "Hant" ? CHINESE.traditional : CHINESE.simplified;
165
174
  }
166
175
  /**
167
176
  * Map a locale onto a catalogue language tag.
@@ -171,12 +180,14 @@ function tagForLocale(raw) {
171
180
  const locale = parseLocale(raw);
172
181
  if (locale === undefined)
173
182
  return undefined;
183
+ if (locale.language === "zh")
184
+ return chineseTag(locale);
174
185
  for (const candidate of candidatesOf(locale)) {
175
186
  const match = BY_TAG.get(candidate.toLowerCase());
176
187
  if (match !== undefined)
177
188
  return match.tag;
178
189
  }
179
- return locale.language === "zh" ? chineseTag(locale) : undefined;
190
+ return undefined;
180
191
  }
181
192
  /**
182
193
  * Coerce an untrusted settings section into a complete configuration.
@@ -187,10 +198,13 @@ function normalizeReminder(raw) {
187
198
  const numeric = typeof raw === "number" ? raw : typeof raw === "string" && raw.trim() !== "" ? Number(raw) : NaN;
188
199
  if (!Number.isFinite(numeric))
189
200
  return DEFAULT_REMINDER_MINUTES;
190
- const rounded = Math.round(numeric);
191
- if (rounded < 0)
201
+ if (numeric < 0)
192
202
  return REMINDER_OFF;
193
- return rounded > MAX_REMINDER_MINUTES ? MAX_REMINDER_MINUTES : rounded;
203
+ return Math.max(REMINDER_EVERY_TURN, Math.min(MAX_REMINDER_MINUTES, Math.round(numeric)));
204
+ }
205
+ /** Coerce one untrusted extra-injection value; only an explicit false turns it off. / 把不可信的额外注入值收敛为布尔;只有明确的 false 视为关闭。 */
206
+ function normalizeExtra(raw) {
207
+ return raw !== false && raw !== "false";
194
208
  }
195
209
  /**
196
210
  * Convert stored minutes into the minimum gap between reminders.
@@ -211,7 +225,8 @@ export function normalizeSettings(raw) {
211
225
  const stored = section?.[FIELD_LANGUAGE];
212
226
  return {
213
227
  language: typeof stored === "string" && stored !== "" ? stored : DEFAULTS.language,
214
- reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER])
228
+ reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER]),
229
+ extraInjection: normalizeExtra(section?.[FIELD_EXTRA])
215
230
  };
216
231
  }
217
232
  /**
@@ -256,3 +271,10 @@ export function sectionText(code) {
256
271
  export function reminderText(code) {
257
272
  return languageOf(code)?.reminder ?? "";
258
273
  }
274
+ /**
275
+ * Build the closing reminder appended as the request's last message.
276
+ * 生成追加在请求最后一条消息里的收尾提醒。
277
+ */
278
+ export function tailText(code) {
279
+ return languageOf(code)?.tail ?? "";
280
+ }
package/lib/index.d.ts CHANGED
@@ -29,6 +29,8 @@ interface HostContext {
29
29
  on(event: "agent/pre-step", listener: (payload: PreStepPayload, next: () => Promise<PreStepDecision>) => Promise<PreStepDecision>, options?: {
30
30
  prepend?: boolean;
31
31
  }): unknown;
32
+ on(event: "agent/created", listener: (payload: unknown) => unknown): unknown;
33
+ on(event: "settings/document-updated", listener: (namespace: string) => void): unknown;
32
34
  systemPrompt: {
33
35
  section(section: {
34
36
  name: string;