agentxjs 0.1.1 → 0.1.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.
- package/dist/browser.cjs +246 -66
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.js +230 -6
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +263 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +244 -8
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var common = require('@agentxjs/common');
|
|
4
|
-
var agentx = require('@agentxjs/types/agentx');
|
|
5
|
-
var event = require('@agentxjs/types/event');
|
|
6
|
-
|
|
7
3
|
var __defProp = Object.defineProperty;
|
|
8
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
5
|
var __esm = (fn, res) => function __init() {
|
|
@@ -14,6 +10,192 @@ var __export = (target, all) => {
|
|
|
14
10
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
11
|
};
|
|
16
12
|
|
|
13
|
+
// ../common/dist/index.js
|
|
14
|
+
var dist_exports = {};
|
|
15
|
+
__export(dist_exports, {
|
|
16
|
+
ConsoleLogger: () => exports.ConsoleLogger,
|
|
17
|
+
LoggerFactoryImpl: () => exports.LoggerFactoryImpl,
|
|
18
|
+
createLogger: () => createLogger,
|
|
19
|
+
setLoggerFactory: () => setLoggerFactory
|
|
20
|
+
});
|
|
21
|
+
function setLoggerFactory(factory) {
|
|
22
|
+
externalFactory = factory;
|
|
23
|
+
exports.LoggerFactoryImpl.reset();
|
|
24
|
+
externalFactory = factory;
|
|
25
|
+
}
|
|
26
|
+
function createLogger(name) {
|
|
27
|
+
return exports.LoggerFactoryImpl.getLogger(name);
|
|
28
|
+
}
|
|
29
|
+
var __defProp2, __defNormalProp, __publicField, _ConsoleLogger; exports.ConsoleLogger = void 0; var externalFactory; exports.LoggerFactoryImpl = void 0;
|
|
30
|
+
var init_dist = __esm({
|
|
31
|
+
"../common/dist/index.js"() {
|
|
32
|
+
__defProp2 = Object.defineProperty;
|
|
33
|
+
__defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
34
|
+
__publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
35
|
+
_ConsoleLogger = class _ConsoleLogger2 {
|
|
36
|
+
constructor(name, options = {}) {
|
|
37
|
+
__publicField(this, "name");
|
|
38
|
+
__publicField(this, "level");
|
|
39
|
+
__publicField(this, "colors");
|
|
40
|
+
__publicField(this, "timestamps");
|
|
41
|
+
this.name = name;
|
|
42
|
+
this.level = options.level ?? "info";
|
|
43
|
+
this.colors = options.colors ?? this.isNodeEnvironment();
|
|
44
|
+
this.timestamps = options.timestamps ?? true;
|
|
45
|
+
}
|
|
46
|
+
debug(message, context) {
|
|
47
|
+
if (this.isDebugEnabled()) {
|
|
48
|
+
this.log("DEBUG", message, context);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
info(message, context) {
|
|
52
|
+
if (this.isInfoEnabled()) {
|
|
53
|
+
this.log("INFO", message, context);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
warn(message, context) {
|
|
57
|
+
if (this.isWarnEnabled()) {
|
|
58
|
+
this.log("WARN", message, context);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
error(message, context) {
|
|
62
|
+
if (this.isErrorEnabled()) {
|
|
63
|
+
if (message instanceof Error) {
|
|
64
|
+
this.log("ERROR", message.message, { ...context, stack: message.stack });
|
|
65
|
+
} else {
|
|
66
|
+
this.log("ERROR", message, context);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
isDebugEnabled() {
|
|
71
|
+
return this.getLevelValue(this.level) <= this.getLevelValue("debug");
|
|
72
|
+
}
|
|
73
|
+
isInfoEnabled() {
|
|
74
|
+
return this.getLevelValue(this.level) <= this.getLevelValue("info");
|
|
75
|
+
}
|
|
76
|
+
isWarnEnabled() {
|
|
77
|
+
return this.getLevelValue(this.level) <= this.getLevelValue("warn");
|
|
78
|
+
}
|
|
79
|
+
isErrorEnabled() {
|
|
80
|
+
return this.getLevelValue(this.level) <= this.getLevelValue("error");
|
|
81
|
+
}
|
|
82
|
+
getLevelValue(level) {
|
|
83
|
+
const levels = {
|
|
84
|
+
debug: 0,
|
|
85
|
+
info: 1,
|
|
86
|
+
warn: 2,
|
|
87
|
+
error: 3,
|
|
88
|
+
silent: 4
|
|
89
|
+
};
|
|
90
|
+
return levels[level];
|
|
91
|
+
}
|
|
92
|
+
log(level, message, context) {
|
|
93
|
+
const parts = [];
|
|
94
|
+
if (this.timestamps) {
|
|
95
|
+
parts.push((/* @__PURE__ */ new Date()).toISOString());
|
|
96
|
+
}
|
|
97
|
+
if (this.colors) {
|
|
98
|
+
const color = _ConsoleLogger2.COLORS[level];
|
|
99
|
+
parts.push(`${color}${level.padEnd(5)}${_ConsoleLogger2.COLORS.RESET}`);
|
|
100
|
+
} else {
|
|
101
|
+
parts.push(level.padEnd(5));
|
|
102
|
+
}
|
|
103
|
+
parts.push(`[${this.name}]`);
|
|
104
|
+
parts.push(message);
|
|
105
|
+
const logLine = parts.join(" ");
|
|
106
|
+
const consoleMethod = this.getConsoleMethod(level);
|
|
107
|
+
if (context && Object.keys(context).length > 0) {
|
|
108
|
+
consoleMethod(logLine, context);
|
|
109
|
+
} else {
|
|
110
|
+
consoleMethod(logLine);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
getConsoleMethod(level) {
|
|
114
|
+
switch (level) {
|
|
115
|
+
case "DEBUG":
|
|
116
|
+
return console.debug.bind(console);
|
|
117
|
+
case "INFO":
|
|
118
|
+
return console.info.bind(console);
|
|
119
|
+
case "WARN":
|
|
120
|
+
return console.warn.bind(console);
|
|
121
|
+
case "ERROR":
|
|
122
|
+
return console.error.bind(console);
|
|
123
|
+
default:
|
|
124
|
+
return console.log.bind(console);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
isNodeEnvironment() {
|
|
128
|
+
return typeof process !== "undefined" && process.versions?.node !== void 0;
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
__publicField(_ConsoleLogger, "COLORS", {
|
|
132
|
+
DEBUG: "\x1B[36m",
|
|
133
|
+
INFO: "\x1B[32m",
|
|
134
|
+
WARN: "\x1B[33m",
|
|
135
|
+
ERROR: "\x1B[31m",
|
|
136
|
+
RESET: "\x1B[0m"
|
|
137
|
+
});
|
|
138
|
+
exports.ConsoleLogger = _ConsoleLogger;
|
|
139
|
+
externalFactory = null;
|
|
140
|
+
exports.LoggerFactoryImpl = class {
|
|
141
|
+
static getLogger(nameOrClass) {
|
|
142
|
+
const name = typeof nameOrClass === "string" ? nameOrClass : nameOrClass.name;
|
|
143
|
+
if (this.loggers.has(name)) {
|
|
144
|
+
return this.loggers.get(name);
|
|
145
|
+
}
|
|
146
|
+
const lazyLogger = this.createLazyLogger(name);
|
|
147
|
+
this.loggers.set(name, lazyLogger);
|
|
148
|
+
return lazyLogger;
|
|
149
|
+
}
|
|
150
|
+
static configure(config) {
|
|
151
|
+
this.config = { ...this.config, ...config };
|
|
152
|
+
}
|
|
153
|
+
static reset() {
|
|
154
|
+
this.loggers.clear();
|
|
155
|
+
this.config = { defaultLevel: "info" };
|
|
156
|
+
externalFactory = null;
|
|
157
|
+
}
|
|
158
|
+
static createLazyLogger(name) {
|
|
159
|
+
let realLogger = null;
|
|
160
|
+
const getRealLogger = () => {
|
|
161
|
+
if (!realLogger) {
|
|
162
|
+
realLogger = this.createLogger(name);
|
|
163
|
+
}
|
|
164
|
+
return realLogger;
|
|
165
|
+
};
|
|
166
|
+
return {
|
|
167
|
+
name,
|
|
168
|
+
level: this.config.defaultLevel || "info",
|
|
169
|
+
debug: (message, context) => getRealLogger().debug(message, context),
|
|
170
|
+
info: (message, context) => getRealLogger().info(message, context),
|
|
171
|
+
warn: (message, context) => getRealLogger().warn(message, context),
|
|
172
|
+
error: (message, context) => getRealLogger().error(message, context),
|
|
173
|
+
isDebugEnabled: () => getRealLogger().isDebugEnabled(),
|
|
174
|
+
isInfoEnabled: () => getRealLogger().isInfoEnabled(),
|
|
175
|
+
isWarnEnabled: () => getRealLogger().isWarnEnabled(),
|
|
176
|
+
isErrorEnabled: () => getRealLogger().isErrorEnabled()
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
static createLogger(name) {
|
|
180
|
+
if (externalFactory) {
|
|
181
|
+
return externalFactory.getLogger(name);
|
|
182
|
+
}
|
|
183
|
+
if (this.config.defaultImplementation) {
|
|
184
|
+
return this.config.defaultImplementation(name);
|
|
185
|
+
}
|
|
186
|
+
return new exports.ConsoleLogger(name, {
|
|
187
|
+
level: this.config.defaultLevel,
|
|
188
|
+
...this.config.consoleOptions
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
__publicField(exports.LoggerFactoryImpl, "loggers", /* @__PURE__ */ new Map());
|
|
193
|
+
__publicField(exports.LoggerFactoryImpl, "config", {
|
|
194
|
+
defaultLevel: "info"
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
|
|
17
199
|
// src/createLocalAgentX.ts
|
|
18
200
|
var createLocalAgentX_exports = {};
|
|
19
201
|
__export(createLocalAgentX_exports, {
|
|
@@ -58,7 +240,7 @@ function setupBroadcasting(connections, runtime) {
|
|
|
58
240
|
}
|
|
59
241
|
async function createLocalAgentX(config) {
|
|
60
242
|
if (config.logger) {
|
|
61
|
-
const { LoggerFactoryImpl: LoggerFactoryImpl2, setLoggerFactory: setLoggerFactory2 } = await
|
|
243
|
+
const { LoggerFactoryImpl: LoggerFactoryImpl2, setLoggerFactory: setLoggerFactory2 } = await Promise.resolve().then(() => (init_dist(), dist_exports));
|
|
62
244
|
LoggerFactoryImpl2.configure({
|
|
63
245
|
defaultLevel: config.logger.level,
|
|
64
246
|
consoleOptions: config.logger.console
|
|
@@ -162,12 +344,24 @@ async function createLocalAgentX(config) {
|
|
|
162
344
|
var logger;
|
|
163
345
|
var init_createLocalAgentX = __esm({
|
|
164
346
|
"src/createLocalAgentX.ts"() {
|
|
165
|
-
|
|
347
|
+
init_dist();
|
|
348
|
+
logger = createLogger("agentx/createAgentX");
|
|
166
349
|
}
|
|
167
350
|
});
|
|
168
|
-
|
|
351
|
+
|
|
352
|
+
// ../types/dist/agentx.js
|
|
353
|
+
function isRemoteConfig(config) {
|
|
354
|
+
return "serverUrl" in config && typeof config.serverUrl === "string";
|
|
355
|
+
}
|
|
356
|
+
function isLocalConfig(config) {
|
|
357
|
+
return !isRemoteConfig(config);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// src/createAgentX.ts
|
|
361
|
+
init_dist();
|
|
362
|
+
var remoteLogger = createLogger("agentx/RemoteClient");
|
|
169
363
|
async function createAgentX(config) {
|
|
170
|
-
if (config &&
|
|
364
|
+
if (config && isRemoteConfig(config)) {
|
|
171
365
|
return createRemoteAgentX(config.serverUrl);
|
|
172
366
|
}
|
|
173
367
|
const { createLocalAgentX: createLocalAgentX2 } = await Promise.resolve().then(() => (init_createLocalAgentX(), createLocalAgentX_exports));
|
|
@@ -306,83 +500,68 @@ async function createRemoteAgentX(serverUrl) {
|
|
|
306
500
|
};
|
|
307
501
|
}
|
|
308
502
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
Object.defineProperty(exports, "isAgentTurnEvent", {
|
|
354
|
-
enumerable: true,
|
|
355
|
-
get: function () { return event.isAgentTurnEvent; }
|
|
356
|
-
});
|
|
357
|
-
Object.defineProperty(exports, "isCommandEvent", {
|
|
358
|
-
enumerable: true,
|
|
359
|
-
get: function () { return event.isCommandEvent; }
|
|
360
|
-
});
|
|
361
|
-
Object.defineProperty(exports, "isCommandRequest", {
|
|
362
|
-
enumerable: true,
|
|
363
|
-
get: function () { return event.isCommandRequest; }
|
|
364
|
-
});
|
|
365
|
-
Object.defineProperty(exports, "isCommandResponse", {
|
|
366
|
-
enumerable: true,
|
|
367
|
-
get: function () { return event.isCommandResponse; }
|
|
368
|
-
});
|
|
369
|
-
Object.defineProperty(exports, "isFromSource", {
|
|
370
|
-
enumerable: true,
|
|
371
|
-
get: function () { return event.isFromSource; }
|
|
372
|
-
});
|
|
373
|
-
Object.defineProperty(exports, "isNotification", {
|
|
374
|
-
enumerable: true,
|
|
375
|
-
get: function () { return event.isNotification; }
|
|
376
|
-
});
|
|
377
|
-
Object.defineProperty(exports, "isRequest", {
|
|
378
|
-
enumerable: true,
|
|
379
|
-
get: function () { return event.isRequest; }
|
|
380
|
-
});
|
|
381
|
-
Object.defineProperty(exports, "isResult", {
|
|
382
|
-
enumerable: true,
|
|
383
|
-
get: function () { return event.isResult; }
|
|
384
|
-
});
|
|
503
|
+
// ../types/dist/event.js
|
|
504
|
+
function isFromSource(event, source) {
|
|
505
|
+
return event.source === source;
|
|
506
|
+
}
|
|
507
|
+
function hasIntent(event, intent) {
|
|
508
|
+
return event.intent === intent;
|
|
509
|
+
}
|
|
510
|
+
function isRequest(event) {
|
|
511
|
+
return event.intent === "request";
|
|
512
|
+
}
|
|
513
|
+
function isResult(event) {
|
|
514
|
+
return event.intent === "result";
|
|
515
|
+
}
|
|
516
|
+
function isNotification(event) {
|
|
517
|
+
return event.intent === "notification";
|
|
518
|
+
}
|
|
519
|
+
function isCommandEvent(event) {
|
|
520
|
+
return event.source === "command";
|
|
521
|
+
}
|
|
522
|
+
function isCommandRequest(event) {
|
|
523
|
+
return event.source === "command" && event.category === "request";
|
|
524
|
+
}
|
|
525
|
+
function isCommandResponse(event) {
|
|
526
|
+
return event.source === "command" && event.category === "response";
|
|
527
|
+
}
|
|
528
|
+
function isAgentStreamEvent(event) {
|
|
529
|
+
return event.source === "agent" && event.category === "stream";
|
|
530
|
+
}
|
|
531
|
+
function isAgentStateEvent(event) {
|
|
532
|
+
return event.source === "agent" && event.category === "state";
|
|
533
|
+
}
|
|
534
|
+
function isAgentMessageEvent(event) {
|
|
535
|
+
return event.source === "agent" && event.category === "message";
|
|
536
|
+
}
|
|
537
|
+
function isAgentTurnEvent(event) {
|
|
538
|
+
return event.source === "agent" && event.category === "turn";
|
|
539
|
+
}
|
|
540
|
+
function isAgentEvent(event) {
|
|
541
|
+
return event.source === "agent";
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// src/index.ts
|
|
545
|
+
init_dist();
|
|
546
|
+
|
|
385
547
|
exports.createAgentX = createAgentX;
|
|
548
|
+
exports.createLogger = createLogger;
|
|
386
549
|
exports.createRemoteAgentX = createRemoteAgentX;
|
|
550
|
+
exports.hasIntent = hasIntent;
|
|
551
|
+
exports.isAgentEvent = isAgentEvent;
|
|
552
|
+
exports.isAgentMessageEvent = isAgentMessageEvent;
|
|
553
|
+
exports.isAgentStateEvent = isAgentStateEvent;
|
|
554
|
+
exports.isAgentStreamEvent = isAgentStreamEvent;
|
|
555
|
+
exports.isAgentTurnEvent = isAgentTurnEvent;
|
|
556
|
+
exports.isCommandEvent = isCommandEvent;
|
|
557
|
+
exports.isCommandRequest = isCommandRequest;
|
|
558
|
+
exports.isCommandResponse = isCommandResponse;
|
|
559
|
+
exports.isFromSource = isFromSource;
|
|
560
|
+
exports.isLocalConfig = isLocalConfig;
|
|
561
|
+
exports.isNotification = isNotification;
|
|
562
|
+
exports.isRemoteConfig = isRemoteConfig;
|
|
563
|
+
exports.isRequest = isRequest;
|
|
564
|
+
exports.isResult = isResult;
|
|
565
|
+
exports.setLoggerFactory = setLoggerFactory;
|
|
387
566
|
//# sourceMappingURL=index.cjs.map
|
|
388
567
|
//# sourceMappingURL=index.cjs.map
|