@qontinui/ui-bridge-wrapper 0.14.0 → 0.15.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"frame-capture.d.ts","sourceRoot":"","sources":["../src/frame-capture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAMH,qDAAqD;AACrD,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,OAAO,CAAC;AAEhD,iEAAiE;AACjE,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,QAAQ,EAAE,OAAO,CAAC;IAClB,4EAA4E;IAC5E,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;;OAKG;IACH,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,WAAW;IAC1B,wCAAwC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,KAAK,CAAC;IACd,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB,8EAA8E;IAC9E,WAAW,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/C,oDAAoD;IACpD,WAAW,EAAE,gBAAgB,CAAC;IAC9B,yDAAyD;IACzD,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,cAAc,CAAC;CAC1B;AAED,mFAAmF;AACnF,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,sBAAsB,GAAG,sBAAsB,CAAC;IACtD,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,yDAAyD;AACzD,MAAM,WAAW,WAAW;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,WA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M,OAAO,CAAC,OAAO,CAAC,CAAC;IACrC;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kCAAkC;IAClC,GAAG,CAAC,EAAE,MAAM,IAAI,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,eAAe,CAAC,CA4GhG"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * The page-side frame helpers: what a capture reads off a Playwright-like page
3
+ * and off the PNG it returns. NODE-FREE by contract — no Node builtin, no
4
+ * `Buffer`, no `process` — because the browser-safe `./live` entry imports it
5
+ * (through `screenshot-capture.ts`). `frame-capture.ts` re-exports all of it.
6
+ */
7
+ /** The `prefers-color-scheme` a page rendered in. */
8
+ export type FrameColorScheme = 'dark' | 'light';
9
+ /** What the page says about how it is being rendered. */
10
+ export interface PageMetrics {
11
+ devicePixelRatio: number;
12
+ innerWidth: number;
13
+ innerHeight: number;
14
+ colorScheme: FrameColorScheme;
15
+ }
16
+ /** The slice of a Playwright `Page` frame capture needs. */
17
+ export interface FramePage {
18
+ evaluate<R>(fn: () => R | Promise<R>): Promise<R>;
19
+ screenshot(options: {
20
+ type: 'png';
21
+ scale: 'device';
22
+ fullPage: false;
23
+ }): Promise<Uint8Array>;
24
+ }
25
+ /**
26
+ * Width and height from a PNG's IHDR chunk. Throws on anything that is not a
27
+ * PNG with an IHDR first — a frame whose size cannot be read cannot be mapped.
28
+ */
29
+ export declare function pngDimensions(buf: Uint8Array): {
30
+ width: number;
31
+ height: number;
32
+ };
33
+ /** Read the page's own rendering metrics — never the flags that requested them. */
34
+ export declare function readPageMetrics(page: Pick<FramePage, 'evaluate'>): Promise<PageMetrics>;
35
+ //# sourceMappingURL=frame-page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frame-page.d.ts","sourceRoot":"","sources":["../src/frame-page.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,qDAAqD;AACrD,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,OAAO,CAAC;AAEhD,yDAAyD;AACzD,MAAM,WAAW,WAAW;IAC1B,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,gBAAgB,CAAC;CAC/B;AAED,4DAA4D;AAC5D,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAClD,UAAU,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,KAAK,CAAC;QAAC,KAAK,EAAE,QAAQ,CAAC;QAAC,QAAQ,EAAE,KAAK,CAAA;KAAE,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CAC7F;AAID;;;GAGG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAUhF;AAED,mFAAmF;AACnF,wBAAsB,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAS7F"}
package/dist/index.cjs CHANGED
@@ -1,171 +1,14 @@
1
1
  'use strict';
2
2
 
3
+ var chunkZ32CC665_cjs = require('./chunk-Z32CC665.cjs');
3
4
  var module$1 = require('module');
4
5
  var fs = require('fs');
5
6
  var crypto = require('crypto');
7
+ require('path');
6
8
 
7
9
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
8
- // src/types.ts
9
- var WrapperTransportError = class extends Error {
10
- code;
11
- retryable;
12
- cause;
13
- /**
14
- * Optional structured diagnostic payload (error-code-specific shape) so
15
- * programmatic callers can branch on data instead of parsing the message —
16
- * e.g. `INJECTED_EXPECT_SELECTOR_UNMET` attaches
17
- * `{ registeredElements, elementCount }`.
18
- */
19
- details;
20
- constructor(code, message, options = {}) {
21
- super(message);
22
- this.name = "WrapperTransportError";
23
- this.code = code;
24
- this.retryable = options.retryable ?? false;
25
- if (options.cause !== void 0) {
26
- this.cause = options.cause;
27
- }
28
- if (options.details !== void 0) {
29
- this.details = options.details;
30
- }
31
- }
32
- };
33
-
34
- // src/handler-registry.ts
35
- var HandlerRegistry = class {
36
- handlers = /* @__PURE__ */ new Map();
37
- /**
38
- * Register (or replace) a handler for `actionId`. Replacement is explicit
39
- * rather than throwing because live reloading / hot module scenarios need
40
- * to update handlers without tearing the whole transport down.
41
- */
42
- register(actionId, fn) {
43
- this.handlers.set(actionId, fn);
44
- }
45
- /** Remove a handler. Returns `true` if a handler was removed. */
46
- unregister(actionId) {
47
- return this.handlers.delete(actionId);
48
- }
49
- /** All registered action ids. Stable iteration order (insertion order). */
50
- list() {
51
- return Array.from(this.handlers.keys());
52
- }
53
- /** Check whether a handler is registered for `actionId`. */
54
- has(actionId) {
55
- return this.handlers.has(actionId);
56
- }
57
- /**
58
- * Invoke the handler registered under `actionId`.
59
- *
60
- * Throws `WrapperTransportError("NO_HANDLER")` if no handler is registered.
61
- * Propagates handler errors wrapped as `WrapperTransportError("HANDLER_ERROR")`
62
- * so callers can uniformly check `err.code`.
63
- */
64
- async dispatch(actionId, params, ctx) {
65
- const handler = this.handlers.get(actionId);
66
- if (!handler) {
67
- throw new WrapperTransportError(
68
- "NO_HANDLER",
69
- `No handler registered for action '${actionId}'`
70
- );
71
- }
72
- try {
73
- const result = await handler(params, ctx);
74
- return result;
75
- } catch (err) {
76
- if (err instanceof WrapperTransportError) throw err;
77
- const message = err instanceof Error ? err.message : String(err);
78
- throw new WrapperTransportError("HANDLER_ERROR", message, { cause: err });
79
- }
80
- }
81
- };
82
-
83
- // src/base-transport.ts
84
- var BaseTransport = class {
85
- _status = "idle";
86
- listeners = /* @__PURE__ */ new Set();
87
- registry;
88
- readyPromise = null;
89
- constructor(registry) {
90
- this.registry = registry ?? new HandlerRegistry();
91
- }
92
- get status() {
93
- return this._status;
94
- }
95
- /** Expose the underlying registry so wrappers can register handlers. */
96
- get handlerRegistry() {
97
- return this.registry;
98
- }
99
- /** Convenience: register a handler on the transport's registry. */
100
- register(actionId, fn) {
101
- this.registry.register(actionId, fn);
102
- }
103
- /**
104
- * Idempotent async setup. First call runs `onReady()`; subsequent calls
105
- * share the same promise until it settles, after which further calls
106
- * are no-ops if `status === 'ready'`, or re-run setup if it errored.
107
- */
108
- async ready() {
109
- if (this._status === "ready") return;
110
- if (this._status === "closed") {
111
- throw new WrapperTransportError("TRANSPORT_CLOSED", `Transport '${this.kind}' is closed`);
112
- }
113
- if (this.readyPromise) return this.readyPromise;
114
- this.setStatus("connecting");
115
- this.readyPromise = this.onReady().then(() => {
116
- this.setStatus("ready");
117
- }).catch((err) => {
118
- this.setStatus("error");
119
- this.readyPromise = null;
120
- throw err;
121
- });
122
- return this.readyPromise;
123
- }
124
- /** Default dispatch — waits for ready, builds ctx, delegates to registry. */
125
- async dispatch(actionId, params) {
126
- await this.ready();
127
- const ctx = await this.buildContext(actionId, params);
128
- return this.registry.dispatch(actionId, params, ctx);
129
- }
130
- async close() {
131
- if (this._status === "closed") return;
132
- try {
133
- await this.onClose();
134
- } finally {
135
- this.setStatus("closed");
136
- this.listeners.clear();
137
- this.readyPromise = null;
138
- }
139
- }
140
- onStatusChange(listener) {
141
- this.listeners.add(listener);
142
- return () => {
143
- this.listeners.delete(listener);
144
- };
145
- }
146
- /** Update status and notify listeners. Safe to call from subclasses. */
147
- setStatus(next) {
148
- if (this._status === next) return;
149
- this._status = next;
150
- for (const l of this.listeners) {
151
- try {
152
- l(next);
153
- } catch {
154
- }
155
- }
156
- }
157
- /**
158
- * Subclass hook: build the context object passed to handlers. Default is
159
- * `undefined` (api transport). Headless/headed override to provide the
160
- * Playwright `page`; live overrides to provide a response helper.
161
- */
162
- async buildContext(_actionId, _params) {
163
- return void 0;
164
- }
165
- };
166
-
167
10
  // src/transports/api.ts
168
- var ApiTransport = class extends BaseTransport {
11
+ var ApiTransport = class extends chunkZ32CC665_cjs.BaseTransport {
169
12
  kind = "api";
170
13
  fallback;
171
14
  constructor(config = { kind: "api" }, registry) {
@@ -196,17 +39,17 @@ var ApiTransport = class extends BaseTransport {
196
39
  try {
197
40
  return await this.fallback(actionId, params);
198
41
  } catch (err) {
199
- if (err instanceof WrapperTransportError) throw err;
42
+ if (err instanceof chunkZ32CC665_cjs.WrapperTransportError) throw err;
200
43
  const message = err instanceof Error ? err.message : String(err);
201
- throw new WrapperTransportError("HANDLER_ERROR", message, { cause: err });
44
+ throw new chunkZ32CC665_cjs.WrapperTransportError("HANDLER_ERROR", message, { cause: err });
202
45
  }
203
46
  }
204
- throw new WrapperTransportError("NO_HANDLER", `No handler registered for action '${actionId}'`);
47
+ throw new chunkZ32CC665_cjs.WrapperTransportError("NO_HANDLER", `No handler registered for action '${actionId}'`);
205
48
  }
206
49
  };
207
50
 
208
51
  // src/transports/headless.ts
209
- var HeadlessTransport = class extends BaseTransport {
52
+ var HeadlessTransport = class extends chunkZ32CC665_cjs.BaseTransport {
210
53
  kind;
211
54
  options;
212
55
  headless;
@@ -221,7 +64,7 @@ var HeadlessTransport = class extends BaseTransport {
221
64
  const raw = config.options ?? {};
222
65
  const targetUrl = raw["targetUrl"];
223
66
  if (typeof targetUrl !== "string" || targetUrl.length === 0) {
224
- throw new WrapperTransportError(
67
+ throw new chunkZ32CC665_cjs.WrapperTransportError(
225
68
  "INVALID_CONFIG",
226
69
  `Transport kind '${this.kind}' requires options.targetUrl (string)`
227
70
  );
@@ -250,7 +93,7 @@ var HeadlessTransport = class extends BaseTransport {
250
93
  */
251
94
  parseContextOptions(raw) {
252
95
  const out = {};
253
- const invalid = (what) => new WrapperTransportError("INVALID_CONFIG", `Transport kind '${this.kind}': ${what}`);
96
+ const invalid = (what) => new chunkZ32CC665_cjs.WrapperTransportError("INVALID_CONFIG", `Transport kind '${this.kind}': ${what}`);
254
97
  const har = raw["recordHar"];
255
98
  if (har !== void 0) {
256
99
  if (typeof har !== "object" || har === null || typeof har.path !== "string" || har.path.length === 0) {
@@ -301,7 +144,7 @@ var HeadlessTransport = class extends BaseTransport {
301
144
  const cause = err instanceof Error ? err.message : String(err);
302
145
  const code = err?.code;
303
146
  if (code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND") {
304
- throw new WrapperTransportError(
147
+ throw new chunkZ32CC665_cjs.WrapperTransportError(
305
148
  "INVALID_CONFIG",
306
149
  `Transport kind '${this.kind}' needs the optional '@qontinui/ui-bridge-headless' peer, which is not installed. Install it and the Chromium browser:
307
150
  npm i @qontinui/ui-bridge-headless && npx playwright install chromium
@@ -310,7 +153,7 @@ var HeadlessTransport = class extends BaseTransport {
310
153
  Underlying import error: ${cause}`
311
154
  );
312
155
  }
313
- throw new WrapperTransportError(
156
+ throw new chunkZ32CC665_cjs.WrapperTransportError(
314
157
  "INVALID_CONFIG",
315
158
  `'@qontinui/ui-bridge-headless' is installed but failed to load \u2014 this is a broken install (missing transitive dependency or version skew), not a missing peer. Try reinstalling it. Underlying error: ${cause}`
316
159
  );
@@ -352,7 +195,7 @@ Underlying import error: ${cause}`
352
195
  } catch (err) {
353
196
  const cause = err instanceof Error ? err.message : String(err);
354
197
  if (/Executable doesn't exist|browserType\.launch/i.test(cause)) {
355
- throw new WrapperTransportError(
198
+ throw new chunkZ32CC665_cjs.WrapperTransportError(
356
199
  "INVALID_CONFIG",
357
200
  `Playwright's Chromium browser is not installed (the '@qontinui/ui-bridge-headless' peer itself loaded fine). Run:
358
201
  npx playwright install chromium
@@ -372,7 +215,7 @@ Underlying launch error: ${cause}`
372
215
  if (contextOptionsRequested && !routerCalled) {
373
216
  await this.onClose().catch(() => {
374
217
  });
375
- throw new WrapperTransportError(
218
+ throw new chunkZ32CC665_cjs.WrapperTransportError(
376
219
  "CONTEXT_OPTIONS_NOT_APPLIED",
377
220
  `The installed '@qontinui/ui-bridge-headless' peer launched the tab without calling initRouter, so it predates the recordHar / recordVideo / serviceWorkers / initRouter passthrough (0.8.0, ui-bridge#381) and ignored them: no HAR or video would be written and no route installed. Upgrade it to 0.8.0 or later.`,
378
221
  {
@@ -414,7 +257,7 @@ Underlying launch error: ${cause}`
414
257
  if (problems.length === 0) return;
415
258
  await this.onClose().catch(() => {
416
259
  });
417
- throw new WrapperTransportError(
260
+ throw new chunkZ32CC665_cjs.WrapperTransportError(
418
261
  "EMULATION_NOT_APPLIED",
419
262
  `The launched page reports ${problems.join(" and ")}. The installed '@qontinui/ui-bridge-headless' peer most likely predates deviceScaleFactor/colorScheme support (added after 0.5.0) and ignored them; upgrade it. A page measured at an emulation it is not actually rendering at would be stamped with the wrong values.`,
420
263
  { details: { requested: { deviceScaleFactor: wantDpr, colorScheme: wantScheme }, seen } }
@@ -458,7 +301,7 @@ Underlying launch error: ${cause}`
458
301
  }
459
302
  async buildContext() {
460
303
  if (!this.tab) {
461
- throw new WrapperTransportError(
304
+ throw new chunkZ32CC665_cjs.WrapperTransportError(
462
305
  "NOT_READY",
463
306
  `Transport '${this.kind}' is not ready; call ready() before dispatch`
464
307
  );
@@ -496,7 +339,7 @@ function loadInjectedBundle() {
496
339
  try {
497
340
  cachedBundle = fs.readFileSync(bundlePath, "utf8");
498
341
  } catch (cause) {
499
- throw new WrapperTransportError(
342
+ throw new chunkZ32CC665_cjs.WrapperTransportError(
500
343
  "INJECTED_BUNDLE_MISSING",
501
344
  `Could not read the UI Bridge injected runtime bundle at '${bundlePath}'. Ensure @qontinui/ui-bridge is built (the IIFE is emitted by its tsup build).`,
502
345
  { cause }
@@ -591,7 +434,7 @@ var InjectedTransport = class extends HeadlessTransport {
591
434
  { timeout: this.injected.readyTimeoutMs }
592
435
  );
593
436
  } catch (cause) {
594
- throw new WrapperTransportError(
437
+ throw new chunkZ32CC665_cjs.WrapperTransportError(
595
438
  "INJECTED_RUNTIME_NOT_READY",
596
439
  `The injected UI Bridge runtime did not report ready within ${this.injected.readyTimeoutMs}ms. The bundle may have failed to evaluate (check page console / CSP) or the page never reached DOMContentLoaded.`,
597
440
  { cause, retryable: true }
@@ -615,7 +458,7 @@ var InjectedTransport = class extends HeadlessTransport {
615
458
  };
616
459
  });
617
460
  } catch (cause) {
618
- throw new WrapperTransportError(
461
+ throw new chunkZ32CC665_cjs.WrapperTransportError(
619
462
  "INJECTED_RUNTIME_NOT_SETTLED",
620
463
  `The injected UI Bridge runtime did not report settled within ${this.injected.readyTimeoutMs}ms. The page kept mutating past its settle cap, or the realm was torn down. Pass options.waitForSettle=false to gate on ready only, or raise options.settleTimeoutMs / readyTimeoutMs.`,
621
464
  { cause, retryable: true }
@@ -626,12 +469,12 @@ var InjectedTransport = class extends HeadlessTransport {
626
469
  const baseMessage = sel ? `The injected runtime settled at its cap without the expected control (selector '${sel}') appearing \u2014 ${state.elementCount} element(s) were registered, but none matched. The control may mount slower than the settle cap (raise options.settleTimeoutMs), the selector may be wrong, or the inject failed. Treat as BLOCKED/UNVERIFIED, not a clean page.` : `The injected runtime settled at its cap with an empty registry (0 elements). The page never rendered interactive content within the settle cap, or the inject failed. Raise options.settleTimeoutMs for a slow page; otherwise treat as BLOCKED/UNVERIFIED.`;
627
470
  const digest = await this.registeredElementDigest(page);
628
471
  if (digest === null) {
629
- throw new WrapperTransportError("INJECTED_EXPECT_SELECTOR_UNMET", baseMessage, {
472
+ throw new chunkZ32CC665_cjs.WrapperTransportError("INJECTED_EXPECT_SELECTOR_UNMET", baseMessage, {
630
473
  retryable: true
631
474
  });
632
475
  }
633
476
  const summary = digest.length > 0 ? ` Registered: ${digest.map((el) => el.role ? `${el.id} (${el.role})` : el.id).join(", ")}${state.elementCount > digest.length ? ", \u2026" : ""}` : "";
634
- throw new WrapperTransportError(
477
+ throw new chunkZ32CC665_cjs.WrapperTransportError(
635
478
  "INJECTED_EXPECT_SELECTOR_UNMET",
636
479
  `${baseMessage}${summary}`,
637
480
  {
@@ -688,7 +531,7 @@ var InjectedTransport = class extends HeadlessTransport {
688
531
  }
689
532
  async buildContext() {
690
533
  if (!this.tab) {
691
- throw new WrapperTransportError(
534
+ throw new chunkZ32CC665_cjs.WrapperTransportError(
692
535
  "NOT_READY",
693
536
  `Transport 'injected' is not ready; call ready() before dispatch`
694
537
  );
@@ -745,192 +588,6 @@ function isRegistrationMetadata(value) {
745
588
  return typeof v.userId === "string" && typeof v.sessionId === "string";
746
589
  }
747
590
 
748
- // src/transports/live.ts
749
- var LiveSessionTransport = class extends BaseTransport {
750
- kind = "live";
751
- url;
752
- appId;
753
- appName;
754
- opts;
755
- wsCtor;
756
- ws = null;
757
- ackResolvers = null;
758
- constructor(config, registry, injected) {
759
- super(registry);
760
- if (!config.runnerUrl) {
761
- throw new WrapperTransportError("INVALID_CONFIG", `Transport kind 'live' requires runnerUrl`);
762
- }
763
- this.url = config.runnerUrl;
764
- this.appId = config.appId;
765
- this.appName = config.appName;
766
- this.opts = config.options ?? {};
767
- const fromInjection = injected?.webSocketCtor;
768
- const fromGlobal = typeof globalThis.WebSocket === "function" ? globalThis.WebSocket : void 0;
769
- const resolved = fromInjection ?? fromGlobal;
770
- if (!resolved) {
771
- throw new WrapperTransportError(
772
- "NO_WEBSOCKET",
773
- `No WebSocket constructor available. Provide one via the second constructor arg or run in an environment with global WebSocket.`
774
- );
775
- }
776
- this.wsCtor = resolved;
777
- }
778
- async onReady() {
779
- const ws = new this.wsCtor(this.url);
780
- this.ws = ws;
781
- ws.addEventListener("message", (ev) => this.handleMessage(ev.data));
782
- ws.addEventListener("close", () => this.handleClose());
783
- ws.addEventListener("error", (ev) => this.handleError(ev));
784
- await new Promise((resolve, reject) => {
785
- const onOpen = () => {
786
- try {
787
- const frame = {
788
- type: "register",
789
- transport: "websocket",
790
- appId: this.appId,
791
- appName: this.appName,
792
- appType: this.opts.appType ?? "wrapper"
793
- };
794
- if (this.opts.framework !== void 0) frame.framework = this.opts.framework;
795
- if (this.opts.version !== void 0) frame.version = this.opts.version;
796
- if (this.opts.capabilities !== void 0) frame.capabilities = this.opts.capabilities;
797
- if (this.opts.origin !== void 0) frame.origin = this.opts.origin;
798
- if (this.opts.pageUrl !== void 0) frame.pageUrl = this.opts.pageUrl;
799
- ws.send(JSON.stringify(frame));
800
- } catch (err) {
801
- reject(err instanceof Error ? err : new Error(String(err)));
802
- return;
803
- }
804
- const timeoutMs = this.opts.handshakeTimeoutMs ?? 1e4;
805
- const timer = setTimeout(() => {
806
- this.ackResolvers = null;
807
- reject(
808
- new WrapperTransportError(
809
- "HANDSHAKE_TIMEOUT",
810
- `Did not receive register ack within ${timeoutMs}ms`
811
- )
812
- );
813
- }, timeoutMs);
814
- this.ackResolvers = { resolve, reject, timer };
815
- };
816
- ws.addEventListener("open", onOpen);
817
- });
818
- }
819
- async onClose() {
820
- const ws = this.ws;
821
- this.ws = null;
822
- if (this.ackResolvers) {
823
- clearTimeout(this.ackResolvers.timer);
824
- this.ackResolvers.reject(
825
- new WrapperTransportError("TRANSPORT_CLOSED", "Transport closed during handshake")
826
- );
827
- this.ackResolvers = null;
828
- }
829
- if (ws) {
830
- try {
831
- ws.close();
832
- } catch {
833
- }
834
- }
835
- }
836
- async buildContext() {
837
- return { kind: "live", commandId: null };
838
- }
839
- handleMessage(data) {
840
- let frame;
841
- try {
842
- const text = typeof data === "string" ? data : String(data);
843
- frame = JSON.parse(text);
844
- } catch {
845
- return;
846
- }
847
- switch (frame.type) {
848
- case "ack":
849
- case "registered": {
850
- const f = frame;
851
- if (!this.ackResolvers) return;
852
- clearTimeout(this.ackResolvers.timer);
853
- if (f.ok === false) {
854
- const err = new WrapperTransportError(
855
- f.error?.code ?? "REGISTER_FAILED",
856
- f.error?.message ?? "Runner refused registration"
857
- );
858
- this.ackResolvers.reject(err);
859
- } else {
860
- this.ackResolvers.resolve();
861
- }
862
- this.ackResolvers = null;
863
- return;
864
- }
865
- case "command": {
866
- const f = frame;
867
- void this.handleCommand(f);
868
- return;
869
- }
870
- default:
871
- return;
872
- }
873
- }
874
- async handleCommand(frame) {
875
- const ctx = { kind: "live", commandId: frame.commandId };
876
- let response;
877
- try {
878
- const result = await this.registry.dispatch(frame.action, frame.payload, ctx);
879
- response = {
880
- type: "response",
881
- commandId: frame.commandId,
882
- success: true,
883
- result
884
- };
885
- } catch (err) {
886
- const code = err instanceof WrapperTransportError ? err.code : "HANDLER_ERROR";
887
- const retryable = err instanceof WrapperTransportError ? err.retryable : false;
888
- const message = err instanceof Error ? err.message : String(err);
889
- response = {
890
- type: "response",
891
- commandId: frame.commandId,
892
- success: false,
893
- error: { code, message, retryable }
894
- };
895
- }
896
- try {
897
- this.ws?.send(JSON.stringify(response));
898
- } catch {
899
- }
900
- }
901
- handleClose() {
902
- if (this._status === "closed") return;
903
- this.setStatus("closed");
904
- if (this.ackResolvers) {
905
- clearTimeout(this.ackResolvers.timer);
906
- this.ackResolvers.reject(
907
- new WrapperTransportError("DISCONNECTED", "WebSocket closed before ack")
908
- );
909
- this.ackResolvers = null;
910
- }
911
- }
912
- handleError(ev) {
913
- if (this.ackResolvers) {
914
- clearTimeout(this.ackResolvers.timer);
915
- const message = this.extractErrorMessage(ev);
916
- this.ackResolvers.reject(
917
- new WrapperTransportError("WEBSOCKET_ERROR", message, { retryable: true })
918
- );
919
- this.ackResolvers = null;
920
- } else {
921
- this.setStatus("error");
922
- }
923
- }
924
- extractErrorMessage(ev) {
925
- if (ev && typeof ev === "object" && "message" in ev) {
926
- const m = ev.message;
927
- if (typeof m === "string") return m;
928
- }
929
- if (ev instanceof Error) return ev.message;
930
- return "WebSocket error";
931
- }
932
- };
933
-
934
591
  // src/create-transport.ts
935
592
  function createTransport(config) {
936
593
  switch (config.kind) {
@@ -945,19 +602,19 @@ function createTransport(config) {
945
602
  case "live": {
946
603
  const opts = config.options ?? {};
947
604
  const injected = typeof opts.webSocketCtor === "function" ? { webSocketCtor: opts.webSocketCtor } : void 0;
948
- return new LiveSessionTransport(config, void 0, injected);
605
+ return new chunkZ32CC665_cjs.LiveSessionTransport(config, void 0, injected);
949
606
  }
950
607
  default: {
951
608
  const kind = config.kind ?? "<missing>";
952
- throw new WrapperTransportError("UNKNOWN_TRANSPORT", `Unknown transport kind '${kind}'`);
609
+ throw new chunkZ32CC665_cjs.WrapperTransportError("UNKNOWN_TRANSPORT", `Unknown transport kind '${kind}'`);
953
610
  }
954
611
  }
955
612
  }
956
613
 
957
614
  // src/helpers/retry.ts
958
- var defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
615
+ var defaultSleep = (ms) => new Promise((resolve2) => setTimeout(resolve2, ms));
959
616
  var defaultShouldRetry = (err) => {
960
- if (err instanceof WrapperTransportError) {
617
+ if (err instanceof chunkZ32CC665_cjs.WrapperTransportError) {
961
618
  return err.retryable;
962
619
  }
963
620
  return true;
@@ -986,7 +643,7 @@ async function withRetry(fn, opts = {}) {
986
643
 
987
644
  // src/helpers/auth.ts
988
645
  var defaultIsAuthError = (err) => {
989
- if (err instanceof WrapperTransportError) {
646
+ if (err instanceof chunkZ32CC665_cjs.WrapperTransportError) {
990
647
  return /^(AUTH|UNAUTH|401)/i.test(err.code);
991
648
  }
992
649
  const status = err?.status;
@@ -1171,23 +828,55 @@ async function startDispatchServer(transport, port, logName) {
1171
828
  res.writeHead(404, { "Content-Type": "application/json" });
1172
829
  res.end(JSON.stringify({ success: false, error: "not found" }));
1173
830
  });
1174
- await new Promise((resolve, reject) => {
831
+ await new Promise((resolve2, reject) => {
1175
832
  server.once("error", reject);
1176
833
  server.listen(port, "127.0.0.1", () => {
1177
834
  server.removeListener("error", reject);
1178
- resolve();
835
+ resolve2();
1179
836
  });
1180
837
  });
1181
838
  }
1182
839
 
840
+ Object.defineProperty(exports, "BaseTransport", {
841
+ enumerable: true,
842
+ get: function () { return chunkZ32CC665_cjs.BaseTransport; }
843
+ });
844
+ Object.defineProperty(exports, "HandlerRegistry", {
845
+ enumerable: true,
846
+ get: function () { return chunkZ32CC665_cjs.HandlerRegistry; }
847
+ });
848
+ Object.defineProperty(exports, "LiveSessionTransport", {
849
+ enumerable: true,
850
+ get: function () { return chunkZ32CC665_cjs.LiveSessionTransport; }
851
+ });
852
+ Object.defineProperty(exports, "SCREENSHOT_ACTION", {
853
+ enumerable: true,
854
+ get: function () { return chunkZ32CC665_cjs.SCREENSHOT_ACTION; }
855
+ });
856
+ Object.defineProperty(exports, "SCREENSHOT_CAPABILITY", {
857
+ enumerable: true,
858
+ get: function () { return chunkZ32CC665_cjs.SCREENSHOT_CAPABILITY; }
859
+ });
860
+ Object.defineProperty(exports, "SCREENSHOT_TIMEOUT_MS", {
861
+ enumerable: true,
862
+ get: function () { return chunkZ32CC665_cjs.SCREENSHOT_TIMEOUT_MS; }
863
+ });
864
+ Object.defineProperty(exports, "WrapperTransportError", {
865
+ enumerable: true,
866
+ get: function () { return chunkZ32CC665_cjs.WrapperTransportError; }
867
+ });
868
+ Object.defineProperty(exports, "captureScreenshotReply", {
869
+ enumerable: true,
870
+ get: function () { return chunkZ32CC665_cjs.captureScreenshotReply; }
871
+ });
872
+ Object.defineProperty(exports, "registerScreenshotCapture", {
873
+ enumerable: true,
874
+ get: function () { return chunkZ32CC665_cjs.registerScreenshotCapture; }
875
+ });
1183
876
  exports.ApiTransport = ApiTransport;
1184
- exports.BaseTransport = BaseTransport;
1185
- exports.HandlerRegistry = HandlerRegistry;
1186
877
  exports.HeadedTransport = HeadedTransport;
1187
878
  exports.HeadlessTransport = HeadlessTransport;
1188
879
  exports.InjectedTransport = InjectedTransport;
1189
- exports.LiveSessionTransport = LiveSessionTransport;
1190
- exports.WrapperTransportError = WrapperTransportError;
1191
880
  exports.createTransport = createTransport;
1192
881
  exports.emitManifestOnly = emitManifestOnly;
1193
882
  exports.paramSchemaOf = paramSchemaOf;