@agentxjs/ui 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/index.js +203 -25
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -4,15 +4,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
4
4
|
import * as React from "react";
|
|
5
5
|
import React__default, { useState, useRef, useEffect, useCallback, forwardRef, createElement } from "react";
|
|
6
6
|
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var _ConsoleLogger = class
|
|
7
|
+
var __defProp$1 = Object.defineProperty;
|
|
8
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
10
|
+
var _ConsoleLogger$1 = class _ConsoleLogger {
|
|
11
11
|
constructor(name2, options = {}) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
__publicField$1(this, "name");
|
|
13
|
+
__publicField$1(this, "level");
|
|
14
|
+
__publicField$1(this, "colors");
|
|
15
|
+
__publicField$1(this, "timestamps");
|
|
16
16
|
this.name = name2;
|
|
17
17
|
this.level = options.level ?? "info";
|
|
18
18
|
this.colors = options.colors ?? this.isNodeEnvironment();
|
|
@@ -70,8 +70,8 @@ var _ConsoleLogger = class _ConsoleLogger2 {
|
|
|
70
70
|
parts.push((/* @__PURE__ */ new Date()).toISOString());
|
|
71
71
|
}
|
|
72
72
|
if (this.colors) {
|
|
73
|
-
const color2 =
|
|
74
|
-
parts.push(`${color2}${level.padEnd(5)}${
|
|
73
|
+
const color2 = _ConsoleLogger.COLORS[level];
|
|
74
|
+
parts.push(`${color2}${level.padEnd(5)}${_ConsoleLogger.COLORS.RESET}`);
|
|
75
75
|
} else {
|
|
76
76
|
parts.push(level.padEnd(5));
|
|
77
77
|
}
|
|
@@ -104,16 +104,16 @@ var _ConsoleLogger = class _ConsoleLogger2 {
|
|
|
104
104
|
return typeof process !== "undefined" && ((_a = process.versions) == null ? void 0 : _a.node) !== void 0;
|
|
105
105
|
}
|
|
106
106
|
};
|
|
107
|
-
|
|
107
|
+
__publicField$1(_ConsoleLogger$1, "COLORS", {
|
|
108
108
|
DEBUG: "\x1B[36m",
|
|
109
109
|
INFO: "\x1B[32m",
|
|
110
110
|
WARN: "\x1B[33m",
|
|
111
111
|
ERROR: "\x1B[31m",
|
|
112
112
|
RESET: "\x1B[0m"
|
|
113
113
|
});
|
|
114
|
-
var ConsoleLogger = _ConsoleLogger;
|
|
115
|
-
var externalFactory = null;
|
|
116
|
-
var LoggerFactoryImpl = class {
|
|
114
|
+
var ConsoleLogger$1 = _ConsoleLogger$1;
|
|
115
|
+
var externalFactory$1 = null;
|
|
116
|
+
var LoggerFactoryImpl$1 = class LoggerFactoryImpl {
|
|
117
117
|
static getLogger(nameOrClass) {
|
|
118
118
|
const name2 = typeof nameOrClass === "string" ? nameOrClass : nameOrClass.name;
|
|
119
119
|
if (this.loggers.has(name2)) {
|
|
@@ -129,7 +129,7 @@ var LoggerFactoryImpl = class {
|
|
|
129
129
|
static reset() {
|
|
130
130
|
this.loggers.clear();
|
|
131
131
|
this.config = { defaultLevel: "info" };
|
|
132
|
-
externalFactory = null;
|
|
132
|
+
externalFactory$1 = null;
|
|
133
133
|
}
|
|
134
134
|
static createLazyLogger(name2) {
|
|
135
135
|
let realLogger = null;
|
|
@@ -153,26 +153,26 @@ var LoggerFactoryImpl = class {
|
|
|
153
153
|
};
|
|
154
154
|
}
|
|
155
155
|
static createLogger(name2) {
|
|
156
|
-
if (externalFactory) {
|
|
157
|
-
return externalFactory.getLogger(name2);
|
|
156
|
+
if (externalFactory$1) {
|
|
157
|
+
return externalFactory$1.getLogger(name2);
|
|
158
158
|
}
|
|
159
159
|
if (this.config.defaultImplementation) {
|
|
160
160
|
return this.config.defaultImplementation(name2);
|
|
161
161
|
}
|
|
162
|
-
return new ConsoleLogger(name2, {
|
|
162
|
+
return new ConsoleLogger$1(name2, {
|
|
163
163
|
level: this.config.defaultLevel,
|
|
164
164
|
...this.config.consoleOptions
|
|
165
165
|
});
|
|
166
166
|
}
|
|
167
167
|
};
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
__publicField$1(LoggerFactoryImpl$1, "loggers", /* @__PURE__ */ new Map());
|
|
169
|
+
__publicField$1(LoggerFactoryImpl$1, "config", {
|
|
170
170
|
defaultLevel: "info"
|
|
171
171
|
});
|
|
172
|
-
function createLogger(name2) {
|
|
173
|
-
return LoggerFactoryImpl.getLogger(name2);
|
|
172
|
+
function createLogger$1(name2) {
|
|
173
|
+
return LoggerFactoryImpl$1.getLogger(name2);
|
|
174
174
|
}
|
|
175
|
-
const logger$2 = createLogger("ui/useAgent");
|
|
175
|
+
const logger$2 = createLogger$1("ui/useAgent");
|
|
176
176
|
function useAgent(agentx, imageId, options = {}) {
|
|
177
177
|
const { initialMessages = [], onSend, onError, onStatusChange } = options;
|
|
178
178
|
const [messages, setMessages] = useState(initialMessages);
|
|
@@ -412,9 +412,187 @@ function useAgent(agentx, imageId, options = {}) {
|
|
|
412
412
|
agentId: agentIdState
|
|
413
413
|
};
|
|
414
414
|
}
|
|
415
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
416
|
+
var __esm = (fn, res) => function __init() {
|
|
417
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
418
|
+
};
|
|
419
|
+
function createLogger(name2) {
|
|
420
|
+
return LoggerFactoryImpl2.getLogger(name2);
|
|
421
|
+
}
|
|
422
|
+
var __defProp2, __defNormalProp2, __publicField2, _ConsoleLogger2, ConsoleLogger, externalFactory, LoggerFactoryImpl2;
|
|
423
|
+
var init_dist = __esm({
|
|
424
|
+
"../common/dist/index.js"() {
|
|
425
|
+
__defProp2 = Object.defineProperty;
|
|
426
|
+
__defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
427
|
+
__publicField2 = (obj, key, value) => __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
428
|
+
_ConsoleLogger2 = class _ConsoleLogger22 {
|
|
429
|
+
constructor(name2, options = {}) {
|
|
430
|
+
__publicField2(this, "name");
|
|
431
|
+
__publicField2(this, "level");
|
|
432
|
+
__publicField2(this, "colors");
|
|
433
|
+
__publicField2(this, "timestamps");
|
|
434
|
+
this.name = name2;
|
|
435
|
+
this.level = options.level ?? "info";
|
|
436
|
+
this.colors = options.colors ?? this.isNodeEnvironment();
|
|
437
|
+
this.timestamps = options.timestamps ?? true;
|
|
438
|
+
}
|
|
439
|
+
debug(message, context) {
|
|
440
|
+
if (this.isDebugEnabled()) {
|
|
441
|
+
this.log("DEBUG", message, context);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
info(message, context) {
|
|
445
|
+
if (this.isInfoEnabled()) {
|
|
446
|
+
this.log("INFO", message, context);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
warn(message, context) {
|
|
450
|
+
if (this.isWarnEnabled()) {
|
|
451
|
+
this.log("WARN", message, context);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
error(message, context) {
|
|
455
|
+
if (this.isErrorEnabled()) {
|
|
456
|
+
if (message instanceof Error) {
|
|
457
|
+
this.log("ERROR", message.message, { ...context, stack: message.stack });
|
|
458
|
+
} else {
|
|
459
|
+
this.log("ERROR", message, context);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
isDebugEnabled() {
|
|
464
|
+
return this.getLevelValue(this.level) <= this.getLevelValue("debug");
|
|
465
|
+
}
|
|
466
|
+
isInfoEnabled() {
|
|
467
|
+
return this.getLevelValue(this.level) <= this.getLevelValue("info");
|
|
468
|
+
}
|
|
469
|
+
isWarnEnabled() {
|
|
470
|
+
return this.getLevelValue(this.level) <= this.getLevelValue("warn");
|
|
471
|
+
}
|
|
472
|
+
isErrorEnabled() {
|
|
473
|
+
return this.getLevelValue(this.level) <= this.getLevelValue("error");
|
|
474
|
+
}
|
|
475
|
+
getLevelValue(level) {
|
|
476
|
+
const levels = {
|
|
477
|
+
debug: 0,
|
|
478
|
+
info: 1,
|
|
479
|
+
warn: 2,
|
|
480
|
+
error: 3,
|
|
481
|
+
silent: 4
|
|
482
|
+
};
|
|
483
|
+
return levels[level];
|
|
484
|
+
}
|
|
485
|
+
log(level, message, context) {
|
|
486
|
+
const parts = [];
|
|
487
|
+
if (this.timestamps) {
|
|
488
|
+
parts.push((/* @__PURE__ */ new Date()).toISOString());
|
|
489
|
+
}
|
|
490
|
+
if (this.colors) {
|
|
491
|
+
const color2 = _ConsoleLogger22.COLORS[level];
|
|
492
|
+
parts.push(`${color2}${level.padEnd(5)}${_ConsoleLogger22.COLORS.RESET}`);
|
|
493
|
+
} else {
|
|
494
|
+
parts.push(level.padEnd(5));
|
|
495
|
+
}
|
|
496
|
+
parts.push(`[${this.name}]`);
|
|
497
|
+
parts.push(message);
|
|
498
|
+
const logLine = parts.join(" ");
|
|
499
|
+
const consoleMethod = this.getConsoleMethod(level);
|
|
500
|
+
if (context && Object.keys(context).length > 0) {
|
|
501
|
+
consoleMethod(logLine, context);
|
|
502
|
+
} else {
|
|
503
|
+
consoleMethod(logLine);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
getConsoleMethod(level) {
|
|
507
|
+
switch (level) {
|
|
508
|
+
case "DEBUG":
|
|
509
|
+
return console.debug.bind(console);
|
|
510
|
+
case "INFO":
|
|
511
|
+
return console.info.bind(console);
|
|
512
|
+
case "WARN":
|
|
513
|
+
return console.warn.bind(console);
|
|
514
|
+
case "ERROR":
|
|
515
|
+
return console.error.bind(console);
|
|
516
|
+
default:
|
|
517
|
+
return console.log.bind(console);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
isNodeEnvironment() {
|
|
521
|
+
var _a;
|
|
522
|
+
return typeof process !== "undefined" && ((_a = process.versions) == null ? void 0 : _a.node) !== void 0;
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
__publicField2(_ConsoleLogger2, "COLORS", {
|
|
526
|
+
DEBUG: "\x1B[36m",
|
|
527
|
+
INFO: "\x1B[32m",
|
|
528
|
+
WARN: "\x1B[33m",
|
|
529
|
+
ERROR: "\x1B[31m",
|
|
530
|
+
RESET: "\x1B[0m"
|
|
531
|
+
});
|
|
532
|
+
ConsoleLogger = _ConsoleLogger2;
|
|
533
|
+
externalFactory = null;
|
|
534
|
+
LoggerFactoryImpl2 = class {
|
|
535
|
+
static getLogger(nameOrClass) {
|
|
536
|
+
const name2 = typeof nameOrClass === "string" ? nameOrClass : nameOrClass.name;
|
|
537
|
+
if (this.loggers.has(name2)) {
|
|
538
|
+
return this.loggers.get(name2);
|
|
539
|
+
}
|
|
540
|
+
const lazyLogger = this.createLazyLogger(name2);
|
|
541
|
+
this.loggers.set(name2, lazyLogger);
|
|
542
|
+
return lazyLogger;
|
|
543
|
+
}
|
|
544
|
+
static configure(config) {
|
|
545
|
+
this.config = { ...this.config, ...config };
|
|
546
|
+
}
|
|
547
|
+
static reset() {
|
|
548
|
+
this.loggers.clear();
|
|
549
|
+
this.config = { defaultLevel: "info" };
|
|
550
|
+
externalFactory = null;
|
|
551
|
+
}
|
|
552
|
+
static createLazyLogger(name2) {
|
|
553
|
+
let realLogger = null;
|
|
554
|
+
const getRealLogger = () => {
|
|
555
|
+
if (!realLogger) {
|
|
556
|
+
realLogger = this.createLogger(name2);
|
|
557
|
+
}
|
|
558
|
+
return realLogger;
|
|
559
|
+
};
|
|
560
|
+
return {
|
|
561
|
+
name: name2,
|
|
562
|
+
level: this.config.defaultLevel || "info",
|
|
563
|
+
debug: (message, context) => getRealLogger().debug(message, context),
|
|
564
|
+
info: (message, context) => getRealLogger().info(message, context),
|
|
565
|
+
warn: (message, context) => getRealLogger().warn(message, context),
|
|
566
|
+
error: (message, context) => getRealLogger().error(message, context),
|
|
567
|
+
isDebugEnabled: () => getRealLogger().isDebugEnabled(),
|
|
568
|
+
isInfoEnabled: () => getRealLogger().isInfoEnabled(),
|
|
569
|
+
isWarnEnabled: () => getRealLogger().isWarnEnabled(),
|
|
570
|
+
isErrorEnabled: () => getRealLogger().isErrorEnabled()
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
static createLogger(name2) {
|
|
574
|
+
if (externalFactory) {
|
|
575
|
+
return externalFactory.getLogger(name2);
|
|
576
|
+
}
|
|
577
|
+
if (this.config.defaultImplementation) {
|
|
578
|
+
return this.config.defaultImplementation(name2);
|
|
579
|
+
}
|
|
580
|
+
return new ConsoleLogger(name2, {
|
|
581
|
+
level: this.config.defaultLevel,
|
|
582
|
+
...this.config.consoleOptions
|
|
583
|
+
});
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
__publicField2(LoggerFactoryImpl2, "loggers", /* @__PURE__ */ new Map());
|
|
587
|
+
__publicField2(LoggerFactoryImpl2, "config", {
|
|
588
|
+
defaultLevel: "info"
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
});
|
|
415
592
|
function isRemoteConfig(config) {
|
|
416
593
|
return "serverUrl" in config && typeof config.serverUrl === "string";
|
|
417
594
|
}
|
|
595
|
+
init_dist();
|
|
418
596
|
var remoteLogger = createLogger("agentx/RemoteClient");
|
|
419
597
|
var isBrowser = typeof window !== "undefined" && typeof window.WebSocket !== "undefined";
|
|
420
598
|
async function createRemoteAgentX(serverUrl) {
|
|
@@ -558,7 +736,7 @@ async function createAgentX(config) {
|
|
|
558
736
|
}
|
|
559
737
|
return createRemoteAgentX(config.serverUrl);
|
|
560
738
|
}
|
|
561
|
-
const logger$1 = createLogger("ui/useAgentX");
|
|
739
|
+
const logger$1 = createLogger$1("ui/useAgentX");
|
|
562
740
|
function useAgentX(serverUrl) {
|
|
563
741
|
const [agentx, setAgentx] = useState(null);
|
|
564
742
|
useEffect(() => {
|
|
@@ -586,7 +764,7 @@ function useAgentX(serverUrl) {
|
|
|
586
764
|
}, [serverUrl]);
|
|
587
765
|
return agentx;
|
|
588
766
|
}
|
|
589
|
-
const logger = createLogger("ui/useImages");
|
|
767
|
+
const logger = createLogger$1("ui/useImages");
|
|
590
768
|
function useImages(agentx, options = {}) {
|
|
591
769
|
const { containerId, autoLoad = true, onRun, onImagesChange } = options;
|
|
592
770
|
const [images, setImages] = useState([]);
|