@dexto/core 1.3.0 → 1.5.0
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 +53 -9
- package/dist/agent/DextoAgent.cjs +570 -210
- package/dist/agent/DextoAgent.d.ts +175 -35
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +568 -208
- package/dist/agent/agentCard.js +1 -1
- package/dist/agent/error-codes.cjs +1 -0
- package/dist/agent/error-codes.d.ts +2 -1
- package/dist/agent/error-codes.d.ts.map +1 -1
- package/dist/agent/error-codes.js +2 -1
- package/dist/agent/errors.cjs +13 -0
- package/dist/agent/errors.d.ts +4 -0
- package/dist/agent/errors.d.ts.map +1 -1
- package/dist/agent/errors.js +14 -1
- package/dist/agent/index.cjs +4 -1
- package/dist/agent/index.d.ts +2 -2
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +6 -2
- package/dist/agent/schemas.cjs +90 -68
- package/dist/agent/schemas.d.ts +5998 -146
- package/dist/agent/schemas.d.ts.map +1 -1
- package/dist/agent/schemas.js +90 -65
- package/dist/agent/state-manager.cjs +5 -5
- package/dist/agent/state-manager.d.ts +4 -4
- package/dist/agent/state-manager.js +6 -6
- package/dist/agent/types.d.ts +24 -10
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/approval/error-codes.js +1 -1
- package/dist/approval/errors.js +1 -1
- package/dist/approval/factory.js +1 -1
- package/dist/approval/index.js +1 -1
- package/dist/approval/manager.cjs +234 -4
- package/dist/approval/manager.d.ts +131 -4
- package/dist/approval/manager.d.ts.map +1 -1
- package/dist/approval/manager.js +225 -5
- package/dist/approval/schemas.cjs +57 -7
- package/dist/approval/schemas.d.ts +344 -33
- package/dist/approval/schemas.d.ts.map +1 -1
- package/dist/approval/schemas.js +54 -8
- package/dist/approval/types.cjs +1 -0
- package/dist/approval/types.d.ts +32 -1
- package/dist/approval/types.d.ts.map +1 -1
- package/dist/approval/types.js +2 -1
- package/dist/{chunk-C6A6W6XS.js → chunk-PTJYTZNU.js} +44 -1
- package/dist/context/compaction/factory.cjs +57 -0
- package/dist/context/compaction/factory.d.ts +17 -0
- package/dist/context/compaction/factory.d.ts.map +1 -0
- package/dist/context/compaction/factory.js +34 -0
- package/dist/context/compaction/index.cjs +49 -0
- package/dist/context/compaction/index.d.ts +11 -0
- package/dist/context/compaction/index.d.ts.map +1 -0
- package/dist/context/compaction/index.js +19 -0
- package/dist/context/compaction/overflow.cjs +43 -0
- package/dist/context/compaction/overflow.d.ts +33 -0
- package/dist/context/compaction/overflow.d.ts.map +1 -0
- package/dist/context/compaction/overflow.js +19 -0
- package/dist/context/compaction/provider.cjs +16 -0
- package/dist/context/compaction/provider.d.ts +48 -0
- package/dist/context/compaction/provider.d.ts.map +1 -0
- package/dist/context/compaction/providers/noop-provider.cjs +48 -0
- package/dist/context/compaction/providers/noop-provider.d.ts +24 -0
- package/dist/context/compaction/providers/noop-provider.d.ts.map +1 -0
- package/dist/context/compaction/providers/noop-provider.js +24 -0
- package/dist/context/compaction/providers/reactive-overflow-provider.cjs +61 -0
- package/dist/context/compaction/providers/reactive-overflow-provider.d.ts +36 -0
- package/dist/context/compaction/providers/reactive-overflow-provider.d.ts.map +1 -0
- package/dist/context/compaction/providers/reactive-overflow-provider.js +37 -0
- package/dist/{llm/tokenizer/factory.cjs → context/compaction/registry.cjs} +15 -20
- package/dist/context/compaction/registry.d.ts +19 -0
- package/dist/context/compaction/registry.d.ts.map +1 -0
- package/dist/context/compaction/registry.js +16 -0
- package/dist/context/compaction/schemas.cjs +38 -0
- package/dist/context/compaction/schemas.d.ts +24 -0
- package/dist/context/compaction/schemas.d.ts.map +1 -0
- package/dist/context/compaction/schemas.js +14 -0
- package/dist/{llm/tokenizer/types.cjs → context/compaction/strategies/noop.cjs} +12 -9
- package/dist/context/compaction/strategies/noop.d.ts +18 -0
- package/dist/context/compaction/strategies/noop.d.ts.map +1 -0
- package/dist/context/compaction/strategies/noop.js +13 -0
- package/dist/context/compaction/strategies/reactive-overflow.cjs +201 -0
- package/dist/context/compaction/strategies/reactive-overflow.d.ts +81 -0
- package/dist/context/compaction/strategies/reactive-overflow.d.ts.map +1 -0
- package/dist/context/compaction/strategies/reactive-overflow.js +178 -0
- package/dist/context/compaction/types.d.ts +20 -0
- package/dist/context/compaction/types.d.ts.map +1 -0
- package/dist/context/error-codes.cjs +7 -0
- package/dist/context/error-codes.d.ts +8 -1
- package/dist/context/error-codes.d.ts.map +1 -1
- package/dist/context/error-codes.js +8 -1
- package/dist/context/errors.cjs +68 -0
- package/dist/context/errors.d.ts +21 -0
- package/dist/context/errors.d.ts.map +1 -1
- package/dist/context/errors.js +69 -1
- package/dist/context/index.cjs +3 -1
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +2 -1
- package/dist/context/manager.cjs +280 -323
- package/dist/context/manager.d.ts +65 -111
- package/dist/context/manager.d.ts.map +1 -1
- package/dist/context/manager.js +280 -328
- package/dist/context/media-helpers.js +1 -1
- package/dist/context/types.cjs +49 -0
- package/dist/context/types.d.ts +187 -72
- package/dist/context/types.d.ts.map +1 -1
- package/dist/context/types.js +35 -0
- package/dist/context/utils.cjs +293 -290
- package/dist/context/utils.d.ts +32 -18
- package/dist/context/utils.d.ts.map +1 -1
- package/dist/context/utils.js +293 -290
- package/dist/errors/DextoBaseError.js +1 -1
- package/dist/errors/DextoRuntimeError.js +1 -1
- package/dist/errors/DextoValidationError.js +1 -1
- package/dist/errors/index.js +1 -1
- package/dist/errors/result-bridge.cjs +2 -3
- package/dist/errors/result-bridge.d.ts.map +1 -1
- package/dist/errors/result-bridge.js +3 -4
- package/dist/errors/types.js +1 -1
- package/dist/events/index.cjs +18 -1
- package/dist/events/index.d.ts +149 -12
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +19 -2
- package/dist/filesystem/error-codes.js +1 -1
- package/dist/filesystem/errors.js +1 -1
- package/dist/filesystem/filesystem-service.cjs +39 -0
- package/dist/filesystem/filesystem-service.d.ts +32 -0
- package/dist/filesystem/filesystem-service.d.ts.map +1 -1
- package/dist/filesystem/filesystem-service.js +40 -1
- package/dist/filesystem/index.d.ts +1 -1
- package/dist/filesystem/index.d.ts.map +1 -1
- package/dist/filesystem/index.js +1 -1
- package/dist/filesystem/path-validator.cjs +69 -1
- package/dist/filesystem/path-validator.d.ts +43 -2
- package/dist/filesystem/path-validator.d.ts.map +1 -1
- package/dist/filesystem/path-validator.js +70 -2
- package/dist/image/define-image.cjs +146 -0
- package/dist/image/define-image.d.ts +71 -0
- package/dist/image/define-image.d.ts.map +1 -0
- package/dist/image/define-image.js +121 -0
- package/dist/{llm/tokenizer/default.cjs → image/index.cjs} +10 -19
- package/dist/image/index.d.ts +53 -0
- package/dist/image/index.d.ts.map +1 -0
- package/dist/image/index.js +7 -0
- package/dist/image/types.d.ts +231 -0
- package/dist/image/types.d.ts.map +1 -0
- package/dist/image/types.js +0 -0
- package/dist/index.browser.cjs +23 -8
- package/dist/index.browser.d.ts +4 -3
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.browser.js +20 -3
- package/dist/index.cjs +5 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/llm/error-codes.cjs +1 -1
- package/dist/llm/error-codes.d.ts +1 -1
- package/dist/llm/error-codes.d.ts.map +1 -1
- package/dist/llm/error-codes.js +2 -2
- package/dist/llm/errors.cjs +34 -10
- package/dist/llm/errors.d.ts +23 -11
- package/dist/llm/errors.d.ts.map +1 -1
- package/dist/llm/errors.js +36 -12
- package/dist/llm/executor/stream-processor.cjs +375 -0
- package/dist/llm/executor/stream-processor.d.ts +55 -0
- package/dist/llm/executor/stream-processor.d.ts.map +1 -0
- package/dist/llm/executor/stream-processor.js +352 -0
- package/dist/llm/executor/tool-output-truncator.cjs +75 -0
- package/dist/llm/executor/tool-output-truncator.d.ts +27 -0
- package/dist/llm/executor/tool-output-truncator.d.ts.map +1 -0
- package/dist/llm/executor/tool-output-truncator.js +48 -0
- package/dist/llm/executor/turn-executor.cjs +780 -0
- package/dist/llm/executor/turn-executor.d.ts +167 -0
- package/dist/llm/executor/turn-executor.d.ts.map +1 -0
- package/dist/llm/executor/turn-executor.js +711 -0
- package/dist/llm/executor/types.cjs +16 -0
- package/dist/llm/executor/types.d.ts +27 -0
- package/dist/llm/executor/types.d.ts.map +1 -0
- package/dist/llm/executor/types.js +0 -0
- package/dist/llm/formatters/vercel.cjs +26 -188
- package/dist/llm/formatters/vercel.d.ts +2 -14
- package/dist/llm/formatters/vercel.d.ts.map +1 -1
- package/dist/llm/formatters/vercel.js +25 -187
- package/dist/llm/index.cjs +18 -1
- package/dist/llm/index.d.ts +2 -0
- package/dist/llm/index.d.ts.map +1 -1
- package/dist/llm/index.js +14 -0
- package/dist/llm/providers/local/ai-sdk-adapter.cjs +308 -0
- package/dist/llm/providers/local/ai-sdk-adapter.d.ts +29 -0
- package/dist/llm/providers/local/ai-sdk-adapter.d.ts.map +1 -0
- package/dist/llm/providers/local/ai-sdk-adapter.js +278 -0
- package/dist/llm/providers/local/downloader.cjs +291 -0
- package/dist/llm/providers/local/downloader.d.ts +82 -0
- package/dist/llm/providers/local/downloader.d.ts.map +1 -0
- package/dist/llm/providers/local/downloader.js +251 -0
- package/dist/llm/providers/local/error-codes.cjs +57 -0
- package/dist/llm/providers/local/error-codes.d.ts +66 -0
- package/dist/llm/providers/local/error-codes.d.ts.map +1 -0
- package/dist/llm/providers/local/error-codes.js +34 -0
- package/dist/llm/providers/local/errors.cjs +240 -0
- package/dist/llm/providers/local/errors.d.ts +31 -0
- package/dist/llm/providers/local/errors.d.ts.map +1 -0
- package/dist/llm/providers/local/errors.js +217 -0
- package/dist/llm/providers/local/gpu-detector.cjs +214 -0
- package/dist/llm/providers/local/gpu-detector.d.ts +28 -0
- package/dist/llm/providers/local/gpu-detector.d.ts.map +1 -0
- package/dist/llm/providers/local/gpu-detector.js +178 -0
- package/dist/llm/providers/local/index.cjs +147 -0
- package/dist/llm/providers/local/index.d.ts +21 -0
- package/dist/llm/providers/local/index.d.ts.map +1 -0
- package/dist/llm/providers/local/index.js +126 -0
- package/dist/llm/providers/local/node-llama-provider.cjs +216 -0
- package/dist/llm/providers/local/node-llama-provider.d.ts +90 -0
- package/dist/llm/providers/local/node-llama-provider.d.ts.map +1 -0
- package/dist/llm/providers/local/node-llama-provider.js +176 -0
- package/dist/llm/providers/local/ollama-provider.cjs +230 -0
- package/dist/llm/providers/local/ollama-provider.d.ts +70 -0
- package/dist/llm/providers/local/ollama-provider.d.ts.map +1 -0
- package/dist/llm/providers/local/ollama-provider.js +198 -0
- package/dist/llm/providers/local/registry.cjs +343 -0
- package/dist/llm/providers/local/registry.d.ts +51 -0
- package/dist/llm/providers/local/registry.d.ts.map +1 -0
- package/dist/llm/providers/local/registry.js +312 -0
- package/dist/llm/providers/local/schemas.cjs +169 -0
- package/dist/llm/providers/local/schemas.d.ts +395 -0
- package/dist/llm/providers/local/schemas.d.ts.map +1 -0
- package/dist/llm/providers/local/schemas.js +133 -0
- package/dist/llm/providers/local/types.cjs +16 -0
- package/dist/llm/providers/local/types.d.ts +219 -0
- package/dist/llm/providers/local/types.d.ts.map +1 -0
- package/dist/llm/providers/local/types.js +0 -0
- package/dist/llm/providers/openrouter-model-registry.cjs +350 -0
- package/dist/llm/providers/openrouter-model-registry.d.ts +120 -0
- package/dist/llm/providers/openrouter-model-registry.d.ts.map +1 -0
- package/dist/llm/providers/openrouter-model-registry.js +309 -0
- package/dist/llm/registry.cjs +569 -52
- package/dist/llm/registry.d.ts +79 -39
- package/dist/llm/registry.d.ts.map +1 -1
- package/dist/llm/registry.js +564 -49
- package/dist/llm/resolver.cjs +62 -34
- package/dist/llm/resolver.d.ts +3 -3
- package/dist/llm/resolver.d.ts.map +1 -1
- package/dist/llm/resolver.js +69 -38
- package/dist/llm/schemas.cjs +92 -97
- package/dist/llm/schemas.d.ts +162 -39
- package/dist/llm/schemas.d.ts.map +1 -1
- package/dist/llm/schemas.js +93 -100
- package/dist/llm/services/factory.cjs +88 -103
- package/dist/llm/services/factory.d.ts +17 -4
- package/dist/llm/services/factory.d.ts.map +1 -1
- package/dist/llm/services/factory.js +87 -93
- package/dist/llm/services/test-utils.integration.cjs +28 -10
- package/dist/llm/services/test-utils.integration.d.ts +7 -1
- package/dist/llm/services/test-utils.integration.d.ts.map +1 -1
- package/dist/llm/services/test-utils.integration.js +33 -12
- package/dist/llm/services/types.d.ts +1 -28
- package/dist/llm/services/types.d.ts.map +1 -1
- package/dist/llm/services/vercel.cjs +58 -469
- package/dist/llm/services/vercel.d.ts +39 -21
- package/dist/llm/services/vercel.d.ts.map +1 -1
- package/dist/llm/services/vercel.js +60 -476
- package/dist/llm/types.cjs +11 -4
- package/dist/llm/types.d.ts +9 -9
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/llm/types.js +12 -4
- package/dist/llm/validation.js +1 -1
- package/dist/logger/browser.js +1 -1
- package/dist/logger/factory.js +1 -1
- package/dist/logger/index.js +1 -1
- package/dist/logger/logger.js +1 -1
- package/dist/logger/v2/dexto-logger.cjs +34 -6
- package/dist/logger/v2/dexto-logger.d.ts +20 -2
- package/dist/logger/v2/dexto-logger.d.ts.map +1 -1
- package/dist/logger/v2/dexto-logger.js +35 -7
- package/dist/logger/v2/error-codes.js +1 -1
- package/dist/logger/v2/errors.js +1 -1
- package/dist/logger/v2/schemas.js +1 -1
- package/dist/logger/v2/test-utils.cjs +70 -0
- package/dist/logger/v2/test-utils.d.ts +17 -0
- package/dist/logger/v2/test-utils.d.ts.map +1 -0
- package/dist/logger/v2/test-utils.js +46 -0
- package/dist/logger/v2/transport-factory.js +1 -1
- package/dist/logger/v2/transports/console-transport.js +1 -1
- package/dist/logger/v2/transports/file-transport.cjs +6 -0
- package/dist/logger/v2/transports/file-transport.d.ts +4 -0
- package/dist/logger/v2/transports/file-transport.d.ts.map +1 -1
- package/dist/logger/v2/transports/file-transport.js +7 -1
- package/dist/logger/v2/types.cjs +1 -0
- package/dist/logger/v2/types.d.ts +18 -2
- package/dist/logger/v2/types.d.ts.map +1 -1
- package/dist/logger/v2/types.js +2 -1
- package/dist/mcp/error-codes.cjs +1 -0
- package/dist/mcp/error-codes.d.ts +1 -0
- package/dist/mcp/error-codes.d.ts.map +1 -1
- package/dist/mcp/error-codes.js +2 -1
- package/dist/mcp/errors.cjs +13 -0
- package/dist/mcp/errors.d.ts +7 -0
- package/dist/mcp/errors.d.ts.map +1 -1
- package/dist/mcp/errors.js +14 -1
- package/dist/mcp/manager.cjs +12 -0
- package/dist/mcp/manager.d.ts +17 -0
- package/dist/mcp/manager.d.ts.map +1 -1
- package/dist/mcp/manager.js +13 -1
- package/dist/mcp/mcp-client.cjs +0 -3
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js +1 -4
- package/dist/mcp/resolver.js +1 -1
- package/dist/mcp/schemas.cjs +6 -0
- package/dist/mcp/schemas.d.ts +52 -0
- package/dist/mcp/schemas.d.ts.map +1 -1
- package/dist/mcp/schemas.js +6 -1
- package/dist/memory/error-codes.js +1 -1
- package/dist/memory/errors.js +1 -1
- package/dist/memory/index.js +1 -1
- package/dist/memory/manager.js +1 -1
- package/dist/memory/schemas.d.ts +3 -3
- package/dist/memory/schemas.js +1 -1
- package/dist/plugins/builtins/content-policy.js +1 -1
- package/dist/plugins/builtins/response-sanitizer.js +1 -1
- package/dist/plugins/error-codes.cjs +3 -0
- package/dist/plugins/error-codes.d.ts +7 -1
- package/dist/plugins/error-codes.d.ts.map +1 -1
- package/dist/plugins/error-codes.js +4 -1
- package/dist/plugins/index.cjs +7 -0
- package/dist/plugins/index.d.ts +4 -2
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +7 -2
- package/dist/plugins/loader.js +1 -1
- package/dist/plugins/manager.cjs +92 -7
- package/dist/plugins/manager.d.ts +10 -3
- package/dist/plugins/manager.d.ts.map +1 -1
- package/dist/plugins/manager.js +93 -8
- package/dist/plugins/registrations/builtins.js +1 -1
- package/dist/plugins/registry.cjs +63 -0
- package/dist/plugins/registry.d.ts +101 -0
- package/dist/plugins/registry.d.ts.map +1 -0
- package/dist/plugins/registry.js +39 -0
- package/dist/plugins/schemas.cjs +17 -5
- package/dist/plugins/schemas.d.ts +65 -8
- package/dist/plugins/schemas.d.ts.map +1 -1
- package/dist/plugins/schemas.js +16 -5
- package/dist/plugins/types.d.ts +0 -1
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/process/command-validator.js +1 -1
- package/dist/process/error-codes.js +1 -1
- package/dist/process/errors.js +1 -1
- package/dist/process/index.js +1 -1
- package/dist/process/process-service.cjs +78 -26
- package/dist/process/process-service.d.ts +6 -1
- package/dist/process/process-service.d.ts.map +1 -1
- package/dist/process/process-service.js +79 -27
- package/dist/process/types.d.ts +2 -2
- package/dist/process/types.d.ts.map +1 -1
- package/dist/prompts/error-codes.cjs +1 -0
- package/dist/prompts/error-codes.d.ts +2 -1
- package/dist/prompts/error-codes.d.ts.map +1 -1
- package/dist/prompts/error-codes.js +2 -1
- package/dist/prompts/errors.cjs +15 -0
- package/dist/prompts/errors.d.ts +4 -0
- package/dist/prompts/errors.d.ts.map +1 -1
- package/dist/prompts/errors.js +16 -1
- package/dist/prompts/index.js +1 -1
- package/dist/prompts/name-validation.js +1 -1
- package/dist/prompts/prompt-manager.cjs +13 -2
- package/dist/prompts/prompt-manager.d.ts +7 -0
- package/dist/prompts/prompt-manager.d.ts.map +1 -1
- package/dist/prompts/prompt-manager.js +14 -3
- package/dist/prompts/providers/config-prompt-provider.cjs +12 -3
- package/dist/prompts/providers/config-prompt-provider.d.ts +2 -1
- package/dist/prompts/providers/config-prompt-provider.d.ts.map +1 -1
- package/dist/prompts/providers/config-prompt-provider.js +13 -4
- package/dist/prompts/providers/custom-prompt-provider.js +1 -1
- package/dist/prompts/providers/mcp-prompt-provider.js +1 -1
- package/dist/prompts/schemas.d.ts +12 -0
- package/dist/prompts/schemas.d.ts.map +1 -1
- package/dist/prompts/schemas.js +1 -1
- package/dist/prompts/types.d.ts +2 -0
- package/dist/prompts/types.d.ts.map +1 -1
- package/dist/prompts/utils.js +1 -1
- package/dist/providers/base-registry.cjs +147 -0
- package/dist/providers/base-registry.d.ts +147 -0
- package/dist/providers/base-registry.d.ts.map +1 -0
- package/dist/providers/base-registry.js +123 -0
- package/dist/providers/discovery.cjs +95 -0
- package/dist/providers/discovery.d.ts +94 -0
- package/dist/providers/discovery.d.ts.map +1 -0
- package/dist/providers/discovery.js +70 -0
- package/dist/providers/index.cjs +24 -0
- package/dist/providers/index.d.ts +32 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +2 -0
- package/dist/resources/error-codes.js +1 -1
- package/dist/resources/errors.js +1 -1
- package/dist/resources/handlers/blob-handler.js +1 -1
- package/dist/resources/handlers/factory.js +1 -1
- package/dist/resources/handlers/filesystem-handler.js +1 -1
- package/dist/resources/index.js +1 -1
- package/dist/resources/internal-provider.js +1 -1
- package/dist/resources/manager.js +1 -1
- package/dist/resources/reference-parser.cjs +3 -3
- package/dist/resources/reference-parser.d.ts.map +1 -1
- package/dist/resources/reference-parser.js +4 -4
- package/dist/resources/schemas.js +1 -1
- package/dist/search/index.js +1 -1
- package/dist/search/search-service.js +1 -1
- package/dist/session/chat-session.cjs +169 -54
- package/dist/session/chat-session.d.ts +69 -29
- package/dist/session/chat-session.d.ts.map +1 -1
- package/dist/session/chat-session.js +171 -56
- package/dist/session/error-codes.js +1 -1
- package/dist/session/errors.js +1 -1
- package/dist/session/history/database.cjs +134 -21
- package/dist/session/history/database.d.ts +37 -8
- package/dist/session/history/database.d.ts.map +1 -1
- package/dist/session/history/database.js +135 -22
- package/dist/session/history/factory.js +1 -1
- package/dist/session/history/memory.cjs +18 -0
- package/dist/session/history/memory.d.ts +8 -0
- package/dist/session/history/memory.d.ts.map +1 -1
- package/dist/session/history/memory.js +19 -1
- package/dist/session/history/types.d.ts +13 -1
- package/dist/session/history/types.d.ts.map +1 -1
- package/dist/session/index.cjs +3 -0
- package/dist/session/index.d.ts +3 -0
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +3 -1
- package/dist/session/message-queue.cjs +201 -0
- package/dist/session/message-queue.d.ts +114 -0
- package/dist/session/message-queue.d.ts.map +1 -0
- package/dist/session/message-queue.js +178 -0
- package/dist/session/schemas.js +1 -1
- package/dist/session/session-manager.cjs +57 -7
- package/dist/session/session-manager.d.ts +18 -0
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +58 -8
- package/dist/session/title-generator.cjs +4 -8
- package/dist/session/title-generator.d.ts +1 -2
- package/dist/session/title-generator.d.ts.map +1 -1
- package/dist/session/title-generator.js +5 -9
- package/dist/session/types.cjs +16 -0
- package/dist/session/types.d.ts +14 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +0 -0
- package/dist/storage/blob/factory.cjs +8 -11
- package/dist/storage/blob/factory.d.ts +32 -6
- package/dist/storage/blob/factory.d.ts.map +1 -1
- package/dist/storage/blob/factory.js +9 -12
- package/dist/storage/blob/index.cjs +56 -0
- package/dist/storage/blob/index.d.ts +45 -0
- package/dist/storage/blob/index.d.ts.map +1 -0
- package/dist/storage/blob/index.js +30 -0
- package/dist/storage/blob/local-blob-store.js +1 -1
- package/dist/storage/blob/memory-blob-store.js +1 -1
- package/dist/storage/blob/provider.cjs +16 -0
- package/dist/storage/blob/provider.d.ts +50 -0
- package/dist/storage/blob/provider.d.ts.map +1 -0
- package/dist/storage/blob/provider.js +0 -0
- package/dist/storage/blob/providers/index.cjs +31 -0
- package/dist/storage/blob/providers/index.d.ts +8 -0
- package/dist/storage/blob/providers/index.d.ts.map +1 -0
- package/dist/storage/blob/providers/index.js +7 -0
- package/dist/storage/blob/providers/local.cjs +39 -0
- package/dist/storage/blob/providers/local.d.ts +17 -0
- package/dist/storage/blob/providers/local.d.ts.map +1 -0
- package/dist/storage/blob/providers/local.js +16 -0
- package/dist/storage/blob/providers/memory.cjs +39 -0
- package/dist/storage/blob/providers/memory.d.ts +17 -0
- package/dist/storage/blob/providers/memory.d.ts.map +1 -0
- package/dist/storage/blob/providers/memory.js +16 -0
- package/dist/storage/blob/registry.cjs +50 -0
- package/dist/storage/blob/registry.d.ts +42 -0
- package/dist/storage/blob/registry.d.ts.map +1 -0
- package/dist/storage/blob/registry.js +26 -0
- package/dist/storage/blob/schemas.cjs +9 -12
- package/dist/storage/blob/schemas.d.ts +39 -34
- package/dist/storage/blob/schemas.d.ts.map +1 -1
- package/dist/storage/blob/schemas.js +7 -12
- package/dist/storage/cache/factory.cjs +8 -36
- package/dist/storage/cache/factory.d.ts +32 -7
- package/dist/storage/cache/factory.d.ts.map +1 -1
- package/dist/storage/cache/factory.js +9 -27
- package/dist/storage/cache/index.cjs +53 -0
- package/dist/storage/cache/index.d.ts +44 -0
- package/dist/storage/cache/index.d.ts.map +1 -0
- package/dist/storage/cache/index.js +28 -0
- package/dist/storage/cache/memory-cache-store.js +1 -1
- package/dist/storage/cache/provider.cjs +16 -0
- package/dist/storage/cache/provider.d.ts +56 -0
- package/dist/storage/cache/provider.d.ts.map +1 -0
- package/dist/storage/cache/provider.js +0 -0
- package/dist/storage/cache/providers/index.cjs +31 -0
- package/dist/storage/cache/providers/index.d.ts +8 -0
- package/dist/storage/cache/providers/index.d.ts.map +1 -0
- package/dist/storage/cache/providers/index.js +7 -0
- package/dist/storage/cache/providers/memory.cjs +40 -0
- package/dist/storage/cache/providers/memory.d.ts +17 -0
- package/dist/storage/cache/providers/memory.d.ts.map +1 -0
- package/dist/storage/cache/providers/memory.js +17 -0
- package/dist/storage/cache/providers/redis.cjs +66 -0
- package/dist/storage/cache/providers/redis.d.ts +20 -0
- package/dist/storage/cache/providers/redis.d.ts.map +1 -0
- package/dist/storage/cache/providers/redis.js +33 -0
- package/dist/storage/cache/redis-store.js +1 -1
- package/dist/{llm/tokenizer/google.cjs → storage/cache/registry.cjs} +23 -25
- package/dist/storage/cache/registry.d.ts +42 -0
- package/dist/storage/cache/registry.d.ts.map +1 -0
- package/dist/storage/cache/registry.js +26 -0
- package/dist/storage/cache/schemas.cjs +6 -2
- package/dist/storage/cache/schemas.d.ts +2 -3
- package/dist/storage/cache/schemas.d.ts.map +1 -1
- package/dist/storage/cache/schemas.js +4 -2
- package/dist/storage/database/factory.cjs +8 -47
- package/dist/storage/database/factory.d.ts +34 -8
- package/dist/storage/database/factory.d.ts.map +1 -1
- package/dist/storage/database/factory.js +9 -38
- package/dist/storage/database/index.cjs +58 -0
- package/dist/storage/database/index.d.ts +45 -0
- package/dist/storage/database/index.d.ts.map +1 -0
- package/dist/storage/database/index.js +37 -0
- package/dist/storage/database/memory-database-store.js +1 -1
- package/dist/storage/database/postgres-store.cjs +12 -0
- package/dist/storage/database/postgres-store.d.ts.map +1 -1
- package/dist/storage/database/postgres-store.js +13 -1
- package/dist/storage/database/provider.cjs +16 -0
- package/dist/storage/database/provider.d.ts +56 -0
- package/dist/storage/database/provider.d.ts.map +1 -0
- package/dist/storage/database/provider.js +0 -0
- package/dist/storage/database/providers/index.cjs +34 -0
- package/dist/storage/database/providers/index.d.ts +9 -0
- package/dist/storage/database/providers/index.d.ts.map +1 -0
- package/dist/storage/database/providers/index.js +9 -0
- package/dist/storage/database/providers/memory.cjs +40 -0
- package/dist/storage/database/providers/memory.d.ts +16 -0
- package/dist/storage/database/providers/memory.d.ts.map +1 -0
- package/dist/storage/database/providers/memory.js +17 -0
- package/dist/storage/database/providers/postgres.cjs +62 -0
- package/dist/storage/database/providers/postgres.d.ts +19 -0
- package/dist/storage/database/providers/postgres.d.ts.map +1 -0
- package/dist/storage/database/providers/postgres.js +29 -0
- package/dist/storage/database/providers/sqlite.cjs +66 -0
- package/dist/storage/database/providers/sqlite.d.ts +20 -0
- package/dist/storage/database/providers/sqlite.d.ts.map +1 -0
- package/dist/storage/database/providers/sqlite.js +33 -0
- package/dist/storage/database/registry.cjs +50 -0
- package/dist/storage/database/registry.d.ts +42 -0
- package/dist/storage/database/registry.d.ts.map +1 -0
- package/dist/storage/database/registry.js +26 -0
- package/dist/storage/database/schemas.cjs +8 -2
- package/dist/storage/database/schemas.d.ts +3 -4
- package/dist/storage/database/schemas.d.ts.map +1 -1
- package/dist/storage/database/schemas.js +5 -2
- package/dist/storage/database/sqlite-store.js +1 -1
- package/dist/storage/error-codes.cjs +6 -0
- package/dist/storage/error-codes.d.ts +7 -1
- package/dist/storage/error-codes.d.ts.map +1 -1
- package/dist/storage/error-codes.js +7 -1
- package/dist/storage/errors.cjs +80 -0
- package/dist/storage/errors.d.ts +24 -0
- package/dist/storage/errors.d.ts.map +1 -1
- package/dist/storage/errors.js +81 -1
- package/dist/storage/index.cjs +47 -4
- package/dist/storage/index.d.ts +34 -8
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +33 -4
- package/dist/storage/schemas.cjs +4 -0
- package/dist/storage/schemas.d.ts +17 -50
- package/dist/storage/schemas.d.ts.map +1 -1
- package/dist/storage/schemas.js +6 -2
- package/dist/storage/storage-manager.cjs +6 -6
- package/dist/storage/storage-manager.d.ts.map +1 -1
- package/dist/storage/storage-manager.js +4 -4
- package/dist/systemPrompt/contributors.js +1 -1
- package/dist/systemPrompt/error-codes.js +1 -1
- package/dist/systemPrompt/errors.js +1 -1
- package/dist/systemPrompt/in-built-prompts.cjs +7 -6
- package/dist/systemPrompt/in-built-prompts.d.ts +2 -2
- package/dist/systemPrompt/in-built-prompts.d.ts.map +1 -1
- package/dist/systemPrompt/in-built-prompts.js +7 -6
- package/dist/systemPrompt/index.js +1 -1
- package/dist/systemPrompt/manager.js +1 -1
- package/dist/systemPrompt/registry.cjs +2 -2
- package/dist/systemPrompt/registry.d.ts +1 -1
- package/dist/systemPrompt/registry.d.ts.map +1 -1
- package/dist/systemPrompt/registry.js +3 -3
- package/dist/systemPrompt/schemas.cjs +2 -2
- package/dist/systemPrompt/schemas.d.ts +18 -18
- package/dist/systemPrompt/schemas.js +3 -3
- package/dist/telemetry/decorators.js +1 -1
- package/dist/telemetry/error-codes.js +1 -1
- package/dist/telemetry/errors.js +1 -1
- package/dist/telemetry/exporters.js +1 -1
- package/dist/telemetry/index.js +1 -1
- package/dist/telemetry/schemas.js +1 -1
- package/dist/telemetry/telemetry.js +1 -1
- package/dist/telemetry/utils.js +1 -1
- package/dist/tools/bash-pattern-utils.cjs +91 -0
- package/dist/tools/bash-pattern-utils.d.ts +58 -0
- package/dist/tools/bash-pattern-utils.d.ts.map +1 -0
- package/dist/tools/bash-pattern-utils.js +64 -0
- package/dist/tools/confirmation/allowed-tools-provider/factory.js +1 -1
- package/dist/tools/confirmation/allowed-tools-provider/in-memory.js +1 -1
- package/dist/tools/confirmation/allowed-tools-provider/storage.js +1 -1
- package/dist/tools/custom-tool-registry.cjs +64 -0
- package/dist/tools/custom-tool-registry.d.ts +120 -0
- package/dist/tools/custom-tool-registry.d.ts.map +1 -0
- package/dist/tools/custom-tool-registry.js +40 -0
- package/dist/tools/custom-tool-schema-registry.cjs +164 -0
- package/dist/tools/custom-tool-schema-registry.d.ts +86 -0
- package/dist/tools/custom-tool-schema-registry.d.ts.map +1 -0
- package/dist/tools/custom-tool-schema-registry.js +140 -0
- package/dist/tools/display-types.cjs +60 -0
- package/dist/tools/display-types.d.ts +133 -0
- package/dist/tools/display-types.d.ts.map +1 -0
- package/dist/tools/display-types.js +32 -0
- package/dist/tools/error-codes.cjs +5 -0
- package/dist/tools/error-codes.d.ts +6 -1
- package/dist/tools/error-codes.d.ts.map +1 -1
- package/dist/tools/error-codes.js +6 -1
- package/dist/tools/errors.cjs +71 -0
- package/dist/tools/errors.d.ts +33 -0
- package/dist/tools/errors.d.ts.map +1 -1
- package/dist/tools/errors.js +72 -1
- package/dist/tools/index.cjs +15 -1
- package/dist/tools/index.d.ts +5 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +13 -2
- package/dist/tools/internal-tools/constants.cjs +3 -9
- package/dist/tools/internal-tools/constants.d.ts +1 -1
- package/dist/tools/internal-tools/constants.d.ts.map +1 -1
- package/dist/tools/internal-tools/constants.js +4 -10
- package/dist/tools/internal-tools/implementations/ask-user-tool.cjs +1 -1
- package/dist/tools/internal-tools/implementations/ask-user-tool.js +2 -2
- package/dist/tools/internal-tools/implementations/delegate-to-url-tool.js +1 -1
- package/dist/tools/internal-tools/implementations/get-resource-tool.cjs +113 -0
- package/dist/tools/internal-tools/implementations/get-resource-tool.d.ts +30 -0
- package/dist/tools/internal-tools/implementations/get-resource-tool.d.ts.map +1 -0
- package/dist/tools/internal-tools/implementations/get-resource-tool.js +90 -0
- package/dist/tools/internal-tools/implementations/list-resources-tool.cjs +91 -0
- package/dist/tools/internal-tools/implementations/list-resources-tool.d.ts +24 -0
- package/dist/tools/internal-tools/implementations/list-resources-tool.d.ts.map +1 -0
- package/dist/tools/internal-tools/implementations/list-resources-tool.js +68 -0
- package/dist/tools/internal-tools/implementations/search-history-tool.js +1 -1
- package/dist/tools/internal-tools/provider.cjs +175 -31
- package/dist/tools/internal-tools/provider.d.ts +62 -14
- package/dist/tools/internal-tools/provider.d.ts.map +1 -1
- package/dist/tools/internal-tools/provider.js +176 -32
- package/dist/tools/internal-tools/registry.cjs +19 -43
- package/dist/tools/internal-tools/registry.d.ts +32 -11
- package/dist/tools/internal-tools/registry.d.ts.map +1 -1
- package/dist/tools/internal-tools/registry.js +20 -44
- package/dist/tools/schemas.cjs +36 -6
- package/dist/tools/schemas.d.ts +74 -5
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +30 -6
- package/dist/tools/tool-manager.cjs +279 -30
- package/dist/tools/tool-manager.d.ts +45 -4
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +284 -31
- package/dist/tools/types.d.ts +63 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils/api-key-resolver.cjs +19 -1
- package/dist/utils/api-key-resolver.d.ts.map +1 -1
- package/dist/utils/api-key-resolver.js +20 -2
- package/dist/utils/async-context.js +1 -1
- package/dist/utils/debug.js +1 -1
- package/dist/{llm/tokenizer/anthropic.cjs → utils/defer.cjs} +19 -20
- package/dist/utils/defer.d.ts +63 -0
- package/dist/utils/defer.d.ts.map +1 -0
- package/dist/utils/defer.js +19 -0
- package/dist/utils/error-conversion.js +1 -1
- package/dist/utils/execution-context.js +1 -1
- package/dist/utils/fs-walk.js +1 -1
- package/dist/utils/index.cjs +3 -3
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/path.js +1 -1
- package/dist/utils/redactor.cjs +18 -3
- package/dist/utils/redactor.d.ts +0 -7
- package/dist/utils/redactor.d.ts.map +1 -1
- package/dist/utils/redactor.js +19 -4
- package/dist/utils/result.js +1 -1
- package/dist/utils/safe-stringify.js +1 -1
- package/dist/utils/schema-metadata.js +1 -1
- package/dist/utils/schema.js +1 -1
- package/dist/utils/service-initializer.cjs +15 -37
- package/dist/utils/service-initializer.d.ts.map +1 -1
- package/dist/utils/service-initializer.js +16 -38
- package/dist/utils/user-info.js +1 -1
- package/dist/utils/zod-schema-converter.js +1 -1
- package/package.json +10 -8
- package/dist/context/compression/middle-removal.cjs +0 -95
- package/dist/context/compression/middle-removal.d.ts +0 -47
- package/dist/context/compression/middle-removal.d.ts.map +0 -1
- package/dist/context/compression/middle-removal.js +0 -72
- package/dist/context/compression/oldest-removal.cjs +0 -83
- package/dist/context/compression/oldest-removal.d.ts +0 -42
- package/dist/context/compression/oldest-removal.d.ts.map +0 -1
- package/dist/context/compression/oldest-removal.js +0 -60
- package/dist/context/compression/types.d.ts +0 -18
- package/dist/context/compression/types.d.ts.map +0 -1
- package/dist/llm/formatters/anthropic.cjs +0 -257
- package/dist/llm/formatters/anthropic.d.ts +0 -46
- package/dist/llm/formatters/anthropic.d.ts.map +0 -1
- package/dist/llm/formatters/anthropic.js +0 -239
- package/dist/llm/formatters/factory.cjs +0 -50
- package/dist/llm/formatters/factory.d.ts +0 -10
- package/dist/llm/formatters/factory.d.ts.map +0 -1
- package/dist/llm/formatters/factory.js +0 -27
- package/dist/llm/formatters/openai.cjs +0 -203
- package/dist/llm/formatters/openai.d.ts +0 -39
- package/dist/llm/formatters/openai.d.ts.map +0 -1
- package/dist/llm/formatters/openai.js +0 -184
- package/dist/llm/formatters/types.d.ts +0 -41
- package/dist/llm/formatters/types.d.ts.map +0 -1
- package/dist/llm/services/anthropic.cjs +0 -511
- package/dist/llm/services/anthropic.d.ts +0 -48
- package/dist/llm/services/anthropic.d.ts.map +0 -1
- package/dist/llm/services/anthropic.js +0 -447
- package/dist/llm/services/openai.cjs +0 -611
- package/dist/llm/services/openai.d.ts +0 -48
- package/dist/llm/services/openai.d.ts.map +0 -1
- package/dist/llm/services/openai.js +0 -547
- package/dist/llm/tokenizer/anthropic.d.ts +0 -19
- package/dist/llm/tokenizer/anthropic.d.ts.map +0 -1
- package/dist/llm/tokenizer/anthropic.js +0 -20
- package/dist/llm/tokenizer/default.d.ts +0 -14
- package/dist/llm/tokenizer/default.d.ts.map +0 -1
- package/dist/llm/tokenizer/default.js +0 -18
- package/dist/llm/tokenizer/factory.d.ts +0 -12
- package/dist/llm/tokenizer/factory.d.ts.map +0 -1
- package/dist/llm/tokenizer/factory.js +0 -21
- package/dist/llm/tokenizer/google.d.ts +0 -29
- package/dist/llm/tokenizer/google.d.ts.map +0 -1
- package/dist/llm/tokenizer/google.js +0 -29
- package/dist/llm/tokenizer/openai.cjs +0 -115
- package/dist/llm/tokenizer/openai.d.ts +0 -41
- package/dist/llm/tokenizer/openai.d.ts.map +0 -1
- package/dist/llm/tokenizer/openai.js +0 -91
- package/dist/llm/tokenizer/types.d.ts +0 -18
- package/dist/llm/tokenizer/types.d.ts.map +0 -1
- package/dist/llm/tokenizer/types.js +0 -10
- package/dist/tools/internal-tools/implementations/bash-exec-tool.cjs +0 -106
- package/dist/tools/internal-tools/implementations/bash-exec-tool.d.ts +0 -13
- package/dist/tools/internal-tools/implementations/bash-exec-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/bash-exec-tool.js +0 -73
- package/dist/tools/internal-tools/implementations/bash-output-tool.cjs +0 -49
- package/dist/tools/internal-tools/implementations/bash-output-tool.d.ts +0 -12
- package/dist/tools/internal-tools/implementations/bash-output-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/bash-output-tool.js +0 -26
- package/dist/tools/internal-tools/implementations/edit-file-tool.cjs +0 -62
- package/dist/tools/internal-tools/implementations/edit-file-tool.d.ts +0 -12
- package/dist/tools/internal-tools/implementations/edit-file-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/edit-file-tool.js +0 -39
- package/dist/tools/internal-tools/implementations/glob-files-tool.cjs +0 -57
- package/dist/tools/internal-tools/implementations/glob-files-tool.d.ts +0 -12
- package/dist/tools/internal-tools/implementations/glob-files-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/glob-files-tool.js +0 -34
- package/dist/tools/internal-tools/implementations/grep-content-tool.cjs +0 -71
- package/dist/tools/internal-tools/implementations/grep-content-tool.d.ts +0 -12
- package/dist/tools/internal-tools/implementations/grep-content-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/grep-content-tool.js +0 -48
- package/dist/tools/internal-tools/implementations/kill-process-tool.cjs +0 -47
- package/dist/tools/internal-tools/implementations/kill-process-tool.d.ts +0 -12
- package/dist/tools/internal-tools/implementations/kill-process-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/kill-process-tool.js +0 -24
- package/dist/tools/internal-tools/implementations/read-file-tool.cjs +0 -55
- package/dist/tools/internal-tools/implementations/read-file-tool.d.ts +0 -12
- package/dist/tools/internal-tools/implementations/read-file-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/read-file-tool.js +0 -32
- package/dist/tools/internal-tools/implementations/write-file-tool.cjs +0 -56
- package/dist/tools/internal-tools/implementations/write-file-tool.d.ts +0 -12
- package/dist/tools/internal-tools/implementations/write-file-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/write-file-tool.js +0 -33
- package/dist/utils/env-file.cjs +0 -118
- package/dist/utils/env-file.d.ts +0 -5
- package/dist/utils/env-file.d.ts.map +0 -1
- package/dist/utils/env-file.js +0 -85
- /package/dist/context/{compression/types.js → compaction/provider.js} +0 -0
- /package/dist/context/{compression → compaction}/types.cjs +0 -0
- /package/dist/{llm/formatters → context/compaction}/types.js +0 -0
- /package/dist/{llm/formatters → image}/types.cjs +0 -0
|
@@ -66,6 +66,8 @@ __export(DextoAgent_exports, {
|
|
|
66
66
|
DextoAgent: () => DextoAgent
|
|
67
67
|
});
|
|
68
68
|
module.exports = __toCommonJS(DextoAgent_exports);
|
|
69
|
+
var import_crypto = require("crypto");
|
|
70
|
+
var import_events = require("events");
|
|
69
71
|
var import_resources = require("../resources/index.js");
|
|
70
72
|
var import_utils = require("../context/utils.js");
|
|
71
73
|
var import_prompts = require("../prompts/index.js");
|
|
@@ -81,13 +83,14 @@ var import_errors = require("../llm/errors.js");
|
|
|
81
83
|
var import_errors2 = require("./errors.js");
|
|
82
84
|
var import_errors3 = require("../mcp/errors.js");
|
|
83
85
|
var import_DextoRuntimeError = require("../errors/DextoRuntimeError.js");
|
|
86
|
+
var import_DextoValidationError = require("../errors/DextoValidationError.js");
|
|
84
87
|
var import_result_bridge = require("../errors/result-bridge.cjs");
|
|
85
88
|
var import_result = require("../utils/result.cjs");
|
|
86
89
|
var import_resolver2 = require("../mcp/resolver.js");
|
|
87
90
|
var import_registry = require("../llm/registry.js");
|
|
88
91
|
var import_service_initializer2 = require("../utils/service-initializer.js");
|
|
89
92
|
var import_schemas2 = require("./schemas.js");
|
|
90
|
-
var
|
|
93
|
+
var import_events2 = require("../events/index.js");
|
|
91
94
|
var import_safe_stringify = require("../utils/safe-stringify.cjs");
|
|
92
95
|
var import_title_generator = require("../session/title-generator.js");
|
|
93
96
|
var _DextoAgent_decorators, _init;
|
|
@@ -118,16 +121,20 @@ class DextoAgent {
|
|
|
118
121
|
*
|
|
119
122
|
* @param config - Agent configuration (validated and enriched)
|
|
120
123
|
* @param configPath - Optional path to config file (for relative path resolution)
|
|
124
|
+
* @param options - Validation options
|
|
125
|
+
* @param options.strict - When true (default), enforces API key and baseURL requirements.
|
|
126
|
+
* When false, allows missing credentials for interactive configuration.
|
|
121
127
|
*/
|
|
122
|
-
constructor(config, configPath) {
|
|
128
|
+
constructor(config, configPath, options) {
|
|
123
129
|
this.configPath = configPath;
|
|
124
|
-
|
|
130
|
+
const schema = options?.strict === false ? (0, import_schemas2.createAgentConfigSchema)({ strict: false }) : import_schemas2.AgentConfigSchema;
|
|
131
|
+
this.config = schema.parse(config);
|
|
125
132
|
this.logger = (0, import_factory.createLogger)({
|
|
126
133
|
config: this.config.logger,
|
|
127
134
|
agentId: this.config.agentId,
|
|
128
135
|
component: import_types.DextoLogComponent.AGENT
|
|
129
136
|
});
|
|
130
|
-
this.agentEventBus = new
|
|
137
|
+
this.agentEventBus = new import_events2.AgentEventBus();
|
|
131
138
|
this.logger.info("DextoAgent created.");
|
|
132
139
|
}
|
|
133
140
|
/**
|
|
@@ -159,6 +166,8 @@ class DextoAgent {
|
|
|
159
166
|
// Approval handler for manual tool confirmation and elicitation
|
|
160
167
|
// Set via setApprovalHandler() before start() if needed
|
|
161
168
|
approvalHandler;
|
|
169
|
+
// Active stream controllers per session - allows cancel() to abort iterators
|
|
170
|
+
activeStreamControllers = /* @__PURE__ */ new Map();
|
|
162
171
|
// Logger instance for this agent (dependency injection)
|
|
163
172
|
logger;
|
|
164
173
|
/**
|
|
@@ -217,6 +226,8 @@ Either:
|
|
|
217
226
|
memoryManager: services.memoryManager,
|
|
218
227
|
services
|
|
219
228
|
});
|
|
229
|
+
services.toolManager.setAgent(this);
|
|
230
|
+
await services.toolManager.initialize();
|
|
220
231
|
this.searchService = services.searchService;
|
|
221
232
|
const promptManager = new import_prompts.PromptManager(
|
|
222
233
|
this.mcpManager,
|
|
@@ -234,10 +245,6 @@ Either:
|
|
|
234
245
|
for (const subscriber of this.eventSubscribers) {
|
|
235
246
|
subscriber.subscribe(this.agentEventBus);
|
|
236
247
|
}
|
|
237
|
-
const fileTransport = this.config.logger?.transports?.find((t) => t.type === "file");
|
|
238
|
-
if (fileTransport && "path" in fileTransport) {
|
|
239
|
-
console.log(`\u{1F4CB} Logs available at: ${fileTransport.path}`);
|
|
240
|
-
}
|
|
241
248
|
} catch (error) {
|
|
242
249
|
this.logger.error("Failed to start DextoAgent", {
|
|
243
250
|
error: error instanceof Error ? error.message : String(error)
|
|
@@ -368,173 +375,88 @@ Either:
|
|
|
368
375
|
}
|
|
369
376
|
// ============= CORE AGENT FUNCTIONALITY =============
|
|
370
377
|
/**
|
|
371
|
-
*
|
|
372
|
-
*
|
|
378
|
+
* Process user input and return the response.
|
|
379
|
+
*
|
|
380
|
+
* @deprecated Use generate() or stream() instead for multi-image support.
|
|
381
|
+
* This method is kept for backward compatibility and only supports single image/file.
|
|
373
382
|
*
|
|
374
|
-
* @param textInput - The user's text message
|
|
375
|
-
* @param imageDataInput - Optional image data
|
|
376
|
-
* @param fileDataInput - Optional file data
|
|
383
|
+
* @param textInput - The user's text message
|
|
384
|
+
* @param imageDataInput - Optional single image data
|
|
385
|
+
* @param fileDataInput - Optional single file data
|
|
377
386
|
* @param sessionId - Session ID for the conversation (required)
|
|
378
|
-
* @param
|
|
379
|
-
* @returns Promise that resolves to the AI's response text
|
|
380
|
-
* @throws Error if processing fails
|
|
387
|
+
* @param _stream - Ignored (streaming is handled internally)
|
|
388
|
+
* @returns Promise that resolves to the AI's response text
|
|
381
389
|
*/
|
|
382
|
-
async run(textInput, imageDataInput, fileDataInput, sessionId,
|
|
383
|
-
|
|
384
|
-
if (
|
|
385
|
-
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
}
|
|
393
|
-
const existingBaggage = import_api.propagation.getBaggage(activeContext);
|
|
394
|
-
const baggageEntries = {};
|
|
395
|
-
if (existingBaggage) {
|
|
396
|
-
existingBaggage.getAllEntries().forEach(([key, entry]) => {
|
|
397
|
-
baggageEntries[key] = { ...entry };
|
|
390
|
+
async run(textInput, imageDataInput, fileDataInput, sessionId, _stream = false) {
|
|
391
|
+
const parts = [];
|
|
392
|
+
if (textInput) {
|
|
393
|
+
parts.push({ type: "text", text: textInput });
|
|
394
|
+
}
|
|
395
|
+
if (imageDataInput) {
|
|
396
|
+
parts.push({
|
|
397
|
+
type: "image",
|
|
398
|
+
image: imageDataInput.image,
|
|
399
|
+
mimeType: imageDataInput.mimeType
|
|
398
400
|
});
|
|
399
401
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
);
|
|
411
|
-
return await import_api.context.with(updatedContext, async () => {
|
|
412
|
-
try {
|
|
413
|
-
const llmConfig = this.stateManager.getLLMConfig(targetSessionId);
|
|
414
|
-
const validation = (0, import_validation.validateInputForLLM)(
|
|
415
|
-
{
|
|
416
|
-
text: textInput,
|
|
417
|
-
...imageDataInput && { imageData: imageDataInput },
|
|
418
|
-
...fileDataInput && { fileData: fileDataInput }
|
|
419
|
-
},
|
|
420
|
-
{
|
|
421
|
-
provider: llmConfig.provider,
|
|
422
|
-
model: llmConfig.model
|
|
423
|
-
},
|
|
424
|
-
this.logger
|
|
425
|
-
);
|
|
426
|
-
(0, import_result_bridge.ensureOk)(validation, this.logger);
|
|
427
|
-
const session = await this.sessionManager.getSession(targetSessionId) || await this.sessionManager.createSession(targetSessionId);
|
|
428
|
-
this.logger.debug(
|
|
429
|
-
`DextoAgent.run: sessionId=${targetSessionId}, textLength=${textInput?.length ?? 0}, hasImage=${Boolean(
|
|
430
|
-
imageDataInput
|
|
431
|
-
)}, hasFile=${Boolean(fileDataInput)}`
|
|
432
|
-
);
|
|
433
|
-
let finalText = textInput;
|
|
434
|
-
let finalImageData = imageDataInput;
|
|
435
|
-
if (textInput && textInput.includes("@")) {
|
|
436
|
-
try {
|
|
437
|
-
const resources = await this.resourceManager.list();
|
|
438
|
-
const expansion = await (0, import_resources.expandMessageReferences)(
|
|
439
|
-
textInput,
|
|
440
|
-
resources,
|
|
441
|
-
(uri) => this.resourceManager.read(uri)
|
|
442
|
-
);
|
|
443
|
-
if (expansion.unresolvedReferences.length > 0) {
|
|
444
|
-
const unresolvedNames = expansion.unresolvedReferences.map((ref) => ref.originalRef).join(", ");
|
|
445
|
-
this.logger.warn(
|
|
446
|
-
`Could not resolve ${expansion.unresolvedReferences.length} resource reference(s): ${unresolvedNames}`
|
|
447
|
-
);
|
|
448
|
-
}
|
|
449
|
-
const MAX_EXPANDED_SIZE = 5 * 1024 * 1024;
|
|
450
|
-
const expandedSize = Buffer.byteLength(expansion.expandedMessage, "utf-8");
|
|
451
|
-
if (expandedSize > MAX_EXPANDED_SIZE) {
|
|
452
|
-
this.logger.warn(
|
|
453
|
-
`Expanded message size (${(expandedSize / 1024 / 1024).toFixed(2)}MB) exceeds limit (${MAX_EXPANDED_SIZE / 1024 / 1024}MB). Content may be truncated.`
|
|
454
|
-
);
|
|
455
|
-
}
|
|
456
|
-
finalText = expansion.expandedMessage;
|
|
457
|
-
if (expansion.extractedImages.length > 0 && !imageDataInput) {
|
|
458
|
-
const firstImage = expansion.extractedImages[0];
|
|
459
|
-
if (firstImage) {
|
|
460
|
-
finalImageData = {
|
|
461
|
-
image: firstImage.image,
|
|
462
|
-
mimeType: firstImage.mimeType
|
|
463
|
-
};
|
|
464
|
-
this.logger.debug(
|
|
465
|
-
`Using extracted image: ${firstImage.name} (${firstImage.mimeType})`
|
|
466
|
-
);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
} catch (error) {
|
|
470
|
-
this.logger.error(
|
|
471
|
-
`Failed to expand resource references: ${error instanceof Error ? error.message : String(error)}. Continuing with original message.`
|
|
472
|
-
);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
if (!finalText.trim() && !finalImageData && !fileDataInput) {
|
|
476
|
-
this.logger.warn(
|
|
477
|
-
"Resource expansion resulted in empty content. Using original message."
|
|
478
|
-
);
|
|
479
|
-
finalText = textInput;
|
|
480
|
-
}
|
|
481
|
-
const response = await session.run(
|
|
482
|
-
finalText,
|
|
483
|
-
finalImageData,
|
|
484
|
-
fileDataInput,
|
|
485
|
-
stream
|
|
486
|
-
);
|
|
487
|
-
this.sessionManager.incrementMessageCount(session.id).catch(
|
|
488
|
-
(error) => this.logger.warn(
|
|
489
|
-
`Failed to increment message count: ${error instanceof Error ? error.message : String(error)}`
|
|
490
|
-
)
|
|
491
|
-
);
|
|
492
|
-
return response;
|
|
493
|
-
} catch (error) {
|
|
494
|
-
this.logger.error(
|
|
495
|
-
`Error during DextoAgent.run: ${error instanceof Error ? error.message : JSON.stringify(error)}`
|
|
496
|
-
);
|
|
497
|
-
throw error;
|
|
498
|
-
}
|
|
499
|
-
});
|
|
402
|
+
if (fileDataInput) {
|
|
403
|
+
parts.push({
|
|
404
|
+
type: "file",
|
|
405
|
+
data: fileDataInput.data,
|
|
406
|
+
mimeType: fileDataInput.mimeType,
|
|
407
|
+
...fileDataInput.filename && { filename: fileDataInput.filename }
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
const response = await this.generate(parts.length > 0 ? parts : textInput, sessionId);
|
|
411
|
+
return response.content;
|
|
500
412
|
}
|
|
501
413
|
/**
|
|
502
414
|
* Generate a complete response (waits for full completion).
|
|
503
415
|
* This is the recommended method for non-streaming use cases.
|
|
504
416
|
*
|
|
505
|
-
* @param message
|
|
506
|
-
* @param
|
|
417
|
+
* @param content String message or array of content parts (text, images, files)
|
|
418
|
+
* @param sessionId Session ID for the conversation
|
|
419
|
+
* @param options Optional configuration (signal for cancellation)
|
|
507
420
|
* @returns Promise that resolves to the complete response
|
|
508
421
|
*
|
|
509
422
|
* @example
|
|
510
423
|
* ```typescript
|
|
511
|
-
*
|
|
424
|
+
* // Simple text message
|
|
425
|
+
* const response = await agent.generate('What is 2+2?', 'session-1');
|
|
512
426
|
* console.log(response.content); // "4"
|
|
513
|
-
*
|
|
427
|
+
*
|
|
428
|
+
* // Multimodal with image
|
|
429
|
+
* const response = await agent.generate(
|
|
430
|
+
* [
|
|
431
|
+
* { type: 'text', text: 'Describe this image' },
|
|
432
|
+
* { type: 'image', image: base64Data, mimeType: 'image/png' }
|
|
433
|
+
* ],
|
|
434
|
+
* 'session-1'
|
|
435
|
+
* );
|
|
514
436
|
* ```
|
|
515
437
|
*/
|
|
516
|
-
async generate(
|
|
438
|
+
async generate(content, sessionId, options) {
|
|
517
439
|
const events = [];
|
|
518
|
-
for await (const event of await this.stream(
|
|
440
|
+
for await (const event of await this.stream(content, sessionId, options)) {
|
|
519
441
|
events.push(event);
|
|
520
442
|
}
|
|
521
|
-
const
|
|
522
|
-
(e) => e.name === "llm:error"
|
|
443
|
+
const fatalErrorEvent = events.find(
|
|
444
|
+
(e) => e.name === "llm:error" && e.recoverable !== true
|
|
523
445
|
);
|
|
524
|
-
if (
|
|
525
|
-
if (
|
|
526
|
-
throw
|
|
446
|
+
if (fatalErrorEvent) {
|
|
447
|
+
if (fatalErrorEvent.error instanceof import_DextoRuntimeError.DextoRuntimeError || fatalErrorEvent.error instanceof import_DextoValidationError.DextoValidationError) {
|
|
448
|
+
throw fatalErrorEvent.error;
|
|
527
449
|
}
|
|
528
|
-
const llmConfig = this.stateManager.getLLMConfig(
|
|
450
|
+
const llmConfig = this.stateManager.getLLMConfig(sessionId);
|
|
529
451
|
throw import_errors.LLMError.generationFailed(
|
|
530
|
-
|
|
452
|
+
fatalErrorEvent.error.message,
|
|
531
453
|
llmConfig.provider,
|
|
532
454
|
llmConfig.model
|
|
533
455
|
);
|
|
534
456
|
}
|
|
535
457
|
const responseEvent = events.find((e) => e.name === "llm:response");
|
|
536
458
|
if (!responseEvent || responseEvent.name !== "llm:response") {
|
|
537
|
-
const llmConfig = this.stateManager.getLLMConfig(
|
|
459
|
+
const llmConfig = this.stateManager.getLLMConfig(sessionId);
|
|
538
460
|
throw import_errors.LLMError.generationFailed(
|
|
539
461
|
"Stream did not complete successfully - no response received",
|
|
540
462
|
llmConfig.provider,
|
|
@@ -570,7 +492,7 @@ Either:
|
|
|
570
492
|
reasoning: responseEvent.reasoning,
|
|
571
493
|
usage,
|
|
572
494
|
toolCalls,
|
|
573
|
-
sessionId
|
|
495
|
+
sessionId
|
|
574
496
|
};
|
|
575
497
|
}
|
|
576
498
|
/**
|
|
@@ -584,36 +506,38 @@ Either:
|
|
|
584
506
|
* Events are forwarded directly from the AgentEventBus with no mapping layer,
|
|
585
507
|
* providing a unified event system across all API layers.
|
|
586
508
|
*
|
|
587
|
-
* @param message
|
|
588
|
-
* @param
|
|
509
|
+
* @param content String message or array of content parts (text, images, files)
|
|
510
|
+
* @param sessionId Session ID for the conversation
|
|
511
|
+
* @param options Optional configuration (signal for cancellation)
|
|
589
512
|
* @returns AsyncIterator that yields StreamingEvent objects (core events with name property)
|
|
590
513
|
*
|
|
591
514
|
* @example
|
|
592
515
|
* ```typescript
|
|
593
|
-
*
|
|
594
|
-
*
|
|
595
|
-
*
|
|
596
|
-
* }
|
|
597
|
-
* if (event.name === 'llm:tool-call') {
|
|
598
|
-
* console.log(`\n[Using ${event.toolName}]\n`);
|
|
599
|
-
* }
|
|
516
|
+
* // Simple text
|
|
517
|
+
* for await (const event of await agent.stream('Write a poem', 'session-1')) {
|
|
518
|
+
* if (event.name === 'llm:chunk') process.stdout.write(event.content);
|
|
600
519
|
* }
|
|
520
|
+
*
|
|
521
|
+
* // Multimodal
|
|
522
|
+
* for await (const event of await agent.stream(
|
|
523
|
+
* [{ type: 'text', text: 'Describe this' }, { type: 'image', image: data, mimeType: 'image/png' }],
|
|
524
|
+
* 'session-1'
|
|
525
|
+
* )) { ... }
|
|
601
526
|
* ```
|
|
602
527
|
*/
|
|
603
|
-
async stream(
|
|
528
|
+
async stream(content, sessionId, options) {
|
|
604
529
|
this.ensureStarted();
|
|
605
|
-
if (!
|
|
606
|
-
throw
|
|
530
|
+
if (!sessionId) {
|
|
531
|
+
throw import_errors2.AgentError.apiValidationError("sessionId is required");
|
|
607
532
|
}
|
|
608
|
-
const
|
|
609
|
-
|
|
610
|
-
const fileData = options.fileData;
|
|
611
|
-
const signal = options.signal;
|
|
533
|
+
const signal = options?.signal;
|
|
534
|
+
let contentParts = typeof content === "string" ? [{ type: "text", text: content }] : [...content];
|
|
612
535
|
const eventQueue = [];
|
|
613
536
|
let completed = false;
|
|
614
|
-
let _streamError = null;
|
|
615
537
|
const controller = new AbortController();
|
|
616
538
|
const cleanupSignal = controller.signal;
|
|
539
|
+
this.activeStreamControllers.set(sessionId, controller);
|
|
540
|
+
(0, import_events.setMaxListeners)(30, cleanupSignal);
|
|
617
541
|
const listeners = [];
|
|
618
542
|
const cleanupListeners = () => {
|
|
619
543
|
if (listeners.length === 0) {
|
|
@@ -626,6 +550,7 @@ Either:
|
|
|
626
550
|
);
|
|
627
551
|
}
|
|
628
552
|
listeners.length = 0;
|
|
553
|
+
this.activeStreamControllers.delete(sessionId);
|
|
629
554
|
};
|
|
630
555
|
if (signal) {
|
|
631
556
|
const abortHandler = () => {
|
|
@@ -649,7 +574,6 @@ Either:
|
|
|
649
574
|
const responseListener = (data) => {
|
|
650
575
|
if (data.sessionId !== sessionId) return;
|
|
651
576
|
eventQueue.push({ name: "llm:response", ...data });
|
|
652
|
-
completed = true;
|
|
653
577
|
};
|
|
654
578
|
this.agentEventBus.on("llm:response", responseListener, { signal: cleanupSignal });
|
|
655
579
|
listeners.push({ event: "llm:response", listener: responseListener });
|
|
@@ -706,34 +630,191 @@ Either:
|
|
|
706
630
|
signal: cleanupSignal
|
|
707
631
|
});
|
|
708
632
|
listeners.push({ event: "approval:response", listener: approvalResponseListener });
|
|
709
|
-
const
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
633
|
+
const toolRunningListener = (data) => {
|
|
634
|
+
if (data.sessionId !== sessionId) return;
|
|
635
|
+
eventQueue.push({ name: "tool:running", ...data });
|
|
636
|
+
};
|
|
637
|
+
this.agentEventBus.on("tool:running", toolRunningListener, {
|
|
638
|
+
signal: cleanupSignal
|
|
639
|
+
});
|
|
640
|
+
listeners.push({ event: "tool:running", listener: toolRunningListener });
|
|
641
|
+
const messageQueuedListener = (data) => {
|
|
642
|
+
if (data.sessionId !== sessionId) return;
|
|
643
|
+
eventQueue.push({ name: "message:queued", ...data });
|
|
644
|
+
};
|
|
645
|
+
this.agentEventBus.on("message:queued", messageQueuedListener, {
|
|
646
|
+
signal: cleanupSignal
|
|
647
|
+
});
|
|
648
|
+
listeners.push({ event: "message:queued", listener: messageQueuedListener });
|
|
649
|
+
const messageDequeuedListener = (data) => {
|
|
650
|
+
if (data.sessionId !== sessionId) return;
|
|
651
|
+
eventQueue.push({ name: "message:dequeued", ...data });
|
|
652
|
+
};
|
|
653
|
+
this.agentEventBus.on("message:dequeued", messageDequeuedListener, {
|
|
654
|
+
signal: cleanupSignal
|
|
655
|
+
});
|
|
656
|
+
listeners.push({ event: "message:dequeued", listener: messageDequeuedListener });
|
|
657
|
+
const runCompleteListener = (data) => {
|
|
658
|
+
if (data.sessionId !== sessionId) return;
|
|
659
|
+
eventQueue.push({ name: "run:complete", ...data });
|
|
721
660
|
completed = true;
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
error,
|
|
726
|
-
recoverable: false,
|
|
727
|
-
context: "run_failed",
|
|
728
|
-
sessionId
|
|
729
|
-
};
|
|
730
|
-
eventQueue.push(errorEvent);
|
|
661
|
+
};
|
|
662
|
+
this.agentEventBus.on("run:complete", runCompleteListener, {
|
|
663
|
+
signal: cleanupSignal
|
|
731
664
|
});
|
|
665
|
+
listeners.push({ event: "run:complete", listener: runCompleteListener });
|
|
666
|
+
(async () => {
|
|
667
|
+
const activeContext = import_api.context.active();
|
|
668
|
+
const activeSpan = import_api.trace.getActiveSpan();
|
|
669
|
+
if (activeSpan) {
|
|
670
|
+
activeSpan.setAttribute("sessionId", sessionId);
|
|
671
|
+
}
|
|
672
|
+
const existingBaggage = import_api.propagation.getBaggage(activeContext);
|
|
673
|
+
const baggageEntries = {};
|
|
674
|
+
if (existingBaggage) {
|
|
675
|
+
existingBaggage.getAllEntries().forEach(([key, entry]) => {
|
|
676
|
+
baggageEntries[key] = { ...entry };
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
baggageEntries.sessionId = { ...baggageEntries.sessionId, value: sessionId };
|
|
680
|
+
const updatedContext = import_api.propagation.setBaggage(
|
|
681
|
+
activeContext,
|
|
682
|
+
import_api.propagation.createBaggage(baggageEntries)
|
|
683
|
+
);
|
|
684
|
+
await import_api.context.with(updatedContext, async () => {
|
|
685
|
+
try {
|
|
686
|
+
const llmConfig = this.stateManager.getLLMConfig(sessionId);
|
|
687
|
+
const textParts = contentParts.filter(
|
|
688
|
+
(p) => p.type === "text"
|
|
689
|
+
);
|
|
690
|
+
const textContent = textParts.map((p) => p.text).join("\n");
|
|
691
|
+
const imageParts = contentParts.filter(
|
|
692
|
+
(p) => p.type === "image"
|
|
693
|
+
);
|
|
694
|
+
const fileParts = contentParts.filter(
|
|
695
|
+
(p) => p.type === "file"
|
|
696
|
+
);
|
|
697
|
+
this.logger.debug(
|
|
698
|
+
`DextoAgent.stream: sessionId=${sessionId}, textLength=${textContent?.length ?? 0}, imageCount=${imageParts.length}, fileCount=${fileParts.length}`
|
|
699
|
+
);
|
|
700
|
+
const textValidation = (0, import_validation.validateInputForLLM)(
|
|
701
|
+
{ text: textContent },
|
|
702
|
+
{ provider: llmConfig.provider, model: llmConfig.model },
|
|
703
|
+
this.logger
|
|
704
|
+
);
|
|
705
|
+
(0, import_result_bridge.ensureOk)(textValidation, this.logger);
|
|
706
|
+
for (const imagePart of imageParts) {
|
|
707
|
+
const imageValidation = (0, import_validation.validateInputForLLM)(
|
|
708
|
+
{
|
|
709
|
+
imageData: {
|
|
710
|
+
image: typeof imagePart.image === "string" ? imagePart.image : imagePart.image.toString(),
|
|
711
|
+
mimeType: imagePart.mimeType || "image/png"
|
|
712
|
+
}
|
|
713
|
+
},
|
|
714
|
+
{ provider: llmConfig.provider, model: llmConfig.model },
|
|
715
|
+
this.logger
|
|
716
|
+
);
|
|
717
|
+
(0, import_result_bridge.ensureOk)(imageValidation, this.logger);
|
|
718
|
+
}
|
|
719
|
+
for (const filePart of fileParts) {
|
|
720
|
+
const fileValidation = (0, import_validation.validateInputForLLM)(
|
|
721
|
+
{
|
|
722
|
+
fileData: {
|
|
723
|
+
data: typeof filePart.data === "string" ? filePart.data : filePart.data.toString(),
|
|
724
|
+
mimeType: filePart.mimeType
|
|
725
|
+
}
|
|
726
|
+
},
|
|
727
|
+
{ provider: llmConfig.provider, model: llmConfig.model },
|
|
728
|
+
this.logger
|
|
729
|
+
);
|
|
730
|
+
(0, import_result_bridge.ensureOk)(fileValidation, this.logger);
|
|
731
|
+
}
|
|
732
|
+
if (textContent.includes("@")) {
|
|
733
|
+
try {
|
|
734
|
+
const resources = await this.resourceManager.list();
|
|
735
|
+
const expansion = await (0, import_resources.expandMessageReferences)(
|
|
736
|
+
textContent,
|
|
737
|
+
resources,
|
|
738
|
+
(uri) => this.resourceManager.read(uri)
|
|
739
|
+
);
|
|
740
|
+
if (expansion.unresolvedReferences.length > 0) {
|
|
741
|
+
const unresolvedNames = expansion.unresolvedReferences.map((ref) => ref.originalRef).join(", ");
|
|
742
|
+
this.logger.warn(
|
|
743
|
+
`Could not resolve ${expansion.unresolvedReferences.length} resource reference(s): ${unresolvedNames}`
|
|
744
|
+
);
|
|
745
|
+
}
|
|
746
|
+
const MAX_EXPANDED_SIZE = 5 * 1024 * 1024;
|
|
747
|
+
const expandedSize = Buffer.byteLength(
|
|
748
|
+
expansion.expandedMessage,
|
|
749
|
+
"utf-8"
|
|
750
|
+
);
|
|
751
|
+
if (expandedSize > MAX_EXPANDED_SIZE) {
|
|
752
|
+
this.logger.warn(
|
|
753
|
+
`Expanded message size (${(expandedSize / 1024 / 1024).toFixed(2)}MB) exceeds limit (${MAX_EXPANDED_SIZE / 1024 / 1024}MB). Content may be truncated.`
|
|
754
|
+
);
|
|
755
|
+
}
|
|
756
|
+
contentParts = contentParts.filter((p) => p.type !== "text");
|
|
757
|
+
if (expansion.expandedMessage.trim()) {
|
|
758
|
+
contentParts.unshift({
|
|
759
|
+
type: "text",
|
|
760
|
+
text: expansion.expandedMessage
|
|
761
|
+
});
|
|
762
|
+
}
|
|
763
|
+
for (const img of expansion.extractedImages) {
|
|
764
|
+
contentParts.push({
|
|
765
|
+
type: "image",
|
|
766
|
+
image: img.image,
|
|
767
|
+
mimeType: img.mimeType
|
|
768
|
+
});
|
|
769
|
+
this.logger.debug(
|
|
770
|
+
`Added extracted image: ${img.name} (${img.mimeType})`
|
|
771
|
+
);
|
|
772
|
+
}
|
|
773
|
+
} catch (error) {
|
|
774
|
+
this.logger.error(
|
|
775
|
+
`Failed to expand resource references: ${error instanceof Error ? error.message : String(error)}. Continuing with original message.`
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
const hasTextContent = contentParts.some(
|
|
780
|
+
(p) => p.type === "text" && p.text.trim()
|
|
781
|
+
);
|
|
782
|
+
const hasMediaContent = contentParts.some(
|
|
783
|
+
(p) => p.type === "image" || p.type === "file"
|
|
784
|
+
);
|
|
785
|
+
if (!hasTextContent && !hasMediaContent) {
|
|
786
|
+
this.logger.warn(
|
|
787
|
+
"Resource expansion resulted in empty content. Using original message."
|
|
788
|
+
);
|
|
789
|
+
contentParts = [{ type: "text", text: textContent }];
|
|
790
|
+
}
|
|
791
|
+
const session = await this.sessionManager.getSession(sessionId) || await this.sessionManager.createSession(sessionId);
|
|
792
|
+
await session.stream(contentParts, signal ? { signal } : void 0);
|
|
793
|
+
this.sessionManager.incrementMessageCount(session.id).catch(
|
|
794
|
+
(error) => this.logger.warn(
|
|
795
|
+
`Failed to increment message count: ${error instanceof Error ? error.message : String(error)}`
|
|
796
|
+
)
|
|
797
|
+
);
|
|
798
|
+
} catch (err) {
|
|
799
|
+
const error = err instanceof import_DextoRuntimeError.DextoRuntimeError || err instanceof import_DextoValidationError.DextoValidationError ? err : err instanceof Error ? err : import_errors2.AgentError.streamFailed(String(err));
|
|
800
|
+
completed = true;
|
|
801
|
+
this.logger.error(`Error in DextoAgent.stream: ${error.message}`);
|
|
802
|
+
const errorEvent = {
|
|
803
|
+
name: "llm:error",
|
|
804
|
+
error,
|
|
805
|
+
recoverable: false,
|
|
806
|
+
context: "run_failed",
|
|
807
|
+
sessionId
|
|
808
|
+
};
|
|
809
|
+
eventQueue.push(errorEvent);
|
|
810
|
+
}
|
|
811
|
+
});
|
|
812
|
+
})();
|
|
732
813
|
const iterator = {
|
|
733
814
|
async next() {
|
|
734
815
|
while (!completed && eventQueue.length === 0) {
|
|
735
816
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
736
|
-
if (signal?.aborted) {
|
|
817
|
+
if (signal?.aborted || cleanupSignal.aborted) {
|
|
737
818
|
cleanupListeners();
|
|
738
819
|
controller.abort();
|
|
739
820
|
return { done: true, value: void 0 };
|
|
@@ -761,6 +842,73 @@ Either:
|
|
|
761
842
|
};
|
|
762
843
|
return iterator;
|
|
763
844
|
}
|
|
845
|
+
/**
|
|
846
|
+
* Check if a session is currently processing a message.
|
|
847
|
+
* @param sessionId Session id
|
|
848
|
+
* @returns true if the session is busy processing; false otherwise
|
|
849
|
+
*/
|
|
850
|
+
async isSessionBusy(sessionId) {
|
|
851
|
+
this.ensureStarted();
|
|
852
|
+
const session = await this.sessionManager.getSession(sessionId, false);
|
|
853
|
+
return session?.isBusy() ?? false;
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Queue a message for processing when a session is busy.
|
|
857
|
+
* The message will be injected into the conversation when the current turn completes.
|
|
858
|
+
*
|
|
859
|
+
* @param sessionId Session id
|
|
860
|
+
* @param message The user message to queue
|
|
861
|
+
* @returns Queue position and message ID
|
|
862
|
+
* @throws Error if session doesn't support message queueing
|
|
863
|
+
*/
|
|
864
|
+
async queueMessage(sessionId, message) {
|
|
865
|
+
this.ensureStarted();
|
|
866
|
+
const session = await this.sessionManager.getSession(sessionId, false);
|
|
867
|
+
if (!session) {
|
|
868
|
+
throw import_session.SessionError.notFound(sessionId);
|
|
869
|
+
}
|
|
870
|
+
return session.queueMessage(message);
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Get all queued messages for a session.
|
|
874
|
+
* @param sessionId Session id
|
|
875
|
+
* @returns Array of queued messages
|
|
876
|
+
*/
|
|
877
|
+
async getQueuedMessages(sessionId) {
|
|
878
|
+
this.ensureStarted();
|
|
879
|
+
const session = await this.sessionManager.getSession(sessionId, false);
|
|
880
|
+
if (!session) {
|
|
881
|
+
throw import_session.SessionError.notFound(sessionId);
|
|
882
|
+
}
|
|
883
|
+
return session.getQueuedMessages();
|
|
884
|
+
}
|
|
885
|
+
/**
|
|
886
|
+
* Remove a queued message.
|
|
887
|
+
* @param sessionId Session id
|
|
888
|
+
* @param messageId The ID of the queued message to remove
|
|
889
|
+
* @returns true if message was found and removed, false otherwise
|
|
890
|
+
*/
|
|
891
|
+
async removeQueuedMessage(sessionId, messageId) {
|
|
892
|
+
this.ensureStarted();
|
|
893
|
+
const session = await this.sessionManager.getSession(sessionId, false);
|
|
894
|
+
if (!session) {
|
|
895
|
+
throw import_session.SessionError.notFound(sessionId);
|
|
896
|
+
}
|
|
897
|
+
return session.removeQueuedMessage(messageId);
|
|
898
|
+
}
|
|
899
|
+
/**
|
|
900
|
+
* Clear all queued messages for a session.
|
|
901
|
+
* @param sessionId Session id
|
|
902
|
+
* @returns Number of messages that were cleared
|
|
903
|
+
*/
|
|
904
|
+
async clearMessageQueue(sessionId) {
|
|
905
|
+
this.ensureStarted();
|
|
906
|
+
const session = await this.sessionManager.getSession(sessionId, false);
|
|
907
|
+
if (!session) {
|
|
908
|
+
throw import_session.SessionError.notFound(sessionId);
|
|
909
|
+
}
|
|
910
|
+
return session.clearMessageQueue();
|
|
911
|
+
}
|
|
764
912
|
/**
|
|
765
913
|
* Cancels the currently running turn for a session.
|
|
766
914
|
* Safe to call even if no run is in progress.
|
|
@@ -770,13 +918,20 @@ Either:
|
|
|
770
918
|
async cancel(sessionId) {
|
|
771
919
|
this.ensureStarted();
|
|
772
920
|
if (!sessionId || typeof sessionId !== "string") {
|
|
773
|
-
throw
|
|
921
|
+
throw import_errors2.AgentError.apiValidationError(
|
|
922
|
+
"sessionId is required and must be a non-empty string"
|
|
923
|
+
);
|
|
924
|
+
}
|
|
925
|
+
const streamController = this.activeStreamControllers.get(sessionId);
|
|
926
|
+
if (streamController) {
|
|
927
|
+
streamController.abort();
|
|
928
|
+
this.activeStreamControllers.delete(sessionId);
|
|
774
929
|
}
|
|
775
930
|
const existing = await this.sessionManager.getSession(sessionId, false);
|
|
776
931
|
if (existing) {
|
|
777
932
|
return existing.cancel();
|
|
778
933
|
}
|
|
779
|
-
return
|
|
934
|
+
return !!streamController;
|
|
780
935
|
}
|
|
781
936
|
// ============= SESSION MANAGEMENT =============
|
|
782
937
|
/**
|
|
@@ -883,7 +1038,6 @@ Either:
|
|
|
883
1038
|
const llmConfig = this.getEffectiveConfig(sessionId).llm;
|
|
884
1039
|
const result = await (0, import_title_generator.generateSessionTitle)(
|
|
885
1040
|
llmConfig,
|
|
886
|
-
llmConfig.router,
|
|
887
1041
|
this.toolManager,
|
|
888
1042
|
this.systemPromptManager,
|
|
889
1043
|
this.resourceManager,
|
|
@@ -966,7 +1120,9 @@ Either:
|
|
|
966
1120
|
async resetConversation(sessionId) {
|
|
967
1121
|
this.ensureStarted();
|
|
968
1122
|
if (!sessionId || typeof sessionId !== "string") {
|
|
969
|
-
throw
|
|
1123
|
+
throw import_errors2.AgentError.apiValidationError(
|
|
1124
|
+
"sessionId is required and must be a non-empty string"
|
|
1125
|
+
);
|
|
970
1126
|
}
|
|
971
1127
|
try {
|
|
972
1128
|
await this.sessionManager.resetSession(sessionId);
|
|
@@ -981,6 +1137,37 @@ Either:
|
|
|
981
1137
|
throw error;
|
|
982
1138
|
}
|
|
983
1139
|
}
|
|
1140
|
+
/**
|
|
1141
|
+
* Clears the context window for a session without deleting history.
|
|
1142
|
+
*
|
|
1143
|
+
* This adds a "context clear" marker to the conversation history. When the
|
|
1144
|
+
* context is loaded for LLM, messages before this marker are filtered out
|
|
1145
|
+
* (via filterCompacted). The full history remains in the database for
|
|
1146
|
+
* review via /resume or session history.
|
|
1147
|
+
*
|
|
1148
|
+
* Use this for /clear command - it preserves history but gives a fresh
|
|
1149
|
+
* context window to the LLM.
|
|
1150
|
+
*
|
|
1151
|
+
* @param sessionId Session ID (required)
|
|
1152
|
+
*/
|
|
1153
|
+
async clearContext(sessionId) {
|
|
1154
|
+
this.ensureStarted();
|
|
1155
|
+
if (!sessionId || typeof sessionId !== "string") {
|
|
1156
|
+
throw import_errors2.AgentError.apiValidationError(
|
|
1157
|
+
"sessionId is required and must be a non-empty string"
|
|
1158
|
+
);
|
|
1159
|
+
}
|
|
1160
|
+
const session = await this.sessionManager.getSession(sessionId);
|
|
1161
|
+
if (!session) {
|
|
1162
|
+
throw import_session.SessionError.notFound(sessionId);
|
|
1163
|
+
}
|
|
1164
|
+
const contextManager = session.getContextManager();
|
|
1165
|
+
await contextManager.clearContext();
|
|
1166
|
+
this.logger.info(`Context cleared for session: ${sessionId}`);
|
|
1167
|
+
this.agentEventBus.emit("context:cleared", {
|
|
1168
|
+
sessionId
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
984
1171
|
// ============= LLM MANAGEMENT =============
|
|
985
1172
|
/**
|
|
986
1173
|
* Gets the current LLM configuration with all defaults applied.
|
|
@@ -995,7 +1182,7 @@ Either:
|
|
|
995
1182
|
* This is a comprehensive method that handles ALL validation, configuration building, and switching internally.
|
|
996
1183
|
*
|
|
997
1184
|
* Design:
|
|
998
|
-
* - Input: Partial<LLMConfig> (allows optional fields like maxIterations
|
|
1185
|
+
* - Input: Partial<LLMConfig> (allows optional fields like maxIterations?)
|
|
999
1186
|
* - Output: LLMConfig (user-friendly type with all defaults applied)
|
|
1000
1187
|
*
|
|
1001
1188
|
* Key features:
|
|
@@ -1020,8 +1207,8 @@ Either:
|
|
|
1020
1207
|
* // Switch to a different provider with explicit API key
|
|
1021
1208
|
* await agent.switchLLM({ provider: 'anthropic', model: 'claude-4-sonnet-20250514', apiKey: 'sk-ant-...' });
|
|
1022
1209
|
*
|
|
1023
|
-
* // Switch with
|
|
1024
|
-
* await agent.switchLLM({ provider: 'anthropic', model: 'claude-4-sonnet-20250514'
|
|
1210
|
+
* // Switch with session options
|
|
1211
|
+
* await agent.switchLLM({ provider: 'anthropic', model: 'claude-4-sonnet-20250514' }, 'user-123');
|
|
1025
1212
|
*
|
|
1026
1213
|
* // Switch for all sessions
|
|
1027
1214
|
* await agent.switchLLM({ model: 'gpt-5' }, '*');
|
|
@@ -1038,7 +1225,11 @@ Either:
|
|
|
1038
1225
|
}
|
|
1039
1226
|
const validatedUpdates = parseResult.data;
|
|
1040
1227
|
const currentLLMConfig = sessionId ? this.stateManager.getRuntimeConfig(sessionId).llm : this.stateManager.getRuntimeConfig().llm;
|
|
1041
|
-
const result = (0, import_resolver.resolveAndValidateLLMConfig)(
|
|
1228
|
+
const result = await (0, import_resolver.resolveAndValidateLLMConfig)(
|
|
1229
|
+
currentLLMConfig,
|
|
1230
|
+
validatedUpdates,
|
|
1231
|
+
this.logger
|
|
1232
|
+
);
|
|
1042
1233
|
const validatedConfig = (0, import_result_bridge.ensureOk)(result, this.logger);
|
|
1043
1234
|
await this.performLLMSwitch(validatedConfig, sessionId);
|
|
1044
1235
|
this.logger.info(
|
|
@@ -1173,19 +1364,23 @@ Either:
|
|
|
1173
1364
|
}
|
|
1174
1365
|
// ============= MCP SERVER MANAGEMENT =============
|
|
1175
1366
|
/**
|
|
1176
|
-
*
|
|
1367
|
+
* Adds a new MCP server to the runtime configuration and connects it if enabled.
|
|
1177
1368
|
* This method handles validation, state management, and establishing the connection.
|
|
1178
1369
|
*
|
|
1179
|
-
* @param name The name of the server to
|
|
1370
|
+
* @param name The name of the server to add.
|
|
1180
1371
|
* @param config The configuration object for the server.
|
|
1181
1372
|
* @throws DextoError if validation fails or connection fails
|
|
1182
1373
|
*/
|
|
1183
|
-
async
|
|
1374
|
+
async addMcpServer(name, config) {
|
|
1184
1375
|
this.ensureStarted();
|
|
1185
1376
|
const existingServerNames = Object.keys(this.stateManager.getRuntimeConfig().mcpServers);
|
|
1186
1377
|
const validation = (0, import_resolver2.resolveAndValidateMcpServerConfig)(name, config, existingServerNames);
|
|
1187
1378
|
const validatedConfig = (0, import_result_bridge.ensureOk)(validation, this.logger);
|
|
1188
|
-
this.stateManager.
|
|
1379
|
+
this.stateManager.setMcpServer(name, validatedConfig);
|
|
1380
|
+
if (validatedConfig.enabled === false) {
|
|
1381
|
+
this.logger.info(`MCP server '${name}' added but not connected (disabled)`);
|
|
1382
|
+
return;
|
|
1383
|
+
}
|
|
1189
1384
|
try {
|
|
1190
1385
|
await this.mcpManager.connectServer(name, validatedConfig);
|
|
1191
1386
|
await this.toolManager.refresh();
|
|
@@ -1197,9 +1392,7 @@ Either:
|
|
|
1197
1392
|
tools: Object.keys(await this.toolManager.getAllTools()),
|
|
1198
1393
|
source: "mcp"
|
|
1199
1394
|
});
|
|
1200
|
-
this.logger.info(
|
|
1201
|
-
`DextoAgent: Successfully added and connected to MCP server '${name}'.`
|
|
1202
|
-
);
|
|
1395
|
+
this.logger.info(`MCP server '${name}' added and connected successfully`);
|
|
1203
1396
|
const warnings = validation.issues.filter((i) => i.severity === "warning");
|
|
1204
1397
|
if (warnings.length > 0) {
|
|
1205
1398
|
this.logger.warn(
|
|
@@ -1208,9 +1401,7 @@ Either:
|
|
|
1208
1401
|
}
|
|
1209
1402
|
} catch (error) {
|
|
1210
1403
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1211
|
-
this.logger.error(
|
|
1212
|
-
`DextoAgent: Failed to connect to MCP server '${name}': ${errorMessage}`
|
|
1213
|
-
);
|
|
1404
|
+
this.logger.error(`Failed to connect MCP server '${name}': ${errorMessage}`);
|
|
1214
1405
|
this.stateManager.removeMcpServer(name);
|
|
1215
1406
|
this.agentEventBus.emit("mcp:server-connected", {
|
|
1216
1407
|
name,
|
|
@@ -1221,14 +1412,81 @@ Either:
|
|
|
1221
1412
|
}
|
|
1222
1413
|
}
|
|
1223
1414
|
/**
|
|
1224
|
-
*
|
|
1415
|
+
* @deprecated Use `addMcpServer` instead. This method will be removed in a future version.
|
|
1416
|
+
*/
|
|
1417
|
+
async connectMcpServer(name, config) {
|
|
1418
|
+
return this.addMcpServer(name, config);
|
|
1419
|
+
}
|
|
1420
|
+
/**
|
|
1421
|
+
* Enables a disabled MCP server and connects it.
|
|
1422
|
+
* Updates the runtime state to enabled=true and establishes the connection.
|
|
1423
|
+
*
|
|
1424
|
+
* @param name The name of the server to enable.
|
|
1425
|
+
* @throws MCPError if server is not found or connection fails
|
|
1426
|
+
*/
|
|
1427
|
+
async enableMcpServer(name) {
|
|
1428
|
+
this.ensureStarted();
|
|
1429
|
+
const currentConfig = this.stateManager.getRuntimeConfig().mcpServers[name];
|
|
1430
|
+
if (!currentConfig) {
|
|
1431
|
+
throw import_errors3.MCPError.serverNotFound(name);
|
|
1432
|
+
}
|
|
1433
|
+
const updatedConfig = { ...currentConfig, enabled: true };
|
|
1434
|
+
this.stateManager.setMcpServer(name, updatedConfig);
|
|
1435
|
+
try {
|
|
1436
|
+
await this.mcpManager.connectServer(name, updatedConfig);
|
|
1437
|
+
await this.toolManager.refresh();
|
|
1438
|
+
this.agentEventBus.emit("mcp:server-connected", { name, success: true });
|
|
1439
|
+
this.logger.info(`MCP server '${name}' enabled and connected`);
|
|
1440
|
+
} catch (error) {
|
|
1441
|
+
this.stateManager.setMcpServer(name, currentConfig);
|
|
1442
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1443
|
+
this.logger.error(`Failed to enable MCP server '${name}': ${errorMessage}`);
|
|
1444
|
+
throw import_errors3.MCPError.connectionFailed(name, errorMessage);
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
/**
|
|
1448
|
+
* Disables an MCP server and disconnects it.
|
|
1449
|
+
* Updates the runtime state to enabled=false and closes the connection.
|
|
1450
|
+
*
|
|
1451
|
+
* @param name The name of the server to disable.
|
|
1452
|
+
* @throws MCPError if server is not found or disconnect fails
|
|
1453
|
+
*/
|
|
1454
|
+
async disableMcpServer(name) {
|
|
1455
|
+
this.ensureStarted();
|
|
1456
|
+
const currentConfig = this.stateManager.getRuntimeConfig().mcpServers[name];
|
|
1457
|
+
if (!currentConfig) {
|
|
1458
|
+
throw import_errors3.MCPError.serverNotFound(name);
|
|
1459
|
+
}
|
|
1460
|
+
const updatedConfig = { ...currentConfig, enabled: false };
|
|
1461
|
+
this.stateManager.setMcpServer(name, updatedConfig);
|
|
1462
|
+
try {
|
|
1463
|
+
await this.mcpManager.removeClient(name);
|
|
1464
|
+
await this.toolManager.refresh();
|
|
1465
|
+
this.logger.info(`MCP server '${name}' disabled and disconnected`);
|
|
1466
|
+
} catch (error) {
|
|
1467
|
+
this.stateManager.setMcpServer(name, currentConfig);
|
|
1468
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1469
|
+
this.logger.error(`Failed to disable MCP server '${name}': ${errorMessage}`);
|
|
1470
|
+
throw import_errors3.MCPError.disconnectionFailed(name, errorMessage);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Removes and disconnects an MCP server completely.
|
|
1475
|
+
* Use this for deleting a server - removes from both runtime state and disconnects.
|
|
1225
1476
|
* @param name The name of the server to remove.
|
|
1477
|
+
* @throws MCPError if disconnection fails
|
|
1226
1478
|
*/
|
|
1227
1479
|
async removeMcpServer(name) {
|
|
1228
1480
|
this.ensureStarted();
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1481
|
+
try {
|
|
1482
|
+
await this.mcpManager.removeClient(name);
|
|
1483
|
+
this.stateManager.removeMcpServer(name);
|
|
1484
|
+
await this.toolManager.refresh();
|
|
1485
|
+
} catch (error) {
|
|
1486
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1487
|
+
this.logger.error(`Failed to remove MCP server '${name}': ${errorMessage}`);
|
|
1488
|
+
throw import_errors3.MCPError.disconnectionFailed(name, errorMessage);
|
|
1489
|
+
}
|
|
1232
1490
|
}
|
|
1233
1491
|
/**
|
|
1234
1492
|
* Restarts an MCP server by disconnecting and reconnecting with its original configuration.
|
|
@@ -1261,13 +1519,18 @@ Either:
|
|
|
1261
1519
|
/**
|
|
1262
1520
|
* Executes a tool from any source (MCP servers, custom tools, or internal tools).
|
|
1263
1521
|
* This is the unified interface for tool execution that can handle all tool types.
|
|
1522
|
+
*
|
|
1523
|
+
* Note: This is for direct/programmatic tool execution outside of LLM flow.
|
|
1524
|
+
* A toolCallId is generated automatically for tracking purposes.
|
|
1525
|
+
*
|
|
1264
1526
|
* @param toolName The name of the tool to execute
|
|
1265
1527
|
* @param args The arguments to pass to the tool
|
|
1266
1528
|
* @returns The result of the tool execution
|
|
1267
1529
|
*/
|
|
1268
1530
|
async executeTool(toolName, args) {
|
|
1269
1531
|
this.ensureStarted();
|
|
1270
|
-
|
|
1532
|
+
const toolCallId = `direct-${(0, import_crypto.randomUUID)()}`;
|
|
1533
|
+
return await this.toolManager.executeTool(toolName, args, toolCallId);
|
|
1271
1534
|
}
|
|
1272
1535
|
/**
|
|
1273
1536
|
* Gets all available tools from all connected MCP servers.
|
|
@@ -1278,6 +1541,15 @@ Either:
|
|
|
1278
1541
|
this.ensureStarted();
|
|
1279
1542
|
return await this.mcpManager.getAllTools();
|
|
1280
1543
|
}
|
|
1544
|
+
/**
|
|
1545
|
+
* Gets all MCP tools with their server metadata.
|
|
1546
|
+
* Returns tool cache entries which include server names for proper grouping.
|
|
1547
|
+
* @returns Map of tool names to cache entries with server info
|
|
1548
|
+
*/
|
|
1549
|
+
getAllMcpToolsWithServerInfo() {
|
|
1550
|
+
this.ensureStarted();
|
|
1551
|
+
return this.mcpManager.getAllToolsWithServerInfo();
|
|
1552
|
+
}
|
|
1281
1553
|
/**
|
|
1282
1554
|
* Gets all available tools from all sources (MCP servers and custom tools).
|
|
1283
1555
|
* This is the unified interface for tool discovery that includes both MCP and custom tools.
|
|
@@ -1305,6 +1577,79 @@ Either:
|
|
|
1305
1577
|
this.ensureStarted();
|
|
1306
1578
|
return this.mcpManager.getFailedConnections();
|
|
1307
1579
|
}
|
|
1580
|
+
/**
|
|
1581
|
+
* Gets the connection status of a single MCP server.
|
|
1582
|
+
* @param name The server name
|
|
1583
|
+
* @returns The connection status, or undefined if server not configured
|
|
1584
|
+
*
|
|
1585
|
+
* TODO: Move to MCPManager once it has access to server configs (enabled state).
|
|
1586
|
+
* Currently here because MCPManager only tracks connections, not config.
|
|
1587
|
+
*/
|
|
1588
|
+
getMcpServerStatus(name) {
|
|
1589
|
+
this.ensureStarted();
|
|
1590
|
+
const config = this.stateManager.getRuntimeConfig();
|
|
1591
|
+
const serverConfig = config.mcpServers[name];
|
|
1592
|
+
if (!serverConfig) return void 0;
|
|
1593
|
+
const enabled = serverConfig.enabled !== false;
|
|
1594
|
+
const connectedClients = this.mcpManager.getClients();
|
|
1595
|
+
const failedConnections = this.mcpManager.getFailedConnections();
|
|
1596
|
+
let status;
|
|
1597
|
+
if (!enabled) {
|
|
1598
|
+
status = "disconnected";
|
|
1599
|
+
} else if (connectedClients.has(name)) {
|
|
1600
|
+
status = "connected";
|
|
1601
|
+
} else {
|
|
1602
|
+
status = "error";
|
|
1603
|
+
}
|
|
1604
|
+
const result = {
|
|
1605
|
+
name,
|
|
1606
|
+
type: serverConfig.type,
|
|
1607
|
+
enabled,
|
|
1608
|
+
status
|
|
1609
|
+
};
|
|
1610
|
+
if (failedConnections[name]) {
|
|
1611
|
+
result.error = failedConnections[name];
|
|
1612
|
+
}
|
|
1613
|
+
return result;
|
|
1614
|
+
}
|
|
1615
|
+
/**
|
|
1616
|
+
* Gets all configured MCP servers with their connection status.
|
|
1617
|
+
* Centralizes the status computation logic used by CLI, server, and webui.
|
|
1618
|
+
* @returns Array of server info with computed status
|
|
1619
|
+
*
|
|
1620
|
+
* TODO: Move to MCPManager once it has access to server configs (enabled state).
|
|
1621
|
+
* Currently here because MCPManager only tracks connections, not config.
|
|
1622
|
+
*/
|
|
1623
|
+
getMcpServersWithStatus() {
|
|
1624
|
+
this.ensureStarted();
|
|
1625
|
+
const config = this.stateManager.getRuntimeConfig();
|
|
1626
|
+
const mcpServers = config.mcpServers || {};
|
|
1627
|
+
const connectedClients = this.mcpManager.getClients();
|
|
1628
|
+
const failedConnections = this.mcpManager.getFailedConnections();
|
|
1629
|
+
const servers = [];
|
|
1630
|
+
for (const [name, serverConfig] of Object.entries(mcpServers)) {
|
|
1631
|
+
const enabled = serverConfig.enabled !== false;
|
|
1632
|
+
let status;
|
|
1633
|
+
if (!enabled) {
|
|
1634
|
+
status = "disconnected";
|
|
1635
|
+
} else if (connectedClients.has(name)) {
|
|
1636
|
+
status = "connected";
|
|
1637
|
+
} else {
|
|
1638
|
+
status = "error";
|
|
1639
|
+
}
|
|
1640
|
+
const server = {
|
|
1641
|
+
name,
|
|
1642
|
+
type: serverConfig.type,
|
|
1643
|
+
enabled,
|
|
1644
|
+
status
|
|
1645
|
+
};
|
|
1646
|
+
if (failedConnections[name]) {
|
|
1647
|
+
server.error = failedConnections[name];
|
|
1648
|
+
}
|
|
1649
|
+
servers.push(server);
|
|
1650
|
+
}
|
|
1651
|
+
return servers;
|
|
1652
|
+
}
|
|
1308
1653
|
// ============= RESOURCE MANAGEMENT =============
|
|
1309
1654
|
/**
|
|
1310
1655
|
* Lists all available resources with their info.
|
|
@@ -1400,6 +1745,21 @@ Either:
|
|
|
1400
1745
|
this.ensureStarted();
|
|
1401
1746
|
return await this.promptManager.has(name);
|
|
1402
1747
|
}
|
|
1748
|
+
/**
|
|
1749
|
+
* Refreshes the prompts cache, reloading from all providers.
|
|
1750
|
+
* Call this after adding/deleting prompts to make them immediately available.
|
|
1751
|
+
*
|
|
1752
|
+
* @param newPrompts Optional - if provided, updates the config prompts before refreshing.
|
|
1753
|
+
* Use this when you've modified the agent config file and need to
|
|
1754
|
+
* update both the runtime config and refresh the cache.
|
|
1755
|
+
*/
|
|
1756
|
+
async refreshPrompts(newPrompts) {
|
|
1757
|
+
this.ensureStarted();
|
|
1758
|
+
if (newPrompts) {
|
|
1759
|
+
this.promptManager.updateConfigPrompts(newPrompts);
|
|
1760
|
+
}
|
|
1761
|
+
await this.promptManager.refresh();
|
|
1762
|
+
}
|
|
1403
1763
|
/**
|
|
1404
1764
|
* Gets a prompt with its messages.
|
|
1405
1765
|
* @param name The name of the prompt
|