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.
- package/CHANGELOG.md +62 -1
- package/bin/pi-web-ui.mjs +90 -8
- package/dist/gh-comment-781.md +5 -0
- package/dist/server/agent-service-daemon.js +522 -32
- package/dist/server/agent-service.js +954 -402
- package/dist/server/canvas/canvas-dispatch.js +13 -1
- package/dist/server/client-state.js +42 -2
- package/dist/server/communicate-tool.js +2 -0
- package/dist/server/conversation-communication.js +14 -0
- package/dist/server/conversation-identity.js +27 -0
- package/dist/server/device-center/approval-summary.js +31 -0
- package/dist/server/device-center/bot-catalog.js +21 -7
- package/dist/server/device-center/bot-execution.js +100 -9
- package/dist/server/device-center/bot-presets.js +46 -0
- package/dist/server/device-center/collab-service.js +362 -13
- package/dist/server/device-center/collab-tool.js +824 -13
- package/dist/server/device-center/connector.js +359 -23
- package/dist/server/device-center/desktop-page.js +22 -16
- package/dist/server/device-center/device-integration.js +595 -0
- package/dist/server/device-center/execution-guides.js +32 -0
- package/dist/server/device-center/execution-instructions.js +20 -0
- package/dist/server/device-center/execution-settings.js +213 -0
- package/dist/server/device-center/execution-system-prompt.js +38 -0
- package/dist/server/device-center/execution-workspace.js +20 -0
- package/dist/server/device-center/executor.js +392 -40
- package/dist/server/device-center/file-sync-paths.js +171 -0
- package/dist/server/device-center/file-sync.js +186 -96
- package/dist/server/device-center/group-context-delta.js +37 -0
- package/dist/server/device-center/group-context-message.js +210 -0
- package/dist/server/device-center/group-context.js +179 -0
- package/dist/server/device-center/group-events.js +136 -0
- package/dist/server/device-center/group-plan-guard.js +138 -0
- package/dist/server/device-center/hub-conversations.js +233 -0
- package/dist/server/device-center/hub-deliveries.js +277 -0
- package/dist/server/device-center/hub-integration.js +451 -0
- package/dist/server/device-center/hub-locks.js +320 -0
- package/dist/server/device-center/hub-page.js +13 -33
- package/dist/server/device-center/hub-webhooks.js +165 -0
- package/dist/server/device-center/hub.js +2379 -107
- package/dist/server/device-center/human-interaction.js +232 -0
- package/dist/server/device-center/integration-errors.js +25 -0
- package/dist/server/device-center/local-hub.js +20 -1
- package/dist/server/device-center/local-page.js +17 -0
- package/dist/server/device-center/local.js +430 -41
- package/dist/server/device-center/main.js +11 -1
- package/dist/server/device-center/partition-log.js +293 -0
- package/dist/server/device-center/path-portal.js +11 -3
- package/dist/server/device-center/relay.js +364 -35
- package/dist/server/device-center/report-metadata.js +66 -0
- package/dist/server/device-center/report-upload.js +63 -0
- package/dist/server/device-center/runtime.js +598 -41
- package/dist/server/device-center/smoke-preview.js +3 -0
- package/dist/server/device-center/store.js +203 -41
- package/dist/server/device-center/task-context-budget.js +161 -0
- package/dist/server/device-center/task-journal.js +385 -0
- package/dist/server/device-center/task-plan.js +33 -0
- package/dist/server/device-center/task-progress.js +141 -0
- package/dist/server/device-center/task-recovery.js +452 -0
- package/dist/server/device-center/task-report-outbox.js +216 -0
- package/dist/server/device-center/task-report.js +384 -0
- package/dist/server/device-center/task-scheduler.js +445 -0
- package/dist/server/device-center/task-state.js +333 -0
- package/dist/server/device-center/transfer-stream.js +1006 -0
- package/dist/server/device-center/transfers.js +841 -8
- package/dist/server/dispatch-domain-handlers.js +35 -6
- package/dist/server/dsh/dsh-agent-service.js +6 -0
- package/dist/server/durable/durable-capabilities.js +11 -0
- package/dist/server/engine-probe.js +112 -1
- package/dist/server/global-loader.js +119 -19
- package/dist/server/goal-service.js +10 -5
- package/dist/server/index.js +222 -29
- package/dist/server/managed.js +2 -0
- package/dist/server/markers/builtins/services.js +123 -0
- package/dist/server/markers/builtins/todo.js +189 -0
- package/dist/server/markers-list-tool.js +34 -0
- package/dist/server/message-deletion.js +40 -0
- package/dist/server/message-window.js +9 -0
- package/dist/server/model-admin.js +48 -6
- package/dist/server/model-enrich.js +10 -1
- package/dist/server/orchestrator.js +109 -0
- package/dist/server/patch-executable-lookup.js +396 -0
- package/dist/server/payload-limits.js +2 -0
- package/dist/server/plugin-llm.js +100 -9
- package/dist/server/plugins.js +65 -7
- package/dist/server/preset-fields.js +24 -0
- package/dist/server/preset-share.js +2 -0
- package/dist/server/prompt-base-store.js +85 -0
- package/dist/server/prompt-composer.js +44 -2
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/protocol.js +2 -2
- package/dist/server/reasoning-registry.js +207 -0
- package/dist/server/remote-ssh-service.js +22 -9
- package/dist/server/resolve-global-sdk.js +2 -0
- package/dist/server/session-search.js +1 -1
- package/dist/server/settings-service.js +90 -39
- package/dist/server/skill-content-filler.js +29 -8
- package/dist/server/skill-tool.js +12 -3
- package/dist/server/startup-banner.js +35 -0
- package/dist/server/subagent-helpers.js +4 -1
- package/dist/server/subagents.js +52 -37
- package/dist/server/system-prompt-soul.js +41 -0
- package/dist/server/tool-host-factories.js +1 -0
- package/dist/server/tool-manager.js +17 -9
- package/dist/server/unauthorized-page.js +319 -0
- package/dist/server/univer-service.js +448 -0
- package/dist/server/universal/drivers/dsh-driver.js +379 -0
- package/dist/server/universal/universal-session.js +5 -0
- package/dist/server/webui-context.js +25 -5
- package/dist/test-artifact.md +9 -0
- package/dist/test-preview-modal.md +11 -0
- package/dist/test-report.html +20 -0
- package/docs/README.md +94 -0
- package/docs/architecture-plugins.md +946 -0
- package/docs/device-center.md +106 -12
- package/docs/dsh-engine.md +10 -10
- package/extensions/webui.ts +43 -1
- package/package.json +2 -1
- package/themes/aetheris.css +5 -0
- package/themes/ayu-light.css +6 -0
- package/themes/bases/flow-base.css +68 -68
- package/themes/catppuccin-latte.css +6 -0
- package/themes/catppuccin.css +6 -0
- package/themes/claude-code-dark.css +5 -0
- package/themes/codex.css +6 -0
- package/themes/cyberpunk.css +6 -0
- package/themes/dark-teal.css +6 -1
- package/themes/dazzle.css +6 -0
- package/themes/everforest-light.css +6 -0
- package/themes/flow-light.css +8 -1
- package/themes/flow.css +6 -1
- package/themes/geist.css +6 -0
- package/themes/gruvbox-light.css +6 -0
- package/themes/kanagawa-lotus.css +6 -0
- package/themes/md-preview.css +6 -0
- package/themes/mist.css +6 -0
- package/themes/nord.css +6 -0
- package/themes/one-dark.css +6 -0
- package/themes/paper.css +6 -0
- package/themes/rose-pine-dawn.css +6 -0
- package/themes/sakura.css +6 -0
- package/themes/solarized-light.css +6 -0
- package/themes/tokyo-night.css +6 -0
- package/themes/translucent.css +6 -0
- package/themes/transparent.css +6 -0
- package/themes/vs-code-dark.css +5 -0
- package/themes/wallpaper-flow.css +5 -1
- package/themes/wallpaper-obsidian.css +6 -0
- package/themes/white.css +6 -0
- package/themes/zhujian-dark.css +6 -1
- package/themes/zhujian.css +6 -1
- package/themes/zhupi-dark.css +6 -1
- package/themes/zhupi.css +6 -1
- package/web/dist/.build-assets.json +1 -1
- package/web/dist/assets/BgTasksModal-BDoOpj-F.js +1 -0
- package/web/dist/assets/BgTasksModal-C0i3O1FT.js +1 -0
- package/web/dist/assets/{CanvasStudio-BSg9ghPV.js → CanvasStudio-B8thymBN.js} +3 -3
- package/web/dist/assets/{CanvasStudio-DxW7C3Sz.js → CanvasStudio-zSxyIx1R.js} +3 -3
- package/web/dist/assets/DeviceCenter-DfAHKcid.js +3 -0
- package/web/dist/assets/DeviceCenter-ydvOTlzE.js +3 -0
- package/web/dist/assets/DeviceExecutionSettings-q5Ik8oXg.js +1 -0
- package/web/dist/assets/DeviceGroups-CI14_SRb.js +1 -0
- package/web/dist/assets/DeviceGroups-DvsB5IEU.js +1 -0
- package/web/dist/assets/Dropdown-C4LIhshN.js +1 -0
- package/web/dist/assets/FilePreview-BgGongmv.js +2 -0
- package/web/dist/assets/FilePreview-D4NrhF-U.js +2 -0
- package/web/dist/assets/GlobalSearchModal-BWgU8yPd.js +1 -0
- package/web/dist/assets/GlobalSearchModal-F7fNimKk.js +1 -0
- package/web/dist/assets/GroupConversation-Dh71Pdb-.js +17 -0
- package/web/dist/assets/GroupConversation-ZK3nRmNm.js +17 -0
- package/web/dist/assets/HintTip-c6d0TJoh.js +1 -0
- package/web/dist/assets/ModelConfigModal-YVEgyy34.js +2 -0
- package/web/dist/assets/ModelConfigModal-vWtg3srp.js +2 -0
- package/web/dist/assets/PiSetupModal-BmMrrgB9.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-BGSBIKD7.js +1 -0
- package/web/dist/assets/SCMPanel-B8_EDxNr.js +2 -0
- package/web/dist/assets/SCMPanel-BU58qk3T.js +2 -0
- package/web/dist/assets/SettingsModal-CMUybq3J.js +32 -0
- package/web/dist/assets/SettingsModal-OBmGTh-5.js +32 -0
- package/web/dist/assets/TerminalPanel-0CYvD72B.js +3 -0
- package/web/dist/assets/TerminalPanel-DDavKvFr.js +3 -0
- package/web/dist/assets/TuiOverlayModal-BsA-QTvN.js +1 -0
- package/web/dist/assets/TuiOverlayModal-DzoVQBuG.js +1 -0
- package/web/dist/assets/app-globals-CZxzGvIo.js +123 -0
- package/web/dist/assets/canvas-client-CUnXlQYX.js +1 -0
- package/web/dist/assets/{desktop-7EvUHhKQ.js → desktop-aAKpvKJV.js} +1 -1
- package/web/dist/assets/group-view-state-CGCzYF8k.js +1 -0
- package/web/dist/assets/index-C6DwztqE.css +1 -0
- package/web/dist/assets/index-CuN802Sj.js +93 -0
- package/web/dist/assets/index-EH5Fw9fa.js +93 -0
- package/web/dist/assets/plugin-host-BRWib9DF.js +1 -0
- package/web/dist/assets/remote-ssh-client-CfYSMEZg.js +1 -0
- package/web/dist/assets/theme-D2l_mLNo.js +1 -0
- package/web/dist/index.html +10 -9
- package/web/dist/sw.js +1 -1
- package/web/dist/assets/BgTasksModal-BvnUHjFe.js +0 -1
- package/web/dist/assets/BgTasksModal-DSC8ncW3.js +0 -1
- package/web/dist/assets/DeviceCenter-Bmgr-Bwm.js +0 -3
- package/web/dist/assets/DeviceCenter-Cl9MBXaH.js +0 -3
- package/web/dist/assets/DeviceGroups-aeLD2msl.js +0 -1
- package/web/dist/assets/Dropdown-D1Jl35dw.js +0 -1
- package/web/dist/assets/FilePreview-6CqoDF_P.js +0 -2
- package/web/dist/assets/FilePreview-CJa27G_Q.js +0 -2
- package/web/dist/assets/GlobalSearchModal-CJX35rZL.js +0 -1
- package/web/dist/assets/GlobalSearchModal-CMW0xz0P.js +0 -1
- package/web/dist/assets/GroupConversation-Cq4daBFb.js +0 -1
- package/web/dist/assets/GroupConversation-DoELa83U.js +0 -1
- package/web/dist/assets/ModelConfigModal-Bp7tfKYh.js +0 -2
- package/web/dist/assets/PiSetupModal-DD8srwBJ.js +0 -1
- package/web/dist/assets/ProviderOAuthControls-C6tfXb88.js +0 -1
- package/web/dist/assets/SCMPanel-CghgsyBN.js +0 -2
- package/web/dist/assets/SCMPanel-D8-8aqwC.js +0 -2
- package/web/dist/assets/SettingsModal-BbBe2rYo.js +0 -20
- package/web/dist/assets/SettingsModal-qETiVPKj.js +0 -20
- package/web/dist/assets/TerminalPanel-Da-Xs4Wk.js +0 -3
- package/web/dist/assets/TerminalPanel-DnS4tFQO.js +0 -3
- package/web/dist/assets/TuiOverlayModal-CGyGkKYl.js +0 -1
- package/web/dist/assets/TuiOverlayModal-CpBKjG6x.js +0 -1
- package/web/dist/assets/app-globals-DcyO0UPi.js +0 -1
- package/web/dist/assets/fi-NyN-ZrgD.js +0 -325
- package/web/dist/assets/index-DK3F5ZJo.js +0 -85
- package/web/dist/assets/index-DQMii2he.js +0 -85
- package/web/dist/assets/index-vwBnwzkr.css +0 -1
- package/web/dist/assets/plugin-host-BCnX3P8U.js +0 -1
- package/web/dist/assets/theme-D2DMH6tH.js +0 -1
|
@@ -3,11 +3,13 @@ import { hostname } from "node:os";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
import { getLocalBotOptions } from "./bot-catalog.js";
|
|
6
|
-
import {
|
|
6
|
+
import { applyLocalBotPreset } from "./bot-presets.js";
|
|
7
7
|
import { installHubSetupRoutes } from "./hub-setup.js";
|
|
8
8
|
import { DeviceWorkspaceError } from "./workspaces.js";
|
|
9
9
|
import { createLocalDeviceHub } from "./local-hub.js";
|
|
10
10
|
import { createLocalBotRegistry } from "./bots.js";
|
|
11
|
+
import { loadExecutionSettings, saveExecutionSettings } from "./execution-settings.js";
|
|
12
|
+
import { hostWithoutPort, isLoopbackHost } from "../host-guard.js";
|
|
11
13
|
/** Hub enrollment accepts HTTP(S) origins, including public IP addresses. */
|
|
12
14
|
export function normalizeHubUrl(input) {
|
|
13
15
|
if (typeof input !== "string" || input.length > 2048)
|
|
@@ -22,37 +24,61 @@ export function normalizeHubUrl(input) {
|
|
|
22
24
|
throw new Error("Hub must use HTTP(S), without a path, query, fragment or credentials");
|
|
23
25
|
return url.origin;
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
27
|
+
/**
|
|
28
|
+
* Hub failures reach the browser as a cause the user can act on, but never verbatim: the raw message
|
|
29
|
+
* may echo configured credentials or opaque tokens. Redact known secrets plus token-shaped runs.
|
|
30
|
+
*/
|
|
31
|
+
export function scrubHubMessage(message, secrets) {
|
|
32
|
+
let safe = message;
|
|
33
|
+
for (const secret of secrets)
|
|
34
|
+
if (secret && secret.length >= 6)
|
|
35
|
+
safe = safe.split(secret).join("[REDACTED]");
|
|
36
|
+
safe = safe
|
|
37
|
+
.replace(/((?:bearer|token|api[-_]?key|secret|password|passwd|credential|authorization)[\s:="']{1,4})[A-Za-z0-9_\-./+=]{8,}/gi, "$1[REDACTED]")
|
|
38
|
+
.replace(/[A-Za-z0-9_\-./+=]{32,}/g, (token) => /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(token) ? token : "[REDACTED]");
|
|
39
|
+
return safe.trim().slice(0, 300);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Local-only guard for the device center API: the peer must be loopback, and the
|
|
43
|
+
* Host must be loopback too — except for hostnames the operator explicitly declared
|
|
44
|
+
* in PI_WEB_ALLOW_HOSTS. Those domains are the ones a reverse proxy forwards; the
|
|
45
|
+
* global host guard already trusts them (and is in strict-whitelist mode once the
|
|
46
|
+
* list is non-empty), so extending that decision here keeps a proxied deployment
|
|
47
|
+
* usable without weakening DNS-rebinding protection.
|
|
48
|
+
*/
|
|
49
|
+
function localOnly(allowHosts) {
|
|
50
|
+
return (req, res, next) => {
|
|
51
|
+
const peer = req.socket.remoteAddress?.replace(/^::ffff:/, "");
|
|
52
|
+
if (!(peer === "::1" || peer?.startsWith("127."))) {
|
|
53
|
+
res.status(403).json({ code: "LOCAL_ONLY", error: "Configure devices from this computer's loopback address" });
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
let host;
|
|
44
57
|
try {
|
|
45
|
-
|
|
46
|
-
if (!["http:", "https:"].includes(origin.protocol) || origin.host !== req.headers.host)
|
|
47
|
-
throw new Error();
|
|
58
|
+
host = new URL(`http://${req.headers.host}`).hostname.replace(/^\[|\]$/g, "");
|
|
48
59
|
}
|
|
49
60
|
catch {
|
|
50
|
-
res.status(403).json({ code: "LOCAL_ONLY", error: "
|
|
61
|
+
res.status(403).json({ code: "LOCAL_ONLY", error: "Invalid host" });
|
|
51
62
|
return;
|
|
52
63
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
64
|
+
if (!isLoopbackHost(host) && !allowHosts.has(host)) {
|
|
65
|
+
res.status(403).json({ code: "LOCAL_ONLY", error: "Use localhost to configure device access" });
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (!["GET", "HEAD"].includes(req.method)) {
|
|
69
|
+
try {
|
|
70
|
+
const origin = new URL(req.headers.origin ?? "");
|
|
71
|
+
if (!["http:", "https:"].includes(origin.protocol) || origin.host !== req.headers.host)
|
|
72
|
+
throw new Error();
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
res.status(403).json({ code: "LOCAL_ONLY", error: "Same-origin request required" });
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
res.setHeader("Cache-Control", "no-store");
|
|
80
|
+
next();
|
|
81
|
+
};
|
|
56
82
|
}
|
|
57
83
|
export async function installLocalDeviceCenter(options) {
|
|
58
84
|
const file = join(options.dataDir, "device-center.json");
|
|
@@ -67,7 +93,7 @@ export async function installLocalDeviceCenter(options) {
|
|
|
67
93
|
return;
|
|
68
94
|
if (!localStarting) {
|
|
69
95
|
localStarting = (async () => {
|
|
70
|
-
const hub = await createLocalDeviceHub(options.dataDir);
|
|
96
|
+
const hub = await createLocalDeviceHub(options.dataDir, () => loadExecutionSettings(options.dataDir));
|
|
71
97
|
try {
|
|
72
98
|
const { uiCredential: _uiCredential, ...agentConfig } = hub.config;
|
|
73
99
|
localHub = hub;
|
|
@@ -133,9 +159,14 @@ export async function installLocalDeviceCenter(options) {
|
|
|
133
159
|
Authorization: `Bearer ${captured.credential}`,
|
|
134
160
|
},
|
|
135
161
|
body: JSON.stringify({
|
|
136
|
-
bots: bots
|
|
137
|
-
|
|
138
|
-
|
|
162
|
+
bots: bots.list().map(({ id, name, description, enabled, revision, tools }) => ({
|
|
163
|
+
id,
|
|
164
|
+
name,
|
|
165
|
+
description,
|
|
166
|
+
enabled,
|
|
167
|
+
revision,
|
|
168
|
+
tools,
|
|
169
|
+
})),
|
|
139
170
|
}),
|
|
140
171
|
});
|
|
141
172
|
await response.body?.cancel();
|
|
@@ -183,6 +214,7 @@ export async function installLocalDeviceCenter(options) {
|
|
|
183
214
|
typeof value.deviceId !== "string" ||
|
|
184
215
|
typeof value.credential !== "string" ||
|
|
185
216
|
typeof value.name !== "string" ||
|
|
217
|
+
(value.remark !== undefined && typeof value.remark !== "string") ||
|
|
186
218
|
typeof value.allowExecution !== "boolean" ||
|
|
187
219
|
(value.uiCredential !== undefined && typeof value.uiCredential !== "string"))
|
|
188
220
|
throw new Error("Invalid saved device configuration");
|
|
@@ -194,21 +226,84 @@ export async function installLocalDeviceCenter(options) {
|
|
|
194
226
|
if (error.code !== "ENOENT")
|
|
195
227
|
throw error;
|
|
196
228
|
}
|
|
229
|
+
// Hostnames the operator declared as legitimate entry points (reverse proxy);
|
|
230
|
+
// entries are normalised exactly like the global guard does.
|
|
231
|
+
const allowHosts = new Set((options.allowHosts ?? []).map((entry) => hostWithoutPort(String(entry))).filter(Boolean));
|
|
232
|
+
const guard = localOnly(allowHosts);
|
|
233
|
+
// Public incoming webhook forwarding (authenticates via webhook token inside hub)
|
|
234
|
+
options.app.post("/api/rooms/:id/webhooks/incoming/:webhookId", async (req, res) => {
|
|
235
|
+
const captured = activeConfig();
|
|
236
|
+
if (!captured)
|
|
237
|
+
return res.status(503).json({ error: "Device hub not paired" });
|
|
238
|
+
try {
|
|
239
|
+
const queryIndex = req.url.indexOf("?");
|
|
240
|
+
const queryStr = queryIndex >= 0 ? req.url.slice(queryIndex) : "";
|
|
241
|
+
const forwardUrl = `${captured.hubUrl}/api/rooms/${encodeURIComponent(String(req.params.id))}/webhooks/incoming/${encodeURIComponent(String(req.params.webhookId))}${queryStr}`;
|
|
242
|
+
const response = await fetch(forwardUrl, {
|
|
243
|
+
method: "POST",
|
|
244
|
+
headers: {
|
|
245
|
+
"Content-Type": "application/json",
|
|
246
|
+
...(req.headers.authorization ? { Authorization: req.headers.authorization } : {}),
|
|
247
|
+
...(req.headers["x-webhook-token"] ? { "x-webhook-token": String(req.headers["x-webhook-token"]) } : {}),
|
|
248
|
+
},
|
|
249
|
+
body: JSON.stringify(req.body ?? {}),
|
|
250
|
+
signal: AbortSignal.timeout(15000),
|
|
251
|
+
});
|
|
252
|
+
const data = await response.json().catch(() => ({}));
|
|
253
|
+
res.status(response.status).json(data);
|
|
254
|
+
}
|
|
255
|
+
catch (err) {
|
|
256
|
+
res.status(502).json({ error: err?.message ?? "Failed to forward webhook to hub" });
|
|
257
|
+
}
|
|
258
|
+
});
|
|
197
259
|
// Existing bookmarks now enter the native application view.
|
|
198
|
-
options.app.get("/devices",
|
|
260
|
+
options.app.get("/devices", guard, (_req, res) => {
|
|
199
261
|
res.redirect("./?view=devices");
|
|
200
262
|
});
|
|
201
|
-
options.app.use("/api/device-center",
|
|
263
|
+
options.app.use("/api/device-center", guard);
|
|
202
264
|
const hubSetup = installHubSetupRoutes(options.app, options.dataDir);
|
|
203
265
|
options.app.get("/api/device-center/status", (_req, res) => {
|
|
204
266
|
res.json({
|
|
205
267
|
name: config?.name ?? hostname(),
|
|
268
|
+
remark: config?.remark,
|
|
206
269
|
hubUrl: config?.hubUrl,
|
|
207
270
|
deviceId: config?.deviceId,
|
|
208
271
|
allowExecution: config?.allowExecution ?? false,
|
|
209
272
|
connected: connection?.isConnected?.() ?? false,
|
|
210
273
|
});
|
|
211
274
|
});
|
|
275
|
+
options.app.get("/api/device-center/execution-settings", (_req, res) => {
|
|
276
|
+
try {
|
|
277
|
+
const settings = loadExecutionSettings(options.dataDir);
|
|
278
|
+
res.json({ settings });
|
|
279
|
+
}
|
|
280
|
+
catch (error) {
|
|
281
|
+
res.status(500).json({ error: error.message });
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
options.app.get("/api/device-center/execution-queue", (_req, res) => {
|
|
285
|
+
try {
|
|
286
|
+
const currentRuntime = connection?.runtime;
|
|
287
|
+
if (currentRuntime) {
|
|
288
|
+
res.json(currentRuntime.getSchedulerSnapshot());
|
|
289
|
+
}
|
|
290
|
+
else {
|
|
291
|
+
const settings = loadExecutionSettings(options.dataDir);
|
|
292
|
+
res.json({
|
|
293
|
+
settings,
|
|
294
|
+
activeCount: 0,
|
|
295
|
+
waitingCount: 0,
|
|
296
|
+
blockedCount: 0,
|
|
297
|
+
running: [],
|
|
298
|
+
waiting: [],
|
|
299
|
+
blocked: [],
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
res.status(500).json({ error: error.message });
|
|
305
|
+
}
|
|
306
|
+
});
|
|
212
307
|
// Account chat discovery is safe to relay; local settings remain device-only.
|
|
213
308
|
options.app.get("/api/device-center/chat-status", async (_req, res) => {
|
|
214
309
|
try {
|
|
@@ -222,6 +317,78 @@ export async function installLocalDeviceCenter(options) {
|
|
|
222
317
|
});
|
|
223
318
|
const activeRequests = new Set();
|
|
224
319
|
let inFlight = 0;
|
|
320
|
+
let eventStreams = 0;
|
|
321
|
+
options.app.get("/api/device-center/rooms/:id/events", async (req, res) => {
|
|
322
|
+
try {
|
|
323
|
+
await serialize(ensureLocalHub);
|
|
324
|
+
}
|
|
325
|
+
catch {
|
|
326
|
+
res.sendStatus(503);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
const captured = activeConfig();
|
|
330
|
+
const capturedGeneration = generation;
|
|
331
|
+
if (!captured?.uiCredential) {
|
|
332
|
+
res.sendStatus(409);
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
if (closed || eventStreams >= 8) {
|
|
336
|
+
res.sendStatus(429);
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
const controller = new AbortController();
|
|
340
|
+
activeRequests.add(controller);
|
|
341
|
+
eventStreams++;
|
|
342
|
+
const cancel = () => controller.abort();
|
|
343
|
+
res.once("close", cancel);
|
|
344
|
+
req.once("aborted", cancel);
|
|
345
|
+
try {
|
|
346
|
+
const upstream = await fetch(`${captured.hubUrl}/api/device-user/rooms/${encodeURIComponent(String(req.params.id))}/events`, {
|
|
347
|
+
redirect: "error",
|
|
348
|
+
signal: controller.signal,
|
|
349
|
+
headers: { "X-Device-Id": captured.deviceId, Authorization: `Bearer ${captured.uiCredential}` },
|
|
350
|
+
});
|
|
351
|
+
if (!upstream.ok || !upstream.body || !upstream.headers.get("content-type")?.startsWith("text/event-stream")) {
|
|
352
|
+
await upstream.body?.cancel();
|
|
353
|
+
res.sendStatus(502);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (closed || generation !== capturedGeneration || activeConfig() !== captured)
|
|
357
|
+
return;
|
|
358
|
+
res.set({ "Content-Type": "text/event-stream", "Cache-Control": "no-store", "X-Accel-Buffering": "no" });
|
|
359
|
+
res.flushHeaders();
|
|
360
|
+
const reader = upstream.body.getReader();
|
|
361
|
+
try {
|
|
362
|
+
for (;;) {
|
|
363
|
+
const chunk = await reader.read();
|
|
364
|
+
if (chunk.done)
|
|
365
|
+
break;
|
|
366
|
+
if (closed ||
|
|
367
|
+
controller.signal.aborted ||
|
|
368
|
+
generation !== capturedGeneration ||
|
|
369
|
+
activeConfig() !== captured ||
|
|
370
|
+
chunk.value.byteLength > 65536 ||
|
|
371
|
+
!res.write(chunk.value))
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
finally {
|
|
376
|
+
await reader.cancel();
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
catch {
|
|
380
|
+
if (!res.headersSent && !res.destroyed)
|
|
381
|
+
res.sendStatus(502);
|
|
382
|
+
}
|
|
383
|
+
finally {
|
|
384
|
+
controller.abort();
|
|
385
|
+
activeRequests.delete(controller);
|
|
386
|
+
eventStreams--;
|
|
387
|
+
res.off("close", cancel);
|
|
388
|
+
req.off("aborted", cancel);
|
|
389
|
+
res.end();
|
|
390
|
+
}
|
|
391
|
+
});
|
|
225
392
|
function userRoute(method, path, fields) {
|
|
226
393
|
options.app[method](`/api/device-center/${path}`, async (req, res) => {
|
|
227
394
|
try {
|
|
@@ -258,8 +425,10 @@ export async function installLocalDeviceCenter(options) {
|
|
|
258
425
|
req.once("aborted", cancel);
|
|
259
426
|
res.once("close", cancel);
|
|
260
427
|
try {
|
|
261
|
-
const suffix = path.replace(
|
|
262
|
-
const
|
|
428
|
+
const suffix = path.replace(/:([A-Za-z]+)/g, (_match, key) => encodeURIComponent(String(req.params[key])));
|
|
429
|
+
const queryIndex = req.url.indexOf("?");
|
|
430
|
+
const queryStr = queryIndex >= 0 ? req.url.slice(queryIndex) : "";
|
|
431
|
+
const response = await fetch(`${captured.hubUrl}/api/device-user/${suffix}${queryStr}`, {
|
|
263
432
|
method: method.toUpperCase(),
|
|
264
433
|
redirect: "error",
|
|
265
434
|
signal: AbortSignal.any([controller.signal, AbortSignal.timeout(15000)]),
|
|
@@ -292,19 +461,43 @@ export async function installLocalDeviceCenter(options) {
|
|
|
292
461
|
if (closed || activeConfig() !== captured || generation !== capturedGeneration)
|
|
293
462
|
return res.status(409).json({ code: "DEVICE_CHANGED", error: "Device binding changed; refresh" });
|
|
294
463
|
if (!response.ok) {
|
|
295
|
-
|
|
296
|
-
|
|
464
|
+
let failure = null;
|
|
465
|
+
try {
|
|
466
|
+
const parsed = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
467
|
+
if (parsed && typeof parsed === "object")
|
|
468
|
+
failure = parsed;
|
|
469
|
+
}
|
|
470
|
+
catch {
|
|
471
|
+
failure = null;
|
|
472
|
+
}
|
|
473
|
+
const hubCode = typeof failure?.code === "string" && /^[A-Z0-9_]{1,40}$/.test(failure.code) ? failure.code : undefined;
|
|
474
|
+
const hubMessage = typeof failure?.error === "string" && failure.error.trim()
|
|
475
|
+
? scrubHubMessage(failure.error, [captured.uiCredential, captured.credential]) || undefined
|
|
476
|
+
: undefined;
|
|
477
|
+
if (response.status === 409 && (hubCode === "ACTIVE_TASKS" || hubMessage === "ACTIVE_TASKS"))
|
|
297
478
|
return res.status(409).json({
|
|
298
479
|
code: "ACTIVE_TASKS",
|
|
299
|
-
error: "Stop active tasks before removing members or deleting this group",
|
|
480
|
+
error: "Stop active tasks before removing members, clearing messages or deleting this group",
|
|
300
481
|
});
|
|
301
482
|
const status = [400, 401, 403, 404, 409, 429].includes(response.status) ? response.status : 502;
|
|
302
483
|
return res.status(status === 401 ? 409 : status).json({
|
|
303
484
|
code: status === 401 ? "REPAIR_REQUIRED" : status === 403 ? "HUB_FORBIDDEN" : "HUB_REJECTED",
|
|
304
|
-
|
|
485
|
+
// Forward the hub's own diagnosis: a fixed "rejected" string erases the real cause
|
|
486
|
+
// ("Task missing", "Plan conversation unavailable", …) and makes the UI undebuggable.
|
|
487
|
+
error: status === 401 ? "Pair this computer again" : (hubMessage ?? "Hub rejected group request"),
|
|
488
|
+
hubStatus: response.status,
|
|
489
|
+
...(hubCode ? { hubCode } : {}),
|
|
305
490
|
});
|
|
306
491
|
}
|
|
307
492
|
const data = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
493
|
+
if (path === "devices/:id/remark" &&
|
|
494
|
+
String(req.params.id) === captured.deviceId &&
|
|
495
|
+
config) {
|
|
496
|
+
const rawRemark = req.body?.remark;
|
|
497
|
+
const remark = typeof rawRemark === "string" ? rawRemark.trim().slice(0, 80) : "";
|
|
498
|
+
config = { ...config, remark: remark || undefined };
|
|
499
|
+
void persist(config);
|
|
500
|
+
}
|
|
308
501
|
res.status(response.status).json(data);
|
|
309
502
|
}
|
|
310
503
|
catch {
|
|
@@ -324,6 +517,65 @@ export async function installLocalDeviceCenter(options) {
|
|
|
324
517
|
options.app.get("/api/device-center/local-bots", (_req, res) => {
|
|
325
518
|
res.json({ bots: bots.list() });
|
|
326
519
|
});
|
|
520
|
+
options.app.get("/api/device-center/local-bots/:id", (req, res) => {
|
|
521
|
+
res.setHeader("Cache-Control", "no-store");
|
|
522
|
+
const bot = bots.get(String(req.params.id));
|
|
523
|
+
if (!bot) {
|
|
524
|
+
res.status(404).json({ code: "BOT_MISSING", error: "Bot is not configured on this device" });
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
res.json({ bot });
|
|
528
|
+
});
|
|
529
|
+
options.app.post("/api/device-center/local-bots/:id/preset", (req, res) => {
|
|
530
|
+
const controller = new AbortController();
|
|
531
|
+
const cancel = () => {
|
|
532
|
+
if (!res.writableEnded)
|
|
533
|
+
controller.abort();
|
|
534
|
+
};
|
|
535
|
+
req.once("aborted", cancel);
|
|
536
|
+
res.once("close", cancel);
|
|
537
|
+
void serialize(async () => {
|
|
538
|
+
if (closed)
|
|
539
|
+
throw new DeviceWorkspaceError(409, "CLOSED", "Device center is shutting down");
|
|
540
|
+
const input = req.body;
|
|
541
|
+
if (!input ||
|
|
542
|
+
typeof input !== "object" ||
|
|
543
|
+
Array.isArray(input) ||
|
|
544
|
+
Object.keys(input).some((key) => !["revision", "preset"].includes(key)))
|
|
545
|
+
throw new DeviceWorkspaceError(400, "BOT_PRESET_INVALID", "Expected revision and preset");
|
|
546
|
+
const bot = bots.get(String(req.params.id));
|
|
547
|
+
if (!bot)
|
|
548
|
+
throw new DeviceWorkspaceError(404, "BOT_MISSING", "Bot is not configured on this device");
|
|
549
|
+
if (input.revision !== bot.revision)
|
|
550
|
+
throw new DeviceWorkspaceError(409, "BOT_STALE", "Reload the current Bot revision before saving");
|
|
551
|
+
const catalog = await getLocalBotOptions(options.botCatalog ?? { defaultCwd: process.cwd(), dataDir: options.dataDir }, bot.cwd, controller.signal);
|
|
552
|
+
const next = applyLocalBotPreset(bot, input.preset, catalog);
|
|
553
|
+
controller.signal.throwIfAborted();
|
|
554
|
+
const saved = await bots.upsert(next);
|
|
555
|
+
try {
|
|
556
|
+
await syncBots();
|
|
557
|
+
return { bot: saved, synced: true };
|
|
558
|
+
}
|
|
559
|
+
catch {
|
|
560
|
+
return { bot: saved, synced: false };
|
|
561
|
+
}
|
|
562
|
+
})
|
|
563
|
+
.then((data) => {
|
|
564
|
+
if (!controller.signal.aborted)
|
|
565
|
+
res.json(data);
|
|
566
|
+
}, (error) => {
|
|
567
|
+
if (controller.signal.aborted)
|
|
568
|
+
return;
|
|
569
|
+
const known = error instanceof DeviceWorkspaceError;
|
|
570
|
+
res
|
|
571
|
+
.status(known ? error.status : 500)
|
|
572
|
+
.json({ code: known ? error.code : "BOT_FAILED", error: known ? error.message : "Bot preset save failed" });
|
|
573
|
+
})
|
|
574
|
+
.finally(() => {
|
|
575
|
+
req.off("aborted", cancel);
|
|
576
|
+
res.off("close", cancel);
|
|
577
|
+
});
|
|
578
|
+
});
|
|
327
579
|
function botMutation(remove) {
|
|
328
580
|
return (req, res) => {
|
|
329
581
|
void serialize(async () => {
|
|
@@ -413,11 +665,89 @@ export async function installLocalDeviceCenter(options) {
|
|
|
413
665
|
userRoute("get", "bots", []);
|
|
414
666
|
userRoute("get", "devices", []);
|
|
415
667
|
userRoute("post", "devices/:id/open", []);
|
|
668
|
+
userRoute("post", "devices/:id/remark", ["remark"]);
|
|
416
669
|
userRoute("get", "rooms", []);
|
|
417
670
|
userRoute("get", "rooms/:id", []);
|
|
418
|
-
userRoute("post", "rooms", ["
|
|
671
|
+
userRoute("post", "rooms/:id/canvas", ["binding"]);
|
|
672
|
+
userRoute("get", "rooms/:id/tasks/:taskId", []);
|
|
673
|
+
userRoute("get", "rooms/:id/tasks/:taskId/journal", []);
|
|
674
|
+
userRoute("get", "rooms/:id/tasks/:taskId/report", []);
|
|
675
|
+
userRoute("post", "rooms/:id/tasks/:taskId/report", [
|
|
676
|
+
"chunkIndex",
|
|
677
|
+
"totalChunks",
|
|
678
|
+
"text",
|
|
679
|
+
"attemptId",
|
|
680
|
+
"isFinal",
|
|
681
|
+
"sha256",
|
|
682
|
+
]);
|
|
683
|
+
userRoute("post", "rooms/:id/tasks/:taskId/approve-plan", []);
|
|
684
|
+
userRoute("get", "rooms/:id/interactions", []);
|
|
685
|
+
userRoute("post", "rooms/:id/interactions", [
|
|
686
|
+
"taskId",
|
|
687
|
+
"attemptId",
|
|
688
|
+
"interactionId",
|
|
689
|
+
"answers",
|
|
690
|
+
"cancelled",
|
|
691
|
+
"decision",
|
|
692
|
+
]);
|
|
693
|
+
userRoute("get", "rooms/:id/conversations", []);
|
|
694
|
+
userRoute("get", "rooms/:id/conversations/:conversationId", []);
|
|
695
|
+
userRoute("post", "rooms/:id/conversations", ["name", "targetBotId", "text", "idempotencyKey", "planOnly"]);
|
|
696
|
+
userRoute("post", "rooms/:id/conversations/:conversationId/messages", [
|
|
697
|
+
"text",
|
|
698
|
+
"kind",
|
|
699
|
+
"requestId",
|
|
700
|
+
"attentionId",
|
|
701
|
+
"idempotencyKey",
|
|
702
|
+
"planOnly",
|
|
703
|
+
]);
|
|
704
|
+
userRoute("post", "rooms/:id/conversations/:conversationId/deliveries", [
|
|
705
|
+
"repository",
|
|
706
|
+
"baseCommit",
|
|
707
|
+
"commit",
|
|
708
|
+
"branch",
|
|
709
|
+
"summary",
|
|
710
|
+
"checks",
|
|
711
|
+
"limitations",
|
|
712
|
+
"idempotencyKey",
|
|
713
|
+
]);
|
|
714
|
+
userRoute("post", "rooms/:id/conversations/:conversationId/reviews", [
|
|
715
|
+
"deliveryId",
|
|
716
|
+
"commit",
|
|
717
|
+
"verdict",
|
|
718
|
+
"summary",
|
|
719
|
+
"idempotencyKey",
|
|
720
|
+
]);
|
|
721
|
+
userRoute("get", "rooms/:id/conversations/:conversationId/integrations", []);
|
|
722
|
+
userRoute("post", "rooms/:id/conversations/:conversationId/integrations", [
|
|
723
|
+
"deliveryId",
|
|
724
|
+
"targetBotId",
|
|
725
|
+
"targetBranch",
|
|
726
|
+
"idempotencyKey",
|
|
727
|
+
]);
|
|
728
|
+
userRoute("post", "rooms/:id/conversations/:conversationId/integrations/:integrationId/verify", ["commands"]);
|
|
729
|
+
userRoute("post", "rooms/:id/conversations/:conversationId/integrations/:integrationId/apply", ["expectedTargetSha"]);
|
|
730
|
+
userRoute("post", "rooms/:id/conversations/:conversationId/integrations/:integrationId/cancel", []);
|
|
731
|
+
userRoute("get", "rooms/:id/transfers", []);
|
|
732
|
+
userRoute("post", "rooms/:id/transfers/start", [
|
|
733
|
+
"sourceBotId",
|
|
734
|
+
"targetBotId",
|
|
735
|
+
"paths",
|
|
736
|
+
"recursive",
|
|
737
|
+
"idempotencyKey",
|
|
738
|
+
]);
|
|
739
|
+
userRoute("get", "rooms/:id/transfers/:transferId/preview", []);
|
|
740
|
+
userRoute("post", "rooms/:id/transfers/:transferId/resume", [
|
|
741
|
+
"manifestHash",
|
|
742
|
+
"sourceBotRevision",
|
|
743
|
+
"targetBotRevision",
|
|
744
|
+
]);
|
|
745
|
+
userRoute("post", "rooms/:id/transfers/:transferId/apply", ["revision", "overwritePaths"]);
|
|
746
|
+
userRoute("post", "rooms/:id/transfers/:transferId/abort", []);
|
|
747
|
+
userRoute("post", "rooms", ["name", "botIds", "primaryBotId"]);
|
|
419
748
|
userRoute("post", "rooms/:id/rename", ["name"]);
|
|
420
|
-
userRoute("post", "rooms/:id/members", ["botIds"]);
|
|
749
|
+
userRoute("post", "rooms/:id/members", ["botIds", "primaryBotId"]);
|
|
750
|
+
userRoute("post", "rooms/:id/clear", []);
|
|
421
751
|
userRoute("post", "rooms/:id/delete", []);
|
|
422
752
|
userRoute("post", "rooms/:id/messages", [
|
|
423
753
|
"text",
|
|
@@ -426,7 +756,32 @@ export async function installLocalDeviceCenter(options) {
|
|
|
426
756
|
"idempotencyKey",
|
|
427
757
|
"handoff",
|
|
428
758
|
"parentTaskId",
|
|
759
|
+
"planOnly",
|
|
429
760
|
]);
|
|
761
|
+
userRoute("get", "rooms/:id/webhooks", []);
|
|
762
|
+
userRoute("post", "rooms/:id/webhooks", [
|
|
763
|
+
"name",
|
|
764
|
+
"type",
|
|
765
|
+
"enabled",
|
|
766
|
+
"allowBotTrigger",
|
|
767
|
+
"url",
|
|
768
|
+
"secret",
|
|
769
|
+
"events",
|
|
770
|
+
"relayViaHub",
|
|
771
|
+
]);
|
|
772
|
+
userRoute("post", "rooms/:id/webhooks/:webhookId", [
|
|
773
|
+
"name",
|
|
774
|
+
"enabled",
|
|
775
|
+
"allowBotTrigger",
|
|
776
|
+
"url",
|
|
777
|
+
"secret",
|
|
778
|
+
"events",
|
|
779
|
+
"relayViaHub",
|
|
780
|
+
]);
|
|
781
|
+
userRoute("post", "rooms/:id/webhooks/:webhookId/regenerate-token", []);
|
|
782
|
+
userRoute("post", "rooms/:id/webhooks/:webhookId/delete", []);
|
|
783
|
+
userRoute("post", "rooms/:id/webhooks/:webhookId/test", []);
|
|
784
|
+
userRoute("post", "rooms/:id/hub-relay", ["hubRelayBaseUrl"]);
|
|
430
785
|
function route(path, work) {
|
|
431
786
|
options.app.post(`/api/device-center/${path}`, (req, res) => {
|
|
432
787
|
void serialize(async () => {
|
|
@@ -493,6 +848,40 @@ export async function installLocalDeviceCenter(options) {
|
|
|
493
848
|
await reconnect();
|
|
494
849
|
return { saved: true };
|
|
495
850
|
});
|
|
851
|
+
route("remark", async (req) => {
|
|
852
|
+
if (!config)
|
|
853
|
+
throw new Error("Pair this computer first");
|
|
854
|
+
const rawRemark = req.body?.remark;
|
|
855
|
+
if (rawRemark !== null && rawRemark !== undefined && typeof rawRemark !== "string")
|
|
856
|
+
throw new Error("Invalid remark");
|
|
857
|
+
const remark = typeof rawRemark === "string" ? rawRemark.trim().slice(0, 80) : "";
|
|
858
|
+
const next = { ...config, remark: remark || undefined };
|
|
859
|
+
await persist(next);
|
|
860
|
+
config = next;
|
|
861
|
+
return { saved: true, remark: next.remark };
|
|
862
|
+
});
|
|
863
|
+
route("execution-settings", async (req) => {
|
|
864
|
+
const boundConnection = connection;
|
|
865
|
+
// Persist first, then apply to captured active runtime
|
|
866
|
+
const saved = saveExecutionSettings(options.dataDir, req.body);
|
|
867
|
+
if (boundConnection?.runtime) {
|
|
868
|
+
boundConnection.runtime.updateExecutionSettings(saved);
|
|
869
|
+
}
|
|
870
|
+
return { settings: saved };
|
|
871
|
+
});
|
|
872
|
+
route("execution-queue/cancel", async (req) => {
|
|
873
|
+
const boundConnection = connection;
|
|
874
|
+
const taskId = req.body?.taskId;
|
|
875
|
+
const attemptId = req.body?.attemptId;
|
|
876
|
+
if (typeof taskId !== "string" || !taskId) {
|
|
877
|
+
throw new Error("taskId is required");
|
|
878
|
+
}
|
|
879
|
+
if (attemptId !== undefined && (typeof attemptId !== "string" || !attemptId)) {
|
|
880
|
+
throw new Error("attemptId must be a string");
|
|
881
|
+
}
|
|
882
|
+
const cancelled = boundConnection?.runtime?.cancelScheduledTask(taskId, attemptId) ?? false;
|
|
883
|
+
return { cancelled };
|
|
884
|
+
});
|
|
496
885
|
route("disconnect", async () => {
|
|
497
886
|
await persist(undefined);
|
|
498
887
|
generation++;
|
|
@@ -49,10 +49,18 @@ export async function startDeviceHub(env = process.env) {
|
|
|
49
49
|
authenticateDevice: (id, credential) => hub.store.authenticateDevice(id, credential),
|
|
50
50
|
getAccount: (req) => hub.getRelayAccount(req),
|
|
51
51
|
ownsDevice: (accountId, id) => hub.store.getDeviceOwner(id) === accountId,
|
|
52
|
+
getDeviceName: (id) => hub.store.getDevice(id)?.name,
|
|
52
53
|
onTaskEvent: (id, event) => hub.acceptTaskEvent(id, event).then(() => undefined),
|
|
54
|
+
onTaskInteractions: (id, event) => hub.acceptInteractions(id, event),
|
|
55
|
+
onTaskProgress: (id, event) => hub.acceptTaskProgress(id, event),
|
|
56
|
+
onTaskToolLifecycle: (id, frame) => hub.acceptTaskToolLifecycle(id, frame),
|
|
57
|
+
onTaskPlanReady: (id, frame) => hub.acceptTaskPlanReady(id, frame),
|
|
58
|
+
onTaskClaim: (id, claim) => hub.claimTask(id, claim),
|
|
59
|
+
onTaskLeaseRenew: (id, renew) => hub.renewTaskLease(id, renew),
|
|
60
|
+
onTaskDisconnect: (id, taskId, attemptId) => hub.onTaskDisconnect(id, taskId, attemptId),
|
|
53
61
|
});
|
|
54
62
|
hub.setRelay(relay);
|
|
55
|
-
await installDeviceTransfers({
|
|
63
|
+
const transfers = await installDeviceTransfers({
|
|
56
64
|
app: hub.app,
|
|
57
65
|
hub,
|
|
58
66
|
dataDir: resolve(env.PI_DEVICE_HUB_DATA_DIR ?? join(homedir(), ".pi-device-hub")),
|
|
@@ -91,6 +99,7 @@ export async function startDeviceHub(env = process.env) {
|
|
|
91
99
|
await listen(hub.server, port);
|
|
92
100
|
}
|
|
93
101
|
catch (error) {
|
|
102
|
+
await transfers.close();
|
|
94
103
|
relay.close();
|
|
95
104
|
await closePortals();
|
|
96
105
|
await hub.close();
|
|
@@ -110,6 +119,7 @@ export async function startDeviceHub(env = process.env) {
|
|
|
110
119
|
...hub,
|
|
111
120
|
portals,
|
|
112
121
|
async close() {
|
|
122
|
+
await transfers.close();
|
|
113
123
|
relay?.close();
|
|
114
124
|
await closePortals();
|
|
115
125
|
await hub.close();
|