@minded-ai/mindedjs 1.0.108 → 1.0.109
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 +44 -30
- package/dist/agent.js.map +1 -1
- package/dist/browserTask/executeBrowserTask.d.ts.map +1 -1
- package/dist/checkpointer/checkpointSaverFactory.js +7 -17
- package/dist/checkpointer/checkpointSaverFactory.js.map +1 -1
- package/dist/cli/index.js +7 -17
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/lambdaHandlerTemplate.d.ts.map +1 -1
- package/dist/edges/createDirectEdge.d.ts.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 +48 -19
- package/dist/edges/createLogicalRouter.js.map +1 -1
- package/dist/edges/createPromptRouter.d.ts.map +1 -1
- package/dist/edges/edgeFactory.d.ts.map +1 -1
- package/dist/edges/edgeFactory.js +7 -2
- 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 +11 -18
- package/dist/index.js.map +1 -1
- package/dist/interfaces/zendesk.js +7 -17
- package/dist/interfaces/zendesk.js.map +1 -1
- package/dist/internalTools/appActionRunnerTool.d.ts.map +1 -1
- package/dist/internalTools/appActionRunnerTool.js +7 -17
- package/dist/internalTools/appActionRunnerTool.js.map +1 -1
- package/dist/internalTools/documentExtraction/documentExtraction.js +7 -17
- package/dist/internalTools/documentExtraction/documentExtraction.js.map +1 -1
- package/dist/internalTools/libraryActionRunnerTool.d.ts.map +1 -1
- package/dist/internalTools/retell.js +7 -17
- package/dist/internalTools/retell.js.map +1 -1
- package/dist/internalTools/sendPlaceholderMessage.js +7 -17
- package/dist/internalTools/sendPlaceholderMessage.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 +10 -20
- package/dist/internalTools/timer.js.map +1 -1
- package/dist/llm/createLlmInstance.d.ts.map +1 -1
- package/dist/nodes/addAppToolNode.d.ts.map +1 -1
- package/dist/nodes/addBrowserTaskNode.d.ts.map +1 -1
- package/dist/nodes/addBrowserTaskNode.js +7 -17
- package/dist/nodes/addBrowserTaskNode.js.map +1 -1
- package/dist/nodes/addBrowserTaskRunNode.d.ts.map +1 -1
- package/dist/nodes/addHumanInTheLoopNode.d.ts.map +1 -1
- package/dist/nodes/addJumpToNode.d.ts.map +1 -1
- package/dist/nodes/addJunctionNode.d.ts.map +1 -1
- package/dist/nodes/addPromptNode.d.ts.map +1 -1
- package/dist/nodes/addToolNode.d.ts.map +1 -1
- package/dist/nodes/addToolRunNode.d.ts.map +1 -1
- package/dist/nodes/addTriggerNode.d.ts.map +1 -1
- package/dist/nodes/nodeFactory.d.ts.map +1 -1
- package/dist/platform/mindedCheckpointSaver.js +7 -17
- package/dist/platform/mindedCheckpointSaver.js.map +1 -1
- package/dist/platform/mindedConnection.d.ts.map +1 -1
- package/dist/platform/piiGateway/gateway.js +7 -17
- package/dist/platform/piiGateway/gateway.js.map +1 -1
- package/dist/platform/utils/parseAttachments.d.ts.map +1 -1
- package/dist/playbooks/playbooks.js +7 -17
- package/dist/playbooks/playbooks.js.map +1 -1
- package/dist/toolsLibrary/index.js +7 -17
- package/dist/toolsLibrary/index.js.map +1 -1
- package/dist/toolsLibrary/parseDocument.d.ts +3 -3
- package/dist/types/LangGraph.types.d.ts.map +1 -1
- package/dist/utils/extractStateMemoryResponse.d.ts.map +1 -1
- package/dist/utils/history.d.ts.map +1 -1
- package/dist/utils/wait.d.ts.map +1 -1
- package/dist/voice/voiceSession.js +7 -17
- package/dist/voice/voiceSession.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 +2 -2
- package/src/agent.ts +48 -21
- package/src/edges/createLogicalRouter.ts +50 -2
- package/src/edges/edgeFactory.ts +7 -2
- package/src/events/AgentEvents.ts +19 -1
- package/src/index.ts +4 -0
- package/src/internalTools/timer.ts +20 -17
- /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,12 +1,14 @@
|
|
|
1
1
|
import { LogicalConditionEdge } from '../types/Flows.types';
|
|
2
2
|
import { stateAnnotation } from '../types/LangGraph.types';
|
|
3
3
|
import { logger } from '../utils/logger';
|
|
4
|
+
import { Agent } from '../agent';
|
|
5
|
+
import { AgentEvents } from '../events/AgentEvents';
|
|
4
6
|
import * as vm from 'vm';
|
|
5
7
|
|
|
6
8
|
// Default timeout for condition evaluation (in milliseconds)
|
|
7
9
|
const CONDITION_TIMEOUT = 5000; // 5 seconds
|
|
8
10
|
|
|
9
|
-
export const createLogicalRouter = ({ edges }: { edges: LogicalConditionEdge[] }) => {
|
|
11
|
+
export const createLogicalRouter = ({ edges, agent }: { edges: LogicalConditionEdge[]; agent: Agent }) => {
|
|
10
12
|
return async (state: typeof stateAnnotation.State) => {
|
|
11
13
|
logger.debug({ msg: `[Router] Evaluating logical conditions for ${edges.length} edges` });
|
|
12
14
|
|
|
@@ -21,7 +23,19 @@ export const createLogicalRouter = ({ edges }: { edges: LogicalConditionEdge[] }
|
|
|
21
23
|
|
|
22
24
|
// First, evaluate all regular conditions
|
|
23
25
|
for (const edge of regularEdges) {
|
|
26
|
+
const startTime = Date.now();
|
|
27
|
+
|
|
24
28
|
try {
|
|
29
|
+
// Log condition start if in debug mode
|
|
30
|
+
logger.debug({ msg: '[LogicalCondition] Evaluating condition', edge, state });
|
|
31
|
+
|
|
32
|
+
// Emit ON_LOGICAL_CONDITION event
|
|
33
|
+
await agent.emit(AgentEvents.ON_LOGICAL_CONDITION, {
|
|
34
|
+
edge,
|
|
35
|
+
state,
|
|
36
|
+
condition: edge.condition,
|
|
37
|
+
});
|
|
38
|
+
|
|
25
39
|
// Customer is responsible for providing valid JavaScript syntax
|
|
26
40
|
// We execute their condition in a sandboxed VM with timeout protection
|
|
27
41
|
const conditionCode = `
|
|
@@ -63,7 +77,28 @@ export const createLogicalRouter = ({ edges }: { edges: LogicalConditionEdge[] }
|
|
|
63
77
|
new Promise((_, reject) => setTimeout(() => reject(new Error('Condition execution timeout')), CONDITION_TIMEOUT)),
|
|
64
78
|
]);
|
|
65
79
|
|
|
66
|
-
|
|
80
|
+
const executionTime = Date.now() - startTime;
|
|
81
|
+
const booleanResult = result === true;
|
|
82
|
+
|
|
83
|
+
// Log condition result if in debug mode
|
|
84
|
+
logger.debug({
|
|
85
|
+
msg: '[LogicalCondition] Condition evaluated',
|
|
86
|
+
edge,
|
|
87
|
+
result: booleanResult,
|
|
88
|
+
executionTimeMs: executionTime,
|
|
89
|
+
nextNode: booleanResult ? edge.target : null,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Emit ON_LOGICAL_CONDITION_RESULT event
|
|
93
|
+
await agent.emit(AgentEvents.ON_LOGICAL_CONDITION_RESULT, {
|
|
94
|
+
edge,
|
|
95
|
+
state,
|
|
96
|
+
condition: edge.condition,
|
|
97
|
+
result: booleanResult,
|
|
98
|
+
executionTimeMs: executionTime,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
if (booleanResult) {
|
|
67
102
|
if (edge.source == edge.target) {
|
|
68
103
|
logger.info({ msg: `[Router] Stay at node ${edge.source}`, node: edge.source, condition: edge.condition });
|
|
69
104
|
} else {
|
|
@@ -77,6 +112,9 @@ export const createLogicalRouter = ({ edges }: { edges: LogicalConditionEdge[] }
|
|
|
77
112
|
return edge.target;
|
|
78
113
|
}
|
|
79
114
|
} catch (error) {
|
|
115
|
+
const executionTime = Date.now() - startTime;
|
|
116
|
+
const errorObj = error instanceof Error ? error : new Error(String(error));
|
|
117
|
+
|
|
80
118
|
// Provide detailed error information back to the customer
|
|
81
119
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
82
120
|
const conditionPreview = edge.condition.length > 100 ? `${edge.condition.substring(0, 100)}...` : edge.condition;
|
|
@@ -89,6 +127,16 @@ export const createLogicalRouter = ({ edges }: { edges: LogicalConditionEdge[] }
|
|
|
89
127
|
timeout: CONDITION_TIMEOUT,
|
|
90
128
|
});
|
|
91
129
|
|
|
130
|
+
// Emit ON_LOGICAL_CONDITION_RESULT event with error
|
|
131
|
+
await agent.emit(AgentEvents.ON_LOGICAL_CONDITION_RESULT, {
|
|
132
|
+
edge,
|
|
133
|
+
state,
|
|
134
|
+
condition: edge.condition,
|
|
135
|
+
result: false,
|
|
136
|
+
executionTimeMs: executionTime,
|
|
137
|
+
error: errorObj,
|
|
138
|
+
});
|
|
139
|
+
|
|
92
140
|
// Continue to next edge instead of failing completely
|
|
93
141
|
// This allows other conditions to be evaluated even if one fails
|
|
94
142
|
continue;
|
package/src/edges/edgeFactory.ts
CHANGED
|
@@ -55,7 +55,7 @@ export const edgeFactory = ({
|
|
|
55
55
|
|
|
56
56
|
// Priority 2: Logical condition edges
|
|
57
57
|
if (edgesBySource.logical.length > 0) {
|
|
58
|
-
const logicalRouter = createLogicalRouter({ edges: edgesBySource.logical });
|
|
58
|
+
const logicalRouter = createLogicalRouter({ edges: edgesBySource.logical, agent });
|
|
59
59
|
const result = await logicalRouter(state);
|
|
60
60
|
if (result) {
|
|
61
61
|
return result;
|
|
@@ -67,7 +67,12 @@ export const edgeFactory = ({
|
|
|
67
67
|
// Priority 3: Prompt condition edges
|
|
68
68
|
if (edgesBySource.prompt.length > 0) {
|
|
69
69
|
// Use the original node to check canStayOnNode property
|
|
70
|
-
|
|
70
|
+
// For PROMPT_NODE: default to true when undefined
|
|
71
|
+
// For other types: default to false when undefined
|
|
72
|
+
let canStayInCurrentNode = originalNode?.canStayOnNode;
|
|
73
|
+
if (canStayInCurrentNode === undefined) {
|
|
74
|
+
canStayInCurrentNode = originalNode?.type === NodeType.PROMPT_NODE;
|
|
75
|
+
}
|
|
71
76
|
|
|
72
77
|
const promptRouter = createPromptRouter({
|
|
73
78
|
edges: edgesBySource.prompt,
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { BaseMessage } from '@langchain/core/messages';
|
|
2
2
|
import { HistoryStep } from '../types/Agent.types';
|
|
3
3
|
import { State } from '../types/LangGraph.types';
|
|
4
|
+
import { LogicalConditionEdge } from '../types/Flows.types';
|
|
4
5
|
|
|
5
6
|
export enum AgentEvents {
|
|
6
7
|
INIT = 'INIT',
|
|
7
8
|
AI_MESSAGE = 'AI_MESSAGE',
|
|
8
9
|
TRIGGER_EVENT = 'TRIGGER_EVENT',
|
|
9
10
|
VOICE_SESSION_START = 'VOICE_SESSION_START',
|
|
10
|
-
ERROR = 'ERROR'
|
|
11
|
+
ERROR = 'ERROR',
|
|
12
|
+
ON_LOGICAL_CONDITION = 'ON_LOGICAL_CONDITION',
|
|
13
|
+
ON_LOGICAL_CONDITION_RESULT = 'ON_LOGICAL_CONDITION_RESULT',
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
export type AgentEventRequestPayloads<Memory> = {
|
|
@@ -30,6 +33,19 @@ export type AgentEventRequestPayloads<Memory> = {
|
|
|
30
33
|
error: Error;
|
|
31
34
|
state?: State<Memory>;
|
|
32
35
|
};
|
|
36
|
+
[AgentEvents.ON_LOGICAL_CONDITION]: {
|
|
37
|
+
edge: LogicalConditionEdge;
|
|
38
|
+
state: State<Memory>;
|
|
39
|
+
condition: string;
|
|
40
|
+
};
|
|
41
|
+
[AgentEvents.ON_LOGICAL_CONDITION_RESULT]: {
|
|
42
|
+
edge: LogicalConditionEdge;
|
|
43
|
+
state: State<Memory>;
|
|
44
|
+
condition: string;
|
|
45
|
+
result: boolean;
|
|
46
|
+
executionTimeMs: number;
|
|
47
|
+
error?: Error;
|
|
48
|
+
};
|
|
33
49
|
};
|
|
34
50
|
|
|
35
51
|
export type AgentEventResponsePayloads<Memory> = {
|
|
@@ -44,4 +60,6 @@ export type AgentEventResponsePayloads<Memory> = {
|
|
|
44
60
|
};
|
|
45
61
|
[AgentEvents.VOICE_SESSION_START]: void;
|
|
46
62
|
[AgentEvents.ERROR]: void;
|
|
63
|
+
[AgentEvents.ON_LOGICAL_CONDITION]: void;
|
|
64
|
+
[AgentEvents.ON_LOGICAL_CONDITION_RESULT]: void;
|
|
47
65
|
};
|
package/src/index.ts
CHANGED
|
@@ -68,3 +68,7 @@ export { zendesk } from './interfaces/zendesk';
|
|
|
68
68
|
|
|
69
69
|
// Export tools library
|
|
70
70
|
export * as toolsLibrary from './toolsLibrary';
|
|
71
|
+
|
|
72
|
+
// Export event types
|
|
73
|
+
export { AgentEvents } from './events/AgentEvents';
|
|
74
|
+
export type { AgentEventRequestPayloads, AgentEventResponsePayloads } from './events/AgentEvents';
|
|
@@ -2,26 +2,29 @@ import * as mindedConnection from '../platform/mindedConnection';
|
|
|
2
2
|
import { mindedConnectionSocketMessageType, TimerResetResponse, TimerCancelResponse } from '../platform/mindedConnectionTypes';
|
|
3
3
|
|
|
4
4
|
// Store timer handlers by timer name
|
|
5
|
-
export const timerHandlers = new Map<
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
export const timerHandlers = new Map<
|
|
6
|
+
string,
|
|
7
|
+
Array<{
|
|
8
|
+
handler: (params: { sessionId: string; payload: Record<string, any> }) => void | Promise<void>;
|
|
9
|
+
}>
|
|
10
|
+
>();
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* Reset or set a timer for a specific session.
|
|
11
14
|
* When the timer expires, all registered timer handlers will be called.
|
|
12
|
-
*
|
|
15
|
+
*
|
|
13
16
|
* @param params - The timer configuration
|
|
14
17
|
* @param params.sessionId - The session ID to associate the timer with
|
|
15
18
|
* @param params.seconds - Number of seconds until the timer expires
|
|
16
19
|
* @param params.timerName - Unique name for this timer (used for cancellation and identification)
|
|
17
|
-
* @param params.
|
|
20
|
+
* @param params.payload - Additional data to pass to the timer handler when it triggers
|
|
18
21
|
* @returns Promise resolving to timer reset response
|
|
19
22
|
* @throws {Error} When the Minded connection is not established
|
|
20
|
-
*
|
|
23
|
+
*
|
|
21
24
|
* @example
|
|
22
25
|
* ```typescript
|
|
23
26
|
* import { resetTimer } from '@minded-ai/mindedjs';
|
|
24
|
-
*
|
|
27
|
+
*
|
|
25
28
|
* // Set a timer to follow up in 10 seconds
|
|
26
29
|
* await resetTimer({
|
|
27
30
|
* sessionId: 'session-123',
|
|
@@ -37,7 +40,7 @@ export async function resetTimer({
|
|
|
37
40
|
sessionId,
|
|
38
41
|
seconds,
|
|
39
42
|
timerName,
|
|
40
|
-
payload = {}
|
|
43
|
+
payload = {},
|
|
41
44
|
}: {
|
|
42
45
|
sessionId: string;
|
|
43
46
|
seconds: number;
|
|
@@ -54,16 +57,16 @@ export async function resetTimer({
|
|
|
54
57
|
|
|
55
58
|
/**
|
|
56
59
|
* Cancel an existing timer for a specific session.
|
|
57
|
-
*
|
|
60
|
+
*
|
|
58
61
|
* @param sessionId - The session ID the timer is associated with
|
|
59
62
|
* @param timerName - The name of the timer to cancel
|
|
60
63
|
* @returns Promise resolving to timer cancel response
|
|
61
64
|
* @throws {Error} When the Minded connection is not established
|
|
62
|
-
*
|
|
65
|
+
*
|
|
63
66
|
* @example
|
|
64
67
|
* ```typescript
|
|
65
68
|
* import { cancelTimer } from '@minded-ai/mindedjs';
|
|
66
|
-
*
|
|
69
|
+
*
|
|
67
70
|
* // Cancel a previously set timer
|
|
68
71
|
* await cancelTimer('session-123', 'followup');
|
|
69
72
|
* ```
|
|
@@ -81,21 +84,21 @@ export async function cancelTimer(sessionId: string, timerName: string): Promise
|
|
|
81
84
|
/**
|
|
82
85
|
* Register a handler for timer trigger events for a specific timer name.
|
|
83
86
|
* The handler will be called when the specified timer expires for any session.
|
|
84
|
-
*
|
|
87
|
+
*
|
|
85
88
|
* @param params - The configuration for the timer handler
|
|
86
89
|
* @param params.timerName - The name of the timer to handle
|
|
87
90
|
* @param params.handler - Function to call when the timer triggers
|
|
88
|
-
*
|
|
91
|
+
*
|
|
89
92
|
* @example
|
|
90
93
|
* ```typescript
|
|
91
94
|
* import { onTimer } from '@minded-ai/mindedjs';
|
|
92
|
-
*
|
|
95
|
+
*
|
|
93
96
|
* // Register a handler for the 'followup' timer
|
|
94
97
|
* onTimer({
|
|
95
98
|
* timerName: 'followup',
|
|
96
99
|
* handler: async ({ sessionId, payload }) => {
|
|
97
100
|
* console.log(`Followup timer triggered for session ${sessionId}`);
|
|
98
|
-
*
|
|
101
|
+
*
|
|
99
102
|
* // Handle the followup timer
|
|
100
103
|
* await agent.invoke({
|
|
101
104
|
* triggerName: 'timerFollowup',
|
|
@@ -108,7 +111,7 @@ export async function cancelTimer(sessionId: string, timerName: string): Promise
|
|
|
108
111
|
*/
|
|
109
112
|
export function onTimer({
|
|
110
113
|
timerName,
|
|
111
|
-
handler
|
|
114
|
+
handler,
|
|
112
115
|
}: {
|
|
113
116
|
timerName: string;
|
|
114
117
|
handler: (params: { sessionId: string; payload: Record<string, any> }) => void | Promise<void>;
|
|
@@ -134,4 +137,4 @@ mindedConnection.on(mindedConnectionSocketMessageType.TIMER_TRIGGER, async (time
|
|
|
134
137
|
payload: timerTriggerMessage.eventArgs,
|
|
135
138
|
});
|
|
136
139
|
}
|
|
137
|
-
});
|
|
140
|
+
});
|
|
File without changes
|
|
File without changes
|
|
File without changes
|