@minded-ai/mindedjs 1.0.20 → 1.0.21
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/agent.d.ts +9 -11
- package/dist/agent.js +76 -53
- package/dist/agent.js.map +1 -1
- package/dist/checkpointer/checkpointSaverFactory.d.ts +7 -0
- package/dist/checkpointer/checkpointSaverFactory.js +30 -0
- package/dist/checkpointer/checkpointSaverFactory.js.map +1 -0
- package/dist/edges/createDirectEdge.d.ts +4 -5
- package/dist/edges/createDirectEdge.js +5 -6
- package/dist/edges/createDirectEdge.js.map +1 -1
- package/dist/edges/createLogicalRouter.d.ts +4 -6
- package/dist/edges/createLogicalRouter.js +4 -6
- package/dist/edges/createLogicalRouter.js.map +1 -1
- package/dist/edges/createPromptRouter.d.ts +5 -5
- package/dist/edges/createPromptRouter.js +8 -10
- package/dist/edges/createPromptRouter.js.map +1 -1
- package/dist/edges/edgeFactory.d.ts +6 -5
- package/dist/edges/edgeFactory.js +55 -19
- package/dist/edges/edgeFactory.js.map +1 -1
- package/dist/events/AgentEvents.d.ts +2 -3
- package/dist/events/AgentEvents.js.map +1 -1
- package/dist/events/index.d.ts +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js.map +1 -1
- package/dist/llm/createLlmInstance.js +3 -0
- package/dist/llm/createLlmInstance.js.map +1 -1
- package/dist/nodes/addHumanInTheLoopNode.d.ts +8 -0
- package/dist/nodes/addHumanInTheLoopNode.js +17 -0
- package/dist/nodes/addHumanInTheLoopNode.js.map +1 -0
- package/dist/nodes/addPromptNode.d.ts +11 -11
- package/dist/nodes/addPromptNode.js +6 -26
- package/dist/nodes/addPromptNode.js.map +1 -1
- package/dist/nodes/addToolNode.d.ts +3 -3
- package/dist/nodes/addToolNode.js +16 -8
- package/dist/nodes/addToolNode.js.map +1 -1
- package/dist/nodes/addTriggerNode.d.ts +4 -7
- package/dist/nodes/addTriggerNode.js +3 -37
- package/dist/nodes/addTriggerNode.js.map +1 -1
- package/dist/nodes/nodeFactory.d.ts +10 -10
- package/dist/nodes/nodeFactory.js +3 -3
- package/dist/nodes/nodeFactory.js.map +1 -1
- package/dist/platform/analytics.js +2 -2
- package/dist/platform/analytics.js.map +1 -1
- package/dist/platform/mindedCheckpointSaver.d.ts +2 -2
- package/dist/platform/mindedCheckpointSaver.js +59 -14
- package/dist/platform/mindedCheckpointSaver.js.map +1 -1
- package/dist/platform/mindedConnection.d.ts +6 -2
- package/dist/platform/mindedConnection.js +93 -57
- package/dist/platform/mindedConnection.js.map +1 -1
- package/dist/platform/mindedConnectionTypes.d.ts +6 -1
- package/dist/platform/mindedConnectionTypes.js +0 -1
- package/dist/platform/mindedConnectionTypes.js.map +1 -1
- package/dist/platform/mindedRequest.d.ts +1 -1
- package/dist/platform/mindedRequest.js +4 -4
- package/dist/platform/mindedRequest.js.map +1 -1
- package/dist/types/Agent.types.d.ts +6 -0
- package/dist/types/Flows.types.d.ts +21 -20
- package/dist/types/Flows.types.js.map +1 -1
- package/dist/types/LLM.types.d.ts +3 -11
- package/dist/types/LLM.types.js +3 -8
- package/dist/types/LLM.types.js.map +1 -1
- package/dist/types/LangGraph.types.d.ts +7 -8
- package/dist/types/LangGraph.types.js +1 -1
- package/dist/types/LangGraph.types.js.map +1 -1
- package/dist/types/Tools.types.d.ts +2 -1
- package/package.json +1 -1
package/dist/agent.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { Tool } from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { z } from "zod";
|
|
1
|
+
import { Tool } from './types/Tools.types';
|
|
2
|
+
import { BaseCheckpointSaver } from '@langchain/langgraph';
|
|
3
|
+
import { AgentEventRequestPayloads, AgentEventResponsePayloads } from './events/AgentEvents';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { MindedSDKConfig } from './types/Agent.types';
|
|
7
6
|
type CreateAgentParams<Memory> = {
|
|
8
7
|
memorySchema: z.ZodSchema;
|
|
9
|
-
|
|
8
|
+
config: MindedSDKConfig;
|
|
10
9
|
tools: Tool<any, Memory>[];
|
|
11
|
-
llm: BaseLanguageModel;
|
|
12
10
|
platformToken?: string;
|
|
13
|
-
memorySaver?:
|
|
11
|
+
memorySaver?: BaseCheckpointSaver;
|
|
14
12
|
};
|
|
15
13
|
export declare class Agent {
|
|
16
14
|
private memorySchema;
|
|
@@ -27,8 +25,8 @@ export declare class Agent {
|
|
|
27
25
|
private validate;
|
|
28
26
|
private initializeGraph;
|
|
29
27
|
private init;
|
|
30
|
-
invoke({ triggerBody, triggerName, sessionId
|
|
31
|
-
triggerBody:
|
|
28
|
+
invoke({ triggerBody, triggerName, sessionId }: {
|
|
29
|
+
triggerBody: any;
|
|
32
30
|
triggerName: string;
|
|
33
31
|
sessionId?: string;
|
|
34
32
|
}): Promise<import("@langchain/langgraph").StateType<import("@langchain/langgraph").StateDefinition>>;
|
package/dist/agent.js
CHANGED
|
@@ -37,77 +37,93 @@ exports.Agent = void 0;
|
|
|
37
37
|
const Flows_types_1 = require("./types/Flows.types");
|
|
38
38
|
const uuid_1 = require("uuid");
|
|
39
39
|
const langgraph_1 = require("@langchain/langgraph");
|
|
40
|
-
const langgraph_2 = require("@langchain/langgraph");
|
|
41
40
|
const nodeFactory_1 = require("./nodes/nodeFactory");
|
|
42
41
|
const LangGraph_types_1 = require("./types/LangGraph.types");
|
|
43
42
|
const edgeFactory_1 = require("./edges/edgeFactory");
|
|
43
|
+
const AgentEvents_1 = require("./events/AgentEvents");
|
|
44
44
|
const mindedConnection_1 = require("./platform/mindedConnection");
|
|
45
45
|
const mindedConnectionTypes_1 = require("./platform/mindedConnectionTypes");
|
|
46
46
|
const fs = __importStar(require("fs"));
|
|
47
47
|
const path = __importStar(require("path"));
|
|
48
48
|
const yaml = __importStar(require("js-yaml"));
|
|
49
|
+
const createLlmInstance_1 = require("./llm/createLlmInstance");
|
|
50
|
+
const dotenv_1 = require("dotenv");
|
|
51
|
+
const path_1 = require("path");
|
|
52
|
+
const checkpointSaverFactory_1 = require("./checkpointer/checkpointSaverFactory");
|
|
53
|
+
(0, dotenv_1.config)({ path: (0, path_1.resolve)(__dirname, '../.env') });
|
|
49
54
|
class Agent {
|
|
50
55
|
constructor(params) {
|
|
56
|
+
this.mindedConnection = null;
|
|
51
57
|
// Event handlers storage keyed by event name. Handlers can optionally return a value.
|
|
52
58
|
this.eventHandlers = {};
|
|
53
|
-
const {
|
|
59
|
+
const { config, tools, platformToken, memorySaver, memorySchema } = params;
|
|
54
60
|
this.memorySchema = memorySchema;
|
|
55
|
-
this.flows = this.loadFlowsFromDirectory(
|
|
61
|
+
this.flows = this.loadFlowsFromDirectory(config.flows);
|
|
56
62
|
this.tools = tools;
|
|
57
63
|
this.platformToken = platformToken;
|
|
58
|
-
this.llm = llm;
|
|
59
|
-
this.checkpointer = memorySaver ||
|
|
64
|
+
this.llm = (0, createLlmInstance_1.createLlmInstance)(config.llm);
|
|
65
|
+
this.checkpointer = memorySaver || (0, checkpointSaverFactory_1.createCheckpointSaver)('');
|
|
60
66
|
this.validate();
|
|
61
67
|
this.compiledGraph = this.initializeGraph();
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
if (process.env.NODE_ENV !== 'test' && process.env.NO_PLATFORM_CONNECT !== 'true') {
|
|
69
|
+
this.mindedConnection = new mindedConnection_1.MindedConnection();
|
|
70
|
+
this.mindedConnection.start();
|
|
71
|
+
this.mindedConnection.on(mindedConnectionTypes_1.MindedConnectionSocketMessageType.OnAppTrigger, async (message) => {
|
|
72
|
+
const trigger = message;
|
|
73
|
+
await this.invoke({
|
|
74
|
+
triggerBody: trigger.body,
|
|
75
|
+
triggerName: trigger.name,
|
|
76
|
+
sessionId: trigger.cnvId,
|
|
77
|
+
});
|
|
78
|
+
});
|
|
71
79
|
}
|
|
80
|
+
}
|
|
81
|
+
loadFlowsFromDirectory(flowsDirectories) {
|
|
72
82
|
const flows = [];
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
for (const flowsDirectory of flowsDirectories) {
|
|
84
|
+
if (!fs.existsSync(flowsDirectory)) {
|
|
85
|
+
throw new Error(`Flows directory does not exist: ${flowsDirectory}`);
|
|
86
|
+
}
|
|
87
|
+
const files = fs.readdirSync(flowsDirectory);
|
|
88
|
+
for (const file of files) {
|
|
89
|
+
if (file.endsWith('.yaml') || file.endsWith('.yml')) {
|
|
90
|
+
const filePath = path.join(flowsDirectory, file);
|
|
91
|
+
try {
|
|
92
|
+
const fileContent = fs.readFileSync(filePath, 'utf8');
|
|
93
|
+
const parsedFlow = yaml.load(fileContent);
|
|
94
|
+
// Validate that the parsed flow has the required structure
|
|
95
|
+
if (!parsedFlow.name || !parsedFlow.nodes || !parsedFlow.edges) {
|
|
96
|
+
throw new Error(`Invalid flow structure in ${file}. Flow must have name, nodes, and edges.`);
|
|
97
|
+
}
|
|
98
|
+
flows.push(parsedFlow);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
throw new Error(`Failed to parse flow file ${file}: ${error}`);
|
|
83
102
|
}
|
|
84
|
-
flows.push(parsedFlow);
|
|
85
|
-
console.log(`Loaded flow: ${parsedFlow.name} from ${file}`);
|
|
86
|
-
}
|
|
87
|
-
catch (error) {
|
|
88
|
-
throw new Error(`Failed to parse flow file ${file}: ${error}`);
|
|
89
103
|
}
|
|
90
104
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
105
|
+
if (flows.length === 0) {
|
|
106
|
+
throw new Error(`No YAML flow files found in directory: ${flowsDirectory}`);
|
|
107
|
+
}
|
|
94
108
|
}
|
|
95
109
|
return flows;
|
|
96
110
|
}
|
|
97
111
|
validate() {
|
|
98
112
|
if (this.flows.length === 0) {
|
|
99
|
-
throw new Error(
|
|
113
|
+
throw new Error('No flows provided');
|
|
100
114
|
}
|
|
101
115
|
}
|
|
102
116
|
initializeGraph() {
|
|
103
117
|
const nodes = this.flows.flatMap((flow) => flow.nodes);
|
|
104
118
|
const edges = this.flows.flatMap((flow) => flow.edges);
|
|
105
119
|
// Initialize the graph
|
|
106
|
-
const graph = new langgraph_1.StateGraph(LangGraph_types_1.stateAnnotation)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
// Add nodes
|
|
120
|
+
const graph = new langgraph_1.StateGraph(LangGraph_types_1.stateAnnotation).addNode('init', this.init.bind(this)).addEdge('__start__', 'init');
|
|
121
|
+
// Add nodes and create nodes object
|
|
122
|
+
const nodesObject = {};
|
|
110
123
|
nodes.forEach((node) => {
|
|
124
|
+
// Add to nodes object
|
|
125
|
+
nodesObject[node.name] = node;
|
|
126
|
+
// Add to graph
|
|
111
127
|
(0, nodeFactory_1.nodeFactory)({
|
|
112
128
|
graph,
|
|
113
129
|
node,
|
|
@@ -117,17 +133,16 @@ class Agent {
|
|
|
117
133
|
});
|
|
118
134
|
});
|
|
119
135
|
// Add edges
|
|
120
|
-
(0, edgeFactory_1.edgeFactory)({ graph, edges, llm: this.llm });
|
|
121
|
-
// Add edges to trigger nodes
|
|
136
|
+
(0, edgeFactory_1.edgeFactory)({ graph, edges, nodes: nodesObject, llm: this.llm });
|
|
122
137
|
nodes.forEach((node) => {
|
|
123
138
|
if (node.type === Flows_types_1.NodeType.TRIGGER) {
|
|
124
|
-
graph.addEdge(
|
|
139
|
+
graph.addEdge('__start__', node.name);
|
|
125
140
|
}
|
|
126
141
|
});
|
|
127
142
|
// Compile the graph
|
|
128
143
|
return graph.compile({ checkpointer: this.checkpointer });
|
|
129
144
|
}
|
|
130
|
-
init(
|
|
145
|
+
init() {
|
|
131
146
|
return {
|
|
132
147
|
messages: [],
|
|
133
148
|
memory: {},
|
|
@@ -135,28 +150,36 @@ class Agent {
|
|
|
135
150
|
interruptedNode: null,
|
|
136
151
|
};
|
|
137
152
|
}
|
|
138
|
-
async invoke({ triggerBody, triggerName, sessionId
|
|
139
|
-
var _a;
|
|
153
|
+
async invoke({ triggerBody, triggerName, sessionId }) {
|
|
154
|
+
var _a, _b, _c, _d;
|
|
140
155
|
const session = sessionId || (0, uuid_1.v4)();
|
|
156
|
+
const results = await this.emit(AgentEvents_1.AgentEvents.TRIGGER_EVENT, {
|
|
157
|
+
triggerName,
|
|
158
|
+
triggerBody,
|
|
159
|
+
});
|
|
160
|
+
const handlerResult = results.find((r) => r !== undefined);
|
|
161
|
+
if (handlerResult === false) {
|
|
162
|
+
console.log(`Disqualified trigger ${triggerName}`);
|
|
163
|
+
throw new Error('Disqualified trigger');
|
|
164
|
+
}
|
|
165
|
+
const memoryUpdate = (handlerResult === null || handlerResult === void 0 ? void 0 : handlerResult.memory) || {};
|
|
166
|
+
const messages = (_a = handlerResult === null || handlerResult === void 0 ? void 0 : handlerResult.messages) !== null && _a !== void 0 ? _a : [];
|
|
141
167
|
console.log(`Invoking trigger ${triggerName} with session ${session}`);
|
|
142
168
|
const config = { configurable: { thread_id: session, recursionLimit: 3 } };
|
|
143
|
-
const triggerNode = this.compiledGraph.builder.nodes[triggerName];
|
|
144
|
-
if (!triggerNode) {
|
|
145
|
-
|
|
146
|
-
}
|
|
169
|
+
// const triggerNode = this.compiledGraph.builder.nodes[triggerName];
|
|
170
|
+
// if (!triggerNode) {
|
|
171
|
+
// throw new Error(`Trigger node not found: ${triggerName}`);
|
|
172
|
+
// }
|
|
147
173
|
const state = await this.compiledGraph.getState(config);
|
|
148
|
-
const triggerMetadata = { name: triggerName, triggerBody };
|
|
149
174
|
// Resume interruption
|
|
150
|
-
if ((
|
|
175
|
+
if (((_d = (_c = (_b = state.tasks) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.interrupts) === null || _d === void 0 ? void 0 : _d.length) > 0) {
|
|
151
176
|
const res = await this.compiledGraph.invoke(new langgraph_1.Command({
|
|
152
|
-
resume:
|
|
153
|
-
goto: triggerName,
|
|
154
|
-
update: { triggerMetadata },
|
|
177
|
+
resume: { memory: memoryUpdate, messages },
|
|
155
178
|
}), config);
|
|
156
179
|
return res;
|
|
157
180
|
}
|
|
158
181
|
else {
|
|
159
|
-
const res = await this.compiledGraph.invoke({
|
|
182
|
+
const res = await this.compiledGraph.invoke({ messages, memory: memoryUpdate }, config);
|
|
160
183
|
return res;
|
|
161
184
|
}
|
|
162
185
|
}
|
package/dist/agent.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAA2D;AAE3D,+BAAoC;AAEpC,oDAA2D;AAE3D,qDAAkD;AAClD,6DAA2F;AAC3F,qDAAkD;AAClD,sDAA0G;AAG1G,kEAA+D;AAC/D,4EAAsI;AACtI,uCAAyB;AACzB,2CAA6B;AAC7B,8CAAgC;AAEhC,+DAA4D;AAC5D,mCAAgC;AAChC,+BAA+B;AAC/B,kFAA8E;AAE9E,IAAA,eAAM,EAAC,EAAE,IAAI,EAAE,IAAA,cAAO,EAAC,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC,CAAC;AAShD,MAAa,KAAK;IAmBhB,YAAY,MAA4D;QAbhE,qBAAgB,GAA4B,IAAI,CAAC;QAMzD,sFAAsF;QAC9E,kBAAa,GAIjB,EAAE,CAAC;QAGL,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,GAAG,MAAM,CAAC;QAC3E,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,CA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AAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QACvG,OAAO,OAAO,CAAC;IACjB,CAAC;CACF;AA7LD,sBA6LC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BaseCheckpointSaver } from '@langchain/langgraph';
|
|
2
|
+
/**
|
|
3
|
+
* Factory function to create the appropriate checkpoint saver based on environment variables
|
|
4
|
+
* @param platformToken - Optional platform token for remote checkpoint saving
|
|
5
|
+
* @returns BaseCheckpointSaver instance (either MemorySaver or MindedCheckpointSaver)
|
|
6
|
+
*/
|
|
7
|
+
export declare function createCheckpointSaver(platformToken: string): BaseCheckpointSaver;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createCheckpointSaver = createCheckpointSaver;
|
|
4
|
+
const langgraph_1 = require("@langchain/langgraph");
|
|
5
|
+
const mindedCheckpointSaver_1 = require("../platform/mindedCheckpointSaver");
|
|
6
|
+
/**
|
|
7
|
+
* Factory function to create the appropriate checkpoint saver based on environment variables
|
|
8
|
+
* @param platformToken - Optional platform token for remote checkpoint saving
|
|
9
|
+
* @returns BaseCheckpointSaver instance (either MemorySaver or MindedCheckpointSaver)
|
|
10
|
+
*/
|
|
11
|
+
function createCheckpointSaver(platformToken) {
|
|
12
|
+
const useRemoteCheckpointSaver = process.env.REMOTE_CHECKPOINT_SAVER === 'true';
|
|
13
|
+
if (!useRemoteCheckpointSaver || process.env.NODE_ENV === 'test') {
|
|
14
|
+
console.log('Using in-memory checkpoint saver');
|
|
15
|
+
return new langgraph_1.MemorySaver();
|
|
16
|
+
}
|
|
17
|
+
// // If not using in-memory, check for platform token and MINDED_SERVER
|
|
18
|
+
// if (!platformToken) {
|
|
19
|
+
// console.warn('No platform token provided, falling back to in-memory checkpoint saver');
|
|
20
|
+
// return new MemorySaver();
|
|
21
|
+
// }
|
|
22
|
+
const mindedServer = process.env.MINDED_SERVER;
|
|
23
|
+
if (!mindedServer) {
|
|
24
|
+
console.warn('MINDED_SERVER environment variable not set, falling back to in-memory checkpoint saver');
|
|
25
|
+
return new langgraph_1.MemorySaver();
|
|
26
|
+
}
|
|
27
|
+
console.log(`Using remote checkpoint saver with server: ${mindedServer}`);
|
|
28
|
+
return new mindedCheckpointSaver_1.MindedCheckpointSaver(platformToken);
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=checkpointSaverFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkpointSaverFactory.js","sourceRoot":"","sources":["../../src/checkpointer/checkpointSaverFactory.ts"],"names":[],"mappings":";;AAQA,sDAsBC;AA9BD,oDAAwE;AACxE,6EAA0E;AAE1E;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,aAAqB;IACzD,MAAM,wBAAwB,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,KAAK,MAAM,CAAC;IAEhF,IAAI,CAAC,wBAAwB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM,EAAE,CAAC;QACjE,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;QAChD,OAAO,IAAI,uBAAW,EAAE,CAAC;IAC3B,CAAC;IAED,0EAA0E;IAC1E,0BAA0B;IAC1B,8FAA8F;IAC9F,gCAAgC;IAChC,MAAM;IAEN,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IAC/C,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,OAAO,CAAC,IAAI,CAAC,wFAAwF,CAAC,CAAC;QACvG,OAAO,IAAI,uBAAW,EAAE,CAAC;IAC3B,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,8CAA8C,YAAY,EAAE,CAAC,CAAC;IAC1E,OAAO,IAAI,6CAAqB,CAAC,aAAa,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}) => (state: typeof stateAnnotation.State) => Promise<string>;
|
|
1
|
+
import { StepForwardEdge } from '../types/Flows.types';
|
|
2
|
+
export declare const createDirectEdge: ({ edges }: {
|
|
3
|
+
edges: StepForwardEdge[];
|
|
4
|
+
}) => () => Promise<string>;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createDirectEdge = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
4
|
+
const createDirectEdge = ({ edges }) => {
|
|
5
|
+
return async () => {
|
|
6
|
+
// For direct edges, we just return the target of the first edge
|
|
7
|
+
// since there's no conditional logic needed
|
|
8
|
+
const edge = edges[0];
|
|
10
9
|
console.log(`Executing edge ${JSON.stringify(edge)}`);
|
|
11
10
|
return edge.target;
|
|
12
11
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDirectEdge.js","sourceRoot":"","sources":["../../src/edges/createDirectEdge.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"createDirectEdge.js","sourceRoot":"","sources":["../../src/edges/createDirectEdge.ts"],"names":[],"mappings":";;;AAEO,MAAM,gBAAgB,GAAG,CAAC,EAAE,KAAK,EAAgC,EAAE,EAAE;IAC1E,OAAO,KAAK,IAAI,EAAE;QAChB,gEAAgE;QAChE,4CAA4C;QAC5C,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACtD,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC,CAAC;AACJ,CAAC,CAAC;AARW,QAAA,gBAAgB,oBAQ3B"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
edges: LogicalConditionEdge<Memory>[];
|
|
6
|
-
llm: BaseLanguageModel;
|
|
1
|
+
import { LogicalConditionEdge } from '../types/Flows.types';
|
|
2
|
+
import { stateAnnotation } from '../types/LangGraph.types';
|
|
3
|
+
export declare const createLogicalRouter: ({ edges }: {
|
|
4
|
+
edges: LogicalConditionEdge[];
|
|
7
5
|
}) => (state: typeof stateAnnotation.State) => Promise<string>;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createLogicalRouter = void 0;
|
|
4
|
-
const
|
|
5
|
-
const createLogicalRouter = ({ edges, llm }) => {
|
|
4
|
+
const createLogicalRouter = ({ edges }) => {
|
|
6
5
|
return async (state) => {
|
|
7
|
-
if (state.interruptedNode) {
|
|
8
|
-
return langgraph_1.END;
|
|
9
|
-
}
|
|
10
6
|
console.log(`Executing logical router. Edges: ${JSON.stringify(edges)}`);
|
|
11
7
|
for (const edge of edges) {
|
|
12
|
-
|
|
8
|
+
const conditionFn = eval(edge.condition);
|
|
9
|
+
const result = await conditionFn({ memory: state.memory });
|
|
10
|
+
if (result) {
|
|
13
11
|
return edge.target;
|
|
14
12
|
}
|
|
15
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createLogicalRouter.js","sourceRoot":"","sources":["../../src/edges/createLogicalRouter.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"createLogicalRouter.js","sourceRoot":"","sources":["../../src/edges/createLogicalRouter.ts"],"names":[],"mappings":";;;AAGO,MAAM,mBAAmB,GAAG,CAAC,EAAE,KAAK,EAAqC,EAAE,EAAE;IAClF,OAAO,KAAK,EAAE,KAAmC,EAAE,EAAE;QACnD,OAAO,CAAC,GAAG,CAAC,oCAAoC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACzE,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;YACzB,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACzC,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;YAC3D,IAAI,MAAM,EAAE,CAAC;gBACX,OAAO,IAAI,CAAC,MAAM,CAAC;YACrB,CAAC;QACH,CAAC;QACD,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACzB,CAAC,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,mBAAmB,uBAY9B"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PromptConditionEdge } from
|
|
2
|
-
import { BaseLanguageModel } from
|
|
3
|
-
import { stateAnnotation } from
|
|
4
|
-
export declare const createPromptRouter:
|
|
5
|
-
edges: PromptConditionEdge
|
|
1
|
+
import { PromptConditionEdge } from '../types/Flows.types';
|
|
2
|
+
import { BaseLanguageModel } from '@langchain/core/language_models/base';
|
|
3
|
+
import { stateAnnotation } from '../types/LangGraph.types';
|
|
4
|
+
export declare const createPromptRouter: ({ edges, llm }: {
|
|
5
|
+
edges: PromptConditionEdge[];
|
|
6
6
|
llm: BaseLanguageModel;
|
|
7
7
|
}) => (state: typeof stateAnnotation.State) => Promise<string>;
|
|
@@ -4,8 +4,7 @@ exports.createPromptRouter = void 0;
|
|
|
4
4
|
const prebuilt_1 = require("@langchain/langgraph/prebuilt");
|
|
5
5
|
const zod_1 = require("zod");
|
|
6
6
|
const messages_1 = require("@langchain/core/messages");
|
|
7
|
-
const
|
|
8
|
-
const createPromptRouter = ({ edges, llm, }) => {
|
|
7
|
+
const createPromptRouter = ({ edges, llm }) => {
|
|
9
8
|
const agent = (0, prebuilt_1.createReactAgent)({
|
|
10
9
|
llm,
|
|
11
10
|
tools: [],
|
|
@@ -15,19 +14,17 @@ const createPromptRouter = ({ edges, llm, }) => {
|
|
|
15
14
|
}),
|
|
16
15
|
});
|
|
17
16
|
return async (state) => {
|
|
18
|
-
if (state.interruptedNode) {
|
|
19
|
-
return langgraph_1.END;
|
|
20
|
-
}
|
|
21
17
|
console.log(`Executing prompt router. Edges: ${JSON.stringify(edges)}`);
|
|
22
18
|
const result = await agent.invoke({
|
|
23
19
|
messages: [
|
|
24
20
|
new messages_1.AIMessage({
|
|
25
21
|
content: `You are a router that decides which node to take in a flow based on the current memory state, history and available node ids.
|
|
26
22
|
|
|
27
|
-
Your task is to analyze the current memory state, history and available nodes and determine the most appropriate next node in the flow
|
|
23
|
+
Your task is to analyze the current memory state, history and available nodes and determine the most appropriate next node in the flow, the returned nodeId should be only the id without the prompt.
|
|
24
|
+
|
|
28
25
|
|
|
29
|
-
Available nodes:
|
|
30
|
-
${edges.map((edge) => `- ${edge.target}: ${edge.prompt}`).join(
|
|
26
|
+
Available nodes in the format of {nodeId}: {prompt}:
|
|
27
|
+
${edges.map((edge) => `- {${edge.target}}: {${edge.prompt}}`).join('\n')}
|
|
31
28
|
|
|
32
29
|
Current memory state:
|
|
33
30
|
${JSON.stringify(state.memory)}
|
|
@@ -42,13 +39,14 @@ Based on the memory state and available nodes, determine the most appropriate ne
|
|
|
42
39
|
});
|
|
43
40
|
try {
|
|
44
41
|
const nextNode = result.structuredResponse.nextNodeId;
|
|
42
|
+
console.log(`Next node: ${nextNode}`);
|
|
45
43
|
if (!nextNode) {
|
|
46
|
-
throw new Error(
|
|
44
|
+
throw new Error('No next node id returned from router');
|
|
47
45
|
}
|
|
48
46
|
return nextNode;
|
|
49
47
|
}
|
|
50
48
|
catch (e) {
|
|
51
|
-
throw new Error(`Failed to parse router response: ${result.structuredResponse}`);
|
|
49
|
+
throw new Error(`Failed to parse router response: ${result.structuredResponse}; Error: ${e.message}`);
|
|
52
50
|
}
|
|
53
51
|
};
|
|
54
52
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createPromptRouter.js","sourceRoot":"","sources":["../../src/edges/createPromptRouter.ts"],"names":[],"mappings":";;;AAAA,4DAAiE;AACjE,6BAAwB;AAGxB,
|
|
1
|
+
{"version":3,"file":"createPromptRouter.js","sourceRoot":"","sources":["../../src/edges/createPromptRouter.ts"],"names":[],"mappings":";;;AAAA,4DAAiE;AACjE,6BAAwB;AAGxB,uDAAqD;AAG9C,MAAM,kBAAkB,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,EAA4D,EAAE,EAAE;IAC7G,MAAM,KAAK,GAAG,IAAA,2BAAgB,EAAC;QAC7B,GAAG;QACH,KAAK,EAAE,EAAE;QACT,cAAc,EAAE,OAAC,CAAC,MAAM,CAAC;YACvB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;YACtB,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE;SACtB,CAAC;KACH,CAAC,CAAC;IACH,OAAO,KAAK,EAAE,KAAmC,EAAE,EAAE;QACnD,OAAO,CAAC,GAAG,CAAC,mCAAmC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACxE,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,CAAC;YAChC,QAAQ,EAAE;gBACR,IAAI,oBAAS,CAAC;oBACZ,OAAO,EAAE;;;;;;EAMjB,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,IAAI,CAAC,MAAM,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;EAGtE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC;;;EAG5B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,QAAQ,CAAC;;;OAGzB;iBACE,CAAC;aACH;SACF,CAAC,CAAC;QACH,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,CAAC,kBAAkB,CAAC,UAAU,CAAC;YACtD,OAAO,CAAC,GAAG,CAAC,cAAc,QAAQ,EAAE,CAAC,CAAC;YACtC,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;YAC1D,CAAC;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,oCAAoC,MAAM,CAAC,kBAAkB,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QACxG,CAAC;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AA5CW,QAAA,kBAAkB,sBA4C7B"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Edge } from
|
|
2
|
-
import { PreCompiledGraph } from
|
|
3
|
-
import { BaseLanguageModel } from
|
|
4
|
-
export declare const edgeFactory:
|
|
1
|
+
import { Edge, Node } from '../types/Flows.types';
|
|
2
|
+
import { PreCompiledGraph } from '../types/LangGraph.types';
|
|
3
|
+
import { BaseLanguageModel } from '@langchain/core/language_models/base';
|
|
4
|
+
export declare const edgeFactory: ({ graph, edges, nodes, llm, }: {
|
|
5
5
|
graph: PreCompiledGraph;
|
|
6
|
-
edges: Edge
|
|
6
|
+
edges: Edge[];
|
|
7
|
+
nodes: Record<string, Node>;
|
|
7
8
|
llm: BaseLanguageModel;
|
|
8
9
|
}) => void;
|
|
@@ -5,25 +5,61 @@ const Flows_types_1 = require("../types/Flows.types");
|
|
|
5
5
|
const createPromptRouter_1 = require("./createPromptRouter");
|
|
6
6
|
const createLogicalRouter_1 = require("./createLogicalRouter");
|
|
7
7
|
const createDirectEdge_1 = require("./createDirectEdge");
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
8
|
+
const addHumanInTheLoopNode_1 = require("../nodes/addHumanInTheLoopNode");
|
|
9
|
+
const edgeFactory = ({ graph, edges, nodes, llm, }) => {
|
|
10
|
+
/**
|
|
11
|
+
* Processes edges with enhanced node capabilities (humanInTheLoop, canStayOnNode)
|
|
12
|
+
* This elegant abstraction handles both prompt and logical edges uniformly
|
|
13
|
+
*/
|
|
14
|
+
const processEdges = (edgeProcessor) => {
|
|
15
|
+
const { edges: filteredEdges, router } = edgeProcessor;
|
|
16
|
+
const uniqueSources = [...new Set(filteredEdges.map((edge) => edge.source))];
|
|
17
|
+
uniqueSources.forEach((source) => {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
const edgesForSource = [...filteredEdges.filter((edge) => edge.source === source)];
|
|
20
|
+
let effectiveSource = source;
|
|
21
|
+
// Handle human-in-the-loop enhancement
|
|
22
|
+
if ((_a = nodes[source]) === null || _a === void 0 ? void 0 : _a.humanInTheLoop) {
|
|
23
|
+
(0, addHumanInTheLoopNode_1.addHumanInTheLoopNode)({ graph, attachedToNodeName: source });
|
|
24
|
+
effectiveSource = (0, addHumanInTheLoopNode_1.buildHumanInTheLoopNodeName)(source);
|
|
25
|
+
}
|
|
26
|
+
// Handle stay-on-node capability
|
|
27
|
+
if ((_b = nodes[source]) === null || _b === void 0 ? void 0 : _b.canStayOnNode) {
|
|
28
|
+
const stayEdge = {
|
|
29
|
+
source,
|
|
30
|
+
target: source,
|
|
31
|
+
type: Flows_types_1.EdgeType.PROMPT_CONDITION,
|
|
32
|
+
prompt: 'stay at current node if still relevant',
|
|
33
|
+
};
|
|
34
|
+
edgesForSource.push(stayEdge);
|
|
35
|
+
}
|
|
36
|
+
graph.addConditionalEdges(effectiveSource, router({ edges: edgesForSource, llm }));
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
// Direct edges - simple and straightforward
|
|
40
|
+
const directEdges = edges.filter((edge) => edge.type === Flows_types_1.EdgeType.STEP_FORWARD);
|
|
41
|
+
if (directEdges.length > 0) {
|
|
42
|
+
processEdges({
|
|
43
|
+
edges: directEdges,
|
|
44
|
+
router: createDirectEdge_1.createDirectEdge,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
// Prompt condition edges - enhanced with AI-driven routing
|
|
48
|
+
const promptEdges = edges.filter((edge) => edge.type === Flows_types_1.EdgeType.PROMPT_CONDITION);
|
|
49
|
+
if (promptEdges.length > 0) {
|
|
50
|
+
processEdges({
|
|
51
|
+
edges: promptEdges,
|
|
52
|
+
router: createPromptRouter_1.createPromptRouter,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// Logical condition edges - enhanced with programmatic routing
|
|
56
|
+
const logicalEdges = edges.filter((edge) => edge.type === Flows_types_1.EdgeType.LOGICAL_CONDITION);
|
|
57
|
+
if (logicalEdges.length > 0) {
|
|
58
|
+
processEdges({
|
|
59
|
+
edges: logicalEdges,
|
|
60
|
+
router: createLogicalRouter_1.createLogicalRouter,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
27
63
|
};
|
|
28
64
|
exports.edgeFactory = edgeFactory;
|
|
29
65
|
//# sourceMappingURL=edgeFactory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edgeFactory.js","sourceRoot":"","sources":["../../src/edges/edgeFactory.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"edgeFactory.js","sourceRoot":"","sources":["../../src/edges/edgeFactory.ts"],"names":[],"mappings":";;;AAAA,sDAAwH;AAGxH,6DAA0D;AAC1D,+DAA4D;AAC5D,yDAAsD;AACtD,0EAAoG;AAO7F,MAAM,WAAW,GAAG,CAAC,EAC1B,KAAK,EACL,KAAK,EACL,KAAK,EACL,GAAG,GAMJ,EAAE,EAAE;IACH;;;OAGG;IACH,MAAM,YAAY,GAAG,CAAiB,aAA+B,EAAQ,EAAE;QAC7E,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,a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;IACrG,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,YAAY,CAAC;YACX,KAAK,EAAE,WAAW;YAClB,MAAM,EAAE,mCAAgB;SACzB,CAAC,CAAC;IACL,CAAC;IAED,2DAA2D;IAC3D,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,sBAAQ,CAAC,gBAAgB,CAA0B,CAAC;IAC7G,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC3B,YAAY,CAAC;YACX,KAAK,EAAE,WAAW;YAClB,MAAM,EAAE,uCAAkB;SAC3B,CAAC,CAAC;IACL,CAAC;IAED,+DAA+D;IAC/D,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,sBAAQ,CAAC,iBAAiB,CAA2B,CAAC;IAChH,IAAI,YAAY,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC5B,YAAY,CAAC;YACX,KAAK,EAAE,YAAY;YACnB,MAAM,EAAE,yCAAmB;SAC5B,CAAC,CAAC;IACL,CAAC;AACH,CAAC,CAAC;AAvEW,QAAA,WAAW,eAuEtB"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { BaseMessage } from "@langchain/core/messages";
|
|
1
|
+
import { BaseMessage } from '@langchain/core/messages';
|
|
3
2
|
export declare enum AgentEvents {
|
|
4
3
|
AI_MESSAGE = "AI_MESSAGE",
|
|
5
4
|
TRIGGER_EVENT = "TRIGGER_EVENT"
|
|
@@ -11,7 +10,7 @@ export type AgentEventRequestPayloads<Memory> = {
|
|
|
11
10
|
};
|
|
12
11
|
[AgentEvents.TRIGGER_EVENT]: {
|
|
13
12
|
triggerName: string;
|
|
14
|
-
triggerBody:
|
|
13
|
+
triggerBody: any;
|
|
15
14
|
};
|
|
16
15
|
};
|
|
17
16
|
export type AgentEventResponsePayloads<Memory> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentEvents.js","sourceRoot":"","sources":["../../src/events/AgentEvents.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"AgentEvents.js","sourceRoot":"","sources":["../../src/events/AgentEvents.ts"],"names":[],"mappings":";;;AAEA,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,wCAAyB,CAAA;IACzB,8CAA+B,CAAA;AACjC,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB"}
|
package/dist/events/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { AgentEvents } from
|
|
1
|
+
import { AgentEvents } from './AgentEvents';
|
|
2
2
|
export default AgentEvents;
|