@runanywhere/web 0.1.0-beta.5 → 0.1.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Foundation/ErrorTypes.d.ts +1 -0
- package/dist/Foundation/ErrorTypes.d.ts.map +1 -1
- package/dist/Foundation/ErrorTypes.js +3 -0
- package/dist/Foundation/ErrorTypes.js.map +1 -1
- package/dist/Foundation/EventBus.d.ts +0 -1
- package/dist/Foundation/EventBus.d.ts.map +1 -1
- package/dist/Foundation/StructOffsets.d.ts +5 -65
- package/dist/Foundation/StructOffsets.d.ts.map +1 -1
- package/dist/Foundation/StructOffsets.js +6 -191
- package/dist/Foundation/StructOffsets.js.map +1 -1
- package/dist/Foundation/WASMBridge.d.ts +8 -236
- package/dist/Foundation/WASMBridge.d.ts.map +1 -1
- package/dist/Foundation/WASMBridge.js +7 -388
- package/dist/Foundation/WASMBridge.js.map +1 -1
- package/dist/Infrastructure/DeviceCapabilities.d.ts.map +1 -1
- package/dist/Infrastructure/DeviceCapabilities.js +1 -3
- package/dist/Infrastructure/DeviceCapabilities.js.map +1 -1
- package/dist/Infrastructure/ExtensionPoint.d.ts +36 -0
- package/dist/Infrastructure/ExtensionPoint.d.ts.map +1 -1
- package/dist/Infrastructure/ExtensionPoint.js +60 -0
- package/dist/Infrastructure/ExtensionPoint.js.map +1 -1
- package/dist/Infrastructure/LocalFileStorage.d.ts +18 -0
- package/dist/Infrastructure/LocalFileStorage.d.ts.map +1 -1
- package/dist/Infrastructure/LocalFileStorage.js +60 -0
- package/dist/Infrastructure/LocalFileStorage.js.map +1 -1
- package/dist/Infrastructure/ModelDownloader.d.ts +5 -0
- package/dist/Infrastructure/ModelDownloader.d.ts.map +1 -1
- package/dist/Infrastructure/ModelDownloader.js +25 -0
- package/dist/Infrastructure/ModelDownloader.js.map +1 -1
- package/dist/Infrastructure/ModelFileInference.d.ts.map +1 -1
- package/dist/Infrastructure/ModelFileInference.js +13 -4
- package/dist/Infrastructure/ModelFileInference.js.map +1 -1
- package/dist/Infrastructure/ModelLoaderTypes.d.ts +18 -4
- package/dist/Infrastructure/ModelLoaderTypes.d.ts.map +1 -1
- package/dist/Infrastructure/ModelManager.d.ts +3 -2
- package/dist/Infrastructure/ModelManager.d.ts.map +1 -1
- package/dist/Infrastructure/ModelManager.js +33 -57
- package/dist/Infrastructure/ModelManager.js.map +1 -1
- package/dist/Infrastructure/OPFSStorage.d.ts +8 -0
- package/dist/Infrastructure/OPFSStorage.d.ts.map +1 -1
- package/dist/Infrastructure/OPFSStorage.js +37 -0
- package/dist/Infrastructure/OPFSStorage.js.map +1 -1
- package/dist/Public/Extensions/RunAnywhere+ModelManagement.d.ts +12 -4
- package/dist/Public/Extensions/RunAnywhere+ModelManagement.d.ts.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.d.ts +42 -10
- package/dist/Public/Extensions/RunAnywhere+VoiceAgent.d.ts.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.d.ts.map +1 -1
- package/dist/Public/Extensions/RunAnywhere+VoicePipeline.js +5 -25
- package/dist/Public/Extensions/RunAnywhere+VoicePipeline.js.map +1 -1
- package/dist/Public/RunAnywhere.d.ts +11 -71
- package/dist/Public/RunAnywhere.d.ts.map +1 -1
- package/dist/Public/RunAnywhere.js +55 -149
- package/dist/Public/RunAnywhere.js.map +1 -1
- package/dist/index.d.ts +7 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -11
- package/dist/index.js.map +1 -1
- package/package.json +4 -6
- 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/wasm/racommons.js +0 -126
- package/wasm/racommons.wasm +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WASMBridge.d.ts","sourceRoot":"","sources":["../../src/Foundation/WASMBridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;
|
|
1
|
+
{"version":3,"file":"WASMBridge.d.ts","sourceRoot":"","sources":["../../src/Foundation/WASMBridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,sEAAsE;AACtE,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,KAAK,CAAC"}
|
|
@@ -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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeviceCapabilities.d.ts","sourceRoot":"","sources":["../../src/Infrastructure/DeviceCapabilities.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAIjE,MAAM,WAAW,eAAe;IAC9B,sCAAsC;IACtC,SAAS,EAAE,OAAO,CAAC;IACnB,yCAAyC;IACzC,cAAc,CA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,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,eAAe,CAAC,CA4CnE;AAED;;GAEG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,cAAc,CAAC,CAY7D"}
|
|
@@ -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(),
|
|
@@ -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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AAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,EAAE;SAC7C,CAAC,CAAC;QACH,OAAO,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,EAAU;IAChC,IAAI,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC;QAAE,OAAO,SAAS,CAAC;IAC7C,IAAI,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAC;IACvC,IAAI,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC3C,IAAI,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAC;IAC3C,OAAO,iBAAiB,CAAC;AAC3B,CAAC;AAED,SAAS,YAAY,CAAC,EAAU;IAC9B,IAAI,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC;QAAE,OAAO,SAAS,CAAC;IAC7C,IAAI,EAAE,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,OAAO,CAAC;IAC5C,IAAI,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC;IACzC,IAAI,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC;QAAE,OAAO,SAAS,CAAC;IAC7C,IAAI,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACrC,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -31,6 +31,24 @@ export declare enum BackendCapability {
|
|
|
31
31
|
ToolCalling = "toolCalling",
|
|
32
32
|
StructuredOutput = "structuredOutput"
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Typed service keys for cross-package singleton access.
|
|
36
|
+
*
|
|
37
|
+
* Backend packages register service instances (e.g. TextGeneration, STT, TTS)
|
|
38
|
+
* under these keys during their registration phase. Core code (e.g. VoicePipeline)
|
|
39
|
+
* retrieves them at runtime via `ExtensionPoint.getService(ServiceKey.XXX)` instead
|
|
40
|
+
* of relying on untyped globalThis keys.
|
|
41
|
+
*/
|
|
42
|
+
export declare enum ServiceKey {
|
|
43
|
+
TextGeneration = "textGeneration",
|
|
44
|
+
STT = "stt",
|
|
45
|
+
TTS = "tts",
|
|
46
|
+
VLM = "vlm",
|
|
47
|
+
Embeddings = "embeddings",
|
|
48
|
+
Diffusion = "diffusion",
|
|
49
|
+
ToolCalling = "toolCalling",
|
|
50
|
+
VAD = "vad"
|
|
51
|
+
}
|
|
34
52
|
/**
|
|
35
53
|
* Interface that every backend package must implement to register
|
|
36
54
|
* itself with the core SDK.
|
|
@@ -49,6 +67,7 @@ export interface BackendExtension {
|
|
|
49
67
|
declare class ExtensionPointImpl {
|
|
50
68
|
private backends;
|
|
51
69
|
private capabilityMap;
|
|
70
|
+
private services;
|
|
52
71
|
/**
|
|
53
72
|
* Register a backend extension.
|
|
54
73
|
* Idempotent — re-registering the same id is a no-op.
|
|
@@ -65,6 +84,23 @@ declare class ExtensionPointImpl {
|
|
|
65
84
|
* Use in extension methods that depend on a backend being registered.
|
|
66
85
|
*/
|
|
67
86
|
requireCapability(capability: BackendCapability): void;
|
|
87
|
+
/**
|
|
88
|
+
* Register a service singleton under a typed key.
|
|
89
|
+
* Backend packages call this during their registration phase.
|
|
90
|
+
*/
|
|
91
|
+
registerService<T>(key: ServiceKey, service: T): void;
|
|
92
|
+
/**
|
|
93
|
+
* Retrieve a registered service singleton.
|
|
94
|
+
* Returns undefined if the service is not registered yet.
|
|
95
|
+
*/
|
|
96
|
+
getService<T>(key: ServiceKey): T | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Retrieve a registered service or throw a descriptive error.
|
|
99
|
+
* Use in code that requires a specific backend to be registered.
|
|
100
|
+
*/
|
|
101
|
+
requireService<T>(key: ServiceKey, packageHint?: string): T;
|
|
102
|
+
/** Remove a registered service. */
|
|
103
|
+
removeService(key: ServiceKey): void;
|
|
68
104
|
/**
|
|
69
105
|
* Cleanup all registered backends in reverse registration order.
|
|
70
106
|
* Called during SDK shutdown.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionPoint.d.ts","sourceRoot":"","sources":["../../src/Infrastructure/ExtensionPoint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAUH,+CAA+C;AAC/C,oBAAY,iBAAiB;IAC3B,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,GAAG,QAAQ;IACX,UAAU,eAAe;IACzB,SAAS,cAAc;IACvB,WAAW,gBAAgB;IAC3B,gBAAgB,qBAAqB;CACtC;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB,0CAA0C;IAC1C,QAAQ,CAAC,YAAY,EAAE,iBAAiB,EAAE,CAAC;IAE3C;;;OAGG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAMD,cAAM,kBAAkB;IACtB,OAAO,CAAC,QAAQ,CAA4C;IAC5D,OAAO,CAAC,aAAa,CAAuD;IAE5E;;;OAGG;IACH,eAAe,CAAC,SAAS,EAAE,gBAAgB,GAAG,IAAI;IAqBlD,+BAA+B;IAC/B,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAIpD,sFAAsF;IACtF,aAAa,CAAC,UAAU,EAAE,iBAAiB,GAAG,OAAO;IAIrD,8DAA8D;IAC9D,yBAAyB,CAAC,UAAU,EAAE,iBAAiB,GAAG,gBAAgB,GAAG,SAAS;IAItF;;;OAGG;IACH,iBAAiB,CAAC,UAAU,EAAE,iBAAiB,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"ExtensionPoint.d.ts","sourceRoot":"","sources":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,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC,GAAG,IAAI;IAOrD;;;OAGG;IACH,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,GAAG,CAAC,GAAG,SAAS;IAI7C;;;OAGG;IACH,cAAc,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,CAAC;IAe3D,mCAAmC;IACnC,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI;IAIpC;;;OAGG;IACH,UAAU,IAAI,IAAI;IAYlB,qDAAqD;IACrD,KAAK,IAAI,IAAI;CAKd;AAED,eAAO,MAAM,cAAc,oBAA2B,CAAC"}
|
|
@@ -37,12 +37,33 @@ export var BackendCapability;
|
|
|
37
37
|
BackendCapability["ToolCalling"] = "toolCalling";
|
|
38
38
|
BackendCapability["StructuredOutput"] = "structuredOutput";
|
|
39
39
|
})(BackendCapability || (BackendCapability = {}));
|
|
40
|
+
/**
|
|
41
|
+
* Typed service keys for cross-package singleton access.
|
|
42
|
+
*
|
|
43
|
+
* Backend packages register service instances (e.g. TextGeneration, STT, TTS)
|
|
44
|
+
* under these keys during their registration phase. Core code (e.g. VoicePipeline)
|
|
45
|
+
* retrieves them at runtime via `ExtensionPoint.getService(ServiceKey.XXX)` instead
|
|
46
|
+
* of relying on untyped globalThis keys.
|
|
47
|
+
*/
|
|
48
|
+
export var ServiceKey;
|
|
49
|
+
(function (ServiceKey) {
|
|
50
|
+
ServiceKey["TextGeneration"] = "textGeneration";
|
|
51
|
+
ServiceKey["STT"] = "stt";
|
|
52
|
+
ServiceKey["TTS"] = "tts";
|
|
53
|
+
ServiceKey["VLM"] = "vlm";
|
|
54
|
+
ServiceKey["Embeddings"] = "embeddings";
|
|
55
|
+
ServiceKey["Diffusion"] = "diffusion";
|
|
56
|
+
ServiceKey["ToolCalling"] = "toolCalling";
|
|
57
|
+
ServiceKey["VAD"] = "vad";
|
|
58
|
+
})(ServiceKey || (ServiceKey = {}));
|
|
40
59
|
// ---------------------------------------------------------------------------
|
|
41
60
|
// ExtensionPoint Singleton
|
|
42
61
|
// ---------------------------------------------------------------------------
|
|
43
62
|
class ExtensionPointImpl {
|
|
44
63
|
backends = new Map();
|
|
45
64
|
capabilityMap = new Map();
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
|
+
services = new Map();
|
|
46
67
|
/**
|
|
47
68
|
* Register a backend extension.
|
|
48
69
|
* Idempotent — re-registering the same id is a no-op.
|
|
@@ -92,6 +113,44 @@ class ExtensionPointImpl {
|
|
|
92
113
|
`Install and register the ${packageHint} package.`);
|
|
93
114
|
}
|
|
94
115
|
}
|
|
116
|
+
// -------------------------------------------------------------------------
|
|
117
|
+
// Service Registry — typed singleton access for cross-package communication
|
|
118
|
+
// -------------------------------------------------------------------------
|
|
119
|
+
/**
|
|
120
|
+
* Register a service singleton under a typed key.
|
|
121
|
+
* Backend packages call this during their registration phase.
|
|
122
|
+
*/
|
|
123
|
+
registerService(key, service) {
|
|
124
|
+
if (this.services.has(key)) {
|
|
125
|
+
logger.debug(`Service '${key}' already registered, overwriting`);
|
|
126
|
+
}
|
|
127
|
+
this.services.set(key, service);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Retrieve a registered service singleton.
|
|
131
|
+
* Returns undefined if the service is not registered yet.
|
|
132
|
+
*/
|
|
133
|
+
getService(key) {
|
|
134
|
+
return this.services.get(key);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Retrieve a registered service or throw a descriptive error.
|
|
138
|
+
* Use in code that requires a specific backend to be registered.
|
|
139
|
+
*/
|
|
140
|
+
requireService(key, packageHint) {
|
|
141
|
+
const service = this.services.get(key);
|
|
142
|
+
if (!service) {
|
|
143
|
+
const hint = packageHint ?? (key === ServiceKey.STT || key === ServiceKey.TTS || key === ServiceKey.VAD
|
|
144
|
+
? '@runanywhere/web-onnx'
|
|
145
|
+
: '@runanywhere/web-llamacpp');
|
|
146
|
+
throw new Error(`Service '${key}' not available. Install and register the ${hint} package.`);
|
|
147
|
+
}
|
|
148
|
+
return service;
|
|
149
|
+
}
|
|
150
|
+
/** Remove a registered service. */
|
|
151
|
+
removeService(key) {
|
|
152
|
+
this.services.delete(key);
|
|
153
|
+
}
|
|
95
154
|
/**
|
|
96
155
|
* Cleanup all registered backends in reverse registration order.
|
|
97
156
|
* Called during SDK shutdown.
|
|
@@ -112,6 +171,7 @@ class ExtensionPointImpl {
|
|
|
112
171
|
reset() {
|
|
113
172
|
this.backends.clear();
|
|
114
173
|
this.capabilityMap.clear();
|
|
174
|
+
this.services.clear();
|
|
115
175
|
}
|
|
116
176
|
}
|
|
117
177
|
export const ExtensionPoint = new ExtensionPointImpl();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExtensionPoint.js","sourceRoot":"","sources":["../../src/Infrastructure/ExtensionPoint.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,gBAAgB,CAAC,CAAC;AAE/C,8EAA8E;AAC9E,QAAQ;AACR,8EAA8E;AAE9E,+CAA+C;AAC/C,MAAM,CAAN,IAAY,iBAUX;AAVD,WAAY,iBAAiB;IAC3B,gCAAW,CAAA;IACX,gCAAW,CAAA;IACX,gCAAW,CAAA;IACX,gCAAW,CAAA;IACX,gCAAW,CAAA;IACX,8CAAyB,CAAA;IACzB,4CAAuB,CAAA;IACvB,gDAA2B,CAAA;IAC3B,0DAAqC,CAAA;AACvC,CAAC,EAVW,iBAAiB,KAAjB,iBAAiB,QAU5B;AAoBD,8EAA8E;AAC9E,2BAA2B;AAC3B,8EAA8E;AAE9E,MAAM,kBAAkB;IACd,QAAQ,GAAkC,IAAI,GAAG,EAAE,CAAC;IACpD,aAAa,GAA6C,IAAI,GAAG,EAAE,CAAC;
|
|
1
|
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