@omote/core 0.1.2 → 0.1.3
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/index.js +58 -65
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -59
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2137,13 +2137,13 @@ async function isWebGPUAvailable() {
|
|
|
2137
2137
|
return false;
|
|
2138
2138
|
}
|
|
2139
2139
|
}
|
|
2140
|
-
function configureWasm(
|
|
2141
|
-
|
|
2140
|
+
function configureWasm(ort) {
|
|
2141
|
+
ort.env.wasm.wasmPaths = WASM_CDN_PATH;
|
|
2142
2142
|
const numThreads = getOptimalWasmThreads();
|
|
2143
2143
|
const enableProxy = shouldEnableWasmProxy();
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2144
|
+
ort.env.wasm.numThreads = numThreads;
|
|
2145
|
+
ort.env.wasm.simd = true;
|
|
2146
|
+
ort.env.wasm.proxy = enableProxy;
|
|
2147
2147
|
logger.info("WASM configured", {
|
|
2148
2148
|
numThreads,
|
|
2149
2149
|
simd: true,
|
|
@@ -2191,8 +2191,8 @@ async function getOnnxRuntimeForPreference(preference = "auto") {
|
|
|
2191
2191
|
webgpuAvailable,
|
|
2192
2192
|
resolvedBackend: backend
|
|
2193
2193
|
});
|
|
2194
|
-
const
|
|
2195
|
-
return { ort
|
|
2194
|
+
const ort = await getOnnxRuntime(backend);
|
|
2195
|
+
return { ort, backend };
|
|
2196
2196
|
}
|
|
2197
2197
|
function getSessionOptions(backend) {
|
|
2198
2198
|
if (backend === "webgpu") {
|
|
@@ -2213,12 +2213,12 @@ function getSessionOptions(backend) {
|
|
|
2213
2213
|
};
|
|
2214
2214
|
}
|
|
2215
2215
|
async function createSessionWithFallback(modelBuffer, preferredBackend) {
|
|
2216
|
-
const
|
|
2216
|
+
const ort = await getOnnxRuntime(preferredBackend);
|
|
2217
2217
|
const modelData = new Uint8Array(modelBuffer);
|
|
2218
2218
|
if (preferredBackend === "webgpu") {
|
|
2219
2219
|
try {
|
|
2220
2220
|
const options2 = getSessionOptions("webgpu");
|
|
2221
|
-
const session2 = await
|
|
2221
|
+
const session2 = await ort.InferenceSession.create(modelData, options2);
|
|
2222
2222
|
logger.info("Session created with WebGPU backend");
|
|
2223
2223
|
return { session: session2, backend: "webgpu" };
|
|
2224
2224
|
} catch (err) {
|
|
@@ -2228,7 +2228,7 @@ async function createSessionWithFallback(modelBuffer, preferredBackend) {
|
|
|
2228
2228
|
}
|
|
2229
2229
|
}
|
|
2230
2230
|
const options = getSessionOptions("wasm");
|
|
2231
|
-
const session = await
|
|
2231
|
+
const session = await ort.InferenceSession.create(modelData, options);
|
|
2232
2232
|
logger.info("Session created with WASM backend");
|
|
2233
2233
|
return { session, backend: "wasm" };
|
|
2234
2234
|
}
|
|
@@ -2400,8 +2400,8 @@ var Wav2Vec2Inference = class {
|
|
|
2400
2400
|
});
|
|
2401
2401
|
try {
|
|
2402
2402
|
logger2.info("Loading ONNX Runtime...", { preference: this.config.backend || "auto" });
|
|
2403
|
-
const { ort
|
|
2404
|
-
this.ort =
|
|
2403
|
+
const { ort, backend } = await getOnnxRuntimeForPreference(this.config.backend || "auto");
|
|
2404
|
+
this.ort = ort;
|
|
2405
2405
|
this._backend = backend;
|
|
2406
2406
|
logger2.info("ONNX Runtime loaded", { backend: this._backend });
|
|
2407
2407
|
const cache = getModelCache();
|
|
@@ -3042,8 +3042,8 @@ var SileroVADInference = class {
|
|
|
3042
3042
|
});
|
|
3043
3043
|
try {
|
|
3044
3044
|
logger5.info("Loading ONNX Runtime...", { preference: this.config.backend });
|
|
3045
|
-
const { ort
|
|
3046
|
-
this.ort =
|
|
3045
|
+
const { ort, backend } = await getOnnxRuntimeForPreference(this.config.backend);
|
|
3046
|
+
this.ort = ort;
|
|
3047
3047
|
this._backend = backend;
|
|
3048
3048
|
logger5.info("ONNX Runtime loaded", { backend: this._backend });
|
|
3049
3049
|
const cache = getModelCache();
|
|
@@ -3063,7 +3063,7 @@ var SileroVADInference = class {
|
|
|
3063
3063
|
});
|
|
3064
3064
|
const sessionOptions = getSessionOptions(this._backend);
|
|
3065
3065
|
const modelData = new Uint8Array(modelBuffer);
|
|
3066
|
-
this.session = await
|
|
3066
|
+
this.session = await ort.InferenceSession.create(modelData, sessionOptions);
|
|
3067
3067
|
this.reset();
|
|
3068
3068
|
const loadTimeMs = performance.now() - startTime;
|
|
3069
3069
|
logger5.info("Model loaded successfully", {
|
|
@@ -4032,8 +4032,8 @@ var Emotion2VecInference = class {
|
|
|
4032
4032
|
});
|
|
4033
4033
|
try {
|
|
4034
4034
|
logger8.info("Loading ONNX Runtime...", { preference: this.config.backend });
|
|
4035
|
-
const { ort
|
|
4036
|
-
this.ort =
|
|
4035
|
+
const { ort, backend } = await getOnnxRuntimeForPreference(this.config.backend);
|
|
4036
|
+
this.ort = ort;
|
|
4037
4037
|
this._backend = backend;
|
|
4038
4038
|
logger8.info("ONNX Runtime loaded", { backend: this._backend });
|
|
4039
4039
|
logger8.info("Checking model cache...");
|
|
@@ -4058,7 +4058,7 @@ var Emotion2VecInference = class {
|
|
|
4058
4058
|
});
|
|
4059
4059
|
const sessionOptions = getSessionOptions(this._backend);
|
|
4060
4060
|
const modelData = new Uint8Array(modelBuffer);
|
|
4061
|
-
this.session = await
|
|
4061
|
+
this.session = await ort.InferenceSession.create(modelData, sessionOptions);
|
|
4062
4062
|
const loadTimeMs = performance.now() - startTime;
|
|
4063
4063
|
logger8.info("Model loaded successfully", {
|
|
4064
4064
|
backend: this._backend,
|
|
@@ -4248,14 +4248,8 @@ var Emotion2VecInference = class {
|
|
|
4248
4248
|
*/
|
|
4249
4249
|
Emotion2VecInference.isWebGPUAvailable = isWebGPUAvailable;
|
|
4250
4250
|
|
|
4251
|
-
// src/inference/ChatterboxTurboInference.ts
|
|
4252
|
-
import ort from "onnxruntime-web/webgpu";
|
|
4253
|
-
var logger9 = createLogger("ChatterboxTurbo");
|
|
4254
|
-
env.allowLocalModels = true;
|
|
4255
|
-
ort.env.wasm.wasmPaths = "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.23.2/dist/";
|
|
4256
|
-
|
|
4257
4251
|
// src/inference/SafariSpeechRecognition.ts
|
|
4258
|
-
var
|
|
4252
|
+
var logger9 = createLogger("SafariSpeech");
|
|
4259
4253
|
var SafariSpeechRecognition = class _SafariSpeechRecognition {
|
|
4260
4254
|
constructor(config = {}) {
|
|
4261
4255
|
this.recognition = null;
|
|
@@ -4274,7 +4268,7 @@ var SafariSpeechRecognition = class _SafariSpeechRecognition {
|
|
|
4274
4268
|
interimResults: config.interimResults ?? true,
|
|
4275
4269
|
maxAlternatives: config.maxAlternatives ?? 1
|
|
4276
4270
|
};
|
|
4277
|
-
|
|
4271
|
+
logger9.debug("SafariSpeechRecognition created", {
|
|
4278
4272
|
language: this.config.language,
|
|
4279
4273
|
continuous: this.config.continuous
|
|
4280
4274
|
});
|
|
@@ -4335,7 +4329,7 @@ var SafariSpeechRecognition = class _SafariSpeechRecognition {
|
|
|
4335
4329
|
*/
|
|
4336
4330
|
async start() {
|
|
4337
4331
|
if (this.isListening) {
|
|
4338
|
-
|
|
4332
|
+
logger9.warn("Already listening");
|
|
4339
4333
|
return;
|
|
4340
4334
|
}
|
|
4341
4335
|
if (!_SafariSpeechRecognition.isAvailable()) {
|
|
@@ -4365,7 +4359,7 @@ var SafariSpeechRecognition = class _SafariSpeechRecognition {
|
|
|
4365
4359
|
this.isListening = true;
|
|
4366
4360
|
this.startTime = performance.now();
|
|
4367
4361
|
this.accumulatedText = "";
|
|
4368
|
-
|
|
4362
|
+
logger9.info("Speech recognition started", {
|
|
4369
4363
|
language: this.config.language
|
|
4370
4364
|
});
|
|
4371
4365
|
span?.end();
|
|
@@ -4380,7 +4374,7 @@ var SafariSpeechRecognition = class _SafariSpeechRecognition {
|
|
|
4380
4374
|
*/
|
|
4381
4375
|
async stop() {
|
|
4382
4376
|
if (!this.isListening || !this.recognition) {
|
|
4383
|
-
|
|
4377
|
+
logger9.warn("Not currently listening");
|
|
4384
4378
|
return {
|
|
4385
4379
|
text: this.accumulatedText,
|
|
4386
4380
|
language: this.config.language,
|
|
@@ -4409,7 +4403,7 @@ var SafariSpeechRecognition = class _SafariSpeechRecognition {
|
|
|
4409
4403
|
if (this.recognition && this.isListening) {
|
|
4410
4404
|
this.recognition.abort();
|
|
4411
4405
|
this.isListening = false;
|
|
4412
|
-
|
|
4406
|
+
logger9.info("Speech recognition aborted");
|
|
4413
4407
|
}
|
|
4414
4408
|
}
|
|
4415
4409
|
/**
|
|
@@ -4440,7 +4434,7 @@ var SafariSpeechRecognition = class _SafariSpeechRecognition {
|
|
|
4440
4434
|
this.isListening = false;
|
|
4441
4435
|
this.resultCallbacks = [];
|
|
4442
4436
|
this.errorCallbacks = [];
|
|
4443
|
-
|
|
4437
|
+
logger9.debug("SafariSpeechRecognition disposed");
|
|
4444
4438
|
}
|
|
4445
4439
|
/**
|
|
4446
4440
|
* Set up event handlers for the recognition instance
|
|
@@ -4468,7 +4462,7 @@ var SafariSpeechRecognition = class _SafariSpeechRecognition {
|
|
|
4468
4462
|
confidence: alternative.confidence
|
|
4469
4463
|
};
|
|
4470
4464
|
this.emitResult(speechResult);
|
|
4471
|
-
|
|
4465
|
+
logger9.trace("Speech result", {
|
|
4472
4466
|
text: text.substring(0, 50),
|
|
4473
4467
|
isFinal,
|
|
4474
4468
|
confidence: alternative.confidence
|
|
@@ -4478,12 +4472,12 @@ var SafariSpeechRecognition = class _SafariSpeechRecognition {
|
|
|
4478
4472
|
span?.end();
|
|
4479
4473
|
} catch (error) {
|
|
4480
4474
|
span?.endWithError(error instanceof Error ? error : new Error(String(error)));
|
|
4481
|
-
|
|
4475
|
+
logger9.error("Error processing speech result", { error });
|
|
4482
4476
|
}
|
|
4483
4477
|
};
|
|
4484
4478
|
this.recognition.onerror = (event) => {
|
|
4485
4479
|
const error = new Error(`Speech recognition error: ${event.error} - ${event.message}`);
|
|
4486
|
-
|
|
4480
|
+
logger9.error("Speech recognition error", { error: event.error, message: event.message });
|
|
4487
4481
|
this.emitError(error);
|
|
4488
4482
|
if (this.stopRejecter) {
|
|
4489
4483
|
this.stopRejecter(error);
|
|
@@ -4493,7 +4487,7 @@ var SafariSpeechRecognition = class _SafariSpeechRecognition {
|
|
|
4493
4487
|
};
|
|
4494
4488
|
this.recognition.onend = () => {
|
|
4495
4489
|
this.isListening = false;
|
|
4496
|
-
|
|
4490
|
+
logger9.info("Speech recognition ended", {
|
|
4497
4491
|
totalText: this.accumulatedText.length,
|
|
4498
4492
|
durationMs: performance.now() - this.startTime
|
|
4499
4493
|
});
|
|
@@ -4510,13 +4504,13 @@ var SafariSpeechRecognition = class _SafariSpeechRecognition {
|
|
|
4510
4504
|
}
|
|
4511
4505
|
};
|
|
4512
4506
|
this.recognition.onstart = () => {
|
|
4513
|
-
|
|
4507
|
+
logger9.debug("Speech recognition started by browser");
|
|
4514
4508
|
};
|
|
4515
4509
|
this.recognition.onspeechstart = () => {
|
|
4516
|
-
|
|
4510
|
+
logger9.debug("Speech detected");
|
|
4517
4511
|
};
|
|
4518
4512
|
this.recognition.onspeechend = () => {
|
|
4519
|
-
|
|
4513
|
+
logger9.debug("Speech ended");
|
|
4520
4514
|
};
|
|
4521
4515
|
}
|
|
4522
4516
|
/**
|
|
@@ -4527,7 +4521,7 @@ var SafariSpeechRecognition = class _SafariSpeechRecognition {
|
|
|
4527
4521
|
try {
|
|
4528
4522
|
callback(result);
|
|
4529
4523
|
} catch (error) {
|
|
4530
|
-
|
|
4524
|
+
logger9.error("Error in result callback", { error });
|
|
4531
4525
|
}
|
|
4532
4526
|
}
|
|
4533
4527
|
}
|
|
@@ -4539,7 +4533,7 @@ var SafariSpeechRecognition = class _SafariSpeechRecognition {
|
|
|
4539
4533
|
try {
|
|
4540
4534
|
callback(error);
|
|
4541
4535
|
} catch (callbackError) {
|
|
4542
|
-
|
|
4536
|
+
logger9.error("Error in error callback", { error: callbackError });
|
|
4543
4537
|
}
|
|
4544
4538
|
}
|
|
4545
4539
|
}
|
|
@@ -5962,12 +5956,12 @@ async function isHuggingFaceCDNReachable(testUrl = HF_CDN_TEST_URL) {
|
|
|
5962
5956
|
}
|
|
5963
5957
|
|
|
5964
5958
|
// src/utils/transformersCacheClear.ts
|
|
5965
|
-
var
|
|
5959
|
+
var logger10 = createLogger("TransformersCache");
|
|
5966
5960
|
async function clearTransformersCache(options) {
|
|
5967
5961
|
const verbose = options?.verbose ?? true;
|
|
5968
5962
|
const additionalPatterns = options?.additionalPatterns ?? [];
|
|
5969
5963
|
if (!("caches" in window)) {
|
|
5970
|
-
|
|
5964
|
+
logger10.warn("Cache API not available in this environment");
|
|
5971
5965
|
return [];
|
|
5972
5966
|
}
|
|
5973
5967
|
try {
|
|
@@ -5985,18 +5979,18 @@ async function clearTransformersCache(options) {
|
|
|
5985
5979
|
);
|
|
5986
5980
|
if (shouldDelete) {
|
|
5987
5981
|
if (verbose) {
|
|
5988
|
-
|
|
5982
|
+
logger10.info("Deleting cache", { cacheName });
|
|
5989
5983
|
}
|
|
5990
5984
|
const deleted = await caches.delete(cacheName);
|
|
5991
5985
|
if (deleted) {
|
|
5992
5986
|
deletedCaches.push(cacheName);
|
|
5993
5987
|
} else if (verbose) {
|
|
5994
|
-
|
|
5988
|
+
logger10.warn("Failed to delete cache", { cacheName });
|
|
5995
5989
|
}
|
|
5996
5990
|
}
|
|
5997
5991
|
}
|
|
5998
5992
|
if (verbose) {
|
|
5999
|
-
|
|
5993
|
+
logger10.info("Cache clearing complete", {
|
|
6000
5994
|
totalCaches: cacheNames.length,
|
|
6001
5995
|
deletedCount: deletedCaches.length,
|
|
6002
5996
|
deletedCaches
|
|
@@ -6004,35 +5998,35 @@ async function clearTransformersCache(options) {
|
|
|
6004
5998
|
}
|
|
6005
5999
|
return deletedCaches;
|
|
6006
6000
|
} catch (error) {
|
|
6007
|
-
|
|
6001
|
+
logger10.error("Error clearing caches", { error });
|
|
6008
6002
|
throw error;
|
|
6009
6003
|
}
|
|
6010
6004
|
}
|
|
6011
6005
|
async function clearSpecificCache(cacheName) {
|
|
6012
6006
|
if (!("caches" in window)) {
|
|
6013
|
-
|
|
6007
|
+
logger10.warn("Cache API not available in this environment");
|
|
6014
6008
|
return false;
|
|
6015
6009
|
}
|
|
6016
6010
|
try {
|
|
6017
6011
|
const deleted = await caches.delete(cacheName);
|
|
6018
|
-
|
|
6012
|
+
logger10.info("Cache deletion attempt", { cacheName, deleted });
|
|
6019
6013
|
return deleted;
|
|
6020
6014
|
} catch (error) {
|
|
6021
|
-
|
|
6015
|
+
logger10.error("Error deleting cache", { cacheName, error });
|
|
6022
6016
|
return false;
|
|
6023
6017
|
}
|
|
6024
6018
|
}
|
|
6025
6019
|
async function listCaches() {
|
|
6026
6020
|
if (!("caches" in window)) {
|
|
6027
|
-
|
|
6021
|
+
logger10.warn("Cache API not available in this environment");
|
|
6028
6022
|
return [];
|
|
6029
6023
|
}
|
|
6030
6024
|
try {
|
|
6031
6025
|
const cacheNames = await caches.keys();
|
|
6032
|
-
|
|
6026
|
+
logger10.debug("Available caches", { cacheNames });
|
|
6033
6027
|
return cacheNames;
|
|
6034
6028
|
} catch (error) {
|
|
6035
|
-
|
|
6029
|
+
logger10.error("Error listing caches", { error });
|
|
6036
6030
|
return [];
|
|
6037
6031
|
}
|
|
6038
6032
|
}
|
|
@@ -6074,7 +6068,7 @@ async function validateCachedResponse(cacheName, requestUrl) {
|
|
|
6074
6068
|
reason: valid ? "Valid response" : `Invalid: status=${response.status}, contentType=${contentType}, isHtml=${isHtml || looksLikeHtml}`
|
|
6075
6069
|
};
|
|
6076
6070
|
} catch (error) {
|
|
6077
|
-
|
|
6071
|
+
logger10.error("Error validating cached response", { cacheName, requestUrl, error });
|
|
6078
6072
|
return {
|
|
6079
6073
|
exists: false,
|
|
6080
6074
|
valid: false,
|
|
@@ -6111,7 +6105,7 @@ async function scanForInvalidCaches() {
|
|
|
6111
6105
|
}
|
|
6112
6106
|
}
|
|
6113
6107
|
}
|
|
6114
|
-
|
|
6108
|
+
logger10.info("Cache scan complete", {
|
|
6115
6109
|
totalCaches: cacheNames.length,
|
|
6116
6110
|
scannedEntries,
|
|
6117
6111
|
invalidCount: invalidEntries.length
|
|
@@ -6122,13 +6116,13 @@ async function scanForInvalidCaches() {
|
|
|
6122
6116
|
invalidEntries
|
|
6123
6117
|
};
|
|
6124
6118
|
} catch (error) {
|
|
6125
|
-
|
|
6119
|
+
logger10.error("Error scanning caches", { error });
|
|
6126
6120
|
throw error;
|
|
6127
6121
|
}
|
|
6128
6122
|
}
|
|
6129
6123
|
async function nukeBrowserCaches(preventRecreation = false) {
|
|
6130
6124
|
if (!("caches" in window)) {
|
|
6131
|
-
|
|
6125
|
+
logger10.warn("Cache API not available in this environment");
|
|
6132
6126
|
return 0;
|
|
6133
6127
|
}
|
|
6134
6128
|
try {
|
|
@@ -6140,17 +6134,17 @@ async function nukeBrowserCaches(preventRecreation = false) {
|
|
|
6140
6134
|
deletedCount++;
|
|
6141
6135
|
}
|
|
6142
6136
|
}
|
|
6143
|
-
|
|
6137
|
+
logger10.info("All browser caches cleared", {
|
|
6144
6138
|
totalDeleted: deletedCount
|
|
6145
6139
|
});
|
|
6146
6140
|
if (preventRecreation) {
|
|
6147
6141
|
const { env: env2 } = await import("./transformers.web-ALDLCPHT.mjs");
|
|
6148
6142
|
env2.useBrowserCache = false;
|
|
6149
|
-
|
|
6143
|
+
logger10.warn("Browser cache creation disabled (env.useBrowserCache = false)");
|
|
6150
6144
|
}
|
|
6151
6145
|
return deletedCount;
|
|
6152
6146
|
} catch (error) {
|
|
6153
|
-
|
|
6147
|
+
logger10.error("Error nuking caches", { error });
|
|
6154
6148
|
throw error;
|
|
6155
6149
|
}
|
|
6156
6150
|
}
|