@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
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
/* eslint-disable no-debugger */
|
|
3
|
+
|
|
4
|
+
import { BaseCallbackHandler } from '@langchain/core/callbacks/base';
|
|
5
|
+
import { Serialized } from '@langchain/core/load/serializable';
|
|
6
|
+
import { LLMResult } from '@langchain/core/outputs';
|
|
7
|
+
import { BaseMessage } from '@langchain/core/messages';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* A callback handler for debugging LLM interactions in MindedJS agents.
|
|
11
|
+
* This handler allows you to inspect messages before they are sent to the LLM
|
|
12
|
+
* and see the responses received.
|
|
13
|
+
*
|
|
14
|
+
* This class extends BaseCallbackHandler from LangChain and provides several
|
|
15
|
+
* callback methods. You can override additional methods for more comprehensive debugging:
|
|
16
|
+
*
|
|
17
|
+
* Available LangChain Callback Methods:
|
|
18
|
+
* - handleChatModelStart - For chat model requests (receives BaseMessage arrays)
|
|
19
|
+
* - handleLLMStart - For standard LLM requests (receives string prompts)
|
|
20
|
+
* - handleLLMNewToken - For streaming tokens as they're generated
|
|
21
|
+
* - handleLLMEnd - When LLM finishes generating
|
|
22
|
+
* - handleLLMError - When LLM encounters an error
|
|
23
|
+
* - handleChainStart - When a LangChain chain starts execution
|
|
24
|
+
* - handleChainEnd - When a chain completes execution
|
|
25
|
+
* - handleChainError - When a chain encounters an error
|
|
26
|
+
* - handleToolStart - When a tool/function starts execution
|
|
27
|
+
* - handleToolEnd - When a tool completes execution
|
|
28
|
+
* - handleToolError - When a tool encounters an error
|
|
29
|
+
* - handleAgentAction - When an agent takes an action
|
|
30
|
+
* - handleAgentFinish - When an agent completes its task
|
|
31
|
+
*
|
|
32
|
+
* For more details on all available callbacks and their signatures, see the LangChain documentation:
|
|
33
|
+
* https://js.langchain.com/docs/modules/callbacks/
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import { Agent, LLMDebugCallbackHandler } from '@minded-ai/mindedjs';
|
|
38
|
+
*
|
|
39
|
+
* const debugHandler = new LLMDebugCallbackHandler();
|
|
40
|
+
*
|
|
41
|
+
* const agent = new Agent({
|
|
42
|
+
* config: {
|
|
43
|
+
* ...config,
|
|
44
|
+
* llm: {
|
|
45
|
+
* ...config.llm,
|
|
46
|
+
* properties: {
|
|
47
|
+
* ...config.llm.properties,
|
|
48
|
+
* callbacks: [debugHandler],
|
|
49
|
+
* },
|
|
50
|
+
* },
|
|
51
|
+
* },
|
|
52
|
+
* // ... other agent configuration
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
import { logger } from '../utils/logger';
|
|
57
|
+
export class LLMDebugCallbackHandler extends BaseCallbackHandler {
|
|
58
|
+
name = 'LLMDebugCallbackHandler';
|
|
59
|
+
|
|
60
|
+
constructor() {
|
|
61
|
+
super();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Called when a chat model (like GPT-4) starts processing.
|
|
66
|
+
* This is triggered before the messages are sent to the LLM.
|
|
67
|
+
* The messages parameter contains the full conversation history.
|
|
68
|
+
*/
|
|
69
|
+
async handleChatModelStart(
|
|
70
|
+
llm: Serialized,
|
|
71
|
+
messages: BaseMessage[][],
|
|
72
|
+
runId: string,
|
|
73
|
+
parentRunId?: string,
|
|
74
|
+
extraParams?: Record<string, unknown>,
|
|
75
|
+
tags?: string[],
|
|
76
|
+
metadata?: Record<string, unknown>,
|
|
77
|
+
name?: string,
|
|
78
|
+
): Promise<void> {
|
|
79
|
+
logger.info({ msg: 'handleChatModelStart called with messages:', messages });
|
|
80
|
+
// Set a breakpoint here to inspect messages
|
|
81
|
+
debugger;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Called when any LLM starts processing (including non-chat models).
|
|
86
|
+
* For chat models, the messages are available in extraParams.messages.
|
|
87
|
+
* This is a more general callback that works with all LLM types.
|
|
88
|
+
*/
|
|
89
|
+
async handleLLMStart(
|
|
90
|
+
llm: Serialized,
|
|
91
|
+
prompts: string[],
|
|
92
|
+
runId: string,
|
|
93
|
+
parentRunId?: string,
|
|
94
|
+
extraParams?: Record<string, unknown>,
|
|
95
|
+
tags?: string[],
|
|
96
|
+
metadata?: Record<string, unknown>,
|
|
97
|
+
name?: string,
|
|
98
|
+
): Promise<void> {
|
|
99
|
+
logger.info({ msg: 'handleLLMStart called with extraParams.messages:', messages: extraParams?.messages });
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Called when a chat model finishes processing and returns a response.
|
|
104
|
+
* The output contains the generated message and metadata.
|
|
105
|
+
*/
|
|
106
|
+
async handleChatModelEnd(output: LLMResult, runId: string, parentRunId?: string): Promise<void> {
|
|
107
|
+
logger.info({ msg: 'handleChatModelEnd called with output:', output });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Called when any LLM finishes processing and returns a response.
|
|
112
|
+
* This is called for all LLM types, including chat models.
|
|
113
|
+
*/
|
|
114
|
+
async handleLLMEnd(output: LLMResult, runId: string, parentRunId?: string): Promise<void> {
|
|
115
|
+
logger.info({ msg: 'handleLLMEnd called with output:', output });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Called when an error occurs during LLM processing.
|
|
120
|
+
* This captures any errors that happen during the LLM call.
|
|
121
|
+
*/
|
|
122
|
+
async handleLLMError(err: Error, runId: string, parentRunId?: string): Promise<void> {
|
|
123
|
+
logger.info({ msg: 'handleLLMError called with error:', err });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { StepForwardEdge } from '../types/Flows.types';
|
|
2
|
+
import { stateAnnotation } from '../types/LangGraph.types';
|
|
3
|
+
import { logger } from '../utils/logger';
|
|
4
|
+
|
|
5
|
+
export const createDirectEdge = (edge: StepForwardEdge) => {
|
|
6
|
+
return async (state: typeof stateAnnotation.State) => {
|
|
7
|
+
if (state.goto) {
|
|
8
|
+
logger.info({
|
|
9
|
+
msg: 'Jumping to node',
|
|
10
|
+
node: state.goto,
|
|
11
|
+
sessionId: state.sessionId,
|
|
12
|
+
edgeSource: edge.source,
|
|
13
|
+
edgeTarget: edge.target,
|
|
14
|
+
});
|
|
15
|
+
return state.goto;
|
|
16
|
+
}
|
|
17
|
+
// For direct edges, we just return the target of the first edge
|
|
18
|
+
// since there's no conditional logic needed
|
|
19
|
+
logger.info({ message: `[Router] Direct edge`, edgeTarget: edge.target, edgeSource: edge.source, sessionId: state.sessionId });
|
|
20
|
+
return edge.target;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { LogicalConditionEdge } from '../types/Flows.types';
|
|
2
|
+
import { stateAnnotation } from '../types/LangGraph.types';
|
|
3
|
+
import { logger } from '../utils/logger';
|
|
4
|
+
import { Agent } from '../agent';
|
|
5
|
+
import { AgentEvents } from '../events/AgentEvents';
|
|
6
|
+
import * as vm from 'vm';
|
|
7
|
+
|
|
8
|
+
// Default timeout for condition evaluation (in milliseconds)
|
|
9
|
+
const CONDITION_TIMEOUT = 5000; // 5 seconds
|
|
10
|
+
|
|
11
|
+
export const createLogicalRouter = ({ edges, agent }: { edges: LogicalConditionEdge[]; agent: Agent }) => {
|
|
12
|
+
return async (state: typeof stateAnnotation.State) => {
|
|
13
|
+
logger.debug({ msg: `[Router] Evaluating logical conditions for ${edges.length} edges`, sessionId: state.sessionId, edges });
|
|
14
|
+
|
|
15
|
+
if (state.goto) {
|
|
16
|
+
logger.debug({ msg: `[Router] Jumping to node`, node: state.goto, sessionId: state.sessionId, edges });
|
|
17
|
+
return state.goto;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Separate regular conditions from "else" conditions
|
|
21
|
+
const regularEdges = edges.filter((edge) => edge.condition.trim() !== 'else');
|
|
22
|
+
const elseEdges = edges.filter((edge) => edge.condition.trim() === 'else');
|
|
23
|
+
|
|
24
|
+
// First, evaluate all regular conditions
|
|
25
|
+
for (const edge of regularEdges) {
|
|
26
|
+
const startTime = Date.now();
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
// Log condition start if in debug mode
|
|
30
|
+
logger.debug({ msg: '[LogicalCondition] Evaluating condition', edge, sessionId: state.sessionId });
|
|
31
|
+
|
|
32
|
+
// Emit ON_LOGICAL_CONDITION event
|
|
33
|
+
await agent.emit(AgentEvents.ON_LOGICAL_CONDITION, {
|
|
34
|
+
edge,
|
|
35
|
+
state,
|
|
36
|
+
condition: edge.condition,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Customer is responsible for providing valid JavaScript syntax
|
|
40
|
+
// We execute their condition in a sandboxed VM with timeout protection
|
|
41
|
+
const conditionCode = `
|
|
42
|
+
(function({ state }) {
|
|
43
|
+
return ${edge.condition}
|
|
44
|
+
})
|
|
45
|
+
`;
|
|
46
|
+
|
|
47
|
+
// Create a sandboxed context with limited access
|
|
48
|
+
const context = vm.createContext({
|
|
49
|
+
// Provide safe utilities that customers might need
|
|
50
|
+
console: {
|
|
51
|
+
log: (...args: any[]) => logger.debug('Customer condition log:', ...args),
|
|
52
|
+
error: (...args: any[]) => logger.debug('Customer condition error:', ...args),
|
|
53
|
+
},
|
|
54
|
+
// Add other safe globals if needed
|
|
55
|
+
JSON,
|
|
56
|
+
Math,
|
|
57
|
+
Date,
|
|
58
|
+
// Prevent access to dangerous globals
|
|
59
|
+
process: undefined,
|
|
60
|
+
require: undefined,
|
|
61
|
+
global: undefined,
|
|
62
|
+
Buffer: undefined,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Compile and run the condition with timeout
|
|
66
|
+
const script = new vm.Script(conditionCode, {
|
|
67
|
+
filename: `edge-condition-${edge.source}-to-${edge.target}`,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const conditionFn = script.runInContext(context, {
|
|
71
|
+
timeout: CONDITION_TIMEOUT,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Execute the customer's condition with the current state
|
|
75
|
+
const result = await Promise.race([
|
|
76
|
+
Promise.resolve(conditionFn({ state })),
|
|
77
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error('Condition execution timeout')), CONDITION_TIMEOUT)),
|
|
78
|
+
]);
|
|
79
|
+
|
|
80
|
+
const executionTime = Date.now() - startTime;
|
|
81
|
+
const booleanResult = result === true;
|
|
82
|
+
|
|
83
|
+
// Log condition result if in debug mode
|
|
84
|
+
logger.debug({
|
|
85
|
+
msg: '[LogicalCondition] Condition evaluated',
|
|
86
|
+
edge,
|
|
87
|
+
result: booleanResult,
|
|
88
|
+
executionTimeMs: executionTime,
|
|
89
|
+
nextNode: booleanResult ? edge.target : null,
|
|
90
|
+
sessionId: state.sessionId,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Emit ON_LOGICAL_CONDITION_RESULT event
|
|
94
|
+
await agent.emit(AgentEvents.ON_LOGICAL_CONDITION_RESULT, {
|
|
95
|
+
edge,
|
|
96
|
+
state,
|
|
97
|
+
condition: edge.condition,
|
|
98
|
+
result: booleanResult,
|
|
99
|
+
executionTimeMs: executionTime,
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const goto = state.goto;
|
|
103
|
+
state.goto = null;
|
|
104
|
+
|
|
105
|
+
if (goto) {
|
|
106
|
+
logger.debug({ msg: `[Router] Jumping to node`, node: goto, sessionId: state.sessionId });
|
|
107
|
+
return goto;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (booleanResult) {
|
|
111
|
+
if (edge.source == edge.target) {
|
|
112
|
+
logger.info({ msg: `[Router] Stay at node ${edge.source}`, node: edge.source, condition: edge.condition });
|
|
113
|
+
} else {
|
|
114
|
+
logger.info({
|
|
115
|
+
msg: `[Router] Logical condition matched`,
|
|
116
|
+
transitionFrom: edge.source,
|
|
117
|
+
transitionTo: edge.target,
|
|
118
|
+
condition: edge.condition,
|
|
119
|
+
sessionId: state.sessionId,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return edge.target;
|
|
123
|
+
}
|
|
124
|
+
} catch (err) {
|
|
125
|
+
const executionTime = Date.now() - startTime;
|
|
126
|
+
const errorObj = err instanceof Error ? err : new Error(String(err));
|
|
127
|
+
|
|
128
|
+
const conditionPreview = edge.condition.length > 100 ? `${edge.condition.substring(0, 100)}...` : edge.condition;
|
|
129
|
+
|
|
130
|
+
logger.error({
|
|
131
|
+
msg: `[Router] Error evaluating condition for edge ${edge.source} → ${edge.target}`,
|
|
132
|
+
condition: conditionPreview,
|
|
133
|
+
err,
|
|
134
|
+
edgeIndex: edges.indexOf(edge),
|
|
135
|
+
timeout: CONDITION_TIMEOUT,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Emit ON_LOGICAL_CONDITION_RESULT event with error
|
|
139
|
+
const onLogicalConditionResultRes = await agent.emit(AgentEvents.ON_LOGICAL_CONDITION_RESULT, {
|
|
140
|
+
edge,
|
|
141
|
+
state,
|
|
142
|
+
condition: edge.condition,
|
|
143
|
+
result: false,
|
|
144
|
+
executionTimeMs: executionTime,
|
|
145
|
+
error: errorObj,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const onLogicalConditionResultHandlerResult = onLogicalConditionResultRes.find((r) => r !== undefined);
|
|
149
|
+
let throwError = false;
|
|
150
|
+
throwError = onLogicalConditionResultHandlerResult?.throwError == true;
|
|
151
|
+
|
|
152
|
+
// Continue to next edge instead of failing completely
|
|
153
|
+
// This allows other conditions to be evaluated even if one fails
|
|
154
|
+
if (throwError) {
|
|
155
|
+
throw errorObj;
|
|
156
|
+
}
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// If no regular conditions matched, check for "else" conditions
|
|
162
|
+
if (elseEdges.length > 0) {
|
|
163
|
+
// Return the first "else" condition's target
|
|
164
|
+
const elseEdge = elseEdges[0];
|
|
165
|
+
logger.info({
|
|
166
|
+
msg: `[Router] Else condition matched`,
|
|
167
|
+
transitionFrom: elseEdge.source,
|
|
168
|
+
transitionTo: elseEdge.target,
|
|
169
|
+
sessionId: state.sessionId,
|
|
170
|
+
});
|
|
171
|
+
return elseEdge.target;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// If no conditions matched or all failed, return to the source node
|
|
175
|
+
logger.info({
|
|
176
|
+
msg: `[Router] Stay at node ${edges[0].source}, no conditions matched`,
|
|
177
|
+
node: edges[0].source,
|
|
178
|
+
sessionId: state.sessionId,
|
|
179
|
+
});
|
|
180
|
+
return null;
|
|
181
|
+
};
|
|
182
|
+
};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { PromptConditionEdge } from '../types/Flows.types';
|
|
3
|
+
import { BaseLanguageModel } from '@langchain/core/language_models/base';
|
|
4
|
+
import { SystemMessage } from '@langchain/core/messages';
|
|
5
|
+
import { stateAnnotation } from '../types/LangGraph.types';
|
|
6
|
+
import { logger } from '../utils/logger';
|
|
7
|
+
import { compilePrompt } from '../nodes/compilePrompt';
|
|
8
|
+
|
|
9
|
+
const ROUTER_PROMPT = `
|
|
10
|
+
You are a routing agent that decides which node to take in a flow based on the current state.
|
|
11
|
+
Based on the conversation history and memory state, you should classify the next step for the conversation.
|
|
12
|
+
Each step has a nodeId and a condition. You should decide to move to the right step based on the condition.
|
|
13
|
+
|
|
14
|
+
Here are the available options and their conditions:
|
|
15
|
+
<%= steps %>
|
|
16
|
+
|
|
17
|
+
Recent messages:
|
|
18
|
+
<%= messages %>
|
|
19
|
+
|
|
20
|
+
You MUST respond with the exact nodeId from the options above. Do not use step numbers or any other identifiers.
|
|
21
|
+
|
|
22
|
+
You should output the result in the following JSON format:
|
|
23
|
+
{
|
|
24
|
+
"nextNodeId": "exact_node_name_from_options_above",
|
|
25
|
+
"reasoning": "I think the next step should be exact_node_name_from_options_above because of the following reasons: ..."
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
Return JSON and nothing more.
|
|
29
|
+
`;
|
|
30
|
+
|
|
31
|
+
const ROUTER_PROMPT_WITHOUT_REASONING = `
|
|
32
|
+
You are a routing agent that decides which node to take in a flow based on the current state.
|
|
33
|
+
Based on the conversation history and memory state, you should classify the next step for the conversation.
|
|
34
|
+
Each step has a nodeId and a condition. You should decide to move to the right step based on the condition.
|
|
35
|
+
|
|
36
|
+
Here are the available options and their conditions:
|
|
37
|
+
<%= steps %>
|
|
38
|
+
|
|
39
|
+
Recent messages:
|
|
40
|
+
<%= messages %>
|
|
41
|
+
|
|
42
|
+
You MUST respond with the exact nodeId from the options above. Do not use step numbers or any other identifiers.
|
|
43
|
+
|
|
44
|
+
You should output the result in the following JSON format:
|
|
45
|
+
{
|
|
46
|
+
"nextNodeId": "exact_node_name_from_options_above"
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Return JSON and nothing more.
|
|
50
|
+
`;
|
|
51
|
+
|
|
52
|
+
export const createPromptRouter = ({
|
|
53
|
+
edges,
|
|
54
|
+
llm,
|
|
55
|
+
includeReasoning = true,
|
|
56
|
+
maxRetries = 3,
|
|
57
|
+
canStayInCurrentNode = false,
|
|
58
|
+
currentNodeName,
|
|
59
|
+
}: {
|
|
60
|
+
edges: PromptConditionEdge[];
|
|
61
|
+
llm: BaseLanguageModel;
|
|
62
|
+
includeReasoning?: boolean;
|
|
63
|
+
maxRetries?: number;
|
|
64
|
+
canStayInCurrentNode?: boolean;
|
|
65
|
+
currentNodeName?: string;
|
|
66
|
+
}) => {
|
|
67
|
+
return async (state: typeof stateAnnotation.State) => {
|
|
68
|
+
logger.debug({ msg: `[Router] Executing prompt router`, currentNodeName, sessionId: state.sessionId, edges });
|
|
69
|
+
|
|
70
|
+
if (state.goto) {
|
|
71
|
+
logger.debug({ msg: `[Router] Jumping to node`, node: state.goto, sessionId: state.sessionId, edges });
|
|
72
|
+
return state.goto;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// If canStayInCurrentNode is true and there are no edges, return current node immediately
|
|
76
|
+
if (canStayInCurrentNode && edges.length === 0 && currentNodeName) {
|
|
77
|
+
logger.info({
|
|
78
|
+
msg: `[Router] Stay at node, No edges available and canStayInCurrentNode==true`,
|
|
79
|
+
node: currentNodeName,
|
|
80
|
+
sessionId: state.sessionId,
|
|
81
|
+
});
|
|
82
|
+
return currentNodeName;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Prepare the steps string
|
|
86
|
+
let stepsStr = '';
|
|
87
|
+
|
|
88
|
+
// Add "stay in current node" option if enabled
|
|
89
|
+
if (canStayInCurrentNode && currentNodeName) {
|
|
90
|
+
stepsStr = `- Node: "${currentNodeName}" (stay in current node)\n`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Add the edge options
|
|
94
|
+
stepsStr += edges.map((edge) => `- Node: "${edge.target}" - Condition: "${edge.prompt}"`).join('\n');
|
|
95
|
+
|
|
96
|
+
// Prepare recent messages (last 10 messages for context)
|
|
97
|
+
const recentMessages = state.messages.slice(-10);
|
|
98
|
+
const messagesStr = recentMessages
|
|
99
|
+
.map((msg) => {
|
|
100
|
+
const role = msg.getType();
|
|
101
|
+
const content = typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content);
|
|
102
|
+
return `${role}: ${content}`;
|
|
103
|
+
})
|
|
104
|
+
.join('\n');
|
|
105
|
+
|
|
106
|
+
// Select prompt based on reasoning preference
|
|
107
|
+
const promptTemplate = includeReasoning ? ROUTER_PROMPT : ROUTER_PROMPT_WITHOUT_REASONING;
|
|
108
|
+
|
|
109
|
+
// Compile prompt with EJS and parameters
|
|
110
|
+
const routerPrompt = compilePrompt(promptTemplate, {
|
|
111
|
+
steps: stepsStr,
|
|
112
|
+
messages: messagesStr,
|
|
113
|
+
memory: state.memory,
|
|
114
|
+
state: state,
|
|
115
|
+
env: process.env,
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Define response schema
|
|
119
|
+
const responseSchema = includeReasoning
|
|
120
|
+
? z.object({
|
|
121
|
+
nextNodeId: z.string(),
|
|
122
|
+
reasoning: z.string(),
|
|
123
|
+
})
|
|
124
|
+
: z.object({
|
|
125
|
+
nextNodeId: z.string(),
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
let attempts = 0;
|
|
129
|
+
let lastError: Error | null = null;
|
|
130
|
+
|
|
131
|
+
while (attempts < maxRetries) {
|
|
132
|
+
try {
|
|
133
|
+
attempts++;
|
|
134
|
+
|
|
135
|
+
// Create messages for the LLM
|
|
136
|
+
const messages = [new SystemMessage(routerPrompt)];
|
|
137
|
+
|
|
138
|
+
// If this is a retry, add the error message
|
|
139
|
+
if (lastError) {
|
|
140
|
+
messages.push(
|
|
141
|
+
new SystemMessage(`Previous attempt failed with error: ${lastError.message}. Please provide a valid JSON response.`),
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Call the LLM with structured output
|
|
146
|
+
const response = await llm.invoke(messages);
|
|
147
|
+
|
|
148
|
+
// Extract content from response
|
|
149
|
+
let content = '';
|
|
150
|
+
if (typeof response.content === 'string') {
|
|
151
|
+
content = response.content;
|
|
152
|
+
} else if (response.content && typeof response.content === 'object' && 'text' in response.content) {
|
|
153
|
+
content = (response.content as any).text;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Try to parse JSON from the response
|
|
157
|
+
let parsedResponse;
|
|
158
|
+
try {
|
|
159
|
+
// Clean the response - remove markdown code blocks if present
|
|
160
|
+
content = content
|
|
161
|
+
.replace(/```json\n?/g, '')
|
|
162
|
+
.replace(/```\n?/g, '')
|
|
163
|
+
.trim();
|
|
164
|
+
parsedResponse = JSON.parse(content);
|
|
165
|
+
} catch {
|
|
166
|
+
throw new Error(`Failed to parse JSON response: ${content}`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Validate the response
|
|
170
|
+
const validatedResponse = responseSchema.parse(parsedResponse);
|
|
171
|
+
|
|
172
|
+
// Check if the selected node is valid
|
|
173
|
+
const validTargets = edges.map((e) => e.target);
|
|
174
|
+
if (canStayInCurrentNode && currentNodeName) {
|
|
175
|
+
validTargets.push(currentNodeName);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!validTargets.includes(validatedResponse.nextNodeId)) {
|
|
179
|
+
throw new Error(`Invalid nextNodeId: ${validatedResponse.nextNodeId}. Must be one of: ${validTargets.join(', ')}`);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const decision = validatedResponse.nextNodeId === currentNodeName ? 'stay in current node' : validatedResponse.nextNodeId;
|
|
183
|
+
const reasoning = includeReasoning && 'reasoning' in validatedResponse ? ` - Reasoning: ${validatedResponse.reasoning}` : '';
|
|
184
|
+
logger.debug({ msg: `[Router] Decision: ${decision}`, reasoning, sessionId: state.sessionId, edges });
|
|
185
|
+
|
|
186
|
+
return validatedResponse.nextNodeId;
|
|
187
|
+
} catch (err) {
|
|
188
|
+
lastError = err instanceof Error ? err : new Error(String(err));
|
|
189
|
+
logger.warn({
|
|
190
|
+
message: `[Router] Prompt router attempt ${attempts} failed`,
|
|
191
|
+
err: lastError,
|
|
192
|
+
attempt: attempts,
|
|
193
|
+
maxRetries,
|
|
194
|
+
sessionId: state.sessionId,
|
|
195
|
+
edges,
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
if (attempts >= maxRetries) {
|
|
199
|
+
logger.error({
|
|
200
|
+
msg: '[Router] Prompt router reached max retries',
|
|
201
|
+
lastError: lastError.message,
|
|
202
|
+
sessionId: state.sessionId,
|
|
203
|
+
edges,
|
|
204
|
+
});
|
|
205
|
+
throw new Error('Prompt router reached max retries, no edges available for routing');
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// This should never be reached, but TypeScript needs it
|
|
211
|
+
throw new Error('Unexpected error in prompt router');
|
|
212
|
+
};
|
|
213
|
+
};
|