@codingfrees/uap-device-control 0.1.20 → 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/dist/uap-device-control.mjs +33 -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.21",
|
|
628
628
|
description: "Cross-platform outbound UAP Device Control client",
|
|
629
629
|
type: "module",
|
|
630
630
|
bin: {
|
|
@@ -1792,28 +1792,46 @@ 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 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
|
+
};
|
|
1795
1814
|
try {
|
|
1796
1815
|
while (!signal?.aborted) {
|
|
1816
|
+
if (inFlight.size >= 4) await Promise.race(inFlight);
|
|
1817
|
+
if (resultFailure) throw resultFailure;
|
|
1797
1818
|
const next = await invoke2("/device-control/remote/poll", { sessionId, deviceId }, signal, 35e3);
|
|
1819
|
+
if (resultFailure) throw resultFailure;
|
|
1798
1820
|
if (next.notice !== void 0) log?.({ event: "plugin.tool", ...noticeValue(next.notice) });
|
|
1799
1821
|
if (next.command === null || next.command === void 0) continue;
|
|
1800
1822
|
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
|
-
}
|
|
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));
|
|
1815
1831
|
}
|
|
1832
|
+
if (resultFailure) throw resultFailure;
|
|
1816
1833
|
} finally {
|
|
1834
|
+
await Promise.allSettled(inFlight);
|
|
1817
1835
|
await authorizedRequest(fetcher, origin, stateDirectory, "/device-control/remote/disconnect", { sessionId, deviceId }, void 0, 5e3).catch(() => void 0);
|
|
1818
1836
|
log?.({ event: "remote.session", status: "disconnected", deviceId });
|
|
1819
1837
|
}
|