@airtop/sdk 1.0.0-alpha2.16 → 1.0.0-alpha2.17

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.16",
12
+ version: "1.0.0-alpha2.17",
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.29",
50
+ "@airtop/core": "0.1.0-alpha.30",
51
51
  "date-fns": "4.1.0",
52
52
  loglayer: "6.3.3",
53
53
  "serialize-error": "12.0.0",
@@ -290,7 +290,7 @@ async function waitForRequestCompletion(client, requestId, requestOptions) {
290
290
  const startTime = Date.now();
291
291
  const timeoutMs = _datefns.secondsToMilliseconds.call(void 0, _optionalChain([requestOptions, 'optionalAccess', _5 => _5.timeoutInSeconds]) || DEFAULT_TIMEOUT_SECONDS);
292
292
  while (Date.now() - startTime < timeoutMs) {
293
- const apiResponse = await client.requests.getRequestStatus(requestId, requestOptions);
293
+ const apiResponse = await client.requests.getRequestStatusV2(requestId, requestOptions);
294
294
  if (apiResponse.status === "completed") {
295
295
  return apiResponse.response;
296
296
  }
@@ -302,8 +302,15 @@ async function waitForRequestCompletion(client, requestId, requestOptions) {
302
302
  throw new Error("Waiting for request timed out");
303
303
  }
304
304
  async function withRequestCompletionPolling(client, fn, requestOptions) {
305
- const response = await fn();
306
- return waitForRequestCompletion(client, response.requestId, requestOptions);
305
+ try {
306
+ const response = await fn();
307
+ return waitForRequestCompletion(client, response.requestId, requestOptions);
308
+ } catch (thrownError) {
309
+ if (_optionalChain([thrownError, 'access', _6 => _6.error, 'optionalAccess', _7 => _7.errors])) {
310
+ throw new AirtopError(thrownError.error.errors);
311
+ }
312
+ throw thrownError;
313
+ }
307
314
  }
308
315
 
309
316
  // src/window/AirtopNode.ts
@@ -675,7 +682,7 @@ var AirtopWindowClient = class extends AirtopBase {
675
682
  prompt
676
683
  }).info("Performing a page query");
677
684
  const newConfig = config;
678
- if (_optionalChain([config, 'optionalAccess', _6 => _6.configuration, 'access', _7 => _7.outputSchema])) {
685
+ if (_optionalChain([config, 'optionalAccess', _8 => _8.configuration, 'access', _9 => _9.outputSchema])) {
679
686
  newConfig.configuration.outputSchema = this.convertToJsonSchema(config.configuration.outputSchema);
680
687
  }
681
688
  return this.client.windows.pageQuery(
@@ -703,7 +710,7 @@ var AirtopWindowClient = class extends AirtopBase {
703
710
  prompt
704
711
  }).info("Performing a paginated extraction");
705
712
  const newConfig = config;
706
- if (_optionalChain([config, 'optionalAccess', _8 => _8.configuration, 'access', _9 => _9.outputSchema])) {
713
+ if (_optionalChain([config, 'optionalAccess', _10 => _10.configuration, 'access', _11 => _11.outputSchema])) {
707
714
  newConfig.configuration.outputSchema = this.convertToJsonSchema(config.configuration.outputSchema);
708
715
  }
709
716
  return this.client.windows.paginatedExtraction(
@@ -851,6 +858,7 @@ var AirtopWindowClient = class extends AirtopBase {
851
858
  {
852
859
  prompt,
853
860
  sessionId: this.sessionId,
861
+ jobId: this.jobId,
854
862
  ...config || {}
855
863
  },
856
864
  {
@@ -882,16 +890,12 @@ var AirtopWindowClient = class extends AirtopBase {
882
890
  throw new AirtopError(apiResponse.errors);
883
891
  }
884
892
  try {
885
- if (!apiResponse.data.modelResponse) {
886
- return null;
887
- }
888
- const nodeData = JSON.parse(apiResponse.data.modelResponse);
889
- if (Object.keys(nodeData).length === 0) {
893
+ if (!apiResponse.data.nodeHandle) {
890
894
  return null;
891
895
  }
892
- return new AirtopNode(this, nodeData);
896
+ return new AirtopNode(this, apiResponse.data.nodeHandle);
893
897
  } catch (error) {
894
- this.log.withMetadata({ nodeDataStr: apiResponse.data.modelResponse }).withError(error).error("Error parsing node data");
898
+ this.log.withMetadata({ nodeDataStr: apiResponse.data.nodeHandle }).withError(error).error("Error parsing node data");
895
899
  throw error;
896
900
  }
897
901
  }
@@ -924,21 +928,8 @@ var AirtopWindowClient = class extends AirtopBase {
924
928
  if (apiResponse.errors.length > 0) {
925
929
  throw new AirtopError(apiResponse.errors);
926
930
  }
927
- const nodeHandles = apiResponse.data.modelResponse.split("___DELIM___");
928
- return nodeHandles.map((nodeDataStr) => {
929
- try {
930
- if (!nodeDataStr) {
931
- return null;
932
- }
933
- const nodeData = JSON.parse(nodeDataStr);
934
- if (Object.keys(nodeData).length === 0) {
935
- return null;
936
- }
937
- return new AirtopNode(this, nodeData);
938
- } catch (error) {
939
- this.log.withMetadata({ nodeDataStr }).withError(error).error("Error parsing node data");
940
- }
941
- }).filter((node) => !!node);
931
+ const nodeHandleData = apiResponse.data.nodeHandles;
932
+ return nodeHandleData.map((nodeHandle) => new AirtopNode(this, nodeHandle));
942
933
  }
943
934
  async findMany(prompt, config, requestOptions = {}) {
944
935
  const configOverride = { ...config, optional: false };
@@ -955,6 +946,7 @@ var AirtopWindowClient = class extends AirtopBase {
955
946
  this.getWindowId(),
956
947
  {
957
948
  sessionId: this.sessionId,
949
+ jobId: this.jobId,
958
950
  ...config || {}
959
951
  },
960
952
  {
@@ -972,6 +964,7 @@ var AirtopWindowClient = class extends AirtopBase {
972
964
  {
973
965
  direction,
974
966
  sessionId: this.sessionId,
967
+ jobId: this.jobId,
975
968
  ...config || {}
976
969
  },
977
970
  {
@@ -1230,19 +1223,19 @@ var AirtopClient = class extends AirtopBase {
1230
1223
  */
1231
1224
  constructor(config) {
1232
1225
  super({
1233
- logLevel: _optionalChain([config, 'optionalAccess', _10 => _10.logLevel]),
1226
+ logLevel: _optionalChain([config, 'optionalAccess', _12 => _12.logLevel]),
1234
1227
  client: new (0, _core.Airtop)({
1235
1228
  maxRetries: 0,
1236
1229
  timeout: _minutesToMilliseconds.minutesToMilliseconds.call(void 0, 1),
1237
1230
  apiKey: config.apiKey,
1238
- baseURL: _optionalChain([config, 'optionalAccess', _11 => _11.airtopUrl]),
1239
- logLevel: _optionalChain([config, 'optionalAccess', _12 => _12.logLevel]) || "off",
1231
+ baseURL: _optionalChain([config, 'optionalAccess', _13 => _13.airtopUrl]),
1232
+ logLevel: _optionalChain([config, 'optionalAccess', _14 => _14.logLevel]) || "off",
1240
1233
  defaultHeaders: {
1241
1234
  "x-airtop-sdk-source": "typescript",
1242
1235
  "x-airtop-sdk-version": version
1243
1236
  }
1244
1237
  }),
1245
- log: _optionalChain([config, 'optionalAccess', _13 => _13.logger]) || new (0, _loglayer.LogLayer)({
1238
+ log: _optionalChain([config, 'optionalAccess', _15 => _15.logger]) || new (0, _loglayer.LogLayer)({
1246
1239
  errorSerializer: _serializeerror.serializeError,
1247
1240
  transport: new (0, _loglayer.ConsoleTransport)({
1248
1241
  logger: console,
@@ -1281,8 +1274,8 @@ var AirtopClient = class extends AirtopBase {
1281
1274
  * @returns A new AirtopSession instance
1282
1275
  */
1283
1276
  async createSession(config, options = {}) {
1284
- const skipWaitSessionReady = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _14 => _14.skipWaitSessionReady]), () => ( false));
1285
- _optionalChainDelete([config, 'optionalAccess', _15 => delete _15.skipWaitSessionReady]);
1277
+ const skipWaitSessionReady = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _16 => _16.skipWaitSessionReady]), () => ( false));
1278
+ _optionalChainDelete([config, 'optionalAccess', _17 => delete _17.skipWaitSessionReady]);
1286
1279
  const sessionResponse = await this.client.sessions.create(
1287
1280
  {
1288
1281
  configuration: config
@@ -1489,19 +1482,19 @@ var AirtopAgentClient = class extends AirtopBase {
1489
1482
  */
1490
1483
  constructor(config) {
1491
1484
  super({
1492
- logLevel: _optionalChain([config, 'optionalAccess', _16 => _16.logLevel]),
1485
+ logLevel: _optionalChain([config, 'optionalAccess', _18 => _18.logLevel]),
1493
1486
  client: new (0, _core.Airtop)({
1494
1487
  maxRetries: 0,
1495
1488
  timeout: _datefns.minutesToMilliseconds.call(void 0, 1),
1496
1489
  apiKey: config.apiKey,
1497
- baseURL: _optionalChain([config, 'optionalAccess', _17 => _17.airtopUrl]),
1498
- logLevel: _optionalChain([config, 'optionalAccess', _18 => _18.logLevel]) || "off",
1490
+ baseURL: _optionalChain([config, 'optionalAccess', _19 => _19.airtopUrl]),
1491
+ logLevel: _optionalChain([config, 'optionalAccess', _20 => _20.logLevel]) || "off",
1499
1492
  defaultHeaders: {
1500
1493
  "x-airtop-sdk-source": "typescript",
1501
1494
  "x-airtop-sdk-version": _process.version
1502
1495
  }
1503
1496
  }),
1504
- log: _optionalChain([config, 'optionalAccess', _19 => _19.logger]) || new (0, _loglayer.LogLayer)({
1497
+ log: _optionalChain([config, 'optionalAccess', _21 => _21.logger]) || new (0, _loglayer.LogLayer)({
1505
1498
  errorSerializer: _serializeerror.serializeError,
1506
1499
  transport: new (0, _loglayer.ConsoleTransport)({
1507
1500
  logger: console,