@agentxjs/common 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +206 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +79 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.js +179 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
21
|
+
|
|
22
|
+
// src/index.ts
|
|
23
|
+
var index_exports = {};
|
|
24
|
+
__export(index_exports, {
|
|
25
|
+
ConsoleLogger: () => ConsoleLogger,
|
|
26
|
+
LogLevel: () => import_types3.LogLevel,
|
|
27
|
+
LoggerFactoryImpl: () => LoggerFactoryImpl,
|
|
28
|
+
createLogger: () => createLogger,
|
|
29
|
+
setLoggerFactory: () => setLoggerFactory
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(index_exports);
|
|
32
|
+
var import_types3 = require("@agentxjs/types");
|
|
33
|
+
|
|
34
|
+
// src/logger/ConsoleLogger.ts
|
|
35
|
+
var import_types = require("@agentxjs/types");
|
|
36
|
+
var _ConsoleLogger = class _ConsoleLogger {
|
|
37
|
+
constructor(name, options = {}) {
|
|
38
|
+
__publicField(this, "name");
|
|
39
|
+
__publicField(this, "level");
|
|
40
|
+
__publicField(this, "colors");
|
|
41
|
+
__publicField(this, "timestamps");
|
|
42
|
+
this.name = name;
|
|
43
|
+
this.level = options.level ?? import_types.LogLevel.INFO;
|
|
44
|
+
this.colors = options.colors ?? this.isNodeEnvironment();
|
|
45
|
+
this.timestamps = options.timestamps ?? true;
|
|
46
|
+
}
|
|
47
|
+
debug(message, context) {
|
|
48
|
+
if (this.isDebugEnabled()) {
|
|
49
|
+
this.log("DEBUG", message, context);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
info(message, context) {
|
|
53
|
+
if (this.isInfoEnabled()) {
|
|
54
|
+
this.log("INFO", message, context);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
warn(message, context) {
|
|
58
|
+
if (this.isWarnEnabled()) {
|
|
59
|
+
this.log("WARN", message, context);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
error(message, context) {
|
|
63
|
+
if (this.isErrorEnabled()) {
|
|
64
|
+
if (message instanceof Error) {
|
|
65
|
+
this.log("ERROR", message.message, { ...context, stack: message.stack });
|
|
66
|
+
} else {
|
|
67
|
+
this.log("ERROR", message, context);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
isDebugEnabled() {
|
|
72
|
+
return this.level <= import_types.LogLevel.DEBUG;
|
|
73
|
+
}
|
|
74
|
+
isInfoEnabled() {
|
|
75
|
+
return this.level <= import_types.LogLevel.INFO;
|
|
76
|
+
}
|
|
77
|
+
isWarnEnabled() {
|
|
78
|
+
return this.level <= import_types.LogLevel.WARN;
|
|
79
|
+
}
|
|
80
|
+
isErrorEnabled() {
|
|
81
|
+
return this.level <= import_types.LogLevel.ERROR;
|
|
82
|
+
}
|
|
83
|
+
log(level, message, context) {
|
|
84
|
+
const parts = [];
|
|
85
|
+
if (this.timestamps) {
|
|
86
|
+
parts.push((/* @__PURE__ */ new Date()).toISOString());
|
|
87
|
+
}
|
|
88
|
+
if (this.colors) {
|
|
89
|
+
const color = _ConsoleLogger.COLORS[level];
|
|
90
|
+
parts.push(`${color}${level.padEnd(5)}${_ConsoleLogger.COLORS.RESET}`);
|
|
91
|
+
} else {
|
|
92
|
+
parts.push(level.padEnd(5));
|
|
93
|
+
}
|
|
94
|
+
parts.push(`[${this.name}]`);
|
|
95
|
+
parts.push(message);
|
|
96
|
+
const logLine = parts.join(" ");
|
|
97
|
+
const consoleMethod = this.getConsoleMethod(level);
|
|
98
|
+
if (context && Object.keys(context).length > 0) {
|
|
99
|
+
consoleMethod(logLine, context);
|
|
100
|
+
} else {
|
|
101
|
+
consoleMethod(logLine);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
getConsoleMethod(level) {
|
|
105
|
+
switch (level) {
|
|
106
|
+
case "DEBUG":
|
|
107
|
+
return console.debug.bind(console);
|
|
108
|
+
case "INFO":
|
|
109
|
+
return console.info.bind(console);
|
|
110
|
+
case "WARN":
|
|
111
|
+
return console.warn.bind(console);
|
|
112
|
+
case "ERROR":
|
|
113
|
+
return console.error.bind(console);
|
|
114
|
+
default:
|
|
115
|
+
return console.log.bind(console);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
isNodeEnvironment() {
|
|
119
|
+
return typeof process !== "undefined" && process.versions?.node !== void 0;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
__publicField(_ConsoleLogger, "COLORS", {
|
|
123
|
+
DEBUG: "\x1B[36m",
|
|
124
|
+
INFO: "\x1B[32m",
|
|
125
|
+
WARN: "\x1B[33m",
|
|
126
|
+
ERROR: "\x1B[31m",
|
|
127
|
+
RESET: "\x1B[0m"
|
|
128
|
+
});
|
|
129
|
+
var ConsoleLogger = _ConsoleLogger;
|
|
130
|
+
|
|
131
|
+
// src/logger/LoggerFactoryImpl.ts
|
|
132
|
+
var import_types2 = require("@agentxjs/types");
|
|
133
|
+
var externalFactory = null;
|
|
134
|
+
var LoggerFactoryImpl = class {
|
|
135
|
+
static getLogger(nameOrClass) {
|
|
136
|
+
const name = typeof nameOrClass === "string" ? nameOrClass : nameOrClass.name;
|
|
137
|
+
if (this.loggers.has(name)) {
|
|
138
|
+
return this.loggers.get(name);
|
|
139
|
+
}
|
|
140
|
+
const lazyLogger = this.createLazyLogger(name);
|
|
141
|
+
this.loggers.set(name, lazyLogger);
|
|
142
|
+
return lazyLogger;
|
|
143
|
+
}
|
|
144
|
+
static configure(config) {
|
|
145
|
+
this.config = { ...this.config, ...config };
|
|
146
|
+
}
|
|
147
|
+
static reset() {
|
|
148
|
+
this.loggers.clear();
|
|
149
|
+
this.config = { defaultLevel: import_types2.LogLevel.INFO };
|
|
150
|
+
externalFactory = null;
|
|
151
|
+
}
|
|
152
|
+
static createLazyLogger(name) {
|
|
153
|
+
let realLogger = null;
|
|
154
|
+
const getRealLogger = () => {
|
|
155
|
+
if (!realLogger) {
|
|
156
|
+
realLogger = this.createLogger(name);
|
|
157
|
+
}
|
|
158
|
+
return realLogger;
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
name,
|
|
162
|
+
level: this.config.defaultLevel || import_types2.LogLevel.INFO,
|
|
163
|
+
debug: (message, context) => getRealLogger().debug(message, context),
|
|
164
|
+
info: (message, context) => getRealLogger().info(message, context),
|
|
165
|
+
warn: (message, context) => getRealLogger().warn(message, context),
|
|
166
|
+
error: (message, context) => getRealLogger().error(message, context),
|
|
167
|
+
isDebugEnabled: () => getRealLogger().isDebugEnabled(),
|
|
168
|
+
isInfoEnabled: () => getRealLogger().isInfoEnabled(),
|
|
169
|
+
isWarnEnabled: () => getRealLogger().isWarnEnabled(),
|
|
170
|
+
isErrorEnabled: () => getRealLogger().isErrorEnabled()
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
static createLogger(name) {
|
|
174
|
+
if (externalFactory) {
|
|
175
|
+
return externalFactory.getLogger(name);
|
|
176
|
+
}
|
|
177
|
+
if (this.config.defaultImplementation) {
|
|
178
|
+
return this.config.defaultImplementation(name);
|
|
179
|
+
}
|
|
180
|
+
return new ConsoleLogger(name, {
|
|
181
|
+
level: this.config.defaultLevel,
|
|
182
|
+
...this.config.consoleOptions
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
__publicField(LoggerFactoryImpl, "loggers", /* @__PURE__ */ new Map());
|
|
187
|
+
__publicField(LoggerFactoryImpl, "config", {
|
|
188
|
+
defaultLevel: import_types2.LogLevel.INFO
|
|
189
|
+
});
|
|
190
|
+
function setLoggerFactory(factory) {
|
|
191
|
+
externalFactory = factory;
|
|
192
|
+
LoggerFactoryImpl.reset();
|
|
193
|
+
externalFactory = factory;
|
|
194
|
+
}
|
|
195
|
+
function createLogger(name) {
|
|
196
|
+
return LoggerFactoryImpl.getLogger(name);
|
|
197
|
+
}
|
|
198
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
199
|
+
0 && (module.exports = {
|
|
200
|
+
ConsoleLogger,
|
|
201
|
+
LogLevel,
|
|
202
|
+
LoggerFactoryImpl,
|
|
203
|
+
createLogger,
|
|
204
|
+
setLoggerFactory
|
|
205
|
+
});
|
|
206
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/logger/ConsoleLogger.ts","../src/logger/LoggerFactoryImpl.ts"],"sourcesContent":["/**\n * AgentX Common\n *\n * Internal common infrastructure for AgentX platform.\n * Provides shared utilities used by internal packages (engine, agent, etc.)\n *\n * ## Module Structure\n *\n * | Module | Purpose |\n * |----------|----------------------------------------------|\n * | logger/ | Lazy-initialized logging with pluggable backends |\n *\n * ## Design Principles\n *\n * 1. **Internal Use**: For AgentX internal packages only\n * 2. **Lazy Initialization**: Safe to use at module level\n * 3. **Pluggable**: External implementations via Runtime injection\n *\n * @example\n * ```typescript\n * import { createLogger } from \"@agentxjs/common\";\n *\n * const logger = createLogger(\"engine/AgentEngine\");\n * logger.info(\"Hello\");\n * ```\n *\n * @packageDocumentation\n */\n\n// Re-export types from agentx-types for convenience\nexport { LogLevel } from \"@agentxjs/types\";\nexport type { Logger, LogContext, LoggerFactory } from \"@agentxjs/types\";\n\n// Logger implementation\nexport {\n ConsoleLogger,\n type ConsoleLoggerOptions,\n LoggerFactoryImpl,\n type LoggerFactoryConfig,\n setLoggerFactory,\n createLogger,\n} from \"./logger\";\n","/**\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 \"@agentxjs/types\";\nimport { LogLevel as LogLevelEnum } from \"@agentxjs/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 ?? LogLevelEnum.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.level <= LogLevelEnum.DEBUG;\n }\n\n isInfoEnabled(): boolean {\n return this.level <= LogLevelEnum.INFO;\n }\n\n isWarnEnabled(): boolean {\n return this.level <= LogLevelEnum.WARN;\n }\n\n isErrorEnabled(): boolean {\n return this.level <= LogLevelEnum.ERROR;\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 \"@agentxjs/types\";\nimport { LogLevel as LogLevelEnum } from \"@agentxjs/types\";\nimport { ConsoleLogger, type ConsoleLoggerOptions } from \"./ConsoleLogger\";\n\n// External factory injected via Runtime\nlet externalFactory: LoggerFactory | null = null;\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: LogLevelEnum.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: LogLevelEnum.INFO };\n externalFactory = null;\n }\n\n private static createLazyLogger(name: string): Logger {\n let realLogger: Logger | null = null;\n\n const getRealLogger = (): Logger => {\n if (!realLogger) {\n realLogger = this.createLogger(name);\n }\n return realLogger;\n };\n\n return {\n name,\n level: this.config.defaultLevel || LogLevelEnum.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":";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BA,IAAAA,gBAAyB;;;ACtBzB,mBAAyC;AAQlC,IAAM,iBAAN,MAAM,eAAgC;AAAA,EAc3C,YAAY,MAAc,UAAgC,CAAC,GAAG;AAb9D,wBAAS;AACT,wBAAS;AACT,wBAAiB;AACjB,wBAAiB;AAWf,SAAK,OAAO;AACZ,SAAK,QAAQ,QAAQ,SAAS,aAAAC,SAAa;AAC3C,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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;AACjD,SAAO,kBAAkB,UAAU,IAAI;AACzC;","names":["import_types","LogLevelEnum","import_types","LogLevelEnum"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Logger, LogLevel, LogContext, LoggerFactory } from '@agentxjs/types';
|
|
2
|
+
export { LogContext, LogLevel, Logger, LoggerFactory } from '@agentxjs/types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ConsoleLogger - Default logger implementation
|
|
6
|
+
*
|
|
7
|
+
* Simple console-based logger with color support.
|
|
8
|
+
* Used as fallback when no custom LoggerFactory is provided.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface ConsoleLoggerOptions {
|
|
12
|
+
level?: LogLevel;
|
|
13
|
+
colors?: boolean;
|
|
14
|
+
timestamps?: boolean;
|
|
15
|
+
}
|
|
16
|
+
declare class ConsoleLogger implements Logger {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly level: LogLevel;
|
|
19
|
+
private readonly colors;
|
|
20
|
+
private readonly timestamps;
|
|
21
|
+
private static readonly COLORS;
|
|
22
|
+
constructor(name: string, options?: ConsoleLoggerOptions);
|
|
23
|
+
debug(message: string, context?: LogContext): void;
|
|
24
|
+
info(message: string, context?: LogContext): void;
|
|
25
|
+
warn(message: string, context?: LogContext): void;
|
|
26
|
+
error(message: string | Error, context?: LogContext): void;
|
|
27
|
+
isDebugEnabled(): boolean;
|
|
28
|
+
isInfoEnabled(): boolean;
|
|
29
|
+
isWarnEnabled(): boolean;
|
|
30
|
+
isErrorEnabled(): boolean;
|
|
31
|
+
private log;
|
|
32
|
+
private getConsoleMethod;
|
|
33
|
+
private isNodeEnvironment;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* LoggerFactoryImpl - Central factory for creating logger instances
|
|
38
|
+
*
|
|
39
|
+
* Implements lazy initialization pattern:
|
|
40
|
+
* - createLogger() can be called at module level (before config)
|
|
41
|
+
* - Real logger is created on first use
|
|
42
|
+
* - External LoggerFactory can be injected via Runtime
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
interface LoggerFactoryConfig {
|
|
46
|
+
defaultImplementation?: (name: string) => Logger;
|
|
47
|
+
defaultLevel?: LogLevel;
|
|
48
|
+
consoleOptions?: Omit<ConsoleLoggerOptions, "level">;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Internal LoggerFactory implementation
|
|
52
|
+
*
|
|
53
|
+
* Uses lazy proxy pattern to allow module-level createLogger() calls.
|
|
54
|
+
*/
|
|
55
|
+
declare class LoggerFactoryImpl {
|
|
56
|
+
private static loggers;
|
|
57
|
+
private static config;
|
|
58
|
+
static getLogger(nameOrClass: string | (new (...args: unknown[]) => unknown)): Logger;
|
|
59
|
+
static configure(config: LoggerFactoryConfig): void;
|
|
60
|
+
static reset(): void;
|
|
61
|
+
private static createLazyLogger;
|
|
62
|
+
private static createLogger;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Set external LoggerFactory (called by Runtime initialization)
|
|
66
|
+
*/
|
|
67
|
+
declare function setLoggerFactory(factory: LoggerFactory): void;
|
|
68
|
+
/**
|
|
69
|
+
* Create a logger instance
|
|
70
|
+
*
|
|
71
|
+
* Safe to call at module level before Runtime is configured.
|
|
72
|
+
* Uses lazy initialization - actual logger is created on first use.
|
|
73
|
+
*
|
|
74
|
+
* @param name - Logger name (hierarchical, e.g., "engine/AgentEngine")
|
|
75
|
+
* @returns Logger instance (lazy proxy)
|
|
76
|
+
*/
|
|
77
|
+
declare function createLogger(name: string): Logger;
|
|
78
|
+
|
|
79
|
+
export { ConsoleLogger, type ConsoleLoggerOptions, type LoggerFactoryConfig, LoggerFactoryImpl, createLogger, setLoggerFactory };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Logger, LogLevel, LogContext, LoggerFactory } from '@agentxjs/types';
|
|
2
|
+
export { LogContext, LogLevel, Logger, LoggerFactory } from '@agentxjs/types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ConsoleLogger - Default logger implementation
|
|
6
|
+
*
|
|
7
|
+
* Simple console-based logger with color support.
|
|
8
|
+
* Used as fallback when no custom LoggerFactory is provided.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
interface ConsoleLoggerOptions {
|
|
12
|
+
level?: LogLevel;
|
|
13
|
+
colors?: boolean;
|
|
14
|
+
timestamps?: boolean;
|
|
15
|
+
}
|
|
16
|
+
declare class ConsoleLogger implements Logger {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly level: LogLevel;
|
|
19
|
+
private readonly colors;
|
|
20
|
+
private readonly timestamps;
|
|
21
|
+
private static readonly COLORS;
|
|
22
|
+
constructor(name: string, options?: ConsoleLoggerOptions);
|
|
23
|
+
debug(message: string, context?: LogContext): void;
|
|
24
|
+
info(message: string, context?: LogContext): void;
|
|
25
|
+
warn(message: string, context?: LogContext): void;
|
|
26
|
+
error(message: string | Error, context?: LogContext): void;
|
|
27
|
+
isDebugEnabled(): boolean;
|
|
28
|
+
isInfoEnabled(): boolean;
|
|
29
|
+
isWarnEnabled(): boolean;
|
|
30
|
+
isErrorEnabled(): boolean;
|
|
31
|
+
private log;
|
|
32
|
+
private getConsoleMethod;
|
|
33
|
+
private isNodeEnvironment;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* LoggerFactoryImpl - Central factory for creating logger instances
|
|
38
|
+
*
|
|
39
|
+
* Implements lazy initialization pattern:
|
|
40
|
+
* - createLogger() can be called at module level (before config)
|
|
41
|
+
* - Real logger is created on first use
|
|
42
|
+
* - External LoggerFactory can be injected via Runtime
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
interface LoggerFactoryConfig {
|
|
46
|
+
defaultImplementation?: (name: string) => Logger;
|
|
47
|
+
defaultLevel?: LogLevel;
|
|
48
|
+
consoleOptions?: Omit<ConsoleLoggerOptions, "level">;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Internal LoggerFactory implementation
|
|
52
|
+
*
|
|
53
|
+
* Uses lazy proxy pattern to allow module-level createLogger() calls.
|
|
54
|
+
*/
|
|
55
|
+
declare class LoggerFactoryImpl {
|
|
56
|
+
private static loggers;
|
|
57
|
+
private static config;
|
|
58
|
+
static getLogger(nameOrClass: string | (new (...args: unknown[]) => unknown)): Logger;
|
|
59
|
+
static configure(config: LoggerFactoryConfig): void;
|
|
60
|
+
static reset(): void;
|
|
61
|
+
private static createLazyLogger;
|
|
62
|
+
private static createLogger;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Set external LoggerFactory (called by Runtime initialization)
|
|
66
|
+
*/
|
|
67
|
+
declare function setLoggerFactory(factory: LoggerFactory): void;
|
|
68
|
+
/**
|
|
69
|
+
* Create a logger instance
|
|
70
|
+
*
|
|
71
|
+
* Safe to call at module level before Runtime is configured.
|
|
72
|
+
* Uses lazy initialization - actual logger is created on first use.
|
|
73
|
+
*
|
|
74
|
+
* @param name - Logger name (hierarchical, e.g., "engine/AgentEngine")
|
|
75
|
+
* @returns Logger instance (lazy proxy)
|
|
76
|
+
*/
|
|
77
|
+
declare function createLogger(name: string): Logger;
|
|
78
|
+
|
|
79
|
+
export { ConsoleLogger, type ConsoleLoggerOptions, type LoggerFactoryConfig, LoggerFactoryImpl, createLogger, setLoggerFactory };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
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
|
+
// src/index.ts
|
|
6
|
+
import { LogLevel } from "@agentxjs/types";
|
|
7
|
+
|
|
8
|
+
// src/logger/ConsoleLogger.ts
|
|
9
|
+
import { LogLevel as LogLevelEnum } from "@agentxjs/types";
|
|
10
|
+
var _ConsoleLogger = class _ConsoleLogger {
|
|
11
|
+
constructor(name, options = {}) {
|
|
12
|
+
__publicField(this, "name");
|
|
13
|
+
__publicField(this, "level");
|
|
14
|
+
__publicField(this, "colors");
|
|
15
|
+
__publicField(this, "timestamps");
|
|
16
|
+
this.name = name;
|
|
17
|
+
this.level = options.level ?? LogLevelEnum.INFO;
|
|
18
|
+
this.colors = options.colors ?? this.isNodeEnvironment();
|
|
19
|
+
this.timestamps = options.timestamps ?? true;
|
|
20
|
+
}
|
|
21
|
+
debug(message, context) {
|
|
22
|
+
if (this.isDebugEnabled()) {
|
|
23
|
+
this.log("DEBUG", message, context);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
info(message, context) {
|
|
27
|
+
if (this.isInfoEnabled()) {
|
|
28
|
+
this.log("INFO", message, context);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
warn(message, context) {
|
|
32
|
+
if (this.isWarnEnabled()) {
|
|
33
|
+
this.log("WARN", message, context);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
error(message, context) {
|
|
37
|
+
if (this.isErrorEnabled()) {
|
|
38
|
+
if (message instanceof Error) {
|
|
39
|
+
this.log("ERROR", message.message, { ...context, stack: message.stack });
|
|
40
|
+
} else {
|
|
41
|
+
this.log("ERROR", message, context);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
isDebugEnabled() {
|
|
46
|
+
return this.level <= LogLevelEnum.DEBUG;
|
|
47
|
+
}
|
|
48
|
+
isInfoEnabled() {
|
|
49
|
+
return this.level <= LogLevelEnum.INFO;
|
|
50
|
+
}
|
|
51
|
+
isWarnEnabled() {
|
|
52
|
+
return this.level <= LogLevelEnum.WARN;
|
|
53
|
+
}
|
|
54
|
+
isErrorEnabled() {
|
|
55
|
+
return this.level <= LogLevelEnum.ERROR;
|
|
56
|
+
}
|
|
57
|
+
log(level, message, context) {
|
|
58
|
+
const parts = [];
|
|
59
|
+
if (this.timestamps) {
|
|
60
|
+
parts.push((/* @__PURE__ */ new Date()).toISOString());
|
|
61
|
+
}
|
|
62
|
+
if (this.colors) {
|
|
63
|
+
const color = _ConsoleLogger.COLORS[level];
|
|
64
|
+
parts.push(`${color}${level.padEnd(5)}${_ConsoleLogger.COLORS.RESET}`);
|
|
65
|
+
} else {
|
|
66
|
+
parts.push(level.padEnd(5));
|
|
67
|
+
}
|
|
68
|
+
parts.push(`[${this.name}]`);
|
|
69
|
+
parts.push(message);
|
|
70
|
+
const logLine = parts.join(" ");
|
|
71
|
+
const consoleMethod = this.getConsoleMethod(level);
|
|
72
|
+
if (context && Object.keys(context).length > 0) {
|
|
73
|
+
consoleMethod(logLine, context);
|
|
74
|
+
} else {
|
|
75
|
+
consoleMethod(logLine);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
getConsoleMethod(level) {
|
|
79
|
+
switch (level) {
|
|
80
|
+
case "DEBUG":
|
|
81
|
+
return console.debug.bind(console);
|
|
82
|
+
case "INFO":
|
|
83
|
+
return console.info.bind(console);
|
|
84
|
+
case "WARN":
|
|
85
|
+
return console.warn.bind(console);
|
|
86
|
+
case "ERROR":
|
|
87
|
+
return console.error.bind(console);
|
|
88
|
+
default:
|
|
89
|
+
return console.log.bind(console);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
isNodeEnvironment() {
|
|
93
|
+
return typeof process !== "undefined" && process.versions?.node !== void 0;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
__publicField(_ConsoleLogger, "COLORS", {
|
|
97
|
+
DEBUG: "\x1B[36m",
|
|
98
|
+
INFO: "\x1B[32m",
|
|
99
|
+
WARN: "\x1B[33m",
|
|
100
|
+
ERROR: "\x1B[31m",
|
|
101
|
+
RESET: "\x1B[0m"
|
|
102
|
+
});
|
|
103
|
+
var ConsoleLogger = _ConsoleLogger;
|
|
104
|
+
|
|
105
|
+
// src/logger/LoggerFactoryImpl.ts
|
|
106
|
+
import { LogLevel as LogLevelEnum2 } from "@agentxjs/types";
|
|
107
|
+
var externalFactory = null;
|
|
108
|
+
var LoggerFactoryImpl = class {
|
|
109
|
+
static getLogger(nameOrClass) {
|
|
110
|
+
const name = typeof nameOrClass === "string" ? nameOrClass : nameOrClass.name;
|
|
111
|
+
if (this.loggers.has(name)) {
|
|
112
|
+
return this.loggers.get(name);
|
|
113
|
+
}
|
|
114
|
+
const lazyLogger = this.createLazyLogger(name);
|
|
115
|
+
this.loggers.set(name, lazyLogger);
|
|
116
|
+
return lazyLogger;
|
|
117
|
+
}
|
|
118
|
+
static configure(config) {
|
|
119
|
+
this.config = { ...this.config, ...config };
|
|
120
|
+
}
|
|
121
|
+
static reset() {
|
|
122
|
+
this.loggers.clear();
|
|
123
|
+
this.config = { defaultLevel: LogLevelEnum2.INFO };
|
|
124
|
+
externalFactory = null;
|
|
125
|
+
}
|
|
126
|
+
static createLazyLogger(name) {
|
|
127
|
+
let realLogger = null;
|
|
128
|
+
const getRealLogger = () => {
|
|
129
|
+
if (!realLogger) {
|
|
130
|
+
realLogger = this.createLogger(name);
|
|
131
|
+
}
|
|
132
|
+
return realLogger;
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
name,
|
|
136
|
+
level: this.config.defaultLevel || LogLevelEnum2.INFO,
|
|
137
|
+
debug: (message, context) => getRealLogger().debug(message, context),
|
|
138
|
+
info: (message, context) => getRealLogger().info(message, context),
|
|
139
|
+
warn: (message, context) => getRealLogger().warn(message, context),
|
|
140
|
+
error: (message, context) => getRealLogger().error(message, context),
|
|
141
|
+
isDebugEnabled: () => getRealLogger().isDebugEnabled(),
|
|
142
|
+
isInfoEnabled: () => getRealLogger().isInfoEnabled(),
|
|
143
|
+
isWarnEnabled: () => getRealLogger().isWarnEnabled(),
|
|
144
|
+
isErrorEnabled: () => getRealLogger().isErrorEnabled()
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
static createLogger(name) {
|
|
148
|
+
if (externalFactory) {
|
|
149
|
+
return externalFactory.getLogger(name);
|
|
150
|
+
}
|
|
151
|
+
if (this.config.defaultImplementation) {
|
|
152
|
+
return this.config.defaultImplementation(name);
|
|
153
|
+
}
|
|
154
|
+
return new ConsoleLogger(name, {
|
|
155
|
+
level: this.config.defaultLevel,
|
|
156
|
+
...this.config.consoleOptions
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
__publicField(LoggerFactoryImpl, "loggers", /* @__PURE__ */ new Map());
|
|
161
|
+
__publicField(LoggerFactoryImpl, "config", {
|
|
162
|
+
defaultLevel: LogLevelEnum2.INFO
|
|
163
|
+
});
|
|
164
|
+
function setLoggerFactory(factory) {
|
|
165
|
+
externalFactory = factory;
|
|
166
|
+
LoggerFactoryImpl.reset();
|
|
167
|
+
externalFactory = factory;
|
|
168
|
+
}
|
|
169
|
+
function createLogger(name) {
|
|
170
|
+
return LoggerFactoryImpl.getLogger(name);
|
|
171
|
+
}
|
|
172
|
+
export {
|
|
173
|
+
ConsoleLogger,
|
|
174
|
+
LogLevel,
|
|
175
|
+
LoggerFactoryImpl,
|
|
176
|
+
createLogger,
|
|
177
|
+
setLoggerFactory
|
|
178
|
+
};
|
|
179
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/logger/ConsoleLogger.ts","../src/logger/LoggerFactoryImpl.ts"],"sourcesContent":["/**\n * AgentX Common\n *\n * Internal common infrastructure for AgentX platform.\n * Provides shared utilities used by internal packages (engine, agent, etc.)\n *\n * ## Module Structure\n *\n * | Module | Purpose |\n * |----------|----------------------------------------------|\n * | logger/ | Lazy-initialized logging with pluggable backends |\n *\n * ## Design Principles\n *\n * 1. **Internal Use**: For AgentX internal packages only\n * 2. **Lazy Initialization**: Safe to use at module level\n * 3. **Pluggable**: External implementations via Runtime injection\n *\n * @example\n * ```typescript\n * import { createLogger } from \"@agentxjs/common\";\n *\n * const logger = createLogger(\"engine/AgentEngine\");\n * logger.info(\"Hello\");\n * ```\n *\n * @packageDocumentation\n */\n\n// Re-export types from agentx-types for convenience\nexport { LogLevel } from \"@agentxjs/types\";\nexport type { Logger, LogContext, LoggerFactory } from \"@agentxjs/types\";\n\n// Logger implementation\nexport {\n ConsoleLogger,\n type ConsoleLoggerOptions,\n LoggerFactoryImpl,\n type LoggerFactoryConfig,\n setLoggerFactory,\n createLogger,\n} from \"./logger\";\n","/**\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 \"@agentxjs/types\";\nimport { LogLevel as LogLevelEnum } from \"@agentxjs/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 ?? LogLevelEnum.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.level <= LogLevelEnum.DEBUG;\n }\n\n isInfoEnabled(): boolean {\n return this.level <= LogLevelEnum.INFO;\n }\n\n isWarnEnabled(): boolean {\n return this.level <= LogLevelEnum.WARN;\n }\n\n isErrorEnabled(): boolean {\n return this.level <= LogLevelEnum.ERROR;\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 \"@agentxjs/types\";\nimport { LogLevel as LogLevelEnum } from \"@agentxjs/types\";\nimport { ConsoleLogger, type ConsoleLoggerOptions } from \"./ConsoleLogger\";\n\n// External factory injected via Runtime\nlet externalFactory: LoggerFactory | null = null;\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: LogLevelEnum.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: LogLevelEnum.INFO };\n externalFactory = null;\n }\n\n private static createLazyLogger(name: string): Logger {\n let realLogger: Logger | null = null;\n\n const getRealLogger = (): Logger => {\n if (!realLogger) {\n realLogger = this.createLogger(name);\n }\n return realLogger;\n };\n\n return {\n name,\n level: this.config.defaultLevel || LogLevelEnum.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":";;;;;AA8BA,SAAS,gBAAgB;;;ACtBzB,SAAS,YAAY,oBAAoB;AAQlC,IAAM,iBAAN,MAAM,eAAgC;AAAA,EAc3C,YAAY,MAAc,UAAgC,CAAC,GAAG;AAb9D,wBAAS;AACT,wBAAS;AACT,wBAAiB;AACjB,wBAAiB;AAWf,SAAK,OAAO;AACZ,SAAK,QAAQ,QAAQ,SAAS,aAAa;AAC3C,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;AAAA,EAEA,MAAM,SAAyB,SAA4B;AACzD,QAAI,KAAK,eAAe,GAAG;AACzB,UAAI,mBAAmB,OAAO;AAC5B,aAAK,IAAI,SAAS,QAAQ,SAAS,EAAE,GAAG,SAAS,OAAO,QAAQ,MAAM,CAAC;AAAA,MACzE,OAAO;AACL,aAAK,IAAI,SAAS,SAAS,OAAO;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tF,MAAM,CAAC,SAAiB,YAAyB,cAAc,EAAE,KAAK,SAAS,OAAO;AAAA,MACtF,OAAO,CAAC,SAAyB,YAC/B,cAAc,EAAE,MAAM,SAAS,OAAO;AAAA,MACxC,gBAAgB,MAAM,cAAc,EAAE,eAAe;AAAA,MACrD,eAAe,MAAM,cAAc,EAAE,cAAc;AAAA,MACnD,eAAe,MAAM,cAAc,EAAE,cAAc;AAAA,MACnD,gBAAgB,MAAM,cAAc,EAAE,eAAe;AAAA,IACvD;AAAA,EACF;AAAA,EAEA,OAAe,aAAa,MAAsB;AAChD,QAAI,iBAAiB;AACnB,aAAO,gBAAgB,UAAU,IAAI;AAAA,IACvC;AAEA,QAAI,KAAK,OAAO,uBAAuB;AACrC,aAAO,KAAK,OAAO,sBAAsB,IAAI;AAAA,IAC/C;AAEA,WAAO,IAAI,cAAc,MAAM;AAAA,MAC7B,OAAO,KAAK,OAAO;AAAA,MACnB,GAAG,KAAK,OAAO;AAAA,IACjB,CAAC;AAAA,EACH;AACF;AAlEE,cADW,mBACI,WAA+B,oBAAI,IAAI;AACtD,cAFW,mBAEI,UAA8B;AAAA,EAC3C,cAAcA,cAAa;AAC7B;AAoEK,SAAS,iBAAiB,SAA8B;AAC7D,oBAAkB;AAClB,oBAAkB,MAAM;AACxB,oBAAkB;AACpB;AAWO,SAAS,aAAa,MAAsB;AACjD,SAAO,kBAAkB,UAAU,IAAI;AACzC;","names":["LogLevelEnum","LogLevelEnum"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentxjs/common",
|
|
3
|
+
"version": "0.0.8",
|
|
4
|
+
"description": "Common utilities for AgentX platform - Logger facade and shared infrastructure",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"agentx",
|
|
7
|
+
"common",
|
|
8
|
+
"logger",
|
|
9
|
+
"internal"
|
|
10
|
+
],
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/deepractice/Agent",
|
|
14
|
+
"directory": "packages/agentx-common"
|
|
15
|
+
},
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"main": "./dist/index.cjs",
|
|
26
|
+
"module": "./dist/index.js",
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"README.md"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup",
|
|
34
|
+
"dev": "tsup --watch",
|
|
35
|
+
"lint": "eslint .",
|
|
36
|
+
"typecheck": "tsc --noEmit",
|
|
37
|
+
"clean": "rm -rf dist"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@agentxjs/types": "workspace:*"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^22.19.1",
|
|
44
|
+
"tsup": "^8.5.0",
|
|
45
|
+
"typescript": "^5.9.3"
|
|
46
|
+
},
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
}
|
|
50
|
+
}
|