pi-web-ui 0.114.3 → 0.116.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 (224) hide show
  1. package/CHANGELOG.md +62 -1
  2. package/bin/pi-web-ui.mjs +90 -8
  3. package/dist/gh-comment-781.md +5 -0
  4. package/dist/server/agent-service-daemon.js +522 -32
  5. package/dist/server/agent-service.js +954 -402
  6. package/dist/server/canvas/canvas-dispatch.js +13 -1
  7. package/dist/server/client-state.js +42 -2
  8. package/dist/server/communicate-tool.js +2 -0
  9. package/dist/server/conversation-communication.js +14 -0
  10. package/dist/server/conversation-identity.js +27 -0
  11. package/dist/server/device-center/approval-summary.js +31 -0
  12. package/dist/server/device-center/bot-catalog.js +21 -7
  13. package/dist/server/device-center/bot-execution.js +100 -9
  14. package/dist/server/device-center/bot-presets.js +46 -0
  15. package/dist/server/device-center/collab-service.js +362 -13
  16. package/dist/server/device-center/collab-tool.js +824 -13
  17. package/dist/server/device-center/connector.js +359 -23
  18. package/dist/server/device-center/desktop-page.js +22 -16
  19. package/dist/server/device-center/device-integration.js +595 -0
  20. package/dist/server/device-center/execution-guides.js +32 -0
  21. package/dist/server/device-center/execution-instructions.js +20 -0
  22. package/dist/server/device-center/execution-settings.js +213 -0
  23. package/dist/server/device-center/execution-system-prompt.js +38 -0
  24. package/dist/server/device-center/execution-workspace.js +20 -0
  25. package/dist/server/device-center/executor.js +392 -40
  26. package/dist/server/device-center/file-sync-paths.js +171 -0
  27. package/dist/server/device-center/file-sync.js +186 -96
  28. package/dist/server/device-center/group-context-delta.js +37 -0
  29. package/dist/server/device-center/group-context-message.js +210 -0
  30. package/dist/server/device-center/group-context.js +179 -0
  31. package/dist/server/device-center/group-events.js +136 -0
  32. package/dist/server/device-center/group-plan-guard.js +138 -0
  33. package/dist/server/device-center/hub-conversations.js +233 -0
  34. package/dist/server/device-center/hub-deliveries.js +277 -0
  35. package/dist/server/device-center/hub-integration.js +451 -0
  36. package/dist/server/device-center/hub-locks.js +320 -0
  37. package/dist/server/device-center/hub-page.js +13 -33
  38. package/dist/server/device-center/hub-webhooks.js +165 -0
  39. package/dist/server/device-center/hub.js +2379 -107
  40. package/dist/server/device-center/human-interaction.js +232 -0
  41. package/dist/server/device-center/integration-errors.js +25 -0
  42. package/dist/server/device-center/local-hub.js +20 -1
  43. package/dist/server/device-center/local-page.js +17 -0
  44. package/dist/server/device-center/local.js +430 -41
  45. package/dist/server/device-center/main.js +11 -1
  46. package/dist/server/device-center/partition-log.js +293 -0
  47. package/dist/server/device-center/path-portal.js +11 -3
  48. package/dist/server/device-center/relay.js +364 -35
  49. package/dist/server/device-center/report-metadata.js +66 -0
  50. package/dist/server/device-center/report-upload.js +63 -0
  51. package/dist/server/device-center/runtime.js +598 -41
  52. package/dist/server/device-center/smoke-preview.js +3 -0
  53. package/dist/server/device-center/store.js +203 -41
  54. package/dist/server/device-center/task-context-budget.js +161 -0
  55. package/dist/server/device-center/task-journal.js +385 -0
  56. package/dist/server/device-center/task-plan.js +33 -0
  57. package/dist/server/device-center/task-progress.js +141 -0
  58. package/dist/server/device-center/task-recovery.js +452 -0
  59. package/dist/server/device-center/task-report-outbox.js +216 -0
  60. package/dist/server/device-center/task-report.js +384 -0
  61. package/dist/server/device-center/task-scheduler.js +445 -0
  62. package/dist/server/device-center/task-state.js +333 -0
  63. package/dist/server/device-center/transfer-stream.js +1006 -0
  64. package/dist/server/device-center/transfers.js +841 -8
  65. package/dist/server/dispatch-domain-handlers.js +35 -6
  66. package/dist/server/dsh/dsh-agent-service.js +6 -0
  67. package/dist/server/durable/durable-capabilities.js +11 -0
  68. package/dist/server/engine-probe.js +112 -1
  69. package/dist/server/global-loader.js +119 -19
  70. package/dist/server/goal-service.js +10 -5
  71. package/dist/server/index.js +222 -29
  72. package/dist/server/managed.js +2 -0
  73. package/dist/server/markers/builtins/services.js +123 -0
  74. package/dist/server/markers/builtins/todo.js +189 -0
  75. package/dist/server/markers-list-tool.js +34 -0
  76. package/dist/server/message-deletion.js +40 -0
  77. package/dist/server/message-window.js +9 -0
  78. package/dist/server/model-admin.js +48 -6
  79. package/dist/server/model-enrich.js +10 -1
  80. package/dist/server/orchestrator.js +109 -0
  81. package/dist/server/patch-executable-lookup.js +396 -0
  82. package/dist/server/payload-limits.js +2 -0
  83. package/dist/server/plugin-llm.js +100 -9
  84. package/dist/server/plugins.js +65 -7
  85. package/dist/server/preset-fields.js +24 -0
  86. package/dist/server/preset-share.js +2 -0
  87. package/dist/server/prompt-base-store.js +85 -0
  88. package/dist/server/prompt-composer.js +44 -2
  89. package/dist/server/protocol-version.js +1 -1
  90. package/dist/server/protocol.js +2 -2
  91. package/dist/server/reasoning-registry.js +207 -0
  92. package/dist/server/remote-ssh-service.js +22 -9
  93. package/dist/server/resolve-global-sdk.js +2 -0
  94. package/dist/server/session-search.js +1 -1
  95. package/dist/server/settings-service.js +90 -39
  96. package/dist/server/skill-content-filler.js +29 -8
  97. package/dist/server/skill-tool.js +12 -3
  98. package/dist/server/startup-banner.js +35 -0
  99. package/dist/server/subagent-helpers.js +4 -1
  100. package/dist/server/subagents.js +52 -37
  101. package/dist/server/system-prompt-soul.js +41 -0
  102. package/dist/server/tool-host-factories.js +1 -0
  103. package/dist/server/tool-manager.js +17 -9
  104. package/dist/server/unauthorized-page.js +319 -0
  105. package/dist/server/univer-service.js +448 -0
  106. package/dist/server/universal/drivers/dsh-driver.js +379 -0
  107. package/dist/server/universal/universal-session.js +5 -0
  108. package/dist/server/webui-context.js +25 -5
  109. package/dist/test-artifact.md +9 -0
  110. package/dist/test-preview-modal.md +11 -0
  111. package/dist/test-report.html +20 -0
  112. package/docs/README.md +94 -0
  113. package/docs/architecture-plugins.md +946 -0
  114. package/docs/device-center.md +106 -12
  115. package/docs/dsh-engine.md +10 -10
  116. package/extensions/webui.ts +43 -1
  117. package/package.json +2 -1
  118. package/themes/aetheris.css +5 -0
  119. package/themes/ayu-light.css +6 -0
  120. package/themes/bases/flow-base.css +68 -68
  121. package/themes/catppuccin-latte.css +6 -0
  122. package/themes/catppuccin.css +6 -0
  123. package/themes/claude-code-dark.css +5 -0
  124. package/themes/codex.css +6 -0
  125. package/themes/cyberpunk.css +6 -0
  126. package/themes/dark-teal.css +6 -1
  127. package/themes/dazzle.css +6 -0
  128. package/themes/everforest-light.css +6 -0
  129. package/themes/flow-light.css +8 -1
  130. package/themes/flow.css +6 -1
  131. package/themes/geist.css +6 -0
  132. package/themes/gruvbox-light.css +6 -0
  133. package/themes/kanagawa-lotus.css +6 -0
  134. package/themes/md-preview.css +6 -0
  135. package/themes/mist.css +6 -0
  136. package/themes/nord.css +6 -0
  137. package/themes/one-dark.css +6 -0
  138. package/themes/paper.css +6 -0
  139. package/themes/rose-pine-dawn.css +6 -0
  140. package/themes/sakura.css +6 -0
  141. package/themes/solarized-light.css +6 -0
  142. package/themes/tokyo-night.css +6 -0
  143. package/themes/translucent.css +6 -0
  144. package/themes/transparent.css +6 -0
  145. package/themes/vs-code-dark.css +5 -0
  146. package/themes/wallpaper-flow.css +5 -1
  147. package/themes/wallpaper-obsidian.css +6 -0
  148. package/themes/white.css +6 -0
  149. package/themes/zhujian-dark.css +6 -1
  150. package/themes/zhujian.css +6 -1
  151. package/themes/zhupi-dark.css +6 -1
  152. package/themes/zhupi.css +6 -1
  153. package/web/dist/.build-assets.json +1 -1
  154. package/web/dist/assets/BgTasksModal-BDoOpj-F.js +1 -0
  155. package/web/dist/assets/BgTasksModal-C0i3O1FT.js +1 -0
  156. package/web/dist/assets/{CanvasStudio-BSg9ghPV.js → CanvasStudio-B8thymBN.js} +3 -3
  157. package/web/dist/assets/{CanvasStudio-DxW7C3Sz.js → CanvasStudio-zSxyIx1R.js} +3 -3
  158. package/web/dist/assets/DeviceCenter-DfAHKcid.js +3 -0
  159. package/web/dist/assets/DeviceCenter-ydvOTlzE.js +3 -0
  160. package/web/dist/assets/DeviceExecutionSettings-q5Ik8oXg.js +1 -0
  161. package/web/dist/assets/DeviceGroups-CI14_SRb.js +1 -0
  162. package/web/dist/assets/DeviceGroups-DvsB5IEU.js +1 -0
  163. package/web/dist/assets/Dropdown-C4LIhshN.js +1 -0
  164. package/web/dist/assets/FilePreview-BgGongmv.js +2 -0
  165. package/web/dist/assets/FilePreview-D4NrhF-U.js +2 -0
  166. package/web/dist/assets/GlobalSearchModal-BWgU8yPd.js +1 -0
  167. package/web/dist/assets/GlobalSearchModal-F7fNimKk.js +1 -0
  168. package/web/dist/assets/GroupConversation-Dh71Pdb-.js +17 -0
  169. package/web/dist/assets/GroupConversation-ZK3nRmNm.js +17 -0
  170. package/web/dist/assets/HintTip-c6d0TJoh.js +1 -0
  171. package/web/dist/assets/ModelConfigModal-YVEgyy34.js +2 -0
  172. package/web/dist/assets/ModelConfigModal-vWtg3srp.js +2 -0
  173. package/web/dist/assets/PiSetupModal-BmMrrgB9.js +1 -0
  174. package/web/dist/assets/ProviderOAuthControls-BGSBIKD7.js +1 -0
  175. package/web/dist/assets/SCMPanel-B8_EDxNr.js +2 -0
  176. package/web/dist/assets/SCMPanel-BU58qk3T.js +2 -0
  177. package/web/dist/assets/SettingsModal-CMUybq3J.js +32 -0
  178. package/web/dist/assets/SettingsModal-OBmGTh-5.js +32 -0
  179. package/web/dist/assets/TerminalPanel-0CYvD72B.js +3 -0
  180. package/web/dist/assets/TerminalPanel-DDavKvFr.js +3 -0
  181. package/web/dist/assets/TuiOverlayModal-BsA-QTvN.js +1 -0
  182. package/web/dist/assets/TuiOverlayModal-DzoVQBuG.js +1 -0
  183. package/web/dist/assets/app-globals-CZxzGvIo.js +123 -0
  184. package/web/dist/assets/canvas-client-CUnXlQYX.js +1 -0
  185. package/web/dist/assets/{desktop-7EvUHhKQ.js → desktop-aAKpvKJV.js} +1 -1
  186. package/web/dist/assets/group-view-state-CGCzYF8k.js +1 -0
  187. package/web/dist/assets/index-C6DwztqE.css +1 -0
  188. package/web/dist/assets/index-CuN802Sj.js +93 -0
  189. package/web/dist/assets/index-EH5Fw9fa.js +93 -0
  190. package/web/dist/assets/plugin-host-BRWib9DF.js +1 -0
  191. package/web/dist/assets/remote-ssh-client-CfYSMEZg.js +1 -0
  192. package/web/dist/assets/theme-D2l_mLNo.js +1 -0
  193. package/web/dist/index.html +10 -9
  194. package/web/dist/sw.js +1 -1
  195. package/web/dist/assets/BgTasksModal-BvnUHjFe.js +0 -1
  196. package/web/dist/assets/BgTasksModal-DSC8ncW3.js +0 -1
  197. package/web/dist/assets/DeviceCenter-Bmgr-Bwm.js +0 -3
  198. package/web/dist/assets/DeviceCenter-Cl9MBXaH.js +0 -3
  199. package/web/dist/assets/DeviceGroups-aeLD2msl.js +0 -1
  200. package/web/dist/assets/Dropdown-D1Jl35dw.js +0 -1
  201. package/web/dist/assets/FilePreview-6CqoDF_P.js +0 -2
  202. package/web/dist/assets/FilePreview-CJa27G_Q.js +0 -2
  203. package/web/dist/assets/GlobalSearchModal-CJX35rZL.js +0 -1
  204. package/web/dist/assets/GlobalSearchModal-CMW0xz0P.js +0 -1
  205. package/web/dist/assets/GroupConversation-Cq4daBFb.js +0 -1
  206. package/web/dist/assets/GroupConversation-DoELa83U.js +0 -1
  207. package/web/dist/assets/ModelConfigModal-Bp7tfKYh.js +0 -2
  208. package/web/dist/assets/PiSetupModal-DD8srwBJ.js +0 -1
  209. package/web/dist/assets/ProviderOAuthControls-C6tfXb88.js +0 -1
  210. package/web/dist/assets/SCMPanel-CghgsyBN.js +0 -2
  211. package/web/dist/assets/SCMPanel-D8-8aqwC.js +0 -2
  212. package/web/dist/assets/SettingsModal-BbBe2rYo.js +0 -20
  213. package/web/dist/assets/SettingsModal-qETiVPKj.js +0 -20
  214. package/web/dist/assets/TerminalPanel-Da-Xs4Wk.js +0 -3
  215. package/web/dist/assets/TerminalPanel-DnS4tFQO.js +0 -3
  216. package/web/dist/assets/TuiOverlayModal-CGyGkKYl.js +0 -1
  217. package/web/dist/assets/TuiOverlayModal-CpBKjG6x.js +0 -1
  218. package/web/dist/assets/app-globals-DcyO0UPi.js +0 -1
  219. package/web/dist/assets/fi-NyN-ZrgD.js +0 -325
  220. package/web/dist/assets/index-DK3F5ZJo.js +0 -85
  221. package/web/dist/assets/index-DQMii2he.js +0 -85
  222. package/web/dist/assets/index-vwBnwzkr.css +0 -1
  223. package/web/dist/assets/plugin-host-BCnX3P8U.js +0 -1
  224. package/web/dist/assets/theme-D2DMH6tH.js +0 -1
@@ -1,7 +1,10 @@
1
- import { randomUUID } from "node:crypto";
1
+ import { createHash, randomUUID } from "node:crypto";
2
2
  import { resolve } from "node:path";
3
3
  import { transferSummary } from "./transfers.js";
4
4
  import { checkedUrl } from "./relay.js";
5
+ import { validateDeviceCollabInput } from "./collab-tool.js";
6
+ import { getExecutionGuide } from "./execution-guides.js";
7
+ import { getGroupContextMetrics } from "./group-context-message.js";
5
8
  export function createDeviceCollabService(options) {
6
9
  const root = options.root === undefined ? undefined : resolve(options.root);
7
10
  return {
@@ -11,6 +14,54 @@ export function createDeviceCollabService(options) {
11
14
  signal?.throwIfAborted();
12
15
  if (!context)
13
16
  throw new Error("Invalid workspace");
17
+ const bound = options.getExecutionContext?.(context);
18
+ // Resolve authority before workspace acquisition; never mutate caller arguments.
19
+ if ([
20
+ "task_state",
21
+ "task_update",
22
+ "task_evidence",
23
+ "execution_guide",
24
+ "context_metrics",
25
+ "blackboard_read",
26
+ "blackboard_update",
27
+ ].includes(action))
28
+ validateDeviceCollabInput({ ...args, action });
29
+ args = { ...args };
30
+ const boundBot = bound?.botId ?? options.getSourceBot?.(context);
31
+ const parentTaskId = bound?.taskId ?? options.getParentTask?.(context);
32
+ if (args.sourceBotId !== undefined && boundBot && args.sourceBotId !== boundBot)
33
+ throw new Error("Invalid source bot");
34
+ if (args.roomId !== undefined && bound && args.roomId !== bound.roomId)
35
+ throw new Error("Invalid room");
36
+ if (args.parentTaskId !== undefined && args.parentTaskId !== parentTaskId)
37
+ throw new Error("Parent task spoofing denied");
38
+ args.sourceBotId ??= bound?.botId;
39
+ args.roomId ??= bound?.roomId;
40
+ if (action === "conversation_attention" ||
41
+ action === "conversation_deliver" ||
42
+ action === "task_state" ||
43
+ action === "task_update" ||
44
+ action === "task_evidence")
45
+ args.conversationId ??= bound?.conversationId;
46
+ if (action === "reply_to_request") {
47
+ if (!bound || bound.kind !== "request" || !bound.sourceConversationId || !bound.requestId)
48
+ throw new Error("Incoming request binding required");
49
+ if ((args.conversationId !== undefined && args.conversationId !== bound.sourceConversationId) ||
50
+ (args.requestId !== undefined && args.requestId !== bound.requestId) ||
51
+ (args.kind !== undefined && args.kind !== "reply"))
52
+ throw new Error("Reply route mismatch");
53
+ action = "conversation_send";
54
+ args.conversationId = bound.sourceConversationId;
55
+ args.requestId = bound.requestId;
56
+ args.kind = "reply";
57
+ }
58
+ if (action === "task_update" &&
59
+ (!bound?.conversationId || !bound.taskId || args.conversationId !== bound.conversationId))
60
+ throw new Error("Task updates require the bound conversation and task.");
61
+ if (["current_task", "execution_guide", "context_metrics"].includes(action) && !bound)
62
+ throw new Error("Task session binding required");
63
+ if (action === "context_metrics" && !context.sessionId)
64
+ throw new Error("Session binding required");
14
65
  const readOnly = action === "list_bots" || action === "list_rooms";
15
66
  if (!readOnly && !args.sourceBotId)
16
67
  throw new Error("Source bot required");
@@ -35,24 +86,49 @@ export function createDeviceCollabService(options) {
35
86
  throw new Error("Device unavailable");
36
87
  if (!["list_bots", "list_rooms"].includes(action) && !config.allowExecution)
37
88
  throw new Error("Device execution disabled");
89
+ signal?.throwIfAborted();
90
+ if (action === "execution_guide")
91
+ return { topic: args.topic, guide: getExecutionGuide(args.topic) };
92
+ if (action === "context_metrics")
93
+ return getGroupContextMetrics(context.sessionId);
38
94
  const base = checkedUrl(config.hubUrl);
39
95
  if (!["http:", "https:"].includes(base.protocol) || base.search)
40
96
  throw new Error("Invalid hub URL");
41
- const parentTaskId = options.getParentTask?.(context);
42
- const boundBot = options.getSourceBot?.(context);
43
- if (args.sourceBotId && boundBot && args.sourceBotId !== boundBot)
44
- throw new Error("Invalid source bot");
97
+ if (action === "current_task") {
98
+ const result = {};
99
+ if (bound?.taskState)
100
+ result.taskState = bound.taskState;
101
+ for (const key of [
102
+ "roomId",
103
+ "taskId",
104
+ "botId",
105
+ "conversationId",
106
+ "sourceConversationId",
107
+ "requestId",
108
+ "kind",
109
+ ]) {
110
+ const value = bound[key];
111
+ if (value !== undefined) {
112
+ if (typeof value !== "string" || !value || value.length > 256)
113
+ throw new Error("Invalid task binding");
114
+ result[key] = value;
115
+ }
116
+ }
117
+ return result;
118
+ }
45
119
  if (action === "create_room" && options.workspaceResolver) {
46
120
  workspace = await options.workspaceResolver({ roomId: "", sourceBotId: args.sourceBotId, context, signal });
47
121
  if (resolve(context.cwd) !== resolve(workspace.root))
48
122
  throw new Error("Invalid workspace");
49
123
  }
50
- const request = async (path, body) => {
124
+ const request = async (path, body, query, method) => {
51
125
  signal?.throwIfAborted();
52
126
  const url = new URL(base.href);
53
127
  url.pathname = `${url.pathname.replace(/\/$/, "")}/api/agent/${path}`;
128
+ if (query)
129
+ url.search = query.toString();
54
130
  const response = await (options.fetch ?? fetch)(url, {
55
- method: body === undefined ? "GET" : "POST",
131
+ method: method ?? (body === undefined ? "GET" : "POST"),
56
132
  headers: {
57
133
  authorization: `Bearer ${config.credential}`,
58
134
  "X-Device-Id": config.deviceId,
@@ -62,8 +138,17 @@ export function createDeviceCollabService(options) {
62
138
  signal,
63
139
  redirect: "error",
64
140
  });
65
- if (!response.ok)
66
- throw new Error("Hub request failed");
141
+ if (!response.ok) {
142
+ let detail = "";
143
+ try {
144
+ const errBody = (await response.json());
145
+ detail = errBody?.error ? `: ${errBody.error}` : "";
146
+ }
147
+ catch { }
148
+ throw Object.assign(new Error(`Hub request failed (${response.status}${detail})`), {
149
+ status: response.status,
150
+ });
151
+ }
67
152
  const result = await response.json();
68
153
  signal?.throwIfAborted();
69
154
  return result;
@@ -74,12 +159,73 @@ export function createDeviceCollabService(options) {
74
159
  return `rooms/${encodeURIComponent(args.roomId)}`;
75
160
  };
76
161
  switch (action) {
162
+ case "task_state":
163
+ case "task_update": {
164
+ if (!args.conversationId)
165
+ throw new Error("Conversation required");
166
+ const path = `${room()}/conversations/${encodeURIComponent(args.conversationId)}/task-state`;
167
+ if (action === "task_state") {
168
+ const query = new URLSearchParams({ sourceBotId: args.sourceBotId });
169
+ if (args.beforeSequence !== undefined)
170
+ query.set("beforeSequence", String(args.beforeSequence));
171
+ if (args.summaryOnly)
172
+ query.set("summaryOnly", "true");
173
+ return await request(path, undefined, query);
174
+ }
175
+ return await request(path, {
176
+ sourceBotId: args.sourceBotId,
177
+ parentTaskId: bound.taskId,
178
+ expectedRevision: args.expectedRevision,
179
+ ...(args.constraints !== undefined ? { constraints: args.constraints } : {}),
180
+ ...(args.progress !== undefined ? { progress: args.progress } : {}),
181
+ ...(args.blockers !== undefined ? { blockers: args.blockers } : {}),
182
+ ...(args.nextSteps !== undefined ? { nextSteps: args.nextSteps } : {}),
183
+ });
184
+ }
185
+ case "task_evidence": {
186
+ if (!args.conversationId)
187
+ throw new Error("Conversation required");
188
+ const path = `${room()}/conversations/${encodeURIComponent(args.conversationId)}/evidence`;
189
+ const query = new URLSearchParams({ sourceBotId: args.sourceBotId });
190
+ if (args.taskId !== undefined)
191
+ query.set("taskId", args.taskId);
192
+ if (args.deliveryId !== undefined)
193
+ query.set("deliveryId", args.deliveryId);
194
+ if (args.offset !== undefined)
195
+ query.set("offset", String(args.offset));
196
+ if (args.limit !== undefined)
197
+ query.set("limit", String(args.limit));
198
+ if (args.expectedDigest !== undefined)
199
+ query.set("expectedDigest", args.expectedDigest);
200
+ return await request(path, undefined, query);
201
+ }
77
202
  case "list_bots": {
78
203
  const result = (await request("bots"));
79
204
  return { bots: result.bots?.map((bot) => ({ ...bot, local: bot.deviceId === config.deviceId })) ?? [] };
80
205
  }
81
206
  case "list_rooms":
82
207
  return await request("rooms");
208
+ case "blackboard_read": {
209
+ const query = new URLSearchParams({ sourceBotId: args.sourceBotId });
210
+ return await request(`${room()}/blackboard`, undefined, query);
211
+ }
212
+ case "blackboard_update": {
213
+ return await request(`${room()}/blackboard`, {
214
+ sourceBotId: args.sourceBotId,
215
+ content: args.content,
216
+ expectedVersion: args.expectedVersion,
217
+ ...(args.title !== undefined ? { title: args.title } : {}),
218
+ }, undefined, "PUT");
219
+ }
220
+ case "read_history": {
221
+ if (args.before !== undefined &&
222
+ (typeof args.before !== "string" || !args.before.trim() || args.before.length > 256))
223
+ throw new Error("Invalid history cursor");
224
+ const query = new URLSearchParams({ sourceBotId: args.sourceBotId });
225
+ if (args.before !== undefined)
226
+ query.set("before", args.before);
227
+ return await request(`${room()}/history`, undefined, query);
228
+ }
83
229
  case "create_room":
84
230
  if (!args.targetBotId)
85
231
  throw new Error("Target required");
@@ -99,14 +245,192 @@ export function createDeviceCollabService(options) {
99
245
  targetBotIds: [args.targetBotId],
100
246
  idempotencyKey: randomUUID(),
101
247
  ...(parentTaskId ? { parentTaskId } : {}),
248
+ ...(args.resourceLocks?.length ? { resourceLocks: args.resourceLocks } : {}),
249
+ });
250
+ case "conversation_list":
251
+ case "conversation_read": {
252
+ if (action === "conversation_read" && !args.conversationId)
253
+ throw new Error("Conversation required");
254
+ const suffix = action === "conversation_read" ? `/${encodeURIComponent(args.conversationId)}` : "";
255
+ const query = new URLSearchParams({ sourceBotId: args.sourceBotId });
256
+ if (action === "conversation_read" && args.before !== undefined) {
257
+ if (typeof args.before !== "string" || !args.before.trim() || args.before.length > 256)
258
+ throw new Error("Invalid conversation cursor");
259
+ query.set("before", args.before);
260
+ }
261
+ return await request(`${room()}/conversations${suffix}`, undefined, query);
262
+ }
263
+ case "conversation_deliver": {
264
+ if (!args.conversationId ||
265
+ !parentTaskId ||
266
+ !args.repository ||
267
+ !args.baseCommit ||
268
+ !args.commit ||
269
+ !args.summary ||
270
+ !Array.isArray(args.checks))
271
+ throw new Error("Delivery fields required");
272
+ const body = {
273
+ sourceBotId: args.sourceBotId,
274
+ parentTaskId,
275
+ idempotencyKey: args.idempotencyKey ?? randomUUID(),
276
+ repository: args.repository,
277
+ baseCommit: args.baseCommit,
278
+ commit: args.commit,
279
+ branch: args.branch,
280
+ summary: args.summary,
281
+ checks: args.checks,
282
+ limitations: args.limitations ?? [],
283
+ };
284
+ return await request(`${room()}/conversations/${encodeURIComponent(args.conversationId)}/deliveries`, body);
285
+ }
286
+ case "conversation_review": {
287
+ if (!args.conversationId ||
288
+ !parentTaskId ||
289
+ !args.deliveryId ||
290
+ !args.commit ||
291
+ !args.summary ||
292
+ !args.verdict)
293
+ throw new Error("Review fields required");
294
+ const body = {
295
+ sourceBotId: args.sourceBotId,
296
+ parentTaskId,
297
+ idempotencyKey: args.idempotencyKey ?? randomUUID(),
298
+ deliveryId: args.deliveryId,
299
+ commit: args.commit,
300
+ verdict: args.verdict,
301
+ summary: args.summary,
302
+ };
303
+ return await request(`${room()}/conversations/${encodeURIComponent(args.conversationId)}/reviews`, body);
304
+ }
305
+ case "conversation_attention":
306
+ if (!args.conversationId ||
307
+ !args.question ||
308
+ !["answer", "decision"].includes(args.attentionKind ?? "") ||
309
+ !parentTaskId)
310
+ throw new Error("Attention fields required");
311
+ return await request(`${room()}/conversations/${encodeURIComponent(args.conversationId)}/attention`, {
312
+ sourceBotId: args.sourceBotId,
313
+ parentTaskId,
314
+ question: args.question,
315
+ kind: args.attentionKind,
316
+ });
317
+ case "conversation_stop":
318
+ if (!args.conversationId)
319
+ throw new Error("Conversation required");
320
+ return await request(`${room()}/conversations/${encodeURIComponent(args.conversationId)}/stop`, {
321
+ sourceBotId: args.sourceBotId,
322
+ });
323
+ case "conversation_create":
324
+ if (!args.targetBotId ||
325
+ !args.prompt ||
326
+ (args.kind !== undefined && !["message", "request"].includes(args.kind)) ||
327
+ (args.requestId && args.kind !== "request"))
328
+ throw new Error("Conversation fields required");
329
+ return await request(`${room()}/conversations`, {
330
+ targetBotId: args.targetBotId,
331
+ text: args.prompt,
332
+ ...(args.kind ? { kind: args.kind } : {}),
333
+ ...(args.requestId ? { requestId: args.requestId } : {}),
334
+ sourceBotId: args.sourceBotId,
335
+ parentTaskId,
336
+ idempotencyKey: args.idempotencyKey ?? randomUUID(),
337
+ });
338
+ case "conversation_send":
339
+ if (!args.conversationId ||
340
+ !args.message ||
341
+ (args.kind !== undefined && !["message", "request", "reply"].includes(args.kind)) ||
342
+ (args.kind === "reply" && !args.requestId))
343
+ throw new Error("Conversation fields required");
344
+ return await request(`${room()}/conversations/${encodeURIComponent(args.conversationId)}/messages`, {
345
+ text: args.message,
346
+ sourceBotId: args.sourceBotId,
347
+ parentTaskId,
348
+ kind: args.kind ?? "message",
349
+ requestId: args.requestId,
350
+ idempotencyKey: args.idempotencyKey ?? randomUUID(),
351
+ ...(args.resourceLocks?.length ? { resourceLocks: args.resourceLocks } : {}),
102
352
  });
103
353
  case "sync_files": {
104
- if (!args.targetBotId || !args.roomId || !args.paths?.length)
354
+ if (!args.targetBotId || !args.roomId || !args.sourceBotId || !args.paths?.length)
105
355
  throw new Error("Transfer fields required");
106
356
  const files = workspace?.files ?? options.files;
107
357
  if (!files)
108
358
  throw new Error("File workspace unavailable");
109
- const bundle = await files.prepare({ paths: args.paths, signal });
359
+ const transferId = (typeof args.transferId === "string" && args.transferId) ||
360
+ computeStableTransferId(args.roomId, args.sourceBotId, args.targetBotId, args.paths);
361
+ if (typeof files.prepareChunked === "function" && typeof files.readChunk === "function") {
362
+ const manifest = await files.prepareChunked({
363
+ paths: args.paths,
364
+ signal,
365
+ recursive: args.recursive,
366
+ transferId,
367
+ });
368
+ const initResponse = await request("transfers", {
369
+ action: "init",
370
+ roomId: args.roomId,
371
+ sourceBotId: args.sourceBotId,
372
+ targetBotId: args.targetBotId,
373
+ manifest,
374
+ });
375
+ const initSummary = summarizeTransfer(initResponse);
376
+ const activeTransferId = initSummary.transferId;
377
+ if (!activeTransferId)
378
+ throw new Error("Transfer ID missing in init response");
379
+ const receivedSet = new Set(Array.isArray(initSummary.receivedChunks) ? initSummary.receivedChunks : []);
380
+ for (const file of manifest.files) {
381
+ signal?.throwIfAborted();
382
+ for (let c = 0; c < file.chunkCount; c++) {
383
+ signal?.throwIfAborted();
384
+ const chunkIndex = file.firstChunkIndex + c;
385
+ if (receivedSet.has(chunkIndex))
386
+ continue; // Resume skip
387
+ const chunkOffset = c * manifest.chunkSize;
388
+ const chunkSize = Math.min(manifest.chunkSize, file.size - chunkOffset);
389
+ const { buffer, sha256 } = await files.readChunk({
390
+ path: file.path,
391
+ offset: chunkOffset,
392
+ size: chunkSize,
393
+ signal,
394
+ });
395
+ await request("transfers", {
396
+ action: "chunk",
397
+ roomId: args.roomId,
398
+ sourceBotId: args.sourceBotId,
399
+ targetBotId: args.targetBotId,
400
+ transferId: activeTransferId,
401
+ chunk: {
402
+ transferId: activeTransferId,
403
+ chunkIndex,
404
+ path: file.path,
405
+ offset: chunkOffset,
406
+ size: buffer.length,
407
+ sha256,
408
+ data: buffer.toString("base64"),
409
+ },
410
+ });
411
+ receivedSet.add(chunkIndex);
412
+ }
413
+ }
414
+ const previewResponse = await request("transfers", {
415
+ action: "preview",
416
+ roomId: args.roomId,
417
+ sourceBotId: args.sourceBotId,
418
+ targetBotId: args.targetBotId,
419
+ transferId: activeTransferId,
420
+ });
421
+ return {
422
+ ...summarizeTransfer(previewResponse),
423
+ transferId: activeTransferId,
424
+ status: "staged",
425
+ totalFiles: manifest.totalFiles,
426
+ totalBytes: manifest.totalBytes,
427
+ totalChunks: manifest.totalChunks,
428
+ ...(manifest.exclusions
429
+ ? { exclusions: manifest.exclusions, totalExcluded: manifest.totalExcluded }
430
+ : {}),
431
+ };
432
+ }
433
+ const bundle = await files.prepare({ paths: args.paths, signal, recursive: args.recursive });
110
434
  const response = await request("transfers", {
111
435
  action: "stage",
112
436
  roomId: args.roomId,
@@ -114,7 +438,24 @@ export function createDeviceCollabService(options) {
114
438
  targetBotId: args.targetBotId,
115
439
  bundle,
116
440
  });
117
- return summarizeTransfer(response);
441
+ return {
442
+ ...summarizeTransfer(response),
443
+ ...(bundle.manifest.exclusions
444
+ ? { exclusions: bundle.manifest.exclusions, totalExcluded: bundle.manifest.totalExcluded }
445
+ : {}),
446
+ };
447
+ }
448
+ case "transfer_status":
449
+ case "transfer_abort": {
450
+ if (!args.roomId || !args.targetBotId || !args.transferId)
451
+ throw new Error("Transfer fields required");
452
+ return summarizeTransfer(await request("transfers", {
453
+ action: action === "transfer_status" ? "status" : "abort",
454
+ roomId: args.roomId,
455
+ sourceBotId: args.sourceBotId,
456
+ targetBotId: args.targetBotId,
457
+ transferId: args.transferId,
458
+ }));
118
459
  }
119
460
  case "transfer_preview":
120
461
  case "transfer_apply": {
@@ -149,5 +490,13 @@ export function createDeviceCollabService(options) {
149
490
  }
150
491
  function summarizeTransfer(value) {
151
492
  const id = value && typeof value === "object" ? value.transferId : undefined;
152
- return { ...transferSummary(value), ...(typeof id === "string" ? { transferId: id } : {}) };
493
+ return {
494
+ ...transferSummary(value),
495
+ ...(typeof id === "string" ? { transferId: id } : {}),
496
+ };
497
+ }
498
+ function computeStableTransferId(roomId, sourceBotId, targetBotId, paths) {
499
+ const raw = `${roomId}:${sourceBotId}:${targetBotId}:${[...paths].sort().join(",")}`;
500
+ const h = createHash("sha256").update(raw).digest("hex");
501
+ return `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-8${h.slice(17, 20)}-${h.slice(20, 32)}`;
153
502
  }