dsh-nova-lewis 0.2.4 → 0.2.5
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.cn.md +5 -5
- package/README.md +8 -8
- package/dist/client.js +83 -7
- package/host/chat-replies.mjs +1 -1
- package/host/index.mjs +10 -9
- package/host/models.mjs +53 -13
- package/host/reply-view.mjs +10 -7
- package/host/roll-call.mjs +7 -27
- package/host/selection.mjs +13 -1
- package/package.json +3 -3
- package/src/engine-plan.mjs +4 -34
- package/src/engine.mjs +55 -15
- package/src/knowledge-intelligence.mjs +20 -0
- package/src/model-knowledge.mjs +8 -2
- package/src/preset-catalog.mjs +10 -3
- package/src/role-routing.mjs +41 -10
package/README.cn.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
`dsh-nova-lewis` · v0.2.
|
|
1
|
+
`dsh-nova-lewis` · v0.2.5 · [npm](https://www.npmjs.com/package/dsh-nova-lewis)
|
|
2
2
|
|
|
3
|
-
[English](https://www.npmjs.com/package/dsh-nova-lewis/v/0.2.
|
|
3
|
+
[English](https://www.npmjs.com/package/dsh-nova-lewis/v/0.2.5) | 简体中文
|
|
4
4
|
|
|
5
5
|
# ds-nova · 附魔台多模型协作
|
|
6
6
|
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
2. 在各个 API 连接下勾选具体型号。同一连接下可以勾选多个型号。只有一个型号时,它也可以分步完成能力范围内的工作。
|
|
17
17
|
3. 选择 **确认后执行** 或 **直接执行**,然后照常发送任务。前一种方式会先生成计划,你可以查看分工、改派负责人,再点 **确认并开始**。
|
|
18
18
|
|
|
19
|
-

|
|
20
20
|
|
|
21
21
|
可以直接把这个订单迁移任务发到聊天框。
|
|
22
22
|
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
|
|
29
29
|
下面的本机演示使用同一个 API 连接。A 整理字段映射,B 据此分析兼容读取,C 需要 A 和 B 的成果才能评估回滚。
|
|
30
30
|
|
|
31
|
-

|
|
32
32
|
|
|
33
33
|
- **任务资料** 在协作设置中添加验收条款等原文,发送时在 **本次资料** 中勾选。复核模型可以按行引用这些条款。
|
|
34
34
|
- **分工建议** 在 **模型与分工** 中查看哪些已选型号适合统筹、起草工作提示词或执行复核,以及这些建议的依据。
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
- **两种更新** 在 **更新与作者** 检查插件软件版本。在线模型推荐资料有独立版本,在 **模型预设 → 检查开发者更新** 查看哪些型号的分工建议有变化,选择 **应用更新** 即可使用新资料。
|
|
37
37
|
- **作者与数据共享** 在 **更新与作者** 查看作者信息。数据共享默认关闭,只有阅读说明并明确同意后才会开启,共享记录只归在 DS Nova 名下。你可以随时在同一窗口停止共享并请求删除记录。
|
|
38
38
|
|
|
39
|
-

|
|
40
40
|
|
|
41
41
|
## 作者
|
|
42
42
|
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
`dsh-nova-lewis` · v0.2.
|
|
1
|
+
`dsh-nova-lewis` · v0.2.5 · [npm](https://www.npmjs.com/package/dsh-nova-lewis)
|
|
2
2
|
|
|
3
|
-
[English](#english) | [简体中文](#简体中文) · [中文版 Markdown 文件](https://cdn.jsdelivr.net/npm/dsh-nova-lewis@0.2.
|
|
3
|
+
[English](#english) | [简体中文](#简体中文) · [中文版 Markdown 文件](https://cdn.jsdelivr.net/npm/dsh-nova-lewis@0.2.5/README.cn.md)
|
|
4
4
|
|
|
5
5
|
# ds-nova · Multi-model collaboration for DeepSeek Harness
|
|
6
6
|
|
|
@@ -18,7 +18,7 @@ In DeepSeek Harness 0.2.2-rc.5, open **Plugins → Add Plugin**, enter `dsh-nova
|
|
|
18
18
|
2. Select individual models under their API connections. You can select several models from one connection. If you have one model, it can handle successive steps within its capabilities.
|
|
19
19
|
3. Choose **确认后执行** (Review the plan first) or **直接执行** (Start directly), then send your task. With the first option, you can inspect the plan and reassign a step before clicking **确认并开始** (Confirm and start).
|
|
20
20
|
|
|
21
|
-

|
|
22
22
|
|
|
23
23
|
Try this order migration task in chat.
|
|
24
24
|
|
|
@@ -30,7 +30,7 @@ Open **协作导图** (Task graph) from the collaboration menu. The canvas conne
|
|
|
30
30
|
|
|
31
31
|
In this local demonstration, all three models use one API connection. Step A maps the fields. Step B uses that mapping to assess read compatibility. Step C needs both results to evaluate rollback.
|
|
32
32
|
|
|
33
|
-

|
|
34
34
|
|
|
35
35
|
- **Task materials.** Add a source such as acceptance criteria in collaboration settings. Select it under **本次资料** when sending the task so the reviewer can cite the original lines.
|
|
36
36
|
- **Assignment guidance.** Under **模型与分工**, see which selected models are suited to coordination, drafting work instructions, or reviewing a result, along with the evidence for those suggestions.
|
|
@@ -38,7 +38,7 @@ In this local demonstration, all three models use one API connection. Step A map
|
|
|
38
38
|
- **Software and model updates.** Check the software version under **更新与作者**. Model recommendations have their own version. Open **模型预设 → 检查开发者更新** to see which model profiles have changed, then choose **应用更新** to apply the new guidance to your installed plugin.
|
|
39
39
|
- **Author and data sharing.** Open **更新与作者** to view author information. Data sharing is off by default and requires your explicit consent. Shared records are attributed only to DS Nova. You can stop sharing and request deletion in the same window at any time.
|
|
40
40
|
|
|
41
|
-

|
|
42
42
|
|
|
43
43
|
### Author
|
|
44
44
|
|
|
@@ -58,7 +58,7 @@ Zhou Yichen (FerrariLewis) created the DSH LEWIS ENCHANTMENT series. Its startup
|
|
|
58
58
|
2. 在各个 API 连接下勾选具体型号。同一连接下可以勾选多个型号。只有一个型号时,它也可以分步完成能力范围内的工作。
|
|
59
59
|
3. 选择 **确认后执行** 或 **直接执行**,然后照常发送任务。前一种方式会先生成计划,你可以查看分工、改派负责人,再点 **确认并开始**。
|
|
60
60
|
|
|
61
|
-

|
|
62
62
|
|
|
63
63
|
可以直接把这个订单迁移任务发到聊天框。
|
|
64
64
|
|
|
@@ -70,7 +70,7 @@ Zhou Yichen (FerrariLewis) created the DSH LEWIS ENCHANTMENT series. Its startup
|
|
|
70
70
|
|
|
71
71
|
下面的本机演示使用同一个 API 连接。A 整理字段映射,B 据此分析兼容读取,C 需要 A 和 B 的成果才能评估回滚。
|
|
72
72
|
|
|
73
|
-

|
|
74
74
|
|
|
75
75
|
- **任务资料** 在协作设置中添加验收条款等原文,发送时在 **本次资料** 中勾选。复核模型可以按行引用这些条款。
|
|
76
76
|
- **分工建议** 在 **模型与分工** 中查看哪些已选型号适合统筹、起草工作提示词或执行复核,以及这些建议的依据。
|
|
@@ -78,7 +78,7 @@ Zhou Yichen (FerrariLewis) created the DSH LEWIS ENCHANTMENT series. Its startup
|
|
|
78
78
|
- **两种更新** 在 **更新与作者** 检查插件软件版本。在线模型推荐资料有独立版本,在 **模型预设 → 检查开发者更新** 查看哪些型号的分工建议有变化,选择 **应用更新** 即可使用新资料。
|
|
79
79
|
- **作者与数据共享** 在 **更新与作者** 查看作者信息。数据共享默认关闭,只有阅读说明并明确同意后才会开启,共享记录只归在 DS Nova 名下。你可以随时在同一窗口停止共享并请求删除记录。
|
|
80
80
|
|
|
81
|
-

|
|
82
82
|
|
|
83
83
|
### 作者
|
|
84
84
|
|
package/dist/client.js
CHANGED
|
@@ -200,6 +200,7 @@ var roleLabel = (role) => roles[role] || role || "执行节点";
|
|
|
200
200
|
function allNodes(run) {
|
|
201
201
|
if (!run) return [];
|
|
202
202
|
if (run.settings?.easterEgg) return run.nodes || [];
|
|
203
|
+
if (run.nodes?.length === 1 && run.attempts?.some((a) => a.directAnswer && a.id === run.nodes[0].attemptId)) return run.nodes;
|
|
203
204
|
const plans = (run.attempts || []).filter(
|
|
204
205
|
(a) => a.kind === "planning" || a.kind === "plan" || a.nodeId === "plan"
|
|
205
206
|
);
|
|
@@ -1338,6 +1339,37 @@ var alternativeProfiles = [
|
|
|
1338
1339
|
...expandedAlternativeProfiles
|
|
1339
1340
|
];
|
|
1340
1341
|
|
|
1342
|
+
// src/knowledge-intelligence.mjs
|
|
1343
|
+
var scores = /* @__PURE__ */ new Map([
|
|
1344
|
+
["claude-fable-5-2", [65, "Max, Default Fallback"]],
|
|
1345
|
+
["gpt-6.2-astra", [62, "Max"]],
|
|
1346
|
+
["gemini-4-neon", [62, "Xhigh"]],
|
|
1347
|
+
["gemini-4-carbon", [60, "High"]],
|
|
1348
|
+
["claude-opus-5-5", [59, "Max, Default Fallback"]],
|
|
1349
|
+
["gpt-6.2-sol", [57, "Max"]],
|
|
1350
|
+
["claude-sonnet-5-5", [55, "Max, Default Fallback"]],
|
|
1351
|
+
["gemini-4-hydrogen", [54, "Xhigh"]],
|
|
1352
|
+
["gpt-6.1-terra", [51, "Max"]],
|
|
1353
|
+
["gemini-4-argon", [51, "High"]],
|
|
1354
|
+
["kimi-k3.1-pro", [47, "Kimi K3.1 Pro"]],
|
|
1355
|
+
["qwen4-max", [43, "Qwen4 Max"]],
|
|
1356
|
+
["claude-haiku-5-5", [37, "Max"]],
|
|
1357
|
+
["grok-4.7", [35, "Xhigh"]],
|
|
1358
|
+
["deepseek-flash", [32, "V4.1 Flash 1017 Max"]],
|
|
1359
|
+
["glm-5.3", [32, "Max"]],
|
|
1360
|
+
["MiniMax-M3.1-Flash", [29, "MiniMax-M3.1-Flash"]],
|
|
1361
|
+
["gpt-6-luna", [28, "Max"]],
|
|
1362
|
+
["glm-5.3-flash", [28, "Max"]],
|
|
1363
|
+
["mistral-large-4-0", [26, "High"]],
|
|
1364
|
+
["deepseek-v4-pro", [23, "V4 Pro 0813 Max"]],
|
|
1365
|
+
["MiniMax-M3", [19, "MiniMax-M3"]]
|
|
1366
|
+
]);
|
|
1367
|
+
var benchmarkCatalogVersion = "2026-12-02.1";
|
|
1368
|
+
function builtinIntelligenceIndex(id2) {
|
|
1369
|
+
const result = scores.get(id2);
|
|
1370
|
+
if (result) return { score: result[0], configuration: result[1] };
|
|
1371
|
+
}
|
|
1372
|
+
|
|
1341
1373
|
// src/preset-catalog.mjs
|
|
1342
1374
|
var presetFileLimit = 2 * 1024 * 1024;
|
|
1343
1375
|
var roles2 = /* @__PURE__ */ new Set(["planning", "prompting", "coding", "review", "research", "analysis", "writing", "vision", "final"]);
|
|
@@ -1391,6 +1423,12 @@ function profile2(value, ids) {
|
|
|
1391
1423
|
}
|
|
1392
1424
|
requireValue(value.existingOnly === void 0 || typeof value.existingOnly === "boolean", "已有部署标记无效。");
|
|
1393
1425
|
requireValue(value.workload === void 0 || ["efficient", "balanced", "advanced", "frontier"].includes(value.workload), id2 + " 的任务难度定位无效。");
|
|
1426
|
+
let intelligenceIndex;
|
|
1427
|
+
if (value.intelligenceIndex !== void 0) {
|
|
1428
|
+
const score = value.intelligenceIndex?.score;
|
|
1429
|
+
requireValue(Number.isFinite(score) && score >= 0 && score <= 100, id2 + " 的 AA Intelligence Index 分数无效。");
|
|
1430
|
+
intelligenceIndex = { score, configuration: string(value.intelligenceIndex.configuration, "AA 评测配置", 200) };
|
|
1431
|
+
}
|
|
1394
1432
|
const conditions = list2(value.conditions ?? [], 24, "岗位条件", 0).map((c) => {
|
|
1395
1433
|
const roleSet = list2(c?.roles, roles2.size, "条件岗位");
|
|
1396
1434
|
requireValue(roleSet.every((r) => Object.hasOwn(strengths, r)), id2 + " 的条件引用了未收录的岗位。");
|
|
@@ -1406,6 +1444,7 @@ function profile2(value, ids) {
|
|
|
1406
1444
|
aliases,
|
|
1407
1445
|
...value.existingOnly ? { existingOnly: true } : {},
|
|
1408
1446
|
...value.workload ? { workload: value.workload } : {},
|
|
1447
|
+
...intelligenceIndex && { intelligenceIndex },
|
|
1409
1448
|
...conditions.length ? { conditions } : {}
|
|
1410
1449
|
};
|
|
1411
1450
|
}
|
|
@@ -1462,8 +1501,12 @@ var workloadGroups = {
|
|
|
1462
1501
|
frontier: ["gpt-6.2-astra", "claude-fable-5-2", "claude-mythos-5-2", "gemini-4-carbon", "kimi-k3.1-pro", "kimi-k3.1-pro-highspeed"]
|
|
1463
1502
|
};
|
|
1464
1503
|
var workloads = new Map(Object.entries(workloadGroups).flatMap(([tier, ids]) => ids.map((id2) => [id2, tier])));
|
|
1465
|
-
var builtinCards = [...coreProfiles, ...alternativeProfiles].map((p) => ({ ...p, workload: workloads.get(p.id), conditions: taskHints.filter((h3) => h3.ids.includes(p.id)).map((h3) => ({ roles: h3.roles.filter((r) => Object.hasOwn(p.strengths, r)), keywords: h3.keywords, reason: h3.reason })).filter((h3) => h3.roles.length) }));
|
|
1466
|
-
var builtinPresetCatalog = validatePresetCatalog({ schemaVersion: 1, version:
|
|
1504
|
+
var builtinCards = [...coreProfiles, ...alternativeProfiles].map((p) => ({ ...p, workload: workloads.get(p.id), intelligenceIndex: builtinIntelligenceIndex(p.id), conditions: taskHints.filter((h3) => h3.ids.includes(p.id)).map((h3) => ({ roles: h3.roles.filter((r) => Object.hasOwn(p.strengths, r)), keywords: h3.keywords, reason: h3.reason })).filter((h3) => h3.roles.length) }));
|
|
1505
|
+
var builtinPresetCatalog = validatePresetCatalog({ schemaVersion: 1, version: benchmarkCatalogVersion, reviewedOn: "2026-12-02", profiles: builtinCards });
|
|
1506
|
+
function comparePresetVersion(a, b) {
|
|
1507
|
+
const [ad, an] = a.split("."), [bd, bn] = b.split(".");
|
|
1508
|
+
return ad.localeCompare(bd) || Number(an) - Number(bn);
|
|
1509
|
+
}
|
|
1467
1510
|
|
|
1468
1511
|
// src/model-knowledge.mjs
|
|
1469
1512
|
var knowledgeReviewedOn = builtinPresetCatalog.reviewedOn;
|
|
@@ -1544,8 +1587,12 @@ function nodeRole(node = {}, task = "") {
|
|
|
1544
1587
|
}
|
|
1545
1588
|
function indexPresetCatalog(catalog) {
|
|
1546
1589
|
const known = /* @__PURE__ */ new Map();
|
|
1547
|
-
|
|
1590
|
+
const legacy = comparePresetVersion(catalog.version, benchmarkCatalogVersion) < 0;
|
|
1591
|
+
for (const card4 of catalog.profiles) {
|
|
1592
|
+
const inherited = legacy && !card4.intelligenceIndex && builtinIntelligenceIndex(card4.id);
|
|
1593
|
+
const profile3 = inherited ? { ...card4, intelligenceIndex: inherited } : card4;
|
|
1548
1594
|
for (const alias of [profile3.id, ...profile3.aliases]) known.set(alias.toLowerCase(), profile3);
|
|
1595
|
+
}
|
|
1549
1596
|
return { catalog, known };
|
|
1550
1597
|
}
|
|
1551
1598
|
var activeCatalog = indexPresetCatalog(builtinPresetCatalog);
|
|
@@ -1614,6 +1661,24 @@ function modelAdvice(routes = [], role = "planning", task = "") {
|
|
|
1614
1661
|
}
|
|
1615
1662
|
|
|
1616
1663
|
// src/role-routing.mjs
|
|
1664
|
+
function taskClauses(task) {
|
|
1665
|
+
const text = String(task || "").replace(/(?:\x60{3}[\s\S]*?(?:\x60{3}|$)|~{3}[\s\S]*?(?:~{3}|$))/g, " ").replace(/\x60[^\x60\n]*\x60|「[^」]*」|『[^』]*』|“[^”]*”|"[^"\n]*"|‘[^’]*’|'[^'\n]*'/g, " ");
|
|
1666
|
+
let reference = false;
|
|
1667
|
+
const sentences = [];
|
|
1668
|
+
for (const line2 of text.split(/\r?\n/)) {
|
|
1669
|
+
if (!line2.trim()) {
|
|
1670
|
+
reference = false;
|
|
1671
|
+
continue;
|
|
1672
|
+
}
|
|
1673
|
+
if (/^\s*(?:本次要求|我的要求|实际要求|现在请|本次请|my request\b|actual request\b)/iu.test(line2)) reference = false;
|
|
1674
|
+
const ref2 = line2.match(/(?:参考资料|示例|样例|资料|原文|引文|引用|文档片段|reference text|example)\s*(?:中写道|写道|如下|说明)?\s*[::]/iu);
|
|
1675
|
+
const own = reference ? "" : ref2 ? line2.slice(0, ref2.index) : line2;
|
|
1676
|
+
if (ref2) reference = true;
|
|
1677
|
+
if (!own || /^\s*>/.test(own)) continue;
|
|
1678
|
+
sentences.push(...own.match(/[^。;;!??!]+[。;;!??!]?/gu) || []);
|
|
1679
|
+
}
|
|
1680
|
+
return sentences;
|
|
1681
|
+
}
|
|
1617
1682
|
var difficultyLabels = { routine: "例行", standard: "常规", complex: "复杂" };
|
|
1618
1683
|
var workloadPreference = {
|
|
1619
1684
|
routine: { efficient: 2.6, balanced: 1.4, advanced: 0.2, frontier: 0 },
|
|
@@ -1645,6 +1710,17 @@ function routeSuitability(route, role, nodeOrTask = "", declaredDifficulty) {
|
|
|
1645
1710
|
const score = fit4.score > 0 ? fit4.score + (workloadPreference[difficulty][workload] ?? 0) : 0;
|
|
1646
1711
|
return { score, fit: fit4, difficulty, workload };
|
|
1647
1712
|
}
|
|
1713
|
+
function rankPlannerCandidates(candidates, task, preferredId) {
|
|
1714
|
+
const content = taskClauses(task).join("\n");
|
|
1715
|
+
const tiers = { frontier: 4, advanced: 3, balanced: 2, efficient: 1 };
|
|
1716
|
+
const candidatesByStrength = candidates.map((route) => {
|
|
1717
|
+
const fit4 = roleFit(route, "planning", content);
|
|
1718
|
+
return { route, fit: fit4, tier: tiers[fit4.profile?.workload] || 0, index: fit4.profile?.intelligenceIndex };
|
|
1719
|
+
}).sort((a, b) => b.tier - a.tier || b.fit.score - a.fit.score || Number(b.route.id === preferredId) - Number(a.route.id === preferredId));
|
|
1720
|
+
const measured = candidatesByStrength.filter((row) => row.index).sort((a, b) => b.index.score - a.index.score);
|
|
1721
|
+
let nextMeasured = 0;
|
|
1722
|
+
return candidatesByStrength.map((row) => row.index ? measured[nextMeasured++] : row);
|
|
1723
|
+
}
|
|
1648
1724
|
|
|
1649
1725
|
// ui/roles.mjs
|
|
1650
1726
|
var roleLabelFor = (role) => roleLabels[role] || role;
|
|
@@ -1751,7 +1827,7 @@ function recommendation(s, v) {
|
|
|
1751
1827
|
if (node) stats.set(r.id, routeEvidence(s.routeHistory || [], node, r.id, v.priceTable || []));
|
|
1752
1828
|
}
|
|
1753
1829
|
const assigned = node && (stats.get(node.routeId) || routeEvidence(s.routeHistory || [], node, node.routeId, v.priceTable || []));
|
|
1754
|
-
candidates.sort((a, b) => fits.get(b.id).score - fits.get(a.id).score || Number(b.id === assignedId) - Number(a.id === assignedId) || Number(!!stats.get(b.id)?.samples.length) - Number(!!stats.get(a.id)?.samples.length));
|
|
1830
|
+
const ordered = !node && role === "planning" ? rankPlannerCandidates(candidates, task, assignedId).map((row) => row.route) : candidates.sort((a, b) => fits.get(b.id).score - fits.get(a.id).score || Number(b.id === assignedId) - Number(a.id === assignedId) || Number(!!stats.get(b.id)?.samples.length) - Number(!!stats.get(a.id)?.samples.length));
|
|
1755
1831
|
const card4 = (r) => {
|
|
1756
1832
|
const isAssigned = r.id === assignedId, ev = stats.get(r.id), fit4 = fits.get(r.id).fit;
|
|
1757
1833
|
const limits = [r.window, r.contextWindow, r.deploymentWindow].filter((n) => n > 0);
|
|
@@ -1768,7 +1844,7 @@ function recommendation(s, v) {
|
|
|
1768
1844
|
return '<div class="recommend">' + actualAssignments(run, routes) + '<div class="bs-section-title" data-role-candidates><h2>模型与岗位匹配</h2></div>' + tabBar("recommend-target", "岗位与执行步骤", targets.map((t) => [t.value, t.label]), target, "recommendTarget") + tabPanel(
|
|
1769
1845
|
"recommend-target",
|
|
1770
1846
|
target,
|
|
1771
|
-
(node ? "<p>「" + esc(node.title) + "」需要" + esc(req.map(capName).join("、")) + (node.tools?.length ? "及工具 " + esc(node.tools.join("、")) : "") + "。现有选择 " + esc(current ? routeName(current) : node.routeId) + "," + esc(why || (candidates.some((r) => r.id === node.routeId) ? "可继续执行。" : "未勾选参与本次运行。")) + "</p><p>同类验收与耗时取自本会话已完成的同角色、同能力和同工具要求的节点。本节点总费用与等待时间未知。</p>" : role === "planning" ? "<p
|
|
1847
|
+
(node ? "<p>「" + esc(node.title) + "」需要" + esc(req.map(capName).join("、")) + (node.tools?.length ? "及工具 " + esc(node.tools.join("、")) : "") + "。现有选择 " + esc(current ? routeName(current) : node.routeId) + "," + esc(why || (candidates.some((r) => r.id === node.routeId) ? "可继续执行。" : "未勾选参与本次运行。")) + "</p><p>同类验收与耗时取自本会话已完成的同角色、同能力和同工具要求的节点。本节点总费用与等待时间未知。</p>" : role === "planning" ? "<p>统筹模型先分析任务,可以直接答复,也可以选择执行模型和步骤。</p>" : role === "prompting" ? "<p>需要单独起草工作提示词时,计划可增加一个提示词步骤,交付给依赖它的执行模型。</p>" : "") + '<div class="bs-section-title"><h2>本次可用候选 · ' + esc(roleLabelFor(role)) + "</h2><span>" + esc(count2) + "</span></div>" + (included.length === 1 && candidates.length === 1 ? '<p class="bodycopy">本次只选用了一个型号,符合能力要求的步骤可由它分次完成。</p>' : "") + (ordered.map(card4).join("") || "<p>本次选择中缺少符合条件的路由。可在输入框旁的「协作」调整参与模型。</p>") + (unselected.length ? '<details class="role-other"><summary>已配置但未参与 · ' + unselected.length + " 条路由</summary><p>" + esc(unselected.map(routeName).join("、")) + "</p></details>" : "") + optionalAdvice(routes, role, task, false)
|
|
1772
1848
|
) + "</div>";
|
|
1773
1849
|
}
|
|
1774
1850
|
function assignmentImpact(run, node, routes, routeId) {
|
|
@@ -2522,7 +2598,7 @@ function inspector(s, v) {
|
|
|
2522
2598
|
"交付物",
|
|
2523
2599
|
'<div class="deliverable">' + icon("file", 16) + "<span>" + esc(n.deliverable) + "</span></div>"
|
|
2524
2600
|
) + section("验收条件", txt(n.acceptance));
|
|
2525
|
-
if (!isPlan && !rollCall) {
|
|
2601
|
+
if (!isPlan && !rollCall && nodes.some((node) => node.id === plannerKey)) {
|
|
2526
2602
|
const deps = n.deps?.length ? n.deps : [plannerKey];
|
|
2527
2603
|
body += section(
|
|
2528
2604
|
"前置依赖",
|
|
@@ -6165,7 +6241,7 @@ function ChatReplies({ sessionId, turn, seq, useChat }) {
|
|
|
6165
6241
|
import_react2.default.Fragment,
|
|
6166
6242
|
null,
|
|
6167
6243
|
h("span", { ref: marker, hidden: true }),
|
|
6168
|
-
value?.kind === "roll-call" && value.
|
|
6244
|
+
value?.kind === "roll-call" && value.closing && (0, import_react_dom.createPortal)(h(Replies, { value }), target)
|
|
6169
6245
|
);
|
|
6170
6246
|
}
|
|
6171
6247
|
|
package/host/chat-replies.mjs
CHANGED
|
@@ -147,5 +147,5 @@ export function ChatReplies({sessionId, turn, seq, useChat}) {
|
|
|
147
147
|
setTarget(row || null)
|
|
148
148
|
}, [sessionId, nodeKey])
|
|
149
149
|
return h(React.Fragment, null, h('span',{ref:marker,hidden:true}),
|
|
150
|
-
value?.kind === 'roll-call' && value.
|
|
150
|
+
value?.kind === 'roll-call' && value.closing && createPortal(h(Replies,{value}),target))
|
|
151
151
|
}
|
package/host/index.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import { recommendationHistory } from '../src/recommendation.mjs'
|
|
|
11
11
|
import { discoverRoutes, executorFor, plannerFor } from './models.mjs'
|
|
12
12
|
import {choosePlanner} from '../src/role-routing.mjs'
|
|
13
13
|
import { createChildren } from './children.mjs'
|
|
14
|
-
import {sessionSelection} from './selection.mjs'
|
|
14
|
+
import {runReasoningLevels,sessionSelection} from './selection.mjs'
|
|
15
15
|
import {isRollCall,prepareRollCall,executeRollCall} from './roll-call.mjs'
|
|
16
16
|
import {RUN_RECORD as RECORD, completedText, delivered, transcriptReply} from './reply-view.mjs'
|
|
17
17
|
|
|
@@ -229,17 +229,18 @@ export async function installHost(ctx,config,api) {
|
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
const create=(session,p,native)=>presets.run(()=>createRun(session,p,native))
|
|
232
|
-
function rollCall(session,pref,promptId,
|
|
232
|
+
function rollCall(session,pref,promptId,options) {
|
|
233
233
|
let pending=pendingRollCalls.get(session)
|
|
234
234
|
if (!pending) { pending=new Map(); pendingRollCalls.set(session,pending) }
|
|
235
235
|
if (pending.has(promptId)) return pending.get(promptId)
|
|
236
236
|
const stored=Object.values(view.stateOf(session).runs).find(run=>run.sessionId===session.id && run.settings?.nativePromptId===promptId)
|
|
237
237
|
if (stored) return Promise.resolve(stored.runId)
|
|
238
|
-
const start=createRollCall(session,pref,promptId,
|
|
238
|
+
const start=createRollCall(session,pref,promptId,options).finally(()=>pending.delete(promptId))
|
|
239
239
|
pending.set(promptId,start)
|
|
240
240
|
return start
|
|
241
241
|
}
|
|
242
|
-
async function createRollCall(session,pref,promptId,
|
|
242
|
+
async function createRollCall(session,pref,promptId,options) {
|
|
243
|
+
const {signal}=options
|
|
243
244
|
const {routes}=await catalog()
|
|
244
245
|
await profileQueue
|
|
245
246
|
signal?.throwIfAborted()
|
|
@@ -249,7 +250,7 @@ export async function installHost(ctx,config,api) {
|
|
|
249
250
|
const nodes=participants.map((route,i)=>({id:'roll-call-'+(i+1),routeId:route.id,title:route.label || route.modelId || route.id,
|
|
250
251
|
deliverable:'点名回应 '+(i+1),acceptance:'从该型号的彩蛋选项中选一句。',final:true,optional:true}))
|
|
251
252
|
const engine=new RunEngine({runId,sessionId:session.id,task:'在嘛?',mode:'auto',routes:participants,allowedRouteIds,
|
|
252
|
-
settings:{...settings,nativePromptId:promptId,easterEgg:{replies,closing},reasoningLevels:pref
|
|
253
|
+
settings:{...settings,nativePromptId:promptId,easterEgg:{replies,closing},reasoningLevels:runReasoningLevels(participants,pref,options)},
|
|
253
254
|
...bind(session,runId)})
|
|
254
255
|
engines.set(runId,{session,engine}); active.set(session,runId)
|
|
255
256
|
nativeDeliveries.set(runId,0)
|
|
@@ -292,8 +293,7 @@ export async function installHost(ctx,config,api) {
|
|
|
292
293
|
const selectedMaterials=sources.slice()
|
|
293
294
|
if (native?.history) sources.push(native.history)
|
|
294
295
|
const runId = randomUUID()
|
|
295
|
-
const runSettings={...settings
|
|
296
|
-
.map(route=>[route.id,preference.reasoningLevels[route.id]])),
|
|
296
|
+
const runSettings={...settings,...(missing.length && {unavailableRouteIds:missing}),reasoningLevels:runReasoningLevels(allowed,preference,native?.selection),
|
|
297
297
|
...(native?{nativePromptId:native.promptId}:{}),
|
|
298
298
|
...(native?.materialSelectionId?{nativeMaterialSelectionId:native.materialSelectionId}:{})}
|
|
299
299
|
const engine = new RunEngine({runId,sessionId:session.id,task,routes,settings:runSettings,sources,plannerAssignment,
|
|
@@ -419,7 +419,7 @@ export async function installHost(ctx,config,api) {
|
|
|
419
419
|
let runId=snapshotList.find(r=>r.settings?.nativePromptId===promptId)?.runId, engine
|
|
420
420
|
let blockStarted=false
|
|
421
421
|
try{
|
|
422
|
-
if (!runId && egg) runId=await rollCall(session,pref,promptId,options
|
|
422
|
+
if (!runId && egg) runId=await rollCall(session,pref,promptId,options)
|
|
423
423
|
if (!runId) {
|
|
424
424
|
const currentIds=new Set(current.map(m=>m.id))
|
|
425
425
|
const historyText=options.messages.filter(m=>!currentIds.has(m.id) && (m.role==='assistant'||m.role==='user'&&m.source?.kind==='user'))
|
|
@@ -433,7 +433,8 @@ export async function installHost(ctx,config,api) {
|
|
|
433
433
|
const provider=(await catalog()).routes.find(r=>r.providerId===options.provider && r.modelId===options.model && selected.includes(r.id))
|
|
434
434
|
const materialIds=pref.materialIds
|
|
435
435
|
const created=await create(session,{task,routeIds:selected,preferredPlannerId:provider?.id,materialIds},
|
|
436
|
-
{history,promptId,
|
|
436
|
+
{history,promptId,selection:{provider:options.provider,model:options.model,reasoningEffort:options.reasoningEffort},
|
|
437
|
+
materialSelectionId:materialIds.length?room.materialSelection.id:null})
|
|
437
438
|
runId=created.runId
|
|
438
439
|
}
|
|
439
440
|
engine=obtain(session,runId)
|
package/host/models.mjs
CHANGED
|
@@ -86,11 +86,16 @@ export async function discoverRoutes(ctx) {
|
|
|
86
86
|
const efforts=info.reasoning?.efforts
|
|
87
87
|
const reasoningLevels=Array.isArray(efforts) ? identifiedRows(efforts).map(effort=>effort.id) : []
|
|
88
88
|
if (info.reasoning!=null && !reasoningLevels.length) reasoningUnavailable=true
|
|
89
|
+
// pi-ai can send disabled thinking on omission even when the profile only offers active levels.
|
|
90
|
+
// DSH orders the exact model's levels from least to greatest and owns any configured default.
|
|
91
|
+
const requiredEffort = configured.has(provider.id) && info.reasoning?.defaultEffort == null &&
|
|
92
|
+
!reasoningLevels.includes('off') ? reasoningLevels[0] : undefined
|
|
89
93
|
return {
|
|
90
94
|
id: routeKey(provider.id, model.id), providerId: provider.id, apiId: provider.id, apiLabel: displayName(provider),
|
|
91
95
|
modelId: model.id, label: displayName(model), enabled: true, capabilities, capabilitySource: modalities == null ? 'text-assumed' : 'catalog',
|
|
92
96
|
contextWindow: window,window,
|
|
93
97
|
...(reasoningLevels.length && {reasoningLevels}),
|
|
98
|
+
...(requiredEffort && {requiredReasoningEffort:requiredEffort}),
|
|
94
99
|
...(reasoningUnavailable && {reasoningUnavailable:true}),
|
|
95
100
|
maxOutput: positiveLimit(info.defaultMaxTokens) ?? positiveLimit(model.maxTokens), local: configured.get(provider.id)?.local===true, upstream: null,
|
|
96
101
|
}
|
|
@@ -124,24 +129,49 @@ export async function streamText(ctx, args, messages, desiredOutput, margin) {
|
|
|
124
129
|
const ceiling = args.reserveTokens ? await args.reserveTokens(inputEstimate,available) : args.maxAttemptTokens
|
|
125
130
|
const maxTokens = Math.floor(Math.min(available, ceiling == null ? Infinity : ceiling - inputEstimate))
|
|
126
131
|
if (maxTokens < 1) throw Object.assign(Error('该请求的输入估算已超出此次预算,请调整预算或缩短输入。'),{dispatched:false})
|
|
132
|
+
const idle = new AbortController()
|
|
133
|
+
const signal = AbortSignal.any([args.signal, idle.signal])
|
|
134
|
+
signal.throwIfAborted()
|
|
135
|
+
let onAbort, timer
|
|
136
|
+
const aborted = new Promise((_, reject) => {
|
|
137
|
+
onAbort = () => reject(signal.reason)
|
|
138
|
+
signal.addEventListener('abort', onAbort, {once:true})
|
|
139
|
+
})
|
|
140
|
+
const activity = () => {
|
|
141
|
+
clearTimeout(timer)
|
|
142
|
+
timer = setTimeout(() => idle.abort(Error('模型连接长时间未返回数据。')), 5 * 60_000).unref()
|
|
143
|
+
}
|
|
144
|
+
activity()
|
|
145
|
+
try {
|
|
146
|
+
const chunks = ctx.llm.stream({provider:args.route.providerId, model:args.route.modelId, system,
|
|
147
|
+
messages:user, ...(declared != null || Number.isFinite(ceiling) ? {maxTokens} : {}), signal, sessionId:args.sessionId,
|
|
148
|
+
...reasoningOptions(args)})
|
|
149
|
+
// Some adapters ignore abort and never settle their iterator. Free the slot independently.
|
|
150
|
+
return await Promise.race([collectText(chunks, signal, activity, args.report, maxTokens, inputEstimate), aborted])
|
|
151
|
+
} finally {
|
|
152
|
+
clearTimeout(timer)
|
|
153
|
+
signal.removeEventListener('abort', onAbort)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
async function collectText(chunks, signal, activity, report, maxTokens, inputEstimate) {
|
|
127
158
|
const blocks = new Map()
|
|
128
159
|
let usage = null, finish, observedOutput = false
|
|
129
|
-
const chunks = ctx.llm.stream({provider:args.route.providerId, model:args.route.modelId, system,
|
|
130
|
-
messages:user, ...(declared != null || Number.isFinite(ceiling) ? {maxTokens} : {}), signal:args.signal, sessionId:args.sessionId,
|
|
131
|
-
...reasoningOptions(args)})
|
|
132
160
|
for await (const chunk of chunks) {
|
|
133
|
-
|
|
161
|
+
signal.throwIfAborted()
|
|
162
|
+
activity()
|
|
134
163
|
if (chunk.type === 'usage') {
|
|
135
164
|
usage = receipt(chunk.usage)
|
|
136
|
-
await
|
|
165
|
+
await report({usage})
|
|
137
166
|
} else if (chunk.type === 'text-delta' || (chunk.type === 'block-end' && chunk.block.type === 'text')) {
|
|
138
|
-
if (!observedOutput) { observedOutput = true; await
|
|
167
|
+
if (!observedOutput) { observedOutput = true; await report({phase:'streaming'}) }
|
|
139
168
|
blocks.set(chunk.index, chunk.type === 'text-delta' ? (blocks.get(chunk.index) || '') + chunk.text : chunk.block.text)
|
|
140
169
|
} else if (chunk.type === 'finish') finish = chunk.reason
|
|
141
170
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
171
|
+
signal.throwIfAborted()
|
|
172
|
+
if (finish?.kind !== 'stop') {
|
|
173
|
+
const error = Error(finish?.failure?.message || '模型响应未完整结束(' + (finish?.kind || '连接中断') + ')')
|
|
174
|
+
if (finish?.kind === 'max-tokens') Object.assign(error,{finishKind:'max-tokens',maxTokens,inputEstimate})
|
|
145
175
|
error.usage = usage
|
|
146
176
|
error.retryAfterMs = finish?.failure?.providerRetryAfterMs
|
|
147
177
|
throw error
|
|
@@ -192,18 +222,22 @@ export function plannerFor(ctx, options = {}) {
|
|
|
192
222
|
const requestedOutput=args.planningOutputTokens || 4096
|
|
193
223
|
const outputReserve=Math.max(1,Math.min(requestedOutput,4096,Math.floor(window/2),
|
|
194
224
|
args.route.maxOutput || Infinity,args.route.outputLimit || Infinity))
|
|
225
|
+
const allowDirectAnswer = args.allowDirectAnswer === true && !options.materials?.length
|
|
195
226
|
const instruction = [
|
|
196
|
-
'你是 DSH
|
|
227
|
+
'你是 DSH 任务规划者。先判断完成用户任务所需的最少步骤和型号,只输出 JSON 对象。',
|
|
228
|
+
allowDirectAnswer
|
|
229
|
+
? '若你能直接用已给文本完成问答,无需工具、指定的其他负责人或独立复核,直接输出 {"answer":"完整答复"}。否则输出 {"rationale":"分工理由","nodes":[...]}。'
|
|
230
|
+
: '输出 {"rationale":"一句分工理由","nodes":[...]},等计划发布、确认后由执行节点工作。',
|
|
197
231
|
'每个节点包含 id,title,role,routeId,assignmentReason,difficulty,deps,sourceIds,requiredCapabilities,tools,deliverable,acceptance。由你为此步骤选择具体负责人,在 assignmentReason 中用一句话说明选择依据。使用目录中的实际路由 ID、唯一交付物、有效前置依赖。',
|
|
198
232
|
'逐节点评定 difficulty。routine 是边界明确、可按固定规则验收的工作,standard 是常规专业工作,complex 是需要多步判断、权衡约束或处理依赖风险的工作。同一计划可包含不同难度。为执行节点给出具体的 instructions。',
|
|
199
233
|
'在本次勾选的具体型号中,结合步骤本身、验收方式、实际能力与工具、型号卡的岗位依据和可选 workload 定位安排负责人。同一个 API 下的各型号各自独立,同一个型号也可承担多个步骤。资料未知的自定义型号仍可安排。不要按名称猜测能力、费用或速度。',
|
|
200
234
|
'需要起草提示词再交给其他模型时,用 role=prompting 的节点独立交付提示词;在 promptFor 数组写接收节点 ID,接收步骤把它列入 deps。若用户只索要提示词,直接以提示词作为交付。普通问答无需增加起草轮次。',
|
|
201
235
|
'根据本条任务、资料索引与本次参与型号,即席分析目标和依赖后设计分工。目录使用 profile 数字时,从 catalogProfiles 对应下标读取该型号的能力与工具。',
|
|
202
|
-
'
|
|
203
|
-
|
|
236
|
+
'勾选型号是可调用范围。简单任务至多安排一个工作节点;复杂任务可全程由最合适的一个型号完成。仅在分工对交付有帮助时调用其他型号。可在多个节点重复使用同一型号,用 deps 传递上一步成果。',
|
|
237
|
+
'统一交付由最后一个工作节点完成,仅在确需整合时安排合稿。用户要求分别交付时,把各独立终点标为 final:true。独立复核使用原文并声明 reviewOf。平替只列入 fallbackRouteIds,主选无法交付才调用。',
|
|
204
238
|
'资料索引仅供分配,切勿编造资料。每组资料至少有一个执行步骤负责;其后依赖该步骤的路由也须在同组可读范围。仅使用授权工具。请以用户的语言作答。'
|
|
205
239
|
].join('\n')
|
|
206
|
-
const request = {task:args.task,workMode:options.workMode || 'recommended',catalog,
|
|
240
|
+
const request = {task:args.task,workMode:options.workMode || 'recommended',allowDirectAnswer,catalog,
|
|
207
241
|
materials:args.sources,materialRouteGroups:(options.materials || []).map(source=>({
|
|
208
242
|
...(args.sources.some(s=>s.id===source.id)?{id:source.id}:{}),routeIds:args.routes.filter(r=>mayRead(source,r)).map(r=>r.id)
|
|
209
243
|
})), allowedTools:options.allowedTools || [],
|
|
@@ -250,6 +284,12 @@ export function plannerFor(ctx, options = {}) {
|
|
|
250
284
|
let plan
|
|
251
285
|
let invalid
|
|
252
286
|
try { plan = JSON.parse(result.text.replace(/^\s*```(?:json)?\s*|\s*```\s*$/gi,'')) } catch {plan={};invalid='规划回执不是有效 JSON'}
|
|
287
|
+
if (Object.hasOwn(plan ?? {}, 'answer')) {
|
|
288
|
+
if (allowDirectAnswer && plan.nodes === undefined && typeof plan.answer === 'string' && plan.answer.trim()) {
|
|
289
|
+
return {answer:plan.answer.trim(),usage:result.usage,context:packed.context}
|
|
290
|
+
}
|
|
291
|
+
invalid = '请使用本次允许的答复格式;分工计划须包含执行节点,不能同时给出 answer。'
|
|
292
|
+
}
|
|
253
293
|
if (Array.isArray(plan?.nodes)) {
|
|
254
294
|
const ids=new Set(catalog.map(r=>r.id))
|
|
255
295
|
for (const n of plan.nodes) {
|
package/host/reply-view.mjs
CHANGED
|
@@ -24,13 +24,16 @@ function matchingRollCall(run, markdown) {
|
|
|
24
24
|
const replies = rollCallReplies(run)
|
|
25
25
|
const closing = run.settings.easterEgg.closing
|
|
26
26
|
if (renderRollCall(run, replies) !== markdown) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
const legacy = rollCallReplies(run, true)
|
|
28
|
+
if (renderRollCall(run, legacy) !== markdown) {
|
|
29
|
+
// 0.2.2 and 0.2.3 included the account name in saved lines.
|
|
30
|
+
const older = legacy.map(({route, text}) => {
|
|
31
|
+
const provider = route.providerId || route.apiId
|
|
32
|
+
const name = route.modelId || route.label || route.id
|
|
33
|
+
return formatEggReply({modelId:provider ? provider + ' / ' + name : name}, text)
|
|
34
|
+
})
|
|
35
|
+
if (formatEggMessage(older, closing) !== markdown) return null
|
|
36
|
+
}
|
|
34
37
|
}
|
|
35
38
|
return {kind:'roll-call', markdown, participants:replies.map(({route, text}) => ({name:route.modelId || route.label || route.id, text})),
|
|
36
39
|
closing:closing.slice(2, -2)}
|
package/host/roll-call.mjs
CHANGED
|
@@ -74,45 +74,25 @@ export async function executeRollCall(ctx, args) {
|
|
|
74
74
|
{role:'system', content:'NOVA 彩蛋点名。用户问“在嘛?”。请从用户消息的 JSON 数组中任选一句作答。只返回从 1 开始的选项编号,或逐字返回所选原句。'},
|
|
75
75
|
{role:'user', content:JSON.stringify(reply.choices)},
|
|
76
76
|
]
|
|
77
|
-
|
|
78
|
-
const idle = new AbortController()
|
|
79
|
-
const signal = AbortSignal.any([args.signal, idle.signal])
|
|
80
|
-
signal.throwIfAborted()
|
|
81
|
-
let onAbort
|
|
82
|
-
const aborted = new Promise((_, reject) => {
|
|
83
|
-
onAbort = () => reject(signal.reason)
|
|
84
|
-
signal.addEventListener('abort', onAbort, {once:true})
|
|
85
|
-
})
|
|
86
|
-
let result
|
|
87
|
-
let timer
|
|
88
|
-
const onStreamActivity = () => {
|
|
89
|
-
clearTimeout(timer)
|
|
90
|
-
if (!signal.aborted) timer = setTimeout(() => idle.abort(Error('点名连接长时间未返回数据。')), 5 * 60_000).unref()
|
|
91
|
-
}
|
|
92
|
-
onStreamActivity()
|
|
93
|
-
try {
|
|
94
|
-
result = await Promise.race([streamText(ctx, {...args, signal, onStreamActivity}, messages), aborted])
|
|
95
|
-
} finally {
|
|
96
|
-
clearTimeout(timer)
|
|
97
|
-
signal.removeEventListener('abort', onAbort)
|
|
98
|
-
}
|
|
77
|
+
const result = await streamText(ctx, args, messages)
|
|
99
78
|
const chosen = selectedPhrase(result.text, reply.choices)
|
|
100
79
|
if (chosen === undefined) throw Object.assign(Error('该型号未返回有效的彩蛋选项。'), {usage:result.usage})
|
|
101
80
|
return {...result, text:chosen}
|
|
102
81
|
}
|
|
103
82
|
|
|
104
|
-
export function rollCallReplies(snapshot) {
|
|
83
|
+
export function rollCallReplies(snapshot, legacyPlaceholders=false) {
|
|
105
84
|
const {replies} = snapshot.settings.easterEgg
|
|
106
85
|
const directory = new Map(snapshot.routes.map(route => [route.id, route]))
|
|
107
86
|
const nodes = new Map(snapshot.nodes.map(node => [node.routeId, node]))
|
|
108
87
|
const artifacts = new Map(snapshot.artifacts.map(artifact => [artifact.id, artifact]))
|
|
109
|
-
return replies.
|
|
88
|
+
return replies.flatMap(({routeId, choices}) => {
|
|
110
89
|
const route = directory.get(routeId) || unavailableRoute(routeId)
|
|
111
90
|
const node = nodes.get(routeId)
|
|
112
91
|
const artifact = artifacts.get(node?.artifactId)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return {route, text}
|
|
92
|
+
if (artifact?.routeId === routeId && choices.includes(artifact.text)) return [{route, text:artifact.text}]
|
|
93
|
+
// Earlier releases wrote a row for every checkbox into the durable assistant message.
|
|
94
|
+
if (legacyPlaceholders) return [{route, text:route.enabled === false ? '(型号当前不可用)' : '(本次未回应)'}]
|
|
95
|
+
return []
|
|
116
96
|
})
|
|
117
97
|
}
|
|
118
98
|
|
package/host/selection.mjs
CHANGED
|
@@ -21,7 +21,19 @@ function reasoningSelection(patch, available, previous) {
|
|
|
21
21
|
|
|
22
22
|
export function reasoningOptions({route, settings}) {
|
|
23
23
|
const level = settings?.reasoningLevels?.[route.id]
|
|
24
|
-
|
|
24
|
+
const effort = route.reasoningLevels?.includes(level) ? level : route.requiredReasoningEffort
|
|
25
|
+
return effort && route.reasoningLevels?.includes(effort) ? {reasoningEffort:effort} : {}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function runReasoningLevels(routes, preference, native) {
|
|
29
|
+
const result = {}
|
|
30
|
+
for (const route of routes) {
|
|
31
|
+
const selected = preference.reasoningLevels?.[route.id]
|
|
32
|
+
if (route.reasoningLevels?.includes(selected)) result[route.id] = selected
|
|
33
|
+
else if (route.providerId === native?.provider && route.modelId === native?.model &&
|
|
34
|
+
route.reasoningLevels?.includes(native?.reasoningEffort)) result[route.id] = native.reasoningEffort
|
|
35
|
+
}
|
|
36
|
+
return result
|
|
25
37
|
}
|
|
26
38
|
|
|
27
39
|
export function sessionSelection(patch,available,previous) {
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-nova-lewis",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"lewisEnchantRelease": {
|
|
5
|
-
"version": "0.2.
|
|
5
|
+
"version": "0.2.5",
|
|
6
6
|
"notes": ""
|
|
7
7
|
},
|
|
8
8
|
"lewisEnchantReleaseEn": {
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.5",
|
|
10
10
|
"notes": ""
|
|
11
11
|
},
|
|
12
12
|
"type": "module",
|
package/src/engine-plan.mjs
CHANGED
|
@@ -79,44 +79,14 @@ export function normalizeNodes(plan, maxNodes = 100) {
|
|
|
79
79
|
return nodes
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
// A coordinator can describe the work without enumerating a large roster in its JSON.
|
|
83
|
-
// Give each remaining selected text route its own artifact and wire it into the existing final.
|
|
84
|
-
export function includeSelectedContributors(state, nodes) {
|
|
85
|
-
const final = nodes.find(node => node.final && !node.optional)
|
|
86
|
-
if (!final) return
|
|
87
|
-
const assigned = new Set(nodes.map(node => node.routeId))
|
|
88
|
-
const allowed = new Set(state.allowedRouteIds)
|
|
89
|
-
const ids = new Set(nodes.map(node => node.id))
|
|
90
|
-
const deliverables = new Set(nodes.map(node => node.deliverable.trim().normalize('NFKC').toLowerCase()))
|
|
91
|
-
const finalSources = state.sources.filter(source => final.sourceIds.includes(source.id))
|
|
92
|
-
const extra = []
|
|
93
|
-
let ordinal = 0
|
|
94
|
-
for (const route of state.routes) {
|
|
95
|
-
if (!allowed.has(route.id) || assigned.has(route.id) || route.enabled === false || !(route.capabilities ?? ['text']).includes('text')) continue
|
|
96
|
-
let id, deliverable
|
|
97
|
-
do {
|
|
98
|
-
ordinal++
|
|
99
|
-
id = 'contributor-' + ordinal
|
|
100
|
-
deliverable = '独立建议 ' + ordinal
|
|
101
|
-
} while (ids.has(id) || deliverables.has(deliverable))
|
|
102
|
-
extra.push({id, title:'独立建议 · '+(route.label || route.modelId || route.id), role:'contributor', routeId:route.id,
|
|
103
|
-
deliverable, acceptance:'就当前任务给出具体、可核查的建议。', optional:true,
|
|
104
|
-
instructions:'独立提出对当前任务有帮助的结论、依据或需要核实的问题,交给最终负责人参考。',
|
|
105
|
-
sourceIds:finalSources.filter(source => mayRead(source, route)).map(source => source.id),
|
|
106
|
-
assignment:{routeId:route.id, role:'contributor', source:'selection', reasons:['此型号已勾选参与,本次独立提供建议。'], evidence:[]}})
|
|
107
|
-
}
|
|
108
|
-
if (!extra.length) return
|
|
109
|
-
for (const contributor of normalizeNodes({nodes:extra}, extra.length)) {
|
|
110
|
-
nodes.push(contributor)
|
|
111
|
-
final.deps.push(contributor.id)
|
|
112
|
-
}
|
|
113
|
-
final.instructions = [final.instructions, '结合直接上游各型号的独立建议,核实后给出最终答复。'].filter(Boolean).join('\n')
|
|
114
|
-
}
|
|
115
|
-
|
|
116
82
|
export function positiveNumber(value) {
|
|
117
83
|
return Number.isSafeInteger(value) && value > 0 ? value : 0
|
|
118
84
|
}
|
|
119
85
|
|
|
86
|
+
export function mayModifyWorkspace(node) {
|
|
87
|
+
return Boolean(node.writePaths?.length || node.tools?.some(tool => ['write','edit','bash'].includes(tool)))
|
|
88
|
+
}
|
|
89
|
+
|
|
120
90
|
export function inheritedSources(state, node) {
|
|
121
91
|
const ids = new Set()
|
|
122
92
|
const seen = new Set()
|
package/src/engine.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { assignmentsHash, copy, descendants, incompatibility, inheritedSources, mayRead,
|
|
1
|
+
import { assignmentsHash, copy, descendants, incompatibility, inheritedSources, mayRead, mayModifyWorkspace,
|
|
2
2
|
normalizeNodes, positiveNumber, routeCatalog, strings, uid, writeConflict } from './engine-plan.mjs'
|
|
3
3
|
import { estimateInput } from './context.mjs'
|
|
4
4
|
import { assessReview, reviewDecisions } from './engine-review.mjs'
|
|
5
|
-
import {choosePlanner} from './role-routing.mjs'
|
|
5
|
+
import {choosePlanner, permitsDirectAnswer} from './role-routing.mjs'
|
|
6
6
|
import {nodeRole} from './model-knowledge.mjs'
|
|
7
7
|
|
|
8
8
|
export { normalizeNodes as validatePlan } from './engine-plan.mjs'
|
|
@@ -87,8 +87,7 @@ function beginAttempt(state, node, route, kind, reserved) {
|
|
|
87
87
|
|
|
88
88
|
function publish(state, plan, fromPlanner = false) {
|
|
89
89
|
if (plan?.validationError) throw Error(String(plan.validationError))
|
|
90
|
-
const limit = state.settings.easterEgg ? state.allowedRouteIds.length :
|
|
91
|
-
state.settings.includeAllParticipants ? 100 + state.allowedRouteIds.length : undefined
|
|
90
|
+
const limit = state.settings.easterEgg ? state.allowedRouteIds.length : 100 + state.allowedRouteIds.length
|
|
92
91
|
const nodes = normalizeNodes(plan, limit)
|
|
93
92
|
if (fromPlanner && nodes.length > 1) {
|
|
94
93
|
const byId = new Map(nodes.map(n => [n.id, n])), prerequisites = new Set()
|
|
@@ -100,8 +99,11 @@ function publish(state, plan, fromPlanner = false) {
|
|
|
100
99
|
const required = nodes.filter(node => !node.optional)
|
|
101
100
|
required.forEach(node => node.deps.forEach(include))
|
|
102
101
|
const terminals = required.filter(node => !prerequisites.has(node.id))
|
|
103
|
-
if (terminals.length
|
|
104
|
-
|
|
102
|
+
if (!terminals.length || (terminals.length > 1 && !terminals.every(n => n.final))) {
|
|
103
|
+
throw Error('统一交付须由最后一个工作或合稿节点覆盖所有必需成果;分别交付时须为每个独立终点声明 final:true。当前终点:' + terminals.map(n=>n.id).join('、'))
|
|
104
|
+
}
|
|
105
|
+
const finalIds = new Set(terminals.map(n => n.id))
|
|
106
|
+
nodes.forEach(n => { n.final = finalIds.has(n.id) })
|
|
105
107
|
}
|
|
106
108
|
for (const node of nodes) {
|
|
107
109
|
if (!state.routes.some(route => route.id === node.routeId)) throw Error(node.id + ' 指定了目录外路由:' + node.routeId)
|
|
@@ -112,7 +114,6 @@ function publish(state, plan, fromPlanner = false) {
|
|
|
112
114
|
if (!state.sources.some(source => source.id === id)) throw Error(node.id + ' 引用了不存在的资料:' + id)
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
|
-
if (fromPlanner && state.settings.includeAllParticipants) includeSelectedContributors(state, nodes)
|
|
116
117
|
state.nodes = nodes
|
|
117
118
|
state.planVersion += 1
|
|
118
119
|
state.assignmentsHash = assignmentsHash(state)
|
|
@@ -126,6 +127,26 @@ function checkpoint(result) {
|
|
|
126
127
|
if (result.accepted === false) throw Error(String(result.reason || '交付物未通过验收'))
|
|
127
128
|
}
|
|
128
129
|
|
|
130
|
+
function directAnswerText(result, permitted) {
|
|
131
|
+
if (result?.answer === undefined) return
|
|
132
|
+
if (!permitted || result.nodes !== undefined || result.validationError) throw Error('本次须先提交分工计划。')
|
|
133
|
+
checkpoint({text:result.answer})
|
|
134
|
+
return result.answer
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function publishDirectAnswer(state, attempt, text, hash) {
|
|
138
|
+
publish(state, {rationale:'统筹模型直接完成本次问答。', nodes:[{id:'answer',title:'统筹直接答复',role:'final',
|
|
139
|
+
routeId:attempt.routeId, final:true, sourceIds:state.sources.filter(s=>mayRead(s,attempt.route)).map(s=>s.id),
|
|
140
|
+
deliverable:'答复',acceptance:'完整回答本条问题。'}]}, true)
|
|
141
|
+
const answer = state.nodes[0]
|
|
142
|
+
Object.assign(answer, {attemptId:attempt.id, startedAt:attempt.startedAt, context:attempt.context})
|
|
143
|
+
Object.assign(attempt, {nodeId:answer.id, directAnswer:true, phase:'delivered'})
|
|
144
|
+
commitArtifact(state, answer, attempt, {text}, hash)
|
|
145
|
+
state.confirmedVersion = state.planVersion
|
|
146
|
+
state.confirmedHash = state.assignmentsHash
|
|
147
|
+
state.status = 'completed'
|
|
148
|
+
}
|
|
149
|
+
|
|
129
150
|
function missingInputs(state, node) {
|
|
130
151
|
const missing = []
|
|
131
152
|
for (const depId of node.deps) {
|
|
@@ -231,7 +252,7 @@ function recordUnsent(state, attempt, error) {
|
|
|
231
252
|
function largerPlanningOutput(state, attempt, error) {
|
|
232
253
|
if (error.finishKind !== 'max-tokens' || !positiveNumber(error.maxTokens) || !Number.isSafeInteger(error.inputEstimate)) return 0
|
|
233
254
|
const route = state.routes.find(r => r.id === attempt.routeId && r.enabled !== false)
|
|
234
|
-
const node = {id:'plan', routeId:attempt.routeId}
|
|
255
|
+
const node = {id:'plan', routeId:attempt.routeId, final:attempt.usesFinalReserve}
|
|
235
256
|
if (!route || limitReason(state,node).reason) return 0
|
|
236
257
|
const window = Math.min(...[route.contextWindow,route.window,route.deploymentWindow].filter(positiveNumber))
|
|
237
258
|
const available = state.maxTokens == null ? Infinity : remainingTokens(state,node) - error.inputEstimate
|
|
@@ -407,6 +428,9 @@ export class RunEngine {
|
|
|
407
428
|
|
|
408
429
|
async #runPlanner(planner) {
|
|
409
430
|
const initial = this.#state.plannerAssignment
|
|
431
|
+
// The planner receives a material index; only permitted conversation history is sent in full.
|
|
432
|
+
const allowDirectAnswer = this.#state.mode === 'auto' && this.#state.sources.every(s=>s.id===initial?.historySourceId) &&
|
|
433
|
+
permitsDirectAnswer(this.#state.task)
|
|
410
434
|
const initialPlannerId = this.#state.plannerRouteId
|
|
411
435
|
const plannerIds = [...new Set([initialPlannerId, ...(initial?.fallbackRouteIds || [])])]
|
|
412
436
|
let index = 0, correction = '', revising = false, planningOutputTokens = 4096, expanded = false
|
|
@@ -428,7 +452,11 @@ export class RunEngine {
|
|
|
428
452
|
}
|
|
429
453
|
const route = eligible.get(selected.id)
|
|
430
454
|
const node = {id:'plan', revision:1, routeId:route.id, outputReserve:planningOutputTokens}
|
|
431
|
-
|
|
455
|
+
let budget = limitReason(state, node)
|
|
456
|
+
if (budget.reason && allowDirectAnswer) {
|
|
457
|
+
node.final = true
|
|
458
|
+
budget = limitReason(state, node)
|
|
459
|
+
}
|
|
432
460
|
if (budget.reason) throw Error(budget.reason)
|
|
433
461
|
if (selected.retryAfter) return {type:'planning.waiting_for_provider',retryAfter:selected.retryAfter}
|
|
434
462
|
if (state.plannerRouteId !== route.id) {
|
|
@@ -440,6 +468,8 @@ export class RunEngine {
|
|
|
440
468
|
const attempt = beginAttempt(state,node,route,kind,budget.reserved)
|
|
441
469
|
attempt.plannedRouteId = initialPlannerId
|
|
442
470
|
attempt.planningOutputTokens = planningOutputTokens
|
|
471
|
+
if (allowDirectAnswer) attempt.allowDirectAnswer = true
|
|
472
|
+
if (node.final) attempt.usesFinalReserve = true
|
|
443
473
|
return {attemptId: attempt.id}
|
|
444
474
|
}).catch(async error => {
|
|
445
475
|
if (!this.#fault) await this.#change('planning.blocked', state => {
|
|
@@ -473,16 +503,19 @@ export class RunEngine {
|
|
|
473
503
|
}))
|
|
474
504
|
result = await planner({task: state.task, node: {id: 'plan', role: 'planner', title: '规划任务', sourceIds: [], deps: []},
|
|
475
505
|
route, routes: state.routes.filter(r => r.enabled !== false && state.allowedRouteIds.includes(r.id)), sources, settings: state.settings,
|
|
476
|
-
inputs: [], correction, planningOutputTokens, signal: controller.signal, attemptId: id, report: patch => this.#report(id, patch),
|
|
477
|
-
planningTokenBudget:state.maxTokens == null ? null : remainingTokens(state,{id:'plan'},id),
|
|
506
|
+
inputs: [], correction, allowDirectAnswer, planningOutputTokens, signal: controller.signal, attemptId: id, report: patch => this.#report(id, patch),
|
|
507
|
+
planningTokenBudget:state.maxTokens == null ? null : remainingTokens(state,{id:'plan',final:attempt.usesFinalReserve},id),
|
|
478
508
|
reserveTokens: (input, output) => this.#reserveTokens(id, input, output),
|
|
479
509
|
maxAttemptTokens: state.maxTokens == null ? null : attempt.reservedTokens,
|
|
480
510
|
runId: state.runId, sessionId: state.sessionId})
|
|
511
|
+
const answer = directAnswerText(result, allowDirectAnswer)
|
|
512
|
+
const answerHash = answer && await contentHash(answer)
|
|
481
513
|
await this.#change('plan.published', draft => {
|
|
482
514
|
const current = byAttempt(draft, id)
|
|
483
515
|
setReceipt(draft, current, result)
|
|
484
516
|
if (draft.status !== 'planning' || current.status !== 'running') return {attemptId: id, stale: true}
|
|
485
|
-
|
|
517
|
+
if (answerHash) publishDirectAnswer(draft, current, answer, answerHash)
|
|
518
|
+
else publish(draft, result, true)
|
|
486
519
|
Object.assign(current, {status: 'completed', endedAt: now()})
|
|
487
520
|
return {attemptId: id, planVersion: draft.planVersion}
|
|
488
521
|
})
|
|
@@ -586,7 +619,7 @@ export class RunEngine {
|
|
|
586
619
|
const event = await this.#change('attempt.budget_reserved', state => {
|
|
587
620
|
const attempt = byAttempt(state,id)
|
|
588
621
|
if (attempt?.status !== 'running') throw Object.assign(Error('此请求已结束'), {dispatched:false})
|
|
589
|
-
const node = attempt.nodeId === 'plan' ? {id:'plan',outputReserve:attempt.planningOutputTokens} : byNode(state,attempt.nodeId)
|
|
622
|
+
const node = attempt.nodeId === 'plan' ? {id:'plan',outputReserve:attempt.planningOutputTokens,final:attempt.usesFinalReserve} : byNode(state,attempt.nodeId)
|
|
590
623
|
// The host now has the actual assembled request, including the selected catalog and conversation history.
|
|
591
624
|
const ceiling = Math.min(input + output, node.tokenBudget || Infinity, remainingTokens(state,node,id))
|
|
592
625
|
if (ceiling <= input) throw Object.assign(Error('输入约 '+input+' Token,当前请求可用 '+Math.max(0,ceiling)+' Token,无法预留输出。'), {dispatched:false})
|
|
@@ -722,7 +755,9 @@ export class RunEngine {
|
|
|
722
755
|
current.reason = a.error
|
|
723
756
|
current.finishedAt = a.endedAt
|
|
724
757
|
if (problem.retryAfterMs) current.retryAfter = a.retryAfter = retryAfter(problem)
|
|
725
|
-
|
|
758
|
+
// A lost receipt cannot establish whether a write or shell command already took effect.
|
|
759
|
+
const canRepeat = problem.dispatched === false || !mayModifyWorkspace(current)
|
|
760
|
+
const candidate = canRepeat && availableFallback(state,current,a.routeId)
|
|
726
761
|
if (candidate && problem.retryable !== false && !controller.signal.aborted) {
|
|
727
762
|
Object.assign(current, {nextRouteId:candidate.id, retryAfter:candidate.retryAfter, switchReason:a.error, status:'pending', phase:'queued', reason:null})
|
|
728
763
|
}
|
|
@@ -837,7 +872,11 @@ export class RunEngine {
|
|
|
837
872
|
}
|
|
838
873
|
|
|
839
874
|
async reconcile(attemptId, outcome) {
|
|
840
|
-
const
|
|
875
|
+
const observed = byAttempt(this.#state,attemptId)
|
|
876
|
+
const answer = outcome?.status === 'completed' && observed?.nodeId === 'plan'
|
|
877
|
+
? directAnswerText(outcome.plan, observed.allowDirectAnswer === true) : undefined
|
|
878
|
+
const body = answer ?? outcome?.text
|
|
879
|
+
const hash = outcome?.status === 'completed' && typeof body === 'string' ? await contentHash(body) : null
|
|
841
880
|
await this.#change('attempt.reconciled', state => {
|
|
842
881
|
const attempt = byAttempt(state, attemptId)
|
|
843
882
|
if (!attempt || attempt.status !== 'unknown') throw Error('没有待核对的请求')
|
|
@@ -846,6 +885,7 @@ export class RunEngine {
|
|
|
846
885
|
setReceipt(state, attempt, outcome)
|
|
847
886
|
if (outcome.status === 'completed') {
|
|
848
887
|
if (node) { checkpoint(outcome); commitArtifact(state, node, attempt, outcome, hash) }
|
|
888
|
+
else if (answer) publishDirectAnswer(state, attempt, answer, hash)
|
|
849
889
|
else { if (!outcome.plan) throw Error('缺少已核实的计划'); publish(state, outcome.plan, true) }
|
|
850
890
|
attempt.status = 'completed'
|
|
851
891
|
} else {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Highest reported configuration for each matched model on the AA leaderboard, 2026-12-02.
|
|
2
|
+
// This reference does not change the user's configured reasoning effort.
|
|
3
|
+
export const intelligenceSource = {title:'Artificial Analysis · Intelligence Index',url:'https://artificialanalysis.ai/leaderboards/models'}
|
|
4
|
+
const scores = new Map([
|
|
5
|
+
['claude-fable-5-2', [65,'Max, Default Fallback']], ['gpt-6.2-astra', [62,'Max']],
|
|
6
|
+
['gemini-4-neon', [62,'Xhigh']], ['gemini-4-carbon', [60,'High']],
|
|
7
|
+
['claude-opus-5-5', [59,'Max, Default Fallback']], ['gpt-6.2-sol', [57,'Max']],
|
|
8
|
+
['claude-sonnet-5-5', [55,'Max, Default Fallback']], ['gemini-4-hydrogen', [54,'Xhigh']],
|
|
9
|
+
['gpt-6.1-terra', [51,'Max']], ['gemini-4-argon', [51,'High']], ['kimi-k3.1-pro', [47,'Kimi K3.1 Pro']],
|
|
10
|
+
['qwen4-max', [43,'Qwen4 Max']], ['claude-haiku-5-5', [37,'Max']], ['grok-4.7', [35,'Xhigh']],
|
|
11
|
+
['deepseek-flash', [32,'V4.1 Flash 1017 Max']], ['glm-5.3', [32,'Max']],
|
|
12
|
+
['MiniMax-M3.1-Flash', [29,'MiniMax-M3.1-Flash']], ['gpt-6-luna', [28,'Max']], ['glm-5.3-flash', [28,'Max']],
|
|
13
|
+
['mistral-large-4-0', [26,'High']], ['deepseek-v4-pro', [23,'V4 Pro 0813 Max']], ['MiniMax-M3', [19,'MiniMax-M3']],
|
|
14
|
+
])
|
|
15
|
+
|
|
16
|
+
export const benchmarkCatalogVersion = '2026-12-02.1'
|
|
17
|
+
export function builtinIntelligenceIndex(id) {
|
|
18
|
+
const result = scores.get(id)
|
|
19
|
+
if (result) return {score:result[0],configuration:result[1]}
|
|
20
|
+
}
|
package/src/model-knowledge.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {builtinPresetCatalog,validatePresetCatalog} from './preset-catalog.mjs'
|
|
1
|
+
import {builtinPresetCatalog,comparePresetVersion,validatePresetCatalog} from './preset-catalog.mjs'
|
|
2
|
+
import {benchmarkCatalogVersion,builtinIntelligenceIndex} from './knowledge-intelligence.mjs'
|
|
2
3
|
|
|
3
4
|
export let knowledgeReviewedOn=builtinPresetCatalog.reviewedOn
|
|
4
5
|
export let modelProfiles=builtinPresetCatalog.profiles
|
|
@@ -52,8 +53,13 @@ export function nodeRole(node={},task=''){
|
|
|
52
53
|
}
|
|
53
54
|
export function indexPresetCatalog(catalog) {
|
|
54
55
|
const known = new Map()
|
|
55
|
-
|
|
56
|
+
const legacy=comparePresetVersion(catalog.version,benchmarkCatalogVersion)<0
|
|
57
|
+
for(const card of catalog.profiles) {
|
|
58
|
+
// An already-applied older catalog predates AA scores. Keep its own roles and aliases.
|
|
59
|
+
const inherited=legacy && !card.intelligenceIndex && builtinIntelligenceIndex(card.id)
|
|
60
|
+
const profile=inherited?{...card,intelligenceIndex:inherited}:card
|
|
56
61
|
for(const alias of [profile.id,...profile.aliases])known.set(alias.toLowerCase(),profile)
|
|
62
|
+
}
|
|
57
63
|
return {catalog,known}
|
|
58
64
|
}
|
|
59
65
|
let activeCatalog=indexPresetCatalog(builtinPresetCatalog)
|
package/src/preset-catalog.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {coreProfiles} from './knowledge-core.mjs'
|
|
2
2
|
import {alternativeProfiles} from './knowledge-alternatives.mjs'
|
|
3
3
|
import {officialPresetChannel} from './preset-channel.mjs'
|
|
4
|
+
import {benchmarkCatalogVersion,builtinIntelligenceIndex} from './knowledge-intelligence.mjs'
|
|
4
5
|
|
|
5
6
|
export const presetFileLimit = 2 * 1024 * 1024
|
|
6
7
|
const roles = new Set(['planning','prompting','coding','review','research','analysis','writing','vision','final'])
|
|
@@ -49,6 +50,12 @@ function profile(value, ids) {
|
|
|
49
50
|
}
|
|
50
51
|
requireValue(value.existingOnly === undefined || typeof value.existingOnly === 'boolean','已有部署标记无效。')
|
|
51
52
|
requireValue(value.workload === undefined || ['efficient','balanced','advanced','frontier'].includes(value.workload),id+' 的任务难度定位无效。')
|
|
53
|
+
let intelligenceIndex
|
|
54
|
+
if (value.intelligenceIndex !== undefined) {
|
|
55
|
+
const score=value.intelligenceIndex?.score
|
|
56
|
+
requireValue(Number.isFinite(score) && score>=0 && score<=100,id+' 的 AA Intelligence Index 分数无效。')
|
|
57
|
+
intelligenceIndex={score,configuration:string(value.intelligenceIndex.configuration,'AA 评测配置',200)}
|
|
58
|
+
}
|
|
52
59
|
const conditions = list(value.conditions ?? [],24,'岗位条件',0).map(c=>{
|
|
53
60
|
const roleSet = list(c?.roles,roles.size,'条件岗位')
|
|
54
61
|
requireValue(roleSet.every(r=>Object.hasOwn(strengths,r)),id+' 的条件引用了未收录的岗位。')
|
|
@@ -56,7 +63,7 @@ function profile(value, ids) {
|
|
|
56
63
|
})
|
|
57
64
|
return {id,label:string(value.label,'型号名称',180),vendor:string(value.vendor,'厂商',100),strengths,
|
|
58
65
|
limits:string(value.limits,'使用条件'),sources,aliases,...(value.existingOnly?{existingOnly:true}:{}),
|
|
59
|
-
...(value.workload?{workload:value.workload}:{}),...(conditions.length?{conditions}:{})}
|
|
66
|
+
...(value.workload?{workload:value.workload}:{}),...(intelligenceIndex && {intelligenceIndex}),...(conditions.length?{conditions}:{})}
|
|
60
67
|
}
|
|
61
68
|
export function validatePresetCatalog(data) {
|
|
62
69
|
requireValue(data?.schemaVersion === 1,'不支持的预设文件格式,请使用 schemaVersion 1。')
|
|
@@ -89,9 +96,9 @@ const workloadGroups={
|
|
|
89
96
|
frontier:['gpt-6.2-astra','claude-fable-5-2','claude-mythos-5-2','gemini-4-carbon','kimi-k3.1-pro','kimi-k3.1-pro-highspeed']
|
|
90
97
|
}
|
|
91
98
|
const workloads=new Map(Object.entries(workloadGroups).flatMap(([tier,ids])=>ids.map(id=>[id,tier])))
|
|
92
|
-
const builtinCards=[...coreProfiles,...alternativeProfiles].map(p=>({...p,workload:workloads.get(p.id),conditions:taskHints.filter(h=>h.ids.includes(p.id))
|
|
99
|
+
const builtinCards=[...coreProfiles,...alternativeProfiles].map(p=>({...p,workload:workloads.get(p.id),intelligenceIndex:builtinIntelligenceIndex(p.id),conditions:taskHints.filter(h=>h.ids.includes(p.id))
|
|
93
100
|
.map(h=>({roles:h.roles.filter(r=>Object.hasOwn(p.strengths,r)),keywords:h.keywords,reason:h.reason})).filter(h=>h.roles.length)}))
|
|
94
|
-
export const builtinPresetCatalog = validatePresetCatalog({schemaVersion:1,version:
|
|
101
|
+
export const builtinPresetCatalog = validatePresetCatalog({schemaVersion:1,version:benchmarkCatalogVersion,reviewedOn:'2026-12-02',profiles:builtinCards})
|
|
95
102
|
|
|
96
103
|
export function comparePresetVersion(a,b) {
|
|
97
104
|
const [ad,an] = a.split('.'), [bd,bn] = b.split('.')
|
package/src/role-routing.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {nodeRole, roleFit, taskRoles} from './model-knowledge.mjs'
|
|
2
|
-
import {incompatibility, mayRead} from './engine-plan.mjs'
|
|
2
|
+
import {incompatibility, mayRead, mayModifyWorkspace} from './engine-plan.mjs'
|
|
3
|
+
import {intelligenceSource} from './knowledge-intelligence.mjs'
|
|
3
4
|
|
|
4
5
|
const roleWords = {
|
|
5
6
|
planning:'统筹|规划|拆解', prompting:'提示词|提示语|prompts?', coding:'编码|编程|代码|写代码|代码实现|函数',
|
|
@@ -109,23 +110,44 @@ function choose(candidates,role,content,preferredId,difficulty) {
|
|
|
109
110
|
return {role,routeId:route.id,difficulty,...(workload && {workload}),source:'knowledge',reasons,evidence}
|
|
110
111
|
}
|
|
111
112
|
|
|
113
|
+
export function rankPlannerCandidates(candidates,task,preferredId) {
|
|
114
|
+
const content=taskClauses(task).join('\n')
|
|
115
|
+
const tiers={frontier:4,advanced:3,balanced:2,efficient:1}
|
|
116
|
+
const candidatesByStrength=candidates.map(route=>{
|
|
117
|
+
const fit=roleFit(route,'planning',content)
|
|
118
|
+
return {route,fit,tier:tiers[fit.profile?.workload] || 0,index:fit.profile?.intelligenceIndex}
|
|
119
|
+
}).sort((a,b)=>b.tier-a.tier || b.fit.score-a.fit.score || Number(b.route.id===preferredId)-Number(a.route.id===preferredId))
|
|
120
|
+
// Leave unmeasured models in their capability-based slots and order the measured ones by the same benchmark.
|
|
121
|
+
const measured=candidatesByStrength.filter(row=>row.index).sort((a,b)=>b.index.score-a.index.score)
|
|
122
|
+
let nextMeasured=0
|
|
123
|
+
return candidatesByStrength.map(row=>row.index?measured[nextMeasured++]:row)
|
|
124
|
+
}
|
|
125
|
+
|
|
112
126
|
export function choosePlanner(routes, task, {lockedId,preferredId,history} = {}) {
|
|
113
127
|
const candidates = routes.filter(r=>r.enabled !== false && (r.capabilities || ['text']).includes('text') && (!history || mayRead(history,r)))
|
|
114
128
|
const {owner,denied}=namedAssignments(routes,'planning',task)
|
|
115
|
-
const
|
|
129
|
+
const difficulty=difficultyFor(taskClauses(task).join('\n'))
|
|
116
130
|
lockedId ||= owner
|
|
117
131
|
if (lockedId) {
|
|
118
132
|
if (!candidates.some(r=>r.id===lockedId)) throw Error('显式指定的统筹路由未获准、不可读取所需前文或缺少文本能力。')
|
|
119
133
|
return {role:'planning',routeId:lockedId,difficulty,source:'manual',reasons:['用户指定了本次统筹模型。'],evidence:[],
|
|
120
134
|
...(history?.id && {historySourceId:history.id})}
|
|
121
135
|
}
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
136
|
+
const ordered=rankPlannerCandidates(candidates.filter(r=>!denied.has(r.id)),task,preferredId)
|
|
137
|
+
if (!ordered.length) return null
|
|
138
|
+
const [{route,fit,index},...backups]=ordered
|
|
139
|
+
const workload=fit.profile?.workload
|
|
140
|
+
const reasons=[...fit.reasons], evidence=[...fit.evidence]
|
|
141
|
+
if (index) {
|
|
142
|
+
reasons.unshift('该型号在 AA Intelligence Index 的参考分为 '+index.score+'('+index.configuration+')。')
|
|
143
|
+
evidence.unshift(intelligenceSource)
|
|
144
|
+
} else if (workload) {
|
|
145
|
+
reasons.unshift('型号资料中的能力定位为'+workloadLabels[workload]+'。')
|
|
146
|
+
if (!evidence.length) evidence.push(...fit.profile.sources)
|
|
127
147
|
}
|
|
128
|
-
|
|
148
|
+
if (!reasons.length) reasons.push('缺少可比较的型号资料,沿用已选路由中的首选或目录顺序。')
|
|
149
|
+
return {role:'planning',routeId:route.id,difficulty,source:evidence.length?'knowledge':'fallback',reasons,evidence,
|
|
150
|
+
...(workload && {workload}),fallbackRouteIds:backups.map(row=>row.route.id),...(history?.id && {historySourceId:history.id})}
|
|
129
151
|
}
|
|
130
152
|
|
|
131
153
|
export function planningCards(routes,task) {
|
|
@@ -161,6 +183,13 @@ function requestedHandoff(task) {
|
|
|
161
183
|
!/(?:不要|无需|不必|不需要|别).{0,8}(?:实现|执行|编写|生成|运行)/u.test(next)
|
|
162
184
|
})
|
|
163
185
|
}
|
|
186
|
+
|
|
187
|
+
// Explicit delegation belongs in the graph so the host can validate its owners and dependencies.
|
|
188
|
+
export function permitsDirectAnswer(task) {
|
|
189
|
+
return !intentClauses(task).some(clause =>
|
|
190
|
+
/负责|担任|交给|交由|分给|分别|各自|各给|各写|各答|每个模型|所有模型|全体模型|指派|委托|承担|\b(?:delegate|assign|independently|each model|all models)\b/iu.test(clause)) && !requestedHandoff(task)
|
|
191
|
+
}
|
|
192
|
+
|
|
164
193
|
const instructionFor = {
|
|
165
194
|
prompting:'为接收节点起草可直接执行的工作提示词。写清目标、输入引用、限制、交付格式和验收标准。',
|
|
166
195
|
coding:'按验收条件交付实现、可运行的最小用例及预期结果。有工具回执时分别列出实测结果。',
|
|
@@ -239,10 +268,12 @@ export function assignGeneratedPlan(nodes, routes, task, sources, options={}) {
|
|
|
239
268
|
}
|
|
240
269
|
nodes[i].routeId=pick.routeId
|
|
241
270
|
nodes[i].difficulty=difficulty
|
|
242
|
-
if (nodes[i].fallbackRouteIds) {
|
|
271
|
+
if (nodes[i].fallbackRouteIds?.length) {
|
|
243
272
|
nodes[i].fallbackRouteIds=nodes[i].fallbackRouteIds.filter(id=>!denied.has(id) && (!lock || id===lock) && id!==pick.routeId)
|
|
244
|
-
} else if (!options.offline && !options.single && !lock && !n
|
|
273
|
+
} else if (!options.offline && !options.single && !lock && !mayModifyWorkspace(n)) {
|
|
245
274
|
const compatible=routes.filter(r=>r.id!==pick.routeId && !denied.has(r.id) && !incompatibility(state,n,r.id))
|
|
275
|
+
.map(route=>({id:route.id,score:routeSuitability(route,role,content,difficulty).score}))
|
|
276
|
+
.sort((a,b)=>b.score-a.score)
|
|
246
277
|
if (compatible.length) {
|
|
247
278
|
nodes[i].fallbackRouteIds=compatible.map(r=>r.id)
|
|
248
279
|
pick.automaticFallbacks=true
|