@lynx-js/devtool-connector 0.9.5 → 0.13.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.
Files changed (49) hide show
  1. package/LICENSE +1 -1
  2. package/dist/346.js +635 -0
  3. package/dist/390.js +262 -35
  4. package/dist/556.js +9 -4
  5. package/dist/61.js +3432 -0
  6. package/dist/63.js +112 -30
  7. package/dist/712.js +28 -2
  8. package/dist/872.js +552 -122
  9. package/dist/962.js +25 -17
  10. package/dist/client-discovery-errors.d.ts +1 -0
  11. package/dist/client-id.d.ts +9 -2
  12. package/dist/command/client.d.ts +28 -0
  13. package/dist/command/contract.d.ts +255 -0
  14. package/dist/command/core.d.ts +32 -0
  15. package/dist/command/index.d.ts +20 -0
  16. package/dist/command/index.js +224 -0
  17. package/dist/command/query.d.ts +5 -0
  18. package/dist/command/reactlynx/controller.d.ts +71 -0
  19. package/dist/command/reactlynx/model.d.ts +48 -0
  20. package/dist/command/reactlynx/protocol.d.ts +40 -0
  21. package/dist/command/reactlynx/session.d.ts +43 -0
  22. package/dist/command/reactlynx/types.d.ts +73 -0
  23. package/dist/command/ref-actions.d.ts +17 -0
  24. package/dist/command/result.d.ts +29 -0
  25. package/dist/command/screenshot-annotation.d.ts +22 -0
  26. package/dist/command/screenshot.d.ts +28 -0
  27. package/dist/command/snapshot.d.ts +79 -0
  28. package/dist/command/targets.d.ts +15 -0
  29. package/dist/daemon/device-connection.d.ts +3 -1
  30. package/dist/daemon/entry.js +11 -0
  31. package/dist/daemon/index.d.ts +1 -0
  32. package/dist/daemon/index.js +3 -0
  33. package/dist/daemon/manager.d.ts +11 -9
  34. package/dist/daemon/protocol.d.ts +24 -3
  35. package/dist/daemon/server.d.ts +1 -0
  36. package/dist/index.d.ts +6 -2
  37. package/dist/index.js +2 -454
  38. package/dist/streams/customized.d.ts +2 -1
  39. package/dist/transport/android.d.ts +1 -1
  40. package/dist/transport/desktop.d.ts +1 -1
  41. package/dist/transport/index.js +2 -2
  42. package/dist/transport/ios.d.ts +1 -1
  43. package/dist/transport/transport.d.ts +7 -1
  44. package/dist/transport/ws-stream.d.ts +9 -0
  45. package/dist/types.d.ts +35 -0
  46. package/package.json +10 -2
  47. package/dist/187.js +0 -272
  48. package/dist/43.js +0 -20
  49. package/dist/677.js +0 -19
@@ -0,0 +1,224 @@
1
+ import { DaemonManager } from "../390.js";
2
+ import { fail as result_fail, appendCommandQueryParam } from "../61.js";
3
+ const MAX_SSE_BUFFER_LENGTH = 1048576;
4
+ async function ensureCommandServer(port, ensureDaemon) {
5
+ if (ensureDaemon) await DaemonManager.ensureRunning(port, {
6
+ commandProtocol: true
7
+ });
8
+ }
9
+ async function responseText(response) {
10
+ try {
11
+ return await response.text();
12
+ } catch {
13
+ return '';
14
+ }
15
+ }
16
+ function httpFailure(action, response, body) {
17
+ const suffix = body.trim() ? `: ${body.trim()}` : '';
18
+ return result_fail(action, `Daemon command ${action} failed with HTTP ${response.status} ${response.statusText}${suffix}`, {
19
+ reason: 'http-error',
20
+ recoverable: true,
21
+ nextActions: [
22
+ 'Ensure the connector daemon is running and up to date.',
23
+ 'Retry after restarting the connector daemon.'
24
+ ]
25
+ });
26
+ }
27
+ function isCommandResult(value) {
28
+ if ('object' != typeof value || null === value) return false;
29
+ const candidate = value;
30
+ if ('string' != typeof candidate['action'] || 'boolean' != typeof candidate['ok']) return false;
31
+ if (true === candidate['ok']) return Object.hasOwn(candidate, 'data');
32
+ const error = candidate['error'];
33
+ if ('object' != typeof error || null === error) return false;
34
+ const commandError = error;
35
+ 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
+ }
37
+ function invalidResponse(action, message, cause) {
38
+ return result_fail(action, message, {
39
+ reason: 'invalid-response',
40
+ recoverable: true,
41
+ ...void 0 === cause ? {} : {
42
+ cause
43
+ },
44
+ nextActions: [
45
+ 'Restart the connector daemon, then retry the command.'
46
+ ]
47
+ });
48
+ }
49
+ function requestFailure(action, error, signal) {
50
+ const aborted = signal?.aborted === true || error instanceof DOMException && ('AbortError' === error.name || 'TimeoutError' === error.name);
51
+ return result_fail(action, aborted ? `Daemon command ${action} was aborted or timed out.` : `Unable to reach the connector daemon for command ${action}.`, {
52
+ cause: error,
53
+ reason: aborted ? 'aborted' : 'daemon-unavailable',
54
+ recoverable: true,
55
+ nextActions: [
56
+ 'Ensure the connector daemon is running and up to date.',
57
+ 'Retry after restarting the connector daemon.'
58
+ ]
59
+ });
60
+ }
61
+ async function callRawCommand(action, params, options = {}) {
62
+ const port = options.port ?? 21783;
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
+ }
86
+ }
87
+ function callCommand(action, params, options = {}) {
88
+ return callRawCommand(action, params, options);
89
+ }
90
+ function getStreamUrl(port, action, params) {
91
+ const query = new URLSearchParams();
92
+ for (const [key, value] of Object.entries(params))appendCommandQueryParam(query, key, value);
93
+ const suffix = query.size > 0 ? `?${query}` : '';
94
+ return `http://127.0.0.1:${port}/command/${encodeURIComponent(action)}${suffix}`;
95
+ }
96
+ async function* streamRawCommand(action, params, options = {}) {
97
+ const port = options.port ?? 21783;
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
+ }
183
+ }
184
+ function streamCommand(action, params, options = {}) {
185
+ return streamRawCommand(action, params, options);
186
+ }
187
+ class HttpCommandClient {
188
+ #port;
189
+ #ensureDaemon;
190
+ constructor(options = {}){
191
+ this.#port = options.port ?? 21783;
192
+ this.#ensureDaemon = options.ensureDaemon ?? true;
193
+ }
194
+ execute(action, params, options = {}) {
195
+ return callCommand(action, params, {
196
+ ...options,
197
+ port: this.#port,
198
+ ensureDaemon: this.#ensureDaemon
199
+ });
200
+ }
201
+ stream(action, params, options = {}) {
202
+ return streamCommand(action, params, {
203
+ ...options,
204
+ port: this.#port,
205
+ ensureDaemon: this.#ensureDaemon
206
+ });
207
+ }
208
+ executeRaw(action, params, options = {}) {
209
+ return callRawCommand(action, params, {
210
+ ...options,
211
+ port: this.#port,
212
+ ensureDaemon: this.#ensureDaemon
213
+ });
214
+ }
215
+ streamRaw(action, params, options = {}) {
216
+ return streamRawCommand(action, params, {
217
+ ...options,
218
+ port: this.#port,
219
+ ensureDaemon: this.#ensureDaemon
220
+ });
221
+ }
222
+ }
223
+ export { ActionCore, DevNodeType, ScreenshotAnnotationError, ScreenshotTimeoutError, annotateScreenshot, applyOperationV2, applyRootOrder, buildReactLynxUpdatePath, buildRefs, buildRegexMatcher, buildSnapshot, buildSubstringMatcher, captureScreenshot, captureScreenshotFrame, centerOfQuad, createRendererState, deserializeRendererState, fail, findReactLynxComponents, formatReactLynxTree, normalizeRef, ok, parseReactLynxComponentRef, parseReactLynxLinkRef, serializeRendererState, touchTap, typeTag, validateRef } from "../61.js";
224
+ export { HttpCommandClient, callCommand, callRawCommand, streamCommand, streamRawCommand };
@@ -0,0 +1,5 @@
1
+ import type { CommandObject } from './contract.ts';
2
+ /** Preserve value types when a command client uses the curl-friendly GET SSE route. */
3
+ export declare function appendCommandQueryParam(query: URLSearchParams, key: string, value: unknown): void;
4
+ /** Decode both typed-client values and repeated, unprefixed curl parameters. */
5
+ export declare function decodeCommandQuery(params: URLSearchParams): CommandObject;
@@ -0,0 +1,71 @@
1
+ import type { Connector } from '../../index.ts';
2
+ import type { ID } from './protocol.ts';
3
+ import type { ReactLynxCacheInfo, ReactLynxComponentData, ReactLynxFindData, ReactLynxLinkedComponent, ReactLynxTreeData, ReactLynxUpdateKind } from './types.ts';
4
+ export interface ReactLynxCacheSnapshot {
5
+ capturedAt: number;
6
+ generation: number;
7
+ nodeCount: number;
8
+ compactLabels?: ID[];
9
+ shellLabels?: ID[];
10
+ }
11
+ export declare class ReactLynxActionError extends Error {
12
+ readonly reason: string;
13
+ readonly recoverable: boolean;
14
+ readonly nextActions: string[];
15
+ constructor(message: string, options: {
16
+ reason: string;
17
+ recoverable?: boolean;
18
+ nextActions?: string[];
19
+ });
20
+ }
21
+ interface Target {
22
+ clientId: string;
23
+ sessionId: number;
24
+ }
25
+ export interface ReactLynxElementToComponentMapping {
26
+ cache: ReactLynxCacheInfo;
27
+ component: ReactLynxLinkedComponent;
28
+ }
29
+ export interface ReactLynxComponentToElementMapping extends ReactLynxElementToComponentMapping {
30
+ uniqueId: number;
31
+ }
32
+ /** Daemon-owned ReactLynx tree cache and Preact DevTools action implementation. */
33
+ export declare class ReactLynxController {
34
+ #private;
35
+ getCache(clientId: string, sessionId: number): ReactLynxCacheSnapshot | undefined;
36
+ tree(connector: Connector, target: Target, options: {
37
+ depth?: number;
38
+ showShells: boolean;
39
+ }, signal: AbortSignal): Promise<ReactLynxTreeData>;
40
+ find(connector: Connector, target: Target, options: {
41
+ pattern: string;
42
+ regex: boolean;
43
+ showShells: boolean;
44
+ limit: number;
45
+ refresh: boolean;
46
+ }, signal: AbortSignal): Promise<ReactLynxFindData>;
47
+ component(connector: Connector, target: Target, options: {
48
+ ref: string;
49
+ showShells: boolean;
50
+ refresh: boolean;
51
+ }, signal: AbortSignal): Promise<ReactLynxComponentData>;
52
+ componentForElement(connector: Connector, target: Target, options: {
53
+ uniqueId: number;
54
+ showShells: boolean;
55
+ refresh: boolean;
56
+ }, signal: AbortSignal): Promise<ReactLynxElementToComponentMapping>;
57
+ elementForComponent(connector: Connector, target: Target, options: {
58
+ ref: string;
59
+ showShells: boolean;
60
+ refresh: boolean;
61
+ }, signal: AbortSignal): Promise<ReactLynxComponentToElementMapping>;
62
+ update(connector: Connector, target: Target, options: {
63
+ kind: ReactLynxUpdateKind;
64
+ ref: string;
65
+ path: string;
66
+ value: unknown;
67
+ showShells: boolean;
68
+ refresh: boolean;
69
+ }, signal: AbortSignal): Promise<ReactLynxComponentData>;
70
+ }
71
+ export {};
@@ -0,0 +1,48 @@
1
+ import { type ID, type RendererState, type VNode } from './protocol.ts';
2
+ import type { ReactLynxFindMatch } from './types.ts';
3
+ export interface FormattedReactLynxTree {
4
+ text: string;
5
+ /** `labels[index]` is the vnode id represented by `@c${index + 1}`. */
6
+ labels: ID[];
7
+ }
8
+ export interface ReactLynxTreeState {
9
+ roots: ID[];
10
+ nodes: VNode[];
11
+ }
12
+ export type ReactLynxLinkRef = {
13
+ kind: 'element';
14
+ ref: string;
15
+ } | {
16
+ kind: 'component-label';
17
+ index: number;
18
+ } | {
19
+ kind: 'component-id';
20
+ id: ID;
21
+ };
22
+ /** Assign canonical `@cN` labels and render the matching compact tree. */
23
+ export declare function formatReactLynxTree(state: RendererState, options?: {
24
+ maxDepth?: number;
25
+ hideShells?: boolean;
26
+ }): FormattedReactLynxTree;
27
+ /** Copy a mutable renderer tree into an HTTP/JSON-safe representation. */
28
+ export declare function serializeRendererState(state: RendererState): ReactLynxTreeState;
29
+ /** Rebuild a renderer tree at the CLI edge without sharing daemon state. */
30
+ export declare function deserializeRendererState(value: ReactLynxTreeState): RendererState;
31
+ export declare function buildSubstringMatcher(pattern: string): (name: string) => boolean;
32
+ export declare function buildRegexMatcher(pattern: string): (name: string) => boolean;
33
+ /** Find components in the exact label order used by the tree renderer. */
34
+ export declare function findReactLynxComponents(state: RendererState, matcher: (name: string) => boolean, options: {
35
+ hideShells: boolean;
36
+ limit: number;
37
+ formatted?: FormattedReactLynxTree;
38
+ }): ReactLynxFindMatch[];
39
+ export declare function parseReactLynxComponentRef(ref: string): {
40
+ kind: 'label';
41
+ index: number;
42
+ } | {
43
+ kind: 'id';
44
+ id: ID;
45
+ };
46
+ export declare function parseReactLynxLinkRef(ref: string): ReactLynxLinkRef;
47
+ /** Add the sentinel segment discarded by the app-side Preact adapter. */
48
+ export declare function buildReactLynxUpdatePath(userPath: string): string;
@@ -0,0 +1,40 @@
1
+ /** Stable component id assigned by the Preact-side renderer (`getOrCreateID`). */
2
+ export type ID = number;
3
+ /** Mirrors `DevNodeType` from `@lynx-js/preact-devtools`. */
4
+ export declare const DevNodeType: {
5
+ readonly Group: 0;
6
+ readonly Element: 1;
7
+ readonly ClassComponent: 2;
8
+ readonly FunctionComponent: 3;
9
+ readonly ForwardRef: 4;
10
+ readonly Memo: 5;
11
+ readonly Suspense: 6;
12
+ readonly Context: 7;
13
+ readonly Consumer: 8;
14
+ readonly Portal: 9;
15
+ };
16
+ export type DevNodeType = (typeof DevNodeType)[keyof typeof DevNodeType];
17
+ /** Serializable subset of an upstream Preact DevTools `DevNode`. */
18
+ export interface VNode {
19
+ id: ID;
20
+ type: DevNodeType;
21
+ name: string;
22
+ key: string;
23
+ parent: ID;
24
+ owner: ID;
25
+ children: ID[];
26
+ startTime: number;
27
+ endTime: number;
28
+ }
29
+ /** Mutable tree decoded from successive `operation_v2` frames. */
30
+ export interface RendererState {
31
+ tree: Map<ID, VNode>;
32
+ roots: ID[];
33
+ }
34
+ export declare function createRendererState(): RendererState;
35
+ /** Apply one upstream `operation_v2` payload to a renderer tree. */
36
+ export declare function applyOperationV2(state: RendererState, ops: number[]): void;
37
+ /** Replace the renderer's roots vector. */
38
+ export declare function applyRootOrder(state: RendererState, rootOrder: ID[]): void;
39
+ /** Short type tag used by the CLI's compact renderer. */
40
+ export declare function typeTag(type: DevNodeType): string;
@@ -0,0 +1,43 @@
1
+ import type { Connector } from '../../index.ts';
2
+ import { type RendererState } from './protocol.ts';
3
+ export declare const DEFAULT_REACTLYNX_IDLE_MS = 700;
4
+ export declare const DEFAULT_REACTLYNX_MAX_MS = 5000;
5
+ export interface PreactEnvelope<T = unknown> {
6
+ source: string;
7
+ type: string;
8
+ data: T;
9
+ }
10
+ export interface ReactLynxOutboundFrame {
11
+ method: string;
12
+ params: {
13
+ vmType: string;
14
+ event: string;
15
+ data: string;
16
+ };
17
+ }
18
+ export declare function buildReactLynxOutboundFrame<T = null>(type: string, data?: T): ReactLynxOutboundFrame;
19
+ export interface ReactLynxSessionResult {
20
+ state: RendererState;
21
+ framesSeen: number;
22
+ operationFrames: number;
23
+ rootOrderFrames: number;
24
+ envelopeTypes: Set<string>;
25
+ }
26
+ export type ReactLynxEnvelopeAction = 'continue' | 'stop';
27
+ export interface RunReactLynxSessionOptions {
28
+ connector: Connector;
29
+ clientId: string;
30
+ sessionId: number;
31
+ outbound: ReactLynxOutboundFrame[];
32
+ sendInit?: boolean;
33
+ onEnvelope?: (envelope: PreactEnvelope) => ReactLynxEnvelopeAction;
34
+ afterSnapshot?: (state: RendererState) => [type: string, data?: unknown] | null;
35
+ awaitEnvelope?: boolean;
36
+ snapshotIdleMs?: number;
37
+ idleMs?: number;
38
+ maxMs?: number;
39
+ signal?: AbortSignal;
40
+ }
41
+ /** Drive one short-lived Preact DevTools VM-event exchange. */
42
+ export declare function runReactLynxSession(options: RunReactLynxSessionOptions): Promise<ReactLynxSessionResult>;
43
+ export declare function reactLynxEmptyTreeDiagnostic(result: ReactLynxSessionResult): string;
@@ -0,0 +1,73 @@
1
+ import type { SnapshotRef } from '../snapshot.ts';
2
+ import type { DevNodeType, ID, VNode } from './protocol.ts';
3
+ export type ReactLynxCacheInfo = {
4
+ status: 'not-used';
5
+ } | {
6
+ status: 'refreshed' | 'reused';
7
+ generation: number;
8
+ capturedAt: number;
9
+ };
10
+ export interface ReactLynxTargetData {
11
+ clientId: string;
12
+ sessionId: number;
13
+ cache: ReactLynxCacheInfo;
14
+ }
15
+ export interface ReactLynxTreeData extends ReactLynxTargetData {
16
+ labels: ID[];
17
+ roots: ID[];
18
+ nodes: VNode[];
19
+ }
20
+ export interface ReactLynxFindMatch {
21
+ label: string;
22
+ id: ID;
23
+ name: string;
24
+ type: DevNodeType;
25
+ key: string;
26
+ ancestors: Array<{
27
+ label: string;
28
+ name: string;
29
+ }>;
30
+ }
31
+ export interface ReactLynxFindData extends ReactLynxTargetData {
32
+ componentCount: number;
33
+ matches: ReactLynxFindMatch[];
34
+ }
35
+ /** JSON-ish `InspectData` emitted by `@lynx-js/preact-devtools`. */
36
+ export interface ReactLynxInspectResult {
37
+ id: ID;
38
+ name: string;
39
+ type: DevNodeType;
40
+ key: string | null;
41
+ props: unknown;
42
+ state: unknown;
43
+ hooks: unknown;
44
+ context: unknown;
45
+ signals: unknown;
46
+ suspended?: boolean;
47
+ canSuspend?: boolean;
48
+ version?: string;
49
+ __source?: {
50
+ fileName: string;
51
+ lineNumber: number;
52
+ columnNumber: number;
53
+ };
54
+ }
55
+ export interface ReactLynxComponentData extends ReactLynxTargetData {
56
+ ref: string;
57
+ id: ID;
58
+ component: ReactLynxInspectResult;
59
+ }
60
+ export interface ReactLynxLinkedComponent {
61
+ ref: string | null;
62
+ id: ID;
63
+ type: DevNodeType;
64
+ name: string;
65
+ key: string;
66
+ }
67
+ export interface ReactLynxLinkData extends ReactLynxTargetData {
68
+ direction: 'element-to-component' | 'component-to-element';
69
+ relation: 'nearest-component' | 'first-host-element';
70
+ element: SnapshotRef;
71
+ component: ReactLynxLinkedComponent;
72
+ }
73
+ export type ReactLynxUpdateKind = 'update-prop' | 'update-state' | 'update-context';
@@ -0,0 +1,17 @@
1
+ import type { Connector } from '../index.ts';
2
+ import { type CommandFailure } from './result.ts';
3
+ import { type Point, type SnapshotRef } from './snapshot.ts';
4
+ export type RefFailureReason = 'no-snapshot' | 'ref-not-found' | 'stale-ref' | 'not-visible' | 'covered' | 'offscreen' | 'disabled' | 'not-editable';
5
+ export declare function normalizeRef(ref: string): string;
6
+ export type RefValidationResult = CommandFailure | {
7
+ ok: true;
8
+ nodeId: number;
9
+ };
10
+ /** Validate cached geometry against the live hit target before mutating the page. */
11
+ export declare function validateRef(action: string, connector: Connector, clientId: string, sessionId: number, ref: SnapshotRef, options?: {
12
+ requireEditable?: boolean;
13
+ }, signal?: AbortSignal): Promise<RefValidationResult>;
14
+ export declare function touchTap(connector: Connector, clientId: string, sessionId: number, point: Point, signal: AbortSignal): Promise<void>;
15
+ export declare function touchLongPress(connector: Connector, clientId: string, sessionId: number, point: Point, durationMs: number, signal: AbortSignal): Promise<void>;
16
+ export declare function touchSwipe(connector: Connector, clientId: string, sessionId: number, from: Point, to: Point, signal: AbortSignal, steps?: number): Promise<void>;
17
+ export declare function setValue(connector: Connector, clientId: string, sessionId: number, nodeId: number, value: string, signal: AbortSignal, currentValue?: string): Promise<void>;
@@ -0,0 +1,29 @@
1
+ /** Structured result envelope returned by the daemon command HTTP surface. */
2
+ export interface CommandError {
3
+ message: string;
4
+ cause?: string;
5
+ reason?: string;
6
+ recoverable: boolean;
7
+ nextActions: string[];
8
+ }
9
+ export interface CommandSuccess<T> {
10
+ ok: true;
11
+ action: string;
12
+ data: T;
13
+ error?: never;
14
+ }
15
+ export interface CommandFailure {
16
+ ok: false;
17
+ action: string;
18
+ data?: never;
19
+ error: CommandError;
20
+ }
21
+ export type CommandResult<T = unknown> = CommandSuccess<T> | CommandFailure;
22
+ export declare function ok<T>(action: string, data: T): CommandResult<T>;
23
+ export interface FailOptions {
24
+ cause?: unknown;
25
+ reason?: string;
26
+ recoverable?: boolean;
27
+ nextActions?: string[];
28
+ }
29
+ export declare function fail(action: string, message: string, options?: FailOptions): CommandFailure;
@@ -0,0 +1,22 @@
1
+ import type { ScreenshotAnnotation } from './contract.ts';
2
+ import { type Box, type SnapshotRef } from './snapshot.ts';
3
+ export declare class ScreenshotAnnotationError extends Error {
4
+ constructor(message: string, options?: ErrorOptions);
5
+ }
6
+ export interface AnnotateScreenshotOptions {
7
+ jpeg: Buffer;
8
+ refs: readonly SnapshotRef[];
9
+ /** Full screencast frame bounds in the same logical coordinate space as snapshot refs. */
10
+ frame: Box;
11
+ /** Visible page bounds used to clip refs, which may be inset within the frame. */
12
+ viewport: Box;
13
+ quality?: number;
14
+ }
15
+ export interface AnnotatedScreenshot {
16
+ jpeg: Buffer;
17
+ width: number;
18
+ height: number;
19
+ annotations: ScreenshotAnnotation[];
20
+ }
21
+ /** Draw numbered snapshot refs into a JPEG and return matching pixel-space metadata. */
22
+ export declare function annotateScreenshot(options: AnnotateScreenshotOptions): AnnotatedScreenshot;
@@ -0,0 +1,28 @@
1
+ import type { Connector } from '../index.ts';
2
+ export interface CaptureScreenshotOptions {
3
+ fullscreen?: boolean;
4
+ quality?: number;
5
+ signal?: AbortSignal;
6
+ timeoutMs?: number;
7
+ }
8
+ /** Coordinate metadata attached to `Page.screencastFrame` by the Lynx runtime. */
9
+ export interface ScreencastFrameMetadata {
10
+ offsetTop?: number;
11
+ pageScaleFactor?: number;
12
+ deviceWidth?: number;
13
+ deviceHeight?: number;
14
+ scrollOffsetX?: number;
15
+ scrollOffsetY?: number;
16
+ timestamp?: number;
17
+ }
18
+ export interface CapturedScreenshot {
19
+ data: string;
20
+ metadata?: ScreencastFrameMetadata;
21
+ }
22
+ export declare class ScreenshotTimeoutError extends Error {
23
+ constructor(timeoutMs: number);
24
+ }
25
+ /** Capture one JPEG screencast frame, including its logical coordinate metadata. */
26
+ export declare function captureScreenshotFrame(connector: Connector, clientId: string, sessionId: number, options?: CaptureScreenshotOptions): Promise<CapturedScreenshot>;
27
+ /** Capture one JPEG screencast frame and return only its base64 image data. */
28
+ export declare function captureScreenshot(connector: Connector, clientId: string, sessionId: number, options?: CaptureScreenshotOptions): Promise<string>;