@lynx-js/devtool-connector 0.18.0 → 0.18.2
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 +17 -0
- package/dist/2.js +1 -1
- package/dist/a.js +18 -8
- package/dist/daemon/device-connection.d.ts +1 -1
- package/dist/f.js +1 -1
- package/dist/f1.js +2 -1
- package/dist/h.js +14 -6
- package/dist/index.d.ts +1 -1
- package/dist/t.js +33 -8
- package/dist/transport/android.d.ts +1 -1
- package/dist/transport/desktop.d.ts +1 -0
- package/dist/transport/transport.d.ts +3 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @lynx-js/devtool-connector
|
|
2
2
|
|
|
3
|
+
## 0.18.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Route requests through a sole daemon without requiring a fresh device scan, so it can reuse a healthy pooled connection and validate unknown targets itself.
|
|
8
|
+
- Add a daemon-managed Simulator with a lazily prepared Core/native host, window options, and JSON/JavaScript page environments on `open`.
|
|
9
|
+
|
|
10
|
+
## 0.18.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Include transport and request context when a connection ends before a response.
|
|
15
|
+
- Add sandbox apps open -S/--restart to stop the target app before launching its page through the shared Transport restart option.
|
|
16
|
+
- Use the open command's deadline while waiting for the page SessionList, while keeping the 10-second default for direct library calls.
|
|
17
|
+
- Preserve device transport error names, codes and messages in daemon WebSocket close reasons.
|
|
18
|
+
- Allow HDT client discovery three seconds to complete its handshake and fresh ClientList exchange.
|
|
19
|
+
|
|
3
20
|
## 0.18.0
|
|
4
21
|
|
|
5
22
|
### Minor Changes
|
package/dist/2.js
CHANGED
|
@@ -1659,7 +1659,7 @@ const DAEMON_SHUTDOWN_PATH = `${DAEMON_WS_PATH}/shutdown`;
|
|
|
1659
1659
|
const DAEMON_INSPECTOR_PATH = `${DAEMON_WS_PATH}/inspector`;
|
|
1660
1660
|
const DAEMON_COMMAND_PATH_PREFIX = "/command/";
|
|
1661
1661
|
var package_namespaceObject = {
|
|
1662
|
-
rE: "0.18.
|
|
1662
|
+
rE: "0.18.2"
|
|
1663
1663
|
};
|
|
1664
1664
|
const CONNECTOR_VERSION = package_namespaceObject.rE;
|
|
1665
1665
|
const node_modules_semver = __webpack_require__("../../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/index.js");
|
package/dist/a.js
CHANGED
|
@@ -80,6 +80,15 @@ const clientSetupSwitches = [
|
|
|
80
80
|
function hasClientList(transport) {
|
|
81
81
|
return "function" == typeof transport.listClients;
|
|
82
82
|
}
|
|
83
|
+
function describeRequest(input) {
|
|
84
|
+
if ("object" != typeof input || null === input) return "request";
|
|
85
|
+
const message = input;
|
|
86
|
+
if ("string" == typeof message["method"]) return `method ${message["method"]}`;
|
|
87
|
+
if ("string" != typeof message["event"]) return "request";
|
|
88
|
+
const data = "object" == typeof message["data"] && null !== message["data"] ? message["data"] : void 0;
|
|
89
|
+
if ("string" == typeof data?.["type"]) return `${message["event"]} ${data["type"]}`;
|
|
90
|
+
return `${message["event"]} event`;
|
|
91
|
+
}
|
|
83
92
|
function isNonEmptyListSessionResponse(response) {
|
|
84
93
|
return isListSessionResponse(response) && response.data.data.length > 0;
|
|
85
94
|
}
|
|
@@ -202,7 +211,7 @@ class Connector {
|
|
|
202
211
|
]
|
|
203
212
|
});
|
|
204
213
|
}
|
|
205
|
-
async openPage(clientId, url) {
|
|
214
|
+
async openPage(clientId, url, signal) {
|
|
206
215
|
return await this.#sendMessage(clientId, {
|
|
207
216
|
event: "Customized",
|
|
208
217
|
data: {
|
|
@@ -219,7 +228,7 @@ class Connector {
|
|
|
219
228
|
output: [
|
|
220
229
|
new FilterTransformStream(isNonEmptyListSessionResponse)
|
|
221
230
|
]
|
|
222
|
-
});
|
|
231
|
+
}, signal);
|
|
223
232
|
}
|
|
224
233
|
async sendCDPMessage(clientId, sessionId, method, params, isMainThread = false) {
|
|
225
234
|
const id = nextRequestId();
|
|
@@ -359,6 +368,8 @@ class Connector {
|
|
|
359
368
|
return parsed;
|
|
360
369
|
}
|
|
361
370
|
async #findTransportWithDeviceId(deviceId) {
|
|
371
|
+
const [onlyTransport] = this.#transports;
|
|
372
|
+
if (1 === this.#transports.length && onlyTransport instanceof DaemonTransport) return onlyTransport;
|
|
362
373
|
const daemonTransport = await this.#findTransportWithDeviceIdInPool(this.#daemonTransports, deviceId);
|
|
363
374
|
if (daemonTransport) return daemonTransport;
|
|
364
375
|
const transport = await this.#findTransportWithDeviceIdInPool(this.#transports.filter((t)=>!(t instanceof DaemonTransport)), deviceId);
|
|
@@ -417,17 +428,16 @@ class Connector {
|
|
|
417
428
|
async #sendMessage(clientId, input, pipeline = {
|
|
418
429
|
input: [],
|
|
419
430
|
output: []
|
|
420
|
-
}) {
|
|
431
|
+
}, signal) {
|
|
421
432
|
const { deviceId, port } = this.#resolveClientId(clientId);
|
|
422
433
|
const transport = await this.#findTransportWithDeviceId(deviceId);
|
|
423
|
-
const signal = AbortSignal.timeout(10000);
|
|
424
434
|
return this.#sendMessageWithTransport(transport, {
|
|
425
435
|
deviceId,
|
|
426
436
|
port,
|
|
427
|
-
signal
|
|
428
|
-
}, input, pipeline);
|
|
437
|
+
signal: signal ?? AbortSignal.timeout(10000)
|
|
438
|
+
}, input, pipeline, describeRequest(input));
|
|
429
439
|
}
|
|
430
|
-
async #sendMessageWithTransport(transport, options, input, pipeline) {
|
|
440
|
+
async #sendMessageWithTransport(transport, options, input, pipeline, request = "request") {
|
|
431
441
|
const outputStream = await this.#connect(transport, options, ReadableStream.from([
|
|
432
442
|
input
|
|
433
443
|
]), pipeline);
|
|
@@ -446,7 +456,7 @@ class Connector {
|
|
|
446
456
|
if (response.done) {
|
|
447
457
|
options.signal?.throwIfAborted();
|
|
448
458
|
const clientId = ClientId.serialize(options.deviceId, options.port);
|
|
449
|
-
throw new Error(`
|
|
459
|
+
throw new Error(`Transport ${transport.constructor.name} ended cleanly (EOF) while waiting for a response to ${request} on clientId: ${clientId}.`);
|
|
450
460
|
} else result = response.value;
|
|
451
461
|
} catch (err) {
|
|
452
462
|
failed = true;
|
|
@@ -4,7 +4,7 @@ import { type AppInfo } from "../types.js";
|
|
|
4
4
|
export interface DeviceConnectionSubscriber {
|
|
5
5
|
readonly id: number;
|
|
6
6
|
send(message: unknown): void;
|
|
7
|
-
close(): void;
|
|
7
|
+
close(cause?: unknown): void;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Maintains a persistent connection to a single device:port through a real
|
package/dist/f.js
CHANGED
|
@@ -2115,7 +2115,7 @@ async function openAction(connector, params, signal) {
|
|
|
2115
2115
|
signal
|
|
2116
2116
|
} : {});
|
|
2117
2117
|
signal?.throwIfAborted();
|
|
2118
|
-
const response = await connector.openPage(clientId, params.url);
|
|
2118
|
+
const response = await connector.openPage(clientId, params.url, signal);
|
|
2119
2119
|
return ok("open", {
|
|
2120
2120
|
clientId,
|
|
2121
2121
|
response
|
package/dist/f1.js
CHANGED
|
@@ -219,7 +219,7 @@ class HDTTransport {
|
|
|
219
219
|
hasError: false
|
|
220
220
|
};
|
|
221
221
|
try {
|
|
222
|
-
const signal = AbortSignal.timeout(
|
|
222
|
+
const signal = AbortSignal.timeout(3000);
|
|
223
223
|
const conn = _ts_add_disposable_resource(env, await this.#createWebSocketStream(signal), true);
|
|
224
224
|
if ("ws://127.0.0.1:3005/ws" !== this.#url) try {
|
|
225
225
|
await requestFreshClientList(conn.readable, conn.writable, signal);
|
|
@@ -504,6 +504,7 @@ class DaemonTransport {
|
|
|
504
504
|
deviceId,
|
|
505
505
|
packageName,
|
|
506
506
|
withDataCleared: options?.withDataCleared,
|
|
507
|
+
restart: options?.restart,
|
|
507
508
|
schema: options?.schema
|
|
508
509
|
});
|
|
509
510
|
}
|
package/dist/h.js
CHANGED
|
@@ -8822,12 +8822,14 @@ function parseLauncherActivityComponents(output) {
|
|
|
8822
8822
|
return !/\s/u.test(line) && separatorIndex > 0 && separatorIndex === line.lastIndexOf("/") && separatorIndex < line.length - 1;
|
|
8823
8823
|
});
|
|
8824
8824
|
}
|
|
8825
|
-
function createOpenAppCommandArgs(componentName) {
|
|
8825
|
+
function createOpenAppCommandArgs(componentName, restart) {
|
|
8826
8826
|
return [
|
|
8827
8827
|
"am",
|
|
8828
8828
|
"start",
|
|
8829
8829
|
"-W",
|
|
8830
|
-
|
|
8830
|
+
...restart ? [
|
|
8831
|
+
"-S"
|
|
8832
|
+
] : [],
|
|
8831
8833
|
"-a",
|
|
8832
8834
|
"android.intent.action.MAIN",
|
|
8833
8835
|
"-c",
|
|
@@ -9043,7 +9045,7 @@ class AndroidTransport {
|
|
|
9043
9045
|
throw error;
|
|
9044
9046
|
}
|
|
9045
9047
|
}
|
|
9046
|
-
async openApp(deviceId, packageName, { withDataCleared, schema } = {}) {
|
|
9048
|
+
async openApp(deviceId, packageName, { withDataCleared, schema, restart = true } = {}) {
|
|
9047
9049
|
const env = {
|
|
9048
9050
|
stack: [],
|
|
9049
9051
|
error: void 0,
|
|
@@ -9072,7 +9074,9 @@ class AndroidTransport {
|
|
|
9072
9074
|
"am",
|
|
9073
9075
|
"start",
|
|
9074
9076
|
"-W",
|
|
9075
|
-
|
|
9077
|
+
...restart ? [
|
|
9078
|
+
"-S"
|
|
9079
|
+
] : [],
|
|
9076
9080
|
"-a",
|
|
9077
9081
|
"android.intent.action.VIEW",
|
|
9078
9082
|
"-d",
|
|
@@ -9089,7 +9093,7 @@ class AndroidTransport {
|
|
|
9089
9093
|
[componentName] = parseLauncherActivityComponents(queryOutput);
|
|
9090
9094
|
}
|
|
9091
9095
|
if (!componentName) throw new Error(`No launchable activity found for package ${packageName}.`);
|
|
9092
|
-
command = createOpenAppCommandArgs(componentName);
|
|
9096
|
+
command = createOpenAppCommandArgs(componentName, restart);
|
|
9093
9097
|
}
|
|
9094
9098
|
const output = await spawnWaitText(adb, command);
|
|
9095
9099
|
android_debug(`openApp output ${output}`);
|
|
@@ -9105,8 +9109,12 @@ class AndroidTransport {
|
|
|
9105
9109
|
}
|
|
9106
9110
|
const desktop_debug = ansi_createDebug("devtool-mcp-server:connector:desktop");
|
|
9107
9111
|
class DesktopTransport {
|
|
9112
|
+
#takeoverHDT;
|
|
9113
|
+
constructor(takeoverHDT = true){
|
|
9114
|
+
this.#takeoverHDT = takeoverHDT;
|
|
9115
|
+
}
|
|
9108
9116
|
async connect(options) {
|
|
9109
|
-
return connectWithPeertalk((opts)=>this.#connectRaw(opts), options);
|
|
9117
|
+
return connectWithPeertalk((opts)=>this.#connectRaw(opts), options, this.#takeoverHDT);
|
|
9110
9118
|
}
|
|
9111
9119
|
async close() {
|
|
9112
9120
|
desktop_debug("Desktop transport closed");
|
package/dist/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ export declare class Connector {
|
|
|
24
24
|
/**
|
|
25
25
|
* Open a page on the given client by sending an `OpenCard` Customized event.
|
|
26
26
|
*/
|
|
27
|
-
openPage(clientId: string, url: string): Promise<ListSessionResponse>;
|
|
27
|
+
openPage(clientId: string, url: string, signal?: AbortSignal): Promise<ListSessionResponse>;
|
|
28
28
|
sendCDPMessage<Output, Params = never>(clientId: string, sessionId: number, method: string, params?: Params, isMainThread?: boolean): Promise<Output>;
|
|
29
29
|
sendListSessionMessage(clientId: string): Promise<Session[]>;
|
|
30
30
|
/**
|
package/dist/t.js
CHANGED
|
@@ -138,6 +138,7 @@ class DeviceConnection {
|
|
|
138
138
|
async #readLoop() {
|
|
139
139
|
if (!this.#conn) return;
|
|
140
140
|
let terminalCause;
|
|
141
|
+
let readFailed = false;
|
|
141
142
|
try {
|
|
142
143
|
for await (const message of this.#conn.readable){
|
|
143
144
|
if (null === this.appInfo) {
|
|
@@ -151,21 +152,22 @@ class DeviceConnection {
|
|
|
151
152
|
if (!isClientListMessage(message)) this.#broadcast(message);
|
|
152
153
|
}
|
|
153
154
|
} catch (err) {
|
|
155
|
+
readFailed = true;
|
|
154
156
|
terminalCause = err;
|
|
155
157
|
if (!this.#disposed) debug("read loop error on %s: %O", this.key, err);
|
|
156
158
|
}
|
|
157
159
|
if (!this.#disposed) {
|
|
158
160
|
debug("device connection %s closed by remote", this.key);
|
|
159
|
-
this.#terminate(terminalCause ?? new Error(null === this.appInfo ? `Device connection ${this.key} closed before Register` : `Device connection ${this.key} closed by remote`), true);
|
|
161
|
+
this.#terminate(terminalCause ?? new Error(null === this.appInfo ? `Device connection ${this.key} closed before Register` : `Device connection ${this.key} closed by remote`), true, !readFailed);
|
|
160
162
|
}
|
|
161
163
|
}
|
|
162
|
-
#terminate(cause, readLoopEnded) {
|
|
164
|
+
#terminate(cause, readLoopEnded, cleanEof = false) {
|
|
163
165
|
if (this.#disposed) return;
|
|
164
166
|
this.#disposed = true;
|
|
165
167
|
this.#terminalCause = cause;
|
|
166
168
|
this.#rejectRegistration(cause);
|
|
167
169
|
this.#startDisposal(!readLoopEnded);
|
|
168
|
-
this.#closeAllSubscribers();
|
|
170
|
+
this.#closeAllSubscribers(cleanEof ? void 0 : cause);
|
|
169
171
|
}
|
|
170
172
|
#resolveRegistration(appInfo) {
|
|
171
173
|
if (this.#registrationSettled) return;
|
|
@@ -178,9 +180,9 @@ class DeviceConnection {
|
|
|
178
180
|
this.#registrationSettled = true;
|
|
179
181
|
this.#rejectRegistered(reason);
|
|
180
182
|
}
|
|
181
|
-
#closeAllSubscribers() {
|
|
183
|
+
#closeAllSubscribers(cause) {
|
|
182
184
|
for (const [, subscriber] of this.#subscribers)try {
|
|
183
|
-
subscriber.close();
|
|
185
|
+
subscriber.close(cause);
|
|
184
186
|
} catch (err) {
|
|
185
187
|
debug("failed to close subscriber %d: %O", subscriber.id, err);
|
|
186
188
|
}
|
|
@@ -896,11 +898,12 @@ class DevtoolDaemon {
|
|
|
896
898
|
send (message) {
|
|
897
899
|
if (!closing && 1 === ws.readyState) ws.send(JSON.stringify(message));
|
|
898
900
|
},
|
|
899
|
-
close: ()=>{
|
|
901
|
+
close: (cause)=>{
|
|
900
902
|
if (closing) return;
|
|
901
903
|
closing = true;
|
|
902
904
|
this.#wsClients.delete(clientId);
|
|
903
|
-
ws.close(1001, "device disconnected");
|
|
905
|
+
if (void 0 === cause) ws.close(1001, "device disconnected");
|
|
906
|
+
else ws.close(1011, websocketCloseReason(cause));
|
|
904
907
|
}
|
|
905
908
|
};
|
|
906
909
|
session.send({
|
|
@@ -996,7 +999,8 @@ class DevtoolDaemon {
|
|
|
996
999
|
const transport = await this.#findTransportWithDeviceId(p.deviceId);
|
|
997
1000
|
await transport.openApp(p.deviceId, p.packageName, {
|
|
998
1001
|
withDataCleared: p.withDataCleared,
|
|
999
|
-
schema: p.schema
|
|
1002
|
+
schema: p.schema,
|
|
1003
|
+
restart: p.restart
|
|
1000
1004
|
});
|
|
1001
1005
|
result = null;
|
|
1002
1006
|
break;
|
|
@@ -1226,6 +1230,7 @@ class DevtoolDaemon {
|
|
|
1226
1230
|
server_debug("no clients connected, starting idle timer (%dms)", this.#idleTimeoutMs);
|
|
1227
1231
|
this.#idleTimer = setTimeout(()=>{
|
|
1228
1232
|
if (0 === this.#wsClients.size && 0 === this.#activeCommandRequests) {
|
|
1233
|
+
if (this.#transports.some((transport)=>transport.active)) return void this.#resetIdleTimer();
|
|
1229
1234
|
server_debug("idle timeout reached, shutting down daemon");
|
|
1230
1235
|
this.#onIdle?.();
|
|
1231
1236
|
}
|
|
@@ -1239,6 +1244,26 @@ class DevtoolDaemon {
|
|
|
1239
1244
|
}
|
|
1240
1245
|
}
|
|
1241
1246
|
}
|
|
1247
|
+
function websocketCloseReason(cause) {
|
|
1248
|
+
let summary;
|
|
1249
|
+
if (cause instanceof Error) {
|
|
1250
|
+
const code = cause.code;
|
|
1251
|
+
const codeText = "string" == typeof code || "number" == typeof code ? ` (${code})` : "";
|
|
1252
|
+
summary = `${cause.name}${codeText}: ${cause.message}`;
|
|
1253
|
+
} else summary = String(cause);
|
|
1254
|
+
const truncated = Buffer.byteLength(summary) > 123;
|
|
1255
|
+
const suffix = truncated ? "…" : "";
|
|
1256
|
+
const maxBytes = 123 - Buffer.byteLength(suffix);
|
|
1257
|
+
let reason = "";
|
|
1258
|
+
let byteLength = 0;
|
|
1259
|
+
for (const character of summary){
|
|
1260
|
+
const characterBytes = Buffer.byteLength(character);
|
|
1261
|
+
if (byteLength + characterBytes > maxBytes) break;
|
|
1262
|
+
reason += character;
|
|
1263
|
+
byteLength += characterBytes;
|
|
1264
|
+
}
|
|
1265
|
+
return reason + suffix;
|
|
1266
|
+
}
|
|
1242
1267
|
function createDeviceConnectionSetupTimeoutError(key) {
|
|
1243
1268
|
return new Error(`Timed out setting up device connection ${key} after ${DEVICE_CONN_SETUP_TIMEOUT_MS}ms`);
|
|
1244
1269
|
}
|
|
@@ -19,5 +19,5 @@ export declare class AndroidTransport implements Transport {
|
|
|
19
19
|
} | undefined;
|
|
20
20
|
listAvailableApps(deviceId: string): Promise<App[]>;
|
|
21
21
|
getAppIcon(deviceId: string, packageName: string): Promise<AppIcon>;
|
|
22
|
-
openApp(deviceId: string, packageName: string, { withDataCleared, schema }?: OpenAppOptions): Promise<void>;
|
|
22
|
+
openApp(deviceId: string, packageName: string, { withDataCleared, schema, restart }?: OpenAppOptions): Promise<void>;
|
|
23
23
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type App, type Connection, type Device, type Transport, type TransportConnectOptions } from "./transport.js";
|
|
2
2
|
export declare class DesktopTransport implements Transport {
|
|
3
3
|
#private;
|
|
4
|
+
constructor(takeoverHDT?: boolean);
|
|
4
5
|
connect<TInput = unknown, TOutput = unknown>(options: TransportConnectOptions): Promise<Connection<TOutput, TInput>>;
|
|
5
6
|
close(): Promise<void>;
|
|
6
7
|
listDevices(): Promise<Device[]>;
|
|
@@ -10,6 +10,8 @@ export declare function requireNumericPort(port: ClientTarget): number;
|
|
|
10
10
|
export interface OpenAppOptions {
|
|
11
11
|
signal?: AbortSignal;
|
|
12
12
|
withDataCleared?: boolean | undefined;
|
|
13
|
+
/** Stop the app before launching; Android preserves its existing default of true. */
|
|
14
|
+
restart?: boolean | undefined;
|
|
13
15
|
/** Open a deep link instead of the launcher on supported transports; ignored otherwise. */
|
|
14
16
|
schema?: string | undefined;
|
|
15
17
|
}
|
|
@@ -21,6 +23,7 @@ export interface Transport {
|
|
|
21
23
|
openApp(deviceId: string, packageName: string, options?: OpenAppOptions): Promise<void>;
|
|
22
24
|
connect<TInput = unknown, TOutput = unknown>(options: TransportConnectOptions): Promise<Connection<TOutput, TInput>>;
|
|
23
25
|
readonly persistent?: boolean;
|
|
26
|
+
readonly active?: boolean;
|
|
24
27
|
}
|
|
25
28
|
export interface Device {
|
|
26
29
|
id: string;
|