@minded-ai/mindedjs 1.0.0-ec2-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/README.md +6 -0
- package/dist/agent.d.ts +256 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +896 -0
- package/dist/agent.js.map +1 -0
- 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 +14 -0
- package/dist/browserTask/executeBrowserTask.d.ts.map +1 -0
- package/dist/browserTask/executeBrowserTask.js +195 -0
- package/dist/browserTask/executeBrowserTask.js.map +1 -0
- package/dist/browserTask/executeBrowserTask.py +153 -0
- package/dist/browserTask/executeBrowserTask.ts +79 -0
- package/dist/browserTask/localBrowserTask.d.ts +49 -0
- package/dist/browserTask/localBrowserTask.d.ts.map +1 -0
- package/dist/browserTask/localBrowserTask.js +284 -0
- package/dist/browserTask/localBrowserTask.js.map +1 -0
- package/dist/browserTask/requirements.txt +8 -0
- package/dist/browserTask/setup.sh +144 -0
- package/dist/browserTask/types.d.ts +35 -0
- package/dist/browserTask/types.d.ts.map +1 -0
- package/dist/browserTask/types.js +10 -0
- package/dist/browserTask/types.js.map +1 -0
- package/dist/checkpointer/checkpointSaverFactory.d.ts +7 -0
- package/dist/checkpointer/checkpointSaverFactory.d.ts.map +1 -0
- package/dist/checkpointer/checkpointSaverFactory.js +53 -0
- package/dist/checkpointer/checkpointSaverFactory.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +209 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/lambdaHandlerTemplate.d.ts +10 -0
- package/dist/cli/lambdaHandlerTemplate.d.ts.map +1 -0
- package/dist/cli/lambdaHandlerTemplate.js +76 -0
- package/dist/cli/lambdaHandlerTemplate.js.map +1 -0
- package/dist/cli/lambdaHandlerTemplate.ts +78 -0
- package/dist/cli/localOperatorSetup.d.ts +6 -0
- package/dist/cli/localOperatorSetup.d.ts.map +1 -0
- package/dist/cli/localOperatorSetup.js +310 -0
- package/dist/cli/localOperatorSetup.js.map +1 -0
- 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 +36 -0
- package/dist/debugging/llmCallbackHandler.d.ts.map +1 -0
- package/dist/debugging/llmCallbackHandler.js +101 -0
- package/dist/debugging/llmCallbackHandler.js.map +1 -0
- package/dist/edges/createDirectEdge.d.ts +4 -0
- package/dist/edges/createDirectEdge.d.ts.map +1 -0
- package/dist/edges/createDirectEdge.js +24 -0
- package/dist/edges/createDirectEdge.js.map +1 -0
- package/dist/edges/createLogicalRouter.d.ts +8 -0
- package/dist/edges/createLogicalRouter.d.ts.map +1 -0
- package/dist/edges/createLogicalRouter.js +194 -0
- package/dist/edges/createLogicalRouter.js.map +1 -0
- package/dist/edges/createPromptRouter.d.ts +12 -0
- package/dist/edges/createPromptRouter.d.ts.map +1 -0
- package/dist/edges/createPromptRouter.js +176 -0
- package/dist/edges/createPromptRouter.js.map +1 -0
- package/dist/edges/edgeFactory.d.ts +14 -0
- package/dist/edges/edgeFactory.d.ts.map +1 -0
- package/dist/edges/edgeFactory.js +125 -0
- package/dist/edges/edgeFactory.js.map +1 -0
- package/dist/events/AgentEvents.d.ts +56 -0
- package/dist/events/AgentEvents.d.ts.map +1 -0
- package/dist/events/AgentEvents.js +13 -0
- package/dist/events/AgentEvents.js.map +1 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +5 -0
- package/dist/events/index.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +98 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/zendesk.d.ts +35 -0
- package/dist/interfaces/zendesk.d.ts.map +1 -0
- package/dist/interfaces/zendesk.js +219 -0
- package/dist/interfaces/zendesk.js.map +1 -0
- package/dist/internalTools/appActionRunnerTool.d.ts +5 -0
- package/dist/internalTools/appActionRunnerTool.d.ts.map +1 -0
- package/dist/internalTools/appActionRunnerTool.js +88 -0
- package/dist/internalTools/appActionRunnerTool.js.map +1 -0
- package/dist/internalTools/documentExtraction/documentExtraction.d.ts +129 -0
- package/dist/internalTools/documentExtraction/documentExtraction.d.ts.map +1 -0
- package/dist/internalTools/documentExtraction/documentExtraction.js +736 -0
- package/dist/internalTools/documentExtraction/documentExtraction.js.map +1 -0
- package/dist/internalTools/documentExtraction/types.d.ts +29 -0
- package/dist/internalTools/documentExtraction/types.d.ts.map +1 -0
- package/dist/internalTools/documentExtraction/types.js +35 -0
- package/dist/internalTools/documentExtraction/types.js.map +1 -0
- package/dist/internalTools/libraryActionRunnerTool.d.ts +4 -0
- package/dist/internalTools/libraryActionRunnerTool.d.ts.map +1 -0
- package/dist/internalTools/libraryActionRunnerTool.js +53 -0
- package/dist/internalTools/libraryActionRunnerTool.js.map +1 -0
- package/dist/internalTools/retell.d.ts +12 -0
- package/dist/internalTools/retell.d.ts.map +1 -0
- package/dist/internalTools/retell.js +54 -0
- package/dist/internalTools/retell.js.map +1 -0
- package/dist/internalTools/sendPlaceholderMessage.d.ts +14 -0
- package/dist/internalTools/sendPlaceholderMessage.d.ts.map +1 -0
- package/dist/internalTools/sendPlaceholderMessage.js +61 -0
- package/dist/internalTools/sendPlaceholderMessage.js.map +1 -0
- package/dist/internalTools/timer.d.ts +99 -0
- package/dist/internalTools/timer.d.ts.map +1 -0
- package/dist/internalTools/timer.js +139 -0
- package/dist/internalTools/timer.js.map +1 -0
- package/dist/internalTools/voice/escalateVoiceCall.d.ts +2 -0
- package/dist/internalTools/voice/escalateVoiceCall.d.ts.map +1 -0
- package/dist/internalTools/voice/escalateVoiceCall.js +52 -0
- package/dist/internalTools/voice/escalateVoiceCall.js.map +1 -0
- package/dist/internalTools/voice/retell.d.ts +12 -0
- package/dist/internalTools/voice/retell.d.ts.map +1 -0
- package/dist/internalTools/voice/retell.js +54 -0
- package/dist/internalTools/voice/retell.js.map +1 -0
- package/dist/internalTools/voice/sendPlaceholderMessage.d.ts +14 -0
- package/dist/internalTools/voice/sendPlaceholderMessage.d.ts.map +1 -0
- package/dist/internalTools/voice/sendPlaceholderMessage.js +61 -0
- package/dist/internalTools/voice/sendPlaceholderMessage.js.map +1 -0
- package/dist/interrupts/BaseInterruptSessionManager.d.ts +49 -0
- package/dist/interrupts/BaseInterruptSessionManager.d.ts.map +1 -0
- package/dist/interrupts/BaseInterruptSessionManager.js +34 -0
- package/dist/interrupts/BaseInterruptSessionManager.js.map +1 -0
- package/dist/interrupts/MemoryInterruptSessionManager.d.ts +14 -0
- package/dist/interrupts/MemoryInterruptSessionManager.d.ts.map +1 -0
- package/dist/interrupts/MemoryInterruptSessionManager.js +60 -0
- package/dist/interrupts/MemoryInterruptSessionManager.js.map +1 -0
- package/dist/interrupts/MindedInterruptSessionManager.d.ts +13 -0
- package/dist/interrupts/MindedInterruptSessionManager.d.ts.map +1 -0
- package/dist/interrupts/MindedInterruptSessionManager.js +162 -0
- package/dist/interrupts/MindedInterruptSessionManager.js.map +1 -0
- package/dist/interrupts/interruptSessionManagerFactory.d.ts +3 -0
- package/dist/interrupts/interruptSessionManagerFactory.d.ts.map +1 -0
- package/dist/interrupts/interruptSessionManagerFactory.js +56 -0
- package/dist/interrupts/interruptSessionManagerFactory.js.map +1 -0
- package/dist/llm/createLlmInstance.d.ts +3 -0
- package/dist/llm/createLlmInstance.d.ts.map +1 -0
- package/dist/llm/createLlmInstance.js +31 -0
- package/dist/llm/createLlmInstance.js.map +1 -0
- package/dist/nodes/addAppToolNode.d.ts +13 -0
- package/dist/nodes/addAppToolNode.d.ts.map +1 -0
- package/dist/nodes/addAppToolNode.js +87 -0
- package/dist/nodes/addAppToolNode.js.map +1 -0
- package/dist/nodes/addBrowserTaskNode.d.ts +13 -0
- package/dist/nodes/addBrowserTaskNode.d.ts.map +1 -0
- package/dist/nodes/addBrowserTaskNode.js +167 -0
- package/dist/nodes/addBrowserTaskNode.js.map +1 -0
- package/dist/nodes/addBrowserTaskRunNode.d.ts +13 -0
- package/dist/nodes/addBrowserTaskRunNode.d.ts.map +1 -0
- package/dist/nodes/addBrowserTaskRunNode.js +167 -0
- package/dist/nodes/addBrowserTaskRunNode.js.map +1 -0
- package/dist/nodes/addHumanInTheLoopNode.d.ts +9 -0
- package/dist/nodes/addHumanInTheLoopNode.d.ts.map +1 -0
- package/dist/nodes/addHumanInTheLoopNode.js +22 -0
- package/dist/nodes/addHumanInTheLoopNode.js.map +1 -0
- package/dist/nodes/addJumpToNode.d.ts +7 -0
- package/dist/nodes/addJumpToNode.d.ts.map +1 -0
- package/dist/nodes/addJumpToNode.js +24 -0
- package/dist/nodes/addJumpToNode.js.map +1 -0
- package/dist/nodes/addJunctionNode.d.ts +7 -0
- package/dist/nodes/addJunctionNode.d.ts.map +1 -0
- package/dist/nodes/addJunctionNode.js +20 -0
- package/dist/nodes/addJunctionNode.js.map +1 -0
- package/dist/nodes/addPromptNode.d.ts +18 -0
- package/dist/nodes/addPromptNode.d.ts.map +1 -0
- package/dist/nodes/addPromptNode.js +253 -0
- package/dist/nodes/addPromptNode.js.map +1 -0
- package/dist/nodes/addRpaNode.d.ts +18 -0
- package/dist/nodes/addRpaNode.d.ts.map +1 -0
- package/dist/nodes/addRpaNode.js +180 -0
- package/dist/nodes/addRpaNode.js.map +1 -0
- package/dist/nodes/addToolNode.d.ts +13 -0
- package/dist/nodes/addToolNode.d.ts.map +1 -0
- package/dist/nodes/addToolNode.js +67 -0
- package/dist/nodes/addToolNode.js.map +1 -0
- package/dist/nodes/addToolRunNode.d.ts +17 -0
- package/dist/nodes/addToolRunNode.d.ts.map +1 -0
- package/dist/nodes/addToolRunNode.js +59 -0
- package/dist/nodes/addToolRunNode.js.map +1 -0
- package/dist/nodes/addTriggerNode.d.ts +7 -0
- package/dist/nodes/addTriggerNode.d.ts.map +1 -0
- package/dist/nodes/addTriggerNode.js +25 -0
- package/dist/nodes/addTriggerNode.js.map +1 -0
- package/dist/nodes/compilePrompt.d.ts +5 -0
- package/dist/nodes/compilePrompt.d.ts.map +1 -0
- package/dist/nodes/compilePrompt.js +76 -0
- package/dist/nodes/compilePrompt.js.map +1 -0
- package/dist/nodes/nodeFactory.d.ts +16 -0
- package/dist/nodes/nodeFactory.d.ts.map +1 -0
- package/dist/nodes/nodeFactory.js +45 -0
- package/dist/nodes/nodeFactory.js.map +1 -0
- package/dist/nodes/rpaStepsExecutor.d.ts +5 -0
- package/dist/nodes/rpaStepsExecutor.d.ts.map +1 -0
- package/dist/nodes/rpaStepsExecutor.js +156 -0
- package/dist/nodes/rpaStepsExecutor.js.map +1 -0
- package/dist/platform/config.d.ts +16 -0
- package/dist/platform/config.d.ts.map +1 -0
- package/dist/platform/config.js +80 -0
- package/dist/platform/config.js.map +1 -0
- package/dist/platform/mindedCheckpointSaver.d.ts +10 -0
- package/dist/platform/mindedCheckpointSaver.d.ts.map +1 -0
- package/dist/platform/mindedCheckpointSaver.js +137 -0
- package/dist/platform/mindedCheckpointSaver.js.map +1 -0
- package/dist/platform/mindedConnection.d.ts +15 -0
- package/dist/platform/mindedConnection.d.ts.map +1 -0
- package/dist/platform/mindedConnection.js +254 -0
- package/dist/platform/mindedConnection.js.map +1 -0
- package/dist/platform/mindedConnectionTypes.d.ts +404 -0
- package/dist/platform/mindedConnectionTypes.d.ts.map +1 -0
- package/dist/platform/mindedConnectionTypes.js +51 -0
- package/dist/platform/mindedConnectionTypes.js.map +1 -0
- package/dist/platform/models/mindedChatOpenAI.d.ts +20 -0
- package/dist/platform/models/mindedChatOpenAI.d.ts.map +1 -0
- package/dist/platform/models/mindedChatOpenAI.js +32 -0
- package/dist/platform/models/mindedChatOpenAI.js.map +1 -0
- package/dist/platform/models/parallelWrapper.d.ts +17 -0
- package/dist/platform/models/parallelWrapper.d.ts.map +1 -0
- package/dist/platform/models/parallelWrapper.js +105 -0
- package/dist/platform/models/parallelWrapper.js.map +1 -0
- package/dist/platform/piiGateway/gateway.d.ts +14 -0
- package/dist/platform/piiGateway/gateway.d.ts.map +1 -0
- package/dist/platform/piiGateway/gateway.js +117 -0
- package/dist/platform/piiGateway/gateway.js.map +1 -0
- package/dist/platform/piiGateway/index.d.ts +3 -0
- package/dist/platform/piiGateway/index.d.ts.map +1 -0
- package/dist/platform/piiGateway/index.js +7 -0
- package/dist/platform/piiGateway/index.js.map +1 -0
- package/dist/platform/piiGateway/types.d.ts +27 -0
- package/dist/platform/piiGateway/types.d.ts.map +1 -0
- package/dist/platform/piiGateway/types.js +3 -0
- package/dist/platform/piiGateway/types.js.map +1 -0
- package/dist/platform/toolExecutor.d.ts +29 -0
- package/dist/platform/toolExecutor.d.ts.map +1 -0
- package/dist/platform/toolExecutor.js +84 -0
- package/dist/platform/toolExecutor.js.map +1 -0
- package/dist/platform/utils/parseAttachments.d.ts +14 -0
- package/dist/platform/utils/parseAttachments.d.ts.map +1 -0
- package/dist/platform/utils/parseAttachments.js +53 -0
- package/dist/platform/utils/parseAttachments.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.d.ts +15 -0
- package/dist/playbooks/playbooks.d.ts.map +1 -0
- package/dist/playbooks/playbooks.js +208 -0
- package/dist/playbooks/playbooks.js.map +1 -0
- package/dist/toolsLibrary/classifier.d.ts +74 -0
- package/dist/toolsLibrary/classifier.d.ts.map +1 -0
- package/dist/toolsLibrary/classifier.js +256 -0
- package/dist/toolsLibrary/classifier.js.map +1 -0
- package/dist/toolsLibrary/extraction.d.ts +83 -0
- package/dist/toolsLibrary/extraction.d.ts.map +1 -0
- package/dist/toolsLibrary/extraction.js +328 -0
- package/dist/toolsLibrary/extraction.js.map +1 -0
- package/dist/toolsLibrary/index.d.ts +9 -0
- package/dist/toolsLibrary/index.d.ts.map +1 -0
- package/dist/toolsLibrary/index.js +46 -0
- package/dist/toolsLibrary/index.js.map +1 -0
- package/dist/toolsLibrary/parseDocument.d.ts +30 -0
- package/dist/toolsLibrary/parseDocument.d.ts.map +1 -0
- package/dist/toolsLibrary/parseDocument.js +119 -0
- package/dist/toolsLibrary/parseDocument.js.map +1 -0
- package/dist/triggers/triggerTypeToDefaultMessage.d.ts +4 -0
- package/dist/triggers/triggerTypeToDefaultMessage.d.ts.map +1 -0
- package/dist/triggers/triggerTypeToDefaultMessage.js +10 -0
- package/dist/triggers/triggerTypeToDefaultMessage.js.map +1 -0
- package/dist/types/Agent.types.d.ts +60 -0
- package/dist/types/Agent.types.d.ts.map +1 -0
- package/dist/types/Agent.types.js +9 -0
- package/dist/types/Agent.types.js.map +1 -0
- package/dist/types/Flows.types.d.ts +232 -0
- package/dist/types/Flows.types.d.ts.map +1 -0
- package/dist/types/Flows.types.js +65 -0
- package/dist/types/Flows.types.js.map +1 -0
- package/dist/types/LLM.types.d.ts +7 -0
- package/dist/types/LLM.types.d.ts.map +1 -0
- package/dist/types/LLM.types.js +11 -0
- package/dist/types/LLM.types.js.map +1 -0
- package/dist/types/LangGraph.types.d.ts +45 -0
- package/dist/types/LangGraph.types.d.ts.map +1 -0
- package/dist/types/LangGraph.types.js +77 -0
- package/dist/types/LangGraph.types.js.map +1 -0
- package/dist/types/Platform.types.d.ts +7 -0
- package/dist/types/Platform.types.d.ts.map +1 -0
- package/dist/types/Platform.types.js +11 -0
- package/dist/types/Platform.types.js.map +1 -0
- package/dist/types/Tools.types.d.ts +26 -0
- package/dist/types/Tools.types.d.ts.map +1 -0
- package/dist/types/Tools.types.js +3 -0
- package/dist/types/Tools.types.js.map +1 -0
- package/dist/types/Voice.types.d.ts +5 -0
- package/dist/types/Voice.types.d.ts.map +1 -0
- package/dist/types/Voice.types.js +3 -0
- package/dist/types/Voice.types.js.map +1 -0
- package/dist/utils/agentUtils.d.ts +5 -0
- package/dist/utils/agentUtils.d.ts.map +1 -0
- package/dist/utils/agentUtils.js +97 -0
- package/dist/utils/agentUtils.js.map +1 -0
- package/dist/utils/extractStateMemoryResponse.d.ts +5 -0
- package/dist/utils/extractStateMemoryResponse.d.ts.map +1 -0
- package/dist/utils/extractStateMemoryResponse.js +91 -0
- package/dist/utils/extractStateMemoryResponse.js.map +1 -0
- package/dist/utils/history.d.ts +4 -0
- package/dist/utils/history.d.ts.map +1 -0
- package/dist/utils/history.js +33 -0
- package/dist/utils/history.js.map +1 -0
- package/dist/utils/logger.d.ts +3 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +39 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/schemaUtils.d.ts +15 -0
- package/dist/utils/schemaUtils.d.ts.map +1 -0
- package/dist/utils/schemaUtils.js +56 -0
- package/dist/utils/schemaUtils.js.map +1 -0
- package/dist/utils/wait.d.ts +2 -0
- package/dist/utils/wait.d.ts.map +1 -0
- package/dist/utils/wait.js +6 -0
- package/dist/utils/wait.js.map +1 -0
- package/dist/voice/elevenLabsUtils.d.ts +65 -0
- package/dist/voice/elevenLabsUtils.d.ts.map +1 -0
- package/dist/voice/elevenLabsUtils.js +4 -0
- package/dist/voice/elevenLabsUtils.js.map +1 -0
- package/dist/voice/voiceSession.d.ts +37 -0
- package/dist/voice/voiceSession.d.ts.map +1 -0
- package/dist/voice/voiceSession.js +306 -0
- package/dist/voice/voiceSession.js.map +1 -0
- package/docs/.gitbook/assets/ADLC.png +0 -0
- package/docs/.gitbook/assets/PII-masking.png +0 -0
- package/docs/.gitbook/assets/image.png +0 -0
- package/docs/.gitbook/assets/on-prem.svg +4 -0
- package/docs/README.md +54 -0
- package/docs/SUMMARY.md +56 -0
- package/docs/examples/order-refund-flow.md +566 -0
- package/docs/getting-started/environment-configuration.md +158 -0
- package/docs/getting-started/installation.md +44 -0
- package/docs/getting-started/project-configuration.md +206 -0
- package/docs/getting-started/quick-start.md +262 -0
- package/docs/integrations/zendesk.md +554 -0
- package/docs/low-code-editor/edges.md +396 -0
- package/docs/low-code-editor/flows.md +74 -0
- package/docs/low-code-editor/nodes.md +367 -0
- package/docs/low-code-editor/playbooks.md +280 -0
- package/docs/low-code-editor/tools.md +358 -0
- package/docs/low-code-editor/triggers.md +182 -0
- package/docs/platform/on-prem.md +182 -0
- package/docs/platform/operator.md +89 -0
- package/docs/platform/pii-masking.md +221 -0
- package/docs/platform/scenarios.md +43 -0
- package/docs/platform/secrets.md +99 -0
- package/docs/platform/sso.md +27 -0
- package/docs/resources/your-first-eval.md +108 -0
- package/docs/sdk/agent-api.md +540 -0
- package/docs/sdk/debugging.md +80 -0
- package/docs/sdk/events.md +595 -0
- package/docs/sdk/logging.md +72 -0
- package/docs/sdk/memory.md +271 -0
- package/docs/sdk/parallel-llm.md +242 -0
- package/docs/sdk/vectorstore-query.md +60 -0
- package/docs/tooling/classifier.md +217 -0
- package/docs/tooling/document-processing.md +389 -0
- package/docs/tooling/extraction.md +78 -0
- package/docs/tooling/timers.md +61 -0
- package/package.json +73 -0
- package/src/agent.ts +1019 -0
- package/src/browserTask/executeBrowserTask.py +153 -0
- package/src/browserTask/executeBrowserTask.ts +253 -0
- package/src/browserTask/localBrowserTask.ts +300 -0
- package/src/browserTask/profile/Default/Extension Rules/000003.log +0 -0
- package/src/browserTask/profile/Default/Extension Scripts/000003.log +0 -0
- package/src/browserTask/profile/Default/Extension State/000003.log +0 -0
- package/src/browserTask/profile/Default/GCM Store/000003.log +0 -0
- package/src/browserTask/profile/Default/Local Storage/leveldb/000004.log +0 -0
- package/src/browserTask/profile/Default/Session Storage/000003.log +0 -0
- package/src/browserTask/profile/Default/Site Characteristics Database/000003.log +0 -0
- package/src/browserTask/profile/Default/Sync Data/LevelDB/000003.log +0 -0
- package/src/browserTask/profile/Default/shared_proto_db/000003.log +0 -0
- package/src/browserTask/profile/Default/shared_proto_db/metadata/000003.log +0 -0
- package/src/browserTask/types.ts +37 -0
- package/src/checkpointer/checkpointSaverFactory.ts +18 -0
- package/src/cli/index.ts +188 -0
- package/src/cli/lambdaHandlerTemplate.ts +78 -0
- package/src/cli/localOperatorSetup.ts +308 -0
- package/src/debugging/index.ts +1 -0
- package/src/debugging/llmCallbackHandler.ts +125 -0
- package/src/edges/createDirectEdge.ts +22 -0
- package/src/edges/createLogicalRouter.ts +182 -0
- package/src/edges/createPromptRouter.ts +213 -0
- package/src/edges/edgeFactory.ts +167 -0
- package/src/events/AgentEvents.ts +58 -0
- package/src/events/index.ts +3 -0
- package/src/index.ts +105 -0
- package/src/interfaces/zendesk.ts +212 -0
- package/src/internalTools/appActionRunnerTool.ts +68 -0
- package/src/internalTools/documentExtraction/documentExtraction.ts +804 -0
- package/src/internalTools/documentExtraction/types.ts +59 -0
- package/src/internalTools/libraryActionRunnerTool.ts +62 -0
- package/src/internalTools/timer.ts +125 -0
- package/src/internalTools/voice/escalateVoiceCall.ts +15 -0
- package/src/internalTools/voice/retell.ts +28 -0
- package/src/internalTools/voice/sendPlaceholderMessage.ts +27 -0
- package/src/interrupts/BaseInterruptSessionManager.ts +80 -0
- package/src/interrupts/MemoryInterruptSessionManager.ts +63 -0
- package/src/interrupts/MindedInterruptSessionManager.ts +163 -0
- package/src/interrupts/interruptSessionManagerFactory.ts +20 -0
- package/src/llm/createLlmInstance.ts +33 -0
- package/src/nodes/addAppToolNode.ts +111 -0
- package/src/nodes/addBrowserTaskNode.ts +191 -0
- package/src/nodes/addBrowserTaskRunNode.ts +190 -0
- package/src/nodes/addHumanInTheLoopNode.ts +26 -0
- package/src/nodes/addJumpToNode.ts +26 -0
- package/src/nodes/addJunctionNode.ts +21 -0
- package/src/nodes/addPromptNode.ts +305 -0
- package/src/nodes/addRpaNode.ts +217 -0
- package/src/nodes/addToolNode.ts +84 -0
- package/src/nodes/addToolRunNode.ts +80 -0
- package/src/nodes/addTriggerNode.ts +27 -0
- package/src/nodes/compilePrompt.ts +44 -0
- package/src/nodes/nodeFactory.ts +61 -0
- package/src/nodes/rpaStepsExecutor.ts +175 -0
- package/src/platform/config.ts +89 -0
- package/src/platform/mindedCheckpointSaver.ts +146 -0
- package/src/platform/mindedConnection.ts +250 -0
- package/src/platform/mindedConnectionTypes.ts +495 -0
- package/src/platform/models/mindedChatOpenAI.ts +49 -0
- package/src/platform/models/parallelWrapper.ts +141 -0
- package/src/platform/piiGateway/gateway.ts +103 -0
- package/src/platform/piiGateway/index.ts +5 -0
- package/src/platform/piiGateway/types.ts +29 -0
- package/src/platform/toolExecutor.ts +106 -0
- package/src/platform/utils/parseAttachments.ts +56 -0
- package/src/platform/utils/tools.ts +55 -0
- package/src/playbooks/playbooks.ts +200 -0
- package/src/toolsLibrary/classifier.ts +326 -0
- package/src/toolsLibrary/extraction.ts +393 -0
- package/src/toolsLibrary/index.ts +10 -0
- package/src/toolsLibrary/parseDocument.ts +129 -0
- package/src/triggers/triggerTypeToDefaultMessage.ts +9 -0
- package/src/types/Agent.types.ts +73 -0
- package/src/types/Flows.types.ts +262 -0
- package/src/types/LLM.types.ts +15 -0
- package/src/types/LangGraph.types.ts +86 -0
- package/src/types/Platform.types.ts +6 -0
- package/src/types/Tools.types.ts +28 -0
- package/src/types/Voice.types.ts +4 -0
- package/src/utils/agentUtils.ts +69 -0
- package/src/utils/history.ts +38 -0
- package/src/utils/logger.ts +38 -0
- package/src/utils/schemaUtils.ts +68 -0
- package/src/utils/wait.ts +1 -0
- package/src/voice/elevenLabsUtils.ts +81 -0
- package/src/voice/voiceSession.ts +309 -0
package/src/agent.ts
ADDED
|
@@ -0,0 +1,1019 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Flow,
|
|
3
|
+
NodeType,
|
|
4
|
+
Node,
|
|
5
|
+
EdgeType,
|
|
6
|
+
KnownTriggerNames,
|
|
7
|
+
TriggerType,
|
|
8
|
+
VoiceTriggerNode,
|
|
9
|
+
internalNodesSuffix,
|
|
10
|
+
AppToolNode,
|
|
11
|
+
} from './types/Flows.types';
|
|
12
|
+
|
|
13
|
+
import { Tool } from './types/Tools.types';
|
|
14
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
15
|
+
import { BaseLanguageModel } from '@langchain/core/language_models/base';
|
|
16
|
+
import { Command, StateGraph } from '@langchain/langgraph';
|
|
17
|
+
import { BaseCheckpointSaver } from '@langchain/langgraph';
|
|
18
|
+
import { nodeFactory } from './nodes/nodeFactory';
|
|
19
|
+
import { CompiledGraph, PreCompiledGraph, State, createStateAnnotation, stateAnnotation } from './types/LangGraph.types';
|
|
20
|
+
import { edgeFactory } from './edges/edgeFactory';
|
|
21
|
+
import { AgentEventRequestPayloads, AgentEventResponsePayloads, AgentEvents } from './events/AgentEvents';
|
|
22
|
+
import { z } from 'zod';
|
|
23
|
+
import * as mindedConnection from './platform/mindedConnection';
|
|
24
|
+
import { InvokeMessage, mindedConnectionSocketMessageType, UpdateStateRequest } from './platform/mindedConnectionTypes';
|
|
25
|
+
import { AgentInvokeParams, MindedSDKConfig, SessionType } from './types/Agent.types';
|
|
26
|
+
import { createLlmInstance } from './llm/createLlmInstance';
|
|
27
|
+
import { createCheckpointSaver } from './checkpointer/checkpointSaverFactory';
|
|
28
|
+
import { getConfig } from './platform/config';
|
|
29
|
+
import { InterruptPayload, InterruptSessionManager, InterruptType } from './interrupts/BaseInterruptSessionManager';
|
|
30
|
+
import { createInterruptSessionManager } from './interrupts/interruptSessionManagerFactory';
|
|
31
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
32
|
+
import triggerTypeToDefaultMessage from './triggers/triggerTypeToDefaultMessage';
|
|
33
|
+
import appActionRunnerToolCreator from './internalTools/appActionRunnerTool';
|
|
34
|
+
import { VoiceSession } from './voice/voiceSession';
|
|
35
|
+
import { BaseVoiceMessage, OnVoiceAudioOut, VectorStoreQueryRequest, VectorStoreQueryResponse } from './platform/mindedConnectionTypes';
|
|
36
|
+
import { PIIGateway, PIIGatewayInstance } from './platform/piiGateway';
|
|
37
|
+
import { logger } from './utils/logger';
|
|
38
|
+
import { combinePlaybooks, loadPlaybooks, Playbook } from './playbooks/playbooks';
|
|
39
|
+
import { createTriggerHistoryStep } from './utils/history';
|
|
40
|
+
import { timerHandlers } from './internalTools/timer';
|
|
41
|
+
import { parseAttachments, combineContentWithAttachments } from './platform/utils/parseAttachments';
|
|
42
|
+
import { ToolExecutor, ToolExecutionRequest, ToolExecutionResponse } from './platform/toolExecutor';
|
|
43
|
+
import { initLibraryActionsRunnerTools, loadFlows } from './utils/agentUtils';
|
|
44
|
+
import { Document } from '@langchain/core/documents';
|
|
45
|
+
import { getInitialState } from './types/LangGraph.types';
|
|
46
|
+
import { compilePrompt } from './nodes/compilePrompt';
|
|
47
|
+
|
|
48
|
+
type CreateAgentParams<Memory> = {
|
|
49
|
+
memorySchema: z.ZodSchema;
|
|
50
|
+
config: MindedSDKConfig;
|
|
51
|
+
tools: Tool<any, Memory>[];
|
|
52
|
+
platformToken?: string;
|
|
53
|
+
memorySaver?: BaseCheckpointSaver;
|
|
54
|
+
interruptSessionManager?: InterruptSessionManager;
|
|
55
|
+
// A parser to extract unique sessionId from the trigger
|
|
56
|
+
parseSessionIdFromTrigger?: (trigger: any) => string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The main Agent class that orchestrates flows, tools, and integrations with the Minded platform.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const agent = new Agent({
|
|
65
|
+
* memorySchema: z.object({
|
|
66
|
+
* userName: z.string().optional(),
|
|
67
|
+
* preferences: z.record(z.any()).optional()
|
|
68
|
+
* }),
|
|
69
|
+
* config: {
|
|
70
|
+
* flows: ['./src/flows'],
|
|
71
|
+
* llm: { provider: 'openai', model: 'gpt-4' }
|
|
72
|
+
* },
|
|
73
|
+
* tools: [myCustomTool]
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export class Agent {
|
|
78
|
+
private memorySchema: z.ZodSchema;
|
|
79
|
+
private stateAnnotation: ReturnType<typeof createStateAnnotation>;
|
|
80
|
+
public flows!: Flow[];
|
|
81
|
+
public tools!: Tool<any, any>[];
|
|
82
|
+
/**
|
|
83
|
+
* Internal tools
|
|
84
|
+
*/
|
|
85
|
+
public llm!: BaseLanguageModel;
|
|
86
|
+
// Remove the mindedConnection property since it's now a singleton module
|
|
87
|
+
|
|
88
|
+
// Langgraph memory saver. In memory for local development, Custom for Platform
|
|
89
|
+
private checkpointer!: BaseCheckpointSaver;
|
|
90
|
+
// Interrupt session manager. In memory for local development, Custom for Platform
|
|
91
|
+
public interruptSessionManager!: InterruptSessionManager;
|
|
92
|
+
// Langgraph compiled graph
|
|
93
|
+
public compiledGraph!: CompiledGraph;
|
|
94
|
+
// Cache for secrets to avoid repeated API calls
|
|
95
|
+
private secretsCache: Record<string, string> | null = null;
|
|
96
|
+
public config: MindedSDKConfig;
|
|
97
|
+
|
|
98
|
+
// PII gateway instance
|
|
99
|
+
private _piiGateway: PIIGatewayInstance | null = null;
|
|
100
|
+
public playbooks: Playbook[] = [];
|
|
101
|
+
|
|
102
|
+
// Tool executor for standalone tool execution
|
|
103
|
+
private toolExecutor: ToolExecutor;
|
|
104
|
+
|
|
105
|
+
// Getter for PII Gateway that ensures it's available
|
|
106
|
+
public get piiGateway(): PIIGatewayInstance {
|
|
107
|
+
if (!this._piiGateway) {
|
|
108
|
+
throw new Error('PII Gateway is not initialized. Make sure the agent is connected to the Minded platform.');
|
|
109
|
+
}
|
|
110
|
+
return this._piiGateway;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Event handlers storage keyed by event name. Handlers can optionally return a value.
|
|
114
|
+
private eventHandlers: {
|
|
115
|
+
[K in keyof AgentEventRequestPayloads<z.infer<typeof this.memorySchema>>]?: Array<
|
|
116
|
+
(payload: AgentEventRequestPayloads<z.infer<typeof this.memorySchema>>[K]) => any | Promise<any>
|
|
117
|
+
>;
|
|
118
|
+
} = {};
|
|
119
|
+
|
|
120
|
+
private initialized = false;
|
|
121
|
+
private initPromise: Promise<void> | null = null;
|
|
122
|
+
private startingNodeId: string | null = null;
|
|
123
|
+
public voiceSessions: Map<string, VoiceSession> = new Map();
|
|
124
|
+
|
|
125
|
+
// Session storage
|
|
126
|
+
public parseSessionIdFromTrigger?: (trigger: any, triggerName: string) => string;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Create a new Agent instance.
|
|
130
|
+
*
|
|
131
|
+
* @param params - Configuration parameters for the agent containing:
|
|
132
|
+
* - memorySchema: Zod schema defining the structure of the agent's memory
|
|
133
|
+
* - config: SDK configuration including flows directory and LLM settings
|
|
134
|
+
* - tools: Array of custom tools to be available to the agent
|
|
135
|
+
* - platformToken: Optional token for platform authentication
|
|
136
|
+
* - memorySaver: Optional custom checkpoint saver for conversation memory
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* const agent = new Agent({
|
|
141
|
+
* memorySchema: z.object({
|
|
142
|
+
* userName: z.string().optional(),
|
|
143
|
+
* conversationHistory: z.array(z.string()).optional()
|
|
144
|
+
* }),
|
|
145
|
+
* config: {
|
|
146
|
+
* flows: ['./src/flows'],
|
|
147
|
+
* llm: {
|
|
148
|
+
* provider: 'openai',
|
|
149
|
+
* model: 'gpt-4-turbo'
|
|
150
|
+
* }
|
|
151
|
+
* },
|
|
152
|
+
* tools: [
|
|
153
|
+
* weatherTool,
|
|
154
|
+
* databaseTool
|
|
155
|
+
* ]
|
|
156
|
+
* });
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
constructor(params: CreateAgentParams<z.infer<typeof this.memorySchema>>) {
|
|
160
|
+
const { memorySchema } = params;
|
|
161
|
+
this.memorySchema = memorySchema;
|
|
162
|
+
this.stateAnnotation = createStateAnnotation(memorySchema);
|
|
163
|
+
this.initPromise = this.init(params);
|
|
164
|
+
this.config = params.config;
|
|
165
|
+
this.toolExecutor = new ToolExecutor(this);
|
|
166
|
+
this.parseSessionIdFromTrigger = params.parseSessionIdFromTrigger;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
private async init(params: CreateAgentParams<z.infer<typeof this.memorySchema>>): Promise<void> {
|
|
170
|
+
try {
|
|
171
|
+
const { config, tools, memorySaver, interruptSessionManager } = params;
|
|
172
|
+
const { runLocally } = getConfig();
|
|
173
|
+
if (!runLocally) {
|
|
174
|
+
await mindedConnection.start();
|
|
175
|
+
|
|
176
|
+
// Initialize PII gateway
|
|
177
|
+
this._piiGateway = new PIIGateway();
|
|
178
|
+
|
|
179
|
+
mindedConnection.on(mindedConnectionSocketMessageType.INVOKE, async (message) => {
|
|
180
|
+
const invokeMessage = message as InvokeMessage;
|
|
181
|
+
try {
|
|
182
|
+
const result = await this.invoke({
|
|
183
|
+
triggerBody: invokeMessage.triggerBody,
|
|
184
|
+
triggerName: invokeMessage.triggerName,
|
|
185
|
+
appName: invokeMessage.appName,
|
|
186
|
+
});
|
|
187
|
+
return result;
|
|
188
|
+
} catch (err: any) {
|
|
189
|
+
logger.error({ message: '[Agent] Error invoking trigger', err });
|
|
190
|
+
return {
|
|
191
|
+
errorMessage: err.message,
|
|
192
|
+
error: 'Error invoking the agent',
|
|
193
|
+
errorStack: err.stack,
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
mindedConnection.on(mindedConnectionSocketMessageType.TIMER_TRIGGER, async (timerTriggerMessage) => {
|
|
199
|
+
// Get handler for the specific timer name
|
|
200
|
+
const handlerEntry = timerHandlers.get(timerTriggerMessage.timerName);
|
|
201
|
+
|
|
202
|
+
// Call the handler if it exists
|
|
203
|
+
if (handlerEntry) {
|
|
204
|
+
await handlerEntry.handler({
|
|
205
|
+
sessionId: timerTriggerMessage.sessionId,
|
|
206
|
+
payload: timerTriggerMessage.eventArgs,
|
|
207
|
+
state: await this.getState(timerTriggerMessage.sessionId),
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
mindedConnection.on(mindedConnectionSocketMessageType.RESTORE_CHECKPOINT, async (restoreCheckpointMessage) => {
|
|
213
|
+
await this.restoreCheckpoint(restoreCheckpointMessage.sessionId, restoreCheckpointMessage.checkpointId);
|
|
214
|
+
return { success: true };
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
mindedConnection.on(mindedConnectionSocketMessageType.SDK_VERSION_MISMATCH, (data) => {
|
|
218
|
+
logger.warn(`\x1b[33mMindedJS SDK outdated, we recommend upgrading ${data.currentVersion}->${data.requiredVersion}\x1b[0m`);
|
|
219
|
+
logger.warn(`\x1b[33mnpm install @minded-ai/mindedjs / yarn upgrade @minded-ai/mindedjs\x1b[0m`);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
mindedConnection.on(mindedConnectionSocketMessageType.UPDATE_STATE, (message) => {
|
|
223
|
+
const { sessionId, state } = message as UpdateStateRequest;
|
|
224
|
+
this.updateState({ sessionId, state });
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// Handle tool execution requests from browser-use
|
|
228
|
+
mindedConnection.on(mindedConnectionSocketMessageType.EXECUTE_TOOL, async (message) => {
|
|
229
|
+
const request = message as ToolExecutionRequest;
|
|
230
|
+
const requestId = message.requestId;
|
|
231
|
+
logger.debug({ msg: '[Agent] Received tool execution request', toolName: request.toolName, sessionId: request.sessionId });
|
|
232
|
+
|
|
233
|
+
try {
|
|
234
|
+
const response = await this.executeTool(request);
|
|
235
|
+
// Send response back via socket
|
|
236
|
+
return {
|
|
237
|
+
...response,
|
|
238
|
+
requestId,
|
|
239
|
+
};
|
|
240
|
+
} catch (err) {
|
|
241
|
+
logger.error({ message: '[Agent] Error executing tool', err });
|
|
242
|
+
return {
|
|
243
|
+
error: err instanceof Error ? err.message : String(err),
|
|
244
|
+
requestId,
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const [, flows, playbooks] = await Promise.all([this.loadSecrets(), loadFlows(config.flows), loadPlaybooks(config.playbooks)]);
|
|
251
|
+
|
|
252
|
+
this.playbooks = playbooks;
|
|
253
|
+
this.flows = flows;
|
|
254
|
+
this.validate();
|
|
255
|
+
const appActionsRunnerTools = this.initAppActionsRunnerTools();
|
|
256
|
+
const libraryActionsRunnerTools = initLibraryActionsRunnerTools(flows);
|
|
257
|
+
this.tools = [...tools, ...appActionsRunnerTools, ...libraryActionsRunnerTools];
|
|
258
|
+
|
|
259
|
+
// Register tools with the tool executor
|
|
260
|
+
this.toolExecutor.registerTools(this.tools);
|
|
261
|
+
|
|
262
|
+
this.checkpointer = memorySaver || createCheckpointSaver();
|
|
263
|
+
this.interruptSessionManager = interruptSessionManager || createInterruptSessionManager();
|
|
264
|
+
|
|
265
|
+
// call here methods that needs environment variables to be loaded
|
|
266
|
+
this.llm = createLlmInstance(config.llm);
|
|
267
|
+
this.compiledGraph = this.initializeGraph();
|
|
268
|
+
this.initialized = true;
|
|
269
|
+
|
|
270
|
+
const flowHasVoiceTrigger = this.flows.some((flow) =>
|
|
271
|
+
flow.nodes.some((node) => node.type === NodeType.TRIGGER && node.triggerType === TriggerType.VOICE),
|
|
272
|
+
);
|
|
273
|
+
if (flowHasVoiceTrigger) {
|
|
274
|
+
this.setupVoice();
|
|
275
|
+
}
|
|
276
|
+
} catch (err) {
|
|
277
|
+
this.initialized = false;
|
|
278
|
+
throw err;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
private validate() {
|
|
283
|
+
if (this.flows.length === 0) {
|
|
284
|
+
throw new Error('No flows provided');
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
private async waitForInitialization(): Promise<void> {
|
|
289
|
+
if (this.initialized) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (this.initPromise) {
|
|
293
|
+
try {
|
|
294
|
+
await this.initPromise;
|
|
295
|
+
if (!this.initialized) {
|
|
296
|
+
throw new Error('Agent initialization failed');
|
|
297
|
+
}
|
|
298
|
+
} catch (err) {
|
|
299
|
+
throw new Error(`Failed to initialize agent: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
300
|
+
}
|
|
301
|
+
} else {
|
|
302
|
+
throw new Error('Agent initialization has not started');
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
private initializeGraph(): CompiledGraph {
|
|
307
|
+
const nodes = this.flows.flatMap((flow) => flow.nodes);
|
|
308
|
+
const edges = this.flows.flatMap((flow) => flow.edges);
|
|
309
|
+
|
|
310
|
+
// Initialize the graph
|
|
311
|
+
const graph = new StateGraph(this.stateAnnotation) as PreCompiledGraph;
|
|
312
|
+
|
|
313
|
+
// Add nodes and create nodes object
|
|
314
|
+
const nodesObject: { [key: string]: Node } = {};
|
|
315
|
+
nodes.forEach((node) => {
|
|
316
|
+
// Add to nodes object
|
|
317
|
+
nodesObject[node.name] = node;
|
|
318
|
+
// Add to graph
|
|
319
|
+
nodeFactory({
|
|
320
|
+
graph,
|
|
321
|
+
node,
|
|
322
|
+
tools: this.tools,
|
|
323
|
+
llm: this.llm,
|
|
324
|
+
emit: this.emit.bind(this),
|
|
325
|
+
agent: this,
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
// Add edge from start to first node if no triggers exist
|
|
330
|
+
const hasTrigger = nodes.some((node) => node.type === NodeType.TRIGGER && node.triggerType !== TriggerType.MANUAL);
|
|
331
|
+
if (!hasTrigger) {
|
|
332
|
+
// Find the Main flow
|
|
333
|
+
const mainFlow = this.flows.find((flow) => flow.name === 'Main flow');
|
|
334
|
+
if (mainFlow && mainFlow.nodes.length > 0) {
|
|
335
|
+
this.startingNodeId = mainFlow.nodes[0].name;
|
|
336
|
+
graph.addEdge('__start__', mainFlow.nodes[0].name as any);
|
|
337
|
+
} else if (nodes.length > 0) {
|
|
338
|
+
// Fallback to first node if Main flow not found
|
|
339
|
+
this.startingNodeId = nodes[0].name;
|
|
340
|
+
graph.addEdge('__start__', nodes[0].name as any);
|
|
341
|
+
} else {
|
|
342
|
+
throw new Error('No starting node found');
|
|
343
|
+
}
|
|
344
|
+
} else {
|
|
345
|
+
nodes.forEach((node) => {
|
|
346
|
+
if (node.type === NodeType.TRIGGER && node.triggerType !== TriggerType.MANUAL) {
|
|
347
|
+
this.startingNodeId = node.name;
|
|
348
|
+
graph.addEdge('__start__', node.name as any);
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Add edges to __end__ for nodes with no outgoing edges
|
|
354
|
+
// Default behavior depends on node type:
|
|
355
|
+
// - PROMPT_NODE: defaults to canStayOnNode=true (stays at node)
|
|
356
|
+
// - TOOL, APP_TOOL, JUMP_TO_NODE, BROWSER_TASK: defaults to canStayOnNode=false (ends flow)
|
|
357
|
+
// - Other types: defaults to canStayOnNode=false (ends flow)
|
|
358
|
+
const sourceNodes = new Set(edges.map((edge) => edge.source));
|
|
359
|
+
const lastNodes = Object.keys(nodesObject).filter((nodeName) => {
|
|
360
|
+
if (sourceNodes.has(nodeName)) return false; // Not a leaf node
|
|
361
|
+
|
|
362
|
+
const node = nodesObject[nodeName];
|
|
363
|
+
|
|
364
|
+
// If canStayOnNode is explicitly set, respect that
|
|
365
|
+
if (node.canStayOnNode !== undefined) {
|
|
366
|
+
return !node.canStayOnNode;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// Default behavior based on node type
|
|
370
|
+
switch (node.type) {
|
|
371
|
+
case NodeType.PROMPT_NODE:
|
|
372
|
+
return false; // Default: stay at node (no edge to __end__)
|
|
373
|
+
case NodeType.TOOL:
|
|
374
|
+
case NodeType.APP_TOOL:
|
|
375
|
+
case NodeType.JUMP_TO_NODE:
|
|
376
|
+
case NodeType.BROWSER_TASK:
|
|
377
|
+
return true; // Default: end flow (add edge to __end__)
|
|
378
|
+
default:
|
|
379
|
+
return true; // Default for other types: end flow
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
lastNodes.forEach((nodeName) => {
|
|
384
|
+
edges.push({
|
|
385
|
+
source: nodeName,
|
|
386
|
+
target: '__end__',
|
|
387
|
+
type: EdgeType.STEP_FORWARD,
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
// Add edges
|
|
392
|
+
edgeFactory({ graph, edges, nodes: nodesObject, tools: this.tools, llm: this.llm, agent: this });
|
|
393
|
+
|
|
394
|
+
// Compile the graph
|
|
395
|
+
return graph.compile({ checkpointer: this.checkpointer }) as CompiledGraph;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Invoke a trigger to start agent execution with the specified parameters.
|
|
400
|
+
*
|
|
401
|
+
* This method processes triggers from external systems or applications, allowing the agent
|
|
402
|
+
* to respond to events and execute the appropriate flows based on the trigger type.
|
|
403
|
+
*
|
|
404
|
+
* @param params - The trigger invocation parameters containing:
|
|
405
|
+
* - triggerBody: The payload/data associated with the trigger
|
|
406
|
+
* - triggerName: The name/type of the trigger being invoked
|
|
407
|
+
* - sessionId: Optional session identifier for conversation continuity
|
|
408
|
+
* - appName: Optional name of the application triggering the agent in case of an app trigger
|
|
409
|
+
*
|
|
410
|
+
* @returns Promise that resolves with the agent's execution result
|
|
411
|
+
*
|
|
412
|
+
* @throws {Error} When the agent is not properly initialized
|
|
413
|
+
*
|
|
414
|
+
* @example
|
|
415
|
+
* ```typescript
|
|
416
|
+
* // Manual invoke with a message trigger
|
|
417
|
+
* const result = await agent.invoke({
|
|
418
|
+
* triggerName: 'minded.message.in.conversation',
|
|
419
|
+
* triggerBody: {
|
|
420
|
+
* text: 'Hello, how can you help me?',
|
|
421
|
+
* },
|
|
422
|
+
* sessionId: 'user-123-session'
|
|
423
|
+
* });
|
|
424
|
+
* ```
|
|
425
|
+
*/
|
|
426
|
+
public async invoke({ triggerBody, triggerName, appName, bypassSessionCheck }: AgentInvokeParams): Promise<any> {
|
|
427
|
+
// Parse sessionId from trigger body if provided
|
|
428
|
+
const sessionId = this.parseSessionIdFromTrigger?.(triggerBody, triggerName) ?? triggerBody?.sessionId ?? uuidv4();
|
|
429
|
+
|
|
430
|
+
try {
|
|
431
|
+
await this.waitForInitialization();
|
|
432
|
+
} catch (err) {
|
|
433
|
+
logger.error({ msg: '[Trigger] Agent initialization failed', err });
|
|
434
|
+
throw err;
|
|
435
|
+
}
|
|
436
|
+
const [, flows, playbooks] = await Promise.all([
|
|
437
|
+
this.loadSecrets(),
|
|
438
|
+
loadFlows(this.config.flows),
|
|
439
|
+
loadPlaybooks(this.config.playbooks),
|
|
440
|
+
]);
|
|
441
|
+
|
|
442
|
+
this.playbooks = playbooks;
|
|
443
|
+
this.flows = flows;
|
|
444
|
+
this.compiledGraph = this.initializeGraph();
|
|
445
|
+
|
|
446
|
+
try {
|
|
447
|
+
// Try to acquire lock atomically (unless bypassing session check)
|
|
448
|
+
if (!bypassSessionCheck && !(await this.interruptSessionManager.lock(sessionId))) {
|
|
449
|
+
// Could not acquire lock, session is being processed - enqueue the message
|
|
450
|
+
logger.debug({ msg: 'Enqueuing message', sessionId, triggerBody, triggerName, appName });
|
|
451
|
+
await this.interruptSessionManager.enqueueMessage(sessionId, {
|
|
452
|
+
triggerBody,
|
|
453
|
+
triggerName,
|
|
454
|
+
appName,
|
|
455
|
+
});
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
// Session lock acquired, proceed with processing
|
|
459
|
+
const langgraphConfig = this.getLangraphConfig(sessionId);
|
|
460
|
+
const langgraphState = await this.compiledGraph.getState(langgraphConfig);
|
|
461
|
+
let state = langgraphState.values as State<z.infer<typeof this.memorySchema>>;
|
|
462
|
+
|
|
463
|
+
const lastTask = langgraphState.tasks[langgraphState.tasks.length - 1];
|
|
464
|
+
const hasInterrupt = lastTask?.interrupts?.length > 0;
|
|
465
|
+
if (hasInterrupt) {
|
|
466
|
+
const interruptValue = lastTask!.interrupts[0].value as InterruptPayload;
|
|
467
|
+
if (interruptValue?.type === InterruptType.NEW_TRIGGERS) {
|
|
468
|
+
const updatedInterruptState = interruptValue.updateStateObject;
|
|
469
|
+
if (updatedInterruptState) {
|
|
470
|
+
state = updatedInterruptState;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// initialize state with default values
|
|
476
|
+
if (Object.keys(state).length === 0) {
|
|
477
|
+
state = getInitialState(this.memorySchema);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
state.sessionId = sessionId;
|
|
481
|
+
state.sessionType = SessionType.TEXT;
|
|
482
|
+
|
|
483
|
+
// Add playbooks to messages
|
|
484
|
+
const combinedPlaybooks = combinePlaybooks(this.playbooks);
|
|
485
|
+
if (combinedPlaybooks) {
|
|
486
|
+
const compiledPrompt = compilePrompt(combinedPlaybooks, { state: state, memory: state.memory, env: process.env });
|
|
487
|
+
const systemMessage = new SystemMessage(compiledPrompt);
|
|
488
|
+
if (state.messages.length === 0 || state.messages[0].getType() === 'system') {
|
|
489
|
+
state.messages[0] = systemMessage;
|
|
490
|
+
} else {
|
|
491
|
+
state.messages.unshift(systemMessage);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// Process special trigger types (dashboard/voice messages)
|
|
496
|
+
if (triggerName === KnownTriggerNames.DASHBOARD_MESSAGE || triggerName === KnownTriggerNames.VOICE_MESSAGE) {
|
|
497
|
+
// Parse attachments and create message
|
|
498
|
+
const attachmentsString = parseAttachments(triggerBody);
|
|
499
|
+
const finalContent = combineContentWithAttachments(triggerBody.content || '', attachmentsString);
|
|
500
|
+
if (finalContent) {
|
|
501
|
+
state.messages.push(new HumanMessage({ content: finalContent, id: uuidv4() }));
|
|
502
|
+
}
|
|
503
|
+
triggerBody.content = finalContent;
|
|
504
|
+
state.sessionType = triggerName === KnownTriggerNames.VOICE_MESSAGE ? SessionType.VOICE : SessionType.TEXT;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// Emit trigger event and let handlers modify the state
|
|
508
|
+
const results = await this.emit(AgentEvents.TRIGGER_EVENT, { triggerName, triggerBody, state });
|
|
509
|
+
|
|
510
|
+
// Process handler results
|
|
511
|
+
const handlerResult = results.find((r) => r !== undefined);
|
|
512
|
+
if (handlerResult) {
|
|
513
|
+
if (!handlerResult.isQualified) {
|
|
514
|
+
logger.debug({ message: '[Trigger] Disqualified', triggerName, triggerBody, sessionId });
|
|
515
|
+
// Process any queued messages even when disqualified
|
|
516
|
+
return await this.processQueuedMessages(sessionId);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// If no messages were set by handler or initial processing, create default message
|
|
521
|
+
if (!state.messages || state.messages.length === 0) {
|
|
522
|
+
if (appName && triggerTypeToDefaultMessage[appName]?.[triggerName]) {
|
|
523
|
+
state.messages = triggerTypeToDefaultMessage[appName][triggerName](triggerBody);
|
|
524
|
+
} else {
|
|
525
|
+
state.messages = [new HumanMessage({ content: JSON.stringify(triggerBody), id: uuidv4() })];
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
logger.info({ msg: '[Trigger] Received', triggerName, triggerBody, sessionId });
|
|
530
|
+
|
|
531
|
+
// 2) Decide how to invoke: resume/update/goto/normal
|
|
532
|
+
let nodeToBeInvoked = langgraphState.next.length > 0 ? (state.goto ? state.goto : langgraphState.next[0]) : this.startingNodeId;
|
|
533
|
+
if (!nodeToBeInvoked) throw new Error('No node to be invoked');
|
|
534
|
+
|
|
535
|
+
const suffixes = Object.values(internalNodesSuffix);
|
|
536
|
+
nodeToBeInvoked = nodeToBeInvoked.replace(new RegExp(suffixes.join('|'), 'g'), '');
|
|
537
|
+
|
|
538
|
+
// Create a history step
|
|
539
|
+
const messageIds = state.messages?.map((m) => m.id!) || [];
|
|
540
|
+
const historyStep = createTriggerHistoryStep(state.history, nodeToBeInvoked, messageIds, triggerName, triggerBody, appName);
|
|
541
|
+
state.history.push(historyStep);
|
|
542
|
+
|
|
543
|
+
// 3) Handle interrupts/goto, else normal invoke
|
|
544
|
+
let res;
|
|
545
|
+
if (hasInterrupt) {
|
|
546
|
+
res = await this.compiledGraph.invoke(
|
|
547
|
+
new Command({
|
|
548
|
+
update: state,
|
|
549
|
+
resume: '',
|
|
550
|
+
}),
|
|
551
|
+
langgraphConfig,
|
|
552
|
+
);
|
|
553
|
+
} else if (state.goto) {
|
|
554
|
+
res = await this.compiledGraph.invoke(
|
|
555
|
+
new Command({
|
|
556
|
+
update: {
|
|
557
|
+
...state,
|
|
558
|
+
goto: null, //reset the goto
|
|
559
|
+
},
|
|
560
|
+
goto: state.goto,
|
|
561
|
+
}),
|
|
562
|
+
langgraphConfig,
|
|
563
|
+
);
|
|
564
|
+
} else {
|
|
565
|
+
res = await this.compiledGraph.invoke(state, langgraphConfig);
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
// Process any queued messages before returning
|
|
569
|
+
const queueResult = await this.processQueuedMessages(sessionId);
|
|
570
|
+
return queueResult !== undefined ? queueResult : res;
|
|
571
|
+
} catch (err) {
|
|
572
|
+
logger.error({ msg: '[Trigger] Error', err, sessionId });
|
|
573
|
+
|
|
574
|
+
// Release the session lock on error
|
|
575
|
+
await this.interruptSessionManager.release(sessionId);
|
|
576
|
+
|
|
577
|
+
const state = await this.compiledGraph.getState(this.getLangraphConfig(sessionId));
|
|
578
|
+
const results = await this.emit(AgentEvents.ERROR, {
|
|
579
|
+
error: err instanceof Error ? err : new Error(JSON.stringify(err)),
|
|
580
|
+
state: state.values,
|
|
581
|
+
});
|
|
582
|
+
const handlerResult = results.find((r) => r !== undefined);
|
|
583
|
+
let throwError = handlerResult === undefined;
|
|
584
|
+
if (handlerResult) {
|
|
585
|
+
// If one handler returns throwError, we throw the error
|
|
586
|
+
throwError = throwError || handlerResult.throwError;
|
|
587
|
+
}
|
|
588
|
+
if (throwError) {
|
|
589
|
+
throw err;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
/**
|
|
595
|
+
* Register an event handler for agent events. Multiple handlers can be registered for the same event.
|
|
596
|
+
*
|
|
597
|
+
* ## Available Events
|
|
598
|
+
*
|
|
599
|
+
* ### INIT
|
|
600
|
+
* Fired when a new session starts.
|
|
601
|
+
* - **Input:** `{ state: AgentState }` - Initial agent state with empty messages/history
|
|
602
|
+
* - **Output:** `void`
|
|
603
|
+
* - **Use for:** Session logging, resource initialization, analytics
|
|
604
|
+
*
|
|
605
|
+
* ### AI_MESSAGE
|
|
606
|
+
* Fired when AI generates a message for the user.
|
|
607
|
+
* - **Input:** `{ message: string, state: AgentState }` - AI message and current state
|
|
608
|
+
* - **Output:** `void`
|
|
609
|
+
* - **Use for:** Sending to UI, logging responses, notifications
|
|
610
|
+
*
|
|
611
|
+
* ### TRIGGER_EVENT
|
|
612
|
+
* Fired when a trigger executes. Allows qualifying/transforming trigger inputs.
|
|
613
|
+
* - **Input:** `{ triggerName: string, triggerBody: any }`
|
|
614
|
+
* - **Output Options:**
|
|
615
|
+
* - `{ messages?, memory?, sessionId? }` - Provide initial state
|
|
616
|
+
* - `false` - Disqualify the trigger
|
|
617
|
+
* - `void` - Qualify without initial state
|
|
618
|
+
* - **Use for:** Input validation, data transformation, access control
|
|
619
|
+
*
|
|
620
|
+
* @template E - The event type
|
|
621
|
+
* @param event - Event name to listen for
|
|
622
|
+
* @param handler - Function to call when event fires
|
|
623
|
+
*
|
|
624
|
+
* @example
|
|
625
|
+
* ```typescript
|
|
626
|
+
* // Session initialization
|
|
627
|
+
* agent.on('INIT', async ({ state }) => {
|
|
628
|
+
* logger.info({ msg: 'Session started', sessionId: state.sessionId });
|
|
629
|
+
* await initializeResources(state.sessionId);
|
|
630
|
+
* });
|
|
631
|
+
*
|
|
632
|
+
* // Handle AI messages
|
|
633
|
+
* agent.on('AI_MESSAGE', async ({ message, state }) => {
|
|
634
|
+
* await sendToUI(message, state.sessionId);
|
|
635
|
+
* });
|
|
636
|
+
*
|
|
637
|
+
* // Validate and transform triggers
|
|
638
|
+
* agent.on('TRIGGER_EVENT', async ({ triggerName, triggerBody }) => {
|
|
639
|
+
* if (!isValid(triggerBody)) return false;
|
|
640
|
+
*
|
|
641
|
+
* return {
|
|
642
|
+
* memory: { validated: true },
|
|
643
|
+
* messages: [new HumanMessage('Request received')],
|
|
644
|
+
* sessionId: triggerBody.userId
|
|
645
|
+
* };
|
|
646
|
+
* });
|
|
647
|
+
* ```
|
|
648
|
+
*/
|
|
649
|
+
// Public API for registering event listeners
|
|
650
|
+
public on<E extends keyof AgentEventRequestPayloads<z.infer<typeof this.memorySchema>>>(
|
|
651
|
+
event: E,
|
|
652
|
+
handler: (payload: AgentEventRequestPayloads<z.infer<typeof this.memorySchema>>[E]) => Promise<AgentEventResponsePayloads[E] | void>,
|
|
653
|
+
): void {
|
|
654
|
+
if (!this.eventHandlers[event]) {
|
|
655
|
+
this.eventHandlers[event] = [];
|
|
656
|
+
}
|
|
657
|
+
// We can safely cast here since we ensured the array exists
|
|
658
|
+
(this.eventHandlers[event] as Array<typeof handler>).push(handler);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// Method to emit events to the registered listeners
|
|
662
|
+
public async emit<E extends keyof AgentEventRequestPayloads<z.infer<typeof this.memorySchema>>>(
|
|
663
|
+
event: E,
|
|
664
|
+
payload: AgentEventRequestPayloads<z.infer<typeof this.memorySchema>>[E],
|
|
665
|
+
): Promise<AgentEventResponsePayloads[E][]> {
|
|
666
|
+
if (!this.eventHandlers[event]) {
|
|
667
|
+
return [];
|
|
668
|
+
}
|
|
669
|
+
const results = await Promise.all(this.eventHandlers[event]!.map(async (handler) => handler(payload)));
|
|
670
|
+
return results;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
private initAppActionsRunnerTools() {
|
|
674
|
+
const { runLocally } = getConfig();
|
|
675
|
+
if (!runLocally && !mindedConnection.isConnected() && process.env.NODE_ENV !== 'test') {
|
|
676
|
+
throw new Error('Minded connection is mandatory to use run app action tools');
|
|
677
|
+
}
|
|
678
|
+
return this.flows
|
|
679
|
+
.flatMap((flow) =>
|
|
680
|
+
flow.nodes.filter((node): node is AppToolNode => node.type === NodeType.APP_TOOL && (node as AppToolNode).appName !== 'Minded'),
|
|
681
|
+
)
|
|
682
|
+
.map((node) => appActionRunnerToolCreator(node.metadata.schema, node.displayName!));
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
// Private method to get secrets from the backend service and load them into environment variables
|
|
686
|
+
private async loadSecrets(): Promise<Record<string, string>> {
|
|
687
|
+
// Skip secret loading in local development
|
|
688
|
+
const { runLocally } = getConfig();
|
|
689
|
+
if (runLocally) {
|
|
690
|
+
logger.debug({ msg: '[Agent] Secrets loaded from local .env file' });
|
|
691
|
+
return {};
|
|
692
|
+
}
|
|
693
|
+
if (!mindedConnection.isConnected()) {
|
|
694
|
+
throw new Error('Minded connection is not established when trying to get secrets');
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
// Return cached secrets if available
|
|
698
|
+
if (this.secretsCache !== null) {
|
|
699
|
+
return this.secretsCache;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
try {
|
|
703
|
+
// Check if mindedConnection is available
|
|
704
|
+
if (!mindedConnection.isConnected()) {
|
|
705
|
+
throw new Error('Platform is not available');
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
const response = await mindedConnection.awaitEmit<object, { secrets: Record<string, string> }>(
|
|
709
|
+
mindedConnectionSocketMessageType.GET_SECRETS,
|
|
710
|
+
{},
|
|
711
|
+
);
|
|
712
|
+
|
|
713
|
+
// Extract secrets from response
|
|
714
|
+
const secrets = response.secrets || {};
|
|
715
|
+
|
|
716
|
+
// Load secrets into process.env
|
|
717
|
+
Object.entries(secrets).forEach(([key, value]) => {
|
|
718
|
+
process.env[key] = value;
|
|
719
|
+
});
|
|
720
|
+
logger.debug(`[Agent] Loaded ${Object.keys(secrets).length} secrets from platform`);
|
|
721
|
+
|
|
722
|
+
// Cache the secrets for future requests
|
|
723
|
+
this.secretsCache = secrets;
|
|
724
|
+
|
|
725
|
+
return secrets;
|
|
726
|
+
} catch (err) {
|
|
727
|
+
throw new Error(`Failed to fetch secrets: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
public getLangraphConfig(sessionId: string, checkpointId?: string) {
|
|
732
|
+
return { configurable: { thread_id: sessionId, recursionLimit: 3, checkpoint_id: checkpointId } };
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
private setupVoice(): void {
|
|
736
|
+
logger.info('[Voice] Setting up voice');
|
|
737
|
+
if (!mindedConnection.isConnected()) {
|
|
738
|
+
throw new Error('Minded connection is required');
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
const connection = mindedConnection;
|
|
742
|
+
const { dashboardConnected } = getConfig();
|
|
743
|
+
|
|
744
|
+
if (dashboardConnected) {
|
|
745
|
+
// Listen for voice session start
|
|
746
|
+
connection.on(mindedConnectionSocketMessageType.VOICE_SESSION_START, async (message) => {
|
|
747
|
+
const { sessionId, metadata } = message;
|
|
748
|
+
await this.startVoiceSession({ sessionId, metadata });
|
|
749
|
+
});
|
|
750
|
+
|
|
751
|
+
// Listen for incoming audio from the platform
|
|
752
|
+
connection.on(mindedConnectionSocketMessageType.VOICE_USER_AUDIO, (message) => {
|
|
753
|
+
const audioMessage = message as OnVoiceAudioOut;
|
|
754
|
+
const voiceSession = this.voiceSessions.get(audioMessage.sessionId);
|
|
755
|
+
if (voiceSession) {
|
|
756
|
+
voiceSession.sendAudio(audioMessage.audioData);
|
|
757
|
+
} else {
|
|
758
|
+
logger.trace({
|
|
759
|
+
message: '[Voice] Audio received; voice session not found for sessionId',
|
|
760
|
+
sessionId: audioMessage.sessionId,
|
|
761
|
+
activeSessions: Array.from(this.voiceSessions.keys()),
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
});
|
|
765
|
+
|
|
766
|
+
// Hangup / end session handler
|
|
767
|
+
connection.on(mindedConnectionSocketMessageType.VOICE_SESSION_END, (message) => {
|
|
768
|
+
const hangup = message as BaseVoiceMessage;
|
|
769
|
+
logger.debug({ msg: '[Voice] Dashboard eneded voice session', sessionId: hangup.sessionId });
|
|
770
|
+
const voiceSession = this.voiceSessions.get(hangup.sessionId);
|
|
771
|
+
if (voiceSession) {
|
|
772
|
+
voiceSession.hangup();
|
|
773
|
+
} else {
|
|
774
|
+
logger.trace({
|
|
775
|
+
message: '[Voice] Session ended; voice session not found for sessionId',
|
|
776
|
+
sessionId: hangup.sessionId,
|
|
777
|
+
activeSessions: this.voiceSessions.keys(),
|
|
778
|
+
});
|
|
779
|
+
}
|
|
780
|
+
});
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
/*
|
|
785
|
+
* Update the state of a session
|
|
786
|
+
* @param params - The parameters object containing:
|
|
787
|
+
* - sessionId: The session ID
|
|
788
|
+
* - state: The state to update
|
|
789
|
+
*/
|
|
790
|
+
public async updateState({ sessionId, state }: { sessionId: string; state: Partial<typeof stateAnnotation.State> }): Promise<void> {
|
|
791
|
+
logger.info({ msg: '[Agent] Updating state', sessionId });
|
|
792
|
+
await this.waitForInitialization();
|
|
793
|
+
await this.compiledGraph.updateState(this.getLangraphConfig(sessionId), state);
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
public async getState(sessionId: string): Promise<State<z.infer<typeof this.memorySchema>>> {
|
|
797
|
+
const state = await this.compiledGraph.getState(this.getLangraphConfig(sessionId));
|
|
798
|
+
return state.values as State<z.infer<typeof this.memorySchema>>;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/*
|
|
802
|
+
* To be used by the Lambda wrapper to start voice sessions
|
|
803
|
+
*/
|
|
804
|
+
public async startVoiceSession(params: { sessionId: string; metadata?: Record<string, any> }): Promise<VoiceSession> {
|
|
805
|
+
await this.waitForInitialization();
|
|
806
|
+
const voiceTrigger = this.flows
|
|
807
|
+
.flatMap((flow) => flow.nodes)
|
|
808
|
+
.find((node) => node.type === NodeType.TRIGGER && node.triggerType === TriggerType.VOICE) as VoiceTriggerNode;
|
|
809
|
+
if (!voiceTrigger) {
|
|
810
|
+
throw new Error('Voice trigger not found in flows');
|
|
811
|
+
}
|
|
812
|
+
const voiceSession = new VoiceSession({
|
|
813
|
+
agent: this,
|
|
814
|
+
sessionId: params.sessionId,
|
|
815
|
+
firstMessage: voiceTrigger.firstMessage,
|
|
816
|
+
voiceId: voiceTrigger.voiceId,
|
|
817
|
+
});
|
|
818
|
+
await voiceSession.init();
|
|
819
|
+
logger.debug({ msg: '[Voice] Voice session initialized', sessionId: params.sessionId });
|
|
820
|
+
|
|
821
|
+
this.voiceSessions.set(params.sessionId, voiceSession);
|
|
822
|
+
|
|
823
|
+
const state = await this.compiledGraph.getState(this.getLangraphConfig(params.sessionId));
|
|
824
|
+
|
|
825
|
+
// Emit voice session start event
|
|
826
|
+
await this.emit(AgentEvents.VOICE_SESSION_START, {
|
|
827
|
+
metadata: params.metadata,
|
|
828
|
+
state: state.values as State<z.infer<typeof this.memorySchema>>,
|
|
829
|
+
});
|
|
830
|
+
|
|
831
|
+
return voiceSession;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/*
|
|
835
|
+
To be used by the Lambda wrapper to trigger timers
|
|
836
|
+
*/
|
|
837
|
+
public async timerTrigger(params: { sessionId: string; timerName: string; eventArgs: Record<string, any> }): Promise<void> {
|
|
838
|
+
await this.waitForInitialization();
|
|
839
|
+
const handlerEntry = timerHandlers.get(params.timerName);
|
|
840
|
+
if (handlerEntry) {
|
|
841
|
+
await handlerEntry.handler({
|
|
842
|
+
sessionId: params.sessionId,
|
|
843
|
+
payload: params.eventArgs,
|
|
844
|
+
state: await this.getState(params.sessionId),
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
/*
|
|
850
|
+
To be used by the Lambda wrapper to restore checkpoints
|
|
851
|
+
*/
|
|
852
|
+
public async restoreCheckpoint(sessionId: string, checkpointId: string): Promise<void> {
|
|
853
|
+
logger.info({ msg: '[Agent] Restoring checkpoint', sessionId, checkpointId });
|
|
854
|
+
await this.waitForInitialization();
|
|
855
|
+
const langraphConfig = this.getLangraphConfig(sessionId, checkpointId);
|
|
856
|
+
await this.compiledGraph.invoke(
|
|
857
|
+
new Command({
|
|
858
|
+
resume: {
|
|
859
|
+
sessionId,
|
|
860
|
+
},
|
|
861
|
+
}),
|
|
862
|
+
langraphConfig,
|
|
863
|
+
);
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* Execute a tool by name with given parameters
|
|
868
|
+
* This is used for standalone tool execution (e.g., from browser-use)
|
|
869
|
+
*/
|
|
870
|
+
async executeTool(request: ToolExecutionRequest): Promise<ToolExecutionResponse> {
|
|
871
|
+
await this.waitForInitialization();
|
|
872
|
+
try {
|
|
873
|
+
return await this.toolExecutor.executeTool(request);
|
|
874
|
+
} catch (err) {
|
|
875
|
+
logger.error({ message: '[Agent] Error executing tool', err });
|
|
876
|
+
return { error: 'Failed to execute tool' };
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
public async getCurrentNode(sessionId: string) {
|
|
881
|
+
const langConfig = this.getLangraphConfig(sessionId);
|
|
882
|
+
const currentNodeId = (await this.compiledGraph.getState(langConfig))?.tasks?.[0]?.name;
|
|
883
|
+
if (!currentNodeId) {
|
|
884
|
+
// Will be supported in the future
|
|
885
|
+
return null;
|
|
886
|
+
}
|
|
887
|
+
const currentNode = this.flows.flatMap((flow) => flow.nodes).find((node) => node.name === currentNodeId);
|
|
888
|
+
return currentNode;
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
/**
|
|
892
|
+
* Query an Vector Store collection for relevant documents.
|
|
893
|
+
*
|
|
894
|
+
* This method sends a query to the backend vector store service to retrieve documents
|
|
895
|
+
* from a specified collection that match the given query.
|
|
896
|
+
*
|
|
897
|
+
* @param collectionName - The name of the vector store collection to query
|
|
898
|
+
* @param query - The search query string
|
|
899
|
+
* @param options - Optional parameters for the query
|
|
900
|
+
* @param options.filter - Optional filter to apply to the search
|
|
901
|
+
* @param options.numChunks - Number of document chunks to return (default: from vector store config)
|
|
902
|
+
* @param options.minScore - Minimum similarity score threshold (default: no minimum)
|
|
903
|
+
*
|
|
904
|
+
* @returns Promise that resolves with an array of documents containing pageContent and metadata
|
|
905
|
+
*
|
|
906
|
+
* @throws {Error} When not connected to the Minded platform
|
|
907
|
+
* @throws {Error} When the vector store query fails
|
|
908
|
+
*
|
|
909
|
+
*/
|
|
910
|
+
public async getDocumentsFromDB(
|
|
911
|
+
collectionName: string,
|
|
912
|
+
query: string,
|
|
913
|
+
options?: {
|
|
914
|
+
filter?: any;
|
|
915
|
+
numChunks?: number;
|
|
916
|
+
minScore?: number;
|
|
917
|
+
},
|
|
918
|
+
timeoutMs: number = 30000,
|
|
919
|
+
): Promise<Document[]> {
|
|
920
|
+
await this.waitForInitialization();
|
|
921
|
+
|
|
922
|
+
try {
|
|
923
|
+
const request: VectorStoreQueryRequest = {
|
|
924
|
+
type: mindedConnectionSocketMessageType.VECTORSTORE_QUERY,
|
|
925
|
+
collectionName,
|
|
926
|
+
query,
|
|
927
|
+
filter: options?.filter,
|
|
928
|
+
numChunks: options?.numChunks,
|
|
929
|
+
minScore: options?.minScore,
|
|
930
|
+
};
|
|
931
|
+
|
|
932
|
+
const response = await mindedConnection.awaitEmit<VectorStoreQueryRequest, VectorStoreQueryResponse>(
|
|
933
|
+
mindedConnectionSocketMessageType.VECTORSTORE_QUERY,
|
|
934
|
+
request,
|
|
935
|
+
timeoutMs,
|
|
936
|
+
);
|
|
937
|
+
|
|
938
|
+
if (response.error) {
|
|
939
|
+
throw new Error(`Vector store query failed: ${response.error}`);
|
|
940
|
+
}
|
|
941
|
+
|
|
942
|
+
logger.debug({ msg: '[Agent] Vector store query completed', documentsFound: response.documents?.length || 0 });
|
|
943
|
+
|
|
944
|
+
const documents: Document[] = [];
|
|
945
|
+
for (const document of response.documents || []) {
|
|
946
|
+
documents.push(new Document({ pageContent: document.pageContent, metadata: document.metadata }));
|
|
947
|
+
}
|
|
948
|
+
return documents;
|
|
949
|
+
} catch (err) {
|
|
950
|
+
logger.error({ msg: '[Agent] Error querying vector store', err, collectionName, query });
|
|
951
|
+
throw new Error(`Failed to query vector store: ${err instanceof Error ? err.message : 'Unknown error'}`);
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
|
|
955
|
+
public onEnd(): void {
|
|
956
|
+
mindedConnection.disconnect();
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
/**
|
|
960
|
+
* Process any queued messages for a session.
|
|
961
|
+
* If a message is found, it will be processed recursively.
|
|
962
|
+
* If no messages are found, checks if the graph was interrupted and resumes if needed.
|
|
963
|
+
* Only releases the lock when there's nothing left to process.
|
|
964
|
+
*
|
|
965
|
+
* @param sessionId - The session ID to check for queued messages
|
|
966
|
+
* @returns The result of processing the next message or resuming the graph, or undefined if nothing to process
|
|
967
|
+
*/
|
|
968
|
+
private async processQueuedMessages(sessionId: string): Promise<any> {
|
|
969
|
+
const nextMessage = await this.interruptSessionManager.dequeue(sessionId);
|
|
970
|
+
if (nextMessage) {
|
|
971
|
+
// Dequeue the first message and process it recursively
|
|
972
|
+
const invokeParams: AgentInvokeParams = {
|
|
973
|
+
triggerBody: nextMessage.triggerBody,
|
|
974
|
+
triggerName: nextMessage.triggerName,
|
|
975
|
+
bypassSessionCheck: true,
|
|
976
|
+
};
|
|
977
|
+
if (nextMessage.appName) {
|
|
978
|
+
invokeParams.appName = nextMessage.appName;
|
|
979
|
+
}
|
|
980
|
+
logger.debug({
|
|
981
|
+
msg: 'Invoking next message in the queue',
|
|
982
|
+
invokeParams,
|
|
983
|
+
});
|
|
984
|
+
|
|
985
|
+
return await this.invoke(invokeParams);
|
|
986
|
+
}
|
|
987
|
+
|
|
988
|
+
// No more messages in queue - check if we need to resume an interrupted graph
|
|
989
|
+
const langgraphConfig = this.getLangraphConfig(sessionId);
|
|
990
|
+
const langgraphState = await this.compiledGraph.getState(langgraphConfig);
|
|
991
|
+
const lastTask = langgraphState.tasks[langgraphState.tasks.length - 1];
|
|
992
|
+
const hasInterrupt = lastTask?.interrupts?.length > 0;
|
|
993
|
+
|
|
994
|
+
if (hasInterrupt) {
|
|
995
|
+
const interruptValue = lastTask!.interrupts[0].value as InterruptPayload;
|
|
996
|
+
if (interruptValue?.type === InterruptType.NEW_TRIGGERS) {
|
|
997
|
+
// Graph was interrupted by new triggers - resume it
|
|
998
|
+
logger.debug({ msg: 'Resuming interrupted graph after processing queued messages', sessionId });
|
|
999
|
+
|
|
1000
|
+
const state = langgraphState.values as State<any>;
|
|
1001
|
+
const resumeResult = await this.compiledGraph.invoke(
|
|
1002
|
+
new Command({
|
|
1003
|
+
update: state,
|
|
1004
|
+
resume: '',
|
|
1005
|
+
}),
|
|
1006
|
+
langgraphConfig,
|
|
1007
|
+
);
|
|
1008
|
+
|
|
1009
|
+
// After resuming, check again for queued messages (recursive)
|
|
1010
|
+
const queueResult = await this.processQueuedMessages(sessionId);
|
|
1011
|
+
return queueResult !== undefined ? queueResult : resumeResult;
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
// No more messages and no interrupt to resume - release the session lock
|
|
1016
|
+
await this.interruptSessionManager.release(sessionId);
|
|
1017
|
+
return undefined;
|
|
1018
|
+
}
|
|
1019
|
+
}
|