pi-web-ui 0.115.0 → 0.117.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.
- package/CHANGELOG.md +65 -2
- package/bin/device-hub-cli.mjs +26 -3
- package/bin/pi-web-ui.mjs +159 -71
- package/dist/server/agent-service-daemon.js +136 -8
- package/dist/server/agent-service.js +594 -159
- package/dist/server/canvas/canvas-workspace.js +18 -86
- package/dist/server/client-state.js +52 -8
- package/dist/server/compaction-markers.js +43 -24
- package/dist/server/dangling-tools.js +172 -16
- package/dist/server/device-center/bot-execution.js +77 -2
- package/dist/server/device-center/collab-service.js +61 -12
- package/dist/server/device-center/collab-tool.js +482 -21
- package/dist/server/device-center/connector.js +107 -37
- package/dist/server/device-center/delivery-authority.js +98 -0
- package/dist/server/device-center/delivery-subject.js +30 -0
- package/dist/server/device-center/device-integration.js +453 -183
- package/dist/server/device-center/execution-guides.js +17 -7
- package/dist/server/device-center/execution-instructions.js +2 -1
- package/dist/server/device-center/execution-settings.js +138 -25
- package/dist/server/device-center/executor.js +51 -6
- package/dist/server/device-center/file-sync.js +14 -13
- package/dist/server/device-center/group-context-message.js +3 -1
- package/dist/server/device-center/group-context.js +73 -3
- package/dist/server/device-center/hub-conversations.js +71 -6
- package/dist/server/device-center/hub-deliveries.js +120 -15
- package/dist/server/device-center/hub-integration.js +655 -334
- package/dist/server/device-center/hub-locks.js +320 -0
- package/dist/server/device-center/hub-page.js +16 -35
- package/dist/server/device-center/hub-setup.js +23 -1
- package/dist/server/device-center/hub-transaction-log.js +197 -0
- package/dist/server/device-center/hub-webhooks.js +165 -0
- package/dist/server/device-center/hub.js +1531 -305
- package/dist/server/device-center/integration-verification.js +113 -0
- package/dist/server/device-center/local-hub.js +8 -3
- package/dist/server/device-center/local-publication.js +423 -0
- package/dist/server/device-center/local-verification-job.js +97 -0
- package/dist/server/device-center/local-verification.js +274 -0
- package/dist/server/device-center/local.js +181 -13
- package/dist/server/device-center/main.js +4 -1
- package/dist/server/device-center/partition-log.js +330 -0
- package/dist/server/device-center/publication-journal.js +312 -0
- package/dist/server/device-center/publish-intent.js +379 -0
- package/dist/server/device-center/relay.js +134 -24
- package/dist/server/device-center/runtime.js +475 -42
- package/dist/server/device-center/store.js +366 -89
- package/dist/server/device-center/task-outcome.js +81 -0
- package/dist/server/device-center/task-recovery.js +603 -178
- package/dist/server/device-center/task-scheduler.js +48 -3
- package/dist/server/device-center/task-settlement.js +353 -0
- package/dist/server/device-center/task-workspace.js +443 -0
- package/dist/server/device-center/transfers.js +41 -15
- package/dist/server/device-center/verification-limits.js +10 -0
- package/dist/server/device-center/work-contract.js +995 -0
- package/dist/server/dispatch-domain-handlers.js +29 -3
- package/dist/server/dsh/dsh-agent-service.js +9 -2
- package/dist/server/engine-probe.js +112 -1
- package/dist/server/global-loader.js +119 -19
- package/dist/server/index.js +159 -17
- package/dist/server/managed.js +2 -0
- package/dist/server/model-admin.js +48 -6
- package/dist/server/model-enrich.js +10 -1
- package/dist/server/patch-node-pty.js +3 -2
- package/dist/server/patch-remote-catalog.js +3 -2
- package/dist/server/plugins.js +64 -7
- package/dist/server/preset-fields.js +17 -1
- package/dist/server/preset-share.js +1 -0
- package/dist/server/prompt-composer.js +39 -0
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/quick-ask-settings.js +28 -0
- package/dist/server/quick-ask.js +164 -0
- package/dist/server/reasoning-registry.js +207 -0
- package/dist/server/resolve-global-sdk.js +61 -11
- package/dist/server/scheduler-tasks.js +35 -8
- package/dist/server/session-list-scan.js +223 -0
- package/dist/server/session-open.js +93 -0
- package/dist/server/session-parser.js +4 -0
- package/dist/server/session-scan.js +90 -38
- package/dist/server/settings-service.js +9 -1
- package/dist/server/soft-cap.js +5 -0
- package/dist/server/startup-banner.js +35 -0
- package/dist/server/subagents.js +2 -1
- package/dist/server/tool-manager.js +17 -9
- package/dist/server/transcript-prepare.js +73 -0
- package/dist/server/unauthorized-page.js +319 -0
- package/dist/server/universal/drivers/claude-code.js +98 -34
- package/dist/server/universal/universal-session.js +4 -0
- package/dist/server/workspace-handle.js +428 -0
- package/docs/architecture-plugins.md +959 -0
- package/docs/device-center.md +34 -20
- package/package.json +4 -4
- package/plugin-sdk/README.md +16 -8
- package/plugin-sdk/client.d.ts +27 -0
- package/plugin-sdk/client.mjs +82 -0
- package/plugin-sdk/index.d.ts +10 -0
- package/plugin-sdk/index.mjs +4 -683
- package/plugin-sdk/package.json +15 -4
- package/plugin-sdk/testing.d.ts +10 -0
- package/plugin-sdk/testing.mjs +566 -0
- package/themes/flow-cristallo.css +168 -0
- package/themes/flow-ink.css +169 -0
- package/themes/flow-obsidian.css +169 -0
- package/themes/flow-zurich.css +169 -0
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/{BgTasksModal-BYzPgmoq.js → BgTasksModal-BjNRIUIc.js} +1 -1
- package/web/dist/assets/{BgTasksModal-ni0VTmAQ.js → BgTasksModal-C0zuU8FE.js} +1 -1
- package/web/dist/assets/{CanvasStudio-DNmDNBod.js → CanvasStudio-BWvdmJ0M.js} +3 -3
- package/web/dist/assets/{CanvasStudio-BCUeEf25.js → CanvasStudio-VQFjmTGq.js} +3 -3
- package/web/dist/assets/DeviceCenter-DI9_0aBB.js +3 -0
- package/web/dist/assets/DeviceCenter-DsNtXqzY.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-BLP1Su5G.js +1 -0
- package/web/dist/assets/DeviceGroups-2Pvk0Cds.js +1 -0
- package/web/dist/assets/DeviceGroups-CP7CcyPD.js +1 -0
- package/web/dist/assets/{Dropdown-CGXD0DfT.js → Dropdown-CQtstPGv.js} +1 -1
- package/web/dist/assets/FilePreview-BMB2tNyT.js +2 -0
- package/web/dist/assets/FilePreview-RGFQUbJo.js +2 -0
- package/web/dist/assets/{GlobalSearchModal-mevF-ySi.js → GlobalSearchModal-BM5wxiqU.js} +1 -1
- package/web/dist/assets/{GlobalSearchModal-qL99FN_F.js → GlobalSearchModal-DGv_WINq.js} +1 -1
- package/web/dist/assets/GroupConversation-B7SnuXj1.js +61 -0
- package/web/dist/assets/GroupConversation-Dda69q-2.js +61 -0
- package/web/dist/assets/{HintTip-LHwkS2jV.js → HintTip-ChTW8o1m.js} +1 -1
- package/web/dist/assets/ModelConfigModal-C-0Z4hUZ.js +2 -0
- package/web/dist/assets/ModelConfigModal-yqeadyab.js +2 -0
- package/web/dist/assets/{PiSetupModal-DE5-gEtI.js → PiSetupModal-BX5rUuoI.js} +1 -1
- package/web/dist/assets/{ProviderOAuthControls-6UMARucA.js → ProviderOAuthControls-DY4SCfXg.js} +1 -1
- package/web/dist/assets/SCMPanel-C4KbQvvK.js +2 -0
- package/web/dist/assets/SCMPanel-DPAyY2sW.js +2 -0
- package/web/dist/assets/SettingsModal-DxZp6D_g.js +32 -0
- package/web/dist/assets/SettingsModal-WhQzaOPt.js +32 -0
- package/web/dist/assets/{TerminalPanel-CTp_BZ4S.js → TerminalPanel-D4By_RVc.js} +2 -2
- package/web/dist/assets/{TerminalPanel-CkYxC-Gh.js → TerminalPanel-lZw8-i3j.js} +2 -2
- package/web/dist/assets/{TuiOverlayModal-1cRLP8IF.js → TuiOverlayModal-C3pAVuC8.js} +1 -1
- package/web/dist/assets/{TuiOverlayModal-2xlptqWX.js → TuiOverlayModal-D7_rEXcJ.js} +1 -1
- package/web/dist/assets/app-globals-KqOVtmp1.js +123 -0
- package/web/dist/assets/{canvas-client-Bye9nSFO.js → canvas-client-BY6ojmle.js} +1 -1
- package/web/dist/assets/{desktop-kjBoE3Nu.js → desktop-CV6KKp9R.js} +1 -1
- package/web/dist/assets/index-BawF7ZP5.js +397 -0
- package/web/dist/assets/index-BoGCoq5X.js +397 -0
- package/web/dist/assets/index-CVW9FoY2.css +1 -0
- package/web/dist/assets/{plugin-host-C8mNgghx.js → plugin-host-Dn8Dd6SC.js} +1 -1
- package/web/dist/assets/{remote-ssh-client-CeP3CLUW.js → remote-ssh-client-Dzi-eEyE.js} +1 -1
- package/web/dist/assets/{theme-BXGpyTMh.js → theme-D_bihpdN.js} +1 -1
- package/web/dist/index.html +11 -11
- package/web/dist/sw.js +1 -1
- package/dist/server/patch-turn-end-boundary.js +0 -77
- package/web/dist/assets/DeviceCenter-BcBhRgL6.js +0 -3
- package/web/dist/assets/DeviceCenter-CmL5FZmt.js +0 -3
- package/web/dist/assets/DeviceGroups-CLdpdnI7.js +0 -1
- package/web/dist/assets/DeviceGroups-CgBaDPrD.js +0 -1
- package/web/dist/assets/FilePreview-B8iqnBjy.js +0 -2
- package/web/dist/assets/FilePreview-BqviZKCN.js +0 -2
- package/web/dist/assets/GroupConversation-B88Yy-lt.js +0 -3
- package/web/dist/assets/GroupConversation-BwP5NVOE.js +0 -3
- package/web/dist/assets/ModelConfigModal-Do3Fe3jH.js +0 -2
- package/web/dist/assets/SCMPanel-Hi6QqC1Q.js +0 -2
- package/web/dist/assets/SCMPanel-ezY_ZtCu.js +0 -2
- package/web/dist/assets/SettingsModal-6HgeEsJ8.js +0 -20
- package/web/dist/assets/SettingsModal-CF-7MwqS.js +0 -20
- package/web/dist/assets/app-globals-DZNa9v8u.js +0 -325
- package/web/dist/assets/index-CsFs_HMb.css +0 -1
- package/web/dist/assets/index-DHeeHS_l.js +0 -85
- package/web/dist/assets/index-DTZch8uz.js +0 -85
|
@@ -10,6 +10,8 @@ import { createLocalDeviceHub } from "./local-hub.js";
|
|
|
10
10
|
import { createLocalBotRegistry } from "./bots.js";
|
|
11
11
|
import { loadExecutionSettings, saveExecutionSettings } from "./execution-settings.js";
|
|
12
12
|
import { hostWithoutPort, isLoopbackHost } from "../host-guard.js";
|
|
13
|
+
import { MAX_CONTRACT_REQUEST_BYTES } from "./work-contract.js";
|
|
14
|
+
import { INTEGRATION_HTTP_TIMEOUT_MS, VERIFICATION_HTTP_TIMEOUT_MS } from "./verification-limits.js";
|
|
13
15
|
/** Hub enrollment accepts HTTP(S) origins, including public IP addresses. */
|
|
14
16
|
export function normalizeHubUrl(input) {
|
|
15
17
|
if (typeof input !== "string" || input.length > 2048)
|
|
@@ -88,16 +90,24 @@ export async function installLocalDeviceCenter(options) {
|
|
|
88
90
|
let localHub;
|
|
89
91
|
let localStarting;
|
|
90
92
|
const activeConfig = () => config ?? localHub?.config;
|
|
93
|
+
function forAgent(captured) {
|
|
94
|
+
const { uiCredential: _uiCredential, ...agentConfig } = captured;
|
|
95
|
+
return {
|
|
96
|
+
...agentConfig,
|
|
97
|
+
get accountId() {
|
|
98
|
+
return captured.accountId;
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
91
102
|
async function ensureLocalHub() {
|
|
92
103
|
if (config || localHub || closed)
|
|
93
104
|
return;
|
|
94
105
|
if (!localStarting) {
|
|
95
106
|
localStarting = (async () => {
|
|
96
|
-
const hub = await createLocalDeviceHub(options.dataDir);
|
|
107
|
+
const hub = await createLocalDeviceHub(options.dataDir, () => loadExecutionSettings(options.dataDir));
|
|
97
108
|
try {
|
|
98
|
-
const { uiCredential: _uiCredential, ...agentConfig } = hub.config;
|
|
99
109
|
localHub = hub;
|
|
100
|
-
connection = await options.connect(
|
|
110
|
+
connection = await options.connect(forAgent(hub.config), syncBots);
|
|
101
111
|
await syncBots();
|
|
102
112
|
}
|
|
103
113
|
catch (error) {
|
|
@@ -141,8 +151,7 @@ export async function installLocalDeviceCenter(options) {
|
|
|
141
151
|
localHub = undefined;
|
|
142
152
|
await bots.setScope(config ? JSON.stringify([config.hubUrl, config.deviceId]) : "unpaired");
|
|
143
153
|
if (config && !closed) {
|
|
144
|
-
|
|
145
|
-
connection = await options.connect(agentConfig, syncBots);
|
|
154
|
+
connection = await options.connect(forAgent(config), syncBots);
|
|
146
155
|
}
|
|
147
156
|
}
|
|
148
157
|
async function syncBots() {
|
|
@@ -169,11 +178,22 @@ export async function installLocalDeviceCenter(options) {
|
|
|
169
178
|
})),
|
|
170
179
|
}),
|
|
171
180
|
});
|
|
172
|
-
|
|
173
|
-
|
|
181
|
+
if (!response.ok) {
|
|
182
|
+
await response.body?.cancel();
|
|
174
183
|
throw new Error("Bot configuration saved locally, but Hub synchronization failed; retry after reconnecting");
|
|
184
|
+
}
|
|
185
|
+
// Only the authenticated Hub supplies the owner, never a publication command's wire scope.
|
|
186
|
+
const result = await response.json();
|
|
187
|
+
const accountId = result && typeof result === "object" && "accountId" in result ? result.accountId : undefined;
|
|
175
188
|
if (activeConfig() !== captured || closed)
|
|
176
189
|
throw new Error("Device binding changed during Bot synchronization");
|
|
190
|
+
if (typeof accountId === "string" && accountId) {
|
|
191
|
+
if (captured.accountId && captured.accountId !== accountId)
|
|
192
|
+
throw new Error("Device account binding changed");
|
|
193
|
+
// Legacy bindings are refreshed each connection; do not race pairing's serialized config writes.
|
|
194
|
+
if (!captured.accountId)
|
|
195
|
+
captured.accountId = accountId;
|
|
196
|
+
}
|
|
177
197
|
}
|
|
178
198
|
async function hubRequest(hubUrl, path, body) {
|
|
179
199
|
const response = await fetch(`${hubUrl}${path}`, {
|
|
@@ -214,8 +234,10 @@ export async function installLocalDeviceCenter(options) {
|
|
|
214
234
|
typeof value.deviceId !== "string" ||
|
|
215
235
|
typeof value.credential !== "string" ||
|
|
216
236
|
typeof value.name !== "string" ||
|
|
237
|
+
(value.remark !== undefined && typeof value.remark !== "string") ||
|
|
217
238
|
typeof value.allowExecution !== "boolean" ||
|
|
218
|
-
(value.uiCredential !== undefined && typeof value.uiCredential !== "string")
|
|
239
|
+
(value.uiCredential !== undefined && typeof value.uiCredential !== "string") ||
|
|
240
|
+
(value.accountId !== undefined && (typeof value.accountId !== "string" || !value.accountId)))
|
|
219
241
|
throw new Error("Invalid saved device configuration");
|
|
220
242
|
config = { ...value, hubUrl: normalizeHubUrl(value.hubUrl) };
|
|
221
243
|
await reconnect();
|
|
@@ -229,6 +251,32 @@ export async function installLocalDeviceCenter(options) {
|
|
|
229
251
|
// entries are normalised exactly like the global guard does.
|
|
230
252
|
const allowHosts = new Set((options.allowHosts ?? []).map((entry) => hostWithoutPort(String(entry))).filter(Boolean));
|
|
231
253
|
const guard = localOnly(allowHosts);
|
|
254
|
+
// Public incoming webhook forwarding (authenticates via webhook token inside hub)
|
|
255
|
+
options.app.post("/api/rooms/:id/webhooks/incoming/:webhookId", async (req, res) => {
|
|
256
|
+
const captured = activeConfig();
|
|
257
|
+
if (!captured)
|
|
258
|
+
return res.status(503).json({ error: "Device hub not paired" });
|
|
259
|
+
try {
|
|
260
|
+
const queryIndex = req.url.indexOf("?");
|
|
261
|
+
const queryStr = queryIndex >= 0 ? req.url.slice(queryIndex) : "";
|
|
262
|
+
const forwardUrl = `${captured.hubUrl}/api/rooms/${encodeURIComponent(String(req.params.id))}/webhooks/incoming/${encodeURIComponent(String(req.params.webhookId))}${queryStr}`;
|
|
263
|
+
const response = await fetch(forwardUrl, {
|
|
264
|
+
method: "POST",
|
|
265
|
+
headers: {
|
|
266
|
+
"Content-Type": "application/json",
|
|
267
|
+
...(req.headers.authorization ? { Authorization: req.headers.authorization } : {}),
|
|
268
|
+
...(req.headers["x-webhook-token"] ? { "x-webhook-token": String(req.headers["x-webhook-token"]) } : {}),
|
|
269
|
+
},
|
|
270
|
+
body: JSON.stringify(req.body ?? {}),
|
|
271
|
+
signal: AbortSignal.timeout(15000),
|
|
272
|
+
});
|
|
273
|
+
const data = await response.json().catch(() => ({}));
|
|
274
|
+
res.status(response.status).json(data);
|
|
275
|
+
}
|
|
276
|
+
catch (err) {
|
|
277
|
+
res.status(502).json({ error: err?.message ?? "Failed to forward webhook to hub" });
|
|
278
|
+
}
|
|
279
|
+
});
|
|
232
280
|
// Existing bookmarks now enter the native application view.
|
|
233
281
|
options.app.get("/devices", guard, (_req, res) => {
|
|
234
282
|
res.redirect("./?view=devices");
|
|
@@ -238,12 +286,57 @@ export async function installLocalDeviceCenter(options) {
|
|
|
238
286
|
options.app.get("/api/device-center/status", (_req, res) => {
|
|
239
287
|
res.json({
|
|
240
288
|
name: config?.name ?? hostname(),
|
|
289
|
+
remark: config?.remark,
|
|
241
290
|
hubUrl: config?.hubUrl,
|
|
242
291
|
deviceId: config?.deviceId,
|
|
243
292
|
allowExecution: config?.allowExecution ?? false,
|
|
244
293
|
connected: connection?.isConnected?.() ?? false,
|
|
245
294
|
});
|
|
246
295
|
});
|
|
296
|
+
options.app.post("/api/device-center/upgrade-hub", async (_req, res) => {
|
|
297
|
+
const captured = activeConfig();
|
|
298
|
+
if (!captured)
|
|
299
|
+
return res.status(400).json({ error: "Device hub not paired" });
|
|
300
|
+
try {
|
|
301
|
+
const hubUrl = captured.hubUrl;
|
|
302
|
+
const forwardUrl = `${hubUrl}/api/system/upgrade`;
|
|
303
|
+
const response = await fetch(forwardUrl, {
|
|
304
|
+
method: "POST",
|
|
305
|
+
headers: {
|
|
306
|
+
"Content-Type": "application/json",
|
|
307
|
+
"x-device-id": captured.deviceId,
|
|
308
|
+
authorization: `Bearer ${captured.credential}`,
|
|
309
|
+
},
|
|
310
|
+
signal: AbortSignal.timeout(15_000),
|
|
311
|
+
});
|
|
312
|
+
if (!response.ok) {
|
|
313
|
+
const errData = (await response.json().catch(() => ({})));
|
|
314
|
+
throw new Error(errData.error || `Hub returned HTTP ${response.status}`);
|
|
315
|
+
}
|
|
316
|
+
const deadline = Date.now() + 60_000;
|
|
317
|
+
let healthy = false;
|
|
318
|
+
await new Promise((r) => setTimeout(r, 1500));
|
|
319
|
+
while (Date.now() < deadline) {
|
|
320
|
+
try {
|
|
321
|
+
const probe = await fetch(`${hubUrl}/health`, { signal: AbortSignal.timeout(2000) });
|
|
322
|
+
if (probe.ok) {
|
|
323
|
+
const data = (await probe.json().catch(() => ({})));
|
|
324
|
+
if (data && data.status === "ok") {
|
|
325
|
+
healthy = true;
|
|
326
|
+
break;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
catch { }
|
|
331
|
+
await new Promise((r) => setTimeout(r, 1500));
|
|
332
|
+
}
|
|
333
|
+
await reconnect().catch(() => { });
|
|
334
|
+
res.json({ ok: true, healthy, message: healthy ? "Hub updated successfully" : "Hub update triggered" });
|
|
335
|
+
}
|
|
336
|
+
catch (error) {
|
|
337
|
+
res.status(500).json({ error: error?.message || "Failed to upgrade hub" });
|
|
338
|
+
}
|
|
339
|
+
});
|
|
247
340
|
options.app.get("/api/device-center/execution-settings", (_req, res) => {
|
|
248
341
|
try {
|
|
249
342
|
const settings = loadExecutionSettings(options.dataDir);
|
|
@@ -362,6 +455,7 @@ export async function installLocalDeviceCenter(options) {
|
|
|
362
455
|
}
|
|
363
456
|
});
|
|
364
457
|
function userRoute(method, path, fields) {
|
|
458
|
+
const supportsContract = method === "post" && fields.includes("contract");
|
|
365
459
|
options.app[method](`/api/device-center/${path}`, async (req, res) => {
|
|
366
460
|
try {
|
|
367
461
|
await serialize(ensureLocalHub);
|
|
@@ -385,7 +479,8 @@ export async function installLocalDeviceCenter(options) {
|
|
|
385
479
|
typeof body !== "object" ||
|
|
386
480
|
Array.isArray(body) ||
|
|
387
481
|
Object.keys(body).some((key) => !fields.includes(key)) ||
|
|
388
|
-
Buffer.byteLength(JSON.stringify(body)) >
|
|
482
|
+
Buffer.byteLength(JSON.stringify(body)) >
|
|
483
|
+
(supportsContract && body.contract !== undefined ? MAX_CONTRACT_REQUEST_BYTES : 32768)))
|
|
389
484
|
return res.status(400).json({ code: "INVALID_BODY", error: "Invalid group request" });
|
|
390
485
|
const controller = new AbortController();
|
|
391
486
|
activeRequests.add(controller);
|
|
@@ -400,10 +495,15 @@ export async function installLocalDeviceCenter(options) {
|
|
|
400
495
|
const suffix = path.replace(/:([A-Za-z]+)/g, (_match, key) => encodeURIComponent(String(req.params[key])));
|
|
401
496
|
const queryIndex = req.url.indexOf("?");
|
|
402
497
|
const queryStr = queryIndex >= 0 ? req.url.slice(queryIndex) : "";
|
|
498
|
+
const timeoutMs = method === "post" && path.includes("/integrations")
|
|
499
|
+
? path.endsWith("/verify")
|
|
500
|
+
? VERIFICATION_HTTP_TIMEOUT_MS
|
|
501
|
+
: INTEGRATION_HTTP_TIMEOUT_MS
|
|
502
|
+
: 15000;
|
|
403
503
|
const response = await fetch(`${captured.hubUrl}/api/device-user/${suffix}${queryStr}`, {
|
|
404
504
|
method: method.toUpperCase(),
|
|
405
505
|
redirect: "error",
|
|
406
|
-
signal: AbortSignal.any([controller.signal, AbortSignal.timeout(
|
|
506
|
+
signal: AbortSignal.any([controller.signal, AbortSignal.timeout(timeoutMs)]),
|
|
407
507
|
headers: {
|
|
408
508
|
"Content-Type": "application/json",
|
|
409
509
|
"X-Device-Id": captured.deviceId,
|
|
@@ -462,6 +562,14 @@ export async function installLocalDeviceCenter(options) {
|
|
|
462
562
|
});
|
|
463
563
|
}
|
|
464
564
|
const data = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
565
|
+
if (path === "devices/:id/remark" &&
|
|
566
|
+
String(req.params.id) === captured.deviceId &&
|
|
567
|
+
config) {
|
|
568
|
+
const rawRemark = req.body?.remark;
|
|
569
|
+
const remark = typeof rawRemark === "string" ? rawRemark.trim().slice(0, 80) : "";
|
|
570
|
+
config = { ...config, remark: remark || undefined };
|
|
571
|
+
void persist(config);
|
|
572
|
+
}
|
|
465
573
|
res.status(response.status).json(data);
|
|
466
574
|
}
|
|
467
575
|
catch {
|
|
@@ -629,6 +737,7 @@ export async function installLocalDeviceCenter(options) {
|
|
|
629
737
|
userRoute("get", "bots", []);
|
|
630
738
|
userRoute("get", "devices", []);
|
|
631
739
|
userRoute("post", "devices/:id/open", []);
|
|
740
|
+
userRoute("post", "devices/:id/remark", ["remark"]);
|
|
632
741
|
userRoute("get", "rooms", []);
|
|
633
742
|
userRoute("get", "rooms/:id", []);
|
|
634
743
|
userRoute("post", "rooms/:id/canvas", ["binding"]);
|
|
@@ -655,7 +764,15 @@ export async function installLocalDeviceCenter(options) {
|
|
|
655
764
|
]);
|
|
656
765
|
userRoute("get", "rooms/:id/conversations", []);
|
|
657
766
|
userRoute("get", "rooms/:id/conversations/:conversationId", []);
|
|
658
|
-
userRoute("post", "rooms/:id/conversations", [
|
|
767
|
+
userRoute("post", "rooms/:id/conversations", [
|
|
768
|
+
"name",
|
|
769
|
+
"targetBotId",
|
|
770
|
+
"text",
|
|
771
|
+
"idempotencyKey",
|
|
772
|
+
"planOnly",
|
|
773
|
+
"executionMode",
|
|
774
|
+
"contract",
|
|
775
|
+
]);
|
|
659
776
|
userRoute("post", "rooms/:id/conversations/:conversationId/messages", [
|
|
660
777
|
"text",
|
|
661
778
|
"kind",
|
|
@@ -663,8 +780,11 @@ export async function installLocalDeviceCenter(options) {
|
|
|
663
780
|
"attentionId",
|
|
664
781
|
"idempotencyKey",
|
|
665
782
|
"planOnly",
|
|
783
|
+
"executionMode",
|
|
784
|
+
"contract",
|
|
666
785
|
]);
|
|
667
786
|
userRoute("post", "rooms/:id/conversations/:conversationId/deliveries", [
|
|
787
|
+
"artifactTaskId",
|
|
668
788
|
"repository",
|
|
669
789
|
"baseCommit",
|
|
670
790
|
"commit",
|
|
@@ -677,6 +797,10 @@ export async function installLocalDeviceCenter(options) {
|
|
|
677
797
|
userRoute("post", "rooms/:id/conversations/:conversationId/reviews", [
|
|
678
798
|
"deliveryId",
|
|
679
799
|
"commit",
|
|
800
|
+
"artifactDigest",
|
|
801
|
+
"integrationId",
|
|
802
|
+
"verificationDigest",
|
|
803
|
+
"criteriaResults",
|
|
680
804
|
"verdict",
|
|
681
805
|
"summary",
|
|
682
806
|
"idempotencyKey",
|
|
@@ -691,6 +815,12 @@ export async function installLocalDeviceCenter(options) {
|
|
|
691
815
|
userRoute("post", "rooms/:id/conversations/:conversationId/integrations/:integrationId/verify", ["commands"]);
|
|
692
816
|
userRoute("post", "rooms/:id/conversations/:conversationId/integrations/:integrationId/apply", ["expectedTargetSha"]);
|
|
693
817
|
userRoute("post", "rooms/:id/conversations/:conversationId/integrations/:integrationId/cancel", []);
|
|
818
|
+
userRoute("post", "rooms/:id/conversations/:conversationId/integrations/:integrationId/reconcile", []);
|
|
819
|
+
userRoute("post", "rooms/:id/conversations/:conversationId/integrations/:integrationId/resume", [
|
|
820
|
+
"intentId",
|
|
821
|
+
"intentDigest",
|
|
822
|
+
"candidateSha",
|
|
823
|
+
]);
|
|
694
824
|
userRoute("get", "rooms/:id/transfers", []);
|
|
695
825
|
userRoute("post", "rooms/:id/transfers/start", [
|
|
696
826
|
"sourceBotId",
|
|
@@ -720,7 +850,33 @@ export async function installLocalDeviceCenter(options) {
|
|
|
720
850
|
"handoff",
|
|
721
851
|
"parentTaskId",
|
|
722
852
|
"planOnly",
|
|
853
|
+
"executionMode",
|
|
854
|
+
"contract",
|
|
855
|
+
]);
|
|
856
|
+
userRoute("get", "rooms/:id/webhooks", []);
|
|
857
|
+
userRoute("post", "rooms/:id/webhooks", [
|
|
858
|
+
"name",
|
|
859
|
+
"type",
|
|
860
|
+
"enabled",
|
|
861
|
+
"allowBotTrigger",
|
|
862
|
+
"url",
|
|
863
|
+
"secret",
|
|
864
|
+
"events",
|
|
865
|
+
"relayViaHub",
|
|
723
866
|
]);
|
|
867
|
+
userRoute("post", "rooms/:id/webhooks/:webhookId", [
|
|
868
|
+
"name",
|
|
869
|
+
"enabled",
|
|
870
|
+
"allowBotTrigger",
|
|
871
|
+
"url",
|
|
872
|
+
"secret",
|
|
873
|
+
"events",
|
|
874
|
+
"relayViaHub",
|
|
875
|
+
]);
|
|
876
|
+
userRoute("post", "rooms/:id/webhooks/:webhookId/regenerate-token", []);
|
|
877
|
+
userRoute("post", "rooms/:id/webhooks/:webhookId/delete", []);
|
|
878
|
+
userRoute("post", "rooms/:id/webhooks/:webhookId/test", []);
|
|
879
|
+
userRoute("post", "rooms/:id/hub-relay", ["hubRelayBaseUrl"]);
|
|
724
880
|
function route(path, work) {
|
|
725
881
|
options.app.post(`/api/device-center/${path}`, (req, res) => {
|
|
726
882
|
void serialize(async () => {
|
|
@@ -766,6 +922,7 @@ export async function installLocalDeviceCenter(options) {
|
|
|
766
922
|
hubUrl: pair.hubUrl,
|
|
767
923
|
name: pair.name,
|
|
768
924
|
deviceId: result.deviceId,
|
|
925
|
+
...(typeof result.accountId === "string" && result.accountId ? { accountId: result.accountId } : {}),
|
|
769
926
|
credential: result.credential,
|
|
770
927
|
uiCredential: result.uiCredential,
|
|
771
928
|
allowExecution: false,
|
|
@@ -787,6 +944,18 @@ export async function installLocalDeviceCenter(options) {
|
|
|
787
944
|
await reconnect();
|
|
788
945
|
return { saved: true };
|
|
789
946
|
});
|
|
947
|
+
route("remark", async (req) => {
|
|
948
|
+
if (!config)
|
|
949
|
+
throw new Error("Pair this computer first");
|
|
950
|
+
const rawRemark = req.body?.remark;
|
|
951
|
+
if (rawRemark !== null && rawRemark !== undefined && typeof rawRemark !== "string")
|
|
952
|
+
throw new Error("Invalid remark");
|
|
953
|
+
const remark = typeof rawRemark === "string" ? rawRemark.trim().slice(0, 80) : "";
|
|
954
|
+
const next = { ...config, remark: remark || undefined };
|
|
955
|
+
await persist(next);
|
|
956
|
+
config = next;
|
|
957
|
+
return { saved: true, remark: next.remark };
|
|
958
|
+
});
|
|
790
959
|
route("execution-settings", async (req) => {
|
|
791
960
|
const boundConnection = connection;
|
|
792
961
|
// Persist first, then apply to captured active runtime
|
|
@@ -825,8 +994,7 @@ export async function installLocalDeviceCenter(options) {
|
|
|
825
994
|
const current = activeConfig();
|
|
826
995
|
if (!current)
|
|
827
996
|
return undefined;
|
|
828
|
-
|
|
829
|
-
return agentConfig;
|
|
997
|
+
return forAgent(current);
|
|
830
998
|
},
|
|
831
999
|
async close() {
|
|
832
1000
|
closed = true;
|
|
@@ -50,7 +50,10 @@ export async function startDeviceHub(env = process.env) {
|
|
|
50
50
|
getAccount: (req) => hub.getRelayAccount(req),
|
|
51
51
|
ownsDevice: (accountId, id) => hub.store.getDeviceOwner(id) === accountId,
|
|
52
52
|
getDeviceName: (id) => hub.store.getDevice(id)?.name,
|
|
53
|
-
onTaskEvent: (id, event) => hub.acceptTaskEvent(id, event)
|
|
53
|
+
onTaskEvent: (id, event) => hub.acceptTaskEvent(id, event),
|
|
54
|
+
onDeviceConnect: async (id) => {
|
|
55
|
+
await Promise.all([hub.resumeQueuedTasks(id), hub.reconcilePendingPublications(id)]);
|
|
56
|
+
},
|
|
54
57
|
onTaskInteractions: (id, event) => hub.acceptInteractions(id, event),
|
|
55
58
|
onTaskProgress: (id, event) => hub.acceptTaskProgress(id, event),
|
|
56
59
|
onTaskToolLifecycle: (id, frame) => hub.acceptTaskToolLifecycle(id, frame),
|