@minded-ai/mindedjs 1.0.96 → 1.0.97-beta-1235

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.
Files changed (77) hide show
  1. package/dist/browserTask/README.md +419 -0
  2. package/dist/browserTask/browserAgent.py +632 -0
  3. package/dist/browserTask/captcha_isolated.png +0 -0
  4. package/dist/browserTask/executeBrowserTask.d.ts +2 -0
  5. package/dist/browserTask/executeBrowserTask.d.ts.map +1 -0
  6. package/dist/browserTask/executeBrowserTask.js +78 -0
  7. package/dist/browserTask/executeBrowserTask.js.map +1 -0
  8. package/dist/browserTask/executeBrowserTask.ts +78 -0
  9. package/dist/browserTask/requirements.txt +8 -0
  10. package/dist/browserTask/setup.sh +144 -0
  11. package/dist/cli/index.js +44 -1
  12. package/dist/cli/index.js.map +1 -1
  13. package/dist/nodes/addAppToolNode.js +2 -2
  14. package/dist/nodes/addAppToolNode.js.map +1 -1
  15. package/dist/nodes/addBrowserTaskNode.d.ts +11 -0
  16. package/dist/nodes/addBrowserTaskNode.d.ts.map +1 -0
  17. package/dist/nodes/addBrowserTaskNode.js +100 -0
  18. package/dist/nodes/addBrowserTaskNode.js.map +1 -0
  19. package/dist/nodes/nodeFactory.d.ts.map +1 -1
  20. package/dist/nodes/nodeFactory.js +4 -0
  21. package/dist/nodes/nodeFactory.js.map +1 -1
  22. package/dist/types/Flows.types.d.ts +9 -2
  23. package/dist/types/Flows.types.d.ts.map +1 -1
  24. package/dist/types/Flows.types.js +1 -0
  25. package/dist/types/Flows.types.js.map +1 -1
  26. package/dist/utils/logger.js +1 -1
  27. package/dist/utils/logger.js.map +1 -1
  28. package/docs/getting-started/installation.md +42 -0
  29. package/package.json +13 -5
  30. package/src/agent.ts +0 -897
  31. package/src/checkpointer/checkpointSaverFactory.ts +0 -18
  32. package/src/cli/index.ts +0 -170
  33. package/src/cli/lambdaHandlerTemplate.ts +0 -46
  34. package/src/edges/createDirectEdge.ts +0 -11
  35. package/src/edges/createLogicalRouter.ts +0 -98
  36. package/src/edges/createPromptRouter.ts +0 -210
  37. package/src/edges/edgeFactory.ts +0 -125
  38. package/src/events/AgentEvents.ts +0 -47
  39. package/src/events/index.ts +0 -3
  40. package/src/index.ts +0 -51
  41. package/src/interfaces/zendesk.ts +0 -157
  42. package/src/internalTools/appActionRunnerTool.ts +0 -75
  43. package/src/internalTools/sendPlaceholderMessage.ts +0 -27
  44. package/src/internalTools/timer.ts +0 -137
  45. package/src/llm/createLlmInstance.ts +0 -10
  46. package/src/nodes/addAppToolNode.ts +0 -95
  47. package/src/nodes/addHumanInTheLoopNode.ts +0 -25
  48. package/src/nodes/addJumpToNode.ts +0 -24
  49. package/src/nodes/addJunctionNode.ts +0 -19
  50. package/src/nodes/addPromptNode.ts +0 -117
  51. package/src/nodes/addToolNode.ts +0 -71
  52. package/src/nodes/addToolRunNode.ts +0 -74
  53. package/src/nodes/addTriggerNode.ts +0 -26
  54. package/src/nodes/nodeFactory.ts +0 -53
  55. package/src/platform/config.ts +0 -77
  56. package/src/platform/mindedChatOpenAI.ts +0 -19
  57. package/src/platform/mindedCheckpointSaver.ts +0 -146
  58. package/src/platform/mindedConnection.ts +0 -199
  59. package/src/platform/mindedConnectionTypes.ts +0 -191
  60. package/src/platform/piiGateway/gateway.ts +0 -103
  61. package/src/platform/piiGateway/index.ts +0 -5
  62. package/src/platform/piiGateway/types.ts +0 -29
  63. package/src/playbooks/playbooks.ts +0 -209
  64. package/src/triggers/triggerTypeToDefaultMessage.ts +0 -9
  65. package/src/types/Agent.types.ts +0 -67
  66. package/src/types/Flows.types.ts +0 -184
  67. package/src/types/LLM.types.ts +0 -15
  68. package/src/types/LangGraph.types.ts +0 -48
  69. package/src/types/Platform.types.ts +0 -1
  70. package/src/types/Tools.types.ts +0 -31
  71. package/src/types/Voice.types.ts +0 -4
  72. package/src/utils/extractStateMemoryResponse.ts +0 -16
  73. package/src/utils/history.ts +0 -9
  74. package/src/utils/logger.ts +0 -22
  75. package/src/utils/wait.ts +0 -1
  76. package/src/voice/elevenLabsUtils.ts +0 -81
  77. package/src/voice/voiceSession.ts +0 -295
@@ -1,47 +0,0 @@
1
- import { BaseMessage } from '@langchain/core/messages';
2
- import { HistoryStep } from '../types/Agent.types';
3
- import { State } from '../types/LangGraph.types';
4
-
5
- export enum AgentEvents {
6
- INIT = 'INIT',
7
- AI_MESSAGE = 'AI_MESSAGE',
8
- TRIGGER_EVENT = 'TRIGGER_EVENT',
9
- VOICE_SESSION_START = 'VOICE_SESSION_START',
10
- ERROR = 'ERROR'
11
- }
12
-
13
- export type AgentEventRequestPayloads<Memory> = {
14
- [AgentEvents.INIT]: {
15
- state: State<Memory>;
16
- };
17
- [AgentEvents.AI_MESSAGE]: {
18
- message: string;
19
- state: State<Memory>;
20
- };
21
- [AgentEvents.TRIGGER_EVENT]: {
22
- triggerName: string;
23
- triggerBody: any;
24
- sessionId?: string;
25
- };
26
- [AgentEvents.VOICE_SESSION_START]: {
27
- sessionId: string;
28
- };
29
- [AgentEvents.ERROR]: {
30
- error: Error;
31
- state?: State<Memory>;
32
- };
33
- };
34
-
35
- export type AgentEventResponsePayloads<Memory> = {
36
- [AgentEvents.INIT]: void;
37
- [AgentEvents.AI_MESSAGE]: void;
38
- [AgentEvents.TRIGGER_EVENT]: {
39
- isQualified: boolean;
40
- messages?: BaseMessage[];
41
- memory?: Memory;
42
- history?: HistoryStep[];
43
- sessionId?: string;
44
- };
45
- [AgentEvents.VOICE_SESSION_START]: void;
46
- [AgentEvents.ERROR]: void;
47
- };
@@ -1,3 +0,0 @@
1
- import { AgentEvents } from './AgentEvents';
2
-
3
- export default AgentEvents;
package/src/index.ts DELETED
@@ -1,51 +0,0 @@
1
- import { Agent } from './agent';
2
- import events from './events';
3
- import { logger } from './utils/logger';
4
- import { sendPlaceholderMessage } from './internalTools/sendPlaceholderMessage';
5
- import { resetTimer, cancelTimer, onTimer } from './internalTools/timer';
6
-
7
- export type { ElevenLabsContext } from './types/Voice.types';
8
- export { Agent, events, logger, sendPlaceholderMessage, resetTimer, cancelTimer, onTimer };
9
-
10
- // HTTP module for PII masking - only public API
11
- export type { PIIGatewayInstance, HttpRequestConfig, HttpResponse } from './platform/piiGateway';
12
-
13
- export type {
14
- Flow,
15
- Node,
16
- Edge,
17
- TriggerNode,
18
- AppTriggerNode,
19
- PromptNode,
20
- PromptConditionEdge,
21
- LogicalConditionEdge,
22
- StepForwardEdge,
23
- ManualTriggerNode,
24
- JunctionNode,
25
- ToolNode,
26
- AppToolNode,
27
- VoiceTriggerNode,
28
- WebhookTriggerNode,
29
- } from './types/Flows.types';
30
- export {
31
- NodeType,
32
- TriggerType,
33
- EdgeType,
34
- AppNodeMetadata,
35
- AppNodeMetadataType,
36
- NodeMetadata,
37
- KnownTriggerNames,
38
- } from './types/Flows.types';
39
- export type { Tool, ToolExecuteInput } from './types/Tools.types';
40
- export {
41
- HistoryStep,
42
- TriggerHistoryStep,
43
- AppActionInvocationHistoryStep,
44
- AppTriggerHistoryStep,
45
- CustomActionInvocationHistoryStep,
46
- SessionType,
47
- } from './types/Agent.types';
48
- export type { AgentInvokeParams, MindedSDKConfig } from './types/Agent.types';
49
- export type { Environment } from './types/Platform.types';
50
- export type { State } from './types/LangGraph.types';
51
- export { zendesk } from './interfaces/zendesk';
@@ -1,157 +0,0 @@
1
- import { Agent } from '../agent';
2
- import * as mindedConnection from '../platform/mindedConnection';
3
- import { mindedConnectionSocketMessageType } from '../platform/mindedConnectionTypes';
4
-
5
- export const zendesk = {
6
- agent: null as Agent | null,
7
- init: async (agent: Agent) => {
8
- zendesk.agent = agent;
9
- },
10
-
11
- sendMessage: async (sessionId: string, message: string) => {
12
- if (!mindedConnection.isConnected()) return;
13
- return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
14
- type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
15
- interfaceName: 'zendesk',
16
- sessionId,
17
- functionName: 'sendMessage',
18
- functionArgs: { message },
19
- });
20
- },
21
-
22
- sendComment: async (sessionId: string, comment: string) => {
23
- if (!mindedConnection.isConnected()) return;
24
- return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
25
- type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
26
- interfaceName: 'zendesk',
27
- sessionId,
28
- functionName: 'sendComment',
29
- functionArgs: { comment },
30
- });
31
- },
32
-
33
- sendPublicComment: async (sessionId: string, comment: string) => {
34
- if (!mindedConnection.isConnected()) return;
35
- return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
36
- type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
37
- interfaceName: 'zendesk',
38
- sessionId,
39
- functionName: 'sendPublicComment',
40
- functionArgs: { comment },
41
- });
42
- },
43
-
44
- getConversation: async (sessionId: string) => {
45
- if (!mindedConnection.isConnected()) return;
46
- return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
47
- type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
48
- interfaceName: 'zendesk',
49
- sessionId,
50
- functionName: 'getConversation',
51
- functionArgs: {},
52
- });
53
- },
54
-
55
- getConversationMessages: async (sessionId: string) => {
56
- if (!mindedConnection.isConnected()) return;
57
- return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
58
- type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
59
- interfaceName: 'zendesk',
60
- sessionId,
61
- functionName: 'getConversationMessages',
62
- functionArgs: {},
63
- });
64
- },
65
-
66
- addTag: async (sessionId: string, tag: string) => {
67
- if (!mindedConnection.isConnected()) return;
68
- return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
69
- type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
70
- interfaceName: 'zendesk',
71
- sessionId,
72
- functionName: 'addTag',
73
- functionArgs: { tag },
74
- });
75
- },
76
-
77
- getTicket: async (sessionId: string) => {
78
- if (!mindedConnection.isConnected()) return;
79
- return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
80
- type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
81
- interfaceName: 'zendesk',
82
- sessionId,
83
- functionName: 'getTicket',
84
- functionArgs: {
85
- sessionId,
86
- },
87
- });
88
- },
89
-
90
- createTicket: async ({
91
- sessionId,
92
- subject,
93
- ticketBody,
94
- priority,
95
- tags,
96
- customFields,
97
- }: {
98
- sessionId: string;
99
- subject: string;
100
- ticketBody: string;
101
- priority: string;
102
- tags: string[];
103
- customFields: any[];
104
- }) => {
105
- if (!mindedConnection.isConnected()) return;
106
- return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
107
- type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
108
- interfaceName: 'zendesk',
109
- sessionId,
110
- functionName: 'createTicket',
111
- functionArgs: { subject, ticketBody, priority, tags, customFields },
112
- });
113
- },
114
- markTicketAsSolved: async ({ sessionId }: { sessionId: string }) => {
115
- if (!mindedConnection.isConnected()) return;
116
- return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
117
- type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
118
- interfaceName: 'zendesk',
119
- sessionId,
120
- functionName: 'markTicketAsSolved',
121
- functionArgs: { sessionId },
122
- });
123
- },
124
-
125
- markTicketAsOpen: async ({ sessionId }: { sessionId: string }) => {
126
- if (!mindedConnection.isConnected()) return;
127
- return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
128
- type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
129
- interfaceName: 'zendesk',
130
- sessionId,
131
- functionName: 'markTicketAsOpen',
132
- functionArgs: { sessionId },
133
- });
134
- },
135
-
136
- setCustomFields: async ({ sessionId, fields }: { sessionId: string; fields: any[] }) => {
137
- if (!mindedConnection.isConnected()) return;
138
- return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
139
- type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
140
- interfaceName: 'zendesk',
141
- sessionId,
142
- functionName: 'setCustomFields',
143
- functionArgs: { sessionId, fields },
144
- });
145
- },
146
-
147
- search: async ({ sessionId, query }: { sessionId: string; query: string }) => {
148
- if (!mindedConnection.isConnected()) return;
149
- return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL, {
150
- type: mindedConnectionSocketMessageType.INTERFACE_FUNCTION_CALL,
151
- interfaceName: 'zendesk',
152
- sessionId,
153
- functionName: 'search',
154
- functionArgs: { query },
155
- });
156
- },
157
- };
@@ -1,75 +0,0 @@
1
- import * as mindedConnection from '../platform/mindedConnection';
2
- import { mindedConnectionSocketMessageType } from '../platform/mindedConnectionTypes';
3
- import { ActionInputParam } from '../types/Flows.types';
4
- import { Tool, ToolExecuteInput } from '../types/Tools.types';
5
- import { z } from 'zod';
6
-
7
- const typeToZodMap = {
8
- string: z.string(),
9
- number: z.number(),
10
- boolean: z.boolean(),
11
- array: z.array(z.any()),
12
- object: z.record(z.any()),
13
- any: z.any(),
14
- } as const;
15
-
16
- const convertToZodSchema = (schema: Record<string, { type: string; example?: any }>) => {
17
- const zodSchema: Record<string, z.ZodType> = {};
18
- for (const [key, { type }] of Object.entries(schema)) {
19
- const zodType = typeToZodMap[type.toLowerCase() as keyof typeof typeToZodMap] ?? z.string();
20
- zodSchema[key] = zodType;
21
- }
22
- return z.object(zodSchema);
23
- };
24
-
25
- const createdTools: Record<string, Tool<any, any>> = {};
26
-
27
- const appActionRunnerToolCreator = (schema: ActionInputParam[], nodeTitle: string): Tool<any, any> => {
28
- const zodSchema = convertToZodSchema(
29
- schema.reduce((acc, param) => {
30
- if (param.required) {
31
- acc[param.name] = { type: param.type, example: param.example };
32
- }
33
- return acc;
34
- }, {} as Record<string, { type: string; example?: any }>),
35
- );
36
- // Create a description that includes examples
37
- const description = `Run ${nodeTitle} action. Example input: ${JSON.stringify(
38
- schema.reduce((acc, param) => {
39
- if (param.example !== undefined) {
40
- acc[param.name] = param.example;
41
- }
42
- return acc;
43
- }, {} as Record<string, any>),
44
- null,
45
- 2,
46
- )}`;
47
-
48
- const tool = {
49
- name: nodeTitle,
50
- description,
51
- input: zodSchema,
52
- execute: async ({ input, state }: ToolExecuteInput<typeof zodSchema>) => {
53
- const response = await mindedConnection.awaitEmit(
54
- mindedConnectionSocketMessageType.OnAppAction,
55
- {
56
- nodeTitle,
57
- actionInput: input,
58
- },
59
- 20000,
60
- );
61
- return {
62
- state,
63
- result: response as { result?: any },
64
- };
65
- },
66
- };
67
- createdTools[nodeTitle] = tool;
68
- return tool;
69
- };
70
-
71
- export const getAppActionRunnerTool = (nodeTitle: string) => {
72
- return createdTools[nodeTitle];
73
- };
74
-
75
- export default appActionRunnerToolCreator;
@@ -1,27 +0,0 @@
1
- import * as mindedConnection from '../platform/mindedConnection';
2
- import { mindedConnectionSocketMessageType } from '../platform/mindedConnectionTypes';
3
-
4
- /**
5
- * Send a placeholder message to the dashboard voice session.
6
- * This is typically used for voice sessions to provide immediate feedback to users.
7
- *
8
- * @param params - The parameters for sending the placeholder message
9
- * @param params.sessionId - The session ID of the voice session
10
- * @param params.message - The placeholder message to send
11
- * @throws {Error} When the Minded connection is not established
12
- */
13
- export async function sendPlaceholderMessage(params: { sessionId: string; message: string }): Promise<void> {
14
- const { sessionId, message } = params;
15
-
16
- if (!mindedConnection.isConnected()) {
17
- throw new Error('Minded connection is not established when trying to send placeholder message');
18
- }
19
-
20
- const connection = mindedConnection;
21
- connection.emit(mindedConnectionSocketMessageType.DASHBOARD_VOICE_PLACEHOLDER_MESSAGES, {
22
- sessionId,
23
- message,
24
- timestamp: Date.now(),
25
- type: mindedConnectionSocketMessageType.DASHBOARD_VOICE_PLACEHOLDER_MESSAGES,
26
- });
27
- }
@@ -1,137 +0,0 @@
1
- import * as mindedConnection from '../platform/mindedConnection';
2
- import { mindedConnectionSocketMessageType, TimerResetResponse, TimerCancelResponse } from '../platform/mindedConnectionTypes';
3
-
4
- // Store timer handlers by timer name
5
- export const timerHandlers = new Map<string, Array<{
6
- handler: (params: { sessionId: string; payload: Record<string, any> }) => void | Promise<void>;
7
- }>>();
8
-
9
- /**
10
- * Reset or set a timer for a specific session.
11
- * When the timer expires, all registered timer handlers will be called.
12
- *
13
- * @param params - The timer configuration
14
- * @param params.sessionId - The session ID to associate the timer with
15
- * @param params.seconds - Number of seconds until the timer expires
16
- * @param params.timerName - Unique name for this timer (used for cancellation and identification)
17
- * @param params.eventArgs - Additional data to pass to the timer handler when it triggers
18
- * @returns Promise resolving to timer reset response
19
- * @throws {Error} When the Minded connection is not established
20
- *
21
- * @example
22
- * ```typescript
23
- * import { resetTimer } from '@minded-ai/mindedjs';
24
- *
25
- * // Set a timer to follow up in 10 seconds
26
- * await resetTimer({
27
- * sessionId: 'session-123',
28
- * seconds: 10,
29
- * timerName: 'followup',
30
- * payload: {
31
- * message: 'Are you still there?'
32
- * }
33
- * });
34
- * ```
35
- */
36
- export async function resetTimer({
37
- sessionId,
38
- seconds,
39
- timerName,
40
- payload = {}
41
- }: {
42
- sessionId: string;
43
- seconds: number;
44
- timerName: string;
45
- payload?: Record<string, any>;
46
- }): Promise<TimerResetResponse> {
47
- return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.TIMER_RESET, {
48
- sessionId,
49
- seconds,
50
- timerName,
51
- eventArgs: payload,
52
- });
53
- }
54
-
55
- /**
56
- * Cancel an existing timer for a specific session.
57
- *
58
- * @param sessionId - The session ID the timer is associated with
59
- * @param timerName - The name of the timer to cancel
60
- * @returns Promise resolving to timer cancel response
61
- * @throws {Error} When the Minded connection is not established
62
- *
63
- * @example
64
- * ```typescript
65
- * import { cancelTimer } from '@minded-ai/mindedjs';
66
- *
67
- * // Cancel a previously set timer
68
- * await cancelTimer('session-123', 'followup');
69
- * ```
70
- */
71
- export async function cancelTimer(sessionId: string, timerName: string): Promise<TimerCancelResponse> {
72
- if (!mindedConnection.isConnected()) {
73
- throw new Error('Minded connection is not established when trying to cancel timer');
74
- }
75
- return await mindedConnection.awaitEmit(mindedConnectionSocketMessageType.TIMER_CANCEL, {
76
- sessionId,
77
- timerName,
78
- });
79
- }
80
-
81
- /**
82
- * Register a handler for timer trigger events for a specific timer name.
83
- * The handler will be called when the specified timer expires for any session.
84
- *
85
- * @param params - The configuration for the timer handler
86
- * @param params.timerName - The name of the timer to handle
87
- * @param params.handler - Function to call when the timer triggers
88
- *
89
- * @example
90
- * ```typescript
91
- * import { onTimer } from '@minded-ai/mindedjs';
92
- *
93
- * // Register a handler for the 'followup' timer
94
- * onTimer({
95
- * timerName: 'followup',
96
- * handler: async ({ sessionId, payload }) => {
97
- * console.log(`Followup timer triggered for session ${sessionId}`);
98
- *
99
- * // Handle the followup timer
100
- * await agent.invoke({
101
- * triggerName: 'timerFollowup',
102
- * triggerBody: { message: payload.message },
103
- * sessionId
104
- * });
105
- * }
106
- * });
107
- * ```
108
- */
109
- export function onTimer({
110
- timerName,
111
- handler
112
- }: {
113
- timerName: string;
114
- handler: (params: { sessionId: string; payload: Record<string, any> }) => void | Promise<void>;
115
- }): void {
116
- // Initialize handlers array for this timer name if it doesn't exist
117
- if (!timerHandlers.has(timerName)) {
118
- timerHandlers.set(timerName, []);
119
- }
120
-
121
- // Add the handler to the array for this timer name
122
- const handlers = timerHandlers.get(timerName)!;
123
- handlers.push({ handler });
124
- }
125
-
126
- mindedConnection.on(mindedConnectionSocketMessageType.TIMER_TRIGGER, async (timerTriggerMessage) => {
127
- // Get handlers for the specific timer name
128
- const handlers = timerHandlers.get(timerTriggerMessage.timerName) || [];
129
-
130
- // Call all handlers registered for this timer name
131
- for (const { handler } of handlers) {
132
- await handler({
133
- sessionId: timerTriggerMessage.sessionId,
134
- payload: timerTriggerMessage.eventArgs,
135
- });
136
- }
137
- });
@@ -1,10 +0,0 @@
1
- import { LLMConfig, LLMProviders, LLMProvider } from "../types/LLM.types";
2
-
3
- export const createLlmInstance = (llmConfig: LLMConfig) => {
4
- const { name, properties } = llmConfig;
5
- const LLMClass = LLMProviders[name as LLMProvider];
6
- if (!LLMClass) {
7
- throw new Error(`Unsupported LLM provider: ${name}`);
8
- }
9
- return new LLMClass(properties);
10
- };
@@ -1,95 +0,0 @@
1
- import { AppToolNode, NodeType } from '../types/Flows.types';
2
- import { tool as langchainTool } from '@langchain/core/tools';
3
- import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
4
- import { SystemMessage } from '@langchain/core/messages';
5
- import { RunnableLike } from '@langchain/core/runnables';
6
- import { z } from 'zod';
7
- import { LLMProviders } from '../types/LLM.types';
8
- import { getAppActionRunnerTool } from '../internalTools/appActionRunnerTool';
9
- import { AppActionInvocationHistoryStep } from '../types/Agent.types';
10
- import { Agent } from '../agent';
11
- import { logger } from '../utils/logger';
12
- import { compilePlaybooks } from '../playbooks/playbooks';
13
- import { createHistoryStep } from '../utils/history';
14
-
15
- export const addAppToolNode = async ({
16
- graph,
17
- node,
18
- llm,
19
- agent,
20
- }: {
21
- graph: PreCompiledGraph;
22
- node: AppToolNode;
23
- llm: (typeof LLMProviders)[keyof typeof LLMProviders];
24
- agent: Agent;
25
- }) => {
26
- const cleanedParameters = Object.fromEntries(Object.entries(node.parameters || {}).filter(([, value]) => value !== ''));
27
- const appRunnerTool = getAppActionRunnerTool(node.displayName!);
28
- const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
29
- logger.info(`Executing tool node ${appRunnerTool.name}`);
30
-
31
- const executeWrapper = async (input: z.infer<typeof appRunnerTool.input>) => {
32
- try {
33
- const response = await appRunnerTool.execute({ input, state, agent });
34
- return response || {};
35
- } catch (error) {
36
- logger.error({ msg: 'Error executing tool', error });
37
- throw error;
38
- }
39
- };
40
- const tool = langchainTool(executeWrapper, {
41
- name: appRunnerTool.name,
42
- description: appRunnerTool.description,
43
- schema: appRunnerTool.input,
44
- });
45
- // Get compiled playbooks with proper parameters
46
- const playbookParams = {
47
- ...state.memory, // Spread memory fields at the top level
48
- };
49
- const compiledPlaybooks = compilePlaybooks(agent.playbooks, playbookParams) || '';
50
-
51
- const message = `${compiledPlaybooks ? compiledPlaybooks + '\n\n' : ''}
52
- Additional context:
53
- previous messages are available for context.
54
- Your goal is execute the tool with the correct parameters, some of them already chosen by the user and the rest should be generated.
55
- You have 4 things to base your parameters on:
56
- - Previous messages
57
- - Parameters manually configured by the user (if any)
58
- - User instructions for choosing tool parameters that are not set by the user (if any)
59
- - Workflow memory
60
- Parameters manually configured by the user are:
61
- ${JSON.stringify(cleanedParameters)}
62
- User instructions for choosing tool parameters are:
63
- ${node.prompt ? `${node.prompt}` : 'no instructions set by the user'}
64
- Workflow memory is:
65
- ${JSON.stringify(state.memory)}
66
- `;
67
- const AIToolCallMessage = await llm
68
- .bindTools([tool], {
69
- tool_choice: tool.name,
70
- })
71
- .invoke([...state.messages, new SystemMessage(message)]);
72
- AIToolCallMessage.tool_calls[0].args = {
73
- ...AIToolCallMessage.tool_calls[0].args,
74
- ...cleanedParameters, //user set parameters have priority over ai generated parameters
75
- };
76
- const toolCallMessage = await tool.invoke(AIToolCallMessage.tool_calls[0]);
77
- AIToolCallMessage.additional_kwargs = {
78
- appActionInvocation: {
79
- nodeTitle: node.name,
80
- },
81
- };
82
- return {
83
- messages: [AIToolCallMessage, toolCallMessage],
84
- history: createHistoryStep<AppActionInvocationHistoryStep>(state.history, {
85
- type: NodeType.APP_TOOL,
86
- nodeId: node.name,
87
- nodeDisplayName: node.displayName!,
88
- raw: AIToolCallMessage.tool_calls[0],
89
- appName: node.appName,
90
- messageIds: [AIToolCallMessage.id!],
91
- }),
92
- };
93
- };
94
- graph.addNode(node.name, callback);
95
- };
@@ -1,25 +0,0 @@
1
- import { interrupt } from '@langchain/langgraph';
2
- import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
3
- import { RunnableLike } from '@langchain/core/runnables';
4
- import { logger } from '../utils/logger';
5
- import { internalNodesSuffix } from '../types/Flows.types';
6
-
7
- type AddHumanInTheLoopNodeParams = {
8
- graph: PreCompiledGraph;
9
- attachedToNodeName: string;
10
- };
11
-
12
- export const buildHumanInTheLoopNodeName = (nodeName: string) => `${nodeName}${internalNodesSuffix.HUMAN_IN_THE_LOOP}`;
13
-
14
- export const addHumanInTheLoopNode = async ({ graph, attachedToNodeName }: AddHumanInTheLoopNodeParams) => {
15
- const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
16
- logger.info(`Executing "human in the loop" node for the attached node${attachedToNodeName}`);
17
-
18
- if (state.messages[state.messages.length - 1].getType() === 'ai') {
19
- const value = interrupt('input from human in the loop');
20
- return value;
21
- }
22
- };
23
- graph.addNode(buildHumanInTheLoopNodeName(attachedToNodeName), callback);
24
- graph.addEdge(attachedToNodeName as any, buildHumanInTheLoopNodeName(attachedToNodeName) as any);
25
- };
@@ -1,24 +0,0 @@
1
- import { RunnableLike } from '@langchain/core/runnables';
2
- import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
3
- import { JumpToNode, NodeType } from '../types/Flows.types';
4
- import { logger } from '../utils/logger';
5
- import { HistoryStep } from '../types/Agent.types';
6
- import { createHistoryStep } from '../utils/history';
7
-
8
- export const addJumpToNode = async ({ graph, node }: { graph: PreCompiledGraph; node: JumpToNode }) => {
9
- const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
10
- logger.info(`Executing jump node ${node.displayName} – jumping to ${node.targetNodeId}`);
11
- // No state modifications are necessary; control flow is handled via edges.
12
- return {
13
- history: createHistoryStep<HistoryStep>(state.history, {
14
- type: NodeType.JUMP_TO_NODE,
15
- nodeId: node.name,
16
- nodeDisplayName: node.displayName,
17
- raw: '',
18
- }),
19
- };
20
- };
21
-
22
- graph.addNode(node.name, callback);
23
- graph.addEdge(node.name as any, node.targetNodeId as any);
24
- };
@@ -1,19 +0,0 @@
1
- import { JunctionNode, NodeType } from '../types/Flows.types';
2
- import { PreCompiledGraph, stateAnnotation } from '../types/LangGraph.types';
3
- import { RunnableLike } from '@langchain/core/runnables';
4
- import { createHistoryStep } from '../utils/history';
5
- import { HistoryStep } from '../types/Agent.types';
6
-
7
- export const addJunctionNode = ({ graph, node }: { graph: PreCompiledGraph; node: JunctionNode }) => {
8
- const callback: RunnableLike = async (state: typeof stateAnnotation.State) => {
9
- return {
10
- history: createHistoryStep<HistoryStep>(state.history, {
11
- type: NodeType.JUNCTION,
12
- nodeId: node.name,
13
- nodeDisplayName: node.displayName,
14
- raw: '',
15
- }),
16
- };
17
- };
18
- graph.addNode(node.name, callback);
19
- };