@minded-ai/mindedjs 1.0.29 → 1.0.31
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 +3 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +27 -2
- package/dist/agent.js.map +1 -1
- package/dist/checkpointer/checkpointSaverFactory.d.ts +1 -0
- package/dist/checkpointer/checkpointSaverFactory.d.ts.map +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +0 -0
- package/dist/edges/createDirectEdge.d.ts +1 -0
- package/dist/edges/createDirectEdge.d.ts.map +1 -0
- package/dist/edges/createLogicalRouter.d.ts +1 -0
- package/dist/edges/createLogicalRouter.d.ts.map +1 -0
- package/dist/edges/createPromptRouter.d.ts +1 -0
- package/dist/edges/createPromptRouter.d.ts.map +1 -0
- package/dist/edges/edgeFactory.d.ts +1 -0
- package/dist/edges/edgeFactory.d.ts.map +1 -0
- package/dist/events/AgentEvents.d.ts +1 -0
- package/dist/events/AgentEvents.d.ts.map +1 -0
- package/dist/events/index.d.ts +1 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/llm/createLlmInstance.d.ts +1 -0
- package/dist/llm/createLlmInstance.d.ts.map +1 -0
- package/dist/nodes/addHumanInTheLoopNode.d.ts +1 -0
- package/dist/nodes/addHumanInTheLoopNode.d.ts.map +1 -0
- package/dist/nodes/addPromptNode.d.ts +1 -0
- package/dist/nodes/addPromptNode.d.ts.map +1 -0
- package/dist/nodes/addToolNode.d.ts +1 -0
- package/dist/nodes/addToolNode.d.ts.map +1 -0
- package/dist/nodes/addToolNode.js +33 -17
- package/dist/nodes/addToolNode.js.map +1 -1
- package/dist/nodes/addTriggerNode.d.ts +1 -0
- package/dist/nodes/addTriggerNode.d.ts.map +1 -0
- package/dist/nodes/nodeFactory.d.ts +1 -0
- package/dist/nodes/nodeFactory.d.ts.map +1 -0
- package/dist/platform/config.d.ts +1 -0
- package/dist/platform/config.d.ts.map +1 -0
- package/dist/platform/config.js +1 -1
- package/dist/platform/config.js.map +1 -1
- package/dist/platform/mindedChatOpenAI.d.ts +1 -0
- package/dist/platform/mindedChatOpenAI.d.ts.map +1 -0
- package/dist/platform/mindedCheckpointSaver.d.ts +1 -0
- package/dist/platform/mindedCheckpointSaver.d.ts.map +1 -0
- package/dist/platform/mindedConnection.d.ts +2 -0
- package/dist/platform/mindedConnection.d.ts.map +1 -0
- package/dist/platform/mindedConnection.js +25 -5
- package/dist/platform/mindedConnection.js.map +1 -1
- package/dist/platform/mindedConnectionTypes.d.ts +3 -1
- package/dist/platform/mindedConnectionTypes.d.ts.map +1 -0
- package/dist/platform/mindedConnectionTypes.js +1 -0
- package/dist/platform/mindedConnectionTypes.js.map +1 -1
- package/dist/platform/mindedRequest.js +2 -2
- package/dist/platform/mindedRequest.js.map +1 -1
- package/dist/triggers/triggerTypeToDefaultMessage.d.ts +1 -0
- package/dist/triggers/triggerTypeToDefaultMessage.d.ts.map +1 -0
- package/dist/types/Agent.types.d.ts +1 -0
- package/dist/types/Agent.types.d.ts.map +1 -0
- package/dist/types/Flows.types.d.ts +1 -0
- package/dist/types/Flows.types.d.ts.map +1 -0
- package/dist/types/LLM.types.d.ts +1 -0
- package/dist/types/LLM.types.d.ts.map +1 -0
- package/dist/types/LangGraph.types.d.ts +1 -0
- package/dist/types/LangGraph.types.d.ts.map +1 -0
- package/dist/types/Tools.types.d.ts +1 -0
- package/dist/types/Tools.types.d.ts.map +1 -0
- 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 +6 -2
- package/src/agent.ts +35 -2
- package/src/nodes/addToolNode.ts +44 -17
- package/src/platform/config.ts +1 -1
- package/src/platform/mindedConnection.ts +29 -8
- package/src/platform/mindedConnectionTypes.ts +1 -0
- package/.github/workflows/CI.yml +0 -34
- package/.prettierrc +0 -8
- package/dist/internalTools/appActionRunnerTool.d.ts +0 -6
- package/dist/internalTools/appActionRunnerTool.js +0 -55
- package/dist/internalTools/appActionRunnerTool.js.map +0 -1
- package/dist/nodes/actionRunnerTool.d.ts +0 -11
- package/dist/nodes/actionRunnerTool.js +0 -84
- 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/addAppToolNode.d.ts +0 -8
- package/dist/nodes/addAppToolNode.js +0 -29
- package/dist/nodes/addAppToolNode.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/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/docs/.gitbook/assets/image.png +0 -0
- package/docs/README.md +0 -51
- package/docs/SUMMARY.md +0 -23
- package/docs/api-reference/.nojekyll +0 -1
- package/docs/api-reference/assets/hierarchy.js +0 -1
- package/docs/api-reference/assets/highlight.css +0 -120
- package/docs/api-reference/assets/icons.js +0 -18
- package/docs/api-reference/assets/icons.svg +0 -1
- package/docs/api-reference/assets/main.js +0 -60
- package/docs/api-reference/assets/navigation.js +0 -1
- package/docs/api-reference/assets/search.js +0 -1
- package/docs/api-reference/assets/style.css +0 -1640
- package/docs/api-reference/classes/index.Agent.html +0 -4
- package/docs/api-reference/enums/index.EdgeType.html +0 -4
- package/docs/api-reference/enums/index.NodeType.html +0 -6
- package/docs/api-reference/enums/index.TriggerType.html +0 -4
- package/docs/api-reference/enums/index.events.html +0 -3
- package/docs/api-reference/hierarchy.html +0 -1
- package/docs/api-reference/index.html +0 -310
- package/docs/api-reference/interfaces/index.AppToolNode.html +0 -5
- package/docs/api-reference/interfaces/index.AppTriggerNode.html +0 -6
- package/docs/api-reference/interfaces/index.Flow.html +0 -4
- package/docs/api-reference/interfaces/index.JunctionNode.html +0 -4
- package/docs/api-reference/interfaces/index.LogicalConditionEdge.html +0 -5
- package/docs/api-reference/interfaces/index.ManualTriggerNode.html +0 -5
- package/docs/api-reference/interfaces/index.PromptConditionEdge.html +0 -5
- package/docs/api-reference/interfaces/index.PromptNode.html +0 -6
- package/docs/api-reference/interfaces/index.StepForwardEdge.html +0 -4
- package/docs/api-reference/interfaces/index.Tool.html +0 -6
- package/docs/api-reference/interfaces/index.ToolNode.html +0 -5
- package/docs/api-reference/modules/index-1.html +0 -1
- package/docs/api-reference/modules/index.html +0 -1
- package/docs/api-reference/modules.html +0 -1
- package/docs/api-reference/types/index.Edge.html +0 -1
- package/docs/api-reference/types/index.Node.html +0 -1
- package/docs/api-reference/types/index.TriggerNode.html +0 -1
- package/docs/core-concepts/edges.md +0 -299
- package/docs/core-concepts/events.md +0 -165
- package/docs/core-concepts/flows.md +0 -74
- package/docs/core-concepts/memory-types.md +0 -208
- package/docs/core-concepts/nodes.md +0 -257
- package/docs/core-concepts/tools.md +0 -225
- package/docs/core-concepts/triggers.md +0 -87
- package/docs/examples/order-refund-flow.md +0 -560
- package/docs/getting-started/environment-configuration.md +0 -117
- package/docs/getting-started/installation.md +0 -40
- package/docs/getting-started/quick-start.md +0 -264
- package/docs-structure.md +0 -144
- package/eslint.config.js +0 -68
- package/examples/orderRefundAgent/flows/orderRefundFlow.yaml +0 -26
- package/examples/orderRefundAgent/minded.json +0 -10
- package/examples/orderRefundAgent/orderRefundAgent.ts +0 -64
- package/examples/orderRefundAgent/schema.ts +0 -7
- package/examples/orderRefundAgent/tools/escalateConversation.ts +0 -28
- package/examples/orderRefundAgent/tools/index.ts +0 -4
- package/examples/orderRefundAgent/tools/refundOrder.ts +0 -27
- package/test/can-stay-on-node/can-stay-on-node.test.ts +0 -154
- package/test/can-stay-on-node/flows/test-flow.yaml +0 -25
- package/test/cannot-stay-on-node/cannot-stay-on-node.test.ts +0 -209
- package/test/cannot-stay-on-node/flows/test-flow.yaml +0 -34
- package/test/checkpoint-saver/minded-checkpoint-saver-list.test.ts +0 -140
- package/test/checkpoint-saver/minded-checkpoint-saver.test.ts +0 -100
- package/test/edge-priority/edge-priority.test.ts +0 -182
- package/test/edge-priority/flows/all-three-edges/test-flow.yaml +0 -35
- package/test/edge-priority/flows/logical-prompt-edges/test-flow.yaml +0 -26
- package/test/edge-priority/flows/stepforward-logical-edges/test-flow.yaml +0 -25
- package/test/edge-priority/flows/stepforward-prompt-edges/test-flow.yaml +0 -25
- package/test/human-in-the-loop-node/flows/test-flow.yaml +0 -23
- package/test/human-in-the-loop-node/human-in-the-loop-node.test.ts +0 -94
- package/test/logical-edges/flows/logical-edge-test-flow.yaml +0 -24
- package/test/logical-edges/logical-edges.test.ts +0 -68
- package/test/no-human-in-the-loop-node/flows/test-flow.yaml +0 -23
- package/test/no-human-in-the-loop-node/no-human-in-the-loop-node.test.ts +0 -81
- package/test/prompt-edges/flows/test-flow.yaml +0 -24
- package/test/prompt-edges/prompt-edges.test.ts +0 -92
- package/test/prompt-node/flows/test-flow.yaml +0 -24
- package/test/prompt-node/prompt-node.test.ts +0 -88
- package/test/setup.ts +0 -5
- package/test/tool-node/flows/test-flow.yaml +0 -14
- package/test/tool-node/tool-node.test.ts +0 -68
- package/test/trigger/flows/test-flow.yaml +0 -7
- package/test/trigger/trigger.test.ts +0 -185
- package/tsconfig.json +0 -17
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LangGraph.types.d.ts","sourceRoot":"","sources":["../../src/types/LangGraph.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAc,kBAAkB,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClF,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAEtE,eAAO,MAAM,eAAe;;;;;;kBAclB,MAAM;yBACC,GAAG;;;kBADV,MAAM;yBACC,GAAG;;kBADV,MAAM;yBACC,GAAG;;kBADV,MAAM;yBACC,GAAG;;kBADV,MAAM;yBACC,GAAG;;;;;EAMlB,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,kBAAkB,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC;AACjE,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Tools.types.d.ts","sourceRoot":"","sources":["../../src/types/Tools.types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,MAAM,WAAW,IAAI,CAAC,KAAK,SAAS,CAAC,CAAC,SAAS,EAAE,MAAM;IACrD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,KAAK,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,kBAAkB,EAAE,EAAE;QAAE,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,kBAAkB,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,CAAA;KAAE,KAAK,OAAO,CAAC;QAAE,MAAM,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAAC,MAAM,CAAC,EAAE,GAAG,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;CACpM"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TriggerBody = any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Triggers.types.js","sourceRoot":"","sources":["../../src/types/Triggers.types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minded-ai/mindedjs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.31",
|
|
4
4
|
"description": "MindedJS is a TypeScript library for building agents.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"bin": {
|
|
8
8
|
"minded": "./dist/cli/index.js"
|
|
9
9
|
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist",
|
|
12
|
+
"src"
|
|
13
|
+
],
|
|
10
14
|
"scripts": {
|
|
11
15
|
"build": "tsc",
|
|
12
16
|
"watch": "tsc -w",
|
|
@@ -49,4 +53,4 @@
|
|
|
49
53
|
"uuid": "^11.1.0",
|
|
50
54
|
"zod": "^3.24.4"
|
|
51
55
|
}
|
|
52
|
-
}
|
|
56
|
+
}
|
package/src/agent.ts
CHANGED
|
@@ -43,6 +43,8 @@ export class Agent {
|
|
|
43
43
|
private checkpointer: BaseCheckpointSaver;
|
|
44
44
|
// Langgraph compiled graph
|
|
45
45
|
private compiledGraph: CompiledGraph;
|
|
46
|
+
// Cache for secrets to avoid repeated API calls
|
|
47
|
+
private secretsCache: Record<string, string> | null = null;
|
|
46
48
|
|
|
47
49
|
// Event handlers storage keyed by event name. Handlers can optionally return a value.
|
|
48
50
|
private eventHandlers: {
|
|
@@ -60,9 +62,9 @@ export class Agent {
|
|
|
60
62
|
this.llm = createLlmInstance(config.llm);
|
|
61
63
|
this.validate();
|
|
62
64
|
|
|
63
|
-
const {
|
|
65
|
+
const { runLocally, token } = getConfig();
|
|
64
66
|
|
|
65
|
-
if (
|
|
67
|
+
if (token && !runLocally) {
|
|
66
68
|
this.mindedConnection = new MindedConnection();
|
|
67
69
|
this.mindedConnection.start();
|
|
68
70
|
this.mindedConnection.on(MindedConnectionSocketMessageType.OnAppTrigger, async (message: BaseMindedConnectionSocketMessage) => {
|
|
@@ -244,4 +246,35 @@ export class Agent {
|
|
|
244
246
|
const results = await Promise.all(this.eventHandlers[event]!.map(async (handler) => handler(payload)));
|
|
245
247
|
return results;
|
|
246
248
|
}
|
|
249
|
+
|
|
250
|
+
// Public method to get secrets from the backend service with caching
|
|
251
|
+
public async getSecrets(): Promise<Record<string, string>> {
|
|
252
|
+
// Return cached secrets if available
|
|
253
|
+
if (this.secretsCache !== null) {
|
|
254
|
+
return this.secretsCache;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
try {
|
|
258
|
+
// Check if mindedConnection is available
|
|
259
|
+
if (!this.mindedConnection) {
|
|
260
|
+
throw new Error('Platform is not available');
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Make socket request to fetch secrets
|
|
264
|
+
const response = await this.mindedConnection.awaitEmit<object, { secrets: Record<string, string> }>(
|
|
265
|
+
MindedConnectionSocketMessageType.GET_SECRETS,
|
|
266
|
+
{},
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
// Extract secrets from response
|
|
270
|
+
const secrets = response.secrets || {};
|
|
271
|
+
|
|
272
|
+
// Cache the secrets for future requests
|
|
273
|
+
this.secretsCache = secrets;
|
|
274
|
+
|
|
275
|
+
return secrets;
|
|
276
|
+
} catch (error) {
|
|
277
|
+
throw new Error(`Failed to fetch secrets: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
247
280
|
}
|
package/src/nodes/addToolNode.ts
CHANGED
|
@@ -44,25 +44,52 @@ export const addToolNode = async <Memory>({
|
|
|
44
44
|
description: matchedTool.description,
|
|
45
45
|
schema: matchedTool.input,
|
|
46
46
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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 = `
|
|
55
|
+
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
|
+
}
|
|
69
|
+
`;
|
|
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
|
+
|
|
63
89
|
if (!toolCallMessage || !toolResponseMessage) {
|
|
64
|
-
throw new Error('
|
|
90
|
+
throw new Error('Failed to get tool call or response after multiple attempts');
|
|
65
91
|
}
|
|
92
|
+
|
|
66
93
|
const toolMemory = extractToolMemoryResponse<Memory>(toolResponseMessage);
|
|
67
94
|
return { memory: toolMemory, messages: [toolCallMessage, toolResponseMessage], triggerInvocations: state.triggerInvocations };
|
|
68
95
|
} catch (error) {
|
package/src/platform/config.ts
CHANGED
|
@@ -15,7 +15,7 @@ export const getConfig = (): MindedConfig => {
|
|
|
15
15
|
baseUrl: 'http://localhost:8888',
|
|
16
16
|
env: 'test',
|
|
17
17
|
token: process.env.MINDED_CONNECTION_TOKEN || '',
|
|
18
|
-
runLocally:
|
|
18
|
+
runLocally: process.env.RUN_LOCALLY !== 'false',
|
|
19
19
|
};
|
|
20
20
|
case 'development':
|
|
21
21
|
return {
|
|
@@ -70,6 +70,27 @@ export class MindedConnection {
|
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
+
private async waitForConnection(): Promise<void> {
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
let attempts = 0;
|
|
76
|
+
const maxAttempts = 50;
|
|
77
|
+
const checkInterval = 100;
|
|
78
|
+
|
|
79
|
+
const checkConnection = () => {
|
|
80
|
+
if (this.socket?.connected) {
|
|
81
|
+
resolve();
|
|
82
|
+
} else {
|
|
83
|
+
attempts++;
|
|
84
|
+
if (attempts >= maxAttempts) {
|
|
85
|
+
reject(new Error('Connection failed'));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
setInterval(checkConnection, checkInterval);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
73
94
|
public on = (event: MindedConnectionSocketMessageType, callback: (message: BaseMindedConnectionSocketMessage) => void) => {
|
|
74
95
|
if (!this.listeners[event]) {
|
|
75
96
|
this.listeners[event] = [];
|
|
@@ -83,21 +104,21 @@ export class MindedConnection {
|
|
|
83
104
|
}
|
|
84
105
|
};
|
|
85
106
|
|
|
86
|
-
public awaitEmit = <T, R>(event: MindedConnectionSocketMessageType, message: T, timeoutMs: number = 5000): Promise<R> => {
|
|
87
|
-
|
|
88
|
-
if (!this.socket) {
|
|
89
|
-
reject(new Error('Socket is not connected'));
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
107
|
+
public awaitEmit = async <T, R>(event: MindedConnectionSocketMessageType, message: T, timeoutMs: number = 5000): Promise<R> => {
|
|
108
|
+
await this.waitForConnection();
|
|
92
109
|
|
|
110
|
+
if (!this.socket) {
|
|
111
|
+
throw new Error('Socket is not connected');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return new Promise((resolve, reject) => {
|
|
93
115
|
// Set up timeout
|
|
94
116
|
const timeout = setTimeout(() => {
|
|
95
117
|
reject(new Error(`Acknowledgement timeout after ${timeoutMs}ms`));
|
|
96
118
|
}, timeoutMs);
|
|
97
119
|
|
|
98
120
|
// Emit with acknowledgement callback
|
|
99
|
-
|
|
100
|
-
this.socket.emit(event, stringify(message), (response: any) => {
|
|
121
|
+
this.socket!.emit(event, stringify(message), (response: any) => {
|
|
101
122
|
clearTimeout(timeout);
|
|
102
123
|
|
|
103
124
|
// Check if the response indicates an error
|
|
@@ -14,6 +14,7 @@ export enum MindedConnectionSocketMessageType {
|
|
|
14
14
|
CHECKPOINT_PUT = 'checkpoint-put',
|
|
15
15
|
CHECKPOINT_LIST = 'checkpoint-list',
|
|
16
16
|
CHECKPOINT_PUT_WRITES = 'checkpoint-put-writes',
|
|
17
|
+
GET_SECRETS = 'get-secrets',
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export interface BaseMindedConnectionSocketMessage {
|
package/.github/workflows/CI.yml
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
name: CI
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
branches: [ main ]
|
|
6
|
-
|
|
7
|
-
jobs:
|
|
8
|
-
test:
|
|
9
|
-
runs-on: ubuntu-latest
|
|
10
|
-
|
|
11
|
-
steps:
|
|
12
|
-
- name: Checkout code
|
|
13
|
-
uses: actions/checkout@v4
|
|
14
|
-
|
|
15
|
-
- name: Use Node.js 20.x
|
|
16
|
-
uses: actions/setup-node@v4
|
|
17
|
-
with:
|
|
18
|
-
node-version: 20.x
|
|
19
|
-
cache: 'npm'
|
|
20
|
-
|
|
21
|
-
- name: Install dependencies
|
|
22
|
-
run: npm ci
|
|
23
|
-
|
|
24
|
-
- name: Build project
|
|
25
|
-
run: npm run build
|
|
26
|
-
|
|
27
|
-
- name: Run lint
|
|
28
|
-
run: npm run lint
|
|
29
|
-
|
|
30
|
-
- name: Run tests
|
|
31
|
-
run: npm test
|
|
32
|
-
env:
|
|
33
|
-
NODE_ENV: test
|
|
34
|
-
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
package/.prettierrc
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
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[], name: string, appName: string, awaitEmit: (event: MindedConnectionSocketMessageType, payload: any) => Promise<any>) => Tool<any, any>;
|
|
5
|
-
export declare const getAppActionRunnerTool: (appName: string, actionName: string) => Tool<any, any>;
|
|
6
|
-
export default appActionRunnerToolCreator;
|
|
@@ -1,55 +0,0 @@
|
|
|
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 sanitizeName = (name) => {
|
|
24
|
-
return name.replace(/[^a-zA-Z0-9_-]/g, '-');
|
|
25
|
-
};
|
|
26
|
-
const createdTools = {};
|
|
27
|
-
const appActionRunnerToolCreator = (schema, name, appName, awaitEmit) => {
|
|
28
|
-
const zodSchema = convertToZodSchema(schema.reduce((acc, param) => {
|
|
29
|
-
acc[param.name] = param.type;
|
|
30
|
-
return acc;
|
|
31
|
-
}, {}));
|
|
32
|
-
const tool = {
|
|
33
|
-
name: `${sanitizeName(appName)}-${sanitizeName(name)}`,
|
|
34
|
-
description: `Run ${name} action from ${appName}`,
|
|
35
|
-
input: zodSchema,
|
|
36
|
-
execute: async ({ input }) => {
|
|
37
|
-
console.log('*Action: App action runner*');
|
|
38
|
-
console.log('input', input);
|
|
39
|
-
const response = await awaitEmit(mindedConnectionTypes_1.MindedConnectionSocketMessageType.OnAppAction, {
|
|
40
|
-
appName,
|
|
41
|
-
actionName: name,
|
|
42
|
-
actionInput: input,
|
|
43
|
-
});
|
|
44
|
-
return response;
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
createdTools[`${appName}-${name}`] = tool;
|
|
48
|
-
return tool;
|
|
49
|
-
};
|
|
50
|
-
const getAppActionRunnerTool = (appName, actionName) => {
|
|
51
|
-
return createdTools[`${appName}-${actionName}`];
|
|
52
|
-
};
|
|
53
|
-
exports.getAppActionRunnerTool = getAppActionRunnerTool;
|
|
54
|
-
exports.default = appActionRunnerToolCreator;
|
|
55
|
-
//# sourceMappingURL=appActionRunnerTool.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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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G,IAAI,CAAC;IAC1C,OAAO,IAAI,CAAC;AAChB,CAAC,CAAA;AAEM,MAAM,sBAAsB,GAAG,CAAC,OAAe,EAAE,UAAkB,EAAE,EAAE;IAC1E,OAAO,YAAY,CAAC,GAAG,OAAO,IAAI,UAAU,EAAE,CAAC,CAAC;AACpD,CAAC,CAAA;AAFY,QAAA,sBAAsB,0BAElC;AAED,kBAAe,0BAA0B,CAAC"}
|
|
@@ -1,11 +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
|
-
declare const actionRunnerTool: <Memory>(matchedTool: Tool<any, Memory>, toolNode: ToolNode | AppToolNode, llm: BaseLanguageModel, addedPrompt?: string) => (state: typeof stateAnnotation.State) => Promise<{
|
|
7
|
-
memory: {};
|
|
8
|
-
messages: (BaseMessage | ToolMessage)[];
|
|
9
|
-
triggerInvocations: import("..").TriggerInvocationHistory[];
|
|
10
|
-
}>;
|
|
11
|
-
export default actionRunnerTool;
|
|
@@ -1,84 +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) => {
|
|
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
|
-
${addedPrompt && `Additional instructions: ${addedPrompt}`}
|
|
36
|
-
`;
|
|
37
|
-
const toolCallingAgent = (0, prebuilt_1.createReactAgent)({
|
|
38
|
-
checkpointer: new langgraph_1.MemorySaver(),
|
|
39
|
-
llm,
|
|
40
|
-
tools: [tool],
|
|
41
|
-
});
|
|
42
|
-
const response = await toolCallingAgent.invoke({ messages: [new messages_1.SystemMessage(prompt)] }, { configurable: { thread_id: (0, uuid_1.v4)() } });
|
|
43
|
-
console.log('response', JSON.stringify({ response, matchedTool, toolNode, tool }, null, 2));
|
|
44
|
-
const toolCallMessage = getLastToolCallMessage(response.messages);
|
|
45
|
-
const toolResponseMessage = getLastToolMessage(response.messages);
|
|
46
|
-
if (!toolCallMessage || !toolResponseMessage) {
|
|
47
|
-
throw new Error('Tool call or tool response message not found');
|
|
48
|
-
}
|
|
49
|
-
let toolMemory = {};
|
|
50
|
-
if (toolNode.type === Flows_types_1.NodeType.APP_TOOL) {
|
|
51
|
-
toolMemory = extractToolMemoryResponse(toolResponseMessage);
|
|
52
|
-
}
|
|
53
|
-
return { memory: toolMemory, messages: [toolCallMessage, toolResponseMessage], triggerInvocations: state.triggerInvocations };
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
console.error('Error executing tool node', error);
|
|
57
|
-
throw error;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
exports.default = actionRunnerTool;
|
|
62
|
-
const getLastToolCallMessage = (messages) => {
|
|
63
|
-
const toolCallMessages = messages.filter((message) => { var _a; return ((_a = message.tool_calls) === null || _a === void 0 ? void 0 : _a.length) || 0 > 0; });
|
|
64
|
-
const lastToolCallMessage = toolCallMessages[toolCallMessages.length - 1];
|
|
65
|
-
return lastToolCallMessage;
|
|
66
|
-
};
|
|
67
|
-
const getLastToolMessage = (messages) => {
|
|
68
|
-
const toolMessages = messages.filter((message) => message.getType() === 'tool');
|
|
69
|
-
const lastToolMessage = toolMessages[toolMessages.length - 1];
|
|
70
|
-
return lastToolMessage;
|
|
71
|
-
};
|
|
72
|
-
const extractToolMemoryResponse = (toolMessage) => {
|
|
73
|
-
try {
|
|
74
|
-
const parsed = JSON.parse(toolMessage.content);
|
|
75
|
-
if (typeof parsed === 'object' && parsed !== null && 'memory' in parsed) {
|
|
76
|
-
return parsed.memory;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
catch (error) {
|
|
80
|
-
console.error('Error parsing tool memory response', error);
|
|
81
|
-
}
|
|
82
|
-
return {};
|
|
83
|
-
};
|
|
84
|
-
//# 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;AAE9D,MAAM,gBAAgB,GAAG,CAAS,WAA8B,EAAE,QAAgC,EAAE,G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AAQ,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"}
|
|
@@ -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"}
|
|
@@ -1,8 +0,0 @@
|
|
|
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;
|
|
@@ -1,29 +0,0 @@
|
|
|
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 actionRunnerTool_1 = __importDefault(require("./actionRunnerTool"));
|
|
8
|
-
const appActionRunnerTool_1 = require("../internalTools/appActionRunnerTool");
|
|
9
|
-
const addAppToolNode = ({ graph, node, llm, }) => {
|
|
10
|
-
const appRunnerTool = (0, appActionRunnerTool_1.getAppActionRunnerTool)(node.appName, node.metadata.name);
|
|
11
|
-
const addedPrompt = `
|
|
12
|
-
You are executing the app tool "${node.appName}" with action "${node.metadata.name}".
|
|
13
|
-
The tool requires the following parameters:
|
|
14
|
-
${node.metadata.schema.map(param => `
|
|
15
|
-
- ${param.name} (${param.type}): ${param.description}
|
|
16
|
-
${param.example ? `Example: ${param.example}` : ''}
|
|
17
|
-
${param.enum ? `Allowed values: ${param.enum.join(', ')}` : ''}
|
|
18
|
-
${param.items ? `Array items type: ${param.items.type}` : ''}
|
|
19
|
-
`).join('\n')}
|
|
20
|
-
|
|
21
|
-
Please analyze the conversation context and workflow memory to determine the appropriate values for these parameters.
|
|
22
|
-
Ensure all required parameters are provided and values match the specified types and constraints.
|
|
23
|
-
If any parameter is unclear from the context, ask for clarification.
|
|
24
|
-
`;
|
|
25
|
-
const callback = (0, actionRunnerTool_1.default)(appRunnerTool, node, llm, addedPrompt);
|
|
26
|
-
graph.addNode(node.name, callback);
|
|
27
|
-
};
|
|
28
|
-
exports.addAppToolNode = addAppToolNode;
|
|
29
|
-
//# sourceM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/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 = callToolRunner;
|
|
57
|
-
//# sourceMappingURL=callTool.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,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