@minded-ai/mindedjs 1.0.35 → 1.0.37

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.
Files changed (78) hide show
  1. package/dist/agent.d.ts.map +1 -1
  2. package/dist/agent.js +20 -10
  3. package/dist/agent.js.map +1 -1
  4. package/dist/analytics.d.ts +6 -0
  5. package/dist/analytics.js +19 -0
  6. package/dist/analytics.js.map +1 -0
  7. package/dist/cli/index.js +28 -6
  8. package/dist/cli/index.js.map +1 -1
  9. package/dist/edges/edgeFactory.d.ts +3 -1
  10. package/dist/edges/edgeFactory.d.ts.map +1 -1
  11. package/dist/edges/edgeFactory.js +8 -3
  12. package/dist/edges/edgeFactory.js.map +1 -1
  13. package/dist/infrastructure.ts/mindedRequest.d.ts +8 -0
  14. package/dist/infrastructure.ts/mindedRequest.js +22 -0
  15. package/dist/infrastructure.ts/mindedRequest.js.map +1 -0
  16. package/dist/nodes/addToolNode.d.ts +1 -1
  17. package/dist/nodes/addToolNode.d.ts.map +1 -1
  18. package/dist/nodes/addToolNode.js +6 -24
  19. package/dist/nodes/addToolNode.js.map +1 -1
  20. package/dist/nodes/addToolRunNode.d.ts +15 -0
  21. package/dist/nodes/addToolRunNode.d.ts.map +1 -0
  22. package/dist/nodes/addToolRunNode.js +44 -0
  23. package/dist/nodes/addToolRunNode.js.map +1 -0
  24. package/dist/platform/{mindedChatOpenAI.js → MindedChatOpenAI.js} +3 -0
  25. package/dist/platform/MindedChatOpenAI.js.map +1 -0
  26. package/dist/platform/config.d.ts +1 -1
  27. package/dist/platform/config.d.ts.map +1 -1
  28. package/dist/platform/config.js +3 -0
  29. package/dist/platform/config.js.map +1 -1
  30. package/dist/platform/mindedChatOpenAI.d.ts.map +1 -1
  31. package/dist/platform/mindedConnection.d.ts +0 -7
  32. package/dist/platform/mindedConnection.d.ts.map +1 -1
  33. package/dist/platform/mindedConnection.js +5 -93
  34. package/dist/platform/mindedConnection.js.map +1 -1
  35. package/dist/types/Triggers.types.d.ts +1 -0
  36. package/dist/types/Triggers.types.js +3 -0
  37. package/dist/types/Triggers.types.js.map +1 -0
  38. package/package.json +2 -2
  39. package/src/agent.ts +24 -13
  40. package/src/cli/index.ts +31 -6
  41. package/src/edges/edgeFactory.ts +10 -1
  42. package/src/nodes/addToolNode.ts +9 -24
  43. package/src/nodes/addToolRunNode.ts +54 -0
  44. package/src/platform/config.ts +5 -1
  45. package/src/platform/mindedChatOpenAI.ts +3 -0
  46. package/src/platform/mindedConnection.ts +5 -68
  47. package/dist/internalTools/utils.d.ts +0 -2
  48. package/dist/internalTools/utils.d.ts.map +0 -1
  49. package/dist/internalTools/utils.js +0 -8
  50. package/dist/internalTools/utils.js.map +0 -1
  51. package/dist/nodes/actionRunnerNode.d.ts +0 -14
  52. package/dist/nodes/actionRunnerNode.d.ts.map +0 -1
  53. package/dist/nodes/actionRunnerNode.js +0 -100
  54. package/dist/nodes/actionRunnerNode.js.map +0 -1
  55. package/dist/nodes/actionRunnerTool.d.ts +0 -14
  56. package/dist/nodes/actionRunnerTool.d.ts.map +0 -1
  57. package/dist/nodes/actionRunnerTool.js +0 -101
  58. package/dist/nodes/actionRunnerTool.js.map +0 -1
  59. package/dist/nodes/addAppTool.d.ts +0 -8
  60. package/dist/nodes/addAppTool.js +0 -12
  61. package/dist/nodes/addAppTool.js.map +0 -1
  62. package/dist/nodes/callTool.d.ts +0 -10
  63. package/dist/nodes/callTool.js +0 -57
  64. package/dist/nodes/callTool.js.map +0 -1
  65. package/dist/nodes/toolNodeRunner.d.ts +0 -15
  66. package/dist/nodes/toolNodeRunner.js +0 -79
  67. package/dist/nodes/toolNodeRunner.js.map +0 -1
  68. package/dist/platform/mindedChatOpenAI.js.map +0 -1
  69. package/dist/tools/appToolRunner.d.ts +0 -30
  70. package/dist/tools/appToolRunner.js +0 -35
  71. package/dist/tools/appToolRunner.js.map +0 -1
  72. package/dist/tools/parser.d.ts +0 -14
  73. package/dist/tools/parser.js +0 -17
  74. package/dist/tools/parser.js.map +0 -1
  75. package/dist/tools/triggerTypeToDefaultMessage.d.ts +0 -3
  76. package/dist/tools/triggerTypeToDefaultMessage.js +0 -10
  77. package/dist/tools/triggerTypeToDefaultMessage.js.map +0 -1
  78. /package/dist/platform/{mindedChatOpenAI.d.ts → MindedChatOpenAI.d.ts} +0 -0
@@ -1,50 +1,12 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  Object.defineProperty(exports, "__esModule", { value: true });
36
3
  exports.MindedConnection = void 0;
37
4
  const socket_io_client_1 = require("socket.io-client");
38
- const readline = __importStar(require("readline"));
39
- const fs = __importStar(require("fs"));
40
- const path = __importStar(require("path"));
41
5
  const flatted_1 = require("flatted");
42
6
  const config_1 = require("./config");
43
7
  class MindedConnection {
44
8
  constructor() {
45
9
  this.socket = null;
46
- this.rl = null;
47
- this.tokenPath = path.join(process.cwd(), '.minded-token');
48
10
  this.listeners = {};
49
11
  this.on = (event, callback) => {
50
12
  if (!this.listeners[event]) {
@@ -80,54 +42,6 @@ class MindedConnection {
80
42
  });
81
43
  });
82
44
  };
83
- if (!(0, config_1.getConfig)().token && !this.getSavedToken()) {
84
- this.initializeReadline();
85
- }
86
- }
87
- initializeReadline() {
88
- this.rl = readline.createInterface({
89
- input: process.stdin,
90
- output: process.stdout,
91
- });
92
- }
93
- getSavedToken() {
94
- try {
95
- if (fs.existsSync(this.tokenPath)) {
96
- return fs.readFileSync(this.tokenPath, 'utf8').trim();
97
- }
98
- }
99
- catch (error) {
100
- console.error('Error reading token file:', error);
101
- }
102
- return null;
103
- }
104
- saveToken(token) {
105
- try {
106
- fs.writeFileSync(this.tokenPath, token);
107
- }
108
- catch (error) {
109
- console.error('Error saving token:', error);
110
- }
111
- }
112
- async getMindedToken() {
113
- const envToken = (0, config_1.getConfig)().token;
114
- if (envToken) {
115
- this.saveToken(envToken);
116
- return envToken;
117
- }
118
- const savedToken = this.getSavedToken();
119
- if (savedToken) {
120
- return savedToken;
121
- }
122
- if (!this.rl) {
123
- this.initializeReadline();
124
- }
125
- return new Promise((resolve) => {
126
- this.rl.question('Enter your Minded connection token: ', (token) => {
127
- this.saveToken(token.trim());
128
- resolve(token.trim());
129
- });
130
- });
131
45
  }
132
46
  async waitForConnection() {
133
47
  return new Promise((resolve, reject) => {
@@ -173,17 +87,12 @@ class MindedConnection {
173
87
  console.error('Server error:', error.message);
174
88
  if (error.message.includes('Invalid token')) {
175
89
  console.log('Invalid token');
176
- // Delete saved token on connection error
177
- if (fs.existsSync(this.tokenPath)) {
178
- fs.unlinkSync(this.tokenPath);
179
- }
180
90
  // Disconnect current socket
181
91
  if ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.connected) {
182
92
  this.socket.disconnect();
183
93
  }
184
94
  // Get new token and reconnect
185
- const newToken = await this.getMindedToken();
186
- await this.connect(newToken);
95
+ await this.connect(token);
187
96
  }
188
97
  });
189
98
  // Listen for specific message types
@@ -205,7 +114,10 @@ class MindedConnection {
205
114
  });
206
115
  }
207
116
  async start() {
208
- const token = await this.getMindedToken();
117
+ const { token } = (0, config_1.getConfig)();
118
+ if (!token) {
119
+ throw new Error('Minded token not found');
120
+ }
209
121
  await this.connect(token);
210
122
  }
211
123
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mindedConnection.js","sourceRoot":"","sources":["../../src/platform/mindedConnection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAA8C;AAC9C,mDAAqC;AAErC,uCAAyB;AACzB,2CAA6B;AAC7B,qCAAoC;AACpC,qCAAqC;AAErC,MAAa,gBAAgB;IAQ3B;QAPQ,WAAM,GAAkB,IAAI,CAAC;QAC7B,OAAE,GAA8B,IAAI,CAAC;QAC5B,cAAS,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,eAAe,CAAC,CAAC;QACvE,cAAS,GAEL,EAAE,CAAC;QA+EA,OAAE,GAAG,CAAC,KAAwC,EAAE,QAA8D,EAAE,EAAE;YACvH,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3B,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;YAC7B,CAAC;YACD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvC,CAAC,CAAC;QAEK,SAAI,GAAG,CAAC,KAAwC,EAAE,OAA0C,EAAE,EAAE;YACrG,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;gBAChB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YACnC,CAAC;QACH,CAAC,CAAC;QAEK,cAAS,GAAG,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AK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAC5C,CAAC;QACD,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC5B,CAAC;CACF;AApID,4CAoIC"}
@@ -0,0 +1 @@
1
+ export type TriggerBody = any;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Triggers.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Triggers.types.js","sourceRoot":"","sources":["../../src/types/Triggers.types.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minded-ai/mindedjs",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "description": "MindedJS is a TypeScript library for building agents.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -53,4 +53,4 @@
53
53
  "uuid": "^11.1.0",
54
54
  "zod": "^3.24.4"
55
55
  }
56
- }
56
+ }
package/src/agent.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Flow, NodeType, Node, KnownTriggerNames } from './types/Flows.types';
1
+ import { Flow, NodeType, Node, EdgeType, KnownTriggerNames } from './types/Flows.types';
2
+
2
3
  import { Tool } from './types/Tools.types';
3
4
  import { v4 as uuidv4 } from 'uuid';
4
5
  import { BaseLanguageModel } from '@langchain/core/language_models/base';
@@ -16,16 +17,12 @@ import * as path from 'path';
16
17
  import * as yaml from 'js-yaml';
17
18
  import { FlowHistoryType, MindedSDKConfig, TriggerInvocationHistory } from './types/Agent.types';
18
19
  import { createLlmInstance } from './llm/createLlmInstance';
19
- import { config } from 'dotenv';
20
- import { resolve } from 'path';
21
20
  import { createCheckpointSaver } from './checkpointer/checkpointSaverFactory';
22
21
  import { getConfig } from './platform/config';
23
22
  import { BaseMessage, HumanMessage } from '@langchain/core/messages';
24
23
  import triggerTypeToDefaultMessage from './triggers/triggerTypeToDefaultMessage';
25
24
  import appActionRunnerToolCreator from './internalTools/appActionRunnerTool';
26
25
 
27
- config({ path: resolve(__dirname, '../.env') });
28
-
29
26
  type CreateAgentParams<Memory> = {
30
27
  memorySchema: z.ZodSchema;
31
28
  config: MindedSDKConfig;
@@ -58,15 +55,13 @@ export class Agent {
58
55
  const { config, tools, platformToken, memorySaver, memorySchema } = params;
59
56
  this.memorySchema = memorySchema;
60
57
  this.flows = this.loadFlowsFromDirectory(config.flows);
61
- const appActionsRunnerTools = this.initAppActionsRunnerTools();
62
- this.tools = [...tools, ...appActionsRunnerTools];
63
58
  this.platformToken = platformToken;
64
59
  this.llm = createLlmInstance(config.llm);
65
60
  this.validate();
66
61
 
67
- const { runLocally, token } = getConfig();
62
+ const { runLocally } = getConfig();
68
63
 
69
- if (token && !runLocally) {
64
+ if (!runLocally) {
70
65
  this.mindedConnection = new MindedConnection();
71
66
  this.mindedConnection.start();
72
67
  this.mindedConnection.on(MindedConnectionSocketMessageType.OnAppTrigger, async (message: BaseMindedConnectionSocketMessage) => {
@@ -74,6 +69,8 @@ export class Agent {
74
69
  await this.invoke({ triggerBody: trigger.body, triggerName: trigger.name, appName: trigger.appName, sessionId: trigger.cnvId });
75
70
  });
76
71
  }
72
+ const appActionsRunnerTools = this.initAppActionsRunnerTools();
73
+ this.tools = [...tools, ...appActionsRunnerTools];
77
74
  this.checkpointer = memorySaver || createCheckpointSaver(this.mindedConnection);
78
75
  this.compiledGraph = this.initializeGraph();
79
76
  }
@@ -141,9 +138,6 @@ export class Agent {
141
138
  });
142
139
  });
143
140
 
144
- // Add edges
145
- edgeFactory({ graph, edges, nodes: nodesObject, llm: this.llm });
146
-
147
141
  // Add edge from start to first node if no triggers exist
148
142
  const hasTrigger = nodes.some((node) => node.type === NodeType.TRIGGER);
149
143
  if (!hasTrigger && nodes.length > 0) {
@@ -156,6 +150,21 @@ export class Agent {
156
150
  });
157
151
  }
158
152
 
153
+ // Add edges to __end__ for nodes with no outgoing edges
154
+ const nodeNames = nodes.map((node) => node.name);
155
+ const sourceNodes = new Set(edges.map((edge) => edge.source));
156
+ const lastNodes = nodeNames.filter((nodeName) => !sourceNodes.has(nodeName));
157
+ lastNodes.forEach((nodeName) => {
158
+ edges.push({
159
+ source: nodeName,
160
+ target: '__end__',
161
+ type: EdgeType.STEP_FORWARD,
162
+ });
163
+ });
164
+
165
+ // Add edges
166
+ edgeFactory({ graph, edges, nodes: nodesObject, tools: this.tools, llm: this.llm });
167
+
159
168
  // Compile the graph
160
169
  return graph.compile({ checkpointer: this.checkpointer }) as CompiledGraph;
161
170
  }
@@ -255,7 +264,9 @@ export class Agent {
255
264
  if (!this.mindedConnection && process.env.NODE_ENV !== 'test') {
256
265
  throw new Error('Minded connection is mandatory to use run app action tools');
257
266
  }
258
- return this.flows.flatMap((flow) => flow.nodes.filter((node) => node.type === NodeType.APP_TOOL)).map((node) => appActionRunnerToolCreator(node.metadata.schema, node.name, this.mindedConnection as MindedConnection));
267
+ return this.flows
268
+ .flatMap((flow) => flow.nodes.filter((node) => node.type === NodeType.APP_TOOL))
269
+ .map((node) => appActionRunnerToolCreator(node.metadata.schema, node.name, this.mindedConnection as MindedConnection));
259
270
  }
260
271
 
261
272
  // Public method to get secrets from the backend service with caching
package/src/cli/index.ts CHANGED
@@ -3,16 +3,41 @@
3
3
  import * as fs from 'fs';
4
4
  import * as path from 'path';
5
5
 
6
- const TOKEN_FILE = '.minded-token';
6
+ const ENV_FILE = '.env';
7
7
 
8
- function getTokenFilePath(): string {
9
- return path.join(process.cwd(), TOKEN_FILE);
8
+ function getEnvFilePath(): string {
9
+ return path.join(process.cwd(), ENV_FILE);
10
10
  }
11
11
 
12
12
  function setToken(token: string): void {
13
- const tokenPath = getTokenFilePath();
14
- fs.writeFileSync(tokenPath, token);
15
- console.log(`Token saved to ${tokenPath}`);
13
+ const envPath = getEnvFilePath();
14
+ const tokenLine = `MINDED_CONNECTION_TOKEN=${token}`;
15
+
16
+ // Check if .env file exists
17
+ if (!fs.existsSync(envPath)) {
18
+ // Create .env file with the token
19
+ fs.writeFileSync(envPath, tokenLine + '\n');
20
+ console.log(`Created ${envPath} and added token`);
21
+ } else {
22
+ // Read existing .env file
23
+ const envContent = fs.readFileSync(envPath, 'utf8');
24
+
25
+ // Check if MINDED_CONNECTION_TOKEN already exists
26
+ if (envContent.includes('MINDED_CONNECTION_TOKEN=')) {
27
+ // Replace existing token
28
+ const updatedContent = envContent.replace(
29
+ /MINDED_CONNECTION_TOKEN=.*/,
30
+ tokenLine
31
+ );
32
+ fs.writeFileSync(envPath, updatedContent);
33
+ console.log(`Updated MINDED_CONNECTION_TOKEN in ${envPath}`);
34
+ } else {
35
+ // Append token to existing file
36
+ const newContent = envContent.endsWith('\n') ? envContent + tokenLine + '\n' : envContent + '\n' + tokenLine + '\n';
37
+ fs.writeFileSync(envPath, newContent);
38
+ console.log(`Added MINDED_CONNECTION_TOKEN to ${envPath}`);
39
+ }
40
+ }
16
41
  }
17
42
 
18
43
  function main() {
@@ -1,10 +1,12 @@
1
- import { Edge, EdgeType, Node, PromptConditionEdge, LogicalConditionEdge, StepForwardEdge } from '../types/Flows.types';
1
+ import { Edge, EdgeType, Node, PromptConditionEdge, LogicalConditionEdge, StepForwardEdge, NodeType, ToolNode } from '../types/Flows.types';
2
2
  import { PreCompiledGraph } from '../types/LangGraph.types';
3
3
  import { BaseLanguageModel } from '@langchain/core/language_models/base';
4
4
  import { createPromptRouter } from './createPromptRouter';
5
5
  import { createLogicalRouter } from './createLogicalRouter';
6
6
  import { createDirectEdge } from './createDirectEdge';
7
7
  import { addHumanInTheLoopNode, buildHumanInTheLoopNodeName } from '../nodes/addHumanInTheLoopNode';
8
+ import { addToolRunNode, buildToolRunNodeName } from '../nodes/addToolRunNode';
9
+ import { Tool } from '../types/Tools.types';
8
10
 
9
11
  type EdgesBySource = {
10
12
  stepForward?: StepForwardEdge;
@@ -16,11 +18,13 @@ export const edgeFactory = ({
16
18
  graph,
17
19
  edges,
18
20
  nodes,
21
+ tools,
19
22
  llm,
20
23
  }: {
21
24
  graph: PreCompiledGraph;
22
25
  edges: Edge[];
23
26
  nodes: Record<string, Node>;
27
+ tools: Tool<any, any>[];
24
28
  llm: BaseLanguageModel;
25
29
  }) => {
26
30
  /**
@@ -66,6 +70,11 @@ export const edgeFactory = ({
66
70
  effectiveSource = buildHumanInTheLoopNodeName(source);
67
71
  }
68
72
 
73
+ if (nodes[source]?.type === NodeType.TOOL) {
74
+ addToolRunNode({ graph, tools, llm, toolNode: nodes[source] as ToolNode, attachedToNodeName: source });
75
+ effectiveSource = buildToolRunNodeName(source);
76
+ }
77
+
69
78
  // Handle stay-on-node capability
70
79
  if (nodes[source]?.canStayOnNode) {
71
80
  const stayEdge: PromptConditionEdge = {
@@ -2,13 +2,11 @@ import { ToolNode } from '../types/Flows.types';
2
2
  import { Tool } from '../types/Tools.types';
3
3
  import { tool as langchainTool } from '@langchain/core/tools';
4
4
  import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
5
- import { SystemMessage, ToolMessage } from '@langchain/core/messages';
5
+ import { SystemMessage } from '@langchain/core/messages';
6
6
  import { RunnableLike } from '@langchain/core/runnables';
7
- import { z } from 'zod';
8
7
  import { LLMProviders } from '../types/LLM.types';
9
- import extractToolMemoryResponse from '../utils/extractToolMemoryResponse';
10
8
 
11
- export const addToolNode = async <Memory>({
9
+ export const addToolNode = async ({
12
10
  graph,
13
11
  node,
14
12
  tools,
@@ -27,16 +25,7 @@ export const addToolNode = async <Memory>({
27
25
  const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
28
26
  console.log(`Executing tool node ${toolNode.name}`);
29
27
 
30
- const executeWrapper = async (input: z.infer<typeof matchedTool.input>) => {
31
- try {
32
- const response = await matchedTool.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
33
- return response || {};
34
- } catch (error) {
35
- console.error('Error executing tool', error);
36
- throw error;
37
- }
38
- };
39
- const tool = langchainTool(executeWrapper, {
28
+ const tool = langchainTool(() => {}, {
40
29
  name: matchedTool.name,
41
30
  description: matchedTool.description,
42
31
  schema: matchedTool.input,
@@ -45,16 +34,12 @@ export const addToolNode = async <Memory>({
45
34
  Additional context:
46
35
  workflow memory: ${JSON.stringify(state.memory)}
47
36
  `;
48
- const messages = state.messages || [];
49
- if (Object.keys(state.memory).length !== 0) {
50
- messages.push(new SystemMessage(prompt));
51
- }
52
- const AIToolCallMessage = await llm.bindTools([tool], {
53
- tool_choice: tool.name,
54
- }).invoke(messages);
55
- const toolCallMessage = await tool.invoke(AIToolCallMessage.tool_calls[0])
56
- const toolMemory = extractToolMemoryResponse<Memory>(toolCallMessage as ToolMessage);
57
- return { memory: toolMemory, messages: [AIToolCallMessage, toolCallMessage] };
37
+ const AIToolCallMessage = await llm
38
+ .bindTools([tool], {
39
+ tool_choice: tool.name,
40
+ })
41
+ .invoke([...state.messages, new SystemMessage(prompt)]);
42
+ return { messages: [AIToolCallMessage] };
58
43
  };
59
44
  graph.addNode(node.name, callback);
60
45
  };
@@ -0,0 +1,54 @@
1
+ import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
2
+ import { RunnableLike } from '@langchain/core/runnables';
3
+ import { Tool } from '../types/Tools.types';
4
+ import { LLMProviders } from '../types/LLM.types';
5
+ import { ToolNode } from '../types/Flows.types';
6
+ import { tool as langchainTool } from '@langchain/core/tools';
7
+ import { ToolMessage } from '@langchain/core/messages';
8
+ import { z } from 'zod';
9
+ import extractToolMemoryResponse from '../utils/extractToolMemoryResponse';
10
+
11
+ type AddToolRunNodeParams = {
12
+ graph: PreCompiledGraph;
13
+ tools: Tool<any, any>[];
14
+ llm: (typeof LLMProviders)[keyof typeof LLMProviders];
15
+ toolNode: ToolNode;
16
+ attachedToNodeName: string;
17
+ };
18
+
19
+ export const buildToolRunNodeName = (nodeName: string) => `${nodeName}_toolRun`;
20
+
21
+ export const addToolRunNode = async ({ graph, tools, toolNode, attachedToNodeName }: AddToolRunNodeParams) => {
22
+ const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
23
+ const matchedTool = tools.find((tool) => tool.name === toolNode.toolName);
24
+ if (!matchedTool) {
25
+ throw new Error(`Tool not found: ${toolNode.toolName}`);
26
+ }
27
+
28
+ const executeWrapper = async (input: z.infer<typeof matchedTool.input>) => {
29
+ try {
30
+ const response = await matchedTool.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
31
+ return response || {};
32
+ } catch (error) {
33
+ console.error('Error executing tool', error);
34
+ throw error;
35
+ }
36
+ };
37
+ const tool = langchainTool(executeWrapper, {
38
+ name: matchedTool.name,
39
+ description: matchedTool.description,
40
+ schema: matchedTool.input,
41
+ });
42
+
43
+ const toolCallObj = state.messages[state.messages.length - 1] as any;
44
+ if (!toolCallObj.tool_calls) {
45
+ throw new Error('Tool call not found');
46
+ }
47
+ const toolCallMessage = await tool.invoke(toolCallObj.tool_calls[0]);
48
+ const toolMemory = extractToolMemoryResponse(toolCallMessage as ToolMessage);
49
+ return { memory: toolMemory, messages: [toolCallMessage] };
50
+ };
51
+
52
+ graph.addNode(buildToolRunNodeName(attachedToNodeName), callback);
53
+ graph.addEdge(attachedToNodeName as any, buildToolRunNodeName(attachedToNodeName) as any);
54
+ };
@@ -1,7 +1,11 @@
1
+ import { resolve } from 'path';
2
+ import { config } from 'dotenv';
3
+ config({ path: resolve(__dirname, '../.env') });
4
+
1
5
  type MindedConfig = {
2
6
  baseUrl: string;
3
7
  env: Environment;
4
- token: string;
8
+ token: string | null;
5
9
  runLocally: boolean;
6
10
  };
7
11
 
@@ -5,6 +5,9 @@ export class MindedChatOpenAI extends ChatOpenAI {
5
5
  constructor(fields?: ChatOpenAIFields) {
6
6
  const { token, baseUrl } = getConfig();
7
7
  const mindedBaseUrl = `${baseUrl}/sdk/llmGateway/chatOpenAI`;
8
+ if (!token) {
9
+ throw new Error('Minded token not found');
10
+ }
8
11
  super({
9
12
  ...fields,
10
13
  apiKey: token,
@@ -1,75 +1,14 @@
1
1
  import { io, Socket } from 'socket.io-client';
2
- import * as readline from 'readline';
3
2
  import { BaseMindedConnectionSocketMessage, MindedConnectionSocketMessageType } from './mindedConnectionTypes';
4
- import * as fs from 'fs';
5
- import * as path from 'path';
6
3
  import { stringify } from 'flatted';
7
4
  import { getConfig } from './config';
8
5
 
9
6
  export class MindedConnection {
10
7
  private socket: Socket | null = null;
11
- private rl: readline.Interface | null = null;
12
- private readonly tokenPath = path.join(process.cwd(), '.minded-token');
13
8
  listeners: {
14
9
  [key: string]: ((message: BaseMindedConnectionSocketMessage) => void)[];
15
10
  } = {};
16
11
 
17
- constructor() {
18
- if (!getConfig().token && !this.getSavedToken()) {
19
- this.initializeReadline();
20
- }
21
- }
22
-
23
- private initializeReadline() {
24
- this.rl = readline.createInterface({
25
- input: process.stdin,
26
- output: process.stdout,
27
- });
28
- }
29
-
30
- private getSavedToken(): string | null {
31
- try {
32
- if (fs.existsSync(this.tokenPath)) {
33
- return fs.readFileSync(this.tokenPath, 'utf8').trim();
34
- }
35
- } catch (error) {
36
- console.error('Error reading token file:', error);
37
- }
38
- return null;
39
- }
40
-
41
- private saveToken(token: string): void {
42
- try {
43
- fs.writeFileSync(this.tokenPath, token);
44
- } catch (error) {
45
- console.error('Error saving token:', error);
46
- }
47
- }
48
-
49
- private async getMindedToken(): Promise<string> {
50
- const envToken = getConfig().token;
51
- if (envToken) {
52
- this.saveToken(envToken);
53
- return envToken;
54
- }
55
-
56
- const savedToken = this.getSavedToken();
57
- if (savedToken) {
58
- return savedToken;
59
- }
60
-
61
- if (!this.rl) {
62
- this.initializeReadline();
63
- }
64
-
65
- return new Promise((resolve) => {
66
- this.rl!.question('Enter your Minded connection token: ', (token: string) => {
67
- this.saveToken(token.trim());
68
- resolve(token.trim());
69
- });
70
- });
71
- }
72
-
73
12
  private async waitForConnection(): Promise<void> {
74
13
  return new Promise((resolve, reject) => {
75
14
  let attempts = 0;
@@ -159,10 +98,6 @@ export class MindedConnection {
159
98
 
160
99
  if (error.message.includes('Invalid token')) {
161
100
  console.log('Invalid token');
162
- // Delete saved token on connection error
163
- if (fs.existsSync(this.tokenPath)) {
164
- fs.unlinkSync(this.tokenPath);
165
- }
166
101
 
167
102
  // Disconnect current socket
168
103
  if (this.socket?.connected) {
@@ -170,8 +105,7 @@ export class MindedConnection {
170
105
  }
171
106
 
172
107
  // Get new token and reconnect
173
- const newToken = await this.getMindedToken();
174
- await this.connect(newToken);
108
+ await this.connect(token);
175
109
  }
176
110
  });
177
111
 
@@ -195,7 +129,10 @@ export class MindedConnection {
195
129
  }
196
130
 
197
131
  public async start(): Promise<void> {
198
- const token = await this.getMindedToken();
132
+ const { token } = getConfig();
133
+ if (!token) {
134
+ throw new Error('Minded token not found');
135
+ }
199
136
  await this.connect(token);
200
137
  }
201
138
  }
@@ -1,2 +0,0 @@
1
- export declare const sanitizeName: (name: string) => string;
2
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/internalTools/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,KAAG,MAE3C,CAAC"}
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sanitizeName = void 0;
4
- const sanitizeName = (name) => {
5
- return name.replace(/[^a-zA-Z0-9_-]/g, '-');
6
- };
7
- exports.sanitizeName = sanitizeName;
8
- //# sourceMappingURL=utils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/internalTools/utils.ts"],"names":[],"mappings":";;;AAAO,MAAM,YAAY,GAAG,CAAC,IAAY,EAAU,EAAE;IACjD,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,CAAC;AAChD,CAAC,CAAC;AAFW,QAAA,YAAY,gBAEvB"}
@@ -1,14 +0,0 @@
1
- import { AppToolNode, ToolNode } from "../types/Flows.types";
2
- import { stateAnnotation } from "../types/LangGraph.types";
3
- import { Tool } from "../types/Tools.types";
4
- import { BaseLanguageModel } from "@langchain/core/language_models/base";
5
- import { BaseMessage, ToolMessage } from "@langchain/core/messages";
6
- import { FlowHistory } from "../types/Agent.types";
7
- declare const actionRunnerTool: <Memory>(matchedTool: Tool<any, Memory>, toolNode: ToolNode | AppToolNode, llm: BaseLanguageModel, addedPrompt?: string, history?: FlowHistory[]) => (state: typeof stateAnnotation.State) => Promise<{
8
- memory: {};
9
- messages: (BaseMessage | ToolMessage)[];
10
- triggerInvocations: import("../types/Agent.types").TriggerInvocationHistory[];
11
- history: FlowHistory[];
12
- }>;
13
- export default actionRunnerTool;
14
- //# sourceMappingURL=actionRunnerNode.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"actionRunnerNode.d.ts","sourceRoot":"","sources":["../../src/nodes/actionRunnerNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAY,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAIzE,OAAO,EAAa,WAAW,EAAiB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAG9F,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD,QAAA,MAAM,gBAAgB,GAAI,MAAM,EAAE,aAAa,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,UAAU,QAAQ,GAAG,WAAW,EAAE,KAAK,iBAAiB,EAAE,cAAc,MAAM,EAAE,UAAU,WAAW,EAAE,MACvJ,OAAO,OAAO,eAAe,CAAC,KAAK;;;;;EA2EpD,CAAC;AAEF,eAAe,gBAAgB,CAAC"}