@omote/core 0.7.1 → 0.9.2
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 +12 -10
- package/dist/ErrorCodes-AX3ADZri.d.mts +266 -0
- package/dist/ErrorCodes-AX3ADZri.d.ts +266 -0
- package/dist/Logger-BeUI6jG7.d.mts +145 -0
- package/dist/Logger-BeUI6jG7.d.ts +145 -0
- package/dist/chunk-3NDJA3I4.mjs +853 -0
- package/dist/chunk-3NDJA3I4.mjs.map +1 -0
- package/dist/chunk-CYBTTLG7.mjs +927 -0
- package/dist/chunk-CYBTTLG7.mjs.map +1 -0
- package/dist/chunk-J5LAM7VW.mjs +44 -0
- package/dist/chunk-J5LAM7VW.mjs.map +1 -0
- package/dist/chunk-MXKJOF4I.mjs +38 -0
- package/dist/chunk-MXKJOF4I.mjs.map +1 -0
- package/dist/chunk-X5OTUOE6.mjs +927 -0
- package/dist/chunk-X5OTUOE6.mjs.map +1 -0
- package/dist/chunk-Y3DTP5P3.mjs +927 -0
- package/dist/chunk-Y3DTP5P3.mjs.map +1 -0
- package/dist/events/index.d.mts +2 -87
- package/dist/events/index.d.ts +2 -87
- package/dist/events/index.js +8 -2
- package/dist/events/index.js.map +1 -1
- package/dist/events/index.mjs +1 -1
- package/dist/index.d.mts +1474 -1230
- package/dist/index.d.ts +1474 -1230
- package/dist/index.js +10548 -9785
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9197 -9063
- package/dist/index.mjs.map +1 -1
- package/dist/logging/index.d.mts +2 -2
- package/dist/logging/index.d.ts +2 -2
- package/dist/logging/index.js +86 -1
- package/dist/logging/index.js.map +1 -1
- package/dist/logging/index.mjs +9 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -4,14 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- **Lip Sync (A2E)** — Audio to 52 ARKit blendshapes via
|
|
7
|
+
- **Lip Sync (A2E)** — Audio to 52 ARKit blendshapes via LAM, with automatic WebGPU/WASM platform detection
|
|
8
8
|
- **PlaybackPipeline** — TTS audio playback to lip sync with ExpressionProfile scaling, gapless scheduling
|
|
9
9
|
- **Speech Recognition** — SenseVoice ASR (ONNX), 15x faster than Whisper, progressive transcription
|
|
10
10
|
- **Voice Activity Detection** — Silero VAD with Worker and main-thread modes
|
|
11
|
-
- **Text-to-Speech** — Kokoro TTS (82M q8,
|
|
11
|
+
- **Text-to-Speech** — Kokoro TTS (82M q8, offline) with TTSBackend interface for custom engines
|
|
12
12
|
- **CharacterController** — Renderer-agnostic avatar composition (compositor + gaze + life layer)
|
|
13
13
|
- **TTSPlayback** — Composes TTSBackend + PlaybackPipeline for text → lip sync
|
|
14
|
+
- **TTSSpeaker** — High-level speak(text) with abort, queueing, and LLM streaming
|
|
15
|
+
- **SpeechListener** — Mic → VAD → ASR orchestration with adaptive silence detection
|
|
16
|
+
- **createTTSPlayer()** — Factory composing Kokoro TTS + TTSSpeaker for zero-config playback
|
|
14
17
|
- **VoicePipeline** — Full conversational agent loop with local TTS support (cloud or offline)
|
|
18
|
+
- **configureOrtCdn()** — Enterprise CDN override for ORT WASM/WebGPU binaries
|
|
15
19
|
- **Animation Graph** — State machine (idle/listening/thinking/speaking) with emotion blending
|
|
16
20
|
- **Emotion Controller** — Preset-based emotion system with smooth transitions
|
|
17
21
|
- **Model Caching** — IndexedDB with versioning, LRU eviction, and quota monitoring
|
|
@@ -70,7 +74,7 @@ Auto-detects platform: Chrome/Edge/Android use WebGPU, Safari/iOS use WASM CPU f
|
|
|
70
74
|
```typescript
|
|
71
75
|
import { createA2E } from '@omote/core';
|
|
72
76
|
|
|
73
|
-
const a2e = createA2E(); // auto-detects:
|
|
77
|
+
const a2e = createA2E(); // auto-detects: WebGPU on Chrome/Edge, WASM on Safari/iOS/Firefox
|
|
74
78
|
await a2e.load();
|
|
75
79
|
|
|
76
80
|
const { blendshapes } = await a2e.infer(audioSamples); // Float32Array (16kHz)
|
|
@@ -80,13 +84,13 @@ const { blendshapes } = await a2e.infer(audioSamples); // Float32Array (16kHz)
|
|
|
80
84
|
#### Direct API
|
|
81
85
|
|
|
82
86
|
```typescript
|
|
83
|
-
import {
|
|
87
|
+
import { A2EInference, ARKIT_BLENDSHAPES } from '@omote/core';
|
|
84
88
|
|
|
85
|
-
const lam = new
|
|
89
|
+
const lam = new A2EInference({ modelUrl: '/models/model_fp16.onnx' });
|
|
86
90
|
await lam.load();
|
|
87
91
|
|
|
88
92
|
const { blendshapes } = await lam.infer(audioSamples);
|
|
89
|
-
const jawOpen = blendshapes[
|
|
93
|
+
const jawOpen = blendshapes[ARKIT_BLENDSHAPES.indexOf('jawOpen')];
|
|
90
94
|
```
|
|
91
95
|
|
|
92
96
|
### PlaybackPipeline
|
|
@@ -310,8 +314,6 @@ Place models in your public assets directory:
|
|
|
310
314
|
```
|
|
311
315
|
public/models/
|
|
312
316
|
model_fp16.onnx # A2E lip sync — WebGPU (192MB fp16, from omote-ai/lam-a2e)
|
|
313
|
-
wav2arkit_cpu.onnx # A2E lip sync — WASM fallback (1.86MB graph)
|
|
314
|
-
wav2arkit_cpu.onnx.data # A2E lip sync — WASM fallback (402MB weights)
|
|
315
317
|
sensevoice/model.int8.onnx # SenseVoice ASR (239MB)
|
|
316
318
|
silero-vad.onnx # Voice activity detection (~2MB)
|
|
317
319
|
```
|
|
@@ -339,7 +341,7 @@ const webgpu = await isWebGPUAvailable();
|
|
|
339
341
|
All iOS browsers use WebKit under the hood. The SDK handles three platform constraints automatically:
|
|
340
342
|
|
|
341
343
|
1. **WASM binary selection** — iOS crashes with the default JSEP/ASYNCIFY WASM binary. The SDK imports `onnxruntime-web/wasm` (non-JSEP) on iOS/Safari.
|
|
342
|
-
2. **A2E model
|
|
344
|
+
2. **A2E model routing** — `createA2E()` routes all platforms through `A2EInference` via `UnifiedInferenceWorker`. WebGPU on Chrome/Edge, WASM on Safari/iOS/Firefox.
|
|
343
345
|
3. **Worker memory** — Multiple Workers each load their own ORT WASM runtime, exceeding iOS tab memory (~1.5GB). The SDK defaults to main-thread inference on iOS.
|
|
344
346
|
|
|
345
347
|
**Consumer requirement:** COEP/COOP headers must be skipped for iOS to avoid triggering SharedArrayBuffer (which forces threaded WASM with 4GB shared memory — crashes iOS). Desktop should keep COEP/COOP for multi-threaded performance.
|
|
@@ -348,7 +350,7 @@ All iOS browsers use WebKit under the hood. The SDK handles three platform const
|
|
|
348
350
|
|---------|------------|-------|
|
|
349
351
|
| Silero VAD | Works | 0.9ms latency |
|
|
350
352
|
| SenseVoice ASR | Works | WASM, ~200ms |
|
|
351
|
-
| A2E Lip Sync | Works |
|
|
353
|
+
| A2E Lip Sync | Works | A2EInference (WASM) via createA2E(), ~45ms |
|
|
352
354
|
|
|
353
355
|
## License
|
|
354
356
|
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logging types for Omote SDK
|
|
3
|
+
*
|
|
4
|
+
* 6-level logging system with structured output:
|
|
5
|
+
* - error: Critical failures that prevent operation
|
|
6
|
+
* - warn: Recoverable issues or degraded performance
|
|
7
|
+
* - info: Key lifecycle events (model loaded, inference complete)
|
|
8
|
+
* - debug: Detailed operational info for development
|
|
9
|
+
* - trace: Fine-grained tracing for performance analysis
|
|
10
|
+
* - verbose: Extremely detailed output (tensor shapes, intermediate values)
|
|
11
|
+
*/
|
|
12
|
+
type LogLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'verbose';
|
|
13
|
+
/**
|
|
14
|
+
* Numeric priority for log levels (lower = more severe)
|
|
15
|
+
*/
|
|
16
|
+
declare const LOG_LEVEL_PRIORITY: Record<LogLevel, number>;
|
|
17
|
+
/**
|
|
18
|
+
* Structured log entry
|
|
19
|
+
*/
|
|
20
|
+
interface LogEntry {
|
|
21
|
+
/** Unix timestamp in milliseconds */
|
|
22
|
+
timestamp: number;
|
|
23
|
+
/** Log level */
|
|
24
|
+
level: LogLevel;
|
|
25
|
+
/** Module name (e.g., 'LocalInference', 'ModelCache') */
|
|
26
|
+
module: string;
|
|
27
|
+
/** Human-readable message */
|
|
28
|
+
message: string;
|
|
29
|
+
/** Optional structured error code from ErrorCodes (e.g., 'OMOTE_INF_001') */
|
|
30
|
+
code?: string;
|
|
31
|
+
/** Optional structured data */
|
|
32
|
+
data?: Record<string, unknown>;
|
|
33
|
+
/** Optional error object */
|
|
34
|
+
error?: Error;
|
|
35
|
+
/** Trace ID from active telemetry span (log-to-span correlation) */
|
|
36
|
+
traceId?: string;
|
|
37
|
+
/** Span ID from active telemetry span (log-to-span correlation) */
|
|
38
|
+
spanId?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Log output sink interface.
|
|
42
|
+
*
|
|
43
|
+
* **Portability contract**: Replace the default console sink to route logs to
|
|
44
|
+
* any backend — Node.js winston/pino, Unreal UE_LOG, Unity Debug.Log, or a
|
|
45
|
+
* remote telemetry service. Register via `configureLogging({ sink: mySink })`.
|
|
46
|
+
*/
|
|
47
|
+
interface LogSink {
|
|
48
|
+
(entry: LogEntry): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Log formatter interface
|
|
52
|
+
*/
|
|
53
|
+
interface LogFormatter {
|
|
54
|
+
(entry: LogEntry): string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Global logging configuration
|
|
58
|
+
*/
|
|
59
|
+
interface LoggingConfig {
|
|
60
|
+
/** Minimum log level to output (default: 'info') */
|
|
61
|
+
level: LogLevel;
|
|
62
|
+
/** Enable/disable logging globally (default: true) */
|
|
63
|
+
enabled: boolean;
|
|
64
|
+
/** Output format: 'json' for structured, 'pretty' for human-readable */
|
|
65
|
+
format: 'json' | 'pretty';
|
|
66
|
+
/** Custom output sink (default: console) */
|
|
67
|
+
sink?: LogSink;
|
|
68
|
+
/** Include timestamps in output (default: true) */
|
|
69
|
+
timestamps?: boolean;
|
|
70
|
+
/** Include module name in output (default: true) */
|
|
71
|
+
includeModule?: boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Logger interface for module-specific logging.
|
|
75
|
+
*
|
|
76
|
+
* **Portability contract**: All SDK modules depend only on this interface.
|
|
77
|
+
* To integrate with a non-browser runtime (Node.js, Unreal, Unity), either:
|
|
78
|
+
* 1. Use the built-in Logger with a custom `LogSink`, or
|
|
79
|
+
* 2. Provide your own `ILogger` implementation that bridges to the host
|
|
80
|
+
* runtime's logging system (e.g., `console.log`, `UE_LOG`, `Debug.Log`).
|
|
81
|
+
*/
|
|
82
|
+
interface ILogger {
|
|
83
|
+
error(message: string, data?: Record<string, unknown>): void;
|
|
84
|
+
warn(message: string, data?: Record<string, unknown>): void;
|
|
85
|
+
info(message: string, data?: Record<string, unknown>): void;
|
|
86
|
+
debug(message: string, data?: Record<string, unknown>): void;
|
|
87
|
+
trace(message: string, data?: Record<string, unknown>): void;
|
|
88
|
+
verbose(message: string, data?: Record<string, unknown>): void;
|
|
89
|
+
/** Create a child logger with a sub-module name */
|
|
90
|
+
child(subModule: string): ILogger;
|
|
91
|
+
/** Get the module name for this logger */
|
|
92
|
+
readonly module: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Default configuration
|
|
96
|
+
*/
|
|
97
|
+
declare const DEFAULT_LOGGING_CONFIG: LoggingConfig;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Omote SDK Logger
|
|
101
|
+
*
|
|
102
|
+
* Unified logging system with:
|
|
103
|
+
* - 6 log levels (error, warn, info, debug, trace, verbose)
|
|
104
|
+
* - Structured JSON output for machine parsing
|
|
105
|
+
* - Pretty output for human readability
|
|
106
|
+
* - Module-based child loggers
|
|
107
|
+
* - Runtime configuration
|
|
108
|
+
* - Browser and Node.js compatible
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Configure global logging settings
|
|
113
|
+
*/
|
|
114
|
+
declare function configureLogging(config: Partial<LoggingConfig>): void;
|
|
115
|
+
/**
|
|
116
|
+
* Get current logging configuration
|
|
117
|
+
*/
|
|
118
|
+
declare function getLoggingConfig(): LoggingConfig;
|
|
119
|
+
/**
|
|
120
|
+
* Reset logging configuration to defaults
|
|
121
|
+
*/
|
|
122
|
+
declare function resetLoggingConfig(): void;
|
|
123
|
+
/**
|
|
124
|
+
* Set log level at runtime
|
|
125
|
+
*/
|
|
126
|
+
declare function setLogLevel(level: LogLevel): void;
|
|
127
|
+
/**
|
|
128
|
+
* Enable or disable logging
|
|
129
|
+
*/
|
|
130
|
+
declare function setLoggingEnabled(enabled: boolean): void;
|
|
131
|
+
/**
|
|
132
|
+
* Create a logger for a specific module
|
|
133
|
+
*
|
|
134
|
+
* @param module - Module name (e.g., 'LocalInference', 'ModelCache')
|
|
135
|
+
* @returns Logger instance
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const logger = createLogger('LocalInference');
|
|
140
|
+
* logger.info('Model loaded', { backend: 'webgpu', loadTimeMs: 1234 });
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
declare function createLogger(module: string): ILogger;
|
|
144
|
+
/**
|
|
145
|
+
* Clear logger cache (useful for testing)
|
|
146
|
+
*/
|
|
147
|
+
declare function clearLoggerCache(): void;
|
|
148
|
+
/**
|
|
149
|
+
* No-op logger for when logging is completely disabled
|
|
150
|
+
*/
|
|
151
|
+
declare const noopLogger: ILogger;
|
|
152
|
+
/**
|
|
153
|
+
* Get a no-op logger (for production builds that tree-shake logging)
|
|
154
|
+
*/
|
|
155
|
+
declare function getNoopLogger(): ILogger;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Abstract monotonic clock for runtime-agnostic timing.
|
|
159
|
+
*
|
|
160
|
+
* **Portability contract**: To port the SDK to Node.js, Python, Unreal, or Unity,
|
|
161
|
+
* implement this interface with your runtime's high-resolution timer and call
|
|
162
|
+
* `configureClock()` at startup.
|
|
163
|
+
*
|
|
164
|
+
* @example Node.js
|
|
165
|
+
* ```typescript
|
|
166
|
+
* import { configureClock } from '@omote/core';
|
|
167
|
+
* configureClock({
|
|
168
|
+
* now: () => Number(process.hrtime.bigint() / 1_000_000n),
|
|
169
|
+
* timestamp: () => Date.now(),
|
|
170
|
+
* });
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @example Unreal Engine (via wasm-bindgen)
|
|
174
|
+
* ```typescript
|
|
175
|
+
* configureClock({
|
|
176
|
+
* now: () => FPlatformTime.Seconds() * 1000,
|
|
177
|
+
* timestamp: () => FDateTime.UtcNow().ToUnixTimestamp() * 1000,
|
|
178
|
+
* });
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* @example Unity (via jslib bridge)
|
|
182
|
+
* ```typescript
|
|
183
|
+
* configureClock({
|
|
184
|
+
* now: () => Time.realtimeSinceStartup * 1000,
|
|
185
|
+
* timestamp: () => Date.now(),
|
|
186
|
+
* });
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
interface Clock {
|
|
190
|
+
/** Monotonic high-resolution milliseconds (for durations, telemetry spans) */
|
|
191
|
+
now(): number;
|
|
192
|
+
/** Wall-clock milliseconds since epoch (for log timestamps) */
|
|
193
|
+
timestamp(): number;
|
|
194
|
+
}
|
|
195
|
+
declare const defaultClock: Clock;
|
|
196
|
+
/** Replace the default browser clock with a custom implementation. */
|
|
197
|
+
declare function configureClock(clock: Clock): void;
|
|
198
|
+
/** Get the active clock instance. */
|
|
199
|
+
declare function getClock(): Clock;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Structured error codes for the Omote SDK.
|
|
203
|
+
*
|
|
204
|
+
* Codes follow the pattern `OMOTE_{CATEGORY}_{SEQ}` where:
|
|
205
|
+
* - **INF** = Inference (model loading, session, OOM)
|
|
206
|
+
* - **AUD** = Audio (AudioContext, scheduling, decoding)
|
|
207
|
+
* - **SPH** = Speech (VAD, ASR, microphone)
|
|
208
|
+
* - **TTS** = Text-to-Speech (synthesis, streaming, phonemizer)
|
|
209
|
+
* - **PIP** = Pipeline (state machine, abort)
|
|
210
|
+
* - **CAC** = Cache (IndexedDB quota, eviction, staleness)
|
|
211
|
+
* - **NET** = Network (fetch, timeout, WebSocket)
|
|
212
|
+
*
|
|
213
|
+
* Exported as a const object (not enum) for tree-shaking.
|
|
214
|
+
*/
|
|
215
|
+
declare const ErrorCodes: {
|
|
216
|
+
/** Model failed to load (file not found, corrupted, unsupported format) */
|
|
217
|
+
readonly INF_LOAD_FAILED: "OMOTE_INF_001";
|
|
218
|
+
/** ORT session poisoned after WebGPU device loss — must reload tab */
|
|
219
|
+
readonly INF_SESSION_POISON: "OMOTE_INF_002";
|
|
220
|
+
/** Inference exceeded timeout threshold */
|
|
221
|
+
readonly INF_TIMEOUT: "OMOTE_INF_003";
|
|
222
|
+
/** Out-of-memory during inference or model loading */
|
|
223
|
+
readonly INF_OOM: "OMOTE_INF_004";
|
|
224
|
+
/** WebGPU unavailable, fell back to WASM */
|
|
225
|
+
readonly INF_WEBGPU_FALLBACK: "OMOTE_INF_005";
|
|
226
|
+
/** Input tensor shape does not match model expectations */
|
|
227
|
+
readonly INF_SHAPE_MISMATCH: "OMOTE_INF_006";
|
|
228
|
+
/** AudioContext creation or resume failed */
|
|
229
|
+
readonly AUD_CONTEXT_FAILED: "OMOTE_AUD_001";
|
|
230
|
+
/** Gap detected in audio scheduling (buffer underrun) */
|
|
231
|
+
readonly AUD_SCHEDULE_GAP: "OMOTE_AUD_002";
|
|
232
|
+
/** Audio buffer decoding failed */
|
|
233
|
+
readonly AUD_DECODE_FAILED: "OMOTE_AUD_003";
|
|
234
|
+
/** Voice activity detection error */
|
|
235
|
+
readonly SPH_VAD_ERROR: "OMOTE_SPH_001";
|
|
236
|
+
/** Automatic speech recognition error */
|
|
237
|
+
readonly SPH_ASR_ERROR: "OMOTE_SPH_002";
|
|
238
|
+
/** Microphone access denied or unavailable */
|
|
239
|
+
readonly SPH_MIC_DENIED: "OMOTE_SPH_003";
|
|
240
|
+
/** TTS synthesis failed */
|
|
241
|
+
readonly TTS_SYNTH_FAILED: "OMOTE_TTS_001";
|
|
242
|
+
/** TTS streaming error (chunk delivery failure) */
|
|
243
|
+
readonly TTS_STREAM_ERROR: "OMOTE_TTS_002";
|
|
244
|
+
/** Phonemizer (eSpeak-NG WASM) ran out of memory */
|
|
245
|
+
readonly TTS_PHONEMIZER_OOM: "OMOTE_TTS_003";
|
|
246
|
+
/** Invalid state transition in pipeline state machine */
|
|
247
|
+
readonly PIP_STATE_ERROR: "OMOTE_PIP_001";
|
|
248
|
+
/** Pipeline operation aborted (user interrupt or signal) */
|
|
249
|
+
readonly PIP_ABORT: "OMOTE_PIP_002";
|
|
250
|
+
/** IndexedDB storage quota exceeded */
|
|
251
|
+
readonly CAC_QUOTA_EXCEEDED: "OMOTE_CAC_001";
|
|
252
|
+
/** Cache entry evicted (LRU or manual) */
|
|
253
|
+
readonly CAC_EVICTION: "OMOTE_CAC_002";
|
|
254
|
+
/** Cached model is stale (version mismatch) */
|
|
255
|
+
readonly CAC_STALE: "OMOTE_CAC_003";
|
|
256
|
+
/** HTTP fetch failed (model download, CDN) */
|
|
257
|
+
readonly NET_FETCH_FAILED: "OMOTE_NET_001";
|
|
258
|
+
/** Network request timed out */
|
|
259
|
+
readonly NET_TIMEOUT: "OMOTE_NET_002";
|
|
260
|
+
/** WebSocket connection error */
|
|
261
|
+
readonly NET_WEBSOCKET_ERROR: "OMOTE_NET_003";
|
|
262
|
+
};
|
|
263
|
+
/** Union type of all error code string values. */
|
|
264
|
+
type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
265
|
+
|
|
266
|
+
export { type Clock as C, DEFAULT_LOGGING_CONFIG as D, type ErrorCode as E, type ILogger as I, type LogFormatter as L, ErrorCodes as a, LOG_LEVEL_PRIORITY as b, type LogEntry as c, type LogLevel as d, type LogSink as e, type LoggingConfig as f, clearLoggerCache as g, configureClock as h, configureLogging as i, createLogger as j, defaultClock as k, getClock as l, getLoggingConfig as m, getNoopLogger as n, noopLogger as o, setLoggingEnabled as p, resetLoggingConfig as r, setLogLevel as s };
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logging types for Omote SDK
|
|
3
|
+
*
|
|
4
|
+
* 6-level logging system with structured output:
|
|
5
|
+
* - error: Critical failures that prevent operation
|
|
6
|
+
* - warn: Recoverable issues or degraded performance
|
|
7
|
+
* - info: Key lifecycle events (model loaded, inference complete)
|
|
8
|
+
* - debug: Detailed operational info for development
|
|
9
|
+
* - trace: Fine-grained tracing for performance analysis
|
|
10
|
+
* - verbose: Extremely detailed output (tensor shapes, intermediate values)
|
|
11
|
+
*/
|
|
12
|
+
type LogLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'verbose';
|
|
13
|
+
/**
|
|
14
|
+
* Numeric priority for log levels (lower = more severe)
|
|
15
|
+
*/
|
|
16
|
+
declare const LOG_LEVEL_PRIORITY: Record<LogLevel, number>;
|
|
17
|
+
/**
|
|
18
|
+
* Structured log entry
|
|
19
|
+
*/
|
|
20
|
+
interface LogEntry {
|
|
21
|
+
/** Unix timestamp in milliseconds */
|
|
22
|
+
timestamp: number;
|
|
23
|
+
/** Log level */
|
|
24
|
+
level: LogLevel;
|
|
25
|
+
/** Module name (e.g., 'LocalInference', 'ModelCache') */
|
|
26
|
+
module: string;
|
|
27
|
+
/** Human-readable message */
|
|
28
|
+
message: string;
|
|
29
|
+
/** Optional structured error code from ErrorCodes (e.g., 'OMOTE_INF_001') */
|
|
30
|
+
code?: string;
|
|
31
|
+
/** Optional structured data */
|
|
32
|
+
data?: Record<string, unknown>;
|
|
33
|
+
/** Optional error object */
|
|
34
|
+
error?: Error;
|
|
35
|
+
/** Trace ID from active telemetry span (log-to-span correlation) */
|
|
36
|
+
traceId?: string;
|
|
37
|
+
/** Span ID from active telemetry span (log-to-span correlation) */
|
|
38
|
+
spanId?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Log output sink interface.
|
|
42
|
+
*
|
|
43
|
+
* **Portability contract**: Replace the default console sink to route logs to
|
|
44
|
+
* any backend — Node.js winston/pino, Unreal UE_LOG, Unity Debug.Log, or a
|
|
45
|
+
* remote telemetry service. Register via `configureLogging({ sink: mySink })`.
|
|
46
|
+
*/
|
|
47
|
+
interface LogSink {
|
|
48
|
+
(entry: LogEntry): void;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Log formatter interface
|
|
52
|
+
*/
|
|
53
|
+
interface LogFormatter {
|
|
54
|
+
(entry: LogEntry): string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Global logging configuration
|
|
58
|
+
*/
|
|
59
|
+
interface LoggingConfig {
|
|
60
|
+
/** Minimum log level to output (default: 'info') */
|
|
61
|
+
level: LogLevel;
|
|
62
|
+
/** Enable/disable logging globally (default: true) */
|
|
63
|
+
enabled: boolean;
|
|
64
|
+
/** Output format: 'json' for structured, 'pretty' for human-readable */
|
|
65
|
+
format: 'json' | 'pretty';
|
|
66
|
+
/** Custom output sink (default: console) */
|
|
67
|
+
sink?: LogSink;
|
|
68
|
+
/** Include timestamps in output (default: true) */
|
|
69
|
+
timestamps?: boolean;
|
|
70
|
+
/** Include module name in output (default: true) */
|
|
71
|
+
includeModule?: boolean;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Logger interface for module-specific logging.
|
|
75
|
+
*
|
|
76
|
+
* **Portability contract**: All SDK modules depend only on this interface.
|
|
77
|
+
* To integrate with a non-browser runtime (Node.js, Unreal, Unity), either:
|
|
78
|
+
* 1. Use the built-in Logger with a custom `LogSink`, or
|
|
79
|
+
* 2. Provide your own `ILogger` implementation that bridges to the host
|
|
80
|
+
* runtime's logging system (e.g., `console.log`, `UE_LOG`, `Debug.Log`).
|
|
81
|
+
*/
|
|
82
|
+
interface ILogger {
|
|
83
|
+
error(message: string, data?: Record<string, unknown>): void;
|
|
84
|
+
warn(message: string, data?: Record<string, unknown>): void;
|
|
85
|
+
info(message: string, data?: Record<string, unknown>): void;
|
|
86
|
+
debug(message: string, data?: Record<string, unknown>): void;
|
|
87
|
+
trace(message: string, data?: Record<string, unknown>): void;
|
|
88
|
+
verbose(message: string, data?: Record<string, unknown>): void;
|
|
89
|
+
/** Create a child logger with a sub-module name */
|
|
90
|
+
child(subModule: string): ILogger;
|
|
91
|
+
/** Get the module name for this logger */
|
|
92
|
+
readonly module: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Default configuration
|
|
96
|
+
*/
|
|
97
|
+
declare const DEFAULT_LOGGING_CONFIG: LoggingConfig;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Omote SDK Logger
|
|
101
|
+
*
|
|
102
|
+
* Unified logging system with:
|
|
103
|
+
* - 6 log levels (error, warn, info, debug, trace, verbose)
|
|
104
|
+
* - Structured JSON output for machine parsing
|
|
105
|
+
* - Pretty output for human readability
|
|
106
|
+
* - Module-based child loggers
|
|
107
|
+
* - Runtime configuration
|
|
108
|
+
* - Browser and Node.js compatible
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Configure global logging settings
|
|
113
|
+
*/
|
|
114
|
+
declare function configureLogging(config: Partial<LoggingConfig>): void;
|
|
115
|
+
/**
|
|
116
|
+
* Get current logging configuration
|
|
117
|
+
*/
|
|
118
|
+
declare function getLoggingConfig(): LoggingConfig;
|
|
119
|
+
/**
|
|
120
|
+
* Reset logging configuration to defaults
|
|
121
|
+
*/
|
|
122
|
+
declare function resetLoggingConfig(): void;
|
|
123
|
+
/**
|
|
124
|
+
* Set log level at runtime
|
|
125
|
+
*/
|
|
126
|
+
declare function setLogLevel(level: LogLevel): void;
|
|
127
|
+
/**
|
|
128
|
+
* Enable or disable logging
|
|
129
|
+
*/
|
|
130
|
+
declare function setLoggingEnabled(enabled: boolean): void;
|
|
131
|
+
/**
|
|
132
|
+
* Create a logger for a specific module
|
|
133
|
+
*
|
|
134
|
+
* @param module - Module name (e.g., 'LocalInference', 'ModelCache')
|
|
135
|
+
* @returns Logger instance
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```typescript
|
|
139
|
+
* const logger = createLogger('LocalInference');
|
|
140
|
+
* logger.info('Model loaded', { backend: 'webgpu', loadTimeMs: 1234 });
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
declare function createLogger(module: string): ILogger;
|
|
144
|
+
/**
|
|
145
|
+
* Clear logger cache (useful for testing)
|
|
146
|
+
*/
|
|
147
|
+
declare function clearLoggerCache(): void;
|
|
148
|
+
/**
|
|
149
|
+
* No-op logger for when logging is completely disabled
|
|
150
|
+
*/
|
|
151
|
+
declare const noopLogger: ILogger;
|
|
152
|
+
/**
|
|
153
|
+
* Get a no-op logger (for production builds that tree-shake logging)
|
|
154
|
+
*/
|
|
155
|
+
declare function getNoopLogger(): ILogger;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Abstract monotonic clock for runtime-agnostic timing.
|
|
159
|
+
*
|
|
160
|
+
* **Portability contract**: To port the SDK to Node.js, Python, Unreal, or Unity,
|
|
161
|
+
* implement this interface with your runtime's high-resolution timer and call
|
|
162
|
+
* `configureClock()` at startup.
|
|
163
|
+
*
|
|
164
|
+
* @example Node.js
|
|
165
|
+
* ```typescript
|
|
166
|
+
* import { configureClock } from '@omote/core';
|
|
167
|
+
* configureClock({
|
|
168
|
+
* now: () => Number(process.hrtime.bigint() / 1_000_000n),
|
|
169
|
+
* timestamp: () => Date.now(),
|
|
170
|
+
* });
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* @example Unreal Engine (via wasm-bindgen)
|
|
174
|
+
* ```typescript
|
|
175
|
+
* configureClock({
|
|
176
|
+
* now: () => FPlatformTime.Seconds() * 1000,
|
|
177
|
+
* timestamp: () => FDateTime.UtcNow().ToUnixTimestamp() * 1000,
|
|
178
|
+
* });
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* @example Unity (via jslib bridge)
|
|
182
|
+
* ```typescript
|
|
183
|
+
* configureClock({
|
|
184
|
+
* now: () => Time.realtimeSinceStartup * 1000,
|
|
185
|
+
* timestamp: () => Date.now(),
|
|
186
|
+
* });
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
interface Clock {
|
|
190
|
+
/** Monotonic high-resolution milliseconds (for durations, telemetry spans) */
|
|
191
|
+
now(): number;
|
|
192
|
+
/** Wall-clock milliseconds since epoch (for log timestamps) */
|
|
193
|
+
timestamp(): number;
|
|
194
|
+
}
|
|
195
|
+
declare const defaultClock: Clock;
|
|
196
|
+
/** Replace the default browser clock with a custom implementation. */
|
|
197
|
+
declare function configureClock(clock: Clock): void;
|
|
198
|
+
/** Get the active clock instance. */
|
|
199
|
+
declare function getClock(): Clock;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Structured error codes for the Omote SDK.
|
|
203
|
+
*
|
|
204
|
+
* Codes follow the pattern `OMOTE_{CATEGORY}_{SEQ}` where:
|
|
205
|
+
* - **INF** = Inference (model loading, session, OOM)
|
|
206
|
+
* - **AUD** = Audio (AudioContext, scheduling, decoding)
|
|
207
|
+
* - **SPH** = Speech (VAD, ASR, microphone)
|
|
208
|
+
* - **TTS** = Text-to-Speech (synthesis, streaming, phonemizer)
|
|
209
|
+
* - **PIP** = Pipeline (state machine, abort)
|
|
210
|
+
* - **CAC** = Cache (IndexedDB quota, eviction, staleness)
|
|
211
|
+
* - **NET** = Network (fetch, timeout, WebSocket)
|
|
212
|
+
*
|
|
213
|
+
* Exported as a const object (not enum) for tree-shaking.
|
|
214
|
+
*/
|
|
215
|
+
declare const ErrorCodes: {
|
|
216
|
+
/** Model failed to load (file not found, corrupted, unsupported format) */
|
|
217
|
+
readonly INF_LOAD_FAILED: "OMOTE_INF_001";
|
|
218
|
+
/** ORT session poisoned after WebGPU device loss — must reload tab */
|
|
219
|
+
readonly INF_SESSION_POISON: "OMOTE_INF_002";
|
|
220
|
+
/** Inference exceeded timeout threshold */
|
|
221
|
+
readonly INF_TIMEOUT: "OMOTE_INF_003";
|
|
222
|
+
/** Out-of-memory during inference or model loading */
|
|
223
|
+
readonly INF_OOM: "OMOTE_INF_004";
|
|
224
|
+
/** WebGPU unavailable, fell back to WASM */
|
|
225
|
+
readonly INF_WEBGPU_FALLBACK: "OMOTE_INF_005";
|
|
226
|
+
/** Input tensor shape does not match model expectations */
|
|
227
|
+
readonly INF_SHAPE_MISMATCH: "OMOTE_INF_006";
|
|
228
|
+
/** AudioContext creation or resume failed */
|
|
229
|
+
readonly AUD_CONTEXT_FAILED: "OMOTE_AUD_001";
|
|
230
|
+
/** Gap detected in audio scheduling (buffer underrun) */
|
|
231
|
+
readonly AUD_SCHEDULE_GAP: "OMOTE_AUD_002";
|
|
232
|
+
/** Audio buffer decoding failed */
|
|
233
|
+
readonly AUD_DECODE_FAILED: "OMOTE_AUD_003";
|
|
234
|
+
/** Voice activity detection error */
|
|
235
|
+
readonly SPH_VAD_ERROR: "OMOTE_SPH_001";
|
|
236
|
+
/** Automatic speech recognition error */
|
|
237
|
+
readonly SPH_ASR_ERROR: "OMOTE_SPH_002";
|
|
238
|
+
/** Microphone access denied or unavailable */
|
|
239
|
+
readonly SPH_MIC_DENIED: "OMOTE_SPH_003";
|
|
240
|
+
/** TTS synthesis failed */
|
|
241
|
+
readonly TTS_SYNTH_FAILED: "OMOTE_TTS_001";
|
|
242
|
+
/** TTS streaming error (chunk delivery failure) */
|
|
243
|
+
readonly TTS_STREAM_ERROR: "OMOTE_TTS_002";
|
|
244
|
+
/** Phonemizer (eSpeak-NG WASM) ran out of memory */
|
|
245
|
+
readonly TTS_PHONEMIZER_OOM: "OMOTE_TTS_003";
|
|
246
|
+
/** Invalid state transition in pipeline state machine */
|
|
247
|
+
readonly PIP_STATE_ERROR: "OMOTE_PIP_001";
|
|
248
|
+
/** Pipeline operation aborted (user interrupt or signal) */
|
|
249
|
+
readonly PIP_ABORT: "OMOTE_PIP_002";
|
|
250
|
+
/** IndexedDB storage quota exceeded */
|
|
251
|
+
readonly CAC_QUOTA_EXCEEDED: "OMOTE_CAC_001";
|
|
252
|
+
/** Cache entry evicted (LRU or manual) */
|
|
253
|
+
readonly CAC_EVICTION: "OMOTE_CAC_002";
|
|
254
|
+
/** Cached model is stale (version mismatch) */
|
|
255
|
+
readonly CAC_STALE: "OMOTE_CAC_003";
|
|
256
|
+
/** HTTP fetch failed (model download, CDN) */
|
|
257
|
+
readonly NET_FETCH_FAILED: "OMOTE_NET_001";
|
|
258
|
+
/** Network request timed out */
|
|
259
|
+
readonly NET_TIMEOUT: "OMOTE_NET_002";
|
|
260
|
+
/** WebSocket connection error */
|
|
261
|
+
readonly NET_WEBSOCKET_ERROR: "OMOTE_NET_003";
|
|
262
|
+
};
|
|
263
|
+
/** Union type of all error code string values. */
|
|
264
|
+
type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
265
|
+
|
|
266
|
+
export { type Clock as C, DEFAULT_LOGGING_CONFIG as D, type ErrorCode as E, type ILogger as I, type LogFormatter as L, ErrorCodes as a, LOG_LEVEL_PRIORITY as b, type LogEntry as c, type LogLevel as d, type LogSink as e, type LoggingConfig as f, clearLoggerCache as g, configureClock as h, configureLogging as i, createLogger as j, defaultClock as k, getClock as l, getLoggingConfig as m, getNoopLogger as n, noopLogger as o, setLoggingEnabled as p, resetLoggingConfig as r, setLogLevel as s };
|