pi-web-ui 0.110.0 → 0.111.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/bin/frp-manager.mjs +85 -7
  2. package/dist/server/agent-formatters.js +10 -6
  3. package/dist/server/agent-service-daemon.js +27 -9
  4. package/dist/server/agent-service.js +140 -24
  5. package/dist/server/attachments.js +114 -31
  6. package/dist/server/canvas/canvas-agent-tool.js +587 -0
  7. package/dist/server/canvas/canvas-cards.js +144 -0
  8. package/dist/server/canvas/canvas-dispatch.js +155 -0
  9. package/dist/server/canvas/canvas-orchestrator.js +1027 -0
  10. package/dist/server/canvas/canvas-store.js +260 -0
  11. package/dist/server/client-id-utils.js +2 -2
  12. package/dist/server/client-state.js +24 -0
  13. package/dist/server/context-budget.js +6 -3
  14. package/dist/server/dsh/dsh-agent-service.js +115 -9
  15. package/dist/server/dsh/dsh-client.js +10 -1
  16. package/dist/server/dsh/runtime/goal-rpc.mjs +128 -3
  17. package/dist/server/dsh/runtime/launcher.mjs +59 -5
  18. package/dist/server/dsh/runtime/runtime-root.mjs +353 -40
  19. package/dist/server/durable/durable-agent-service.js +3 -0
  20. package/dist/server/file-transfer-routes.js +8 -2
  21. package/dist/server/files-service.js +10 -2
  22. package/dist/server/index.js +137 -4
  23. package/dist/server/marker-service.js +3 -1
  24. package/dist/server/markers/marker.js +45 -4
  25. package/dist/server/markers/registry.js +31 -0
  26. package/dist/server/message-window.js +6 -3
  27. package/dist/server/office-parse.js +394 -7
  28. package/dist/server/plugin-api-catalog.js +6 -0
  29. package/dist/server/plugins.js +97 -20
  30. package/dist/server/preset-fields.js +35 -1
  31. package/dist/server/preset-share.js +3 -0
  32. package/dist/server/prompt-assembler.js +7 -1
  33. package/dist/server/prompt-composer.js +66 -36
  34. package/dist/server/protocol-version.js +1 -1
  35. package/dist/server/remote-ssh-service.js +16 -4
  36. package/dist/server/settings-service.js +19 -3
  37. package/dist/server/tool-manager.js +30 -0
  38. package/dist/server/univer-service.js +448 -0
  39. package/dist/server/universal/drivers/claude-code.js +19 -2
  40. package/dist/server/universal/universal-attachments.js +5 -0
  41. package/dist/server/universal/universal-service.js +5 -0
  42. package/dist/server/universal/universal-session.js +28 -12
  43. package/dist/server/update-check.js +90 -5
  44. package/dist/server/workspace-snapshot.js +33 -2
  45. package/docs/dsh-engine.md +497 -0
  46. package/package.json +5 -4
  47. package/plugin-sdk/index.d.ts +17 -0
  48. package/plugin-sdk/index.mjs +5 -0
  49. package/plugins/catalog.json +22 -0
  50. package/themes/aetheris.css +114 -0
  51. package/themes/bases/obsidian-base.css +216 -0
  52. package/themes/md-preview.css +113 -0
  53. package/themes/wallpaper-flow.css +182 -0
  54. package/web/dist/assets/{TerminalPanel-BHjM6pzY.js → TerminalPanel-BiUNySMA.js} +2 -2
  55. package/web/dist/assets/index-B0ajS__T.js +697 -0
  56. package/web/dist/assets/index-BHik5WGG.css +1 -0
  57. package/web/dist/assets/{markdown-DXwnfD9T.js → markdown-BJZlfvdP.js} +24 -24
  58. package/web/dist/assets/markdown-DSNUiDzp.css +1 -0
  59. package/web/dist/index.html +4 -4
  60. package/web/dist/sw.js +1 -1
  61. package/web/dist/assets/es-DIDZppIF.js +0 -2
  62. package/web/dist/assets/index-DwInT7-a.css +0 -1
  63. package/web/dist/assets/index-GfVFIgIL.js +0 -693
  64. package/web/dist/assets/markdown-CCeVCbci.css +0 -1
@@ -0,0 +1,144 @@
1
+ /**
2
+ * canvas-cards.ts — 自定义卡片注册表(AI/用户沉淀的可复用节点模板,永久有效)。
3
+ *
4
+ * 存放在 <dataDir>/canvas/custom-cards.json 中:{ cards: CanvasCustomCard[] }。
5
+ * 卡片落图时展开为普通节点(role 沿用内置角色),不碰封闭的 CanvasNodeRole 联合类型。
6
+ */
7
+ import { existsSync, mkdirSync, readFileSync } from "node:fs";
8
+ import { join } from "node:path";
9
+ import { writeJsonAtomicSync } from "../atomic-file.js";
10
+ import { isSafeGraphId } from "./canvas-store.js";
11
+ const VALID_ENGINES = new Set(["pi", "dsh", "claude", "durable"]);
12
+ /** 卡片 id 与节点 id 同一安全口径:可作文件名/分支名,不穿越。 */
13
+ export function isSafeCardId(id) {
14
+ return isSafeGraphId(id);
15
+ }
16
+ function cardsPath(dataDir) {
17
+ const dir = join(dataDir, "canvas");
18
+ if (!existsSync(dir))
19
+ mkdirSync(dir, { recursive: true });
20
+ return join(dir, "custom-cards.json");
21
+ }
22
+ /** 读全表(文件缺失/损坏 → 空表,不炸)。 */
23
+ export function listCustomCards(dataDir) {
24
+ try {
25
+ const raw = JSON.parse(readFileSync(cardsPath(dataDir), "utf8"));
26
+ if (!Array.isArray(raw?.cards))
27
+ return [];
28
+ return raw.cards.filter((c) => c && isSafeCardId(c.id));
29
+ }
30
+ catch {
31
+ return [];
32
+ }
33
+ }
34
+ function persist(dataDir, cards) {
35
+ writeJsonAtomicSync(cardsPath(dataDir), { cards });
36
+ }
37
+ /** 净化输入:标题≤24,文案各≤2000,role/engine 非法直接抛(调用方转用户提示)。 */
38
+ export function sanitizeCardInput(input, isValidRole) {
39
+ const title = (typeof input.title === "string" ? input.title : "").trim().slice(0, 24);
40
+ if (!title)
41
+ throw new Error("Card title is required (1-24 chars).");
42
+ const role = (typeof input.role === "string" ? input.role : "").trim();
43
+ if (!role || !isValidRole(role))
44
+ throw new Error(`Invalid card role: ${JSON.stringify(input.role)}`);
45
+ const out = {
46
+ title,
47
+ role: role,
48
+ };
49
+ const instruction = (typeof input.instruction === "string" ? input.instruction : "").trim().slice(0, 2000);
50
+ if (instruction)
51
+ out.instruction = instruction;
52
+ const systemPrompt = (typeof input.systemPrompt === "string" ? input.systemPrompt : "").trim().slice(0, 2000);
53
+ if (systemPrompt)
54
+ out.systemPrompt = systemPrompt;
55
+ const model = (typeof input.model === "string" ? input.model : "").trim().slice(0, 120);
56
+ if (model)
57
+ out.model = model;
58
+ const engine = (typeof input.engine === "string" ? input.engine : "").trim();
59
+ if (engine) {
60
+ if (!VALID_ENGINES.has(engine))
61
+ throw new Error(`Invalid card engine: ${JSON.stringify(input.engine)}`);
62
+ out.engine = engine;
63
+ }
64
+ // 行为参数:纯量键值≤20个(落图即节点 config,循环次数/表达式/cron/api 等都靠它)
65
+ if (input.config !== undefined) {
66
+ if (typeof input.config !== "object" || input.config === null || Array.isArray(input.config)) {
67
+ throw new Error("Card config must be a plain object.");
68
+ }
69
+ const entries = Object.entries(input.config);
70
+ if (entries.length > 20)
71
+ throw new Error("Card config holds at most 20 keys.");
72
+ const clean = {};
73
+ for (const [k, v] of entries) {
74
+ if (!/^[A-Za-z0-9_-]{1,32}$/.test(k))
75
+ throw new Error(`Invalid card config key: ${JSON.stringify(k)}`);
76
+ if (typeof v === "string")
77
+ clean[k] = v.slice(0, 500);
78
+ else if (typeof v === "number" || typeof v === "boolean")
79
+ clean[k] = v;
80
+ else
81
+ throw new Error(`Invalid card config value for ${JSON.stringify(k)} (scalar only).`);
82
+ }
83
+ if (Object.keys(clean).length > 0)
84
+ out.config = clean;
85
+ }
86
+ return out;
87
+ }
88
+ /** 新增卡片(id 服务端生成)。 */
89
+ export function addCustomCard(dataDir, input, isValidRole) {
90
+ const clean = sanitizeCardInput(input, isValidRole);
91
+ const cards = listCustomCards(dataDir);
92
+ const card = {
93
+ id: `card_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`,
94
+ ...clean,
95
+ updatedAt: Date.now(),
96
+ };
97
+ cards.push(card);
98
+ persist(dataDir, cards);
99
+ return card;
100
+ }
101
+ /** 更新卡片(只改给定字段,id 不可改)。 */
102
+ export function updateCustomCard(dataDir, id, patch, isValidRole) {
103
+ if (!isSafeCardId(id))
104
+ throw new Error(`Invalid card id: ${JSON.stringify(id)}`);
105
+ const cards = listCustomCards(dataDir);
106
+ const card = cards.find((c) => c.id === id);
107
+ if (!card)
108
+ throw new Error(`Card not found: ${id}`);
109
+ const merged = {
110
+ title: patch.title ?? card.title,
111
+ role: patch.role ?? card.role,
112
+ instruction: patch.instruction ?? card.instruction ?? "",
113
+ systemPrompt: patch.systemPrompt ?? card.systemPrompt ?? "",
114
+ model: patch.model ?? card.model ?? "",
115
+ engine: patch.engine ?? card.engine ?? "",
116
+ config: patch.config ?? card.config ?? {},
117
+ };
118
+ const clean = sanitizeCardInput(merged, isValidRole);
119
+ Object.assign(card, clean, { updatedAt: Date.now() });
120
+ // 清掉被置空的可选字段
121
+ if (!clean.instruction)
122
+ delete card.instruction;
123
+ if (!clean.systemPrompt)
124
+ delete card.systemPrompt;
125
+ if (!clean.model)
126
+ delete card.model;
127
+ if (!clean.engine)
128
+ delete card.engine;
129
+ if (!clean.config)
130
+ delete card.config;
131
+ persist(dataDir, cards);
132
+ return card;
133
+ }
134
+ /** 删除卡片(不存在返回 false)。 */
135
+ export function deleteCustomCard(dataDir, id) {
136
+ if (!isSafeCardId(id))
137
+ throw new Error(`Invalid card id: ${JSON.stringify(id)}`);
138
+ const cards = listCustomCards(dataDir);
139
+ const next = cards.filter((c) => c.id !== id);
140
+ if (next.length === cards.length)
141
+ return false;
142
+ persist(dataDir, next);
143
+ return true;
144
+ }
@@ -0,0 +1,155 @@
1
+ import { deleteCanvasGraph, isSafeGraphId, listCanvasGraphs, loadCanvasGraph, saveCanvasGraph, } from "./canvas-store.js";
2
+ import { deleteCustomCard, listCustomCards } from "./canvas-cards.js";
3
+ export function handleCanvasMessage(msg, dataDir, orchestrator, send, opts) {
4
+ switch (msg.type) {
5
+ case "canvas_list": {
6
+ const graphs = listCanvasGraphs(dataDir);
7
+ send({ type: "canvas_list_result", graphs });
8
+ return true;
9
+ }
10
+ case "canvas_cards": {
11
+ send({ type: "canvas_cards_state", cards: listCustomCards(dataDir) });
12
+ return true;
13
+ }
14
+ case "canvas_card_delete": {
15
+ try {
16
+ deleteCustomCard(dataDir, msg.id);
17
+ }
18
+ catch {
19
+ // 非法 id 直接忽略
20
+ }
21
+ send({ type: "canvas_cards_state", cards: listCustomCards(dataDir) });
22
+ return true;
23
+ }
24
+ case "canvas_load": {
25
+ if (!isSafeGraphId(msg.id))
26
+ return true;
27
+ try {
28
+ const graph = loadCanvasGraph(dataDir, msg.id);
29
+ send({ type: "canvas_graph_state", graph });
30
+ }
31
+ catch {
32
+ send({
33
+ type: "canvas_graph_state",
34
+ graph: loadCanvasGraph(dataDir, "default"),
35
+ });
36
+ }
37
+ return true;
38
+ }
39
+ case "canvas_save": {
40
+ if (!isSafeGraphId(msg.graph?.id))
41
+ return true;
42
+ const res = saveCanvasGraph(dataDir, msg.graph, { expectedRev: msg.baseRev });
43
+ if (res.conflict) {
44
+ send({
45
+ type: "canvas_error",
46
+ code: "rev_conflict",
47
+ message: "stale",
48
+ graphId: msg.graph.id,
49
+ graph: res.graph,
50
+ requestId: msg.requestId,
51
+ });
52
+ send({ type: "canvas_graph_state", graph: res.graph });
53
+ return true;
54
+ }
55
+ send({ type: "canvas_graph_state", graph: msg.graph });
56
+ const graphs = listCanvasGraphs(dataDir);
57
+ send({ type: "canvas_list_result", graphs });
58
+ return true;
59
+ }
60
+ case "canvas_delete": {
61
+ if (!isSafeGraphId(msg.id))
62
+ return true;
63
+ deleteCanvasGraph(dataDir, msg.id);
64
+ const graphs = listCanvasGraphs(dataDir);
65
+ send({ type: "canvas_list_result", graphs });
66
+ return true;
67
+ }
68
+ case "canvas_run_all": {
69
+ try {
70
+ const graph = loadCanvasGraph(dataDir, msg.graphId);
71
+ void orchestrator.runAll(graph, msg.initialPrompt, opts?.runBase);
72
+ }
73
+ catch {
74
+ // 忽略
75
+ }
76
+ return true;
77
+ }
78
+ case "canvas_run_node": {
79
+ try {
80
+ const graph = loadCanvasGraph(dataDir, msg.graphId);
81
+ void orchestrator.runNode(graph, msg.nodeId, msg.prompt, opts?.runBase);
82
+ }
83
+ catch {
84
+ // 忽略
85
+ }
86
+ return true;
87
+ }
88
+ case "canvas_stop_node": {
89
+ orchestrator.stopNode(msg.graphId, msg.nodeId);
90
+ return true;
91
+ }
92
+ case "canvas_stop_all": {
93
+ orchestrator.stopAll(msg.graphId);
94
+ return true;
95
+ }
96
+ case "canvas_steer_node": {
97
+ if (!isSafeGraphId(msg.graphId))
98
+ return true;
99
+ orchestrator.steerNode(msg.graphId, msg.nodeId, msg.message);
100
+ return true;
101
+ }
102
+ case "canvas_get_log": {
103
+ if (!isSafeGraphId(msg.graphId))
104
+ return true;
105
+ send({
106
+ type: "canvas_node_log_state",
107
+ graphId: msg.graphId,
108
+ nodeId: msg.nodeId,
109
+ entries: orchestrator.getNodeLog(msg.graphId, msg.nodeId),
110
+ messages: orchestrator.getNodeMessages(msg.graphId, msg.nodeId),
111
+ });
112
+ return true;
113
+ }
114
+ case "canvas_clear_log": {
115
+ if (!isSafeGraphId(msg.graphId))
116
+ return true;
117
+ orchestrator.clearNodeLog(msg.graphId, msg.nodeId);
118
+ send({
119
+ type: "canvas_node_log_state",
120
+ graphId: msg.graphId,
121
+ nodeId: msg.nodeId,
122
+ entries: [],
123
+ messages: [],
124
+ });
125
+ return true;
126
+ }
127
+ case "canvas_review_node": {
128
+ // 审查门禁真动作:落盘持久化 + 广播,非本地假状态(#707)
129
+ if (!isSafeGraphId(msg.graphId))
130
+ return true;
131
+ try {
132
+ const graph = orchestrator.reviewNode(msg.graphId, msg.nodeId, msg.decision, msg.comment);
133
+ if (graph)
134
+ send({ type: "canvas_graph_state", graph });
135
+ }
136
+ catch {
137
+ // 忽略
138
+ }
139
+ return true;
140
+ }
141
+ case "canvas_reset_status": {
142
+ try {
143
+ const graph = loadCanvasGraph(dataDir, msg.graphId);
144
+ orchestrator.resetStatus(graph);
145
+ send({ type: "canvas_graph_state", graph });
146
+ }
147
+ catch {
148
+ // 忽略
149
+ }
150
+ return true;
151
+ }
152
+ default:
153
+ return false;
154
+ }
155
+ }