@minded-ai/mindedjs 1.0.36 → 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.
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +18 -8
- package/dist/agent.js.map +1 -1
- package/dist/analytics.d.ts +6 -0
- package/dist/analytics.js +19 -0
- package/dist/analytics.js.map +1 -0
- package/dist/cli/index.js +28 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/edges/edgeFactory.d.ts +3 -1
- package/dist/edges/edgeFactory.d.ts.map +1 -1
- package/dist/edges/edgeFactory.js +8 -3
- package/dist/edges/edgeFactory.js.map +1 -1
- package/dist/infrastructure.ts/mindedRequest.d.ts +8 -0
- package/dist/infrastructure.ts/mindedRequest.js +22 -0
- package/dist/infrastructure.ts/mindedRequest.js.map +1 -0
- package/dist/nodes/addToolNode.d.ts +1 -1
- package/dist/nodes/addToolNode.d.ts.map +1 -1
- package/dist/nodes/addToolNode.js +6 -24
- package/dist/nodes/addToolNode.js.map +1 -1
- package/dist/nodes/addToolRunNode.d.ts +15 -0
- package/dist/nodes/addToolRunNode.d.ts.map +1 -0
- package/dist/nodes/addToolRunNode.js +44 -0
- package/dist/nodes/addToolRunNode.js.map +1 -0
- package/dist/platform/{mindedChatOpenAI.js → MindedChatOpenAI.js} +3 -0
- package/dist/platform/MindedChatOpenAI.js.map +1 -0
- package/dist/platform/config.d.ts +1 -1
- package/dist/platform/config.d.ts.map +1 -1
- package/dist/platform/config.js +3 -0
- package/dist/platform/config.js.map +1 -1
- package/dist/platform/mindedChatOpenAI.d.ts.map +1 -1
- package/dist/platform/mindedConnection.d.ts +0 -7
- package/dist/platform/mindedConnection.d.ts.map +1 -1
- package/dist/platform/mindedConnection.js +5 -93
- package/dist/platform/mindedConnection.js.map +1 -1
- package/dist/types/Triggers.types.d.ts +1 -0
- package/dist/types/Triggers.types.js +3 -0
- package/dist/types/Triggers.types.js.map +1 -0
- package/package.json +2 -2
- package/src/agent.ts +22 -11
- package/src/cli/index.ts +31 -6
- package/src/edges/edgeFactory.ts +10 -1
- package/src/nodes/addToolNode.ts +9 -24
- package/src/nodes/addToolRunNode.ts +54 -0
- package/src/platform/config.ts +5 -1
- package/src/platform/mindedChatOpenAI.ts +3 -0
- package/src/platform/mindedConnection.ts +5 -68
- package/dist/internalTools/utils.d.ts +0 -2
- package/dist/internalTools/utils.d.ts.map +0 -1
- package/dist/internalTools/utils.js +0 -8
- package/dist/internalTools/utils.js.map +0 -1
- package/dist/nodes/actionRunnerNode.d.ts +0 -14
- package/dist/nodes/actionRunnerNode.d.ts.map +0 -1
- package/dist/nodes/actionRunnerNode.js +0 -100
- package/dist/nodes/actionRunnerNode.js.map +0 -1
- package/dist/nodes/actionRunnerTool.d.ts +0 -14
- package/dist/nodes/actionRunnerTool.d.ts.map +0 -1
- package/dist/nodes/actionRunnerTool.js +0 -101
- package/dist/nodes/actionRunnerTool.js.map +0 -1
- package/dist/nodes/addAppTool.d.ts +0 -8
- package/dist/nodes/addAppTool.js +0 -12
- package/dist/nodes/addAppTool.js.map +0 -1
- package/dist/nodes/callTool.d.ts +0 -10
- package/dist/nodes/callTool.js +0 -57
- package/dist/nodes/callTool.js.map +0 -1
- package/dist/nodes/toolNodeRunner.d.ts +0 -15
- package/dist/nodes/toolNodeRunner.js +0 -79
- package/dist/nodes/toolNodeRunner.js.map +0 -1
- package/dist/platform/mindedChatOpenAI.js.map +0 -1
- package/dist/tools/appToolRunner.d.ts +0 -30
- package/dist/tools/appToolRunner.js +0 -35
- package/dist/tools/appToolRunner.js.map +0 -1
- package/dist/tools/parser.d.ts +0 -14
- package/dist/tools/parser.js +0 -17
- package/dist/tools/parser.js.map +0 -1
- package/dist/tools/triggerTypeToDefaultMessage.d.ts +0 -3
- package/dist/tools/triggerTypeToDefaultMessage.js +0 -10
- package/dist/tools/triggerTypeToDefaultMessage.js.map +0 -1
- /package/dist/platform/{mindedChatOpenAI.d.ts → MindedChatOpenAI.d.ts} +0 -0
|
@@ -1,100 +0,0 @@
|
|
|
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
|
-
console.log("response", response);
|
|
17
|
-
return response || {};
|
|
18
|
-
}
|
|
19
|
-
catch (error) {
|
|
20
|
-
console.error('Error executing tool', error);
|
|
21
|
-
throw error;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const tool = (0, tools_1.tool)(executeWrapper, {
|
|
25
|
-
name: matchedTool.name,
|
|
26
|
-
description: matchedTool.description,
|
|
27
|
-
schema: matchedTool.input,
|
|
28
|
-
});
|
|
29
|
-
let toolCallMessage;
|
|
30
|
-
let toolResponseMessage;
|
|
31
|
-
let attempts = 0;
|
|
32
|
-
const maxAttempts = 3;
|
|
33
|
-
while ((!toolCallMessage || !toolResponseMessage) && attempts < maxAttempts) {
|
|
34
|
-
const prompt = `
|
|
35
|
-
Context:
|
|
36
|
-
messages: ${JSON.stringify(state.messages)}
|
|
37
|
-
workflow memory: ${JSON.stringify(state.memory)}
|
|
38
|
-
Instructions:
|
|
39
|
-
Your ONLY task is to call the tool ${tool.name}(...) using the context above.
|
|
40
|
-
Do not engage in conversation or provide any other responses.
|
|
41
|
-
Just make the tool call immediately.
|
|
42
|
-
You MUST call the tool even if you are uncertain about some parameters - use your best judgment to fill in any missing values.
|
|
43
|
-
${toolNode.prompt ? `Tool parameters guidance: ${toolNode.prompt}` : ''}
|
|
44
|
-
${addedPrompt ? `Additional instructions: ${addedPrompt}` : ''}
|
|
45
|
-
${attempts > 0
|
|
46
|
-
? `Previous attempts failed. You MUST make a tool call now with your best guess at the parameters - this is your only job.`
|
|
47
|
-
: ''}
|
|
48
|
-
`;
|
|
49
|
-
const toolCallingAgent = (0, prebuilt_1.createReactAgent)({
|
|
50
|
-
checkpointer: new langgraph_1.MemorySaver(),
|
|
51
|
-
llm,
|
|
52
|
-
tools: [tool],
|
|
53
|
-
});
|
|
54
|
-
const response = await toolCallingAgent.invoke({ messages: [new messages_1.SystemMessage(prompt)] }, { configurable: { thread_id: (0, uuid_1.v4)() } });
|
|
55
|
-
toolCallMessage = getLastToolCallMessage(response.messages);
|
|
56
|
-
toolResponseMessage = getLastToolMessage(response.messages);
|
|
57
|
-
if (!toolCallMessage || !toolResponseMessage) {
|
|
58
|
-
response.messages.push(new messages_1.SystemMessage('No tool call was made. Please try again and make sure to call the tool.'));
|
|
59
|
-
attempts++;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
if (!toolCallMessage || !toolResponseMessage) {
|
|
63
|
-
throw new Error('Failed to get tool call or response after multiple attempts');
|
|
64
|
-
}
|
|
65
|
-
let toolMemory = {};
|
|
66
|
-
if (toolNode.type === Flows_types_1.NodeType.APP_TOOL) {
|
|
67
|
-
toolMemory = extractToolMemoryResponse(toolResponseMessage);
|
|
68
|
-
}
|
|
69
|
-
return { memory: toolMemory, messages: [toolCallMessage, toolResponseMessage], triggerInvocations: state.triggerInvocations, history: history || [] };
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
console.error('Error executing tool node', error);
|
|
73
|
-
throw error;
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
exports.default = actionRunnerTool;
|
|
78
|
-
const getLastToolCallMessage = (messages) => {
|
|
79
|
-
const toolCallMessages = messages.filter((message) => { var _a; return ((_a = message.tool_calls) === null || _a === void 0 ? void 0 : _a.length) || 0 > 0; });
|
|
80
|
-
const lastToolCallMessage = toolCallMessages[toolCallMessages.length - 1];
|
|
81
|
-
return lastToolCallMessage;
|
|
82
|
-
};
|
|
83
|
-
const getLastToolMessage = (messages) => {
|
|
84
|
-
const toolMessages = messages.filter((message) => message.getType() === 'tool');
|
|
85
|
-
const lastToolMessage = toolMessages[toolMessages.length - 1];
|
|
86
|
-
return lastToolMessage;
|
|
87
|
-
};
|
|
88
|
-
const extractToolMemoryResponse = (toolMessage) => {
|
|
89
|
-
try {
|
|
90
|
-
const parsed = JSON.parse(toolMessage.content);
|
|
91
|
-
if (typeof parsed === 'object' && parsed !== null && 'memory' in parsed) {
|
|
92
|
-
return parsed.memory;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
catch (error) {
|
|
96
|
-
console.error('Error parsing tool memory response', error);
|
|
97
|
-
}
|
|
98
|
-
return {};
|
|
99
|
-
};
|
|
100
|
-
//# sourceMappingURL=actionRunnerNode.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,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CAAoC,EAAE,KAAK,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -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=actionRunnerTool.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,101 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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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AAC,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"}
|
|
@@ -1,8 +0,0 @@
|
|
|
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;
|
package/dist/nodes/addAppTool.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/nodes/callTool.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { BaseLanguageModel } 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;
|
package/dist/nodes/callTool.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
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 = callToolR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CAAC,KAAK,CAAC,MAAM,CAAC;;gCAEvB,IAAI,CAAC,IAAI;UAC/B,QAAQ,CAAC,MAAM,IAAI,gCAAgC,QAAQ,CAAC,MAAM,EAAE;OACvE,CAAC;YACI,MAAM,gBAAgB,GAAG,IAAA,2BAAgB,EAAC;gBACtC,GAAG;gBACH,KAAK,EAAE,CAAC,IAAI,CAAC;aAChB,CAAC,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,gBAAgB,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;YAC1F,MAAM,eAAe,GAAG,sBAAsB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAClE,MAAM,mBAAmB,GAAG,kBAAkB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;YAClE,IAAI,CAAC,eAAe,IAAI,CAAC,mBAAmB,EAAE,CAAC;gBAC3C,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;YACpE,CAAC;YACD,MAAM,UAAU,GAAG,yBAAyB,CAAS,mBAAmB,CAAC,CAAC;YAC1E,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC,eAAe,EAAE,mBAAmB,CAAC,EAAE,kBAAkB,EAAE,KAAK,CAAC,kBAAkB,EAAE,CAAC;QAClI,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE,KAAK,CAAC,CAAC;YAClD,MAAM,KAAK,CAAC;QAChB,CAAC;IACL,CAAC,CAAC;AACN,CAAC,CAAC;AA5CW,QAAA,cAAc,kBA4CzB"}
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}>;
|
|
@@ -1,79 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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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,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,EAAE,CAAC;AACd,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mindedChatOpenAI.js","sourceRoot":"","sources":["../../src/platform/mindedChatOpenAI.ts"],"names":[],"mappings":";;;AAAA,8CAAiE;AACjE,qCAAqC;AAErC,MAAa,gBAAiB,SAAQ,mBAAU;IAC9C,YAAY,MAAyB;QACnC,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,IAAA,kBAAS,GAAE,CAAC;QACvC,MAAM,aAAa,GAAG,GAAG,OAAO,4BAA4B,CAAC;QAC7D,KAAK,CAAC;YACJ,GAAG,MAAM;YACT,MAAM,EAAE,KAAK;YACb,aAAa,EAAE;gBACb,OAAO,EAAE,aAAa;aACvB;SACF,CAAC,CAAC;IACL,CAAC;CACF;AAZD,4CAYC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,35 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
package/dist/tools/parser.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/tools/parser.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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
|
package/dist/tools/parser.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
File without changes
|