@google/gemini-cli-core 0.26.0-preview.4 → 0.27.0-nightly.20260126.cb772a5b7
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 +18 -1
- package/dist/docs/changelogs/index.md +87 -0
- package/dist/docs/changelogs/latest.md +355 -150
- package/dist/docs/changelogs/preview.md +318 -210
- package/dist/docs/cli/commands.md +0 -6
- package/dist/docs/cli/keyboard-shortcuts.md +32 -31
- package/dist/docs/cli/settings.md +16 -18
- package/dist/docs/cli/system-prompt.md +32 -0
- package/dist/docs/cli/uninstall.md +18 -0
- package/dist/docs/extensions/index.md +1 -1
- package/dist/docs/get-started/configuration.md +9 -34
- package/dist/docs/hooks/best-practices.md +219 -398
- package/dist/docs/hooks/index.md +111 -656
- package/dist/docs/hooks/reference.md +280 -136
- package/dist/docs/hooks/writing-hooks.md +202 -796
- package/dist/docs/sidebar.json +1 -5
- package/dist/docs/tools/mcp-server.md +24 -1
- package/dist/google-gemini-cli-core-0.27.0-nightly.20260121.97aac696f.tgz +0 -0
- package/dist/src/agents/agentLoader.js +10 -10
- package/dist/src/agents/agentLoader.js.map +1 -1
- package/dist/src/agents/agentLoader.test.js +16 -19
- package/dist/src/agents/agentLoader.test.js.map +1 -1
- package/dist/src/agents/cli-help-agent.js +8 -5
- package/dist/src/agents/cli-help-agent.js.map +1 -1
- package/dist/src/agents/cli-help-agent.test.js +4 -2
- package/dist/src/agents/cli-help-agent.test.js.map +1 -1
- package/dist/src/agents/codebase-investigator.d.ts +2 -1
- package/dist/src/agents/codebase-investigator.js +62 -41
- package/dist/src/agents/codebase-investigator.js.map +1 -1
- package/dist/src/agents/codebase-investigator.test.js +15 -8
- package/dist/src/agents/codebase-investigator.test.js.map +1 -1
- package/dist/src/agents/generalist-agent.js +9 -11
- package/dist/src/agents/generalist-agent.js.map +1 -1
- package/dist/src/agents/generalist-agent.test.js +3 -3
- package/dist/src/agents/generalist-agent.test.js.map +1 -1
- package/dist/src/agents/local-executor.js +25 -9
- package/dist/src/agents/local-executor.js.map +1 -1
- package/dist/src/agents/local-executor.test.js +74 -7
- package/dist/src/agents/local-executor.test.js.map +1 -1
- package/dist/src/agents/local-invocation.test.js +7 -3
- package/dist/src/agents/local-invocation.test.js.map +1 -1
- package/dist/src/agents/registry.d.ts +8 -5
- package/dist/src/agents/registry.js +31 -75
- package/dist/src/agents/registry.js.map +1 -1
- package/dist/src/agents/registry.test.js +93 -30
- package/dist/src/agents/registry.test.js.map +1 -1
- package/dist/src/agents/remote-invocation.js +2 -1
- package/dist/src/agents/remote-invocation.js.map +1 -1
- package/dist/src/agents/remote-invocation.test.js +15 -3
- package/dist/src/agents/remote-invocation.test.js.map +1 -1
- package/dist/src/agents/subagent-tool-wrapper.js +1 -3
- package/dist/src/agents/subagent-tool-wrapper.js.map +1 -1
- package/dist/src/agents/subagent-tool-wrapper.test.js +10 -25
- package/dist/src/agents/subagent-tool-wrapper.test.js.map +1 -1
- package/dist/src/agents/subagent-tool.d.ts +15 -0
- package/dist/src/agents/subagent-tool.js +61 -0
- package/dist/src/agents/subagent-tool.js.map +1 -0
- package/dist/src/agents/types.d.ts +6 -9
- package/dist/src/agents/types.js +4 -0
- package/dist/src/agents/types.js.map +1 -1
- package/dist/src/code_assist/codeAssist.js +1 -1
- package/dist/src/code_assist/codeAssist.js.map +1 -1
- package/dist/src/code_assist/codeAssist.test.js +2 -2
- package/dist/src/code_assist/codeAssist.test.js.map +1 -1
- package/dist/src/code_assist/experiments/experiments.test.js +1 -0
- package/dist/src/code_assist/experiments/experiments.test.js.map +1 -1
- package/dist/src/code_assist/experiments/experiments_local.test.js +11 -6
- package/dist/src/code_assist/experiments/experiments_local.test.js.map +1 -1
- package/dist/src/code_assist/experiments/flagNames.d.ts +2 -0
- package/dist/src/code_assist/experiments/flagNames.js +2 -0
- package/dist/src/code_assist/experiments/flagNames.js.map +1 -1
- package/dist/src/code_assist/oauth2.js +3 -3
- package/dist/src/code_assist/oauth2.test.js +1 -1
- package/dist/src/code_assist/server.d.ts +2 -1
- package/dist/src/code_assist/server.js +3 -1
- package/dist/src/code_assist/server.js.map +1 -1
- package/dist/src/code_assist/setup.d.ts +1 -0
- package/dist/src/code_assist/setup.js +5 -1
- package/dist/src/code_assist/setup.js.map +1 -1
- package/dist/src/code_assist/setup.test.js +10 -4
- package/dist/src/code_assist/setup.test.js.map +1 -1
- package/dist/src/config/config.d.ts +25 -18
- package/dist/src/config/config.js +70 -40
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/config.test.js +48 -21
- package/dist/src/config/config.test.js.map +1 -1
- package/dist/src/confirmation-bus/message-bus.js +2 -32
- package/dist/src/confirmation-bus/message-bus.js.map +1 -1
- package/dist/src/confirmation-bus/types.d.ts +35 -21
- package/dist/src/confirmation-bus/types.js +8 -3
- package/dist/src/confirmation-bus/types.js.map +1 -1
- package/dist/src/core/client.js +25 -7
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/client.test.js +52 -6
- package/dist/src/core/client.test.js.map +1 -1
- package/dist/src/core/contentGenerator.d.ts +1 -0
- package/dist/src/core/contentGenerator.js.map +1 -1
- package/dist/src/core/coreToolHookTriggers.d.ts +2 -38
- package/dist/src/core/coreToolHookTriggers.js +12 -159
- package/dist/src/core/coreToolHookTriggers.js.map +1 -1
- package/dist/src/core/coreToolHookTriggers.test.js +62 -94
- package/dist/src/core/coreToolHookTriggers.test.js.map +1 -1
- package/dist/src/core/coreToolScheduler.js +3 -5
- package/dist/src/core/coreToolScheduler.js.map +1 -1
- package/dist/src/core/coreToolScheduler.test.js +3 -0
- package/dist/src/core/coreToolScheduler.test.js.map +1 -1
- package/dist/src/core/fakeContentGenerator.d.ts +1 -0
- package/dist/src/core/fakeContentGenerator.js +1 -0
- package/dist/src/core/fakeContentGenerator.js.map +1 -1
- package/dist/src/core/geminiChat.js +1 -0
- package/dist/src/core/geminiChat.js.map +1 -1
- package/dist/src/core/geminiChat.test.js +21 -0
- package/dist/src/core/geminiChat.test.js.map +1 -1
- package/dist/src/core/geminiChat_network_retry.test.js +17 -12
- package/dist/src/core/geminiChat_network_retry.test.js.map +1 -1
- package/dist/src/core/loggingContentGenerator.d.ts +3 -0
- package/dist/src/core/loggingContentGenerator.js +6 -0
- package/dist/src/core/loggingContentGenerator.js.map +1 -1
- package/dist/src/core/loggingContentGenerator.test.js +11 -0
- package/dist/src/core/loggingContentGenerator.test.js.map +1 -1
- package/dist/src/core/prompts-substitution.test.js +101 -0
- package/dist/src/core/prompts-substitution.test.js.map +1 -0
- package/dist/src/core/prompts.js +115 -31
- package/dist/src/core/prompts.js.map +1 -1
- package/dist/src/core/prompts.test.js +32 -0
- package/dist/src/core/prompts.test.js.map +1 -1
- package/dist/src/core/recordingContentGenerator.d.ts +2 -1
- package/dist/src/core/recordingContentGenerator.js +6 -1
- package/dist/src/core/recordingContentGenerator.js.map +1 -1
- package/dist/src/core/turn.d.ts +2 -0
- package/dist/src/core/turn.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/hooks/hookAggregator.js +13 -3
- package/dist/src/hooks/hookAggregator.js.map +1 -1
- package/dist/src/hooks/hookEventHandler.d.ts +1 -13
- package/dist/src/hooks/hookEventHandler.js +1 -289
- package/dist/src/hooks/hookEventHandler.js.map +1 -1
- package/dist/src/hooks/hookEventHandler.test.js +1 -4
- package/dist/src/hooks/hookEventHandler.test.js.map +1 -1
- package/dist/src/hooks/hookSystem.d.ts +47 -3
- package/dist/src/hooks/hookSystem.js +90 -6
- package/dist/src/hooks/hookSystem.js.map +1 -1
- package/dist/src/hooks/hookSystem.test.js +19 -8
- package/dist/src/hooks/hookSystem.test.js.map +1 -1
- package/dist/src/hooks/types.d.ts +23 -1
- package/dist/src/hooks/types.js +28 -2
- package/dist/src/hooks/types.js.map +1 -1
- package/dist/src/hooks/types.test.js +9 -1
- package/dist/src/hooks/types.test.js.map +1 -1
- package/dist/src/ide/detect-ide.d.ts +41 -0
- package/dist/src/ide/detect-ide.js +47 -3
- package/dist/src/ide/detect-ide.js.map +1 -1
- package/dist/src/ide/detect-ide.test.js +46 -0
- package/dist/src/ide/detect-ide.test.js.map +1 -1
- package/dist/src/ide/ide-client.d.ts +1 -0
- package/dist/src/ide/ide-client.js +36 -9
- package/dist/src/ide/ide-client.js.map +1 -1
- package/dist/src/ide/ide-client.test.js +154 -6
- package/dist/src/ide/ide-client.test.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/oauth-provider.d.ts +1 -2
- package/dist/src/mcp/oauth-provider.js +4 -8
- package/dist/src/mcp/oauth-provider.js.map +1 -1
- package/dist/src/mcp/oauth-provider.test.js +32 -0
- package/dist/src/mcp/oauth-provider.test.js.map +1 -1
- package/dist/src/mcp/oauth-utils.d.ts +13 -4
- package/dist/src/mcp/oauth-utils.js +23 -19
- package/dist/src/mcp/oauth-utils.js.map +1 -1
- package/dist/src/mcp/oauth-utils.test.js +13 -8
- package/dist/src/mcp/oauth-utils.test.js.map +1 -1
- package/dist/src/policy/policy-engine.d.ts +1 -8
- package/dist/src/policy/policy-engine.js +1 -75
- package/dist/src/policy/policy-engine.js.map +1 -1
- package/dist/src/policy/policy-engine.test.js +0 -222
- package/dist/src/policy/policy-engine.test.js.map +1 -1
- package/dist/src/routing/modelRouterService.js +18 -8
- package/dist/src/routing/modelRouterService.js.map +1 -1
- package/dist/src/routing/modelRouterService.test.js +14 -6
- package/dist/src/routing/modelRouterService.test.js.map +1 -1
- package/dist/src/routing/strategies/classifierStrategy.js +4 -7
- package/dist/src/routing/strategies/classifierStrategy.js.map +1 -1
- package/dist/src/routing/strategies/classifierStrategy.test.js +10 -4
- package/dist/src/routing/strategies/classifierStrategy.test.js.map +1 -1
- package/dist/src/routing/strategies/numericalClassifierStrategy.d.ts +13 -0
- package/dist/src/routing/strategies/numericalClassifierStrategy.js +178 -0
- package/dist/src/routing/strategies/numericalClassifierStrategy.js.map +1 -0
- package/dist/src/routing/strategies/numericalClassifierStrategy.test.js +347 -0
- package/dist/src/routing/strategies/numericalClassifierStrategy.test.js.map +1 -0
- package/dist/src/scheduler/confirmation.js +2 -3
- package/dist/src/scheduler/confirmation.js.map +1 -1
- package/dist/src/scheduler/confirmation.test.js +8 -8
- package/dist/src/scheduler/confirmation.test.js.map +1 -1
- package/dist/src/scheduler/scheduler.test.js +0 -3
- package/dist/src/scheduler/scheduler.test.js.map +1 -1
- package/dist/src/scheduler/state-manager.js +4 -0
- package/dist/src/scheduler/state-manager.js.map +1 -1
- package/dist/src/scheduler/state-manager.test.js +11 -0
- package/dist/src/scheduler/state-manager.test.js.map +1 -1
- package/dist/src/scheduler/tool-executor.js +2 -4
- package/dist/src/scheduler/tool-executor.js.map +1 -1
- package/dist/src/scheduler/tool-executor.test.js +1 -1
- package/dist/src/scheduler/tool-executor.test.js.map +1 -1
- package/dist/src/services/chatRecordingService.d.ts +1 -1
- package/dist/src/services/chatRecordingService.js +23 -1
- package/dist/src/services/chatRecordingService.js.map +1 -1
- package/dist/src/services/chatRecordingService.test.js +111 -0
- package/dist/src/services/chatRecordingService.test.js.map +1 -1
- package/dist/src/services/sessionSummaryService.test.js +1 -1
- package/dist/src/services/sessionSummaryService.test.js.map +1 -1
- package/dist/src/telemetry/metrics.js +15 -4
- package/dist/src/telemetry/metrics.js.map +1 -1
- package/dist/src/telemetry/metrics.test.js +7 -0
- package/dist/src/telemetry/metrics.test.js.map +1 -1
- package/dist/src/telemetry/types.d.ts +3 -1
- package/dist/src/telemetry/types.js +19 -4
- package/dist/src/telemetry/types.js.map +1 -1
- package/dist/src/test-utils/mock-message-bus.d.ts +1 -19
- package/dist/src/test-utils/mock-message-bus.js +1 -65
- package/dist/src/test-utils/mock-message-bus.js.map +1 -1
- package/dist/src/tools/ask-user.d.ts +20 -0
- package/dist/src/tools/ask-user.js +142 -0
- package/dist/src/tools/ask-user.js.map +1 -0
- package/dist/src/{core/geminiChatHookTriggers.test.d.ts → tools/ask-user.test.d.ts} +1 -1
- package/dist/src/tools/ask-user.test.js +187 -0
- package/dist/src/tools/ask-user.test.js.map +1 -0
- package/dist/src/tools/confirmation-policy.test.js +1 -1
- package/dist/src/tools/confirmation-policy.test.js.map +1 -1
- package/dist/src/tools/diffOptions.d.ts +1 -1
- package/dist/src/tools/diffOptions.js +7 -3
- package/dist/src/tools/diffOptions.js.map +1 -1
- package/dist/src/tools/diffOptions.test.js +17 -0
- package/dist/src/tools/diffOptions.test.js.map +1 -1
- package/dist/src/tools/edit.js +1 -1
- package/dist/src/tools/edit.js.map +1 -1
- package/dist/src/tools/edit.test.js +11 -3
- package/dist/src/tools/edit.test.js.map +1 -1
- package/dist/src/tools/mcp-client-manager.d.ts +13 -4
- package/dist/src/tools/mcp-client-manager.js +53 -21
- package/dist/src/tools/mcp-client-manager.js.map +1 -1
- package/dist/src/tools/mcp-client-manager.test.js +1 -0
- package/dist/src/tools/mcp-client-manager.test.js.map +1 -1
- package/dist/src/tools/mcp-client.test.js +1 -2
- package/dist/src/tools/mcp-client.test.js.map +1 -1
- package/dist/src/tools/modifiable-tool.test.js +3 -3
- package/dist/src/tools/modifiable-tool.test.js.map +1 -1
- package/dist/src/tools/read-many-files.js +3 -2
- package/dist/src/tools/read-many-files.js.map +1 -1
- package/dist/src/tools/ripGrep.js +7 -2
- package/dist/src/tools/ripGrep.js.map +1 -1
- package/dist/src/tools/ripGrep.test.js +2 -2
- package/dist/src/tools/ripGrep.test.js.map +1 -1
- package/dist/src/tools/tool-names.d.ts +8 -2
- package/dist/src/tools/tool-names.js +14 -2
- package/dist/src/tools/tool-names.js.map +1 -1
- package/dist/src/tools/tools.d.ts +1 -0
- package/dist/src/tools/tools.js +2 -1
- package/dist/src/tools/tools.js.map +1 -1
- package/dist/src/tools/write-file.test.js +7 -7
- package/dist/src/tools/write-file.test.js.map +1 -1
- package/dist/src/utils/constants.d.ts +7 -0
- package/dist/src/utils/constants.js +8 -0
- package/dist/src/utils/constants.js.map +1 -0
- package/dist/src/utils/editCorrector.js +1 -1
- package/dist/src/utils/editCorrector.js.map +1 -1
- package/dist/src/utils/editor.js +4 -1
- package/dist/src/utils/editor.js.map +1 -1
- package/dist/src/utils/editor.test.js +6 -4
- package/dist/src/utils/editor.test.js.map +1 -1
- package/dist/src/utils/events.d.ts +2 -0
- package/dist/src/utils/events.js +1 -0
- package/dist/src/utils/events.js.map +1 -1
- package/dist/src/utils/extensionLoader.js +1 -0
- package/dist/src/utils/extensionLoader.js.map +1 -1
- package/dist/src/utils/extensionLoader.test.js +11 -0
- package/dist/src/utils/extensionLoader.test.js.map +1 -1
- package/dist/src/utils/googleQuotaErrors.d.ts +3 -3
- package/dist/src/utils/googleQuotaErrors.js +6 -17
- package/dist/src/utils/googleQuotaErrors.js.map +1 -1
- package/dist/src/utils/googleQuotaErrors.test.js +4 -22
- package/dist/src/utils/googleQuotaErrors.test.js.map +1 -1
- package/dist/src/utils/llm-edit-fixer.js +4 -7
- package/dist/src/utils/llm-edit-fixer.js.map +1 -1
- package/dist/src/utils/llm-edit-fixer.test.js +2 -2
- package/dist/src/utils/llm-edit-fixer.test.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.js +7 -24
- package/dist/src/utils/memoryImportProcessor.js.map +1 -1
- package/dist/src/utils/promptIdContext.d.ts +6 -0
- package/dist/src/utils/promptIdContext.js +15 -0
- package/dist/src/utils/promptIdContext.js.map +1 -1
- package/dist/src/utils/schemaValidator.d.ts +6 -0
- package/dist/src/utils/schemaValidator.js +12 -1
- package/dist/src/utils/schemaValidator.js.map +1 -1
- package/dist/src/utils/workspaceContext.d.ts +15 -0
- package/dist/src/utils/workspaceContext.js +32 -11
- package/dist/src/utils/workspaceContext.js.map +1 -1
- package/dist/src/utils/workspaceContext.test.js +55 -0
- package/dist/src/utils/workspaceContext.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -3
- package/dist/docs/changelogs/releases.md +0 -1543
- package/dist/google-gemini-cli-core-0.26.0-preview.3.tgz +0 -0
- package/dist/src/agents/delegate-to-agent-tool.d.ts +0 -19
- package/dist/src/agents/delegate-to-agent-tool.js +0 -178
- package/dist/src/agents/delegate-to-agent-tool.js.map +0 -1
- package/dist/src/agents/delegate-to-agent-tool.test.js +0 -213
- package/dist/src/agents/delegate-to-agent-tool.test.js.map +0 -1
- package/dist/src/agents/schema-utils.d.ts +0 -39
- package/dist/src/agents/schema-utils.js +0 -57
- package/dist/src/agents/schema-utils.js.map +0 -1
- package/dist/src/agents/schema-utils.test.js +0 -144
- package/dist/src/agents/schema-utils.test.js.map +0 -1
- package/dist/src/core/clientHookTriggers.d.ts +0 -36
- package/dist/src/core/clientHookTriggers.js +0 -76
- package/dist/src/core/clientHookTriggers.js.map +0 -1
- package/dist/src/core/geminiChatHookTriggers.d.ts +0 -68
- package/dist/src/core/geminiChatHookTriggers.js +0 -158
- package/dist/src/core/geminiChatHookTriggers.js.map +0 -1
- package/dist/src/core/geminiChatHookTriggers.test.js +0 -153
- package/dist/src/core/geminiChatHookTriggers.test.js.map +0 -1
- /package/dist/src/{agents/delegate-to-agent-tool.test.d.ts → core/prompts-substitution.test.d.ts} +0 -0
- /package/dist/src/{agents/schema-utils.test.d.ts → routing/strategies/numericalClassifierStrategy.test.d.ts} +0 -0
|
@@ -1,144 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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;AAGnE,MAAM,sBAAsB,GAAgB;IAC1C,MAAM,EAAE;QACN,IAAI,EAAE;YACJ,IAAI,EAAE,QAAQ;YACd,WAAW,EAAE,uBAAuB;YACpC,QAAQ,EAAE,IAAI;SACf;QACD,WAAW,EAAE;YACX,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C,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"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2025 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
import type { PartListUnion } from '@google/genai';
|
|
7
|
-
import type { MessageBus } from '../confirmation-bus/message-bus.js';
|
|
8
|
-
import { type DefaultHookOutput } from '../hooks/types.js';
|
|
9
|
-
/**
|
|
10
|
-
* Fires the BeforeAgent hook and returns the hook output.
|
|
11
|
-
* This should be called before processing a user prompt.
|
|
12
|
-
*
|
|
13
|
-
* The caller can use the returned DefaultHookOutput methods:
|
|
14
|
-
* - isBlockingDecision() / shouldStopExecution() to check if blocked
|
|
15
|
-
* - getEffectiveReason() to get the blocking reason
|
|
16
|
-
* - getAdditionalContext() to get additional context to add
|
|
17
|
-
*
|
|
18
|
-
* @param messageBus The message bus to use for hook communication
|
|
19
|
-
* @param request The user's request (prompt)
|
|
20
|
-
* @returns The hook output, or undefined if no hook was executed or on error
|
|
21
|
-
*/
|
|
22
|
-
export declare function fireBeforeAgentHook(messageBus: MessageBus, request: PartListUnion): Promise<DefaultHookOutput | undefined>;
|
|
23
|
-
/**
|
|
24
|
-
* Fires the AfterAgent hook and returns the hook output.
|
|
25
|
-
* This should be called after the agent has generated a response.
|
|
26
|
-
*
|
|
27
|
-
* The caller can use the returned DefaultHookOutput methods:
|
|
28
|
-
* - isBlockingDecision() / shouldStopExecution() to check if continuation is requested
|
|
29
|
-
* - getEffectiveReason() to get the continuation reason
|
|
30
|
-
*
|
|
31
|
-
* @param messageBus The message bus to use for hook communication
|
|
32
|
-
* @param request The original user's request (prompt)
|
|
33
|
-
* @param responseText The agent's response text
|
|
34
|
-
* @returns The hook output, or undefined if no hook was executed or on error
|
|
35
|
-
*/
|
|
36
|
-
export declare function fireAfterAgentHook(messageBus: MessageBus, request: PartListUnion, responseText: string): Promise<DefaultHookOutput | undefined>;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2025 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
import { MessageBusType, } from '../confirmation-bus/types.js';
|
|
7
|
-
import { createHookOutput } from '../hooks/types.js';
|
|
8
|
-
import { partToString } from '../utils/partUtils.js';
|
|
9
|
-
import { debugLogger } from '../utils/debugLogger.js';
|
|
10
|
-
/**
|
|
11
|
-
* Fires the BeforeAgent hook and returns the hook output.
|
|
12
|
-
* This should be called before processing a user prompt.
|
|
13
|
-
*
|
|
14
|
-
* The caller can use the returned DefaultHookOutput methods:
|
|
15
|
-
* - isBlockingDecision() / shouldStopExecution() to check if blocked
|
|
16
|
-
* - getEffectiveReason() to get the blocking reason
|
|
17
|
-
* - getAdditionalContext() to get additional context to add
|
|
18
|
-
*
|
|
19
|
-
* @param messageBus The message bus to use for hook communication
|
|
20
|
-
* @param request The user's request (prompt)
|
|
21
|
-
* @returns The hook output, or undefined if no hook was executed or on error
|
|
22
|
-
*/
|
|
23
|
-
export async function fireBeforeAgentHook(messageBus, request) {
|
|
24
|
-
try {
|
|
25
|
-
const promptText = partToString(request);
|
|
26
|
-
const response = await messageBus.request({
|
|
27
|
-
type: MessageBusType.HOOK_EXECUTION_REQUEST,
|
|
28
|
-
eventName: 'BeforeAgent',
|
|
29
|
-
input: {
|
|
30
|
-
prompt: promptText,
|
|
31
|
-
},
|
|
32
|
-
}, MessageBusType.HOOK_EXECUTION_RESPONSE);
|
|
33
|
-
return response.output
|
|
34
|
-
? createHookOutput('BeforeAgent', response.output)
|
|
35
|
-
: undefined;
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
debugLogger.debug(`BeforeAgent hook failed: ${error}`);
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Fires the AfterAgent hook and returns the hook output.
|
|
44
|
-
* This should be called after the agent has generated a response.
|
|
45
|
-
*
|
|
46
|
-
* The caller can use the returned DefaultHookOutput methods:
|
|
47
|
-
* - isBlockingDecision() / shouldStopExecution() to check if continuation is requested
|
|
48
|
-
* - getEffectiveReason() to get the continuation reason
|
|
49
|
-
*
|
|
50
|
-
* @param messageBus The message bus to use for hook communication
|
|
51
|
-
* @param request The original user's request (prompt)
|
|
52
|
-
* @param responseText The agent's response text
|
|
53
|
-
* @returns The hook output, or undefined if no hook was executed or on error
|
|
54
|
-
*/
|
|
55
|
-
export async function fireAfterAgentHook(messageBus, request, responseText) {
|
|
56
|
-
try {
|
|
57
|
-
const promptText = partToString(request);
|
|
58
|
-
const response = await messageBus.request({
|
|
59
|
-
type: MessageBusType.HOOK_EXECUTION_REQUEST,
|
|
60
|
-
eventName: 'AfterAgent',
|
|
61
|
-
input: {
|
|
62
|
-
prompt: promptText,
|
|
63
|
-
prompt_response: responseText,
|
|
64
|
-
stop_hook_active: false,
|
|
65
|
-
},
|
|
66
|
-
}, MessageBusType.HOOK_EXECUTION_RESPONSE);
|
|
67
|
-
return response.output
|
|
68
|
-
? createHookOutput('AfterAgent', response.output)
|
|
69
|
-
: undefined;
|
|
70
|
-
}
|
|
71
|
-
catch (error) {
|
|
72
|
-
debugLogger.debug(`AfterAgent hook failed: ${error}`);
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
//# sourceMappingURL=clientHookTriggers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clientHookTriggers.js","sourceRoot":"","sources":["../../../src/core/clientHookTriggers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EACL,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;aACxB;SACF,EACD,cAAc,CAAC,uBAAuB,CACvC,CAAC;QAEF,OAAO,QAAQ,CAAC,MAAM;YACpB,CAAC,CAAC,gBAAgB,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC;YACjD,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,WAAW,CAAC,KAAK,CAAC,2BAA2B,KAAK,EAAE,CAAC,CAAC;QACtD,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC"}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2025 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
import type { GenerateContentResponse, GenerateContentParameters, GenerateContentConfig, ContentListUnion, ToolConfig, ToolListUnion } from '@google/genai';
|
|
7
|
-
import type { MessageBus } from '../confirmation-bus/message-bus.js';
|
|
8
|
-
/**
|
|
9
|
-
* Result from firing the BeforeModel hook.
|
|
10
|
-
*/
|
|
11
|
-
export interface BeforeModelHookResult {
|
|
12
|
-
/** Whether the model call was blocked */
|
|
13
|
-
blocked: boolean;
|
|
14
|
-
/** Whether the execution should be stopped entirely */
|
|
15
|
-
stopped?: boolean;
|
|
16
|
-
/** Reason for blocking (if blocked) */
|
|
17
|
-
reason?: string;
|
|
18
|
-
/** Synthetic response to return instead of calling the model (if blocked) */
|
|
19
|
-
syntheticResponse?: GenerateContentResponse;
|
|
20
|
-
/** Modified config (if not blocked) */
|
|
21
|
-
modifiedConfig?: GenerateContentConfig;
|
|
22
|
-
/** Modified contents (if not blocked) */
|
|
23
|
-
modifiedContents?: ContentListUnion;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Result from firing the BeforeToolSelection hook.
|
|
27
|
-
*/
|
|
28
|
-
export interface BeforeToolSelectionHookResult {
|
|
29
|
-
/** Modified tool config */
|
|
30
|
-
toolConfig?: ToolConfig;
|
|
31
|
-
/** Modified tools */
|
|
32
|
-
tools?: ToolListUnion;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Result from firing the AfterModel hook.
|
|
36
|
-
* Contains either a modified response or indicates to use the original chunk.
|
|
37
|
-
*/
|
|
38
|
-
export interface AfterModelHookResult {
|
|
39
|
-
/** The response to yield (either modified or original) */
|
|
40
|
-
response: GenerateContentResponse;
|
|
41
|
-
/** Whether the execution should be stopped entirely */
|
|
42
|
-
stopped?: boolean;
|
|
43
|
-
/** Whether the model call was blocked */
|
|
44
|
-
blocked?: boolean;
|
|
45
|
-
/** Reason for blocking or stopping */
|
|
46
|
-
reason?: string;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Fires the BeforeModel hook and returns the result.
|
|
50
|
-
*/
|
|
51
|
-
export declare function fireBeforeModelHook(messageBus: MessageBus, llmRequest: GenerateContentParameters): Promise<BeforeModelHookResult>;
|
|
52
|
-
/**
|
|
53
|
-
* Fires the BeforeToolSelection hook and returns the result.
|
|
54
|
-
*
|
|
55
|
-
* @param messageBus The message bus to use for hook communication
|
|
56
|
-
* @param llmRequest The LLM request parameters
|
|
57
|
-
* @returns The hook result with tool configuration modifications
|
|
58
|
-
*/
|
|
59
|
-
export declare function fireBeforeToolSelectionHook(messageBus: MessageBus, llmRequest: GenerateContentParameters): Promise<BeforeToolSelectionHookResult>;
|
|
60
|
-
/**
|
|
61
|
-
* Fires the AfterModel hook and returns the result.
|
|
62
|
-
*
|
|
63
|
-
* @param messageBus The message bus to use for hook communication
|
|
64
|
-
* @param originalRequest The original LLM request parameters
|
|
65
|
-
* @param chunk The current response chunk from the model
|
|
66
|
-
* @returns The hook result containing the response to yield
|
|
67
|
-
*/
|
|
68
|
-
export declare function fireAfterModelHook(messageBus: MessageBus, originalRequest: GenerateContentParameters, chunk: GenerateContentResponse): Promise<AfterModelHookResult>;
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2025 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
|
-
import { MessageBusType, } from '../confirmation-bus/types.js';
|
|
7
|
-
import { createHookOutput, } from '../hooks/types.js';
|
|
8
|
-
import { debugLogger } from '../utils/debugLogger.js';
|
|
9
|
-
/**
|
|
10
|
-
* Fires the BeforeModel hook and returns the result.
|
|
11
|
-
*/
|
|
12
|
-
export async function fireBeforeModelHook(messageBus, llmRequest) {
|
|
13
|
-
try {
|
|
14
|
-
const response = await messageBus.request({
|
|
15
|
-
type: MessageBusType.HOOK_EXECUTION_REQUEST,
|
|
16
|
-
eventName: 'BeforeModel',
|
|
17
|
-
input: {
|
|
18
|
-
llm_request: llmRequest,
|
|
19
|
-
},
|
|
20
|
-
}, MessageBusType.HOOK_EXECUTION_RESPONSE);
|
|
21
|
-
// Reconstruct result from response
|
|
22
|
-
const beforeResultFinalOutput = response.output
|
|
23
|
-
? createHookOutput('BeforeModel', response.output)
|
|
24
|
-
: undefined;
|
|
25
|
-
const hookOutput = beforeResultFinalOutput;
|
|
26
|
-
// Check if hook requested to stop execution
|
|
27
|
-
if (hookOutput?.shouldStopExecution()) {
|
|
28
|
-
return {
|
|
29
|
-
blocked: true,
|
|
30
|
-
stopped: true,
|
|
31
|
-
reason: hookOutput.getEffectiveReason(),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
// Check if hook blocked the model call
|
|
35
|
-
const blockingError = hookOutput?.getBlockingError();
|
|
36
|
-
if (blockingError?.blocked) {
|
|
37
|
-
const beforeModelOutput = hookOutput;
|
|
38
|
-
const syntheticResponse = beforeModelOutput.getSyntheticResponse();
|
|
39
|
-
const reason = hookOutput?.getEffectiveReason() || 'Model call blocked by hook';
|
|
40
|
-
return {
|
|
41
|
-
blocked: true,
|
|
42
|
-
reason,
|
|
43
|
-
syntheticResponse,
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
// Apply modifications from hook
|
|
47
|
-
if (hookOutput) {
|
|
48
|
-
const beforeModelOutput = hookOutput;
|
|
49
|
-
const modifiedRequest = beforeModelOutput.applyLLMRequestModifications(llmRequest);
|
|
50
|
-
return {
|
|
51
|
-
blocked: false,
|
|
52
|
-
modifiedConfig: modifiedRequest.config,
|
|
53
|
-
modifiedContents: modifiedRequest.contents,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
return { blocked: false };
|
|
57
|
-
}
|
|
58
|
-
catch (error) {
|
|
59
|
-
debugLogger.debug(`BeforeModel hook failed:`, error);
|
|
60
|
-
return { blocked: false };
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Fires the BeforeToolSelection hook and returns the result.
|
|
65
|
-
*
|
|
66
|
-
* @param messageBus The message bus to use for hook communication
|
|
67
|
-
* @param llmRequest The LLM request parameters
|
|
68
|
-
* @returns The hook result with tool configuration modifications
|
|
69
|
-
*/
|
|
70
|
-
export async function fireBeforeToolSelectionHook(messageBus, llmRequest) {
|
|
71
|
-
try {
|
|
72
|
-
const response = await messageBus.request({
|
|
73
|
-
type: MessageBusType.HOOK_EXECUTION_REQUEST,
|
|
74
|
-
eventName: 'BeforeToolSelection',
|
|
75
|
-
input: {
|
|
76
|
-
llm_request: llmRequest,
|
|
77
|
-
},
|
|
78
|
-
}, MessageBusType.HOOK_EXECUTION_RESPONSE);
|
|
79
|
-
// Reconstruct result from response
|
|
80
|
-
const toolSelectionResultFinalOutput = response.output
|
|
81
|
-
? createHookOutput('BeforeToolSelection', response.output)
|
|
82
|
-
: undefined;
|
|
83
|
-
// Apply tool configuration modifications
|
|
84
|
-
if (toolSelectionResultFinalOutput) {
|
|
85
|
-
const beforeToolSelectionOutput = toolSelectionResultFinalOutput;
|
|
86
|
-
const modifiedConfig = beforeToolSelectionOutput.applyToolConfigModifications({
|
|
87
|
-
toolConfig: llmRequest.config?.toolConfig,
|
|
88
|
-
tools: llmRequest.config?.tools,
|
|
89
|
-
});
|
|
90
|
-
return {
|
|
91
|
-
toolConfig: modifiedConfig.toolConfig,
|
|
92
|
-
tools: modifiedConfig.tools,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
return {};
|
|
96
|
-
}
|
|
97
|
-
catch (error) {
|
|
98
|
-
debugLogger.debug(`BeforeToolSelection hook failed:`, error);
|
|
99
|
-
return {};
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Fires the AfterModel hook and returns the result.
|
|
104
|
-
*
|
|
105
|
-
* @param messageBus The message bus to use for hook communication
|
|
106
|
-
* @param originalRequest The original LLM request parameters
|
|
107
|
-
* @param chunk The current response chunk from the model
|
|
108
|
-
* @returns The hook result containing the response to yield
|
|
109
|
-
*/
|
|
110
|
-
export async function fireAfterModelHook(messageBus, originalRequest, chunk) {
|
|
111
|
-
try {
|
|
112
|
-
const response = await messageBus.request({
|
|
113
|
-
type: MessageBusType.HOOK_EXECUTION_REQUEST,
|
|
114
|
-
eventName: 'AfterModel',
|
|
115
|
-
input: {
|
|
116
|
-
llm_request: originalRequest,
|
|
117
|
-
llm_response: chunk,
|
|
118
|
-
},
|
|
119
|
-
}, MessageBusType.HOOK_EXECUTION_RESPONSE);
|
|
120
|
-
// Reconstruct result from response
|
|
121
|
-
const afterResultFinalOutput = response.output
|
|
122
|
-
? createHookOutput('AfterModel', response.output)
|
|
123
|
-
: undefined;
|
|
124
|
-
const hookOutput = afterResultFinalOutput;
|
|
125
|
-
// Check if hook requested to stop execution
|
|
126
|
-
if (hookOutput?.shouldStopExecution()) {
|
|
127
|
-
return {
|
|
128
|
-
response: chunk,
|
|
129
|
-
stopped: true,
|
|
130
|
-
reason: hookOutput.getEffectiveReason(),
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
// Check if hook blocked the model call
|
|
134
|
-
const blockingError = hookOutput?.getBlockingError();
|
|
135
|
-
if (blockingError?.blocked) {
|
|
136
|
-
return {
|
|
137
|
-
response: chunk,
|
|
138
|
-
blocked: true,
|
|
139
|
-
reason: hookOutput?.getEffectiveReason(),
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
// Apply modifications from hook
|
|
143
|
-
if (hookOutput) {
|
|
144
|
-
const afterModelOutput = hookOutput;
|
|
145
|
-
const modifiedResponse = afterModelOutput.getModifiedResponse();
|
|
146
|
-
if (modifiedResponse) {
|
|
147
|
-
return { response: modifiedResponse };
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
return { response: chunk };
|
|
151
|
-
}
|
|
152
|
-
catch (error) {
|
|
153
|
-
debugLogger.debug(`AfterModel hook failed:`, error);
|
|
154
|
-
// On error, return original chunk to avoid interrupting the stream.
|
|
155
|
-
return { response: chunk };
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
//# sourceMappingURL=geminiChatHookTriggers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"geminiChatHookTriggers.js","sourceRoot":"","sources":["../../../src/core/geminiChatHookTriggers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH,OAAO,EACL,cAAc,GAGf,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,gBAAgB,GAIjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AA6CtD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,UAAsB,EACtB,UAAqC;IAErC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,UAAU,CAAC,OAAO,CAIvC;YACE,IAAI,EAAE,cAAc,CAAC,sBAAsB;YAC3C,SAAS,EAAE,aAAa;YACxB,KAAK,EAAE;gBACL,WAAW,EAAE,UAAgD;aAC9D;SACF,EACD,cAAc,CAAC,uBAAuB,CACvC,CAAC;QAEF,mCAAmC;QACnC,MAAM,uBAAuB,GAAG,QAAQ,CAAC,MAAM;YAC7C,CAAC,CAAC,gBAAgB,CAAC,aAAa,EAAE,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 -1,153 +0,0 @@
|
|
|
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 { fireBeforeModelHook, fireAfterModelHook, } from './geminiChatHookTriggers.js';
|
|
8
|
-
// Mock dependencies
|
|
9
|
-
const mockRequest = vi.fn();
|
|
10
|
-
const mockMessageBus = {
|
|
11
|
-
request: mockRequest,
|
|
12
|
-
};
|
|
13
|
-
// Mock hook types
|
|
14
|
-
vi.mock('../hooks/types.js', async () => {
|
|
15
|
-
const actual = await vi.importActual('../hooks/types.js');
|
|
16
|
-
return {
|
|
17
|
-
...actual,
|
|
18
|
-
createHookOutput: vi.fn(),
|
|
19
|
-
};
|
|
20
|
-
});
|
|
21
|
-
import { createHookOutput } from '../hooks/types.js';
|
|
22
|
-
describe('Gemini Chat Hook Triggers', () => {
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
vi.clearAllMocks();
|
|
25
|
-
});
|
|
26
|
-
describe('fireBeforeModelHook', () => {
|
|
27
|
-
const llmRequest = {
|
|
28
|
-
model: 'gemini-pro',
|
|
29
|
-
contents: [{ parts: [{ text: 'test' }] }],
|
|
30
|
-
};
|
|
31
|
-
it('should return stopped: true when hook requests stop execution', async () => {
|
|
32
|
-
mockRequest.mockResolvedValue({
|
|
33
|
-
output: { continue: false, stopReason: 'stopped by hook' },
|
|
34
|
-
});
|
|
35
|
-
vi.mocked(createHookOutput).mockReturnValue({
|
|
36
|
-
shouldStopExecution: () => true,
|
|
37
|
-
getEffectiveReason: () => 'stopped by hook',
|
|
38
|
-
getBlockingError: () => ({ blocked: false, reason: '' }),
|
|
39
|
-
});
|
|
40
|
-
const result = await fireBeforeModelHook(mockMessageBus, llmRequest);
|
|
41
|
-
expect(result).toEqual({
|
|
42
|
-
blocked: true,
|
|
43
|
-
stopped: true,
|
|
44
|
-
reason: 'stopped by hook',
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
it('should return blocked: true when hook blocks execution', async () => {
|
|
48
|
-
mockRequest.mockResolvedValue({
|
|
49
|
-
output: { decision: 'block', reason: 'blocked by hook' },
|
|
50
|
-
});
|
|
51
|
-
vi.mocked(createHookOutput).mockReturnValue({
|
|
52
|
-
shouldStopExecution: () => false,
|
|
53
|
-
getBlockingError: () => ({ blocked: true, reason: 'blocked by hook' }),
|
|
54
|
-
getEffectiveReason: () => 'blocked by hook',
|
|
55
|
-
getSyntheticResponse: () => undefined,
|
|
56
|
-
});
|
|
57
|
-
const result = await fireBeforeModelHook(mockMessageBus, llmRequest);
|
|
58
|
-
expect(result).toEqual({
|
|
59
|
-
blocked: true,
|
|
60
|
-
reason: 'blocked by hook',
|
|
61
|
-
syntheticResponse: undefined,
|
|
62
|
-
});
|
|
63
|
-
});
|
|
64
|
-
it('should return modifications when hook allows execution', async () => {
|
|
65
|
-
mockRequest.mockResolvedValue({
|
|
66
|
-
output: { decision: 'allow' },
|
|
67
|
-
});
|
|
68
|
-
vi.mocked(createHookOutput).mockReturnValue({
|
|
69
|
-
shouldStopExecution: () => false,
|
|
70
|
-
getBlockingError: () => ({ blocked: false, reason: '' }),
|
|
71
|
-
applyLLMRequestModifications: (req) => req,
|
|
72
|
-
});
|
|
73
|
-
const result = await fireBeforeModelHook(mockMessageBus, llmRequest);
|
|
74
|
-
expect(result).toEqual({
|
|
75
|
-
blocked: false,
|
|
76
|
-
modifiedConfig: undefined,
|
|
77
|
-
modifiedContents: llmRequest.contents,
|
|
78
|
-
});
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
describe('fireAfterModelHook', () => {
|
|
82
|
-
const llmRequest = {
|
|
83
|
-
model: 'gemini-pro',
|
|
84
|
-
contents: [],
|
|
85
|
-
};
|
|
86
|
-
const llmResponse = {
|
|
87
|
-
candidates: [
|
|
88
|
-
{ content: { role: 'model', parts: [{ text: 'response' }] } },
|
|
89
|
-
],
|
|
90
|
-
};
|
|
91
|
-
it('should return stopped: true when hook requests stop execution', async () => {
|
|
92
|
-
mockRequest.mockResolvedValue({
|
|
93
|
-
output: { continue: false, stopReason: 'stopped by hook' },
|
|
94
|
-
});
|
|
95
|
-
vi.mocked(createHookOutput).mockReturnValue({
|
|
96
|
-
shouldStopExecution: () => true,
|
|
97
|
-
getEffectiveReason: () => 'stopped by hook',
|
|
98
|
-
});
|
|
99
|
-
const result = await fireAfterModelHook(mockMessageBus, llmRequest, llmResponse);
|
|
100
|
-
expect(result).toEqual({
|
|
101
|
-
response: llmResponse,
|
|
102
|
-
stopped: true,
|
|
103
|
-
reason: 'stopped by hook',
|
|
104
|
-
});
|
|
105
|
-
});
|
|
106
|
-
it('should return blocked: true when hook blocks execution', async () => {
|
|
107
|
-
mockRequest.mockResolvedValue({
|
|
108
|
-
output: { decision: 'block', reason: 'blocked by hook' },
|
|
109
|
-
});
|
|
110
|
-
vi.mocked(createHookOutput).mockReturnValue({
|
|
111
|
-
shouldStopExecution: () => false,
|
|
112
|
-
getBlockingError: () => ({ blocked: true, reason: 'blocked by hook' }),
|
|
113
|
-
getEffectiveReason: () => 'blocked by hook',
|
|
114
|
-
});
|
|
115
|
-
const result = await fireAfterModelHook(mockMessageBus, llmRequest, llmResponse);
|
|
116
|
-
expect(result).toEqual({
|
|
117
|
-
response: llmResponse,
|
|
118
|
-
blocked: true,
|
|
119
|
-
reason: 'blocked by hook',
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
it('should return modified response when hook modifies response', async () => {
|
|
123
|
-
const modifiedResponse = { ...llmResponse, text: 'modified' };
|
|
124
|
-
mockRequest.mockResolvedValue({
|
|
125
|
-
output: { hookSpecificOutput: { llm_response: {} } },
|
|
126
|
-
});
|
|
127
|
-
vi.mocked(createHookOutput).mockReturnValue({
|
|
128
|
-
shouldStopExecution: () => false,
|
|
129
|
-
getBlockingError: () => ({ blocked: false, reason: '' }),
|
|
130
|
-
getModifiedResponse: () => modifiedResponse,
|
|
131
|
-
});
|
|
132
|
-
const result = await fireAfterModelHook(mockMessageBus, llmRequest, llmResponse);
|
|
133
|
-
expect(result).toEqual({
|
|
134
|
-
response: modifiedResponse,
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
it('should return original response when hook has no effect', async () => {
|
|
138
|
-
mockRequest.mockResolvedValue({
|
|
139
|
-
output: {},
|
|
140
|
-
});
|
|
141
|
-
vi.mocked(createHookOutput).mockReturnValue({
|
|
142
|
-
shouldStopExecution: () => false,
|
|
143
|
-
getBlockingError: () => ({ blocked: false, reason: '' }),
|
|
144
|
-
getModifiedResponse: () => undefined,
|
|
145
|
-
});
|
|
146
|
-
const result = await fireAfterModelHook(mockMessageBus, llmRequest, llmResponse);
|
|
147
|
-
expect(result).toEqual({
|
|
148
|
-
response: llmResponse,
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
//# sourceMappingURL=geminiChatHookTriggers.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"geminiChatHookTriggers.test.js","sourceRoot":"","sources":["../../../src/core/geminiChatHookTriggers.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC9D,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,6BAA6B,CAAC;AAOrC,oBAAoB;AACpB,MAAM,WAAW,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;AAC5B,MAAM,cAAc,GAAG;IACrB,OAAO,EAAE,WAAW;CACI,CAAC;AAE3B,kBAAkB;AAClB,EAAE,CAAC,IAAI,CAAC,mBAAmB,EAAE,KAAK,IAAI,EAAE;IACtC,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,YAAY,CAAC,mBAAmB,CAAC,CAAC;IAC1D,OAAO;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