@omote/core 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,141 @@
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 data */
30
+ data?: Record<string, unknown>;
31
+ /** Optional error object */
32
+ error?: Error;
33
+ }
34
+ /**
35
+ * Log output sink interface
36
+ */
37
+ interface LogSink {
38
+ (entry: LogEntry): void;
39
+ }
40
+ /**
41
+ * Log formatter interface
42
+ */
43
+ interface LogFormatter {
44
+ (entry: LogEntry): string;
45
+ }
46
+ /**
47
+ * Global logging configuration
48
+ */
49
+ interface LoggingConfig {
50
+ /** Minimum log level to output (default: 'info') */
51
+ level: LogLevel;
52
+ /** Enable/disable logging globally (default: true) */
53
+ enabled: boolean;
54
+ /** Output format: 'json' for structured, 'pretty' for human-readable */
55
+ format: 'json' | 'pretty';
56
+ /** Custom output sink (default: console) */
57
+ sink?: LogSink;
58
+ /** Include timestamps in output (default: true) */
59
+ timestamps?: boolean;
60
+ /** Include module name in output (default: true) */
61
+ includeModule?: boolean;
62
+ }
63
+ /**
64
+ * Logger interface for module-specific logging
65
+ */
66
+ interface ILogger {
67
+ error(message: string, data?: Record<string, unknown>): void;
68
+ warn(message: string, data?: Record<string, unknown>): void;
69
+ info(message: string, data?: Record<string, unknown>): void;
70
+ debug(message: string, data?: Record<string, unknown>): void;
71
+ trace(message: string, data?: Record<string, unknown>): void;
72
+ verbose(message: string, data?: Record<string, unknown>): void;
73
+ /** Create a child logger with a sub-module name */
74
+ child(subModule: string): ILogger;
75
+ /** Get the module name for this logger */
76
+ readonly module: string;
77
+ }
78
+ /**
79
+ * Default configuration
80
+ */
81
+ declare const DEFAULT_LOGGING_CONFIG: LoggingConfig;
82
+
83
+ /**
84
+ * Omote SDK Logger
85
+ *
86
+ * Unified logging system with:
87
+ * - 6 log levels (error, warn, info, debug, trace, verbose)
88
+ * - Structured JSON output for machine parsing
89
+ * - Pretty output for human readability
90
+ * - Module-based child loggers
91
+ * - Runtime configuration
92
+ * - Browser and Node.js compatible
93
+ */
94
+
95
+ /**
96
+ * Configure global logging settings
97
+ */
98
+ declare function configureLogging(config: Partial<LoggingConfig>): void;
99
+ /**
100
+ * Get current logging configuration
101
+ */
102
+ declare function getLoggingConfig(): LoggingConfig;
103
+ /**
104
+ * Reset logging configuration to defaults
105
+ */
106
+ declare function resetLoggingConfig(): void;
107
+ /**
108
+ * Set log level at runtime
109
+ */
110
+ declare function setLogLevel(level: LogLevel): void;
111
+ /**
112
+ * Enable or disable logging
113
+ */
114
+ declare function setLoggingEnabled(enabled: boolean): void;
115
+ /**
116
+ * Create a logger for a specific module
117
+ *
118
+ * @param module - Module name (e.g., 'LocalInference', 'ModelCache')
119
+ * @returns Logger instance
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * const logger = createLogger('LocalInference');
124
+ * logger.info('Model loaded', { backend: 'webgpu', loadTimeMs: 1234 });
125
+ * ```
126
+ */
127
+ declare function createLogger(module: string): ILogger;
128
+ /**
129
+ * Clear logger cache (useful for testing)
130
+ */
131
+ declare function clearLoggerCache(): void;
132
+ /**
133
+ * No-op logger for when logging is completely disabled
134
+ */
135
+ declare const noopLogger: ILogger;
136
+ /**
137
+ * Get a no-op logger (for production builds that tree-shake logging)
138
+ */
139
+ declare function getNoopLogger(): ILogger;
140
+
141
+ export { DEFAULT_LOGGING_CONFIG as D, type ILogger as I, type LogFormatter as L, type LogLevel as a, type LogEntry as b, type LogSink as c, type LoggingConfig as d, LOG_LEVEL_PRIORITY as e, configureLogging as f, getLoggingConfig as g, setLoggingEnabled as h, createLogger as i, clearLoggerCache as j, getNoopLogger as k, noopLogger as n, resetLoggingConfig as r, setLogLevel as s };
@@ -0,0 +1,141 @@
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 data */
30
+ data?: Record<string, unknown>;
31
+ /** Optional error object */
32
+ error?: Error;
33
+ }
34
+ /**
35
+ * Log output sink interface
36
+ */
37
+ interface LogSink {
38
+ (entry: LogEntry): void;
39
+ }
40
+ /**
41
+ * Log formatter interface
42
+ */
43
+ interface LogFormatter {
44
+ (entry: LogEntry): string;
45
+ }
46
+ /**
47
+ * Global logging configuration
48
+ */
49
+ interface LoggingConfig {
50
+ /** Minimum log level to output (default: 'info') */
51
+ level: LogLevel;
52
+ /** Enable/disable logging globally (default: true) */
53
+ enabled: boolean;
54
+ /** Output format: 'json' for structured, 'pretty' for human-readable */
55
+ format: 'json' | 'pretty';
56
+ /** Custom output sink (default: console) */
57
+ sink?: LogSink;
58
+ /** Include timestamps in output (default: true) */
59
+ timestamps?: boolean;
60
+ /** Include module name in output (default: true) */
61
+ includeModule?: boolean;
62
+ }
63
+ /**
64
+ * Logger interface for module-specific logging
65
+ */
66
+ interface ILogger {
67
+ error(message: string, data?: Record<string, unknown>): void;
68
+ warn(message: string, data?: Record<string, unknown>): void;
69
+ info(message: string, data?: Record<string, unknown>): void;
70
+ debug(message: string, data?: Record<string, unknown>): void;
71
+ trace(message: string, data?: Record<string, unknown>): void;
72
+ verbose(message: string, data?: Record<string, unknown>): void;
73
+ /** Create a child logger with a sub-module name */
74
+ child(subModule: string): ILogger;
75
+ /** Get the module name for this logger */
76
+ readonly module: string;
77
+ }
78
+ /**
79
+ * Default configuration
80
+ */
81
+ declare const DEFAULT_LOGGING_CONFIG: LoggingConfig;
82
+
83
+ /**
84
+ * Omote SDK Logger
85
+ *
86
+ * Unified logging system with:
87
+ * - 6 log levels (error, warn, info, debug, trace, verbose)
88
+ * - Structured JSON output for machine parsing
89
+ * - Pretty output for human readability
90
+ * - Module-based child loggers
91
+ * - Runtime configuration
92
+ * - Browser and Node.js compatible
93
+ */
94
+
95
+ /**
96
+ * Configure global logging settings
97
+ */
98
+ declare function configureLogging(config: Partial<LoggingConfig>): void;
99
+ /**
100
+ * Get current logging configuration
101
+ */
102
+ declare function getLoggingConfig(): LoggingConfig;
103
+ /**
104
+ * Reset logging configuration to defaults
105
+ */
106
+ declare function resetLoggingConfig(): void;
107
+ /**
108
+ * Set log level at runtime
109
+ */
110
+ declare function setLogLevel(level: LogLevel): void;
111
+ /**
112
+ * Enable or disable logging
113
+ */
114
+ declare function setLoggingEnabled(enabled: boolean): void;
115
+ /**
116
+ * Create a logger for a specific module
117
+ *
118
+ * @param module - Module name (e.g., 'LocalInference', 'ModelCache')
119
+ * @returns Logger instance
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * const logger = createLogger('LocalInference');
124
+ * logger.info('Model loaded', { backend: 'webgpu', loadTimeMs: 1234 });
125
+ * ```
126
+ */
127
+ declare function createLogger(module: string): ILogger;
128
+ /**
129
+ * Clear logger cache (useful for testing)
130
+ */
131
+ declare function clearLoggerCache(): void;
132
+ /**
133
+ * No-op logger for when logging is completely disabled
134
+ */
135
+ declare const noopLogger: ILogger;
136
+ /**
137
+ * Get a no-op logger (for production builds that tree-shake logging)
138
+ */
139
+ declare function getNoopLogger(): ILogger;
140
+
141
+ export { DEFAULT_LOGGING_CONFIG as D, type ILogger as I, type LogFormatter as L, type LogLevel as a, type LogEntry as b, type LogSink as c, type LoggingConfig as d, LOG_LEVEL_PRIORITY as e, configureLogging as f, getLoggingConfig as g, setLoggingEnabled as h, createLogger as i, clearLoggerCache as j, getNoopLogger as k, noopLogger as n, resetLoggingConfig as r, setLogLevel as s };
@@ -0,0 +1,287 @@
1
+ // src/logging/types.ts
2
+ var LOG_LEVEL_PRIORITY = {
3
+ error: 0,
4
+ warn: 1,
5
+ info: 2,
6
+ debug: 3,
7
+ trace: 4,
8
+ verbose: 5
9
+ };
10
+ var DEFAULT_LOGGING_CONFIG = {
11
+ level: "info",
12
+ enabled: true,
13
+ format: "pretty",
14
+ timestamps: true,
15
+ includeModule: true
16
+ };
17
+
18
+ // src/logging/formatters.ts
19
+ var COLORS = {
20
+ reset: "\x1B[0m",
21
+ red: "\x1B[31m",
22
+ yellow: "\x1B[33m",
23
+ blue: "\x1B[34m",
24
+ cyan: "\x1B[36m",
25
+ gray: "\x1B[90m",
26
+ white: "\x1B[37m",
27
+ magenta: "\x1B[35m"
28
+ };
29
+ var LEVEL_COLORS = {
30
+ error: COLORS.red,
31
+ warn: COLORS.yellow,
32
+ info: COLORS.blue,
33
+ debug: COLORS.cyan,
34
+ trace: COLORS.magenta,
35
+ verbose: COLORS.gray
36
+ };
37
+ var LEVEL_NAMES = {
38
+ error: "ERROR ",
39
+ warn: "WARN ",
40
+ info: "INFO ",
41
+ debug: "DEBUG ",
42
+ trace: "TRACE ",
43
+ verbose: "VERBOSE"
44
+ };
45
+ var isBrowser = typeof window !== "undefined";
46
+ function formatTimestamp(timestamp) {
47
+ const date = new Date(timestamp);
48
+ return date.toISOString().substring(11, 23);
49
+ }
50
+ function safeStringify(data) {
51
+ const seen = /* @__PURE__ */ new WeakSet();
52
+ return JSON.stringify(data, (key, value) => {
53
+ if (typeof value === "object" && value !== null) {
54
+ if (seen.has(value)) {
55
+ return "[Circular]";
56
+ }
57
+ seen.add(value);
58
+ }
59
+ if (value instanceof Error) {
60
+ return {
61
+ name: value.name,
62
+ message: value.message,
63
+ stack: value.stack
64
+ };
65
+ }
66
+ if (value instanceof Float32Array || value instanceof Int16Array) {
67
+ return `${value.constructor.name}(${value.length})`;
68
+ }
69
+ if (ArrayBuffer.isView(value)) {
70
+ return `${value.constructor.name}(${value.byteLength})`;
71
+ }
72
+ return value;
73
+ });
74
+ }
75
+ var jsonFormatter = (entry) => {
76
+ const output = {
77
+ timestamp: entry.timestamp,
78
+ level: entry.level,
79
+ module: entry.module,
80
+ message: entry.message
81
+ };
82
+ if (entry.data && Object.keys(entry.data).length > 0) {
83
+ output.data = entry.data;
84
+ }
85
+ if (entry.error) {
86
+ output.error = {
87
+ name: entry.error.name,
88
+ message: entry.error.message,
89
+ stack: entry.error.stack
90
+ };
91
+ }
92
+ return safeStringify(output);
93
+ };
94
+ var prettyFormatter = (entry) => {
95
+ const time = formatTimestamp(entry.timestamp);
96
+ const level = LEVEL_NAMES[entry.level];
97
+ const module = entry.module;
98
+ const message = entry.message;
99
+ let output;
100
+ if (isBrowser) {
101
+ output = `${time} ${level} [${module}] ${message}`;
102
+ } else {
103
+ const color = LEVEL_COLORS[entry.level];
104
+ output = `${COLORS.gray}${time}${COLORS.reset} ${color}${level}${COLORS.reset} ${COLORS.cyan}[${module}]${COLORS.reset} ${message}`;
105
+ }
106
+ if (entry.data && Object.keys(entry.data).length > 0) {
107
+ const dataStr = safeStringify(entry.data);
108
+ if (dataStr.length > 80) {
109
+ output += "\n " + JSON.stringify(entry.data, null, 2).replace(/\n/g, "\n ");
110
+ } else {
111
+ output += " " + dataStr;
112
+ }
113
+ }
114
+ if (entry.error) {
115
+ output += `
116
+ ${entry.error.name}: ${entry.error.message}`;
117
+ if (entry.error.stack) {
118
+ const stackLines = entry.error.stack.split("\n").slice(1, 4);
119
+ output += "\n " + stackLines.join("\n ");
120
+ }
121
+ }
122
+ return output;
123
+ };
124
+ function getFormatter(format) {
125
+ return format === "json" ? jsonFormatter : prettyFormatter;
126
+ }
127
+ function createBrowserConsoleArgs(entry) {
128
+ const time = formatTimestamp(entry.timestamp);
129
+ const level = entry.level.toUpperCase().padEnd(7);
130
+ const module = entry.module;
131
+ const message = entry.message;
132
+ const styles = {
133
+ time: "color: gray;",
134
+ error: "color: red; font-weight: bold;",
135
+ warn: "color: orange; font-weight: bold;",
136
+ info: "color: blue;",
137
+ debug: "color: cyan;",
138
+ trace: "color: magenta;",
139
+ verbose: "color: gray;",
140
+ module: "color: teal; font-weight: bold;",
141
+ message: "color: inherit;"
142
+ };
143
+ let formatStr = "%c%s %c%s %c[%s]%c %s";
144
+ const args = [
145
+ styles.time,
146
+ time,
147
+ styles[entry.level],
148
+ level,
149
+ styles.module,
150
+ module,
151
+ styles.message,
152
+ message
153
+ ];
154
+ if (entry.data && Object.keys(entry.data).length > 0) {
155
+ formatStr += " %o";
156
+ args.push(entry.data);
157
+ }
158
+ return [formatStr, ...args];
159
+ }
160
+
161
+ // src/logging/Logger.ts
162
+ var isBrowser2 = typeof window !== "undefined";
163
+ var globalConfig = { ...DEFAULT_LOGGING_CONFIG };
164
+ function configureLogging(config) {
165
+ globalConfig = { ...globalConfig, ...config };
166
+ }
167
+ function getLoggingConfig() {
168
+ return { ...globalConfig };
169
+ }
170
+ function resetLoggingConfig() {
171
+ globalConfig = { ...DEFAULT_LOGGING_CONFIG };
172
+ }
173
+ function setLogLevel(level) {
174
+ globalConfig.level = level;
175
+ }
176
+ function setLoggingEnabled(enabled) {
177
+ globalConfig.enabled = enabled;
178
+ }
179
+ var consoleSink = (entry) => {
180
+ const consoleMethod = entry.level === "error" ? "error" : entry.level === "warn" ? "warn" : "log";
181
+ if (globalConfig.format === "pretty" && isBrowser2) {
182
+ const args = createBrowserConsoleArgs(entry);
183
+ console[consoleMethod](...args);
184
+ } else {
185
+ const formatter = getFormatter(globalConfig.format);
186
+ const formatted = formatter(entry);
187
+ console[consoleMethod](formatted);
188
+ }
189
+ };
190
+ function getActiveSink() {
191
+ return globalConfig.sink || consoleSink;
192
+ }
193
+ function shouldLog(level) {
194
+ if (!globalConfig.enabled) return false;
195
+ return LOG_LEVEL_PRIORITY[level] <= LOG_LEVEL_PRIORITY[globalConfig.level];
196
+ }
197
+ var Logger = class _Logger {
198
+ constructor(module) {
199
+ this.module = module;
200
+ }
201
+ log(level, message, data) {
202
+ if (!shouldLog(level)) return;
203
+ const entry = {
204
+ timestamp: Date.now(),
205
+ level,
206
+ module: this.module,
207
+ message,
208
+ data
209
+ };
210
+ if (data?.error instanceof Error) {
211
+ entry.error = data.error;
212
+ const { error, ...rest } = data;
213
+ entry.data = Object.keys(rest).length > 0 ? rest : void 0;
214
+ }
215
+ getActiveSink()(entry);
216
+ }
217
+ error(message, data) {
218
+ this.log("error", message, data);
219
+ }
220
+ warn(message, data) {
221
+ this.log("warn", message, data);
222
+ }
223
+ info(message, data) {
224
+ this.log("info", message, data);
225
+ }
226
+ debug(message, data) {
227
+ this.log("debug", message, data);
228
+ }
229
+ trace(message, data) {
230
+ this.log("trace", message, data);
231
+ }
232
+ verbose(message, data) {
233
+ this.log("verbose", message, data);
234
+ }
235
+ child(subModule) {
236
+ return new _Logger(`${this.module}.${subModule}`);
237
+ }
238
+ };
239
+ var loggerCache = /* @__PURE__ */ new Map();
240
+ function createLogger(module) {
241
+ let logger = loggerCache.get(module);
242
+ if (!logger) {
243
+ logger = new Logger(module);
244
+ loggerCache.set(module, logger);
245
+ }
246
+ return logger;
247
+ }
248
+ function clearLoggerCache() {
249
+ loggerCache.clear();
250
+ }
251
+ var noopLogger = {
252
+ module: "noop",
253
+ error: () => {
254
+ },
255
+ warn: () => {
256
+ },
257
+ info: () => {
258
+ },
259
+ debug: () => {
260
+ },
261
+ trace: () => {
262
+ },
263
+ verbose: () => {
264
+ },
265
+ child: () => noopLogger
266
+ };
267
+ function getNoopLogger() {
268
+ return noopLogger;
269
+ }
270
+
271
+ export {
272
+ LOG_LEVEL_PRIORITY,
273
+ DEFAULT_LOGGING_CONFIG,
274
+ jsonFormatter,
275
+ prettyFormatter,
276
+ getFormatter,
277
+ configureLogging,
278
+ getLoggingConfig,
279
+ resetLoggingConfig,
280
+ setLogLevel,
281
+ setLoggingEnabled,
282
+ createLogger,
283
+ clearLoggerCache,
284
+ noopLogger,
285
+ getNoopLogger
286
+ };
287
+ //# sourceMappingURL=chunk-ESU52TDS.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/logging/types.ts","../src/logging/formatters.ts","../src/logging/Logger.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 data */\n data?: Record<string, unknown>;\n /** Optional error object */\n error?: Error;\n}\n\n/**\n * Log output sink interface\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 */\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.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 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 * 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';\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 any)[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 any)[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: Date.now(),\n level,\n module: this.module,\n message,\n data,\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"],"mappings":";AAiBO,IAAM,qBAA+C;AAAA,EAC1D,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,SAAS;AACX;AAyEO,IAAM,yBAAwC;AAAA,EACnD,OAAO;AAAA,EACP,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,eAAe;AACjB;;;AC9FA,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,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AAAA,EACP,SAAS;AACX;AAKA,IAAM,YAAY,OAAO,WAAW;AAKpC,SAAS,gBAAgB,WAA2B;AAClD,QAAM,OAAO,IAAI,KAAK,SAAS;AAC/B,SAAO,KAAK,YAAY,EAAE,UAAU,IAAI,EAAE;AAC5C;AAKA,SAAS,cAAc,MAAuB;AAC5C,QAAM,OAAO,oBAAI,QAAQ;AACzB,SAAO,KAAK,UAA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;AAC1B,gBAAY,IAAI,QAAQ,MAAM;AAAA,EAChC;AACA,SAAO;AACT;AAKO,SAAS,mBAAyB;AACvC,cAAY,MAAM;AACpB;AAKO,IAAM,aAAsB;AAAA,EACjC,QAAQ;AAAA,EACR,OAAO,MAAM;AAAA,EAAC;AAAA,EACd,MAAM,MAAM;AAAA,EAAC;AAAA,EACb,MAAM,MAAM;AAAA,EAAC;AAAA,EACb,OAAO,MAAM;AAAA,EAAC;AAAA,EACd,OAAO,MAAM;AAAA,EAAC;AAAA,EACd,SAAS,MAAM;AAAA,EAAC;AAAA,EAChB,OAAO,MAAM;AACf;AAKO,SAAS,gBAAyB;AACvC,SAAO;AACT;","names":["isBrowser"]}
@@ -0,0 +1,8 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+
5
+ export {
6
+ __publicField
7
+ };
8
+ //# sourceMappingURL=chunk-NSSMTXJJ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}