@minded-ai/mindedjs 1.0.95-beta-2 → 1.0.95
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 +1 -4
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +29 -72
- package/dist/agent.js.map +1 -1
- package/dist/cli/index.js +12 -12
- package/dist/cli/index.js.map +1 -1
- package/dist/edges/createDirectEdge.js +1 -1
- package/dist/edges/createDirectEdge.js.map +1 -1
- package/dist/edges/createLogicalRouter.d.ts.map +1 -1
- package/dist/edges/createLogicalRouter.js +7 -7
- package/dist/edges/createLogicalRouter.js.map +1 -1
- package/dist/edges/createPromptRouter.d.ts.map +1 -1
- package/dist/edges/createPromptRouter.js +3 -4
- package/dist/edges/createPromptRouter.js.map +1 -1
- package/dist/edges/edgeFactory.js +2 -2
- package/dist/edges/edgeFactory.js.map +1 -1
- package/dist/nodes/addAppToolNode.js +1 -1
- package/dist/nodes/addAppToolNode.js.map +1 -1
- package/dist/nodes/addHumanInTheLoopNode.d.ts.map +1 -1
- package/dist/nodes/addHumanInTheLoopNode.js +2 -3
- package/dist/nodes/addHumanInTheLoopNode.js.map +1 -1
- package/dist/nodes/addJumpToNode.js +1 -1
- package/dist/nodes/addJumpToNode.js.map +1 -1
- package/dist/nodes/addPromptNode.d.ts.map +1 -1
- package/dist/nodes/addPromptNode.js +1 -45
- package/dist/nodes/addPromptNode.js.map +1 -1
- package/dist/nodes/addToolNode.d.ts.map +1 -1
- package/dist/nodes/addToolNode.js +1 -4
- package/dist/nodes/addToolNode.js.map +1 -1
- package/dist/nodes/addToolRunNode.d.ts.map +1 -1
- package/dist/nodes/addToolRunNode.js +0 -1
- package/dist/nodes/addToolRunNode.js.map +1 -1
- package/dist/nodes/addTriggerNode.js +1 -1
- package/dist/nodes/addTriggerNode.js.map +1 -1
- package/dist/platform/mindedConnection.d.ts.map +1 -1
- package/dist/platform/mindedConnection.js +12 -12
- package/dist/platform/mindedConnection.js.map +1 -1
- package/dist/platform/mindedConnectionTypes.d.ts +1 -162
- package/dist/platform/mindedConnectionTypes.d.ts.map +1 -1
- package/dist/platform/mindedConnectionTypes.js +0 -10
- package/dist/platform/mindedConnectionTypes.js.map +1 -1
- package/dist/playbooks/playbooks.js +4 -4
- package/dist/playbooks/playbooks.js.map +1 -1
- package/dist/types/Agent.types.d.ts +0 -2
- package/dist/types/Agent.types.d.ts.map +1 -1
- package/dist/types/Agent.types.js.map +1 -1
- package/dist/types/LangGraph.types.d.ts +4 -2
- package/dist/types/LangGraph.types.d.ts.map +1 -1
- package/dist/types/LangGraph.types.js +5 -3
- package/dist/types/LangGraph.types.js.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +0 -1
- package/dist/utils/logger.js.map +1 -1
- package/dist/voice/voiceSession.d.ts.map +1 -1
- package/dist/voice/voiceSession.js +3 -2
- package/dist/voice/voiceSession.js.map +1 -1
- package/package.json +1 -1
- package/src/agent.ts +34 -90
- package/src/cli/index.ts +12 -12
- package/src/edges/createDirectEdge.ts +1 -1
- package/src/edges/createLogicalRouter.ts +8 -7
- package/src/edges/createPromptRouter.ts +3 -4
- package/src/edges/edgeFactory.ts +2 -2
- package/src/nodes/addAppToolNode.ts +1 -1
- package/src/nodes/addHumanInTheLoopNode.ts +3 -3
- package/src/nodes/addJumpToNode.ts +1 -1
- package/src/nodes/addPromptNode.ts +6 -51
- package/src/nodes/addToolNode.ts +2 -4
- package/src/nodes/addToolRunNode.ts +1 -1
- package/src/nodes/addTriggerNode.ts +1 -1
- package/src/platform/mindedConnection.ts +25 -15
- package/src/platform/mindedConnectionTypes.ts +1 -202
- package/src/playbooks/playbooks.ts +4 -4
- package/src/types/Agent.types.ts +0 -2
- package/src/types/LangGraph.types.ts +5 -3
- package/src/utils/logger.ts +0 -1
- package/src/voice/voiceSession.ts +4 -7
- package/dist/interrupts/BaseInterruptSessionManager.d.ts +0 -36
- package/dist/interrupts/BaseInterruptSessionManager.d.ts.map +0 -1
- package/dist/interrupts/BaseInterruptSessionManager.js +0 -39
- package/dist/interrupts/BaseInterruptSessionManager.js.map +0 -1
- package/dist/interrupts/InterruptSessionManager.types.d.ts +0 -36
- package/dist/interrupts/InterruptSessionManager.types.d.ts.map +0 -1
- package/dist/interrupts/InterruptSessionManager.types.js +0 -40
- package/dist/interrupts/InterruptSessionManager.types.js.map +0 -1
- package/dist/interrupts/MemoryInterruptSessionManager.d.ts +0 -14
- package/dist/interrupts/MemoryInterruptSessionManager.d.ts.map +0 -1
- package/dist/interrupts/MemoryInterruptSessionManager.js +0 -56
- package/dist/interrupts/MemoryInterruptSessionManager.js.map +0 -1
- package/dist/interrupts/MindedInterruptSessionManager.d.ts +0 -14
- package/dist/interrupts/MindedInterruptSessionManager.d.ts.map +0 -1
- package/dist/interrupts/MindedInterruptSessionManager.js +0 -168
- package/dist/interrupts/MindedInterruptSessionManager.js.map +0 -1
- package/dist/interrupts/interruptSessionManagerFactory.d.ts +0 -3
- package/dist/interrupts/interruptSessionManagerFactory.d.ts.map +0 -1
- package/dist/interrupts/interruptSessionManagerFactory.js +0 -56
- package/dist/interrupts/interruptSessionManagerFactory.js.map +0 -1
- package/src/interrupts/BaseInterruptSessionManager.ts +0 -79
- package/src/interrupts/MemoryInterruptSessionManager.ts +0 -57
- package/src/interrupts/MindedInterruptSessionManager.ts +0 -172
- package/src/interrupts/interruptSessionManagerFactory.ts +0 -20
|
@@ -11,8 +11,8 @@ export const createLogicalRouter = ({ edges }: { edges: LogicalConditionEdge[] }
|
|
|
11
11
|
logger.debug(`Evaluating logical conditions for ${edges.length} edges`);
|
|
12
12
|
|
|
13
13
|
// Separate regular conditions from "else" conditions
|
|
14
|
-
const regularEdges = edges.filter(
|
|
15
|
-
const elseEdges = edges.filter(
|
|
14
|
+
const regularEdges = edges.filter(edge => edge.condition.trim() !== 'else');
|
|
15
|
+
const elseEdges = edges.filter(edge => edge.condition.trim() === 'else');
|
|
16
16
|
|
|
17
17
|
// First, evaluate all regular conditions
|
|
18
18
|
for (const edge of regularEdges) {
|
|
@@ -59,16 +59,17 @@ export const createLogicalRouter = ({ edges }: { edges: LogicalConditionEdge[] }
|
|
|
59
59
|
]);
|
|
60
60
|
|
|
61
61
|
if (result === true) {
|
|
62
|
-
logger.info(
|
|
62
|
+
logger.info(`Condition matched for edge ${edge.source} → ${edge.target}`);
|
|
63
63
|
return edge.target;
|
|
64
64
|
}
|
|
65
|
+
|
|
65
66
|
} catch (error) {
|
|
66
67
|
// Provide detailed error information back to the customer
|
|
67
68
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
68
69
|
const conditionPreview = edge.condition.length > 100 ? `${edge.condition.substring(0, 100)}...` : edge.condition;
|
|
69
70
|
|
|
70
71
|
logger.error({
|
|
71
|
-
|
|
72
|
+
msg: `Error evaluating condition for edge ${edge.source} → ${edge.target}`,
|
|
72
73
|
condition: conditionPreview,
|
|
73
74
|
error: errorMessage,
|
|
74
75
|
edgeIndex: edges.indexOf(edge),
|
|
@@ -83,15 +84,15 @@ export const createLogicalRouter = ({ edges }: { edges: LogicalConditionEdge[] }
|
|
|
83
84
|
|
|
84
85
|
// If no regular conditions matched, check for "else" conditions
|
|
85
86
|
if (elseEdges.length > 0) {
|
|
86
|
-
logger.info(
|
|
87
|
+
logger.info(`No regular conditions matched, evaluating ${elseEdges.length} else condition(s)`);
|
|
87
88
|
// Return the first "else" condition's target
|
|
88
89
|
const elseEdge = elseEdges[0];
|
|
89
|
-
logger.info(
|
|
90
|
+
logger.info(`Else condition matched for edge ${elseEdge.source} → ${elseEdge.target}`);
|
|
90
91
|
return elseEdge.target;
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
// If no conditions matched or all failed, return to the source node
|
|
94
|
-
logger.info(
|
|
95
|
+
logger.info('No conditions matched');
|
|
95
96
|
return null;
|
|
96
97
|
};
|
|
97
98
|
};
|
|
@@ -70,11 +70,11 @@ export const createPromptRouter = ({
|
|
|
70
70
|
currentNodeName?: string;
|
|
71
71
|
}) => {
|
|
72
72
|
return async (state: typeof stateAnnotation.State) => {
|
|
73
|
-
logger.info(
|
|
73
|
+
logger.info(`Executing prompt router. Edges: ${JSON.stringify(edges)}`);
|
|
74
74
|
|
|
75
75
|
// If canStayInCurrentNode is true and there are no edges, return current node immediately
|
|
76
76
|
if (canStayInCurrentNode && edges.length === 0 && currentNodeName) {
|
|
77
|
-
logger.info(
|
|
77
|
+
logger.info(`No edges available and canStayInCurrentNode is true, staying in current node: ${currentNodeName}`);
|
|
78
78
|
return currentNodeName;
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -174,14 +174,13 @@ export const createPromptRouter = ({
|
|
|
174
174
|
|
|
175
175
|
const decision = validatedResponse.nextNodeId === currentNodeName ? 'stay in current node' : validatedResponse.nextNodeId;
|
|
176
176
|
const reasoning = includeReasoning && 'reasoning' in validatedResponse ? ` - Reasoning: ${validatedResponse.reasoning}` : '';
|
|
177
|
-
logger.info({
|
|
177
|
+
logger.info({ msg: `Router decision: ${decision}`, reasoning });
|
|
178
178
|
|
|
179
179
|
return validatedResponse.nextNodeId;
|
|
180
180
|
} catch (error) {
|
|
181
181
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
182
182
|
logger.warn({
|
|
183
183
|
message: `Prompt router attempt ${attempts} failed`,
|
|
184
|
-
edge: edges,
|
|
185
184
|
error: lastError.message,
|
|
186
185
|
attempt: attempts,
|
|
187
186
|
maxRetries,
|
package/src/edges/edgeFactory.ts
CHANGED
|
@@ -49,7 +49,7 @@ export const edgeFactory = ({
|
|
|
49
49
|
if (result) {
|
|
50
50
|
return result;
|
|
51
51
|
} else {
|
|
52
|
-
logger.debug(
|
|
52
|
+
logger.debug('No logical conditions matched, continuing to prompt conditions');
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -69,7 +69,7 @@ export const edgeFactory = ({
|
|
|
69
69
|
|
|
70
70
|
// Fallback: stay at current source node
|
|
71
71
|
const source = originalNode?.name || sourceNode;
|
|
72
|
-
logger.info(
|
|
72
|
+
logger.info(`No conditions matched, returning to source: ${source}`);
|
|
73
73
|
return source;
|
|
74
74
|
};
|
|
75
75
|
};
|
|
@@ -26,7 +26,7 @@ export const addAppToolNode = async ({
|
|
|
26
26
|
const cleanedParameters = Object.fromEntries(Object.entries(node.parameters || {}).filter(([, value]) => value !== ''));
|
|
27
27
|
const appRunnerTool = getAppActionRunnerTool(node.displayName!);
|
|
28
28
|
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
29
|
-
logger.info(
|
|
29
|
+
logger.info(`Executing tool node ${appRunnerTool.name}`);
|
|
30
30
|
|
|
31
31
|
const executeWrapper = async (input: z.infer<typeof appRunnerTool.input>) => {
|
|
32
32
|
try {
|
|
@@ -3,7 +3,6 @@ import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
|
|
|
3
3
|
import { RunnableLike } from '@langchain/core/runnables';
|
|
4
4
|
import { logger } from '../utils/logger';
|
|
5
5
|
import { internalNodesSuffix } from '../types/Flows.types';
|
|
6
|
-
import { InterruptType } from '../interrupts/BaseInterruptSessionManager';
|
|
7
6
|
|
|
8
7
|
type AddHumanInTheLoopNodeParams = {
|
|
9
8
|
graph: PreCompiledGraph;
|
|
@@ -14,9 +13,10 @@ export const buildHumanInTheLoopNodeName = (nodeName: string) => `${nodeName}${i
|
|
|
14
13
|
|
|
15
14
|
export const addHumanInTheLoopNode = async ({ graph, attachedToNodeName }: AddHumanInTheLoopNodeParams) => {
|
|
16
15
|
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
17
|
-
logger.info(
|
|
16
|
+
logger.info(`Executing "human in the loop" node for the attached node${attachedToNodeName}`);
|
|
17
|
+
|
|
18
18
|
if (state.messages[state.messages.length - 1].getType() === 'ai') {
|
|
19
|
-
const value = interrupt(
|
|
19
|
+
const value = interrupt('input from human in the loop');
|
|
20
20
|
return value;
|
|
21
21
|
}
|
|
22
22
|
};
|
|
@@ -7,7 +7,7 @@ import { createHistoryStep } from '../utils/history';
|
|
|
7
7
|
|
|
8
8
|
export const addJumpToNode = async ({ graph, node }: { graph: PreCompiledGraph; node: JumpToNode }) => {
|
|
9
9
|
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
10
|
-
logger.info(
|
|
10
|
+
logger.info(`Executing jump node ${node.displayName} – jumping to ${node.targetNodeId}`);
|
|
11
11
|
// No state modifications are necessary; control flow is handled via edges.
|
|
12
12
|
return {
|
|
13
13
|
history: createHistoryStep<HistoryStep>(state.history, {
|
|
@@ -14,8 +14,7 @@ import { Agent } from '../agent';
|
|
|
14
14
|
import { logger } from '../utils/logger';
|
|
15
15
|
import { compilePlaybooks } from '../playbooks/playbooks';
|
|
16
16
|
import { createHistoryStep } from '../utils/history';
|
|
17
|
-
|
|
18
|
-
import { wait } from '../utils/wait';
|
|
17
|
+
|
|
19
18
|
type AddPromptNodeParams = {
|
|
20
19
|
graph: PreCompiledGraph;
|
|
21
20
|
node: PromptNode;
|
|
@@ -27,8 +26,7 @@ type AddPromptNodeParams = {
|
|
|
27
26
|
|
|
28
27
|
export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: AddPromptNodeParams) => {
|
|
29
28
|
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
30
|
-
|
|
31
|
-
logger.info({ message: `Executing prompt node ${node.displayName}` });
|
|
29
|
+
logger.info(`Executing prompt node ${node.displayName}`);
|
|
32
30
|
const llmToUse = node.llmConfig ? createLlmInstance(node.llmConfig) : llm;
|
|
33
31
|
|
|
34
32
|
const globalTools = tools
|
|
@@ -52,9 +50,9 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
|
|
|
52
50
|
${state.memory ? `# Task context:\n${JSON.stringify(state.memory)}\n\n` : ''}
|
|
53
51
|
${compiledPlaybooks ? `# General guidelines:\n${compiledPlaybooks}\n\n` : ''}
|
|
54
52
|
`;
|
|
55
|
-
|
|
53
|
+
|
|
56
54
|
const result: AIMessage = await llmToUse.bindTools(globalTools).invoke([...state.messages, new SystemMessage(message)]);
|
|
57
|
-
|
|
55
|
+
|
|
58
56
|
// Check if the result contains tool calls
|
|
59
57
|
if (result.tool_calls && result.tool_calls.length > 0) {
|
|
60
58
|
// Execute the tools
|
|
@@ -68,29 +66,6 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
|
|
|
68
66
|
try {
|
|
69
67
|
// Invoke the LangChain tool directly
|
|
70
68
|
const toolResult = await matchedTool.invoke(toolCall);
|
|
71
|
-
//check for queue after tool call
|
|
72
|
-
const systemMessageId = uuidv4();
|
|
73
|
-
|
|
74
|
-
await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, {
|
|
75
|
-
messages: [
|
|
76
|
-
result,
|
|
77
|
-
toolResult,
|
|
78
|
-
new SystemMessage({
|
|
79
|
-
id: systemMessageId,
|
|
80
|
-
content:
|
|
81
|
-
'you called tool when the user send a new message, Consider calling the function again after user message is processed',
|
|
82
|
-
}),
|
|
83
|
-
],
|
|
84
|
-
history: [
|
|
85
|
-
createHistoryStep<HistoryStep>(state.history, {
|
|
86
|
-
type: NodeType.TOOL,
|
|
87
|
-
nodeId: node.name,
|
|
88
|
-
nodeDisplayName: node.displayName,
|
|
89
|
-
raw: toolResult,
|
|
90
|
-
messageIds: [toolResult.id!, systemMessageId],
|
|
91
|
-
}),
|
|
92
|
-
],
|
|
93
|
-
});
|
|
94
69
|
const toolStateUpdate = extractToolStateResponse(toolResult);
|
|
95
70
|
// Properly merge memory and other state updates
|
|
96
71
|
stateUpdates = {
|
|
@@ -99,8 +74,7 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
|
|
|
99
74
|
memory: { ...(stateUpdates as any).memory, ...(toolStateUpdate as any).memory },
|
|
100
75
|
};
|
|
101
76
|
toolResults.push(toolResult);
|
|
102
|
-
} catch (error
|
|
103
|
-
if (error?.name === 'GraphInterrupt') throw error;
|
|
77
|
+
} catch (error) {
|
|
104
78
|
logger.error({ msg: `Error executing tool ${toolCall.name}:`, error });
|
|
105
79
|
const errorMessage = new ToolMessage({
|
|
106
80
|
content: JSON.stringify({ error: error instanceof Error ? error.message : String(error) }),
|
|
@@ -113,30 +87,10 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
|
|
|
113
87
|
}
|
|
114
88
|
}
|
|
115
89
|
|
|
116
|
-
// await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId);
|
|
117
|
-
|
|
118
90
|
// Return the tool call message and tool results with state updates spread at top level
|
|
119
91
|
return {
|
|
120
92
|
...stateUpdates,
|
|
121
93
|
messages: [result, ...toolResults],
|
|
122
|
-
history: [
|
|
123
|
-
createHistoryStep<HistoryStep>(state.history, {
|
|
124
|
-
type: NodeType.TOOL,
|
|
125
|
-
nodeId: node.name,
|
|
126
|
-
nodeDisplayName: node.displayName,
|
|
127
|
-
raw: result,
|
|
128
|
-
messageIds: [result.id!],
|
|
129
|
-
}),
|
|
130
|
-
...toolResults.map((toolResult) =>
|
|
131
|
-
createHistoryStep<HistoryStep>(state.history, {
|
|
132
|
-
type: NodeType.TOOL,
|
|
133
|
-
nodeId: node.name,
|
|
134
|
-
nodeDisplayName: node.displayName,
|
|
135
|
-
raw: toolResult,
|
|
136
|
-
messageIds: [toolResult.id!],
|
|
137
|
-
}),
|
|
138
|
-
),
|
|
139
|
-
],
|
|
140
94
|
};
|
|
141
95
|
}
|
|
142
96
|
|
|
@@ -147,6 +101,7 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
|
|
|
147
101
|
});
|
|
148
102
|
console.log('AI Message', result.content);
|
|
149
103
|
}
|
|
104
|
+
|
|
150
105
|
return {
|
|
151
106
|
history: createHistoryStep<HistoryStep>(state.history, {
|
|
152
107
|
type: NodeType.PROMPT_NODE,
|
package/src/nodes/addToolNode.ts
CHANGED
|
@@ -30,8 +30,8 @@ export const addToolNode = async ({
|
|
|
30
30
|
throw new Error(`Tool not found: ${toolNode.toolName} in node ${node.name}`);
|
|
31
31
|
}
|
|
32
32
|
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
logger.info(`Executing tool node ${toolNode.displayName}`);
|
|
34
|
+
|
|
35
35
|
const tool = langchainTool(() => {}, {
|
|
36
36
|
name: matchedTool.name,
|
|
37
37
|
description: matchedTool.description,
|
|
@@ -56,8 +56,6 @@ export const addToolNode = async ({
|
|
|
56
56
|
tool_choice: tool.name,
|
|
57
57
|
})
|
|
58
58
|
.invoke([...state.messages, new SystemMessage(prompt)]);
|
|
59
|
-
logger.info({ message: 'after llm tool invoke' });
|
|
60
|
-
await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId);
|
|
61
59
|
return {
|
|
62
60
|
messages: [AIToolCallMessage],
|
|
63
61
|
history: createHistoryStep<HistoryStep>(state.history, {
|
|
@@ -23,7 +23,6 @@ type AddToolRunNodeParams = {
|
|
|
23
23
|
|
|
24
24
|
export const buildToolRunNodeName = (nodeName: string) => `${nodeName}${internalNodesSuffix.TOOL_RUN}`;
|
|
25
25
|
|
|
26
|
-
//you never want to interrupt here because of new triggers, as this node depends on the last message to be the tool call from the addToolNode, interrupting will add human message here
|
|
27
26
|
export const addToolRunNode = async ({ graph, tools, toolNode, attachedToNodeName, agent }: AddToolRunNodeParams) => {
|
|
28
27
|
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
29
28
|
const matchedTool = tools.find((tool) => tool.name === toolNode.toolName);
|
|
@@ -55,6 +54,7 @@ export const addToolRunNode = async ({ graph, tools, toolNode, attachedToNodeNam
|
|
|
55
54
|
|
|
56
55
|
// Push the toolCallMessage into the messages array from toolStateUpdate
|
|
57
56
|
const updatedMessages = [toolCallMessage, ...((toolStateUpdate as any).messages || [])];
|
|
57
|
+
|
|
58
58
|
// Return the full state update from the tool with the updated messages
|
|
59
59
|
return {
|
|
60
60
|
...toolStateUpdate,
|
|
@@ -7,7 +7,7 @@ import { createHistoryStep } from '../utils/history';
|
|
|
7
7
|
|
|
8
8
|
export const addTriggerNode = async ({ graph, node }: { graph: PreCompiledGraph; node: TriggerNode }) => {
|
|
9
9
|
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
10
|
-
logger.info(
|
|
10
|
+
logger.info(`Executing trigger node ${node.displayName}`);
|
|
11
11
|
if (node.triggerType === TriggerType.MANUAL) {
|
|
12
12
|
return {
|
|
13
13
|
history: createHistoryStep<HistoryStep>(state.history, {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { io, Socket } from 'socket.io-client';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
mindedConnectionSocketMessageType,
|
|
4
|
+
mindedConnectionSocketMessageTypeMap,
|
|
5
|
+
} from './mindedConnectionTypes';
|
|
3
6
|
import { stringify } from 'flatted';
|
|
4
7
|
import { getConfig } from './config';
|
|
5
8
|
import { logger } from '../utils/logger';
|
|
@@ -25,13 +28,20 @@ export const on = <E extends keyof mindedConnectionSocketMessageTypeMap>(
|
|
|
25
28
|
listeners[event].push(callback);
|
|
26
29
|
};
|
|
27
30
|
|
|
28
|
-
export const emit = <E extends keyof mindedConnectionSocketMessageTypeMap>(
|
|
31
|
+
export const emit = <E extends keyof mindedConnectionSocketMessageTypeMap>(
|
|
32
|
+
event: E,
|
|
33
|
+
message: mindedConnectionSocketMessageTypeMap[E]
|
|
34
|
+
) => {
|
|
29
35
|
if (socket) {
|
|
30
36
|
socket.emit(event, message);
|
|
31
37
|
}
|
|
32
38
|
};
|
|
33
39
|
|
|
34
|
-
export const awaitEmit = async <T, R>(
|
|
40
|
+
export const awaitEmit = async <T, R>(
|
|
41
|
+
event: mindedConnectionSocketMessageType,
|
|
42
|
+
message: T,
|
|
43
|
+
timeoutMs: number = 5000
|
|
44
|
+
): Promise<R> => {
|
|
35
45
|
if (!socket) {
|
|
36
46
|
throw new Error('Socket is not connected');
|
|
37
47
|
}
|
|
@@ -87,43 +97,43 @@ const connect = async (token: string): Promise<void> => {
|
|
|
87
97
|
|
|
88
98
|
const checkReady = () => {
|
|
89
99
|
if (connected && ready) {
|
|
90
|
-
logger.info(
|
|
91
|
-
logger.info(
|
|
100
|
+
logger.info('\x1b[32mConnection with Minded platform is ready!\x1b[0m');
|
|
101
|
+
logger.info('\x1b[32mPress Ctrl+C to exit...');
|
|
92
102
|
resolve();
|
|
93
103
|
}
|
|
94
104
|
};
|
|
95
105
|
|
|
96
106
|
// Connection event handlers
|
|
97
107
|
socket.on('connect', () => {
|
|
98
|
-
logger.info(
|
|
108
|
+
logger.info('Socket connected, waiting for server setup...');
|
|
99
109
|
connected = true;
|
|
100
110
|
checkReady();
|
|
101
111
|
});
|
|
102
112
|
|
|
103
113
|
// Listen for ready event from server
|
|
104
114
|
socket.on('sdk-socket-ready', (data: { agentId: string; orgName: string }) => {
|
|
105
|
-
logger.info(
|
|
115
|
+
logger.info('Server ready signal received', data);
|
|
106
116
|
ready = true;
|
|
107
117
|
checkReady();
|
|
108
118
|
});
|
|
109
119
|
|
|
110
120
|
socket.on('connect_error', () => {
|
|
111
|
-
logger.error(
|
|
121
|
+
logger.error('Failed to connect to minded platform');
|
|
112
122
|
reject(new Error('Failed to connect to minded platform'));
|
|
113
123
|
});
|
|
114
124
|
|
|
115
125
|
socket.on('disconnect', () => {
|
|
116
|
-
logger.info(
|
|
126
|
+
logger.info('Disconnected from local debugging socket');
|
|
117
127
|
connected = false;
|
|
118
128
|
ready = false;
|
|
119
129
|
});
|
|
120
130
|
|
|
121
131
|
// Listen for error messages from the server
|
|
122
132
|
socket.on('error', async (error: { message: string }) => {
|
|
123
|
-
logger.error({
|
|
133
|
+
logger.error({ msg: 'Server error:', error });
|
|
124
134
|
|
|
125
135
|
if (error.message.includes('Invalid token')) {
|
|
126
|
-
logger.info(
|
|
136
|
+
logger.info('Invalid token');
|
|
127
137
|
|
|
128
138
|
// Disconnect current socket
|
|
129
139
|
if (socket?.connected) {
|
|
@@ -149,7 +159,7 @@ const connect = async (token: string): Promise<void> => {
|
|
|
149
159
|
// Handle process termination
|
|
150
160
|
process.on('SIGINT', () => {
|
|
151
161
|
if (socket?.connected) {
|
|
152
|
-
logger.info(
|
|
162
|
+
logger.info('\nDisconnecting...');
|
|
153
163
|
socket.disconnect();
|
|
154
164
|
}
|
|
155
165
|
process.exit(0);
|
|
@@ -167,17 +177,17 @@ export const start = async (): Promise<void> => {
|
|
|
167
177
|
|
|
168
178
|
export const disconnect = () => {
|
|
169
179
|
if (!socket) {
|
|
170
|
-
logger.warn(
|
|
180
|
+
logger.warn('No socket connection to disconnect');
|
|
171
181
|
return;
|
|
172
182
|
}
|
|
173
183
|
|
|
174
184
|
if (socket.connected) {
|
|
175
|
-
logger.info(
|
|
185
|
+
logger.info('Disconnecting from Minded platform...');
|
|
176
186
|
socket.disconnect();
|
|
177
187
|
return;
|
|
178
188
|
}
|
|
179
189
|
|
|
180
|
-
logger.warn(
|
|
190
|
+
logger.warn('Socket is already disconnected');
|
|
181
191
|
};
|
|
182
192
|
|
|
183
193
|
export const mindedConnection = {
|
|
@@ -33,16 +33,6 @@ export enum mindedConnectionSocketMessageType {
|
|
|
33
33
|
TIMER_RESET = 'timer-reset',
|
|
34
34
|
TIMER_CANCEL = 'timer-cancel',
|
|
35
35
|
TIMER_TRIGGER = 'timer-trigger',
|
|
36
|
-
// Interrupt Session Management
|
|
37
|
-
INTERRUPT_SESSION_IS_PROCESSED = 'interrupt-session-is-processed',
|
|
38
|
-
INTERRUPT_SESSION_LOCK = 'interrupt-session-lock',
|
|
39
|
-
INTERRUPT_SESSION_TRY_LOCK = 'interrupt-session-try-lock',
|
|
40
|
-
INTERRUPT_SESSION_RELEASE = 'interrupt-session-release',
|
|
41
|
-
INTERRUPT_SESSION_ENQUEUE = 'interrupt-session-enqueue',
|
|
42
|
-
INTERRUPT_SESSION_DEQUEUE_ALL = 'interrupt-session-dequeue-all',
|
|
43
|
-
INTERRUPT_SESSION_DEQUEUE = 'interrupt-session-dequeue',
|
|
44
|
-
INTERRUPT_SESSION_HAS_MESSAGES = 'interrupt-session-has-messages',
|
|
45
|
-
INTERRUPT_SESSION_GET_MESSAGES = 'interrupt-session-get-messages',
|
|
46
36
|
}
|
|
47
37
|
|
|
48
38
|
export type mindedConnectionSocketMessageTypeMap = {
|
|
@@ -67,16 +57,6 @@ export type mindedConnectionSocketMessageTypeMap = {
|
|
|
67
57
|
[mindedConnectionSocketMessageType.TIMER_CANCEL]: TimerCancelRequest;
|
|
68
58
|
[mindedConnectionSocketMessageType.TIMER_TRIGGER]: TimerTriggerRequest;
|
|
69
59
|
[mindedConnectionSocketMessageType.RESTORE_CHECKPOINT]: RestoreCheckpointRequest;
|
|
70
|
-
// Interrupt Session Management
|
|
71
|
-
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_IS_PROCESSED]: InterruptSessionIsProcessedRequest;
|
|
72
|
-
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_LOCK]: InterruptSessionLockRequest;
|
|
73
|
-
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_TRY_LOCK]: InterruptSessionTryLockRequest;
|
|
74
|
-
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_RELEASE]: InterruptSessionReleaseRequest;
|
|
75
|
-
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_ENQUEUE]: InterruptSessionEnqueueRequest;
|
|
76
|
-
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_DEQUEUE_ALL]: InterruptSessionDequeueAllRequest;
|
|
77
|
-
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_DEQUEUE]: InterruptSessionDequeueRequest;
|
|
78
|
-
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_HAS_MESSAGES]: InterruptSessionHasMessagesRequest;
|
|
79
|
-
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_GET_MESSAGES]: InterruptSessionGetMessagesRequest;
|
|
80
60
|
};
|
|
81
61
|
|
|
82
62
|
export interface BasemindedConnectionSocketMessage {
|
|
@@ -201,187 +181,6 @@ export interface TimerTriggerRequest extends BasemindedConnectionSocketMessage {
|
|
|
201
181
|
eventArgs: Record<string, any>;
|
|
202
182
|
}
|
|
203
183
|
|
|
204
|
-
// Interrupt Session Management Interfaces
|
|
205
|
-
export interface InterruptSessionIsProcessedRequest extends BasemindedConnectionSocketMessage {
|
|
206
|
-
sessionId: string;
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
export interface InterruptSessionIsProcessedResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
210
|
-
isProcessed?: boolean;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
export interface InterruptSessionLockRequest extends BasemindedConnectionSocketMessage {
|
|
214
|
-
sessionId: string;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
export interface InterruptSessionLockResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
218
|
-
success?: boolean;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
export interface InterruptSessionTryLockRequest extends BasemindedConnectionSocketMessage {
|
|
222
|
-
sessionId: string;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
export interface InterruptSessionTryLockResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
226
|
-
lockAcquired?: boolean;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
export interface InterruptSessionReleaseRequest extends BasemindedConnectionSocketMessage {
|
|
230
|
-
sessionId: string;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export interface InterruptSessionReleaseResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
234
|
-
success?: boolean;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
export interface InterruptSessionEnqueueRequest extends BasemindedConnectionSocketMessage {
|
|
238
|
-
sessionId: string;
|
|
239
|
-
message: {
|
|
240
|
-
triggerBody: any;
|
|
241
|
-
triggerName: string;
|
|
242
|
-
appName?: string;
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
export interface InterruptSessionEnqueueResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
247
|
-
success?: boolean;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export interface InterruptSessionDequeueAllRequest extends BasemindedConnectionSocketMessage {
|
|
251
|
-
sessionId: string;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export interface InterruptSessionDequeueAllResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
255
|
-
messages?: Array<{
|
|
256
|
-
triggerBody: any;
|
|
257
|
-
triggerName: string;
|
|
258
|
-
appName?: string;
|
|
259
|
-
}>;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
export interface InterruptSessionDequeueRequest extends BasemindedConnectionSocketMessage {
|
|
263
|
-
sessionId: string;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
export interface InterruptSessionDequeueResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
267
|
-
message?: {
|
|
268
|
-
triggerBody: any;
|
|
269
|
-
triggerName: string;
|
|
270
|
-
appName?: string;
|
|
271
|
-
} | null;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
export interface InterruptSessionHasMessagesRequest extends BasemindedConnectionSocketMessage {
|
|
275
|
-
sessionId: string;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export interface InterruptSessionHasMessagesResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
279
|
-
hasMessages?: boolean;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
export interface InterruptSessionGetMessagesRequest extends BasemindedConnectionSocketMessage {
|
|
283
|
-
sessionId: string;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
export interface InterruptSessionGetMessagesResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
287
|
-
messages?: Array<{
|
|
288
|
-
triggerBody: any;
|
|
289
|
-
triggerName: string;
|
|
290
|
-
appName?: string;
|
|
291
|
-
}>;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// Interrupt Session Management Interfaces
|
|
295
|
-
export interface InterruptSessionIsProcessedRequest extends BasemindedConnectionSocketMessage {
|
|
296
|
-
sessionId: string;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
export interface InterruptSessionIsProcessedResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
300
|
-
isProcessed?: boolean;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
export interface InterruptSessionLockRequest extends BasemindedConnectionSocketMessage {
|
|
304
|
-
sessionId: string;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
export interface InterruptSessionLockResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
308
|
-
success?: boolean;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
export interface InterruptSessionReleaseRequest extends BasemindedConnectionSocketMessage {
|
|
312
|
-
sessionId: string;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
export interface InterruptSessionReleaseResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
316
|
-
success?: boolean;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
export interface InterruptSessionEnqueueRequest extends BasemindedConnectionSocketMessage {
|
|
320
|
-
sessionId: string;
|
|
321
|
-
message: {
|
|
322
|
-
triggerBody: any;
|
|
323
|
-
triggerName: string;
|
|
324
|
-
appName?: string;
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
export interface InterruptSessionEnqueueResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
329
|
-
success?: boolean;
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
export interface InterruptSessionDequeueAllRequest extends BasemindedConnectionSocketMessage {
|
|
333
|
-
sessionId: string;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
export interface InterruptSessionDequeueAllResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
337
|
-
messages?: Array<{
|
|
338
|
-
triggerBody: any;
|
|
339
|
-
triggerName: string;
|
|
340
|
-
appName?: string;
|
|
341
|
-
}>;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
export interface InterruptSessionDequeueRequest extends BasemindedConnectionSocketMessage {
|
|
345
|
-
sessionId: string;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
export interface InterruptSessionDequeueResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
349
|
-
message?: {
|
|
350
|
-
triggerBody: any;
|
|
351
|
-
triggerName: string;
|
|
352
|
-
appName?: string;
|
|
353
|
-
} | null;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
export interface InterruptSessionHasMessagesRequest extends BasemindedConnectionSocketMessage {
|
|
357
|
-
sessionId: string;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
export interface InterruptSessionHasMessagesResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
361
|
-
hasMessages?: boolean;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
export interface InterruptSessionGetMessagesRequest extends BasemindedConnectionSocketMessage {
|
|
365
|
-
sessionId: string;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
export interface InterruptSessionGetMessagesResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
369
|
-
messages?: Array<{
|
|
370
|
-
triggerBody: any;
|
|
371
|
-
triggerName: string;
|
|
372
|
-
appName?: string;
|
|
373
|
-
}>;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
export interface RestoreCheckpointRequest extends BasemindedConnectionSocketMessage {
|
|
377
|
-
sessionId: string;
|
|
378
|
-
checkpointId: string;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
export interface RestoreCheckpointResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
382
|
-
success?: boolean;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
184
|
export interface RestoreCheckpointRequest extends BasemindedConnectionSocketMessage {
|
|
386
185
|
sessionId: string;
|
|
387
186
|
checkpointId: string;
|
|
@@ -389,4 +188,4 @@ export interface RestoreCheckpointRequest extends BasemindedConnectionSocketMess
|
|
|
389
188
|
|
|
390
189
|
export interface RestoreCheckpointResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
391
190
|
success?: boolean;
|
|
392
|
-
}
|
|
191
|
+
}
|
|
@@ -113,7 +113,7 @@ function loadPlaybooksFromDirectories(directories: string[]): Playbook[] {
|
|
|
113
113
|
|
|
114
114
|
for (const directory of directories) {
|
|
115
115
|
if (!fs.existsSync(directory)) {
|
|
116
|
-
logger.info(
|
|
116
|
+
logger.info(`Playbooks directory does not exist: ${directory}`);
|
|
117
117
|
continue;
|
|
118
118
|
}
|
|
119
119
|
|
|
@@ -126,12 +126,12 @@ function loadPlaybooksFromDirectories(directories: string[]): Playbook[] {
|
|
|
126
126
|
|
|
127
127
|
if (playbook && playbook.name && playbook.blocks) {
|
|
128
128
|
playbooks.push(playbook);
|
|
129
|
-
logger.info(
|
|
129
|
+
logger.info(`Loaded playbook: ${playbook.name} from ${file}`);
|
|
130
130
|
} else {
|
|
131
|
-
logger.warn(
|
|
131
|
+
logger.warn(`Invalid playbook structure in ${file}`);
|
|
132
132
|
}
|
|
133
133
|
} catch (error) {
|
|
134
|
-
logger.error(
|
|
134
|
+
logger.error(`Failed to load playbook file ${file}: ${error}`);
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
}
|
package/src/types/Agent.types.ts
CHANGED
|
@@ -29,8 +29,6 @@ export interface AgentInvokeParams {
|
|
|
29
29
|
sessionId?: string;
|
|
30
30
|
/** Optional name of the application triggering the agent in case of an app trigger */
|
|
31
31
|
appName?: string;
|
|
32
|
-
/** Internal flag to bypass session processing check for recursive calls */
|
|
33
|
-
bypassSessionCheck?: boolean;
|
|
34
32
|
}
|
|
35
33
|
export interface HistoryStep {
|
|
36
34
|
type: NodeType;
|