@minded-ai/mindedjs 1.0.31 → 1.0.32

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 (53) hide show
  1. package/dist/internalTools/appActionRunnerTool.d.ts +7 -0
  2. package/dist/internalTools/appActionRunnerTool.d.ts.map +1 -0
  3. package/dist/internalTools/appActionRunnerTool.js +49 -0
  4. package/dist/internalTools/appActionRunnerTool.js.map +1 -0
  5. package/dist/internalTools/utils.d.ts +2 -0
  6. package/dist/internalTools/utils.d.ts.map +1 -0
  7. package/dist/internalTools/utils.js +8 -0
  8. package/dist/internalTools/utils.js.map +1 -0
  9. package/dist/nodes/actionRunnerNode.d.ts +14 -0
  10. package/dist/nodes/actionRunnerNode.d.ts.map +1 -0
  11. package/dist/nodes/actionRunnerNode.js +99 -0
  12. package/dist/nodes/actionRunnerNode.js.map +1 -0
  13. package/dist/nodes/actionRunnerTool.d.ts +14 -0
  14. package/dist/nodes/actionRunnerTool.d.ts.map +1 -0
  15. package/dist/nodes/actionRunnerTool.js +101 -0
  16. package/dist/nodes/actionRunnerTool.js.map +1 -0
  17. package/dist/nodes/addAppTool.d.ts +8 -0
  18. package/dist/nodes/addAppTool.js +12 -0
  19. package/dist/nodes/addAppTool.js.map +1 -0
  20. package/dist/nodes/addAppToolNode.d.ts +9 -0
  21. package/dist/nodes/addAppToolNode.d.ts.map +1 -0
  22. package/dist/nodes/addAppToolNode.js +35 -0
  23. package/dist/nodes/addAppToolNode.js.map +1 -0
  24. package/dist/nodes/addToolNode.d.ts +2 -2
  25. package/dist/nodes/addToolNode.d.ts.map +1 -1
  26. package/dist/nodes/addToolNode.js +39 -69
  27. package/dist/nodes/addToolNode.js.map +1 -1
  28. package/dist/nodes/callTool.d.ts +10 -0
  29. package/dist/nodes/callTool.js +57 -0
  30. package/dist/nodes/callTool.js.map +1 -0
  31. package/dist/nodes/nodeFactory.d.ts +2 -2
  32. package/dist/nodes/nodeFactory.d.ts.map +1 -1
  33. package/dist/nodes/nodeFactory.js.map +1 -1
  34. package/dist/nodes/toolNodeRunner.d.ts +15 -0
  35. package/dist/nodes/toolNodeRunner.js +79 -0
  36. package/dist/nodes/toolNodeRunner.js.map +1 -0
  37. package/dist/platform/mindedRequest.js +2 -2
  38. package/dist/platform/mindedRequest.js.map +1 -1
  39. package/dist/tools/appToolRunner.d.ts +30 -0
  40. package/dist/tools/appToolRunner.js +35 -0
  41. package/dist/tools/appToolRunner.js.map +1 -0
  42. package/dist/tools/parser.d.ts +14 -0
  43. package/dist/tools/parser.js +17 -0
  44. package/dist/tools/parser.js.map +1 -0
  45. package/dist/tools/triggerTypeToDefaultMessage.d.ts +3 -0
  46. package/dist/tools/triggerTypeToDefaultMessage.js +10 -0
  47. package/dist/tools/triggerTypeToDefaultMessage.js.map +1 -0
  48. package/package.json +2 -2
  49. package/src/nodes/addToolNode.ts +43 -82
  50. package/src/nodes/nodeFactory.ts +2 -1
  51. package/dist/types/Triggers.types.d.ts +0 -1
  52. package/dist/types/Triggers.types.js +0 -3
  53. package/dist/types/Triggers.types.js.map +0 -1
@@ -0,0 +1,7 @@
1
+ import { MindedConnectionSocketMessageType } from '../platform/mindedConnectionTypes';
2
+ import { ActionInputParam } from '../types/Flows.types';
3
+ import { Tool } from '../types/Tools.types';
4
+ declare const appActionRunnerToolCreator: (schema: ActionInputParam[], nodeTitle: string, awaitEmit: (event: MindedConnectionSocketMessageType, payload: any) => Promise<any>) => Tool<any, any>;
5
+ export declare const getAppActionRunnerTool: (nodeTitle: string) => Tool<any, any>;
6
+ export default appActionRunnerToolCreator;
7
+ //# sourceMappingURL=appActionRunnerTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appActionRunnerTool.d.ts","sourceRoot":"","sources":["../../src/internalTools/appActionRunnerTool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iCAAiC,EAAE,MAAM,mCAAmC,CAAC;AACtF,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAuB5C,QAAA,MAAM,0BAA0B,GAAI,QAAQ,gBAAgB,EAAE,EAAE,WAAW,MAAM,EAAE,WAAW,CAAC,KAAK,EAAE,iCAAiC,EAAE,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,GAAG,CAAC,KAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAwBrL,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,WAAW,MAAM,mBAEvD,CAAA;AAED,eAAe,0BAA0B,CAAC"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAppActionRunnerTool = void 0;
4
+ const mindedConnectionTypes_1 = require("../platform/mindedConnectionTypes");
5
+ const zod_1 = require("zod");
6
+ const typeToZodMap = {
7
+ string: zod_1.z.string(),
8
+ number: zod_1.z.number(),
9
+ boolean: zod_1.z.boolean(),
10
+ array: zod_1.z.array(zod_1.z.any()),
11
+ object: zod_1.z.record(zod_1.z.any()),
12
+ any: zod_1.z.any()
13
+ };
14
+ const convertToZodSchema = (schema) => {
15
+ var _a;
16
+ const zodSchema = {};
17
+ for (const [key, type] of Object.entries(schema)) {
18
+ const zodType = (_a = typeToZodMap[type.toLowerCase()]) !== null && _a !== void 0 ? _a : zod_1.z.string();
19
+ zodSchema[key] = zodType;
20
+ }
21
+ return zod_1.z.object(zodSchema);
22
+ };
23
+ const createdTools = {};
24
+ const appActionRunnerToolCreator = (schema, nodeTitle, awaitEmit) => {
25
+ const zodSchema = convertToZodSchema(schema.reduce((acc, param) => {
26
+ acc[param.name] = param.type;
27
+ return acc;
28
+ }, {}));
29
+ const tool = {
30
+ name: nodeTitle,
31
+ description: `Run ${nodeTitle} action from`,
32
+ input: zodSchema,
33
+ execute: async ({ input }) => {
34
+ const response = await awaitEmit(mindedConnectionTypes_1.MindedConnectionSocketMessageType.OnAppAction, {
35
+ nodeTitle,
36
+ actionInput: input,
37
+ });
38
+ return response;
39
+ },
40
+ };
41
+ createdTools[nodeTitle] = tool;
42
+ return tool;
43
+ };
44
+ const getAppActionRunnerTool = (nodeTitle) => {
45
+ return createdTools[nodeTitle];
46
+ };
47
+ exports.getAppActionRunnerTool = getAppActionRunnerTool;
48
+ exports.default = appActionRunnerToolCreator;
49
+ //# sourceMappingURL=appActionRunnerTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appActionRunnerTool.js","sourceRoot":"","sources":["../../src/internalTools/appActionRunnerTool.ts"],"names":[],"mappings":";;;AAAA,6EAAsF;AAGtF,6BAAwB;AAExB,MAAM,YAAY,GAAG;IACjB,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;IAClB,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;IAClB,OAAO,EAAE,OAAC,CAAC,OAAO,EAAE;IACpB,KAAK,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,GAAG,EAAE,CAAC;IACvB,MAAM,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,GAAG,EAAE,CAAC;IACzB,GAAG,EAAE,OAAC,CAAC,GAAG,EAAE;CACN,CAAC;AAEX,MAAM,kBAAkB,GAAG,CAAC,MAA8B,EAAE,EAAE;;IAC1D,MAAM,SAAS,GAA8B,EAAE,CAAC;IAChD,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC/C,MAAM,OAAO,GAAG,MAAA,YAAY,CAAC,IAAI,CAAC,WAAW,EAA+B,CAAC,mCAAI,OAAC,CAAC,MAAM,EAAE,CAAC;QAC5F,SAAS,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;IAC7B,CAAC;IACD,OAAO,OAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AAC/B,CAAC,CAAC;AAEF,MAAM,YAAY,GAAmC,EAAE,CAAC;AAExD,MAAM,0BAA0B,GAAG,CAAC,MAA0B,EAAE,SAAiB,EAAE,SAAmF,EAAkB,EAAE;IACtL,MAAM,SAAS,GAAG,kBAAkB,CAAC,MAAM,CAAC,MAAM,CAC9C,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QACX,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC;QAC7B,OAAO,GAAG,CAAC;IACf,CAAC,EACD,EAA4B,CAC/B,CAAC,CAAC;IAGH,MAAM,IAAI,GAAG;QACT,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,OAAO,SAAS,cAAc;QAC3C,KAAK,EAAE,SAAS;QAChB,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,EAAwB,EAAE,EAAE;YAC/C,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,yDAAiC,CAAC,WAAW,EAAE;gBAC5E,SAAS;gBACT,WAAW,EAAE,KAAK;aACrB,CAAC,CAAC;YACH,OAAO,QAAQ,CAAC;QACpB,CAAC;KACJ,CAAC;IACF,YAAY,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;IAC/B,OAAO,IAAI,CAAC;AAChB,CAAC,CAAA;AAEM,MAAM,sBAAsB,GAAG,CAAC,SAAiB,EAAE,EAAE;IACxD,OAAO,YAAY,CAAC,SAAS,CAAC,CAAC;AACnC,CAAC,CAAA;AAFY,QAAA,sBAAsB,0BAElC;AAED,kBAAe,0BAA0B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const sanitizeName: (name: string) => string;
2
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,8 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,14 @@
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
@@ -0,0 +1 @@
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;;;;;EA0EpD,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Flows_types_1 = require("../types/Flows.types");
4
+ const prebuilt_1 = require("@langchain/langgraph/prebuilt");
5
+ const langgraph_1 = require("@langchain/langgraph");
6
+ const messages_1 = require("@langchain/core/messages");
7
+ const uuid_1 = require("uuid");
8
+ const tools_1 = require("@langchain/core/tools");
9
+ const actionRunnerTool = (matchedTool, toolNode, llm, addedPrompt, history) => {
10
+ return async (state) => {
11
+ try {
12
+ console.log(`Executing tool node ${toolNode.name}`);
13
+ const executeWrapper = async (input) => {
14
+ try {
15
+ const response = await matchedTool.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
16
+ return response || {};
17
+ }
18
+ catch (error) {
19
+ console.error('Error executing tool', error);
20
+ throw error;
21
+ }
22
+ };
23
+ const tool = (0, tools_1.tool)(executeWrapper, {
24
+ name: matchedTool.name,
25
+ description: matchedTool.description,
26
+ schema: matchedTool.input,
27
+ });
28
+ let toolCallMessage;
29
+ let toolResponseMessage;
30
+ let attempts = 0;
31
+ const maxAttempts = 3;
32
+ while ((!toolCallMessage || !toolResponseMessage) && attempts < maxAttempts) {
33
+ const prompt = `
34
+ Context:
35
+ messages: ${JSON.stringify(state.messages)}
36
+ workflow memory: ${JSON.stringify(state.memory)}
37
+ Instructions:
38
+ Your ONLY task is to call the tool ${tool.name}(...) using the context above.
39
+ Do not engage in conversation or provide any other responses.
40
+ Just make the tool call immediately.
41
+ You MUST call the tool even if you are uncertain about some parameters - use your best judgment to fill in any missing values.
42
+ ${toolNode.prompt ? `Tool parameters guidance: ${toolNode.prompt}` : ''}
43
+ ${addedPrompt ? `Additional instructions: ${addedPrompt}` : ''}
44
+ ${attempts > 0
45
+ ? `Previous attempts failed. You MUST make a tool call now with your best guess at the parameters - this is your only job.`
46
+ : ''}
47
+ `;
48
+ const toolCallingAgent = (0, prebuilt_1.createReactAgent)({
49
+ checkpointer: new langgraph_1.MemorySaver(),
50
+ llm,
51
+ tools: [tool],
52
+ });
53
+ const response = await toolCallingAgent.invoke({ messages: [new messages_1.SystemMessage(prompt)] }, { configurable: { thread_id: (0, uuid_1.v4)() } });
54
+ toolCallMessage = getLastToolCallMessage(response.messages);
55
+ toolResponseMessage = getLastToolMessage(response.messages);
56
+ if (!toolCallMessage || !toolResponseMessage) {
57
+ response.messages.push(new messages_1.SystemMessage('No tool call was made. Please try again and make sure to call the tool.'));
58
+ attempts++;
59
+ }
60
+ }
61
+ if (!toolCallMessage || !toolResponseMessage) {
62
+ throw new Error('Failed to get tool call or response after multiple attempts');
63
+ }
64
+ let toolMemory = {};
65
+ if (toolNode.type === Flows_types_1.NodeType.APP_TOOL) {
66
+ toolMemory = extractToolMemoryResponse(toolResponseMessage);
67
+ }
68
+ return { memory: toolMemory, messages: [toolCallMessage, toolResponseMessage], triggerInvocations: state.triggerInvocations, history: history || [] };
69
+ }
70
+ catch (error) {
71
+ console.error('Error executing tool node', error);
72
+ throw error;
73
+ }
74
+ };
75
+ };
76
+ exports.default = actionRunnerTool;
77
+ const getLastToolCallMessage = (messages) => {
78
+ const toolCallMessages = messages.filter((message) => { var _a; return ((_a = message.tool_calls) === null || _a === void 0 ? void 0 : _a.length) || 0 > 0; });
79
+ const lastToolCallMessage = toolCallMessages[toolCallMessages.length - 1];
80
+ return lastToolCallMessage;
81
+ };
82
+ const getLastToolMessage = (messages) => {
83
+ const toolMessages = messages.filter((message) => message.getType() === 'tool');
84
+ const lastToolMessage = toolMessages[toolMessages.length - 1];
85
+ return lastToolMessage;
86
+ };
87
+ const extractToolMemoryResponse = (toolMessage) => {
88
+ try {
89
+ const parsed = JSON.parse(toolMessage.content);
90
+ if (typeof parsed === 'object' && parsed !== null && 'memory' in parsed) {
91
+ return parsed.memory;
92
+ }
93
+ }
94
+ catch (error) {
95
+ console.error('Error parsing tool memory response', error);
96
+ }
97
+ return {};
98
+ };
99
+ //# sourceMappingURL=actionRunnerNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actionRunnerNode.js","sourceRoot":"","sources":["../../src/nodes/actionRunnerNode.ts"],"names":[],"mappings":";;AAAA,sDAAuE;AAIvE,4DAAiE;AACjE,oDAAmD;AAEnD,uDAA8F;AAC9F,+BAAoC;AACpC,iDAA8D;AAG9D,MAAM,gBAAgB,GAAG,CAAS,WAA8B,EAAE,QAAgC,EAAE,GAAsB,EAAE,WAAoB,EAAE,OAAuB,EAAE,EAAE;IACzK,OAAO,KAAK,EAAE,KAAmC,EAAE,EAAE;QACjD,IAAI,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,uBAAuB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;YAEpD,MAAM,cAAc,GAAG,KAAK,EAAE,KAAwC,EAAE,EAAE;gBACtE,IAAI,CAAC;oBACD,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,EAAE,CAAC,CAAC;oBAC1H,OAAO,QAAQ,IAAI,EAAE,CAAC;gBAC1B,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACb,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;oBAC7C,MAAM,KAAK,CAAC;gBAChB,CAAC;YACL,CAAC,CAAC;YACF,M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B,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC1E,OAAO,mBAAmB,CAAC;AAC/B,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,QAAuB,EAAe,EAAE;IAChE,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,MAAM,CAAC,CAAC;IAChF,MAAM,eAAe,GAAG,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC9D,OAAO,eAA8B,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,yBAAyB,GAAG,CAAS,WAAwB,EAAmB,EAAE;IACpF,IAAI,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAiB,CAAC,CAAC;QACzD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,QAAQ,IAAI,MAAM,EAAE,CAAC;YACtE,OAAO,MAAM,CAAC,MAAM,CAAC;QACzB,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1,14 @@
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=actionRunnerTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actionRunnerTool.d.ts","sourceRoot":"","sources":["../../src/nodes/actionRunnerTool.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;;;;;EA6EpD,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const Flows_types_1 = require("../types/Flows.types");
4
+ const prebuilt_1 = require("@langchain/langgraph/prebuilt");
5
+ const langgraph_1 = require("@langchain/langgraph");
6
+ const messages_1 = require("@langchain/core/messages");
7
+ const uuid_1 = require("uuid");
8
+ const tools_1 = require("@langchain/core/tools");
9
+ const actionRunnerTool = (matchedTool, toolNode, llm, addedPrompt, history) => {
10
+ return async (state) => {
11
+ try {
12
+ console.log(`Executing tool node ${toolNode.name}`);
13
+ const executeWrapper = async (input) => {
14
+ try {
15
+ const response = await matchedTool.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
16
+ return response || {};
17
+ }
18
+ catch (error) {
19
+ console.error('Error executing tool', error);
20
+ throw error;
21
+ }
22
+ };
23
+ const tool = (0, tools_1.tool)(executeWrapper, {
24
+ name: matchedTool.name,
25
+ description: matchedTool.description,
26
+ schema: matchedTool.input,
27
+ });
28
+ let toolCallMessage;
29
+ let toolResponseMessage;
30
+ let attempts = 0;
31
+ const maxAttempts = 1;
32
+ // TODO : figure out why we added this while loop
33
+ if ((!toolCallMessage || !toolResponseMessage) && attempts < maxAttempts) {
34
+ console.log("asdasdasd");
35
+ const prompt = `
36
+ Context:
37
+ messages: ${JSON.stringify(state.messages)}
38
+ workflow memory: ${JSON.stringify(state.memory)}
39
+ Instructions:
40
+ Your ONLY task is to call the tool ${tool.name}(...) using the context above.
41
+ Do not engage in conversation or provide any other responses.
42
+ Just make the tool call immediately.
43
+ You MUST call the tool even if you are uncertain about some parameters - use your best judgment to fill in any missing values.
44
+ ${toolNode.prompt ? `Tool parameters guidance: ${toolNode.prompt}` : ''}
45
+ ${addedPrompt ? `Additional instructions: ${addedPrompt}` : ''}
46
+ ${attempts > 0
47
+ ? `Previous attempts failed. You MUST make a tool call now with your best guess at the parameters - this is your only job.`
48
+ : ''}
49
+ `;
50
+ const toolCallingAgent = (0, prebuilt_1.createReactAgent)({
51
+ checkpointer: new langgraph_1.MemorySaver(),
52
+ llm,
53
+ tools: [tool],
54
+ });
55
+ const response = await toolCallingAgent.invoke({ messages: [new messages_1.SystemMessage(prompt)] }, { configurable: { thread_id: (0, uuid_1.v4)() } });
56
+ toolCallMessage = getLastToolCallMessage(response.messages);
57
+ toolResponseMessage = getLastToolMessage(response.messages);
58
+ if (!toolCallMessage || !toolResponseMessage) {
59
+ response.messages.push(new messages_1.SystemMessage('No tool call was made. Please try again and make sure to call the tool.'));
60
+ attempts++;
61
+ }
62
+ }
63
+ if (!toolCallMessage || !toolResponseMessage) {
64
+ throw new Error('Failed to get tool call or response after multiple attempts');
65
+ }
66
+ let toolMemory = {};
67
+ if (toolNode.type === Flows_types_1.NodeType.APP_TOOL) {
68
+ toolMemory = extractToolMemoryResponse(toolResponseMessage);
69
+ }
70
+ return { memory: toolMemory, messages: [toolCallMessage, toolResponseMessage], triggerInvocations: state.triggerInvocations, history: history || [] };
71
+ }
72
+ catch (error) {
73
+ console.error('Error executing tool node', error);
74
+ throw error;
75
+ }
76
+ };
77
+ };
78
+ exports.default = actionRunnerTool;
79
+ const getLastToolCallMessage = (messages) => {
80
+ const toolCallMessages = messages.filter((message) => { var _a; return ((_a = message.tool_calls) === null || _a === void 0 ? void 0 : _a.length) || 0 > 0; });
81
+ const lastToolCallMessage = toolCallMessages[toolCallMessages.length - 1];
82
+ return lastToolCallMessage;
83
+ };
84
+ const getLastToolMessage = (messages) => {
85
+ const toolMessages = messages.filter((message) => message.getType() === 'tool');
86
+ const lastToolMessage = toolMessages[toolMessages.length - 1];
87
+ return lastToolMessage;
88
+ };
89
+ const extractToolMemoryResponse = (toolMessage) => {
90
+ try {
91
+ const parsed = JSON.parse(toolMessage.content);
92
+ if (typeof parsed === 'object' && parsed !== null && 'memory' in parsed) {
93
+ return parsed.memory;
94
+ }
95
+ }
96
+ catch (error) {
97
+ console.error('Error parsing tool memory response', error);
98
+ }
99
+ return {};
100
+ };
101
+ //# sourceMappingURL=actionRunnerTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"actionRunnerTool.js","sourceRoot":"","sources":["../../src/nodes/actionRunnerTool.ts"],"names":[],"mappings":";;AAAA,sDAAuE;AAIvE,4DAAiE;AACjE,oDAAmD;AAEnD,uDAA8F;AAC9F,+BAAoC;AACpC,iDAA8D;AAG9D,MAAM,gBAAgB,GAAG,CAAS,WAA8B,EAAE,QAAgC,EAAE,GAAsB,EAAE,WAAoB,EAAE,OAAuB,EAAE,EAAE;IACzK,OAAO,KAAK,EAAE,KAAmC,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,KAAK,IAAI,IAAI,QAAQ,IAAI,MAAM,EAAE,CAAC;YACtE,OAAO,MAAM,CAAC,MAAM,CAAC;QACzB,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { AppToolNode } from '../types/Flows.types';
2
+ import { PreCompiledGraph } from "../types/LangGraph.types";
3
+ import { BaseLanguageModel } from "@langchain/core/language_models/base";
4
+ export declare const addAppToolNode: <Memory>({ graph, node, llm, }: {
5
+ graph: PreCompiledGraph;
6
+ node: AppToolNode;
7
+ llm: BaseLanguageModel;
8
+ }) => void;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addAppToolNode = void 0;
4
+ const appToolRunner_1 = require("../tools/appToolRunner");
5
+ const toolNodeRunner_1 = require("./toolNodeRunner");
6
+ const addAppToolNode = ({ graph, node, llm, }) => {
7
+ const toolNode = node;
8
+ const callback = (0, toolNodeRunner_1.getToolNodeRunner)(toolNode, appToolRunner_1.appToolRunnerTool, llm);
9
+ graph.addNode(node.name, callback);
10
+ };
11
+ exports.addAppToolNode = addAppToolNode;
12
+ //# sourceMappingURL=addAppTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addAppTool.js","sourceRoot":"","sources":["../../src/nodes/addAppTool.ts"],"names":[],"mappings":";;;AAGA,0DAA2D;AAC3D,qDAAqD;AAG9C,MAAM,cAAc,GAAG,CAAS,EACnC,KAAK,EACL,IAAI,EACJ,GAAG,GAKN,EAAE,EAAE;IACD,MAAM,QAAQ,GAAG,IAAmB,CAAC;IACrC,MAAM,QAAQ,GAAiB,IAAA,kCAAiB,EAAS,QAAQ,EAAE,iCAAiB,EAAE,GAAG,CAAC,CAAC;IAC3F,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACvC,CAAC,CAAC;AAZW,QAAA,cAAc,kBAYzB"}
@@ -0,0 +1,9 @@
1
+ import { BaseLanguageModel } from "@langchain/core/language_models/base";
2
+ import { AppToolNode } from "../types/Flows.types";
3
+ import { PreCompiledGraph } from "../types/LangGraph.types";
4
+ export declare const addAppToolNode: ({ graph, node, llm, }: {
5
+ graph: PreCompiledGraph;
6
+ node: AppToolNode;
7
+ llm: BaseLanguageModel;
8
+ }) => void;
9
+ //# sourceMappingURL=addAppToolNode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addAppToolNode.d.ts","sourceRoot":"","sources":["../../src/nodes/addAppToolNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAEzE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAK5D,eAAO,MAAM,cAAc,GAAI,uBAI5B;IACC,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,EAAE,WAAW,CAAC;IAClB,GAAG,EAAE,iBAAiB,CAAC;CAC1B,SAuBA,CAAC"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.addAppToolNode = void 0;
7
+ const actionRunnerNode_1 = __importDefault(require("./actionRunnerNode"));
8
+ const appActionRunnerTool_1 = require("../internalTools/appActionRunnerTool");
9
+ const Agent_types_1 = require("../types/Agent.types");
10
+ const addAppToolNode = ({ graph, node, llm, }) => {
11
+ const appRunnerTool = (0, appActionRunnerTool_1.getAppActionRunnerTool)(node.name);
12
+ const addedPrompt = `
13
+ when You are executing the app tool "${appRunnerTool.name}".
14
+ The tool requires the following parameters:
15
+ ${node.metadata.schema.map(param => `
16
+ - ${param.name} (${param.type}): ${param.description}
17
+ ${param.example ? `Example: ${param.example}` : ''}
18
+ ${param.enum ? `Allowed values: ${param.enum.join(', ')}` : ''}
19
+ ${param.items ? `Array items type: ${param.items.type}` : ''}
20
+ `).join('\n')}
21
+
22
+ Please analyze the conversation context and workflow memory to determine the appropriate values for these parameters.
23
+ Ensure all required parameters are provided and values match the specified types and constraints.
24
+ If any parameter is unclear from the context, ask for clarification.
25
+ finally, don't forget to Call immediately tool ${appRunnerTool.name}(...) with exact name and parameters as asked. don't add any other prefixes or characters to the provided ${appRunnerTool.name}, simply run it with the parameters as requested.
26
+ `;
27
+ const history = [{
28
+ type: Agent_types_1.FlowHistoryType.APP_ACTION_INVOCATION,
29
+ nodeTitle: node.name,
30
+ }];
31
+ const callback = (0, actionRunnerNode_1.default)(appRunnerTool, node, llm, addedPrompt, history);
32
+ graph.addNode(node.name, callback);
33
+ };
34
+ exports.addAppToolNode = addAppToolNode;
35
+ //# sourceMappingURL=addAppToolNode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addAppToolNode.js","sourceRoot":"","sources":["../../src/nodes/addAppToolNode.ts"],"names":[],"mappings":";;;;;;AAIA,0EAAkD;AAClD,8EAA8E;AAC9E,sDAAuD;AAEhD,MAAM,cAAc,GAAG,CAAC,EAC3B,KAAK,EACL,IAAI,EACJ,GAAG,GAKN,EAAE,EAAE;IACD,MAAM,aAAa,GAAG,IAAA,4CAAsB,EAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACxD,MAAM,WAAW,GAAG;uCACe,aAAa,CAAC,IAAI;;EAEvD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;IAChC,KAAK,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,MAAM,KAAK,CAAC,WAAW;IAChD,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE;IAChD,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,mBAAmB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE;IAC5D,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,qBAAqB,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE;CAC7D,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;;;;;iDAKoC,aAAa,CAAC,IAAI,6GAA6G,aAAa,CAAC,IAAI;CACjM,CAAA;IACG,MAAM,OAAO,GAAG,CAAC;YACb,IAAI,EAAE,6BAAe,CAAC,qBAAqB;YAC3C,SAAS,EAAE,IAAI,CAAC,IAAI;SACvB,CAAC,CAAC;IACH,MAAM,QAAQ,GAAiB,IAAA,0BAAgB,EAAC,aAAa,EAAE,IAAI,EAAE,GAAG,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;IAChG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACvC,CAAC,CAAC;AA/BW,QAAA,cAAc,kBA+BzB"}
@@ -1,11 +1,11 @@
1
- import { BaseLanguageModel } from '@langchain/core/language_models/base';
2
1
  import { ToolNode } from '../types/Flows.types';
3
2
  import { Tool } from '../types/Tools.types';
4
3
  import { PreCompiledGraph } from '../types/LangGraph.types';
4
+ import { LLMProviders } from '../types/LLM.types';
5
5
  export declare const addToolNode: <Memory>({ graph, node, tools, llm, }: {
6
6
  graph: PreCompiledGraph;
7
7
  node: ToolNode;
8
8
  tools: Tool<any, any>[];
9
- llm: BaseLanguageModel;
9
+ llm: (typeof LLMProviders)[keyof typeof LLMProviders];
10
10
  }) => Promise<void>;
11
11
  //# sourceMappingURL=addToolNode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"addToolNode.d.ts","sourceRoot":"","sources":["../../src/nodes/addToolNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAmB,MAAM,0BAA0B,CAAC;AAQ7E,eAAO,MAAM,WAAW,GAAU,MAAM,EAAE,8BAKvC;IACD,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IACxB,GAAG,EAAE,iBAAiB,CAAC;CACxB,kBA8EA,CAAC"}
1
+ {"version":3,"file":"addToolNode.d.ts","sourceRoot":"","sources":["../../src/nodes/addToolNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAmB,MAAM,0BAA0B,CAAC;AAK7E,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,eAAO,MAAM,WAAW,GAAU,MAAM,EAAE,8BAKvC;IACD,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,EAAE,QAAQ,CAAC;IACf,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IACxB,GAAG,EAAE,CAAA,OAAO,YAAY,EAAC,MAAM,OAAO,YAAY,CAAC,CAAC;CACrD,kBAoDA,CAAC"}
@@ -3,8 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addToolNode = void 0;
4
4
  const tools_1 = require("@langchain/core/tools");
5
5
  const messages_1 = require("@langchain/core/messages");
6
- const prebuilt_1 = require("@langchain/langgraph/prebuilt");
7
- const langgraph_1 = require("@langchain/langgraph");
8
6
  const uuid_1 = require("uuid");
9
7
  const addToolNode = async ({ graph, node, tools, llm, }) => {
10
8
  const toolNode = node;
@@ -13,79 +11,51 @@ const addToolNode = async ({ graph, node, tools, llm, }) => {
13
11
  throw new Error(`Tool not found: ${toolNode.toolName}`);
14
12
  }
15
13
  const callback = async (state) => {
16
- try {
17
- console.log(`Executing tool node ${toolNode.name}`);
18
- const executeWrapper = async (input) => {
19
- try {
20
- const response = await matchedTool.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
21
- return response || {};
22
- }
23
- catch (error) {
24
- console.error('Error executing tool', error);
25
- throw error;
26
- }
27
- };
28
- const tool = (0, tools_1.tool)(executeWrapper, {
29
- name: matchedTool.name,
30
- description: matchedTool.description,
31
- schema: matchedTool.input,
32
- });
33
- let toolCallMessage;
34
- let toolResponseMessage;
35
- let attempts = 0;
36
- const maxAttempts = 3;
37
- while ((!toolCallMessage || !toolResponseMessage) && attempts < maxAttempts) {
38
- const prompt = `
39
- Context:
40
- messages: ${JSON.stringify(state.messages)}
41
- workflow memory: ${JSON.stringify(state.memory)}
42
- Instructions:
43
- Your ONLY task is to call the tool ${tool.name}(...) using the context above.
44
- Do not engage in conversation or provide any other responses.
45
- Just make the tool call immediately.
46
- You MUST call the tool even if you are uncertain about some parameters - use your best judgment to fill in any missing values.
47
- ${toolNode.prompt ? `Tool parameters guidance: ${toolNode.prompt}` : ''}
48
- ${attempts > 0
49
- ? `Previous attempts failed. You MUST make a tool call now with your best guess at the parameters - this is your only job.`
50
- : ''}
51
- `;
52
- const toolCallingAgent = (0, prebuilt_1.createReactAgent)({
53
- checkpointer: new langgraph_1.MemorySaver(),
54
- llm,
55
- tools: [tool],
56
- });
57
- const response = await toolCallingAgent.invoke({ messages: [new messages_1.SystemMessage(prompt)] }, { configurable: { thread_id: (0, uuid_1.v4)() } });
58
- toolCallMessage = getLastToolCallMessage(response.messages);
59
- toolResponseMessage = getLastToolMessage(response.messages);
60
- if (!toolCallMessage || !toolResponseMessage) {
61
- response.messages.push(new messages_1.SystemMessage('No tool call was made. Please try again and make sure to call the tool.'));
62
- attempts++;
63
- }
14
+ console.log(`Executing tool node ${toolNode.name}`);
15
+ const executeWrapper = async (input) => {
16
+ try {
17
+ const response = await matchedTool.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
18
+ return response || {};
64
19
  }
65
- if (!toolCallMessage || !toolResponseMessage) {
66
- throw new Error('Failed to get tool call or response after multiple attempts');
20
+ catch (error) {
21
+ console.error('Error executing tool', error);
22
+ throw error;
67
23
  }
68
- const toolMemory = extractToolMemoryResponse(toolResponseMessage);
69
- return { memory: toolMemory, messages: [toolCallMessage, toolResponseMessage], triggerInvocations: state.triggerInvocations };
70
- }
71
- catch (error) {
72
- console.error('Error executing tool node', error);
73
- throw error;
74
- }
24
+ };
25
+ const prompt = `
26
+ Context:
27
+ workflow memory: ${JSON.stringify(state.memory)}
28
+
29
+ Task:
30
+ Extract the necessary parameters for the tool "${matchedTool.name}" based on the context above and the previous messages.
31
+
32
+ ${toolNode.prompt ? `Additional guidance for parameter extraction: ${toolNode.prompt}` : ''}
33
+
34
+ Important:
35
+ - Extract ONLY the parameters that match the schema
36
+ - Use your best judgment to fill in any missing values
37
+ - Do not include any parameters not defined in the schema
38
+ - Return a valid JSON object matching the schema exactly
39
+ `;
40
+ const structuredLlm = llm.withStructuredOutput(matchedTool.input);
41
+ const structuredResponse = await structuredLlm.invoke([...state.messages, new messages_1.SystemMessage(prompt)]);
42
+ const tool = (0, tools_1.tool)(executeWrapper, {
43
+ name: matchedTool.name,
44
+ description: matchedTool.description,
45
+ schema: matchedTool.input,
46
+ });
47
+ const response = await tool.invoke({
48
+ args: structuredResponse,
49
+ type: 'tool_call',
50
+ id: (0, uuid_1.v4)(),
51
+ name: matchedTool.name,
52
+ });
53
+ const toolMemory = extractToolMemoryResponse(response);
54
+ return { memory: toolMemory, messages: [response] };
75
55
  };
76
56
  graph.addNode(node.name, callback);
77
57
  };
78
58
  exports.addToolNode = addToolNode;
79
- const getLastToolCallMessage = (messages) => {
80
- const toolCallMessages = messages.filter((message) => { var _a; return ((_a = message.tool_calls) === null || _a === void 0 ? void 0 : _a.length) || 0 > 0; });
81
- const lastToolCallMessage = toolCallMessages[toolCallMessages.length - 1];
82
- return lastToolCallMessage;
83
- };
84
- const getLastToolMessage = (messages) => {
85
- const toolMessages = messages.filter((message) => message.getType() === 'tool');
86
- const lastToolMessage = toolMessages[toolMessages.length - 1];
87
- return lastToolMessage;
88
- };
89
59
  const extractToolMemoryResponse = (toolMessage) => {
90
60
  try {
91
61
  const parsed = JSON.parse(toolMessage.content);
@@ -1 +1 @@
1
- {"version":3,"file":"addToolNode.js","sourceRoot":"","sources":["../../src/nodes/addToolNode.ts"],"names":[],"mappings":";;;AAGA,iDAA8D;AAE9D,uDAA8F;AAC9F,4DAAiE;AAGjE,oDAAmD;AACnD,+BAAoC;AAE7B,MAAM,WAAW,GAAG,KAAK,EAAU,EACxC,KAAK,EACL,IAAI,EACJ,KAAK,EACL,GAAG,GAMJ,EAAE,EAAE;IACH,MAAM,QAAQ,GAAG,IAAgB,CAAC;IAClC,MAAM,WAAW,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAC1E,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,mBAAmB,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC1D,CAAC;IACD,MAAM,QAAQ,GAAiB,KAAK,EAAE,KAAmC,EAAE,EAAE;QAC3E,IAAI,CAAC;YACH,OAAO,CAAC,GAAG,CAAC,uBAAuB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;YAEpD,MAAM,cAAc,GAAG,KAAK,EAAE,KAAwC,EAAE,EAAE;gBACxE,IAAI,CAAC;oBACH,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM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guageModel } from "@langchain/core/language_models/base";
2
+ import { ToolNode } from "../types/Flows.types";
3
+ import { Tool } from "@langchain/core/tools";
4
+ import { PreCompiledGraph } from "../types/LangGraph.types";
5
+ export declare const callToolRunner: (tool: Tool, toolNode: ToolNode, { graph, node, tools, llm }: {
6
+ graph: PreCompiledGraph;
7
+ node: ToolNode;
8
+ tools: Tool[];
9
+ llm: BaseLanguageModel;
10
+ }) => void;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.callToolRunner = void 0;
4
+ const prebuilt_1 = require("@langchain/langgraph/prebuilt");
5
+ // export const callToolRunner = (toolNode: ToolNode) => {
6
+ // return async (input: any) => {
7
+ // console.log(`Calling tool ${toolNode.name} with input ${JSON.stringify(input)}`);
8
+ // };
9
+ // };
10
+ const callToolRunner = (tool, toolNode, { graph, node, tools, llm }) => {
11
+ const callback = async (state) => {
12
+ try {
13
+ console.log(`Executing tool node ${toolNode.name}`);
14
+ const executeWrapper = async (input) => {
15
+ try {
16
+ const response = await toolNode.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
17
+ return response || {};
18
+ }
19
+ catch (error) {
20
+ console.error('Error executing tool', error);
21
+ throw error;
22
+ }
23
+ };
24
+ const tool = langchainTool(executeWrapper, {
25
+ name: toolNode.name,
26
+ description: toolNode.description,
27
+ schema: toolNode.input,
28
+ });
29
+ const prompt = `
30
+ Context:
31
+ messages: ${JSON.stringify(state.messages)}
32
+ workflow memory: ${JSON.stringify(state.memory)}
33
+ Instructions:
34
+ Call immediately tool ${tool.name}(...)
35
+ ${toolNode.prompt && `Tool execution instructions: ${toolNode.prompt}`}
36
+ `;
37
+ const toolCallingAgent = (0, prebuilt_1.createReactAgent)({
38
+ llm,
39
+ tools: [tool],
40
+ });
41
+ const response = await toolCallingAgent.invoke({ messages: [new SystemMessage(prompt)] });
42
+ const toolCallMessage = getLastToolCallMessage(response.messages);
43
+ const toolResponseMessage = getLastToolMessage(response.messages);
44
+ if (!toolCallMessage || !toolResponseMessage) {
45
+ throw new Error('Tool call or tool response message not found');
46
+ }
47
+ const toolMemory = extractToolMemoryResponse(toolResponseMessage);
48
+ return { memory: toolMemory, messages: [toolCallMessage, toolResponseMessage], triggerInvocations: state.triggerInvocations };
49
+ }
50
+ catch (error) {
51
+ console.error('Error executing tool node', error);
52
+ throw error;
53
+ }
54
+ };
55
+ };
56
+ exports.callToolRunner = callToolRunner;
57
+ //# sourceMappingURL=callTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"callTool.js","sourceRoot":"","sources":["../../src/nodes/callTool.ts"],"names":[],"mappings":";;;AAIA,4DAAiE;AAGjE,0DAA0D;AAC1D,mCAAmC;AACnC,wFAAwF;AACxF,OAAO;AACP,KAAK;AAEE,MAAM,cAAc,GAAG,CAAC,IAAU,EAAE,QAAkB,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAsF,EAAE,EAAE;IAC9K,MAAM,QAAQ,GAAiB,KAAK,EAAE,KAAmC,EAAE,EAAE;QACzE,IAAI,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,uBAAuB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;YAEpD,MAAM,cAAc,GAAG,KAAK,EAAE,KAAqC,EAAE,EAAE;gBACnE,IAAI,CAAC;oBACD,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,EAAE,CAAC,CAAC;oBACvH,OAAO,QAAQ,IAAI,EAAE,CAAC;gBAC1B,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACb,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;oBAC7C,MAAM,KAAK,CAAC;gBAChB,CAAC;YACL,CAAC,CAAC;YACF,MAAM,IAAI,GAAG,aAAa,CA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C;QAChB,CAAC;IACL,CAAC,CAAC;AACN,CAAC,CAAC;AA5CW,QAAA,cAAc,kBA4CzB"}
@@ -1,14 +1,14 @@
1
1
  import { Node } from '../types/Flows.types';
2
2
  import { PreCompiledGraph } from '../types/LangGraph.types';
3
3
  import { Tool } from '../types/Tools.types';
4
- import { BaseLanguageModel } from '@langchain/core/language_models/base';
5
4
  import { AgentEventRequestPayloads } from '../events/AgentEvents';
6
5
  import { EmitSignature } from '../types/Agent.types';
6
+ import { LLMProviders } from '../types/LLM.types';
7
7
  export declare const nodeFactory: ({ graph, node, tools, llm, emit, }: {
8
8
  graph: PreCompiledGraph;
9
9
  node: Node;
10
10
  tools: Tool<any, any>[];
11
- llm: BaseLanguageModel;
11
+ llm: (typeof LLMProviders)[keyof typeof LLMProviders];
12
12
  emit: EmitSignature<any, keyof AgentEventRequestPayloads<any>>;
13
13
  }) => void;
14
14
  //# sourceMappingURL=nodeFactory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"nodeFactory.d.ts","sourceRoot":"","sources":["../../src/nodes/nodeFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAA6B,IAAI,EAAY,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AAGzE,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAuBrD,eAAO,MAAM,WAAW,GAAI,oCAMzB;IACD,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IACxB,GAAG,EAAE,iBAAiB,CAAC;IACvB,IAAI,EAAE,aAAa,CAAC,GAAG,EAAE,MAAM,yBAAyB,CAAC,GAAG,CAAC,CAAC,CAAC;CAChE,SAqBA,CAAC"}
1
+ {"version":3,"file":"nodeFactory.d.ts","sourceRoot":"","sources":["../../src/nodes/nodeFactory.ts"],"names":[],"mappings":"AACA,OAAO,EAA6B,IAAI,EAAY,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAI5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAsBlD,eAAO,MAAM,WAAW,GAAI,oCAMzB;IACD,KAAK,EAAE,gBAAgB,CAAC;IACxB,IAAI,EAAE,IAAI,CAAC;IACX,KAAK,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IACxB,GAAG,EAAE,CAAA,OAAO,YAAY,EAAC,MAAM,OAAO,YAAY,CAAC,CAAC;IACpD,IAAI,EAAE,aAAa,CAAC,GAAG,EAAE,MAAM,yBAAyB,CAAC,GAAG,CAAC,CAAC,CAAC;CAChE,SAqBA,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"nodeFactory.js","sourceRoot":"","sources":["../../src/nodes/nodeFactory.ts"],"names":[],"mappings":";;;AACA,sDAAiF;AAIjF,+CAA4C;AAC5C,mDAAgD;AAGhD,qDAAkD;AAElD,MAAM,eAAe,GAAG,CAAC,EAAE,KAAK,EAAE,IAAI,EAAmD,EAAE,EAAE;IAC3F,MAAM,QAAQ,GAAiB,KAAK,IAAI,EAAE,GAAG,CAAC,CAAC;IAC/C,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF,MAAM,cAAc,GAAG,CAAC,EAC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,EAAE,CAAC,CAAC;YAC5C,MAAM;QACR,KAAK,sBAAQ,CAAC,WAAW;YACvB,IAAA,6BAAa,EAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;YACjD,MAAM;QACR;YACE,MAAM,IAAI,KAAK,CAAC,0BAA0B,QAAQ,EAAE,CAAC,CAAC;IAC1D,CAAC;AACH,CAAC,CAAC;AAjCW,QAAA,WAAW,eAiCtB"}
@@ -0,0 +1,15 @@
1
+ import { BaseLanguageModel } from "@langchain/core/language_models/base";
2
+ import { AppToolNode, ToolNode } from "../types/Flows.types";
3
+ import { Tool } from "../types/Tools.types";
4
+ import { stateAnnotation } from "../types/LangGraph.types";
5
+ import { BaseMessage } from "@langchain/core/messages";
6
+ import { ToolMessage } from "@langchain/core/messages";
7
+ export declare const getToolNodeRunner: <Memory>(toolNode: ToolNode | AppToolNode, matchedTool: Tool<any, any>, llm: BaseLanguageModel) => (state: typeof stateAnnotation.State) => Promise<{
8
+ memory: Partial<Memory>;
9
+ messages: (BaseMessage | ToolMessage)[];
10
+ triggerInvocations: {
11
+ appName: string;
12
+ triggerName: string;
13
+ triggerBody: any;
14
+ }[];
15
+ }>;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getToolNodeRunner = void 0;
4
+ const tools_1 = require("@langchain/core/tools");
5
+ const messages_1 = require("@langchain/core/messages");
6
+ const prebuilt_1 = require("@langchain/langgraph/prebuilt");
7
+ const langgraph_1 = require("@langchain/langgraph");
8
+ const uuid_1 = require("uuid");
9
+ const getToolNodeRunner = (toolNode, matchedTool, llm) => {
10
+ return async (state) => {
11
+ try {
12
+ console.log(`Executing tool node ${toolNode.name}`);
13
+ const executeWrapper = async (input) => {
14
+ try {
15
+ const response = await matchedTool.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
16
+ return response || {};
17
+ }
18
+ catch (error) {
19
+ console.error('Error executing tool', error);
20
+ throw error;
21
+ }
22
+ };
23
+ const tool = (0, tools_1.tool)(executeWrapper, {
24
+ name: matchedTool.name,
25
+ description: matchedTool.description,
26
+ schema: matchedTool.input,
27
+ });
28
+ const prompt = `
29
+ Context:
30
+ messages: ${JSON.stringify(state.messages)}
31
+ workflow memory: ${JSON.stringify(state.memory)}
32
+ Instructions:
33
+ Call immediately tool ${tool.name}(...)
34
+ ${toolNode.prompt && `Tool execution instructions: ${toolNode.prompt}`}
35
+ `;
36
+ const toolCallingAgent = (0, prebuilt_1.createReactAgent)({
37
+ checkpointer: new langgraph_1.MemorySaver(),
38
+ llm,
39
+ tools: [tool],
40
+ });
41
+ const response = await toolCallingAgent.invoke({ messages: [new messages_1.SystemMessage(prompt)] }, { configurable: { thread_id: (0, uuid_1.v4)() } });
42
+ const toolCallMessage = getLastToolCallMessage(response.messages);
43
+ const toolResponseMessage = getLastToolMessage(response.messages);
44
+ if (!toolCallMessage || !toolResponseMessage) {
45
+ throw new Error('Tool call or tool response message not found');
46
+ }
47
+ const toolMemory = extractToolMemoryResponse(toolResponseMessage);
48
+ return { memory: toolMemory, messages: [toolCallMessage, toolResponseMessage], triggerInvocations: state.triggerInvocations };
49
+ }
50
+ catch (error) {
51
+ console.error('Error executing tool node', error);
52
+ throw error;
53
+ }
54
+ };
55
+ };
56
+ exports.getToolNodeRunner = getToolNodeRunner;
57
+ const getLastToolCallMessage = (messages) => {
58
+ const toolCallMessages = messages.filter((message) => { var _a; return ((_a = message.tool_calls) === null || _a === void 0 ? void 0 : _a.length) || 0 > 0; });
59
+ const lastToolCallMessage = toolCallMessages[toolCallMessages.length - 1];
60
+ return lastToolCallMessage;
61
+ };
62
+ const getLastToolMessage = (messages) => {
63
+ const toolMessages = messages.filter((message) => message.getType() === 'tool');
64
+ const lastToolMessage = toolMessages[toolMessages.length - 1];
65
+ return lastToolMessage;
66
+ };
67
+ const extractToolMemoryResponse = (toolMessage) => {
68
+ try {
69
+ const parsed = JSON.parse(toolMessage.content);
70
+ if (typeof parsed === 'object' && parsed !== null && 'memory' in parsed) {
71
+ return parsed.memory;
72
+ }
73
+ }
74
+ catch (error) {
75
+ console.error('Error parsing tool memory response', error);
76
+ }
77
+ return {};
78
+ };
79
+ //# sourceMappingURL=toolNodeRunner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"toolNodeRunner.js","sourceRoot":"","sources":["../../src/nodes/toolNodeRunner.ts"],"names":[],"mappings":";;;AAGA,iDAA8D;AAE9D,uDAAiF;AACjF,4DAAiE;AAGjE,oDAAmD;AACnD,+BAAoC;AAE7B,MAAM,iBAAiB,GAAG,CAAS,QAAgC,EAAE,WAA2B,EAAE,GAAsB,EAAE,EAAE;IAC/H,OAAO,KAAK,EAAE,KAAmC,EAAE,EAAE;QACjD,IAAI,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,uBAAuB,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;YAEpD,MAAM,cAAc,GAAG,KAAK,EAAE,KAAwC,EAAE,EAAE;gBACtE,IAAI,CAAC;oBACD,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,EAAE,CAAC,CAAC;oBAC1H,OAAO,QAAQ,IAAI,EAAE,CAAC;gBAC1B,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACb,OAAO,CAAC,KAAK,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;oBAC7C,MAAM,KAAK,CAAC;gBAChB,CAAC;YACL,CAAC,CAAC;YACF,MAAM,IAAI,GAAG,IAAA,YAAa,EAAC,cAAc,EAAE;gBACvC,IAAI,EAAE,WAAW,CAAC,IAAI;gBACtB,WAAW,EAAE,WAAW,CAAC,WAAW;gBACpC,MAAM,EAAE,WAAW,CAAC,KAAK;aAC5B,CAAC,CAAC;YACH,MAAM,MAAM,GAAG;;oB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AAiB,qBA6C5B;AAEF,MAAM,sBAAsB,GAAG,CAAC,QAAuB,EAAe,EAAE;IACpE,MAAM,gBAAgB,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,WAAC,OAAA,CAAA,MAAC,OAAqB,CAAC,UAAU,0CAAE,MAAM,KAAI,CAAC,GAAG,CAAC,CAAA,EAAA,CAAC,CAAC;IAC1G,MAAM,mBAAmB,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC1E,OAAO,mBAAmB,CAAC;AAC/B,CAAC,CAAC;AAEF,MAAM,kBAAkB,GAAG,CAAC,QAAuB,EAAe,EAAE;IAChE,MAAM,YAAY,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,KAAK,MAAM,CAAC,CAAC;IAChF,MAAM,eAAe,GAAG,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC9D,OAAO,eAA8B,CAAC;AAC1C,CAAC,CAAC;AAEF,MAAM,yBAAyB,GAAG,CAAS,WAAwB,EAAmB,EAAE;IACpF,IAAI,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAiB,CAAC,CAAC;QACzD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAI,QAAQ,IAAI,MAAM,EAAE,CAAC;YACtE,OAAO,MAAM,CAAC,MAAM,CAAC;QACzB,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC,CAAC"}
@@ -5,11 +5,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.mindedRequest = void 0;
7
7
  const axios_1 = __importDefault(require("axios"));
8
+ const config_1 = require("./config");
8
9
  const mindedRequest = async ({ path, method, body, token, }) => {
9
- const baseUrl = process.env.MINDED_SERVER || 'https://api.minded.com/sdk';
10
10
  const response = await (0, axios_1.default)({
11
11
  method,
12
- url: `${baseUrl}${path}`,
12
+ url: `${(0, config_1.getConfig)().baseUrl}${path}`,
13
13
  data: body,
14
14
  headers: {
15
15
  'Content-Type': 'application/json',
@@ -1 +1 @@
1
- {"version":3,"file":"mindedRequest.js","sourceRoot":"","sources":["../../src/platform/mindedRequest.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAInB,MAAM,aAAa,GAAG,KAAK,EAA8B,EAC9D,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,KAAK,GAMN,EAAqB,EAAE;IACtB,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,4BAA4B,CAAC;IAE1E,MAAM,QAAQ,GAAG,MAAM,IAAA,eAAK,EAAC;QAC3B,MAAM;QACN,GAAG,EAAE,GAAG,OAAO,GAAG,IAAI,EAAE;QACxB,IAAI,EAAE,IAAI;QACV,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,KAAK,EAAE;SACjC;KACF,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC,CAAC;AAxBW,QAAA,aAAa,iBAwBxB"}
1
+ {"version":3,"file":"mindedRequest.js","sourceRoot":"","sources":["../../src/platform/mindedRequest.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,qCAAqC;AAI9B,MAAM,aAAa,GAAG,KAAK,EAA8B,EAC9D,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,KAAK,GAMN,EAAqB,EAAE;IAEtB,MAAM,QAAQ,GAAG,MAAM,IAAA,eAAK,EAAC;QAC3B,MAAM;QACN,GAAG,EAAE,GAAG,IAAA,kBAAS,GAAE,CAAC,OAAO,GAAG,IAAI,EAAE;QACpC,IAAI,EAAE,IAAI;QACV,OAAO,EAAE;YACP,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,UAAU,KAAK,EAAE;SACjC;KACF,CAAC,CAAC;IAEH,OAAO,QAAQ,CAAC,IAAI,CAAC;AACvB,CAAC,CAAC;AAvBW,QAAA,aAAa,iBAuBxB"}
@@ -0,0 +1,30 @@
1
+ import { z } from "zod";
2
+ import { Tool } from "../types/Tools.types";
3
+ declare const schema: z.ZodObject<{
4
+ appName: z.ZodString;
5
+ actionName: z.ZodString;
6
+ parameters: z.ZodRecord<z.ZodString, z.ZodString>;
7
+ }, "strip", z.ZodTypeAny, {
8
+ appName: string;
9
+ actionName: string;
10
+ parameters: Record<string, string>;
11
+ }, {
12
+ appName: string;
13
+ actionName: string;
14
+ parameters: Record<string, string>;
15
+ }>;
16
+ declare const memorySchema: z.ZodObject<{
17
+ appName: z.ZodString;
18
+ actionName: z.ZodString;
19
+ output: z.ZodAny;
20
+ }, "strip", z.ZodTypeAny, {
21
+ appName: string;
22
+ actionName: string;
23
+ output?: any;
24
+ }, {
25
+ appName: string;
26
+ actionName: string;
27
+ output?: any;
28
+ }>;
29
+ export declare const appToolRunnerTool: Tool<typeof schema, typeof memorySchema>;
30
+ export {};
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ // import { z } from 'zod';
3
+ // import memorySchema from '../src/schema';
4
+ // import { Tool } from '@minded-ai/mindedjs';
5
+ // type Memory = z.infer<typeof memorySchema>;
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.appToolRunnerTool = void 0;
8
+ const zod_1 = require("zod");
9
+ const schema = zod_1.z.object({
10
+ appName: zod_1.z.string(),
11
+ actionName: zod_1.z.string(),
12
+ parameters: zod_1.z.record(zod_1.z.string(), zod_1.z.string()),
13
+ });
14
+ const memorySchema = zod_1.z.object({
15
+ appName: zod_1.z.string(),
16
+ actionName: zod_1.z.string(),
17
+ output: zod_1.z.any(),
18
+ });
19
+ exports.appToolRunnerTool = {
20
+ name: 'appToolRunner',
21
+ description: 'Run an app tool',
22
+ input: schema,
23
+ execute: async ({ input, memory }) => {
24
+ console.log("will run app tool", input, memory);
25
+ // call server to run the app tool
26
+ return {
27
+ // memory: {
28
+ // issue: input.issue,
29
+ // orderId: input.orderId,
30
+ // customerName: input.customerName,
31
+ // },
32
+ };
33
+ },
34
+ };
35
+ //# sourceMappingURL=appToolRunner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"appToolRunner.js","sourceRoot":"","sources":["../../src/tools/appToolRunner.ts"],"names":[],"mappings":";AAAA,2BAA2B;AAC3B,4CAA4C;AAC5C,8CAA8C;AAC9C,8CAA8C;;;AAE9C,6BAAwB;AAGxB,MAAM,MAAM,GAAG,OAAC,CAAC,MAAM,CAAC;IACpB,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;IACnB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;IACtB,UAAU,EAAE,OAAC,CAAC,MAAM,CAAC,OAAC,CAAC,MAAM,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC;CAC/C,CAAC,CAAC;AAEH,MAAM,YAAY,GAAG,OAAC,CAAC,MAAM,CAAC;IAC1B,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;IACnB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;IACtB,MAAM,EAAE,OAAC,CAAC,GAAG,EAAE;CAClB,CAAC,CAAC;AAEU,QAAA,iBAAiB,GAA6C;IACvE,IAAI,EAAE,eAAe;IACrB,WAAW,EAAE,iBAAiB;IAC9B,KAAK,EAAE,MAAM;IACb,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE;QACjC,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAChD,kCAAkC;QAClC,OAAO;QACH,YAAY;QACZ,0BAA0B;QAC1B,8BAA8B;QAC9B,wCAAwC;QACxC,KAAK;SACR,CAAC;IACN,CAAC;CACJ,CAAC"}
@@ -0,0 +1,14 @@
1
+ export declare class ToolParser {
2
+ qualify({ name, payload }: {
3
+ name: string;
4
+ payload: any;
5
+ }): Promise<boolean>;
6
+ transform({ name, payload }: {
7
+ name: string;
8
+ payload: any;
9
+ }): Promise<any>;
10
+ matchesTool({ name, source }: {
11
+ name: string;
12
+ source?: string;
13
+ }): Promise<boolean>;
14
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ToolParser = void 0;
4
+ /* eslint-disable @typescript-eslint/no-unused-vars */
5
+ class ToolParser {
6
+ async qualify({ name, payload }) {
7
+ return true;
8
+ }
9
+ async transform({ name, payload }) {
10
+ return payload;
11
+ }
12
+ async matchesTool({ name, source }) {
13
+ return false;
14
+ }
15
+ }
16
+ exports.ToolParser = ToolParser;
17
+ //# sourceMappingURL=parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/tools/parser.ts"],"names":[],"mappings":";;;AAAA,sDAAsD;AACtD,MAAa,UAAU;IACZ,KAAK,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAkC;QAClE,OAAO,IAAI,CAAC;IAChB,CAAC;IACM,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,OAAO,EAAkC;QACpE,OAAO,OAAO,CAAA;IAClB,CAAC;IAEM,KAAK,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,MAAM,EAAqC;QACxE,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AAXD,gCAWC"}
@@ -0,0 +1,3 @@
1
+ import { BaseMessage } from "@langchain/core/messages";
2
+ declare const triggerTypeToDefaultMessage: Record<string, Record<string, (triggerBody: any) => Array<BaseMessage>>>;
3
+ export default triggerTypeToDefaultMessage;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const messages_1 = require("@langchain/core/messages");
4
+ const triggerTypeToDefaultMessage = {
5
+ ["Slack"]: {
6
+ "New Direct Message (Instant)": (triggerBody) => [new messages_1.HumanMessage({ content: triggerBody.text })],
7
+ }
8
+ };
9
+ exports.default = triggerTypeToDefaultMessage;
10
+ //# sourceMappingURL=triggerTypeToDefaultMessage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"triggerTypeToDefaultMessage.js","sourceRoot":"","sources":["../../src/tools/triggerTypeToDefaultMessage.ts"],"names":[],"mappings":";;AAAA,uDAAqE;AAErE,MAAM,2BAA2B,GAA6E;IAC1G,CAAC,OAAO,CAAC,EAAE;QACP,8BAA8B,EAAE,CAAC,WAAgB,EAAE,EAAE,CAAC,CAAC,IAAI,uBAAY,CAAC,EAAE,OAAO,EAAE,WAAW,CAAC,IAAI,EAAE,CAAC,CAAC;KAC1G;CACJ,CAAC;AAEF,kBAAe,2BAA2B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minded-ai/mindedjs",
3
- "version": "1.0.31",
3
+ "version": "1.0.32",
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
+ }
@@ -1,14 +1,12 @@
1
- import { BaseLanguageModel } from '@langchain/core/language_models/base';
2
1
  import { ToolNode } from '../types/Flows.types';
3
2
  import { Tool } from '../types/Tools.types';
4
3
  import { tool as langchainTool } from '@langchain/core/tools';
5
4
  import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
6
- import { AIMessage, BaseMessage, SystemMessage, ToolMessage } from '@langchain/core/messages';
7
- import { createReactAgent } from '@langchain/langgraph/prebuilt';
5
+ import { SystemMessage, ToolMessage } from '@langchain/core/messages';
8
6
  import { RunnableLike } from '@langchain/core/runnables';
9
7
  import { z } from 'zod';
10
- import { MemorySaver } from '@langchain/langgraph';
11
8
  import { v4 as uuidv4 } from 'uuid';
9
+ import { LLMProviders } from '../types/LLM.types';
12
10
 
13
11
  export const addToolNode = async <Memory>({
14
12
  graph,
@@ -19,7 +17,7 @@ export const addToolNode = async <Memory>({
19
17
  graph: PreCompiledGraph;
20
18
  node: ToolNode;
21
19
  tools: Tool<any, any>[];
22
- llm: BaseLanguageModel;
20
+ llm: typeof LLMProviders[keyof typeof LLMProviders];
23
21
  }) => {
24
22
  const toolNode = node as ToolNode;
25
23
  const matchedTool = tools.find((tool) => tool.name === toolNode.toolName);
@@ -27,90 +25,53 @@ export const addToolNode = async <Memory>({
27
25
  throw new Error(`Tool not found: ${toolNode.toolName}`);
28
26
  }
29
27
  const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
30
- try {
31
- console.log(`Executing tool node ${toolNode.name}`);
28
+ console.log(`Executing tool node ${toolNode.name}`);
32
29
 
33
- const executeWrapper = async (input: z.infer<typeof matchedTool.input>) => {
34
- try {
35
- const response = await matchedTool.execute({ input, memory: state.memory, triggerInvocations: state.triggerInvocations });
36
- return response || {};
37
- } catch (error) {
38
- console.error('Error executing tool', error);
39
- throw error;
40
- }
41
- };
42
- const tool = langchainTool(executeWrapper, {
43
- name: matchedTool.name,
44
- description: matchedTool.description,
45
- schema: matchedTool.input,
46
- });
47
-
48
- let toolCallMessage;
49
- let toolResponseMessage;
50
- let attempts = 0;
51
- const maxAttempts = 3;
52
-
53
- while ((!toolCallMessage || !toolResponseMessage) && attempts < maxAttempts) {
54
- const prompt = `
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 prompt = `
55
40
  Context:
56
- messages: ${JSON.stringify(state.messages)}
57
- workflow memory: ${JSON.stringify(state.memory)}
58
- Instructions:
59
- Your ONLY task is to call the tool ${tool.name}(...) using the context above.
60
- Do not engage in conversation or provide any other responses.
61
- Just make the tool call immediately.
62
- You MUST call the tool even if you are uncertain about some parameters - use your best judgment to fill in any missing values.
63
- ${toolNode.prompt ? `Tool parameters guidance: ${toolNode.prompt}` : ''}
64
- ${
65
- attempts > 0
66
- ? `Previous attempts failed. You MUST make a tool call now with your best guess at the parameters - this is your only job.`
67
- : ''
68
- }
41
+ workflow memory: ${JSON.stringify(state.memory)}
42
+
43
+ Task:
44
+ Extract the necessary parameters for the tool "${matchedTool.name}" based on the context above and the previous messages.
45
+
46
+ ${toolNode.prompt ? `Additional guidance for parameter extraction: ${toolNode.prompt}` : ''}
47
+
48
+ Important:
49
+ - Extract ONLY the parameters that match the schema
50
+ - Use your best judgment to fill in any missing values
51
+ - Do not include any parameters not defined in the schema
52
+ - Return a valid JSON object matching the schema exactly
69
53
  `;
70
- const toolCallingAgent = createReactAgent({
71
- checkpointer: new MemorySaver(),
72
- llm,
73
- tools: [tool],
74
- });
75
-
76
- const response = await toolCallingAgent.invoke(
77
- { messages: [new SystemMessage(prompt)] },
78
- { configurable: { thread_id: uuidv4() } },
79
- );
80
- toolCallMessage = getLastToolCallMessage(response.messages);
81
- toolResponseMessage = getLastToolMessage(response.messages);
82
-
83
- if (!toolCallMessage || !toolResponseMessage) {
84
- response.messages.push(new SystemMessage('No tool call was made. Please try again and make sure to call the tool.'));
85
- attempts++;
86
- }
87
- }
88
-
89
- if (!toolCallMessage || !toolResponseMessage) {
90
- throw new Error('Failed to get tool call or response after multiple attempts');
54
+ const structuredLlm = llm.withStructuredOutput(matchedTool.input);
55
+ const structuredResponse = await structuredLlm.invoke([...state.messages, new SystemMessage(prompt)])
56
+ const tool = langchainTool(executeWrapper, {
57
+ name: matchedTool.name,
58
+ description: matchedTool.description,
59
+ schema: matchedTool.input,
60
+ });
61
+ const response = await tool.invoke(
62
+ {
63
+ args: structuredResponse,
64
+ type: 'tool_call',
65
+ id: uuidv4(),
66
+ name: matchedTool.name,
91
67
  }
92
-
93
- const toolMemory = extractToolMemoryResponse<Memory>(toolResponseMessage);
94
- return { memory: toolMemory, messages: [toolCallMessage, toolResponseMessage], triggerInvocations: state.triggerInvocations };
95
- } catch (error) {
96
- console.error('Error executing tool node', error);
97
- throw error;
98
- }
99
- };
68
+ )
69
+ const toolMemory = extractToolMemoryResponse<Memory>(response as ToolMessage);
70
+ return { memory: toolMemory, messages: [response] };
71
+ }
100
72
  graph.addNode(node.name, callback);
101
73
  };
102
74
 
103
- const getLastToolCallMessage = (messages: BaseMessage[]): BaseMessage => {
104
- const toolCallMessages = messages.filter((message) => (message as AIMessage).tool_calls?.length || 0 > 0);
105
- const lastToolCallMessage = toolCallMessages[toolCallMessages.length - 1];
106
- return lastToolCallMessage;
107
- };
108
-
109
- const getLastToolMessage = (messages: BaseMessage[]): ToolMessage => {
110
- const toolMessages = messages.filter((message) => message.getType() === 'tool');
111
- const lastToolMessage = toolMessages[toolMessages.length - 1];
112
- return lastToolMessage as ToolMessage;
113
- };
114
75
 
115
76
  const extractToolMemoryResponse = <Memory>(toolMessage: ToolMessage): Partial<Memory> => {
116
77
  try {
@@ -8,6 +8,7 @@ import { addPromptNode } from './addPromptNode';
8
8
  import { AgentEventRequestPayloads } from '../events/AgentEvents';
9
9
  import { EmitSignature } from '../types/Agent.types';
10
10
  import { addTriggerNode } from './addTriggerNode';
11
+ import { LLMProviders } from '../types/LLM.types';
11
12
 
12
13
  const addJunctionNode = ({ graph, node }: { graph: PreCompiledGraph; node: JunctionNode }) => {
13
14
  const callback: RunnableLike = async () => { };
@@ -39,7 +40,7 @@ export const nodeFactory = ({
39
40
  graph: PreCompiledGraph;
40
41
  node: Node;
41
42
  tools: Tool<any, any>[];
42
- llm: BaseLanguageModel;
43
+ llm: typeof LLMProviders[keyof typeof LLMProviders];
43
44
  emit: EmitSignature<any, keyof AgentEventRequestPayloads<any>>;
44
45
  }) => {
45
46
  const nodeType = node.type;
@@ -1 +0,0 @@
1
- export type TriggerBody = any;
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=Triggers.types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Triggers.types.js","sourceRoot":"","sources":["../../src/types/Triggers.types.ts"],"names":[],"mappings":""}