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

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.11",
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,16 @@ var AirtopBase = class {
102
102
  * @internal
103
103
  **/
104
104
 
105
+ /**
106
+ * The job id for the ongoing automation
107
+ * @internal
108
+ */
109
+
110
+ /**
111
+ * Instance for sending agent events
112
+ * @internal
113
+ */
114
+
105
115
  /**
106
116
  * Creates a new instance of AirtopBase
107
117
  * @param config - Configuration options for the SDK
@@ -110,6 +120,25 @@ var AirtopBase = class {
110
120
  this.log = config.log.withPrefix("[Airtop]");
111
121
  this.client = config.client;
112
122
  this.outputJsonAdapter = config.outputSchemaAdapter;
123
+ this.jobId = config.jobId;
124
+ }
125
+ /**
126
+ * Sets the publisher for sending agent events. Internal use only.
127
+ * @internal
128
+ */
129
+ _setAgentEventPublisher(logger) {
130
+ this.agentEventPublisher = logger;
131
+ }
132
+ /**
133
+ * Sends a payload to the agent with the specified event name.
134
+ * @param eventName The name of the event
135
+ * @param payload The payload to send to the agent
136
+ * @internal
137
+ */
138
+ _sendAgentPayload(eventName, payload) {
139
+ if (this.agentEventPublisher) {
140
+ this.agentEventPublisher.withMetadata(payload).info(eventName);
141
+ }
113
142
  }
114
143
  /**
115
144
  * Returns the API key used by the SDK
@@ -163,7 +192,8 @@ var AirtopBase = class {
163
192
  getCommonConfig() {
164
193
  return {
165
194
  client: this.client,
166
- log: this.log
195
+ log: this.log,
196
+ jobId: this.jobId
167
197
  };
168
198
  }
169
199
  /**
@@ -237,6 +267,117 @@ var processLogMessage = (log, logLevel, ...args) => {
237
267
  // src/window/AirtopWindowClient.ts
238
268
 
239
269
 
270
+ // src/async-utils.ts
271
+
272
+ var DEFAULT_TIMEOUT_SECONDS = 300;
273
+ var DEFAULT_POLLING_INTERVAL_SECONDS = 2;
274
+ async function waitForRequestCompletion(client, requestId, requestOptions) {
275
+ const startTime = Date.now();
276
+ const timeoutMs = _datefns.secondsToMilliseconds.call(void 0, _optionalChain([requestOptions, 'optionalAccess', _5 => _5.timeoutInSeconds]) || DEFAULT_TIMEOUT_SECONDS);
277
+ while (Date.now() - startTime < timeoutMs) {
278
+ const apiResponse = await client.requests.getRequestStatus(requestId, requestOptions);
279
+ if (apiResponse.status === "completed") {
280
+ return apiResponse.response;
281
+ }
282
+ if (apiResponse.status === "error") {
283
+ throw new Error(apiResponse.error);
284
+ }
285
+ await new Promise((resolve) => setTimeout(resolve, _datefns.secondsToMilliseconds.call(void 0, DEFAULT_POLLING_INTERVAL_SECONDS)));
286
+ }
287
+ throw new Error("Waiting for request timed out");
288
+ }
289
+ async function withRequestCompletionPolling(client, fn, requestOptions) {
290
+ const response = await fn();
291
+ return waitForRequestCompletion(client, response.requestId, requestOptions);
292
+ }
293
+
294
+ // src/window/AirtopNode.ts
295
+ var AirtopNode = class {
296
+ /**
297
+ * The window client
298
+ */
299
+
300
+ /**
301
+ * The node handle id to use for all requests
302
+ */
303
+
304
+ /**
305
+ * The xpath selector of the node
306
+ */
307
+
308
+ /**
309
+ * Constructor
310
+ * @param client - The window client
311
+ * @param nodeData - The node data to use for all requests
312
+ */
313
+ constructor(client, nodeData) {
314
+ this.windowClient = client;
315
+ this.nodeHandleId = nodeData.id;
316
+ this.selector = nodeData.xpath;
317
+ }
318
+ /**
319
+ * Extract content from the node
320
+ * @param prompt - The prompt to use for the extraction
321
+ * @param config - The configuration to use for the extraction
322
+ * @param requestOptions - The request options to use for the extraction
323
+ */
324
+ async extract(prompt, config, requestOptions = {}) {
325
+ const augmentedConfig = {
326
+ ...config,
327
+ nodeHandleId: this.nodeHandleId
328
+ };
329
+ return this.windowClient.extract(prompt, augmentedConfig, requestOptions);
330
+ }
331
+ /**
332
+ * Act on the node
333
+ * @param prompt - The prompt to use for the action
334
+ * @param config - The configuration to use for the action
335
+ * @param requestOptions - The request options to use for the action
336
+ */
337
+ async act(prompt, config, requestOptions = {}) {
338
+ const augmentedConfig = {
339
+ ...config,
340
+ nodeHandleId: this.nodeHandleId
341
+ };
342
+ return this.windowClient.act(prompt, augmentedConfig, requestOptions);
343
+ }
344
+ /**
345
+ * Execute an LLM call on the node
346
+ * @param prompt - The prompt to use for the LLM call
347
+ * @param config - The configuration to use for the LLM call
348
+ * @param requestOptions - The request options to use for the LLM call
349
+ */
350
+ async llm(prompt, config, requestOptions = {}) {
351
+ return this.windowClient.llm(prompt, config, requestOptions);
352
+ }
353
+ /**
354
+ * Find one element in the node
355
+ * @param prompt - The prompt to use for the find one
356
+ * @param config - The configuration to use for the find one
357
+ * @param requestOptions - The request options to use for the find one
358
+ */
359
+ async findOne(prompt, config, requestOptions = {}) {
360
+ const augmentedConfig = {
361
+ ...config,
362
+ nodeHandleId: this.nodeHandleId
363
+ };
364
+ return this.windowClient.findOne(prompt, augmentedConfig, requestOptions);
365
+ }
366
+ /**
367
+ * Find many elements in the node
368
+ * @param prompt - The prompt to use for the find many
369
+ * @param config - The configuration to use for the find many
370
+ * @param requestOptions - The request options to use for the find many
371
+ */
372
+ async findMany(prompt, config, requestOptions = {}) {
373
+ const augmentedConfig = {
374
+ ...config,
375
+ nodeHandleId: this.nodeHandleId
376
+ };
377
+ return this.windowClient.findMany(prompt, augmentedConfig, requestOptions);
378
+ }
379
+ };
380
+
240
381
  // src/window/AirtopWindowScreenshot.ts
241
382
  function extractMimeAndBase64(dataUrl) {
242
383
  const match = dataUrl.match(/^data:(image\/\w+);base64,(.+)$/);
@@ -364,6 +505,11 @@ var AirtopWindowClient = class extends AirtopBase {
364
505
  },
365
506
  this.resolveRequestOptions(requestOptions)
366
507
  );
508
+ this._sendAgentPayload("LiveViewUrl", {
509
+ liveViewUrl: results.data.liveViewUrl,
510
+ windowId: this.windowId,
511
+ sessionId: this.sessionId
512
+ });
367
513
  return new AirtopWindow(this.getCommonConfig(), this.sessionId, results);
368
514
  }
369
515
  /**
@@ -480,7 +626,7 @@ var AirtopWindowClient = class extends AirtopBase {
480
626
  prompt
481
627
  }).info("Performing a page query");
482
628
  const newConfig = config;
483
- if (_optionalChain([config, 'optionalAccess', _5 => _5.configuration, 'access', _6 => _6.outputSchema])) {
629
+ if (_optionalChain([config, 'optionalAccess', _6 => _6.configuration, 'access', _7 => _7.outputSchema])) {
484
630
  newConfig.configuration.outputSchema = this.convertToJsonSchema(config.configuration.outputSchema);
485
631
  }
486
632
  return this.client.windows.pageQuery(
@@ -508,7 +654,7 @@ var AirtopWindowClient = class extends AirtopBase {
508
654
  prompt
509
655
  }).info("Performing a paginated extraction");
510
656
  const newConfig = config;
511
- if (_optionalChain([config, 'optionalAccess', _7 => _7.configuration, 'access', _8 => _8.outputSchema])) {
657
+ if (_optionalChain([config, 'optionalAccess', _8 => _8.configuration, 'access', _9 => _9.outputSchema])) {
512
658
  newConfig.configuration.outputSchema = this.convertToJsonSchema(config.configuration.outputSchema);
513
659
  }
514
660
  return this.client.windows.paginatedExtraction(
@@ -609,6 +755,132 @@ var AirtopWindowClient = class extends AirtopBase {
609
755
  }
610
756
  );
611
757
  }
758
+ async extract(prompt, config, requestOptions = {}) {
759
+ this.log.withMetadata({ prompt }).info("Extracting content");
760
+ return withRequestCompletionPolling(
761
+ this.client,
762
+ () => this.client.windows.extract(
763
+ this.getWindowId(),
764
+ {
765
+ prompt,
766
+ sessionId: this.sessionId,
767
+ jobId: this.jobId,
768
+ ...config || {}
769
+ },
770
+ {
771
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
772
+ ...this.resolveRequestOptions(requestOptions)
773
+ }
774
+ )
775
+ );
776
+ }
777
+ async act(prompt, config, requestOptions = {}) {
778
+ this.log.withMetadata({ prompt }).info("Acting on content");
779
+ return withRequestCompletionPolling(
780
+ this.client,
781
+ () => this.client.windows.act(
782
+ this.getWindowId(),
783
+ {
784
+ prompt,
785
+ sessionId: this.sessionId,
786
+ jobId: this.jobId,
787
+ ...config || {}
788
+ },
789
+ {
790
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
791
+ ...this.resolveRequestOptions(requestOptions)
792
+ }
793
+ )
794
+ );
795
+ }
796
+ async llm(prompt, config, requestOptions = {}) {
797
+ this.log.withMetadata({ prompt }).info("Executing LLM call");
798
+ return withRequestCompletionPolling(
799
+ this.client,
800
+ () => this.client.windows.llm(
801
+ this.getWindowId(),
802
+ {
803
+ prompt,
804
+ sessionId: this.sessionId,
805
+ ...config || {}
806
+ },
807
+ {
808
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
809
+ ...this.resolveRequestOptions(requestOptions)
810
+ }
811
+ )
812
+ );
813
+ }
814
+ async findOne(prompt, config, requestOptions = {}) {
815
+ this.log.withMetadata({ prompt }).info("Executing LLM call");
816
+ const apiResponse = await withRequestCompletionPolling(
817
+ this.client,
818
+ () => this.client.windows.findOne(
819
+ this.getWindowId(),
820
+ {
821
+ prompt,
822
+ sessionId: this.sessionId,
823
+ jobId: this.jobId,
824
+ ...config || {}
825
+ },
826
+ {
827
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
828
+ ...this.resolveRequestOptions(requestOptions)
829
+ }
830
+ )
831
+ );
832
+ try {
833
+ const nodeData = JSON.parse(apiResponse.data.modelResponse);
834
+ return new AirtopNode(this, nodeData);
835
+ } catch (error) {
836
+ this.log.withMetadata({ nodeDataStr: apiResponse.data.modelResponse }).withError(error).error("Error parsing node data");
837
+ throw error;
838
+ }
839
+ }
840
+ async findMany(prompt, config, requestOptions = {}) {
841
+ this.log.withMetadata({ prompt }).info("Executing LLM call");
842
+ const apiResponse = await withRequestCompletionPolling(
843
+ this.client,
844
+ () => this.client.windows.findMany(
845
+ this.getWindowId(),
846
+ {
847
+ prompt,
848
+ sessionId: this.sessionId,
849
+ jobId: this.jobId,
850
+ ...config || {}
851
+ },
852
+ {
853
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
854
+ ...this.resolveRequestOptions(requestOptions)
855
+ }
856
+ )
857
+ );
858
+ const nodeHandles = apiResponse.data.modelResponse.split("___DELIM___");
859
+ return nodeHandles.map((nodeDataStr) => {
860
+ try {
861
+ const nodeData = JSON.parse(nodeDataStr);
862
+ return new AirtopNode(this, nodeData);
863
+ } catch (error) {
864
+ this.log.withMetadata({ nodeDataStr }).withError(error).error("Error parsing node data");
865
+ }
866
+ });
867
+ }
868
+ async waitForPage(config, requestOptions = {}) {
869
+ return await withRequestCompletionPolling(
870
+ this.client,
871
+ () => this.client.windows.waitForPage(
872
+ this.getWindowId(),
873
+ {
874
+ sessionId: this.sessionId,
875
+ ...config || {}
876
+ },
877
+ {
878
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
879
+ ...this.resolveRequestOptions(requestOptions)
880
+ }
881
+ )
882
+ );
883
+ }
612
884
  };
613
885
 
614
886
  // src/window/AirtopWindow.ts
@@ -782,7 +1054,7 @@ var AirtopSessionClient = class extends AirtopBase {
782
1054
  {
783
1055
  ...config,
784
1056
  fileName,
785
- sessionId: this.sessionId
1057
+ sessionIds: [this.sessionId]
786
1058
  },
787
1059
  this.resolveRequestOptions(requestOptions)
788
1060
  );
@@ -845,19 +1117,19 @@ var AirtopClient = class extends AirtopBase {
845
1117
  */
846
1118
  constructor(config) {
847
1119
  super({
848
- logLevel: _optionalChain([config, 'optionalAccess', _9 => _9.logLevel]),
1120
+ logLevel: _optionalChain([config, 'optionalAccess', _10 => _10.logLevel]),
849
1121
  client: new (0, _core.Airtop)({
850
1122
  maxRetries: 0,
851
1123
  timeout: _minutesToMilliseconds.minutesToMilliseconds.call(void 0, 1),
852
1124
  apiKey: config.apiKey,
853
- baseURL: _optionalChain([config, 'optionalAccess', _10 => _10.airtopUrl]),
854
- logLevel: _optionalChain([config, 'optionalAccess', _11 => _11.logLevel]) || "off",
1125
+ baseURL: _optionalChain([config, 'optionalAccess', _11 => _11.airtopUrl]),
1126
+ logLevel: _optionalChain([config, 'optionalAccess', _12 => _12.logLevel]) || "off",
855
1127
  defaultHeaders: {
856
1128
  "x-airtop-sdk-source": "typescript",
857
1129
  "x-airtop-sdk-version": version
858
1130
  }
859
1131
  }),
860
- log: _optionalChain([config, 'optionalAccess', _12 => _12.logger]) || new (0, _loglayer.LogLayer)({
1132
+ log: _optionalChain([config, 'optionalAccess', _13 => _13.logger]) || new (0, _loglayer.LogLayer)({
861
1133
  errorSerializer: _serializeerror.serializeError,
862
1134
  transport: new (0, _loglayer.ConsoleTransport)({
863
1135
  logger: console,
@@ -868,7 +1140,8 @@ var AirtopClient = class extends AirtopBase {
868
1140
  contextFieldName: "context",
869
1141
  metadataFieldName: "metadata"
870
1142
  }),
871
- outputSchemaAdapter: config.outputSchemaAdapter
1143
+ outputSchemaAdapter: config.outputSchemaAdapter,
1144
+ jobId: config.jobId
872
1145
  });
873
1146
  this.log.withPrefix("[Airtop SDK]");
874
1147
  this.client.logLevel = config.logLevel;
@@ -894,8 +1167,8 @@ var AirtopClient = class extends AirtopBase {
894
1167
  * @returns A new AirtopSession instance
895
1168
  */
896
1169
  async createSession(config, options = {}) {
897
- const skipWaitSessionReady = _nullishCoalesce(config.skipWaitSessionReady, () => ( false));
898
- delete config.skipWaitSessionReady;
1170
+ const skipWaitSessionReady = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _14 => _14.skipWaitSessionReady]), () => ( false));
1171
+ _optionalChainDelete([config, 'optionalAccess', _15 => delete _15.skipWaitSessionReady]);
899
1172
  const sessionResponse = await this.client.sessions.create(
900
1173
  {
901
1174
  configuration: config
@@ -1003,23 +1276,6 @@ var AirtopClient = class extends AirtopBase {
1003
1276
  async getFile(fileId, requestOptions = {}) {
1004
1277
  return this.client.files.get(fileId, this.resolveRequestOptions(requestOptions));
1005
1278
  }
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
1279
  /**
1024
1280
  * Removes a file by ID.
1025
1281
  * @param fileId - ID of the file to remove
@@ -1028,6 +1284,14 @@ var AirtopClient = class extends AirtopBase {
1028
1284
  async removeFile(fileId, requestOptions = {}) {
1029
1285
  return this.client.files.delete(fileId, this.resolveRequestOptions(requestOptions));
1030
1286
  }
1287
+ /**
1288
+ * List files
1289
+ * @param query
1290
+ * @param requestOptions
1291
+ */
1292
+ async listFiles(query, requestOptions = {}) {
1293
+ return this.client.files.list(query, this.resolveRequestOptions(requestOptions));
1294
+ }
1031
1295
  /**
1032
1296
  * List all automations
1033
1297
  * @param requestOptions - Request options
@@ -1191,5 +1455,6 @@ var AirtopMocks = class {
1191
1455
 
1192
1456
 
1193
1457
 
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;
1458
+
1459
+ 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
1460
  //# sourceMappingURL=index.cjs.map