@inbrowser/driver 0.0.0-stage → 0.5.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.
Files changed (39) hide show
  1. package/AGENTS.md +20 -0
  2. package/LICENSE +21 -0
  3. package/README.md +112 -2
  4. package/THIRD_PARTY_NOTICES.txt +216 -0
  5. package/dist/LICENSE +21 -0
  6. package/dist/THIRD_PARTY_NOTICES.txt +216 -0
  7. package/dist/index.js +1631 -0
  8. package/dist/index.js.map +7 -0
  9. package/dist/preload.iife.js +5 -0
  10. package/dist/preload.js +2 -0
  11. package/dist/puppeteer.js +2569 -0
  12. package/dist/puppeteer.js.map +7 -0
  13. package/dist/tools.js +1283 -0
  14. package/dist/tools.js.map +7 -0
  15. package/dist/types/host/capture-seam.d.ts +17 -0
  16. package/dist/types/host/preview-backend.d.ts +9 -0
  17. package/dist/types/host/sandbox-connect.d.ts +38 -0
  18. package/dist/types/host/viewport-capture.d.ts +2 -0
  19. package/dist/types/index.d.ts +5 -0
  20. package/dist/types/preload/act.d.ts +4 -0
  21. package/dist/types/preload/capture-seam.d.ts +1 -0
  22. package/dist/types/preload/cursor-overlay.d.ts +5 -0
  23. package/dist/types/preload/diagnostics.d.ts +13 -0
  24. package/dist/types/preload/diff.d.ts +3 -0
  25. package/dist/types/preload/entry.d.ts +1 -0
  26. package/dist/types/preload/eval.d.ts +7 -0
  27. package/dist/types/preload/export.d.ts +11 -0
  28. package/dist/types/preload/intrinsics.d.ts +255 -0
  29. package/dist/types/preload/observe.d.ts +27 -0
  30. package/dist/types/preload/ref-registry.d.ts +44 -0
  31. package/dist/types/preload/silent-capture.d.ts +3 -0
  32. package/dist/types/protocol.d.ts +103 -0
  33. package/dist/types/puppeteer/cdp-driver.d.ts +11 -0
  34. package/dist/types/puppeteer/index.d.ts +2 -0
  35. package/dist/types/tools/format.d.ts +7 -0
  36. package/dist/types/tools/index.d.ts +9 -0
  37. package/dist/types/tools/schemas.d.ts +36 -0
  38. package/dist/types/types.d.ts +268 -0
  39. package/package.json +70 -4
@@ -0,0 +1,268 @@
1
+ /**
2
+ * Frozen public and cross-lane contracts for `@inbrowser/driver`.
3
+ *
4
+ * Zero imports so both browser host bundles and the isolated preload IIFE can
5
+ * depend on these contracts without pulling external runtime code.
6
+ */
7
+ export type RefId = `e${number}`;
8
+ export type SnapshotRevision = number;
9
+ export interface SemanticFingerprint {
10
+ readonly role: string;
11
+ readonly name: string;
12
+ readonly landmark?: string;
13
+ readonly driverId?: string;
14
+ readonly nth: number;
15
+ }
16
+ export type TargetSpec = RefId | {
17
+ readonly role: string;
18
+ readonly name?: string;
19
+ readonly nth?: number;
20
+ } | {
21
+ readonly driver: string;
22
+ readonly nth?: number;
23
+ } | {
24
+ readonly text: string;
25
+ readonly exact?: boolean;
26
+ };
27
+ export interface SnapshotMediaState {
28
+ readonly kind: 'video' | 'audio';
29
+ readonly paused: boolean;
30
+ readonly currentTime: number;
31
+ readonly duration: number | null;
32
+ readonly width: number;
33
+ readonly height: number;
34
+ readonly ready: boolean;
35
+ readonly error: string | null;
36
+ }
37
+ export interface SnapshotCanvasState {
38
+ readonly width: number;
39
+ readonly height: number;
40
+ readonly nonBlank: boolean;
41
+ }
42
+ export interface SnapshotNode {
43
+ readonly role: string;
44
+ readonly name: string;
45
+ readonly ref?: RefId;
46
+ readonly driverId?: string;
47
+ readonly intent?: string;
48
+ readonly value?: string;
49
+ readonly checked?: boolean;
50
+ readonly disabled?: boolean;
51
+ readonly expanded?: boolean;
52
+ readonly min?: number;
53
+ readonly max?: number;
54
+ readonly media?: SnapshotMediaState;
55
+ readonly canvas?: SnapshotCanvasState;
56
+ readonly children?: readonly SnapshotNode[];
57
+ }
58
+ export interface NetworkFailure {
59
+ readonly method: string;
60
+ readonly url: string;
61
+ readonly status: number;
62
+ readonly statusText: string;
63
+ }
64
+ export interface DiagnosticsDelta {
65
+ readonly compileOverlay: string | null;
66
+ readonly consoleErrors: readonly string[];
67
+ readonly pageErrors: readonly string[];
68
+ readonly networkFailures: readonly NetworkFailure[];
69
+ }
70
+ export interface ViewportSize {
71
+ readonly width: number;
72
+ readonly height: number;
73
+ }
74
+ export interface ObservationOptions {
75
+ readonly scope?: string;
76
+ readonly includeAllText?: boolean;
77
+ readonly signal?: AbortSignal;
78
+ }
79
+ export interface ObservationSnapshot {
80
+ readonly rev: SnapshotRevision;
81
+ readonly url: string;
82
+ readonly title: string;
83
+ readonly viewport: ViewportSize;
84
+ readonly diagnostics: DiagnosticsDelta;
85
+ readonly elements: readonly SnapshotNode[];
86
+ }
87
+ export interface ClickStep {
88
+ readonly kind: 'click';
89
+ readonly target: TargetSpec;
90
+ readonly button?: 'left' | 'middle' | 'right';
91
+ readonly clickCount?: number;
92
+ }
93
+ export interface FillStep {
94
+ readonly kind: 'fill';
95
+ readonly target: TargetSpec;
96
+ readonly value: string;
97
+ readonly submit?: boolean;
98
+ }
99
+ export interface SetValueStep {
100
+ readonly kind: 'setValue';
101
+ readonly target: TargetSpec;
102
+ readonly value: string | number;
103
+ }
104
+ export interface SelectStep {
105
+ readonly kind: 'select';
106
+ readonly target: TargetSpec;
107
+ readonly value: string | readonly string[];
108
+ }
109
+ export interface PressStep {
110
+ readonly kind: 'press';
111
+ readonly key: string;
112
+ readonly target?: TargetSpec;
113
+ }
114
+ export type DragDestination = {
115
+ readonly target: TargetSpec;
116
+ } | {
117
+ readonly deltaX: number;
118
+ readonly deltaY: number;
119
+ } | {
120
+ readonly clientX: number;
121
+ readonly clientY: number;
122
+ };
123
+ export interface DragStep {
124
+ readonly kind: 'drag';
125
+ readonly from: TargetSpec;
126
+ readonly to: DragDestination;
127
+ readonly steps?: number;
128
+ }
129
+ export type NavigateStep = {
130
+ readonly kind: 'navigate';
131
+ readonly url: string;
132
+ } | {
133
+ readonly kind: 'navigate';
134
+ readonly action: 'reload' | 'back' | 'forward';
135
+ };
136
+ export interface WaitForStep {
137
+ readonly kind: 'waitFor';
138
+ readonly target?: TargetSpec;
139
+ readonly text?: string;
140
+ readonly state?: 'attached' | 'visible' | 'hidden' | 'detached';
141
+ readonly idleMs?: number;
142
+ readonly timeoutMs?: number;
143
+ }
144
+ export type DriverStep = ClickStep | FillStep | SetValueStep | SelectStep | PressStep | DragStep | NavigateStep | WaitForStep;
145
+ export type ActInterruptionReason = 'step_error' | 'dialog_opened' | 'compile_error' | 'navigation' | 'user_takeover';
146
+ export interface SnapshotDiff {
147
+ readonly fromRev: SnapshotRevision;
148
+ readonly toRev: SnapshotRevision;
149
+ readonly fullReset: boolean;
150
+ readonly added: readonly SnapshotNode[];
151
+ readonly removed: readonly RefId[];
152
+ readonly changed: readonly SnapshotNode[];
153
+ readonly elements?: readonly SnapshotNode[];
154
+ }
155
+ export interface ActOptions {
156
+ readonly rev: SnapshotRevision;
157
+ readonly steps: readonly DriverStep[];
158
+ readonly timeoutMs?: number;
159
+ readonly signal?: AbortSignal;
160
+ }
161
+ export interface ActResult {
162
+ readonly completedSteps: number;
163
+ readonly totalSteps: number;
164
+ readonly interruptedReason?: ActInterruptionReason;
165
+ readonly error?: string;
166
+ readonly rev: SnapshotRevision;
167
+ readonly url: string;
168
+ readonly title: string;
169
+ readonly diff: SnapshotDiff;
170
+ readonly diagnostics: DiagnosticsDelta;
171
+ }
172
+ export type CaptureBackendMode = 'silent' | 'viewport-gpu';
173
+ export interface ScreenshotCaptureOptions {
174
+ readonly mode: 'screenshot';
175
+ readonly target?: TargetSpec;
176
+ readonly format?: 'webp' | 'png';
177
+ readonly quality?: number;
178
+ readonly signal?: AbortSignal;
179
+ }
180
+ export interface StartRecordingCaptureOptions {
181
+ readonly mode: 'start_recording';
182
+ readonly signal?: AbortSignal;
183
+ }
184
+ export interface StopRecordingCaptureOptions {
185
+ readonly mode: 'stop_recording';
186
+ readonly signal?: AbortSignal;
187
+ }
188
+ export type CaptureOptions = ScreenshotCaptureOptions | StartRecordingCaptureOptions | StopRecordingCaptureOptions;
189
+ export interface CaptureResult {
190
+ readonly mimeType: string;
191
+ readonly bytes: Uint8Array;
192
+ readonly width: number;
193
+ readonly height: number;
194
+ readonly modeUsed: CaptureBackendMode;
195
+ readonly durationMs?: number;
196
+ }
197
+ export interface EvalOptions {
198
+ readonly expression: string;
199
+ readonly timeoutMs?: number;
200
+ readonly signal?: AbortSignal;
201
+ }
202
+ export interface EvalResult {
203
+ readonly value: unknown;
204
+ readonly diagnostics: DiagnosticsDelta;
205
+ }
206
+ export interface DriverCapabilities {
207
+ readonly protocolVersion: 1;
208
+ readonly allowEval: boolean;
209
+ readonly captureModes: readonly CaptureBackendMode[];
210
+ readonly trustedInput: boolean;
211
+ }
212
+ export interface PageDriver {
213
+ readonly capabilities: DriverCapabilities;
214
+ observe(options?: ObservationOptions): Promise<ObservationSnapshot>;
215
+ act(options: ActOptions): Promise<ActResult>;
216
+ capture(options: CaptureOptions): Promise<CaptureResult>;
217
+ eval(options: EvalOptions): Promise<EvalResult>;
218
+ dispose(): void;
219
+ }
220
+ export type DriverErrorCode = 'DRIVER_TIMEOUT' | 'DRIVER_DISPOSED' | 'DRIVER_PROTOCOL' | 'DRIVER_UNSUPPORTED' | 'DRIVER_TARGET_NOT_FOUND' | 'DRIVER_TARGET_AMBIGUOUS' | 'DRIVER_EVAL_DISABLED';
221
+ export interface DriverErrorOptions {
222
+ readonly cause?: unknown;
223
+ readonly candidates?: readonly SemanticFingerprint[];
224
+ }
225
+ export declare class DriverError extends Error {
226
+ readonly code: DriverErrorCode;
227
+ readonly candidates?: readonly SemanticFingerprint[];
228
+ constructor(code: DriverErrorCode, message: string, options?: DriverErrorOptions);
229
+ }
230
+ export interface DisplayMediaProvider {
231
+ getDisplayMedia(constraints?: DisplayMediaStreamOptions): Promise<MediaStream>;
232
+ }
233
+ export interface ConnectPortOptions {
234
+ readonly handshakeTimeoutMs?: number;
235
+ readonly rpcTimeoutMs?: number;
236
+ readonly allowEval?: boolean;
237
+ readonly displayMediaProvider?: DisplayMediaProvider;
238
+ readonly onPortReplacement?: (rebind: (port: MessagePort) => void) => () => void;
239
+ readonly signal?: AbortSignal;
240
+ }
241
+ export interface ConnectIframeOptions extends ConnectPortOptions {
242
+ readonly targetOrigin?: string;
243
+ }
244
+ export type DriverJsonSchema = {
245
+ type?: string;
246
+ description?: string;
247
+ properties?: Record<string, DriverJsonSchema>;
248
+ required?: string[];
249
+ items?: DriverJsonSchema | DriverJsonSchema[];
250
+ enum?: unknown[];
251
+ [key: string]: unknown;
252
+ };
253
+ export interface DriverToolExecutionContext {
254
+ readonly signal?: AbortSignal;
255
+ }
256
+ export interface DriverToolResult<D = unknown> {
257
+ readonly ok: boolean;
258
+ readonly summary: string;
259
+ readonly data?: D;
260
+ }
261
+ export interface DriverTool<A = unknown, D = unknown> {
262
+ readonly name: string;
263
+ readonly description: string;
264
+ readonly parameters: DriverJsonSchema;
265
+ readonly parallelSafe?: false;
266
+ readonly pure?: false;
267
+ execute(args: A, ctx?: DriverToolExecutionContext): Promise<DriverToolResult<D>>;
268
+ }
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
2
  "name": "@inbrowser/driver",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.5.0",
4
+ "description": "1-RTT browser UI observation, transactional action, and visual capture driver for live iframes, MessagePorts, container previews, and real-CDP tabs.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/types/index.d.ts",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/types/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ },
14
+ "./preload": {
15
+ "types": "./dist/types/preload/export.d.ts",
16
+ "import": "./dist/preload.js"
17
+ },
18
+ "./tools": {
19
+ "types": "./dist/types/tools/index.d.ts",
20
+ "import": "./dist/tools.js"
21
+ },
22
+ "./puppeteer": {
23
+ "types": "./dist/types/puppeteer/index.d.ts",
24
+ "import": "./dist/puppeteer.js"
25
+ }
26
+ },
27
+ "files": ["dist", "LICENSE", "THIRD_PARTY_NOTICES.txt", "README.md", "AGENTS.md"],
28
+ "peerDependencies": {
29
+ "@inbrowser/agent": ">=0.4.0",
30
+ "@inbrowser/node": ">=0.4.0",
31
+ "@inbrowser/sandbox": ">=0.4.0",
32
+ "puppeteer-core": "^24.0.0"
33
+ },
34
+ "peerDependenciesMeta": {
35
+ "@inbrowser/agent": {
36
+ "optional": true
37
+ },
38
+ "@inbrowser/node": {
39
+ "optional": true
40
+ },
41
+ "@inbrowser/sandbox": {
42
+ "optional": true
43
+ },
44
+ "puppeteer-core": {
45
+ "optional": true
46
+ }
47
+ },
48
+ "scripts": {
49
+ "build": "node scripts/build.mjs && node scripts/check-boundaries.mjs",
50
+ "prepublishOnly": "bun run build",
51
+ "typecheck": "tsc -p tsconfig.json --noEmit",
52
+ "test": "vitest run",
53
+ "test:e2e": "playwright test"
54
+ },
55
+ "devDependencies": {
56
+ "@playwright/test": "1.58.2",
57
+ "@types/node": "22.20.2",
58
+ "esbuild": "^0.25.12",
59
+ "puppeteer-core": "24.43.1",
60
+ "typescript": "^5.7.0",
61
+ "vitest": "5.0.0"
62
+ },
63
+ "repository": {
64
+ "type": "git",
65
+ "url": "git+https://github.com/davideast/inbrowser-agent.git",
66
+ "directory": "packages/driver"
67
+ },
68
+ "license": "MIT",
69
+ "publishConfig": {
70
+ "access": "public"
71
+ }
72
+ }