pi-web-ui 0.114.2 → 0.115.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 (195) hide show
  1. package/CHANGELOG.md +55 -1
  2. package/bin/pi-web-ui.mjs +69 -7
  3. package/dist/server/agent-service-daemon.js +440 -32
  4. package/dist/server/agent-service.js +878 -383
  5. package/dist/server/canvas/canvas-dispatch.js +13 -1
  6. package/dist/server/client-state.js +25 -0
  7. package/dist/server/communicate-tool.js +2 -0
  8. package/dist/server/context-usage.js +105 -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 +72 -9
  14. package/dist/server/device-center/bot-presets.js +46 -0
  15. package/dist/server/device-center/collab-service.js +328 -10
  16. package/dist/server/device-center/collab-tool.js +738 -12
  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 +19 -0
  22. package/dist/server/device-center/execution-settings.js +100 -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 +389 -40
  26. package/dist/server/device-center/file-sync-paths.js +171 -0
  27. package/dist/server/device-center/file-sync.js +180 -91
  28. package/dist/server/device-center/group-context-delta.js +37 -0
  29. package/dist/server/device-center/group-context-message.js +208 -0
  30. package/dist/server/device-center/group-context.js +109 -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 +178 -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.js +1544 -80
  37. package/dist/server/device-center/human-interaction.js +232 -0
  38. package/dist/server/device-center/integration-errors.js +25 -0
  39. package/dist/server/device-center/local-hub.js +18 -0
  40. package/dist/server/device-center/local.js +356 -40
  41. package/dist/server/device-center/main.js +11 -1
  42. package/dist/server/device-center/path-portal.js +11 -3
  43. package/dist/server/device-center/relay.js +364 -35
  44. package/dist/server/device-center/report-metadata.js +66 -0
  45. package/dist/server/device-center/report-upload.js +63 -0
  46. package/dist/server/device-center/runtime.js +549 -41
  47. package/dist/server/device-center/store.js +66 -3
  48. package/dist/server/device-center/task-context-budget.js +161 -0
  49. package/dist/server/device-center/task-journal.js +385 -0
  50. package/dist/server/device-center/task-plan.js +33 -0
  51. package/dist/server/device-center/task-progress.js +141 -0
  52. package/dist/server/device-center/task-recovery.js +452 -0
  53. package/dist/server/device-center/task-report-outbox.js +216 -0
  54. package/dist/server/device-center/task-report.js +384 -0
  55. package/dist/server/device-center/task-scheduler.js +400 -0
  56. package/dist/server/device-center/task-state.js +333 -0
  57. package/dist/server/device-center/transfer-stream.js +1006 -0
  58. package/dist/server/device-center/transfers.js +815 -8
  59. package/dist/server/dispatch-domain-handlers.js +21 -3
  60. package/dist/server/dsh/dsh-agent-service.js +6 -0
  61. package/dist/server/goal-service.js +10 -5
  62. package/dist/server/index.js +89 -13
  63. package/dist/server/message-deletion.js +40 -0
  64. package/dist/server/message-window.js +9 -0
  65. package/dist/server/patch-executable-lookup.js +396 -0
  66. package/dist/server/payload-limits.js +2 -0
  67. package/dist/server/plugin-llm.js +100 -9
  68. package/dist/server/plugins.js +1 -0
  69. package/dist/server/preset-fields.js +24 -0
  70. package/dist/server/preset-share.js +2 -0
  71. package/dist/server/prompt-base-store.js +85 -0
  72. package/dist/server/prompt-composer.js +5 -2
  73. package/dist/server/protocol-version.js +1 -1
  74. package/dist/server/protocol.js +2 -2
  75. package/dist/server/remote-ssh-service.js +22 -9
  76. package/dist/server/resolve-global-sdk.js +2 -0
  77. package/dist/server/session-search.js +1 -1
  78. package/dist/server/settings-service.js +90 -39
  79. package/dist/server/skill-content-filler.js +29 -8
  80. package/dist/server/skill-tool.js +12 -3
  81. package/dist/server/subagent-helpers.js +4 -1
  82. package/dist/server/subagents.js +50 -36
  83. package/dist/server/tool-host-factories.js +1 -0
  84. package/dist/server/universal/universal-session.js +5 -0
  85. package/dist/server/webui-context.js +25 -5
  86. package/docs/README.md +94 -0
  87. package/docs/device-center.md +100 -12
  88. package/docs/dsh-engine.md +10 -10
  89. package/extensions/webui.ts +43 -1
  90. package/package.json +1 -1
  91. package/themes/aetheris.css +5 -0
  92. package/themes/ayu-light.css +6 -0
  93. package/themes/bases/flow-base.css +68 -68
  94. package/themes/catppuccin-latte.css +6 -0
  95. package/themes/catppuccin.css +6 -0
  96. package/themes/claude-code-dark.css +5 -0
  97. package/themes/codex.css +6 -0
  98. package/themes/cyberpunk.css +6 -0
  99. package/themes/dark-teal.css +6 -1
  100. package/themes/dazzle.css +6 -0
  101. package/themes/everforest-light.css +6 -0
  102. package/themes/flow-light.css +8 -1
  103. package/themes/flow.css +6 -1
  104. package/themes/geist.css +6 -0
  105. package/themes/gruvbox-light.css +6 -0
  106. package/themes/kanagawa-lotus.css +6 -0
  107. package/themes/md-preview.css +6 -0
  108. package/themes/mist.css +6 -0
  109. package/themes/nord.css +6 -0
  110. package/themes/one-dark.css +6 -0
  111. package/themes/paper.css +6 -0
  112. package/themes/rose-pine-dawn.css +6 -0
  113. package/themes/sakura.css +6 -0
  114. package/themes/solarized-light.css +6 -0
  115. package/themes/tokyo-night.css +6 -0
  116. package/themes/translucent.css +6 -0
  117. package/themes/transparent.css +6 -0
  118. package/themes/vs-code-dark.css +5 -0
  119. package/themes/wallpaper-flow.css +5 -1
  120. package/themes/wallpaper-obsidian.css +6 -0
  121. package/themes/white.css +6 -0
  122. package/themes/zhujian-dark.css +6 -1
  123. package/themes/zhujian.css +6 -1
  124. package/themes/zhupi-dark.css +6 -1
  125. package/themes/zhupi.css +6 -1
  126. package/web/dist/.build-assets.json +1 -1
  127. package/web/dist/assets/BgTasksModal-BYzPgmoq.js +1 -0
  128. package/web/dist/assets/BgTasksModal-ni0VTmAQ.js +1 -0
  129. package/web/dist/assets/{CanvasStudio-B3W6b_rA.js → CanvasStudio-BCUeEf25.js} +3 -3
  130. package/web/dist/assets/{CanvasStudio-Csv1Sj1-.js → CanvasStudio-DNmDNBod.js} +3 -3
  131. package/web/dist/assets/DeviceCenter-BcBhRgL6.js +3 -0
  132. package/web/dist/assets/DeviceCenter-CmL5FZmt.js +3 -0
  133. package/web/dist/assets/DeviceGroups-CLdpdnI7.js +1 -0
  134. package/web/dist/assets/DeviceGroups-CgBaDPrD.js +1 -0
  135. package/web/dist/assets/Dropdown-CGXD0DfT.js +1 -0
  136. package/web/dist/assets/FilePreview-B8iqnBjy.js +2 -0
  137. package/web/dist/assets/FilePreview-BqviZKCN.js +2 -0
  138. package/web/dist/assets/GlobalSearchModal-mevF-ySi.js +1 -0
  139. package/web/dist/assets/GlobalSearchModal-qL99FN_F.js +1 -0
  140. package/web/dist/assets/GroupConversation-B88Yy-lt.js +3 -0
  141. package/web/dist/assets/GroupConversation-BwP5NVOE.js +3 -0
  142. package/web/dist/assets/HintTip-LHwkS2jV.js +1 -0
  143. package/web/dist/assets/ModelConfigModal-Do3Fe3jH.js +2 -0
  144. package/web/dist/assets/PiSetupModal-DE5-gEtI.js +1 -0
  145. package/web/dist/assets/ProviderOAuthControls-6UMARucA.js +1 -0
  146. package/web/dist/assets/SCMPanel-Hi6QqC1Q.js +2 -0
  147. package/web/dist/assets/SCMPanel-ezY_ZtCu.js +2 -0
  148. package/web/dist/assets/SettingsModal-6HgeEsJ8.js +20 -0
  149. package/web/dist/assets/SettingsModal-CF-7MwqS.js +20 -0
  150. package/web/dist/assets/TerminalPanel-CTp_BZ4S.js +3 -0
  151. package/web/dist/assets/TerminalPanel-CkYxC-Gh.js +3 -0
  152. package/web/dist/assets/TuiOverlayModal-1cRLP8IF.js +1 -0
  153. package/web/dist/assets/TuiOverlayModal-2xlptqWX.js +1 -0
  154. package/web/dist/assets/app-globals-DZNa9v8u.js +325 -0
  155. package/web/dist/assets/canvas-client-Bye9nSFO.js +1 -0
  156. package/web/dist/assets/{desktop-YguLbrX1.js → desktop-kjBoE3Nu.js} +1 -1
  157. package/web/dist/assets/group-view-state-CGCzYF8k.js +1 -0
  158. package/web/dist/assets/index-CsFs_HMb.css +1 -0
  159. package/web/dist/assets/index-DHeeHS_l.js +85 -0
  160. package/web/dist/assets/index-DTZch8uz.js +85 -0
  161. package/web/dist/assets/plugin-host-C8mNgghx.js +1 -0
  162. package/web/dist/assets/remote-ssh-client-CeP3CLUW.js +1 -0
  163. package/web/dist/assets/theme-BXGpyTMh.js +1 -0
  164. package/web/dist/index.html +10 -9
  165. package/web/dist/sw.js +1 -1
  166. package/web/dist/assets/BgTasksModal-BIlQ89vr.js +0 -1
  167. package/web/dist/assets/BgTasksModal-Ck2sjlPM.js +0 -1
  168. package/web/dist/assets/DeviceCenter-BQdDcO8A.js +0 -3
  169. package/web/dist/assets/DeviceCenter-CHRKL0Vy.js +0 -3
  170. package/web/dist/assets/DeviceGroups-D2rogxEN.js +0 -1
  171. package/web/dist/assets/Dropdown-ZLS04O8p.js +0 -1
  172. package/web/dist/assets/FilePreview-B9xoU6ON.js +0 -2
  173. package/web/dist/assets/FilePreview-DUQpVZkH.js +0 -2
  174. package/web/dist/assets/GlobalSearchModal-BXEGvUZq.js +0 -1
  175. package/web/dist/assets/GlobalSearchModal-CnVPmfOI.js +0 -1
  176. package/web/dist/assets/GroupConversation-CyIpQzDd.js +0 -1
  177. package/web/dist/assets/GroupConversation-DgYV3uYS.js +0 -1
  178. package/web/dist/assets/ModelConfigModal-DDZccDYt.js +0 -2
  179. package/web/dist/assets/PiSetupModal-DHbqfx8T.js +0 -1
  180. package/web/dist/assets/ProviderOAuthControls-C-MK36Dk.js +0 -1
  181. package/web/dist/assets/SCMPanel-imYI2Ecw.js +0 -2
  182. package/web/dist/assets/SCMPanel-sVZcV7dR.js +0 -2
  183. package/web/dist/assets/SettingsModal-Xw1Yoi3_.js +0 -20
  184. package/web/dist/assets/SettingsModal-mb4e34-0.js +0 -20
  185. package/web/dist/assets/TerminalPanel-CLkJJvxg.js +0 -3
  186. package/web/dist/assets/TerminalPanel-DpcIellm.js +0 -3
  187. package/web/dist/assets/TuiOverlayModal-4-fFAZe7.js +0 -1
  188. package/web/dist/assets/TuiOverlayModal-DCu01lks.js +0 -1
  189. package/web/dist/assets/app-globals-DcyO0UPi.js +0 -1
  190. package/web/dist/assets/fi-DaSO0Q-m.js +0 -325
  191. package/web/dist/assets/index-Cdh3sibd.js +0 -85
  192. package/web/dist/assets/index-DDZMv6LO.css +0 -1
  193. package/web/dist/assets/index-DWw_SxRq.js +0 -85
  194. package/web/dist/assets/plugin-host-BRBg6zmQ.js +0 -1
  195. package/web/dist/assets/theme-DDl-Oy1b.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,46 @@ 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 (["task_state", "task_update", "task_evidence", "execution_guide", "context_metrics"].includes(action))
20
+ validateDeviceCollabInput({ ...args, action });
21
+ args = { ...args };
22
+ const boundBot = bound?.botId ?? options.getSourceBot?.(context);
23
+ const parentTaskId = bound?.taskId ?? options.getParentTask?.(context);
24
+ if (args.sourceBotId !== undefined && boundBot && args.sourceBotId !== boundBot)
25
+ throw new Error("Invalid source bot");
26
+ if (args.roomId !== undefined && bound && args.roomId !== bound.roomId)
27
+ throw new Error("Invalid room");
28
+ if (args.parentTaskId !== undefined && args.parentTaskId !== parentTaskId)
29
+ throw new Error("Parent task spoofing denied");
30
+ args.sourceBotId ??= bound?.botId;
31
+ args.roomId ??= bound?.roomId;
32
+ if (action === "conversation_attention" ||
33
+ action === "conversation_deliver" ||
34
+ action === "task_state" ||
35
+ action === "task_update" ||
36
+ action === "task_evidence")
37
+ args.conversationId ??= bound?.conversationId;
38
+ if (action === "reply_to_request") {
39
+ if (!bound || bound.kind !== "request" || !bound.sourceConversationId || !bound.requestId)
40
+ throw new Error("Incoming request binding required");
41
+ if ((args.conversationId !== undefined && args.conversationId !== bound.sourceConversationId) ||
42
+ (args.requestId !== undefined && args.requestId !== bound.requestId) ||
43
+ (args.kind !== undefined && args.kind !== "reply"))
44
+ throw new Error("Reply route mismatch");
45
+ action = "conversation_send";
46
+ args.conversationId = bound.sourceConversationId;
47
+ args.requestId = bound.requestId;
48
+ args.kind = "reply";
49
+ }
50
+ if (action === "task_update" &&
51
+ (!bound?.conversationId || !bound.taskId || args.conversationId !== bound.conversationId))
52
+ throw new Error("Task updates require the bound conversation and task.");
53
+ if (["current_task", "execution_guide", "context_metrics"].includes(action) && !bound)
54
+ throw new Error("Task session binding required");
55
+ if (action === "context_metrics" && !context.sessionId)
56
+ throw new Error("Session binding required");
14
57
  const readOnly = action === "list_bots" || action === "list_rooms";
15
58
  if (!readOnly && !args.sourceBotId)
16
59
  throw new Error("Source bot required");
@@ -35,22 +78,47 @@ export function createDeviceCollabService(options) {
35
78
  throw new Error("Device unavailable");
36
79
  if (!["list_bots", "list_rooms"].includes(action) && !config.allowExecution)
37
80
  throw new Error("Device execution disabled");
81
+ signal?.throwIfAborted();
82
+ if (action === "execution_guide")
83
+ return { topic: args.topic, guide: getExecutionGuide(args.topic) };
84
+ if (action === "context_metrics")
85
+ return getGroupContextMetrics(context.sessionId);
38
86
  const base = checkedUrl(config.hubUrl);
39
87
  if (!["http:", "https:"].includes(base.protocol) || base.search)
40
88
  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");
89
+ if (action === "current_task") {
90
+ const result = {};
91
+ if (bound?.taskState)
92
+ result.taskState = bound.taskState;
93
+ for (const key of [
94
+ "roomId",
95
+ "taskId",
96
+ "botId",
97
+ "conversationId",
98
+ "sourceConversationId",
99
+ "requestId",
100
+ "kind",
101
+ ]) {
102
+ const value = bound[key];
103
+ if (value !== undefined) {
104
+ if (typeof value !== "string" || !value || value.length > 256)
105
+ throw new Error("Invalid task binding");
106
+ result[key] = value;
107
+ }
108
+ }
109
+ return result;
110
+ }
45
111
  if (action === "create_room" && options.workspaceResolver) {
46
112
  workspace = await options.workspaceResolver({ roomId: "", sourceBotId: args.sourceBotId, context, signal });
47
113
  if (resolve(context.cwd) !== resolve(workspace.root))
48
114
  throw new Error("Invalid workspace");
49
115
  }
50
- const request = async (path, body) => {
116
+ const request = async (path, body, query) => {
51
117
  signal?.throwIfAborted();
52
118
  const url = new URL(base.href);
53
119
  url.pathname = `${url.pathname.replace(/\/$/, "")}/api/agent/${path}`;
120
+ if (query)
121
+ url.search = query.toString();
54
122
  const response = await (options.fetch ?? fetch)(url, {
55
123
  method: body === undefined ? "GET" : "POST",
56
124
  headers: {
@@ -74,12 +142,61 @@ export function createDeviceCollabService(options) {
74
142
  return `rooms/${encodeURIComponent(args.roomId)}`;
75
143
  };
76
144
  switch (action) {
145
+ case "task_state":
146
+ case "task_update": {
147
+ if (!args.conversationId)
148
+ throw new Error("Conversation required");
149
+ const path = `${room()}/conversations/${encodeURIComponent(args.conversationId)}/task-state`;
150
+ if (action === "task_state") {
151
+ const query = new URLSearchParams({ sourceBotId: args.sourceBotId });
152
+ if (args.beforeSequence !== undefined)
153
+ query.set("beforeSequence", String(args.beforeSequence));
154
+ if (args.summaryOnly)
155
+ query.set("summaryOnly", "true");
156
+ return await request(path, undefined, query);
157
+ }
158
+ return await request(path, {
159
+ sourceBotId: args.sourceBotId,
160
+ parentTaskId: bound.taskId,
161
+ expectedRevision: args.expectedRevision,
162
+ ...(args.constraints !== undefined ? { constraints: args.constraints } : {}),
163
+ ...(args.progress !== undefined ? { progress: args.progress } : {}),
164
+ ...(args.blockers !== undefined ? { blockers: args.blockers } : {}),
165
+ ...(args.nextSteps !== undefined ? { nextSteps: args.nextSteps } : {}),
166
+ });
167
+ }
168
+ case "task_evidence": {
169
+ if (!args.conversationId)
170
+ throw new Error("Conversation required");
171
+ const path = `${room()}/conversations/${encodeURIComponent(args.conversationId)}/evidence`;
172
+ const query = new URLSearchParams({ sourceBotId: args.sourceBotId });
173
+ if (args.taskId !== undefined)
174
+ query.set("taskId", args.taskId);
175
+ if (args.deliveryId !== undefined)
176
+ query.set("deliveryId", args.deliveryId);
177
+ if (args.offset !== undefined)
178
+ query.set("offset", String(args.offset));
179
+ if (args.limit !== undefined)
180
+ query.set("limit", String(args.limit));
181
+ if (args.expectedDigest !== undefined)
182
+ query.set("expectedDigest", args.expectedDigest);
183
+ return await request(path, undefined, query);
184
+ }
77
185
  case "list_bots": {
78
186
  const result = (await request("bots"));
79
187
  return { bots: result.bots?.map((bot) => ({ ...bot, local: bot.deviceId === config.deviceId })) ?? [] };
80
188
  }
81
189
  case "list_rooms":
82
190
  return await request("rooms");
191
+ case "read_history": {
192
+ if (args.before !== undefined &&
193
+ (typeof args.before !== "string" || !args.before.trim() || args.before.length > 256))
194
+ throw new Error("Invalid history cursor");
195
+ const query = new URLSearchParams({ sourceBotId: args.sourceBotId });
196
+ if (args.before !== undefined)
197
+ query.set("before", args.before);
198
+ return await request(`${room()}/history`, undefined, query);
199
+ }
83
200
  case "create_room":
84
201
  if (!args.targetBotId)
85
202
  throw new Error("Target required");
@@ -100,13 +217,189 @@ export function createDeviceCollabService(options) {
100
217
  idempotencyKey: randomUUID(),
101
218
  ...(parentTaskId ? { parentTaskId } : {}),
102
219
  });
220
+ case "conversation_list":
221
+ case "conversation_read": {
222
+ if (action === "conversation_read" && !args.conversationId)
223
+ throw new Error("Conversation required");
224
+ const suffix = action === "conversation_read" ? `/${encodeURIComponent(args.conversationId)}` : "";
225
+ const query = new URLSearchParams({ sourceBotId: args.sourceBotId });
226
+ if (action === "conversation_read" && args.before !== undefined) {
227
+ if (typeof args.before !== "string" || !args.before.trim() || args.before.length > 256)
228
+ throw new Error("Invalid conversation cursor");
229
+ query.set("before", args.before);
230
+ }
231
+ return await request(`${room()}/conversations${suffix}`, undefined, query);
232
+ }
233
+ case "conversation_deliver": {
234
+ if (!args.conversationId ||
235
+ !parentTaskId ||
236
+ !args.repository ||
237
+ !args.baseCommit ||
238
+ !args.commit ||
239
+ !args.summary ||
240
+ !Array.isArray(args.checks))
241
+ throw new Error("Delivery fields required");
242
+ const body = {
243
+ sourceBotId: args.sourceBotId,
244
+ parentTaskId,
245
+ idempotencyKey: args.idempotencyKey ?? randomUUID(),
246
+ repository: args.repository,
247
+ baseCommit: args.baseCommit,
248
+ commit: args.commit,
249
+ branch: args.branch,
250
+ summary: args.summary,
251
+ checks: args.checks,
252
+ limitations: args.limitations ?? [],
253
+ };
254
+ return await request(`${room()}/conversations/${encodeURIComponent(args.conversationId)}/deliveries`, body);
255
+ }
256
+ case "conversation_review": {
257
+ if (!args.conversationId ||
258
+ !parentTaskId ||
259
+ !args.deliveryId ||
260
+ !args.commit ||
261
+ !args.summary ||
262
+ !args.verdict)
263
+ throw new Error("Review fields required");
264
+ const body = {
265
+ sourceBotId: args.sourceBotId,
266
+ parentTaskId,
267
+ idempotencyKey: args.idempotencyKey ?? randomUUID(),
268
+ deliveryId: args.deliveryId,
269
+ commit: args.commit,
270
+ verdict: args.verdict,
271
+ summary: args.summary,
272
+ };
273
+ return await request(`${room()}/conversations/${encodeURIComponent(args.conversationId)}/reviews`, body);
274
+ }
275
+ case "conversation_attention":
276
+ if (!args.conversationId ||
277
+ !args.question ||
278
+ !["answer", "decision"].includes(args.attentionKind ?? "") ||
279
+ !parentTaskId)
280
+ throw new Error("Attention fields required");
281
+ return await request(`${room()}/conversations/${encodeURIComponent(args.conversationId)}/attention`, {
282
+ sourceBotId: args.sourceBotId,
283
+ parentTaskId,
284
+ question: args.question,
285
+ kind: args.attentionKind,
286
+ });
287
+ case "conversation_stop":
288
+ if (!args.conversationId)
289
+ throw new Error("Conversation required");
290
+ return await request(`${room()}/conversations/${encodeURIComponent(args.conversationId)}/stop`, {
291
+ sourceBotId: args.sourceBotId,
292
+ });
293
+ case "conversation_create":
294
+ if (!args.targetBotId ||
295
+ !args.prompt ||
296
+ (args.kind !== undefined && !["message", "request"].includes(args.kind)) ||
297
+ (args.requestId && args.kind !== "request"))
298
+ throw new Error("Conversation fields required");
299
+ return await request(`${room()}/conversations`, {
300
+ targetBotId: args.targetBotId,
301
+ text: args.prompt,
302
+ ...(args.kind ? { kind: args.kind } : {}),
303
+ ...(args.requestId ? { requestId: args.requestId } : {}),
304
+ sourceBotId: args.sourceBotId,
305
+ parentTaskId,
306
+ idempotencyKey: args.idempotencyKey ?? randomUUID(),
307
+ });
308
+ case "conversation_send":
309
+ if (!args.conversationId ||
310
+ !args.message ||
311
+ (args.kind !== undefined && !["message", "request", "reply"].includes(args.kind)) ||
312
+ (args.kind === "reply" && !args.requestId))
313
+ throw new Error("Conversation fields required");
314
+ return await request(`${room()}/conversations/${encodeURIComponent(args.conversationId)}/messages`, {
315
+ text: args.message,
316
+ sourceBotId: args.sourceBotId,
317
+ parentTaskId,
318
+ kind: args.kind ?? "message",
319
+ requestId: args.requestId,
320
+ idempotencyKey: args.idempotencyKey ?? randomUUID(),
321
+ });
103
322
  case "sync_files": {
104
- if (!args.targetBotId || !args.roomId || !args.paths?.length)
323
+ if (!args.targetBotId || !args.roomId || !args.sourceBotId || !args.paths?.length)
105
324
  throw new Error("Transfer fields required");
106
325
  const files = workspace?.files ?? options.files;
107
326
  if (!files)
108
327
  throw new Error("File workspace unavailable");
109
- const bundle = await files.prepare({ paths: args.paths, signal });
328
+ const transferId = (typeof args.transferId === "string" && args.transferId) ||
329
+ computeStableTransferId(args.roomId, args.sourceBotId, args.targetBotId, args.paths);
330
+ if (typeof files.prepareChunked === "function" && typeof files.readChunk === "function") {
331
+ const manifest = await files.prepareChunked({
332
+ paths: args.paths,
333
+ signal,
334
+ recursive: args.recursive,
335
+ transferId,
336
+ });
337
+ const initResponse = await request("transfers", {
338
+ action: "init",
339
+ roomId: args.roomId,
340
+ sourceBotId: args.sourceBotId,
341
+ targetBotId: args.targetBotId,
342
+ manifest,
343
+ });
344
+ const initSummary = summarizeTransfer(initResponse);
345
+ const activeTransferId = initSummary.transferId;
346
+ if (!activeTransferId)
347
+ throw new Error("Transfer ID missing in init response");
348
+ const receivedSet = new Set(Array.isArray(initSummary.receivedChunks) ? initSummary.receivedChunks : []);
349
+ for (const file of manifest.files) {
350
+ signal?.throwIfAborted();
351
+ for (let c = 0; c < file.chunkCount; c++) {
352
+ signal?.throwIfAborted();
353
+ const chunkIndex = file.firstChunkIndex + c;
354
+ if (receivedSet.has(chunkIndex))
355
+ continue; // Resume skip
356
+ const chunkOffset = c * manifest.chunkSize;
357
+ const chunkSize = Math.min(manifest.chunkSize, file.size - chunkOffset);
358
+ const { buffer, sha256 } = await files.readChunk({
359
+ path: file.path,
360
+ offset: chunkOffset,
361
+ size: chunkSize,
362
+ signal,
363
+ });
364
+ await request("transfers", {
365
+ action: "chunk",
366
+ roomId: args.roomId,
367
+ sourceBotId: args.sourceBotId,
368
+ targetBotId: args.targetBotId,
369
+ transferId: activeTransferId,
370
+ chunk: {
371
+ transferId: activeTransferId,
372
+ chunkIndex,
373
+ path: file.path,
374
+ offset: chunkOffset,
375
+ size: buffer.length,
376
+ sha256,
377
+ data: buffer.toString("base64"),
378
+ },
379
+ });
380
+ receivedSet.add(chunkIndex);
381
+ }
382
+ }
383
+ const previewResponse = await request("transfers", {
384
+ action: "preview",
385
+ roomId: args.roomId,
386
+ sourceBotId: args.sourceBotId,
387
+ targetBotId: args.targetBotId,
388
+ transferId: activeTransferId,
389
+ });
390
+ return {
391
+ ...summarizeTransfer(previewResponse),
392
+ transferId: activeTransferId,
393
+ status: "staged",
394
+ totalFiles: manifest.totalFiles,
395
+ totalBytes: manifest.totalBytes,
396
+ totalChunks: manifest.totalChunks,
397
+ ...(manifest.exclusions
398
+ ? { exclusions: manifest.exclusions, totalExcluded: manifest.totalExcluded }
399
+ : {}),
400
+ };
401
+ }
402
+ const bundle = await files.prepare({ paths: args.paths, signal, recursive: args.recursive });
110
403
  const response = await request("transfers", {
111
404
  action: "stage",
112
405
  roomId: args.roomId,
@@ -114,7 +407,24 @@ export function createDeviceCollabService(options) {
114
407
  targetBotId: args.targetBotId,
115
408
  bundle,
116
409
  });
117
- return summarizeTransfer(response);
410
+ return {
411
+ ...summarizeTransfer(response),
412
+ ...(bundle.manifest.exclusions
413
+ ? { exclusions: bundle.manifest.exclusions, totalExcluded: bundle.manifest.totalExcluded }
414
+ : {}),
415
+ };
416
+ }
417
+ case "transfer_status":
418
+ case "transfer_abort": {
419
+ if (!args.roomId || !args.targetBotId || !args.transferId)
420
+ throw new Error("Transfer fields required");
421
+ return summarizeTransfer(await request("transfers", {
422
+ action: action === "transfer_status" ? "status" : "abort",
423
+ roomId: args.roomId,
424
+ sourceBotId: args.sourceBotId,
425
+ targetBotId: args.targetBotId,
426
+ transferId: args.transferId,
427
+ }));
118
428
  }
119
429
  case "transfer_preview":
120
430
  case "transfer_apply": {
@@ -149,5 +459,13 @@ export function createDeviceCollabService(options) {
149
459
  }
150
460
  function summarizeTransfer(value) {
151
461
  const id = value && typeof value === "object" ? value.transferId : undefined;
152
- return { ...transferSummary(value), ...(typeof id === "string" ? { transferId: id } : {}) };
462
+ return {
463
+ ...transferSummary(value),
464
+ ...(typeof id === "string" ? { transferId: id } : {}),
465
+ };
466
+ }
467
+ function computeStableTransferId(roomId, sourceBotId, targetBotId, paths) {
468
+ const raw = `${roomId}:${sourceBotId}:${targetBotId}:${[...paths].sort().join(",")}`;
469
+ const h = createHash("sha256").update(raw).digest("hex");
470
+ return `${h.slice(0, 8)}-${h.slice(8, 12)}-4${h.slice(13, 16)}-8${h.slice(17, 20)}-${h.slice(20, 32)}`;
153
471
  }