@agentforge/core 0.16.86 → 0.16.88
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 +38 -99
- package/dist/index.d.cts +34 -198
- package/dist/index.d.ts +34 -198
- package/dist/index.js +38 -99
- 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) {
|
|
@@ -5714,9 +5654,11 @@ function createAuditLogger(options) {
|
|
|
5714
5654
|
return new AuditLogger(options);
|
|
5715
5655
|
}
|
|
5716
5656
|
|
|
5717
|
-
// src/prompt-loader/
|
|
5657
|
+
// src/prompt-loader/file-loader.ts
|
|
5718
5658
|
var import_fs = require("fs");
|
|
5719
5659
|
var import_path = require("path");
|
|
5660
|
+
|
|
5661
|
+
// src/prompt-loader/variables.ts
|
|
5720
5662
|
var MAX_VARIABLE_LENGTH = 500;
|
|
5721
5663
|
function createPromptVariableMap() {
|
|
5722
5664
|
return /* @__PURE__ */ Object.create(null);
|
|
@@ -5728,9 +5670,7 @@ function isRenderTemplateOptions(value) {
|
|
|
5728
5670
|
return isPromptVariableMap(value) && (Object.prototype.hasOwnProperty.call(value, "trustedVariables") || Object.prototype.hasOwnProperty.call(value, "untrustedVariables"));
|
|
5729
5671
|
}
|
|
5730
5672
|
function normalizeVariableMap(value) {
|
|
5731
|
-
if (!isPromptVariableMap(value))
|
|
5732
|
-
return createPromptVariableMap();
|
|
5733
|
-
}
|
|
5673
|
+
if (!isPromptVariableMap(value)) return createPromptVariableMap();
|
|
5734
5674
|
return Object.assign(createPromptVariableMap(), value);
|
|
5735
5675
|
}
|
|
5736
5676
|
function sanitizeVariableMap(variables) {
|
|
@@ -5741,11 +5681,7 @@ function sanitizeVariableMap(variables) {
|
|
|
5741
5681
|
return sanitizedVariables;
|
|
5742
5682
|
}
|
|
5743
5683
|
function mergeVariableMaps(baseVariables, overrideVariables) {
|
|
5744
|
-
return Object.assign(
|
|
5745
|
-
createPromptVariableMap(),
|
|
5746
|
-
baseVariables,
|
|
5747
|
-
overrideVariables
|
|
5748
|
-
);
|
|
5684
|
+
return Object.assign(createPromptVariableMap(), baseVariables, overrideVariables);
|
|
5749
5685
|
}
|
|
5750
5686
|
function sanitizeValue(value) {
|
|
5751
5687
|
if (value === void 0 || value === null) return "";
|
|
@@ -5754,10 +5690,12 @@ function sanitizeValue(value) {
|
|
|
5754
5690
|
sanitized = sanitized.replace(/[\r\n]+/g, " ");
|
|
5755
5691
|
sanitized = sanitized.trim().replace(/\s+/g, " ");
|
|
5756
5692
|
if (sanitized.length > MAX_VARIABLE_LENGTH) {
|
|
5757
|
-
sanitized = sanitized.substring(0, MAX_VARIABLE_LENGTH)
|
|
5693
|
+
sanitized = `${sanitized.substring(0, MAX_VARIABLE_LENGTH)}...`;
|
|
5758
5694
|
}
|
|
5759
5695
|
return sanitized;
|
|
5760
5696
|
}
|
|
5697
|
+
|
|
5698
|
+
// src/prompt-loader/renderer.ts
|
|
5761
5699
|
function renderTemplate(template, options) {
|
|
5762
5700
|
let rawVariables;
|
|
5763
5701
|
let sanitizedVariables;
|
|
@@ -5773,17 +5711,18 @@ function renderTemplate(template, options) {
|
|
|
5773
5711
|
rawVariables = normalizeVariableMap(options);
|
|
5774
5712
|
sanitizedVariables = rawVariables;
|
|
5775
5713
|
}
|
|
5776
|
-
let result = template
|
|
5777
|
-
|
|
5778
|
-
|
|
5779
|
-
|
|
5780
|
-
result = result.replace(/\{\{(\w+)\}\}/g, (_,
|
|
5781
|
-
const value = sanitizedVariables[
|
|
5782
|
-
|
|
5783
|
-
return String(value);
|
|
5714
|
+
let result = template.replace(
|
|
5715
|
+
/\{\{#if\s+(\w+)\}\}([\s\S]*?)\{\{\/if\}\}/g,
|
|
5716
|
+
(_, variableName, content) => rawVariables[variableName] ? content : ""
|
|
5717
|
+
);
|
|
5718
|
+
result = result.replace(/\{\{(\w+)\}\}/g, (_, variableName) => {
|
|
5719
|
+
const value = sanitizedVariables[variableName];
|
|
5720
|
+
return value === void 0 || value === null ? "" : String(value);
|
|
5784
5721
|
});
|
|
5785
5722
|
return result;
|
|
5786
5723
|
}
|
|
5724
|
+
|
|
5725
|
+
// src/prompt-loader/file-loader.ts
|
|
5787
5726
|
function loadPrompt(promptName, options = {}, promptsDir) {
|
|
5788
5727
|
const baseDir = promptsDir || (0, import_path.join)(process.cwd(), "prompts");
|
|
5789
5728
|
const promptPath = (0, import_path.join)(baseDir, `${promptName}.md`);
|
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
|
/**
|
|
@@ -4590,115 +4505,36 @@ declare class AuditLogger {
|
|
|
4590
4505
|
}
|
|
4591
4506
|
declare function createAuditLogger(options?: AuditLoggerOptions): AuditLogger;
|
|
4592
4507
|
|
|
4593
|
-
/**
|
|
4594
|
-
* Prompt Template Loader
|
|
4595
|
-
*
|
|
4596
|
-
* Utility for loading and rendering prompt templates from .md files.
|
|
4597
|
-
* Supports variable substitution and conditional blocks.
|
|
4598
|
-
*
|
|
4599
|
-
* SECURITY: This module includes protection against prompt injection attacks
|
|
4600
|
-
* by sanitizing variable values before substitution.
|
|
4601
|
-
*/
|
|
4602
4508
|
type PromptVariableValue = unknown;
|
|
4603
4509
|
type PromptVariableMap = Record<string, PromptVariableValue>;
|
|
4604
|
-
/**
|
|
4605
|
-
* Options for rendering templates with security controls
|
|
4606
|
-
*/
|
|
4510
|
+
/** Options for rendering templates with trusted and untrusted variables. */
|
|
4607
4511
|
interface RenderTemplateOptions {
|
|
4608
|
-
/**
|
|
4609
|
-
* Variables from trusted sources (config files, hardcoded values)
|
|
4610
|
-
* These will NOT be sanitized
|
|
4611
|
-
*/
|
|
4512
|
+
/** Variables from trusted sources. These values are not sanitized. */
|
|
4612
4513
|
trustedVariables?: PromptVariableMap;
|
|
4613
|
-
/**
|
|
4614
|
-
* Variables from untrusted sources (user input, API calls, databases)
|
|
4615
|
-
* These WILL be sanitized to prevent prompt injection
|
|
4616
|
-
*/
|
|
4514
|
+
/** Variables from untrusted sources. These values are sanitized. */
|
|
4617
4515
|
untrustedVariables?: PromptVariableMap;
|
|
4618
4516
|
}
|
|
4517
|
+
|
|
4619
4518
|
/**
|
|
4620
|
-
*
|
|
4621
|
-
*
|
|
4622
|
-
* Protections:
|
|
4623
|
-
* - Removes markdown headers (prevents structure hijacking)
|
|
4624
|
-
* - Removes newlines (prevents multi-line injection)
|
|
4625
|
-
* - Limits length (prevents prompt bloat)
|
|
4626
|
-
*
|
|
4627
|
-
* @param value - The value to sanitize
|
|
4628
|
-
* @returns Sanitized string safe for use in prompts
|
|
4519
|
+
* Load and render a Markdown prompt template from a custom directory or the
|
|
4520
|
+
* `prompts` directory beneath the current working directory.
|
|
4629
4521
|
*/
|
|
4630
|
-
declare function
|
|
4522
|
+
declare function loadPrompt(promptName: string, options?: RenderTemplateOptions | PromptVariableMap, promptsDir?: string): string;
|
|
4523
|
+
|
|
4631
4524
|
/**
|
|
4632
|
-
* Render
|
|
4633
|
-
*
|
|
4634
|
-
*
|
|
4635
|
-
*
|
|
4636
|
-
* - Conditional blocks: {{#if variableName}}...{{/if}}
|
|
4637
|
-
*
|
|
4638
|
-
* SECURITY: Distinguishes between trusted and untrusted variables.
|
|
4639
|
-
* - Trusted variables (from config) are used as-is
|
|
4640
|
-
* - Untrusted variables (from user input) are sanitized
|
|
4641
|
-
* - Only own enumerable properties are considered from provided variable maps
|
|
4642
|
-
* or backwards-compatible plain objects
|
|
4643
|
-
*
|
|
4644
|
-
* @param template - Template string with {{variable}} placeholders
|
|
4645
|
-
* @param options - Variables and security options
|
|
4646
|
-
* @returns Rendered template string
|
|
4647
|
-
*
|
|
4648
|
-
* @example
|
|
4649
|
-
* ```typescript
|
|
4650
|
-
* // Safe: Trusted variables from config
|
|
4651
|
-
* const result = renderTemplate(template, {
|
|
4652
|
-
* trustedVariables: {
|
|
4653
|
-
* companyName: 'Acme Corp', // From config file
|
|
4654
|
-
* premium: true
|
|
4655
|
-
* }
|
|
4656
|
-
* });
|
|
4657
|
-
*
|
|
4658
|
-
* // Safe: Untrusted variables are sanitized
|
|
4659
|
-
* const result = renderTemplate(template, {
|
|
4660
|
-
* untrustedVariables: {
|
|
4661
|
-
* userName: req.body.name, // User input - will be sanitized
|
|
4662
|
-
* }
|
|
4663
|
-
* });
|
|
4664
|
-
*
|
|
4665
|
-
* // Mixed: Some trusted, some untrusted
|
|
4666
|
-
* const result = renderTemplate(template, {
|
|
4667
|
-
* trustedVariables: {
|
|
4668
|
-
* companyName: 'Acme Corp', // From config
|
|
4669
|
-
* },
|
|
4670
|
-
* untrustedVariables: {
|
|
4671
|
-
* userName: req.body.name, // User input
|
|
4672
|
-
* }
|
|
4673
|
-
* });
|
|
4674
|
-
* ```
|
|
4525
|
+
* Render substitutions and conditional blocks with trusted/untrusted controls.
|
|
4526
|
+
* Trusted values are substituted unchanged, untrusted values are sanitized,
|
|
4527
|
+
* and conditional truthiness is evaluated against the original raw values.
|
|
4528
|
+
* Plain variable maps remain supported as trusted input for compatibility.
|
|
4675
4529
|
*/
|
|
4676
4530
|
declare function renderTemplate(template: string, options: RenderTemplateOptions | PromptVariableMap): string;
|
|
4531
|
+
|
|
4677
4532
|
/**
|
|
4678
|
-
*
|
|
4679
|
-
*
|
|
4680
|
-
* Looks for prompts in a `prompts/` directory relative to the caller's location.
|
|
4681
|
-
*
|
|
4682
|
-
* @param promptName - Name of the prompt file (without .md extension)
|
|
4683
|
-
* @param options - Variables and security options
|
|
4684
|
-
* @param promptsDir - Optional custom prompts directory path
|
|
4685
|
-
* @returns Rendered prompt string
|
|
4686
|
-
*
|
|
4687
|
-
* @example
|
|
4688
|
-
* ```typescript
|
|
4689
|
-
* // Backwards compatible: all variables treated as trusted
|
|
4690
|
-
* loadPrompt('system', { companyName: 'Acme' });
|
|
4691
|
-
*
|
|
4692
|
-
* // Explicit: separate trusted and untrusted
|
|
4693
|
-
* loadPrompt('system', {
|
|
4694
|
-
* trustedVariables: { companyName: 'Acme' },
|
|
4695
|
-
* untrustedVariables: { userName: userInput }
|
|
4696
|
-
* });
|
|
4533
|
+
* Sanitize an untrusted value before prompt substitution.
|
|
4697
4534
|
*
|
|
4698
|
-
*
|
|
4699
|
-
*
|
|
4700
|
-
* ```
|
|
4535
|
+
* Removes Markdown header markers and line breaks, collapses whitespace,
|
|
4536
|
+
* and limits output to 500 characters plus an ellipsis.
|
|
4701
4537
|
*/
|
|
4702
|
-
declare function
|
|
4538
|
+
declare function sanitizeValue(value: unknown): string;
|
|
4703
4539
|
|
|
4704
4540
|
export { AgentError, type AgentResumedEventData, type AgentWaitingEventData, type AggregateNode, type Alert, type AlertChannel, AlertManager, type AlertManagerOptions, type AlertRule, type AlertSeverity, type AnyInterrupt, type ApprovalRequiredInterrupt, type AuditLogEntry, type AuditLogQuery, AuditLogger, type AuditLoggerOptions, type BackoffStrategy, type BatchOptions, BatchProcessor, type BatchProcessorOptions, type BatchStats, type CacheKeyGenerator, type CachingOptions, type CheckInterruptOptions, type CheckpointHistoryOptions, type CheckpointerOptions, type ChunkOptions, CircuitBreaker, type CircuitBreakerOptions, type CircuitBreakerStats, type CircuitState, type ComposeGraphsOptions, type ComposeOptions, type ComposeToolConfig, type ComposedTool, type ConcurrencyOptions, type ConditionalConfig, type ConditionalRouter, type ConditionalRouterConfig, ConnectionPool, type ConnectionPoolOptions, type ConversationConfig, type CustomAlertChannel, type CustomInterrupt, type DatabaseConfig, type DatabaseConnection, DatabasePool, type DatabasePoolOptions, type DatabaseQueryParams, type DatabaseQueryResult, type DevelopmentPresetOptions, type EmailAlertChannel, type ErrorContext, type ErrorHandlerOptions, type ErrorReporter, type ErrorReporterOptions, type EventHandler, type EvictionStrategy, type ExecutionMetrics, type GenericAlertChannel, type HealthCheck, type HealthCheckConfig, type HealthCheckResult, HealthChecker, type HealthCheckerOptions, type HealthReport, type HealthStatus, type HttpClient, type HttpConfig, HttpPool, type HttpPoolConfig, type HttpPoolOptions, type HttpResponse, type HumanInLoopEventData, type HumanInLoopEventType, type HumanRequest, type HumanRequestEventData, type HumanRequestInterrupt, type HumanRequestPriority, type HumanRequestStatus, type HumanResponseEventData, type InterruptData, type InterruptEventData, type InterruptType, type JsonObject, type JsonPrimitive, type JsonValue, type LangSmithConfig, type LogEntry, LogLevel, type Logger, type LoggerOptions, type LoggingOptions, ManagedTool, type ManagedToolConfig, type ManagedToolStats, MemoryManager, type MemoryManagerOptions, type MemoryStats, type MetricEntry, MetricType, type Metrics, type MetricsNodeOptions, type Middleware, MiddlewareChain, type MiddlewareContext, type MiddlewareFactory, type MiddlewareMetadata, type MiddlewareWithMetadata, MissingDescriptionError, type MockExecutionRuntimeOptions, type MockToolConfig, type MockToolResponse, type NodeFunction, type NodeFunctionWithContext, type ParallelNode, type ParallelWorkflowConfig, type ParallelWorkflowOptions, type PoolConfig, type PoolStats, type Priority$1 as Priority, type ProductionPresetOptions, type ProfileReport, type ProfileSample, type ProfileStats, Profiler, type ProfilerOptions, type Progress, type ProgressTracker, type ProgressTrackerOptions, type PromptOptions, type PromptVariableMap, type PromptVariableValue, type RateLimitOptions, type RateLimitStrategy, type ReducerFunction, RegistryEvent, type RenderTemplateOptions, type RequestConfig, type ResumeCommand, type ResumeEventData, type ResumeOptions, type RetryOptions, type RetryPolicy, type RouteCondition, type RouteMap, type RouteName, type SSEEvent, type SSEFormatter, type SSEFormatterOptions, type SequentialNode, type SequentialWorkflowOptions, type SimpleMiddleware, type SlackAlertChannel, type SqliteCheckpointerOptions, type StateChannelConfig, type SubgraphBuilder, type TestingPresetOptions, type ThreadConfig, type ThreadInfo, type ThreadStatus, type ThrottleOptions, TimeoutError, type TimeoutOptions, type Timer, type Tool, type BackoffStrategy$1 as ToolBackoffStrategy, ToolBuilder, ToolCategory, ToolCategorySchema, type ToolExample, ToolExampleSchema, type ToolExecution, type ToolExecutorConfig, type ToolHealthCheckResult, type ToolInvocation, type ToolMetadata, ToolMetadataSchema, ToolNameSchema, ToolRegistry, type ToolRelations, ToolRelationsSchema, type ToolSimulatorConfig, type TracingOptions, type ValidationErrorHandler, type ValidationMode, type ValidationOptions, type ValidatorFunction, type WebSocketBinaryData, type WebSocketCloseReason, type WebSocketCloseReasonFor, type WebSocketConnection, type WebSocketEvent, type WebSocketEventHandler, type WebSocketHandlerOptions, type WebSocketMessage, type WebSocketMessageFor, type WebSocketRawMessage, type WebSocketSendTarget, type WebhookAlertChannel, batch, broadcast, cache, chain, chunk, clearThread, collect, compose, composeGraphs, composeTool, composeWithOptions, conditional, configureLangSmith, createAlertManager, createApprovalRequiredInterrupt, createAuditLogger, createBatchProcessor, createBinaryRouter, createCircuitBreaker, createConditionalRouter, createConnectionPool, createConversationConfig, createCustomInterrupt, createDatabasePool, createErrorReporter, createHealthChecker, createHeartbeat, createHttpPool, createHumanRequestInterrupt, createLogger, createManagedTool, createMemoryCheckpointer, createMemoryManager, createMessage, createMetrics, createMiddlewareContext, createMockTool, createMultiRouter, createParallelWorkflow, createProfiler, createProgressTracker, createSSEFormatter, createSequentialWorkflow, createSharedCache, createSharedConcurrencyController, createSharedRateLimiter, createSqliteCheckpointer, createStateAnnotation, createSubgraph, createThreadConfig, createTool, createToolExecutor, createToolSimulator, createToolUnsafe, createWebSocketHandler, development, filter, formatAgentResumedEvent, formatAgentWaitingEvent, formatHumanRequestEvent, formatHumanResponseEvent, formatInterruptEvent, formatResumeEvent, generateThreadId, getCheckpointHistory, getLangSmithConfig, getLatestCheckpoint, getMissingDescriptions, getThreadStatus, getToolDescription, getToolJsonSchema, isApprovalRequiredInterrupt, isCustomInterrupt, isHumanRequestInterrupt, isMemoryCheckpointer, isTracingEnabled, loadPrompt, map, merge, mergeState, parallel, parseSSEEvent, presets, production, reduce, renderTemplate, retry, runMockExecution, safeValidateSchemaDescriptions, sanitizeValue, sendMessage, sequential, sequentialBuilder, take, testing, throttle, timeout, toLangChainTool, toLangChainTools, toolBuilder, validateSchemaDescriptions, validateState, validateTool, validateToolMetadata, validateToolName, withCache, withConcurrency, withErrorHandler, withLogging, withMetrics, withRateLimit, withRetry, withTimeout, withTracing, withValidation };
|
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
|
/**
|
|
@@ -4590,115 +4505,36 @@ declare class AuditLogger {
|
|
|
4590
4505
|
}
|
|
4591
4506
|
declare function createAuditLogger(options?: AuditLoggerOptions): AuditLogger;
|
|
4592
4507
|
|
|
4593
|
-
/**
|
|
4594
|
-
* Prompt Template Loader
|
|
4595
|
-
*
|
|
4596
|
-
* Utility for loading and rendering prompt templates from .md files.
|
|
4597
|
-
* Supports variable substitution and conditional blocks.
|
|
4598
|
-
*
|
|
4599
|
-
* SECURITY: This module includes protection against prompt injection attacks
|
|
4600
|
-
* by sanitizing variable values before substitution.
|
|
4601
|
-
*/
|
|
4602
4508
|
type PromptVariableValue = unknown;
|
|
4603
4509
|
type PromptVariableMap = Record<string, PromptVariableValue>;
|
|
4604
|
-
/**
|
|
4605
|
-
* Options for rendering templates with security controls
|
|
4606
|
-
*/
|
|
4510
|
+
/** Options for rendering templates with trusted and untrusted variables. */
|
|
4607
4511
|
interface RenderTemplateOptions {
|
|
4608
|
-
/**
|
|
4609
|
-
* Variables from trusted sources (config files, hardcoded values)
|
|
4610
|
-
* These will NOT be sanitized
|
|
4611
|
-
*/
|
|
4512
|
+
/** Variables from trusted sources. These values are not sanitized. */
|
|
4612
4513
|
trustedVariables?: PromptVariableMap;
|
|
4613
|
-
/**
|
|
4614
|
-
* Variables from untrusted sources (user input, API calls, databases)
|
|
4615
|
-
* These WILL be sanitized to prevent prompt injection
|
|
4616
|
-
*/
|
|
4514
|
+
/** Variables from untrusted sources. These values are sanitized. */
|
|
4617
4515
|
untrustedVariables?: PromptVariableMap;
|
|
4618
4516
|
}
|
|
4517
|
+
|
|
4619
4518
|
/**
|
|
4620
|
-
*
|
|
4621
|
-
*
|
|
4622
|
-
* Protections:
|
|
4623
|
-
* - Removes markdown headers (prevents structure hijacking)
|
|
4624
|
-
* - Removes newlines (prevents multi-line injection)
|
|
4625
|
-
* - Limits length (prevents prompt bloat)
|
|
4626
|
-
*
|
|
4627
|
-
* @param value - The value to sanitize
|
|
4628
|
-
* @returns Sanitized string safe for use in prompts
|
|
4519
|
+
* Load and render a Markdown prompt template from a custom directory or the
|
|
4520
|
+
* `prompts` directory beneath the current working directory.
|
|
4629
4521
|
*/
|
|
4630
|
-
declare function
|
|
4522
|
+
declare function loadPrompt(promptName: string, options?: RenderTemplateOptions | PromptVariableMap, promptsDir?: string): string;
|
|
4523
|
+
|
|
4631
4524
|
/**
|
|
4632
|
-
* Render
|
|
4633
|
-
*
|
|
4634
|
-
*
|
|
4635
|
-
*
|
|
4636
|
-
* - Conditional blocks: {{#if variableName}}...{{/if}}
|
|
4637
|
-
*
|
|
4638
|
-
* SECURITY: Distinguishes between trusted and untrusted variables.
|
|
4639
|
-
* - Trusted variables (from config) are used as-is
|
|
4640
|
-
* - Untrusted variables (from user input) are sanitized
|
|
4641
|
-
* - Only own enumerable properties are considered from provided variable maps
|
|
4642
|
-
* or backwards-compatible plain objects
|
|
4643
|
-
*
|
|
4644
|
-
* @param template - Template string with {{variable}} placeholders
|
|
4645
|
-
* @param options - Variables and security options
|
|
4646
|
-
* @returns Rendered template string
|
|
4647
|
-
*
|
|
4648
|
-
* @example
|
|
4649
|
-
* ```typescript
|
|
4650
|
-
* // Safe: Trusted variables from config
|
|
4651
|
-
* const result = renderTemplate(template, {
|
|
4652
|
-
* trustedVariables: {
|
|
4653
|
-
* companyName: 'Acme Corp', // From config file
|
|
4654
|
-
* premium: true
|
|
4655
|
-
* }
|
|
4656
|
-
* });
|
|
4657
|
-
*
|
|
4658
|
-
* // Safe: Untrusted variables are sanitized
|
|
4659
|
-
* const result = renderTemplate(template, {
|
|
4660
|
-
* untrustedVariables: {
|
|
4661
|
-
* userName: req.body.name, // User input - will be sanitized
|
|
4662
|
-
* }
|
|
4663
|
-
* });
|
|
4664
|
-
*
|
|
4665
|
-
* // Mixed: Some trusted, some untrusted
|
|
4666
|
-
* const result = renderTemplate(template, {
|
|
4667
|
-
* trustedVariables: {
|
|
4668
|
-
* companyName: 'Acme Corp', // From config
|
|
4669
|
-
* },
|
|
4670
|
-
* untrustedVariables: {
|
|
4671
|
-
* userName: req.body.name, // User input
|
|
4672
|
-
* }
|
|
4673
|
-
* });
|
|
4674
|
-
* ```
|
|
4525
|
+
* Render substitutions and conditional blocks with trusted/untrusted controls.
|
|
4526
|
+
* Trusted values are substituted unchanged, untrusted values are sanitized,
|
|
4527
|
+
* and conditional truthiness is evaluated against the original raw values.
|
|
4528
|
+
* Plain variable maps remain supported as trusted input for compatibility.
|
|
4675
4529
|
*/
|
|
4676
4530
|
declare function renderTemplate(template: string, options: RenderTemplateOptions | PromptVariableMap): string;
|
|
4531
|
+
|
|
4677
4532
|
/**
|
|
4678
|
-
*
|
|
4679
|
-
*
|
|
4680
|
-
* Looks for prompts in a `prompts/` directory relative to the caller's location.
|
|
4681
|
-
*
|
|
4682
|
-
* @param promptName - Name of the prompt file (without .md extension)
|
|
4683
|
-
* @param options - Variables and security options
|
|
4684
|
-
* @param promptsDir - Optional custom prompts directory path
|
|
4685
|
-
* @returns Rendered prompt string
|
|
4686
|
-
*
|
|
4687
|
-
* @example
|
|
4688
|
-
* ```typescript
|
|
4689
|
-
* // Backwards compatible: all variables treated as trusted
|
|
4690
|
-
* loadPrompt('system', { companyName: 'Acme' });
|
|
4691
|
-
*
|
|
4692
|
-
* // Explicit: separate trusted and untrusted
|
|
4693
|
-
* loadPrompt('system', {
|
|
4694
|
-
* trustedVariables: { companyName: 'Acme' },
|
|
4695
|
-
* untrustedVariables: { userName: userInput }
|
|
4696
|
-
* });
|
|
4533
|
+
* Sanitize an untrusted value before prompt substitution.
|
|
4697
4534
|
*
|
|
4698
|
-
*
|
|
4699
|
-
*
|
|
4700
|
-
* ```
|
|
4535
|
+
* Removes Markdown header markers and line breaks, collapses whitespace,
|
|
4536
|
+
* and limits output to 500 characters plus an ellipsis.
|
|
4701
4537
|
*/
|
|
4702
|
-
declare function
|
|
4538
|
+
declare function sanitizeValue(value: unknown): string;
|
|
4703
4539
|
|
|
4704
4540
|
export { AgentError, type AgentResumedEventData, type AgentWaitingEventData, type AggregateNode, type Alert, type AlertChannel, AlertManager, type AlertManagerOptions, type AlertRule, type AlertSeverity, type AnyInterrupt, type ApprovalRequiredInterrupt, type AuditLogEntry, type AuditLogQuery, AuditLogger, type AuditLoggerOptions, type BackoffStrategy, type BatchOptions, BatchProcessor, type BatchProcessorOptions, type BatchStats, type CacheKeyGenerator, type CachingOptions, type CheckInterruptOptions, type CheckpointHistoryOptions, type CheckpointerOptions, type ChunkOptions, CircuitBreaker, type CircuitBreakerOptions, type CircuitBreakerStats, type CircuitState, type ComposeGraphsOptions, type ComposeOptions, type ComposeToolConfig, type ComposedTool, type ConcurrencyOptions, type ConditionalConfig, type ConditionalRouter, type ConditionalRouterConfig, ConnectionPool, type ConnectionPoolOptions, type ConversationConfig, type CustomAlertChannel, type CustomInterrupt, type DatabaseConfig, type DatabaseConnection, DatabasePool, type DatabasePoolOptions, type DatabaseQueryParams, type DatabaseQueryResult, type DevelopmentPresetOptions, type EmailAlertChannel, type ErrorContext, type ErrorHandlerOptions, type ErrorReporter, type ErrorReporterOptions, type EventHandler, type EvictionStrategy, type ExecutionMetrics, type GenericAlertChannel, type HealthCheck, type HealthCheckConfig, type HealthCheckResult, HealthChecker, type HealthCheckerOptions, type HealthReport, type HealthStatus, type HttpClient, type HttpConfig, HttpPool, type HttpPoolConfig, type HttpPoolOptions, type HttpResponse, type HumanInLoopEventData, type HumanInLoopEventType, type HumanRequest, type HumanRequestEventData, type HumanRequestInterrupt, type HumanRequestPriority, type HumanRequestStatus, type HumanResponseEventData, type InterruptData, type InterruptEventData, type InterruptType, type JsonObject, type JsonPrimitive, type JsonValue, type LangSmithConfig, type LogEntry, LogLevel, type Logger, type LoggerOptions, type LoggingOptions, ManagedTool, type ManagedToolConfig, type ManagedToolStats, MemoryManager, type MemoryManagerOptions, type MemoryStats, type MetricEntry, MetricType, type Metrics, type MetricsNodeOptions, type Middleware, MiddlewareChain, type MiddlewareContext, type MiddlewareFactory, type MiddlewareMetadata, type MiddlewareWithMetadata, MissingDescriptionError, type MockExecutionRuntimeOptions, type MockToolConfig, type MockToolResponse, type NodeFunction, type NodeFunctionWithContext, type ParallelNode, type ParallelWorkflowConfig, type ParallelWorkflowOptions, type PoolConfig, type PoolStats, type Priority$1 as Priority, type ProductionPresetOptions, type ProfileReport, type ProfileSample, type ProfileStats, Profiler, type ProfilerOptions, type Progress, type ProgressTracker, type ProgressTrackerOptions, type PromptOptions, type PromptVariableMap, type PromptVariableValue, type RateLimitOptions, type RateLimitStrategy, type ReducerFunction, RegistryEvent, type RenderTemplateOptions, type RequestConfig, type ResumeCommand, type ResumeEventData, type ResumeOptions, type RetryOptions, type RetryPolicy, type RouteCondition, type RouteMap, type RouteName, type SSEEvent, type SSEFormatter, type SSEFormatterOptions, type SequentialNode, type SequentialWorkflowOptions, type SimpleMiddleware, type SlackAlertChannel, type SqliteCheckpointerOptions, type StateChannelConfig, type SubgraphBuilder, type TestingPresetOptions, type ThreadConfig, type ThreadInfo, type ThreadStatus, type ThrottleOptions, TimeoutError, type TimeoutOptions, type Timer, type Tool, type BackoffStrategy$1 as ToolBackoffStrategy, ToolBuilder, ToolCategory, ToolCategorySchema, type ToolExample, ToolExampleSchema, type ToolExecution, type ToolExecutorConfig, type ToolHealthCheckResult, type ToolInvocation, type ToolMetadata, ToolMetadataSchema, ToolNameSchema, ToolRegistry, type ToolRelations, ToolRelationsSchema, type ToolSimulatorConfig, type TracingOptions, type ValidationErrorHandler, type ValidationMode, type ValidationOptions, type ValidatorFunction, type WebSocketBinaryData, type WebSocketCloseReason, type WebSocketCloseReasonFor, type WebSocketConnection, type WebSocketEvent, type WebSocketEventHandler, type WebSocketHandlerOptions, type WebSocketMessage, type WebSocketMessageFor, type WebSocketRawMessage, type WebSocketSendTarget, type WebhookAlertChannel, batch, broadcast, cache, chain, chunk, clearThread, collect, compose, composeGraphs, composeTool, composeWithOptions, conditional, configureLangSmith, createAlertManager, createApprovalRequiredInterrupt, createAuditLogger, createBatchProcessor, createBinaryRouter, createCircuitBreaker, createConditionalRouter, createConnectionPool, createConversationConfig, createCustomInterrupt, createDatabasePool, createErrorReporter, createHealthChecker, createHeartbeat, createHttpPool, createHumanRequestInterrupt, createLogger, createManagedTool, createMemoryCheckpointer, createMemoryManager, createMessage, createMetrics, createMiddlewareContext, createMockTool, createMultiRouter, createParallelWorkflow, createProfiler, createProgressTracker, createSSEFormatter, createSequentialWorkflow, createSharedCache, createSharedConcurrencyController, createSharedRateLimiter, createSqliteCheckpointer, createStateAnnotation, createSubgraph, createThreadConfig, createTool, createToolExecutor, createToolSimulator, createToolUnsafe, createWebSocketHandler, development, filter, formatAgentResumedEvent, formatAgentWaitingEvent, formatHumanRequestEvent, formatHumanResponseEvent, formatInterruptEvent, formatResumeEvent, generateThreadId, getCheckpointHistory, getLangSmithConfig, getLatestCheckpoint, getMissingDescriptions, getThreadStatus, getToolDescription, getToolJsonSchema, isApprovalRequiredInterrupt, isCustomInterrupt, isHumanRequestInterrupt, isMemoryCheckpointer, isTracingEnabled, loadPrompt, map, merge, mergeState, parallel, parseSSEEvent, presets, production, reduce, renderTemplate, retry, runMockExecution, safeValidateSchemaDescriptions, sanitizeValue, sendMessage, sequential, sequentialBuilder, take, testing, throttle, timeout, toLangChainTool, toLangChainTools, toolBuilder, validateSchemaDescriptions, validateState, validateTool, validateToolMetadata, validateToolName, withCache, withConcurrency, withErrorHandler, withLogging, withMetrics, withRateLimit, withRetry, withTimeout, withTracing, withValidation };
|
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) {
|
|
@@ -5538,9 +5478,11 @@ function createAuditLogger(options) {
|
|
|
5538
5478
|
return new AuditLogger(options);
|
|
5539
5479
|
}
|
|
5540
5480
|
|
|
5541
|
-
// src/prompt-loader/
|
|
5481
|
+
// src/prompt-loader/file-loader.ts
|
|
5542
5482
|
import { readFileSync } from "fs";
|
|
5543
5483
|
import { join } from "path";
|
|
5484
|
+
|
|
5485
|
+
// src/prompt-loader/variables.ts
|
|
5544
5486
|
var MAX_VARIABLE_LENGTH = 500;
|
|
5545
5487
|
function createPromptVariableMap() {
|
|
5546
5488
|
return /* @__PURE__ */ Object.create(null);
|
|
@@ -5552,9 +5494,7 @@ function isRenderTemplateOptions(value) {
|
|
|
5552
5494
|
return isPromptVariableMap(value) && (Object.prototype.hasOwnProperty.call(value, "trustedVariables") || Object.prototype.hasOwnProperty.call(value, "untrustedVariables"));
|
|
5553
5495
|
}
|
|
5554
5496
|
function normalizeVariableMap(value) {
|
|
5555
|
-
if (!isPromptVariableMap(value))
|
|
5556
|
-
return createPromptVariableMap();
|
|
5557
|
-
}
|
|
5497
|
+
if (!isPromptVariableMap(value)) return createPromptVariableMap();
|
|
5558
5498
|
return Object.assign(createPromptVariableMap(), value);
|
|
5559
5499
|
}
|
|
5560
5500
|
function sanitizeVariableMap(variables) {
|
|
@@ -5565,11 +5505,7 @@ function sanitizeVariableMap(variables) {
|
|
|
5565
5505
|
return sanitizedVariables;
|
|
5566
5506
|
}
|
|
5567
5507
|
function mergeVariableMaps(baseVariables, overrideVariables) {
|
|
5568
|
-
return Object.assign(
|
|
5569
|
-
createPromptVariableMap(),
|
|
5570
|
-
baseVariables,
|
|
5571
|
-
overrideVariables
|
|
5572
|
-
);
|
|
5508
|
+
return Object.assign(createPromptVariableMap(), baseVariables, overrideVariables);
|
|
5573
5509
|
}
|
|
5574
5510
|
function sanitizeValue(value) {
|
|
5575
5511
|
if (value === void 0 || value === null) return "";
|
|
@@ -5578,10 +5514,12 @@ function sanitizeValue(value) {
|
|
|
5578
5514
|
sanitized = sanitized.replace(/[\r\n]+/g, " ");
|
|
5579
5515
|
sanitized = sanitized.trim().replace(/\s+/g, " ");
|
|
5580
5516
|
if (sanitized.length > MAX_VARIABLE_LENGTH) {
|
|
5581
|
-
sanitized = sanitized.substring(0, MAX_VARIABLE_LENGTH)
|
|
5517
|
+
sanitized = `${sanitized.substring(0, MAX_VARIABLE_LENGTH)}...`;
|
|
5582
5518
|
}
|
|
5583
5519
|
return sanitized;
|
|
5584
5520
|
}
|
|
5521
|
+
|
|
5522
|
+
// src/prompt-loader/renderer.ts
|
|
5585
5523
|
function renderTemplate(template, options) {
|
|
5586
5524
|
let rawVariables;
|
|
5587
5525
|
let sanitizedVariables;
|
|
@@ -5597,17 +5535,18 @@ function renderTemplate(template, options) {
|
|
|
5597
5535
|
rawVariables = normalizeVariableMap(options);
|
|
5598
5536
|
sanitizedVariables = rawVariables;
|
|
5599
5537
|
}
|
|
5600
|
-
let result = template
|
|
5601
|
-
|
|
5602
|
-
|
|
5603
|
-
|
|
5604
|
-
result = result.replace(/\{\{(\w+)\}\}/g, (_,
|
|
5605
|
-
const value = sanitizedVariables[
|
|
5606
|
-
|
|
5607
|
-
return String(value);
|
|
5538
|
+
let result = template.replace(
|
|
5539
|
+
/\{\{#if\s+(\w+)\}\}([\s\S]*?)\{\{\/if\}\}/g,
|
|
5540
|
+
(_, variableName, content) => rawVariables[variableName] ? content : ""
|
|
5541
|
+
);
|
|
5542
|
+
result = result.replace(/\{\{(\w+)\}\}/g, (_, variableName) => {
|
|
5543
|
+
const value = sanitizedVariables[variableName];
|
|
5544
|
+
return value === void 0 || value === null ? "" : String(value);
|
|
5608
5545
|
});
|
|
5609
5546
|
return result;
|
|
5610
5547
|
}
|
|
5548
|
+
|
|
5549
|
+
// src/prompt-loader/file-loader.ts
|
|
5611
5550
|
function loadPrompt(promptName, options = {}, promptsDir) {
|
|
5612
5551
|
const baseDir = promptsDir || join(process.cwd(), "prompts");
|
|
5613
5552
|
const promptPath = join(baseDir, `${promptName}.md`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentforge/core",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.88",
|
|
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",
|