agentxjs 0.0.2 → 0.0.4

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.
@@ -1,9 +1,167 @@
1
- import { isStreamEvent, isErrorEvent } from '@agentxjs/types';
2
- import { createLogger } from '@agentxjs/common';
1
+ import { LogLevel, isStreamEvent, isErrorEvent } from '@agentxjs/types';
3
2
 
4
3
  var __defProp = Object.defineProperty;
5
4
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
5
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
6
+ var __defProp2 = Object.defineProperty;
7
+ var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __publicField2 = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
9
+ var _ConsoleLogger = class _ConsoleLogger2 {
10
+ constructor(name, options = {}) {
11
+ __publicField2(this, "name");
12
+ __publicField2(this, "level");
13
+ __publicField2(this, "colors");
14
+ __publicField2(this, "timestamps");
15
+ this.name = name;
16
+ this.level = options.level ?? LogLevel.INFO;
17
+ this.colors = options.colors ?? this.isNodeEnvironment();
18
+ this.timestamps = options.timestamps ?? true;
19
+ }
20
+ debug(message, context) {
21
+ if (this.isDebugEnabled()) {
22
+ this.log("DEBUG", message, context);
23
+ }
24
+ }
25
+ info(message, context) {
26
+ if (this.isInfoEnabled()) {
27
+ this.log("INFO", message, context);
28
+ }
29
+ }
30
+ warn(message, context) {
31
+ if (this.isWarnEnabled()) {
32
+ this.log("WARN", message, context);
33
+ }
34
+ }
35
+ error(message, context) {
36
+ if (this.isErrorEnabled()) {
37
+ if (message instanceof Error) {
38
+ this.log("ERROR", message.message, { ...context, stack: message.stack });
39
+ } else {
40
+ this.log("ERROR", message, context);
41
+ }
42
+ }
43
+ }
44
+ isDebugEnabled() {
45
+ return this.level <= LogLevel.DEBUG;
46
+ }
47
+ isInfoEnabled() {
48
+ return this.level <= LogLevel.INFO;
49
+ }
50
+ isWarnEnabled() {
51
+ return this.level <= LogLevel.WARN;
52
+ }
53
+ isErrorEnabled() {
54
+ return this.level <= LogLevel.ERROR;
55
+ }
56
+ log(level, message, context) {
57
+ const parts = [];
58
+ if (this.timestamps) {
59
+ parts.push((/* @__PURE__ */ new Date()).toISOString());
60
+ }
61
+ if (this.colors) {
62
+ const color = _ConsoleLogger2.COLORS[level];
63
+ parts.push(`${color}${level.padEnd(5)}${_ConsoleLogger2.COLORS.RESET}`);
64
+ } else {
65
+ parts.push(level.padEnd(5));
66
+ }
67
+ parts.push(`[${this.name}]`);
68
+ parts.push(message);
69
+ const logLine = parts.join(" ");
70
+ const consoleMethod = this.getConsoleMethod(level);
71
+ if (context && Object.keys(context).length > 0) {
72
+ consoleMethod(logLine, context);
73
+ } else {
74
+ consoleMethod(logLine);
75
+ }
76
+ }
77
+ getConsoleMethod(level) {
78
+ switch (level) {
79
+ case "DEBUG":
80
+ return console.debug.bind(console);
81
+ case "INFO":
82
+ return console.info.bind(console);
83
+ case "WARN":
84
+ return console.warn.bind(console);
85
+ case "ERROR":
86
+ return console.error.bind(console);
87
+ default:
88
+ return console.log.bind(console);
89
+ }
90
+ }
91
+ isNodeEnvironment() {
92
+ return typeof process !== "undefined" && process.versions?.node !== void 0;
93
+ }
94
+ };
95
+ __publicField2(_ConsoleLogger, "COLORS", {
96
+ DEBUG: "\x1B[36m",
97
+ INFO: "\x1B[32m",
98
+ WARN: "\x1B[33m",
99
+ ERROR: "\x1B[31m",
100
+ RESET: "\x1B[0m"
101
+ });
102
+ var ConsoleLogger = _ConsoleLogger;
103
+ var externalFactory = null;
104
+ var LoggerFactoryImpl = class {
105
+ static getLogger(nameOrClass) {
106
+ const name = typeof nameOrClass === "string" ? nameOrClass : nameOrClass.name;
107
+ if (this.loggers.has(name)) {
108
+ return this.loggers.get(name);
109
+ }
110
+ const lazyLogger = this.createLazyLogger(name);
111
+ this.loggers.set(name, lazyLogger);
112
+ return lazyLogger;
113
+ }
114
+ static configure(config) {
115
+ this.config = { ...this.config, ...config };
116
+ }
117
+ static reset() {
118
+ this.loggers.clear();
119
+ this.config = { defaultLevel: LogLevel.INFO };
120
+ externalFactory = null;
121
+ }
122
+ static createLazyLogger(name) {
123
+ let realLogger = null;
124
+ const getRealLogger = () => {
125
+ if (!realLogger) {
126
+ realLogger = this.createLogger(name);
127
+ }
128
+ return realLogger;
129
+ };
130
+ return {
131
+ name,
132
+ level: this.config.defaultLevel || LogLevel.INFO,
133
+ debug: (message, context) => getRealLogger().debug(message, context),
134
+ info: (message, context) => getRealLogger().info(message, context),
135
+ warn: (message, context) => getRealLogger().warn(message, context),
136
+ error: (message, context) => getRealLogger().error(message, context),
137
+ isDebugEnabled: () => getRealLogger().isDebugEnabled(),
138
+ isInfoEnabled: () => getRealLogger().isInfoEnabled(),
139
+ isWarnEnabled: () => getRealLogger().isWarnEnabled(),
140
+ isErrorEnabled: () => getRealLogger().isErrorEnabled()
141
+ };
142
+ }
143
+ static createLogger(name) {
144
+ if (externalFactory) {
145
+ return externalFactory.getLogger(name);
146
+ }
147
+ if (this.config.defaultImplementation) {
148
+ return this.config.defaultImplementation(name);
149
+ }
150
+ return new ConsoleLogger(name, {
151
+ level: this.config.defaultLevel,
152
+ ...this.config.consoleOptions
153
+ });
154
+ }
155
+ };
156
+ __publicField2(LoggerFactoryImpl, "loggers", /* @__PURE__ */ new Map());
157
+ __publicField2(LoggerFactoryImpl, "config", {
158
+ defaultLevel: LogLevel.INFO
159
+ });
160
+ function createLogger(name) {
161
+ return LoggerFactoryImpl.getLogger(name);
162
+ }
163
+
164
+ // src/server/SSEServerTransport.ts
7
165
  var logger = createLogger("agentx/SSEServerTransport");
8
166
  var SSEConnection = class {
9
167
  constructor(connectionId, agentId) {
@@ -215,6 +373,8 @@ var SSEConnectionManager = class {
215
373
  return this._connections.size;
216
374
  }
217
375
  };
376
+
377
+ // src/server/createAgentXHandler.ts
218
378
  var logger2 = createLogger("agentx/AgentXHandler");
219
379
  var VERSION = "0.1.0";
220
380
  function createAgentXHandler(agentx, options = {}) {