@airtop/sdk 1.0.0-alpha2.3 → 1.0.0-alpha2.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -9,7 +9,7 @@ var require_package = __commonJS({
9
9
  module.exports = {
10
10
  name: "@airtop/sdk",
11
11
  description: "Airtop SDK for TypeScript",
12
- version: "1.0.0-alpha2.3",
12
+ version: "1.0.0-alpha2.31",
13
13
  type: "module",
14
14
  main: "./dist/index.cjs",
15
15
  module: "./dist/index.js",
@@ -38,34 +38,36 @@ var require_package = __commonJS({
38
38
  "agentic"
39
39
  ],
40
40
  scripts: {
41
- "build:second-stage": "tsup src/index.ts",
42
- "test:e2e": "vitest --run",
41
+ "test:e2e": "vitest --run --max-concurrency=1 --no-file-parallelism",
42
+ "test:e2e:parallel": "vitest --run",
43
43
  "build:dev": "node_modules/.bin/hash-runner",
44
+ build: "tsup src/index.ts",
44
45
  clean: "rm -rf .turbo node_modules dist",
45
- lint: "biome check --write --unsafe src && biome format src --write && biome lint src --fix",
46
- "verify-types": "tsc --noEmit"
46
+ lint: "biome check --no-errors-on-unmatched --write --unsafe src",
47
+ "lint:staged": "biome check --no-errors-on-unmatched --write --unsafe --staged src",
48
+ "verify-types": "tsc --noEmit && tsc --noEmit --project tsconfig.e2e.json"
47
49
  },
48
50
  dependencies: {
51
+ "@airtop/core": "0.1.0-alpha.42",
49
52
  "@airtop/json-schema-adapter": "workspace:*",
50
- "@airtop/core": "0.1.0-alpha.17",
51
53
  "date-fns": "4.1.0",
52
- loglayer: "6.3.3",
54
+ loglayer: "6.7.0",
53
55
  "serialize-error": "12.0.0",
54
56
  uuid: "11.1.0"
55
57
  },
56
58
  devDependencies: {
57
- "@biomejs/biome": "1.9.4",
58
- "@dotenvx/dotenvx": "1.39.0",
59
+ "@biomejs/biome": "2.2.4",
60
+ "@dotenvx/dotenvx": "1.49.1",
59
61
  "@internal/tsconfig": "workspace:*",
60
62
  "deep-utility-types": "1.3.1",
61
63
  "env-var": "7.5.0",
62
- "hash-runner": "2.0.1",
64
+ "hash-runner": "4.0.0",
63
65
  nanoid: "5.1.5",
64
- tsup: "8.4.0",
65
- typescript: "5.8.2",
66
+ tsup: "8.5.0",
67
+ typescript: "5.9.2",
66
68
  "utility-types": "3.11.0",
67
69
  uuid: "11.1.0",
68
- vitest: "3.1.1",
70
+ vitest: "3.2.4",
69
71
  zod: "*"
70
72
  },
71
73
  bugs: "https://github.com/airtop-ai/airtop-sdk/issues",
@@ -79,13 +81,24 @@ var require_package = __commonJS({
79
81
  optionalDependencies: {
80
82
  "@airtop/json-schema-adapter-zod": "workspace:*"
81
83
  },
82
- packageManager: "pnpm@10.5.0"
84
+ packageManager: "pnpm@10.17.0"
83
85
  };
84
86
  }
85
87
  });
86
88
 
89
+ // src/index.ts
90
+ import * as AirtopCore4 from "@airtop/core/resources/index.js";
91
+ import * as AirtopCoreShared from "@airtop/core/resources/shared.mjs";
92
+ import * as AirtopCoreWindows from "@airtop/core/resources/windows.js";
93
+
87
94
  // src/AirtopBase.ts
88
95
  import { secondsToMilliseconds } from "date-fns";
96
+
97
+ // src/constants.ts
98
+ var TIMEOUT_SECONDS_DEFAULT_VALUE = 300;
99
+ var DEFAULT_POLLING_INTERVAL_MS = 500;
100
+
101
+ // src/AirtopBase.ts
89
102
  var AirtopBase = class {
90
103
  /**
91
104
  * Logger instance for the SDK
@@ -102,6 +115,21 @@ var AirtopBase = class {
102
115
  * @internal
103
116
  **/
104
117
  outputJsonAdapter;
118
+ /**
119
+ * The job id for the ongoing automation
120
+ * @internal
121
+ */
122
+ jobId;
123
+ /**
124
+ * Instance for sending agent events
125
+ * @internal
126
+ */
127
+ agentEventPublisher;
128
+ /**
129
+ * The default timeout in seconds for API requests.
130
+ * @internal
131
+ */
132
+ defaultTimeoutInSeconds;
105
133
  /**
106
134
  * Creates a new instance of AirtopBase
107
135
  * @param config - Configuration options for the SDK
@@ -110,6 +138,29 @@ var AirtopBase = class {
110
138
  this.log = config.log.withPrefix("[Airtop]");
111
139
  this.client = config.client;
112
140
  this.outputJsonAdapter = config.outputSchemaAdapter;
141
+ this.jobId = config.jobId;
142
+ this.defaultTimeoutInSeconds = config.defaultTimeoutInSeconds ?? TIMEOUT_SECONDS_DEFAULT_VALUE;
143
+ if (config.agentEventPublisher) {
144
+ this.agentEventPublisher = config.agentEventPublisher;
145
+ }
146
+ }
147
+ /**
148
+ * Sets the publisher for sending agent events. Internal use only.
149
+ * @internal
150
+ */
151
+ _setAgentEventPublisher(logger) {
152
+ this.agentEventPublisher = logger;
153
+ }
154
+ /**
155
+ * Sends a payload to the agent with the specified event name.
156
+ * @param eventName The name of the event
157
+ * @param payload The payload to send to the agent
158
+ * @internal
159
+ */
160
+ _sendAgentPayload(eventName, payload) {
161
+ if (this.agentEventPublisher) {
162
+ this.agentEventPublisher.withMetadata(payload).info(eventName);
163
+ }
113
164
  }
114
165
  /**
115
166
  * Returns the API key used by the SDK
@@ -163,7 +214,10 @@ var AirtopBase = class {
163
214
  getCommonConfig() {
164
215
  return {
165
216
  client: this.client,
166
- log: this.log
217
+ log: this.log,
218
+ jobId: this.jobId,
219
+ outputSchemaAdapter: this.outputJsonAdapter,
220
+ agentEventPublisher: this.agentEventPublisher
167
221
  };
168
222
  }
169
223
  /**
@@ -174,7 +228,7 @@ var AirtopBase = class {
174
228
  */
175
229
  resolveRequestOptions(options = {}) {
176
230
  return {
177
- timeout: secondsToMilliseconds(options.timeoutInSeconds || 60),
231
+ timeout: secondsToMilliseconds(options.timeoutInSeconds || this.defaultTimeoutInSeconds),
178
232
  maxRetries: options.maxRetries || 0,
179
233
  signal: options.abortSignal
180
234
  };
@@ -183,10 +237,94 @@ var AirtopBase = class {
183
237
 
184
238
  // src/AirtopClient.ts
185
239
  import { Airtop as AirtopCore } from "@airtop/core";
186
- import { minutesToMilliseconds } from "date-fns/minutesToMilliseconds";
240
+ import { secondsToMilliseconds as secondsToMilliseconds3 } from "date-fns/secondsToMilliseconds";
187
241
  import { ConsoleTransport, LogLayer } from "loglayer";
188
242
  import { serializeError } from "serialize-error";
189
243
 
244
+ // src/file/AirtopFileClient.ts
245
+ var AirtopFileClient = class extends AirtopBase {
246
+ /**
247
+ * The file id
248
+ * @internal
249
+ */
250
+ fileId;
251
+ /**
252
+ * Creates a new AirtopFileClient instance.
253
+ * @param config - Common configuration options
254
+ * @param fileId - File id
255
+ */
256
+ constructor(config, fileId) {
257
+ super(config);
258
+ this.log = this.log.child().withContext({
259
+ fileId
260
+ });
261
+ this.fileId = fileId;
262
+ }
263
+ /**
264
+ * Gets a file by ID.
265
+ * @param requestOptions
266
+ * @returns AirtopFile instance
267
+ */
268
+ async getFile(requestOptions = {}) {
269
+ const results = await this.client.files.get(this.fileId, this.resolveRequestOptions(requestOptions));
270
+ return new AirtopFile(this.getCommonConfig(), results);
271
+ }
272
+ /**
273
+ * Removes a file by ID.
274
+ * @param requestOptions - Request options
275
+ */
276
+ async removeFile(requestOptions = {}) {
277
+ return this.client.files.delete(this.fileId, this.resolveRequestOptions(requestOptions));
278
+ }
279
+ };
280
+
281
+ // src/file/AirtopFile.ts
282
+ var AirtopFile = class extends AirtopFileClient {
283
+ /**
284
+ * The file data containing details such as the id, file name, type, and download URL.
285
+ * Includes all information about the file that was processed or retrieved.
286
+ */
287
+ data;
288
+ /**
289
+ * The metadata associated with the file operation.
290
+ * Contains information about the request that processed the file.
291
+ */
292
+ meta;
293
+ /**
294
+ * Warnings that occurred during file processing or operation.
295
+ * These are non-fatal issues that didn't prevent file processing.
296
+ */
297
+ warnings;
298
+ /**
299
+ * Errors that occurred during file processing or operation.
300
+ * These are fatal issues that prevented file processing.
301
+ */
302
+ errors;
303
+ /**
304
+ * Creates a new AirtopFile instance.
305
+ * @param config - Common configuration options for the file
306
+ * @param fileData - File data
307
+ */
308
+ constructor(config, fileData) {
309
+ super(config, fileData.data.id);
310
+ this.meta = fileData.meta;
311
+ this.data = fileData.data;
312
+ this.warnings = fileData.warnings;
313
+ this.errors = fileData.errors;
314
+ }
315
+ /**
316
+ * Returns response data as a JSON object.
317
+ */
318
+ toJSON() {
319
+ return {
320
+ data: this.data,
321
+ meta: this.meta,
322
+ warnings: this.warnings,
323
+ errors: this.errors
324
+ };
325
+ }
326
+ };
327
+
190
328
  // src/logger-utils.ts
191
329
  var processLogMessage = (log, logLevel, ...args) => {
192
330
  if (logLevel === "off") {
@@ -234,9 +372,166 @@ var processLogMessage = (log, logLevel, ...args) => {
234
372
  // src/session/AirtopSessionClient.ts
235
373
  import { NotFoundError } from "@airtop/core";
236
374
 
237
- // src/window/AirtopWindowClient.ts
375
+ // src/async-utils.ts
238
376
  import { secondsToMilliseconds as secondsToMilliseconds2 } from "date-fns";
239
377
 
378
+ // src/types.ts
379
+ var AirtopError = class extends Error {
380
+ issues;
381
+ metadata;
382
+ constructor(issues, metadata) {
383
+ const errorMessage = issues.map((issue) => issue.message).join("\n");
384
+ const errorMessageWithMetadata = metadata ? `${errorMessage}
385
+ ${JSON.stringify(metadata)}` : errorMessage;
386
+ super(errorMessageWithMetadata);
387
+ this.issues = issues;
388
+ this.metadata = metadata;
389
+ }
390
+ };
391
+
392
+ // src/async-utils.ts
393
+ async function waitForRequestCompletion(client, requestId, requestOptions) {
394
+ const startTime = Date.now();
395
+ const timeoutMs = secondsToMilliseconds2(requestOptions?.timeoutInSeconds || TIMEOUT_SECONDS_DEFAULT_VALUE);
396
+ while (Date.now() - startTime < timeoutMs) {
397
+ const apiResponse = await client.requests.getRequestStatusV2(requestId, requestOptions);
398
+ if (apiResponse.status === "completed") {
399
+ return apiResponse.response;
400
+ }
401
+ if (apiResponse.status === "error") {
402
+ throw new Error(apiResponse.error);
403
+ }
404
+ await new Promise((resolve) => setTimeout(resolve, DEFAULT_POLLING_INTERVAL_MS));
405
+ }
406
+ throw new Error("Waiting for request timed out");
407
+ }
408
+ async function withRequestCompletionPolling(client, fn, requestOptions) {
409
+ try {
410
+ const response = await fn();
411
+ return waitForRequestCompletion(client, response.requestId, requestOptions);
412
+ } catch (thrownError) {
413
+ if (thrownError.error?.errors) {
414
+ throw new AirtopError(thrownError.error.errors, {
415
+ requestId: thrownError.error.requestId
416
+ });
417
+ }
418
+ throw thrownError;
419
+ }
420
+ }
421
+
422
+ // src/window/AirtopNode.ts
423
+ var AirtopNode = class {
424
+ /**
425
+ * The window client
426
+ */
427
+ windowClient;
428
+ /**
429
+ * The node handle id to use for all requests
430
+ */
431
+ nodeHandleId;
432
+ /**
433
+ * The xpath selector of the node
434
+ */
435
+ selector;
436
+ /**
437
+ * Constructor
438
+ * @param client - The window client
439
+ * @param nodeData - The node data to use for all requests
440
+ */
441
+ constructor(client, nodeData) {
442
+ this.windowClient = client;
443
+ this.nodeHandleId = nodeData.id;
444
+ this.selector = nodeData.xpath;
445
+ }
446
+ /**
447
+ * Extract content from the node
448
+ * @param prompt - The prompt to use for the extraction
449
+ * @param config - The configuration to use for the extraction
450
+ * @param requestOptions - The request options to use for the extraction
451
+ */
452
+ async extract(prompt, config, requestOptions = {}) {
453
+ const augmentedConfig = {
454
+ ...config,
455
+ nodeHandleId: this.nodeHandleId
456
+ };
457
+ return this.windowClient.extract(prompt, augmentedConfig, requestOptions);
458
+ }
459
+ /**
460
+ * Act on the node
461
+ * @param prompt - The prompt to use for the action
462
+ * @param config - The configuration to use for the action
463
+ * @param requestOptions - The request options to use for the action
464
+ */
465
+ async act(prompt, config, requestOptions = {}) {
466
+ const augmentedConfig = {
467
+ ...config,
468
+ nodeHandleId: this.nodeHandleId
469
+ };
470
+ return this.windowClient.act(prompt, augmentedConfig, requestOptions);
471
+ }
472
+ /**
473
+ * Execute an LLM call on the node
474
+ * @param prompt - The prompt to use for the LLM call
475
+ * @param config - The configuration to use for the LLM call
476
+ * @param requestOptions - The request options to use for the LLM call
477
+ */
478
+ async llm(prompt, config, requestOptions = {}) {
479
+ return this.windowClient.llm(prompt, { ...config, nodeHandleId: this.nodeHandleId }, requestOptions);
480
+ }
481
+ /**
482
+ * Find one element in the node
483
+ * @param prompt - The prompt to use for the find one
484
+ * @param config - The configuration to use for the find one
485
+ * @param requestOptions - The request options to use for the find one
486
+ */
487
+ async findOne(prompt, config, requestOptions = {}) {
488
+ const augmentedConfig = {
489
+ ...config,
490
+ nodeHandleId: this.nodeHandleId
491
+ };
492
+ return this.windowClient.findOne(prompt, augmentedConfig, requestOptions);
493
+ }
494
+ /**
495
+ * Find one element in the node
496
+ * @param prompt - The prompt to use for the find one
497
+ * @param config - The configuration to use for the find one
498
+ * @param requestOptions - The request options to use for the find one
499
+ */
500
+ async findOneOptional(prompt, config, requestOptions = {}) {
501
+ const augmentedConfig = {
502
+ ...config,
503
+ nodeHandleId: this.nodeHandleId
504
+ };
505
+ return this.windowClient.findOneOptional(prompt, augmentedConfig, requestOptions);
506
+ }
507
+ /**
508
+ * Find many elements in the node
509
+ * @param prompt - The prompt to use for the find many
510
+ * @param config - The configuration to use for the find many
511
+ * @param requestOptions - The request options to use for the find many
512
+ */
513
+ async findMany(prompt, config, requestOptions = {}) {
514
+ const augmentedConfig = {
515
+ ...config,
516
+ nodeHandleId: this.nodeHandleId
517
+ };
518
+ return this.windowClient.findMany(prompt, augmentedConfig, requestOptions);
519
+ }
520
+ /**
521
+ * Find many elements in the node
522
+ * @param prompt - The prompt to use for the find many
523
+ * @param config - The configuration to use for the find many
524
+ * @param requestOptions - The request options to use for the find many
525
+ */
526
+ async findManyOptional(prompt, config, requestOptions = {}) {
527
+ const augmentedConfig = {
528
+ ...config,
529
+ nodeHandleId: this.nodeHandleId
530
+ };
531
+ return this.windowClient.findManyOptional(prompt, augmentedConfig, requestOptions);
532
+ }
533
+ };
534
+
240
535
  // src/window/AirtopWindowScreenshot.ts
241
536
  function extractMimeAndBase64(dataUrl) {
242
537
  const match = dataUrl.match(/^data:(image\/\w+);base64,(.+)$/);
@@ -336,6 +631,19 @@ var AirtopWindowClient = class extends AirtopBase {
336
631
  });
337
632
  this.windowId = windowId;
338
633
  this.sessionId = sessionId;
634
+ this.client.windows.get(
635
+ this.windowId,
636
+ {
637
+ sessionId: this.sessionId
638
+ },
639
+ this.resolveRequestOptions()
640
+ ).then((results) => {
641
+ this._sendAgentPayload("LiveViewUrl", {
642
+ liveViewUrl: results.data.liveViewUrl,
643
+ windowId: this.windowId,
644
+ sessionId: this.sessionId
645
+ });
646
+ });
339
647
  }
340
648
  /**
341
649
  * Gets the window ID.
@@ -377,17 +685,19 @@ var AirtopWindowClient = class extends AirtopBase {
377
685
  this.log.withMetadata({
378
686
  elementDescription
379
687
  }).info("Clicking on element");
380
- return this.client.windows.click(
381
- this.getWindowId(),
382
- {
383
- ...config,
384
- elementDescription,
385
- sessionId: this.sessionId
386
- },
387
- {
388
- timeout: secondsToMilliseconds2(600),
389
- ...this.resolveRequestOptions(requestOptions)
390
- }
688
+ return withRequestCompletionPolling(
689
+ this.client,
690
+ () => this.client.windows.clickAsync(
691
+ this.getWindowId(),
692
+ {
693
+ ...config,
694
+ elementDescription,
695
+ sessionId: this.sessionId
696
+ },
697
+ {
698
+ ...this.resolveRequestOptions(requestOptions)
699
+ }
700
+ )
391
701
  );
392
702
  }
393
703
  /**
@@ -409,17 +719,19 @@ var AirtopWindowClient = class extends AirtopBase {
409
719
  */
410
720
  async hover(elementDescription, config, requestOptions = {}) {
411
721
  this.log.withMetadata(config).info("Hovering over window");
412
- return this.client.windows.hover(
413
- this.getWindowId(),
414
- {
415
- elementDescription,
416
- sessionId: this.sessionId,
417
- ...config || {}
418
- },
419
- {
420
- timeout: secondsToMilliseconds2(600),
421
- ...this.resolveRequestOptions(requestOptions)
422
- }
722
+ return withRequestCompletionPolling(
723
+ this.client,
724
+ () => this.client.windows.hoverAsync(
725
+ this.getWindowId(),
726
+ {
727
+ elementDescription,
728
+ sessionId: this.sessionId,
729
+ ...config || {}
730
+ },
731
+ {
732
+ ...this.resolveRequestOptions(requestOptions)
733
+ }
734
+ )
423
735
  );
424
736
  }
425
737
  /**
@@ -441,7 +753,6 @@ var AirtopWindowClient = class extends AirtopBase {
441
753
  ...config
442
754
  },
443
755
  {
444
- timeout: secondsToMilliseconds2(600),
445
756
  ...this.resolveRequestOptions(requestOptions)
446
757
  }
447
758
  );
@@ -453,19 +764,33 @@ var AirtopWindowClient = class extends AirtopBase {
453
764
  * @param requestOptions - Request options
454
765
  * @returns Promise resolving to the monitoring operation result
455
766
  */
456
- async monitor(condition, config, requestOptions = {}) {
767
+ async monitor(condition, config = {}, requestOptions = {}) {
457
768
  this.log.withMetadata().info("Monitoring window");
458
- return this.client.windows.monitor(
459
- this.getWindowId(),
460
- {
461
- condition,
462
- sessionId: this.sessionId,
463
- ...config || {}
464
- },
465
- {
466
- timeout: secondsToMilliseconds2(600),
467
- ...this.resolveRequestOptions(requestOptions)
769
+ if (!config?.configuration?.interval?.timeoutSeconds) {
770
+ if (!config.configuration) {
771
+ config.configuration = {};
772
+ }
773
+ if (!config.configuration.interval) {
774
+ config.configuration.interval = {};
468
775
  }
776
+ config.configuration.interval.timeoutSeconds = this.defaultTimeoutInSeconds;
777
+ }
778
+ if (!config?.timeThresholdSeconds) {
779
+ config.timeThresholdSeconds = this.defaultTimeoutInSeconds;
780
+ }
781
+ return withRequestCompletionPolling(
782
+ this.client,
783
+ () => this.client.windows.monitorAsync(
784
+ this.getWindowId(),
785
+ {
786
+ condition,
787
+ sessionId: this.sessionId,
788
+ ...config || {}
789
+ },
790
+ {
791
+ ...this.resolveRequestOptions(requestOptions)
792
+ }
793
+ )
469
794
  );
470
795
  }
471
796
  /**
@@ -483,17 +808,19 @@ var AirtopWindowClient = class extends AirtopBase {
483
808
  if (config?.configuration.outputSchema) {
484
809
  newConfig.configuration.outputSchema = this.convertToJsonSchema(config.configuration.outputSchema);
485
810
  }
486
- return this.client.windows.pageQuery(
487
- this.getWindowId(),
488
- {
489
- sessionId: this.sessionId,
490
- prompt,
491
- ...newConfig || {}
492
- },
493
- {
494
- timeout: secondsToMilliseconds2(600),
495
- ...this.resolveRequestOptions(requestOptions)
496
- }
811
+ return withRequestCompletionPolling(
812
+ this.client,
813
+ () => this.client.windows.pageQueryAsync(
814
+ this.getWindowId(),
815
+ {
816
+ sessionId: this.sessionId,
817
+ prompt,
818
+ ...newConfig || {}
819
+ },
820
+ {
821
+ ...this.resolveRequestOptions(requestOptions)
822
+ }
823
+ )
497
824
  );
498
825
  }
499
826
  /**
@@ -511,17 +838,19 @@ var AirtopWindowClient = class extends AirtopBase {
511
838
  if (config?.configuration.outputSchema) {
512
839
  newConfig.configuration.outputSchema = this.convertToJsonSchema(config.configuration.outputSchema);
513
840
  }
514
- return this.client.windows.paginatedExtraction(
515
- this.getWindowId(),
516
- {
517
- prompt,
518
- sessionId: this.sessionId,
519
- ...newConfig || {}
520
- },
521
- {
522
- timeout: secondsToMilliseconds2(600),
523
- ...this.resolveRequestOptions(requestOptions)
524
- }
841
+ return withRequestCompletionPolling(
842
+ this.client,
843
+ () => this.client.windows.paginatedExtractionAsync(
844
+ this.getWindowId(),
845
+ {
846
+ prompt,
847
+ sessionId: this.sessionId,
848
+ ...newConfig || {}
849
+ },
850
+ {
851
+ ...this.resolveRequestOptions(requestOptions)
852
+ }
853
+ )
525
854
  );
526
855
  }
527
856
  /**
@@ -532,16 +861,18 @@ var AirtopWindowClient = class extends AirtopBase {
532
861
  */
533
862
  async scrape(config, requestOptions = {}) {
534
863
  this.log.info("Scraping window");
535
- return this.client.windows.scrape(
536
- this.getWindowId(),
537
- {
538
- sessionId: this.sessionId,
539
- ...config || {}
540
- },
541
- {
542
- timeout: secondsToMilliseconds2(600),
543
- ...this.resolveRequestOptions(requestOptions)
544
- }
864
+ return withRequestCompletionPolling(
865
+ this.client,
866
+ () => this.client.windows.scrapeAsync(
867
+ this.getWindowId(),
868
+ {
869
+ sessionId: this.sessionId,
870
+ ...config || {}
871
+ },
872
+ {
873
+ ...this.resolveRequestOptions(requestOptions)
874
+ }
875
+ )
545
876
  );
546
877
  }
547
878
  /**
@@ -552,16 +883,18 @@ var AirtopWindowClient = class extends AirtopBase {
552
883
  */
553
884
  async screenshot(config, requestOptions = {}) {
554
885
  this.log.info("Screenshotting window");
555
- const resp = await this.client.windows.screenshot(
556
- this.getWindowId(),
557
- {
558
- sessionId: this.sessionId,
559
- ...config || {}
560
- },
561
- {
562
- timeout: secondsToMilliseconds2(600),
563
- ...this.resolveRequestOptions(requestOptions)
564
- }
886
+ const resp = await withRequestCompletionPolling(
887
+ this.client,
888
+ () => this.client.windows.screenshotAsync(
889
+ this.getWindowId(),
890
+ {
891
+ sessionId: this.sessionId,
892
+ ...config || {}
893
+ },
894
+ {
895
+ ...this.resolveRequestOptions(requestOptions)
896
+ }
897
+ )
565
898
  );
566
899
  return new AirtopWindowScreenshot(resp);
567
900
  }
@@ -573,16 +906,18 @@ var AirtopWindowClient = class extends AirtopBase {
573
906
  */
574
907
  async scroll(config, requestOptions = {}) {
575
908
  this.log.info("Scrolling window");
576
- return this.client.windows.scroll(
577
- this.getWindowId(),
578
- {
579
- sessionId: this.sessionId,
580
- ...config || {}
581
- },
582
- {
583
- timeout: secondsToMilliseconds2(600),
584
- ...this.resolveRequestOptions(requestOptions)
585
- }
909
+ return withRequestCompletionPolling(
910
+ this.client,
911
+ () => this.client.windows.scrollAsync(
912
+ this.getWindowId(),
913
+ {
914
+ sessionId: this.sessionId,
915
+ ...config || {}
916
+ },
917
+ {
918
+ ...this.resolveRequestOptions(requestOptions)
919
+ }
920
+ )
586
921
  );
587
922
  }
588
923
  /**
@@ -596,17 +931,198 @@ var AirtopWindowClient = class extends AirtopBase {
596
931
  this.log.withMetadata({
597
932
  text
598
933
  }).info("Typing text");
599
- return this.client.windows.type(
600
- this.getWindowId(),
601
- {
602
- sessionId: this.sessionId,
603
- text,
604
- ...config || {}
605
- },
606
- {
607
- timeout: secondsToMilliseconds2(600),
608
- ...this.resolveRequestOptions(requestOptions)
934
+ return withRequestCompletionPolling(
935
+ this.client,
936
+ () => this.client.windows.typeAsync(
937
+ this.getWindowId(),
938
+ {
939
+ sessionId: this.sessionId,
940
+ text,
941
+ ...config || {}
942
+ },
943
+ {
944
+ ...this.resolveRequestOptions(requestOptions)
945
+ }
946
+ )
947
+ );
948
+ }
949
+ async extract(prompt, config, requestOptions = {}) {
950
+ this.log.withMetadata({ prompt }).info("Extracting content");
951
+ return withRequestCompletionPolling(
952
+ this.client,
953
+ () => this.client.windows.extract(
954
+ this.getWindowId(),
955
+ {
956
+ prompt,
957
+ sessionId: this.sessionId,
958
+ jobId: this.jobId,
959
+ ...config || {}
960
+ },
961
+ {
962
+ ...this.resolveRequestOptions(requestOptions)
963
+ }
964
+ )
965
+ );
966
+ }
967
+ async act(prompt, config, requestOptions = {}) {
968
+ this.log.withMetadata({ prompt }).info("Acting on content");
969
+ return withRequestCompletionPolling(
970
+ this.client,
971
+ () => this.client.windows.act(
972
+ this.getWindowId(),
973
+ {
974
+ prompt,
975
+ sessionId: this.sessionId,
976
+ jobId: this.jobId,
977
+ ...config || {}
978
+ },
979
+ {
980
+ ...this.resolveRequestOptions(requestOptions)
981
+ }
982
+ )
983
+ );
984
+ }
985
+ async llm(prompt, config, requestOptions = {}) {
986
+ this.log.withMetadata({ prompt }).info("Executing LLM call");
987
+ return withRequestCompletionPolling(
988
+ this.client,
989
+ () => this.client.windows.llm(
990
+ this.getWindowId(),
991
+ {
992
+ prompt,
993
+ sessionId: this.sessionId,
994
+ jobId: this.jobId,
995
+ ...config || {},
996
+ includeWebContext: true,
997
+ // Always include web context for window.llm() calls
998
+ outputSchema: config?.outputSchema ? this.convertToJsonSchema(config.outputSchema) : void 0
999
+ },
1000
+ {
1001
+ ...this.resolveRequestOptions(requestOptions)
1002
+ }
1003
+ )
1004
+ );
1005
+ }
1006
+ async findOnePrivate(prompt, config, requestOptions = {}) {
1007
+ this.log.withMetadata({ prompt }).info("Executing LLM call");
1008
+ const apiResponse = await withRequestCompletionPolling(
1009
+ this.client,
1010
+ () => this.client.windows.findOne(
1011
+ this.getWindowId(),
1012
+ {
1013
+ prompt,
1014
+ sessionId: this.sessionId,
1015
+ jobId: this.jobId,
1016
+ ...config || {}
1017
+ },
1018
+ {
1019
+ ...this.resolveRequestOptions(requestOptions)
1020
+ }
1021
+ )
1022
+ );
1023
+ if (apiResponse.errors.length > 0) {
1024
+ throw new AirtopError(apiResponse.errors);
1025
+ }
1026
+ try {
1027
+ if (!apiResponse.data.nodeHandle) {
1028
+ return null;
609
1029
  }
1030
+ return new AirtopNode(this, apiResponse.data.nodeHandle);
1031
+ } catch (error) {
1032
+ this.log.withMetadata({ nodeDataStr: apiResponse.data.nodeHandle }).withError(error).error("Error parsing node data");
1033
+ throw error;
1034
+ }
1035
+ }
1036
+ async findOne(prompt, config, requestOptions = {}) {
1037
+ const configOverride = { ...config, optional: false };
1038
+ return await this.findOnePrivate(prompt, configOverride, requestOptions);
1039
+ }
1040
+ async findOneOptional(prompt, config, requestOptions = {}) {
1041
+ const configOverride = { ...config, optional: true };
1042
+ return await this.findOnePrivate(prompt, configOverride, requestOptions);
1043
+ }
1044
+ async findManyPrivate(prompt, config, requestOptions = {}) {
1045
+ this.log.withMetadata({ prompt }).info("Executing LLM call");
1046
+ const apiResponse = await withRequestCompletionPolling(
1047
+ this.client,
1048
+ () => this.client.windows.findMany(
1049
+ this.getWindowId(),
1050
+ {
1051
+ prompt,
1052
+ sessionId: this.sessionId,
1053
+ jobId: this.jobId,
1054
+ ...config || {}
1055
+ },
1056
+ {
1057
+ ...this.resolveRequestOptions(requestOptions)
1058
+ }
1059
+ )
1060
+ );
1061
+ if (apiResponse.errors.length > 0) {
1062
+ throw new AirtopError(apiResponse.errors);
1063
+ }
1064
+ const nodeHandleData = apiResponse.data.nodeHandles;
1065
+ return nodeHandleData.map((nodeHandle) => new AirtopNode(this, nodeHandle));
1066
+ }
1067
+ async findMany(prompt, config, requestOptions = {}) {
1068
+ const configOverride = { ...config, optional: false };
1069
+ return await this.findManyPrivate(prompt, configOverride, requestOptions);
1070
+ }
1071
+ async findManyOptional(prompt, config, requestOptions = {}) {
1072
+ const configOverride = { ...config, optional: true };
1073
+ return await this.findManyPrivate(prompt, configOverride, requestOptions);
1074
+ }
1075
+ async waitForPage(config, requestOptions = {}) {
1076
+ return await withRequestCompletionPolling(
1077
+ this.client,
1078
+ () => this.client.windows.waitForPage(
1079
+ this.getWindowId(),
1080
+ {
1081
+ sessionId: this.sessionId,
1082
+ jobId: this.jobId,
1083
+ ...config || {}
1084
+ },
1085
+ {
1086
+ ...this.resolveRequestOptions(requestOptions)
1087
+ }
1088
+ )
1089
+ );
1090
+ }
1091
+ async navigate(direction, config, requestOptions = {}) {
1092
+ return await withRequestCompletionPolling(
1093
+ this.client,
1094
+ () => this.client.windows.navigate(
1095
+ this.getWindowId(),
1096
+ {
1097
+ direction,
1098
+ sessionId: this.sessionId,
1099
+ jobId: this.jobId,
1100
+ ...config || {}
1101
+ },
1102
+ {
1103
+ ...this.resolveRequestOptions(requestOptions)
1104
+ }
1105
+ )
1106
+ );
1107
+ }
1108
+ async fillForm(formData, config, requestOptions = {}) {
1109
+ return await withRequestCompletionPolling(
1110
+ this.client,
1111
+ () => this.client.windows.executeAutomation(
1112
+ this.getWindowId(),
1113
+ {
1114
+ sessionId: this.sessionId,
1115
+ ...config || {},
1116
+ automationId: config?.automationId || "auto",
1117
+ parameters: {
1118
+ customData: typeof formData === "string" ? formData : JSON.stringify(formData)
1119
+ // Will be interpreted by the LLM
1120
+ }
1121
+ },
1122
+ {
1123
+ ...this.resolveRequestOptions(requestOptions)
1124
+ }
1125
+ )
610
1126
  );
611
1127
  }
612
1128
  };
@@ -665,7 +1181,7 @@ var AirtopSessionClient = class extends AirtopBase {
665
1181
  */
666
1182
  sessionId;
667
1183
  /**
668
- * Creates a new AirtopSession instance.
1184
+ * Creates a new AirtopSessionClient instance.
669
1185
  * @param config - Common configuration options for the session
670
1186
  * @param sessionId - Browser session id
671
1187
  */
@@ -682,6 +1198,9 @@ var AirtopSessionClient = class extends AirtopBase {
682
1198
  getSessionId() {
683
1199
  return this.sessionId;
684
1200
  }
1201
+ async listWindows(requestOptions = {}) {
1202
+ return this.client.sessions.listWindows(this.sessionId, this.resolveRequestOptions(requestOptions));
1203
+ }
685
1204
  /**
686
1205
  * Gets the state of the session using the attached session id.
687
1206
  * @param requestOptions - Request options
@@ -751,15 +1270,29 @@ var AirtopSessionClient = class extends AirtopBase {
751
1270
  * @param requestOptions - Request options
752
1271
  * @returns A new AirtopWindow<AirtopWindowCreateResponse> instance
753
1272
  */
754
- async createWindow(url, requestOptions = {}) {
1273
+ async createWindow(url, createOptions = {}, requestOptions = {}) {
755
1274
  this.log.info("Creating window");
756
1275
  const results = await this.client.windows.create(
757
1276
  this.sessionId,
758
1277
  {
759
- url
1278
+ url,
1279
+ ...createOptions
760
1280
  },
761
1281
  this.resolveRequestOptions(requestOptions)
762
1282
  );
1283
+ this.client.windows.get(
1284
+ results.data.windowId,
1285
+ {
1286
+ sessionId: this.sessionId
1287
+ },
1288
+ this.resolveRequestOptions()
1289
+ ).then((windowResults) => {
1290
+ this._sendAgentPayload("LiveViewUrl", {
1291
+ liveViewUrl: windowResults.data.liveViewUrl,
1292
+ windowId: results.data.windowId,
1293
+ sessionId: this.sessionId
1294
+ });
1295
+ });
763
1296
  return new AirtopWindow(this.getCommonConfig(), this.sessionId, results);
764
1297
  }
765
1298
  /**
@@ -775,17 +1308,146 @@ var AirtopSessionClient = class extends AirtopBase {
775
1308
  * @param fileName - The name of the file to create
776
1309
  * @param config - Additional configuration options for creating the file
777
1310
  * @param requestOptions - Request options
1311
+ * @returns AirtopFile instance
778
1312
  */
779
- createFile(fileName, config = {}, requestOptions = {}) {
1313
+ async createFile(fileName, config = {}, requestOptions = {}) {
780
1314
  this.log.info("Creating file");
781
- return this.client.files.createFile(
1315
+ const results = await this.client.files.createFile(
782
1316
  {
783
1317
  ...config,
784
1318
  fileName,
785
- sessionId: this.sessionId
1319
+ sessionIds: [this.sessionId]
786
1320
  },
787
1321
  this.resolveRequestOptions(requestOptions)
788
1322
  );
1323
+ return new AirtopFile(this.getCommonConfig(), results);
1324
+ }
1325
+ async llm(prompt, config, requestOptions = {}) {
1326
+ this.log.withMetadata({ prompt }).info("Executing LLM call");
1327
+ const currentWindows = await this.listWindows();
1328
+ if (currentWindows.data.windows.length === 0) {
1329
+ throw new AirtopError([
1330
+ {
1331
+ message: "No windows found in the session. Please create a window before calling the llm() method."
1332
+ }
1333
+ ]);
1334
+ }
1335
+ const firstWindow = currentWindows.data.windows[0];
1336
+ return withRequestCompletionPolling(
1337
+ this.client,
1338
+ () => this.client.windows.llm(
1339
+ firstWindow.windowId,
1340
+ {
1341
+ prompt,
1342
+ sessionId: this.sessionId,
1343
+ jobId: this.jobId,
1344
+ ...config || {},
1345
+ includeWebContext: false,
1346
+ // Do not include web context for session.llm() calls
1347
+ outputSchema: config?.outputSchema ? this.convertToJsonSchema(config.outputSchema) : void 0
1348
+ },
1349
+ {
1350
+ ...this.resolveRequestOptions(requestOptions)
1351
+ }
1352
+ )
1353
+ );
1354
+ }
1355
+ /**
1356
+ * Implementation for the overloaded service method.
1357
+ */
1358
+ async service(promptOrArgs, serviceOrRequestOptions, requestOptions = {}) {
1359
+ if (typeof promptOrArgs === "string") {
1360
+ const prompt = promptOrArgs;
1361
+ const service = typeof serviceOrRequestOptions === "string" ? serviceOrRequestOptions : void 0;
1362
+ const options2 = typeof serviceOrRequestOptions === "object" ? serviceOrRequestOptions : requestOptions;
1363
+ this.log.withMetadata({ prompt }).info("Service");
1364
+ const parameters2 = { prompt, services: service };
1365
+ const body2 = { parameters: parameters2 };
1366
+ return withRequestCompletionPolling(
1367
+ this.client,
1368
+ () => this.client.sessions.service(this.sessionId, body2),
1369
+ options2
1370
+ );
1371
+ }
1372
+ const parameters = promptOrArgs;
1373
+ const options = serviceOrRequestOptions || {};
1374
+ this.log.withMetadata({ parameters }).info("Service");
1375
+ const body = {
1376
+ parameters: {
1377
+ prompt: parameters.prompt,
1378
+ services: parameters.services,
1379
+ outputSchema: parameters.outputSchema ? this.convertToJsonSchema(parameters.outputSchema) : void 0
1380
+ }
1381
+ };
1382
+ return withRequestCompletionPolling(
1383
+ this.client,
1384
+ () => this.client.sessions.service(this.sessionId, body),
1385
+ options
1386
+ );
1387
+ }
1388
+ /**
1389
+ * Retrieves the list of connected services available for the current session.
1390
+ * @param requestOptions - Request options
1391
+ * @returns A promise that resolves to the connected services response containing service details
1392
+ */
1393
+ async getConnectedServices(requestOptions = {}) {
1394
+ return withRequestCompletionPolling(
1395
+ this.client,
1396
+ () => this.client.sessions.getConnectedServices(this.sessionId),
1397
+ requestOptions
1398
+ );
1399
+ }
1400
+ /**
1401
+ * Waits for a file to be downloaded in a session and reach 'available' status.
1402
+ * Defaults to looking back 5 seconds in the event stream for the file to be available.
1403
+ * Use `lookbackSeconds` to control this behavior.
1404
+ *
1405
+ * @param configuration - The optional configuration parameters for the function
1406
+ * @param configuration.lookbackSeconds - The number of seconds to look back for prior events. Default `5`. 0 means no lookback.
1407
+ * @param requestOptions - Optional request configuration including timeout
1408
+ * @returns Object containing file's id and downloadUrl, or null if timed out
1409
+ */
1410
+ async waitForDownload(configuration, requestOptions = {}) {
1411
+ const { lookbackSeconds = 5 } = configuration || {};
1412
+ this.log.info(`waiting for file to be available on session: ${this.sessionId}`);
1413
+ const startTime = /* @__PURE__ */ new Date();
1414
+ const timeoutSeconds = requestOptions?.timeoutInSeconds || 120;
1415
+ const timeoutPromise = new Promise((resolve) => {
1416
+ setTimeout(() => {
1417
+ this.log.info(`waiting for file timed out after ${timeoutSeconds} seconds`);
1418
+ resolve(null);
1419
+ }, timeoutSeconds * 1e3);
1420
+ });
1421
+ const processEventsPromise = (async () => {
1422
+ const sessionEvents = await this.client.sessions.getEvents(
1423
+ this.sessionId,
1424
+ { all: lookbackSeconds >= 0 },
1425
+ { timeoutInSeconds: timeoutSeconds, ...requestOptions || {} }
1426
+ );
1427
+ for await (const event of sessionEvents) {
1428
+ const e = event;
1429
+ if (e.event === "file_status") {
1430
+ if (e.status === "available") {
1431
+ const eventTime = Date.parse(e.eventTime);
1432
+ this.log.info(`file_status message received:
1433
+ ${JSON.stringify(event, null, 2)}`);
1434
+ const thresholdTime = startTime.getTime() - lookbackSeconds * 1e3;
1435
+ if (eventTime < thresholdTime) {
1436
+ this.log.info(
1437
+ `skipping file available event for ${e.fileId} because its timestamp is earlier than lookbackSeconds`
1438
+ );
1439
+ continue;
1440
+ }
1441
+ return {
1442
+ id: e.fileId,
1443
+ downloadUrl: e.downloadUrl
1444
+ };
1445
+ }
1446
+ }
1447
+ }
1448
+ return null;
1449
+ })();
1450
+ return Promise.race([timeoutPromise, processEventsPromise]);
789
1451
  }
790
1452
  };
791
1453
 
@@ -848,7 +1510,7 @@ var AirtopClient = class extends AirtopBase {
848
1510
  logLevel: config?.logLevel,
849
1511
  client: new AirtopCore({
850
1512
  maxRetries: 0,
851
- timeout: minutesToMilliseconds(1),
1513
+ timeout: secondsToMilliseconds3(config.defaultTimeoutInSeconds ?? TIMEOUT_SECONDS_DEFAULT_VALUE),
852
1514
  apiKey: config.apiKey,
853
1515
  baseURL: config?.airtopUrl,
854
1516
  logLevel: config?.logLevel || "off",
@@ -868,7 +1530,10 @@ var AirtopClient = class extends AirtopBase {
868
1530
  contextFieldName: "context",
869
1531
  metadataFieldName: "metadata"
870
1532
  }),
871
- outputSchemaAdapter: config.outputSchemaAdapter
1533
+ outputSchemaAdapter: config.outputSchemaAdapter,
1534
+ jobId: config.jobId,
1535
+ agentEventPublisher: config.agentEventPublisher,
1536
+ defaultTimeoutInSeconds: config.defaultTimeoutInSeconds ?? TIMEOUT_SECONDS_DEFAULT_VALUE
872
1537
  });
873
1538
  this.log.withPrefix("[Airtop SDK]");
874
1539
  this.client.logLevel = config.logLevel;
@@ -894,8 +1559,8 @@ var AirtopClient = class extends AirtopBase {
894
1559
  * @returns A new AirtopSession instance
895
1560
  */
896
1561
  async createSession(config, options = {}) {
897
- const skipWaitSessionReady = config.skipWaitSessionReady ?? false;
898
- delete config.skipWaitSessionReady;
1562
+ const skipWaitSessionReady = config?.skipWaitSessionReady ?? false;
1563
+ delete config?.skipWaitSessionReady;
899
1564
  const sessionResponse = await this.client.sessions.create(
900
1565
  {
901
1566
  configuration: config
@@ -983,6 +1648,13 @@ var AirtopClient = class extends AirtopBase {
983
1648
  withSessionId(sessionId) {
984
1649
  return new AirtopSessionClient(this.getCommonConfig(), sessionId);
985
1650
  }
1651
+ /**
1652
+ * Returns a file client instance for making file-based requests for a given file id.
1653
+ * @param fileId - The file ID to attach to the AirtopFileClient instance
1654
+ */
1655
+ withFileId(fileId) {
1656
+ return new AirtopFileClient(this.getCommonConfig(), fileId);
1657
+ }
986
1658
  /**
987
1659
  * Retrieves the status of a request.
988
1660
  * @param requestId - ID of the request to check
@@ -996,20 +1668,24 @@ var AirtopClient = class extends AirtopBase {
996
1668
  return this.client.requests.getRequestStatus(requestId, this.resolveRequestOptions(requestOptions));
997
1669
  }
998
1670
  /**
999
- * Gets a file by ID.
1000
- * @param fileId
1001
- * @param requestOptions
1002
- */
1003
- async getFile(fileId, requestOptions = {}) {
1004
- return this.client.files.get(fileId, this.resolveRequestOptions(requestOptions));
1005
- }
1006
- /**
1007
- * Removes a file by ID.
1008
- * @param fileId - ID of the file to remove
1671
+ * List files
1672
+ * @param query - File list parameters
1009
1673
  * @param requestOptions - Request options
1674
+ * @returns Object containing pagination info and array of AirtopFile instances
1010
1675
  */
1011
- async removeFile(fileId, requestOptions = {}) {
1012
- return this.client.files.delete(fileId, this.resolveRequestOptions(requestOptions));
1676
+ async listFiles(query, requestOptions = {}) {
1677
+ const files = await this.client.files.list(query, this.resolveRequestOptions(requestOptions));
1678
+ return {
1679
+ pagination: files.data.pagination,
1680
+ files: files.data.files.map(
1681
+ (file) => new AirtopFile(this.getCommonConfig(), {
1682
+ data: file
1683
+ })
1684
+ ),
1685
+ errors: files.errors,
1686
+ meta: files.meta,
1687
+ warnings: files.warnings
1688
+ };
1013
1689
  }
1014
1690
  /**
1015
1691
  * List all automations
@@ -1036,43 +1712,6 @@ var AirtopClient = class extends AirtopBase {
1036
1712
  }
1037
1713
  };
1038
1714
 
1039
- // src/plugin/AirtopPlugin.types.ts
1040
- var AirtopPluginAugmentationType = /* @__PURE__ */ ((AirtopPluginAugmentationType2) => {
1041
- AirtopPluginAugmentationType2["AirtopClient"] = "AirtopClient";
1042
- AirtopPluginAugmentationType2["AirtopWindowClient"] = "AirtopWindowClient";
1043
- AirtopPluginAugmentationType2["AirtopWindow"] = "AirtopWindow";
1044
- AirtopPluginAugmentationType2["AirtopSessionClient"] = "AirtopSessionClient";
1045
- AirtopPluginAugmentationType2["AirtopSession"] = "AirtopSession";
1046
- AirtopPluginAugmentationType2["AirtopWindowScreenshot"] = "AirtopWindowScreenshot";
1047
- return AirtopPluginAugmentationType2;
1048
- })(AirtopPluginAugmentationType || {});
1049
-
1050
- // src/plugin/AirtopPlugin.ts
1051
- function registerAirtopPlugin(plugin) {
1052
- for (const pluginToAdd of plugin.pluginsToAdd) {
1053
- switch (pluginToAdd.augmentationType) {
1054
- case "AirtopClient" /* AirtopClient */:
1055
- pluginToAdd.augment(AirtopClient.prototype);
1056
- break;
1057
- case "AirtopSessionClient" /* AirtopSessionClient */:
1058
- pluginToAdd.augment(AirtopSessionClient.prototype);
1059
- break;
1060
- case "AirtopSession" /* AirtopSession */:
1061
- pluginToAdd.augment(AirtopSession.prototype);
1062
- break;
1063
- case "AirtopWindowClient" /* AirtopWindowClient */:
1064
- pluginToAdd.augment(AirtopWindowClient.prototype);
1065
- break;
1066
- case "AirtopWindow" /* AirtopWindow */:
1067
- pluginToAdd.augment(AirtopWindow.prototype);
1068
- break;
1069
- case "AirtopWindowScreenshot" /* AirtopWindowScreenshot */:
1070
- pluginToAdd.augment(AirtopWindowScreenshot.prototype);
1071
- break;
1072
- }
1073
- }
1074
- }
1075
-
1076
1715
  // src/AirtopMocks.ts
1077
1716
  import { Airtop as AirtopCore2 } from "@airtop/core";
1078
1717
  import { MockLogLayer } from "loglayer";
@@ -1163,16 +1802,276 @@ var AirtopMocks = class {
1163
1802
  });
1164
1803
  }
1165
1804
  };
1805
+
1806
+ // src/agent/AirtopAgentClient.ts
1807
+ import { version as version2 } from "process";
1808
+ import { Airtop as AirtopCore3 } from "@airtop/core";
1809
+ import { minutesToMilliseconds } from "date-fns";
1810
+ import { ConsoleTransport as ConsoleTransport2, LogLayer as LogLayer2 } from "loglayer";
1811
+ import { serializeError as serializeError2 } from "serialize-error";
1812
+ var AirtopAgentClient = class extends AirtopBase {
1813
+ /**
1814
+ * Creates a new instance of the Airtop SDK.
1815
+ * @param config - Configuration options for the Airtop SDK
1816
+ */
1817
+ constructor(config) {
1818
+ super({
1819
+ logLevel: config?.logLevel,
1820
+ client: new AirtopCore3({
1821
+ maxRetries: 0,
1822
+ timeout: minutesToMilliseconds(1),
1823
+ apiKey: config.apiKey,
1824
+ baseURL: config?.airtopUrl,
1825
+ logLevel: config?.logLevel || "off",
1826
+ defaultHeaders: {
1827
+ "x-airtop-sdk-source": "typescript",
1828
+ "x-airtop-sdk-version": version2
1829
+ }
1830
+ }),
1831
+ log: config?.logger || new LogLayer2({
1832
+ errorSerializer: serializeError2,
1833
+ transport: new ConsoleTransport2({
1834
+ logger: console,
1835
+ messageField: "message",
1836
+ enabled: config.logLevel !== "off",
1837
+ level: config.logLevel === "off" ? "error" : config.logLevel || "error"
1838
+ }),
1839
+ contextFieldName: "context",
1840
+ metadataFieldName: "metadata"
1841
+ }),
1842
+ outputSchemaAdapter: config.outputSchemaAdapter,
1843
+ jobId: config.jobId
1844
+ });
1845
+ this.log.withPrefix("[Airtop SDK]");
1846
+ this.client.logLevel = config.logLevel;
1847
+ this.client.logger = {
1848
+ debug: (message, ...rest) => {
1849
+ processLogMessage(this.log, "debug", message, rest);
1850
+ },
1851
+ error: (message, ...rest) => {
1852
+ processLogMessage(this.log, "error", message, rest);
1853
+ },
1854
+ info: (message, ...rest) => {
1855
+ processLogMessage(this.log, "info", message, rest);
1856
+ },
1857
+ warn: (message, ...rest) => {
1858
+ processLogMessage(this.log, "warn", message, rest);
1859
+ }
1860
+ };
1861
+ }
1862
+ /**
1863
+ * Creates a new agent. A new draft version is created by default.
1864
+ * @param params - Parameters for creating the agent.
1865
+ * @param requestOptions - Request options.
1866
+ * @returns The created agent data.
1867
+ */
1868
+ async createAgent(params, requestOptions = {}) {
1869
+ this.log.info("Creating agent");
1870
+ return this.client.agents.createAgent(params, this.resolveRequestOptions(requestOptions));
1871
+ }
1872
+ /**
1873
+ * Retrieves a specific agent by its ID.
1874
+ * @param agentId - The ID of the agent to retrieve.
1875
+ * @param requestOptions - Request options.
1876
+ * @returns The agent data.
1877
+ */
1878
+ async getAgent(agentId, params = {}, requestOptions = {}) {
1879
+ this.log.withMetadata({ agentId }).info("Retrieving agent");
1880
+ return this.client.agents.getAgent(agentId, params, this.resolveRequestOptions(requestOptions));
1881
+ }
1882
+ /**
1883
+ * Lists agents.
1884
+ * @param params - Optional parameters for listing agents (e.g., pagination).
1885
+ * @param requestOptions - Request options.
1886
+ * @returns A list of agents.
1887
+ */
1888
+ async listAgents(params, requestOptions = {}) {
1889
+ this.log.info("Listing agents");
1890
+ return this.client.agents.getAgents(params, this.resolveRequestOptions(requestOptions));
1891
+ }
1892
+ /**
1893
+ * Creates a new draft version of an agent. If one already exists, does nothing.
1894
+ * @param agentId - The ID of the agent for which to create a new draft version.
1895
+ * @param requestOptions - Request options.
1896
+ * @returns The draft version data.
1897
+ */
1898
+ async createNewAgentDraftVersion(agentId, requestOptions = {}) {
1899
+ this.log.withMetadata({ agentId }).info("Creating new draft version of agent");
1900
+ return this.client.agents.createAgentDraft(agentId, {}, this.resolveRequestOptions(requestOptions));
1901
+ }
1902
+ /**
1903
+ * Publishes a new version of an agent from the current draft.
1904
+ * @param agentId - The ID of the agent to publish.
1905
+ * @returns The published version data
1906
+ */
1907
+ async publishNewAgentVersion(agentId, params = {}, requestOptions = {}) {
1908
+ this.log.withMetadata({ agentId }).info("Publishing new version of agent");
1909
+ return this.client.agents.publishAgent(agentId, params, this.resolveRequestOptions(requestOptions));
1910
+ }
1911
+ /**
1912
+ * Retrieves the data for a specific version of an agent.
1913
+ * @param agentId - The ID of the agent.
1914
+ * @param version - The version number of the agent to retrieve.
1915
+ * @param requestOptions - Request options.
1916
+ * @returns The agent version data.
1917
+ */
1918
+ async getAgentVersionData(agentId, version3, requestOptions = {}) {
1919
+ this.log.withMetadata({ agentId }).info("Retrieving agent version data");
1920
+ return this.client.agents.getAgentVersion(
1921
+ version3,
1922
+ {
1923
+ id: agentId
1924
+ },
1925
+ this.resolveRequestOptions(requestOptions)
1926
+ );
1927
+ }
1928
+ async updateAgentVersionData(agentId, version3, params, requestOptions = {}) {
1929
+ this.log.withMetadata({ agentId }).info("Updating agent");
1930
+ return this.client.agents.updateAgentVersionData(
1931
+ version3,
1932
+ {
1933
+ id: agentId,
1934
+ ...params
1935
+ },
1936
+ this.resolveRequestOptions(requestOptions)
1937
+ );
1938
+ }
1939
+ /**
1940
+ * Retrieves the current version data of an agent. This is the version that is currently active or in draft state.
1941
+ * @param agentId - The ID of the agent.
1942
+ * @param params - Optional parameters for retrieving the version data.
1943
+ * @param requestOptions - Request options.
1944
+ * @returns The current agent version data
1945
+ */
1946
+ async getCurrentAgentVersionData(agentId, params, requestOptions = {}) {
1947
+ this.log.withMetadata({ agentId }).info("Retrieving current agent version data");
1948
+ return this.client.agents.getCurrentAgentVersion(agentId, params, this.resolveRequestOptions(requestOptions));
1949
+ }
1950
+ /**
1951
+ * Updates an existing agent.
1952
+ * @param agentId - The ID of the agent to update.
1953
+ * @param params - The new data for the agent.
1954
+ * @param requestOptions - Request options.
1955
+ * @returns The updated agent data.
1956
+ */
1957
+ async updateAgent(agentId, params, requestOptions = {}) {
1958
+ this.log.withMetadata({ agentId }).info("Updating agent");
1959
+ return this.client.agents.updateAgent(agentId, params, this.resolveRequestOptions(requestOptions));
1960
+ }
1961
+ /**
1962
+ * Deletes one or more agents.
1963
+ * @param params - Parameters for deleting agents.
1964
+ * @param requestOptions - Request options.
1965
+ * @returns A response confirming the deletion.
1966
+ */
1967
+ async deleteAgents(params, requestOptions = {}) {
1968
+ this.log.info("Deleting agent(s)");
1969
+ return this.client.agents.deleteAgents(params, this.resolveRequestOptions(requestOptions));
1970
+ }
1971
+ /**
1972
+ * Creates an invocation for an agent.
1973
+ * @param agentId - The ID of the agent for which to create an invocation.
1974
+ * @param params - Parameters for creating the agent invocation.
1975
+ * @param requestOptions - Request options.
1976
+ * @returns The created agent invocation data.
1977
+ */
1978
+ async createAgentInvocation(agentId, params, requestOptions = {}) {
1979
+ this.log.withMetadata({ agentId }).info("Creating agent invocation");
1980
+ return this.client.agents.createInvocation(agentId, params, this.resolveRequestOptions(requestOptions));
1981
+ }
1982
+ /**
1983
+ * Lists invocations of an agent.
1984
+ * @param agentIds - The ID of the agent whose invocations to list.
1985
+ * @param params - Optional parameters for listing agent invocations.
1986
+ * @param requestOptions - Request options.
1987
+ * @returns A list of agent invocations.
1988
+ */
1989
+ async listAgentInvocations(agentIds, params, requestOptions = {}) {
1990
+ this.log.withMetadata({ agentIds }).info("Listing agent invocations");
1991
+ return this.client.agents.getInvocations(agentIds, params, this.resolveRequestOptions(requestOptions));
1992
+ }
1993
+ /**
1994
+ * Cancels a specific invocation of an agent.
1995
+ * @param agentId - The ID of the agent.
1996
+ * @param invocationId - The ID of the invocation to cancel.
1997
+ * @param paramsBody - Optional body parameters for cancelling the invocation.
1998
+ * @param requestOptions - Request options.
1999
+ * @returns A promise that resolves when the operation is complete.
2000
+ */
2001
+ async cancelAgentInvocation(agentId, invocationId, paramsBody, requestOptions = {}) {
2002
+ this.log.withMetadata({ agentId, invocationId }).info("Cancelling agent invocation");
2003
+ const resolvedOptions = this.resolveRequestOptions(requestOptions);
2004
+ const finalOptions = { ...resolvedOptions };
2005
+ const params = { id: agentId, ...paramsBody };
2006
+ if (paramsBody) {
2007
+ finalOptions.body = paramsBody;
2008
+ }
2009
+ await this.client.agents.cancelInvocation(invocationId, params, finalOptions);
2010
+ }
2011
+ };
2012
+
2013
+ // src/window/AirtopWindowClient.types.ts
2014
+ var WindowNavigateDirection = /* @__PURE__ */ ((WindowNavigateDirection2) => {
2015
+ WindowNavigateDirection2["BACK"] = "backward";
2016
+ WindowNavigateDirection2["FORWARD"] = "forward";
2017
+ return WindowNavigateDirection2;
2018
+ })(WindowNavigateDirection || {});
2019
+
2020
+ // src/plugin/AirtopPlugin.types.ts
2021
+ var AirtopPluginAugmentationType = /* @__PURE__ */ ((AirtopPluginAugmentationType2) => {
2022
+ AirtopPluginAugmentationType2["AirtopClient"] = "AirtopClient";
2023
+ AirtopPluginAugmentationType2["AirtopWindowClient"] = "AirtopWindowClient";
2024
+ AirtopPluginAugmentationType2["AirtopWindow"] = "AirtopWindow";
2025
+ AirtopPluginAugmentationType2["AirtopSessionClient"] = "AirtopSessionClient";
2026
+ AirtopPluginAugmentationType2["AirtopSession"] = "AirtopSession";
2027
+ AirtopPluginAugmentationType2["AirtopWindowScreenshot"] = "AirtopWindowScreenshot";
2028
+ return AirtopPluginAugmentationType2;
2029
+ })(AirtopPluginAugmentationType || {});
2030
+
2031
+ // src/plugin/AirtopPlugin.ts
2032
+ function registerAirtopPlugin(plugin) {
2033
+ for (const pluginToAdd of plugin.pluginsToAdd) {
2034
+ switch (pluginToAdd.augmentationType) {
2035
+ case "AirtopClient" /* AirtopClient */:
2036
+ pluginToAdd.augment(AirtopClient.prototype);
2037
+ break;
2038
+ case "AirtopSessionClient" /* AirtopSessionClient */:
2039
+ pluginToAdd.augment(AirtopSessionClient.prototype);
2040
+ break;
2041
+ case "AirtopSession" /* AirtopSession */:
2042
+ pluginToAdd.augment(AirtopSession.prototype);
2043
+ break;
2044
+ case "AirtopWindowClient" /* AirtopWindowClient */:
2045
+ pluginToAdd.augment(AirtopWindowClient.prototype);
2046
+ break;
2047
+ case "AirtopWindow" /* AirtopWindow */:
2048
+ pluginToAdd.augment(AirtopWindow.prototype);
2049
+ break;
2050
+ case "AirtopWindowScreenshot" /* AirtopWindowScreenshot */:
2051
+ pluginToAdd.augment(AirtopWindowScreenshot.prototype);
2052
+ break;
2053
+ }
2054
+ }
2055
+ }
1166
2056
  export {
2057
+ AirtopAgentClient,
1167
2058
  AirtopBase,
1168
2059
  AirtopClient,
2060
+ AirtopCore4 as AirtopCore,
2061
+ AirtopCoreShared,
2062
+ AirtopCoreWindows,
2063
+ AirtopError,
2064
+ AirtopFile,
2065
+ AirtopFileClient,
1169
2066
  AirtopMocks,
2067
+ AirtopNode,
1170
2068
  AirtopPluginAugmentationType,
1171
2069
  AirtopSession,
1172
2070
  AirtopSessionClient,
1173
2071
  AirtopWindow,
1174
2072
  AirtopWindowClient,
1175
2073
  AirtopWindowScreenshot,
2074
+ WindowNavigateDirection,
1176
2075
  registerAirtopPlugin
1177
2076
  };
1178
2077
  //# sourceMappingURL=index.js.map