@agentforge/core 0.6.2 → 0.6.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.cjs +118 -100
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +118 -100
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -803,7 +803,103 @@ Examples:`);
|
|
|
803
803
|
return parts.join("\n");
|
|
804
804
|
}
|
|
805
805
|
|
|
806
|
+
// src/langgraph/observability/logger.ts
|
|
807
|
+
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
808
|
+
LogLevel2["DEBUG"] = "debug";
|
|
809
|
+
LogLevel2["INFO"] = "info";
|
|
810
|
+
LogLevel2["WARN"] = "warn";
|
|
811
|
+
LogLevel2["ERROR"] = "error";
|
|
812
|
+
return LogLevel2;
|
|
813
|
+
})(LogLevel || {});
|
|
814
|
+
var LOG_LEVEL_PRIORITY = {
|
|
815
|
+
["debug" /* DEBUG */]: 0,
|
|
816
|
+
["info" /* INFO */]: 1,
|
|
817
|
+
["warn" /* WARN */]: 2,
|
|
818
|
+
["error" /* ERROR */]: 3
|
|
819
|
+
};
|
|
820
|
+
var LoggerImpl = class _LoggerImpl {
|
|
821
|
+
name;
|
|
822
|
+
options;
|
|
823
|
+
context;
|
|
824
|
+
constructor(name, options = {}, context = {}) {
|
|
825
|
+
this.name = name;
|
|
826
|
+
this.context = context;
|
|
827
|
+
this.options = {
|
|
828
|
+
level: options.level ?? "info" /* INFO */,
|
|
829
|
+
format: options.format ?? "pretty",
|
|
830
|
+
destination: options.destination ?? process.stdout,
|
|
831
|
+
includeTimestamp: options.includeTimestamp ?? true,
|
|
832
|
+
includeContext: options.includeContext ?? true
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
debug(message, data) {
|
|
836
|
+
this.log("debug" /* DEBUG */, message, data);
|
|
837
|
+
}
|
|
838
|
+
info(message, data) {
|
|
839
|
+
this.log("info" /* INFO */, message, data);
|
|
840
|
+
}
|
|
841
|
+
warn(message, data) {
|
|
842
|
+
this.log("warn" /* WARN */, message, data);
|
|
843
|
+
}
|
|
844
|
+
error(message, data) {
|
|
845
|
+
this.log("error" /* ERROR */, message, data);
|
|
846
|
+
}
|
|
847
|
+
isDebugEnabled() {
|
|
848
|
+
return this.isLevelEnabled("debug" /* DEBUG */);
|
|
849
|
+
}
|
|
850
|
+
isLevelEnabled(level) {
|
|
851
|
+
return LOG_LEVEL_PRIORITY[level] >= LOG_LEVEL_PRIORITY[this.options.level];
|
|
852
|
+
}
|
|
853
|
+
withContext(context) {
|
|
854
|
+
return new _LoggerImpl(this.name, this.options, { ...this.context, ...context });
|
|
855
|
+
}
|
|
856
|
+
log(level, message, data) {
|
|
857
|
+
if (LOG_LEVEL_PRIORITY[level] < LOG_LEVEL_PRIORITY[this.options.level]) {
|
|
858
|
+
return;
|
|
859
|
+
}
|
|
860
|
+
const entry = {
|
|
861
|
+
level,
|
|
862
|
+
name: this.name,
|
|
863
|
+
message
|
|
864
|
+
};
|
|
865
|
+
if (this.options.includeTimestamp) {
|
|
866
|
+
entry.timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
867
|
+
}
|
|
868
|
+
if (this.options.includeContext && Object.keys(this.context).length > 0) {
|
|
869
|
+
entry.context = this.context;
|
|
870
|
+
}
|
|
871
|
+
if (data) {
|
|
872
|
+
entry.data = data;
|
|
873
|
+
}
|
|
874
|
+
const output = this.format(entry);
|
|
875
|
+
this.options.destination.write(output + "\n");
|
|
876
|
+
}
|
|
877
|
+
format(entry) {
|
|
878
|
+
if (this.options.format === "json") {
|
|
879
|
+
return JSON.stringify(entry);
|
|
880
|
+
}
|
|
881
|
+
const parts = [];
|
|
882
|
+
if (entry.timestamp) {
|
|
883
|
+
parts.push(`[${entry.timestamp}]`);
|
|
884
|
+
}
|
|
885
|
+
parts.push(`[${entry.level.toUpperCase()}]`);
|
|
886
|
+
parts.push(`[${entry.name}]`);
|
|
887
|
+
parts.push(entry.message);
|
|
888
|
+
if (entry.context) {
|
|
889
|
+
parts.push(`context=${JSON.stringify(entry.context)}`);
|
|
890
|
+
}
|
|
891
|
+
if (entry.data) {
|
|
892
|
+
parts.push(`data=${JSON.stringify(entry.data)}`);
|
|
893
|
+
}
|
|
894
|
+
return parts.join(" ");
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
function createLogger(name, options) {
|
|
898
|
+
return new LoggerImpl(name, options);
|
|
899
|
+
}
|
|
900
|
+
|
|
806
901
|
// src/tools/registry.ts
|
|
902
|
+
var logger = createLogger("agentforge:core:tools:registry", { level: "info" /* INFO */ });
|
|
807
903
|
var RegistryEvent = /* @__PURE__ */ ((RegistryEvent2) => {
|
|
808
904
|
RegistryEvent2["TOOL_REGISTERED"] = "tool:registered";
|
|
809
905
|
RegistryEvent2["TOOL_REMOVED"] = "tool:removed";
|
|
@@ -1095,7 +1191,11 @@ var ToolRegistry = class {
|
|
|
1095
1191
|
try {
|
|
1096
1192
|
handler(data);
|
|
1097
1193
|
} catch (error) {
|
|
1098
|
-
|
|
1194
|
+
logger.error("Event handler error", {
|
|
1195
|
+
event,
|
|
1196
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1197
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
1198
|
+
});
|
|
1099
1199
|
}
|
|
1100
1200
|
});
|
|
1101
1201
|
}
|
|
@@ -1493,6 +1593,7 @@ function createToolExecutor(config = {}) {
|
|
|
1493
1593
|
}
|
|
1494
1594
|
|
|
1495
1595
|
// src/tools/lifecycle.ts
|
|
1596
|
+
var logger2 = createLogger("agentforge:core:tools:lifecycle", { level: "info" /* INFO */ });
|
|
1496
1597
|
var ManagedTool = class {
|
|
1497
1598
|
name;
|
|
1498
1599
|
description;
|
|
@@ -1523,7 +1624,13 @@ var ManagedTool = class {
|
|
|
1523
1624
|
this._context = config.context;
|
|
1524
1625
|
if (this.autoCleanup) {
|
|
1525
1626
|
process.on("beforeExit", () => {
|
|
1526
|
-
this.cleanup().catch(
|
|
1627
|
+
this.cleanup().catch(
|
|
1628
|
+
(err) => logger2.error("Cleanup failed", {
|
|
1629
|
+
toolName: this.name,
|
|
1630
|
+
error: err instanceof Error ? err.message : String(err),
|
|
1631
|
+
stack: err instanceof Error ? err.stack : void 0
|
|
1632
|
+
})
|
|
1633
|
+
);
|
|
1527
1634
|
});
|
|
1528
1635
|
}
|
|
1529
1636
|
}
|
|
@@ -2393,95 +2500,6 @@ function withTracing(node, options) {
|
|
|
2393
2500
|
};
|
|
2394
2501
|
}
|
|
2395
2502
|
|
|
2396
|
-
// src/langgraph/observability/logger.ts
|
|
2397
|
-
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
2398
|
-
LogLevel2["DEBUG"] = "debug";
|
|
2399
|
-
LogLevel2["INFO"] = "info";
|
|
2400
|
-
LogLevel2["WARN"] = "warn";
|
|
2401
|
-
LogLevel2["ERROR"] = "error";
|
|
2402
|
-
return LogLevel2;
|
|
2403
|
-
})(LogLevel || {});
|
|
2404
|
-
var LOG_LEVEL_PRIORITY = {
|
|
2405
|
-
["debug" /* DEBUG */]: 0,
|
|
2406
|
-
["info" /* INFO */]: 1,
|
|
2407
|
-
["warn" /* WARN */]: 2,
|
|
2408
|
-
["error" /* ERROR */]: 3
|
|
2409
|
-
};
|
|
2410
|
-
var LoggerImpl = class _LoggerImpl {
|
|
2411
|
-
name;
|
|
2412
|
-
options;
|
|
2413
|
-
context;
|
|
2414
|
-
constructor(name, options = {}, context = {}) {
|
|
2415
|
-
this.name = name;
|
|
2416
|
-
this.context = context;
|
|
2417
|
-
this.options = {
|
|
2418
|
-
level: options.level ?? "info" /* INFO */,
|
|
2419
|
-
format: options.format ?? "pretty",
|
|
2420
|
-
destination: options.destination ?? process.stdout,
|
|
2421
|
-
includeTimestamp: options.includeTimestamp ?? true,
|
|
2422
|
-
includeContext: options.includeContext ?? true
|
|
2423
|
-
};
|
|
2424
|
-
}
|
|
2425
|
-
debug(message, data) {
|
|
2426
|
-
this.log("debug" /* DEBUG */, message, data);
|
|
2427
|
-
}
|
|
2428
|
-
info(message, data) {
|
|
2429
|
-
this.log("info" /* INFO */, message, data);
|
|
2430
|
-
}
|
|
2431
|
-
warn(message, data) {
|
|
2432
|
-
this.log("warn" /* WARN */, message, data);
|
|
2433
|
-
}
|
|
2434
|
-
error(message, data) {
|
|
2435
|
-
this.log("error" /* ERROR */, message, data);
|
|
2436
|
-
}
|
|
2437
|
-
withContext(context) {
|
|
2438
|
-
return new _LoggerImpl(this.name, this.options, { ...this.context, ...context });
|
|
2439
|
-
}
|
|
2440
|
-
log(level, message, data) {
|
|
2441
|
-
if (LOG_LEVEL_PRIORITY[level] < LOG_LEVEL_PRIORITY[this.options.level]) {
|
|
2442
|
-
return;
|
|
2443
|
-
}
|
|
2444
|
-
const entry = {
|
|
2445
|
-
level,
|
|
2446
|
-
name: this.name,
|
|
2447
|
-
message
|
|
2448
|
-
};
|
|
2449
|
-
if (this.options.includeTimestamp) {
|
|
2450
|
-
entry.timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
2451
|
-
}
|
|
2452
|
-
if (this.options.includeContext && Object.keys(this.context).length > 0) {
|
|
2453
|
-
entry.context = this.context;
|
|
2454
|
-
}
|
|
2455
|
-
if (data) {
|
|
2456
|
-
entry.data = data;
|
|
2457
|
-
}
|
|
2458
|
-
const output = this.format(entry);
|
|
2459
|
-
this.options.destination.write(output + "\n");
|
|
2460
|
-
}
|
|
2461
|
-
format(entry) {
|
|
2462
|
-
if (this.options.format === "json") {
|
|
2463
|
-
return JSON.stringify(entry);
|
|
2464
|
-
}
|
|
2465
|
-
const parts = [];
|
|
2466
|
-
if (entry.timestamp) {
|
|
2467
|
-
parts.push(`[${entry.timestamp}]`);
|
|
2468
|
-
}
|
|
2469
|
-
parts.push(`[${entry.level.toUpperCase()}]`);
|
|
2470
|
-
parts.push(`[${entry.name}]`);
|
|
2471
|
-
parts.push(entry.message);
|
|
2472
|
-
if (entry.context) {
|
|
2473
|
-
parts.push(`context=${JSON.stringify(entry.context)}`);
|
|
2474
|
-
}
|
|
2475
|
-
if (entry.data) {
|
|
2476
|
-
parts.push(`data=${JSON.stringify(entry.data)}`);
|
|
2477
|
-
}
|
|
2478
|
-
return parts.join(" ");
|
|
2479
|
-
}
|
|
2480
|
-
};
|
|
2481
|
-
function createLogger(name, options) {
|
|
2482
|
-
return new LoggerImpl(name, options);
|
|
2483
|
-
}
|
|
2484
|
-
|
|
2485
2503
|
// src/langgraph/observability/metrics.ts
|
|
2486
2504
|
var MetricType = /* @__PURE__ */ ((MetricType2) => {
|
|
2487
2505
|
MetricType2["COUNTER"] = "counter";
|
|
@@ -2791,14 +2809,14 @@ var withLogging = (options) => {
|
|
|
2791
2809
|
onComplete,
|
|
2792
2810
|
onError
|
|
2793
2811
|
} = options;
|
|
2794
|
-
const
|
|
2812
|
+
const logger3 = providedLogger || createLogger(name, { level });
|
|
2795
2813
|
return (node) => {
|
|
2796
2814
|
return async (state) => {
|
|
2797
2815
|
const startTime = Date.now();
|
|
2798
2816
|
try {
|
|
2799
2817
|
if (logInput) {
|
|
2800
2818
|
const data = extractData ? extractData(state) : { state };
|
|
2801
|
-
|
|
2819
|
+
logger3.info("Node execution started", data);
|
|
2802
2820
|
}
|
|
2803
2821
|
if (onStart) {
|
|
2804
2822
|
onStart(state);
|
|
@@ -2808,9 +2826,9 @@ var withLogging = (options) => {
|
|
|
2808
2826
|
if (logOutput) {
|
|
2809
2827
|
const data = extractData ? extractData(result) : { result };
|
|
2810
2828
|
if (logDuration) {
|
|
2811
|
-
|
|
2829
|
+
logger3.info(`Node execution completed (${duration}ms)`, data);
|
|
2812
2830
|
} else {
|
|
2813
|
-
|
|
2831
|
+
logger3.info("Node execution completed", data);
|
|
2814
2832
|
}
|
|
2815
2833
|
}
|
|
2816
2834
|
if (onComplete) {
|
|
@@ -2821,7 +2839,7 @@ var withLogging = (options) => {
|
|
|
2821
2839
|
const duration = Date.now() - startTime;
|
|
2822
2840
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
2823
2841
|
if (logErrors) {
|
|
2824
|
-
|
|
2842
|
+
logger3.error(`Node execution failed (${duration}ms)`, {
|
|
2825
2843
|
error: err.message,
|
|
2826
2844
|
stack: err.stack
|
|
2827
2845
|
});
|
|
@@ -2857,7 +2875,7 @@ function withLogging2(options) {
|
|
|
2857
2875
|
function production(node, options) {
|
|
2858
2876
|
const {
|
|
2859
2877
|
nodeName,
|
|
2860
|
-
logger,
|
|
2878
|
+
logger: logger3,
|
|
2861
2879
|
enableMetrics = true,
|
|
2862
2880
|
enableTracing = true,
|
|
2863
2881
|
enableRetry = true,
|
|
@@ -2865,7 +2883,7 @@ function production(node, options) {
|
|
|
2865
2883
|
retryOptions = {},
|
|
2866
2884
|
errorOptions = {}
|
|
2867
2885
|
} = options;
|
|
2868
|
-
const actualLogger =
|
|
2886
|
+
const actualLogger = logger3 || createLogger(nodeName, { level: "info" /* INFO */ });
|
|
2869
2887
|
const middleware = [];
|
|
2870
2888
|
middleware.push(
|
|
2871
2889
|
withLogging2({
|
|
@@ -2929,9 +2947,9 @@ function development(node, options) {
|
|
|
2929
2947
|
const {
|
|
2930
2948
|
nodeName,
|
|
2931
2949
|
verbose = true,
|
|
2932
|
-
logger
|
|
2950
|
+
logger: logger3
|
|
2933
2951
|
} = options;
|
|
2934
|
-
const actualLogger =
|
|
2952
|
+
const actualLogger = logger3 || createLogger(nodeName, { level: "debug" /* DEBUG */ });
|
|
2935
2953
|
return withLogging2({
|
|
2936
2954
|
logger: actualLogger,
|
|
2937
2955
|
name: nodeName,
|
package/dist/index.d.cts
CHANGED
|
@@ -3013,6 +3013,15 @@ interface Logger {
|
|
|
3013
3013
|
* Log an error message
|
|
3014
3014
|
*/
|
|
3015
3015
|
error(message: string, data?: Record<string, any>): void;
|
|
3016
|
+
/**
|
|
3017
|
+
* Check if debug logging is enabled
|
|
3018
|
+
* Useful for avoiding expensive computations when debug is disabled
|
|
3019
|
+
*/
|
|
3020
|
+
isDebugEnabled(): boolean;
|
|
3021
|
+
/**
|
|
3022
|
+
* Check if a specific log level is enabled
|
|
3023
|
+
*/
|
|
3024
|
+
isLevelEnabled(level: LogLevel): boolean;
|
|
3016
3025
|
/**
|
|
3017
3026
|
* Create a child logger with additional context
|
|
3018
3027
|
*/
|
|
@@ -3022,6 +3031,7 @@ interface Logger {
|
|
|
3022
3031
|
* Create a structured logger.
|
|
3023
3032
|
*
|
|
3024
3033
|
* @example
|
|
3034
|
+
* Basic usage:
|
|
3025
3035
|
* ```typescript
|
|
3026
3036
|
* import { createLogger, LogLevel } from '@agentforge/core';
|
|
3027
3037
|
*
|
|
@@ -3034,6 +3044,16 @@ interface Logger {
|
|
|
3034
3044
|
* logger.error('Request failed', { error: err.message });
|
|
3035
3045
|
* ```
|
|
3036
3046
|
*
|
|
3047
|
+
* @example
|
|
3048
|
+
* Performance optimization with isDebugEnabled:
|
|
3049
|
+
* ```typescript
|
|
3050
|
+
* // Avoid expensive computations when debug is disabled
|
|
3051
|
+
* if (logger.isDebugEnabled()) {
|
|
3052
|
+
* const expensiveData = computeExpensiveDebugInfo();
|
|
3053
|
+
* logger.debug('Debug info', expensiveData);
|
|
3054
|
+
* }
|
|
3055
|
+
* ```
|
|
3056
|
+
*
|
|
3037
3057
|
* @param name - Logger name (typically the agent or component name)
|
|
3038
3058
|
* @param options - Logger configuration options
|
|
3039
3059
|
* @returns A logger instance
|
package/dist/index.d.ts
CHANGED
|
@@ -3013,6 +3013,15 @@ interface Logger {
|
|
|
3013
3013
|
* Log an error message
|
|
3014
3014
|
*/
|
|
3015
3015
|
error(message: string, data?: Record<string, any>): void;
|
|
3016
|
+
/**
|
|
3017
|
+
* Check if debug logging is enabled
|
|
3018
|
+
* Useful for avoiding expensive computations when debug is disabled
|
|
3019
|
+
*/
|
|
3020
|
+
isDebugEnabled(): boolean;
|
|
3021
|
+
/**
|
|
3022
|
+
* Check if a specific log level is enabled
|
|
3023
|
+
*/
|
|
3024
|
+
isLevelEnabled(level: LogLevel): boolean;
|
|
3016
3025
|
/**
|
|
3017
3026
|
* Create a child logger with additional context
|
|
3018
3027
|
*/
|
|
@@ -3022,6 +3031,7 @@ interface Logger {
|
|
|
3022
3031
|
* Create a structured logger.
|
|
3023
3032
|
*
|
|
3024
3033
|
* @example
|
|
3034
|
+
* Basic usage:
|
|
3025
3035
|
* ```typescript
|
|
3026
3036
|
* import { createLogger, LogLevel } from '@agentforge/core';
|
|
3027
3037
|
*
|
|
@@ -3034,6 +3044,16 @@ interface Logger {
|
|
|
3034
3044
|
* logger.error('Request failed', { error: err.message });
|
|
3035
3045
|
* ```
|
|
3036
3046
|
*
|
|
3047
|
+
* @example
|
|
3048
|
+
* Performance optimization with isDebugEnabled:
|
|
3049
|
+
* ```typescript
|
|
3050
|
+
* // Avoid expensive computations when debug is disabled
|
|
3051
|
+
* if (logger.isDebugEnabled()) {
|
|
3052
|
+
* const expensiveData = computeExpensiveDebugInfo();
|
|
3053
|
+
* logger.debug('Debug info', expensiveData);
|
|
3054
|
+
* }
|
|
3055
|
+
* ```
|
|
3056
|
+
*
|
|
3037
3057
|
* @param name - Logger name (typically the agent or component name)
|
|
3038
3058
|
* @param options - Logger configuration options
|
|
3039
3059
|
* @returns A logger instance
|
package/dist/index.js
CHANGED
|
@@ -647,7 +647,103 @@ Examples:`);
|
|
|
647
647
|
return parts.join("\n");
|
|
648
648
|
}
|
|
649
649
|
|
|
650
|
+
// src/langgraph/observability/logger.ts
|
|
651
|
+
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
652
|
+
LogLevel2["DEBUG"] = "debug";
|
|
653
|
+
LogLevel2["INFO"] = "info";
|
|
654
|
+
LogLevel2["WARN"] = "warn";
|
|
655
|
+
LogLevel2["ERROR"] = "error";
|
|
656
|
+
return LogLevel2;
|
|
657
|
+
})(LogLevel || {});
|
|
658
|
+
var LOG_LEVEL_PRIORITY = {
|
|
659
|
+
["debug" /* DEBUG */]: 0,
|
|
660
|
+
["info" /* INFO */]: 1,
|
|
661
|
+
["warn" /* WARN */]: 2,
|
|
662
|
+
["error" /* ERROR */]: 3
|
|
663
|
+
};
|
|
664
|
+
var LoggerImpl = class _LoggerImpl {
|
|
665
|
+
name;
|
|
666
|
+
options;
|
|
667
|
+
context;
|
|
668
|
+
constructor(name, options = {}, context = {}) {
|
|
669
|
+
this.name = name;
|
|
670
|
+
this.context = context;
|
|
671
|
+
this.options = {
|
|
672
|
+
level: options.level ?? "info" /* INFO */,
|
|
673
|
+
format: options.format ?? "pretty",
|
|
674
|
+
destination: options.destination ?? process.stdout,
|
|
675
|
+
includeTimestamp: options.includeTimestamp ?? true,
|
|
676
|
+
includeContext: options.includeContext ?? true
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
debug(message, data) {
|
|
680
|
+
this.log("debug" /* DEBUG */, message, data);
|
|
681
|
+
}
|
|
682
|
+
info(message, data) {
|
|
683
|
+
this.log("info" /* INFO */, message, data);
|
|
684
|
+
}
|
|
685
|
+
warn(message, data) {
|
|
686
|
+
this.log("warn" /* WARN */, message, data);
|
|
687
|
+
}
|
|
688
|
+
error(message, data) {
|
|
689
|
+
this.log("error" /* ERROR */, message, data);
|
|
690
|
+
}
|
|
691
|
+
isDebugEnabled() {
|
|
692
|
+
return this.isLevelEnabled("debug" /* DEBUG */);
|
|
693
|
+
}
|
|
694
|
+
isLevelEnabled(level) {
|
|
695
|
+
return LOG_LEVEL_PRIORITY[level] >= LOG_LEVEL_PRIORITY[this.options.level];
|
|
696
|
+
}
|
|
697
|
+
withContext(context) {
|
|
698
|
+
return new _LoggerImpl(this.name, this.options, { ...this.context, ...context });
|
|
699
|
+
}
|
|
700
|
+
log(level, message, data) {
|
|
701
|
+
if (LOG_LEVEL_PRIORITY[level] < LOG_LEVEL_PRIORITY[this.options.level]) {
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
const entry = {
|
|
705
|
+
level,
|
|
706
|
+
name: this.name,
|
|
707
|
+
message
|
|
708
|
+
};
|
|
709
|
+
if (this.options.includeTimestamp) {
|
|
710
|
+
entry.timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
711
|
+
}
|
|
712
|
+
if (this.options.includeContext && Object.keys(this.context).length > 0) {
|
|
713
|
+
entry.context = this.context;
|
|
714
|
+
}
|
|
715
|
+
if (data) {
|
|
716
|
+
entry.data = data;
|
|
717
|
+
}
|
|
718
|
+
const output = this.format(entry);
|
|
719
|
+
this.options.destination.write(output + "\n");
|
|
720
|
+
}
|
|
721
|
+
format(entry) {
|
|
722
|
+
if (this.options.format === "json") {
|
|
723
|
+
return JSON.stringify(entry);
|
|
724
|
+
}
|
|
725
|
+
const parts = [];
|
|
726
|
+
if (entry.timestamp) {
|
|
727
|
+
parts.push(`[${entry.timestamp}]`);
|
|
728
|
+
}
|
|
729
|
+
parts.push(`[${entry.level.toUpperCase()}]`);
|
|
730
|
+
parts.push(`[${entry.name}]`);
|
|
731
|
+
parts.push(entry.message);
|
|
732
|
+
if (entry.context) {
|
|
733
|
+
parts.push(`context=${JSON.stringify(entry.context)}`);
|
|
734
|
+
}
|
|
735
|
+
if (entry.data) {
|
|
736
|
+
parts.push(`data=${JSON.stringify(entry.data)}`);
|
|
737
|
+
}
|
|
738
|
+
return parts.join(" ");
|
|
739
|
+
}
|
|
740
|
+
};
|
|
741
|
+
function createLogger(name, options) {
|
|
742
|
+
return new LoggerImpl(name, options);
|
|
743
|
+
}
|
|
744
|
+
|
|
650
745
|
// src/tools/registry.ts
|
|
746
|
+
var logger = createLogger("agentforge:core:tools:registry", { level: "info" /* INFO */ });
|
|
651
747
|
var RegistryEvent = /* @__PURE__ */ ((RegistryEvent2) => {
|
|
652
748
|
RegistryEvent2["TOOL_REGISTERED"] = "tool:registered";
|
|
653
749
|
RegistryEvent2["TOOL_REMOVED"] = "tool:removed";
|
|
@@ -939,7 +1035,11 @@ var ToolRegistry = class {
|
|
|
939
1035
|
try {
|
|
940
1036
|
handler(data);
|
|
941
1037
|
} catch (error) {
|
|
942
|
-
|
|
1038
|
+
logger.error("Event handler error", {
|
|
1039
|
+
event,
|
|
1040
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1041
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
1042
|
+
});
|
|
943
1043
|
}
|
|
944
1044
|
});
|
|
945
1045
|
}
|
|
@@ -1337,6 +1437,7 @@ function createToolExecutor(config = {}) {
|
|
|
1337
1437
|
}
|
|
1338
1438
|
|
|
1339
1439
|
// src/tools/lifecycle.ts
|
|
1440
|
+
var logger2 = createLogger("agentforge:core:tools:lifecycle", { level: "info" /* INFO */ });
|
|
1340
1441
|
var ManagedTool = class {
|
|
1341
1442
|
name;
|
|
1342
1443
|
description;
|
|
@@ -1367,7 +1468,13 @@ var ManagedTool = class {
|
|
|
1367
1468
|
this._context = config.context;
|
|
1368
1469
|
if (this.autoCleanup) {
|
|
1369
1470
|
process.on("beforeExit", () => {
|
|
1370
|
-
this.cleanup().catch(
|
|
1471
|
+
this.cleanup().catch(
|
|
1472
|
+
(err) => logger2.error("Cleanup failed", {
|
|
1473
|
+
toolName: this.name,
|
|
1474
|
+
error: err instanceof Error ? err.message : String(err),
|
|
1475
|
+
stack: err instanceof Error ? err.stack : void 0
|
|
1476
|
+
})
|
|
1477
|
+
);
|
|
1371
1478
|
});
|
|
1372
1479
|
}
|
|
1373
1480
|
}
|
|
@@ -2237,95 +2344,6 @@ function withTracing(node, options) {
|
|
|
2237
2344
|
};
|
|
2238
2345
|
}
|
|
2239
2346
|
|
|
2240
|
-
// src/langgraph/observability/logger.ts
|
|
2241
|
-
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
2242
|
-
LogLevel2["DEBUG"] = "debug";
|
|
2243
|
-
LogLevel2["INFO"] = "info";
|
|
2244
|
-
LogLevel2["WARN"] = "warn";
|
|
2245
|
-
LogLevel2["ERROR"] = "error";
|
|
2246
|
-
return LogLevel2;
|
|
2247
|
-
})(LogLevel || {});
|
|
2248
|
-
var LOG_LEVEL_PRIORITY = {
|
|
2249
|
-
["debug" /* DEBUG */]: 0,
|
|
2250
|
-
["info" /* INFO */]: 1,
|
|
2251
|
-
["warn" /* WARN */]: 2,
|
|
2252
|
-
["error" /* ERROR */]: 3
|
|
2253
|
-
};
|
|
2254
|
-
var LoggerImpl = class _LoggerImpl {
|
|
2255
|
-
name;
|
|
2256
|
-
options;
|
|
2257
|
-
context;
|
|
2258
|
-
constructor(name, options = {}, context = {}) {
|
|
2259
|
-
this.name = name;
|
|
2260
|
-
this.context = context;
|
|
2261
|
-
this.options = {
|
|
2262
|
-
level: options.level ?? "info" /* INFO */,
|
|
2263
|
-
format: options.format ?? "pretty",
|
|
2264
|
-
destination: options.destination ?? process.stdout,
|
|
2265
|
-
includeTimestamp: options.includeTimestamp ?? true,
|
|
2266
|
-
includeContext: options.includeContext ?? true
|
|
2267
|
-
};
|
|
2268
|
-
}
|
|
2269
|
-
debug(message, data) {
|
|
2270
|
-
this.log("debug" /* DEBUG */, message, data);
|
|
2271
|
-
}
|
|
2272
|
-
info(message, data) {
|
|
2273
|
-
this.log("info" /* INFO */, message, data);
|
|
2274
|
-
}
|
|
2275
|
-
warn(message, data) {
|
|
2276
|
-
this.log("warn" /* WARN */, message, data);
|
|
2277
|
-
}
|
|
2278
|
-
error(message, data) {
|
|
2279
|
-
this.log("error" /* ERROR */, message, data);
|
|
2280
|
-
}
|
|
2281
|
-
withContext(context) {
|
|
2282
|
-
return new _LoggerImpl(this.name, this.options, { ...this.context, ...context });
|
|
2283
|
-
}
|
|
2284
|
-
log(level, message, data) {
|
|
2285
|
-
if (LOG_LEVEL_PRIORITY[level] < LOG_LEVEL_PRIORITY[this.options.level]) {
|
|
2286
|
-
return;
|
|
2287
|
-
}
|
|
2288
|
-
const entry = {
|
|
2289
|
-
level,
|
|
2290
|
-
name: this.name,
|
|
2291
|
-
message
|
|
2292
|
-
};
|
|
2293
|
-
if (this.options.includeTimestamp) {
|
|
2294
|
-
entry.timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
2295
|
-
}
|
|
2296
|
-
if (this.options.includeContext && Object.keys(this.context).length > 0) {
|
|
2297
|
-
entry.context = this.context;
|
|
2298
|
-
}
|
|
2299
|
-
if (data) {
|
|
2300
|
-
entry.data = data;
|
|
2301
|
-
}
|
|
2302
|
-
const output = this.format(entry);
|
|
2303
|
-
this.options.destination.write(output + "\n");
|
|
2304
|
-
}
|
|
2305
|
-
format(entry) {
|
|
2306
|
-
if (this.options.format === "json") {
|
|
2307
|
-
return JSON.stringify(entry);
|
|
2308
|
-
}
|
|
2309
|
-
const parts = [];
|
|
2310
|
-
if (entry.timestamp) {
|
|
2311
|
-
parts.push(`[${entry.timestamp}]`);
|
|
2312
|
-
}
|
|
2313
|
-
parts.push(`[${entry.level.toUpperCase()}]`);
|
|
2314
|
-
parts.push(`[${entry.name}]`);
|
|
2315
|
-
parts.push(entry.message);
|
|
2316
|
-
if (entry.context) {
|
|
2317
|
-
parts.push(`context=${JSON.stringify(entry.context)}`);
|
|
2318
|
-
}
|
|
2319
|
-
if (entry.data) {
|
|
2320
|
-
parts.push(`data=${JSON.stringify(entry.data)}`);
|
|
2321
|
-
}
|
|
2322
|
-
return parts.join(" ");
|
|
2323
|
-
}
|
|
2324
|
-
};
|
|
2325
|
-
function createLogger(name, options) {
|
|
2326
|
-
return new LoggerImpl(name, options);
|
|
2327
|
-
}
|
|
2328
|
-
|
|
2329
2347
|
// src/langgraph/observability/metrics.ts
|
|
2330
2348
|
var MetricType = /* @__PURE__ */ ((MetricType2) => {
|
|
2331
2349
|
MetricType2["COUNTER"] = "counter";
|
|
@@ -2635,14 +2653,14 @@ var withLogging = (options) => {
|
|
|
2635
2653
|
onComplete,
|
|
2636
2654
|
onError
|
|
2637
2655
|
} = options;
|
|
2638
|
-
const
|
|
2656
|
+
const logger3 = providedLogger || createLogger(name, { level });
|
|
2639
2657
|
return (node) => {
|
|
2640
2658
|
return async (state) => {
|
|
2641
2659
|
const startTime = Date.now();
|
|
2642
2660
|
try {
|
|
2643
2661
|
if (logInput) {
|
|
2644
2662
|
const data = extractData ? extractData(state) : { state };
|
|
2645
|
-
|
|
2663
|
+
logger3.info("Node execution started", data);
|
|
2646
2664
|
}
|
|
2647
2665
|
if (onStart) {
|
|
2648
2666
|
onStart(state);
|
|
@@ -2652,9 +2670,9 @@ var withLogging = (options) => {
|
|
|
2652
2670
|
if (logOutput) {
|
|
2653
2671
|
const data = extractData ? extractData(result) : { result };
|
|
2654
2672
|
if (logDuration) {
|
|
2655
|
-
|
|
2673
|
+
logger3.info(`Node execution completed (${duration}ms)`, data);
|
|
2656
2674
|
} else {
|
|
2657
|
-
|
|
2675
|
+
logger3.info("Node execution completed", data);
|
|
2658
2676
|
}
|
|
2659
2677
|
}
|
|
2660
2678
|
if (onComplete) {
|
|
@@ -2665,7 +2683,7 @@ var withLogging = (options) => {
|
|
|
2665
2683
|
const duration = Date.now() - startTime;
|
|
2666
2684
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
2667
2685
|
if (logErrors) {
|
|
2668
|
-
|
|
2686
|
+
logger3.error(`Node execution failed (${duration}ms)`, {
|
|
2669
2687
|
error: err.message,
|
|
2670
2688
|
stack: err.stack
|
|
2671
2689
|
});
|
|
@@ -2701,7 +2719,7 @@ function withLogging2(options) {
|
|
|
2701
2719
|
function production(node, options) {
|
|
2702
2720
|
const {
|
|
2703
2721
|
nodeName,
|
|
2704
|
-
logger,
|
|
2722
|
+
logger: logger3,
|
|
2705
2723
|
enableMetrics = true,
|
|
2706
2724
|
enableTracing = true,
|
|
2707
2725
|
enableRetry = true,
|
|
@@ -2709,7 +2727,7 @@ function production(node, options) {
|
|
|
2709
2727
|
retryOptions = {},
|
|
2710
2728
|
errorOptions = {}
|
|
2711
2729
|
} = options;
|
|
2712
|
-
const actualLogger =
|
|
2730
|
+
const actualLogger = logger3 || createLogger(nodeName, { level: "info" /* INFO */ });
|
|
2713
2731
|
const middleware = [];
|
|
2714
2732
|
middleware.push(
|
|
2715
2733
|
withLogging2({
|
|
@@ -2773,9 +2791,9 @@ function development(node, options) {
|
|
|
2773
2791
|
const {
|
|
2774
2792
|
nodeName,
|
|
2775
2793
|
verbose = true,
|
|
2776
|
-
logger
|
|
2794
|
+
logger: logger3
|
|
2777
2795
|
} = options;
|
|
2778
|
-
const actualLogger =
|
|
2796
|
+
const actualLogger = logger3 || createLogger(nodeName, { level: "debug" /* DEBUG */ });
|
|
2779
2797
|
return withLogging2({
|
|
2780
2798
|
logger: actualLogger,
|
|
2781
2799
|
name: nodeName,
|