@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,736 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.DocumentProcessor = void 0;
|
|
37
|
+
exports.extractFromDocument = extractFromDocument;
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
39
|
+
const path = __importStar(require("path"));
|
|
40
|
+
const logger_1 = require("../../utils/logger");
|
|
41
|
+
const os = __importStar(require("os"));
|
|
42
|
+
const types_1 = require("./types");
|
|
43
|
+
/**
|
|
44
|
+
* Extract data from documents using AI or return raw text.
|
|
45
|
+
*
|
|
46
|
+
* This function allows you to process various document types (PDFs, images, Word docs, etc.)
|
|
47
|
+
* in multiple ways:
|
|
48
|
+
* - With LLM + Schema: Extract structured data according to a Zod schema
|
|
49
|
+
* - With LLM + System Prompt: Extract unstructured data based on prompt instructions
|
|
50
|
+
* - Without LLM: Extract raw text content using LlamaParse
|
|
51
|
+
*
|
|
52
|
+
* @param options - Document extraction options
|
|
53
|
+
* @param options.llm - Optional language model for AI-powered extraction
|
|
54
|
+
* @param options.documentPath - Path to the document file
|
|
55
|
+
* @param options.documentContent - Document content as Buffer or string
|
|
56
|
+
* @param options.documentUrl - URL to fetch the document from
|
|
57
|
+
* @param options.schema - Optional Zod schema for structured data extraction
|
|
58
|
+
* @param options.systemPrompt - Optional prompt for guiding extraction
|
|
59
|
+
* @param options.config - Optional document processor configuration
|
|
60
|
+
*
|
|
61
|
+
* @returns Promise resolving to extracted data/text and metadata
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```typescript
|
|
65
|
+
* import { extractFromDocument } from '@minded-ai/mindedjs';
|
|
66
|
+
* import { z } from 'zod';
|
|
67
|
+
*
|
|
68
|
+
* // Extract structured data with schema
|
|
69
|
+
* const result1 = await extractFromDocument({
|
|
70
|
+
* llm: agent.llm,
|
|
71
|
+
* documentPath: './invoice.pdf',
|
|
72
|
+
* schema: z.object({
|
|
73
|
+
* invoiceNumber: z.string(),
|
|
74
|
+
* amount: z.number(),
|
|
75
|
+
* })
|
|
76
|
+
* });
|
|
77
|
+
*
|
|
78
|
+
* // Extract unstructured data with prompt
|
|
79
|
+
* const result2 = await extractFromDocument({
|
|
80
|
+
* llm: agent.llm,
|
|
81
|
+
* documentPath: './contract.pdf',
|
|
82
|
+
* systemPrompt: 'Extract all payment terms and conditions'
|
|
83
|
+
* });
|
|
84
|
+
*
|
|
85
|
+
* // Extract raw text without LLM
|
|
86
|
+
* const result3 = await extractFromDocument({
|
|
87
|
+
* documentPath: './document.pdf'
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
async function extractFromDocument(options) {
|
|
92
|
+
// Create a document processor
|
|
93
|
+
const processor = new DocumentProcessor(options.config, options.llm);
|
|
94
|
+
// Extract from document using the processor
|
|
95
|
+
return processor.extractFromDocument({
|
|
96
|
+
documentPath: options.documentPath,
|
|
97
|
+
documentContent: options.documentContent,
|
|
98
|
+
documentUrl: options.documentUrl,
|
|
99
|
+
schema: options.schema,
|
|
100
|
+
systemPrompt: options.systemPrompt,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Generic document processor that can extract structured data from various document types
|
|
105
|
+
* including images, PDFs, Word documents, spreadsheets, and more.
|
|
106
|
+
*/
|
|
107
|
+
class DocumentProcessor {
|
|
108
|
+
constructor(config = {}, llm) {
|
|
109
|
+
this.llm = null;
|
|
110
|
+
this.llamaCloudApiKey = null;
|
|
111
|
+
this.sharpModule = null;
|
|
112
|
+
this.sharpLoadAttempted = false;
|
|
113
|
+
this.config = {
|
|
114
|
+
maxImageWidth: 1200,
|
|
115
|
+
imageQuality: 85,
|
|
116
|
+
useBase64: false,
|
|
117
|
+
...config,
|
|
118
|
+
};
|
|
119
|
+
this.llm = llm || null;
|
|
120
|
+
this.llamaCloudApiKey = this.config.llamaCloudApiKey || process.env.LLAMA_CLOUD_API_KEY || null;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Parse document using LlamaCloud REST API
|
|
124
|
+
*/
|
|
125
|
+
async parseWithLlamaCloud(filePath) {
|
|
126
|
+
if (!this.llamaCloudApiKey) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
// Step 1: Upload file and start parsing
|
|
131
|
+
const fileContent = fs.readFileSync(filePath);
|
|
132
|
+
const fileName = path.basename(filePath);
|
|
133
|
+
const mimeType = this.getMimeType(path.extname(filePath));
|
|
134
|
+
const formData = new FormData();
|
|
135
|
+
const blob = new Blob([fileContent], { type: mimeType });
|
|
136
|
+
formData.append('file', blob, fileName);
|
|
137
|
+
formData.append('premium_mode', 'true');
|
|
138
|
+
const uploadResponse = await fetch('https://api.cloud.llamaindex.ai/api/v1/parsing/upload', {
|
|
139
|
+
method: 'POST',
|
|
140
|
+
headers: {
|
|
141
|
+
Accept: 'application/json',
|
|
142
|
+
Authorization: `Bearer ${this.llamaCloudApiKey}`,
|
|
143
|
+
},
|
|
144
|
+
body: formData,
|
|
145
|
+
});
|
|
146
|
+
if (!uploadResponse.ok) {
|
|
147
|
+
const errorText = await uploadResponse.text();
|
|
148
|
+
throw new Error(`Failed to upload file: ${uploadResponse.status} - ${errorText}`);
|
|
149
|
+
}
|
|
150
|
+
const uploadResult = await uploadResponse.json();
|
|
151
|
+
const jobId = uploadResult.id || uploadResult.job_id;
|
|
152
|
+
if (!jobId) {
|
|
153
|
+
throw new Error('No job ID returned from upload');
|
|
154
|
+
}
|
|
155
|
+
logger_1.logger.info({
|
|
156
|
+
msg: '[DocumentProcessor] File uploaded to LlamaCloud',
|
|
157
|
+
jobId,
|
|
158
|
+
fileName,
|
|
159
|
+
});
|
|
160
|
+
// Step 2: Poll for job completion
|
|
161
|
+
let attempts = 0;
|
|
162
|
+
const maxAttempts = 60; // 60 attempts with 2 second delay = 2 minutes max
|
|
163
|
+
const pollDelay = 2000; // 2 seconds
|
|
164
|
+
while (attempts < maxAttempts) {
|
|
165
|
+
const statusResponse = await fetch(`https://api.cloud.llamaindex.ai/api/v1/parsing/job/${jobId}`, {
|
|
166
|
+
method: 'GET',
|
|
167
|
+
headers: {
|
|
168
|
+
Accept: 'application/json',
|
|
169
|
+
Authorization: `Bearer ${this.llamaCloudApiKey}`,
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
if (!statusResponse.ok) {
|
|
173
|
+
throw new Error(`Failed to check job status: ${statusResponse.status}`);
|
|
174
|
+
}
|
|
175
|
+
const statusResult = await statusResponse.json();
|
|
176
|
+
const status = statusResult.status || statusResult.job_status;
|
|
177
|
+
if (status === 'SUCCESS' || status === 'COMPLETED' || status === 'completed') {
|
|
178
|
+
// Step 3: Retrieve results in Markdown
|
|
179
|
+
// Create an AbortController for timeout
|
|
180
|
+
const controller = new AbortController();
|
|
181
|
+
const timeout = setTimeout(() => controller.abort(), 20000); // 20 second timeout
|
|
182
|
+
let resultResponse;
|
|
183
|
+
try {
|
|
184
|
+
resultResponse = await fetch(`https://api.cloud.llamaindex.ai/api/v1/parsing/job/${jobId}/result/markdown`, {
|
|
185
|
+
method: 'GET',
|
|
186
|
+
headers: {
|
|
187
|
+
Accept: 'application/json',
|
|
188
|
+
Authorization: `Bearer ${this.llamaCloudApiKey}`,
|
|
189
|
+
},
|
|
190
|
+
signal: controller.signal,
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
catch (fetchError) {
|
|
194
|
+
clearTimeout(timeout);
|
|
195
|
+
if (fetchError instanceof Error && fetchError.name === 'AbortError') {
|
|
196
|
+
throw new Error('Timeout fetching results from LlamaCloud after 20 seconds');
|
|
197
|
+
}
|
|
198
|
+
throw fetchError;
|
|
199
|
+
}
|
|
200
|
+
clearTimeout(timeout);
|
|
201
|
+
if (!resultResponse.ok) {
|
|
202
|
+
const errorText = await resultResponse.text();
|
|
203
|
+
throw new Error(`Failed to retrieve results: ${resultResponse.status} - ${errorText}`);
|
|
204
|
+
}
|
|
205
|
+
let resultData;
|
|
206
|
+
try {
|
|
207
|
+
// Read response using manual stream reading (more reliable than text())
|
|
208
|
+
let responseText;
|
|
209
|
+
if (resultResponse.body) {
|
|
210
|
+
const reader = resultResponse.body.getReader();
|
|
211
|
+
const chunks = [];
|
|
212
|
+
let totalLength = 0;
|
|
213
|
+
try {
|
|
214
|
+
while (true) {
|
|
215
|
+
const { done, value } = await reader.read();
|
|
216
|
+
if (done)
|
|
217
|
+
break;
|
|
218
|
+
if (value) {
|
|
219
|
+
chunks.push(value);
|
|
220
|
+
totalLength += value.length;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// Combine chunks
|
|
224
|
+
const combined = new Uint8Array(totalLength);
|
|
225
|
+
let offset = 0;
|
|
226
|
+
for (const chunk of chunks) {
|
|
227
|
+
combined.set(chunk, offset);
|
|
228
|
+
offset += chunk.length;
|
|
229
|
+
}
|
|
230
|
+
responseText = new TextDecoder().decode(combined);
|
|
231
|
+
}
|
|
232
|
+
finally {
|
|
233
|
+
reader.releaseLock();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
responseText = await resultResponse.text();
|
|
238
|
+
}
|
|
239
|
+
// Try to parse as JSON, but if it fails, use the text directly
|
|
240
|
+
try {
|
|
241
|
+
resultData = JSON.parse(responseText);
|
|
242
|
+
}
|
|
243
|
+
catch (_a) {
|
|
244
|
+
// If it's not JSON, assume it's the markdown content directly
|
|
245
|
+
resultData = responseText;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
catch (textError) {
|
|
249
|
+
logger_1.logger.error({
|
|
250
|
+
msg: '[DocumentProcessor] Failed to read response text',
|
|
251
|
+
jobId,
|
|
252
|
+
error: textError instanceof Error ? textError.message : String(textError),
|
|
253
|
+
stack: textError instanceof Error ? textError.stack : undefined,
|
|
254
|
+
});
|
|
255
|
+
throw new Error('Failed to read response from LlamaCloud');
|
|
256
|
+
}
|
|
257
|
+
logger_1.logger.debug({
|
|
258
|
+
msg: '[DocumentProcessor] Result data structure',
|
|
259
|
+
jobId,
|
|
260
|
+
dataType: typeof resultData,
|
|
261
|
+
keys: typeof resultData === 'object' && resultData !== null ? Object.keys(resultData) : [],
|
|
262
|
+
hasMarkdown: typeof resultData === 'object' && 'markdown' in resultData,
|
|
263
|
+
hasContent: typeof resultData === 'object' && 'content' in resultData,
|
|
264
|
+
hasText: typeof resultData === 'object' && 'text' in resultData,
|
|
265
|
+
});
|
|
266
|
+
// The API might return the markdown directly as a string or nested in an object
|
|
267
|
+
let markdownContent;
|
|
268
|
+
if (typeof resultData === 'string') {
|
|
269
|
+
markdownContent = resultData;
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
markdownContent = resultData.markdown || resultData.content || resultData.text || '';
|
|
273
|
+
}
|
|
274
|
+
if (!markdownContent) {
|
|
275
|
+
logger_1.logger.error({
|
|
276
|
+
msg: '[DocumentProcessor] No content in result',
|
|
277
|
+
jobId,
|
|
278
|
+
resultData: JSON.stringify(resultData).substring(0, 500),
|
|
279
|
+
});
|
|
280
|
+
throw new Error('No content returned from parsing');
|
|
281
|
+
}
|
|
282
|
+
logger_1.logger.info({
|
|
283
|
+
msg: '[DocumentProcessor] Successfully parsed document with LlamaCloud',
|
|
284
|
+
jobId,
|
|
285
|
+
contentLength: markdownContent.length,
|
|
286
|
+
preview: markdownContent.substring(0, 100),
|
|
287
|
+
});
|
|
288
|
+
logger_1.logger.debug({
|
|
289
|
+
msg: '[DocumentProcessor] About to return markdown content',
|
|
290
|
+
jobId,
|
|
291
|
+
});
|
|
292
|
+
return markdownContent;
|
|
293
|
+
}
|
|
294
|
+
else if (status === 'FAILED' || status === 'ERROR' || status === 'failed') {
|
|
295
|
+
throw new Error(`Parsing job failed: ${statusResult.error || 'Unknown error'}`);
|
|
296
|
+
}
|
|
297
|
+
// Wait before next attempt
|
|
298
|
+
await new Promise((resolve) => setTimeout(resolve, pollDelay));
|
|
299
|
+
attempts++;
|
|
300
|
+
}
|
|
301
|
+
throw new Error('Parsing job timed out after 2 minutes');
|
|
302
|
+
}
|
|
303
|
+
catch (err) {
|
|
304
|
+
logger_1.logger.warn({
|
|
305
|
+
message: '[DocumentProcessor] LlamaCloud parsing failed',
|
|
306
|
+
err,
|
|
307
|
+
});
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
finally {
|
|
311
|
+
logger_1.logger.debug({
|
|
312
|
+
msg: '[DocumentProcessor] parseWithLlamaCloud finished',
|
|
313
|
+
filePath,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Get MIME type for file extension
|
|
319
|
+
*/
|
|
320
|
+
getMimeType(fileExtension) {
|
|
321
|
+
const mimeTypes = {
|
|
322
|
+
'.pdf': 'application/pdf',
|
|
323
|
+
'.doc': 'application/msword',
|
|
324
|
+
'.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
325
|
+
'.txt': 'text/plain',
|
|
326
|
+
'.rtf': 'application/rtf',
|
|
327
|
+
'.jpg': 'image/jpeg',
|
|
328
|
+
'.jpeg': 'image/jpeg',
|
|
329
|
+
'.png': 'image/png',
|
|
330
|
+
'.gif': 'image/gif',
|
|
331
|
+
'.bmp': 'image/bmp',
|
|
332
|
+
'.webp': 'image/webp',
|
|
333
|
+
'.tiff': 'image/tiff',
|
|
334
|
+
'.xls': 'application/vnd.ms-excel',
|
|
335
|
+
'.xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
336
|
+
'.csv': 'text/csv',
|
|
337
|
+
'.html': 'text/html',
|
|
338
|
+
'.htm': 'text/html',
|
|
339
|
+
'.xml': 'application/xml',
|
|
340
|
+
'.md': 'text/markdown',
|
|
341
|
+
};
|
|
342
|
+
return mimeTypes[fileExtension.toLowerCase()] || 'application/octet-stream';
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Extract data from a document - either structured data using AI or raw text
|
|
346
|
+
*/
|
|
347
|
+
async extractFromDocument(options) {
|
|
348
|
+
logger_1.logger.debug({
|
|
349
|
+
msg: '[DocumentProcessor] extractFromDocument called',
|
|
350
|
+
hasDocumentPath: !!options.documentPath,
|
|
351
|
+
hasDocumentUrl: !!options.documentUrl,
|
|
352
|
+
hasDocumentContent: !!options.documentContent,
|
|
353
|
+
hasLLM: !!this.llm,
|
|
354
|
+
hasSchema: !!options.schema,
|
|
355
|
+
});
|
|
356
|
+
const startTime = Date.now();
|
|
357
|
+
try {
|
|
358
|
+
logger_1.logger.debug({
|
|
359
|
+
msg: '[DocumentProcessor] Getting document content',
|
|
360
|
+
});
|
|
361
|
+
// Determine document source and content
|
|
362
|
+
const { content, fileType, fileSize } = await this.getDocumentContent(options);
|
|
363
|
+
// Process document content based on type
|
|
364
|
+
let processedContent;
|
|
365
|
+
if (this.isImageFile(fileType)) {
|
|
366
|
+
processedContent = await this.processImageDocument(content, fileType, options.documentPath);
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
processedContent = await this.processTextDocument(content, options.documentPath, fileType);
|
|
370
|
+
}
|
|
371
|
+
logger_1.logger.info({
|
|
372
|
+
msg: '[DocumentProcessor] Document content processed',
|
|
373
|
+
fileType,
|
|
374
|
+
contentLength: processedContent.length,
|
|
375
|
+
});
|
|
376
|
+
const processingTime = Date.now() - startTime;
|
|
377
|
+
// If no LLM is provided, return the raw text content
|
|
378
|
+
if (!this.llm) {
|
|
379
|
+
return {
|
|
380
|
+
data: processedContent,
|
|
381
|
+
metadata: {
|
|
382
|
+
fileSize,
|
|
383
|
+
fileType,
|
|
384
|
+
processingTime,
|
|
385
|
+
contentLength: processedContent.length,
|
|
386
|
+
},
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
// If LLM is provided, extract data (structured or unstructured)
|
|
390
|
+
const extractedData = await this.extractStructuredData(processedContent, options.schema, options.llmConfig, options.systemPrompt);
|
|
391
|
+
return {
|
|
392
|
+
data: extractedData,
|
|
393
|
+
metadata: {
|
|
394
|
+
fileSize,
|
|
395
|
+
fileType,
|
|
396
|
+
processingTime,
|
|
397
|
+
contentLength: processedContent.length,
|
|
398
|
+
},
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
catch (err) {
|
|
402
|
+
logger_1.logger.error({
|
|
403
|
+
message: '[DocumentProcessor] Document processing failed',
|
|
404
|
+
err,
|
|
405
|
+
});
|
|
406
|
+
throw new Error(`Document processing failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Get document content from various sources
|
|
411
|
+
*/
|
|
412
|
+
async getDocumentContent(options) {
|
|
413
|
+
logger_1.logger.debug({
|
|
414
|
+
msg: '[DocumentProcessor] getDocumentContent called',
|
|
415
|
+
hasPath: !!options.documentPath,
|
|
416
|
+
hasContent: !!options.documentContent,
|
|
417
|
+
hasUrl: !!options.documentUrl,
|
|
418
|
+
});
|
|
419
|
+
// From file path
|
|
420
|
+
if (options.documentPath) {
|
|
421
|
+
if (!fs.existsSync(options.documentPath)) {
|
|
422
|
+
throw new Error(`Document not found: ${options.documentPath}`);
|
|
423
|
+
}
|
|
424
|
+
const content = fs.readFileSync(options.documentPath);
|
|
425
|
+
const fileType = path.extname(options.documentPath).toLowerCase();
|
|
426
|
+
return {
|
|
427
|
+
content,
|
|
428
|
+
fileType,
|
|
429
|
+
fileSize: content.length,
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
// From provided content
|
|
433
|
+
if (options.documentContent) {
|
|
434
|
+
// Try to infer file type from content if it's a buffer
|
|
435
|
+
let fileType = '.unknown';
|
|
436
|
+
if (Buffer.isBuffer(options.documentContent)) {
|
|
437
|
+
fileType = this.inferFileTypeFromBuffer(options.documentContent);
|
|
438
|
+
}
|
|
439
|
+
else if (typeof options.documentContent === 'string') {
|
|
440
|
+
fileType = '.txt'; // Assume text content
|
|
441
|
+
}
|
|
442
|
+
return {
|
|
443
|
+
content: options.documentContent,
|
|
444
|
+
fileType,
|
|
445
|
+
fileSize: Buffer.isBuffer(options.documentContent) ? options.documentContent.length : Buffer.byteLength(options.documentContent),
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
// From URL
|
|
449
|
+
if (options.documentUrl) {
|
|
450
|
+
logger_1.logger.debug({
|
|
451
|
+
msg: '[DocumentProcessor] Fetching document from URL',
|
|
452
|
+
url: options.documentUrl,
|
|
453
|
+
});
|
|
454
|
+
const response = await fetch(options.documentUrl);
|
|
455
|
+
logger_1.logger.debug({
|
|
456
|
+
msg: '[DocumentProcessor] URL fetch response',
|
|
457
|
+
status: response.status,
|
|
458
|
+
ok: response.ok,
|
|
459
|
+
});
|
|
460
|
+
if (!response.ok) {
|
|
461
|
+
throw new Error(`Failed to fetch document from URL: ${response.statusText}`);
|
|
462
|
+
}
|
|
463
|
+
const arrayBuffer = await response.arrayBuffer();
|
|
464
|
+
const content = Buffer.from(arrayBuffer);
|
|
465
|
+
const fileType = this.inferFileTypeFromUrl(options.documentUrl) || this.inferFileTypeFromBuffer(content);
|
|
466
|
+
logger_1.logger.debug({
|
|
467
|
+
msg: '[DocumentProcessor] Document fetched from URL',
|
|
468
|
+
contentSize: content.length,
|
|
469
|
+
fileType,
|
|
470
|
+
});
|
|
471
|
+
return {
|
|
472
|
+
content,
|
|
473
|
+
fileType,
|
|
474
|
+
fileSize: content.length,
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
throw new Error('No document source provided. Specify documentPath, documentContent, or documentUrl.');
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Process image documents by converting them to a standardized format
|
|
481
|
+
*/
|
|
482
|
+
async processImageDocument(content, fileType, filePath) {
|
|
483
|
+
try {
|
|
484
|
+
// First, try to use LlamaParser if available for text extraction
|
|
485
|
+
if (filePath && this.llamaCloudApiKey) {
|
|
486
|
+
logger_1.logger.debug({
|
|
487
|
+
msg: '[DocumentProcessor] Calling parseWithLlamaCloud for image',
|
|
488
|
+
filePath,
|
|
489
|
+
});
|
|
490
|
+
const parsedContent = await this.parseWithLlamaCloud(filePath);
|
|
491
|
+
logger_1.logger.debug({
|
|
492
|
+
msg: '[DocumentProcessor] parseWithLlamaCloud returned for image',
|
|
493
|
+
hasContent: !!parsedContent,
|
|
494
|
+
contentLength: parsedContent === null || parsedContent === void 0 ? void 0 : parsedContent.length,
|
|
495
|
+
});
|
|
496
|
+
if (parsedContent) {
|
|
497
|
+
return parsedContent;
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
// If no file path, create a temporary file for LlamaCloud parsing
|
|
501
|
+
if (!filePath && this.llamaCloudApiKey) {
|
|
502
|
+
const tempDir = os.tmpdir();
|
|
503
|
+
const tempFileName = `temp_${Date.now()}${fileType}`;
|
|
504
|
+
const tempFilePath = path.join(tempDir, tempFileName);
|
|
505
|
+
logger_1.logger.debug({
|
|
506
|
+
msg: '[DocumentProcessor] Creating temp file for image',
|
|
507
|
+
tempFilePath,
|
|
508
|
+
contentSize: content.length,
|
|
509
|
+
});
|
|
510
|
+
try {
|
|
511
|
+
fs.writeFileSync(tempFilePath, content);
|
|
512
|
+
logger_1.logger.debug({
|
|
513
|
+
msg: '[DocumentProcessor] Calling parseWithLlamaCloud for temp image',
|
|
514
|
+
tempFilePath,
|
|
515
|
+
});
|
|
516
|
+
const parsedContent = await this.parseWithLlamaCloud(tempFilePath);
|
|
517
|
+
logger_1.logger.debug({
|
|
518
|
+
msg: '[DocumentProcessor] parseWithLlamaCloud returned for temp image',
|
|
519
|
+
hasContent: !!parsedContent,
|
|
520
|
+
contentLength: parsedContent === null || parsedContent === void 0 ? void 0 : parsedContent.length,
|
|
521
|
+
});
|
|
522
|
+
fs.unlinkSync(tempFilePath);
|
|
523
|
+
if (parsedContent) {
|
|
524
|
+
return parsedContent;
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
catch (err) {
|
|
528
|
+
// Clean up temp file on error
|
|
529
|
+
if (fs.existsSync(tempFilePath)) {
|
|
530
|
+
fs.unlinkSync(tempFilePath);
|
|
531
|
+
}
|
|
532
|
+
logger_1.logger.warn({ msg: '[DocumentProcessor] Failed to parse image with LlamaCloud', err });
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
// Fallback: Convert to image format for LLM processing
|
|
536
|
+
// For PDFs, convert first page to image
|
|
537
|
+
if (fileType === '.pdf') {
|
|
538
|
+
throw new Error('Failed to convert PDF to image');
|
|
539
|
+
}
|
|
540
|
+
logger_1.logger.warn({
|
|
541
|
+
msg: '[DocumentProcessor] Sharp module not available. Using original image without optimization.',
|
|
542
|
+
fileType,
|
|
543
|
+
contentSize: content.length,
|
|
544
|
+
});
|
|
545
|
+
// If sharp is not available, use the original image
|
|
546
|
+
if (this.config.useBase64) {
|
|
547
|
+
// Return original image as base64
|
|
548
|
+
const base64Image = content.toString('base64');
|
|
549
|
+
const mimeType = this.getMimeType(fileType);
|
|
550
|
+
return `data:${mimeType};base64,${base64Image}`;
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
553
|
+
// Without sharp and without base64, we cannot process the image
|
|
554
|
+
return `[IMAGE CONTENT - ${fileType.toUpperCase()} file. Size: ${content.length} bytes. Consider using LLAMA_CLOUD_API_KEY for text extraction or set useBase64: true]`;
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
catch (err) {
|
|
558
|
+
throw new Error(`Failed to process image document: ${err instanceof Error ? err.message : String(err)}`);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Process text-based documents using LlamaParser or fallback methods
|
|
563
|
+
*/
|
|
564
|
+
async processTextDocument(content, filePath, fileType) {
|
|
565
|
+
// Try LlamaCloud parsing if we have a file path
|
|
566
|
+
if (filePath && this.llamaCloudApiKey) {
|
|
567
|
+
const parsedContent = await this.parseWithLlamaCloud(filePath);
|
|
568
|
+
if (parsedContent) {
|
|
569
|
+
return parsedContent;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
// If no file path but we have content and LlamaCloud API key, create a temp file
|
|
573
|
+
if (!filePath && this.llamaCloudApiKey && Buffer.isBuffer(content)) {
|
|
574
|
+
const tempDir = os.tmpdir();
|
|
575
|
+
const tempFileName = `temp_${Date.now()}${fileType || '.txt'}`;
|
|
576
|
+
const tempFilePath = path.join(tempDir, tempFileName);
|
|
577
|
+
try {
|
|
578
|
+
fs.writeFileSync(tempFilePath, content);
|
|
579
|
+
const parsedContent = await this.parseWithLlamaCloud(tempFilePath);
|
|
580
|
+
fs.unlinkSync(tempFilePath);
|
|
581
|
+
if (parsedContent) {
|
|
582
|
+
return parsedContent;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
catch (err) {
|
|
586
|
+
// Clean up temp file on error
|
|
587
|
+
if (fs.existsSync(tempFilePath)) {
|
|
588
|
+
fs.unlinkSync(tempFilePath);
|
|
589
|
+
}
|
|
590
|
+
logger_1.logger.warn({ msg: '[DocumentProcessor] Failed to parse text document with LlamaCloud', err });
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
// Fallback: handle based on file type
|
|
594
|
+
if (typeof content === 'string') {
|
|
595
|
+
return content;
|
|
596
|
+
}
|
|
597
|
+
// For binary content, convert to text
|
|
598
|
+
if (fileType === '.pdf' && !this.llamaCloudApiKey) {
|
|
599
|
+
throw new Error('PDF processing requires LLAMA_CLOUD_API_KEY environment variable for LlamaParser');
|
|
600
|
+
}
|
|
601
|
+
// Basic text extraction for simple formats
|
|
602
|
+
if (['.txt', '.md', '.html', '.htm', '.xml', '.csv'].includes(fileType || '')) {
|
|
603
|
+
return content.toString('utf-8');
|
|
604
|
+
}
|
|
605
|
+
// For unsupported binary formats without LlamaParser
|
|
606
|
+
throw new Error(`Unsupported document type ${fileType}. Please provide LLAMA_CLOUD_API_KEY for advanced document processing.`);
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Extract data using LLM - either structured with schema or unstructured with prompt
|
|
610
|
+
*/
|
|
611
|
+
async extractStructuredData(content, schema, llmConfig, systemPrompt) {
|
|
612
|
+
if (!this.llm) {
|
|
613
|
+
throw new Error('LLM instance is required for data extraction. Please provide an LLM when creating the DocumentProcessor.');
|
|
614
|
+
}
|
|
615
|
+
// Note: llmConfig is ignored when using the provided LLM instance
|
|
616
|
+
// The LLM should already be configured with the desired model and temperature
|
|
617
|
+
const defaultSystemPrompt = 'You are an expert data-extraction assistant. ' +
|
|
618
|
+
'Extract the requested information from the provided document content. ' +
|
|
619
|
+
'If you cannot find a value for a required field, use "N/A" or a descriptive placeholder. ' +
|
|
620
|
+
'Be accurate and thorough in your extraction.';
|
|
621
|
+
const finalSystemPrompt = systemPrompt || defaultSystemPrompt;
|
|
622
|
+
try {
|
|
623
|
+
// If schema is provided, use structured output
|
|
624
|
+
if (schema) {
|
|
625
|
+
// Check if the LLM supports withStructuredOutput
|
|
626
|
+
if (!('withStructuredOutput' in this.llm)) {
|
|
627
|
+
throw new Error('The provided LLM does not support structured output. Please use a compatible LLM instance.');
|
|
628
|
+
}
|
|
629
|
+
const structuredLlm = this.llm.withStructuredOutput(schema);
|
|
630
|
+
const result = await structuredLlm.invoke([
|
|
631
|
+
{
|
|
632
|
+
role: 'system',
|
|
633
|
+
content: finalSystemPrompt,
|
|
634
|
+
},
|
|
635
|
+
{
|
|
636
|
+
role: 'user',
|
|
637
|
+
content: `Please extract the following information from this document:\n\n${content}`,
|
|
638
|
+
},
|
|
639
|
+
]);
|
|
640
|
+
logger_1.logger.debug({
|
|
641
|
+
msg: '[DocumentProcessor] Structured data extraction completed',
|
|
642
|
+
extractedData: JSON.stringify(result, null, 2),
|
|
643
|
+
});
|
|
644
|
+
return result;
|
|
645
|
+
}
|
|
646
|
+
else {
|
|
647
|
+
// Without schema, return the LLM's text response
|
|
648
|
+
const response = await this.llm.invoke([
|
|
649
|
+
{
|
|
650
|
+
role: 'system',
|
|
651
|
+
content: finalSystemPrompt,
|
|
652
|
+
},
|
|
653
|
+
{
|
|
654
|
+
role: 'user',
|
|
655
|
+
content: `Please analyze and extract information from this document:\n\n${content}`,
|
|
656
|
+
},
|
|
657
|
+
]);
|
|
658
|
+
// Extract the text content from the response
|
|
659
|
+
let textContent;
|
|
660
|
+
if (typeof response.content === 'string') {
|
|
661
|
+
textContent = response.content;
|
|
662
|
+
}
|
|
663
|
+
else if (Array.isArray(response.content) && response.content.length > 0) {
|
|
664
|
+
// Handle array of content blocks
|
|
665
|
+
textContent = response.content.map((block) => (typeof block === 'string' ? block : block.text || '')).join('\n');
|
|
666
|
+
}
|
|
667
|
+
else {
|
|
668
|
+
textContent = String(response.content);
|
|
669
|
+
}
|
|
670
|
+
logger_1.logger.debug({
|
|
671
|
+
msg: '[DocumentProcessor] Unstructured data extraction completed',
|
|
672
|
+
contentLength: textContent.length,
|
|
673
|
+
});
|
|
674
|
+
return textContent;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
catch (err) {
|
|
678
|
+
throw new Error(`LLM extraction failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Check if file is an image type
|
|
683
|
+
*/
|
|
684
|
+
isImageFile(fileType) {
|
|
685
|
+
const imageTypes = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.tiff'];
|
|
686
|
+
return imageTypes.includes(fileType.toLowerCase());
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Infer file type from buffer content
|
|
690
|
+
*/
|
|
691
|
+
inferFileTypeFromBuffer(buffer) {
|
|
692
|
+
// Check common file signatures
|
|
693
|
+
const signatures = {
|
|
694
|
+
'89504E47': '.png',
|
|
695
|
+
FFD8FF: '.jpg',
|
|
696
|
+
'47494638': '.gif',
|
|
697
|
+
'25504446': '.pdf',
|
|
698
|
+
'504B0304': '.zip', // Also used by docx, xlsx, pptx
|
|
699
|
+
D0CF11E0: '.doc', // Also xls, ppt
|
|
700
|
+
};
|
|
701
|
+
const hex = buffer.toString('hex', 0, 4).toUpperCase();
|
|
702
|
+
for (const [signature, type] of Object.entries(signatures)) {
|
|
703
|
+
if (hex.startsWith(signature)) {
|
|
704
|
+
return type;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
return '.unknown';
|
|
708
|
+
}
|
|
709
|
+
/**
|
|
710
|
+
* Infer file type from URL
|
|
711
|
+
*/
|
|
712
|
+
inferFileTypeFromUrl(url) {
|
|
713
|
+
try {
|
|
714
|
+
const pathname = new URL(url).pathname;
|
|
715
|
+
const extension = path.extname(pathname).toLowerCase();
|
|
716
|
+
return extension || null;
|
|
717
|
+
}
|
|
718
|
+
catch (_a) {
|
|
719
|
+
return null;
|
|
720
|
+
}
|
|
721
|
+
}
|
|
722
|
+
/**
|
|
723
|
+
* Get list of supported document types
|
|
724
|
+
*/
|
|
725
|
+
static getSupportedDocumentTypes() {
|
|
726
|
+
return [...types_1.SUPPORTED_DOCUMENT_TYPES];
|
|
727
|
+
}
|
|
728
|
+
/**
|
|
729
|
+
* Check if a file type is supported
|
|
730
|
+
*/
|
|
731
|
+
static isDocumentTypeSupported(fileType) {
|
|
732
|
+
return types_1.SUPPORTED_DOCUMENT_TYPES.includes(fileType.toLowerCase());
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
exports.DocumentProcessor = DocumentProcessor;
|
|
736
|
+
//# sourceMappingURL=documentExtraction.js.map
|