@codingfrees/uap-device-control 0.1.19 → 0.1.21

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 CHANGED
@@ -101,3 +101,7 @@ Validate the exact release without publishing with `pnpm publish:public -- --dry
101
101
  For `npm whoami` HTTP 401 in Linux/WSL, renew authentication locally using `npm login --registry=https://registry.npmjs.org/ --auth-type=web`, then confirm `npm whoami`. Do not paste credentials into issue reports or logs. npm versions are immutable: bump the package version and commit a clean tree before publishing.
102
102
 
103
103
  The script requires clean package inputs, refuses an already-published version, builds and dry-runs the package, then calls npm publish and verifies the registry version plus the `latest` dist-tag. The root `pnpm deploy:npm` entrypoint invokes the publisher directly; a separate package-local node_modules directory is unnecessary when workspace dependencies are installed. npm account 2FA remains mandatory and is handled by npm during the publish step.
104
+
105
+ ## UAP Downloads release candidates
106
+
107
+ The `UAP downloadable product candidates` workflow also builds the Node 26 portable `uap-device-control-remote-<version>.mjs`, its SHA-256 and sanitized provenance from the exact candidate source SHA. This executable JavaScript file **requires Node.js 26**; it is not a signed Windows/macOS native installer and is separate from the existing npm release channel. The private CI artifact is not a public UAP Downloads release. Each approved public release must embed Windows/Linux/macOS download, checksum, login, scoped-root, browser pairing and update/removal instructions in its description; live OS/browser certification and separate publication approval are required.
@@ -181,7 +181,7 @@ function exists(error) {
181
181
  // src/auth.ts
182
182
  var scopes = "device-control:device offline_access";
183
183
  async function loginDeviceControl(origin, stateDirectory, options = {}) {
184
- if (!options.pairingCode || !/^[A-Za-z0-9_-]{32}$/.test(options.pairingCode)) throw new TypeError("A single-use pairing code from the admin console is required");
184
+ if (options.pairingCode !== void 0 && !/^[A-Za-z0-9_-]{32}$/.test(options.pairingCode)) throw new TypeError("invalid single-use pairing code");
185
185
  const fetcher = options.fetcher ?? fetch;
186
186
  const issuer = canonicalOrigin(origin);
187
187
  const metadata = await json(fetcher(new URL("/.well-known/oauth-authorization-server", issuer), { redirect: "error", cache: "no-store" }));
@@ -208,7 +208,7 @@ async function loginDeviceControl(origin, stateDirectory, options = {}) {
208
208
  authorize2.searchParams.set("state", pkce.state);
209
209
  authorize2.searchParams.set("code_challenge", pkce.challenge);
210
210
  authorize2.searchParams.set("code_challenge_method", "S256");
211
- const result = await automaticPairing(fetcher, issuer, authorize2, options.pairingCode, pkce.state);
211
+ const result = options.pairingCode ? await automaticPairing(fetcher, issuer, authorize2, options.pairingCode, pkce.state) : await browserAuthorization(authorize2, callback.result, options.onAuthorizationUrl);
212
212
  if (result.state !== pkce.state || !result.code) throw new TypeError("OAuth callback is invalid");
213
213
  const token = await json(
214
214
  fetcher(tokenEndpoint, {
@@ -265,6 +265,10 @@ async function logoutDeviceControl(stateDirectory, fetcher = fetch) {
265
265
  await clearRemoteAuth(stateDirectory);
266
266
  return true;
267
267
  }
268
+ async function browserAuthorization(authorize2, result, onAuthorizationUrl) {
269
+ await onAuthorizationUrl?.(authorize2.href);
270
+ return result;
271
+ }
268
272
  async function automaticPairing(fetcher, issuer, authorize2, pairingCode, expectedState) {
269
273
  const started = await json(
270
274
  fetcher(new URL("/pairing/start", issuer), { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ authorizeUrl: authorize2.href }), redirect: "error", cache: "no-store" })
@@ -299,6 +303,11 @@ async function callbackServer(timeoutMs) {
299
303
  return;
300
304
  }
301
305
  response.writeHead(200, { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" });
306
+ if (url.searchParams.has("error")) {
307
+ response.end("UAP Device Control authorization declined. You can close this window.");
308
+ reject(new TypeError("OAuth browser authorization was declined"));
309
+ return;
310
+ }
302
311
  response.end("UAP Device Control login completed. You can close this window.");
303
312
  settle({ code: url.searchParams.get("code") ?? void 0, state: url.searchParams.get("state") ?? void 0 });
304
313
  });
@@ -615,7 +624,7 @@ import path4 from "node:path";
615
624
  // package.json
616
625
  var package_default = {
617
626
  name: "@codingfrees/uap-device-control",
618
- version: "0.1.19",
627
+ version: "0.1.21",
619
628
  description: "Cross-platform outbound UAP Device Control client",
620
629
  type: "module",
621
630
  bin: {
@@ -1783,22 +1792,47 @@ async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, si
1783
1792
  const connected = await invoke2("/device-control/remote/connect", { device: engine.info() });
1784
1793
  const sessionId = bounded2(connected.sessionId, "remote session id");
1785
1794
  log?.({ event: "remote.session", status: "connected", deviceId, agentVersion: UAP_DEVICE_CONTROL_AGENT_VERSION });
1795
+ const inFlight = /* @__PURE__ */ new Set();
1796
+ const dispatched = /* @__PURE__ */ new Set();
1797
+ let resultFailure;
1798
+ const complete = async (command, workspaceId) => {
1799
+ const startedAt = Date.now();
1800
+ let outcome;
1801
+ try {
1802
+ const output = await engine.execute(command.capability, command.parameters, { workspaceId });
1803
+ outcome = { ok: true, output };
1804
+ } catch (error) {
1805
+ outcome = { ok: false, error: safeError(error) };
1806
+ }
1807
+ try {
1808
+ await invoke2("/device-control/remote/result", { sessionId, deviceId, requestId: command.requestId, ...outcome, executionMs: elapsed(startedAt) });
1809
+ } catch (error) {
1810
+ if (!(error instanceof RemoteResultExpiredError)) throw error;
1811
+ log?.({ event: "remote.result", status: "expired", deviceId, requestId: command.requestId });
1812
+ }
1813
+ };
1786
1814
  try {
1787
1815
  while (!signal?.aborted) {
1816
+ if (inFlight.size >= 4) await Promise.race(inFlight);
1817
+ if (resultFailure) throw resultFailure;
1788
1818
  const next = await invoke2("/device-control/remote/poll", { sessionId, deviceId }, signal, 35e3);
1819
+ if (resultFailure) throw resultFailure;
1789
1820
  if (next.notice !== void 0) log?.({ event: "plugin.tool", ...noticeValue(next.notice) });
1790
1821
  if (next.command === null || next.command === void 0) continue;
1791
1822
  const command = commandValue(next.command);
1792
- const startedAt = Date.now();
1793
- try {
1794
- const output = await engine.execute(command.capability, command.parameters, { workspaceId: bounded2(next.workspaceId, "workspace id") });
1795
- await invoke2("/device-control/remote/result", { sessionId, deviceId, requestId: command.requestId, ok: true, output, executionMs: elapsed(startedAt) });
1796
- } catch (error) {
1797
- await invoke2("/device-control/remote/result", { sessionId, deviceId, requestId: command.requestId, ok: false, error: safeError(error), executionMs: elapsed(startedAt) });
1798
- }
1823
+ if (dispatched.has(command.requestId)) continue;
1824
+ dispatched.add(command.requestId);
1825
+ if (dispatched.size > 2048) dispatched.delete(dispatched.values().next().value);
1826
+ const job = complete(command, bounded2(next.workspaceId, "workspace id")).catch((error) => {
1827
+ resultFailure ??= error;
1828
+ });
1829
+ inFlight.add(job);
1830
+ void job.then(() => inFlight.delete(job));
1799
1831
  }
1832
+ if (resultFailure) throw resultFailure;
1800
1833
  } finally {
1801
- await invoke2("/device-control/remote/disconnect", { sessionId, deviceId }, void 0, 5e3, void 0).catch(() => void 0);
1834
+ await Promise.allSettled(inFlight);
1835
+ await authorizedRequest(fetcher, origin, stateDirectory, "/device-control/remote/disconnect", { sessionId, deviceId }, void 0, 5e3).catch(() => void 0);
1802
1836
  log?.({ event: "remote.session", status: "disconnected", deviceId });
1803
1837
  }
1804
1838
  }
@@ -1833,9 +1867,12 @@ async function request(fetcher, origin, pathname, token, body, signal, timeoutMs
1833
1867
  throw new RemoteUnavailableError(void 0, pathname, controller.signal.aborted ? "timeout" : "transport");
1834
1868
  }
1835
1869
  if (response.status === 401 || response.status === 403) throw new RemoteAuthorizationError(response.status, pathname);
1836
- if (response.status === 409 && pathname === "/device-control/remote/poll") {
1870
+ if (response.status === 409 && (pathname === "/device-control/remote/poll" || pathname === "/device-control/remote/result")) {
1837
1871
  const body2 = await response.json().catch(() => void 0);
1838
- if (body2 && typeof body2 === "object" && !Array.isArray(body2) && "error" in body2 && body2.error === "session_expired") throw new RemoteSessionExpiredError(pathname);
1872
+ if (body2 && typeof body2 === "object" && !Array.isArray(body2) && "error" in body2) {
1873
+ if (body2.error === "session_expired") throw new RemoteSessionExpiredError(pathname);
1874
+ if (pathname.endsWith("/result") && body2.error === "request_not_pending") throw new RemoteResultExpiredError(pathname);
1875
+ }
1839
1876
  }
1840
1877
  if (!response.ok) throw new RemoteUnavailableError(response.status, pathname);
1841
1878
  const raw = await response.json();
@@ -1863,6 +1900,13 @@ var RemoteSessionExpiredError = class extends Error {
1863
1900
  }
1864
1901
  pathname;
1865
1902
  };
1903
+ var RemoteResultExpiredError = class extends Error {
1904
+ constructor(pathname) {
1905
+ super("remote command waiter expired before result acceptance");
1906
+ this.pathname = pathname;
1907
+ }
1908
+ pathname;
1909
+ };
1866
1910
  var RemoteUnavailableError = class extends Error {
1867
1911
  constructor(httpStatus, pathname, reason) {
1868
1912
  super("remote endpoint is unavailable");
@@ -1973,22 +2017,22 @@ async function installRemoteService(origin, stateDirectory) {
1973
2017
  }
1974
2018
  async function runnerV2Installed(platform = process.platform, run = execute3, exists2 = existsSync) {
1975
2019
  if (platform === "linux") {
1976
- if (exists2("/opt/uap-local-node-runner-v2/current")) return true;
2020
+ if (exists2("/opt/uap-local-runner/current")) return true;
1977
2021
  for (const args of [
1978
- ["list-unit-files", "uap-local-node-runner-v2.service", "--no-legend"],
1979
- ["--user", "list-unit-files", "uap-local-node-runner-v2.service", "--no-legend"]
2022
+ ["list-unit-files", "uap-local-runner.service", "--no-legend"],
2023
+ ["--user", "list-unit-files", "uap-local-runner.service", "--no-legend"]
1980
2024
  ]) {
1981
2025
  try {
1982
2026
  const result = await run("systemctl", args);
1983
- if (/^uap-local-node-runner-v2\.service\s/m.test(result.stdout)) return true;
2027
+ if (/^uap-local-runner\.service\s/m.test(result.stdout)) return true;
1984
2028
  } catch {
1985
2029
  }
1986
2030
  }
1987
2031
  }
1988
2032
  if (platform === "win32") {
1989
2033
  for (const [command, args] of [
1990
- ["sc.exe", ["query", "UAPLocalNodeRunnerV2"]],
1991
- ["schtasks.exe", ["/Query", "/TN", "UAPLocalNodeRunnerV2"]]
2034
+ ["sc.exe", ["query", "UAPLocalRunner"]],
2035
+ ["schtasks.exe", ["/Query", "/TN", "UAPLocalRunner"]]
1992
2036
  ]) {
1993
2037
  try {
1994
2038
  await run(command, [...args]);
@@ -2114,7 +2158,12 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
2114
2158
  const resolvedOrigin = resolveConfiguredOrigin(config.origin, existingAuth?.origin);
2115
2159
  const output = (event) => process.stdout.write(formatCliEvent(event, config.json) + "\n");
2116
2160
  if (config.command === "login") {
2117
- const auth = await loginDeviceControl(resolvedOrigin, config.stateDirectory, { pairingCode: config.pairingCode });
2161
+ const auth = await loginDeviceControl(resolvedOrigin, config.stateDirectory, {
2162
+ pairingCode: config.pairingCode,
2163
+ onAuthorizationUrl: (url) => {
2164
+ output({ event: "oauth.browser", status: "authorization-required", url });
2165
+ }
2166
+ });
2118
2167
  output({ status: "authenticated", origin: auth.origin });
2119
2168
  return;
2120
2169
  }
@@ -2148,7 +2197,12 @@ async function runDeviceControlCli(args = process.argv.slice(2)) {
2148
2197
  try {
2149
2198
  if (!existingAuth) {
2150
2199
  if (config.service) throw new TypeError("service mode requires login");
2151
- await loginDeviceControl(resolvedOrigin, config.stateDirectory, { pairingCode: config.pairingCode });
2200
+ await loginDeviceControl(resolvedOrigin, config.stateDirectory, {
2201
+ pairingCode: config.pairingCode,
2202
+ onAuthorizationUrl: (url) => {
2203
+ output({ event: "oauth.browser", status: "authorization-required", url });
2204
+ }
2205
+ });
2152
2206
  }
2153
2207
  const controller = new AbortController();
2154
2208
  for (const signal of ["SIGINT", "SIGTERM"]) process.once(signal, () => controller.abort());
@@ -2202,6 +2256,8 @@ function formatCliEvent(event, json2 = false) {
2202
2256
  if (status === "reconnecting") return "\u26A0\uFE0F Connection interrupted" + httpDetail(event) + " \xB7 retrying in " + String(event.retryMs) + " ms";
2203
2257
  if (status === "reauthorizing") return "\u{1F510} Refreshing Device Control authorization" + httpDetail(event);
2204
2258
  }
2259
+ if (event.event === "oauth.browser" && status === "authorization-required")
2260
+ return "Open this URL in a browser and explicitly approve this computer:\n" + String(event.url) + "\nIf using WSL2, open the link in Windows and keep this terminal running for the localhost callback.\nAlternatively, run login --pairing-code <code>.";
2205
2261
  if (status === "connecting") return "\u{1F310} Connecting to " + String(event.origin) + " \xB7 " + String(event.platform);
2206
2262
  if (status === "authenticated") return "\u2705 Authenticated \xB7 " + String(event.origin);
2207
2263
  if (status === "logged-out") return "\u2705 Logged out";
@@ -2235,7 +2291,7 @@ Usage:
2235
2291
  Commands:
2236
2292
  remote Connect this computer to Device Control
2237
2293
  status Show authentication, device and connection status
2238
- login Pair this computer using a temporary admin-issued code
2294
+ login Sign in through browser OAuth/PKCE or an admin-issued pairing code
2239
2295
  logout Remove the saved authorization
2240
2296
  browser-reset Reset only the saved browser-extension pairing
2241
2297
  install-service Install the authenticated Remote as a system service
@@ -2256,6 +2312,7 @@ Remote options:
2256
2312
 
2257
2313
  Examples:
2258
2314
  npx @codingfrees/uap-device-control@latest
2315
+ npx @codingfrees/uap-device-control@latest login
2259
2316
  npx @codingfrees/uap-device-control@latest login --pairing-code <code>
2260
2317
  npx @codingfrees/uap-device-control@latest browser-reset
2261
2318
  npx @codingfrees/uap-device-control@latest remote
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingfrees/uap-device-control",
3
- "version": "0.1.19",
3
+ "version": "0.1.21",
4
4
  "description": "Cross-platform outbound UAP Device Control client",
5
5
  "type": "module",
6
6
  "bin": {