@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.js
CHANGED
|
@@ -2263,110 +2263,6 @@ function createMiddlewareContext() {
|
|
|
2263
2263
|
};
|
|
2264
2264
|
}
|
|
2265
2265
|
|
|
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
2266
|
// src/langgraph/observability/metrics.ts
|
|
2371
2267
|
var MetricType = /* @__PURE__ */ ((MetricType2) => {
|
|
2372
2268
|
MetricType2["COUNTER"] = "counter";
|
|
@@ -2511,6 +2407,26 @@ function withTracing(node, options) {
|
|
|
2511
2407
|
};
|
|
2512
2408
|
}
|
|
2513
2409
|
|
|
2410
|
+
// src/langgraph/middleware/error-handler.ts
|
|
2411
|
+
function withErrorHandler(node, options) {
|
|
2412
|
+
const { onError, logError, rethrow = false } = options;
|
|
2413
|
+
return async (state) => {
|
|
2414
|
+
try {
|
|
2415
|
+
return await Promise.resolve(node(state));
|
|
2416
|
+
} catch (error) {
|
|
2417
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
2418
|
+
if (logError) {
|
|
2419
|
+
logError(err, state);
|
|
2420
|
+
}
|
|
2421
|
+
const result = await Promise.resolve(onError(err, state));
|
|
2422
|
+
if (rethrow) {
|
|
2423
|
+
throw err;
|
|
2424
|
+
}
|
|
2425
|
+
return result;
|
|
2426
|
+
}
|
|
2427
|
+
};
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2514
2430
|
// src/langgraph/middleware/logging.ts
|
|
2515
2431
|
var withLogging = (options) => {
|
|
2516
2432
|
const {
|
|
@@ -2570,7 +2486,91 @@ var withLogging = (options) => {
|
|
|
2570
2486
|
};
|
|
2571
2487
|
};
|
|
2572
2488
|
|
|
2573
|
-
// src/langgraph/middleware/
|
|
2489
|
+
// src/langgraph/middleware/retry.ts
|
|
2490
|
+
function calculateDelay(attempt, strategy, initialDelay, maxDelay) {
|
|
2491
|
+
let delay;
|
|
2492
|
+
switch (strategy) {
|
|
2493
|
+
case "constant":
|
|
2494
|
+
delay = initialDelay;
|
|
2495
|
+
break;
|
|
2496
|
+
case "linear":
|
|
2497
|
+
delay = initialDelay * attempt;
|
|
2498
|
+
break;
|
|
2499
|
+
case "exponential":
|
|
2500
|
+
delay = initialDelay * Math.pow(2, attempt - 1);
|
|
2501
|
+
break;
|
|
2502
|
+
}
|
|
2503
|
+
return Math.min(delay, maxDelay);
|
|
2504
|
+
}
|
|
2505
|
+
function sleep(ms) {
|
|
2506
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
2507
|
+
}
|
|
2508
|
+
function withRetry(node, options = {}) {
|
|
2509
|
+
const {
|
|
2510
|
+
maxAttempts = 3,
|
|
2511
|
+
backoff = "exponential",
|
|
2512
|
+
initialDelay = 1e3,
|
|
2513
|
+
maxDelay = 3e4,
|
|
2514
|
+
onRetry,
|
|
2515
|
+
shouldRetry = () => true
|
|
2516
|
+
} = options;
|
|
2517
|
+
return async (state) => {
|
|
2518
|
+
let lastError;
|
|
2519
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
2520
|
+
try {
|
|
2521
|
+
return await Promise.resolve(node(state));
|
|
2522
|
+
} catch (error) {
|
|
2523
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
2524
|
+
if (!shouldRetry(lastError)) {
|
|
2525
|
+
throw lastError;
|
|
2526
|
+
}
|
|
2527
|
+
if (attempt === maxAttempts) {
|
|
2528
|
+
throw lastError;
|
|
2529
|
+
}
|
|
2530
|
+
if (onRetry) {
|
|
2531
|
+
onRetry(lastError, attempt);
|
|
2532
|
+
}
|
|
2533
|
+
const delay = calculateDelay(attempt, backoff, initialDelay, maxDelay);
|
|
2534
|
+
await sleep(delay);
|
|
2535
|
+
}
|
|
2536
|
+
}
|
|
2537
|
+
throw lastError || new Error("Retry failed");
|
|
2538
|
+
};
|
|
2539
|
+
}
|
|
2540
|
+
|
|
2541
|
+
// src/langgraph/middleware/timeout.ts
|
|
2542
|
+
var TimeoutError = class extends Error {
|
|
2543
|
+
constructor(timeout2) {
|
|
2544
|
+
super(`Node execution timed out after ${timeout2}ms`);
|
|
2545
|
+
this.name = "TimeoutError";
|
|
2546
|
+
}
|
|
2547
|
+
};
|
|
2548
|
+
function withTimeout(node, options) {
|
|
2549
|
+
const { timeout: timeout2, onTimeout, logTimeout, throwOnTimeout = false } = options;
|
|
2550
|
+
return async (state) => {
|
|
2551
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
2552
|
+
setTimeout(() => {
|
|
2553
|
+
reject(new TimeoutError(timeout2));
|
|
2554
|
+
}, timeout2);
|
|
2555
|
+
});
|
|
2556
|
+
try {
|
|
2557
|
+
return await Promise.race([Promise.resolve(node(state)), timeoutPromise]);
|
|
2558
|
+
} catch (error) {
|
|
2559
|
+
if (error instanceof TimeoutError) {
|
|
2560
|
+
if (logTimeout) {
|
|
2561
|
+
logTimeout(state);
|
|
2562
|
+
}
|
|
2563
|
+
if (throwOnTimeout) {
|
|
2564
|
+
throw error;
|
|
2565
|
+
}
|
|
2566
|
+
return await Promise.resolve(onTimeout(state));
|
|
2567
|
+
}
|
|
2568
|
+
throw error;
|
|
2569
|
+
}
|
|
2570
|
+
};
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2573
|
+
// src/langgraph/middleware/preset-adapters.ts
|
|
2574
2574
|
function withRetry2(options) {
|
|
2575
2575
|
return (node) => withRetry(node, options);
|
|
2576
2576
|
}
|
|
@@ -2589,6 +2589,8 @@ function withTracing2(options) {
|
|
|
2589
2589
|
function withLogging2(options) {
|
|
2590
2590
|
return (node) => withLogging(options)(node);
|
|
2591
2591
|
}
|
|
2592
|
+
|
|
2593
|
+
// src/langgraph/middleware/preset-production.ts
|
|
2592
2594
|
function production(node, options) {
|
|
2593
2595
|
const {
|
|
2594
2596
|
nodeName,
|
|
@@ -2601,27 +2603,20 @@ function production(node, options) {
|
|
|
2601
2603
|
errorOptions = {}
|
|
2602
2604
|
} = options;
|
|
2603
2605
|
const actualLogger = logger6 || createLogger(nodeName, { level: "info" /* INFO */ });
|
|
2604
|
-
const middleware = [
|
|
2605
|
-
middleware.push(
|
|
2606
|
+
const middleware = [
|
|
2606
2607
|
withLogging2({
|
|
2607
2608
|
logger: actualLogger,
|
|
2608
2609
|
name: nodeName,
|
|
2609
2610
|
logInput: false,
|
|
2610
|
-
// Don't log input in production by default
|
|
2611
2611
|
logOutput: false,
|
|
2612
|
-
// Don't log output in production by default
|
|
2613
2612
|
logDuration: true,
|
|
2614
2613
|
logErrors: true
|
|
2615
|
-
})
|
|
2616
|
-
);
|
|
2617
|
-
middleware.push(
|
|
2614
|
+
}),
|
|
2618
2615
|
withErrorHandler2({
|
|
2619
|
-
onError: (
|
|
2620
|
-
return state;
|
|
2621
|
-
},
|
|
2616
|
+
onError: (_error, state) => state,
|
|
2622
2617
|
...errorOptions
|
|
2623
2618
|
})
|
|
2624
|
-
|
|
2619
|
+
];
|
|
2625
2620
|
if (enableRetry) {
|
|
2626
2621
|
middleware.push(
|
|
2627
2622
|
withRetry2({
|
|
@@ -2635,19 +2630,18 @@ function production(node, options) {
|
|
|
2635
2630
|
middleware.push(
|
|
2636
2631
|
withTimeout2({
|
|
2637
2632
|
timeout: timeout2,
|
|
2638
|
-
onTimeout: (state) =>
|
|
2639
|
-
return state;
|
|
2640
|
-
}
|
|
2633
|
+
onTimeout: (state) => state
|
|
2641
2634
|
})
|
|
2642
2635
|
);
|
|
2643
2636
|
if (enableMetrics) {
|
|
2637
|
+
const metricsOptions = {
|
|
2638
|
+
name: nodeName,
|
|
2639
|
+
trackDuration: true,
|
|
2640
|
+
trackErrors: true,
|
|
2641
|
+
trackInvocations: true
|
|
2642
|
+
};
|
|
2644
2643
|
middleware.push(
|
|
2645
|
-
withMetrics2(
|
|
2646
|
-
name: nodeName,
|
|
2647
|
-
trackDuration: true,
|
|
2648
|
-
trackErrors: true,
|
|
2649
|
-
trackInvocations: true
|
|
2650
|
-
})
|
|
2644
|
+
withMetrics2(metricsOptions)
|
|
2651
2645
|
);
|
|
2652
2646
|
}
|
|
2653
2647
|
if (enableTracing) {
|
|
@@ -2660,12 +2654,10 @@ function production(node, options) {
|
|
|
2660
2654
|
}
|
|
2661
2655
|
return compose(...middleware)(node);
|
|
2662
2656
|
}
|
|
2657
|
+
|
|
2658
|
+
// src/langgraph/middleware/preset-development.ts
|
|
2663
2659
|
function development(node, options) {
|
|
2664
|
-
const {
|
|
2665
|
-
nodeName,
|
|
2666
|
-
verbose = true,
|
|
2667
|
-
logger: logger6
|
|
2668
|
-
} = options;
|
|
2660
|
+
const { nodeName, verbose = true, logger: logger6 } = options;
|
|
2669
2661
|
const actualLogger = logger6 || createLogger(nodeName, { level: "debug" /* DEBUG */ });
|
|
2670
2662
|
return withLogging2({
|
|
2671
2663
|
logger: actualLogger,
|
|
@@ -2676,9 +2668,10 @@ function development(node, options) {
|
|
|
2676
2668
|
logErrors: true
|
|
2677
2669
|
})(node);
|
|
2678
2670
|
}
|
|
2671
|
+
|
|
2672
|
+
// src/langgraph/middleware/preset-testing.ts
|
|
2679
2673
|
function testing(node, options) {
|
|
2680
2674
|
const {
|
|
2681
|
-
nodeName,
|
|
2682
2675
|
mockResponse,
|
|
2683
2676
|
simulateError,
|
|
2684
2677
|
delay = 0,
|
|
@@ -2700,9 +2693,12 @@ function testing(node, options) {
|
|
|
2700
2693
|
}
|
|
2701
2694
|
return await Promise.resolve(node(state));
|
|
2702
2695
|
};
|
|
2703
|
-
|
|
2704
|
-
|
|
2696
|
+
const testingNode = wrappedNode;
|
|
2697
|
+
testingNode.invocations = invocations;
|
|
2698
|
+
return testingNode;
|
|
2705
2699
|
}
|
|
2700
|
+
|
|
2701
|
+
// src/langgraph/middleware/preset-collection.ts
|
|
2706
2702
|
var presets = {
|
|
2707
2703
|
production,
|
|
2708
2704
|
development,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentforge/core",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.51",
|
|
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",
|