@minded-ai/mindedjs 1.0.128 → 1.0.130
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 +45 -72
- package/dist/agent.js.map +1 -1
- package/dist/browserTask/executeBrowserTask.d.ts +2 -13
- package/dist/browserTask/executeBrowserTask.d.ts.map +1 -1
- package/dist/browserTask/executeBrowserTask.js +9 -180
- package/dist/browserTask/executeBrowserTask.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/nodes/addBrowserTaskNode.d.ts.map +1 -1
- package/dist/nodes/addBrowserTaskNode.js +2 -1
- package/dist/nodes/addBrowserTaskNode.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/platform/mindedConnectionTypes.d.ts +28 -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/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/types/Flows.types.d.ts +1 -0
- package/dist/types/Flows.types.d.ts.map +1 -1
- package/dist/types/Flows.types.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/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/docs/SUMMARY.md +1 -0
- package/docs/sdk/agent-api.md +524 -0
- package/docs/sdk/debugging.md +42 -306
- package/package.json +2 -2
- package/src/agent.ts +53 -103
- package/src/browserTask/executeBrowserTask.ts +11 -215
- package/src/debugging/index.ts +1 -0
- package/src/debugging/llmCallbackHandler.ts +126 -0
- package/src/nodes/addBrowserTaskNode.ts +3 -2
- package/src/nodes/addBrowserTaskRunNode.ts +21 -2
- package/src/platform/mindedConnectionTypes.ts +33 -1
- package/src/platform/toolExecutor.ts +118 -0
- package/src/platform/utils/tools.ts +55 -0
- package/src/types/Flows.types.ts +1 -0
- 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/history.ts +29 -1
|
@@ -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 (error) {
|
|
27
|
+
logger.warn({
|
|
28
|
+
msg: '[ToolExecutor] Error parsing Zod schema',
|
|
29
|
+
error: error instanceof Error ? error.message : String(error),
|
|
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
|
+
};
|
package/src/types/Flows.types.ts
CHANGED
|
@@ -120,6 +120,7 @@ export interface BrowserTaskNode extends BaseNode {
|
|
|
120
120
|
defaultPayload?: string;
|
|
121
121
|
proxy?: string; // 2-digit country code like 'IL'
|
|
122
122
|
hooks?: { name: string }[]; // Array of hooks to be passed to the browser-use lambda
|
|
123
|
+
onPrem?: boolean;
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
export type TriggerNode = AppTriggerNode | WebhookTriggerNode | ManualTriggerNode | VoiceTriggerNode | InterfaceTriggerNode;
|
|
@@ -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 (error) {
|
|
49
|
+
throw new Error(`Failed to parse flow file ${file}: ${error}`);
|
|
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
|
+
}
|
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
|
+
}
|