@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
package/dist/agent/DextoAgent.js
CHANGED
|
@@ -2,8 +2,10 @@ import {
|
|
|
2
2
|
__decorateElement,
|
|
3
3
|
__decoratorStart,
|
|
4
4
|
__runInitializers
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-PTJYTZNU.js";
|
|
6
6
|
var _DextoAgent_decorators, _init;
|
|
7
|
+
import { randomUUID } from "crypto";
|
|
8
|
+
import { setMaxListeners } from "events";
|
|
7
9
|
import { expandMessageReferences } from "../resources/index.js";
|
|
8
10
|
import { expandBlobReferences } from "../context/utils.js";
|
|
9
11
|
import { PromptManager } from "../prompts/index.js";
|
|
@@ -19,6 +21,7 @@ import { LLMError } from "../llm/errors.js";
|
|
|
19
21
|
import { AgentError } from "./errors.js";
|
|
20
22
|
import { MCPError } from "../mcp/errors.js";
|
|
21
23
|
import { DextoRuntimeError } from "../errors/DextoRuntimeError.js";
|
|
24
|
+
import { DextoValidationError } from "../errors/DextoValidationError.js";
|
|
22
25
|
import { ensureOk } from "../errors/result-bridge.js";
|
|
23
26
|
import { fail, zodToIssues } from "../utils/result.js";
|
|
24
27
|
import { resolveAndValidateMcpServerConfig } from "../mcp/resolver.js";
|
|
@@ -29,7 +32,7 @@ import {
|
|
|
29
32
|
LLM_REGISTRY
|
|
30
33
|
} from "../llm/registry.js";
|
|
31
34
|
import { createAgentServices } from "../utils/service-initializer.js";
|
|
32
|
-
import { AgentConfigSchema } from "./schemas.js";
|
|
35
|
+
import { AgentConfigSchema, createAgentConfigSchema } from "./schemas.js";
|
|
33
36
|
import {
|
|
34
37
|
AgentEventBus
|
|
35
38
|
} from "../events/index.js";
|
|
@@ -62,10 +65,14 @@ class DextoAgent {
|
|
|
62
65
|
*
|
|
63
66
|
* @param config - Agent configuration (validated and enriched)
|
|
64
67
|
* @param configPath - Optional path to config file (for relative path resolution)
|
|
68
|
+
* @param options - Validation options
|
|
69
|
+
* @param options.strict - When true (default), enforces API key and baseURL requirements.
|
|
70
|
+
* When false, allows missing credentials for interactive configuration.
|
|
65
71
|
*/
|
|
66
|
-
constructor(config, configPath) {
|
|
72
|
+
constructor(config, configPath, options) {
|
|
67
73
|
this.configPath = configPath;
|
|
68
|
-
|
|
74
|
+
const schema = options?.strict === false ? createAgentConfigSchema({ strict: false }) : AgentConfigSchema;
|
|
75
|
+
this.config = schema.parse(config);
|
|
69
76
|
this.logger = createLogger({
|
|
70
77
|
config: this.config.logger,
|
|
71
78
|
agentId: this.config.agentId,
|
|
@@ -103,6 +110,8 @@ class DextoAgent {
|
|
|
103
110
|
// Approval handler for manual tool confirmation and elicitation
|
|
104
111
|
// Set via setApprovalHandler() before start() if needed
|
|
105
112
|
approvalHandler;
|
|
113
|
+
// Active stream controllers per session - allows cancel() to abort iterators
|
|
114
|
+
activeStreamControllers = /* @__PURE__ */ new Map();
|
|
106
115
|
// Logger instance for this agent (dependency injection)
|
|
107
116
|
logger;
|
|
108
117
|
/**
|
|
@@ -161,6 +170,8 @@ Either:
|
|
|
161
170
|
memoryManager: services.memoryManager,
|
|
162
171
|
services
|
|
163
172
|
});
|
|
173
|
+
services.toolManager.setAgent(this);
|
|
174
|
+
await services.toolManager.initialize();
|
|
164
175
|
this.searchService = services.searchService;
|
|
165
176
|
const promptManager = new PromptManager(
|
|
166
177
|
this.mcpManager,
|
|
@@ -178,10 +189,6 @@ Either:
|
|
|
178
189
|
for (const subscriber of this.eventSubscribers) {
|
|
179
190
|
subscriber.subscribe(this.agentEventBus);
|
|
180
191
|
}
|
|
181
|
-
const fileTransport = this.config.logger?.transports?.find((t) => t.type === "file");
|
|
182
|
-
if (fileTransport && "path" in fileTransport) {
|
|
183
|
-
console.log(`\u{1F4CB} Logs available at: ${fileTransport.path}`);
|
|
184
|
-
}
|
|
185
192
|
} catch (error) {
|
|
186
193
|
this.logger.error("Failed to start DextoAgent", {
|
|
187
194
|
error: error instanceof Error ? error.message : String(error)
|
|
@@ -312,173 +319,88 @@ Either:
|
|
|
312
319
|
}
|
|
313
320
|
// ============= CORE AGENT FUNCTIONALITY =============
|
|
314
321
|
/**
|
|
315
|
-
*
|
|
316
|
-
*
|
|
322
|
+
* Process user input and return the response.
|
|
323
|
+
*
|
|
324
|
+
* @deprecated Use generate() or stream() instead for multi-image support.
|
|
325
|
+
* This method is kept for backward compatibility and only supports single image/file.
|
|
317
326
|
*
|
|
318
|
-
* @param textInput - The user's text message
|
|
319
|
-
* @param imageDataInput - Optional image data
|
|
320
|
-
* @param fileDataInput - Optional file data
|
|
327
|
+
* @param textInput - The user's text message
|
|
328
|
+
* @param imageDataInput - Optional single image data
|
|
329
|
+
* @param fileDataInput - Optional single file data
|
|
321
330
|
* @param sessionId - Session ID for the conversation (required)
|
|
322
|
-
* @param
|
|
323
|
-
* @returns Promise that resolves to the AI's response text
|
|
324
|
-
* @throws Error if processing fails
|
|
331
|
+
* @param _stream - Ignored (streaming is handled internally)
|
|
332
|
+
* @returns Promise that resolves to the AI's response text
|
|
325
333
|
*/
|
|
326
|
-
async run(textInput, imageDataInput, fileDataInput, sessionId,
|
|
327
|
-
|
|
328
|
-
if (
|
|
329
|
-
|
|
334
|
+
async run(textInput, imageDataInput, fileDataInput, sessionId, _stream = false) {
|
|
335
|
+
const parts = [];
|
|
336
|
+
if (textInput) {
|
|
337
|
+
parts.push({ type: "text", text: textInput });
|
|
330
338
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
339
|
+
if (imageDataInput) {
|
|
340
|
+
parts.push({
|
|
341
|
+
type: "image",
|
|
342
|
+
image: imageDataInput.image,
|
|
343
|
+
mimeType: imageDataInput.mimeType
|
|
344
|
+
});
|
|
336
345
|
}
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
346
|
+
if (fileDataInput) {
|
|
347
|
+
parts.push({
|
|
348
|
+
type: "file",
|
|
349
|
+
data: fileDataInput.data,
|
|
350
|
+
mimeType: fileDataInput.mimeType,
|
|
351
|
+
...fileDataInput.filename && { filename: fileDataInput.filename }
|
|
342
352
|
});
|
|
343
353
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
activeContext,
|
|
347
|
-
propagation.createBaggage(baggageEntries)
|
|
348
|
-
);
|
|
349
|
-
const verifyBaggage = propagation.getBaggage(updatedContext);
|
|
350
|
-
this.logger.debug(
|
|
351
|
-
`Baggage after setting sessionId: ${JSON.stringify(
|
|
352
|
-
Array.from(verifyBaggage?.getAllEntries() || [])
|
|
353
|
-
)}`
|
|
354
|
-
);
|
|
355
|
-
return await context.with(updatedContext, async () => {
|
|
356
|
-
try {
|
|
357
|
-
const llmConfig = this.stateManager.getLLMConfig(targetSessionId);
|
|
358
|
-
const validation = validateInputForLLM(
|
|
359
|
-
{
|
|
360
|
-
text: textInput,
|
|
361
|
-
...imageDataInput && { imageData: imageDataInput },
|
|
362
|
-
...fileDataInput && { fileData: fileDataInput }
|
|
363
|
-
},
|
|
364
|
-
{
|
|
365
|
-
provider: llmConfig.provider,
|
|
366
|
-
model: llmConfig.model
|
|
367
|
-
},
|
|
368
|
-
this.logger
|
|
369
|
-
);
|
|
370
|
-
ensureOk(validation, this.logger);
|
|
371
|
-
const session = await this.sessionManager.getSession(targetSessionId) || await this.sessionManager.createSession(targetSessionId);
|
|
372
|
-
this.logger.debug(
|
|
373
|
-
`DextoAgent.run: sessionId=${targetSessionId}, textLength=${textInput?.length ?? 0}, hasImage=${Boolean(
|
|
374
|
-
imageDataInput
|
|
375
|
-
)}, hasFile=${Boolean(fileDataInput)}`
|
|
376
|
-
);
|
|
377
|
-
let finalText = textInput;
|
|
378
|
-
let finalImageData = imageDataInput;
|
|
379
|
-
if (textInput && textInput.includes("@")) {
|
|
380
|
-
try {
|
|
381
|
-
const resources = await this.resourceManager.list();
|
|
382
|
-
const expansion = await expandMessageReferences(
|
|
383
|
-
textInput,
|
|
384
|
-
resources,
|
|
385
|
-
(uri) => this.resourceManager.read(uri)
|
|
386
|
-
);
|
|
387
|
-
if (expansion.unresolvedReferences.length > 0) {
|
|
388
|
-
const unresolvedNames = expansion.unresolvedReferences.map((ref) => ref.originalRef).join(", ");
|
|
389
|
-
this.logger.warn(
|
|
390
|
-
`Could not resolve ${expansion.unresolvedReferences.length} resource reference(s): ${unresolvedNames}`
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
|
-
const MAX_EXPANDED_SIZE = 5 * 1024 * 1024;
|
|
394
|
-
const expandedSize = Buffer.byteLength(expansion.expandedMessage, "utf-8");
|
|
395
|
-
if (expandedSize > MAX_EXPANDED_SIZE) {
|
|
396
|
-
this.logger.warn(
|
|
397
|
-
`Expanded message size (${(expandedSize / 1024 / 1024).toFixed(2)}MB) exceeds limit (${MAX_EXPANDED_SIZE / 1024 / 1024}MB). Content may be truncated.`
|
|
398
|
-
);
|
|
399
|
-
}
|
|
400
|
-
finalText = expansion.expandedMessage;
|
|
401
|
-
if (expansion.extractedImages.length > 0 && !imageDataInput) {
|
|
402
|
-
const firstImage = expansion.extractedImages[0];
|
|
403
|
-
if (firstImage) {
|
|
404
|
-
finalImageData = {
|
|
405
|
-
image: firstImage.image,
|
|
406
|
-
mimeType: firstImage.mimeType
|
|
407
|
-
};
|
|
408
|
-
this.logger.debug(
|
|
409
|
-
`Using extracted image: ${firstImage.name} (${firstImage.mimeType})`
|
|
410
|
-
);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
} catch (error) {
|
|
414
|
-
this.logger.error(
|
|
415
|
-
`Failed to expand resource references: ${error instanceof Error ? error.message : String(error)}. Continuing with original message.`
|
|
416
|
-
);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
if (!finalText.trim() && !finalImageData && !fileDataInput) {
|
|
420
|
-
this.logger.warn(
|
|
421
|
-
"Resource expansion resulted in empty content. Using original message."
|
|
422
|
-
);
|
|
423
|
-
finalText = textInput;
|
|
424
|
-
}
|
|
425
|
-
const response = await session.run(
|
|
426
|
-
finalText,
|
|
427
|
-
finalImageData,
|
|
428
|
-
fileDataInput,
|
|
429
|
-
stream
|
|
430
|
-
);
|
|
431
|
-
this.sessionManager.incrementMessageCount(session.id).catch(
|
|
432
|
-
(error) => this.logger.warn(
|
|
433
|
-
`Failed to increment message count: ${error instanceof Error ? error.message : String(error)}`
|
|
434
|
-
)
|
|
435
|
-
);
|
|
436
|
-
return response;
|
|
437
|
-
} catch (error) {
|
|
438
|
-
this.logger.error(
|
|
439
|
-
`Error during DextoAgent.run: ${error instanceof Error ? error.message : JSON.stringify(error)}`
|
|
440
|
-
);
|
|
441
|
-
throw error;
|
|
442
|
-
}
|
|
443
|
-
});
|
|
354
|
+
const response = await this.generate(parts.length > 0 ? parts : textInput, sessionId);
|
|
355
|
+
return response.content;
|
|
444
356
|
}
|
|
445
357
|
/**
|
|
446
358
|
* Generate a complete response (waits for full completion).
|
|
447
359
|
* This is the recommended method for non-streaming use cases.
|
|
448
360
|
*
|
|
449
|
-
* @param message
|
|
450
|
-
* @param
|
|
361
|
+
* @param content String message or array of content parts (text, images, files)
|
|
362
|
+
* @param sessionId Session ID for the conversation
|
|
363
|
+
* @param options Optional configuration (signal for cancellation)
|
|
451
364
|
* @returns Promise that resolves to the complete response
|
|
452
365
|
*
|
|
453
366
|
* @example
|
|
454
367
|
* ```typescript
|
|
455
|
-
*
|
|
368
|
+
* // Simple text message
|
|
369
|
+
* const response = await agent.generate('What is 2+2?', 'session-1');
|
|
456
370
|
* console.log(response.content); // "4"
|
|
457
|
-
*
|
|
371
|
+
*
|
|
372
|
+
* // Multimodal with image
|
|
373
|
+
* const response = await agent.generate(
|
|
374
|
+
* [
|
|
375
|
+
* { type: 'text', text: 'Describe this image' },
|
|
376
|
+
* { type: 'image', image: base64Data, mimeType: 'image/png' }
|
|
377
|
+
* ],
|
|
378
|
+
* 'session-1'
|
|
379
|
+
* );
|
|
458
380
|
* ```
|
|
459
381
|
*/
|
|
460
|
-
async generate(
|
|
382
|
+
async generate(content, sessionId, options) {
|
|
461
383
|
const events = [];
|
|
462
|
-
for await (const event of await this.stream(
|
|
384
|
+
for await (const event of await this.stream(content, sessionId, options)) {
|
|
463
385
|
events.push(event);
|
|
464
386
|
}
|
|
465
|
-
const
|
|
466
|
-
(e) => e.name === "llm:error"
|
|
387
|
+
const fatalErrorEvent = events.find(
|
|
388
|
+
(e) => e.name === "llm:error" && e.recoverable !== true
|
|
467
389
|
);
|
|
468
|
-
if (
|
|
469
|
-
if (
|
|
470
|
-
throw
|
|
390
|
+
if (fatalErrorEvent) {
|
|
391
|
+
if (fatalErrorEvent.error instanceof DextoRuntimeError || fatalErrorEvent.error instanceof DextoValidationError) {
|
|
392
|
+
throw fatalErrorEvent.error;
|
|
471
393
|
}
|
|
472
|
-
const llmConfig = this.stateManager.getLLMConfig(
|
|
394
|
+
const llmConfig = this.stateManager.getLLMConfig(sessionId);
|
|
473
395
|
throw LLMError.generationFailed(
|
|
474
|
-
|
|
396
|
+
fatalErrorEvent.error.message,
|
|
475
397
|
llmConfig.provider,
|
|
476
398
|
llmConfig.model
|
|
477
399
|
);
|
|
478
400
|
}
|
|
479
401
|
const responseEvent = events.find((e) => e.name === "llm:response");
|
|
480
402
|
if (!responseEvent || responseEvent.name !== "llm:response") {
|
|
481
|
-
const llmConfig = this.stateManager.getLLMConfig(
|
|
403
|
+
const llmConfig = this.stateManager.getLLMConfig(sessionId);
|
|
482
404
|
throw LLMError.generationFailed(
|
|
483
405
|
"Stream did not complete successfully - no response received",
|
|
484
406
|
llmConfig.provider,
|
|
@@ -514,7 +436,7 @@ Either:
|
|
|
514
436
|
reasoning: responseEvent.reasoning,
|
|
515
437
|
usage,
|
|
516
438
|
toolCalls,
|
|
517
|
-
sessionId
|
|
439
|
+
sessionId
|
|
518
440
|
};
|
|
519
441
|
}
|
|
520
442
|
/**
|
|
@@ -528,36 +450,38 @@ Either:
|
|
|
528
450
|
* Events are forwarded directly from the AgentEventBus with no mapping layer,
|
|
529
451
|
* providing a unified event system across all API layers.
|
|
530
452
|
*
|
|
531
|
-
* @param message
|
|
532
|
-
* @param
|
|
453
|
+
* @param content String message or array of content parts (text, images, files)
|
|
454
|
+
* @param sessionId Session ID for the conversation
|
|
455
|
+
* @param options Optional configuration (signal for cancellation)
|
|
533
456
|
* @returns AsyncIterator that yields StreamingEvent objects (core events with name property)
|
|
534
457
|
*
|
|
535
458
|
* @example
|
|
536
459
|
* ```typescript
|
|
537
|
-
*
|
|
538
|
-
*
|
|
539
|
-
*
|
|
540
|
-
* }
|
|
541
|
-
* if (event.name === 'llm:tool-call') {
|
|
542
|
-
* console.log(`\n[Using ${event.toolName}]\n`);
|
|
543
|
-
* }
|
|
460
|
+
* // Simple text
|
|
461
|
+
* for await (const event of await agent.stream('Write a poem', 'session-1')) {
|
|
462
|
+
* if (event.name === 'llm:chunk') process.stdout.write(event.content);
|
|
544
463
|
* }
|
|
464
|
+
*
|
|
465
|
+
* // Multimodal
|
|
466
|
+
* for await (const event of await agent.stream(
|
|
467
|
+
* [{ type: 'text', text: 'Describe this' }, { type: 'image', image: data, mimeType: 'image/png' }],
|
|
468
|
+
* 'session-1'
|
|
469
|
+
* )) { ... }
|
|
545
470
|
* ```
|
|
546
471
|
*/
|
|
547
|
-
async stream(
|
|
472
|
+
async stream(content, sessionId, options) {
|
|
548
473
|
this.ensureStarted();
|
|
549
|
-
if (!
|
|
550
|
-
throw
|
|
474
|
+
if (!sessionId) {
|
|
475
|
+
throw AgentError.apiValidationError("sessionId is required");
|
|
551
476
|
}
|
|
552
|
-
const
|
|
553
|
-
|
|
554
|
-
const fileData = options.fileData;
|
|
555
|
-
const signal = options.signal;
|
|
477
|
+
const signal = options?.signal;
|
|
478
|
+
let contentParts = typeof content === "string" ? [{ type: "text", text: content }] : [...content];
|
|
556
479
|
const eventQueue = [];
|
|
557
480
|
let completed = false;
|
|
558
|
-
let _streamError = null;
|
|
559
481
|
const controller = new AbortController();
|
|
560
482
|
const cleanupSignal = controller.signal;
|
|
483
|
+
this.activeStreamControllers.set(sessionId, controller);
|
|
484
|
+
setMaxListeners(30, cleanupSignal);
|
|
561
485
|
const listeners = [];
|
|
562
486
|
const cleanupListeners = () => {
|
|
563
487
|
if (listeners.length === 0) {
|
|
@@ -570,6 +494,7 @@ Either:
|
|
|
570
494
|
);
|
|
571
495
|
}
|
|
572
496
|
listeners.length = 0;
|
|
497
|
+
this.activeStreamControllers.delete(sessionId);
|
|
573
498
|
};
|
|
574
499
|
if (signal) {
|
|
575
500
|
const abortHandler = () => {
|
|
@@ -593,7 +518,6 @@ Either:
|
|
|
593
518
|
const responseListener = (data) => {
|
|
594
519
|
if (data.sessionId !== sessionId) return;
|
|
595
520
|
eventQueue.push({ name: "llm:response", ...data });
|
|
596
|
-
completed = true;
|
|
597
521
|
};
|
|
598
522
|
this.agentEventBus.on("llm:response", responseListener, { signal: cleanupSignal });
|
|
599
523
|
listeners.push({ event: "llm:response", listener: responseListener });
|
|
@@ -650,34 +574,191 @@ Either:
|
|
|
650
574
|
signal: cleanupSignal
|
|
651
575
|
});
|
|
652
576
|
listeners.push({ event: "approval:response", listener: approvalResponseListener });
|
|
653
|
-
const
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
577
|
+
const toolRunningListener = (data) => {
|
|
578
|
+
if (data.sessionId !== sessionId) return;
|
|
579
|
+
eventQueue.push({ name: "tool:running", ...data });
|
|
580
|
+
};
|
|
581
|
+
this.agentEventBus.on("tool:running", toolRunningListener, {
|
|
582
|
+
signal: cleanupSignal
|
|
583
|
+
});
|
|
584
|
+
listeners.push({ event: "tool:running", listener: toolRunningListener });
|
|
585
|
+
const messageQueuedListener = (data) => {
|
|
586
|
+
if (data.sessionId !== sessionId) return;
|
|
587
|
+
eventQueue.push({ name: "message:queued", ...data });
|
|
588
|
+
};
|
|
589
|
+
this.agentEventBus.on("message:queued", messageQueuedListener, {
|
|
590
|
+
signal: cleanupSignal
|
|
591
|
+
});
|
|
592
|
+
listeners.push({ event: "message:queued", listener: messageQueuedListener });
|
|
593
|
+
const messageDequeuedListener = (data) => {
|
|
594
|
+
if (data.sessionId !== sessionId) return;
|
|
595
|
+
eventQueue.push({ name: "message:dequeued", ...data });
|
|
596
|
+
};
|
|
597
|
+
this.agentEventBus.on("message:dequeued", messageDequeuedListener, {
|
|
598
|
+
signal: cleanupSignal
|
|
599
|
+
});
|
|
600
|
+
listeners.push({ event: "message:dequeued", listener: messageDequeuedListener });
|
|
601
|
+
const runCompleteListener = (data) => {
|
|
602
|
+
if (data.sessionId !== sessionId) return;
|
|
603
|
+
eventQueue.push({ name: "run:complete", ...data });
|
|
665
604
|
completed = true;
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
error,
|
|
670
|
-
recoverable: false,
|
|
671
|
-
context: "run_failed",
|
|
672
|
-
sessionId
|
|
673
|
-
};
|
|
674
|
-
eventQueue.push(errorEvent);
|
|
605
|
+
};
|
|
606
|
+
this.agentEventBus.on("run:complete", runCompleteListener, {
|
|
607
|
+
signal: cleanupSignal
|
|
675
608
|
});
|
|
609
|
+
listeners.push({ event: "run:complete", listener: runCompleteListener });
|
|
610
|
+
(async () => {
|
|
611
|
+
const activeContext = context.active();
|
|
612
|
+
const activeSpan = trace.getActiveSpan();
|
|
613
|
+
if (activeSpan) {
|
|
614
|
+
activeSpan.setAttribute("sessionId", sessionId);
|
|
615
|
+
}
|
|
616
|
+
const existingBaggage = propagation.getBaggage(activeContext);
|
|
617
|
+
const baggageEntries = {};
|
|
618
|
+
if (existingBaggage) {
|
|
619
|
+
existingBaggage.getAllEntries().forEach(([key, entry]) => {
|
|
620
|
+
baggageEntries[key] = { ...entry };
|
|
621
|
+
});
|
|
622
|
+
}
|
|
623
|
+
baggageEntries.sessionId = { ...baggageEntries.sessionId, value: sessionId };
|
|
624
|
+
const updatedContext = propagation.setBaggage(
|
|
625
|
+
activeContext,
|
|
626
|
+
propagation.createBaggage(baggageEntries)
|
|
627
|
+
);
|
|
628
|
+
await context.with(updatedContext, async () => {
|
|
629
|
+
try {
|
|
630
|
+
const llmConfig = this.stateManager.getLLMConfig(sessionId);
|
|
631
|
+
const textParts = contentParts.filter(
|
|
632
|
+
(p) => p.type === "text"
|
|
633
|
+
);
|
|
634
|
+
const textContent = textParts.map((p) => p.text).join("\n");
|
|
635
|
+
const imageParts = contentParts.filter(
|
|
636
|
+
(p) => p.type === "image"
|
|
637
|
+
);
|
|
638
|
+
const fileParts = contentParts.filter(
|
|
639
|
+
(p) => p.type === "file"
|
|
640
|
+
);
|
|
641
|
+
this.logger.debug(
|
|
642
|
+
`DextoAgent.stream: sessionId=${sessionId}, textLength=${textContent?.length ?? 0}, imageCount=${imageParts.length}, fileCount=${fileParts.length}`
|
|
643
|
+
);
|
|
644
|
+
const textValidation = validateInputForLLM(
|
|
645
|
+
{ text: textContent },
|
|
646
|
+
{ provider: llmConfig.provider, model: llmConfig.model },
|
|
647
|
+
this.logger
|
|
648
|
+
);
|
|
649
|
+
ensureOk(textValidation, this.logger);
|
|
650
|
+
for (const imagePart of imageParts) {
|
|
651
|
+
const imageValidation = validateInputForLLM(
|
|
652
|
+
{
|
|
653
|
+
imageData: {
|
|
654
|
+
image: typeof imagePart.image === "string" ? imagePart.image : imagePart.image.toString(),
|
|
655
|
+
mimeType: imagePart.mimeType || "image/png"
|
|
656
|
+
}
|
|
657
|
+
},
|
|
658
|
+
{ provider: llmConfig.provider, model: llmConfig.model },
|
|
659
|
+
this.logger
|
|
660
|
+
);
|
|
661
|
+
ensureOk(imageValidation, this.logger);
|
|
662
|
+
}
|
|
663
|
+
for (const filePart of fileParts) {
|
|
664
|
+
const fileValidation = validateInputForLLM(
|
|
665
|
+
{
|
|
666
|
+
fileData: {
|
|
667
|
+
data: typeof filePart.data === "string" ? filePart.data : filePart.data.toString(),
|
|
668
|
+
mimeType: filePart.mimeType
|
|
669
|
+
}
|
|
670
|
+
},
|
|
671
|
+
{ provider: llmConfig.provider, model: llmConfig.model },
|
|
672
|
+
this.logger
|
|
673
|
+
);
|
|
674
|
+
ensureOk(fileValidation, this.logger);
|
|
675
|
+
}
|
|
676
|
+
if (textContent.includes("@")) {
|
|
677
|
+
try {
|
|
678
|
+
const resources = await this.resourceManager.list();
|
|
679
|
+
const expansion = await expandMessageReferences(
|
|
680
|
+
textContent,
|
|
681
|
+
resources,
|
|
682
|
+
(uri) => this.resourceManager.read(uri)
|
|
683
|
+
);
|
|
684
|
+
if (expansion.unresolvedReferences.length > 0) {
|
|
685
|
+
const unresolvedNames = expansion.unresolvedReferences.map((ref) => ref.originalRef).join(", ");
|
|
686
|
+
this.logger.warn(
|
|
687
|
+
`Could not resolve ${expansion.unresolvedReferences.length} resource reference(s): ${unresolvedNames}`
|
|
688
|
+
);
|
|
689
|
+
}
|
|
690
|
+
const MAX_EXPANDED_SIZE = 5 * 1024 * 1024;
|
|
691
|
+
const expandedSize = Buffer.byteLength(
|
|
692
|
+
expansion.expandedMessage,
|
|
693
|
+
"utf-8"
|
|
694
|
+
);
|
|
695
|
+
if (expandedSize > MAX_EXPANDED_SIZE) {
|
|
696
|
+
this.logger.warn(
|
|
697
|
+
`Expanded message size (${(expandedSize / 1024 / 1024).toFixed(2)}MB) exceeds limit (${MAX_EXPANDED_SIZE / 1024 / 1024}MB). Content may be truncated.`
|
|
698
|
+
);
|
|
699
|
+
}
|
|
700
|
+
contentParts = contentParts.filter((p) => p.type !== "text");
|
|
701
|
+
if (expansion.expandedMessage.trim()) {
|
|
702
|
+
contentParts.unshift({
|
|
703
|
+
type: "text",
|
|
704
|
+
text: expansion.expandedMessage
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
for (const img of expansion.extractedImages) {
|
|
708
|
+
contentParts.push({
|
|
709
|
+
type: "image",
|
|
710
|
+
image: img.image,
|
|
711
|
+
mimeType: img.mimeType
|
|
712
|
+
});
|
|
713
|
+
this.logger.debug(
|
|
714
|
+
`Added extracted image: ${img.name} (${img.mimeType})`
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
} catch (error) {
|
|
718
|
+
this.logger.error(
|
|
719
|
+
`Failed to expand resource references: ${error instanceof Error ? error.message : String(error)}. Continuing with original message.`
|
|
720
|
+
);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
const hasTextContent = contentParts.some(
|
|
724
|
+
(p) => p.type === "text" && p.text.trim()
|
|
725
|
+
);
|
|
726
|
+
const hasMediaContent = contentParts.some(
|
|
727
|
+
(p) => p.type === "image" || p.type === "file"
|
|
728
|
+
);
|
|
729
|
+
if (!hasTextContent && !hasMediaContent) {
|
|
730
|
+
this.logger.warn(
|
|
731
|
+
"Resource expansion resulted in empty content. Using original message."
|
|
732
|
+
);
|
|
733
|
+
contentParts = [{ type: "text", text: textContent }];
|
|
734
|
+
}
|
|
735
|
+
const session = await this.sessionManager.getSession(sessionId) || await this.sessionManager.createSession(sessionId);
|
|
736
|
+
await session.stream(contentParts, signal ? { signal } : void 0);
|
|
737
|
+
this.sessionManager.incrementMessageCount(session.id).catch(
|
|
738
|
+
(error) => this.logger.warn(
|
|
739
|
+
`Failed to increment message count: ${error instanceof Error ? error.message : String(error)}`
|
|
740
|
+
)
|
|
741
|
+
);
|
|
742
|
+
} catch (err) {
|
|
743
|
+
const error = err instanceof DextoRuntimeError || err instanceof DextoValidationError ? err : err instanceof Error ? err : AgentError.streamFailed(String(err));
|
|
744
|
+
completed = true;
|
|
745
|
+
this.logger.error(`Error in DextoAgent.stream: ${error.message}`);
|
|
746
|
+
const errorEvent = {
|
|
747
|
+
name: "llm:error",
|
|
748
|
+
error,
|
|
749
|
+
recoverable: false,
|
|
750
|
+
context: "run_failed",
|
|
751
|
+
sessionId
|
|
752
|
+
};
|
|
753
|
+
eventQueue.push(errorEvent);
|
|
754
|
+
}
|
|
755
|
+
});
|
|
756
|
+
})();
|
|
676
757
|
const iterator = {
|
|
677
758
|
async next() {
|
|
678
759
|
while (!completed && eventQueue.length === 0) {
|
|
679
760
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
680
|
-
if (signal?.aborted) {
|
|
761
|
+
if (signal?.aborted || cleanupSignal.aborted) {
|
|
681
762
|
cleanupListeners();
|
|
682
763
|
controller.abort();
|
|
683
764
|
return { done: true, value: void 0 };
|
|
@@ -705,6 +786,73 @@ Either:
|
|
|
705
786
|
};
|
|
706
787
|
return iterator;
|
|
707
788
|
}
|
|
789
|
+
/**
|
|
790
|
+
* Check if a session is currently processing a message.
|
|
791
|
+
* @param sessionId Session id
|
|
792
|
+
* @returns true if the session is busy processing; false otherwise
|
|
793
|
+
*/
|
|
794
|
+
async isSessionBusy(sessionId) {
|
|
795
|
+
this.ensureStarted();
|
|
796
|
+
const session = await this.sessionManager.getSession(sessionId, false);
|
|
797
|
+
return session?.isBusy() ?? false;
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Queue a message for processing when a session is busy.
|
|
801
|
+
* The message will be injected into the conversation when the current turn completes.
|
|
802
|
+
*
|
|
803
|
+
* @param sessionId Session id
|
|
804
|
+
* @param message The user message to queue
|
|
805
|
+
* @returns Queue position and message ID
|
|
806
|
+
* @throws Error if session doesn't support message queueing
|
|
807
|
+
*/
|
|
808
|
+
async queueMessage(sessionId, message) {
|
|
809
|
+
this.ensureStarted();
|
|
810
|
+
const session = await this.sessionManager.getSession(sessionId, false);
|
|
811
|
+
if (!session) {
|
|
812
|
+
throw SessionError.notFound(sessionId);
|
|
813
|
+
}
|
|
814
|
+
return session.queueMessage(message);
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Get all queued messages for a session.
|
|
818
|
+
* @param sessionId Session id
|
|
819
|
+
* @returns Array of queued messages
|
|
820
|
+
*/
|
|
821
|
+
async getQueuedMessages(sessionId) {
|
|
822
|
+
this.ensureStarted();
|
|
823
|
+
const session = await this.sessionManager.getSession(sessionId, false);
|
|
824
|
+
if (!session) {
|
|
825
|
+
throw SessionError.notFound(sessionId);
|
|
826
|
+
}
|
|
827
|
+
return session.getQueuedMessages();
|
|
828
|
+
}
|
|
829
|
+
/**
|
|
830
|
+
* Remove a queued message.
|
|
831
|
+
* @param sessionId Session id
|
|
832
|
+
* @param messageId The ID of the queued message to remove
|
|
833
|
+
* @returns true if message was found and removed, false otherwise
|
|
834
|
+
*/
|
|
835
|
+
async removeQueuedMessage(sessionId, messageId) {
|
|
836
|
+
this.ensureStarted();
|
|
837
|
+
const session = await this.sessionManager.getSession(sessionId, false);
|
|
838
|
+
if (!session) {
|
|
839
|
+
throw SessionError.notFound(sessionId);
|
|
840
|
+
}
|
|
841
|
+
return session.removeQueuedMessage(messageId);
|
|
842
|
+
}
|
|
843
|
+
/**
|
|
844
|
+
* Clear all queued messages for a session.
|
|
845
|
+
* @param sessionId Session id
|
|
846
|
+
* @returns Number of messages that were cleared
|
|
847
|
+
*/
|
|
848
|
+
async clearMessageQueue(sessionId) {
|
|
849
|
+
this.ensureStarted();
|
|
850
|
+
const session = await this.sessionManager.getSession(sessionId, false);
|
|
851
|
+
if (!session) {
|
|
852
|
+
throw SessionError.notFound(sessionId);
|
|
853
|
+
}
|
|
854
|
+
return session.clearMessageQueue();
|
|
855
|
+
}
|
|
708
856
|
/**
|
|
709
857
|
* Cancels the currently running turn for a session.
|
|
710
858
|
* Safe to call even if no run is in progress.
|
|
@@ -714,13 +862,20 @@ Either:
|
|
|
714
862
|
async cancel(sessionId) {
|
|
715
863
|
this.ensureStarted();
|
|
716
864
|
if (!sessionId || typeof sessionId !== "string") {
|
|
717
|
-
throw
|
|
865
|
+
throw AgentError.apiValidationError(
|
|
866
|
+
"sessionId is required and must be a non-empty string"
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
const streamController = this.activeStreamControllers.get(sessionId);
|
|
870
|
+
if (streamController) {
|
|
871
|
+
streamController.abort();
|
|
872
|
+
this.activeStreamControllers.delete(sessionId);
|
|
718
873
|
}
|
|
719
874
|
const existing = await this.sessionManager.getSession(sessionId, false);
|
|
720
875
|
if (existing) {
|
|
721
876
|
return existing.cancel();
|
|
722
877
|
}
|
|
723
|
-
return
|
|
878
|
+
return !!streamController;
|
|
724
879
|
}
|
|
725
880
|
// ============= SESSION MANAGEMENT =============
|
|
726
881
|
/**
|
|
@@ -827,7 +982,6 @@ Either:
|
|
|
827
982
|
const llmConfig = this.getEffectiveConfig(sessionId).llm;
|
|
828
983
|
const result = await generateSessionTitle(
|
|
829
984
|
llmConfig,
|
|
830
|
-
llmConfig.router,
|
|
831
985
|
this.toolManager,
|
|
832
986
|
this.systemPromptManager,
|
|
833
987
|
this.resourceManager,
|
|
@@ -910,7 +1064,9 @@ Either:
|
|
|
910
1064
|
async resetConversation(sessionId) {
|
|
911
1065
|
this.ensureStarted();
|
|
912
1066
|
if (!sessionId || typeof sessionId !== "string") {
|
|
913
|
-
throw
|
|
1067
|
+
throw AgentError.apiValidationError(
|
|
1068
|
+
"sessionId is required and must be a non-empty string"
|
|
1069
|
+
);
|
|
914
1070
|
}
|
|
915
1071
|
try {
|
|
916
1072
|
await this.sessionManager.resetSession(sessionId);
|
|
@@ -925,6 +1081,37 @@ Either:
|
|
|
925
1081
|
throw error;
|
|
926
1082
|
}
|
|
927
1083
|
}
|
|
1084
|
+
/**
|
|
1085
|
+
* Clears the context window for a session without deleting history.
|
|
1086
|
+
*
|
|
1087
|
+
* This adds a "context clear" marker to the conversation history. When the
|
|
1088
|
+
* context is loaded for LLM, messages before this marker are filtered out
|
|
1089
|
+
* (via filterCompacted). The full history remains in the database for
|
|
1090
|
+
* review via /resume or session history.
|
|
1091
|
+
*
|
|
1092
|
+
* Use this for /clear command - it preserves history but gives a fresh
|
|
1093
|
+
* context window to the LLM.
|
|
1094
|
+
*
|
|
1095
|
+
* @param sessionId Session ID (required)
|
|
1096
|
+
*/
|
|
1097
|
+
async clearContext(sessionId) {
|
|
1098
|
+
this.ensureStarted();
|
|
1099
|
+
if (!sessionId || typeof sessionId !== "string") {
|
|
1100
|
+
throw AgentError.apiValidationError(
|
|
1101
|
+
"sessionId is required and must be a non-empty string"
|
|
1102
|
+
);
|
|
1103
|
+
}
|
|
1104
|
+
const session = await this.sessionManager.getSession(sessionId);
|
|
1105
|
+
if (!session) {
|
|
1106
|
+
throw SessionError.notFound(sessionId);
|
|
1107
|
+
}
|
|
1108
|
+
const contextManager = session.getContextManager();
|
|
1109
|
+
await contextManager.clearContext();
|
|
1110
|
+
this.logger.info(`Context cleared for session: ${sessionId}`);
|
|
1111
|
+
this.agentEventBus.emit("context:cleared", {
|
|
1112
|
+
sessionId
|
|
1113
|
+
});
|
|
1114
|
+
}
|
|
928
1115
|
// ============= LLM MANAGEMENT =============
|
|
929
1116
|
/**
|
|
930
1117
|
* Gets the current LLM configuration with all defaults applied.
|
|
@@ -939,7 +1126,7 @@ Either:
|
|
|
939
1126
|
* This is a comprehensive method that handles ALL validation, configuration building, and switching internally.
|
|
940
1127
|
*
|
|
941
1128
|
* Design:
|
|
942
|
-
* - Input: Partial<LLMConfig> (allows optional fields like maxIterations
|
|
1129
|
+
* - Input: Partial<LLMConfig> (allows optional fields like maxIterations?)
|
|
943
1130
|
* - Output: LLMConfig (user-friendly type with all defaults applied)
|
|
944
1131
|
*
|
|
945
1132
|
* Key features:
|
|
@@ -964,8 +1151,8 @@ Either:
|
|
|
964
1151
|
* // Switch to a different provider with explicit API key
|
|
965
1152
|
* await agent.switchLLM({ provider: 'anthropic', model: 'claude-4-sonnet-20250514', apiKey: 'sk-ant-...' });
|
|
966
1153
|
*
|
|
967
|
-
* // Switch with
|
|
968
|
-
* await agent.switchLLM({ provider: 'anthropic', model: 'claude-4-sonnet-20250514'
|
|
1154
|
+
* // Switch with session options
|
|
1155
|
+
* await agent.switchLLM({ provider: 'anthropic', model: 'claude-4-sonnet-20250514' }, 'user-123');
|
|
969
1156
|
*
|
|
970
1157
|
* // Switch for all sessions
|
|
971
1158
|
* await agent.switchLLM({ model: 'gpt-5' }, '*');
|
|
@@ -982,7 +1169,11 @@ Either:
|
|
|
982
1169
|
}
|
|
983
1170
|
const validatedUpdates = parseResult.data;
|
|
984
1171
|
const currentLLMConfig = sessionId ? this.stateManager.getRuntimeConfig(sessionId).llm : this.stateManager.getRuntimeConfig().llm;
|
|
985
|
-
const result = resolveAndValidateLLMConfig(
|
|
1172
|
+
const result = await resolveAndValidateLLMConfig(
|
|
1173
|
+
currentLLMConfig,
|
|
1174
|
+
validatedUpdates,
|
|
1175
|
+
this.logger
|
|
1176
|
+
);
|
|
986
1177
|
const validatedConfig = ensureOk(result, this.logger);
|
|
987
1178
|
await this.performLLMSwitch(validatedConfig, sessionId);
|
|
988
1179
|
this.logger.info(
|
|
@@ -1117,19 +1308,23 @@ Either:
|
|
|
1117
1308
|
}
|
|
1118
1309
|
// ============= MCP SERVER MANAGEMENT =============
|
|
1119
1310
|
/**
|
|
1120
|
-
*
|
|
1311
|
+
* Adds a new MCP server to the runtime configuration and connects it if enabled.
|
|
1121
1312
|
* This method handles validation, state management, and establishing the connection.
|
|
1122
1313
|
*
|
|
1123
|
-
* @param name The name of the server to
|
|
1314
|
+
* @param name The name of the server to add.
|
|
1124
1315
|
* @param config The configuration object for the server.
|
|
1125
1316
|
* @throws DextoError if validation fails or connection fails
|
|
1126
1317
|
*/
|
|
1127
|
-
async
|
|
1318
|
+
async addMcpServer(name, config) {
|
|
1128
1319
|
this.ensureStarted();
|
|
1129
1320
|
const existingServerNames = Object.keys(this.stateManager.getRuntimeConfig().mcpServers);
|
|
1130
1321
|
const validation = resolveAndValidateMcpServerConfig(name, config, existingServerNames);
|
|
1131
1322
|
const validatedConfig = ensureOk(validation, this.logger);
|
|
1132
|
-
this.stateManager.
|
|
1323
|
+
this.stateManager.setMcpServer(name, validatedConfig);
|
|
1324
|
+
if (validatedConfig.enabled === false) {
|
|
1325
|
+
this.logger.info(`MCP server '${name}' added but not connected (disabled)`);
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1133
1328
|
try {
|
|
1134
1329
|
await this.mcpManager.connectServer(name, validatedConfig);
|
|
1135
1330
|
await this.toolManager.refresh();
|
|
@@ -1141,9 +1336,7 @@ Either:
|
|
|
1141
1336
|
tools: Object.keys(await this.toolManager.getAllTools()),
|
|
1142
1337
|
source: "mcp"
|
|
1143
1338
|
});
|
|
1144
|
-
this.logger.info(
|
|
1145
|
-
`DextoAgent: Successfully added and connected to MCP server '${name}'.`
|
|
1146
|
-
);
|
|
1339
|
+
this.logger.info(`MCP server '${name}' added and connected successfully`);
|
|
1147
1340
|
const warnings = validation.issues.filter((i) => i.severity === "warning");
|
|
1148
1341
|
if (warnings.length > 0) {
|
|
1149
1342
|
this.logger.warn(
|
|
@@ -1152,9 +1345,7 @@ Either:
|
|
|
1152
1345
|
}
|
|
1153
1346
|
} catch (error) {
|
|
1154
1347
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1155
|
-
this.logger.error(
|
|
1156
|
-
`DextoAgent: Failed to connect to MCP server '${name}': ${errorMessage}`
|
|
1157
|
-
);
|
|
1348
|
+
this.logger.error(`Failed to connect MCP server '${name}': ${errorMessage}`);
|
|
1158
1349
|
this.stateManager.removeMcpServer(name);
|
|
1159
1350
|
this.agentEventBus.emit("mcp:server-connected", {
|
|
1160
1351
|
name,
|
|
@@ -1165,14 +1356,81 @@ Either:
|
|
|
1165
1356
|
}
|
|
1166
1357
|
}
|
|
1167
1358
|
/**
|
|
1168
|
-
*
|
|
1359
|
+
* @deprecated Use `addMcpServer` instead. This method will be removed in a future version.
|
|
1360
|
+
*/
|
|
1361
|
+
async connectMcpServer(name, config) {
|
|
1362
|
+
return this.addMcpServer(name, config);
|
|
1363
|
+
}
|
|
1364
|
+
/**
|
|
1365
|
+
* Enables a disabled MCP server and connects it.
|
|
1366
|
+
* Updates the runtime state to enabled=true and establishes the connection.
|
|
1367
|
+
*
|
|
1368
|
+
* @param name The name of the server to enable.
|
|
1369
|
+
* @throws MCPError if server is not found or connection fails
|
|
1370
|
+
*/
|
|
1371
|
+
async enableMcpServer(name) {
|
|
1372
|
+
this.ensureStarted();
|
|
1373
|
+
const currentConfig = this.stateManager.getRuntimeConfig().mcpServers[name];
|
|
1374
|
+
if (!currentConfig) {
|
|
1375
|
+
throw MCPError.serverNotFound(name);
|
|
1376
|
+
}
|
|
1377
|
+
const updatedConfig = { ...currentConfig, enabled: true };
|
|
1378
|
+
this.stateManager.setMcpServer(name, updatedConfig);
|
|
1379
|
+
try {
|
|
1380
|
+
await this.mcpManager.connectServer(name, updatedConfig);
|
|
1381
|
+
await this.toolManager.refresh();
|
|
1382
|
+
this.agentEventBus.emit("mcp:server-connected", { name, success: true });
|
|
1383
|
+
this.logger.info(`MCP server '${name}' enabled and connected`);
|
|
1384
|
+
} catch (error) {
|
|
1385
|
+
this.stateManager.setMcpServer(name, currentConfig);
|
|
1386
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1387
|
+
this.logger.error(`Failed to enable MCP server '${name}': ${errorMessage}`);
|
|
1388
|
+
throw MCPError.connectionFailed(name, errorMessage);
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
/**
|
|
1392
|
+
* Disables an MCP server and disconnects it.
|
|
1393
|
+
* Updates the runtime state to enabled=false and closes the connection.
|
|
1394
|
+
*
|
|
1395
|
+
* @param name The name of the server to disable.
|
|
1396
|
+
* @throws MCPError if server is not found or disconnect fails
|
|
1397
|
+
*/
|
|
1398
|
+
async disableMcpServer(name) {
|
|
1399
|
+
this.ensureStarted();
|
|
1400
|
+
const currentConfig = this.stateManager.getRuntimeConfig().mcpServers[name];
|
|
1401
|
+
if (!currentConfig) {
|
|
1402
|
+
throw MCPError.serverNotFound(name);
|
|
1403
|
+
}
|
|
1404
|
+
const updatedConfig = { ...currentConfig, enabled: false };
|
|
1405
|
+
this.stateManager.setMcpServer(name, updatedConfig);
|
|
1406
|
+
try {
|
|
1407
|
+
await this.mcpManager.removeClient(name);
|
|
1408
|
+
await this.toolManager.refresh();
|
|
1409
|
+
this.logger.info(`MCP server '${name}' disabled and disconnected`);
|
|
1410
|
+
} catch (error) {
|
|
1411
|
+
this.stateManager.setMcpServer(name, currentConfig);
|
|
1412
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1413
|
+
this.logger.error(`Failed to disable MCP server '${name}': ${errorMessage}`);
|
|
1414
|
+
throw MCPError.disconnectionFailed(name, errorMessage);
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
/**
|
|
1418
|
+
* Removes and disconnects an MCP server completely.
|
|
1419
|
+
* Use this for deleting a server - removes from both runtime state and disconnects.
|
|
1169
1420
|
* @param name The name of the server to remove.
|
|
1421
|
+
* @throws MCPError if disconnection fails
|
|
1170
1422
|
*/
|
|
1171
1423
|
async removeMcpServer(name) {
|
|
1172
1424
|
this.ensureStarted();
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1425
|
+
try {
|
|
1426
|
+
await this.mcpManager.removeClient(name);
|
|
1427
|
+
this.stateManager.removeMcpServer(name);
|
|
1428
|
+
await this.toolManager.refresh();
|
|
1429
|
+
} catch (error) {
|
|
1430
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1431
|
+
this.logger.error(`Failed to remove MCP server '${name}': ${errorMessage}`);
|
|
1432
|
+
throw MCPError.disconnectionFailed(name, errorMessage);
|
|
1433
|
+
}
|
|
1176
1434
|
}
|
|
1177
1435
|
/**
|
|
1178
1436
|
* Restarts an MCP server by disconnecting and reconnecting with its original configuration.
|
|
@@ -1205,13 +1463,18 @@ Either:
|
|
|
1205
1463
|
/**
|
|
1206
1464
|
* Executes a tool from any source (MCP servers, custom tools, or internal tools).
|
|
1207
1465
|
* This is the unified interface for tool execution that can handle all tool types.
|
|
1466
|
+
*
|
|
1467
|
+
* Note: This is for direct/programmatic tool execution outside of LLM flow.
|
|
1468
|
+
* A toolCallId is generated automatically for tracking purposes.
|
|
1469
|
+
*
|
|
1208
1470
|
* @param toolName The name of the tool to execute
|
|
1209
1471
|
* @param args The arguments to pass to the tool
|
|
1210
1472
|
* @returns The result of the tool execution
|
|
1211
1473
|
*/
|
|
1212
1474
|
async executeTool(toolName, args) {
|
|
1213
1475
|
this.ensureStarted();
|
|
1214
|
-
|
|
1476
|
+
const toolCallId = `direct-${randomUUID()}`;
|
|
1477
|
+
return await this.toolManager.executeTool(toolName, args, toolCallId);
|
|
1215
1478
|
}
|
|
1216
1479
|
/**
|
|
1217
1480
|
* Gets all available tools from all connected MCP servers.
|
|
@@ -1222,6 +1485,15 @@ Either:
|
|
|
1222
1485
|
this.ensureStarted();
|
|
1223
1486
|
return await this.mcpManager.getAllTools();
|
|
1224
1487
|
}
|
|
1488
|
+
/**
|
|
1489
|
+
* Gets all MCP tools with their server metadata.
|
|
1490
|
+
* Returns tool cache entries which include server names for proper grouping.
|
|
1491
|
+
* @returns Map of tool names to cache entries with server info
|
|
1492
|
+
*/
|
|
1493
|
+
getAllMcpToolsWithServerInfo() {
|
|
1494
|
+
this.ensureStarted();
|
|
1495
|
+
return this.mcpManager.getAllToolsWithServerInfo();
|
|
1496
|
+
}
|
|
1225
1497
|
/**
|
|
1226
1498
|
* Gets all available tools from all sources (MCP servers and custom tools).
|
|
1227
1499
|
* This is the unified interface for tool discovery that includes both MCP and custom tools.
|
|
@@ -1249,6 +1521,79 @@ Either:
|
|
|
1249
1521
|
this.ensureStarted();
|
|
1250
1522
|
return this.mcpManager.getFailedConnections();
|
|
1251
1523
|
}
|
|
1524
|
+
/**
|
|
1525
|
+
* Gets the connection status of a single MCP server.
|
|
1526
|
+
* @param name The server name
|
|
1527
|
+
* @returns The connection status, or undefined if server not configured
|
|
1528
|
+
*
|
|
1529
|
+
* TODO: Move to MCPManager once it has access to server configs (enabled state).
|
|
1530
|
+
* Currently here because MCPManager only tracks connections, not config.
|
|
1531
|
+
*/
|
|
1532
|
+
getMcpServerStatus(name) {
|
|
1533
|
+
this.ensureStarted();
|
|
1534
|
+
const config = this.stateManager.getRuntimeConfig();
|
|
1535
|
+
const serverConfig = config.mcpServers[name];
|
|
1536
|
+
if (!serverConfig) return void 0;
|
|
1537
|
+
const enabled = serverConfig.enabled !== false;
|
|
1538
|
+
const connectedClients = this.mcpManager.getClients();
|
|
1539
|
+
const failedConnections = this.mcpManager.getFailedConnections();
|
|
1540
|
+
let status;
|
|
1541
|
+
if (!enabled) {
|
|
1542
|
+
status = "disconnected";
|
|
1543
|
+
} else if (connectedClients.has(name)) {
|
|
1544
|
+
status = "connected";
|
|
1545
|
+
} else {
|
|
1546
|
+
status = "error";
|
|
1547
|
+
}
|
|
1548
|
+
const result = {
|
|
1549
|
+
name,
|
|
1550
|
+
type: serverConfig.type,
|
|
1551
|
+
enabled,
|
|
1552
|
+
status
|
|
1553
|
+
};
|
|
1554
|
+
if (failedConnections[name]) {
|
|
1555
|
+
result.error = failedConnections[name];
|
|
1556
|
+
}
|
|
1557
|
+
return result;
|
|
1558
|
+
}
|
|
1559
|
+
/**
|
|
1560
|
+
* Gets all configured MCP servers with their connection status.
|
|
1561
|
+
* Centralizes the status computation logic used by CLI, server, and webui.
|
|
1562
|
+
* @returns Array of server info with computed status
|
|
1563
|
+
*
|
|
1564
|
+
* TODO: Move to MCPManager once it has access to server configs (enabled state).
|
|
1565
|
+
* Currently here because MCPManager only tracks connections, not config.
|
|
1566
|
+
*/
|
|
1567
|
+
getMcpServersWithStatus() {
|
|
1568
|
+
this.ensureStarted();
|
|
1569
|
+
const config = this.stateManager.getRuntimeConfig();
|
|
1570
|
+
const mcpServers = config.mcpServers || {};
|
|
1571
|
+
const connectedClients = this.mcpManager.getClients();
|
|
1572
|
+
const failedConnections = this.mcpManager.getFailedConnections();
|
|
1573
|
+
const servers = [];
|
|
1574
|
+
for (const [name, serverConfig] of Object.entries(mcpServers)) {
|
|
1575
|
+
const enabled = serverConfig.enabled !== false;
|
|
1576
|
+
let status;
|
|
1577
|
+
if (!enabled) {
|
|
1578
|
+
status = "disconnected";
|
|
1579
|
+
} else if (connectedClients.has(name)) {
|
|
1580
|
+
status = "connected";
|
|
1581
|
+
} else {
|
|
1582
|
+
status = "error";
|
|
1583
|
+
}
|
|
1584
|
+
const server = {
|
|
1585
|
+
name,
|
|
1586
|
+
type: serverConfig.type,
|
|
1587
|
+
enabled,
|
|
1588
|
+
status
|
|
1589
|
+
};
|
|
1590
|
+
if (failedConnections[name]) {
|
|
1591
|
+
server.error = failedConnections[name];
|
|
1592
|
+
}
|
|
1593
|
+
servers.push(server);
|
|
1594
|
+
}
|
|
1595
|
+
return servers;
|
|
1596
|
+
}
|
|
1252
1597
|
// ============= RESOURCE MANAGEMENT =============
|
|
1253
1598
|
/**
|
|
1254
1599
|
* Lists all available resources with their info.
|
|
@@ -1344,6 +1689,21 @@ Either:
|
|
|
1344
1689
|
this.ensureStarted();
|
|
1345
1690
|
return await this.promptManager.has(name);
|
|
1346
1691
|
}
|
|
1692
|
+
/**
|
|
1693
|
+
* Refreshes the prompts cache, reloading from all providers.
|
|
1694
|
+
* Call this after adding/deleting prompts to make them immediately available.
|
|
1695
|
+
*
|
|
1696
|
+
* @param newPrompts Optional - if provided, updates the config prompts before refreshing.
|
|
1697
|
+
* Use this when you've modified the agent config file and need to
|
|
1698
|
+
* update both the runtime config and refresh the cache.
|
|
1699
|
+
*/
|
|
1700
|
+
async refreshPrompts(newPrompts) {
|
|
1701
|
+
this.ensureStarted();
|
|
1702
|
+
if (newPrompts) {
|
|
1703
|
+
this.promptManager.updateConfigPrompts(newPrompts);
|
|
1704
|
+
}
|
|
1705
|
+
await this.promptManager.refresh();
|
|
1706
|
+
}
|
|
1347
1707
|
/**
|
|
1348
1708
|
* Gets a prompt with its messages.
|
|
1349
1709
|
* @param name The name of the prompt
|