@omote/core 0.10.5 → 0.10.6
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 +76 -34
- package/dist/chunk-3FILA2CD.mjs +785 -0
- package/dist/chunk-3FILA2CD.mjs.map +1 -0
- package/dist/chunk-5WIOGMJA.mjs +785 -0
- package/dist/chunk-5WIOGMJA.mjs.map +1 -0
- package/dist/chunk-NWZMIQK4.mjs +782 -0
- package/dist/chunk-NWZMIQK4.mjs.map +1 -0
- package/dist/chunk-WW4XAUJ3.mjs +208 -0
- package/dist/chunk-WW4XAUJ3.mjs.map +1 -0
- package/dist/index.d.mts +84 -79
- package/dist/index.d.ts +84 -79
- package/dist/index.js +514 -406
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +233 -199
- package/dist/index.mjs.map +1 -1
- package/dist/logging/index.js +5 -0
- package/dist/logging/index.js.map +1 -1
- package/dist/logging/index.mjs +1 -1
- package/dist/otlp-2BML6FIK.mjs +7 -0
- package/dist/otlp-2BML6FIK.mjs.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/logging/types.ts","../src/logging/formatters.ts","../src/telemetry/exporters/console.ts","../src/logging/Clock.ts","../src/telemetry/OmoteTelemetry.ts","../src/logging/Logger.ts","../src/logging/ErrorCodes.ts"],"sourcesContent":["/**\n * Logging types for Omote SDK\n *\n * 6-level logging system with structured output:\n * - error: Critical failures that prevent operation\n * - warn: Recoverable issues or degraded performance\n * - info: Key lifecycle events (model loaded, inference complete)\n * - debug: Detailed operational info for development\n * - trace: Fine-grained tracing for performance analysis\n * - verbose: Extremely detailed output (tensor shapes, intermediate values)\n */\n\nexport type LogLevel = 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'verbose';\n\n/**\n * Numeric priority for log levels (lower = more severe)\n */\nexport const LOG_LEVEL_PRIORITY: Record<LogLevel, number> = {\n error: 0,\n warn: 1,\n info: 2,\n debug: 3,\n trace: 4,\n verbose: 5,\n};\n\n/**\n * Structured log entry\n */\nexport interface LogEntry {\n /** Unix timestamp in milliseconds */\n timestamp: number;\n /** Log level */\n level: LogLevel;\n /** Module name (e.g., 'LocalInference', 'ModelCache') */\n module: string;\n /** Human-readable message */\n message: string;\n /** Optional structured error code from ErrorCodes (e.g., 'OMOTE_INF_001') */\n code?: string;\n /** Optional structured data */\n data?: Record<string, unknown>;\n /** Optional error object */\n error?: Error;\n /** Trace ID from active telemetry span (log-to-span correlation) */\n traceId?: string;\n /** Span ID from active telemetry span (log-to-span correlation) */\n spanId?: string;\n}\n\n/**\n * Log output sink interface.\n *\n * **Portability contract**: Replace the default console sink to route logs to\n * any backend — Node.js winston/pino, Unreal UE_LOG, Unity Debug.Log, or a\n * remote telemetry service. Register via `configureLogging({ sink: mySink })`.\n */\nexport interface LogSink {\n (entry: LogEntry): void;\n}\n\n/**\n * Log formatter interface\n */\nexport interface LogFormatter {\n (entry: LogEntry): string;\n}\n\n/**\n * Global logging configuration\n */\nexport interface LoggingConfig {\n /** Minimum log level to output (default: 'info') */\n level: LogLevel;\n /** Enable/disable logging globally (default: true) */\n enabled: boolean;\n /** Output format: 'json' for structured, 'pretty' for human-readable */\n format: 'json' | 'pretty';\n /** Custom output sink (default: console) */\n sink?: LogSink;\n /** Include timestamps in output (default: true) */\n timestamps?: boolean;\n /** Include module name in output (default: true) */\n includeModule?: boolean;\n}\n\n/**\n * Logger interface for module-specific logging.\n *\n * **Portability contract**: All SDK modules depend only on this interface.\n * To integrate with a non-browser runtime (Node.js, Unreal, Unity), either:\n * 1. Use the built-in Logger with a custom `LogSink`, or\n * 2. Provide your own `ILogger` implementation that bridges to the host\n * runtime's logging system (e.g., `console.log`, `UE_LOG`, `Debug.Log`).\n */\nexport interface ILogger {\n error(message: string, data?: Record<string, unknown>): void;\n warn(message: string, data?: Record<string, unknown>): void;\n info(message: string, data?: Record<string, unknown>): void;\n debug(message: string, data?: Record<string, unknown>): void;\n trace(message: string, data?: Record<string, unknown>): void;\n verbose(message: string, data?: Record<string, unknown>): void;\n\n /** Create a child logger with a sub-module name */\n child(subModule: string): ILogger;\n\n /** Get the module name for this logger */\n readonly module: string;\n}\n\n/**\n * Default configuration\n */\nexport const DEFAULT_LOGGING_CONFIG: LoggingConfig = {\n level: 'info',\n enabled: true,\n format: 'pretty',\n timestamps: true,\n includeModule: true,\n};\n","/**\n * Log formatters for different output formats\n */\n\nimport type { LogEntry, LogFormatter, LogLevel } from './types';\n\n/**\n * ANSI color codes for terminal output\n */\nconst COLORS = {\n reset: '\\x1b[0m',\n red: '\\x1b[31m',\n yellow: '\\x1b[33m',\n blue: '\\x1b[34m',\n cyan: '\\x1b[36m',\n gray: '\\x1b[90m',\n white: '\\x1b[37m',\n magenta: '\\x1b[35m',\n};\n\n/**\n * Level-specific colors\n */\nconst LEVEL_COLORS: Record<LogLevel, string> = {\n error: COLORS.red,\n warn: COLORS.yellow,\n info: COLORS.blue,\n debug: COLORS.cyan,\n trace: COLORS.magenta,\n verbose: COLORS.gray,\n};\n\n/**\n * Level display names (padded for alignment)\n */\nconst LEVEL_NAMES: Record<LogLevel, string> = {\n error: 'ERROR ',\n warn: 'WARN ',\n info: 'INFO ',\n debug: 'DEBUG ',\n trace: 'TRACE ',\n verbose: 'VERBOSE',\n};\n\n/**\n * Check if we're in a browser environment\n */\nconst isBrowser = typeof window !== 'undefined';\n\n/**\n * Format timestamp as ISO string or relative time\n */\nfunction formatTimestamp(timestamp: number): string {\n const date = new Date(timestamp);\n return date.toISOString().substring(11, 23); // HH:mm:ss.SSS\n}\n\n/**\n * Safely serialize data to JSON, handling circular references\n */\nfunction safeStringify(data: unknown): string {\n const seen = new WeakSet();\n return JSON.stringify(data, (key, value) => {\n if (typeof value === 'object' && value !== null) {\n if (seen.has(value)) {\n return '[Circular]';\n }\n seen.add(value);\n }\n // Handle special types\n if (value instanceof Error) {\n return {\n name: value.name,\n message: value.message,\n stack: value.stack,\n };\n }\n if (value instanceof Float32Array || value instanceof Int16Array) {\n return `${value.constructor.name}(${value.length})`;\n }\n if (ArrayBuffer.isView(value)) {\n return `${value.constructor.name}(${value.byteLength})`;\n }\n return value;\n });\n}\n\n/**\n * JSON formatter - structured output for machine parsing\n */\nexport const jsonFormatter: LogFormatter = (entry: LogEntry): string => {\n const output: Record<string, unknown> = {\n timestamp: entry.timestamp,\n level: entry.level,\n module: entry.module,\n message: entry.message,\n };\n\n if (entry.data && Object.keys(entry.data).length > 0) {\n output.data = entry.data;\n }\n\n if (entry.traceId) output.traceId = entry.traceId;\n if (entry.spanId) output.spanId = entry.spanId;\n\n if (entry.error) {\n output.error = {\n name: entry.error.name,\n message: entry.error.message,\n stack: entry.error.stack,\n };\n }\n\n return safeStringify(output);\n};\n\n/**\n * Pretty formatter - human-readable output with colors\n */\nexport const prettyFormatter: LogFormatter = (entry: LogEntry): string => {\n const time = formatTimestamp(entry.timestamp);\n const level = LEVEL_NAMES[entry.level];\n const module = entry.module;\n const message = entry.message;\n\n // Build the base message\n let output: string;\n\n if (isBrowser) {\n // Browser: no ANSI colors, use plain text\n output = `${time} ${level} [${module}] ${message}`;\n } else {\n // Terminal: use ANSI colors\n const color = LEVEL_COLORS[entry.level];\n output = `${COLORS.gray}${time}${COLORS.reset} ${color}${level}${COLORS.reset} ${COLORS.cyan}[${module}]${COLORS.reset} ${message}`;\n }\n\n // Append trace correlation if present\n if (entry.traceId) {\n output += ` [trace:${entry.traceId.slice(0, 8)}]`;\n }\n\n // Append data if present\n if (entry.data && Object.keys(entry.data).length > 0) {\n const dataStr = safeStringify(entry.data);\n // For pretty format, indent multi-line data\n if (dataStr.length > 80) {\n output += '\\n ' + JSON.stringify(entry.data, null, 2).replace(/\\n/g, '\\n ');\n } else {\n output += ' ' + dataStr;\n }\n }\n\n // Append error if present\n if (entry.error) {\n output += `\\n ${entry.error.name}: ${entry.error.message}`;\n if (entry.error.stack) {\n const stackLines = entry.error.stack.split('\\n').slice(1, 4);\n output += '\\n ' + stackLines.join('\\n ');\n }\n }\n\n return output;\n};\n\n/**\n * Get formatter by name\n */\nexport function getFormatter(format: 'json' | 'pretty'): LogFormatter {\n return format === 'json' ? jsonFormatter : prettyFormatter;\n}\n\n/**\n * Create browser console arguments for styled output\n * Returns [formatString, ...styleArgs] for console.log\n */\nexport function createBrowserConsoleArgs(entry: LogEntry): [string, ...string[]] {\n const time = formatTimestamp(entry.timestamp);\n const level = entry.level.toUpperCase().padEnd(7);\n const module = entry.module;\n const message = entry.message;\n\n // CSS styles for browser console\n const styles = {\n time: 'color: gray;',\n error: 'color: red; font-weight: bold;',\n warn: 'color: orange; font-weight: bold;',\n info: 'color: blue;',\n debug: 'color: cyan;',\n trace: 'color: magenta;',\n verbose: 'color: gray;',\n module: 'color: teal; font-weight: bold;',\n message: 'color: inherit;',\n };\n\n let formatStr = '%c%s %c%s %c[%s]%c %s';\n const args: string[] = [\n styles.time,\n time,\n styles[entry.level],\n level,\n styles.module,\n module,\n styles.message,\n message,\n ];\n\n // Append data\n if (entry.data && Object.keys(entry.data).length > 0) {\n formatStr += ' %o';\n args.push(entry.data as unknown as string);\n }\n\n return [formatStr, ...args];\n}\n","/**\n * Console Exporter\n *\n * Exports telemetry data to the browser console for development/debugging.\n *\n * @category Telemetry\n */\n\nimport type { SpanAttributes } from '../types';\n\n/**\n * Span data structure for export\n */\nexport interface SpanData {\n name: string;\n traceId: string;\n spanId: string;\n parentSpanId?: string;\n startTime: number;\n endTime: number;\n durationMs: number;\n /** Epoch timestamp in ms for OTLP export (start) */\n epochMs: number;\n /** Epoch timestamp in ms for OTLP export (end) */\n endEpochMs: number;\n status: 'ok' | 'error';\n attributes: SpanAttributes;\n error?: Error;\n}\n\n/**\n * Metric data structure for export\n */\nexport interface MetricData {\n name: string;\n type: 'counter' | 'histogram';\n value: number;\n attributes: Record<string, string | number | boolean>;\n timestamp: number;\n /** Histogram bucket data for OTLP export */\n histogramData?: {\n count: number;\n sum: number;\n min: number;\n max: number;\n bucketBoundaries: number[];\n bucketCounts: number[];\n };\n}\n\n/**\n * Exporter interface that all exporters must implement\n */\nexport interface TelemetryExporterInterface {\n /** Export a completed span */\n exportSpan(span: SpanData): void;\n /** Export a metric */\n exportMetric(metric: MetricData): void;\n /** Flush any buffered data */\n flush(): Promise<void>;\n /** Shutdown the exporter */\n shutdown(): Promise<void>;\n}\n\n/**\n * Console exporter for development/debugging\n *\n * Outputs spans and metrics to the browser console with formatting.\n */\nexport class ConsoleExporter implements TelemetryExporterInterface {\n private enabled: boolean;\n private prefix: string;\n\n constructor(options: { enabled?: boolean; prefix?: string } = {}) {\n this.enabled = options.enabled ?? true;\n this.prefix = options.prefix ?? '[Omote Telemetry]';\n }\n\n exportSpan(span: SpanData): void {\n if (!this.enabled) return;\n\n const statusIcon = span.status === 'ok' ? '✓' : '✗';\n const statusColor = span.status === 'ok' ? 'color: green' : 'color: red';\n\n console.groupCollapsed(\n `%c${this.prefix} %c${statusIcon} ${span.name} %c(${span.durationMs.toFixed(2)}ms)`,\n 'color: gray',\n statusColor,\n 'color: gray'\n );\n\n console.log('Trace ID:', span.traceId);\n console.log('Span ID:', span.spanId);\n if (span.parentSpanId) {\n console.log('Parent Span ID:', span.parentSpanId);\n }\n console.log('Duration:', `${span.durationMs.toFixed(2)}ms`);\n console.log('Status:', span.status);\n\n if (Object.keys(span.attributes).length > 0) {\n console.log('Attributes:', span.attributes);\n }\n\n if (span.error) {\n console.error('Error:', span.error);\n }\n\n console.groupEnd();\n }\n\n exportMetric(metric: MetricData): void {\n if (!this.enabled) return;\n\n const typeIcon = metric.type === 'counter' ? '↑' : '📊';\n\n console.log(\n `%c${this.prefix} %c${typeIcon} ${metric.name}: %c${metric.value}`,\n 'color: gray',\n 'color: blue',\n 'color: black; font-weight: bold',\n metric.attributes\n );\n }\n\n async flush(): Promise<void> {\n // Console exporter doesn't buffer, nothing to flush\n }\n\n async shutdown(): Promise<void> {\n this.enabled = false;\n }\n}\n","/**\n * Abstract monotonic clock for runtime-agnostic timing.\n *\n * **Portability contract**: To port the SDK to Node.js, Python, Unreal, or Unity,\n * implement this interface with your runtime's high-resolution timer and call\n * `configureClock()` at startup.\n *\n * @example Node.js\n * ```typescript\n * import { configureClock } from '@omote/core';\n * configureClock({\n * now: () => Number(process.hrtime.bigint() / 1_000_000n),\n * timestamp: () => Date.now(),\n * });\n * ```\n *\n * @example Unreal Engine (via wasm-bindgen)\n * ```typescript\n * configureClock({\n * now: () => FPlatformTime.Seconds() * 1000,\n * timestamp: () => FDateTime.UtcNow().ToUnixTimestamp() * 1000,\n * });\n * ```\n *\n * @example Unity (via jslib bridge)\n * ```typescript\n * configureClock({\n * now: () => Time.realtimeSinceStartup * 1000,\n * timestamp: () => Date.now(),\n * });\n * ```\n */\nexport interface Clock {\n /** Monotonic high-resolution milliseconds (for durations, telemetry spans) */\n now(): number;\n /** Wall-clock milliseconds since epoch (for log timestamps) */\n timestamp(): number;\n}\n\nexport const defaultClock: Clock = {\n now: () => performance.now(),\n timestamp: () => Date.now(),\n};\n\nlet activeClock: Clock = defaultClock;\n\n/** Replace the default browser clock with a custom implementation. */\nexport function configureClock(clock: Clock): void {\n activeClock = clock;\n}\n\n/** Get the active clock instance. */\nexport function getClock(): Clock {\n return activeClock;\n}\n","/**\n * Muse Telemetry\n *\n * Main orchestrator for SDK telemetry. Manages spans, metrics, and exporters.\n *\n * @category Telemetry\n */\n\nimport type { TelemetryConfig, SpanAttributes, SamplingConfig } from './types';\nimport type { SpanData, MetricData, TelemetryExporterInterface } from './exporters/console';\nimport { ConsoleExporter } from './exporters/console';\nimport { getClock } from '../logging/Clock';\n\n/** Default histogram bucket boundaries (union of inference + model load buckets) */\nconst DEFAULT_HISTOGRAM_BUCKETS = [1, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, 30000, 60000];\n\n/**\n * Generate a random hex ID\n */\nfunction generateId(length: number = 16): string {\n const bytes = new Uint8Array(length);\n crypto.getRandomValues(bytes);\n return Array.from(bytes)\n .map(b => b.toString(16).padStart(2, '0'))\n .join('');\n}\n\n/**\n * Span context for tracing\n */\ninterface SpanContext {\n traceId: string;\n spanId: string;\n parentSpanId?: string;\n}\n\n/**\n * Active span handle returned by startSpan\n */\nexport interface ActiveSpan {\n /** End the span with success status */\n end(): void;\n /** End the span with error status */\n endWithError(error: Error): void;\n /** Add attributes to the span */\n setAttributes(attrs: Partial<SpanAttributes>): void;\n /** Get the span context */\n getContext(): SpanContext;\n}\n\n/**\n * Global telemetry instance\n */\nlet globalTelemetry: OmoteTelemetry | null = null;\n\n/**\n * Configure global telemetry\n *\n * @example\n * ```typescript\n * // Development\n * configureTelemetry({\n * enabled: true,\n * serviceName: 'omote-dev',\n * exporter: 'console',\n * });\n *\n * // Production\n * configureTelemetry({\n * enabled: true,\n * serviceName: 'omote-prod',\n * exporter: 'otlp',\n * exporterConfig: {\n * endpoint: 'https://tempo.example.com',\n * },\n * sampling: { ratio: 0.1 },\n * });\n * ```\n */\nexport function configureTelemetry(config: TelemetryConfig): OmoteTelemetry {\n if (globalTelemetry) {\n globalTelemetry.shutdown();\n }\n globalTelemetry = new OmoteTelemetry(config);\n return globalTelemetry;\n}\n\n/**\n * Get the global telemetry instance\n */\nexport function getTelemetry(): OmoteTelemetry | null {\n return globalTelemetry;\n}\n\n/**\n * Main telemetry class\n *\n * Manages spans, metrics, and exports to configured backends.\n */\nexport class OmoteTelemetry {\n private config: Required<Omit<TelemetryConfig, 'exporterConfig' | 'customExporter'>> & { exporterConfig?: TelemetryConfig['exporterConfig'] };\n private exporter: TelemetryExporterInterface | null = null;\n private exporterReady: Promise<void> | null = null;\n private activeTraceId: string | null = null;\n private metricsIntervalId: ReturnType<typeof setInterval> | null = null;\n\n // Span stack for log-to-span correlation\n private spanStack: Array<{ traceId: string; spanId: string }> = [];\n\n // Metric accumulators\n private counters: Map<string, { value: number; attributes: Record<string, string | number | boolean> }> = new Map();\n private histograms: Map<string, { count: number; sum: number; min: number; max: number; bucketBoundaries: number[]; bucketCounts: number[]; attributes: Record<string, string | number | boolean> }> = new Map();\n\n constructor(config: TelemetryConfig) {\n this.config = {\n enabled: config.enabled ?? false,\n serviceName: config.serviceName ?? 'omote-sdk',\n serviceVersion: config.serviceVersion ?? '0.1.0',\n exporter: config.exporter ?? 'none',\n exporterConfig: config.exporterConfig,\n sampling: config.sampling ?? { ratio: 1.0, alwaysSampleErrors: true },\n metricsEnabled: config.metricsEnabled ?? true,\n metricsIntervalMs: config.metricsIntervalMs ?? 60000,\n };\n\n if (this.config.enabled) {\n // Custom exporter: set synchronously (no async import needed)\n if ((config as TelemetryConfig).customExporter) {\n this.exporter = (config as TelemetryConfig).customExporter!;\n this.startMetricsCollection();\n } else {\n this.exporterReady = this.initExporter();\n }\n }\n }\n\n /**\n * Initialize the configured exporter\n */\n private async initExporter(): Promise<void> {\n switch (this.config.exporter) {\n case 'console':\n this.exporter = new ConsoleExporter({ enabled: true });\n break;\n case 'otlp':\n if (!this.config.exporterConfig) {\n console.warn('[Telemetry] OTLP exporter requires exporterConfig with endpoint');\n return;\n }\n {\n const { OTLPExporter } = await import('./exporters/otlp');\n this.exporter = new OTLPExporter(\n this.config.exporterConfig,\n this.config.serviceName,\n this.config.serviceVersion\n );\n }\n break;\n case 'none':\n default:\n this.exporter = null;\n }\n\n this.startMetricsCollection();\n }\n\n /**\n * Start periodic metrics collection\n */\n private startMetricsCollection(): void {\n if (!this.config.metricsEnabled || !this.exporter) return;\n\n this.metricsIntervalId = setInterval(() => {\n this.flushMetrics();\n }, this.config.metricsIntervalMs);\n }\n\n /**\n * Check if this operation should be sampled\n */\n private shouldSample(isError: boolean = false): boolean {\n if (!this.config.enabled) return false;\n\n const sampling = this.config.sampling as SamplingConfig;\n if (isError && sampling.alwaysSampleErrors) return true;\n\n const ratio = sampling.ratio ?? 1.0;\n return Math.random() < ratio;\n }\n\n /**\n * Start a new span\n *\n * @example\n * ```typescript\n * const span = telemetry.startSpan('Wav2Vec2.infer', {\n * 'inference.input_samples': samples.length,\n * 'model.backend': 'webgpu',\n * });\n *\n * try {\n * const result = await doInference();\n * span.setAttributes({ 'inference.output_frames': result.frames });\n * span.end();\n * } catch (error) {\n * span.endWithError(error);\n * }\n * ```\n */\n startSpan(name: string, attributes: Partial<SpanAttributes> = {}, parentContext?: SpanContext): ActiveSpan {\n const traceId = parentContext?.traceId ?? this.activeTraceId ?? generateId(16);\n const spanId = generateId(8);\n const parentSpanId = parentContext?.spanId;\n const startTime = getClock().now();\n const epochMs = Date.now();\n\n // Set active trace if this is a root span\n if (!parentContext && !this.activeTraceId) {\n this.activeTraceId = traceId;\n }\n\n let spanAttributes = { ...attributes };\n let ended = false;\n let sampled = this.shouldSample();\n\n const context: SpanContext = { traceId, spanId, parentSpanId };\n\n // Push to span stack for log-to-span correlation\n this.spanStack.push({ traceId, spanId });\n\n const endSpan = (status: 'ok' | 'error', error?: Error): void => {\n if (ended) return;\n ended = true;\n\n // Pop from span stack\n const idx = this.spanStack.findIndex(s => s.spanId === spanId);\n if (idx !== -1) this.spanStack.splice(idx, 1);\n\n const endTime = getClock().now();\n const durationMs = endTime - startTime;\n const endEpochMs = epochMs + (endTime - startTime);\n\n // Re-check sampling for errors\n if (status === 'error' && !sampled) {\n sampled = this.shouldSample(true);\n }\n\n if (!sampled || !this.exporter) return;\n\n const spanData: SpanData = {\n name,\n traceId,\n spanId,\n parentSpanId,\n startTime,\n endTime,\n durationMs,\n epochMs,\n endEpochMs,\n status,\n attributes: spanAttributes as SpanAttributes,\n error,\n };\n\n this.exporter.exportSpan(spanData);\n\n // Clear active trace if this was the root span\n if (!parentSpanId && this.activeTraceId === traceId) {\n this.activeTraceId = null;\n }\n };\n\n return {\n end: () => endSpan('ok'),\n endWithError: (error: Error) => endSpan('error', error),\n setAttributes: (attrs: Partial<SpanAttributes>) => {\n spanAttributes = { ...spanAttributes, ...attrs };\n },\n getContext: () => context,\n };\n }\n\n /**\n * Wrap an async function with a span\n *\n * @example\n * ```typescript\n * const result = await telemetry.withSpan('Model.load', async (span) => {\n * const model = await loadModel();\n * span.setAttributes({ 'model.size_bytes': model.size });\n * return model;\n * });\n * ```\n */\n async withSpan<T>(\n name: string,\n fn: (span: ActiveSpan) => Promise<T>,\n attributes: Partial<SpanAttributes> = {},\n parentContext?: SpanContext\n ): Promise<T> {\n const span = this.startSpan(name, attributes, parentContext);\n\n try {\n const result = await fn(span);\n span.end();\n return result;\n } catch (error) {\n span.endWithError(error as Error);\n throw error;\n }\n }\n\n /**\n * Increment a counter metric\n *\n * @example\n * ```typescript\n * telemetry.incrementCounter('omote.inference.total', 1, {\n * model: 'wav2vec2',\n * backend: 'webgpu',\n * status: 'success',\n * });\n * ```\n */\n incrementCounter(\n name: string,\n value: number = 1,\n attributes: Record<string, string | number | boolean> = {}\n ): void {\n if (!this.config.enabled || !this.config.metricsEnabled) return;\n\n const key = this.getMetricKey(name, attributes);\n const existing = this.counters.get(key);\n\n if (existing) {\n existing.value += value;\n } else {\n this.counters.set(key, { value, attributes });\n }\n }\n\n /**\n * Record a histogram value\n *\n * @example\n * ```typescript\n * telemetry.recordHistogram('omote.inference.latency', durationMs, {\n * model: 'wav2vec2',\n * backend: 'webgpu',\n * });\n * ```\n */\n recordHistogram(\n name: string,\n value: number,\n attributes: Record<string, string | number | boolean> = {},\n bucketBoundaries: number[] = DEFAULT_HISTOGRAM_BUCKETS\n ): void {\n if (!this.config.enabled || !this.config.metricsEnabled) return;\n\n const key = this.getMetricKey(name, attributes);\n const existing = this.histograms.get(key);\n\n if (existing) {\n existing.count++;\n existing.sum += value;\n if (value < existing.min) existing.min = value;\n if (value > existing.max) existing.max = value;\n // Increment bucket count\n let placed = false;\n for (let i = 0; i < existing.bucketBoundaries.length; i++) {\n if (value <= existing.bucketBoundaries[i]) {\n existing.bucketCounts[i]++;\n placed = true;\n break;\n }\n }\n if (!placed) existing.bucketCounts[existing.bucketCounts.length - 1]++;\n } else {\n // Initialize bucket counts (boundaries.length + 1 for overflow bucket)\n const bucketCounts = new Array(bucketBoundaries.length + 1).fill(0);\n let placed = false;\n for (let i = 0; i < bucketBoundaries.length; i++) {\n if (value <= bucketBoundaries[i]) {\n bucketCounts[i]++;\n placed = true;\n break;\n }\n }\n if (!placed) bucketCounts[bucketCounts.length - 1]++;\n this.histograms.set(key, { count: 1, sum: value, min: value, max: value, bucketBoundaries, bucketCounts, attributes });\n }\n }\n\n /**\n * Generate unique key for metric with attributes\n */\n private getMetricKey(name: string, attributes: Record<string, string | number | boolean>): string {\n // Fast path: no attributes → return name directly (avoids Object.entries + sort + join)\n const keys = Object.keys(attributes);\n if (keys.length === 0) return name;\n\n const sortedAttrs = Object.entries(attributes)\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([k, v]) => `${k}=${v}`)\n .join(',');\n return `${name}|${sortedAttrs}`;\n }\n\n /**\n * Flush accumulated metrics to exporter\n */\n private flushMetrics(): void {\n if (!this.exporter) return;\n\n const timestamp = Date.now();\n\n // Export counters (delta temporality — reset after export)\n for (const [key, data] of this.counters) {\n if (data.value === 0) continue;\n const name = key.split('|')[0];\n const metric: MetricData = {\n name,\n type: 'counter',\n value: data.value,\n attributes: data.attributes,\n timestamp,\n };\n this.exporter.exportMetric(metric);\n data.value = 0;\n }\n\n // Export histogram aggregates\n for (const [key, data] of this.histograms) {\n const name = key.split('|')[0];\n if (data.count === 0) continue;\n\n const avg = data.sum / data.count;\n\n const metric: MetricData = {\n name,\n type: 'histogram',\n value: avg,\n attributes: {\n ...data.attributes,\n count: data.count,\n sum: data.sum,\n min: data.min,\n max: data.max,\n },\n timestamp,\n histogramData: {\n count: data.count,\n sum: data.sum,\n min: data.min,\n max: data.max,\n bucketBoundaries: [...data.bucketBoundaries],\n bucketCounts: [...data.bucketCounts],\n },\n };\n this.exporter.exportMetric(metric);\n\n // Reset accumulators after export\n data.count = 0;\n data.sum = 0;\n data.min = Infinity;\n data.max = -Infinity;\n data.bucketCounts.fill(0);\n }\n }\n\n /**\n * Force flush all pending data\n */\n async flush(): Promise<void> {\n if (this.exporterReady) await this.exporterReady;\n this.flushMetrics();\n await this.exporter?.flush();\n }\n\n /**\n * Shutdown telemetry\n */\n async shutdown(): Promise<void> {\n if (this.metricsIntervalId) {\n clearInterval(this.metricsIntervalId);\n this.metricsIntervalId = null;\n }\n\n await this.flush();\n await this.exporter?.shutdown();\n this.exporter = null;\n }\n\n /**\n * Check if telemetry is enabled\n */\n isEnabled(): boolean {\n return this.config.enabled;\n }\n\n /**\n * Get current configuration\n */\n getConfig(): TelemetryConfig {\n return { ...this.config };\n }\n\n /**\n * Get the active span context for log-to-span correlation.\n * Returns the most recent (top of stack) active span, or null if none.\n */\n getActiveContext(): { traceId: string; spanId: string } | null {\n return this.spanStack.length > 0 ? this.spanStack[this.spanStack.length - 1] : null;\n }\n}\n","/**\n * Omote SDK Logger\n *\n * Unified logging system with:\n * - 6 log levels (error, warn, info, debug, trace, verbose)\n * - Structured JSON output for machine parsing\n * - Pretty output for human readability\n * - Module-based child loggers\n * - Runtime configuration\n * - Browser and Node.js compatible\n */\n\nimport type {\n LogLevel,\n LogEntry,\n LoggingConfig,\n LogSink,\n ILogger,\n} from './types';\nimport { LOG_LEVEL_PRIORITY, DEFAULT_LOGGING_CONFIG } from './types';\nimport { getFormatter, createBrowserConsoleArgs } from './formatters';\nimport { getTelemetry } from '../telemetry/OmoteTelemetry';\nimport { getClock } from './Clock';\n\n/**\n * Check if running in browser\n */\nconst isBrowser = typeof window !== 'undefined';\n\n/**\n * Global logging configuration\n */\nlet globalConfig: LoggingConfig = { ...DEFAULT_LOGGING_CONFIG };\n\n/**\n * Configure global logging settings\n */\nexport function configureLogging(config: Partial<LoggingConfig>): void {\n globalConfig = { ...globalConfig, ...config };\n}\n\n/**\n * Get current logging configuration\n */\nexport function getLoggingConfig(): LoggingConfig {\n return { ...globalConfig };\n}\n\n/**\n * Reset logging configuration to defaults\n */\nexport function resetLoggingConfig(): void {\n globalConfig = { ...DEFAULT_LOGGING_CONFIG };\n}\n\n/**\n * Set log level at runtime\n */\nexport function setLogLevel(level: LogLevel): void {\n globalConfig.level = level;\n}\n\n/**\n * Enable or disable logging\n */\nexport function setLoggingEnabled(enabled: boolean): void {\n globalConfig.enabled = enabled;\n}\n\n/**\n * Default console sink with browser-optimized output\n */\nconst consoleSink: LogSink = (entry: LogEntry): void => {\n const consoleMethod = entry.level === 'error' ? 'error'\n : entry.level === 'warn' ? 'warn'\n : 'log';\n\n if (globalConfig.format === 'pretty' && isBrowser) {\n // Use styled console output in browser\n const args = createBrowserConsoleArgs(entry);\n (console as unknown as Record<string, (...args: unknown[]) => void>)[consoleMethod](...args);\n } else {\n // Use formatter for terminal or JSON output\n const formatter = getFormatter(globalConfig.format);\n const formatted = formatter(entry);\n (console as unknown as Record<string, (...args: unknown[]) => void>)[consoleMethod](formatted);\n }\n};\n\n/**\n * Get the active sink (custom or default console)\n */\nfunction getActiveSink(): LogSink {\n return globalConfig.sink || consoleSink;\n}\n\n/**\n * Check if a log level should be output given current config\n */\nfunction shouldLog(level: LogLevel): boolean {\n if (!globalConfig.enabled) return false;\n return LOG_LEVEL_PRIORITY[level] <= LOG_LEVEL_PRIORITY[globalConfig.level];\n}\n\n/**\n * Logger implementation\n */\nclass Logger implements ILogger {\n readonly module: string;\n\n constructor(module: string) {\n this.module = module;\n }\n\n private log(level: LogLevel, message: string, data?: Record<string, unknown>): void {\n if (!shouldLog(level)) return;\n\n const entry: LogEntry = {\n timestamp: getClock().timestamp(),\n level,\n module: this.module,\n message,\n data,\n };\n\n // Attach active span context for log-to-span correlation\n const ctx = getTelemetry()?.getActiveContext();\n if (ctx) {\n entry.traceId = ctx.traceId;\n entry.spanId = ctx.spanId;\n }\n\n // Extract error from data if present\n if (data?.error instanceof Error) {\n entry.error = data.error;\n // Remove from data to avoid duplication\n const { error, ...rest } = data;\n entry.data = Object.keys(rest).length > 0 ? rest : undefined;\n }\n\n getActiveSink()(entry);\n }\n\n error(message: string, data?: Record<string, unknown>): void {\n this.log('error', message, data);\n }\n\n warn(message: string, data?: Record<string, unknown>): void {\n this.log('warn', message, data);\n }\n\n info(message: string, data?: Record<string, unknown>): void {\n this.log('info', message, data);\n }\n\n debug(message: string, data?: Record<string, unknown>): void {\n this.log('debug', message, data);\n }\n\n trace(message: string, data?: Record<string, unknown>): void {\n this.log('trace', message, data);\n }\n\n verbose(message: string, data?: Record<string, unknown>): void {\n this.log('verbose', message, data);\n }\n\n child(subModule: string): ILogger {\n return new Logger(`${this.module}.${subModule}`);\n }\n}\n\n/**\n * Logger cache for reusing instances\n */\nconst loggerCache = new Map<string, Logger>();\n\n/**\n * Create a logger for a specific module\n *\n * @param module - Module name (e.g., 'LocalInference', 'ModelCache')\n * @returns Logger instance\n *\n * @example\n * ```typescript\n * const logger = createLogger('LocalInference');\n * logger.info('Model loaded', { backend: 'webgpu', loadTimeMs: 1234 });\n * ```\n */\nexport function createLogger(module: string): ILogger {\n let logger = loggerCache.get(module);\n if (!logger) {\n logger = new Logger(module);\n loggerCache.set(module, logger);\n }\n return logger;\n}\n\n/**\n * Clear logger cache (useful for testing)\n */\nexport function clearLoggerCache(): void {\n loggerCache.clear();\n}\n\n/**\n * No-op logger for when logging is completely disabled\n */\nexport const noopLogger: ILogger = {\n module: 'noop',\n error: () => {},\n warn: () => {},\n info: () => {},\n debug: () => {},\n trace: () => {},\n verbose: () => {},\n child: () => noopLogger,\n};\n\n/**\n * Get a no-op logger (for production builds that tree-shake logging)\n */\nexport function getNoopLogger(): ILogger {\n return noopLogger;\n}\n","/**\r\n * Structured error codes for the Omote SDK.\r\n *\r\n * Codes follow the pattern `OMOTE_{CATEGORY}_{SEQ}` where:\r\n * - **INF** = Inference (model loading, session, OOM)\r\n * - **AUD** = Audio (AudioContext, scheduling, decoding)\r\n * - **SPH** = Speech (VAD, ASR, microphone)\r\n * - **TTS** = Text-to-Speech (synthesis, streaming, phonemizer)\r\n * - **PIP** = Pipeline (state machine, abort)\r\n * - **CAC** = Cache (IndexedDB quota, eviction, staleness)\r\n * - **NET** = Network (fetch, timeout, WebSocket)\r\n *\r\n * Exported as a const object (not enum) for tree-shaking.\r\n */\r\nexport const ErrorCodes = {\r\n // ── Inference ──────────────────────────────────────────────────────────\r\n /** Model failed to load (file not found, corrupted, unsupported format) */\r\n INF_LOAD_FAILED: 'OMOTE_INF_001',\r\n /** ORT session poisoned after WebGPU device loss — must reload tab */\r\n INF_SESSION_POISON: 'OMOTE_INF_002',\r\n /** Inference exceeded timeout threshold */\r\n INF_TIMEOUT: 'OMOTE_INF_003',\r\n /** Out-of-memory during inference or model loading */\r\n INF_OOM: 'OMOTE_INF_004',\r\n /** WebGPU unavailable, fell back to WASM */\r\n INF_WEBGPU_FALLBACK: 'OMOTE_INF_005',\r\n /** Input tensor shape does not match model expectations */\r\n INF_SHAPE_MISMATCH: 'OMOTE_INF_006',\r\n\r\n // ── Audio ──────────────────────────────────────────────────────────────\r\n /** AudioContext creation or resume failed */\r\n AUD_CONTEXT_FAILED: 'OMOTE_AUD_001',\r\n /** Gap detected in audio scheduling (buffer underrun) */\r\n AUD_SCHEDULE_GAP: 'OMOTE_AUD_002',\r\n /** Audio buffer decoding failed */\r\n AUD_DECODE_FAILED: 'OMOTE_AUD_003',\r\n\r\n // ── Speech ─────────────────────────────────────────────────────────────\r\n /** Voice activity detection error */\r\n SPH_VAD_ERROR: 'OMOTE_SPH_001',\r\n /** Automatic speech recognition error */\r\n SPH_ASR_ERROR: 'OMOTE_SPH_002',\r\n /** Microphone access denied or unavailable */\r\n SPH_MIC_DENIED: 'OMOTE_SPH_003',\r\n\r\n // ── TTS ────────────────────────────────────────────────────────────────\r\n /** TTS synthesis failed */\r\n TTS_SYNTH_FAILED: 'OMOTE_TTS_001',\r\n /** TTS streaming error (chunk delivery failure) */\r\n TTS_STREAM_ERROR: 'OMOTE_TTS_002',\r\n /** Phonemizer (eSpeak-NG WASM) ran out of memory */\r\n TTS_PHONEMIZER_OOM: 'OMOTE_TTS_003',\r\n\r\n // ── Pipeline ───────────────────────────────────────────────────────────\r\n /** Invalid state transition in pipeline state machine */\r\n PIP_STATE_ERROR: 'OMOTE_PIP_001',\r\n /** Pipeline operation aborted (user interrupt or signal) */\r\n PIP_ABORT: 'OMOTE_PIP_002',\r\n\r\n // ── Cache ──────────────────────────────────────────────────────────────\r\n /** IndexedDB storage quota exceeded */\r\n CAC_QUOTA_EXCEEDED: 'OMOTE_CAC_001',\r\n /** Cache entry evicted (LRU or manual) */\r\n CAC_EVICTION: 'OMOTE_CAC_002',\r\n /** Cached model is stale (version mismatch) */\r\n CAC_STALE: 'OMOTE_CAC_003',\r\n\r\n // ── Network ────────────────────────────────────────────────────────────\r\n /** HTTP fetch failed (model download, CDN) */\r\n NET_FETCH_FAILED: 'OMOTE_NET_001',\r\n /** Network request timed out */\r\n NET_TIMEOUT: 'OMOTE_NET_002',\r\n /** WebSocket connection error */\r\n NET_WEBSOCKET_ERROR: 'OMOTE_NET_003',\r\n} as const;\r\n\r\n/** Union type of all error code string values. */\r\nexport type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];\r\n"],"mappings":";AAiBO,IAAM,qBAA+C;AAAA,EAC1D,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,SAAS;AACX;AAyFO,IAAM,yBAAwC;AAAA,EACnD,OAAO;AAAA,EACP,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,eAAe;AACjB;;;AC9GA,IAAM,SAAS;AAAA,EACb,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,SAAS;AACX;AAKA,IAAM,eAAyC;AAAA,EAC7C,OAAO,OAAO;AAAA,EACd,MAAM,OAAO;AAAA,EACb,MAAM,OAAO;AAAA,EACb,OAAO,OAAO;AAAA,EACd,OAAO,OAAO;AAAA,EACd,SAAS,OAAO;AAClB;AAKA,IAAM,cAAwC;AAAA,EAC5C,OAAO;AAAA,EACP,MAAM;AAAA,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Code = {
|
|
3
|
+
UNSET: 0,
|
|
4
|
+
OK: 1,
|
|
5
|
+
ERROR: 2
|
|
6
|
+
};
|
|
7
|
+
function toOTLPAttributeValue(value) {
|
|
8
|
+
if (typeof value === "string") return { stringValue: value };
|
|
9
|
+
if (typeof value === "number") return Number.isInteger(value) ? { intValue: value } : { doubleValue: value };
|
|
10
|
+
return { boolValue: value };
|
|
11
|
+
}
|
|
12
|
+
function toOTLPAttributes(attrs) {
|
|
13
|
+
return Object.entries(attrs).filter(([, v]) => v !== void 0).map(([key, value]) => ({ key, value: toOTLPAttributeValue(value) }));
|
|
14
|
+
}
|
|
15
|
+
function spanToOTLPSpan(span) {
|
|
16
|
+
return {
|
|
17
|
+
traceId: span.traceId,
|
|
18
|
+
spanId: span.spanId,
|
|
19
|
+
parentSpanId: span.parentSpanId || "",
|
|
20
|
+
name: span.name,
|
|
21
|
+
kind: 1,
|
|
22
|
+
// INTERNAL
|
|
23
|
+
startTimeUnixNano: String(span.epochMs * 1e6),
|
|
24
|
+
endTimeUnixNano: String(span.endEpochMs * 1e6),
|
|
25
|
+
attributes: toOTLPAttributes(span.attributes),
|
|
26
|
+
status: {
|
|
27
|
+
code: span.status === "ok" ? StatusCode.OK : StatusCode.ERROR,
|
|
28
|
+
message: span.error?.message || ""
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function metricToOTLPMetric(metric) {
|
|
33
|
+
const attributes = toOTLPAttributes(metric.attributes);
|
|
34
|
+
const timeUnixNano = String(metric.timestamp * 1e6);
|
|
35
|
+
if (metric.type === "counter") {
|
|
36
|
+
return {
|
|
37
|
+
name: metric.name,
|
|
38
|
+
sum: {
|
|
39
|
+
dataPoints: [{
|
|
40
|
+
attributes,
|
|
41
|
+
timeUnixNano,
|
|
42
|
+
asInt: metric.value
|
|
43
|
+
}],
|
|
44
|
+
aggregationTemporality: 1,
|
|
45
|
+
// DELTA
|
|
46
|
+
isMonotonic: true
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
if (metric.histogramData) {
|
|
51
|
+
return {
|
|
52
|
+
name: metric.name,
|
|
53
|
+
histogram: {
|
|
54
|
+
dataPoints: [{
|
|
55
|
+
attributes,
|
|
56
|
+
timeUnixNano,
|
|
57
|
+
count: metric.histogramData.count,
|
|
58
|
+
sum: metric.histogramData.sum,
|
|
59
|
+
min: metric.histogramData.min,
|
|
60
|
+
max: metric.histogramData.max,
|
|
61
|
+
explicitBounds: metric.histogramData.bucketBoundaries,
|
|
62
|
+
bucketCounts: metric.histogramData.bucketCounts
|
|
63
|
+
}],
|
|
64
|
+
aggregationTemporality: 1
|
|
65
|
+
// DELTA
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
name: metric.name,
|
|
71
|
+
gauge: {
|
|
72
|
+
dataPoints: [{
|
|
73
|
+
attributes,
|
|
74
|
+
timeUnixNano,
|
|
75
|
+
asDouble: metric.value
|
|
76
|
+
}]
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
var OTLPExporter = class {
|
|
81
|
+
constructor(config, serviceName = "omote-sdk", serviceVersion = "0.1.0") {
|
|
82
|
+
this.spanBuffer = [];
|
|
83
|
+
this.metricBuffer = [];
|
|
84
|
+
this.flushIntervalId = null;
|
|
85
|
+
this.BUFFER_SIZE = 100;
|
|
86
|
+
this.FLUSH_INTERVAL_MS = 5e3;
|
|
87
|
+
this.isShutdown = false;
|
|
88
|
+
const parsed = new URL(config.endpoint);
|
|
89
|
+
if (parsed.protocol !== "https:") {
|
|
90
|
+
const isLocalhost = parsed.hostname === "localhost" || parsed.hostname === "127.0.0.1" || parsed.hostname === "[::1]";
|
|
91
|
+
if (!isLocalhost) {
|
|
92
|
+
throw new Error("OTLP endpoint must use HTTPS (or localhost for development)");
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
this.config = {
|
|
96
|
+
endpoint: config.endpoint,
|
|
97
|
+
timeoutMs: config.timeoutMs ?? 1e4,
|
|
98
|
+
headers: config.headers ? { ...config.headers } : {}
|
|
99
|
+
};
|
|
100
|
+
this.serviceName = serviceName;
|
|
101
|
+
this.serviceVersion = serviceVersion;
|
|
102
|
+
this.flushIntervalId = setInterval(() => {
|
|
103
|
+
this.flush().catch(console.error);
|
|
104
|
+
}, this.FLUSH_INTERVAL_MS);
|
|
105
|
+
}
|
|
106
|
+
exportSpan(span) {
|
|
107
|
+
if (this.isShutdown) return;
|
|
108
|
+
this.spanBuffer.push(span);
|
|
109
|
+
if (this.spanBuffer.length >= this.BUFFER_SIZE) {
|
|
110
|
+
this.flush().catch(console.error);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exportMetric(metric) {
|
|
114
|
+
if (this.isShutdown) return;
|
|
115
|
+
this.metricBuffer.push(metric);
|
|
116
|
+
if (this.metricBuffer.length >= this.BUFFER_SIZE) {
|
|
117
|
+
this.flush().catch(console.error);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
async flush() {
|
|
121
|
+
if (this.isShutdown) return;
|
|
122
|
+
const spans = this.spanBuffer.splice(0);
|
|
123
|
+
const metrics = this.metricBuffer.splice(0);
|
|
124
|
+
const promises = [];
|
|
125
|
+
if (spans.length > 0) {
|
|
126
|
+
promises.push(this.exportSpans(spans));
|
|
127
|
+
}
|
|
128
|
+
if (metrics.length > 0) {
|
|
129
|
+
promises.push(this.exportMetrics(metrics));
|
|
130
|
+
}
|
|
131
|
+
await Promise.all(promises);
|
|
132
|
+
}
|
|
133
|
+
async shutdown() {
|
|
134
|
+
if (this.flushIntervalId) {
|
|
135
|
+
clearInterval(this.flushIntervalId);
|
|
136
|
+
this.flushIntervalId = null;
|
|
137
|
+
}
|
|
138
|
+
await this.flush();
|
|
139
|
+
this.isShutdown = true;
|
|
140
|
+
}
|
|
141
|
+
async exportSpans(spans) {
|
|
142
|
+
const resourceAttrs = [
|
|
143
|
+
{ key: "service.name", value: { stringValue: this.serviceName } },
|
|
144
|
+
{ key: "service.version", value: { stringValue: this.serviceVersion } },
|
|
145
|
+
{ key: "telemetry.sdk.name", value: { stringValue: "omote-sdk" } },
|
|
146
|
+
{ key: "telemetry.sdk.language", value: { stringValue: "javascript" } }
|
|
147
|
+
];
|
|
148
|
+
const body = {
|
|
149
|
+
resourceSpans: [{
|
|
150
|
+
resource: { attributes: resourceAttrs },
|
|
151
|
+
scopeSpans: [{
|
|
152
|
+
scope: { name: "omote-sdk", version: this.serviceVersion },
|
|
153
|
+
spans: spans.map(spanToOTLPSpan)
|
|
154
|
+
}]
|
|
155
|
+
}]
|
|
156
|
+
};
|
|
157
|
+
const endpoint = this.config.endpoint.replace(/\/$/, "") + "/v1/traces";
|
|
158
|
+
await this.sendRequest(endpoint, body);
|
|
159
|
+
}
|
|
160
|
+
async exportMetrics(metrics) {
|
|
161
|
+
const resourceAttrs = [
|
|
162
|
+
{ key: "service.name", value: { stringValue: this.serviceName } },
|
|
163
|
+
{ key: "service.version", value: { stringValue: this.serviceVersion } }
|
|
164
|
+
];
|
|
165
|
+
const body = {
|
|
166
|
+
resourceMetrics: [{
|
|
167
|
+
resource: { attributes: resourceAttrs },
|
|
168
|
+
scopeMetrics: [{
|
|
169
|
+
scope: { name: "omote-sdk", version: this.serviceVersion },
|
|
170
|
+
metrics: metrics.map(metricToOTLPMetric)
|
|
171
|
+
}]
|
|
172
|
+
}]
|
|
173
|
+
};
|
|
174
|
+
const endpoint = this.config.endpoint.replace(/\/$/, "") + "/v1/metrics";
|
|
175
|
+
await this.sendRequest(endpoint, body);
|
|
176
|
+
}
|
|
177
|
+
async sendRequest(endpoint, body) {
|
|
178
|
+
const controller = new AbortController();
|
|
179
|
+
const timeoutId = setTimeout(() => controller.abort(), this.config.timeoutMs);
|
|
180
|
+
try {
|
|
181
|
+
const response = await fetch(endpoint, {
|
|
182
|
+
method: "POST",
|
|
183
|
+
headers: {
|
|
184
|
+
"Content-Type": "application/json",
|
|
185
|
+
...this.config.headers
|
|
186
|
+
},
|
|
187
|
+
body: JSON.stringify(body),
|
|
188
|
+
signal: controller.signal
|
|
189
|
+
});
|
|
190
|
+
if (!response.ok) {
|
|
191
|
+
console.warn(`[OTLP] Export failed: ${response.status} ${response.statusText}`);
|
|
192
|
+
}
|
|
193
|
+
} catch (error) {
|
|
194
|
+
if (error.name === "AbortError") {
|
|
195
|
+
console.warn("[OTLP] Export timed out");
|
|
196
|
+
} else {
|
|
197
|
+
console.warn("[OTLP] Export error:", error);
|
|
198
|
+
}
|
|
199
|
+
} finally {
|
|
200
|
+
clearTimeout(timeoutId);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export {
|
|
206
|
+
OTLPExporter
|
|
207
|
+
};
|
|
208
|
+
//# sourceMappingURL=chunk-WW4XAUJ3.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/telemetry/exporters/otlp.ts"],"sourcesContent":["/**\n * OTLP Exporter\n *\n * Exports telemetry data to OTLP-compatible backends (Jaeger, Tempo, etc.)\n * using the OTLP/HTTP JSON protocol.\n *\n * @category Telemetry\n */\n\nimport type { OTLPExporterConfig } from '../types';\nimport type { SpanData, MetricData, TelemetryExporterInterface } from './console';\n\n/**\n * OTLP span status codes\n */\nconst StatusCode = {\n UNSET: 0,\n OK: 1,\n ERROR: 2,\n} as const;\n\n/**\n * Convert attribute value to OTLP format\n */\nfunction toOTLPAttributeValue(value: string | number | boolean | undefined) {\n if (typeof value === 'string') return { stringValue: value };\n if (typeof value === 'number') return Number.isInteger(value) ? { intValue: value } : { doubleValue: value };\n return { boolValue: value };\n}\n\n/**\n * Convert attributes object to OTLP attribute array\n */\nfunction toOTLPAttributes(attrs: Record<string, string | number | boolean | undefined>) {\n return Object.entries(attrs)\n .filter(([, v]) => v !== undefined)\n .map(([key, value]) => ({ key, value: toOTLPAttributeValue(value) }));\n}\n\n/**\n * Convert internal span to OTLP span format (without resource wrapper)\n */\nfunction spanToOTLPSpan(span: SpanData) {\n return {\n traceId: span.traceId,\n spanId: span.spanId,\n parentSpanId: span.parentSpanId || '',\n name: span.name,\n kind: 1, // INTERNAL\n startTimeUnixNano: String(span.epochMs * 1_000_000),\n endTimeUnixNano: String(span.endEpochMs * 1_000_000),\n attributes: toOTLPAttributes(span.attributes as Record<string, string | number | boolean | undefined>),\n status: {\n code: span.status === 'ok' ? StatusCode.OK : StatusCode.ERROR,\n message: span.error?.message || '',\n },\n };\n}\n\n/**\n * Convert internal metric to OTLP metric format (without resource wrapper)\n */\nfunction metricToOTLPMetric(metric: MetricData) {\n const attributes = toOTLPAttributes(metric.attributes);\n const timeUnixNano = String(metric.timestamp * 1_000_000);\n\n if (metric.type === 'counter') {\n return {\n name: metric.name,\n sum: {\n dataPoints: [{\n attributes,\n timeUnixNano,\n asInt: metric.value,\n }],\n aggregationTemporality: 1, // DELTA\n isMonotonic: true,\n },\n };\n }\n\n // Histogram type\n if (metric.histogramData) {\n return {\n name: metric.name,\n histogram: {\n dataPoints: [{\n attributes,\n timeUnixNano,\n count: metric.histogramData.count,\n sum: metric.histogramData.sum,\n min: metric.histogramData.min,\n max: metric.histogramData.max,\n explicitBounds: metric.histogramData.bucketBoundaries,\n bucketCounts: metric.histogramData.bucketCounts,\n }],\n aggregationTemporality: 1, // DELTA\n },\n };\n }\n\n // Fallback for histogram without bucket data\n return {\n name: metric.name,\n gauge: {\n dataPoints: [{\n attributes,\n timeUnixNano,\n asDouble: metric.value,\n }],\n },\n };\n}\n\n/**\n * OTLP exporter for production telemetry\n *\n * Sends spans and metrics to OTLP-compatible backends like:\n * - Jaeger\n * - Grafana Tempo\n * - Honeycomb\n * - Datadog\n * - AWS X-Ray (with collector)\n */\nexport class OTLPExporter implements TelemetryExporterInterface {\n private config: Required<OTLPExporterConfig>;\n private serviceName: string;\n private serviceVersion: string;\n private spanBuffer: SpanData[] = [];\n private metricBuffer: MetricData[] = [];\n private flushIntervalId: ReturnType<typeof setInterval> | null = null;\n private readonly BUFFER_SIZE = 100;\n private readonly FLUSH_INTERVAL_MS = 5000;\n private isShutdown = false;\n\n constructor(\n config: OTLPExporterConfig,\n serviceName: string = 'omote-sdk',\n serviceVersion: string = '0.1.0'\n ) {\n // Validate endpoint URL: must be HTTPS or localhost\n const parsed = new URL(config.endpoint);\n if (parsed.protocol !== 'https:') {\n const isLocalhost = parsed.hostname === 'localhost' || parsed.hostname === '127.0.0.1' || parsed.hostname === '[::1]';\n if (!isLocalhost) {\n throw new Error('OTLP endpoint must use HTTPS (or localhost for development)');\n }\n }\n this.config = {\n endpoint: config.endpoint,\n timeoutMs: config.timeoutMs ?? 10000,\n headers: config.headers ? { ...config.headers } : {},\n };\n this.serviceName = serviceName;\n this.serviceVersion = serviceVersion;\n\n // Start periodic flush\n this.flushIntervalId = setInterval(() => {\n this.flush().catch(console.error);\n }, this.FLUSH_INTERVAL_MS);\n }\n\n exportSpan(span: SpanData): void {\n if (this.isShutdown) return;\n\n this.spanBuffer.push(span);\n\n if (this.spanBuffer.length >= this.BUFFER_SIZE) {\n this.flush().catch(console.error);\n }\n }\n\n exportMetric(metric: MetricData): void {\n if (this.isShutdown) return;\n\n this.metricBuffer.push(metric);\n\n if (this.metricBuffer.length >= this.BUFFER_SIZE) {\n this.flush().catch(console.error);\n }\n }\n\n async flush(): Promise<void> {\n if (this.isShutdown) return;\n\n const spans = this.spanBuffer.splice(0);\n const metrics = this.metricBuffer.splice(0);\n\n const promises: Promise<void>[] = [];\n\n // Export spans\n if (spans.length > 0) {\n promises.push(this.exportSpans(spans));\n }\n\n // Export metrics\n if (metrics.length > 0) {\n promises.push(this.exportMetrics(metrics));\n }\n\n await Promise.all(promises);\n }\n\n async shutdown(): Promise<void> {\n if (this.flushIntervalId) {\n clearInterval(this.flushIntervalId);\n this.flushIntervalId = null;\n }\n\n // Final flush before marking shutdown\n await this.flush();\n\n this.isShutdown = true;\n }\n\n private async exportSpans(spans: SpanData[]): Promise<void> {\n // Group all spans into a single ResourceSpan\n const resourceAttrs = [\n { key: 'service.name', value: { stringValue: this.serviceName } },\n { key: 'service.version', value: { stringValue: this.serviceVersion } },\n { key: 'telemetry.sdk.name', value: { stringValue: 'omote-sdk' } },\n { key: 'telemetry.sdk.language', value: { stringValue: 'javascript' } },\n ];\n\n const body = {\n resourceSpans: [{\n resource: { attributes: resourceAttrs },\n scopeSpans: [{\n scope: { name: 'omote-sdk', version: this.serviceVersion },\n spans: spans.map(spanToOTLPSpan),\n }],\n }],\n };\n\n const endpoint = this.config.endpoint.replace(/\\/$/, '') + '/v1/traces';\n await this.sendRequest(endpoint, body);\n }\n\n private async exportMetrics(metrics: MetricData[]): Promise<void> {\n // Group all metrics into a single ResourceMetric\n const resourceAttrs = [\n { key: 'service.name', value: { stringValue: this.serviceName } },\n { key: 'service.version', value: { stringValue: this.serviceVersion } },\n ];\n\n const body = {\n resourceMetrics: [{\n resource: { attributes: resourceAttrs },\n scopeMetrics: [{\n scope: { name: 'omote-sdk', version: this.serviceVersion },\n metrics: metrics.map(metricToOTLPMetric),\n }],\n }],\n };\n\n const endpoint = this.config.endpoint.replace(/\\/$/, '') + '/v1/metrics';\n await this.sendRequest(endpoint, body);\n }\n\n private async sendRequest(endpoint: string, body: unknown): Promise<void> {\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), this.config.timeoutMs);\n\n try {\n const response = await fetch(endpoint, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n ...this.config.headers,\n },\n body: JSON.stringify(body),\n signal: controller.signal,\n });\n\n if (!response.ok) {\n console.warn(`[OTLP] Export failed: ${response.status} ${response.statusText}`);\n }\n } catch (error) {\n if ((error as Error).name === 'AbortError') {\n console.warn('[OTLP] Export timed out');\n } else {\n console.warn('[OTLP] Export error:', error);\n }\n } finally {\n clearTimeout(timeoutId);\n }\n }\n}\n"],"mappings":";AAeA,IAAM,aAAa;AAAA,EACjB,OAAO;AAAA,EACP,IAAI;AAAA,EACJ,OAAO;AACT;AAKA,SAAS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B;AAAA,QACA,MAAM,KAAK,UAAU,IAAI;AAAA,QACzB,QAAQ,WAAW;AAAA,MACrB,CAAC;AAED,UAAI,CAAC,SAAS,IAAI;AAChB,gBAAQ,KAAK,yBAAyB,SAAS,MAAM,IAAI,SAAS,UAAU,EAAE;AAAA,MAChF;AAAA,IACF,SAAS,OAAO;AACd,UAAK,MAAgB,SAAS,cAAc;AAC1C,gBAAQ,KAAK,yBAAyB;AAAA,MACxC,OAAO;AACL,gBAAQ,KAAK,wBAAwB,KAAK;AAAA,MAC5C;AAAA,IACF,UAAE;AACA,mBAAa,SAAS;AAAA,IACxB;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -3139,6 +3139,83 @@ declare function preloadModels(urls: string[], onProgress?: (current: number, to
|
|
|
3139
3139
|
*/
|
|
3140
3140
|
declare function formatBytes(bytes: number): string;
|
|
3141
3141
|
|
|
3142
|
+
/**
|
|
3143
|
+
* Console Exporter
|
|
3144
|
+
*
|
|
3145
|
+
* Exports telemetry data to the browser console for development/debugging.
|
|
3146
|
+
*
|
|
3147
|
+
* @category Telemetry
|
|
3148
|
+
*/
|
|
3149
|
+
|
|
3150
|
+
/**
|
|
3151
|
+
* Span data structure for export
|
|
3152
|
+
*/
|
|
3153
|
+
interface SpanData {
|
|
3154
|
+
name: string;
|
|
3155
|
+
traceId: string;
|
|
3156
|
+
spanId: string;
|
|
3157
|
+
parentSpanId?: string;
|
|
3158
|
+
startTime: number;
|
|
3159
|
+
endTime: number;
|
|
3160
|
+
durationMs: number;
|
|
3161
|
+
/** Epoch timestamp in ms for OTLP export (start) */
|
|
3162
|
+
epochMs: number;
|
|
3163
|
+
/** Epoch timestamp in ms for OTLP export (end) */
|
|
3164
|
+
endEpochMs: number;
|
|
3165
|
+
status: 'ok' | 'error';
|
|
3166
|
+
attributes: SpanAttributes;
|
|
3167
|
+
error?: Error;
|
|
3168
|
+
}
|
|
3169
|
+
/**
|
|
3170
|
+
* Metric data structure for export
|
|
3171
|
+
*/
|
|
3172
|
+
interface MetricData {
|
|
3173
|
+
name: string;
|
|
3174
|
+
type: 'counter' | 'histogram';
|
|
3175
|
+
value: number;
|
|
3176
|
+
attributes: Record<string, string | number | boolean>;
|
|
3177
|
+
timestamp: number;
|
|
3178
|
+
/** Histogram bucket data for OTLP export */
|
|
3179
|
+
histogramData?: {
|
|
3180
|
+
count: number;
|
|
3181
|
+
sum: number;
|
|
3182
|
+
min: number;
|
|
3183
|
+
max: number;
|
|
3184
|
+
bucketBoundaries: number[];
|
|
3185
|
+
bucketCounts: number[];
|
|
3186
|
+
};
|
|
3187
|
+
}
|
|
3188
|
+
/**
|
|
3189
|
+
* Exporter interface that all exporters must implement
|
|
3190
|
+
*/
|
|
3191
|
+
interface TelemetryExporterInterface {
|
|
3192
|
+
/** Export a completed span */
|
|
3193
|
+
exportSpan(span: SpanData): void;
|
|
3194
|
+
/** Export a metric */
|
|
3195
|
+
exportMetric(metric: MetricData): void;
|
|
3196
|
+
/** Flush any buffered data */
|
|
3197
|
+
flush(): Promise<void>;
|
|
3198
|
+
/** Shutdown the exporter */
|
|
3199
|
+
shutdown(): Promise<void>;
|
|
3200
|
+
}
|
|
3201
|
+
/**
|
|
3202
|
+
* Console exporter for development/debugging
|
|
3203
|
+
*
|
|
3204
|
+
* Outputs spans and metrics to the browser console with formatting.
|
|
3205
|
+
*/
|
|
3206
|
+
declare class ConsoleExporter implements TelemetryExporterInterface {
|
|
3207
|
+
private enabled;
|
|
3208
|
+
private prefix;
|
|
3209
|
+
constructor(options?: {
|
|
3210
|
+
enabled?: boolean;
|
|
3211
|
+
prefix?: string;
|
|
3212
|
+
});
|
|
3213
|
+
exportSpan(span: SpanData): void;
|
|
3214
|
+
exportMetric(metric: MetricData): void;
|
|
3215
|
+
flush(): Promise<void>;
|
|
3216
|
+
shutdown(): Promise<void>;
|
|
3217
|
+
}
|
|
3218
|
+
|
|
3142
3219
|
/**
|
|
3143
3220
|
* Telemetry Types
|
|
3144
3221
|
*
|
|
@@ -3190,6 +3267,8 @@ interface TelemetryConfig {
|
|
|
3190
3267
|
metricsEnabled?: boolean;
|
|
3191
3268
|
/** Metrics export interval in ms. Default: 60000 */
|
|
3192
3269
|
metricsIntervalMs?: number;
|
|
3270
|
+
/** Custom exporter instance (overrides `exporter` when provided) */
|
|
3271
|
+
customExporter?: TelemetryExporterInterface;
|
|
3193
3272
|
}
|
|
3194
3273
|
/**
|
|
3195
3274
|
* Span attributes for model operations
|
|
@@ -3290,20 +3369,9 @@ declare const MetricNames: {
|
|
|
3290
3369
|
readonly COMPOSITOR_COMPOSE_LATENCY: "omote.compositor.compose.latency_us";
|
|
3291
3370
|
/** Counter: Frames exceeding budget threshold */
|
|
3292
3371
|
readonly AVATAR_FRAME_DROPS: "omote.avatar.frame.drops";
|
|
3372
|
+
/** Counter: Audio scheduling gaps (playback fell behind) */
|
|
3373
|
+
readonly AUDIO_SCHEDULE_GAP: "omote.audio.schedule_gap";
|
|
3293
3374
|
};
|
|
3294
|
-
/**
|
|
3295
|
-
* Centralized error type taxonomy for structured error reporting.
|
|
3296
|
-
*/
|
|
3297
|
-
declare const ErrorTypes: {
|
|
3298
|
-
readonly INFERENCE: "inference_error";
|
|
3299
|
-
readonly NETWORK: "network_error";
|
|
3300
|
-
readonly TIMEOUT: "timeout";
|
|
3301
|
-
readonly USER: "user_error";
|
|
3302
|
-
readonly RUNTIME: "runtime_error";
|
|
3303
|
-
readonly MEDIA: "media_error";
|
|
3304
|
-
readonly MODEL: "model_error";
|
|
3305
|
-
};
|
|
3306
|
-
type ErrorType = typeof ErrorTypes[keyof typeof ErrorTypes];
|
|
3307
3375
|
/**
|
|
3308
3376
|
* Histogram buckets for inference latency (ms)
|
|
3309
3377
|
*/
|
|
@@ -3379,6 +3447,7 @@ declare function getTelemetry(): OmoteTelemetry | null;
|
|
|
3379
3447
|
declare class OmoteTelemetry {
|
|
3380
3448
|
private config;
|
|
3381
3449
|
private exporter;
|
|
3450
|
+
private exporterReady;
|
|
3382
3451
|
private activeTraceId;
|
|
3383
3452
|
private metricsIntervalId;
|
|
3384
3453
|
private spanStack;
|
|
@@ -3454,7 +3523,7 @@ declare class OmoteTelemetry {
|
|
|
3454
3523
|
* });
|
|
3455
3524
|
* ```
|
|
3456
3525
|
*/
|
|
3457
|
-
recordHistogram(name: string, value: number, attributes?: Record<string, string | number | boolean
|
|
3526
|
+
recordHistogram(name: string, value: number, attributes?: Record<string, string | number | boolean>, bucketBoundaries?: number[]): void;
|
|
3458
3527
|
/**
|
|
3459
3528
|
* Generate unique key for metric with attributes
|
|
3460
3529
|
*/
|
|
@@ -3489,70 +3558,6 @@ declare class OmoteTelemetry {
|
|
|
3489
3558
|
} | null;
|
|
3490
3559
|
}
|
|
3491
3560
|
|
|
3492
|
-
/**
|
|
3493
|
-
* Console Exporter
|
|
3494
|
-
*
|
|
3495
|
-
* Exports telemetry data to the browser console for development/debugging.
|
|
3496
|
-
*
|
|
3497
|
-
* @category Telemetry
|
|
3498
|
-
*/
|
|
3499
|
-
|
|
3500
|
-
/**
|
|
3501
|
-
* Span data structure for export
|
|
3502
|
-
*/
|
|
3503
|
-
interface SpanData {
|
|
3504
|
-
name: string;
|
|
3505
|
-
traceId: string;
|
|
3506
|
-
spanId: string;
|
|
3507
|
-
parentSpanId?: string;
|
|
3508
|
-
startTime: number;
|
|
3509
|
-
endTime: number;
|
|
3510
|
-
durationMs: number;
|
|
3511
|
-
status: 'ok' | 'error';
|
|
3512
|
-
attributes: SpanAttributes;
|
|
3513
|
-
error?: Error;
|
|
3514
|
-
}
|
|
3515
|
-
/**
|
|
3516
|
-
* Metric data structure for export
|
|
3517
|
-
*/
|
|
3518
|
-
interface MetricData {
|
|
3519
|
-
name: string;
|
|
3520
|
-
type: 'counter' | 'histogram';
|
|
3521
|
-
value: number;
|
|
3522
|
-
attributes: Record<string, string | number | boolean>;
|
|
3523
|
-
timestamp: number;
|
|
3524
|
-
}
|
|
3525
|
-
/**
|
|
3526
|
-
* Exporter interface that all exporters must implement
|
|
3527
|
-
*/
|
|
3528
|
-
interface TelemetryExporterInterface {
|
|
3529
|
-
/** Export a completed span */
|
|
3530
|
-
exportSpan(span: SpanData): void;
|
|
3531
|
-
/** Export a metric */
|
|
3532
|
-
exportMetric(metric: MetricData): void;
|
|
3533
|
-
/** Flush any buffered data */
|
|
3534
|
-
flush(): Promise<void>;
|
|
3535
|
-
/** Shutdown the exporter */
|
|
3536
|
-
shutdown(): Promise<void>;
|
|
3537
|
-
}
|
|
3538
|
-
/**
|
|
3539
|
-
* Console exporter for development/debugging
|
|
3540
|
-
*
|
|
3541
|
-
* Outputs spans and metrics to the browser console with formatting.
|
|
3542
|
-
*/
|
|
3543
|
-
declare class ConsoleExporter implements TelemetryExporterInterface {
|
|
3544
|
-
private enabled;
|
|
3545
|
-
private prefix;
|
|
3546
|
-
constructor(options?: {
|
|
3547
|
-
enabled?: boolean;
|
|
3548
|
-
prefix?: string;
|
|
3549
|
-
});
|
|
3550
|
-
exportSpan(span: SpanData): void;
|
|
3551
|
-
exportMetric(metric: MetricData): void;
|
|
3552
|
-
flush(): Promise<void>;
|
|
3553
|
-
shutdown(): Promise<void>;
|
|
3554
|
-
}
|
|
3555
|
-
|
|
3556
3561
|
/**
|
|
3557
3562
|
* OTLP Exporter
|
|
3558
3563
|
*
|
|
@@ -4831,4 +4836,4 @@ declare class VoiceOrchestrator extends EventEmitter<VoiceOrchestratorEvents> {
|
|
|
4831
4836
|
private setState;
|
|
4832
4837
|
}
|
|
4833
4838
|
|
|
4834
|
-
export { type A2EBackend, type A2EModelInfo, A2EProcessor, type A2EProcessorConfig, type A2EResult, A2EUnifiedAdapter, ALL_AUS, ARKIT_BLENDSHAPES, type AUActivation, AU_TO_ARKIT, type ActiveSpan, type AnimationClip, type AnimationController, AnimationGraph, type AnimationGraphConfig, type AnimationGraphEvents, type AnimationLayer, type AnimationOutput, type AnimationSource, type AnimationSourceOptions, type AnimationState, type AnimationStateName, type AnimationTrigger, AudioChunkCoalescer, type AudioChunkCoalescerOptions, AudioEnergyAnalyzer, AudioScheduler, type AudioSchedulerOptions, BLENDSHAPE_TO_GROUP, type BackendPreference, type BlendWeight, type BlendshapeGroup, BlendshapeSmoother, type BlendshapeSmootherConfig, type BoneFilterConfig, type CacheConfig, type CacheSpanAttributes, CharacterController, type CharacterControllerConfig, type CharacterProfile, type CharacterUpdateInput, type CharacterUpdateOutput, ConsoleExporter, type ConversationalState, type CreateA2EConfig, type CreateKokoroTTSConfig, type CreateSenseVoiceConfig, type CreateTTSPlayerConfig, DEFAULT_ANIMATION_CONFIG, DEFAULT_BONE_FILTER, DEFAULT_MODEL_URLS, EMOTION_NAMES, EMOTION_TO_AU, EMOTION_VECTOR_SIZE, EXPLICIT_EMOTION_COUNT, type ElevenLabsConfig, ElevenLabsTTSBackend, type EmotionAnimationMap, EmotionController, type EmotionLabel, type EmotionName, type EmotionPresetName, EmotionPresets, EmotionResolver, type EmotionWeights, EmphasisDetector,
|
|
4839
|
+
export { type A2EBackend, type A2EModelInfo, A2EProcessor, type A2EProcessorConfig, type A2EResult, A2EUnifiedAdapter, ALL_AUS, ARKIT_BLENDSHAPES, type AUActivation, AU_TO_ARKIT, type ActiveSpan, type AnimationClip, type AnimationController, AnimationGraph, type AnimationGraphConfig, type AnimationGraphEvents, type AnimationLayer, type AnimationOutput, type AnimationSource, type AnimationSourceOptions, type AnimationState, type AnimationStateName, type AnimationTrigger, AudioChunkCoalescer, type AudioChunkCoalescerOptions, AudioEnergyAnalyzer, AudioScheduler, type AudioSchedulerOptions, BLENDSHAPE_TO_GROUP, type BackendPreference, type BlendWeight, type BlendshapeGroup, BlendshapeSmoother, type BlendshapeSmootherConfig, type BoneFilterConfig, type CacheConfig, type CacheSpanAttributes, CharacterController, type CharacterControllerConfig, type CharacterProfile, type CharacterUpdateInput, type CharacterUpdateOutput, ConsoleExporter, type ConversationalState, type CreateA2EConfig, type CreateKokoroTTSConfig, type CreateSenseVoiceConfig, type CreateTTSPlayerConfig, DEFAULT_ANIMATION_CONFIG, DEFAULT_BONE_FILTER, DEFAULT_MODEL_URLS, EMOTION_NAMES, EMOTION_TO_AU, EMOTION_VECTOR_SIZE, EXPLICIT_EMOTION_COUNT, type ElevenLabsConfig, ElevenLabsTTSBackend, type EmotionAnimationMap, EmotionController, type EmotionLabel, type EmotionName, type EmotionPresetName, EmotionPresets, EmotionResolver, type EmotionWeights, EmphasisDetector, EventEmitter, type ExpressionProfile, FaceCompositor, type FaceCompositorConfig, type FaceCompositorInput, type FaceCompositorOutput, type FetchWithCacheOptions, type FrameSource, type FullFaceFrame, HF_CDN_URLS, INFERENCE_LATENCY_BUCKETS, type InferenceFactoryConfig, type InferenceSpanAttributes, type InterruptionConfig, type InterruptionEvents, InterruptionHandler, KOKORO_VOICES, type KokoroStreamChunk, type KokoroTTSConfig, type KokoroTTSModelInfo, type KokoroTTSResult, KokoroTTSUnifiedAdapter, type KokoroVoiceName, LAM_BLENDSHAPES, type LifeLayerConfig, type LifeLayerInput, type LifeLayerOutput, type LoadingProgress, MIXAMO_PREFIX, MODEL_LOAD_TIME_BUCKETS, type MetricData, MetricNames, MicLipSync, type MicLipSyncConfig, type MicLipSyncEvents, type MicLipSyncFrame, type MicLipSyncState, MicrophoneCapture, type MicrophoneCaptureConfig, ModelCache, type ModelSpanAttributes, type ModelUrlKey, OTLPExporter, type OTLPExporterConfig, OmoteEvents, OmoteTelemetry, PRESERVE_POSITION_BONES, PlaybackPipeline, type PlaybackPipelineConfig, type PlaybackPipelineEvents, type PlaybackState, ProceduralLifeLayer, type Quat, type QuotaInfo, type ResolvedEmotion, type ResponseHandler, RingBuffer, type RuntimeBackend, type SafariSpeechConfig, SafariSpeechRecognition, type SamplingConfig, type SenseVoiceBackend, type SenseVoiceConfig, type SenseVoiceLanguage, type SenseVoiceModelInfo, type SenseVoiceResult, SenseVoiceUnifiedAdapter, type SenseVoiceWorkerConfig, type SileroVADBackend, type SileroVADConfig, type SileroVADFactoryConfig, SileroVADUnifiedAdapter, type SpanAttributes, type SpanData, type SpeechErrorCallback, SpeechListener, type SpeechListenerConfig, type SpeechListenerEvents, type SpeechListenerState, type SpeechRecognitionResult, type SpeechResultCallback, type SpeechSegment, type SynthesizeOptions, type TTSBackend, type TTSChunk, TTSPlayback, type TTSPlaybackConfig, type TTSPlaybackEvents, TTSPlayer, TTSSpeaker, type TTSSpeakerConfig, type TTSStreamOptions, type TelemetryConfig, type TelemetryExporter, type TelemetryExporterInterface, type TrackDescriptor, type TranscriptResult, type Transition, UnifiedInferenceWorker, type VADBackend, type VADModelInfo, type VADResult, type VADWorkerConfig, type VADWorkerModelInfo, type ValidationResult, type Vec3, VoiceOrchestrator, type VoiceOrchestratorCloudConfig, type VoiceOrchestratorConfig, type VoiceOrchestratorEvents, type VoiceOrchestratorLocalConfig, type VoicePipelineState, type WorkerHealthState, analyzeTextEmotion, applyProfile, blendEmotions, calculatePeak, calculateRMS, configureCacheLimit, configureModelUrls, configureTelemetry, createA2E, createEmotionVector, createKokoroTTS, createSenseVoice, createSileroVAD, createTTSPlayer, fetchWithCache, float32ToPcm16, formatBytes, getCacheConfig, getCacheKey, getEmotionPreset, getModelCache, getOptimalWasmThreads, getRecommendedBackend, getTelemetry, hasWebGPUApi, int16ToFloat32, isAndroid, isIOS, isIOSSafari, isMobile, isSafari, isSpeechRecognitionAvailable, isWebGPUAvailable, lerpBlendshapes, lerpEmotion, listVoices as listKokoroVoices, parseEmotionTags, pcm16ToFloat32, preloadModels, resampleLinear, resetModelUrls, resolveBackend, resolveEmotion, shouldEnableWasmProxy, shouldKeepTrack, shouldUseNativeASR, shouldUseServerA2E, stripMixamoPrefix, ttsToPlaybackFormat, validateTTSInput };
|