@minded-ai/mindedjs 1.0.129 → 1.0.131
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 +7 -4
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +51 -78
- package/dist/agent.js.map +1 -1
- package/dist/browserTask/executeBrowserTask.d.ts +1 -1
- package/dist/browserTask/executeBrowserTask.d.ts.map +1 -1
- package/dist/browserTask/executeBrowserTask.js +10 -8
- package/dist/browserTask/executeBrowserTask.js.map +1 -1
- package/dist/cli/index.js +4 -4
- package/dist/cli/index.js.map +1 -1
- package/dist/debugging/index.d.ts +2 -0
- package/dist/debugging/index.d.ts.map +1 -0
- package/dist/debugging/index.js +6 -0
- package/dist/debugging/index.js.map +1 -0
- package/dist/debugging/llmCallbackHandler.d.ts +83 -0
- package/dist/debugging/llmCallbackHandler.d.ts.map +1 -0
- package/dist/debugging/llmCallbackHandler.js +102 -0
- package/dist/debugging/llmCallbackHandler.js.map +1 -0
- package/dist/edges/createLogicalRouter.js +3 -3
- package/dist/edges/createLogicalRouter.js.map +1 -1
- package/dist/edges/createPromptRouter.js +4 -4
- package/dist/edges/createPromptRouter.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/index.js.map +1 -1
- package/dist/internalTools/documentExtraction/documentExtraction.d.ts.map +1 -1
- package/dist/internalTools/documentExtraction/documentExtraction.js +15 -21
- package/dist/internalTools/documentExtraction/documentExtraction.js.map +1 -1
- package/dist/internalTools/libraryActionRunnerTool.js +4 -4
- package/dist/internalTools/libraryActionRunnerTool.js.map +1 -1
- package/dist/interrupts/MindedInterruptSessionManager.d.ts.map +1 -1
- package/dist/interrupts/MindedInterruptSessionManager.js +19 -18
- package/dist/interrupts/MindedInterruptSessionManager.js.map +1 -1
- package/dist/nodes/addAppToolNode.js +3 -3
- package/dist/nodes/addAppToolNode.js.map +1 -1
- package/dist/nodes/addBrowserTaskRunNode.d.ts +1 -1
- package/dist/nodes/addBrowserTaskRunNode.d.ts.map +1 -1
- package/dist/nodes/addBrowserTaskRunNode.js +10 -2
- package/dist/nodes/addBrowserTaskRunNode.js.map +1 -1
- package/dist/nodes/addToolRunNode.js +3 -3
- package/dist/nodes/addToolRunNode.js.map +1 -1
- package/dist/nodes/compilePrompt.js +2 -2
- package/dist/nodes/compilePrompt.js.map +1 -1
- package/dist/platform/mindedCheckpointSaver.js +4 -4
- package/dist/platform/mindedCheckpointSaver.js.map +1 -1
- package/dist/platform/mindedConnectionTypes.d.ts +27 -1
- package/dist/platform/mindedConnectionTypes.d.ts.map +1 -1
- package/dist/platform/mindedConnectionTypes.js +2 -0
- package/dist/platform/mindedConnectionTypes.js.map +1 -1
- package/dist/platform/piiGateway/gateway.js +2 -2
- package/dist/platform/piiGateway/gateway.js.map +1 -1
- package/dist/platform/toolExecutor.d.ts +29 -0
- package/dist/platform/toolExecutor.d.ts.map +1 -0
- package/dist/platform/toolExecutor.js +95 -0
- package/dist/platform/toolExecutor.js.map +1 -0
- package/dist/platform/utils/tools.d.ts +6 -0
- package/dist/platform/utils/tools.d.ts.map +1 -0
- package/dist/platform/utils/tools.js +57 -0
- package/dist/platform/utils/tools.js.map +1 -0
- package/dist/playbooks/playbooks.js +5 -5
- package/dist/playbooks/playbooks.js.map +1 -1
- package/dist/toolsLibrary/classifier.d.ts.map +1 -1
- package/dist/toolsLibrary/classifier.js +9 -12
- package/dist/toolsLibrary/classifier.js.map +1 -1
- package/dist/toolsLibrary/parseDocument.js +5 -5
- package/dist/toolsLibrary/parseDocument.js.map +1 -1
- package/dist/types/LangGraph.types.d.ts +2 -0
- package/dist/types/LangGraph.types.d.ts.map +1 -1
- package/dist/types/LangGraph.types.js +5 -0
- package/dist/types/LangGraph.types.js.map +1 -1
- package/dist/types/Tools.types.d.ts +3 -2
- package/dist/types/Tools.types.d.ts.map +1 -1
- package/dist/utils/agentUtils.d.ts +5 -0
- package/dist/utils/agentUtils.d.ts.map +1 -0
- package/dist/utils/agentUtils.js +86 -0
- package/dist/utils/agentUtils.js.map +1 -0
- package/dist/utils/extractStateMemoryResponse.d.ts.map +1 -1
- package/dist/utils/extractStateMemoryResponse.js +10 -8
- package/dist/utils/extractStateMemoryResponse.js.map +1 -1
- package/dist/utils/history.d.ts +1 -0
- package/dist/utils/history.d.ts.map +1 -1
- package/dist/utils/history.js +20 -0
- package/dist/utils/history.js.map +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +3 -0
- package/dist/utils/logger.js.map +1 -1
- package/dist/voice/voiceSession.js +6 -6
- package/dist/voice/voiceSession.js.map +1 -1
- package/docs/SUMMARY.md +1 -0
- package/docs/examples/order-refund-flow.md +6 -6
- package/docs/integrations/zendesk.md +2 -2
- package/docs/low-code-editor/tools.md +5 -4
- package/docs/platform/pii-masking.md +5 -4
- package/docs/sdk/agent-api.md +524 -0
- package/docs/sdk/debugging.md +42 -306
- package/docs/sdk/logging.md +1 -1
- package/docs/tooling/document-processing.md +7 -7
- package/package.json +1 -1
- package/src/agent.ts +59 -109
- package/src/browserTask/executeBrowserTask.ts +12 -8
- package/src/cli/index.ts +4 -4
- package/src/debugging/index.ts +1 -0
- package/src/debugging/llmCallbackHandler.ts +126 -0
- package/src/edges/createLogicalRouter.ts +3 -3
- package/src/edges/createPromptRouter.ts +4 -4
- package/src/index.ts +4 -0
- package/src/internalTools/documentExtraction/documentExtraction.ts +15 -21
- package/src/internalTools/libraryActionRunnerTool.ts +4 -4
- package/src/interrupts/MindedInterruptSessionManager.ts +19 -18
- package/src/nodes/addAppToolNode.ts +3 -3
- package/src/nodes/addBrowserTaskRunNode.ts +21 -2
- package/src/nodes/addToolRunNode.ts +3 -3
- package/src/nodes/compilePrompt.ts +2 -2
- package/src/platform/mindedCheckpointSaver.ts +4 -4
- package/src/platform/mindedConnectionTypes.ts +32 -1
- package/src/platform/piiGateway/gateway.ts +2 -2
- package/src/platform/toolExecutor.ts +118 -0
- package/src/platform/utils/tools.ts +55 -0
- package/src/playbooks/playbooks.ts +5 -5
- package/src/toolsLibrary/classifier.ts +9 -12
- package/src/toolsLibrary/parseDocument.ts +5 -5
- package/src/types/LangGraph.types.ts +5 -0
- package/src/types/Tools.types.ts +2 -1
- package/src/utils/agentUtils.ts +68 -0
- package/src/utils/extractStateMemoryResponse.ts +64 -62
- package/src/utils/history.ts +29 -1
- package/src/utils/logger.ts +3 -0
- package/src/voice/voiceSession.ts +6 -6
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { Tool } from '../types/Tools.types';
|
|
2
|
+
import { Agent } from '../agent';
|
|
3
|
+
import { logger } from '../utils/logger';
|
|
4
|
+
import extractToolStateResponse from '../utils/extractStateMemoryResponse';
|
|
5
|
+
import { ToolMessage } from '@langchain/core/messages';
|
|
6
|
+
|
|
7
|
+
export interface ToolExecutionRequest {
|
|
8
|
+
toolName: string;
|
|
9
|
+
toolParams: any;
|
|
10
|
+
sessionId: string;
|
|
11
|
+
requestId: string;
|
|
12
|
+
cdpUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ToolExecutionResponse {
|
|
16
|
+
result?: any;
|
|
17
|
+
state?: any;
|
|
18
|
+
error?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export class ToolExecutor {
|
|
22
|
+
private tools: Map<string, Tool<any, any>> = new Map();
|
|
23
|
+
|
|
24
|
+
constructor(private agent: Agent) {}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Register tools for standalone execution
|
|
28
|
+
*/
|
|
29
|
+
registerTools(tools: Tool<any, any>[]) {
|
|
30
|
+
tools.forEach((tool) => {
|
|
31
|
+
if (tool.allowExecutionRequests === true) {
|
|
32
|
+
this.tools.set(tool.name, tool);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Execute a tool by name with given parameters
|
|
39
|
+
* This is called when browser-use requests tool execution via socket
|
|
40
|
+
*/
|
|
41
|
+
async executeTool(request: ToolExecutionRequest): Promise<ToolExecutionResponse> {
|
|
42
|
+
const { toolName, toolParams, sessionId, cdpUrl } = request;
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
// Find the tool
|
|
46
|
+
const tool = this.tools.get(toolName);
|
|
47
|
+
if (!tool) {
|
|
48
|
+
throw new Error(`Tool not found: ${toolName}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// We only allow to execute tools that are marked as allowed to be executed
|
|
52
|
+
|
|
53
|
+
logger.debug({
|
|
54
|
+
msg: '[ToolExecutor] Executing tool',
|
|
55
|
+
toolName,
|
|
56
|
+
sessionId,
|
|
57
|
+
hasCdpUrl: !!cdpUrl,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Get the current state for the session
|
|
61
|
+
const state = await this.agent.getState(sessionId);
|
|
62
|
+
if (!state) {
|
|
63
|
+
throw new Error(`Session state not found: ${sessionId}`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Execute the tool
|
|
67
|
+
const startTime = Date.now();
|
|
68
|
+
|
|
69
|
+
if (cdpUrl) {
|
|
70
|
+
state.cdpUrl = cdpUrl;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const response = await tool.execute({
|
|
74
|
+
input: toolParams,
|
|
75
|
+
state,
|
|
76
|
+
agent: this.agent,
|
|
77
|
+
});
|
|
78
|
+
const endTime = Date.now();
|
|
79
|
+
|
|
80
|
+
logger.debug({
|
|
81
|
+
msg: '[ToolExecutor] Tool execution completed',
|
|
82
|
+
toolName,
|
|
83
|
+
executionTimeMs: endTime - startTime,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Extract state updates from the response
|
|
87
|
+
let stateUpdate = {};
|
|
88
|
+
let result = response;
|
|
89
|
+
|
|
90
|
+
// If the response is a ToolMessage, extract state updates
|
|
91
|
+
if (response && typeof response === 'object' && 'content' in response) {
|
|
92
|
+
const toolMessage = response as ToolMessage;
|
|
93
|
+
stateUpdate = extractToolStateResponse(toolMessage);
|
|
94
|
+
// Extract the content as the result
|
|
95
|
+
result = { result: toolMessage.content };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Update the session state if there are state changes
|
|
99
|
+
if (Object.keys(stateUpdate).length > 0) {
|
|
100
|
+
await this.agent.updateState({ sessionId, state: stateUpdate });
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
result,
|
|
105
|
+
};
|
|
106
|
+
} catch (err) {
|
|
107
|
+
logger.error({
|
|
108
|
+
message: '[ToolExecutor] Error executing tool',
|
|
109
|
+
toolName,
|
|
110
|
+
err,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
return {
|
|
114
|
+
error: err instanceof Error ? err.message : String(err),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { logger } from '../../utils/logger';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Convert Zod schema to parameter format
|
|
5
|
+
* This is a simplified version - you might need to expand based on your needs
|
|
6
|
+
*/
|
|
7
|
+
export const zodSchemaToParams = (zodSchema: any): any[] => {
|
|
8
|
+
try {
|
|
9
|
+
// Get the shape of the Zod object
|
|
10
|
+
const shape = zodSchema._def?.shape?.() || {};
|
|
11
|
+
const params = [];
|
|
12
|
+
|
|
13
|
+
for (const [key, value] of Object.entries(shape)) {
|
|
14
|
+
const zodValue = value as any; // Zod schema type
|
|
15
|
+
const param: any = {
|
|
16
|
+
name: key,
|
|
17
|
+
type: getZodType(zodValue),
|
|
18
|
+
required: !zodValue.isOptional?.(),
|
|
19
|
+
description: zodValue._def?.description || '',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
params.push(param);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return params;
|
|
26
|
+
} catch (err) {
|
|
27
|
+
logger.warn({
|
|
28
|
+
message: '[ToolExecutor] Error parsing Zod schema',
|
|
29
|
+
err,
|
|
30
|
+
});
|
|
31
|
+
return [];
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Get type string from Zod type
|
|
37
|
+
*/
|
|
38
|
+
const getZodType = (zodType: any): string => {
|
|
39
|
+
const typeName = zodType._def?.typeName;
|
|
40
|
+
|
|
41
|
+
switch (typeName) {
|
|
42
|
+
case 'ZodString':
|
|
43
|
+
return 'string';
|
|
44
|
+
case 'ZodNumber':
|
|
45
|
+
return 'number';
|
|
46
|
+
case 'ZodBoolean':
|
|
47
|
+
return 'boolean';
|
|
48
|
+
case 'ZodArray':
|
|
49
|
+
return 'array';
|
|
50
|
+
case 'ZodObject':
|
|
51
|
+
return 'object';
|
|
52
|
+
default:
|
|
53
|
+
return 'any';
|
|
54
|
+
}
|
|
55
|
+
};
|
|
@@ -92,9 +92,9 @@ function editorJsToMarkdown(blocks: OutputBlockData[]): string {
|
|
|
92
92
|
return '';
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
} catch (
|
|
96
|
-
logger.error({
|
|
97
|
-
throw
|
|
95
|
+
} catch (err) {
|
|
96
|
+
logger.error({ message: 'Error converting EditorJS blocks to markdown', err, block });
|
|
97
|
+
throw err;
|
|
98
98
|
}
|
|
99
99
|
})
|
|
100
100
|
.join('\n\n');
|
|
@@ -152,8 +152,8 @@ function loadPlaybooksFromDirectories(directories: string[]): Playbook[] {
|
|
|
152
152
|
} else {
|
|
153
153
|
logger.warn({ msg: `Invalid playbook structure in ${file}` });
|
|
154
154
|
}
|
|
155
|
-
} catch (
|
|
156
|
-
logger.error({
|
|
155
|
+
} catch (err) {
|
|
156
|
+
logger.error({ message: `Failed to load playbook file ${file}: ${err}` });
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
}
|
|
@@ -76,14 +76,13 @@ export async function classify(content: string, config: ClassifierConfig, llm: B
|
|
|
76
76
|
const classText = typeof result.content === 'string' ? result.content.trim() : '';
|
|
77
77
|
return { class: classText };
|
|
78
78
|
}
|
|
79
|
-
} catch (
|
|
80
|
-
|
|
81
|
-
logger.error({ message: 'Classification failed, using default', error: errorMessage });
|
|
79
|
+
} catch (err) {
|
|
80
|
+
logger.error({ message: 'Classification failed, using default', err });
|
|
82
81
|
|
|
83
82
|
// Return default classification on error
|
|
84
83
|
return {
|
|
85
84
|
class: mergedConfig.defaultClass || 'unknown',
|
|
86
|
-
reason: mergedConfig.defaultReason ||
|
|
85
|
+
reason: mergedConfig.defaultReason || (err as Error).message,
|
|
87
86
|
confidence: 0,
|
|
88
87
|
};
|
|
89
88
|
}
|
|
@@ -204,15 +203,14 @@ const classifierTool: Tool<typeof schema, any> = {
|
|
|
204
203
|
},
|
|
205
204
|
},
|
|
206
205
|
};
|
|
207
|
-
} catch (
|
|
208
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
206
|
+
} catch (err) {
|
|
209
207
|
logger.error({
|
|
210
208
|
message: 'Classification failed',
|
|
211
209
|
sessionId: state.sessionId,
|
|
212
|
-
|
|
210
|
+
err,
|
|
213
211
|
});
|
|
214
212
|
|
|
215
|
-
throw
|
|
213
|
+
throw err;
|
|
216
214
|
}
|
|
217
215
|
},
|
|
218
216
|
};
|
|
@@ -258,14 +256,13 @@ ${content}`;
|
|
|
258
256
|
|
|
259
257
|
// If single result returned, wrap in array
|
|
260
258
|
return [result as ClassificationResult];
|
|
261
|
-
} catch (
|
|
262
|
-
|
|
263
|
-
logger.error({ message: 'Multi-classification failed', error: errorMessage });
|
|
259
|
+
} catch (err) {
|
|
260
|
+
logger.error({ message: 'Multi-classification failed', err });
|
|
264
261
|
|
|
265
262
|
return [
|
|
266
263
|
{
|
|
267
264
|
class: mergedConfig.defaultClass || 'unknown',
|
|
268
|
-
reason: mergedConfig.defaultReason ||
|
|
265
|
+
reason: mergedConfig.defaultReason || (err as Error).message,
|
|
269
266
|
confidence: 0,
|
|
270
267
|
},
|
|
271
268
|
];
|
|
@@ -114,18 +114,18 @@ const parseDocumentTool: Tool<typeof schema, any> = {
|
|
|
114
114
|
},
|
|
115
115
|
},
|
|
116
116
|
};
|
|
117
|
-
} catch (
|
|
117
|
+
} catch (err) {
|
|
118
118
|
logger.error({
|
|
119
|
-
|
|
119
|
+
message: 'Failed to parse document',
|
|
120
120
|
sessionId: state.sessionId,
|
|
121
|
-
|
|
121
|
+
err,
|
|
122
122
|
});
|
|
123
123
|
|
|
124
124
|
return {
|
|
125
|
-
result: `Failed to parse document: ${
|
|
125
|
+
result: `Failed to parse document: ${err instanceof Error ? err.message : String(err)}`,
|
|
126
126
|
state: {
|
|
127
127
|
memory: {
|
|
128
|
-
documentParsingError:
|
|
128
|
+
documentParsingError: err instanceof Error ? err.message : String(err),
|
|
129
129
|
},
|
|
130
130
|
},
|
|
131
131
|
};
|
|
@@ -49,6 +49,11 @@ export const createStateAnnotation = <Memory = any>() =>
|
|
|
49
49
|
default: () => ({}),
|
|
50
50
|
reducer: (a, b) => b,
|
|
51
51
|
}),
|
|
52
|
+
// Available only when executing browser-use
|
|
53
|
+
cdpUrl: Annotation<string | null>({
|
|
54
|
+
default: () => null,
|
|
55
|
+
reducer: (a, b) => b,
|
|
56
|
+
}),
|
|
52
57
|
});
|
|
53
58
|
|
|
54
59
|
// Default state annotation with any memory type
|
package/src/types/Tools.types.ts
CHANGED
|
@@ -8,13 +8,14 @@ type StateUpdate<Memory = any> = Omit<Partial<State<Memory>>, 'memory'> & {
|
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
// Valid return type for new API
|
|
11
|
-
export type ToolReturnType<Memory = any> =
|
|
11
|
+
export type ToolReturnType<Memory = any> = { state?: StateUpdate<Memory>; result?: any } | void;
|
|
12
12
|
|
|
13
13
|
export interface Tool<Input extends z.ZodSchema, Memory = any> {
|
|
14
14
|
name: string;
|
|
15
15
|
description: string;
|
|
16
16
|
input: Input;
|
|
17
17
|
isGlobal?: boolean;
|
|
18
|
+
allowExecutionRequests?: boolean;
|
|
18
19
|
execute: (input: ToolExecuteInput<Input, Memory>) => Promise<ToolReturnType<Memory>>;
|
|
19
20
|
}
|
|
20
21
|
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import * as yaml from 'js-yaml';
|
|
4
|
+
|
|
5
|
+
import { getConfig } from '../platform/config';
|
|
6
|
+
import { AppToolNode, Flow, NodeType } from '../types/Flows.types';
|
|
7
|
+
import { mindedConnection } from '../platform/mindedConnection';
|
|
8
|
+
import { mindedConnectionSocketMessageType } from '../platform/mindedConnectionTypes';
|
|
9
|
+
import libraryActionRunnerToolCreator from '../internalTools/libraryActionRunnerTool';
|
|
10
|
+
|
|
11
|
+
export async function loadFlows(flowsDirectories: string[]) {
|
|
12
|
+
const { env, isDeployed } = getConfig();
|
|
13
|
+
if (['sandbox-staging', 'sandbox'].includes(env) && isDeployed) {
|
|
14
|
+
const response = await mindedConnection.awaitEmit<object, { flows: Record<string, Flow> }>(
|
|
15
|
+
mindedConnectionSocketMessageType.GET_FLOWS,
|
|
16
|
+
{},
|
|
17
|
+
);
|
|
18
|
+
if (!response?.flows) {
|
|
19
|
+
throw new Error('Could not load flows from the platform connection');
|
|
20
|
+
}
|
|
21
|
+
return Object.values(response.flows);
|
|
22
|
+
}
|
|
23
|
+
return loadFlowsFromDirectory(flowsDirectories);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function loadFlowsFromDirectory(flowsDirectories: string[]): Flow[] {
|
|
27
|
+
const flows: Flow[] = [];
|
|
28
|
+
for (const flowsDirectory of flowsDirectories) {
|
|
29
|
+
if (!fs.existsSync(flowsDirectory)) {
|
|
30
|
+
throw new Error(`Flows directory does not exist: ${flowsDirectory}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const files = fs.readdirSync(flowsDirectory);
|
|
34
|
+
|
|
35
|
+
for (const file of files) {
|
|
36
|
+
if (file.endsWith('.yaml') || file.endsWith('.yml')) {
|
|
37
|
+
const filePath = path.join(flowsDirectory, file);
|
|
38
|
+
try {
|
|
39
|
+
const fileContent = fs.readFileSync(filePath, 'utf8');
|
|
40
|
+
const parsedFlow = yaml.load(fileContent) as Flow;
|
|
41
|
+
|
|
42
|
+
// Validate that the parsed flow has the required structure
|
|
43
|
+
if (!parsedFlow.name || !parsedFlow.nodes || !parsedFlow.edges) {
|
|
44
|
+
throw new Error(`Invalid flow structure in ${file}. Flow must have name, nodes, and edges.`);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
flows.push(parsedFlow);
|
|
48
|
+
} catch (err) {
|
|
49
|
+
throw new Error(`Failed to parse flow file ${file}: ${err}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (flows.length === 0) {
|
|
55
|
+
throw new Error(`No YAML flow files found in directory: ${flowsDirectory}`);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return flows;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function initLibraryActionsRunnerTools(flows: Flow[]) {
|
|
63
|
+
return flows
|
|
64
|
+
.flatMap((flow) =>
|
|
65
|
+
flow.nodes.filter((node): node is AppToolNode => node.type === NodeType.APP_TOOL && (node as AppToolNode).appName === 'Minded'),
|
|
66
|
+
)
|
|
67
|
+
.map((node) => libraryActionRunnerToolCreator(node.actionKey, node.displayName!));
|
|
68
|
+
}
|
|
@@ -11,8 +11,8 @@ const extractToolStateResponse = (toolMessage: ToolMessage): Partial<State> => {
|
|
|
11
11
|
}
|
|
12
12
|
return parsed.state;
|
|
13
13
|
}
|
|
14
|
-
} catch (
|
|
15
|
-
logger.error({
|
|
14
|
+
} catch (err) {
|
|
15
|
+
logger.error({ message: 'Error parsing tool state response', err });
|
|
16
16
|
}
|
|
17
17
|
return {};
|
|
18
18
|
};
|
|
@@ -23,70 +23,72 @@ const constructMessagesFromToolMessage = (messages: any[]): BaseMessage[] => {
|
|
|
23
23
|
return [];
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
return messages
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
return messages
|
|
27
|
+
.map((messageObj) => {
|
|
28
|
+
try {
|
|
29
|
+
// Handle case where message is already a BaseMessage instance
|
|
30
|
+
if (messageObj instanceof BaseMessage) {
|
|
31
|
+
return messageObj;
|
|
32
|
+
}
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
// Handle case where message is a plain object that needs reconstruction
|
|
35
|
+
const messageType = messageObj.id[2];
|
|
36
|
+
const content = messageObj.kwargs.content || '';
|
|
37
|
+
const id = messageObj.kwargs.id;
|
|
38
|
+
const additionalKwargs = messageObj.additional_kwargs || {};
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
40
|
+
switch (messageType) {
|
|
41
|
+
case 'AIMessage':
|
|
42
|
+
return new AIMessage({
|
|
43
|
+
content,
|
|
44
|
+
id,
|
|
45
|
+
additional_kwargs: additionalKwargs,
|
|
46
|
+
tool_calls: messageObj.tool_calls || [],
|
|
47
|
+
invalid_tool_calls: messageObj.invalid_tool_calls || [],
|
|
48
|
+
});
|
|
49
|
+
case 'HumanMessage':
|
|
50
|
+
return new HumanMessage({
|
|
51
|
+
content,
|
|
52
|
+
id,
|
|
53
|
+
additional_kwargs: additionalKwargs,
|
|
54
|
+
});
|
|
55
|
+
case 'SystemMessage':
|
|
56
|
+
return new SystemMessage({
|
|
57
|
+
content,
|
|
58
|
+
id,
|
|
59
|
+
additional_kwargs: additionalKwargs,
|
|
60
|
+
});
|
|
61
|
+
case 'ToolMessage':
|
|
62
|
+
return new ToolMessage({
|
|
63
|
+
content,
|
|
64
|
+
id,
|
|
65
|
+
additional_kwargs: additionalKwargs,
|
|
66
|
+
tool_call_id: messageObj.tool_call_id || '',
|
|
67
|
+
});
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
default:
|
|
70
|
+
// Default to HumanMessage for unknown types
|
|
71
|
+
logger.warn({
|
|
72
|
+
msg: 'Unknown message type, defaulting to HumanMessage',
|
|
73
|
+
messageType,
|
|
74
|
+
messageObj,
|
|
75
|
+
});
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
} catch (err) {
|
|
79
|
+
logger.error({
|
|
80
|
+
msg: 'Error reconstructing message',
|
|
81
|
+
err,
|
|
82
|
+
messageObj,
|
|
83
|
+
});
|
|
84
|
+
// Return a fallback HumanMessage in case of error
|
|
85
|
+
return new HumanMessage({
|
|
86
|
+
content: messageObj.content || 'Error reconstructing message',
|
|
87
|
+
id: messageObj.id,
|
|
88
|
+
});
|
|
76
89
|
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
msg: 'Error reconstructing message',
|
|
80
|
-
error,
|
|
81
|
-
messageObj
|
|
82
|
-
});
|
|
83
|
-
// Return a fallback HumanMessage in case of error
|
|
84
|
-
return new HumanMessage({
|
|
85
|
-
content: messageObj.content || 'Error reconstructing message',
|
|
86
|
-
id: messageObj.id,
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
}).filter(Boolean) as BaseMessage[];
|
|
90
|
+
})
|
|
91
|
+
.filter(Boolean) as BaseMessage[];
|
|
90
92
|
};
|
|
91
93
|
|
|
92
94
|
export default extractToolStateResponse;
|
package/src/utils/history.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { HistoryStep } from '../types/Agent.types';
|
|
1
|
+
import { AppTriggerHistoryStep, HistoryStep, TriggerHistoryStep } from '../types/Agent.types';
|
|
2
|
+
import { NodeType } from '../types/Flows.types';
|
|
2
3
|
|
|
3
4
|
export const createHistoryStep = <T extends HistoryStep>(currentHistory: HistoryStep[], stepPayload: Omit<T, 'step'>): HistoryStep => {
|
|
4
5
|
const lastHistoryStep = currentHistory?.[currentHistory?.length - 1];
|
|
@@ -7,3 +8,30 @@ export const createHistoryStep = <T extends HistoryStep>(currentHistory: History
|
|
|
7
8
|
step: lastHistoryStep?.step + 1 || 0,
|
|
8
9
|
} as HistoryStep;
|
|
9
10
|
};
|
|
11
|
+
|
|
12
|
+
export function createTriggerHistoryStep(
|
|
13
|
+
currentHistory: HistoryStep[],
|
|
14
|
+
nodeId: string,
|
|
15
|
+
messageIds: string[],
|
|
16
|
+
triggerName: string,
|
|
17
|
+
triggerBody: any,
|
|
18
|
+
appName?: string,
|
|
19
|
+
): HistoryStep {
|
|
20
|
+
const baseStep = {
|
|
21
|
+
nodeId: nodeId,
|
|
22
|
+
nodeDisplayName: triggerName,
|
|
23
|
+
raw: triggerBody,
|
|
24
|
+
messageIds,
|
|
25
|
+
} as HistoryStep;
|
|
26
|
+
|
|
27
|
+
return appName
|
|
28
|
+
? createHistoryStep<AppTriggerHistoryStep>(currentHistory, {
|
|
29
|
+
...baseStep,
|
|
30
|
+
type: NodeType.TRIGGER,
|
|
31
|
+
appName,
|
|
32
|
+
})
|
|
33
|
+
: createHistoryStep<TriggerHistoryStep>(currentHistory, {
|
|
34
|
+
...baseStep,
|
|
35
|
+
type: NodeType.TRIGGER,
|
|
36
|
+
});
|
|
37
|
+
}
|
package/src/utils/logger.ts
CHANGED
|
@@ -173,8 +173,8 @@ export class VoiceSession {
|
|
|
173
173
|
sessionId: this.sessionId,
|
|
174
174
|
timestamp: Date.now(),
|
|
175
175
|
});
|
|
176
|
-
} catch (
|
|
177
|
-
logger.error({
|
|
176
|
+
} catch (err) {
|
|
177
|
+
logger.error({ message: '[Voice] Error sending interruption to dashboard', sessionId: this.sessionId, err });
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
break;
|
|
@@ -191,8 +191,8 @@ export class VoiceSession {
|
|
|
191
191
|
timestamp: Date.now(),
|
|
192
192
|
type: mindedConnectionSocketMessageType.VOICE_AGENT_AUDIO,
|
|
193
193
|
});
|
|
194
|
-
} catch (
|
|
195
|
-
logger.error({
|
|
194
|
+
} catch (err) {
|
|
195
|
+
logger.error({ message: '[Voice] Error sending audio to dashboard', sessionId: this.sessionId, err });
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
break;
|
|
@@ -210,8 +210,8 @@ export class VoiceSession {
|
|
|
210
210
|
data.agent_response_correction_event.original_agent_response,
|
|
211
211
|
data.agent_response_correction_event.corrected_agent_response,
|
|
212
212
|
);
|
|
213
|
-
} catch (
|
|
214
|
-
logger.error({
|
|
213
|
+
} catch (err) {
|
|
214
|
+
logger.error({ message: '[Voice] Error updating agent response', sessionId: this.sessionId, err });
|
|
215
215
|
}
|
|
216
216
|
break;
|
|
217
217
|
default:
|