@minded-ai/mindedjs 1.0.122 → 1.0.123-beta-1
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 +4 -1
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +65 -9
- package/dist/agent.js.map +1 -1
- package/dist/browserTask/README.md +419 -0
- package/dist/browserTask/browserAgent.py +632 -0
- package/dist/browserTask/captcha_isolated.png +0 -0
- package/dist/browserTask/executeBrowserTask.ts +79 -0
- package/dist/browserTask/requirements.txt +8 -0
- package/dist/browserTask/setup.sh +144 -0
- package/dist/cli/index.js +14 -14
- package/dist/cli/index.js.map +1 -1
- package/dist/edges/edgeFactory.js +2 -2
- package/dist/edges/edgeFactory.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/internalTools/retell.d.ts +12 -0
- package/dist/internalTools/retell.d.ts.map +1 -0
- package/dist/internalTools/retell.js +54 -0
- package/dist/internalTools/retell.js.map +1 -0
- package/dist/internalTools/sendPlaceholderMessage.d.ts +14 -0
- package/dist/internalTools/sendPlaceholderMessage.d.ts.map +1 -0
- package/dist/internalTools/sendPlaceholderMessage.js +61 -0
- package/dist/internalTools/sendPlaceholderMessage.js.map +1 -0
- package/dist/interrupts/BaseInterruptSessionManager.d.ts +52 -0
- package/dist/interrupts/BaseInterruptSessionManager.d.ts.map +1 -0
- package/dist/interrupts/BaseInterruptSessionManager.js +40 -0
- package/dist/interrupts/BaseInterruptSessionManager.js.map +1 -0
- package/dist/interrupts/MemoryInterruptSessionManager.d.ts +14 -0
- package/dist/interrupts/MemoryInterruptSessionManager.d.ts.map +1 -0
- package/dist/interrupts/MemoryInterruptSessionManager.js +60 -0
- package/dist/interrupts/MemoryInterruptSessionManager.js.map +1 -0
- package/dist/interrupts/MindedInterruptSessionManager.d.ts +13 -0
- package/dist/interrupts/MindedInterruptSessionManager.d.ts.map +1 -0
- package/dist/interrupts/MindedInterruptSessionManager.js +151 -0
- package/dist/interrupts/MindedInterruptSessionManager.js.map +1 -0
- package/dist/interrupts/interruptSessionManagerFactory.d.ts +3 -0
- package/dist/interrupts/interruptSessionManagerFactory.d.ts.map +1 -0
- package/dist/interrupts/interruptSessionManagerFactory.js +46 -0
- package/dist/interrupts/interruptSessionManagerFactory.js.map +1 -0
- package/dist/nodes/addBrowserTaskNode.js +2 -0
- package/dist/nodes/addBrowserTaskNode.js.map +1 -1
- package/dist/nodes/addHumanInTheLoopNode.d.ts.map +1 -1
- package/dist/nodes/addHumanInTheLoopNode.js +2 -1
- 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 +43 -1
- package/dist/nodes/addPromptNode.js.map +1 -1
- package/dist/nodes/addToolNode.d.ts.map +1 -1
- package/dist/nodes/addToolNode.js +2 -0
- package/dist/nodes/addToolNode.js.map +1 -1
- package/dist/nodes/addToolRunNode.d.ts.map +1 -1
- package/dist/nodes/addToolRunNode.js +1 -0
- package/dist/nodes/addToolRunNode.js.map +1 -1
- package/dist/platform/mindedConnection.js +12 -12
- package/dist/platform/mindedConnection.js.map +1 -1
- package/dist/platform/mindedConnectionTypes.d.ts +151 -1
- package/dist/platform/mindedConnectionTypes.d.ts.map +1 -1
- package/dist/platform/mindedConnectionTypes.js +9 -0
- package/dist/platform/mindedConnectionTypes.js.map +1 -1
- package/dist/playbooks/playbooks.js +5 -5
- package/dist/playbooks/playbooks.js.map +1 -1
- package/dist/types/Agent.types.d.ts +2 -0
- 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 +2 -2
- package/dist/types/LangGraph.types.d.ts.map +1 -1
- package/dist/types/LangGraph.types.js +3 -1
- package/dist/types/LangGraph.types.js.map +1 -1
- package/dist/voice/voiceSession.d.ts.map +1 -1
- package/dist/voice/voiceSession.js +9 -1
- package/dist/voice/voiceSession.js.map +1 -1
- package/package.json +1 -1
- package/src/agent.ts +89 -19
- package/src/cli/index.ts +14 -14
- package/src/edges/edgeFactory.ts +2 -2
- package/src/index.ts +14 -1
- package/src/interrupts/BaseInterruptSessionManager.ts +88 -0
- package/src/interrupts/MemoryInterruptSessionManager.ts +63 -0
- package/src/interrupts/MindedInterruptSessionManager.ts +162 -0
- package/src/interrupts/interruptSessionManagerFactory.ts +20 -0
- package/src/nodes/addBrowserTaskNode.ts +2 -2
- package/src/nodes/addHumanInTheLoopNode.ts +2 -1
- package/src/nodes/addJumpToNode.ts +1 -1
- package/src/nodes/addPromptNode.ts +47 -4
- package/src/nodes/addToolNode.ts +2 -0
- package/src/nodes/addToolRunNode.ts +1 -1
- package/src/platform/mindedConnection.ts +12 -12
- package/src/platform/mindedConnectionTypes.ts +187 -0
- package/src/playbooks/playbooks.ts +5 -5
- package/src/types/Agent.types.ts +2 -0
- package/src/types/LangGraph.types.ts +3 -1
- package/src/voice/voiceSession.ts +9 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { BaseInterruptSessionManager, QueuedMessage, QUEUE_INTERRUPT_DETECTED_BEFORE_SPEECH } from './BaseInterruptSessionManager';
|
|
2
|
+
import * as mindedConnection from '../platform/mindedConnection';
|
|
3
|
+
import {
|
|
4
|
+
mindedConnectionSocketMessageType,
|
|
5
|
+
InterruptSessionIsProcessedRequest,
|
|
6
|
+
InterruptSessionIsProcessedResponse,
|
|
7
|
+
InterruptSessionLockRequest,
|
|
8
|
+
InterruptSessionLockResponse,
|
|
9
|
+
InterruptSessionReleaseRequest,
|
|
10
|
+
InterruptSessionReleaseResponse,
|
|
11
|
+
InterruptSessionEnqueueRequest,
|
|
12
|
+
InterruptSessionEnqueueResponse,
|
|
13
|
+
InterruptSessionDequeueAllRequest,
|
|
14
|
+
InterruptSessionDequeueAllResponse,
|
|
15
|
+
InterruptSessionDequeueRequest,
|
|
16
|
+
InterruptSessionDequeueResponse,
|
|
17
|
+
InterruptSessionHasMessagesRequest,
|
|
18
|
+
InterruptSessionHasMessagesResponse,
|
|
19
|
+
InterruptSessionGetMessagesRequest,
|
|
20
|
+
InterruptSessionGetMessagesResponse,
|
|
21
|
+
} from '../platform/mindedConnectionTypes';
|
|
22
|
+
|
|
23
|
+
export class MindedInterruptSessionManager extends BaseInterruptSessionManager {
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async isProcessed(sessionId: string): Promise<boolean> {
|
|
29
|
+
try {
|
|
30
|
+
const response = await mindedConnection.awaitEmit<InterruptSessionIsProcessedRequest, InterruptSessionIsProcessedResponse>(
|
|
31
|
+
mindedConnectionSocketMessageType.INTERRUPT_SESSION_IS_PROCESSED,
|
|
32
|
+
{
|
|
33
|
+
type: mindedConnectionSocketMessageType.INTERRUPT_SESSION_IS_PROCESSED,
|
|
34
|
+
sessionId,
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
return response.isProcessed ?? false;
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error('Error checking if session is processed:', error);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async lock(sessionId: string): Promise<boolean> {
|
|
45
|
+
try {
|
|
46
|
+
const response = await mindedConnection.awaitEmit<InterruptSessionLockRequest, InterruptSessionLockResponse>(
|
|
47
|
+
mindedConnectionSocketMessageType.INTERRUPT_SESSION_LOCK,
|
|
48
|
+
{
|
|
49
|
+
type: mindedConnectionSocketMessageType.INTERRUPT_SESSION_LOCK,
|
|
50
|
+
sessionId,
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
return response.lockAcquired ?? false;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error('Error locking session:', error);
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async release(sessionId: string): Promise<void> {
|
|
61
|
+
try {
|
|
62
|
+
await mindedConnection.awaitEmit<InterruptSessionReleaseRequest, InterruptSessionReleaseResponse>(
|
|
63
|
+
mindedConnectionSocketMessageType.INTERRUPT_SESSION_RELEASE,
|
|
64
|
+
{
|
|
65
|
+
type: mindedConnectionSocketMessageType.INTERRUPT_SESSION_RELEASE,
|
|
66
|
+
sessionId,
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error('Error releasing session:', error);
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async enqueueMessage(sessionId: string, message: QueuedMessage): Promise<void> {
|
|
76
|
+
try {
|
|
77
|
+
await mindedConnection.awaitEmit<InterruptSessionEnqueueRequest, InterruptSessionEnqueueResponse>(
|
|
78
|
+
mindedConnectionSocketMessageType.INTERRUPT_SESSION_ENQUEUE,
|
|
79
|
+
{
|
|
80
|
+
type: mindedConnectionSocketMessageType.INTERRUPT_SESSION_ENQUEUE,
|
|
81
|
+
sessionId,
|
|
82
|
+
message,
|
|
83
|
+
},
|
|
84
|
+
);
|
|
85
|
+
} catch (error) {
|
|
86
|
+
console.error('Error enqueuing message:', error);
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
async dequeueAll(sessionId: string): Promise<QueuedMessage[]> {
|
|
92
|
+
try {
|
|
93
|
+
const response = await mindedConnection.awaitEmit<InterruptSessionDequeueAllRequest, InterruptSessionDequeueAllResponse>(
|
|
94
|
+
mindedConnectionSocketMessageType.INTERRUPT_SESSION_DEQUEUE_ALL,
|
|
95
|
+
{
|
|
96
|
+
type: mindedConnectionSocketMessageType.INTERRUPT_SESSION_DEQUEUE_ALL,
|
|
97
|
+
sessionId,
|
|
98
|
+
},
|
|
99
|
+
);
|
|
100
|
+
return response.messages ?? [];
|
|
101
|
+
} catch (error) {
|
|
102
|
+
console.error('Error dequeuing all messages:', error);
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async dequeue(sessionId: string): Promise<QueuedMessage | null> {
|
|
108
|
+
try {
|
|
109
|
+
const response = await mindedConnection.awaitEmit<InterruptSessionDequeueRequest, InterruptSessionDequeueResponse>(
|
|
110
|
+
mindedConnectionSocketMessageType.INTERRUPT_SESSION_DEQUEUE,
|
|
111
|
+
{
|
|
112
|
+
type: mindedConnectionSocketMessageType.INTERRUPT_SESSION_DEQUEUE,
|
|
113
|
+
sessionId,
|
|
114
|
+
},
|
|
115
|
+
);
|
|
116
|
+
const message = response.message ?? null;
|
|
117
|
+
|
|
118
|
+
// If the dequeued message has the special trigger name, recursively dequeue the next one
|
|
119
|
+
if (message && message.triggerName === QUEUE_INTERRUPT_DETECTED_BEFORE_SPEECH) {
|
|
120
|
+
return this.dequeue(sessionId);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return message;
|
|
124
|
+
} catch (error) {
|
|
125
|
+
console.error('Error dequeuing message:', error);
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Implementation of abstract methods from BaseInterruptSessionManager
|
|
131
|
+
protected async hasQueuedMessages(sessionId: string): Promise<boolean> {
|
|
132
|
+
try {
|
|
133
|
+
const response = await mindedConnection.awaitEmit<InterruptSessionHasMessagesRequest, InterruptSessionHasMessagesResponse>(
|
|
134
|
+
mindedConnectionSocketMessageType.INTERRUPT_SESSION_HAS_MESSAGES,
|
|
135
|
+
{
|
|
136
|
+
type: mindedConnectionSocketMessageType.INTERRUPT_SESSION_HAS_MESSAGES,
|
|
137
|
+
sessionId,
|
|
138
|
+
},
|
|
139
|
+
);
|
|
140
|
+
return response.hasMessages ?? false;
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.error('Error checking if session has messages:', error);
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
protected async getQueuedMessages(sessionId: string): Promise<QueuedMessage[]> {
|
|
148
|
+
try {
|
|
149
|
+
const response = await mindedConnection.awaitEmit<InterruptSessionGetMessagesRequest, InterruptSessionGetMessagesResponse>(
|
|
150
|
+
mindedConnectionSocketMessageType.INTERRUPT_SESSION_GET_MESSAGES,
|
|
151
|
+
{
|
|
152
|
+
type: mindedConnectionSocketMessageType.INTERRUPT_SESSION_GET_MESSAGES,
|
|
153
|
+
sessionId,
|
|
154
|
+
},
|
|
155
|
+
);
|
|
156
|
+
return response.messages ?? [];
|
|
157
|
+
} catch (error) {
|
|
158
|
+
console.error('Error getting queued messages:', error);
|
|
159
|
+
return [];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { InterruptSessionManager } from './BaseInterruptSessionManager';
|
|
2
|
+
import { MemoryInterruptSessionManager } from './MemoryInterruptSessionManager';
|
|
3
|
+
import { MindedInterruptSessionManager } from './MindedInterruptSessionManager';
|
|
4
|
+
import * as mindedConnection from '../platform/mindedConnection';
|
|
5
|
+
import { getConfig } from '../platform/config';
|
|
6
|
+
import { logger } from '../utils/logger';
|
|
7
|
+
|
|
8
|
+
export function createInterruptSessionManager(): InterruptSessionManager {
|
|
9
|
+
const { runLocally } = getConfig();
|
|
10
|
+
if (runLocally) {
|
|
11
|
+
logger.info({ msg: 'Using memory interrupt session manager' });
|
|
12
|
+
return new MemoryInterruptSessionManager();
|
|
13
|
+
} else {
|
|
14
|
+
if (!mindedConnection.isConnected()) {
|
|
15
|
+
throw new Error('MindedConnection is required for platform interrupt session manager');
|
|
16
|
+
}
|
|
17
|
+
logger.info({ msg: 'Using Minded interrupt session manager' });
|
|
18
|
+
return new MindedInterruptSessionManager();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -24,7 +24,7 @@ type AddBrowserTaskNodeParams = {
|
|
|
24
24
|
export const addBrowserTaskNode = async ({ graph, node, agent, llm }: AddBrowserTaskNodeParams) => {
|
|
25
25
|
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
26
26
|
logger.info({ msg: `Executing browser task node ${node.displayName}`, prompt: node.prompt });
|
|
27
|
-
|
|
27
|
+
await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId);
|
|
28
28
|
// Create Zod schema from inputSchema
|
|
29
29
|
const schemaFields: Record<string, z.ZodTypeAny> = {};
|
|
30
30
|
if (node.inputSchema) {
|
|
@@ -70,7 +70,7 @@ export const addBrowserTaskNode = async ({ graph, node, agent, llm }: AddBrowser
|
|
|
70
70
|
tool_choice: tool.name,
|
|
71
71
|
})
|
|
72
72
|
.invoke([...state.messages, new SystemMessage(systemPrompt)]);
|
|
73
|
-
|
|
73
|
+
await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId);
|
|
74
74
|
if (!AIToolCallMessage.tool_calls || AIToolCallMessage.tool_calls.length === 0) {
|
|
75
75
|
throw new Error('No tool calls generated by LLM');
|
|
76
76
|
}
|
|
@@ -3,6 +3,7 @@ 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';
|
|
6
7
|
|
|
7
8
|
type AddHumanInTheLoopNodeParams = {
|
|
8
9
|
graph: PreCompiledGraph;
|
|
@@ -16,7 +17,7 @@ export const addHumanInTheLoopNode = async ({ graph, attachedToNodeName }: AddHu
|
|
|
16
17
|
logger.debug({ msg: `[Node] Waiting for human input`, node: attachedToNodeName });
|
|
17
18
|
|
|
18
19
|
if (state.messages[state.messages.length - 1].getType() === 'ai') {
|
|
19
|
-
const value = interrupt(
|
|
20
|
+
const value = interrupt({ type: InterruptType.HUMAN_IN_THE_LOOP });
|
|
20
21
|
return value;
|
|
21
22
|
}
|
|
22
23
|
};
|
|
@@ -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(`Executing jump node ${node.displayName} – jumping to ${node.targetNodeId}`);
|
|
10
|
+
logger.info({ msg: `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
|
goto: node.targetNodeId,
|
|
@@ -15,7 +15,7 @@ import { logger } from '../utils/logger';
|
|
|
15
15
|
import { combinePlaybooks } from '../playbooks/playbooks';
|
|
16
16
|
import { createHistoryStep } from '../utils/history';
|
|
17
17
|
import { compilePrompt } from './compilePrompt';
|
|
18
|
-
|
|
18
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
19
19
|
type AddPromptNodeParams = {
|
|
20
20
|
graph: PreCompiledGraph;
|
|
21
21
|
node: PromptNode;
|
|
@@ -27,7 +27,8 @@ type AddPromptNodeParams = {
|
|
|
27
27
|
|
|
28
28
|
export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: AddPromptNodeParams) => {
|
|
29
29
|
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
30
|
-
|
|
30
|
+
await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId);
|
|
31
|
+
logger.info({ msg: `[Node] Executing prompt node`, node: node.displayName });
|
|
31
32
|
const llmToUse = node.llmConfig ? createLlmInstance(node.llmConfig) : llm;
|
|
32
33
|
|
|
33
34
|
const globalTools = tools
|
|
@@ -51,6 +52,7 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
|
|
|
51
52
|
|
|
52
53
|
const startTime = Date.now();
|
|
53
54
|
const result: AIMessage = await llmToUse.bindTools(globalTools).invoke([new SystemMessage(compiledPrompt), ...state.messages]);
|
|
55
|
+
await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId);
|
|
54
56
|
const endTime = Date.now();
|
|
55
57
|
logger.debug({ msg: '[Model] Model execution time', executionTimeMs: endTime - startTime });
|
|
56
58
|
// Check if the result contains tool calls
|
|
@@ -69,6 +71,29 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
|
|
|
69
71
|
const toolResult = await matchedTool.invoke(toolCall);
|
|
70
72
|
const endTime = Date.now();
|
|
71
73
|
logger.debug({ msg: `[Tool] Tool result`, tool: matchedTool?.name, result: toolResult, executionTimeMs: endTime - startTime });
|
|
74
|
+
//check for queue after tool call
|
|
75
|
+
const systemMessageId = uuidv4();
|
|
76
|
+
|
|
77
|
+
await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId, {
|
|
78
|
+
messages: [
|
|
79
|
+
result,
|
|
80
|
+
toolResult,
|
|
81
|
+
new SystemMessage({
|
|
82
|
+
id: systemMessageId,
|
|
83
|
+
content:
|
|
84
|
+
'you called tool when the user send a new message, Consider calling the function again after user message is processed',
|
|
85
|
+
}),
|
|
86
|
+
],
|
|
87
|
+
history: [
|
|
88
|
+
createHistoryStep<HistoryStep>(state.history, {
|
|
89
|
+
type: NodeType.TOOL,
|
|
90
|
+
nodeId: node.name,
|
|
91
|
+
nodeDisplayName: node.displayName,
|
|
92
|
+
raw: toolResult,
|
|
93
|
+
messageIds: [toolResult.id!, systemMessageId],
|
|
94
|
+
}),
|
|
95
|
+
],
|
|
96
|
+
});
|
|
72
97
|
const toolStateUpdate = extractToolStateResponse(toolResult);
|
|
73
98
|
// Properly merge memory and other state updates
|
|
74
99
|
stateUpdates = {
|
|
@@ -77,7 +102,8 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
|
|
|
77
102
|
memory: { ...(stateUpdates as any).memory, ...(toolStateUpdate as any).memory },
|
|
78
103
|
};
|
|
79
104
|
toolResults.push(toolResult);
|
|
80
|
-
} catch (error) {
|
|
105
|
+
} catch (error: any) {
|
|
106
|
+
if (error?.name === 'GraphInterrupt') throw error;
|
|
81
107
|
logger.error({ msg: `[Tool] Error executing tool`, tool: toolCall.name, error });
|
|
82
108
|
const errorMessage = new ToolMessage({
|
|
83
109
|
content: JSON.stringify({ error: error instanceof Error ? error.message : String(error) }),
|
|
@@ -94,6 +120,24 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
|
|
|
94
120
|
return {
|
|
95
121
|
...stateUpdates,
|
|
96
122
|
messages: [result, ...toolResults],
|
|
123
|
+
history: [
|
|
124
|
+
createHistoryStep<HistoryStep>(state.history, {
|
|
125
|
+
type: NodeType.TOOL,
|
|
126
|
+
nodeId: node.name,
|
|
127
|
+
nodeDisplayName: node.displayName,
|
|
128
|
+
raw: result,
|
|
129
|
+
messageIds: [result.id!],
|
|
130
|
+
}),
|
|
131
|
+
...toolResults.map((toolResult) =>
|
|
132
|
+
createHistoryStep<HistoryStep>(state.history, {
|
|
133
|
+
type: NodeType.TOOL,
|
|
134
|
+
nodeId: node.name,
|
|
135
|
+
nodeDisplayName: node.displayName,
|
|
136
|
+
raw: toolResult,
|
|
137
|
+
messageIds: [toolResult.id!],
|
|
138
|
+
}),
|
|
139
|
+
),
|
|
140
|
+
],
|
|
97
141
|
};
|
|
98
142
|
}
|
|
99
143
|
|
|
@@ -104,7 +148,6 @@ export const addPromptNode = async ({ graph, node, llm, tools, emit, agent }: Ad
|
|
|
104
148
|
});
|
|
105
149
|
logger.info({ msg: `[Model] Response`, content: result.content });
|
|
106
150
|
}
|
|
107
|
-
|
|
108
151
|
return {
|
|
109
152
|
goto: null,
|
|
110
153
|
history: createHistoryStep<HistoryStep>(state.history, {
|
package/src/nodes/addToolNode.ts
CHANGED
|
@@ -31,6 +31,7 @@ export const addToolNode = async ({
|
|
|
31
31
|
throw new Error(`Tool not found: ${toolNode.toolName} in node ${node.name}`);
|
|
32
32
|
}
|
|
33
33
|
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
34
|
+
await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId);
|
|
34
35
|
logger.debug({ msg: `[Node] Executing tool node`, node: toolNode.displayName });
|
|
35
36
|
|
|
36
37
|
const tool = langchainTool(() => {}, {
|
|
@@ -52,6 +53,7 @@ export const addToolNode = async ({
|
|
|
52
53
|
.invoke([...state.messages, new SystemMessage(systemPrompt)]);
|
|
53
54
|
const endTime = Date.now();
|
|
54
55
|
logger.debug({ msg: '[Tool] Model execution time', tool: matchedTool.name, executionTimeMs: endTime - startTime });
|
|
56
|
+
await agent.interruptSessionManager.checkQueueAndInterrupt(state.sessionId);
|
|
55
57
|
return {
|
|
56
58
|
goto: null,
|
|
57
59
|
messages: [AIToolCallMessage],
|
|
@@ -23,6 +23,7 @@ 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
|
|
26
27
|
export const addToolRunNode = async ({ graph, tools, toolNode, attachedToNodeName, agent }: AddToolRunNodeParams) => {
|
|
27
28
|
const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
|
|
28
29
|
const matchedTool = tools.find((tool) => tool.name === toolNode.toolName);
|
|
@@ -57,7 +58,6 @@ export const addToolRunNode = async ({ graph, tools, toolNode, attachedToNodeNam
|
|
|
57
58
|
|
|
58
59
|
// Push the toolCallMessage into the messages array from toolStateUpdate
|
|
59
60
|
const updatedMessages = [toolCallMessage, ...((toolStateUpdate as any).messages || [])];
|
|
60
|
-
|
|
61
61
|
// Return the full state update from the tool with the updated messages
|
|
62
62
|
|
|
63
63
|
return {
|
|
@@ -100,33 +100,33 @@ const connect = async (token: string): Promise<void> => {
|
|
|
100
100
|
|
|
101
101
|
const checkReady = () => {
|
|
102
102
|
if (connected && ready) {
|
|
103
|
-
logger.info('\x1b[32mConnection with Minded platform is ready!\x1b[0m');
|
|
104
|
-
logger.info('\x1b[32mPress Ctrl+C to exit...');
|
|
103
|
+
logger.info({ msg: '\x1b[32mConnection with Minded platform is ready!\x1b[0m' });
|
|
104
|
+
logger.info({ msg: '\x1b[32mPress Ctrl+C to exit...' });
|
|
105
105
|
resolve();
|
|
106
106
|
}
|
|
107
107
|
};
|
|
108
108
|
|
|
109
109
|
// Connection event handlers
|
|
110
110
|
socket.on('connect', () => {
|
|
111
|
-
logger.info('Socket connected, waiting for server setup...');
|
|
111
|
+
logger.info({ msg: 'Socket connected, waiting for server setup...' });
|
|
112
112
|
connected = true;
|
|
113
113
|
checkReady();
|
|
114
114
|
});
|
|
115
115
|
|
|
116
116
|
// Listen for ready event from server
|
|
117
117
|
socket.on('sdk-socket-ready', (data: { agentId: string; orgName: string }) => {
|
|
118
|
-
logger.info('Server ready signal received', data);
|
|
118
|
+
logger.info({ msg: 'Server ready signal received', data });
|
|
119
119
|
ready = true;
|
|
120
120
|
checkReady();
|
|
121
121
|
});
|
|
122
122
|
|
|
123
123
|
socket.on('connect_error', () => {
|
|
124
|
-
logger.error('Failed to connect to minded platform');
|
|
124
|
+
logger.error({ msg: 'Failed to connect to minded platform' });
|
|
125
125
|
reject(new Error('Failed to connect to minded platform'));
|
|
126
126
|
});
|
|
127
127
|
|
|
128
128
|
socket.on('disconnect', () => {
|
|
129
|
-
logger.info('Disconnected from local debugging socket');
|
|
129
|
+
logger.info({ msg: 'Disconnected from local debugging socket' });
|
|
130
130
|
connected = false;
|
|
131
131
|
ready = false;
|
|
132
132
|
});
|
|
@@ -136,7 +136,7 @@ const connect = async (token: string): Promise<void> => {
|
|
|
136
136
|
logger.error({ msg: 'Server error:', error });
|
|
137
137
|
|
|
138
138
|
if (error.message.includes('Invalid token')) {
|
|
139
|
-
logger.info('Invalid token');
|
|
139
|
+
logger.info({ msg: 'Invalid token' });
|
|
140
140
|
|
|
141
141
|
// Disconnect current socket
|
|
142
142
|
if (socket?.connected) {
|
|
@@ -158,14 +158,14 @@ const connect = async (token: string): Promise<void> => {
|
|
|
158
158
|
}
|
|
159
159
|
});
|
|
160
160
|
} else {
|
|
161
|
-
console.warn({
|
|
161
|
+
console.warn({ msg: 'No listeners found for event', event });
|
|
162
162
|
}
|
|
163
163
|
});
|
|
164
164
|
|
|
165
165
|
// Handle process termination
|
|
166
166
|
process.on('SIGINT', () => {
|
|
167
167
|
if (socket?.connected) {
|
|
168
|
-
logger.info('\nDisconnecting...');
|
|
168
|
+
logger.info({ msg: '\nDisconnecting...' });
|
|
169
169
|
socket.disconnect();
|
|
170
170
|
}
|
|
171
171
|
process.exit(0);
|
|
@@ -183,17 +183,17 @@ export const start = async (): Promise<void> => {
|
|
|
183
183
|
|
|
184
184
|
export const disconnect = () => {
|
|
185
185
|
if (!socket) {
|
|
186
|
-
logger.warn('No socket connection to disconnect');
|
|
186
|
+
logger.warn({ msg: 'No socket connection to disconnect' });
|
|
187
187
|
return;
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
if (socket.connected) {
|
|
191
|
-
logger.info('Disconnecting from Minded platform...');
|
|
191
|
+
logger.info({ msg: 'Disconnecting from Minded platform...' });
|
|
192
192
|
socket.disconnect();
|
|
193
193
|
return;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
logger.warn('Socket is already disconnected');
|
|
196
|
+
logger.warn({ msg: 'Socket is already disconnected' });
|
|
197
197
|
};
|
|
198
198
|
|
|
199
199
|
export const mindedConnection = {
|
|
@@ -42,6 +42,15 @@ export enum mindedConnectionSocketMessageType {
|
|
|
42
42
|
SDK_VERSION_MISMATCH = 'sdk-version-mismatch', // Browser Task
|
|
43
43
|
CREATE_BROWSER_SESSION = 'create-browser-session',
|
|
44
44
|
INVOKE_BROWSER_TASK = 'invoke-browser-task',
|
|
45
|
+
// Interrupt Session Management
|
|
46
|
+
INTERRUPT_SESSION_IS_PROCESSED = 'interrupt-session-is-processed',
|
|
47
|
+
INTERRUPT_SESSION_LOCK = 'interrupt-session-lock',
|
|
48
|
+
INTERRUPT_SESSION_RELEASE = 'interrupt-session-release',
|
|
49
|
+
INTERRUPT_SESSION_ENQUEUE = 'interrupt-session-enqueue',
|
|
50
|
+
INTERRUPT_SESSION_DEQUEUE_ALL = 'interrupt-session-dequeue-all',
|
|
51
|
+
INTERRUPT_SESSION_DEQUEUE = 'interrupt-session-dequeue',
|
|
52
|
+
INTERRUPT_SESSION_HAS_MESSAGES = 'interrupt-session-has-messages',
|
|
53
|
+
INTERRUPT_SESSION_GET_MESSAGES = 'interrupt-session-get-messages',
|
|
45
54
|
}
|
|
46
55
|
|
|
47
56
|
export type mindedConnectionSocketMessageTypeMap = {
|
|
@@ -73,6 +82,15 @@ export type mindedConnectionSocketMessageTypeMap = {
|
|
|
73
82
|
[mindedConnectionSocketMessageType.UPDATE_STATE]: UpdateStateRequest;
|
|
74
83
|
[mindedConnectionSocketMessageType.CREATE_BROWSER_SESSION]: CreateBrowserSessionRequest;
|
|
75
84
|
[mindedConnectionSocketMessageType.INVOKE_BROWSER_TASK]: InvokeBrowserTaskRequest;
|
|
85
|
+
// Interrupt Session Management
|
|
86
|
+
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_IS_PROCESSED]: InterruptSessionIsProcessedRequest;
|
|
87
|
+
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_LOCK]: InterruptSessionLockRequest;
|
|
88
|
+
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_RELEASE]: InterruptSessionReleaseRequest;
|
|
89
|
+
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_ENQUEUE]: InterruptSessionEnqueueRequest;
|
|
90
|
+
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_DEQUEUE_ALL]: InterruptSessionDequeueAllRequest;
|
|
91
|
+
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_DEQUEUE]: InterruptSessionDequeueRequest;
|
|
92
|
+
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_HAS_MESSAGES]: InterruptSessionHasMessagesRequest;
|
|
93
|
+
[mindedConnectionSocketMessageType.INTERRUPT_SESSION_GET_MESSAGES]: InterruptSessionGetMessagesRequest;
|
|
76
94
|
};
|
|
77
95
|
|
|
78
96
|
export interface BasemindedConnectionSocketMessage {
|
|
@@ -206,6 +224,175 @@ export interface TimerTriggerRequest extends BasemindedConnectionSocketMessage {
|
|
|
206
224
|
eventArgs: Record<string, any>;
|
|
207
225
|
}
|
|
208
226
|
|
|
227
|
+
// Interrupt Session Management Interfaces
|
|
228
|
+
export interface InterruptSessionIsProcessedRequest extends BasemindedConnectionSocketMessage {
|
|
229
|
+
sessionId: string;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export interface InterruptSessionIsProcessedResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
233
|
+
isProcessed?: boolean;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface InterruptSessionLockRequest extends BasemindedConnectionSocketMessage {
|
|
237
|
+
sessionId: string;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
export interface InterruptSessionLockResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
241
|
+
lockAcquired?: boolean;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export interface InterruptSessionReleaseRequest extends BasemindedConnectionSocketMessage {
|
|
245
|
+
sessionId: string;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export interface InterruptSessionReleaseResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
249
|
+
success?: boolean;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export interface InterruptSessionEnqueueRequest extends BasemindedConnectionSocketMessage {
|
|
253
|
+
sessionId: string;
|
|
254
|
+
message: {
|
|
255
|
+
triggerBody: any;
|
|
256
|
+
triggerName: string;
|
|
257
|
+
appName?: string;
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export interface InterruptSessionEnqueueResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
262
|
+
success?: boolean;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export interface InterruptSessionDequeueAllRequest extends BasemindedConnectionSocketMessage {
|
|
266
|
+
sessionId: string;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export interface InterruptSessionDequeueAllResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
270
|
+
messages?: Array<{
|
|
271
|
+
triggerBody: any;
|
|
272
|
+
triggerName: string;
|
|
273
|
+
appName?: string;
|
|
274
|
+
}>;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export interface InterruptSessionDequeueRequest extends BasemindedConnectionSocketMessage {
|
|
278
|
+
sessionId: string;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
export interface InterruptSessionDequeueResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
282
|
+
message?: {
|
|
283
|
+
triggerBody: any;
|
|
284
|
+
triggerName: string;
|
|
285
|
+
appName?: string;
|
|
286
|
+
} | null;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export interface InterruptSessionHasMessagesRequest extends BasemindedConnectionSocketMessage {
|
|
290
|
+
sessionId: string;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export interface InterruptSessionHasMessagesResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
294
|
+
hasMessages?: boolean;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export interface InterruptSessionGetMessagesRequest extends BasemindedConnectionSocketMessage {
|
|
298
|
+
sessionId: string;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
export interface InterruptSessionGetMessagesResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
302
|
+
messages?: Array<{
|
|
303
|
+
triggerBody: any;
|
|
304
|
+
triggerName: string;
|
|
305
|
+
appName?: string;
|
|
306
|
+
}>;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Interrupt Session Management Interfaces
|
|
310
|
+
export interface InterruptSessionIsProcessedRequest extends BasemindedConnectionSocketMessage {
|
|
311
|
+
sessionId: string;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export interface InterruptSessionIsProcessedResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
315
|
+
isProcessed?: boolean;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export interface InterruptSessionLockRequest extends BasemindedConnectionSocketMessage {
|
|
319
|
+
sessionId: string;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
export interface InterruptSessionReleaseRequest extends BasemindedConnectionSocketMessage {
|
|
323
|
+
sessionId: string;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
export interface InterruptSessionReleaseResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
327
|
+
success?: boolean;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export interface InterruptSessionEnqueueRequest extends BasemindedConnectionSocketMessage {
|
|
331
|
+
sessionId: string;
|
|
332
|
+
message: {
|
|
333
|
+
triggerBody: any;
|
|
334
|
+
triggerName: string;
|
|
335
|
+
appName?: string;
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export interface InterruptSessionEnqueueResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
340
|
+
success?: boolean;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export interface InterruptSessionDequeueAllRequest extends BasemindedConnectionSocketMessage {
|
|
344
|
+
sessionId: string;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
export interface InterruptSessionDequeueAllResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
348
|
+
messages?: Array<{
|
|
349
|
+
triggerBody: any;
|
|
350
|
+
triggerName: string;
|
|
351
|
+
appName?: string;
|
|
352
|
+
}>;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export interface InterruptSessionDequeueRequest extends BasemindedConnectionSocketMessage {
|
|
356
|
+
sessionId: string;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export interface InterruptSessionDequeueResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
360
|
+
message?: {
|
|
361
|
+
triggerBody: any;
|
|
362
|
+
triggerName: string;
|
|
363
|
+
appName?: string;
|
|
364
|
+
} | null;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export interface InterruptSessionHasMessagesRequest extends BasemindedConnectionSocketMessage {
|
|
368
|
+
sessionId: string;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
export interface InterruptSessionHasMessagesResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
372
|
+
hasMessages?: boolean;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
export interface InterruptSessionGetMessagesRequest extends BasemindedConnectionSocketMessage {
|
|
376
|
+
sessionId: string;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export interface InterruptSessionGetMessagesResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
380
|
+
messages?: Array<{
|
|
381
|
+
triggerBody: any;
|
|
382
|
+
triggerName: string;
|
|
383
|
+
appName?: string;
|
|
384
|
+
}>;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export interface RestoreCheckpointRequest extends BasemindedConnectionSocketMessage {
|
|
388
|
+
sessionId: string;
|
|
389
|
+
checkpointId: string;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export interface RestoreCheckpointResponse extends BaseSdkConnectionSocketMessageResponseCallbackAck {
|
|
393
|
+
success?: boolean;
|
|
394
|
+
}
|
|
395
|
+
|
|
209
396
|
export interface RestoreCheckpointRequest extends BasemindedConnectionSocketMessage {
|
|
210
397
|
sessionId: string;
|
|
211
398
|
checkpointId: string;
|