dsh-thinking-lang 0.0.0-stage → 1.0.4
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/LICENSE +21 -0
- package/PROVENANCE.md +40 -0
- package/README.md +227 -2
- package/client/client.js +309 -0
- package/client/client.raw.cjs +301 -0
- package/cordis.patch.yml +14 -0
- package/lib/core.d.ts +109 -0
- package/lib/core.js +221 -0
- package/lib/index.d.ts +45 -0
- package/lib/index.js +281 -0
- package/package.json +89 -4
- package/src/client/index.ts +130 -0
- package/src/client/locales.ts +88 -0
- package/src/client/panel.ts +217 -0
- package/src/client/react.d.ts +33 -0
- package/src/core.ts +252 -0
- package/src/index.ts +353 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsh-thinking-lang contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/PROVENANCE.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# 来源记录
|
|
2
|
+
|
|
3
|
+
[](https://github.com/deepseek-ai/deepseek-harness)
|
|
4
|
+
|
|
5
|
+
本文件只记录一件事:设置行的样式从哪里来。使用说明看 [README.md](README.md)。
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 设置行样式:宿主 PreferenceRow
|
|
10
|
+
|
|
11
|
+
设置行的 CSS **声明顺序与属性值照宿主的 `PreferenceRow`**——也就是本行紧挨着的那一行。
|
|
12
|
+
|
|
13
|
+
| | |
|
|
14
|
+
|---|---|
|
|
15
|
+
| 宿主源码 | `packages/client/ui-chat/src/client/settings/PreferenceRow.module.css` |
|
|
16
|
+
| 包 | `@deepseek-ai/dsh-client-ui-chat` |
|
|
17
|
+
| 协议 | MIT,`Copyright (c) 2026 DeepSeek`(包内随附 LICENSE) |
|
|
18
|
+
| 仓库 | [deepseek-ai/deepseek-harness](https://github.com/deepseek-ai/deepseek-harness)(取自包的 `repository` 字段) |
|
|
19
|
+
|
|
20
|
+
逐属性核对结果:7 条规则一一对应,其中 6 条的属性集与顺序完全相同,选择器多一条 `flex:none`。
|
|
21
|
+
|
|
22
|
+
两处有意的差异:
|
|
23
|
+
|
|
24
|
+
- **类名**:宿主用 CSS Modules,编译后是 `XZcbxG_row` 这类带哈希的名字(每次构建都会变),运行时拿不到也复现不了;而且本插件的样式表注入到 `document.head`,是**页面级全局**表,裸 `.row` 会污染其它插件的元素。所以类名必须自起。
|
|
25
|
+
- **`flex:none`**:本行布局需要,宿主那一行不需要。
|
|
26
|
+
|
|
27
|
+
注意 `dsh-client-locale` 的 `LanguageRow.module.css` 是**另一个**组件,只有 5 条规则、没有说明文字;本行带标题 + 说明 + 选择器,对应的才是 `PreferenceRow`。
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
## 附:怎么从 app.asar 里读宿主源码
|
|
32
|
+
|
|
33
|
+
宿主升级后若要重新对照官方样式,按这几步走。踩过的坑一并记下:
|
|
34
|
+
|
|
35
|
+
- asar 头部布局是 `[payloadSize u32][stringLength u32][json...]`,JSON 从头部缓冲区的**偏移 8** 开始——按偏移 4 读会得到 `Unexpected non-whitespace character after JSON`;
|
|
36
|
+
- 文件数据起点是 `8 + headerSize`;
|
|
37
|
+
- 目录树里每个条目的 `offset` 是**字符串**而不是数字。用 `Number.isFinite(entry.offset)` 判断会把所有文件误判成 unpacked;正确判据是**没有 `offset` 字段**;
|
|
38
|
+
- 客户端包把 CSS Modules 编译成 JS 里的字符串,源头路径写在生成的注释里:搜 `dsh-css:` 或 `<组件名>.module.css.mjs` 就能定位到原始文件。
|
|
39
|
+
|
|
40
|
+
安装目录顶层只有 Electron 与 Chromium 的许可文件,容易误以为 DSH 客户端是闭源的;实际许可在各包内部,`@deepseek-ai/dsh-client-*` 都是 MIT。
|
package/README.md
CHANGED
|
@@ -1,3 +1,228 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-thinking-lang
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/deepseek-ai/deepseek-harness)
|
|
4
|
+
|
|
5
|
+
面向 **DeepSeek Harness(dsh-desk)** 的插件:设置智能体内部推理(思考)所用的语言。
|
|
6
|
+
|
|
7
|
+
**目标环境:** DeepSeek Harness **`0.2.0-rc.2`+**(`dsh -V`)。**License:** MIT。
|
|
8
|
+
|
|
9
|
+
> **本项目的代码、文案与文档均由 DeepSeek 生成**(在人工指导下迭代产出)。它不是 DeepSeek Harness 官方组件,未经官方审核;使用前请自行阅读源码。
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
dsh plugin --profile desktop add https://github.com/aymidasing/dsh-thinking-lang/releases/latest/download/dsh-thinking-lang.tgz
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
同一段地址也可以粘进设置里的插件管理器。执行前请**完全退出桌面端**:`--profile desktop` 操作的 profile 必须已经初始化,且没有进程正占用它。装完重启 GUI。
|
|
20
|
+
|
|
21
|
+
`main` 分支只有 TypeScript 源码;`lib/` 与 `client/` 是构建产物,只随 Release 提供。
|
|
22
|
+
|
|
23
|
+
**更新**:换用新版本的附件地址重装一次。依赖是以 URL 记录的,`pnpm update` 对它无效。
|
|
24
|
+
|
|
25
|
+
**卸载**:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
dsh plugin --profile desktop remove dsh-thinking-lang
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
设置里的「思考语言」那一行随之消失,提示词也不再注入。和安装一样,要在桌面端完全退出后执行。
|
|
32
|
+
|
|
33
|
+
从源码装(开发用):
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install
|
|
37
|
+
npm run build
|
|
38
|
+
dsh plugin --profile desktop add "$PWD"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**语言约束对新会话生效**;切语言本身在已有会话的下一轮就生效。
|
|
42
|
+
|
|
43
|
+
> **不要再用 `github:` 安装。** pnpm 11 默认拦下依赖的构建脚本,而 `github:` 源要靠 `prepare` 才产出 `lib/` 与 `client/`,安装会停在 `ERR_PNPM_GIT_DEP_PREPARE_NOT_ALLOWED`,除非在 profile 的 `pnpm-workspace.yaml` 里逐名放行 `allowBuilds`。Release 附件是构建好的成品,包里没有 `prepack`/`prepare`,装它不会触发构建授权。
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## 它做什么
|
|
48
|
+
|
|
49
|
+

|
|
50
|
+
|
|
51
|
+
在**设置 → 通用**里新增一行「思考语言」,位于宿主自身的语言设置项下方。整行只有一个下拉框:
|
|
52
|
+
|
|
53
|
+
| 配置项 | 取值 | 作用 |
|
|
54
|
+
|--------|------|------|
|
|
55
|
+
| **思考语言** | 自动 / 简体中文 / 繁體中文 / English | 内部推理与规划所用的语言 |
|
|
56
|
+
|
|
57
|
+
### `auto` 是怎么判定的
|
|
58
|
+
|
|
59
|
+
选「自动」时,按顺序取**第一个**能映射到语言目录的来源:
|
|
60
|
+
|
|
61
|
+
| 顺序 | 来源 | 取值方式 |
|
|
62
|
+
|---|---|---|
|
|
63
|
+
| 1 | **操作系统语言** | POSIX 环境变量 `LC_ALL` / `LC_MESSAGES` / `LANG`;Windows 上这些通常为空,改用 `Intl.DateTimeFormat().resolvedOptions().locale`(跟随系统区域设置) |
|
|
64
|
+
| 2 | **DSH 界面语言** | 设置服务里 `locale` 命名空间的 `preference` 字段 |
|
|
65
|
+
| 3 | **兜底** | 硬编码的 `zh-CN`(`FALLBACK_TAG`) |
|
|
66
|
+
|
|
67
|
+
标签先被清洗成 BCP-47(`_`→`-`,去掉 `.UTF-8`、`@latin` 这类 POSIX 修饰),再交给平台自带的 `Intl.Locale` 拆成语言/文字/地区三段,**不手写标签文法**。查找从最具体到最一般:完整标签 → 带文字的 → 带地区的 → 裸主标签,所以 `en-GB` 会落到 `en`。
|
|
68
|
+
|
|
69
|
+
中文是唯一的例外——两个条目共用 `zh` 这个主标签,决定简繁的是**文字**而不是地区。这部分交给 CLDR:`maximize()` 会把短标签省略的文字补出来,`Hant` 判为繁體、其余判为简体。于是 `zh-TW`/`zh-HK`/`zh-MO`/`zh-Hant` 都是繁體,`zh`/`zh-SG`/`zh-Hans` 都是简体,两张对照表都不需要。
|
|
70
|
+
|
|
71
|
+
| 系统 | 界面 | 结果 |
|
|
72
|
+
|---|---|---|
|
|
73
|
+
| `zh-CN` | `en-US` | 简体中文 |
|
|
74
|
+
| `en-US` | `zh-CN` | English |
|
|
75
|
+
| `fr-FR`(目录里没有) | `en-US` | English(落到下一级) |
|
|
76
|
+
| 取不到 | 取不到 | 简体中文 |
|
|
77
|
+
|
|
78
|
+
在下拉里**显式选了某个语言**时,那个选择优先于上面全部三级,与系统/界面语言无关。
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## 提示词是怎么注入的
|
|
83
|
+
|
|
84
|
+
规则用**所选语言本身**书写(不是英文语言名),分两个位置注入——区别在**频率**:
|
|
85
|
+
|
|
86
|
+
| | `systemPrompt.section` | `agent/pre-step` 提醒 |
|
|
87
|
+
|---|---|---|
|
|
88
|
+
| 由谁生成 | [`sectionText`](src/core.ts) | [`reminderText`](src/core.ts) |
|
|
89
|
+
| 内容 | 完整规则句 | 一句短提醒 |
|
|
90
|
+
| 注入形态 | 系统提示词的一段 | 一条 user 消息,追加在请求末尾 |
|
|
91
|
+
| 频率 | 每会话组装一次(文本变化时提交) | 每轮第一步,且距上次 ≥10 分钟 |
|
|
92
|
+
| 顺序 | `order: 1`,紧跟 persona | `prepend` 注册,晚于其它 pre-step 注入 |
|
|
93
|
+
|
|
94
|
+
### 实际注入的文本
|
|
95
|
+
|
|
96
|
+
文本由 [`src/core.ts`](src/core.ts) 的 `CATALOGUE` 提供,每种语言一份、**用该语言书写**:
|
|
97
|
+
|
|
98
|
+
| 语言 | section(规则句) | reminder(每轮提醒) |
|
|
99
|
+
|---|---|---|
|
|
100
|
+
| 简体中文 | 推理规则:思考、推理与规划一律使用简体中文。回复用户时使用用户所用的语言。 | 继续用简体中文思考、推理与规划。 |
|
|
101
|
+
| 繁體中文 | 推理規則:思考、推理與規劃一律使用繁體中文。回覆使用者時使用使用者所用的語言。 | 繼續用繁體中文思考、推理與規劃。 |
|
|
102
|
+
| English | Reasoning rules: think, reason, and plan in English. Reply to the user in the language they use. | Keep thinking, reasoning, and planning in English. |
|
|
103
|
+
|
|
104
|
+
改文本改 `CATALOGUE`,再 `npm run build`。
|
|
105
|
+
|
|
106
|
+
这个拆分带来两个直接结果:
|
|
107
|
+
|
|
108
|
+
1. **section 是权威版本** —— 位于 persona 之后、所有工具说明之前;切语言后由宿主按文本变化提交。
|
|
109
|
+
2. **pre-step 提醒负责实时性** —— 追加在 `decision.messages` 末尾,落在 runtime-context、skill catalog、time-context 之后,是请求里最后的内容。
|
|
110
|
+
|
|
111
|
+
> 上一版把提醒塞进 `systemPrompt.context`:它随 runtime-context 快照走,只在快照内容变化时追加,稳定期会沉到历史深处。现在改成独立消息、按轮注入。
|
|
112
|
+
|
|
113
|
+
### 顺序与优先级
|
|
114
|
+
|
|
115
|
+
- section 的 `order: 1` 紧跟在宿主的 persona 之后、第一个策略段之前——也就是渲染出来的 persona 那句话的下一行。
|
|
116
|
+
- 提醒消息排在请求最末。`prepend` 让本监听器先于其它 pre-step 监听器执行,其 append 发生在链返回之后,因此晚于 time-context 等注入。
|
|
117
|
+
|
|
118
|
+
> 取值依据是 DSH 自己的分段表:`@deepseek-ai/dsh-system-prompt` 里的 `SECTION_ORDERS`——身份 `-1000`、部署 persona `0`、`PLAN_POLICY` `500`、工具段从 `1000` 起。`order: 1` 正好落在 persona 与第一个策略段之间。
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Token 开销(实测)
|
|
123
|
+
|
|
124
|
+
用 DeepSeek V4 词表实测(不计特殊 token):
|
|
125
|
+
|
|
126
|
+
| 语言 | section | reminder |
|
|
127
|
+
|---|---|---|
|
|
128
|
+
| 简体中文 | 21 | 10 |
|
|
129
|
+
| 繁體中文 | 22 | 10 |
|
|
130
|
+
| English | 23 | 10 |
|
|
131
|
+
|
|
132
|
+
section 每会话一次;reminder 每轮最多一条(10 分钟内不重复),100 轮约 1000 token。**换语言对每轮开销几乎没有影响**。
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## ⚠️ 切换语言的缓存代价
|
|
137
|
+
|
|
138
|
+
DeepSeek 的上下文缓存自动生效、无需改代码,但它**只认从第 0 个 token 起完全相同的前缀**——官方原话:「只有当两个请求的前缀内容相同时(从第 0 个 token 开始相同),才算重复。**中间开始的重复不能被缓存命中**。」([API 上线硬盘缓存](https://api-docs.deepseek.com/zh-cn/news/news0802/))
|
|
139
|
+
|
|
140
|
+
切语言会改变 section 文本,影响范围取决于宿主如何处理 system prompt 更新:
|
|
141
|
+
|
|
142
|
+
- **支持 in-history 的模型**(DeepSeek 官方模型声明 `systemPromptUpdate: 'in-history'`):新 system prompt 作为一条消息追加到历史尾部,旧前缀仍可命中;
|
|
143
|
+
- **其它模型**:宿主替换开头那条 system message,从那里往后的 Token 全部重算。
|
|
144
|
+
|
|
145
|
+
reminder 每轮追加在请求末尾,只新增尾部 Token,不会让已有前缀失效。
|
|
146
|
+
|
|
147
|
+
差价是 **50 倍**(`deepseek-flash` 空闲时段:命中 0.02 元 / 百万 token,未命中 1 元 / 百万 token;高峰时段同样 50 倍。见[模型 & 价格](https://api-docs.deepseek.com/zh-cn/quick_start/pricing/))。切换的代价仍是一次性的,从下一轮起恢复命中。
|
|
148
|
+
|
|
149
|
+
**实用建议**:选定一种语言就别频繁来回切,尤其别在一轮对话中间切。切换不影响正确性,只影响钱。
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## 构建
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
npm install
|
|
157
|
+
npm run check # typecheck + build
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
构建分两段:
|
|
161
|
+
|
|
162
|
+
1. `tsc -p tsconfig.json` 编译宿主端到 `lib/`;
|
|
163
|
+
2. tsdown 把客户端打成 **CommonJS** 到 `client/client.raw.cjs`,再由 [`scripts/wrap-client-bundle.mjs`](scripts/wrap-client-bundle.mjs) 套上 DSH 的 `__ModuleLoader__` 工厂外壳,输出 `client/client.js`。
|
|
164
|
+
|
|
165
|
+
选 CommonJS 是为了让产物天生就是 `require(...)` 形态——DSH 的客户端工厂只提供 `require`,若先打成 ESM 就还得事后用正则把导入语句改回来。
|
|
166
|
+
|
|
167
|
+
Node(构建)需要 `^22.18.0 || >=24.11.0`;插件运行时不依赖本机 Node。
|
|
168
|
+
|
|
169
|
+
打包与发版:先 `npm run build`,再 `npm pack` 产出 `dsh-thinking-lang-<version>.tgz`;[`scripts/verify-pack.mjs`](scripts/verify-pack.mjs) 校验它带着运行时要加载的文件。发版流程是改 [`package.json`](package.json) 的 `version` → 提交 → `git tag v<version>` → 推送 tag;工作流会构建、校验并把附件传到该 tag 的 Release,tag 与 `version` 不一致时直接失败。工作流还会上传一个固定名副本 `dsh-thinking-lang.tgz`,README 与插件市场都通过 `releases/latest/download/dsh-thinking-lang.tgz` 安装——这个地址永远指向最新版本,发版后不用改任何引用。发布包不带 `prepack`/`prepare`,所以 `dsh plugin add` 安装时不会触发 pnpm 的构建授权。
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## 目录结构
|
|
174
|
+
|
|
175
|
+
| 路径 | 说明 |
|
|
176
|
+
|------|------|
|
|
177
|
+
| [`src/core.ts`](src/core.ts) | 语言目录、配置归一化、两份提示词生成。**纯函数,无宿主依赖**,客户端与宿主端共用。locale 解析走平台自带的 `Intl.Locale` |
|
|
178
|
+
| [`src/index.ts`](src/index.ts) | 宿主入口:Config schema、section 与 pre-step 提醒注册、语言解析(含操作系统语言探测) |
|
|
179
|
+
| [`src/client/index.ts`](src/client/index.ts) | 客户端入口:在 `settings.general.item` 插槽注册设置行 |
|
|
180
|
+
| [`src/client/panel.ts`](src/client/panel.ts) | 单行设置控件与样式 |
|
|
181
|
+
| [`src/client/locales.ts`](src/client/locales.ts) | 三套行文案(简 / 繁 / 英) |
|
|
182
|
+
| [`cordis.patch.yml`](cordis.patch.yml) | bundle patch,登记宿主入口 |
|
|
183
|
+
| [`PROVENANCE.md`](PROVENANCE.md) | 设置行样式的来源记录,以及从 `app.asar` 读宿主源码的方法(维护用) |
|
|
184
|
+
| `lib/` · `client/` | 构建产物,**不入库**——只随 Release 附件提供;[`package.json`](package.json) 的 `files` 白名单负责把它们打进包 |
|
|
185
|
+
| [`.github/workflows/release.yml`](.github/workflows/release.yml) | tag 触发:构建、校验、上传 Release 附件 |
|
|
186
|
+
| [`scripts/verify-pack.mjs`](scripts/verify-pack.mjs) | 校验附件里带着运行时要加载的文件(构建链的看门人) |
|
|
187
|
+
| [`assets/`](assets/) | README 用的截图;GitHub 直接渲染,不随 npm 包发布 |
|
|
188
|
+
|
|
189
|
+
### 依赖面
|
|
190
|
+
|
|
191
|
+
| 类型 | 包 | 说明 |
|
|
192
|
+
|---|---|---|
|
|
193
|
+
| 运行时 | `@deepseek-ai/schemastery` | DSH 的设置 schema 格式,`export const Config` 必需 |
|
|
194
|
+
| 构建期 | `typescript` · `tsdown` · `@types/node` | 只在 `npm run build` 时用到 |
|
|
195
|
+
| 宿主提供 | `@deepseek-ai/dsh-client-ui-primitives` | 客户端用 `tryRequire` 按需取用;宿主没有时降级为原生控件 |
|
|
196
|
+
|
|
197
|
+
**不依赖任何 DSH 类型包。** 宿主上下文由 [`src/index.ts`](src/index.ts) 里的本地 `HostContext` 接口结构化描述,所以包里没有 `@deepseek-ai/cordis`(既不是 dependency 也不是 peerDependency)。
|
|
198
|
+
|
|
199
|
+
宿主端对包只暴露四个导出:`name`、`inject`、`Config`、`apply`——其余全部是模块内私有。
|
|
200
|
+
|
|
201
|
+
### 设置行文案的语言(预留功能,默认关闭)
|
|
202
|
+
|
|
203
|
+
设置行的文案**可以**跟随思考语言而不是界面语言——选 繁體中文,这一行的标题与说明就变繁体。整套机制已经实现并接线完毕,但**当前不生效**。
|
|
204
|
+
|
|
205
|
+
| | |
|
|
206
|
+
|---|---|
|
|
207
|
+
| 开关 | [`src/client/locales.ts`](src/client/locales.ts) 里的 `COPY_FOLLOWS_THINKING_LANGUAGE`,默认 `false` |
|
|
208
|
+
| 启用 | 改成 `true` → `npm run build` → 重启 GUI |
|
|
209
|
+
| 还要改别的文件吗 | 不用。三套字典与选取函数 `dictionaryFor` 都在 `locales.ts` 里 |
|
|
210
|
+
|
|
211
|
+
因为开关是编译期常量,构建时 rolldown 会把这条死分支连同繁体字典一起摇掉——当前产物里没有这些文案,行为与「只跟随界面语言」完全一致。语言选择器的选项始终显示各语言的本族语名(简体中文 / English),所以即使文案换成了你不熟悉的语言,也能从同一个下拉里切回来。
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## 已知限制
|
|
216
|
+
|
|
217
|
+
- **section 的位置绑住宿主的分段表**:`order: 1` 取自 `@deepseek-ai/dsh-system-prompt` 的 `SECTION_ORDERS`(persona `0`、`PLAN_POLICY` `500`)。宿主若调整那张表,改 [`src/index.ts`](src/index.ts) 的 `SECTION_ORDER`。
|
|
218
|
+
- **设置行的位置绑住宿主语言项的 order**:宿主语言行注册在 `order: 0`(`@deepseek-ai/dsh-client-locale`),本插件用 `order: 1` 紧贴其后。宿主若调整,改 [`src/client/index.ts`](src/client/index.ts) 的 `ROW_ORDER` 即可。
|
|
219
|
+
- **只支持三种思考语言**:简体中文、繁體中文、English。要增删语言,改 [`src/core.ts`](src/core.ts) 的 `CATALOGUE`,并在 [`src/client/locales.ts`](src/client/locales.ts) 补上对应文案。
|
|
220
|
+
- **没有聊天命令**:切换语言只走设置页。如需 `/thinking-language`,可参照 `dsh-thinking-language` 的命令实现补上。
|
|
221
|
+
- **`auto` 依赖运行时能报出系统语言**:Linux/macOS 走环境变量,Windows 走 `Intl`。两者都拿不到时会静默落到界面语言,再不行才是 `zh-CN`——顺序与取值方式见上文「`auto` 是怎么判定的」。
|
|
222
|
+
- **插件 id 与设置命名空间**:两者都是 `ay-dsh-tk-lang`,占的是一套自有命名;包名 `dsh-thinking-lang` 与 `dsh-thinking-language` 这类仍然相似,注意区分。不过功能重复的插件同时装上,设置页会各插一行、各自注入提示词,功能上仍是重复的。
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## License
|
|
227
|
+
|
|
228
|
+
MIT,见 [LICENSE](LICENSE)。
|
package/client/client.js
ADDED
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: "dsh-thinking-lang",
|
|
3
|
+
factory: (require) => {
|
|
4
|
+
const module = { exports: {} };
|
|
5
|
+
const exports = module.exports;
|
|
6
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
|
+
let react = require("react");
|
|
8
|
+
//#region src/core.ts
|
|
9
|
+
/**
|
|
10
|
+
* The catalogue, in picker order.
|
|
11
|
+
* 语言目录,按选择器顺序排列。
|
|
12
|
+
*
|
|
13
|
+
* A tag that carries no region (`en`) is reachable through its bare primary
|
|
14
|
+
* subtag as well; one that does carry a region (`zh-CN`, `zh-TW`) is not. That
|
|
15
|
+
* asymmetry is what the resolution order in {@link tagForLocale} relies on, so
|
|
16
|
+
* it needs no extra flag on the entries.
|
|
17
|
+
* 不含地区的标签(`en`)也可以由裸主语言标签命中,含地区的(`zh-CN`、`zh-TW`)则
|
|
18
|
+
* 不能。{@link tagForLocale} 的解析顺序正是建立在这一不对称之上,因此条目本身不必
|
|
19
|
+
* 额外带标记。
|
|
20
|
+
*/
|
|
21
|
+
const CATALOGUE = [
|
|
22
|
+
{
|
|
23
|
+
tag: "zh-CN",
|
|
24
|
+
nativeName: "简体中文",
|
|
25
|
+
section: "推理规则:思考、推理与规划一律使用简体中文。回复用户时使用用户所用的语言。",
|
|
26
|
+
reminder: "继续用简体中文思考、推理与规划。"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
tag: "zh-TW",
|
|
30
|
+
nativeName: "繁體中文",
|
|
31
|
+
section: "推理規則:思考、推理與規劃一律使用繁體中文。回覆使用者時使用使用者所用的語言。",
|
|
32
|
+
reminder: "繼續用繁體中文思考、推理與規劃。"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
tag: "en",
|
|
36
|
+
nativeName: "English",
|
|
37
|
+
section: "Reasoning rules: think, reason, and plan in English. Reply to the user in the language they use.",
|
|
38
|
+
reminder: "Keep thinking, reasoning, and planning in English."
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
/** The sentinel meaning "follow the host locale". / 表示「跟随宿主语言」的哨兵值。 */
|
|
42
|
+
const AUTO = "auto";
|
|
43
|
+
/** Settings namespace owned by this plugin. / 本插件拥有的设置命名空间。 */
|
|
44
|
+
const SETTINGS_NAMESPACE = "ay-dsh-tk-lang";
|
|
45
|
+
/** The one field this plugin stores. / 本插件唯一保存的字段。 */
|
|
46
|
+
const FIELD_LANGUAGE = "language";
|
|
47
|
+
CATALOGUE.map((language) => language.tag);
|
|
48
|
+
/** Configuration applied when the field is absent. / 字段缺失时采用的配置。 */
|
|
49
|
+
const DEFAULTS = { language: AUTO };
|
|
50
|
+
/** Catalogue lookup keyed by lower-cased tag. / 以小写标签为键的目录索引。 */
|
|
51
|
+
const BY_TAG = new Map(CATALOGUE.map((language) => [language.tag.toLowerCase(), language]));
|
|
52
|
+
/**
|
|
53
|
+
* Look up a catalogue entry by language tag.
|
|
54
|
+
* 按语言标签查找目录条目。
|
|
55
|
+
*/
|
|
56
|
+
function languageOf(tag) {
|
|
57
|
+
if (tag === "" || tag === "auto") return void 0;
|
|
58
|
+
return BY_TAG.get(tag.toLowerCase());
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Return the native name of a language tag, for display in the picker.
|
|
62
|
+
* 返回语言标签的本族语名,用于选择器展示。
|
|
63
|
+
*/
|
|
64
|
+
function nativeNameFor(tag) {
|
|
65
|
+
return languageOf(tag)?.nativeName;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Coerce an untrusted settings section into a complete configuration.
|
|
69
|
+
* 把不可信的设置段强制转换为完整配置。
|
|
70
|
+
*/
|
|
71
|
+
function normalizeSettings(raw) {
|
|
72
|
+
const stored = raw !== null && typeof raw === "object" && !Array.isArray(raw) ? raw[FIELD_LANGUAGE] : void 0;
|
|
73
|
+
return { language: typeof stored === "string" && stored !== "" ? stored : DEFAULTS.language };
|
|
74
|
+
}
|
|
75
|
+
/** Dictionaries keyed by UI locale, handed to the host locale service. / 以界面语言为键、交给宿主 locale 服务的字典。 */
|
|
76
|
+
const dictionaries = {
|
|
77
|
+
zh: {
|
|
78
|
+
heading: "思考语言",
|
|
79
|
+
description: "内部推理与规划使用的语言。「自动」优先跟随操作系统语言,其次是界面语言。",
|
|
80
|
+
autoLabel: "自动"
|
|
81
|
+
},
|
|
82
|
+
en: {
|
|
83
|
+
heading: "Thinking language",
|
|
84
|
+
description: "Language used for internal reasoning and planning. Automatic follows the operating-system language first, then the UI language.",
|
|
85
|
+
autoLabel: "Automatic"
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/client/panel.ts
|
|
90
|
+
/**
|
|
91
|
+
* The settings row: one language picker bound to the plugin's settings document.
|
|
92
|
+
* 设置行:一个绑定到本插件设置文档的语言选择器。
|
|
93
|
+
*
|
|
94
|
+
* It is registered into the General settings page (see `./index.ts`) rather than
|
|
95
|
+
* as a section of its own, so it sits directly under the host's language row.
|
|
96
|
+
* 它注册进「通用」设置页(见 `./index.ts`)而不是自成菜单,因此紧邻宿主自身的
|
|
97
|
+
* 语言设置项下方。
|
|
98
|
+
*
|
|
99
|
+
* The row owns no state of its own: it reads the host's settings document,
|
|
100
|
+
* subscribes to it, and writes the single field back.
|
|
101
|
+
* 本行不持有自己的状态:它读取宿主的设置文档、订阅其变化,并回写那唯一一个字段。
|
|
102
|
+
*/
|
|
103
|
+
/**
|
|
104
|
+
* Read and normalize the current settings, falling back to defaults on refusal.
|
|
105
|
+
* 读取并归一化当前设置;被拒绝时回退到默认值。
|
|
106
|
+
*/
|
|
107
|
+
function readSettings(doc) {
|
|
108
|
+
try {
|
|
109
|
+
return normalizeSettings(doc.getSnapshot()?.value);
|
|
110
|
+
} catch {
|
|
111
|
+
return DEFAULTS;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Write one field back, swallowing a refusal so a read-only host cannot break the row.
|
|
116
|
+
* 回写单个字段,并吞掉拒绝异常,使只读宿主不会让这一行崩溃。
|
|
117
|
+
*
|
|
118
|
+
* A host may return a promise instead of a value; an unhandled rejection from a
|
|
119
|
+
* read-only document is not worth surfacing, so it is discarded here.
|
|
120
|
+
* 宿主可能返回 promise 而不是值;只读文档产生的未处理拒绝不值得上抛,因此在此丢弃。
|
|
121
|
+
*/
|
|
122
|
+
function writeField(doc, field, value) {
|
|
123
|
+
try {
|
|
124
|
+
const outcome = doc.set(field, value);
|
|
125
|
+
if (typeof outcome?.then === "function") outcome.then(void 0, () => {});
|
|
126
|
+
} catch {}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Build the row component bound to the host's UI primitives.
|
|
130
|
+
* 构建绑定到宿主 UI 原语的行组件。
|
|
131
|
+
*/
|
|
132
|
+
function createRow(primitives) {
|
|
133
|
+
const Menu = primitives?.Menu;
|
|
134
|
+
const Chevron = primitives?.IconChevronDownOutlineRegular ?? primitives?.IconChevronDownOutline14 ?? primitives?.IconChevronDownOutlineMedium;
|
|
135
|
+
return function ThinkingLanguageRow(props) {
|
|
136
|
+
const { doc, t: hostT } = props;
|
|
137
|
+
const [settings, setSettings] = (0, react.useState)(() => readSettings(doc));
|
|
138
|
+
const [open, setOpen] = (0, react.useState)(false);
|
|
139
|
+
settings.language;
|
|
140
|
+
const t = (key) => hostT(key);
|
|
141
|
+
(0, react.useEffect)(() => {
|
|
142
|
+
const sync = () => setSettings(readSettings(doc));
|
|
143
|
+
sync();
|
|
144
|
+
return doc.subscribe(sync);
|
|
145
|
+
}, [doc]);
|
|
146
|
+
const items = [{
|
|
147
|
+
id: AUTO,
|
|
148
|
+
label: t("autoLabel")
|
|
149
|
+
}, ...CATALOGUE.map((language) => ({
|
|
150
|
+
id: language.tag,
|
|
151
|
+
label: language.nativeName
|
|
152
|
+
}))];
|
|
153
|
+
const activeLabel = settings.language === "auto" ? t("autoLabel") : nativeNameFor(settings.language) ?? settings.language;
|
|
154
|
+
const close = () => setOpen(false);
|
|
155
|
+
const toggle = () => setOpen((value) => !value);
|
|
156
|
+
const choose = (id) => {
|
|
157
|
+
writeField(doc, FIELD_LANGUAGE, id);
|
|
158
|
+
close();
|
|
159
|
+
};
|
|
160
|
+
const picker = (0, react.createElement)("button", {
|
|
161
|
+
type: "button",
|
|
162
|
+
className: "dsh_desk_lang_picker",
|
|
163
|
+
"aria-haspopup": "menu",
|
|
164
|
+
"aria-expanded": open,
|
|
165
|
+
onClick: toggle
|
|
166
|
+
}, activeLabel, Chevron === void 0 ? null : (0, react.createElement)(Chevron, { className: "dsh_desk_lang_chevron" }));
|
|
167
|
+
const control = Menu ? (0, react.createElement)(Menu, {
|
|
168
|
+
open,
|
|
169
|
+
anchor: picker,
|
|
170
|
+
items,
|
|
171
|
+
selectedId: settings.language,
|
|
172
|
+
align: "end",
|
|
173
|
+
portal: true,
|
|
174
|
+
onClose: close,
|
|
175
|
+
onSelect: choose
|
|
176
|
+
}) : picker;
|
|
177
|
+
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" }, t("heading")), (0, react.createElement)("div", { className: "dsh_desk_lang_desc" }, t("description"))), control);
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
const rowCss = [
|
|
181
|
+
".dsh_desk_lang_row{border-bottom:.5px solid var(--dsw-alias-border-l2);align-items:center;gap:8px;padding:16px 0;display:flex}",
|
|
182
|
+
".dsh_desk_lang_text{flex-direction:column;flex:1;gap:4px;min-width:0;padding-right:48px;display:flex}",
|
|
183
|
+
".dsh_desk_lang_title{color:var(--dsw-alias-label-primary);font-size:14px;font-weight:400;line-height:22px}",
|
|
184
|
+
".dsh_desk_lang_desc{color:var(--dsw-alias-label-tertiary);font-size:12px;font-weight:400;line-height:18px}",
|
|
185
|
+
".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}",
|
|
186
|
+
".dsh_desk_lang_picker:hover{background:var(--dsw-alias-interactive-bg-hover)}",
|
|
187
|
+
".dsh_desk_lang_chevron{flex:none}"
|
|
188
|
+
].join("\n");
|
|
189
|
+
/** Marks the injected stylesheet, so a second mount can detect the first. / 标记已注入的样式表,使第二次挂载能发现第一次。 */
|
|
190
|
+
const STYLE_MARKER = "dsh-thinking-lang";
|
|
191
|
+
/**
|
|
192
|
+
* Inject the row stylesheet once per document, replacing a stale one.
|
|
193
|
+
* 每份文档只注入一次行样式表,已过期的那张会被替换。
|
|
194
|
+
*
|
|
195
|
+
* The guard reads the document rather than a module-level flag: a client plugin
|
|
196
|
+
* can be mounted more than once against the same page, and only the DOM knows
|
|
197
|
+
* whether this sheet is already there. Content is compared as well, because a
|
|
198
|
+
* hot-reloaded bundle keeps its marker while its CSS changes; skipping on the
|
|
199
|
+
* marker alone would leave the row styled by class names that no longer exist.
|
|
200
|
+
* 判重依据是文档本身而不是模块级标志:客户端插件可能被重复挂载到同一页面,只有 DOM
|
|
201
|
+
* 知道这张样式表是否已经存在。同时比对内容:热重载的 bundle 标记不变而 CSS 已变,
|
|
202
|
+
* 只看标记就跳过会让这一行按已不存在的类名取样式。
|
|
203
|
+
*/
|
|
204
|
+
function mountRowStyles() {
|
|
205
|
+
if (typeof document === "undefined") return;
|
|
206
|
+
const existing = document.head.querySelector(`style[data-plugin=${JSON.stringify(STYLE_MARKER)}]`);
|
|
207
|
+
if (existing !== null) {
|
|
208
|
+
if (existing.textContent === rowCss) return;
|
|
209
|
+
existing.remove();
|
|
210
|
+
}
|
|
211
|
+
const style = document.createElement("style");
|
|
212
|
+
style.dataset.plugin = STYLE_MARKER;
|
|
213
|
+
style.dataset.pluginCss = `${STYLE_MARKER}/row.css`;
|
|
214
|
+
style.textContent = rowCss;
|
|
215
|
+
document.head.append(style);
|
|
216
|
+
}
|
|
217
|
+
//#endregion
|
|
218
|
+
//#region src/client/index.ts
|
|
219
|
+
/**
|
|
220
|
+
* Client entry: registers the plugin's settings row in General settings.
|
|
221
|
+
* 客户端入口:在「通用」设置页注册本插件的设置行。
|
|
222
|
+
*
|
|
223
|
+
* The row is registered through the `settings.general.item` slot, which the
|
|
224
|
+
* settings shell renders as one item on the General page — directly under the
|
|
225
|
+
* host's own language row.
|
|
226
|
+
* 该行通过 `settings.general.item` 插槽注册;设置外壳把它渲染成「通用」页上的
|
|
227
|
+
* 一个条目——紧邻宿主自身的语言设置项下方。
|
|
228
|
+
*/
|
|
229
|
+
/** Stable Cordis plugin name. / 稳定的 Cordis 插件名。 */
|
|
230
|
+
const name = "ay-dsh-tk-lang";
|
|
231
|
+
/** The one client service this plugin requires. / 本插件唯一需要的客户端服务。 */
|
|
232
|
+
const inject = ["slots"];
|
|
233
|
+
/** Locale namespace holding the row copy. / 保存行文案的 locale 命名空间。 */
|
|
234
|
+
const LOCALE_NS = "ay-dsh-tk-lang";
|
|
235
|
+
/**
|
|
236
|
+
* Position on the General page, sorted ascending. The host's own language row
|
|
237
|
+
* registers at `order: 0` (dsh-client-locale) and the next known row — chat's
|
|
238
|
+
* "link opening" — sits at 17, so 1 lands directly beneath the language row.
|
|
239
|
+
* 在「通用」页中的位置,按 order 升序排列。宿主自己的语言行注册在 `order: 0`
|
|
240
|
+
* (dsh-client-locale),下一个已知项——对话的「链接打开方式」——是 17,因此取
|
|
241
|
+
* 1 即可紧贴在语言行下方。
|
|
242
|
+
*/
|
|
243
|
+
const ROW_ORDER = 1;
|
|
244
|
+
/**
|
|
245
|
+
* Require one of several module ids, returning the first that resolves.
|
|
246
|
+
* 依次尝试 require 若干模块 id,返回第一个成功解析的结果。
|
|
247
|
+
*
|
|
248
|
+
* The host decides which optional modules exist, so a miss is expected rather
|
|
249
|
+
* than exceptional and simply moves on to the next candidate.
|
|
250
|
+
* 可选模块是否存在由宿主决定,因此未命中属于预期情况而非异常,直接尝试下一个即可。
|
|
251
|
+
*/
|
|
252
|
+
function tryRequire(...names) {
|
|
253
|
+
for (const name of names) try {
|
|
254
|
+
const mod = require(name);
|
|
255
|
+
if (mod != null) return mod;
|
|
256
|
+
} catch {}
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Report a client-side problem through the host logger when one exists.
|
|
260
|
+
* 在宿主提供 logger 时,通过它报告客户端问题。
|
|
261
|
+
*/
|
|
262
|
+
function report(ctx, message, error) {
|
|
263
|
+
const logger = ctx.get("logger");
|
|
264
|
+
const line = `dsh-thinking-lang: ${message}`;
|
|
265
|
+
(typeof logger?.warn === "function" ? logger.warn.bind(logger) : console.warn)(line, ...error === void 0 ? [] : [error]);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Register the dictionaries, the settings document binding, and the General row.
|
|
269
|
+
* 注册字典、绑定设置文档,并登记「通用」页上的设置行。
|
|
270
|
+
*/
|
|
271
|
+
function apply(ctx) {
|
|
272
|
+
ctx.inject(["configForms", "locale"], (uiCtx) => {
|
|
273
|
+
const forms = uiCtx.get("configForms");
|
|
274
|
+
const locale = uiCtx.get("locale");
|
|
275
|
+
if (!forms || typeof forms.get !== "function") {
|
|
276
|
+
report(uiCtx, "configForms service unavailable; settings row disabled");
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
if (!locale || typeof locale.register !== "function" || typeof locale.bind !== "function") {
|
|
280
|
+
report(uiCtx, "locale service unavailable; settings row disabled");
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
uiCtx.effect(() => locale.register(LOCALE_NS, dictionaries), "dsh-thinking-lang: dictionaries");
|
|
284
|
+
const t = locale.bind(LOCALE_NS);
|
|
285
|
+
const doc = forms.get(SETTINGS_NAMESPACE);
|
|
286
|
+
const primitives = tryRequire("@deepseek-ai/dsh-client-ui-primitives");
|
|
287
|
+
mountRowStyles();
|
|
288
|
+
const Row = createRow(primitives);
|
|
289
|
+
uiCtx.slots.inject("settings.general.item", function* registerRow() {
|
|
290
|
+
yield uiCtx.slots.register({
|
|
291
|
+
name: "settings.general.item",
|
|
292
|
+
id: "ay-dsh-tk-lang",
|
|
293
|
+
order: ROW_ORDER,
|
|
294
|
+
locale: LOCALE_NS,
|
|
295
|
+
inject: () => ({
|
|
296
|
+
doc,
|
|
297
|
+
t
|
|
298
|
+
})
|
|
299
|
+
}, Row);
|
|
300
|
+
});
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
//#endregion
|
|
304
|
+
exports.apply = apply;
|
|
305
|
+
exports.inject = inject;
|
|
306
|
+
exports.name = name;
|
|
307
|
+
return module.exports;
|
|
308
|
+
}
|
|
309
|
+
});
|