pi-web-ui 0.114.3 → 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.
- package/CHANGELOG.md +33 -1
- package/bin/pi-web-ui.mjs +69 -7
- package/dist/server/agent-service-daemon.js +440 -32
- package/dist/server/agent-service.js +849 -378
- package/dist/server/canvas/canvas-dispatch.js +13 -1
- package/dist/server/client-state.js +25 -0
- 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 +72 -9
- package/dist/server/device-center/bot-presets.js +46 -0
- package/dist/server/device-center/collab-service.js +328 -10
- package/dist/server/device-center/collab-tool.js +738 -12
- 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 +19 -0
- package/dist/server/device-center/execution-settings.js +100 -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 +389 -40
- package/dist/server/device-center/file-sync-paths.js +171 -0
- package/dist/server/device-center/file-sync.js +180 -91
- package/dist/server/device-center/group-context-delta.js +37 -0
- package/dist/server/device-center/group-context-message.js +208 -0
- package/dist/server/device-center/group-context.js +109 -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 +178 -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.js +1544 -80
- 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 +18 -0
- package/dist/server/device-center/local.js +356 -40
- package/dist/server/device-center/main.js +11 -1
- 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 +549 -41
- package/dist/server/device-center/store.js +66 -3
- 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 +400 -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 +815 -8
- package/dist/server/dispatch-domain-handlers.js +21 -3
- package/dist/server/dsh/dsh-agent-service.js +6 -0
- package/dist/server/goal-service.js +10 -5
- package/dist/server/index.js +89 -13
- package/dist/server/message-deletion.js +40 -0
- package/dist/server/message-window.js +9 -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 +1 -0
- 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 +5 -2
- package/dist/server/protocol-version.js +1 -1
- package/dist/server/protocol.js +2 -2
- 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/subagent-helpers.js +4 -1
- package/dist/server/subagents.js +50 -36
- package/dist/server/tool-host-factories.js +1 -0
- package/dist/server/universal/universal-session.js +5 -0
- package/dist/server/webui-context.js +25 -5
- package/docs/README.md +94 -0
- package/docs/device-center.md +100 -12
- package/docs/dsh-engine.md +10 -10
- package/extensions/webui.ts +43 -1
- package/package.json +1 -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-BYzPgmoq.js +1 -0
- package/web/dist/assets/BgTasksModal-ni0VTmAQ.js +1 -0
- package/web/dist/assets/{CanvasStudio-BSg9ghPV.js → CanvasStudio-BCUeEf25.js} +3 -3
- package/web/dist/assets/{CanvasStudio-DxW7C3Sz.js → CanvasStudio-DNmDNBod.js} +3 -3
- package/web/dist/assets/DeviceCenter-BcBhRgL6.js +3 -0
- package/web/dist/assets/DeviceCenter-CmL5FZmt.js +3 -0
- package/web/dist/assets/DeviceGroups-CLdpdnI7.js +1 -0
- package/web/dist/assets/DeviceGroups-CgBaDPrD.js +1 -0
- package/web/dist/assets/Dropdown-CGXD0DfT.js +1 -0
- package/web/dist/assets/FilePreview-B8iqnBjy.js +2 -0
- package/web/dist/assets/FilePreview-BqviZKCN.js +2 -0
- package/web/dist/assets/GlobalSearchModal-mevF-ySi.js +1 -0
- package/web/dist/assets/GlobalSearchModal-qL99FN_F.js +1 -0
- package/web/dist/assets/GroupConversation-B88Yy-lt.js +3 -0
- package/web/dist/assets/GroupConversation-BwP5NVOE.js +3 -0
- package/web/dist/assets/HintTip-LHwkS2jV.js +1 -0
- package/web/dist/assets/ModelConfigModal-Do3Fe3jH.js +2 -0
- package/web/dist/assets/PiSetupModal-DE5-gEtI.js +1 -0
- package/web/dist/assets/ProviderOAuthControls-6UMARucA.js +1 -0
- package/web/dist/assets/SCMPanel-Hi6QqC1Q.js +2 -0
- package/web/dist/assets/SCMPanel-ezY_ZtCu.js +2 -0
- package/web/dist/assets/SettingsModal-6HgeEsJ8.js +20 -0
- package/web/dist/assets/SettingsModal-CF-7MwqS.js +20 -0
- package/web/dist/assets/TerminalPanel-CTp_BZ4S.js +3 -0
- package/web/dist/assets/TerminalPanel-CkYxC-Gh.js +3 -0
- package/web/dist/assets/TuiOverlayModal-1cRLP8IF.js +1 -0
- package/web/dist/assets/TuiOverlayModal-2xlptqWX.js +1 -0
- package/web/dist/assets/app-globals-DZNa9v8u.js +325 -0
- package/web/dist/assets/canvas-client-Bye9nSFO.js +1 -0
- package/web/dist/assets/{desktop-7EvUHhKQ.js → desktop-kjBoE3Nu.js} +1 -1
- package/web/dist/assets/group-view-state-CGCzYF8k.js +1 -0
- package/web/dist/assets/index-CsFs_HMb.css +1 -0
- package/web/dist/assets/index-DHeeHS_l.js +85 -0
- package/web/dist/assets/index-DTZch8uz.js +85 -0
- package/web/dist/assets/plugin-host-C8mNgghx.js +1 -0
- package/web/dist/assets/remote-ssh-client-CeP3CLUW.js +1 -0
- package/web/dist/assets/theme-BXGpyTMh.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
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import http, {} from "node:http";
|
|
2
|
+
import { projectTaskActivity } from "./task-progress.js";
|
|
2
3
|
import https from "node:https";
|
|
3
4
|
import { WebSocket } from "ws";
|
|
4
5
|
import { deviceTaskFailure } from "./task-error.js";
|
|
5
|
-
import {
|
|
6
|
+
import { uploadTaskReport } from "./report-upload.js";
|
|
7
|
+
import { reportUploadMetadata } from "./report-metadata.js";
|
|
8
|
+
import { checkedUrl, createCommandChannel, createWsMessageChannel, WS_MESSAGE_BYTES, cleanHeaders, decodeChunk, loopback, parseFrame, RELAY_LIMITS, safePath, sendFrame, } from "./relay.js";
|
|
9
|
+
import { validInteractionAnswer } from "./human-interaction.js";
|
|
6
10
|
export function createDeviceConnector(options) {
|
|
7
11
|
const hub = checkedUrl(options.hubUrl);
|
|
8
12
|
const local = new URL(options.localOrigin);
|
|
@@ -24,14 +28,26 @@ export function createDeviceConnector(options) {
|
|
|
24
28
|
endpoint.searchParams.set("deviceId", options.deviceId);
|
|
25
29
|
let closed = false;
|
|
26
30
|
let tasksDisabled = false;
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
const waitingForHumanTaskIds = new Set();
|
|
32
|
+
const planAcks = new Map();
|
|
33
|
+
const runningTasks = new Map();
|
|
34
|
+
function stopTasks(forceAll = false) {
|
|
35
|
+
for (const pending of planAcks.values())
|
|
36
|
+
pending.settle(false);
|
|
37
|
+
if (forceAll) {
|
|
38
|
+
tasksDisabled = true;
|
|
39
|
+
for (const task of runningTasks.values())
|
|
40
|
+
task.controller.abort();
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
// Passive network disconnect: ONLY retain tasks that have an active lease and recovery enabled!
|
|
44
|
+
// Tasks without leaseToken or without recovery cannot be claimed on reconnect; abort them.
|
|
45
|
+
for (const task of runningTasks.values()) {
|
|
46
|
+
if (!options.recovery || !task.leaseToken) {
|
|
47
|
+
task.controller.abort();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
35
51
|
try {
|
|
36
52
|
options.onDisconnect?.();
|
|
37
53
|
}
|
|
@@ -82,6 +98,38 @@ export function createDeviceConnector(options) {
|
|
|
82
98
|
catch { }
|
|
83
99
|
return undefined;
|
|
84
100
|
}
|
|
101
|
+
const reportUploads = new Map();
|
|
102
|
+
const reportAbort = new AbortController();
|
|
103
|
+
function uploadReport(entry) {
|
|
104
|
+
const key = `${entry.id}:${entry.attemptId}`;
|
|
105
|
+
const current = reportUploads.get(key);
|
|
106
|
+
if (current)
|
|
107
|
+
return current;
|
|
108
|
+
const outbox = options.reportOutbox;
|
|
109
|
+
if (!outbox || !entry.uploadPending || entry.rejected)
|
|
110
|
+
return Promise.resolve();
|
|
111
|
+
const operation = Promise.resolve()
|
|
112
|
+
.then(async () => {
|
|
113
|
+
try {
|
|
114
|
+
const text = outbox.read(entry);
|
|
115
|
+
await uploadTaskReport({ ...options, entry, text, signal: reportAbort.signal });
|
|
116
|
+
outbox.accepted(entry);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
outbox.failed(entry, error);
|
|
120
|
+
console.warn(`[Connector] Full report upload pending for task ${entry.id}: ${error instanceof Error && /^Report upload rejected: HTTP \d{3}$/.test(error.message) ? error.message : "upload or integrity check failed"}`);
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
.finally(() => reportUploads.delete(key));
|
|
124
|
+
reportUploads.set(key, operation);
|
|
125
|
+
return operation;
|
|
126
|
+
}
|
|
127
|
+
function retryReports() {
|
|
128
|
+
if (closed)
|
|
129
|
+
return;
|
|
130
|
+
for (const entry of options.reportOutbox?.pending() ?? [])
|
|
131
|
+
void uploadReport(entry).catch(() => console.warn("[Connector] Report outbox persistence failed; retry retained"));
|
|
132
|
+
}
|
|
85
133
|
function connect() {
|
|
86
134
|
if (closed)
|
|
87
135
|
return;
|
|
@@ -94,6 +142,7 @@ export function createDeviceConnector(options) {
|
|
|
94
142
|
socket = ws;
|
|
95
143
|
const rpc = createCommandChannel(ws, options.onCommand);
|
|
96
144
|
const messages = createWsMessageChannel(ws);
|
|
145
|
+
const cancellations = new Set();
|
|
97
146
|
ws.on("open", () => {
|
|
98
147
|
if (socket !== ws || closed) {
|
|
99
148
|
ws.terminate();
|
|
@@ -101,8 +150,53 @@ export function createDeviceConnector(options) {
|
|
|
101
150
|
}
|
|
102
151
|
attempts = 0;
|
|
103
152
|
tasksDisabled = false;
|
|
104
|
-
runningTasks.clear();
|
|
105
153
|
lastPong = Date.now();
|
|
154
|
+
retryReports();
|
|
155
|
+
// === Task Recovery / Reconnect Claim / Outbox Replay ===
|
|
156
|
+
const claimsToSend = new Map();
|
|
157
|
+
if (options.recovery) {
|
|
158
|
+
for (const claim of options.recovery.prepareClaims()) {
|
|
159
|
+
claimsToSend.set(`${claim.taskId}:${claim.attemptId}`, claim);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
for (const [taskId, running] of runningTasks) {
|
|
163
|
+
running.ws = ws;
|
|
164
|
+
claimsToSend.set(`${taskId}:${running.attemptId}`, {
|
|
165
|
+
taskId,
|
|
166
|
+
attemptId: running.attemptId,
|
|
167
|
+
botId: running.botId,
|
|
168
|
+
leaseToken: running.leaseToken,
|
|
169
|
+
leaseGeneration: running.leaseGeneration,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
for (const claim of claimsToSend.values()) {
|
|
173
|
+
sendFrame(ws, {
|
|
174
|
+
type: "task_claim",
|
|
175
|
+
taskId: claim.taskId,
|
|
176
|
+
attemptId: claim.attemptId,
|
|
177
|
+
botId: claim.botId,
|
|
178
|
+
leaseToken: claim.leaseToken,
|
|
179
|
+
leaseGeneration: claim.leaseGeneration,
|
|
180
|
+
claim,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
if (options.recovery) {
|
|
184
|
+
for (const item of options.recovery.getPendingOutbox()) {
|
|
185
|
+
options.recovery.markOutboxAttempt(item.id);
|
|
186
|
+
sendFrame(ws, {
|
|
187
|
+
type: "task_event",
|
|
188
|
+
taskId: item.taskId,
|
|
189
|
+
botId: item.botId,
|
|
190
|
+
attemptId: item.attemptId,
|
|
191
|
+
status: item.status,
|
|
192
|
+
...(item.report ? { report: item.report } : {}),
|
|
193
|
+
...(item.error ? { error: item.error } : {}),
|
|
194
|
+
...(item.reportMetadata ? { reportMetadata: item.reportMetadata } : {}),
|
|
195
|
+
...(item.fingerprint ? { fingerprint: item.fingerprint } : {}),
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
// =======================================================
|
|
106
200
|
void Promise.resolve()
|
|
107
201
|
.then(() => options.onConnect?.())
|
|
108
202
|
.catch(() => ws.close(1011, "Bot sync failed"));
|
|
@@ -117,6 +211,93 @@ export function createDeviceConnector(options) {
|
|
|
117
211
|
const frame = parseFrame(Buffer.from(raw));
|
|
118
212
|
if (rpc.handle(frame))
|
|
119
213
|
return;
|
|
214
|
+
// === Task Recovery / Reconnect Results ===
|
|
215
|
+
if (frame.type === "task_claim_result") {
|
|
216
|
+
if (typeof frame.taskId === "string" && typeof frame.attemptId === "string" && frame.accepted === false) {
|
|
217
|
+
const task = runningTasks.get(frame.taskId);
|
|
218
|
+
if (task && task.attemptId === frame.attemptId) {
|
|
219
|
+
task.controller.abort();
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
if (frame.type === "task_lease_result") {
|
|
225
|
+
if (typeof frame.taskId === "string" && typeof frame.attemptId === "string" && frame.accepted === false) {
|
|
226
|
+
const task = runningTasks.get(frame.taskId);
|
|
227
|
+
if (task && task.attemptId === frame.attemptId) {
|
|
228
|
+
task.controller.abort();
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return;
|
|
232
|
+
}
|
|
233
|
+
if (frame.type === "task_plan_ack") {
|
|
234
|
+
if (typeof frame.taskId === "string") {
|
|
235
|
+
const pending = planAcks.get(frame.taskId);
|
|
236
|
+
if (socket === ws &&
|
|
237
|
+
pending?.ws === ws &&
|
|
238
|
+
pending.botId === frame.botId &&
|
|
239
|
+
pending.attemptId === frame.attemptId)
|
|
240
|
+
pending.settle(frame.accepted === true);
|
|
241
|
+
}
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
if (frame.type === "task_result_ack") {
|
|
245
|
+
if (typeof frame.taskId === "string" && typeof frame.attemptId === "string") {
|
|
246
|
+
const fp = typeof frame.fingerprint === "string" ? frame.fingerprint : undefined;
|
|
247
|
+
options.recovery?.ackOutbox(frame.taskId, frame.attemptId, fp);
|
|
248
|
+
}
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
// =========================================
|
|
252
|
+
if (frame.type === "task_cancel") {
|
|
253
|
+
if (typeof frame.id !== "string" ||
|
|
254
|
+
!frame.id ||
|
|
255
|
+
frame.id.length > 128 ||
|
|
256
|
+
typeof frame.taskId !== "string" ||
|
|
257
|
+
typeof frame.attemptId !== "string" ||
|
|
258
|
+
cancellations.size >= RELAY_LIMITS.cancellations ||
|
|
259
|
+
cancellations.has(frame.id))
|
|
260
|
+
throw new Error("Invalid task cancellation");
|
|
261
|
+
const id = frame.id;
|
|
262
|
+
const task = runningTasks.get(frame.taskId);
|
|
263
|
+
const matched = task?.ws === ws && task.attemptId === frame.attemptId;
|
|
264
|
+
cancellations.add(frame.id);
|
|
265
|
+
if (matched)
|
|
266
|
+
task.controller.abort();
|
|
267
|
+
void (matched ? task.settled : Promise.resolve()).then(() => {
|
|
268
|
+
cancellations.delete(id);
|
|
269
|
+
if (socket === ws && !closed)
|
|
270
|
+
sendFrame(ws, {
|
|
271
|
+
type: "task_cancelled",
|
|
272
|
+
id: frame.id,
|
|
273
|
+
taskId: frame.taskId,
|
|
274
|
+
attemptId: frame.attemptId,
|
|
275
|
+
stopped: matched && !task.stopUnconfirmed,
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
if (frame.type === "task_interaction_answer") {
|
|
281
|
+
if (!validInteractionAnswer(frame.answer))
|
|
282
|
+
return;
|
|
283
|
+
const task = runningTasks.get(frame.answer.taskId);
|
|
284
|
+
if (socket !== ws ||
|
|
285
|
+
closed ||
|
|
286
|
+
!task ||
|
|
287
|
+
task.ws !== ws ||
|
|
288
|
+
task.controller.signal.aborted ||
|
|
289
|
+
task.attemptId !== frame.answer.attemptId)
|
|
290
|
+
return;
|
|
291
|
+
waitingForHumanTaskIds.delete(frame.answer.taskId);
|
|
292
|
+
let accepted = false;
|
|
293
|
+
try {
|
|
294
|
+
accepted = options.onInteractionAnswer?.(frame.answer) === true;
|
|
295
|
+
}
|
|
296
|
+
catch { }
|
|
297
|
+
if (typeof frame.id === "string" && frame.id.length <= 128)
|
|
298
|
+
sendFrame(ws, { type: "task_interaction_result", id: frame.id, accepted });
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
120
301
|
if (frame.type === "task") {
|
|
121
302
|
if (tasksDisabled)
|
|
122
303
|
throw new Error("Task executor disconnected");
|
|
@@ -132,34 +313,174 @@ export function createDeviceConnector(options) {
|
|
|
132
313
|
runningTasks.has(task.id) ||
|
|
133
314
|
runningTasks.size >= RELAY_LIMITS.streams)
|
|
134
315
|
throw new Error("Invalid task");
|
|
135
|
-
runningTasks.add(task.id);
|
|
136
316
|
const controller = new AbortController();
|
|
137
|
-
|
|
317
|
+
const leaseToken = typeof task.leaseToken === "string" ? task.leaseToken : "";
|
|
318
|
+
const leaseGeneration = Number.isSafeInteger(task.leaseGeneration) ? task.leaseGeneration : 1;
|
|
319
|
+
let sequence = 0;
|
|
320
|
+
let lastProgress = 0;
|
|
321
|
+
const execution = {
|
|
322
|
+
attemptId: task.attemptId,
|
|
323
|
+
botId: task.botId,
|
|
324
|
+
leaseToken,
|
|
325
|
+
leaseGeneration,
|
|
326
|
+
roomId: task.roomId,
|
|
327
|
+
ws,
|
|
328
|
+
controller,
|
|
329
|
+
settled: Promise.resolve(),
|
|
330
|
+
stopUnconfirmed: false,
|
|
331
|
+
};
|
|
332
|
+
runningTasks.set(task.id, execution);
|
|
333
|
+
const onProgress = (value) => {
|
|
334
|
+
options.recovery?.recordActivity(task.id, task.attemptId);
|
|
335
|
+
const activity = projectTaskActivity(value);
|
|
336
|
+
const activeWs = execution.ws;
|
|
337
|
+
if (!activity ||
|
|
338
|
+
!activeWs ||
|
|
339
|
+
activeWs.readyState !== WebSocket.OPEN ||
|
|
340
|
+
closed ||
|
|
341
|
+
controller.signal.aborted ||
|
|
342
|
+
runningTasks.get(task.id) !== execution ||
|
|
343
|
+
Date.now() - lastProgress < 250)
|
|
344
|
+
return;
|
|
345
|
+
lastProgress = Date.now();
|
|
346
|
+
sendFrame(activeWs, {
|
|
347
|
+
type: "task_progress",
|
|
348
|
+
taskId: task.id,
|
|
349
|
+
botId: task.botId,
|
|
350
|
+
attemptId: task.attemptId,
|
|
351
|
+
sequence: ++sequence,
|
|
352
|
+
...activity,
|
|
353
|
+
});
|
|
354
|
+
};
|
|
138
355
|
const emit = (status, report) => {
|
|
139
|
-
|
|
140
|
-
|
|
356
|
+
const activeWs = execution.ws;
|
|
357
|
+
if (activeWs &&
|
|
358
|
+
activeWs.readyState === WebSocket.OPEN &&
|
|
359
|
+
!closed &&
|
|
360
|
+
!controller.signal.aborted &&
|
|
361
|
+
runningTasks.get(task.id) === execution) {
|
|
362
|
+
const outboxItem = options.recovery
|
|
363
|
+
?.getPendingOutbox()
|
|
364
|
+
.find((e) => e.taskId === task.id && e.attemptId === task.attemptId);
|
|
365
|
+
sendFrame(activeWs, {
|
|
141
366
|
type: "task_event",
|
|
142
367
|
taskId: task.id,
|
|
143
368
|
botId: task.botId,
|
|
144
369
|
attemptId: task.attemptId,
|
|
145
370
|
status,
|
|
146
|
-
...(report ? { report
|
|
371
|
+
...(report ? { report } : {}),
|
|
372
|
+
...(status !== "running"
|
|
373
|
+
? { reportMetadata: reportUploadMetadata(options.reportOutbox?.get(task)) }
|
|
374
|
+
: {}),
|
|
375
|
+
...(outboxItem?.fingerprint ? { fingerprint: outboxItem.fingerprint } : {}),
|
|
147
376
|
});
|
|
377
|
+
}
|
|
148
378
|
};
|
|
149
379
|
emit("running");
|
|
150
|
-
Promise.resolve()
|
|
380
|
+
execution.settled = Promise.resolve()
|
|
151
381
|
.then(() => {
|
|
152
382
|
if (!options.onTask)
|
|
153
383
|
throw new Error("Task handler unavailable");
|
|
154
384
|
if (controller.signal.aborted)
|
|
155
385
|
throw new Error("Task cancelled");
|
|
156
|
-
return options.onTask(task, controller.signal
|
|
386
|
+
return options.onTask(task, controller.signal, {
|
|
387
|
+
onStarted() { },
|
|
388
|
+
onActivity() {
|
|
389
|
+
options.recovery?.recordActivity(task.id, task.attemptId);
|
|
390
|
+
},
|
|
391
|
+
onProgress,
|
|
392
|
+
onPlanReady(taskId, plan) {
|
|
393
|
+
const activeWs = execution.ws;
|
|
394
|
+
if (taskId !== task.id ||
|
|
395
|
+
!activeWs ||
|
|
396
|
+
activeWs.readyState !== WebSocket.OPEN ||
|
|
397
|
+
controller.signal.aborted)
|
|
398
|
+
return Promise.resolve(false);
|
|
399
|
+
return new Promise((resolve) => {
|
|
400
|
+
const settle = (accepted) => {
|
|
401
|
+
clearTimeout(timer);
|
|
402
|
+
controller.signal.removeEventListener("abort", abort);
|
|
403
|
+
planAcks.delete(task.id);
|
|
404
|
+
resolve(accepted);
|
|
405
|
+
};
|
|
406
|
+
const abort = () => settle(false);
|
|
407
|
+
const timer = setTimeout(abort, 15_000);
|
|
408
|
+
planAcks.set(task.id, { ws: activeWs, botId: task.botId, attemptId: task.attemptId, settle });
|
|
409
|
+
controller.signal.addEventListener("abort", abort, { once: true });
|
|
410
|
+
sendFrame(activeWs, {
|
|
411
|
+
type: "task_plan_ready",
|
|
412
|
+
taskId,
|
|
413
|
+
botId: task.botId,
|
|
414
|
+
attemptId: task.attemptId,
|
|
415
|
+
plan,
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
},
|
|
419
|
+
onFullReport(taskId, attemptId, fullReport) {
|
|
420
|
+
if (taskId !== task.id || attemptId !== task.attemptId)
|
|
421
|
+
throw new Error("Report task binding mismatch");
|
|
422
|
+
if (!options.reportOutbox?.get(task))
|
|
423
|
+
options.reportOutbox?.capture(task, fullReport);
|
|
424
|
+
},
|
|
425
|
+
onToolLifecycle(lifecycle) {
|
|
426
|
+
options.recovery?.recordActivity(task.id, task.attemptId);
|
|
427
|
+
const activeWs = execution.ws;
|
|
428
|
+
if (activeWs &&
|
|
429
|
+
activeWs.readyState === WebSocket.OPEN &&
|
|
430
|
+
!closed &&
|
|
431
|
+
!controller.signal.aborted &&
|
|
432
|
+
runningTasks.get(task.id) === execution) {
|
|
433
|
+
sendFrame(activeWs, {
|
|
434
|
+
type: "task_tool_lifecycle",
|
|
435
|
+
taskId: task.id,
|
|
436
|
+
botId: task.botId,
|
|
437
|
+
attemptId: task.attemptId,
|
|
438
|
+
...lifecycle,
|
|
439
|
+
});
|
|
440
|
+
}
|
|
441
|
+
onProgress({
|
|
442
|
+
phase: "tool",
|
|
443
|
+
toolName: lifecycle.toolName,
|
|
444
|
+
text: lifecycle.outputSnippet || lifecycle.summary || `[Tool ${lifecycle.toolName} ${lifecycle.phase}]`,
|
|
445
|
+
});
|
|
446
|
+
},
|
|
447
|
+
onInteractions(items) {
|
|
448
|
+
options.recovery?.recordActivity(task.id, task.attemptId);
|
|
449
|
+
if (items && items.length > 0)
|
|
450
|
+
waitingForHumanTaskIds.add(task.id);
|
|
451
|
+
else
|
|
452
|
+
waitingForHumanTaskIds.delete(task.id);
|
|
453
|
+
const activeWs = execution.ws;
|
|
454
|
+
if (activeWs &&
|
|
455
|
+
activeWs.readyState === WebSocket.OPEN &&
|
|
456
|
+
!closed &&
|
|
457
|
+
!controller.signal.aborted &&
|
|
458
|
+
runningTasks.get(task.id) === execution)
|
|
459
|
+
sendFrame(activeWs, {
|
|
460
|
+
type: "task_interactions",
|
|
461
|
+
taskId: task.id,
|
|
462
|
+
attemptId: task.attemptId,
|
|
463
|
+
botId: task.botId,
|
|
464
|
+
items,
|
|
465
|
+
});
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
})
|
|
469
|
+
.then(async (result) => {
|
|
470
|
+
if (controller.signal.aborted)
|
|
471
|
+
return;
|
|
472
|
+
const safeReport = typeof result === "string" ? result : undefined;
|
|
473
|
+
const reportEntry = options.reportOutbox?.get(task) ?? options.reportOutbox?.markMissing(task);
|
|
474
|
+
if (reportEntry)
|
|
475
|
+
await uploadReport(reportEntry);
|
|
476
|
+
emit("completed", safeReport);
|
|
477
|
+
}, (error) => {
|
|
478
|
+
execution.stopUnconfirmed = !!error && typeof error === "object" && error.stopUnconfirmed === true;
|
|
479
|
+
emit("failed", deviceTaskFailure(error));
|
|
157
480
|
})
|
|
158
|
-
.then((result) => emit("completed", typeof result === "string" ? result : undefined), (error) => emit("failed", deviceTaskFailure(error)))
|
|
159
481
|
.finally(() => {
|
|
160
|
-
if (
|
|
482
|
+
if (runningTasks.get(task.id) === execution)
|
|
161
483
|
runningTasks.delete(task.id);
|
|
162
|
-
taskControllers.delete(controller);
|
|
163
484
|
});
|
|
164
485
|
return;
|
|
165
486
|
}
|
|
@@ -315,7 +636,7 @@ export function createDeviceConnector(options) {
|
|
|
315
636
|
if (socket !== ws)
|
|
316
637
|
return;
|
|
317
638
|
socket = undefined;
|
|
318
|
-
stopTasks();
|
|
639
|
+
stopTasks(false); // Retain running tasks locally across disconnects
|
|
319
640
|
for (const id of streams.keys())
|
|
320
641
|
dispose(id);
|
|
321
642
|
if (!closed) {
|
|
@@ -325,13 +646,27 @@ export function createDeviceConnector(options) {
|
|
|
325
646
|
}
|
|
326
647
|
});
|
|
327
648
|
}
|
|
328
|
-
const runningTasks = new Set();
|
|
329
649
|
const heartbeat = setInterval(() => {
|
|
330
650
|
if (socket?.readyState === WebSocket.OPEN) {
|
|
331
651
|
if (Date.now() - lastPong > 45_000)
|
|
332
652
|
socket.terminate();
|
|
333
653
|
else
|
|
334
654
|
socket.ping();
|
|
655
|
+
retryReports();
|
|
656
|
+
// === Heartbeat Lease Renewal ===
|
|
657
|
+
if (options.recovery) {
|
|
658
|
+
const renews = options.recovery.prepareLeaseRenews({ waitingForHumanTaskIds });
|
|
659
|
+
for (const renew of renews) {
|
|
660
|
+
sendFrame(socket, { type: "task_lease_renew", renew });
|
|
661
|
+
}
|
|
662
|
+
for (const [taskId, running] of runningTasks) {
|
|
663
|
+
const check = options.recovery.checkTaskTimeout(taskId, running.attemptId, waitingForHumanTaskIds.has(taskId));
|
|
664
|
+
if (check.expired) {
|
|
665
|
+
running.controller.abort();
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
// ===============================
|
|
335
670
|
}
|
|
336
671
|
}, 15_000);
|
|
337
672
|
heartbeat.unref();
|
|
@@ -340,7 +675,8 @@ export function createDeviceConnector(options) {
|
|
|
340
675
|
isOnline: () => socket?.readyState === WebSocket.OPEN,
|
|
341
676
|
close() {
|
|
342
677
|
closed = true;
|
|
343
|
-
|
|
678
|
+
reportAbort.abort();
|
|
679
|
+
stopTasks(true);
|
|
344
680
|
clearInterval(heartbeat);
|
|
345
681
|
clearTimeout(retry);
|
|
346
682
|
socket?.terminate();
|
|
@@ -3,15 +3,14 @@ export function desktopPage() {
|
|
|
3
3
|
return `<!doctype html>
|
|
4
4
|
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Remote desktop</title>
|
|
5
5
|
<style>
|
|
6
|
-
:root{color-scheme:dark;font-family:system-ui,sans-serif;background:#101827;color:#e5edf8}*{box-sizing:border-box}body{margin:0}main{display:flex;flex-direction:column;gap:
|
|
6
|
+
:root{color-scheme:dark;font-family:system-ui,sans-serif;background:#101827;color:#e5edf8}*{box-sizing:border-box}body{margin:0}main{display:flex;flex-direction:column;gap:0;min-width:0;min-height:0;max-width:100%;height:100dvh;padding:0;overflow:hidden}header,nav,form,.actions{display:flex;flex-wrap:wrap;align-items:center;gap:8px;min-width:0;max-width:100%}p{margin:0;font-size:13px;white-space:pre-wrap;overflow-wrap:anywhere;word-break:break-word}button,input{font:inherit;border:1px solid #657287;border-radius:5px;background:#202f45;color:#fff}button{padding:8px 12px;min-height:40px;cursor:pointer}button:disabled,input:disabled{opacity:.5;cursor:default}label{display:flex;align-items:center;gap:6px}input[type=checkbox]{width:18px;height:18px}input[type=text]{padding:8px;min-width:0;flex:1;width:160px}button:focus-visible,input:focus-visible,canvas:focus-visible{outline:2px solid #8cc8ff;outline-offset:2px}#setup{display:grid;gap:8px;border:1px solid #657287;border-radius:6px;padding:10px}#screen{flex:1;min-width:0;min-height:0;overflow:auto;background:#000;position:relative}main:fullscreen{width:100%;height:100%;background:#101827}canvas{display:block;width:100%;height:100%;object-fit:contain;touch-action:none;outline-offset:-3px}#screen.native canvas{width:auto;height:auto;max-width:none}#status[data-error=true]{color:#ffb4b4}#text-form label{font-size:13px}#text-form button{flex:none}
|
|
7
|
+
#toolbar{flex:none;flex-wrap:nowrap;gap:6px;min-height:32px;padding:3px 6px;border-bottom:1px solid #35445a;font-size:12px;overflow-x:auto}#controls{flex:none;flex-wrap:nowrap;gap:6px}#toolbar button{min-height:24px;padding:2px 7px;font-size:12px}#toolbar label{gap:3px;white-space:nowrap}#toolbar input[type=checkbox]{width:14px;height:14px;margin:0}summary{cursor:pointer;white-space:nowrap;padding:3px 6px;border:1px solid #657287;border-radius:5px}details{flex:none}#setup,#text-form{position:absolute;z-index:2;top:36px;left:6px;width:min(640px,calc(100% - 12px));max-height:calc(100dvh - 44px);overflow:auto;overscroll-behavior:contain;background:#101827;border:1px solid #657287;border-radius:6px;padding:10px;box-shadow:0 8px 24px #0008}#text-form{display:flex}#text-form label{width:100%}#status{font-size:12px;white-space:nowrap;flex:1;min-width:120px}#status[data-error=true]{position:absolute;z-index:1;top:36px;right:6px;max-width:min(640px,calc(100% - 12px));white-space:pre-wrap;background:#101827;border:1px solid #ffb4b4;border-radius:5px;padding:8px}summary:focus-visible{outline:2px solid #8cc8ff;outline-offset:2px}
|
|
7
8
|
</style></head><body><main>
|
|
8
|
-
<header><
|
|
9
|
-
<section id="setup" aria-label="Desktop setup"><p id="setup-status" role="status" aria-live="polite"></p><div class="actions"><button id="check" data-i18n="check"></button><button id="enable" disabled data-i18n="enable"></button><button id="disable" disabled data-i18n="disable"></button></div></section>
|
|
10
|
-
<
|
|
11
|
-
<
|
|
12
|
-
<p id="status" role="status" aria-live="polite"></p><p id="hint" data-i18n="hint"></p>
|
|
9
|
+
<header id="toolbar"><nav id="controls"><button id="connect" disabled data-i18n="connect"></button><button id="disconnect" disabled data-i18n="disconnect"></button><label><input id="viewonly" type="checkbox"><span data-i18n="viewonly"></span></label><label><input id="scale" type="checkbox" checked><span data-i18n="scale"></span></label><button id="fullscreen" data-i18n="fullscreen"></button></nav>
|
|
10
|
+
<details id="settings"><summary data-i18n="setup"></summary><section id="setup" aria-label="Desktop setup"><p id="setup-status" role="status" aria-live="polite"></p><div class="actions"><button id="check" data-i18n="check"></button><button id="enable" disabled data-i18n="enable"></button><button id="disable" disabled data-i18n="disable"></button></div><aside id="mac-permission-guide" hidden aria-label="macOS permissions"><p data-i18n="macGuide"></p></aside><p id="hint" data-i18n="hint"></p></section></details>
|
|
11
|
+
<details id="text-panel"><summary data-i18n="textToggle"></summary><form id="text-form"><label for="text" data-i18n="text"></label><input id="text" type="text" disabled autocomplete="off" maxlength="2048"><button id="send-text" type="submit" disabled data-i18n="send"></button></form></details>
|
|
12
|
+
<p id="status" role="status" aria-live="polite"></p></header>
|
|
13
13
|
<div id="screen"><canvas id="canvas" width="1" height="1" tabindex="0" aria-describedby="hint"></canvas></div>
|
|
14
|
-
<form id="text-form"><label for="text" data-i18n="text"></label><input id="text" type="text" disabled autocomplete="off" maxlength="2048"><button id="send-text" type="submit" disabled data-i18n="send"></button></form>
|
|
15
14
|
</main><script type="module">
|
|
16
15
|
const appUrl = path => new URL(path, document.baseURI);
|
|
17
16
|
const $ = id => document.getElementById(id);
|
|
@@ -19,9 +18,9 @@ const zh = (navigator.language || 'en').toLowerCase().startsWith('zh');
|
|
|
19
18
|
const messages = {
|
|
20
19
|
title:['设备远程桌面','Remote desktop'],connect:['连接','Connect'],disconnect:['断开','Disconnect'],
|
|
21
20
|
check:['检查状态','Check status'],enable:['启用','Enable'],disable:['停用','Disable'],setup:['桌面设置','Desktop setup'],
|
|
22
|
-
viewonly:['
|
|
23
|
-
text:['文字输入(支持中文)','Text input (including Chinese)'],send:['发送','Send'],
|
|
24
|
-
hint:['
|
|
21
|
+
viewonly:['只读','View only'],scale:['适应窗口','Fit to window'],fullscreen:['全屏','Fullscreen'],
|
|
22
|
+
textToggle:['文字输入','Text input'],text:['文字输入(支持中文)','Text input (including Chinese)'],send:['发送','Send'],
|
|
23
|
+
hint:['控制模式:点击画面后使用键盘;触屏可拖动,中文请用顶部文字输入发送。只读模式由服务端强制执行。','Control mode: focus the image to use the keyboard; drag with touch. Use Text input in the toolbar for composed text. View only is enforced by the server.'],
|
|
25
24
|
checking:['正在检查…','Checking…'],saving:['正在保存…','Saving…'],enabled:['已启用','Enabled'],disabled:['已停用','Disabled'],
|
|
26
25
|
macGuide:['请在被控 Mac 本机打开 pi-web-ui → 设备中心 → 本机远程桌面,点击“授予屏幕录制权限”或“授予远程控制权限”,并在系统弹窗或设置中确认。仅查看只需屏幕录制,控制还需辅助功能。远端连接不会触发授权或打开系统设置。系统可能不重复弹窗;请授权 macOS 列出的实际启动宿主,授权后按系统提示重启服务,再连接。不要在“+”文件选择器中猜选应用。','On the controlled Mac itself, open pi-web-ui → Device Center → Local remote desktop, then click Grant screen recording permission or Grant remote control permission and confirm in the system prompt or Settings. Viewing needs screen recording; control also needs Accessibility. Remote connections never request permission or open Settings. macOS may suppress repeat prompts. Authorize the actual launch host listed by macOS, restart the service if requested, then reconnect. Do not guess an app in the “+” file picker.'],
|
|
27
26
|
macScreenPermission:['被控 Mac 缺少屏幕录制权限。请在该 Mac 本机的设备中心 → 本机远程桌面点击“授予屏幕录制权限”,完成系统确认后重新连接。','Screen recording permission is required. On the controlled Mac itself, open Device Center → Local remote desktop and click Grant screen recording permission. Confirm in macOS, then reconnect.'],
|
|
@@ -59,7 +58,7 @@ function controls() {
|
|
|
59
58
|
$('enable').disabled = busy || !config || config.enabled || !config.supported;
|
|
60
59
|
$('disable').disabled = busy || !config?.enabled || config.environmentEnabled;
|
|
61
60
|
$('text').disabled = $('send-text').disabled = !canInput();
|
|
62
|
-
$('fullscreen').disabled = !
|
|
61
|
+
$('fullscreen').disabled = !document.querySelector('main').requestFullscreen;
|
|
63
62
|
}
|
|
64
63
|
function send(message) {
|
|
65
64
|
if (!canInput()) return false;
|
|
@@ -148,7 +147,7 @@ function applyConfig(next) {
|
|
|
148
147
|
if (!canConnect() && socket) stop();
|
|
149
148
|
if (!socket) status(t(!browserSupported ? 'browserError' : canConnect() ? 'ready' : 'unavailable'), !browserSupported);
|
|
150
149
|
}
|
|
151
|
-
async function update(enabled) {
|
|
150
|
+
async function update(enabled, autoConnect = false) {
|
|
152
151
|
if (busy || disposed) return;
|
|
153
152
|
busy = true; controls(); $('setup-status').textContent = t(enabled === undefined ? 'checking' : 'saving');
|
|
154
153
|
try {
|
|
@@ -159,9 +158,13 @@ async function update(enabled) {
|
|
|
159
158
|
let next;
|
|
160
159
|
try { next = await request('api/device-desktop/status'); }
|
|
161
160
|
catch { next = await request('api/device-desktop/setup/status'); }
|
|
162
|
-
if (!disposed)
|
|
161
|
+
if (!disposed) {
|
|
162
|
+
applyConfig(next);
|
|
163
|
+
if ((autoConnect || enabled === true) && canConnect()) connect();
|
|
164
|
+
if (!canConnect()) $('settings').open = true;
|
|
165
|
+
}
|
|
163
166
|
} catch (error) {
|
|
164
|
-
if (!disposed) { $('setup-status').textContent = t('requestError') + ': ' + error.message; status(t('requestError'), true); }
|
|
167
|
+
if (!disposed) { $('settings').open = true; $('setup-status').textContent = t('requestError') + ': ' + error.message; status(t('requestError'), true); }
|
|
165
168
|
} finally { busy = false; if (!disposed) controls(); }
|
|
166
169
|
}
|
|
167
170
|
// object-fit: contain can letterbox the canvas; normalize only the visible image.
|
|
@@ -221,12 +224,15 @@ $('check').onclick = () => void update();
|
|
|
221
224
|
$('enable').onclick = () => void update(true);
|
|
222
225
|
$('disable').onclick = () => void update(false);
|
|
223
226
|
$('viewonly').onchange = () => { if (socket) connect(); };
|
|
227
|
+
for (const id of ['settings', 'text-panel']) $(id).addEventListener('toggle', () => {
|
|
228
|
+
if ($(id).open) $(id === 'settings' ? 'text-panel' : 'settings').open = false;
|
|
229
|
+
});
|
|
224
230
|
$('scale').onchange = () => screen.classList.toggle('native', !$('scale').checked);
|
|
225
231
|
$('fullscreen').onclick = async () => {
|
|
226
|
-
try { if (document.fullscreenElement) await document.exitFullscreen(); else await
|
|
232
|
+
try { if (document.fullscreenElement) await document.exitFullscreen(); else await document.querySelector('main').requestFullscreen(); }
|
|
227
233
|
catch (error) { status(t('fullscreenError') + ': ' + error.message, true); }
|
|
228
234
|
};
|
|
229
235
|
window.addEventListener('pagehide', () => { disposed = true; stop(); });
|
|
230
|
-
controls(); void update();
|
|
236
|
+
controls(); void update(undefined, true);
|
|
231
237
|
</script></body></html>`;
|
|
232
238
|
}
|