@airtop/sdk 1.0.0-alpha2.0 → 1.0.0-alpha2.10
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/README.md +20 -0
- package/dist/index.cjs +269 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +130 -15
- package/dist/index.d.ts +130 -15
- package/dist/index.js +271 -34
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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.10",
|
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.27",
|
51
51
|
"date-fns": "4.1.0",
|
52
52
|
loglayer: "6.3.3",
|
53
53
|
"serialize-error": "12.0.0",
|
@@ -102,6 +102,11 @@ var AirtopBase = class {
|
|
102
102
|
* @internal
|
103
103
|
**/
|
104
104
|
outputJsonAdapter;
|
105
|
+
/**
|
106
|
+
* The job id for the ongoing automation
|
107
|
+
* @internal
|
108
|
+
*/
|
109
|
+
jobId;
|
105
110
|
/**
|
106
111
|
* Creates a new instance of AirtopBase
|
107
112
|
* @param config - Configuration options for the SDK
|
@@ -110,6 +115,7 @@ var AirtopBase = class {
|
|
110
115
|
this.log = config.log.withPrefix("[Airtop]");
|
111
116
|
this.client = config.client;
|
112
117
|
this.outputJsonAdapter = config.outputSchemaAdapter;
|
118
|
+
this.jobId = config.jobId;
|
113
119
|
}
|
114
120
|
/**
|
115
121
|
* Returns the API key used by the SDK
|
@@ -163,7 +169,8 @@ var AirtopBase = class {
|
|
163
169
|
getCommonConfig() {
|
164
170
|
return {
|
165
171
|
client: this.client,
|
166
|
-
log: this.log
|
172
|
+
log: this.log,
|
173
|
+
jobId: this.jobId
|
167
174
|
};
|
168
175
|
}
|
169
176
|
/**
|
@@ -235,7 +242,118 @@ var processLogMessage = (log, logLevel, ...args) => {
|
|
235
242
|
import { NotFoundError } from "@airtop/core";
|
236
243
|
|
237
244
|
// src/window/AirtopWindowClient.ts
|
245
|
+
import { secondsToMilliseconds as secondsToMilliseconds3 } from "date-fns";
|
246
|
+
|
247
|
+
// src/async-utils.ts
|
238
248
|
import { secondsToMilliseconds as secondsToMilliseconds2 } from "date-fns";
|
249
|
+
var DEFAULT_TIMEOUT_SECONDS = 300;
|
250
|
+
var DEFAULT_POLLING_INTERVAL_SECONDS = 2;
|
251
|
+
async function waitForRequestCompletion(client, requestId, requestOptions) {
|
252
|
+
const startTime = Date.now();
|
253
|
+
const timeoutMs = secondsToMilliseconds2(requestOptions?.timeoutInSeconds || DEFAULT_TIMEOUT_SECONDS);
|
254
|
+
while (Date.now() - startTime < timeoutMs) {
|
255
|
+
const apiResponse = await client.requests.getRequestStatus(requestId, requestOptions);
|
256
|
+
if (apiResponse.status === "completed") {
|
257
|
+
return apiResponse.response;
|
258
|
+
}
|
259
|
+
if (apiResponse.status === "error") {
|
260
|
+
throw new Error(apiResponse.error);
|
261
|
+
}
|
262
|
+
await new Promise((resolve) => setTimeout(resolve, secondsToMilliseconds2(DEFAULT_POLLING_INTERVAL_SECONDS)));
|
263
|
+
}
|
264
|
+
throw new Error("Waiting for request timed out");
|
265
|
+
}
|
266
|
+
async function withRequestCompletionPolling(client, fn, requestOptions) {
|
267
|
+
const response = await fn();
|
268
|
+
return waitForRequestCompletion(client, response.requestId, requestOptions);
|
269
|
+
}
|
270
|
+
|
271
|
+
// src/window/AirtopNode.ts
|
272
|
+
var AirtopNode = class {
|
273
|
+
/**
|
274
|
+
* The window client
|
275
|
+
*/
|
276
|
+
windowClient;
|
277
|
+
/**
|
278
|
+
* The node handle id to use for all requests
|
279
|
+
*/
|
280
|
+
nodeHandleId;
|
281
|
+
/**
|
282
|
+
* The xpath selector of the node
|
283
|
+
*/
|
284
|
+
selector;
|
285
|
+
/**
|
286
|
+
* Constructor
|
287
|
+
* @param client - The window client
|
288
|
+
* @param nodeData - The node data to use for all requests
|
289
|
+
*/
|
290
|
+
constructor(client, nodeData) {
|
291
|
+
this.windowClient = client;
|
292
|
+
this.nodeHandleId = nodeData.id;
|
293
|
+
this.selector = nodeData.xpath;
|
294
|
+
}
|
295
|
+
/**
|
296
|
+
* Extract content from the node
|
297
|
+
* @param prompt - The prompt to use for the extraction
|
298
|
+
* @param config - The configuration to use for the extraction
|
299
|
+
* @param requestOptions - The request options to use for the extraction
|
300
|
+
*/
|
301
|
+
async extract(prompt, config, requestOptions = {}) {
|
302
|
+
const augmentedConfig = {
|
303
|
+
...config,
|
304
|
+
nodeHandleId: this.nodeHandleId
|
305
|
+
};
|
306
|
+
return this.windowClient.extract(prompt, augmentedConfig, requestOptions);
|
307
|
+
}
|
308
|
+
/**
|
309
|
+
* Act on the node
|
310
|
+
* @param prompt - The prompt to use for the action
|
311
|
+
* @param config - The configuration to use for the action
|
312
|
+
* @param requestOptions - The request options to use for the action
|
313
|
+
*/
|
314
|
+
async act(prompt, config, requestOptions = {}) {
|
315
|
+
const augmentedConfig = {
|
316
|
+
...config,
|
317
|
+
nodeHandleId: this.nodeHandleId
|
318
|
+
};
|
319
|
+
return this.windowClient.act(prompt, augmentedConfig, requestOptions);
|
320
|
+
}
|
321
|
+
/**
|
322
|
+
* Execute an LLM call on the node
|
323
|
+
* @param prompt - The prompt to use for the LLM call
|
324
|
+
* @param config - The configuration to use for the LLM call
|
325
|
+
* @param requestOptions - The request options to use for the LLM call
|
326
|
+
*/
|
327
|
+
async llm(prompt, config, requestOptions = {}) {
|
328
|
+
return this.windowClient.llm(prompt, config, requestOptions);
|
329
|
+
}
|
330
|
+
/**
|
331
|
+
* Find one element in the node
|
332
|
+
* @param prompt - The prompt to use for the find one
|
333
|
+
* @param config - The configuration to use for the find one
|
334
|
+
* @param requestOptions - The request options to use for the find one
|
335
|
+
*/
|
336
|
+
async findOne(prompt, config, requestOptions = {}) {
|
337
|
+
const augmentedConfig = {
|
338
|
+
...config,
|
339
|
+
nodeHandleId: this.nodeHandleId
|
340
|
+
};
|
341
|
+
return this.windowClient.findOne(prompt, augmentedConfig, requestOptions);
|
342
|
+
}
|
343
|
+
/**
|
344
|
+
* Find many elements in the node
|
345
|
+
* @param prompt - The prompt to use for the find many
|
346
|
+
* @param config - The configuration to use for the find many
|
347
|
+
* @param requestOptions - The request options to use for the find many
|
348
|
+
*/
|
349
|
+
async findMany(prompt, config, requestOptions = {}) {
|
350
|
+
const augmentedConfig = {
|
351
|
+
...config,
|
352
|
+
nodeHandleId: this.nodeHandleId
|
353
|
+
};
|
354
|
+
return this.windowClient.findMany(prompt, augmentedConfig, requestOptions);
|
355
|
+
}
|
356
|
+
};
|
239
357
|
|
240
358
|
// src/window/AirtopWindowScreenshot.ts
|
241
359
|
function extractMimeAndBase64(dataUrl) {
|
@@ -385,7 +503,7 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
385
503
|
sessionId: this.sessionId
|
386
504
|
},
|
387
505
|
{
|
388
|
-
timeout:
|
506
|
+
timeout: secondsToMilliseconds3(600),
|
389
507
|
...this.resolveRequestOptions(requestOptions)
|
390
508
|
}
|
391
509
|
);
|
@@ -417,7 +535,7 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
417
535
|
...config || {}
|
418
536
|
},
|
419
537
|
{
|
420
|
-
timeout:
|
538
|
+
timeout: secondsToMilliseconds3(600),
|
421
539
|
...this.resolveRequestOptions(requestOptions)
|
422
540
|
}
|
423
541
|
);
|
@@ -441,7 +559,7 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
441
559
|
...config
|
442
560
|
},
|
443
561
|
{
|
444
|
-
timeout:
|
562
|
+
timeout: secondsToMilliseconds3(600),
|
445
563
|
...this.resolveRequestOptions(requestOptions)
|
446
564
|
}
|
447
565
|
);
|
@@ -463,7 +581,7 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
463
581
|
...config || {}
|
464
582
|
},
|
465
583
|
{
|
466
|
-
timeout:
|
584
|
+
timeout: secondsToMilliseconds3(600),
|
467
585
|
...this.resolveRequestOptions(requestOptions)
|
468
586
|
}
|
469
587
|
);
|
@@ -491,7 +609,7 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
491
609
|
...newConfig || {}
|
492
610
|
},
|
493
611
|
{
|
494
|
-
timeout:
|
612
|
+
timeout: secondsToMilliseconds3(600),
|
495
613
|
...this.resolveRequestOptions(requestOptions)
|
496
614
|
}
|
497
615
|
);
|
@@ -519,7 +637,7 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
519
637
|
...newConfig || {}
|
520
638
|
},
|
521
639
|
{
|
522
|
-
timeout:
|
640
|
+
timeout: secondsToMilliseconds3(600),
|
523
641
|
...this.resolveRequestOptions(requestOptions)
|
524
642
|
}
|
525
643
|
);
|
@@ -539,7 +657,7 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
539
657
|
...config || {}
|
540
658
|
},
|
541
659
|
{
|
542
|
-
timeout:
|
660
|
+
timeout: secondsToMilliseconds3(600),
|
543
661
|
...this.resolveRequestOptions(requestOptions)
|
544
662
|
}
|
545
663
|
);
|
@@ -559,7 +677,7 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
559
677
|
...config || {}
|
560
678
|
},
|
561
679
|
{
|
562
|
-
timeout:
|
680
|
+
timeout: secondsToMilliseconds3(600),
|
563
681
|
...this.resolveRequestOptions(requestOptions)
|
564
682
|
}
|
565
683
|
);
|
@@ -580,7 +698,7 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
580
698
|
...config || {}
|
581
699
|
},
|
582
700
|
{
|
583
|
-
timeout:
|
701
|
+
timeout: secondsToMilliseconds3(600),
|
584
702
|
...this.resolveRequestOptions(requestOptions)
|
585
703
|
}
|
586
704
|
);
|
@@ -604,11 +722,137 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
604
722
|
...config || {}
|
605
723
|
},
|
606
724
|
{
|
607
|
-
timeout:
|
725
|
+
timeout: secondsToMilliseconds3(600),
|
608
726
|
...this.resolveRequestOptions(requestOptions)
|
609
727
|
}
|
610
728
|
);
|
611
729
|
}
|
730
|
+
async extract(prompt, config, requestOptions = {}) {
|
731
|
+
this.log.withMetadata({ prompt }).info("Extracting content");
|
732
|
+
return withRequestCompletionPolling(
|
733
|
+
this.client,
|
734
|
+
() => this.client.windows.extract(
|
735
|
+
this.getWindowId(),
|
736
|
+
{
|
737
|
+
prompt,
|
738
|
+
sessionId: this.sessionId,
|
739
|
+
jobId: this.jobId,
|
740
|
+
...config || {}
|
741
|
+
},
|
742
|
+
{
|
743
|
+
timeout: secondsToMilliseconds3(600),
|
744
|
+
...this.resolveRequestOptions(requestOptions)
|
745
|
+
}
|
746
|
+
)
|
747
|
+
);
|
748
|
+
}
|
749
|
+
async act(prompt, config, requestOptions = {}) {
|
750
|
+
this.log.withMetadata({ prompt }).info("Acting on content");
|
751
|
+
return withRequestCompletionPolling(
|
752
|
+
this.client,
|
753
|
+
() => this.client.windows.act(
|
754
|
+
this.getWindowId(),
|
755
|
+
{
|
756
|
+
prompt,
|
757
|
+
sessionId: this.sessionId,
|
758
|
+
jobId: this.jobId,
|
759
|
+
...config || {}
|
760
|
+
},
|
761
|
+
{
|
762
|
+
timeout: secondsToMilliseconds3(600),
|
763
|
+
...this.resolveRequestOptions(requestOptions)
|
764
|
+
}
|
765
|
+
)
|
766
|
+
);
|
767
|
+
}
|
768
|
+
async llm(prompt, config, requestOptions = {}) {
|
769
|
+
this.log.withMetadata({ prompt }).info("Executing LLM call");
|
770
|
+
return withRequestCompletionPolling(
|
771
|
+
this.client,
|
772
|
+
() => this.client.windows.llm(
|
773
|
+
this.getWindowId(),
|
774
|
+
{
|
775
|
+
prompt,
|
776
|
+
sessionId: this.sessionId,
|
777
|
+
...config || {}
|
778
|
+
},
|
779
|
+
{
|
780
|
+
timeout: secondsToMilliseconds3(600),
|
781
|
+
...this.resolveRequestOptions(requestOptions)
|
782
|
+
}
|
783
|
+
)
|
784
|
+
);
|
785
|
+
}
|
786
|
+
async findOne(prompt, config, requestOptions = {}) {
|
787
|
+
this.log.withMetadata({ prompt }).info("Executing LLM call");
|
788
|
+
const apiResponse = await withRequestCompletionPolling(
|
789
|
+
this.client,
|
790
|
+
() => this.client.windows.findOne(
|
791
|
+
this.getWindowId(),
|
792
|
+
{
|
793
|
+
prompt,
|
794
|
+
sessionId: this.sessionId,
|
795
|
+
jobId: this.jobId,
|
796
|
+
...config || {}
|
797
|
+
},
|
798
|
+
{
|
799
|
+
timeout: secondsToMilliseconds3(600),
|
800
|
+
...this.resolveRequestOptions(requestOptions)
|
801
|
+
}
|
802
|
+
)
|
803
|
+
);
|
804
|
+
try {
|
805
|
+
const nodeData = JSON.parse(apiResponse.data.modelResponse);
|
806
|
+
return new AirtopNode(this, nodeData);
|
807
|
+
} catch (error) {
|
808
|
+
this.log.withMetadata({ nodeDataStr: apiResponse.data.modelResponse }).withError(error).error("Error parsing node data");
|
809
|
+
throw error;
|
810
|
+
}
|
811
|
+
}
|
812
|
+
async findMany(prompt, config, requestOptions = {}) {
|
813
|
+
this.log.withMetadata({ prompt }).info("Executing LLM call");
|
814
|
+
const apiResponse = await withRequestCompletionPolling(
|
815
|
+
this.client,
|
816
|
+
() => this.client.windows.findMany(
|
817
|
+
this.getWindowId(),
|
818
|
+
{
|
819
|
+
prompt,
|
820
|
+
sessionId: this.sessionId,
|
821
|
+
jobId: this.jobId,
|
822
|
+
...config || {}
|
823
|
+
},
|
824
|
+
{
|
825
|
+
timeout: secondsToMilliseconds3(600),
|
826
|
+
...this.resolveRequestOptions(requestOptions)
|
827
|
+
}
|
828
|
+
)
|
829
|
+
);
|
830
|
+
const nodeHandles = apiResponse.data.modelResponse.split("___DELIM___");
|
831
|
+
return nodeHandles.map((nodeDataStr) => {
|
832
|
+
try {
|
833
|
+
const nodeData = JSON.parse(nodeDataStr);
|
834
|
+
return new AirtopNode(this, nodeData);
|
835
|
+
} catch (error) {
|
836
|
+
this.log.withMetadata({ nodeDataStr }).withError(error).error("Error parsing node data");
|
837
|
+
}
|
838
|
+
});
|
839
|
+
}
|
840
|
+
async waitForPage(config, requestOptions = {}) {
|
841
|
+
return await withRequestCompletionPolling(
|
842
|
+
this.client,
|
843
|
+
() => this.client.windows.waitForPage(
|
844
|
+
this.getWindowId(),
|
845
|
+
{
|
846
|
+
sessionId: this.sessionId,
|
847
|
+
...config || {}
|
848
|
+
},
|
849
|
+
{
|
850
|
+
timeout: secondsToMilliseconds3(600),
|
851
|
+
...this.resolveRequestOptions(requestOptions)
|
852
|
+
}
|
853
|
+
)
|
854
|
+
);
|
855
|
+
}
|
612
856
|
};
|
613
857
|
|
614
858
|
// src/window/AirtopWindow.ts
|
@@ -782,7 +1026,7 @@ var AirtopSessionClient = class extends AirtopBase {
|
|
782
1026
|
{
|
783
1027
|
...config,
|
784
1028
|
fileName,
|
785
|
-
|
1029
|
+
sessionIds: [this.sessionId]
|
786
1030
|
},
|
787
1031
|
this.resolveRequestOptions(requestOptions)
|
788
1032
|
);
|
@@ -868,7 +1112,8 @@ var AirtopClient = class extends AirtopBase {
|
|
868
1112
|
contextFieldName: "context",
|
869
1113
|
metadataFieldName: "metadata"
|
870
1114
|
}),
|
871
|
-
outputSchemaAdapter: config.outputSchemaAdapter
|
1115
|
+
outputSchemaAdapter: config.outputSchemaAdapter,
|
1116
|
+
jobId: config.jobId
|
872
1117
|
});
|
873
1118
|
this.log.withPrefix("[Airtop SDK]");
|
874
1119
|
this.client.logLevel = config.logLevel;
|
@@ -894,8 +1139,8 @@ var AirtopClient = class extends AirtopBase {
|
|
894
1139
|
* @returns A new AirtopSession instance
|
895
1140
|
*/
|
896
1141
|
async createSession(config, options = {}) {
|
897
|
-
const skipWaitSessionReady = config
|
898
|
-
delete config
|
1142
|
+
const skipWaitSessionReady = config?.skipWaitSessionReady ?? false;
|
1143
|
+
delete config?.skipWaitSessionReady;
|
899
1144
|
const sessionResponse = await this.client.sessions.create(
|
900
1145
|
{
|
901
1146
|
configuration: config
|
@@ -1003,23 +1248,6 @@ var AirtopClient = class extends AirtopBase {
|
|
1003
1248
|
async getFile(fileId, requestOptions = {}) {
|
1004
1249
|
return this.client.files.get(fileId, this.resolveRequestOptions(requestOptions));
|
1005
1250
|
}
|
1006
|
-
/**
|
1007
|
-
* Lists files filtered by session IDs.
|
1008
|
-
* @param sessionIds - Array of session IDs to retrieve files for
|
1009
|
-
* @param config - Configuration options for the request
|
1010
|
-
* @param requestOptions - Request options
|
1011
|
-
* @returns Object containing pagination info and array of AirtopSession instances
|
1012
|
-
*/
|
1013
|
-
async listFiles(sessionIds, config, requestOptions = {}) {
|
1014
|
-
return this.client.files.list(
|
1015
|
-
{
|
1016
|
-
sessionIds,
|
1017
|
-
limit: config.limit,
|
1018
|
-
offset: config.offset
|
1019
|
-
},
|
1020
|
-
this.resolveRequestOptions(requestOptions)
|
1021
|
-
);
|
1022
|
-
}
|
1023
1251
|
/**
|
1024
1252
|
* Removes a file by ID.
|
1025
1253
|
* @param fileId - ID of the file to remove
|
@@ -1028,6 +1256,14 @@ var AirtopClient = class extends AirtopBase {
|
|
1028
1256
|
async removeFile(fileId, requestOptions = {}) {
|
1029
1257
|
return this.client.files.delete(fileId, this.resolveRequestOptions(requestOptions));
|
1030
1258
|
}
|
1259
|
+
/**
|
1260
|
+
* List files
|
1261
|
+
* @param query
|
1262
|
+
* @param requestOptions
|
1263
|
+
*/
|
1264
|
+
async listFiles(query, requestOptions = {}) {
|
1265
|
+
return this.client.files.list(query, this.resolveRequestOptions(requestOptions));
|
1266
|
+
}
|
1031
1267
|
/**
|
1032
1268
|
* List all automations
|
1033
1269
|
* @param requestOptions - Request options
|
@@ -1184,6 +1420,7 @@ export {
|
|
1184
1420
|
AirtopBase,
|
1185
1421
|
AirtopClient,
|
1186
1422
|
AirtopMocks,
|
1423
|
+
AirtopNode,
|
1187
1424
|
AirtopPluginAugmentationType,
|
1188
1425
|
AirtopSession,
|
1189
1426
|
AirtopSessionClient,
|