@airtop/sdk 1.0.0-alpha2.1 → 1.0.0-alpha2.10

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.1",
12
+ version: "1.0.0-alpha2.10",
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.17",
50
+ "@airtop/core": "0.1.0-alpha.27",
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,117 @@ 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 AirtopNode = class {
273
+ /**
274
+ * The window client
275
+ */
276
+
277
+ /**
278
+ * The node handle id to use for all requests
279
+ */
280
+
281
+ /**
282
+ * The xpath selector of the node
283
+ */
284
+
285
+ /**
286
+ * Constructor
287
+ * @param client - The window client
288
+ * @param nodeData - The node data to use for all requests
289
+ */
290
+ constructor(client, nodeData) {
291
+ this.windowClient = client;
292
+ this.nodeHandleId = nodeData.id;
293
+ this.selector = nodeData.xpath;
294
+ }
295
+ /**
296
+ * Extract content from the node
297
+ * @param prompt - The prompt to use for the extraction
298
+ * @param config - The configuration to use for the extraction
299
+ * @param requestOptions - The request options to use for the extraction
300
+ */
301
+ async extract(prompt, config, requestOptions = {}) {
302
+ const augmentedConfig = {
303
+ ...config,
304
+ nodeHandleId: this.nodeHandleId
305
+ };
306
+ return this.windowClient.extract(prompt, augmentedConfig, requestOptions);
307
+ }
308
+ /**
309
+ * Act on the node
310
+ * @param prompt - The prompt to use for the action
311
+ * @param config - The configuration to use for the action
312
+ * @param requestOptions - The request options to use for the action
313
+ */
314
+ async act(prompt, config, requestOptions = {}) {
315
+ const augmentedConfig = {
316
+ ...config,
317
+ nodeHandleId: this.nodeHandleId
318
+ };
319
+ return this.windowClient.act(prompt, augmentedConfig, requestOptions);
320
+ }
321
+ /**
322
+ * Execute an LLM call on the node
323
+ * @param prompt - The prompt to use for the LLM call
324
+ * @param config - The configuration to use for the LLM call
325
+ * @param requestOptions - The request options to use for the LLM call
326
+ */
327
+ async llm(prompt, config, requestOptions = {}) {
328
+ return this.windowClient.llm(prompt, config, requestOptions);
329
+ }
330
+ /**
331
+ * Find one element in the node
332
+ * @param prompt - The prompt to use for the find one
333
+ * @param config - The configuration to use for the find one
334
+ * @param requestOptions - The request options to use for the find one
335
+ */
336
+ async findOne(prompt, config, requestOptions = {}) {
337
+ const augmentedConfig = {
338
+ ...config,
339
+ nodeHandleId: this.nodeHandleId
340
+ };
341
+ return this.windowClient.findOne(prompt, augmentedConfig, requestOptions);
342
+ }
343
+ /**
344
+ * Find many elements in the node
345
+ * @param prompt - The prompt to use for the find many
346
+ * @param config - The configuration to use for the find many
347
+ * @param requestOptions - The request options to use for the find many
348
+ */
349
+ async findMany(prompt, config, requestOptions = {}) {
350
+ const augmentedConfig = {
351
+ ...config,
352
+ nodeHandleId: this.nodeHandleId
353
+ };
354
+ return this.windowClient.findMany(prompt, augmentedConfig, requestOptions);
355
+ }
356
+ };
357
+
240
358
  // src/window/AirtopWindowScreenshot.ts
241
359
  function extractMimeAndBase64(dataUrl) {
242
360
  const match = dataUrl.match(/^data:(image\/\w+);base64,(.+)$/);
@@ -480,7 +598,7 @@ var AirtopWindowClient = class extends AirtopBase {
480
598
  prompt
481
599
  }).info("Performing a page query");
482
600
  const newConfig = config;
483
- if (_optionalChain([config, 'optionalAccess', _5 => _5.configuration, 'access', _6 => _6.outputSchema])) {
601
+ if (_optionalChain([config, 'optionalAccess', _6 => _6.configuration, 'access', _7 => _7.outputSchema])) {
484
602
  newConfig.configuration.outputSchema = this.convertToJsonSchema(config.configuration.outputSchema);
485
603
  }
486
604
  return this.client.windows.pageQuery(
@@ -508,7 +626,7 @@ var AirtopWindowClient = class extends AirtopBase {
508
626
  prompt
509
627
  }).info("Performing a paginated extraction");
510
628
  const newConfig = config;
511
- if (_optionalChain([config, 'optionalAccess', _7 => _7.configuration, 'access', _8 => _8.outputSchema])) {
629
+ if (_optionalChain([config, 'optionalAccess', _8 => _8.configuration, 'access', _9 => _9.outputSchema])) {
512
630
  newConfig.configuration.outputSchema = this.convertToJsonSchema(config.configuration.outputSchema);
513
631
  }
514
632
  return this.client.windows.paginatedExtraction(
@@ -609,6 +727,132 @@ var AirtopWindowClient = class extends AirtopBase {
609
727
  }
610
728
  );
611
729
  }
730
+ async extract(prompt, config, requestOptions = {}) {
731
+ this.log.withMetadata({ prompt }).info("Extracting content");
732
+ return withRequestCompletionPolling(
733
+ this.client,
734
+ () => this.client.windows.extract(
735
+ this.getWindowId(),
736
+ {
737
+ prompt,
738
+ sessionId: this.sessionId,
739
+ jobId: this.jobId,
740
+ ...config || {}
741
+ },
742
+ {
743
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
744
+ ...this.resolveRequestOptions(requestOptions)
745
+ }
746
+ )
747
+ );
748
+ }
749
+ async act(prompt, config, requestOptions = {}) {
750
+ this.log.withMetadata({ prompt }).info("Acting on content");
751
+ return withRequestCompletionPolling(
752
+ this.client,
753
+ () => this.client.windows.act(
754
+ this.getWindowId(),
755
+ {
756
+ prompt,
757
+ sessionId: this.sessionId,
758
+ jobId: this.jobId,
759
+ ...config || {}
760
+ },
761
+ {
762
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
763
+ ...this.resolveRequestOptions(requestOptions)
764
+ }
765
+ )
766
+ );
767
+ }
768
+ async llm(prompt, config, requestOptions = {}) {
769
+ this.log.withMetadata({ prompt }).info("Executing LLM call");
770
+ return withRequestCompletionPolling(
771
+ this.client,
772
+ () => this.client.windows.llm(
773
+ this.getWindowId(),
774
+ {
775
+ prompt,
776
+ sessionId: this.sessionId,
777
+ ...config || {}
778
+ },
779
+ {
780
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
781
+ ...this.resolveRequestOptions(requestOptions)
782
+ }
783
+ )
784
+ );
785
+ }
786
+ async findOne(prompt, config, requestOptions = {}) {
787
+ this.log.withMetadata({ prompt }).info("Executing LLM call");
788
+ const apiResponse = await withRequestCompletionPolling(
789
+ this.client,
790
+ () => this.client.windows.findOne(
791
+ this.getWindowId(),
792
+ {
793
+ prompt,
794
+ sessionId: this.sessionId,
795
+ jobId: this.jobId,
796
+ ...config || {}
797
+ },
798
+ {
799
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
800
+ ...this.resolveRequestOptions(requestOptions)
801
+ }
802
+ )
803
+ );
804
+ try {
805
+ const nodeData = JSON.parse(apiResponse.data.modelResponse);
806
+ return new AirtopNode(this, nodeData);
807
+ } catch (error) {
808
+ this.log.withMetadata({ nodeDataStr: apiResponse.data.modelResponse }).withError(error).error("Error parsing node data");
809
+ throw error;
810
+ }
811
+ }
812
+ async findMany(prompt, config, requestOptions = {}) {
813
+ this.log.withMetadata({ prompt }).info("Executing LLM call");
814
+ const apiResponse = await withRequestCompletionPolling(
815
+ this.client,
816
+ () => this.client.windows.findMany(
817
+ this.getWindowId(),
818
+ {
819
+ prompt,
820
+ sessionId: this.sessionId,
821
+ jobId: this.jobId,
822
+ ...config || {}
823
+ },
824
+ {
825
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
826
+ ...this.resolveRequestOptions(requestOptions)
827
+ }
828
+ )
829
+ );
830
+ const nodeHandles = apiResponse.data.modelResponse.split("___DELIM___");
831
+ return nodeHandles.map((nodeDataStr) => {
832
+ try {
833
+ const nodeData = JSON.parse(nodeDataStr);
834
+ return new AirtopNode(this, nodeData);
835
+ } catch (error) {
836
+ this.log.withMetadata({ nodeDataStr }).withError(error).error("Error parsing node data");
837
+ }
838
+ });
839
+ }
840
+ async waitForPage(config, requestOptions = {}) {
841
+ return await withRequestCompletionPolling(
842
+ this.client,
843
+ () => this.client.windows.waitForPage(
844
+ this.getWindowId(),
845
+ {
846
+ sessionId: this.sessionId,
847
+ ...config || {}
848
+ },
849
+ {
850
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
851
+ ...this.resolveRequestOptions(requestOptions)
852
+ }
853
+ )
854
+ );
855
+ }
612
856
  };
613
857
 
614
858
  // src/window/AirtopWindow.ts
@@ -782,7 +1026,7 @@ var AirtopSessionClient = class extends AirtopBase {
782
1026
  {
783
1027
  ...config,
784
1028
  fileName,
785
- sessionId: this.sessionId
1029
+ sessionIds: [this.sessionId]
786
1030
  },
787
1031
  this.resolveRequestOptions(requestOptions)
788
1032
  );
@@ -845,19 +1089,19 @@ var AirtopClient = class extends AirtopBase {
845
1089
  */
846
1090
  constructor(config) {
847
1091
  super({
848
- logLevel: _optionalChain([config, 'optionalAccess', _9 => _9.logLevel]),
1092
+ logLevel: _optionalChain([config, 'optionalAccess', _10 => _10.logLevel]),
849
1093
  client: new (0, _core.Airtop)({
850
1094
  maxRetries: 0,
851
1095
  timeout: _minutesToMilliseconds.minutesToMilliseconds.call(void 0, 1),
852
1096
  apiKey: config.apiKey,
853
- baseURL: _optionalChain([config, 'optionalAccess', _10 => _10.airtopUrl]),
854
- logLevel: _optionalChain([config, 'optionalAccess', _11 => _11.logLevel]) || "off",
1097
+ baseURL: _optionalChain([config, 'optionalAccess', _11 => _11.airtopUrl]),
1098
+ logLevel: _optionalChain([config, 'optionalAccess', _12 => _12.logLevel]) || "off",
855
1099
  defaultHeaders: {
856
1100
  "x-airtop-sdk-source": "typescript",
857
1101
  "x-airtop-sdk-version": version
858
1102
  }
859
1103
  }),
860
- log: _optionalChain([config, 'optionalAccess', _12 => _12.logger]) || new (0, _loglayer.LogLayer)({
1104
+ log: _optionalChain([config, 'optionalAccess', _13 => _13.logger]) || new (0, _loglayer.LogLayer)({
861
1105
  errorSerializer: _serializeerror.serializeError,
862
1106
  transport: new (0, _loglayer.ConsoleTransport)({
863
1107
  logger: console,
@@ -868,7 +1112,8 @@ var AirtopClient = class extends AirtopBase {
868
1112
  contextFieldName: "context",
869
1113
  metadataFieldName: "metadata"
870
1114
  }),
871
- outputSchemaAdapter: config.outputSchemaAdapter
1115
+ outputSchemaAdapter: config.outputSchemaAdapter,
1116
+ jobId: config.jobId
872
1117
  });
873
1118
  this.log.withPrefix("[Airtop SDK]");
874
1119
  this.client.logLevel = config.logLevel;
@@ -894,8 +1139,8 @@ var AirtopClient = class extends AirtopBase {
894
1139
  * @returns A new AirtopSession instance
895
1140
  */
896
1141
  async createSession(config, options = {}) {
897
- const skipWaitSessionReady = _nullishCoalesce(config.skipWaitSessionReady, () => ( false));
898
- delete config.skipWaitSessionReady;
1142
+ const skipWaitSessionReady = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _14 => _14.skipWaitSessionReady]), () => ( false));
1143
+ _optionalChainDelete([config, 'optionalAccess', _15 => delete _15.skipWaitSessionReady]);
899
1144
  const sessionResponse = await this.client.sessions.create(
900
1145
  {
901
1146
  configuration: config
@@ -1003,23 +1248,6 @@ var AirtopClient = class extends AirtopBase {
1003
1248
  async getFile(fileId, requestOptions = {}) {
1004
1249
  return this.client.files.get(fileId, this.resolveRequestOptions(requestOptions));
1005
1250
  }
1006
- /**
1007
- * Lists files filtered by session IDs.
1008
- * @param sessionIds - Array of session IDs to retrieve files for
1009
- * @param config - Configuration options for the request
1010
- * @param requestOptions - Request options
1011
- * @returns Object containing pagination info and array of AirtopSession instances
1012
- */
1013
- async listFiles(sessionIds, config, requestOptions = {}) {
1014
- return this.client.files.list(
1015
- {
1016
- sessionIds,
1017
- limit: config.limit,
1018
- offset: config.offset
1019
- },
1020
- this.resolveRequestOptions(requestOptions)
1021
- );
1022
- }
1023
1251
  /**
1024
1252
  * Removes a file by ID.
1025
1253
  * @param fileId - ID of the file to remove
@@ -1028,6 +1256,14 @@ var AirtopClient = class extends AirtopBase {
1028
1256
  async removeFile(fileId, requestOptions = {}) {
1029
1257
  return this.client.files.delete(fileId, this.resolveRequestOptions(requestOptions));
1030
1258
  }
1259
+ /**
1260
+ * List files
1261
+ * @param query
1262
+ * @param requestOptions
1263
+ */
1264
+ async listFiles(query, requestOptions = {}) {
1265
+ return this.client.files.list(query, this.resolveRequestOptions(requestOptions));
1266
+ }
1031
1267
  /**
1032
1268
  * List all automations
1033
1269
  * @param requestOptions - Request options
@@ -1191,5 +1427,6 @@ var AirtopMocks = class {
1191
1427
 
1192
1428
 
1193
1429
 
1194
- exports.AirtopBase = AirtopBase; exports.AirtopClient = AirtopClient; exports.AirtopMocks = AirtopMocks; exports.AirtopPluginAugmentationType = AirtopPluginAugmentationType; exports.AirtopSession = AirtopSession; exports.AirtopSessionClient = AirtopSessionClient; exports.AirtopWindow = AirtopWindow; exports.AirtopWindowClient = AirtopWindowClient; exports.AirtopWindowScreenshot = AirtopWindowScreenshot; exports.registerAirtopPlugin = registerAirtopPlugin;
1430
+
1431
+ exports.AirtopBase = AirtopBase; exports.AirtopClient = AirtopClient; exports.AirtopMocks = AirtopMocks; exports.AirtopNode = AirtopNode; exports.AirtopPluginAugmentationType = AirtopPluginAugmentationType; exports.AirtopSession = AirtopSession; exports.AirtopSessionClient = AirtopSessionClient; exports.AirtopWindow = AirtopWindow; exports.AirtopWindowClient = AirtopWindowClient; exports.AirtopWindowScreenshot = AirtopWindowScreenshot; exports.registerAirtopPlugin = registerAirtopPlugin;
1195
1432
  //# sourceMappingURL=index.cjs.map