@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
|
@@ -0,0 +1,780 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
9
|
+
var __typeError = (msg) => {
|
|
10
|
+
throw TypeError(msg);
|
|
11
|
+
};
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
+
mod
|
|
31
|
+
));
|
|
32
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
+
var __using = (stack, value, async) => {
|
|
34
|
+
if (value != null) {
|
|
35
|
+
if (typeof value !== "object" && typeof value !== "function") __typeError("Object expected");
|
|
36
|
+
var dispose, inner;
|
|
37
|
+
if (async) dispose = value[__knownSymbol("asyncDispose")];
|
|
38
|
+
if (dispose === void 0) {
|
|
39
|
+
dispose = value[__knownSymbol("dispose")];
|
|
40
|
+
if (async) inner = dispose;
|
|
41
|
+
}
|
|
42
|
+
if (typeof dispose !== "function") __typeError("Object not disposable");
|
|
43
|
+
if (inner) dispose = function() {
|
|
44
|
+
try {
|
|
45
|
+
inner.call(this);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
return Promise.reject(e);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
stack.push([async, dispose, value]);
|
|
51
|
+
} else if (async) {
|
|
52
|
+
stack.push([async]);
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
};
|
|
56
|
+
var __callDispose = (stack, error, hasError) => {
|
|
57
|
+
var E = typeof SuppressedError === "function" ? SuppressedError : function(e, s, m, _) {
|
|
58
|
+
return _ = Error(m), _.name = "SuppressedError", _.error = e, _.suppressed = s, _;
|
|
59
|
+
};
|
|
60
|
+
var fail = (e) => error = hasError ? new E(e, error, "An error was suppressed during disposal") : (hasError = true, e);
|
|
61
|
+
var next = (it) => {
|
|
62
|
+
while (it = stack.pop()) {
|
|
63
|
+
try {
|
|
64
|
+
var result = it[1] && it[1].call(it[2]);
|
|
65
|
+
if (it[0]) return Promise.resolve(result).then(next, (e) => (fail(e), next()));
|
|
66
|
+
} catch (e) {
|
|
67
|
+
fail(e);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (hasError) throw error;
|
|
71
|
+
};
|
|
72
|
+
return next();
|
|
73
|
+
};
|
|
74
|
+
var turn_executor_exports = {};
|
|
75
|
+
__export(turn_executor_exports, {
|
|
76
|
+
TurnExecutor: () => TurnExecutor
|
|
77
|
+
});
|
|
78
|
+
module.exports = __toCommonJS(turn_executor_exports);
|
|
79
|
+
var import_ai = require("ai");
|
|
80
|
+
var import_api = require("@opentelemetry/api");
|
|
81
|
+
var import_stream_processor = require("./stream-processor.js");
|
|
82
|
+
var import_types4 = require("../../logger/v2/types.js");
|
|
83
|
+
var import_defer = require("../../utils/defer.js");
|
|
84
|
+
var import_DextoRuntimeError = require("../../errors/DextoRuntimeError.js");
|
|
85
|
+
var import_types7 = require("../../errors/types.js");
|
|
86
|
+
var import_error_codes = require("../error-codes.js");
|
|
87
|
+
var import_error_conversion = require("../../utils/error-conversion.js");
|
|
88
|
+
var import_overflow = require("../../context/compaction/overflow.js");
|
|
89
|
+
var import_reactive_overflow = require("../../context/compaction/strategies/reactive-overflow.js");
|
|
90
|
+
const toolSupportCache = /* @__PURE__ */ new Map();
|
|
91
|
+
const LOCAL_PROVIDERS = ["ollama", "local"];
|
|
92
|
+
class TurnExecutor {
|
|
93
|
+
constructor(model, toolManager, contextManager, eventBus, resourceManager, sessionId, config, llmContext, logger, messageQueue, modelLimits, externalSignal, compactionStrategy) {
|
|
94
|
+
this.model = model;
|
|
95
|
+
this.toolManager = toolManager;
|
|
96
|
+
this.contextManager = contextManager;
|
|
97
|
+
this.eventBus = eventBus;
|
|
98
|
+
this.resourceManager = resourceManager;
|
|
99
|
+
this.sessionId = sessionId;
|
|
100
|
+
this.config = config;
|
|
101
|
+
this.llmContext = llmContext;
|
|
102
|
+
this.messageQueue = messageQueue;
|
|
103
|
+
this.modelLimits = modelLimits;
|
|
104
|
+
this.externalSignal = externalSignal;
|
|
105
|
+
this.logger = logger.createChild(import_types4.DextoLogComponent.EXECUTOR);
|
|
106
|
+
this.stepAbortController = new AbortController();
|
|
107
|
+
if (compactionStrategy !== void 0) {
|
|
108
|
+
this.compactionStrategy = compactionStrategy;
|
|
109
|
+
} else if (modelLimits) {
|
|
110
|
+
this.compactionStrategy = new import_reactive_overflow.ReactiveOverflowStrategy(model, {}, this.logger);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
logger;
|
|
114
|
+
/**
|
|
115
|
+
* Per-step abort controller. Created fresh for each iteration of the loop.
|
|
116
|
+
* This allows soft cancel (abort current step) while still continuing with queued messages.
|
|
117
|
+
*/
|
|
118
|
+
stepAbortController;
|
|
119
|
+
compactionStrategy = null;
|
|
120
|
+
/**
|
|
121
|
+
* Map to track approval metadata by toolCallId.
|
|
122
|
+
* Used to pass approval info from tool execution to result persistence.
|
|
123
|
+
*/
|
|
124
|
+
approvalMetadata = /* @__PURE__ */ new Map();
|
|
125
|
+
/**
|
|
126
|
+
* Get StreamProcessor config from TurnExecutor state.
|
|
127
|
+
*/
|
|
128
|
+
getStreamProcessorConfig() {
|
|
129
|
+
return {
|
|
130
|
+
provider: this.llmContext.provider,
|
|
131
|
+
model: this.llmContext.model
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Main agent execution loop.
|
|
136
|
+
* Uses stopWhen: stepCountIs(1) to regain control after each step.
|
|
137
|
+
*
|
|
138
|
+
* @param contributorContext Context for system prompt contributors
|
|
139
|
+
* @param streaming If true, emits llm:chunk events during streaming. Default true.
|
|
140
|
+
*/
|
|
141
|
+
async execute(contributorContext, streaming = true) {
|
|
142
|
+
var _stack = [];
|
|
143
|
+
try {
|
|
144
|
+
const _ = __using(_stack, (0, import_defer.defer)(() => this.cleanup()));
|
|
145
|
+
const startTime = Date.now();
|
|
146
|
+
let stepCount = 0;
|
|
147
|
+
let lastStepTokens = null;
|
|
148
|
+
let lastFinishReason = "unknown";
|
|
149
|
+
let lastText = "";
|
|
150
|
+
this.eventBus.emit("llm:thinking");
|
|
151
|
+
const supportsTools = await this.validateToolSupport();
|
|
152
|
+
if (!supportsTools) {
|
|
153
|
+
const modelKey = `${this.llmContext.provider}:${this.llmContext.model}`;
|
|
154
|
+
this.eventBus.emit("llm:unsupported-input", {
|
|
155
|
+
errors: [
|
|
156
|
+
`Model '${modelKey}' does not support tool calling.`,
|
|
157
|
+
"You can still chat, but the model will not be able to use tools or execute commands."
|
|
158
|
+
],
|
|
159
|
+
provider: this.llmContext.provider,
|
|
160
|
+
model: this.llmContext.model,
|
|
161
|
+
details: {
|
|
162
|
+
feature: "tool-calling",
|
|
163
|
+
supported: false
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
this.logger.warn(
|
|
167
|
+
`Model ${modelKey} does not support tools - continuing without tool calling`
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
let currentAbortHandler = null;
|
|
171
|
+
try {
|
|
172
|
+
while (true) {
|
|
173
|
+
if (currentAbortHandler && this.externalSignal) {
|
|
174
|
+
this.externalSignal.removeEventListener("abort", currentAbortHandler);
|
|
175
|
+
}
|
|
176
|
+
this.stepAbortController = new AbortController();
|
|
177
|
+
currentAbortHandler = () => this.stepAbortController.abort();
|
|
178
|
+
if (this.externalSignal && !this.externalSignal.aborted) {
|
|
179
|
+
this.externalSignal.addEventListener("abort", currentAbortHandler, {
|
|
180
|
+
once: true
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
const coalesced = this.messageQueue.dequeueAll();
|
|
184
|
+
if (coalesced) {
|
|
185
|
+
await this.injectQueuedMessages(coalesced);
|
|
186
|
+
}
|
|
187
|
+
if (lastStepTokens && this.checkAndHandleOverflow(lastStepTokens)) {
|
|
188
|
+
await this.compress(lastStepTokens.inputTokens ?? 0);
|
|
189
|
+
}
|
|
190
|
+
const prepared = await this.contextManager.getFormattedMessagesWithCompression(
|
|
191
|
+
contributorContext,
|
|
192
|
+
this.llmContext
|
|
193
|
+
);
|
|
194
|
+
this.logger.debug(`Step ${stepCount}: Starting`);
|
|
195
|
+
const tools = supportsTools ? await this.createTools() : {};
|
|
196
|
+
const streamProcessor = new import_stream_processor.StreamProcessor(
|
|
197
|
+
this.contextManager,
|
|
198
|
+
this.eventBus,
|
|
199
|
+
this.resourceManager,
|
|
200
|
+
this.stepAbortController.signal,
|
|
201
|
+
this.getStreamProcessorConfig(),
|
|
202
|
+
this.logger,
|
|
203
|
+
streaming,
|
|
204
|
+
this.approvalMetadata
|
|
205
|
+
);
|
|
206
|
+
const result = await streamProcessor.process(
|
|
207
|
+
() => (0, import_ai.streamText)({
|
|
208
|
+
model: this.model,
|
|
209
|
+
stopWhen: (0, import_ai.stepCountIs)(1),
|
|
210
|
+
tools,
|
|
211
|
+
abortSignal: this.stepAbortController.signal,
|
|
212
|
+
messages: prepared.formattedMessages,
|
|
213
|
+
...this.config.maxOutputTokens !== void 0 && {
|
|
214
|
+
maxOutputTokens: this.config.maxOutputTokens
|
|
215
|
+
},
|
|
216
|
+
...this.config.temperature !== void 0 && {
|
|
217
|
+
temperature: this.config.temperature
|
|
218
|
+
},
|
|
219
|
+
// Log stream-level errors (tool errors, API errors during streaming)
|
|
220
|
+
onError: (error) => {
|
|
221
|
+
this.logger.error("Stream error", { error });
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
);
|
|
225
|
+
lastStepTokens = result.usage;
|
|
226
|
+
lastFinishReason = result.finishReason;
|
|
227
|
+
lastText = result.text;
|
|
228
|
+
this.logger.debug(
|
|
229
|
+
`Step ${stepCount}: Finished with reason="${result.finishReason}", tokens=${JSON.stringify(result.usage)}`
|
|
230
|
+
);
|
|
231
|
+
if (result.finishReason !== "tool-calls") {
|
|
232
|
+
const queuedOnTerminate = this.messageQueue.dequeueAll();
|
|
233
|
+
if (queuedOnTerminate) {
|
|
234
|
+
this.logger.debug(
|
|
235
|
+
`Continuing: ${queuedOnTerminate.messages.length} queued message(s) to process`
|
|
236
|
+
);
|
|
237
|
+
await this.injectQueuedMessages(queuedOnTerminate);
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
this.logger.debug(`Terminating: finishReason is "${result.finishReason}"`);
|
|
241
|
+
break;
|
|
242
|
+
}
|
|
243
|
+
if (this.externalSignal?.aborted && !this.messageQueue.hasPending()) {
|
|
244
|
+
this.logger.debug("Terminating: hard cancel - external abort signal received");
|
|
245
|
+
lastFinishReason = "cancelled";
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
if (++stepCount >= this.config.maxSteps) {
|
|
249
|
+
this.logger.debug(`Terminating: reached maxSteps (${this.config.maxSteps})`);
|
|
250
|
+
lastFinishReason = "max-steps";
|
|
251
|
+
break;
|
|
252
|
+
}
|
|
253
|
+
await this.pruneOldToolOutputs();
|
|
254
|
+
}
|
|
255
|
+
} catch (error) {
|
|
256
|
+
const mappedError = this.mapProviderError(error);
|
|
257
|
+
this.logger.error("TurnExecutor failed", { error: mappedError });
|
|
258
|
+
this.eventBus.emit("llm:error", {
|
|
259
|
+
error: mappedError,
|
|
260
|
+
context: "TurnExecutor",
|
|
261
|
+
recoverable: false
|
|
262
|
+
});
|
|
263
|
+
await this.contextManager.flush();
|
|
264
|
+
this.eventBus.emit("run:complete", {
|
|
265
|
+
finishReason: "error",
|
|
266
|
+
stepCount,
|
|
267
|
+
durationMs: Date.now() - startTime,
|
|
268
|
+
error: mappedError
|
|
269
|
+
});
|
|
270
|
+
throw mappedError;
|
|
271
|
+
}
|
|
272
|
+
await this.contextManager.flush();
|
|
273
|
+
this.setTelemetryAttributes(lastStepTokens);
|
|
274
|
+
this.eventBus.emit("run:complete", {
|
|
275
|
+
finishReason: lastFinishReason,
|
|
276
|
+
stepCount,
|
|
277
|
+
durationMs: Date.now() - startTime
|
|
278
|
+
});
|
|
279
|
+
return {
|
|
280
|
+
text: lastText,
|
|
281
|
+
stepCount,
|
|
282
|
+
usage: lastStepTokens,
|
|
283
|
+
finishReason: lastFinishReason
|
|
284
|
+
};
|
|
285
|
+
} catch (_2) {
|
|
286
|
+
var _error = _2, _hasError = true;
|
|
287
|
+
} finally {
|
|
288
|
+
__callDispose(_stack, _error, _hasError);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Abort the current step execution.
|
|
293
|
+
* Note: For full run cancellation, use the external abort signal.
|
|
294
|
+
*/
|
|
295
|
+
abort() {
|
|
296
|
+
this.stepAbortController.abort();
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Inject coalesced queued messages into the context as a single user message.
|
|
300
|
+
* This enables mid-task user guidance.
|
|
301
|
+
*/
|
|
302
|
+
async injectQueuedMessages(coalesced) {
|
|
303
|
+
await this.contextManager.addMessage({
|
|
304
|
+
role: "user",
|
|
305
|
+
content: coalesced.combinedContent,
|
|
306
|
+
metadata: {
|
|
307
|
+
coalesced: coalesced.messages.length > 1,
|
|
308
|
+
messageCount: coalesced.messages.length,
|
|
309
|
+
originalMessageIds: coalesced.messages.map((m) => m.id)
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
this.logger.info(`Injected ${coalesced.messages.length} queued message(s) into context`, {
|
|
313
|
+
count: coalesced.messages.length,
|
|
314
|
+
firstQueued: coalesced.firstQueuedAt,
|
|
315
|
+
lastQueued: coalesced.lastQueuedAt
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Validates if the current model supports tools.
|
|
320
|
+
* Uses a static cache to avoid repeated validation calls.
|
|
321
|
+
*
|
|
322
|
+
* For local providers (Ollama, local) and custom baseURL endpoints, makes a test call to verify tool support.
|
|
323
|
+
* Known cloud providers without baseURL are assumed to support tools.
|
|
324
|
+
*/
|
|
325
|
+
async validateToolSupport() {
|
|
326
|
+
const modelKey = `${this.llmContext.provider}:${this.llmContext.model}:${this.config.baseURL ?? ""}`;
|
|
327
|
+
if (toolSupportCache.has(modelKey)) {
|
|
328
|
+
return toolSupportCache.get(modelKey);
|
|
329
|
+
}
|
|
330
|
+
const isLocalProvider = LOCAL_PROVIDERS.includes(this.llmContext.provider);
|
|
331
|
+
if (!this.config.baseURL && !isLocalProvider) {
|
|
332
|
+
this.logger.debug(
|
|
333
|
+
`Skipping tool validation for ${modelKey} - known cloud provider without custom baseURL`
|
|
334
|
+
);
|
|
335
|
+
toolSupportCache.set(modelKey, true);
|
|
336
|
+
return true;
|
|
337
|
+
}
|
|
338
|
+
this.logger.debug(
|
|
339
|
+
`Testing tool support for ${isLocalProvider ? "local provider" : "custom endpoint"} model: ${modelKey}`
|
|
340
|
+
);
|
|
341
|
+
const testTool = {
|
|
342
|
+
test_tool: {
|
|
343
|
+
inputSchema: (0, import_ai.jsonSchema)({
|
|
344
|
+
type: "object",
|
|
345
|
+
properties: {},
|
|
346
|
+
additionalProperties: false
|
|
347
|
+
}),
|
|
348
|
+
execute: async () => ({ result: "test" })
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
const testAbort = new AbortController();
|
|
352
|
+
const testTimeout = setTimeout(() => testAbort.abort(), 5e3);
|
|
353
|
+
try {
|
|
354
|
+
await (0, import_ai.generateText)({
|
|
355
|
+
model: this.model,
|
|
356
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
357
|
+
tools: testTool,
|
|
358
|
+
stopWhen: (0, import_ai.stepCountIs)(1),
|
|
359
|
+
abortSignal: testAbort.signal
|
|
360
|
+
});
|
|
361
|
+
clearTimeout(testTimeout);
|
|
362
|
+
toolSupportCache.set(modelKey, true);
|
|
363
|
+
this.logger.debug(`Model ${modelKey} supports tools`);
|
|
364
|
+
return true;
|
|
365
|
+
} catch (error) {
|
|
366
|
+
clearTimeout(testTimeout);
|
|
367
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
368
|
+
if (errorMessage.includes("does not support tools")) {
|
|
369
|
+
toolSupportCache.set(modelKey, false);
|
|
370
|
+
this.logger.debug(
|
|
371
|
+
`Detected that model ${modelKey} does not support tool calling - tool functionality will be disabled`
|
|
372
|
+
);
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
this.logger.debug(
|
|
376
|
+
`Tool validation error for ${modelKey}, assuming supported: ${errorMessage}`
|
|
377
|
+
);
|
|
378
|
+
toolSupportCache.set(modelKey, true);
|
|
379
|
+
return true;
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Creates tools with execute callbacks and toModelOutput.
|
|
384
|
+
*
|
|
385
|
+
* Key design decisions:
|
|
386
|
+
* - execute() returns raw result with inline images (async)
|
|
387
|
+
* - toModelOutput() formats for LLM consumption (sync)
|
|
388
|
+
* - StreamProcessor handles persistence via tool-result events
|
|
389
|
+
*/
|
|
390
|
+
async createTools() {
|
|
391
|
+
const tools = await this.toolManager.getAllTools();
|
|
392
|
+
return Object.fromEntries(
|
|
393
|
+
Object.entries(tools).map(([name, tool]) => [
|
|
394
|
+
name,
|
|
395
|
+
{
|
|
396
|
+
inputSchema: (0, import_ai.jsonSchema)(tool.parameters),
|
|
397
|
+
...tool.description && { description: tool.description },
|
|
398
|
+
/**
|
|
399
|
+
* Execute callback - runs the tool and returns raw result.
|
|
400
|
+
* Does NOT persist - StreamProcessor handles that on tool-result event.
|
|
401
|
+
*
|
|
402
|
+
* Uses Promise.race to ensure we return quickly on abort, even if the
|
|
403
|
+
* underlying tool (especially MCP tools we don't control) keeps running.
|
|
404
|
+
*/
|
|
405
|
+
execute: async (args, options) => {
|
|
406
|
+
this.logger.debug(
|
|
407
|
+
`Executing tool: ${name} (toolCallId: ${options.toolCallId})`
|
|
408
|
+
);
|
|
409
|
+
const abortSignal = this.stepAbortController.signal;
|
|
410
|
+
if (abortSignal.aborted) {
|
|
411
|
+
this.logger.debug(`Tool ${name} cancelled before execution`);
|
|
412
|
+
return { error: "Cancelled by user", cancelled: true };
|
|
413
|
+
}
|
|
414
|
+
let abortHandler = null;
|
|
415
|
+
const abortPromise = new Promise(
|
|
416
|
+
(resolve) => {
|
|
417
|
+
abortHandler = () => {
|
|
418
|
+
this.logger.debug(`Tool ${name} cancelled during execution`);
|
|
419
|
+
resolve({ error: "Cancelled by user", cancelled: true });
|
|
420
|
+
};
|
|
421
|
+
abortSignal.addEventListener("abort", abortHandler, { once: true });
|
|
422
|
+
}
|
|
423
|
+
);
|
|
424
|
+
try {
|
|
425
|
+
const result = await Promise.race([
|
|
426
|
+
(async () => {
|
|
427
|
+
const executionResult = await this.toolManager.executeTool(
|
|
428
|
+
name,
|
|
429
|
+
args,
|
|
430
|
+
options.toolCallId,
|
|
431
|
+
this.sessionId,
|
|
432
|
+
abortSignal
|
|
433
|
+
);
|
|
434
|
+
if (executionResult.requireApproval !== void 0) {
|
|
435
|
+
const metadata = {
|
|
436
|
+
requireApproval: executionResult.requireApproval
|
|
437
|
+
};
|
|
438
|
+
if (executionResult.approvalStatus !== void 0) {
|
|
439
|
+
metadata.approvalStatus = executionResult.approvalStatus;
|
|
440
|
+
}
|
|
441
|
+
this.approvalMetadata.set(options.toolCallId, metadata);
|
|
442
|
+
}
|
|
443
|
+
return executionResult.result;
|
|
444
|
+
})(),
|
|
445
|
+
abortPromise
|
|
446
|
+
]);
|
|
447
|
+
return result;
|
|
448
|
+
} finally {
|
|
449
|
+
if (abortHandler) {
|
|
450
|
+
abortSignal.removeEventListener("abort", abortHandler);
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
/**
|
|
455
|
+
* toModelOutput - formats raw result for LLM consumption.
|
|
456
|
+
* Called by Vercel SDK when preparing messages for next LLM call.
|
|
457
|
+
* SYNC - images are already inline in the raw result.
|
|
458
|
+
*/
|
|
459
|
+
toModelOutput: (result) => {
|
|
460
|
+
return this.formatToolResultForLLM(result, name);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
])
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Format tool result for LLM consumption.
|
|
468
|
+
* Handles multimodal content (text + images).
|
|
469
|
+
*
|
|
470
|
+
* This handles RAW tool results - the structure may vary.
|
|
471
|
+
*/
|
|
472
|
+
formatToolResultForLLM(result, toolName) {
|
|
473
|
+
if (result && typeof result === "object" && "error" in result) {
|
|
474
|
+
const errorResult = result;
|
|
475
|
+
let errorFlags = "";
|
|
476
|
+
if (errorResult.denied) errorFlags += " (denied)";
|
|
477
|
+
if (errorResult.timeout) errorFlags += " (timeout)";
|
|
478
|
+
return {
|
|
479
|
+
type: "text",
|
|
480
|
+
value: `Tool ${toolName} failed${errorFlags}: ${errorResult.error}`
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
if (this.hasMultimodalContent(result)) {
|
|
484
|
+
const contentArray = result.content;
|
|
485
|
+
const contentValue = [];
|
|
486
|
+
for (const part of contentArray) {
|
|
487
|
+
if (part.type === "text" && typeof part.text === "string") {
|
|
488
|
+
contentValue.push({ type: "text", text: part.text });
|
|
489
|
+
} else if (part.type === "image") {
|
|
490
|
+
const imageData = this.extractImageData(part);
|
|
491
|
+
if (imageData) {
|
|
492
|
+
contentValue.push({
|
|
493
|
+
type: "media",
|
|
494
|
+
data: imageData,
|
|
495
|
+
mediaType: part.mimeType || "image/jpeg"
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
} else if (part.type === "file") {
|
|
499
|
+
const fileData = this.extractFileData(part);
|
|
500
|
+
if (fileData) {
|
|
501
|
+
contentValue.push({
|
|
502
|
+
type: "media",
|
|
503
|
+
data: fileData,
|
|
504
|
+
mediaType: part.mimeType || "application/octet-stream"
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
if (contentValue.length > 0 && contentValue.some((v) => v.type === "media")) {
|
|
510
|
+
return { type: "content", value: contentValue };
|
|
511
|
+
}
|
|
512
|
+
const textParts = contentArray.filter((p) => p.type === "text" && typeof p.text === "string").map((p) => p.text);
|
|
513
|
+
return {
|
|
514
|
+
type: "text",
|
|
515
|
+
value: textParts.join("\n") || "[empty result]"
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
if (typeof result === "string") {
|
|
519
|
+
return { type: "text", value: result };
|
|
520
|
+
}
|
|
521
|
+
return {
|
|
522
|
+
type: "text",
|
|
523
|
+
value: typeof result === "object" && result !== null ? JSON.stringify(result) : String(result)
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Extract image data from a part, handling various formats.
|
|
528
|
+
*/
|
|
529
|
+
extractImageData(part) {
|
|
530
|
+
if (typeof part.image === "string") {
|
|
531
|
+
return part.image;
|
|
532
|
+
}
|
|
533
|
+
if (typeof part.data === "string") {
|
|
534
|
+
return part.data;
|
|
535
|
+
}
|
|
536
|
+
if (part.image instanceof Buffer) {
|
|
537
|
+
return part.image.toString("base64");
|
|
538
|
+
}
|
|
539
|
+
if (part.data instanceof Buffer) {
|
|
540
|
+
return part.data.toString("base64");
|
|
541
|
+
}
|
|
542
|
+
if (part.image instanceof ArrayBuffer) {
|
|
543
|
+
return Buffer.from(new Uint8Array(part.image)).toString("base64");
|
|
544
|
+
}
|
|
545
|
+
if (part.data instanceof ArrayBuffer) {
|
|
546
|
+
return Buffer.from(new Uint8Array(part.data)).toString("base64");
|
|
547
|
+
}
|
|
548
|
+
return null;
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Extract file data from a part.
|
|
552
|
+
*/
|
|
553
|
+
extractFileData(part) {
|
|
554
|
+
if (typeof part.data === "string") {
|
|
555
|
+
return part.data;
|
|
556
|
+
}
|
|
557
|
+
if (part.data instanceof Buffer) {
|
|
558
|
+
return part.data.toString("base64");
|
|
559
|
+
}
|
|
560
|
+
if (part.data instanceof ArrayBuffer) {
|
|
561
|
+
return Buffer.from(new Uint8Array(part.data)).toString("base64");
|
|
562
|
+
}
|
|
563
|
+
return null;
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Check if result has multimodal content array
|
|
567
|
+
*/
|
|
568
|
+
hasMultimodalContent(result) {
|
|
569
|
+
return result !== null && typeof result === "object" && "content" in result && Array.isArray(result.content);
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Constants for pruning thresholds
|
|
573
|
+
*/
|
|
574
|
+
static PRUNE_PROTECT = 4e4;
|
|
575
|
+
// Keep last 40K tokens of tool outputs
|
|
576
|
+
static PRUNE_MINIMUM = 2e4;
|
|
577
|
+
// Only prune if we can save 20K+
|
|
578
|
+
/**
|
|
579
|
+
* Prunes old tool outputs by marking them with compactedAt timestamp.
|
|
580
|
+
* Does NOT modify content - transformation happens at format time in
|
|
581
|
+
* ContextManager.getFormattedMessagesWithCompression().
|
|
582
|
+
*
|
|
583
|
+
* Algorithm:
|
|
584
|
+
* 1. Go backwards through history (most recent first)
|
|
585
|
+
* 2. Stop at summary message (only process post-summary messages)
|
|
586
|
+
* 3. Count tool message tokens
|
|
587
|
+
* 4. If total exceeds PRUNE_PROTECT, mark older ones for pruning
|
|
588
|
+
* 5. Only prune if savings exceed PRUNE_MINIMUM
|
|
589
|
+
*/
|
|
590
|
+
async pruneOldToolOutputs() {
|
|
591
|
+
const history = await this.contextManager.getHistory();
|
|
592
|
+
let totalToolTokens = 0;
|
|
593
|
+
let prunedTokens = 0;
|
|
594
|
+
const toPrune = [];
|
|
595
|
+
for (let i = history.length - 1; i >= 0; i--) {
|
|
596
|
+
const msg = history[i];
|
|
597
|
+
if (!msg) continue;
|
|
598
|
+
if (msg.metadata?.isSummary === true) break;
|
|
599
|
+
if (msg.role !== "tool") continue;
|
|
600
|
+
if (msg.compactedAt) continue;
|
|
601
|
+
if (!Array.isArray(msg.content)) continue;
|
|
602
|
+
const tokens = this.estimateToolTokens(msg.content);
|
|
603
|
+
totalToolTokens += tokens;
|
|
604
|
+
if (totalToolTokens > TurnExecutor.PRUNE_PROTECT && msg.id) {
|
|
605
|
+
prunedTokens += tokens;
|
|
606
|
+
toPrune.push(msg.id);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
if (prunedTokens > TurnExecutor.PRUNE_MINIMUM && toPrune.length > 0) {
|
|
610
|
+
const markedCount = await this.contextManager.markMessagesAsCompacted(toPrune);
|
|
611
|
+
this.eventBus.emit("context:pruned", {
|
|
612
|
+
prunedCount: markedCount,
|
|
613
|
+
savedTokens: prunedTokens
|
|
614
|
+
});
|
|
615
|
+
this.logger.debug(`Pruned ${markedCount} tool outputs, saving ~${prunedTokens} tokens`);
|
|
616
|
+
return { prunedCount: markedCount, savedTokens: prunedTokens };
|
|
617
|
+
}
|
|
618
|
+
return { prunedCount: 0, savedTokens: 0 };
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Estimates tokens for tool message content using simple heuristic (length/4).
|
|
622
|
+
* Used for pruning decisions only - actual token counts come from API.
|
|
623
|
+
*
|
|
624
|
+
* Tool message content is always Array<TextPart | ImagePart | FilePart | UIResourcePart>
|
|
625
|
+
* after sanitization via SanitizedToolResult.
|
|
626
|
+
*/
|
|
627
|
+
estimateToolTokens(content) {
|
|
628
|
+
return content.reduce((sum, part) => {
|
|
629
|
+
if (part.type === "text") {
|
|
630
|
+
return sum + Math.ceil(part.text.length / 4);
|
|
631
|
+
}
|
|
632
|
+
if (part.type === "image" || part.type === "file") {
|
|
633
|
+
return sum + 1e3;
|
|
634
|
+
}
|
|
635
|
+
return sum;
|
|
636
|
+
}, 0);
|
|
637
|
+
}
|
|
638
|
+
/**
|
|
639
|
+
* Cleanup resources when execution scope exits.
|
|
640
|
+
* Called automatically via defer() on normal exit, throw, or abort.
|
|
641
|
+
*/
|
|
642
|
+
cleanup() {
|
|
643
|
+
this.logger.debug("TurnExecutor cleanup triggered");
|
|
644
|
+
if (!this.stepAbortController.signal.aborted) {
|
|
645
|
+
this.stepAbortController.abort();
|
|
646
|
+
}
|
|
647
|
+
this.messageQueue.clear();
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* Check if context has overflowed based on actual token usage from API.
|
|
651
|
+
*/
|
|
652
|
+
checkAndHandleOverflow(tokens) {
|
|
653
|
+
if (!this.modelLimits || !this.compactionStrategy) {
|
|
654
|
+
return false;
|
|
655
|
+
}
|
|
656
|
+
return (0, import_overflow.isOverflow)(tokens, this.modelLimits);
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* Compress context using ReactiveOverflowStrategy.
|
|
660
|
+
*
|
|
661
|
+
* Generates a summary of older messages and adds it to history.
|
|
662
|
+
* The actual token reduction happens at read-time via filterCompacted()
|
|
663
|
+
* in getFormattedMessagesWithCompression().
|
|
664
|
+
*
|
|
665
|
+
* @param originalTokens The actual input token count from API that triggered overflow
|
|
666
|
+
*/
|
|
667
|
+
async compress(originalTokens) {
|
|
668
|
+
if (!this.compactionStrategy) {
|
|
669
|
+
return;
|
|
670
|
+
}
|
|
671
|
+
this.logger.info(
|
|
672
|
+
`Context overflow detected (${originalTokens} tokens), running compression`
|
|
673
|
+
);
|
|
674
|
+
const history = await this.contextManager.getHistory();
|
|
675
|
+
const summaryMessages = await this.compactionStrategy.compact(history);
|
|
676
|
+
if (summaryMessages.length === 0) {
|
|
677
|
+
this.logger.debug("Compaction returned no summary (history too short)");
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
for (const summary of summaryMessages) {
|
|
681
|
+
await this.contextManager.addMessage(summary);
|
|
682
|
+
}
|
|
683
|
+
const { filterCompacted, estimateMessagesTokens } = await import("../../context/utils.js");
|
|
684
|
+
const updatedHistory = await this.contextManager.getHistory();
|
|
685
|
+
const filteredHistory = filterCompacted(updatedHistory);
|
|
686
|
+
const compactedTokens = estimateMessagesTokens(filteredHistory);
|
|
687
|
+
this.eventBus.emit("context:compacted", {
|
|
688
|
+
originalTokens,
|
|
689
|
+
compactedTokens,
|
|
690
|
+
originalMessages: history.length,
|
|
691
|
+
compactedMessages: filteredHistory.length,
|
|
692
|
+
strategy: this.compactionStrategy.name,
|
|
693
|
+
reason: "overflow"
|
|
694
|
+
});
|
|
695
|
+
this.logger.info(
|
|
696
|
+
`Compaction complete: ${originalTokens} \u2192 ~${compactedTokens} tokens (${history.length} \u2192 ${filteredHistory.length} messages after filtering)`
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* Set telemetry span attributes for token usage.
|
|
701
|
+
*/
|
|
702
|
+
setTelemetryAttributes(usage) {
|
|
703
|
+
const activeSpan = import_api.trace.getActiveSpan();
|
|
704
|
+
if (!activeSpan || !usage) {
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
if (usage.inputTokens !== void 0) {
|
|
708
|
+
activeSpan.setAttribute("gen_ai.usage.input_tokens", usage.inputTokens);
|
|
709
|
+
}
|
|
710
|
+
if (usage.outputTokens !== void 0) {
|
|
711
|
+
activeSpan.setAttribute("gen_ai.usage.output_tokens", usage.outputTokens);
|
|
712
|
+
}
|
|
713
|
+
if (usage.totalTokens !== void 0) {
|
|
714
|
+
activeSpan.setAttribute("gen_ai.usage.total_tokens", usage.totalTokens);
|
|
715
|
+
}
|
|
716
|
+
if (usage.reasoningTokens !== void 0) {
|
|
717
|
+
activeSpan.setAttribute("gen_ai.usage.reasoning_tokens", usage.reasoningTokens);
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
/**
|
|
721
|
+
* Map provider errors to DextoRuntimeError.
|
|
722
|
+
*/
|
|
723
|
+
mapProviderError(err) {
|
|
724
|
+
if (import_ai.APICallError.isInstance?.(err)) {
|
|
725
|
+
const status = err.statusCode;
|
|
726
|
+
const headers = err.responseHeaders || {};
|
|
727
|
+
const retryAfter = headers["retry-after"] ? Number(headers["retry-after"]) : void 0;
|
|
728
|
+
const body = typeof err.responseBody === "string" ? err.responseBody : JSON.stringify(err.responseBody ?? "");
|
|
729
|
+
if (status === 429) {
|
|
730
|
+
return new import_DextoRuntimeError.DextoRuntimeError(
|
|
731
|
+
import_error_codes.LLMErrorCode.RATE_LIMIT_EXCEEDED,
|
|
732
|
+
import_types7.ErrorScope.LLM,
|
|
733
|
+
import_types7.ErrorType.RATE_LIMIT,
|
|
734
|
+
`Rate limit exceeded${body ? ` - ${body}` : ""}`,
|
|
735
|
+
{
|
|
736
|
+
sessionId: this.sessionId,
|
|
737
|
+
provider: this.llmContext.provider,
|
|
738
|
+
model: this.llmContext.model,
|
|
739
|
+
status,
|
|
740
|
+
retryAfter,
|
|
741
|
+
body
|
|
742
|
+
}
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
if (status === 408) {
|
|
746
|
+
return new import_DextoRuntimeError.DextoRuntimeError(
|
|
747
|
+
import_error_codes.LLMErrorCode.GENERATION_FAILED,
|
|
748
|
+
import_types7.ErrorScope.LLM,
|
|
749
|
+
import_types7.ErrorType.TIMEOUT,
|
|
750
|
+
`Provider timed out${body ? ` - ${body}` : ""}`,
|
|
751
|
+
{
|
|
752
|
+
sessionId: this.sessionId,
|
|
753
|
+
provider: this.llmContext.provider,
|
|
754
|
+
model: this.llmContext.model,
|
|
755
|
+
status,
|
|
756
|
+
body
|
|
757
|
+
}
|
|
758
|
+
);
|
|
759
|
+
}
|
|
760
|
+
return new import_DextoRuntimeError.DextoRuntimeError(
|
|
761
|
+
import_error_codes.LLMErrorCode.GENERATION_FAILED,
|
|
762
|
+
import_types7.ErrorScope.LLM,
|
|
763
|
+
import_types7.ErrorType.THIRD_PARTY,
|
|
764
|
+
`Provider error ${status}${body ? ` - ${body}` : ""}`,
|
|
765
|
+
{
|
|
766
|
+
sessionId: this.sessionId,
|
|
767
|
+
provider: this.llmContext.provider,
|
|
768
|
+
model: this.llmContext.model,
|
|
769
|
+
status,
|
|
770
|
+
body
|
|
771
|
+
}
|
|
772
|
+
);
|
|
773
|
+
}
|
|
774
|
+
return (0, import_error_conversion.toError)(err, this.logger);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
778
|
+
0 && (module.exports = {
|
|
779
|
+
TurnExecutor
|
|
780
|
+
});
|