@incodetech/core 0.0.0-dev-20260826-e81bd6f9 → 0.0.0-dev-20260826-80a51538

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.
Files changed (93) hide show
  1. package/dist/{BrowserDiagnosticsCryptoProvider-DroaGhav.esm.js → BrowserDiagnosticsCryptoProvider-DfkPafSO.esm.js} +1 -1
  2. package/dist/{BrowserStorageProvider-C8847M9W.esm.js → BrowserStorageProvider-DC___749.esm.js} +1 -1
  3. package/dist/{IWasmUtilCapability-5-Pncgma.d.ts → IWasmUtilCapability-SNPhmIwB.d.ts} +0 -1
  4. package/dist/{MotionSensorProvider-CxTjgXe6.esm.js → MotionSensorProvider-Dq6GJ-ke.esm.js} +1 -1
  5. package/dist/ae-signature.esm.js +1 -1
  6. package/dist/{apiError-BbJ7ewMs.esm.js → apiError-C_90i3vV.esm.js} +1 -1
  7. package/dist/authentication.d.ts +3 -3
  8. package/dist/authentication.esm.js +2 -2
  9. package/dist/{authenticationManager-BXZfUKaI.esm.js → authenticationManager-7ec9wEfD.esm.js} +4 -4
  10. package/dist/{authenticationManager-QbR9ezH3.d.ts → authenticationManager-DFA73BWw.d.ts} +1 -1
  11. package/dist/{authenticationStateMachine-DS9N05Mj.esm.js → authenticationStateMachine-d7NM3jSI.esm.js} +2 -2
  12. package/dist/camera.esm.js +1 -1
  13. package/dist/consent.d.ts +1 -1
  14. package/dist/{consentManager-uhDPdU6i.d.ts → consentManager-DLOyIZzt.d.ts} +1 -1
  15. package/dist/{deepsightLoader-D_pTgevT.esm.js → deepsightLoader-CQ8p6f3n.esm.js} +6 -6
  16. package/dist/{deepsightService-BQO1pV6B.d.ts → deepsightService-MZOpj7Vp.d.ts} +1 -1
  17. package/dist/document-capture.esm.js +2 -2
  18. package/dist/{documentCaptureManager-BbdImodx.esm.js → documentCaptureManager-BsgEpSEe.esm.js} +1 -1
  19. package/dist/{documentCaptureStateMachine-BjBgWp7z.esm.js → documentCaptureStateMachine-BmcBWiUz.esm.js} +2 -2
  20. package/dist/dynamic-forms.esm.js +2 -2
  21. package/dist/{dynamicFormsManager-CBVWDFYZ.esm.js → dynamicFormsManager-BD78xRhz.esm.js} +1 -1
  22. package/dist/{dynamicFormsStateMachine-Cc_mw7BP.esm.js → dynamicFormsStateMachine-CQ8uFClH.esm.js} +1 -1
  23. package/dist/ekyb.esm.js +3 -3
  24. package/dist/{ekybManager-DQy8cwae.esm.js → ekybManager-Ce6FEncZ.esm.js} +1 -1
  25. package/dist/{ekybStateMachine-DvRr4p-k.esm.js → ekybStateMachine-mfXIl5v-.esm.js} +1 -1
  26. package/dist/electronic-signature.esm.js +1 -1
  27. package/dist/{electronicSignatureManager-5cwtDmd5.esm.js → electronicSignatureManager-q0-iMmIE.esm.js} +1 -1
  28. package/dist/extensibility.d.ts +11 -12
  29. package/dist/extensibility.esm.js +12 -12
  30. package/dist/{faceCaptureManagerFactory-ZRoAAJ-9.esm.js → faceCaptureManagerFactory-BQn2gK5B.esm.js} +3 -3
  31. package/dist/{faceCaptureManagerFactory-B0Ce6p_p.d.ts → faceCaptureManagerFactory-D-eOL-h6.d.ts} +4 -4
  32. package/dist/{faceCaptureSetup-CThWhLbH.esm.js → faceCaptureSetup-Civi4sX0.esm.js} +4 -4
  33. package/dist/{feature-management-BdXv1wdg.esm.js → feature-management-VVeaOPVH.esm.js} +1 -1
  34. package/dist/feature-management.esm.js +1 -1
  35. package/dist/flow.d.ts +2 -2
  36. package/dist/flow.esm.js +3 -3
  37. package/dist/{flowCompletionService-8LZdgnFO.esm.js → flowCompletionService-BeGI43Sa.esm.js} +1 -1
  38. package/dist/{flowServices-0Unj1i_g.esm.js → flowServices-B8KjJDqC.esm.js} +4 -4
  39. package/dist/geolocation.esm.js +2 -2
  40. package/dist/{geolocationManager-njjgkoz_.esm.js → geolocationManager-ZACmKzTE.esm.js} +1 -1
  41. package/dist/{geolocationStateMachine-ChxMczVf.esm.js → geolocationStateMachine-MsxfZhyZ.esm.js} +1 -1
  42. package/dist/id-ocr.d.ts +1 -1
  43. package/dist/id-selfie-flow.d.ts +1 -1
  44. package/dist/id-selfie-flow.esm.js +8 -8
  45. package/dist/id.d.ts +2 -2
  46. package/dist/id.esm.js +4 -4
  47. package/dist/idCaptureDefaults-SJH6Td2K.esm.js +276 -0
  48. package/dist/{idCaptureManager-w0XxDand.d.ts → idCaptureManager-C-ef1D5r.d.ts} +2 -2
  49. package/dist/{idCaptureManager-B7Hdyqoc.esm.js → idCaptureManager-kkVWhnDe.esm.js} +5 -5
  50. package/dist/{idCaptureServices-BSZquQ6d.esm.js → idCaptureServices-CLserSrT.esm.js} +5 -5
  51. package/dist/{idCaptureStateMachine-D7ms1UTC.esm.js → idCaptureStateMachine-DtGemWtA.esm.js} +11 -11
  52. package/dist/{idOcrManager-BF_cXZq8.d.ts → idOcrManager-CFlDwUvN.d.ts} +1 -1
  53. package/dist/identity-reuse.d.ts +1 -1
  54. package/dist/{identityReuseManager-v2TH5g7e.d.ts → identityReuseManager-BXEBBI3N.d.ts} +5 -5
  55. package/dist/index.esm.js +1 -1
  56. package/dist/mandatory-consent.d.ts +1 -1
  57. package/dist/{mandatoryConsentManager-BG3ZPM3f.d.ts → mandatoryConsentManager-CohPXtwL.d.ts} +5 -5
  58. package/dist/{onDeviceFaceResults-BxRVRs9-.esm.js → onDeviceFaceResults-B6Gtw21L.esm.js} +75 -12
  59. package/dist/{permissionGuards-DCzi2X20.esm.js → permissionGuards-DKnCqOsF.esm.js} +1 -1
  60. package/dist/{permissionServices-Ct-QgtAi.esm.js → permissionServices-QCFFUVkj.esm.js} +2 -2
  61. package/dist/personhood.d.ts +3 -3
  62. package/dist/personhood.esm.js +6 -6
  63. package/dist/qe-signature.esm.js +1 -1
  64. package/dist/{recordingService-CN3rO3Rl.esm.js → recordingService-DBxMZwD9.esm.js} +1 -1
  65. package/dist/{runChildModule-CWYUt6Eb.esm.js → runChildModule-BVRBfQKD.esm.js} +1 -1
  66. package/dist/{safeStorage-2nOSCCnG.esm.js → safeStorage-7CmStgyt.esm.js} +348 -363
  67. package/dist/{sdkVersion-CBs-fcJT.esm.js → sdkVersion-DayEIYK-.esm.js} +1 -1
  68. package/dist/selfie.d.ts +4 -4
  69. package/dist/selfie.esm.js +6 -6
  70. package/dist/{selfieManager-DeSGiO2o.esm.js → selfieManager-DZcXrdkt.esm.js} +4 -4
  71. package/dist/{selfieManager-BRb_-wHE.d.ts → selfieManager-DpU8kDro.d.ts} +1 -1
  72. package/dist/{selfieStateMachine-q9zW90MX.esm.js → selfieStateMachine-BJiFfV1Q.esm.js} +2 -2
  73. package/dist/{session-nsNphgUa.esm.js → session-Bat4R9kV.esm.js} +4 -4
  74. package/dist/session.esm.js +4 -4
  75. package/dist/{sessionInitializer-bq_60unZ.esm.js → sessionInitializer-DcdeBlD1.esm.js} +4 -4
  76. package/dist/{setup-FUYImQXy.esm.js → setup-P7NmS-XX.esm.js} +8 -8
  77. package/dist/trueSight-CpKAW400.esm.js +1 -0
  78. package/dist/{trueSightService-DA5Bt2s3.esm.js → trueSightService-CYxmF608.esm.js} +3 -3
  79. package/dist/{types-lw5kpZ0i2.d.ts → types-CyoB7Hym2.d.ts} +2 -2
  80. package/dist/{types-BMa0ZqAi.d.ts → types-DQ-TrzPk.d.ts} +1 -1
  81. package/dist/{types-jBSE34JY.d.ts → types-EDqrHgXD.d.ts} +1 -1
  82. package/dist/video-selfie.d.ts +1 -1
  83. package/dist/video-selfie.esm.js +4 -4
  84. package/dist/{videoSelfieCameraWarmer-DlYZA78k.esm.js → videoSelfieCameraWarmer-B6q6lWkk.esm.js} +4 -4
  85. package/dist/{videoSelfieStepDetector-g3PJIqyq.d.ts → videoSelfieStepDetector-DVXE0upL.d.ts} +2 -2
  86. package/dist/wasm.esm.js +4 -4
  87. package/dist/{wasmDefaults-BrwMccqW.esm.js → wasmDefaults-DEOK0oAq.esm.js} +1 -1
  88. package/dist/{wasmDsFlagSync-Dd7Yj25O.esm.js → wasmDsFlagSync-BTc8xI86.esm.js} +2 -2
  89. package/dist/{wasmWebClient-BzFsDjU6.esm.js → wasmWebClient-BJCaFeBL.esm.js} +55 -6
  90. package/dist/workflow.esm.js +16 -16
  91. package/package.json +3 -3
  92. package/dist/idCaptureDefaults-Dowxd3J3.esm.js +0 -226
  93. package/dist/trueSight-Cw9ktWo0.esm.js +0 -1
@@ -1,7 +1,48 @@
1
- import { c as loadWasmModule, g as resolveWasmSource, h as missingWasmModelError, l as SemaphoreProvider, n as createWebApiHostAdapter, p as WASM_PIPELINE_MODELS, s as wasmCallWrapper } from "./wasmWebClient-BzFsDjU6.esm.js";
2
- var mlWasmJSApi_default = class MlWasmJSApi {
3
- constructor() {
4
- this.versionsFile = null;
1
+ import { _ as resolveWasmSource, c as wasmCallWrapper, g as missingWasmModelError, l as loadWasmModule, m as WASM_PIPELINE_MODELS, n as createWebApiHostAdapter, s as ML_CALL_MAX_POLLS, u as SemaphoreProvider } from "./wasmWebClient-BJCaFeBL.esm.js";
2
+ //#region ../infra/src/wasm/wasmEnumMaps.ts
3
+ function pipelineTypeToWasmEnum(wasmModule, type) {
4
+ switch (type) {
5
+ case 0: return wasmModule.WorkflowType.IdBlurGlareWorkflow;
6
+ case 1: return wasmModule.WorkflowType.IdBarcodeAndTextQualityWorkflow;
7
+ case 2: return wasmModule.WorkflowType.IdVideoSelfieWorkflow;
8
+ case 3: return wasmModule.WorkflowType.SelfieWithAggregationMetrics;
9
+ case 4: return wasmModule.WorkflowType.SelfieWithQualityMetrics;
10
+ case 5: return wasmModule.WorkflowType.OnDeviceSelfieWorkflow;
11
+ default: throw new Error("Unknown pipeline type");
12
+ }
13
+ }
14
+ function pipelineTypeFromWasmEnum(wasmModule, type) {
15
+ switch (type) {
16
+ case wasmModule.WorkflowType.IdBlurGlareWorkflow: return 0;
17
+ case wasmModule.WorkflowType.IdBarcodeAndTextQualityWorkflow: return 1;
18
+ case wasmModule.WorkflowType.IdVideoSelfieWorkflow: return 2;
19
+ case wasmModule.WorkflowType.SelfieWithAggregationMetrics: return 3;
20
+ case wasmModule.WorkflowType.SelfieWithQualityMetrics: return 4;
21
+ case wasmModule.WorkflowType.OnDeviceSelfieWorkflow: return 5;
22
+ default: throw new Error("Unknown pipeline type");
23
+ }
24
+ }
25
+ function idCaptureModelTypeToWasmEnum(wasmModule, type) {
26
+ switch (type) {
27
+ case 0: return wasmModule.IdCaptureModelType.IdCaptureV1x;
28
+ case 1: return wasmModule.IdCaptureModelType.IdCaptureV2x;
29
+ case 2: return wasmModule.IdCaptureModelType.IdCaptureV3x;
30
+ default: throw new Error("Unknown Id Capture model type");
31
+ }
32
+ }
33
+ function idCaptureModelTypeFromWasmEnum(wasmModule, type) {
34
+ switch (type) {
35
+ case wasmModule.IdCaptureModelType.IdCaptureV1x: return 0;
36
+ case wasmModule.IdCaptureModelType.IdCaptureV2x: return 1;
37
+ case wasmModule.IdCaptureModelType.IdCaptureV3x: return 2;
38
+ default: throw new Error("Unknown Id Capture model type");
39
+ }
40
+ }
41
+ //#endregion
42
+ //#region ../infra/src/wasm/WasmRuntime.ts
43
+ var WasmRuntime = class WasmRuntime {
44
+ constructor(loadModule = loadWasmModule) {
45
+ this.loadModule = loadModule;
5
46
  this.modelsBuffers = null;
6
47
  this.inputImageBuffer = null;
7
48
  this.wasmModule = null;
@@ -14,19 +55,14 @@ var mlWasmJSApi_default = class MlWasmJSApi {
14
55
  this.imageHeight_ = null;
15
56
  this.pipelines_ = null;
16
57
  this.isInitialized_ = false;
17
- this.inspectorOpened_ = false;
18
58
  this.onDeviceMode_ = false;
19
- this.dsEnabled_ = false;
20
- this.wasmCallSemaphore = new SemaphoreProvider();
21
- this.Module = null;
59
+ this.mlCallSemaphore = new SemaphoreProvider();
22
60
  }
23
- async initialize({ module, versionsFile, pipelines }) {
61
+ async initialize({ module, pipelines }) {
24
62
  await this.freeResources();
25
63
  this.pipelines_ = pipelines;
26
- this.versionsFile = versionsFile;
27
- const { wasmModule, simdUsed } = await loadWasmModule(module);
64
+ const { wasmModule, simdUsed } = await this.loadModule(module);
28
65
  this.wasmModule = wasmModule;
29
- this.Module = window.Module;
30
66
  this.workflowApiUtilities = new this.wasmModule.WorkflowApiUtilities();
31
67
  this.utilityApi = new this.wasmModule.UtilityApi();
32
68
  this.utilityApi.setOnDeviceMode(this.onDeviceMode_);
@@ -36,10 +72,6 @@ var mlWasmJSApi_default = class MlWasmJSApi {
36
72
  this.isInitialized_ = true;
37
73
  return simdUsed;
38
74
  }
39
- static getInstance() {
40
- if (!MlWasmJSApi.instance) MlWasmJSApi.instance = new MlWasmJSApi();
41
- return MlWasmJSApi.instance;
42
- }
43
75
  /**
44
76
  * Returns initialization status
45
77
  * @returns
@@ -54,46 +86,43 @@ var mlWasmJSApi_default = class MlWasmJSApi {
54
86
  * @param {number} imageHeight - image height
55
87
  */
56
88
  async allocateImageBuffers(imageWidth, imageHeight) {
57
- this.checkWasmInitialization("Unable to allocate image buffers, cpp API hasn't been initialized");
89
+ const workflowApiUtilities = this.requireWorkflowApiUtilities("Unable to allocate image buffers, cpp API hasn't been initialized");
58
90
  if (imageWidth && imageHeight && imageWidth == this.imageWidth_ && imageHeight == this.imageHeight_ && this.inputImageBuffer && imageWidth * imageHeight * 4 === this.inputImageBuffer.length) return;
59
91
  this.imageWidth_ = imageWidth;
60
92
  this.imageHeight_ = imageHeight;
61
- this.inputImageBuffer = this.workflowApiUtilities.allocateInputImageBuffer(imageWidth, imageHeight, 4);
62
- }
63
- async handleDetectionCallAndUpdateState(type) {
64
- this.checkWasmInitialization("Unable to update pipeline state, cpp API hasn't been initialized");
65
- this.workflowApiUtilities.handleDetectionCallAndUpdateState(this.pipelineTypeToWasmEnum(type));
66
- }
67
- ens(image) {
68
- this.checkWasmInitialization("Unable to encrypt the image, cpp API hasn't been initialized");
69
- return this.utilityApi.ens(image);
70
- }
71
- isVirtualCamera(label) {
72
- this.checkWasmInitialization("Unable to check if the camera is virtual, cpp API hasn't been initialized");
73
- if (label) return this.utilityApi.isVirtualCamera(label);
74
- return false;
75
- }
76
- estimatePerformance() {
77
- this.checkWasmInitialization("Unable to estimate performance, cpp API hasn't been initialized");
78
- return this.utilityApi.estimatePerformance();
93
+ this.inputImageBuffer = workflowApiUtilities.allocateInputImageBuffer(imageWidth, imageHeight, 4);
79
94
  }
80
- async analyzeFrame(image) {
81
- this.checkWasmInitialization("Unable to analyze the frame, cpp API hasn't been initialized");
82
- await this.allocateImageBuffers(image.width, image.height);
95
+ /**
96
+ * Copies one frame into the shared input image buffer.
97
+ *
98
+ * The only write path into `inputImageBuffer`, so no caller outside this class
99
+ * touches the field. It is the guard + `set()` pair that `process`,
100
+ * `runIdCapture`, `runSelfieCapture` and `analyzeFrame` each performed inline,
101
+ * including the error message: semantically identical at all four sites, and
102
+ * byte-identical at three. `analyzeFrame`'s local capture (`const
103
+ * inputImageBuffer = this.inputImageBuffer`, then `.set()` on the local) is
104
+ * folded into a double read of the field, which cannot observe two different
105
+ * values because nothing awaits between the guard and the `set()`.
106
+ *
107
+ * Buffers must already be sized by {@link allocateImageBuffers}.
108
+ */
109
+ writeFrame(image) {
110
+ if (this.inputImageBuffer === null) throw new Error("Unable to process the image, buffers haven't been allocated!");
83
111
  this.inputImageBuffer.set(image.data);
84
- this.utilityApi.analyzeFrame();
112
+ }
113
+ async handleDetectionCallAndUpdateState(type) {
114
+ this.requireWorkflowApiUtilities("Unable to update pipeline state, cpp API hasn't been initialized").handleDetectionCallAndUpdateState(this.pipelineTypeToWasmEnum(type));
85
115
  }
86
116
  /**
87
117
  * Free allocated memory
88
118
  */
89
119
  async freeResources() {
90
- this.versionsFile = null;
91
120
  this.modelsBuffers = null;
92
121
  this.inputImageBuffer = null;
93
122
  this.imageWidth_ = null;
94
123
  this.imageHeight_ = null;
95
124
  this.pipelines_ = null;
96
- window.wasmArrayBuffer = null;
125
+ if (typeof window !== "undefined") window.wasmArrayBuffer = null;
97
126
  if (this.workflowApiUtilities && typeof this.workflowApiUtilities.delete === "function") {
98
127
  this.workflowApiUtilities.delete();
99
128
  this.workflowApiUtilities = null;
@@ -119,29 +148,15 @@ var mlWasmJSApi_default = class MlWasmJSApi {
119
148
  * Clear pipeline state
120
149
  */
121
150
  resetPipeline(type) {
122
- this.checkWasmInitialization("Unable to reset pipeline, cpp API hasn't been initialized");
123
- this.workflowApiUtilities.resetWorkflow(this.pipelineTypeToWasmEnum(type));
151
+ this.requireWorkflowApiUtilities("Unable to reset pipeline, cpp API hasn't been initialized").resetWorkflow(this.pipelineTypeToWasmEnum(type));
124
152
  }
125
153
  /**
126
154
  * Clear all pipelines states
127
155
  */
128
156
  resetAllPipelines() {
129
- this.checkWasmInitialization("Unable to reset pipelines, cpp API hasn't been initialized");
130
- for (const [type, model] of this.pipelines_) this.resetPipeline(type);
131
- }
132
- /**
133
- * Clear all states, not related to ml pipelines
134
- */
135
- resetOther() {
136
- this.checkWasmInitialization("Unable to reset other states, cpp API hasn't been initialized");
137
- this.utilityApi.resetOther();
138
- }
139
- /**
140
- * Full reset
141
- */
142
- reset() {
143
- this.resetAllPipelines();
144
- this.resetOther();
157
+ const pipelines = this.pipelines_;
158
+ if (!this.isInitialized() || pipelines === null) throw new Error("Unable to reset pipelines, cpp API hasn't been initialized");
159
+ for (const [type] of pipelines) this.resetPipeline(type);
145
160
  }
146
161
  /**
147
162
  * Process one frame using one of the pipelines
@@ -150,317 +165,136 @@ var mlWasmJSApi_default = class MlWasmJSApi {
150
165
  * @returns
151
166
  */
152
167
  async process(image, type) {
153
- this.checkWasmInitialization("Unable to process the image, cpp API hasn't been initialized");
154
- if (this.inputImageBuffer === null) throw new Error("Unable to process the image, buffers haven't been allocated!");
155
- this.inputImageBuffer.set(image.data);
168
+ const message = "Unable to process the image, cpp API hasn't been initialized";
169
+ const idCaptureWasmApi = this.requireIdCaptureApi(message);
170
+ const faceProcessingWasmApi = this.requireFaceProcessingApi(message);
171
+ this.writeFrame(image);
156
172
  switch (type) {
157
173
  case 0:
158
- case 1: return this.idCaptureWasmApi.runIdCaptureWorkflow(this.pipelineTypeToWasmEnum(type));
159
- case 2: return this.idCaptureWasmApi.runIdVideoSelfieWorkflow();
174
+ case 1: return idCaptureWasmApi.runIdCaptureWorkflow(this.pipelineTypeToWasmEnum(type));
175
+ case 2: return idCaptureWasmApi.runIdVideoSelfieWorkflow();
160
176
  case 3:
161
177
  case 4:
162
- case 5: return this.faceProcessingWasmApi.runSelfieWorkflow(this.pipelineTypeToWasmEnum(type));
178
+ case 5: return faceProcessingWasmApi.runSelfieWorkflow(this.pipelineTypeToWasmEnum(type));
163
179
  default: throw new Error("Unknown pipeline type");
164
180
  }
165
181
  }
166
- async runIdCapture(image) {
167
- this.checkWasmInitialization("Unable to run Id Capture, cpp API hasn't been initialized");
168
- if (this.inputImageBuffer === null) throw new Error("Unable to process the image, buffers haven't been allocated!");
169
- this.inputImageBuffer.set(image.data);
170
- return this.idCaptureWasmApi.runIdCapture();
171
- }
172
- async runSelfieCapture(image) {
173
- this.checkWasmInitialization("Unable to run Selfie Capture, cpp API hasn't been initialized");
174
- if (this.inputImageBuffer === null) throw new Error("Unable to process the image, buffers haven't been allocated!");
175
- this.inputImageBuffer.set(image.data);
176
- return this.faceProcessingWasmApi.runSelfieCapture();
177
- }
178
- async setFacePositionConstraints(type, minX, minY, maxX, maxY) {
179
- this.checkWasmInitialization("Unable to set face position constraints, cpp API hasn't been initialized");
180
- this.faceProcessingWasmApi.setFacePositionConstraints(this.pipelineTypeToWasmEnum(type), minX, minY, maxX, maxY);
181
- }
182
- async setFaceDetectionThresholds(type, brightnessThreshold, blurrinessThreshold, tiltRotationAngleThreshold, minMagicCropSize, autocaptureInterval, minFaceQualityScore, faceOcclusionThreshold, getReadyDelay, framesAggregationInterval, minFramesWithFace) {
183
- this.checkWasmInitialization("Unable to set face detection thresholds, cpp API hasn't been initialized");
184
- this.faceProcessingWasmApi.setFaceProcessingThresholds(this.pipelineTypeToWasmEnum(type), brightnessThreshold, blurrinessThreshold, tiltRotationAngleThreshold, minMagicCropSize, autocaptureInterval, minFaceQualityScore, faceOcclusionThreshold, getReadyDelay, framesAggregationInterval, minFramesWithFace);
185
- }
186
- async setFaceAttributesThresholds(type, headwearThreshold, lensesThreshold, closedEyesThreshold, maskThreshold) {
187
- this.checkWasmInitialization("Unable to set face attributes thresholds, cpp API hasn't been initialized");
188
- this.faceProcessingWasmApi.setFaceAttributesThresholds(this.pipelineTypeToWasmEnum(type), headwearThreshold, lensesThreshold, closedEyesThreshold, maskThreshold);
189
- }
190
- async setFaceChecksEnabled(type, isLensesCheckEnabled, isMaskCheckEnabled, isClosedEyesCheckEnabled, isHeadWearCheckEnabled, isOcclusionCheckEnabled) {
191
- this.checkWasmInitialization("Unable to set face checks enabled flags, cpp API hasn't been initialized");
192
- this.faceProcessingWasmApi.setFaceChecksEnabled(this.pipelineTypeToWasmEnum(type), isLensesCheckEnabled, isMaskCheckEnabled, isClosedEyesCheckEnabled, isHeadWearCheckEnabled, isOcclusionCheckEnabled);
193
- }
194
- async setFaceDetectionMode(type, isVideoSelfie) {
195
- this.checkWasmInitialization("Unable to set face detection mode, cpp API hasn't been initialized");
196
- this.faceProcessingWasmApi.setFaceProcessingMode(this.pipelineTypeToWasmEnum(type), isVideoSelfie);
197
- }
198
- async setFaceDetectionCallbacks(type, onFarAway, onTooClose, onTooManyFaces, onNoFace, onCapture, onGetReady, onGetReadyFinished, onCenterFace, onDark, onBlur, onFaceAngle, onLenses, onMask, onEyesClosed, onHeadWear, onSwitchToManualCapture, onFaceOccluded) {
199
- this.checkWasmInitialization("Unable to set face detection callbacks, cpp API hasn't been initialized");
200
- this.faceProcessingWasmApi.setFaceProcessingCallbacks(this.pipelineTypeToWasmEnum(type), onFarAway, onTooClose, onTooManyFaces, onNoFace, onCapture, onGetReady, onGetReadyFinished, onCenterFace, onDark, onBlur, onFaceAngle, onLenses, onMask, onEyesClosed, onHeadWear, onSwitchToManualCapture, onFaceOccluded);
201
- }
202
- async setIdCaptureThresholds(type, blurThreshold, blurChangeThreshold, glareThreshold, clsThreshold, sideThreshold, iouThreshold, idDetectedTimeout, autocaptureTimeout, framesAggregationInterval) {
203
- this.checkWasmInitialization("Unable to set thresholds, cpp API hasn't been initialized");
204
- this.idCaptureWasmApi.setIdCaptureThresholds(this.pipelineTypeToWasmEnum(type), blurThreshold, blurChangeThreshold, glareThreshold, clsThreshold, sideThreshold, iouThreshold, idDetectedTimeout, autocaptureTimeout, framesAggregationInterval);
205
- }
206
- async setIdCaptureCallbacks(type, onFarAway, onDetectionStarted, onMaskChange, onBlur, onGlare, onCapturing, onCapture, onBestFrame, onIDNotDetected, onSwitchToManualCapture, onIDTypeChange, onIDSideChange, onCapturingCounterValueChange) {
207
- this.checkWasmInitialization("Unable to set callbacks, cpp API hasn't been initialized");
208
- this.idCaptureWasmApi.setIdCaptureCallbacks(this.pipelineTypeToWasmEnum(type), onFarAway, onDetectionStarted, onMaskChange, onBlur, onGlare, onCapturing, onCapture, onBestFrame, onIDNotDetected, onSwitchToManualCapture, onIDTypeChange, onIDSideChange, onCapturingCounterValueChange);
209
- }
210
- async setIdCaptureGeometryParams(type, areaDown, areaUp, areaIOSPassportUp, areaIOSPassportDown, widthIOSUp, widthIOSDown, widthDown, widthUp, windowOuterWidth, windowOuterHeight, windowInnerWidth, windowInnerHeight) {
211
- this.checkWasmInitialization("Unable to set geometry params, cpp API hasn't been initialized");
212
- this.idCaptureWasmApi.setIdCaptureGeometryParams(this.pipelineTypeToWasmEnum(type), areaDown, areaUp, areaIOSPassportUp, areaIOSPassportDown, widthIOSUp, widthIOSDown, widthDown, widthUp, windowOuterWidth, windowOuterHeight, windowInnerWidth, windowInnerHeight);
213
- }
214
- async setIdCaptureConfigParams(type, isFixedMask, isIPhone14OrHigher, idType, isBlurCheckEnabled, isGlareCheckEnabled, _isIdFaceQualityCheckEnabled, isIouCheckEnabled, isFPSLimitEnabled) {
215
- this.checkWasmInitialization("Unable to set config params, cpp API hasn't been initialized");
216
- this.idCaptureWasmApi.setIdCaptureConfigParams(this.pipelineTypeToWasmEnum(type), isFixedMask, isIPhone14OrHigher, idType, isBlurCheckEnabled, isGlareCheckEnabled, isIouCheckEnabled, isFPSLimitEnabled);
217
- }
218
- setIdCaptureModelType(pipelineType, modelType) {
219
- this.checkWasmInitialization("Unable to set model type, cpp API hasn't been initialized");
220
- this.idCaptureWasmApi.setIdCaptureModelType(this.pipelineTypeToWasmEnum(pipelineType), this.IdCaptureModelTypeToWasmEnum(modelType));
221
- }
222
- setIdBarcodeCaptureEnabled(pipelineType, enabled) {
223
- this.checkWasmInitialization("Unable to set barcode capture enabled, cpp API hasn't been initialized");
224
- this.idCaptureWasmApi.setIdBarcodeCaptureEnabled(this.pipelineTypeToWasmEnum(pipelineType), enabled);
225
- }
226
- setIdBarcodeAutoCaptureOnDecode(pipelineType, enabled) {
227
- this.checkWasmInitialization("Unable to set barcode auto-capture-on-decode, cpp API hasn't been initialized");
228
- this.idCaptureWasmApi.setIdBarcodeAutoCaptureOnDecode(this.pipelineTypeToWasmEnum(pipelineType), enabled);
229
- }
230
- setIdBarcodeDecodedCallback(pipelineType, onBarcodeDecoded) {
231
- this.checkWasmInitialization("Unable to set barcode decoded callback, cpp API hasn't been initialized");
232
- this.idCaptureWasmApi.setIdBarcodeDecodedCallback(this.pipelineTypeToWasmEnum(pipelineType), onBarcodeDecoded);
233
- }
234
- async setIdBarcodeEnhancementModel(pipelineType, modelPath) {
235
- this.checkWasmInitialization("Unable to set barcode enhancement model, cpp API hasn't been initialized");
236
- const buffer = await resolveWasmSource(modelPath, "barcode model");
237
- return this.idCaptureWasmApi.setBarcodeEnhancementModel(this.pipelineTypeToWasmEnum(pipelineType), buffer);
238
- }
239
- IdPerspectiveTransform(image, frameRect) {
240
- this.checkWasmInitialization("Unable to perform perspective transform, cpp API hasn't been initialized");
241
- return this.idCaptureWasmApi.IdPerspectiveTransform(image, frameRect);
242
- }
243
- async getVersions() {
244
- const text = await (await fetch(this.versionsFile)).text();
245
- return JSON.parse(text);
246
- }
247
182
  async loadModels() {
248
- this.checkWasmInitialization("Unable load the models, cpp API hasn't been initialized");
249
- const buffSizes = new this.wasmModule.WorkflowTypeToIntMap();
183
+ const message = "Unable load the models, cpp API hasn't been initialized";
184
+ const buffSizes = new (this.requireWasmModule(message)).WorkflowTypeToIntMap();
250
185
  const modelData = /* @__PURE__ */ new Map();
251
186
  const loadedModels = /* @__PURE__ */ new Map();
252
- for (const [type, modelsPaths] of this.pipelines_) {
187
+ const sizeVectors = [];
188
+ const pipelines = this.pipelines_;
189
+ if (pipelines === null) throw new Error(message);
190
+ for (const [type, modelsPaths] of pipelines) {
253
191
  const wasmType = this.pipelineTypeToWasmEnum(type);
254
192
  const pipelineBuffers = [];
255
- const sizes = new this.wasmModule.VectorInt();
193
+ const sizes = new (this.requireWasmModule(message)).VectorInt();
194
+ sizeVectors.push(sizes);
256
195
  for (const path of modelsPaths) {
257
- if (!loadedModels.has(path)) {
258
- const model = await resolveWasmSource(path, "model");
196
+ let model = loadedModels.get(path);
197
+ if (!model) {
198
+ model = await resolveWasmSource(path, "model");
259
199
  loadedModels.set(path, model);
260
200
  }
261
- const model = loadedModels.get(path);
262
201
  sizes.push_back(model.byteLength);
263
202
  pipelineBuffers.push(model);
264
203
  }
265
204
  buffSizes.set(wasmType, sizes);
266
205
  modelData.set(wasmType, pipelineBuffers);
267
206
  }
268
- this.modelsBuffers = this.workflowApiUtilities.allocateModelsBuffers(buffSizes);
207
+ const modelsBuffers = this.requireWorkflowApiUtilities(message).allocateModelsBuffers(buffSizes);
208
+ for (const sizes of sizeVectors) sizes.delete?.();
209
+ buffSizes.delete?.();
210
+ this.modelsBuffers = modelsBuffers;
269
211
  for (const [type, data] of modelData) {
270
- const buffers = this.modelsBuffers?.get(type);
212
+ const buffers = modelsBuffers.get(type);
213
+ if (!buffers) throw new Error("Unable to get model buffer from shared memory!");
271
214
  for (let k = 0; k < buffers.size(); k++) {
272
- const buffer = buffers?.get(k);
215
+ const buffer = buffers.get(k);
273
216
  if (buffer) buffer.set(data[k]);
274
217
  else throw new Error("Unable to get model buffer from shared memory!");
275
218
  }
276
219
  }
277
220
  }
278
221
  async initializePipelines() {
279
- this.checkWasmInitialization("Unable to initialize pipelines, cpp API hasn't been initialized");
222
+ const message = "Unable to initialize pipelines, cpp API hasn't been initialized";
223
+ this.requireWorkflowApiUtilities(message);
280
224
  if (!this.modelsBuffers) await this.loadModels();
281
- this.workflowApiUtilities.initializeWorkflows();
282
- }
283
- /**
284
- * Sets the native (C++) utility API's production mode. When `true`, the WASM
285
- * module suppresses its verbose debug logging; when `false`, it emits it.
286
- *
287
- * @param productionMode - `true` to silence WASM logs, `false` to emit them.
288
- * @throws If the WASM C++ API has not been initialized yet.
289
- */
290
- async setProductionMode(productionMode) {
291
- this.checkWasmInitialization("Unable to set production mode, cpp API hasn't been initialized");
292
- this.utilityApi.setProductionMode(productionMode);
225
+ this.requireWorkflowApiUtilities(message).initializeWorkflows();
293
226
  }
294
227
  getPipelineState() {
295
- this.checkWasmInitialization("Unable to get pipeline state, cpp API hasn't been initialized");
296
- return this.workflowApiUtilities.getWorkflowState();
228
+ return this.requireWorkflowApiUtilities("Unable to get pipeline state, cpp API hasn't been initialized").getWorkflowState();
297
229
  }
298
230
  getCurrentPipeline() {
299
- this.checkWasmInitialization("Unable to get current pipeline, cpp API hasn't been initialized");
300
- return this.pipelineTypeFromWasmEnum(this.workflowApiUtilities.getCurrentWorkflow());
301
- }
302
- setSdkVersion(sdkVersion) {
303
- this.checkWasmInitialization("Unable to set sdk version, cpp API hasn't been initialized");
304
- this.utilityApi.setSdkVersion(sdkVersion);
305
- }
306
- setSdkPlatform(sdkPlatform) {
307
- this.checkWasmInitialization("Unable to set device type, cpp API hasn't been initialized");
308
- this.utilityApi.setSdkPlatform(sdkPlatform);
309
- }
310
- setDeviceInfo(deviceInfo, overrideExisting = true) {
311
- this.checkWasmInitialization("Unable to set device info, cpp API hasn't been initialized");
312
- this.utilityApi.setDeviceInfo(deviceInfo, overrideExisting);
313
- }
314
- setBrowserInfo(browserInfo, overrideExisting = true) {
315
- this.checkWasmInitialization("Unable to set browser info, cpp API hasn't been initialized");
316
- this.utilityApi.setBrowserInfo(browserInfo, overrideExisting);
317
- }
318
- setCameraInfo(cameraInfo, overrideExisting = true) {
319
- this.checkWasmInitialization("Unable to set camera info, cpp API hasn't been initialized");
320
- this.utilityApi.setCameraInfo(cameraInfo, overrideExisting);
321
- }
322
- setZc(zc) {
323
- this.checkWasmInitialization("Unable to set zc, cpp API hasn't been initialized");
324
- this.utilityApi.setZc(zc);
325
- }
326
- setMotionStatus(motionStatus) {
327
- this.checkWasmInitialization("Unable to set motion status, cpp API hasn't been initialized");
328
- this.utilityApi.setMotionStatus(motionStatus);
329
- }
330
- setMetadataField(key, value) {
331
- this.checkWasmInitialization("Unable to set metadata field, cpp API hasn't been initialized");
332
- this.utilityApi.setMetadataField(key, value);
333
- }
334
- setInspectorOpened(inspectorOpened) {
335
- this.inspectorOpened_ = inspectorOpened;
336
- }
337
- getInspectorOpened() {
338
- return this.inspectorOpened_;
339
- }
340
- setBackgroundMode(backgroundMode) {
341
- this.checkWasmInitialization("Unable to set background mode, cpp API hasn't been initialized");
342
- this.utilityApi.setBackgroundMode(backgroundMode);
231
+ const workflowApiUtilities = this.requireWorkflowApiUtilities("Unable to get current pipeline, cpp API hasn't been initialized");
232
+ return this.pipelineTypeFromWasmEnum(workflowApiUtilities.getCurrentWorkflow());
343
233
  }
344
234
  setOnDeviceMode(enabled) {
345
235
  this.onDeviceMode_ = enabled;
346
236
  if (this.utilityApi != null) this.utilityApi.setOnDeviceMode(enabled);
347
237
  }
348
- setDsEnabled(enabled) {
349
- this.dsEnabled_ = enabled;
350
- }
351
- getCheck() {
352
- this.checkWasmInitialization("Unable to get check, cpp API hasn't been initialized");
353
- return this.utilityApi.getCheck();
354
- }
355
- getMetadata() {
356
- this.checkWasmInitialization("Unable to get metadata, cpp API hasn't been initialized");
357
- this.utilityApi.setInspectorOpened(this.inspectorOpened_);
358
- return this.utilityApi.getMetadata();
359
- }
360
- async prc() {
361
- this.checkWasmInitialization("Unable to prc, cpp API hasn't been initialized");
362
- await wasmCallWrapper(this.wasmCallSemaphore, () => this.utilityApi.prc(this.dsEnabled_, false), true);
363
- }
364
- async poc(output) {
365
- this.checkWasmInitialization("Unable to poc, cpp API hasn't been initialized");
366
- await wasmCallWrapper(this.wasmCallSemaphore, () => this.utilityApi.poc(this.dsEnabled_, output), true);
367
- }
368
- async rsp() {
369
- this.checkWasmInitialization("Unable to rsp, cpp API hasn't been initialized");
370
- await wasmCallWrapper(this.wasmCallSemaphore, () => this.utilityApi.rsp(this.dsEnabled_), true);
371
- }
372
- ssl() {
373
- this.checkWasmInitialization("Unable to ssl, cpp API hasn't been initialized");
374
- this.utilityApi.ssl(this.dsEnabled_);
375
- }
376
- stl() {
377
- this.checkWasmInitialization("Unable to stl, cpp API hasn't been initialized");
378
- this.utilityApi.stl();
379
- }
380
- osv() {
381
- this.checkWasmInitialization("Unable to set sensor beginning timestamp, cpp API hasn't been initialized");
382
- this.utilityApi.osv();
238
+ pipelineTypeToWasmEnum(type) {
239
+ return pipelineTypeToWasmEnum(this.requireWasmModule(WasmRuntime.UNINITIALIZED_ENUM_MAP_MESSAGE), type);
383
240
  }
384
- oev() {
385
- this.checkWasmInitialization("Unable to set sensor ending timestamp, cpp API hasn't been initialized");
386
- this.utilityApi.oev();
241
+ pipelineTypeFromWasmEnum(type) {
242
+ return pipelineTypeFromWasmEnum(this.requireWasmModule(WasmRuntime.UNINITIALIZED_ENUM_MAP_MESSAGE), type);
387
243
  }
388
- ckvcks(data) {
389
- this.checkWasmInitialization("Unable to ckvcks, cpp API hasn't been initialized");
390
- this.utilityApi.ckvcks(data);
244
+ IdCaptureModelTypeToWasmEnum(type) {
245
+ return idCaptureModelTypeToWasmEnum(this.requireWasmModule(WasmRuntime.UNINITIALIZED_ENUM_MAP_MESSAGE), type);
391
246
  }
392
247
  /**
393
- * Synchronous manual-capture entry point for the OnDevice selfie workflow.
394
- * Runs face detection + the full on-device quality / liveness / age pipeline
395
- * on a single canvas image and stages the results inside the WASM `WebApi`
396
- * for the next {@link postFaceResults} call. No polling, no semaphore wrap.
397
- *
398
- * Mirrors `ml-wasm-kit/WasmApi.processPhoto`.
248
+ * Kept as an upstream mirror (`src/web/wasmApi.ts` declares the reverse map)
249
+ * but has no callers, so it stays **private** and off {@link WasmRuntimeApi}:
250
+ * dead code must not become public surface.
399
251
  */
400
- processPhoto(canvas) {
401
- this.checkWasmInitialization("Unable to process photo, cpp API hasn't been initialized");
402
- this.faceProcessingWasmApi.processPhoto(canvas);
252
+ IdCaptureModelTypeFromWasmEnum(type) {
253
+ return idCaptureModelTypeFromWasmEnum(this.requireWasmModule(WasmRuntime.UNINITIALIZED_ENUM_MAP_MESSAGE), type);
403
254
  }
404
255
  /**
405
- * POSTs the staged on-device face-results JSON to `/omni/add/face-results`
406
- * via the C++ `WebApi`. The C++ side encrypts the body with
407
- * `SessionEncryptor` and routes through the WASM `WebClient` with inline
408
- * encryption (`ie=true`) — this does NOT depend on the WebClient E2EE
409
- * session setup, so it works whether `setupWasmConnection` was called with
410
- * `encryptionEnabled` true or false.
256
+ * Handle accessors. Each throws the caller's message when the C++ API is not
257
+ * initialized and otherwise returns the non-null handle, so every wrapper gets
258
+ * a narrowed handle without repeating a null check. The message is the
259
+ * caller's, not this class's, so the wrapper's own pre-init contract is
260
+ * preserved verbatim.
411
261
  *
412
- * Reads from the `WebApi` instance constructed in {@link initialize}. The
413
- * C++ `OnDeviceSelfieWorkflow` has already staged the aggregated best-shot
414
- * results into that instance via `WebApi::setFaceResults(...)` during
415
- * per-frame processing (auto-capture) or via {@link processPhoto}
416
- * (manual-capture).
262
+ * `isInitialized()` checks the four ML handles plus `isInitialized_`; it does
263
+ * not check `wasmModule` or `webApi`. Both are set in `initialize()` and
264
+ * cleared in `freeResources()`, i.e. they share the exact lifetime of the four
265
+ * checked handles, so the extra `=== null` clause is unreachable in practice —
266
+ * it turns a would-be `TypeError` into the same `Error(message)` in a state
267
+ * that cannot occur. `!this.isInitialized()` is tested first so the observable
268
+ * message never changes.
417
269
  */
418
- postFaceResults(config) {
419
- this.checkWasmInitialization("Unable to post face results, cpp API hasn't been initialized");
420
- return this.webApi.postFaceResults(config ?? {});
270
+ requireWorkflowApiUtilities(message) {
271
+ if (!this.isInitialized() || this.workflowApiUtilities === null) throw new Error(message);
272
+ return this.workflowApiUtilities;
421
273
  }
422
- pipelineTypeToWasmEnum(type) {
423
- switch (type) {
424
- case 0: return this.wasmModule.WorkflowType.IdBlurGlareWorkflow;
425
- case 1: return this.wasmModule.WorkflowType.IdBarcodeAndTextQualityWorkflow;
426
- case 2: return this.wasmModule.WorkflowType.IdVideoSelfieWorkflow;
427
- case 3: return this.wasmModule.WorkflowType.SelfieWithAggregationMetrics;
428
- case 4: return this.wasmModule.WorkflowType.SelfieWithQualityMetrics;
429
- case 5: return this.wasmModule.WorkflowType.OnDeviceSelfieWorkflow;
430
- default: throw new Error("Unknown pipeline type");
431
- }
274
+ requireUtilityApi(message) {
275
+ if (!this.isInitialized() || this.utilityApi === null) throw new Error(message);
276
+ return this.utilityApi;
432
277
  }
433
- pipelineTypeFromWasmEnum(type) {
434
- switch (type) {
435
- case this.wasmModule.WorkflowType.IdBlurGlareWorkflow: return 0;
436
- case this.wasmModule.WorkflowType.IdBarcodeAndTextQualityWorkflow: return 1;
437
- case this.wasmModule.WorkflowType.IdVideoSelfieWorkflow: return 2;
438
- case this.wasmModule.WorkflowType.SelfieWithAggregationMetrics: return 3;
439
- case this.wasmModule.WorkflowType.SelfieWithQualityMetrics: return 4;
440
- case this.wasmModule.WorkflowType.OnDeviceSelfieWorkflow: return 5;
441
- default: throw new Error("Unknown pipeline type");
442
- }
278
+ requireIdCaptureApi(message) {
279
+ if (!this.isInitialized() || this.idCaptureWasmApi === null) throw new Error(message);
280
+ return this.idCaptureWasmApi;
443
281
  }
444
- IdCaptureModelTypeToWasmEnum(type) {
445
- switch (type) {
446
- case 0: return this.wasmModule.IdCaptureModelType.IdCaptureV1x;
447
- case 1: return this.wasmModule.IdCaptureModelType.IdCaptureV2x;
448
- case 2: return this.wasmModule.IdCaptureModelType.IdCaptureV3x;
449
- default: throw new Error("Unknown Id Capture model type");
450
- }
282
+ requireFaceProcessingApi(message) {
283
+ if (!this.isInitialized() || this.faceProcessingWasmApi === null) throw new Error(message);
284
+ return this.faceProcessingWasmApi;
451
285
  }
452
- IdCaptureModelTypeFromWasmEnum(type) {
453
- switch (type) {
454
- case this.wasmModule.IdCaptureModelType.IdCaptureV1x: return 0;
455
- case this.wasmModule.IdCaptureModelType.IdCaptureV2x: return 1;
456
- case this.wasmModule.IdCaptureModelType.IdCaptureV3x: return 2;
457
- default: throw new Error("Unknown Id Capture model type");
458
- }
286
+ requireWasmModule(message) {
287
+ if (!this.isInitialized() || this.wasmModule === null) throw new Error(message);
288
+ return this.wasmModule;
459
289
  }
460
- checkWasmInitialization(message) {
461
- if (!this.isInitialized()) throw new Error(message);
290
+ requireWebApi(message) {
291
+ if (!this.isInitialized() || this.webApi === null) throw new Error(message);
292
+ return this.webApi;
462
293
  }
463
- }.getInstance();
294
+ };
295
+ WasmRuntime.UNINITIALIZED_ENUM_MAP_MESSAGE = "Unable to map pipeline type, cpp API hasn't been initialized";
296
+ /** Process-wide runtime. One binary, one heap, one owner. */
297
+ const wasmRuntime = new WasmRuntime();
464
298
  //#endregion
465
299
  //#region ../infra/src/wasm/warmup.ts
466
300
  /**
@@ -586,13 +420,12 @@ async function warmupWasm(config) {
586
420
  loadingPromise = (async () => {
587
421
  try {
588
422
  const pipelinesMap = buildPipelinesMap(combinedPipelines, lastConfig);
589
- await mlWasmJSApi_default.initialize({
423
+ await wasmRuntime.initialize({
590
424
  module: lastConfig,
591
- versionsFile: "",
592
425
  pipelines: pipelinesMap
593
426
  });
594
- await mlWasmJSApi_default.loadModels();
595
- await mlWasmJSApi_default.initializePipelines();
427
+ await wasmRuntime.loadModels();
428
+ await wasmRuntime.initializePipelines();
596
429
  state = "ready";
597
430
  loadedPipelines = combinedPipelines;
598
431
  lastConfig = {
@@ -616,14 +449,13 @@ async function warmupWasm(config) {
616
449
  loadingPromise = (async () => {
617
450
  try {
618
451
  const pipelinesMap = buildPipelinesMap(pipelines, config);
619
- if (config.onDeviceMode !== void 0) mlWasmJSApi_default.setOnDeviceMode(config.onDeviceMode);
620
- await mlWasmJSApi_default.initialize({
452
+ if (config.onDeviceMode !== void 0) wasmRuntime.setOnDeviceMode(config.onDeviceMode);
453
+ await wasmRuntime.initialize({
621
454
  module: config,
622
- versionsFile: "",
623
455
  pipelines: pipelinesMap
624
456
  });
625
- await mlWasmJSApi_default.loadModels();
626
- await mlWasmJSApi_default.initializePipelines();
457
+ await wasmRuntime.loadModels();
458
+ await wasmRuntime.initializePipelines();
627
459
  state = "ready";
628
460
  loadedPipelines = [...pipelines];
629
461
  lastConfig = {
@@ -679,15 +511,172 @@ function waitForWasm() {
679
511
  return Promise.reject(/* @__PURE__ */ new Error("WASM warmup was not started. Call warmupWasm() first."));
680
512
  }
681
513
  /**
682
- * Sets WASM on-device mode on the shared WASM singleton. Applied on the next
514
+ * Sets WASM on-device mode on the shared `wasmRuntime`. Applied on the next
683
515
  * `initialize()` (via warmupWasm), or live if WASM is already initialized.
684
516
  * Used by setup() to derive on-device mode from the `fingerprint` option so
685
517
  * the intent is honored even by lazy warmups whose config does not carry it.
686
518
  */
687
519
  function setWasmOnDeviceMode(enabled) {
688
- mlWasmJSApi_default.setOnDeviceMode(enabled);
520
+ wasmRuntime.setOnDeviceMode(enabled);
689
521
  }
690
522
  //#endregion
523
+ //#region ../infra/src/wasm/utilityWasmApi.ts
524
+ /**
525
+ * Utility / metadata domain facade over {@link WasmRuntime}.
526
+ *
527
+ * Holds no WASM state — the runtime owns every handle and buffer. The one
528
+ * qualification: it owns exactly two JS-side flags that the C++ side does not
529
+ * persist and that must be replayed into it at call time —
530
+ *
531
+ * - `dsEnabled_` (deepsight) is passed as an argument on every
532
+ * `prc`/`poc`/`rsp`/`ssl` call;
533
+ * - `inspectorOpened_` is pushed into C++ inside {@link getMetadata}, right
534
+ * before reading the metadata, because `setInspectorOpened` may legitimately be
535
+ * called before WASM is initialized.
536
+ *
537
+ * Both are deliberately **unguarded** setters: they never throw, so the SDK can
538
+ * record them during setup and have them honored once WASM comes up.
539
+ *
540
+ * `prc`/`poc`/`rsp` are the only methods here that hold the ML semaphore.
541
+ * `ssl`/`stl`/`osv`/`oev`/`ckvcks` and everything else are unlocked **by design**
542
+ * (decision D6) — never add locking.
543
+ *
544
+ * Method names, argument order and the pre-initialization error strings are
545
+ * copied verbatim from the mirrored upstream `wasmApi.ts` so a WASM version bump
546
+ * stays a diff against upstream (`docs/processes/WASM_VERSION_MIGRATION.md`).
547
+ * `setSdkPlatform`'s message says "device type" on purpose — do not "fix" it.
548
+ */
549
+ var UtilityWasmApi = class {
550
+ constructor(runtime = wasmRuntime) {
551
+ this.runtime = runtime;
552
+ this.inspectorOpened_ = false;
553
+ this.dsEnabled_ = false;
554
+ }
555
+ ens(image) {
556
+ return this.runtime.requireUtilityApi("Unable to encrypt the image, cpp API hasn't been initialized").ens(image);
557
+ }
558
+ isVirtualCamera(label) {
559
+ const utilityApi = this.runtime.requireUtilityApi("Unable to check if the camera is virtual, cpp API hasn't been initialized");
560
+ if (label) return utilityApi.isVirtualCamera(label);
561
+ return false;
562
+ }
563
+ estimatePerformance() {
564
+ return this.runtime.requireUtilityApi("Unable to estimate performance, cpp API hasn't been initialized").estimatePerformance();
565
+ }
566
+ async analyzeFrame(image) {
567
+ const message = "Unable to analyze the frame, cpp API hasn't been initialized";
568
+ this.runtime.requireUtilityApi(message);
569
+ await this.runtime.allocateImageBuffers(image.width, image.height);
570
+ this.runtime.writeFrame(image);
571
+ this.runtime.requireUtilityApi(message).analyzeFrame();
572
+ }
573
+ /**
574
+ * Sets the native (C++) utility API's production mode. When `true`, the WASM
575
+ * module suppresses its verbose debug logging; when `false`, it emits it.
576
+ *
577
+ * @param productionMode - `true` to silence WASM logs, `false` to emit them.
578
+ * @throws If the WASM C++ API has not been initialized yet.
579
+ */
580
+ async setProductionMode(productionMode) {
581
+ this.runtime.requireUtilityApi("Unable to set production mode, cpp API hasn't been initialized").setProductionMode(productionMode);
582
+ }
583
+ setSdkVersion(sdkVersion) {
584
+ this.runtime.requireUtilityApi("Unable to set sdk version, cpp API hasn't been initialized").setSdkVersion(sdkVersion);
585
+ }
586
+ setSdkPlatform(sdkPlatform) {
587
+ this.runtime.requireUtilityApi("Unable to set device type, cpp API hasn't been initialized").setSdkPlatform(sdkPlatform);
588
+ }
589
+ setDeviceInfo(deviceInfo, overrideExisting = true) {
590
+ this.runtime.requireUtilityApi("Unable to set device info, cpp API hasn't been initialized").setDeviceInfo(deviceInfo, overrideExisting);
591
+ }
592
+ setBrowserInfo(browserInfo, overrideExisting = true) {
593
+ this.runtime.requireUtilityApi("Unable to set browser info, cpp API hasn't been initialized").setBrowserInfo(browserInfo, overrideExisting);
594
+ }
595
+ setCameraInfo(cameraInfo, overrideExisting = true) {
596
+ this.runtime.requireUtilityApi("Unable to set camera info, cpp API hasn't been initialized").setCameraInfo(cameraInfo, overrideExisting);
597
+ }
598
+ setZc(zc) {
599
+ this.runtime.requireUtilityApi("Unable to set zc, cpp API hasn't been initialized").setZc(zc);
600
+ }
601
+ setMotionStatus(motionStatus) {
602
+ this.runtime.requireUtilityApi("Unable to set motion status, cpp API hasn't been initialized").setMotionStatus(motionStatus);
603
+ }
604
+ setInspectorOpened(inspectorOpened) {
605
+ this.inspectorOpened_ = inspectorOpened;
606
+ }
607
+ getInspectorOpened() {
608
+ return this.inspectorOpened_;
609
+ }
610
+ setBackgroundMode(backgroundMode) {
611
+ this.runtime.requireUtilityApi("Unable to set background mode, cpp API hasn't been initialized").setBackgroundMode(backgroundMode);
612
+ }
613
+ setDsEnabled(enabled) {
614
+ this.dsEnabled_ = enabled;
615
+ }
616
+ getCheck() {
617
+ return this.runtime.requireUtilityApi("Unable to get check, cpp API hasn't been initialized").getCheck();
618
+ }
619
+ getMetadata() {
620
+ const utilityApi = this.runtime.requireUtilityApi("Unable to get metadata, cpp API hasn't been initialized");
621
+ utilityApi.setInspectorOpened(this.inspectorOpened_);
622
+ return utilityApi.getMetadata();
623
+ }
624
+ async prc() {
625
+ const message = "Unable to prc, cpp API hasn't been initialized";
626
+ this.runtime.requireUtilityApi(message);
627
+ await wasmCallWrapper(this.runtime.mlCallSemaphore, () => this.runtime.requireUtilityApi(message).prc(this.dsEnabled_, false), true, {
628
+ maxPolls: ML_CALL_MAX_POLLS,
629
+ label: "prc"
630
+ });
631
+ }
632
+ async poc(output) {
633
+ const message = "Unable to poc, cpp API hasn't been initialized";
634
+ this.runtime.requireUtilityApi(message);
635
+ await wasmCallWrapper(this.runtime.mlCallSemaphore, () => this.runtime.requireUtilityApi(message).poc(this.dsEnabled_, output), true, {
636
+ maxPolls: ML_CALL_MAX_POLLS,
637
+ label: "poc"
638
+ });
639
+ }
640
+ async rsp() {
641
+ const message = "Unable to rsp, cpp API hasn't been initialized";
642
+ this.runtime.requireUtilityApi(message);
643
+ await wasmCallWrapper(this.runtime.mlCallSemaphore, () => this.runtime.requireUtilityApi(message).rsp(this.dsEnabled_), true, {
644
+ maxPolls: ML_CALL_MAX_POLLS,
645
+ label: "rsp"
646
+ });
647
+ }
648
+ ssl() {
649
+ this.runtime.requireUtilityApi("Unable to ssl, cpp API hasn't been initialized").ssl(this.dsEnabled_);
650
+ }
651
+ stl() {
652
+ this.runtime.requireUtilityApi("Unable to stl, cpp API hasn't been initialized").stl();
653
+ }
654
+ osv() {
655
+ this.runtime.requireUtilityApi("Unable to set sensor beginning timestamp, cpp API hasn't been initialized").osv();
656
+ }
657
+ oev() {
658
+ this.runtime.requireUtilityApi("Unable to set sensor ending timestamp, cpp API hasn't been initialized").oev();
659
+ }
660
+ ckvcks(data) {
661
+ this.runtime.requireUtilityApi("Unable to ckvcks, cpp API hasn't been initialized").ckvcks(data);
662
+ }
663
+ /**
664
+ * Clear all states, not related to ml pipelines
665
+ */
666
+ resetOther() {
667
+ this.runtime.requireUtilityApi("Unable to reset other states, cpp API hasn't been initialized").resetOther();
668
+ }
669
+ /**
670
+ * Full reset. Pipelines first, then the non-pipeline state — the order the
671
+ * mirrored upstream wrapper uses.
672
+ */
673
+ reset() {
674
+ this.runtime.resetAllPipelines();
675
+ this.resetOther();
676
+ }
677
+ };
678
+ const utilityWasmApi = new UtilityWasmApi();
679
+ //#endregion
691
680
  //#region ../infra/src/providers/wasm/BaseWasmProvider.ts
692
681
  /**
693
682
  * Base provider class that abstracts common WASM functionality.
@@ -748,16 +737,16 @@ var BaseWasmProvider = class {
748
737
  async processFrameWasm(image) {
749
738
  this.ensureInitialized();
750
739
  const pipelineType = this.getPipelineType();
751
- await mlWasmJSApi_default.allocateImageBuffers(image.width, image.height);
752
- await mlWasmJSApi_default.handleDetectionCallAndUpdateState(pipelineType);
753
- return await mlWasmJSApi_default.process(image, pipelineType);
740
+ await wasmRuntime.allocateImageBuffers(image.width, image.height);
741
+ await wasmRuntime.handleDetectionCallAndUpdateState(pipelineType);
742
+ return await wasmRuntime.process(image, pipelineType);
754
743
  }
755
744
  /**
756
745
  * Resets the pipeline to its initial state.
757
746
  * Safe to call even if not initialized (no-op in that case).
758
747
  */
759
748
  reset() {
760
- if (this._isInitialized && this.pipelineType !== void 0) mlWasmJSApi_default.resetPipeline(this.pipelineType);
749
+ if (this._isInitialized && this.pipelineType !== void 0) wasmRuntime.resetPipeline(this.pipelineType);
761
750
  }
762
751
  /**
763
752
  * Disposes of resources and resets initialization state.
@@ -799,50 +788,50 @@ var WasmUtilProvider = class WasmUtilProvider extends BaseWasmProvider {
799
788
  }
800
789
  encryptImage(image) {
801
790
  this.ensureInitialized();
802
- return mlWasmJSApi_default.ens(image);
791
+ return utilityWasmApi.ens(image);
803
792
  }
804
793
  setSdkVersion(version) {
805
794
  this.ensureInitialized();
806
- mlWasmJSApi_default.setSdkVersion(version);
795
+ utilityWasmApi.setSdkVersion(version);
807
796
  }
808
797
  setSdkPlatform(platform) {
809
798
  this.ensureInitialized();
810
- mlWasmJSApi_default.setSdkPlatform(platform);
799
+ utilityWasmApi.setSdkPlatform(platform);
811
800
  }
812
801
  setDeviceInfo(deviceInfo, overrideExisting = true) {
813
802
  this.ensureInitialized();
814
- mlWasmJSApi_default.setDeviceInfo(deviceInfo, overrideExisting);
803
+ utilityWasmApi.setDeviceInfo(deviceInfo, overrideExisting);
815
804
  }
816
805
  setBrowserInfo(browserInfo, overrideExisting = true) {
817
806
  this.ensureInitialized();
818
- mlWasmJSApi_default.setBrowserInfo(browserInfo, overrideExisting);
807
+ utilityWasmApi.setBrowserInfo(browserInfo, overrideExisting);
819
808
  }
820
809
  setCameraInfo(cameraInfo, overrideExisting = true) {
821
810
  this.ensureInitialized();
822
- mlWasmJSApi_default.setCameraInfo(cameraInfo, overrideExisting);
811
+ utilityWasmApi.setCameraInfo(cameraInfo, overrideExisting);
823
812
  }
824
813
  setMotionStatus(status) {
825
814
  this.ensureInitialized();
826
- mlWasmJSApi_default.setMotionStatus(status);
815
+ utilityWasmApi.setMotionStatus(status);
827
816
  }
828
817
  setBackgroundMode(backgroundMode) {
829
818
  this.ensureInitialized();
830
- mlWasmJSApi_default.setBackgroundMode(backgroundMode);
819
+ utilityWasmApi.setBackgroundMode(backgroundMode);
831
820
  }
832
821
  setOnDeviceMode(enabled) {
833
822
  this.ensureInitialized();
834
- mlWasmJSApi_default.setOnDeviceMode(enabled);
823
+ wasmRuntime.setOnDeviceMode(enabled);
835
824
  }
836
825
  setZc(zc) {
837
826
  this.ensureInitialized();
838
- mlWasmJSApi_default.setZc(zc);
827
+ utilityWasmApi.setZc(zc);
839
828
  }
840
829
  setInspectorOpened(opened) {
841
830
  this.ensureInitialized();
842
- mlWasmJSApi_default.setInspectorOpened(opened);
831
+ utilityWasmApi.setInspectorOpened(opened);
843
832
  }
844
833
  getInspectorOpened() {
845
- return mlWasmJSApi_default.getInspectorOpened();
834
+ return utilityWasmApi.getInspectorOpened();
846
835
  }
847
836
  /**
848
837
  * Toggles the WASM module's production mode. When `true`, the native module
@@ -854,67 +843,63 @@ var WasmUtilProvider = class WasmUtilProvider extends BaseWasmProvider {
854
843
  */
855
844
  async setProductionMode(productionMode) {
856
845
  this.ensureInitialized();
857
- await mlWasmJSApi_default.setProductionMode(productionMode);
846
+ await utilityWasmApi.setProductionMode(productionMode);
858
847
  }
859
848
  getMetadata() {
860
849
  this.ensureInitialized();
861
- return mlWasmJSApi_default.getMetadata();
850
+ return utilityWasmApi.getMetadata();
862
851
  }
863
852
  async analyzeFrame(image) {
864
853
  this.ensureInitialized();
865
- await mlWasmJSApi_default.analyzeFrame(image);
854
+ await utilityWasmApi.analyzeFrame(image);
866
855
  }
867
856
  getCheck() {
868
857
  this.ensureInitialized();
869
- return mlWasmJSApi_default.getCheck();
858
+ return utilityWasmApi.getCheck();
870
859
  }
871
860
  getPipelineState() {
872
861
  this.ensureInitialized();
873
- return mlWasmJSApi_default.getPipelineState();
862
+ return wasmRuntime.getPipelineState();
874
863
  }
875
864
  estimatePerformance() {
876
865
  this.ensureInitialized();
877
- return mlWasmJSApi_default.estimatePerformance();
866
+ return utilityWasmApi.estimatePerformance();
878
867
  }
879
868
  isVirtualCamera(label) {
880
869
  this.ensureInitialized();
881
- return mlWasmJSApi_default.isVirtualCamera(label);
870
+ return utilityWasmApi.isVirtualCamera(label);
882
871
  }
883
872
  async prc() {
884
873
  this.ensureInitialized();
885
- await mlWasmJSApi_default.prc();
874
+ await utilityWasmApi.prc();
886
875
  }
887
876
  async poc(output) {
888
877
  this.ensureInitialized();
889
- await mlWasmJSApi_default.poc(output);
878
+ await utilityWasmApi.poc(output);
890
879
  }
891
880
  async rsp() {
892
881
  this.ensureInitialized();
893
- await mlWasmJSApi_default.rsp();
882
+ await utilityWasmApi.rsp();
894
883
  }
895
884
  ssl() {
896
885
  this.ensureInitialized();
897
- mlWasmJSApi_default.ssl();
886
+ utilityWasmApi.ssl();
898
887
  }
899
888
  stl() {
900
889
  this.ensureInitialized();
901
- mlWasmJSApi_default.stl();
890
+ utilityWasmApi.stl();
902
891
  }
903
892
  osv() {
904
893
  this.ensureInitialized();
905
- mlWasmJSApi_default.osv();
894
+ utilityWasmApi.osv();
906
895
  }
907
896
  oev() {
908
897
  this.ensureInitialized();
909
- mlWasmJSApi_default.oev();
898
+ utilityWasmApi.oev();
910
899
  }
911
900
  ckvcks(data) {
912
901
  this.ensureInitialized();
913
- mlWasmJSApi_default.ckvcks(data);
914
- }
915
- async getVersions() {
916
- this.ensureInitialized();
917
- return mlWasmJSApi_default.getVersions();
902
+ utilityWasmApi.ckvcks(data);
918
903
  }
919
904
  };
920
905
  //#endregion
@@ -952,4 +937,4 @@ function resolveSessionStorage() {
952
937
  }
953
938
  }
954
939
  //#endregion
955
- export { getResolvedModelSource as a, mlWasmJSApi_default as c, BaseWasmProvider as i, resolveSessionStorage as n, setWasmOnDeviceMode as o, WasmUtilProvider as r, warmupWasm as s, resolveLocalStorage as t };
940
+ export { utilityWasmApi as a, warmupWasm as c, BaseWasmProvider as i, wasmRuntime as l, resolveSessionStorage as n, getResolvedModelSource as o, WasmUtilProvider as r, setWasmOnDeviceMode as s, resolveLocalStorage as t };