@agentforge/core 0.16.50 → 0.16.52
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 +138 -134
- package/dist/index.d.cts +122 -291
- package/dist/index.d.ts +122 -291
- package/dist/index.js +138 -134
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2107,8 +2107,10 @@ function createToolSimulator(config) {
|
|
|
2107
2107
|
};
|
|
2108
2108
|
}
|
|
2109
2109
|
|
|
2110
|
-
// src/langgraph/state.ts
|
|
2110
|
+
// src/langgraph/state-annotation.ts
|
|
2111
2111
|
var import_langgraph = require("@langchain/langgraph");
|
|
2112
|
+
|
|
2113
|
+
// src/langgraph/state-shared.ts
|
|
2112
2114
|
function entriesOf(value) {
|
|
2113
2115
|
return Object.entries(value);
|
|
2114
2116
|
}
|
|
@@ -2127,6 +2129,8 @@ function setStateValue(target, key, value) {
|
|
|
2127
2129
|
function setStateDefinitionValue(target, key, value) {
|
|
2128
2130
|
target[key] = value;
|
|
2129
2131
|
}
|
|
2132
|
+
|
|
2133
|
+
// src/langgraph/state-annotation.ts
|
|
2130
2134
|
function createChannel(channelConfig) {
|
|
2131
2135
|
if (channelConfig.reducer) {
|
|
2132
2136
|
return (0, import_langgraph.Annotation)({
|
|
@@ -2153,6 +2157,8 @@ function createStateAnnotation(config) {
|
|
|
2153
2157
|
}
|
|
2154
2158
|
return import_langgraph.Annotation.Root(stateDefinition);
|
|
2155
2159
|
}
|
|
2160
|
+
|
|
2161
|
+
// src/langgraph/state-validation.ts
|
|
2156
2162
|
function validateState(state, config) {
|
|
2157
2163
|
const validated = {};
|
|
2158
2164
|
for (const [key, channelConfig] of entriesOf(config)) {
|
|
@@ -2170,6 +2176,8 @@ function validateState(state, config) {
|
|
|
2170
2176
|
}
|
|
2171
2177
|
return validated;
|
|
2172
2178
|
}
|
|
2179
|
+
|
|
2180
|
+
// src/langgraph/state-merge.ts
|
|
2173
2181
|
function mergeState(currentState, update, config) {
|
|
2174
2182
|
const merged = { ...currentState };
|
|
2175
2183
|
for (const key of keysOf(update)) {
|
|
@@ -2438,110 +2446,6 @@ function createMiddlewareContext() {
|
|
|
2438
2446
|
};
|
|
2439
2447
|
}
|
|
2440
2448
|
|
|
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
2449
|
// src/langgraph/observability/metrics.ts
|
|
2546
2450
|
var MetricType = /* @__PURE__ */ ((MetricType2) => {
|
|
2547
2451
|
MetricType2["COUNTER"] = "counter";
|
|
@@ -2686,6 +2590,26 @@ function withTracing(node, options) {
|
|
|
2686
2590
|
};
|
|
2687
2591
|
}
|
|
2688
2592
|
|
|
2593
|
+
// src/langgraph/middleware/error-handler.ts
|
|
2594
|
+
function withErrorHandler(node, options) {
|
|
2595
|
+
const { onError, logError, rethrow = false } = options;
|
|
2596
|
+
return async (state) => {
|
|
2597
|
+
try {
|
|
2598
|
+
return await Promise.resolve(node(state));
|
|
2599
|
+
} catch (error) {
|
|
2600
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
2601
|
+
if (logError) {
|
|
2602
|
+
logError(err, state);
|
|
2603
|
+
}
|
|
2604
|
+
const result = await Promise.resolve(onError(err, state));
|
|
2605
|
+
if (rethrow) {
|
|
2606
|
+
throw err;
|
|
2607
|
+
}
|
|
2608
|
+
return result;
|
|
2609
|
+
}
|
|
2610
|
+
};
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2689
2613
|
// src/langgraph/middleware/logging.ts
|
|
2690
2614
|
var withLogging = (options) => {
|
|
2691
2615
|
const {
|
|
@@ -2745,7 +2669,91 @@ var withLogging = (options) => {
|
|
|
2745
2669
|
};
|
|
2746
2670
|
};
|
|
2747
2671
|
|
|
2748
|
-
// src/langgraph/middleware/
|
|
2672
|
+
// src/langgraph/middleware/retry.ts
|
|
2673
|
+
function calculateDelay(attempt, strategy, initialDelay, maxDelay) {
|
|
2674
|
+
let delay;
|
|
2675
|
+
switch (strategy) {
|
|
2676
|
+
case "constant":
|
|
2677
|
+
delay = initialDelay;
|
|
2678
|
+
break;
|
|
2679
|
+
case "linear":
|
|
2680
|
+
delay = initialDelay * attempt;
|
|
2681
|
+
break;
|
|
2682
|
+
case "exponential":
|
|
2683
|
+
delay = initialDelay * Math.pow(2, attempt - 1);
|
|
2684
|
+
break;
|
|
2685
|
+
}
|
|
2686
|
+
return Math.min(delay, maxDelay);
|
|
2687
|
+
}
|
|
2688
|
+
function sleep(ms) {
|
|
2689
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2690
|
+
}
|
|
2691
|
+
function withRetry(node, options = {}) {
|
|
2692
|
+
const {
|
|
2693
|
+
maxAttempts = 3,
|
|
2694
|
+
backoff = "exponential",
|
|
2695
|
+
initialDelay = 1e3,
|
|
2696
|
+
maxDelay = 3e4,
|
|
2697
|
+
onRetry,
|
|
2698
|
+
shouldRetry = () => true
|
|
2699
|
+
} = options;
|
|
2700
|
+
return async (state) => {
|
|
2701
|
+
let lastError;
|
|
2702
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
2703
|
+
try {
|
|
2704
|
+
return await Promise.resolve(node(state));
|
|
2705
|
+
} catch (error) {
|
|
2706
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
2707
|
+
if (!shouldRetry(lastError)) {
|
|
2708
|
+
throw lastError;
|
|
2709
|
+
}
|
|
2710
|
+
if (attempt === maxAttempts) {
|
|
2711
|
+
throw lastError;
|
|
2712
|
+
}
|
|
2713
|
+
if (onRetry) {
|
|
2714
|
+
onRetry(lastError, attempt);
|
|
2715
|
+
}
|
|
2716
|
+
const delay = calculateDelay(attempt, backoff, initialDelay, maxDelay);
|
|
2717
|
+
await sleep(delay);
|
|
2718
|
+
}
|
|
2719
|
+
}
|
|
2720
|
+
throw lastError || new Error("Retry failed");
|
|
2721
|
+
};
|
|
2722
|
+
}
|
|
2723
|
+
|
|
2724
|
+
// src/langgraph/middleware/timeout.ts
|
|
2725
|
+
var TimeoutError = class extends Error {
|
|
2726
|
+
constructor(timeout2) {
|
|
2727
|
+
super(`Node execution timed out after ${timeout2}ms`);
|
|
2728
|
+
this.name = "TimeoutError";
|
|
2729
|
+
}
|
|
2730
|
+
};
|
|
2731
|
+
function withTimeout(node, options) {
|
|
2732
|
+
const { timeout: timeout2, onTimeout, logTimeout, throwOnTimeout = false } = options;
|
|
2733
|
+
return async (state) => {
|
|
2734
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
2735
|
+
setTimeout(() => {
|
|
2736
|
+
reject(new TimeoutError(timeout2));
|
|
2737
|
+
}, timeout2);
|
|
2738
|
+
});
|
|
2739
|
+
try {
|
|
2740
|
+
return await Promise.race([Promise.resolve(node(state)), timeoutPromise]);
|
|
2741
|
+
} catch (error) {
|
|
2742
|
+
if (error instanceof TimeoutError) {
|
|
2743
|
+
if (logTimeout) {
|
|
2744
|
+
logTimeout(state);
|
|
2745
|
+
}
|
|
2746
|
+
if (throwOnTimeout) {
|
|
2747
|
+
throw error;
|
|
2748
|
+
}
|
|
2749
|
+
return await Promise.resolve(onTimeout(state));
|
|
2750
|
+
}
|
|
2751
|
+
throw error;
|
|
2752
|
+
}
|
|
2753
|
+
};
|
|
2754
|
+
}
|
|
2755
|
+
|
|
2756
|
+
// src/langgraph/middleware/preset-adapters.ts
|
|
2749
2757
|
function withRetry2(options) {
|
|
2750
2758
|
return (node) => withRetry(node, options);
|
|
2751
2759
|
}
|
|
@@ -2764,6 +2772,8 @@ function withTracing2(options) {
|
|
|
2764
2772
|
function withLogging2(options) {
|
|
2765
2773
|
return (node) => withLogging(options)(node);
|
|
2766
2774
|
}
|
|
2775
|
+
|
|
2776
|
+
// src/langgraph/middleware/preset-production.ts
|
|
2767
2777
|
function production(node, options) {
|
|
2768
2778
|
const {
|
|
2769
2779
|
nodeName,
|
|
@@ -2776,27 +2786,20 @@ function production(node, options) {
|
|
|
2776
2786
|
errorOptions = {}
|
|
2777
2787
|
} = options;
|
|
2778
2788
|
const actualLogger = logger6 || createLogger(nodeName, { level: "info" /* INFO */ });
|
|
2779
|
-
const middleware = [
|
|
2780
|
-
middleware.push(
|
|
2789
|
+
const middleware = [
|
|
2781
2790
|
withLogging2({
|
|
2782
2791
|
logger: actualLogger,
|
|
2783
2792
|
name: nodeName,
|
|
2784
2793
|
logInput: false,
|
|
2785
|
-
// Don't log input in production by default
|
|
2786
2794
|
logOutput: false,
|
|
2787
|
-
// Don't log output in production by default
|
|
2788
2795
|
logDuration: true,
|
|
2789
2796
|
logErrors: true
|
|
2790
|
-
})
|
|
2791
|
-
);
|
|
2792
|
-
middleware.push(
|
|
2797
|
+
}),
|
|
2793
2798
|
withErrorHandler2({
|
|
2794
|
-
onError: (
|
|
2795
|
-
return state;
|
|
2796
|
-
},
|
|
2799
|
+
onError: (_error, state) => state,
|
|
2797
2800
|
...errorOptions
|
|
2798
2801
|
})
|
|
2799
|
-
|
|
2802
|
+
];
|
|
2800
2803
|
if (enableRetry) {
|
|
2801
2804
|
middleware.push(
|
|
2802
2805
|
withRetry2({
|
|
@@ -2810,19 +2813,18 @@ function production(node, options) {
|
|
|
2810
2813
|
middleware.push(
|
|
2811
2814
|
withTimeout2({
|
|
2812
2815
|
timeout: timeout2,
|
|
2813
|
-
onTimeout: (state) =>
|
|
2814
|
-
return state;
|
|
2815
|
-
}
|
|
2816
|
+
onTimeout: (state) => state
|
|
2816
2817
|
})
|
|
2817
2818
|
);
|
|
2818
2819
|
if (enableMetrics) {
|
|
2820
|
+
const metricsOptions = {
|
|
2821
|
+
name: nodeName,
|
|
2822
|
+
trackDuration: true,
|
|
2823
|
+
trackErrors: true,
|
|
2824
|
+
trackInvocations: true
|
|
2825
|
+
};
|
|
2819
2826
|
middleware.push(
|
|
2820
|
-
withMetrics2(
|
|
2821
|
-
name: nodeName,
|
|
2822
|
-
trackDuration: true,
|
|
2823
|
-
trackErrors: true,
|
|
2824
|
-
trackInvocations: true
|
|
2825
|
-
})
|
|
2827
|
+
withMetrics2(metricsOptions)
|
|
2826
2828
|
);
|
|
2827
2829
|
}
|
|
2828
2830
|
if (enableTracing) {
|
|
@@ -2835,12 +2837,10 @@ function production(node, options) {
|
|
|
2835
2837
|
}
|
|
2836
2838
|
return compose(...middleware)(node);
|
|
2837
2839
|
}
|
|
2840
|
+
|
|
2841
|
+
// src/langgraph/middleware/preset-development.ts
|
|
2838
2842
|
function development(node, options) {
|
|
2839
|
-
const {
|
|
2840
|
-
nodeName,
|
|
2841
|
-
verbose = true,
|
|
2842
|
-
logger: logger6
|
|
2843
|
-
} = options;
|
|
2843
|
+
const { nodeName, verbose = true, logger: logger6 } = options;
|
|
2844
2844
|
const actualLogger = logger6 || createLogger(nodeName, { level: "debug" /* DEBUG */ });
|
|
2845
2845
|
return withLogging2({
|
|
2846
2846
|
logger: actualLogger,
|
|
@@ -2851,9 +2851,10 @@ function development(node, options) {
|
|
|
2851
2851
|
logErrors: true
|
|
2852
2852
|
})(node);
|
|
2853
2853
|
}
|
|
2854
|
+
|
|
2855
|
+
// src/langgraph/middleware/preset-testing.ts
|
|
2854
2856
|
function testing(node, options) {
|
|
2855
2857
|
const {
|
|
2856
|
-
nodeName,
|
|
2857
2858
|
mockResponse,
|
|
2858
2859
|
simulateError,
|
|
2859
2860
|
delay = 0,
|
|
@@ -2875,9 +2876,12 @@ function testing(node, options) {
|
|
|
2875
2876
|
}
|
|
2876
2877
|
return await Promise.resolve(node(state));
|
|
2877
2878
|
};
|
|
2878
|
-
|
|
2879
|
-
|
|
2879
|
+
const testingNode = wrappedNode;
|
|
2880
|
+
testingNode.invocations = invocations;
|
|
2881
|
+
return testingNode;
|
|
2880
2882
|
}
|
|
2883
|
+
|
|
2884
|
+
// src/langgraph/middleware/preset-collection.ts
|
|
2881
2885
|
var presets = {
|
|
2882
2886
|
production,
|
|
2883
2887
|
development,
|