@codingfrees/uap-device-control 0.1.20 → 0.1.22
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/dist/uap-device-control.mjs +40 -15
- package/package.json +1 -1
|
@@ -624,7 +624,7 @@ import path4 from "node:path";
|
|
|
624
624
|
// package.json
|
|
625
625
|
var package_default = {
|
|
626
626
|
name: "@codingfrees/uap-device-control",
|
|
627
|
-
version: "0.1.
|
|
627
|
+
version: "0.1.22",
|
|
628
628
|
description: "Cross-platform outbound UAP Device Control client",
|
|
629
629
|
type: "module",
|
|
630
630
|
bin: {
|
|
@@ -1792,28 +1792,53 @@ async function remoteSession(origin, stateDirectory, engine, fetcher = fetch, si
|
|
|
1792
1792
|
const connected = await invoke2("/device-control/remote/connect", { device: engine.info() });
|
|
1793
1793
|
const sessionId = bounded2(connected.sessionId, "remote session id");
|
|
1794
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 browserExecution = Promise.resolve(void 0);
|
|
1798
|
+
let resultFailure;
|
|
1799
|
+
const execute4 = (command, workspaceId) => {
|
|
1800
|
+
if (!command.capability.startsWith("browser.")) return engine.execute(command.capability, command.parameters, { workspaceId });
|
|
1801
|
+
const current = browserExecution.then(() => engine.execute(command.capability, command.parameters, { workspaceId }));
|
|
1802
|
+
browserExecution = current.catch(() => void 0);
|
|
1803
|
+
return current;
|
|
1804
|
+
};
|
|
1805
|
+
const complete = async (command, workspaceId) => {
|
|
1806
|
+
const startedAt = Date.now();
|
|
1807
|
+
let outcome;
|
|
1808
|
+
try {
|
|
1809
|
+
const output = await execute4(command, workspaceId);
|
|
1810
|
+
outcome = { ok: true, output };
|
|
1811
|
+
} catch (error) {
|
|
1812
|
+
outcome = { ok: false, error: safeError(error) };
|
|
1813
|
+
}
|
|
1814
|
+
try {
|
|
1815
|
+
await invoke2("/device-control/remote/result", { sessionId, deviceId, requestId: command.requestId, ...outcome, executionMs: elapsed(startedAt) });
|
|
1816
|
+
} catch (error) {
|
|
1817
|
+
if (!(error instanceof RemoteResultExpiredError)) throw error;
|
|
1818
|
+
log?.({ event: "remote.result", status: "expired", deviceId, requestId: command.requestId });
|
|
1819
|
+
}
|
|
1820
|
+
};
|
|
1795
1821
|
try {
|
|
1796
1822
|
while (!signal?.aborted) {
|
|
1823
|
+
if (inFlight.size >= 4) await Promise.race(inFlight);
|
|
1824
|
+
if (resultFailure) throw resultFailure;
|
|
1797
1825
|
const next = await invoke2("/device-control/remote/poll", { sessionId, deviceId }, signal, 35e3);
|
|
1826
|
+
if (resultFailure) throw resultFailure;
|
|
1798
1827
|
if (next.notice !== void 0) log?.({ event: "plugin.tool", ...noticeValue(next.notice) });
|
|
1799
1828
|
if (next.command === null || next.command === void 0) continue;
|
|
1800
1829
|
const command = commandValue(next.command);
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
}
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
try {
|
|
1810
|
-
await invoke2("/device-control/remote/result", { sessionId, deviceId, requestId: command.requestId, ...outcome, executionMs: elapsed(startedAt) });
|
|
1811
|
-
} catch (error) {
|
|
1812
|
-
if (!(error instanceof RemoteResultExpiredError)) throw error;
|
|
1813
|
-
log?.({ event: "remote.result", status: "expired", deviceId, requestId: command.requestId });
|
|
1814
|
-
}
|
|
1830
|
+
if (dispatched.has(command.requestId)) continue;
|
|
1831
|
+
dispatched.add(command.requestId);
|
|
1832
|
+
if (dispatched.size > 2048) dispatched.delete(dispatched.values().next().value);
|
|
1833
|
+
const job = complete(command, bounded2(next.workspaceId, "workspace id")).catch((error) => {
|
|
1834
|
+
resultFailure ??= error;
|
|
1835
|
+
});
|
|
1836
|
+
inFlight.add(job);
|
|
1837
|
+
void job.then(() => inFlight.delete(job));
|
|
1815
1838
|
}
|
|
1839
|
+
if (resultFailure) throw resultFailure;
|
|
1816
1840
|
} finally {
|
|
1841
|
+
await Promise.allSettled(inFlight);
|
|
1817
1842
|
await authorizedRequest(fetcher, origin, stateDirectory, "/device-control/remote/disconnect", { sessionId, deviceId }, void 0, 5e3).catch(() => void 0);
|
|
1818
1843
|
log?.({ event: "remote.session", status: "disconnected", deviceId });
|
|
1819
1844
|
}
|