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

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
@@ -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.11",
12
+ version: "1.0.0-alpha2.12",
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.27",
50
+ "@airtop/core": "0.1.0-alpha.28",
51
51
  "date-fns": "4.1.0",
52
52
  loglayer: "6.3.3",
53
53
  "serialize-error": "12.0.0",
@@ -264,13 +264,23 @@ var processLogMessage = (log, logLevel, ...args) => {
264
264
  // src/session/AirtopSessionClient.ts
265
265
 
266
266
 
267
+ // src/types.ts
268
+ var AirtopError = class extends Error {
269
+
270
+ constructor(issues) {
271
+ const errorMessage = issues.map((issue) => issue.message).join("\n");
272
+ super(errorMessage);
273
+ this.issues = issues;
274
+ }
275
+ };
276
+
267
277
  // src/window/AirtopWindowClient.ts
268
278
 
269
279
 
270
280
  // src/async-utils.ts
271
281
 
272
282
  var DEFAULT_TIMEOUT_SECONDS = 300;
273
- var DEFAULT_POLLING_INTERVAL_SECONDS = 2;
283
+ var DEFAULT_POLLING_INTERVAL_MS = 500;
274
284
  async function waitForRequestCompletion(client, requestId, requestOptions) {
275
285
  const startTime = Date.now();
276
286
  const timeoutMs = _datefns.secondsToMilliseconds.call(void 0, _optionalChain([requestOptions, 'optionalAccess', _5 => _5.timeoutInSeconds]) || DEFAULT_TIMEOUT_SECONDS);
@@ -282,7 +292,7 @@ async function waitForRequestCompletion(client, requestId, requestOptions) {
282
292
  if (apiResponse.status === "error") {
283
293
  throw new Error(apiResponse.error);
284
294
  }
285
- await new Promise((resolve) => setTimeout(resolve, _datefns.secondsToMilliseconds.call(void 0, DEFAULT_POLLING_INTERVAL_SECONDS)));
295
+ await new Promise((resolve) => setTimeout(resolve, DEFAULT_POLLING_INTERVAL_MS));
286
296
  }
287
297
  throw new Error("Waiting for request timed out");
288
298
  }
@@ -811,7 +821,7 @@ var AirtopWindowClient = class extends AirtopBase {
811
821
  )
812
822
  );
813
823
  }
814
- async findOne(prompt, config, requestOptions = {}) {
824
+ async findOnePrivate(prompt, config, requestOptions = {}) {
815
825
  this.log.withMetadata({ prompt }).info("Executing LLM call");
816
826
  const apiResponse = await withRequestCompletionPolling(
817
827
  this.client,
@@ -829,15 +839,32 @@ var AirtopWindowClient = class extends AirtopBase {
829
839
  }
830
840
  )
831
841
  );
842
+ if (apiResponse.errors.length > 0) {
843
+ throw new AirtopError(apiResponse.errors);
844
+ }
832
845
  try {
846
+ if (!apiResponse.data.modelResponse) {
847
+ return null;
848
+ }
833
849
  const nodeData = JSON.parse(apiResponse.data.modelResponse);
850
+ if (Object.keys(nodeData).length === 0) {
851
+ return null;
852
+ }
834
853
  return new AirtopNode(this, nodeData);
835
854
  } catch (error) {
836
855
  this.log.withMetadata({ nodeDataStr: apiResponse.data.modelResponse }).withError(error).error("Error parsing node data");
837
856
  throw error;
838
857
  }
839
858
  }
840
- async findMany(prompt, config, requestOptions = {}) {
859
+ async findOne(prompt, config, requestOptions = {}) {
860
+ const configOverride = { ...config, optional: false };
861
+ return await this.findOnePrivate(prompt, configOverride, requestOptions);
862
+ }
863
+ async findOneOptional(prompt, config, requestOptions = {}) {
864
+ const configOverride = { ...config, optional: true };
865
+ return await this.findOnePrivate(prompt, configOverride, requestOptions);
866
+ }
867
+ async findManyPrivate(prompt, config, requestOptions = {}) {
841
868
  this.log.withMetadata({ prompt }).info("Executing LLM call");
842
869
  const apiResponse = await withRequestCompletionPolling(
843
870
  this.client,
@@ -855,15 +882,32 @@ var AirtopWindowClient = class extends AirtopBase {
855
882
  }
856
883
  )
857
884
  );
885
+ if (apiResponse.errors.length > 0) {
886
+ throw new AirtopError(apiResponse.errors);
887
+ }
858
888
  const nodeHandles = apiResponse.data.modelResponse.split("___DELIM___");
859
889
  return nodeHandles.map((nodeDataStr) => {
860
890
  try {
891
+ if (!nodeDataStr) {
892
+ return null;
893
+ }
861
894
  const nodeData = JSON.parse(nodeDataStr);
895
+ if (Object.keys(nodeData).length === 0) {
896
+ return null;
897
+ }
862
898
  return new AirtopNode(this, nodeData);
863
899
  } catch (error) {
864
900
  this.log.withMetadata({ nodeDataStr }).withError(error).error("Error parsing node data");
865
901
  }
866
- });
902
+ }).filter((node) => !!node);
903
+ }
904
+ async findMany(prompt, config, requestOptions = {}) {
905
+ const configOverride = { ...config, optional: false };
906
+ return await this.findManyPrivate(prompt, configOverride, requestOptions);
907
+ }
908
+ async findManyOptional(prompt, config, requestOptions = {}) {
909
+ const configOverride = { ...config, optional: true };
910
+ return await this.findManyPrivate(prompt, configOverride, requestOptions);
867
911
  }
868
912
  async waitForPage(config, requestOptions = {}) {
869
913
  return await withRequestCompletionPolling(
@@ -881,6 +925,23 @@ var AirtopWindowClient = class extends AirtopBase {
881
925
  )
882
926
  );
883
927
  }
928
+ async navigate(direction, config, requestOptions = {}) {
929
+ return await withRequestCompletionPolling(
930
+ this.client,
931
+ () => this.client.windows.navigate(
932
+ this.getWindowId(),
933
+ {
934
+ direction,
935
+ sessionId: this.sessionId,
936
+ ...config || {}
937
+ },
938
+ {
939
+ timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
940
+ ...this.resolveRequestOptions(requestOptions)
941
+ }
942
+ )
943
+ );
944
+ }
884
945
  };
885
946
 
886
947
  // src/window/AirtopWindow.ts
@@ -1317,6 +1378,13 @@ var AirtopClient = class extends AirtopBase {
1317
1378
  }
1318
1379
  };
1319
1380
 
1381
+ // src/window/AirtopWindowClient.types.ts
1382
+ var WindowNavigateDirection = /* @__PURE__ */ ((WindowNavigateDirection2) => {
1383
+ WindowNavigateDirection2["BACK"] = "backward";
1384
+ WindowNavigateDirection2["FORWARD"] = "forward";
1385
+ return WindowNavigateDirection2;
1386
+ })(WindowNavigateDirection || {});
1387
+
1320
1388
  // src/plugin/AirtopPlugin.types.ts
1321
1389
  var AirtopPluginAugmentationType = /* @__PURE__ */ ((AirtopPluginAugmentationType2) => {
1322
1390
  AirtopPluginAugmentationType2["AirtopClient"] = "AirtopClient";
@@ -1456,5 +1524,7 @@ var AirtopMocks = class {
1456
1524
 
1457
1525
 
1458
1526
 
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;
1527
+
1528
+
1529
+ exports.AirtopBase = AirtopBase; exports.AirtopClient = AirtopClient; exports.AirtopError = AirtopError; 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.WindowNavigateDirection = WindowNavigateDirection; exports.registerAirtopPlugin = registerAirtopPlugin;
1460
1530
  //# sourceMappingURL=index.cjs.map