dsh-workbench-tasks 5.4.0 → 5.5.4
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/lib/client.js +653 -1900
- package/lib/index.js +3 -26
- package/lib/publisher/brief.js +1 -0
- package/lib/publisher/roles.js +3 -3
- package/package.json +5 -9
- package/lib/infra/data.js +0 -368
- package/lib/publisher/catalog.js +0 -100
- package/lib/publisher/command.js +0 -82
package/lib/publisher/command.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 任务插件注册的斜杠命令:把用户原话、附件交给单次绑定角色的下一轮。
|
|
3
|
-
* 命令本身不建任务、不写业务数据;无 commands 服务(ACP/无 UI)时静默跳过。
|
|
4
|
-
*
|
|
5
|
-
* 命令的元信息与正文生成函数都在 catalog.js:这里只做注册循环,
|
|
6
|
-
* 新增命令时改目录即可,不用再写一遍 register 调用。
|
|
7
|
-
*/
|
|
8
|
-
import { TASK_COMMANDS, usageText } from "./catalog.js";
|
|
9
|
-
|
|
10
|
-
export const PUBLISHER_COMMAND = TASK_COMMANDS[0].name;
|
|
11
|
-
|
|
12
|
-
export const PUBLISHER_USAGE = usageText(TASK_COMMANDS[0], "zh");
|
|
13
|
-
|
|
14
|
-
function newMessageId() {
|
|
15
|
-
const c = globalThis.crypto;
|
|
16
|
-
if (c && typeof c.randomUUID === "function") return c.randomUUID();
|
|
17
|
-
return "msg-" + Date.now().toString(36) + "-" + Math.random().toString(36).slice(2, 10);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** 取当前会话 id;用于绑定命令生成的消息。 */
|
|
21
|
-
function sessionIdOf(agent) {
|
|
22
|
-
return String((agent && agent.session && agent.session.id) || (agent && agent.id) || "");
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** 注册目录里的全部命令,返回清理函数。commands 服务缺失时返回空清理函数且不报错。 */
|
|
26
|
-
export function registerPublisherCommand(ctx) {
|
|
27
|
-
let commands;
|
|
28
|
-
try {
|
|
29
|
-
commands = ctx && typeof ctx.get === "function" ? ctx.get("commands") : undefined;
|
|
30
|
-
} catch {
|
|
31
|
-
commands = undefined;
|
|
32
|
-
}
|
|
33
|
-
if (!commands || typeof commands.register !== "function") return () => {};
|
|
34
|
-
|
|
35
|
-
const disposes = TASK_COMMANDS.map((entry) =>
|
|
36
|
-
commands.register({
|
|
37
|
-
name: entry.name,
|
|
38
|
-
description: entry.title.zh + ":" + entry.summary.zh,
|
|
39
|
-
input: { hint: entry.inputHint.zh, attachments: entry.attachments !== false },
|
|
40
|
-
// 正文由 followup 带入模型历史,命令日志里不再重复记一遍。
|
|
41
|
-
recordInput: false,
|
|
42
|
-
handler: ({ agent, rawInput, attachments } = {}) => {
|
|
43
|
-
const requirement = typeof rawInput === "string" ? rawInput : "";
|
|
44
|
-
if (!requirement.trim()) {
|
|
45
|
-
return { kind: "success", text: usageText(entry, "zh") };
|
|
46
|
-
}
|
|
47
|
-
const limit = entry.limit;
|
|
48
|
-
if (limit && requirement.length > limit.max) {
|
|
49
|
-
return {
|
|
50
|
-
kind: "error",
|
|
51
|
-
text:
|
|
52
|
-
limit.field.zh + "约 " + requirement.length + " 字符,超过 " + limit.max +
|
|
53
|
-
" 字符上限。请精简需求,或把长材料作为附件随命令发送。",
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
if (!agent || typeof agent.followup !== "function") {
|
|
57
|
-
return { kind: "error", text: "当前会话无法接收下一轮消息," + entry.title.zh + "引导没有送出。" };
|
|
58
|
-
}
|
|
59
|
-
const host = ctx.workbench;
|
|
60
|
-
const sessionId = sessionIdOf(agent);
|
|
61
|
-
if (!sessionId || typeof host?.bindMessageRole !== "function") {
|
|
62
|
-
return { kind: "error", text: "当前会话无法绑定单次发布角色,请检查工作台宿主版本和会话状态。" };
|
|
63
|
-
}
|
|
64
|
-
const id = newMessageId();
|
|
65
|
-
const content = [...(Array.isArray(attachments) ? attachments : []), { type: "text", text: requirement }];
|
|
66
|
-
let cancel;
|
|
67
|
-
try {
|
|
68
|
-
cancel = host.bindMessageRole(sessionId, id, entry.roleId);
|
|
69
|
-
agent.followup({ id, role: "user", content, source: { kind: "user" } });
|
|
70
|
-
} catch (error) {
|
|
71
|
-
cancel?.();
|
|
72
|
-
const message = error && error.message ? error.message : String(error);
|
|
73
|
-
return { kind: "error", text: entry.title.zh + "引导送入失败:" + message };
|
|
74
|
-
}
|
|
75
|
-
return { kind: "success", text: entry.sentText.zh };
|
|
76
|
-
},
|
|
77
|
-
}),
|
|
78
|
-
);
|
|
79
|
-
return () => {
|
|
80
|
-
for (const dispose of disposes) if (typeof dispose === "function") dispose();
|
|
81
|
-
};
|
|
82
|
-
}
|