@runanywhere/web 0.1.0-beta.1 → 0.1.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -34
- package/dist/Foundation/ErrorTypes.js +7 -0
- package/dist/Foundation/ErrorTypes.js.map +1 -1
- package/dist/Foundation/EventBus.js.map +1 -1
- package/dist/Foundation/StructOffsets.js +6 -156
- package/dist/Foundation/StructOffsets.js.map +1 -1
- package/dist/Foundation/WASMBridge.js +7 -388
- package/dist/Foundation/WASMBridge.js.map +1 -1
- package/dist/Infrastructure/AudioFileLoader.js +57 -0
- package/dist/Infrastructure/AudioFileLoader.js.map +1 -0
- package/dist/Infrastructure/DeviceCapabilities.js +8 -3
- package/dist/Infrastructure/DeviceCapabilities.js.map +1 -1
- package/dist/Infrastructure/ExtensionPoint.js +225 -0
- package/dist/Infrastructure/ExtensionPoint.js.map +1 -0
- package/dist/Infrastructure/LocalFileStorage.js +462 -0
- package/dist/Infrastructure/LocalFileStorage.js.map +1 -0
- package/dist/Infrastructure/ModelDownloader.js +186 -16
- package/dist/Infrastructure/ModelDownloader.js.map +1 -1
- package/dist/Infrastructure/ModelFileInference.js +119 -0
- package/dist/Infrastructure/ModelFileInference.js.map +1 -0
- package/dist/Infrastructure/ModelLoaderTypes.js +7 -1
- package/dist/Infrastructure/ModelLoaderTypes.js.map +1 -1
- package/dist/Infrastructure/ModelManager.js +233 -566
- package/dist/Infrastructure/ModelManager.js.map +1 -1
- package/dist/Infrastructure/ModelRegistry.js +11 -0
- package/dist/Infrastructure/ModelRegistry.js.map +1 -1
- package/dist/Infrastructure/OPFSStorage.js +77 -0
- package/dist/Infrastructure/OPFSStorage.js.map +1 -1
- package/dist/Infrastructure/ProviderTypes.js +13 -0
- package/dist/Infrastructure/ProviderTypes.js.map +1 -0
- package/dist/Infrastructure/VideoCapture.js +15 -0
- package/dist/Infrastructure/VideoCapture.js.map +1 -1
- package/dist/Public/Extensions/RunAnywhere+ModelManagement.js +23 -51
- package/dist/Public/Extensions/RunAnywhere+ModelManagement.js.map +1 -1
- package/dist/Public/Extensions/RunAnywhere+VoiceAgent.js +63 -161
- package/dist/Public/Extensions/RunAnywhere+VoiceAgent.js.map +1 -1
- package/dist/Public/Extensions/RunAnywhere+VoicePipeline.js +30 -44
- package/dist/Public/Extensions/RunAnywhere+VoicePipeline.js.map +1 -1
- package/dist/Public/Extensions/VoicePipelineTypes.js +4 -1
- package/dist/Public/Extensions/VoicePipelineTypes.js.map +1 -1
- package/dist/Public/RunAnywhere.js +167 -211
- package/dist/Public/RunAnywhere.js.map +1 -1
- package/dist/index.js +24 -27
- package/dist/index.js.map +1 -1
- package/dist/services/AnalyticsEmitter.js +85 -0
- package/dist/services/AnalyticsEmitter.js.map +1 -0
- package/dist/services/HTTPService.js +255 -0
- package/dist/services/HTTPService.js.map +1 -0
- package/dist/{Foundation → types/Foundation}/ErrorTypes.d.ts +3 -0
- package/dist/types/Foundation/ErrorTypes.d.ts.map +1 -0
- package/dist/{Foundation → types/Foundation}/EventBus.d.ts +13 -2
- package/dist/types/Foundation/EventBus.d.ts.map +1 -0
- package/dist/types/Foundation/SDKLogger.d.ts.map +1 -0
- package/dist/{Foundation → types/Foundation}/StructOffsets.d.ts +6 -37
- package/dist/types/Foundation/StructOffsets.d.ts.map +1 -0
- package/dist/types/Foundation/WASMBridge.d.ts +13 -0
- package/dist/types/Foundation/WASMBridge.d.ts.map +1 -0
- package/dist/types/Infrastructure/ArchiveUtility.d.ts.map +1 -0
- package/dist/types/Infrastructure/AudioCapture.d.ts.map +1 -0
- package/dist/types/Infrastructure/AudioFileLoader.d.ts +32 -0
- package/dist/types/Infrastructure/AudioFileLoader.d.ts.map +1 -0
- package/dist/types/Infrastructure/AudioPlayback.d.ts.map +1 -0
- package/dist/types/Infrastructure/DeviceCapabilities.d.ts.map +1 -0
- package/dist/types/Infrastructure/ExtensionPoint.d.ts +138 -0
- package/dist/types/Infrastructure/ExtensionPoint.d.ts.map +1 -0
- package/dist/types/Infrastructure/ExtensionRegistry.d.ts.map +1 -0
- package/dist/types/Infrastructure/LocalFileStorage.d.ts +146 -0
- package/dist/types/Infrastructure/LocalFileStorage.d.ts.map +1 -0
- package/dist/{Infrastructure → types/Infrastructure}/ModelDownloader.d.ts +35 -5
- package/dist/types/Infrastructure/ModelDownloader.d.ts.map +1 -0
- package/dist/types/Infrastructure/ModelFileInference.d.ts +39 -0
- package/dist/types/Infrastructure/ModelFileInference.d.ts.map +1 -0
- package/dist/types/Infrastructure/ModelLoaderTypes.d.ts +124 -0
- package/dist/types/Infrastructure/ModelLoaderTypes.d.ts.map +1 -0
- package/dist/types/Infrastructure/ModelManager.d.ts +146 -0
- package/dist/types/Infrastructure/ModelManager.d.ts.map +1 -0
- package/dist/{Infrastructure → types/Infrastructure}/ModelRegistry.d.ts +6 -0
- package/dist/types/Infrastructure/ModelRegistry.d.ts.map +1 -0
- package/dist/{Infrastructure → types/Infrastructure}/OPFSStorage.d.ts +22 -0
- package/dist/types/Infrastructure/OPFSStorage.d.ts.map +1 -0
- package/dist/types/Infrastructure/ProviderTypes.d.ts +55 -0
- package/dist/types/Infrastructure/ProviderTypes.d.ts.map +1 -0
- package/dist/{Infrastructure → types/Infrastructure}/VideoCapture.d.ts +2 -0
- package/dist/types/Infrastructure/VideoCapture.d.ts.map +1 -0
- package/dist/{Public → types/Public}/Extensions/RunAnywhere+ModelManagement.d.ts +12 -4
- package/dist/types/Public/Extensions/RunAnywhere+ModelManagement.d.ts.map +1 -0
- package/dist/types/Public/Extensions/RunAnywhere+VoiceAgent.d.ts +81 -0
- package/dist/types/Public/Extensions/RunAnywhere+VoiceAgent.d.ts.map +1 -0
- package/dist/types/Public/Extensions/RunAnywhere+VoicePipeline.d.ts +37 -0
- package/dist/types/Public/Extensions/RunAnywhere+VoicePipeline.d.ts.map +1 -0
- package/dist/types/Public/Extensions/VoiceAgentTypes.d.ts.map +1 -0
- package/dist/types/Public/Extensions/VoicePipelineTypes.d.ts +60 -0
- package/dist/types/Public/Extensions/VoicePipelineTypes.d.ts.map +1 -0
- package/dist/types/Public/RunAnywhere.d.ts +65 -0
- package/dist/types/Public/RunAnywhere.d.ts.map +1 -0
- package/dist/types/STTTypes.js +9 -0
- package/dist/types/STTTypes.js.map +1 -0
- package/dist/types/TTSTypes.js +8 -0
- package/dist/types/TTSTypes.js.map +1 -0
- package/dist/types/VADTypes.js +13 -0
- package/dist/types/VADTypes.js.map +1 -0
- package/dist/types/VLMTypes.js +13 -0
- package/dist/types/VLMTypes.js.map +1 -0
- package/dist/types/enums.js +7 -0
- package/dist/types/enums.js.map +1 -1
- package/dist/types/index.d.ts +59 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +6 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/services/AnalyticsEmitter.d.ts +53 -0
- package/dist/types/services/AnalyticsEmitter.d.ts.map +1 -0
- package/dist/types/services/HTTPService.d.ts +87 -0
- package/dist/types/services/HTTPService.d.ts.map +1 -0
- package/dist/types/{LLMTypes.d.ts → types/LLMTypes.d.ts} +1 -0
- package/dist/types/types/LLMTypes.d.ts.map +1 -0
- package/dist/types/types/STTTypes.d.ts +44 -0
- package/dist/types/types/STTTypes.d.ts.map +1 -0
- package/dist/types/types/TTSTypes.d.ts +24 -0
- package/dist/types/types/TTSTypes.d.ts.map +1 -0
- package/dist/types/types/VADTypes.d.ts +19 -0
- package/dist/types/types/VADTypes.d.ts.map +1 -0
- package/dist/{Public/Extensions → types/types}/VLMTypes.d.ts +6 -12
- package/dist/types/types/VLMTypes.d.ts.map +1 -0
- package/dist/types/{enums.d.ts → types/enums.d.ts} +7 -0
- package/dist/types/types/enums.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +17 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/{models.d.ts → types/models.d.ts} +1 -0
- package/dist/types/types/models.d.ts.map +1 -0
- package/dist/types/types.d.ts +65 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types.js +21 -0
- package/dist/types.js.map +1 -0
- package/package.json +28 -42
- package/dist/Foundation/ErrorTypes.d.ts.map +0 -1
- package/dist/Foundation/EventBus.d.ts.map +0 -1
- package/dist/Foundation/PlatformAdapter.d.ts +0 -101
- package/dist/Foundation/PlatformAdapter.d.ts.map +0 -1
- package/dist/Foundation/PlatformAdapter.js +0 -417
- package/dist/Foundation/PlatformAdapter.js.map +0 -1
- package/dist/Foundation/SDKLogger.d.ts.map +0 -1
- package/dist/Foundation/SherpaONNXBridge.d.ts +0 -134
- package/dist/Foundation/SherpaONNXBridge.d.ts.map +0 -1
- package/dist/Foundation/SherpaONNXBridge.js +0 -332
- package/dist/Foundation/SherpaONNXBridge.js.map +0 -1
- package/dist/Foundation/StructOffsets.d.ts.map +0 -1
- package/dist/Foundation/WASMBridge.d.ts +0 -241
- package/dist/Foundation/WASMBridge.d.ts.map +0 -1
- package/dist/Infrastructure/ArchiveUtility.d.ts.map +0 -1
- package/dist/Infrastructure/AudioCapture.d.ts.map +0 -1
- package/dist/Infrastructure/AudioPlayback.d.ts.map +0 -1
- package/dist/Infrastructure/DeviceCapabilities.d.ts.map +0 -1
- package/dist/Infrastructure/ExtensionRegistry.d.ts.map +0 -1
- package/dist/Infrastructure/ModelDownloader.d.ts.map +0 -1
- package/dist/Infrastructure/ModelLoaderTypes.d.ts +0 -34
- package/dist/Infrastructure/ModelLoaderTypes.d.ts.map +0 -1
- package/dist/Infrastructure/ModelManager.d.ts +0 -219
- package/dist/Infrastructure/ModelManager.d.ts.map +0 -1
- package/dist/Infrastructure/ModelRegistry.d.ts.map +0 -1
- package/dist/Infrastructure/OPFSStorage.d.ts.map +0 -1
- package/dist/Infrastructure/VLMWorkerBridge.d.ts +0 -211
- package/dist/Infrastructure/VLMWorkerBridge.d.ts.map +0 -1
- package/dist/Infrastructure/VLMWorkerBridge.js +0 -264
- package/dist/Infrastructure/VLMWorkerBridge.js.map +0 -1
- package/dist/Infrastructure/VLMWorkerRuntime.d.ts +0 -38
- package/dist/Infrastructure/VLMWorkerRuntime.d.ts.map +0 -1
- package/dist/Infrastructure/VLMWorkerRuntime.js +0 -503
- package/dist/Infrastructure/VLMWorkerRuntime.js.map +0 -1
- package/dist/Infrastructure/VideoCapture.d.ts.map +0 -1
- package/dist/Public/Extensions/DiffusionTypes.d.ts +0 -64
- package/dist/Public/Extensions/DiffusionTypes.d.ts.map +0 -1
- package/dist/Public/Extensions/DiffusionTypes.js +0 -28
- package/dist/Public/Extensions/DiffusionTypes.js.map +0 -1
- package/dist/Public/Extensions/EmbeddingsTypes.d.ts +0 -33
- package/dist/Public/Extensions/EmbeddingsTypes.d.ts.map +0 -1
- package/dist/Public/Extensions/EmbeddingsTypes.js +0 -13
- package/dist/Public/Extensions/EmbeddingsTypes.js.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+Diffusion.d.ts +0 -44
- package/dist/Public/Extensions/RunAnywhere+Diffusion.d.ts.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+Diffusion.js +0 -189
- package/dist/Public/Extensions/RunAnywhere+Diffusion.js.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+Embeddings.d.ts +0 -56
- package/dist/Public/Extensions/RunAnywhere+Embeddings.d.ts.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+Embeddings.js +0 -240
- package/dist/Public/Extensions/RunAnywhere+Embeddings.js.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+ModelManagement.d.ts.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+STT.d.ts +0 -95
- package/dist/Public/Extensions/RunAnywhere+STT.d.ts.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+STT.js +0 -417
- package/dist/Public/Extensions/RunAnywhere+STT.js.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+StructuredOutput.d.ts +0 -69
- package/dist/Public/Extensions/RunAnywhere+StructuredOutput.d.ts.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+StructuredOutput.js +0 -196
- package/dist/Public/Extensions/RunAnywhere+StructuredOutput.js.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+TTS.d.ts +0 -55
- package/dist/Public/Extensions/RunAnywhere+TTS.d.ts.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+TTS.js +0 -253
- package/dist/Public/Extensions/RunAnywhere+TTS.js.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+TextGeneration.d.ts +0 -80
- package/dist/Public/Extensions/RunAnywhere+TextGeneration.d.ts.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+TextGeneration.js +0 -436
- package/dist/Public/Extensions/RunAnywhere+TextGeneration.js.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+ToolCalling.d.ts +0 -82
- package/dist/Public/Extensions/RunAnywhere+ToolCalling.d.ts.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+ToolCalling.js +0 -576
- package/dist/Public/Extensions/RunAnywhere+ToolCalling.js.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+VAD.d.ts +0 -70
- package/dist/Public/Extensions/RunAnywhere+VAD.d.ts.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+VAD.js +0 -231
- package/dist/Public/Extensions/RunAnywhere+VAD.js.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+VLM.d.ts +0 -58
- package/dist/Public/Extensions/RunAnywhere+VLM.d.ts.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+VLM.js +0 -262
- package/dist/Public/Extensions/RunAnywhere+VLM.js.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+VoiceAgent.d.ts +0 -49
- package/dist/Public/Extensions/RunAnywhere+VoiceAgent.d.ts.map +0 -1
- package/dist/Public/Extensions/RunAnywhere+VoicePipeline.d.ts +0 -63
- package/dist/Public/Extensions/RunAnywhere+VoicePipeline.d.ts.map +0 -1
- package/dist/Public/Extensions/STTTypes.d.ts +0 -53
- package/dist/Public/Extensions/STTTypes.d.ts.map +0 -1
- package/dist/Public/Extensions/STTTypes.js +0 -16
- package/dist/Public/Extensions/STTTypes.js.map +0 -1
- package/dist/Public/Extensions/TTSTypes.d.ts +0 -31
- package/dist/Public/Extensions/TTSTypes.d.ts.map +0 -1
- package/dist/Public/Extensions/TTSTypes.js +0 -3
- package/dist/Public/Extensions/TTSTypes.js.map +0 -1
- package/dist/Public/Extensions/ToolCallingTypes.d.ts +0 -78
- package/dist/Public/Extensions/ToolCallingTypes.d.ts.map +0 -1
- package/dist/Public/Extensions/ToolCallingTypes.js +0 -8
- package/dist/Public/Extensions/ToolCallingTypes.js.map +0 -1
- package/dist/Public/Extensions/VADTypes.d.ts +0 -30
- package/dist/Public/Extensions/VADTypes.d.ts.map +0 -1
- package/dist/Public/Extensions/VADTypes.js +0 -8
- package/dist/Public/Extensions/VADTypes.js.map +0 -1
- package/dist/Public/Extensions/VLMTypes.d.ts.map +0 -1
- package/dist/Public/Extensions/VLMTypes.js +0 -24
- package/dist/Public/Extensions/VLMTypes.js.map +0 -1
- package/dist/Public/Extensions/VoiceAgentTypes.d.ts.map +0 -1
- package/dist/Public/Extensions/VoicePipelineTypes.d.ts +0 -69
- package/dist/Public/Extensions/VoicePipelineTypes.d.ts.map +0 -1
- package/dist/Public/RunAnywhere.d.ts +0 -121
- package/dist/Public/RunAnywhere.d.ts.map +0 -1
- package/dist/index.d.ts +0 -67
- package/dist/index.d.ts.map +0 -1
- package/dist/types/LLMTypes.d.ts.map +0 -1
- package/dist/types/enums.d.ts.map +0 -1
- package/dist/types/models.d.ts.map +0 -1
- package/dist/workers/vlm-worker.d.ts +0 -9
- package/dist/workers/vlm-worker.d.ts.map +0 -1
- package/dist/workers/vlm-worker.js +0 -10
- package/dist/workers/vlm-worker.js.map +0 -1
- package/wasm/racommons-webgpu.js +0 -156
- package/wasm/racommons-webgpu.wasm +0 -0
- package/wasm/racommons.js +0 -126
- package/wasm/racommons.wasm +0 -0
- package/wasm/sherpa/sherpa-onnx-asr.js +0 -1538
- package/wasm/sherpa/sherpa-onnx-glue-original.js +0 -19
- package/wasm/sherpa/sherpa-onnx-glue.js +0 -17
- package/wasm/sherpa/sherpa-onnx-tts.js +0 -657
- package/wasm/sherpa/sherpa-onnx-vad.js +0 -337
- package/wasm/sherpa/sherpa-onnx-wave.js +0 -88
- package/wasm/sherpa/sherpa-onnx.wasm +0 -0
- /package/dist/{Foundation → types/Foundation}/SDKLogger.d.ts +0 -0
- /package/dist/{Infrastructure → types/Infrastructure}/ArchiveUtility.d.ts +0 -0
- /package/dist/{Infrastructure → types/Infrastructure}/AudioCapture.d.ts +0 -0
- /package/dist/{Infrastructure → types/Infrastructure}/AudioPlayback.d.ts +0 -0
- /package/dist/{Infrastructure → types/Infrastructure}/DeviceCapabilities.d.ts +0 -0
- /package/dist/{Infrastructure → types/Infrastructure}/ExtensionRegistry.d.ts +0 -0
- /package/dist/{Public → types/Public}/Extensions/VoiceAgentTypes.d.ts +0 -0
|
@@ -1,393 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* RunAnywhere Web SDK - WASM Bridge
|
|
2
|
+
* RunAnywhere Web SDK - WASM Bridge Types
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
8
|
-
* - dart_bridge.dart (Flutter)
|
|
9
|
-
* - HybridRunAnywhereCore.cpp (React Native)
|
|
10
|
-
*/
|
|
11
|
-
import { SDKError, SDKErrorCode } from './ErrorTypes';
|
|
12
|
-
import { SDKLogger } from './SDKLogger';
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
// WASM Bridge
|
|
15
|
-
// ---------------------------------------------------------------------------
|
|
16
|
-
const logger = new SDKLogger('WASMBridge');
|
|
17
|
-
/**
|
|
18
|
-
* WASMBridge - Loads and manages the RACommons WASM module.
|
|
4
|
+
* Core is now pure TypeScript. The actual WASM bridge implementations
|
|
5
|
+
* live in each backend package:
|
|
6
|
+
* - LlamaCppBridge in @runanywhere/web-llamacpp
|
|
7
|
+
* - SherpaONNXBridge in @runanywhere/web-onnx
|
|
19
8
|
*
|
|
20
|
-
*
|
|
21
|
-
* compiled to WebAssembly. This is the central point through which
|
|
22
|
-
* all SDK operations flow, identical to CppBridge on mobile platforms.
|
|
9
|
+
* This file only exports shared types used by the public API.
|
|
23
10
|
*/
|
|
24
|
-
export
|
|
25
|
-
static _instance = null;
|
|
26
|
-
_module = null;
|
|
27
|
-
_loaded = false;
|
|
28
|
-
_loading = null;
|
|
29
|
-
_accelerationMode = 'cpu';
|
|
30
|
-
/** The URL that was used to load the WASM glue JS (for worker reuse). */
|
|
31
|
-
_loadedModuleUrl = null;
|
|
32
|
-
static get shared() {
|
|
33
|
-
if (!WASMBridge._instance) {
|
|
34
|
-
WASMBridge._instance = new WASMBridge();
|
|
35
|
-
}
|
|
36
|
-
return WASMBridge._instance;
|
|
37
|
-
}
|
|
38
|
-
/** Whether the WASM module is loaded */
|
|
39
|
-
get isLoaded() {
|
|
40
|
-
return this._loaded && this._module !== null;
|
|
41
|
-
}
|
|
42
|
-
/** Get the raw Emscripten module (throws if not loaded) */
|
|
43
|
-
get module() {
|
|
44
|
-
if (!this._module) {
|
|
45
|
-
throw SDKError.wasmNotLoaded();
|
|
46
|
-
}
|
|
47
|
-
return this._module;
|
|
48
|
-
}
|
|
49
|
-
/** The hardware acceleration mode in use (webgpu or cpu). */
|
|
50
|
-
get accelerationMode() {
|
|
51
|
-
return this._accelerationMode;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* The URL of the WASM glue JS that was successfully loaded.
|
|
55
|
-
* Web Workers should use this URL to load the same WASM variant
|
|
56
|
-
* (WebGPU or CPU) that the main thread is using.
|
|
57
|
-
*
|
|
58
|
-
* Returns `null` if `load()` has not been called yet.
|
|
59
|
-
*/
|
|
60
|
-
get workerWasmUrl() {
|
|
61
|
-
return this._loadedModuleUrl;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Load the RACommons WASM module.
|
|
65
|
-
*
|
|
66
|
-
* Detects WebGPU at init time and loads the appropriate build variant:
|
|
67
|
-
* - `racommons-webgpu.js` when WebGPU + JSPI are available
|
|
68
|
-
* - `racommons.js` as the CPU-only fallback
|
|
69
|
-
*
|
|
70
|
-
* Safe to call concurrently -- only the first caller triggers the actual
|
|
71
|
-
* load; subsequent callers await the same in-flight promise.
|
|
72
|
-
*
|
|
73
|
-
* @param wasmUrl - URL to the CPU-only racommons.js glue file.
|
|
74
|
-
* @param webgpuWasmUrl - URL to the WebGPU racommons-webgpu.js glue file.
|
|
75
|
-
* @param acceleration - Force a specific mode ('auto' detects, 'webgpu' forces GPU, 'cpu' forces CPU).
|
|
76
|
-
*/
|
|
77
|
-
async load(wasmUrl, webgpuWasmUrl, acceleration = 'auto') {
|
|
78
|
-
if (this._loaded) {
|
|
79
|
-
logger.debug('WASM module already loaded');
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
// Prevent duplicate loading -- return the in-flight promise
|
|
83
|
-
if (this._loading) {
|
|
84
|
-
await this._loading;
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
this._loading = this._doLoad(wasmUrl, webgpuWasmUrl, acceleration);
|
|
88
|
-
try {
|
|
89
|
-
await this._loading;
|
|
90
|
-
}
|
|
91
|
-
finally {
|
|
92
|
-
this._loading = null;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Internal load implementation.
|
|
97
|
-
* Separated from `load()` so the concurrent-load guard can wrap it.
|
|
98
|
-
*/
|
|
99
|
-
async _doLoad(wasmUrl, webgpuWasmUrl, acceleration = 'auto') {
|
|
100
|
-
logger.info('Loading RACommons WASM module...');
|
|
101
|
-
try {
|
|
102
|
-
// Determine whether to use the WebGPU variant
|
|
103
|
-
const useWebGPU = await this.resolveAcceleration(acceleration);
|
|
104
|
-
this._accelerationMode = useWebGPU ? 'webgpu' : 'cpu';
|
|
105
|
-
// Select the correct module URL
|
|
106
|
-
const moduleUrl = useWebGPU
|
|
107
|
-
? (webgpuWasmUrl ?? new URL('../../wasm/racommons-webgpu.js', import.meta.url).href)
|
|
108
|
-
: (wasmUrl ?? new URL('../../wasm/racommons.js', import.meta.url).href);
|
|
109
|
-
this._loadedModuleUrl = moduleUrl;
|
|
110
|
-
logger.info(`Acceleration mode: ${this._accelerationMode} (loading ${useWebGPU ? 'racommons-webgpu' : 'racommons'})`);
|
|
111
|
-
// Safety-net probe: verify the WebGPU glue JS was compiled with
|
|
112
|
-
// JSPI support. A JSPI-enabled build contains "WebAssembly.promising"
|
|
113
|
-
// which wraps exported WASM functions so they can suspend during
|
|
114
|
-
// async WebGPU operations. If the marker is absent the build is
|
|
115
|
-
// either outdated or misconfigured and generation would crash with
|
|
116
|
-
// "RuntimeError: unreachable". Fall back to CPU in that case.
|
|
117
|
-
if (useWebGPU && acceleration === 'auto') {
|
|
118
|
-
try {
|
|
119
|
-
const probeResp = await fetch(moduleUrl);
|
|
120
|
-
const probeText = await probeResp.text();
|
|
121
|
-
if (!probeText.includes('WebAssembly.promising')) {
|
|
122
|
-
logger.warning('WebGPU WASM build lacks JSPI support (WebAssembly.promising not found). Falling back to CPU.');
|
|
123
|
-
return this._doLoad(wasmUrl, undefined, 'cpu');
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
catch {
|
|
127
|
-
// If the probe fails, proceed with WebGPU and let runtime errors
|
|
128
|
-
// surface normally.
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
// Dynamic import of the Emscripten glue JS
|
|
132
|
-
// The glue file exports a factory function: createRACommonsModule()
|
|
133
|
-
const { default: createModule } = await import(/* @vite-ignore */ moduleUrl);
|
|
134
|
-
// Instantiate the WASM module
|
|
135
|
-
this._module = await createModule({
|
|
136
|
-
// Emscripten module overrides
|
|
137
|
-
print: (text) => logger.info(text),
|
|
138
|
-
printErr: (text) => logger.error(text),
|
|
139
|
-
});
|
|
140
|
-
// Verify module loaded correctly.
|
|
141
|
-
// With JSPI builds some exports may return Promises, so await just
|
|
142
|
-
// in case _rac_wasm_ping was wrapped with WebAssembly.promising.
|
|
143
|
-
const pingRaw = this._module._rac_wasm_ping();
|
|
144
|
-
const pingResult = (typeof pingRaw === 'object' && pingRaw !== null && 'then' in pingRaw)
|
|
145
|
-
? await pingRaw
|
|
146
|
-
: pingRaw;
|
|
147
|
-
if (pingResult !== 42) {
|
|
148
|
-
throw new Error(`WASM ping failed: expected 42, got ${pingResult}`);
|
|
149
|
-
}
|
|
150
|
-
this._loaded = true;
|
|
151
|
-
logger.info(`RACommons WASM module loaded successfully (${this._accelerationMode})`);
|
|
152
|
-
}
|
|
153
|
-
catch (error) {
|
|
154
|
-
// If WebGPU load failed, fall back to CPU automatically
|
|
155
|
-
if (this._accelerationMode === 'webgpu' && acceleration === 'auto') {
|
|
156
|
-
const reason = error instanceof Error ? error.message : String(error);
|
|
157
|
-
logger.warning(`WebGPU WASM module failed to load (${reason}), falling back to CPU`);
|
|
158
|
-
this._accelerationMode = 'cpu';
|
|
159
|
-
this._module = null;
|
|
160
|
-
this._loaded = false;
|
|
161
|
-
return this._doLoad(wasmUrl, undefined, 'cpu');
|
|
162
|
-
}
|
|
163
|
-
this._module = null;
|
|
164
|
-
this._loaded = false;
|
|
165
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
166
|
-
logger.error(`Failed to load WASM module: ${message}`);
|
|
167
|
-
throw new SDKError(SDKErrorCode.WASMLoadFailed, `Failed to load WASM module: ${message}`);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
// -----------------------------------------------------------------------
|
|
171
|
-
// WebGPU Detection
|
|
172
|
-
// -----------------------------------------------------------------------
|
|
173
|
-
/**
|
|
174
|
-
* Determine whether to use WebGPU based on the acceleration preference
|
|
175
|
-
* and actual browser capability.
|
|
176
|
-
*/
|
|
177
|
-
async resolveAcceleration(preference) {
|
|
178
|
-
if (preference === 'cpu')
|
|
179
|
-
return false;
|
|
180
|
-
const hasWebGPU = await WASMBridge.detectWebGPU();
|
|
181
|
-
if (preference === 'webgpu' && !hasWebGPU) {
|
|
182
|
-
logger.warning('WebGPU requested but not available; falling back to CPU');
|
|
183
|
-
return false;
|
|
184
|
-
}
|
|
185
|
-
if (!hasWebGPU)
|
|
186
|
-
return false;
|
|
187
|
-
// The WebGPU WASM module is compiled with JSPI (WebAssembly JavaScript
|
|
188
|
-
// Promise Integration). If the browser doesn't expose the JSPI APIs
|
|
189
|
-
// the module will fail to instantiate.
|
|
190
|
-
const hasJSPI = WASMBridge.detectJSPI();
|
|
191
|
-
if (!hasJSPI) {
|
|
192
|
-
logger.warning('WebGPU available but browser lacks JSPI support (WebAssembly.promising). ' +
|
|
193
|
-
'Update Chrome to 128+ or enable chrome://flags/#experimental-wasm-jspi. Falling back to CPU.');
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Probe for a functional WebGPU adapter.
|
|
200
|
-
* Returns true only when the browser exposes navigator.gpu AND
|
|
201
|
-
* a valid adapter can be obtained.
|
|
202
|
-
*/
|
|
203
|
-
static async detectWebGPU() {
|
|
204
|
-
if (typeof navigator === 'undefined' || !('gpu' in navigator))
|
|
205
|
-
return false;
|
|
206
|
-
try {
|
|
207
|
-
const gpu = navigator.gpu;
|
|
208
|
-
const adapter = await gpu?.requestAdapter();
|
|
209
|
-
return adapter !== null;
|
|
210
|
-
}
|
|
211
|
-
catch {
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Detect JSPI (JavaScript Promise Integration) support.
|
|
217
|
-
* The WebGPU WASM module requires WebAssembly.promising and
|
|
218
|
-
* WebAssembly.Suspending to suspend during async GPU operations.
|
|
219
|
-
*/
|
|
220
|
-
static detectJSPI() {
|
|
221
|
-
try {
|
|
222
|
-
return (typeof WebAssembly !== 'undefined' &&
|
|
223
|
-
'promising' in WebAssembly &&
|
|
224
|
-
'Suspending' in WebAssembly);
|
|
225
|
-
}
|
|
226
|
-
catch {
|
|
227
|
-
return false;
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
// -----------------------------------------------------------------------
|
|
231
|
-
// String Helpers
|
|
232
|
-
// -----------------------------------------------------------------------
|
|
233
|
-
/** Allocate a C string in WASM memory. Caller must free. */
|
|
234
|
-
allocString(str) {
|
|
235
|
-
const m = this.module;
|
|
236
|
-
const len = m.lengthBytesUTF8(str) + 1;
|
|
237
|
-
const ptr = m._malloc(len);
|
|
238
|
-
m.stringToUTF8(str, ptr, len);
|
|
239
|
-
return ptr;
|
|
240
|
-
}
|
|
241
|
-
/** Read a C string from WASM memory */
|
|
242
|
-
readString(ptr) {
|
|
243
|
-
if (ptr === 0)
|
|
244
|
-
return '';
|
|
245
|
-
return this.module.UTF8ToString(ptr);
|
|
246
|
-
}
|
|
247
|
-
/** Free WASM memory */
|
|
248
|
-
free(ptr) {
|
|
249
|
-
if (ptr !== 0) {
|
|
250
|
-
this.module._free(ptr);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
// -----------------------------------------------------------------------
|
|
254
|
-
// Binary Data Helpers
|
|
255
|
-
//
|
|
256
|
-
// HEAPU8 / HEAPF32 may not be exported by the Emscripten module.
|
|
257
|
-
// These helpers try the fast HEAPU8/HEAPF32 path first, then fall
|
|
258
|
-
// back to byte-by-byte setValue/getValue which is always available.
|
|
259
|
-
// -----------------------------------------------------------------------
|
|
260
|
-
/**
|
|
261
|
-
* Write a Uint8Array into WASM linear memory at `destPtr`.
|
|
262
|
-
*
|
|
263
|
-
* Fast path uses `HEAPU8.set()` when available (after WASM rebuild).
|
|
264
|
-
* Fallback uses `setValue` byte-by-byte (works with any build).
|
|
265
|
-
*/
|
|
266
|
-
writeBytes(src, destPtr) {
|
|
267
|
-
const m = this.module;
|
|
268
|
-
if (m.HEAPU8) {
|
|
269
|
-
m.HEAPU8.set(src, destPtr);
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
for (let i = 0; i < src.length; i++) {
|
|
273
|
-
m.setValue(destPtr + i, src[i], 'i8');
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Read `length` bytes from WASM linear memory starting at `srcPtr`.
|
|
278
|
-
*
|
|
279
|
-
* Fast path uses `HEAPU8.slice()` when available.
|
|
280
|
-
* Fallback uses `getValue` byte-by-byte.
|
|
281
|
-
*/
|
|
282
|
-
readBytes(srcPtr, length) {
|
|
283
|
-
const m = this.module;
|
|
284
|
-
if (m.HEAPU8) {
|
|
285
|
-
return m.HEAPU8.slice(srcPtr, srcPtr + length);
|
|
286
|
-
}
|
|
287
|
-
const result = new Uint8Array(length);
|
|
288
|
-
for (let i = 0; i < length; i++) {
|
|
289
|
-
result[i] = m.getValue(srcPtr + i, 'i8') & 0xFF;
|
|
290
|
-
}
|
|
291
|
-
return result;
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* Read `count` float32 values from WASM linear memory starting at `srcPtr`.
|
|
295
|
-
*
|
|
296
|
-
* Fast path uses `HEAPF32` when available.
|
|
297
|
-
* Fallback reads 4 bytes at a time via getValue('float').
|
|
298
|
-
*/
|
|
299
|
-
readFloat32Array(srcPtr, count) {
|
|
300
|
-
const m = this.module;
|
|
301
|
-
if (m.HEAPF32) {
|
|
302
|
-
const startIndex = srcPtr >> 2; // byte offset → float32 index
|
|
303
|
-
return m.HEAPF32.slice(startIndex, startIndex + count);
|
|
304
|
-
}
|
|
305
|
-
const result = new Float32Array(count);
|
|
306
|
-
for (let i = 0; i < count; i++) {
|
|
307
|
-
result[i] = m.getValue(srcPtr + i * 4, 'float');
|
|
308
|
-
}
|
|
309
|
-
return result;
|
|
310
|
-
}
|
|
311
|
-
/**
|
|
312
|
-
* Write a Float32Array into WASM linear memory at `destPtr`.
|
|
313
|
-
* `destPtr` must be 4-byte aligned.
|
|
314
|
-
*
|
|
315
|
-
* Fast path uses `HEAPF32.set()` when available.
|
|
316
|
-
* Fallback uses `setValue` with 'float'.
|
|
317
|
-
*/
|
|
318
|
-
writeFloat32Array(src, destPtr) {
|
|
319
|
-
const m = this.module;
|
|
320
|
-
if (m.HEAPF32) {
|
|
321
|
-
m.HEAPF32.set(src, destPtr >> 2);
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
for (let i = 0; i < src.length; i++) {
|
|
325
|
-
m.setValue(destPtr + i * 4, src[i], 'float');
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Read a single float32 value from WASM linear memory.
|
|
330
|
-
*/
|
|
331
|
-
readFloat32(ptr) {
|
|
332
|
-
const m = this.module;
|
|
333
|
-
if (m.HEAPF32) {
|
|
334
|
-
return m.HEAPF32[ptr >> 2];
|
|
335
|
-
}
|
|
336
|
-
return m.getValue(ptr, 'float');
|
|
337
|
-
}
|
|
338
|
-
// -----------------------------------------------------------------------
|
|
339
|
-
// C API Wrappers
|
|
340
|
-
// -----------------------------------------------------------------------
|
|
341
|
-
/** Check a rac_result_t and throw SDKError if not success */
|
|
342
|
-
checkResult(result, operation) {
|
|
343
|
-
if (result !== 0) {
|
|
344
|
-
const errMsgPtr = this.module._rac_error_message(result);
|
|
345
|
-
const errMsg = this.readString(errMsgPtr);
|
|
346
|
-
throw SDKError.fromRACResult(result, `${operation}: ${errMsg}`);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
/** Get RACommons error message for a result code */
|
|
350
|
-
getErrorMessage(resultCode) {
|
|
351
|
-
const ptr = this.module._rac_error_message(resultCode);
|
|
352
|
-
return this.readString(ptr);
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Type-safe wrapper around Emscripten ccall().
|
|
356
|
-
* Centralizes all dynamic WASM function calls through the bridge.
|
|
357
|
-
*/
|
|
358
|
-
callFunction(funcName, returnType, argTypes, args, opts) {
|
|
359
|
-
if (!this._module)
|
|
360
|
-
throw SDKError.wasmNotLoaded();
|
|
361
|
-
return this._module.ccall(funcName, returnType, argTypes, args, opts);
|
|
362
|
-
}
|
|
363
|
-
/**
|
|
364
|
-
* Call a WASM function that returns rac_result_t and throw SDKError if
|
|
365
|
-
* the result is non-zero.
|
|
366
|
-
*/
|
|
367
|
-
callWithCheck(funcName, argTypes, args) {
|
|
368
|
-
const result = this.callFunction(funcName, 'number', argTypes, args);
|
|
369
|
-
this.checkResult(result, funcName);
|
|
370
|
-
}
|
|
371
|
-
// -----------------------------------------------------------------------
|
|
372
|
-
// Cleanup
|
|
373
|
-
// -----------------------------------------------------------------------
|
|
374
|
-
/** Shutdown the WASM module */
|
|
375
|
-
shutdown() {
|
|
376
|
-
if (this._module && this._loaded) {
|
|
377
|
-
try {
|
|
378
|
-
this._module._rac_shutdown();
|
|
379
|
-
}
|
|
380
|
-
catch {
|
|
381
|
-
// Ignore shutdown errors
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
this._module = null;
|
|
385
|
-
this._loaded = false;
|
|
386
|
-
this._loading = null;
|
|
387
|
-
this._accelerationMode = 'cpu';
|
|
388
|
-
this._loadedModuleUrl = null;
|
|
389
|
-
WASMBridge._instance = null;
|
|
390
|
-
logger.info('WASM bridge shut down');
|
|
391
|
-
}
|
|
392
|
-
}
|
|
11
|
+
export {};
|
|
393
12
|
//# sourceMappingURL=WASMBridge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WASMBridge.js","sourceRoot":"","sources":["../../src/Foundation/WASMBridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG
|
|
1
|
+
{"version":3,"file":"WASMBridge.js","sourceRoot":"","sources":["../../src/Foundation/WASMBridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AudioFileLoader
|
|
3
|
+
*
|
|
4
|
+
* Decodes a browser audio File/Blob into a mono Float32Array PCM buffer
|
|
5
|
+
* suitable for on-device STT transcription.
|
|
6
|
+
*
|
|
7
|
+
* Centralizing this conversion in the SDK means host applications only
|
|
8
|
+
* need to pass a File — the resampling, channel-mixing, and Web Audio
|
|
9
|
+
* setup are all handled here.
|
|
10
|
+
*
|
|
11
|
+
* Supported input formats: anything the browser's AudioContext can decode
|
|
12
|
+
* (wav, mp3, m4a, ogg, flac, aac, opus, webm, etc.)
|
|
13
|
+
*/
|
|
14
|
+
export class AudioFileLoader {
|
|
15
|
+
/**
|
|
16
|
+
* Decode an audio File to a mono Float32Array PCM buffer.
|
|
17
|
+
* Resamples to targetSampleRate if the file's native rate differs.
|
|
18
|
+
*
|
|
19
|
+
* @param file Any browser-supported audio file
|
|
20
|
+
* @param targetSampleRate Output sample rate (default: 16000 Hz for STT models)
|
|
21
|
+
*/
|
|
22
|
+
static async toFloat32Array(file, targetSampleRate = 16000) {
|
|
23
|
+
const arrayBuffer = await file.arrayBuffer();
|
|
24
|
+
// Decode at the file's native sample rate
|
|
25
|
+
const nativeCtx = new AudioContext();
|
|
26
|
+
let audioBuffer;
|
|
27
|
+
try {
|
|
28
|
+
audioBuffer = await nativeCtx.decodeAudioData(arrayBuffer);
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
await nativeCtx.close();
|
|
32
|
+
}
|
|
33
|
+
const durationSeconds = audioBuffer.duration;
|
|
34
|
+
// If already at target rate, take channel 0 directly (copy to avoid detached buffer issues)
|
|
35
|
+
if (audioBuffer.sampleRate === targetSampleRate) {
|
|
36
|
+
return {
|
|
37
|
+
samples: new Float32Array(audioBuffer.getChannelData(0)),
|
|
38
|
+
sampleRate: targetSampleRate,
|
|
39
|
+
durationSeconds,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
// Resample to target rate using OfflineAudioContext
|
|
43
|
+
const targetLength = Math.ceil(durationSeconds * targetSampleRate);
|
|
44
|
+
const offlineCtx = new OfflineAudioContext(1, targetLength, targetSampleRate);
|
|
45
|
+
const source = offlineCtx.createBufferSource();
|
|
46
|
+
source.buffer = audioBuffer;
|
|
47
|
+
source.connect(offlineCtx.destination);
|
|
48
|
+
source.start();
|
|
49
|
+
const resampled = await offlineCtx.startRendering();
|
|
50
|
+
return {
|
|
51
|
+
samples: new Float32Array(resampled.getChannelData(0)),
|
|
52
|
+
sampleRate: targetSampleRate,
|
|
53
|
+
durationSeconds,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=AudioFileLoader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AudioFileLoader.js","sourceRoot":"","sources":["../../src/Infrastructure/AudioFileLoader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAWH,MAAM,OAAO,eAAe;IAC1B;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,cAAc,CACzB,IAAU,EACV,gBAAgB,GAAG,KAAK;QAExB,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC;QAE7C,0CAA0C;QAC1C,MAAM,SAAS,GAAG,IAAI,YAAY,EAAE,CAAC;QACrC,IAAI,WAAwB,CAAC;QAC7B,IAAI,CAAC;YACH,WAAW,GAAG,MAAM,SAAS,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QAC7D,CAAC;gBAAS,CAAC;YACT,MAAM,SAAS,CAAC,KAAK,EAAE,CAAC;QAC1B,CAAC;QAED,MAAM,eAAe,GAAG,WAAW,CAAC,QAAQ,CAAC;QAE7C,4FAA4F;QAC5F,IAAI,WAAW,CAAC,UAAU,KAAK,gBAAgB,EAAE,CAAC;YAChD,OAAO;gBACL,OAAO,EAAE,IAAI,YAAY,CAAC,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;gBACxD,UAAU,EAAE,gBAAgB;gBAC5B,eAAe;aAChB,CAAC;QACJ,CAAC;QAED,oDAAoD;QACpD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,GAAG,gBAAgB,CAAC,CAAC;QACnE,MAAM,UAAU,GAAG,IAAI,mBAAmB,CAAC,CAAC,EAAE,YAAY,EAAE,gBAAgB,CAAC,CAAC;QAC9E,MAAM,MAAM,GAAG,UAAU,CAAC,kBAAkB,EAAE,CAAC;QAC/C,MAAM,CAAC,MAAM,GAAG,WAAW,CAAC;QAC5B,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QACvC,MAAM,CAAC,KAAK,EAAE,CAAC;QAEf,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,cAAc,EAAE,CAAC;QACpD,OAAO;YACL,OAAO,EAAE,IAAI,YAAY,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;YACtD,UAAU,EAAE,gBAAgB;YAC5B,eAAe;SAChB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -10,11 +10,9 @@ const logger = new SDKLogger('DeviceCapabilities');
|
|
|
10
10
|
* Detect all browser capabilities relevant to AI inference.
|
|
11
11
|
*/
|
|
12
12
|
export async function detectCapabilities() {
|
|
13
|
-
// Import WASMBridge lazily to avoid circular imports at module level
|
|
14
|
-
const { WASMBridge } = await import('../Foundation/WASMBridge');
|
|
15
13
|
const capabilities = {
|
|
16
14
|
hasWebGPU: false,
|
|
17
|
-
activeAcceleration:
|
|
15
|
+
activeAcceleration: 'cpu',
|
|
18
16
|
hasSharedArrayBuffer: typeof SharedArrayBuffer !== 'undefined',
|
|
19
17
|
isCrossOriginIsolated: typeof crossOriginIsolated !== 'undefined' ? crossOriginIsolated : false,
|
|
20
18
|
hasWASMSIMD: detectWASMSIMD(),
|
|
@@ -51,6 +49,13 @@ export async function detectCapabilities() {
|
|
|
51
49
|
`OPFS=${capabilities.hasOPFS}, ` +
|
|
52
50
|
`Memory=${capabilities.deviceMemoryGB}GB, ` +
|
|
53
51
|
`Cores=${capabilities.hardwareConcurrency}`);
|
|
52
|
+
if (!capabilities.isCrossOriginIsolated) {
|
|
53
|
+
logger.warning('Cross-Origin Isolation is NOT enabled. SharedArrayBuffer and multi-threaded WASM ' +
|
|
54
|
+
'will be unavailable. Set these HTTP headers on your server:\n' +
|
|
55
|
+
' Cross-Origin-Opener-Policy: same-origin\n' +
|
|
56
|
+
' Cross-Origin-Embedder-Policy: credentialless\n' +
|
|
57
|
+
'See: https://github.com/AnywhereAI/runanywhere-sdks/tree/main/sdk/runanywhere-web#cross-origin-isolation-headers');
|
|
58
|
+
}
|
|
54
59
|
return capabilities;
|
|
55
60
|
}
|
|
56
61
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceCapabilities.js","sourceRoot":"","sources":["../../src/Infrastructure/DeviceCapabilities.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,oBAAoB,CAAC,CAAC;AAyBnD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,
|
|
1
|
+
{"version":3,"file":"DeviceCapabilities.js","sourceRoot":"","sources":["../../src/Infrastructure/DeviceCapabilities.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAGpD,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,oBAAoB,CAAC,CAAC;AAyBnD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,MAAM,YAAY,GAAoB;QACpC,SAAS,EAAE,KAAK;QAChB,kBAAkB,EAAE,KAAK;QACzB,oBAAoB,EAAE,OAAO,iBAAiB,KAAK,WAAW;QAC9D,qBAAqB,EAAE,OAAO,mBAAmB,KAAK,WAAW,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,KAAK;QAC/F,WAAW,EAAE,cAAc,EAAE;QAC7B,OAAO,EAAE,OAAO,SAAS,KAAK,WAAW,IAAI,SAAS,IAAI,SAAS,IAAI,cAAc,IAAI,SAAS,CAAC,OAAO;QAC1G,cAAc,EAAG,SAAuC,CAAC,YAAY,IAAI,CAAC;QAC1E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