dsh-thinking-lang 1.0.5 → 1.0.7
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 +156 -0
- package/README.md +26 -178
- package/assets/plugin-config.png +0 -0
- package/assets/settings-general.png +0 -0
- package/client/client.js +231 -51
- package/client/client.raw.cjs +231 -51
- package/lib/core.d.ts +25 -4
- package/lib/core.js +43 -6
- package/lib/index.js +21 -13
- package/package.json +3 -1
- package/src/client/index.ts +32 -1
- package/src/client/locales.ts +37 -61
- package/src/client/panel.ts +232 -72
- package/src/core.ts +53 -6
- package/src/index.ts +23 -13
package/client/client.raw.cjs
CHANGED
|
@@ -37,11 +37,18 @@ const CATALOGUE = [
|
|
|
37
37
|
const AUTO = "auto";
|
|
38
38
|
/** Settings namespace owned by this plugin. / 本插件拥有的设置命名空间。 */
|
|
39
39
|
const SETTINGS_NAMESPACE = "ay-dsh-tk-lang";
|
|
40
|
-
/** The
|
|
40
|
+
/** The language field this plugin stores. / 本插件保存的语言字段。 */
|
|
41
41
|
const FIELD_LANGUAGE = "language";
|
|
42
|
+
/** The reminder field this plugin stores. / 本插件保存的提醒字段。 */
|
|
43
|
+
const FIELD_REMINDER = "reminderMinutes";
|
|
44
|
+
/** Largest accepted reminder interval. / 允许的最大提醒间隔(分钟)。 */
|
|
45
|
+
const MAX_REMINDER_MINUTES = 1440;
|
|
42
46
|
CATALOGUE.map((language) => language.tag);
|
|
43
|
-
/** Configuration applied when the
|
|
44
|
-
const DEFAULTS = {
|
|
47
|
+
/** Configuration applied when the fields are absent. / 字段缺失时采用的配置。 */
|
|
48
|
+
const DEFAULTS = {
|
|
49
|
+
language: AUTO,
|
|
50
|
+
reminderMinutes: 30
|
|
51
|
+
};
|
|
45
52
|
/** Catalogue lookup keyed by lower-cased tag. / 以小写标签为键的目录索引。 */
|
|
46
53
|
const BY_TAG = new Map(CATALOGUE.map((language) => [language.tag.toLowerCase(), language]));
|
|
47
54
|
/**
|
|
@@ -63,38 +70,68 @@ function nativeNameFor(tag) {
|
|
|
63
70
|
* Coerce an untrusted settings section into a complete configuration.
|
|
64
71
|
* 把不可信的设置段强制转换为完整配置。
|
|
65
72
|
*/
|
|
73
|
+
/** Clamp one untrusted reminder value into the accepted range; any negative value disables it. / 把不可信的提醒值收敛到允许范围;负数一律视为关闭。 */
|
|
74
|
+
function normalizeReminder(raw) {
|
|
75
|
+
const numeric = typeof raw === "number" ? raw : typeof raw === "string" && raw.trim() !== "" ? Number(raw) : NaN;
|
|
76
|
+
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;
|
|
80
|
+
}
|
|
66
81
|
function normalizeSettings(raw) {
|
|
67
|
-
const
|
|
68
|
-
|
|
82
|
+
const section = raw !== null && typeof raw === "object" && !Array.isArray(raw) ? raw : void 0;
|
|
83
|
+
const stored = section?.[FIELD_LANGUAGE];
|
|
84
|
+
return {
|
|
85
|
+
language: typeof stored === "string" && stored !== "" ? stored : DEFAULTS.language,
|
|
86
|
+
reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER])
|
|
87
|
+
};
|
|
69
88
|
}
|
|
70
89
|
/** Dictionaries keyed by UI locale, handed to the host locale service. / 以界面语言为键、交给宿主 locale 服务的字典。 */
|
|
71
90
|
const dictionaries = {
|
|
72
91
|
zh: {
|
|
73
92
|
heading: "思考语言",
|
|
74
93
|
description: "内部推理与规划使用的语言。「自动」优先跟随操作系统语言,其次是界面语言。",
|
|
75
|
-
autoLabel: "自动"
|
|
94
|
+
autoLabel: "自动",
|
|
95
|
+
reminderHeading: "提醒间隔",
|
|
96
|
+
reminderDescription: "两次提醒之间的最小间隔;关闭后只保留系统提示里的规则。",
|
|
97
|
+
reminderOff: "关闭",
|
|
98
|
+
reminderTurn: "每轮",
|
|
99
|
+
reminderCustom: "自定义",
|
|
100
|
+
reminderUnit: "分钟",
|
|
101
|
+
reminderCustomHint: "1–1440 分钟"
|
|
76
102
|
},
|
|
77
103
|
en: {
|
|
78
104
|
heading: "Thinking language",
|
|
79
105
|
description: "Language used for internal reasoning and planning. Automatic follows the operating-system language first, then the UI language.",
|
|
80
|
-
autoLabel: "Automatic"
|
|
106
|
+
autoLabel: "Automatic",
|
|
107
|
+
reminderHeading: "Reminder interval",
|
|
108
|
+
reminderDescription: "Minimum gap between reminders. Off keeps only the system-prompt rule.",
|
|
109
|
+
reminderOff: "Off",
|
|
110
|
+
reminderTurn: "Every turn",
|
|
111
|
+
reminderCustom: "Custom",
|
|
112
|
+
reminderUnit: "min",
|
|
113
|
+
reminderCustomHint: "1–1440 minutes"
|
|
81
114
|
}
|
|
82
115
|
};
|
|
83
116
|
//#endregion
|
|
84
117
|
//#region src/client/panel.ts
|
|
85
118
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
119
|
+
* Settings UI: the General row and the plugin's configuration card.
|
|
120
|
+
* 设置界面:「通用」页的设置行,以及插件详情页的配置卡片。
|
|
88
121
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
* 语言设置项下方。
|
|
122
|
+
* Both surfaces bind to the same host settings document, so a change in either
|
|
123
|
+
* place is visible in the other. / 两个入口绑定同一份宿主设置文档,任一处修改
|
|
124
|
+
* 另一处都会看到。
|
|
93
125
|
*
|
|
94
|
-
* The row owns no state of its own: it reads the
|
|
95
|
-
*
|
|
96
|
-
* 本行不持有自己的状态:它读取宿主的设置文档、订阅其变化,并回写那唯一一个字段。
|
|
126
|
+
* The row owns no state of its own: it reads the document, subscribes to it, and
|
|
127
|
+
* writes the fields back. / 控件不持有自己的状态:读取文档、订阅变化、回写字段。
|
|
97
128
|
*/
|
|
129
|
+
/** Preset reminder intervals in minutes. / 预设提醒间隔(分钟)。 */
|
|
130
|
+
const PRESET_MINUTES = [
|
|
131
|
+
10,
|
|
132
|
+
30,
|
|
133
|
+
60
|
|
134
|
+
];
|
|
98
135
|
/**
|
|
99
136
|
* Read and normalize the current settings, falling back to defaults on refusal.
|
|
100
137
|
* 读取并归一化当前设置;被拒绝时回退到默认值。
|
|
@@ -107,12 +144,8 @@ function readSettings(doc) {
|
|
|
107
144
|
}
|
|
108
145
|
}
|
|
109
146
|
/**
|
|
110
|
-
* Write one field back, swallowing a refusal so a read-only host cannot break the
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* A host may return a promise instead of a value; an unhandled rejection from a
|
|
114
|
-
* read-only document is not worth surfacing, so it is discarded here.
|
|
115
|
-
* 宿主可能返回 promise 而不是值;只读文档产生的未处理拒绝不值得上抛,因此在此丢弃。
|
|
147
|
+
* Write one field back, swallowing a refusal so a read-only host cannot break the UI.
|
|
148
|
+
* 回写单个字段,并吞掉拒绝异常,使只读宿主不会让控件崩溃。
|
|
116
149
|
*/
|
|
117
150
|
function writeField(doc, field, value) {
|
|
118
151
|
try {
|
|
@@ -120,24 +153,26 @@ function writeField(doc, field, value) {
|
|
|
120
153
|
if (typeof outcome?.then === "function") outcome.then(void 0, () => {});
|
|
121
154
|
} catch {}
|
|
122
155
|
}
|
|
156
|
+
/** Subscribe one component to the document and re-read it on every revision. / 订阅设置文档,并在每次修订时重新读取。 */
|
|
157
|
+
function useSettings(doc) {
|
|
158
|
+
const [settings, setSettings] = (0, react.useState)(() => readSettings(doc));
|
|
159
|
+
(0, react.useEffect)(() => {
|
|
160
|
+
const sync = () => setSettings(readSettings(doc));
|
|
161
|
+
sync();
|
|
162
|
+
return doc.subscribe(sync);
|
|
163
|
+
}, [doc]);
|
|
164
|
+
return settings;
|
|
165
|
+
}
|
|
123
166
|
/**
|
|
124
|
-
* Build the
|
|
125
|
-
* 构建绑定到宿主 UI
|
|
167
|
+
* Build the language picker bound to the host's UI primitives.
|
|
168
|
+
* 构建绑定到宿主 UI 原语的语言选择器。
|
|
126
169
|
*/
|
|
127
|
-
function
|
|
170
|
+
function createLanguagePicker(primitives) {
|
|
128
171
|
const Menu = primitives?.Menu;
|
|
129
172
|
const Chevron = primitives?.IconChevronDownOutlineRegular ?? primitives?.IconChevronDownOutline14 ?? primitives?.IconChevronDownOutlineMedium;
|
|
130
|
-
return function
|
|
131
|
-
const { doc, t
|
|
132
|
-
const [settings, setSettings] = (0, react.useState)(() => readSettings(doc));
|
|
173
|
+
return function LanguagePicker(props) {
|
|
174
|
+
const { doc, t, settings } = props;
|
|
133
175
|
const [open, setOpen] = (0, react.useState)(false);
|
|
134
|
-
settings.language;
|
|
135
|
-
const t = (key) => hostT(key);
|
|
136
|
-
(0, react.useEffect)(() => {
|
|
137
|
-
const sync = () => setSettings(readSettings(doc));
|
|
138
|
-
sync();
|
|
139
|
-
return doc.subscribe(sync);
|
|
140
|
-
}, [doc]);
|
|
141
176
|
const items = [{
|
|
142
177
|
id: AUTO,
|
|
143
178
|
label: t("autoLabel")
|
|
@@ -147,7 +182,6 @@ function createRow(primitives) {
|
|
|
147
182
|
}))];
|
|
148
183
|
const activeLabel = settings.language === "auto" ? t("autoLabel") : nativeNameFor(settings.language) ?? settings.language;
|
|
149
184
|
const close = () => setOpen(false);
|
|
150
|
-
const toggle = () => setOpen((value) => !value);
|
|
151
185
|
const choose = (id) => {
|
|
152
186
|
writeField(doc, FIELD_LANGUAGE, id);
|
|
153
187
|
close();
|
|
@@ -157,9 +191,10 @@ function createRow(primitives) {
|
|
|
157
191
|
className: "dsh_desk_lang_picker",
|
|
158
192
|
"aria-haspopup": "menu",
|
|
159
193
|
"aria-expanded": open,
|
|
160
|
-
onClick:
|
|
194
|
+
onClick: () => setOpen((value) => !value)
|
|
161
195
|
}, activeLabel, Chevron === void 0 ? null : (0, react.createElement)(Chevron, { className: "dsh_desk_lang_chevron" }));
|
|
162
|
-
|
|
196
|
+
if (!Menu) return picker;
|
|
197
|
+
return (0, react.createElement)(Menu, {
|
|
163
198
|
open,
|
|
164
199
|
anchor: picker,
|
|
165
200
|
items,
|
|
@@ -168,8 +203,142 @@ function createRow(primitives) {
|
|
|
168
203
|
portal: true,
|
|
169
204
|
onClose: close,
|
|
170
205
|
onSelect: choose
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/** Map a stored minute count onto the picker id it should show. / 把存储的分钟数映射成选择器应显示的选项 id。 */
|
|
210
|
+
function derivedPreset(minutes) {
|
|
211
|
+
if (minutes < 0) return "off";
|
|
212
|
+
if (minutes === 0) return "turn";
|
|
213
|
+
const preset = PRESET_MINUTES.find((candidate) => candidate === minutes);
|
|
214
|
+
return preset === void 0 ? "custom" : String(preset);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Build the reminder picker: presets, every turn, off, and a custom minute count.
|
|
218
|
+
* 构建提醒选择器:预设、每轮、关闭,以及自定义分钟数。
|
|
219
|
+
*
|
|
220
|
+
* It uses the host Menu like the language picker, so the two controls match;
|
|
221
|
+
* a native `<select>` renders its own list chrome and breaks the row style.
|
|
222
|
+
* 与语言选择器一样使用宿主 Menu,两个控件因此外观一致;原生 `<select>` 的下拉列表
|
|
223
|
+
* 自带浏览器样式,会破坏这一行。
|
|
224
|
+
*/
|
|
225
|
+
function createReminderPicker(primitives) {
|
|
226
|
+
const Menu = primitives?.Menu;
|
|
227
|
+
const Chevron = primitives?.IconChevronDownOutlineRegular ?? primitives?.IconChevronDownOutline14 ?? primitives?.IconChevronDownOutlineMedium;
|
|
228
|
+
return function ReminderPicker(props) {
|
|
229
|
+
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);
|
|
233
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
234
|
+
const [draft, setDraft] = (0, react.useState)(String(current));
|
|
235
|
+
(0, react.useEffect)(() => {
|
|
236
|
+
setSelected(derived);
|
|
237
|
+
}, [derived]);
|
|
238
|
+
(0, react.useEffect)(() => {
|
|
239
|
+
setDraft(String(current));
|
|
240
|
+
}, [current]);
|
|
241
|
+
const labelOf = (id) => {
|
|
242
|
+
if (id === "off") return t("reminderOff");
|
|
243
|
+
if (id === "turn") return t("reminderTurn");
|
|
244
|
+
if (id === "custom") return t("reminderCustom");
|
|
245
|
+
return `${id} ${t("reminderUnit")}`;
|
|
246
|
+
};
|
|
247
|
+
const items = [
|
|
248
|
+
"off",
|
|
249
|
+
"turn",
|
|
250
|
+
...PRESET_MINUTES.map(String),
|
|
251
|
+
"custom"
|
|
252
|
+
].map((id) => ({
|
|
253
|
+
id,
|
|
254
|
+
label: labelOf(id)
|
|
255
|
+
}));
|
|
256
|
+
const choose = (id) => {
|
|
257
|
+
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));
|
|
262
|
+
};
|
|
263
|
+
const commit = () => {
|
|
264
|
+
const minutes = Math.round(Number(draft));
|
|
265
|
+
if (!Number.isFinite(minutes) || draft.trim() === "") {
|
|
266
|
+
setDraft(String(current));
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const clamped = Math.min(MAX_REMINDER_MINUTES, Math.max(1, minutes));
|
|
270
|
+
writeField(doc, FIELD_REMINDER, clamped);
|
|
271
|
+
setDraft(String(clamped));
|
|
272
|
+
};
|
|
273
|
+
const picker = (0, react.createElement)("button", {
|
|
274
|
+
type: "button",
|
|
275
|
+
className: "dsh_desk_lang_picker",
|
|
276
|
+
"aria-haspopup": "menu",
|
|
277
|
+
"aria-expanded": open,
|
|
278
|
+
onClick: () => setOpen((value) => !value)
|
|
279
|
+
}, labelOf(selected), Chevron === void 0 ? null : (0, react.createElement)(Chevron, { className: "dsh_desk_lang_chevron" }));
|
|
280
|
+
const control = Menu ? (0, react.createElement)(Menu, {
|
|
281
|
+
open,
|
|
282
|
+
anchor: picker,
|
|
283
|
+
items,
|
|
284
|
+
selectedId: selected,
|
|
285
|
+
align: "end",
|
|
286
|
+
portal: true,
|
|
287
|
+
onClose: () => setOpen(false),
|
|
288
|
+
onSelect: choose
|
|
171
289
|
}) : picker;
|
|
172
|
-
|
|
290
|
+
if (selected !== "custom") return control;
|
|
291
|
+
return (0, react.createElement)("div", { className: "dsh_desk_lang_control" }, control, (0, react.createElement)("input", {
|
|
292
|
+
type: "number",
|
|
293
|
+
className: "dsh_desk_lang_input",
|
|
294
|
+
min: 1,
|
|
295
|
+
max: MAX_REMINDER_MINUTES,
|
|
296
|
+
placeholder: String(settings.reminderMinutes > 0 ? settings.reminderMinutes : 30),
|
|
297
|
+
value: draft,
|
|
298
|
+
onChange: (event) => setDraft(event.currentTarget.value),
|
|
299
|
+
onBlur: commit,
|
|
300
|
+
onKeyDown: (event) => {
|
|
301
|
+
if (event.key === "Enter") commit();
|
|
302
|
+
}
|
|
303
|
+
}), (0, react.createElement)("span", { className: "dsh_desk_lang_hint" }, t("reminderCustomHint")));
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Build the General settings row: heading, description and the language picker.
|
|
308
|
+
* 构建「通用」设置行:标题、说明与语言选择器。
|
|
309
|
+
*/
|
|
310
|
+
function createRow(primitives) {
|
|
311
|
+
const LanguagePicker = createLanguagePicker(primitives);
|
|
312
|
+
return function ThinkingLanguageRow(props) {
|
|
313
|
+
const settings = useSettings(props.doc);
|
|
314
|
+
return (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, {
|
|
315
|
+
doc: props.doc,
|
|
316
|
+
t: props.t,
|
|
317
|
+
settings
|
|
318
|
+
}));
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Build the plugin configuration card: language and reminder interval.
|
|
323
|
+
* 构建插件配置卡片:思考语言与提醒间隔。
|
|
324
|
+
*
|
|
325
|
+
* The host renders this inside the plugin's detail page; `view: 'summary'` is the
|
|
326
|
+
* one-line form a card may ask for, which this plugin leaves empty.
|
|
327
|
+
* 宿主把它渲染在插件详情页里;`view: 'summary'` 是卡片可能请求的单行形式,本插件
|
|
328
|
+
* 留空。
|
|
329
|
+
*/
|
|
330
|
+
function createConfigCard(primitives) {
|
|
331
|
+
const LanguagePicker = createLanguagePicker(primitives);
|
|
332
|
+
const ReminderPicker = createReminderPicker(primitives);
|
|
333
|
+
return function ThinkingLanguageCard(props) {
|
|
334
|
+
const settings = useSettings(props.doc);
|
|
335
|
+
if (props.view === "summary") return null;
|
|
336
|
+
const binding = {
|
|
337
|
+
doc: props.doc,
|
|
338
|
+
t: props.t,
|
|
339
|
+
settings
|
|
340
|
+
};
|
|
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)));
|
|
173
342
|
};
|
|
174
343
|
}
|
|
175
344
|
const rowCss = [
|
|
@@ -179,22 +348,16 @@ const rowCss = [
|
|
|
179
348
|
".dsh_desk_lang_desc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}",
|
|
180
349
|
".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}",
|
|
181
350
|
".dsh_desk_lang_picker:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
182
|
-
".dsh_desk_lang_chevron{flex:none}"
|
|
351
|
+
".dsh_desk_lang_chevron{flex:none}",
|
|
352
|
+
".dsh_desk_lang_control{align-items:center;gap:8px;display:flex;flex:none}",
|
|
353
|
+
".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
|
+
".dsh_desk_lang_hint{color:var(--dsw-alias-label-tertiary);font-size:12px;white-space:nowrap}"
|
|
183
355
|
].join("\n");
|
|
184
356
|
/** Marks the injected stylesheet, so a second mount can detect the first. / 标记已注入的样式表,使第二次挂载能发现第一次。 */
|
|
185
357
|
const STYLE_MARKER = "dsh-thinking-lang";
|
|
186
358
|
/**
|
|
187
|
-
* Inject the
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
* The guard reads the document rather than a module-level flag: a client plugin
|
|
191
|
-
* can be mounted more than once against the same page, and only the DOM knows
|
|
192
|
-
* whether this sheet is already there. Content is compared as well, because a
|
|
193
|
-
* hot-reloaded bundle keeps its marker while its CSS changes; skipping on the
|
|
194
|
-
* marker alone would leave the row styled by class names that no longer exist.
|
|
195
|
-
* 判重依据是文档本身而不是模块级标志:客户端插件可能被重复挂载到同一页面,只有 DOM
|
|
196
|
-
* 知道这张样式表是否已经存在。同时比对内容:热重载的 bundle 标记不变而 CSS 已变,
|
|
197
|
-
* 只看标记就跳过会让这一行按已不存在的类名取样式。
|
|
359
|
+
* Inject the settings stylesheet once per document, replacing a stale one.
|
|
360
|
+
* 每份文档只注入一次设置样式表,已过期的那张会被替换。
|
|
198
361
|
*/
|
|
199
362
|
function mountRowStyles() {
|
|
200
363
|
if (typeof document === "undefined") return;
|
|
@@ -223,6 +386,8 @@ function mountRowStyles() {
|
|
|
223
386
|
*/
|
|
224
387
|
/** Stable Cordis plugin name. / 稳定的 Cordis 插件名。 */
|
|
225
388
|
const name = "ay-dsh-tk-lang";
|
|
389
|
+
/** Package name; the key Plugins page uses to find a bundle's configuration page. / 包名;插件页用它查找某个 bundle 的配置页。 */
|
|
390
|
+
const PACKAGE_NAME = "dsh-thinking-lang";
|
|
226
391
|
/** The one client service this plugin requires. / 本插件唯一需要的客户端服务。 */
|
|
227
392
|
const inject = ["slots"];
|
|
228
393
|
/** Locale namespace holding the row copy. / 保存行文案的 locale 命名空间。 */
|
|
@@ -293,6 +458,21 @@ function apply(ctx) {
|
|
|
293
458
|
})
|
|
294
459
|
}, Row);
|
|
295
460
|
});
|
|
461
|
+
const whileServed = typeof forms.whileServed === "function" ? forms.whileServed.bind(forms) : void 0;
|
|
462
|
+
if (whileServed === void 0) {
|
|
463
|
+
report(uiCtx, "configForms.whileServed unavailable; plugin configuration page disabled");
|
|
464
|
+
return;
|
|
465
|
+
}
|
|
466
|
+
const Card = createConfigCard(primitives);
|
|
467
|
+
uiCtx.effect(() => whileServed([SETTINGS_NAMESPACE], () => uiCtx.slots.inject("plugins.bundle.config", () => uiCtx.slots.register({
|
|
468
|
+
name: "plugins.bundle.config",
|
|
469
|
+
key: PACKAGE_NAME,
|
|
470
|
+
locale: LOCALE_NS,
|
|
471
|
+
inject: () => ({
|
|
472
|
+
doc,
|
|
473
|
+
t
|
|
474
|
+
})
|
|
475
|
+
}, Card))), "dsh-thinking-lang: plugin configuration page");
|
|
296
476
|
});
|
|
297
477
|
}
|
|
298
478
|
//#endregion
|
package/lib/core.d.ts
CHANGED
|
@@ -53,16 +53,33 @@ export declare const CATALOGUE: readonly Language[];
|
|
|
53
53
|
export declare const AUTO = "auto";
|
|
54
54
|
/** Settings namespace owned by this plugin. / 本插件拥有的设置命名空间。 */
|
|
55
55
|
export declare const SETTINGS_NAMESPACE = "ay-dsh-tk-lang";
|
|
56
|
-
/** The
|
|
56
|
+
/** The language field this plugin stores. / 本插件保存的语言字段。 */
|
|
57
57
|
export declare const FIELD_LANGUAGE = "language";
|
|
58
|
+
/** The reminder field this plugin stores. / 本插件保存的提醒字段。 */
|
|
59
|
+
export declare const FIELD_REMINDER = "reminderMinutes";
|
|
60
|
+
/** Reminder value that disables the per-turn reminder. / 关闭每轮提醒的取值。 */
|
|
61
|
+
export declare const REMINDER_OFF = -1;
|
|
62
|
+
/** Reminder value that injects on every turn. / 每轮都注入的取值。 */
|
|
63
|
+
export declare const REMINDER_EVERY_TURN = 0;
|
|
64
|
+
/** Reminder interval applied when the field is absent. / 字段缺失时的提醒间隔(分钟)。 */
|
|
65
|
+
export declare const DEFAULT_REMINDER_MINUTES = 30;
|
|
66
|
+
/** Largest accepted reminder interval. / 允许的最大提醒间隔(分钟)。 */
|
|
67
|
+
export declare const MAX_REMINDER_MINUTES = 1440;
|
|
58
68
|
/** Every value the picker offers besides {@link AUTO}. / 选择器在 {@link AUTO} 之外提供的全部取值。 */
|
|
59
69
|
export declare const SELECTABLE_TAGS: readonly string[];
|
|
60
70
|
/** The resolved configuration this plugin acts on. / 本插件实际作用的已解析配置。 */
|
|
61
71
|
export interface ThinkingSettings {
|
|
62
72
|
/** Selected language tag, or {@link AUTO}. / 所选语言标签,或 {@link AUTO}。 */
|
|
63
73
|
language: string;
|
|
74
|
+
/**
|
|
75
|
+
* Minutes between reminders: {@link REMINDER_OFF} disables them,
|
|
76
|
+
* {@link REMINDER_EVERY_TURN} injects on every turn, and 1–1440 is a minimum gap.
|
|
77
|
+
* 提醒间隔(分钟):{@link REMINDER_OFF} 关闭,{@link REMINDER_EVERY_TURN} 每轮
|
|
78
|
+
* 注入,1–1440 为最小间隔。
|
|
79
|
+
*/
|
|
80
|
+
reminderMinutes: number;
|
|
64
81
|
}
|
|
65
|
-
/** Configuration applied when the
|
|
82
|
+
/** Configuration applied when the fields are absent. / 字段缺失时采用的配置。 */
|
|
66
83
|
export declare const DEFAULTS: ThinkingSettings;
|
|
67
84
|
/** A minimal read handle over the host settings service. / 宿主设置服务的最小读取句柄。 */
|
|
68
85
|
export interface Reader {
|
|
@@ -74,9 +91,13 @@ export interface Reader {
|
|
|
74
91
|
*/
|
|
75
92
|
export declare function nativeNameFor(tag: string): string | undefined;
|
|
76
93
|
/**
|
|
77
|
-
*
|
|
78
|
-
*
|
|
94
|
+
* Convert stored minutes into the minimum gap between reminders.
|
|
95
|
+
* 把存储的分钟数换算成两次提醒之间的最小间隔。
|
|
96
|
+
*
|
|
97
|
+
* Returns {@link REMINDER_OFF} when the reminder is disabled and `0` when it runs
|
|
98
|
+
* on every turn. / 关闭时返回 {@link REMINDER_OFF},每轮注入时返回 `0`。
|
|
79
99
|
*/
|
|
100
|
+
export declare function reminderDelayMs(minutes: number): number;
|
|
80
101
|
export declare function normalizeSettings(raw: unknown): ThinkingSettings;
|
|
81
102
|
/**
|
|
82
103
|
* Resolve the effective language for `auto`, most authoritative source first.
|
package/lib/core.js
CHANGED
|
@@ -63,12 +63,22 @@ export const AUTO = "auto";
|
|
|
63
63
|
const FALLBACK_TAG = "zh-CN";
|
|
64
64
|
/** Settings namespace owned by this plugin. / 本插件拥有的设置命名空间。 */
|
|
65
65
|
export const SETTINGS_NAMESPACE = "ay-dsh-tk-lang";
|
|
66
|
-
/** The
|
|
66
|
+
/** The language field this plugin stores. / 本插件保存的语言字段。 */
|
|
67
67
|
export const FIELD_LANGUAGE = "language";
|
|
68
|
+
/** The reminder field this plugin stores. / 本插件保存的提醒字段。 */
|
|
69
|
+
export const FIELD_REMINDER = "reminderMinutes";
|
|
70
|
+
/** Reminder value that disables the per-turn reminder. / 关闭每轮提醒的取值。 */
|
|
71
|
+
export const REMINDER_OFF = -1;
|
|
72
|
+
/** Reminder value that injects on every turn. / 每轮都注入的取值。 */
|
|
73
|
+
export const REMINDER_EVERY_TURN = 0;
|
|
74
|
+
/** Reminder interval applied when the field is absent. / 字段缺失时的提醒间隔(分钟)。 */
|
|
75
|
+
export const DEFAULT_REMINDER_MINUTES = 30;
|
|
76
|
+
/** Largest accepted reminder interval. / 允许的最大提醒间隔(分钟)。 */
|
|
77
|
+
export const MAX_REMINDER_MINUTES = 1440;
|
|
68
78
|
/** Every value the picker offers besides {@link AUTO}. / 选择器在 {@link AUTO} 之外提供的全部取值。 */
|
|
69
79
|
export const SELECTABLE_TAGS = CATALOGUE.map((language) => language.tag);
|
|
70
|
-
/** Configuration applied when the
|
|
71
|
-
export const DEFAULTS = { language: AUTO };
|
|
80
|
+
/** Configuration applied when the fields are absent. / 字段缺失时采用的配置。 */
|
|
81
|
+
export const DEFAULTS = { language: AUTO, reminderMinutes: DEFAULT_REMINDER_MINUTES };
|
|
72
82
|
/** Catalogue lookup keyed by lower-cased tag. / 以小写标签为键的目录索引。 */
|
|
73
83
|
const BY_TAG = new Map(CATALOGUE.map((language) => [language.tag.toLowerCase(), language]));
|
|
74
84
|
/**
|
|
@@ -172,10 +182,37 @@ function tagForLocale(raw) {
|
|
|
172
182
|
* Coerce an untrusted settings section into a complete configuration.
|
|
173
183
|
* 把不可信的设置段强制转换为完整配置。
|
|
174
184
|
*/
|
|
185
|
+
/** Clamp one untrusted reminder value into the accepted range; any negative value disables it. / 把不可信的提醒值收敛到允许范围;负数一律视为关闭。 */
|
|
186
|
+
function normalizeReminder(raw) {
|
|
187
|
+
const numeric = typeof raw === "number" ? raw : typeof raw === "string" && raw.trim() !== "" ? Number(raw) : NaN;
|
|
188
|
+
if (!Number.isFinite(numeric))
|
|
189
|
+
return DEFAULT_REMINDER_MINUTES;
|
|
190
|
+
const rounded = Math.round(numeric);
|
|
191
|
+
if (rounded < 0)
|
|
192
|
+
return REMINDER_OFF;
|
|
193
|
+
return rounded > MAX_REMINDER_MINUTES ? MAX_REMINDER_MINUTES : rounded;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Convert stored minutes into the minimum gap between reminders.
|
|
197
|
+
* 把存储的分钟数换算成两次提醒之间的最小间隔。
|
|
198
|
+
*
|
|
199
|
+
* Returns {@link REMINDER_OFF} when the reminder is disabled and `0` when it runs
|
|
200
|
+
* on every turn. / 关闭时返回 {@link REMINDER_OFF},每轮注入时返回 `0`。
|
|
201
|
+
*/
|
|
202
|
+
export function reminderDelayMs(minutes) {
|
|
203
|
+
if (minutes < 0)
|
|
204
|
+
return REMINDER_OFF;
|
|
205
|
+
if (minutes === REMINDER_EVERY_TURN)
|
|
206
|
+
return 0;
|
|
207
|
+
return minutes * 60_000;
|
|
208
|
+
}
|
|
175
209
|
export function normalizeSettings(raw) {
|
|
176
|
-
const
|
|
177
|
-
const stored =
|
|
178
|
-
return {
|
|
210
|
+
const section = raw !== null && typeof raw === "object" && !Array.isArray(raw) ? raw : undefined;
|
|
211
|
+
const stored = section?.[FIELD_LANGUAGE];
|
|
212
|
+
return {
|
|
213
|
+
language: typeof stored === "string" && stored !== "" ? stored : DEFAULTS.language,
|
|
214
|
+
reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER])
|
|
215
|
+
};
|
|
179
216
|
}
|
|
180
217
|
/**
|
|
181
218
|
* Resolve the effective language for `auto`, most authoritative source first.
|
package/lib/index.js
CHANGED
|
@@ -6,10 +6,10 @@
|
|
|
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 (
|
|
9
|
+
* pre-step step 1 → a short reminder, at most once per turn (interval configurable, default 30 min)
|
|
10
10
|
*
|
|
11
11
|
* section order 1 → 权威规则,每会话组装一次
|
|
12
|
-
* pre-step step 1 →
|
|
12
|
+
* pre-step step 1 → 短提醒,每轮最多一次(间隔可配置,默认 30 分钟)
|
|
13
13
|
*
|
|
14
14
|
* The host context is described by a local structural interface rather than the
|
|
15
15
|
* `@deepseek-ai/cordis` type, so this package carries no DSH type dependency.
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { randomUUID } from "node:crypto";
|
|
20
20
|
import z from "@deepseek-ai/schemastery";
|
|
21
|
-
import { AUTO, FIELD_LANGUAGE, SELECTABLE_TAGS, SETTINGS_NAMESPACE, effectiveCode, nativeNameFor, normalizeSettings, reminderText, sectionText } from "./core.js";
|
|
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";
|
|
22
22
|
/** Stable Cordis plugin name. / 稳定的 Cordis 插件名。 */
|
|
23
23
|
export const name = "ay-dsh-tk-lang";
|
|
24
24
|
/** Plugin-level service requirements; services are acquired per branch below. / 插件级服务声明;服务在下方逐分支获取。 */
|
|
@@ -31,8 +31,6 @@ export const inject = [];
|
|
|
31
31
|
* persona 前缀放在 0、第一个策略段放在 500,因此取 1 就紧跟在 persona 那行之后。
|
|
32
32
|
*/
|
|
33
33
|
const SECTION_ORDER = 1;
|
|
34
|
-
/** Minimum milliseconds between two per-turn reminders in one session. / 同一会话中两次每轮提醒之间的最小毫秒数。 */
|
|
35
|
-
const REMINDER_INTERVAL_MS = 600_000;
|
|
36
34
|
/** Settings namespace holding the desktop UI locale. / 保存桌面 UI 语言的设置命名空间。 */
|
|
37
35
|
const LOCALE_NAMESPACE = "locale";
|
|
38
36
|
/** Field of {@link LOCALE_NAMESPACE} holding the UI locale. / {@link LOCALE_NAMESPACE} 中保存 UI 语言的字段。 */
|
|
@@ -91,7 +89,10 @@ function labelled(node, label) {
|
|
|
91
89
|
*/
|
|
92
90
|
function buildSchema() {
|
|
93
91
|
const choices = [AUTO, ...SELECTABLE_TAGS].map((value) => labelled(z.const(value), nativeNameFor(value)));
|
|
94
|
-
return z.object({
|
|
92
|
+
return z.object({
|
|
93
|
+
[FIELD_LANGUAGE]: live(z.union(choices).default(AUTO)),
|
|
94
|
+
[FIELD_REMINDER]: live(z.number().default(DEFAULT_REMINDER_MINUTES))
|
|
95
|
+
});
|
|
95
96
|
}
|
|
96
97
|
/** Durable settings schema; the field defaults to {@link AUTO}. / 持久化设置 schema;字段默认为 {@link AUTO}。 */
|
|
97
98
|
export const Config = buildSchema();
|
|
@@ -219,13 +220,16 @@ function osLocale() {
|
|
|
219
220
|
return value;
|
|
220
221
|
}
|
|
221
222
|
/**
|
|
222
|
-
* Resolve the
|
|
223
|
-
*
|
|
223
|
+
* Resolve the configuration in effect for one prompt build.
|
|
224
|
+
* 为一次提示词构建解析出当前生效的配置。
|
|
224
225
|
*/
|
|
225
|
-
function
|
|
226
|
+
function currentSettings(reader) {
|
|
226
227
|
const settings = normalizeSettings(sectionOf(reader, SETTINGS_NAMESPACE));
|
|
227
228
|
const desktop = sectionOf(reader, LOCALE_NAMESPACE)?.[LOCALE_FIELD];
|
|
228
|
-
return
|
|
229
|
+
return {
|
|
230
|
+
...settings,
|
|
231
|
+
language: effectiveCode(settings, osLocale(), typeof desktop === "string" ? desktop : undefined)
|
|
232
|
+
};
|
|
229
233
|
}
|
|
230
234
|
/**
|
|
231
235
|
* Build the durable user message carrying one reminder.
|
|
@@ -258,7 +262,7 @@ export function apply(ctx) {
|
|
|
258
262
|
promptCtx.systemPrompt.section({
|
|
259
263
|
name: "app:tk-lang",
|
|
260
264
|
order: SECTION_ORDER,
|
|
261
|
-
text: () => sectionText(
|
|
265
|
+
text: () => sectionText(currentSettings(reader()).language)
|
|
262
266
|
});
|
|
263
267
|
// The reminder runs before the other pre-step listeners, so its message is
|
|
264
268
|
// appended after theirs and stays closest to the end of the request.
|
|
@@ -267,11 +271,15 @@ export function apply(ctx) {
|
|
|
267
271
|
const decision = await next();
|
|
268
272
|
if (decision.kind !== "enter" || payload.signal.aborted || payload.step !== 1)
|
|
269
273
|
return decision;
|
|
274
|
+
const settings = currentSettings(reader());
|
|
275
|
+
const delay = reminderDelayMs(settings.reminderMinutes);
|
|
276
|
+
if (delay === REMINDER_OFF)
|
|
277
|
+
return decision;
|
|
270
278
|
const now = Date.now();
|
|
271
279
|
const previous = lastReminderAt.get(payload.agent.session.id);
|
|
272
|
-
if (previous !== undefined && now - previous <
|
|
280
|
+
if (delay > 0 && previous !== undefined && now - previous < delay)
|
|
273
281
|
return decision;
|
|
274
|
-
const text = reminderText(
|
|
282
|
+
const text = reminderText(settings.language);
|
|
275
283
|
if (text === "")
|
|
276
284
|
return decision;
|
|
277
285
|
lastReminderAt.set(payload.agent.session.id, now);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-thinking-lang",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "DSH plugin: set the agent's reasoning language (Settings → General)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -36,8 +36,10 @@
|
|
|
36
36
|
"lib",
|
|
37
37
|
"client",
|
|
38
38
|
"src",
|
|
39
|
+
"assets",
|
|
39
40
|
"cordis.patch.yml",
|
|
40
41
|
"README.md",
|
|
42
|
+
"DEVELOPMENT.md",
|
|
41
43
|
"PROVENANCE.md",
|
|
42
44
|
"LICENSE"
|
|
43
45
|
],
|