@minded-ai/mindedjs 1.0.108 → 1.0.109-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 +12 -12
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +37 -13
- 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.d.ts +1 -11
- package/dist/browserTask/executeBrowserTask.d.ts.map +1 -1
- package/dist/browserTask/executeBrowserTask.js +67 -170
- package/dist/browserTask/executeBrowserTask.js.map +1 -1
- 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 +103 -1
- package/dist/cli/index.js.map +1 -1
- package/dist/edges/createLogicalRouter.d.ts +3 -1
- package/dist/edges/createLogicalRouter.d.ts.map +1 -1
- package/dist/edges/createLogicalRouter.js +41 -2
- package/dist/edges/createLogicalRouter.js.map +1 -1
- package/dist/edges/edgeFactory.d.ts.map +1 -1
- package/dist/edges/edgeFactory.js +7 -7
- package/dist/edges/edgeFactory.js.map +1 -1
- package/dist/events/AgentEvents.d.ts +19 -1
- package/dist/events/AgentEvents.d.ts.map +1 -1
- package/dist/events/AgentEvents.js +2 -0
- package/dist/events/AgentEvents.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/internalTools/timer.d.ts +3 -3
- package/dist/internalTools/timer.d.ts.map +1 -1
- package/dist/internalTools/timer.js +3 -3
- package/dist/internalTools/timer.js.map +1 -1
- package/dist/nodes/addBrowserTaskNode.d.ts +1 -3
- package/dist/nodes/addBrowserTaskNode.d.ts.map +1 -1
- package/dist/nodes/addBrowserTaskNode.js +54 -186
- package/dist/nodes/addBrowserTaskNode.js.map +1 -1
- package/dist/nodes/nodeFactory.js +1 -1
- package/dist/nodes/nodeFactory.js.map +1 -1
- package/docs/SUMMARY.md +8 -4
- package/docs/low-code-editor/edges.md +4 -0
- package/docs/sdk/debugging.md +342 -0
- package/docs/{platform → sdk}/events.md +168 -1
- package/package.json +12 -5
- package/dist/nodes/addBrowserTaskRunNode.d.ts +0 -13
- package/dist/nodes/addBrowserTaskRunNode.d.ts.map +0 -1
- package/dist/nodes/addBrowserTaskRunNode.js +0 -130
- package/dist/nodes/addBrowserTaskRunNode.js.map +0 -1
- package/src/agent.ts +0 -928
- package/src/browserTask/executeBrowserTask.ts +0 -213
- package/src/checkpointer/checkpointSaverFactory.ts +0 -18
- package/src/cli/index.ts +0 -170
- package/src/cli/lambdaHandlerTemplate.ts +0 -45
- package/src/edges/createDirectEdge.ts +0 -16
- package/src/edges/createLogicalRouter.ts +0 -114
- package/src/edges/createPromptRouter.ts +0 -218
- package/src/edges/edgeFactory.ts +0 -141
- package/src/events/AgentEvents.ts +0 -47
- package/src/events/index.ts +0 -3
- package/src/index.ts +0 -70
- package/src/interfaces/zendesk.ts +0 -157
- package/src/internalTools/appActionRunnerTool.ts +0 -68
- package/src/internalTools/documentExtraction/documentExtraction.ts +0 -809
- package/src/internalTools/documentExtraction/types.ts +0 -59
- package/src/internalTools/libraryActionRunnerTool.ts +0 -63
- package/src/internalTools/retell.ts +0 -28
- package/src/internalTools/sendPlaceholderMessage.ts +0 -27
- package/src/internalTools/timer.ts +0 -137
- package/src/llm/createLlmInstance.ts +0 -33
- package/src/nodes/addAppToolNode.ts +0 -106
- package/src/nodes/addBrowserTaskNode.ts +0 -231
- package/src/nodes/addBrowserTaskRunNode.ts +0 -144
- package/src/nodes/addHumanInTheLoopNode.ts +0 -25
- package/src/nodes/addJumpToNode.ts +0 -25
- package/src/nodes/addJunctionNode.ts +0 -20
- package/src/nodes/addPromptNode.ts +0 -119
- package/src/nodes/addToolNode.ts +0 -72
- package/src/nodes/addToolRunNode.ts +0 -76
- package/src/nodes/addTriggerNode.ts +0 -27
- package/src/nodes/nodeFactory.ts +0 -57
- package/src/platform/config.ts +0 -77
- package/src/platform/mindedCheckpointSaver.ts +0 -146
- package/src/platform/mindedConnection.ts +0 -199
- package/src/platform/mindedConnectionTypes.ts +0 -220
- package/src/platform/models/mindedChatOpenAI.ts +0 -49
- package/src/platform/models/parallelWrapper.ts +0 -141
- package/src/platform/piiGateway/gateway.ts +0 -103
- package/src/platform/piiGateway/index.ts +0 -5
- package/src/platform/piiGateway/types.ts +0 -29
- package/src/platform/utils/parseAttachments.ts +0 -56
- package/src/playbooks/playbooks.ts +0 -209
- package/src/toolsLibrary/index.ts +0 -6
- package/src/toolsLibrary/parseDocument.ts +0 -136
- package/src/triggers/triggerTypeToDefaultMessage.ts +0 -9
- package/src/types/Agent.types.ts +0 -67
- package/src/types/Flows.types.ts +0 -200
- package/src/types/LLM.types.ts +0 -15
- package/src/types/LangGraph.types.ts +0 -53
- package/src/types/Platform.types.ts +0 -1
- package/src/types/Tools.types.ts +0 -31
- package/src/types/Voice.types.ts +0 -4
- package/src/utils/extractStateMemoryResponse.ts +0 -16
- package/src/utils/history.ts +0 -9
- package/src/utils/logger.ts +0 -22
- package/src/utils/wait.ts +0 -1
- package/src/voice/elevenLabsUtils.ts +0 -81
- package/src/voice/voiceSession.ts +0 -294
- /package/docs/{platform → sdk}/logging.md +0 -0
- /package/docs/{platform → sdk}/memory.md +0 -0
- /package/docs/{platform → sdk}/parallel-llm.md +0 -0
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
import { WebSocket } from 'ws';
|
|
2
|
-
import { Agent } from '../agent';
|
|
3
|
-
import * as mindedConnection from '../platform/mindedConnection';
|
|
4
|
-
import { mindedConnectionSocketMessageType } from '../platform/mindedConnectionTypes';
|
|
5
|
-
import { getConfig } from '../platform/config';
|
|
6
|
-
import { ConversationInitiationClientData, ElevenLabsWebSocketEvent } from './elevenLabsUtils';
|
|
7
|
-
import { AIMessage, BaseMessage, HumanMessage } from '@langchain/core/messages';
|
|
8
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
9
|
-
import { logger } from '../utils/logger';
|
|
10
|
-
import { SessionType } from '../types/Agent.types';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Voice Conversation class for managing individual ElevenLabs voice conversations
|
|
14
|
-
*/
|
|
15
|
-
export class VoiceSession {
|
|
16
|
-
private agent: Agent;
|
|
17
|
-
private sessionId: string;
|
|
18
|
-
private firstMessage: string;
|
|
19
|
-
private voiceId?: string;
|
|
20
|
-
private elevenLabsSocket?: WebSocket;
|
|
21
|
-
|
|
22
|
-
private onAudioCallback?: (data: string) => void;
|
|
23
|
-
private onInterruptionCallback?: () => void;
|
|
24
|
-
private onMessageCallback?: (text: string, message: BaseMessage) => void;
|
|
25
|
-
private onDisconnectCallback?: () => void;
|
|
26
|
-
|
|
27
|
-
constructor({ agent, sessionId, firstMessage, voiceId }: { agent: Agent; sessionId: string; firstMessage: string; voiceId?: string }) {
|
|
28
|
-
logger.debug({ msg: '[Voice] Starting voice session', sessionId, firstMessage, voiceId });
|
|
29
|
-
this.agent = agent;
|
|
30
|
-
this.sessionId = sessionId;
|
|
31
|
-
this.firstMessage = firstMessage;
|
|
32
|
-
this.voiceId = voiceId;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Initialize the voice conversation connection
|
|
37
|
-
*/
|
|
38
|
-
public async init(): Promise<void> {
|
|
39
|
-
const { elevenLabsKey, elevenLabsAgentId } = getConfig();
|
|
40
|
-
|
|
41
|
-
if (!elevenLabsKey) {
|
|
42
|
-
throw new Error('Missing ElevenLabs key - set ELEVEN_LABS_API_KEY env var');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (!elevenLabsAgentId) {
|
|
46
|
-
throw new Error('Missing ElevenLabs agent id - set ELEVEN_LABS_AGENT_ID env var');
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const signedUrl = await this.getSignedUrl({
|
|
50
|
-
agentId: elevenLabsAgentId,
|
|
51
|
-
apiKey: elevenLabsKey,
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
this.elevenLabsSocket = new WebSocket(signedUrl);
|
|
55
|
-
this.setupSocketHandlers();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
private async sendToElevenLabs(message: string): Promise<void> {
|
|
59
|
-
if (!this.elevenLabsSocket) {
|
|
60
|
-
throw new Error('Socket not initialized');
|
|
61
|
-
}
|
|
62
|
-
await this.waitForSocketOpen(this.elevenLabsSocket);
|
|
63
|
-
this.elevenLabsSocket.send(message);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private async waitForSocketOpen(socket: WebSocket): Promise<void> {
|
|
67
|
-
if (socket.readyState === WebSocket.OPEN) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
return new Promise((resolve, reject) => {
|
|
71
|
-
const timeoutMs = 10000;
|
|
72
|
-
const intervalMs = 100;
|
|
73
|
-
let tries = 0;
|
|
74
|
-
const interval = setInterval(() => {
|
|
75
|
-
if (socket.readyState === WebSocket.OPEN) {
|
|
76
|
-
clearInterval(interval);
|
|
77
|
-
resolve();
|
|
78
|
-
}
|
|
79
|
-
tries++;
|
|
80
|
-
if (tries >= timeoutMs) {
|
|
81
|
-
clearInterval(interval);
|
|
82
|
-
reject(new Error('Socket not open'));
|
|
83
|
-
}
|
|
84
|
-
}, intervalMs);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private setupSocketHandlers(): void {
|
|
89
|
-
const socket = this.elevenLabsSocket!; // non-null assertion once, we ensured it's assigned in init()
|
|
90
|
-
|
|
91
|
-
socket.onopen = () => {
|
|
92
|
-
logger.debug({ msg: '[Voice] Connected to ElevenLabs', sessionId: this.sessionId });
|
|
93
|
-
const initiationData: ConversationInitiationClientData = {
|
|
94
|
-
type: 'conversation_initiation_client_data',
|
|
95
|
-
conversation_config_override: {
|
|
96
|
-
agent: {
|
|
97
|
-
first_message: this.firstMessage,
|
|
98
|
-
language: 'en',
|
|
99
|
-
},
|
|
100
|
-
...(this.voiceId
|
|
101
|
-
? {
|
|
102
|
-
tts: {
|
|
103
|
-
voice_id: this.voiceId,
|
|
104
|
-
},
|
|
105
|
-
}
|
|
106
|
-
: {}),
|
|
107
|
-
} as ConversationInitiationClientData['conversation_config_override'],
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
this.sendToElevenLabs(JSON.stringify(initiationData));
|
|
111
|
-
this.sendToElevenLabs(
|
|
112
|
-
JSON.stringify({ type: 'contextual_update', text: JSON.stringify({ sessionId: this.sessionId, mindedToken: getConfig().token! }) }),
|
|
113
|
-
);
|
|
114
|
-
this.addFirstMessageToState();
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
socket.onclose = () => {
|
|
118
|
-
logger.debug({ msg: '[Voice] Disconnected from ElevenLabs, removing voice session', sessionId: this.sessionId });
|
|
119
|
-
this.onDisconnectCallback?.();
|
|
120
|
-
this.agent.voiceSessions.delete(this.sessionId);
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
socket.onerror = (err: unknown) => {
|
|
124
|
-
logger.error({ msg: '[Voice] socket error', sessionId: this.sessionId, error: err });
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
socket.onmessage = async (event: any) => {
|
|
128
|
-
const data: ElevenLabsWebSocketEvent = JSON.parse(event.data.toString());
|
|
129
|
-
|
|
130
|
-
switch (data.type) {
|
|
131
|
-
case 'ping':
|
|
132
|
-
setTimeout(() => {
|
|
133
|
-
this.sendToElevenLabs(JSON.stringify({ type: 'pong', event_id: data.ping_event.event_id }));
|
|
134
|
-
}, data.ping_event.ping_ms);
|
|
135
|
-
break;
|
|
136
|
-
case 'user_transcript':
|
|
137
|
-
logger.debug({
|
|
138
|
-
msg: '[Voice] Received user transcript',
|
|
139
|
-
sessionId: this.sessionId,
|
|
140
|
-
data: data.user_transcription_event.user_transcript,
|
|
141
|
-
});
|
|
142
|
-
if (this.onMessageCallback) {
|
|
143
|
-
this.onMessageCallback(
|
|
144
|
-
data.user_transcription_event.user_transcript,
|
|
145
|
-
new HumanMessage({ content: data.user_transcription_event.user_transcript }),
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
break;
|
|
149
|
-
case 'agent_response':
|
|
150
|
-
logger.debug({ msg: '[Voice] Received agent response' });
|
|
151
|
-
if (this.onMessageCallback) {
|
|
152
|
-
this.onMessageCallback(
|
|
153
|
-
data.agent_response_event.agent_response,
|
|
154
|
-
new AIMessage({ content: data.agent_response_event.agent_response }),
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
break;
|
|
158
|
-
case 'interruption':
|
|
159
|
-
logger.debug({ msg: '[Voice] Received interruption' });
|
|
160
|
-
this.onInterruptionCallback?.();
|
|
161
|
-
// Send interruption event to dashboard if connected
|
|
162
|
-
if (getConfig().dashboardConnected) {
|
|
163
|
-
try {
|
|
164
|
-
mindedConnection.emit(mindedConnectionSocketMessageType.DASHBOARD_VOICE_INTERRUPTION, {
|
|
165
|
-
type: mindedConnectionSocketMessageType.DASHBOARD_VOICE_INTERRUPTION,
|
|
166
|
-
sessionId: this.sessionId,
|
|
167
|
-
timestamp: Date.now(),
|
|
168
|
-
});
|
|
169
|
-
} catch (error) {
|
|
170
|
-
logger.error({ msg: '[Voice] Error sending interruption to dashboard', sessionId: this.sessionId, error });
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
break;
|
|
174
|
-
case 'audio':
|
|
175
|
-
logger.debug({ msg: '[Voice] Received audio response to user', sessionId: this.sessionId });
|
|
176
|
-
if (this.onAudioCallback) {
|
|
177
|
-
this.onAudioCallback(data.audio_event.audio_base_64);
|
|
178
|
-
}
|
|
179
|
-
if (getConfig().dashboardConnected) {
|
|
180
|
-
try {
|
|
181
|
-
mindedConnection.emit(mindedConnectionSocketMessageType.DASHBOARD_VOICE_AGENT_AUDIO, {
|
|
182
|
-
sessionId: this.sessionId,
|
|
183
|
-
audioData: data.audio_event.audio_base_64,
|
|
184
|
-
timestamp: Date.now(),
|
|
185
|
-
type: mindedConnectionSocketMessageType.DASHBOARD_VOICE_AGENT_AUDIO,
|
|
186
|
-
});
|
|
187
|
-
} catch (error) {
|
|
188
|
-
logger.error({ msg: '[Voice] Error sending audio to dashboard', sessionId: this.sessionId, error });
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
break;
|
|
192
|
-
case 'conversation_initiation_metadata':
|
|
193
|
-
logger.trace({ msg: '[Voice] ElevenLabs conversation initiation metadata', sessionId: this.sessionId, data });
|
|
194
|
-
break;
|
|
195
|
-
case 'agent_response_correction':
|
|
196
|
-
try {
|
|
197
|
-
logger.debug({
|
|
198
|
-
msg: '[Voice] Received agent response correction',
|
|
199
|
-
sessionId: this.sessionId,
|
|
200
|
-
data: data.agent_response_correction_event,
|
|
201
|
-
});
|
|
202
|
-
await this.updateAgentResponse(
|
|
203
|
-
data.agent_response_correction_event.original_agent_response,
|
|
204
|
-
data.agent_response_correction_event.corrected_agent_response,
|
|
205
|
-
);
|
|
206
|
-
} catch (error) {
|
|
207
|
-
logger.error({ msg: '[Voice] Error updating agent response', sessionId: this.sessionId, error });
|
|
208
|
-
}
|
|
209
|
-
break;
|
|
210
|
-
default:
|
|
211
|
-
logger.debug({ msg: '[Voice] Received unknown message from ElevenLabs', sessionId: this.sessionId, data });
|
|
212
|
-
break;
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
private async addFirstMessageToState(): Promise<void> {
|
|
218
|
-
const graphState = await this.agent.compiledGraph.getState(this.agent.getLangraphConfig(this.sessionId));
|
|
219
|
-
if (!graphState.values.messages?.length) {
|
|
220
|
-
await this.agent.compiledGraph.updateState(this.agent.getLangraphConfig(this.sessionId), {
|
|
221
|
-
messages: [new AIMessage({ content: this.firstMessage, id: uuidv4() })],
|
|
222
|
-
sessionType: SessionType.VOICE,
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
private async updateAgentResponse(originalAgentResponse: string, correctedAgentResponse: string): Promise<void> {
|
|
228
|
-
const graphState = await this.agent.compiledGraph.getState(this.agent.getLangraphConfig(this.sessionId));
|
|
229
|
-
const agentMessage: AIMessage | null = graphState.values.messages.find(
|
|
230
|
-
(message: BaseMessage) => message.content === originalAgentResponse && message instanceof AIMessage,
|
|
231
|
-
);
|
|
232
|
-
if (agentMessage) {
|
|
233
|
-
agentMessage.content = correctedAgentResponse;
|
|
234
|
-
agentMessage.additional_kwargs = agentMessage.additional_kwargs || {};
|
|
235
|
-
agentMessage.additional_kwargs.update = true;
|
|
236
|
-
const currentNodeId = graphState.tasks[graphState.tasks.length - 1].name;
|
|
237
|
-
await this.agent.compiledGraph.updateState(graphState.config, {
|
|
238
|
-
messages: [agentMessage],
|
|
239
|
-
overrideStartFromNodeId: currentNodeId,
|
|
240
|
-
});
|
|
241
|
-
} else {
|
|
242
|
-
logger.warn({ msg: '[Voice] Agent message not found for correction', sessionId: this.sessionId, originalAgentResponse });
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
public hangup(): void {
|
|
247
|
-
logger.info({ msg: '[Voice] Hanging up voice session', sessionId: this.sessionId });
|
|
248
|
-
this.onDisconnectCallback?.();
|
|
249
|
-
this.elevenLabsSocket?.close();
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Set callback for audio data in base64 format
|
|
254
|
-
*/
|
|
255
|
-
onAudio(callback: (data: string) => void): void {
|
|
256
|
-
this.onAudioCallback = callback;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Set callback for interruption events
|
|
261
|
-
*/
|
|
262
|
-
onInterruption(callback: () => void): void {
|
|
263
|
-
this.onInterruptionCallback = callback;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Set callback for disconnect events
|
|
268
|
-
*/
|
|
269
|
-
onDisconnect(callback: () => void): void {
|
|
270
|
-
this.onDisconnectCallback = callback;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* User audio in base64 format
|
|
275
|
-
*/
|
|
276
|
-
sendAudio(audioData: string): void {
|
|
277
|
-
this.sendToElevenLabs(JSON.stringify({ user_audio_chunk: audioData }));
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
/** Fetch signed URL from ElevenLabs API */
|
|
281
|
-
private async getSignedUrl({ agentId, apiKey }: { agentId: string; apiKey: string }): Promise<string> {
|
|
282
|
-
const response = await fetch(`https://api.elevenlabs.io/v1/convai/conversation/get_signed_url?agent_id=${agentId}`, {
|
|
283
|
-
method: 'GET',
|
|
284
|
-
headers: {
|
|
285
|
-
'xi-api-key': apiKey,
|
|
286
|
-
},
|
|
287
|
-
});
|
|
288
|
-
if (!response.ok) {
|
|
289
|
-
throw new Error(`Failed to fetch signed url - status ${response.status}`);
|
|
290
|
-
}
|
|
291
|
-
const body = await response.json();
|
|
292
|
-
return body.signed_url;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|