@agentforge/core 0.15.7 → 0.15.9
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 +123 -45
- package/dist/index.d.cts +124 -35
- package/dist/index.d.ts +124 -35
- package/dist/index.js +123 -45
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -946,7 +946,7 @@ var LoggerImpl = class _LoggerImpl {
|
|
|
946
946
|
if (this.options.includeContext && Object.keys(this.context).length > 0) {
|
|
947
947
|
entry.context = this.context;
|
|
948
948
|
}
|
|
949
|
-
if (data) {
|
|
949
|
+
if (data !== void 0) {
|
|
950
950
|
entry.data = data;
|
|
951
951
|
}
|
|
952
952
|
const output = this.format(entry);
|
|
@@ -966,7 +966,7 @@ var LoggerImpl = class _LoggerImpl {
|
|
|
966
966
|
if (entry.context) {
|
|
967
967
|
parts.push(`context=${JSON.stringify(entry.context)}`);
|
|
968
968
|
}
|
|
969
|
-
if (entry.data) {
|
|
969
|
+
if (entry.data !== void 0) {
|
|
970
970
|
parts.push(`data=${JSON.stringify(entry.data)}`);
|
|
971
971
|
}
|
|
972
972
|
return parts.join(" ");
|
|
@@ -1299,7 +1299,7 @@ var ToolRegistry = class {
|
|
|
1299
1299
|
logger.error("Event handler error", {
|
|
1300
1300
|
event,
|
|
1301
1301
|
error: error instanceof Error ? error.message : String(error),
|
|
1302
|
-
|
|
1302
|
+
...error instanceof Error && error.stack ? { stack: error.stack } : {}
|
|
1303
1303
|
});
|
|
1304
1304
|
}
|
|
1305
1305
|
});
|
|
@@ -1766,7 +1766,7 @@ var ManagedTool = class {
|
|
|
1766
1766
|
(err) => logger3.error("Cleanup failed", {
|
|
1767
1767
|
toolName: this.name,
|
|
1768
1768
|
error: err instanceof Error ? err.message : String(err),
|
|
1769
|
-
|
|
1769
|
+
...err instanceof Error && err.stack ? { stack: err.stack } : {}
|
|
1770
1770
|
})
|
|
1771
1771
|
);
|
|
1772
1772
|
});
|
|
@@ -2211,46 +2211,84 @@ function createToolSimulator(config) {
|
|
|
2211
2211
|
|
|
2212
2212
|
// src/langgraph/state.ts
|
|
2213
2213
|
var import_langgraph = require("@langchain/langgraph");
|
|
2214
|
+
function entriesOf(value) {
|
|
2215
|
+
return Object.entries(value);
|
|
2216
|
+
}
|
|
2217
|
+
function keysOf(value) {
|
|
2218
|
+
return Object.keys(value);
|
|
2219
|
+
}
|
|
2220
|
+
function hasOwnProperty(value, key) {
|
|
2221
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
2222
|
+
}
|
|
2223
|
+
function useLatestValue(_left, right) {
|
|
2224
|
+
return right;
|
|
2225
|
+
}
|
|
2226
|
+
function setStateValue(target, key, value) {
|
|
2227
|
+
target[key] = value;
|
|
2228
|
+
}
|
|
2229
|
+
function setStateDefinitionValue(target, key, value) {
|
|
2230
|
+
target[key] = value;
|
|
2231
|
+
}
|
|
2232
|
+
function createChannel(channelConfig) {
|
|
2233
|
+
if (channelConfig.reducer) {
|
|
2234
|
+
return (0, import_langgraph.Annotation)({
|
|
2235
|
+
reducer: channelConfig.reducer,
|
|
2236
|
+
default: channelConfig.default
|
|
2237
|
+
});
|
|
2238
|
+
}
|
|
2239
|
+
if (channelConfig.default) {
|
|
2240
|
+
return (0, import_langgraph.Annotation)({
|
|
2241
|
+
reducer: useLatestValue,
|
|
2242
|
+
default: channelConfig.default
|
|
2243
|
+
});
|
|
2244
|
+
}
|
|
2245
|
+
return (0, import_langgraph.Annotation)();
|
|
2246
|
+
}
|
|
2214
2247
|
function createStateAnnotation(config) {
|
|
2215
2248
|
const stateDefinition = {};
|
|
2216
|
-
for (const [key, channelConfig] of
|
|
2217
|
-
|
|
2218
|
-
stateDefinition
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
} else if (channelConfig.default) {
|
|
2223
|
-
stateDefinition[key] = (0, import_langgraph.Annotation)({
|
|
2224
|
-
reducer: (_left, right) => right,
|
|
2225
|
-
default: channelConfig.default
|
|
2226
|
-
});
|
|
2227
|
-
} else {
|
|
2228
|
-
stateDefinition[key] = (0, import_langgraph.Annotation)();
|
|
2229
|
-
}
|
|
2249
|
+
for (const [key, channelConfig] of entriesOf(config)) {
|
|
2250
|
+
setStateDefinitionValue(
|
|
2251
|
+
stateDefinition,
|
|
2252
|
+
key,
|
|
2253
|
+
createChannel(channelConfig)
|
|
2254
|
+
);
|
|
2230
2255
|
}
|
|
2231
2256
|
return import_langgraph.Annotation.Root(stateDefinition);
|
|
2232
2257
|
}
|
|
2233
2258
|
function validateState(state, config) {
|
|
2234
2259
|
const validated = {};
|
|
2235
|
-
for (const [key, channelConfig] of
|
|
2236
|
-
if (channelConfig.schema && key
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2260
|
+
for (const [key, channelConfig] of entriesOf(config)) {
|
|
2261
|
+
if (channelConfig.schema && hasOwnProperty(state, key)) {
|
|
2262
|
+
setStateValue(
|
|
2263
|
+
validated,
|
|
2264
|
+
key,
|
|
2265
|
+
channelConfig.schema.parse(state[key])
|
|
2266
|
+
);
|
|
2267
|
+
} else if (hasOwnProperty(state, key)) {
|
|
2268
|
+
setStateValue(validated, key, state[key]);
|
|
2240
2269
|
} else if (channelConfig.default) {
|
|
2241
|
-
validated
|
|
2270
|
+
setStateValue(validated, key, channelConfig.default());
|
|
2242
2271
|
}
|
|
2243
2272
|
}
|
|
2244
2273
|
return validated;
|
|
2245
2274
|
}
|
|
2246
2275
|
function mergeState(currentState, update, config) {
|
|
2247
2276
|
const merged = { ...currentState };
|
|
2248
|
-
for (const
|
|
2277
|
+
for (const key of keysOf(update)) {
|
|
2278
|
+
const value = update[key];
|
|
2249
2279
|
const channelConfig = config[key];
|
|
2250
|
-
|
|
2251
|
-
|
|
2280
|
+
const reducer = channelConfig?.reducer;
|
|
2281
|
+
if (reducer && hasOwnProperty(merged, key)) {
|
|
2282
|
+
setStateValue(
|
|
2283
|
+
merged,
|
|
2284
|
+
key,
|
|
2285
|
+
reducer(
|
|
2286
|
+
merged[key],
|
|
2287
|
+
value
|
|
2288
|
+
)
|
|
2289
|
+
);
|
|
2252
2290
|
} else {
|
|
2253
|
-
merged
|
|
2291
|
+
setStateValue(merged, key, value);
|
|
2254
2292
|
}
|
|
2255
2293
|
}
|
|
2256
2294
|
return merged;
|
|
@@ -2788,7 +2826,7 @@ var withLogging = (options) => {
|
|
|
2788
2826
|
if (logErrors) {
|
|
2789
2827
|
logger5.error(`Node execution failed (${duration}ms)`, {
|
|
2790
2828
|
error: err.message,
|
|
2791
|
-
stack: err.stack
|
|
2829
|
+
...err.stack ? { stack: err.stack } : {}
|
|
2792
2830
|
});
|
|
2793
2831
|
}
|
|
2794
2832
|
if (onError) {
|
|
@@ -5236,6 +5274,40 @@ function createProfiler(options) {
|
|
|
5236
5274
|
|
|
5237
5275
|
// src/monitoring/alerts.ts
|
|
5238
5276
|
var logger4 = createLogger("agentforge:core:monitoring:alerts", { level: "info" /* INFO */ });
|
|
5277
|
+
function toAlertSummary(alert) {
|
|
5278
|
+
return {
|
|
5279
|
+
name: alert.name,
|
|
5280
|
+
severity: alert.severity,
|
|
5281
|
+
message: alert.message
|
|
5282
|
+
};
|
|
5283
|
+
}
|
|
5284
|
+
function toRuleErrorPayload(ruleName, error) {
|
|
5285
|
+
return {
|
|
5286
|
+
ruleName,
|
|
5287
|
+
error: error instanceof Error ? error.message : String(error),
|
|
5288
|
+
...error instanceof Error && error.stack ? { stack: error.stack } : {}
|
|
5289
|
+
};
|
|
5290
|
+
}
|
|
5291
|
+
function toAlertDispatchErrorPayload(ruleName, error) {
|
|
5292
|
+
return {
|
|
5293
|
+
stage: "alert-dispatch",
|
|
5294
|
+
...toRuleErrorPayload(ruleName, error)
|
|
5295
|
+
};
|
|
5296
|
+
}
|
|
5297
|
+
function toAlertCallbackErrorPayload(error) {
|
|
5298
|
+
return {
|
|
5299
|
+
stage: "alert-callback",
|
|
5300
|
+
error: error instanceof Error ? error.message : String(error),
|
|
5301
|
+
...error instanceof Error && error.stack ? { stack: error.stack } : {}
|
|
5302
|
+
};
|
|
5303
|
+
}
|
|
5304
|
+
function toMetricsProviderErrorPayload(error) {
|
|
5305
|
+
return {
|
|
5306
|
+
stage: "metrics-provider",
|
|
5307
|
+
error: error instanceof Error ? error.message : String(error),
|
|
5308
|
+
...error instanceof Error && error.stack ? { stack: error.stack } : {}
|
|
5309
|
+
};
|
|
5310
|
+
}
|
|
5239
5311
|
var AlertManager = class {
|
|
5240
5312
|
constructor(options) {
|
|
5241
5313
|
this.options = options;
|
|
@@ -5249,8 +5321,12 @@ var AlertManager = class {
|
|
|
5249
5321
|
}
|
|
5250
5322
|
this.running = true;
|
|
5251
5323
|
this.monitorTimer = setInterval(() => {
|
|
5252
|
-
|
|
5253
|
-
|
|
5324
|
+
try {
|
|
5325
|
+
const currentMetrics = metrics();
|
|
5326
|
+
this.checkRules(currentMetrics);
|
|
5327
|
+
} catch (error) {
|
|
5328
|
+
logger4.error("Metrics collection failed", toMetricsProviderErrorPayload(error));
|
|
5329
|
+
}
|
|
5254
5330
|
}, interval);
|
|
5255
5331
|
}
|
|
5256
5332
|
stop() {
|
|
@@ -5266,18 +5342,22 @@ var AlertManager = class {
|
|
|
5266
5342
|
async alert(alert) {
|
|
5267
5343
|
const fullAlert = {
|
|
5268
5344
|
...alert,
|
|
5269
|
-
timestamp: alert.timestamp
|
|
5345
|
+
timestamp: alert.timestamp ?? Date.now()
|
|
5270
5346
|
};
|
|
5271
5347
|
if (this.isThrottled(alert.name)) {
|
|
5272
5348
|
return;
|
|
5273
5349
|
}
|
|
5274
5350
|
this.lastAlertTime.set(alert.name, Date.now());
|
|
5275
|
-
|
|
5351
|
+
try {
|
|
5352
|
+
await this.options.onAlert?.(fullAlert);
|
|
5353
|
+
} catch (error) {
|
|
5354
|
+
logger4.error("Alert callback failed", toAlertCallbackErrorPayload(error));
|
|
5355
|
+
}
|
|
5276
5356
|
logger4.warn("Alert triggered", {
|
|
5277
5357
|
name: alert.name,
|
|
5278
5358
|
severity: alert.severity,
|
|
5279
5359
|
message: alert.message,
|
|
5280
|
-
data: alert.data
|
|
5360
|
+
...alert.data ? { data: alert.data } : {}
|
|
5281
5361
|
});
|
|
5282
5362
|
}
|
|
5283
5363
|
checkRules(metrics) {
|
|
@@ -5287,19 +5367,17 @@ var AlertManager = class {
|
|
|
5287
5367
|
for (const rule of this.options.rules) {
|
|
5288
5368
|
try {
|
|
5289
5369
|
if (rule.condition(metrics)) {
|
|
5290
|
-
this.alert({
|
|
5370
|
+
void this.alert({
|
|
5291
5371
|
name: rule.name,
|
|
5292
5372
|
severity: rule.severity,
|
|
5293
5373
|
message: rule.message || `Alert triggered: ${rule.name}`,
|
|
5294
5374
|
data: { metrics }
|
|
5375
|
+
}).catch((error) => {
|
|
5376
|
+
logger4.error("Alert dispatch failed", toAlertDispatchErrorPayload(rule.name, error));
|
|
5295
5377
|
});
|
|
5296
5378
|
}
|
|
5297
5379
|
} catch (error) {
|
|
5298
|
-
logger4.error("Rule check failed",
|
|
5299
|
-
ruleName: rule.name,
|
|
5300
|
-
error: error instanceof Error ? error.message : String(error),
|
|
5301
|
-
stack: error instanceof Error ? error.stack : void 0
|
|
5302
|
-
});
|
|
5380
|
+
logger4.error("Rule check failed", toRuleErrorPayload(rule.name, error));
|
|
5303
5381
|
}
|
|
5304
5382
|
}
|
|
5305
5383
|
}
|
|
@@ -5324,32 +5402,32 @@ var AlertManager = class {
|
|
|
5324
5402
|
logger4.info("Alert sent to email", {
|
|
5325
5403
|
channel: channelName,
|
|
5326
5404
|
to: channel.config.to,
|
|
5327
|
-
alert:
|
|
5405
|
+
alert: toAlertSummary(alert)
|
|
5328
5406
|
});
|
|
5329
5407
|
break;
|
|
5330
5408
|
case "slack":
|
|
5331
5409
|
logger4.info("Alert sent to Slack", {
|
|
5332
5410
|
channel: channelName,
|
|
5333
5411
|
webhookUrl: channel.config.webhookUrl,
|
|
5334
|
-
alert:
|
|
5412
|
+
alert: toAlertSummary(alert)
|
|
5335
5413
|
});
|
|
5336
5414
|
break;
|
|
5337
5415
|
case "webhook":
|
|
5338
5416
|
logger4.info("Alert sent to webhook", {
|
|
5339
5417
|
channel: channelName,
|
|
5340
5418
|
url: channel.config.url,
|
|
5341
|
-
alert:
|
|
5419
|
+
alert: toAlertSummary(alert)
|
|
5342
5420
|
});
|
|
5343
5421
|
break;
|
|
5344
5422
|
default:
|
|
5345
5423
|
logger4.info("Alert sent", {
|
|
5346
5424
|
channel: channelName,
|
|
5347
5425
|
channelType: channel.type,
|
|
5348
|
-
alert:
|
|
5426
|
+
alert: toAlertSummary(alert)
|
|
5349
5427
|
});
|
|
5350
5428
|
}
|
|
5351
5429
|
}
|
|
5352
|
-
getAlertHistory(
|
|
5430
|
+
getAlertHistory(_name, _limit = 100) {
|
|
5353
5431
|
return [];
|
|
5354
5432
|
}
|
|
5355
5433
|
clearAlertHistory(name) {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { z, ZodType, ZodTypeDef } from 'zod';
|
|
1
|
+
import { z, ZodTypeAny, output, ZodType, ZodTypeDef } from 'zod';
|
|
2
2
|
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
3
|
-
import { AnnotationRoot,
|
|
3
|
+
import { AnnotationRoot, BaseChannel, StateGraph, END, MemorySaver, BaseCheckpointSaver, CheckpointTuple } from '@langchain/langgraph';
|
|
4
4
|
import { RunnableConfig } from '@langchain/core/runnables';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1901,11 +1901,11 @@ declare function getToolDescription<TInput, TOutput>(tool: Tool<TInput, TOutput>
|
|
|
1901
1901
|
/**
|
|
1902
1902
|
* State channel configuration with optional Zod schema validation
|
|
1903
1903
|
*/
|
|
1904
|
-
interface StateChannelConfig<T =
|
|
1904
|
+
interface StateChannelConfig<T = unknown, U = T> {
|
|
1905
1905
|
/**
|
|
1906
1906
|
* Optional Zod schema for runtime validation
|
|
1907
1907
|
*/
|
|
1908
|
-
schema?: ZodType<T, ZodTypeDef,
|
|
1908
|
+
schema?: ZodType<T, ZodTypeDef, unknown>;
|
|
1909
1909
|
/**
|
|
1910
1910
|
* Optional reducer function for aggregating updates
|
|
1911
1911
|
*/
|
|
@@ -1919,6 +1919,52 @@ interface StateChannelConfig<T = any, U = T> {
|
|
|
1919
1919
|
*/
|
|
1920
1920
|
description?: string;
|
|
1921
1921
|
}
|
|
1922
|
+
type StateChannelConfigLike = {
|
|
1923
|
+
schema?: ZodTypeAny;
|
|
1924
|
+
reducer?: (left: never, right: never) => unknown;
|
|
1925
|
+
default?: () => unknown;
|
|
1926
|
+
description?: string;
|
|
1927
|
+
};
|
|
1928
|
+
type StateConfigMap = Record<string, StateChannelConfigLike>;
|
|
1929
|
+
type IsExact<TLeft, TRight> = [
|
|
1930
|
+
TLeft
|
|
1931
|
+
] extends [TRight] ? ([TRight] extends [TLeft] ? true : false) : false;
|
|
1932
|
+
type HasReducer<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1933
|
+
reducer: (left: unknown, right: unknown) => unknown;
|
|
1934
|
+
} ? true : false;
|
|
1935
|
+
type SchemaValue<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1936
|
+
schema: infer TSchema extends ZodTypeAny;
|
|
1937
|
+
} ? output<TSchema> : never;
|
|
1938
|
+
type DefaultValue<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1939
|
+
default: () => infer TValue;
|
|
1940
|
+
} ? TValue : never;
|
|
1941
|
+
type ReducerValue<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1942
|
+
reducer: (left: infer TValue, right: unknown) => infer TResult;
|
|
1943
|
+
} ? IsExact<TValue, TResult> extends true ? TValue : never : never;
|
|
1944
|
+
type ReducerUpdate<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1945
|
+
reducer: (left: unknown, right: infer TUpdate) => unknown;
|
|
1946
|
+
} ? TUpdate : never;
|
|
1947
|
+
type ChannelValue<TChannel extends StateChannelConfigLike> = HasReducer<TChannel> extends true ? ReducerValue<TChannel> : [SchemaValue<TChannel>] extends [never] ? [DefaultValue<TChannel>] extends [never] ? unknown : DefaultValue<TChannel> : SchemaValue<TChannel>;
|
|
1948
|
+
type ChannelUpdate<TChannel extends StateChannelConfigLike> = HasReducer<TChannel> extends true ? ReducerUpdate<TChannel> : ChannelValue<TChannel>;
|
|
1949
|
+
type StateShape<TConfig extends StateConfigMap> = {
|
|
1950
|
+
[K in keyof TConfig]: ChannelValue<TConfig[K]>;
|
|
1951
|
+
};
|
|
1952
|
+
type StateUpdateShape<TConfig extends StateConfigMap> = {
|
|
1953
|
+
[K in keyof TConfig]?: ChannelUpdate<TConfig[K]>;
|
|
1954
|
+
};
|
|
1955
|
+
type StateChannelDefinition<TChannel extends StateChannelConfigLike> = BaseChannel<ChannelValue<TChannel>, ChannelUpdate<TChannel>>;
|
|
1956
|
+
type StateAnnotationDefinition<TConfig extends StateConfigMap> = {
|
|
1957
|
+
[K in keyof TConfig]: StateChannelDefinition<TConfig[K]>;
|
|
1958
|
+
};
|
|
1959
|
+
type DefaultedKeys<TConfig extends StateConfigMap> = {
|
|
1960
|
+
[K in keyof TConfig]-?: TConfig[K] extends {
|
|
1961
|
+
default: () => ChannelValue<TConfig[K]>;
|
|
1962
|
+
} ? K : never;
|
|
1963
|
+
}[keyof TConfig];
|
|
1964
|
+
type InputStateKeys<TConfig extends StateConfigMap, TState> = Extract<keyof TConfig, keyof TState>;
|
|
1965
|
+
type ValidatedState<TConfig extends StateConfigMap, TState extends Partial<Record<keyof TConfig, unknown>>> = {
|
|
1966
|
+
[K in InputStateKeys<TConfig, TState> | DefaultedKeys<TConfig>]: ChannelValue<TConfig[K]>;
|
|
1967
|
+
};
|
|
1922
1968
|
/**
|
|
1923
1969
|
* Create a type-safe state annotation with optional Zod validation
|
|
1924
1970
|
*
|
|
@@ -1949,7 +1995,7 @@ interface StateChannelConfig<T = any, U = T> {
|
|
|
1949
1995
|
* type State = typeof AgentState.State;
|
|
1950
1996
|
* ```
|
|
1951
1997
|
*/
|
|
1952
|
-
declare function createStateAnnotation<
|
|
1998
|
+
declare function createStateAnnotation<TConfig extends StateConfigMap>(config: TConfig): AnnotationRoot<StateAnnotationDefinition<TConfig>>;
|
|
1953
1999
|
/**
|
|
1954
2000
|
* Validate state against Zod schemas
|
|
1955
2001
|
*
|
|
@@ -1971,7 +2017,7 @@ declare function createStateAnnotation<T extends Record<string, StateChannelConf
|
|
|
1971
2017
|
* );
|
|
1972
2018
|
* ```
|
|
1973
2019
|
*/
|
|
1974
|
-
declare function validateState<
|
|
2020
|
+
declare function validateState<TConfig extends StateConfigMap, TState extends Partial<Record<keyof TConfig, unknown>>>(state: TState, config: TConfig): ValidatedState<TConfig, TState>;
|
|
1975
2021
|
/**
|
|
1976
2022
|
* Merge state updates using configured reducers
|
|
1977
2023
|
*
|
|
@@ -1996,7 +2042,7 @@ declare function validateState<T extends Record<string, StateChannelConfig>>(sta
|
|
|
1996
2042
|
* // Result: { messages: ['a', 'b', 'c'] }
|
|
1997
2043
|
* ```
|
|
1998
2044
|
*/
|
|
1999
|
-
declare function mergeState<
|
|
2045
|
+
declare function mergeState<TConfig extends StateConfigMap>(currentState: Partial<StateShape<TConfig>>, update: StateUpdateShape<TConfig>, config: TConfig): Partial<StateShape<TConfig>>;
|
|
2000
2046
|
|
|
2001
2047
|
/**
|
|
2002
2048
|
* Sequential Workflow Builder
|
|
@@ -2770,11 +2816,21 @@ interface ErrorHandlerOptions<State> {
|
|
|
2770
2816
|
*/
|
|
2771
2817
|
declare function withErrorHandler<State>(node: (state: State) => State | Promise<State> | Partial<State> | Promise<Partial<State>>, options: ErrorHandlerOptions<State>): (state: State) => Promise<State | Partial<State>>;
|
|
2772
2818
|
|
|
2819
|
+
/**
|
|
2820
|
+
* Shared JSON-safe payload contracts for observability and monitoring paths.
|
|
2821
|
+
*/
|
|
2822
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
2823
|
+
type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
2824
|
+
interface JsonObject {
|
|
2825
|
+
[key: string]: JsonValue;
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2773
2828
|
/**
|
|
2774
2829
|
* Structured Logging Utilities
|
|
2775
2830
|
*
|
|
2776
2831
|
* Provides consistent, structured logging for LangGraph agents.
|
|
2777
2832
|
*/
|
|
2833
|
+
|
|
2778
2834
|
/**
|
|
2779
2835
|
* Log levels
|
|
2780
2836
|
*/
|
|
@@ -2822,8 +2878,8 @@ interface LogEntry {
|
|
|
2822
2878
|
name: string;
|
|
2823
2879
|
message: string;
|
|
2824
2880
|
timestamp?: string;
|
|
2825
|
-
context?:
|
|
2826
|
-
data?:
|
|
2881
|
+
context?: JsonObject;
|
|
2882
|
+
data?: JsonValue;
|
|
2827
2883
|
}
|
|
2828
2884
|
/**
|
|
2829
2885
|
* Logger interface
|
|
@@ -2832,19 +2888,19 @@ interface Logger {
|
|
|
2832
2888
|
/**
|
|
2833
2889
|
* Log a debug message
|
|
2834
2890
|
*/
|
|
2835
|
-
debug(message: string, data?:
|
|
2891
|
+
debug(message: string, data?: JsonValue): void;
|
|
2836
2892
|
/**
|
|
2837
2893
|
* Log an info message
|
|
2838
2894
|
*/
|
|
2839
|
-
info(message: string, data?:
|
|
2895
|
+
info(message: string, data?: JsonValue): void;
|
|
2840
2896
|
/**
|
|
2841
2897
|
* Log a warning message
|
|
2842
2898
|
*/
|
|
2843
|
-
warn(message: string, data?:
|
|
2899
|
+
warn(message: string, data?: JsonValue): void;
|
|
2844
2900
|
/**
|
|
2845
2901
|
* Log an error message
|
|
2846
2902
|
*/
|
|
2847
|
-
error(message: string, data?:
|
|
2903
|
+
error(message: string, data?: JsonValue): void;
|
|
2848
2904
|
/**
|
|
2849
2905
|
* Check if debug logging is enabled
|
|
2850
2906
|
* Useful for avoiding expensive computations when debug is disabled
|
|
@@ -2857,7 +2913,7 @@ interface Logger {
|
|
|
2857
2913
|
/**
|
|
2858
2914
|
* Create a child logger with additional context
|
|
2859
2915
|
*/
|
|
2860
|
-
withContext(context:
|
|
2916
|
+
withContext(context: JsonObject): Logger;
|
|
2861
2917
|
}
|
|
2862
2918
|
/**
|
|
2863
2919
|
* Create a structured logger.
|
|
@@ -5288,47 +5344,80 @@ declare function createProfiler(options?: ProfilerOptions): Profiler;
|
|
|
5288
5344
|
/**
|
|
5289
5345
|
* Alert system for production monitoring
|
|
5290
5346
|
*/
|
|
5347
|
+
|
|
5291
5348
|
type AlertSeverity = 'info' | 'warning' | 'error' | 'critical';
|
|
5292
|
-
interface Alert {
|
|
5349
|
+
interface Alert<TData extends JsonObject = JsonObject> {
|
|
5293
5350
|
name: string;
|
|
5294
5351
|
severity: AlertSeverity;
|
|
5295
5352
|
message: string;
|
|
5296
5353
|
timestamp?: number;
|
|
5297
|
-
data?:
|
|
5298
|
-
}
|
|
5299
|
-
interface AlertChannel {
|
|
5300
|
-
type: string;
|
|
5301
|
-
config: Record<string, any>;
|
|
5354
|
+
data?: TData;
|
|
5302
5355
|
}
|
|
5303
|
-
|
|
5356
|
+
type BuiltInAlertChannelType = 'email' | 'slack' | 'webhook';
|
|
5357
|
+
type EmailAlertChannelConfig = JsonObject & {
|
|
5358
|
+
to: string | string[];
|
|
5359
|
+
};
|
|
5360
|
+
type SlackAlertChannelConfig = JsonObject & {
|
|
5361
|
+
webhookUrl: string;
|
|
5362
|
+
};
|
|
5363
|
+
type WebhookAlertChannelConfig = JsonObject & {
|
|
5364
|
+
url: string;
|
|
5365
|
+
};
|
|
5366
|
+
interface EmailAlertChannel {
|
|
5367
|
+
type: 'email';
|
|
5368
|
+
config: EmailAlertChannelConfig;
|
|
5369
|
+
}
|
|
5370
|
+
interface SlackAlertChannel {
|
|
5371
|
+
type: 'slack';
|
|
5372
|
+
config: SlackAlertChannelConfig;
|
|
5373
|
+
}
|
|
5374
|
+
interface WebhookAlertChannel {
|
|
5375
|
+
type: 'webhook';
|
|
5376
|
+
config: WebhookAlertChannelConfig;
|
|
5377
|
+
}
|
|
5378
|
+
interface GenericAlertChannel<TType extends string = string, TConfig extends JsonObject = JsonObject> {
|
|
5379
|
+
type: TType;
|
|
5380
|
+
config: TConfig;
|
|
5381
|
+
}
|
|
5382
|
+
type CustomAlertChannel<TType extends string = string, TConfig extends JsonObject = JsonObject> = GenericAlertChannel<Exclude<TType, BuiltInAlertChannelType>, TConfig>;
|
|
5383
|
+
type AlertChannel<TType extends string = string, TConfig extends JsonObject = JsonObject> = TType extends 'email' ? EmailAlertChannel : TType extends 'slack' ? SlackAlertChannel : TType extends 'webhook' ? WebhookAlertChannel : GenericAlertChannel<TType, TConfig>;
|
|
5384
|
+
type AlertChannelMap = Record<string, GenericAlertChannel>;
|
|
5385
|
+
type ValidatedAlertChannels<TChannels extends AlertChannelMap> = {
|
|
5386
|
+
[TName in keyof TChannels]: TChannels[TName] extends GenericAlertChannel<infer TType, infer TConfig> ? AlertChannel<TType, TConfig> : never;
|
|
5387
|
+
};
|
|
5388
|
+
type AlertChannelName<TChannels extends AlertChannelMap> = keyof ValidatedAlertChannels<TChannels> & string;
|
|
5389
|
+
interface AlertRule<TMetrics extends JsonObject = JsonObject, TChannelName extends string = string> {
|
|
5304
5390
|
name: string;
|
|
5305
|
-
condition: (metrics:
|
|
5391
|
+
condition: (metrics: TMetrics) => boolean;
|
|
5306
5392
|
severity: AlertSeverity;
|
|
5307
|
-
channels:
|
|
5393
|
+
channels: TChannelName[];
|
|
5308
5394
|
throttle?: number;
|
|
5309
5395
|
message?: string;
|
|
5310
5396
|
}
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5397
|
+
type AlertCallbackData<TMetrics extends JsonObject> = JsonObject & {
|
|
5398
|
+
metrics?: TMetrics;
|
|
5399
|
+
};
|
|
5400
|
+
interface AlertManagerOptions<TMetrics extends JsonObject = JsonObject, TChannels extends AlertChannelMap = Record<string, GenericAlertChannel>> {
|
|
5401
|
+
channels: ValidatedAlertChannels<TChannels>;
|
|
5402
|
+
rules?: AlertRule<TMetrics, AlertChannelName<TChannels>>[];
|
|
5403
|
+
onAlert?: (alert: Alert<AlertCallbackData<TMetrics>>) => void | Promise<void>;
|
|
5315
5404
|
}
|
|
5316
|
-
declare class AlertManager {
|
|
5405
|
+
declare class AlertManager<TMetrics extends JsonObject = JsonObject, TChannels extends AlertChannelMap = Record<string, GenericAlertChannel>> {
|
|
5317
5406
|
private options;
|
|
5318
5407
|
private lastAlertTime;
|
|
5319
5408
|
private monitorTimer?;
|
|
5320
5409
|
private running;
|
|
5321
|
-
constructor(options: AlertManagerOptions);
|
|
5322
|
-
start(metrics?: () =>
|
|
5410
|
+
constructor(options: AlertManagerOptions<TMetrics, TChannels>);
|
|
5411
|
+
start(metrics?: () => TMetrics, interval?: number): void;
|
|
5323
5412
|
stop(): void;
|
|
5324
|
-
alert(alert: Alert): Promise<void>;
|
|
5413
|
+
alert(alert: Alert<AlertCallbackData<TMetrics>>): Promise<void>;
|
|
5325
5414
|
private checkRules;
|
|
5326
5415
|
private isThrottled;
|
|
5327
|
-
sendToChannel(channelName: string, alert: Alert): Promise<void>;
|
|
5328
|
-
getAlertHistory(
|
|
5416
|
+
sendToChannel(channelName: keyof TChannels & string, alert: Alert<AlertCallbackData<TMetrics>>): Promise<void>;
|
|
5417
|
+
getAlertHistory(_name?: string, _limit?: number): Alert<AlertCallbackData<TMetrics>>[];
|
|
5329
5418
|
clearAlertHistory(name?: string): void;
|
|
5330
5419
|
}
|
|
5331
|
-
declare function createAlertManager(options: AlertManagerOptions): AlertManager
|
|
5420
|
+
declare function createAlertManager<TMetrics extends JsonObject = JsonObject, TChannels extends AlertChannelMap = Record<string, GenericAlertChannel>>(options: AlertManagerOptions<TMetrics, TChannels>): AlertManager<TMetrics, TChannels>;
|
|
5332
5421
|
|
|
5333
5422
|
/**
|
|
5334
5423
|
* Audit logging for compliance and tracking
|
|
@@ -5502,4 +5591,4 @@ declare function renderTemplate(template: string, options: RenderTemplateOptions
|
|
|
5502
5591
|
*/
|
|
5503
5592
|
declare function loadPrompt(promptName: string, options?: RenderTemplateOptions | Record<string, any>, promptsDir?: string): string;
|
|
5504
5593
|
|
|
5505
|
-
export { AgentError, type AgentResumedEventData, type AgentWaitingEventData, type AggregateNode, type Alert, type AlertChannel, AlertManager, type AlertManagerOptions, type AlertRule, type AlertSeverity, type AnyInterrupt, type ApprovalRequiredInterrupt, type AuditLogEntry, type AuditLogQuery, AuditLogger, type AuditLoggerOptions, type BackoffStrategy, type BatchOptions, BatchProcessor, type BatchProcessorOptions, type BatchStats, type CacheKeyGenerator, type CachingOptions, type CheckInterruptOptions, type CheckpointHistoryOptions, type CheckpointerOptions, type ChunkOptions, CircuitBreaker, type CircuitBreakerOptions, type CircuitBreakerStats, type CircuitState, type ComposeGraphsOptions, type ComposeOptions, type ComposeToolConfig, type ComposedTool, type ConcurrencyOptions, type ConditionalConfig, type ConditionalRouter, type ConditionalRouterConfig, ConnectionPool, type ConnectionPoolOptions, type ConversationConfig, type CustomInterrupt, type DatabaseConfig, type DatabaseConnection, DatabasePool, type DatabasePoolOptions, type DevelopmentPresetOptions, type ErrorContext, type ErrorHandlerOptions, type ErrorReporter, type ErrorReporterOptions, type EventHandler, type EvictionStrategy, type ExecutionMetrics, type HealthCheck, type HealthCheckConfig, type HealthCheckResult, HealthChecker, type HealthCheckerOptions, type HealthReport, type HealthStatus, type HttpClient, type HttpConfig, HttpPool, type HttpPoolConfig, type HttpPoolOptions, type HttpResponse, type HumanInLoopEventData, type HumanInLoopEventType, type HumanRequest, type HumanRequestEventData, type HumanRequestInterrupt, type HumanRequestPriority, type HumanRequestStatus, type HumanResponseEventData, type InterruptData, type InterruptEventData, type InterruptType, type LangSmithConfig, type LogEntry, LogLevel, type Logger, type LoggerOptions, type LoggingOptions, ManagedTool, type ManagedToolConfig, type ManagedToolStats, MemoryManager, type MemoryManagerOptions, type MemoryStats, type MetricEntry, MetricType, type Metrics, type MetricsNodeOptions, type Middleware, MiddlewareChain, type MiddlewareContext, type MiddlewareFactory, type MiddlewareMetadata, type MiddlewareWithMetadata, MissingDescriptionError, type MockToolConfig, type MockToolResponse, type NodeFunction, type NodeFunctionWithContext, type ParallelNode, type ParallelWorkflowConfig, type ParallelWorkflowOptions, type PoolConfig, type PoolStats, type Priority$1 as Priority, type ProductionPresetOptions, type ProfileReport, type ProfileSample, type ProfileStats, Profiler, type ProfilerOptions, type Progress, type ProgressTracker, type ProgressTrackerOptions, type PromptOptions, type RateLimitOptions, type RateLimitStrategy, type ReducerFunction, RegistryEvent, type RenderTemplateOptions, type RequestConfig, type ResumeCommand, type ResumeEventData, type ResumeOptions, type RetryOptions, type RetryPolicy, type RouteCondition, type RouteMap, type RouteName, type SSEEvent, type SSEFormatter, type SSEFormatterOptions, type SequentialNode, type SequentialWorkflowOptions, type SimpleMiddleware, type SqliteCheckpointerOptions, type StateChannelConfig, type SubgraphBuilder, type TestingPresetOptions, type ThreadConfig, type ThreadInfo, type ThreadStatus, type ThrottleOptions, TimeoutError, type TimeoutOptions, type Timer, type Tool, type BackoffStrategy$1 as ToolBackoffStrategy, ToolBuilder, ToolCategory, ToolCategorySchema, type ToolExample, ToolExampleSchema, type ToolExecution, type ToolExecutorConfig, type ToolHealthCheckResult, type ToolInvocation, type ToolMetadata, ToolMetadataSchema, ToolNameSchema, ToolRegistry, type ToolRelations, ToolRelationsSchema, type ToolSimulatorConfig, type TracingOptions, type ValidationErrorHandler, type ValidationMode, type ValidationOptions, type ValidatorFunction, type WebSocketHandlerOptions, type WebSocketMessage, batch, broadcast, cache, chain, chunk, clearThread, collect, compose, composeGraphs, composeTool, composeWithOptions, conditional, configureLangSmith, createAlertManager, createApprovalRequiredInterrupt, createAuditLogger, createBatchProcessor, createBinaryRouter, createCircuitBreaker, createConditionalRouter, createConnectionPool, createConversationConfig, createCustomInterrupt, createDatabasePool, createErrorReporter, createHealthChecker, createHeartbeat, createHttpPool, createHumanRequestInterrupt, createLogger, createManagedTool, createMemoryCheckpointer, createMemoryManager, createMessage, createMetrics, createMiddlewareContext, createMockTool, createMultiRouter, createParallelWorkflow, createProfiler, createProgressTracker, createSSEFormatter, createSequentialWorkflow, createSharedCache, createSharedConcurrencyController, createSharedRateLimiter, createSqliteCheckpointer, createStateAnnotation, createSubgraph, createThreadConfig, createTool, createToolExecutor, createToolSimulator, createToolUnsafe, createWebSocketHandler, development, filter, formatAgentResumedEvent, formatAgentWaitingEvent, formatHumanRequestEvent, formatHumanResponseEvent, formatInterruptEvent, formatResumeEvent, generateThreadId, getCheckpointHistory, getLangSmithConfig, getLatestCheckpoint, getMissingDescriptions, getThreadStatus, getToolDescription, getToolJsonSchema, isApprovalRequiredInterrupt, isCustomInterrupt, isHumanRequestInterrupt, isMemoryCheckpointer, isTracingEnabled, loadPrompt, map, merge, mergeState, parallel, parseSSEEvent, presets, production, reduce, renderTemplate, retry, safeValidateSchemaDescriptions, sanitizeValue, sendMessage, sequential, sequentialBuilder, take, testing, throttle, timeout, toLangChainTool, toLangChainTools, toolBuilder, validateSchemaDescriptions, validateState, validateTool, validateToolMetadata, validateToolName, withCache, withConcurrency, withErrorHandler, withLogging, withMetrics, withRateLimit, withRetry, withTimeout, withTracing, withValidation };
|
|
5594
|
+
export { AgentError, type AgentResumedEventData, type AgentWaitingEventData, type AggregateNode, type Alert, type AlertChannel, AlertManager, type AlertManagerOptions, type AlertRule, type AlertSeverity, type AnyInterrupt, type ApprovalRequiredInterrupt, type AuditLogEntry, type AuditLogQuery, AuditLogger, type AuditLoggerOptions, type BackoffStrategy, type BatchOptions, BatchProcessor, type BatchProcessorOptions, type BatchStats, type CacheKeyGenerator, type CachingOptions, type CheckInterruptOptions, type CheckpointHistoryOptions, type CheckpointerOptions, type ChunkOptions, CircuitBreaker, type CircuitBreakerOptions, type CircuitBreakerStats, type CircuitState, type ComposeGraphsOptions, type ComposeOptions, type ComposeToolConfig, type ComposedTool, type ConcurrencyOptions, type ConditionalConfig, type ConditionalRouter, type ConditionalRouterConfig, ConnectionPool, type ConnectionPoolOptions, type ConversationConfig, type CustomAlertChannel, type CustomInterrupt, type DatabaseConfig, type DatabaseConnection, DatabasePool, type DatabasePoolOptions, type DevelopmentPresetOptions, type EmailAlertChannel, type ErrorContext, type ErrorHandlerOptions, type ErrorReporter, type ErrorReporterOptions, type EventHandler, type EvictionStrategy, type ExecutionMetrics, type GenericAlertChannel, type HealthCheck, type HealthCheckConfig, type HealthCheckResult, HealthChecker, type HealthCheckerOptions, type HealthReport, type HealthStatus, type HttpClient, type HttpConfig, HttpPool, type HttpPoolConfig, type HttpPoolOptions, type HttpResponse, type HumanInLoopEventData, type HumanInLoopEventType, type HumanRequest, type HumanRequestEventData, type HumanRequestInterrupt, type HumanRequestPriority, type HumanRequestStatus, type HumanResponseEventData, type InterruptData, type InterruptEventData, type InterruptType, type JsonObject, type JsonPrimitive, type JsonValue, type LangSmithConfig, type LogEntry, LogLevel, type Logger, type LoggerOptions, type LoggingOptions, ManagedTool, type ManagedToolConfig, type ManagedToolStats, MemoryManager, type MemoryManagerOptions, type MemoryStats, type MetricEntry, MetricType, type Metrics, type MetricsNodeOptions, type Middleware, MiddlewareChain, type MiddlewareContext, type MiddlewareFactory, type MiddlewareMetadata, type MiddlewareWithMetadata, MissingDescriptionError, type MockToolConfig, type MockToolResponse, type NodeFunction, type NodeFunctionWithContext, type ParallelNode, type ParallelWorkflowConfig, type ParallelWorkflowOptions, type PoolConfig, type PoolStats, type Priority$1 as Priority, type ProductionPresetOptions, type ProfileReport, type ProfileSample, type ProfileStats, Profiler, type ProfilerOptions, type Progress, type ProgressTracker, type ProgressTrackerOptions, type PromptOptions, type RateLimitOptions, type RateLimitStrategy, type ReducerFunction, RegistryEvent, type RenderTemplateOptions, type RequestConfig, type ResumeCommand, type ResumeEventData, type ResumeOptions, type RetryOptions, type RetryPolicy, type RouteCondition, type RouteMap, type RouteName, type SSEEvent, type SSEFormatter, type SSEFormatterOptions, type SequentialNode, type SequentialWorkflowOptions, type SimpleMiddleware, type SlackAlertChannel, type SqliteCheckpointerOptions, type StateChannelConfig, type SubgraphBuilder, type TestingPresetOptions, type ThreadConfig, type ThreadInfo, type ThreadStatus, type ThrottleOptions, TimeoutError, type TimeoutOptions, type Timer, type Tool, type BackoffStrategy$1 as ToolBackoffStrategy, ToolBuilder, ToolCategory, ToolCategorySchema, type ToolExample, ToolExampleSchema, type ToolExecution, type ToolExecutorConfig, type ToolHealthCheckResult, type ToolInvocation, type ToolMetadata, ToolMetadataSchema, ToolNameSchema, ToolRegistry, type ToolRelations, ToolRelationsSchema, type ToolSimulatorConfig, type TracingOptions, type ValidationErrorHandler, type ValidationMode, type ValidationOptions, type ValidatorFunction, type WebSocketHandlerOptions, type WebSocketMessage, type WebhookAlertChannel, batch, broadcast, cache, chain, chunk, clearThread, collect, compose, composeGraphs, composeTool, composeWithOptions, conditional, configureLangSmith, createAlertManager, createApprovalRequiredInterrupt, createAuditLogger, createBatchProcessor, createBinaryRouter, createCircuitBreaker, createConditionalRouter, createConnectionPool, createConversationConfig, createCustomInterrupt, createDatabasePool, createErrorReporter, createHealthChecker, createHeartbeat, createHttpPool, createHumanRequestInterrupt, createLogger, createManagedTool, createMemoryCheckpointer, createMemoryManager, createMessage, createMetrics, createMiddlewareContext, createMockTool, createMultiRouter, createParallelWorkflow, createProfiler, createProgressTracker, createSSEFormatter, createSequentialWorkflow, createSharedCache, createSharedConcurrencyController, createSharedRateLimiter, createSqliteCheckpointer, createStateAnnotation, createSubgraph, createThreadConfig, createTool, createToolExecutor, createToolSimulator, createToolUnsafe, createWebSocketHandler, development, filter, formatAgentResumedEvent, formatAgentWaitingEvent, formatHumanRequestEvent, formatHumanResponseEvent, formatInterruptEvent, formatResumeEvent, generateThreadId, getCheckpointHistory, getLangSmithConfig, getLatestCheckpoint, getMissingDescriptions, getThreadStatus, getToolDescription, getToolJsonSchema, isApprovalRequiredInterrupt, isCustomInterrupt, isHumanRequestInterrupt, isMemoryCheckpointer, isTracingEnabled, loadPrompt, map, merge, mergeState, parallel, parseSSEEvent, presets, production, reduce, renderTemplate, retry, safeValidateSchemaDescriptions, sanitizeValue, sendMessage, sequential, sequentialBuilder, take, testing, throttle, timeout, toLangChainTool, toLangChainTools, toolBuilder, validateSchemaDescriptions, validateState, validateTool, validateToolMetadata, validateToolName, withCache, withConcurrency, withErrorHandler, withLogging, withMetrics, withRateLimit, withRetry, withTimeout, withTracing, withValidation };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { z, ZodType, ZodTypeDef } from 'zod';
|
|
1
|
+
import { z, ZodTypeAny, output, ZodType, ZodTypeDef } from 'zod';
|
|
2
2
|
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
3
|
-
import { AnnotationRoot,
|
|
3
|
+
import { AnnotationRoot, BaseChannel, StateGraph, END, MemorySaver, BaseCheckpointSaver, CheckpointTuple } from '@langchain/langgraph';
|
|
4
4
|
import { RunnableConfig } from '@langchain/core/runnables';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1901,11 +1901,11 @@ declare function getToolDescription<TInput, TOutput>(tool: Tool<TInput, TOutput>
|
|
|
1901
1901
|
/**
|
|
1902
1902
|
* State channel configuration with optional Zod schema validation
|
|
1903
1903
|
*/
|
|
1904
|
-
interface StateChannelConfig<T =
|
|
1904
|
+
interface StateChannelConfig<T = unknown, U = T> {
|
|
1905
1905
|
/**
|
|
1906
1906
|
* Optional Zod schema for runtime validation
|
|
1907
1907
|
*/
|
|
1908
|
-
schema?: ZodType<T, ZodTypeDef,
|
|
1908
|
+
schema?: ZodType<T, ZodTypeDef, unknown>;
|
|
1909
1909
|
/**
|
|
1910
1910
|
* Optional reducer function for aggregating updates
|
|
1911
1911
|
*/
|
|
@@ -1919,6 +1919,52 @@ interface StateChannelConfig<T = any, U = T> {
|
|
|
1919
1919
|
*/
|
|
1920
1920
|
description?: string;
|
|
1921
1921
|
}
|
|
1922
|
+
type StateChannelConfigLike = {
|
|
1923
|
+
schema?: ZodTypeAny;
|
|
1924
|
+
reducer?: (left: never, right: never) => unknown;
|
|
1925
|
+
default?: () => unknown;
|
|
1926
|
+
description?: string;
|
|
1927
|
+
};
|
|
1928
|
+
type StateConfigMap = Record<string, StateChannelConfigLike>;
|
|
1929
|
+
type IsExact<TLeft, TRight> = [
|
|
1930
|
+
TLeft
|
|
1931
|
+
] extends [TRight] ? ([TRight] extends [TLeft] ? true : false) : false;
|
|
1932
|
+
type HasReducer<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1933
|
+
reducer: (left: unknown, right: unknown) => unknown;
|
|
1934
|
+
} ? true : false;
|
|
1935
|
+
type SchemaValue<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1936
|
+
schema: infer TSchema extends ZodTypeAny;
|
|
1937
|
+
} ? output<TSchema> : never;
|
|
1938
|
+
type DefaultValue<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1939
|
+
default: () => infer TValue;
|
|
1940
|
+
} ? TValue : never;
|
|
1941
|
+
type ReducerValue<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1942
|
+
reducer: (left: infer TValue, right: unknown) => infer TResult;
|
|
1943
|
+
} ? IsExact<TValue, TResult> extends true ? TValue : never : never;
|
|
1944
|
+
type ReducerUpdate<TChannel extends StateChannelConfigLike> = TChannel extends {
|
|
1945
|
+
reducer: (left: unknown, right: infer TUpdate) => unknown;
|
|
1946
|
+
} ? TUpdate : never;
|
|
1947
|
+
type ChannelValue<TChannel extends StateChannelConfigLike> = HasReducer<TChannel> extends true ? ReducerValue<TChannel> : [SchemaValue<TChannel>] extends [never] ? [DefaultValue<TChannel>] extends [never] ? unknown : DefaultValue<TChannel> : SchemaValue<TChannel>;
|
|
1948
|
+
type ChannelUpdate<TChannel extends StateChannelConfigLike> = HasReducer<TChannel> extends true ? ReducerUpdate<TChannel> : ChannelValue<TChannel>;
|
|
1949
|
+
type StateShape<TConfig extends StateConfigMap> = {
|
|
1950
|
+
[K in keyof TConfig]: ChannelValue<TConfig[K]>;
|
|
1951
|
+
};
|
|
1952
|
+
type StateUpdateShape<TConfig extends StateConfigMap> = {
|
|
1953
|
+
[K in keyof TConfig]?: ChannelUpdate<TConfig[K]>;
|
|
1954
|
+
};
|
|
1955
|
+
type StateChannelDefinition<TChannel extends StateChannelConfigLike> = BaseChannel<ChannelValue<TChannel>, ChannelUpdate<TChannel>>;
|
|
1956
|
+
type StateAnnotationDefinition<TConfig extends StateConfigMap> = {
|
|
1957
|
+
[K in keyof TConfig]: StateChannelDefinition<TConfig[K]>;
|
|
1958
|
+
};
|
|
1959
|
+
type DefaultedKeys<TConfig extends StateConfigMap> = {
|
|
1960
|
+
[K in keyof TConfig]-?: TConfig[K] extends {
|
|
1961
|
+
default: () => ChannelValue<TConfig[K]>;
|
|
1962
|
+
} ? K : never;
|
|
1963
|
+
}[keyof TConfig];
|
|
1964
|
+
type InputStateKeys<TConfig extends StateConfigMap, TState> = Extract<keyof TConfig, keyof TState>;
|
|
1965
|
+
type ValidatedState<TConfig extends StateConfigMap, TState extends Partial<Record<keyof TConfig, unknown>>> = {
|
|
1966
|
+
[K in InputStateKeys<TConfig, TState> | DefaultedKeys<TConfig>]: ChannelValue<TConfig[K]>;
|
|
1967
|
+
};
|
|
1922
1968
|
/**
|
|
1923
1969
|
* Create a type-safe state annotation with optional Zod validation
|
|
1924
1970
|
*
|
|
@@ -1949,7 +1995,7 @@ interface StateChannelConfig<T = any, U = T> {
|
|
|
1949
1995
|
* type State = typeof AgentState.State;
|
|
1950
1996
|
* ```
|
|
1951
1997
|
*/
|
|
1952
|
-
declare function createStateAnnotation<
|
|
1998
|
+
declare function createStateAnnotation<TConfig extends StateConfigMap>(config: TConfig): AnnotationRoot<StateAnnotationDefinition<TConfig>>;
|
|
1953
1999
|
/**
|
|
1954
2000
|
* Validate state against Zod schemas
|
|
1955
2001
|
*
|
|
@@ -1971,7 +2017,7 @@ declare function createStateAnnotation<T extends Record<string, StateChannelConf
|
|
|
1971
2017
|
* );
|
|
1972
2018
|
* ```
|
|
1973
2019
|
*/
|
|
1974
|
-
declare function validateState<
|
|
2020
|
+
declare function validateState<TConfig extends StateConfigMap, TState extends Partial<Record<keyof TConfig, unknown>>>(state: TState, config: TConfig): ValidatedState<TConfig, TState>;
|
|
1975
2021
|
/**
|
|
1976
2022
|
* Merge state updates using configured reducers
|
|
1977
2023
|
*
|
|
@@ -1996,7 +2042,7 @@ declare function validateState<T extends Record<string, StateChannelConfig>>(sta
|
|
|
1996
2042
|
* // Result: { messages: ['a', 'b', 'c'] }
|
|
1997
2043
|
* ```
|
|
1998
2044
|
*/
|
|
1999
|
-
declare function mergeState<
|
|
2045
|
+
declare function mergeState<TConfig extends StateConfigMap>(currentState: Partial<StateShape<TConfig>>, update: StateUpdateShape<TConfig>, config: TConfig): Partial<StateShape<TConfig>>;
|
|
2000
2046
|
|
|
2001
2047
|
/**
|
|
2002
2048
|
* Sequential Workflow Builder
|
|
@@ -2770,11 +2816,21 @@ interface ErrorHandlerOptions<State> {
|
|
|
2770
2816
|
*/
|
|
2771
2817
|
declare function withErrorHandler<State>(node: (state: State) => State | Promise<State> | Partial<State> | Promise<Partial<State>>, options: ErrorHandlerOptions<State>): (state: State) => Promise<State | Partial<State>>;
|
|
2772
2818
|
|
|
2819
|
+
/**
|
|
2820
|
+
* Shared JSON-safe payload contracts for observability and monitoring paths.
|
|
2821
|
+
*/
|
|
2822
|
+
type JsonPrimitive = string | number | boolean | null;
|
|
2823
|
+
type JsonValue = JsonPrimitive | JsonObject | JsonValue[];
|
|
2824
|
+
interface JsonObject {
|
|
2825
|
+
[key: string]: JsonValue;
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2773
2828
|
/**
|
|
2774
2829
|
* Structured Logging Utilities
|
|
2775
2830
|
*
|
|
2776
2831
|
* Provides consistent, structured logging for LangGraph agents.
|
|
2777
2832
|
*/
|
|
2833
|
+
|
|
2778
2834
|
/**
|
|
2779
2835
|
* Log levels
|
|
2780
2836
|
*/
|
|
@@ -2822,8 +2878,8 @@ interface LogEntry {
|
|
|
2822
2878
|
name: string;
|
|
2823
2879
|
message: string;
|
|
2824
2880
|
timestamp?: string;
|
|
2825
|
-
context?:
|
|
2826
|
-
data?:
|
|
2881
|
+
context?: JsonObject;
|
|
2882
|
+
data?: JsonValue;
|
|
2827
2883
|
}
|
|
2828
2884
|
/**
|
|
2829
2885
|
* Logger interface
|
|
@@ -2832,19 +2888,19 @@ interface Logger {
|
|
|
2832
2888
|
/**
|
|
2833
2889
|
* Log a debug message
|
|
2834
2890
|
*/
|
|
2835
|
-
debug(message: string, data?:
|
|
2891
|
+
debug(message: string, data?: JsonValue): void;
|
|
2836
2892
|
/**
|
|
2837
2893
|
* Log an info message
|
|
2838
2894
|
*/
|
|
2839
|
-
info(message: string, data?:
|
|
2895
|
+
info(message: string, data?: JsonValue): void;
|
|
2840
2896
|
/**
|
|
2841
2897
|
* Log a warning message
|
|
2842
2898
|
*/
|
|
2843
|
-
warn(message: string, data?:
|
|
2899
|
+
warn(message: string, data?: JsonValue): void;
|
|
2844
2900
|
/**
|
|
2845
2901
|
* Log an error message
|
|
2846
2902
|
*/
|
|
2847
|
-
error(message: string, data?:
|
|
2903
|
+
error(message: string, data?: JsonValue): void;
|
|
2848
2904
|
/**
|
|
2849
2905
|
* Check if debug logging is enabled
|
|
2850
2906
|
* Useful for avoiding expensive computations when debug is disabled
|
|
@@ -2857,7 +2913,7 @@ interface Logger {
|
|
|
2857
2913
|
/**
|
|
2858
2914
|
* Create a child logger with additional context
|
|
2859
2915
|
*/
|
|
2860
|
-
withContext(context:
|
|
2916
|
+
withContext(context: JsonObject): Logger;
|
|
2861
2917
|
}
|
|
2862
2918
|
/**
|
|
2863
2919
|
* Create a structured logger.
|
|
@@ -5288,47 +5344,80 @@ declare function createProfiler(options?: ProfilerOptions): Profiler;
|
|
|
5288
5344
|
/**
|
|
5289
5345
|
* Alert system for production monitoring
|
|
5290
5346
|
*/
|
|
5347
|
+
|
|
5291
5348
|
type AlertSeverity = 'info' | 'warning' | 'error' | 'critical';
|
|
5292
|
-
interface Alert {
|
|
5349
|
+
interface Alert<TData extends JsonObject = JsonObject> {
|
|
5293
5350
|
name: string;
|
|
5294
5351
|
severity: AlertSeverity;
|
|
5295
5352
|
message: string;
|
|
5296
5353
|
timestamp?: number;
|
|
5297
|
-
data?:
|
|
5298
|
-
}
|
|
5299
|
-
interface AlertChannel {
|
|
5300
|
-
type: string;
|
|
5301
|
-
config: Record<string, any>;
|
|
5354
|
+
data?: TData;
|
|
5302
5355
|
}
|
|
5303
|
-
|
|
5356
|
+
type BuiltInAlertChannelType = 'email' | 'slack' | 'webhook';
|
|
5357
|
+
type EmailAlertChannelConfig = JsonObject & {
|
|
5358
|
+
to: string | string[];
|
|
5359
|
+
};
|
|
5360
|
+
type SlackAlertChannelConfig = JsonObject & {
|
|
5361
|
+
webhookUrl: string;
|
|
5362
|
+
};
|
|
5363
|
+
type WebhookAlertChannelConfig = JsonObject & {
|
|
5364
|
+
url: string;
|
|
5365
|
+
};
|
|
5366
|
+
interface EmailAlertChannel {
|
|
5367
|
+
type: 'email';
|
|
5368
|
+
config: EmailAlertChannelConfig;
|
|
5369
|
+
}
|
|
5370
|
+
interface SlackAlertChannel {
|
|
5371
|
+
type: 'slack';
|
|
5372
|
+
config: SlackAlertChannelConfig;
|
|
5373
|
+
}
|
|
5374
|
+
interface WebhookAlertChannel {
|
|
5375
|
+
type: 'webhook';
|
|
5376
|
+
config: WebhookAlertChannelConfig;
|
|
5377
|
+
}
|
|
5378
|
+
interface GenericAlertChannel<TType extends string = string, TConfig extends JsonObject = JsonObject> {
|
|
5379
|
+
type: TType;
|
|
5380
|
+
config: TConfig;
|
|
5381
|
+
}
|
|
5382
|
+
type CustomAlertChannel<TType extends string = string, TConfig extends JsonObject = JsonObject> = GenericAlertChannel<Exclude<TType, BuiltInAlertChannelType>, TConfig>;
|
|
5383
|
+
type AlertChannel<TType extends string = string, TConfig extends JsonObject = JsonObject> = TType extends 'email' ? EmailAlertChannel : TType extends 'slack' ? SlackAlertChannel : TType extends 'webhook' ? WebhookAlertChannel : GenericAlertChannel<TType, TConfig>;
|
|
5384
|
+
type AlertChannelMap = Record<string, GenericAlertChannel>;
|
|
5385
|
+
type ValidatedAlertChannels<TChannels extends AlertChannelMap> = {
|
|
5386
|
+
[TName in keyof TChannels]: TChannels[TName] extends GenericAlertChannel<infer TType, infer TConfig> ? AlertChannel<TType, TConfig> : never;
|
|
5387
|
+
};
|
|
5388
|
+
type AlertChannelName<TChannels extends AlertChannelMap> = keyof ValidatedAlertChannels<TChannels> & string;
|
|
5389
|
+
interface AlertRule<TMetrics extends JsonObject = JsonObject, TChannelName extends string = string> {
|
|
5304
5390
|
name: string;
|
|
5305
|
-
condition: (metrics:
|
|
5391
|
+
condition: (metrics: TMetrics) => boolean;
|
|
5306
5392
|
severity: AlertSeverity;
|
|
5307
|
-
channels:
|
|
5393
|
+
channels: TChannelName[];
|
|
5308
5394
|
throttle?: number;
|
|
5309
5395
|
message?: string;
|
|
5310
5396
|
}
|
|
5311
|
-
|
|
5312
|
-
|
|
5313
|
-
|
|
5314
|
-
|
|
5397
|
+
type AlertCallbackData<TMetrics extends JsonObject> = JsonObject & {
|
|
5398
|
+
metrics?: TMetrics;
|
|
5399
|
+
};
|
|
5400
|
+
interface AlertManagerOptions<TMetrics extends JsonObject = JsonObject, TChannels extends AlertChannelMap = Record<string, GenericAlertChannel>> {
|
|
5401
|
+
channels: ValidatedAlertChannels<TChannels>;
|
|
5402
|
+
rules?: AlertRule<TMetrics, AlertChannelName<TChannels>>[];
|
|
5403
|
+
onAlert?: (alert: Alert<AlertCallbackData<TMetrics>>) => void | Promise<void>;
|
|
5315
5404
|
}
|
|
5316
|
-
declare class AlertManager {
|
|
5405
|
+
declare class AlertManager<TMetrics extends JsonObject = JsonObject, TChannels extends AlertChannelMap = Record<string, GenericAlertChannel>> {
|
|
5317
5406
|
private options;
|
|
5318
5407
|
private lastAlertTime;
|
|
5319
5408
|
private monitorTimer?;
|
|
5320
5409
|
private running;
|
|
5321
|
-
constructor(options: AlertManagerOptions);
|
|
5322
|
-
start(metrics?: () =>
|
|
5410
|
+
constructor(options: AlertManagerOptions<TMetrics, TChannels>);
|
|
5411
|
+
start(metrics?: () => TMetrics, interval?: number): void;
|
|
5323
5412
|
stop(): void;
|
|
5324
|
-
alert(alert: Alert): Promise<void>;
|
|
5413
|
+
alert(alert: Alert<AlertCallbackData<TMetrics>>): Promise<void>;
|
|
5325
5414
|
private checkRules;
|
|
5326
5415
|
private isThrottled;
|
|
5327
|
-
sendToChannel(channelName: string, alert: Alert): Promise<void>;
|
|
5328
|
-
getAlertHistory(
|
|
5416
|
+
sendToChannel(channelName: keyof TChannels & string, alert: Alert<AlertCallbackData<TMetrics>>): Promise<void>;
|
|
5417
|
+
getAlertHistory(_name?: string, _limit?: number): Alert<AlertCallbackData<TMetrics>>[];
|
|
5329
5418
|
clearAlertHistory(name?: string): void;
|
|
5330
5419
|
}
|
|
5331
|
-
declare function createAlertManager(options: AlertManagerOptions): AlertManager
|
|
5420
|
+
declare function createAlertManager<TMetrics extends JsonObject = JsonObject, TChannels extends AlertChannelMap = Record<string, GenericAlertChannel>>(options: AlertManagerOptions<TMetrics, TChannels>): AlertManager<TMetrics, TChannels>;
|
|
5332
5421
|
|
|
5333
5422
|
/**
|
|
5334
5423
|
* Audit logging for compliance and tracking
|
|
@@ -5502,4 +5591,4 @@ declare function renderTemplate(template: string, options: RenderTemplateOptions
|
|
|
5502
5591
|
*/
|
|
5503
5592
|
declare function loadPrompt(promptName: string, options?: RenderTemplateOptions | Record<string, any>, promptsDir?: string): string;
|
|
5504
5593
|
|
|
5505
|
-
export { AgentError, type AgentResumedEventData, type AgentWaitingEventData, type AggregateNode, type Alert, type AlertChannel, AlertManager, type AlertManagerOptions, type AlertRule, type AlertSeverity, type AnyInterrupt, type ApprovalRequiredInterrupt, type AuditLogEntry, type AuditLogQuery, AuditLogger, type AuditLoggerOptions, type BackoffStrategy, type BatchOptions, BatchProcessor, type BatchProcessorOptions, type BatchStats, type CacheKeyGenerator, type CachingOptions, type CheckInterruptOptions, type CheckpointHistoryOptions, type CheckpointerOptions, type ChunkOptions, CircuitBreaker, type CircuitBreakerOptions, type CircuitBreakerStats, type CircuitState, type ComposeGraphsOptions, type ComposeOptions, type ComposeToolConfig, type ComposedTool, type ConcurrencyOptions, type ConditionalConfig, type ConditionalRouter, type ConditionalRouterConfig, ConnectionPool, type ConnectionPoolOptions, type ConversationConfig, type CustomInterrupt, type DatabaseConfig, type DatabaseConnection, DatabasePool, type DatabasePoolOptions, type DevelopmentPresetOptions, type ErrorContext, type ErrorHandlerOptions, type ErrorReporter, type ErrorReporterOptions, type EventHandler, type EvictionStrategy, type ExecutionMetrics, type HealthCheck, type HealthCheckConfig, type HealthCheckResult, HealthChecker, type HealthCheckerOptions, type HealthReport, type HealthStatus, type HttpClient, type HttpConfig, HttpPool, type HttpPoolConfig, type HttpPoolOptions, type HttpResponse, type HumanInLoopEventData, type HumanInLoopEventType, type HumanRequest, type HumanRequestEventData, type HumanRequestInterrupt, type HumanRequestPriority, type HumanRequestStatus, type HumanResponseEventData, type InterruptData, type InterruptEventData, type InterruptType, type LangSmithConfig, type LogEntry, LogLevel, type Logger, type LoggerOptions, type LoggingOptions, ManagedTool, type ManagedToolConfig, type ManagedToolStats, MemoryManager, type MemoryManagerOptions, type MemoryStats, type MetricEntry, MetricType, type Metrics, type MetricsNodeOptions, type Middleware, MiddlewareChain, type MiddlewareContext, type MiddlewareFactory, type MiddlewareMetadata, type MiddlewareWithMetadata, MissingDescriptionError, type MockToolConfig, type MockToolResponse, type NodeFunction, type NodeFunctionWithContext, type ParallelNode, type ParallelWorkflowConfig, type ParallelWorkflowOptions, type PoolConfig, type PoolStats, type Priority$1 as Priority, type ProductionPresetOptions, type ProfileReport, type ProfileSample, type ProfileStats, Profiler, type ProfilerOptions, type Progress, type ProgressTracker, type ProgressTrackerOptions, type PromptOptions, type RateLimitOptions, type RateLimitStrategy, type ReducerFunction, RegistryEvent, type RenderTemplateOptions, type RequestConfig, type ResumeCommand, type ResumeEventData, type ResumeOptions, type RetryOptions, type RetryPolicy, type RouteCondition, type RouteMap, type RouteName, type SSEEvent, type SSEFormatter, type SSEFormatterOptions, type SequentialNode, type SequentialWorkflowOptions, type SimpleMiddleware, type SqliteCheckpointerOptions, type StateChannelConfig, type SubgraphBuilder, type TestingPresetOptions, type ThreadConfig, type ThreadInfo, type ThreadStatus, type ThrottleOptions, TimeoutError, type TimeoutOptions, type Timer, type Tool, type BackoffStrategy$1 as ToolBackoffStrategy, ToolBuilder, ToolCategory, ToolCategorySchema, type ToolExample, ToolExampleSchema, type ToolExecution, type ToolExecutorConfig, type ToolHealthCheckResult, type ToolInvocation, type ToolMetadata, ToolMetadataSchema, ToolNameSchema, ToolRegistry, type ToolRelations, ToolRelationsSchema, type ToolSimulatorConfig, type TracingOptions, type ValidationErrorHandler, type ValidationMode, type ValidationOptions, type ValidatorFunction, type WebSocketHandlerOptions, type WebSocketMessage, batch, broadcast, cache, chain, chunk, clearThread, collect, compose, composeGraphs, composeTool, composeWithOptions, conditional, configureLangSmith, createAlertManager, createApprovalRequiredInterrupt, createAuditLogger, createBatchProcessor, createBinaryRouter, createCircuitBreaker, createConditionalRouter, createConnectionPool, createConversationConfig, createCustomInterrupt, createDatabasePool, createErrorReporter, createHealthChecker, createHeartbeat, createHttpPool, createHumanRequestInterrupt, createLogger, createManagedTool, createMemoryCheckpointer, createMemoryManager, createMessage, createMetrics, createMiddlewareContext, createMockTool, createMultiRouter, createParallelWorkflow, createProfiler, createProgressTracker, createSSEFormatter, createSequentialWorkflow, createSharedCache, createSharedConcurrencyController, createSharedRateLimiter, createSqliteCheckpointer, createStateAnnotation, createSubgraph, createThreadConfig, createTool, createToolExecutor, createToolSimulator, createToolUnsafe, createWebSocketHandler, development, filter, formatAgentResumedEvent, formatAgentWaitingEvent, formatHumanRequestEvent, formatHumanResponseEvent, formatInterruptEvent, formatResumeEvent, generateThreadId, getCheckpointHistory, getLangSmithConfig, getLatestCheckpoint, getMissingDescriptions, getThreadStatus, getToolDescription, getToolJsonSchema, isApprovalRequiredInterrupt, isCustomInterrupt, isHumanRequestInterrupt, isMemoryCheckpointer, isTracingEnabled, loadPrompt, map, merge, mergeState, parallel, parseSSEEvent, presets, production, reduce, renderTemplate, retry, safeValidateSchemaDescriptions, sanitizeValue, sendMessage, sequential, sequentialBuilder, take, testing, throttle, timeout, toLangChainTool, toLangChainTools, toolBuilder, validateSchemaDescriptions, validateState, validateTool, validateToolMetadata, validateToolName, withCache, withConcurrency, withErrorHandler, withLogging, withMetrics, withRateLimit, withRetry, withTimeout, withTracing, withValidation };
|
|
5594
|
+
export { AgentError, type AgentResumedEventData, type AgentWaitingEventData, type AggregateNode, type Alert, type AlertChannel, AlertManager, type AlertManagerOptions, type AlertRule, type AlertSeverity, type AnyInterrupt, type ApprovalRequiredInterrupt, type AuditLogEntry, type AuditLogQuery, AuditLogger, type AuditLoggerOptions, type BackoffStrategy, type BatchOptions, BatchProcessor, type BatchProcessorOptions, type BatchStats, type CacheKeyGenerator, type CachingOptions, type CheckInterruptOptions, type CheckpointHistoryOptions, type CheckpointerOptions, type ChunkOptions, CircuitBreaker, type CircuitBreakerOptions, type CircuitBreakerStats, type CircuitState, type ComposeGraphsOptions, type ComposeOptions, type ComposeToolConfig, type ComposedTool, type ConcurrencyOptions, type ConditionalConfig, type ConditionalRouter, type ConditionalRouterConfig, ConnectionPool, type ConnectionPoolOptions, type ConversationConfig, type CustomAlertChannel, type CustomInterrupt, type DatabaseConfig, type DatabaseConnection, DatabasePool, type DatabasePoolOptions, type DevelopmentPresetOptions, type EmailAlertChannel, type ErrorContext, type ErrorHandlerOptions, type ErrorReporter, type ErrorReporterOptions, type EventHandler, type EvictionStrategy, type ExecutionMetrics, type GenericAlertChannel, type HealthCheck, type HealthCheckConfig, type HealthCheckResult, HealthChecker, type HealthCheckerOptions, type HealthReport, type HealthStatus, type HttpClient, type HttpConfig, HttpPool, type HttpPoolConfig, type HttpPoolOptions, type HttpResponse, type HumanInLoopEventData, type HumanInLoopEventType, type HumanRequest, type HumanRequestEventData, type HumanRequestInterrupt, type HumanRequestPriority, type HumanRequestStatus, type HumanResponseEventData, type InterruptData, type InterruptEventData, type InterruptType, type JsonObject, type JsonPrimitive, type JsonValue, type LangSmithConfig, type LogEntry, LogLevel, type Logger, type LoggerOptions, type LoggingOptions, ManagedTool, type ManagedToolConfig, type ManagedToolStats, MemoryManager, type MemoryManagerOptions, type MemoryStats, type MetricEntry, MetricType, type Metrics, type MetricsNodeOptions, type Middleware, MiddlewareChain, type MiddlewareContext, type MiddlewareFactory, type MiddlewareMetadata, type MiddlewareWithMetadata, MissingDescriptionError, type MockToolConfig, type MockToolResponse, type NodeFunction, type NodeFunctionWithContext, type ParallelNode, type ParallelWorkflowConfig, type ParallelWorkflowOptions, type PoolConfig, type PoolStats, type Priority$1 as Priority, type ProductionPresetOptions, type ProfileReport, type ProfileSample, type ProfileStats, Profiler, type ProfilerOptions, type Progress, type ProgressTracker, type ProgressTrackerOptions, type PromptOptions, type RateLimitOptions, type RateLimitStrategy, type ReducerFunction, RegistryEvent, type RenderTemplateOptions, type RequestConfig, type ResumeCommand, type ResumeEventData, type ResumeOptions, type RetryOptions, type RetryPolicy, type RouteCondition, type RouteMap, type RouteName, type SSEEvent, type SSEFormatter, type SSEFormatterOptions, type SequentialNode, type SequentialWorkflowOptions, type SimpleMiddleware, type SlackAlertChannel, type SqliteCheckpointerOptions, type StateChannelConfig, type SubgraphBuilder, type TestingPresetOptions, type ThreadConfig, type ThreadInfo, type ThreadStatus, type ThrottleOptions, TimeoutError, type TimeoutOptions, type Timer, type Tool, type BackoffStrategy$1 as ToolBackoffStrategy, ToolBuilder, ToolCategory, ToolCategorySchema, type ToolExample, ToolExampleSchema, type ToolExecution, type ToolExecutorConfig, type ToolHealthCheckResult, type ToolInvocation, type ToolMetadata, ToolMetadataSchema, ToolNameSchema, ToolRegistry, type ToolRelations, ToolRelationsSchema, type ToolSimulatorConfig, type TracingOptions, type ValidationErrorHandler, type ValidationMode, type ValidationOptions, type ValidatorFunction, type WebSocketHandlerOptions, type WebSocketMessage, type WebhookAlertChannel, batch, broadcast, cache, chain, chunk, clearThread, collect, compose, composeGraphs, composeTool, composeWithOptions, conditional, configureLangSmith, createAlertManager, createApprovalRequiredInterrupt, createAuditLogger, createBatchProcessor, createBinaryRouter, createCircuitBreaker, createConditionalRouter, createConnectionPool, createConversationConfig, createCustomInterrupt, createDatabasePool, createErrorReporter, createHealthChecker, createHeartbeat, createHttpPool, createHumanRequestInterrupt, createLogger, createManagedTool, createMemoryCheckpointer, createMemoryManager, createMessage, createMetrics, createMiddlewareContext, createMockTool, createMultiRouter, createParallelWorkflow, createProfiler, createProgressTracker, createSSEFormatter, createSequentialWorkflow, createSharedCache, createSharedConcurrencyController, createSharedRateLimiter, createSqliteCheckpointer, createStateAnnotation, createSubgraph, createThreadConfig, createTool, createToolExecutor, createToolSimulator, createToolUnsafe, createWebSocketHandler, development, filter, formatAgentResumedEvent, formatAgentWaitingEvent, formatHumanRequestEvent, formatHumanResponseEvent, formatInterruptEvent, formatResumeEvent, generateThreadId, getCheckpointHistory, getLangSmithConfig, getLatestCheckpoint, getMissingDescriptions, getThreadStatus, getToolDescription, getToolJsonSchema, isApprovalRequiredInterrupt, isCustomInterrupt, isHumanRequestInterrupt, isMemoryCheckpointer, isTracingEnabled, loadPrompt, map, merge, mergeState, parallel, parseSSEEvent, presets, production, reduce, renderTemplate, retry, safeValidateSchemaDescriptions, sanitizeValue, sendMessage, sequential, sequentialBuilder, take, testing, throttle, timeout, toLangChainTool, toLangChainTools, toolBuilder, validateSchemaDescriptions, validateState, validateTool, validateToolMetadata, validateToolName, withCache, withConcurrency, withErrorHandler, withLogging, withMetrics, withRateLimit, withRetry, withTimeout, withTracing, withValidation };
|
package/dist/index.js
CHANGED
|
@@ -771,7 +771,7 @@ var LoggerImpl = class _LoggerImpl {
|
|
|
771
771
|
if (this.options.includeContext && Object.keys(this.context).length > 0) {
|
|
772
772
|
entry.context = this.context;
|
|
773
773
|
}
|
|
774
|
-
if (data) {
|
|
774
|
+
if (data !== void 0) {
|
|
775
775
|
entry.data = data;
|
|
776
776
|
}
|
|
777
777
|
const output = this.format(entry);
|
|
@@ -791,7 +791,7 @@ var LoggerImpl = class _LoggerImpl {
|
|
|
791
791
|
if (entry.context) {
|
|
792
792
|
parts.push(`context=${JSON.stringify(entry.context)}`);
|
|
793
793
|
}
|
|
794
|
-
if (entry.data) {
|
|
794
|
+
if (entry.data !== void 0) {
|
|
795
795
|
parts.push(`data=${JSON.stringify(entry.data)}`);
|
|
796
796
|
}
|
|
797
797
|
return parts.join(" ");
|
|
@@ -1124,7 +1124,7 @@ var ToolRegistry = class {
|
|
|
1124
1124
|
logger.error("Event handler error", {
|
|
1125
1125
|
event,
|
|
1126
1126
|
error: error instanceof Error ? error.message : String(error),
|
|
1127
|
-
|
|
1127
|
+
...error instanceof Error && error.stack ? { stack: error.stack } : {}
|
|
1128
1128
|
});
|
|
1129
1129
|
}
|
|
1130
1130
|
});
|
|
@@ -1591,7 +1591,7 @@ var ManagedTool = class {
|
|
|
1591
1591
|
(err) => logger3.error("Cleanup failed", {
|
|
1592
1592
|
toolName: this.name,
|
|
1593
1593
|
error: err instanceof Error ? err.message : String(err),
|
|
1594
|
-
|
|
1594
|
+
...err instanceof Error && err.stack ? { stack: err.stack } : {}
|
|
1595
1595
|
})
|
|
1596
1596
|
);
|
|
1597
1597
|
});
|
|
@@ -2036,46 +2036,84 @@ function createToolSimulator(config) {
|
|
|
2036
2036
|
|
|
2037
2037
|
// src/langgraph/state.ts
|
|
2038
2038
|
import { Annotation } from "@langchain/langgraph";
|
|
2039
|
+
function entriesOf(value) {
|
|
2040
|
+
return Object.entries(value);
|
|
2041
|
+
}
|
|
2042
|
+
function keysOf(value) {
|
|
2043
|
+
return Object.keys(value);
|
|
2044
|
+
}
|
|
2045
|
+
function hasOwnProperty(value, key) {
|
|
2046
|
+
return Object.prototype.hasOwnProperty.call(value, key);
|
|
2047
|
+
}
|
|
2048
|
+
function useLatestValue(_left, right) {
|
|
2049
|
+
return right;
|
|
2050
|
+
}
|
|
2051
|
+
function setStateValue(target, key, value) {
|
|
2052
|
+
target[key] = value;
|
|
2053
|
+
}
|
|
2054
|
+
function setStateDefinitionValue(target, key, value) {
|
|
2055
|
+
target[key] = value;
|
|
2056
|
+
}
|
|
2057
|
+
function createChannel(channelConfig) {
|
|
2058
|
+
if (channelConfig.reducer) {
|
|
2059
|
+
return Annotation({
|
|
2060
|
+
reducer: channelConfig.reducer,
|
|
2061
|
+
default: channelConfig.default
|
|
2062
|
+
});
|
|
2063
|
+
}
|
|
2064
|
+
if (channelConfig.default) {
|
|
2065
|
+
return Annotation({
|
|
2066
|
+
reducer: useLatestValue,
|
|
2067
|
+
default: channelConfig.default
|
|
2068
|
+
});
|
|
2069
|
+
}
|
|
2070
|
+
return Annotation();
|
|
2071
|
+
}
|
|
2039
2072
|
function createStateAnnotation(config) {
|
|
2040
2073
|
const stateDefinition = {};
|
|
2041
|
-
for (const [key, channelConfig] of
|
|
2042
|
-
|
|
2043
|
-
stateDefinition
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
} else if (channelConfig.default) {
|
|
2048
|
-
stateDefinition[key] = Annotation({
|
|
2049
|
-
reducer: (_left, right) => right,
|
|
2050
|
-
default: channelConfig.default
|
|
2051
|
-
});
|
|
2052
|
-
} else {
|
|
2053
|
-
stateDefinition[key] = Annotation();
|
|
2054
|
-
}
|
|
2074
|
+
for (const [key, channelConfig] of entriesOf(config)) {
|
|
2075
|
+
setStateDefinitionValue(
|
|
2076
|
+
stateDefinition,
|
|
2077
|
+
key,
|
|
2078
|
+
createChannel(channelConfig)
|
|
2079
|
+
);
|
|
2055
2080
|
}
|
|
2056
2081
|
return Annotation.Root(stateDefinition);
|
|
2057
2082
|
}
|
|
2058
2083
|
function validateState(state, config) {
|
|
2059
2084
|
const validated = {};
|
|
2060
|
-
for (const [key, channelConfig] of
|
|
2061
|
-
if (channelConfig.schema && key
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2085
|
+
for (const [key, channelConfig] of entriesOf(config)) {
|
|
2086
|
+
if (channelConfig.schema && hasOwnProperty(state, key)) {
|
|
2087
|
+
setStateValue(
|
|
2088
|
+
validated,
|
|
2089
|
+
key,
|
|
2090
|
+
channelConfig.schema.parse(state[key])
|
|
2091
|
+
);
|
|
2092
|
+
} else if (hasOwnProperty(state, key)) {
|
|
2093
|
+
setStateValue(validated, key, state[key]);
|
|
2065
2094
|
} else if (channelConfig.default) {
|
|
2066
|
-
validated
|
|
2095
|
+
setStateValue(validated, key, channelConfig.default());
|
|
2067
2096
|
}
|
|
2068
2097
|
}
|
|
2069
2098
|
return validated;
|
|
2070
2099
|
}
|
|
2071
2100
|
function mergeState(currentState, update, config) {
|
|
2072
2101
|
const merged = { ...currentState };
|
|
2073
|
-
for (const
|
|
2102
|
+
for (const key of keysOf(update)) {
|
|
2103
|
+
const value = update[key];
|
|
2074
2104
|
const channelConfig = config[key];
|
|
2075
|
-
|
|
2076
|
-
|
|
2105
|
+
const reducer = channelConfig?.reducer;
|
|
2106
|
+
if (reducer && hasOwnProperty(merged, key)) {
|
|
2107
|
+
setStateValue(
|
|
2108
|
+
merged,
|
|
2109
|
+
key,
|
|
2110
|
+
reducer(
|
|
2111
|
+
merged[key],
|
|
2112
|
+
value
|
|
2113
|
+
)
|
|
2114
|
+
);
|
|
2077
2115
|
} else {
|
|
2078
|
-
merged
|
|
2116
|
+
setStateValue(merged, key, value);
|
|
2079
2117
|
}
|
|
2080
2118
|
}
|
|
2081
2119
|
return merged;
|
|
@@ -2613,7 +2651,7 @@ var withLogging = (options) => {
|
|
|
2613
2651
|
if (logErrors) {
|
|
2614
2652
|
logger5.error(`Node execution failed (${duration}ms)`, {
|
|
2615
2653
|
error: err.message,
|
|
2616
|
-
stack: err.stack
|
|
2654
|
+
...err.stack ? { stack: err.stack } : {}
|
|
2617
2655
|
});
|
|
2618
2656
|
}
|
|
2619
2657
|
if (onError) {
|
|
@@ -5061,6 +5099,40 @@ function createProfiler(options) {
|
|
|
5061
5099
|
|
|
5062
5100
|
// src/monitoring/alerts.ts
|
|
5063
5101
|
var logger4 = createLogger("agentforge:core:monitoring:alerts", { level: "info" /* INFO */ });
|
|
5102
|
+
function toAlertSummary(alert) {
|
|
5103
|
+
return {
|
|
5104
|
+
name: alert.name,
|
|
5105
|
+
severity: alert.severity,
|
|
5106
|
+
message: alert.message
|
|
5107
|
+
};
|
|
5108
|
+
}
|
|
5109
|
+
function toRuleErrorPayload(ruleName, error) {
|
|
5110
|
+
return {
|
|
5111
|
+
ruleName,
|
|
5112
|
+
error: error instanceof Error ? error.message : String(error),
|
|
5113
|
+
...error instanceof Error && error.stack ? { stack: error.stack } : {}
|
|
5114
|
+
};
|
|
5115
|
+
}
|
|
5116
|
+
function toAlertDispatchErrorPayload(ruleName, error) {
|
|
5117
|
+
return {
|
|
5118
|
+
stage: "alert-dispatch",
|
|
5119
|
+
...toRuleErrorPayload(ruleName, error)
|
|
5120
|
+
};
|
|
5121
|
+
}
|
|
5122
|
+
function toAlertCallbackErrorPayload(error) {
|
|
5123
|
+
return {
|
|
5124
|
+
stage: "alert-callback",
|
|
5125
|
+
error: error instanceof Error ? error.message : String(error),
|
|
5126
|
+
...error instanceof Error && error.stack ? { stack: error.stack } : {}
|
|
5127
|
+
};
|
|
5128
|
+
}
|
|
5129
|
+
function toMetricsProviderErrorPayload(error) {
|
|
5130
|
+
return {
|
|
5131
|
+
stage: "metrics-provider",
|
|
5132
|
+
error: error instanceof Error ? error.message : String(error),
|
|
5133
|
+
...error instanceof Error && error.stack ? { stack: error.stack } : {}
|
|
5134
|
+
};
|
|
5135
|
+
}
|
|
5064
5136
|
var AlertManager = class {
|
|
5065
5137
|
constructor(options) {
|
|
5066
5138
|
this.options = options;
|
|
@@ -5074,8 +5146,12 @@ var AlertManager = class {
|
|
|
5074
5146
|
}
|
|
5075
5147
|
this.running = true;
|
|
5076
5148
|
this.monitorTimer = setInterval(() => {
|
|
5077
|
-
|
|
5078
|
-
|
|
5149
|
+
try {
|
|
5150
|
+
const currentMetrics = metrics();
|
|
5151
|
+
this.checkRules(currentMetrics);
|
|
5152
|
+
} catch (error) {
|
|
5153
|
+
logger4.error("Metrics collection failed", toMetricsProviderErrorPayload(error));
|
|
5154
|
+
}
|
|
5079
5155
|
}, interval);
|
|
5080
5156
|
}
|
|
5081
5157
|
stop() {
|
|
@@ -5091,18 +5167,22 @@ var AlertManager = class {
|
|
|
5091
5167
|
async alert(alert) {
|
|
5092
5168
|
const fullAlert = {
|
|
5093
5169
|
...alert,
|
|
5094
|
-
timestamp: alert.timestamp
|
|
5170
|
+
timestamp: alert.timestamp ?? Date.now()
|
|
5095
5171
|
};
|
|
5096
5172
|
if (this.isThrottled(alert.name)) {
|
|
5097
5173
|
return;
|
|
5098
5174
|
}
|
|
5099
5175
|
this.lastAlertTime.set(alert.name, Date.now());
|
|
5100
|
-
|
|
5176
|
+
try {
|
|
5177
|
+
await this.options.onAlert?.(fullAlert);
|
|
5178
|
+
} catch (error) {
|
|
5179
|
+
logger4.error("Alert callback failed", toAlertCallbackErrorPayload(error));
|
|
5180
|
+
}
|
|
5101
5181
|
logger4.warn("Alert triggered", {
|
|
5102
5182
|
name: alert.name,
|
|
5103
5183
|
severity: alert.severity,
|
|
5104
5184
|
message: alert.message,
|
|
5105
|
-
data: alert.data
|
|
5185
|
+
...alert.data ? { data: alert.data } : {}
|
|
5106
5186
|
});
|
|
5107
5187
|
}
|
|
5108
5188
|
checkRules(metrics) {
|
|
@@ -5112,19 +5192,17 @@ var AlertManager = class {
|
|
|
5112
5192
|
for (const rule of this.options.rules) {
|
|
5113
5193
|
try {
|
|
5114
5194
|
if (rule.condition(metrics)) {
|
|
5115
|
-
this.alert({
|
|
5195
|
+
void this.alert({
|
|
5116
5196
|
name: rule.name,
|
|
5117
5197
|
severity: rule.severity,
|
|
5118
5198
|
message: rule.message || `Alert triggered: ${rule.name}`,
|
|
5119
5199
|
data: { metrics }
|
|
5200
|
+
}).catch((error) => {
|
|
5201
|
+
logger4.error("Alert dispatch failed", toAlertDispatchErrorPayload(rule.name, error));
|
|
5120
5202
|
});
|
|
5121
5203
|
}
|
|
5122
5204
|
} catch (error) {
|
|
5123
|
-
logger4.error("Rule check failed",
|
|
5124
|
-
ruleName: rule.name,
|
|
5125
|
-
error: error instanceof Error ? error.message : String(error),
|
|
5126
|
-
stack: error instanceof Error ? error.stack : void 0
|
|
5127
|
-
});
|
|
5205
|
+
logger4.error("Rule check failed", toRuleErrorPayload(rule.name, error));
|
|
5128
5206
|
}
|
|
5129
5207
|
}
|
|
5130
5208
|
}
|
|
@@ -5149,32 +5227,32 @@ var AlertManager = class {
|
|
|
5149
5227
|
logger4.info("Alert sent to email", {
|
|
5150
5228
|
channel: channelName,
|
|
5151
5229
|
to: channel.config.to,
|
|
5152
|
-
alert:
|
|
5230
|
+
alert: toAlertSummary(alert)
|
|
5153
5231
|
});
|
|
5154
5232
|
break;
|
|
5155
5233
|
case "slack":
|
|
5156
5234
|
logger4.info("Alert sent to Slack", {
|
|
5157
5235
|
channel: channelName,
|
|
5158
5236
|
webhookUrl: channel.config.webhookUrl,
|
|
5159
|
-
alert:
|
|
5237
|
+
alert: toAlertSummary(alert)
|
|
5160
5238
|
});
|
|
5161
5239
|
break;
|
|
5162
5240
|
case "webhook":
|
|
5163
5241
|
logger4.info("Alert sent to webhook", {
|
|
5164
5242
|
channel: channelName,
|
|
5165
5243
|
url: channel.config.url,
|
|
5166
|
-
alert:
|
|
5244
|
+
alert: toAlertSummary(alert)
|
|
5167
5245
|
});
|
|
5168
5246
|
break;
|
|
5169
5247
|
default:
|
|
5170
5248
|
logger4.info("Alert sent", {
|
|
5171
5249
|
channel: channelName,
|
|
5172
5250
|
channelType: channel.type,
|
|
5173
|
-
alert:
|
|
5251
|
+
alert: toAlertSummary(alert)
|
|
5174
5252
|
});
|
|
5175
5253
|
}
|
|
5176
5254
|
}
|
|
5177
|
-
getAlertHistory(
|
|
5255
|
+
getAlertHistory(_name, _limit = 100) {
|
|
5178
5256
|
return [];
|
|
5179
5257
|
}
|
|
5180
5258
|
clearAlertHistory(name) {
|
package/package.json
CHANGED