@machina.ai/cell-cli-core 1.6.1-rc2 → 1.10.0-rc1
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/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/package.json +1 -1
- package/dist/src/agents/codebase-investigator.d.ts +46 -0
- package/dist/src/agents/codebase-investigator.js +135 -0
- package/dist/src/agents/codebase-investigator.js.map +1 -0
- package/dist/src/agents/executor.d.ts +92 -0
- package/dist/src/agents/executor.js +579 -0
- package/dist/src/agents/executor.js.map +1 -0
- package/dist/src/agents/executor.test.d.ts +6 -0
- package/dist/src/agents/executor.test.js +680 -0
- package/dist/src/agents/executor.test.js.map +1 -0
- package/dist/src/agents/invocation.d.ts +46 -0
- package/dist/src/agents/invocation.js +102 -0
- package/dist/src/agents/invocation.js.map +1 -0
- package/dist/src/agents/invocation.test.d.ts +6 -0
- package/dist/src/agents/invocation.test.js +215 -0
- package/dist/src/agents/invocation.test.js.map +1 -0
- package/dist/src/agents/registry.d.ts +36 -0
- package/dist/src/agents/registry.js +81 -0
- package/dist/src/agents/registry.js.map +1 -0
- package/dist/src/agents/registry.test.d.ts +6 -0
- package/dist/src/agents/registry.test.js +146 -0
- package/dist/src/agents/registry.test.js.map +1 -0
- package/dist/src/agents/schema-utils.d.ts +39 -0
- package/dist/src/agents/schema-utils.js +57 -0
- package/dist/src/agents/schema-utils.js.map +1 -0
- package/dist/src/agents/schema-utils.test.d.ts +6 -0
- package/dist/src/agents/schema-utils.test.js +144 -0
- package/dist/src/agents/schema-utils.test.js.map +1 -0
- package/dist/src/agents/subagent-tool-wrapper.d.ts +38 -0
- package/dist/src/agents/subagent-tool-wrapper.js +48 -0
- package/dist/src/agents/subagent-tool-wrapper.js.map +1 -0
- package/dist/src/agents/subagent-tool-wrapper.test.d.ts +6 -0
- package/dist/src/agents/subagent-tool-wrapper.test.js +112 -0
- package/dist/src/agents/subagent-tool-wrapper.test.js.map +1 -0
- package/dist/src/agents/types.d.ts +145 -0
- package/dist/src/agents/types.js +18 -0
- package/dist/src/agents/types.js.map +1 -0
- package/dist/src/agents/utils.d.ts +15 -0
- package/dist/src/agents/utils.js +29 -0
- package/dist/src/agents/utils.js.map +1 -0
- package/dist/src/agents/utils.test.d.ts +6 -0
- package/dist/src/agents/utils.test.js +87 -0
- package/dist/src/agents/utils.test.js.map +1 -0
- package/dist/src/code_assist/oauth-credential-storage.js +1 -1
- package/dist/src/code_assist/oauth-credential-storage.js.map +1 -1
- package/dist/src/code_assist/oauth-credential-storage.test.js +1 -1
- package/dist/src/code_assist/oauth-credential-storage.test.js.map +1 -1
- package/dist/src/code_assist/oauth2.test.js +14 -13
- package/dist/src/code_assist/oauth2.test.js.map +1 -1
- package/dist/src/code_assist/setup.js +4 -2
- package/dist/src/code_assist/setup.js.map +1 -1
- package/dist/src/config/config.d.ts +61 -15
- package/dist/src/config/config.js +132 -28
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/config.test.js +67 -3
- package/dist/src/config/config.test.js.map +1 -1
- package/dist/src/config/constants.d.ts +11 -0
- package/dist/src/config/constants.js +16 -0
- package/dist/src/config/constants.js.map +1 -0
- package/dist/src/config/storage.d.ts +0 -1
- package/dist/src/config/storage.js +2 -2
- package/dist/src/config/storage.js.map +1 -1
- package/dist/src/config/storage.test.js +7 -6
- package/dist/src/config/storage.test.js.map +1 -1
- package/dist/src/core/baseLlmClient.d.ts +4 -0
- package/dist/src/core/baseLlmClient.js +24 -23
- package/dist/src/core/baseLlmClient.js.map +1 -1
- package/dist/src/core/baseLlmClient.test.js +76 -13
- package/dist/src/core/baseLlmClient.test.js.map +1 -1
- package/dist/src/core/client.d.ts +6 -3
- package/dist/src/core/client.js +103 -64
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/client.test.js +470 -118
- package/dist/src/core/client.test.js.map +1 -1
- package/dist/src/core/contentGenerator.js +3 -1
- package/dist/src/core/contentGenerator.js.map +1 -1
- package/dist/src/core/coreToolScheduler.js +12 -12
- package/dist/src/core/coreToolScheduler.js.map +1 -1
- package/dist/src/core/coreToolScheduler.test.js +260 -23
- package/dist/src/core/coreToolScheduler.test.js.map +1 -1
- package/dist/src/core/geminiChat.d.ts +11 -14
- package/dist/src/core/geminiChat.js +80 -124
- package/dist/src/core/geminiChat.js.map +1 -1
- package/dist/src/core/geminiChat.test.js +316 -239
- package/dist/src/core/geminiChat.test.js.map +1 -1
- package/dist/src/core/logger.test.js +16 -16
- package/dist/src/core/logger.test.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.d.ts +3 -2
- package/dist/src/core/nonInteractiveToolExecutor.js +2 -2
- package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.test.js +19 -19
- package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
- package/dist/src/core/prompts.d.ts +2 -1
- package/dist/src/core/prompts.js +53 -111
- package/dist/src/core/prompts.js.map +1 -1
- package/dist/src/core/prompts.test.js +83 -29
- package/dist/src/core/prompts.test.js.map +1 -1
- package/dist/src/core/subagent.js +1 -1
- package/dist/src/core/subagent.js.map +1 -1
- package/dist/src/core/subagent.test.js +38 -12
- package/dist/src/core/subagent.test.js.map +1 -1
- package/dist/src/core/turn.d.ts +15 -6
- package/dist/src/core/turn.js +14 -13
- package/dist/src/core/turn.js.map +1 -1
- package/dist/src/core/turn.test.js +14 -2
- package/dist/src/core/turn.test.js.map +1 -1
- package/dist/src/generated/git-commit.d.ts +2 -2
- package/dist/src/generated/git-commit.js +2 -2
- package/dist/src/generated/git-commit.js.map +1 -1
- package/dist/src/ide/detect-ide.d.ts +45 -14
- package/dist/src/ide/detect-ide.js +32 -69
- package/dist/src/ide/detect-ide.js.map +1 -1
- package/dist/src/ide/detect-ide.test.js +40 -46
- package/dist/src/ide/detect-ide.test.js.map +1 -1
- package/dist/src/ide/ide-client.d.ts +4 -4
- package/dist/src/ide/ide-client.js +33 -32
- package/dist/src/ide/ide-client.js.map +1 -1
- package/dist/src/ide/ide-client.test.js +12 -25
- package/dist/src/ide/ide-client.test.js.map +1 -1
- package/dist/src/ide/ide-installer.d.ts +2 -2
- package/dist/src/ide/ide-installer.js +8 -10
- package/dist/src/ide/ide-installer.js.map +1 -1
- package/dist/src/ide/ide-installer.test.js +33 -14
- package/dist/src/ide/ide-installer.test.js.map +1 -1
- package/dist/src/ide/process-utils.js +85 -75
- package/dist/src/ide/process-utils.js.map +1 -1
- package/dist/src/ide/process-utils.test.js +83 -90
- package/dist/src/ide/process-utils.test.js.map +1 -1
- package/dist/src/index.d.ts +7 -2
- package/dist/src/index.js +7 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/oauth-provider.d.ts +4 -1
- package/dist/src/mcp/oauth-provider.js +31 -25
- package/dist/src/mcp/oauth-provider.js.map +1 -1
- package/dist/src/mcp/sa-impersonation-provider.d.ts +33 -0
- package/dist/src/mcp/sa-impersonation-provider.js +130 -0
- package/dist/src/mcp/sa-impersonation-provider.js.map +1 -0
- package/dist/src/mcp/sa-impersonation-provider.test.d.ts +6 -0
- package/dist/src/mcp/sa-impersonation-provider.test.js +117 -0
- package/dist/src/mcp/sa-impersonation-provider.test.js.map +1 -0
- package/dist/src/mcp/token-storage/file-token-storage.js +2 -1
- package/dist/src/mcp/token-storage/file-token-storage.js.map +1 -1
- package/dist/src/mcp/token-storage/file-token-storage.test.js +4 -3
- package/dist/src/mcp/token-storage/file-token-storage.test.js.map +1 -1
- package/dist/src/policy/policy-engine.js +11 -2
- package/dist/src/policy/policy-engine.js.map +1 -1
- package/dist/src/policy/policy-engine.test.js +45 -0
- package/dist/src/policy/policy-engine.test.js.map +1 -1
- package/dist/src/routing/strategies/compositeStrategy.js +4 -3
- package/dist/src/routing/strategies/compositeStrategy.js.map +1 -1
- package/dist/src/services/chatRecordingService.d.ts +3 -2
- package/dist/src/services/chatRecordingService.js +3 -2
- package/dist/src/services/chatRecordingService.js.map +1 -1
- package/dist/src/services/fileSystemService.d.ts +9 -0
- package/dist/src/services/fileSystemService.js +11 -0
- package/dist/src/services/fileSystemService.js.map +1 -1
- package/dist/src/services/shellExecutionService.d.ts +3 -0
- package/dist/src/services/shellExecutionService.js +165 -49
- package/dist/src/services/shellExecutionService.js.map +1 -1
- package/dist/src/services/shellExecutionService.test.js +74 -5
- package/dist/src/services/shellExecutionService.test.js.map +1 -1
- package/dist/src/telemetry/activity-detector.d.ts +41 -0
- package/dist/src/telemetry/activity-detector.js +61 -0
- package/dist/src/telemetry/activity-detector.js.map +1 -0
- package/dist/src/telemetry/activity-detector.test.d.ts +6 -0
- package/dist/src/telemetry/activity-detector.test.js +136 -0
- package/dist/src/telemetry/activity-detector.test.js.map +1 -0
- package/dist/src/telemetry/activity-types.d.ts +19 -0
- package/dist/src/telemetry/activity-types.js +21 -0
- package/dist/src/telemetry/activity-types.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +18 -2
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +257 -108
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.d.ts +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +258 -33
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +118 -100
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +146 -103
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
- package/dist/src/telemetry/config.d.ts +31 -0
- package/dist/src/telemetry/config.js +74 -0
- package/dist/src/telemetry/config.js.map +1 -0
- package/dist/src/telemetry/config.test.d.ts +6 -0
- package/dist/src/telemetry/config.test.js +124 -0
- package/dist/src/telemetry/config.test.js.map +1 -0
- package/dist/src/telemetry/constants.d.ts +0 -34
- package/dist/src/telemetry/constants.js +0 -34
- package/dist/src/telemetry/constants.js.map +1 -1
- package/dist/src/telemetry/index.d.ts +9 -3
- package/dist/src/telemetry/index.js +19 -2
- package/dist/src/telemetry/index.js.map +1 -1
- package/dist/src/telemetry/loggers.d.ts +10 -2
- package/dist/src/telemetry/loggers.js +206 -273
- package/dist/src/telemetry/loggers.js.map +1 -1
- package/dist/src/telemetry/loggers.test.circular.js +3 -3
- package/dist/src/telemetry/loggers.test.circular.js.map +1 -1
- package/dist/src/telemetry/loggers.test.js +316 -13
- package/dist/src/telemetry/loggers.test.js.map +1 -1
- package/dist/src/telemetry/memory-monitor.d.ts +149 -0
- package/dist/src/telemetry/memory-monitor.js +335 -0
- package/dist/src/telemetry/memory-monitor.js.map +1 -0
- package/dist/src/telemetry/memory-monitor.test.d.ts +6 -0
- package/dist/src/telemetry/memory-monitor.test.js +472 -0
- package/dist/src/telemetry/memory-monitor.test.js.map +1 -0
- package/dist/src/telemetry/metrics.d.ts +436 -11
- package/dist/src/telemetry/metrics.js +600 -110
- package/dist/src/telemetry/metrics.js.map +1 -1
- package/dist/src/telemetry/metrics.test.js +898 -16
- package/dist/src/telemetry/metrics.test.js.map +1 -1
- package/dist/src/telemetry/sdk.js +1 -1
- package/dist/src/telemetry/sdk.js.map +1 -1
- package/dist/src/telemetry/sdk.test.js +13 -0
- package/dist/src/telemetry/sdk.test.js.map +1 -1
- package/dist/src/telemetry/telemetryAttributes.d.ts +8 -0
- package/dist/src/telemetry/telemetryAttributes.js +18 -0
- package/dist/src/telemetry/telemetryAttributes.js.map +1 -0
- package/dist/src/telemetry/types.d.ts +168 -5
- package/dist/src/telemetry/types.js +696 -34
- package/dist/src/telemetry/types.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.d.ts +2 -2
- package/dist/src/telemetry/uiTelemetry.js +3 -4
- package/dist/src/telemetry/uiTelemetry.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.test.js +14 -14
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
- package/dist/src/test-utils/mock-tool.d.ts +28 -3
- package/dist/src/test-utils/mock-tool.js +71 -1
- package/dist/src/test-utils/mock-tool.js.map +1 -1
- package/dist/src/tools/glob.js +4 -2
- package/dist/src/tools/glob.js.map +1 -1
- package/dist/src/tools/ls.js +1 -1
- package/dist/src/tools/ls.js.map +1 -1
- package/dist/src/tools/mcp-client.d.ts +5 -14
- package/dist/src/tools/mcp-client.js +51 -98
- package/dist/src/tools/mcp-client.js.map +1 -1
- package/dist/src/tools/mcp-client.test.js +175 -157
- package/dist/src/tools/mcp-client.test.js.map +1 -1
- package/dist/src/tools/memoryTool.d.ts +1 -1
- package/dist/src/tools/memoryTool.js +1 -2
- package/dist/src/tools/memoryTool.js.map +1 -1
- package/dist/src/tools/memoryTool.test.js +9 -8
- package/dist/src/tools/memoryTool.test.js.map +1 -1
- package/dist/src/tools/message-bus-integration.test.d.ts +6 -0
- package/dist/src/tools/message-bus-integration.test.js +183 -0
- package/dist/src/tools/message-bus-integration.test.js.map +1 -0
- package/dist/src/tools/shell.js +60 -4
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/shell.test.js +2 -1
- package/dist/src/tools/shell.test.js.map +1 -1
- package/dist/src/tools/smart-edit.d.ts +1 -1
- package/dist/src/tools/smart-edit.js +116 -12
- package/dist/src/tools/smart-edit.js.map +1 -1
- package/dist/src/tools/smart-edit.test.js +91 -29
- package/dist/src/tools/smart-edit.test.js.map +1 -1
- package/dist/src/tools/tool-error.d.ts +22 -0
- package/dist/src/tools/tool-error.js +28 -0
- package/dist/src/tools/tool-error.js.map +1 -1
- package/dist/src/tools/tool-names.d.ts +9 -0
- package/dist/src/tools/tool-names.js +18 -0
- package/dist/src/tools/tool-names.js.map +1 -0
- package/dist/src/tools/tool-registry.test.js +10 -10
- package/dist/src/tools/tool-registry.test.js.map +1 -1
- package/dist/src/tools/tools.d.ts +11 -3
- package/dist/src/tools/tools.js +94 -3
- package/dist/src/tools/tools.js.map +1 -1
- package/dist/src/tools/web-fetch.d.ts +7 -0
- package/dist/src/tools/web-fetch.js +42 -10
- package/dist/src/tools/web-fetch.js.map +1 -1
- package/dist/src/tools/web-fetch.test.js +127 -8
- package/dist/src/tools/web-fetch.test.js.map +1 -1
- package/dist/src/tools/web-search.js +2 -1
- package/dist/src/tools/web-search.js.map +1 -1
- package/dist/src/tools/write-file.js +2 -1
- package/dist/src/tools/write-file.js.map +1 -1
- package/dist/src/tools/write-todos.d.ts +25 -0
- package/dist/src/tools/write-todos.js +151 -0
- package/dist/src/tools/write-todos.js.map +1 -0
- package/dist/src/tools/write-todos.test.d.ts +6 -0
- package/dist/src/tools/write-todos.test.js +89 -0
- package/dist/src/tools/write-todos.test.js.map +1 -0
- package/dist/src/utils/bfsFileSearch.d.ts +1 -1
- package/dist/src/utils/editCorrector.js +2 -2
- package/dist/src/utils/editCorrector.js.map +1 -1
- package/dist/src/utils/editor.js +1 -0
- package/dist/src/utils/editor.js.map +1 -1
- package/dist/src/utils/editor.test.js +1 -0
- package/dist/src/utils/editor.test.js.map +1 -1
- package/dist/src/utils/flashFallback.test.js +2 -2
- package/dist/src/utils/flashFallback.test.js.map +1 -1
- package/dist/src/utils/formatters.d.ts +1 -0
- package/dist/src/utils/formatters.js +2 -1
- package/dist/src/utils/formatters.js.map +1 -1
- package/dist/src/utils/formatters.test.d.ts +6 -0
- package/dist/src/utils/formatters.test.js +26 -0
- package/dist/src/utils/formatters.test.js.map +1 -0
- package/dist/src/utils/getFolderStructure.d.ts +1 -1
- package/dist/src/utils/getFolderStructure.js +1 -1
- package/dist/src/utils/getFolderStructure.js.map +1 -1
- package/dist/src/utils/getFolderStructure.test.js +7 -6
- package/dist/src/utils/getFolderStructure.test.js.map +1 -1
- package/dist/src/utils/installationManager.test.js +2 -1
- package/dist/src/utils/installationManager.test.js.map +1 -1
- package/dist/src/utils/llm-edit-fixer.js +14 -4
- package/dist/src/utils/llm-edit-fixer.js.map +1 -1
- package/dist/src/utils/llm-edit-fixer.test.js +81 -0
- package/dist/src/utils/llm-edit-fixer.test.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.d.ts +2 -1
- package/dist/src/utils/memoryDiscovery.js +3 -2
- package/dist/src/utils/memoryDiscovery.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.test.js +99 -21
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.js +13 -20
- package/dist/src/utils/memoryImportProcessor.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.test.js +14 -0
- package/dist/src/utils/memoryImportProcessor.test.js.map +1 -1
- package/dist/src/utils/pathCorrector.d.ts +25 -0
- package/dist/src/utils/pathCorrector.js +33 -0
- package/dist/src/utils/pathCorrector.js.map +1 -0
- package/dist/src/utils/pathCorrector.test.d.ts +6 -0
- package/dist/src/utils/pathCorrector.test.js +83 -0
- package/dist/src/utils/pathCorrector.test.js.map +1 -0
- package/dist/src/utils/retry.d.ts +4 -1
- package/dist/src/utils/retry.js +40 -17
- package/dist/src/utils/retry.js.map +1 -1
- package/dist/src/utils/retry.test.js +104 -31
- package/dist/src/utils/retry.test.js.map +1 -1
- package/dist/src/utils/schemaValidator.js +11 -1
- package/dist/src/utils/schemaValidator.js.map +1 -1
- package/dist/src/utils/schemaValidator.test.d.ts +6 -0
- package/dist/src/utils/schemaValidator.test.js +113 -0
- package/dist/src/utils/schemaValidator.test.js.map +1 -0
- package/dist/src/utils/shell-utils.d.ts +1 -0
- package/dist/src/utils/shell-utils.js +6 -2
- package/dist/src/utils/shell-utils.js.map +1 -1
- package/dist/src/utils/shell-utils.test.js +5 -0
- package/dist/src/utils/shell-utils.test.js.map +1 -1
- package/dist/src/utils/terminalSerializer.d.ts +1 -4
- package/dist/src/utils/terminalSerializer.js +3 -3
- package/dist/src/utils/terminalSerializer.js.map +1 -1
- package/dist/src/utils/thoughtUtils.d.ts +21 -0
- package/dist/src/utils/thoughtUtils.js +39 -0
- package/dist/src/utils/thoughtUtils.js.map +1 -0
- package/dist/src/utils/thoughtUtils.test.d.ts +6 -0
- package/dist/src/utils/thoughtUtils.test.js +78 -0
- package/dist/src/utils/thoughtUtils.test.js.map +1 -0
- package/dist/src/utils/tool-utils.js +2 -2
- package/dist/src/utils/tool-utils.js.map +1 -1
- package/dist/src/utils/tool-utils.test.js +8 -0
- package/dist/src/utils/tool-utils.test.js.map +1 -1
- package/dist/src/utils/userAccountManager.test.js +2 -1
- package/dist/src/utils/userAccountManager.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/dist/src/test-utils/tools.d.ts +0 -45
- package/dist/src/test-utils/tools.js +0 -105
- package/dist/src/test-utils/tools.js.map +0 -1
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
7
|
+
import { AgentRegistry } from './registry.js';
|
|
8
|
+
import { makeFakeConfig } from '../test-utils/config.js';
|
|
9
|
+
// A test-only subclass to expose the protected `registerAgent` method.
|
|
10
|
+
class TestableAgentRegistry extends AgentRegistry {
|
|
11
|
+
testRegisterAgent(definition) {
|
|
12
|
+
this.registerAgent(definition);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
// Define mock agent structures for testing registration logic
|
|
16
|
+
const MOCK_AGENT_V1 = {
|
|
17
|
+
name: 'MockAgent',
|
|
18
|
+
description: 'Mock Description V1',
|
|
19
|
+
inputConfig: { inputs: {} },
|
|
20
|
+
modelConfig: { model: 'test', temp: 0, top_p: 1 },
|
|
21
|
+
runConfig: { max_time_minutes: 1 },
|
|
22
|
+
promptConfig: { systemPrompt: 'test' },
|
|
23
|
+
};
|
|
24
|
+
const MOCK_AGENT_V2 = {
|
|
25
|
+
...MOCK_AGENT_V1,
|
|
26
|
+
description: 'Mock Description V2 (Updated)',
|
|
27
|
+
};
|
|
28
|
+
describe('AgentRegistry', () => {
|
|
29
|
+
let mockConfig;
|
|
30
|
+
let registry;
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
// Default configuration (debugMode: false)
|
|
33
|
+
mockConfig = makeFakeConfig();
|
|
34
|
+
registry = new TestableAgentRegistry(mockConfig);
|
|
35
|
+
});
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
vi.restoreAllMocks(); // Restore spies after each test
|
|
38
|
+
});
|
|
39
|
+
describe('initialize', () => {
|
|
40
|
+
// TODO: Add this test once we actually have a built-in agent configured.
|
|
41
|
+
// it('should load built-in agents upon initialization', async () => {
|
|
42
|
+
// expect(registry.getAllDefinitions()).toHaveLength(0);
|
|
43
|
+
// await registry.initialize();
|
|
44
|
+
// // There are currently no built-in agents.
|
|
45
|
+
// expect(registry.getAllDefinitions()).toEqual([]);
|
|
46
|
+
// });
|
|
47
|
+
it('should log the count of loaded agents in debug mode', async () => {
|
|
48
|
+
const debugConfig = makeFakeConfig({ debugMode: true });
|
|
49
|
+
const debugRegistry = new TestableAgentRegistry(debugConfig);
|
|
50
|
+
const consoleLogSpy = vi
|
|
51
|
+
.spyOn(console, 'log')
|
|
52
|
+
.mockImplementation(() => { });
|
|
53
|
+
await debugRegistry.initialize();
|
|
54
|
+
const agentCount = debugRegistry.getAllDefinitions().length;
|
|
55
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(`[AgentRegistry] Initialized with ${agentCount} agents.`);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe('registration logic', () => {
|
|
59
|
+
it('should register a valid agent definition', () => {
|
|
60
|
+
registry.testRegisterAgent(MOCK_AGENT_V1);
|
|
61
|
+
expect(registry.getDefinition('MockAgent')).toEqual(MOCK_AGENT_V1);
|
|
62
|
+
});
|
|
63
|
+
it('should handle special characters in agent names', () => {
|
|
64
|
+
const specialAgent = {
|
|
65
|
+
...MOCK_AGENT_V1,
|
|
66
|
+
name: 'Agent-123_$pecial.v2',
|
|
67
|
+
};
|
|
68
|
+
registry.testRegisterAgent(specialAgent);
|
|
69
|
+
expect(registry.getDefinition('Agent-123_$pecial.v2')).toEqual(specialAgent);
|
|
70
|
+
});
|
|
71
|
+
it('should reject an agent definition missing a name', () => {
|
|
72
|
+
const invalidAgent = { ...MOCK_AGENT_V1, name: '' };
|
|
73
|
+
const consoleWarnSpy = vi
|
|
74
|
+
.spyOn(console, 'warn')
|
|
75
|
+
.mockImplementation(() => { });
|
|
76
|
+
registry.testRegisterAgent(invalidAgent);
|
|
77
|
+
expect(registry.getDefinition('MockAgent')).toBeUndefined();
|
|
78
|
+
expect(consoleWarnSpy).toHaveBeenCalledWith('[AgentRegistry] Skipping invalid agent definition. Missing name or description.');
|
|
79
|
+
});
|
|
80
|
+
it('should reject an agent definition missing a description', () => {
|
|
81
|
+
const invalidAgent = { ...MOCK_AGENT_V1, description: '' };
|
|
82
|
+
const consoleWarnSpy = vi
|
|
83
|
+
.spyOn(console, 'warn')
|
|
84
|
+
.mockImplementation(() => { });
|
|
85
|
+
registry.testRegisterAgent(invalidAgent);
|
|
86
|
+
expect(registry.getDefinition('MockAgent')).toBeUndefined();
|
|
87
|
+
expect(consoleWarnSpy).toHaveBeenCalledWith('[AgentRegistry] Skipping invalid agent definition. Missing name or description.');
|
|
88
|
+
});
|
|
89
|
+
it('should overwrite an existing agent definition', () => {
|
|
90
|
+
registry.testRegisterAgent(MOCK_AGENT_V1);
|
|
91
|
+
expect(registry.getDefinition('MockAgent')?.description).toBe('Mock Description V1');
|
|
92
|
+
registry.testRegisterAgent(MOCK_AGENT_V2);
|
|
93
|
+
expect(registry.getDefinition('MockAgent')?.description).toBe('Mock Description V2 (Updated)');
|
|
94
|
+
expect(registry.getAllDefinitions()).toHaveLength(1);
|
|
95
|
+
});
|
|
96
|
+
it('should log overwrites when in debug mode', () => {
|
|
97
|
+
const debugConfig = makeFakeConfig({ debugMode: true });
|
|
98
|
+
const debugRegistry = new TestableAgentRegistry(debugConfig);
|
|
99
|
+
const consoleLogSpy = vi
|
|
100
|
+
.spyOn(console, 'log')
|
|
101
|
+
.mockImplementation(() => { });
|
|
102
|
+
debugRegistry.testRegisterAgent(MOCK_AGENT_V1);
|
|
103
|
+
debugRegistry.testRegisterAgent(MOCK_AGENT_V2);
|
|
104
|
+
expect(consoleLogSpy).toHaveBeenCalledWith(`[AgentRegistry] Overriding agent 'MockAgent'`);
|
|
105
|
+
});
|
|
106
|
+
it('should not log overwrites when not in debug mode', () => {
|
|
107
|
+
const consoleLogSpy = vi
|
|
108
|
+
.spyOn(console, 'log')
|
|
109
|
+
.mockImplementation(() => { });
|
|
110
|
+
registry.testRegisterAgent(MOCK_AGENT_V1);
|
|
111
|
+
registry.testRegisterAgent(MOCK_AGENT_V2);
|
|
112
|
+
expect(consoleLogSpy).not.toHaveBeenCalledWith(`[AgentRegistry] Overriding agent 'MockAgent'`);
|
|
113
|
+
});
|
|
114
|
+
it('should handle bulk registrations correctly', async () => {
|
|
115
|
+
const promises = Array.from({ length: 100 }, (_, i) => Promise.resolve(registry.testRegisterAgent({
|
|
116
|
+
...MOCK_AGENT_V1,
|
|
117
|
+
name: `Agent${i}`,
|
|
118
|
+
})));
|
|
119
|
+
await Promise.all(promises);
|
|
120
|
+
expect(registry.getAllDefinitions()).toHaveLength(100);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
describe('accessors', () => {
|
|
124
|
+
const ANOTHER_AGENT = {
|
|
125
|
+
...MOCK_AGENT_V1,
|
|
126
|
+
name: 'AnotherAgent',
|
|
127
|
+
};
|
|
128
|
+
beforeEach(() => {
|
|
129
|
+
registry.testRegisterAgent(MOCK_AGENT_V1);
|
|
130
|
+
registry.testRegisterAgent(ANOTHER_AGENT);
|
|
131
|
+
});
|
|
132
|
+
it('getDefinition should return the correct definition', () => {
|
|
133
|
+
expect(registry.getDefinition('MockAgent')).toEqual(MOCK_AGENT_V1);
|
|
134
|
+
expect(registry.getDefinition('AnotherAgent')).toEqual(ANOTHER_AGENT);
|
|
135
|
+
});
|
|
136
|
+
it('getDefinition should return undefined for unknown agents', () => {
|
|
137
|
+
expect(registry.getDefinition('NonExistentAgent')).toBeUndefined();
|
|
138
|
+
});
|
|
139
|
+
it('getAllDefinitions should return all registered definitions', () => {
|
|
140
|
+
const all = registry.getAllDefinitions();
|
|
141
|
+
expect(all).toHaveLength(2);
|
|
142
|
+
expect(all).toEqual(expect.arrayContaining([MOCK_AGENT_V1, ANOTHER_AGENT]));
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
//# sourceMappingURL=registry.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.test.js","sourceRoot":"","sources":["../../../src/agents/registry.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAIzD,uEAAuE;AACvE,MAAM,qBAAsB,SAAQ,aAAa;IAC/C,iBAAiB,CAAC,UAA2B;QAC3C,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IACjC,CAAC;CACF;AAED,8DAA8D;AAC9D,MAAM,aAAa,GAAoB;IACrC,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,qBAAqB;IAClC,WAAW,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;IAC3B,WAAW,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE;IACjD,SAAS,EAAE,EAAE,gBAAgB,EAAE,CAAC,EAAE;IAClC,YAAY,EAAE,EAAE,YAAY,EAAE,MAAM,EAAE;CACvC,CAAC;AAEF,MAAM,aAAa,GAAoB;IACrC,GAAG,aAAa;IAChB,WAAW,EAAE,+BAA+B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AC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;YACnE,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QACxE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,0DAA0D,EAAE,GAAG,EAAE;YAClE,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAAC,aAAa,EAAE,CAAC;QACrE,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,4DAA4D,EAAE,GAAG,EAAE;YACpE,MAAM,GAAG,GAAG,QAAQ,CAAC,iBAAiB,EAAE,CAAC;YACzC,MAAM,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAC5B,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CACjB,MAAM,CAAC,eAAe,CAAC,CAAC,aAAa,EAAE,aAAa,CAAC,CAAC,CACvD,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { InputConfig } from './types.js';
|
|
7
|
+
/**
|
|
8
|
+
* Defines the structure for a JSON Schema object, used for tool function
|
|
9
|
+
* declarations.
|
|
10
|
+
*/
|
|
11
|
+
interface JsonSchemaObject {
|
|
12
|
+
type: 'object';
|
|
13
|
+
properties: Record<string, JsonSchemaProperty>;
|
|
14
|
+
required?: string[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Defines the structure for a property within a {@link JsonSchemaObject}.
|
|
18
|
+
*/
|
|
19
|
+
interface JsonSchemaProperty {
|
|
20
|
+
type: 'string' | 'number' | 'integer' | 'boolean' | 'array';
|
|
21
|
+
description: string;
|
|
22
|
+
items?: {
|
|
23
|
+
type: 'string' | 'number';
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Converts an internal `InputConfig` definition into a standard JSON Schema
|
|
28
|
+
* object suitable for a tool's `FunctionDeclaration`.
|
|
29
|
+
*
|
|
30
|
+
* This utility ensures that the configuration for a subagent's inputs is
|
|
31
|
+
* correctly translated into the format expected by the generative model.
|
|
32
|
+
*
|
|
33
|
+
* @param inputConfig The internal `InputConfig` to convert.
|
|
34
|
+
* @returns A JSON Schema object representing the inputs.
|
|
35
|
+
* @throws An `Error` if an unsupported input type is encountered, ensuring
|
|
36
|
+
* configuration errors are caught early.
|
|
37
|
+
*/
|
|
38
|
+
export declare function convertInputConfigToJsonSchema(inputConfig: InputConfig): JsonSchemaObject;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Converts an internal `InputConfig` definition into a standard JSON Schema
|
|
8
|
+
* object suitable for a tool's `FunctionDeclaration`.
|
|
9
|
+
*
|
|
10
|
+
* This utility ensures that the configuration for a subagent's inputs is
|
|
11
|
+
* correctly translated into the format expected by the generative model.
|
|
12
|
+
*
|
|
13
|
+
* @param inputConfig The internal `InputConfig` to convert.
|
|
14
|
+
* @returns A JSON Schema object representing the inputs.
|
|
15
|
+
* @throws An `Error` if an unsupported input type is encountered, ensuring
|
|
16
|
+
* configuration errors are caught early.
|
|
17
|
+
*/
|
|
18
|
+
export function convertInputConfigToJsonSchema(inputConfig) {
|
|
19
|
+
const properties = {};
|
|
20
|
+
const required = [];
|
|
21
|
+
for (const [name, definition] of Object.entries(inputConfig.inputs)) {
|
|
22
|
+
const schemaProperty = {
|
|
23
|
+
description: definition.description,
|
|
24
|
+
};
|
|
25
|
+
switch (definition.type) {
|
|
26
|
+
case 'string':
|
|
27
|
+
case 'number':
|
|
28
|
+
case 'integer':
|
|
29
|
+
case 'boolean':
|
|
30
|
+
schemaProperty.type = definition.type;
|
|
31
|
+
break;
|
|
32
|
+
case 'string[]':
|
|
33
|
+
schemaProperty.type = 'array';
|
|
34
|
+
schemaProperty.items = { type: 'string' };
|
|
35
|
+
break;
|
|
36
|
+
case 'number[]':
|
|
37
|
+
schemaProperty.type = 'array';
|
|
38
|
+
schemaProperty.items = { type: 'number' };
|
|
39
|
+
break;
|
|
40
|
+
default: {
|
|
41
|
+
const exhaustiveCheck = definition.type;
|
|
42
|
+
throw new Error(`Unsupported input type '${exhaustiveCheck}' for parameter '${name}'. ` +
|
|
43
|
+
'Supported types: string, number, integer, boolean, string[], number[]');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
properties[name] = schemaProperty;
|
|
47
|
+
if (definition.required) {
|
|
48
|
+
required.push(name);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
type: 'object',
|
|
53
|
+
properties,
|
|
54
|
+
required: required.length > 0 ? required : undefined,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=schema-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-utils.js","sourceRoot":"","sources":["../../../src/agents/schema-utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAuBH;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,8BAA8B,CAC5C,WAAwB;IAExB,MAAM,UAAU,GAAuC,EAAE,CAAC;IAC1D,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,KAAK,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;QACpE,MAAM,cAAc,GAAgC;YAClD,WAAW,EAAE,UAAU,CAAC,WAAW;SACpC,CAAC;QAEF,QAAQ,UAAU,CAAC,IAAI,EAAE,CAAC;YACxB,KAAK,QAAQ,CAAC;YACd,KAAK,QAAQ,CAAC;YACd,KAAK,SAAS,CAAC;YACf,KAAK,SAAS;gBACZ,cAAc,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;gBACtC,MAAM;YAER,KAAK,UAAU;gBACb,cAAc,CAAC,IAAI,GAAG,OAAO,CAAC;gBAC9B,cAAc,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;gBAC1C,MAAM;YAER,KAAK,UAAU;gBACb,cAAc,CAAC,IAAI,GAAG,OAAO,CAAC;gBAC9B,cAAc,CAAC,KAAK,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;gBAC1C,MAAM;YAER,OAAO,CAAC,CAAC,CAAC;gBACR,MAAM,eAAe,GAAU,UAAU,CAAC,IAAI,CAAC;gBAC/C,MAAM,IAAI,KAAK,CACb,2BAA2B,eAAe,oBAAoB,IAAI,KAAK;oBACrE,uEAAuE,CAC1E,CAAC;YACJ,CAAC;QACH,CAAC;QAED,UAAU,CAAC,IAAI,CAAC,GAAG,cAAoC,CAAC;QAExD,IAAI,UAAU,CAAC,QAAQ,EAAE,CAAC;YACxB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACtB,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,EAAE,QAAQ;QACd,UAAU;QACV,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;KACrD,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect } from 'vitest';
|
|
7
|
+
import { convertInputConfigToJsonSchema } from './schema-utils.js';
|
|
8
|
+
const PRIMITIVE_TYPES_CONFIG = {
|
|
9
|
+
inputs: {
|
|
10
|
+
goal: {
|
|
11
|
+
type: 'string',
|
|
12
|
+
description: 'The primary objective',
|
|
13
|
+
required: true,
|
|
14
|
+
},
|
|
15
|
+
max_retries: {
|
|
16
|
+
type: 'integer',
|
|
17
|
+
description: 'Maximum number of retries',
|
|
18
|
+
required: false,
|
|
19
|
+
},
|
|
20
|
+
temperature: {
|
|
21
|
+
type: 'number',
|
|
22
|
+
description: 'The model temperature',
|
|
23
|
+
required: true,
|
|
24
|
+
},
|
|
25
|
+
verbose: {
|
|
26
|
+
type: 'boolean',
|
|
27
|
+
description: 'Enable verbose logging',
|
|
28
|
+
required: false,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
const ARRAY_TYPES_CONFIG = {
|
|
33
|
+
inputs: {
|
|
34
|
+
filenames: {
|
|
35
|
+
type: 'string[]',
|
|
36
|
+
description: 'A list of file paths',
|
|
37
|
+
required: true,
|
|
38
|
+
},
|
|
39
|
+
scores: {
|
|
40
|
+
type: 'number[]',
|
|
41
|
+
description: 'A list of scores',
|
|
42
|
+
required: false,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
const NO_REQUIRED_FIELDS_CONFIG = {
|
|
47
|
+
inputs: {
|
|
48
|
+
optional_param: {
|
|
49
|
+
type: 'string',
|
|
50
|
+
description: 'An optional parameter',
|
|
51
|
+
required: false,
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
const ALL_REQUIRED_FIELDS_CONFIG = {
|
|
56
|
+
inputs: {
|
|
57
|
+
paramA: { type: 'string', description: 'Parameter A', required: true },
|
|
58
|
+
paramB: { type: 'boolean', description: 'Parameter B', required: true },
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
const EMPTY_CONFIG = {
|
|
62
|
+
inputs: {},
|
|
63
|
+
};
|
|
64
|
+
const UNSUPPORTED_TYPE_CONFIG = {
|
|
65
|
+
inputs: {
|
|
66
|
+
invalid_param: {
|
|
67
|
+
// @ts-expect-error - Intentionally testing an invalid type
|
|
68
|
+
type: 'date',
|
|
69
|
+
description: 'This type is not supported',
|
|
70
|
+
required: true,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
describe('convertInputConfigToJsonSchema', () => {
|
|
75
|
+
describe('type conversion', () => {
|
|
76
|
+
it('should correctly convert an InputConfig with various primitive types', () => {
|
|
77
|
+
const result = convertInputConfigToJsonSchema(PRIMITIVE_TYPES_CONFIG);
|
|
78
|
+
expect(result).toEqual({
|
|
79
|
+
type: 'object',
|
|
80
|
+
properties: {
|
|
81
|
+
goal: { type: 'string', description: 'The primary objective' },
|
|
82
|
+
max_retries: {
|
|
83
|
+
type: 'integer',
|
|
84
|
+
description: 'Maximum number of retries',
|
|
85
|
+
},
|
|
86
|
+
temperature: { type: 'number', description: 'The model temperature' },
|
|
87
|
+
verbose: { type: 'boolean', description: 'Enable verbose logging' },
|
|
88
|
+
},
|
|
89
|
+
required: ['goal', 'temperature'],
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
it('should correctly handle array types for strings and numbers', () => {
|
|
93
|
+
const result = convertInputConfigToJsonSchema(ARRAY_TYPES_CONFIG);
|
|
94
|
+
expect(result).toEqual({
|
|
95
|
+
type: 'object',
|
|
96
|
+
properties: {
|
|
97
|
+
filenames: {
|
|
98
|
+
type: 'array',
|
|
99
|
+
description: 'A list of file paths',
|
|
100
|
+
items: { type: 'string' },
|
|
101
|
+
},
|
|
102
|
+
scores: {
|
|
103
|
+
type: 'array',
|
|
104
|
+
description: 'A list of scores',
|
|
105
|
+
items: { type: 'number' },
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
required: ['filenames'],
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
describe('required field handling', () => {
|
|
113
|
+
it('should produce an undefined `required` field when no inputs are required', () => {
|
|
114
|
+
const result = convertInputConfigToJsonSchema(NO_REQUIRED_FIELDS_CONFIG);
|
|
115
|
+
expect(result.properties['optional_param']).toBeDefined();
|
|
116
|
+
// Per the implementation and JSON Schema spec, the `required` field
|
|
117
|
+
// should be omitted if no properties are required.
|
|
118
|
+
expect(result.required).toBeUndefined();
|
|
119
|
+
});
|
|
120
|
+
it('should list all properties in `required` when all are marked as required', () => {
|
|
121
|
+
const result = convertInputConfigToJsonSchema(ALL_REQUIRED_FIELDS_CONFIG);
|
|
122
|
+
expect(result.required).toHaveLength(2);
|
|
123
|
+
expect(result.required).toEqual(expect.arrayContaining(['paramA', 'paramB']));
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
describe('edge cases', () => {
|
|
127
|
+
it('should return a valid, empty schema for an empty input config', () => {
|
|
128
|
+
const result = convertInputConfigToJsonSchema(EMPTY_CONFIG);
|
|
129
|
+
expect(result).toEqual({
|
|
130
|
+
type: 'object',
|
|
131
|
+
properties: {},
|
|
132
|
+
required: undefined,
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
describe('error handling', () => {
|
|
137
|
+
it('should throw an informative error for an unsupported input type', () => {
|
|
138
|
+
const action = () => convertInputConfigToJsonSchema(UNSUPPORTED_TYPE_CONFIG);
|
|
139
|
+
expect(action).toThrow(/Unsupported input type 'date'/);
|
|
140
|
+
expect(action).toThrow(/parameter 'invalid_param'/);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
//# sourceMappingURL=schema-utils.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-utils.test.js","sourceRoot":"","sources":["../../../src/agents/schema-utils.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAC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C,gBAAgB,EAAE,GAAG,EAAE;QAC9B,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;YACzE,MAAM,MAAM,GAAG,GAAG,EAAE,CAClB,8BAA8B,CAAC,uBAAuB,CAAC,CAAC;YAE1D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC;YACxD,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,2BAA2B,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { BaseDeclarativeTool, type ToolInvocation, type ToolResult } from '../tools/tools.js';
|
|
7
|
+
import type { Config } from '../config/config.js';
|
|
8
|
+
import type { AgentDefinition, AgentInputs } from './types.js';
|
|
9
|
+
import type { MessageBus } from '../confirmation-bus/message-bus.js';
|
|
10
|
+
/**
|
|
11
|
+
* A tool wrapper that dynamically exposes a subagent as a standard,
|
|
12
|
+
* strongly-typed `DeclarativeTool`.
|
|
13
|
+
*/
|
|
14
|
+
export declare class SubagentToolWrapper extends BaseDeclarativeTool<AgentInputs, ToolResult> {
|
|
15
|
+
private readonly definition;
|
|
16
|
+
private readonly config;
|
|
17
|
+
/**
|
|
18
|
+
* Constructs the tool wrapper.
|
|
19
|
+
*
|
|
20
|
+
* The constructor dynamically generates the JSON schema for the tool's
|
|
21
|
+
* parameters based on the subagent's input configuration.
|
|
22
|
+
*
|
|
23
|
+
* @param definition The `AgentDefinition` of the subagent to wrap.
|
|
24
|
+
* @param config The runtime configuration, passed down to the subagent.
|
|
25
|
+
* @param messageBus Optional message bus for policy enforcement.
|
|
26
|
+
*/
|
|
27
|
+
constructor(definition: AgentDefinition, config: Config, messageBus?: MessageBus);
|
|
28
|
+
/**
|
|
29
|
+
* Creates an invocation instance for executing the subagent.
|
|
30
|
+
*
|
|
31
|
+
* This method is called by the tool framework when the parent agent decides
|
|
32
|
+
* to use this tool.
|
|
33
|
+
*
|
|
34
|
+
* @param params The validated input parameters from the parent agent's call.
|
|
35
|
+
* @returns A `ToolInvocation` instance ready for execution.
|
|
36
|
+
*/
|
|
37
|
+
protected createInvocation(params: AgentInputs): ToolInvocation<AgentInputs, ToolResult>;
|
|
38
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { BaseDeclarativeTool, Kind, } from '../tools/tools.js';
|
|
7
|
+
import { convertInputConfigToJsonSchema } from './schema-utils.js';
|
|
8
|
+
import { SubagentInvocation } from './invocation.js';
|
|
9
|
+
/**
|
|
10
|
+
* A tool wrapper that dynamically exposes a subagent as a standard,
|
|
11
|
+
* strongly-typed `DeclarativeTool`.
|
|
12
|
+
*/
|
|
13
|
+
export class SubagentToolWrapper extends BaseDeclarativeTool {
|
|
14
|
+
definition;
|
|
15
|
+
config;
|
|
16
|
+
/**
|
|
17
|
+
* Constructs the tool wrapper.
|
|
18
|
+
*
|
|
19
|
+
* The constructor dynamically generates the JSON schema for the tool's
|
|
20
|
+
* parameters based on the subagent's input configuration.
|
|
21
|
+
*
|
|
22
|
+
* @param definition The `AgentDefinition` of the subagent to wrap.
|
|
23
|
+
* @param config The runtime configuration, passed down to the subagent.
|
|
24
|
+
* @param messageBus Optional message bus for policy enforcement.
|
|
25
|
+
*/
|
|
26
|
+
constructor(definition, config, messageBus) {
|
|
27
|
+
// Dynamically generate the JSON schema required for the tool definition.
|
|
28
|
+
const parameterSchema = convertInputConfigToJsonSchema(definition.inputConfig);
|
|
29
|
+
super(definition.name, definition.displayName ?? definition.name, definition.description, Kind.Think, parameterSchema,
|
|
30
|
+
/* isOutputMarkdown */ true,
|
|
31
|
+
/* canUpdateOutput */ true, messageBus);
|
|
32
|
+
this.definition = definition;
|
|
33
|
+
this.config = config;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates an invocation instance for executing the subagent.
|
|
37
|
+
*
|
|
38
|
+
* This method is called by the tool framework when the parent agent decides
|
|
39
|
+
* to use this tool.
|
|
40
|
+
*
|
|
41
|
+
* @param params The validated input parameters from the parent agent's call.
|
|
42
|
+
* @returns A `ToolInvocation` instance ready for execution.
|
|
43
|
+
*/
|
|
44
|
+
createInvocation(params) {
|
|
45
|
+
return new SubagentInvocation(params, this.definition, this.config, this.messageBus);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=subagent-tool-wrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagent-tool-wrapper.js","sourceRoot":"","sources":["../../../src/agents/subagent-tool-wrapper.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,mBAAmB,EACnB,IAAI,GAGL,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAGrD;;;GAGG;AACH,MAAM,OAAO,mBAAoB,SAAQ,mBAGxC;IAYoB;IACA;IAZnB;;;;;;;;;OASG;IACH,YACmB,UAA2B,EAC3B,MAAc,EAC/B,UAAuB;QAEvB,yEAAyE;QACzE,MAAM,eAAe,GAAG,8BAA8B,CACpD,UAAU,CAAC,WAAW,CACvB,CAAC;QAEF,KAAK,CACH,UAAU,CAAC,IAAI,EACf,UAAU,CAAC,WAAW,IAAI,UAAU,CAAC,IAAI,EACzC,UAAU,CAAC,WAAW,EACtB,IAAI,CAAC,KAAK,EACV,eAAe;QACf,sBAAsB,CAAC,IAAI;QAC3B,qBAAqB,CAAC,IAAI,EAC1B,UAAU,CACX,CAAC;QAlBe,eAAU,GAAV,UAAU,CAAiB;QAC3B,WAAM,GAAN,MAAM,CAAQ;IAkBjC,CAAC;IAED;;;;;;;;OAQG;IACO,gBAAgB,CACxB,MAAmB;QAEnB,OAAO,IAAI,kBAAkB,CAC3B,MAAM,EACN,IAAI,CAAC,UAAU,EACf,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,UAAU,CAChB,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
7
|
+
import { SubagentToolWrapper } from './subagent-tool-wrapper.js';
|
|
8
|
+
import { SubagentInvocation } from './invocation.js';
|
|
9
|
+
import { convertInputConfigToJsonSchema } from './schema-utils.js';
|
|
10
|
+
import { makeFakeConfig } from '../test-utils/config.js';
|
|
11
|
+
import { Kind } from '../tools/tools.js';
|
|
12
|
+
// Mock dependencies to isolate the SubagentToolWrapper class
|
|
13
|
+
vi.mock('./invocation.js');
|
|
14
|
+
vi.mock('./schema-utils.js');
|
|
15
|
+
const MockedSubagentInvocation = vi.mocked(SubagentInvocation);
|
|
16
|
+
const mockConvertInputConfigToJsonSchema = vi.mocked(convertInputConfigToJsonSchema);
|
|
17
|
+
// Define reusable test data
|
|
18
|
+
let mockConfig;
|
|
19
|
+
const mockDefinition = {
|
|
20
|
+
name: 'TestAgent',
|
|
21
|
+
displayName: 'Test Agent Display Name',
|
|
22
|
+
description: 'An agent for testing.',
|
|
23
|
+
inputConfig: {
|
|
24
|
+
inputs: {
|
|
25
|
+
goal: { type: 'string', required: true, description: 'The goal.' },
|
|
26
|
+
priority: {
|
|
27
|
+
type: 'number',
|
|
28
|
+
required: false,
|
|
29
|
+
description: 'The priority.',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
modelConfig: { model: 'gemini-test-model', temp: 0, top_p: 1 },
|
|
34
|
+
runConfig: { max_time_minutes: 5 },
|
|
35
|
+
promptConfig: { systemPrompt: 'You are a test agent.' },
|
|
36
|
+
};
|
|
37
|
+
const mockSchema = {
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: {
|
|
40
|
+
goal: { type: 'string', description: 'The goal.' },
|
|
41
|
+
priority: { type: 'number', description: 'The priority.' },
|
|
42
|
+
},
|
|
43
|
+
required: ['goal'],
|
|
44
|
+
};
|
|
45
|
+
describe('SubagentToolWrapper', () => {
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
vi.clearAllMocks();
|
|
48
|
+
mockConfig = makeFakeConfig();
|
|
49
|
+
// Provide a mock implementation for the schema conversion utility
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
51
|
+
mockConvertInputConfigToJsonSchema.mockReturnValue(mockSchema);
|
|
52
|
+
});
|
|
53
|
+
describe('constructor', () => {
|
|
54
|
+
it('should call convertInputConfigToJsonSchema with the correct agent inputConfig', () => {
|
|
55
|
+
new SubagentToolWrapper(mockDefinition, mockConfig);
|
|
56
|
+
expect(convertInputConfigToJsonSchema).toHaveBeenCalledOnce();
|
|
57
|
+
expect(convertInputConfigToJsonSchema).toHaveBeenCalledWith(mockDefinition.inputConfig);
|
|
58
|
+
});
|
|
59
|
+
it('should correctly configure the tool properties from the agent definition', () => {
|
|
60
|
+
const wrapper = new SubagentToolWrapper(mockDefinition, mockConfig);
|
|
61
|
+
expect(wrapper.name).toBe(mockDefinition.name);
|
|
62
|
+
expect(wrapper.displayName).toBe(mockDefinition.displayName);
|
|
63
|
+
expect(wrapper.description).toBe(mockDefinition.description);
|
|
64
|
+
expect(wrapper.kind).toBe(Kind.Think);
|
|
65
|
+
expect(wrapper.isOutputMarkdown).toBe(true);
|
|
66
|
+
expect(wrapper.canUpdateOutput).toBe(true);
|
|
67
|
+
});
|
|
68
|
+
it('should fall back to the agent name for displayName if it is not provided', () => {
|
|
69
|
+
const definitionWithoutDisplayName = {
|
|
70
|
+
...mockDefinition,
|
|
71
|
+
displayName: undefined,
|
|
72
|
+
};
|
|
73
|
+
const wrapper = new SubagentToolWrapper(definitionWithoutDisplayName, mockConfig);
|
|
74
|
+
expect(wrapper.displayName).toBe(definitionWithoutDisplayName.name);
|
|
75
|
+
});
|
|
76
|
+
it('should generate a valid tool schema using the definition and converted schema', () => {
|
|
77
|
+
const wrapper = new SubagentToolWrapper(mockDefinition, mockConfig);
|
|
78
|
+
const schema = wrapper.schema;
|
|
79
|
+
expect(schema.name).toBe(mockDefinition.name);
|
|
80
|
+
expect(schema.description).toBe(mockDefinition.description);
|
|
81
|
+
expect(schema.parametersJsonSchema).toEqual(mockSchema);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
describe('createInvocation', () => {
|
|
85
|
+
it('should create a SubagentInvocation with the correct parameters', () => {
|
|
86
|
+
const wrapper = new SubagentToolWrapper(mockDefinition, mockConfig);
|
|
87
|
+
const params = { goal: 'Test the invocation', priority: 1 };
|
|
88
|
+
// The public `build` method calls the protected `createInvocation` after validation
|
|
89
|
+
const invocation = wrapper.build(params);
|
|
90
|
+
expect(invocation).toBeInstanceOf(SubagentInvocation);
|
|
91
|
+
expect(MockedSubagentInvocation).toHaveBeenCalledOnce();
|
|
92
|
+
expect(MockedSubagentInvocation).toHaveBeenCalledWith(params, mockDefinition, mockConfig, undefined);
|
|
93
|
+
});
|
|
94
|
+
it('should pass the messageBus to the SubagentInvocation constructor', () => {
|
|
95
|
+
const mockMessageBus = {};
|
|
96
|
+
const wrapper = new SubagentToolWrapper(mockDefinition, mockConfig, mockMessageBus);
|
|
97
|
+
const params = { goal: 'Test the invocation', priority: 1 };
|
|
98
|
+
wrapper.build(params);
|
|
99
|
+
expect(MockedSubagentInvocation).toHaveBeenCalledWith(params, mockDefinition, mockConfig, mockMessageBus);
|
|
100
|
+
});
|
|
101
|
+
it('should throw a validation error for invalid parameters before creating an invocation', () => {
|
|
102
|
+
const wrapper = new SubagentToolWrapper(mockDefinition, mockConfig);
|
|
103
|
+
// Missing the required 'goal' parameter
|
|
104
|
+
const invalidParams = { priority: 1 };
|
|
105
|
+
// The `build` method in the base class performs JSON schema validation
|
|
106
|
+
// before calling the protected `createInvocation` method.
|
|
107
|
+
expect(() => wrapper.build(invalidParams)).toThrow("params must have required property 'goal'");
|
|
108
|
+
expect(MockedSubagentInvocation).not.toHaveBeenCalled();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
//# sourceMappingURL=subagent-tool-wrapper.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subagent-tool-wrapper.test.js","sourceRoot":"","sources":["../../../src/agents/subagent-tool-wrapper.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,8BAA8B,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAGzD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAGzC,6DAA6D;AAC7D,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;AAC3B,EAAE,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;AAE7B,MAAM,wBAAwB,GAAG,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;AAC/D,MAAM,kCAAkC,GAAG,EAAE,CAAC,MAAM,CAClD,8BAA8B,CAC/B,CAAC;AAEF,4BAA4B;AAC5B,IAAI,UAAkB,CAAC;AAEvB,MAAM,cAAc,GA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