dsh-pin-default-model 0.0.0-stage → 1.3.0
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 +22 -0
- package/README.md +99 -2
- package/README.zh.md +100 -0
- package/client/client.js +437 -0
- package/cordis.patch.yml +9 -0
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/docs/preview.svg +31 -0
- package/docs/preview.zh.svg +31 -0
- package/docs//351/234/200/346/261/202/345/210/206/346/236/220-/346/216/250/347/220/206/347/255/211/347/272/247/351/224/201/345/256/232-20261118.md +244 -0
- package/icon.svg +8 -0
- package/lib/index.js +361 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +65 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 dsh-archive-pro contributors
|
|
4
|
+
Copyright (c) 2026 dsh-archive-manager-plus contributors
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,100 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-pin-default-model
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
English | [简体中文](./README.zh.md)
|
|
4
|
+
|
|
5
|
+
Pins the DeepSeek Harness default model **and reasoning effort**, so switching either inside a session never changes what the next new session starts with. Change the pin any time from **Settings → Default model pin**.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## The problem
|
|
10
|
+
|
|
11
|
+
DSH records a model change made inside a session as the new process-wide default. In `sessionController.selectModel()` the choice is applied to the session, and then `agentDefaultModel.saveSelection()` rewrites the profile patch with the same selection.
|
|
12
|
+
|
|
13
|
+
The visible effect: every new conversation — hand-made or created by a scheduled task — silently inherits whatever model you picked last, instead of the default you configured. There is no setting that turns this off.
|
|
14
|
+
|
|
15
|
+
## What this plugin does
|
|
16
|
+
|
|
17
|
+
It replaces `saveSelection` on the live `agentDefaultModel` service with one that refuses to move the default away from the pin:
|
|
18
|
+
|
|
19
|
+
| Action | Result |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| Switch models inside a session | ✅ works, that session uses the new model |
|
|
22
|
+
| Switch reasoning effort inside a session | ✅ works, that session uses the new effort |
|
|
23
|
+
| New session afterwards | ✅ still starts on the pinned model and effort |
|
|
24
|
+
| Change the pin in Settings | ✅ applies to all later new sessions |
|
|
25
|
+
| Unload the plugin | ✅ original behaviour returns |
|
|
26
|
+
|
|
27
|
+
The pin is a routing triple: provider, model, and an optional reasoning effort. The browser page talks to two local host routes with plain fetch; it has no dependency on DSH's settings-client services, so it loads regardless of plugin activation order.
|
|
28
|
+
|
|
29
|
+
## Reasoning effort
|
|
30
|
+
|
|
31
|
+
The effort dropdown lists the levels the **selected model** actually offers, taken from the live model catalog.
|
|
32
|
+
|
|
33
|
+
- **Follow the model default** leaves the effort unlocked. A session may then use any effort the model offers, and the pin keeps holding only the route.
|
|
34
|
+
- **Locking an effort** (for example `high`) pins the route *and* the effort. A session that changes only its effort no longer rewrites the default.
|
|
35
|
+
|
|
36
|
+
> **A locked effort must be one the model supports.** DSH rejects a call whose effort the model does not offer (`UNSUPPORTED_REASONING_EFFORT`), and some models offer no reasoning effort at all. The plugin refuses to store such a pin and the settings page shows a warning instead of failing later at session creation.
|
|
37
|
+
|
|
38
|
+
## Configuration
|
|
39
|
+
|
|
40
|
+
Open **Settings → Default model pin** and pick a model from the grouped dropdown, then pick a reasoning effort and press **Save**. The pin is written to the profile and survives a restart.
|
|
41
|
+
|
|
42
|
+
It can also be set by hand in `cordis.patch.yml`:
|
|
43
|
+
|
|
44
|
+
```yaml
|
|
45
|
+
- insert:
|
|
46
|
+
- id: dsh-pin-default-model
|
|
47
|
+
name: 'dsh-pin-default-model'
|
|
48
|
+
config:
|
|
49
|
+
provider: magpie
|
|
50
|
+
model: group/x-call
|
|
51
|
+
reasoningEffort: high
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
| Field | Required | Meaning |
|
|
55
|
+
| --- | --- | --- |
|
|
56
|
+
| `provider` | yes | Provider route to hold, e.g. `magpie`, `workbuddy-ai` |
|
|
57
|
+
| `model` | yes | Model id on that route, e.g. `group/x-call` |
|
|
58
|
+
| `reasoningEffort` | no | Reasoning effort to hold. Omit it to let the provider default apply |
|
|
59
|
+
|
|
60
|
+
With no pin configured, the bundled default `magpie / group/x-call` applies.
|
|
61
|
+
|
|
62
|
+
A change affects sessions created **after** it is saved. An open conversation keeps the model and effort recorded in its own request log.
|
|
63
|
+
|
|
64
|
+
## Safety and caveats
|
|
65
|
+
|
|
66
|
+
- All operations are local. No telemetry, no uploads, no network calls.
|
|
67
|
+
- Every destructive-looking action is avoided: the original session model switch is untouched.
|
|
68
|
+
- **This plugin replaces an internal service method** (`agentDefaultModel.saveSelection`). A future DSH update that renames or restructures that method may make the pin ineffective. The change is installed on the live service instance and fully reverted when the plugin unloads.
|
|
69
|
+
|
|
70
|
+
## Install
|
|
71
|
+
|
|
72
|
+
From the DSH app: **Settings → Plugins → Install**, then search `dsh-pin-default-model`.
|
|
73
|
+
|
|
74
|
+
Or from a terminal:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
dsh plugin --profile web add dsh-pin-default-model
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Published on [npm](https://www.npmjs.com/package/dsh-pin-default-model).
|
|
81
|
+
|
|
82
|
+
## Requirements
|
|
83
|
+
|
|
84
|
+
- DeepSeek Harness `>= 0.2.1`
|
|
85
|
+
- Node.js ≥ 22
|
|
86
|
+
- Zero runtime dependencies
|
|
87
|
+
|
|
88
|
+
## Development
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
node --check lib/index.js
|
|
92
|
+
node --check client/client.js
|
|
93
|
+
node test/behaviour.mjs
|
|
94
|
+
node test/client.mjs
|
|
95
|
+
node test/render.mjs
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## License
|
|
99
|
+
|
|
100
|
+
MIT. See [LICENSE](./LICENSE).
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# dsh-pin-default-model
|
|
2
|
+
|
|
3
|
+
[English](./README.md) | 简体中文
|
|
4
|
+
|
|
5
|
+
锁定 DeepSeek Harness 的默认模型**与推理等级**,让「会话内切换模型或推理等级」不再影响下一个新会话。随时可在 **设置 → 默认模型锁定** 修改锁定值。
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## 它解决什么问题
|
|
10
|
+
|
|
11
|
+
DSH 会把「在会话里切换模型」记录成新的进程级默认值。`sessionController.selectModel()` 里,选择先应用到当前会话,紧接着 `agentDefaultModel.saveSelection()` 用同一个选择改写 profile 补丁。
|
|
12
|
+
|
|
13
|
+
实际表现:每个新对话——手动建的、自动化任务建的——都悄悄继承您最后一次选的模型,而不是您配置的默认值。设置里没有开关能关掉这个行为。
|
|
14
|
+
|
|
15
|
+
## 这个插件做什么
|
|
16
|
+
|
|
17
|
+
它把 `agentDefaultModel` 服务实例上的 `saveSelection` 换成拒绝改写默认值的版本:
|
|
18
|
+
|
|
19
|
+
| 操作 | 结果 |
|
|
20
|
+
| --- | --- |
|
|
21
|
+
| 会话内切换模型 | ✅ 正常生效,该会话用新模型 |
|
|
22
|
+
| 会话内切换推理等级 | ✅ 正常生效,该会话用新档位 |
|
|
23
|
+
| 之后新建的会话 | ✅ 仍然使用锁定的模型与推理等级 |
|
|
24
|
+
| 在设置里改锁定值 | ✅ 之后新建的会话全部用新值 |
|
|
25
|
+
| 卸载插件 | ✅ 恢复 DSH 原有行为 |
|
|
26
|
+
|
|
27
|
+
锁定值是一个三元组:provider、model,以及可选的推理等级。浏览器页面通过两条本地路由用纯 fetch 读写,不依赖 DSH 的设置客户端服务,因此不受插件加载顺序影响。
|
|
28
|
+
|
|
29
|
+
## 推理等级
|
|
30
|
+
|
|
31
|
+
推理等级下拉框列出的是**当前所选模型实际提供**的档位,来源是实时模型目录。
|
|
32
|
+
|
|
33
|
+
- **跟随模型默认**表示不锁定推理等级。会话可以自由使用该模型支持的任何档位,锁定值只约束模型路由。
|
|
34
|
+
- **锁定某个档位**(例如 `high`)则同时锁定路由和档位,会话内只切档位也不再改写默认值。
|
|
35
|
+
|
|
36
|
+
> **锁定的档位必须是该模型支持的。** DSH 对模型不支持的档位会直接报错(`UNSUPPORTED_REASONING_EFFORT`),而且部分模型完全不提供推理等级。插件会拒绝保存这类锁定值,设置页也会明确警告,而不是等到新建会话时才失败。
|
|
37
|
+
|
|
38
|
+
## 配置
|
|
39
|
+
|
|
40
|
+
打开 **设置 → 默认模型锁定**,在下拉框里选模型,再选推理等级,点 **保存**。锁定值写入 profile,重启后依然有效。
|
|
41
|
+
|
|
42
|
+
也可以手改 `cordis.patch.yml`:
|
|
43
|
+
|
|
44
|
+
```yaml
|
|
45
|
+
- insert:
|
|
46
|
+
- id: dsh-pin-default-model
|
|
47
|
+
name: 'dsh-pin-default-model'
|
|
48
|
+
config:
|
|
49
|
+
provider: magpie
|
|
50
|
+
model: group/x-call
|
|
51
|
+
reasoningEffort: high
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
| 字段 | 必填 | 含义 |
|
|
55
|
+
| --- | --- | --- |
|
|
56
|
+
| `provider` | 是 | 要锁定的提供方路由,如 `magpie`、`workbuddy-ai` |
|
|
57
|
+
| `model` | 是 | 该路由下的模型 id,如 `group/x-call` |
|
|
58
|
+
| `reasoningEffort` | 否 | 要锁定的推理等级。省略则跟随提供方默认 |
|
|
59
|
+
|
|
60
|
+
没有配置锁定值时,使用内置的 `magpie / group/x-call`。
|
|
61
|
+
|
|
62
|
+
改动只对**保存之后**新建的会话生效;已经打开的对话继续使用它请求日志里记录的模型与推理等级。
|
|
63
|
+
|
|
64
|
+
## 安全性与注意
|
|
65
|
+
|
|
66
|
+
- 全部操作在本机完成,无遥测、无上传、无网络请求。
|
|
67
|
+
- 不改动会话内正常的模型切换。
|
|
68
|
+
- **本插件替换了一个内部服务方法**(`agentDefaultModel.saveSelection`)。若未来 DSH 升级改名或调整该方法结构,锁定可能失效。替换发生在服务实例上,卸载插件时会完全还原。
|
|
69
|
+
|
|
70
|
+
## 安装
|
|
71
|
+
|
|
72
|
+
在 DSH 应用里打开 **设置 → 插件 → 安装**,搜索 `dsh-pin-default-model`。
|
|
73
|
+
|
|
74
|
+
或在终端执行:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
dsh plugin --profile web add dsh-pin-default-model
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
已发布到 [npm](https://www.npmjs.com/package/dsh-pin-default-model)。
|
|
81
|
+
|
|
82
|
+
## 环境要求
|
|
83
|
+
|
|
84
|
+
- DeepSeek Harness `>= 0.2.1`
|
|
85
|
+
- Node.js ≥ 22
|
|
86
|
+
- 零运行时依赖
|
|
87
|
+
|
|
88
|
+
## 开发
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
node --check lib/index.js
|
|
92
|
+
node --check client/client.js
|
|
93
|
+
node test/behaviour.mjs
|
|
94
|
+
node test/client.mjs
|
|
95
|
+
node test/render.mjs
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## 许可
|
|
99
|
+
|
|
100
|
+
MIT,见 [LICENSE](./LICENSE)。
|
package/client/client.js
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-pin-default-model browser half: a Settings section for choosing which
|
|
3
|
+
* model and reasoning effort every new conversation starts on.
|
|
4
|
+
*
|
|
5
|
+
* All state lives on the host; this page only talks to two local routes with
|
|
6
|
+
* plain fetch. It deliberately avoids the settings-client services so it can
|
|
7
|
+
* load regardless of plugin activation order.
|
|
8
|
+
*
|
|
9
|
+
* The catalog exposes `reasoning.efforts` as an array of `{ id, name }`, so
|
|
10
|
+
* the effort dropdown lists effort ids and shows their display names.
|
|
11
|
+
*/
|
|
12
|
+
window.__ModuleLoader__.load({
|
|
13
|
+
id: "dsh-pin-default-model",
|
|
14
|
+
factory: (require) => {
|
|
15
|
+
var module = { exports: {} };
|
|
16
|
+
var exports = module.exports;
|
|
17
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
18
|
+
let react = require("react");
|
|
19
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
20
|
+
|
|
21
|
+
const NS = "dsh-pin-default-model";
|
|
22
|
+
const VIEW_URL = "/dsh-pin-model/view";
|
|
23
|
+
const SET_URL = "/dsh-pin-model/set";
|
|
24
|
+
|
|
25
|
+
const zh = {
|
|
26
|
+
nav: "默认模型锁定",
|
|
27
|
+
desc: "锁定新建会话使用的模型与推理等级。在会话内切换模型或推理等级仍然只对那个会话生效,不会改写这里的设置。",
|
|
28
|
+
current: "当前锁定",
|
|
29
|
+
notSet: "未设置(使用插件默认值 magpie/group/x-call)",
|
|
30
|
+
choose: "选择模型",
|
|
31
|
+
save: "保存",
|
|
32
|
+
saving: "保存中…",
|
|
33
|
+
saved: "已保存",
|
|
34
|
+
loadFailed: "读取失败。",
|
|
35
|
+
saveFailed: "保存失败。",
|
|
36
|
+
loading: "加载中…",
|
|
37
|
+
noCatalog: "没有可用模型。",
|
|
38
|
+
noCatalogHint: "请先在设置 → 模型里配置至少一个提供方。",
|
|
39
|
+
effort: "推理等级",
|
|
40
|
+
effortDefault: "跟随模型默认",
|
|
41
|
+
effortNone: "该模型不提供推理等级。",
|
|
42
|
+
effortSuggested: "建议锁定 high",
|
|
43
|
+
effortLockHigh: "锁定 high",
|
|
44
|
+
effortFollow: "改为跟随模型默认",
|
|
45
|
+
effortIncompatible: "当前模型不支持推理等级",
|
|
46
|
+
effortIncompatibleDetail: "该模型只支持:",
|
|
47
|
+
reset: "刷新",
|
|
48
|
+
unavailable: "该模型当前不在可用目录中(仍会按此值锁定)。",
|
|
49
|
+
note: "锁定值写入 profile 配置。修改后对新建会话立即生效,已打开的会话保持不变。"
|
|
50
|
+
};
|
|
51
|
+
const en = {
|
|
52
|
+
nav: "Default model pin",
|
|
53
|
+
desc: "Hold the model and reasoning effort that new conversations start on. Switching either inside a session still applies to that session only and no longer rewrites this setting.",
|
|
54
|
+
current: "Currently pinned",
|
|
55
|
+
notSet: "Not set — the bundled default magpie/group/x-call applies",
|
|
56
|
+
choose: "Choose a model",
|
|
57
|
+
save: "Save",
|
|
58
|
+
saving: "Saving…",
|
|
59
|
+
saved: "Saved",
|
|
60
|
+
loadFailed: "Could not load the current pin.",
|
|
61
|
+
saveFailed: "Save failed.",
|
|
62
|
+
loading: "Loading…",
|
|
63
|
+
noCatalog: "No models available.",
|
|
64
|
+
noCatalogHint: "Configure at least one provider in Settings → Models first.",
|
|
65
|
+
effort: "Reasoning effort",
|
|
66
|
+
effortDefault: "Follow the model default",
|
|
67
|
+
effortNone: "This model offers no reasoning effort.",
|
|
68
|
+
effortSuggested: "Suggested: lock high",
|
|
69
|
+
effortLockHigh: "Lock high",
|
|
70
|
+
effortFollow: "Follow the model default instead",
|
|
71
|
+
effortIncompatible: "The current model does not support this reasoning effort",
|
|
72
|
+
effortIncompatibleDetail: "Supported:",
|
|
73
|
+
reset: "Refresh",
|
|
74
|
+
unavailable: "This model is not in the current catalog (the pin still uses it).",
|
|
75
|
+
note: "The pin is written to the profile. A change applies to new conversations immediately; open conversations stay as they are."
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const box = {
|
|
79
|
+
padding: "5px 10px",
|
|
80
|
+
borderRadius: 6,
|
|
81
|
+
border: "1px solid var(--dsh-border, rgba(128,128,128,.35))",
|
|
82
|
+
background: "var(--dsw-alias-bg-overlay, rgba(128,128,128,.08))",
|
|
83
|
+
color: "inherit",
|
|
84
|
+
fontSize: 12,
|
|
85
|
+
outline: "none"
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/** Render `provider/model`, or a placeholder when nothing is pinned. */
|
|
89
|
+
function labelOf(selection, emptyText) {
|
|
90
|
+
if (!selection?.provider || !selection?.model) return emptyText;
|
|
91
|
+
return `${selection.provider}/${selection.model}`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Find one model in a provider-grouped catalog.
|
|
96
|
+
* @param groups - provider groups from the model catalog.
|
|
97
|
+
* @param provider - provider id.
|
|
98
|
+
* @param model - model id.
|
|
99
|
+
* @returns the catalog entry, or undefined.
|
|
100
|
+
*/
|
|
101
|
+
function findModel(groups, provider, model) {
|
|
102
|
+
const group = (groups ?? []).find((candidate) => candidate?.id === provider);
|
|
103
|
+
if (group === undefined) return undefined;
|
|
104
|
+
return (group.models ?? []).find((candidate) => candidate?.id === model);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* List the reasoning efforts of one model route.
|
|
109
|
+
* The catalog exposes `efforts` as an array of `{ id, name }`.
|
|
110
|
+
* @param groups - provider groups from the model catalog.
|
|
111
|
+
* @param provider - provider id.
|
|
112
|
+
* @param model - model id.
|
|
113
|
+
* @returns an array of `{ id, name }` entries.
|
|
114
|
+
*/
|
|
115
|
+
function effortsOf(groups, provider, model) {
|
|
116
|
+
const entry = findModel(groups, provider, model);
|
|
117
|
+
const efforts = entry?.reasoning?.efforts;
|
|
118
|
+
if (!Array.isArray(efforts)) return [];
|
|
119
|
+
return efforts
|
|
120
|
+
.filter((effort) => typeof effort?.id === 'string' && effort.id !== '')
|
|
121
|
+
.map((effort) => ({ id: effort.id, name: effort.name ?? effort.id }));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function PinSection({ t }) {
|
|
125
|
+
const [loading, setLoading] = react.useState(true);
|
|
126
|
+
const [pinned, setPinned] = react.useState(null);
|
|
127
|
+
const [groups, setGroups] = react.useState([]);
|
|
128
|
+
const [draft, setDraft] = react.useState(null);
|
|
129
|
+
const [busy, setBusy] = react.useState(false);
|
|
130
|
+
const [error, setError] = react.useState(null);
|
|
131
|
+
const [saved, setSaved] = react.useState(false);
|
|
132
|
+
|
|
133
|
+
const load = react.useCallback(() => {
|
|
134
|
+
setLoading(true);
|
|
135
|
+
setError(null);
|
|
136
|
+
fetch(VIEW_URL, { cache: "no-store" })
|
|
137
|
+
.then((res) => res.json())
|
|
138
|
+
.then((body) => {
|
|
139
|
+
if (body && body.ok === true) {
|
|
140
|
+
setPinned(body.selection ?? null);
|
|
141
|
+
setGroups(Array.isArray(body.groups) ? body.groups : []);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
setError(t("loadFailed"));
|
|
145
|
+
}
|
|
146
|
+
})
|
|
147
|
+
.catch(() => setError(t("loadFailed")))
|
|
148
|
+
.finally(() => setLoading(false));
|
|
149
|
+
}, [t]);
|
|
150
|
+
|
|
151
|
+
react.useEffect(() => {
|
|
152
|
+
load();
|
|
153
|
+
}, [load]);
|
|
154
|
+
|
|
155
|
+
const effective = draft ?? pinned ?? {};
|
|
156
|
+
const effectiveProvider = effective.provider;
|
|
157
|
+
const effectiveModel = effective.model;
|
|
158
|
+
|
|
159
|
+
// Efforts belong to one exact model route, so they follow the selection.
|
|
160
|
+
const efforts = react.useMemo(
|
|
161
|
+
() => effortsOf(groups, effectiveProvider, effectiveModel),
|
|
162
|
+
[groups, effectiveProvider, effectiveModel],
|
|
163
|
+
);
|
|
164
|
+
const effortIds = efforts.map((effort) => effort.id);
|
|
165
|
+
const supportsHigh = effortIds.includes("high");
|
|
166
|
+
|
|
167
|
+
// A locked effort the current model cannot serve is a hard DSH error at
|
|
168
|
+
// call time, so it is called out here instead of failing silently later.
|
|
169
|
+
const lockedEffort = effective.reasoningEffort;
|
|
170
|
+
const effortIncompatible = Boolean(
|
|
171
|
+
lockedEffort && effortIds.length > 0 && !effortIds.includes(lockedEffort),
|
|
172
|
+
);
|
|
173
|
+
const effortUnsupported = Boolean(lockedEffort && effortIds.length === 0);
|
|
174
|
+
|
|
175
|
+
const pickModel = (provider, model) => {
|
|
176
|
+
// Carry over a locked effort only when the new route supports it.
|
|
177
|
+
const nextEfforts = effortsOf(groups, provider, model).map((effort) => effort.id);
|
|
178
|
+
const carried = lockedEffort && nextEfforts.includes(lockedEffort) ? lockedEffort : undefined;
|
|
179
|
+
setDraft({
|
|
180
|
+
provider,
|
|
181
|
+
model,
|
|
182
|
+
...(carried === undefined ? {} : { reasoningEffort: carried }),
|
|
183
|
+
});
|
|
184
|
+
setSaved(false);
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const pickEffort = (effort) => {
|
|
188
|
+
setDraft({
|
|
189
|
+
provider: effectiveProvider,
|
|
190
|
+
model: effectiveModel,
|
|
191
|
+
...(effort === "" ? {} : { reasoningEffort: effort }),
|
|
192
|
+
});
|
|
193
|
+
setSaved(false);
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const submit = react.useCallback(() => {
|
|
197
|
+
if (!draft) return;
|
|
198
|
+
setBusy(true);
|
|
199
|
+
setError(null);
|
|
200
|
+
setSaved(false);
|
|
201
|
+
fetch(SET_URL, {
|
|
202
|
+
method: "POST",
|
|
203
|
+
headers: { "content-type": "application/json" },
|
|
204
|
+
body: JSON.stringify(draft)
|
|
205
|
+
})
|
|
206
|
+
.then((res) => res.json())
|
|
207
|
+
.then((body) => {
|
|
208
|
+
if (body && body.ok === true) {
|
|
209
|
+
setPinned(body.selection);
|
|
210
|
+
setSaved(true);
|
|
211
|
+
setDraft(null);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
setError(`${t("saveFailed")} ${body?.error ?? ""}`.trim());
|
|
215
|
+
}
|
|
216
|
+
})
|
|
217
|
+
.catch((reason) => setError(`${t("saveFailed")} ${reason instanceof Error ? reason.message : String(reason)}`))
|
|
218
|
+
.finally(() => setBusy(false));
|
|
219
|
+
}, [draft, t]);
|
|
220
|
+
|
|
221
|
+
if (loading) {
|
|
222
|
+
return react_jsx_runtime.jsx("div", { style: { padding: 12, opacity: 0.75 }, children: t("loading") });
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const fromCatalog = Boolean(
|
|
226
|
+
groups.some((g) => g.id === pinned?.provider && g.models?.some((m) => m.id === pinned?.model)),
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
return react_jsx_runtime.jsxs("div", {
|
|
230
|
+
style: { display: "flex", flexDirection: "column", gap: 12, padding: "4px 0" },
|
|
231
|
+
children: [
|
|
232
|
+
react_jsx_runtime.jsx("div", { style: { fontSize: 13, opacity: 0.82, lineHeight: 1.55 }, children: t("desc") }),
|
|
233
|
+
|
|
234
|
+
react_jsx_runtime.jsxs("div", {
|
|
235
|
+
style: {
|
|
236
|
+
display: "flex",
|
|
237
|
+
flexDirection: "column",
|
|
238
|
+
gap: 10,
|
|
239
|
+
padding: "12px 14px",
|
|
240
|
+
borderRadius: 8,
|
|
241
|
+
border: "1px solid var(--dsh-border, rgba(128,128,128,.24))",
|
|
242
|
+
background: "rgba(128,128,128,.04)"
|
|
243
|
+
},
|
|
244
|
+
children: [
|
|
245
|
+
react_jsx_runtime.jsxs("div", {
|
|
246
|
+
style: { display: "flex", alignItems: "baseline", gap: 8, flexWrap: "wrap" },
|
|
247
|
+
children: [
|
|
248
|
+
react_jsx_runtime.jsx("span", { style: { fontSize: 12, opacity: 0.68 }, children: t("current") }),
|
|
249
|
+
react_jsx_runtime.jsx("code", {
|
|
250
|
+
style: {
|
|
251
|
+
fontSize: 13,
|
|
252
|
+
fontWeight: 600,
|
|
253
|
+
padding: "2px 8px",
|
|
254
|
+
borderRadius: 5,
|
|
255
|
+
background: "rgba(65,118,230,.12)",
|
|
256
|
+
color: "var(--dsw-alias-brand-primary, #4176e6)"
|
|
257
|
+
},
|
|
258
|
+
children: labelOf(pinned, t("notSet"))
|
|
259
|
+
}),
|
|
260
|
+
pinned?.reasoningEffort ? react_jsx_runtime.jsx("span", {
|
|
261
|
+
style: { fontSize: 12, opacity: 0.7 },
|
|
262
|
+
children: `${t("effort")}: ${pinned.reasoningEffort}`
|
|
263
|
+
}) : react_jsx_runtime.jsx("span", {
|
|
264
|
+
style: { fontSize: 12, opacity: 0.7 },
|
|
265
|
+
children: `${t("effort")}: ${t("effortDefault")}`
|
|
266
|
+
})
|
|
267
|
+
]
|
|
268
|
+
}),
|
|
269
|
+
|
|
270
|
+
groups.length === 0 ? react_jsx_runtime.jsxs("div", {
|
|
271
|
+
style: { fontSize: 12, opacity: 0.75, padding: "8px 0" },
|
|
272
|
+
children: [
|
|
273
|
+
react_jsx_runtime.jsx("div", { children: t("noCatalog") }),
|
|
274
|
+
react_jsx_runtime.jsx("div", { style: { opacity: 0.75, marginTop: 2 }, children: t("noCatalogHint") })
|
|
275
|
+
]
|
|
276
|
+
}) : react_jsx_runtime.jsxs("div", {
|
|
277
|
+
style: { display: "flex", gap: 8, flexWrap: "wrap", alignItems: "center" },
|
|
278
|
+
children: [
|
|
279
|
+
react_jsx_runtime.jsxs("select", {
|
|
280
|
+
value: effectiveProvider ? `${effectiveProvider}\u0000${effectiveModel}` : "",
|
|
281
|
+
disabled: busy,
|
|
282
|
+
onChange: (event) => {
|
|
283
|
+
const [provider, model] = String(event.target.value).split("\u0000");
|
|
284
|
+
if (provider && model) pickModel(provider, model);
|
|
285
|
+
},
|
|
286
|
+
style: { ...box, flex: "1 1 240px", minWidth: 190 },
|
|
287
|
+
children: [
|
|
288
|
+
react_jsx_runtime.jsx("option", { value: "", children: t("choose") }),
|
|
289
|
+
groups.map((group) => react_jsx_runtime.jsx("optgroup", {
|
|
290
|
+
label: group.name || group.id,
|
|
291
|
+
children: (group.models ?? []).map((model) => react_jsx_runtime.jsx("option", {
|
|
292
|
+
value: `${group.id}\u0000${model.id}`,
|
|
293
|
+
children: model.name && model.name !== model.id ? `${model.name} · ${model.id}` : model.id
|
|
294
|
+
}, `${group.id}:${model.id}`))
|
|
295
|
+
}, group.id))
|
|
296
|
+
]
|
|
297
|
+
}),
|
|
298
|
+
react_jsx_runtime.jsxs("select", {
|
|
299
|
+
value: lockedEffort ?? "",
|
|
300
|
+
disabled: busy || effortIds.length === 0,
|
|
301
|
+
onChange: (event) => pickEffort(String(event.target.value)),
|
|
302
|
+
style: { ...box, flex: "0 1 180px" },
|
|
303
|
+
children: [
|
|
304
|
+
react_jsx_runtime.jsx("option", { value: "", children: t("effortDefault") }),
|
|
305
|
+
efforts.map((effort) => react_jsx_runtime.jsx("option", {
|
|
306
|
+
value: effort.id,
|
|
307
|
+
children: effort.name === effort.id ? effort.id : `${effort.name} · ${effort.id}`
|
|
308
|
+
}, effort.id))
|
|
309
|
+
]
|
|
310
|
+
})
|
|
311
|
+
]
|
|
312
|
+
}),
|
|
313
|
+
|
|
314
|
+
effortIds.length === 0 && effectiveProvider ? react_jsx_runtime.jsx("div", {
|
|
315
|
+
style: { fontSize: 12, opacity: 0.7 },
|
|
316
|
+
children: t("effortNone")
|
|
317
|
+
}) : null,
|
|
318
|
+
|
|
319
|
+
effortIncompatible || effortUnsupported ? react_jsx_runtime.jsxs("div", {
|
|
320
|
+
style: {
|
|
321
|
+
display: "flex",
|
|
322
|
+
flexDirection: "column",
|
|
323
|
+
gap: 6,
|
|
324
|
+
padding: "8px 10px",
|
|
325
|
+
borderRadius: 6,
|
|
326
|
+
border: "1px solid rgba(230,162,60,.4)",
|
|
327
|
+
background: "rgba(230,162,60,.08)"
|
|
328
|
+
},
|
|
329
|
+
children: [
|
|
330
|
+
react_jsx_runtime.jsx("div", {
|
|
331
|
+
style: { fontSize: 12, color: "var(--dsh-warning, #e6a23c)" },
|
|
332
|
+
children: `${t("effortIncompatible")}:${lockedEffort}`
|
|
333
|
+
}),
|
|
334
|
+
effortIds.length > 0 ? react_jsx_runtime.jsx("div", {
|
|
335
|
+
style: { fontSize: 12, opacity: 0.8 },
|
|
336
|
+
children: `${t("effortIncompatibleDetail")} ${effortIds.join(", ")}`
|
|
337
|
+
}) : null,
|
|
338
|
+
react_jsx_runtime.jsx("button", {
|
|
339
|
+
type: "button",
|
|
340
|
+
disabled: busy,
|
|
341
|
+
onClick: () => pickEffort(""),
|
|
342
|
+
style: { ...box, cursor: "pointer", alignSelf: "flex-start", opacity: 0.9 },
|
|
343
|
+
children: t("effortFollow")
|
|
344
|
+
})
|
|
345
|
+
]
|
|
346
|
+
}) : null,
|
|
347
|
+
|
|
348
|
+
!effortIncompatible && !effortUnsupported && !lockedEffort && supportsHigh ? react_jsx_runtime.jsxs("div", {
|
|
349
|
+
style: { display: "flex", gap: 8, alignItems: "center", flexWrap: "wrap" },
|
|
350
|
+
children: [
|
|
351
|
+
react_jsx_runtime.jsx("span", { style: { fontSize: 12, opacity: 0.72 }, children: t("effortSuggested") }),
|
|
352
|
+
react_jsx_runtime.jsx("button", {
|
|
353
|
+
type: "button",
|
|
354
|
+
disabled: busy,
|
|
355
|
+
onClick: () => pickEffort("high"),
|
|
356
|
+
style: { ...box, cursor: "pointer", opacity: 0.9 },
|
|
357
|
+
children: t("effortLockHigh")
|
|
358
|
+
})
|
|
359
|
+
]
|
|
360
|
+
}) : null,
|
|
361
|
+
|
|
362
|
+
!fromCatalog && pinned?.provider ? react_jsx_runtime.jsx("div", {
|
|
363
|
+
style: { fontSize: 12, color: "var(--dsh-warning, #e6a23c)" },
|
|
364
|
+
children: t("unavailable")
|
|
365
|
+
}) : null,
|
|
366
|
+
|
|
367
|
+
react_jsx_runtime.jsxs("div", {
|
|
368
|
+
style: { display: "flex", gap: 8, alignItems: "center", flexWrap: "wrap" },
|
|
369
|
+
children: [
|
|
370
|
+
react_jsx_runtime.jsx("button", {
|
|
371
|
+
type: "button",
|
|
372
|
+
disabled: !draft || busy,
|
|
373
|
+
onClick: submit,
|
|
374
|
+
style: {
|
|
375
|
+
padding: "6px 16px",
|
|
376
|
+
borderRadius: 6,
|
|
377
|
+
fontSize: 12,
|
|
378
|
+
fontWeight: 600,
|
|
379
|
+
border: "1px solid rgba(65,118,230,.5)",
|
|
380
|
+
background: draft && !busy ? "rgba(65,118,230,.14)" : "transparent",
|
|
381
|
+
color: draft && !busy ? "var(--dsw-alias-brand-primary, #4176e6)" : "inherit",
|
|
382
|
+
opacity: draft && !busy ? 1 : 0.45,
|
|
383
|
+
cursor: draft && !busy ? "pointer" : "default"
|
|
384
|
+
},
|
|
385
|
+
children: busy ? t("saving") : t("save")
|
|
386
|
+
}),
|
|
387
|
+
react_jsx_runtime.jsx("button", {
|
|
388
|
+
type: "button",
|
|
389
|
+
disabled: busy,
|
|
390
|
+
onClick: load,
|
|
391
|
+
style: { ...box, cursor: "pointer", opacity: 0.85 },
|
|
392
|
+
children: t("reset")
|
|
393
|
+
}),
|
|
394
|
+
saved ? react_jsx_runtime.jsx("span", {
|
|
395
|
+
style: { fontSize: 12, color: "var(--dsh-success, #4aa05a)" },
|
|
396
|
+
children: t("saved")
|
|
397
|
+
}) : null
|
|
398
|
+
]
|
|
399
|
+
})
|
|
400
|
+
]
|
|
401
|
+
}),
|
|
402
|
+
|
|
403
|
+
error === null ? null : react_jsx_runtime.jsx("div", {
|
|
404
|
+
role: "alert",
|
|
405
|
+
style: { fontSize: 12, color: "var(--dsh-danger, #dc5050)", whiteSpace: "pre-wrap" },
|
|
406
|
+
children: error
|
|
407
|
+
}),
|
|
408
|
+
|
|
409
|
+
react_jsx_runtime.jsx("div", { style: { fontSize: 12, opacity: 0.62, lineHeight: 1.5 }, children: t("note") })
|
|
410
|
+
]
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
const name = "dsh-pin-default-model";
|
|
415
|
+
const inject = ["slots", "locale"];
|
|
416
|
+
|
|
417
|
+
function apply(ctx) {
|
|
418
|
+
ctx.effect(() => ctx.locale.register(NS, { zh, en }), `${NS}: dictionaries`);
|
|
419
|
+
const t = ctx.locale.bind(NS);
|
|
420
|
+
|
|
421
|
+
ctx.slots.inject("settings.section", () => ctx.slots.register({
|
|
422
|
+
name: "settings.section",
|
|
423
|
+
id: "default-model-pin",
|
|
424
|
+
priority: -2,
|
|
425
|
+
order: 70,
|
|
426
|
+
label: () => t("nav"),
|
|
427
|
+
locale: NS,
|
|
428
|
+
inject: () => ({ t })
|
|
429
|
+
}, PinSection));
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
exports.name = name;
|
|
433
|
+
exports.inject = inject;
|
|
434
|
+
exports.apply = apply;
|
|
435
|
+
return module.exports;
|
|
436
|
+
}
|
|
437
|
+
});
|
package/cordis.patch.yml
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
- insert:
|
|
2
|
+
- id: dsh-pin-default-model
|
|
3
|
+
name: 'dsh-pin-default-model'
|
|
4
|
+
config:
|
|
5
|
+
provider: magpie
|
|
6
|
+
model: group/x-call
|
|
7
|
+
# Optional. Omit it to let each model use its own default effort.
|
|
8
|
+
# When set, the model above must actually offer this effort level.
|
|
9
|
+
# reasoningEffort: high
|
package/docs/DETAIL.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+

|
|
@@ -0,0 +1 @@
|
|
|
1
|
+

|