langchain 1.0.0-alpha.3 → 1.0.0-alpha.5
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/agents/ReactAgent.cjs +1 -1
- package/dist/agents/ReactAgent.cjs.map +1 -1
- package/dist/agents/ReactAgent.d.cts +3 -3
- package/dist/agents/ReactAgent.d.cts.map +1 -1
- package/dist/agents/ReactAgent.d.ts +3 -3
- package/dist/agents/ReactAgent.d.ts.map +1 -1
- package/dist/agents/ReactAgent.js +2 -2
- package/dist/agents/ReactAgent.js.map +1 -1
- package/dist/agents/RunnableCallable.cjs +5 -0
- package/dist/agents/RunnableCallable.cjs.map +1 -1
- package/dist/agents/RunnableCallable.d.cts +2 -0
- package/dist/agents/RunnableCallable.d.cts.map +1 -1
- package/dist/agents/RunnableCallable.d.ts +2 -0
- package/dist/agents/RunnableCallable.d.ts.map +1 -1
- package/dist/agents/RunnableCallable.js +5 -0
- package/dist/agents/RunnableCallable.js.map +1 -1
- package/dist/agents/annotation.cjs +2 -2
- package/dist/agents/annotation.cjs.map +1 -1
- package/dist/agents/annotation.d.cts +4 -4
- package/dist/agents/annotation.d.cts.map +1 -1
- package/dist/agents/annotation.d.ts +3 -3
- package/dist/agents/annotation.d.ts.map +1 -1
- package/dist/agents/annotation.js +2 -2
- package/dist/agents/annotation.js.map +1 -1
- package/dist/agents/createAgent.cjs +10 -0
- package/dist/agents/createAgent.cjs.map +1 -0
- package/dist/agents/createAgent.js +10 -0
- package/dist/agents/createAgent.js.map +1 -0
- package/dist/agents/errors.cjs +1 -1
- package/dist/agents/errors.cjs.map +1 -1
- package/dist/agents/errors.js +1 -1
- package/dist/agents/errors.js.map +1 -1
- package/dist/agents/index.cjs +23 -4
- package/dist/agents/index.cjs.map +1 -1
- package/dist/agents/index.d.cts +96 -33
- package/dist/agents/index.d.cts.map +1 -1
- package/dist/agents/index.d.ts +96 -33
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +23 -4
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/middlewareAgent/ReactAgent.cjs +255 -0
- package/dist/agents/middlewareAgent/ReactAgent.cjs.map +1 -0
- package/dist/agents/middlewareAgent/ReactAgent.d.cts +68 -0
- package/dist/agents/middlewareAgent/ReactAgent.d.cts.map +1 -0
- package/dist/agents/middlewareAgent/ReactAgent.d.ts +68 -0
- package/dist/agents/middlewareAgent/ReactAgent.d.ts.map +1 -0
- package/dist/agents/middlewareAgent/ReactAgent.js +254 -0
- package/dist/agents/middlewareAgent/ReactAgent.js.map +1 -0
- package/dist/agents/middlewareAgent/annotation.cjs +39 -0
- package/dist/agents/middlewareAgent/annotation.cjs.map +1 -0
- package/dist/agents/middlewareAgent/annotation.js +38 -0
- package/dist/agents/middlewareAgent/annotation.js.map +1 -0
- package/dist/agents/middlewareAgent/index.cjs +11 -0
- package/dist/agents/middlewareAgent/index.cjs.map +1 -0
- package/dist/agents/middlewareAgent/index.js +11 -0
- package/dist/agents/middlewareAgent/index.js.map +1 -0
- package/dist/agents/middlewareAgent/middleware.cjs +47 -0
- package/dist/agents/middlewareAgent/middleware.cjs.map +1 -0
- package/dist/agents/middlewareAgent/middleware.d.cts +46 -0
- package/dist/agents/middlewareAgent/middleware.d.cts.map +1 -0
- package/dist/agents/middlewareAgent/middleware.d.ts +46 -0
- package/dist/agents/middlewareAgent/middleware.d.ts.map +1 -0
- package/dist/agents/middlewareAgent/middleware.js +46 -0
- package/dist/agents/middlewareAgent/middleware.js.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/hitl.cjs +235 -0
- package/dist/agents/middlewareAgent/middlewares/hitl.cjs.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/hitl.d.cts +199 -0
- package/dist/agents/middlewareAgent/middlewares/hitl.d.cts.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/hitl.d.ts +199 -0
- package/dist/agents/middlewareAgent/middlewares/hitl.d.ts.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/hitl.js +234 -0
- package/dist/agents/middlewareAgent/middlewares/hitl.js.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/index.cjs +8 -0
- package/dist/agents/middlewareAgent/middlewares/index.d.cts +4 -0
- package/dist/agents/middlewareAgent/middlewares/index.d.ts +4 -0
- package/dist/agents/middlewareAgent/middlewares/index.js +5 -0
- package/dist/agents/middlewareAgent/middlewares/promptCaching.cjs +153 -0
- package/dist/agents/middlewareAgent/middlewares/promptCaching.cjs.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/promptCaching.d.cts +152 -0
- package/dist/agents/middlewareAgent/middlewares/promptCaching.d.cts.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/promptCaching.d.ts +152 -0
- package/dist/agents/middlewareAgent/middlewares/promptCaching.d.ts.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/promptCaching.js +152 -0
- package/dist/agents/middlewareAgent/middlewares/promptCaching.js.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/summarization.cjs +262 -0
- package/dist/agents/middlewareAgent/middlewares/summarization.cjs.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/summarization.d.cts +89 -0
- package/dist/agents/middlewareAgent/middlewares/summarization.d.cts.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/summarization.d.ts +89 -0
- package/dist/agents/middlewareAgent/middlewares/summarization.d.ts.map +1 -0
- package/dist/agents/middlewareAgent/middlewares/summarization.js +260 -0
- package/dist/agents/middlewareAgent/middlewares/summarization.js.map +1 -0
- package/dist/agents/middlewareAgent/nodes/AfterModalNode.cjs +29 -0
- package/dist/agents/middlewareAgent/nodes/AfterModalNode.cjs.map +1 -0
- package/dist/agents/middlewareAgent/nodes/AfterModalNode.js +29 -0
- package/dist/agents/middlewareAgent/nodes/AfterModalNode.js.map +1 -0
- package/dist/agents/middlewareAgent/nodes/AgentNode.cjs +332 -0
- package/dist/agents/middlewareAgent/nodes/AgentNode.cjs.map +1 -0
- package/dist/agents/middlewareAgent/nodes/AgentNode.js +331 -0
- package/dist/agents/middlewareAgent/nodes/AgentNode.js.map +1 -0
- package/dist/agents/middlewareAgent/nodes/BeforeModalNode.cjs +27 -0
- package/dist/agents/middlewareAgent/nodes/BeforeModalNode.cjs.map +1 -0
- package/dist/agents/middlewareAgent/nodes/BeforeModalNode.js +27 -0
- package/dist/agents/middlewareAgent/nodes/BeforeModalNode.js.map +1 -0
- package/dist/agents/middlewareAgent/nodes/middleware.cjs +73 -0
- package/dist/agents/middlewareAgent/nodes/middleware.cjs.map +1 -0
- package/dist/agents/middlewareAgent/nodes/middleware.js +73 -0
- package/dist/agents/middlewareAgent/nodes/middleware.js.map +1 -0
- package/dist/agents/middlewareAgent/nodes/utils.cjs +74 -0
- package/dist/agents/middlewareAgent/nodes/utils.cjs.map +1 -0
- package/dist/agents/middlewareAgent/nodes/utils.js +70 -0
- package/dist/agents/middlewareAgent/nodes/utils.js.map +1 -0
- package/dist/agents/middlewareAgent/types.d.cts +393 -0
- package/dist/agents/middlewareAgent/types.d.cts.map +1 -0
- package/dist/agents/middlewareAgent/types.d.ts +393 -0
- package/dist/agents/middlewareAgent/types.d.ts.map +1 -0
- package/dist/agents/nodes/AgentNode.cjs.map +1 -1
- package/dist/agents/nodes/AgentNode.js.map +1 -1
- package/dist/agents/nodes/ToolNode.cjs +1 -1
- package/dist/agents/nodes/ToolNode.cjs.map +1 -1
- package/dist/agents/nodes/ToolNode.d.cts +4 -4
- package/dist/agents/nodes/ToolNode.d.cts.map +1 -1
- package/dist/agents/nodes/ToolNode.d.ts +1 -1
- package/dist/agents/nodes/ToolNode.d.ts.map +1 -1
- package/dist/agents/nodes/ToolNode.js +1 -1
- package/dist/agents/nodes/ToolNode.js.map +1 -1
- package/dist/agents/responses.cjs +1 -1
- package/dist/agents/responses.cjs.map +1 -1
- package/dist/agents/responses.d.cts +1 -1
- package/dist/agents/responses.d.cts.map +1 -1
- package/dist/agents/responses.d.ts +1 -1
- package/dist/agents/responses.d.ts.map +1 -1
- package/dist/agents/responses.js +1 -1
- package/dist/agents/responses.js.map +1 -1
- package/dist/agents/types.d.cts +12 -12
- package/dist/agents/types.d.cts.map +1 -1
- package/dist/agents/types.d.ts +8 -8
- package/dist/agents/types.d.ts.map +1 -1
- package/dist/agents/utils.cjs +1 -1
- package/dist/agents/utils.cjs.map +1 -1
- package/dist/agents/utils.js +1 -1
- package/dist/agents/utils.js.map +1 -1
- package/dist/agents/withAgentName.cjs +1 -1
- package/dist/agents/withAgentName.cjs.map +1 -1
- package/dist/agents/withAgentName.js +1 -1
- package/dist/agents/withAgentName.js.map +1 -1
- package/dist/chains/api/api_chain.d.cts +1 -1
- package/dist/chains/base.d.cts +1 -1
- package/dist/chains/combine_docs_chain.d.cts +1 -1
- package/dist/chains/combine_documents/stuff.d.cts +1 -1
- package/dist/chains/conversational_retrieval_chain.d.cts +1 -1
- package/dist/chains/graph_qa/cypher.d.cts +1 -1
- package/dist/chains/history_aware_retriever.d.cts +2 -2
- package/dist/chains/llm_chain.d.cts +3 -3
- package/dist/chains/openai_functions/base.d.cts +3 -3
- package/dist/chains/openai_functions/openapi.d.cts +1 -1
- package/dist/chains/openai_functions/structured_output.d.cts +3 -3
- package/dist/chains/openai_functions/tagging.d.cts +1 -1
- package/dist/chains/query_constructor/index.cjs +1 -1
- package/dist/chains/query_constructor/index.d.cts +2 -2
- package/dist/chains/query_constructor/index.d.ts +1 -1
- package/dist/chains/query_constructor/index.js +1 -1
- package/dist/chains/question_answering/load.d.ts +2 -2
- package/dist/chains/question_answering/load.d.ts.map +1 -1
- package/dist/chains/retrieval.d.cts +1 -1
- package/dist/chains/router/llm_router.d.cts +1 -1
- package/dist/chains/router/multi_prompt.cjs +1 -1
- package/dist/chains/router/multi_prompt.js +1 -1
- package/dist/chains/router/multi_retrieval_qa.cjs +1 -1
- package/dist/chains/router/multi_retrieval_qa.js +1 -1
- package/dist/chains/sql_db/sql_db_chain.d.cts +2 -2
- package/dist/chains/summarization/load.d.ts +2 -2
- package/dist/chains/summarization/load.d.ts.map +1 -1
- package/dist/chat_models/universal.d.cts +3 -3
- package/dist/evaluation/agents/trajectory.d.cts +3 -3
- package/dist/evaluation/agents/trajectory.d.ts.map +1 -1
- package/dist/evaluation/comparison/pairwise.d.cts +1 -1
- package/dist/evaluation/comparison/pairwise.d.ts.map +1 -1
- package/dist/evaluation/criteria/criteria.d.cts +1 -1
- package/dist/evaluation/qa/eval_chain.d.cts +1 -1
- package/dist/index.cjs +5 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +4 -3
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/load/import_map.cjs +1 -1
- package/dist/load/import_map.js +1 -1
- package/dist/memory/summary.d.cts +1 -1
- package/dist/output_parsers/fix.d.cts +1 -1
- package/dist/output_parsers/http_response.d.cts +1 -1
- package/dist/output_parsers/structured.cjs +1 -1
- package/dist/output_parsers/structured.d.cts +2 -2
- package/dist/output_parsers/structured.d.ts +1 -1
- package/dist/output_parsers/structured.js +1 -1
- package/dist/tools/fs.d.cts +1 -1
- package/dist/tools/json.d.cts +1 -1
- package/dist/tools/retriever.d.cts +1 -1
- package/dist/tools/vectorstore.d.cts +1 -1
- package/dist/tools/webbrowser.d.cts +1 -1
- package/package.json +14 -3
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_utils = require('../utils.cjs');
|
|
3
|
+
const require_ToolNode = require('../nodes/ToolNode.cjs');
|
|
4
|
+
const require_annotation = require('./annotation.cjs');
|
|
5
|
+
const require_utils$1 = require('./nodes/utils.cjs');
|
|
6
|
+
const require_AgentNode = require('./nodes/AgentNode.cjs');
|
|
7
|
+
const require_BeforeModalNode = require('./nodes/BeforeModalNode.cjs');
|
|
8
|
+
const require_AfterModalNode = require('./nodes/AfterModalNode.cjs');
|
|
9
|
+
const __langchain_core_messages = require_rolldown_runtime.__toESM(require("@langchain/core/messages"));
|
|
10
|
+
const __langchain_langgraph = require_rolldown_runtime.__toESM(require("@langchain/langgraph"));
|
|
11
|
+
|
|
12
|
+
//#region src/agents/middlewareAgent/ReactAgent.ts
|
|
13
|
+
var ReactAgent = class {
|
|
14
|
+
#graph;
|
|
15
|
+
#toolBehaviorVersion = "v2";
|
|
16
|
+
constructor(options) {
|
|
17
|
+
this.options = options;
|
|
18
|
+
this.#toolBehaviorVersion = options.version ?? this.#toolBehaviorVersion;
|
|
19
|
+
/**
|
|
20
|
+
* Check if the LLM already has bound tools and throw if it does.
|
|
21
|
+
*/
|
|
22
|
+
if (options.llm && typeof options.llm !== "function") require_utils.validateLLMHasNoBoundTools(options.llm);
|
|
23
|
+
/**
|
|
24
|
+
* validate that model and llm options are not provided together
|
|
25
|
+
*/
|
|
26
|
+
if (options.llm && options.model) throw new Error("Cannot provide both `model` and `llm` options.");
|
|
27
|
+
/**
|
|
28
|
+
* validate that either model or llm option is provided
|
|
29
|
+
*/
|
|
30
|
+
if (!options.llm && !options.model) throw new Error("Either `model` or `llm` option must be provided to create an agent.");
|
|
31
|
+
const toolClasses = (Array.isArray(options.tools) ? options.tools : options.tools?.tools) ?? [];
|
|
32
|
+
/**
|
|
33
|
+
* If any of the tools are configured to return_directly after running,
|
|
34
|
+
* our graph needs to check if these were called
|
|
35
|
+
*/
|
|
36
|
+
const shouldReturnDirect = new Set(toolClasses.filter(require_utils.isClientTool).filter((tool) => "returnDirect" in tool && tool.returnDirect).map((tool) => tool.name));
|
|
37
|
+
const schema = require_annotation.createAgentAnnotationConditional(this.options.responseFormat !== void 0, this.options.middlewares);
|
|
38
|
+
const workflow = new __langchain_langgraph.StateGraph(schema, this.options.contextSchema);
|
|
39
|
+
const allNodeWorkflows = workflow;
|
|
40
|
+
const beforeModelNodes = [];
|
|
41
|
+
const afterModelNodes = [];
|
|
42
|
+
const prepareModelRequestHookMiddlewares = [];
|
|
43
|
+
const middlewares = this.options.middlewares ?? [];
|
|
44
|
+
for (let i = 0; i < middlewares.length; i++) {
|
|
45
|
+
let beforeModelNode;
|
|
46
|
+
let afterModelNode;
|
|
47
|
+
const middleware = middlewares[i];
|
|
48
|
+
if (middleware.beforeModel) {
|
|
49
|
+
beforeModelNode = new require_BeforeModalNode.BeforeModelNode(middleware);
|
|
50
|
+
const name = `before_model_${middleware.name}_${i}`;
|
|
51
|
+
beforeModelNodes.push({
|
|
52
|
+
index: i,
|
|
53
|
+
name
|
|
54
|
+
});
|
|
55
|
+
allNodeWorkflows.addNode(name, beforeModelNode, beforeModelNode.nodeOptions);
|
|
56
|
+
}
|
|
57
|
+
if (middleware.afterModel) {
|
|
58
|
+
afterModelNode = new require_AfterModalNode.AfterModelNode(middleware);
|
|
59
|
+
const name = `after_model_${middleware.name}_${i}`;
|
|
60
|
+
afterModelNodes.push({
|
|
61
|
+
index: i,
|
|
62
|
+
name
|
|
63
|
+
});
|
|
64
|
+
allNodeWorkflows.addNode(name, afterModelNode, afterModelNode.nodeOptions);
|
|
65
|
+
}
|
|
66
|
+
if (middleware.prepareModelRequest) prepareModelRequestHookMiddlewares.push([middleware, () => ({
|
|
67
|
+
...beforeModelNode?.getState(),
|
|
68
|
+
...afterModelNode?.getState()
|
|
69
|
+
})]);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Add Nodes
|
|
73
|
+
*/
|
|
74
|
+
allNodeWorkflows.addNode("model_request", new require_AgentNode.AgentNode({
|
|
75
|
+
llm: this.options.llm,
|
|
76
|
+
model: this.options.model,
|
|
77
|
+
prompt: this.options.prompt,
|
|
78
|
+
includeAgentName: this.options.includeAgentName,
|
|
79
|
+
name: this.options.name,
|
|
80
|
+
responseFormat: this.options.responseFormat,
|
|
81
|
+
middlewares: this.options.middlewares,
|
|
82
|
+
toolClasses,
|
|
83
|
+
shouldReturnDirect,
|
|
84
|
+
signal: this.options.signal,
|
|
85
|
+
prepareModelRequestHookMiddlewares
|
|
86
|
+
}), require_AgentNode.AgentNode.nodeOptions);
|
|
87
|
+
/**
|
|
88
|
+
* add single tool node for all tools
|
|
89
|
+
*/
|
|
90
|
+
if (toolClasses.length > 0) {
|
|
91
|
+
const toolNode = new require_ToolNode.ToolNode(toolClasses.filter(require_utils.isClientTool), { signal: this.options.signal });
|
|
92
|
+
allNodeWorkflows.addNode("tools", toolNode);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Add Edges
|
|
96
|
+
*/
|
|
97
|
+
if (beforeModelNodes.length > 0) allNodeWorkflows.addEdge(__langchain_langgraph.START, beforeModelNodes[0].name);
|
|
98
|
+
else allNodeWorkflows.addEdge(__langchain_langgraph.START, "model_request");
|
|
99
|
+
for (let i = 0; i < beforeModelNodes.length - 1; i++) allNodeWorkflows.addEdge(beforeModelNodes[i].name, beforeModelNodes[i + 1].name);
|
|
100
|
+
const lastBeforeModelNode = beforeModelNodes.at(-1);
|
|
101
|
+
if (beforeModelNodes.length > 0 && lastBeforeModelNode) allNodeWorkflows.addEdge(lastBeforeModelNode.name, "model_request");
|
|
102
|
+
const lastAfterModelNode = afterModelNodes.at(-1);
|
|
103
|
+
if (afterModelNodes.length > 0 && lastAfterModelNode) allNodeWorkflows.addEdge("model_request", lastAfterModelNode.name);
|
|
104
|
+
else {
|
|
105
|
+
const modelPaths = this.#getModelPaths(toolClasses.filter(require_utils.isClientTool));
|
|
106
|
+
if (modelPaths.length === 1) allNodeWorkflows.addEdge("model_request", modelPaths[0]);
|
|
107
|
+
else allNodeWorkflows.addConditionalEdges("model_request", this.#createModelRouter(), modelPaths);
|
|
108
|
+
}
|
|
109
|
+
for (let i = afterModelNodes.length - 1; i > 0; i--) allNodeWorkflows.addEdge(afterModelNodes[i].name, afterModelNodes[i - 1].name);
|
|
110
|
+
if (afterModelNodes.length > 0) {
|
|
111
|
+
const firstAfterModelNode = afterModelNodes[0].name;
|
|
112
|
+
const modelPaths = this.#getModelPaths(toolClasses.filter(require_utils.isClientTool));
|
|
113
|
+
if (modelPaths.length === 1) allNodeWorkflows.addEdge(firstAfterModelNode, modelPaths[0]);
|
|
114
|
+
else allNodeWorkflows.addConditionalEdges(firstAfterModelNode, this.#createModelRouter(), modelPaths);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* add edges for tools node
|
|
118
|
+
*/
|
|
119
|
+
if (toolClasses.length > 0) {
|
|
120
|
+
let toolReturnTarget;
|
|
121
|
+
if (beforeModelNodes.length > 0) toolReturnTarget = beforeModelNodes[0].name;
|
|
122
|
+
else toolReturnTarget = "model_request";
|
|
123
|
+
if (shouldReturnDirect.size > 0) allNodeWorkflows.addConditionalEdges("tools", this.#createToolsRouter(shouldReturnDirect), [toolReturnTarget, __langchain_langgraph.END]);
|
|
124
|
+
else allNodeWorkflows.addEdge("tools", toolReturnTarget);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* compile the graph
|
|
128
|
+
*/
|
|
129
|
+
this.#graph = allNodeWorkflows.compile({
|
|
130
|
+
checkpointer: this.options.checkpointer ?? this.options.checkpointSaver,
|
|
131
|
+
interruptBefore: this.options.interruptBefore,
|
|
132
|
+
interruptAfter: this.options.interruptAfter,
|
|
133
|
+
store: this.options.store,
|
|
134
|
+
name: this.options.name,
|
|
135
|
+
description: this.options.description
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get the compiled graph.
|
|
140
|
+
*/
|
|
141
|
+
get graph() {
|
|
142
|
+
return this.#graph;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Get possible edge destinations from model node.
|
|
146
|
+
* @param toolClasses names of tools to call
|
|
147
|
+
* @returns list of possible edge destinations
|
|
148
|
+
*/
|
|
149
|
+
#getModelPaths(toolClasses) {
|
|
150
|
+
const paths = [];
|
|
151
|
+
if (toolClasses.length > 0) paths.push("tools");
|
|
152
|
+
paths.push(__langchain_langgraph.END);
|
|
153
|
+
return paths;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Create routing function for model node conditional edges.
|
|
157
|
+
*/
|
|
158
|
+
#createModelRouter() {
|
|
159
|
+
/**
|
|
160
|
+
* determine if the agent should continue or not
|
|
161
|
+
*/
|
|
162
|
+
/**
|
|
163
|
+
* ToDo: fix type
|
|
164
|
+
*/
|
|
165
|
+
return (state) => {
|
|
166
|
+
const messages = state.messages;
|
|
167
|
+
const lastMessage = messages.at(-1);
|
|
168
|
+
if (!(lastMessage instanceof __langchain_core_messages.AIMessage) || !lastMessage.tool_calls || lastMessage.tool_calls.length === 0) return __langchain_langgraph.END;
|
|
169
|
+
/**
|
|
170
|
+
* The tool node processes a single message.
|
|
171
|
+
*/
|
|
172
|
+
if (this.#toolBehaviorVersion === "v1") return "tools";
|
|
173
|
+
/**
|
|
174
|
+
* Route to tools node
|
|
175
|
+
*/
|
|
176
|
+
return lastMessage.tool_calls.map((toolCall) => new __langchain_langgraph.Send("tools", {
|
|
177
|
+
...state,
|
|
178
|
+
lg_tool_call: toolCall
|
|
179
|
+
}));
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Create routing function for tools node conditional edges.
|
|
184
|
+
*/
|
|
185
|
+
#createToolsRouter(shouldReturnDirect) {
|
|
186
|
+
/**
|
|
187
|
+
* ToDo: fix type
|
|
188
|
+
*/
|
|
189
|
+
return (state) => {
|
|
190
|
+
const messages = state.messages;
|
|
191
|
+
const lastMessage = messages[messages.length - 1];
|
|
192
|
+
if (lastMessage instanceof __langchain_core_messages.ToolMessage && lastMessage.name && shouldReturnDirect.has(lastMessage.name)) return this.options.responseFormat ? "model_request" : __langchain_langgraph.END;
|
|
193
|
+
return "model_request";
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Initialize middleware states if not already present in the input state.
|
|
198
|
+
*/
|
|
199
|
+
#initializeMiddlewareStates(state) {
|
|
200
|
+
if (!this.options.middlewares || this.options.middlewares.length === 0 || state instanceof __langchain_langgraph.Command || !state) return state;
|
|
201
|
+
const defaultStates = require_utils$1.initializeMiddlewareStates(this.options.middlewares, state);
|
|
202
|
+
const updatedState = { ...state };
|
|
203
|
+
if (!updatedState) return updatedState;
|
|
204
|
+
for (const [key, value] of Object.entries(defaultStates)) if (!(key in updatedState)) updatedState[key] = value;
|
|
205
|
+
return updatedState;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* @inheritdoc
|
|
209
|
+
*/
|
|
210
|
+
get invoke() {
|
|
211
|
+
const invokeFunc = async (state, config) => {
|
|
212
|
+
const initializedState = this.#initializeMiddlewareStates(state);
|
|
213
|
+
return this.#graph.invoke(initializedState, config);
|
|
214
|
+
};
|
|
215
|
+
return invokeFunc;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* ToDo(@christian-bromann): Add stream and streamEvents methods
|
|
219
|
+
*/
|
|
220
|
+
/**
|
|
221
|
+
* Visualize the graph as a PNG image.
|
|
222
|
+
* @param params - Parameters for the drawMermaidPng method.
|
|
223
|
+
* @param params.withStyles - Whether to include styles in the graph.
|
|
224
|
+
* @param params.curveStyle - The style of the graph's curves.
|
|
225
|
+
* @param params.nodeColors - The colors of the graph's nodes.
|
|
226
|
+
* @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.
|
|
227
|
+
* @param params.backgroundColor - The background color of the graph.
|
|
228
|
+
* @returns PNG image as a buffer
|
|
229
|
+
*/
|
|
230
|
+
async drawMermaidPng(params) {
|
|
231
|
+
const representation = await this.#graph.getGraphAsync();
|
|
232
|
+
const image = await representation.drawMermaidPng(params);
|
|
233
|
+
const arrayBuffer = await image.arrayBuffer();
|
|
234
|
+
const buffer = new Uint8Array(arrayBuffer);
|
|
235
|
+
return buffer;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Draw the graph as a Mermaid string.
|
|
239
|
+
* @param params - Parameters for the drawMermaid method.
|
|
240
|
+
* @param params.withStyles - Whether to include styles in the graph.
|
|
241
|
+
* @param params.curveStyle - The style of the graph's curves.
|
|
242
|
+
* @param params.nodeColors - The colors of the graph's nodes.
|
|
243
|
+
* @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.
|
|
244
|
+
* @param params.backgroundColor - The background color of the graph.
|
|
245
|
+
* @returns Mermaid string
|
|
246
|
+
*/
|
|
247
|
+
async drawMermaid(params) {
|
|
248
|
+
const representation = await this.#graph.getGraphAsync();
|
|
249
|
+
return representation.drawMermaid(params);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
//#endregion
|
|
254
|
+
exports.ReactAgent = ReactAgent;
|
|
255
|
+
//# sourceMappingURL=ReactAgent.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactAgent.cjs","names":["options: CreateAgentParams<StructuredResponseFormat, ContextSchema>","#toolBehaviorVersion","validateLLMHasNoBoundTools","isClientTool","createAgentAnnotationConditional","StateGraph","beforeModelNodes: { index: number; name: string }[]","afterModelNodes: { index: number; name: string }[]","prepareModelRequestHookMiddlewares: [\n AgentMiddleware,\n /**\n * ToDo: better type to get the state of middleware\n */\n () => any\n ][]","beforeModelNode: BeforeModelNode | undefined","afterModelNode: AfterModelNode | undefined","BeforeModelNode","AfterModelNode","AgentNode","ToolNode","START","#getModelPaths","#createModelRouter","toolReturnTarget: string","#createToolsRouter","END","#graph","toolClasses: (ClientTool | ServerTool)[]","paths: (\"tools\" | typeof END)[]","state: any","AIMessage","Send","shouldReturnDirect: Set<string>","ToolMessage","state: InvokeStateParameter<TMiddlewares>","Command","initializeMiddlewareStates","invokeFunc: InvokeFunction","config?: LangGraphRunnableConfig<FullContext>","#initializeMiddlewareStates","params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }"],"sources":["../../../src/agents/middlewareAgent/ReactAgent.ts"],"sourcesContent":["/* eslint-disable prefer-destructuring, no-instanceof/no-instanceof, @typescript-eslint/ban-types */\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\n\nimport {\n AnnotationRoot,\n StateGraph,\n END,\n START,\n Send,\n Command,\n CompiledStateGraph,\n type LangGraphRunnableConfig,\n} from \"@langchain/langgraph\";\nimport { ToolMessage, AIMessage } from \"@langchain/core/messages\";\n\nimport { createAgentAnnotationConditional } from \"./annotation.js\";\nimport { isClientTool, validateLLMHasNoBoundTools } from \"../utils.js\";\n\nimport { AgentNode } from \"./nodes/AgentNode.js\";\nimport { ToolNode } from \"../nodes/ToolNode.js\";\nimport { BeforeModelNode } from \"./nodes/BeforeModalNode.js\";\nimport { AfterModelNode } from \"./nodes/AfterModalNode.js\";\nimport { initializeMiddlewareStates } from \"./nodes/utils.js\";\n\nimport type { ClientTool, ServerTool, WithStateGraphNodes } from \"../types.js\";\n\nimport {\n CreateAgentParams,\n AgentMiddleware,\n InferMiddlewareStates,\n InferMiddlewareInputStates,\n BuiltInState,\n InferMiddlewareContextInputs,\n IsAllOptional,\n InferContextInput,\n} from \"./types.js\";\n\nimport {\n type AnyAnnotationRoot,\n type ToAnnotationRoot,\n} from \"../annotation.js\";\nimport type { ResponseFormatUndefined } from \"../responses.js\";\n\n// Helper type to get the state definition with middleware states\ntype MergedAgentState<\n StructuredResponseFormat extends\n | Record<string, any>\n | ResponseFormatUndefined,\n TMiddlewares extends readonly AgentMiddleware<any, any, any>[]\n> = (StructuredResponseFormat extends ResponseFormatUndefined\n ? BuiltInState\n : BuiltInState & { structuredResponse: StructuredResponseFormat }) &\n InferMiddlewareStates<TMiddlewares>;\n\ntype InvokeStateParameter<\n TMiddlewares extends readonly AgentMiddleware<any, any, any>[]\n> =\n | (BuiltInState & InferMiddlewareInputStates<TMiddlewares>)\n | Command<any, any, any>\n | null;\n\ntype AgentGraph<\n StructuredResponseFormat extends\n | Record<string, any>\n | ResponseFormatUndefined = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []\n> = CompiledStateGraph<\n any,\n any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n any,\n any,\n MergedAgentState<StructuredResponseFormat, TMiddlewares>,\n ToAnnotationRoot<ContextSchema>[\"spec\"],\n unknown\n>;\n\nexport class ReactAgent<\n StructuredResponseFormat extends\n | Record<string, any>\n | ResponseFormatUndefined = Record<string, any>,\n ContextSchema extends\n | AnyAnnotationRoot\n | InteropZodObject = AnyAnnotationRoot,\n TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []\n> {\n #graph: AgentGraph<StructuredResponseFormat, ContextSchema, TMiddlewares>;\n\n #toolBehaviorVersion: \"v1\" | \"v2\" = \"v2\";\n\n constructor(\n public options: CreateAgentParams<StructuredResponseFormat, ContextSchema>\n ) {\n this.#toolBehaviorVersion = options.version ?? this.#toolBehaviorVersion;\n\n /**\n * Check if the LLM already has bound tools and throw if it does.\n */\n if (options.llm && typeof options.llm !== \"function\") {\n validateLLMHasNoBoundTools(options.llm);\n }\n\n /**\n * validate that model and llm options are not provided together\n */\n if (options.llm && options.model) {\n throw new Error(\"Cannot provide both `model` and `llm` options.\");\n }\n\n /**\n * validate that either model or llm option is provided\n */\n if (!options.llm && !options.model) {\n throw new Error(\n \"Either `model` or `llm` option must be provided to create an agent.\"\n );\n }\n\n const toolClasses =\n (Array.isArray(options.tools) ? options.tools : options.tools?.tools) ??\n [];\n\n /**\n * If any of the tools are configured to return_directly after running,\n * our graph needs to check if these were called\n */\n const shouldReturnDirect = new Set(\n toolClasses\n .filter(isClientTool)\n .filter((tool) => \"returnDirect\" in tool && tool.returnDirect)\n .map((tool) => tool.name)\n );\n\n // Create a schema that merges agent base schema with middleware state schemas\n const schema = createAgentAnnotationConditional<\n StructuredResponseFormat,\n TMiddlewares\n >(\n this.options.responseFormat !== undefined,\n this.options.middlewares as TMiddlewares\n );\n\n const workflow = new StateGraph(\n schema as AnnotationRoot<any>,\n this.options.contextSchema\n );\n\n const allNodeWorkflows = workflow as WithStateGraphNodes<\n \"tools\" | \"model_request\" | string,\n typeof workflow\n >;\n\n // Generate node names for middleware nodes that have hooks\n const beforeModelNodes: { index: number; name: string }[] = [];\n const afterModelNodes: { index: number; name: string }[] = [];\n const prepareModelRequestHookMiddlewares: [\n AgentMiddleware,\n /**\n * ToDo: better type to get the state of middleware\n */\n () => any\n ][] = [];\n\n const middlewares = this.options.middlewares ?? [];\n for (let i = 0; i < middlewares.length; i++) {\n let beforeModelNode: BeforeModelNode | undefined;\n let afterModelNode: AfterModelNode | undefined;\n const middleware = middlewares[i];\n if (middleware.beforeModel) {\n beforeModelNode = new BeforeModelNode(middleware);\n const name = `before_model_${middleware.name}_${i}`;\n beforeModelNodes.push({\n index: i,\n name,\n });\n allNodeWorkflows.addNode(\n name,\n beforeModelNode,\n beforeModelNode.nodeOptions\n );\n }\n if (middleware.afterModel) {\n afterModelNode = new AfterModelNode(middleware);\n const name = `after_model_${middleware.name}_${i}`;\n afterModelNodes.push({\n index: i,\n name,\n });\n allNodeWorkflows.addNode(\n name,\n afterModelNode,\n afterModelNode.nodeOptions\n );\n }\n\n if (middleware.prepareModelRequest) {\n prepareModelRequestHookMiddlewares.push([\n middleware,\n () => ({\n ...beforeModelNode?.getState(),\n ...afterModelNode?.getState(),\n }),\n ]);\n }\n }\n\n /**\n * Add Nodes\n */\n allNodeWorkflows.addNode(\n \"model_request\",\n new AgentNode({\n llm: this.options.llm,\n model: this.options.model,\n prompt: this.options.prompt,\n includeAgentName: this.options.includeAgentName,\n name: this.options.name,\n responseFormat: this.options.responseFormat,\n middlewares: this.options.middlewares,\n toolClasses,\n shouldReturnDirect,\n signal: this.options.signal,\n prepareModelRequestHookMiddlewares,\n }),\n AgentNode.nodeOptions\n );\n\n /**\n * add single tool node for all tools\n */\n if (toolClasses.length > 0) {\n const toolNode = new ToolNode(toolClasses.filter(isClientTool), {\n signal: this.options.signal,\n });\n allNodeWorkflows.addNode(\"tools\", toolNode);\n }\n\n /**\n * Add Edges\n */\n // Determine starting point based on what nodes exist\n if (beforeModelNodes.length > 0) {\n // If we have beforeModel nodes, start with the first one\n allNodeWorkflows.addEdge(START, beforeModelNodes[0].name);\n } else {\n // If no beforeModel nodes, go directly to agent\n allNodeWorkflows.addEdge(START, \"model_request\");\n }\n\n // Connect beforeModel nodes in sequence\n for (let i = 0; i < beforeModelNodes.length - 1; i++) {\n allNodeWorkflows.addEdge(\n beforeModelNodes[i].name,\n beforeModelNodes[i + 1].name\n );\n }\n\n // Connect last beforeModel node to agent\n const lastBeforeModelNode = beforeModelNodes.at(-1);\n if (beforeModelNodes.length > 0 && lastBeforeModelNode) {\n allNodeWorkflows.addEdge(lastBeforeModelNode.name, \"model_request\");\n }\n\n // Connect agent to last afterModel node (for reverse order execution)\n const lastAfterModelNode = afterModelNodes.at(-1);\n if (afterModelNodes.length > 0 && lastAfterModelNode) {\n allNodeWorkflows.addEdge(\"model_request\", lastAfterModelNode.name);\n } else {\n const modelPaths = this.#getModelPaths(toolClasses.filter(isClientTool));\n if (modelPaths.length === 1) {\n allNodeWorkflows.addEdge(\"model_request\", modelPaths[0]);\n } else {\n allNodeWorkflows.addConditionalEdges(\n \"model_request\",\n this.#createModelRouter(),\n modelPaths\n );\n }\n }\n\n // Connect afterModel nodes in reverse sequence\n for (let i = afterModelNodes.length - 1; i > 0; i--) {\n allNodeWorkflows.addEdge(\n afterModelNodes[i].name,\n afterModelNodes[i - 1].name\n );\n }\n\n // Connect first afterModel node (last to execute) to model paths\n if (afterModelNodes.length > 0) {\n const firstAfterModelNode = afterModelNodes[0].name;\n const modelPaths = this.#getModelPaths(toolClasses.filter(isClientTool));\n if (modelPaths.length === 1) {\n allNodeWorkflows.addEdge(firstAfterModelNode, modelPaths[0]);\n } else {\n allNodeWorkflows.addConditionalEdges(\n firstAfterModelNode,\n this.#createModelRouter(),\n modelPaths\n );\n }\n }\n\n /**\n * add edges for tools node\n */\n if (toolClasses.length > 0) {\n // Tools should return to first beforeModel node or agent\n let toolReturnTarget: string;\n if (beforeModelNodes.length > 0) {\n toolReturnTarget = beforeModelNodes[0].name;\n } else {\n toolReturnTarget = \"model_request\";\n }\n\n if (shouldReturnDirect.size > 0) {\n allNodeWorkflows.addConditionalEdges(\n \"tools\",\n this.#createToolsRouter(shouldReturnDirect),\n [toolReturnTarget, END]\n );\n } else {\n allNodeWorkflows.addEdge(\"tools\", toolReturnTarget);\n }\n }\n\n /**\n * compile the graph\n */\n this.#graph = allNodeWorkflows.compile({\n checkpointer: this.options.checkpointer ?? this.options.checkpointSaver,\n interruptBefore: this.options.interruptBefore,\n interruptAfter: this.options.interruptAfter,\n store: this.options.store,\n name: this.options.name,\n description: this.options.description,\n }) as AgentGraph<StructuredResponseFormat, ContextSchema, TMiddlewares>;\n }\n\n /**\n * Get the compiled graph.\n */\n get graph(): AgentGraph<\n StructuredResponseFormat,\n ContextSchema,\n TMiddlewares\n > {\n return this.#graph;\n }\n\n /**\n * Get possible edge destinations from model node.\n * @param toolClasses names of tools to call\n * @returns list of possible edge destinations\n */\n #getModelPaths(\n toolClasses: (ClientTool | ServerTool)[]\n ): (\"tools\" | typeof END)[] {\n const paths: (\"tools\" | typeof END)[] = [];\n if (toolClasses.length > 0) {\n paths.push(\"tools\");\n }\n\n paths.push(END);\n\n return paths;\n }\n\n /**\n * Create routing function for model node conditional edges.\n */\n #createModelRouter() {\n /**\n * determine if the agent should continue or not\n */\n /**\n * ToDo: fix type\n */\n return (state: any) => {\n const messages = state.messages;\n const lastMessage = messages.at(-1);\n\n if (\n !(lastMessage instanceof AIMessage) ||\n !lastMessage.tool_calls ||\n lastMessage.tool_calls.length === 0\n ) {\n return END;\n }\n\n /**\n * The tool node processes a single message.\n */\n if (this.#toolBehaviorVersion === \"v1\") {\n return \"tools\";\n }\n\n /**\n * Route to tools node\n */\n return lastMessage.tool_calls.map(\n (toolCall) => new Send(\"tools\", { ...state, lg_tool_call: toolCall })\n );\n };\n }\n\n /**\n * Create routing function for tools node conditional edges.\n */\n #createToolsRouter(shouldReturnDirect: Set<string>) {\n /**\n * ToDo: fix type\n */\n return (state: any) => {\n const messages = state.messages;\n const lastMessage = messages[messages.length - 1];\n\n // Check if we just executed a returnDirect tool\n if (\n lastMessage instanceof ToolMessage &&\n lastMessage.name &&\n shouldReturnDirect.has(lastMessage.name)\n ) {\n // If we have a response format, route to agent to generate structured response\n // Otherwise, return directly\n return this.options.responseFormat ? \"model_request\" : END;\n }\n\n // For non-returnDirect tools, always route back to agent\n return \"model_request\";\n };\n }\n\n /**\n * Initialize middleware states if not already present in the input state.\n */\n #initializeMiddlewareStates(\n state: InvokeStateParameter<TMiddlewares>\n ): InvokeStateParameter<TMiddlewares> {\n if (\n !this.options.middlewares ||\n this.options.middlewares.length === 0 ||\n state instanceof Command ||\n !state\n ) {\n return state;\n }\n\n const defaultStates = initializeMiddlewareStates(\n this.options.middlewares,\n state\n );\n const updatedState = { ...state } as InvokeStateParameter<TMiddlewares>;\n if (!updatedState) {\n return updatedState;\n }\n\n // Only add defaults for keys that don't exist in current state\n for (const [key, value] of Object.entries(defaultStates)) {\n if (!(key in updatedState)) {\n // @ts-expect-error - ToDo: fix type\n updatedState[key as keyof InvokeStateParameter<TMiddlewares>] = value;\n }\n }\n\n return updatedState;\n }\n\n /**\n * @inheritdoc\n */\n get invoke() {\n type FullState = MergedAgentState<StructuredResponseFormat, TMiddlewares>;\n type FullContext = InferContextInput<ContextSchema> &\n InferMiddlewareContextInputs<TMiddlewares>;\n\n // Create overloaded function type based on whether context has required fields\n type InvokeFunction = IsAllOptional<FullContext> extends true\n ? (\n state: InvokeStateParameter<TMiddlewares>,\n config?: LangGraphRunnableConfig<FullContext>\n ) => Promise<FullState>\n : (\n state: InvokeStateParameter<TMiddlewares>,\n config?: LangGraphRunnableConfig<FullContext>\n ) => Promise<FullState>;\n\n const invokeFunc: InvokeFunction = async (\n state: InvokeStateParameter<TMiddlewares>,\n config?: LangGraphRunnableConfig<FullContext>\n ): Promise<FullState> => {\n const initializedState = this.#initializeMiddlewareStates(state);\n return this.#graph.invoke(\n initializedState,\n config as any\n ) as Promise<FullState>;\n };\n\n return invokeFunc;\n }\n\n /**\n * ToDo(@christian-bromann): Add stream and streamEvents methods\n */\n\n /**\n * Visualize the graph as a PNG image.\n * @param params - Parameters for the drawMermaidPng method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns PNG image as a buffer\n */\n async drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }) {\n const representation = await this.#graph.getGraphAsync();\n const image = await representation.drawMermaidPng(params);\n const arrayBuffer = await image.arrayBuffer();\n const buffer = new Uint8Array(arrayBuffer);\n return buffer;\n }\n\n /**\n * Draw the graph as a Mermaid string.\n * @param params - Parameters for the drawMermaid method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns Mermaid string\n */\n async drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }) {\n const representation = await this.#graph.getGraphAsync();\n return representation.drawMermaid(params);\n }\n}\n"],"mappings":";;;;;;;;;;;;AAgFA,IAAa,aAAb,MAQE;CACA;CAEA,uBAAoC;CAEpC,YACSA,SACP;EADO;EAEP,KAAKC,uBAAuB,QAAQ,WAAW,KAAKA;;;;AAKpD,MAAI,QAAQ,OAAO,OAAO,QAAQ,QAAQ,YACxCC,yCAA2B,QAAQ,IAAI;;;;AAMzC,MAAI,QAAQ,OAAO,QAAQ,MACzB,OAAM,IAAI,MAAM;;;;AAMlB,MAAI,CAAC,QAAQ,OAAO,CAAC,QAAQ,MAC3B,OAAM,IAAI,MACR;EAI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ses.cjs";
|
|
2
|
+
import { AnyAnnotationRoot, ToAnnotationRoot } from "../annotation.cjs";
|
|
3
|
+
import { AgentMiddleware, BuiltInState, CreateAgentParams, InferContextInput, InferMiddlewareContextInputs, InferMiddlewareInputStates, InferMiddlewareStates, IsAllOptional } from "./types.cjs";
|
|
4
|
+
import { InteropZodObject } from "@langchain/core/utils/types";
|
|
5
|
+
import { Command, CompiledStateGraph, LangGraphRunnableConfig } from "@langchain/langgraph";
|
|
6
|
+
|
|
7
|
+
//#region src/agents/middlewareAgent/ReactAgent.d.ts
|
|
8
|
+
// Helper type to get the state definition with middleware states
|
|
9
|
+
type MergedAgentState<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined, TMiddlewares extends readonly AgentMiddleware<any, any, any>[]> = (StructuredResponseFormat extends ResponseFormatUndefined ? BuiltInState : BuiltInState & {
|
|
10
|
+
structuredResponse: StructuredResponseFormat;
|
|
11
|
+
}) & InferMiddlewareStates<TMiddlewares>;
|
|
12
|
+
type InvokeStateParameter<TMiddlewares extends readonly AgentMiddleware<any, any, any>[]> = (BuiltInState & InferMiddlewareInputStates<TMiddlewares>) | Command<any, any, any> | null;
|
|
13
|
+
type AgentGraph<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []> = CompiledStateGraph<any, any,
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
any, any, MergedAgentState<StructuredResponseFormat, TMiddlewares>, ToAnnotationRoot<ContextSchema>["spec"], unknown>;
|
|
16
|
+
declare class ReactAgent<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []> {
|
|
17
|
+
#private;
|
|
18
|
+
options: CreateAgentParams<StructuredResponseFormat, ContextSchema>;
|
|
19
|
+
constructor(options: CreateAgentParams<StructuredResponseFormat, ContextSchema>);
|
|
20
|
+
/**
|
|
21
|
+
* Get the compiled graph.
|
|
22
|
+
*/
|
|
23
|
+
get graph(): AgentGraph<StructuredResponseFormat, ContextSchema, TMiddlewares>;
|
|
24
|
+
/**
|
|
25
|
+
* @inheritdoc
|
|
26
|
+
*/
|
|
27
|
+
get invoke(): IsAllOptional<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> extends true ? (state: InvokeStateParameter<TMiddlewares>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddlewares>> : (state: InvokeStateParameter<TMiddlewares>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddlewares>>;
|
|
28
|
+
/**
|
|
29
|
+
* ToDo(@christian-bromann): Add stream and streamEvents methods
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Visualize the graph as a PNG image.
|
|
33
|
+
* @param params - Parameters for the drawMermaidPng method.
|
|
34
|
+
* @param params.withStyles - Whether to include styles in the graph.
|
|
35
|
+
* @param params.curveStyle - The style of the graph's curves.
|
|
36
|
+
* @param params.nodeColors - The colors of the graph's nodes.
|
|
37
|
+
* @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.
|
|
38
|
+
* @param params.backgroundColor - The background color of the graph.
|
|
39
|
+
* @returns PNG image as a buffer
|
|
40
|
+
*/
|
|
41
|
+
drawMermaidPng(params?: {
|
|
42
|
+
withStyles?: boolean;
|
|
43
|
+
curveStyle?: string;
|
|
44
|
+
nodeColors?: Record<string, string>;
|
|
45
|
+
wrapLabelNWords?: number;
|
|
46
|
+
backgroundColor?: string;
|
|
47
|
+
}): Promise<Uint8Array<ArrayBuffer>>;
|
|
48
|
+
/**
|
|
49
|
+
* Draw the graph as a Mermaid string.
|
|
50
|
+
* @param params - Parameters for the drawMermaid method.
|
|
51
|
+
* @param params.withStyles - Whether to include styles in the graph.
|
|
52
|
+
* @param params.curveStyle - The style of the graph's curves.
|
|
53
|
+
* @param params.nodeColors - The colors of the graph's nodes.
|
|
54
|
+
* @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.
|
|
55
|
+
* @param params.backgroundColor - The background color of the graph.
|
|
56
|
+
* @returns Mermaid string
|
|
57
|
+
*/
|
|
58
|
+
drawMermaid(params?: {
|
|
59
|
+
withStyles?: boolean;
|
|
60
|
+
curveStyle?: string;
|
|
61
|
+
nodeColors?: Record<string, string>;
|
|
62
|
+
wrapLabelNWords?: number;
|
|
63
|
+
backgroundColor?: string;
|
|
64
|
+
}): Promise<string>;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { ReactAgent };
|
|
68
|
+
//# sourceMappingURL=ReactAgent.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactAgent.d.cts","names":["InteropZodObject","Command","CompiledStateGraph","LangGraphRunnableConfig","CreateAgentParams","AgentMiddleware","InferMiddlewareStates","InferMiddlewareInputStates","BuiltInState","InferMiddlewareContextInputs","IsAllOptional","InferContextInput","AnyAnnotationRoot","ToAnnotationRoot","ResponseFormatUndefined","MergedAgentState","Record","StructuredResponseFormat","TMiddlewares","InvokeStateParameter","AgentGraph","ContextSchema","ReactAgent","Promise","ArrayBuffer","Uint8Array"],"sources":["../../../src/agents/middlewareAgent/ReactAgent.d.ts"],"sourcesContent":["/* eslint-disable prefer-destructuring, no-instanceof/no-instanceof, @typescript-eslint/ban-types */\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\nimport { Command, CompiledStateGraph, type LangGraphRunnableConfig } from \"@langchain/langgraph\";\nimport { CreateAgentParams, AgentMiddleware, InferMiddlewareStates, InferMiddlewareInputStates, BuiltInState, InferMiddlewareContextInputs, IsAllOptional, InferContextInput } from \"./types.js\";\nimport { type AnyAnnotationRoot, type ToAnnotationRoot } from \"../annotation.js\";\nimport type { ResponseFormatUndefined } from \"../responses.js\";\n// Helper type to get the state definition with middleware states\ntype MergedAgentState<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined, TMiddlewares extends readonly AgentMiddleware<any, any, any>[]> = (StructuredResponseFormat extends ResponseFormatUndefined ? BuiltInState : BuiltInState & {\n structuredResponse: StructuredResponseFormat;\n}) & InferMiddlewareStates<TMiddlewares>;\ntype InvokeStateParameter<TMiddlewares extends readonly AgentMiddleware<any, any, any>[]> = (BuiltInState & InferMiddlewareInputStates<TMiddlewares>) | Command<any, any, any> | null;\ntype AgentGraph<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []> = CompiledStateGraph<any, any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nany, any, MergedAgentState<StructuredResponseFormat, TMiddlewares>, ToAnnotationRoot<ContextSchema>[\"spec\"], unknown>;\nexport declare class ReactAgent<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []> {\n #private;\n options: CreateAgentParams<StructuredResponseFormat, ContextSchema>;\n constructor(options: CreateAgentParams<StructuredResponseFormat, ContextSchema>);\n /**\n * Get the compiled graph.\n */\n get graph(): AgentGraph<StructuredResponseFormat, ContextSchema, TMiddlewares>;\n /**\n * @inheritdoc\n */\n get invoke(): IsAllOptional<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> extends true ? (state: InvokeStateParameter<TMiddlewares>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddlewares>> : (state: InvokeStateParameter<TMiddlewares>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddlewares>>;\n /**\n * ToDo(@christian-bromann): Add stream and streamEvents methods\n */\n /**\n * Visualize the graph as a PNG image.\n * @param params - Parameters for the drawMermaidPng method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns PNG image as a buffer\n */\n drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<Uint8Array<ArrayBuffer>>;\n /**\n * Draw the graph as a Mermaid string.\n * @param params - Parameters for the drawMermaid method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns Mermaid string\n */\n drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<string>;\n}\nexport {};\n"],"mappings":";;;;;;;;AAK+D,KAE1De,gBAAAA,CAAAA,iCAAkDC,MAAlC,CAAA,MAAA,EAAA,GAAA,CAAA,GAAwDF,uBAAxD,EAAA,qBAAA,SAA+GT,eAA/G,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA,EAAA,CAAA,GAAA,CAAoJY,wBAApJ,SAAqLH,uBAArL,GAA+MN,YAA/M,GAA8NA,YAA9N,GAAA;EAAA,kBAAA,EACGS,wBADH;CAAA,CAAA,GAEhBX,qBAFkDU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AAAA;IAAkB,eAAA,CAAA,EAAA,MAAA;IAG1QoB,eAAU,CAAA,EAAA,MAAA;EAAA,CAAA,CAAA,EA+BvBC,OA/BuB,CA+BfE,UA/Be,CA+BJD,WA/BI,CAAA,CAAA;EAAA;;;;;;;;;;EAED,WACaP,CAAAA,MAIsC,CAJtCA,EAAAA;IAA0BI,UAAAA,CAAAA,EAAAA,OAAAA;IAA5CjB,UAAAA,CAAAA,EAAAA,MAAAA;IAIGa,UAAAA,CAAAA,EAsCPD,MAtCOC,CAAAA,MAAAA,EAAAA,MAAAA,CAAAA;IAA0BI,eAAAA,CAAAA,EAAAA,MAAAA;IAAeH,eAAAA,CAAAA,EAAAA,MAAAA;EAAY,CAAA,CAAA,EAyCzEK,OAzCSH,CAAAA,MAAAA,CAAAA"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ResponseFormatUndefined } from "../responses.js";
|
|
2
|
+
import { AnyAnnotationRoot, ToAnnotationRoot } from "../annotation.js";
|
|
3
|
+
import { AgentMiddleware, BuiltInState, CreateAgentParams, InferContextInput, InferMiddlewareContextInputs, InferMiddlewareInputStates, InferMiddlewareStates, IsAllOptional } from "./types.js";
|
|
4
|
+
import { Command, CompiledStateGraph, LangGraphRunnableConfig } from "@langchain/langgraph";
|
|
5
|
+
import { InteropZodObject } from "@langchain/core/utils/types";
|
|
6
|
+
|
|
7
|
+
//#region src/agents/middlewareAgent/ReactAgent.d.ts
|
|
8
|
+
// Helper type to get the state definition with middleware states
|
|
9
|
+
type MergedAgentState<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined, TMiddlewares extends readonly AgentMiddleware<any, any, any>[]> = (StructuredResponseFormat extends ResponseFormatUndefined ? BuiltInState : BuiltInState & {
|
|
10
|
+
structuredResponse: StructuredResponseFormat;
|
|
11
|
+
}) & InferMiddlewareStates<TMiddlewares>;
|
|
12
|
+
type InvokeStateParameter<TMiddlewares extends readonly AgentMiddleware<any, any, any>[]> = (BuiltInState & InferMiddlewareInputStates<TMiddlewares>) | Command<any, any, any> | null;
|
|
13
|
+
type AgentGraph<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []> = CompiledStateGraph<any, any,
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
15
|
+
any, any, MergedAgentState<StructuredResponseFormat, TMiddlewares>, ToAnnotationRoot<ContextSchema>["spec"], unknown>;
|
|
16
|
+
declare class ReactAgent<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []> {
|
|
17
|
+
#private;
|
|
18
|
+
options: CreateAgentParams<StructuredResponseFormat, ContextSchema>;
|
|
19
|
+
constructor(options: CreateAgentParams<StructuredResponseFormat, ContextSchema>);
|
|
20
|
+
/**
|
|
21
|
+
* Get the compiled graph.
|
|
22
|
+
*/
|
|
23
|
+
get graph(): AgentGraph<StructuredResponseFormat, ContextSchema, TMiddlewares>;
|
|
24
|
+
/**
|
|
25
|
+
* @inheritdoc
|
|
26
|
+
*/
|
|
27
|
+
get invoke(): IsAllOptional<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> extends true ? (state: InvokeStateParameter<TMiddlewares>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddlewares>> : (state: InvokeStateParameter<TMiddlewares>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddlewares>>;
|
|
28
|
+
/**
|
|
29
|
+
* ToDo(@christian-bromann): Add stream and streamEvents methods
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* Visualize the graph as a PNG image.
|
|
33
|
+
* @param params - Parameters for the drawMermaidPng method.
|
|
34
|
+
* @param params.withStyles - Whether to include styles in the graph.
|
|
35
|
+
* @param params.curveStyle - The style of the graph's curves.
|
|
36
|
+
* @param params.nodeColors - The colors of the graph's nodes.
|
|
37
|
+
* @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.
|
|
38
|
+
* @param params.backgroundColor - The background color of the graph.
|
|
39
|
+
* @returns PNG image as a buffer
|
|
40
|
+
*/
|
|
41
|
+
drawMermaidPng(params?: {
|
|
42
|
+
withStyles?: boolean;
|
|
43
|
+
curveStyle?: string;
|
|
44
|
+
nodeColors?: Record<string, string>;
|
|
45
|
+
wrapLabelNWords?: number;
|
|
46
|
+
backgroundColor?: string;
|
|
47
|
+
}): Promise<Uint8Array<ArrayBuffer>>;
|
|
48
|
+
/**
|
|
49
|
+
* Draw the graph as a Mermaid string.
|
|
50
|
+
* @param params - Parameters for the drawMermaid method.
|
|
51
|
+
* @param params.withStyles - Whether to include styles in the graph.
|
|
52
|
+
* @param params.curveStyle - The style of the graph's curves.
|
|
53
|
+
* @param params.nodeColors - The colors of the graph's nodes.
|
|
54
|
+
* @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.
|
|
55
|
+
* @param params.backgroundColor - The background color of the graph.
|
|
56
|
+
* @returns Mermaid string
|
|
57
|
+
*/
|
|
58
|
+
drawMermaid(params?: {
|
|
59
|
+
withStyles?: boolean;
|
|
60
|
+
curveStyle?: string;
|
|
61
|
+
nodeColors?: Record<string, string>;
|
|
62
|
+
wrapLabelNWords?: number;
|
|
63
|
+
backgroundColor?: string;
|
|
64
|
+
}): Promise<string>;
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
export { ReactAgent };
|
|
68
|
+
//# sourceMappingURL=ReactAgent.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactAgent.d.ts","names":["InteropZodObject","Command","CompiledStateGraph","LangGraphRunnableConfig","CreateAgentParams","AgentMiddleware","InferMiddlewareStates","InferMiddlewareInputStates","BuiltInState","InferMiddlewareContextInputs","IsAllOptional","InferContextInput","AnyAnnotationRoot","ToAnnotationRoot","ResponseFormatUndefined","MergedAgentState","Record","StructuredResponseFormat","TMiddlewares","InvokeStateParameter","AgentGraph","ContextSchema","ReactAgent","Promise","ArrayBuffer","Uint8Array"],"sources":["../../../src/agents/middlewareAgent/ReactAgent.d.ts"],"sourcesContent":["/* eslint-disable prefer-destructuring, no-instanceof/no-instanceof, @typescript-eslint/ban-types */\nimport { InteropZodObject } from \"@langchain/core/utils/types\";\nimport { Command, CompiledStateGraph, type LangGraphRunnableConfig } from \"@langchain/langgraph\";\nimport { CreateAgentParams, AgentMiddleware, InferMiddlewareStates, InferMiddlewareInputStates, BuiltInState, InferMiddlewareContextInputs, IsAllOptional, InferContextInput } from \"./types.js\";\nimport { type AnyAnnotationRoot, type ToAnnotationRoot } from \"../annotation.js\";\nimport type { ResponseFormatUndefined } from \"../responses.js\";\n// Helper type to get the state definition with middleware states\ntype MergedAgentState<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined, TMiddlewares extends readonly AgentMiddleware<any, any, any>[]> = (StructuredResponseFormat extends ResponseFormatUndefined ? BuiltInState : BuiltInState & {\n structuredResponse: StructuredResponseFormat;\n}) & InferMiddlewareStates<TMiddlewares>;\ntype InvokeStateParameter<TMiddlewares extends readonly AgentMiddleware<any, any, any>[]> = (BuiltInState & InferMiddlewareInputStates<TMiddlewares>) | Command<any, any, any> | null;\ntype AgentGraph<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []> = CompiledStateGraph<any, any, \n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nany, any, MergedAgentState<StructuredResponseFormat, TMiddlewares>, ToAnnotationRoot<ContextSchema>[\"spec\"], unknown>;\nexport declare class ReactAgent<StructuredResponseFormat extends Record<string, any> | ResponseFormatUndefined = Record<string, any>, ContextSchema extends AnyAnnotationRoot | InteropZodObject = AnyAnnotationRoot, TMiddlewares extends readonly AgentMiddleware<any, any, any>[] = []> {\n #private;\n options: CreateAgentParams<StructuredResponseFormat, ContextSchema>;\n constructor(options: CreateAgentParams<StructuredResponseFormat, ContextSchema>);\n /**\n * Get the compiled graph.\n */\n get graph(): AgentGraph<StructuredResponseFormat, ContextSchema, TMiddlewares>;\n /**\n * @inheritdoc\n */\n get invoke(): IsAllOptional<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> extends true ? (state: InvokeStateParameter<TMiddlewares>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddlewares>> : (state: InvokeStateParameter<TMiddlewares>, config?: LangGraphRunnableConfig<InferContextInput<ContextSchema> & InferMiddlewareContextInputs<TMiddlewares>> | undefined) => Promise<MergedAgentState<StructuredResponseFormat, TMiddlewares>>;\n /**\n * ToDo(@christian-bromann): Add stream and streamEvents methods\n */\n /**\n * Visualize the graph as a PNG image.\n * @param params - Parameters for the drawMermaidPng method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns PNG image as a buffer\n */\n drawMermaidPng(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<Uint8Array<ArrayBuffer>>;\n /**\n * Draw the graph as a Mermaid string.\n * @param params - Parameters for the drawMermaid method.\n * @param params.withStyles - Whether to include styles in the graph.\n * @param params.curveStyle - The style of the graph's curves.\n * @param params.nodeColors - The colors of the graph's nodes.\n * @param params.wrapLabelNWords - The maximum number of words to wrap in a node's label.\n * @param params.backgroundColor - The background color of the graph.\n * @returns Mermaid string\n */\n drawMermaid(params?: {\n withStyles?: boolean;\n curveStyle?: string;\n nodeColors?: Record<string, string>;\n wrapLabelNWords?: number;\n backgroundColor?: string;\n }): Promise<string>;\n}\nexport {};\n"],"mappings":";;;;;;;;AAK+D,KAE1De,gBAAAA,CAAAA,iCAAkDC,MAAlC,CAAA,MAAA,EAAA,GAAA,CAAA,GAAwDF,uBAAxD,EAAA,qBAAA,SAA+GT,eAA/G,CAAA,GAAA,EAAA,GAAA,EAAA,GAAA,CAAA,EAAA,CAAA,GAAA,CAAoJY,wBAApJ,SAAqLH,uBAArL,GAA+MN,YAA/M,GAA8NA,YAA9N,GAAA;EAAA,kBAAA,EACGS,wBADH;CAAA,CAAA,GAEhBX,qBAFkDU,CAE5BE,YAF4BF,CAAAA;KAGlDG,oBAHwEL,CAAAA,qBAAAA,SAGrBT,eAHqBS,CAAAA,GAAAA,EAAAA,GAAAA,EAAAA,GAAAA,CAAAA,EAAAA,CAAAA,GAAAA,CAGgBN,YAHhBM,GAG+BP,0BAH/BO,CAG0DI,YAH1DJ,CAAAA,CAAAA,GAG2Eb,OAH3Ea,CAAAA,GAAAA,EAAAA,GAAAA,EAAAA,GAAAA,CAAAA,GAAAA,IAAAA;KAIxEM,UAJ+Hf,CAAAA,iCAInFW,MAJmFX,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,GAI7DS,uBAJ6DT,GAInCW,MAJmCX,CAAAA,MAAAA,EAAAA,GAAAA,CAAAA,EAAAA,sBAIQO,iBAJRP,GAI4BL,gBAJ5BK,GAI+CO,iBAJ/CP,EAAAA,qBAAAA,SAIgGA,eAJhGA,CAAAA,GAAAA,EAAAA,GAAAA,EAAAA,GAAAA,CAAAA,EAAAA,GAAAA,EAAAA,CAAAA,GAIyIH,kBAJzIG,CAAAA,GAAAA,EAAAA,GAAAA;;GAA6D,EAAA,G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