@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.js
CHANGED
|
@@ -1932,8 +1932,10 @@ function createToolSimulator(config) {
|
|
|
1932
1932
|
};
|
|
1933
1933
|
}
|
|
1934
1934
|
|
|
1935
|
-
// src/langgraph/state.ts
|
|
1935
|
+
// src/langgraph/state-annotation.ts
|
|
1936
1936
|
import { Annotation } from "@langchain/langgraph";
|
|
1937
|
+
|
|
1938
|
+
// src/langgraph/state-shared.ts
|
|
1937
1939
|
function entriesOf(value) {
|
|
1938
1940
|
return Object.entries(value);
|
|
1939
1941
|
}
|
|
@@ -1952,6 +1954,8 @@ function setStateValue(target, key, value) {
|
|
|
1952
1954
|
function setStateDefinitionValue(target, key, value) {
|
|
1953
1955
|
target[key] = value;
|
|
1954
1956
|
}
|
|
1957
|
+
|
|
1958
|
+
// src/langgraph/state-annotation.ts
|
|
1955
1959
|
function createChannel(channelConfig) {
|
|
1956
1960
|
if (channelConfig.reducer) {
|
|
1957
1961
|
return Annotation({
|
|
@@ -1978,6 +1982,8 @@ function createStateAnnotation(config) {
|
|
|
1978
1982
|
}
|
|
1979
1983
|
return Annotation.Root(stateDefinition);
|
|
1980
1984
|
}
|
|
1985
|
+
|
|
1986
|
+
// src/langgraph/state-validation.ts
|
|
1981
1987
|
function validateState(state, config) {
|
|
1982
1988
|
const validated = {};
|
|
1983
1989
|
for (const [key, channelConfig] of entriesOf(config)) {
|
|
@@ -1995,6 +2001,8 @@ function validateState(state, config) {
|
|
|
1995
2001
|
}
|
|
1996
2002
|
return validated;
|
|
1997
2003
|
}
|
|
2004
|
+
|
|
2005
|
+
// src/langgraph/state-merge.ts
|
|
1998
2006
|
function mergeState(currentState, update, config) {
|
|
1999
2007
|
const merged = { ...currentState };
|
|
2000
2008
|
for (const key of keysOf(update)) {
|
|
@@ -2263,110 +2271,6 @@ function createMiddlewareContext() {
|
|
|
2263
2271
|
};
|
|
2264
2272
|
}
|
|
2265
2273
|
|
|
2266
|
-
// src/langgraph/middleware/retry.ts
|
|
2267
|
-
function calculateDelay(attempt, strategy, initialDelay, maxDelay) {
|
|
2268
|
-
let delay;
|
|
2269
|
-
switch (strategy) {
|
|
2270
|
-
case "constant":
|
|
2271
|
-
delay = initialDelay;
|
|
2272
|
-
break;
|
|
2273
|
-
case "linear":
|
|
2274
|
-
delay = initialDelay * attempt;
|
|
2275
|
-
break;
|
|
2276
|
-
case "exponential":
|
|
2277
|
-
delay = initialDelay * Math.pow(2, attempt - 1);
|
|
2278
|
-
break;
|
|
2279
|
-
}
|
|
2280
|
-
return Math.min(delay, maxDelay);
|
|
2281
|
-
}
|
|
2282
|
-
function sleep(ms) {
|
|
2283
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2284
|
-
}
|
|
2285
|
-
function withRetry(node, options = {}) {
|
|
2286
|
-
const {
|
|
2287
|
-
maxAttempts = 3,
|
|
2288
|
-
backoff = "exponential",
|
|
2289
|
-
initialDelay = 1e3,
|
|
2290
|
-
maxDelay = 3e4,
|
|
2291
|
-
onRetry,
|
|
2292
|
-
shouldRetry = () => true
|
|
2293
|
-
} = options;
|
|
2294
|
-
return async (state) => {
|
|
2295
|
-
let lastError;
|
|
2296
|
-
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
2297
|
-
try {
|
|
2298
|
-
return await Promise.resolve(node(state));
|
|
2299
|
-
} catch (error) {
|
|
2300
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
2301
|
-
if (!shouldRetry(lastError)) {
|
|
2302
|
-
throw lastError;
|
|
2303
|
-
}
|
|
2304
|
-
if (attempt === maxAttempts) {
|
|
2305
|
-
throw lastError;
|
|
2306
|
-
}
|
|
2307
|
-
if (onRetry) {
|
|
2308
|
-
onRetry(lastError, attempt);
|
|
2309
|
-
}
|
|
2310
|
-
const delay = calculateDelay(attempt, backoff, initialDelay, maxDelay);
|
|
2311
|
-
await sleep(delay);
|
|
2312
|
-
}
|
|
2313
|
-
}
|
|
2314
|
-
throw lastError || new Error("Retry failed");
|
|
2315
|
-
};
|
|
2316
|
-
}
|
|
2317
|
-
|
|
2318
|
-
// src/langgraph/middleware/error-handler.ts
|
|
2319
|
-
function withErrorHandler(node, options) {
|
|
2320
|
-
const { onError, logError, rethrow = false } = options;
|
|
2321
|
-
return async (state) => {
|
|
2322
|
-
try {
|
|
2323
|
-
return await Promise.resolve(node(state));
|
|
2324
|
-
} catch (error) {
|
|
2325
|
-
const err = error instanceof Error ? error : new Error(String(error));
|
|
2326
|
-
if (logError) {
|
|
2327
|
-
logError(err, state);
|
|
2328
|
-
}
|
|
2329
|
-
const result = await Promise.resolve(onError(err, state));
|
|
2330
|
-
if (rethrow) {
|
|
2331
|
-
throw err;
|
|
2332
|
-
}
|
|
2333
|
-
return result;
|
|
2334
|
-
}
|
|
2335
|
-
};
|
|
2336
|
-
}
|
|
2337
|
-
|
|
2338
|
-
// src/langgraph/middleware/timeout.ts
|
|
2339
|
-
var TimeoutError = class extends Error {
|
|
2340
|
-
constructor(timeout2) {
|
|
2341
|
-
super(`Node execution timed out after ${timeout2}ms`);
|
|
2342
|
-
this.name = "TimeoutError";
|
|
2343
|
-
}
|
|
2344
|
-
};
|
|
2345
|
-
function withTimeout(node, options) {
|
|
2346
|
-
const { timeout: timeout2, onTimeout, logTimeout, throwOnTimeout = false } = options;
|
|
2347
|
-
return async (state) => {
|
|
2348
|
-
const timeoutPromise = new Promise((_, reject) => {
|
|
2349
|
-
setTimeout(() => {
|
|
2350
|
-
reject(new TimeoutError(timeout2));
|
|
2351
|
-
}, timeout2);
|
|
2352
|
-
});
|
|
2353
|
-
try {
|
|
2354
|
-
return await Promise.race([Promise.resolve(node(state)), timeoutPromise]);
|
|
2355
|
-
} catch (error) {
|
|
2356
|
-
if (error instanceof TimeoutError) {
|
|
2357
|
-
if (logTimeout) {
|
|
2358
|
-
logTimeout(state);
|
|
2359
|
-
}
|
|
2360
|
-
if (throwOnTimeout) {
|
|
2361
|
-
throw error;
|
|
2362
|
-
}
|
|
2363
|
-
return await Promise.resolve(onTimeout(state));
|
|
2364
|
-
}
|
|
2365
|
-
throw error;
|
|
2366
|
-
}
|
|
2367
|
-
};
|
|
2368
|
-
}
|
|
2369
|
-
|
|
2370
2274
|
// src/langgraph/observability/metrics.ts
|
|
2371
2275
|
var MetricType = /* @__PURE__ */ ((MetricType2) => {
|
|
2372
2276
|
MetricType2["COUNTER"] = "counter";
|
|
@@ -2511,6 +2415,26 @@ function withTracing(node, options) {
|
|
|
2511
2415
|
};
|
|
2512
2416
|
}
|
|
2513
2417
|
|
|
2418
|
+
// src/langgraph/middleware/error-handler.ts
|
|
2419
|
+
function withErrorHandler(node, options) {
|
|
2420
|
+
const { onError, logError, rethrow = false } = options;
|
|
2421
|
+
return async (state) => {
|
|
2422
|
+
try {
|
|
2423
|
+
return await Promise.resolve(node(state));
|
|
2424
|
+
} catch (error) {
|
|
2425
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
2426
|
+
if (logError) {
|
|
2427
|
+
logError(err, state);
|
|
2428
|
+
}
|
|
2429
|
+
const result = await Promise.resolve(onError(err, state));
|
|
2430
|
+
if (rethrow) {
|
|
2431
|
+
throw err;
|
|
2432
|
+
}
|
|
2433
|
+
return result;
|
|
2434
|
+
}
|
|
2435
|
+
};
|
|
2436
|
+
}
|
|
2437
|
+
|
|
2514
2438
|
// src/langgraph/middleware/logging.ts
|
|
2515
2439
|
var withLogging = (options) => {
|
|
2516
2440
|
const {
|
|
@@ -2570,7 +2494,91 @@ var withLogging = (options) => {
|
|
|
2570
2494
|
};
|
|
2571
2495
|
};
|
|
2572
2496
|
|
|
2573
|
-
// src/langgraph/middleware/
|
|
2497
|
+
// src/langgraph/middleware/retry.ts
|
|
2498
|
+
function calculateDelay(attempt, strategy, initialDelay, maxDelay) {
|
|
2499
|
+
let delay;
|
|
2500
|
+
switch (strategy) {
|
|
2501
|
+
case "constant":
|
|
2502
|
+
delay = initialDelay;
|
|
2503
|
+
break;
|
|
2504
|
+
case "linear":
|
|
2505
|
+
delay = initialDelay * attempt;
|
|
2506
|
+
break;
|
|
2507
|
+
case "exponential":
|
|
2508
|
+
delay = initialDelay * Math.pow(2, attempt - 1);
|
|
2509
|
+
break;
|
|
2510
|
+
}
|
|
2511
|
+
return Math.min(delay, maxDelay);
|
|
2512
|
+
}
|
|
2513
|
+
function sleep(ms) {
|
|
2514
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2515
|
+
}
|
|
2516
|
+
function withRetry(node, options = {}) {
|
|
2517
|
+
const {
|
|
2518
|
+
maxAttempts = 3,
|
|
2519
|
+
backoff = "exponential",
|
|
2520
|
+
initialDelay = 1e3,
|
|
2521
|
+
maxDelay = 3e4,
|
|
2522
|
+
onRetry,
|
|
2523
|
+
shouldRetry = () => true
|
|
2524
|
+
} = options;
|
|
2525
|
+
return async (state) => {
|
|
2526
|
+
let lastError;
|
|
2527
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
2528
|
+
try {
|
|
2529
|
+
return await Promise.resolve(node(state));
|
|
2530
|
+
} catch (error) {
|
|
2531
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
2532
|
+
if (!shouldRetry(lastError)) {
|
|
2533
|
+
throw lastError;
|
|
2534
|
+
}
|
|
2535
|
+
if (attempt === maxAttempts) {
|
|
2536
|
+
throw lastError;
|
|
2537
|
+
}
|
|
2538
|
+
if (onRetry) {
|
|
2539
|
+
onRetry(lastError, attempt);
|
|
2540
|
+
}
|
|
2541
|
+
const delay = calculateDelay(attempt, backoff, initialDelay, maxDelay);
|
|
2542
|
+
await sleep(delay);
|
|
2543
|
+
}
|
|
2544
|
+
}
|
|
2545
|
+
throw lastError || new Error("Retry failed");
|
|
2546
|
+
};
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
// src/langgraph/middleware/timeout.ts
|
|
2550
|
+
var TimeoutError = class extends Error {
|
|
2551
|
+
constructor(timeout2) {
|
|
2552
|
+
super(`Node execution timed out after ${timeout2}ms`);
|
|
2553
|
+
this.name = "TimeoutError";
|
|
2554
|
+
}
|
|
2555
|
+
};
|
|
2556
|
+
function withTimeout(node, options) {
|
|
2557
|
+
const { timeout: timeout2, onTimeout, logTimeout, throwOnTimeout = false } = options;
|
|
2558
|
+
return async (state) => {
|
|
2559
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
2560
|
+
setTimeout(() => {
|
|
2561
|
+
reject(new TimeoutError(timeout2));
|
|
2562
|
+
}, timeout2);
|
|
2563
|
+
});
|
|
2564
|
+
try {
|
|
2565
|
+
return await Promise.race([Promise.resolve(node(state)), timeoutPromise]);
|
|
2566
|
+
} catch (error) {
|
|
2567
|
+
if (error instanceof TimeoutError) {
|
|
2568
|
+
if (logTimeout) {
|
|
2569
|
+
logTimeout(state);
|
|
2570
|
+
}
|
|
2571
|
+
if (throwOnTimeout) {
|
|
2572
|
+
throw error;
|
|
2573
|
+
}
|
|
2574
|
+
return await Promise.resolve(onTimeout(state));
|
|
2575
|
+
}
|
|
2576
|
+
throw error;
|
|
2577
|
+
}
|
|
2578
|
+
};
|
|
2579
|
+
}
|
|
2580
|
+
|
|
2581
|
+
// src/langgraph/middleware/preset-adapters.ts
|
|
2574
2582
|
function withRetry2(options) {
|
|
2575
2583
|
return (node) => withRetry(node, options);
|
|
2576
2584
|
}
|
|
@@ -2589,6 +2597,8 @@ function withTracing2(options) {
|
|
|
2589
2597
|
function withLogging2(options) {
|
|
2590
2598
|
return (node) => withLogging(options)(node);
|
|
2591
2599
|
}
|
|
2600
|
+
|
|
2601
|
+
// src/langgraph/middleware/preset-production.ts
|
|
2592
2602
|
function production(node, options) {
|
|
2593
2603
|
const {
|
|
2594
2604
|
nodeName,
|
|
@@ -2601,27 +2611,20 @@ function production(node, options) {
|
|
|
2601
2611
|
errorOptions = {}
|
|
2602
2612
|
} = options;
|
|
2603
2613
|
const actualLogger = logger6 || createLogger(nodeName, { level: "info" /* INFO */ });
|
|
2604
|
-
const middleware = [
|
|
2605
|
-
middleware.push(
|
|
2614
|
+
const middleware = [
|
|
2606
2615
|
withLogging2({
|
|
2607
2616
|
logger: actualLogger,
|
|
2608
2617
|
name: nodeName,
|
|
2609
2618
|
logInput: false,
|
|
2610
|
-
// Don't log input in production by default
|
|
2611
2619
|
logOutput: false,
|
|
2612
|
-
// Don't log output in production by default
|
|
2613
2620
|
logDuration: true,
|
|
2614
2621
|
logErrors: true
|
|
2615
|
-
})
|
|
2616
|
-
);
|
|
2617
|
-
middleware.push(
|
|
2622
|
+
}),
|
|
2618
2623
|
withErrorHandler2({
|
|
2619
|
-
onError: (
|
|
2620
|
-
return state;
|
|
2621
|
-
},
|
|
2624
|
+
onError: (_error, state) => state,
|
|
2622
2625
|
...errorOptions
|
|
2623
2626
|
})
|
|
2624
|
-
|
|
2627
|
+
];
|
|
2625
2628
|
if (enableRetry) {
|
|
2626
2629
|
middleware.push(
|
|
2627
2630
|
withRetry2({
|
|
@@ -2635,19 +2638,18 @@ function production(node, options) {
|
|
|
2635
2638
|
middleware.push(
|
|
2636
2639
|
withTimeout2({
|
|
2637
2640
|
timeout: timeout2,
|
|
2638
|
-
onTimeout: (state) =>
|
|
2639
|
-
return state;
|
|
2640
|
-
}
|
|
2641
|
+
onTimeout: (state) => state
|
|
2641
2642
|
})
|
|
2642
2643
|
);
|
|
2643
2644
|
if (enableMetrics) {
|
|
2645
|
+
const metricsOptions = {
|
|
2646
|
+
name: nodeName,
|
|
2647
|
+
trackDuration: true,
|
|
2648
|
+
trackErrors: true,
|
|
2649
|
+
trackInvocations: true
|
|
2650
|
+
};
|
|
2644
2651
|
middleware.push(
|
|
2645
|
-
withMetrics2(
|
|
2646
|
-
name: nodeName,
|
|
2647
|
-
trackDuration: true,
|
|
2648
|
-
trackErrors: true,
|
|
2649
|
-
trackInvocations: true
|
|
2650
|
-
})
|
|
2652
|
+
withMetrics2(metricsOptions)
|
|
2651
2653
|
);
|
|
2652
2654
|
}
|
|
2653
2655
|
if (enableTracing) {
|
|
@@ -2660,12 +2662,10 @@ function production(node, options) {
|
|
|
2660
2662
|
}
|
|
2661
2663
|
return compose(...middleware)(node);
|
|
2662
2664
|
}
|
|
2665
|
+
|
|
2666
|
+
// src/langgraph/middleware/preset-development.ts
|
|
2663
2667
|
function development(node, options) {
|
|
2664
|
-
const {
|
|
2665
|
-
nodeName,
|
|
2666
|
-
verbose = true,
|
|
2667
|
-
logger: logger6
|
|
2668
|
-
} = options;
|
|
2668
|
+
const { nodeName, verbose = true, logger: logger6 } = options;
|
|
2669
2669
|
const actualLogger = logger6 || createLogger(nodeName, { level: "debug" /* DEBUG */ });
|
|
2670
2670
|
return withLogging2({
|
|
2671
2671
|
logger: actualLogger,
|
|
@@ -2676,9 +2676,10 @@ function development(node, options) {
|
|
|
2676
2676
|
logErrors: true
|
|
2677
2677
|
})(node);
|
|
2678
2678
|
}
|
|
2679
|
+
|
|
2680
|
+
// src/langgraph/middleware/preset-testing.ts
|
|
2679
2681
|
function testing(node, options) {
|
|
2680
2682
|
const {
|
|
2681
|
-
nodeName,
|
|
2682
2683
|
mockResponse,
|
|
2683
2684
|
simulateError,
|
|
2684
2685
|
delay = 0,
|
|
@@ -2700,9 +2701,12 @@ function testing(node, options) {
|
|
|
2700
2701
|
}
|
|
2701
2702
|
return await Promise.resolve(node(state));
|
|
2702
2703
|
};
|
|
2703
|
-
|
|
2704
|
-
|
|
2704
|
+
const testingNode = wrappedNode;
|
|
2705
|
+
testingNode.invocations = invocations;
|
|
2706
|
+
return testingNode;
|
|
2705
2707
|
}
|
|
2708
|
+
|
|
2709
|
+
// src/langgraph/middleware/preset-collection.ts
|
|
2706
2710
|
var presets = {
|
|
2707
2711
|
production,
|
|
2708
2712
|
development,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentforge/core",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.52",
|
|
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",
|