@airtop/sdk 1.0.0-alpha2.18 → 1.0.0-alpha2.19
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 +72 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +26 -4
- package/dist/index.d.ts +26 -4
- package/dist/index.js +59 -53
- 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.19",
|
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.34",
|
51
51
|
"date-fns": "4.1.0",
|
52
52
|
loglayer: "6.3.3",
|
53
53
|
"serialize-error": "12.0.0",
|
@@ -86,6 +86,12 @@ var require_package = __commonJS({
|
|
86
86
|
|
87
87
|
// src/AirtopBase.ts
|
88
88
|
var _datefns = require('date-fns');
|
89
|
+
|
90
|
+
// src/constants.ts
|
91
|
+
var TIMEOUT_SECONDS_DEFAULT_VALUE = 300;
|
92
|
+
var DEFAULT_POLLING_INTERVAL_MS = 500;
|
93
|
+
|
94
|
+
// src/AirtopBase.ts
|
89
95
|
var AirtopBase = class {
|
90
96
|
/**
|
91
97
|
* Logger instance for the SDK
|
@@ -112,6 +118,11 @@ var AirtopBase = class {
|
|
112
118
|
* @internal
|
113
119
|
*/
|
114
120
|
|
121
|
+
/**
|
122
|
+
* The default timeout in seconds for API requests.
|
123
|
+
* @internal
|
124
|
+
*/
|
125
|
+
|
115
126
|
/**
|
116
127
|
* Creates a new instance of AirtopBase
|
117
128
|
* @param config - Configuration options for the SDK
|
@@ -121,6 +132,7 @@ var AirtopBase = class {
|
|
121
132
|
this.client = config.client;
|
122
133
|
this.outputJsonAdapter = config.outputSchemaAdapter;
|
123
134
|
this.jobId = config.jobId;
|
135
|
+
this.defaultTimeoutInSeconds = _nullishCoalesce(config.defaultTimeoutInSeconds, () => ( TIMEOUT_SECONDS_DEFAULT_VALUE));
|
124
136
|
if (config.agentEventPublisher) {
|
125
137
|
this.agentEventPublisher = config.agentEventPublisher;
|
126
138
|
}
|
@@ -209,7 +221,7 @@ var AirtopBase = class {
|
|
209
221
|
*/
|
210
222
|
resolveRequestOptions(options = {}) {
|
211
223
|
return {
|
212
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, options.timeoutInSeconds ||
|
224
|
+
timeout: _datefns.secondsToMilliseconds.call(void 0, options.timeoutInSeconds || this.defaultTimeoutInSeconds),
|
213
225
|
maxRetries: options.maxRetries || 0,
|
214
226
|
signal: options.abortSignal
|
215
227
|
};
|
@@ -218,7 +230,7 @@ var AirtopBase = class {
|
|
218
230
|
|
219
231
|
// src/AirtopClient.ts
|
220
232
|
var _core = require('@airtop/core');
|
221
|
-
var
|
233
|
+
var _secondsToMilliseconds = require('date-fns/secondsToMilliseconds');
|
222
234
|
var _loglayer = require('loglayer');
|
223
235
|
var _serializeerror = require('serialize-error');
|
224
236
|
|
@@ -269,7 +281,6 @@ var processLogMessage = (log, logLevel, ...args) => {
|
|
269
281
|
// src/session/AirtopSessionClient.ts
|
270
282
|
|
271
283
|
|
272
|
-
|
273
284
|
// src/async-utils.ts
|
274
285
|
|
275
286
|
|
@@ -288,11 +299,9 @@ ${JSON.stringify(metadata)}` : errorMessage;
|
|
288
299
|
};
|
289
300
|
|
290
301
|
// src/async-utils.ts
|
291
|
-
var DEFAULT_TIMEOUT_SECONDS = 300;
|
292
|
-
var DEFAULT_POLLING_INTERVAL_MS = 500;
|
293
302
|
async function waitForRequestCompletion(client, requestId, requestOptions) {
|
294
303
|
const startTime = Date.now();
|
295
|
-
const timeoutMs = _datefns.secondsToMilliseconds.call(void 0, _optionalChain([requestOptions, 'optionalAccess', _5 => _5.timeoutInSeconds]) ||
|
304
|
+
const timeoutMs = _datefns.secondsToMilliseconds.call(void 0, _optionalChain([requestOptions, 'optionalAccess', _5 => _5.timeoutInSeconds]) || TIMEOUT_SECONDS_DEFAULT_VALUE);
|
296
305
|
while (Date.now() - startTime < timeoutMs) {
|
297
306
|
const apiResponse = await client.requests.getRequestStatusV2(requestId, requestOptions);
|
298
307
|
if (apiResponse.status === "completed") {
|
@@ -319,9 +328,6 @@ async function withRequestCompletionPolling(client, fn, requestOptions) {
|
|
319
328
|
}
|
320
329
|
}
|
321
330
|
|
322
|
-
// src/window/AirtopWindowClient.ts
|
323
|
-
|
324
|
-
|
325
331
|
// src/window/AirtopNode.ts
|
326
332
|
var AirtopNode = class {
|
327
333
|
/**
|
@@ -598,7 +604,6 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
598
604
|
sessionId: this.sessionId
|
599
605
|
},
|
600
606
|
{
|
601
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
602
607
|
...this.resolveRequestOptions(requestOptions)
|
603
608
|
}
|
604
609
|
)
|
@@ -633,7 +638,6 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
633
638
|
...config || {}
|
634
639
|
},
|
635
640
|
{
|
636
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
637
641
|
...this.resolveRequestOptions(requestOptions)
|
638
642
|
}
|
639
643
|
)
|
@@ -658,7 +662,6 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
658
662
|
...config
|
659
663
|
},
|
660
664
|
{
|
661
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
662
665
|
...this.resolveRequestOptions(requestOptions)
|
663
666
|
}
|
664
667
|
);
|
@@ -670,8 +673,20 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
670
673
|
* @param requestOptions - Request options
|
671
674
|
* @returns Promise resolving to the monitoring operation result
|
672
675
|
*/
|
673
|
-
async monitor(condition, config, requestOptions = {}) {
|
676
|
+
async monitor(condition, config = {}, requestOptions = {}) {
|
674
677
|
this.log.withMetadata().info("Monitoring window");
|
678
|
+
if (!_optionalChain([config, 'optionalAccess', _8 => _8.configuration, 'optionalAccess', _9 => _9.interval, 'optionalAccess', _10 => _10.timeoutSeconds])) {
|
679
|
+
if (!config.configuration) {
|
680
|
+
config.configuration = {};
|
681
|
+
}
|
682
|
+
if (!config.configuration.interval) {
|
683
|
+
config.configuration.interval = {};
|
684
|
+
}
|
685
|
+
config.configuration.interval.timeoutSeconds = this.defaultTimeoutInSeconds;
|
686
|
+
}
|
687
|
+
if (!_optionalChain([config, 'optionalAccess', _11 => _11.timeThresholdSeconds])) {
|
688
|
+
config.timeThresholdSeconds = this.defaultTimeoutInSeconds;
|
689
|
+
}
|
675
690
|
return withRequestCompletionPolling(
|
676
691
|
this.client,
|
677
692
|
() => this.client.windows.monitorAsync(
|
@@ -682,7 +697,6 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
682
697
|
...config || {}
|
683
698
|
},
|
684
699
|
{
|
685
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
686
700
|
...this.resolveRequestOptions(requestOptions)
|
687
701
|
}
|
688
702
|
)
|
@@ -700,7 +714,7 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
700
714
|
prompt
|
701
715
|
}).info("Performing a page query");
|
702
716
|
const newConfig = config;
|
703
|
-
if (_optionalChain([config, 'optionalAccess',
|
717
|
+
if (_optionalChain([config, 'optionalAccess', _12 => _12.configuration, 'access', _13 => _13.outputSchema])) {
|
704
718
|
newConfig.configuration.outputSchema = this.convertToJsonSchema(config.configuration.outputSchema);
|
705
719
|
}
|
706
720
|
return withRequestCompletionPolling(
|
@@ -713,7 +727,6 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
713
727
|
...newConfig || {}
|
714
728
|
},
|
715
729
|
{
|
716
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
717
730
|
...this.resolveRequestOptions(requestOptions)
|
718
731
|
}
|
719
732
|
)
|
@@ -731,7 +744,7 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
731
744
|
prompt
|
732
745
|
}).info("Performing a paginated extraction");
|
733
746
|
const newConfig = config;
|
734
|
-
if (_optionalChain([config, 'optionalAccess',
|
747
|
+
if (_optionalChain([config, 'optionalAccess', _14 => _14.configuration, 'access', _15 => _15.outputSchema])) {
|
735
748
|
newConfig.configuration.outputSchema = this.convertToJsonSchema(config.configuration.outputSchema);
|
736
749
|
}
|
737
750
|
return withRequestCompletionPolling(
|
@@ -744,7 +757,6 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
744
757
|
...newConfig || {}
|
745
758
|
},
|
746
759
|
{
|
747
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
748
760
|
...this.resolveRequestOptions(requestOptions)
|
749
761
|
}
|
750
762
|
)
|
@@ -758,16 +770,18 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
758
770
|
*/
|
759
771
|
async scrape(config, requestOptions = {}) {
|
760
772
|
this.log.info("Scraping window");
|
761
|
-
return
|
762
|
-
this.
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
773
|
+
return withRequestCompletionPolling(
|
774
|
+
this.client,
|
775
|
+
() => this.client.windows.scrapeAsync(
|
776
|
+
this.getWindowId(),
|
777
|
+
{
|
778
|
+
sessionId: this.sessionId,
|
779
|
+
...config || {}
|
780
|
+
},
|
781
|
+
{
|
782
|
+
...this.resolveRequestOptions(requestOptions)
|
783
|
+
}
|
784
|
+
)
|
771
785
|
);
|
772
786
|
}
|
773
787
|
/**
|
@@ -787,7 +801,6 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
787
801
|
...config || {}
|
788
802
|
},
|
789
803
|
{
|
790
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
791
804
|
...this.resolveRequestOptions(requestOptions)
|
792
805
|
}
|
793
806
|
)
|
@@ -802,16 +815,18 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
802
815
|
*/
|
803
816
|
async scroll(config, requestOptions = {}) {
|
804
817
|
this.log.info("Scrolling window");
|
805
|
-
return
|
806
|
-
this.
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
818
|
+
return withRequestCompletionPolling(
|
819
|
+
this.client,
|
820
|
+
() => this.client.windows.scrollAsync(
|
821
|
+
this.getWindowId(),
|
822
|
+
{
|
823
|
+
sessionId: this.sessionId,
|
824
|
+
...config || {}
|
825
|
+
},
|
826
|
+
{
|
827
|
+
...this.resolveRequestOptions(requestOptions)
|
828
|
+
}
|
829
|
+
)
|
815
830
|
);
|
816
831
|
}
|
817
832
|
/**
|
@@ -835,7 +850,6 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
835
850
|
...config || {}
|
836
851
|
},
|
837
852
|
{
|
838
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
839
853
|
...this.resolveRequestOptions(requestOptions)
|
840
854
|
}
|
841
855
|
)
|
@@ -854,7 +868,6 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
854
868
|
...config || {}
|
855
869
|
},
|
856
870
|
{
|
857
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
858
871
|
...this.resolveRequestOptions(requestOptions)
|
859
872
|
}
|
860
873
|
)
|
@@ -873,7 +886,6 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
873
886
|
...config || {}
|
874
887
|
},
|
875
888
|
{
|
876
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
877
889
|
...this.resolveRequestOptions(requestOptions)
|
878
890
|
}
|
879
891
|
)
|
@@ -892,10 +904,9 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
892
904
|
...config || {},
|
893
905
|
includeWebContext: true,
|
894
906
|
// Always include web context for window.llm() calls
|
895
|
-
outputSchema: _optionalChain([config, 'optionalAccess',
|
907
|
+
outputSchema: _optionalChain([config, 'optionalAccess', _16 => _16.outputSchema]) ? this.convertToJsonSchema(config.outputSchema) : void 0
|
896
908
|
},
|
897
909
|
{
|
898
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
899
910
|
...this.resolveRequestOptions(requestOptions)
|
900
911
|
}
|
901
912
|
)
|
@@ -914,7 +925,6 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
914
925
|
...config || {}
|
915
926
|
},
|
916
927
|
{
|
917
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
918
928
|
...this.resolveRequestOptions(requestOptions)
|
919
929
|
}
|
920
930
|
)
|
@@ -953,7 +963,6 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
953
963
|
...config || {}
|
954
964
|
},
|
955
965
|
{
|
956
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
957
966
|
...this.resolveRequestOptions(requestOptions)
|
958
967
|
}
|
959
968
|
)
|
@@ -983,7 +992,6 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
983
992
|
...config || {}
|
984
993
|
},
|
985
994
|
{
|
986
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
987
995
|
...this.resolveRequestOptions(requestOptions)
|
988
996
|
}
|
989
997
|
)
|
@@ -1001,7 +1009,6 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
1001
1009
|
...config || {}
|
1002
1010
|
},
|
1003
1011
|
{
|
1004
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
1005
1012
|
...this.resolveRequestOptions(requestOptions)
|
1006
1013
|
}
|
1007
1014
|
)
|
@@ -1015,14 +1022,13 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
1015
1022
|
{
|
1016
1023
|
sessionId: this.sessionId,
|
1017
1024
|
...config || {},
|
1018
|
-
automationId: _optionalChain([config, 'optionalAccess',
|
1025
|
+
automationId: _optionalChain([config, 'optionalAccess', _17 => _17.automationId]) || "auto",
|
1019
1026
|
parameters: {
|
1020
1027
|
customData: typeof formData === "string" ? formData : JSON.stringify(formData)
|
1021
1028
|
// Will be interpreted by the LLM
|
1022
1029
|
}
|
1023
1030
|
},
|
1024
1031
|
{
|
1025
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
1026
1032
|
...this.resolveRequestOptions(requestOptions)
|
1027
1033
|
}
|
1028
1034
|
)
|
@@ -1244,10 +1250,9 @@ var AirtopSessionClient = class extends AirtopBase {
|
|
1244
1250
|
...config || {},
|
1245
1251
|
includeWebContext: false,
|
1246
1252
|
// Do not include web context for session.llm() calls
|
1247
|
-
outputSchema: _optionalChain([config, 'optionalAccess',
|
1253
|
+
outputSchema: _optionalChain([config, 'optionalAccess', _18 => _18.outputSchema]) ? this.convertToJsonSchema(config.outputSchema) : void 0
|
1248
1254
|
},
|
1249
1255
|
{
|
1250
|
-
timeout: _datefns.secondsToMilliseconds.call(void 0, 600),
|
1251
1256
|
...this.resolveRequestOptions(requestOptions)
|
1252
1257
|
}
|
1253
1258
|
)
|
@@ -1325,19 +1330,19 @@ var AirtopClient = class extends AirtopBase {
|
|
1325
1330
|
*/
|
1326
1331
|
constructor(config) {
|
1327
1332
|
super({
|
1328
|
-
logLevel: _optionalChain([config, 'optionalAccess',
|
1333
|
+
logLevel: _optionalChain([config, 'optionalAccess', _19 => _19.logLevel]),
|
1329
1334
|
client: new (0, _core.Airtop)({
|
1330
1335
|
maxRetries: 0,
|
1331
|
-
timeout:
|
1336
|
+
timeout: _secondsToMilliseconds.secondsToMilliseconds.call(void 0, _nullishCoalesce(config.defaultTimeoutInSeconds, () => ( TIMEOUT_SECONDS_DEFAULT_VALUE))),
|
1332
1337
|
apiKey: config.apiKey,
|
1333
|
-
baseURL: _optionalChain([config, 'optionalAccess',
|
1334
|
-
logLevel: _optionalChain([config, 'optionalAccess',
|
1338
|
+
baseURL: _optionalChain([config, 'optionalAccess', _20 => _20.airtopUrl]),
|
1339
|
+
logLevel: _optionalChain([config, 'optionalAccess', _21 => _21.logLevel]) || "off",
|
1335
1340
|
defaultHeaders: {
|
1336
1341
|
"x-airtop-sdk-source": "typescript",
|
1337
1342
|
"x-airtop-sdk-version": version
|
1338
1343
|
}
|
1339
1344
|
}),
|
1340
|
-
log: _optionalChain([config, 'optionalAccess',
|
1345
|
+
log: _optionalChain([config, 'optionalAccess', _22 => _22.logger]) || new (0, _loglayer.LogLayer)({
|
1341
1346
|
errorSerializer: _serializeerror.serializeError,
|
1342
1347
|
transport: new (0, _loglayer.ConsoleTransport)({
|
1343
1348
|
logger: console,
|
@@ -1350,7 +1355,8 @@ var AirtopClient = class extends AirtopBase {
|
|
1350
1355
|
}),
|
1351
1356
|
outputSchemaAdapter: config.outputSchemaAdapter,
|
1352
1357
|
jobId: config.jobId,
|
1353
|
-
agentEventPublisher: config.agentEventPublisher
|
1358
|
+
agentEventPublisher: config.agentEventPublisher,
|
1359
|
+
defaultTimeoutInSeconds: _nullishCoalesce(config.defaultTimeoutInSeconds, () => ( TIMEOUT_SECONDS_DEFAULT_VALUE))
|
1354
1360
|
});
|
1355
1361
|
this.log.withPrefix("[Airtop SDK]");
|
1356
1362
|
this.client.logLevel = config.logLevel;
|
@@ -1376,8 +1382,8 @@ var AirtopClient = class extends AirtopBase {
|
|
1376
1382
|
* @returns A new AirtopSession instance
|
1377
1383
|
*/
|
1378
1384
|
async createSession(config, options = {}) {
|
1379
|
-
const skipWaitSessionReady = _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
1380
|
-
_optionalChainDelete([config, 'optionalAccess',
|
1385
|
+
const skipWaitSessionReady = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _23 => _23.skipWaitSessionReady]), () => ( false));
|
1386
|
+
_optionalChainDelete([config, 'optionalAccess', _24 => delete _24.skipWaitSessionReady]);
|
1381
1387
|
const sessionResponse = await this.client.sessions.create(
|
1382
1388
|
{
|
1383
1389
|
configuration: config
|
@@ -1584,19 +1590,19 @@ var AirtopAgentClient = class extends AirtopBase {
|
|
1584
1590
|
*/
|
1585
1591
|
constructor(config) {
|
1586
1592
|
super({
|
1587
|
-
logLevel: _optionalChain([config, 'optionalAccess',
|
1593
|
+
logLevel: _optionalChain([config, 'optionalAccess', _25 => _25.logLevel]),
|
1588
1594
|
client: new (0, _core.Airtop)({
|
1589
1595
|
maxRetries: 0,
|
1590
1596
|
timeout: _datefns.minutesToMilliseconds.call(void 0, 1),
|
1591
1597
|
apiKey: config.apiKey,
|
1592
|
-
baseURL: _optionalChain([config, 'optionalAccess',
|
1593
|
-
logLevel: _optionalChain([config, 'optionalAccess',
|
1598
|
+
baseURL: _optionalChain([config, 'optionalAccess', _26 => _26.airtopUrl]),
|
1599
|
+
logLevel: _optionalChain([config, 'optionalAccess', _27 => _27.logLevel]) || "off",
|
1594
1600
|
defaultHeaders: {
|
1595
1601
|
"x-airtop-sdk-source": "typescript",
|
1596
1602
|
"x-airtop-sdk-version": _process.version
|
1597
1603
|
}
|
1598
1604
|
}),
|
1599
|
-
log: _optionalChain([config, 'optionalAccess',
|
1605
|
+
log: _optionalChain([config, 'optionalAccess', _28 => _28.logger]) || new (0, _loglayer.LogLayer)({
|
1600
1606
|
errorSerializer: _serializeerror.serializeError,
|
1601
1607
|
transport: new (0, _loglayer.ConsoleTransport)({
|
1602
1608
|
logger: console,
|