@dexto/core 1.5.8 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -8
- package/dist/agent/DextoAgent.cjs +318 -159
- package/dist/agent/DextoAgent.d.ts +94 -56
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +315 -156
- package/dist/{context/compaction/provider.cjs → agent/agent-options.cjs} +2 -2
- package/dist/agent/agent-options.d.ts +53 -0
- package/dist/agent/agent-options.d.ts.map +1 -0
- package/dist/agent/agentCard.cjs +1 -1
- package/dist/agent/errors.cjs +2 -2
- package/dist/agent/errors.d.ts.map +1 -1
- package/dist/agent/index.cjs +1 -6
- package/dist/agent/index.d.ts +3 -2
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +1 -7
- package/dist/{storage/blob/provider.cjs → agent/runtime-config.cjs} +2 -2
- package/dist/agent/runtime-config.d.ts +53 -0
- package/dist/agent/runtime-config.d.ts.map +1 -0
- package/dist/agent/schemas.cjs +2 -104
- package/dist/agent/schemas.d.ts +8 -9197
- package/dist/agent/schemas.d.ts.map +1 -1
- package/dist/agent/schemas.js +1 -109
- package/dist/agent/state-manager.d.ts +5 -5
- package/dist/agent/state-manager.d.ts.map +1 -1
- package/dist/approval/error-codes.cjs +1 -1
- package/dist/approval/error-codes.d.ts +1 -1
- package/dist/approval/error-codes.d.ts.map +1 -1
- package/dist/approval/error-codes.js +1 -1
- package/dist/approval/errors.cjs +5 -5
- package/dist/approval/errors.d.ts +2 -2
- package/dist/approval/errors.d.ts.map +1 -1
- package/dist/approval/errors.js +5 -5
- package/dist/approval/index.cjs +8 -8
- package/dist/approval/index.d.ts +2 -2
- package/dist/approval/index.d.ts.map +1 -1
- package/dist/approval/index.js +8 -8
- package/dist/approval/manager.cjs +163 -83
- package/dist/approval/manager.d.ts +50 -43
- package/dist/approval/manager.d.ts.map +1 -1
- package/dist/approval/manager.js +161 -81
- package/dist/approval/schemas.cjs +47 -32
- package/dist/approval/schemas.d.ts +291 -97
- package/dist/approval/schemas.d.ts.map +1 -1
- package/dist/approval/schemas.js +43 -28
- package/dist/approval/types.cjs +1 -1
- package/dist/approval/types.d.ts +14 -14
- package/dist/approval/types.d.ts.map +1 -1
- package/dist/approval/types.js +1 -1
- package/dist/context/compaction/index.cjs +2 -23
- package/dist/context/compaction/index.d.ts +1 -7
- package/dist/context/compaction/index.d.ts.map +1 -1
- package/dist/context/compaction/index.js +1 -16
- package/dist/context/compaction/strategies/noop.cjs +19 -1
- package/dist/context/compaction/strategies/noop.d.ts +13 -3
- package/dist/context/compaction/strategies/noop.d.ts.map +1 -1
- package/dist/context/compaction/strategies/noop.js +19 -1
- package/dist/context/compaction/strategies/{reactive-overflow.cjs → reactive-overflow-compaction.cjs} +67 -64
- package/dist/context/compaction/strategies/{reactive-overflow.d.ts → reactive-overflow-compaction.d.ts} +19 -36
- package/dist/context/compaction/strategies/reactive-overflow-compaction.d.ts.map +1 -0
- package/dist/context/compaction/strategies/{reactive-overflow.js → reactive-overflow-compaction.js} +63 -60
- package/dist/context/compaction/types.d.ts +40 -8
- package/dist/context/compaction/types.d.ts.map +1 -1
- package/dist/context/manager.cjs +4 -2
- package/dist/context/manager.d.ts +5 -3
- package/dist/context/manager.d.ts.map +1 -1
- package/dist/context/manager.js +4 -2
- package/dist/context/types.d.ts +3 -0
- package/dist/context/types.d.ts.map +1 -1
- package/dist/context/utils.cjs +2 -2
- package/dist/context/utils.d.ts +14 -14
- package/dist/context/utils.d.ts.map +1 -1
- package/dist/errors/result-bridge.d.ts +2 -2
- package/dist/errors/result-bridge.d.ts.map +1 -1
- package/dist/errors/types.cjs +1 -1
- package/dist/errors/types.d.ts +3 -3
- package/dist/errors/types.d.ts.map +1 -1
- package/dist/errors/types.js +1 -1
- package/dist/events/index.cjs +11 -1
- package/dist/events/index.d.ts +48 -7
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +11 -1
- package/dist/{plugins → hooks}/builtins/content-policy.cjs +7 -6
- package/dist/hooks/builtins/content-policy.d.ts +24 -0
- package/dist/hooks/builtins/content-policy.d.ts.map +1 -0
- package/dist/{plugins → hooks}/builtins/content-policy.js +6 -5
- package/dist/{plugins → hooks}/builtins/response-sanitizer.cjs +3 -3
- package/dist/hooks/builtins/response-sanitizer.d.ts +22 -0
- package/dist/hooks/builtins/response-sanitizer.d.ts.map +1 -0
- package/dist/{plugins → hooks}/builtins/response-sanitizer.js +2 -2
- package/dist/hooks/error-codes.cjs +43 -0
- package/dist/hooks/error-codes.d.ts +34 -0
- package/dist/hooks/error-codes.d.ts.map +1 -0
- package/dist/hooks/error-codes.js +20 -0
- package/dist/{storage/cache/providers/memory.cjs → hooks/index.cjs} +15 -18
- package/dist/hooks/index.d.ts +14 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +11 -0
- package/dist/hooks/manager.cjs +354 -0
- package/dist/hooks/manager.d.ts +103 -0
- package/dist/hooks/manager.d.ts.map +1 -0
- package/dist/hooks/manager.js +331 -0
- package/dist/{plugins → hooks}/types.d.ts +26 -45
- package/dist/hooks/types.d.ts.map +1 -0
- package/dist/index.browser.cjs +13 -12
- package/dist/index.browser.d.ts +5 -5
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.browser.js +8 -7
- package/dist/index.cjs +5 -7
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/llm/errors.cjs +1 -1
- package/dist/llm/executor/stream-processor.cjs +131 -11
- package/dist/llm/executor/stream-processor.d.ts +8 -5
- package/dist/llm/executor/stream-processor.d.ts.map +1 -1
- package/dist/llm/executor/stream-processor.js +131 -11
- package/dist/llm/executor/turn-executor.cjs +49 -54
- package/dist/llm/executor/turn-executor.d.ts +7 -8
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +49 -54
- package/dist/llm/formatters/vercel.cjs +2 -2
- package/dist/llm/formatters/vercel.d.ts +2 -2
- package/dist/llm/formatters/vercel.d.ts.map +1 -1
- package/dist/llm/providers/local/schemas.d.ts +12 -12
- package/dist/llm/registry/auto-update.d.ts +2 -2
- package/dist/llm/registry/auto-update.d.ts.map +1 -1
- package/dist/llm/registry/index.d.ts +3 -3
- package/dist/llm/registry/index.d.ts.map +1 -1
- package/dist/llm/resolver.cjs +2 -2
- package/dist/llm/resolver.d.ts +4 -4
- package/dist/llm/resolver.d.ts.map +1 -1
- package/dist/llm/schemas.cjs +67 -104
- package/dist/llm/schemas.d.ts +10 -149
- package/dist/llm/schemas.d.ts.map +1 -1
- package/dist/llm/schemas.js +64 -101
- package/dist/llm/services/factory.cjs +2 -3
- package/dist/llm/services/factory.d.ts +3 -4
- package/dist/llm/services/factory.d.ts.map +1 -1
- package/dist/llm/services/factory.js +2 -3
- package/dist/llm/services/vercel.cjs +8 -15
- package/dist/llm/services/vercel.d.ts +6 -7
- package/dist/llm/services/vercel.d.ts.map +1 -1
- package/dist/llm/services/vercel.js +8 -15
- package/dist/llm/validation.cjs +1 -1
- package/dist/llm/validation.d.ts +2 -2
- package/dist/llm/validation.d.ts.map +1 -1
- package/dist/logger/browser.cjs +4 -4
- package/dist/logger/browser.d.ts +4 -4
- package/dist/logger/browser.d.ts.map +1 -1
- package/dist/logger/browser.js +3 -3
- package/dist/{context/compaction/providers/noop-provider.cjs → logger/default-logger-factory.cjs} +16 -22
- package/dist/logger/default-logger-factory.d.ts +301 -0
- package/dist/logger/default-logger-factory.d.ts.map +1 -0
- package/dist/logger/default-logger-factory.js +18 -0
- package/dist/logger/factory.d.ts +2 -2
- package/dist/logger/factory.d.ts.map +1 -1
- package/dist/logger/index.cjs +7 -2
- package/dist/logger/index.d.ts +5 -3
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/logger/index.js +8 -2
- package/dist/logger/logger.cjs +4 -4
- package/dist/logger/logger.d.ts +4 -4
- package/dist/logger/logger.d.ts.map +1 -1
- package/dist/logger/logger.js +3 -3
- package/dist/logger/v2/dexto-logger.cjs +35 -0
- package/dist/logger/v2/dexto-logger.d.ts +22 -3
- package/dist/logger/v2/dexto-logger.d.ts.map +1 -1
- package/dist/logger/v2/dexto-logger.js +35 -0
- package/dist/logger/v2/schemas.d.ts +6 -6
- package/dist/logger/v2/test-utils.cjs +2 -0
- package/dist/logger/v2/test-utils.d.ts +5 -5
- package/dist/logger/v2/test-utils.d.ts.map +1 -1
- package/dist/logger/v2/test-utils.js +2 -0
- package/dist/logger/v2/transport-factory.d.ts +3 -3
- package/dist/logger/v2/transport-factory.d.ts.map +1 -1
- package/dist/logger/v2/transports/console-transport.d.ts +2 -2
- package/dist/logger/v2/transports/console-transport.d.ts.map +1 -1
- package/dist/logger/v2/transports/file-transport.d.ts +2 -2
- package/dist/logger/v2/transports/file-transport.d.ts.map +1 -1
- package/dist/logger/v2/transports/silent-transport.d.ts +2 -2
- package/dist/logger/v2/transports/silent-transport.d.ts.map +1 -1
- package/dist/logger/v2/types.cjs +1 -1
- package/dist/logger/v2/types.d.ts +22 -9
- package/dist/logger/v2/types.d.ts.map +1 -1
- package/dist/logger/v2/types.js +1 -1
- package/dist/mcp/errors.cjs +2 -2
- package/dist/mcp/errors.d.ts.map +1 -1
- package/dist/mcp/manager.cjs +16 -11
- package/dist/mcp/manager.d.ts +16 -13
- package/dist/mcp/manager.d.ts.map +1 -1
- package/dist/mcp/manager.js +17 -12
- package/dist/mcp/mcp-client.cjs +25 -20
- package/dist/mcp/mcp-client.d.ts +5 -5
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js +20 -15
- package/dist/mcp/resolver.cjs +1 -1
- package/dist/mcp/schemas.cjs +5 -5
- package/dist/mcp/schemas.d.ts +19 -19
- package/dist/mcp/schemas.js +2 -2
- package/dist/mcp/types.d.ts +7 -7
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/memory/manager.d.ts +2 -2
- package/dist/memory/manager.d.ts.map +1 -1
- package/dist/memory/schemas.d.ts +2 -2
- package/dist/prompts/errors.cjs +3 -3
- package/dist/prompts/errors.d.ts.map +1 -1
- package/dist/prompts/prompt-manager.d.ts +3 -3
- package/dist/prompts/prompt-manager.d.ts.map +1 -1
- package/dist/prompts/providers/config-prompt-provider.cjs +15 -29
- package/dist/prompts/providers/config-prompt-provider.d.ts +3 -3
- package/dist/prompts/providers/config-prompt-provider.d.ts.map +1 -1
- package/dist/prompts/providers/config-prompt-provider.js +15 -29
- package/dist/prompts/providers/custom-prompt-provider.d.ts +2 -2
- package/dist/prompts/providers/custom-prompt-provider.d.ts.map +1 -1
- package/dist/prompts/providers/mcp-prompt-provider.d.ts +2 -2
- package/dist/prompts/providers/mcp-prompt-provider.d.ts.map +1 -1
- package/dist/prompts/schemas.d.ts +7 -7
- package/dist/resources/{internal-provider.cjs → agent-resources-provider.cjs} +16 -16
- package/dist/resources/{internal-provider.d.ts → agent-resources-provider.d.ts} +6 -6
- package/dist/resources/agent-resources-provider.d.ts.map +1 -0
- package/dist/resources/{internal-provider.js → agent-resources-provider.js} +13 -13
- package/dist/resources/errors.cjs +2 -2
- package/dist/resources/errors.d.ts.map +1 -1
- package/dist/resources/handlers/blob-handler.d.ts +2 -2
- package/dist/resources/handlers/blob-handler.d.ts.map +1 -1
- package/dist/resources/handlers/factory.d.ts +3 -3
- package/dist/resources/handlers/factory.d.ts.map +1 -1
- package/dist/resources/handlers/filesystem-handler.d.ts +2 -2
- package/dist/resources/handlers/filesystem-handler.d.ts.map +1 -1
- package/dist/resources/index.cjs +7 -9
- package/dist/resources/index.d.ts +3 -3
- package/dist/resources/index.d.ts.map +1 -1
- package/dist/resources/index.js +5 -10
- package/dist/resources/manager.cjs +77 -74
- package/dist/resources/manager.d.ts +16 -7
- package/dist/resources/manager.d.ts.map +1 -1
- package/dist/resources/manager.js +77 -74
- package/dist/resources/schemas.cjs +6 -26
- package/dist/resources/schemas.d.ts +8 -100
- package/dist/resources/schemas.d.ts.map +1 -1
- package/dist/resources/schemas.js +4 -23
- package/dist/search/search-service.d.ts +2 -2
- package/dist/search/search-service.d.ts.map +1 -1
- package/dist/session/chat-session.cjs +15 -25
- package/dist/session/chat-session.d.ts +7 -5
- package/dist/session/chat-session.d.ts.map +1 -1
- package/dist/session/chat-session.js +16 -26
- package/dist/session/errors.cjs +2 -2
- package/dist/session/errors.d.ts.map +1 -1
- package/dist/session/history/database.cjs +1 -1
- package/dist/session/history/database.d.ts +4 -4
- package/dist/session/history/database.d.ts.map +1 -1
- package/dist/session/history/factory.d.ts +3 -3
- package/dist/session/history/factory.d.ts.map +1 -1
- package/dist/session/history/memory.d.ts +4 -4
- package/dist/session/history/memory.d.ts.map +1 -1
- package/dist/session/history/types.d.ts +2 -2
- package/dist/session/history/types.d.ts.map +1 -1
- package/dist/session/index.cjs +3 -0
- package/dist/session/index.d.ts +2 -0
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +2 -0
- package/dist/session/message-queue.d.ts +2 -2
- package/dist/session/message-queue.d.ts.map +1 -1
- package/dist/session/session-manager.cjs +67 -9
- package/dist/session/session-manager.d.ts +46 -7
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +67 -9
- package/dist/session/title-generator.cjs +2 -2
- package/dist/session/title-generator.d.ts +2 -2
- package/dist/session/title-generator.d.ts.map +1 -1
- package/dist/storage/blob/index.cjs +0 -40
- package/dist/storage/blob/index.d.ts +2 -44
- package/dist/storage/blob/index.d.ts.map +1 -1
- package/dist/storage/blob/index.js +0 -30
- package/dist/storage/cache/index.cjs +0 -37
- package/dist/storage/cache/index.d.ts +0 -42
- package/dist/storage/cache/index.d.ts.map +1 -1
- package/dist/storage/cache/index.js +0 -28
- package/dist/storage/database/index.cjs +0 -42
- package/dist/storage/database/index.d.ts +0 -43
- package/dist/storage/database/index.d.ts.map +1 -1
- package/dist/storage/database/index.js +0 -37
- package/dist/storage/error-codes.cjs +1 -6
- package/dist/storage/error-codes.d.ts +2 -7
- package/dist/storage/error-codes.d.ts.map +1 -1
- package/dist/storage/error-codes.js +1 -6
- package/dist/storage/errors.cjs +18 -82
- package/dist/storage/errors.d.ts +4 -24
- package/dist/storage/errors.d.ts.map +1 -1
- package/dist/storage/errors.js +16 -80
- package/dist/storage/index.cjs +8 -69
- package/dist/storage/index.d.ts +11 -66
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +6 -50
- package/dist/storage/storage-manager.cjs +9 -25
- package/dist/storage/storage-manager.d.ts +11 -15
- package/dist/storage/storage-manager.d.ts.map +1 -1
- package/dist/storage/storage-manager.js +8 -23
- package/dist/storage/types.d.ts +0 -1
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/systemPrompt/contributors.d.ts +4 -4
- package/dist/systemPrompt/contributors.d.ts.map +1 -1
- package/dist/systemPrompt/errors.cjs +2 -2
- package/dist/systemPrompt/errors.d.ts.map +1 -1
- package/dist/systemPrompt/in-built-prompts.cjs +5 -5
- package/dist/systemPrompt/in-built-prompts.d.ts +1 -1
- package/dist/systemPrompt/in-built-prompts.d.ts.map +1 -1
- package/dist/systemPrompt/in-built-prompts.js +5 -5
- package/dist/systemPrompt/manager.cjs +1 -5
- package/dist/systemPrompt/manager.d.ts +2 -3
- package/dist/systemPrompt/manager.d.ts.map +1 -1
- package/dist/systemPrompt/manager.js +1 -5
- package/dist/systemPrompt/schemas.d.ts +5 -5
- package/dist/systemPrompt/types.d.ts +11 -0
- package/dist/systemPrompt/types.d.ts.map +1 -1
- package/dist/telemetry/index.cjs +3 -0
- package/dist/telemetry/index.d.ts +2 -0
- package/dist/telemetry/index.d.ts.map +1 -1
- package/dist/telemetry/index.js +2 -0
- package/dist/telemetry/utils.d.ts +4 -4
- package/dist/telemetry/utils.d.ts.map +1 -1
- package/dist/test-utils/in-memory-storage.cjs +288 -0
- package/dist/test-utils/in-memory-storage.js +252 -0
- package/dist/tools/confirmation/allowed-tools-provider/factory.d.ts +3 -3
- package/dist/tools/confirmation/allowed-tools-provider/factory.d.ts.map +1 -1
- package/dist/tools/confirmation/allowed-tools-provider/in-memory.d.ts +2 -2
- package/dist/tools/confirmation/allowed-tools-provider/in-memory.d.ts.map +1 -1
- package/dist/tools/confirmation/allowed-tools-provider/storage.d.ts +4 -4
- package/dist/tools/confirmation/allowed-tools-provider/storage.d.ts.map +1 -1
- package/dist/tools/confirmation/allowed-tools-provider/types.d.ts +2 -2
- package/dist/tools/confirmation/allowed-tools-provider/types.d.ts.map +1 -1
- package/dist/tools/{internal-tools/constants.cjs → define-tool.cjs} +8 -13
- package/dist/tools/define-tool.d.ts +11 -0
- package/dist/tools/define-tool.d.ts.map +1 -0
- package/dist/tools/define-tool.js +7 -0
- package/dist/tools/display-types.d.ts +10 -0
- package/dist/tools/display-types.d.ts.map +1 -1
- package/dist/tools/error-codes.cjs +2 -2
- package/dist/tools/error-codes.d.ts +2 -2
- package/dist/tools/error-codes.d.ts.map +1 -1
- package/dist/tools/error-codes.js +2 -2
- package/dist/tools/errors.cjs +11 -23
- package/dist/tools/errors.d.ts +4 -10
- package/dist/tools/errors.d.ts.map +1 -1
- package/dist/tools/errors.js +9 -21
- package/dist/tools/index.cjs +6 -9
- package/dist/tools/index.d.ts +3 -4
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +3 -7
- package/dist/{storage/blob/providers/index.cjs → tools/pattern-utils.cjs} +11 -9
- package/dist/tools/pattern-utils.d.ts +20 -0
- package/dist/tools/pattern-utils.d.ts.map +1 -0
- package/dist/tools/pattern-utils.js +10 -0
- package/dist/{storage/cache/factory.cjs → tools/presentation.cjs} +26 -15
- package/dist/tools/presentation.d.ts +11 -0
- package/dist/tools/presentation.d.ts.map +1 -0
- package/dist/tools/presentation.js +24 -0
- package/dist/tools/schemas.cjs +14 -40
- package/dist/tools/schemas.d.ts +6 -50
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +11 -32
- package/dist/tools/tool-call-metadata.cjs +3 -3
- package/dist/tools/tool-call-metadata.d.ts +1 -1
- package/dist/tools/tool-call-metadata.d.ts.map +1 -1
- package/dist/tools/tool-call-metadata.js +3 -3
- package/dist/tools/tool-manager.cjs +608 -392
- package/dist/tools/tool-manager.d.ts +79 -98
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +608 -396
- package/dist/tools/types.d.ts +223 -45
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils/error-conversion.d.ts +2 -2
- package/dist/utils/error-conversion.d.ts.map +1 -1
- package/dist/utils/path.cjs +10 -1
- package/dist/utils/path.d.ts +7 -4
- package/dist/utils/path.d.ts.map +1 -1
- package/dist/utils/path.js +10 -1
- package/dist/utils/result.cjs +1 -1
- package/dist/utils/result.d.ts.map +1 -1
- package/dist/utils/schema.cjs +9 -5
- package/dist/utils/schema.d.ts +4 -2
- package/dist/utils/schema.d.ts.map +1 -1
- package/dist/utils/schema.js +9 -5
- package/dist/utils/service-initializer.cjs +51 -56
- package/dist/utils/service-initializer.d.ts +17 -14
- package/dist/utils/service-initializer.d.ts.map +1 -1
- package/dist/utils/service-initializer.js +51 -56
- package/dist/{storage/cache/providers/index.cjs → workspace/error-codes.cjs} +8 -9
- package/dist/workspace/error-codes.d.ts +5 -0
- package/dist/workspace/error-codes.d.ts.map +1 -0
- package/dist/workspace/error-codes.js +7 -0
- package/dist/{storage/blob/factory.cjs → workspace/errors.cjs} +20 -14
- package/dist/workspace/errors.d.ts +5 -0
- package/dist/workspace/errors.d.ts.map +1 -0
- package/dist/workspace/errors.js +21 -0
- package/dist/{image → workspace}/index.cjs +12 -10
- package/dist/workspace/index.d.ts +5 -0
- package/dist/workspace/index.d.ts.map +1 -0
- package/dist/workspace/index.js +9 -0
- package/dist/workspace/manager.cjs +113 -0
- package/dist/workspace/manager.d.ts +18 -0
- package/dist/workspace/manager.d.ts.map +1 -0
- package/dist/workspace/manager.js +90 -0
- package/dist/workspace/types.d.ts +14 -0
- package/dist/workspace/types.d.ts.map +1 -0
- package/package.json +2 -2
- package/dist/context/compaction/factory.cjs +0 -57
- package/dist/context/compaction/factory.d.ts +0 -17
- package/dist/context/compaction/factory.d.ts.map +0 -1
- package/dist/context/compaction/factory.js +0 -34
- package/dist/context/compaction/provider.d.ts +0 -48
- package/dist/context/compaction/provider.d.ts.map +0 -1
- package/dist/context/compaction/providers/noop-provider.d.ts +0 -24
- package/dist/context/compaction/providers/noop-provider.d.ts.map +0 -1
- package/dist/context/compaction/providers/noop-provider.js +0 -24
- package/dist/context/compaction/providers/reactive-overflow-provider.cjs +0 -76
- package/dist/context/compaction/providers/reactive-overflow-provider.d.ts +0 -51
- package/dist/context/compaction/providers/reactive-overflow-provider.d.ts.map +0 -1
- package/dist/context/compaction/providers/reactive-overflow-provider.js +0 -52
- package/dist/context/compaction/registry.cjs +0 -39
- package/dist/context/compaction/registry.d.ts +0 -19
- package/dist/context/compaction/registry.d.ts.map +0 -1
- package/dist/context/compaction/registry.js +0 -16
- package/dist/context/compaction/schemas.cjs +0 -58
- package/dist/context/compaction/schemas.d.ts +0 -69
- package/dist/context/compaction/schemas.d.ts.map +0 -1
- package/dist/context/compaction/schemas.js +0 -34
- package/dist/context/compaction/strategies/reactive-overflow.d.ts.map +0 -1
- package/dist/image/define-image.cjs +0 -146
- package/dist/image/define-image.d.ts +0 -71
- package/dist/image/define-image.d.ts.map +0 -1
- package/dist/image/define-image.js +0 -121
- package/dist/image/index.d.ts +0 -53
- package/dist/image/index.d.ts.map +0 -1
- package/dist/image/index.js +0 -7
- package/dist/image/types.d.ts +0 -246
- package/dist/image/types.d.ts.map +0 -1
- package/dist/llm/services/test-utils.integration.cjs +0 -237
- package/dist/llm/services/test-utils.integration.d.ts +0 -48
- package/dist/llm/services/test-utils.integration.d.ts.map +0 -1
- package/dist/llm/services/test-utils.integration.js +0 -214
- package/dist/plugins/builtins/content-policy.d.ts +0 -26
- package/dist/plugins/builtins/content-policy.d.ts.map +0 -1
- package/dist/plugins/builtins/response-sanitizer.d.ts +0 -25
- package/dist/plugins/builtins/response-sanitizer.d.ts.map +0 -1
- package/dist/plugins/error-codes.cjs +0 -43
- package/dist/plugins/error-codes.d.ts +0 -34
- package/dist/plugins/error-codes.d.ts.map +0 -1
- package/dist/plugins/error-codes.js +0 -20
- package/dist/plugins/index.cjs +0 -61
- package/dist/plugins/index.d.ts +0 -21
- package/dist/plugins/index.d.ts.map +0 -1
- package/dist/plugins/index.js +0 -30
- package/dist/plugins/loader.cjs +0 -171
- package/dist/plugins/loader.d.ts +0 -30
- package/dist/plugins/loader.d.ts.map +0 -1
- package/dist/plugins/loader.js +0 -145
- package/dist/plugins/manager.cjs +0 -473
- package/dist/plugins/manager.d.ts +0 -106
- package/dist/plugins/manager.d.ts.map +0 -1
- package/dist/plugins/manager.js +0 -450
- package/dist/plugins/registrations/builtins.cjs +0 -51
- package/dist/plugins/registrations/builtins.d.ts +0 -17
- package/dist/plugins/registrations/builtins.d.ts.map +0 -1
- package/dist/plugins/registrations/builtins.js +0 -28
- package/dist/plugins/registry.cjs +0 -63
- package/dist/plugins/registry.d.ts +0 -101
- package/dist/plugins/registry.d.ts.map +0 -1
- package/dist/plugins/registry.js +0 -39
- package/dist/plugins/schemas.cjs +0 -73
- package/dist/plugins/schemas.d.ts +0 -195
- package/dist/plugins/schemas.d.ts.map +0 -1
- package/dist/plugins/schemas.js +0 -47
- package/dist/plugins/types.d.ts.map +0 -1
- package/dist/providers/base-registry.cjs +0 -147
- package/dist/providers/base-registry.d.ts +0 -147
- package/dist/providers/base-registry.d.ts.map +0 -1
- package/dist/providers/base-registry.js +0 -123
- package/dist/providers/discovery.cjs +0 -109
- package/dist/providers/discovery.d.ts +0 -96
- package/dist/providers/discovery.d.ts.map +0 -1
- package/dist/providers/discovery.js +0 -84
- package/dist/providers/index.cjs +0 -24
- package/dist/providers/index.d.ts +0 -32
- package/dist/providers/index.d.ts.map +0 -1
- package/dist/providers/index.js +0 -2
- package/dist/resources/internal-provider.d.ts.map +0 -1
- package/dist/storage/blob/factory.d.ts +0 -37
- package/dist/storage/blob/factory.d.ts.map +0 -1
- package/dist/storage/blob/factory.js +0 -15
- package/dist/storage/blob/local-blob-store.cjs +0 -496
- package/dist/storage/blob/local-blob-store.d.ts +0 -58
- package/dist/storage/blob/local-blob-store.d.ts.map +0 -1
- package/dist/storage/blob/local-blob-store.js +0 -463
- package/dist/storage/blob/memory-blob-store.cjs +0 -326
- package/dist/storage/blob/memory-blob-store.d.ts +0 -66
- package/dist/storage/blob/memory-blob-store.d.ts.map +0 -1
- package/dist/storage/blob/memory-blob-store.js +0 -303
- package/dist/storage/blob/provider.d.ts +0 -50
- package/dist/storage/blob/provider.d.ts.map +0 -1
- package/dist/storage/blob/providers/index.d.ts +0 -8
- package/dist/storage/blob/providers/index.d.ts.map +0 -1
- package/dist/storage/blob/providers/index.js +0 -7
- package/dist/storage/blob/providers/local.cjs +0 -39
- package/dist/storage/blob/providers/local.d.ts +0 -17
- package/dist/storage/blob/providers/local.d.ts.map +0 -1
- package/dist/storage/blob/providers/local.js +0 -16
- package/dist/storage/blob/providers/memory.cjs +0 -39
- package/dist/storage/blob/providers/memory.d.ts +0 -17
- package/dist/storage/blob/providers/memory.d.ts.map +0 -1
- package/dist/storage/blob/providers/memory.js +0 -16
- package/dist/storage/blob/registry.cjs +0 -50
- package/dist/storage/blob/registry.d.ts +0 -42
- package/dist/storage/blob/registry.d.ts.map +0 -1
- package/dist/storage/blob/registry.js +0 -26
- package/dist/storage/blob/schemas.cjs +0 -52
- package/dist/storage/blob/schemas.d.ts +0 -85
- package/dist/storage/blob/schemas.d.ts.map +0 -1
- package/dist/storage/blob/schemas.js +0 -26
- package/dist/storage/cache/factory.d.ts +0 -37
- package/dist/storage/cache/factory.d.ts.map +0 -1
- package/dist/storage/cache/factory.js +0 -15
- package/dist/storage/cache/memory-cache-store.cjs +0 -107
- package/dist/storage/cache/memory-cache-store.d.ts +0 -26
- package/dist/storage/cache/memory-cache-store.d.ts.map +0 -1
- package/dist/storage/cache/memory-cache-store.js +0 -84
- package/dist/storage/cache/provider.cjs +0 -16
- package/dist/storage/cache/provider.d.ts +0 -56
- package/dist/storage/cache/provider.d.ts.map +0 -1
- package/dist/storage/cache/provider.js +0 -0
- package/dist/storage/cache/providers/index.d.ts +0 -8
- package/dist/storage/cache/providers/index.d.ts.map +0 -1
- package/dist/storage/cache/providers/index.js +0 -7
- package/dist/storage/cache/providers/memory.d.ts +0 -17
- package/dist/storage/cache/providers/memory.d.ts.map +0 -1
- package/dist/storage/cache/providers/memory.js +0 -17
- package/dist/storage/cache/providers/redis.cjs +0 -66
- package/dist/storage/cache/providers/redis.d.ts +0 -20
- package/dist/storage/cache/providers/redis.d.ts.map +0 -1
- package/dist/storage/cache/providers/redis.js +0 -33
- package/dist/storage/cache/redis-store.cjs +0 -173
- package/dist/storage/cache/redis-store.d.ts +0 -32
- package/dist/storage/cache/redis-store.d.ts.map +0 -1
- package/dist/storage/cache/redis-store.js +0 -150
- package/dist/storage/cache/registry.cjs +0 -50
- package/dist/storage/cache/registry.d.ts +0 -42
- package/dist/storage/cache/registry.d.ts.map +0 -1
- package/dist/storage/cache/registry.js +0 -26
- package/dist/storage/cache/schemas.cjs +0 -81
- package/dist/storage/cache/schemas.d.ts +0 -150
- package/dist/storage/cache/schemas.d.ts.map +0 -1
- package/dist/storage/cache/schemas.js +0 -55
- package/dist/storage/database/factory.cjs +0 -38
- package/dist/storage/database/factory.d.ts +0 -39
- package/dist/storage/database/factory.d.ts.map +0 -1
- package/dist/storage/database/factory.js +0 -15
- package/dist/storage/database/memory-database-store.cjs +0 -122
- package/dist/storage/database/memory-database-store.d.ts +0 -29
- package/dist/storage/database/memory-database-store.d.ts.map +0 -1
- package/dist/storage/database/memory-database-store.js +0 -99
- package/dist/storage/database/postgres-store.cjs +0 -342
- package/dist/storage/database/postgres-store.d.ts +0 -55
- package/dist/storage/database/postgres-store.d.ts.map +0 -1
- package/dist/storage/database/postgres-store.js +0 -319
- package/dist/storage/database/provider.cjs +0 -16
- package/dist/storage/database/provider.d.ts +0 -56
- package/dist/storage/database/provider.d.ts.map +0 -1
- package/dist/storage/database/provider.js +0 -0
- package/dist/storage/database/providers/index.cjs +0 -34
- package/dist/storage/database/providers/index.d.ts +0 -9
- package/dist/storage/database/providers/index.d.ts.map +0 -1
- package/dist/storage/database/providers/index.js +0 -9
- package/dist/storage/database/providers/memory.cjs +0 -40
- package/dist/storage/database/providers/memory.d.ts +0 -16
- package/dist/storage/database/providers/memory.d.ts.map +0 -1
- package/dist/storage/database/providers/memory.js +0 -17
- package/dist/storage/database/providers/postgres.cjs +0 -62
- package/dist/storage/database/providers/postgres.d.ts +0 -19
- package/dist/storage/database/providers/postgres.d.ts.map +0 -1
- package/dist/storage/database/providers/postgres.js +0 -29
- package/dist/storage/database/providers/sqlite.cjs +0 -66
- package/dist/storage/database/providers/sqlite.d.ts +0 -20
- package/dist/storage/database/providers/sqlite.d.ts.map +0 -1
- package/dist/storage/database/providers/sqlite.js +0 -33
- package/dist/storage/database/registry.cjs +0 -50
- package/dist/storage/database/registry.d.ts +0 -42
- package/dist/storage/database/registry.d.ts.map +0 -1
- package/dist/storage/database/registry.js +0 -26
- package/dist/storage/database/schemas.cjs +0 -97
- package/dist/storage/database/schemas.d.ts +0 -226
- package/dist/storage/database/schemas.d.ts.map +0 -1
- package/dist/storage/database/schemas.js +0 -70
- package/dist/storage/database/sqlite-store.cjs +0 -270
- package/dist/storage/database/sqlite-store.d.ts +0 -33
- package/dist/storage/database/sqlite-store.d.ts.map +0 -1
- package/dist/storage/database/sqlite-store.js +0 -237
- package/dist/storage/schemas.cjs +0 -57
- package/dist/storage/schemas.d.ts +0 -347
- package/dist/storage/schemas.d.ts.map +0 -1
- package/dist/storage/schemas.js +0 -37
- package/dist/tools/bash-pattern-utils.cjs +0 -91
- package/dist/tools/bash-pattern-utils.d.ts +0 -58
- package/dist/tools/bash-pattern-utils.d.ts.map +0 -1
- package/dist/tools/bash-pattern-utils.js +0 -64
- package/dist/tools/custom-tool-registry.cjs +0 -64
- package/dist/tools/custom-tool-registry.d.ts +0 -126
- package/dist/tools/custom-tool-registry.d.ts.map +0 -1
- package/dist/tools/custom-tool-registry.js +0 -40
- package/dist/tools/custom-tool-schema-registry.cjs +0 -164
- package/dist/tools/custom-tool-schema-registry.d.ts +0 -86
- package/dist/tools/custom-tool-schema-registry.d.ts.map +0 -1
- package/dist/tools/custom-tool-schema-registry.js +0 -140
- package/dist/tools/internal-tools/constants.d.ts +0 -12
- package/dist/tools/internal-tools/constants.d.ts.map +0 -1
- package/dist/tools/internal-tools/constants.js +0 -12
- package/dist/tools/internal-tools/implementations/ask-user-tool.cjs +0 -57
- package/dist/tools/internal-tools/implementations/ask-user-tool.d.ts +0 -18
- package/dist/tools/internal-tools/implementations/ask-user-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/ask-user-tool.js +0 -34
- package/dist/tools/internal-tools/implementations/delegate-to-url-tool.cjs +0 -192
- package/dist/tools/internal-tools/implementations/delegate-to-url-tool.d.ts +0 -33
- package/dist/tools/internal-tools/implementations/delegate-to-url-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/delegate-to-url-tool.js +0 -169
- package/dist/tools/internal-tools/implementations/get-resource-tool.cjs +0 -113
- package/dist/tools/internal-tools/implementations/get-resource-tool.d.ts +0 -30
- package/dist/tools/internal-tools/implementations/get-resource-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/get-resource-tool.js +0 -90
- package/dist/tools/internal-tools/implementations/invoke-skill-tool.cjs +0 -140
- package/dist/tools/internal-tools/implementations/invoke-skill-tool.d.ts +0 -24
- package/dist/tools/internal-tools/implementations/invoke-skill-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/invoke-skill-tool.js +0 -117
- package/dist/tools/internal-tools/implementations/list-resources-tool.cjs +0 -91
- package/dist/tools/internal-tools/implementations/list-resources-tool.d.ts +0 -24
- package/dist/tools/internal-tools/implementations/list-resources-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/list-resources-tool.js +0 -68
- package/dist/tools/internal-tools/implementations/search-history-tool.cjs +0 -61
- package/dist/tools/internal-tools/implementations/search-history-tool.d.ts +0 -7
- package/dist/tools/internal-tools/implementations/search-history-tool.d.ts.map +0 -1
- package/dist/tools/internal-tools/implementations/search-history-tool.js +0 -38
- package/dist/tools/internal-tools/index.cjs +0 -26
- package/dist/tools/internal-tools/index.d.ts +0 -4
- package/dist/tools/internal-tools/index.d.ts.map +0 -1
- package/dist/tools/internal-tools/index.js +0 -3
- package/dist/tools/internal-tools/provider.cjs +0 -324
- package/dist/tools/internal-tools/provider.d.ts +0 -116
- package/dist/tools/internal-tools/provider.d.ts.map +0 -1
- package/dist/tools/internal-tools/provider.js +0 -301
- package/dist/tools/internal-tools/registry.cjs +0 -71
- package/dist/tools/internal-tools/registry.d.ts +0 -91
- package/dist/tools/internal-tools/registry.d.ts.map +0 -1
- package/dist/tools/internal-tools/registry.js +0 -47
- /package/dist/{context/compaction/provider.js → agent/agent-options.js} +0 -0
- /package/dist/{image/types.js → agent/runtime-config.js} +0 -0
- /package/dist/{image → hooks}/types.cjs +0 -0
- /package/dist/{plugins → hooks}/types.js +0 -0
- /package/dist/{plugins → workspace}/types.cjs +0 -0
- /package/dist/{storage/blob/provider.js → workspace/types.js} +0 -0
|
@@ -4,45 +4,41 @@ import {
|
|
|
4
4
|
__runInitializers
|
|
5
5
|
} from "../chunk-PTJYTZNU.js";
|
|
6
6
|
var _ToolManager_decorators, _init;
|
|
7
|
-
import { InternalToolsProvider } from "./internal-tools/provider.js";
|
|
8
7
|
import { ToolError } from "./errors.js";
|
|
9
8
|
import { ToolErrorCode } from "./error-codes.js";
|
|
10
9
|
import { DextoRuntimeError } from "../errors/index.js";
|
|
11
10
|
import { DextoLogComponent } from "../logger/v2/types.js";
|
|
11
|
+
import { convertZodSchemaToJsonSchema } from "../utils/schema.js";
|
|
12
12
|
import { ApprovalStatus, ApprovalType, DenialReason } from "../approval/types.js";
|
|
13
13
|
import { InstrumentClass } from "../telemetry/decorators.js";
|
|
14
14
|
import { extractToolCallMeta, wrapToolParametersSchema } from "./tool-call-metadata.js";
|
|
15
|
-
import {
|
|
16
|
-
generateBashPatternKey,
|
|
17
|
-
generateBashPatternSuggestions,
|
|
18
|
-
isDangerousCommand
|
|
19
|
-
} from "./bash-pattern-utils.js";
|
|
20
15
|
import { isBackgroundTasksEnabled } from "../utils/env.js";
|
|
21
16
|
_ToolManager_decorators = [InstrumentClass({
|
|
22
17
|
prefix: "tool",
|
|
23
|
-
excludeMethods: [
|
|
24
|
-
"setPluginManager",
|
|
25
|
-
"setStateManager",
|
|
26
|
-
"getApprovalManager",
|
|
27
|
-
"getAllowedToolsProvider"
|
|
28
|
-
]
|
|
18
|
+
excludeMethods: ["setHookSupport", "getApprovalManager", "getAllowedToolsProvider"]
|
|
29
19
|
})];
|
|
30
20
|
let _ToolManager = class _ToolManager {
|
|
31
21
|
mcpManager;
|
|
32
|
-
|
|
22
|
+
agentTools = /* @__PURE__ */ new Map();
|
|
33
23
|
approvalManager;
|
|
34
24
|
allowedToolsProvider;
|
|
35
25
|
approvalMode;
|
|
36
26
|
agentEventBus;
|
|
37
27
|
toolPolicies;
|
|
38
|
-
|
|
39
|
-
|
|
28
|
+
toolExecutionContextFactory;
|
|
29
|
+
contributorContextFactory;
|
|
30
|
+
// Hook support - set after construction to avoid circular dependencies
|
|
31
|
+
hookManager;
|
|
40
32
|
sessionManager;
|
|
41
33
|
stateManager;
|
|
42
|
-
|
|
34
|
+
workspaceManager;
|
|
35
|
+
currentWorkspace;
|
|
36
|
+
workspaceListenerAttached = false;
|
|
37
|
+
workspaceListenerAbort = new AbortController();
|
|
38
|
+
// Tool naming:
|
|
39
|
+
// - MCP tools are prefixed with `mcp--` for disambiguation.
|
|
40
|
+
// - Local tools use their `Tool.id` as-is (no internal/custom prefixing).
|
|
43
41
|
static MCP_TOOL_PREFIX = "mcp--";
|
|
44
|
-
static INTERNAL_TOOL_PREFIX = "internal--";
|
|
45
|
-
static CUSTOM_TOOL_PREFIX = "custom--";
|
|
46
42
|
// Tool caching for performance
|
|
47
43
|
toolsCache = {};
|
|
48
44
|
cacheValid = false;
|
|
@@ -55,7 +51,29 @@ let _ToolManager = class _ToolManager {
|
|
|
55
51
|
sessionUserAutoApproveTools = /* @__PURE__ */ new Map();
|
|
56
52
|
sessionDisabledTools = /* @__PURE__ */ new Map();
|
|
57
53
|
globalDisabledTools = [];
|
|
58
|
-
|
|
54
|
+
cleanupHandlers = /* @__PURE__ */ new Set();
|
|
55
|
+
cleanupStarted = false;
|
|
56
|
+
resolveLocalToolIdOrAlias(name) {
|
|
57
|
+
const direct = this.agentTools.get(name);
|
|
58
|
+
if (direct) return direct.id;
|
|
59
|
+
const lower = name.toLowerCase();
|
|
60
|
+
for (const tool of this.agentTools.values()) {
|
|
61
|
+
if (tool.id.toLowerCase() === lower) {
|
|
62
|
+
return tool.id;
|
|
63
|
+
}
|
|
64
|
+
if (tool.aliases?.some((alias) => alias.toLowerCase() === lower)) {
|
|
65
|
+
return tool.id;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
normalizeToolPolicyPattern(pattern) {
|
|
71
|
+
if (pattern.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
72
|
+
return pattern;
|
|
73
|
+
}
|
|
74
|
+
return this.resolveLocalToolIdOrAlias(pattern) ?? pattern;
|
|
75
|
+
}
|
|
76
|
+
constructor(mcpManager, approvalManager, allowedToolsProvider, approvalMode, agentEventBus, toolPolicies, tools, logger) {
|
|
59
77
|
this.mcpManager = mcpManager;
|
|
60
78
|
this.approvalManager = approvalManager;
|
|
61
79
|
this.allowedToolsProvider = allowedToolsProvider;
|
|
@@ -63,18 +81,12 @@ let _ToolManager = class _ToolManager {
|
|
|
63
81
|
this.agentEventBus = agentEventBus;
|
|
64
82
|
this.toolPolicies = toolPolicies;
|
|
65
83
|
this.logger = logger.createChild(DextoLogComponent.TOOLS);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
};
|
|
71
|
-
this.internalToolsProvider = new InternalToolsProvider(
|
|
72
|
-
internalToolsServices,
|
|
73
|
-
options.internalToolsConfig || [],
|
|
74
|
-
options.customToolsConfig || [],
|
|
75
|
-
this.logger
|
|
84
|
+
this.setTools(tools);
|
|
85
|
+
this.toolExecutionContextFactory = () => {
|
|
86
|
+
throw ToolError.configInvalid(
|
|
87
|
+
"ToolExecutionContextFactory not configured. DextoAgent.start() must configure tool execution context before tools can run."
|
|
76
88
|
);
|
|
77
|
-
}
|
|
89
|
+
};
|
|
78
90
|
this.setupNotificationListeners();
|
|
79
91
|
this.logger.debug("ToolManager initialized");
|
|
80
92
|
}
|
|
@@ -82,50 +94,78 @@ let _ToolManager = class _ToolManager {
|
|
|
82
94
|
* Initialize the ToolManager and its components
|
|
83
95
|
*/
|
|
84
96
|
async initialize() {
|
|
85
|
-
if (this.internalToolsProvider) {
|
|
86
|
-
await this.internalToolsProvider.initialize();
|
|
87
|
-
}
|
|
88
97
|
this.logger.debug("ToolManager initialization complete");
|
|
89
98
|
}
|
|
99
|
+
setTools(tools) {
|
|
100
|
+
this.agentTools.clear();
|
|
101
|
+
for (const tool of tools) {
|
|
102
|
+
this.agentTools.set(tool.id, tool);
|
|
103
|
+
}
|
|
104
|
+
this.invalidateCache();
|
|
105
|
+
}
|
|
106
|
+
setToolExecutionContextFactory(factory) {
|
|
107
|
+
this.toolExecutionContextFactory = factory;
|
|
108
|
+
}
|
|
109
|
+
registerCleanup(handler) {
|
|
110
|
+
this.cleanupHandlers.add(handler);
|
|
111
|
+
}
|
|
112
|
+
async cleanup() {
|
|
113
|
+
if (this.cleanupStarted) {
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
this.cleanupStarted = true;
|
|
117
|
+
for (const handler of this.cleanupHandlers) {
|
|
118
|
+
try {
|
|
119
|
+
await handler();
|
|
120
|
+
} catch (error) {
|
|
121
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
122
|
+
this.logger.warn(`ToolManager cleanup handler failed: ${err.message}`, {
|
|
123
|
+
color: "yellow"
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
90
128
|
/**
|
|
91
|
-
* Set
|
|
129
|
+
* Set hook support services (called after construction to avoid circular dependencies)
|
|
92
130
|
*/
|
|
93
|
-
|
|
94
|
-
this.
|
|
131
|
+
setHookSupport(hookManager, sessionManager, stateManager) {
|
|
132
|
+
this.hookManager = hookManager;
|
|
95
133
|
this.sessionManager = sessionManager;
|
|
96
134
|
this.stateManager = stateManager;
|
|
97
|
-
this.logger.debug("
|
|
135
|
+
this.logger.debug("Hook support configured for ToolManager");
|
|
98
136
|
}
|
|
99
137
|
/**
|
|
100
|
-
* Set
|
|
101
|
-
* Must be called before initialize() if custom tools are configured
|
|
138
|
+
* Set workspace manager for tool execution context propagation.
|
|
102
139
|
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
140
|
+
setWorkspaceManager(workspaceManager) {
|
|
141
|
+
this.workspaceManager = workspaceManager;
|
|
142
|
+
void this.refreshWorkspace();
|
|
143
|
+
if (!this.workspaceListenerAttached) {
|
|
144
|
+
this.workspaceListenerAttached = true;
|
|
145
|
+
this.agentEventBus.on(
|
|
146
|
+
"workspace:changed",
|
|
147
|
+
(payload) => {
|
|
148
|
+
this.currentWorkspace = payload.workspace ?? void 0;
|
|
149
|
+
},
|
|
150
|
+
{ signal: this.workspaceListenerAbort.signal }
|
|
151
|
+
);
|
|
152
|
+
this.registerCleanup(() => {
|
|
153
|
+
if (!this.workspaceListenerAbort.signal.aborted) {
|
|
154
|
+
this.workspaceListenerAbort.abort();
|
|
155
|
+
}
|
|
156
|
+
});
|
|
107
157
|
}
|
|
158
|
+
this.logger.debug("WorkspaceManager reference configured for ToolManager");
|
|
108
159
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
*/
|
|
113
|
-
setPromptManager(promptManager) {
|
|
114
|
-
if (this.internalToolsProvider) {
|
|
115
|
-
this.internalToolsProvider.setPromptManager(promptManager);
|
|
116
|
-
this.logger.debug("PromptManager reference configured for invoke_skill tool");
|
|
160
|
+
async refreshWorkspace() {
|
|
161
|
+
if (!this.workspaceManager) {
|
|
162
|
+
return;
|
|
117
163
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
* Called by agent-spawner custom tool provider after RuntimeService is created.
|
|
122
|
-
* This enables invoke_skill to fork execution to an isolated subagent.
|
|
123
|
-
*/
|
|
124
|
-
setTaskForker(taskForker) {
|
|
125
|
-
if (this.internalToolsProvider) {
|
|
126
|
-
this.internalToolsProvider.setTaskForker(taskForker);
|
|
164
|
+
try {
|
|
165
|
+
this.currentWorkspace = await this.workspaceManager.getWorkspace();
|
|
166
|
+
} catch (error) {
|
|
127
167
|
this.logger.debug(
|
|
128
|
-
|
|
168
|
+
`Failed to refresh workspace context: ${error instanceof Error ? error.message : String(error)}`
|
|
129
169
|
);
|
|
130
170
|
}
|
|
131
171
|
}
|
|
@@ -136,18 +176,21 @@ let _ToolManager = class _ToolManager {
|
|
|
136
176
|
* This is ADDITIVE - other tools are NOT blocked, they just go through normal approval flow.
|
|
137
177
|
*
|
|
138
178
|
* @param sessionId The session ID
|
|
139
|
-
* @param autoApproveTools Array of tool names to auto-approve (e.g., ['
|
|
179
|
+
* @param autoApproveTools Array of tool names to auto-approve (e.g., ['bash_exec', 'mcp--read_file'])
|
|
140
180
|
*/
|
|
141
181
|
setSessionAutoApproveTools(sessionId, autoApproveTools) {
|
|
142
182
|
if (autoApproveTools.length === 0) {
|
|
143
183
|
this.clearSessionAutoApproveTools(sessionId);
|
|
144
184
|
return;
|
|
145
185
|
}
|
|
146
|
-
|
|
186
|
+
const normalized = autoApproveTools.map(
|
|
187
|
+
(pattern) => this.normalizeToolPolicyPattern(pattern)
|
|
188
|
+
);
|
|
189
|
+
this.sessionAutoApproveTools.set(sessionId, normalized);
|
|
147
190
|
this.logger.info(
|
|
148
191
|
`Session auto-approve tools set for '${sessionId}': ${autoApproveTools.length} tools`
|
|
149
192
|
);
|
|
150
|
-
this.logger.debug(`Auto-approve tools: ${
|
|
193
|
+
this.logger.debug(`Auto-approve tools: ${normalized.join(", ")}`);
|
|
151
194
|
}
|
|
152
195
|
/**
|
|
153
196
|
* Set session-level auto-approve tools chosen by the user.
|
|
@@ -157,11 +200,14 @@ let _ToolManager = class _ToolManager {
|
|
|
157
200
|
this.clearSessionUserAutoApproveTools(sessionId);
|
|
158
201
|
return;
|
|
159
202
|
}
|
|
160
|
-
|
|
203
|
+
const normalized = autoApproveTools.map(
|
|
204
|
+
(pattern) => this.normalizeToolPolicyPattern(pattern)
|
|
205
|
+
);
|
|
206
|
+
this.sessionUserAutoApproveTools.set(sessionId, normalized);
|
|
161
207
|
this.logger.info(
|
|
162
208
|
`Session user auto-approve tools set for '${sessionId}': ${autoApproveTools.length} tools`
|
|
163
209
|
);
|
|
164
|
-
this.logger.debug(`User auto-approve tools: ${
|
|
210
|
+
this.logger.debug(`User auto-approve tools: ${normalized.join(", ")}`);
|
|
165
211
|
}
|
|
166
212
|
/**
|
|
167
213
|
* Clear session-level auto-approve tools chosen by the user.
|
|
@@ -338,39 +384,203 @@ let _ToolManager = class _ToolManager {
|
|
|
338
384
|
}
|
|
339
385
|
});
|
|
340
386
|
}
|
|
341
|
-
// ====================
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
isBashTool(toolName) {
|
|
346
|
-
return toolName === "bash_exec" || toolName === "internal--bash_exec" || toolName === "custom--bash_exec";
|
|
387
|
+
// ==================== Pattern Approval Helpers ====================
|
|
388
|
+
getToolApprovalPatternKeyFn(toolName) {
|
|
389
|
+
const tool = this.agentTools.get(toolName);
|
|
390
|
+
return tool?.approval?.patternKey;
|
|
347
391
|
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
392
|
+
getToolSuggestApprovalPatternsFn(toolName) {
|
|
393
|
+
const tool = this.agentTools.get(toolName);
|
|
394
|
+
return tool?.approval?.suggestPatterns;
|
|
395
|
+
}
|
|
396
|
+
getToolApprovalOverrideFn(toolName) {
|
|
397
|
+
const tool = this.agentTools.get(toolName);
|
|
398
|
+
return tool?.approval?.override;
|
|
399
|
+
}
|
|
400
|
+
getToolApprovalOnGrantedFn(toolName) {
|
|
401
|
+
const tool = this.agentTools.get(toolName);
|
|
402
|
+
return tool?.approval?.onGranted;
|
|
403
|
+
}
|
|
404
|
+
getToolPreviewFn(toolName) {
|
|
405
|
+
const tool = this.agentTools.get(toolName);
|
|
406
|
+
return tool?.presentation?.preview;
|
|
407
|
+
}
|
|
408
|
+
getToolDescribeHeaderFn(toolName) {
|
|
409
|
+
const tool = this.agentTools.get(toolName);
|
|
410
|
+
return tool?.presentation?.describeHeader;
|
|
411
|
+
}
|
|
412
|
+
getToolDescribeArgsFn(toolName) {
|
|
413
|
+
const tool = this.agentTools.get(toolName);
|
|
414
|
+
return tool?.presentation?.describeArgs;
|
|
415
|
+
}
|
|
416
|
+
getToolDescribeResultFn(toolName) {
|
|
417
|
+
const tool = this.agentTools.get(toolName);
|
|
418
|
+
return tool?.presentation?.describeResult;
|
|
419
|
+
}
|
|
420
|
+
buildGenericToolPresentationSnapshot(toolName) {
|
|
421
|
+
const toTitleCase = (name) => name.replace(/[_-]+/g, " ").split(" ").filter(Boolean).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join(" ");
|
|
422
|
+
const isMcp = toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX);
|
|
423
|
+
const fallbackTitle = (() => {
|
|
424
|
+
if (!isMcp) {
|
|
425
|
+
return toTitleCase(toolName);
|
|
426
|
+
}
|
|
427
|
+
const actualToolName = toolName.substring(_ToolManager.MCP_TOOL_PREFIX.length);
|
|
428
|
+
const parts = actualToolName.split("--");
|
|
429
|
+
const toolPart = parts.length >= 2 ? parts.slice(1).join("--") : actualToolName;
|
|
430
|
+
return toTitleCase(toolPart);
|
|
431
|
+
})();
|
|
432
|
+
const snapshot = {
|
|
433
|
+
version: 1,
|
|
434
|
+
source: {
|
|
435
|
+
type: toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX) ? "mcp" : "local"
|
|
436
|
+
},
|
|
437
|
+
header: {
|
|
438
|
+
title: fallbackTitle
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
if (snapshot.source?.type === "mcp") {
|
|
442
|
+
const actualToolName = toolName.substring(_ToolManager.MCP_TOOL_PREFIX.length);
|
|
443
|
+
const parts = actualToolName.split("--");
|
|
444
|
+
if (parts.length >= 2 && parts[0]) {
|
|
445
|
+
snapshot.source.mcpServerName = parts[0];
|
|
361
446
|
}
|
|
362
|
-
return { approved: false, suggestedPatterns: [] };
|
|
363
447
|
}
|
|
364
|
-
|
|
365
|
-
|
|
448
|
+
return snapshot;
|
|
449
|
+
}
|
|
450
|
+
getToolPresentationSnapshotForToolCallEvent(toolName, args, toolCallId, sessionId) {
|
|
451
|
+
const fallback = this.buildGenericToolPresentationSnapshot(toolName);
|
|
452
|
+
if (toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
453
|
+
return fallback;
|
|
454
|
+
}
|
|
455
|
+
const describeHeader = this.getToolDescribeHeaderFn(toolName);
|
|
456
|
+
const describeArgs = this.getToolDescribeArgsFn(toolName);
|
|
457
|
+
if (!describeHeader && !describeArgs) {
|
|
458
|
+
return fallback;
|
|
459
|
+
}
|
|
460
|
+
try {
|
|
461
|
+
const validatedArgs = this.validateLocalToolArgs(toolName, args);
|
|
462
|
+
const context = this.buildToolExecutionContext({ sessionId, toolCallId });
|
|
463
|
+
const isPromiseLike = (value) => {
|
|
464
|
+
if (typeof value !== "object" || value === null) {
|
|
465
|
+
return false;
|
|
466
|
+
}
|
|
467
|
+
return typeof value.then === "function";
|
|
468
|
+
};
|
|
469
|
+
let nextSnapshot = fallback;
|
|
470
|
+
if (describeHeader) {
|
|
471
|
+
const header = describeHeader(validatedArgs, context);
|
|
472
|
+
if (!isPromiseLike(header) && header) {
|
|
473
|
+
nextSnapshot = {
|
|
474
|
+
...nextSnapshot,
|
|
475
|
+
header: { ...nextSnapshot.header, ...header }
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
if (describeArgs) {
|
|
480
|
+
const argsPresentation = describeArgs(validatedArgs, context);
|
|
481
|
+
if (!isPromiseLike(argsPresentation) && argsPresentation) {
|
|
482
|
+
nextSnapshot = {
|
|
483
|
+
...nextSnapshot,
|
|
484
|
+
args: argsPresentation
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
return nextSnapshot;
|
|
489
|
+
} catch (error) {
|
|
490
|
+
this.logger.debug(
|
|
491
|
+
`Tool presentation snapshot generation failed for '${toolName}': ${error instanceof Error ? error.message : String(error)}`
|
|
492
|
+
);
|
|
493
|
+
return fallback;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
async getToolPresentationSnapshotForCall(toolName, args, toolCallId, sessionId) {
|
|
497
|
+
const fallback = this.buildGenericToolPresentationSnapshot(toolName);
|
|
498
|
+
if (toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
499
|
+
return fallback;
|
|
500
|
+
}
|
|
501
|
+
const describeHeader = this.getToolDescribeHeaderFn(toolName);
|
|
502
|
+
const describeArgs = this.getToolDescribeArgsFn(toolName);
|
|
503
|
+
if (!describeHeader && !describeArgs) {
|
|
504
|
+
return fallback;
|
|
505
|
+
}
|
|
506
|
+
try {
|
|
507
|
+
const context = this.buildToolExecutionContext({ sessionId, toolCallId });
|
|
508
|
+
const describedHeader = describeHeader ? await Promise.resolve(describeHeader(args, context)) : null;
|
|
509
|
+
const describedArgs = describeArgs ? await Promise.resolve(describeArgs(args, context)) : null;
|
|
510
|
+
return {
|
|
511
|
+
...fallback,
|
|
512
|
+
...describedHeader ? { header: { ...fallback.header, ...describedHeader } } : {},
|
|
513
|
+
...describedArgs ? { args: describedArgs } : {}
|
|
514
|
+
};
|
|
515
|
+
} catch (error) {
|
|
516
|
+
this.logger.debug(
|
|
517
|
+
`Tool presentation snapshot generation failed for '${toolName}': ${error instanceof Error ? error.message : String(error)}`
|
|
518
|
+
);
|
|
519
|
+
return fallback;
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
async augmentSnapshotWithResult(toolName, snapshot, result, args, toolCallId, sessionId) {
|
|
523
|
+
if (toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
524
|
+
return snapshot;
|
|
525
|
+
}
|
|
526
|
+
const describeResult = this.getToolDescribeResultFn(toolName);
|
|
527
|
+
if (!describeResult) {
|
|
528
|
+
return snapshot;
|
|
529
|
+
}
|
|
530
|
+
try {
|
|
531
|
+
const context = this.buildToolExecutionContext({ sessionId, toolCallId });
|
|
532
|
+
const resultPresentation = await Promise.resolve(describeResult(result, args, context));
|
|
533
|
+
if (!resultPresentation) {
|
|
534
|
+
return snapshot;
|
|
535
|
+
}
|
|
536
|
+
return {
|
|
537
|
+
...snapshot,
|
|
538
|
+
result: resultPresentation
|
|
539
|
+
};
|
|
540
|
+
} catch (error) {
|
|
541
|
+
this.logger.debug(
|
|
542
|
+
`Tool result presentation snapshot generation failed for '${toolName}': ${error instanceof Error ? error.message : String(error)}`
|
|
543
|
+
);
|
|
544
|
+
return snapshot;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
getToolPatternKey(toolName, args) {
|
|
548
|
+
if (toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
549
|
+
return null;
|
|
550
|
+
}
|
|
551
|
+
const getPatternKey = this.getToolApprovalPatternKeyFn(toolName);
|
|
552
|
+
if (!getPatternKey) {
|
|
553
|
+
return null;
|
|
554
|
+
}
|
|
555
|
+
try {
|
|
556
|
+
return getPatternKey(args);
|
|
557
|
+
} catch (error) {
|
|
558
|
+
this.logger.debug(
|
|
559
|
+
`Pattern key generation failed for '${toolName}': ${error instanceof Error ? error.message : String(error)}`
|
|
560
|
+
);
|
|
561
|
+
return null;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
getToolSuggestedPatterns(toolName, args) {
|
|
565
|
+
if (toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
566
|
+
return void 0;
|
|
567
|
+
}
|
|
568
|
+
const suggestPatterns = this.getToolSuggestApprovalPatternsFn(toolName);
|
|
569
|
+
if (!suggestPatterns) {
|
|
570
|
+
return void 0;
|
|
571
|
+
}
|
|
572
|
+
try {
|
|
573
|
+
const patterns = suggestPatterns(args);
|
|
574
|
+
return patterns.length > 0 ? patterns : void 0;
|
|
575
|
+
} catch (error) {
|
|
576
|
+
this.logger.debug(
|
|
577
|
+
`Pattern suggestion failed for '${toolName}': ${error instanceof Error ? error.message : String(error)}`
|
|
578
|
+
);
|
|
579
|
+
return void 0;
|
|
366
580
|
}
|
|
367
|
-
return {
|
|
368
|
-
approved: false,
|
|
369
|
-
suggestedPatterns: generateBashPatternSuggestions(command)
|
|
370
|
-
};
|
|
371
581
|
}
|
|
372
582
|
/**
|
|
373
|
-
* Auto-approve pending tool
|
|
583
|
+
* Auto-approve pending tool approval requests for the same tool.
|
|
374
584
|
* Called after a user selects "remember choice" for a tool.
|
|
375
585
|
* This handles the case where parallel tool calls come in before the first one is approved.
|
|
376
586
|
*
|
|
@@ -380,14 +590,13 @@ let _ToolManager = class _ToolManager {
|
|
|
380
590
|
autoApprovePendingToolRequests(toolName, sessionId) {
|
|
381
591
|
const count = this.approvalManager.autoApprovePendingRequests(
|
|
382
592
|
(request) => {
|
|
383
|
-
if (request.type !== ApprovalType.
|
|
593
|
+
if (request.type !== ApprovalType.TOOL_APPROVAL) {
|
|
384
594
|
return false;
|
|
385
595
|
}
|
|
386
596
|
if (request.sessionId !== sessionId) {
|
|
387
597
|
return false;
|
|
388
598
|
}
|
|
389
|
-
|
|
390
|
-
return metadata.toolName === toolName;
|
|
599
|
+
return request.metadata.toolName === toolName;
|
|
391
600
|
},
|
|
392
601
|
{ rememberChoice: false }
|
|
393
602
|
// Don't propagate remember choice to auto-approved requests
|
|
@@ -399,48 +608,86 @@ let _ToolManager = class _ToolManager {
|
|
|
399
608
|
}
|
|
400
609
|
}
|
|
401
610
|
/**
|
|
402
|
-
* Auto-approve pending
|
|
403
|
-
* Called after a user selects "remember pattern" for a
|
|
404
|
-
* This handles the case where parallel bash commands come in before the first one is approved.
|
|
405
|
-
*
|
|
406
|
-
* @param pattern The bash pattern that was just remembered
|
|
407
|
-
* @param sessionId The session ID for context
|
|
611
|
+
* Auto-approve pending tool approval requests that are now covered by a remembered pattern.
|
|
612
|
+
* Called after a user selects "remember pattern" for a tool.
|
|
408
613
|
*/
|
|
409
|
-
|
|
614
|
+
autoApprovePendingPatternRequests(toolName, sessionId) {
|
|
615
|
+
if (toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
const getPatternKey = this.getToolApprovalPatternKeyFn(toolName);
|
|
619
|
+
if (!getPatternKey) {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
410
622
|
const count = this.approvalManager.autoApprovePendingRequests(
|
|
411
623
|
(request) => {
|
|
412
|
-
if (request.type !== ApprovalType.
|
|
624
|
+
if (request.type !== ApprovalType.TOOL_APPROVAL) {
|
|
413
625
|
return false;
|
|
414
626
|
}
|
|
415
627
|
if (request.sessionId !== sessionId) {
|
|
416
628
|
return false;
|
|
417
629
|
}
|
|
418
|
-
|
|
419
|
-
if (!this.isBashTool(metadata.toolName)) {
|
|
630
|
+
if (request.metadata.toolName !== toolName) {
|
|
420
631
|
return false;
|
|
421
632
|
}
|
|
422
|
-
const
|
|
423
|
-
if (
|
|
633
|
+
const args = request.metadata.args;
|
|
634
|
+
if (typeof args !== "object" || args === null) {
|
|
424
635
|
return false;
|
|
425
636
|
}
|
|
426
|
-
const
|
|
427
|
-
|
|
637
|
+
const argsRecord = args;
|
|
638
|
+
let patternKey;
|
|
639
|
+
try {
|
|
640
|
+
patternKey = getPatternKey(argsRecord);
|
|
641
|
+
} catch (error) {
|
|
642
|
+
this.logger.debug(
|
|
643
|
+
`Pattern key generation failed for '${toolName}': ${error instanceof Error ? error.message : String(error)}`
|
|
644
|
+
);
|
|
428
645
|
return false;
|
|
429
646
|
}
|
|
430
|
-
|
|
647
|
+
if (!patternKey) return false;
|
|
648
|
+
return this.approvalManager.matchesPattern(toolName, patternKey);
|
|
431
649
|
},
|
|
432
650
|
{ rememberPattern: void 0 }
|
|
433
|
-
// Don't propagate pattern to auto-approved requests
|
|
651
|
+
// Don't propagate pattern choice to auto-approved requests
|
|
434
652
|
);
|
|
435
653
|
if (count > 0) {
|
|
436
654
|
this.logger.info(
|
|
437
|
-
`Auto-approved ${count} parallel
|
|
655
|
+
`Auto-approved ${count} parallel request(s) for tool '${toolName}' after user selected "remember pattern"`
|
|
438
656
|
);
|
|
439
657
|
}
|
|
440
658
|
}
|
|
441
659
|
getMcpManager() {
|
|
442
660
|
return this.mcpManager;
|
|
443
661
|
}
|
|
662
|
+
setContributorContextFactory(factory) {
|
|
663
|
+
this.contributorContextFactory = factory ?? void 0;
|
|
664
|
+
}
|
|
665
|
+
async buildContributorContext() {
|
|
666
|
+
const baseWorkspace = this.currentWorkspace ?? null;
|
|
667
|
+
const baseContext = {
|
|
668
|
+
mcpManager: this.mcpManager,
|
|
669
|
+
workspace: baseWorkspace
|
|
670
|
+
};
|
|
671
|
+
if (!this.contributorContextFactory) {
|
|
672
|
+
return baseContext;
|
|
673
|
+
}
|
|
674
|
+
try {
|
|
675
|
+
const overrides = await this.contributorContextFactory() ?? {};
|
|
676
|
+
const workspace = overrides.workspace !== void 0 ? overrides.workspace : baseWorkspace;
|
|
677
|
+
const environment = overrides.environment !== void 0 ? overrides.environment : baseContext.environment;
|
|
678
|
+
const mcpManager = overrides.mcpManager ?? baseContext.mcpManager;
|
|
679
|
+
return {
|
|
680
|
+
mcpManager,
|
|
681
|
+
workspace,
|
|
682
|
+
...environment !== void 0 ? { environment } : {}
|
|
683
|
+
};
|
|
684
|
+
} catch (error) {
|
|
685
|
+
this.logger.warn(
|
|
686
|
+
`Failed to build contributor context: ${error instanceof Error ? error.message : String(error)}`
|
|
687
|
+
);
|
|
688
|
+
return baseContext;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
444
691
|
/**
|
|
445
692
|
* Get all MCP tools (delegates to mcpManager.getAllTools())
|
|
446
693
|
* This provides access to MCP tools while maintaining separation of concerns
|
|
@@ -448,11 +695,66 @@ let _ToolManager = class _ToolManager {
|
|
|
448
695
|
async getMcpTools() {
|
|
449
696
|
return await this.mcpManager.getAllTools();
|
|
450
697
|
}
|
|
698
|
+
buildToolExecutionContext(options) {
|
|
699
|
+
const workspace = this.currentWorkspace;
|
|
700
|
+
const baseContext = {
|
|
701
|
+
sessionId: options.sessionId,
|
|
702
|
+
workspaceId: workspace?.id,
|
|
703
|
+
workspace,
|
|
704
|
+
abortSignal: options.abortSignal,
|
|
705
|
+
toolCallId: options.toolCallId,
|
|
706
|
+
logger: this.logger
|
|
707
|
+
};
|
|
708
|
+
return this.toolExecutionContextFactory(baseContext);
|
|
709
|
+
}
|
|
710
|
+
validateLocalToolArgs(toolName, args) {
|
|
711
|
+
if (toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
712
|
+
return args;
|
|
713
|
+
}
|
|
714
|
+
const tool = this.agentTools.get(toolName);
|
|
715
|
+
if (!tool) {
|
|
716
|
+
return args;
|
|
717
|
+
}
|
|
718
|
+
const validationResult = tool.inputSchema.safeParse(args);
|
|
719
|
+
if (!validationResult.success) {
|
|
720
|
+
this.logger.error(
|
|
721
|
+
`\u274C Invalid arguments for tool ${toolName}: ${validationResult.error.message}`
|
|
722
|
+
);
|
|
723
|
+
throw ToolError.validationFailed(
|
|
724
|
+
toolName,
|
|
725
|
+
`Invalid arguments: ${validationResult.error.message}`
|
|
726
|
+
);
|
|
727
|
+
}
|
|
728
|
+
const validated = validationResult.data;
|
|
729
|
+
if (typeof validated !== "object" || validated === null || Array.isArray(validated)) {
|
|
730
|
+
throw ToolError.validationFailed(toolName, "Invalid arguments: expected an object");
|
|
731
|
+
}
|
|
732
|
+
return validated;
|
|
733
|
+
}
|
|
734
|
+
async executeLocalTool(toolName, args, sessionId, abortSignal, toolCallId) {
|
|
735
|
+
const tool = this.agentTools.get(toolName);
|
|
736
|
+
if (!tool) {
|
|
737
|
+
this.logger.error(`\u274C No local tool found: ${toolName}`);
|
|
738
|
+
this.logger.debug(
|
|
739
|
+
`Available local tools: ${Array.from(this.agentTools.keys()).join(", ")}`
|
|
740
|
+
);
|
|
741
|
+
throw ToolError.notFound(toolName);
|
|
742
|
+
}
|
|
743
|
+
try {
|
|
744
|
+
const context = this.buildToolExecutionContext({ sessionId, abortSignal, toolCallId });
|
|
745
|
+
const result = await tool.execute(args, context);
|
|
746
|
+
return result;
|
|
747
|
+
} catch (error) {
|
|
748
|
+
this.logger.error(`\u274C Local tool execution failed: ${toolName}`, {
|
|
749
|
+
error: error instanceof Error ? error.message : String(error)
|
|
750
|
+
});
|
|
751
|
+
throw error;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
451
754
|
/**
|
|
452
|
-
* Build all tools from sources
|
|
453
|
-
* ALL tools get prefixed by their source - no exceptions
|
|
755
|
+
* Build all tools from sources.
|
|
454
756
|
*
|
|
455
|
-
* TODO: Rethink tool naming convention for more consistency
|
|
757
|
+
* TODO: Rethink MCP tool naming convention for more consistency.
|
|
456
758
|
* Current issue: MCP tools have dynamic naming based on conflicts:
|
|
457
759
|
* - No conflict: mcp--toolName
|
|
458
760
|
* - With conflict: mcp--serverName--toolName
|
|
@@ -465,8 +767,6 @@ let _ToolManager = class _ToolManager {
|
|
|
465
767
|
async buildAllTools() {
|
|
466
768
|
const allTools = {};
|
|
467
769
|
let mcpTools = {};
|
|
468
|
-
let internalTools = {};
|
|
469
|
-
let customTools = {};
|
|
470
770
|
try {
|
|
471
771
|
mcpTools = await this.mcpManager.getAllTools();
|
|
472
772
|
} catch (error) {
|
|
@@ -475,38 +775,13 @@ let _ToolManager = class _ToolManager {
|
|
|
475
775
|
);
|
|
476
776
|
mcpTools = {};
|
|
477
777
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
}
|
|
486
|
-
try {
|
|
487
|
-
customTools = this.internalToolsProvider?.getCustomTools() || {};
|
|
488
|
-
} catch (error) {
|
|
489
|
-
this.logger.error(
|
|
490
|
-
`Failed to get custom tools: ${error instanceof Error ? error.message : String(error)}`
|
|
491
|
-
);
|
|
492
|
-
customTools = {};
|
|
493
|
-
}
|
|
494
|
-
for (const [toolName, toolDef] of Object.entries(internalTools)) {
|
|
495
|
-
const qualifiedName = `${_ToolManager.INTERNAL_TOOL_PREFIX}${toolName}`;
|
|
496
|
-
allTools[qualifiedName] = {
|
|
497
|
-
...toolDef,
|
|
498
|
-
name: qualifiedName,
|
|
499
|
-
description: `${toolDef.description || "No description provided"} (internal tool)`,
|
|
500
|
-
parameters: wrapToolParametersSchema(toolDef.parameters)
|
|
501
|
-
};
|
|
502
|
-
}
|
|
503
|
-
for (const [toolName, toolDef] of Object.entries(customTools)) {
|
|
504
|
-
const qualifiedName = `${_ToolManager.CUSTOM_TOOL_PREFIX}${toolName}`;
|
|
505
|
-
allTools[qualifiedName] = {
|
|
506
|
-
...toolDef,
|
|
507
|
-
name: qualifiedName,
|
|
508
|
-
description: `${toolDef.description || "No description provided"} (custom tool)`,
|
|
509
|
-
parameters: wrapToolParametersSchema(toolDef.parameters)
|
|
778
|
+
for (const [toolName, tool] of this.agentTools) {
|
|
779
|
+
allTools[toolName] = {
|
|
780
|
+
name: toolName,
|
|
781
|
+
description: tool.description || "No description provided",
|
|
782
|
+
parameters: wrapToolParametersSchema(
|
|
783
|
+
convertZodSchemaToJsonSchema(tool.inputSchema, this.logger)
|
|
784
|
+
)
|
|
510
785
|
};
|
|
511
786
|
}
|
|
512
787
|
for (const [toolName, toolDef] of Object.entries(mcpTools)) {
|
|
@@ -520,10 +795,9 @@ let _ToolManager = class _ToolManager {
|
|
|
520
795
|
}
|
|
521
796
|
const totalTools = Object.keys(allTools).length;
|
|
522
797
|
const mcpCount = Object.keys(mcpTools).length;
|
|
523
|
-
const
|
|
524
|
-
const customCount = Object.keys(customTools).length;
|
|
798
|
+
const localCount = this.agentTools.size;
|
|
525
799
|
this.logger.debug(
|
|
526
|
-
`\u{1F527} Unified tool discovery: ${totalTools} total tools (${mcpCount} MCP, ${
|
|
800
|
+
`\u{1F527} Unified tool discovery: ${totalTools} total tools (${mcpCount} MCP, ${localCount} local)`
|
|
527
801
|
);
|
|
528
802
|
return allTools;
|
|
529
803
|
}
|
|
@@ -541,10 +815,11 @@ let _ToolManager = class _ToolManager {
|
|
|
541
815
|
return this.toolsCache;
|
|
542
816
|
}
|
|
543
817
|
/**
|
|
544
|
-
* Execute a tool by routing based on
|
|
545
|
-
*
|
|
818
|
+
* Execute a tool by routing based on prefix:
|
|
819
|
+
* - MCP tools: `mcp--...`
|
|
820
|
+
* - Local tools: `Tool.id`
|
|
546
821
|
*
|
|
547
|
-
* @param toolName
|
|
822
|
+
* @param toolName Tool name (e.g., "edit_file", "mcp--filesystem--read_file")
|
|
548
823
|
* @param args The arguments for the tool
|
|
549
824
|
* @param toolCallId The unique tool call ID for tracking (from LLM or generated for direct calls)
|
|
550
825
|
* @param sessionId Optional session ID for context
|
|
@@ -553,24 +828,39 @@ let _ToolManager = class _ToolManager {
|
|
|
553
828
|
async executeTool(toolName, args, toolCallId, sessionId, abortSignal) {
|
|
554
829
|
const { toolArgs: rawToolArgs, meta } = extractToolCallMeta(args);
|
|
555
830
|
let toolArgs = rawToolArgs;
|
|
831
|
+
const callDescription = typeof meta.callDescription === "string" ? meta.callDescription : typeof rawToolArgs.description === "string" ? rawToolArgs.description : void 0;
|
|
556
832
|
const backgroundTasksEnabled = isBackgroundTasksEnabled();
|
|
557
833
|
this.logger.debug(`\u{1F527} Tool execution requested: '${toolName}' (toolCallId: ${toolCallId})`);
|
|
558
834
|
this.logger.debug(`Tool args: ${JSON.stringify(toolArgs, null, 2)}`);
|
|
559
835
|
if (sessionId) {
|
|
836
|
+
const presentationSnapshot = this.getToolPresentationSnapshotForToolCallEvent(
|
|
837
|
+
toolName,
|
|
838
|
+
toolArgs,
|
|
839
|
+
toolCallId,
|
|
840
|
+
sessionId
|
|
841
|
+
);
|
|
560
842
|
this.agentEventBus.emit("llm:tool-call", {
|
|
561
843
|
toolName,
|
|
844
|
+
presentationSnapshot,
|
|
562
845
|
args: toolArgs,
|
|
846
|
+
...callDescription !== void 0 && { callDescription },
|
|
563
847
|
callId: toolCallId,
|
|
564
848
|
sessionId
|
|
565
849
|
});
|
|
566
850
|
}
|
|
567
|
-
const {
|
|
851
|
+
const {
|
|
852
|
+
requireApproval,
|
|
853
|
+
approvalStatus,
|
|
854
|
+
args: validatedToolArgs,
|
|
855
|
+
presentationSnapshot: callSnapshot
|
|
856
|
+
} = await this.handleToolApproval(
|
|
568
857
|
toolName,
|
|
569
858
|
toolArgs,
|
|
570
859
|
toolCallId,
|
|
571
860
|
sessionId,
|
|
572
|
-
|
|
861
|
+
callDescription
|
|
573
862
|
);
|
|
863
|
+
toolArgs = validatedToolArgs;
|
|
574
864
|
this.logger.debug(`\u2705 Tool execution approved: ${toolName}`);
|
|
575
865
|
this.logger.info(
|
|
576
866
|
`\u{1F527} Tool execution started for ${toolName}, sessionId: ${sessionId ?? "global"}`
|
|
@@ -583,13 +873,13 @@ let _ToolManager = class _ToolManager {
|
|
|
583
873
|
});
|
|
584
874
|
}
|
|
585
875
|
const startTime = Date.now();
|
|
586
|
-
if (this.
|
|
876
|
+
if (this.hookManager && this.sessionManager && this.stateManager) {
|
|
587
877
|
const beforePayload = {
|
|
588
878
|
toolName,
|
|
589
879
|
args: toolArgs,
|
|
590
880
|
...sessionId !== void 0 && { sessionId }
|
|
591
881
|
};
|
|
592
|
-
const modifiedPayload = await this.
|
|
882
|
+
const modifiedPayload = await this.hookManager.executeHooks(
|
|
593
883
|
"beforeToolCall",
|
|
594
884
|
beforePayload,
|
|
595
885
|
{
|
|
@@ -601,6 +891,14 @@ let _ToolManager = class _ToolManager {
|
|
|
601
891
|
}
|
|
602
892
|
);
|
|
603
893
|
toolArgs = modifiedPayload.args;
|
|
894
|
+
try {
|
|
895
|
+
toolArgs = this.validateLocalToolArgs(toolName, toolArgs);
|
|
896
|
+
} catch (error) {
|
|
897
|
+
this.logger.error(
|
|
898
|
+
`Post-hook validation failed for tool '${toolName}': a beforeToolCall hook may have set invalid args`
|
|
899
|
+
);
|
|
900
|
+
throw error;
|
|
901
|
+
}
|
|
604
902
|
}
|
|
605
903
|
try {
|
|
606
904
|
let result;
|
|
@@ -650,16 +948,7 @@ let _ToolManager = class _ToolManager {
|
|
|
650
948
|
} else {
|
|
651
949
|
result = await this.mcpManager.executeTool(actualToolName, toolArgs, sessionId);
|
|
652
950
|
}
|
|
653
|
-
} else
|
|
654
|
-
this.logger.debug(`\u{1F527} Detected internal tool: '${toolName}'`);
|
|
655
|
-
const actualToolName = toolName.substring(_ToolManager.INTERNAL_TOOL_PREFIX.length);
|
|
656
|
-
if (actualToolName.length === 0) {
|
|
657
|
-
throw ToolError.invalidName(toolName, "tool name cannot be empty after prefix");
|
|
658
|
-
}
|
|
659
|
-
if (!this.internalToolsProvider) {
|
|
660
|
-
throw ToolError.internalToolsNotInitialized(toolName);
|
|
661
|
-
}
|
|
662
|
-
this.logger.debug(`\u{1F3AF} Internal routing: '${toolName}' -> '${actualToolName}'`);
|
|
951
|
+
} else {
|
|
663
952
|
const runInBackground = backgroundTasksEnabled && meta.runInBackground === true && sessionId !== void 0;
|
|
664
953
|
if (meta.runInBackground === true && !backgroundTasksEnabled) {
|
|
665
954
|
this.logger.debug(
|
|
@@ -670,14 +959,14 @@ let _ToolManager = class _ToolManager {
|
|
|
670
959
|
if (runInBackground) {
|
|
671
960
|
const backgroundSessionId = sessionId;
|
|
672
961
|
const { result: backgroundResult, promise } = registerBackgroundTask(
|
|
673
|
-
this.
|
|
674
|
-
|
|
962
|
+
this.executeLocalTool(
|
|
963
|
+
toolName,
|
|
675
964
|
toolArgs,
|
|
676
965
|
backgroundSessionId,
|
|
677
966
|
abortSignal,
|
|
678
967
|
toolCallId
|
|
679
968
|
),
|
|
680
|
-
`
|
|
969
|
+
`Tool ${toolName}`
|
|
681
970
|
);
|
|
682
971
|
this.agentEventBus.emit("tool:background", {
|
|
683
972
|
toolName,
|
|
@@ -692,88 +981,28 @@ let _ToolManager = class _ToolManager {
|
|
|
692
981
|
});
|
|
693
982
|
result = backgroundResult;
|
|
694
983
|
} else {
|
|
695
|
-
result = await this.
|
|
696
|
-
actualToolName,
|
|
697
|
-
toolArgs,
|
|
698
|
-
sessionId,
|
|
699
|
-
abortSignal,
|
|
700
|
-
toolCallId
|
|
701
|
-
);
|
|
702
|
-
}
|
|
703
|
-
} else if (toolName.startsWith(_ToolManager.CUSTOM_TOOL_PREFIX)) {
|
|
704
|
-
this.logger.debug(`\u{1F527} Detected custom tool: '${toolName}'`);
|
|
705
|
-
const actualToolName = toolName.substring(_ToolManager.CUSTOM_TOOL_PREFIX.length);
|
|
706
|
-
if (actualToolName.length === 0) {
|
|
707
|
-
throw ToolError.invalidName(toolName, "tool name cannot be empty after prefix");
|
|
708
|
-
}
|
|
709
|
-
if (!this.internalToolsProvider) {
|
|
710
|
-
throw ToolError.internalToolsNotInitialized(toolName);
|
|
711
|
-
}
|
|
712
|
-
this.logger.debug(`\u{1F3AF} Custom routing: '${toolName}' -> '${actualToolName}'`);
|
|
713
|
-
const runInBackground = backgroundTasksEnabled && meta.runInBackground === true && sessionId !== void 0;
|
|
714
|
-
if (meta.runInBackground === true && !backgroundTasksEnabled) {
|
|
715
|
-
this.logger.debug(
|
|
716
|
-
"Background tool execution disabled; running synchronously instead.",
|
|
717
|
-
{ toolName }
|
|
718
|
-
);
|
|
719
|
-
}
|
|
720
|
-
if (runInBackground) {
|
|
721
|
-
const backgroundSessionId = sessionId;
|
|
722
|
-
const { result: backgroundResult, promise } = registerBackgroundTask(
|
|
723
|
-
this.internalToolsProvider.executeTool(
|
|
724
|
-
actualToolName,
|
|
725
|
-
toolArgs,
|
|
726
|
-
backgroundSessionId,
|
|
727
|
-
abortSignal,
|
|
728
|
-
toolCallId
|
|
729
|
-
),
|
|
730
|
-
`Custom tool ${actualToolName}`
|
|
731
|
-
);
|
|
732
|
-
this.agentEventBus.emit("tool:background", {
|
|
984
|
+
result = await this.executeLocalTool(
|
|
733
985
|
toolName,
|
|
734
|
-
toolCallId: backgroundResult.taskId,
|
|
735
|
-
sessionId: backgroundSessionId,
|
|
736
|
-
description: backgroundResult.description,
|
|
737
|
-
promise,
|
|
738
|
-
...meta.timeoutMs !== void 0 && { timeoutMs: meta.timeoutMs },
|
|
739
|
-
...meta.notifyOnComplete !== void 0 && {
|
|
740
|
-
notifyOnComplete: meta.notifyOnComplete
|
|
741
|
-
}
|
|
742
|
-
});
|
|
743
|
-
result = backgroundResult;
|
|
744
|
-
} else {
|
|
745
|
-
result = await this.internalToolsProvider.executeTool(
|
|
746
|
-
actualToolName,
|
|
747
986
|
toolArgs,
|
|
748
987
|
sessionId,
|
|
749
988
|
abortSignal,
|
|
750
989
|
toolCallId
|
|
751
990
|
);
|
|
752
991
|
}
|
|
753
|
-
} else {
|
|
754
|
-
this.logger.debug(`\u{1F527} Detected tool without proper prefix: '${toolName}'`);
|
|
755
|
-
const stats = await this.getToolStats();
|
|
756
|
-
this.logger.error(
|
|
757
|
-
`\u274C Tool missing source prefix: '${toolName}' (expected '${_ToolManager.MCP_TOOL_PREFIX}*', '${_ToolManager.INTERNAL_TOOL_PREFIX}*', or '${_ToolManager.CUSTOM_TOOL_PREFIX}*')`
|
|
758
|
-
);
|
|
759
|
-
this.logger.debug(
|
|
760
|
-
`Available: ${stats.mcp} MCP, ${stats.internal} internal, ${stats.custom} custom tools`
|
|
761
|
-
);
|
|
762
|
-
throw ToolError.notFound(toolName);
|
|
763
992
|
}
|
|
764
993
|
const duration = Date.now() - startTime;
|
|
765
994
|
this.logger.debug(`\u{1F3AF} Tool execution completed in ${duration}ms: '${toolName}'`);
|
|
766
995
|
this.logger.info(
|
|
767
996
|
`\u2705 Tool execution completed successfully for ${toolName} in ${duration}ms, sessionId: ${sessionId ?? "global"}`
|
|
768
997
|
);
|
|
769
|
-
if (this.
|
|
998
|
+
if (this.hookManager && this.sessionManager && this.stateManager) {
|
|
770
999
|
const afterPayload = {
|
|
771
1000
|
toolName,
|
|
772
1001
|
result,
|
|
773
1002
|
success: true,
|
|
774
1003
|
...sessionId !== void 0 && { sessionId }
|
|
775
1004
|
};
|
|
776
|
-
const modifiedPayload = await this.
|
|
1005
|
+
const modifiedPayload = await this.hookManager.executeHooks(
|
|
777
1006
|
"afterToolResult",
|
|
778
1007
|
afterPayload,
|
|
779
1008
|
{
|
|
@@ -786,8 +1015,17 @@ let _ToolManager = class _ToolManager {
|
|
|
786
1015
|
);
|
|
787
1016
|
result = modifiedPayload.result;
|
|
788
1017
|
}
|
|
1018
|
+
const presentationSnapshot = await this.augmentSnapshotWithResult(
|
|
1019
|
+
toolName,
|
|
1020
|
+
callSnapshot,
|
|
1021
|
+
result,
|
|
1022
|
+
toolArgs,
|
|
1023
|
+
toolCallId,
|
|
1024
|
+
sessionId
|
|
1025
|
+
);
|
|
789
1026
|
return {
|
|
790
1027
|
result,
|
|
1028
|
+
...presentationSnapshot !== void 0 && { presentationSnapshot },
|
|
791
1029
|
...requireApproval && { requireApproval, approvalStatus }
|
|
792
1030
|
};
|
|
793
1031
|
} catch (error) {
|
|
@@ -795,14 +1033,14 @@ let _ToolManager = class _ToolManager {
|
|
|
795
1033
|
this.logger.error(
|
|
796
1034
|
`\u274C Tool execution failed for ${toolName} after ${duration}ms, sessionId: ${sessionId ?? "global"}: ${error instanceof Error ? error.message : String(error)}`
|
|
797
1035
|
);
|
|
798
|
-
if (this.
|
|
1036
|
+
if (this.hookManager && this.sessionManager && this.stateManager) {
|
|
799
1037
|
const afterPayload = {
|
|
800
1038
|
toolName,
|
|
801
1039
|
result: error instanceof Error ? error.message : String(error),
|
|
802
1040
|
success: false,
|
|
803
1041
|
...sessionId !== void 0 && { sessionId }
|
|
804
1042
|
};
|
|
805
|
-
await this.
|
|
1043
|
+
await this.hookManager.executeHooks("afterToolResult", afterPayload, {
|
|
806
1044
|
sessionManager: this.sessionManager,
|
|
807
1045
|
mcpManager: this.mcpManager,
|
|
808
1046
|
toolManager: this,
|
|
@@ -814,30 +1052,20 @@ let _ToolManager = class _ToolManager {
|
|
|
814
1052
|
}
|
|
815
1053
|
}
|
|
816
1054
|
/**
|
|
817
|
-
* Check if a tool exists
|
|
1055
|
+
* Check if a tool exists.
|
|
818
1056
|
*/
|
|
819
1057
|
async hasTool(toolName) {
|
|
820
1058
|
if (toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
821
1059
|
const actualToolName = toolName.substring(_ToolManager.MCP_TOOL_PREFIX.length);
|
|
822
1060
|
return this.mcpManager.getToolClient(actualToolName) !== void 0;
|
|
823
1061
|
}
|
|
824
|
-
|
|
825
|
-
const actualToolName = toolName.substring(_ToolManager.INTERNAL_TOOL_PREFIX.length);
|
|
826
|
-
return this.internalToolsProvider?.hasInternalTool(actualToolName) ?? false;
|
|
827
|
-
}
|
|
828
|
-
if (toolName.startsWith(_ToolManager.CUSTOM_TOOL_PREFIX)) {
|
|
829
|
-
const actualToolName = toolName.substring(_ToolManager.CUSTOM_TOOL_PREFIX.length);
|
|
830
|
-
return this.internalToolsProvider?.hasCustomTool(actualToolName) ?? false;
|
|
831
|
-
}
|
|
832
|
-
return false;
|
|
1062
|
+
return this.agentTools.has(toolName);
|
|
833
1063
|
}
|
|
834
1064
|
/**
|
|
835
1065
|
* Get tool statistics across all sources
|
|
836
1066
|
*/
|
|
837
1067
|
async getToolStats() {
|
|
838
1068
|
let mcpTools = {};
|
|
839
|
-
let internalTools = {};
|
|
840
|
-
let customTools = {};
|
|
841
1069
|
try {
|
|
842
1070
|
mcpTools = await this.mcpManager.getAllTools();
|
|
843
1071
|
} catch (error) {
|
|
@@ -846,34 +1074,16 @@ let _ToolManager = class _ToolManager {
|
|
|
846
1074
|
);
|
|
847
1075
|
mcpTools = {};
|
|
848
1076
|
}
|
|
849
|
-
try {
|
|
850
|
-
internalTools = this.internalToolsProvider?.getInternalTools() || {};
|
|
851
|
-
} catch (error) {
|
|
852
|
-
this.logger.error(
|
|
853
|
-
`Failed to get internal tools for stats: ${error instanceof Error ? error.message : String(error)}`
|
|
854
|
-
);
|
|
855
|
-
internalTools = {};
|
|
856
|
-
}
|
|
857
|
-
try {
|
|
858
|
-
customTools = this.internalToolsProvider?.getCustomTools() || {};
|
|
859
|
-
} catch (error) {
|
|
860
|
-
this.logger.error(
|
|
861
|
-
`Failed to get custom tools for stats: ${error instanceof Error ? error.message : String(error)}`
|
|
862
|
-
);
|
|
863
|
-
customTools = {};
|
|
864
|
-
}
|
|
865
1077
|
const mcpCount = Object.keys(mcpTools).length;
|
|
866
|
-
const
|
|
867
|
-
const customCount = Object.keys(customTools).length;
|
|
1078
|
+
const localCount = this.agentTools.size;
|
|
868
1079
|
return {
|
|
869
|
-
total: mcpCount +
|
|
1080
|
+
total: mcpCount + localCount,
|
|
870
1081
|
mcp: mcpCount,
|
|
871
|
-
|
|
872
|
-
custom: customCount
|
|
1082
|
+
local: localCount
|
|
873
1083
|
};
|
|
874
1084
|
}
|
|
875
1085
|
/**
|
|
876
|
-
* Get the source of a tool (mcp,
|
|
1086
|
+
* Get the source of a tool (mcp, local, or unknown).
|
|
877
1087
|
* @param toolName The name of the tool to check
|
|
878
1088
|
* @returns The source of the tool
|
|
879
1089
|
*/
|
|
@@ -881,11 +1091,8 @@ let _ToolManager = class _ToolManager {
|
|
|
881
1091
|
if (toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX) && toolName.length > _ToolManager.MCP_TOOL_PREFIX.length) {
|
|
882
1092
|
return "mcp";
|
|
883
1093
|
}
|
|
884
|
-
if (
|
|
885
|
-
return "
|
|
886
|
-
}
|
|
887
|
-
if (toolName.startsWith(_ToolManager.CUSTOM_TOOL_PREFIX) && toolName.length > _ToolManager.CUSTOM_TOOL_PREFIX.length) {
|
|
888
|
-
return "custom";
|
|
1094
|
+
if (this.agentTools.has(toolName)) {
|
|
1095
|
+
return "local";
|
|
889
1096
|
}
|
|
890
1097
|
return "unknown";
|
|
891
1098
|
}
|
|
@@ -896,7 +1103,7 @@ let _ToolManager = class _ToolManager {
|
|
|
896
1103
|
* Examples:
|
|
897
1104
|
* - Policy "mcp--read_file" matches "mcp--read_file" (exact)
|
|
898
1105
|
* - Policy "mcp--read_file" matches "mcp--filesystem--read_file" (suffix)
|
|
899
|
-
* - Policy "
|
|
1106
|
+
* - Policy "read_file" matches "read_file" (local tool exact only)
|
|
900
1107
|
*
|
|
901
1108
|
* @param toolName The fully qualified tool name (e.g., "mcp--filesystem--read_file")
|
|
902
1109
|
* @param policyPattern The policy pattern to match against (e.g., "mcp--read_file")
|
|
@@ -943,99 +1150,113 @@ let _ToolManager = class _ToolManager {
|
|
|
943
1150
|
);
|
|
944
1151
|
}
|
|
945
1152
|
/**
|
|
946
|
-
*
|
|
947
|
-
*
|
|
948
|
-
* (e.g., directory access approval for file tools) instead of default tool confirmation.
|
|
949
|
-
*
|
|
950
|
-
* @param toolName The fully qualified tool name
|
|
951
|
-
* @param args The tool arguments
|
|
952
|
-
* @param sessionId Optional session ID
|
|
953
|
-
* @returns { handled: true } if custom approval was processed, { handled: false } to continue normal flow
|
|
1153
|
+
* Handle tool approval flow. Checks various precedence levels to determine
|
|
1154
|
+
* if a tool should be auto-approved, denied, or requires manual approval.
|
|
954
1155
|
*/
|
|
955
|
-
async
|
|
956
|
-
|
|
957
|
-
if (toolName.startsWith(_ToolManager.INTERNAL_TOOL_PREFIX)) {
|
|
958
|
-
actualToolName = toolName.substring(_ToolManager.INTERNAL_TOOL_PREFIX.length);
|
|
959
|
-
} else if (toolName.startsWith(_ToolManager.CUSTOM_TOOL_PREFIX)) {
|
|
960
|
-
actualToolName = toolName.substring(_ToolManager.CUSTOM_TOOL_PREFIX.length);
|
|
961
|
-
}
|
|
962
|
-
if (!actualToolName || !this.internalToolsProvider) {
|
|
963
|
-
return { handled: false };
|
|
964
|
-
}
|
|
965
|
-
const tool = this.internalToolsProvider.getTool(actualToolName);
|
|
966
|
-
if (!tool?.getApprovalOverride) {
|
|
967
|
-
return { handled: false };
|
|
968
|
-
}
|
|
969
|
-
const approvalRequest = await tool.getApprovalOverride(args);
|
|
970
|
-
if (!approvalRequest) {
|
|
971
|
-
return { handled: false };
|
|
972
|
-
}
|
|
973
|
-
this.logger.debug(
|
|
974
|
-
`Tool '${toolName}' requested custom approval: type=${approvalRequest.type}`
|
|
975
|
-
);
|
|
976
|
-
if (sessionId && !approvalRequest.sessionId) {
|
|
977
|
-
approvalRequest.sessionId = sessionId;
|
|
978
|
-
}
|
|
979
|
-
const response = await this.approvalManager.requestApproval(approvalRequest);
|
|
980
|
-
if (response.status === ApprovalStatus.APPROVED) {
|
|
981
|
-
if (tool.onApprovalGranted) {
|
|
982
|
-
tool.onApprovalGranted(response);
|
|
983
|
-
}
|
|
1156
|
+
async handleToolApproval(toolName, args, toolCallId, sessionId, callDescription) {
|
|
1157
|
+
if (this.isInAlwaysDenyList(toolName)) {
|
|
984
1158
|
this.logger.info(
|
|
985
|
-
`
|
|
1159
|
+
`Tool '${toolName}' is in static deny list \u2013 blocking execution (session: ${sessionId ?? "global"})`
|
|
986
1160
|
);
|
|
987
|
-
|
|
1161
|
+
throw ToolError.executionDenied(toolName, sessionId);
|
|
988
1162
|
}
|
|
989
|
-
this.
|
|
990
|
-
|
|
1163
|
+
const validatedArgs = this.validateLocalToolArgs(toolName, args);
|
|
1164
|
+
const presentationSnapshot = await this.getToolPresentationSnapshotForCall(
|
|
1165
|
+
toolName,
|
|
1166
|
+
validatedArgs,
|
|
1167
|
+
toolCallId,
|
|
1168
|
+
sessionId
|
|
991
1169
|
);
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
1170
|
+
let directoryAccess;
|
|
1171
|
+
let directoryAccessApprovalRequest;
|
|
1172
|
+
if (!toolName.startsWith(_ToolManager.MCP_TOOL_PREFIX)) {
|
|
1173
|
+
const getApprovalOverride = this.getToolApprovalOverrideFn(toolName);
|
|
1174
|
+
if (getApprovalOverride) {
|
|
1175
|
+
const context = this.buildToolExecutionContext({ sessionId, toolCallId });
|
|
1176
|
+
const approvalRequest = await getApprovalOverride(validatedArgs, context);
|
|
1177
|
+
if (approvalRequest) {
|
|
1178
|
+
if (approvalRequest.type === ApprovalType.DIRECTORY_ACCESS) {
|
|
1179
|
+
const metadata = approvalRequest.metadata;
|
|
1180
|
+
if (typeof metadata !== "object" || metadata === null || typeof metadata.path !== "string" || typeof metadata.parentDir !== "string" || typeof metadata.operation !== "string" || typeof metadata.toolName !== "string") {
|
|
1181
|
+
throw ToolError.configInvalid(
|
|
1182
|
+
`Tool '${toolName}' returned invalid directory access metadata`
|
|
1183
|
+
);
|
|
1184
|
+
}
|
|
1185
|
+
directoryAccess = metadata;
|
|
1186
|
+
directoryAccessApprovalRequest = approvalRequest;
|
|
1187
|
+
} else {
|
|
1188
|
+
this.logger.debug(
|
|
1189
|
+
`Tool '${toolName}' requested custom approval: type=${approvalRequest.type}`
|
|
1190
|
+
);
|
|
1191
|
+
if (sessionId && !approvalRequest.sessionId) {
|
|
1192
|
+
approvalRequest.sessionId = sessionId;
|
|
1193
|
+
}
|
|
1194
|
+
const response = await this.approvalManager.requestApproval(approvalRequest);
|
|
1195
|
+
if (response.status === ApprovalStatus.APPROVED) {
|
|
1196
|
+
const onGranted = this.getToolApprovalOnGrantedFn(toolName);
|
|
1197
|
+
if (onGranted) {
|
|
1198
|
+
await Promise.resolve(
|
|
1199
|
+
onGranted(response, context, approvalRequest)
|
|
1200
|
+
);
|
|
1201
|
+
}
|
|
1202
|
+
this.logger.info(
|
|
1203
|
+
`Custom approval granted for '${toolName}', type=${approvalRequest.type}, session=${sessionId ?? "global"}`
|
|
1204
|
+
);
|
|
1205
|
+
return {
|
|
1206
|
+
requireApproval: true,
|
|
1207
|
+
approvalStatus: "approved",
|
|
1208
|
+
args: validatedArgs,
|
|
1209
|
+
presentationSnapshot
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1212
|
+
this.logger.info(
|
|
1213
|
+
`Custom approval denied for '${toolName}', type=${approvalRequest.type}, reason=${response.reason ?? "unknown"}`
|
|
1214
|
+
);
|
|
1215
|
+
throw ToolError.executionDenied(toolName, sessionId);
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
}
|
|
998
1219
|
}
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
async handleToolApproval(toolName, args, toolCallId, sessionId, callDescription) {
|
|
1006
|
-
const quickResult = await this.tryQuickApprovalResolution(toolName, args, sessionId);
|
|
1220
|
+
const quickResult = await this.tryQuickApprovalResolution(
|
|
1221
|
+
toolName,
|
|
1222
|
+
validatedArgs,
|
|
1223
|
+
sessionId,
|
|
1224
|
+
directoryAccess
|
|
1225
|
+
);
|
|
1007
1226
|
if (quickResult !== null) {
|
|
1008
|
-
return quickResult;
|
|
1227
|
+
return { ...quickResult, args: validatedArgs, presentationSnapshot };
|
|
1009
1228
|
}
|
|
1010
|
-
|
|
1229
|
+
const manualResult = await this.requestManualApproval(
|
|
1230
|
+
toolName,
|
|
1231
|
+
validatedArgs,
|
|
1232
|
+
toolCallId,
|
|
1233
|
+
sessionId,
|
|
1234
|
+
directoryAccess,
|
|
1235
|
+
directoryAccessApprovalRequest,
|
|
1236
|
+
callDescription,
|
|
1237
|
+
presentationSnapshot
|
|
1238
|
+
);
|
|
1239
|
+
return { ...manualResult, args: validatedArgs, presentationSnapshot };
|
|
1011
1240
|
}
|
|
1012
1241
|
/**
|
|
1013
1242
|
* Try to resolve tool approval quickly based on policies and cached permissions.
|
|
1014
1243
|
* Returns null if manual approval is needed.
|
|
1015
1244
|
*
|
|
1016
1245
|
* Precedence order (highest to lowest):
|
|
1017
|
-
* 1.
|
|
1018
|
-
* 2.
|
|
1019
|
-
* 3.
|
|
1020
|
-
* 4.
|
|
1021
|
-
* 5.
|
|
1022
|
-
* 6.
|
|
1023
|
-
* 7. Approval mode (auto-approve/auto-deny)
|
|
1246
|
+
* 1. Directory access requirement (outside-root paths)
|
|
1247
|
+
* 2. Session auto-approve (skill allowed-tools)
|
|
1248
|
+
* 3. Static allow list
|
|
1249
|
+
* 4. Dynamic "remembered" allowed list
|
|
1250
|
+
* 5. Tool approval patterns
|
|
1251
|
+
* 6. Approval mode (auto-approve/auto-deny)
|
|
1024
1252
|
*/
|
|
1025
|
-
async tryQuickApprovalResolution(toolName, args, sessionId) {
|
|
1026
|
-
if (
|
|
1027
|
-
this.
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
const customApprovalResult = await this.checkCustomApprovalOverride(
|
|
1033
|
-
toolName,
|
|
1034
|
-
args,
|
|
1035
|
-
sessionId
|
|
1036
|
-
);
|
|
1037
|
-
if (customApprovalResult.handled) {
|
|
1038
|
-
return { requireApproval: true, approvalStatus: "approved" };
|
|
1253
|
+
async tryQuickApprovalResolution(toolName, args, sessionId, directoryAccess) {
|
|
1254
|
+
if (directoryAccess) {
|
|
1255
|
+
if (this.approvalMode === "auto-approve") {
|
|
1256
|
+
this.approvalManager.addApprovedDirectory(directoryAccess.parentDir, "once");
|
|
1257
|
+
return { requireApproval: false };
|
|
1258
|
+
}
|
|
1259
|
+
return null;
|
|
1039
1260
|
}
|
|
1040
1261
|
if (sessionId && this.isToolAutoApprovedForSession(sessionId, toolName)) {
|
|
1041
1262
|
this.logger.info(
|
|
@@ -1055,17 +1276,12 @@ let _ToolManager = class _ToolManager {
|
|
|
1055
1276
|
);
|
|
1056
1277
|
return { requireApproval: false };
|
|
1057
1278
|
}
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
`Bash command '${command}' matched approved pattern \u2013 skipping confirmation.`
|
|
1065
|
-
);
|
|
1066
|
-
return { requireApproval: false };
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1279
|
+
const patternKey = this.getToolPatternKey(toolName, args);
|
|
1280
|
+
if (patternKey && this.approvalManager.matchesPattern(toolName, patternKey)) {
|
|
1281
|
+
this.logger.info(
|
|
1282
|
+
`Tool '${toolName}' matched approved pattern key '${patternKey}' \u2013 skipping confirmation.`
|
|
1283
|
+
);
|
|
1284
|
+
return { requireApproval: false };
|
|
1069
1285
|
}
|
|
1070
1286
|
if (this.approvalMode === "auto-approve") {
|
|
1071
1287
|
this.logger.debug(`\u{1F7E2} Auto-approving tool execution: ${toolName}`);
|
|
@@ -1081,9 +1297,9 @@ let _ToolManager = class _ToolManager {
|
|
|
1081
1297
|
* Request manual approval from the user for a tool execution.
|
|
1082
1298
|
* Generates preview, sends approval request, and handles the response.
|
|
1083
1299
|
*/
|
|
1084
|
-
async requestManualApproval(toolName, args, toolCallId, sessionId, callDescription) {
|
|
1300
|
+
async requestManualApproval(toolName, args, toolCallId, sessionId, directoryAccess, directoryAccessApprovalRequest, callDescription, presentationSnapshot) {
|
|
1085
1301
|
this.logger.info(
|
|
1086
|
-
`Tool
|
|
1302
|
+
`Tool approval requested for ${toolName}, sessionId: ${sessionId ?? "global"}`
|
|
1087
1303
|
);
|
|
1088
1304
|
try {
|
|
1089
1305
|
const displayPreview = await this.generateToolPreview(
|
|
@@ -1092,16 +1308,27 @@ let _ToolManager = class _ToolManager {
|
|
|
1092
1308
|
toolCallId,
|
|
1093
1309
|
sessionId
|
|
1094
1310
|
);
|
|
1095
|
-
const suggestedPatterns = this.
|
|
1096
|
-
const response = await this.approvalManager.
|
|
1311
|
+
const suggestedPatterns = this.getToolSuggestedPatterns(toolName, args);
|
|
1312
|
+
const response = await this.approvalManager.requestToolApproval({
|
|
1097
1313
|
toolName,
|
|
1314
|
+
...presentationSnapshot !== void 0 && { presentationSnapshot },
|
|
1098
1315
|
toolCallId,
|
|
1099
1316
|
args,
|
|
1100
1317
|
...callDescription !== void 0 && { description: callDescription },
|
|
1101
1318
|
...sessionId !== void 0 && { sessionId },
|
|
1102
1319
|
...displayPreview !== void 0 && { displayPreview },
|
|
1320
|
+
...directoryAccess !== void 0 && { directoryAccess },
|
|
1103
1321
|
...suggestedPatterns !== void 0 && { suggestedPatterns }
|
|
1104
1322
|
});
|
|
1323
|
+
if (response.status === ApprovalStatus.APPROVED && directoryAccessApprovalRequest !== void 0) {
|
|
1324
|
+
const onGranted = this.getToolApprovalOnGrantedFn(toolName);
|
|
1325
|
+
if (onGranted) {
|
|
1326
|
+
const context = this.buildToolExecutionContext({ sessionId, toolCallId });
|
|
1327
|
+
await Promise.resolve(
|
|
1328
|
+
onGranted(response, context, directoryAccessApprovalRequest)
|
|
1329
|
+
);
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1105
1332
|
if (response.status === ApprovalStatus.APPROVED && response.data) {
|
|
1106
1333
|
await this.handleRememberChoice(toolName, response, sessionId);
|
|
1107
1334
|
}
|
|
@@ -1109,12 +1336,12 @@ let _ToolManager = class _ToolManager {
|
|
|
1109
1336
|
this.handleApprovalDenied(toolName, response, sessionId);
|
|
1110
1337
|
}
|
|
1111
1338
|
this.logger.info(
|
|
1112
|
-
`Tool
|
|
1339
|
+
`Tool approval approved for ${toolName}, sessionId: ${sessionId ?? "global"}`
|
|
1113
1340
|
);
|
|
1114
1341
|
return { requireApproval: true, approvalStatus: "approved" };
|
|
1115
1342
|
} catch (error) {
|
|
1116
1343
|
this.logger.error(
|
|
1117
|
-
`Tool
|
|
1344
|
+
`Tool approval error for ${toolName}: ${error instanceof Error ? error.message : String(error)}`
|
|
1118
1345
|
);
|
|
1119
1346
|
throw error;
|
|
1120
1347
|
}
|
|
@@ -1123,14 +1350,13 @@ let _ToolManager = class _ToolManager {
|
|
|
1123
1350
|
* Generate a preview for the tool approval UI if the tool supports it.
|
|
1124
1351
|
*/
|
|
1125
1352
|
async generateToolPreview(toolName, args, toolCallId, sessionId) {
|
|
1126
|
-
const
|
|
1127
|
-
|
|
1128
|
-
if (!internalTool?.generatePreview) {
|
|
1353
|
+
const previewFn = this.getToolPreviewFn(toolName);
|
|
1354
|
+
if (!previewFn) {
|
|
1129
1355
|
return void 0;
|
|
1130
1356
|
}
|
|
1131
1357
|
try {
|
|
1132
|
-
const context = { sessionId, toolCallId };
|
|
1133
|
-
const preview = await
|
|
1358
|
+
const context = this.buildToolExecutionContext({ sessionId, toolCallId });
|
|
1359
|
+
const preview = await previewFn(args, context);
|
|
1134
1360
|
this.logger.debug(`Generated preview for ${toolName}`);
|
|
1135
1361
|
return preview ?? void 0;
|
|
1136
1362
|
} catch (previewError) {
|
|
@@ -1144,20 +1370,6 @@ let _ToolManager = class _ToolManager {
|
|
|
1144
1370
|
return void 0;
|
|
1145
1371
|
}
|
|
1146
1372
|
}
|
|
1147
|
-
/**
|
|
1148
|
-
* Get suggested bash patterns for the approval UI.
|
|
1149
|
-
*/
|
|
1150
|
-
getBashSuggestedPatterns(toolName, args) {
|
|
1151
|
-
if (!this.isBashTool(toolName)) {
|
|
1152
|
-
return void 0;
|
|
1153
|
-
}
|
|
1154
|
-
const command = args.command;
|
|
1155
|
-
if (!command) {
|
|
1156
|
-
return void 0;
|
|
1157
|
-
}
|
|
1158
|
-
const result = this.checkBashPatternApproval(command);
|
|
1159
|
-
return result.suggestedPatterns?.length ? result.suggestedPatterns : void 0;
|
|
1160
|
-
}
|
|
1161
1373
|
/**
|
|
1162
1374
|
* Handle "remember choice" or "remember pattern" when user approves a tool.
|
|
1163
1375
|
*/
|
|
@@ -1173,10 +1385,10 @@ let _ToolManager = class _ToolManager {
|
|
|
1173
1385
|
`Tool '${toolName}' added to allowed tools for session '${allowSessionId ?? "global"}' (remember choice selected)`
|
|
1174
1386
|
);
|
|
1175
1387
|
this.autoApprovePendingToolRequests(toolName, allowSessionId);
|
|
1176
|
-
} else if (rememberPattern && this.
|
|
1177
|
-
this.approvalManager.
|
|
1178
|
-
this.logger.info(`
|
|
1179
|
-
this.
|
|
1388
|
+
} else if (rememberPattern && this.getToolApprovalPatternKeyFn(toolName)) {
|
|
1389
|
+
this.approvalManager.addPattern(toolName, rememberPattern);
|
|
1390
|
+
this.logger.info(`Pattern '${rememberPattern}' added for tool '${toolName}' approval`);
|
|
1391
|
+
this.autoApprovePendingPatternRequests(toolName, sessionId);
|
|
1180
1392
|
}
|
|
1181
1393
|
}
|
|
1182
1394
|
/**
|