@lynx-js/devtool-connector 0.13.2 → 0.16.3
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/CHANGELOG.md +19 -0
- package/LICENSE +1 -1
- package/README.md +18 -134
- package/dist/2.js +2019 -0
- package/dist/{346.js → a.js} +102 -143
- package/dist/client-id.d.ts +0 -6
- package/dist/command/client.d.ts +8 -7
- package/dist/command/contract.d.ts +82 -24
- package/dist/command/core.d.ts +11 -10
- package/dist/command/in-process-client.d.ts +16 -0
- package/dist/command/index.d.ts +28 -20
- package/dist/command/index.js +177 -159
- package/dist/command/list-clients.d.ts +6 -0
- package/dist/command/list-sessions.d.ts +5 -0
- package/dist/command/open.d.ts +5 -0
- package/dist/command/query.d.ts +1 -1
- package/dist/command/reactlynx/controller.d.ts +3 -3
- package/dist/command/reactlynx/model.d.ts +7 -7
- package/dist/command/reactlynx/protocol.d.ts +0 -1
- package/dist/command/reactlynx/session.d.ts +3 -3
- package/dist/command/reactlynx/types.d.ts +7 -7
- package/dist/command/ref-actions.d.ts +4 -4
- package/dist/command/result.d.ts +0 -1
- package/dist/command/screenshot-annotation.d.ts +2 -2
- package/dist/command/screenshot.d.ts +2 -2
- package/dist/command/snapshot.d.ts +2 -2
- package/dist/command/source-info.d.ts +20 -0
- package/dist/command/targets.d.ts +8 -10
- package/dist/command/timeout.d.ts +3 -0
- package/dist/command/wait-for-client.d.ts +5 -0
- package/dist/daemon/device-connection.d.ts +4 -3
- package/dist/daemon/entry.js +18 -20
- package/dist/daemon/index.d.ts +7 -2
- package/dist/daemon/index.js +7 -3
- package/dist/daemon/inspector-assets.d.ts +11 -0
- package/dist/daemon/manager.d.ts +12 -4
- package/dist/daemon/protocol.d.ts +20 -16
- package/dist/daemon/server.d.ts +7 -1
- package/dist/daemon/static-server.d.ts +3 -1
- package/dist/f.js +5790 -0
- package/dist/f1.js +737 -0
- package/dist/{962.js → h.js} +854 -3274
- package/dist/{712.js → hb.js} +26 -19
- package/dist/i.js +2505 -0
- package/dist/index.d.ts +13 -18
- package/dist/index.js +3 -2
- package/dist/main.d.ts +2 -0
- package/dist/main.js +3 -0
- package/dist/request-id.d.ts +1 -0
- package/dist/streams/cdp.d.ts +3 -3
- package/dist/streams/customized.d.ts +5 -5
- package/dist/streams/index.d.ts +4 -3
- package/dist/streams/index.js +1 -1
- package/dist/streams/utils.d.ts +3 -3
- package/dist/{872.js → t.js} +364 -301
- package/dist/transport/adb-shell-types.d.ts +14 -0
- package/dist/transport/android-app-icon-helper.d.ts +1 -0
- package/dist/transport/android.d.ts +13 -3
- package/dist/transport/base.d.ts +2 -9
- package/dist/transport/daemon.d.ts +3 -2
- package/dist/transport/desktop.d.ts +1 -1
- package/dist/transport/hdt.d.ts +13 -0
- package/dist/transport/index.d.ts +9 -9
- package/dist/transport/index.js +2 -3
- package/dist/transport/ios.d.ts +2 -2
- package/dist/transport/peertalk.d.ts +4 -3
- package/dist/transport/stream-lifecycle.d.ts +4 -0
- package/dist/transport/transport.d.ts +4 -8
- package/dist/transport/usbmux.d.ts +5 -5
- package/dist/transport/ws-stream.d.ts +3 -10
- package/dist/types.d.ts +28 -24
- package/dist/{63.js → ws-stream.js} +23 -24
- package/package.json +33 -23
- package/dist/390.js +0 -329
- package/dist/556.js +0 -258
- package/dist/61.js +0 -3432
package/dist/command/index.js
CHANGED
|
@@ -1,185 +1,82 @@
|
|
|
1
|
-
import { DaemonManager } from "../
|
|
2
|
-
import { fail as result_fail, appendCommandQueryParam } from "../
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { DaemonManager } from "../2.js";
|
|
2
|
+
import { fail as result_fail, appendCommandQueryParam, ActionCore } from "../f.js";
|
|
3
|
+
const DEFAULT_COMMAND_TIMEOUT_MS = 30000;
|
|
4
|
+
const HEADLESS_OPEN_TIMEOUT_MS = 360000;
|
|
5
|
+
function getDefaultCommandTimeoutMs(action, params) {
|
|
6
|
+
const clientId = params["clientId"];
|
|
7
|
+
if ("open" === action && "string" == typeof clientId && clientId.trim().startsWith("headless:")) return HEADLESS_OPEN_TIMEOUT_MS;
|
|
8
|
+
return DEFAULT_COMMAND_TIMEOUT_MS;
|
|
8
9
|
}
|
|
10
|
+
const MAX_SSE_BUFFER_LENGTH = 1048576;
|
|
9
11
|
async function responseText(response) {
|
|
10
12
|
try {
|
|
11
13
|
return await response.text();
|
|
12
14
|
} catch {
|
|
13
|
-
return
|
|
15
|
+
return "";
|
|
14
16
|
}
|
|
15
17
|
}
|
|
16
18
|
function httpFailure(action, response, body) {
|
|
17
|
-
const suffix = body.trim() ? `: ${body.trim()}` :
|
|
19
|
+
const suffix = body.trim() ? `: ${body.trim()}` : "";
|
|
18
20
|
return result_fail(action, `Daemon command ${action} failed with HTTP ${response.status} ${response.statusText}${suffix}`, {
|
|
19
|
-
reason:
|
|
21
|
+
reason: "http-error",
|
|
20
22
|
recoverable: true,
|
|
21
23
|
nextActions: [
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
"Ensure the connector daemon is running and up to date.",
|
|
25
|
+
"Retry after restarting the connector daemon."
|
|
24
26
|
]
|
|
25
27
|
});
|
|
26
28
|
}
|
|
27
29
|
function isCommandResult(value) {
|
|
28
|
-
if (
|
|
30
|
+
if ("object" != typeof value || null === value) return false;
|
|
29
31
|
const candidate = value;
|
|
30
|
-
if (
|
|
31
|
-
if (true === candidate[
|
|
32
|
-
const error = candidate[
|
|
33
|
-
if (
|
|
32
|
+
if ("string" != typeof candidate["action"] || "boolean" != typeof candidate["ok"]) return false;
|
|
33
|
+
if (true === candidate["ok"]) return Object.hasOwn(candidate, "data");
|
|
34
|
+
const error = candidate["error"];
|
|
35
|
+
if ("object" != typeof error || null === error) return false;
|
|
34
36
|
const commandError = error;
|
|
35
|
-
return
|
|
37
|
+
return "string" == typeof commandError["message"] && "boolean" == typeof commandError["recoverable"] && Array.isArray(commandError["nextActions"]) && commandError["nextActions"].every((item)=>"string" == typeof item) && (void 0 === commandError["reason"] || "string" == typeof commandError["reason"]);
|
|
36
38
|
}
|
|
37
39
|
function invalidResponse(action, message, cause) {
|
|
38
40
|
return result_fail(action, message, {
|
|
39
|
-
reason:
|
|
41
|
+
reason: "invalid-response",
|
|
40
42
|
recoverable: true,
|
|
41
43
|
...void 0 === cause ? {} : {
|
|
42
44
|
cause
|
|
43
45
|
},
|
|
44
46
|
nextActions: [
|
|
45
|
-
|
|
47
|
+
"Restart the connector daemon, then retry the command."
|
|
46
48
|
]
|
|
47
49
|
});
|
|
48
50
|
}
|
|
49
51
|
function requestFailure(action, error, signal) {
|
|
50
|
-
const aborted = signal?.aborted === true || error instanceof DOMException && (
|
|
52
|
+
const aborted = signal?.aborted === true || error instanceof DOMException && ("AbortError" === error.name || "TimeoutError" === error.name);
|
|
51
53
|
return result_fail(action, aborted ? `Daemon command ${action} was aborted or timed out.` : `Unable to reach the connector daemon for command ${action}.`, {
|
|
52
54
|
cause: error,
|
|
53
|
-
reason: aborted ?
|
|
55
|
+
reason: aborted ? "aborted" : "daemon-unavailable",
|
|
54
56
|
recoverable: true,
|
|
55
57
|
nextActions: [
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
"Ensure the connector daemon is running and up to date.",
|
|
59
|
+
"Retry after restarting the connector daemon."
|
|
58
60
|
]
|
|
59
61
|
});
|
|
60
62
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const signal = AbortSignal.timeout(options.timeoutMs ?? 30000);
|
|
64
|
-
let response;
|
|
65
|
-
try {
|
|
66
|
-
await ensureCommandServer(port, options.ensureDaemon ?? true);
|
|
67
|
-
response = await fetch(`http://127.0.0.1:${port}/command/${encodeURIComponent(action)}`, {
|
|
68
|
-
method: 'POST',
|
|
69
|
-
headers: {
|
|
70
|
-
'content-type': 'application/json'
|
|
71
|
-
},
|
|
72
|
-
body: JSON.stringify(params),
|
|
73
|
-
signal
|
|
74
|
-
});
|
|
75
|
-
} catch (error) {
|
|
76
|
-
return requestFailure(action, error, signal);
|
|
77
|
-
}
|
|
78
|
-
if (!response.ok) return httpFailure(action, response, await responseText(response));
|
|
79
|
-
try {
|
|
80
|
-
const parsed = await response.json();
|
|
81
|
-
if (isCommandResult(parsed)) return parsed;
|
|
82
|
-
return invalidResponse(action, `Daemon command ${action} returned an invalid result envelope.`);
|
|
83
|
-
} catch (error) {
|
|
84
|
-
return invalidResponse(action, `Daemon command ${action} returned invalid JSON.`, error);
|
|
85
|
-
}
|
|
63
|
+
function callRawCommand(action, params, options = {}) {
|
|
64
|
+
return new HttpCommandClient(options).executeRaw(action, params, options);
|
|
86
65
|
}
|
|
87
66
|
function callCommand(action, params, options = {}) {
|
|
88
|
-
return callRawCommand(action, params,
|
|
67
|
+
return callRawCommand(action, params, {
|
|
68
|
+
...options,
|
|
69
|
+
timeoutMs: options.timeoutMs ?? getDefaultCommandTimeoutMs(action, params)
|
|
70
|
+
});
|
|
89
71
|
}
|
|
90
72
|
function getStreamUrl(port, action, params) {
|
|
91
73
|
const query = new URLSearchParams();
|
|
92
74
|
for (const [key, value] of Object.entries(params))appendCommandQueryParam(query, key, value);
|
|
93
|
-
const suffix = query.size > 0 ? `?${query}` :
|
|
75
|
+
const suffix = query.size > 0 ? `?${query}` : "";
|
|
94
76
|
return `http://127.0.0.1:${port}/command/${encodeURIComponent(action)}${suffix}`;
|
|
95
77
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const method = options.method ?? 'POST';
|
|
99
|
-
let response;
|
|
100
|
-
try {
|
|
101
|
-
options.signal?.throwIfAborted();
|
|
102
|
-
await ensureCommandServer(port, options.ensureDaemon ?? true);
|
|
103
|
-
response = await fetch('GET' === method ? getStreamUrl(port, action, params) : `http://127.0.0.1:${port}/command/${encodeURIComponent(action)}`, {
|
|
104
|
-
method,
|
|
105
|
-
headers: {
|
|
106
|
-
accept: 'text/event-stream',
|
|
107
|
-
...'POST' === method ? {
|
|
108
|
-
'content-type': 'application/json'
|
|
109
|
-
} : {}
|
|
110
|
-
},
|
|
111
|
-
...'POST' === method ? {
|
|
112
|
-
body: JSON.stringify(params)
|
|
113
|
-
} : {},
|
|
114
|
-
...options.signal ? {
|
|
115
|
-
signal: options.signal
|
|
116
|
-
} : {}
|
|
117
|
-
});
|
|
118
|
-
} catch (error) {
|
|
119
|
-
yield requestFailure(action, error, options.signal);
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (!response.ok) return void (yield httpFailure(action, response, await responseText(response)));
|
|
123
|
-
if (!response.body) return void (yield result_fail(action, `Daemon stream ${action} returned no response body.`, {
|
|
124
|
-
reason: 'invalid-response',
|
|
125
|
-
recoverable: true
|
|
126
|
-
}));
|
|
127
|
-
if (!response.headers.get('content-type')?.toLowerCase().startsWith('text/event-stream')) return void (yield result_fail(action, `Daemon stream ${action} returned a non-SSE response.`, {
|
|
128
|
-
reason: 'invalid-response',
|
|
129
|
-
recoverable: true
|
|
130
|
-
}));
|
|
131
|
-
const decoder = new TextDecoder();
|
|
132
|
-
let buffer = '';
|
|
133
|
-
const drainDataEvents = function*() {
|
|
134
|
-
for(;;){
|
|
135
|
-
const match = /\r?\n\r?\n/.exec(buffer);
|
|
136
|
-
if (null === match) return;
|
|
137
|
-
const rawEvent = buffer.slice(0, match.index);
|
|
138
|
-
buffer = buffer.slice(match.index + match[0].length);
|
|
139
|
-
const data = rawEvent.split(/\r?\n/).filter((line)=>line.startsWith('data:')).map((line)=>line.slice(5).trimStart()).join('\n');
|
|
140
|
-
if ('' !== data) yield data;
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
const parseEvent = (data)=>{
|
|
144
|
-
try {
|
|
145
|
-
const parsed = JSON.parse(data);
|
|
146
|
-
if (!isCommandResult(parsed)) throw new Error('SSE data is not a command result envelope.');
|
|
147
|
-
return parsed;
|
|
148
|
-
} catch (error) {
|
|
149
|
-
return invalidResponse(action, `Daemon stream ${action} returned invalid SSE data.`, error);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
const reader = response.body.getReader();
|
|
153
|
-
let completed = false;
|
|
154
|
-
try {
|
|
155
|
-
for(;;){
|
|
156
|
-
const { done, value } = await reader.read();
|
|
157
|
-
if (done) {
|
|
158
|
-
completed = true;
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
buffer += decoder.decode(value, {
|
|
162
|
-
stream: true
|
|
163
|
-
});
|
|
164
|
-
if (buffer.length > MAX_SSE_BUFFER_LENGTH) return void (yield invalidResponse(action, `Daemon stream ${action} exceeded the 1 MiB SSE event limit.`));
|
|
165
|
-
for (const data of drainDataEvents()){
|
|
166
|
-
const event = parseEvent(data);
|
|
167
|
-
yield event;
|
|
168
|
-
if (!event.ok && 'invalid-response' === event.error.reason) return;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
buffer += decoder.decode();
|
|
172
|
-
if (buffer.length > MAX_SSE_BUFFER_LENGTH) return void (yield invalidResponse(action, `Daemon stream ${action} exceeded the 1 MiB SSE event limit.`));
|
|
173
|
-
if ('' !== buffer.trim()) buffer += '\n\n';
|
|
174
|
-
for (const data of drainDataEvents()){
|
|
175
|
-
const event = parseEvent(data);
|
|
176
|
-
yield event;
|
|
177
|
-
if (!event.ok && 'invalid-response' === event.error.reason) return;
|
|
178
|
-
}
|
|
179
|
-
} finally{
|
|
180
|
-
if (!completed) await reader.cancel(new Error('Command stream consumer stopped.')).catch(()=>{});
|
|
181
|
-
reader.releaseLock();
|
|
182
|
-
}
|
|
78
|
+
function streamRawCommand(action, params, options = {}) {
|
|
79
|
+
return new HttpCommandClient(options).streamRaw(action, params, options);
|
|
183
80
|
}
|
|
184
81
|
function streamCommand(action, params, options = {}) {
|
|
185
82
|
return streamRawCommand(action, params, options);
|
|
@@ -192,33 +89,154 @@ class HttpCommandClient {
|
|
|
192
89
|
this.#ensureDaemon = options.ensureDaemon ?? true;
|
|
193
90
|
}
|
|
194
91
|
execute(action, params, options = {}) {
|
|
195
|
-
return
|
|
92
|
+
return this.executeRaw(action, params, {
|
|
196
93
|
...options,
|
|
197
|
-
|
|
198
|
-
ensureDaemon: this.#ensureDaemon
|
|
94
|
+
timeoutMs: options.timeoutMs ?? getDefaultCommandTimeoutMs(action, params)
|
|
199
95
|
});
|
|
200
96
|
}
|
|
201
97
|
stream(action, params, options = {}) {
|
|
202
|
-
return
|
|
203
|
-
...options,
|
|
204
|
-
port: this.#port,
|
|
205
|
-
ensureDaemon: this.#ensureDaemon
|
|
206
|
-
});
|
|
98
|
+
return this.streamRaw(action, params, options);
|
|
207
99
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
port: this.#port,
|
|
212
|
-
ensureDaemon: this.#ensureDaemon
|
|
100
|
+
async ensureDaemonRunning(port) {
|
|
101
|
+
await DaemonManager.ensureRunning(port, {
|
|
102
|
+
commandProtocol: true
|
|
213
103
|
});
|
|
214
104
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
105
|
+
async executeRaw(action, params, options = {}) {
|
|
106
|
+
const port = this.#port;
|
|
107
|
+
const signal = AbortSignal.timeout(options.timeoutMs ?? 30000);
|
|
108
|
+
let response;
|
|
109
|
+
try {
|
|
110
|
+
if (this.#ensureDaemon) await this.ensureDaemonRunning(port);
|
|
111
|
+
response = await fetch(`http://127.0.0.1:${port}/command/${encodeURIComponent(action)}`, {
|
|
112
|
+
method: "POST",
|
|
113
|
+
headers: {
|
|
114
|
+
"content-type": "application/json"
|
|
115
|
+
},
|
|
116
|
+
body: JSON.stringify(params),
|
|
117
|
+
signal
|
|
118
|
+
});
|
|
119
|
+
} catch (error) {
|
|
120
|
+
return requestFailure(action, error, signal);
|
|
121
|
+
}
|
|
122
|
+
if (!response.ok) return httpFailure(action, response, await responseText(response));
|
|
123
|
+
try {
|
|
124
|
+
const parsed = await response.json();
|
|
125
|
+
if (isCommandResult(parsed)) return parsed;
|
|
126
|
+
return invalidResponse(action, `Daemon command ${action} returned an invalid result envelope.`);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
return invalidResponse(action, `Daemon command ${action} returned invalid JSON.`, error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async *streamRaw(action, params, options = {}) {
|
|
132
|
+
const port = this.#port;
|
|
133
|
+
const method = options.method ?? "POST";
|
|
134
|
+
let response;
|
|
135
|
+
try {
|
|
136
|
+
options.signal?.throwIfAborted();
|
|
137
|
+
if (this.#ensureDaemon) await this.ensureDaemonRunning(port);
|
|
138
|
+
response = await fetch("GET" === method ? getStreamUrl(port, action, params) : `http://127.0.0.1:${port}/command/${encodeURIComponent(action)}`, {
|
|
139
|
+
method,
|
|
140
|
+
headers: {
|
|
141
|
+
accept: "text/event-stream",
|
|
142
|
+
..."POST" === method ? {
|
|
143
|
+
"content-type": "application/json"
|
|
144
|
+
} : {}
|
|
145
|
+
},
|
|
146
|
+
..."POST" === method ? {
|
|
147
|
+
body: JSON.stringify(params)
|
|
148
|
+
} : {},
|
|
149
|
+
...options.signal ? {
|
|
150
|
+
signal: options.signal
|
|
151
|
+
} : {}
|
|
152
|
+
});
|
|
153
|
+
} catch (error) {
|
|
154
|
+
yield requestFailure(action, error, options.signal);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (!response.ok) return void (yield httpFailure(action, response, await responseText(response)));
|
|
158
|
+
if (!response.body) return void (yield result_fail(action, `Daemon stream ${action} returned no response body.`, {
|
|
159
|
+
reason: "invalid-response",
|
|
160
|
+
recoverable: true
|
|
161
|
+
}));
|
|
162
|
+
if (!response.headers.get("content-type")?.toLowerCase().startsWith("text/event-stream")) return void (yield result_fail(action, `Daemon stream ${action} returned a non-SSE response.`, {
|
|
163
|
+
reason: "invalid-response",
|
|
164
|
+
recoverable: true
|
|
165
|
+
}));
|
|
166
|
+
const decoder = new TextDecoder();
|
|
167
|
+
let buffer = "";
|
|
168
|
+
const drainDataEvents = function*() {
|
|
169
|
+
for(let match = /\r?\n\r?\n/.exec(buffer); null !== match; match = /\r?\n\r?\n/.exec(buffer)){
|
|
170
|
+
const rawEvent = buffer.slice(0, match.index);
|
|
171
|
+
buffer = buffer.slice(match.index + match[0].length);
|
|
172
|
+
const data = rawEvent.split(/\r?\n/).filter((line)=>line.startsWith("data:")).map((line)=>line.slice(5).trimStart()).join("\n");
|
|
173
|
+
if ("" !== data) yield data;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const parseEvent = (data)=>{
|
|
177
|
+
try {
|
|
178
|
+
const parsed = JSON.parse(data);
|
|
179
|
+
if (!isCommandResult(parsed)) throw new Error("SSE data is not a command result envelope.");
|
|
180
|
+
return parsed;
|
|
181
|
+
} catch (error) {
|
|
182
|
+
return invalidResponse(action, `Daemon stream ${action} returned invalid SSE data.`, error);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
const reader = response.body.getReader();
|
|
186
|
+
let completed = false;
|
|
187
|
+
try {
|
|
188
|
+
for(;;){
|
|
189
|
+
const { done, value } = await reader.read();
|
|
190
|
+
if (done) {
|
|
191
|
+
completed = true;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
buffer += decoder.decode(value, {
|
|
195
|
+
stream: true
|
|
196
|
+
});
|
|
197
|
+
if (buffer.length > MAX_SSE_BUFFER_LENGTH) return void (yield invalidResponse(action, `Daemon stream ${action} exceeded the 1 MiB SSE event limit.`));
|
|
198
|
+
for (const data of drainDataEvents()){
|
|
199
|
+
const event = parseEvent(data);
|
|
200
|
+
yield event;
|
|
201
|
+
if (!event.ok && "invalid-response" === event.error.reason) return;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
buffer += decoder.decode();
|
|
205
|
+
if (buffer.length > MAX_SSE_BUFFER_LENGTH) return void (yield invalidResponse(action, `Daemon stream ${action} exceeded the 1 MiB SSE event limit.`));
|
|
206
|
+
if ("" !== buffer.trim()) buffer += "\n\n";
|
|
207
|
+
for (const data of drainDataEvents()){
|
|
208
|
+
const event = parseEvent(data);
|
|
209
|
+
yield event;
|
|
210
|
+
if (!event.ok && "invalid-response" === event.error.reason) return;
|
|
211
|
+
}
|
|
212
|
+
} finally{
|
|
213
|
+
if (!completed) await reader.cancel(new Error("Command stream consumer stopped.")).catch(()=>{});
|
|
214
|
+
reader.releaseLock();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
class InProcessCommandClient {
|
|
219
|
+
#connector;
|
|
220
|
+
#core;
|
|
221
|
+
constructor(connector, core = new ActionCore()){
|
|
222
|
+
this.#connector = connector;
|
|
223
|
+
this.#core = core;
|
|
224
|
+
}
|
|
225
|
+
execute(action, params, options = {}) {
|
|
226
|
+
const commandParams = params;
|
|
227
|
+
const signal = AbortSignal.timeout(options.timeoutMs ?? getDefaultCommandTimeoutMs(action, commandParams));
|
|
228
|
+
return this.#core.execute(action, commandParams, {
|
|
229
|
+
connector: this.#connector
|
|
230
|
+
}, signal);
|
|
231
|
+
}
|
|
232
|
+
stream(action, params, options = {}) {
|
|
233
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
234
|
+
return this.#core.stream(action, params, {
|
|
235
|
+
connector: this.#connector
|
|
236
|
+
}, signal);
|
|
221
237
|
}
|
|
222
238
|
}
|
|
223
|
-
|
|
224
|
-
|
|
239
|
+
var command_DEFAULT_REACTLYNX_IDLE_MS = 700;
|
|
240
|
+
var command_DEFAULT_REACTLYNX_MAX_MS = 5000;
|
|
241
|
+
export { ActionCore, DevNodeType, NO_CLIENTS_FOUND_MESSAGE, ScreenshotAnnotationError, ScreenshotTimeoutError, annotateScreenshot, applyOperationV2, applyRootOrder, buildReactLynxOutboundFrame, buildReactLynxUpdatePath, buildRefs, buildRegexMatcher, buildSnapshot, buildSubstringMatcher, captureScreenshot, captureScreenshotFrame, centerOfQuad, createRendererState, deserializeRendererState, fail, fetchDebugMetadata, findReactLynxComponents, formatReactLynxTree, getOriginalNodeSourceInfo, listClientsAction, listSessionsAction, normalizeRef, ok, openAction, parseReactLynxComponentRef, parseReactLynxLinkRef, reactLynxEmptyTreeDiagnostic, remapOriginalNodeSourceInfo, runReactLynxSession, serializeRendererState, touchTap, typeTag, validateRef, waitForClientStream } from "../f.js";
|
|
242
|
+
export { HttpCommandClient, InProcessCommandClient, callCommand, callRawCommand, command_DEFAULT_REACTLYNX_IDLE_MS as DEFAULT_REACTLYNX_IDLE_MS, command_DEFAULT_REACTLYNX_MAX_MS as DEFAULT_REACTLYNX_MAX_MS, streamCommand, streamRawCommand };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Connector } from "../index.js";
|
|
2
|
+
import type { CommandData } from "./contract.js";
|
|
3
|
+
import { type CommandResult } from "./result.js";
|
|
4
|
+
export declare const NO_CLIENTS_FOUND_MESSAGE: string;
|
|
5
|
+
/** The sole production implementation of the list-clients command. */
|
|
6
|
+
export declare function listClientsAction(connector: Pick<Connector, "listClients">): Promise<CommandResult<CommandData<"list-clients">>>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Connector } from "../index.js";
|
|
2
|
+
import type { CommandData, CommandParams } from "./contract.js";
|
|
3
|
+
import { type CommandResult } from "./result.js";
|
|
4
|
+
/** The sole production implementation of the list-sessions command. */
|
|
5
|
+
export declare function listSessionsAction(connector: Pick<Connector, "sendListSessionMessage">, params: CommandParams<"list-sessions">): Promise<CommandResult<CommandData<"list-sessions">>>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Connector } from "../index.js";
|
|
2
|
+
import type { CommandData, CommandParams } from "./contract.js";
|
|
3
|
+
import { type CommandResult } from "./result.js";
|
|
4
|
+
/** The sole production implementation of the open command. */
|
|
5
|
+
export declare function openAction(connector: Pick<Connector, "openPage" | "waitForHeadlessReady">, params: CommandParams<"open">, signal?: AbortSignal): Promise<CommandResult<CommandData<"open">>>;
|
package/dist/command/query.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CommandObject } from
|
|
1
|
+
import type { CommandObject } from "./contract.js";
|
|
2
2
|
/** Preserve value types when a command client uses the curl-friendly GET SSE route. */
|
|
3
3
|
export declare function appendCommandQueryParam(query: URLSearchParams, key: string, value: unknown): void;
|
|
4
4
|
/** Decode both typed-client values and repeated, unprefixed curl parameters. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Connector } from
|
|
2
|
-
import type { ID } from
|
|
3
|
-
import type { ReactLynxCacheInfo, ReactLynxComponentData, ReactLynxFindData, ReactLynxLinkedComponent, ReactLynxTreeData, ReactLynxUpdateKind } from
|
|
1
|
+
import type { Connector } from "../../index.js";
|
|
2
|
+
import type { ID } from "./protocol.js";
|
|
3
|
+
import type { ReactLynxCacheInfo, ReactLynxComponentData, ReactLynxFindData, ReactLynxLinkedComponent, ReactLynxTreeData, ReactLynxUpdateKind } from "./types.js";
|
|
4
4
|
export interface ReactLynxCacheSnapshot {
|
|
5
5
|
capturedAt: number;
|
|
6
6
|
generation: number;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type ID, type RendererState, type VNode } from
|
|
2
|
-
import type { ReactLynxFindMatch } from
|
|
1
|
+
import { type ID, type RendererState, type VNode } from "./protocol.js";
|
|
2
|
+
import type { ReactLynxFindMatch } from "./types.js";
|
|
3
3
|
export interface FormattedReactLynxTree {
|
|
4
4
|
text: string;
|
|
5
5
|
/** `labels[index]` is the vnode id represented by `@c${index + 1}`. */
|
|
@@ -10,13 +10,13 @@ export interface ReactLynxTreeState {
|
|
|
10
10
|
nodes: VNode[];
|
|
11
11
|
}
|
|
12
12
|
export type ReactLynxLinkRef = {
|
|
13
|
-
kind:
|
|
13
|
+
kind: "element";
|
|
14
14
|
ref: string;
|
|
15
15
|
} | {
|
|
16
|
-
kind:
|
|
16
|
+
kind: "component-label";
|
|
17
17
|
index: number;
|
|
18
18
|
} | {
|
|
19
|
-
kind:
|
|
19
|
+
kind: "component-id";
|
|
20
20
|
id: ID;
|
|
21
21
|
};
|
|
22
22
|
/** Assign canonical `@cN` labels and render the matching compact tree. */
|
|
@@ -37,10 +37,10 @@ export declare function findReactLynxComponents(state: RendererState, matcher: (
|
|
|
37
37
|
formatted?: FormattedReactLynxTree;
|
|
38
38
|
}): ReactLynxFindMatch[];
|
|
39
39
|
export declare function parseReactLynxComponentRef(ref: string): {
|
|
40
|
-
kind:
|
|
40
|
+
kind: "label";
|
|
41
41
|
index: number;
|
|
42
42
|
} | {
|
|
43
|
-
kind:
|
|
43
|
+
kind: "id";
|
|
44
44
|
id: ID;
|
|
45
45
|
};
|
|
46
46
|
export declare function parseReactLynxLinkRef(ref: string): ReactLynxLinkRef;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Connector } from
|
|
2
|
-
import { type RendererState } from
|
|
1
|
+
import type { Connector } from "../../index.js";
|
|
2
|
+
import { type RendererState } from "./protocol.js";
|
|
3
3
|
export declare const DEFAULT_REACTLYNX_IDLE_MS = 700;
|
|
4
4
|
export declare const DEFAULT_REACTLYNX_MAX_MS = 5000;
|
|
5
5
|
export interface PreactEnvelope<T = unknown> {
|
|
@@ -23,7 +23,7 @@ export interface ReactLynxSessionResult {
|
|
|
23
23
|
rootOrderFrames: number;
|
|
24
24
|
envelopeTypes: Set<string>;
|
|
25
25
|
}
|
|
26
|
-
export type ReactLynxEnvelopeAction =
|
|
26
|
+
export type ReactLynxEnvelopeAction = "continue" | "stop";
|
|
27
27
|
export interface RunReactLynxSessionOptions {
|
|
28
28
|
connector: Connector;
|
|
29
29
|
clientId: string;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { SnapshotRef } from
|
|
2
|
-
import type { DevNodeType, ID, VNode } from
|
|
1
|
+
import type { SnapshotRef } from "../snapshot.js";
|
|
2
|
+
import type { DevNodeType, ID, VNode } from "./protocol.js";
|
|
3
3
|
export type ReactLynxCacheInfo = {
|
|
4
|
-
status:
|
|
4
|
+
status: "not-used";
|
|
5
5
|
} | {
|
|
6
|
-
status:
|
|
6
|
+
status: "refreshed" | "reused";
|
|
7
7
|
generation: number;
|
|
8
8
|
capturedAt: number;
|
|
9
9
|
};
|
|
@@ -65,9 +65,9 @@ export interface ReactLynxLinkedComponent {
|
|
|
65
65
|
key: string;
|
|
66
66
|
}
|
|
67
67
|
export interface ReactLynxLinkData extends ReactLynxTargetData {
|
|
68
|
-
direction:
|
|
69
|
-
relation:
|
|
68
|
+
direction: "element-to-component" | "component-to-element";
|
|
69
|
+
relation: "nearest-component" | "first-host-element";
|
|
70
70
|
element: SnapshotRef;
|
|
71
71
|
component: ReactLynxLinkedComponent;
|
|
72
72
|
}
|
|
73
|
-
export type ReactLynxUpdateKind =
|
|
73
|
+
export type ReactLynxUpdateKind = "update-prop" | "update-state" | "update-context";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Connector } from
|
|
2
|
-
import { type CommandFailure } from
|
|
3
|
-
import { type Point, type SnapshotRef } from
|
|
4
|
-
export type RefFailureReason =
|
|
1
|
+
import type { Connector } from "../index.js";
|
|
2
|
+
import { type CommandFailure } from "./result.js";
|
|
3
|
+
import { type Point, type SnapshotRef } from "./snapshot.js";
|
|
4
|
+
export type RefFailureReason = "no-snapshot" | "ref-not-found" | "stale-ref" | "not-visible" | "covered" | "offscreen" | "disabled" | "not-editable";
|
|
5
5
|
export declare function normalizeRef(ref: string): string;
|
|
6
6
|
export type RefValidationResult = CommandFailure | {
|
|
7
7
|
ok: true;
|
package/dist/command/result.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ScreenshotAnnotation } from
|
|
2
|
-
import { type Box, type SnapshotRef } from
|
|
1
|
+
import type { ScreenshotAnnotation } from "./contract.js";
|
|
2
|
+
import { type Box, type SnapshotRef } from "./snapshot.js";
|
|
3
3
|
export declare class ScreenshotAnnotationError extends Error {
|
|
4
4
|
constructor(message: string, options?: ErrorOptions);
|
|
5
5
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Connector } from
|
|
1
|
+
import type { Connector } from "../index.js";
|
|
2
2
|
export interface CaptureScreenshotOptions {
|
|
3
3
|
fullscreen?: boolean;
|
|
4
4
|
quality?: number;
|
|
@@ -20,7 +20,7 @@ export interface CapturedScreenshot {
|
|
|
20
20
|
metadata?: ScreencastFrameMetadata;
|
|
21
21
|
}
|
|
22
22
|
export declare class ScreenshotTimeoutError extends Error {
|
|
23
|
-
constructor(timeoutMs: number);
|
|
23
|
+
constructor(timeoutMs: number, phase?: "frame" | "acknowledgement");
|
|
24
24
|
}
|
|
25
25
|
/** Capture one JPEG screencast frame, including its logical coordinate metadata. */
|
|
26
26
|
export declare function captureScreenshotFrame(connector: Connector, clientId: string, sessionId: number, options?: CaptureScreenshotOptions): Promise<CapturedScreenshot>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Connector } from
|
|
1
|
+
import type { Connector } from "../index.js";
|
|
2
2
|
/** A bounding box in CDP logical coordinates. */
|
|
3
3
|
export interface Box {
|
|
4
4
|
x: number;
|
|
@@ -23,7 +23,7 @@ export declare const SNAPSHOT_REF_HIT_NODE_IDS: unique symbol;
|
|
|
23
23
|
declare const SNAPSHOT_REF_VISIBLE_BOX: unique symbol;
|
|
24
24
|
declare const SNAPSHOT_REF_NEEDS_HIT_TEST: unique symbol;
|
|
25
25
|
export declare const SNAPSHOT_REF_ANNOTATION_ROLE: unique symbol;
|
|
26
|
-
export type SnapshotRefAnnotationRole =
|
|
26
|
+
export type SnapshotRefAnnotationRole = "action" | "editable" | "scrollable" | "target" | "generic";
|
|
27
27
|
/** Refs are stable only within the snapshot that produced them. */
|
|
28
28
|
export interface SnapshotRef {
|
|
29
29
|
ref: string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DebugMetadataAsset } from "@lynx-js/debug-metadata";
|
|
2
|
+
import type { Connector } from "../index.js";
|
|
3
|
+
export type RemapStatus = "mapped" | "runtime_only" | "unsupported";
|
|
4
|
+
export interface OriginalNodeSourceInfo {
|
|
5
|
+
nodeId?: number;
|
|
6
|
+
tag?: string;
|
|
7
|
+
nodeIndex?: number;
|
|
8
|
+
debugMetadataUrl?: string;
|
|
9
|
+
lazyBundleUrl?: string | null;
|
|
10
|
+
repo?: string | null;
|
|
11
|
+
source?: string | null;
|
|
12
|
+
line?: number | null;
|
|
13
|
+
column?: number | null;
|
|
14
|
+
status?: RemapStatus;
|
|
15
|
+
reason?: string | null;
|
|
16
|
+
}
|
|
17
|
+
export type DebugMetadataLoader = (url: string) => Promise<DebugMetadataAsset>;
|
|
18
|
+
export declare function fetchDebugMetadata(debugMetadataUrl: string): Promise<DebugMetadataAsset>;
|
|
19
|
+
export declare function remapOriginalNodeSourceInfo(sourceInfo: OriginalNodeSourceInfo, loader?: DebugMetadataLoader): Promise<OriginalNodeSourceInfo>;
|
|
20
|
+
export declare function getOriginalNodeSourceInfo(connector: Connector, clientId: string, sessionId: number, nodeId: number, signal?: AbortSignal, loader?: DebugMetadataLoader): Promise<OriginalNodeSourceInfo>;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import type { Connector } from
|
|
2
|
-
import type { CommandObject } from
|
|
3
|
-
import { type CommandResult } from
|
|
4
|
-
export type
|
|
1
|
+
import type { Connector } from "../index.js";
|
|
2
|
+
import type { CommandObject } from "./contract.js";
|
|
3
|
+
import { type CommandResult } from "./result.js";
|
|
4
|
+
export type TargetRequirement = "none" | "client" | "session";
|
|
5
|
+
export type ResolvedTarget = {
|
|
5
6
|
ok: true;
|
|
6
|
-
params: CommandObject
|
|
7
|
-
clientId: string;
|
|
8
|
-
sessionId: number;
|
|
9
|
-
};
|
|
7
|
+
params: CommandObject;
|
|
10
8
|
} | {
|
|
11
9
|
ok: false;
|
|
12
10
|
result: CommandResult<never>;
|
|
13
11
|
};
|
|
14
|
-
/** Resolve
|
|
15
|
-
export declare function
|
|
12
|
+
/** Resolve only the client/session target required by an action. */
|
|
13
|
+
export declare function resolveTarget(action: string, params: CommandObject, connector: Connector, requirement: TargetRequirement): Promise<ResolvedTarget>;
|