dsh-nova-lewis 0.2.2 → 0.2.3
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 +40 -23
- package/host/children.mjs +8 -3
- package/host/client.mjs +16 -5
- package/host/composer.css +1 -0
- package/host/index.mjs +39 -25
- package/host/models.mjs +15 -10
- package/host/roll-call.mjs +45 -5
- package/package.json +3 -3
- package/src/context.mjs +15 -3
- package/src/engine-plan.mjs +34 -0
- package/src/engine.mjs +8 -5
package/README.cn.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
`dsh-nova-lewis` · v0.2.
|
|
1
|
+
`dsh-nova-lewis` · v0.2.3 · [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.3) | 简体中文
|
|
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.3 · [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.3/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
|
@@ -1616,7 +1616,7 @@ function assignmentFor(run, node, route, isPlanner) {
|
|
|
1616
1616
|
const actual = isPlanner ? run.plannerAssignment : node.assignment;
|
|
1617
1617
|
const role = isPlanner ? "planning" : taskRole(node, run.task);
|
|
1618
1618
|
if (actual?.routeId === node.routeId && actual.reasons?.length) {
|
|
1619
|
-
const source = { knowledge: "已发布计划的能力匹配依据", planner: "统筹模型分工", manual: "手动指定", fallback: "可用模型选择" }[actual.source] || "已发布的分配记录";
|
|
1619
|
+
const source = { knowledge: "已发布计划的能力匹配依据", planner: "统筹模型分工", manual: "手动指定", selection: "按本次勾选参与", fallback: "可用模型选择" }[actual.source] || "已发布的分配记录";
|
|
1620
1620
|
return { role, reasonTitle: source, reasons: actual.reasons, evidence: actual.evidence };
|
|
1621
1621
|
}
|
|
1622
1622
|
if (!route) return { role, reasonTitle: "", reasons: [], evidence: [] };
|
|
@@ -2381,12 +2381,13 @@ var defaultSettings = Object.freeze({
|
|
|
2381
2381
|
policy: "manual",
|
|
2382
2382
|
concurrency: 2,
|
|
2383
2383
|
perApiConcurrency: 2,
|
|
2384
|
-
maxRequests:
|
|
2385
|
-
maxTokens:
|
|
2384
|
+
maxRequests: null,
|
|
2385
|
+
maxTokens: null,
|
|
2386
2386
|
warnAt: 0.75,
|
|
2387
2387
|
compressAt: 0.9,
|
|
2388
2388
|
targetAt: 0.7
|
|
2389
2389
|
});
|
|
2390
|
+
var legacyDefaults = { ...defaultSettings, maxRequests: 60, maxTokens: 16e4 };
|
|
2390
2391
|
|
|
2391
2392
|
// src/engine-review.mjs
|
|
2392
2393
|
var reviewDecisions = {
|
|
@@ -2706,22 +2707,22 @@ function resources(s, v) {
|
|
|
2706
2707
|
return '<section class="bs-preferences settings-panel" data-page="routes"><div class="bs-toolbar"><h2>模型与分工</h2>' + iconButton("refreshRoutes", "刷新模型目录", "cache") + "</div>" + tabBar("route-pages", "模型资料与分工", tabs, v.routeTab, "routeTab") + tabPanel("route-pages", v.routeTab, v.routeTab === "recommend" ? recommendation(s, v) : '<div class="resource-list"><p class="bodycopy">在输入框旁的「协作」中勾选本次使用的型号' + (hasLevels ? ",再选择推理等级" : "") + "。</p>" + (list3 || '<p class="bodycopy">当前 DSH 目录没有可用模型。</p>') + "</div>") + "</section>";
|
|
2707
2708
|
}
|
|
2708
2709
|
var budgetFields = [
|
|
2709
|
-
["concurrency", "同时执行的节点数"
|
|
2710
|
-
["perApiConcurrency", "单个 API 并发数"
|
|
2711
|
-
["maxRequests", "每次运行请求上限"
|
|
2712
|
-
["maxTokens", "每次运行 Token 上限"
|
|
2713
|
-
["warnAt", "输入预算提醒阈值(%)",
|
|
2714
|
-
["compressAt", "压缩触发阈值(%)",
|
|
2715
|
-
["targetAt", "压缩目标(%)",
|
|
2710
|
+
["concurrency", "同时执行的节点数"],
|
|
2711
|
+
["perApiConcurrency", "单个 API 并发数"],
|
|
2712
|
+
["maxRequests", "每次运行请求上限"],
|
|
2713
|
+
["maxTokens", "每次运行 Token 上限"],
|
|
2714
|
+
["warnAt", "输入预算提醒阈值(%)", true],
|
|
2715
|
+
["compressAt", "压缩触发阈值(%)", true],
|
|
2716
|
+
["targetAt", "压缩目标(%)", true]
|
|
2716
2717
|
];
|
|
2717
2718
|
function settings(s, page = "policy") {
|
|
2718
2719
|
const cfg = s.settings || {}, overrides = s.settingsOverrides || s.settingOverrides || {}, budget = page === "budgets";
|
|
2719
|
-
const nf = ([name, label,
|
|
2720
|
+
const nf = ([name, label, pct]) => {
|
|
2720
2721
|
const fmt = (n) => pct ? Math.round(n * 1e4) / 100 : n;
|
|
2721
|
-
const stored = overrides[name], effective =
|
|
2722
|
-
return '<label class="field"><span>' + esc(label) + '</span><input type="number" name="' + name + '" min="' + (pct ? "0.01" : "1") + '" ' + (pct ? 'max="100" step="0.01"' : 'step="1"') + ' value="' + esc(stored == null ? "" : fmt(stored)) + '" placeholder="' + esc(effective) + '" aria-description="
|
|
2722
|
+
const stored = overrides[name], effective = defaultSettings[name];
|
|
2723
|
+
return '<label class="field"><span>' + esc(label) + '</span><input type="number" name="' + name + '" min="' + (pct ? "0.01" : "1") + '" ' + (pct ? 'max="100" step="0.01"' : 'step="1"') + ' value="' + esc(stored == null ? "" : fmt(stored)) + '" placeholder="' + esc(effective == null ? "不限" : fmt(effective)) + '" aria-description="留空使用默认设置"></label>';
|
|
2723
2724
|
};
|
|
2724
|
-
const body = budget ? '<p class="bodycopy"
|
|
2725
|
+
const body = budget ? '<p class="bodycopy">整场请求数与 Token 总额默认不限。每个型号使用自己的输出额度和上下文窗口。</p><div class="form-grid">' + budgetFields.map(nf).join("") + "</div>" : '<div class="field"><span>默认开工方式</span>' + choiceField("默认开工方式", "policy", cfg.policy === "auto" ? "auto" : "manual", POLICY_OPTIONS) + "</div>";
|
|
2725
2726
|
return '<form class="bs-preferences settings-panel" data-form="settings" data-page="' + page + '"><div class="bs-toolbar"><h2>' + (budget ? "上下文与预算" : "开工方式") + '</h2></div><div class="form-body">' + body + '<div class="form-end"><span class="muted">用于之后创建的任务。</span><button class="btn primary" type="submit">' + icon("check", 16) + "保存设置</button></div></div></form>";
|
|
2726
2727
|
}
|
|
2727
2728
|
|
|
@@ -3943,6 +3944,7 @@ function mountWorkbench(container, bridge, options = {}) {
|
|
|
3943
3944
|
payload = { planVersion: v.modal.planVersion };
|
|
3944
3945
|
for (const [key, val] of Object.entries(data)) {
|
|
3945
3946
|
if (val !== "") payload[key] = Number(val);
|
|
3947
|
+
else if (key === "maxRequests" || key === "maxTokens") payload[key] = null;
|
|
3946
3948
|
}
|
|
3947
3949
|
message = "预算已更新,请确认新版计划";
|
|
3948
3950
|
}
|
|
@@ -4823,7 +4825,7 @@ function preserveExactComposerText(conversation, sessions, collaborationEnabled)
|
|
|
4823
4825
|
}
|
|
4824
4826
|
|
|
4825
4827
|
// host/composer.css
|
|
4826
|
-
var composer_default = ".bs-studio.composer-menu {\n width:100%;\n max-width:none;\n container-type:inline-size;\n display:flex;\n flex-direction:column;\n max-height:var(--composer-max-height);\n padding:0;\n margin:0;\n box-sizing:border-box;\n}\n.composer-main {\n min-height:0;\n padding:12px min(5%,18px) 4px;\n overflow-y:auto;\n overflow-x:hidden;\n overscroll-behavior:contain;\n}\n.composer-menu fieldset { min-width:0; margin:0; padding:10px 0 6px; border:0; }\n.composer-menu legend {\n float:left;\n width:100%;\n padding:4px 4px 6px;\n color:var(--bs-muted);\n font-size:.88em;\n font-weight:600;\n overflow-wrap:anywhere;\n}\n.composer-menu .composer-model:first-of-type { clear:both; }\n.composer-menu .bs-field {\n display:grid;\n grid-template-columns:minmax(0,1fr) auto;\n gap:10px;\n align-items:center;\n padding:10px 4px;\n}\n.composer-menu .bs-field strong,.composer-menu .bs-field small,.composer-menu .bs-field > span:first-child {\n min-width:0;\n line-height:1.4;\n white-space:normal;\n overflow-wrap:anywhere;\n}\n.composer-menu .bs-toggle-row input { right:4px; }\n.composer-menu .bs-field .model-id { font-family:var(--dsw-font-mono,monospace); }\n.composer-menu .composer-reasoning { padding:0 4px 10px 12px; }\n.composer-menu .composer-reasoning > span:first-child { color:var(--bs-muted); }\n.composer-menu .composer-materials { border-top:1px solid var(--bs-border); margin-top:6px; padding:7px 0; }\n.composer-menu .composer-materials summary { cursor:pointer; display:list-item; list-style-position:inside; padding:8px 4px; }\n.composer-menu .composer-materials .bs-clip-actions { padding:4px 4px 7px; }\n.composer-menu .composer-actions {\n display:grid;\n flex:none;\n grid-template-columns:repeat(auto-fit,minmax(min(76px,100%),1fr));\n gap:6px;\n margin:0 min(5%,18px);\n padding:9px 0 12px;\n border-top:1px solid var(--bs-border);\n}\n.composer-menu .composer-actions button { min-width:0; padding:7px 5px; white-space:normal; overflow-wrap:anywhere; }\n.composer-menu p { margin:6px 4px; overflow-wrap:anywhere; }\n";
|
|
4828
|
+
var composer_default = ".bs-studio.composer-menu {\n width:100%;\n max-width:none;\n container-type:inline-size;\n display:flex;\n flex-direction:column;\n max-height:var(--composer-max-height);\n padding:0;\n margin:0;\n box-sizing:border-box;\n}\n.composer-main {\n min-height:0;\n padding:12px min(5%,18px) 4px;\n overflow-y:auto;\n overflow-x:hidden;\n overscroll-behavior:contain;\n}\n.composer-menu fieldset { min-width:0; margin:0; padding:10px 0 6px; border:0; }\n.composer-menu legend {\n float:left;\n width:100%;\n padding:4px 4px 6px;\n color:var(--bs-muted);\n font-size:.88em;\n font-weight:600;\n overflow-wrap:anywhere;\n}\n.composer-menu .composer-model:first-of-type { clear:both; }\n.composer-menu .bs-field {\n display:grid;\n grid-template-columns:minmax(0,1fr) auto;\n gap:10px;\n align-items:center;\n padding:10px 4px;\n}\n.composer-menu .bs-field strong,.composer-menu .bs-field small,.composer-menu .bs-field > span:first-child {\n min-width:0;\n line-height:1.4;\n white-space:normal;\n overflow-wrap:anywhere;\n}\n.composer-menu .bs-toggle-row input { right:4px; }\n.composer-menu .bs-field .model-id { font-family:var(--dsw-font-mono,monospace); }\n.composer-menu .composer-reasoning { padding:0 4px 10px 12px; }\n.composer-menu .composer-reasoning > span:first-child { color:var(--bs-muted); }\n.composer-menu .composer-roster { justify-content:space-between; align-items:center; flex-wrap:wrap; padding:4px; }\n.composer-menu .composer-materials { border-top:1px solid var(--bs-border); margin-top:6px; padding:7px 0; }\n.composer-menu .composer-materials summary { cursor:pointer; display:list-item; list-style-position:inside; padding:8px 4px; }\n.composer-menu .composer-materials .bs-clip-actions { padding:4px 4px 7px; }\n.composer-menu .composer-actions {\n display:grid;\n flex:none;\n grid-template-columns:repeat(auto-fit,minmax(min(76px,100%),1fr));\n gap:6px;\n margin:0 min(5%,18px);\n padding:9px 0 12px;\n border-top:1px solid var(--bs-border);\n}\n.composer-menu .composer-actions button { min-width:0; padding:7px 5px; white-space:normal; overflow-wrap:anywhere; }\n.composer-menu p { margin:6px 4px; overflow-wrap:anywhere; }\n";
|
|
4827
4829
|
|
|
4828
4830
|
// host/client.mjs
|
|
4829
4831
|
var h = import_react2.default.createElement;
|
|
@@ -5087,7 +5089,7 @@ function TabBody({ ctx, sessionId, defaultView, useTabInfo }) {
|
|
|
5087
5089
|
}
|
|
5088
5090
|
function Composer({ ctx, sessionId }) {
|
|
5089
5091
|
const [state, setState] = (0, import_react2.useState)(null), [opened, setOpened] = (0, import_react2.useState)(false), [reason, error] = (0, import_react2.useState)(""), [busy, pending] = (0, import_react2.useState)(false);
|
|
5090
|
-
const bridge = (0, import_react2.useRef)(null), button3 = (0, import_react2.useRef)(null), menu = (0, import_react2.useRef)(null), anchor = (0, import_react2.useRef)(null);
|
|
5092
|
+
const bridge = (0, import_react2.useRef)(null), refreshState = (0, import_react2.useRef)(null), button3 = (0, import_react2.useRef)(null), menu = (0, import_react2.useRef)(null), anchor = (0, import_react2.useRef)(null);
|
|
5091
5093
|
const [position, setPosition] = (0, import_react2.useState)(null);
|
|
5092
5094
|
const appearance = useEnchantAppearance();
|
|
5093
5095
|
(0, import_react2.useEffect)(() => {
|
|
@@ -5111,15 +5113,18 @@ function Composer({ ctx, sessionId }) {
|
|
|
5111
5113
|
shownPlans.set(sessionId, value.run.runId);
|
|
5112
5114
|
}
|
|
5113
5115
|
} catch (e) {
|
|
5114
|
-
if (live) error(e.message);
|
|
5116
|
+
if (live && n === seq) error(e.message);
|
|
5115
5117
|
}
|
|
5116
5118
|
};
|
|
5119
|
+
refreshState.current = refresh;
|
|
5117
5120
|
const off = b.subscribe(refresh);
|
|
5118
5121
|
void refresh();
|
|
5119
5122
|
return () => {
|
|
5120
5123
|
live = false;
|
|
5121
5124
|
off();
|
|
5122
5125
|
b.dispose();
|
|
5126
|
+
bridge.current = null;
|
|
5127
|
+
refreshState.current = null;
|
|
5123
5128
|
};
|
|
5124
5129
|
}, [ctx, sessionId]);
|
|
5125
5130
|
(0, import_react2.useEffect)(() => {
|
|
@@ -5172,6 +5177,9 @@ function Composer({ ctx, sessionId }) {
|
|
|
5172
5177
|
};
|
|
5173
5178
|
}, [opened]);
|
|
5174
5179
|
const pref = state?.composer || { enabled: false, routeIds: [] }, run = state?.run;
|
|
5180
|
+
const selectedIds = new Set(pref.routeIds);
|
|
5181
|
+
const availableIds = (state?.routes || []).map((route) => route.id);
|
|
5182
|
+
const availableSelected = availableIds.filter((routeId) => selectedIds.has(routeId)).length;
|
|
5175
5183
|
const materialIds = pref.materialIds || [];
|
|
5176
5184
|
const active = pref.enabled && pref.routeIds.length > 0;
|
|
5177
5185
|
function openView(view) {
|
|
@@ -5191,11 +5199,7 @@ function Composer({ ctx, sessionId }) {
|
|
|
5191
5199
|
pending(true);
|
|
5192
5200
|
try {
|
|
5193
5201
|
await connection.action(type, p);
|
|
5194
|
-
|
|
5195
|
-
if (connection === bridge.current) {
|
|
5196
|
-
setState(value);
|
|
5197
|
-
error("");
|
|
5198
|
-
}
|
|
5202
|
+
if (connection === bridge.current) await refreshState.current();
|
|
5199
5203
|
} catch (e) {
|
|
5200
5204
|
if (connection === bridge.current) error(e.message);
|
|
5201
5205
|
} finally {
|
|
@@ -5236,6 +5240,16 @@ function Composer({ ctx, sessionId }) {
|
|
|
5236
5240
|
onChange: (e) => change("composer", { enabled: e.target.checked, routeIds: pref.routeIds })
|
|
5237
5241
|
}), h("span", { className: "bs-switch", "aria-hidden": true })),
|
|
5238
5242
|
h(ComposerChoice, { label: "开工方式", options: POLICY_OPTIONS, value: pref.policy || "manual", disabled: busy || !state, onChange: (policy) => change("settings", { policy }) }),
|
|
5243
|
+
availableIds.length > 0 && h(
|
|
5244
|
+
"div",
|
|
5245
|
+
{ className: "bs-clip-actions composer-roster" },
|
|
5246
|
+
h("span", null, "已选 " + availableSelected + " / " + availableIds.length + " 个可用型号"),
|
|
5247
|
+
h("button", {
|
|
5248
|
+
type: "button",
|
|
5249
|
+
disabled: busy || availableSelected === availableIds.length,
|
|
5250
|
+
onClick: () => change("composer", { enabled: pref.enabled, routeIds: [.../* @__PURE__ */ new Set([...pref.routeIds, ...availableIds])] })
|
|
5251
|
+
}, "全选当前可用型号")
|
|
5252
|
+
),
|
|
5239
5253
|
...(state?.connections || []).map((group) => h(
|
|
5240
5254
|
"fieldset",
|
|
5241
5255
|
{ key: group.providerId },
|
|
@@ -5295,7 +5309,10 @@ function Composer({ ctx, sessionId }) {
|
|
|
5295
5309
|
title: reason || "本会话的协作开关、模型与进度",
|
|
5296
5310
|
"aria-expanded": opened,
|
|
5297
5311
|
"aria-haspopup": "dialog",
|
|
5298
|
-
onClick: () =>
|
|
5312
|
+
onClick: () => {
|
|
5313
|
+
setOpened(!opened);
|
|
5314
|
+
if (!opened && bridge.current) void change("refreshRoutes");
|
|
5315
|
+
}
|
|
5299
5316
|
}, "协作" + (hint ? " · " + hint : ""))
|
|
5300
5317
|
), pop);
|
|
5301
5318
|
}
|
package/host/children.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { mkdtemp, writeFile, rm } from 'node:fs/promises'
|
|
|
6
6
|
import { realpathSync, existsSync } from 'node:fs'
|
|
7
7
|
import { childReceipt, visibleText } from './models.mjs'
|
|
8
8
|
import {reasoningOptions} from './selection.mjs'
|
|
9
|
+
import {estimateInput,outputLimits} from '../src/context.mjs'
|
|
9
10
|
|
|
10
11
|
const preflightError = message => Object.assign(Error(message), {dispatched:false})
|
|
11
12
|
const shellName = process.platform === 'win32' ? 'powershell' : 'bash'
|
|
@@ -81,7 +82,7 @@ export function createChildren(ctx, config = {}) {
|
|
|
81
82
|
child.reports.catch(()=>{})
|
|
82
83
|
}
|
|
83
84
|
})
|
|
84
|
-
return async (args,messages)=>{
|
|
85
|
+
return async (args,messages,context)=>{
|
|
85
86
|
const tools = [...new Set(args.node.tools)].sort()
|
|
86
87
|
if (tools.some(t=>!['read','edit','write','search','bash'].includes(t))) throw preflightError('节点请求了未适配的工具。')
|
|
87
88
|
if (!get('subagents') || !get('agentPresets') || !get('tools')) throw preflightError('此 DSH profile 尚未启用原生子代理与工具。')
|
|
@@ -115,12 +116,16 @@ export function createChildren(ctx, config = {}) {
|
|
|
115
116
|
}
|
|
116
117
|
const child = {cwd,args,calls:0,spent:0,receipts:[],reports:Promise.resolve()}
|
|
117
118
|
children.set(childId,child)
|
|
118
|
-
const
|
|
119
|
+
const prompt = messages.map(m=>m.content).join('\n\n')+sourceIndex
|
|
120
|
+
const {declared, available} = outputLimits(args.route, (context?.estimated ?? estimateInput(prompt)) +
|
|
121
|
+
(context ? estimateInput(sourceIndex) : 0), args.node.outputReserve || args.settings?.outputReserve, context?.margin)
|
|
122
|
+
const maxTokens = args.maxAttemptTokens == null ? (declared == null ? undefined : available) :
|
|
123
|
+
Math.min(available, Math.max(1, Math.floor(args.maxAttemptTokens / 4)))
|
|
119
124
|
activation = await get('subagents').startActivation({provider:'spawn',agentPreset:presetId,label:args.node.title,parent,childId,cwd,
|
|
120
125
|
signal:args.signal,delivery:'caller',agentOptions:{provider:args.route.providerId,model:args.route.modelId,maxTokens,
|
|
121
126
|
// DSH merges same-route parent options into children. Clear any inherited effort when using the model default.
|
|
122
127
|
reasoningEffort:reasoningOptions(args).reasoningEffort},
|
|
123
|
-
prompt:[{type:'text',text:
|
|
128
|
+
prompt:[{type:'text',text:prompt}]})
|
|
124
129
|
cancel = ()=>{activation.dispose().catch(()=>{})}
|
|
125
130
|
args.signal.addEventListener('abort',cancel,{once:true})
|
|
126
131
|
if (args.signal.aborted) cancel()
|
package/host/client.mjs
CHANGED
|
@@ -189,7 +189,7 @@ function TabBody({ctx,sessionId,defaultView,useTabInfo}) {
|
|
|
189
189
|
}
|
|
190
190
|
function Composer({ctx,sessionId}){
|
|
191
191
|
const [state,setState]=useState(null),[opened,setOpened]=useState(false),[reason,error]=useState(''),[busy,pending]=useState(false)
|
|
192
|
-
const bridge=useRef(null),button=useRef(null),menu=useRef(null),anchor=useRef(null)
|
|
192
|
+
const bridge=useRef(null),refreshState=useRef(null),button=useRef(null),menu=useRef(null),anchor=useRef(null)
|
|
193
193
|
const [position,setPosition]=useState(null)
|
|
194
194
|
const appearance=useEnchantAppearance()
|
|
195
195
|
useEffect(()=>{
|
|
@@ -207,10 +207,11 @@ function Composer({ctx,sessionId}){
|
|
|
207
207
|
ctx.sidebarRight.openTab(id,{params:{view:'graph',runId:value.run.runId}})
|
|
208
208
|
shownPlans.set(sessionId,value.run.runId)
|
|
209
209
|
}
|
|
210
|
-
}catch(e){if(live)error(e.message)}
|
|
210
|
+
}catch(e){if(live && n===seq)error(e.message)}
|
|
211
211
|
}
|
|
212
|
+
refreshState.current=refresh
|
|
212
213
|
const off=b.subscribe(refresh);void refresh()
|
|
213
|
-
return ()=>{live=false;off();b.dispose()}
|
|
214
|
+
return ()=>{live=false;off();b.dispose();bridge.current=null;refreshState.current=null}
|
|
214
215
|
},[ctx,sessionId])
|
|
215
216
|
useEffect(()=>{
|
|
216
217
|
if(!opened)return
|
|
@@ -238,6 +239,9 @@ function Composer({ctx,sessionId}){
|
|
|
238
239
|
visual?.removeEventListener('resize',measure);visual?.removeEventListener('scroll',measure)}
|
|
239
240
|
},[opened])
|
|
240
241
|
const pref=state?.composer || {enabled:false,routeIds:[]}, run=state?.run
|
|
242
|
+
const selectedIds=new Set(pref.routeIds)
|
|
243
|
+
const availableIds=(state?.routes || []).map(route=>route.id)
|
|
244
|
+
const availableSelected=availableIds.filter(routeId=>selectedIds.has(routeId)).length
|
|
241
245
|
const materialIds=pref.materialIds || []
|
|
242
246
|
const active=pref.enabled && pref.routeIds.length>0
|
|
243
247
|
function openView(view){openSidebar(ctx,{view});setOpened(false)}
|
|
@@ -245,7 +249,7 @@ function Composer({ctx,sessionId}){
|
|
|
245
249
|
async function change(type,p){
|
|
246
250
|
const connection=bridge.current
|
|
247
251
|
pending(true)
|
|
248
|
-
try{await connection.action(type,p);
|
|
252
|
+
try{await connection.action(type,p);if(connection===bridge.current)await refreshState.current()}
|
|
249
253
|
catch(e){if(connection===bridge.current)error(e.message)}finally{if(connection===bridge.current)pending(false)}
|
|
250
254
|
}
|
|
251
255
|
const hint=run?.status==='awaiting_confirmation'?'待确认':run?.status==='planning'?'规划中':
|
|
@@ -266,6 +270,10 @@ function Composer({ctx,sessionId}){
|
|
|
266
270
|
h('label',{className:'bs-field bs-toggle-row'},h('span',null,'在本会话启用协作'),h('input',{type:'checkbox',checked:pref.enabled,disabled:busy,
|
|
267
271
|
onChange:e=>change('composer',{enabled:e.target.checked,routeIds:pref.routeIds})}),h('span',{className:'bs-switch','aria-hidden':true})),
|
|
268
272
|
h(ComposerChoice,{label:'开工方式',options:POLICY_OPTIONS,value:pref.policy || 'manual',disabled:busy||!state,onChange:policy=>change('settings',{policy})}),
|
|
273
|
+
availableIds.length>0 && h('div',{className:'bs-clip-actions composer-roster'},
|
|
274
|
+
h('span',null,'已选 '+availableSelected+' / '+availableIds.length+' 个可用型号'),
|
|
275
|
+
h('button',{type:'button',disabled:busy || availableSelected===availableIds.length,
|
|
276
|
+
onClick:()=>change('composer',{enabled:pref.enabled,routeIds:[...new Set([...pref.routeIds,...availableIds])]})},'全选当前可用型号')),
|
|
269
277
|
...(state?.connections || []).map(group=>h('fieldset',{key:group.providerId},
|
|
270
278
|
h('legend',{title:group.providerId},group.label+(group.label!==group.providerId && state.connections.filter(g=>g.label===group.label).length>1?' · '+group.providerId:'')),
|
|
271
279
|
...group.models.map(model=>h(Participant,{key:model.id,model,providerId:group.providerId,pref,busy,change})))),
|
|
@@ -289,7 +297,10 @@ function Composer({ctx,sessionId}){
|
|
|
289
297
|
h('button',{type:'button',onClick:()=>manage('settings')},'协作设置')))),document.body)
|
|
290
298
|
return h('span',{ref:anchor,style:{display:'inline-flex'},onClick:e=>e.stopPropagation()},h(SeriesSurface,null,
|
|
291
299
|
h('button',{ref:button,type:'button',className:'bs-primary',style:{padding:'3px 8px'},
|
|
292
|
-
title:reason || '本会话的协作开关、模型与进度','aria-expanded':opened,'aria-haspopup':'dialog',onClick:()=>
|
|
300
|
+
title:reason || '本会话的协作开关、模型与进度','aria-expanded':opened,'aria-haspopup':'dialog',onClick:()=>{
|
|
301
|
+
setOpened(!opened)
|
|
302
|
+
if (!opened && bridge.current) void change('refreshRoutes')
|
|
303
|
+
}},'协作'+(hint?' · '+hint:''))),pop)
|
|
293
304
|
}
|
|
294
305
|
export function apply(ctx){
|
|
295
306
|
ctx.inject?.(['conversation','sessions'],ready=>ready.effect(()=>preserveExactComposerText(ready.conversation,ready.sessions,async sessionId=>{
|
package/host/composer.css
CHANGED
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
.composer-menu .bs-field .model-id { font-family:var(--dsw-font-mono,monospace); }
|
|
45
45
|
.composer-menu .composer-reasoning { padding:0 4px 10px 12px; }
|
|
46
46
|
.composer-menu .composer-reasoning > span:first-child { color:var(--bs-muted); }
|
|
47
|
+
.composer-menu .composer-roster { justify-content:space-between; align-items:center; flex-wrap:wrap; padding:4px; }
|
|
47
48
|
.composer-menu .composer-materials { border-top:1px solid var(--bs-border); margin-top:6px; padding:7px 0; }
|
|
48
49
|
.composer-menu .composer-materials summary { cursor:pointer; display:list-item; list-style-position:inside; padding:8px 4px; }
|
|
49
50
|
.composer-menu .composer-materials .bs-clip-actions { padding:4px 4px 7px; }
|
package/host/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto'
|
|
2
|
+
import {isDeepStrictEqual} from 'node:util'
|
|
2
3
|
import { RunEngine } from '../src/engine.mjs'
|
|
3
4
|
import { mayRead } from '../src/engine-plan.mjs'
|
|
4
5
|
import { makeMaterial, patchSettings,settingsProfile } from '../src/context.mjs'
|
|
@@ -111,30 +112,38 @@ export async function installHost(ctx,config,api) {
|
|
|
111
112
|
const materialIds=room.materialSelection?.sessionId===sessionId ? room.materialSelection.ids : []
|
|
112
113
|
return {enabled:saved?.enabled===true,routeIds:saved?.routeIds || [],reasoningLevels:saved?.reasoningLevels || {},policy:readProfile().settings.policy,materialIds}
|
|
113
114
|
}
|
|
114
|
-
let epoch = 0, catalogPromise
|
|
115
|
+
let epoch = 0, catalogPromise, lastCatalog
|
|
115
116
|
function updated() { epoch++; for (const wake of [...observers.values()]) wake() }
|
|
116
|
-
function catalog() {
|
|
117
|
-
if (!
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
117
|
+
function catalog(force=false) {
|
|
118
|
+
if (catalogPromise && !force) return catalogPromise
|
|
119
|
+
const pending=Promise.resolve().then(()=>catalogPromise===pending ? discoverRoutes(ctx) : catalog()).then(async result=>{
|
|
120
|
+
if (catalogPromise !== pending) return catalog()
|
|
121
|
+
for (const route of result.routes) route.local ||= (config.localProviders || []).includes(route.providerId)
|
|
122
|
+
const previous=lastCatalog
|
|
123
|
+
lastCatalog=result
|
|
124
|
+
if (previous && !isDeepStrictEqual(previous,result)) {
|
|
125
|
+
if (!isDeepStrictEqual(previous.routes,result.routes)) {
|
|
126
|
+
const running=[...engines.values()].filter(({engine})=>!['completed','cancelled'].includes(engine.snapshot().status))
|
|
127
|
+
await Promise.allSettled(running.map(({engine})=>engine.updateRoutes(result.routes)))
|
|
128
|
+
}
|
|
129
|
+
updated()
|
|
130
|
+
}
|
|
131
|
+
return catalogPromise===pending ? result : catalog()
|
|
132
|
+
})
|
|
133
|
+
catalogPromise=pending
|
|
134
|
+
pending.catch(()=>{if (catalogPromise===pending) catalogPromise=null})
|
|
134
135
|
return pending
|
|
135
136
|
}
|
|
137
|
+
const refresh=()=>catalog(true)
|
|
136
138
|
ctx.on('llm/models-updated',refresh)
|
|
137
139
|
ctx.on('llm/adapters-updated',refresh)
|
|
140
|
+
// DSH can save the profile, its model list and its credential separately.
|
|
141
|
+
// Adapter registration alone does not announce all three changes.
|
|
142
|
+
ctx.on('settings/document-updated',ns=>{
|
|
143
|
+
if (ctx.llm.listConfigurableProviders?.().some(entry=>entry.settingsNs===ns)) return refresh()
|
|
144
|
+
})
|
|
145
|
+
ctx.on('credentials/record-updated',refresh)
|
|
146
|
+
ctx.on('credentials/reference-updated',refresh)
|
|
138
147
|
function bind(session,runId) {
|
|
139
148
|
let last = view.stateOf(session).runs[runId]
|
|
140
149
|
return {execute:args=>args.settings?.easterEgg ? executeRollCall(ctx,args) : execute(args),persist:async (snapshot,event)=>{
|
|
@@ -238,13 +247,12 @@ export async function installHost(ctx,config,api) {
|
|
|
238
247
|
await profileQueue
|
|
239
248
|
signal?.throwIfAborted()
|
|
240
249
|
const {participants,replies,closing}=prepareRollCall(pref,routes)
|
|
241
|
-
const {settings
|
|
250
|
+
const {settings}=readProfile()
|
|
242
251
|
const runId=randomUUID(), allowedRouteIds=participants.map(r=>r.id)
|
|
243
252
|
const nodes=participants.map((route,i)=>({id:'roll-call-'+(i+1),routeId:route.id,title:route.label || route.modelId || route.id,
|
|
244
|
-
deliverable:'点名回应 '+(i+1),acceptance:'从该型号的彩蛋选项中选一句。',
|
|
253
|
+
deliverable:'点名回应 '+(i+1),acceptance:'从该型号的彩蛋选项中选一句。',final:true,optional:true}))
|
|
245
254
|
const engine=new RunEngine({runId,sessionId:session.id,task:'在嘛?',mode:'auto',routes:participants,allowedRouteIds,
|
|
246
|
-
settings:{...settings
|
|
247
|
-
nativePromptId:promptId,easterEgg:{replies,closing},reasoningLevels:pref.reasoningLevels},
|
|
255
|
+
settings:{...settings,nativePromptId:promptId,easterEgg:{replies,closing},reasoningLevels:pref.reasoningLevels},
|
|
248
256
|
...bind(session,runId)})
|
|
249
257
|
engines.set(runId,{session,engine}); active.set(session,runId)
|
|
250
258
|
nativeDeliveries.set(runId,0)
|
|
@@ -287,7 +295,7 @@ export async function installHost(ctx,config,api) {
|
|
|
287
295
|
const selectedMaterials=sources.slice()
|
|
288
296
|
if (native?.history) sources.push(native.history)
|
|
289
297
|
const runId = randomUUID()
|
|
290
|
-
const runSettings={...settings,...(missing.length && {unavailableRouteIds:missing}),reasoningLevels:Object.fromEntries(allowed.filter(route=>route.reasoningLevels?.includes(preference.reasoningLevels[route.id]))
|
|
298
|
+
const runSettings={...settings,includeAllParticipants:p.mode!=='single',...(missing.length && {unavailableRouteIds:missing}),reasoningLevels:Object.fromEntries(allowed.filter(route=>route.reasoningLevels?.includes(preference.reasoningLevels[route.id]))
|
|
291
299
|
.map(route=>[route.id,preference.reasoningLevels[route.id]])),
|
|
292
300
|
...(native?{nativePromptId:native.promptId}:{}),
|
|
293
301
|
...(native?.materialSelectionId?{nativeMaterialSelectionId:native.materialSelectionId}:{})}
|
|
@@ -433,7 +441,13 @@ export async function installHost(ctx,config,api) {
|
|
|
433
441
|
const done=await waitForRun(engine,settled,options.signal)
|
|
434
442
|
const body=done.status==='completed' ? completedText(done) :
|
|
435
443
|
done.status==='cancelled'?'协作已取消。':'协作需要处理。'+(done.error || done.nodes.find(n=>n.reason)?.reason || '请打开任务图查看阻塞原因。')
|
|
436
|
-
|
|
444
|
+
// Limit individual transport frames while preserving one complete assistant message.
|
|
445
|
+
for (let offset=0;offset<body.length;) {
|
|
446
|
+
let end=Math.min(offset+16384,body.length)
|
|
447
|
+
if (end<body.length && body.charCodeAt(end-1)>=0xd800 && body.charCodeAt(end-1)<=0xdbff) end--
|
|
448
|
+
yield {type:'text-delta',index:0,text:body.slice(offset,end)}
|
|
449
|
+
offset=end
|
|
450
|
+
}
|
|
437
451
|
yield {type:'finish',reason:{kind:'stop'}}
|
|
438
452
|
}catch(error){
|
|
439
453
|
if (options.signal?.aborted) throw error
|
package/host/models.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assembleContext, estimateInput } from '../src/context.mjs'
|
|
1
|
+
import { assembleContext, estimateInput, outputLimits } from '../src/context.mjs'
|
|
2
2
|
import { normalizeUsage } from '../src/ledger.mjs'
|
|
3
3
|
import { mayRead } from '../src/engine-plan.mjs'
|
|
4
4
|
import { reviewInstruction,decodeReview } from '../src/engine-review.mjs'
|
|
@@ -114,22 +114,23 @@ export async function discoverRoutes(ctx) {
|
|
|
114
114
|
const receipt = raw => raw ? normalizeUsage(raw, 'dsh', {uncertainZeros:true}) : null
|
|
115
115
|
const visibleText = blocks => (blocks || []).filter(b => b.type === 'text').map(b => b.text).join('')
|
|
116
116
|
|
|
117
|
-
export async function streamText(ctx, args, messages, desiredOutput) {
|
|
117
|
+
export async function streamText(ctx, args, messages, desiredOutput, margin) {
|
|
118
118
|
const system = messages.filter(m => m.role === 'system').map(m => m.content).join('\n')
|
|
119
119
|
const user = messages.filter(m => m.role !== 'system').map(m => ({
|
|
120
120
|
role:'user', content:[{type:'text', text:m.content}]
|
|
121
121
|
}))
|
|
122
122
|
const inputEstimate = messages.reduce((s,m) => s + 4 + estimateInput(m.content), 2)
|
|
123
|
-
const
|
|
124
|
-
const ceiling = args.reserveTokens ? await args.reserveTokens(inputEstimate,
|
|
125
|
-
const maxTokens = Math.floor(Math.min(
|
|
123
|
+
const {declared, available} = outputLimits(args.route, inputEstimate, desiredOutput, margin)
|
|
124
|
+
const ceiling = args.reserveTokens ? await args.reserveTokens(inputEstimate,available) : args.maxAttemptTokens
|
|
125
|
+
const maxTokens = Math.floor(Math.min(available, ceiling == null ? Infinity : ceiling - inputEstimate))
|
|
126
126
|
if (maxTokens < 1) throw Object.assign(Error('该请求的输入估算已超出此次预算,请调整预算或缩短输入。'),{dispatched:false})
|
|
127
127
|
const blocks = new Map()
|
|
128
128
|
let usage = null, finish, observedOutput = false
|
|
129
129
|
const chunks = ctx.llm.stream({provider:args.route.providerId, model:args.route.modelId, system,
|
|
130
|
-
messages:user, maxTokens, signal:args.signal, sessionId:args.sessionId,
|
|
130
|
+
messages:user, ...(declared != null || Number.isFinite(ceiling) ? {maxTokens} : {}), signal:args.signal, sessionId:args.sessionId,
|
|
131
131
|
...reasoningOptions(args)})
|
|
132
132
|
for await (const chunk of chunks) {
|
|
133
|
+
args.onStreamActivity?.()
|
|
133
134
|
if (chunk.type === 'usage') {
|
|
134
135
|
usage = receipt(chunk.usage)
|
|
135
136
|
await args.report({usage})
|
|
@@ -188,16 +189,18 @@ export function plannerFor(ctx, options = {}) {
|
|
|
188
189
|
const catalog = planningCards(args.routes,args.task)
|
|
189
190
|
const windows=[args.route.window,args.route.contextWindow,args.route.deploymentWindow].filter(n=>n>0)
|
|
190
191
|
const window=Math.min(...windows)
|
|
191
|
-
const
|
|
192
|
+
const requestedOutput=args.planningOutputTokens || 4096
|
|
193
|
+
const outputReserve=Math.max(1,Math.min(requestedOutput,4096,Math.floor(window/2),
|
|
192
194
|
args.route.maxOutput || Infinity,args.route.outputLimit || Infinity))
|
|
193
195
|
const instruction = [
|
|
194
196
|
'你是 DSH 任务规划者。只输出 JSON 对象 {"rationale":"一句分工理由","nodes":[...]}。不要执行任务。',
|
|
195
197
|
'每个节点包含 id,title,role,routeId,assignmentReason,difficulty,deps,sourceIds,requiredCapabilities,tools,deliverable,acceptance。由你为此步骤选择具体负责人,在 assignmentReason 中用一句话说明选择依据。使用目录中的实际路由 ID、唯一交付物、有效前置依赖。',
|
|
196
198
|
'逐节点评定 difficulty。routine 是边界明确、可按固定规则验收的工作,standard 是常规专业工作,complex 是需要多步判断、权衡约束或处理依赖风险的工作。同一计划可包含不同难度。为执行节点给出具体的 instructions。',
|
|
197
|
-
'在本次勾选的具体型号中,结合步骤本身、验收方式、实际能力与工具、型号卡的岗位依据和可选 workload 定位安排负责人。同一个 API
|
|
199
|
+
'在本次勾选的具体型号中,结合步骤本身、验收方式、实际能力与工具、型号卡的岗位依据和可选 workload 定位安排负责人。同一个 API 下的各型号各自独立,同一个型号也可承担多个步骤。资料未知的自定义型号仍可安排。不要按名称猜测能力、费用或速度。',
|
|
198
200
|
'需要起草提示词再交给其他模型时,用 role=prompting 的节点独立交付提示词;在 promptFor 数组写接收节点 ID,接收步骤把它列入 deps。若用户只索要提示词,直接以提示词作为交付。普通问答无需增加起草轮次。',
|
|
199
201
|
'根据本条任务、资料索引与本次参与型号,即席分析目标和依赖后设计分工。目录使用 profile 数字时,从 catalogProfiles 对应下标读取该型号的能力与工具。',
|
|
200
202
|
'简单问答也由后续执行节点回答。统筹节点只画计划,不输出用户问题的答案。简单任务只用一个执行节点。多节点最后有 final 汇合所有必要成果;独立复核使用原文并声明 reviewOf。',
|
|
203
|
+
...(args.settings?.includeAllParticipants ? ['只列出完成任务所需的分工。其余已选型号由系统安排独立建议,并交给你的最终负责人。'] : []),
|
|
201
204
|
'资料索引仅供分配,切勿编造资料。每组资料至少有一个执行步骤负责;其后依赖该步骤的路由也须在同组可读范围。仅使用授权工具。请以用户的语言作答。'
|
|
202
205
|
].join('\n')
|
|
203
206
|
const request = {task:args.task,workMode:options.workMode || 'recommended',catalog,
|
|
@@ -242,7 +245,8 @@ export function plannerFor(ctx, options = {}) {
|
|
|
242
245
|
} catch (error) { if (!packed || !isContextOverflow(error)) throw error }
|
|
243
246
|
}
|
|
244
247
|
await args.report({context:packed.context,phase:'waiting'})
|
|
245
|
-
const
|
|
248
|
+
const generationLimit = requestedOutput > 4096 ? requestedOutput : packed.context.outputReserve
|
|
249
|
+
const result = await streamText(ctx,args,packed.messages,generationLimit,packed.context.margin)
|
|
246
250
|
let plan
|
|
247
251
|
let invalid
|
|
248
252
|
try { plan = JSON.parse(result.text.replace(/^\s*```(?:json)?\s*|\s*```\s*$/gi,'')) } catch {plan={};invalid='规划回执不是有效 JSON'}
|
|
@@ -292,7 +296,8 @@ export function executorFor(ctx, spawn) {
|
|
|
292
296
|
const {messages,context,evidence} = assembleContext({task:args.task,node,route:args.route,inputs:args.inputs,
|
|
293
297
|
materials:args.sources,settings:args.settings,tools:args.node.tools})
|
|
294
298
|
await args.report({context,phase:'waiting'})
|
|
295
|
-
const
|
|
299
|
+
const requestedOutput = node.outputReserve || args.settings?.outputReserve
|
|
300
|
+
const result = args.node.tools?.length ? await spawn(args,messages,context) : await streamText(ctx,args,messages,requestedOutput,context.margin)
|
|
296
301
|
return {...result,...decodeReview(result.text,node),context,evidence}
|
|
297
302
|
}
|
|
298
303
|
}
|
package/host/roll-call.mjs
CHANGED
|
@@ -34,6 +34,39 @@ export function prepareRollCall(pref, routes) {
|
|
|
34
34
|
return {participants, replies, closing:chooseNovaClosing()}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
+
function unpackAnswer(value) {
|
|
38
|
+
// Some adapters include reasoning in the visible text even when asked for a single option.
|
|
39
|
+
let answer = value.replace(/^\s*(?:<think>[\s\S]*?<\/think>\s*)+/i, '').trim()
|
|
40
|
+
const fence = answer.match(/^```(?:json|text)?\s*\n([\s\S]*?)\n?```$/i)
|
|
41
|
+
if (fence) answer = fence[1].trim()
|
|
42
|
+
try {
|
|
43
|
+
const parsed = JSON.parse(answer)
|
|
44
|
+
if (typeof parsed === 'string' || typeof parsed === 'number') return String(parsed)
|
|
45
|
+
if (parsed && typeof parsed === 'object' && Object.keys(parsed).length === 1 &&
|
|
46
|
+
['string','number'].includes(typeof parsed.choice)) return String(parsed.choice)
|
|
47
|
+
} catch { /* Plain text and unquoted workbook phrases are normal responses. */ }
|
|
48
|
+
return answer
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function unwrap(value) {
|
|
52
|
+
for (const [left, right] of [['"', '"'], ["'", "'"], ['“', '”'], ['「', '」'], ['**', '**'], ['`', '`']]) {
|
|
53
|
+
if (value.startsWith(left) && value.endsWith(right) && value.length >= left.length + right.length) {
|
|
54
|
+
return value.slice(left.length, -right.length).trim()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return value
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function selectedPhrase(text, choices) {
|
|
61
|
+
const plain = unwrap(unpackAnswer(text))
|
|
62
|
+
const answer = unwrap(plain.replace(/^(?:我(?:选择|选)|选项|编号|(?:I choose|option|choice)\b)\s*[::]?\s*/i, '').trim())
|
|
63
|
+
if (choices.includes(answer)) return answer
|
|
64
|
+
const selection = answer.match(/^([1-91-9][0-90-9]*)(?:\s*([.)::、.)\-])\s*(.*))?$/u)
|
|
65
|
+
if (!selection) return
|
|
66
|
+
const chosen = choices[Number(selection[1].normalize('NFKC')) - 1]
|
|
67
|
+
if (!selection[3] || unwrap(selection[3]) === chosen) return chosen
|
|
68
|
+
}
|
|
69
|
+
|
|
37
70
|
export async function executeRollCall(ctx, args) {
|
|
38
71
|
const reply = args.settings.easterEgg.replies.find(item => item.routeId === args.route.id)
|
|
39
72
|
if (!reply || args.route.id !== args.node.routeId) throw Object.assign(Error('未找到该型号的彩蛋候选。'), {dispatched:false})
|
|
@@ -41,8 +74,9 @@ export async function executeRollCall(ctx, args) {
|
|
|
41
74
|
{role:'system', content:'NOVA 彩蛋点名。用户问“在嘛?”。请从用户消息的 JSON 数组中任选一句作答。只返回从 1 开始的选项编号,或逐字返回所选原句。'},
|
|
42
75
|
{role:'user', content:JSON.stringify(reply.choices)},
|
|
43
76
|
]
|
|
44
|
-
//
|
|
45
|
-
const
|
|
77
|
+
// Reasoning and output both count as activity; only a silent provider should lose its slot.
|
|
78
|
+
const idle = new AbortController()
|
|
79
|
+
const signal = AbortSignal.any([args.signal, idle.signal])
|
|
46
80
|
signal.throwIfAborted()
|
|
47
81
|
let onAbort
|
|
48
82
|
const aborted = new Promise((_, reject) => {
|
|
@@ -50,13 +84,19 @@ export async function executeRollCall(ctx, args) {
|
|
|
50
84
|
signal.addEventListener('abort', onAbort, {once:true})
|
|
51
85
|
})
|
|
52
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()
|
|
53
93
|
try {
|
|
54
|
-
result = await Promise.race([streamText(ctx, {...args, signal}, messages
|
|
94
|
+
result = await Promise.race([streamText(ctx, {...args, signal, onStreamActivity}, messages), aborted])
|
|
55
95
|
} finally {
|
|
96
|
+
clearTimeout(timer)
|
|
56
97
|
signal.removeEventListener('abort', onAbort)
|
|
57
98
|
}
|
|
58
|
-
const
|
|
59
|
-
const chosen = /^[1-9]\d*$/.test(answer) ? reply.choices[Number(answer) - 1] : reply.choices.find(text => text === answer)
|
|
99
|
+
const chosen = selectedPhrase(result.text, reply.choices)
|
|
60
100
|
if (chosen === undefined) throw Object.assign(Error('该型号未返回有效的彩蛋选项。'), {usage:result.usage})
|
|
61
101
|
return {...result, text:chosen}
|
|
62
102
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-nova-lewis",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"lewisEnchantRelease": {
|
|
5
|
-
"version": "0.2.
|
|
5
|
+
"version": "0.2.3",
|
|
6
6
|
"notes": ""
|
|
7
7
|
},
|
|
8
8
|
"lewisEnchantReleaseEn": {
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.3",
|
|
10
10
|
"notes": ""
|
|
11
11
|
},
|
|
12
12
|
"type": "module",
|
package/src/context.mjs
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
const encoder = new TextEncoder()
|
|
2
2
|
export const defaultSettings = Object.freeze({
|
|
3
|
-
policy: 'manual', concurrency: 2, perApiConcurrency: 2, maxRequests:
|
|
4
|
-
maxTokens:
|
|
3
|
+
policy: 'manual', concurrency: 2, perApiConcurrency: 2, maxRequests: null,
|
|
4
|
+
maxTokens: null, warnAt: 0.75, compressAt: 0.9, targetAt: 0.7
|
|
5
5
|
})
|
|
6
|
+
const legacyDefaults = {...defaultSettings, maxRequests:60, maxTokens:160000}
|
|
6
7
|
|
|
7
8
|
export function validateSettings(settings) {
|
|
8
9
|
const result = {...defaultSettings}
|
|
9
10
|
for (const key of Object.keys(result)) if (Object.hasOwn(settings, key)) result[key] = settings[key]
|
|
10
11
|
if (!['manual', 'auto'].includes(result.policy)) throw new Error('请选择开工方式。')
|
|
11
12
|
for (const key of ['concurrency', 'perApiConcurrency', 'maxRequests', 'maxTokens']) {
|
|
13
|
+
if ((key === 'maxRequests' || key === 'maxTokens') && result[key] === null) continue
|
|
12
14
|
if (!Number.isSafeInteger(result[key]) || result[key] < 1) throw new Error('并发与预算必须为正整数。')
|
|
13
15
|
}
|
|
14
16
|
if (!(0 < result.targetAt && result.targetAt <= result.warnAt && result.warnAt < result.compressAt && result.compressAt <= 1)) throw new Error('压缩目标、提醒阈值和触发阈值须按从小到大设置。')
|
|
@@ -20,7 +22,7 @@ export function settingsProfile(profile = {}) {
|
|
|
20
22
|
if (!overrides) {
|
|
21
23
|
const previous=profile.settings || {}
|
|
22
24
|
overrides=Object.fromEntries(Object.keys(defaultSettings).filter(key=>Object.hasOwn(previous,key) &&
|
|
23
|
-
(key==='policy' || previous[key]!==
|
|
25
|
+
(key==='policy' || previous[key]!==legacyDefaults[key])).map(key=>[key,previous[key]]))
|
|
24
26
|
}
|
|
25
27
|
return patchSettings({policy:'manual'},overrides)
|
|
26
28
|
}
|
|
@@ -57,6 +59,16 @@ const ref = item => (item.id ?? item.nodeId) + '@v' + (item.version ?? 1)
|
|
|
57
59
|
const critical = /[\d%%¥¥$€]|不得|除外|除非|未|禁止|不|无需|例外|必须|仅限|except|unless|\b(?:no|not|never|must|error|failed)\b/i
|
|
58
60
|
const beforeDispatch = message => Object.assign(new Error(message), {dispatched:false})
|
|
59
61
|
|
|
62
|
+
// Input compression reserves a minimum space for generation. Once the input is
|
|
63
|
+
// packed, each model can use its own output allowance and the rest of its window.
|
|
64
|
+
export function outputLimits(route, input, requested, margin) {
|
|
65
|
+
const window = knownPositiveMin(route.window, route.contextWindow, route.deploymentWindow)
|
|
66
|
+
const declared = knownPositiveMin(requested, route.maxOutput, route.outputLimit)
|
|
67
|
+
const room = window == null ? Infinity : window - input - (margin ?? Math.ceil(window * 0.032))
|
|
68
|
+
if (room < 1) throw beforeDispatch('上下文超限:当前请求没有可用于输出的窗口。')
|
|
69
|
+
return {declared, available:Math.min(room, declared ?? Infinity)}
|
|
70
|
+
}
|
|
71
|
+
|
|
60
72
|
export function assembleContext({task, node, route, inputs = [], materials = [], settings = {}, system, tools = []}) {
|
|
61
73
|
const s = {...defaultSettings, ...settings}
|
|
62
74
|
const window = knownPositiveMin(route.window, route.contextWindow, route.deploymentWindow)
|
package/src/engine-plan.mjs
CHANGED
|
@@ -79,6 +79,40 @@ 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
|
+
|
|
82
116
|
export function positiveNumber(value) {
|
|
83
117
|
return Number.isSafeInteger(value) && value > 0 ? value : 0
|
|
84
118
|
}
|
package/src/engine.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assignmentsHash, copy, descendants, incompatibility, inheritedSources, mayRead,
|
|
1
|
+
import { assignmentsHash, copy, descendants, incompatibility, inheritedSources, mayRead, includeSelectedContributors,
|
|
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'
|
|
@@ -87,7 +87,9 @@ 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
|
|
90
|
+
const limit = state.settings.easterEgg ? state.allowedRouteIds.length :
|
|
91
|
+
state.settings.includeAllParticipants ? 100 + state.allowedRouteIds.length : undefined
|
|
92
|
+
const nodes = normalizeNodes(plan, limit)
|
|
91
93
|
if (fromPlanner && nodes.length > 1) {
|
|
92
94
|
const byId = new Map(nodes.map(n => [n.id, n])), prerequisites = new Set()
|
|
93
95
|
const include = id => {
|
|
@@ -110,6 +112,7 @@ function publish(state, plan, fromPlanner = false) {
|
|
|
110
112
|
if (!state.sources.some(source => source.id === id)) throw Error(node.id + ' 引用了不存在的资料:' + id)
|
|
111
113
|
}
|
|
112
114
|
}
|
|
115
|
+
if (fromPlanner && state.settings.includeAllParticipants) includeSelectedContributors(state, nodes)
|
|
113
116
|
state.nodes = nodes
|
|
114
117
|
state.planVersion += 1
|
|
115
118
|
state.assignmentsHash = assignmentsHash(state)
|
|
@@ -232,7 +235,8 @@ function largerPlanningOutput(state, attempt, error) {
|
|
|
232
235
|
if (!route || limitReason(state,node).reason) return 0
|
|
233
236
|
const window = Math.min(...[route.contextWindow,route.window,route.deploymentWindow].filter(positiveNumber))
|
|
234
237
|
const available = state.maxTokens == null ? Infinity : remainingTokens(state,node) - error.inputEstimate
|
|
235
|
-
const
|
|
238
|
+
const modelLimit = Math.min(route.maxOutput || Infinity, route.outputLimit || Infinity)
|
|
239
|
+
const limit = Math.min(Number.isFinite(modelLimit) ? modelLimit : error.maxTokens * 2,
|
|
236
240
|
window - (attempt.context?.margin || 0) - error.inputEstimate, available)
|
|
237
241
|
return limit > error.maxTokens ? Math.floor(limit) : 0
|
|
238
242
|
}
|
|
@@ -584,8 +588,7 @@ export class RunEngine {
|
|
|
584
588
|
if (attempt?.status !== 'running') throw Object.assign(Error('此请求已结束'), {dispatched:false})
|
|
585
589
|
const node = attempt.nodeId === 'plan' ? {id:'plan',outputReserve:attempt.planningOutputTokens} : byNode(state,attempt.nodeId)
|
|
586
590
|
// The host now has the actual assembled request, including the selected catalog and conversation history.
|
|
587
|
-
const
|
|
588
|
-
const ceiling = Math.min(input + output, desired, node.tokenBudget || Infinity, remainingTokens(state,node,id))
|
|
591
|
+
const ceiling = Math.min(input + output, node.tokenBudget || Infinity, remainingTokens(state,node,id))
|
|
589
592
|
if (ceiling <= input) throw Object.assign(Error('输入约 '+input+' Token,当前请求可用 '+Math.max(0,ceiling)+' Token,无法预留输出。'), {dispatched:false})
|
|
590
593
|
attempt.reservedTokens = ceiling
|
|
591
594
|
return {attemptId:id, reservedTokens:ceiling}
|