@codingfrees/uap-device-control 0.1.5 → 0.1.7
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/README.md +1 -1
- package/dist/uap-device-control.mjs +203 -69
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ You can also provide the origin through `UAP_DEVICE_CONTROL_ORIGIN`.
|
|
|
28
28
|
npx @codingfrees/uap-device-control@latest remote
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
The interactive CLI uses concise human-readable status lines by default (`✅`, `❌`, `⚠️`, `🔐`, `🌐`, `🔌`, `🔧`). Use `--json` for stable JSONL output in scripts and log collectors.
|
|
31
|
+
The interactive CLI uses concise human-readable status lines by default (`✅`, `❌`, `⚠️`, `🔐`, `🌐`, `🔌`, `🔧`). Use `--json` for stable JSONL output in scripts and log collectors. Only one `remote` process may use a state directory at a time; starting a second process with the same device identity fails locally instead of replacing the live broker session. OAuth refresh is serialized across processes, and access-token renewal is retried in the existing broker session rather than forcing a device reconnect.
|
|
32
32
|
|
|
33
33
|
By default the Remote process also starts the loopback-only semantic browser bridge on port `8800`. Until the UAP Browser Extension is paired, the CLI prints a short-lived pairing code. Browser control can be disabled with `--no-browser-control` or moved to another loopback port with `--browser-port <port>`.
|
|
34
34
|
|
|
@@ -128,6 +128,66 @@ async function saveRemoteAuth(stateDirectory, value) {
|
|
|
128
128
|
async function clearRemoteAuth(stateDirectory) {
|
|
129
129
|
await rm(path.join(stateDirectory, "auth.json"), { force: true });
|
|
130
130
|
}
|
|
131
|
+
function acquireRemoteProcessLock(stateDirectory) {
|
|
132
|
+
return acquireStateLock(stateDirectory, "remote.lock", 0, "another UAP Device Control remote process is already running for this state directory");
|
|
133
|
+
}
|
|
134
|
+
async function withRemoteAuthRefreshLock(stateDirectory, task) {
|
|
135
|
+
const lease = await acquireStateLock(stateDirectory, "auth-refresh.lock", 2e4, "Device Control authorization refresh is busy");
|
|
136
|
+
try {
|
|
137
|
+
return await task();
|
|
138
|
+
} finally {
|
|
139
|
+
await lease.release();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async function acquireStateLock(stateDirectory, name, waitMs, busyMessage) {
|
|
143
|
+
await mkdir(stateDirectory, { recursive: true, mode: 448 });
|
|
144
|
+
const file = path.join(stateDirectory, name);
|
|
145
|
+
const owner = { pid: process.pid, token: randomUUID(), createdAt: Date.now() };
|
|
146
|
+
const deadline = Date.now() + waitMs;
|
|
147
|
+
for (; ; ) {
|
|
148
|
+
try {
|
|
149
|
+
await writeFile(file, JSON.stringify(owner), { encoding: "utf8", flag: "wx", mode: 384 });
|
|
150
|
+
return { release: () => removeOwnedLock(file, owner.token) };
|
|
151
|
+
} catch (error) {
|
|
152
|
+
if (!exists(error)) throw error;
|
|
153
|
+
}
|
|
154
|
+
const current = await readLock(file);
|
|
155
|
+
if (!current) throw new TypeError("Device Control state lock is invalid: " + file);
|
|
156
|
+
if (!processAlive(current.pid)) {
|
|
157
|
+
await removeOwnedLock(file, current.token);
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (Date.now() >= deadline) throw new TypeError(busyMessage);
|
|
161
|
+
await sleep(25);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async function readLock(file) {
|
|
165
|
+
try {
|
|
166
|
+
const raw = JSON.parse(await readFile(file, "utf8"));
|
|
167
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return void 0;
|
|
168
|
+
const value = raw;
|
|
169
|
+
if (!Number.isSafeInteger(value.pid) || Number(value.pid) < 1 || typeof value.token !== "string" || !/^[0-9a-f-]{36}$/.test(value.token) || !Number.isSafeInteger(value.createdAt)) return void 0;
|
|
170
|
+
return { pid: Number(value.pid), token: value.token, createdAt: Number(value.createdAt) };
|
|
171
|
+
} catch (error) {
|
|
172
|
+
if (missing(error)) return void 0;
|
|
173
|
+
return void 0;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async function removeOwnedLock(file, token) {
|
|
177
|
+
const current = await readLock(file);
|
|
178
|
+
if (current?.token === token) await rm(file, { force: true });
|
|
179
|
+
}
|
|
180
|
+
function processAlive(pid) {
|
|
181
|
+
try {
|
|
182
|
+
process.kill(pid, 0);
|
|
183
|
+
return true;
|
|
184
|
+
} catch (error) {
|
|
185
|
+
return !Boolean(error && typeof error === "object" && "code" in error && error.code === "ESRCH");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
function sleep(ms) {
|
|
189
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
190
|
+
}
|
|
131
191
|
function missing(error) {
|
|
132
192
|
return Boolean(error && typeof error === "object" && "code" in error && error.code === "ENOENT");
|
|
133
193
|
}
|
|
@@ -186,27 +246,30 @@ async function loginDeviceControl(origin, stateDirectory, options = {}) {
|
|
|
186
246
|
}
|
|
187
247
|
}
|
|
188
248
|
async function accessToken(stateDirectory, fetcher = fetch, forceRefresh = false) {
|
|
189
|
-
const
|
|
190
|
-
if (!
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
249
|
+
const observed = await requiredDeviceAuth(stateDirectory);
|
|
250
|
+
if (!forceRefresh && usableAccessToken(observed)) return { auth: observed, token: observed.accessToken };
|
|
251
|
+
return withRemoteAuthRefreshLock(stateDirectory, async () => {
|
|
252
|
+
const auth = await requiredDeviceAuth(stateDirectory);
|
|
253
|
+
const refreshedElsewhere = authorizationChanged(observed, auth);
|
|
254
|
+
if (usableAccessToken(auth) && (!forceRefresh || refreshedElsewhere)) return { auth, token: auth.accessToken };
|
|
255
|
+
const tokenEndpoint = new URL("/oauth/token", auth.origin);
|
|
256
|
+
const token = await json(
|
|
257
|
+
fetcher(tokenEndpoint, {
|
|
258
|
+
method: "POST",
|
|
259
|
+
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
260
|
+
body: new URLSearchParams({ grant_type: "refresh_token", client_id: auth.clientId, refresh_token: auth.refreshToken, resource: auth.origin + "/mcp" })
|
|
261
|
+
})
|
|
262
|
+
);
|
|
263
|
+
const next = {
|
|
264
|
+
...auth,
|
|
265
|
+
refreshToken: text(token.refresh_token, "OAuth refresh token"),
|
|
266
|
+
accessToken: text(token.access_token, "OAuth access token"),
|
|
267
|
+
accessExpiresAt: Date.now() + integer(token.expires_in, "OAuth expiry") * 1e3,
|
|
268
|
+
scope: typeof token.scope === "string" ? token.scope : auth.scope
|
|
269
|
+
};
|
|
270
|
+
await saveRemoteAuth(stateDirectory, next);
|
|
271
|
+
return { auth: next, token: next.accessToken };
|
|
272
|
+
});
|
|
210
273
|
}
|
|
211
274
|
async function logoutDeviceControl(stateDirectory, fetcher = fetch) {
|
|
212
275
|
const auth = await loadRemoteAuth(stateDirectory);
|
|
@@ -286,6 +349,18 @@ async function openBrowser(url) {
|
|
|
286
349
|
const launch = browserOpenCommand(process.platform, url);
|
|
287
350
|
await execute(launch.command, launch.args, { windowsHide: true });
|
|
288
351
|
}
|
|
352
|
+
async function requiredDeviceAuth(stateDirectory) {
|
|
353
|
+
const auth = await loadRemoteAuth(stateDirectory);
|
|
354
|
+
if (!auth) throw new TypeError("not logged in");
|
|
355
|
+
if (!auth.scope.split(" ").includes("device-control:device")) throw new TypeError("device authorization is required; run login again");
|
|
356
|
+
return auth;
|
|
357
|
+
}
|
|
358
|
+
function usableAccessToken(auth) {
|
|
359
|
+
return Boolean(auth.accessToken && auth.accessExpiresAt && auth.accessExpiresAt > Date.now() + 3e4);
|
|
360
|
+
}
|
|
361
|
+
function authorizationChanged(before, after) {
|
|
362
|
+
return before.accessToken !== after.accessToken || before.accessExpiresAt !== after.accessExpiresAt || before.refreshToken !== after.refreshToken;
|
|
363
|
+
}
|
|
289
364
|
async function json(response) {
|
|
290
365
|
const value = await response;
|
|
291
366
|
if (!value.ok) {
|
|
@@ -325,6 +400,31 @@ function integer(value, label) {
|
|
|
325
400
|
import os3 from "node:os";
|
|
326
401
|
import path4 from "node:path";
|
|
327
402
|
|
|
403
|
+
// package.json
|
|
404
|
+
var package_default = {
|
|
405
|
+
name: "@codingfrees/uap-device-control",
|
|
406
|
+
version: "0.1.7",
|
|
407
|
+
description: "Cross-platform outbound UAP Device Control client",
|
|
408
|
+
type: "module",
|
|
409
|
+
bin: {
|
|
410
|
+
"uap-device-control": "dist/uap-device-control.mjs"
|
|
411
|
+
},
|
|
412
|
+
files: [
|
|
413
|
+
"dist/"
|
|
414
|
+
],
|
|
415
|
+
engines: {
|
|
416
|
+
node: ">=26.8.1 <27"
|
|
417
|
+
},
|
|
418
|
+
publishConfig: {
|
|
419
|
+
access: "public"
|
|
420
|
+
},
|
|
421
|
+
scripts: {
|
|
422
|
+
build: 'pnpm exec esbuild src/bin.ts --bundle --platform=node --format=esm --target=node26 --outfile=dist/uap-device-control.mjs --banner:js="#!/usr/bin/env node"',
|
|
423
|
+
prepack: "pnpm run build",
|
|
424
|
+
"publish:public": "node scripts/publish.mjs"
|
|
425
|
+
}
|
|
426
|
+
};
|
|
427
|
+
|
|
328
428
|
// ../device-agent/src/engine.ts
|
|
329
429
|
import { spawn } from "node:child_process";
|
|
330
430
|
import { cp, mkdir as mkdir2, readdir, readFile as readFile2, realpath, rename as rename2, rm as rm2, stat, writeFile as writeFile2 } from "node:fs/promises";
|
|
@@ -336,6 +436,7 @@ var DeviceAgentEngine = class {
|
|
|
336
436
|
constructor(options) {
|
|
337
437
|
this.options = options;
|
|
338
438
|
if (!/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/.test(options.deviceId)) throw new TypeError("device id is invalid");
|
|
439
|
+
if (options.agentVersion !== void 0 && !/^[0-9A-Za-z][0-9A-Za-z._+-]{0,119}$/.test(options.agentVersion)) throw new TypeError("device agent version is invalid");
|
|
339
440
|
this.#maxTransfer = bounded(options.maxTransferBytes ?? 8 * 1024 * 1024, 1024, 64 * 1024 * 1024, "transfer limit");
|
|
340
441
|
this.#maxOutput = bounded(options.maxOutputBytes ?? 1024 * 1024, 1024, 8 * 1024 * 1024, "output limit");
|
|
341
442
|
this.#maxProcesses = bounded(options.maxProcesses ?? 8, 1, 64, "process limit");
|
|
@@ -413,7 +514,7 @@ var DeviceAgentEngine = class {
|
|
|
413
514
|
status: "online",
|
|
414
515
|
os: os2.platform(),
|
|
415
516
|
architecture: os2.arch(),
|
|
416
|
-
agentVersion: "0.1.0",
|
|
517
|
+
agentVersion: this.options.agentVersion ?? "0.1.0",
|
|
417
518
|
lastSeen: Date.now(),
|
|
418
519
|
capabilities: [...this.capabilities],
|
|
419
520
|
activeSessions: this.#sessions.size
|
|
@@ -1599,6 +1700,7 @@ function secureEqual(left, right) {
|
|
|
1599
1700
|
}
|
|
1600
1701
|
|
|
1601
1702
|
// src/remote.ts
|
|
1703
|
+
var UAP_DEVICE_CONTROL_AGENT_VERSION = package_default.version;
|
|
1602
1704
|
async function runRemote(options) {
|
|
1603
1705
|
const fetcher = options.fetcher ?? fetch;
|
|
1604
1706
|
const deviceId = await loadRemoteDeviceId(options.stateDirectory);
|
|
@@ -1619,6 +1721,7 @@ async function runRemote(options) {
|
|
|
1619
1721
|
const engine = new DeviceAgentEngine({
|
|
1620
1722
|
deviceId,
|
|
1621
1723
|
name: os3.hostname(),
|
|
1724
|
+
agentVersion: UAP_DEVICE_CONTROL_AGENT_VERSION,
|
|
1622
1725
|
roots: options.roots,
|
|
1623
1726
|
...options.allowedExecutables.length ? { allowedExecutables: options.allowedExecutables } : {},
|
|
1624
1727
|
...services ? { services, allowedServices: options.allowedServices } : {},
|
|
@@ -1641,15 +1744,17 @@ async function runRemote(options) {
|
|
|
1641
1744
|
delay = 500;
|
|
1642
1745
|
continue;
|
|
1643
1746
|
}
|
|
1644
|
-
if (error instanceof RemoteAuthorizationError)
|
|
1645
|
-
options.log?.({ event: "remote.session", status: "reauthorizing", deviceId });
|
|
1646
|
-
await accessToken(options.stateDirectory, fetcher, true);
|
|
1647
|
-
delay = 500;
|
|
1648
|
-
continue;
|
|
1649
|
-
}
|
|
1747
|
+
if (error instanceof RemoteAuthorizationError) throw new TypeError("Device Control authorization was rejected after refresh; run login again");
|
|
1650
1748
|
if (!(error instanceof RemoteUnavailableError)) throw error;
|
|
1651
|
-
options.log?.({
|
|
1652
|
-
|
|
1749
|
+
options.log?.({
|
|
1750
|
+
event: "remote.session",
|
|
1751
|
+
status: "reconnecting",
|
|
1752
|
+
deviceId,
|
|
1753
|
+
retryMs: delay,
|
|
1754
|
+
...error.httpStatus === void 0 ? {} : { httpStatus: error.httpStatus },
|
|
1755
|
+
...error.pathname === void 0 ? {} : { pathname: error.pathname }
|
|
1756
|
+
});
|
|
1757
|
+
await sleep2(delay, options.signal);
|
|
1653
1758
|
delay = Math.min(delay * 2, 15e3);
|
|
1654
1759
|
} finally {
|
|
1655
1760
|
refreshSession = () => {
|
|
@@ -1662,34 +1767,39 @@ async function runRemote(options) {
|
|
|
1662
1767
|
}
|
|
1663
1768
|
}
|
|
1664
1769
|
async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, signal, log) {
|
|
1665
|
-
const
|
|
1666
|
-
const
|
|
1770
|
+
const deviceId = engine.options.deviceId;
|
|
1771
|
+
const invoke2 = (pathname, body, requestSignal = signal, timeoutMs = 15e3, requestLog = log) => authorizedRequest(fetcher, origin, stateDirectory, pathname, body, requestSignal, timeoutMs, requestLog, deviceId);
|
|
1772
|
+
const connected = await invoke2("/device-control/remote/connect", { device: engine.info() });
|
|
1667
1773
|
const sessionId = bounded2(connected.sessionId, "remote session id");
|
|
1668
|
-
log?.({ event: "remote.session", status: "connected", deviceId
|
|
1774
|
+
log?.({ event: "remote.session", status: "connected", deviceId });
|
|
1669
1775
|
try {
|
|
1670
1776
|
while (!signal?.aborted) {
|
|
1671
|
-
const next = await
|
|
1777
|
+
const next = await invoke2("/device-control/remote/poll", { sessionId, deviceId }, signal, 35e3);
|
|
1672
1778
|
if (next.notice !== void 0) log?.({ event: "plugin.tool", ...noticeValue(next.notice) });
|
|
1673
1779
|
if (next.command === null || next.command === void 0) continue;
|
|
1674
1780
|
const command = commandValue(next.command);
|
|
1675
1781
|
const startedAt = Date.now();
|
|
1676
1782
|
try {
|
|
1677
1783
|
const output = await engine.execute(command.capability, command.parameters, { workspaceId: bounded2(next.workspaceId, "workspace id") });
|
|
1678
|
-
await
|
|
1784
|
+
await invoke2("/device-control/remote/result", { sessionId, deviceId, requestId: command.requestId, ok: true, output, executionMs: elapsed(startedAt) });
|
|
1679
1785
|
} catch (error) {
|
|
1680
|
-
await
|
|
1681
|
-
fetcher,
|
|
1682
|
-
origin,
|
|
1683
|
-
"/device-control/remote/result",
|
|
1684
|
-
token,
|
|
1685
|
-
{ sessionId, deviceId: engine.options.deviceId, requestId: command.requestId, ok: false, error: safeError(error), executionMs: elapsed(startedAt) },
|
|
1686
|
-
signal
|
|
1687
|
-
);
|
|
1786
|
+
await invoke2("/device-control/remote/result", { sessionId, deviceId, requestId: command.requestId, ok: false, error: safeError(error), executionMs: elapsed(startedAt) });
|
|
1688
1787
|
}
|
|
1689
1788
|
}
|
|
1690
1789
|
} finally {
|
|
1691
|
-
await
|
|
1692
|
-
log?.({ event: "remote.session", status: "disconnected", deviceId
|
|
1790
|
+
await invoke2("/device-control/remote/disconnect", { sessionId, deviceId }, void 0, 5e3, void 0).catch(() => void 0);
|
|
1791
|
+
log?.({ event: "remote.session", status: "disconnected", deviceId });
|
|
1792
|
+
}
|
|
1793
|
+
}
|
|
1794
|
+
async function authorizedRequest(fetcher, origin, stateDirectory, pathname, body, signal, timeoutMs = 15e3, log, deviceId) {
|
|
1795
|
+
const current = await accessToken(stateDirectory, fetcher);
|
|
1796
|
+
try {
|
|
1797
|
+
return await request(fetcher, origin, pathname, current.token, body, signal, timeoutMs);
|
|
1798
|
+
} catch (error) {
|
|
1799
|
+
if (!(error instanceof RemoteAuthorizationError)) throw error;
|
|
1800
|
+
log?.({ event: "remote.session", status: "reauthorizing", ...deviceId ? { deviceId } : {}, httpStatus: error.httpStatus, pathname: error.pathname });
|
|
1801
|
+
const refreshed = await accessToken(stateDirectory, fetcher, true);
|
|
1802
|
+
return request(fetcher, origin, pathname, refreshed.token, body, signal, timeoutMs);
|
|
1693
1803
|
}
|
|
1694
1804
|
}
|
|
1695
1805
|
async function request(fetcher, origin, pathname, token, body, signal, timeoutMs = 15e3) {
|
|
@@ -1709,10 +1819,10 @@ async function request(fetcher, origin, pathname, token, body, signal, timeoutMs
|
|
|
1709
1819
|
signal: controller.signal
|
|
1710
1820
|
});
|
|
1711
1821
|
} catch {
|
|
1712
|
-
throw new RemoteUnavailableError();
|
|
1822
|
+
throw new RemoteUnavailableError(void 0, pathname);
|
|
1713
1823
|
}
|
|
1714
|
-
if (response.status === 401 || response.status === 403) throw new RemoteAuthorizationError();
|
|
1715
|
-
if (!response.ok) throw new RemoteUnavailableError();
|
|
1824
|
+
if (response.status === 401 || response.status === 403) throw new RemoteAuthorizationError(response.status, pathname);
|
|
1825
|
+
if (!response.ok) throw new RemoteUnavailableError(response.status, pathname);
|
|
1716
1826
|
const raw = await response.json();
|
|
1717
1827
|
if (!raw || typeof raw !== "object" || Array.isArray(raw)) throw new TypeError("remote response is invalid");
|
|
1718
1828
|
return raw;
|
|
@@ -1733,8 +1843,22 @@ function defaultRemoteRoots(cwd = process.cwd()) {
|
|
|
1733
1843
|
return [{ id: "cwd", label: "Current directory", path: path4.resolve(cwd), readOnly: false }];
|
|
1734
1844
|
}
|
|
1735
1845
|
var RemoteUnavailableError = class extends Error {
|
|
1846
|
+
constructor(httpStatus, pathname) {
|
|
1847
|
+
super("remote endpoint is unavailable");
|
|
1848
|
+
this.httpStatus = httpStatus;
|
|
1849
|
+
this.pathname = pathname;
|
|
1850
|
+
}
|
|
1851
|
+
httpStatus;
|
|
1852
|
+
pathname;
|
|
1736
1853
|
};
|
|
1737
1854
|
var RemoteAuthorizationError = class extends Error {
|
|
1855
|
+
constructor(httpStatus, pathname) {
|
|
1856
|
+
super("remote authorization was rejected");
|
|
1857
|
+
this.httpStatus = httpStatus;
|
|
1858
|
+
this.pathname = pathname;
|
|
1859
|
+
}
|
|
1860
|
+
httpStatus;
|
|
1861
|
+
pathname;
|
|
1738
1862
|
};
|
|
1739
1863
|
function canonicalOrigin2(value) {
|
|
1740
1864
|
const url = new URL(value);
|
|
@@ -1775,7 +1899,7 @@ function elapsed(startedAt) {
|
|
|
1775
1899
|
function safeError(error) {
|
|
1776
1900
|
return error instanceof TypeError ? error.message.slice(0, 256) : "device operation failed";
|
|
1777
1901
|
}
|
|
1778
|
-
function
|
|
1902
|
+
function sleep2(ms, signal) {
|
|
1779
1903
|
return new Promise((resolve) => {
|
|
1780
1904
|
const timer = setTimeout(resolve, ms);
|
|
1781
1905
|
const abort = () => {
|
|
@@ -1936,25 +2060,30 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
|
|
|
1936
2060
|
output({ status: "installed", ...await installRemoteService(resolvedOrigin, config.stateDirectory) });
|
|
1937
2061
|
return;
|
|
1938
2062
|
}
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
2063
|
+
const lease = await acquireRemoteProcessLock(config.stateDirectory);
|
|
2064
|
+
try {
|
|
2065
|
+
if (!existingAuth) {
|
|
2066
|
+
if (config.service) throw new TypeError("service mode requires login");
|
|
2067
|
+
await loginDeviceControl(resolvedOrigin, config.stateDirectory);
|
|
2068
|
+
}
|
|
2069
|
+
const controller = new AbortController();
|
|
2070
|
+
for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => controller.abort());
|
|
2071
|
+
const remoteOrigin = resolvedOrigin;
|
|
2072
|
+
output({ status: "connecting", origin: remoteOrigin, platform: process.platform });
|
|
2073
|
+
await runRemote({
|
|
2074
|
+
origin: remoteOrigin,
|
|
2075
|
+
stateDirectory: config.stateDirectory,
|
|
2076
|
+
roots: config.roots,
|
|
2077
|
+
allowedExecutables: config.allowedExecutables,
|
|
2078
|
+
allowedServices: config.allowedServices,
|
|
2079
|
+
browserControl: config.browserControl,
|
|
2080
|
+
browserPort: config.browserPort,
|
|
2081
|
+
signal: controller.signal,
|
|
2082
|
+
log: output
|
|
2083
|
+
});
|
|
2084
|
+
} finally {
|
|
2085
|
+
await lease.release();
|
|
1942
2086
|
}
|
|
1943
|
-
const controller = new AbortController();
|
|
1944
|
-
for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => controller.abort());
|
|
1945
|
-
const remoteOrigin = resolvedOrigin;
|
|
1946
|
-
output({ status: "connecting", origin: remoteOrigin, platform: process.platform });
|
|
1947
|
-
await runRemote({
|
|
1948
|
-
origin: remoteOrigin,
|
|
1949
|
-
stateDirectory: config.stateDirectory,
|
|
1950
|
-
roots: config.roots,
|
|
1951
|
-
allowedExecutables: config.allowedExecutables,
|
|
1952
|
-
allowedServices: config.allowedServices,
|
|
1953
|
-
browserControl: config.browserControl,
|
|
1954
|
-
browserPort: config.browserPort,
|
|
1955
|
-
signal: controller.signal,
|
|
1956
|
-
log: output
|
|
1957
|
-
});
|
|
1958
2087
|
}
|
|
1959
2088
|
function formatCliEvent(event, json2 = false) {
|
|
1960
2089
|
if (json2) return JSON.stringify(event);
|
|
@@ -1977,8 +2106,8 @@ function formatCliEvent(event, json2 = false) {
|
|
|
1977
2106
|
if (event.event === "remote.session") {
|
|
1978
2107
|
if (status === "connected") return "\u2705 Device connected \xB7 " + String(event.deviceId);
|
|
1979
2108
|
if (status === "disconnected") return "\u{1F50C} Device disconnected \xB7 " + String(event.deviceId);
|
|
1980
|
-
if (status === "reconnecting") return "\u26A0\uFE0F Connection interrupted \xB7 retrying in " + String(event.retryMs) + " ms";
|
|
1981
|
-
if (status === "reauthorizing") return "\u{1F510} Refreshing Device Control authorization";
|
|
2109
|
+
if (status === "reconnecting") return "\u26A0\uFE0F Connection interrupted" + httpDetail(event) + " \xB7 retrying in " + String(event.retryMs) + " ms";
|
|
2110
|
+
if (status === "reauthorizing") return "\u{1F510} Refreshing Device Control authorization" + httpDetail(event);
|
|
1982
2111
|
}
|
|
1983
2112
|
if (status === "connecting") return "\u{1F310} Connecting to " + String(event.origin) + " \xB7 " + String(event.platform);
|
|
1984
2113
|
if (status === "authenticated") return "\u2705 Authenticated \xB7 " + String(event.origin);
|
|
@@ -1988,6 +2117,11 @@ function formatCliEvent(event, json2 = false) {
|
|
|
1988
2117
|
if ("authenticated" in event) return (event.authenticated ? "\u2705" : "\u26A0\uFE0F") + " Device " + String(event.deviceId) + " \xB7 " + String(event.origin) + " \xB7 remote=" + JSON.stringify(event.remote);
|
|
1989
2118
|
return "\u2139\uFE0F " + JSON.stringify(event);
|
|
1990
2119
|
}
|
|
2120
|
+
function httpDetail(event) {
|
|
2121
|
+
const status = Number(event.httpStatus);
|
|
2122
|
+
const pathname = typeof event.pathname === "string" && /^\/[A-Za-z0-9._~!$&'()*+,;=:@%/-]{1,255}$/.test(event.pathname) ? event.pathname : "";
|
|
2123
|
+
return Number.isInteger(status) && status >= 100 && status <= 599 ? " \xB7 HTTP " + status + (pathname ? " " + pathname : "") : pathname ? " \xB7 " + pathname : "";
|
|
2124
|
+
}
|
|
1991
2125
|
function resolveConfiguredOrigin(explicit, stored) {
|
|
1992
2126
|
if (explicit && stored && explicit !== stored) throw new TypeError("configured origin does not match the authenticated origin; logout before changing environments");
|
|
1993
2127
|
return explicit ?? stored ?? DEFAULT_DEVICE_CONTROL_ORIGIN;
|