@airtop/sdk 1.0.0-alpha2.25 → 1.0.0-alpha2.27

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; } function _optionalChainDelete(ops) { const result = _optionalChain(ops); return result == null ? true : result; }var __getOwnPropNames = Object.getOwnPropertyNames;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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.25",
12
+ version: "1.0.0-alpha2.27",
13
13
  type: "module",
14
14
  main: "./dist/index.cjs",
15
15
  module: "./dist/index.js",
@@ -38,7 +38,8 @@ var require_package = __commonJS({
38
38
  "agentic"
39
39
  ],
40
40
  scripts: {
41
- "test:e2e": "vitest --run",
41
+ "test:e2e": "vitest --run --max-concurrency=1 --no-file-parallelism",
42
+ "test:e2e:parallel": "vitest --run",
42
43
  "build:dev": "node_modules/.bin/hash-runner",
43
44
  build: "tsup src/index.ts",
44
45
  clean: "rm -rf .turbo node_modules dist",
@@ -47,16 +48,16 @@ var require_package = __commonJS({
47
48
  "verify-types": "tsc --noEmit && tsc --noEmit --project tsconfig.e2e.json"
48
49
  },
49
50
  dependencies: {
50
- "@airtop/core": "0.1.0-alpha.41",
51
+ "@airtop/core": "0.1.0-alpha.42",
51
52
  "@airtop/json-schema-adapter": "workspace:*",
52
53
  "date-fns": "4.1.0",
53
- loglayer: "6.6.0",
54
+ loglayer: "6.7.0",
54
55
  "serialize-error": "12.0.0",
55
56
  uuid: "11.1.0"
56
57
  },
57
58
  devDependencies: {
58
- "@biomejs/biome": "2.2.0",
59
- "@dotenvx/dotenvx": "1.48.4",
59
+ "@biomejs/biome": "2.2.4",
60
+ "@dotenvx/dotenvx": "1.49.1",
60
61
  "@internal/tsconfig": "workspace:*",
61
62
  "deep-utility-types": "1.3.1",
62
63
  "env-var": "7.5.0",
@@ -80,11 +81,16 @@ var require_package = __commonJS({
80
81
  optionalDependencies: {
81
82
  "@airtop/json-schema-adapter-zod": "workspace:*"
82
83
  },
83
- packageManager: "pnpm@10.14.0"
84
+ packageManager: "pnpm@10.17.0"
84
85
  };
85
86
  }
86
87
  });
87
88
 
89
+ // src/index.ts
90
+ var _indexjs = require('@airtop/core/resources/index.js'); var AirtopCore4 = _interopRequireWildcard(_indexjs);
91
+ var _sharedmjs = require('@airtop/core/resources/shared.mjs'); var AirtopCoreShared = _interopRequireWildcard(_sharedmjs);
92
+ var _windowsjs = require('@airtop/core/resources/windows.js'); var AirtopCoreWindows = _interopRequireWildcard(_windowsjs);
93
+
88
94
  // src/AirtopBase.ts
89
95
  var _datefns = require('date-fns');
90
96
 
@@ -235,6 +241,90 @@ var _secondsToMilliseconds = require('date-fns/secondsToMilliseconds');
235
241
  var _loglayer = require('loglayer');
236
242
  var _serializeerror = require('serialize-error');
237
243
 
244
+ // src/file/AirtopFileClient.ts
245
+ var AirtopFileClient = class extends AirtopBase {
246
+ /**
247
+ * The file id
248
+ * @internal
249
+ */
250
+
251
+ /**
252
+ * Creates a new AirtopFileClient instance.
253
+ * @param config - Common configuration options
254
+ * @param fileId - File id
255
+ */
256
+ constructor(config, fileId) {
257
+ super(config);
258
+ this.log = this.log.child().withContext({
259
+ fileId
260
+ });
261
+ this.fileId = fileId;
262
+ }
263
+ /**
264
+ * Gets a file by ID.
265
+ * @param requestOptions
266
+ * @returns AirtopFile instance
267
+ */
268
+ async getFile(requestOptions = {}) {
269
+ const results = await this.client.files.get(this.fileId, this.resolveRequestOptions(requestOptions));
270
+ return new AirtopFile(this.getCommonConfig(), results);
271
+ }
272
+ /**
273
+ * Removes a file by ID.
274
+ * @param requestOptions - Request options
275
+ */
276
+ async removeFile(requestOptions = {}) {
277
+ return this.client.files.delete(this.fileId, this.resolveRequestOptions(requestOptions));
278
+ }
279
+ };
280
+
281
+ // src/file/AirtopFile.ts
282
+ var AirtopFile = class extends AirtopFileClient {
283
+ /**
284
+ * The file data containing details such as the id, file name, type, and download URL.
285
+ * Includes all information about the file that was processed or retrieved.
286
+ */
287
+
288
+ /**
289
+ * The metadata associated with the file operation.
290
+ * Contains information about the request that processed the file.
291
+ */
292
+
293
+ /**
294
+ * Warnings that occurred during file processing or operation.
295
+ * These are non-fatal issues that didn't prevent file processing.
296
+ */
297
+
298
+ /**
299
+ * Errors that occurred during file processing or operation.
300
+ * These are fatal issues that prevented file processing.
301
+ */
302
+
303
+ /**
304
+ * Creates a new AirtopFile instance.
305
+ * @param config - Common configuration options for the file
306
+ * @param fileData - File data
307
+ */
308
+ constructor(config, fileData) {
309
+ super(config, fileData.data.id);
310
+ this.meta = fileData.meta;
311
+ this.data = fileData.data;
312
+ this.warnings = fileData.warnings;
313
+ this.errors = fileData.errors;
314
+ }
315
+ /**
316
+ * Returns response data as a JSON object.
317
+ */
318
+ toJSON() {
319
+ return {
320
+ data: this.data,
321
+ meta: this.meta,
322
+ warnings: this.warnings,
323
+ errors: this.errors
324
+ };
325
+ }
326
+ };
327
+
238
328
  // src/logger-utils.ts
239
329
  var processLogMessage = (log, logLevel, ...args) => {
240
330
  if (logLevel === "off") {
@@ -1091,7 +1181,7 @@ var AirtopSessionClient = class extends AirtopBase {
1091
1181
  */
1092
1182
 
1093
1183
  /**
1094
- * Creates a new AirtopSession instance.
1184
+ * Creates a new AirtopSessionClient instance.
1095
1185
  * @param config - Common configuration options for the session
1096
1186
  * @param sessionId - Browser session id
1097
1187
  */
@@ -1218,10 +1308,11 @@ var AirtopSessionClient = class extends AirtopBase {
1218
1308
  * @param fileName - The name of the file to create
1219
1309
  * @param config - Additional configuration options for creating the file
1220
1310
  * @param requestOptions - Request options
1311
+ * @returns AirtopFile instance
1221
1312
  */
1222
- createFile(fileName, config = {}, requestOptions = {}) {
1313
+ async createFile(fileName, config = {}, requestOptions = {}) {
1223
1314
  this.log.info("Creating file");
1224
- return this.client.files.createFile(
1315
+ const results = await this.client.files.createFile(
1225
1316
  {
1226
1317
  ...config,
1227
1318
  fileName,
@@ -1229,6 +1320,7 @@ var AirtopSessionClient = class extends AirtopBase {
1229
1320
  },
1230
1321
  this.resolveRequestOptions(requestOptions)
1231
1322
  );
1323
+ return new AirtopFile(this.getCommonConfig(), results);
1232
1324
  }
1233
1325
  async llm(prompt, config, requestOptions = {}) {
1234
1326
  this.log.withMetadata({ prompt }).info("Executing LLM call");
@@ -1267,26 +1359,31 @@ var AirtopSessionClient = class extends AirtopBase {
1267
1359
  if (typeof promptOrArgs === "string") {
1268
1360
  const prompt = promptOrArgs;
1269
1361
  const service = typeof serviceOrRequestOptions === "string" ? serviceOrRequestOptions : void 0;
1270
- const options = typeof serviceOrRequestOptions === "object" ? serviceOrRequestOptions : requestOptions;
1362
+ const options2 = typeof serviceOrRequestOptions === "object" ? serviceOrRequestOptions : requestOptions;
1271
1363
  this.log.withMetadata({ prompt }).info("Service");
1272
- const parameters = { prompt, services: service };
1273
- const body = { parameters };
1274
- return withRequestCompletionPolling(
1275
- this.client,
1276
- () => this.client.sessions.service(this.sessionId, body),
1277
- options
1278
- );
1279
- } else {
1280
- const parameters = promptOrArgs;
1281
- const options = serviceOrRequestOptions || {};
1282
- this.log.withMetadata({ parameters }).info("Service");
1283
- const body = { parameters };
1364
+ const parameters2 = { prompt, services: service };
1365
+ const body2 = { parameters: parameters2 };
1284
1366
  return withRequestCompletionPolling(
1285
1367
  this.client,
1286
- () => this.client.sessions.service(this.sessionId, body),
1287
- options
1368
+ () => this.client.sessions.service(this.sessionId, body2),
1369
+ options2
1288
1370
  );
1289
1371
  }
1372
+ const parameters = promptOrArgs;
1373
+ const options = serviceOrRequestOptions || {};
1374
+ this.log.withMetadata({ parameters }).info("Service");
1375
+ const body = {
1376
+ parameters: {
1377
+ prompt: parameters.prompt,
1378
+ services: parameters.services,
1379
+ outputSchema: parameters.outputSchema ? this.convertToJsonSchema(parameters.outputSchema) : void 0
1380
+ }
1381
+ };
1382
+ return withRequestCompletionPolling(
1383
+ this.client,
1384
+ () => this.client.sessions.service(this.sessionId, body),
1385
+ options
1386
+ );
1290
1387
  }
1291
1388
  /**
1292
1389
  * Retrieves the list of connected services available for the current session.
@@ -1300,6 +1397,58 @@ var AirtopSessionClient = class extends AirtopBase {
1300
1397
  requestOptions
1301
1398
  );
1302
1399
  }
1400
+ /**
1401
+ * Waits for a file to be downloaded in a session and reach 'available' status.
1402
+ * Defaults to looking back 5 seconds in the event stream for the file to be available.
1403
+ * Use `lookbackSeconds` to control this behavior.
1404
+ *
1405
+ * @param configuration - The optional configuration parameters for the function
1406
+ * @param configuration.lookbackSeconds - The number of seconds to look back for prior events. Default `5`. 0 means no lookback.
1407
+ * @param requestOptions - Optional request configuration including timeout
1408
+ * @returns Object containing file's id and downloadUrl, or null if timed out
1409
+ */
1410
+ async waitForDownload(configuration, requestOptions = {}) {
1411
+ const { lookbackSeconds = 5 } = configuration || {};
1412
+ this.log.info(`waiting for file to be available on session: ${this.sessionId}`);
1413
+ const startTime = /* @__PURE__ */ new Date();
1414
+ const timeoutSeconds = _optionalChain([requestOptions, 'optionalAccess', _19 => _19.timeoutInSeconds]) || 120;
1415
+ const timeoutPromise = new Promise((resolve) => {
1416
+ setTimeout(() => {
1417
+ this.log.info(`waiting for file timed out after ${timeoutSeconds} seconds`);
1418
+ resolve(null);
1419
+ }, timeoutSeconds * 1e3);
1420
+ });
1421
+ const processEventsPromise = (async () => {
1422
+ const sessionEvents = await this.client.sessions.getEvents(
1423
+ this.sessionId,
1424
+ { all: lookbackSeconds >= 0 },
1425
+ { timeoutInSeconds: timeoutSeconds, ...requestOptions || {} }
1426
+ );
1427
+ for await (const event of sessionEvents) {
1428
+ const e = event;
1429
+ if (e.event === "file_status") {
1430
+ if (e.status === "available") {
1431
+ const eventTime = Date.parse(e.eventTime);
1432
+ this.log.info(`file_status message received:
1433
+ ${JSON.stringify(event, null, 2)}`);
1434
+ const thresholdTime = startTime.getTime() - lookbackSeconds * 1e3;
1435
+ if (eventTime < thresholdTime) {
1436
+ this.log.info(
1437
+ `skipping file available event for ${e.fileId} because its timestamp is earlier than lookbackSeconds`
1438
+ );
1439
+ continue;
1440
+ }
1441
+ return {
1442
+ id: e.fileId,
1443
+ downloadUrl: e.downloadUrl
1444
+ };
1445
+ }
1446
+ }
1447
+ }
1448
+ return null;
1449
+ })();
1450
+ return Promise.race([timeoutPromise, processEventsPromise]);
1451
+ }
1303
1452
  };
1304
1453
 
1305
1454
  // src/session/AirtopSession.ts
@@ -1358,19 +1507,19 @@ var AirtopClient = class extends AirtopBase {
1358
1507
  */
1359
1508
  constructor(config) {
1360
1509
  super({
1361
- logLevel: _optionalChain([config, 'optionalAccess', _19 => _19.logLevel]),
1510
+ logLevel: _optionalChain([config, 'optionalAccess', _20 => _20.logLevel]),
1362
1511
  client: new (0, _core.Airtop)({
1363
1512
  maxRetries: 0,
1364
1513
  timeout: _secondsToMilliseconds.secondsToMilliseconds.call(void 0, _nullishCoalesce(config.defaultTimeoutInSeconds, () => ( TIMEOUT_SECONDS_DEFAULT_VALUE))),
1365
1514
  apiKey: config.apiKey,
1366
- baseURL: _optionalChain([config, 'optionalAccess', _20 => _20.airtopUrl]),
1367
- logLevel: _optionalChain([config, 'optionalAccess', _21 => _21.logLevel]) || "off",
1515
+ baseURL: _optionalChain([config, 'optionalAccess', _21 => _21.airtopUrl]),
1516
+ logLevel: _optionalChain([config, 'optionalAccess', _22 => _22.logLevel]) || "off",
1368
1517
  defaultHeaders: {
1369
1518
  "x-airtop-sdk-source": "typescript",
1370
1519
  "x-airtop-sdk-version": version
1371
1520
  }
1372
1521
  }),
1373
- log: _optionalChain([config, 'optionalAccess', _22 => _22.logger]) || new (0, _loglayer.LogLayer)({
1522
+ log: _optionalChain([config, 'optionalAccess', _23 => _23.logger]) || new (0, _loglayer.LogLayer)({
1374
1523
  errorSerializer: _serializeerror.serializeError,
1375
1524
  transport: new (0, _loglayer.ConsoleTransport)({
1376
1525
  logger: console,
@@ -1410,8 +1559,8 @@ var AirtopClient = class extends AirtopBase {
1410
1559
  * @returns A new AirtopSession instance
1411
1560
  */
1412
1561
  async createSession(config, options = {}) {
1413
- const skipWaitSessionReady = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _23 => _23.skipWaitSessionReady]), () => ( false));
1414
- _optionalChainDelete([config, 'optionalAccess', _24 => delete _24.skipWaitSessionReady]);
1562
+ const skipWaitSessionReady = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _24 => _24.skipWaitSessionReady]), () => ( false));
1563
+ _optionalChainDelete([config, 'optionalAccess', _25 => delete _25.skipWaitSessionReady]);
1415
1564
  const sessionResponse = await this.client.sessions.create(
1416
1565
  {
1417
1566
  configuration: config
@@ -1499,6 +1648,13 @@ var AirtopClient = class extends AirtopBase {
1499
1648
  withSessionId(sessionId) {
1500
1649
  return new AirtopSessionClient(this.getCommonConfig(), sessionId);
1501
1650
  }
1651
+ /**
1652
+ * Returns a file client instance for making file-based requests for a given file id.
1653
+ * @param fileId - The file ID to attach to the AirtopFileClient instance
1654
+ */
1655
+ withFileId(fileId) {
1656
+ return new AirtopFileClient(this.getCommonConfig(), fileId);
1657
+ }
1502
1658
  /**
1503
1659
  * Retrieves the status of a request.
1504
1660
  * @param requestId - ID of the request to check
@@ -1511,29 +1667,25 @@ var AirtopClient = class extends AirtopBase {
1511
1667
  }).info("Getting request status");
1512
1668
  return this.client.requests.getRequestStatus(requestId, this.resolveRequestOptions(requestOptions));
1513
1669
  }
1514
- /**
1515
- * Gets a file by ID.
1516
- * @param fileId
1517
- * @param requestOptions
1518
- */
1519
- async getFile(fileId, requestOptions = {}) {
1520
- return this.client.files.get(fileId, this.resolveRequestOptions(requestOptions));
1521
- }
1522
- /**
1523
- * Removes a file by ID.
1524
- * @param fileId - ID of the file to remove
1525
- * @param requestOptions - Request options
1526
- */
1527
- async removeFile(fileId, requestOptions = {}) {
1528
- return this.client.files.delete(fileId, this.resolveRequestOptions(requestOptions));
1529
- }
1530
1670
  /**
1531
1671
  * List files
1532
- * @param query
1533
- * @param requestOptions
1672
+ * @param query - File list parameters
1673
+ * @param requestOptions - Request options
1674
+ * @returns Object containing pagination info and array of AirtopFile instances
1534
1675
  */
1535
1676
  async listFiles(query, requestOptions = {}) {
1536
- return this.client.files.list(query, this.resolveRequestOptions(requestOptions));
1677
+ const files = await this.client.files.list(query, this.resolveRequestOptions(requestOptions));
1678
+ return {
1679
+ pagination: files.data.pagination,
1680
+ files: files.data.files.map(
1681
+ (file) => new AirtopFile(this.getCommonConfig(), {
1682
+ data: file
1683
+ })
1684
+ ),
1685
+ errors: files.errors,
1686
+ meta: files.meta,
1687
+ warnings: files.warnings
1688
+ };
1537
1689
  }
1538
1690
  /**
1539
1691
  * List all automations
@@ -1664,19 +1816,19 @@ var AirtopAgentClient = class extends AirtopBase {
1664
1816
  */
1665
1817
  constructor(config) {
1666
1818
  super({
1667
- logLevel: _optionalChain([config, 'optionalAccess', _25 => _25.logLevel]),
1819
+ logLevel: _optionalChain([config, 'optionalAccess', _26 => _26.logLevel]),
1668
1820
  client: new (0, _core.Airtop)({
1669
1821
  maxRetries: 0,
1670
1822
  timeout: _datefns.minutesToMilliseconds.call(void 0, 1),
1671
1823
  apiKey: config.apiKey,
1672
- baseURL: _optionalChain([config, 'optionalAccess', _26 => _26.airtopUrl]),
1673
- logLevel: _optionalChain([config, 'optionalAccess', _27 => _27.logLevel]) || "off",
1824
+ baseURL: _optionalChain([config, 'optionalAccess', _27 => _27.airtopUrl]),
1825
+ logLevel: _optionalChain([config, 'optionalAccess', _28 => _28.logLevel]) || "off",
1674
1826
  defaultHeaders: {
1675
1827
  "x-airtop-sdk-source": "typescript",
1676
1828
  "x-airtop-sdk-version": _process.version
1677
1829
  }
1678
1830
  }),
1679
- log: _optionalChain([config, 'optionalAccess', _28 => _28.logger]) || new (0, _loglayer.LogLayer)({
1831
+ log: _optionalChain([config, 'optionalAccess', _29 => _29.logger]) || new (0, _loglayer.LogLayer)({
1680
1832
  errorSerializer: _serializeerror.serializeError,
1681
1833
  transport: new (0, _loglayer.ConsoleTransport)({
1682
1834
  logger: console,
@@ -1916,5 +2068,10 @@ function registerAirtopPlugin(plugin) {
1916
2068
 
1917
2069
 
1918
2070
 
1919
- exports.AirtopAgentClient = AirtopAgentClient; 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;
2071
+
2072
+
2073
+
2074
+
2075
+
2076
+ exports.AirtopAgentClient = AirtopAgentClient; exports.AirtopBase = AirtopBase; exports.AirtopClient = AirtopClient; exports.AirtopCore = AirtopCore4; exports.AirtopCoreShared = AirtopCoreShared; exports.AirtopCoreWindows = AirtopCoreWindows; exports.AirtopError = AirtopError; exports.AirtopFile = AirtopFile; exports.AirtopFileClient = AirtopFileClient; 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;
1920
2077
  //# sourceMappingURL=index.cjs.map