@airtop/sdk 1.0.0-alpha2.6 → 1.0.0-alpha2.8

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.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __getOwnPropNames = Object.getOwnPropertyNames;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } function _optionalChainDelete(ops) { const result = _optionalChain(ops); return result == null ? true : result; }var __getOwnPropNames = Object.getOwnPropertyNames;
2
2
  var __commonJS = (cb, mod) => function __require() {
3
3
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
4
  };
@@ -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.6",
12
+ version: "1.0.0-alpha2.8",
13
13
  type: "module",
14
14
  main: "./dist/index.cjs",
15
15
  module: "./dist/index.js",
@@ -47,7 +47,7 @@ var require_package = __commonJS({
47
47
  },
48
48
  dependencies: {
49
49
  "@airtop/json-schema-adapter": "workspace:*",
50
- "@airtop/core": "0.1.0-alpha.24",
50
+ "@airtop/core": "0.1.0-alpha.26",
51
51
  "date-fns": "4.1.0",
52
52
  loglayer: "6.3.3",
53
53
  "serialize-error": "12.0.0",
@@ -102,6 +102,11 @@ var AirtopBase = class {
102
102
  * @internal
103
103
  **/
104
104
 
105
+ /**
106
+ * The job id for the ongoing automation
107
+ * @internal
108
+ */
109
+
105
110
  /**
106
111
  * Creates a new instance of AirtopBase
107
112
  * @param config - Configuration options for the SDK
@@ -110,6 +115,7 @@ var AirtopBase = class {
110
115
  this.log = config.log.withPrefix("[Airtop]");
111
116
  this.client = config.client;
112
117
  this.outputJsonAdapter = config.outputSchemaAdapter;
118
+ this.jobId = config.jobId;
113
119
  }
114
120
  /**
115
121
  * Returns the API key used by the SDK
@@ -163,7 +169,8 @@ var AirtopBase = class {
163
169
  getCommonConfig() {
164
170
  return {
165
171
  client: this.client,
166
- log: this.log
172
+ log: this.log,
173
+ jobId: this.jobId
167
174
  };
168
175
  }
169
176
  /**
@@ -237,6 +244,99 @@ var processLogMessage = (log, logLevel, ...args) => {
237
244
  // src/window/AirtopWindowClient.ts
238
245
 
239
246
 
247
+ // src/async-utils.ts
248
+
249
+ var DEFAULT_TIMEOUT_SECONDS = 300;
250
+ var DEFAULT_POLLING_INTERVAL_SECONDS = 2;
251
+ async function waitForRequestCompletion(client, requestId, requestOptions) {
252
+ const startTime = Date.now();
253
+ const timeoutMs = _datefns.secondsToMilliseconds.call(void 0, _optionalChain([requestOptions, 'optionalAccess', _5 => _5.timeoutInSeconds]) || DEFAULT_TIMEOUT_SECONDS);
254
+ while (Date.now() - startTime < timeoutMs) {
255
+ const apiResponse = await client.requests.getRequestStatus(requestId, requestOptions);
256
+ if (apiResponse.status === "completed") {
257
+ return apiResponse.response;
258
+ }
259
+ if (apiResponse.status === "error") {
260
+ throw new Error(apiResponse.error);
261
+ }
262
+ await new Promise((resolve) => setTimeout(resolve, _datefns.secondsToMilliseconds.call(void 0, DEFAULT_POLLING_INTERVAL_SECONDS)));
263
+ }
264
+ throw new Error("Waiting for request timed out");
265
+ }
266
+ async function withRequestCompletionPolling(client, fn, requestOptions) {
267
+ const response = await fn();
268
+ return waitForRequestCompletion(client, response.requestId, requestOptions);
269
+ }
270
+
271
+ // src/window/AirtopNode.ts
272
+ var AirtopNodeImpl = class {
273
+ /**
274
+ * The window client
275
+ */
276
+
277
+ /**
278
+ * The node handle id to use for all requests
279
+ */
280
+
281
+ /**
282
+ * Constructor
283
+ * @param client - The window client
284
+ * @param nodeHandleId - The node handle id to use for all requests
285
+ */
286
+ constructor(client, nodeHandleId) {
287
+ this.windowClient = client;
288
+ this.nodeHandleId = nodeHandleId;
289
+ }
290
+ /**
291
+ * Extract content from the node
292
+ * @param prompt - The prompt to use for the extraction
293
+ * @param config - The configuration to use for the extraction
294
+ * @param requestOptions - The request options to use for the extraction
295
+ */
296
+ async extract(prompt, config, requestOptions = {}) {
297
+ const augmentedConfig = {
298
+ ...config,
299
+ nodeHandleId: this.nodeHandleId
300
+ };
301
+ return this.windowClient.extract(prompt, augmentedConfig, requestOptions);
302
+ }
303
+ /**
304
+ * Act on the node
305
+ * @param prompt - The prompt to use for the action
306
+ * @param config - The configuration to use for the action
307
+ * @param requestOptions - The request options to use for the action
308
+ */
309
+ async act(prompt, config, requestOptions = {}) {
310
+ const augmentedConfig = {
311
+ ...config,
312
+ nodeHandleId: this.nodeHandleId
313
+ };
314
+ return this.windowClient.act(prompt, augmentedConfig, requestOptions);
315
+ }
316
+ /**
317
+ * Execute an LLM call on the node
318
+ * @param prompt - The prompt to use for the LLM call
319
+ * @param config - The configuration to use for the LLM call
320
+ * @param requestOptions - The request options to use for the LLM call
321
+ */
322
+ async llm(prompt, config, requestOptions = {}) {
323
+ return this.windowClient.llm(prompt, config, requestOptions);
324
+ }
325
+ /**
326
+ * Find one element in the node
327
+ * @param prompt - The prompt to use for the find one
328
+ * @param config - The configuration to use for the find one
329
+ * @param requestOptions - The request options to use for the find one
330
+ */
331
+ async findOne(prompt, config, requestOptions = {}) {
332
+ const augmentedConfig = {
333
+ ...config,
334
+ nodeHandleId: this.nodeHandleId
335
+ };
336
+ return this.windowClient.findOne(prompt, augmentedConfig, requestOptions);
337
+ }
338
+ };
339
+
240
340
  // src/window/AirtopWindowScreenshot.ts
241
341
  function extractMimeAndBase64(dataUrl) {
242
342
  const match = dataUrl.match(/^data:(image\/\w+);base64,(.+)$/);
@@ -480,7 +580,7 @@ var AirtopWindowClient = class extends AirtopBase {
480
580
  prompt
481
581
  }).info("Performing a page query");
482
582
  const newConfig = config;
483
- if (_optionalChain([config, 'optionalAccess', _5 => _5.configuration, 'access', _6 => _6.outputSchema])) {
583
+ if (_optionalChain([config, 'optionalAccess', _6 => _6.configuration, 'access', _7 => _7.outputSchema])) {
484
584
  newConfig.configuration.outputSchema = this.convertToJsonSchema(config.configuration.outputSchema);
485
585
  }
486
586
  return this.client.windows.pageQuery(
@@ -508,7 +608,7 @@ var AirtopWindowClient = class extends AirtopBase {
508
608
  prompt
509
609
  }).info("Performing a paginated extraction");
510
610
  const newConfig = config;
511
- if (_optionalChain([config, 'optionalAccess', _7 => _7.configuration, 'access', _8 => _8.outputSchema])) {
611
+ if (_optionalChain([config, 'optionalAccess', _8 => _8.configuration, 'access', _9 => _9.outputSchema])) {
512
612
  newConfig.configuration.outputSchema = this.convertToJsonSchema(config.configuration.outputSchema);
513
613
  }
514
614
  return this.client.windows.paginatedExtraction(
@@ -609,6 +709,104 @@ var AirtopWindowClient = class extends AirtopBase {
609
709
  }
610
710
  );
611
711
  }
712
+ async extract(prompt, config, requestOptions = {}) {
713
+ this.log.withMetadata({ prompt }).info("Extracting content");
714
+ return withRequestCompletionPolling(
715
+ this.client,
716
+ () => this.client.windows.extract(
717
+ this.getWindowId(),
718
+ {
719
+ prompt,
720
+ sessionId: this.sessionId,
721
+ jobId: this.jobId,
722
+ ...config || {}
723
+ },
724
+ {
725
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
726
+ ...this.resolveRequestOptions(requestOptions)
727
+ }
728
+ )
729
+ );
730
+ }
731
+ async act(prompt, config, requestOptions = {}) {
732
+ this.log.withMetadata({ prompt }).info("Acting on content");
733
+ return withRequestCompletionPolling(
734
+ this.client,
735
+ () => this.client.windows.act(
736
+ this.getWindowId(),
737
+ {
738
+ prompt,
739
+ sessionId: this.sessionId,
740
+ jobId: this.jobId,
741
+ ...config || {}
742
+ },
743
+ {
744
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
745
+ ...this.resolveRequestOptions(requestOptions)
746
+ }
747
+ )
748
+ );
749
+ }
750
+ async llm(prompt, config, requestOptions = {}) {
751
+ this.log.withMetadata({ prompt }).info("Executing LLM call");
752
+ return withRequestCompletionPolling(
753
+ this.client,
754
+ () => this.client.windows.llm(
755
+ this.getWindowId(),
756
+ {
757
+ prompt,
758
+ sessionId: this.sessionId,
759
+ ...config || {}
760
+ },
761
+ {
762
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
763
+ ...this.resolveRequestOptions(requestOptions)
764
+ }
765
+ )
766
+ );
767
+ }
768
+ async findOne(prompt, config, requestOptions = {}) {
769
+ this.log.withMetadata({ prompt }).info("Executing LLM call");
770
+ const apiResponse = await withRequestCompletionPolling(
771
+ this.client,
772
+ () => this.client.windows.findOne(
773
+ this.getWindowId(),
774
+ {
775
+ prompt,
776
+ sessionId: this.sessionId,
777
+ jobId: this.jobId,
778
+ ...config || {}
779
+ },
780
+ {
781
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
782
+ ...this.resolveRequestOptions(requestOptions)
783
+ }
784
+ )
785
+ );
786
+ const nodeHandleId = apiResponse.data.modelResponse;
787
+ return new AirtopNodeImpl(this, nodeHandleId);
788
+ }
789
+ async findMany(prompt, config, requestOptions = {}) {
790
+ this.log.withMetadata({ prompt }).info("Executing LLM call");
791
+ const apiResponse = await withRequestCompletionPolling(
792
+ this.client,
793
+ () => this.client.windows.findMany(
794
+ this.getWindowId(),
795
+ {
796
+ prompt,
797
+ sessionId: this.sessionId,
798
+ jobId: this.jobId,
799
+ ...config || {}
800
+ },
801
+ {
802
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
803
+ ...this.resolveRequestOptions(requestOptions)
804
+ }
805
+ )
806
+ );
807
+ const nodeHandleIds = apiResponse.data.modelResponse.split(",");
808
+ return nodeHandleIds.map((nodeHandleId) => new AirtopNodeImpl(this, nodeHandleId));
809
+ }
612
810
  };
613
811
 
614
812
  // src/window/AirtopWindow.ts
@@ -845,19 +1043,19 @@ var AirtopClient = class extends AirtopBase {
845
1043
  */
846
1044
  constructor(config) {
847
1045
  super({
848
- logLevel: _optionalChain([config, 'optionalAccess', _9 => _9.logLevel]),
1046
+ logLevel: _optionalChain([config, 'optionalAccess', _10 => _10.logLevel]),
849
1047
  client: new (0, _core.Airtop)({
850
1048
  maxRetries: 0,
851
1049
  timeout: _minutesToMilliseconds.minutesToMilliseconds.call(void 0, 1),
852
1050
  apiKey: config.apiKey,
853
- baseURL: _optionalChain([config, 'optionalAccess', _10 => _10.airtopUrl]),
854
- logLevel: _optionalChain([config, 'optionalAccess', _11 => _11.logLevel]) || "off",
1051
+ baseURL: _optionalChain([config, 'optionalAccess', _11 => _11.airtopUrl]),
1052
+ logLevel: _optionalChain([config, 'optionalAccess', _12 => _12.logLevel]) || "off",
855
1053
  defaultHeaders: {
856
1054
  "x-airtop-sdk-source": "typescript",
857
1055
  "x-airtop-sdk-version": version
858
1056
  }
859
1057
  }),
860
- log: _optionalChain([config, 'optionalAccess', _12 => _12.logger]) || new (0, _loglayer.LogLayer)({
1058
+ log: _optionalChain([config, 'optionalAccess', _13 => _13.logger]) || new (0, _loglayer.LogLayer)({
861
1059
  errorSerializer: _serializeerror.serializeError,
862
1060
  transport: new (0, _loglayer.ConsoleTransport)({
863
1061
  logger: console,
@@ -868,7 +1066,8 @@ var AirtopClient = class extends AirtopBase {
868
1066
  contextFieldName: "context",
869
1067
  metadataFieldName: "metadata"
870
1068
  }),
871
- outputSchemaAdapter: config.outputSchemaAdapter
1069
+ outputSchemaAdapter: config.outputSchemaAdapter,
1070
+ jobId: config.jobId
872
1071
  });
873
1072
  this.log.withPrefix("[Airtop SDK]");
874
1073
  this.client.logLevel = config.logLevel;
@@ -894,8 +1093,8 @@ var AirtopClient = class extends AirtopBase {
894
1093
  * @returns A new AirtopSession instance
895
1094
  */
896
1095
  async createSession(config, options = {}) {
897
- const skipWaitSessionReady = _nullishCoalesce(config.skipWaitSessionReady, () => ( false));
898
- delete config.skipWaitSessionReady;
1096
+ const skipWaitSessionReady = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _14 => _14.skipWaitSessionReady]), () => ( false));
1097
+ _optionalChainDelete([config, 'optionalAccess', _15 => delete _15.skipWaitSessionReady]);
899
1098
  const sessionResponse = await this.client.sessions.create(
900
1099
  {
901
1100
  configuration: config