@velmlabs/unstuck-core 0.2.6 → 0.2.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/dist/index.js +20 -6
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -63,6 +63,16 @@ import {
|
|
|
63
63
|
parseViewerMessage
|
|
64
64
|
} from "@velmlabs/unstuck-protocol";
|
|
65
65
|
|
|
66
|
+
// src/stream/within.ts
|
|
67
|
+
var CAPTURE_TIMEOUT_MS = 5e3;
|
|
68
|
+
function within(p, ms, what) {
|
|
69
|
+
let timer;
|
|
70
|
+
const late = new Promise((_, reject) => {
|
|
71
|
+
timer = setTimeout(() => reject(new Error(`${what} did not answer within ${ms} ms`)), ms);
|
|
72
|
+
});
|
|
73
|
+
return Promise.race([p, late]).finally(() => clearTimeout(timer));
|
|
74
|
+
}
|
|
75
|
+
|
|
66
76
|
// src/stream/screencast.ts
|
|
67
77
|
function b64ToBytes(b64) {
|
|
68
78
|
const bin = atob(b64);
|
|
@@ -97,7 +107,7 @@ async function startScreencast(cdp, onFrame, opts = {}) {
|
|
|
97
107
|
const maxWidth = opts.maxWidth ?? 1600;
|
|
98
108
|
const maxHeight = opts.maxHeight ?? 1600;
|
|
99
109
|
await cdp.send("Page.startScreencast", { format: "jpeg", quality, maxWidth, maxHeight });
|
|
100
|
-
void captureFrame(cdp, quality, maxWidth, maxHeight).then(
|
|
110
|
+
void within(captureFrame(cdp, quality, maxWidth, maxHeight), CAPTURE_TIMEOUT_MS, "Page.captureScreenshot").then(
|
|
101
111
|
(f) => {
|
|
102
112
|
if (f && !framed && !stopped) onFrame(f);
|
|
103
113
|
},
|
|
@@ -122,8 +132,12 @@ async function startScreenshotPolling(cdp, onFrame, opts = {}) {
|
|
|
122
132
|
const tick = async () => {
|
|
123
133
|
const started = Date.now();
|
|
124
134
|
try {
|
|
125
|
-
const metrics = await
|
|
126
|
-
|
|
135
|
+
const metrics = await within(
|
|
136
|
+
cdp.send("Page.getLayoutMetrics"),
|
|
137
|
+
CAPTURE_TIMEOUT_MS,
|
|
138
|
+
"Page.getLayoutMetrics"
|
|
139
|
+
);
|
|
140
|
+
const shot = await within(cdp.send("Page.captureScreenshot", { format: "jpeg", quality }), CAPTURE_TIMEOUT_MS, "Page.captureScreenshot");
|
|
127
141
|
if (!stopped) {
|
|
128
142
|
const bin = atob(shot.data);
|
|
129
143
|
onFrame({
|
|
@@ -1477,7 +1491,7 @@ function createCloudAlerter(o) {
|
|
|
1477
1491
|
const headers = { Authorization: `Bearer ${o.apiKey}` };
|
|
1478
1492
|
let cache = null;
|
|
1479
1493
|
let lastSet = null;
|
|
1480
|
-
async function
|
|
1494
|
+
async function within2(what, call) {
|
|
1481
1495
|
const ac = new AbortController();
|
|
1482
1496
|
let timer;
|
|
1483
1497
|
const timeout = new Promise((_, reject) => {
|
|
@@ -1494,7 +1508,7 @@ function createCloudAlerter(o) {
|
|
|
1494
1508
|
}
|
|
1495
1509
|
async function devices() {
|
|
1496
1510
|
if (cache && now() - cache.at < CACHE_MS) return cache.devices;
|
|
1497
|
-
const list = await
|
|
1511
|
+
const list = await within2("devices lookup", async (signal) => {
|
|
1498
1512
|
const res = await doFetch(`${base}/api/v1/agent/devices`, { headers, signal });
|
|
1499
1513
|
if (res.status === 403 && (await res.json().catch(() => null))?.error === "alerts_not_allowed") {
|
|
1500
1514
|
log("[unstuck] alerts are not enabled for this API key (turn them on in your unstuck.sh dashboard)");
|
|
@@ -1533,7 +1547,7 @@ function createCloudAlerter(o) {
|
|
|
1533
1547
|
log(`[unstuck] alert sealed to ${ok.length} phone(s): ${named}`);
|
|
1534
1548
|
}
|
|
1535
1549
|
const sealed = ok.map((r) => ({ device: r.d.id, blob: r.blob }));
|
|
1536
|
-
const res = await
|
|
1550
|
+
const res = await within2(
|
|
1537
1551
|
"notify",
|
|
1538
1552
|
(signal) => doFetch(`${base}/api/v1/agent/notify`, {
|
|
1539
1553
|
method: "POST",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velmlabs/unstuck-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "The Unstuck takeover engine core: screencast, input, sessions and transports, usable in Node or Cloudflare Workers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"tldts": "^7.5.2",
|
|
50
|
-
"@velmlabs/unstuck-protocol": "0.2.
|
|
50
|
+
"@velmlabs/unstuck-protocol": "0.2.7"
|
|
51
51
|
},
|
|
52
52
|
"publishConfig": {
|
|
53
53
|
"access": "public"
|