@airtop/sdk 1.0.0-alpha2.5 → 1.0.0-alpha2.7

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.5",
12
+ version: "1.0.0-alpha2.7",
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.22",
50
+ "@airtop/core": "0.1.0-alpha.25",
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 AirtopNode = 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,83 @@ 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 AirtopNode(this, nodeHandleId);
788
+ }
612
789
  };
613
790
 
614
791
  // src/window/AirtopWindow.ts
@@ -845,19 +1022,19 @@ var AirtopClient = class extends AirtopBase {
845
1022
  */
846
1023
  constructor(config) {
847
1024
  super({
848
- logLevel: _optionalChain([config, 'optionalAccess', _9 => _9.logLevel]),
1025
+ logLevel: _optionalChain([config, 'optionalAccess', _10 => _10.logLevel]),
849
1026
  client: new (0, _core.Airtop)({
850
1027
  maxRetries: 0,
851
1028
  timeout: _minutesToMilliseconds.minutesToMilliseconds.call(void 0, 1),
852
1029
  apiKey: config.apiKey,
853
- baseURL: _optionalChain([config, 'optionalAccess', _10 => _10.airtopUrl]),
854
- logLevel: _optionalChain([config, 'optionalAccess', _11 => _11.logLevel]) || "off",
1030
+ baseURL: _optionalChain([config, 'optionalAccess', _11 => _11.airtopUrl]),
1031
+ logLevel: _optionalChain([config, 'optionalAccess', _12 => _12.logLevel]) || "off",
855
1032
  defaultHeaders: {
856
1033
  "x-airtop-sdk-source": "typescript",
857
1034
  "x-airtop-sdk-version": version
858
1035
  }
859
1036
  }),
860
- log: _optionalChain([config, 'optionalAccess', _12 => _12.logger]) || new (0, _loglayer.LogLayer)({
1037
+ log: _optionalChain([config, 'optionalAccess', _13 => _13.logger]) || new (0, _loglayer.LogLayer)({
861
1038
  errorSerializer: _serializeerror.serializeError,
862
1039
  transport: new (0, _loglayer.ConsoleTransport)({
863
1040
  logger: console,
@@ -868,7 +1045,8 @@ var AirtopClient = class extends AirtopBase {
868
1045
  contextFieldName: "context",
869
1046
  metadataFieldName: "metadata"
870
1047
  }),
871
- outputSchemaAdapter: config.outputSchemaAdapter
1048
+ outputSchemaAdapter: config.outputSchemaAdapter,
1049
+ jobId: config.jobId
872
1050
  });
873
1051
  this.log.withPrefix("[Airtop SDK]");
874
1052
  this.client.logLevel = config.logLevel;
@@ -894,8 +1072,8 @@ var AirtopClient = class extends AirtopBase {
894
1072
  * @returns A new AirtopSession instance
895
1073
  */
896
1074
  async createSession(config, options = {}) {
897
- const skipWaitSessionReady = _nullishCoalesce(config.skipWaitSessionReady, () => ( false));
898
- delete config.skipWaitSessionReady;
1075
+ const skipWaitSessionReady = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _14 => _14.skipWaitSessionReady]), () => ( false));
1076
+ _optionalChainDelete([config, 'optionalAccess', _15 => delete _15.skipWaitSessionReady]);
899
1077
  const sessionResponse = await this.client.sessions.create(
900
1078
  {
901
1079
  configuration: config
@@ -1011,6 +1189,14 @@ var AirtopClient = class extends AirtopBase {
1011
1189
  async removeFile(fileId, requestOptions = {}) {
1012
1190
  return this.client.files.delete(fileId, this.resolveRequestOptions(requestOptions));
1013
1191
  }
1192
+ /**
1193
+ * List files
1194
+ * @param query
1195
+ * @param requestOptions
1196
+ */
1197
+ async listFiles(query, requestOptions = {}) {
1198
+ return this.client.files.list(query, this.resolveRequestOptions(requestOptions));
1199
+ }
1014
1200
  /**
1015
1201
  * List all automations
1016
1202
  * @param requestOptions - Request options