@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.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ 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';
|
|
5
|
-
import {
|
|
5
|
+
import { BaseChannel, AnnotationRoot, StateDefinition, UpdateType, StateGraph, END, MemorySaver, BaseCheckpointSaver, CheckpointTuple } from '@langchain/langgraph';
|
|
6
6
|
import { RunnableConfig } from '@langchain/core/runnables';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -1093,15 +1093,6 @@ declare function getToolJsonSchema<TInput, TOutput>(tool: Tool<TInput, TOutput>)
|
|
|
1093
1093
|
*/
|
|
1094
1094
|
declare function getToolDescription<TInput, TOutput>(tool: Tool<TInput, TOutput>): string;
|
|
1095
1095
|
|
|
1096
|
-
/**
|
|
1097
|
-
* LangGraph State Utilities
|
|
1098
|
-
*
|
|
1099
|
-
* Type-safe helpers for working with LangGraph state management.
|
|
1100
|
-
* These utilities wrap LangGraph's Annotation API to provide better TypeScript ergonomics.
|
|
1101
|
-
*
|
|
1102
|
-
* @module langgraph/state
|
|
1103
|
-
*/
|
|
1104
|
-
|
|
1105
1096
|
/**
|
|
1106
1097
|
* State channel configuration with optional Zod schema validation
|
|
1107
1098
|
*/
|
|
@@ -1150,6 +1141,16 @@ type ReducerUpdate<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
|
1150
1141
|
} ? TUpdate : never;
|
|
1151
1142
|
type ChannelValue<TChannel extends StateChannelConfigLike> = HasReducer<TChannel> extends true ? ReducerValue<TChannel> : [SchemaValue<TChannel>] extends [never] ? [DefaultValue<TChannel>] extends [never] ? unknown : DefaultValue<TChannel> : SchemaValue<TChannel>;
|
|
1152
1143
|
type ChannelUpdate<TChannel extends StateChannelConfigLike> = HasReducer<TChannel> extends true ? ReducerUpdate<TChannel> : ChannelValue<TChannel>;
|
|
1144
|
+
type SchemaMatchesValue<TChannel extends StateChannelConfigLike> = [
|
|
1145
|
+
SchemaValue<TChannel>
|
|
1146
|
+
] extends [never] ? true : [ChannelValue<TChannel>] extends [SchemaValue<TChannel>] ? true : false;
|
|
1147
|
+
type DefaultMatchesValue<TChannel extends StateChannelConfigLike> = [
|
|
1148
|
+
DefaultValue<TChannel>
|
|
1149
|
+
] extends [never] ? true : [DefaultValue<TChannel>] extends [ChannelValue<TChannel>] ? true : false;
|
|
1150
|
+
type ValidStateChannel<TChannel extends StateChannelConfigLike> = HasReducer<TChannel> extends true ? [ChannelValue<TChannel>] extends [never] ? never : SchemaMatchesValue<TChannel> extends true ? DefaultMatchesValue<TChannel> extends true ? TChannel : never : never : TChannel;
|
|
1151
|
+
type ValidStateConfig<TConfig extends StateConfigMap> = {
|
|
1152
|
+
[K in keyof TConfig]: ValidStateChannel<TConfig[K]>;
|
|
1153
|
+
};
|
|
1153
1154
|
type StateShape<TConfig extends StateConfigMap> = {
|
|
1154
1155
|
[K in keyof TConfig]: ChannelValue<TConfig[K]>;
|
|
1155
1156
|
};
|
|
@@ -1169,6 +1170,7 @@ type InputStateKeys<TConfig extends StateConfigMap, TState> = Extract<keyof TCon
|
|
|
1169
1170
|
type ValidatedState<TConfig extends StateConfigMap, TState extends Partial<Record<keyof TConfig, unknown>>> = {
|
|
1170
1171
|
[K in InputStateKeys<TConfig, TState> | DefaultedKeys<TConfig>]: ChannelValue<TConfig[K]>;
|
|
1171
1172
|
};
|
|
1173
|
+
|
|
1172
1174
|
/**
|
|
1173
1175
|
* Create a type-safe state annotation with optional Zod validation
|
|
1174
1176
|
*
|
|
@@ -1176,75 +1178,16 @@ type ValidatedState<TConfig extends StateConfigMap, TState extends Partial<Recor
|
|
|
1176
1178
|
* - Zod schema validation support
|
|
1177
1179
|
* - Better TypeScript inference
|
|
1178
1180
|
* - Documentation/description support
|
|
1179
|
-
*
|
|
1180
|
-
* @example
|
|
1181
|
-
* ```typescript
|
|
1182
|
-
* import { createStateAnnotation } from '@agentforge/core';
|
|
1183
|
-
* import { z } from 'zod';
|
|
1184
|
-
*
|
|
1185
|
-
* const AgentState = createStateAnnotation({
|
|
1186
|
-
* messages: {
|
|
1187
|
-
* schema: z.array(z.string()),
|
|
1188
|
-
* reducer: (left, right) => [...left, ...right],
|
|
1189
|
-
* default: () => [],
|
|
1190
|
-
* description: 'Chat messages'
|
|
1191
|
-
* },
|
|
1192
|
-
* context: {
|
|
1193
|
-
* schema: z.record(z.any()),
|
|
1194
|
-
* default: () => ({}),
|
|
1195
|
-
* description: 'Agent context'
|
|
1196
|
-
* }
|
|
1197
|
-
* });
|
|
1198
|
-
*
|
|
1199
|
-
* type State = typeof AgentState.State;
|
|
1200
|
-
* ```
|
|
1201
1181
|
*/
|
|
1202
|
-
declare function createStateAnnotation<TConfig extends StateConfigMap>(config: TConfig): AnnotationRoot<StateAnnotationDefinition<TConfig>>;
|
|
1182
|
+
declare function createStateAnnotation<TConfig extends StateConfigMap>(config: ValidStateConfig<TConfig>): AnnotationRoot<StateAnnotationDefinition<TConfig>>;
|
|
1183
|
+
|
|
1203
1184
|
/**
|
|
1204
1185
|
* Validate state against Zod schemas
|
|
1205
|
-
*
|
|
1206
|
-
* @param state - The state object to validate
|
|
1207
|
-
* @param config - The state channel configuration with schemas
|
|
1208
|
-
* @returns Validated state
|
|
1209
|
-
* @throws {z.ZodError} If validation fails
|
|
1210
|
-
*
|
|
1211
|
-
* @example
|
|
1212
|
-
* ```typescript
|
|
1213
|
-
* const config = {
|
|
1214
|
-
* messages: { schema: z.array(z.string()) },
|
|
1215
|
-
* count: { schema: z.number() }
|
|
1216
|
-
* };
|
|
1217
|
-
*
|
|
1218
|
-
* const validatedState = validateState(
|
|
1219
|
-
* { messages: ['hello'], count: 42 },
|
|
1220
|
-
* config
|
|
1221
|
-
* );
|
|
1222
|
-
* ```
|
|
1223
1186
|
*/
|
|
1224
1187
|
declare function validateState<TConfig extends StateConfigMap, TState extends Partial<Record<keyof TConfig, unknown>>>(state: TState, config: TConfig): ValidatedState<TConfig, TState>;
|
|
1188
|
+
|
|
1225
1189
|
/**
|
|
1226
1190
|
* Merge state updates using configured reducers
|
|
1227
|
-
*
|
|
1228
|
-
* @param currentState - Current state
|
|
1229
|
-
* @param update - State update
|
|
1230
|
-
* @param config - State channel configuration
|
|
1231
|
-
* @returns Merged state
|
|
1232
|
-
*
|
|
1233
|
-
* @example
|
|
1234
|
-
* ```typescript
|
|
1235
|
-
* const config = {
|
|
1236
|
-
* messages: {
|
|
1237
|
-
* reducer: (left, right) => [...left, ...right]
|
|
1238
|
-
* }
|
|
1239
|
-
* };
|
|
1240
|
-
*
|
|
1241
|
-
* const merged = mergeState(
|
|
1242
|
-
* { messages: ['a', 'b'] },
|
|
1243
|
-
* { messages: ['c'] },
|
|
1244
|
-
* config
|
|
1245
|
-
* );
|
|
1246
|
-
* // Result: { messages: ['a', 'b', 'c'] }
|
|
1247
|
-
* ```
|
|
1248
1191
|
*/
|
|
1249
1192
|
declare function mergeState<TConfig extends StateConfigMap>(currentState: Partial<StateShape<TConfig>>, update: StateUpdateShape<TConfig>, config: TConfig): Partial<StateShape<TConfig>>;
|
|
1250
1193
|
|
|
@@ -1906,119 +1849,6 @@ declare function chain<State>(): MiddlewareChain<State>;
|
|
|
1906
1849
|
*/
|
|
1907
1850
|
declare function createMiddlewareContext(): MiddlewareContext;
|
|
1908
1851
|
|
|
1909
|
-
/**
|
|
1910
|
-
* Retry pattern for LangGraph nodes
|
|
1911
|
-
*
|
|
1912
|
-
* Wraps a node function with retry logic.
|
|
1913
|
-
*/
|
|
1914
|
-
/**
|
|
1915
|
-
* Backoff strategy for retries
|
|
1916
|
-
*/
|
|
1917
|
-
type BackoffStrategy = 'constant' | 'linear' | 'exponential';
|
|
1918
|
-
/**
|
|
1919
|
-
* Options for retry behavior
|
|
1920
|
-
*/
|
|
1921
|
-
interface RetryOptions {
|
|
1922
|
-
/**
|
|
1923
|
-
* Maximum number of retry attempts
|
|
1924
|
-
* @default 3
|
|
1925
|
-
*/
|
|
1926
|
-
maxAttempts?: number;
|
|
1927
|
-
/**
|
|
1928
|
-
* Backoff strategy between retries
|
|
1929
|
-
* @default 'exponential'
|
|
1930
|
-
*/
|
|
1931
|
-
backoff?: BackoffStrategy;
|
|
1932
|
-
/**
|
|
1933
|
-
* Initial delay in milliseconds
|
|
1934
|
-
* @default 1000
|
|
1935
|
-
*/
|
|
1936
|
-
initialDelay?: number;
|
|
1937
|
-
/**
|
|
1938
|
-
* Maximum delay in milliseconds
|
|
1939
|
-
* @default 30000
|
|
1940
|
-
*/
|
|
1941
|
-
maxDelay?: number;
|
|
1942
|
-
/**
|
|
1943
|
-
* Optional callback when a retry occurs
|
|
1944
|
-
*/
|
|
1945
|
-
onRetry?: (error: Error, attempt: number) => void;
|
|
1946
|
-
/**
|
|
1947
|
-
* Optional predicate to determine if error should be retried
|
|
1948
|
-
* @default () => true (retry all errors)
|
|
1949
|
-
*/
|
|
1950
|
-
shouldRetry?: (error: Error) => boolean;
|
|
1951
|
-
}
|
|
1952
|
-
/**
|
|
1953
|
-
* Wraps a node function with retry logic.
|
|
1954
|
-
*
|
|
1955
|
-
* @example
|
|
1956
|
-
* ```typescript
|
|
1957
|
-
* const robustNode = withRetry(myNode, {
|
|
1958
|
-
* maxAttempts: 3,
|
|
1959
|
-
* backoff: 'exponential',
|
|
1960
|
-
* initialDelay: 1000,
|
|
1961
|
-
* onRetry: (error, attempt) => {
|
|
1962
|
-
* console.log(`Retry attempt ${attempt}: ${error.message}`);
|
|
1963
|
-
* },
|
|
1964
|
-
* });
|
|
1965
|
-
*
|
|
1966
|
-
* graph.addNode('robust', robustNode);
|
|
1967
|
-
* ```
|
|
1968
|
-
*
|
|
1969
|
-
* @param node - The node function to wrap
|
|
1970
|
-
* @param options - Retry configuration options
|
|
1971
|
-
* @returns A wrapped node function with retry logic
|
|
1972
|
-
*/
|
|
1973
|
-
declare function withRetry<State>(node: (state: State) => State | Promise<State> | Partial<State> | Promise<Partial<State>>, options?: RetryOptions): (state: State) => Promise<State | Partial<State>>;
|
|
1974
|
-
|
|
1975
|
-
/**
|
|
1976
|
-
* Error handler pattern for LangGraph nodes
|
|
1977
|
-
*
|
|
1978
|
-
* Wraps a node function with error handling logic.
|
|
1979
|
-
*/
|
|
1980
|
-
/**
|
|
1981
|
-
* Options for error handling behavior
|
|
1982
|
-
*/
|
|
1983
|
-
interface ErrorHandlerOptions<State> {
|
|
1984
|
-
/**
|
|
1985
|
-
* Callback function to handle errors
|
|
1986
|
-
* Should return a state update to apply when an error occurs
|
|
1987
|
-
*/
|
|
1988
|
-
onError: (error: Error, state: State) => State | Partial<State> | Promise<State | Partial<State>>;
|
|
1989
|
-
/**
|
|
1990
|
-
* Optional callback for logging errors
|
|
1991
|
-
*/
|
|
1992
|
-
logError?: (error: Error, state: State) => void;
|
|
1993
|
-
/**
|
|
1994
|
-
* Whether to rethrow the error after handling
|
|
1995
|
-
* @default false
|
|
1996
|
-
*/
|
|
1997
|
-
rethrow?: boolean;
|
|
1998
|
-
}
|
|
1999
|
-
/**
|
|
2000
|
-
* Wraps a node function with error handling logic.
|
|
2001
|
-
*
|
|
2002
|
-
* @example
|
|
2003
|
-
* ```typescript
|
|
2004
|
-
* const safeNode = withErrorHandler(myNode, {
|
|
2005
|
-
* onError: (error, state) => {
|
|
2006
|
-
* return { ...state, error: error.message, failed: true };
|
|
2007
|
-
* },
|
|
2008
|
-
* logError: (error) => {
|
|
2009
|
-
* console.error('Node failed:', error);
|
|
2010
|
-
* },
|
|
2011
|
-
* });
|
|
2012
|
-
*
|
|
2013
|
-
* graph.addNode('safe', safeNode);
|
|
2014
|
-
* ```
|
|
2015
|
-
*
|
|
2016
|
-
* @param node - The node function to wrap
|
|
2017
|
-
* @param options - Error handling configuration options
|
|
2018
|
-
* @returns A wrapped node function with error handling
|
|
2019
|
-
*/
|
|
2020
|
-
declare function withErrorHandler<State>(node: (state: State) => State | Promise<State> | Partial<State> | Promise<Partial<State>>, options: ErrorHandlerOptions<State>): (state: State) => Promise<State | Partial<State>>;
|
|
2021
|
-
|
|
2022
1852
|
/**
|
|
2023
1853
|
* Structured Logging Utilities
|
|
2024
1854
|
*
|
|
@@ -2143,158 +1973,159 @@ interface Logger {
|
|
|
2143
1973
|
declare function createLogger(name: string, options?: LoggerOptions): Logger;
|
|
2144
1974
|
|
|
2145
1975
|
/**
|
|
2146
|
-
*
|
|
2147
|
-
*
|
|
2148
|
-
* Pre-configured middleware combinations for common use cases.
|
|
1976
|
+
* Error handler pattern for LangGraph nodes
|
|
2149
1977
|
*
|
|
2150
|
-
*
|
|
1978
|
+
* Wraps a node function with error handling logic.
|
|
2151
1979
|
*/
|
|
2152
|
-
|
|
2153
1980
|
/**
|
|
2154
|
-
* Options for
|
|
1981
|
+
* Options for error handling behavior
|
|
2155
1982
|
*/
|
|
2156
|
-
interface
|
|
2157
|
-
/**
|
|
2158
|
-
* Name of the node (for logging and metrics)
|
|
2159
|
-
*/
|
|
2160
|
-
nodeName: string;
|
|
2161
|
-
/**
|
|
2162
|
-
* Logger instance
|
|
2163
|
-
*/
|
|
2164
|
-
logger?: Logger;
|
|
2165
|
-
/**
|
|
2166
|
-
* Enable metrics tracking
|
|
2167
|
-
* @default true
|
|
2168
|
-
*/
|
|
2169
|
-
enableMetrics?: boolean;
|
|
2170
|
-
/**
|
|
2171
|
-
* Enable tracing
|
|
2172
|
-
* @default true
|
|
2173
|
-
*/
|
|
2174
|
-
enableTracing?: boolean;
|
|
2175
|
-
/**
|
|
2176
|
-
* Enable retry logic
|
|
2177
|
-
* @default true
|
|
2178
|
-
*/
|
|
2179
|
-
enableRetry?: boolean;
|
|
1983
|
+
interface ErrorHandlerOptions<State> {
|
|
2180
1984
|
/**
|
|
2181
|
-
*
|
|
2182
|
-
*
|
|
1985
|
+
* Callback function to handle errors
|
|
1986
|
+
* Should return a state update to apply when an error occurs
|
|
2183
1987
|
*/
|
|
2184
|
-
|
|
1988
|
+
onError: (error: Error, state: State) => State | Partial<State> | Promise<State | Partial<State>>;
|
|
2185
1989
|
/**
|
|
2186
|
-
*
|
|
1990
|
+
* Optional callback for logging errors
|
|
2187
1991
|
*/
|
|
2188
|
-
|
|
1992
|
+
logError?: (error: Error, state: State) => void;
|
|
2189
1993
|
/**
|
|
2190
|
-
*
|
|
1994
|
+
* Whether to rethrow the error after handling
|
|
1995
|
+
* @default false
|
|
2191
1996
|
*/
|
|
2192
|
-
|
|
1997
|
+
rethrow?: boolean;
|
|
2193
1998
|
}
|
|
2194
1999
|
/**
|
|
2195
|
-
*
|
|
2196
|
-
*
|
|
2197
|
-
* Includes:
|
|
2198
|
-
* - Error handling with fallback
|
|
2199
|
-
* - Retry logic with exponential backoff
|
|
2200
|
-
* - Timeout protection
|
|
2201
|
-
* - Metrics tracking
|
|
2202
|
-
* - Distributed tracing
|
|
2000
|
+
* Wraps a node function with error handling logic.
|
|
2203
2001
|
*
|
|
2204
2002
|
* @example
|
|
2205
2003
|
* ```typescript
|
|
2206
|
-
* const
|
|
2207
|
-
*
|
|
2208
|
-
*
|
|
2004
|
+
* const safeNode = withErrorHandler(myNode, {
|
|
2005
|
+
* onError: (error, state) => {
|
|
2006
|
+
* return { ...state, error: error.message, failed: true };
|
|
2007
|
+
* },
|
|
2008
|
+
* logError: (error) => {
|
|
2009
|
+
* console.error('Node failed:', error);
|
|
2010
|
+
* },
|
|
2209
2011
|
* });
|
|
2012
|
+
*
|
|
2013
|
+
* graph.addNode('safe', safeNode);
|
|
2210
2014
|
* ```
|
|
2015
|
+
*
|
|
2016
|
+
* @param node - The node function to wrap
|
|
2017
|
+
* @param options - Error handling configuration options
|
|
2018
|
+
* @returns A wrapped node function with error handling
|
|
2211
2019
|
*/
|
|
2212
|
-
declare function
|
|
2020
|
+
declare function withErrorHandler<State>(node: (state: State) => State | Promise<State> | Partial<State> | Promise<Partial<State>>, options: ErrorHandlerOptions<State>): (state: State) => Promise<State | Partial<State>>;
|
|
2021
|
+
|
|
2213
2022
|
/**
|
|
2214
|
-
*
|
|
2023
|
+
* Retry pattern for LangGraph nodes
|
|
2024
|
+
*
|
|
2025
|
+
* Wraps a node function with retry logic.
|
|
2215
2026
|
*/
|
|
2216
|
-
interface DevelopmentPresetOptions {
|
|
2217
|
-
/**
|
|
2218
|
-
* Name of the node
|
|
2219
|
-
*/
|
|
2220
|
-
nodeName: string;
|
|
2221
|
-
/**
|
|
2222
|
-
* Enable verbose logging
|
|
2223
|
-
* @default true
|
|
2224
|
-
*/
|
|
2225
|
-
verbose?: boolean;
|
|
2226
|
-
/**
|
|
2227
|
-
* Logger instance
|
|
2228
|
-
*/
|
|
2229
|
-
logger?: Logger;
|
|
2230
|
-
}
|
|
2231
2027
|
/**
|
|
2232
|
-
*
|
|
2233
|
-
*
|
|
2234
|
-
* Includes:
|
|
2235
|
-
* - Verbose logging
|
|
2236
|
-
* - Error details
|
|
2237
|
-
* - No retry (fail fast)
|
|
2238
|
-
* - Extended timeout
|
|
2239
|
-
*
|
|
2240
|
-
* @example
|
|
2241
|
-
* ```typescript
|
|
2242
|
-
* const devNode = presets.development(myNode, {
|
|
2243
|
-
* nodeName: 'my-node',
|
|
2244
|
-
* verbose: true,
|
|
2245
|
-
* });
|
|
2246
|
-
* ```
|
|
2028
|
+
* Backoff strategy for retries
|
|
2247
2029
|
*/
|
|
2248
|
-
|
|
2030
|
+
type BackoffStrategy = 'constant' | 'linear' | 'exponential';
|
|
2249
2031
|
/**
|
|
2250
|
-
* Options for
|
|
2032
|
+
* Options for retry behavior
|
|
2251
2033
|
*/
|
|
2252
|
-
interface
|
|
2034
|
+
interface RetryOptions {
|
|
2253
2035
|
/**
|
|
2254
|
-
*
|
|
2036
|
+
* Maximum number of retry attempts
|
|
2037
|
+
* @default 3
|
|
2255
2038
|
*/
|
|
2256
|
-
|
|
2039
|
+
maxAttempts?: number;
|
|
2257
2040
|
/**
|
|
2258
|
-
*
|
|
2041
|
+
* Backoff strategy between retries
|
|
2042
|
+
* @default 'exponential'
|
|
2259
2043
|
*/
|
|
2260
|
-
|
|
2044
|
+
backoff?: BackoffStrategy;
|
|
2261
2045
|
/**
|
|
2262
|
-
*
|
|
2046
|
+
* Initial delay in milliseconds
|
|
2047
|
+
* @default 1000
|
|
2263
2048
|
*/
|
|
2264
|
-
|
|
2049
|
+
initialDelay?: number;
|
|
2265
2050
|
/**
|
|
2266
|
-
*
|
|
2051
|
+
* Maximum delay in milliseconds
|
|
2052
|
+
* @default 30000
|
|
2267
2053
|
*/
|
|
2268
|
-
|
|
2054
|
+
maxDelay?: number;
|
|
2269
2055
|
/**
|
|
2270
|
-
*
|
|
2056
|
+
* Optional callback when a retry occurs
|
|
2271
2057
|
*/
|
|
2272
|
-
|
|
2058
|
+
onRetry?: (error: Error, attempt: number) => void;
|
|
2059
|
+
/**
|
|
2060
|
+
* Optional predicate to determine if error should be retried
|
|
2061
|
+
* @default () => true (retry all errors)
|
|
2062
|
+
*/
|
|
2063
|
+
shouldRetry?: (error: Error) => boolean;
|
|
2273
2064
|
}
|
|
2274
2065
|
/**
|
|
2275
|
-
*
|
|
2276
|
-
*
|
|
2277
|
-
* Includes:
|
|
2278
|
-
* - Mock responses
|
|
2279
|
-
* - Error simulation
|
|
2280
|
-
* - Invocation tracking
|
|
2281
|
-
* - Configurable delays
|
|
2066
|
+
* Wraps a node function with retry logic.
|
|
2282
2067
|
*
|
|
2283
2068
|
* @example
|
|
2284
2069
|
* ```typescript
|
|
2285
|
-
* const
|
|
2286
|
-
*
|
|
2287
|
-
*
|
|
2288
|
-
*
|
|
2070
|
+
* const robustNode = withRetry(myNode, {
|
|
2071
|
+
* maxAttempts: 3,
|
|
2072
|
+
* backoff: 'exponential',
|
|
2073
|
+
* initialDelay: 1000,
|
|
2074
|
+
* onRetry: (error, attempt) => {
|
|
2075
|
+
* console.log(`Retry attempt ${attempt}: ${error.message}`);
|
|
2076
|
+
* },
|
|
2289
2077
|
* });
|
|
2078
|
+
*
|
|
2079
|
+
* graph.addNode('robust', robustNode);
|
|
2290
2080
|
* ```
|
|
2081
|
+
*
|
|
2082
|
+
* @param node - The node function to wrap
|
|
2083
|
+
* @param options - Retry configuration options
|
|
2084
|
+
* @returns A wrapped node function with retry logic
|
|
2291
2085
|
*/
|
|
2292
|
-
declare function
|
|
2086
|
+
declare function withRetry<State>(node: (state: State) => State | Promise<State> | Partial<State> | Promise<Partial<State>>, options?: RetryOptions): (state: State) => Promise<State | Partial<State>>;
|
|
2087
|
+
|
|
2088
|
+
interface ProductionPresetOptions<State> {
|
|
2089
|
+
nodeName: string;
|
|
2090
|
+
logger?: Logger;
|
|
2091
|
+
enableMetrics?: boolean;
|
|
2092
|
+
enableTracing?: boolean;
|
|
2093
|
+
enableRetry?: boolean;
|
|
2094
|
+
timeout?: number;
|
|
2095
|
+
retryOptions?: Partial<RetryOptions>;
|
|
2096
|
+
errorOptions?: Partial<ErrorHandlerOptions<State>>;
|
|
2097
|
+
}
|
|
2098
|
+
interface DevelopmentPresetOptions {
|
|
2099
|
+
nodeName: string;
|
|
2100
|
+
verbose?: boolean;
|
|
2101
|
+
logger?: Logger;
|
|
2102
|
+
}
|
|
2103
|
+
interface TestingPresetOptions<State> {
|
|
2104
|
+
nodeName: string;
|
|
2105
|
+
mockResponse?: Partial<State>;
|
|
2106
|
+
simulateError?: Error;
|
|
2107
|
+
delay?: number;
|
|
2108
|
+
trackInvocations?: boolean;
|
|
2109
|
+
}
|
|
2110
|
+
type TestingPresetNode<State> = NodeFunction<State> & {
|
|
2293
2111
|
invocations: State[];
|
|
2294
2112
|
};
|
|
2113
|
+
|
|
2295
2114
|
/**
|
|
2296
|
-
*
|
|
2115
|
+
* Production preset with comprehensive error handling, metrics, and tracing.
|
|
2297
2116
|
*/
|
|
2117
|
+
declare function production<State>(node: NodeFunction<State>, options: ProductionPresetOptions<State>): NodeFunction<State>;
|
|
2118
|
+
|
|
2119
|
+
/**
|
|
2120
|
+
* Development preset with verbose logging and debugging.
|
|
2121
|
+
*/
|
|
2122
|
+
declare function development<State>(node: NodeFunction<State>, options: DevelopmentPresetOptions): NodeFunction<State>;
|
|
2123
|
+
|
|
2124
|
+
/**
|
|
2125
|
+
* Testing preset for unit and integration tests.
|
|
2126
|
+
*/
|
|
2127
|
+
declare function testing<State>(node: NodeFunction<State>, options: TestingPresetOptions<State>): TestingPresetNode<State>;
|
|
2128
|
+
|
|
2298
2129
|
declare const presets: {
|
|
2299
2130
|
production: typeof production;
|
|
2300
2131
|
development: typeof development;
|