@airtop/sdk 1.0.0-alpha2.26 → 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.26",
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",
@@ -85,6 +86,11 @@ var require_package = __commonJS({
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,32 +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 = {
1284
- parameters: {
1285
- prompt: parameters.prompt,
1286
- services: parameters.services,
1287
- outputSchema: parameters.outputSchema ? this.convertToJsonSchema(parameters.outputSchema) : void 0
1288
- }
1289
- };
1364
+ const parameters2 = { prompt, services: service };
1365
+ const body2 = { parameters: parameters2 };
1290
1366
  return withRequestCompletionPolling(
1291
1367
  this.client,
1292
- () => this.client.sessions.service(this.sessionId, body),
1293
- options
1368
+ () => this.client.sessions.service(this.sessionId, body2),
1369
+ options2
1294
1370
  );
1295
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
+ );
1296
1387
  }
1297
1388
  /**
1298
1389
  * Retrieves the list of connected services available for the current session.
@@ -1306,6 +1397,58 @@ var AirtopSessionClient = class extends AirtopBase {
1306
1397
  requestOptions
1307
1398
  );
1308
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
+ }
1309
1452
  };
1310
1453
 
1311
1454
  // src/session/AirtopSession.ts
@@ -1364,19 +1507,19 @@ var AirtopClient = class extends AirtopBase {
1364
1507
  */
1365
1508
  constructor(config) {
1366
1509
  super({
1367
- logLevel: _optionalChain([config, 'optionalAccess', _19 => _19.logLevel]),
1510
+ logLevel: _optionalChain([config, 'optionalAccess', _20 => _20.logLevel]),
1368
1511
  client: new (0, _core.Airtop)({
1369
1512
  maxRetries: 0,
1370
1513
  timeout: _secondsToMilliseconds.secondsToMilliseconds.call(void 0, _nullishCoalesce(config.defaultTimeoutInSeconds, () => ( TIMEOUT_SECONDS_DEFAULT_VALUE))),
1371
1514
  apiKey: config.apiKey,
1372
- baseURL: _optionalChain([config, 'optionalAccess', _20 => _20.airtopUrl]),
1373
- 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",
1374
1517
  defaultHeaders: {
1375
1518
  "x-airtop-sdk-source": "typescript",
1376
1519
  "x-airtop-sdk-version": version
1377
1520
  }
1378
1521
  }),
1379
- log: _optionalChain([config, 'optionalAccess', _22 => _22.logger]) || new (0, _loglayer.LogLayer)({
1522
+ log: _optionalChain([config, 'optionalAccess', _23 => _23.logger]) || new (0, _loglayer.LogLayer)({
1380
1523
  errorSerializer: _serializeerror.serializeError,
1381
1524
  transport: new (0, _loglayer.ConsoleTransport)({
1382
1525
  logger: console,
@@ -1416,8 +1559,8 @@ var AirtopClient = class extends AirtopBase {
1416
1559
  * @returns A new AirtopSession instance
1417
1560
  */
1418
1561
  async createSession(config, options = {}) {
1419
- const skipWaitSessionReady = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _23 => _23.skipWaitSessionReady]), () => ( false));
1420
- _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]);
1421
1564
  const sessionResponse = await this.client.sessions.create(
1422
1565
  {
1423
1566
  configuration: config
@@ -1505,6 +1648,13 @@ var AirtopClient = class extends AirtopBase {
1505
1648
  withSessionId(sessionId) {
1506
1649
  return new AirtopSessionClient(this.getCommonConfig(), sessionId);
1507
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
+ }
1508
1658
  /**
1509
1659
  * Retrieves the status of a request.
1510
1660
  * @param requestId - ID of the request to check
@@ -1517,29 +1667,25 @@ var AirtopClient = class extends AirtopBase {
1517
1667
  }).info("Getting request status");
1518
1668
  return this.client.requests.getRequestStatus(requestId, this.resolveRequestOptions(requestOptions));
1519
1669
  }
1520
- /**
1521
- * Gets a file by ID.
1522
- * @param fileId
1523
- * @param requestOptions
1524
- */
1525
- async getFile(fileId, requestOptions = {}) {
1526
- return this.client.files.get(fileId, this.resolveRequestOptions(requestOptions));
1527
- }
1528
- /**
1529
- * Removes a file by ID.
1530
- * @param fileId - ID of the file to remove
1531
- * @param requestOptions - Request options
1532
- */
1533
- async removeFile(fileId, requestOptions = {}) {
1534
- return this.client.files.delete(fileId, this.resolveRequestOptions(requestOptions));
1535
- }
1536
1670
  /**
1537
1671
  * List files
1538
- * @param query
1539
- * @param requestOptions
1672
+ * @param query - File list parameters
1673
+ * @param requestOptions - Request options
1674
+ * @returns Object containing pagination info and array of AirtopFile instances
1540
1675
  */
1541
1676
  async listFiles(query, requestOptions = {}) {
1542
- 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
+ };
1543
1689
  }
1544
1690
  /**
1545
1691
  * List all automations
@@ -1670,19 +1816,19 @@ var AirtopAgentClient = class extends AirtopBase {
1670
1816
  */
1671
1817
  constructor(config) {
1672
1818
  super({
1673
- logLevel: _optionalChain([config, 'optionalAccess', _25 => _25.logLevel]),
1819
+ logLevel: _optionalChain([config, 'optionalAccess', _26 => _26.logLevel]),
1674
1820
  client: new (0, _core.Airtop)({
1675
1821
  maxRetries: 0,
1676
1822
  timeout: _datefns.minutesToMilliseconds.call(void 0, 1),
1677
1823
  apiKey: config.apiKey,
1678
- baseURL: _optionalChain([config, 'optionalAccess', _26 => _26.airtopUrl]),
1679
- 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",
1680
1826
  defaultHeaders: {
1681
1827
  "x-airtop-sdk-source": "typescript",
1682
1828
  "x-airtop-sdk-version": _process.version
1683
1829
  }
1684
1830
  }),
1685
- log: _optionalChain([config, 'optionalAccess', _28 => _28.logger]) || new (0, _loglayer.LogLayer)({
1831
+ log: _optionalChain([config, 'optionalAccess', _29 => _29.logger]) || new (0, _loglayer.LogLayer)({
1686
1832
  errorSerializer: _serializeerror.serializeError,
1687
1833
  transport: new (0, _loglayer.ConsoleTransport)({
1688
1834
  logger: console,
@@ -1922,5 +2068,10 @@ function registerAirtopPlugin(plugin) {
1922
2068
 
1923
2069
 
1924
2070
 
1925
- 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;
1926
2077
  //# sourceMappingURL=index.cjs.map