@coherentglobal/spark-execute-sdk 0.4.2 → 0.4.4

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 CHANGED
@@ -754,10 +754,9 @@ var unzipBuffer = function unzipBuffer(model) {
754
754
  while (1) {
755
755
  switch (_context5.prev = _context5.next) {
756
756
  case 0:
757
- console.log("ENTERED UNZIP");
758
757
  modelToBlob = new Blob([new Uint8Array(model)]);
759
758
  new_zip = new jszip_1["default"]();
760
- _context5.next = 5;
759
+ _context5.next = 4;
761
760
  return new_zip.loadAsync(modelToBlob).then(function (zipped) {
762
761
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regenerator["default"].mark(function _callee4() {
763
762
  var response;
@@ -765,7 +764,6 @@ var unzipBuffer = function unzipBuffer(model) {
765
764
  while (1) {
766
765
  switch (_context4.prev = _context4.next) {
767
766
  case 0:
768
- console.log("ZIPPED: ", zipped);
769
767
  Object.keys(zipped.files).forEach(function (entry) {
770
768
  if (entry.indexOf("__MACOSX") === -1) {
771
769
  if (path_1["default"].extname(entry) === ".js") {
@@ -781,19 +779,14 @@ var unzipBuffer = function unzipBuffer(model) {
781
779
  });
782
780
  // if (!jsPath) return reject(new Error("Missing runtime file"));
783
781
  // if (!wasmPath) return reject(new Error("Missing engine file"));
784
- _context4.next = 4;
782
+ _context4.next = 3;
785
783
  return zipped.file(jsPath).async("text");
786
- case 4:
784
+ case 3:
787
785
  js = _context4.sent;
788
- _context4.next = 7;
786
+ _context4.next = 6;
789
787
  return zipped.file(wasmPath).async("arraybuffer");
790
- case 7:
788
+ case 6:
791
789
  wasm = _context4.sent;
792
- console.log("ZIPP INFO: ", {
793
- wasm: wasm,
794
- js: js,
795
- data: data
796
- });
797
790
  response = {
798
791
  wasm: {
799
792
  url: URL.createObjectURL(new Blob([wasm], {
@@ -809,12 +802,12 @@ var unzipBuffer = function unzipBuffer(model) {
809
802
  }
810
803
  };
811
804
  if (!dataPath) {
812
- _context4.next = 15;
805
+ _context4.next = 13;
813
806
  break;
814
807
  }
815
- _context4.next = 13;
808
+ _context4.next = 11;
816
809
  return zipped.file(dataPath).async("arraybuffer");
817
- case 13:
810
+ case 11:
818
811
  data = _context4.sent;
819
812
  response.data = {
820
813
  url: URL.createObjectURL(new Blob([data], {
@@ -822,9 +815,9 @@ var unzipBuffer = function unzipBuffer(model) {
822
815
  })),
823
816
  path: dataPath
824
817
  };
825
- case 15:
818
+ case 13:
826
819
  return _context4.abrupt("return", response);
827
- case 16:
820
+ case 14:
828
821
  case "end":
829
822
  return _context4.stop();
830
823
  }
@@ -832,10 +825,10 @@ var unzipBuffer = function unzipBuffer(model) {
832
825
  }, _callee4);
833
826
  }));
834
827
  });
835
- case 5:
828
+ case 4:
836
829
  loadZip = _context5.sent;
837
830
  return _context5.abrupt("return", loadZip);
838
- case 7:
831
+ case 6:
839
832
  case "end":
840
833
  return _context5.stop();
841
834
  }
@@ -850,7 +843,6 @@ var unzipppedModel = function unzipppedModel(model) {
850
843
  while (1) {
851
844
  switch (_context6.prev = _context6.next) {
852
845
  case 0:
853
- console.log("Entered UNZIPPED MODEL");
854
846
  servicename = model.servicename, wasm = model.wasm, js = model.js, data = model.data;
855
847
  response = {
856
848
  wasm: {
@@ -875,7 +867,7 @@ var unzipppedModel = function unzipppedModel(model) {
875
867
  };
876
868
  }
877
869
  return _context6.abrupt("return", response);
878
- case 5:
870
+ case 4:
879
871
  case "end":
880
872
  return _context6.stop();
881
873
  }
@@ -891,12 +883,11 @@ var getRuntimeContent = function getRuntimeContent(js, wasm) {
891
883
  while (1) {
892
884
  switch (_context9.prev = _context9.next) {
893
885
  case 0:
894
- console.log("RUNTIME DATA: ", data);
895
886
  if (!data) {
896
- _context9.next = 6;
887
+ _context9.next = 5;
897
888
  break;
898
889
  }
899
- _context9.next = 4;
890
+ _context9.next = 3;
900
891
  return fetch(js.url).then(function (res) {
901
892
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regenerator["default"].mark(function _callee7() {
902
893
  return _regenerator["default"].wrap(function _callee7$(_context7) {
@@ -914,11 +905,11 @@ var getRuntimeContent = function getRuntimeContent(js, wasm) {
914
905
  }).then(function (text) {
915
906
  return text.replace(wasm.path, wasm.url).replace(data.path, data.url).replace(data.path, data.url);
916
907
  });
917
- case 4:
908
+ case 3:
918
909
  _runtime = _context9.sent;
919
910
  return _context9.abrupt("return", _runtime);
920
- case 6:
921
- _context9.next = 8;
911
+ case 5:
912
+ _context9.next = 7;
922
913
  return fetch(js.url).then(function (res) {
923
914
  return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regenerator["default"].mark(function _callee8() {
924
915
  return _regenerator["default"].wrap(function _callee8$(_context8) {
@@ -936,10 +927,10 @@ var getRuntimeContent = function getRuntimeContent(js, wasm) {
936
927
  }).then(function (text) {
937
928
  return text.replace(wasm.path, wasm.url);
938
929
  });
939
- case 8:
930
+ case 7:
940
931
  runtime = _context9.sent;
941
932
  return _context9.abrupt("return", runtime);
942
- case 10:
933
+ case 9:
943
934
  case "end":
944
935
  return _context9.stop();
945
936
  }
@@ -967,7 +958,7 @@ var safeJsonParser = function safeJsonParser(data) {
967
958
  var result = JSON.parse(data);
968
959
  return result;
969
960
  } catch (err) {
970
- console.log('SAFE JSON PARSER FAILED: ', err);
961
+ console.log("SAFE JSON PARSER FAILED: ", err);
971
962
  return undefined;
972
963
  }
973
964
  };
@@ -1000,7 +991,6 @@ var WasmRunner = /*#__PURE__*/function () {
1000
991
  var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultCallback;
1001
992
  (0, _classCallCheck2["default"])(this, WasmRunner);
1002
993
  utils.isCompatible();
1003
- console.log('CALLBACK: ', callback);
1004
994
  this.license = license;
1005
995
  this.callback = callback;
1006
996
  this.models = [];
@@ -1060,47 +1050,45 @@ var WasmRunner = /*#__PURE__*/function () {
1060
1050
  modelUrl = m.url;
1061
1051
  isDataBuffer = (0, is_buffer_1["default"])(modelUrl);
1062
1052
  isObject = (0, _typeof2["default"])(modelUrl) === "object";
1063
- console.log("IS BUFFER: ", isDataBuffer);
1064
1053
  if (!isDataBuffer) {
1065
- _context14.next = 13;
1054
+ _context14.next = 12;
1066
1055
  break;
1067
1056
  }
1068
- _context14.next = 7;
1057
+ _context14.next = 6;
1069
1058
  return unzipBuffer(modelUrl);
1070
- case 7:
1059
+ case 6:
1071
1060
  bufferModel = _context14.sent;
1072
1061
  js = bufferModel.js;
1073
1062
  wasm = bufferModel.wasm;
1074
1063
  data = bufferModel.data;
1075
- _context14.next = 29;
1064
+ _context14.next = 27;
1076
1065
  break;
1077
- case 13:
1066
+ case 12:
1078
1067
  if (!isObject) {
1079
- _context14.next = 23;
1068
+ _context14.next = 21;
1080
1069
  break;
1081
1070
  }
1082
- _context14.next = 16;
1071
+ _context14.next = 15;
1083
1072
  return unzipppedModel(modelUrl);
1084
- case 16:
1073
+ case 15:
1085
1074
  unzipModelFile = _context14.sent;
1086
1075
  js = unzipModelFile.js;
1087
1076
  wasm = unzipModelFile.wasm;
1088
1077
  data = unzipModelFile.data;
1089
- console.log("----MODEL PATH is an OBJECT----");
1090
- _context14.next = 29;
1078
+ _context14.next = 27;
1091
1079
  break;
1092
- case 23:
1093
- _context14.next = 25;
1080
+ case 21:
1081
+ _context14.next = 23;
1094
1082
  return unzipFile(modelUrl);
1095
- case 25:
1083
+ case 23:
1096
1084
  unzipped = _context14.sent;
1097
1085
  js = unzipped.js;
1098
1086
  wasm = unzipped.wasm;
1099
1087
  data = unzipped.data;
1100
- case 29:
1101
- _context14.next = 31;
1088
+ case 27:
1089
+ _context14.next = 29;
1102
1090
  return getRuntimeContent(js, wasm, data);
1103
- case 31:
1091
+ case 29:
1104
1092
  runtime = _context14.sent;
1105
1093
  m.parents = this;
1106
1094
  m.worker = new Worker(utils.jsString2workerURL((0, template_1["default"])(runtime, license)));
@@ -1121,7 +1109,6 @@ var WasmRunner = /*#__PURE__*/function () {
1121
1109
  switch (_context13.prev = _context13.next) {
1122
1110
  case 0:
1123
1111
  _context13.prev = 0;
1124
- // const modelVersionId = "d18c6f24-92ac-454e-a4db-02233389fe7e"
1125
1112
  option = {
1126
1113
  folder_name: folderName,
1127
1114
  service_name: serviceName
@@ -1131,28 +1118,29 @@ var WasmRunner = /*#__PURE__*/function () {
1131
1118
  return m.parents.callback(option);
1132
1119
  case 4:
1133
1120
  modelVersionId = _context13.sent;
1134
- _context13.next = 7;
1121
+ requestData.request_meta.version_id = modelVersionId;
1122
+ _context13.next = 8;
1135
1123
  return m.parents.execute(requestData, modelVersionId);
1136
- case 7:
1124
+ case 8:
1137
1125
  results = _context13.sent;
1138
1126
  m.worker.postMessage([{
1139
1127
  request: oEvent.data.requestData,
1140
1128
  response: results
1141
1129
  }, "", "dispatch"]);
1142
1130
  resolve(results);
1143
- _context13.next = 16;
1131
+ _context13.next = 17;
1144
1132
  break;
1145
- case 12:
1146
- _context13.prev = 12;
1133
+ case 13:
1134
+ _context13.prev = 13;
1147
1135
  _context13.t0 = _context13["catch"](0);
1148
- console.log('CHILD MODEL ERROR:', _context13.t0);
1136
+ console.log("CHILD MODEL ERROR:", _context13.t0);
1149
1137
  reject(_context13.t0);
1150
- case 16:
1138
+ case 17:
1151
1139
  case "end":
1152
1140
  return _context13.stop();
1153
1141
  }
1154
1142
  }
1155
- }, _callee13, null, [[0, 12]]);
1143
+ }, _callee13, null, [[0, 13]]);
1156
1144
  }));
1157
1145
  });
1158
1146
  } else if (Array.isArray(oEvent.data)) {
@@ -1174,7 +1162,7 @@ var WasmRunner = /*#__PURE__*/function () {
1174
1162
  };
1175
1163
  checkModelStatus();
1176
1164
  }));
1177
- case 36:
1165
+ case 34:
1178
1166
  case "end":
1179
1167
  return _context14.stop();
1180
1168
  }
@@ -1334,10 +1322,16 @@ var WasmRunner = /*#__PURE__*/function () {
1334
1322
  while (1) {
1335
1323
  switch (_context17.prev = _context17.next) {
1336
1324
  case 0:
1325
+ version_uuid = id || ((_a = input === null || input === void 0 ? void 0 : input.request_meta) === null || _a === void 0 ? void 0 : _a.version_id) || ((_b = input.request_meta) === null || _b === void 0 ? void 0 : _b.version_uuid);
1326
+ if (!(input === null || input === void 0 ? void 0 : input.request_meta)) {
1327
+ input.request_meta = {};
1328
+ }
1329
+ if (id) {
1330
+ input.request_meta.version_id = version_uuid;
1331
+ }
1337
1332
  console.log("EXECUTING: ".concat(id, ", input: ").concat(JSON.stringify(input)));
1338
- version_uuid = id || ((_a = input.request_meta) === null || _a === void 0 ? void 0 : _a.version_id) || ((_b = input.request_meta) === null || _b === void 0 ? void 0 : _b.version_uuid);
1339
1333
  if (!version_uuid) {
1340
- _context17.next = 7;
1334
+ _context17.next = 9;
1341
1335
  break;
1342
1336
  }
1343
1337
  model = this._getModel(version_uuid);
@@ -1360,7 +1354,8 @@ var WasmRunner = /*#__PURE__*/function () {
1360
1354
  model.results[callid] = undefined;
1361
1355
  resolve(tryParsingResult);
1362
1356
  } else {
1363
- if (counter < 100) {
1357
+ if (counter < 6000) {
1358
+ // Increase timeout into 60s
1364
1359
  counter++;
1365
1360
  getResult();
1366
1361
  } else {
@@ -1368,7 +1363,8 @@ var WasmRunner = /*#__PURE__*/function () {
1368
1363
  }
1369
1364
  }
1370
1365
  } else {
1371
- if (counter < 100) {
1366
+ if (counter < 6000) {
1367
+ // Increase timeout into 60s
1372
1368
  counter++;
1373
1369
  getResult();
1374
1370
  } else {
@@ -1379,9 +1375,9 @@ var WasmRunner = /*#__PURE__*/function () {
1379
1375
  };
1380
1376
  getResult();
1381
1377
  }));
1382
- case 7:
1378
+ case 9:
1383
1379
  throw new error_1["default"].ParameterRequiredError("request_meta.version_id", input);
1384
- case 8:
1380
+ case 10:
1385
1381
  case "end":
1386
1382
  return _context17.stop();
1387
1383
  }
@@ -1402,7 +1398,7 @@ Object.defineProperty(exports, "__esModule", {
1402
1398
  });
1403
1399
  function buildWorkerFN(runtime) {
1404
1400
  var license = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "";
1405
- return "\n ".concat(runtime, "\n\n const license = '").concat(license, "';\n class MyEventEmitter{constructor(){this._events={}}on(e,t){this._events[e]||(this._events[e]=[]),this._events[e].push(t)}removeListener(e,t){if(!this._events[e]){throw new Error(\"Can't emit an event. Event doesn't exits.\"+e)}this._events[e]=this._events[e].filter((e=>e!==t))}emit(e,t){if(!this._events[e]){throw new Error(\"Can't emit an event. Event doesn't exits.\"+e)}this._events[e].forEach((e=>{e(t)}))}}const workerEventEmitter=new MyEventEmitter;let wasm,wb;const CALL_TYPE={0:\"SparkService\",1:\"ExternalApi\"},XcallResBuilder={Json:function(e,t,s,a,n,r){return JSON.stringify({metadata:{calltype:e,name:t,status:s,error_code:a,response_time:n},data:r||{}})},XML:()=>{}};function moduleInitialize(){Module().then((e=>{wasm=e,wb=e._construct(),console.log(\"ASYNC FLAG: \",e._is_async),console.log(\"ASYNC FLAG CALL: \",e._is_async(wb));var t=new TextDecoder(\"utf-8\");new TextEncoder;const s=0;e.dispatch=async(a,n,r)=>{const c=new Uint8Array(e.HEAPU8.subarray(n,n+r)),o=t.decode(c).slice(),i=JSON.parse(o),m=(i.folder_name,i.service_name);if(a===s){return await new Promise((async(e,t)=>{postMessage({requestData:i,type:\"stall\"});const s=\"xcall-loopback-result-\"+m;workerEventEmitter.on(s,(async t=>{const s=XcallResBuilder.Json(CALL_TYPE[0],m,202,\"\",0,JSON.stringify(t));e(s)}))}))}},postMessage(\"Initialized\")}))}moduleInitialize(),onmessage=async function(e){const t=e.data[0];e.data[1];if(\"dispatch\"===e.data[2]){t.request.folder_name;const e=t.request.service_name,s=t.response,a=\"xcall-loopback-result-\"+e;workerEventEmitter.emit(a,s)}else{const t=await runComputation(e);postMessage(t)}};const runComputation=async e=>{const t=e.data[0],s=e.data[1];if(void 0===wasm||void 0===wb)return new Error(\"WASM is not ready\");t?.request_meta?._ctx?.authorization&&(ctx.headers.authorization=t?.request_meta?._ctx?.authorization,delete t?.request_meta?._ctx?.authorization),t?.request_meta?._ctx?.secretkey&&(ctx.headers.secretkey=t?.request_meta?._ctx.secretkey,delete t?.request_meta?._ctx?.secretkey),t?.request_meta?._ctx?.[\"x-synthetic-key\"]&&(ctx.headers[\"x-synthetic-key\"]=t?.request_meta?._ctx?.[\"x-synthetic-key\"],delete t?.request_meta?._ctx?.[\"x-synthetic-key\"]),t?.request_meta?._ctx?.tenant&&(ctx.headers.tenant=t?.request_meta?._ctx?.tenant,delete t?.request_meta?._ctx?.tenant),t?.request_meta?._ctx?.servicemap&&(ctx.servicemap=t?.request_meta?._ctx?.servicemap,delete t?.request_meta?._ctx.servicemap);const a=(new TextEncoder).encode(t),n=wasm._malloc(a.length),r=a.BYTES_PER_ELEMENT;wasm.HEAP8.set(a,n/r);const c=wasm._malloc(8),o=await wasm.ccall(\"node_calc_v3\",\"number\",[\"number\",\"number\",\"number\",\"number\"],[wb,n,a.length,c],{async:!0});var i=wasm.getValue(c,\"i64\");const m=new Uint8Array(wasm.HEAPU8.subarray(o,o+i));const _=new TextDecoder(\"utf-8\").decode(m).slice();return wasm._free(n),wasm._free(c),wasm._free(o),[_,s]};\n\n");
1401
+ return "\n ".concat(runtime, "\n\n const license = '").concat(license, "';\n class MyEventEmitter{constructor(){this._events={}}on(e,t){this._events[e]||(this._events[e]=[]),this._events[e].push(t)}removeListener(e,t){if(!this._events[e]){throw new Error(\"Can't emit an event. Event doesn't exits.\"+e)}this._events[e]=this._events[e].filter((e=>e!==t))}emit(e,t){if(!this._events[e]){throw new Error(\"Can't emit an event. Event doesn't exits.\"+e)}this._events[e].forEach((e=>{e(t)}))}}const workerEventEmitter=new MyEventEmitter;let wasm,wb;const CALL_TYPE={0:\"SparkService\",1:\"ExternalApi\"},XcallResBuilder={Json:function(e,t,s,a,n,r){return JSON.stringify({metadata:{calltype:e,name:t,status:s,error_code:a,response_time:n},data:r||{}})},XML:()=>{}};function moduleInitialize(){Module().then((e=>{wasm=e,wb=e._construct();var t=new TextDecoder(\"utf-8\");new TextEncoder;const s=0;e.dispatch=async(a,n,r)=>{const c=new Uint8Array(e.HEAPU8.subarray(n,n+r)),i=t.decode(c).slice(),o=JSON.parse(i),m=(o.folder_name,o.service_name);if(a===s){return await new Promise((async(e,t)=>{postMessage({requestData:o,type:\"stall\"});const s=\"xcall-loopback-result-\"+m;workerEventEmitter.on(s,(async t=>{const s=XcallResBuilder.Json(CALL_TYPE[0],m,202,\"\",0,t);e(s)}))}))}},postMessage(\"Initialized\")}))}moduleInitialize(),onmessage=async function(e){const t=e.data[0];e.data[1];if(\"dispatch\"===e.data[2]){t.request.folder_name;const e=t.request.service_name,s=t.response,a=\"xcall-loopback-result-\"+e;workerEventEmitter.emit(a,s)}else{const t=await runComputation(e);postMessage(t)}};const runComputation=async e=>{const t=e.data[0],s=e.data[1];if(void 0===wasm||void 0===wb)return new Error(\"WASM is not ready\");t?.request_meta?._ctx?.authorization&&(ctx.headers.authorization=t?.request_meta?._ctx?.authorization,delete t?.request_meta?._ctx?.authorization),t?.request_meta?._ctx?.secretkey&&(ctx.headers.secretkey=t?.request_meta?._ctx.secretkey,delete t?.request_meta?._ctx?.secretkey),t?.request_meta?._ctx?.[\"x-synthetic-key\"]&&(ctx.headers[\"x-synthetic-key\"]=t?.request_meta?._ctx?.[\"x-synthetic-key\"],delete t?.request_meta?._ctx?.[\"x-synthetic-key\"]),t?.request_meta?._ctx?.tenant&&(ctx.headers.tenant=t?.request_meta?._ctx?.tenant,delete t?.request_meta?._ctx?.tenant),t?.request_meta?._ctx?.servicemap&&(ctx.servicemap=t?.request_meta?._ctx?.servicemap,delete t?.request_meta?._ctx.servicemap);const a=(new TextEncoder).encode(t),n=wasm._malloc(a.length),r=a.BYTES_PER_ELEMENT;wasm.HEAP8.set(a,n/r);const c=wasm._malloc(8),i=await wasm.ccall(\"node_calc_v3\",\"number\",[\"number\",\"number\",\"number\",\"number\"],[wb,n,a.length,c],{async:!0});var o=wasm.getValue(c,\"i64\");const m=new Uint8Array(wasm.HEAPU8.subarray(i,i+o));const _=new TextDecoder(\"utf-8\").decode(m).slice();return wasm._free(n),wasm._free(c),wasm._free(i),[_,s]};\n\n");
1406
1402
  }
1407
1403
  exports["default"] = buildWorkerFN;
1408
1404
 
@@ -6260,7 +6256,7 @@ var Spark = /*#__PURE__*/function () {
6260
6256
  /**
6261
6257
  * @private
6262
6258
  */
6263
- this.priority = ["model", "onlineEndpoint"];
6259
+ this.priority = ["model"];
6264
6260
  }
6265
6261
  /**
6266
6262
  *
@@ -6412,31 +6408,24 @@ var Spark = /*#__PURE__*/function () {
6412
6408
  key: "execute",
6413
6409
  value: function () {
6414
6410
  var _execute = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(input, version_id) {
6411
+ var _input$request_meta, _input$request_meta2;
6415
6412
  var versionID, lookup, response;
6416
6413
  return _regenerator["default"].wrap(function _callee$(_context) {
6417
6414
  while (1) {
6418
6415
  switch (_context.prev = _context.next) {
6419
6416
  case 0:
6420
- versionID = version_id || input.request_meta.version_id || input.request_meta.version_uuid;
6417
+ console.log("-------UOPD---");
6418
+ 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);
6421
6419
  lookup = {
6422
6420
  model: this.offlineModel,
6423
6421
  onlineEndpoint: this.onlineModelEndpoint
6424
6422
  };
6425
- _context.next = 4;
6423
+ _context.next = 5;
6426
6424
  return lookup[this.priority[0]](input, versionID, this);
6427
- case 4:
6428
- response = _context.sent;
6429
- if (!(response instanceof Error)) {
6430
- _context.next = 9;
6431
- break;
6432
- }
6433
- _context.next = 8;
6434
- return lookup[this.priority[1]](input, versionID, this);
6435
- case 8:
6425
+ case 5:
6436
6426
  response = _context.sent;
6437
- case 9:
6438
6427
  return _context.abrupt("return", response);
6439
- case 10:
6428
+ case 7:
6440
6429
  case "end":
6441
6430
  return _context.stop();
6442
6431
  }
@@ -6452,13 +6441,20 @@ var Spark = /*#__PURE__*/function () {
6452
6441
  key: "offlineModel",
6453
6442
  value: function () {
6454
6443
  var _offlineModel = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee3(input, versionID, ds) {
6455
- var callback, _model4$folder_name, _model4$service_name, _model4, result;
6444
+ var model, modelVersionId, callback, _model2$metaData$Engi, _model2$metaData, _model2$metaData$Engi2, _model2$metaData$Engi3, _model2$metaData2, _model2$metaData2$Eng, _model2, result;
6456
6445
  return _regenerator["default"].wrap(function _callee3$(_context3) {
6457
6446
  while (1) {
6458
6447
  switch (_context3.prev = _context3.next) {
6459
6448
  case 0:
6460
- console.log("OFFLINES");
6461
- _context3.prev = 1;
6449
+ model = ds._findModel(input.request_meta);
6450
+ modelVersionId = versionID || model && (model === null || model === void 0 ? void 0 : model.versionId); // const modelVersionId = input?.request_meta?.version_id || versionID;
6451
+ if (!(input !== null && input !== void 0 && input.request_meta)) {
6452
+ input.request_meta = {};
6453
+ }
6454
+ if (versionID) {
6455
+ input.request_meta.version_id = modelVersionId;
6456
+ }
6457
+ _context3.prev = 4;
6462
6458
  if (!(registry instanceof WasmRunner)) {
6463
6459
  /**
6464
6460
  * Options is the request data the the runner dispatch
@@ -6468,7 +6464,7 @@ var Spark = /*#__PURE__*/function () {
6468
6464
  */
6469
6465
  callback = /*#__PURE__*/function () {
6470
6466
  var _ref8 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee2(options) {
6471
- var hasFolderName, hasServiceName, hasVersionId, _model$metaData$Engin, _model, _model$metaData, _model$metaData$Engin2, _model$metaData$Engin3, _model2, _model2$metaData, _model2$metaData$Engi, _model3$metaData$Engi, _model3$metaData, _model3$metaData$Engi2, _model3$metaData$Engi3, _model3$metaData2, _model3$metaData2$Eng, _model3;
6467
+ var hasFolderName, hasServiceName, hasVersionId, _model$metaData$Engin, _model$metaData, _model$metaData$Engin2, _model$metaData$Engin3, _model$metaData2, _model$metaData2$Engi, _model$metaData$Engin4, _model$metaData3, _model$metaData3$Engi, _model$metaData$Engin5, _model$metaData4, _model$metaData4$Engi, _model;
6472
6468
  return _regenerator["default"].wrap(function _callee2$(_context2) {
6473
6469
  while (1) {
6474
6470
  switch (_context2.prev = _context2.next) {
@@ -6485,23 +6481,23 @@ var Spark = /*#__PURE__*/function () {
6485
6481
  id: hasVersionId,
6486
6482
  url: model.binary,
6487
6483
  meta: {
6488
- folder_name: (_model$metaData$Engin = (_model = model) === null || _model === void 0 ? void 0 : (_model$metaData = _model.metaData) === null || _model$metaData === void 0 ? void 0 : (_model$metaData$Engin2 = _model$metaData.EngineInformation) === null || _model$metaData$Engin2 === void 0 ? void 0 : _model$metaData$Engin2.ProductName) !== null && _model$metaData$Engin !== void 0 ? _model$metaData$Engin : "",
6489
- service_name: (_model$metaData$Engin3 = (_model2 = model) === null || _model2 === void 0 ? void 0 : (_model2$metaData = _model2.metaData) === null || _model2$metaData === void 0 ? void 0 : (_model2$metaData$Engi = _model2$metaData.EngineInformation) === null || _model2$metaData$Engi === void 0 ? void 0 : _model2$metaData$Engi.ServiceName) !== null && _model$metaData$Engin3 !== void 0 ? _model$metaData$Engin3 : ""
6484
+ folder_name: (_model$metaData$Engin = model === null || model === void 0 ? void 0 : (_model$metaData = model.metaData) === null || _model$metaData === void 0 ? void 0 : (_model$metaData$Engin2 = _model$metaData.EngineInformation) === null || _model$metaData$Engin2 === void 0 ? void 0 : _model$metaData$Engin2.ProductName) !== null && _model$metaData$Engin !== void 0 ? _model$metaData$Engin : "",
6485
+ service_name: (_model$metaData$Engin3 = model === null || model === void 0 ? void 0 : (_model$metaData2 = model.metaData) === null || _model$metaData2 === void 0 ? void 0 : (_model$metaData2$Engi = _model$metaData2.EngineInformation) === null || _model$metaData2$Engi === void 0 ? void 0 : _model$metaData2$Engi.ServiceName) !== null && _model$metaData$Engin3 !== void 0 ? _model$metaData$Engin3 : ""
6490
6486
  }
6491
6487
  });
6492
6488
  case 6:
6493
6489
  _context2.next = 12;
6494
6490
  break;
6495
6491
  case 8:
6496
- _model3 = ds._getModelByMeta(hasFolderName, hasServiceName);
6497
- hasVersionId = _model3 === null || _model3 === void 0 ? void 0 : _model3.versionId;
6492
+ _model = ds._getModelByMeta(hasFolderName, hasServiceName);
6493
+ hasVersionId = _model === null || _model === void 0 ? void 0 : _model.versionId;
6498
6494
  _context2.next = 12;
6499
6495
  return registry.append({
6500
6496
  id: hasVersionId,
6501
- url: _model3.binary,
6497
+ url: _model.binary,
6502
6498
  meta: {
6503
- folder_name: (_model3$metaData$Engi = _model3 === null || _model3 === void 0 ? void 0 : (_model3$metaData = _model3.metaData) === null || _model3$metaData === void 0 ? void 0 : (_model3$metaData$Engi2 = _model3$metaData.EngineInformation) === null || _model3$metaData$Engi2 === void 0 ? void 0 : _model3$metaData$Engi2.ProductName) !== null && _model3$metaData$Engi !== void 0 ? _model3$metaData$Engi : "",
6504
- service_name: (_model3$metaData$Engi3 = _model3 === null || _model3 === void 0 ? void 0 : (_model3$metaData2 = _model3.metaData) === null || _model3$metaData2 === void 0 ? void 0 : (_model3$metaData2$Eng = _model3$metaData2.EngineInformation) === null || _model3$metaData2$Eng === void 0 ? void 0 : _model3$metaData2$Eng.ServiceName) !== null && _model3$metaData$Engi3 !== void 0 ? _model3$metaData$Engi3 : ""
6499
+ folder_name: (_model$metaData$Engin4 = _model === null || _model === void 0 ? void 0 : (_model$metaData3 = _model.metaData) === null || _model$metaData3 === void 0 ? void 0 : (_model$metaData3$Engi = _model$metaData3.EngineInformation) === null || _model$metaData3$Engi === void 0 ? void 0 : _model$metaData3$Engi.ProductName) !== null && _model$metaData$Engin4 !== void 0 ? _model$metaData$Engin4 : "",
6500
+ service_name: (_model$metaData$Engin5 = _model === null || _model === void 0 ? void 0 : (_model$metaData4 = _model.metaData) === null || _model$metaData4 === void 0 ? void 0 : (_model$metaData4$Engi = _model$metaData4.EngineInformation) === null || _model$metaData4$Engi === void 0 ? void 0 : _model$metaData4$Engi.ServiceName) !== null && _model$metaData$Engin5 !== void 0 ? _model$metaData$Engin5 : ""
6505
6501
  }
6506
6502
  });
6507
6503
  case 12:
@@ -6519,36 +6515,36 @@ var Spark = /*#__PURE__*/function () {
6519
6515
  }();
6520
6516
  registry = new WasmRunner("", callback);
6521
6517
  }
6522
- if (registry.isExist(versionID)) {
6523
- _context3.next = 7;
6518
+ if (registry.isExist(modelVersionId)) {
6519
+ _context3.next = 10;
6524
6520
  break;
6525
6521
  }
6526
- _model4 = ds._findModel(versionID);
6527
- _context3.next = 7;
6522
+ _model2 = ds._findModel(input.request_meta);
6523
+ _context3.next = 10;
6528
6524
  return registry.append({
6529
- id: versionID,
6530
- url: _model4.binary,
6525
+ id: modelVersionId,
6526
+ url: _model2.binary,
6531
6527
  meta: {
6532
- folder_name: (_model4$folder_name = _model4 === null || _model4 === void 0 ? void 0 : _model4.folder_name) !== null && _model4$folder_name !== void 0 ? _model4$folder_name : "",
6533
- service_name: (_model4$service_name = _model4 === null || _model4 === void 0 ? void 0 : _model4.service_name) !== null && _model4$service_name !== void 0 ? _model4$service_name : ""
6528
+ folder_name: (_model2$metaData$Engi = _model2 === null || _model2 === void 0 ? void 0 : (_model2$metaData = _model2.metaData) === null || _model2$metaData === void 0 ? void 0 : (_model2$metaData$Engi2 = _model2$metaData.EngineInformation) === null || _model2$metaData$Engi2 === void 0 ? void 0 : _model2$metaData$Engi2.ProductName) !== null && _model2$metaData$Engi !== void 0 ? _model2$metaData$Engi : "",
6529
+ service_name: (_model2$metaData$Engi3 = _model2 === null || _model2 === void 0 ? void 0 : (_model2$metaData2 = _model2.metaData) === null || _model2$metaData2 === void 0 ? void 0 : (_model2$metaData2$Eng = _model2$metaData2.EngineInformation) === null || _model2$metaData2$Eng === void 0 ? void 0 : _model2$metaData2$Eng.ServiceName) !== null && _model2$metaData$Engi3 !== void 0 ? _model2$metaData$Engi3 : ""
6534
6530
  }
6535
6531
  });
6536
- case 7:
6537
- _context3.next = 9;
6538
- return registry.execute(input, versionID, function () {});
6539
- case 9:
6532
+ case 10:
6533
+ _context3.next = 12;
6534
+ return registry.execute(input, modelVersionId, function () {});
6535
+ case 12:
6540
6536
  result = _context3.sent;
6541
6537
  return _context3.abrupt("return", result);
6542
- case 13:
6543
- _context3.prev = 13;
6544
- _context3.t0 = _context3["catch"](1);
6545
- return _context3.abrupt("return", _context3.t0);
6546
6538
  case 16:
6539
+ _context3.prev = 16;
6540
+ _context3.t0 = _context3["catch"](4);
6541
+ return _context3.abrupt("return", _context3.t0);
6542
+ case 19:
6547
6543
  case "end":
6548
6544
  return _context3.stop();
6549
6545
  }
6550
6546
  }
6551
- }, _callee3, null, [[1, 13]]);
6547
+ }, _callee3, null, [[4, 16]]);
6552
6548
  }));
6553
6549
  function offlineModel(_x3, _x4, _x5) {
6554
6550
  return _offlineModel.apply(this, arguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coherentglobal/spark-execute-sdk",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "description": "",
5
5
  "main": "src/node.js",
6
6
  "browser": "dist/browser.js",
@@ -21,7 +21,7 @@
21
21
  "author": "",
22
22
  "license": "ISC",
23
23
  "dependencies": {
24
- "@coherentglobal/wasm-runner": "^0.0.55",
24
+ "@coherentglobal/wasm-runner": "^0.0.57",
25
25
  "@types/node": "^18.7.18",
26
26
  "axios": "^0.27.2",
27
27
  "chai": "^4.3.6",
package/src/browser.js CHANGED
@@ -47,7 +47,7 @@ class Spark {
47
47
  /**
48
48
  * @private
49
49
  */
50
- this.priority = ["model", "onlineEndpoint"];
50
+ this.priority = ["model"];
51
51
  }
52
52
  /**
53
53
  *
@@ -232,28 +232,36 @@ class Spark {
232
232
  * @returns {object}
233
233
  */
234
234
  async execute(input, version_id) {
235
+ console.log("-------UOPD---");
235
236
  const versionID =
236
237
  version_id ||
237
- input.request_meta.version_id ||
238
- input.request_meta.version_uuid;
239
-
238
+ input?.request_meta?.version_id ||
239
+ input?.request_meta?.version_uuid;
240
240
  let lookup = {
241
241
  model: this.offlineModel,
242
242
  onlineEndpoint: this.onlineModelEndpoint,
243
243
  };
244
244
 
245
245
  let response;
246
-
247
246
  response = await lookup[this.priority[0]](input, versionID, this);
248
- if (response instanceof Error) {
249
- response = await lookup[this.priority[1]](input, versionID, this);
250
- }
251
-
247
+ // if (response instanceof Error) {
248
+ // response = await lookup[this.priority[1]](input, versionID, this);
249
+ // }
252
250
  return response;
253
251
  }
254
252
 
255
253
  async offlineModel(input, versionID, ds) {
256
- console.log("OFFLINES");
254
+ const model = ds._findModel(input.request_meta);
255
+
256
+ const modelVersionId = versionID || (model && model?.versionId);
257
+ // const modelVersionId = input?.request_meta?.version_id || versionID;
258
+ if (!input?.request_meta) {
259
+ input.request_meta = {};
260
+ }
261
+ if (versionID) {
262
+ input.request_meta.version_id = modelVersionId;
263
+ }
264
+
257
265
  try {
258
266
  if (!(registry instanceof WasmRunner)) {
259
267
  /**
@@ -266,6 +274,7 @@ class Spark {
266
274
  const hasFolderName = options?.folder_name;
267
275
  const hasServiceName = options?.service_name;
268
276
  let hasVersionId = options?.version_id;
277
+
269
278
  if (hasVersionId && !registry.isExist(hasVersionId)) {
270
279
  await registry.append({
271
280
  id: hasVersionId,
@@ -295,19 +304,18 @@ class Spark {
295
304
  };
296
305
  registry = new WasmRunner("", callback);
297
306
  }
298
-
299
- if (!registry.isExist(versionID)) {
300
- const model = ds._findModel(versionID);
307
+ if (!registry.isExist(modelVersionId)) {
308
+ const model = ds._findModel(input.request_meta);
301
309
  await registry.append({
302
- id: versionID,
310
+ id: modelVersionId,
303
311
  url: model.binary,
304
312
  meta: {
305
- folder_name: model?.folder_name ?? "",
306
- service_name: model?.service_name ?? "",
313
+ folder_name: model?.metaData?.EngineInformation?.ProductName ?? "",
314
+ service_name: model?.metaData?.EngineInformation?.ServiceName ?? "",
307
315
  },
308
316
  });
309
317
  }
310
- const result = await registry.execute(input, versionID, () => {});
318
+ const result = await registry.execute(input, modelVersionId, () => {});
311
319
  return result;
312
320
  } catch (err) {
313
321
  return err;