@lynx-js/devtool-connector 0.0.0 → 0.1.1

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 ADDED
@@ -0,0 +1,615 @@
1
+ import { __webpack_require__ } from "./rslib-runtime.js";
2
+ import { randomInt } from "node:crypto";
3
+ import { ReadableStream, TransformStream } from "node:stream/web";
4
+ import promises from "node:fs/promises";
5
+ import node_os from "node:os";
6
+ import node_path from "node:path";
7
+ import "./844.js";
8
+ function isInitializeResponse(response) {
9
+ return 'Register' === response.event;
10
+ }
11
+ function isListSessionResponse(response) {
12
+ return 'Customized' === response.event && 'SessionList' === response.data.type;
13
+ }
14
+ function isGetGlobalSwitchResponse(response) {
15
+ return 'Customized' === response.event && 'GetGlobalSwitch' === response.data.type;
16
+ }
17
+ function isSetGlobalSwitchResponse(response) {
18
+ return 'Customized' === response.event && 'SetGlobalSwitch' === response.data.type;
19
+ }
20
+ function isCustomizedResponseWithType(response, type) {
21
+ return 'Customized' === response.event && response.data.type === type;
22
+ }
23
+ class CustomizedRequestTransformStream extends TransformStream {
24
+ port;
25
+ constructor(options){
26
+ const { type, port, sessionId = -1, messageBuilder } = options;
27
+ super({
28
+ transform (chunk, controller) {
29
+ const sid = 'function' == typeof sessionId ? sessionId(chunk) : sessionId;
30
+ controller.enqueue({
31
+ event: 'Customized',
32
+ data: {
33
+ type,
34
+ data: {
35
+ client_id: port,
36
+ session_id: sid,
37
+ message: messageBuilder(chunk)
38
+ },
39
+ sender: port
40
+ }
41
+ });
42
+ }
43
+ });
44
+ this.port = port;
45
+ }
46
+ }
47
+ class CustomizedResponseTransformStream extends TransformStream {
48
+ constructor(type, id){
49
+ super({
50
+ transform (response, controller) {
51
+ if (!isCustomizedResponseWithType(response, type)) return;
52
+ try {
53
+ const message = JSON.parse(response.data.data.message);
54
+ if (void 0 === id || message?.id === id) controller.enqueue(message);
55
+ } catch (err) {
56
+ controller.error(new Error(`Failed to parse response for type ${type}`, {
57
+ cause: err
58
+ }));
59
+ }
60
+ }
61
+ });
62
+ }
63
+ }
64
+ class ResponseParserTransformStream extends TransformStream {
65
+ constructor(options){
66
+ const { parseResult, checkError } = options;
67
+ super({
68
+ transform (chunk, controller) {
69
+ const error = checkError(chunk);
70
+ if (error) return void controller.error(error);
71
+ try {
72
+ controller.enqueue(parseResult(chunk));
73
+ } catch (err) {
74
+ controller.error(err);
75
+ }
76
+ }
77
+ });
78
+ }
79
+ }
80
+ class AppResponseTransformStream extends ResponseParserTransformStream {
81
+ constructor(method){
82
+ super({
83
+ checkError: (message)=>{
84
+ try {
85
+ const result = JSON.parse(message.result);
86
+ if (0 !== result.code && '0' !== result.code) return new Error(`App request ${method} error: ${result.message}`, {
87
+ cause: message
88
+ });
89
+ return null;
90
+ } catch (err) {
91
+ return new Error('Failed to parse App response message', {
92
+ cause: err
93
+ });
94
+ }
95
+ },
96
+ parseResult: (message)=>JSON.parse(message.result)
97
+ });
98
+ }
99
+ }
100
+ class GlobalSwitchRequestTransformStream extends CustomizedRequestTransformStream {
101
+ constructor(type, port){
102
+ super({
103
+ type,
104
+ port,
105
+ sessionId: -1,
106
+ messageBuilder: ({ key, value })=>({
107
+ global_key: key,
108
+ global_value: value
109
+ })
110
+ });
111
+ }
112
+ }
113
+ class CDPRequestTransformStream extends CustomizedRequestTransformStream {
114
+ constructor(port, fixedId){
115
+ super({
116
+ type: 'CDP',
117
+ port,
118
+ sessionId: (chunk)=>chunk.sessionId,
119
+ messageBuilder: (chunk)=>{
120
+ const id = fixedId ?? randomInt(10000, 50000);
121
+ const { method, params } = chunk;
122
+ return {
123
+ id,
124
+ method,
125
+ params
126
+ };
127
+ }
128
+ });
129
+ }
130
+ }
131
+ class CDPResponseTransformStream extends CustomizedResponseTransformStream {
132
+ constructor(id){
133
+ super('CDP', id);
134
+ }
135
+ }
136
+ class CDPOutputTransformStream extends ResponseParserTransformStream {
137
+ constructor(){
138
+ super({
139
+ checkError: (message)=>{
140
+ if ('error' in message) return new Error(`CDP request error: ${message.error.message}`, {
141
+ cause: message
142
+ });
143
+ return null;
144
+ },
145
+ parseResult: (message)=>{
146
+ if ('result' in message) return message.result;
147
+ throw new Error('No result in CDP response message', {
148
+ cause: message
149
+ });
150
+ }
151
+ });
152
+ }
153
+ }
154
+ class PeertalkToMessageTransformStream extends TransformStream {
155
+ constructor(){
156
+ let buffer = new Uint8Array(0);
157
+ const decoder = new TextDecoder();
158
+ super({
159
+ transform: (chunk, c)=>{
160
+ const n = new Uint8Array(buffer.length + chunk.length);
161
+ n.set(buffer);
162
+ n.set(chunk, buffer.length);
163
+ buffer = n;
164
+ while(buffer.length >= 20){
165
+ const v = new DataView(buffer.buffer, buffer.byteOffset);
166
+ const len = v.getUint32(16);
167
+ if (buffer.length < 20 + len) break;
168
+ try {
169
+ c.enqueue(JSON.parse(decoder.decode(buffer.subarray(20, 20 + len))));
170
+ } catch (e) {
171
+ c.error(e);
172
+ }
173
+ buffer = buffer.subarray(20 + len);
174
+ }
175
+ }
176
+ });
177
+ }
178
+ }
179
+ class MessageToPeertalkTransformStream extends TransformStream {
180
+ constructor(){
181
+ const encoder = new TextEncoder();
182
+ super({
183
+ transform (chunk, controller) {
184
+ const body = encoder.encode(JSON.stringify(chunk));
185
+ const len = body.length;
186
+ const data = new Uint8Array(20 + len);
187
+ const view = new DataView(data.buffer);
188
+ view.setUint32(0, 1);
189
+ view.setUint32(4, 101);
190
+ view.setUint32(8, 0);
191
+ view.setUint32(12, len + 4);
192
+ view.setUint32(16, len);
193
+ data.set(body, 20);
194
+ controller.enqueue(data);
195
+ }
196
+ });
197
+ }
198
+ }
199
+ class FilterTransformStream extends TransformStream {
200
+ constructor(filter){
201
+ super({
202
+ transform (chunk, controller) {
203
+ if (filter(chunk)) controller.enqueue(chunk);
204
+ }
205
+ });
206
+ }
207
+ }
208
+ class InspectStream extends TransformStream {
209
+ constructor(callback){
210
+ super({
211
+ transform (chunk, controller) {
212
+ callback(chunk);
213
+ controller.enqueue(chunk);
214
+ }
215
+ });
216
+ }
217
+ }
218
+ const src = __webpack_require__("../../../node_modules/.pnpm/debug@4.4.3/node_modules/debug/src/index.js");
219
+ var src_default = /*#__PURE__*/ __webpack_require__.n(src);
220
+ const debug = src_default()('devtool-mcp-server:takeover');
221
+ const DEBUG_ROUTER_DIR = node_path.join(node_os.homedir(), '.DebugRouterConnector');
222
+ const DEBUG_ROUTER_LOCK_DIR = node_path.join(DEBUG_ROUTER_DIR, 'lockfile');
223
+ const DEBUG_ROUTER_LATEST_FILE = node_path.join(DEBUG_ROUTER_DIR, 'LatestDriverProcess');
224
+ async function takeoverDebugRouterLock() {
225
+ try {
226
+ await promises.mkdir(DEBUG_ROUTER_DIR, {
227
+ recursive: true
228
+ });
229
+ await promises.rm(DEBUG_ROUTER_LOCK_DIR, {
230
+ recursive: true,
231
+ force: true
232
+ });
233
+ await promises.mkdir(DEBUG_ROUTER_LOCK_DIR, {
234
+ recursive: true
235
+ });
236
+ await promises.writeFile(DEBUG_ROUTER_LATEST_FILE, `${process.pid}`, 'utf-8');
237
+ debug(`wrote PID=${process.pid}`);
238
+ } catch (err) {
239
+ debug('skipped due to filesystem error %O', err);
240
+ } finally{
241
+ try {
242
+ await promises.rm(DEBUG_ROUTER_LOCK_DIR, {
243
+ recursive: true,
244
+ force: true
245
+ });
246
+ } catch (_cleanupError) {
247
+ debug('failed to remove lock directory %O', _cleanupError);
248
+ }
249
+ }
250
+ }
251
+ function _ts_add_disposable_resource(env, value, async) {
252
+ if (null != value) {
253
+ if ("object" != typeof value && "function" != typeof value) throw new TypeError("Object expected.");
254
+ var dispose, inner;
255
+ if (async) {
256
+ if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
257
+ dispose = value[Symbol.asyncDispose];
258
+ }
259
+ if (void 0 === dispose) {
260
+ if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
261
+ dispose = value[Symbol.dispose];
262
+ if (async) inner = dispose;
263
+ }
264
+ if ("function" != typeof dispose) throw new TypeError("Object not disposable.");
265
+ if (inner) dispose = function() {
266
+ try {
267
+ inner.call(this);
268
+ } catch (e) {
269
+ return Promise.reject(e);
270
+ }
271
+ };
272
+ env.stack.push({
273
+ value: value,
274
+ dispose: dispose,
275
+ async: async
276
+ });
277
+ } else if (async) env.stack.push({
278
+ async: true
279
+ });
280
+ return value;
281
+ }
282
+ function src_ts_dispose_resources(env) {
283
+ var _SuppressedError = "function" == typeof SuppressedError ? SuppressedError : function(error, suppressed, message) {
284
+ var e = new Error(message);
285
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
286
+ };
287
+ return (src_ts_dispose_resources = function(env) {
288
+ function fail(e) {
289
+ env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
290
+ env.hasError = true;
291
+ }
292
+ var r, s = 0;
293
+ function next() {
294
+ while(r = env.stack.pop())try {
295
+ if (!r.async && 1 === s) return s = 0, env.stack.push(r), Promise.resolve().then(next);
296
+ if (r.dispose) {
297
+ var result = r.dispose.call(r.value);
298
+ if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
299
+ fail(e);
300
+ return next();
301
+ });
302
+ } else s |= 1;
303
+ } catch (e) {
304
+ fail(e);
305
+ }
306
+ if (1 === s) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
307
+ if (env.hasError) throw env.error;
308
+ }
309
+ return next();
310
+ })(env);
311
+ }
312
+ const src_debug = src_default()('devtool-mcp-server:connector');
313
+ class ClientId {
314
+ static serialize(deviceId, port) {
315
+ return `${encodeURIComponent(deviceId)}:${port}`;
316
+ }
317
+ static deserialize(clientId) {
318
+ try {
319
+ const lastColonIndex = clientId.lastIndexOf(':');
320
+ if (-1 === lastColonIndex) return null;
321
+ const port = Number.parseInt(clientId.substring(lastColonIndex + 1), 10);
322
+ if (Number.isNaN(port)) return null;
323
+ return {
324
+ deviceId: decodeURIComponent(clientId.substring(0, lastColonIndex)),
325
+ port
326
+ };
327
+ } catch {
328
+ return null;
329
+ }
330
+ }
331
+ }
332
+ class Connector {
333
+ #transports;
334
+ constructor(transports){
335
+ this.#transports = transports;
336
+ }
337
+ async listClients() {
338
+ const transportDevices = await Promise.allSettled(this.#transports.map(async (transport)=>({
339
+ transport,
340
+ devices: await transport.listDevices()
341
+ })));
342
+ const results = await Promise.allSettled(transportDevices.filter((r)=>'fulfilled' === r.status).map((r)=>r.value).flatMap(({ transport, devices })=>devices.flatMap(({ id })=>this.#listClientsForDevice(transport, id))));
343
+ return results.filter((r)=>'fulfilled' === r.status).flatMap((r)=>r.value);
344
+ }
345
+ async listDevices() {
346
+ const results = await Promise.allSettled(this.#transports.map((t)=>t.listDevices()));
347
+ return results.filter((result)=>'fulfilled' === result.status).flatMap(({ value })=>value);
348
+ }
349
+ async close() {
350
+ await Promise.allSettled(this.#transports.map((t)=>t.close()));
351
+ }
352
+ async listAvailableApps(deviceId) {
353
+ const transport = await this.#findTransportWithDeviceId(deviceId);
354
+ return await transport.listAvailableApps(deviceId);
355
+ }
356
+ async openApp(deviceId, packageName, options) {
357
+ const transport = await this.#findTransportWithDeviceId(deviceId);
358
+ await transport.openApp(deviceId, packageName, options);
359
+ const signal = AbortSignal.any([
360
+ options?.signal,
361
+ AbortSignal.timeout(60000)
362
+ ].filter((i)=>void 0 !== i));
363
+ const { setTimeout } = await import("node:timers/promises");
364
+ while(!signal.aborted){
365
+ try {
366
+ const clients = await this.#listClientsForDevice(transport, deviceId);
367
+ if (clients.some(({ info })=>info.AppProcessName === packageName || info.bundleId === packageName || info.bundleName === packageName)) break;
368
+ } catch (err) {
369
+ src_debug(`openApp ${deviceId} ${packageName} client not found %o`, err);
370
+ }
371
+ await setTimeout(1000);
372
+ }
373
+ }
374
+ async sendMessage(clientId, message) {
375
+ return await this.#sendMessage(clientId, message);
376
+ }
377
+ async sendAppMessage(clientId, method, params) {
378
+ const { port } = this.#resolveClientId(clientId);
379
+ const id = randomInt(10000, 50000);
380
+ return await this.#sendMessage(clientId, {
381
+ method,
382
+ params: {
383
+ ...params
384
+ }
385
+ }, {
386
+ input: [
387
+ new CustomizedRequestTransformStream({
388
+ type: 'App',
389
+ port,
390
+ sessionId: -1,
391
+ messageBuilder: (message)=>({
392
+ id,
393
+ ...message
394
+ })
395
+ })
396
+ ],
397
+ output: [
398
+ new CustomizedResponseTransformStream('App', id),
399
+ new AppResponseTransformStream(method)
400
+ ]
401
+ });
402
+ }
403
+ async sendCDPMessage(clientId, sessionId, method, params) {
404
+ const { port } = this.#resolveClientId(clientId);
405
+ const id = randomInt(10000, 50000);
406
+ return await this.#sendMessage(clientId, {
407
+ method,
408
+ params,
409
+ sessionId
410
+ }, {
411
+ input: [
412
+ new CDPRequestTransformStream(port, id)
413
+ ],
414
+ output: [
415
+ new CDPResponseTransformStream(id),
416
+ new CDPOutputTransformStream()
417
+ ]
418
+ });
419
+ }
420
+ async sendListSessionMessage(clientId) {
421
+ const options = this.#resolveClientId(clientId);
422
+ const { data: { data: sessions } } = await this.#sendMessage(clientId, {
423
+ event: 'Customized',
424
+ data: {
425
+ type: 'ListSession',
426
+ sender: options.port,
427
+ data: {}
428
+ }
429
+ }, {
430
+ input: [],
431
+ output: [
432
+ new FilterTransformStream(isListSessionResponse)
433
+ ]
434
+ });
435
+ return sessions;
436
+ }
437
+ async getGlobalSwitch(clientId, key) {
438
+ const options = this.#resolveClientId(clientId);
439
+ const { data: { data: { message } } } = await this.#sendMessage(clientId, {
440
+ key
441
+ }, {
442
+ input: [
443
+ new GlobalSwitchRequestTransformStream('GetGlobalSwitch', options.port)
444
+ ],
445
+ output: [
446
+ new FilterTransformStream(isGetGlobalSwitchResponse)
447
+ ]
448
+ });
449
+ if ('object' == typeof message) return message?.global_value === 'true' || message?.global_value === true;
450
+ return 'true' === message || true === message;
451
+ }
452
+ async setGlobalSwitch(clientId, key, value) {
453
+ const options = this.#resolveClientId(clientId);
454
+ await this.#sendMessage(clientId, {
455
+ key,
456
+ value
457
+ }, {
458
+ input: [
459
+ new GlobalSwitchRequestTransformStream('SetGlobalSwitch', options.port)
460
+ ],
461
+ output: [
462
+ new FilterTransformStream(isSetGlobalSwitchResponse)
463
+ ]
464
+ });
465
+ }
466
+ async sendStream(clientId, inputStream, { signal }) {
467
+ const { deviceId, port } = this.#resolveClientId(clientId);
468
+ const transport = await this.#findTransportWithDeviceId(deviceId);
469
+ return await this.#connect(transport, {
470
+ deviceId,
471
+ port,
472
+ signal
473
+ }, inputStream, {
474
+ input: [],
475
+ output: []
476
+ });
477
+ }
478
+ async sendCDPStream(clientId, inputStream, { signal } = {}) {
479
+ const { deviceId, port } = this.#resolveClientId(clientId);
480
+ const transport = await this.#findTransportWithDeviceId(deviceId);
481
+ return await this.#connect(transport, {
482
+ deviceId,
483
+ port,
484
+ signal
485
+ }, inputStream, {
486
+ input: [
487
+ new CDPRequestTransformStream(port)
488
+ ],
489
+ output: [
490
+ new CDPResponseTransformStream()
491
+ ]
492
+ });
493
+ }
494
+ #resolveClientId(clientId) {
495
+ const parsed = ClientId.deserialize(clientId);
496
+ if (!parsed) throw new Error(`Invalid clientId: ${clientId}`);
497
+ return parsed;
498
+ }
499
+ async #findTransportWithDeviceId(deviceId) {
500
+ return await Promise.any(this.#transports.map(async (t)=>{
501
+ const devices = await t.listDevices();
502
+ if (devices.some(({ id })=>id === deviceId)) return t;
503
+ throw new Error('Not found in this transport');
504
+ })).catch(()=>{
505
+ throw new Error(`Device with id: ${deviceId} not found`);
506
+ });
507
+ }
508
+ async #connect(transport, options, inputStream, pipeline) {
509
+ const { deviceId, port } = options;
510
+ await takeoverDebugRouterLock();
511
+ const conn = await transport.connect(options);
512
+ [
513
+ ...pipeline.input,
514
+ new InspectStream((msg)=>src_debug(`connect ${deviceId}:${port} input stream send %O`, msg)),
515
+ new MessageToPeertalkTransformStream()
516
+ ].reduce((stream, transform)=>stream.pipeThrough(transform), inputStream).pipeTo(conn.writable, {
517
+ preventClose: true
518
+ }).catch((err)=>{
519
+ src_debug(`connect ${deviceId}:${port} input stream err %O`, err);
520
+ conn[Symbol.asyncDispose]();
521
+ });
522
+ const outputStream = [
523
+ new PeertalkToMessageTransformStream(),
524
+ new InspectStream((msg)=>src_debug(`connect ${deviceId}:${port} output stream receive %O`, msg)),
525
+ ...pipeline.output
526
+ ].reduce((stream, transform)=>stream.pipeThrough(transform), conn.readable);
527
+ return Object.assign(outputStream, {
528
+ async [Symbol.asyncDispose] () {
529
+ src_debug(`connect ${deviceId}:${port} close connection`);
530
+ return await conn[Symbol.asyncDispose]();
531
+ }
532
+ });
533
+ }
534
+ async #sendMessage(clientId, input, pipeline = {
535
+ input: [],
536
+ output: []
537
+ }) {
538
+ const { deviceId, port } = this.#resolveClientId(clientId);
539
+ const transport = await this.#findTransportWithDeviceId(deviceId);
540
+ const signal = AbortSignal.timeout(5000);
541
+ return this.#sendMessageWithTransport(transport, {
542
+ deviceId,
543
+ port,
544
+ signal
545
+ }, input, pipeline);
546
+ }
547
+ async #sendMessageWithTransport(transport, options, input, pipeline) {
548
+ const env = {
549
+ stack: [],
550
+ error: void 0,
551
+ hasError: false
552
+ };
553
+ try {
554
+ const outputStream = _ts_add_disposable_resource(env, await this.#connect(transport, options, ReadableStream.from([
555
+ input
556
+ ]), pipeline), true);
557
+ for await (const response of outputStream)return response;
558
+ const { deviceId, port } = options;
559
+ throw new Error(`No response found for deviceId: ${deviceId} port: ${port}`);
560
+ } catch (e) {
561
+ env.error = e;
562
+ env.hasError = true;
563
+ } finally{
564
+ const result = src_ts_dispose_resources(env);
565
+ if (result) await result;
566
+ }
567
+ }
568
+ async #listClientsForDevice(transport, deviceId) {
569
+ const MIN_PORT = 8901;
570
+ const PORTS = Array.from({
571
+ length: 10
572
+ }, (_, i)=>MIN_PORT + i);
573
+ const results = await Promise.allSettled(PORTS.map(async (port)=>{
574
+ const { data: { info } } = await this.#sendMessageWithTransport(transport, {
575
+ deviceId,
576
+ port,
577
+ signal: AbortSignal.timeout(5000)
578
+ }, {
579
+ event: 'Initialize',
580
+ data: port
581
+ }, {
582
+ input: [],
583
+ output: [
584
+ new FilterTransformStream(isInitializeResponse)
585
+ ]
586
+ });
587
+ try {
588
+ await this.#sendMessageWithTransport(transport, {
589
+ deviceId,
590
+ port,
591
+ signal: AbortSignal.timeout(3000)
592
+ }, {
593
+ key: 'enable_devtool',
594
+ value: true
595
+ }, {
596
+ input: [
597
+ new GlobalSwitchRequestTransformStream('SetGlobalSwitch', port)
598
+ ],
599
+ output: [
600
+ new FilterTransformStream(isSetGlobalSwitchResponse)
601
+ ]
602
+ });
603
+ } catch (err) {
604
+ src_debug(`listClientsForDevice ${deviceId}:${port} enable_devtool failed %O`, err);
605
+ }
606
+ return {
607
+ id: ClientId.serialize(deviceId, port),
608
+ info,
609
+ port
610
+ };
611
+ }));
612
+ return results.filter((result)=>'fulfilled' === result.status).map((result)=>result.value);
613
+ }
614
+ }
615
+ export { ClientId, Connector, MessageToPeertalkTransformStream, PeertalkToMessageTransformStream };
@@ -0,0 +1,38 @@
1
+ var __webpack_modules__ = {};
2
+ var __webpack_module_cache__ = {};
3
+ function __webpack_require__(moduleId) {
4
+ var cachedModule = __webpack_module_cache__[moduleId];
5
+ if (void 0 !== cachedModule) return cachedModule.exports;
6
+ var module = __webpack_module_cache__[moduleId] = {
7
+ exports: {}
8
+ };
9
+ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
10
+ return module.exports;
11
+ }
12
+ __webpack_require__.m = __webpack_modules__;
13
+ (()=>{
14
+ __webpack_require__.add = function(modules) {
15
+ Object.assign(__webpack_require__.m, modules);
16
+ };
17
+ })();
18
+ (()=>{
19
+ __webpack_require__.n = (module)=>{
20
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
21
+ __webpack_require__.d(getter, {
22
+ a: getter
23
+ });
24
+ return getter;
25
+ };
26
+ })();
27
+ (()=>{
28
+ __webpack_require__.d = (exports, definition)=>{
29
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
30
+ enumerable: true,
31
+ get: definition[key]
32
+ });
33
+ };
34
+ })();
35
+ (()=>{
36
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
37
+ })();
38
+ export { __webpack_require__ };
@@ -0,0 +1,13 @@
1
+ import type { CDPRequestMessage, CDPResponseMessage } from '../types.ts';
2
+ import { CustomizedRequestTransformStream, CustomizedResponseTransformStream, ResponseParserTransformStream } from './customized.ts';
3
+ export declare class CDPRequestTransformStream extends CustomizedRequestTransformStream<CDPRequestMessage & {
4
+ sessionId: number;
5
+ }> {
6
+ constructor(port: number, fixedId?: number);
7
+ }
8
+ export declare class CDPResponseTransformStream<Output = CDPResponseMessage> extends CustomizedResponseTransformStream<'CDP', Output> {
9
+ constructor(id?: number);
10
+ }
11
+ export declare class CDPOutputTransformStream<Output> extends ResponseParserTransformStream<CDPResponseMessage, Output> {
12
+ constructor();
13
+ }
@@ -0,0 +1,32 @@
1
+ import { TransformStream } from 'node:stream/web';
2
+ import type { AppResponseMessage, CustomizedResponseMap, CustomizedResponseMessageMap, Response } from '../types.ts';
3
+ export declare class CustomizedRequestTransformStream<T = unknown> extends TransformStream<T, unknown> {
4
+ protected port: number;
5
+ constructor(options: {
6
+ type: string;
7
+ port: number;
8
+ sessionId?: number | ((chunk: T) => number);
9
+ messageBuilder: (chunk: T) => unknown;
10
+ });
11
+ }
12
+ export declare class CustomizedResponseTransformStream<T extends keyof CustomizedResponseMap, Output = CustomizedResponseMessageMap[T]> extends TransformStream<Response, Output> {
13
+ constructor(type: T, id?: number);
14
+ }
15
+ /**
16
+ * Common response parser that handles JSON parsing and error checking in the payload.
17
+ */
18
+ export declare class ResponseParserTransformStream<Input, Output> extends TransformStream<Input, Output> {
19
+ constructor(options: {
20
+ parseResult: (input: Input) => Output;
21
+ checkError: (input: Input) => Error | null;
22
+ });
23
+ }
24
+ export declare class AppResponseTransformStream<Output> extends ResponseParserTransformStream<AppResponseMessage, Output> {
25
+ constructor(method: string);
26
+ }
27
+ export declare class GlobalSwitchRequestTransformStream extends CustomizedRequestTransformStream<{
28
+ key: string;
29
+ value?: boolean;
30
+ }> {
31
+ constructor(type: 'SetGlobalSwitch' | 'GetGlobalSwitch', port: number);
32
+ }