@ddwang/magnitude-core 0.3.1-ddwang.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 (142) hide show
  1. package/dist/actions/desktopActions.d.ts +58 -0
  2. package/dist/actions/desktopActions.js +154 -0
  3. package/dist/actions/index.d.ts +26 -0
  4. package/dist/actions/index.js +11 -0
  5. package/dist/actions/taskActions.d.ts +8 -0
  6. package/dist/actions/taskActions.js +27 -0
  7. package/dist/actions/types.d.ts +31 -0
  8. package/dist/actions/types.js +5 -0
  9. package/dist/actions/util.d.ts +20 -0
  10. package/dist/actions/util.js +297 -0
  11. package/dist/actions/webActions.d.ts +79 -0
  12. package/dist/actions/webActions.js +190 -0
  13. package/dist/agent/browserAgent.d.ts +29 -0
  14. package/dist/agent/browserAgent.js +122 -0
  15. package/dist/agent/errors.d.ts +8 -0
  16. package/dist/agent/errors.js +68 -0
  17. package/dist/agent/index.d.ts +53 -0
  18. package/dist/agent/index.js +377 -0
  19. package/dist/agent/narrator.d.ts +4 -0
  20. package/dist/agent/narrator.js +63 -0
  21. package/dist/agent/pause.test.d.ts +1 -0
  22. package/dist/agent/pause.test.js +194 -0
  23. package/dist/ai/baml_client/async_client.d.ts +73 -0
  24. package/dist/ai/baml_client/async_client.js +152 -0
  25. package/dist/ai/baml_client/async_request.d.ts +35 -0
  26. package/dist/ai/baml_client/async_request.js +98 -0
  27. package/dist/ai/baml_client/config.d.ts +11 -0
  28. package/dist/ai/baml_client/config.js +20 -0
  29. package/dist/ai/baml_client/globals.d.ts +16 -0
  30. package/dist/ai/baml_client/globals.js +37 -0
  31. package/dist/ai/baml_client/index.d.ts +16 -0
  32. package/dist/ai/baml_client/index.js +41 -0
  33. package/dist/ai/baml_client/inlinedbaml.d.ts +19 -0
  34. package/dist/ai/baml_client/inlinedbaml.js +31 -0
  35. package/dist/ai/baml_client/parser.d.ts +53 -0
  36. package/dist/ai/baml_client/parser.js +86 -0
  37. package/dist/ai/baml_client/partial_types.d.ts +61 -0
  38. package/dist/ai/baml_client/partial_types.js +10 -0
  39. package/dist/ai/baml_client/sync_client.d.ts +50 -0
  40. package/dist/ai/baml_client/sync_client.js +100 -0
  41. package/dist/ai/baml_client/sync_request.d.ts +35 -0
  42. package/dist/ai/baml_client/sync_request.js +98 -0
  43. package/dist/ai/baml_client/tracing.d.ts +16 -0
  44. package/dist/ai/baml_client/tracing.js +18 -0
  45. package/dist/ai/baml_client/type_builder.d.ts +38 -0
  46. package/dist/ai/baml_client/type_builder.js +96 -0
  47. package/dist/ai/baml_client/types.d.ts +69 -0
  48. package/dist/ai/baml_client/types.js +15 -0
  49. package/dist/ai/claudeCode.d.ts +1 -0
  50. package/dist/ai/claudeCode.js +186 -0
  51. package/dist/ai/modelHarness.d.ts +39 -0
  52. package/dist/ai/modelHarness.js +189 -0
  53. package/dist/ai/multiModelHarness.d.ts +27 -0
  54. package/dist/ai/multiModelHarness.js +52 -0
  55. package/dist/ai/types.d.ts +90 -0
  56. package/dist/ai/types.js +5 -0
  57. package/dist/ai/util.d.ts +13 -0
  58. package/dist/ai/util.js +165 -0
  59. package/dist/cli.d.ts +0 -0
  60. package/dist/cli.js +3 -0
  61. package/dist/common/actions.d.ts +0 -0
  62. package/dist/common/actions.js +14 -0
  63. package/dist/common/events.d.ts +15 -0
  64. package/dist/common/events.js +3 -0
  65. package/dist/common/failure.d.ts +68 -0
  66. package/dist/common/failure.js +1 -0
  67. package/dist/common/index.d.ts +3 -0
  68. package/dist/common/index.js +3 -0
  69. package/dist/common/retry.d.ts +16 -0
  70. package/dist/common/retry.js +30 -0
  71. package/dist/common/util.d.ts +23 -0
  72. package/dist/common/util.js +132 -0
  73. package/dist/connectors/browserConnector.d.ts +40 -0
  74. package/dist/connectors/browserConnector.js +127 -0
  75. package/dist/connectors/desktopConnector.d.ts +58 -0
  76. package/dist/connectors/desktopConnector.js +68 -0
  77. package/dist/connectors/index.d.ts +10 -0
  78. package/dist/connectors/index.js +2 -0
  79. package/dist/index.cjs +6143 -0
  80. package/dist/index.d.cts +825 -0
  81. package/dist/index.d.ts +20 -0
  82. package/dist/index.js +26 -0
  83. package/dist/index.mjs +6097 -0
  84. package/dist/logger.d.ts +3 -0
  85. package/dist/logger.js +15 -0
  86. package/dist/memory/agentMemory.d.ts +37 -0
  87. package/dist/memory/agentMemory.js +121 -0
  88. package/dist/memory/image.d.ts +26 -0
  89. package/dist/memory/image.js +106 -0
  90. package/dist/memory/index.d.ts +3 -0
  91. package/dist/memory/index.js +3 -0
  92. package/dist/memory/masking.d.ts +7 -0
  93. package/dist/memory/masking.js +141 -0
  94. package/dist/memory/masking.test.d.ts +1 -0
  95. package/dist/memory/masking.test.js +117 -0
  96. package/dist/memory/observation.d.ts +38 -0
  97. package/dist/memory/observation.js +79 -0
  98. package/dist/memory/rendering/index.d.ts +10 -0
  99. package/dist/memory/rendering/index.js +13 -0
  100. package/dist/memory/rendering/renderJsonParts.d.ts +3 -0
  101. package/dist/memory/rendering/renderJsonParts.js +115 -0
  102. package/dist/memory/rendering/renderJsonParts.test.d.ts +1 -0
  103. package/dist/memory/rendering/renderJsonParts.test.js +217 -0
  104. package/dist/memory/rendering/renderXmlParts.d.ts +7 -0
  105. package/dist/memory/rendering/renderXmlParts.js +127 -0
  106. package/dist/memory/serde.d.ts +20 -0
  107. package/dist/memory/serde.js +81 -0
  108. package/dist/memory/util.d.ts +2 -0
  109. package/dist/memory/util.js +17 -0
  110. package/dist/telemetry/events.d.ts +9 -0
  111. package/dist/telemetry/events.js +80 -0
  112. package/dist/telemetry/index.d.ts +6 -0
  113. package/dist/telemetry/index.js +91 -0
  114. package/dist/types.d.ts +30 -0
  115. package/dist/types.js +1 -0
  116. package/dist/util.d.ts +1 -0
  117. package/dist/util.js +12 -0
  118. package/dist/version.d.ts +1 -0
  119. package/dist/version.js +3 -0
  120. package/dist/web/browserProvider.d.ts +23 -0
  121. package/dist/web/browserProvider.js +153 -0
  122. package/dist/web/harness.d.ts +102 -0
  123. package/dist/web/harness.js +340 -0
  124. package/dist/web/stability.d.ts +57 -0
  125. package/dist/web/stability.js +316 -0
  126. package/dist/web/tabs.d.ts +58 -0
  127. package/dist/web/tabs.js +293 -0
  128. package/dist/web/transformer.d.ts +7 -0
  129. package/dist/web/transformer.js +41 -0
  130. package/dist/web/types.d.ts +32 -0
  131. package/dist/web/types.js +2 -0
  132. package/dist/web/util.d.ts +3 -0
  133. package/dist/web/util.js +81 -0
  134. package/dist/web/visualizer/cursor.d.ts +16 -0
  135. package/dist/web/visualizer/cursor.js +152 -0
  136. package/dist/web/visualizer/index.d.ts +22 -0
  137. package/dist/web/visualizer/index.js +47 -0
  138. package/dist/web/visualizer/mouseEffects.d.ts +18 -0
  139. package/dist/web/visualizer/mouseEffects.js +287 -0
  140. package/dist/web/visualizer/typeEffects.d.ts +10 -0
  141. package/dist/web/visualizer/typeEffects.js +190 -0
  142. package/package.json +71 -0
@@ -0,0 +1,825 @@
1
+ import EventEmitter from 'eventemitter3';
2
+ import z$1, { Schema, z, ZodTypeAny, ZodSchema } from 'zod';
3
+ import { Image as Image$1 } from '@boundaryml/baml';
4
+ import sharp, { Sharp } from 'sharp';
5
+ import { BrowserContext, Page, PageScreenshotOptions, Browser, BrowserContextOptions, LaunchOptions } from 'playwright';
6
+ import { PostHog } from 'posthog-node';
7
+ import pino from 'pino';
8
+
9
+ type Base64Image = `data:image/${'jpeg' | 'png' | 'gif'};base64,${string}`;
10
+ type WebAction = NavigateWebAction | ClickWebAction | TypeWebAction | ScrollWebAction | SwitchTabWebAction;
11
+ interface NavigateWebAction {
12
+ variant: 'load';
13
+ url: string;
14
+ }
15
+ interface ClickWebAction {
16
+ variant: 'click';
17
+ x: number;
18
+ y: number;
19
+ }
20
+ interface TypeWebAction {
21
+ variant: 'type';
22
+ x: number;
23
+ y: number;
24
+ content: string;
25
+ }
26
+ interface ScrollWebAction {
27
+ variant: 'scroll';
28
+ x: number;
29
+ y: number;
30
+ deltaX: number;
31
+ deltaY: number;
32
+ }
33
+ type SwitchTabWebAction = {
34
+ variant: 'tab';
35
+ index: number;
36
+ };
37
+ interface PixelCoordinate {
38
+ x: number;
39
+ y: number;
40
+ }
41
+
42
+ /**
43
+ * "Intents" are natural language descriptors that align 1:1 with executable web actions.
44
+ * Micro converts intents into web actions.
45
+ */
46
+
47
+ interface Action {
48
+ variant: string;
49
+ [key: string]: any;
50
+ }
51
+ type ActionIntent = ClickIntent | TypeIntent | ScrollIntent | SwitchTabIntent;
52
+ type Intent = ActionIntent | CheckIntent;
53
+ interface ClickIntent {
54
+ variant: 'click';
55
+ target: string;
56
+ }
57
+ interface TypeIntent {
58
+ variant: 'type';
59
+ target: string;
60
+ content: string;
61
+ }
62
+ interface ScrollIntent {
63
+ variant: 'scroll';
64
+ target: string;
65
+ deltaX: number;
66
+ deltaY: number;
67
+ }
68
+ type SwitchTabIntent = SwitchTabWebAction;
69
+ interface CheckIntent {
70
+ variant: 'check';
71
+ checks: string[];
72
+ }
73
+
74
+ type BrowserAgentRole = 'act' | 'extract' | 'query';
75
+ declare const allBrowserAgentRoles: BrowserAgentRole[];
76
+ type LLMClient = (AnthropicClient | ClaudeCodeClient | BedrockClient | GoogleAIClient | GoogleVertexClient | OpenAIClient | OpenAIGenericClient | AzureOpenAIClient) & {
77
+ roles?: BrowserAgentRole[];
78
+ };
79
+ interface AnthropicClient {
80
+ provider: 'anthropic';
81
+ options: {
82
+ model: string;
83
+ apiKey?: string;
84
+ temperature?: number;
85
+ promptCaching?: boolean;
86
+ };
87
+ }
88
+ interface ClaudeCodeClient {
89
+ provider: 'claude-code';
90
+ options: {
91
+ model: string;
92
+ temperature?: number;
93
+ promptCaching?: boolean;
94
+ };
95
+ }
96
+ interface BedrockClient {
97
+ provider: 'aws-bedrock';
98
+ options: {
99
+ model: string;
100
+ temperature?: number;
101
+ };
102
+ }
103
+ interface GoogleAIClient {
104
+ provider: 'google-ai';
105
+ options: {
106
+ model: string;
107
+ apiKey?: string;
108
+ temperature?: number;
109
+ baseUrl?: string;
110
+ };
111
+ }
112
+ interface GoogleVertexClient {
113
+ provider: 'vertex-ai';
114
+ options: {
115
+ model: string;
116
+ location?: string;
117
+ baseUrl?: string;
118
+ projectId?: string;
119
+ credentials?: string | object;
120
+ anthropicVersion?: string;
121
+ temperature?: number;
122
+ };
123
+ }
124
+ interface OpenAIClient {
125
+ provider: 'openai';
126
+ options: {
127
+ model: string;
128
+ apiKey?: string;
129
+ temperature?: number;
130
+ };
131
+ }
132
+ interface AzureOpenAIClient {
133
+ provider: 'azure-openai';
134
+ options: {
135
+ resourceName: string;
136
+ deploymentId: string;
137
+ apiVersion: string;
138
+ apiKey: string;
139
+ };
140
+ }
141
+ interface OpenAIGenericClient {
142
+ provider: 'openai-generic';
143
+ options: {
144
+ model: string;
145
+ baseUrl: string;
146
+ apiKey?: string;
147
+ temperature?: number;
148
+ headers?: Record<string, string>;
149
+ };
150
+ }
151
+ interface LLMClientIdentifier {
152
+ provider: string;
153
+ model: string;
154
+ }
155
+ interface ModelUsage {
156
+ llm: LLMClientIdentifier;
157
+ inputTokens: number;
158
+ outputTokens: number;
159
+ cacheWriteInputTokens?: number;
160
+ cacheReadInputTokens?: number;
161
+ inputCost?: number;
162
+ outputCost?: number;
163
+ }
164
+
165
+ interface AgentEvents {
166
+ 'start': () => void;
167
+ 'stop': () => void;
168
+ 'thought': (thought: string) => void;
169
+ 'actStarted': (task: string, options: ActOptions) => void;
170
+ 'actDone': (task: string, options: ActOptions) => void;
171
+ 'actionStarted': (action: Action) => void;
172
+ 'actionDone': (action: Action) => void;
173
+ 'pause': () => void;
174
+ 'resume': () => void;
175
+ 'tokensUsed': (usage: ModelUsage) => void;
176
+ }
177
+
178
+ type StoredMedia = {
179
+ type: 'media';
180
+ format: string;
181
+ storage: 'base64';
182
+ base64: string;
183
+ };
184
+ interface StoredPrimitive {
185
+ type: 'primitive';
186
+ content: string | boolean | number;
187
+ }
188
+ type MultiMediaPrimitive = StoredMedia | StoredPrimitive | undefined | null;
189
+ type MultiMediaArray = Array<MultiMediaJson>;
190
+ type MultiMediaObject = {
191
+ [key: string]: MultiMediaJson;
192
+ };
193
+ type MultiMediaJson = MultiMediaPrimitive | MultiMediaArray | MultiMediaObject;
194
+
195
+ declare class Image {
196
+ /**
197
+ * Wrapper for a Sharp image with conveniences to go to/from base64, convert to BAML, or serialize as JSON
198
+ */
199
+ private img;
200
+ constructor(img: Sharp);
201
+ static fromBase64(base64: string): Image;
202
+ getFormat(): Promise<keyof sharp.FormatEnum>;
203
+ /**
204
+ * Convert the image to a JSON representation
205
+ */
206
+ toJson(): Promise<StoredMedia>;
207
+ toBase64(): Promise<string>;
208
+ toBaml(): Promise<Image$1>;
209
+ saveToFile(filepath: string): Promise<void>;
210
+ getDimensions(): Promise<{
211
+ width: number;
212
+ height: number;
213
+ }>;
214
+ resize(width: number, height: number): Promise<Image>;
215
+ }
216
+
217
+ /*************************************************************************************************
218
+
219
+ Welcome to Baml! To use this generated code, please run one of the following:
220
+
221
+ $ npm install @boundaryml/baml
222
+ $ yarn add @boundaryml/baml
223
+ $ pnpm add @boundaryml/baml
224
+
225
+ *************************************************************************************************/
226
+
227
+ interface AgentContext {
228
+ instructions?: string | null;
229
+ observationContent: MultiMediaMessage[];
230
+ connectorInstructions: ConnectorInstructions[];
231
+ }
232
+ interface ConnectorInstructions {
233
+ connectorId: string;
234
+ instructions: string;
235
+ }
236
+ interface MultiMediaMessage {
237
+ role: "user" | "assistant";
238
+ cacheControl: boolean;
239
+ content: (Image$1 | string)[];
240
+ }
241
+
242
+ type MultiMediaContentPart = Image$1 | string;
243
+
244
+ type ObservableDataPrimitive = Image | string | number | boolean | null | undefined;
245
+ type ObservableDataArray = Array<RenderableContent>;
246
+ type ObservableDataObject = {
247
+ [key: string]: RenderableContent;
248
+ };
249
+ type RenderableContent = ObservableDataPrimitive | ObservableDataArray | ObservableDataObject;
250
+ type ObservationRole = 'user' | 'assistant';
251
+ interface ObservationRetentionOptions {
252
+ type: string;
253
+ limit?: number;
254
+ dedupe?: boolean;
255
+ }
256
+ type ObservationSource = `connector:${string}` | `action:taken:${string}` | `action:result:${string}` | `thought`;
257
+ declare class Observation {
258
+ readonly source: ObservationSource;
259
+ readonly role: ObservationRole;
260
+ readonly timestamp: number;
261
+ readonly content: RenderableContent;
262
+ readonly retention?: ObservationRetentionOptions;
263
+ constructor(source: ObservationSource, role: ObservationRole, content: RenderableContent, retention?: ObservationRetentionOptions, timestamp?: number);
264
+ static fromConnector(connectorId: string, content: RenderableContent, options?: ObservationRetentionOptions): Observation;
265
+ static fromActionTaken(actionId: string, content: RenderableContent, options?: ObservationRetentionOptions): Observation;
266
+ static fromActionResult(actionId: string, content: RenderableContent, options?: ObservationRetentionOptions): Observation;
267
+ static fromThought(content: RenderableContent, options?: ObservationRetentionOptions): Observation;
268
+ toString(): string;
269
+ toJson(): Promise<MultiMediaJson>;
270
+ render(options?: {
271
+ prefix?: MultiMediaContentPart[];
272
+ postfix?: MultiMediaContentPart[];
273
+ cacheControl?: boolean;
274
+ }): Promise<MultiMediaMessage>;
275
+ hash(): Promise<string>;
276
+ equals(obs: Observation): Promise<boolean>;
277
+ }
278
+
279
+ interface ActionDefinition<T> {
280
+ name: string;
281
+ description?: string;
282
+ schema: Schema<T>;
283
+ resolver: ({ input, agent }: {
284
+ input: T;
285
+ agent: Agent;
286
+ }) => Promise<void | RenderableContent>;
287
+ render: (action: T) => string;
288
+ }
289
+ declare function createAction<S extends ZodTypeAny>(action: {
290
+ name: string;
291
+ description?: string;
292
+ schema?: S;
293
+ resolver: ({ input, agent }: {
294
+ input: z.infer<S>;
295
+ agent: Agent;
296
+ }) => Promise<void | RenderableContent>;
297
+ render?: (action: z.infer<S>) => string;
298
+ }): ActionDefinition<z.infer<S>>;
299
+ type ActionPayload<A extends ActionDefinition<any>> = {
300
+ name: A['name'];
301
+ } & z.infer<A['schema']>;
302
+
303
+ interface AgentConnector {
304
+ id: string;
305
+ onStart?(): Promise<void>;
306
+ onStop?(): Promise<void>;
307
+ getActionSpace?(): ActionDefinition<any>[];
308
+ collectObservations?(): Promise<Observation[]>;
309
+ getInstructions?(): Promise<void | string>;
310
+ }
311
+
312
+ interface SerializedAgentMemory {
313
+ instructions?: string;
314
+ observations: {
315
+ source: ObservationSource;
316
+ role: ObservationRole;
317
+ timestamp: number;
318
+ data: MultiMediaJson;
319
+ options?: ObservationRetentionOptions;
320
+ }[];
321
+ }
322
+ interface AgentMemoryOptions {
323
+ instructions?: string | null;
324
+ promptCaching?: boolean;
325
+ thoughtLimit?: number;
326
+ }
327
+ interface MemoryRenderOptions {
328
+ }
329
+ declare class AgentMemory {
330
+ private options;
331
+ private observations;
332
+ private freezeMask?;
333
+ private cacheControlIndices;
334
+ constructor(options?: AgentMemoryOptions);
335
+ get instructions(): string | null;
336
+ render(options?: MemoryRenderOptions): Promise<MultiMediaMessage[]>;
337
+ simpleRender(): Promise<(Image$1 | string)[]>;
338
+ isEmpty(): boolean;
339
+ recordThought(content: string): void;
340
+ recordObservation(obs: Observation): void;
341
+ getLastThoughtMessage(): string | null;
342
+ toJSON(): Promise<SerializedAgentMemory>;
343
+ loadJSON(data: SerializedAgentMemory): Promise<void>;
344
+ }
345
+
346
+ declare function mergeMessages(messages: MultiMediaMessage[]): MultiMediaMessage[];
347
+
348
+ interface ModelHarnessEvents {
349
+ 'tokensUsed': (usage: ModelUsage) => {};
350
+ }
351
+
352
+ declare class MultiModelHarness {
353
+ /**
354
+ * Delegates model responsibilites to different LLMs and consolidates their usage
355
+ */
356
+ private roles;
357
+ private uniqueModels;
358
+ readonly events: EventEmitter<ModelHarnessEvents>;
359
+ constructor(clients: LLMClient[]);
360
+ setup(): Promise<void>;
361
+ describe(): string;
362
+ partialAct<T>(context: AgentContext, task: string, data: MultiMediaContentPart[], actionVocabulary: ActionDefinition<T>[]): Promise<{
363
+ reasoning: string;
364
+ actions: Action[];
365
+ }>;
366
+ extract<T extends z$1.Schema>(instructions: string, schema: T, screenshot: Image, domContent: string): Promise<z$1.infer<T>>;
367
+ query<T extends z$1.Schema>(context: AgentContext, query: string, schema: T): Promise<z$1.infer<T>>;
368
+ get numUniqueModels(): number;
369
+ }
370
+
371
+ interface AgentOptions {
372
+ llm?: LLMClient | LLMClient[];
373
+ connectors?: AgentConnector[];
374
+ actions?: ActionDefinition<any>[];
375
+ prompt?: string | null;
376
+ telemetry?: boolean;
377
+ }
378
+ interface ActOptions {
379
+ prompt?: string;
380
+ data?: RenderableContent;
381
+ memory?: AgentMemory;
382
+ }
383
+ declare class Agent {
384
+ private options;
385
+ private connectors;
386
+ private actions;
387
+ private memoryOptions;
388
+ readonly models: MultiModelHarness;
389
+ readonly events: EventEmitter<AgentEvents>;
390
+ private doneActing;
391
+ private _paused;
392
+ private _pauseResolve;
393
+ protected latestTaskMemory: AgentMemory;
394
+ constructor(baseConfig?: Partial<AgentOptions>);
395
+ getConnector<C extends AgentConnector>(connectorClass: new (...args: any[]) => C): C | undefined;
396
+ require<C extends AgentConnector>(connectorClass: new (...args: any[]) => C): C;
397
+ start(): Promise<void>;
398
+ identifyAction(action: Action): ActionDefinition<any>;
399
+ exec(action: Action, memory?: AgentMemory): Promise<void>;
400
+ protected _recordConnectorObservations(memory: AgentMemory): Promise<void>;
401
+ get memory(): AgentMemory;
402
+ act(taskOrSteps: string | string[], options?: ActOptions): Promise<void>;
403
+ _traceAct(task: string, memory: AgentMemory, options?: ActOptions): Promise<void>;
404
+ private _buildContext;
405
+ _act(description: string, memory: AgentMemory, options?: ActOptions): Promise<void>;
406
+ query<T extends z$1.Schema>(query: string, schema: T): Promise<z$1.infer<T>>;
407
+ queueDone(): Promise<void>;
408
+ private _waitIfPaused;
409
+ pause(): void;
410
+ resume(): void;
411
+ get paused(): boolean;
412
+ stop(): Promise<void>;
413
+ }
414
+
415
+ interface ActionVisualizerOptions {
416
+ showCursor?: boolean;
417
+ showHoverCircle?: boolean;
418
+ showClickRipple?: boolean;
419
+ showDragLine?: boolean;
420
+ showTypeEffects?: boolean;
421
+ }
422
+ declare class ActionVisualizer {
423
+ private options;
424
+ private context;
425
+ private page;
426
+ private cursor;
427
+ private mouseEffects;
428
+ private typeEffects;
429
+ constructor(context: BrowserContext, options: ActionVisualizerOptions);
430
+ setup(): Promise<void>;
431
+ setActivePage(page: Page): Promise<void>;
432
+ moveVirtualCursor(x: number, y: number): Promise<void>;
433
+ hideAll(): Promise<void>;
434
+ showAll(): Promise<void>;
435
+ }
436
+
437
+ interface TabState {
438
+ activeTab: number;
439
+ tabs: {
440
+ title: string;
441
+ url: string;
442
+ }[];
443
+ }
444
+
445
+ interface WebHarnessOptions {
446
+ virtualScreenDimensions?: {
447
+ width: number;
448
+ height: number;
449
+ };
450
+ visuals?: ActionVisualizerOptions;
451
+ switchTabsOnActivity?: boolean;
452
+ }
453
+ interface WebHarnessEvents {
454
+ 'activePageChanged': (page: Page) => Promise<void>;
455
+ }
456
+ declare class WebHarness {
457
+ /**
458
+ * Executes web actions on a page
459
+ * Not responsible for browser lifecycle
460
+ */
461
+ readonly context: BrowserContext;
462
+ private options;
463
+ private stability;
464
+ readonly visualizer: ActionVisualizer;
465
+ private transformer;
466
+ private tabs;
467
+ readonly events: EventEmitter<WebHarnessEvents>;
468
+ constructor(context: BrowserContext, options?: WebHarnessOptions);
469
+ setActivePage(page: Page): Promise<void>;
470
+ retrieveTabState(): Promise<TabState>;
471
+ start(): Promise<void>;
472
+ stop(): Promise<void>;
473
+ get page(): Page;
474
+ screenshot(options?: PageScreenshotOptions): Promise<Image>;
475
+ _type(content: string): Promise<void>;
476
+ transformCoordinates({ x, y }: {
477
+ x: number;
478
+ y: number;
479
+ }): Promise<{
480
+ x: number;
481
+ y: number;
482
+ }>;
483
+ click({ x, y }: {
484
+ x: number;
485
+ y: number;
486
+ }, options?: {
487
+ transform: boolean;
488
+ }): Promise<void>;
489
+ private _click;
490
+ rightClick({ x, y }: {
491
+ x: number;
492
+ y: number;
493
+ }, options?: {
494
+ transform: boolean;
495
+ }): Promise<void>;
496
+ doubleClick({ x, y }: {
497
+ x: number;
498
+ y: number;
499
+ }, options?: {
500
+ transform: boolean;
501
+ }): Promise<void>;
502
+ drag({ x1, y1, x2, y2 }: {
503
+ x1: number;
504
+ y1: number;
505
+ x2: number;
506
+ y2: number;
507
+ }, options?: {
508
+ transform: boolean;
509
+ }): Promise<void>;
510
+ type({ content }: {
511
+ content: string;
512
+ }): Promise<void>;
513
+ clickAndType({ x, y, content }: {
514
+ x: number;
515
+ y: number;
516
+ content: string;
517
+ }, options?: {
518
+ transform: boolean;
519
+ }): Promise<void>;
520
+ scroll({ x, y, deltaX, deltaY }: {
521
+ x: number;
522
+ y: number;
523
+ deltaX: number;
524
+ deltaY: number;
525
+ }, options?: {
526
+ transform: boolean;
527
+ }): Promise<void>;
528
+ switchTab({ index }: {
529
+ index: number;
530
+ }): Promise<void>;
531
+ newTab(): Promise<void>;
532
+ navigate(url: string): Promise<void>;
533
+ selectAll(): Promise<void>;
534
+ enter(): Promise<void>;
535
+ backspace(): Promise<void>;
536
+ tab(): Promise<void>;
537
+ goBack(): Promise<void>;
538
+ executeAction(action: WebAction): Promise<void>;
539
+ waitForStability(timeout?: number): Promise<void>;
540
+ }
541
+
542
+ type BrowserOptions = {
543
+ instance: Browser;
544
+ contextOptions?: BrowserContextOptions;
545
+ } | {
546
+ cdp: string;
547
+ contextOptions?: BrowserContextOptions;
548
+ } | {
549
+ launchOptions?: LaunchOptions;
550
+ contextOptions?: BrowserContextOptions;
551
+ } | {
552
+ context: BrowserContext;
553
+ };
554
+ declare class BrowserProvider {
555
+ private activeBrowsers;
556
+ private logger;
557
+ private constructor();
558
+ static getInstance(): BrowserProvider;
559
+ private _launchOrReuseBrowser;
560
+ _createAndTrackContext(options: BrowserOptions): Promise<BrowserContext>;
561
+ newContext(options?: BrowserOptions): Promise<BrowserContext>;
562
+ private _applyEmulationSettings;
563
+ }
564
+
565
+ interface BrowserConnectorOptions {
566
+ browser?: BrowserOptions;
567
+ url?: string;
568
+ virtualScreenDimensions?: {
569
+ width: number;
570
+ height: number;
571
+ };
572
+ minScreenshots?: number;
573
+ visuals?: ActionVisualizerOptions;
574
+ }
575
+ interface BrowserConnectorStateData {
576
+ screenshot: Image;
577
+ tabs: TabState;
578
+ }
579
+ declare class BrowserConnector implements AgentConnector {
580
+ readonly id: string;
581
+ private harness;
582
+ private options;
583
+ private browser?;
584
+ private context;
585
+ private logger;
586
+ constructor(options?: BrowserConnectorOptions);
587
+ onStart(): Promise<void>;
588
+ onStop(): Promise<void>;
589
+ getActionSpace(): ActionDefinition<any>[];
590
+ getHarness(): WebHarness;
591
+ private captureCurrentState;
592
+ transformScreenshot(screenshot: Image): Promise<Image>;
593
+ getLastScreenshot(): Promise<Image>;
594
+ collectObservations(): Promise<Observation[]>;
595
+ getInstructions(): Promise<void | string>;
596
+ }
597
+
598
+ declare function startBrowserAgent(options?: AgentOptions & BrowserConnectorOptions & {
599
+ narrate?: boolean;
600
+ }): Promise<BrowserAgent>;
601
+ type ExtractedOutput = string | number | boolean | bigint | Date | null | undefined | {
602
+ [key: string]: ExtractedOutput;
603
+ } | ExtractedOutput[];
604
+ interface BrowserAgentEvents {
605
+ 'nav': (url: string) => void;
606
+ 'extractStarted': (instructions: string, schema: ZodSchema) => void;
607
+ 'extractDone': (instructions: string, data: ExtractedOutput) => void;
608
+ }
609
+ declare class BrowserAgent extends Agent {
610
+ readonly browserAgentEvents: EventEmitter<BrowserAgentEvents>;
611
+ constructor({ agentOptions, browserOptions }: {
612
+ agentOptions?: Partial<AgentOptions>;
613
+ browserOptions?: BrowserConnectorOptions;
614
+ });
615
+ get page(): Page;
616
+ get context(): BrowserContext;
617
+ nav(url: string): Promise<void>;
618
+ extract<T extends Schema>(instructions: string, schema: T): Promise<z$1.infer<T>>;
619
+ }
620
+
621
+ /**
622
+ * Generic desktop automation interface.
623
+ * Implementations can use any desktop automation technology
624
+ * (Lume, PyAutoGUI, Windows UI Automation, etc.)
625
+ */
626
+ interface DesktopInterface {
627
+ click(x: number, y: number): Promise<void>;
628
+ rightClick(x: number, y: number): Promise<void>;
629
+ doubleClick(x: number, y: number): Promise<void>;
630
+ moveCursor(x: number, y: number): Promise<void>;
631
+ drag(fromX: number, fromY: number, toX: number, toY: number): Promise<void>;
632
+ scroll(x: number, y: number, deltaX: number, deltaY: number): Promise<void>;
633
+ type(text: string): Promise<void>;
634
+ key(key: string): Promise<void>;
635
+ hotkey(keys: string[]): Promise<void>;
636
+ screenshot(): Promise<Buffer>;
637
+ getScreenSize(): Promise<{
638
+ width: number;
639
+ height: number;
640
+ }>;
641
+ navigate?(url: string): Promise<void>;
642
+ getActiveWindow?(): Promise<{
643
+ title: string;
644
+ app: string;
645
+ }>;
646
+ getOpenWindows?(): Promise<Array<{
647
+ title: string;
648
+ app: string;
649
+ isActive: boolean;
650
+ }>>;
651
+ focusWindow?(title: string): Promise<void>;
652
+ openApplication?(name: string): Promise<void>;
653
+ closeApplication?(name: string): Promise<void>;
654
+ }
655
+ interface DesktopConnectorOptions {
656
+ desktopInterface: DesktopInterface;
657
+ virtualScreenDimensions?: {
658
+ width: number;
659
+ height: number;
660
+ };
661
+ minScreenshots?: number;
662
+ }
663
+ declare class DesktopConnector implements AgentConnector {
664
+ readonly id: string;
665
+ private desktopInterface;
666
+ private options;
667
+ private logger;
668
+ constructor(options: DesktopConnectorOptions);
669
+ onStart(): Promise<void>;
670
+ onStop(): Promise<void>;
671
+ getActionSpace(): ActionDefinition<any>[];
672
+ collectObservations(): Promise<Observation[]>;
673
+ private formatWindowInfo;
674
+ getInterface(): DesktopInterface;
675
+ }
676
+
677
+ interface AgentErrorOptions {
678
+ variant?: string;
679
+ adaptable?: boolean;
680
+ }
681
+ declare class AgentError extends Error {
682
+ readonly options: Required<AgentErrorOptions>;
683
+ constructor(message: string, options?: AgentErrorOptions);
684
+ }
685
+
686
+ /**
687
+ * Represents any reason why a test case could have failed, for example:
688
+ * - Step could not be completed
689
+ * - Check did not pass
690
+ * - Could not navigate to starting URL
691
+ * - Time or action based timeout
692
+ * - Operation cancelled by signal
693
+ * - ...
694
+ */
695
+ type FailureDescriptor = BugDetectedFailure | MisalignmentFailure | NetworkFailure | BrowserFailure | RateLimitFailure | ApiKeyFailure | UnknownFailure | CancelledFailure;
696
+ type BugSeverity = 'critical' | 'high' | 'medium' | 'low';
697
+ /**
698
+ * Step and check failures are classified into one of:
699
+ * BugDetectedFailure: seems to be something wrong with the application itself
700
+ * MisalignmentFailure: seems to be a discrepency between the test case and the interface
701
+ * OR the agent did not properly recognize the relationship between test case and interface
702
+ */
703
+ interface BugDetectedFailure {
704
+ variant: 'bug';
705
+ title: string;
706
+ expectedResult: string;
707
+ actualResult: string;
708
+ severity: BugSeverity;
709
+ }
710
+ interface MisalignmentFailure {
711
+ /**
712
+ * Major misalignment: when a step/check fails due to:
713
+ * 1. Poorly written step/check that is completely unrelated to the interface
714
+ * 2. Or interface has changed so much that step/check no longer applicable
715
+ * 3. Planner did not do good enough job adjusting recipe for minor misalignment
716
+ * Misalignment could be due to a poorly written test case OR bad agent behavior.
717
+ */
718
+ variant: 'misalignment';
719
+ message: string;
720
+ }
721
+ interface NetworkFailure {
722
+ /**
723
+ * For example, failure to connect to starting URL, or any other network errors
724
+ * that would completely prevent the test from executing.
725
+ */
726
+ variant: 'network';
727
+ message: string;
728
+ }
729
+ interface BrowserFailure {
730
+ /**
731
+ * E.g. something goes wrong with playwright interactions, any DOM manipulation, etc.
732
+ */
733
+ variant: 'browser';
734
+ message: string;
735
+ }
736
+ interface RateLimitFailure {
737
+ variant: 'rate_limit';
738
+ message: string;
739
+ }
740
+ interface ApiKeyFailure {
741
+ variant: 'api_key';
742
+ message: string;
743
+ }
744
+ interface UnknownFailure {
745
+ variant: 'unknown';
746
+ message: string;
747
+ }
748
+ interface CancelledFailure {
749
+ /**
750
+ * Operation was cancelled, typically by an AbortSignal from a controlling process (e.g., test runner pool).
751
+ */
752
+ variant: 'cancelled';
753
+ }
754
+
755
+ type RetryMode = {
756
+ mode: 'retry_on_partial_message';
757
+ errorSubstrings: string[];
758
+ } | {
759
+ mode: 'retry_all';
760
+ };
761
+ type RetryParams = {
762
+ retryLimit: number;
763
+ delayMs: number;
764
+ showWarnOnRetry: boolean;
765
+ };
766
+ type RetryOptions = RetryMode & RetryParams;
767
+ declare function retryOnErrorIsSuccess<T>(fnToRetry: () => Promise<T>, retryOptions: RetryMode & Partial<RetryParams>): Promise<boolean>;
768
+ declare function retryOnError<T>(fnToRetry: () => Promise<T>, retryOptions: RetryMode & Partial<RetryParams>): Promise<T>;
769
+ /**
770
+ * Performs a deep comparison between two values to determine if they are equivalent.
771
+ *
772
+ * @param a The first value to compare.
773
+ * @param b The second value to compare.
774
+ * @param cache A WeakMap to handle circular references. Should not be provided by the caller.
775
+ * @returns `true` if the values are deeply equal, `false` otherwise.
776
+ */
777
+ declare function deepEquals(a: any, b: any, cache?: WeakMap<object, WeakSet<object>>): boolean;
778
+
779
+ interface TestDataEntry {
780
+ key: string;
781
+ value: string;
782
+ sensitive: boolean;
783
+ }
784
+ interface TestData {
785
+ data?: TestDataEntry[];
786
+ other?: string;
787
+ }
788
+ interface TestStepDefinition {
789
+ description: string;
790
+ checks: string[];
791
+ testData: TestData;
792
+ }
793
+ interface TestCaseDefinition {
794
+ url: string;
795
+ steps: TestStepDefinition[];
796
+ recipe?: Intent[];
797
+ }
798
+ type TestCaseResult = SuccessfulTestCaseResult | FailedTestCaseResult;
799
+ interface SuccessfulTestCaseResult {
800
+ passed: true;
801
+ recipe: Intent[];
802
+ }
803
+ interface FailedTestCaseResult {
804
+ passed: false;
805
+ failure: FailureDescriptor;
806
+ }
807
+
808
+ declare const createId: () => string;
809
+ declare const posthog: PostHog;
810
+ declare function getMachineId(): string;
811
+ declare function getCodebaseId(): string | undefined;
812
+ declare function sendTelemetry(eventName: string, properties: Record<string, any>): Promise<void>;
813
+
814
+ declare function buildDefaultBrowserAgentOptions({ agentOptions, browserOptions }: {
815
+ agentOptions: AgentOptions;
816
+ browserOptions: BrowserConnectorOptions;
817
+ }): {
818
+ agentOptions: AgentOptions;
819
+ browserOptions: BrowserConnectorOptions;
820
+ };
821
+
822
+ declare const logger: pino.Logger<never, boolean>;
823
+
824
+ export { Agent, AgentError, AgentMemory, BrowserAgent, BrowserConnector, BrowserProvider, DesktopConnector, Observation, WebHarness, allBrowserAgentRoles, buildDefaultBrowserAgentOptions, createAction, createId, deepEquals, getCodebaseId, getMachineId, logger, mergeMessages, posthog, retryOnError, retryOnErrorIsSuccess, sendTelemetry, startBrowserAgent };
825
+ export type { ActOptions, Action, ActionDefinition, ActionIntent, ActionPayload, AgentConnector, AgentErrorOptions, AgentEvents, AgentMemoryOptions, AgentOptions, AnthropicClient, ApiKeyFailure, AzureOpenAIClient, Base64Image, BedrockClient, BrowserAgentRole, BrowserConnectorOptions, BrowserConnectorStateData, BrowserFailure, BrowserOptions, BugDetectedFailure, BugSeverity, CancelledFailure, CheckIntent, ClaudeCodeClient, ClickIntent, ClickWebAction, DesktopConnectorOptions, DesktopInterface, FailedTestCaseResult, FailureDescriptor, GoogleAIClient, GoogleVertexClient, Intent, LLMClient, LLMClientIdentifier, MemoryRenderOptions, MisalignmentFailure, ModelUsage, NavigateWebAction, NetworkFailure, ObservableDataArray, ObservableDataObject, ObservableDataPrimitive, ObservationRetentionOptions, ObservationRole, ObservationSource, OpenAIClient, OpenAIGenericClient, PixelCoordinate, RateLimitFailure, RenderableContent, RetryMode, RetryOptions, RetryParams, ScrollIntent, ScrollWebAction, SerializedAgentMemory, SuccessfulTestCaseResult, SwitchTabIntent, SwitchTabWebAction, TestCaseDefinition, TestCaseResult, TestData, TestDataEntry, TestStepDefinition, TypeIntent, TypeWebAction, UnknownFailure, WebAction, WebHarnessEvents, WebHarnessOptions };