@office-ai/aioncli-core 0.2.3 → 0.18.4
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 +16 -3
- package/dist/index.js +15 -3
- package/dist/index.js.map +1 -1
- package/dist/src/agents/codebase-investigator.d.ts +46 -0
- package/dist/src/agents/codebase-investigator.js +132 -0
- package/dist/src/agents/codebase-investigator.js.map +1 -0
- package/dist/src/agents/codebase-investigator.test.js +35 -0
- package/dist/src/agents/codebase-investigator.test.js.map +1 -0
- package/dist/src/agents/executor.d.ts +114 -0
- package/dist/src/agents/executor.js +779 -0
- package/dist/src/agents/executor.js.map +1 -0
- package/dist/src/agents/executor.test.js +1362 -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.js +215 -0
- package/dist/src/agents/invocation.test.js.map +1 -0
- package/dist/src/agents/registry.d.ts +40 -0
- package/dist/src/agents/registry.js +105 -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 +160 -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 +110 -0
- package/dist/src/agents/subagent-tool-wrapper.test.js.map +1 -0
- package/dist/src/agents/types.d.ts +146 -0
- package/dist/src/agents/types.js +19 -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/codeAssist.d.ts +6 -3
- package/dist/src/code_assist/codeAssist.js +13 -1
- package/dist/src/code_assist/codeAssist.js.map +1 -1
- package/dist/src/code_assist/codeAssist.test.d.ts +6 -0
- package/dist/src/code_assist/codeAssist.test.js +99 -0
- package/dist/src/code_assist/codeAssist.test.js.map +1 -0
- package/dist/src/code_assist/converter.d.ts +5 -1
- package/dist/src/code_assist/converter.js +39 -5
- package/dist/src/code_assist/converter.js.map +1 -1
- package/dist/src/code_assist/converter.test.js +112 -0
- package/dist/src/code_assist/converter.test.js.map +1 -1
- package/dist/src/code_assist/experiments/client_metadata.d.ts +12 -0
- package/dist/src/code_assist/experiments/client_metadata.js +50 -0
- package/dist/src/code_assist/experiments/client_metadata.js.map +1 -0
- package/dist/src/code_assist/experiments/client_metadata.test.d.ts +6 -0
- package/dist/src/code_assist/experiments/client_metadata.test.js +99 -0
- package/dist/src/code_assist/experiments/client_metadata.test.js.map +1 -0
- package/dist/src/code_assist/experiments/experiments.d.ts +17 -0
- package/dist/src/code_assist/experiments/experiments.js +36 -0
- package/dist/src/code_assist/experiments/experiments.js.map +1 -0
- package/dist/src/code_assist/experiments/experiments.test.d.ts +6 -0
- package/dist/src/code_assist/experiments/experiments.test.js +92 -0
- package/dist/src/code_assist/experiments/experiments.test.js.map +1 -0
- package/dist/src/code_assist/experiments/flagNames.d.ts +13 -0
- package/dist/src/code_assist/experiments/flagNames.js +13 -0
- package/dist/src/code_assist/experiments/flagNames.js.map +1 -0
- package/dist/src/code_assist/experiments/types.d.ts +35 -0
- package/dist/src/code_assist/experiments/types.js +7 -0
- package/dist/src/code_assist/experiments/types.js.map +1 -0
- package/dist/src/code_assist/oauth-credential-storage.d.ts +25 -0
- package/dist/src/code_assist/oauth-credential-storage.js +110 -0
- package/dist/src/code_assist/oauth-credential-storage.js.map +1 -0
- package/dist/src/code_assist/oauth-credential-storage.test.d.ts +6 -0
- package/dist/src/code_assist/oauth-credential-storage.test.js +198 -0
- package/dist/src/code_assist/oauth-credential-storage.test.js.map +1 -0
- package/dist/src/code_assist/oauth2.d.ts +3 -3
- package/dist/src/code_assist/oauth2.js +252 -125
- package/dist/src/code_assist/oauth2.js.map +1 -1
- package/dist/src/code_assist/oauth2.test.js +788 -350
- package/dist/src/code_assist/oauth2.test.js.map +1 -1
- package/dist/src/code_assist/server.d.ts +8 -6
- package/dist/src/code_assist/server.js +41 -10
- package/dist/src/code_assist/server.js.map +1 -1
- package/dist/src/code_assist/server.test.js +151 -28
- package/dist/src/code_assist/server.test.js.map +1 -1
- package/dist/src/code_assist/setup.d.ts +2 -2
- package/dist/src/code_assist/setup.js +5 -3
- package/dist/src/code_assist/setup.js.map +1 -1
- package/dist/src/code_assist/setup.test.js.map +1 -1
- package/dist/src/code_assist/types.d.ts +18 -3
- package/dist/src/code_assist/types.js.map +1 -1
- package/dist/src/commands/extensions.d.ts +7 -0
- package/dist/src/commands/extensions.js +9 -0
- package/dist/src/commands/extensions.js.map +1 -0
- package/dist/src/commands/extensions.test.d.ts +6 -0
- package/dist/src/commands/extensions.test.js +19 -0
- package/dist/src/commands/extensions.test.js.map +1 -0
- package/dist/src/config/config.d.ts +282 -60
- package/dist/src/config/config.js +677 -129
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/config.test.js +1020 -146
- 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/defaultModelConfigs.d.ts +7 -0
- package/dist/src/config/defaultModelConfigs.js +185 -0
- package/dist/src/config/defaultModelConfigs.js.map +1 -0
- package/dist/src/config/models.d.ts +37 -0
- package/dist/src/config/models.js +72 -0
- package/dist/src/config/models.js.map +1 -1
- package/dist/src/config/models.test.d.ts +6 -0
- package/dist/src/config/models.test.js +116 -0
- package/dist/src/config/models.test.js.map +1 -0
- package/dist/src/config/storage.d.ts +36 -0
- package/dist/src/config/storage.js +115 -0
- package/dist/src/config/storage.js.map +1 -0
- package/dist/src/config/storage.test.d.ts +6 -0
- package/dist/src/config/storage.test.js +48 -0
- package/dist/src/config/storage.test.js.map +1 -0
- package/dist/src/confirmation-bus/index.d.ts +7 -0
- package/dist/src/confirmation-bus/index.js +8 -0
- package/dist/src/confirmation-bus/index.js.map +1 -0
- package/dist/src/confirmation-bus/message-bus.d.ts +18 -0
- package/dist/src/confirmation-bus/message-bus.js +87 -0
- package/dist/src/confirmation-bus/message-bus.js.map +1 -0
- package/dist/src/confirmation-bus/message-bus.test.d.ts +6 -0
- package/dist/src/confirmation-bus/message-bus.test.js +170 -0
- package/dist/src/confirmation-bus/message-bus.test.js.map +1 -0
- package/dist/src/confirmation-bus/types.d.ts +49 -0
- package/dist/src/confirmation-bus/types.js +16 -0
- package/dist/src/confirmation-bus/types.js.map +1 -0
- package/dist/src/core/apiKeyCredentialStorage.d.ts +17 -0
- package/dist/src/core/apiKeyCredentialStorage.js +64 -0
- package/dist/src/core/apiKeyCredentialStorage.js.map +1 -0
- package/dist/src/core/apiKeyCredentialStorage.test.d.ts +6 -0
- package/dist/src/core/apiKeyCredentialStorage.test.js +71 -0
- package/dist/src/core/apiKeyCredentialStorage.test.js.map +1 -0
- package/dist/src/core/baseLlmClient.d.ts +50 -0
- package/dist/src/core/baseLlmClient.js +185 -0
- package/dist/src/core/baseLlmClient.js.map +1 -0
- package/dist/src/core/baseLlmClient.test.d.ts +6 -0
- package/dist/src/core/baseLlmClient.test.js +311 -0
- package/dist/src/core/baseLlmClient.test.js.map +1 -0
- package/dist/src/core/client.d.ts +30 -42
- package/dist/src/core/client.js +178 -477
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/client.test.js +739 -617
- package/dist/src/core/client.test.js.map +1 -1
- package/dist/src/core/contentGenerator.d.ts +7 -6
- package/dist/src/core/contentGenerator.js +59 -45
- package/dist/src/core/contentGenerator.js.map +1 -1
- package/dist/src/core/contentGenerator.test.js +50 -4
- package/dist/src/core/contentGenerator.test.js.map +1 -1
- package/dist/src/core/coreToolScheduler.d.ts +28 -11
- package/dist/src/core/coreToolScheduler.js +493 -161
- package/dist/src/core/coreToolScheduler.js.map +1 -1
- package/dist/src/core/coreToolScheduler.test.js +995 -163
- package/dist/src/core/coreToolScheduler.test.js.map +1 -1
- package/dist/src/core/fakeContentGenerator.d.ts +33 -0
- package/dist/src/core/fakeContentGenerator.js +58 -0
- package/dist/src/core/fakeContentGenerator.js.map +1 -0
- package/dist/src/core/fakeContentGenerator.test.d.ts +6 -0
- package/dist/src/core/fakeContentGenerator.test.js +127 -0
- package/dist/src/core/fakeContentGenerator.test.js.map +1 -0
- package/dist/src/core/geminiChat.d.ts +61 -55
- package/dist/src/core/geminiChat.js +388 -366
- package/dist/src/core/geminiChat.js.map +1 -1
- package/dist/src/core/geminiChat.test.js +1600 -355
- package/dist/src/core/geminiChat.test.js.map +1 -1
- package/dist/src/core/geminiRequest.js +1 -0
- package/dist/src/core/geminiRequest.js.map +1 -1
- package/dist/src/core/logger.d.ts +11 -4
- package/dist/src/core/logger.js +39 -30
- package/dist/src/core/logger.js.map +1 -1
- package/dist/src/core/logger.test.js +62 -45
- package/dist/src/core/logger.test.js.map +1 -1
- package/dist/src/core/loggingContentGenerator.d.ts +4 -3
- package/dist/src/core/loggingContentGenerator.js +116 -37
- package/dist/src/core/loggingContentGenerator.js.map +1 -1
- package/dist/src/core/loggingContentGenerator.test.d.ts +6 -0
- package/dist/src/core/loggingContentGenerator.test.js +180 -0
- package/dist/src/core/loggingContentGenerator.test.js.map +1 -0
- package/dist/src/core/nonInteractiveToolExecutor.d.ts +4 -5
- package/dist/src/core/nonInteractiveToolExecutor.js +17 -120
- package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.test.js +168 -84
- package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
- package/dist/src/core/openaiContentGenerator.d.ts +4 -3
- package/dist/src/core/openaiContentGenerator.js +49 -19
- package/dist/src/core/openaiContentGenerator.js.map +1 -1
- package/dist/src/core/openaiContentGenerator.test.js +1 -0
- package/dist/src/core/openaiContentGenerator.test.js.map +1 -1
- package/dist/src/core/prompts.d.ts +7 -1
- package/dist/src/core/prompts.js +198 -195
- package/dist/src/core/prompts.js.map +1 -1
- package/dist/src/core/prompts.test.js +172 -104
- package/dist/src/core/prompts.test.js.map +1 -1
- package/dist/src/core/recordingContentGenerator.d.ts +18 -0
- package/dist/src/core/recordingContentGenerator.js +77 -0
- package/dist/src/core/recordingContentGenerator.js.map +1 -0
- package/dist/src/core/recordingContentGenerator.test.d.ts +6 -0
- package/dist/src/core/recordingContentGenerator.test.js +101 -0
- package/dist/src/core/recordingContentGenerator.test.js.map +1 -0
- package/dist/src/core/subagent.d.ts +24 -18
- package/dist/src/core/subagent.js +125 -90
- package/dist/src/core/subagent.js.map +1 -1
- package/dist/src/core/subagent.test.js +59 -44
- package/dist/src/core/subagent.test.js.map +1 -1
- package/dist/src/core/tokenLimits.test.d.ts +6 -0
- package/dist/src/core/tokenLimits.test.js +26 -0
- package/dist/src/core/tokenLimits.test.js.map +1 -0
- package/dist/src/core/turn.d.ts +57 -13
- package/dist/src/core/turn.js +79 -35
- package/dist/src/core/turn.js.map +1 -1
- package/dist/src/core/turn.test.js +373 -120
- package/dist/src/core/turn.test.js.map +1 -1
- package/dist/src/fallback/handler.d.ts +7 -0
- package/dist/src/fallback/handler.js +181 -0
- package/dist/src/fallback/handler.js.map +1 -0
- package/dist/src/fallback/handler.test.d.ts +6 -0
- package/dist/src/fallback/handler.test.js +245 -0
- package/dist/src/fallback/handler.test.js.map +1 -0
- package/dist/src/fallback/types.d.ts +14 -0
- package/dist/src/fallback/types.js +7 -0
- package/dist/src/fallback/types.js.map +1 -0
- 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.d.ts +68 -0
- package/dist/src/hooks/hookAggregator.js +262 -0
- package/dist/src/hooks/hookAggregator.js.map +1 -0
- package/dist/src/hooks/hookAggregator.test.d.ts +6 -0
- package/dist/src/hooks/hookAggregator.test.js +387 -0
- package/dist/src/hooks/hookAggregator.test.js.map +1 -0
- package/dist/src/hooks/hookPlanner.d.ts +46 -0
- package/dist/src/hooks/hookPlanner.js +108 -0
- package/dist/src/hooks/hookPlanner.js.map +1 -0
- package/dist/src/hooks/hookPlanner.test.d.ts +6 -0
- package/dist/src/hooks/hookPlanner.test.js +255 -0
- package/dist/src/hooks/hookPlanner.test.js.map +1 -0
- package/dist/src/hooks/hookRegistry.d.ts +87 -0
- package/dist/src/hooks/hookRegistry.js +198 -0
- package/dist/src/hooks/hookRegistry.js.map +1 -0
- package/dist/src/hooks/hookRegistry.test.d.ts +6 -0
- package/dist/src/hooks/hookRegistry.test.js +341 -0
- package/dist/src/hooks/hookRegistry.test.js.map +1 -0
- package/dist/src/hooks/hookRunner.d.ts +42 -0
- package/dist/src/hooks/hookRunner.js +272 -0
- package/dist/src/hooks/hookRunner.js.map +1 -0
- package/dist/src/hooks/hookRunner.test.d.ts +6 -0
- package/dist/src/hooks/hookRunner.test.js +468 -0
- package/dist/src/hooks/hookRunner.test.js.map +1 -0
- package/dist/src/hooks/hookTranslator.d.ts +113 -0
- package/dist/src/hooks/hookTranslator.js +232 -0
- package/dist/src/hooks/hookTranslator.js.map +1 -0
- package/dist/src/hooks/hookTranslator.test.d.ts +6 -0
- package/dist/src/hooks/hookTranslator.test.js +192 -0
- package/dist/src/hooks/hookTranslator.test.js.map +1 -0
- package/dist/src/hooks/types.d.ts +384 -0
- package/dist/src/hooks/types.js +284 -0
- package/dist/src/hooks/types.js.map +1 -0
- package/dist/src/hooks/types.test.d.ts +6 -0
- package/dist/src/hooks/types.test.js +313 -0
- package/dist/src/hooks/types.test.js.map +1 -0
- package/dist/src/ide/constants.d.ts +3 -0
- package/dist/src/ide/constants.js +3 -0
- package/dist/src/ide/constants.js.map +1 -1
- package/dist/src/ide/detect-ide.d.ts +52 -12
- package/dist/src/ide/detect-ide.js +51 -65
- package/dist/src/ide/detect-ide.js.map +1 -1
- package/dist/src/ide/detect-ide.test.js +95 -52
- package/dist/src/ide/detect-ide.test.js.map +1 -1
- package/dist/src/ide/ide-client.d.ts +72 -24
- package/dist/src/ide/ide-client.js +380 -84
- package/dist/src/ide/ide-client.js.map +1 -1
- package/dist/src/ide/ide-client.test.js +539 -35
- 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 +93 -35
- package/dist/src/ide/ide-installer.js.map +1 -1
- package/dist/src/ide/ide-installer.test.js +157 -26
- package/dist/src/ide/ide-installer.test.js.map +1 -1
- package/dist/src/ide/ideContext.d.ts +35 -365
- package/dist/src/ide/ideContext.js +60 -106
- package/dist/src/ide/ideContext.js.map +1 -1
- package/dist/src/ide/ideContext.test.js +152 -24
- package/dist/src/ide/ideContext.test.js.map +1 -1
- package/dist/src/ide/process-utils.d.ts +7 -5
- package/dist/src/ide/process-utils.js +108 -67
- package/dist/src/ide/process-utils.js.map +1 -1
- package/dist/src/ide/process-utils.test.d.ts +6 -0
- package/dist/src/ide/process-utils.test.js +151 -0
- package/dist/src/ide/process-utils.test.js.map +1 -0
- package/dist/src/ide/types.d.ts +486 -0
- package/dist/src/ide/types.js +138 -0
- package/dist/src/ide/types.js.map +1 -0
- package/dist/src/index.d.ts +41 -2
- package/dist/src/index.js +44 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/google-auth-provider.d.ts +5 -3
- package/dist/src/mcp/google-auth-provider.js +21 -3
- package/dist/src/mcp/google-auth-provider.js.map +1 -1
- package/dist/src/mcp/google-auth-provider.test.js +42 -9
- package/dist/src/mcp/google-auth-provider.test.js.map +1 -1
- package/dist/src/mcp/oauth-provider.d.ts +25 -18
- package/dist/src/mcp/oauth-provider.js +194 -97
- package/dist/src/mcp/oauth-provider.js.map +1 -1
- package/dist/src/mcp/oauth-provider.test.js +581 -39
- package/dist/src/mcp/oauth-provider.test.js.map +1 -1
- package/dist/src/mcp/oauth-token-storage.d.ts +14 -32
- package/dist/src/mcp/oauth-token-storage.js +58 -28
- package/dist/src/mcp/oauth-token-storage.js.map +1 -1
- package/dist/src/mcp/oauth-token-storage.test.js +262 -162
- package/dist/src/mcp/oauth-token-storage.test.js.map +1 -1
- package/dist/src/mcp/oauth-utils.d.ts +16 -1
- package/dist/src/mcp/oauth-utils.js +68 -33
- package/dist/src/mcp/oauth-utils.js.map +1 -1
- package/dist/src/mcp/oauth-utils.test.js +86 -3
- package/dist/src/mcp/oauth-utils.test.js.map +1 -1
- package/dist/src/mcp/sa-impersonation-provider.d.ts +27 -0
- package/dist/src/mcp/sa-impersonation-provider.js +113 -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/base-token-storage.d.ts +19 -0
- package/dist/src/mcp/token-storage/base-token-storage.js +36 -0
- package/dist/src/mcp/token-storage/base-token-storage.js.map +1 -0
- package/dist/src/mcp/token-storage/base-token-storage.test.d.ts +6 -0
- package/dist/src/mcp/token-storage/base-token-storage.test.js +151 -0
- package/dist/src/mcp/token-storage/base-token-storage.test.js.map +1 -0
- package/dist/src/mcp/token-storage/file-token-storage.d.ts +24 -0
- package/dist/src/mcp/token-storage/file-token-storage.js +145 -0
- package/dist/src/mcp/token-storage/file-token-storage.js.map +1 -0
- package/dist/src/mcp/token-storage/file-token-storage.test.d.ts +6 -0
- package/dist/src/mcp/token-storage/file-token-storage.test.js +238 -0
- package/dist/src/mcp/token-storage/file-token-storage.test.js.map +1 -0
- package/dist/src/mcp/token-storage/hybrid-token-storage.d.ts +23 -0
- package/dist/src/mcp/token-storage/hybrid-token-storage.js +78 -0
- package/dist/src/mcp/token-storage/hybrid-token-storage.js.map +1 -0
- package/dist/src/mcp/token-storage/hybrid-token-storage.test.d.ts +6 -0
- package/dist/src/mcp/token-storage/hybrid-token-storage.test.js +193 -0
- package/dist/src/mcp/token-storage/hybrid-token-storage.test.js.map +1 -0
- package/dist/src/mcp/token-storage/index.d.ts +11 -0
- package/dist/src/mcp/token-storage/index.js +12 -0
- package/dist/src/mcp/token-storage/index.js.map +1 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.d.ts +35 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.js +246 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.js.map +1 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.test.d.ts +6 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.test.js +305 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.test.js.map +1 -0
- package/dist/src/mcp/token-storage/types.d.ts +44 -0
- package/dist/src/mcp/token-storage/types.js +11 -0
- package/dist/src/mcp/token-storage/types.js.map +1 -0
- package/dist/src/output/json-formatter.d.ts +11 -0
- package/dist/src/output/json-formatter.js +30 -0
- package/dist/src/output/json-formatter.js.map +1 -0
- package/dist/src/output/json-formatter.test.d.ts +6 -0
- package/dist/src/output/json-formatter.test.js +266 -0
- package/dist/src/output/json-formatter.test.js.map +1 -0
- package/dist/src/output/stream-json-formatter.d.ts +32 -0
- package/dist/src/output/stream-json-formatter.js +52 -0
- package/dist/src/output/stream-json-formatter.js.map +1 -0
- package/dist/src/output/stream-json-formatter.test.d.ts +6 -0
- package/dist/src/output/stream-json-formatter.test.js +479 -0
- package/dist/src/output/stream-json-formatter.test.js.map +1 -0
- package/dist/src/output/types.d.ts +82 -0
- package/dist/src/output/types.js +22 -0
- package/dist/src/output/types.js.map +1 -0
- package/dist/src/policy/config.d.ts +31 -0
- package/dist/src/policy/config.js +199 -0
- package/dist/src/policy/config.js.map +1 -0
- package/dist/src/policy/config.test.d.ts +6 -0
- package/dist/src/policy/config.test.js +538 -0
- package/dist/src/policy/config.test.js.map +1 -0
- package/dist/src/policy/index.d.ts +9 -0
- package/dist/src/policy/index.js +10 -0
- package/dist/src/policy/index.js.map +1 -0
- package/dist/src/policy/policies/discovered.toml +8 -0
- package/dist/src/policy/policies/read-only.toml +56 -0
- package/dist/src/policy/policies/write.toml +73 -0
- package/dist/src/policy/policies/yolo.toml +31 -0
- package/dist/src/policy/policy-engine.d.ts +39 -0
- package/dist/src/policy/policy-engine.js +158 -0
- package/dist/src/policy/policy-engine.js.map +1 -0
- package/dist/src/policy/policy-engine.test.d.ts +6 -0
- package/dist/src/policy/policy-engine.test.js +899 -0
- package/dist/src/policy/policy-engine.test.js.map +1 -0
- package/dist/src/policy/stable-stringify.d.ts +58 -0
- package/dist/src/policy/stable-stringify.js +122 -0
- package/dist/src/policy/stable-stringify.js.map +1 -0
- package/dist/src/policy/toml-loader.d.ts +47 -0
- package/dist/src/policy/toml-loader.js +411 -0
- package/dist/src/policy/toml-loader.js.map +1 -0
- package/dist/src/policy/toml-loader.test.d.ts +6 -0
- package/dist/src/policy/toml-loader.test.js +376 -0
- package/dist/src/policy/toml-loader.test.js.map +1 -0
- package/dist/src/policy/types.d.ts +130 -0
- package/dist/src/policy/types.js +22 -0
- package/dist/src/policy/types.js.map +1 -0
- package/dist/src/prompts/mcp-prompts.d.ts +2 -2
- package/dist/src/prompts/mcp-prompts.test.d.ts +6 -0
- package/dist/src/prompts/mcp-prompts.test.js +39 -0
- package/dist/src/prompts/mcp-prompts.test.js.map +1 -0
- package/dist/src/prompts/prompt-registry.d.ts +1 -1
- package/dist/src/prompts/prompt-registry.js +2 -1
- package/dist/src/prompts/prompt-registry.js.map +1 -1
- package/dist/src/prompts/prompt-registry.test.d.ts +6 -0
- package/dist/src/prompts/prompt-registry.test.js +96 -0
- package/dist/src/prompts/prompt-registry.test.js.map +1 -0
- package/dist/src/routing/modelRouterService.d.ts +23 -0
- package/dist/src/routing/modelRouterService.js +85 -0
- package/dist/src/routing/modelRouterService.js.map +1 -0
- package/dist/src/routing/modelRouterService.test.d.ts +6 -0
- package/dist/src/routing/modelRouterService.test.js +160 -0
- package/dist/src/routing/modelRouterService.test.js.map +1 -0
- package/dist/src/routing/routingStrategy.d.ts +62 -0
- package/dist/src/routing/routingStrategy.js +7 -0
- package/dist/src/routing/routingStrategy.js.map +1 -0
- package/dist/src/routing/strategies/classifierStrategy.d.ts +12 -0
- package/dist/src/routing/strategies/classifierStrategy.js +166 -0
- package/dist/src/routing/strategies/classifierStrategy.js.map +1 -0
- package/dist/src/routing/strategies/classifierStrategy.test.d.ts +6 -0
- package/dist/src/routing/strategies/classifierStrategy.test.js +196 -0
- package/dist/src/routing/strategies/classifierStrategy.test.js.map +1 -0
- package/dist/src/routing/strategies/compositeStrategy.d.ts +26 -0
- package/dist/src/routing/strategies/compositeStrategy.js +68 -0
- package/dist/src/routing/strategies/compositeStrategy.js.map +1 -0
- package/dist/src/routing/strategies/compositeStrategy.test.d.ts +6 -0
- package/dist/src/routing/strategies/compositeStrategy.test.js +123 -0
- package/dist/src/routing/strategies/compositeStrategy.test.js.map +1 -0
- package/dist/src/routing/strategies/defaultStrategy.d.ts +12 -0
- package/dist/src/routing/strategies/defaultStrategy.js +20 -0
- package/dist/src/routing/strategies/defaultStrategy.js.map +1 -0
- package/dist/src/routing/strategies/defaultStrategy.test.d.ts +6 -0
- package/dist/src/routing/strategies/defaultStrategy.test.js +26 -0
- package/dist/src/routing/strategies/defaultStrategy.test.js.map +1 -0
- package/dist/src/routing/strategies/fallbackStrategy.d.ts +12 -0
- package/dist/src/routing/strategies/fallbackStrategy.js +25 -0
- package/dist/src/routing/strategies/fallbackStrategy.js.map +1 -0
- package/dist/src/routing/strategies/fallbackStrategy.test.d.ts +6 -0
- package/dist/src/routing/strategies/fallbackStrategy.test.js +59 -0
- package/dist/src/routing/strategies/fallbackStrategy.test.js.map +1 -0
- package/dist/src/routing/strategies/overrideStrategy.d.ts +15 -0
- package/dist/src/routing/strategies/overrideStrategy.js +28 -0
- package/dist/src/routing/strategies/overrideStrategy.js.map +1 -0
- package/dist/src/routing/strategies/overrideStrategy.test.d.ts +6 -0
- package/dist/src/routing/strategies/overrideStrategy.test.js +45 -0
- package/dist/src/routing/strategies/overrideStrategy.test.js.map +1 -0
- package/dist/src/safety/built-in.d.ts +21 -0
- package/dist/src/safety/built-in.js +106 -0
- package/dist/src/safety/built-in.js.map +1 -0
- package/dist/src/safety/built-in.test.d.ts +6 -0
- package/dist/src/safety/built-in.test.js +199 -0
- package/dist/src/safety/built-in.test.js.map +1 -0
- package/dist/src/safety/checker-runner.d.ts +48 -0
- package/dist/src/safety/checker-runner.js +208 -0
- package/dist/src/safety/checker-runner.js.map +1 -0
- package/dist/src/safety/checker-runner.test.d.ts +6 -0
- package/dist/src/safety/checker-runner.test.js +238 -0
- package/dist/src/safety/checker-runner.test.js.map +1 -0
- package/dist/src/safety/context-builder.d.ts +23 -0
- package/dist/src/safety/context-builder.js +47 -0
- package/dist/src/safety/context-builder.js.map +1 -0
- package/dist/src/safety/context-builder.test.d.ts +6 -0
- package/dist/src/safety/context-builder.test.js +49 -0
- package/dist/src/safety/context-builder.test.js.map +1 -0
- package/dist/src/safety/protocol.d.ts +88 -0
- package/dist/src/safety/protocol.js +15 -0
- package/dist/src/safety/protocol.js.map +1 -0
- package/dist/src/safety/registry.d.ts +26 -0
- package/dist/src/safety/registry.js +65 -0
- package/dist/src/safety/registry.js.map +1 -0
- package/dist/src/safety/registry.test.d.ts +6 -0
- package/dist/src/safety/registry.test.js +31 -0
- package/dist/src/safety/registry.test.js.map +1 -0
- package/dist/src/services/chatCompressionService.d.ts +32 -0
- package/dist/src/services/chatCompressionService.js +162 -0
- package/dist/src/services/chatCompressionService.js.map +1 -0
- package/dist/src/services/chatCompressionService.test.d.ts +6 -0
- package/dist/src/services/chatCompressionService.test.js +210 -0
- package/dist/src/services/chatCompressionService.test.js.map +1 -0
- package/dist/src/services/chatRecordingService.d.ts +10 -15
- package/dist/src/services/chatRecordingService.js +43 -29
- package/dist/src/services/chatRecordingService.js.map +1 -1
- package/dist/src/services/chatRecordingService.test.js +69 -25
- package/dist/src/services/chatRecordingService.test.js.map +1 -1
- package/dist/src/services/fileDiscoveryService.d.ts +8 -10
- package/dist/src/services/fileDiscoveryService.js +31 -53
- package/dist/src/services/fileDiscoveryService.js.map +1 -1
- package/dist/src/services/fileDiscoveryService.test.js +94 -14
- package/dist/src/services/fileDiscoveryService.test.js.map +1 -1
- package/dist/src/services/fileSystemService.d.ts +9 -0
- package/dist/src/services/fileSystemService.js +12 -1
- package/dist/src/services/fileSystemService.js.map +1 -1
- package/dist/src/services/fileSystemService.test.js +1 -1
- package/dist/src/services/fileSystemService.test.js.map +1 -1
- package/dist/src/services/gitService.d.ts +3 -1
- package/dist/src/services/gitService.js +30 -24
- package/dist/src/services/gitService.js.map +1 -1
- package/dist/src/services/gitService.test.js +30 -37
- package/dist/src/services/gitService.test.js.map +1 -1
- package/dist/src/services/loopDetectionService.d.ts +12 -3
- package/dist/src/services/loopDetectionService.js +148 -55
- package/dist/src/services/loopDetectionService.js.map +1 -1
- package/dist/src/services/loopDetectionService.test.js +280 -21
- package/dist/src/services/loopDetectionService.test.js.map +1 -1
- package/dist/src/services/modelConfig.golden.test.d.ts +6 -0
- package/dist/src/services/modelConfig.golden.test.js +42 -0
- package/dist/src/services/modelConfig.golden.test.js.map +1 -0
- package/dist/src/services/modelConfig.integration.test.d.ts +6 -0
- package/dist/src/services/modelConfig.integration.test.js +247 -0
- package/dist/src/services/modelConfig.integration.test.js.map +1 -0
- package/dist/src/services/modelConfigService.d.ts +48 -0
- package/dist/src/services/modelConfigService.js +151 -0
- package/dist/src/services/modelConfigService.js.map +1 -0
- package/dist/src/services/modelConfigService.test.d.ts +6 -0
- package/dist/src/services/modelConfigService.test.js +531 -0
- package/dist/src/services/modelConfigService.test.js.map +1 -0
- package/dist/src/services/shellExecutionService.d.ts +37 -2
- package/dist/src/services/shellExecutionService.js +361 -67
- package/dist/src/services/shellExecutionService.js.map +1 -1
- package/dist/src/services/shellExecutionService.test.js +333 -71
- package/dist/src/services/shellExecutionService.test.js.map +1 -1
- package/dist/src/services/test-data/resolved-aliases.golden.json +202 -0
- 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-monitor.d.ts +116 -0
- package/dist/src/telemetry/activity-monitor.js +209 -0
- package/dist/src/telemetry/activity-monitor.js.map +1 -0
- package/dist/src/telemetry/activity-monitor.test.d.ts +6 -0
- package/dist/src/telemetry/activity-monitor.test.js +251 -0
- package/dist/src/telemetry/activity-monitor.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 +53 -5
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +581 -56
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.d.ts +2 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +467 -31
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +75 -4
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +182 -6
- 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 +76 -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 -18
- package/dist/src/telemetry/constants.js +0 -18
- package/dist/src/telemetry/constants.js.map +1 -1
- package/dist/src/telemetry/file-exporters.d.ts +5 -4
- package/dist/src/telemetry/file-exporters.js +1 -1
- package/dist/src/telemetry/file-exporters.js.map +1 -1
- package/dist/src/telemetry/gcp-exporters.d.ts +34 -0
- package/dist/src/telemetry/gcp-exporters.js +116 -0
- package/dist/src/telemetry/gcp-exporters.js.map +1 -0
- package/dist/src/telemetry/gcp-exporters.test.d.ts +6 -0
- package/dist/src/telemetry/gcp-exporters.test.js +318 -0
- package/dist/src/telemetry/gcp-exporters.test.js.map +1 -0
- package/dist/src/telemetry/high-water-mark-tracker.d.ts +43 -0
- package/dist/src/telemetry/high-water-mark-tracker.js +88 -0
- package/dist/src/telemetry/high-water-mark-tracker.js.map +1 -0
- package/dist/src/telemetry/high-water-mark-tracker.test.d.ts +6 -0
- package/dist/src/telemetry/high-water-mark-tracker.test.js +152 -0
- package/dist/src/telemetry/high-water-mark-tracker.test.js.map +1 -0
- package/dist/src/telemetry/index.d.ts +16 -2
- package/dist/src/telemetry/index.js +25 -2
- package/dist/src/telemetry/index.js.map +1 -1
- package/dist/src/telemetry/loggers.d.ts +25 -3
- package/dist/src/telemetry/loggers.js +333 -154
- package/dist/src/telemetry/loggers.js.map +1 -1
- package/dist/src/telemetry/loggers.test.circular.js +3 -4
- package/dist/src/telemetry/loggers.test.circular.js.map +1 -1
- package/dist/src/telemetry/loggers.test.js +868 -63
- 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 +498 -11
- package/dist/src/telemetry/metrics.js +729 -84
- package/dist/src/telemetry/metrics.js.map +1 -1
- package/dist/src/telemetry/metrics.test.js +964 -101
- package/dist/src/telemetry/metrics.test.js.map +1 -1
- package/dist/src/telemetry/rate-limiter.d.ts +48 -0
- package/dist/src/telemetry/rate-limiter.js +100 -0
- package/dist/src/telemetry/rate-limiter.js.map +1 -0
- package/dist/src/telemetry/rate-limiter.test.d.ts +6 -0
- package/dist/src/telemetry/rate-limiter.test.js +207 -0
- package/dist/src/telemetry/rate-limiter.test.js.map +1 -0
- package/dist/src/telemetry/sdk.d.ts +1 -1
- package/dist/src/telemetry/sdk.js +23 -4
- package/dist/src/telemetry/sdk.js.map +1 -1
- package/dist/src/telemetry/sdk.test.js +108 -0
- package/dist/src/telemetry/sdk.test.js.map +1 -1
- package/dist/src/telemetry/semantic.d.ts +82 -0
- package/dist/src/telemetry/semantic.js +269 -0
- package/dist/src/telemetry/semantic.js.map +1 -0
- package/dist/src/telemetry/semantic.test.d.ts +6 -0
- package/dist/src/telemetry/semantic.test.js +387 -0
- package/dist/src/telemetry/semantic.test.js.map +1 -0
- package/dist/src/telemetry/telemetry-utils.d.ts +6 -0
- package/dist/src/telemetry/telemetry-utils.js +14 -0
- package/dist/src/telemetry/telemetry-utils.js.map +1 -0
- package/dist/src/telemetry/telemetry-utils.test.d.ts +6 -0
- package/dist/src/telemetry/telemetry-utils.test.js +41 -0
- package/dist/src/telemetry/telemetry-utils.test.js.map +1 -0
- package/dist/src/telemetry/telemetryAttributes.d.ts +8 -0
- package/dist/src/telemetry/telemetryAttributes.js +19 -0
- package/dist/src/telemetry/telemetryAttributes.js.map +1 -0
- package/dist/src/telemetry/trace.d.ts +46 -0
- package/dist/src/telemetry/trace.js +121 -0
- package/dist/src/telemetry/trace.js.map +1 -0
- package/dist/src/telemetry/types.d.ts +351 -25
- package/dist/src/telemetry/types.js +1071 -63
- package/dist/src/telemetry/types.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.d.ts +4 -4
- package/dist/src/telemetry/uiTelemetry.js +14 -15
- package/dist/src/telemetry/uiTelemetry.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.test.js +122 -96
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
- package/dist/src/test-utils/config.d.ts +3 -2
- package/dist/src/test-utils/config.js +1 -1
- package/dist/src/test-utils/config.js.map +1 -1
- package/dist/src/test-utils/index.d.ts +6 -0
- package/dist/src/test-utils/index.js +7 -0
- package/dist/src/test-utils/index.js.map +1 -0
- package/dist/src/test-utils/mock-tool.d.ts +66 -0
- package/dist/src/test-utils/{tools.js → mock-tool.js} +45 -29
- package/dist/src/test-utils/mock-tool.js.map +1 -0
- package/dist/src/test-utils/mockWorkspaceContext.d.ts +1 -1
- package/dist/src/tools/base-tool-invocation.test.d.ts +6 -0
- package/dist/src/tools/base-tool-invocation.test.js +85 -0
- package/dist/src/tools/base-tool-invocation.test.js.map +1 -0
- package/dist/src/tools/diffOptions.d.ts +1 -1
- package/dist/src/tools/diffOptions.js +21 -13
- package/dist/src/tools/diffOptions.js.map +1 -1
- package/dist/src/tools/diffOptions.test.js +58 -22
- package/dist/src/tools/diffOptions.test.js.map +1 -1
- package/dist/src/tools/edit.d.ts +10 -8
- package/dist/src/tools/edit.js +100 -79
- package/dist/src/tools/edit.js.map +1 -1
- package/dist/src/tools/edit.test.js +429 -163
- package/dist/src/tools/edit.test.js.map +1 -1
- package/dist/src/tools/glob.d.ts +11 -5
- package/dist/src/tools/glob.js +58 -42
- package/dist/src/tools/glob.js.map +1 -1
- package/dist/src/tools/glob.test.js +249 -166
- package/dist/src/tools/glob.test.js.map +1 -1
- package/dist/src/tools/grep.d.ts +7 -5
- package/dist/src/tools/grep.js +66 -40
- package/dist/src/tools/grep.js.map +1 -1
- package/dist/src/tools/grep.test.js +41 -15
- package/dist/src/tools/grep.test.js.map +1 -1
- package/dist/src/tools/ls.d.ts +7 -5
- package/dist/src/tools/ls.js +54 -68
- package/dist/src/tools/ls.js.map +1 -1
- package/dist/src/tools/ls.test.js +150 -293
- package/dist/src/tools/ls.test.js.map +1 -1
- package/dist/src/tools/mcp-client-manager.d.ts +52 -12
- package/dist/src/tools/mcp-client-manager.js +196 -27
- package/dist/src/tools/mcp-client-manager.js.map +1 -1
- package/dist/src/tools/mcp-client-manager.test.js +139 -13
- package/dist/src/tools/mcp-client-manager.test.js.map +1 -1
- package/dist/src/tools/mcp-client.d.ts +28 -24
- package/dist/src/tools/mcp-client.js +338 -351
- package/dist/src/tools/mcp-client.js.map +1 -1
- package/dist/src/tools/mcp-client.test.js +380 -193
- package/dist/src/tools/mcp-client.test.js.map +1 -1
- package/dist/src/tools/mcp-tool.d.ts +11 -5
- package/dist/src/tools/mcp-tool.js +66 -17
- package/dist/src/tools/mcp-tool.js.map +1 -1
- package/dist/src/tools/mcp-tool.test.js +278 -211
- package/dist/src/tools/mcp-tool.test.js.map +1 -1
- package/dist/src/tools/memoryTool.d.ts +10 -7
- package/dist/src/tools/memoryTool.js +28 -49
- package/dist/src/tools/memoryTool.js.map +1 -1
- package/dist/src/tools/memoryTool.test.js +26 -13
- 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 +196 -0
- package/dist/src/tools/message-bus-integration.test.js.map +1 -0
- package/dist/src/tools/modifiable-tool.d.ts +7 -3
- package/dist/src/tools/modifiable-tool.js +41 -19
- package/dist/src/tools/modifiable-tool.js.map +1 -1
- package/dist/src/tools/modifiable-tool.test.js +70 -35
- package/dist/src/tools/modifiable-tool.test.js.map +1 -1
- package/dist/src/tools/read-file.d.ts +9 -7
- package/dist/src/tools/read-file.js +39 -60
- package/dist/src/tools/read-file.js.map +1 -1
- package/dist/src/tools/read-file.test.js +103 -36
- package/dist/src/tools/read-file.test.js.map +1 -1
- package/dist/src/tools/read-many-files.d.ts +9 -14
- package/dist/src/tools/read-many-files.js +71 -155
- package/dist/src/tools/read-many-files.js.map +1 -1
- package/dist/src/tools/read-many-files.test.js +98 -44
- package/dist/src/tools/read-many-files.test.js.map +1 -1
- package/dist/src/tools/ripGrep.d.ts +73 -0
- package/dist/src/tools/ripGrep.js +395 -0
- package/dist/src/tools/ripGrep.js.map +1 -0
- package/dist/src/tools/ripGrep.test.d.ts +6 -0
- package/dist/src/tools/ripGrep.test.js +1305 -0
- package/dist/src/tools/ripGrep.test.js.map +1 -0
- package/dist/src/tools/shell.d.ts +19 -6
- package/dist/src/tools/shell.js +92 -56
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/shell.test.js +176 -103
- package/dist/src/tools/shell.test.js.map +1 -1
- package/dist/src/tools/smart-edit.d.ts +78 -0
- package/dist/src/tools/smart-edit.js +717 -0
- package/dist/src/tools/smart-edit.js.map +1 -0
- package/dist/src/tools/smart-edit.test.d.ts +6 -0
- package/dist/src/tools/smart-edit.test.js +592 -0
- package/dist/src/tools/smart-edit.test.js.map +1 -0
- package/dist/src/tools/tool-error.d.ts +39 -1
- package/dist/src/tools/tool-error.js +54 -0
- package/dist/src/tools/tool-error.js.map +1 -1
- package/dist/src/tools/tool-names.d.ts +17 -0
- package/dist/src/tools/tool-names.js +21 -0
- package/dist/src/tools/tool-names.js.map +1 -0
- package/dist/src/tools/tool-registry.d.ts +38 -20
- package/dist/src/tools/tool-registry.js +134 -77
- package/dist/src/tools/tool-registry.js.map +1 -1
- package/dist/src/tools/tool-registry.test.js +218 -58
- package/dist/src/tools/tool-registry.test.js.map +1 -1
- package/dist/src/tools/tools.d.ts +49 -17
- package/dist/src/tools/tools.js +150 -8
- package/dist/src/tools/tools.js.map +1 -1
- package/dist/src/tools/tools.test.js +1 -2
- package/dist/src/tools/tools.test.js.map +1 -1
- package/dist/src/tools/web-fetch.d.ts +14 -5
- package/dist/src/tools/web-fetch.js +90 -44
- package/dist/src/tools/web-fetch.js.map +1 -1
- package/dist/src/tools/web-fetch.test.js +388 -20
- package/dist/src/tools/web-fetch.test.js.map +1 -1
- package/dist/src/tools/web-search.d.ts +8 -6
- package/dist/src/tools/web-search.js +40 -15
- package/dist/src/tools/web-search.js.map +1 -1
- package/dist/src/tools/web-search.test.js +75 -1
- package/dist/src/tools/web-search.test.js.map +1 -1
- package/dist/src/tools/write-file.d.ts +7 -5
- package/dist/src/tools/write-file.js +54 -54
- package/dist/src/tools/write-file.js.map +1 -1
- package/dist/src/tools/write-file.test.js +237 -146
- package/dist/src/tools/write-file.test.js.map +1 -1
- package/dist/src/tools/write-todos.d.ts +50 -0
- package/dist/src/tools/write-todos.js +193 -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 +2 -2
- package/dist/src/utils/bfsFileSearch.js +16 -9
- package/dist/src/utils/bfsFileSearch.js.map +1 -1
- package/dist/src/utils/bfsFileSearch.test.js +3 -3
- package/dist/src/utils/bfsFileSearch.test.js.map +1 -1
- package/dist/src/utils/channel.d.ts +19 -0
- package/dist/src/utils/channel.js +49 -0
- package/dist/src/utils/channel.js.map +1 -0
- package/dist/src/utils/channel.test.d.ts +6 -0
- package/dist/src/utils/channel.test.js +170 -0
- package/dist/src/utils/channel.test.js.map +1 -0
- package/dist/src/utils/debugLogger.d.ts +25 -0
- package/dist/src/utils/debugLogger.js +33 -0
- package/dist/src/utils/debugLogger.js.map +1 -0
- package/dist/src/utils/debugLogger.test.d.ts +6 -0
- package/dist/src/utils/debugLogger.test.js +69 -0
- package/dist/src/utils/debugLogger.test.js.map +1 -0
- package/dist/src/utils/delay.d.ts +16 -0
- package/dist/src/utils/delay.js +43 -0
- package/dist/src/utils/delay.js.map +1 -0
- package/dist/src/utils/delay.test.d.ts +6 -0
- package/dist/src/utils/delay.test.js +88 -0
- package/dist/src/utils/delay.test.js.map +1 -0
- package/dist/src/utils/editCorrector.d.ts +9 -8
- package/dist/src/utils/editCorrector.js +62 -34
- package/dist/src/utils/editCorrector.js.map +1 -1
- package/dist/src/utils/editCorrector.test.js +52 -87
- package/dist/src/utils/editCorrector.test.js.map +1 -1
- package/dist/src/utils/editor.d.ts +4 -2
- package/dist/src/utils/editor.js +56 -55
- package/dist/src/utils/editor.js.map +1 -1
- package/dist/src/utils/editor.test.js +47 -88
- package/dist/src/utils/editor.test.js.map +1 -1
- package/dist/src/utils/environmentContext.d.ts +3 -2
- package/dist/src/utils/environmentContext.js +20 -33
- package/dist/src/utils/environmentContext.js.map +1 -1
- package/dist/src/utils/environmentContext.test.js +6 -34
- package/dist/src/utils/environmentContext.test.js.map +1 -1
- package/dist/src/utils/errorParsing.d.ts +1 -1
- package/dist/src/utils/errorParsing.js +5 -33
- package/dist/src/utils/errorParsing.js.map +1 -1
- package/dist/src/utils/errorParsing.test.js +0 -88
- package/dist/src/utils/errorParsing.test.js.map +1 -1
- package/dist/src/utils/errorReporting.d.ts +1 -1
- package/dist/src/utils/errors.d.ts +28 -0
- package/dist/src/utils/errors.js +48 -0
- package/dist/src/utils/errors.js.map +1 -1
- package/dist/src/utils/events.d.ts +121 -0
- package/dist/src/utils/events.js +84 -0
- package/dist/src/utils/events.js.map +1 -0
- package/dist/src/utils/events.test.d.ts +6 -0
- package/dist/src/utils/events.test.js +212 -0
- package/dist/src/utils/events.test.js.map +1 -0
- package/dist/src/utils/extensionLoader.d.ts +86 -0
- package/dist/src/utils/extensionLoader.js +208 -0
- package/dist/src/utils/extensionLoader.js.map +1 -0
- package/dist/src/utils/extensionLoader.test.d.ts +6 -0
- package/dist/src/utils/extensionLoader.test.js +154 -0
- package/dist/src/utils/extensionLoader.test.js.map +1 -0
- package/dist/src/utils/fetch.d.ts +1 -0
- package/dist/src/utils/fetch.js +5 -1
- package/dist/src/utils/fetch.js.map +1 -1
- package/dist/src/utils/fileUtils.d.ts +28 -12
- package/dist/src/utils/fileUtils.js +204 -81
- package/dist/src/utils/fileUtils.js.map +1 -1
- package/dist/src/utils/fileUtils.test.js +426 -82
- package/dist/src/utils/fileUtils.test.js.map +1 -1
- package/dist/src/utils/filesearch/crawler.d.ts +1 -1
- package/dist/src/utils/filesearch/crawler.test.js +2 -2
- package/dist/src/utils/filesearch/crawler.test.js.map +1 -1
- package/dist/src/utils/filesearch/fileSearch.d.ts +1 -0
- package/dist/src/utils/filesearch/fileSearch.js +14 -9
- package/dist/src/utils/filesearch/fileSearch.js.map +1 -1
- package/dist/src/utils/filesearch/fileSearch.test.js +90 -0
- package/dist/src/utils/filesearch/fileSearch.test.js.map +1 -1
- package/dist/src/utils/flashFallback.test.d.ts +6 -0
- package/dist/src/utils/flashFallback.test.js +103 -0
- package/dist/src/utils/flashFallback.test.js.map +1 -0
- 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/geminiIgnoreParser.d.ts +18 -0
- package/dist/src/utils/geminiIgnoreParser.js +61 -0
- package/dist/src/utils/geminiIgnoreParser.js.map +1 -0
- package/dist/src/utils/geminiIgnoreParser.test.d.ts +6 -0
- package/dist/src/utils/geminiIgnoreParser.test.js +50 -0
- package/dist/src/utils/geminiIgnoreParser.test.js.map +1 -0
- package/dist/src/utils/generateContentResponseUtilities.d.ts +1 -2
- package/dist/src/utils/generateContentResponseUtilities.js +1 -13
- package/dist/src/utils/generateContentResponseUtilities.js.map +1 -1
- package/dist/src/utils/generateContentResponseUtilities.test.js +2 -40
- package/dist/src/utils/generateContentResponseUtilities.test.js.map +1 -1
- package/dist/src/utils/getFolderStructure.d.ts +2 -2
- package/dist/src/utils/getFolderStructure.js +12 -20
- package/dist/src/utils/getFolderStructure.js.map +1 -1
- package/dist/src/utils/getFolderStructure.test.js +11 -10
- package/dist/src/utils/getFolderStructure.test.js.map +1 -1
- package/dist/src/utils/gitIgnoreParser.d.ts +7 -8
- package/dist/src/utils/gitIgnoreParser.js +145 -36
- package/dist/src/utils/gitIgnoreParser.js.map +1 -1
- package/dist/src/utils/gitIgnoreParser.test.js +127 -38
- package/dist/src/utils/gitIgnoreParser.test.js.map +1 -1
- package/dist/src/utils/gitUtils.js +2 -2
- package/dist/src/utils/gitUtils.js.map +1 -1
- package/dist/src/utils/googleErrors.d.ts +104 -0
- package/dist/src/utils/googleErrors.js +152 -0
- package/dist/src/utils/googleErrors.js.map +1 -0
- package/dist/src/utils/googleErrors.test.d.ts +6 -0
- package/dist/src/utils/googleErrors.test.js +301 -0
- package/dist/src/utils/googleErrors.test.js.map +1 -0
- package/dist/src/utils/googleQuotaErrors.d.ts +37 -0
- package/dist/src/utils/googleQuotaErrors.js +157 -0
- package/dist/src/utils/googleQuotaErrors.js.map +1 -0
- package/dist/src/utils/googleQuotaErrors.test.d.ts +6 -0
- package/dist/src/utils/googleQuotaErrors.test.js +311 -0
- package/dist/src/utils/googleQuotaErrors.test.js.map +1 -0
- package/dist/src/utils/httpErrors.d.ts +18 -0
- package/dist/src/utils/httpErrors.js +36 -0
- package/dist/src/utils/httpErrors.js.map +1 -0
- package/dist/src/utils/ignorePatterns.d.ts +103 -0
- package/dist/src/utils/ignorePatterns.js +220 -0
- package/dist/src/utils/ignorePatterns.js.map +1 -0
- package/dist/src/utils/ignorePatterns.test.d.ts +6 -0
- package/dist/src/utils/ignorePatterns.test.js +246 -0
- package/dist/src/utils/ignorePatterns.test.js.map +1 -0
- package/dist/src/utils/installationManager.d.ts +16 -0
- package/dist/src/utils/installationManager.js +51 -0
- package/dist/src/utils/installationManager.js.map +1 -0
- package/dist/src/utils/installationManager.test.d.ts +6 -0
- package/dist/src/utils/installationManager.test.js +85 -0
- package/dist/src/utils/installationManager.test.js.map +1 -0
- package/dist/src/utils/language-detection.d.ts +6 -0
- package/dist/src/utils/language-detection.js +101 -0
- package/dist/src/utils/language-detection.js.map +1 -0
- package/dist/src/utils/llm-edit-fixer.d.ts +26 -0
- package/dist/src/utils/llm-edit-fixer.js +155 -0
- package/dist/src/utils/llm-edit-fixer.js.map +1 -0
- package/dist/src/utils/llm-edit-fixer.test.d.ts +6 -0
- package/dist/src/utils/llm-edit-fixer.test.js +223 -0
- package/dist/src/utils/llm-edit-fixer.test.js.map +1 -0
- package/dist/src/utils/memoryDiscovery.d.ts +26 -6
- package/dist/src/utils/memoryDiscovery.js +239 -40
- package/dist/src/utils/memoryDiscovery.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.test.js +365 -44
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.js +19 -25
- package/dist/src/utils/memoryImportProcessor.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.test.js +24 -155
- package/dist/src/utils/memoryImportProcessor.test.js.map +1 -1
- package/dist/src/utils/messageInspectors.d.ts +1 -1
- package/dist/src/utils/nextSpeakerChecker.d.ts +3 -3
- package/dist/src/utils/nextSpeakerChecker.js +10 -4
- package/dist/src/utils/nextSpeakerChecker.js.map +1 -1
- package/dist/src/utils/nextSpeakerChecker.test.js +85 -66
- package/dist/src/utils/nextSpeakerChecker.test.js.map +1 -1
- package/dist/src/utils/package.d.ts +12 -0
- package/dist/src/utils/package.js +15 -0
- package/dist/src/utils/package.js.map +1 -0
- package/dist/src/utils/partUtils.d.ts +22 -1
- package/dist/src/utils/partUtils.js +68 -0
- package/dist/src/utils/partUtils.js.map +1 -1
- package/dist/src/utils/partUtils.test.js +112 -1
- package/dist/src/utils/partUtils.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/pathReader.d.ts +17 -0
- package/dist/src/utils/pathReader.js +92 -0
- package/dist/src/utils/pathReader.js.map +1 -0
- package/dist/src/utils/pathReader.test.d.ts +6 -0
- package/dist/src/utils/pathReader.test.js +406 -0
- package/dist/src/utils/pathReader.test.js.map +1 -0
- package/dist/src/utils/paths.d.ts +1 -18
- package/dist/src/utils/paths.js +133 -57
- package/dist/src/utils/paths.js.map +1 -1
- package/dist/src/utils/paths.test.js +200 -68
- package/dist/src/utils/paths.test.js.map +1 -1
- package/dist/src/utils/promptIdContext.d.ts +7 -0
- package/dist/src/utils/promptIdContext.js +8 -0
- package/dist/src/utils/promptIdContext.js.map +1 -0
- package/dist/src/utils/quotaErrorDetection.d.ts +1 -3
- package/dist/src/utils/quotaErrorDetection.js +0 -46
- package/dist/src/utils/quotaErrorDetection.js.map +1 -1
- package/dist/src/utils/retry.d.ts +5 -10
- package/dist/src/utils/retry.js +114 -197
- package/dist/src/utils/retry.js.map +1 -1
- package/dist/src/utils/retry.test.js +196 -130
- package/dist/src/utils/retry.test.js.map +1 -1
- package/dist/src/utils/safeJsonStringify.d.ts +4 -4
- package/dist/src/utils/safeJsonStringify.js +31 -7
- package/dist/src/utils/safeJsonStringify.js.map +1 -1
- package/dist/src/utils/schemaValidator.js +15 -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/session.js +1 -1
- package/dist/src/utils/session.js.map +1 -1
- package/dist/src/utils/shell-utils.d.ts +21 -3
- package/dist/src/utils/shell-utils.js +427 -159
- package/dist/src/utils/shell-utils.js.map +1 -1
- package/dist/src/utils/shell-utils.test.js +250 -59
- package/dist/src/utils/shell-utils.test.js.map +1 -1
- package/dist/src/utils/stdio.d.ts +32 -0
- package/dist/src/utils/stdio.js +85 -0
- package/dist/src/utils/stdio.js.map +1 -0
- package/dist/src/utils/stdio.test.d.ts +6 -0
- package/dist/src/utils/stdio.test.js +47 -0
- package/dist/src/utils/stdio.test.js.map +1 -0
- package/dist/src/utils/summarizer.d.ts +6 -4
- package/dist/src/utils/summarizer.js +8 -9
- package/dist/src/utils/summarizer.js.map +1 -1
- package/dist/src/utils/summarizer.test.js +32 -12
- package/dist/src/utils/summarizer.test.js.map +1 -1
- package/dist/src/utils/systemEncoding.js +7 -6
- package/dist/src/utils/systemEncoding.js.map +1 -1
- package/dist/src/utils/systemEncoding.test.js +4 -3
- package/dist/src/utils/systemEncoding.test.js.map +1 -1
- package/dist/src/utils/terminal.d.ts +14 -0
- package/dist/src/utils/terminal.js +38 -0
- package/dist/src/utils/terminal.js.map +1 -0
- package/dist/src/utils/terminalSerializer.d.ts +25 -0
- package/dist/src/utils/terminalSerializer.js +432 -0
- package/dist/src/utils/terminalSerializer.js.map +1 -0
- package/dist/src/utils/terminalSerializer.test.d.ts +6 -0
- package/dist/src/utils/terminalSerializer.test.js +176 -0
- package/dist/src/utils/terminalSerializer.test.js.map +1 -0
- package/dist/src/utils/textUtils.d.ts +5 -0
- package/dist/src/utils/textUtils.js +14 -0
- package/dist/src/utils/textUtils.js.map +1 -1
- package/dist/src/utils/textUtils.test.d.ts +6 -0
- package/dist/src/utils/textUtils.test.js +59 -0
- package/dist/src/utils/textUtils.test.js.map +1 -0
- 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.d.ts +19 -0
- package/dist/src/utils/tool-utils.js +67 -0
- package/dist/src/utils/tool-utils.js.map +1 -0
- package/dist/src/utils/tool-utils.test.d.ts +6 -0
- package/dist/src/utils/tool-utils.test.js +69 -0
- package/dist/src/utils/tool-utils.test.js.map +1 -0
- package/dist/src/utils/userAccountManager.d.ts +20 -0
- package/dist/src/utils/userAccountManager.js +115 -0
- package/dist/src/utils/userAccountManager.js.map +1 -0
- package/dist/src/utils/userAccountManager.test.d.ts +6 -0
- package/dist/src/utils/{user_account.test.js → userAccountManager.test.js} +41 -36
- package/dist/src/utils/userAccountManager.test.js.map +1 -0
- package/dist/src/utils/workspaceContext.d.ts +4 -3
- package/dist/src/utils/workspaceContext.js +23 -17
- package/dist/src/utils/workspaceContext.js.map +1 -1
- package/dist/src/utils/workspaceContext.test.js +45 -19
- package/dist/src/utils/workspaceContext.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +24 -10
- package/dist/src/core/modelCheck.d.ts +0 -14
- package/dist/src/core/modelCheck.js +0 -62
- package/dist/src/core/modelCheck.js.map +0 -1
- package/dist/src/test-utils/tools.d.ts +0 -44
- package/dist/src/test-utils/tools.js.map +0 -1
- package/dist/src/utils/flashFallback.integration.test.js +0 -118
- package/dist/src/utils/flashFallback.integration.test.js.map +0 -1
- package/dist/src/utils/user_account.d.ts +0 -9
- package/dist/src/utils/user_account.js +0 -109
- package/dist/src/utils/user_account.js.map +0 -1
- package/dist/src/utils/user_account.test.js.map +0 -1
- package/dist/src/utils/user_id.d.ts +0 -11
- package/dist/src/utils/user_id.js +0 -49
- package/dist/src/utils/user_id.js.map +0 -1
- package/dist/src/utils/user_id.test.js +0 -21
- package/dist/src/utils/user_id.test.js.map +0 -1
- /package/dist/src/{utils/flashFallback.integration.test.d.ts → agents/codebase-investigator.test.d.ts} +0 -0
- /package/dist/src/{utils/user_account.test.d.ts → agents/executor.test.d.ts} +0 -0
- /package/dist/src/{utils/user_id.test.d.ts → agents/invocation.test.d.ts} +0 -0
|
@@ -3,14 +3,31 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { createUserContent, } from '@google/genai';
|
|
6
|
+
import { ThinkingLevel } from '@google/genai';
|
|
7
|
+
import { toParts } from '../code_assist/converter.js';
|
|
8
|
+
import { createUserContent, FinishReason } from '@google/genai';
|
|
9
9
|
import { retryWithBackoff } from '../utils/retry.js';
|
|
10
|
-
import {
|
|
11
|
-
import { AuthType, createContentGenerator } from './contentGenerator.js';
|
|
12
|
-
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
|
|
10
|
+
import { DEFAULT_GEMINI_MODEL, DEFAULT_THINKING_MODE, PREVIEW_GEMINI_MODEL, getEffectiveModel, isGemini2Model, } from '../config/models.js';
|
|
13
11
|
import { hasCycleInSchema } from '../tools/tools.js';
|
|
12
|
+
import { logContentRetry, logContentRetryFailure, } from '../telemetry/loggers.js';
|
|
13
|
+
import { ChatRecordingService, } from '../services/chatRecordingService.js';
|
|
14
|
+
import { ContentRetryEvent, ContentRetryFailureEvent, } from '../telemetry/types.js';
|
|
15
|
+
import { handleFallback } from '../fallback/handler.js';
|
|
16
|
+
import { isFunctionResponse } from '../utils/messageInspectors.js';
|
|
17
|
+
import { partListUnionToString } from './geminiRequest.js';
|
|
18
|
+
export var StreamEventType;
|
|
19
|
+
(function (StreamEventType) {
|
|
20
|
+
/** A regular content chunk from the API. */
|
|
21
|
+
StreamEventType["CHUNK"] = "chunk";
|
|
22
|
+
/** A signal that a retry is about to happen. The UI should discard any partial
|
|
23
|
+
* content from the attempt that just failed. */
|
|
24
|
+
StreamEventType["RETRY"] = "retry";
|
|
25
|
+
})(StreamEventType || (StreamEventType = {}));
|
|
26
|
+
const INVALID_CONTENT_RETRY_OPTIONS = {
|
|
27
|
+
maxAttempts: 2, // 1 initial call + 1 retry
|
|
28
|
+
initialDelayMs: 500,
|
|
29
|
+
};
|
|
30
|
+
export const SYNTHETIC_THOUGHT_SIGNATURE = 'skip_thought_signature_validator';
|
|
14
31
|
/**
|
|
15
32
|
* Returns true if the response is valid, false otherwise.
|
|
16
33
|
*/
|
|
@@ -24,6 +41,16 @@ function isValidResponse(response) {
|
|
|
24
41
|
}
|
|
25
42
|
return isValidContent(content);
|
|
26
43
|
}
|
|
44
|
+
export function isValidNonThoughtTextPart(part) {
|
|
45
|
+
return (typeof part.text === 'string' &&
|
|
46
|
+
!part.thought &&
|
|
47
|
+
// Technically, the model should never generate parts that have text and
|
|
48
|
+
// any of these but we don't trust them so check anyways.
|
|
49
|
+
!part.functionCall &&
|
|
50
|
+
!part.functionResponse &&
|
|
51
|
+
!part.inlineData &&
|
|
52
|
+
!part.fileData);
|
|
53
|
+
}
|
|
27
54
|
function isValidContent(content) {
|
|
28
55
|
if (content.parts === undefined || content.parts.length === 0) {
|
|
29
56
|
return false;
|
|
@@ -84,14 +111,22 @@ function extractCuratedHistory(comprehensiveHistory) {
|
|
|
84
111
|
if (isValid) {
|
|
85
112
|
curatedHistory.push(...modelOutput);
|
|
86
113
|
}
|
|
87
|
-
else {
|
|
88
|
-
// Remove the last user input when model content is invalid.
|
|
89
|
-
curatedHistory.pop();
|
|
90
|
-
}
|
|
91
114
|
}
|
|
92
115
|
}
|
|
93
116
|
return curatedHistory;
|
|
94
117
|
}
|
|
118
|
+
/**
|
|
119
|
+
* Custom error to signal that a stream completed with invalid content,
|
|
120
|
+
* which should trigger a retry.
|
|
121
|
+
*/
|
|
122
|
+
export class InvalidStreamError extends Error {
|
|
123
|
+
type;
|
|
124
|
+
constructor(message, type) {
|
|
125
|
+
super(message);
|
|
126
|
+
this.name = 'InvalidStreamError';
|
|
127
|
+
this.type = type;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
95
130
|
/**
|
|
96
131
|
* Chat session that enables sending messages to the model with previous
|
|
97
132
|
* conversation context.
|
|
@@ -101,212 +136,26 @@ function extractCuratedHistory(comprehensiveHistory) {
|
|
|
101
136
|
*/
|
|
102
137
|
export class GeminiChat {
|
|
103
138
|
config;
|
|
104
|
-
|
|
105
|
-
|
|
139
|
+
systemInstruction;
|
|
140
|
+
tools;
|
|
106
141
|
history;
|
|
107
142
|
// A promise to represent the current state of the message being sent to the
|
|
108
143
|
// model.
|
|
109
144
|
sendPromise = Promise.resolve();
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
// [/PATCH:API_KEY_ROTATION]
|
|
114
|
-
generationConfig = {}, history = []) {
|
|
145
|
+
chatRecordingService;
|
|
146
|
+
lastPromptTokenCount;
|
|
147
|
+
constructor(config, systemInstruction = '', tools = [], history = [], resumedSessionData) {
|
|
115
148
|
this.config = config;
|
|
116
|
-
this.
|
|
117
|
-
this.
|
|
149
|
+
this.systemInstruction = systemInstruction;
|
|
150
|
+
this.tools = tools;
|
|
118
151
|
this.history = history;
|
|
119
152
|
validateHistory(history);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
console.log('[API_KEY_ROTATION] Updating content generator in GeminiChat instance');
|
|
124
|
-
this.contentGenerator = newContentGenerator;
|
|
125
|
-
console.log('[API_KEY_ROTATION] Content generator updated successfully');
|
|
126
|
-
}
|
|
127
|
-
// [/PATCH:API_KEY_ROTATION]
|
|
128
|
-
/**
|
|
129
|
-
* [PATCH:API_KEY_ROTATION] Safely format API key for logging (shows first 8 and last 4 chars)
|
|
130
|
-
*/
|
|
131
|
-
formatApiKeyForLog(apiKey) {
|
|
132
|
-
if (!apiKey || apiKey.length < 12) {
|
|
133
|
-
return 'invalid-key';
|
|
134
|
-
}
|
|
135
|
-
const start = apiKey.substring(0, 8);
|
|
136
|
-
const end = apiKey.substring(apiKey.length - 4);
|
|
137
|
-
const middle = '*'.repeat(Math.min(apiKey.length - 12, 20));
|
|
138
|
-
return `${start}${middle}${end}`;
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* [PATCH:API_KEY_ROTATION] Tries to rotate API key for GEMINI/OPENAI API key authentication modes.
|
|
142
|
-
* Returns the current model name if key was rotated, null otherwise.
|
|
143
|
-
*/
|
|
144
|
-
async tryRotateApiKey(authType) {
|
|
145
|
-
// Support both GEMINI and OPENAI API key modes
|
|
146
|
-
let envKey;
|
|
147
|
-
if (authType === AuthType.USE_GEMINI) {
|
|
148
|
-
envKey = 'GEMINI_API_KEY';
|
|
149
|
-
}
|
|
150
|
-
else if (authType === AuthType.USE_OPENAI) {
|
|
151
|
-
envKey = 'OPENAI_API_KEY';
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
return null; // Not a supported API key mode
|
|
155
|
-
}
|
|
156
|
-
const newApiKey = process.env[envKey]?.trim();
|
|
157
|
-
if (!newApiKey) {
|
|
158
|
-
return null;
|
|
159
|
-
}
|
|
160
|
-
const currentConfig = this.config.getContentGeneratorConfig();
|
|
161
|
-
if (!currentConfig) {
|
|
162
|
-
return null;
|
|
163
|
-
}
|
|
164
|
-
if (currentConfig.apiKey === newApiKey) {
|
|
165
|
-
return null; // Same key, no rotation needed
|
|
166
|
-
}
|
|
167
|
-
try {
|
|
168
|
-
// Update the API key in config first
|
|
169
|
-
currentConfig.apiKey = newApiKey;
|
|
170
|
-
// Create new content generator with the new API key
|
|
171
|
-
const newContentGenerator = await createContentGenerator(currentConfig, this.config, this.config.getSessionId());
|
|
172
|
-
// Update our content generator
|
|
173
|
-
this.contentGenerator = newContentGenerator;
|
|
174
|
-
const modelName = this.config.getModel();
|
|
175
|
-
return modelName;
|
|
176
|
-
}
|
|
177
|
-
catch (_error) {
|
|
178
|
-
return null;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
// [/PATCH:API_KEY_ROTATION]
|
|
182
|
-
/**
|
|
183
|
-
* Handles falling back to Flash model when persistent 429 errors occur for OAuth users.
|
|
184
|
-
* Uses a fallback handler if provided by the config; otherwise, returns null.
|
|
185
|
-
*/
|
|
186
|
-
async handleFlashFallback(authType, error) {
|
|
187
|
-
// First try to rotate API key for GEMINI/OPENAI API key modes
|
|
188
|
-
const rotateResult = await this.tryRotateApiKey(authType);
|
|
189
|
-
if (rotateResult) {
|
|
190
|
-
return rotateResult;
|
|
191
|
-
}
|
|
192
|
-
const currentModel = this.config.getModel();
|
|
193
|
-
const fallbackModel = DEFAULT_GEMINI_FLASH_MODEL;
|
|
194
|
-
// Don't fallback if already using Flash model
|
|
195
|
-
if (currentModel === fallbackModel) {
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
// Check if config has a fallback handler (set by CLI package)
|
|
199
|
-
const fallbackHandler = this.config.flashFallbackHandler;
|
|
200
|
-
if (typeof fallbackHandler === 'function') {
|
|
201
|
-
try {
|
|
202
|
-
const accepted = await fallbackHandler(currentModel, fallbackModel, error);
|
|
203
|
-
if (accepted !== false && accepted !== null) {
|
|
204
|
-
// Only OAuth users need model fallback, API key users rely on key rotation
|
|
205
|
-
if (authType === AuthType.LOGIN_WITH_GOOGLE) {
|
|
206
|
-
this.config.setModel(fallbackModel);
|
|
207
|
-
this.config.setFallbackMode(true);
|
|
208
|
-
return fallbackModel;
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
const currentModel = this.config.getModel();
|
|
212
|
-
return currentModel; // Continue with original model, rely on API key rotation
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
// Check if the model was switched manually in the handler
|
|
216
|
-
const newModel = this.config.getModel();
|
|
217
|
-
if (newModel === fallbackModel) {
|
|
218
|
-
return null; // Model was switched but don't continue with current prompt
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
catch (error) {
|
|
222
|
-
// Fallback handler failed, continue to return null
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return null;
|
|
153
|
+
this.chatRecordingService = new ChatRecordingService(config);
|
|
154
|
+
this.chatRecordingService.initialize(resumedSessionData);
|
|
155
|
+
this.lastPromptTokenCount = Math.ceil(JSON.stringify(this.history).length / 4);
|
|
226
156
|
}
|
|
227
157
|
setSystemInstruction(sysInstr) {
|
|
228
|
-
this.
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Sends a message to the model and returns the response.
|
|
232
|
-
*
|
|
233
|
-
* @remarks
|
|
234
|
-
* This method will wait for the previous message to be processed before
|
|
235
|
-
* sending the next message.
|
|
236
|
-
*
|
|
237
|
-
* @see {@link Chat#sendMessageStream} for streaming method.
|
|
238
|
-
* @param params - parameters for sending messages within a chat session.
|
|
239
|
-
* @returns The model's response.
|
|
240
|
-
*
|
|
241
|
-
* @example
|
|
242
|
-
* ```ts
|
|
243
|
-
* const chat = ai.chats.create({model: 'gemini-2.0-flash'});
|
|
244
|
-
* const response = await chat.sendMessage({
|
|
245
|
-
* message: 'Why is the sky blue?'
|
|
246
|
-
* });
|
|
247
|
-
* console.log(response.text);
|
|
248
|
-
* ```
|
|
249
|
-
*/
|
|
250
|
-
async sendMessage(params, prompt_id) {
|
|
251
|
-
await this.sendPromise;
|
|
252
|
-
const userContent = createUserContent(params.message);
|
|
253
|
-
const requestContents = this.getHistory(true).concat(userContent);
|
|
254
|
-
let response;
|
|
255
|
-
try {
|
|
256
|
-
const apiCall = () => {
|
|
257
|
-
const modelToUse = this.config.getModel() || DEFAULT_GEMINI_FLASH_MODEL;
|
|
258
|
-
// Prevent Flash model calls immediately after quota error
|
|
259
|
-
if (this.config.getQuotaErrorOccurred() &&
|
|
260
|
-
modelToUse === DEFAULT_GEMINI_FLASH_MODEL) {
|
|
261
|
-
throw new Error('Please submit a new query to continue with the Flash model.');
|
|
262
|
-
}
|
|
263
|
-
return this.contentGenerator.generateContent({
|
|
264
|
-
model: modelToUse,
|
|
265
|
-
contents: requestContents,
|
|
266
|
-
config: { ...this.generationConfig, ...params.config },
|
|
267
|
-
}, prompt_id);
|
|
268
|
-
};
|
|
269
|
-
response = await retryWithBackoff(apiCall, {
|
|
270
|
-
shouldRetry: (error) => {
|
|
271
|
-
// Check for known error messages and codes.
|
|
272
|
-
if (error instanceof Error && error.message) {
|
|
273
|
-
if (isSchemaDepthError(error.message))
|
|
274
|
-
return false;
|
|
275
|
-
if (error.message.includes('429'))
|
|
276
|
-
return true;
|
|
277
|
-
if (error.message.match(/5\d{2}/))
|
|
278
|
-
return true;
|
|
279
|
-
}
|
|
280
|
-
return false; // Don't retry other errors by default
|
|
281
|
-
},
|
|
282
|
-
onPersistent429: async (authType, error) => await this.handleFlashFallback(authType, error),
|
|
283
|
-
authType: this.config.getContentGeneratorConfig()?.authType,
|
|
284
|
-
});
|
|
285
|
-
this.sendPromise = (async () => {
|
|
286
|
-
const outputContent = response.candidates?.[0]?.content;
|
|
287
|
-
// Because the AFC input contains the entire curated chat history in
|
|
288
|
-
// addition to the new user input, we need to truncate the AFC history
|
|
289
|
-
// to deduplicate the existing chat history.
|
|
290
|
-
const fullAutomaticFunctionCallingHistory = response.automaticFunctionCallingHistory;
|
|
291
|
-
const index = this.getHistory(true).length;
|
|
292
|
-
let automaticFunctionCallingHistory = [];
|
|
293
|
-
if (fullAutomaticFunctionCallingHistory != null) {
|
|
294
|
-
automaticFunctionCallingHistory =
|
|
295
|
-
fullAutomaticFunctionCallingHistory.slice(index) ?? [];
|
|
296
|
-
}
|
|
297
|
-
const modelOutput = outputContent ? [outputContent] : [];
|
|
298
|
-
this.recordHistory(userContent, modelOutput, automaticFunctionCallingHistory);
|
|
299
|
-
})();
|
|
300
|
-
await this.sendPromise.catch(() => {
|
|
301
|
-
// Resets sendPromise to avoid subsequent calls failing
|
|
302
|
-
this.sendPromise = Promise.resolve();
|
|
303
|
-
});
|
|
304
|
-
return response;
|
|
305
|
-
}
|
|
306
|
-
catch (error) {
|
|
307
|
-
this.sendPromise = Promise.resolve();
|
|
308
|
-
throw error;
|
|
309
|
-
}
|
|
158
|
+
this.systemInstruction = sysInstr;
|
|
310
159
|
}
|
|
311
160
|
/**
|
|
312
161
|
* Sends a message to the model and returns the response in chunks.
|
|
@@ -316,71 +165,172 @@ export class GeminiChat {
|
|
|
316
165
|
* sending the next message.
|
|
317
166
|
*
|
|
318
167
|
* @see {@link Chat#sendMessage} for non-streaming method.
|
|
319
|
-
* @param
|
|
168
|
+
* @param modelConfigKey - The key for the model config.
|
|
169
|
+
* @param message - The list of messages to send.
|
|
170
|
+
* @param prompt_id - The ID of the prompt.
|
|
171
|
+
* @param signal - An abort signal for this message.
|
|
320
172
|
* @return The model's response.
|
|
321
173
|
*
|
|
322
174
|
* @example
|
|
323
175
|
* ```ts
|
|
324
176
|
* const chat = ai.chats.create({model: 'gemini-2.0-flash'});
|
|
325
177
|
* const response = await chat.sendMessageStream({
|
|
326
|
-
*
|
|
178
|
+
* message: 'Why is the sky blue?'
|
|
327
179
|
* });
|
|
328
180
|
* for await (const chunk of response) {
|
|
329
|
-
*
|
|
181
|
+
* console.log(chunk.text);
|
|
330
182
|
* }
|
|
331
183
|
* ```
|
|
332
184
|
*/
|
|
333
|
-
async sendMessageStream(
|
|
185
|
+
async sendMessageStream(modelConfigKey, message, prompt_id, signal) {
|
|
334
186
|
await this.sendPromise;
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
shouldRetry: (error) => {
|
|
357
|
-
// Check for known error messages and codes.
|
|
358
|
-
if (error instanceof Error && error.message) {
|
|
359
|
-
if (isSchemaDepthError(error.message))
|
|
360
|
-
return false;
|
|
361
|
-
if (error.message.includes('429'))
|
|
362
|
-
return true;
|
|
363
|
-
if (error.message.match(/5\d{2}/))
|
|
364
|
-
return true;
|
|
365
|
-
}
|
|
366
|
-
return false; // Don't retry other errors by default
|
|
367
|
-
},
|
|
368
|
-
onPersistent429: async (authType, error) => await this.handleFlashFallback(authType, error),
|
|
369
|
-
authType: this.config.getContentGeneratorConfig()?.authType,
|
|
187
|
+
// Preview Model Bypass mode for the new request.
|
|
188
|
+
// This ensures that we attempt to use Preview Model for every new user turn
|
|
189
|
+
// (unless the "Always" fallback mode is active, which is handled separately).
|
|
190
|
+
this.config.setPreviewModelBypassMode(false);
|
|
191
|
+
let streamDoneResolver;
|
|
192
|
+
const streamDonePromise = new Promise((resolve) => {
|
|
193
|
+
streamDoneResolver = resolve;
|
|
194
|
+
});
|
|
195
|
+
this.sendPromise = streamDonePromise;
|
|
196
|
+
const userContent = createUserContent(message);
|
|
197
|
+
const { model, generateContentConfig } = this.config.modelConfigService.getResolvedConfig(modelConfigKey);
|
|
198
|
+
generateContentConfig.abortSignal = signal;
|
|
199
|
+
// Record user input - capture complete message with all parts (text, files, images, etc.)
|
|
200
|
+
// but skip recording function responses (tool call results) as they should be stored in tool call records
|
|
201
|
+
if (!isFunctionResponse(userContent)) {
|
|
202
|
+
const userMessage = Array.isArray(message) ? message : [message];
|
|
203
|
+
const userMessageContent = partListUnionToString(toParts(userMessage));
|
|
204
|
+
this.chatRecordingService.recordMessage({
|
|
205
|
+
model,
|
|
206
|
+
type: 'user',
|
|
207
|
+
content: userMessageContent,
|
|
370
208
|
});
|
|
371
|
-
// Resolve the internal tracking of send completion promise - `sendPromise`
|
|
372
|
-
// for both success and failure response. The actual failure is still
|
|
373
|
-
// propagated by the `await streamResponse`.
|
|
374
|
-
this.sendPromise = Promise.resolve(streamResponse)
|
|
375
|
-
.then(() => undefined)
|
|
376
|
-
.catch(() => undefined);
|
|
377
|
-
const result = this.processStreamResponse(streamResponse, userContent);
|
|
378
|
-
return result;
|
|
379
|
-
}
|
|
380
|
-
catch (error) {
|
|
381
|
-
this.sendPromise = Promise.resolve();
|
|
382
|
-
throw error;
|
|
383
209
|
}
|
|
210
|
+
// Add user content to history ONCE before any attempts.
|
|
211
|
+
this.history.push(userContent);
|
|
212
|
+
const requestContents = this.getHistory(true);
|
|
213
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
214
|
+
const self = this;
|
|
215
|
+
return (async function* () {
|
|
216
|
+
try {
|
|
217
|
+
let lastError = new Error('Request failed after all retries.');
|
|
218
|
+
let maxAttempts = INVALID_CONTENT_RETRY_OPTIONS.maxAttempts;
|
|
219
|
+
// If we are in Preview Model Fallback Mode, we want to fail fast (1 attempt)
|
|
220
|
+
// when probing the Preview Model.
|
|
221
|
+
if (self.config.isPreviewModelFallbackMode() &&
|
|
222
|
+
model === PREVIEW_GEMINI_MODEL) {
|
|
223
|
+
maxAttempts = 1;
|
|
224
|
+
}
|
|
225
|
+
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
226
|
+
try {
|
|
227
|
+
if (attempt > 0) {
|
|
228
|
+
yield { type: StreamEventType.RETRY };
|
|
229
|
+
}
|
|
230
|
+
// If this is a retry, set temperature to 1 to encourage different output.
|
|
231
|
+
if (attempt > 0) {
|
|
232
|
+
generateContentConfig.temperature = 1;
|
|
233
|
+
}
|
|
234
|
+
const stream = await self.makeApiCallAndProcessStream(model, generateContentConfig, requestContents, prompt_id);
|
|
235
|
+
for await (const chunk of stream) {
|
|
236
|
+
yield { type: StreamEventType.CHUNK, value: chunk };
|
|
237
|
+
}
|
|
238
|
+
lastError = null;
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
lastError = error;
|
|
243
|
+
const isContentError = error instanceof InvalidStreamError;
|
|
244
|
+
if (isContentError && isGemini2Model(model)) {
|
|
245
|
+
// Check if we have more attempts left.
|
|
246
|
+
if (attempt < maxAttempts - 1) {
|
|
247
|
+
logContentRetry(self.config, new ContentRetryEvent(attempt, error.type, INVALID_CONTENT_RETRY_OPTIONS.initialDelayMs, model));
|
|
248
|
+
await new Promise((res) => setTimeout(res, INVALID_CONTENT_RETRY_OPTIONS.initialDelayMs *
|
|
249
|
+
(attempt + 1)));
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (lastError) {
|
|
257
|
+
if (lastError instanceof InvalidStreamError &&
|
|
258
|
+
isGemini2Model(model)) {
|
|
259
|
+
logContentRetryFailure(self.config, new ContentRetryFailureEvent(maxAttempts, lastError.type, model));
|
|
260
|
+
}
|
|
261
|
+
throw lastError;
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
// Preview Model successfully used, disable fallback mode.
|
|
265
|
+
// We only do this if we didn't bypass Preview Model (i.e. we actually used it).
|
|
266
|
+
if (model === PREVIEW_GEMINI_MODEL &&
|
|
267
|
+
!self.config.isPreviewModelBypassMode()) {
|
|
268
|
+
self.config.setPreviewModelFallbackMode(false);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
finally {
|
|
273
|
+
streamDoneResolver();
|
|
274
|
+
}
|
|
275
|
+
})();
|
|
276
|
+
}
|
|
277
|
+
async makeApiCallAndProcessStream(model, generateContentConfig, requestContents, prompt_id) {
|
|
278
|
+
let effectiveModel = model;
|
|
279
|
+
const contentsForPreviewModel = this.ensureActiveLoopHasThoughtSignatures(requestContents);
|
|
280
|
+
const apiCall = () => {
|
|
281
|
+
let modelToUse = getEffectiveModel(this.config.isInFallbackMode(), model, this.config.getPreviewFeatures());
|
|
282
|
+
// Preview Model Bypass Logic:
|
|
283
|
+
// If we are in "Preview Model Bypass Mode" (transient failure), we force downgrade to 2.5 Pro
|
|
284
|
+
// IF the effective model is currently Preview Model.
|
|
285
|
+
if (this.config.isPreviewModelBypassMode() &&
|
|
286
|
+
modelToUse === PREVIEW_GEMINI_MODEL) {
|
|
287
|
+
modelToUse = DEFAULT_GEMINI_MODEL;
|
|
288
|
+
}
|
|
289
|
+
effectiveModel = modelToUse;
|
|
290
|
+
const config = {
|
|
291
|
+
...generateContentConfig,
|
|
292
|
+
// TODO(12622): Ensure we don't overrwrite these when they are
|
|
293
|
+
// passed via config.
|
|
294
|
+
systemInstruction: this.systemInstruction,
|
|
295
|
+
tools: this.tools,
|
|
296
|
+
};
|
|
297
|
+
// TODO(joshualitt): Clean this up with model configs.
|
|
298
|
+
if (modelToUse.startsWith('gemini-3')) {
|
|
299
|
+
config.thinkingConfig = {
|
|
300
|
+
...config.thinkingConfig,
|
|
301
|
+
thinkingLevel: ThinkingLevel.HIGH,
|
|
302
|
+
};
|
|
303
|
+
delete config.thinkingConfig?.thinkingBudget;
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
// The `gemini-3` configs use thinkingLevel, so we have to invert the
|
|
307
|
+
// change above.
|
|
308
|
+
config.thinkingConfig = {
|
|
309
|
+
...config.thinkingConfig,
|
|
310
|
+
thinkingBudget: DEFAULT_THINKING_MODE,
|
|
311
|
+
};
|
|
312
|
+
delete config.thinkingConfig?.thinkingLevel;
|
|
313
|
+
}
|
|
314
|
+
return this.config.getContentGenerator().generateContentStream({
|
|
315
|
+
model: modelToUse,
|
|
316
|
+
contents: modelToUse === PREVIEW_GEMINI_MODEL
|
|
317
|
+
? contentsForPreviewModel
|
|
318
|
+
: requestContents,
|
|
319
|
+
config,
|
|
320
|
+
}, prompt_id);
|
|
321
|
+
};
|
|
322
|
+
const onPersistent429Callback = async (authType, error) => await handleFallback(this.config, effectiveModel, authType, error);
|
|
323
|
+
const streamResponse = await retryWithBackoff(apiCall, {
|
|
324
|
+
onPersistent429: onPersistent429Callback,
|
|
325
|
+
authType: this.config.getContentGeneratorConfig()?.authType,
|
|
326
|
+
retryFetchErrors: this.config.getRetryFetchErrors(),
|
|
327
|
+
signal: generateContentConfig.abortSignal,
|
|
328
|
+
maxAttempts: this.config.isPreviewModelFallbackMode() &&
|
|
329
|
+
model === PREVIEW_GEMINI_MODEL
|
|
330
|
+
? 1
|
|
331
|
+
: undefined,
|
|
332
|
+
});
|
|
333
|
+
return this.processStreamResponse(model, streamResponse);
|
|
384
334
|
}
|
|
385
335
|
/**
|
|
386
336
|
* Returns the chat history.
|
|
@@ -392,7 +342,7 @@ export class GeminiChat {
|
|
|
392
342
|
* - The `curated history` contains only the valid turns between user and
|
|
393
343
|
* model, which will be included in the subsequent requests sent to the model.
|
|
394
344
|
* - The `comprehensive history` contains all turns, including invalid or
|
|
395
|
-
*
|
|
345
|
+
* empty model outputs, providing a complete record of the history.
|
|
396
346
|
*
|
|
397
347
|
* The history is updated after receiving the response from the model,
|
|
398
348
|
* for streaming response, it means receiving the last chunk of the response.
|
|
@@ -401,9 +351,9 @@ export class GeminiChat {
|
|
|
401
351
|
* history`, set the `curated` parameter to `true`.
|
|
402
352
|
*
|
|
403
353
|
* @param curated - whether to return the curated history or the comprehensive
|
|
404
|
-
*
|
|
354
|
+
* history.
|
|
405
355
|
* @return History contents alternating between user and model for the entire
|
|
406
|
-
*
|
|
356
|
+
* chat session.
|
|
407
357
|
*/
|
|
408
358
|
getHistory(curated = false) {
|
|
409
359
|
const history = curated
|
|
@@ -421,8 +371,6 @@ export class GeminiChat {
|
|
|
421
371
|
}
|
|
422
372
|
/**
|
|
423
373
|
* Adds a new entry to the chat history.
|
|
424
|
-
*
|
|
425
|
-
* @param content - The content to add to the history.
|
|
426
374
|
*/
|
|
427
375
|
addHistory(content) {
|
|
428
376
|
this.history.push(content);
|
|
@@ -430,8 +378,70 @@ export class GeminiChat {
|
|
|
430
378
|
setHistory(history) {
|
|
431
379
|
this.history = history;
|
|
432
380
|
}
|
|
381
|
+
stripThoughtsFromHistory() {
|
|
382
|
+
this.history = this.history.map((content) => {
|
|
383
|
+
const newContent = { ...content };
|
|
384
|
+
if (newContent.parts) {
|
|
385
|
+
newContent.parts = newContent.parts.map((part) => {
|
|
386
|
+
if (part && typeof part === 'object' && 'thoughtSignature' in part) {
|
|
387
|
+
const newPart = { ...part };
|
|
388
|
+
delete newPart.thoughtSignature;
|
|
389
|
+
return newPart;
|
|
390
|
+
}
|
|
391
|
+
return part;
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
return newContent;
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
// To ensure our requests validate, the first function call in every model
|
|
398
|
+
// turn within the active loop must have a `thoughtSignature` property.
|
|
399
|
+
// If we do not do this, we will get back 400 errors from the API.
|
|
400
|
+
ensureActiveLoopHasThoughtSignatures(requestContents) {
|
|
401
|
+
// First, find the start of the active loop by finding the last user turn
|
|
402
|
+
// with a text message, i.e. that is not a function response.
|
|
403
|
+
let activeLoopStartIndex = -1;
|
|
404
|
+
for (let i = requestContents.length - 1; i >= 0; i--) {
|
|
405
|
+
const content = requestContents[i];
|
|
406
|
+
if (content.role === 'user' && content.parts?.some((part) => part.text)) {
|
|
407
|
+
activeLoopStartIndex = i;
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (activeLoopStartIndex === -1) {
|
|
412
|
+
return requestContents;
|
|
413
|
+
}
|
|
414
|
+
// Iterate through every message in the active loop, ensuring that the first
|
|
415
|
+
// function call in each message's list of parts has a valid
|
|
416
|
+
// thoughtSignature property. If it does not we replace the function call
|
|
417
|
+
// with a copy that uses the synthetic thought signature.
|
|
418
|
+
const newContents = requestContents.slice(); // Shallow copy the array
|
|
419
|
+
for (let i = activeLoopStartIndex; i < newContents.length; i++) {
|
|
420
|
+
const content = newContents[i];
|
|
421
|
+
if (content.role === 'model' && content.parts) {
|
|
422
|
+
const newParts = content.parts.slice();
|
|
423
|
+
for (let j = 0; j < newParts.length; j++) {
|
|
424
|
+
const part = newParts[j];
|
|
425
|
+
if (part.functionCall) {
|
|
426
|
+
if (!part.thoughtSignature) {
|
|
427
|
+
newParts[j] = {
|
|
428
|
+
...part,
|
|
429
|
+
thoughtSignature: SYNTHETIC_THOUGHT_SIGNATURE,
|
|
430
|
+
};
|
|
431
|
+
newContents[i] = {
|
|
432
|
+
...content,
|
|
433
|
+
parts: newParts,
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
break; // Only consider the first function call
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return newContents;
|
|
442
|
+
}
|
|
433
443
|
setTools(tools) {
|
|
434
|
-
this.
|
|
444
|
+
this.tools = tools;
|
|
435
445
|
}
|
|
436
446
|
async maybeIncludeSchemaDepthContext(error) {
|
|
437
447
|
// Check for potentially problematic cyclic tools with cyclic schemas
|
|
@@ -455,122 +465,134 @@ export class GeminiChat {
|
|
|
455
465
|
}
|
|
456
466
|
}
|
|
457
467
|
}
|
|
458
|
-
async *processStreamResponse(
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
let
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
468
|
+
async *processStreamResponse(model, streamResponse) {
|
|
469
|
+
const modelResponseParts = [];
|
|
470
|
+
let hasToolCall = false;
|
|
471
|
+
let finishReason;
|
|
472
|
+
for await (const chunk of streamResponse) {
|
|
473
|
+
const candidateWithReason = chunk?.candidates?.find((candidate) => candidate.finishReason);
|
|
474
|
+
if (candidateWithReason) {
|
|
475
|
+
finishReason = candidateWithReason.finishReason;
|
|
476
|
+
}
|
|
477
|
+
if (isValidResponse(chunk)) {
|
|
478
|
+
const content = chunk.candidates?.[0]?.content;
|
|
479
|
+
if (content?.parts) {
|
|
480
|
+
if (content.parts.some((part) => part.thought)) {
|
|
481
|
+
// Record thoughts
|
|
482
|
+
this.recordThoughtFromContent(content);
|
|
473
483
|
}
|
|
484
|
+
if (content.parts.some((part) => part.functionCall)) {
|
|
485
|
+
hasToolCall = true;
|
|
486
|
+
}
|
|
487
|
+
modelResponseParts.push(...content.parts.filter((part) => !part.thought));
|
|
474
488
|
}
|
|
475
|
-
yield chunk;
|
|
476
489
|
}
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
if (!errorOccurred) {
|
|
483
|
-
const allParts = [];
|
|
484
|
-
for (const content of outputContent) {
|
|
485
|
-
if (content.parts) {
|
|
486
|
-
allParts.push(...content.parts);
|
|
490
|
+
// Record token usage if this chunk has usageMetadata
|
|
491
|
+
if (chunk.usageMetadata) {
|
|
492
|
+
this.chatRecordingService.recordMessageTokens(chunk.usageMetadata);
|
|
493
|
+
if (chunk.usageMetadata.promptTokenCount !== undefined) {
|
|
494
|
+
this.lastPromptTokenCount = chunk.usageMetadata.promptTokenCount;
|
|
487
495
|
}
|
|
488
496
|
}
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
const
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
}
|
|
503
|
-
else {
|
|
504
|
-
// When not a function response appends an empty content when model returns empty response, so that the
|
|
505
|
-
// history is always alternating between user and model.
|
|
506
|
-
// Workaround for: https://b.corp.google.com/issues/420354090
|
|
507
|
-
if (!isFunctionResponse(userInput)) {
|
|
508
|
-
outputContents.push({
|
|
509
|
-
role: 'model',
|
|
510
|
-
parts: [],
|
|
511
|
-
});
|
|
497
|
+
yield chunk; // Yield every chunk to the UI immediately.
|
|
498
|
+
}
|
|
499
|
+
// String thoughts and consolidate text parts.
|
|
500
|
+
const consolidatedParts = [];
|
|
501
|
+
for (const part of modelResponseParts) {
|
|
502
|
+
const lastPart = consolidatedParts[consolidatedParts.length - 1];
|
|
503
|
+
if (lastPart?.text &&
|
|
504
|
+
isValidNonThoughtTextPart(lastPart) &&
|
|
505
|
+
isValidNonThoughtTextPart(part)) {
|
|
506
|
+
lastPart.text += part.text;
|
|
507
|
+
}
|
|
508
|
+
else {
|
|
509
|
+
consolidatedParts.push(part);
|
|
512
510
|
}
|
|
513
511
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
512
|
+
const responseText = consolidatedParts
|
|
513
|
+
.filter((part) => part.text)
|
|
514
|
+
.map((part) => part.text)
|
|
515
|
+
.join('')
|
|
516
|
+
.trim();
|
|
517
|
+
// Record model response text from the collected parts
|
|
518
|
+
if (responseText) {
|
|
519
|
+
this.chatRecordingService.recordMessage({
|
|
520
|
+
model,
|
|
521
|
+
type: 'gemini',
|
|
522
|
+
content: responseText,
|
|
523
|
+
});
|
|
520
524
|
}
|
|
521
|
-
//
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
525
|
+
// Stream validation logic: A stream is considered successful if:
|
|
526
|
+
// 1. There's a tool call OR
|
|
527
|
+
// 2. A not MALFORMED_FUNCTION_CALL finish reason and a non-mepty resp
|
|
528
|
+
//
|
|
529
|
+
// We throw an error only when there's no tool call AND:
|
|
530
|
+
// - No finish reason, OR
|
|
531
|
+
// - MALFORMED_FUNCTION_CALL finish reason OR
|
|
532
|
+
// - Empty response text (e.g., only thoughts with no actual content)
|
|
533
|
+
if (!hasToolCall) {
|
|
534
|
+
if (!finishReason) {
|
|
535
|
+
throw new InvalidStreamError('Model stream ended without a finish reason.', 'NO_FINISH_REASON');
|
|
526
536
|
}
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
// If both current and last are text, combine their text into the lastContent's first part
|
|
530
|
-
// and append any other parts from the current content.
|
|
531
|
-
lastContent.parts[0].text += content.parts[0].text || '';
|
|
532
|
-
if (content.parts.length > 1) {
|
|
533
|
-
lastContent.parts.push(...content.parts.slice(1));
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
else {
|
|
537
|
-
consolidatedOutputContents.push(content);
|
|
537
|
+
if (finishReason === FinishReason.MALFORMED_FUNCTION_CALL) {
|
|
538
|
+
throw new InvalidStreamError('Model stream ended with malformed function call.', 'MALFORMED_FUNCTION_CALL');
|
|
538
539
|
}
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
const lastHistoryEntry = this.history[this.history.length - 1];
|
|
542
|
-
const canMergeWithLastHistory = !automaticFunctionCallingHistory ||
|
|
543
|
-
automaticFunctionCallingHistory.length === 0;
|
|
544
|
-
if (canMergeWithLastHistory &&
|
|
545
|
-
this.isTextContent(lastHistoryEntry) &&
|
|
546
|
-
this.isTextContent(consolidatedOutputContents[0])) {
|
|
547
|
-
// If both current and last are text, combine their text into the lastHistoryEntry's first part
|
|
548
|
-
// and append any other parts from the current content.
|
|
549
|
-
lastHistoryEntry.parts[0].text +=
|
|
550
|
-
consolidatedOutputContents[0].parts[0].text || '';
|
|
551
|
-
if (consolidatedOutputContents[0].parts.length > 1) {
|
|
552
|
-
lastHistoryEntry.parts.push(...consolidatedOutputContents[0].parts.slice(1));
|
|
553
|
-
}
|
|
554
|
-
consolidatedOutputContents.shift(); // Remove the first element as it's merged
|
|
540
|
+
if (!responseText) {
|
|
541
|
+
throw new InvalidStreamError('Model stream ended with empty response text.', 'NO_RESPONSE_TEXT');
|
|
555
542
|
}
|
|
556
|
-
this.history.push(...consolidatedOutputContents);
|
|
557
543
|
}
|
|
544
|
+
this.history.push({ role: 'model', parts: consolidatedParts });
|
|
545
|
+
}
|
|
546
|
+
getLastPromptTokenCount() {
|
|
547
|
+
return this.lastPromptTokenCount;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* Gets the chat recording service instance.
|
|
551
|
+
*/
|
|
552
|
+
getChatRecordingService() {
|
|
553
|
+
return this.chatRecordingService;
|
|
558
554
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
555
|
+
/**
|
|
556
|
+
* Records completed tool calls with full metadata.
|
|
557
|
+
* This is called by external components when tool calls complete, before sending responses to Gemini.
|
|
558
|
+
*/
|
|
559
|
+
recordCompletedToolCalls(model, toolCalls) {
|
|
560
|
+
const toolCallRecords = toolCalls.map((call) => {
|
|
561
|
+
const resultDisplayRaw = call.response?.resultDisplay;
|
|
562
|
+
const resultDisplay = typeof resultDisplayRaw === 'string' ? resultDisplayRaw : undefined;
|
|
563
|
+
return {
|
|
564
|
+
id: call.request.callId,
|
|
565
|
+
name: call.request.name,
|
|
566
|
+
args: call.request.args,
|
|
567
|
+
result: call.response?.responseParts || null,
|
|
568
|
+
status: call.status,
|
|
569
|
+
timestamp: new Date().toISOString(),
|
|
570
|
+
resultDisplay,
|
|
571
|
+
};
|
|
572
|
+
});
|
|
573
|
+
this.chatRecordingService.recordToolCalls(model, toolCallRecords);
|
|
566
574
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
575
|
+
/**
|
|
576
|
+
* Extracts and records thought from thought content.
|
|
577
|
+
*/
|
|
578
|
+
recordThoughtFromContent(content) {
|
|
579
|
+
if (!content.parts || content.parts.length === 0) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
const thoughtPart = content.parts[0];
|
|
583
|
+
if (thoughtPart.text) {
|
|
584
|
+
// Extract subject and description using the same logic as turn.ts
|
|
585
|
+
const rawText = thoughtPart.text;
|
|
586
|
+
const subjectStringMatches = rawText.match(/\*\*(.*?)\*\*/s);
|
|
587
|
+
const subject = subjectStringMatches
|
|
588
|
+
? subjectStringMatches[1].trim()
|
|
589
|
+
: '';
|
|
590
|
+
const description = rawText.replace(/\*\*(.*?)\*\*/s, '').trim();
|
|
591
|
+
this.chatRecordingService.recordThought({
|
|
592
|
+
subject,
|
|
593
|
+
description,
|
|
594
|
+
});
|
|
595
|
+
}
|
|
574
596
|
}
|
|
575
597
|
}
|
|
576
598
|
/** Visible for Testing */
|