@agentxjs/core 1.9.5-dev → 1.9.6-dev

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.
Files changed (80) hide show
  1. package/dist/Processor-DT0N1qI6.d.ts +64 -0
  2. package/dist/agent/engine/internal/index.d.ts +223 -0
  3. package/dist/agent/engine/internal/index.js +24 -0
  4. package/dist/agent/engine/internal/index.js.map +1 -0
  5. package/dist/agent/engine/mealy/index.d.ts +157 -0
  6. package/dist/agent/engine/mealy/index.js +26 -0
  7. package/dist/agent/engine/mealy/index.js.map +1 -0
  8. package/dist/agent/index.d.ts +244 -0
  9. package/dist/agent/index.js +66 -0
  10. package/dist/agent/index.js.map +1 -0
  11. package/dist/agent/types/index.d.ts +322 -0
  12. package/dist/agent/types/index.js +12 -0
  13. package/dist/agent/types/index.js.map +1 -0
  14. package/dist/base-m40r3Qgu.d.ts +157 -0
  15. package/dist/bus-uF1DM2ox.d.ts +906 -0
  16. package/dist/chunk-7D4SUZUM.js +38 -0
  17. package/dist/chunk-7D4SUZUM.js.map +1 -0
  18. package/dist/chunk-7ZDX3O6I.js +173 -0
  19. package/dist/chunk-7ZDX3O6I.js.map +1 -0
  20. package/dist/chunk-AT5P47YA.js +543 -0
  21. package/dist/chunk-AT5P47YA.js.map +1 -0
  22. package/dist/chunk-E5FPOAPO.js +123 -0
  23. package/dist/chunk-E5FPOAPO.js.map +1 -0
  24. package/dist/chunk-EKHT54KN.js +272 -0
  25. package/dist/chunk-EKHT54KN.js.map +1 -0
  26. package/dist/chunk-I7GYR3MN.js +502 -0
  27. package/dist/chunk-I7GYR3MN.js.map +1 -0
  28. package/dist/chunk-K6WXQ2RW.js +38 -0
  29. package/dist/chunk-K6WXQ2RW.js.map +1 -0
  30. package/dist/chunk-RL3JRNXM.js +3 -0
  31. package/dist/chunk-RL3JRNXM.js.map +1 -0
  32. package/dist/combinators-nEa5dD0T.d.ts +271 -0
  33. package/dist/common/index.d.ts +1 -0
  34. package/dist/common/index.js +2 -0
  35. package/dist/common/index.js.map +1 -0
  36. package/dist/common/logger/index.d.ts +163 -0
  37. package/dist/common/logger/index.js +184 -0
  38. package/dist/common/logger/index.js.map +1 -0
  39. package/dist/container/index.d.ts +110 -0
  40. package/dist/container/index.js +127 -0
  41. package/dist/container/index.js.map +1 -0
  42. package/dist/driver/index.d.ts +266 -0
  43. package/dist/driver/index.js +1 -0
  44. package/dist/driver/index.js.map +1 -0
  45. package/dist/event/index.d.ts +55 -0
  46. package/dist/event/index.js +60 -0
  47. package/dist/event/index.js.map +1 -0
  48. package/dist/event/types/index.d.ts +1149 -0
  49. package/dist/event/types/index.js +56 -0
  50. package/dist/event/types/index.js.map +1 -0
  51. package/dist/event-CDuTzs__.d.ts +296 -0
  52. package/dist/image/index.d.ts +112 -0
  53. package/dist/image/index.js +151 -0
  54. package/dist/image/index.js.map +1 -0
  55. package/dist/index.d.ts +8 -0
  56. package/dist/index.js +67 -0
  57. package/dist/index.js.map +1 -0
  58. package/dist/message-BMrMm1pq.d.ts +305 -0
  59. package/dist/mq/index.d.ts +165 -0
  60. package/dist/mq/index.js +37 -0
  61. package/dist/mq/index.js.map +1 -0
  62. package/dist/network/index.d.ts +567 -0
  63. package/dist/network/index.js +435 -0
  64. package/dist/network/index.js.map +1 -0
  65. package/dist/persistence/index.d.ts +155 -0
  66. package/dist/persistence/index.js +1 -0
  67. package/dist/persistence/index.js.map +1 -0
  68. package/dist/runtime/index.d.ts +240 -0
  69. package/dist/runtime/index.js +347 -0
  70. package/dist/runtime/index.js.map +1 -0
  71. package/dist/session/index.d.ts +92 -0
  72. package/dist/session/index.js +56 -0
  73. package/dist/session/index.js.map +1 -0
  74. package/dist/workspace/index.d.ts +111 -0
  75. package/dist/workspace/index.js +1 -0
  76. package/dist/workspace/index.js.map +1 -0
  77. package/dist/wrapper-Y3UTVU2E.js +3635 -0
  78. package/dist/wrapper-Y3UTVU2E.js.map +1 -0
  79. package/package.json +73 -14
  80. package/tsconfig.json +0 -10
@@ -0,0 +1,271 @@
1
+ import { P as Processor } from './Processor-DT0N1qI6.js';
2
+
3
+ /**
4
+ * Source - Input adapter for Mealy Machine
5
+ *
6
+ * A Source transforms external requests into internal events.
7
+ * This is a pure function type - lifecycle management belongs to higher layers.
8
+ *
9
+ * Pattern: (request) => AsyncIterable<input>
10
+ *
11
+ * @template TInput - The event type produced for Processors
12
+ * @template TRequest - The request type received from external (default: void)
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * // Simple source (no request)
17
+ * const timerSource: Source<TimerEvent> = async function* () {
18
+ * while (true) {
19
+ * yield { type: 'tick', timestamp: Date.now() };
20
+ * await sleep(1000);
21
+ * }
22
+ * };
23
+ *
24
+ * // Source with request
25
+ * const apiSource: Source<ApiEvent, ApiRequest> = async function* (request) {
26
+ * const response = await fetch(request.url);
27
+ * yield { type: 'response', data: await response.json() };
28
+ * };
29
+ * ```
30
+ */
31
+ type Source<TInput, TRequest = void> = (request: TRequest) => AsyncIterable<TInput>;
32
+ /**
33
+ * SourceDefinition - Named Source with metadata
34
+ *
35
+ * Use this when you need to identify sources by name.
36
+ */
37
+ interface SourceDefinition<TInput, TRequest = void> {
38
+ /**
39
+ * Unique name for this source
40
+ */
41
+ name: string;
42
+ /**
43
+ * Optional description
44
+ */
45
+ description?: string;
46
+ /**
47
+ * The source function
48
+ */
49
+ source: Source<TInput, TRequest>;
50
+ }
51
+
52
+ /**
53
+ * Sink - Output adapter for Mealy Machine
54
+ *
55
+ * A Sink receives outputs from Processors and produces external effects.
56
+ * This is a pure function type - lifecycle management belongs to higher layers.
57
+ *
58
+ * Pattern: (id, outputs) => void | Promise<void>
59
+ *
60
+ * @template TOutput - The output type received from Processors
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * // Sync sink (logging)
65
+ * const logSink: Sink<AgentEvent> = (id, outputs) => {
66
+ * outputs.forEach(output => console.log(`[${id}]`, output));
67
+ * };
68
+ *
69
+ * // Async sink (network)
70
+ * const sseSink: Sink<AgentEvent> = async (id, outputs) => {
71
+ * for (const output of outputs) {
72
+ * await sseConnection.send(id, output);
73
+ * }
74
+ * };
75
+ * ```
76
+ */
77
+ type Sink<TOutput> = (id: string, outputs: TOutput[]) => void | Promise<void>;
78
+ /**
79
+ * SinkDefinition - Named Sink with metadata
80
+ *
81
+ * Use this when you need to identify sinks by name.
82
+ */
83
+ interface SinkDefinition<TOutput> {
84
+ /**
85
+ * Unique name for this sink
86
+ */
87
+ name: string;
88
+ /**
89
+ * Optional description
90
+ */
91
+ description?: string;
92
+ /**
93
+ * Optional filter to select which outputs to process
94
+ *
95
+ * If not provided, all outputs are processed.
96
+ * Return true to process the output, false to skip.
97
+ */
98
+ filter?: (output: TOutput) => boolean;
99
+ /**
100
+ * The sink function
101
+ */
102
+ sink: Sink<TOutput>;
103
+ }
104
+
105
+ /**
106
+ * Store - State storage interface for stream processing
107
+ *
108
+ * A Store abstracts state persistence, allowing processors to be stateless
109
+ * while maintaining state externally.
110
+ *
111
+ * @template T - The state type to store
112
+ *
113
+ * @example
114
+ * ```typescript
115
+ * const store = new MemoryStore<AgentState>();
116
+ * store.set('agent_123', { count: 0 });
117
+ * const state = store.get('agent_123');
118
+ * ```
119
+ */
120
+ interface Store<T> {
121
+ /**
122
+ * Get state by ID
123
+ * @param id - Unique identifier (e.g., agentId, sessionId)
124
+ * @returns The stored state or undefined if not found
125
+ */
126
+ get(id: string): T | undefined;
127
+ /**
128
+ * Set state for an ID
129
+ * @param id - Unique identifier
130
+ * @param state - The state to store
131
+ */
132
+ set(id: string, state: T): void;
133
+ /**
134
+ * Delete state for an ID
135
+ * @param id - Unique identifier
136
+ */
137
+ delete(id: string): void;
138
+ /**
139
+ * Check if state exists for an ID
140
+ * @param id - Unique identifier
141
+ * @returns True if state exists
142
+ */
143
+ has(id: string): boolean;
144
+ }
145
+ /**
146
+ * MemoryStore - In-memory implementation of Store
147
+ *
148
+ * Stores state in a Map. Suitable for development and single-process deployments.
149
+ * For production multi-process scenarios, use RedisStore or PostgresStore.
150
+ *
151
+ * @template T - The state type to store
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const store = new MemoryStore<MyState>();
156
+ * store.set('session_1', { count: 0 });
157
+ * ```
158
+ */
159
+ declare class MemoryStore<T> implements Store<T> {
160
+ private states;
161
+ get(id: string): T | undefined;
162
+ set(id: string, state: T): void;
163
+ delete(id: string): void;
164
+ has(id: string): boolean;
165
+ /**
166
+ * Clear all stored states
167
+ */
168
+ clear(): void;
169
+ /**
170
+ * Get the number of stored states
171
+ */
172
+ get size(): number;
173
+ /**
174
+ * Get all stored IDs
175
+ */
176
+ keys(): IterableIterator<string>;
177
+ }
178
+
179
+ /**
180
+ * Combinators - Functions to compose multiple Processors
181
+ *
182
+ * These utilities allow building complex stream processing pipelines
183
+ * from simple, composable Processor functions.
184
+ */
185
+
186
+ /**
187
+ * combineProcessors - Combine multiple processors into one
188
+ *
189
+ * Each sub-processor manages its own slice of state.
190
+ * All processors receive the same event and their outputs are merged.
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * interface CombinedState {
195
+ * message: MessageState;
196
+ * state: StateMachineState;
197
+ * turn: TurnState;
198
+ * }
199
+ *
200
+ * const combinedProcessor = combineProcessors<CombinedState, Event, Event>({
201
+ * message: messageProcessor,
202
+ * state: stateMachineProcessor,
203
+ * turn: turnTrackerProcessor,
204
+ * });
205
+ * ```
206
+ */
207
+ declare function combineProcessors<TState extends Record<string, unknown>, TInput, TOutput>(processors: {
208
+ [K in keyof TState]: Processor<TState[K], TInput, TOutput>;
209
+ }): Processor<TState, TInput, TOutput>;
210
+ /**
211
+ * combineInitialStates - Helper to create initial state for combined processors
212
+ */
213
+ declare function combineInitialStates<TState extends Record<string, unknown>>(initialStates: {
214
+ [K in keyof TState]: () => TState[K];
215
+ }): () => TState;
216
+ /**
217
+ * chainProcessors - Chain processors where output of one feeds into the next
218
+ *
219
+ * Useful for layered event processing:
220
+ * Stream Events → Message Events → Turn Events
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * const pipeline = chainProcessors(
225
+ * streamToMessageProcessor,
226
+ * messageToTurnProcessor,
227
+ * );
228
+ * ```
229
+ */
230
+ declare function chainProcessors<TState, TEvent>(...processors: Processor<TState, TEvent, TEvent>[]): Processor<TState, TEvent, TEvent>;
231
+ /**
232
+ * filterProcessor - Create a processor that only processes certain events
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * const textOnlyProcessor = filterProcessor(
237
+ * (event) => event.type === 'text_delta',
238
+ * textProcessor,
239
+ * );
240
+ * ```
241
+ */
242
+ declare function filterProcessor<TState, TInput, TOutput>(predicate: (event: TInput) => boolean, processor: Processor<TState, TInput, TOutput>): Processor<TState, TInput, TOutput>;
243
+ /**
244
+ * mapOutput - Transform output events
245
+ *
246
+ * @example
247
+ * ```typescript
248
+ * const withTimestamp = mapOutput(
249
+ * myProcessor,
250
+ * (output) => ({ ...output, processedAt: Date.now() }),
251
+ * );
252
+ * ```
253
+ */
254
+ declare function mapOutput<TState, TInput, TOutput, TMapped>(processor: Processor<TState, TInput, TOutput>, mapper: (output: TOutput) => TMapped): Processor<TState, TInput, TMapped>;
255
+ /**
256
+ * withLogging - Add logging to a processor (for debugging)
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * const debugProcessor = withLogging(myProcessor, 'MyProcessor');
261
+ * ```
262
+ */
263
+ declare function withLogging<TState, TInput, TOutput>(processor: Processor<TState, TInput, TOutput>, name: string, logger?: {
264
+ debug: (message: string, data?: unknown) => void;
265
+ }): Processor<TState, TInput, TOutput>;
266
+ /**
267
+ * identityProcessor - A processor that does nothing (useful as default)
268
+ */
269
+ declare function identityProcessor<TState, TEvent>(): Processor<TState, TEvent, TEvent>;
270
+
271
+ export { MemoryStore as M, type Store as S, type Sink as a, type SinkDefinition as b, type Source as c, type SourceDefinition as d, combineProcessors as e, combineInitialStates as f, chainProcessors as g, filterProcessor as h, identityProcessor as i, mapOutput as m, withLogging as w };
@@ -0,0 +1 @@
1
+ export * from 'commonxjs/logger';
@@ -0,0 +1,2 @@
1
+ import "../chunk-RL3JRNXM.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Logger type definitions
3
+ *
4
+ * Self-contained types for the logger module.
5
+ * No external dependencies required.
6
+ */
7
+ /**
8
+ * LogLevel - Standard log level type
9
+ *
10
+ * Defines the severity levels for logging.
11
+ * Uses string literal types for better readability and type safety.
12
+ */
13
+ type LogLevel = "debug" | "info" | "warn" | "error" | "silent";
14
+ /**
15
+ * Logging context metadata
16
+ */
17
+ type LogContext = Record<string, unknown>;
18
+ /**
19
+ * Logger interface
20
+ *
21
+ * Platform-agnostic logging interface that can be implemented
22
+ * by any logging library (console, pino, winston, etc.)
23
+ *
24
+ * Similar to SLF4J's Logger interface in Java.
25
+ */
26
+ interface Logger {
27
+ /**
28
+ * Logger name (typically class name or module path)
29
+ */
30
+ readonly name: string;
31
+ /**
32
+ * Current log level
33
+ */
34
+ readonly level: LogLevel;
35
+ /**
36
+ * Log debug message
37
+ */
38
+ debug(message: string, context?: LogContext): void;
39
+ /**
40
+ * Log info message
41
+ */
42
+ info(message: string, context?: LogContext): void;
43
+ /**
44
+ * Log warning message
45
+ */
46
+ warn(message: string, context?: LogContext): void;
47
+ /**
48
+ * Log error message or Error object
49
+ */
50
+ error(message: string | Error, context?: LogContext): void;
51
+ /**
52
+ * Check if debug level is enabled
53
+ */
54
+ isDebugEnabled(): boolean;
55
+ /**
56
+ * Check if info level is enabled
57
+ */
58
+ isInfoEnabled(): boolean;
59
+ /**
60
+ * Check if warn level is enabled
61
+ */
62
+ isWarnEnabled(): boolean;
63
+ /**
64
+ * Check if error level is enabled
65
+ */
66
+ isErrorEnabled(): boolean;
67
+ }
68
+ /**
69
+ * LoggerFactory interface
70
+ *
71
+ * Factory for creating named Logger instances.
72
+ * External implementations can provide their own LoggerFactory
73
+ * to integrate custom logging libraries (pino, winston, etc.)
74
+ *
75
+ * Similar to SLF4J's LoggerFactory in Java.
76
+ */
77
+ interface LoggerFactory {
78
+ /**
79
+ * Get or create a logger with the specified name
80
+ *
81
+ * @param name - Logger name (typically class name or module path)
82
+ * @returns Logger instance
83
+ */
84
+ getLogger(name: string): Logger;
85
+ }
86
+
87
+ /**
88
+ * ConsoleLogger - Default logger implementation
89
+ *
90
+ * Simple console-based logger with color support.
91
+ * Used as fallback when no custom LoggerFactory is provided.
92
+ */
93
+
94
+ interface ConsoleLoggerOptions {
95
+ level?: LogLevel;
96
+ colors?: boolean;
97
+ timestamps?: boolean;
98
+ }
99
+ declare class ConsoleLogger implements Logger {
100
+ readonly name: string;
101
+ readonly level: LogLevel;
102
+ private readonly colors;
103
+ private readonly timestamps;
104
+ private static readonly COLORS;
105
+ constructor(name: string, options?: ConsoleLoggerOptions);
106
+ debug(message: string, context?: LogContext): void;
107
+ info(message: string, context?: LogContext): void;
108
+ warn(message: string, context?: LogContext): void;
109
+ error(message: string | Error, context?: LogContext): void;
110
+ isDebugEnabled(): boolean;
111
+ isInfoEnabled(): boolean;
112
+ isWarnEnabled(): boolean;
113
+ isErrorEnabled(): boolean;
114
+ private getLevelValue;
115
+ private log;
116
+ private getConsoleMethod;
117
+ private isNodeEnvironment;
118
+ }
119
+
120
+ /**
121
+ * LoggerFactoryImpl - Central factory for creating logger instances
122
+ *
123
+ * Implements lazy initialization pattern:
124
+ * - createLogger() can be called at module level (before config)
125
+ * - Real logger is created on first use
126
+ * - External LoggerFactory can be injected via Runtime
127
+ */
128
+
129
+ interface LoggerFactoryConfig {
130
+ defaultImplementation?: (name: string) => Logger;
131
+ defaultLevel?: LogLevel;
132
+ consoleOptions?: Omit<ConsoleLoggerOptions, "level">;
133
+ }
134
+ /**
135
+ * Internal LoggerFactory implementation
136
+ *
137
+ * Uses lazy proxy pattern to allow module-level createLogger() calls.
138
+ */
139
+ declare class LoggerFactoryImpl {
140
+ private static loggers;
141
+ private static config;
142
+ static getLogger(nameOrClass: string | (new (...args: unknown[]) => unknown)): Logger;
143
+ static configure(config: LoggerFactoryConfig): void;
144
+ static reset(): void;
145
+ private static createLazyLogger;
146
+ private static createLogger;
147
+ }
148
+ /**
149
+ * Set external LoggerFactory (called by Runtime initialization)
150
+ */
151
+ declare function setLoggerFactory(factory: LoggerFactory): void;
152
+ /**
153
+ * Create a logger instance
154
+ *
155
+ * Safe to call at module level before Runtime is configured.
156
+ * Uses lazy initialization - actual logger is created on first use.
157
+ *
158
+ * @param name - Logger name (hierarchical, e.g., "engine/AgentEngine")
159
+ * @returns Logger instance (lazy proxy)
160
+ */
161
+ declare function createLogger(name: string): Logger;
162
+
163
+ export { ConsoleLogger, type ConsoleLoggerOptions, type LogContext, type LogLevel, type Logger, type LoggerFactory, type LoggerFactoryConfig, LoggerFactoryImpl, createLogger, setLoggerFactory };
@@ -0,0 +1,184 @@
1
+ import "../../chunk-7D4SUZUM.js";
2
+
3
+ // src/common/logger/ConsoleLogger.ts
4
+ var ConsoleLogger = class _ConsoleLogger {
5
+ name;
6
+ level;
7
+ colors;
8
+ timestamps;
9
+ static COLORS = {
10
+ DEBUG: "\x1B[36m",
11
+ INFO: "\x1B[32m",
12
+ WARN: "\x1B[33m",
13
+ ERROR: "\x1B[31m",
14
+ RESET: "\x1B[0m"
15
+ };
16
+ constructor(name, options = {}) {
17
+ this.name = name;
18
+ this.level = options.level ?? "info";
19
+ this.colors = options.colors ?? this.isNodeEnvironment();
20
+ this.timestamps = options.timestamps ?? true;
21
+ }
22
+ debug(message, context) {
23
+ if (this.isDebugEnabled()) {
24
+ this.log("DEBUG", message, context);
25
+ }
26
+ }
27
+ info(message, context) {
28
+ if (this.isInfoEnabled()) {
29
+ this.log("INFO", message, context);
30
+ }
31
+ }
32
+ warn(message, context) {
33
+ if (this.isWarnEnabled()) {
34
+ this.log("WARN", message, context);
35
+ }
36
+ }
37
+ error(message, context) {
38
+ if (this.isErrorEnabled()) {
39
+ if (message instanceof Error) {
40
+ this.log("ERROR", message.message, { ...context, stack: message.stack });
41
+ } else {
42
+ this.log("ERROR", message, context);
43
+ }
44
+ }
45
+ }
46
+ isDebugEnabled() {
47
+ return this.getLevelValue(this.level) <= this.getLevelValue("debug");
48
+ }
49
+ isInfoEnabled() {
50
+ return this.getLevelValue(this.level) <= this.getLevelValue("info");
51
+ }
52
+ isWarnEnabled() {
53
+ return this.getLevelValue(this.level) <= this.getLevelValue("warn");
54
+ }
55
+ isErrorEnabled() {
56
+ return this.getLevelValue(this.level) <= this.getLevelValue("error");
57
+ }
58
+ getLevelValue(level) {
59
+ const levels = {
60
+ debug: 0,
61
+ info: 1,
62
+ warn: 2,
63
+ error: 3,
64
+ silent: 4
65
+ };
66
+ return levels[level];
67
+ }
68
+ log(level, message, context) {
69
+ const parts = [];
70
+ if (this.timestamps) {
71
+ parts.push((/* @__PURE__ */ new Date()).toISOString());
72
+ }
73
+ if (this.colors) {
74
+ const color = _ConsoleLogger.COLORS[level];
75
+ parts.push(`${color}${level.padEnd(5)}${_ConsoleLogger.COLORS.RESET}`);
76
+ } else {
77
+ parts.push(level.padEnd(5));
78
+ }
79
+ parts.push(`[${this.name}]`);
80
+ parts.push(message);
81
+ const logLine = parts.join(" ");
82
+ const consoleMethod = this.getConsoleMethod(level);
83
+ if (context && Object.keys(context).length > 0) {
84
+ consoleMethod(logLine, context);
85
+ } else {
86
+ consoleMethod(logLine);
87
+ }
88
+ }
89
+ getConsoleMethod(level) {
90
+ switch (level) {
91
+ case "DEBUG":
92
+ return console.debug.bind(console);
93
+ case "INFO":
94
+ return console.info.bind(console);
95
+ case "WARN":
96
+ return console.warn.bind(console);
97
+ case "ERROR":
98
+ return console.error.bind(console);
99
+ default:
100
+ return console.log.bind(console);
101
+ }
102
+ }
103
+ isNodeEnvironment() {
104
+ return typeof process !== "undefined" && process.versions?.node !== void 0;
105
+ }
106
+ };
107
+
108
+ // src/common/logger/LoggerFactoryImpl.ts
109
+ var externalFactory = null;
110
+ var factoryVersion = 0;
111
+ var LoggerFactoryImpl = class {
112
+ static loggers = /* @__PURE__ */ new Map();
113
+ static config = {
114
+ defaultLevel: "info"
115
+ };
116
+ static getLogger(nameOrClass) {
117
+ const name = typeof nameOrClass === "string" ? nameOrClass : nameOrClass.name;
118
+ if (this.loggers.has(name)) {
119
+ return this.loggers.get(name);
120
+ }
121
+ const lazyLogger = this.createLazyLogger(name);
122
+ this.loggers.set(name, lazyLogger);
123
+ return lazyLogger;
124
+ }
125
+ static configure(config) {
126
+ this.config = { ...this.config, ...config };
127
+ }
128
+ static reset() {
129
+ this.loggers.clear();
130
+ this.config = { defaultLevel: "info" };
131
+ externalFactory = null;
132
+ factoryVersion++;
133
+ }
134
+ static createLazyLogger(name) {
135
+ let realLogger = null;
136
+ let loggerVersion = -1;
137
+ const getRealLogger = () => {
138
+ if (!realLogger || loggerVersion !== factoryVersion) {
139
+ realLogger = this.createLogger(name);
140
+ loggerVersion = factoryVersion;
141
+ }
142
+ return realLogger;
143
+ };
144
+ return {
145
+ name,
146
+ level: this.config.defaultLevel || "info",
147
+ debug: (message, context) => getRealLogger().debug(message, context),
148
+ info: (message, context) => getRealLogger().info(message, context),
149
+ warn: (message, context) => getRealLogger().warn(message, context),
150
+ error: (message, context) => getRealLogger().error(message, context),
151
+ isDebugEnabled: () => getRealLogger().isDebugEnabled(),
152
+ isInfoEnabled: () => getRealLogger().isInfoEnabled(),
153
+ isWarnEnabled: () => getRealLogger().isWarnEnabled(),
154
+ isErrorEnabled: () => getRealLogger().isErrorEnabled()
155
+ };
156
+ }
157
+ static createLogger(name) {
158
+ if (externalFactory) {
159
+ return externalFactory.getLogger(name);
160
+ }
161
+ if (this.config.defaultImplementation) {
162
+ return this.config.defaultImplementation(name);
163
+ }
164
+ return new ConsoleLogger(name, {
165
+ level: this.config.defaultLevel,
166
+ ...this.config.consoleOptions
167
+ });
168
+ }
169
+ };
170
+ function setLoggerFactory(factory) {
171
+ externalFactory = factory;
172
+ LoggerFactoryImpl.reset();
173
+ externalFactory = factory;
174
+ }
175
+ function createLogger(name) {
176
+ return LoggerFactoryImpl.getLogger(name);
177
+ }
178
+ export {
179
+ ConsoleLogger,
180
+ LoggerFactoryImpl,
181
+ createLogger,
182
+ setLoggerFactory
183
+ };
184
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/common/logger/ConsoleLogger.ts","../../../src/common/logger/LoggerFactoryImpl.ts"],"sourcesContent":["/**\n * ConsoleLogger - Default logger implementation\n *\n * Simple console-based logger with color support.\n * Used as fallback when no custom LoggerFactory is provided.\n */\n\nimport type { Logger, LogContext, LogLevel } from \"./types\";\n\nexport interface ConsoleLoggerOptions {\n level?: LogLevel;\n colors?: boolean;\n timestamps?: boolean;\n}\n\nexport class ConsoleLogger implements Logger {\n readonly name: string;\n readonly level: LogLevel;\n private readonly colors: boolean;\n private readonly timestamps: boolean;\n\n private static readonly COLORS = {\n DEBUG: \"\\x1b[36m\",\n INFO: \"\\x1b[32m\",\n WARN: \"\\x1b[33m\",\n ERROR: \"\\x1b[31m\",\n RESET: \"\\x1b[0m\",\n };\n\n constructor(name: string, options: ConsoleLoggerOptions = {}) {\n this.name = name;\n this.level = options.level ?? \"info\";\n this.colors = options.colors ?? this.isNodeEnvironment();\n this.timestamps = options.timestamps ?? true;\n }\n\n debug(message: string, context?: LogContext): void {\n if (this.isDebugEnabled()) {\n this.log(\"DEBUG\", message, context);\n }\n }\n\n info(message: string, context?: LogContext): void {\n if (this.isInfoEnabled()) {\n this.log(\"INFO\", message, context);\n }\n }\n\n warn(message: string, context?: LogContext): void {\n if (this.isWarnEnabled()) {\n this.log(\"WARN\", message, context);\n }\n }\n\n error(message: string | Error, context?: LogContext): void {\n if (this.isErrorEnabled()) {\n if (message instanceof Error) {\n this.log(\"ERROR\", message.message, { ...context, stack: message.stack });\n } else {\n this.log(\"ERROR\", message, context);\n }\n }\n }\n\n isDebugEnabled(): boolean {\n return this.getLevelValue(this.level) <= this.getLevelValue(\"debug\");\n }\n\n isInfoEnabled(): boolean {\n return this.getLevelValue(this.level) <= this.getLevelValue(\"info\");\n }\n\n isWarnEnabled(): boolean {\n return this.getLevelValue(this.level) <= this.getLevelValue(\"warn\");\n }\n\n isErrorEnabled(): boolean {\n return this.getLevelValue(this.level) <= this.getLevelValue(\"error\");\n }\n\n private getLevelValue(level: LogLevel): number {\n const levels: Record<LogLevel, number> = {\n debug: 0,\n info: 1,\n warn: 2,\n error: 3,\n silent: 4,\n };\n return levels[level];\n }\n\n private log(level: string, message: string, context?: LogContext): void {\n const parts: string[] = [];\n\n if (this.timestamps) {\n parts.push(new Date().toISOString());\n }\n\n if (this.colors) {\n const color = ConsoleLogger.COLORS[level as keyof typeof ConsoleLogger.COLORS];\n parts.push(`${color}${level.padEnd(5)}${ConsoleLogger.COLORS.RESET}`);\n } else {\n parts.push(level.padEnd(5));\n }\n\n parts.push(`[${this.name}]`);\n parts.push(message);\n\n const logLine = parts.join(\" \");\n const consoleMethod = this.getConsoleMethod(level);\n\n if (context && Object.keys(context).length > 0) {\n consoleMethod(logLine, context);\n } else {\n consoleMethod(logLine);\n }\n }\n\n private getConsoleMethod(level: string): (...args: unknown[]) => void {\n switch (level) {\n case \"DEBUG\":\n return console.debug.bind(console);\n case \"INFO\":\n return console.info.bind(console);\n case \"WARN\":\n return console.warn.bind(console);\n case \"ERROR\":\n return console.error.bind(console);\n default:\n return console.log.bind(console);\n }\n }\n\n private isNodeEnvironment(): boolean {\n return typeof process !== \"undefined\" && process.versions?.node !== undefined;\n }\n}\n","/**\n * LoggerFactoryImpl - Central factory for creating logger instances\n *\n * Implements lazy initialization pattern:\n * - createLogger() can be called at module level (before config)\n * - Real logger is created on first use\n * - External LoggerFactory can be injected via Runtime\n */\n\nimport type { Logger, LoggerFactory, LogContext, LogLevel } from \"./types\";\nimport { ConsoleLogger, type ConsoleLoggerOptions } from \"./ConsoleLogger\";\n\n// External factory injected via Runtime\nlet externalFactory: LoggerFactory | null = null;\n\n// Version counter to invalidate cached real loggers\nlet factoryVersion = 0;\n\nexport interface LoggerFactoryConfig {\n defaultImplementation?: (name: string) => Logger;\n defaultLevel?: LogLevel;\n consoleOptions?: Omit<ConsoleLoggerOptions, \"level\">;\n}\n\n/**\n * Internal LoggerFactory implementation\n *\n * Uses lazy proxy pattern to allow module-level createLogger() calls.\n */\nexport class LoggerFactoryImpl {\n private static loggers: Map<string, Logger> = new Map();\n private static config: LoggerFactoryConfig = {\n defaultLevel: \"info\",\n };\n\n static getLogger(nameOrClass: string | (new (...args: unknown[]) => unknown)): Logger {\n const name = typeof nameOrClass === \"string\" ? nameOrClass : nameOrClass.name;\n\n if (this.loggers.has(name)) {\n return this.loggers.get(name)!;\n }\n\n const lazyLogger = this.createLazyLogger(name);\n this.loggers.set(name, lazyLogger);\n return lazyLogger;\n }\n\n static configure(config: LoggerFactoryConfig): void {\n this.config = { ...this.config, ...config };\n }\n\n static reset(): void {\n this.loggers.clear();\n this.config = { defaultLevel: \"info\" };\n externalFactory = null;\n factoryVersion++; // Invalidate all cached real loggers\n }\n\n private static createLazyLogger(name: string): Logger {\n let realLogger: Logger | null = null;\n let loggerVersion = -1; // Track which factory version created this logger\n\n const getRealLogger = (): Logger => {\n // Recreate logger if factory version changed (setLoggerFactory was called)\n if (!realLogger || loggerVersion !== factoryVersion) {\n realLogger = this.createLogger(name);\n loggerVersion = factoryVersion;\n }\n return realLogger;\n };\n\n return {\n name,\n level: this.config.defaultLevel || \"info\",\n debug: (message: string, context?: LogContext) => getRealLogger().debug(message, context),\n info: (message: string, context?: LogContext) => getRealLogger().info(message, context),\n warn: (message: string, context?: LogContext) => getRealLogger().warn(message, context),\n error: (message: string | Error, context?: LogContext) =>\n getRealLogger().error(message, context),\n isDebugEnabled: () => getRealLogger().isDebugEnabled(),\n isInfoEnabled: () => getRealLogger().isInfoEnabled(),\n isWarnEnabled: () => getRealLogger().isWarnEnabled(),\n isErrorEnabled: () => getRealLogger().isErrorEnabled(),\n };\n }\n\n private static createLogger(name: string): Logger {\n if (externalFactory) {\n return externalFactory.getLogger(name);\n }\n\n if (this.config.defaultImplementation) {\n return this.config.defaultImplementation(name);\n }\n\n return new ConsoleLogger(name, {\n level: this.config.defaultLevel,\n ...this.config.consoleOptions,\n });\n }\n}\n\n/**\n * Set external LoggerFactory (called by Runtime initialization)\n */\nexport function setLoggerFactory(factory: LoggerFactory): void {\n externalFactory = factory;\n LoggerFactoryImpl.reset();\n externalFactory = factory;\n}\n\n/**\n * Create a logger instance\n *\n * Safe to call at module level before Runtime is configured.\n * Uses lazy initialization - actual logger is created on first use.\n *\n * @param name - Logger name (hierarchical, e.g., \"engine/AgentEngine\")\n * @returns Logger instance (lazy proxy)\n */\nexport function createLogger(name: string): Logger {\n return LoggerFactoryImpl.getLogger(name);\n}\n"],"mappings":";;;AAeO,IAAM,gBAAN,MAAM,eAAgC;AAAA,EAClC;AAAA,EACA;AAAA,EACQ;AAAA,EACA;AAAA,EAEjB,OAAwB,SAAS;AAAA,IAC/B,OAAO;AAAA,IACP,MAAM;AAAA,IACN,MAAM;AAAA,IACN,OAAO;AAAA,IACP,OAAO;AAAA,EACT;AAAA,EAEA,YAAY,MAAc,UAAgC,CAAC,GAAG;AAC5D,SAAK,OAAO;AACZ,SAAK,QAAQ,QAAQ,SAAS;AAC9B,SAAK,SAAS,QAAQ,UAAU,KAAK,kBAAkB;AACvD,SAAK,aAAa,QAAQ,cAAc;AAAA,EAC1C;AAAA,EAEA,MAAM,SAAiB,SAA4B;AACjD,QAAI,KAAK,eAAe,GAAG;AACzB,WAAK,IAAI,SAAS,SAAS,OAAO;AAAA,IACpC;AAAA,EACF;AAAA,EAEA,KAAK,SAAiB,SAA4B;AAChD,QAAI,KAAK,cAAc,GAAG;AACxB,WAAK,IAAI,QAAQ,SAAS,OAAO;AAAA,IACnC;AAAA,EACF;AAAA,EAEA,KAAK,SAAiB,SAA4B;AAChD,QAAI,KAAK,cAAc,GAAG;AACxB,WAAK,IAAI,QAAQ,SAAS,OAAO;AAAA,IACnC;AAAA,EACF;AA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