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.
package/lib/index.js CHANGED
@@ -6,10 +6,14 @@
6
6
  * 注入形态(设计理由见 README):
7
7
  *
8
8
  * section order 1 → the authoritative rule, once per session
9
- * pre-step step 1 → a short reminder, at most once per turn (interval configurable, default 30 min)
9
+ * pre-step step 1 → a short reminder at the head of the batch, at most once per turn
10
+ * (interval configurable, default 30 min)
11
+ * pre-step step 1 → the closing rule, folded into the skill catalogue or sent
12
+ * as its own message when extra injection is on
10
13
  *
11
14
  * section order 1 → 权威规则,每会话组装一次
12
- * pre-step step 1 → 短提醒,每轮最多一次(间隔可配置,默认 30 分钟)
15
+ * pre-step step 1 → 批次开头的短提醒,每轮最多一次(间隔可配置,默认 30 分钟)
16
+ * pre-step step 1 → 收尾规则,额外注入开启时折进技能目录,或独立发送
13
17
  *
14
18
  * The host context is described by a local structural interface rather than the
15
19
  * `@deepseek-ai/cordis` type, so this package carries no DSH type dependency.
@@ -18,7 +22,7 @@
18
22
  */
19
23
  import { randomUUID } from "node:crypto";
20
24
  import z from "@deepseek-ai/schemastery";
21
- import { AUTO, DEFAULT_REMINDER_MINUTES, FIELD_LANGUAGE, FIELD_REMINDER, REMINDER_OFF, SELECTABLE_TAGS, SETTINGS_NAMESPACE, effectiveCode, nativeNameFor, normalizeSettings, reminderDelayMs, reminderText, sectionText } from "./core.js";
25
+ import { AUTO, DEFAULT_REMINDER_MINUTES, DEFAULTS, FIELD_EXTRA, FIELD_LANGUAGE, FIELD_REMINDER, REMINDER_OFF, SELECTABLE_TAGS, SETTINGS_NAMESPACE, effectiveCode, nativeNameFor, normalizeSettings, reminderDelayMs, reminderText, tailText, sectionText } from "./core.js";
22
26
  /** Stable Cordis plugin name. / 稳定的 Cordis 插件名。 */
23
27
  export const name = "ay-dsh-tk-lang";
24
28
  /** Plugin-level service requirements; services are acquired per branch below. / 插件级服务声明;服务在下方逐分支获取。 */
@@ -91,31 +95,21 @@ function buildSchema() {
91
95
  const choices = [AUTO, ...SELECTABLE_TAGS].map((value) => labelled(z.const(value), nativeNameFor(value)));
92
96
  return z.object({
93
97
  [FIELD_LANGUAGE]: live(z.union(choices).default(AUTO)),
94
- [FIELD_REMINDER]: live(z.number().default(DEFAULT_REMINDER_MINUTES))
98
+ [FIELD_REMINDER]: live(z.number().default(DEFAULT_REMINDER_MINUTES)),
99
+ [FIELD_EXTRA]: live(z.boolean().default(DEFAULTS.extraInjection))
95
100
  });
96
101
  }
97
102
  /** Durable settings schema; the field defaults to {@link AUTO}. / 持久化设置 schema;字段默认为 {@link AUTO}。 */
98
103
  export const Config = buildSchema();
99
104
  /** Handed back while the settings service is unavailable or unreadable. / 设置服务不可用或读不出时交回的空表。 */
100
105
  const NO_SECTIONS = new Map();
101
- let snapshot;
102
- /**
103
- * Pull every namespace section out of the settings document.
104
- * 从设置文档里取出各个命名空间的段。
105
- *
106
- * A section is a `{ns, value}` entry whose `value` is a plain object; anything
107
- * else in the listing is not something this plugin can read, so it is skipped
108
- * rather than coerced.
109
- * 一个段就是 `value` 为普通对象的 `{ns, value}` 条目;列表里其它形状不是本插件能读
110
- * 的东西,因此跳过而不做强制转换。
111
- */
112
106
  /**
113
107
  * Call `describe()` without letting a throwing host escape.
114
108
  * 调用 `describe()`,不让抛异常的宿主逃逸出去。
115
109
  */
116
110
  function described(settings) {
117
111
  try {
118
- return settings.describe();
112
+ return settings.describe({ redactSecrets: true });
119
113
  }
120
114
  catch {
121
115
  return undefined;
@@ -137,42 +131,28 @@ function asSection(value) {
137
131
  return value;
138
132
  }
139
133
  function collect(settings) {
140
- const found = new Map();
141
134
  const listed = described(settings);
142
135
  if (!Array.isArray(listed))
143
- return found;
136
+ return undefined;
137
+ const found = new Map();
144
138
  for (const item of listed) {
145
- const { ns, value } = item;
146
- const section = asSection(value);
147
- if (typeof ns === "string" && section !== undefined)
139
+ const entry = asSection(item);
140
+ const ns = entry?.ns;
141
+ if (ns !== SETTINGS_NAMESPACE && ns !== LOCALE_NAMESPACE)
142
+ continue;
143
+ const section = asSection(entry?.value);
144
+ if (section !== undefined)
148
145
  found.set(ns, section);
149
146
  }
150
147
  return found;
151
148
  }
152
- /**
153
- * Read the namespace sections, reusing one read for a short while.
154
- * 读取各命名空间的段,并在很短的时间内复用同一次读取。
155
- *
156
- * The cache exists because prompt assembly asks on every model step, while
157
- * `describe()` walks the whole settings document each time.
158
- * 缓存的存在是因为提示词组装每一步都会问,而 `describe()` 每次都要遍历整份设置文档。
159
- */
160
- function sectionsOf(settings) {
161
- if (!settings || typeof settings.describe !== "function")
162
- return NO_SECTIONS;
163
- const now = Date.now();
164
- if (snapshot === undefined || now - snapshot.takenAt >= SETTINGS_TTL_MS) {
165
- snapshot = { takenAt: now, sections: collect(settings) };
166
- }
167
- return snapshot.sections;
168
- }
169
149
  /**
170
150
  * Adapt the settings service to the `get()`-style handle the core reads from.
171
151
  * 把设置服务适配成核心代码所用的 `get()` 风格句柄。
172
152
  */
173
- function settingsReader(settings) {
153
+ function settingsReader(sections) {
174
154
  return {
175
- get: (ns) => sectionsOf(settings).get(typeof ns === "string" ? ns : SETTINGS_NAMESPACE)
155
+ get: (ns = SETTINGS_NAMESPACE) => sections.get(ns)
176
156
  };
177
157
  }
178
158
  /**
@@ -247,6 +227,33 @@ function reminderMessage(text) {
247
227
  source: { kind: name, form: "snapshot", sections: [{ name, text }] }
248
228
  };
249
229
  }
230
+ /**
231
+ * Put the rule in front of the text a message already carries.
232
+ * 把规则放到消息已有文本的前面。
233
+ */
234
+ function prefixPrompt(message, text) {
235
+ const content = Array.isArray(message.content) ? message.content : [];
236
+ const head = content[0];
237
+ if (head && head.type === "text" && typeof head.text === "string" && head.text.startsWith(text))
238
+ return message;
239
+ return { ...message, content: [{ type: "text", text: `${text}\n` }, ...content] };
240
+ }
241
+ /**
242
+ * Attach the rule to this batch's skill catalogue, or append a plugin-owned message last.
243
+ * 把规则加到当前批次的技能目录;没有目录时在批次末尾追加一条本插件来源的消息。
244
+ *
245
+ * The fallback lands after every other injected message, so the closing rule stays
246
+ * the last thing the model reads even when no catalogue was sent.
247
+ * 回退的那条落在全部注入消息之后,因此没有技能目录时,收尾规则仍是模型最后读到的一句。
248
+ */
249
+ function withClosingReminder(messages, text) {
250
+ const index = messages.findIndex((message) => asSection(message.source)?.kind === "skill-catalog");
251
+ if (index < 0)
252
+ return [...messages, reminderMessage(text)];
253
+ const next = [...messages];
254
+ next[index] = prefixPrompt(messages[index], text);
255
+ return next;
256
+ }
250
257
  /**
251
258
  * Register the settings consumer, the prompt section, and the per-turn reminder.
252
259
  * 注册设置消费方、提示词段,以及每轮一次的提醒。
@@ -255,7 +262,26 @@ export function apply(ctx) {
255
262
  /** Latest reminder time per session, in process memory. / 每个会话最近一次提醒时间,存于进程内存。 */
256
263
  const lastReminderAt = new Map();
257
264
  ctx.inject(["systemPrompt", "settings"], (promptCtx) => {
258
- const reader = () => settingsReader(promptCtx.get("settings"));
265
+ // A settings write emits this event before acknowledgement. The TTL also
266
+ // refreshes reads when a host change produced no notification.
267
+ // 设置写入在应答前发出此事件。TTL 也会刷新未收到通知的变动。
268
+ let snapshot;
269
+ promptCtx.on("settings/document-updated", (namespace) => {
270
+ if (namespace === SETTINGS_NAMESPACE || namespace === LOCALE_NAMESPACE)
271
+ snapshot = undefined;
272
+ });
273
+ const reader = () => {
274
+ const service = promptCtx.get("settings");
275
+ if (!service || typeof service.describe !== "function")
276
+ return settingsReader(NO_SECTIONS);
277
+ const now = Date.now();
278
+ if (snapshot?.service === service && now >= snapshot.takenAt && now - snapshot.takenAt < SETTINGS_TTL_MS) {
279
+ return settingsReader(snapshot.sections);
280
+ }
281
+ const sections = collect(service);
282
+ snapshot = sections === undefined ? undefined : { service, takenAt: now, sections };
283
+ return settingsReader(sections ?? NO_SECTIONS);
284
+ };
259
285
  // The text thunk is re-evaluated per assembly, so the section always
260
286
  // reflects the newest setting without re-registering anything.
261
287
  // 文本 thunk 每次组装都会重新求值,因此该段始终反映最新设置,无需重新注册。
@@ -264,12 +290,13 @@ export function apply(ctx) {
264
290
  order: SECTION_ORDER,
265
291
  text: () => sectionText(currentSettings(reader()).language)
266
292
  });
267
- // The reminder runs before the other pre-step listeners, so its message is
268
- // appended after theirs and stays closest to the end of the request.
269
- // 该提醒先于其它 pre-step 监听器执行,因此它的消息追加在它们之后,离请求末尾最近。
270
- promptCtx.on("agent/pre-step", async (payload, next) => {
293
+ /**
294
+ * Wrap the batch in two reminders: one before the prompt, one after every injection.
295
+ * 用两条提醒夹住批次:一条在提问之前,一条在全部注入之后。
296
+ */
297
+ const rewrite = async (payload, next) => {
271
298
  const decision = await next();
272
- if (decision.kind !== "enter" || payload.signal.aborted || payload.step !== 1)
299
+ if (decision.kind !== "enter" || payload.signal.aborted || payload.step !== 1 || decision.messages.length === 0)
273
300
  return decision;
274
301
  const settings = currentSettings(reader());
275
302
  const delay = reminderDelayMs(settings.reminderMinutes);
@@ -279,11 +306,32 @@ export function apply(ctx) {
279
306
  const previous = lastReminderAt.get(payload.agent.session.id);
280
307
  if (delay > 0 && previous !== undefined && now - previous < delay)
281
308
  return decision;
282
- const text = reminderText(settings.language);
283
- if (text === "")
309
+ const head = reminderText(settings.language);
310
+ if (head === "")
284
311
  return decision;
285
312
  lastReminderAt.set(payload.agent.session.id, now);
286
- return { ...decision, messages: [...decision.messages, reminderMessage(text)] };
287
- }, { prepend: true });
313
+ // The closing rule rides on the same switch as the reminder: turning the
314
+ // reminder off skips this whole listener, so both injections stop together.
315
+ // 收尾规则与提醒共用一个开关:提醒关闭时本段不执行,两处注入一起停。
316
+ const tail = settings.extraInjection ? tailText(settings.language) : "";
317
+ const messages = tail === "" ? decision.messages : withClosingReminder(decision.messages, tail);
318
+ return { ...decision, messages: [reminderMessage(head), ...messages] };
319
+ };
320
+ /**
321
+ * `prepend` unshifts, so the listener prepended last runs first and returns last:
322
+ * only it sees every message the other pre-step listeners appended, including the
323
+ * trailing `time-context` batch.
324
+ * `prepend` 是 unshift:最后 prepend 的监听器最先执行、最后返回,只有它能看见其它
325
+ * pre-step 监听器追加的全部消息,包括压在最后的 `time-context`。
326
+ */
327
+ let disposeStep;
328
+ const bindOutermost = () => {
329
+ disposeStep?.();
330
+ disposeStep = promptCtx.on("agent/pre-step", rewrite, { prepend: true });
331
+ };
332
+ bindOutermost();
333
+ promptCtx.on("agent/created", () => {
334
+ bindOutermost();
335
+ });
288
336
  });
289
337
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-thinking-lang",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "DSH plugin: set the agent's reasoning language (Settings → General)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -29,6 +29,16 @@ export interface Dict {
29
29
  reminderUnit: string;
30
30
  /** Hint under the custom interval input. / 自定义间隔输入框的提示。 */
31
31
  reminderCustomHint: string;
32
+ /** Extra-injection row heading. / 额外注入行的标题。 */
33
+ extraHeading: string;
34
+ /** Extra-injection row description. / 额外注入行的说明。 */
35
+ extraDescription: string;
36
+ /** Label of the enabled option. / 开启选项的标签。 */
37
+ extraOn: string;
38
+ /** Label of the disabled option. / 关闭选项的标签。 */
39
+ extraOff: string;
40
+ /** Message shown when a write fails. / 写入失败时显示的提示。 */
41
+ saveError: string;
32
42
  }
33
43
 
34
44
  /** Simplified Chinese copy. / 简体中文文案。 */
@@ -42,7 +52,12 @@ export const zh: Dict = {
42
52
  reminderTurn: "每轮",
43
53
  reminderCustom: "自定义",
44
54
  reminderUnit: "分钟",
45
- reminderCustomHint: "1–1440 分钟"
55
+ reminderCustomHint: "1–1440 分钟",
56
+ extraHeading: "额外提醒注入",
57
+ extraDescription: "把额外提醒放进本轮技能目录,没有新目录时独立发送。提醒间隔为「关闭」时停用。",
58
+ extraOn: "开启",
59
+ extraOff: "关闭",
60
+ saveError: "设置未能保存,请重试。"
46
61
  };
47
62
 
48
63
  /** English copy. / 英文文案。 */
@@ -57,7 +72,13 @@ export const en: Dict = {
57
72
  reminderTurn: "Every turn",
58
73
  reminderCustom: "Custom",
59
74
  reminderUnit: "min",
60
- reminderCustomHint: "1–1440 minutes"
75
+ reminderCustomHint: "1–1440 minutes",
76
+ extraHeading: "Extra reminder injection",
77
+ extraDescription:
78
+ "Adds a reminder to the skill catalogue, or sends it separately if no catalogue is sent. Turning reminders off also turns this off.",
79
+ extraOn: "On",
80
+ extraOff: "Off",
81
+ saveError: "Could not save this setting. Try again."
61
82
  };
62
83
 
63
84
  /** Dictionaries keyed by UI locale, handed to the host locale service. / 以界面语言为键、交给宿主 locale 服务的字典。 */
@@ -9,11 +9,12 @@
9
9
  * The row owns no state of its own: it reads the document, subscribes to it, and
10
10
  * writes the fields back. / 控件不持有自己的状态:读取文档、订阅变化、回写字段。
11
11
  */
12
- import { createElement as h, useEffect, useState } from "react";
12
+ import { createElement as h, useEffect, useRef, useState } from "react";
13
13
  import {
14
14
  AUTO,
15
15
  CATALOGUE,
16
16
  DEFAULTS,
17
+ FIELD_EXTRA,
17
18
  FIELD_LANGUAGE,
18
19
  FIELD_REMINDER,
19
20
  MAX_REMINDER_MINUTES,
@@ -29,8 +30,7 @@ import type { Dict } from "./locales.js";
29
30
  export interface SettingsDoc {
30
31
  getSnapshot(): { value?: unknown; revision?: number };
31
32
  subscribe(listener: () => void): () => void;
32
- set(field: string, value: unknown): unknown;
33
- unset(field: string): unknown;
33
+ set(field: string, value: unknown): Promise<boolean>;
34
34
  }
35
35
 
36
36
  /** UI primitives this plugin can use when the host provides them. / 宿主提供时本插件可用的 UI 原语。 */
@@ -65,18 +65,41 @@ function readSettings(doc: SettingsDoc): ThinkingSettings {
65
65
  }
66
66
 
67
67
  /**
68
- * Write one field back, swallowing a refusal so a read-only host cannot break the UI.
69
- * 回写单个字段,并吞掉拒绝异常,使只读宿主不会让控件崩溃。
68
+ * Show the result of the latest write for a field.
69
+ * 显示该字段最近一次写入的结果。
70
70
  */
71
- function writeField(doc: SettingsDoc, field: string, value: unknown): void {
72
- try {
73
- const outcome = doc.set(field, value) as { then?: unknown } | null | undefined;
74
- if (typeof outcome?.then === "function") {
75
- void (outcome as Promise<unknown>).then(undefined, () => {});
71
+ function useSettingWriter(doc: SettingsDoc, field: string) {
72
+ const [failed, setFailed] = useState(false);
73
+ const generation = useRef(0);
74
+ useEffect(() => {
75
+ setFailed(false);
76
+ return () => {
77
+ generation.current += 1;
78
+ };
79
+ }, [doc]);
80
+
81
+ async function save(value: unknown): Promise<void> {
82
+ const attempted = ++generation.current;
83
+ setFailed(false);
84
+ let accepted = false;
85
+ try {
86
+ accepted = await doc.set(field, value);
87
+ } catch {
88
+ // A transport failure leaves the last confirmed setting in the form.
89
+ // 传输失败后,表单仍显示上一次已确认的设置。
76
90
  }
77
- } catch {
78
- /* a read-only settings document is not an error worth surfacing here */
91
+ if (attempted === generation.current) setFailed(!accepted);
79
92
  }
93
+ return { failed, save };
94
+ }
95
+
96
+ function pickerWithError(control: unknown, failed: boolean, t: Binding["t"]): unknown {
97
+ return h(
98
+ "div",
99
+ { className: "dsh_desk_lang_field" },
100
+ control,
101
+ failed ? h("div", { className: "dsh_desk_lang_desc", role: "alert" }, t("saveError")) : null
102
+ );
80
103
  }
81
104
 
82
105
  /** Subscribe one component to the document and re-read it on every revision. / 订阅设置文档,并在每次修订时重新读取。 */
@@ -104,6 +127,7 @@ function createLanguagePicker(primitives: UiPrimitives | undefined) {
104
127
  return function LanguagePicker(props: Binding & { settings: ThinkingSettings }): unknown {
105
128
  const { doc, t, settings } = props;
106
129
  const [open, setOpen] = useState<boolean>(false);
130
+ const { failed, save } = useSettingWriter(doc, FIELD_LANGUAGE);
107
131
  const items = [
108
132
  { id: AUTO, label: t("autoLabel") },
109
133
  ...CATALOGUE.map((language) => ({ id: language.tag, label: language.nativeName }))
@@ -112,7 +136,7 @@ function createLanguagePicker(primitives: UiPrimitives | undefined) {
112
136
  settings.language === AUTO ? t("autoLabel") : nativeNameFor(settings.language) ?? settings.language;
113
137
  const close = (): void => setOpen(false);
114
138
  const choose = (id: string): void => {
115
- writeField(doc, FIELD_LANGUAGE, id);
139
+ void save(id);
116
140
  close();
117
141
  };
118
142
  const picker = h(
@@ -127,17 +151,19 @@ function createLanguagePicker(primitives: UiPrimitives | undefined) {
127
151
  activeLabel,
128
152
  Chevron === undefined ? null : h(Chevron, { className: "dsh_desk_lang_chevron" })
129
153
  );
130
- if (!Menu) return picker;
131
- return h(Menu, {
132
- open,
133
- anchor: picker,
134
- items,
135
- selectedId: settings.language,
136
- align: "end",
137
- portal: true,
138
- onClose: close,
139
- onSelect: choose
140
- });
154
+ const control = Menu
155
+ ? h(Menu, {
156
+ open,
157
+ anchor: picker,
158
+ items,
159
+ selectedId: settings.language,
160
+ align: "end",
161
+ portal: true,
162
+ onClose: close,
163
+ onSelect: choose
164
+ })
165
+ : picker;
166
+ return pickerWithError(control, failed, t);
141
167
  };
142
168
  }
143
169
 
@@ -167,26 +193,18 @@ function createReminderPicker(primitives: UiPrimitives | undefined) {
167
193
 
168
194
  return function ReminderPicker(props: Binding & { settings: ThinkingSettings }): unknown {
169
195
  const { doc, t, settings } = props;
170
- const derived = derivedPreset(settings.reminderMinutes);
171
- const current = settings.reminderMinutes > 0 ? settings.reminderMinutes : 30;
172
- const [selected, setSelected] = useState<string>(derived);
196
+ const minutes = settings.reminderMinutes;
197
+ const selected = derivedPreset(minutes);
198
+ const current = minutes > 0 ? minutes : DEFAULTS.reminderMinutes;
199
+ const [editingCustom, setEditingCustom] = useState(false);
173
200
  const [open, setOpen] = useState<boolean>(false);
174
201
  const [draft, setDraft] = useState<string>(String(current));
202
+ const { failed, save } = useSettingWriter(doc, FIELD_REMINDER);
175
203
 
176
- // An external change (the other surface, or a re-read) wins over a local
177
- // selection; a local "custom" survives because it leaves `derived` alone.
178
- // 外部改动(另一入口或重新读取)优先于本地选择;本地的「自定义」不会改变
179
- // `derived`,因此能保持选中。
180
- useEffect(() => {
181
- setSelected(derived);
182
- }, [derived]);
183
-
184
- // Keep the input in step with the stored value, so an accepted edit never
185
- // falls back to the previous number while the document update lands.
186
- // 让输入框跟随存储值,避免写入落盘前先闪回上一个数字。
187
204
  useEffect(() => {
188
205
  setDraft(String(current));
189
- }, [current]);
206
+ setEditingCustom(false);
207
+ }, [current, doc, minutes]);
190
208
 
191
209
  const labelOf = (id: string): string => {
192
210
  if (id === "off") return t("reminderOff");
@@ -202,21 +220,23 @@ function createReminderPicker(primitives: UiPrimitives | undefined) {
202
220
 
203
221
  const choose = (id: string): void => {
204
222
  setOpen(false);
205
- setSelected(id);
206
- if (id === "off") writeField(doc, FIELD_REMINDER, REMINDER_OFF);
207
- else if (id === "turn") writeField(doc, FIELD_REMINDER, REMINDER_EVERY_TURN);
208
- else if (id !== "custom") writeField(doc, FIELD_REMINDER, Number(id));
223
+ setDraft(String(current));
224
+ setEditingCustom(id === "custom");
225
+ if (id === "custom") return;
226
+ const value = id === "off" ? REMINDER_OFF : id === "turn" ? REMINDER_EVERY_TURN : Number(id);
227
+ void save(value);
209
228
  };
210
229
 
211
230
  const commit = (): void => {
212
- const minutes = Math.round(Number(draft));
213
- if (!Number.isFinite(minutes) || draft.trim() === "") {
231
+ const parsed = Math.round(Number(draft));
232
+ if (!Number.isFinite(parsed) || draft.trim() === "") {
214
233
  setDraft(String(current));
215
234
  return;
216
235
  }
217
- const clamped = Math.min(MAX_REMINDER_MINUTES, Math.max(1, minutes));
218
- writeField(doc, FIELD_REMINDER, clamped);
236
+ const clamped = Math.min(MAX_REMINDER_MINUTES, Math.max(1, parsed));
219
237
  setDraft(String(clamped));
238
+ if (clamped === minutes) setEditingCustom(false);
239
+ void save(clamped);
220
240
  };
221
241
 
222
242
  const picker = h(
@@ -245,8 +265,8 @@ function createReminderPicker(primitives: UiPrimitives | undefined) {
245
265
  })
246
266
  : picker;
247
267
 
248
- if (selected !== "custom") return control;
249
- return h(
268
+ if (!editingCustom && selected !== "custom") return pickerWithError(control, failed, t);
269
+ const editor = h(
250
270
  "div",
251
271
  { className: "dsh_desk_lang_control" },
252
272
  control,
@@ -255,16 +275,77 @@ function createReminderPicker(primitives: UiPrimitives | undefined) {
255
275
  className: "dsh_desk_lang_input",
256
276
  min: 1,
257
277
  max: MAX_REMINDER_MINUTES,
258
- placeholder: String(settings.reminderMinutes > 0 ? settings.reminderMinutes : 30),
278
+ "aria-label": t("reminderHeading"),
279
+ placeholder: String(current),
259
280
  value: draft,
260
281
  onChange: (event: { currentTarget: { value: string } }): void => setDraft(event.currentTarget.value),
261
282
  onBlur: commit,
262
- onKeyDown: (event: { key: string }): void => {
263
- if (event.key === "Enter") commit();
283
+ onKeyDown: (event: { key: string; currentTarget: HTMLInputElement; preventDefault(): void }): void => {
284
+ if (event.key === "Enter") {
285
+ event.preventDefault();
286
+ event.currentTarget.blur();
287
+ }
264
288
  }
265
289
  }),
266
290
  h("span", { className: "dsh_desk_lang_hint" }, t("reminderCustomHint"))
267
291
  );
292
+ return pickerWithError(editor, failed, t);
293
+ };
294
+ }
295
+
296
+ /**
297
+ * Build the extra-injection picker: on or off.
298
+ * 构建额外注入选择器:开启或关闭。
299
+ *
300
+ * It shares the host Menu with the other controls, so the three read as one column.
301
+ * 与另外两个控件共用宿主 Menu,三者在视觉上成一列。
302
+ */
303
+ function createExtraPicker(primitives: UiPrimitives | undefined) {
304
+ const Menu = primitives?.Menu;
305
+ const Chevron =
306
+ primitives?.IconChevronDownOutlineRegular ??
307
+ primitives?.IconChevronDownOutline14 ??
308
+ primitives?.IconChevronDownOutlineMedium;
309
+
310
+ return function ExtraPicker(props: Binding & { settings: ThinkingSettings; disabled?: boolean }): unknown {
311
+ const { doc, t, settings, disabled = false } = props;
312
+ const [open, setOpen] = useState<boolean>(false);
313
+ const { failed, save } = useSettingWriter(doc, FIELD_EXTRA);
314
+ const items = [
315
+ { id: "on", label: t("extraOn") },
316
+ { id: "off", label: t("extraOff") }
317
+ ];
318
+ const close = (): void => setOpen(false);
319
+ const choose = (id: string): void => {
320
+ if (!disabled) void save(id === "on");
321
+ close();
322
+ };
323
+ const picker = h(
324
+ "button",
325
+ {
326
+ type: "button",
327
+ className: "dsh_desk_lang_picker",
328
+ "aria-haspopup": "menu",
329
+ "aria-expanded": open,
330
+ disabled,
331
+ onClick: (): void => setOpen((value: boolean) => !value)
332
+ },
333
+ settings.extraInjection ? t("extraOn") : t("extraOff"),
334
+ Chevron === undefined ? null : h(Chevron, { className: "dsh_desk_lang_chevron" })
335
+ );
336
+ const control = Menu
337
+ ? h(Menu, {
338
+ open: open && !disabled,
339
+ anchor: picker,
340
+ items,
341
+ selectedId: settings.extraInjection ? "on" : "off",
342
+ align: "end",
343
+ portal: true,
344
+ onClose: close,
345
+ onSelect: choose
346
+ })
347
+ : picker;
348
+ return pickerWithError(control, failed, t);
268
349
  };
269
350
  }
270
351
 
@@ -302,10 +383,15 @@ export function createRow(primitives: UiPrimitives | undefined): (props: Binding
302
383
  export function createConfigCard(primitives: UiPrimitives | undefined): (props: Binding & { view?: string }) => unknown {
303
384
  const LanguagePicker = createLanguagePicker(primitives);
304
385
  const ReminderPicker = createReminderPicker(primitives);
386
+ const ExtraPicker = createExtraPicker(primitives);
305
387
  return function ThinkingLanguageCard(props: Binding & { view?: string }): unknown {
306
388
  const settings = useSettings(props.doc);
307
389
  if (props.view === "summary") return null;
308
390
  const binding = { doc: props.doc, t: props.t, settings };
391
+ // Turning the reminder off stops both injections, so the extra-injection
392
+ // control greys out instead of accepting a value that cannot take effect.
393
+ // 提醒关闭时两处注入都会停,因此额外注入控件置灰,而不是让一个不生效的取值可选。
394
+ const reminderOff = settings.reminderMinutes < 0;
309
395
  return h(
310
396
  "div",
311
397
  null,
@@ -330,6 +416,17 @@ export function createConfigCard(primitives: UiPrimitives | undefined): (props:
330
416
  h("div", { className: "dsh_desk_lang_desc" }, props.t("reminderDescription"))
331
417
  ),
332
418
  h(ReminderPicker, binding)
419
+ ),
420
+ h(
421
+ "div",
422
+ { className: reminderOff ? "dsh_desk_lang_row dsh_desk_lang_row_disabled" : "dsh_desk_lang_row" },
423
+ h(
424
+ "div",
425
+ { className: "dsh_desk_lang_text" },
426
+ h("div", { className: "dsh_desk_lang_title" }, props.t("extraHeading")),
427
+ h("div", { className: "dsh_desk_lang_desc" }, props.t("extraDescription"))
428
+ ),
429
+ h(ExtraPicker, { ...binding, disabled: reminderOff })
333
430
  )
334
431
  );
335
432
  };
@@ -339,17 +436,19 @@ export function createConfigCard(primitives: UiPrimitives | undefined): (props:
339
436
  // packages/client/ui-chat/src/client/settings/PreferenceRow.module.css, MIT,
340
437
  // Copyright (c) 2026 DeepSeek — because that is the row this one sits beside.
341
438
  // Class names differ (the host's are CSS-Modules hashes) and the picker carries a
342
- // trailing `flex:none` the host does not need; every other character matches.
439
+ // trailing `flex:none` the host does not need. The form adds styles for its own controls.
343
440
  // 声明顺序逐字照宿主自己的 PreferenceRow——因为那就是本行紧邻的邻居。类名不同,
344
- // 选择器末尾多一个宿主不需要的 `flex:none`;除此之外逐字符一致。
441
+ // 选择器末尾多一个宿主不需要的 `flex:none`。表单还定义了自身控件的样式。
345
442
  const rowCss = [
346
443
  ".dsh_desk_lang_row{border-bottom:.5px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}",
444
+ ".dsh_desk_lang_row_disabled{opacity:.45;pointer-events:none}",
347
445
  ".dsh_desk_lang_text{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}",
348
446
  ".dsh_desk_lang_title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}",
349
447
  ".dsh_desk_lang_desc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}",
350
448
  ".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}",
351
449
  ".dsh_desk_lang_picker:hover{background:var(--dsw-alias-interactive-bg-hover)}",
352
450
  ".dsh_desk_lang_chevron{flex:none}",
451
+ ".dsh_desk_lang_field{display:flex;flex-direction:column;align-items:flex-end;gap:4px}",
353
452
  ".dsh_desk_lang_control{align-items:center;gap:8px;display:flex;flex:none}",
354
453
  ".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}",
355
454
  ".dsh_desk_lang_hint{color:var(--dsw-alias-label-tertiary);font-size:12px;white-space:nowrap}"
@@ -3,10 +3,10 @@
3
3
  * 为宿主提供的 React 运行时声明最小环境类型。
4
4
  *
5
5
  * The plugin never bundles React — the DSH client module loader injects it — and
6
- * this package deliberately does not depend on `@types/react`, so only the three
6
+ * this package deliberately does not depend on `@types/react`, so only the
7
7
  * APIs the panel actually calls are declared here.
8
8
  * 本插件不打包 React(由 DSH 客户端模块加载器注入),且刻意不依赖
9
- * `@types/react`,因此这里只声明面板真正调用的三个 API。
9
+ * `@types/react`,因此这里只声明面板真正调用的 API。
10
10
  */
11
11
  declare module "react" {
12
12
  /**
@@ -25,6 +25,9 @@ declare module "react" {
25
25
  */
26
26
  export function useState<T>(initial: T | (() => T)): [T, (next: T | ((prev: T) => T)) => void];
27
27
 
28
+ /** Keep a mutable value across renders. / 在多次渲染之间保留可变值。 */
29
+ export function useRef<T>(initial: T): { current: T };
30
+
28
31
  /**
29
32
  * Run a side effect after render, optionally cleaning it up on unmount.
30
33
  * 在渲染后运行副作用,并可选地在卸载时清理。