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 +11 -12
- package/README.md +3 -3
- package/client/client.js +81 -46
- package/client/client.raw.cjs +81 -46
- package/lib/core.js +10 -9
- package/lib/index.d.ts +1 -0
- package/lib/index.js +45 -58
- package/package.json +1 -1
- package/src/client/locales.ts +8 -4
- package/src/client/panel.ts +94 -66
- package/src/client/react.d.ts +5 -2
- package/src/core.ts +9 -9
- package/src/index.ts +46 -62
package/lib/core.js
CHANGED
|
@@ -41,21 +41,21 @@ export const CATALOGUE = [
|
|
|
41
41
|
{
|
|
42
42
|
tag: "zh-CN",
|
|
43
43
|
nativeName: "简体中文",
|
|
44
|
-
section: "
|
|
44
|
+
section: "推理规则:思考、推理与规划一律使用简体中文。",
|
|
45
45
|
reminder: "注意:思考、推理与规划用简体中文,即使上文不是",
|
|
46
46
|
tail: "下文请使用简体中文思考"
|
|
47
47
|
},
|
|
48
48
|
{
|
|
49
49
|
tag: "zh-TW",
|
|
50
50
|
nativeName: "繁體中文",
|
|
51
|
-
section: "
|
|
51
|
+
section: "推理規則:思考、推理與規劃一律使用繁體中文。",
|
|
52
52
|
reminder: "注意:思考、推理與規劃用繁體中文,即使上文不是",
|
|
53
53
|
tail: "下文請使用繁體中文思考"
|
|
54
54
|
},
|
|
55
55
|
{
|
|
56
56
|
tag: "en",
|
|
57
57
|
nativeName: "English",
|
|
58
|
-
section: "Reasoning rules: think, reason, and plan in English.
|
|
58
|
+
section: "Reasoning rules: think, reason, and plan in English.",
|
|
59
59
|
reminder: "Note: think, reason, and plan in English, even if the text above is not",
|
|
60
60
|
tail: "Think in English from here on"
|
|
61
61
|
}
|
|
@@ -169,8 +169,8 @@ function candidatesOf(locale) {
|
|
|
169
169
|
* 手写地区对照表。
|
|
170
170
|
*/
|
|
171
171
|
function chineseTag(locale) {
|
|
172
|
-
const
|
|
173
|
-
return
|
|
172
|
+
const script = locale.script ?? locale.maximize().script;
|
|
173
|
+
return script === "Hant" ? CHINESE.traditional : CHINESE.simplified;
|
|
174
174
|
}
|
|
175
175
|
/**
|
|
176
176
|
* Map a locale onto a catalogue language tag.
|
|
@@ -180,12 +180,14 @@ function tagForLocale(raw) {
|
|
|
180
180
|
const locale = parseLocale(raw);
|
|
181
181
|
if (locale === undefined)
|
|
182
182
|
return undefined;
|
|
183
|
+
if (locale.language === "zh")
|
|
184
|
+
return chineseTag(locale);
|
|
183
185
|
for (const candidate of candidatesOf(locale)) {
|
|
184
186
|
const match = BY_TAG.get(candidate.toLowerCase());
|
|
185
187
|
if (match !== undefined)
|
|
186
188
|
return match.tag;
|
|
187
189
|
}
|
|
188
|
-
return
|
|
190
|
+
return undefined;
|
|
189
191
|
}
|
|
190
192
|
/**
|
|
191
193
|
* Coerce an untrusted settings section into a complete configuration.
|
|
@@ -196,10 +198,9 @@ function normalizeReminder(raw) {
|
|
|
196
198
|
const numeric = typeof raw === "number" ? raw : typeof raw === "string" && raw.trim() !== "" ? Number(raw) : NaN;
|
|
197
199
|
if (!Number.isFinite(numeric))
|
|
198
200
|
return DEFAULT_REMINDER_MINUTES;
|
|
199
|
-
|
|
200
|
-
if (rounded < 0)
|
|
201
|
+
if (numeric < 0)
|
|
201
202
|
return REMINDER_OFF;
|
|
202
|
-
return
|
|
203
|
+
return Math.max(REMINDER_EVERY_TURN, Math.min(MAX_REMINDER_MINUTES, Math.round(numeric)));
|
|
203
204
|
}
|
|
204
205
|
/** Coerce one untrusted extra-injection value; only an explicit false turns it off. / 把不可信的额外注入值收敛为布尔;只有明确的 false 视为关闭。 */
|
|
205
206
|
function normalizeExtra(raw) {
|
package/lib/index.d.ts
CHANGED
|
@@ -30,6 +30,7 @@ interface HostContext {
|
|
|
30
30
|
prepend?: boolean;
|
|
31
31
|
}): unknown;
|
|
32
32
|
on(event: "agent/created", listener: (payload: unknown) => unknown): unknown;
|
|
33
|
+
on(event: "settings/document-updated", listener: (namespace: string) => void): unknown;
|
|
33
34
|
systemPrompt: {
|
|
34
35
|
section(section: {
|
|
35
36
|
name: string;
|
package/lib/index.js
CHANGED
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
* section order 1 → the authoritative rule, once per session
|
|
9
9
|
* pre-step step 1 → a short reminder at the head of the batch, at most once per turn
|
|
10
10
|
* (interval configurable, default 30 min)
|
|
11
|
-
* pre-step step 1 → the closing rule, folded into the skill catalogue
|
|
12
|
-
* extra
|
|
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
|
|
13
13
|
*
|
|
14
14
|
* section order 1 → 权威规则,每会话组装一次
|
|
15
15
|
* pre-step step 1 → 批次开头的短提醒,每轮最多一次(间隔可配置,默认 30 分钟)
|
|
16
|
-
* pre-step step 1 →
|
|
16
|
+
* pre-step step 1 → 收尾规则,额外注入开启时折进技能目录,或独立发送
|
|
17
17
|
*
|
|
18
18
|
* The host context is described by a local structural interface rather than the
|
|
19
19
|
* `@deepseek-ai/cordis` type, so this package carries no DSH type dependency.
|
|
@@ -103,24 +103,13 @@ function buildSchema() {
|
|
|
103
103
|
export const Config = buildSchema();
|
|
104
104
|
/** Handed back while the settings service is unavailable or unreadable. / 设置服务不可用或读不出时交回的空表。 */
|
|
105
105
|
const NO_SECTIONS = new Map();
|
|
106
|
-
let snapshot;
|
|
107
|
-
/**
|
|
108
|
-
* Pull every namespace section out of the settings document.
|
|
109
|
-
* 从设置文档里取出各个命名空间的段。
|
|
110
|
-
*
|
|
111
|
-
* A section is a `{ns, value}` entry whose `value` is a plain object; anything
|
|
112
|
-
* else in the listing is not something this plugin can read, so it is skipped
|
|
113
|
-
* rather than coerced.
|
|
114
|
-
* 一个段就是 `value` 为普通对象的 `{ns, value}` 条目;列表里其它形状不是本插件能读
|
|
115
|
-
* 的东西,因此跳过而不做强制转换。
|
|
116
|
-
*/
|
|
117
106
|
/**
|
|
118
107
|
* Call `describe()` without letting a throwing host escape.
|
|
119
108
|
* 调用 `describe()`,不让抛异常的宿主逃逸出去。
|
|
120
109
|
*/
|
|
121
110
|
function described(settings) {
|
|
122
111
|
try {
|
|
123
|
-
return settings.describe();
|
|
112
|
+
return settings.describe({ redactSecrets: true });
|
|
124
113
|
}
|
|
125
114
|
catch {
|
|
126
115
|
return undefined;
|
|
@@ -142,42 +131,28 @@ function asSection(value) {
|
|
|
142
131
|
return value;
|
|
143
132
|
}
|
|
144
133
|
function collect(settings) {
|
|
145
|
-
const found = new Map();
|
|
146
134
|
const listed = described(settings);
|
|
147
135
|
if (!Array.isArray(listed))
|
|
148
|
-
return
|
|
136
|
+
return undefined;
|
|
137
|
+
const found = new Map();
|
|
149
138
|
for (const item of listed) {
|
|
150
|
-
const
|
|
151
|
-
const
|
|
152
|
-
if (
|
|
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)
|
|
153
145
|
found.set(ns, section);
|
|
154
146
|
}
|
|
155
147
|
return found;
|
|
156
148
|
}
|
|
157
|
-
/**
|
|
158
|
-
* Read the namespace sections, reusing one read for a short while.
|
|
159
|
-
* 读取各命名空间的段,并在很短的时间内复用同一次读取。
|
|
160
|
-
*
|
|
161
|
-
* The cache exists because prompt assembly asks on every model step, while
|
|
162
|
-
* `describe()` walks the whole settings document each time.
|
|
163
|
-
* 缓存的存在是因为提示词组装每一步都会问,而 `describe()` 每次都要遍历整份设置文档。
|
|
164
|
-
*/
|
|
165
|
-
function sectionsOf(settings) {
|
|
166
|
-
if (!settings || typeof settings.describe !== "function")
|
|
167
|
-
return NO_SECTIONS;
|
|
168
|
-
const now = Date.now();
|
|
169
|
-
if (snapshot === undefined || now - snapshot.takenAt >= SETTINGS_TTL_MS) {
|
|
170
|
-
snapshot = { takenAt: now, sections: collect(settings) };
|
|
171
|
-
}
|
|
172
|
-
return snapshot.sections;
|
|
173
|
-
}
|
|
174
149
|
/**
|
|
175
150
|
* Adapt the settings service to the `get()`-style handle the core reads from.
|
|
176
151
|
* 把设置服务适配成核心代码所用的 `get()` 风格句柄。
|
|
177
152
|
*/
|
|
178
|
-
function settingsReader(
|
|
153
|
+
function settingsReader(sections) {
|
|
179
154
|
return {
|
|
180
|
-
get: (ns) =>
|
|
155
|
+
get: (ns = SETTINGS_NAMESPACE) => sections.get(ns)
|
|
181
156
|
};
|
|
182
157
|
}
|
|
183
158
|
/**
|
|
@@ -264,24 +239,17 @@ function prefixPrompt(message, text) {
|
|
|
264
239
|
return { ...message, content: [{ type: "text", text: `${text}\n` }, ...content] };
|
|
265
240
|
}
|
|
266
241
|
/**
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
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
|
+
* 回退的那条落在全部注入消息之后,因此没有技能目录时,收尾规则仍是模型最后读到的一句。
|
|
271
248
|
*/
|
|
272
|
-
function
|
|
273
|
-
|
|
274
|
-
if (index < 0) {
|
|
275
|
-
for (let cursor = messages.length - 1; cursor >= 0; cursor -= 1) {
|
|
276
|
-
const source = messages[cursor].source;
|
|
277
|
-
if (messages[cursor].role === "user" && source?.kind !== name) {
|
|
278
|
-
index = cursor;
|
|
279
|
-
break;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
249
|
+
function withClosingReminder(messages, text) {
|
|
250
|
+
const index = messages.findIndex((message) => asSection(message.source)?.kind === "skill-catalog");
|
|
283
251
|
if (index < 0)
|
|
284
|
-
return messages;
|
|
252
|
+
return [...messages, reminderMessage(text)];
|
|
285
253
|
const next = [...messages];
|
|
286
254
|
next[index] = prefixPrompt(messages[index], text);
|
|
287
255
|
return next;
|
|
@@ -294,7 +262,26 @@ export function apply(ctx) {
|
|
|
294
262
|
/** Latest reminder time per session, in process memory. / 每个会话最近一次提醒时间,存于进程内存。 */
|
|
295
263
|
const lastReminderAt = new Map();
|
|
296
264
|
ctx.inject(["systemPrompt", "settings"], (promptCtx) => {
|
|
297
|
-
|
|
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
|
+
};
|
|
298
285
|
// The text thunk is re-evaluated per assembly, so the section always
|
|
299
286
|
// reflects the newest setting without re-registering anything.
|
|
300
287
|
// 文本 thunk 每次组装都会重新求值,因此该段始终反映最新设置,无需重新注册。
|
|
@@ -309,7 +296,7 @@ export function apply(ctx) {
|
|
|
309
296
|
*/
|
|
310
297
|
const rewrite = async (payload, next) => {
|
|
311
298
|
const decision = await next();
|
|
312
|
-
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)
|
|
313
300
|
return decision;
|
|
314
301
|
const settings = currentSettings(reader());
|
|
315
302
|
const delay = reminderDelayMs(settings.reminderMinutes);
|
|
@@ -327,7 +314,7 @@ export function apply(ctx) {
|
|
|
327
314
|
// reminder off skips this whole listener, so both injections stop together.
|
|
328
315
|
// 收尾规则与提醒共用一个开关:提醒关闭时本段不执行,两处注入一起停。
|
|
329
316
|
const tail = settings.extraInjection ? tailText(settings.language) : "";
|
|
330
|
-
const messages = tail === "" ? decision.messages :
|
|
317
|
+
const messages = tail === "" ? decision.messages : withClosingReminder(decision.messages, tail);
|
|
331
318
|
return { ...decision, messages: [reminderMessage(head), ...messages] };
|
|
332
319
|
};
|
|
333
320
|
/**
|
package/package.json
CHANGED
package/src/client/locales.ts
CHANGED
|
@@ -37,6 +37,8 @@ export interface Dict {
|
|
|
37
37
|
extraOn: string;
|
|
38
38
|
/** Label of the disabled option. / 关闭选项的标签。 */
|
|
39
39
|
extraOff: string;
|
|
40
|
+
/** Message shown when a write fails. / 写入失败时显示的提示。 */
|
|
41
|
+
saveError: string;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
/** Simplified Chinese copy. / 简体中文文案。 */
|
|
@@ -52,9 +54,10 @@ export const zh: Dict = {
|
|
|
52
54
|
reminderUnit: "分钟",
|
|
53
55
|
reminderCustomHint: "1–1440 分钟",
|
|
54
56
|
extraHeading: "额外提醒注入",
|
|
55
|
-
extraDescription: "
|
|
57
|
+
extraDescription: "把额外提醒放进本轮技能目录,没有新目录时独立发送。提醒间隔为「关闭」时停用。",
|
|
56
58
|
extraOn: "开启",
|
|
57
|
-
extraOff: "关闭"
|
|
59
|
+
extraOff: "关闭",
|
|
60
|
+
saveError: "设置未能保存,请重试。"
|
|
58
61
|
};
|
|
59
62
|
|
|
60
63
|
/** English copy. / 英文文案。 */
|
|
@@ -72,9 +75,10 @@ export const en: Dict = {
|
|
|
72
75
|
reminderCustomHint: "1–1440 minutes",
|
|
73
76
|
extraHeading: "Extra reminder injection",
|
|
74
77
|
extraDescription:
|
|
75
|
-
"
|
|
78
|
+
"Adds a reminder to the skill catalogue, or sends it separately if no catalogue is sent. Turning reminders off also turns this off.",
|
|
76
79
|
extraOn: "On",
|
|
77
|
-
extraOff: "Off"
|
|
80
|
+
extraOff: "Off",
|
|
81
|
+
saveError: "Could not save this setting. Try again."
|
|
78
82
|
};
|
|
79
83
|
|
|
80
84
|
/** Dictionaries keyed by UI locale, handed to the host locale service. / 以界面语言为键、交给宿主 locale 服务的字典。 */
|
package/src/client/panel.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
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,
|
|
@@ -30,8 +30,7 @@ import type { Dict } from "./locales.js";
|
|
|
30
30
|
export interface SettingsDoc {
|
|
31
31
|
getSnapshot(): { value?: unknown; revision?: number };
|
|
32
32
|
subscribe(listener: () => void): () => void;
|
|
33
|
-
set(field: string, value: unknown):
|
|
34
|
-
unset(field: string): unknown;
|
|
33
|
+
set(field: string, value: unknown): Promise<boolean>;
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
/** UI primitives this plugin can use when the host provides them. / 宿主提供时本插件可用的 UI 原语。 */
|
|
@@ -66,18 +65,41 @@ function readSettings(doc: SettingsDoc): ThinkingSettings {
|
|
|
66
65
|
}
|
|
67
66
|
|
|
68
67
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
68
|
+
* Show the result of the latest write for a field.
|
|
69
|
+
* 显示该字段最近一次写入的结果。
|
|
71
70
|
*/
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
+
// 传输失败后,表单仍显示上一次已确认的设置。
|
|
77
90
|
}
|
|
78
|
-
|
|
79
|
-
/* a read-only settings document is not an error worth surfacing here */
|
|
91
|
+
if (attempted === generation.current) setFailed(!accepted);
|
|
80
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
|
+
);
|
|
81
103
|
}
|
|
82
104
|
|
|
83
105
|
/** Subscribe one component to the document and re-read it on every revision. / 订阅设置文档,并在每次修订时重新读取。 */
|
|
@@ -105,6 +127,7 @@ function createLanguagePicker(primitives: UiPrimitives | undefined) {
|
|
|
105
127
|
return function LanguagePicker(props: Binding & { settings: ThinkingSettings }): unknown {
|
|
106
128
|
const { doc, t, settings } = props;
|
|
107
129
|
const [open, setOpen] = useState<boolean>(false);
|
|
130
|
+
const { failed, save } = useSettingWriter(doc, FIELD_LANGUAGE);
|
|
108
131
|
const items = [
|
|
109
132
|
{ id: AUTO, label: t("autoLabel") },
|
|
110
133
|
...CATALOGUE.map((language) => ({ id: language.tag, label: language.nativeName }))
|
|
@@ -113,7 +136,7 @@ function createLanguagePicker(primitives: UiPrimitives | undefined) {
|
|
|
113
136
|
settings.language === AUTO ? t("autoLabel") : nativeNameFor(settings.language) ?? settings.language;
|
|
114
137
|
const close = (): void => setOpen(false);
|
|
115
138
|
const choose = (id: string): void => {
|
|
116
|
-
|
|
139
|
+
void save(id);
|
|
117
140
|
close();
|
|
118
141
|
};
|
|
119
142
|
const picker = h(
|
|
@@ -128,17 +151,19 @@ function createLanguagePicker(primitives: UiPrimitives | undefined) {
|
|
|
128
151
|
activeLabel,
|
|
129
152
|
Chevron === undefined ? null : h(Chevron, { className: "dsh_desk_lang_chevron" })
|
|
130
153
|
);
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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);
|
|
142
167
|
};
|
|
143
168
|
}
|
|
144
169
|
|
|
@@ -168,26 +193,18 @@ function createReminderPicker(primitives: UiPrimitives | undefined) {
|
|
|
168
193
|
|
|
169
194
|
return function ReminderPicker(props: Binding & { settings: ThinkingSettings }): unknown {
|
|
170
195
|
const { doc, t, settings } = props;
|
|
171
|
-
const
|
|
172
|
-
const
|
|
173
|
-
const
|
|
196
|
+
const minutes = settings.reminderMinutes;
|
|
197
|
+
const selected = derivedPreset(minutes);
|
|
198
|
+
const current = minutes > 0 ? minutes : DEFAULTS.reminderMinutes;
|
|
199
|
+
const [editingCustom, setEditingCustom] = useState(false);
|
|
174
200
|
const [open, setOpen] = useState<boolean>(false);
|
|
175
201
|
const [draft, setDraft] = useState<string>(String(current));
|
|
202
|
+
const { failed, save } = useSettingWriter(doc, FIELD_REMINDER);
|
|
176
203
|
|
|
177
|
-
// An external change (the other surface, or a re-read) wins over a local
|
|
178
|
-
// selection; a local "custom" survives because it leaves `derived` alone.
|
|
179
|
-
// 外部改动(另一入口或重新读取)优先于本地选择;本地的「自定义」不会改变
|
|
180
|
-
// `derived`,因此能保持选中。
|
|
181
|
-
useEffect(() => {
|
|
182
|
-
setSelected(derived);
|
|
183
|
-
}, [derived]);
|
|
184
|
-
|
|
185
|
-
// Keep the input in step with the stored value, so an accepted edit never
|
|
186
|
-
// falls back to the previous number while the document update lands.
|
|
187
|
-
// 让输入框跟随存储值,避免写入落盘前先闪回上一个数字。
|
|
188
204
|
useEffect(() => {
|
|
189
205
|
setDraft(String(current));
|
|
190
|
-
|
|
206
|
+
setEditingCustom(false);
|
|
207
|
+
}, [current, doc, minutes]);
|
|
191
208
|
|
|
192
209
|
const labelOf = (id: string): string => {
|
|
193
210
|
if (id === "off") return t("reminderOff");
|
|
@@ -203,21 +220,23 @@ function createReminderPicker(primitives: UiPrimitives | undefined) {
|
|
|
203
220
|
|
|
204
221
|
const choose = (id: string): void => {
|
|
205
222
|
setOpen(false);
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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);
|
|
210
228
|
};
|
|
211
229
|
|
|
212
230
|
const commit = (): void => {
|
|
213
|
-
const
|
|
214
|
-
if (!Number.isFinite(
|
|
231
|
+
const parsed = Math.round(Number(draft));
|
|
232
|
+
if (!Number.isFinite(parsed) || draft.trim() === "") {
|
|
215
233
|
setDraft(String(current));
|
|
216
234
|
return;
|
|
217
235
|
}
|
|
218
|
-
const clamped = Math.min(MAX_REMINDER_MINUTES, Math.max(1,
|
|
219
|
-
writeField(doc, FIELD_REMINDER, clamped);
|
|
236
|
+
const clamped = Math.min(MAX_REMINDER_MINUTES, Math.max(1, parsed));
|
|
220
237
|
setDraft(String(clamped));
|
|
238
|
+
if (clamped === minutes) setEditingCustom(false);
|
|
239
|
+
void save(clamped);
|
|
221
240
|
};
|
|
222
241
|
|
|
223
242
|
const picker = h(
|
|
@@ -246,8 +265,8 @@ function createReminderPicker(primitives: UiPrimitives | undefined) {
|
|
|
246
265
|
})
|
|
247
266
|
: picker;
|
|
248
267
|
|
|
249
|
-
if (selected !== "custom") return control;
|
|
250
|
-
|
|
268
|
+
if (!editingCustom && selected !== "custom") return pickerWithError(control, failed, t);
|
|
269
|
+
const editor = h(
|
|
251
270
|
"div",
|
|
252
271
|
{ className: "dsh_desk_lang_control" },
|
|
253
272
|
control,
|
|
@@ -256,16 +275,21 @@ function createReminderPicker(primitives: UiPrimitives | undefined) {
|
|
|
256
275
|
className: "dsh_desk_lang_input",
|
|
257
276
|
min: 1,
|
|
258
277
|
max: MAX_REMINDER_MINUTES,
|
|
259
|
-
|
|
278
|
+
"aria-label": t("reminderHeading"),
|
|
279
|
+
placeholder: String(current),
|
|
260
280
|
value: draft,
|
|
261
281
|
onChange: (event: { currentTarget: { value: string } }): void => setDraft(event.currentTarget.value),
|
|
262
282
|
onBlur: commit,
|
|
263
|
-
onKeyDown: (event: { key: string }): void => {
|
|
264
|
-
if (event.key === "Enter")
|
|
283
|
+
onKeyDown: (event: { key: string; currentTarget: HTMLInputElement; preventDefault(): void }): void => {
|
|
284
|
+
if (event.key === "Enter") {
|
|
285
|
+
event.preventDefault();
|
|
286
|
+
event.currentTarget.blur();
|
|
287
|
+
}
|
|
265
288
|
}
|
|
266
289
|
}),
|
|
267
290
|
h("span", { className: "dsh_desk_lang_hint" }, t("reminderCustomHint"))
|
|
268
291
|
);
|
|
292
|
+
return pickerWithError(editor, failed, t);
|
|
269
293
|
};
|
|
270
294
|
}
|
|
271
295
|
|
|
@@ -286,13 +310,14 @@ function createExtraPicker(primitives: UiPrimitives | undefined) {
|
|
|
286
310
|
return function ExtraPicker(props: Binding & { settings: ThinkingSettings; disabled?: boolean }): unknown {
|
|
287
311
|
const { doc, t, settings, disabled = false } = props;
|
|
288
312
|
const [open, setOpen] = useState<boolean>(false);
|
|
313
|
+
const { failed, save } = useSettingWriter(doc, FIELD_EXTRA);
|
|
289
314
|
const items = [
|
|
290
315
|
{ id: "on", label: t("extraOn") },
|
|
291
316
|
{ id: "off", label: t("extraOff") }
|
|
292
317
|
];
|
|
293
318
|
const close = (): void => setOpen(false);
|
|
294
319
|
const choose = (id: string): void => {
|
|
295
|
-
|
|
320
|
+
if (!disabled) void save(id === "on");
|
|
296
321
|
close();
|
|
297
322
|
};
|
|
298
323
|
const picker = h(
|
|
@@ -308,17 +333,19 @@ function createExtraPicker(primitives: UiPrimitives | undefined) {
|
|
|
308
333
|
settings.extraInjection ? t("extraOn") : t("extraOff"),
|
|
309
334
|
Chevron === undefined ? null : h(Chevron, { className: "dsh_desk_lang_chevron" })
|
|
310
335
|
);
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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);
|
|
322
349
|
};
|
|
323
350
|
}
|
|
324
351
|
|
|
@@ -409,9 +436,9 @@ export function createConfigCard(primitives: UiPrimitives | undefined): (props:
|
|
|
409
436
|
// packages/client/ui-chat/src/client/settings/PreferenceRow.module.css, MIT,
|
|
410
437
|
// Copyright (c) 2026 DeepSeek — because that is the row this one sits beside.
|
|
411
438
|
// Class names differ (the host's are CSS-Modules hashes) and the picker carries a
|
|
412
|
-
// trailing `flex:none` the host does not need
|
|
439
|
+
// trailing `flex:none` the host does not need. The form adds styles for its own controls.
|
|
413
440
|
// 声明顺序逐字照宿主自己的 PreferenceRow——因为那就是本行紧邻的邻居。类名不同,
|
|
414
|
-
// 选择器末尾多一个宿主不需要的 `flex:none
|
|
441
|
+
// 选择器末尾多一个宿主不需要的 `flex:none`。表单还定义了自身控件的样式。
|
|
415
442
|
const rowCss = [
|
|
416
443
|
".dsh_desk_lang_row{border-bottom:.5px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}",
|
|
417
444
|
".dsh_desk_lang_row_disabled{opacity:.45;pointer-events:none}",
|
|
@@ -421,6 +448,7 @@ const rowCss = [
|
|
|
421
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}",
|
|
422
449
|
".dsh_desk_lang_picker:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
423
450
|
".dsh_desk_lang_chevron{flex:none}",
|
|
451
|
+
".dsh_desk_lang_field{display:flex;flex-direction:column;align-items:flex-end;gap:4px}",
|
|
424
452
|
".dsh_desk_lang_control{align-items:center;gap:8px;display:flex;flex:none}",
|
|
425
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}",
|
|
426
454
|
".dsh_desk_lang_hint{color:var(--dsw-alias-label-tertiary);font-size:12px;white-space:nowrap}"
|
package/src/client/react.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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
|
* 在渲染后运行副作用,并可选地在卸载时清理。
|
package/src/core.ts
CHANGED
|
@@ -56,21 +56,21 @@ export const CATALOGUE: readonly Language[] = [
|
|
|
56
56
|
{
|
|
57
57
|
tag: "zh-CN",
|
|
58
58
|
nativeName: "简体中文",
|
|
59
|
-
section: "
|
|
59
|
+
section: "推理规则:思考、推理与规划一律使用简体中文。",
|
|
60
60
|
reminder: "注意:思考、推理与规划用简体中文,即使上文不是",
|
|
61
61
|
tail: "下文请使用简体中文思考"
|
|
62
62
|
},
|
|
63
63
|
{
|
|
64
64
|
tag: "zh-TW",
|
|
65
65
|
nativeName: "繁體中文",
|
|
66
|
-
section: "
|
|
66
|
+
section: "推理規則:思考、推理與規劃一律使用繁體中文。",
|
|
67
67
|
reminder: "注意:思考、推理與規劃用繁體中文,即使上文不是",
|
|
68
68
|
tail: "下文請使用繁體中文思考"
|
|
69
69
|
},
|
|
70
70
|
{
|
|
71
71
|
tag: "en",
|
|
72
72
|
nativeName: "English",
|
|
73
|
-
section: "Reasoning rules: think, reason, and plan in English.
|
|
73
|
+
section: "Reasoning rules: think, reason, and plan in English.",
|
|
74
74
|
reminder: "Note: think, reason, and plan in English, even if the text above is not",
|
|
75
75
|
tail: "Think in English from here on"
|
|
76
76
|
}
|
|
@@ -220,8 +220,8 @@ function candidatesOf(locale: Intl.Locale): string[] {
|
|
|
220
220
|
* 手写地区对照表。
|
|
221
221
|
*/
|
|
222
222
|
function chineseTag(locale: Intl.Locale): string {
|
|
223
|
-
const
|
|
224
|
-
return
|
|
223
|
+
const script = locale.script ?? locale.maximize().script;
|
|
224
|
+
return script === "Hant" ? CHINESE.traditional : CHINESE.simplified;
|
|
225
225
|
}
|
|
226
226
|
|
|
227
227
|
/**
|
|
@@ -231,11 +231,12 @@ function chineseTag(locale: Intl.Locale): string {
|
|
|
231
231
|
function tagForLocale(raw: unknown): string | undefined {
|
|
232
232
|
const locale = parseLocale(raw);
|
|
233
233
|
if (locale === undefined) return undefined;
|
|
234
|
+
if (locale.language === "zh") return chineseTag(locale);
|
|
234
235
|
for (const candidate of candidatesOf(locale)) {
|
|
235
236
|
const match = BY_TAG.get(candidate.toLowerCase());
|
|
236
237
|
if (match !== undefined) return match.tag;
|
|
237
238
|
}
|
|
238
|
-
return
|
|
239
|
+
return undefined;
|
|
239
240
|
}
|
|
240
241
|
|
|
241
242
|
/**
|
|
@@ -246,9 +247,8 @@ function tagForLocale(raw: unknown): string | undefined {
|
|
|
246
247
|
function normalizeReminder(raw: unknown): number {
|
|
247
248
|
const numeric = typeof raw === "number" ? raw : typeof raw === "string" && raw.trim() !== "" ? Number(raw) : NaN;
|
|
248
249
|
if (!Number.isFinite(numeric)) return DEFAULT_REMINDER_MINUTES;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
return rounded > MAX_REMINDER_MINUTES ? MAX_REMINDER_MINUTES : rounded;
|
|
250
|
+
if (numeric < 0) return REMINDER_OFF;
|
|
251
|
+
return Math.max(REMINDER_EVERY_TURN, Math.min(MAX_REMINDER_MINUTES, Math.round(numeric)));
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
/** Coerce one untrusted extra-injection value; only an explicit false turns it off. / 把不可信的额外注入值收敛为布尔;只有明确的 false 视为关闭。 */
|