@coherentglobal/spark-execute-sdk 0.4.10 → 0.4.12
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/browser.js +69 -36
- package/package.json +3 -2
- package/src/browser.js +31 -27
- package/types/browser.d.ts +6 -2
- package/types/browser.d.ts.map +1 -1
- package/types/node.d.ts +4 -1
- package/types/node.d.ts.map +1 -1
package/dist/browser.js
CHANGED
|
@@ -900,13 +900,19 @@ var unzipppedModel = function unzipppedModel(model) {
|
|
|
900
900
|
case 0:
|
|
901
901
|
servicename = model.servicename, wasm = model.wasm, js = model.js, data = model.data, metadata = model.metadata;
|
|
902
902
|
response = {
|
|
903
|
-
wasm: {
|
|
903
|
+
wasm: utils.isFilePath(wasm, "wasm") ? {
|
|
904
|
+
url: new URL(wasm, window.location.origin).toString(),
|
|
905
|
+
path: utils.last(wasm.split("/"))
|
|
906
|
+
} : {
|
|
904
907
|
url: URL.createObjectURL(new Blob([wasm], {
|
|
905
908
|
type: "application/wasm"
|
|
906
909
|
})),
|
|
907
910
|
path: "".concat(servicename, ".wasm")
|
|
908
911
|
},
|
|
909
|
-
js: {
|
|
912
|
+
js: utils.isFilePath(js, "js") ? {
|
|
913
|
+
url: new URL(js, window.location.origin).toString(),
|
|
914
|
+
path: utils.last(js.split("/"))
|
|
915
|
+
} : {
|
|
910
916
|
url: URL.createObjectURL(new Blob([js], {
|
|
911
917
|
type: "text/javascript"
|
|
912
918
|
})),
|
|
@@ -914,7 +920,10 @@ var unzipppedModel = function unzipppedModel(model) {
|
|
|
914
920
|
}
|
|
915
921
|
};
|
|
916
922
|
if (data) {
|
|
917
|
-
response.data = {
|
|
923
|
+
response.data = utils.isFilePath(data, "data") ? {
|
|
924
|
+
url: new URL(data, window.location.origin).toString(),
|
|
925
|
+
path: utils.last(data.split("/"))
|
|
926
|
+
} : {
|
|
918
927
|
url: URL.createObjectURL(new Blob([data], {
|
|
919
928
|
type: "application/octet-stream"
|
|
920
929
|
})),
|
|
@@ -922,7 +931,10 @@ var unzipppedModel = function unzipppedModel(model) {
|
|
|
922
931
|
};
|
|
923
932
|
}
|
|
924
933
|
if (metadata) {
|
|
925
|
-
response.metadata = {
|
|
934
|
+
response.metadata = utils.isFilePath(metadata, "json") ? {
|
|
935
|
+
url: new URL(metadata, window.location.origin).toString(),
|
|
936
|
+
path: utils.last(metadata.split("/"))
|
|
937
|
+
} : {
|
|
926
938
|
url: URL.createObjectURL(new Blob([metadata], {
|
|
927
939
|
type: "application/json"
|
|
928
940
|
})),
|
|
@@ -966,7 +978,7 @@ var getRuntimeContent = function getRuntimeContent(js, wasm) {
|
|
|
966
978
|
}, _callee7);
|
|
967
979
|
}));
|
|
968
980
|
}).then(function (text) {
|
|
969
|
-
return text.replace(wasm.path, wasm.url).replace(data.path, data.url).replace(data.path, data.url);
|
|
981
|
+
return text.replace(wasm.path, wasm.url).replace("\"".concat(data.path, "\""), "\"".concat(data.url, "\"")).replace("\"".concat(data.path, "\""), "\"".concat(data.url, "\"")).replace("'".concat(data.path, "'"), "'".concat(data.url, "'")).replace("'".concat(data.path, "'"), "'".concat(data.url, "'"));
|
|
970
982
|
});
|
|
971
983
|
case 3:
|
|
972
984
|
_runtime = _context9.sent;
|
|
@@ -1710,7 +1722,7 @@ var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
|
1710
1722
|
Object.defineProperty(exports, "__esModule", {
|
|
1711
1723
|
value: true
|
|
1712
1724
|
});
|
|
1713
|
-
exports.addScript = exports.isEmpty = exports.fn2workerURL = exports.jsString2workerURL = exports.isCompatible = exports.isWorkerSupported = exports.isWasmSupported = exports.isBrowser = exports.isHttpURL = exports.isPath = exports.ENVIRONMENT_IS_NODE = exports.ENVIRONMENT_IS_WEB = void 0;
|
|
1725
|
+
exports.last = exports.addScript = exports.isEmpty = exports.fn2workerURL = exports.jsString2workerURL = exports.isCompatible = exports.isWorkerSupported = exports.isWasmSupported = exports.isBrowser = exports.isFilePath = exports.isHttpURL = exports.isPath = exports.ENVIRONMENT_IS_NODE = exports.ENVIRONMENT_IS_WEB = void 0;
|
|
1714
1726
|
var fs_1 = __importDefault(require("fs"));
|
|
1715
1727
|
var url_1 = __importDefault(require("url"));
|
|
1716
1728
|
var error_1 = __importDefault(require("./error"));
|
|
@@ -1757,6 +1769,11 @@ function isHttpURL(str) {
|
|
|
1757
1769
|
return urlInstance.protocol === "http:" || urlInstance.protocol === "https:";
|
|
1758
1770
|
}
|
|
1759
1771
|
exports.isHttpURL = isHttpURL;
|
|
1772
|
+
function isFilePath(str, ext) {
|
|
1773
|
+
var idx = str.indexOf(".".concat(ext));
|
|
1774
|
+
return idx > -1 && idx === str.length - ".".concat(ext).length;
|
|
1775
|
+
}
|
|
1776
|
+
exports.isFilePath = isFilePath;
|
|
1760
1777
|
function isBrowser() {
|
|
1761
1778
|
try {
|
|
1762
1779
|
// eslint-disable-next-line no-undef
|
|
@@ -1829,6 +1846,17 @@ function addScript(src) {
|
|
|
1829
1846
|
document.body.appendChild(s);
|
|
1830
1847
|
}
|
|
1831
1848
|
exports.addScript = addScript;
|
|
1849
|
+
function last(arr) {
|
|
1850
|
+
if (!Array.isArray(arr)) {
|
|
1851
|
+
throw new Error("Argument is not array");
|
|
1852
|
+
}
|
|
1853
|
+
var length = arr.length;
|
|
1854
|
+
if (length === 0) {
|
|
1855
|
+
return undefined;
|
|
1856
|
+
}
|
|
1857
|
+
return arr[length - 1];
|
|
1858
|
+
}
|
|
1859
|
+
exports.last = last;
|
|
1832
1860
|
|
|
1833
1861
|
}).call(this)}).call(this,require('_process'))
|
|
1834
1862
|
},{"./error":22,"@babel/runtime/helpers/interopRequireDefault":9,"@babel/runtime/helpers/typeof":17,"@babel/runtime/regenerator":19,"_process":36,"fs":25,"url":42}],24:[function(require,module,exports){
|
|
@@ -7157,7 +7185,6 @@ var _require = require("@coherentglobal/wasm-runner"),
|
|
|
7157
7185
|
var validate = require("./validate.js");
|
|
7158
7186
|
var processModels = require("./models.js");
|
|
7159
7187
|
var findModel = require("./findModels.js");
|
|
7160
|
-
var registry = {};
|
|
7161
7188
|
var Spark = /*#__PURE__*/function () {
|
|
7162
7189
|
/**
|
|
7163
7190
|
* @param {object} config
|
|
@@ -7166,6 +7193,11 @@ var Spark = /*#__PURE__*/function () {
|
|
|
7166
7193
|
var _this$config$sparkEnd, _this$config, _this$config$sparkEnd2, _this$config$sparkEnd3, _this$config2, _this$config2$sparkEn, _ref, _this$config$sparkEnd4, _this$config3, _this$config3$sparkEn, _this$config4, _this$config4$sparkEn, _this$config$sparkEnd5, _this$config5, _this$config5$sparkEn, _this$config6;
|
|
7167
7194
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
7168
7195
|
(0, _classCallCheck2["default"])(this, Spark);
|
|
7196
|
+
/**
|
|
7197
|
+
* @private
|
|
7198
|
+
*/
|
|
7199
|
+
this._registry = undefined;
|
|
7200
|
+
|
|
7169
7201
|
/**
|
|
7170
7202
|
* @private
|
|
7171
7203
|
*/
|
|
@@ -7327,8 +7359,8 @@ var Spark = /*#__PURE__*/function () {
|
|
|
7327
7359
|
case 2:
|
|
7328
7360
|
versionID = version_id || (input === null || input === void 0 ? void 0 : (_input$request_meta = input.request_meta) === null || _input$request_meta === void 0 ? void 0 : _input$request_meta.version_id) || (input === null || input === void 0 ? void 0 : (_input$request_meta2 = input.request_meta) === null || _input$request_meta2 === void 0 ? void 0 : _input$request_meta2.version_uuid);
|
|
7329
7361
|
lookup = {
|
|
7330
|
-
model: this.offlineModel,
|
|
7331
|
-
onlineEndpoint: this.onlineModelEndpoint
|
|
7362
|
+
model: this.offlineModel.bind(this),
|
|
7363
|
+
onlineEndpoint: this.onlineModelEndpoint.bind(this)
|
|
7332
7364
|
};
|
|
7333
7365
|
_context.next = 6;
|
|
7334
7366
|
return lookup[this.priority[0]](input, versionID, this);
|
|
@@ -7359,13 +7391,14 @@ var Spark = /*#__PURE__*/function () {
|
|
|
7359
7391
|
}, {
|
|
7360
7392
|
key: "offlineModel",
|
|
7361
7393
|
value: function () {
|
|
7362
|
-
var _offlineModel = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(input, versionID
|
|
7394
|
+
var _offlineModel = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(input, versionID) {
|
|
7395
|
+
var _this = this;
|
|
7363
7396
|
var model, modelVersionId, callback, _model2$metaData$Engi, _model2$metaData, _model2$metaData$Engi2, _model2$metaData$Engi3, _model2$metaData2, _model2$metaData2$Eng, _model2, result;
|
|
7364
7397
|
return _regenerator["default"].wrap(function _callee3$(_context3) {
|
|
7365
7398
|
while (1) {
|
|
7366
7399
|
switch (_context3.prev = _context3.next) {
|
|
7367
7400
|
case 0:
|
|
7368
|
-
model = findModel(input.request_meta,
|
|
7401
|
+
model = findModel(input.request_meta, this.model);
|
|
7369
7402
|
modelVersionId = versionID || model && (model === null || model === void 0 ? void 0 : model.versionId);
|
|
7370
7403
|
if (!(input !== null && input !== void 0 && input.request_meta)) {
|
|
7371
7404
|
input.request_meta = {};
|
|
@@ -7374,7 +7407,7 @@ var Spark = /*#__PURE__*/function () {
|
|
|
7374
7407
|
input.request_meta.version_id = modelVersionId;
|
|
7375
7408
|
}
|
|
7376
7409
|
_context3.prev = 4;
|
|
7377
|
-
if (
|
|
7410
|
+
if (this._registry === undefined) {
|
|
7378
7411
|
/**
|
|
7379
7412
|
* Options is the request data the the runner dispatch
|
|
7380
7413
|
* receives from the wasm model
|
|
@@ -7391,12 +7424,12 @@ var Spark = /*#__PURE__*/function () {
|
|
|
7391
7424
|
hasFolderName = options === null || options === void 0 ? void 0 : options.folder_name;
|
|
7392
7425
|
hasServiceName = options === null || options === void 0 ? void 0 : options.service_name;
|
|
7393
7426
|
hasVersionId = options === null || options === void 0 ? void 0 : options.version_id;
|
|
7394
|
-
if (!(hasVersionId && !
|
|
7427
|
+
if (!(hasVersionId && !_this._registry.isExist(hasVersionId))) {
|
|
7395
7428
|
_context2.next = 8;
|
|
7396
7429
|
break;
|
|
7397
7430
|
}
|
|
7398
7431
|
_context2.next = 6;
|
|
7399
|
-
return
|
|
7432
|
+
return _this._registry.append({
|
|
7400
7433
|
id: hasVersionId,
|
|
7401
7434
|
url: model.binary,
|
|
7402
7435
|
meta: {
|
|
@@ -7408,10 +7441,10 @@ var Spark = /*#__PURE__*/function () {
|
|
|
7408
7441
|
_context2.next = 12;
|
|
7409
7442
|
break;
|
|
7410
7443
|
case 8:
|
|
7411
|
-
_model =
|
|
7444
|
+
_model = _this._getModelByMeta(hasFolderName, hasServiceName);
|
|
7412
7445
|
hasVersionId = _model === null || _model === void 0 ? void 0 : _model.versionId;
|
|
7413
7446
|
_context2.next = 12;
|
|
7414
|
-
return
|
|
7447
|
+
return _this._registry.append({
|
|
7415
7448
|
id: hasVersionId,
|
|
7416
7449
|
url: _model.binary,
|
|
7417
7450
|
meta: {
|
|
@@ -7428,19 +7461,19 @@ var Spark = /*#__PURE__*/function () {
|
|
|
7428
7461
|
}
|
|
7429
7462
|
}, _callee2);
|
|
7430
7463
|
}));
|
|
7431
|
-
return function callback(
|
|
7464
|
+
return function callback(_x5) {
|
|
7432
7465
|
return _ref2.apply(this, arguments);
|
|
7433
7466
|
};
|
|
7434
7467
|
}();
|
|
7435
|
-
|
|
7468
|
+
this._registry = new WasmRunner("", callback);
|
|
7436
7469
|
}
|
|
7437
|
-
if (
|
|
7470
|
+
if (this._registry.isExist(modelVersionId)) {
|
|
7438
7471
|
_context3.next = 10;
|
|
7439
7472
|
break;
|
|
7440
7473
|
}
|
|
7441
|
-
_model2 = findModel(input.request_meta,
|
|
7474
|
+
_model2 = findModel(input.request_meta, this.model);
|
|
7442
7475
|
_context3.next = 10;
|
|
7443
|
-
return
|
|
7476
|
+
return this._registry.append({
|
|
7444
7477
|
id: modelVersionId,
|
|
7445
7478
|
url: _model2.binary,
|
|
7446
7479
|
meta: {
|
|
@@ -7450,7 +7483,7 @@ var Spark = /*#__PURE__*/function () {
|
|
|
7450
7483
|
});
|
|
7451
7484
|
case 10:
|
|
7452
7485
|
_context3.next = 12;
|
|
7453
|
-
return
|
|
7486
|
+
return this._registry.execute(input, modelVersionId, function () {});
|
|
7454
7487
|
case 12:
|
|
7455
7488
|
result = _context3.sent;
|
|
7456
7489
|
return _context3.abrupt("return", result);
|
|
@@ -7463,9 +7496,9 @@ var Spark = /*#__PURE__*/function () {
|
|
|
7463
7496
|
return _context3.stop();
|
|
7464
7497
|
}
|
|
7465
7498
|
}
|
|
7466
|
-
}, _callee3,
|
|
7499
|
+
}, _callee3, this, [[4, 16]]);
|
|
7467
7500
|
}));
|
|
7468
|
-
function offlineModel(_x3, _x4
|
|
7501
|
+
function offlineModel(_x3, _x4) {
|
|
7469
7502
|
return _offlineModel.apply(this, arguments);
|
|
7470
7503
|
}
|
|
7471
7504
|
return offlineModel;
|
|
@@ -7473,43 +7506,43 @@ var Spark = /*#__PURE__*/function () {
|
|
|
7473
7506
|
}, {
|
|
7474
7507
|
key: "onlineModelEndpoint",
|
|
7475
7508
|
value: function () {
|
|
7476
|
-
var _onlineModelEndpoint = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(input, versionID
|
|
7509
|
+
var _onlineModelEndpoint = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee4(input, versionID) {
|
|
7477
7510
|
var isPublic, token, header, options, modelUrl, response, result;
|
|
7478
7511
|
return _regenerator["default"].wrap(function _callee4$(_context4) {
|
|
7479
7512
|
while (1) {
|
|
7480
7513
|
switch (_context4.prev = _context4.next) {
|
|
7481
7514
|
case 0:
|
|
7482
|
-
isPublic =
|
|
7515
|
+
isPublic = this.authType === "public";
|
|
7483
7516
|
token = "";
|
|
7484
7517
|
if (isPublic) {
|
|
7485
7518
|
_context4.next = 12;
|
|
7486
7519
|
break;
|
|
7487
7520
|
}
|
|
7488
|
-
if (!(
|
|
7521
|
+
if (!(this.token.constructor.name === "AsyncFunction")) {
|
|
7489
7522
|
_context4.next = 9;
|
|
7490
7523
|
break;
|
|
7491
7524
|
}
|
|
7492
7525
|
_context4.next = 6;
|
|
7493
|
-
return
|
|
7526
|
+
return this.token();
|
|
7494
7527
|
case 6:
|
|
7495
7528
|
token = _context4.sent;
|
|
7496
7529
|
_context4.next = 10;
|
|
7497
7530
|
break;
|
|
7498
7531
|
case 9:
|
|
7499
|
-
if (typeof
|
|
7500
|
-
token =
|
|
7532
|
+
if (typeof this.token === "function") {
|
|
7533
|
+
token = this.token();
|
|
7501
7534
|
} else {
|
|
7502
|
-
token =
|
|
7535
|
+
token = this.token;
|
|
7503
7536
|
}
|
|
7504
7537
|
case 10:
|
|
7505
|
-
if (!utils.isEmpty(
|
|
7538
|
+
if (!utils.isEmpty(this.token)) {
|
|
7506
7539
|
_context4.next = 12;
|
|
7507
7540
|
break;
|
|
7508
7541
|
}
|
|
7509
7542
|
throw new WasmRunnerErrors.UnauthorizedError();
|
|
7510
7543
|
case 12:
|
|
7511
7544
|
_context4.prev = 12;
|
|
7512
|
-
header = !isPublic ? utils.getAuthHeaders(token,
|
|
7545
|
+
header = !isPublic ? utils.getAuthHeaders(token, this.authType, this.tenant) : {};
|
|
7513
7546
|
options = {
|
|
7514
7547
|
method: "POST",
|
|
7515
7548
|
body: JSON.stringify({
|
|
@@ -7520,7 +7553,7 @@ var Spark = /*#__PURE__*/function () {
|
|
|
7520
7553
|
"content-type": "application/json"
|
|
7521
7554
|
}), header)
|
|
7522
7555
|
};
|
|
7523
|
-
modelUrl = new URL("/".concat(
|
|
7556
|
+
modelUrl = new URL("/".concat(this.tenant, "/api/v3/").concat(!isPublic ? "execute" : "public"), this.url);
|
|
7524
7557
|
_context4.next = 18;
|
|
7525
7558
|
return fetch(modelUrl, options);
|
|
7526
7559
|
case 18:
|
|
@@ -7539,9 +7572,9 @@ var Spark = /*#__PURE__*/function () {
|
|
|
7539
7572
|
return _context4.stop();
|
|
7540
7573
|
}
|
|
7541
7574
|
}
|
|
7542
|
-
}, _callee4,
|
|
7575
|
+
}, _callee4, this, [[12, 25]]);
|
|
7543
7576
|
}));
|
|
7544
|
-
function onlineModelEndpoint(
|
|
7577
|
+
function onlineModelEndpoint(_x6, _x7) {
|
|
7545
7578
|
return _onlineModelEndpoint.apply(this, arguments);
|
|
7546
7579
|
}
|
|
7547
7580
|
return onlineModelEndpoint;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coherentglobal/spark-execute-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.12",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/node.js",
|
|
6
6
|
"browser": "dist/browser.js",
|
|
7
7
|
"types": "types/node.d.ts",
|
|
8
8
|
"scripts": {
|
|
9
|
+
"build": "npm run build:types && npm run bundle:full && npm run bundle:min",
|
|
9
10
|
"build:types": "tsc --declaration",
|
|
10
11
|
"bundle:full": "browserify src/browser.js --standalone Spark > dist/browser.js",
|
|
11
12
|
"bundle:min": "browserify src/browser.js --standalone Spark | uglifyjs --compress --mangle --comments false > lib/sparkexecute.min.js",
|
|
@@ -22,7 +23,7 @@
|
|
|
22
23
|
"author": "",
|
|
23
24
|
"license": "ISC",
|
|
24
25
|
"dependencies": {
|
|
25
|
-
"@coherentglobal/wasm-runner": "^0.0.
|
|
26
|
+
"@coherentglobal/wasm-runner": "^0.0.63",
|
|
26
27
|
"@types/node": "^18.7.18",
|
|
27
28
|
"axios": "^0.27.2",
|
|
28
29
|
"chai": "^4.3.6",
|
package/src/browser.js
CHANGED
|
@@ -5,13 +5,18 @@ const validate = require("./validate.js");
|
|
|
5
5
|
const processModels = require("./models.js");
|
|
6
6
|
const findModel = require("./findModels.js");
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
|
|
9
9
|
|
|
10
10
|
class Spark {
|
|
11
11
|
/**
|
|
12
12
|
* @param {object} config
|
|
13
13
|
*/
|
|
14
14
|
constructor(config, options = {}) {
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
this._registry = undefined;
|
|
19
|
+
|
|
15
20
|
/**
|
|
16
21
|
* @private
|
|
17
22
|
*/
|
|
@@ -143,8 +148,8 @@ class Spark {
|
|
|
143
148
|
input?.request_meta?.version_id ||
|
|
144
149
|
input?.request_meta?.version_uuid;
|
|
145
150
|
let lookup = {
|
|
146
|
-
model: this.offlineModel,
|
|
147
|
-
onlineEndpoint: this.onlineModelEndpoint,
|
|
151
|
+
model: this.offlineModel.bind(this),
|
|
152
|
+
onlineEndpoint: this.onlineModelEndpoint.bind(this),
|
|
148
153
|
};
|
|
149
154
|
|
|
150
155
|
let response;
|
|
@@ -156,10 +161,9 @@ class Spark {
|
|
|
156
161
|
return response;
|
|
157
162
|
}
|
|
158
163
|
|
|
159
|
-
async offlineModel(input, versionID
|
|
160
|
-
const model = findModel(input.request_meta,
|
|
164
|
+
async offlineModel(input, versionID) {
|
|
165
|
+
const model = findModel(input.request_meta, this.model);
|
|
161
166
|
const modelVersionId = versionID || (model && model?.versionId);
|
|
162
|
-
|
|
163
167
|
if (!input?.request_meta) {
|
|
164
168
|
input.request_meta = {};
|
|
165
169
|
}
|
|
@@ -168,7 +172,7 @@ class Spark {
|
|
|
168
172
|
}
|
|
169
173
|
|
|
170
174
|
try {
|
|
171
|
-
if (
|
|
175
|
+
if (this._registry === undefined) {
|
|
172
176
|
/**
|
|
173
177
|
* Options is the request data the the runner dispatch
|
|
174
178
|
* receives from the wasm model
|
|
@@ -180,8 +184,8 @@ class Spark {
|
|
|
180
184
|
const hasServiceName = options?.service_name;
|
|
181
185
|
let hasVersionId = options?.version_id;
|
|
182
186
|
|
|
183
|
-
if (hasVersionId && !
|
|
184
|
-
await
|
|
187
|
+
if (hasVersionId && !this._registry.isExist(hasVersionId)) {
|
|
188
|
+
await this._registry.append({
|
|
185
189
|
id: hasVersionId,
|
|
186
190
|
url: model.binary,
|
|
187
191
|
meta: {
|
|
@@ -192,9 +196,9 @@ class Spark {
|
|
|
192
196
|
},
|
|
193
197
|
});
|
|
194
198
|
} else {
|
|
195
|
-
const model =
|
|
199
|
+
const model = this._getModelByMeta(hasFolderName, hasServiceName);
|
|
196
200
|
hasVersionId = model?.versionId;
|
|
197
|
-
await
|
|
201
|
+
await this._registry.append({
|
|
198
202
|
id: hasVersionId,
|
|
199
203
|
url: model.binary,
|
|
200
204
|
meta: {
|
|
@@ -207,13 +211,13 @@ class Spark {
|
|
|
207
211
|
}
|
|
208
212
|
return hasVersionId;
|
|
209
213
|
};
|
|
210
|
-
|
|
214
|
+
this._registry = new WasmRunner("", callback);
|
|
211
215
|
}
|
|
212
216
|
|
|
213
|
-
if (!
|
|
214
|
-
const model = findModel(input.request_meta,
|
|
217
|
+
if (!this._registry.isExist(modelVersionId)) {
|
|
218
|
+
const model = findModel(input.request_meta, this.model);
|
|
215
219
|
|
|
216
|
-
await
|
|
220
|
+
await this._registry.append({
|
|
217
221
|
id: modelVersionId,
|
|
218
222
|
url: model.binary,
|
|
219
223
|
meta: {
|
|
@@ -222,35 +226,35 @@ class Spark {
|
|
|
222
226
|
},
|
|
223
227
|
});
|
|
224
228
|
}
|
|
225
|
-
const result = await
|
|
229
|
+
const result = await this._registry.execute(input, modelVersionId, () => { });
|
|
226
230
|
return result;
|
|
227
231
|
} catch (err) {
|
|
228
232
|
return err;
|
|
229
233
|
}
|
|
230
234
|
}
|
|
231
235
|
|
|
232
|
-
async onlineModelEndpoint(input, versionID
|
|
233
|
-
const isPublic =
|
|
236
|
+
async onlineModelEndpoint(input, versionID) {
|
|
237
|
+
const isPublic = this.authType === "public";
|
|
234
238
|
|
|
235
239
|
let token = "";
|
|
236
240
|
|
|
237
241
|
if (!isPublic) {
|
|
238
|
-
if (
|
|
239
|
-
token = await
|
|
240
|
-
} else if (typeof
|
|
241
|
-
token =
|
|
242
|
+
if (this.token.constructor.name === "AsyncFunction") {
|
|
243
|
+
token = await this.token();
|
|
244
|
+
} else if (typeof this.token === "function") {
|
|
245
|
+
token = this.token();
|
|
242
246
|
} else {
|
|
243
|
-
token =
|
|
247
|
+
token = this.token;
|
|
244
248
|
}
|
|
245
249
|
|
|
246
|
-
if (utils.isEmpty(
|
|
250
|
+
if (utils.isEmpty(this.token)) {
|
|
247
251
|
throw new WasmRunnerErrors.UnauthorizedError();
|
|
248
252
|
}
|
|
249
253
|
}
|
|
250
254
|
|
|
251
255
|
try {
|
|
252
256
|
const header = !isPublic
|
|
253
|
-
? utils.getAuthHeaders(token,
|
|
257
|
+
? utils.getAuthHeaders(token, this.authType, this.tenant)
|
|
254
258
|
: {};
|
|
255
259
|
|
|
256
260
|
const options = {
|
|
@@ -263,8 +267,8 @@ class Spark {
|
|
|
263
267
|
};
|
|
264
268
|
|
|
265
269
|
const modelUrl = new URL(
|
|
266
|
-
`/${
|
|
267
|
-
|
|
270
|
+
`/${this.tenant}/api/v3/${!isPublic ? "execute" : "public"}`,
|
|
271
|
+
this.url
|
|
268
272
|
);
|
|
269
273
|
|
|
270
274
|
const response = await fetch(modelUrl, options);
|
package/types/browser.d.ts
CHANGED
|
@@ -4,6 +4,10 @@ declare class Spark {
|
|
|
4
4
|
* @param {object} config
|
|
5
5
|
*/
|
|
6
6
|
constructor(config: object, options?: {});
|
|
7
|
+
/**
|
|
8
|
+
* @private
|
|
9
|
+
*/
|
|
10
|
+
private _registry;
|
|
7
11
|
logger: any;
|
|
8
12
|
/**
|
|
9
13
|
* @private
|
|
@@ -65,7 +69,7 @@ declare class Spark {
|
|
|
65
69
|
* @returns {object}
|
|
66
70
|
*/
|
|
67
71
|
execute(input: object, version_id?: string | undefined): object;
|
|
68
|
-
offlineModel(input: any, versionID: any
|
|
69
|
-
onlineModelEndpoint(input: any, versionID: any
|
|
72
|
+
offlineModel(input: any, versionID: any): Promise<unknown>;
|
|
73
|
+
onlineModelEndpoint(input: any, versionID: any): Promise<any>;
|
|
70
74
|
}
|
|
71
75
|
//# sourceMappingURL=browser.d.ts.map
|
package/types/browser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.js"],"names":[],"mappings":";AASA;IACE;;OAEG;IACH,oBAFW,MAAM,
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.js"],"names":[],"mappings":";AASA;IACE;;OAEG;IACH,oBAFW,MAAM,gBAqDhB;IAlDC;;MAEE;IACF,kBAA0B;IAMxB,YAAyB;IAG3B;;OAEG;IACH,eAAyC;IAEzC;;OAEG;IACH,eAAsD;IACtD;;OAEG;IACH,iBAA0D;IAC1D;;OAEG;IACH,cAGI;IACJ;;OAEG;IACH,YAAgD;IAChD;;OAEG;IACH,qBAA2C;IAE3C;;OAEG;IACH,iBAA2C;IAE3C;;MAEE;IACF,cAAqD;IAGvD,oBAEC;IAED;;;;OAIG;IACH,iBAHW,MAAM,GACJ,MAAM,CAgBlB;IACD;;;;OAIG;IACH,uBAHW,MAAM,GACJ,MAAM,CAgBlB;IACD;;;;OAIG;IACH,cAHW,MAAM,GACJ,OAAO,CAOnB;IAED,wDASC;IAED;;;;;;OAMG;IACH,eAJW,MAAM,oCAEJ,MAAM,CAuBlB;IAED,2DAsEC;IAED,8DA6CC;CACF"}
|
package/types/node.d.ts
CHANGED
package/types/node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.js"],"names":[],"mappings":";AAeA;IACE;;OAEG;IACH,oBAFW,MAAM,+
|
|
1
|
+
{"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../src/node.js"],"names":[],"mappings":";AAeA;IACE;;OAEG;IACH,oBAFW,MAAM,+CAoEhB;IAjEC;;OAEG;IACH,kBAA0B;IAGxB,SAAsB;IAGxB;;MAEE;IACF,mBAA4E;IAU1E,eAAsB;IAMxB;;OAEG;IACH,eAAsD;IACtD;;OAEG;IACH,iBAA0D;IAC1D;;OAEG;IACH,cAGI;IACJ;;OAEG;IACH,YAAgD;IAChD;;OAEG;IACH,qBAA2C;IAC3C;;OAEG;IACH,cAAqD;IAErD;;OAEG;IACH,yBAAmD;IAEnD;;OAEG;IACH,iBAA2C;IAG7C;;;;OAIG;IACH,iBAHW,MAAM,GACJ,MAAM,CAKlB;IAED;;;;OAIG;IACH,uBAHW,MAAM,GACJ,MAAM,CAelB;IAED;;;;;;OAMG;IACH,eAJW,MAAM,oCAEJ,MAAM,CAqBlB;IAED,+BAkFC;IAED,wDAUC;IAED,uBAKC;IAED;;OAEG;IAGH,2DAkCC;IAED,8DA6CC;CACF"}
|