dsh-cohub 0.5.1 → 0.6.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/README.md +64 -8
- package/cordis.patch.yml +13 -1
- package/lib/client.js +1125 -74
- package/lib/co-cordis-plugin.js +8 -2
- package/lib/index.js +971 -168
- package/package.json +6 -2
- package/presets/co-orchestrator/agent.cordis.yml +30 -9
- package/presets/cohub-cordis/agent.cordis.yml +26 -6
package/lib/client.js
CHANGED
|
@@ -1,122 +1,1173 @@
|
|
|
1
1
|
window.__ModuleLoader__.load({
|
|
2
2
|
id: "dsh-cohub",
|
|
3
|
-
factory: (require)
|
|
3
|
+
factory: function (require) {
|
|
4
4
|
var module = { exports: {} };
|
|
5
5
|
var exports = module.exports;
|
|
6
6
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
7
7
|
|
|
8
|
+
var React = require("react");
|
|
9
|
+
|
|
10
|
+
/* ────────────────────────────────────────────────────────────────
|
|
11
|
+
* CoHub 代理模型设置页(DSH 0.2.1)
|
|
12
|
+
*
|
|
13
|
+
* 历史纠正(旧注释是错的,别再抄回去):
|
|
14
|
+
* ❌「0.2 官方设置页会自动按 volatile 字段生成表单,无需客户端」
|
|
15
|
+
* → 官方 0.2.1 的 settings.section 导航与页面全部由客户端插件注册
|
|
16
|
+
* (general / models / plugins / agent-presets / account 都是这么做的)。
|
|
17
|
+
* 官方 README 明说「目前没有已发布的客户端会那样渲染 volatile 字段」,
|
|
18
|
+
* 所以本插件必须自带页面。
|
|
19
|
+
* ❌「旧 settingsScope 服务与 settings.plugin.item slot 已在 0.2 移除」
|
|
20
|
+
* → 是**改名**不是移除:settingsScope → configForms;
|
|
21
|
+
* settings.plugin.item → plugins.item / settings.section。
|
|
22
|
+
*
|
|
23
|
+
* 取证过的 0.2.1 契约(照抄官方插件写法,别再自己发明):
|
|
24
|
+
* 1. 页面挂 settings.section(list/root)。左侧导航由宿主
|
|
25
|
+
* ctx.slots.entries("settings.section") 按 order 升序投影,注册即出现,
|
|
26
|
+
* 无需在别处登记。现有 order:general 0 / models 10 / plugins 15 /
|
|
27
|
+
* agent-presets 20 / account -100,本页取 12(模型与插件之间)。
|
|
28
|
+
* 2. 读写配置走 ctx.configForms.get(<Loader entry id>),namespace 就是
|
|
29
|
+
* cordis.patch.yml 里那一行的 id("cohub"):
|
|
30
|
+
* scope.getSnapshot() → { status: "loading"|"ready"|"unavailable",
|
|
31
|
+
* value, base, user, revision, writable }
|
|
32
|
+
* scope.mutate(ops, expectedRevision) → Promise<boolean>
|
|
33
|
+
* scope.subscribe(fn) → () => void
|
|
34
|
+
* 数组字段整体替换,所以一次 mutate 提交完整 skills 数组。
|
|
35
|
+
* 3. 模型目录走 ctx.remote.session.modelCatalog()({ ok, value }),
|
|
36
|
+
* value.groups = [{ id, name, models: [{ id, name, reasoning? }] }];必须判 .ok。
|
|
37
|
+
* reasoning = { efforts: [{ id, name }], defaultEffort? }(dsh-llm LlmModelReasoningInfo),
|
|
38
|
+
* 不支持的模型整个 reasoning 字段缺失(不是空数组)→ 推理强度下拉禁用。
|
|
39
|
+
* 目录变化订阅 ctx.remote.$on("llm/adapters-updated", fn)。
|
|
40
|
+
* 4. slot 的 inject 返回 { hooks: { <name>: <observable> }, ...props },
|
|
41
|
+
* 渲染器把 observable 绑成 props.use<Name>(selector);
|
|
42
|
+
* observable 只需 { getSnapshot(), subscribe(fn) }(uSES 语义,
|
|
43
|
+
* getSnapshot 必须在未变化时返回同一引用)。
|
|
44
|
+
* 5. 官方 dsh-client-ui-primitives 没有 Select/Dropdown,用原生 select。
|
|
45
|
+
* ──────────────────────────────────────────────────────────────── */
|
|
46
|
+
|
|
47
|
+
/** 设置字典命名空间,同时也是本插件客户端 slot 的 locale 命名空间。 */
|
|
8
48
|
var NS = "cohub";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
49
|
+
/** 配置命名空间 = cordis.patch.yml 中本插件 Loader 行的 id。 */
|
|
50
|
+
var ENTRY_ID = "cohub";
|
|
51
|
+
/** 左侧导航位置:插在「模型」(10) 与「插件」(15) 之间。 */
|
|
52
|
+
var SECTION_ORDER = 12;
|
|
53
|
+
|
|
54
|
+
var inject = ["slots", "locale", "remote", "remote.session", "configForms"];
|
|
55
|
+
|
|
56
|
+
/** src/skills.ts 中 COHUB_SKILLS 的真实清单与顺序。 */
|
|
57
|
+
var SKILL_NAMES = [
|
|
58
|
+
"co-orchestrator",
|
|
59
|
+
"co-planner",
|
|
60
|
+
"co-oracle",
|
|
61
|
+
"co-explorer",
|
|
62
|
+
"co-librarian",
|
|
63
|
+
"co-observer",
|
|
64
|
+
"co-fixer",
|
|
65
|
+
"co-designer",
|
|
66
|
+
"co-council",
|
|
67
|
+
"co-rule-user",
|
|
68
|
+
"co-rule-project",
|
|
69
|
+
"co-rule-app",
|
|
70
|
+
"co-cordis"
|
|
71
|
+
];
|
|
16
72
|
|
|
17
73
|
var zh = {
|
|
74
|
+
nav: "CoHub 代理",
|
|
18
75
|
title: "CoHub 代理模型",
|
|
19
76
|
description: "为每个专职代理单独指定模型供应商与模型。留空则继承父模型;配置失效时自动回退。",
|
|
20
77
|
provider: "供应商",
|
|
21
78
|
model: "模型",
|
|
22
79
|
configured: "显式配置",
|
|
23
80
|
inherited: "继承父模型",
|
|
81
|
+
providerInherit: "(不配置,继承父模型)",
|
|
82
|
+
modelInherit: "(继承父模型)",
|
|
24
83
|
loading: "加载中…",
|
|
25
|
-
unavailable: "
|
|
84
|
+
unavailable: "当前设置不可用(宿主未提供 cohub 配置命名空间)。",
|
|
85
|
+
readOnly: "当前连接只读,无法修改设置。",
|
|
86
|
+
conflicted: "设置已在其他位置更新,请放弃修改后重试。",
|
|
87
|
+
failed: "保存失败,请重试。",
|
|
88
|
+
retry: "重试",
|
|
89
|
+
dirty: "有未保存的修改。",
|
|
26
90
|
save: "保存",
|
|
27
91
|
saving: "保存中…",
|
|
28
|
-
discard: "放弃修改",
|
|
29
92
|
saved: "已保存。",
|
|
30
|
-
|
|
31
|
-
|
|
93
|
+
discard: "放弃修改",
|
|
94
|
+
reset: "重置",
|
|
32
95
|
customModel: "输入模型 ID",
|
|
33
96
|
selectProviderFirst: "请先选择供应商",
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
envSigUseOff: "off(每次都探针)",
|
|
56
|
-
envSigUseManual: "manual(只读 manual 配置)",
|
|
57
|
-
envSigTtl: "缓存 TTL(毫秒)",
|
|
58
|
-
envSigConfirmCount: "确认次数(达到后写入)",
|
|
59
|
-
invalidCleared: "⚠️ 已检测到 {count} 个代理的配置失效,已自动重置为继承。",
|
|
60
|
-
invalidClearedList: "受影响代理:{list}",
|
|
61
|
-
providerPlaceholder: "选择供应商(留空则继承)",
|
|
62
|
-
modelPlaceholder: "选择模型(留空则用供应商默认)"
|
|
97
|
+
loadProvidersFailed: "模型供应商列表加载失败",
|
|
98
|
+
emptyModel: "该供应商未提供模型目录",
|
|
99
|
+
unavailableOption: "{value}(不可用)",
|
|
100
|
+
reasoningEffort: "推理强度",
|
|
101
|
+
effortInherit: "(继承父会话)",
|
|
102
|
+
effortSelectModelFirst: "请先选择模型",
|
|
103
|
+
effortUnsupported: "该模型不支持",
|
|
104
|
+
effortUnsupportedOption: "{value}(当前模型不支持)",
|
|
105
|
+
"skill.co-orchestrator": "调度编排",
|
|
106
|
+
"skill.co-planner": "方案制定",
|
|
107
|
+
"skill.co-oracle": "架构/代码审查",
|
|
108
|
+
"skill.co-explorer": "搜索方案制定",
|
|
109
|
+
"skill.co-librarian": "资料研究",
|
|
110
|
+
"skill.co-observer": "视觉分析",
|
|
111
|
+
"skill.co-fixer": "代码修改方案",
|
|
112
|
+
"skill.co-designer": "UI/UX 设计",
|
|
113
|
+
"skill.co-council": "多模型共识",
|
|
114
|
+
"skill.co-rule-user": "用户规则",
|
|
115
|
+
"skill.co-rule-project": "项目规则",
|
|
116
|
+
"skill.co-rule-app": "应用规则",
|
|
117
|
+
"skill.co-cordis": "Cordis 插件"
|
|
63
118
|
};
|
|
119
|
+
|
|
64
120
|
var en = {
|
|
121
|
+
nav: "CoHub agents",
|
|
65
122
|
title: "CoHub Agent Models",
|
|
66
123
|
description: "Pick a provider and model for each specialist agent. Leave blank to inherit the parent model; stale config auto-resets.",
|
|
67
124
|
provider: "Provider",
|
|
68
125
|
model: "Model",
|
|
69
126
|
configured: "Explicit",
|
|
70
127
|
inherited: "Inherited",
|
|
128
|
+
providerInherit: "(not set — inherit parent model)",
|
|
129
|
+
modelInherit: "(inherit parent model)",
|
|
71
130
|
loading: "Loading…",
|
|
72
|
-
unavailable: "This setting is unavailable.",
|
|
131
|
+
unavailable: "This setting is unavailable (the Host does not serve the cohub configuration namespace).",
|
|
132
|
+
readOnly: "This connection is read-only; settings cannot be changed.",
|
|
133
|
+
conflicted: "Settings changed elsewhere. Discard your edits and retry.",
|
|
134
|
+
failed: "Save failed. Please retry.",
|
|
135
|
+
retry: "Retry",
|
|
136
|
+
dirty: "Unsaved changes.",
|
|
73
137
|
save: "Save",
|
|
74
138
|
saving: "Saving…",
|
|
75
|
-
discard: "Discard",
|
|
76
139
|
saved: "Saved.",
|
|
77
|
-
|
|
78
|
-
|
|
140
|
+
discard: "Discard",
|
|
141
|
+
reset: "Reset",
|
|
79
142
|
customModel: "Enter model ID",
|
|
80
143
|
selectProviderFirst: "Select a provider first",
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
envSigUseOff: "off (probe every time)",
|
|
103
|
-
envSigUseManual: "manual (read manual config only)",
|
|
104
|
-
envSigTtl: "Cache TTL (ms)",
|
|
105
|
-
envSigConfirmCount: "Confirm count (write after threshold)",
|
|
106
|
-
invalidCleared: "⚠️ Detected stale config for {count} agent(s); reset to inherit.",
|
|
107
|
-
invalidClearedList: "Affected agents: {list}",
|
|
108
|
-
providerPlaceholder: "Select provider (leave blank to inherit)",
|
|
109
|
-
modelPlaceholder: "Select model (leave blank for provider default)"
|
|
144
|
+
loadProvidersFailed: "Failed to load the provider catalog",
|
|
145
|
+
emptyModel: "This provider publishes no model catalog",
|
|
146
|
+
unavailableOption: "{value} (unavailable)",
|
|
147
|
+
reasoningEffort: "Reasoning effort",
|
|
148
|
+
effortInherit: "(inherit from parent session)",
|
|
149
|
+
effortSelectModelFirst: "Select a model first",
|
|
150
|
+
effortUnsupported: "Not supported by this model",
|
|
151
|
+
effortUnsupportedOption: "{value} (unsupported by this model)",
|
|
152
|
+
"skill.co-orchestrator": "Orchestrator",
|
|
153
|
+
"skill.co-planner": "Planner",
|
|
154
|
+
"skill.co-oracle": "Architecture/code review",
|
|
155
|
+
"skill.co-explorer": "Codebase search",
|
|
156
|
+
"skill.co-librarian": "Research",
|
|
157
|
+
"skill.co-observer": "Visual analysis",
|
|
158
|
+
"skill.co-fixer": "Implementation",
|
|
159
|
+
"skill.co-designer": "UI/UX design",
|
|
160
|
+
"skill.co-council": "Multi-model consensus",
|
|
161
|
+
"skill.co-rule-user": "User rules",
|
|
162
|
+
"skill.co-rule-project": "Project rules",
|
|
163
|
+
"skill.co-rule-app": "App rules",
|
|
164
|
+
"skill.co-cordis": "Cordis plugins"
|
|
110
165
|
};
|
|
111
166
|
|
|
167
|
+
/** 无 locale 服务时的最小翻译(防止 props.t 缺失导致页面白屏)。 */
|
|
168
|
+
function fallbackTranslate(key, params) {
|
|
169
|
+
var template = zh[key] !== undefined ? zh[key] : key;
|
|
170
|
+
if (!params) return template;
|
|
171
|
+
return template.replace(/\{(\w+)\}/g, function (match, name) {
|
|
172
|
+
return Object.prototype.hasOwnProperty.call(params, name) ? String(params[name]) : match;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function messageOf(error) {
|
|
177
|
+
if (!error) return "unknown error";
|
|
178
|
+
if (typeof error === "string") return error;
|
|
179
|
+
if (error.message) return error.message;
|
|
180
|
+
return String(error);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function modelLabel(model) {
|
|
184
|
+
var id = typeof model.id === "string" ? model.id : "";
|
|
185
|
+
var name = typeof model.name === "string" ? model.name : "";
|
|
186
|
+
return name !== "" && name !== id ? name + " (" + id + ")" : id;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function providerLabel(group) {
|
|
190
|
+
var id = typeof group.id === "string" ? group.id : "";
|
|
191
|
+
var name = typeof group.name === "string" ? group.name : "";
|
|
192
|
+
return name !== "" && name !== id ? name + " (" + id + ")" : id;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* 从模型目录条目里抽出可选推理档位。
|
|
197
|
+
* 契约(dsh-llm LlmModelReasoningInfo):
|
|
198
|
+
* model.reasoning = { efforts: [{ id, name }], defaultEffort? }
|
|
199
|
+
* 不支持的模型**整个 reasoning 字段缺失**(不是空数组)→ 返回空数组,调用方据此禁用控件。
|
|
200
|
+
* @param model - modelCatalog() 的 groups[].models[] 单项(任意形状,逐项校验)。
|
|
201
|
+
* @returns [{ id, label }];label 优先取 effort.name,缺失时退回 id。
|
|
202
|
+
*/
|
|
203
|
+
function reasoningEffortsOf(model) {
|
|
204
|
+
var reasoning = model && typeof model === "object" ? model.reasoning : undefined;
|
|
205
|
+
if (!reasoning || typeof reasoning !== "object") return [];
|
|
206
|
+
var list = Array.isArray(reasoning.efforts) ? reasoning.efforts : [];
|
|
207
|
+
var out = [];
|
|
208
|
+
for (var i = 0; i < list.length; i += 1) {
|
|
209
|
+
var effort = list[i];
|
|
210
|
+
if (!effort || typeof effort !== "object") continue;
|
|
211
|
+
var id = typeof effort.id === "string" ? effort.id : "";
|
|
212
|
+
if (id === "") continue;
|
|
213
|
+
var name = typeof effort.name === "string" ? effort.name : "";
|
|
214
|
+
out.push({ id: id, label: name !== "" ? name : id });
|
|
215
|
+
}
|
|
216
|
+
return out;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* 行的推理强度归一为字符串(缺字段 / 非字符串都当空串 = 不配置,继承父会话)。
|
|
221
|
+
* 注意不能用 row.reasoningEffort !== "" 直接判断:老数据没有该键,undefined !== "" 为真。
|
|
222
|
+
*/
|
|
223
|
+
function effortOf(row) {
|
|
224
|
+
return row && typeof row.reasoningEffort === "string" ? row.reasoningEffort : "";
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/* ── 纯数据层:settings value.skills ↔ 编辑行 ─────────────────── */
|
|
228
|
+
|
|
229
|
+
function emptyRow(name) {
|
|
230
|
+
return { name: name, provider: "", model: "", reasoningEffort: "", extra: {} };
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
function copyRow(row) {
|
|
234
|
+
var extra = {};
|
|
235
|
+
for (var key in row.extra) {
|
|
236
|
+
if (Object.prototype.hasOwnProperty.call(row.extra, key)) extra[key] = row.extra[key];
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
name: row.name,
|
|
240
|
+
provider: row.provider,
|
|
241
|
+
model: row.model,
|
|
242
|
+
reasoningEffort: effortOf(row),
|
|
243
|
+
extra: extra
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* 把 settings 里的 skills 数组转成编辑行。
|
|
249
|
+
* 除 name/provider/model/reasoningEffort 之外的字段(maxTokens 等)原样收进 extra,写回时保留。
|
|
250
|
+
* @param skills - configForms 快照里的 value.skills(任意形状,逐项校验)。
|
|
251
|
+
* @returns 编辑行数组(顺序与存储顺序一致)。
|
|
252
|
+
*/
|
|
253
|
+
function rowsFromSkills(skills) {
|
|
254
|
+
var rows = [];
|
|
255
|
+
if (!Array.isArray(skills)) return rows;
|
|
256
|
+
for (var i = 0; i < skills.length; i += 1) {
|
|
257
|
+
var entry = skills[i];
|
|
258
|
+
if (!entry || typeof entry.name !== "string" || entry.name === "") continue;
|
|
259
|
+
var extra = {};
|
|
260
|
+
for (var key in entry) {
|
|
261
|
+
if (!Object.prototype.hasOwnProperty.call(entry, key)) continue;
|
|
262
|
+
// reasoningEffort 已提升为一等字段,不能再进 extra,否则写回时会重复/冲突。
|
|
263
|
+
if (key === "name" || key === "provider" || key === "model" || key === "reasoningEffort") continue;
|
|
264
|
+
extra[key] = entry[key];
|
|
265
|
+
}
|
|
266
|
+
rows.push({
|
|
267
|
+
name: entry.name,
|
|
268
|
+
provider: typeof entry.provider === "string" ? entry.provider : "",
|
|
269
|
+
model: typeof entry.model === "string" ? entry.model : "",
|
|
270
|
+
reasoningEffort: typeof entry.reasoningEffort === "string" ? entry.reasoningEffort : "",
|
|
271
|
+
extra: extra
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
return rows;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* 编辑行 → 待写入的 skills 数组。
|
|
279
|
+
* 规则(第 1 条是正确性关键):
|
|
280
|
+
* 1. provider 为空 → 整行不写入(= 继承父模型);否则 delegate 会拿空 provider 建路由。
|
|
281
|
+
* 2. model 为空 → 不写 model 键(供应商默认模型),绝不写空字符串(否则 UNKNOWN_MODEL)。
|
|
282
|
+
* 3. reasoningEffort 为空 → 不写该键(绝不写空串),继承父会话的推理强度。
|
|
283
|
+
* 4. extra(maxTokens 等)与未知 skill 名原样保留,不静默丢配置。
|
|
284
|
+
* @param rows - 编辑行数组。
|
|
285
|
+
* @returns 可提交给 configForms.mutate 的 skills 数组。
|
|
286
|
+
*/
|
|
287
|
+
function rowsToSkills(rows) {
|
|
288
|
+
var out = [];
|
|
289
|
+
if (!Array.isArray(rows)) return out;
|
|
290
|
+
for (var i = 0; i < rows.length; i += 1) {
|
|
291
|
+
var row = rows[i];
|
|
292
|
+
if (!row || typeof row.name !== "string" || row.name === "") continue;
|
|
293
|
+
var provider = typeof row.provider === "string" ? row.provider : "";
|
|
294
|
+
if (provider === "") continue;
|
|
295
|
+
var item = {};
|
|
296
|
+
for (var key in row.extra) {
|
|
297
|
+
if (!Object.prototype.hasOwnProperty.call(row.extra, key)) continue;
|
|
298
|
+
if (key === "reasoningEffort") continue; // 以一等字段为准,不让 extra 覆盖/重复
|
|
299
|
+
item[key] = row.extra[key];
|
|
300
|
+
}
|
|
301
|
+
item.name = row.name;
|
|
302
|
+
item.provider = provider;
|
|
303
|
+
var model = typeof row.model === "string" ? row.model : "";
|
|
304
|
+
if (model !== "") item.model = model;
|
|
305
|
+
var effort = effortOf(row);
|
|
306
|
+
if (effort !== "") item.reasoningEffort = effort;
|
|
307
|
+
out.push(item);
|
|
308
|
+
}
|
|
309
|
+
return out;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/** 已知 13 个代理按固定顺序,未知 skill 名按存储顺序追加(不丢用户配置)。 */
|
|
313
|
+
function displayRows(stored) {
|
|
314
|
+
var known = {};
|
|
315
|
+
var unknown = [];
|
|
316
|
+
for (var i = 0; i < stored.length; i += 1) {
|
|
317
|
+
if (SKILL_NAMES.indexOf(stored[i].name) >= 0) known[stored[i].name] = stored[i];
|
|
318
|
+
else unknown.push(stored[i]);
|
|
319
|
+
}
|
|
320
|
+
var rows = [];
|
|
321
|
+
for (var j = 0; j < SKILL_NAMES.length; j += 1) {
|
|
322
|
+
var name = SKILL_NAMES[j];
|
|
323
|
+
rows.push(known[name] !== undefined ? known[name] : emptyRow(name));
|
|
324
|
+
}
|
|
325
|
+
for (var k = 0; k < unknown.length; k += 1) rows.push(unknown[k]);
|
|
326
|
+
return rows;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/* ── 极简 observable store(uSES:快照未变必须返回同一引用) ──── */
|
|
330
|
+
|
|
331
|
+
function createStateStore(initial) {
|
|
332
|
+
var current = initial;
|
|
333
|
+
var listeners = [];
|
|
334
|
+
return {
|
|
335
|
+
getSnapshot: function () {
|
|
336
|
+
return current;
|
|
337
|
+
},
|
|
338
|
+
subscribe: function (listener) {
|
|
339
|
+
listeners.push(listener);
|
|
340
|
+
return function () {
|
|
341
|
+
var index = listeners.indexOf(listener);
|
|
342
|
+
if (index >= 0) listeners.splice(index, 1);
|
|
343
|
+
};
|
|
344
|
+
},
|
|
345
|
+
set: function (next) {
|
|
346
|
+
if (next === current) return;
|
|
347
|
+
current = next;
|
|
348
|
+
var snapshot = listeners.slice();
|
|
349
|
+
for (var i = 0; i < snapshot.length; i += 1) {
|
|
350
|
+
try {
|
|
351
|
+
snapshot[i]();
|
|
352
|
+
} catch (error) {
|
|
353
|
+
/* 单个订阅者异常不阻断其他订阅者 */
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
var EMPTY_STATE = Object.freeze({
|
|
361
|
+
status: "loading",
|
|
362
|
+
writable: false,
|
|
363
|
+
dirty: false,
|
|
364
|
+
conflicted: false,
|
|
365
|
+
saving: false,
|
|
366
|
+
saved: false,
|
|
367
|
+
failed: false,
|
|
368
|
+
rows: [],
|
|
369
|
+
providers: [],
|
|
370
|
+
modelsByProvider: {},
|
|
371
|
+
// effortsByModel[provider][modelId] = [{ id, label }];模型不支持推理强度时该键缺失。
|
|
372
|
+
effortsByModel: {},
|
|
373
|
+
catalogStatus: "loading",
|
|
374
|
+
catalogError: ""
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* 把 configForms 的一个 ConfigForm 与模型目录合成一个带草稿的页面控制器。
|
|
379
|
+
* @param ctx - 客户端 cordis 上下文(remote / locale)。
|
|
380
|
+
* @param scope - ctx.configForms.get(ENTRY_ID),可能为 null(宿主未提供服务)。
|
|
381
|
+
* @returns { store, start, dispose, editRow, resetRow, discard, save, loadCatalog }
|
|
382
|
+
*/
|
|
383
|
+
function buildSkillsController(ctx, scope) {
|
|
384
|
+
var store = createStateStore(null);
|
|
385
|
+
|
|
386
|
+
var draft = null; // { rows, revision }
|
|
387
|
+
var conflicted = false;
|
|
388
|
+
var saving = false;
|
|
389
|
+
var saved = false;
|
|
390
|
+
var failed = false;
|
|
391
|
+
var disposed = false;
|
|
392
|
+
|
|
393
|
+
var catalogStatus = "loading";
|
|
394
|
+
var catalogError = "";
|
|
395
|
+
var catalogProviders = [];
|
|
396
|
+
var catalogByProvider = {};
|
|
397
|
+
// effortsByModel[provider][modelId] = [{ id, label }],与 modelsByProvider 同批构建。
|
|
398
|
+
var catalogEfforts = {};
|
|
399
|
+
var catalogGeneration = 0;
|
|
400
|
+
|
|
401
|
+
var lastValue;
|
|
402
|
+
var lastRows = [];
|
|
403
|
+
var published = null;
|
|
404
|
+
|
|
405
|
+
function readScope() {
|
|
406
|
+
if (!scope || typeof scope.getSnapshot !== "function") {
|
|
407
|
+
return { status: "unavailable", writable: false, value: undefined, revision: undefined };
|
|
408
|
+
}
|
|
409
|
+
try {
|
|
410
|
+
var snapshot = scope.getSnapshot();
|
|
411
|
+
return snapshot && typeof snapshot === "object" ? snapshot : { status: "loading", writable: false };
|
|
412
|
+
} catch (error) {
|
|
413
|
+
return { status: "unavailable", writable: false };
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function currentRows() {
|
|
418
|
+
var snapshot = readScope();
|
|
419
|
+
if (snapshot.value !== lastValue) {
|
|
420
|
+
lastValue = snapshot.value;
|
|
421
|
+
lastRows = displayRows(rowsFromSkills(snapshot.value && snapshot.value.skills));
|
|
422
|
+
}
|
|
423
|
+
return lastRows;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
function buildState() {
|
|
427
|
+
var snapshot = readScope();
|
|
428
|
+
return {
|
|
429
|
+
status: snapshot.status || "loading",
|
|
430
|
+
writable: snapshot.status === "ready" && snapshot.writable === true,
|
|
431
|
+
dirty: draft !== null,
|
|
432
|
+
conflicted: conflicted,
|
|
433
|
+
saving: saving,
|
|
434
|
+
saved: saved,
|
|
435
|
+
failed: failed,
|
|
436
|
+
rows: draft !== null ? draft.rows : currentRows(),
|
|
437
|
+
providers: catalogProviders,
|
|
438
|
+
modelsByProvider: catalogByProvider,
|
|
439
|
+
effortsByModel: catalogEfforts,
|
|
440
|
+
catalogStatus: catalogStatus,
|
|
441
|
+
catalogError: catalogError
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
function sameState(left, right) {
|
|
446
|
+
if (left === null || left === undefined || right === null || right === undefined) return false;
|
|
447
|
+
return left.status === right.status
|
|
448
|
+
&& left.writable === right.writable
|
|
449
|
+
&& left.dirty === right.dirty
|
|
450
|
+
&& left.conflicted === right.conflicted
|
|
451
|
+
&& left.saving === right.saving
|
|
452
|
+
&& left.saved === right.saved
|
|
453
|
+
&& left.failed === right.failed
|
|
454
|
+
&& left.rows === right.rows
|
|
455
|
+
&& left.providers === right.providers
|
|
456
|
+
&& left.modelsByProvider === right.modelsByProvider
|
|
457
|
+
&& left.effortsByModel === right.effortsByModel
|
|
458
|
+
&& left.catalogStatus === right.catalogStatus
|
|
459
|
+
&& left.catalogError === right.catalogError;
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
function publish() {
|
|
463
|
+
if (disposed) return;
|
|
464
|
+
var next = buildState();
|
|
465
|
+
if (sameState(published, next)) return;
|
|
466
|
+
published = next;
|
|
467
|
+
store.set(next);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function onScopeChange() {
|
|
471
|
+
if (disposed) return;
|
|
472
|
+
// 自己的写入进行中不做冲突判定:revision 变化正是本次写入引起的。
|
|
473
|
+
if (!saving && draft !== null) {
|
|
474
|
+
var snapshot = readScope();
|
|
475
|
+
if (snapshot.revision !== draft.revision) conflicted = true;
|
|
476
|
+
}
|
|
477
|
+
publish();
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
function beginDraft() {
|
|
481
|
+
if (draft !== null) return draft;
|
|
482
|
+
var snapshot = readScope();
|
|
483
|
+
var rows = [];
|
|
484
|
+
var source = currentRows();
|
|
485
|
+
for (var i = 0; i < source.length; i += 1) rows.push(copyRow(source[i]));
|
|
486
|
+
draft = { rows: rows, revision: snapshot.revision };
|
|
487
|
+
return draft;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function canEdit() {
|
|
491
|
+
if (disposed || saving || conflicted) return false;
|
|
492
|
+
var snapshot = readScope();
|
|
493
|
+
return snapshot.status === "ready" && snapshot.writable === true;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/** 某 provider+model 支持的推理档位 id 列表(目录未就绪或模型不支持时为空数组)。 */
|
|
497
|
+
function effortIdsFor(provider, model) {
|
|
498
|
+
if (provider === "" || model === "") return [];
|
|
499
|
+
var byModel = catalogEfforts[provider];
|
|
500
|
+
if (!byModel) return [];
|
|
501
|
+
var list = byModel[model];
|
|
502
|
+
if (!Array.isArray(list)) return [];
|
|
503
|
+
var ids = [];
|
|
504
|
+
for (var i = 0; i < list.length; i += 1) ids.push(list[i].id);
|
|
505
|
+
return ids;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* 换供应商/模型后,已选强度若不在新模型的档位里就清空(避免写出必然被宿主拒的配置:
|
|
510
|
+
* delegate 侧对不支持的档位会 UNSUPPORTED_REASONING_EFFORT)。
|
|
511
|
+
* 档位未知(目录未就绪 / 手填 model / 模型不支持)时也清空——此时无法证明该强度仍有效。
|
|
512
|
+
*/
|
|
513
|
+
function reconcileEffort(provider, model, effort) {
|
|
514
|
+
if (effort === "") return "";
|
|
515
|
+
var ids = effortIdsFor(provider, model);
|
|
516
|
+
return ids.indexOf(effort) >= 0 ? effort : "";
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
function editRow(name, field, value) {
|
|
520
|
+
if (field !== "provider" && field !== "model" && field !== "reasoningEffort") return;
|
|
521
|
+
if (!canEdit()) return;
|
|
522
|
+
var current = beginDraft();
|
|
523
|
+
var next = [];
|
|
524
|
+
var changed = false;
|
|
525
|
+
for (var i = 0; i < current.rows.length; i += 1) {
|
|
526
|
+
var row = current.rows[i];
|
|
527
|
+
if (row.name !== name) {
|
|
528
|
+
next.push(row);
|
|
529
|
+
continue;
|
|
530
|
+
}
|
|
531
|
+
if (field === "provider") {
|
|
532
|
+
if (row.provider === value) {
|
|
533
|
+
next.push(row);
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
// 换供应商后旧 model 一定属于旧目录,留着只会写出失效路由;
|
|
537
|
+
// 推理档位属于「供应商+模型」这一对,也一并清空。
|
|
538
|
+
next.push({
|
|
539
|
+
name: row.name,
|
|
540
|
+
provider: value,
|
|
541
|
+
model: "",
|
|
542
|
+
reasoningEffort: "",
|
|
543
|
+
extra: row.extra
|
|
544
|
+
});
|
|
545
|
+
changed = true;
|
|
546
|
+
} else if (field === "model") {
|
|
547
|
+
if (row.model === value) {
|
|
548
|
+
next.push(row);
|
|
549
|
+
continue;
|
|
550
|
+
}
|
|
551
|
+
next.push({
|
|
552
|
+
name: row.name,
|
|
553
|
+
provider: row.provider,
|
|
554
|
+
model: value,
|
|
555
|
+
reasoningEffort: reconcileEffort(row.provider, value, effortOf(row)),
|
|
556
|
+
extra: row.extra
|
|
557
|
+
});
|
|
558
|
+
changed = true;
|
|
559
|
+
} else {
|
|
560
|
+
if (effortOf(row) === value) {
|
|
561
|
+
next.push(row);
|
|
562
|
+
continue;
|
|
563
|
+
}
|
|
564
|
+
next.push({
|
|
565
|
+
name: row.name,
|
|
566
|
+
provider: row.provider,
|
|
567
|
+
model: row.model,
|
|
568
|
+
reasoningEffort: value,
|
|
569
|
+
extra: row.extra
|
|
570
|
+
});
|
|
571
|
+
changed = true;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
if (!changed) return;
|
|
575
|
+
draft.rows = next;
|
|
576
|
+
saved = false;
|
|
577
|
+
failed = false;
|
|
578
|
+
publish();
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function resetRow(name) {
|
|
582
|
+
if (!canEdit()) return;
|
|
583
|
+
var current = beginDraft();
|
|
584
|
+
var next = [];
|
|
585
|
+
var changed = false;
|
|
586
|
+
for (var i = 0; i < current.rows.length; i += 1) {
|
|
587
|
+
var row = current.rows[i];
|
|
588
|
+
if (row.name !== name) {
|
|
589
|
+
next.push(row);
|
|
590
|
+
continue;
|
|
591
|
+
}
|
|
592
|
+
if (row.provider === "" && row.model === "" && effortOf(row) === "") {
|
|
593
|
+
next.push(row);
|
|
594
|
+
continue;
|
|
595
|
+
}
|
|
596
|
+
// 只清 provider/model/reasoningEffort:maxTokens 等页面不展示的字段留着,
|
|
597
|
+
// 避免重置后静默丢配置。
|
|
598
|
+
next.push({
|
|
599
|
+
name: row.name,
|
|
600
|
+
provider: "",
|
|
601
|
+
model: "",
|
|
602
|
+
reasoningEffort: "",
|
|
603
|
+
extra: row.extra
|
|
604
|
+
});
|
|
605
|
+
changed = true;
|
|
606
|
+
}
|
|
607
|
+
if (!changed) return;
|
|
608
|
+
draft.rows = next;
|
|
609
|
+
saved = false;
|
|
610
|
+
failed = false;
|
|
611
|
+
publish();
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
function discard() {
|
|
615
|
+
if (saving) return;
|
|
616
|
+
draft = null;
|
|
617
|
+
conflicted = false;
|
|
618
|
+
saved = false;
|
|
619
|
+
failed = false;
|
|
620
|
+
publish();
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
function save() {
|
|
624
|
+
if (disposed || saving || draft === null) return Promise.resolve(false);
|
|
625
|
+
var snapshot = readScope();
|
|
626
|
+
if (snapshot.status !== "ready" || snapshot.writable !== true || conflicted) return Promise.resolve(false);
|
|
627
|
+
if (draft.revision !== undefined && snapshot.revision !== draft.revision) {
|
|
628
|
+
conflicted = true;
|
|
629
|
+
publish();
|
|
630
|
+
return Promise.resolve(false);
|
|
631
|
+
}
|
|
632
|
+
var expected = draft.revision;
|
|
633
|
+
var next = rowsToSkills(draft.rows);
|
|
634
|
+
saving = true;
|
|
635
|
+
saved = false;
|
|
636
|
+
failed = false;
|
|
637
|
+
publish();
|
|
638
|
+
var request;
|
|
639
|
+
try {
|
|
640
|
+
request = scope.mutate([{ op: "set", path: ["skills"], value: next }], expected);
|
|
641
|
+
} catch (error) {
|
|
642
|
+
saving = false;
|
|
643
|
+
failed = true;
|
|
644
|
+
publish();
|
|
645
|
+
return Promise.resolve(false);
|
|
646
|
+
}
|
|
647
|
+
return Promise.resolve(request).then(function (accepted) {
|
|
648
|
+
if (disposed) return false;
|
|
649
|
+
saving = false;
|
|
650
|
+
if (accepted === true) {
|
|
651
|
+
draft = null;
|
|
652
|
+
conflicted = false;
|
|
653
|
+
failed = false;
|
|
654
|
+
saved = true;
|
|
655
|
+
lastValue = undefined;
|
|
656
|
+
} else {
|
|
657
|
+
failed = true;
|
|
658
|
+
}
|
|
659
|
+
publish();
|
|
660
|
+
return accepted === true;
|
|
661
|
+
}, function () {
|
|
662
|
+
if (disposed) return false;
|
|
663
|
+
saving = false;
|
|
664
|
+
failed = true;
|
|
665
|
+
publish();
|
|
666
|
+
return false;
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
function loadCatalog() {
|
|
671
|
+
catalogGeneration += 1;
|
|
672
|
+
var generation = catalogGeneration;
|
|
673
|
+
catalogStatus = "loading";
|
|
674
|
+
catalogError = "";
|
|
675
|
+
publish();
|
|
676
|
+
|
|
677
|
+
var remote = ctx && ctx.remote;
|
|
678
|
+
var request;
|
|
679
|
+
try {
|
|
680
|
+
if (!remote || !remote.session || typeof remote.session.modelCatalog !== "function") {
|
|
681
|
+
throw new Error("remote.session.modelCatalog is unavailable");
|
|
682
|
+
}
|
|
683
|
+
request = remote.session.modelCatalog();
|
|
684
|
+
} catch (error) {
|
|
685
|
+
catalogStatus = "error";
|
|
686
|
+
catalogError = messageOf(error);
|
|
687
|
+
publish();
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
Promise.resolve(request).then(function (response) {
|
|
692
|
+
if (disposed || generation !== catalogGeneration) return;
|
|
693
|
+
if (!response || response.ok !== true) {
|
|
694
|
+
catalogStatus = "error";
|
|
695
|
+
catalogError = response && response.error ? messageOf(response.error) : "modelCatalog failed";
|
|
696
|
+
publish();
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
var groups = response.value && Array.isArray(response.value.groups) ? response.value.groups : [];
|
|
700
|
+
var providers = [];
|
|
701
|
+
var byProvider = {};
|
|
702
|
+
var effortsByModel = {};
|
|
703
|
+
for (var i = 0; i < groups.length; i += 1) {
|
|
704
|
+
var group = groups[i];
|
|
705
|
+
if (!group || typeof group.id !== "string" || group.id === "") continue;
|
|
706
|
+
var models = [];
|
|
707
|
+
var effortsForProvider = {};
|
|
708
|
+
var list = Array.isArray(group.models) ? group.models : [];
|
|
709
|
+
for (var j = 0; j < list.length; j += 1) {
|
|
710
|
+
var model = list[j];
|
|
711
|
+
if (!model || typeof model.id !== "string" || model.id === "") continue;
|
|
712
|
+
models.push({ id: model.id, label: modelLabel(model) });
|
|
713
|
+
// 不支持推理强度的模型整个 reasoning 字段缺失 → reasoningEffortsOf 返回空数组,
|
|
714
|
+
// 这里只在非空时登记,渲染层用「查不到 = 不支持」判定。
|
|
715
|
+
var efforts = reasoningEffortsOf(model);
|
|
716
|
+
if (efforts.length > 0) effortsForProvider[model.id] = efforts;
|
|
717
|
+
}
|
|
718
|
+
byProvider[group.id] = models;
|
|
719
|
+
if (Object.keys(effortsForProvider).length > 0) effortsByModel[group.id] = effortsForProvider;
|
|
720
|
+
providers.push({ id: group.id, label: providerLabel(group) });
|
|
721
|
+
}
|
|
722
|
+
providers.sort(function (left, right) {
|
|
723
|
+
if (left.id === right.id) return 0;
|
|
724
|
+
return left.id < right.id ? -1 : 1;
|
|
725
|
+
});
|
|
726
|
+
catalogProviders = providers;
|
|
727
|
+
catalogByProvider = byProvider;
|
|
728
|
+
catalogEfforts = effortsByModel;
|
|
729
|
+
catalogStatus = "ready";
|
|
730
|
+
catalogError = "";
|
|
731
|
+
publish();
|
|
732
|
+
}, function (error) {
|
|
733
|
+
if (disposed || generation !== catalogGeneration) return;
|
|
734
|
+
catalogStatus = "error";
|
|
735
|
+
catalogError = messageOf(error);
|
|
736
|
+
publish();
|
|
737
|
+
});
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
function start() {
|
|
741
|
+
var disposers = [];
|
|
742
|
+
if (scope && typeof scope.subscribe === "function") {
|
|
743
|
+
var offScope = scope.subscribe(onScopeChange);
|
|
744
|
+
if (typeof offScope === "function") disposers.push(offScope);
|
|
745
|
+
}
|
|
746
|
+
var remote = ctx && ctx.remote;
|
|
747
|
+
if (remote && typeof remote.$on === "function") {
|
|
748
|
+
try {
|
|
749
|
+
var offCatalog = remote.$on("llm/adapters-updated", function () {
|
|
750
|
+
loadCatalog();
|
|
751
|
+
});
|
|
752
|
+
if (typeof offCatalog === "function") disposers.push(offCatalog);
|
|
753
|
+
} catch (error) {
|
|
754
|
+
/* 事件订阅失败只影响目录自动刷新,不阻断页面 */
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
publish();
|
|
758
|
+
loadCatalog();
|
|
759
|
+
return function () {
|
|
760
|
+
disposed = true;
|
|
761
|
+
var snapshot = disposers;
|
|
762
|
+
disposers = [];
|
|
763
|
+
for (var i = 0; i < snapshot.length; i += 1) {
|
|
764
|
+
try {
|
|
765
|
+
snapshot[i]();
|
|
766
|
+
} catch (error) {
|
|
767
|
+
/* dispose 失败不影响其余清理 */
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
publish();
|
|
774
|
+
|
|
775
|
+
return {
|
|
776
|
+
store: store,
|
|
777
|
+
start: start,
|
|
778
|
+
editRow: editRow,
|
|
779
|
+
resetRow: resetRow,
|
|
780
|
+
discard: discard,
|
|
781
|
+
save: save,
|
|
782
|
+
loadCatalog: loadCatalog
|
|
783
|
+
};
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
/* ── 样式(复用官方 ---dsw-alias-* token,深浅色自动跟随) ─────── */
|
|
787
|
+
|
|
788
|
+
function installCss() {
|
|
789
|
+
if (typeof document === "undefined") return;
|
|
790
|
+
var tagId = "dsh-cohub/cohub-section.css";
|
|
791
|
+
if (document.querySelector('style[data-plugin-css="' + tagId + '"]') !== null) return;
|
|
792
|
+
var css = [
|
|
793
|
+
".cohub-section{max-width:820px;display:flex;flex-direction:column;gap:12px;color:var(--dsw-alias-label-primary);}",
|
|
794
|
+
".cohub-title{margin:0;font-size:16px;font-weight:600;line-height:24px;}",
|
|
795
|
+
".cohub-desc{color:var(--dsw-alias-label-tertiary);margin:0;font-size:13px;line-height:20px;}",
|
|
796
|
+
".cohub-notice{margin:0;padding:8px 12px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-2);font-size:13px;line-height:20px;color:var(--dsw-alias-label-secondary);}",
|
|
797
|
+
".cohub-notice-error{color:var(--dsw-alias-state-error-primary);border-color:var(--dsw-alias-state-error-primary);}",
|
|
798
|
+
".cohub-notice-warn{color:var(--dsw-alias-state-warning-primary,#8d6e00);}",
|
|
799
|
+
".cohub-notice-ok{color:var(--dsw-alias-state-success-primary);}",
|
|
800
|
+
".cohub-rows{margin:0;padding:0;list-style:none;display:flex;flex-direction:column;gap:8px;}",
|
|
801
|
+
".cohub-row{border:1px solid var(--dsw-alias-border-l2);border-radius:10px;padding:10px 12px;background:var(--dsw-alias-bg-layer-2);}",
|
|
802
|
+
".cohub-row-head{display:flex;align-items:center;gap:8px;flex-wrap:wrap;}",
|
|
803
|
+
".cohub-row-name{font-size:13px;font-weight:600;line-height:20px;}",
|
|
804
|
+
".cohub-row-id{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:18px;}",
|
|
805
|
+
".cohub-badge{margin-left:auto;border-radius:999px;padding:1px 8px;font-size:11px;line-height:17px;white-space:nowrap;border:1px solid var(--dsw-alias-border-l2);color:var(--dsw-alias-label-tertiary);}",
|
|
806
|
+
".cohub-badge-explicit{color:var(--dsw-alias-state-success-primary);border-color:var(--dsw-alias-state-success-primary);}",
|
|
807
|
+
// 四列:供应商 / 模型 / 推理强度 / 重置。三列下拉都等分剩余宽度,重置按钮自适应。
|
|
808
|
+
".cohub-fields{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr) minmax(0,1fr) auto;gap:8px;margin-top:8px;align-items:end;}",
|
|
809
|
+
// 窄容器下 4 列会把下拉压到不可读:退成两列(前三个字段各占一行两列,按钮贴右下)。
|
|
810
|
+
"@media (max-width:560px){.cohub-fields{grid-template-columns:minmax(0,1fr) minmax(0,1fr);}}",
|
|
811
|
+
".cohub-field{display:flex;flex-direction:column;gap:4px;min-width:0;}",
|
|
812
|
+
".cohub-label{color:var(--dsw-alias-label-secondary);font-size:12px;line-height:18px;}",
|
|
813
|
+
".cohub-select,.cohub-input{box-sizing:border-box;width:100%;height:32px;font:inherit;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-layer-3);border:1px solid var(--dsw-alias-border-l2);border-radius:8px;padding:0 10px;font-size:13px;line-height:20px;}",
|
|
814
|
+
".cohub-select:focus-visible,.cohub-input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none;}",
|
|
815
|
+
".cohub-select:disabled,.cohub-input:disabled{opacity:.6;cursor:default;}",
|
|
816
|
+
".cohub-row-reset{height:32px;border-radius:8px;padding:0 10px;font:inherit;font-size:12px;line-height:18px;cursor:pointer;color:var(--dsw-alias-label-secondary);background:transparent;border:1px solid var(--dsw-alias-border-l2);}",
|
|
817
|
+
".cohub-row-reset:hover:not(:disabled){color:var(--dsw-alias-label-primary);}",
|
|
818
|
+
".cohub-row-reset:disabled{opacity:.45;cursor:default;}",
|
|
819
|
+
".cohub-actions{display:flex;justify-content:flex-end;align-items:center;gap:8px;flex-wrap:wrap;}",
|
|
820
|
+
".cohub-status{margin:0;margin-right:auto;font-size:12px;line-height:18px;color:var(--dsw-alias-label-tertiary);}",
|
|
821
|
+
".cohub-status-error{color:var(--dsw-alias-state-error-primary);}",
|
|
822
|
+
".cohub-status-warn{color:var(--dsw-alias-state-warning-primary,#8d6e00);}",
|
|
823
|
+
".cohub-status-ok{color:var(--dsw-alias-state-success-primary);}",
|
|
824
|
+
".cohub-button{height:32px;font:inherit;cursor:pointer;border-radius:8px;padding:0 14px;font-size:13px;line-height:20px;}",
|
|
825
|
+
".cohub-button-primary{color:var(--dsw-alias-label-primary-foreground);background:var(--dsw-alias-button-primary-fill);border:none;}",
|
|
826
|
+
".cohub-button-primary:hover:not(:disabled){background:var(--dsw-alias-button-primary-hover);}",
|
|
827
|
+
".cohub-button-ghost{color:var(--dsw-alias-label-secondary);background:transparent;border:1px solid var(--dsw-alias-border-l2);}",
|
|
828
|
+
".cohub-button-ghost:hover:not(:disabled){color:var(--dsw-alias-label-primary);}",
|
|
829
|
+
".cohub-button:disabled{opacity:.45;cursor:default;}"
|
|
830
|
+
].join("\n");
|
|
831
|
+
var tag = document.createElement("style");
|
|
832
|
+
tag.dataset.plugin = "dsh-cohub";
|
|
833
|
+
tag.dataset.pluginCss = tagId;
|
|
834
|
+
tag.textContent = css;
|
|
835
|
+
document.head.appendChild(tag);
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
/* ── 组件 ─────────────────────────────────────────────────────── */
|
|
839
|
+
|
|
840
|
+
/** uSES 选择器:整个快照。 */
|
|
841
|
+
function selectAllSnapshot(value) {
|
|
842
|
+
return value;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/** props.useCohubSkills 缺失时的常量 hook(保持 hook 调用顺序稳定)。 */
|
|
846
|
+
function useStaticState(selector) {
|
|
847
|
+
return selector(EMPTY_STATE);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/**
|
|
851
|
+
* settings.section 页面。
|
|
852
|
+
* @param props - 注入面:hooks.cohubSkills→useCohubSkills、动作、locale 提供的 t。
|
|
853
|
+
* @returns 每个代理一行(供应商下拉 + 模型下拉/手填 + 推理强度下拉 + 重置)与保存/放弃。
|
|
854
|
+
*/
|
|
855
|
+
function CohubSection(props) {
|
|
856
|
+
var t = typeof props.t === "function" ? props.t : fallbackTranslate;
|
|
857
|
+
var useSkills = typeof props.useCohubSkills === "function" ? props.useCohubSkills : useStaticState;
|
|
858
|
+
var state = useSkills(selectAllSnapshot) || EMPTY_STATE;
|
|
859
|
+
|
|
860
|
+
var header = [
|
|
861
|
+
React.createElement("h2", { key: "title", className: "cohub-title" }, t("title")),
|
|
862
|
+
React.createElement("p", { key: "desc", className: "cohub-desc" }, t("description"))
|
|
863
|
+
];
|
|
864
|
+
|
|
865
|
+
if (state.status !== "ready") {
|
|
866
|
+
return React.createElement("div", { className: "cohub-section" },
|
|
867
|
+
header,
|
|
868
|
+
React.createElement("p", { className: "cohub-notice" },
|
|
869
|
+
state.status === "unavailable" ? t("unavailable") : t("loading"))
|
|
870
|
+
);
|
|
871
|
+
}
|
|
872
|
+
|
|
873
|
+
var locked = !state.writable || state.saving || state.conflicted;
|
|
874
|
+
var providers = state.providers || [];
|
|
875
|
+
var modelsByProvider = state.modelsByProvider || {};
|
|
876
|
+
var rows = state.rows || [];
|
|
877
|
+
|
|
878
|
+
function renderRow(row) {
|
|
879
|
+
var known = SKILL_NAMES.indexOf(row.name) >= 0;
|
|
880
|
+
var label = known ? t("skill." + row.name) : row.name;
|
|
881
|
+
var providerIds = [];
|
|
882
|
+
var providerOptions = [
|
|
883
|
+
React.createElement("option", { key: "__inherit", value: "" }, t("providerInherit"))
|
|
884
|
+
];
|
|
885
|
+
for (var i = 0; i < providers.length; i += 1) {
|
|
886
|
+
providerIds.push(providers[i].id);
|
|
887
|
+
providerOptions.push(React.createElement("option", { key: providers[i].id, value: providers[i].id }, providers[i].label));
|
|
888
|
+
}
|
|
889
|
+
if (row.provider !== "" && providerIds.indexOf(row.provider) < 0) {
|
|
890
|
+
// 已存但当前目录里没有:给一个不可选回显项,避免下拉显示成第一项造成误读。
|
|
891
|
+
providerOptions.push(React.createElement("option", {
|
|
892
|
+
key: "__missing-provider",
|
|
893
|
+
value: row.provider,
|
|
894
|
+
disabled: true
|
|
895
|
+
}, state.catalogStatus === "ready" ? t("unavailableOption", { value: row.provider }) : row.provider));
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
var models = modelsByProvider[row.provider] || [];
|
|
899
|
+
var modelControl;
|
|
900
|
+
if (row.provider === "") {
|
|
901
|
+
modelControl = React.createElement("select", { className: "cohub-select", value: "", disabled: true },
|
|
902
|
+
React.createElement("option", { value: "" }, t("selectProviderFirst")));
|
|
903
|
+
} else if (state.catalogStatus === "loading") {
|
|
904
|
+
modelControl = React.createElement("select", { className: "cohub-select", value: "", disabled: true },
|
|
905
|
+
React.createElement("option", { value: "" }, t("loading")));
|
|
906
|
+
} else if (models.length > 0) {
|
|
907
|
+
// 未保存 model 时必须插入 value="" 的占位项。否则 <select value=""> 会被浏览器
|
|
908
|
+
// 渲染成列表第一项,用户以为已选、实际存的仍是空 → 子代理拿不到模型(UNKNOWN_MODEL)。
|
|
909
|
+
var modelOptions = [React.createElement("option", { key: "__inherit", value: "" }, t("modelInherit"))];
|
|
910
|
+
var modelIds = [];
|
|
911
|
+
for (var m = 0; m < models.length; m += 1) {
|
|
912
|
+
modelIds.push(models[m].id);
|
|
913
|
+
modelOptions.push(React.createElement("option", { key: models[m].id, value: models[m].id }, models[m].label));
|
|
914
|
+
}
|
|
915
|
+
if (row.model !== "" && modelIds.indexOf(row.model) < 0) {
|
|
916
|
+
modelOptions.push(React.createElement("option", {
|
|
917
|
+
key: "__missing-model",
|
|
918
|
+
value: row.model,
|
|
919
|
+
disabled: true
|
|
920
|
+
}, t("unavailableOption", { value: row.model })));
|
|
921
|
+
}
|
|
922
|
+
modelControl = React.createElement("select", {
|
|
923
|
+
className: "cohub-select",
|
|
924
|
+
value: row.model === "" ? "" : row.model,
|
|
925
|
+
disabled: locked,
|
|
926
|
+
"aria-label": label + " · " + t("model"),
|
|
927
|
+
onChange: function (event) {
|
|
928
|
+
props.editRow(row.name, "model", event.target.value);
|
|
929
|
+
}
|
|
930
|
+
}, modelOptions);
|
|
931
|
+
} else {
|
|
932
|
+
// 该供应商没有可用模型目录(或目录加载失败)→ 降级为手填 model id。
|
|
933
|
+
modelControl = React.createElement("input", {
|
|
934
|
+
className: "cohub-input",
|
|
935
|
+
type: "text",
|
|
936
|
+
value: row.model,
|
|
937
|
+
disabled: locked,
|
|
938
|
+
"aria-label": label + " · " + t("model"),
|
|
939
|
+
placeholder: state.catalogStatus === "ready" ? t("emptyModel") + " / " + t("customModel") : t("customModel"),
|
|
940
|
+
onChange: function (event) {
|
|
941
|
+
props.editRow(row.name, "model", event.target.value);
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
var configured = row.provider !== "" || row.model !== "" || effortOf(row) !== "";
|
|
947
|
+
|
|
948
|
+
// 第三个下拉:推理强度。档位来自模型目录(models[].reasoning.efforts),
|
|
949
|
+
// 按「供应商 + 模型」这一对查表;不支持的模型整个 reasoning 字段缺失 → 禁用并提示。
|
|
950
|
+
var currentEffort = effortOf(row);
|
|
951
|
+
var efforts = [];
|
|
952
|
+
if (row.provider !== "" && row.model !== "") {
|
|
953
|
+
var byModel = state.effortsByModel && state.effortsByModel[row.provider];
|
|
954
|
+
var list = byModel ? byModel[row.model] : undefined;
|
|
955
|
+
if (Array.isArray(list)) efforts = list;
|
|
956
|
+
}
|
|
957
|
+
var effortControl;
|
|
958
|
+
if (row.provider === "") {
|
|
959
|
+
effortControl = React.createElement("select", { className: "cohub-select", value: "", disabled: true },
|
|
960
|
+
React.createElement("option", { value: "" }, t("selectProviderFirst")));
|
|
961
|
+
} else if (state.catalogStatus === "loading") {
|
|
962
|
+
effortControl = React.createElement("select", { className: "cohub-select", value: "", disabled: true },
|
|
963
|
+
React.createElement("option", { value: "" }, t("loading")));
|
|
964
|
+
} else if (row.model === "") {
|
|
965
|
+
effortControl = React.createElement("select", { className: "cohub-select", value: "", disabled: true },
|
|
966
|
+
React.createElement("option", { value: "" }, t("effortSelectModelFirst")));
|
|
967
|
+
} else if (efforts.length === 0) {
|
|
968
|
+
// 模型目录里没有该模型的 reasoning 信息(或手填了不在目录里的 model id)→ 不支持。
|
|
969
|
+
effortControl = React.createElement("select", { className: "cohub-select", value: "", disabled: true },
|
|
970
|
+
React.createElement("option", { value: "" }, t("effortUnsupported")));
|
|
971
|
+
} else {
|
|
972
|
+
// 与模型下拉同理:value="" 的继承占位项必须在首位,否则浏览器把第一档显示成已选,
|
|
973
|
+
// 而实际存的是空串(用户以为配了 high,其实继承父会话)。
|
|
974
|
+
var effortOptions = [React.createElement("option", { key: "__inherit", value: "" }, t("effortInherit"))];
|
|
975
|
+
var effortIds = [];
|
|
976
|
+
for (var e = 0; e < efforts.length; e += 1) {
|
|
977
|
+
effortIds.push(efforts[e].id);
|
|
978
|
+
effortOptions.push(React.createElement("option", { key: efforts[e].id, value: efforts[e].id }, efforts[e].label));
|
|
979
|
+
}
|
|
980
|
+
if (currentEffort !== "" && effortIds.indexOf(currentEffort) < 0) {
|
|
981
|
+
// 已配强度不在当前模型档位里(手改过 YAML / 换过模型)→ 给不可选回显项,别静默改成第一档。
|
|
982
|
+
effortOptions.push(React.createElement("option", {
|
|
983
|
+
key: "__missing-effort",
|
|
984
|
+
value: currentEffort,
|
|
985
|
+
disabled: true
|
|
986
|
+
}, t("effortUnsupportedOption", { value: currentEffort })));
|
|
987
|
+
}
|
|
988
|
+
effortControl = React.createElement("select", {
|
|
989
|
+
className: "cohub-select",
|
|
990
|
+
value: currentEffort,
|
|
991
|
+
disabled: locked,
|
|
992
|
+
"aria-label": label + " · " + t("reasoningEffort"),
|
|
993
|
+
onChange: function (event) {
|
|
994
|
+
props.editRow(row.name, "reasoningEffort", event.target.value);
|
|
995
|
+
}
|
|
996
|
+
}, effortOptions);
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
return React.createElement("li", { key: row.name, className: "cohub-row" },
|
|
1000
|
+
React.createElement("div", { className: "cohub-row-head" },
|
|
1001
|
+
React.createElement("span", { className: "cohub-row-name" }, label),
|
|
1002
|
+
React.createElement("span", { className: "cohub-row-id" }, row.name),
|
|
1003
|
+
React.createElement("span", {
|
|
1004
|
+
className: configured ? "cohub-badge cohub-badge-explicit" : "cohub-badge"
|
|
1005
|
+
}, configured ? t("configured") : t("inherited"))
|
|
1006
|
+
),
|
|
1007
|
+
React.createElement("div", { className: "cohub-fields" },
|
|
1008
|
+
React.createElement("div", { className: "cohub-field" },
|
|
1009
|
+
React.createElement("label", { className: "cohub-label" }, t("provider")),
|
|
1010
|
+
React.createElement("select", {
|
|
1011
|
+
className: "cohub-select",
|
|
1012
|
+
value: row.provider,
|
|
1013
|
+
disabled: locked,
|
|
1014
|
+
"aria-label": label + " · " + t("provider"),
|
|
1015
|
+
onChange: function (event) {
|
|
1016
|
+
props.editRow(row.name, "provider", event.target.value);
|
|
1017
|
+
}
|
|
1018
|
+
}, providerOptions)
|
|
1019
|
+
),
|
|
1020
|
+
React.createElement("div", { className: "cohub-field" },
|
|
1021
|
+
React.createElement("label", { className: "cohub-label" }, t("model")),
|
|
1022
|
+
modelControl
|
|
1023
|
+
),
|
|
1024
|
+
React.createElement("div", { className: "cohub-field" },
|
|
1025
|
+
React.createElement("label", { className: "cohub-label" }, t("reasoningEffort")),
|
|
1026
|
+
effortControl
|
|
1027
|
+
),
|
|
1028
|
+
React.createElement("button", {
|
|
1029
|
+
type: "button",
|
|
1030
|
+
className: "cohub-row-reset",
|
|
1031
|
+
disabled: locked || !configured,
|
|
1032
|
+
onClick: function () {
|
|
1033
|
+
props.resetRow(row.name);
|
|
1034
|
+
}
|
|
1035
|
+
}, t("reset"))
|
|
1036
|
+
)
|
|
1037
|
+
);
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
var items = [];
|
|
1041
|
+
for (var i = 0; i < rows.length; i += 1) items.push(renderRow(rows[i]));
|
|
1042
|
+
|
|
1043
|
+
var status = null;
|
|
1044
|
+
var statusClass = "cohub-status";
|
|
1045
|
+
if (state.conflicted) {
|
|
1046
|
+
status = t("conflicted");
|
|
1047
|
+
statusClass += " cohub-status-warn";
|
|
1048
|
+
} else if (state.failed) {
|
|
1049
|
+
status = t("failed");
|
|
1050
|
+
statusClass += " cohub-status-error";
|
|
1051
|
+
} else if (state.saved) {
|
|
1052
|
+
status = t("saved");
|
|
1053
|
+
statusClass += " cohub-status-ok";
|
|
1054
|
+
} else if (state.dirty) {
|
|
1055
|
+
status = t("dirty");
|
|
1056
|
+
} else if (!state.writable) {
|
|
1057
|
+
status = t("readOnly");
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
return React.createElement("div", { className: "cohub-section" },
|
|
1061
|
+
header,
|
|
1062
|
+
!state.writable ? React.createElement("p", { className: "cohub-notice" }, t("readOnly")) : null,
|
|
1063
|
+
state.catalogStatus === "error"
|
|
1064
|
+
? React.createElement("p", { className: "cohub-notice cohub-notice-error" },
|
|
1065
|
+
t("loadProvidersFailed") + (state.catalogError ? ": " + state.catalogError : ""),
|
|
1066
|
+
React.createElement("button", {
|
|
1067
|
+
type: "button",
|
|
1068
|
+
className: "cohub-row-reset",
|
|
1069
|
+
style: { marginLeft: "8px" },
|
|
1070
|
+
onClick: function () {
|
|
1071
|
+
props.retryCatalog();
|
|
1072
|
+
}
|
|
1073
|
+
}, t("retry")))
|
|
1074
|
+
: null,
|
|
1075
|
+
state.conflicted
|
|
1076
|
+
? React.createElement("p", { className: "cohub-notice cohub-notice-warn" }, t("conflicted"))
|
|
1077
|
+
: null,
|
|
1078
|
+
React.createElement("ul", { className: "cohub-rows" }, items),
|
|
1079
|
+
React.createElement("div", { className: "cohub-actions" },
|
|
1080
|
+
status !== null ? React.createElement("p", { className: statusClass }, status) : null,
|
|
1081
|
+
React.createElement("button", {
|
|
1082
|
+
type: "button",
|
|
1083
|
+
className: "cohub-button cohub-button-ghost",
|
|
1084
|
+
disabled: !state.dirty || state.saving,
|
|
1085
|
+
onClick: function () {
|
|
1086
|
+
props.discard();
|
|
1087
|
+
}
|
|
1088
|
+
}, t("discard")),
|
|
1089
|
+
React.createElement("button", {
|
|
1090
|
+
type: "button",
|
|
1091
|
+
className: "cohub-button cohub-button-primary",
|
|
1092
|
+
disabled: !state.dirty || !state.writable || state.saving || state.conflicted,
|
|
1093
|
+
onClick: function () {
|
|
1094
|
+
props.save();
|
|
1095
|
+
}
|
|
1096
|
+
}, t(state.saving ? "saving" : "save"))
|
|
1097
|
+
)
|
|
1098
|
+
);
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
/* ── 插件体 ───────────────────────────────────────────────────── */
|
|
1102
|
+
|
|
112
1103
|
function apply(ctx) {
|
|
113
1104
|
ctx.effect(function () {
|
|
114
1105
|
return ctx.locale.register(NS, { zh: zh, en: en });
|
|
115
1106
|
}, "cohub: settings dictionaries");
|
|
1107
|
+
|
|
1108
|
+
installCss();
|
|
1109
|
+
|
|
1110
|
+
var scope = null;
|
|
1111
|
+
if (ctx.configForms && typeof ctx.configForms.get === "function") {
|
|
1112
|
+
try {
|
|
1113
|
+
scope = ctx.configForms.get(ENTRY_ID) || null;
|
|
1114
|
+
} catch (error) {
|
|
1115
|
+
scope = null;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
var controller = buildSkillsController(ctx, scope);
|
|
1120
|
+
|
|
1121
|
+
ctx.effect(function () {
|
|
1122
|
+
return controller.start();
|
|
1123
|
+
}, "cohub: agent model settings wiring");
|
|
1124
|
+
|
|
1125
|
+
var injected = function () {
|
|
1126
|
+
return {
|
|
1127
|
+
hooks: { cohubSkills: controller.store },
|
|
1128
|
+
editRow: function (name, field, value) {
|
|
1129
|
+
controller.editRow(name, field, value);
|
|
1130
|
+
},
|
|
1131
|
+
resetRow: function (name) {
|
|
1132
|
+
controller.resetRow(name);
|
|
1133
|
+
},
|
|
1134
|
+
discard: function () {
|
|
1135
|
+
controller.discard();
|
|
1136
|
+
},
|
|
1137
|
+
save: function () {
|
|
1138
|
+
return controller.save();
|
|
1139
|
+
},
|
|
1140
|
+
retryCatalog: function () {
|
|
1141
|
+
controller.loadCatalog();
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
};
|
|
1145
|
+
|
|
1146
|
+
// settings.section 的 label 是 thunk:宿主每次投影导航都重读,跟随语言切换。
|
|
1147
|
+
var navLabel = function () {
|
|
1148
|
+
return ctx.locale.bind(NS)("nav");
|
|
1149
|
+
};
|
|
1150
|
+
|
|
1151
|
+
ctx.slots.inject("settings.section", function () {
|
|
1152
|
+
return ctx.slots.register({
|
|
1153
|
+
name: "settings.section",
|
|
1154
|
+
id: ENTRY_ID,
|
|
1155
|
+
order: SECTION_ORDER,
|
|
1156
|
+
label: navLabel,
|
|
1157
|
+
locale: NS,
|
|
1158
|
+
inject: injected
|
|
1159
|
+
}, CohubSection);
|
|
1160
|
+
});
|
|
116
1161
|
}
|
|
117
1162
|
|
|
118
1163
|
exports.apply = apply;
|
|
119
1164
|
exports.inject = inject;
|
|
1165
|
+
// 纯函数契约(仅 test/client-runtime-0.2.ts 断言用;宿主不读)。
|
|
1166
|
+
exports.__internals = {
|
|
1167
|
+
rowsFromSkills: rowsFromSkills,
|
|
1168
|
+
rowsToSkills: rowsToSkills,
|
|
1169
|
+
reasoningEffortsOf: reasoningEffortsOf
|
|
1170
|
+
};
|
|
120
1171
|
return module.exports;
|
|
121
1172
|
}
|
|
122
1173
|
});
|