dsh-nova-lewis 0.2.1 → 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 +90 -27
- package/host/children.mjs +8 -3
- package/host/client.mjs +23 -5
- package/host/composer.css +1 -0
- package/host/exact-composer-text.mjs +31 -0
- package/host/index.mjs +107 -54
- package/host/models.mjs +15 -10
- package/host/plan-view.mjs +0 -17
- package/host/roll-call.mjs +118 -0
- package/package.json +5 -5
- package/src/context.mjs +15 -3
- package/src/easter-egg.mjs +86 -0
- package/src/engine-plan.mjs +37 -3
- package/src/engine.mjs +11 -7
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: [] };
|
|
@@ -2127,7 +2127,7 @@ function updateView(update, { locale = "zh-CN", nativeManager = false } = {}) {
|
|
|
2127
2127
|
const available = update.kind === "available";
|
|
2128
2128
|
const published = available && (update.channel === "npm" || update.channel === "official");
|
|
2129
2129
|
const actions = available ? button2("close", "稍后再说") + (published ? button2("release", nativeManager ? "打开插件管理" : "查看 npm 包", { css: primary }) : button2("install", "更新到 " + esc(update.latestVersion), { css: primary, disabled: true, extra: ' title="当前本地示例仅支持检查更新"' })) : button2("close", preview ? "关闭预览" : "知道了", { css: primary });
|
|
2130
|
-
return '<div class="bs-startup-update-card">' + closeButton("关闭更新提示") + '<div class="bs-startup-update-glyph" aria-hidden="true">' + (current ? "✓" : failed ? "!" : "✧") + '</div><p class="bs-startup-update-brand">' + brand + (preview ? "<span> · 更新提醒外观预览</span>" : "") + '</p><h2 id="bs-startup-update-title">' + title + '</h2><p id="bs-startup-update-description" class="bs-startup-update-copy">' + esc(description) + "</p>" + (failed || unpublished ? "" : versions(update, current)) + (failed || unpublished || current ? "" : '<div class="bs-release-notes" aria-label="本次更新"><h3>本次更新</h3>' + (notes
|
|
2130
|
+
return '<div class="bs-startup-update-card">' + closeButton("关闭更新提示") + '<div class="bs-startup-update-glyph" aria-hidden="true">' + (current ? "✓" : failed ? "!" : "✧") + '</div><p class="bs-startup-update-brand">' + brand + (preview ? "<span> · 更新提醒外观预览</span>" : "") + '</p><h2 id="bs-startup-update-title">' + title + '</h2><p id="bs-startup-update-description" class="bs-startup-update-copy">' + esc(description) + "</p>" + (failed || unpublished ? "" : versions(update, current)) + (failed || unpublished || current || !notes && !preview ? "" : '<div class="bs-release-notes" aria-label="本次更新"><h3>本次更新</h3>' + (notes ? "<p>" + esc(notes) + "</p>" : '<p class="bs-release-notes-empty">更新说明待作者填写(仅本地预览)</p>') + "</div>") + (published ? '<p class="bs-startup-update-copy">在 DSH 插件管理的「版本」中选择 v' + esc(update.latestVersion) + " 并确认更新。首次按包名安装时,可在「添加插件」输入 <code>dsh-nova-lewis@" + esc(update.latestVersion) + "</code>。</p>" : "") + (failed || unpublished || current ? "" : '<p class="bs-startup-update-restart">更新完成后,请完全退出并重新打开 Harness,以应用新版本。</p><p class="bs-startup-update-retain">你的协作设置、任务资料和运行记录都会保留</p>') + '<div class="bs-startup-update-actions">' + actions + "</div></div>";
|
|
2131
2131
|
}
|
|
2132
2132
|
function sharingNotice(local) {
|
|
2133
2133
|
const account = local ? "" : "<li>已登录 DeepSeek 的昵称与账户标识。账户标识传至接收服务后用服务端密钥 HMAC 去重,原始标识不落盘。</li>";
|
|
@@ -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 = {
|
|
@@ -2619,9 +2620,11 @@ function notices(s) {
|
|
|
2619
2620
|
const unknown = [...run.operations || [], ...run.attempts || []].filter(
|
|
2620
2621
|
(a) => a.status === "unknown" && !a.parentId
|
|
2621
2622
|
);
|
|
2623
|
+
const unavailable = run.settings?.unavailableRouteIds;
|
|
2624
|
+
const skipped = unavailable?.length ? "<p>" + esc("本次跳过暂不可用的已选型号:" + unavailable.join("、")) + "。</p>" : "";
|
|
2622
2625
|
if (!unknown.length && !tickets.length && !run.error && !run.reason)
|
|
2623
|
-
return
|
|
2624
|
-
return '<details class="tickets" open><summary>' + icon("alert", 15) + "待我处理 <b>" + num(tickets.length || 1) + "</b></summary>" + (run.error || run.reason ? txt(run.error || run.reason) : "") + unknown.map(
|
|
2626
|
+
return skipped;
|
|
2627
|
+
return skipped + '<details class="tickets" open><summary>' + icon("alert", 15) + "待我处理 <b>" + num(tickets.length || 1) + "</b></summary>" + (run.error || run.reason ? txt(run.error || run.reason) : "") + unknown.map(
|
|
2625
2628
|
(a) => button(
|
|
2626
2629
|
"reconcile",
|
|
2627
2630
|
"核对未确认请求 · " + (run.nodes?.find((n) => n.id === a.nodeId)?.title || "统筹规划"),
|
|
@@ -2704,22 +2707,22 @@ function resources(s, v) {
|
|
|
2704
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>";
|
|
2705
2708
|
}
|
|
2706
2709
|
var budgetFields = [
|
|
2707
|
-
["concurrency", "同时执行的节点数"
|
|
2708
|
-
["perApiConcurrency", "单个 API 并发数"
|
|
2709
|
-
["maxRequests", "每次运行请求上限"
|
|
2710
|
-
["maxTokens", "每次运行 Token 上限"
|
|
2711
|
-
["warnAt", "输入预算提醒阈值(%)",
|
|
2712
|
-
["compressAt", "压缩触发阈值(%)",
|
|
2713
|
-
["targetAt", "压缩目标(%)",
|
|
2710
|
+
["concurrency", "同时执行的节点数"],
|
|
2711
|
+
["perApiConcurrency", "单个 API 并发数"],
|
|
2712
|
+
["maxRequests", "每次运行请求上限"],
|
|
2713
|
+
["maxTokens", "每次运行 Token 上限"],
|
|
2714
|
+
["warnAt", "输入预算提醒阈值(%)", true],
|
|
2715
|
+
["compressAt", "压缩触发阈值(%)", true],
|
|
2716
|
+
["targetAt", "压缩目标(%)", true]
|
|
2714
2717
|
];
|
|
2715
2718
|
function settings(s, page = "policy") {
|
|
2716
2719
|
const cfg = s.settings || {}, overrides = s.settingsOverrides || s.settingOverrides || {}, budget = page === "budgets";
|
|
2717
|
-
const nf = ([name, label,
|
|
2720
|
+
const nf = ([name, label, pct]) => {
|
|
2718
2721
|
const fmt = (n) => pct ? Math.round(n * 1e4) / 100 : n;
|
|
2719
|
-
const stored = overrides[name], effective =
|
|
2720
|
-
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>';
|
|
2721
2724
|
};
|
|
2722
|
-
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>";
|
|
2723
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>";
|
|
2724
2727
|
}
|
|
2725
2728
|
|
|
@@ -3387,6 +3390,11 @@ function mountWorkbench(container, bridge, options = {}) {
|
|
|
3387
3390
|
const run = s.run;
|
|
3388
3391
|
if (!run)
|
|
3389
3392
|
return '<div data-graph class="bs-preferences bs-ending-settings">' + renderGraph(s, v) + "</div>";
|
|
3393
|
+
const switchRun = s.runs?.length > 1 ? '<div class="bs-author-entry">' + button("runs", "切换运行(" + num(s.runs.length) + ")", null, "") + "</div>" : "";
|
|
3394
|
+
if (run.settings?.easterEgg) {
|
|
3395
|
+
const answered = run.nodes.filter((n) => n.status === "done").length;
|
|
3396
|
+
return '<div data-graph class="bs-preferences bs-ending-settings"><div class="bs-field bs-ending-header"><h2>型号点名</h2>' + badge(run.status) + "</div><p>" + num(answered) + " / " + num(run.nodes.length) + " 个型号已回应</p>" + (run.status === "running" ? iconButton("cancelDialog", "取消本次点名", "stop") : "") + (run.status === "paused" ? button("resume", "继续点名", "play", "btn primary") : "") + (run.status === "blocked" ? notices(s) : "") + "</div>" + usageSummary(s) + switchRun;
|
|
3397
|
+
}
|
|
3390
3398
|
const active = run.nodes?.filter((n) => n.status === "running") || [];
|
|
3391
3399
|
const activities = active.length ? '<div class="activities">' + active.map(
|
|
3392
3400
|
(n) => button(
|
|
@@ -3400,7 +3408,7 @@ function mountWorkbench(container, bridge, options = {}) {
|
|
|
3400
3408
|
const planning = !run.planVersion || run.status === "awaiting_confirmation";
|
|
3401
3409
|
const diagram = renderGraph(s, v);
|
|
3402
3410
|
const progress = runSummary(s);
|
|
3403
|
-
return '<div data-graph class="bs-preferences bs-ending-settings"><div class="bs-field bs-ending-header"><h2>协作导图</h2><span>' + (planning ? "统筹规划" : "执行进度") + '</span></div><div class="bs-animation-content"><div class="bs-section-title"><h2>' + esc(run.task) + "</h2><span>" + esc(s.mode === "demo" ? "离线演示 · " : "") + "计划 v" + esc(run.planVersion) + " · " + badge(run.status) + '</span></div><div class="run-controls bs-update-actions">' + controls(run) + "</div>" + notices(s) + (planning ? diagram + progress : progress + activities + diagram) + "</div></div>" + inspector(s, v) + usageSummary(s) + history(s) +
|
|
3411
|
+
return '<div data-graph class="bs-preferences bs-ending-settings"><div class="bs-field bs-ending-header"><h2>协作导图</h2><span>' + (planning ? "统筹规划" : "执行进度") + '</span></div><div class="bs-animation-content"><div class="bs-section-title"><h2>' + esc(run.task) + "</h2><span>" + esc(s.mode === "demo" ? "离线演示 · " : "") + "计划 v" + esc(run.planVersion) + " · " + badge(run.status) + '</span></div><div class="run-controls bs-update-actions">' + controls(run) + "</div>" + notices(s) + (planning ? diagram + progress : progress + activities + diagram) + "</div></div>" + inspector(s, v) + usageSummary(s) + history(s) + switchRun;
|
|
3404
3412
|
}
|
|
3405
3413
|
function workspace() {
|
|
3406
3414
|
if (v.view === "graph") return runPanel();
|
|
@@ -3936,6 +3944,7 @@ function mountWorkbench(container, bridge, options = {}) {
|
|
|
3936
3944
|
payload = { planVersion: v.modal.planVersion };
|
|
3937
3945
|
for (const [key, val] of Object.entries(data)) {
|
|
3938
3946
|
if (val !== "") payload[key] = Number(val);
|
|
3947
|
+
else if (key === "maxRequests" || key === "maxTokens") payload[key] = null;
|
|
3939
3948
|
}
|
|
3940
3949
|
message = "预算已更新,请确认新版计划";
|
|
3941
3950
|
}
|
|
@@ -4786,8 +4795,37 @@ function composerPlacement(anchor, viewport, frameTop = 0) {
|
|
|
4786
4795
|
return { width, left, maxHeight: Math.min(540, openAbove ? above : below), ...openAbove ? { bottom: viewport.layoutHeight - aboveEdge } : { top: belowEdge } };
|
|
4787
4796
|
}
|
|
4788
4797
|
|
|
4798
|
+
// host/exact-composer-text.mjs
|
|
4799
|
+
var PRESENCE_TRIGGER = "在嘛?";
|
|
4800
|
+
function preserveExactComposerText(conversation, sessions, collaborationEnabled) {
|
|
4801
|
+
const send = conversation.sendSession;
|
|
4802
|
+
if (typeof send !== "function") return;
|
|
4803
|
+
const previous = Object.getOwnPropertyDescriptor(conversation, "sendSession");
|
|
4804
|
+
let active = true;
|
|
4805
|
+
function sendWithOriginalText(session, text, attachments, ...rest) {
|
|
4806
|
+
if (active && text === PRESENCE_TRIGGER && attachments.length === 0) {
|
|
4807
|
+
const binding = sessions.binding(session.sessionId);
|
|
4808
|
+
if (binding?.session === session) {
|
|
4809
|
+
const draft = conversation.input.for(binding.ctx).state.getSnapshot();
|
|
4810
|
+
const original = draft.draft;
|
|
4811
|
+
if (!draft.occurrences.length && original !== text && original.trim() === text) {
|
|
4812
|
+
return collaborationEnabled(session.sessionId).then((enabled) => send.call(this, session, active && enabled ? original : text, attachments, ...rest));
|
|
4813
|
+
}
|
|
4814
|
+
}
|
|
4815
|
+
}
|
|
4816
|
+
return send.call(this, session, text, attachments, ...rest);
|
|
4817
|
+
}
|
|
4818
|
+
conversation.sendSession = sendWithOriginalText;
|
|
4819
|
+
return () => {
|
|
4820
|
+
active = false;
|
|
4821
|
+
if (conversation.sendSession !== sendWithOriginalText) return;
|
|
4822
|
+
if (previous) Object.defineProperty(conversation, "sendSession", previous);
|
|
4823
|
+
else delete conversation.sendSession;
|
|
4824
|
+
};
|
|
4825
|
+
}
|
|
4826
|
+
|
|
4789
4827
|
// host/composer.css
|
|
4790
|
-
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";
|
|
4791
4829
|
|
|
4792
4830
|
// host/client.mjs
|
|
4793
4831
|
var h = import_react2.default.createElement;
|
|
@@ -5051,7 +5089,7 @@ function TabBody({ ctx, sessionId, defaultView, useTabInfo }) {
|
|
|
5051
5089
|
}
|
|
5052
5090
|
function Composer({ ctx, sessionId }) {
|
|
5053
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);
|
|
5054
|
-
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);
|
|
5055
5093
|
const [position, setPosition] = (0, import_react2.useState)(null);
|
|
5056
5094
|
const appearance = useEnchantAppearance();
|
|
5057
5095
|
(0, import_react2.useEffect)(() => {
|
|
@@ -5075,15 +5113,18 @@ function Composer({ ctx, sessionId }) {
|
|
|
5075
5113
|
shownPlans.set(sessionId, value.run.runId);
|
|
5076
5114
|
}
|
|
5077
5115
|
} catch (e) {
|
|
5078
|
-
if (live) error(e.message);
|
|
5116
|
+
if (live && n === seq) error(e.message);
|
|
5079
5117
|
}
|
|
5080
5118
|
};
|
|
5119
|
+
refreshState.current = refresh;
|
|
5081
5120
|
const off = b.subscribe(refresh);
|
|
5082
5121
|
void refresh();
|
|
5083
5122
|
return () => {
|
|
5084
5123
|
live = false;
|
|
5085
5124
|
off();
|
|
5086
5125
|
b.dispose();
|
|
5126
|
+
bridge.current = null;
|
|
5127
|
+
refreshState.current = null;
|
|
5087
5128
|
};
|
|
5088
5129
|
}, [ctx, sessionId]);
|
|
5089
5130
|
(0, import_react2.useEffect)(() => {
|
|
@@ -5136,6 +5177,9 @@ function Composer({ ctx, sessionId }) {
|
|
|
5136
5177
|
};
|
|
5137
5178
|
}, [opened]);
|
|
5138
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;
|
|
5139
5183
|
const materialIds = pref.materialIds || [];
|
|
5140
5184
|
const active = pref.enabled && pref.routeIds.length > 0;
|
|
5141
5185
|
function openView(view) {
|
|
@@ -5155,11 +5199,7 @@ function Composer({ ctx, sessionId }) {
|
|
|
5155
5199
|
pending(true);
|
|
5156
5200
|
try {
|
|
5157
5201
|
await connection.action(type, p);
|
|
5158
|
-
|
|
5159
|
-
if (connection === bridge.current) {
|
|
5160
|
-
setState(value);
|
|
5161
|
-
error("");
|
|
5162
|
-
}
|
|
5202
|
+
if (connection === bridge.current) await refreshState.current();
|
|
5163
5203
|
} catch (e) {
|
|
5164
5204
|
if (connection === bridge.current) error(e.message);
|
|
5165
5205
|
} finally {
|
|
@@ -5200,6 +5240,16 @@ function Composer({ ctx, sessionId }) {
|
|
|
5200
5240
|
onChange: (e) => change("composer", { enabled: e.target.checked, routeIds: pref.routeIds })
|
|
5201
5241
|
}), h("span", { className: "bs-switch", "aria-hidden": true })),
|
|
5202
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
|
+
),
|
|
5203
5253
|
...(state?.connections || []).map((group) => h(
|
|
5204
5254
|
"fieldset",
|
|
5205
5255
|
{ key: group.providerId },
|
|
@@ -5259,11 +5309,24 @@ function Composer({ ctx, sessionId }) {
|
|
|
5259
5309
|
title: reason || "本会话的协作开关、模型与进度",
|
|
5260
5310
|
"aria-expanded": opened,
|
|
5261
5311
|
"aria-haspopup": "dialog",
|
|
5262
|
-
onClick: () =>
|
|
5312
|
+
onClick: () => {
|
|
5313
|
+
setOpened(!opened);
|
|
5314
|
+
if (!opened && bridge.current) void change("refreshRoutes");
|
|
5315
|
+
}
|
|
5263
5316
|
}, "协作" + (hint ? " · " + hint : ""))
|
|
5264
5317
|
), pop);
|
|
5265
5318
|
}
|
|
5266
5319
|
function apply(ctx) {
|
|
5320
|
+
ctx.inject?.(["conversation", "sessions"], (ready) => ready.effect(() => preserveExactComposerText(ready.conversation, ready.sessions, async (sessionId) => {
|
|
5321
|
+
const bridge = hostBridge(ctx, sessionId, true);
|
|
5322
|
+
try {
|
|
5323
|
+
return (await bridge.getState()).composer?.enabled === true;
|
|
5324
|
+
} catch {
|
|
5325
|
+
return true;
|
|
5326
|
+
} finally {
|
|
5327
|
+
bridge.dispose();
|
|
5328
|
+
}
|
|
5329
|
+
}), "collaboration exact composer text"));
|
|
5267
5330
|
ctx.inject?.(["pluginNavigation"], (ready) => ready.effect(() => {
|
|
5268
5331
|
const manager = ready.pluginNavigation;
|
|
5269
5332
|
pluginManagers.set(ctx, manager);
|
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
|
@@ -13,6 +13,7 @@ import {toggleParticipant} from './selection.mjs'
|
|
|
13
13
|
import {isNewVisiblePlan} from './plan-view.mjs'
|
|
14
14
|
import {mountChoice,POLICY_OPTIONS} from '../ui/choices.mjs'
|
|
15
15
|
import {composerPlacement} from './composer-layout.mjs'
|
|
16
|
+
import {preserveExactComposerText} from './exact-composer-text.mjs'
|
|
16
17
|
import composerCSS from './composer.css'
|
|
17
18
|
|
|
18
19
|
// Keep DSH's persisted sidebar tabs, series shortcuts and settings target valid across the package rename.
|
|
@@ -188,7 +189,7 @@ function TabBody({ctx,sessionId,defaultView,useTabInfo}) {
|
|
|
188
189
|
}
|
|
189
190
|
function Composer({ctx,sessionId}){
|
|
190
191
|
const [state,setState]=useState(null),[opened,setOpened]=useState(false),[reason,error]=useState(''),[busy,pending]=useState(false)
|
|
191
|
-
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)
|
|
192
193
|
const [position,setPosition]=useState(null)
|
|
193
194
|
const appearance=useEnchantAppearance()
|
|
194
195
|
useEffect(()=>{
|
|
@@ -206,10 +207,11 @@ function Composer({ctx,sessionId}){
|
|
|
206
207
|
ctx.sidebarRight.openTab(id,{params:{view:'graph',runId:value.run.runId}})
|
|
207
208
|
shownPlans.set(sessionId,value.run.runId)
|
|
208
209
|
}
|
|
209
|
-
}catch(e){if(live)error(e.message)}
|
|
210
|
+
}catch(e){if(live && n===seq)error(e.message)}
|
|
210
211
|
}
|
|
212
|
+
refreshState.current=refresh
|
|
211
213
|
const off=b.subscribe(refresh);void refresh()
|
|
212
|
-
return ()=>{live=false;off();b.dispose()}
|
|
214
|
+
return ()=>{live=false;off();b.dispose();bridge.current=null;refreshState.current=null}
|
|
213
215
|
},[ctx,sessionId])
|
|
214
216
|
useEffect(()=>{
|
|
215
217
|
if(!opened)return
|
|
@@ -237,6 +239,9 @@ function Composer({ctx,sessionId}){
|
|
|
237
239
|
visual?.removeEventListener('resize',measure);visual?.removeEventListener('scroll',measure)}
|
|
238
240
|
},[opened])
|
|
239
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
|
|
240
245
|
const materialIds=pref.materialIds || []
|
|
241
246
|
const active=pref.enabled && pref.routeIds.length>0
|
|
242
247
|
function openView(view){openSidebar(ctx,{view});setOpened(false)}
|
|
@@ -244,7 +249,7 @@ function Composer({ctx,sessionId}){
|
|
|
244
249
|
async function change(type,p){
|
|
245
250
|
const connection=bridge.current
|
|
246
251
|
pending(true)
|
|
247
|
-
try{await connection.action(type,p);
|
|
252
|
+
try{await connection.action(type,p);if(connection===bridge.current)await refreshState.current()}
|
|
248
253
|
catch(e){if(connection===bridge.current)error(e.message)}finally{if(connection===bridge.current)pending(false)}
|
|
249
254
|
}
|
|
250
255
|
const hint=run?.status==='awaiting_confirmation'?'待确认':run?.status==='planning'?'规划中':
|
|
@@ -265,6 +270,10 @@ function Composer({ctx,sessionId}){
|
|
|
265
270
|
h('label',{className:'bs-field bs-toggle-row'},h('span',null,'在本会话启用协作'),h('input',{type:'checkbox',checked:pref.enabled,disabled:busy,
|
|
266
271
|
onChange:e=>change('composer',{enabled:e.target.checked,routeIds:pref.routeIds})}),h('span',{className:'bs-switch','aria-hidden':true})),
|
|
267
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])]})},'全选当前可用型号')),
|
|
268
277
|
...(state?.connections || []).map(group=>h('fieldset',{key:group.providerId},
|
|
269
278
|
h('legend',{title:group.providerId},group.label+(group.label!==group.providerId && state.connections.filter(g=>g.label===group.label).length>1?' · '+group.providerId:'')),
|
|
270
279
|
...group.models.map(model=>h(Participant,{key:model.id,model,providerId:group.providerId,pref,busy,change})))),
|
|
@@ -288,9 +297,18 @@ function Composer({ctx,sessionId}){
|
|
|
288
297
|
h('button',{type:'button',onClick:()=>manage('settings')},'协作设置')))),document.body)
|
|
289
298
|
return h('span',{ref:anchor,style:{display:'inline-flex'},onClick:e=>e.stopPropagation()},h(SeriesSurface,null,
|
|
290
299
|
h('button',{ref:button,type:'button',className:'bs-primary',style:{padding:'3px 8px'},
|
|
291
|
-
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)
|
|
292
304
|
}
|
|
293
305
|
export function apply(ctx){
|
|
306
|
+
ctx.inject?.(['conversation','sessions'],ready=>ready.effect(()=>preserveExactComposerText(ready.conversation,ready.sessions,async sessionId=>{
|
|
307
|
+
const bridge=hostBridge(ctx,sessionId,true)
|
|
308
|
+
try{return (await bridge.getState()).composer?.enabled===true}
|
|
309
|
+
// A transient settings error must not turn a padded ordinary message into a roll call.
|
|
310
|
+
catch{return true}finally{bridge.dispose()}
|
|
311
|
+
}),'collaboration exact composer text'))
|
|
294
312
|
ctx.inject?.(['pluginNavigation'],ready=>ready.effect(()=>{
|
|
295
313
|
const manager=ready.pluginNavigation
|
|
296
314
|
pluginManagers.set(ctx,manager)
|
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; }
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export const PRESENCE_TRIGGER = '在嘛?'
|
|
2
|
+
|
|
3
|
+
// DSH rc.5 trims both ends of ordinary drafts before handing them to the send
|
|
4
|
+
// service. At that handoff the session's input store still contains the draft.
|
|
5
|
+
export function preserveExactComposerText(conversation, sessions, collaborationEnabled) {
|
|
6
|
+
const send = conversation.sendSession
|
|
7
|
+
if (typeof send !== 'function') return
|
|
8
|
+
const previous = Object.getOwnPropertyDescriptor(conversation, 'sendSession')
|
|
9
|
+
let active = true
|
|
10
|
+
function sendWithOriginalText(session, text, attachments, ...rest) {
|
|
11
|
+
if (active && text === PRESENCE_TRIGGER && attachments.length === 0) {
|
|
12
|
+
const binding = sessions.binding(session.sessionId)
|
|
13
|
+
if (binding?.session === session) {
|
|
14
|
+
const draft = conversation.input.for(binding.ctx).state.getSnapshot()
|
|
15
|
+
const original = draft.draft
|
|
16
|
+
if (!draft.occurrences.length && original !== text && original.trim() === text) {
|
|
17
|
+
return collaborationEnabled(session.sessionId).then(enabled =>
|
|
18
|
+
send.call(this, session, active && enabled ? original : text, attachments, ...rest))
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return send.call(this, session, text, attachments, ...rest)
|
|
23
|
+
}
|
|
24
|
+
conversation.sendSession = sendWithOriginalText
|
|
25
|
+
return () => {
|
|
26
|
+
active = false
|
|
27
|
+
if (conversation.sendSession !== sendWithOriginalText) return
|
|
28
|
+
if (previous) Object.defineProperty(conversation, 'sendSession', previous)
|
|
29
|
+
else delete conversation.sendSession
|
|
30
|
+
}
|
|
31
|
+
}
|