@agentforge/core 0.16.86 → 0.16.87
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 +21 -81
- package/dist/index.d.cts +17 -102
- package/dist/index.d.ts +17 -102
- package/dist/index.js +21 -81
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -316,8 +316,6 @@ var MissingDescriptionError = class extends Error {
|
|
|
316
316
|
this.fieldType = fieldType;
|
|
317
317
|
this.name = "MissingDescriptionError";
|
|
318
318
|
}
|
|
319
|
-
fieldPath;
|
|
320
|
-
fieldType;
|
|
321
319
|
};
|
|
322
320
|
function validateSchemaDescriptions(schema, fieldPath = []) {
|
|
323
321
|
const def = schema._def;
|
|
@@ -608,9 +606,6 @@ var ToolBuilder = class _ToolBuilder {
|
|
|
608
606
|
this._schema = _schema;
|
|
609
607
|
this._invoke = _invoke;
|
|
610
608
|
}
|
|
611
|
-
metadata;
|
|
612
|
-
_schema;
|
|
613
|
-
_invoke;
|
|
614
609
|
name(name) {
|
|
615
610
|
this.metadata.name = name;
|
|
616
611
|
return this;
|
|
@@ -2462,52 +2457,35 @@ function createMiddlewareContext() {
|
|
|
2462
2457
|
};
|
|
2463
2458
|
}
|
|
2464
2459
|
|
|
2465
|
-
// src/langgraph/observability/metrics.ts
|
|
2460
|
+
// src/langgraph/observability/metrics/contracts.ts
|
|
2466
2461
|
var MetricType = /* @__PURE__ */ ((MetricType2) => {
|
|
2467
2462
|
MetricType2["COUNTER"] = "counter";
|
|
2468
2463
|
MetricType2["GAUGE"] = "gauge";
|
|
2469
2464
|
MetricType2["HISTOGRAM"] = "histogram";
|
|
2470
2465
|
return MetricType2;
|
|
2471
2466
|
})(MetricType || {});
|
|
2472
|
-
|
|
2473
|
-
|
|
2467
|
+
|
|
2468
|
+
// src/langgraph/observability/metrics/collector.ts
|
|
2469
|
+
var InMemoryMetrics = class {
|
|
2470
|
+
constructor(namespace) {
|
|
2471
|
+
this.namespace = namespace;
|
|
2472
|
+
}
|
|
2474
2473
|
metrics = [];
|
|
2475
2474
|
counters = /* @__PURE__ */ new Map();
|
|
2476
|
-
constructor(name) {
|
|
2477
|
-
this.name = name;
|
|
2478
|
-
}
|
|
2479
2475
|
increment(name, value = 1, labels) {
|
|
2480
2476
|
const key = this.getKey(name, labels);
|
|
2481
|
-
const
|
|
2482
|
-
this.counters.set(key,
|
|
2483
|
-
this.record(
|
|
2484
|
-
type: "counter" /* COUNTER */,
|
|
2485
|
-
name: this.prefixName(name),
|
|
2486
|
-
value: current + value,
|
|
2487
|
-
timestamp: Date.now(),
|
|
2488
|
-
labels
|
|
2489
|
-
});
|
|
2477
|
+
const nextValue = (this.counters.get(key) ?? 0) + value;
|
|
2478
|
+
this.counters.set(key, nextValue);
|
|
2479
|
+
this.record("counter" /* COUNTER */, name, nextValue, labels);
|
|
2490
2480
|
}
|
|
2491
2481
|
decrement(name, value = 1, labels) {
|
|
2492
2482
|
this.increment(name, -value, labels);
|
|
2493
2483
|
}
|
|
2494
2484
|
gauge(name, value, labels) {
|
|
2495
|
-
this.record(
|
|
2496
|
-
type: "gauge" /* GAUGE */,
|
|
2497
|
-
name: this.prefixName(name),
|
|
2498
|
-
value,
|
|
2499
|
-
timestamp: Date.now(),
|
|
2500
|
-
labels
|
|
2501
|
-
});
|
|
2485
|
+
this.record("gauge" /* GAUGE */, name, value, labels);
|
|
2502
2486
|
}
|
|
2503
2487
|
histogram(name, value, labels) {
|
|
2504
|
-
this.record(
|
|
2505
|
-
type: "histogram" /* HISTOGRAM */,
|
|
2506
|
-
name: this.prefixName(name),
|
|
2507
|
-
value,
|
|
2508
|
-
timestamp: Date.now(),
|
|
2509
|
-
labels
|
|
2510
|
-
});
|
|
2488
|
+
this.record("histogram" /* HISTOGRAM */, name, value, labels);
|
|
2511
2489
|
}
|
|
2512
2490
|
startTimer(name, labels) {
|
|
2513
2491
|
const startTime = Date.now();
|
|
@@ -2526,20 +2504,18 @@ var MetricsImpl = class {
|
|
|
2526
2504
|
this.metrics = [];
|
|
2527
2505
|
this.counters.clear();
|
|
2528
2506
|
}
|
|
2529
|
-
record(
|
|
2530
|
-
this.metrics.push(
|
|
2531
|
-
}
|
|
2532
|
-
prefixName(name) {
|
|
2533
|
-
return `${this.name}.${name}`;
|
|
2507
|
+
record(type, name, value, labels) {
|
|
2508
|
+
this.metrics.push({ type, name: `${this.namespace}.${name}`, value, timestamp: Date.now(), labels });
|
|
2534
2509
|
}
|
|
2535
2510
|
getKey(name, labels) {
|
|
2536
|
-
|
|
2537
|
-
return `${name}:${labelStr}`;
|
|
2511
|
+
return `${name}:${labels ? JSON.stringify(labels) : ""}`;
|
|
2538
2512
|
}
|
|
2539
2513
|
};
|
|
2540
2514
|
function createMetrics(name) {
|
|
2541
|
-
return new
|
|
2515
|
+
return new InMemoryMetrics(name);
|
|
2542
2516
|
}
|
|
2517
|
+
|
|
2518
|
+
// src/langgraph/observability/metrics/node-instrumentation.ts
|
|
2543
2519
|
function withMetrics(node, options) {
|
|
2544
2520
|
const {
|
|
2545
2521
|
name,
|
|
@@ -2549,23 +2525,17 @@ function withMetrics(node, options) {
|
|
|
2549
2525
|
metrics = createMetrics(name)
|
|
2550
2526
|
} = options;
|
|
2551
2527
|
return async (state) => {
|
|
2552
|
-
if (trackInvocations) {
|
|
2553
|
-
metrics.increment(`${name}.invocations`);
|
|
2554
|
-
}
|
|
2528
|
+
if (trackInvocations) metrics.increment(`${name}.invocations`);
|
|
2555
2529
|
const timer = trackDuration ? metrics.startTimer(`${name}.duration`) : null;
|
|
2556
2530
|
try {
|
|
2557
2531
|
const result = await Promise.resolve(node(state));
|
|
2558
2532
|
metrics.increment(`${name}.success`);
|
|
2559
2533
|
return result;
|
|
2560
2534
|
} catch (error) {
|
|
2561
|
-
if (trackErrors) {
|
|
2562
|
-
metrics.increment(`${name}.errors`);
|
|
2563
|
-
}
|
|
2535
|
+
if (trackErrors) metrics.increment(`${name}.errors`);
|
|
2564
2536
|
throw error;
|
|
2565
2537
|
} finally {
|
|
2566
|
-
|
|
2567
|
-
timer.end();
|
|
2568
|
-
}
|
|
2538
|
+
timer?.end();
|
|
2569
2539
|
}
|
|
2570
2540
|
};
|
|
2571
2541
|
}
|
|
@@ -2934,8 +2904,6 @@ var LRUCache = class {
|
|
|
2934
2904
|
this.maxSize = maxSize;
|
|
2935
2905
|
this.evictionStrategy = evictionStrategy;
|
|
2936
2906
|
}
|
|
2937
|
-
maxSize;
|
|
2938
|
-
evictionStrategy;
|
|
2939
2907
|
cache = /* @__PURE__ */ new Map();
|
|
2940
2908
|
get(key) {
|
|
2941
2909
|
const entry = this.cache.get(key);
|
|
@@ -3084,8 +3052,6 @@ var TokenBucket = class {
|
|
|
3084
3052
|
this.tokens = maxTokens;
|
|
3085
3053
|
this.lastRefill = Date.now();
|
|
3086
3054
|
}
|
|
3087
|
-
maxTokens;
|
|
3088
|
-
refillRate;
|
|
3089
3055
|
tokens;
|
|
3090
3056
|
lastRefill;
|
|
3091
3057
|
tryConsume() {
|
|
@@ -3113,8 +3079,6 @@ var SlidingWindow = class {
|
|
|
3113
3079
|
this.maxRequests = maxRequests;
|
|
3114
3080
|
this.windowMs = windowMs;
|
|
3115
3081
|
}
|
|
3116
|
-
maxRequests;
|
|
3117
|
-
windowMs;
|
|
3118
3082
|
requests = [];
|
|
3119
3083
|
tryConsume() {
|
|
3120
3084
|
const now = Date.now();
|
|
@@ -3135,8 +3099,6 @@ var FixedWindow = class {
|
|
|
3135
3099
|
this.windowMs = windowMs;
|
|
3136
3100
|
this.windowStart = Date.now();
|
|
3137
3101
|
}
|
|
3138
|
-
maxRequests;
|
|
3139
|
-
windowMs;
|
|
3140
3102
|
count = 0;
|
|
3141
3103
|
windowStart;
|
|
3142
3104
|
tryConsume() {
|
|
@@ -3176,11 +3138,6 @@ var RateLimiterRegistry = class {
|
|
|
3176
3138
|
this.onRateLimitExceeded = onRateLimitExceeded;
|
|
3177
3139
|
this.onRateLimitReset = onRateLimitReset;
|
|
3178
3140
|
}
|
|
3179
|
-
maxRequests;
|
|
3180
|
-
windowMs;
|
|
3181
|
-
strategy;
|
|
3182
|
-
onRateLimitExceeded;
|
|
3183
|
-
onRateLimitReset;
|
|
3184
3141
|
limiters = /* @__PURE__ */ new Map();
|
|
3185
3142
|
async execute(state, key, executor) {
|
|
3186
3143
|
const limiter = this.getOrCreate(key);
|
|
@@ -3349,13 +3306,6 @@ var ConcurrencyController = class {
|
|
|
3349
3306
|
this.onQueueFull = onQueueFull;
|
|
3350
3307
|
this.queueTimeout = queueTimeout;
|
|
3351
3308
|
}
|
|
3352
|
-
maxConcurrent;
|
|
3353
|
-
maxQueueSize;
|
|
3354
|
-
onQueued;
|
|
3355
|
-
onExecutionStart;
|
|
3356
|
-
onExecutionComplete;
|
|
3357
|
-
onQueueFull;
|
|
3358
|
-
queueTimeout;
|
|
3359
3309
|
activeCount = 0;
|
|
3360
3310
|
queue = [];
|
|
3361
3311
|
async execute(state, priority, executor) {
|
|
@@ -4643,7 +4593,6 @@ var MockDatabaseConnection = class {
|
|
|
4643
4593
|
constructor(config) {
|
|
4644
4594
|
this.config = config;
|
|
4645
4595
|
}
|
|
4646
|
-
config;
|
|
4647
4596
|
closed = false;
|
|
4648
4597
|
async query(_sql, _params) {
|
|
4649
4598
|
if (this.closed) {
|
|
@@ -4686,7 +4635,6 @@ var DatabasePool = class {
|
|
|
4686
4635
|
healthCheck: options.healthCheck
|
|
4687
4636
|
});
|
|
4688
4637
|
}
|
|
4689
|
-
options;
|
|
4690
4638
|
pool;
|
|
4691
4639
|
async acquire() {
|
|
4692
4640
|
return this.pool.acquire();
|
|
@@ -4729,7 +4677,6 @@ var MockHttpClient = class {
|
|
|
4729
4677
|
constructor(_config) {
|
|
4730
4678
|
this._config = _config;
|
|
4731
4679
|
}
|
|
4732
|
-
_config;
|
|
4733
4680
|
closed = false;
|
|
4734
4681
|
async get(url, config) {
|
|
4735
4682
|
return this.request({ ...config, url, method: "GET" });
|
|
@@ -4788,7 +4735,6 @@ var HttpPool = class {
|
|
|
4788
4735
|
healthCheck: options.healthCheck
|
|
4789
4736
|
});
|
|
4790
4737
|
}
|
|
4791
|
-
options;
|
|
4792
4738
|
pool;
|
|
4793
4739
|
async acquire() {
|
|
4794
4740
|
return this.pool.acquire();
|
|
@@ -4823,7 +4769,6 @@ var MemoryManager = class {
|
|
|
4823
4769
|
constructor(options) {
|
|
4824
4770
|
this.options = options;
|
|
4825
4771
|
}
|
|
4826
|
-
options;
|
|
4827
4772
|
cleanupHandlers = /* @__PURE__ */ new Map();
|
|
4828
4773
|
checkTimer;
|
|
4829
4774
|
leakDetectionTimer;
|
|
@@ -4933,7 +4878,6 @@ var BatchProcessor = class {
|
|
|
4933
4878
|
constructor(options) {
|
|
4934
4879
|
this.options = options;
|
|
4935
4880
|
}
|
|
4936
|
-
options;
|
|
4937
4881
|
pending = [];
|
|
4938
4882
|
timer;
|
|
4939
4883
|
processing = false;
|
|
@@ -5040,7 +4984,6 @@ var CircuitBreaker = class {
|
|
|
5040
4984
|
constructor(options) {
|
|
5041
4985
|
this.options = options;
|
|
5042
4986
|
}
|
|
5043
|
-
options;
|
|
5044
4987
|
state = "closed";
|
|
5045
4988
|
failures = 0;
|
|
5046
4989
|
successes = 0;
|
|
@@ -5176,7 +5119,6 @@ var HealthChecker = class {
|
|
|
5176
5119
|
constructor(options) {
|
|
5177
5120
|
this.options = options;
|
|
5178
5121
|
}
|
|
5179
|
-
options;
|
|
5180
5122
|
checkTimer;
|
|
5181
5123
|
lastReport;
|
|
5182
5124
|
startTime = Date.now();
|
|
@@ -5523,7 +5465,6 @@ var AlertManager = class {
|
|
|
5523
5465
|
constructor(options) {
|
|
5524
5466
|
this.options = options;
|
|
5525
5467
|
}
|
|
5526
|
-
options;
|
|
5527
5468
|
lastAlertTime = /* @__PURE__ */ new Map();
|
|
5528
5469
|
monitorTimer;
|
|
5529
5470
|
running = false;
|
|
@@ -5598,7 +5539,6 @@ var AuditLogger = class {
|
|
|
5598
5539
|
this.startCleanup();
|
|
5599
5540
|
}
|
|
5600
5541
|
}
|
|
5601
|
-
options;
|
|
5602
5542
|
logs = [];
|
|
5603
5543
|
cleanupTimer;
|
|
5604
5544
|
async log(entry) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z,
|
|
1
|
+
import { z, ZodTypeAny, output, ZodType, ZodTypeDef } from 'zod';
|
|
2
2
|
import * as _langchain_core_tools from '@langchain/core/tools';
|
|
3
3
|
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
4
4
|
import * as _langchain_langgraph from '@langchain/langgraph';
|
|
@@ -724,7 +724,7 @@ declare class ToolRegistry {
|
|
|
724
724
|
on(event: RegistryEvent, handler: EventHandler): void;
|
|
725
725
|
off(event: RegistryEvent, handler: EventHandler): void;
|
|
726
726
|
private emit;
|
|
727
|
-
toLangChainTools(): _langchain_core_tools.DynamicStructuredTool<_langchain_core_tools.ToolSchemaBase, any, any, any,
|
|
727
|
+
toLangChainTools(): _langchain_core_tools.DynamicStructuredTool<_langchain_core_tools.ToolSchemaBase, any, any, any, string>[];
|
|
728
728
|
generatePrompt(options?: PromptOptions): string;
|
|
729
729
|
}
|
|
730
730
|
|
|
@@ -2202,22 +2202,13 @@ declare class TimeoutError extends Error {
|
|
|
2202
2202
|
*/
|
|
2203
2203
|
declare function withTimeout<State>(node: (state: State) => State | Promise<State> | Partial<State> | Promise<Partial<State>>, options: TimeoutOptions<State>): (state: State) => Promise<State | Partial<State>>;
|
|
2204
2204
|
|
|
2205
|
-
/**
|
|
2206
|
-
* Metrics Collection Utilities
|
|
2207
|
-
*
|
|
2208
|
-
* Provides utilities for collecting performance and usage metrics.
|
|
2209
|
-
*/
|
|
2210
|
-
/**
|
|
2211
|
-
* Metric types
|
|
2212
|
-
*/
|
|
2205
|
+
/** Metric types supported by the in-memory collector. */
|
|
2213
2206
|
declare enum MetricType {
|
|
2214
2207
|
COUNTER = "counter",
|
|
2215
2208
|
GAUGE = "gauge",
|
|
2216
2209
|
HISTOGRAM = "histogram"
|
|
2217
2210
|
}
|
|
2218
|
-
/**
|
|
2219
|
-
* Metric entry
|
|
2220
|
-
*/
|
|
2211
|
+
/** A recorded metric sample. */
|
|
2221
2212
|
interface MetricEntry {
|
|
2222
2213
|
type: MetricType;
|
|
2223
2214
|
name: string;
|
|
@@ -2225,125 +2216,49 @@ interface MetricEntry {
|
|
|
2225
2216
|
timestamp: number;
|
|
2226
2217
|
labels?: Record<string, string>;
|
|
2227
2218
|
}
|
|
2228
|
-
/**
|
|
2229
|
-
* Timer interface for measuring durations
|
|
2230
|
-
*/
|
|
2219
|
+
/** A running duration measurement. */
|
|
2231
2220
|
interface Timer {
|
|
2232
|
-
/**
|
|
2233
|
-
* End the timer and record the duration
|
|
2234
|
-
*/
|
|
2235
2221
|
end(): number;
|
|
2236
2222
|
}
|
|
2237
|
-
/**
|
|
2238
|
-
* Metrics collector interface
|
|
2239
|
-
*/
|
|
2223
|
+
/** Public metrics collector contract. */
|
|
2240
2224
|
interface Metrics {
|
|
2241
|
-
/**
|
|
2242
|
-
* Increment a counter metric
|
|
2243
|
-
*/
|
|
2244
2225
|
increment(name: string, value?: number, labels?: Record<string, string>): void;
|
|
2245
|
-
/**
|
|
2246
|
-
* Decrement a counter metric
|
|
2247
|
-
*/
|
|
2248
2226
|
decrement(name: string, value?: number, labels?: Record<string, string>): void;
|
|
2249
|
-
/**
|
|
2250
|
-
* Set a gauge metric
|
|
2251
|
-
*/
|
|
2252
2227
|
gauge(name: string, value: number, labels?: Record<string, string>): void;
|
|
2253
|
-
/**
|
|
2254
|
-
* Record a histogram value
|
|
2255
|
-
*/
|
|
2256
2228
|
histogram(name: string, value: number, labels?: Record<string, string>): void;
|
|
2257
|
-
/**
|
|
2258
|
-
* Start a timer for measuring duration
|
|
2259
|
-
*/
|
|
2260
2229
|
startTimer(name: string, labels?: Record<string, string>): Timer;
|
|
2261
|
-
/**
|
|
2262
|
-
* Get all recorded metrics
|
|
2263
|
-
*/
|
|
2264
2230
|
getMetrics(): MetricEntry[];
|
|
2265
|
-
/**
|
|
2266
|
-
* Clear all metrics
|
|
2267
|
-
*/
|
|
2268
2231
|
clear(): void;
|
|
2269
2232
|
}
|
|
2270
|
-
/**
|
|
2271
|
-
* Create a metrics collector.
|
|
2272
|
-
*
|
|
2273
|
-
* @example
|
|
2274
|
-
* ```typescript
|
|
2275
|
-
* import { createMetrics } from '@agentforge/core';
|
|
2276
|
-
*
|
|
2277
|
-
* const metrics = createMetrics('my-agent');
|
|
2278
|
-
*
|
|
2279
|
-
* // Track counters
|
|
2280
|
-
* metrics.increment('requests.total');
|
|
2281
|
-
* metrics.increment('requests.success');
|
|
2282
|
-
*
|
|
2283
|
-
* // Track gauges
|
|
2284
|
-
* metrics.gauge('active.connections', 5);
|
|
2285
|
-
*
|
|
2286
|
-
* // Track histograms
|
|
2287
|
-
* metrics.histogram('request.duration', 150);
|
|
2288
|
-
*
|
|
2289
|
-
* // Track timers
|
|
2290
|
-
* const timer = metrics.startTimer('operation.duration');
|
|
2291
|
-
* // ... do work ...
|
|
2292
|
-
* timer.end();
|
|
2293
|
-
* ```
|
|
2294
|
-
*
|
|
2295
|
-
* @param name - Metrics namespace (typically the agent or component name)
|
|
2296
|
-
* @returns A metrics collector instance
|
|
2297
|
-
*/
|
|
2298
|
-
declare function createMetrics(name: string): Metrics;
|
|
2299
|
-
/**
|
|
2300
|
-
* Options for metrics tracking on nodes
|
|
2301
|
-
*/
|
|
2233
|
+
/** Options controlling automatic node instrumentation. */
|
|
2302
2234
|
interface MetricsNodeOptions {
|
|
2303
|
-
/**
|
|
2304
|
-
* Name for the metrics
|
|
2305
|
-
*/
|
|
2235
|
+
/** Name used to identify the instrumented node. */
|
|
2306
2236
|
name: string;
|
|
2307
2237
|
/**
|
|
2308
|
-
* Whether to track execution duration
|
|
2238
|
+
* Whether to track execution duration.
|
|
2309
2239
|
* @default true
|
|
2310
2240
|
*/
|
|
2311
2241
|
trackDuration?: boolean;
|
|
2312
2242
|
/**
|
|
2313
|
-
* Whether to track errors
|
|
2243
|
+
* Whether to track errors.
|
|
2314
2244
|
* @default true
|
|
2315
2245
|
*/
|
|
2316
2246
|
trackErrors?: boolean;
|
|
2317
2247
|
/**
|
|
2318
|
-
* Whether to track invocation count
|
|
2248
|
+
* Whether to track invocation count.
|
|
2319
2249
|
* @default true
|
|
2320
2250
|
*/
|
|
2321
2251
|
trackInvocations?: boolean;
|
|
2322
2252
|
/**
|
|
2323
|
-
* Metrics collector to use
|
|
2324
|
-
* If not provided, a new one will be created
|
|
2253
|
+
* Metrics collector to use. A new collector is created when omitted.
|
|
2325
2254
|
*/
|
|
2326
2255
|
metrics?: Metrics;
|
|
2327
2256
|
}
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
* import { withMetrics, createMetrics } from '@agentforge/core';
|
|
2334
|
-
*
|
|
2335
|
-
* const metrics = createMetrics('my-agent');
|
|
2336
|
-
*
|
|
2337
|
-
* const metricNode = withMetrics(myNode, {
|
|
2338
|
-
* name: 'research-node',
|
|
2339
|
-
* metrics,
|
|
2340
|
-
* });
|
|
2341
|
-
* ```
|
|
2342
|
-
*
|
|
2343
|
-
* @param node - The node function to wrap
|
|
2344
|
-
* @param options - Metrics tracking options
|
|
2345
|
-
* @returns A wrapped node function with metrics tracking
|
|
2346
|
-
*/
|
|
2257
|
+
|
|
2258
|
+
/** Create an in-memory metrics collector for a namespace. */
|
|
2259
|
+
declare function createMetrics(name: string): Metrics;
|
|
2260
|
+
|
|
2261
|
+
/** Wrap a node function with automatic metrics tracking. */
|
|
2347
2262
|
declare function withMetrics<State>(node: (state: State) => State | Promise<State> | Partial<State> | Promise<Partial<State>>, options: MetricsNodeOptions): (state: State) => Promise<State | Partial<State>>;
|
|
2348
2263
|
|
|
2349
2264
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { z,
|
|
1
|
+
import { z, ZodTypeAny, output, ZodType, ZodTypeDef } from 'zod';
|
|
2
2
|
import * as _langchain_core_tools from '@langchain/core/tools';
|
|
3
3
|
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
4
4
|
import * as _langchain_langgraph from '@langchain/langgraph';
|
|
@@ -724,7 +724,7 @@ declare class ToolRegistry {
|
|
|
724
724
|
on(event: RegistryEvent, handler: EventHandler): void;
|
|
725
725
|
off(event: RegistryEvent, handler: EventHandler): void;
|
|
726
726
|
private emit;
|
|
727
|
-
toLangChainTools(): _langchain_core_tools.DynamicStructuredTool<_langchain_core_tools.ToolSchemaBase, any, any, any,
|
|
727
|
+
toLangChainTools(): _langchain_core_tools.DynamicStructuredTool<_langchain_core_tools.ToolSchemaBase, any, any, any, string>[];
|
|
728
728
|
generatePrompt(options?: PromptOptions): string;
|
|
729
729
|
}
|
|
730
730
|
|
|
@@ -2202,22 +2202,13 @@ declare class TimeoutError extends Error {
|
|
|
2202
2202
|
*/
|
|
2203
2203
|
declare function withTimeout<State>(node: (state: State) => State | Promise<State> | Partial<State> | Promise<Partial<State>>, options: TimeoutOptions<State>): (state: State) => Promise<State | Partial<State>>;
|
|
2204
2204
|
|
|
2205
|
-
/**
|
|
2206
|
-
* Metrics Collection Utilities
|
|
2207
|
-
*
|
|
2208
|
-
* Provides utilities for collecting performance and usage metrics.
|
|
2209
|
-
*/
|
|
2210
|
-
/**
|
|
2211
|
-
* Metric types
|
|
2212
|
-
*/
|
|
2205
|
+
/** Metric types supported by the in-memory collector. */
|
|
2213
2206
|
declare enum MetricType {
|
|
2214
2207
|
COUNTER = "counter",
|
|
2215
2208
|
GAUGE = "gauge",
|
|
2216
2209
|
HISTOGRAM = "histogram"
|
|
2217
2210
|
}
|
|
2218
|
-
/**
|
|
2219
|
-
* Metric entry
|
|
2220
|
-
*/
|
|
2211
|
+
/** A recorded metric sample. */
|
|
2221
2212
|
interface MetricEntry {
|
|
2222
2213
|
type: MetricType;
|
|
2223
2214
|
name: string;
|
|
@@ -2225,125 +2216,49 @@ interface MetricEntry {
|
|
|
2225
2216
|
timestamp: number;
|
|
2226
2217
|
labels?: Record<string, string>;
|
|
2227
2218
|
}
|
|
2228
|
-
/**
|
|
2229
|
-
* Timer interface for measuring durations
|
|
2230
|
-
*/
|
|
2219
|
+
/** A running duration measurement. */
|
|
2231
2220
|
interface Timer {
|
|
2232
|
-
/**
|
|
2233
|
-
* End the timer and record the duration
|
|
2234
|
-
*/
|
|
2235
2221
|
end(): number;
|
|
2236
2222
|
}
|
|
2237
|
-
/**
|
|
2238
|
-
* Metrics collector interface
|
|
2239
|
-
*/
|
|
2223
|
+
/** Public metrics collector contract. */
|
|
2240
2224
|
interface Metrics {
|
|
2241
|
-
/**
|
|
2242
|
-
* Increment a counter metric
|
|
2243
|
-
*/
|
|
2244
2225
|
increment(name: string, value?: number, labels?: Record<string, string>): void;
|
|
2245
|
-
/**
|
|
2246
|
-
* Decrement a counter metric
|
|
2247
|
-
*/
|
|
2248
2226
|
decrement(name: string, value?: number, labels?: Record<string, string>): void;
|
|
2249
|
-
/**
|
|
2250
|
-
* Set a gauge metric
|
|
2251
|
-
*/
|
|
2252
2227
|
gauge(name: string, value: number, labels?: Record<string, string>): void;
|
|
2253
|
-
/**
|
|
2254
|
-
* Record a histogram value
|
|
2255
|
-
*/
|
|
2256
2228
|
histogram(name: string, value: number, labels?: Record<string, string>): void;
|
|
2257
|
-
/**
|
|
2258
|
-
* Start a timer for measuring duration
|
|
2259
|
-
*/
|
|
2260
2229
|
startTimer(name: string, labels?: Record<string, string>): Timer;
|
|
2261
|
-
/**
|
|
2262
|
-
* Get all recorded metrics
|
|
2263
|
-
*/
|
|
2264
2230
|
getMetrics(): MetricEntry[];
|
|
2265
|
-
/**
|
|
2266
|
-
* Clear all metrics
|
|
2267
|
-
*/
|
|
2268
2231
|
clear(): void;
|
|
2269
2232
|
}
|
|
2270
|
-
/**
|
|
2271
|
-
* Create a metrics collector.
|
|
2272
|
-
*
|
|
2273
|
-
* @example
|
|
2274
|
-
* ```typescript
|
|
2275
|
-
* import { createMetrics } from '@agentforge/core';
|
|
2276
|
-
*
|
|
2277
|
-
* const metrics = createMetrics('my-agent');
|
|
2278
|
-
*
|
|
2279
|
-
* // Track counters
|
|
2280
|
-
* metrics.increment('requests.total');
|
|
2281
|
-
* metrics.increment('requests.success');
|
|
2282
|
-
*
|
|
2283
|
-
* // Track gauges
|
|
2284
|
-
* metrics.gauge('active.connections', 5);
|
|
2285
|
-
*
|
|
2286
|
-
* // Track histograms
|
|
2287
|
-
* metrics.histogram('request.duration', 150);
|
|
2288
|
-
*
|
|
2289
|
-
* // Track timers
|
|
2290
|
-
* const timer = metrics.startTimer('operation.duration');
|
|
2291
|
-
* // ... do work ...
|
|
2292
|
-
* timer.end();
|
|
2293
|
-
* ```
|
|
2294
|
-
*
|
|
2295
|
-
* @param name - Metrics namespace (typically the agent or component name)
|
|
2296
|
-
* @returns A metrics collector instance
|
|
2297
|
-
*/
|
|
2298
|
-
declare function createMetrics(name: string): Metrics;
|
|
2299
|
-
/**
|
|
2300
|
-
* Options for metrics tracking on nodes
|
|
2301
|
-
*/
|
|
2233
|
+
/** Options controlling automatic node instrumentation. */
|
|
2302
2234
|
interface MetricsNodeOptions {
|
|
2303
|
-
/**
|
|
2304
|
-
* Name for the metrics
|
|
2305
|
-
*/
|
|
2235
|
+
/** Name used to identify the instrumented node. */
|
|
2306
2236
|
name: string;
|
|
2307
2237
|
/**
|
|
2308
|
-
* Whether to track execution duration
|
|
2238
|
+
* Whether to track execution duration.
|
|
2309
2239
|
* @default true
|
|
2310
2240
|
*/
|
|
2311
2241
|
trackDuration?: boolean;
|
|
2312
2242
|
/**
|
|
2313
|
-
* Whether to track errors
|
|
2243
|
+
* Whether to track errors.
|
|
2314
2244
|
* @default true
|
|
2315
2245
|
*/
|
|
2316
2246
|
trackErrors?: boolean;
|
|
2317
2247
|
/**
|
|
2318
|
-
* Whether to track invocation count
|
|
2248
|
+
* Whether to track invocation count.
|
|
2319
2249
|
* @default true
|
|
2320
2250
|
*/
|
|
2321
2251
|
trackInvocations?: boolean;
|
|
2322
2252
|
/**
|
|
2323
|
-
* Metrics collector to use
|
|
2324
|
-
* If not provided, a new one will be created
|
|
2253
|
+
* Metrics collector to use. A new collector is created when omitted.
|
|
2325
2254
|
*/
|
|
2326
2255
|
metrics?: Metrics;
|
|
2327
2256
|
}
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
* import { withMetrics, createMetrics } from '@agentforge/core';
|
|
2334
|
-
*
|
|
2335
|
-
* const metrics = createMetrics('my-agent');
|
|
2336
|
-
*
|
|
2337
|
-
* const metricNode = withMetrics(myNode, {
|
|
2338
|
-
* name: 'research-node',
|
|
2339
|
-
* metrics,
|
|
2340
|
-
* });
|
|
2341
|
-
* ```
|
|
2342
|
-
*
|
|
2343
|
-
* @param node - The node function to wrap
|
|
2344
|
-
* @param options - Metrics tracking options
|
|
2345
|
-
* @returns A wrapped node function with metrics tracking
|
|
2346
|
-
*/
|
|
2257
|
+
|
|
2258
|
+
/** Create an in-memory metrics collector for a namespace. */
|
|
2259
|
+
declare function createMetrics(name: string): Metrics;
|
|
2260
|
+
|
|
2261
|
+
/** Wrap a node function with automatic metrics tracking. */
|
|
2347
2262
|
declare function withMetrics<State>(node: (state: State) => State | Promise<State> | Partial<State> | Promise<Partial<State>>, options: MetricsNodeOptions): (state: State) => Promise<State | Partial<State>>;
|
|
2348
2263
|
|
|
2349
2264
|
/**
|
package/dist/index.js
CHANGED
|
@@ -140,8 +140,6 @@ var MissingDescriptionError = class extends Error {
|
|
|
140
140
|
this.fieldType = fieldType;
|
|
141
141
|
this.name = "MissingDescriptionError";
|
|
142
142
|
}
|
|
143
|
-
fieldPath;
|
|
144
|
-
fieldType;
|
|
145
143
|
};
|
|
146
144
|
function validateSchemaDescriptions(schema, fieldPath = []) {
|
|
147
145
|
const def = schema._def;
|
|
@@ -432,9 +430,6 @@ var ToolBuilder = class _ToolBuilder {
|
|
|
432
430
|
this._schema = _schema;
|
|
433
431
|
this._invoke = _invoke;
|
|
434
432
|
}
|
|
435
|
-
metadata;
|
|
436
|
-
_schema;
|
|
437
|
-
_invoke;
|
|
438
433
|
name(name) {
|
|
439
434
|
this.metadata.name = name;
|
|
440
435
|
return this;
|
|
@@ -2286,52 +2281,35 @@ function createMiddlewareContext() {
|
|
|
2286
2281
|
};
|
|
2287
2282
|
}
|
|
2288
2283
|
|
|
2289
|
-
// src/langgraph/observability/metrics.ts
|
|
2284
|
+
// src/langgraph/observability/metrics/contracts.ts
|
|
2290
2285
|
var MetricType = /* @__PURE__ */ ((MetricType2) => {
|
|
2291
2286
|
MetricType2["COUNTER"] = "counter";
|
|
2292
2287
|
MetricType2["GAUGE"] = "gauge";
|
|
2293
2288
|
MetricType2["HISTOGRAM"] = "histogram";
|
|
2294
2289
|
return MetricType2;
|
|
2295
2290
|
})(MetricType || {});
|
|
2296
|
-
|
|
2297
|
-
|
|
2291
|
+
|
|
2292
|
+
// src/langgraph/observability/metrics/collector.ts
|
|
2293
|
+
var InMemoryMetrics = class {
|
|
2294
|
+
constructor(namespace) {
|
|
2295
|
+
this.namespace = namespace;
|
|
2296
|
+
}
|
|
2298
2297
|
metrics = [];
|
|
2299
2298
|
counters = /* @__PURE__ */ new Map();
|
|
2300
|
-
constructor(name) {
|
|
2301
|
-
this.name = name;
|
|
2302
|
-
}
|
|
2303
2299
|
increment(name, value = 1, labels) {
|
|
2304
2300
|
const key = this.getKey(name, labels);
|
|
2305
|
-
const
|
|
2306
|
-
this.counters.set(key,
|
|
2307
|
-
this.record(
|
|
2308
|
-
type: "counter" /* COUNTER */,
|
|
2309
|
-
name: this.prefixName(name),
|
|
2310
|
-
value: current + value,
|
|
2311
|
-
timestamp: Date.now(),
|
|
2312
|
-
labels
|
|
2313
|
-
});
|
|
2301
|
+
const nextValue = (this.counters.get(key) ?? 0) + value;
|
|
2302
|
+
this.counters.set(key, nextValue);
|
|
2303
|
+
this.record("counter" /* COUNTER */, name, nextValue, labels);
|
|
2314
2304
|
}
|
|
2315
2305
|
decrement(name, value = 1, labels) {
|
|
2316
2306
|
this.increment(name, -value, labels);
|
|
2317
2307
|
}
|
|
2318
2308
|
gauge(name, value, labels) {
|
|
2319
|
-
this.record(
|
|
2320
|
-
type: "gauge" /* GAUGE */,
|
|
2321
|
-
name: this.prefixName(name),
|
|
2322
|
-
value,
|
|
2323
|
-
timestamp: Date.now(),
|
|
2324
|
-
labels
|
|
2325
|
-
});
|
|
2309
|
+
this.record("gauge" /* GAUGE */, name, value, labels);
|
|
2326
2310
|
}
|
|
2327
2311
|
histogram(name, value, labels) {
|
|
2328
|
-
this.record(
|
|
2329
|
-
type: "histogram" /* HISTOGRAM */,
|
|
2330
|
-
name: this.prefixName(name),
|
|
2331
|
-
value,
|
|
2332
|
-
timestamp: Date.now(),
|
|
2333
|
-
labels
|
|
2334
|
-
});
|
|
2312
|
+
this.record("histogram" /* HISTOGRAM */, name, value, labels);
|
|
2335
2313
|
}
|
|
2336
2314
|
startTimer(name, labels) {
|
|
2337
2315
|
const startTime = Date.now();
|
|
@@ -2350,20 +2328,18 @@ var MetricsImpl = class {
|
|
|
2350
2328
|
this.metrics = [];
|
|
2351
2329
|
this.counters.clear();
|
|
2352
2330
|
}
|
|
2353
|
-
record(
|
|
2354
|
-
this.metrics.push(
|
|
2355
|
-
}
|
|
2356
|
-
prefixName(name) {
|
|
2357
|
-
return `${this.name}.${name}`;
|
|
2331
|
+
record(type, name, value, labels) {
|
|
2332
|
+
this.metrics.push({ type, name: `${this.namespace}.${name}`, value, timestamp: Date.now(), labels });
|
|
2358
2333
|
}
|
|
2359
2334
|
getKey(name, labels) {
|
|
2360
|
-
|
|
2361
|
-
return `${name}:${labelStr}`;
|
|
2335
|
+
return `${name}:${labels ? JSON.stringify(labels) : ""}`;
|
|
2362
2336
|
}
|
|
2363
2337
|
};
|
|
2364
2338
|
function createMetrics(name) {
|
|
2365
|
-
return new
|
|
2339
|
+
return new InMemoryMetrics(name);
|
|
2366
2340
|
}
|
|
2341
|
+
|
|
2342
|
+
// src/langgraph/observability/metrics/node-instrumentation.ts
|
|
2367
2343
|
function withMetrics(node, options) {
|
|
2368
2344
|
const {
|
|
2369
2345
|
name,
|
|
@@ -2373,23 +2349,17 @@ function withMetrics(node, options) {
|
|
|
2373
2349
|
metrics = createMetrics(name)
|
|
2374
2350
|
} = options;
|
|
2375
2351
|
return async (state) => {
|
|
2376
|
-
if (trackInvocations) {
|
|
2377
|
-
metrics.increment(`${name}.invocations`);
|
|
2378
|
-
}
|
|
2352
|
+
if (trackInvocations) metrics.increment(`${name}.invocations`);
|
|
2379
2353
|
const timer = trackDuration ? metrics.startTimer(`${name}.duration`) : null;
|
|
2380
2354
|
try {
|
|
2381
2355
|
const result = await Promise.resolve(node(state));
|
|
2382
2356
|
metrics.increment(`${name}.success`);
|
|
2383
2357
|
return result;
|
|
2384
2358
|
} catch (error) {
|
|
2385
|
-
if (trackErrors) {
|
|
2386
|
-
metrics.increment(`${name}.errors`);
|
|
2387
|
-
}
|
|
2359
|
+
if (trackErrors) metrics.increment(`${name}.errors`);
|
|
2388
2360
|
throw error;
|
|
2389
2361
|
} finally {
|
|
2390
|
-
|
|
2391
|
-
timer.end();
|
|
2392
|
-
}
|
|
2362
|
+
timer?.end();
|
|
2393
2363
|
}
|
|
2394
2364
|
};
|
|
2395
2365
|
}
|
|
@@ -2758,8 +2728,6 @@ var LRUCache = class {
|
|
|
2758
2728
|
this.maxSize = maxSize;
|
|
2759
2729
|
this.evictionStrategy = evictionStrategy;
|
|
2760
2730
|
}
|
|
2761
|
-
maxSize;
|
|
2762
|
-
evictionStrategy;
|
|
2763
2731
|
cache = /* @__PURE__ */ new Map();
|
|
2764
2732
|
get(key) {
|
|
2765
2733
|
const entry = this.cache.get(key);
|
|
@@ -2908,8 +2876,6 @@ var TokenBucket = class {
|
|
|
2908
2876
|
this.tokens = maxTokens;
|
|
2909
2877
|
this.lastRefill = Date.now();
|
|
2910
2878
|
}
|
|
2911
|
-
maxTokens;
|
|
2912
|
-
refillRate;
|
|
2913
2879
|
tokens;
|
|
2914
2880
|
lastRefill;
|
|
2915
2881
|
tryConsume() {
|
|
@@ -2937,8 +2903,6 @@ var SlidingWindow = class {
|
|
|
2937
2903
|
this.maxRequests = maxRequests;
|
|
2938
2904
|
this.windowMs = windowMs;
|
|
2939
2905
|
}
|
|
2940
|
-
maxRequests;
|
|
2941
|
-
windowMs;
|
|
2942
2906
|
requests = [];
|
|
2943
2907
|
tryConsume() {
|
|
2944
2908
|
const now = Date.now();
|
|
@@ -2959,8 +2923,6 @@ var FixedWindow = class {
|
|
|
2959
2923
|
this.windowMs = windowMs;
|
|
2960
2924
|
this.windowStart = Date.now();
|
|
2961
2925
|
}
|
|
2962
|
-
maxRequests;
|
|
2963
|
-
windowMs;
|
|
2964
2926
|
count = 0;
|
|
2965
2927
|
windowStart;
|
|
2966
2928
|
tryConsume() {
|
|
@@ -3000,11 +2962,6 @@ var RateLimiterRegistry = class {
|
|
|
3000
2962
|
this.onRateLimitExceeded = onRateLimitExceeded;
|
|
3001
2963
|
this.onRateLimitReset = onRateLimitReset;
|
|
3002
2964
|
}
|
|
3003
|
-
maxRequests;
|
|
3004
|
-
windowMs;
|
|
3005
|
-
strategy;
|
|
3006
|
-
onRateLimitExceeded;
|
|
3007
|
-
onRateLimitReset;
|
|
3008
2965
|
limiters = /* @__PURE__ */ new Map();
|
|
3009
2966
|
async execute(state, key, executor) {
|
|
3010
2967
|
const limiter = this.getOrCreate(key);
|
|
@@ -3173,13 +3130,6 @@ var ConcurrencyController = class {
|
|
|
3173
3130
|
this.onQueueFull = onQueueFull;
|
|
3174
3131
|
this.queueTimeout = queueTimeout;
|
|
3175
3132
|
}
|
|
3176
|
-
maxConcurrent;
|
|
3177
|
-
maxQueueSize;
|
|
3178
|
-
onQueued;
|
|
3179
|
-
onExecutionStart;
|
|
3180
|
-
onExecutionComplete;
|
|
3181
|
-
onQueueFull;
|
|
3182
|
-
queueTimeout;
|
|
3183
3133
|
activeCount = 0;
|
|
3184
3134
|
queue = [];
|
|
3185
3135
|
async execute(state, priority, executor) {
|
|
@@ -4467,7 +4417,6 @@ var MockDatabaseConnection = class {
|
|
|
4467
4417
|
constructor(config) {
|
|
4468
4418
|
this.config = config;
|
|
4469
4419
|
}
|
|
4470
|
-
config;
|
|
4471
4420
|
closed = false;
|
|
4472
4421
|
async query(_sql, _params) {
|
|
4473
4422
|
if (this.closed) {
|
|
@@ -4510,7 +4459,6 @@ var DatabasePool = class {
|
|
|
4510
4459
|
healthCheck: options.healthCheck
|
|
4511
4460
|
});
|
|
4512
4461
|
}
|
|
4513
|
-
options;
|
|
4514
4462
|
pool;
|
|
4515
4463
|
async acquire() {
|
|
4516
4464
|
return this.pool.acquire();
|
|
@@ -4553,7 +4501,6 @@ var MockHttpClient = class {
|
|
|
4553
4501
|
constructor(_config) {
|
|
4554
4502
|
this._config = _config;
|
|
4555
4503
|
}
|
|
4556
|
-
_config;
|
|
4557
4504
|
closed = false;
|
|
4558
4505
|
async get(url, config) {
|
|
4559
4506
|
return this.request({ ...config, url, method: "GET" });
|
|
@@ -4612,7 +4559,6 @@ var HttpPool = class {
|
|
|
4612
4559
|
healthCheck: options.healthCheck
|
|
4613
4560
|
});
|
|
4614
4561
|
}
|
|
4615
|
-
options;
|
|
4616
4562
|
pool;
|
|
4617
4563
|
async acquire() {
|
|
4618
4564
|
return this.pool.acquire();
|
|
@@ -4647,7 +4593,6 @@ var MemoryManager = class {
|
|
|
4647
4593
|
constructor(options) {
|
|
4648
4594
|
this.options = options;
|
|
4649
4595
|
}
|
|
4650
|
-
options;
|
|
4651
4596
|
cleanupHandlers = /* @__PURE__ */ new Map();
|
|
4652
4597
|
checkTimer;
|
|
4653
4598
|
leakDetectionTimer;
|
|
@@ -4757,7 +4702,6 @@ var BatchProcessor = class {
|
|
|
4757
4702
|
constructor(options) {
|
|
4758
4703
|
this.options = options;
|
|
4759
4704
|
}
|
|
4760
|
-
options;
|
|
4761
4705
|
pending = [];
|
|
4762
4706
|
timer;
|
|
4763
4707
|
processing = false;
|
|
@@ -4864,7 +4808,6 @@ var CircuitBreaker = class {
|
|
|
4864
4808
|
constructor(options) {
|
|
4865
4809
|
this.options = options;
|
|
4866
4810
|
}
|
|
4867
|
-
options;
|
|
4868
4811
|
state = "closed";
|
|
4869
4812
|
failures = 0;
|
|
4870
4813
|
successes = 0;
|
|
@@ -5000,7 +4943,6 @@ var HealthChecker = class {
|
|
|
5000
4943
|
constructor(options) {
|
|
5001
4944
|
this.options = options;
|
|
5002
4945
|
}
|
|
5003
|
-
options;
|
|
5004
4946
|
checkTimer;
|
|
5005
4947
|
lastReport;
|
|
5006
4948
|
startTime = Date.now();
|
|
@@ -5347,7 +5289,6 @@ var AlertManager = class {
|
|
|
5347
5289
|
constructor(options) {
|
|
5348
5290
|
this.options = options;
|
|
5349
5291
|
}
|
|
5350
|
-
options;
|
|
5351
5292
|
lastAlertTime = /* @__PURE__ */ new Map();
|
|
5352
5293
|
monitorTimer;
|
|
5353
5294
|
running = false;
|
|
@@ -5422,7 +5363,6 @@ var AuditLogger = class {
|
|
|
5422
5363
|
this.startCleanup();
|
|
5423
5364
|
}
|
|
5424
5365
|
}
|
|
5425
|
-
options;
|
|
5426
5366
|
logs = [];
|
|
5427
5367
|
cleanupTimer;
|
|
5428
5368
|
async log(entry) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentforge/core",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.87",
|
|
4
4
|
"description": "Production-ready TypeScript agent framework built on LangGraph with orchestration, middleware, and typed abstractions.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|