@codingfrees/uap-device-control 0.1.17 → 0.1.19
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 +3 -1
- package/dist/uap-device-control.mjs +36 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,7 +30,9 @@ npx @codingfrees/uap-device-control@latest remote
|
|
|
30
30
|
|
|
31
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
|
-
By default the Remote process also starts the loopback-only semantic browser bridge on port `
|
|
33
|
+
By default the Remote process also starts the loopback-only semantic browser bridge on port `18700`. 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
|
+
|
|
35
|
+
Existing extensions paired on the former port `8800` retain that port in browser storage. After updating npm Remote and Browser Extension, open **Device Control · Browser** in extension Settings and use **Reconnect browser bridge** with port `18700` (or the CLI-reported port). This moves the existing pairing after an explicit user action, rather than silently sending the saved bearer to a new local port or resetting device credentials. Use `browser-reset` only if pairing authority was lost or the extension was replaced.
|
|
34
36
|
|
|
35
37
|
If a browser extension was replaced or lost its local token, stop `remote`, run `npx @codingfrees/uap-device-control@latest browser-reset`, then start `remote` again. This resets only the browser pairing and preserves the device identity and login.
|
|
36
38
|
|
|
@@ -377,7 +377,7 @@ async function resetBrowserBridgePairing(stateDirectory) {
|
|
|
377
377
|
await mkdir2(stateDirectory, { recursive: true, mode: 448 });
|
|
378
378
|
await writeFile2(path2.join(stateDirectory, "browser-bridge.json"), JSON.stringify({ version: 1 }) + "\n", { mode: 384 });
|
|
379
379
|
}
|
|
380
|
-
async function createBrowserBridge(stateDirectory, requestedPort =
|
|
380
|
+
async function createBrowserBridge(stateDirectory, requestedPort = 18700, log) {
|
|
381
381
|
if (!Number.isInteger(requestedPort) || requestedPort !== 0 && (requestedPort < 1024 || requestedPort > 65535)) throw new TypeError("browser bridge port is invalid");
|
|
382
382
|
await mkdir2(stateDirectory, { recursive: true, mode: 448 });
|
|
383
383
|
const statePath = path2.join(stateDirectory, "browser-bridge.json");
|
|
@@ -615,7 +615,7 @@ import path4 from "node:path";
|
|
|
615
615
|
// package.json
|
|
616
616
|
var package_default = {
|
|
617
617
|
name: "@codingfrees/uap-device-control",
|
|
618
|
-
version: "0.1.
|
|
618
|
+
version: "0.1.19",
|
|
619
619
|
description: "Cross-platform outbound UAP Device Control client",
|
|
620
620
|
type: "module",
|
|
621
621
|
bin: {
|
|
@@ -1714,9 +1714,10 @@ async function runRemote(options) {
|
|
|
1714
1714
|
options.log?.(event);
|
|
1715
1715
|
if (event.event === "browser.bridge" && ["paired", "unpaired", "connected", "permissions-granted", "permissions-required"].includes(String(event.status))) refreshSession();
|
|
1716
1716
|
};
|
|
1717
|
-
const
|
|
1717
|
+
const browserPort = options.browserPort ?? 18700;
|
|
1718
|
+
const browser = options.browserControl === false ? void 0 : await createBrowserBridge(options.stateDirectory, browserPort, browserLog).catch((error) => {
|
|
1718
1719
|
if (!optionalBrowserBridgeFailure(error)) throw error;
|
|
1719
|
-
options.log?.({ event: "browser.bridge", status: "unavailable" });
|
|
1720
|
+
options.log?.({ event: "browser.bridge", status: "unavailable", port: browserPort, errorCode: String(error.code) });
|
|
1720
1721
|
return void 0;
|
|
1721
1722
|
});
|
|
1722
1723
|
if (browser) {
|
|
@@ -1829,7 +1830,7 @@ async function request(fetcher, origin, pathname, token, body, signal, timeoutMs
|
|
|
1829
1830
|
signal: controller.signal
|
|
1830
1831
|
});
|
|
1831
1832
|
} catch {
|
|
1832
|
-
throw new RemoteUnavailableError(void 0, pathname);
|
|
1833
|
+
throw new RemoteUnavailableError(void 0, pathname, controller.signal.aborted ? "timeout" : "transport");
|
|
1833
1834
|
}
|
|
1834
1835
|
if (response.status === 401 || response.status === 403) throw new RemoteAuthorizationError(response.status, pathname);
|
|
1835
1836
|
if (response.status === 409 && pathname === "/device-control/remote/poll") {
|
|
@@ -1846,8 +1847,7 @@ async function request(fetcher, origin, pathname, token, body, signal, timeoutMs
|
|
|
1846
1847
|
}
|
|
1847
1848
|
}
|
|
1848
1849
|
async function remoteStatus(origin, stateDirectory, deviceId, fetcher = fetch) {
|
|
1849
|
-
const
|
|
1850
|
-
const value = await request(fetcher, origin, "/device-control/remote/status", token, { deviceId }, void 0, 5e3);
|
|
1850
|
+
const value = await authorizedRequest(fetcher, origin, stateDirectory, "/device-control/remote/status", { deviceId }, void 0, 5e3);
|
|
1851
1851
|
if (typeof value.online !== "boolean") throw new TypeError("remote status response is invalid");
|
|
1852
1852
|
const lastSeen = value.lastSeen;
|
|
1853
1853
|
if (lastSeen !== void 0 && (!Number.isSafeInteger(lastSeen) || Number(lastSeen) < 0)) throw new TypeError("remote status response is invalid");
|
|
@@ -1864,13 +1864,15 @@ var RemoteSessionExpiredError = class extends Error {
|
|
|
1864
1864
|
pathname;
|
|
1865
1865
|
};
|
|
1866
1866
|
var RemoteUnavailableError = class extends Error {
|
|
1867
|
-
constructor(httpStatus, pathname) {
|
|
1867
|
+
constructor(httpStatus, pathname, reason) {
|
|
1868
1868
|
super("remote endpoint is unavailable");
|
|
1869
1869
|
this.httpStatus = httpStatus;
|
|
1870
1870
|
this.pathname = pathname;
|
|
1871
|
+
this.reason = reason;
|
|
1871
1872
|
}
|
|
1872
1873
|
httpStatus;
|
|
1873
1874
|
pathname;
|
|
1875
|
+
reason;
|
|
1874
1876
|
};
|
|
1875
1877
|
var RemoteAuthorizationError = class extends Error {
|
|
1876
1878
|
constructor(httpStatus, pathname) {
|
|
@@ -2067,7 +2069,7 @@ function parseDeviceControlArguments(args, cwd = process.cwd()) {
|
|
|
2067
2069
|
const allowedServices = [];
|
|
2068
2070
|
let service = false;
|
|
2069
2071
|
let browserControl = true;
|
|
2070
|
-
let browserPort =
|
|
2072
|
+
let browserPort = 18700;
|
|
2071
2073
|
let json2 = false;
|
|
2072
2074
|
for (let index = command === "help" ? args.length : 1; index < args.length; index++) {
|
|
2073
2075
|
const option = args[index];
|
|
@@ -2133,9 +2135,8 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
|
|
|
2133
2135
|
if (config.command === "status") {
|
|
2134
2136
|
const [auth, deviceId] = await Promise.all([existingAuth, loadRemoteDeviceId(config.stateDirectory)]);
|
|
2135
2137
|
const deviceAuthorized = !!auth?.scope.split(" ").includes("device-control:device");
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
output({ deviceId, origin: auth?.origin ?? resolvedOrigin, authenticated: !!auth, deviceAuthorized, remote: remote ?? null, serviceMode: config.service, platform: process.platform });
|
|
2138
|
+
const remote = auth && deviceAuthorized ? await checkRemoteStatus(auth.origin, config.stateDirectory, deviceId) : null;
|
|
2139
|
+
output({ deviceId, origin: auth?.origin ?? resolvedOrigin, authenticated: !!auth, deviceAuthorized, remote, serviceMode: config.service, platform: process.platform });
|
|
2139
2140
|
return;
|
|
2140
2141
|
}
|
|
2141
2142
|
if (config.command === "install-service") {
|
|
@@ -2184,7 +2185,13 @@ function formatCliEvent(event, json2 = false) {
|
|
|
2184
2185
|
if (status === "ready")
|
|
2185
2186
|
return "\u{1F310} Browser bridge ready \xB7 127.0.0.1:" + String(event.port) + (event.pairingStored ? " \xB7 pairing saved \xB7 extension offline; new extension? stop Remote, then run: npx @codingfrees/uap-device-control@latest browser-reset" : " \xB7 waiting for pairing");
|
|
2186
2187
|
if (status === "pairing-required") return "\u26A0\uFE0F Browser extension not connected; remote control continues without browser tools \xB7 pairing code " + String(event.pairingCode) + " \xB7 port " + String(event.port);
|
|
2187
|
-
if (status === "unavailable")
|
|
2188
|
+
if (status === "unavailable") {
|
|
2189
|
+
const code = ["EADDRINUSE", "EACCES", "EAFNOSUPPORT", "EPROTONOSUPPORT"].includes(String(event.errorCode)) ? String(event.errorCode) : "UNKNOWN";
|
|
2190
|
+
const port2 = Number.isInteger(event.port) && Number(event.port) >= 1024 && Number(event.port) <= 65535 ? Number(event.port) : 18700;
|
|
2191
|
+
const alternate = port2 === 65535 ? 8801 : port2 + 1;
|
|
2192
|
+
const help = code === "EADDRINUSE" ? "port already in use; inspect the listener or retry remote --browser-port " + alternate : code === "EACCES" ? "local port access denied; check reserved ports or retry remote --browser-port " + alternate : code === "EAFNOSUPPORT" || code === "EPROTONOSUPPORT" ? "local TCP/IPv4 networking unavailable; check OS networking" : "local bridge could not start";
|
|
2193
|
+
return "\u26A0\uFE0F Browser control unavailable \xB7 port " + port2 + " \xB7 " + code + " \xB7 " + help + "; files, terminal and processes remain available";
|
|
2194
|
+
}
|
|
2188
2195
|
if (status === "paired") return "\u2705 UAP Browser Extension paired";
|
|
2189
2196
|
if (status === "connected") return "\u{1F310} UAP Browser Extension connected";
|
|
2190
2197
|
if (status === "unpaired") return "\u{1F50C} UAP Browser Extension unpaired";
|
|
@@ -2204,6 +2211,21 @@ function formatCliEvent(event, json2 = false) {
|
|
|
2204
2211
|
if ("authenticated" in event) return (event.authenticated ? "\u2705" : "\u26A0\uFE0F") + " Device " + String(event.deviceId) + " \xB7 " + String(event.origin) + " \xB7 remote=" + JSON.stringify(event.remote);
|
|
2205
2212
|
return "\u2139\uFE0F " + JSON.stringify(event);
|
|
2206
2213
|
}
|
|
2214
|
+
async function checkRemoteStatus(origin, stateDirectory, deviceId, probe = remoteStatus) {
|
|
2215
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
2216
|
+
try {
|
|
2217
|
+
return await probe(origin, stateDirectory, deviceId);
|
|
2218
|
+
} catch (error) {
|
|
2219
|
+
if (error instanceof RemoteAuthorizationError) return { online: null, error: "status_unauthorized", httpStatus: error.httpStatus };
|
|
2220
|
+
if (error instanceof RemoteUnavailableError) {
|
|
2221
|
+
if (attempt === 0) continue;
|
|
2222
|
+
return { online: null, error: error.reason === "timeout" ? "status_timeout" : "status_unavailable", ...error.httpStatus === void 0 ? {} : { httpStatus: error.httpStatus } };
|
|
2223
|
+
}
|
|
2224
|
+
return { online: null, error: "status_failed" };
|
|
2225
|
+
}
|
|
2226
|
+
}
|
|
2227
|
+
return { online: null, error: "status_unavailable" };
|
|
2228
|
+
}
|
|
2207
2229
|
function deviceControlHelp() {
|
|
2208
2230
|
return `UAP Device Control
|
|
2209
2231
|
|
|
@@ -2225,7 +2247,7 @@ Remote options:
|
|
|
2225
2247
|
--read-only-root <id=path> Add a read-only filesystem root
|
|
2226
2248
|
--allow-executable <path> Allow an executable for terminal commands
|
|
2227
2249
|
--allow-service <name> Allow a native service
|
|
2228
|
-
--browser-port <port> Browser extension bridge port (default:
|
|
2250
|
+
--browser-port <port> Browser extension bridge port (default: 18700)
|
|
2229
2251
|
--no-browser-control Run without browser integration
|
|
2230
2252
|
--state-dir <path> Override the local state directory
|
|
2231
2253
|
--origin <https-origin> Override the Device Control service origin
|