@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 +213 -56
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +318 -30
- package/dist/index.d.ts +318 -30
- package/dist/index.js +201 -44
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
package/dist/index.js
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.
|
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.
|
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.
|
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.
|
59
|
-
"@dotenvx/dotenvx": "1.
|
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.
|
84
|
+
packageManager: "pnpm@10.17.0"
|
84
85
|
};
|
85
86
|
}
|
86
87
|
});
|
87
88
|
|
89
|
+
// src/index.ts
|
90
|
+
import * as AirtopCore4 from "@airtop/core/resources/index.js";
|
91
|
+
import * as AirtopCoreShared from "@airtop/core/resources/shared.mjs";
|
92
|
+
import * as AirtopCoreWindows from "@airtop/core/resources/windows.js";
|
93
|
+
|
88
94
|
// src/AirtopBase.ts
|
89
95
|
import { secondsToMilliseconds } from "date-fns";
|
90
96
|
|
@@ -235,6 +241,90 @@ import { secondsToMilliseconds as secondsToMilliseconds3 } from "date-fns/second
|
|
235
241
|
import { ConsoleTransport, LogLayer } from "loglayer";
|
236
242
|
import { serializeError } from "serialize-error";
|
237
243
|
|
244
|
+
// src/file/AirtopFileClient.ts
|
245
|
+
var AirtopFileClient = class extends AirtopBase {
|
246
|
+
/**
|
247
|
+
* The file id
|
248
|
+
* @internal
|
249
|
+
*/
|
250
|
+
fileId;
|
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
|
+
data;
|
288
|
+
/**
|
289
|
+
* The metadata associated with the file operation.
|
290
|
+
* Contains information about the request that processed the file.
|
291
|
+
*/
|
292
|
+
meta;
|
293
|
+
/**
|
294
|
+
* Warnings that occurred during file processing or operation.
|
295
|
+
* These are non-fatal issues that didn't prevent file processing.
|
296
|
+
*/
|
297
|
+
warnings;
|
298
|
+
/**
|
299
|
+
* Errors that occurred during file processing or operation.
|
300
|
+
* These are fatal issues that prevented file processing.
|
301
|
+
*/
|
302
|
+
errors;
|
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
|
sessionId;
|
1093
1183
|
/**
|
1094
|
-
* Creates a new
|
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
|
-
|
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
|
1362
|
+
const options2 = typeof serviceOrRequestOptions === "object" ? serviceOrRequestOptions : requestOptions;
|
1271
1363
|
this.log.withMetadata({ prompt }).info("Service");
|
1272
|
-
const
|
1273
|
-
const
|
1364
|
+
const parameters2 = { prompt, services: service };
|
1365
|
+
const body2 = { parameters: parameters2 };
|
1274
1366
|
return withRequestCompletionPolling(
|
1275
1367
|
this.client,
|
1276
|
-
() => this.client.sessions.service(this.sessionId,
|
1277
|
-
|
1278
|
-
);
|
1279
|
-
} else {
|
1280
|
-
const parameters = promptOrArgs;
|
1281
|
-
const options = serviceOrRequestOptions || {};
|
1282
|
-
this.log.withMetadata({ parameters }).info("Service");
|
1283
|
-
const body = { parameters };
|
1284
|
-
return withRequestCompletionPolling(
|
1285
|
-
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 = requestOptions?.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
|
@@ -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
|
-
|
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
|
@@ -1905,7 +2057,12 @@ export {
|
|
1905
2057
|
AirtopAgentClient,
|
1906
2058
|
AirtopBase,
|
1907
2059
|
AirtopClient,
|
2060
|
+
AirtopCore4 as AirtopCore,
|
2061
|
+
AirtopCoreShared,
|
2062
|
+
AirtopCoreWindows,
|
1908
2063
|
AirtopError,
|
2064
|
+
AirtopFile,
|
2065
|
+
AirtopFileClient,
|
1909
2066
|
AirtopMocks,
|
1910
2067
|
AirtopNode,
|
1911
2068
|
AirtopPluginAugmentationType,
|