@airtop/sdk 1.0.0-alpha2.40 → 1.0.0-alpha2.42

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.40",
12
+ version: "1.0.0-alpha2.42",
13
13
  type: "module",
14
14
  main: "./dist/index.cjs",
15
15
  module: "./dist/index.js",
@@ -48,7 +48,7 @@ var require_package = __commonJS({
48
48
  "verify-types": "tsc --noEmit && tsc --noEmit --project tsconfig.e2e.json"
49
49
  },
50
50
  dependencies: {
51
- "@airtop/core": "0.1.0-alpha.49",
51
+ "@airtop/core": "0.1.0-alpha.52",
52
52
  "@airtop/json-schema-adapter": "workspace:*",
53
53
  "date-fns": "4.1.0",
54
54
  loglayer: "8.1.0",
@@ -1133,6 +1133,29 @@ var AirtopWindowClient = class extends AirtopBase {
1133
1133
  )
1134
1134
  );
1135
1135
  }
1136
+ /**
1137
+ * Executes a computer use action in the window using AI-driven browser automation.
1138
+ * @param prompt - A natural language description of the action to perform
1139
+ * @param config - Configuration options for the computer use action
1140
+ * @param requestOptions - Request options
1141
+ * @returns Promise resolving to the computer use operation result
1142
+ */
1143
+ async computerUse(prompt, config, requestOptions = {}) {
1144
+ return await withRequestCompletionPolling(
1145
+ this.client,
1146
+ () => this.client.windows.computerUse(
1147
+ this.getWindowId(),
1148
+ {
1149
+ sessionId: this.sessionId,
1150
+ prompt,
1151
+ ...config || {}
1152
+ },
1153
+ {
1154
+ ...this.resolveRequestOptions(requestOptions)
1155
+ }
1156
+ )
1157
+ );
1158
+ }
1136
1159
  };
1137
1160
 
1138
1161
  // src/window/AirtopWindow.ts
@@ -1408,8 +1431,12 @@ var AirtopSessionClient = class extends AirtopBase {
1408
1431
  * Defaults to looking back 5 seconds in the event stream for the file to be available.
1409
1432
  * Use `lookbackSeconds` to control this behavior.
1410
1433
  *
1434
+ * This method uses a two-phase approach:
1435
+ * - Phase 1 (if lookbackSeconds > 0): Check historical events within the lookback window
1436
+ * - Phase 2: Wait for events from startTime forward until timeout (ensures no gap between phases)
1437
+ *
1411
1438
  * @param configuration - The optional configuration parameters for the function
1412
- * @param configuration.lookbackSeconds - The number of seconds to look back for prior events. Default `5`. 0 means no lookback.
1439
+ * @param configuration.lookbackSeconds - The number of seconds to look back for prior events. Default `5`. 0 means no lookback (only wait for new events).
1413
1440
  * @param configuration.fileType - The file type to wait for, such as "browser_download". If provided, only files of this type will be considered.
1414
1441
  * @param requestOptions - Optional request configuration including timeout
1415
1442
  * @returns Object containing file's id and downloadUrl, or null if timed out
@@ -1425,35 +1452,62 @@ var AirtopSessionClient = class extends AirtopBase {
1425
1452
  resolve(null);
1426
1453
  }, timeoutSeconds * 1e3);
1427
1454
  });
1455
+ const isQualifyingEvent = (e) => {
1456
+ if (e.event !== "file_status" || e.status !== "available") {
1457
+ return false;
1458
+ }
1459
+ if (fileType && e.type !== fileType) {
1460
+ this.log.info(`skipping file of type ${e.type} (looking for ${fileType})`);
1461
+ return false;
1462
+ }
1463
+ return true;
1464
+ };
1465
+ const createResult = (e) => ({
1466
+ id: e.fileId,
1467
+ downloadUrl: e.downloadUrl,
1468
+ fileName: e.name,
1469
+ fileType: e.type
1470
+ });
1428
1471
  const processEventsPromise = (async () => {
1429
- const sessionEvents = await this.client.sessions.getEvents(
1472
+ const thresholdTime = startTime.getTime() - lookbackSeconds * 1e3;
1473
+ if (lookbackSeconds > 0) {
1474
+ this.log.info(`Phase 1: checking historical events from last ${lookbackSeconds} seconds`);
1475
+ const historicalEvents = await this.client.sessions.getEvents(
1476
+ this.sessionId,
1477
+ { all: true, reverse: true },
1478
+ { timeoutInSeconds: timeoutSeconds, ...requestOptions || {} }
1479
+ );
1480
+ for await (const event of historicalEvents) {
1481
+ const e = event;
1482
+ const eventTime = Date.parse(e.eventTime);
1483
+ if (eventTime < thresholdTime) {
1484
+ this.log.info(`Phase 1: reached lookback threshold, no matching file found in history`);
1485
+ break;
1486
+ }
1487
+ if (isQualifyingEvent(e)) {
1488
+ this.log.info(`Phase 1: found file in history:
1489
+ ${JSON.stringify(event, null, 2)}`);
1490
+ return createResult(e);
1491
+ }
1492
+ }
1493
+ }
1494
+ this.log.info(`Phase 2: waiting for download events from ${startTime.toISOString()} forward`);
1495
+ const newEvents = await this.client.sessions.getEvents(
1430
1496
  this.sessionId,
1431
- { all: lookbackSeconds >= 0, reverse: true },
1497
+ { all: true, reverse: false },
1432
1498
  { timeoutInSeconds: timeoutSeconds, ...requestOptions || {} }
1433
1499
  );
1434
- for await (const event of sessionEvents) {
1500
+ const startTimeMs = startTime.getTime();
1501
+ for await (const event of newEvents) {
1435
1502
  const e = event;
1436
- if (e.event === "file_status") {
1437
- if (e.status === "available") {
1438
- const eventTime = Date.parse(e.eventTime);
1439
- this.log.info(`file_status message received:
1503
+ const eventTime = Date.parse(e.eventTime);
1504
+ if (eventTime < startTimeMs) {
1505
+ continue;
1506
+ }
1507
+ if (isQualifyingEvent(e)) {
1508
+ this.log.info(`Phase 2: found download event:
1440
1509
  ${JSON.stringify(event, null, 2)}`);
1441
- if (fileType && e.type !== fileType) {
1442
- this.log.info(`skipping file of type ${e.type} (looking for ${fileType})`);
1443
- continue;
1444
- }
1445
- const thresholdTime = startTime.getTime() - lookbackSeconds * 1e3;
1446
- if (eventTime < thresholdTime) {
1447
- this.log.info(`stopping event processing - encountered event older than lookbackSeconds threshold`);
1448
- break;
1449
- }
1450
- return {
1451
- id: e.fileId,
1452
- downloadUrl: e.downloadUrl,
1453
- fileName: e.name,
1454
- fileType: e.type
1455
- };
1456
- }
1510
+ return createResult(e);
1457
1511
  }
1458
1512
  }
1459
1513
  return null;