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