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/DEVELOPMENT.md +35 -15
- package/README.md +17 -3
- package/assets/plugin-config.png +0 -0
- package/client/client.js +151 -45
- package/client/client.raw.cjs +151 -45
- package/lib/core.d.ts +16 -1
- package/lib/core.js +36 -14
- package/lib/index.d.ts +2 -0
- package/lib/index.js +98 -50
- package/package.json +1 -1
- package/src/client/locales.ts +23 -2
- package/src/client/panel.ts +153 -54
- package/src/client/react.d.ts +5 -2
- package/src/core.ts +47 -15
- package/src/index.ts +103 -53
package/DEVELOPMENT.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|---|---|---|
|
|
13
13
|
| 由谁生成 | [`sectionText`](src/core.ts) | [`reminderText`](src/core.ts) |
|
|
14
14
|
| 内容 | 完整规则句 | 一句短提醒 |
|
|
15
|
-
| 注入形态 | 系统提示词的一段 |
|
|
15
|
+
| 注入形态 | 系统提示词的一段 | 批次开头的一条插件消息,可在技能目录或批次末尾加一条额外提醒 |
|
|
16
16
|
| 频率 | 每会话组装一次(文本变化时提交) | 每轮第一步,且距上次 ≥ 提醒间隔(默认 30 分钟) |
|
|
17
17
|
| 顺序 | `order: 1`,紧跟 persona | `prepend` 注册,晚于其它 pre-step 注入 |
|
|
18
18
|
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
|
|
21
21
|
文本由 [`src/core.ts`](src/core.ts) 的 `CATALOGUE` 提供,每种语言一份、**用该语言书写**:
|
|
22
22
|
|
|
23
|
-
| 语言 | section(规则句) | reminder
|
|
24
|
-
|
|
25
|
-
| 简体中文 |
|
|
26
|
-
| 繁體中文 |
|
|
27
|
-
| English | Reasoning rules: think, reason, and plan in English.
|
|
23
|
+
| 语言 | section(规则句) | reminder(批次开头) | tail(请求末尾) |
|
|
24
|
+
|---|---|---|---|
|
|
25
|
+
| 简体中文 | 推理规则:思考、推理与规划一律使用简体中文。 | 注意:思考、推理与规划用简体中文,即使上文不是 | 下文请使用简体中文思考 |
|
|
26
|
+
| 繁體中文 | 推理規則:思考、推理與規劃一律使用繁體中文。 | 注意:思考、推理與規劃用繁體中文,即使上文不是 | 下文請使用繁體中文思考 |
|
|
27
|
+
| English | Reasoning rules: think, reason, and plan in English. | Note: think, reason, and plan in English, even if the text above is not | Think in English from here on |
|
|
28
28
|
|
|
29
29
|
改文本改 `CATALOGUE`,再 `npm run build`。
|
|
30
30
|
|
|
31
|
-
section 的 `order: 1` 紧跟 persona
|
|
31
|
+
section 的 `order: 1` 紧跟 persona。前置提醒作为一条插件消息插在批次最前。`agent/pre-step` 监听器在 `agent/created` 时重新 `prepend`,从而在其他监听器追加消息后处理完整批次。
|
|
32
32
|
|
|
33
33
|
### 提醒间隔
|
|
34
34
|
|
|
@@ -42,19 +42,38 @@ section 的 `order: 1` 紧跟 persona;提醒消息经 `prepend` 注册,落
|
|
|
42
42
|
|
|
43
43
|
宿主端由 [`reminderDelayMs`](src/core.ts) 换算;客户端在插件详情页的配置卡片里修改,两处读写同一份设置文档。
|
|
44
44
|
|
|
45
|
+
### 额外提醒注入
|
|
46
|
+
|
|
47
|
+
存储字段是 `extraInjection`(布尔,默认 `true`)。如果本批次包含 `skill-catalog`,插件把额外提醒加到目录正文之前。如果目录缺席,插件在批次末尾追加一条独立消息,并在会话日志中标记为插件来源。
|
|
48
|
+
|
|
49
|
+
它跟着提醒间隔联动:`reminderMinutes` 为负数时,整个 `agent/pre-step` 监听器提前返回,两处注入一起停;客户端对应地把这一行置灰。
|
|
50
|
+
|
|
45
51
|
---
|
|
46
52
|
|
|
47
53
|
## Token 开销(实测)
|
|
48
54
|
|
|
49
55
|
用 DeepSeek V4 词表实测(不计特殊 token):
|
|
50
56
|
|
|
51
|
-
| 语言 | section |
|
|
52
|
-
|
|
53
|
-
| 简体中文 |
|
|
54
|
-
| 繁體中文 |
|
|
55
|
-
| English |
|
|
57
|
+
| 语言 | section(每会话一次) | 前置提醒(每提醒轮次) | 额外提醒(每提醒轮次) |
|
|
58
|
+
|---|---|---|---|
|
|
59
|
+
| 简体中文 | 13 | 14 | 6 |
|
|
60
|
+
| 繁體中文 | 13 | 14 | 6 |
|
|
61
|
+
| English | 13 | 18 | 6 |
|
|
62
|
+
|
|
63
|
+
前置提醒是一条独立的用户消息,额外提醒只改 `skill-catalog` 的 `content[0]`、不新增消息,所以后者便宜。按默认 30 分钟间隔、100 轮算,一个会话约 50 次提醒、合计约 1000–1300 token。**换语言对每轮开销几乎没有影响**。
|
|
64
|
+
|
|
65
|
+
旧版只有一条 10 token 的提醒;现在为了压住英文正文拆成 14 + 6(简体中文)。
|
|
66
|
+
|
|
67
|
+
### 效果数据
|
|
68
|
+
|
|
69
|
+
2026-11-18 实测,prompt 固定为「英文开场 + 中文测试句结尾」:
|
|
70
|
+
|
|
71
|
+
| 做法 | 按所选语言思考 |
|
|
72
|
+
|---|---|
|
|
73
|
+
| 系统提示 + 前置提醒 | 约 30% |
|
|
74
|
+
| 再加额外提醒注入 | 约 70%(30 个样本 21 中) |
|
|
56
75
|
|
|
57
|
-
|
|
76
|
+
样本:单注入 10 个(3 中);双注入 40 个(29 中)。同一配置重复跑波动在 7 个百分点以内。**注入提高概率,不保证结果**——用户消息首行就是所选语言时基本不受影响。
|
|
58
77
|
|
|
59
78
|
---
|
|
60
79
|
|
|
@@ -67,7 +86,7 @@ DeepSeek 的上下文缓存自动生效、无需改代码,但它**只认从第
|
|
|
67
86
|
- **支持 in-history 的模型**(DeepSeek 官方模型声明 `systemPromptUpdate: 'in-history'`):新 system prompt 作为一条消息追加到历史尾部,旧前缀仍可命中;
|
|
68
87
|
- **其它模型**:宿主替换开头那条 system message,从那里往后的 Token 全部重算。
|
|
69
88
|
|
|
70
|
-
|
|
89
|
+
提醒随当前步的新消息批次追加,因此此前请求已有的前缀仍可复用。
|
|
71
90
|
|
|
72
91
|
差价是 **50 倍**(`deepseek-flash` 空闲时段:命中 0.02 元 / 百万 token,未命中 1 元 / 百万 token;高峰时段同样 50 倍。见[模型 & 价格](https://api-docs.deepseek.com/zh-cn/quick_start/pricing/))。切换的代价仍是一次性的,从下一轮起恢复命中。
|
|
73
92
|
|
|
@@ -141,7 +160,7 @@ dsh plugin --profile desktop add "$PWD"
|
|
|
141
160
|
|
|
142
161
|
标签先被清洗成 BCP-47(`_`→`-`,去掉 `.UTF-8`、`@latin` 这类 POSIX 修饰),再交给平台自带的 `Intl.Locale` 拆成语言/文字/地区三段,**不手写标签文法**。查找从最具体到最一般:完整标签 → 带文字的 → 带地区的 → 裸主标签,所以 `en-GB` 会落到 `en`。
|
|
143
162
|
|
|
144
|
-
|
|
163
|
+
中文优先使用显式文字标签,只有标签省略文字时才调用 `maximize()` 根据 CLDR 数据推断。`Hant` 判为繁体,其余判为简体。`zh-Hant-CN`、`zh-TW`、`zh-HK` 和 `zh-MO` 会得到繁体,`zh-Hans-TW`、`zh` 和 `zh-SG` 会得到简体。
|
|
145
164
|
|
|
146
165
|
---
|
|
147
166
|
|
|
@@ -154,3 +173,4 @@ dsh plugin --profile desktop add "$PWD"
|
|
|
154
173
|
- **没有聊天命令**:切换语言只走设置页。如需 `/thinking-language`,可参照 `dsh-thinking-language` 的命令实现补上。
|
|
155
174
|
- **`auto` 依赖运行时能报出系统语言**:Linux/macOS 走环境变量,Windows 走 `Intl`。两者都拿不到时会静默落到界面语言,再不行才是 `zh-CN`。
|
|
156
175
|
- **插件 id 与设置命名空间**:两者都是 `ay-dsh-tk-lang`,占的是一套自有命名;包名 `dsh-thinking-lang` 与 `dsh-thinking-language` 这类仍然相似,注意区分。功能重复的插件同时装上时,设置页会各插一行、各自注入提示词。
|
|
176
|
+
- **注入只提高概率,不保证结果**:用户消息首行不是所选语言(英文开场、纯图片或附件)时,实测约 30%(仅前置提醒)/ 70%(含额外注入)按所选语言思考。需要稳定拿到目标语言的思考内容,请改用官方思考过程翻译插件。
|
package/README.md
CHANGED
|
@@ -18,16 +18,30 @@
|
|
|
18
18
|
|--------|------|------|
|
|
19
19
|
| **思考语言** | 自动 / 简体中文 / 繁體中文 / English | 内部推理与规划所用的语言 |
|
|
20
20
|
| **提醒间隔** | 关闭 / 每轮 / 10 / 30 / 60 分钟 / 自定义 1–1440 | 两次「用该语言思考」提醒之间的最小间隔,默认 **30 分钟** |
|
|
21
|
+
| **额外提醒注入** | 开启 / 关闭 | 开启时把额外提醒并入本轮技能目录,没有新目录时独立发送。提醒间隔为「关闭」时此项一并停用。默认开启 |
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
「关闭」停止全部注入,只保留系统提示里的规则;「每轮」是每个对话轮次的第一步都提醒一次。
|
|
23
24
|
|
|
24
25
|

|
|
25
26
|
|
|
26
27
|
*截图:设置 → 通用里的「思考语言」行,紧贴在宿主自己的界面语言下方。*
|
|
27
28
|
|
|
28
|
-

|
|
29
30
|
|
|
30
|
-
*截图:插件页 →
|
|
31
|
+
*截图:插件页 → 本插件详情里的同一份配置,含「提醒间隔」的预设与自定义输入,以及「额外提醒注入」开关。*
|
|
32
|
+
|
|
33
|
+
### 效果与限制
|
|
34
|
+
|
|
35
|
+
注入提高的是概率,不是保证。用户消息本身就用的所选语言时基本没问题;**用户消息首行不是所选语言**(英文开场、纯图片、只有附件)时实测:
|
|
36
|
+
|
|
37
|
+
| 做法 | 按所选语言思考的比例 |
|
|
38
|
+
|---|---|
|
|
39
|
+
| 系统提示 + 前置提醒 | 约 **30%** |
|
|
40
|
+
| 再开启「额外提醒注入」 | 约 **70%** |
|
|
41
|
+
|
|
42
|
+
额外提醒的简体中文正文约 6 token。独立发送时还会计入消息格式的开销。
|
|
43
|
+
|
|
44
|
+
**如果目标是稳定拿到目标语言的思考内容**,用官方的思考过程翻译插件更合适:它把思考内容翻译后显示,代价是每次都要多付一遍翻译的 token。本插件只在「直接改思考语言、并接受大多数时候是它」这个场景下更省。
|
|
31
45
|
|
|
32
46
|
### 「自动」怎么判定
|
|
33
47
|
|
package/assets/plugin-config.png
CHANGED
|
Binary file
|
package/client/client.js
CHANGED
|
@@ -22,20 +22,23 @@ window.__ModuleLoader__.load({
|
|
|
22
22
|
{
|
|
23
23
|
tag: "zh-CN",
|
|
24
24
|
nativeName: "简体中文",
|
|
25
|
-
section: "
|
|
26
|
-
reminder: "
|
|
25
|
+
section: "推理规则:思考、推理与规划一律使用简体中文。",
|
|
26
|
+
reminder: "注意:思考、推理与规划用简体中文,即使上文不是",
|
|
27
|
+
tail: "下文请使用简体中文思考"
|
|
27
28
|
},
|
|
28
29
|
{
|
|
29
30
|
tag: "zh-TW",
|
|
30
31
|
nativeName: "繁體中文",
|
|
31
|
-
section: "
|
|
32
|
-
reminder: "
|
|
32
|
+
section: "推理規則:思考、推理與規劃一律使用繁體中文。",
|
|
33
|
+
reminder: "注意:思考、推理與規劃用繁體中文,即使上文不是",
|
|
34
|
+
tail: "下文請使用繁體中文思考"
|
|
33
35
|
},
|
|
34
36
|
{
|
|
35
37
|
tag: "en",
|
|
36
38
|
nativeName: "English",
|
|
37
|
-
section: "Reasoning rules: think, reason, and plan in English.
|
|
38
|
-
reminder: "
|
|
39
|
+
section: "Reasoning rules: think, reason, and plan in English.",
|
|
40
|
+
reminder: "Note: think, reason, and plan in English, even if the text above is not",
|
|
41
|
+
tail: "Think in English from here on"
|
|
39
42
|
}
|
|
40
43
|
];
|
|
41
44
|
/** The sentinel meaning "follow the host locale". / 表示「跟随宿主语言」的哨兵值。 */
|
|
@@ -46,13 +49,16 @@ window.__ModuleLoader__.load({
|
|
|
46
49
|
const FIELD_LANGUAGE = "language";
|
|
47
50
|
/** The reminder field this plugin stores. / 本插件保存的提醒字段。 */
|
|
48
51
|
const FIELD_REMINDER = "reminderMinutes";
|
|
52
|
+
/** The extra-injection field this plugin stores. / 本插件保存的额外注入字段。 */
|
|
53
|
+
const FIELD_EXTRA = "extraInjection";
|
|
49
54
|
/** Largest accepted reminder interval. / 允许的最大提醒间隔(分钟)。 */
|
|
50
55
|
const MAX_REMINDER_MINUTES = 1440;
|
|
51
56
|
CATALOGUE.map((language) => language.tag);
|
|
52
57
|
/** Configuration applied when the fields are absent. / 字段缺失时采用的配置。 */
|
|
53
58
|
const DEFAULTS = {
|
|
54
59
|
language: AUTO,
|
|
55
|
-
reminderMinutes: 30
|
|
60
|
+
reminderMinutes: 30,
|
|
61
|
+
extraInjection: true
|
|
56
62
|
};
|
|
57
63
|
/** Catalogue lookup keyed by lower-cased tag. / 以小写标签为键的目录索引。 */
|
|
58
64
|
const BY_TAG = new Map(CATALOGUE.map((language) => [language.tag.toLowerCase(), language]));
|
|
@@ -79,16 +85,20 @@ window.__ModuleLoader__.load({
|
|
|
79
85
|
function normalizeReminder(raw) {
|
|
80
86
|
const numeric = typeof raw === "number" ? raw : typeof raw === "string" && raw.trim() !== "" ? Number(raw) : NaN;
|
|
81
87
|
if (!Number.isFinite(numeric)) return 30;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
88
|
+
if (numeric < 0) return -1;
|
|
89
|
+
return Math.max(0, Math.min(MAX_REMINDER_MINUTES, Math.round(numeric)));
|
|
90
|
+
}
|
|
91
|
+
/** Coerce one untrusted extra-injection value; only an explicit false turns it off. / 把不可信的额外注入值收敛为布尔;只有明确的 false 视为关闭。 */
|
|
92
|
+
function normalizeExtra(raw) {
|
|
93
|
+
return raw !== false && raw !== "false";
|
|
85
94
|
}
|
|
86
95
|
function normalizeSettings(raw) {
|
|
87
96
|
const section = raw !== null && typeof raw === "object" && !Array.isArray(raw) ? raw : void 0;
|
|
88
97
|
const stored = section?.[FIELD_LANGUAGE];
|
|
89
98
|
return {
|
|
90
99
|
language: typeof stored === "string" && stored !== "" ? stored : DEFAULTS.language,
|
|
91
|
-
reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER])
|
|
100
|
+
reminderMinutes: normalizeReminder(section?.[FIELD_REMINDER]),
|
|
101
|
+
extraInjection: normalizeExtra(section?.[FIELD_EXTRA])
|
|
92
102
|
};
|
|
93
103
|
}
|
|
94
104
|
/** Dictionaries keyed by UI locale, handed to the host locale service. / 以界面语言为键、交给宿主 locale 服务的字典。 */
|
|
@@ -103,7 +113,12 @@ window.__ModuleLoader__.load({
|
|
|
103
113
|
reminderTurn: "每轮",
|
|
104
114
|
reminderCustom: "自定义",
|
|
105
115
|
reminderUnit: "分钟",
|
|
106
|
-
reminderCustomHint: "1–1440 分钟"
|
|
116
|
+
reminderCustomHint: "1–1440 分钟",
|
|
117
|
+
extraHeading: "额外提醒注入",
|
|
118
|
+
extraDescription: "把额外提醒放进本轮技能目录,没有新目录时独立发送。提醒间隔为「关闭」时停用。",
|
|
119
|
+
extraOn: "开启",
|
|
120
|
+
extraOff: "关闭",
|
|
121
|
+
saveError: "设置未能保存,请重试。"
|
|
107
122
|
},
|
|
108
123
|
en: {
|
|
109
124
|
heading: "Thinking language",
|
|
@@ -115,7 +130,12 @@ window.__ModuleLoader__.load({
|
|
|
115
130
|
reminderTurn: "Every turn",
|
|
116
131
|
reminderCustom: "Custom",
|
|
117
132
|
reminderUnit: "min",
|
|
118
|
-
reminderCustomHint: "1–1440 minutes"
|
|
133
|
+
reminderCustomHint: "1–1440 minutes",
|
|
134
|
+
extraHeading: "Extra reminder injection",
|
|
135
|
+
extraDescription: "Adds a reminder to the skill catalogue, or sends it separately if no catalogue is sent. Turning reminders off also turns this off.",
|
|
136
|
+
extraOn: "On",
|
|
137
|
+
extraOff: "Off",
|
|
138
|
+
saveError: "Could not save this setting. Try again."
|
|
119
139
|
}
|
|
120
140
|
};
|
|
121
141
|
//#endregion
|
|
@@ -149,14 +169,37 @@ window.__ModuleLoader__.load({
|
|
|
149
169
|
}
|
|
150
170
|
}
|
|
151
171
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
172
|
+
* Show the result of the latest write for a field.
|
|
173
|
+
* 显示该字段最近一次写入的结果。
|
|
154
174
|
*/
|
|
155
|
-
function
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
175
|
+
function useSettingWriter(doc, field) {
|
|
176
|
+
const [failed, setFailed] = (0, react.useState)(false);
|
|
177
|
+
const generation = (0, react.useRef)(0);
|
|
178
|
+
(0, react.useEffect)(() => {
|
|
179
|
+
setFailed(false);
|
|
180
|
+
return () => {
|
|
181
|
+
generation.current += 1;
|
|
182
|
+
};
|
|
183
|
+
}, [doc]);
|
|
184
|
+
async function save(value) {
|
|
185
|
+
const attempted = ++generation.current;
|
|
186
|
+
setFailed(false);
|
|
187
|
+
let accepted = false;
|
|
188
|
+
try {
|
|
189
|
+
accepted = await doc.set(field, value);
|
|
190
|
+
} catch {}
|
|
191
|
+
if (attempted === generation.current) setFailed(!accepted);
|
|
192
|
+
}
|
|
193
|
+
return {
|
|
194
|
+
failed,
|
|
195
|
+
save
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
function pickerWithError(control, failed, t) {
|
|
199
|
+
return (0, react.createElement)("div", { className: "dsh_desk_lang_field" }, control, failed ? (0, react.createElement)("div", {
|
|
200
|
+
className: "dsh_desk_lang_desc",
|
|
201
|
+
role: "alert"
|
|
202
|
+
}, t("saveError")) : null);
|
|
160
203
|
}
|
|
161
204
|
/** Subscribe one component to the document and re-read it on every revision. / 订阅设置文档,并在每次修订时重新读取。 */
|
|
162
205
|
function useSettings(doc) {
|
|
@@ -178,6 +221,7 @@ window.__ModuleLoader__.load({
|
|
|
178
221
|
return function LanguagePicker(props) {
|
|
179
222
|
const { doc, t, settings } = props;
|
|
180
223
|
const [open, setOpen] = (0, react.useState)(false);
|
|
224
|
+
const { failed, save } = useSettingWriter(doc, FIELD_LANGUAGE);
|
|
181
225
|
const items = [{
|
|
182
226
|
id: AUTO,
|
|
183
227
|
label: t("autoLabel")
|
|
@@ -188,7 +232,7 @@ window.__ModuleLoader__.load({
|
|
|
188
232
|
const activeLabel = settings.language === "auto" ? t("autoLabel") : nativeNameFor(settings.language) ?? settings.language;
|
|
189
233
|
const close = () => setOpen(false);
|
|
190
234
|
const choose = (id) => {
|
|
191
|
-
|
|
235
|
+
save(id);
|
|
192
236
|
close();
|
|
193
237
|
};
|
|
194
238
|
const picker = (0, react.createElement)("button", {
|
|
@@ -198,8 +242,7 @@ window.__ModuleLoader__.load({
|
|
|
198
242
|
"aria-expanded": open,
|
|
199
243
|
onClick: () => setOpen((value) => !value)
|
|
200
244
|
}, activeLabel, Chevron === void 0 ? null : (0, react.createElement)(Chevron, { className: "dsh_desk_lang_chevron" }));
|
|
201
|
-
|
|
202
|
-
return (0, react.createElement)(Menu, {
|
|
245
|
+
return pickerWithError(Menu ? (0, react.createElement)(Menu, {
|
|
203
246
|
open,
|
|
204
247
|
anchor: picker,
|
|
205
248
|
items,
|
|
@@ -208,7 +251,7 @@ window.__ModuleLoader__.load({
|
|
|
208
251
|
portal: true,
|
|
209
252
|
onClose: close,
|
|
210
253
|
onSelect: choose
|
|
211
|
-
});
|
|
254
|
+
}) : picker, failed, t);
|
|
212
255
|
};
|
|
213
256
|
}
|
|
214
257
|
/** Map a stored minute count onto the picker id it should show. / 把存储的分钟数映射成选择器应显示的选项 id。 */
|
|
@@ -232,17 +275,21 @@ window.__ModuleLoader__.load({
|
|
|
232
275
|
const Chevron = primitives?.IconChevronDownOutlineRegular ?? primitives?.IconChevronDownOutline14 ?? primitives?.IconChevronDownOutlineMedium;
|
|
233
276
|
return function ReminderPicker(props) {
|
|
234
277
|
const { doc, t, settings } = props;
|
|
235
|
-
const
|
|
236
|
-
const
|
|
237
|
-
const
|
|
278
|
+
const minutes = settings.reminderMinutes;
|
|
279
|
+
const selected = derivedPreset(minutes);
|
|
280
|
+
const current = minutes > 0 ? minutes : DEFAULTS.reminderMinutes;
|
|
281
|
+
const [editingCustom, setEditingCustom] = (0, react.useState)(false);
|
|
238
282
|
const [open, setOpen] = (0, react.useState)(false);
|
|
239
283
|
const [draft, setDraft] = (0, react.useState)(String(current));
|
|
240
|
-
(
|
|
241
|
-
setSelected(derived);
|
|
242
|
-
}, [derived]);
|
|
284
|
+
const { failed, save } = useSettingWriter(doc, FIELD_REMINDER);
|
|
243
285
|
(0, react.useEffect)(() => {
|
|
244
286
|
setDraft(String(current));
|
|
245
|
-
|
|
287
|
+
setEditingCustom(false);
|
|
288
|
+
}, [
|
|
289
|
+
current,
|
|
290
|
+
doc,
|
|
291
|
+
minutes
|
|
292
|
+
]);
|
|
246
293
|
const labelOf = (id) => {
|
|
247
294
|
if (id === "off") return t("reminderOff");
|
|
248
295
|
if (id === "turn") return t("reminderTurn");
|
|
@@ -260,20 +307,22 @@ window.__ModuleLoader__.load({
|
|
|
260
307
|
}));
|
|
261
308
|
const choose = (id) => {
|
|
262
309
|
setOpen(false);
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
310
|
+
setDraft(String(current));
|
|
311
|
+
setEditingCustom(id === "custom");
|
|
312
|
+
if (id === "custom") return;
|
|
313
|
+
const value = id === "off" ? -1 : id === "turn" ? 0 : Number(id);
|
|
314
|
+
save(value);
|
|
267
315
|
};
|
|
268
316
|
const commit = () => {
|
|
269
|
-
const
|
|
270
|
-
if (!Number.isFinite(
|
|
317
|
+
const parsed = Math.round(Number(draft));
|
|
318
|
+
if (!Number.isFinite(parsed) || draft.trim() === "") {
|
|
271
319
|
setDraft(String(current));
|
|
272
320
|
return;
|
|
273
321
|
}
|
|
274
|
-
const clamped = Math.min(MAX_REMINDER_MINUTES, Math.max(1,
|
|
275
|
-
writeField(doc, FIELD_REMINDER, clamped);
|
|
322
|
+
const clamped = Math.min(MAX_REMINDER_MINUTES, Math.max(1, parsed));
|
|
276
323
|
setDraft(String(clamped));
|
|
324
|
+
if (clamped === minutes) setEditingCustom(false);
|
|
325
|
+
save(clamped);
|
|
277
326
|
};
|
|
278
327
|
const picker = (0, react.createElement)("button", {
|
|
279
328
|
type: "button",
|
|
@@ -292,20 +341,70 @@ window.__ModuleLoader__.load({
|
|
|
292
341
|
onClose: () => setOpen(false),
|
|
293
342
|
onSelect: choose
|
|
294
343
|
}) : picker;
|
|
295
|
-
if (selected !== "custom") return control;
|
|
296
|
-
return (0, react.createElement)("div", { className: "dsh_desk_lang_control" }, control, (0, react.createElement)("input", {
|
|
344
|
+
if (!editingCustom && selected !== "custom") return pickerWithError(control, failed, t);
|
|
345
|
+
return pickerWithError((0, react.createElement)("div", { className: "dsh_desk_lang_control" }, control, (0, react.createElement)("input", {
|
|
297
346
|
type: "number",
|
|
298
347
|
className: "dsh_desk_lang_input",
|
|
299
348
|
min: 1,
|
|
300
349
|
max: MAX_REMINDER_MINUTES,
|
|
301
|
-
|
|
350
|
+
"aria-label": t("reminderHeading"),
|
|
351
|
+
placeholder: String(current),
|
|
302
352
|
value: draft,
|
|
303
353
|
onChange: (event) => setDraft(event.currentTarget.value),
|
|
304
354
|
onBlur: commit,
|
|
305
355
|
onKeyDown: (event) => {
|
|
306
|
-
if (event.key === "Enter")
|
|
356
|
+
if (event.key === "Enter") {
|
|
357
|
+
event.preventDefault();
|
|
358
|
+
event.currentTarget.blur();
|
|
359
|
+
}
|
|
307
360
|
}
|
|
308
|
-
}), (0, react.createElement)("span", { className: "dsh_desk_lang_hint" }, t("reminderCustomHint")));
|
|
361
|
+
}), (0, react.createElement)("span", { className: "dsh_desk_lang_hint" }, t("reminderCustomHint"))), failed, t);
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Build the extra-injection picker: on or off.
|
|
366
|
+
* 构建额外注入选择器:开启或关闭。
|
|
367
|
+
*
|
|
368
|
+
* It shares the host Menu with the other controls, so the three read as one column.
|
|
369
|
+
* 与另外两个控件共用宿主 Menu,三者在视觉上成一列。
|
|
370
|
+
*/
|
|
371
|
+
function createExtraPicker(primitives) {
|
|
372
|
+
const Menu = primitives?.Menu;
|
|
373
|
+
const Chevron = primitives?.IconChevronDownOutlineRegular ?? primitives?.IconChevronDownOutline14 ?? primitives?.IconChevronDownOutlineMedium;
|
|
374
|
+
return function ExtraPicker(props) {
|
|
375
|
+
const { doc, t, settings, disabled = false } = props;
|
|
376
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
377
|
+
const { failed, save } = useSettingWriter(doc, FIELD_EXTRA);
|
|
378
|
+
const items = [{
|
|
379
|
+
id: "on",
|
|
380
|
+
label: t("extraOn")
|
|
381
|
+
}, {
|
|
382
|
+
id: "off",
|
|
383
|
+
label: t("extraOff")
|
|
384
|
+
}];
|
|
385
|
+
const close = () => setOpen(false);
|
|
386
|
+
const choose = (id) => {
|
|
387
|
+
if (!disabled) save(id === "on");
|
|
388
|
+
close();
|
|
389
|
+
};
|
|
390
|
+
const picker = (0, react.createElement)("button", {
|
|
391
|
+
type: "button",
|
|
392
|
+
className: "dsh_desk_lang_picker",
|
|
393
|
+
"aria-haspopup": "menu",
|
|
394
|
+
"aria-expanded": open,
|
|
395
|
+
disabled,
|
|
396
|
+
onClick: () => setOpen((value) => !value)
|
|
397
|
+
}, settings.extraInjection ? t("extraOn") : t("extraOff"), Chevron === void 0 ? null : (0, react.createElement)(Chevron, { className: "dsh_desk_lang_chevron" }));
|
|
398
|
+
return pickerWithError(Menu ? (0, react.createElement)(Menu, {
|
|
399
|
+
open: open && !disabled,
|
|
400
|
+
anchor: picker,
|
|
401
|
+
items,
|
|
402
|
+
selectedId: settings.extraInjection ? "on" : "off",
|
|
403
|
+
align: "end",
|
|
404
|
+
portal: true,
|
|
405
|
+
onClose: close,
|
|
406
|
+
onSelect: choose
|
|
407
|
+
}) : picker, failed, t);
|
|
309
408
|
};
|
|
310
409
|
}
|
|
311
410
|
/**
|
|
@@ -335,6 +434,7 @@ window.__ModuleLoader__.load({
|
|
|
335
434
|
function createConfigCard(primitives) {
|
|
336
435
|
const LanguagePicker = createLanguagePicker(primitives);
|
|
337
436
|
const ReminderPicker = createReminderPicker(primitives);
|
|
437
|
+
const ExtraPicker = createExtraPicker(primitives);
|
|
338
438
|
return function ThinkingLanguageCard(props) {
|
|
339
439
|
const settings = useSettings(props.doc);
|
|
340
440
|
if (props.view === "summary") return null;
|
|
@@ -343,17 +443,23 @@ window.__ModuleLoader__.load({
|
|
|
343
443
|
t: props.t,
|
|
344
444
|
settings
|
|
345
445
|
};
|
|
346
|
-
|
|
446
|
+
const reminderOff = settings.reminderMinutes < 0;
|
|
447
|
+
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, {
|
|
448
|
+
...binding,
|
|
449
|
+
disabled: reminderOff
|
|
450
|
+
})));
|
|
347
451
|
};
|
|
348
452
|
}
|
|
349
453
|
const rowCss = [
|
|
350
454
|
".dsh_desk_lang_row{border-bottom:.5px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}",
|
|
455
|
+
".dsh_desk_lang_row_disabled{opacity:.45;pointer-events:none}",
|
|
351
456
|
".dsh_desk_lang_text{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}",
|
|
352
457
|
".dsh_desk_lang_title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}",
|
|
353
458
|
".dsh_desk_lang_desc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}",
|
|
354
459
|
".dsh_desk_lang_picker{border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-module-platform);height:36px;font:inherit;color:var(--dsw-alias-label-primary);cursor:pointer;border:none;align-items:center;gap:12px;padding:0 14px;font-size:14px;line-height:22px;display:inline-flex;flex:none}",
|
|
355
460
|
".dsh_desk_lang_picker:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
356
461
|
".dsh_desk_lang_chevron{flex:none}",
|
|
462
|
+
".dsh_desk_lang_field{display:flex;flex-direction:column;align-items:flex-end;gap:4px}",
|
|
357
463
|
".dsh_desk_lang_control{align-items:center;gap:8px;display:flex;flex:none}",
|
|
358
464
|
".dsh_desk_lang_input{border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-module-platform);height:36px;width:88px;font:inherit;color:var(--dsw-alias-label-primary);border:none;padding:0 12px;font-size:14px}",
|
|
359
465
|
".dsh_desk_lang_hint{color:var(--dsw-alias-label-tertiary);font-size:12px;white-space:nowrap}"
|