@airtop/sdk 1.0.0-alpha2.44 → 1.0.0-alpha2.46
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 +194 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +83 -2
- package/dist/index.d.ts +83 -2
- package/dist/index.js +170 -19
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } function _optionalChainDelete(ops) { const result = _optionalChain(ops); return result == null ? true : result; }var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } function _optionalChainDelete(ops) { const result = _optionalChain(ops); return result == null ? true : result; }var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
2
|
var __commonJS = (cb, mod) => function __require() {
|
|
3
3
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
4
|
};
|
|
@@ -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.46",
|
|
13
13
|
type: "module",
|
|
14
14
|
main: "./dist/index.cjs",
|
|
15
15
|
module: "./dist/index.js",
|
|
@@ -198,7 +198,7 @@ var AirtopBase = class {
|
|
|
198
198
|
* @internal
|
|
199
199
|
*/
|
|
200
200
|
convertToJsonSchema(input) {
|
|
201
|
-
if (input && _optionalChain([this, 'access',
|
|
201
|
+
if (input && _optionalChain([this, 'access', _2 => _2.outputJsonAdapter, 'optionalAccess', _3 => _3.shouldRunConversion, 'call', _4 => _4(input)])) {
|
|
202
202
|
return JSON.stringify(this.outputJsonAdapter.toJsonSchema(input));
|
|
203
203
|
}
|
|
204
204
|
if (typeof input === "object") {
|
|
@@ -350,7 +350,7 @@ var processLogMessage = (log, logLevel, ...args) => {
|
|
|
350
350
|
}
|
|
351
351
|
let finalMessage = messages.join(" ").trim();
|
|
352
352
|
if (finalMessage === "\u2A2F" && error) {
|
|
353
|
-
finalMessage = _optionalChain([error, 'optionalAccess',
|
|
353
|
+
finalMessage = _optionalChain([error, 'optionalAccess', _5 => _5.message]) || "";
|
|
354
354
|
}
|
|
355
355
|
if (error && hasData && messages.length > 0) {
|
|
356
356
|
log.withError(error).withMetadata(data)[logLevel](finalMessage);
|
|
@@ -370,6 +370,8 @@ var processLogMessage = (log, logLevel, ...args) => {
|
|
|
370
370
|
};
|
|
371
371
|
|
|
372
372
|
// src/session/AirtopSessionClient.ts
|
|
373
|
+
var _fs = require('fs'); var _fs2 = _interopRequireDefault(_fs);
|
|
374
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
373
375
|
|
|
374
376
|
|
|
375
377
|
// src/async-utils.ts
|
|
@@ -392,7 +394,7 @@ ${JSON.stringify(metadata)}` : errorMessage;
|
|
|
392
394
|
// src/async-utils.ts
|
|
393
395
|
async function waitForRequestCompletion(client, requestId, requestOptions) {
|
|
394
396
|
const startTime = Date.now();
|
|
395
|
-
const timeoutMs = _datefns.secondsToMilliseconds.call(void 0, _optionalChain([requestOptions, 'optionalAccess',
|
|
397
|
+
const timeoutMs = _datefns.secondsToMilliseconds.call(void 0, _optionalChain([requestOptions, 'optionalAccess', _6 => _6.timeoutInSeconds]) || TIMEOUT_SECONDS_DEFAULT_VALUE);
|
|
396
398
|
while (Date.now() - startTime < timeoutMs) {
|
|
397
399
|
const apiResponse = await client.requests.getRequestStatusV2(requestId, requestOptions);
|
|
398
400
|
if (apiResponse.status === "completed") {
|
|
@@ -410,7 +412,7 @@ async function withRequestCompletionPolling(client, fn, requestOptions) {
|
|
|
410
412
|
const response = await fn();
|
|
411
413
|
return waitForRequestCompletion(client, response.requestId, requestOptions);
|
|
412
414
|
} catch (thrownError) {
|
|
413
|
-
if (_optionalChain([thrownError, 'access',
|
|
415
|
+
if (_optionalChain([thrownError, 'access', _7 => _7.error, 'optionalAccess', _8 => _8.errors])) {
|
|
414
416
|
throw new AirtopError(thrownError.error.errors, {
|
|
415
417
|
requestId: thrownError.error.requestId
|
|
416
418
|
});
|
|
@@ -699,7 +701,8 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
699
701
|
{
|
|
700
702
|
...this.resolveRequestOptions(requestOptions)
|
|
701
703
|
}
|
|
702
|
-
)
|
|
704
|
+
),
|
|
705
|
+
requestOptions
|
|
703
706
|
);
|
|
704
707
|
}
|
|
705
708
|
/**
|
|
@@ -735,7 +738,8 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
735
738
|
{
|
|
736
739
|
...this.resolveRequestOptions(requestOptions)
|
|
737
740
|
}
|
|
738
|
-
)
|
|
741
|
+
),
|
|
742
|
+
requestOptions
|
|
739
743
|
);
|
|
740
744
|
}
|
|
741
745
|
/**
|
|
@@ -770,7 +774,7 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
770
774
|
*/
|
|
771
775
|
async monitor(condition, config = {}, requestOptions = {}) {
|
|
772
776
|
this.log.withMetadata().info("Monitoring window");
|
|
773
|
-
if (!_optionalChain([config, 'optionalAccess',
|
|
777
|
+
if (!_optionalChain([config, 'optionalAccess', _9 => _9.configuration, 'optionalAccess', _10 => _10.interval, 'optionalAccess', _11 => _11.timeoutSeconds])) {
|
|
774
778
|
if (!config.configuration) {
|
|
775
779
|
config.configuration = {};
|
|
776
780
|
}
|
|
@@ -779,7 +783,7 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
779
783
|
}
|
|
780
784
|
config.configuration.interval.timeoutSeconds = this.defaultTimeoutInSeconds;
|
|
781
785
|
}
|
|
782
|
-
if (!_optionalChain([config, 'optionalAccess',
|
|
786
|
+
if (!_optionalChain([config, 'optionalAccess', _12 => _12.timeThresholdSeconds])) {
|
|
783
787
|
config.timeThresholdSeconds = this.defaultTimeoutInSeconds;
|
|
784
788
|
}
|
|
785
789
|
return withRequestCompletionPolling(
|
|
@@ -794,7 +798,8 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
794
798
|
{
|
|
795
799
|
...this.resolveRequestOptions(requestOptions)
|
|
796
800
|
}
|
|
797
|
-
)
|
|
801
|
+
),
|
|
802
|
+
requestOptions
|
|
798
803
|
);
|
|
799
804
|
}
|
|
800
805
|
/**
|
|
@@ -809,7 +814,7 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
809
814
|
prompt
|
|
810
815
|
}).info("Performing a page query");
|
|
811
816
|
const newConfig = config;
|
|
812
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
817
|
+
if (_optionalChain([config, 'optionalAccess', _13 => _13.configuration, 'access', _14 => _14.outputSchema])) {
|
|
813
818
|
newConfig.configuration.outputSchema = this.convertToJsonSchema(config.configuration.outputSchema);
|
|
814
819
|
}
|
|
815
820
|
return withRequestCompletionPolling(
|
|
@@ -826,7 +831,8 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
826
831
|
{
|
|
827
832
|
...this.resolveRequestOptions(requestOptions)
|
|
828
833
|
}
|
|
829
|
-
)
|
|
834
|
+
),
|
|
835
|
+
requestOptions
|
|
830
836
|
);
|
|
831
837
|
}
|
|
832
838
|
/**
|
|
@@ -841,7 +847,7 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
841
847
|
prompt
|
|
842
848
|
}).info("Performing a paginated extraction");
|
|
843
849
|
const newConfig = config;
|
|
844
|
-
if (_optionalChain([config, 'optionalAccess',
|
|
850
|
+
if (_optionalChain([config, 'optionalAccess', _15 => _15.configuration, 'access', _16 => _16.outputSchema])) {
|
|
845
851
|
newConfig.configuration.outputSchema = this.convertToJsonSchema(config.configuration.outputSchema);
|
|
846
852
|
}
|
|
847
853
|
return withRequestCompletionPolling(
|
|
@@ -856,7 +862,8 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
856
862
|
{
|
|
857
863
|
...this.resolveRequestOptions(requestOptions)
|
|
858
864
|
}
|
|
859
|
-
)
|
|
865
|
+
),
|
|
866
|
+
requestOptions
|
|
860
867
|
);
|
|
861
868
|
}
|
|
862
869
|
/**
|
|
@@ -878,7 +885,8 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
878
885
|
{
|
|
879
886
|
...this.resolveRequestOptions(requestOptions)
|
|
880
887
|
}
|
|
881
|
-
)
|
|
888
|
+
),
|
|
889
|
+
requestOptions
|
|
882
890
|
);
|
|
883
891
|
}
|
|
884
892
|
/**
|
|
@@ -900,7 +908,8 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
900
908
|
{
|
|
901
909
|
...this.resolveRequestOptions(requestOptions)
|
|
902
910
|
}
|
|
903
|
-
)
|
|
911
|
+
),
|
|
912
|
+
requestOptions
|
|
904
913
|
);
|
|
905
914
|
return new AirtopWindowScreenshot(resp);
|
|
906
915
|
}
|
|
@@ -923,7 +932,8 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
923
932
|
{
|
|
924
933
|
...this.resolveRequestOptions(requestOptions)
|
|
925
934
|
}
|
|
926
|
-
)
|
|
935
|
+
),
|
|
936
|
+
requestOptions
|
|
927
937
|
);
|
|
928
938
|
}
|
|
929
939
|
/**
|
|
@@ -951,7 +961,8 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
951
961
|
{
|
|
952
962
|
...this.resolveRequestOptions(requestOptions)
|
|
953
963
|
}
|
|
954
|
-
)
|
|
964
|
+
),
|
|
965
|
+
requestOptions
|
|
955
966
|
);
|
|
956
967
|
}
|
|
957
968
|
async extract(prompt, config, requestOptions = {}) {
|
|
@@ -969,7 +980,8 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
969
980
|
{
|
|
970
981
|
...this.resolveRequestOptions(requestOptions)
|
|
971
982
|
}
|
|
972
|
-
)
|
|
983
|
+
),
|
|
984
|
+
requestOptions
|
|
973
985
|
);
|
|
974
986
|
}
|
|
975
987
|
async act(prompt, config, requestOptions = {}) {
|
|
@@ -987,7 +999,8 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
987
999
|
{
|
|
988
1000
|
...this.resolveRequestOptions(requestOptions)
|
|
989
1001
|
}
|
|
990
|
-
)
|
|
1002
|
+
),
|
|
1003
|
+
requestOptions
|
|
991
1004
|
);
|
|
992
1005
|
}
|
|
993
1006
|
async llm(prompt, config, requestOptions = {}) {
|
|
@@ -1003,12 +1016,13 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
1003
1016
|
...config || {},
|
|
1004
1017
|
includeWebContext: true,
|
|
1005
1018
|
// Always include web context for window.llm() calls
|
|
1006
|
-
outputSchema: _optionalChain([config, 'optionalAccess',
|
|
1019
|
+
outputSchema: _optionalChain([config, 'optionalAccess', _17 => _17.outputSchema]) ? this.convertToJsonSchema(config.outputSchema) : void 0
|
|
1007
1020
|
},
|
|
1008
1021
|
{
|
|
1009
1022
|
...this.resolveRequestOptions(requestOptions)
|
|
1010
1023
|
}
|
|
1011
|
-
)
|
|
1024
|
+
),
|
|
1025
|
+
requestOptions
|
|
1012
1026
|
);
|
|
1013
1027
|
}
|
|
1014
1028
|
async findOnePrivate(prompt, config, requestOptions = {}) {
|
|
@@ -1026,7 +1040,8 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
1026
1040
|
{
|
|
1027
1041
|
...this.resolveRequestOptions(requestOptions)
|
|
1028
1042
|
}
|
|
1029
|
-
)
|
|
1043
|
+
),
|
|
1044
|
+
requestOptions
|
|
1030
1045
|
);
|
|
1031
1046
|
if (apiResponse.errors.length > 0) {
|
|
1032
1047
|
throw new AirtopError(apiResponse.errors);
|
|
@@ -1064,7 +1079,8 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
1064
1079
|
{
|
|
1065
1080
|
...this.resolveRequestOptions(requestOptions)
|
|
1066
1081
|
}
|
|
1067
|
-
)
|
|
1082
|
+
),
|
|
1083
|
+
requestOptions
|
|
1068
1084
|
);
|
|
1069
1085
|
if (apiResponse.errors.length > 0) {
|
|
1070
1086
|
throw new AirtopError(apiResponse.errors);
|
|
@@ -1093,7 +1109,8 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
1093
1109
|
{
|
|
1094
1110
|
...this.resolveRequestOptions(requestOptions)
|
|
1095
1111
|
}
|
|
1096
|
-
)
|
|
1112
|
+
),
|
|
1113
|
+
requestOptions
|
|
1097
1114
|
);
|
|
1098
1115
|
}
|
|
1099
1116
|
async navigate(direction, config, requestOptions = {}) {
|
|
@@ -1110,7 +1127,8 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
1110
1127
|
{
|
|
1111
1128
|
...this.resolveRequestOptions(requestOptions)
|
|
1112
1129
|
}
|
|
1113
|
-
)
|
|
1130
|
+
),
|
|
1131
|
+
requestOptions
|
|
1114
1132
|
);
|
|
1115
1133
|
}
|
|
1116
1134
|
async fillForm(formData, config, requestOptions = {}) {
|
|
@@ -1121,7 +1139,7 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
1121
1139
|
{
|
|
1122
1140
|
sessionId: this.sessionId,
|
|
1123
1141
|
...config || {},
|
|
1124
|
-
automationId: _optionalChain([config, 'optionalAccess',
|
|
1142
|
+
automationId: _optionalChain([config, 'optionalAccess', _18 => _18.automationId]) || "auto",
|
|
1125
1143
|
parameters: {
|
|
1126
1144
|
customData: typeof formData === "string" ? formData : JSON.stringify(formData)
|
|
1127
1145
|
// Will be interpreted by the LLM
|
|
@@ -1130,7 +1148,8 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
1130
1148
|
{
|
|
1131
1149
|
...this.resolveRequestOptions(requestOptions)
|
|
1132
1150
|
}
|
|
1133
|
-
)
|
|
1151
|
+
),
|
|
1152
|
+
requestOptions
|
|
1134
1153
|
);
|
|
1135
1154
|
}
|
|
1136
1155
|
/**
|
|
@@ -1153,7 +1172,43 @@ var AirtopWindowClient = class extends AirtopBase {
|
|
|
1153
1172
|
{
|
|
1154
1173
|
...this.resolveRequestOptions(requestOptions)
|
|
1155
1174
|
}
|
|
1156
|
-
)
|
|
1175
|
+
),
|
|
1176
|
+
requestOptions
|
|
1177
|
+
);
|
|
1178
|
+
}
|
|
1179
|
+
/**
|
|
1180
|
+
* fileInput fills out a file input field in the window, using a file from the session
|
|
1181
|
+
* @param fileId - The ID of the file to use
|
|
1182
|
+
* @param config - Configuration options for the file input
|
|
1183
|
+
* @param requestOptions - Request options
|
|
1184
|
+
* @returns Promise resolving to the file input operation result
|
|
1185
|
+
*/
|
|
1186
|
+
async fileInput(fileId, config, requestOptions = {}) {
|
|
1187
|
+
return await withRequestCompletionPolling(
|
|
1188
|
+
this.client,
|
|
1189
|
+
() => this.client.windows.fileInputAsync(
|
|
1190
|
+
this.getWindowId(),
|
|
1191
|
+
{ sessionId: this.sessionId, ...config || {}, fileId },
|
|
1192
|
+
{ ...this.resolveRequestOptions(requestOptions) }
|
|
1193
|
+
),
|
|
1194
|
+
requestOptions
|
|
1195
|
+
);
|
|
1196
|
+
}
|
|
1197
|
+
/**
|
|
1198
|
+
* uploadFileAndSelectInput uploads a file to the session, gets it ready to upload,
|
|
1199
|
+
* and selects the file in the indicated input field
|
|
1200
|
+
* @param filePath - The path to the file to upload
|
|
1201
|
+
* @param config - Configuration options for the upload file and select input operation
|
|
1202
|
+
* @param requestOptions - Request options
|
|
1203
|
+
* @returns Promise resolving to the upload file and select input operation result
|
|
1204
|
+
*/
|
|
1205
|
+
async uploadFileAndSelectInput({ filePath }, config, requestOptions = {}) {
|
|
1206
|
+
const sessionClient = new AirtopSessionClient(this.getCommonConfig(), this.sessionId);
|
|
1207
|
+
const file = await sessionClient.uploadFile(filePath, { pushToSession: true }, requestOptions);
|
|
1208
|
+
return await this.fileInput(
|
|
1209
|
+
file.id,
|
|
1210
|
+
{ ...config, fileId: file.id },
|
|
1211
|
+
{ ...this.resolveRequestOptions(requestOptions) }
|
|
1157
1212
|
);
|
|
1158
1213
|
}
|
|
1159
1214
|
};
|
|
@@ -1375,7 +1430,7 @@ var AirtopSessionClient = class extends AirtopBase {
|
|
|
1375
1430
|
...config || {},
|
|
1376
1431
|
includeWebContext: false,
|
|
1377
1432
|
// Do not include web context for session.llm() calls
|
|
1378
|
-
outputSchema: _optionalChain([config, 'optionalAccess',
|
|
1433
|
+
outputSchema: _optionalChain([config, 'optionalAccess', _19 => _19.outputSchema]) ? this.convertToJsonSchema(config.outputSchema) : void 0
|
|
1379
1434
|
},
|
|
1380
1435
|
{
|
|
1381
1436
|
...this.resolveRequestOptions(requestOptions)
|
|
@@ -1445,7 +1500,7 @@ var AirtopSessionClient = class extends AirtopBase {
|
|
|
1445
1500
|
const { lookbackSeconds = 5, fileType } = configuration || {};
|
|
1446
1501
|
this.log.info(`waiting for file to be available on session: ${this.sessionId}`);
|
|
1447
1502
|
const startTime = /* @__PURE__ */ new Date();
|
|
1448
|
-
const timeoutSeconds = _optionalChain([requestOptions, 'optionalAccess',
|
|
1503
|
+
const timeoutSeconds = _optionalChain([requestOptions, 'optionalAccess', _20 => _20.timeoutInSeconds]) || 120;
|
|
1449
1504
|
const timeoutPromise = new Promise((resolve) => {
|
|
1450
1505
|
setTimeout(() => {
|
|
1451
1506
|
this.log.info(`waiting for file timed out after ${timeoutSeconds} seconds`);
|
|
@@ -1514,6 +1569,102 @@ ${JSON.stringify(event, null, 2)}`);
|
|
|
1514
1569
|
})();
|
|
1515
1570
|
return Promise.race([timeoutPromise, processEventsPromise]);
|
|
1516
1571
|
}
|
|
1572
|
+
/**
|
|
1573
|
+
* Uploads a file to the session and waits for it to be available.
|
|
1574
|
+
* @param filePath - The path to the file to upload
|
|
1575
|
+
* @param options - Additional configuration options for uploading the file,
|
|
1576
|
+
* @param options.fileName - The name of the file to upload, defaults to the basename of the file path
|
|
1577
|
+
* @param options.fileType - The type of the file to upload, defaults to "customer_upload"
|
|
1578
|
+
* @param options.sessionIds - The IDs of the sessions to upload the file to, defaults to the current session id
|
|
1579
|
+
* @param options.waitForUpload - Whether to wait for the upload to complete, defaults to true
|
|
1580
|
+
* @param options.pushToSession - Whether to push the file to the session, defaults to true, waits for the upload to complete regardless of waitForUpload setting
|
|
1581
|
+
* @param requestOptions - Request options
|
|
1582
|
+
* @returns the uploaded file result
|
|
1583
|
+
*/
|
|
1584
|
+
async uploadFile(filePath, options = {}, requestOptions = {}) {
|
|
1585
|
+
this.log.info(`uploading file ${filePath}`);
|
|
1586
|
+
const fileName = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _21 => _21.fileName]), () => ( _path2.default.basename(filePath)));
|
|
1587
|
+
const fileType = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _22 => _22.fileType]), () => ( "customer_upload"));
|
|
1588
|
+
const sessionIds = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _23 => _23.sessionIds]), () => ( [this.sessionId]));
|
|
1589
|
+
const waitForUpload = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _24 => _24.waitForUpload]), () => ( true));
|
|
1590
|
+
const pushToSession = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _25 => _25.pushToSession]), () => ( true));
|
|
1591
|
+
const file = await this.client.files.createFile(
|
|
1592
|
+
{
|
|
1593
|
+
sessionIds,
|
|
1594
|
+
fileName,
|
|
1595
|
+
fileType
|
|
1596
|
+
},
|
|
1597
|
+
this.resolveRequestOptions(requestOptions)
|
|
1598
|
+
);
|
|
1599
|
+
const fileContent = _fs2.default.readFileSync(filePath);
|
|
1600
|
+
if (waitForUpload || pushToSession) {
|
|
1601
|
+
const uploadWaitPromise = this.waitForUpload(file.data.id, "uploaded");
|
|
1602
|
+
fetch(file.data.uploadUrl, {
|
|
1603
|
+
method: "PUT",
|
|
1604
|
+
body: fileContent,
|
|
1605
|
+
headers: {
|
|
1606
|
+
"Content-Type": "application/octet-stream"
|
|
1607
|
+
}
|
|
1608
|
+
});
|
|
1609
|
+
await uploadWaitPromise;
|
|
1610
|
+
}
|
|
1611
|
+
if (pushToSession) {
|
|
1612
|
+
const pushWaitPromise = this.waitForUpload(file.data.id, "pushed");
|
|
1613
|
+
this.client.files.push(file.data.id, {
|
|
1614
|
+
sessionIds
|
|
1615
|
+
});
|
|
1616
|
+
await pushWaitPromise;
|
|
1617
|
+
}
|
|
1618
|
+
const fileDataResponse = await this.client.files.get(file.data.id);
|
|
1619
|
+
const fileData = fileDataResponse.data;
|
|
1620
|
+
return {
|
|
1621
|
+
id: file.data.id,
|
|
1622
|
+
downloadUrl: fileData.downloadUrl,
|
|
1623
|
+
fileName: file.data.fileName,
|
|
1624
|
+
fileType: file.data.fileType
|
|
1625
|
+
};
|
|
1626
|
+
}
|
|
1627
|
+
/**
|
|
1628
|
+
* Waits for a file to be uploaded, pushed to a session, then reach 'available' status. Throws an error if the file upload fails or times out.
|
|
1629
|
+
* @param fileId - The ID of the file to wait for
|
|
1630
|
+
* @param waitType - The type of wait to perform, "uploaded": just the file being uploaded to Airtop, "pushed": the file being pushed to a session
|
|
1631
|
+
* @param timeoutSeconds - The timeout in seconds, defaults to 300
|
|
1632
|
+
* @returns void
|
|
1633
|
+
*/
|
|
1634
|
+
async waitForUpload(fileId, waitType = "uploaded", timeoutSeconds = 300) {
|
|
1635
|
+
const waitEvent = waitType === "pushed" ? "file_upload_status" : "file_status";
|
|
1636
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
1637
|
+
setTimeout(() => {
|
|
1638
|
+
reject(new Error(`waiting for file upload timed out after ${timeoutSeconds} seconds`));
|
|
1639
|
+
}, timeoutSeconds * 1e3);
|
|
1640
|
+
});
|
|
1641
|
+
const processEventsPromise = (async () => {
|
|
1642
|
+
const newEvents = await this.client.sessions.getEvents(
|
|
1643
|
+
this.sessionId,
|
|
1644
|
+
{ all: false, reverse: false },
|
|
1645
|
+
{ timeout: timeoutSeconds * 1e3 }
|
|
1646
|
+
);
|
|
1647
|
+
for await (const event of newEvents) {
|
|
1648
|
+
const e = event;
|
|
1649
|
+
this.log.info(`waitForUpload processing event:
|
|
1650
|
+
${JSON.stringify(event, null, 2)}`);
|
|
1651
|
+
if (e.event === waitEvent) {
|
|
1652
|
+
if (e.fileId === fileId) {
|
|
1653
|
+
if (e.status === "available") {
|
|
1654
|
+
this.log.info(`uploaded file is now available on session: ${fileId}`);
|
|
1655
|
+
return;
|
|
1656
|
+
}
|
|
1657
|
+
if (e.status === "upload_failed") {
|
|
1658
|
+
this.log.info(`upload failed: ${this.sessionId} ${fileId}`);
|
|
1659
|
+
throw new Error(`upload failed: ${e.eventData.error}`);
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
1663
|
+
}
|
|
1664
|
+
return null;
|
|
1665
|
+
})();
|
|
1666
|
+
return Promise.race([timeoutPromise, processEventsPromise]);
|
|
1667
|
+
}
|
|
1517
1668
|
};
|
|
1518
1669
|
|
|
1519
1670
|
// src/session/AirtopSession.ts
|
|
@@ -1572,20 +1723,20 @@ var AirtopClient = class extends AirtopBase {
|
|
|
1572
1723
|
*/
|
|
1573
1724
|
constructor(config) {
|
|
1574
1725
|
super({
|
|
1575
|
-
logLevel: _optionalChain([config, 'optionalAccess',
|
|
1726
|
+
logLevel: _optionalChain([config, 'optionalAccess', _26 => _26.logLevel]),
|
|
1576
1727
|
client: new (0, _core.Airtop)({
|
|
1577
1728
|
maxRetries: 0,
|
|
1578
1729
|
timeout: _secondsToMilliseconds.secondsToMilliseconds.call(void 0, _nullishCoalesce(config.defaultTimeoutInSeconds, () => ( TIMEOUT_SECONDS_DEFAULT_VALUE))),
|
|
1579
1730
|
apiKey: config.apiKey,
|
|
1580
|
-
baseURL: _optionalChain([config, 'optionalAccess',
|
|
1581
|
-
logLevel: _optionalChain([config, 'optionalAccess',
|
|
1731
|
+
baseURL: _optionalChain([config, 'optionalAccess', _27 => _27.airtopUrl]),
|
|
1732
|
+
logLevel: _optionalChain([config, 'optionalAccess', _28 => _28.logLevel]) || "off",
|
|
1582
1733
|
defaultHeaders: {
|
|
1583
1734
|
"x-airtop-sdk-source": "typescript",
|
|
1584
1735
|
"x-airtop-sdk-version": version,
|
|
1585
|
-
"x-airtop-sdk-environment": _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
1736
|
+
"x-airtop-sdk-environment": _nullishCoalesce(_optionalChain([config, 'optionalAccess', _29 => _29.environment]), () => ( "default"))
|
|
1586
1737
|
}
|
|
1587
1738
|
}),
|
|
1588
|
-
log: _optionalChain([config, 'optionalAccess',
|
|
1739
|
+
log: _optionalChain([config, 'optionalAccess', _30 => _30.logger]) || new (0, _loglayer.LogLayer)({
|
|
1589
1740
|
errorSerializer: _serializeerror.serializeError,
|
|
1590
1741
|
transport: new (0, _loglayer.ConsoleTransport)({
|
|
1591
1742
|
logger: console,
|
|
@@ -1625,8 +1776,8 @@ var AirtopClient = class extends AirtopBase {
|
|
|
1625
1776
|
* @returns A new AirtopSession instance
|
|
1626
1777
|
*/
|
|
1627
1778
|
async createSession(config, options = {}) {
|
|
1628
|
-
const skipWaitSessionReady = _nullishCoalesce(_optionalChain([config, 'optionalAccess',
|
|
1629
|
-
_optionalChainDelete([config, 'optionalAccess',
|
|
1779
|
+
const skipWaitSessionReady = _nullishCoalesce(_optionalChain([config, 'optionalAccess', _31 => _31.skipWaitSessionReady]), () => ( false));
|
|
1780
|
+
_optionalChainDelete([config, 'optionalAccess', _32 => delete _32.skipWaitSessionReady]);
|
|
1630
1781
|
const sessionResponse = await this.client.sessions.create(
|
|
1631
1782
|
{
|
|
1632
1783
|
configuration: config
|
|
@@ -1882,19 +2033,19 @@ var AirtopAgentClient = class extends AirtopBase {
|
|
|
1882
2033
|
*/
|
|
1883
2034
|
constructor(config) {
|
|
1884
2035
|
super({
|
|
1885
|
-
logLevel: _optionalChain([config, 'optionalAccess',
|
|
2036
|
+
logLevel: _optionalChain([config, 'optionalAccess', _33 => _33.logLevel]),
|
|
1886
2037
|
client: new (0, _core.Airtop)({
|
|
1887
2038
|
maxRetries: 0,
|
|
1888
2039
|
timeout: _datefns.minutesToMilliseconds.call(void 0, 1),
|
|
1889
2040
|
apiKey: config.apiKey,
|
|
1890
|
-
baseURL: _optionalChain([config, 'optionalAccess',
|
|
1891
|
-
logLevel: _optionalChain([config, 'optionalAccess',
|
|
2041
|
+
baseURL: _optionalChain([config, 'optionalAccess', _34 => _34.airtopUrl]),
|
|
2042
|
+
logLevel: _optionalChain([config, 'optionalAccess', _35 => _35.logLevel]) || "off",
|
|
1892
2043
|
defaultHeaders: {
|
|
1893
2044
|
"x-airtop-sdk-source": "typescript",
|
|
1894
2045
|
"x-airtop-sdk-version": _process.version
|
|
1895
2046
|
}
|
|
1896
2047
|
}),
|
|
1897
|
-
log: _optionalChain([config, 'optionalAccess',
|
|
2048
|
+
log: _optionalChain([config, 'optionalAccess', _36 => _36.logger]) || new (0, _loglayer.LogLayer)({
|
|
1898
2049
|
errorSerializer: _serializeerror.serializeError,
|
|
1899
2050
|
transport: new (0, _loglayer.ConsoleTransport)({
|
|
1900
2051
|
logger: console,
|