@agentforge/core 0.16.49 → 0.16.51
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 +129 -133
- package/dist/index.d.cts +107 -219
- package/dist/index.d.ts +107 -219
- package/dist/index.js +129 -133
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2438,110 +2438,6 @@ function createMiddlewareContext() {
|
|
|
2438
2438
|
};
|
|
2439
2439
|
}
|
|
2440
2440
|
|
|
2441
|
-
// src/langgraph/middleware/retry.ts
|
|
2442
|
-
function calculateDelay(attempt, strategy, initialDelay, maxDelay) {
|
|
2443
|
-
let delay;
|
|
2444
|
-
switch (strategy) {
|
|
2445
|
-
case "constant":
|
|
2446
|
-
delay = initialDelay;
|
|
2447
|
-
break;
|
|
2448
|
-
case "linear":
|
|
2449
|
-
delay = initialDelay * attempt;
|
|
2450
|
-
break;
|
|
2451
|
-
case "exponential":
|
|
2452
|
-
delay = initialDelay * Math.pow(2, attempt - 1);
|
|
2453
|
-
break;
|
|
2454
|
-
}
|
|
2455
|
-
return Math.min(delay, maxDelay);
|
|
2456
|
-
}
|
|
2457
|
-
function sleep(ms) {
|
|
2458
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2459
|
-
}
|
|
2460
|
-
function withRetry(node, options = {}) {
|
|
2461
|
-
const {
|
|
2462
|
-
maxAttempts = 3,
|
|
2463
|
-
backoff = "exponential",
|
|
2464
|
-
initialDelay = 1e3,
|
|
2465
|
-
maxDelay = 3e4,
|
|
2466
|
-
onRetry,
|
|
2467
|
-
shouldRetry = () => true
|
|
2468
|
-
} = options;
|
|
2469
|
-
return async (state) => {
|
|
2470
|
-
let lastError;
|
|
2471
|
-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
2472
|
-
try {
|
|
2473
|
-
return await Promise.resolve(node(state));
|
|
2474
|
-
} catch (error) {
|
|
2475
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
2476
|
-
if (!shouldRetry(lastError)) {
|
|
2477
|
-
throw lastError;
|
|
2478
|
-
}
|
|
2479
|
-
if (attempt === maxAttempts) {
|
|
2480
|
-
throw lastError;
|
|
2481
|
-
}
|
|
2482
|
-
if (onRetry) {
|
|
2483
|
-
onRetry(lastError, attempt);
|
|
2484
|
-
}
|
|
2485
|
-
const delay = calculateDelay(attempt, backoff, initialDelay, maxDelay);
|
|
2486
|
-
await sleep(delay);
|
|
2487
|
-
}
|
|
2488
|
-
}
|
|
2489
|
-
throw lastError || new Error("Retry failed");
|
|
2490
|
-
};
|
|
2491
|
-
}
|
|
2492
|
-
|
|
2493
|
-
// src/langgraph/middleware/error-handler.ts
|
|
2494
|
-
function withErrorHandler(node, options) {
|
|
2495
|
-
const { onError, logError, rethrow = false } = options;
|
|
2496
|
-
return async (state) => {
|
|
2497
|
-
try {
|
|
2498
|
-
return await Promise.resolve(node(state));
|
|
2499
|
-
} catch (error) {
|
|
2500
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
2501
|
-
if (logError) {
|
|
2502
|
-
logError(err, state);
|
|
2503
|
-
}
|
|
2504
|
-
const result = await Promise.resolve(onError(err, state));
|
|
2505
|
-
if (rethrow) {
|
|
2506
|
-
throw err;
|
|
2507
|
-
}
|
|
2508
|
-
return result;
|
|
2509
|
-
}
|
|
2510
|
-
};
|
|
2511
|
-
}
|
|
2512
|
-
|
|
2513
|
-
// src/langgraph/middleware/timeout.ts
|
|
2514
|
-
var TimeoutError = class extends Error {
|
|
2515
|
-
constructor(timeout2) {
|
|
2516
|
-
super(`Node execution timed out after ${timeout2}ms`);
|
|
2517
|
-
this.name = "TimeoutError";
|
|
2518
|
-
}
|
|
2519
|
-
};
|
|
2520
|
-
function withTimeout(node, options) {
|
|
2521
|
-
const { timeout: timeout2, onTimeout, logTimeout, throwOnTimeout = false } = options;
|
|
2522
|
-
return async (state) => {
|
|
2523
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
2524
|
-
setTimeout(() => {
|
|
2525
|
-
reject(new TimeoutError(timeout2));
|
|
2526
|
-
}, timeout2);
|
|
2527
|
-
});
|
|
2528
|
-
try {
|
|
2529
|
-
return await Promise.race([Promise.resolve(node(state)), timeoutPromise]);
|
|
2530
|
-
} catch (error) {
|
|
2531
|
-
if (error instanceof TimeoutError) {
|
|
2532
|
-
if (logTimeout) {
|
|
2533
|
-
logTimeout(state);
|
|
2534
|
-
}
|
|
2535
|
-
if (throwOnTimeout) {
|
|
2536
|
-
throw error;
|
|
2537
|
-
}
|
|
2538
|
-
return await Promise.resolve(onTimeout(state));
|
|
2539
|
-
}
|
|
2540
|
-
throw error;
|
|
2541
|
-
}
|
|
2542
|
-
};
|
|
2543
|
-
}
|
|
2544
|
-
|
|
2545
2441
|
// src/langgraph/observability/metrics.ts
|
|
2546
2442
|
var MetricType = /* @__PURE__ */ ((MetricType2) => {
|
|
2547
2443
|
MetricType2["COUNTER"] = "counter";
|
|
@@ -2686,6 +2582,26 @@ function withTracing(node, options) {
|
|
|
2686
2582
|
};
|
|
2687
2583
|
}
|
|
2688
2584
|
|
|
2585
|
+
// src/langgraph/middleware/error-handler.ts
|
|
2586
|
+
function withErrorHandler(node, options) {
|
|
2587
|
+
const { onError, logError, rethrow = false } = options;
|
|
2588
|
+
return async (state) => {
|
|
2589
|
+
try {
|
|
2590
|
+
return await Promise.resolve(node(state));
|
|
2591
|
+
} catch (error) {
|
|
2592
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
2593
|
+
if (logError) {
|
|
2594
|
+
logError(err, state);
|
|
2595
|
+
}
|
|
2596
|
+
const result = await Promise.resolve(onError(err, state));
|
|
2597
|
+
if (rethrow) {
|
|
2598
|
+
throw err;
|
|
2599
|
+
}
|
|
2600
|
+
return result;
|
|
2601
|
+
}
|
|
2602
|
+
};
|
|
2603
|
+
}
|
|
2604
|
+
|
|
2689
2605
|
// src/langgraph/middleware/logging.ts
|
|
2690
2606
|
var withLogging = (options) => {
|
|
2691
2607
|
const {
|
|
@@ -2745,7 +2661,91 @@ var withLogging = (options) => {
|
|
|
2745
2661
|
};
|
|
2746
2662
|
};
|
|
2747
2663
|
|
|
2748
|
-
// src/langgraph/middleware/
|
|
2664
|
+
// src/langgraph/middleware/retry.ts
|
|
2665
|
+
function calculateDelay(attempt, strategy, initialDelay, maxDelay) {
|
|
2666
|
+
let delay;
|
|
2667
|
+
switch (strategy) {
|
|
2668
|
+
case "constant":
|
|
2669
|
+
delay = initialDelay;
|
|
2670
|
+
break;
|
|
2671
|
+
case "linear":
|
|
2672
|
+
delay = initialDelay * attempt;
|
|
2673
|
+
break;
|
|
2674
|
+
case "exponential":
|
|
2675
|
+
delay = initialDelay * Math.pow(2, attempt - 1);
|
|
2676
|
+
break;
|
|
2677
|
+
}
|
|
2678
|
+
return Math.min(delay, maxDelay);
|
|
2679
|
+
}
|
|
2680
|
+
function sleep(ms) {
|
|
2681
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2682
|
+
}
|
|
2683
|
+
function withRetry(node, options = {}) {
|
|
2684
|
+
const {
|
|
2685
|
+
maxAttempts = 3,
|
|
2686
|
+
backoff = "exponential",
|
|
2687
|
+
initialDelay = 1e3,
|
|
2688
|
+
maxDelay = 3e4,
|
|
2689
|
+
onRetry,
|
|
2690
|
+
shouldRetry = () => true
|
|
2691
|
+
} = options;
|
|
2692
|
+
return async (state) => {
|
|
2693
|
+
let lastError;
|
|
2694
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
2695
|
+
try {
|
|
2696
|
+
return await Promise.resolve(node(state));
|
|
2697
|
+
} catch (error) {
|
|
2698
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
2699
|
+
if (!shouldRetry(lastError)) {
|
|
2700
|
+
throw lastError;
|
|
2701
|
+
}
|
|
2702
|
+
if (attempt === maxAttempts) {
|
|
2703
|
+
throw lastError;
|
|
2704
|
+
}
|
|
2705
|
+
if (onRetry) {
|
|
2706
|
+
onRetry(lastError, attempt);
|
|
2707
|
+
}
|
|
2708
|
+
const delay = calculateDelay(attempt, backoff, initialDelay, maxDelay);
|
|
2709
|
+
await sleep(delay);
|
|
2710
|
+
}
|
|
2711
|
+
}
|
|
2712
|
+
throw lastError || new Error("Retry failed");
|
|
2713
|
+
};
|
|
2714
|
+
}
|
|
2715
|
+
|
|
2716
|
+
// src/langgraph/middleware/timeout.ts
|
|
2717
|
+
var TimeoutError = class extends Error {
|
|
2718
|
+
constructor(timeout2) {
|
|
2719
|
+
super(`Node execution timed out after ${timeout2}ms`);
|
|
2720
|
+
this.name = "TimeoutError";
|
|
2721
|
+
}
|
|
2722
|
+
};
|
|
2723
|
+
function withTimeout(node, options) {
|
|
2724
|
+
const { timeout: timeout2, onTimeout, logTimeout, throwOnTimeout = false } = options;
|
|
2725
|
+
return async (state) => {
|
|
2726
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
2727
|
+
setTimeout(() => {
|
|
2728
|
+
reject(new TimeoutError(timeout2));
|
|
2729
|
+
}, timeout2);
|
|
2730
|
+
});
|
|
2731
|
+
try {
|
|
2732
|
+
return await Promise.race([Promise.resolve(node(state)), timeoutPromise]);
|
|
2733
|
+
} catch (error) {
|
|
2734
|
+
if (error instanceof TimeoutError) {
|
|
2735
|
+
if (logTimeout) {
|
|
2736
|
+
logTimeout(state);
|
|
2737
|
+
}
|
|
2738
|
+
if (throwOnTimeout) {
|
|
2739
|
+
throw error;
|
|
2740
|
+
}
|
|
2741
|
+
return await Promise.resolve(onTimeout(state));
|
|
2742
|
+
}
|
|
2743
|
+
throw error;
|
|
2744
|
+
}
|
|
2745
|
+
};
|
|
2746
|
+
}
|
|
2747
|
+
|
|
2748
|
+
// src/langgraph/middleware/preset-adapters.ts
|
|
2749
2749
|
function withRetry2(options) {
|
|
2750
2750
|
return (node) => withRetry(node, options);
|
|
2751
2751
|
}
|
|
@@ -2764,6 +2764,8 @@ function withTracing2(options) {
|
|
|
2764
2764
|
function withLogging2(options) {
|
|
2765
2765
|
return (node) => withLogging(options)(node);
|
|
2766
2766
|
}
|
|
2767
|
+
|
|
2768
|
+
// src/langgraph/middleware/preset-production.ts
|
|
2767
2769
|
function production(node, options) {
|
|
2768
2770
|
const {
|
|
2769
2771
|
nodeName,
|
|
@@ -2776,27 +2778,20 @@ function production(node, options) {
|
|
|
2776
2778
|
errorOptions = {}
|
|
2777
2779
|
} = options;
|
|
2778
2780
|
const actualLogger = logger6 || createLogger(nodeName, { level: "info" /* INFO */ });
|
|
2779
|
-
const middleware = [
|
|
2780
|
-
middleware.push(
|
|
2781
|
+
const middleware = [
|
|
2781
2782
|
withLogging2({
|
|
2782
2783
|
logger: actualLogger,
|
|
2783
2784
|
name: nodeName,
|
|
2784
2785
|
logInput: false,
|
|
2785
|
-
// Don't log input in production by default
|
|
2786
2786
|
logOutput: false,
|
|
2787
|
-
// Don't log output in production by default
|
|
2788
2787
|
logDuration: true,
|
|
2789
2788
|
logErrors: true
|
|
2790
|
-
})
|
|
2791
|
-
);
|
|
2792
|
-
middleware.push(
|
|
2789
|
+
}),
|
|
2793
2790
|
withErrorHandler2({
|
|
2794
|
-
onError: (
|
|
2795
|
-
return state;
|
|
2796
|
-
},
|
|
2791
|
+
onError: (_error, state) => state,
|
|
2797
2792
|
...errorOptions
|
|
2798
2793
|
})
|
|
2799
|
-
|
|
2794
|
+
];
|
|
2800
2795
|
if (enableRetry) {
|
|
2801
2796
|
middleware.push(
|
|
2802
2797
|
withRetry2({
|
|
@@ -2810,19 +2805,18 @@ function production(node, options) {
|
|
|
2810
2805
|
middleware.push(
|
|
2811
2806
|
withTimeout2({
|
|
2812
2807
|
timeout: timeout2,
|
|
2813
|
-
onTimeout: (state) =>
|
|
2814
|
-
return state;
|
|
2815
|
-
}
|
|
2808
|
+
onTimeout: (state) => state
|
|
2816
2809
|
})
|
|
2817
2810
|
);
|
|
2818
2811
|
if (enableMetrics) {
|
|
2812
|
+
const metricsOptions = {
|
|
2813
|
+
name: nodeName,
|
|
2814
|
+
trackDuration: true,
|
|
2815
|
+
trackErrors: true,
|
|
2816
|
+
trackInvocations: true
|
|
2817
|
+
};
|
|
2819
2818
|
middleware.push(
|
|
2820
|
-
withMetrics2(
|
|
2821
|
-
name: nodeName,
|
|
2822
|
-
trackDuration: true,
|
|
2823
|
-
trackErrors: true,
|
|
2824
|
-
trackInvocations: true
|
|
2825
|
-
})
|
|
2819
|
+
withMetrics2(metricsOptions)
|
|
2826
2820
|
);
|
|
2827
2821
|
}
|
|
2828
2822
|
if (enableTracing) {
|
|
@@ -2835,12 +2829,10 @@ function production(node, options) {
|
|
|
2835
2829
|
}
|
|
2836
2830
|
return compose(...middleware)(node);
|
|
2837
2831
|
}
|
|
2832
|
+
|
|
2833
|
+
// src/langgraph/middleware/preset-development.ts
|
|
2838
2834
|
function development(node, options) {
|
|
2839
|
-
const {
|
|
2840
|
-
nodeName,
|
|
2841
|
-
verbose = true,
|
|
2842
|
-
logger: logger6
|
|
2843
|
-
} = options;
|
|
2835
|
+
const { nodeName, verbose = true, logger: logger6 } = options;
|
|
2844
2836
|
const actualLogger = logger6 || createLogger(nodeName, { level: "debug" /* DEBUG */ });
|
|
2845
2837
|
return withLogging2({
|
|
2846
2838
|
logger: actualLogger,
|
|
@@ -2851,9 +2843,10 @@ function development(node, options) {
|
|
|
2851
2843
|
logErrors: true
|
|
2852
2844
|
})(node);
|
|
2853
2845
|
}
|
|
2846
|
+
|
|
2847
|
+
// src/langgraph/middleware/preset-testing.ts
|
|
2854
2848
|
function testing(node, options) {
|
|
2855
2849
|
const {
|
|
2856
|
-
nodeName,
|
|
2857
2850
|
mockResponse,
|
|
2858
2851
|
simulateError,
|
|
2859
2852
|
delay = 0,
|
|
@@ -2875,9 +2868,12 @@ function testing(node, options) {
|
|
|
2875
2868
|
}
|
|
2876
2869
|
return await Promise.resolve(node(state));
|
|
2877
2870
|
};
|
|
2878
|
-
|
|
2879
|
-
|
|
2871
|
+
const testingNode = wrappedNode;
|
|
2872
|
+
testingNode.invocations = invocations;
|
|
2873
|
+
return testingNode;
|
|
2880
2874
|
}
|
|
2875
|
+
|
|
2876
|
+
// src/langgraph/middleware/preset-collection.ts
|
|
2881
2877
|
var presets = {
|
|
2882
2878
|
production,
|
|
2883
2879
|
development,
|