@airtop/sdk 1.0.0-alpha2.17 → 1.0.0-alpha2.18
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 +199 -97
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -6
- package/dist/index.d.ts +23 -6
- package/dist/index.js +189 -87
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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.
|
12
|
+
version: "1.0.0-alpha2.18",
|
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.
|
50
|
+
"@airtop/core": "0.1.0-alpha.33",
|
51
51
|
"date-fns": "4.1.0",
|
52
52
|
loglayer: "6.3.3",
|
53
53
|
"serialize-error": "12.0.0",
|
@@ -269,21 +269,25 @@ var processLogMessage = (log, logLevel, ...args) => {
|
|
269
269
|
// src/session/AirtopSessionClient.ts
|
270
270
|
|
271
271
|
|
272
|
+
|
273
|
+
// src/async-utils.ts
|
274
|
+
|
275
|
+
|
272
276
|
// src/types.ts
|
273
277
|
var AirtopError = class extends Error {
|
274
278
|
|
275
|
-
|
279
|
+
|
280
|
+
constructor(issues, metadata) {
|
276
281
|
const errorMessage = issues.map((issue) => issue.message).join("\n");
|
277
|
-
|
282
|
+
const errorMessageWithMetadata = metadata ? `${errorMessage}
|
283
|
+
${JSON.stringify(metadata)}` : errorMessage;
|
284
|
+
super(errorMessageWithMetadata);
|
278
285
|
this.issues = issues;
|
286
|
+
this.metadata = metadata;
|
279
287
|
}
|
280
288
|
};
|
281
289
|
|
282
|
-
// src/window/AirtopWindowClient.ts
|
283
|
-
|
284
|
-
|
285
290
|
// src/async-utils.ts
|
286
|
-
|
287
291
|
var DEFAULT_TIMEOUT_SECONDS = 300;
|
288
292
|
var DEFAULT_POLLING_INTERVAL_MS = 500;
|
289
293
|
async function waitForRequestCompletion(client, requestId, requestOptions) {
|
@@ -307,12 +311,17 @@ async function withRequestCompletionPolling(client, fn, requestOptions) {
|
|
307
311
|
return waitForRequestCompletion(client, response.requestId, requestOptions);
|
308
312
|
} catch (thrownError) {
|
309
313
|
if (_optionalChain([thrownError, 'access', _6 => _6.error, 'optionalAccess', _7 => _7.errors])) {
|
310
|
-
throw new AirtopError(thrownError.error.errors
|
314
|
+
throw new AirtopError(thrownError.error.errors, {
|
315
|
+
requestId: thrownError.error.requestId
|
316
|
+
});
|
311
317
|
}
|
312
318
|
throw thrownError;
|
313
319
|
}
|
314
320
|
}
|
315
321
|
|
322
|
+
// src/window/AirtopWindowClient.ts
|
323
|
+
|
324
|
+
|
316
325
|
// src/window/AirtopNode.ts
|
317
326
|
var AirtopNode = class {
|
318
327
|
/**
|
@@ -370,7 +379,7 @@ var AirtopNode = class {
|
|
370
379
|
* @param requestOptions - The request options to use for the LLM call
|
371
380
|
*/
|
372
381
|
async llm(prompt, config, requestOptions = {}) {
|
373
|
-
return this.windowClient.llm(prompt, config, requestOptions);
|
382
|
+
return this.windowClient.llm(prompt, { ...config, nodeHandleId: this.nodeHandleId }, requestOptions);
|
374
383
|
}
|
375
384
|
/**
|
376
385
|
* Find one element in the node
|
@@ -579,17 +588,20 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
579
588
|
this.log.withMetadata({
|
580
589
|
elementDescription
|
581
590
|
}).info("Clicking on element");
|
582
|
-
return
|
583
|
-
this.
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
591
|
+
return withRequestCompletionPolling(
|
592
|
+
this.client,
|
593
|
+
() => this.client.windows.clickAsync(
|
594
|
+
this.getWindowId(),
|
595
|
+
{
|
596
|
+
...config,
|
597
|
+
elementDescription,
|
598
|
+
sessionId: this.sessionId
|
599
|
+
},
|
600
|
+
{
|
601
|
+
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
602
|
+
...this.resolveRequestOptions(requestOptions)
|
603
|
+
}
|
604
|
+
)
|
593
605
|
);
|
594
606
|
}
|
595
607
|
/**
|
@@ -611,17 +623,20 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
611
623
|
*/
|
612
624
|
async hover(elementDescription, config, requestOptions = {}) {
|
613
625
|
this.log.withMetadata(config).info("Hovering over window");
|
614
|
-
return
|
615
|
-
this.
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
626
|
+
return withRequestCompletionPolling(
|
627
|
+
this.client,
|
628
|
+
() => this.client.windows.hoverAsync(
|
629
|
+
this.getWindowId(),
|
630
|
+
{
|
631
|
+
elementDescription,
|
632
|
+
sessionId: this.sessionId,
|
633
|
+
...config || {}
|
634
|
+
},
|
635
|
+
{
|
636
|
+
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
637
|
+
...this.resolveRequestOptions(requestOptions)
|
638
|
+
}
|
639
|
+
)
|
625
640
|
);
|
626
641
|
}
|
627
642
|
/**
|
@@ -657,17 +672,20 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
657
672
|
*/
|
658
673
|
async monitor(condition, config, requestOptions = {}) {
|
659
674
|
this.log.withMetadata().info("Monitoring window");
|
660
|
-
return
|
661
|
-
this.
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
675
|
+
return withRequestCompletionPolling(
|
676
|
+
this.client,
|
677
|
+
() => this.client.windows.monitorAsync(
|
678
|
+
this.getWindowId(),
|
679
|
+
{
|
680
|
+
condition,
|
681
|
+
sessionId: this.sessionId,
|
682
|
+
...config || {}
|
683
|
+
},
|
684
|
+
{
|
685
|
+
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
686
|
+
...this.resolveRequestOptions(requestOptions)
|
687
|
+
}
|
688
|
+
)
|
671
689
|
);
|
672
690
|
}
|
673
691
|
/**
|
@@ -685,17 +703,20 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
685
703
|
if (_optionalChain([config, 'optionalAccess', _8 => _8.configuration, 'access', _9 => _9.outputSchema])) {
|
686
704
|
newConfig.configuration.outputSchema = this.convertToJsonSchema(config.configuration.outputSchema);
|
687
705
|
}
|
688
|
-
return
|
689
|
-
this.
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
706
|
+
return withRequestCompletionPolling(
|
707
|
+
this.client,
|
708
|
+
() => this.client.windows.pageQueryAsync(
|
709
|
+
this.getWindowId(),
|
710
|
+
{
|
711
|
+
sessionId: this.sessionId,
|
712
|
+
prompt,
|
713
|
+
...newConfig || {}
|
714
|
+
},
|
715
|
+
{
|
716
|
+
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
717
|
+
...this.resolveRequestOptions(requestOptions)
|
718
|
+
}
|
719
|
+
)
|
699
720
|
);
|
700
721
|
}
|
701
722
|
/**
|
@@ -713,17 +734,20 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
713
734
|
if (_optionalChain([config, 'optionalAccess', _10 => _10.configuration, 'access', _11 => _11.outputSchema])) {
|
714
735
|
newConfig.configuration.outputSchema = this.convertToJsonSchema(config.configuration.outputSchema);
|
715
736
|
}
|
716
|
-
return
|
717
|
-
this.
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
737
|
+
return withRequestCompletionPolling(
|
738
|
+
this.client,
|
739
|
+
() => this.client.windows.paginatedExtractionAsync(
|
740
|
+
this.getWindowId(),
|
741
|
+
{
|
742
|
+
prompt,
|
743
|
+
sessionId: this.sessionId,
|
744
|
+
...newConfig || {}
|
745
|
+
},
|
746
|
+
{
|
747
|
+
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
748
|
+
...this.resolveRequestOptions(requestOptions)
|
749
|
+
}
|
750
|
+
)
|
727
751
|
);
|
728
752
|
}
|
729
753
|
/**
|
@@ -754,16 +778,19 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
754
778
|
*/
|
755
779
|
async screenshot(config, requestOptions = {}) {
|
756
780
|
this.log.info("Screenshotting window");
|
757
|
-
const resp = await
|
758
|
-
this.
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
781
|
+
const resp = await withRequestCompletionPolling(
|
782
|
+
this.client,
|
783
|
+
() => this.client.windows.screenshotAsync(
|
784
|
+
this.getWindowId(),
|
785
|
+
{
|
786
|
+
sessionId: this.sessionId,
|
787
|
+
...config || {}
|
788
|
+
},
|
789
|
+
{
|
790
|
+
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
791
|
+
...this.resolveRequestOptions(requestOptions)
|
792
|
+
}
|
793
|
+
)
|
767
794
|
);
|
768
795
|
return new AirtopWindowScreenshot(resp);
|
769
796
|
}
|
@@ -798,17 +825,20 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
798
825
|
this.log.withMetadata({
|
799
826
|
text
|
800
827
|
}).info("Typing text");
|
801
|
-
return
|
802
|
-
this.
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
828
|
+
return withRequestCompletionPolling(
|
829
|
+
this.client,
|
830
|
+
() => this.client.windows.typeAsync(
|
831
|
+
this.getWindowId(),
|
832
|
+
{
|
833
|
+
sessionId: this.sessionId,
|
834
|
+
text,
|
835
|
+
...config || {}
|
836
|
+
},
|
837
|
+
{
|
838
|
+
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
839
|
+
...this.resolveRequestOptions(requestOptions)
|
840
|
+
}
|
841
|
+
)
|
812
842
|
);
|
813
843
|
}
|
814
844
|
async extract(prompt, config, requestOptions = {}) {
|
@@ -859,7 +889,10 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
859
889
|
prompt,
|
860
890
|
sessionId: this.sessionId,
|
861
891
|
jobId: this.jobId,
|
862
|
-
...config || {}
|
892
|
+
...config || {},
|
893
|
+
includeWebContext: true,
|
894
|
+
// Always include web context for window.llm() calls
|
895
|
+
outputSchema: _optionalChain([config, 'optionalAccess', _12 => _12.outputSchema]) ? this.convertToJsonSchema(config.outputSchema) : void 0
|
863
896
|
},
|
864
897
|
{
|
865
898
|
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
@@ -974,6 +1007,27 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
974
1007
|
)
|
975
1008
|
);
|
976
1009
|
}
|
1010
|
+
async fillForm(formData, config, requestOptions = {}) {
|
1011
|
+
return await withRequestCompletionPolling(
|
1012
|
+
this.client,
|
1013
|
+
() => this.client.windows.executeAutomation(
|
1014
|
+
this.getWindowId(),
|
1015
|
+
{
|
1016
|
+
sessionId: this.sessionId,
|
1017
|
+
...config || {},
|
1018
|
+
automationId: _optionalChain([config, 'optionalAccess', _13 => _13.automationId]) || "auto",
|
1019
|
+
parameters: {
|
1020
|
+
customData: typeof formData === "string" ? formData : JSON.stringify(formData)
|
1021
|
+
// Will be interpreted by the LLM
|
1022
|
+
}
|
1023
|
+
},
|
1024
|
+
{
|
1025
|
+
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
1026
|
+
...this.resolveRequestOptions(requestOptions)
|
1027
|
+
}
|
1028
|
+
)
|
1029
|
+
);
|
1030
|
+
}
|
977
1031
|
};
|
978
1032
|
|
979
1033
|
// src/window/AirtopWindow.ts
|
@@ -1047,6 +1101,9 @@ var AirtopSessionClient = class extends AirtopBase {
|
|
1047
1101
|
getSessionId() {
|
1048
1102
|
return this.sessionId;
|
1049
1103
|
}
|
1104
|
+
async listWindows(requestOptions = {}) {
|
1105
|
+
return this.client.sessions.listWindows(this.sessionId, this.resolveRequestOptions(requestOptions));
|
1106
|
+
}
|
1050
1107
|
/**
|
1051
1108
|
* Gets the state of the session using the attached session id.
|
1052
1109
|
* @param requestOptions - Request options
|
@@ -1165,6 +1222,51 @@ var AirtopSessionClient = class extends AirtopBase {
|
|
1165
1222
|
this.resolveRequestOptions(requestOptions)
|
1166
1223
|
);
|
1167
1224
|
}
|
1225
|
+
async llm(prompt, config, requestOptions = {}) {
|
1226
|
+
this.log.withMetadata({ prompt }).info("Executing LLM call");
|
1227
|
+
const currentWindows = await this.listWindows();
|
1228
|
+
if (currentWindows.data.windows.length === 0) {
|
1229
|
+
throw new AirtopError([
|
1230
|
+
{
|
1231
|
+
message: "No windows found in the session. Please create a window before calling the llm() method."
|
1232
|
+
}
|
1233
|
+
]);
|
1234
|
+
}
|
1235
|
+
const firstWindow = currentWindows.data.windows[0];
|
1236
|
+
return withRequestCompletionPolling(
|
1237
|
+
this.client,
|
1238
|
+
() => this.client.windows.llm(
|
1239
|
+
firstWindow.windowId,
|
1240
|
+
{
|
1241
|
+
prompt,
|
1242
|
+
sessionId: this.sessionId,
|
1243
|
+
jobId: this.jobId,
|
1244
|
+
...config || {},
|
1245
|
+
includeWebContext: false,
|
1246
|
+
// Do not include web context for session.llm() calls
|
1247
|
+
outputSchema: _optionalChain([config, 'optionalAccess', _14 => _14.outputSchema]) ? this.convertToJsonSchema(config.outputSchema) : void 0
|
1248
|
+
},
|
1249
|
+
{
|
1250
|
+
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
1251
|
+
...this.resolveRequestOptions(requestOptions)
|
1252
|
+
}
|
1253
|
+
)
|
1254
|
+
);
|
1255
|
+
}
|
1256
|
+
/**
|
1257
|
+
* Calls the service endpoint.
|
1258
|
+
* @param prompt - The prompt to send to the service, describing the actions to take
|
1259
|
+
* @param service - The service to call, if not provided, the service will be inferred from the prompt
|
1260
|
+
* @param requestOptions - Request options
|
1261
|
+
*/
|
1262
|
+
async service(prompt, service, requestOptions = {}) {
|
1263
|
+
this.log.withMetadata({ prompt }).info("Service");
|
1264
|
+
return withRequestCompletionPolling(
|
1265
|
+
this.client,
|
1266
|
+
() => this.client.sessions.service(this.sessionId, { prompt, service }),
|
1267
|
+
requestOptions
|
1268
|
+
);
|
1269
|
+
}
|
1168
1270
|
};
|
1169
1271
|
|
1170
1272
|
// src/session/AirtopSession.ts
|
@@ -1223,19 +1325,19 @@ var AirtopClient = class extends AirtopBase {
|
|
1223
1325
|
*/
|
1224
1326
|
constructor(config) {
|
1225
1327
|
super({
|
1226
|
-
logLevel: _optionalChain([config, 'optionalAccess',
|
1328
|
+
logLevel: _optionalChain([config, 'optionalAccess', _15 => _15.logLevel]),
|
1227
1329
|
client: new (0, _core.Airtop)({
|
1228
1330
|
maxRetries: 0,
|
1229
1331
|
timeout: _minutesToMilliseconds.minutesToMilliseconds.call(void 0, 1),
|
1230
1332
|
apiKey: config.apiKey,
|
1231
|
-
baseURL: _optionalChain([config, 'optionalAccess',
|
1232
|
-
logLevel: _optionalChain([config, 'optionalAccess',
|
1333
|
+
baseURL: _optionalChain([config, 'optionalAccess', _16 => _16.airtopUrl]),
|
1334
|
+
logLevel: _optionalChain([config, 'optionalAccess', _17 => _17.logLevel]) || "off",
|
1233
1335
|
defaultHeaders: {
|
1234
1336
|
"x-airtop-sdk-source": "typescript",
|
1235
1337
|
"x-airtop-sdk-version": version
|
1236
1338
|
}
|
1237
1339
|
}),
|
1238
|
-
log: _optionalChain([config, 'optionalAccess',
|
1340
|
+
log: _optionalChain([config, 'optionalAccess', _18 => _18.logger]) || new (0, _loglayer.LogLayer)({
|
1239
1341
|
errorSerializer: _serializeerror.serializeError,
|
1240
1342
|
transport: new (0, _loglayer.ConsoleTransport)({
|
1241
1343
|
logger: console,
|
@@ -1274,8 +1376,8 @@ var AirtopClient = class extends AirtopBase {
|
|
1274
1376
|
* @returns A new AirtopSession instance
|
1275
1377
|
*/
|
1276
1378
|
async createSession(config, options = {}) {
|
1277
|
-
const skipWaitSessionReady = _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
1278
|
-
_optionalChainDelete([config, 'optionalAccess',
|
1379
|
+
const skipWaitSessionReady = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _19 => _19.skipWaitSessionReady]), () => ( false));
|
1380
|
+
_optionalChainDelete([config, 'optionalAccess', _20 => delete _20.skipWaitSessionReady]);
|
1279
1381
|
const sessionResponse = await this.client.sessions.create(
|
1280
1382
|
{
|
1281
1383
|
configuration: config
|
@@ -1482,19 +1584,19 @@ var AirtopAgentClient = class extends AirtopBase {
|
|
1482
1584
|
*/
|
1483
1585
|
constructor(config) {
|
1484
1586
|
super({
|
1485
|
-
logLevel: _optionalChain([config, 'optionalAccess',
|
1587
|
+
logLevel: _optionalChain([config, 'optionalAccess', _21 => _21.logLevel]),
|
1486
1588
|
client: new (0, _core.Airtop)({
|
1487
1589
|
maxRetries: 0,
|
1488
1590
|
timeout: _datefns.minutesToMilliseconds.call(void 0, 1),
|
1489
1591
|
apiKey: config.apiKey,
|
1490
|
-
baseURL: _optionalChain([config, 'optionalAccess',
|
1491
|
-
logLevel: _optionalChain([config, 'optionalAccess',
|
1592
|
+
baseURL: _optionalChain([config, 'optionalAccess', _22 => _22.airtopUrl]),
|
1593
|
+
logLevel: _optionalChain([config, 'optionalAccess', _23 => _23.logLevel]) || "off",
|
1492
1594
|
defaultHeaders: {
|
1493
1595
|
"x-airtop-sdk-source": "typescript",
|
1494
1596
|
"x-airtop-sdk-version": _process.version
|
1495
1597
|
}
|
1496
1598
|
}),
|
1497
|
-
log: _optionalChain([config, 'optionalAccess',
|
1599
|
+
log: _optionalChain([config, 'optionalAccess', _24 => _24.logger]) || new (0, _loglayer.LogLayer)({
|
1498
1600
|
errorSerializer: _serializeerror.serializeError,
|
1499
1601
|
transport: new (0, _loglayer.ConsoleTransport)({
|
1500
1602
|
logger: console,
|