@office-ai/aioncli-core 0.2.3 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +10 -3
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/dist/src/agents/codebase-investigator.d.ts +11 -0
- package/dist/src/agents/codebase-investigator.js +73 -0
- package/dist/src/agents/codebase-investigator.js.map +1 -0
- package/dist/src/agents/executor.d.ts +88 -0
- package/dist/src/agents/executor.js +417 -0
- package/dist/src/agents/executor.js.map +1 -0
- package/dist/src/agents/executor.test.js +419 -0
- package/dist/src/agents/executor.test.js.map +1 -0
- package/dist/src/agents/invocation.d.ts +43 -0
- package/dist/src/agents/invocation.js +100 -0
- package/dist/src/agents/invocation.js.map +1 -0
- package/dist/src/agents/invocation.test.js +206 -0
- package/dist/src/agents/invocation.test.js.map +1 -0
- package/dist/src/agents/registry.d.ts +35 -0
- package/dist/src/agents/registry.js +58 -0
- package/dist/src/agents/registry.js.map +1 -0
- package/dist/src/agents/registry.test.js +146 -0
- package/dist/src/agents/registry.test.js.map +1 -0
- package/dist/src/agents/schema-utils.d.ts +39 -0
- package/dist/src/agents/schema-utils.js +57 -0
- package/dist/src/agents/schema-utils.js.map +1 -0
- package/dist/src/agents/schema-utils.test.d.ts +6 -0
- package/dist/src/agents/schema-utils.test.js +144 -0
- package/dist/src/agents/schema-utils.test.js.map +1 -0
- package/dist/src/agents/subagent-tool-wrapper.d.ts +36 -0
- package/dist/src/agents/subagent-tool-wrapper.js +47 -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 +105 -0
- package/dist/src/agents/subagent-tool-wrapper.test.js.map +1 -0
- package/dist/src/agents/types.d.ts +116 -0
- package/dist/src/agents/types.js +17 -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 +12 -0
- package/dist/src/code_assist/codeAssist.js.map +1 -1
- package/dist/src/code_assist/converter.d.ts +4 -1
- package/dist/src/code_assist/converter.js +38 -5
- package/dist/src/code_assist/converter.js.map +1 -1
- package/dist/src/code_assist/converter.test.js +93 -0
- package/dist/src/code_assist/converter.test.js.map +1 -1
- package/dist/src/code_assist/oauth-credential-storage.d.ts +25 -0
- package/dist/src/code_assist/oauth-credential-storage.js +109 -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 +136 -0
- package/dist/src/code_assist/oauth-credential-storage.test.js.map +1 -0
- package/dist/src/code_assist/oauth2.d.ts +1 -1
- package/dist/src/code_assist/oauth2.js +107 -48
- package/dist/src/code_assist/oauth2.js.map +1 -1
- package/dist/src/code_assist/oauth2.test.js +735 -343
- package/dist/src/code_assist/oauth2.test.js.map +1 -1
- package/dist/src/code_assist/server.d.ts +4 -4
- package/dist/src/code_assist/server.js +25 -2
- package/dist/src/code_assist/server.js.map +1 -1
- package/dist/src/code_assist/server.test.js +25 -0
- package/dist/src/code_assist/server.test.js.map +1 -1
- package/dist/src/code_assist/setup.d.ts +1 -1
- package/dist/src/code_assist/setup.js +1 -1
- 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 +17 -2
- package/dist/src/config/config.d.ts +121 -25
- package/dist/src/config/config.js +298 -89
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/config.test.js +370 -131
- 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/models.d.ts +16 -0
- package/dist/src/config/models.js +29 -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 +55 -0
- package/dist/src/config/models.test.js.map +1 -0
- package/dist/src/config/storage.d.ts +34 -0
- package/dist/src/config/storage.js +95 -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 +47 -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 +17 -0
- package/dist/src/confirmation-bus/message-bus.js +81 -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 +164 -0
- package/dist/src/confirmation-bus/message-bus.test.js.map +1 -0
- package/dist/src/confirmation-bus/types.d.ts +38 -0
- package/dist/src/confirmation-bus/types.js +15 -0
- package/dist/src/confirmation-bus/types.js.map +1 -0
- package/dist/src/core/baseLlmClient.d.ts +54 -0
- package/dist/src/core/baseLlmClient.js +190 -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 +316 -0
- package/dist/src/core/baseLlmClient.test.js.map +1 -0
- package/dist/src/core/client.d.ts +28 -33
- package/dist/src/core/client.js +187 -384
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/client.test.js +745 -500
- package/dist/src/core/client.test.js.map +1 -1
- package/dist/src/core/contentGenerator.d.ts +4 -4
- package/dist/src/core/contentGenerator.js +6 -7
- package/dist/src/core/contentGenerator.js.map +1 -1
- package/dist/src/core/contentGenerator.test.js +1 -3
- package/dist/src/core/contentGenerator.test.js.map +1 -1
- package/dist/src/core/coreToolScheduler.d.ts +20 -7
- package/dist/src/core/coreToolScheduler.js +216 -53
- package/dist/src/core/coreToolScheduler.js.map +1 -1
- package/dist/src/core/coreToolScheduler.test.js +564 -88
- package/dist/src/core/coreToolScheduler.test.js.map +1 -1
- package/dist/src/core/geminiChat.d.ts +54 -53
- package/dist/src/core/geminiChat.js +300 -356
- package/dist/src/core/geminiChat.js.map +1 -1
- package/dist/src/core/geminiChat.test.js +1255 -321
- 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 +4 -2
- package/dist/src/core/logger.js +4 -3
- package/dist/src/core/logger.js.map +1 -1
- package/dist/src/core/logger.test.js +17 -16
- package/dist/src/core/logger.test.js.map +1 -1
- package/dist/src/core/loggingContentGenerator.d.ts +3 -3
- package/dist/src/core/loggingContentGenerator.js +15 -16
- package/dist/src/core/loggingContentGenerator.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.d.ts +3 -5
- package/dist/src/core/nonInteractiveToolExecutor.js +14 -122
- package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.test.js +158 -78
- 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 +21 -14
- 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 +5 -0
- package/dist/src/core/prompts.js +66 -44
- package/dist/src/core/prompts.js.map +1 -1
- package/dist/src/core/prompts.test.js +130 -1
- package/dist/src/core/prompts.test.js.map +1 -1
- 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/turn.d.ts +37 -13
- package/dist/src/core/turn.js +63 -28
- package/dist/src/core/turn.js.map +1 -1
- package/dist/src/core/turn.test.js +359 -100
- 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 +129 -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 +130 -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/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 +48 -12
- package/dist/src/ide/detect-ide.js +47 -66
- package/dist/src/ide/detect-ide.js.map +1 -1
- package/dist/src/ide/detect-ide.test.js +79 -52
- package/dist/src/ide/detect-ide.test.js.map +1 -1
- package/dist/src/ide/ide-client.d.ts +69 -23
- package/dist/src/ide/ide-client.js +372 -78
- package/dist/src/ide/ide-client.js.map +1 -1
- package/dist/src/ide/ide-client.test.js +375 -30
- 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 +37 -24
- package/dist/src/ide/ide-installer.js.map +1 -1
- package/dist/src/ide/ide-installer.test.js +104 -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 +81 -50
- 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 +158 -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 +20 -2
- package/dist/src/index.js +20 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/google-auth-provider.d.ts +3 -3
- package/dist/src/mcp/google-auth-provider.test.js.map +1 -1
- package/dist/src/mcp/oauth-provider.d.ts +17 -13
- package/dist/src/mcp/oauth-provider.js +81 -69
- package/dist/src/mcp/oauth-provider.js.map +1 -1
- package/dist/src/mcp/oauth-provider.test.js +212 -37
- 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 +54 -25
- package/dist/src/mcp/oauth-token-storage.js.map +1 -1
- package/dist/src/mcp/oauth-token-storage.test.js +256 -162
- package/dist/src/mcp/oauth-token-storage.test.js.map +1 -1
- package/dist/src/mcp/oauth-utils.d.ts +9 -1
- package/dist/src/mcp/oauth-utils.js +42 -27
- package/dist/src/mcp/oauth-utils.js.map +1 -1
- package/dist/src/mcp/oauth-utils.test.js +41 -1
- package/dist/src/mcp/oauth-utils.test.js.map +1 -1
- package/dist/src/mcp/sa-impersonation-provider.d.ts +33 -0
- package/dist/src/mcp/sa-impersonation-provider.js +130 -0
- package/dist/src/mcp/sa-impersonation-provider.js.map +1 -0
- package/dist/src/mcp/sa-impersonation-provider.test.d.ts +6 -0
- package/dist/src/mcp/sa-impersonation-provider.test.js +117 -0
- package/dist/src/mcp/sa-impersonation-provider.test.js.map +1 -0
- package/dist/src/mcp/token-storage/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 +160 -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 +144 -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 +235 -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 +31 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.js +190 -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 +254 -0
- package/dist/src/mcp/token-storage/keychain-token-storage.test.js.map +1 -0
- package/dist/src/mcp/token-storage/types.d.ts +38 -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/types.d.ts +20 -0
- package/dist/src/output/types.js +11 -0
- package/dist/src/output/types.js.map +1 -0
- package/dist/src/policy/index.d.ts +7 -0
- package/dist/src/policy/index.js +8 -0
- package/dist/src/policy/index.js.map +1 -0
- package/dist/src/policy/policy-engine.d.ts +30 -0
- package/dist/src/policy/policy-engine.js +92 -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 +515 -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/types.d.ts +47 -0
- package/dist/src/policy/types.js +12 -0
- package/dist/src/policy/types.js.map +1 -0
- package/dist/src/prompts/mcp-prompts.d.ts +2 -2
- package/dist/src/prompts/prompt-registry.d.ts +1 -1
- package/dist/src/routing/modelRouterService.d.ts +23 -0
- package/dist/src/routing/modelRouterService.js +70 -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 +98 -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 +173 -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 +192 -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 +55 -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 +42 -0
- package/dist/src/routing/strategies/overrideStrategy.test.js.map +1 -0
- package/dist/src/services/chatRecordingService.d.ts +8 -14
- package/dist/src/services/chatRecordingService.js +33 -21
- 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 +10 -0
- package/dist/src/services/fileDiscoveryService.js +32 -18
- package/dist/src/services/fileDiscoveryService.js.map +1 -1
- package/dist/src/services/fileDiscoveryService.test.js +3 -3
- 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 +8 -2
- package/dist/src/services/loopDetectionService.js +64 -24
- package/dist/src/services/loopDetectionService.js.map +1 -1
- package/dist/src/services/loopDetectionService.test.js +64 -13
- package/dist/src/services/loopDetectionService.test.js.map +1 -1
- package/dist/src/services/shellExecutionService.d.ts +36 -2
- package/dist/src/services/shellExecutionService.js +238 -47
- package/dist/src/services/shellExecutionService.js.map +1 -1
- package/dist/src/services/shellExecutionService.test.js +197 -58
- package/dist/src/services/shellExecutionService.test.js.map +1 -1
- package/dist/src/telemetry/activity-detector.d.ts +41 -0
- package/dist/src/telemetry/activity-detector.js +61 -0
- package/dist/src/telemetry/activity-detector.js.map +1 -0
- package/dist/src/telemetry/activity-detector.test.d.ts +6 -0
- package/dist/src/telemetry/activity-detector.test.js +136 -0
- package/dist/src/telemetry/activity-detector.test.js.map +1 -0
- package/dist/src/telemetry/activity-types.d.ts +19 -0
- package/dist/src/telemetry/activity-types.js +21 -0
- package/dist/src/telemetry/activity-types.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +34 -4
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +322 -15
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.d.ts +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +321 -11
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +51 -2
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +124 -2
- 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 +17 -7
- package/dist/src/telemetry/constants.js +18 -7
- 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 +117 -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 +12 -2
- package/dist/src/telemetry/index.js +16 -2
- package/dist/src/telemetry/index.js.map +1 -1
- package/dist/src/telemetry/loggers.d.ts +17 -2
- package/dist/src/telemetry/loggers.js +316 -14
- package/dist/src/telemetry/loggers.js.map +1 -1
- package/dist/src/telemetry/loggers.test.circular.js +3 -3
- package/dist/src/telemetry/loggers.test.circular.js.map +1 -1
- package/dist/src/telemetry/loggers.test.js +452 -48
- package/dist/src/telemetry/loggers.test.js.map +1 -1
- package/dist/src/telemetry/metrics.d.ts +323 -12
- package/dist/src/telemetry/metrics.js +464 -83
- package/dist/src/telemetry/metrics.js.map +1 -1
- package/dist/src/telemetry/metrics.test.js +583 -38
- 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 +20 -2
- 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/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 +40 -0
- package/dist/src/telemetry/telemetry-utils.test.js.map +1 -0
- package/dist/src/telemetry/types.d.ts +136 -8
- package/dist/src/telemetry/types.js +233 -11
- package/dist/src/telemetry/types.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.d.ts +3 -3
- package/dist/src/telemetry/uiTelemetry.js +7 -8
- package/dist/src/telemetry/uiTelemetry.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.test.js +33 -29
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
- package/dist/src/test-utils/config.d.ts +2 -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/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 +6 -5
- package/dist/src/tools/edit.js +58 -40
- package/dist/src/tools/edit.js.map +1 -1
- package/dist/src/tools/edit.test.js +192 -16
- package/dist/src/tools/edit.test.js.map +1 -1
- package/dist/src/tools/glob.d.ts +7 -2
- package/dist/src/tools/glob.js +42 -23
- package/dist/src/tools/glob.js.map +1 -1
- package/dist/src/tools/glob.test.js +80 -4
- package/dist/src/tools/glob.test.js.map +1 -1
- package/dist/src/tools/grep.d.ts +3 -2
- package/dist/src/tools/grep.js +35 -15
- package/dist/src/tools/grep.js.map +1 -1
- package/dist/src/tools/grep.test.js +26 -3
- package/dist/src/tools/grep.test.js.map +1 -1
- package/dist/src/tools/ls.d.ts +3 -2
- package/dist/src/tools/ls.js +31 -39
- package/dist/src/tools/ls.js.map +1 -1
- package/dist/src/tools/ls.test.js +145 -280
- package/dist/src/tools/ls.test.js.map +1 -1
- package/dist/src/tools/mcp-client-manager.d.ts +8 -6
- package/dist/src/tools/mcp-client-manager.js +13 -4
- package/dist/src/tools/mcp-client-manager.js.map +1 -1
- package/dist/src/tools/mcp-client-manager.test.js +20 -1
- package/dist/src/tools/mcp-client-manager.test.js.map +1 -1
- package/dist/src/tools/mcp-client.d.ts +18 -21
- package/dist/src/tools/mcp-client.js +87 -120
- package/dist/src/tools/mcp-client.js.map +1 -1
- package/dist/src/tools/mcp-client.test.js +32 -152
- package/dist/src/tools/mcp-client.test.js.map +1 -1
- package/dist/src/tools/mcp-tool.d.ts +6 -4
- package/dist/src/tools/mcp-tool.js +51 -13
- package/dist/src/tools/mcp-tool.js.map +1 -1
- package/dist/src/tools/mcp-tool.test.js +166 -12
- package/dist/src/tools/mcp-tool.test.js.map +1 -1
- package/dist/src/tools/memoryTool.d.ts +3 -2
- package/dist/src/tools/memoryTool.js +14 -37
- package/dist/src/tools/memoryTool.js.map +1 -1
- package/dist/src/tools/memoryTool.test.js +16 -4
- package/dist/src/tools/memoryTool.test.js.map +1 -1
- package/dist/src/tools/message-bus-integration.test.d.ts +6 -0
- package/dist/src/tools/message-bus-integration.test.js +183 -0
- package/dist/src/tools/message-bus-integration.test.js.map +1 -0
- package/dist/src/tools/modifiable-tool.d.ts +2 -2
- package/dist/src/tools/modifiable-tool.js +3 -3
- package/dist/src/tools/modifiable-tool.js.map +1 -1
- package/dist/src/tools/modifiable-tool.test.js +4 -4
- package/dist/src/tools/modifiable-tool.test.js.map +1 -1
- package/dist/src/tools/read-file.d.ts +3 -2
- package/dist/src/tools/read-file.js +23 -38
- package/dist/src/tools/read-file.js.map +1 -1
- package/dist/src/tools/read-file.test.js +38 -6
- package/dist/src/tools/read-file.test.js.map +1 -1
- package/dist/src/tools/read-many-files.d.ts +3 -2
- package/dist/src/tools/read-many-files.js +52 -107
- package/dist/src/tools/read-many-files.js.map +1 -1
- package/dist/src/tools/read-many-files.test.js +64 -11
- package/dist/src/tools/read-many-files.test.js.map +1 -1
- package/dist/src/tools/ripGrep.d.ts +55 -0
- package/dist/src/tools/ripGrep.js +393 -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 +976 -0
- package/dist/src/tools/ripGrep.test.js.map +1 -0
- package/dist/src/tools/shell.d.ts +13 -2
- package/dist/src/tools/shell.js +42 -32
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/shell.test.js +57 -75
- package/dist/src/tools/shell.test.js.map +1 -1
- package/dist/src/tools/smart-edit.d.ts +91 -0
- package/dist/src/tools/smart-edit.js +702 -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 +542 -0
- package/dist/src/tools/smart-edit.test.js.map +1 -0
- package/dist/src/tools/tool-error.d.ts +18 -1
- package/dist/src/tools/tool-error.js +27 -0
- package/dist/src/tools/tool-error.js.map +1 -1
- package/dist/src/tools/tool-registry.d.ts +10 -4
- package/dist/src/tools/tool-registry.js +20 -7
- package/dist/src/tools/tool-registry.js.map +1 -1
- package/dist/src/tools/tool-registry.test.js +93 -10
- package/dist/src/tools/tool-registry.test.js.map +1 -1
- package/dist/src/tools/tools.d.ts +33 -16
- package/dist/src/tools/tools.js +115 -5
- 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 +3 -2
- package/dist/src/tools/web-fetch.js +14 -10
- package/dist/src/tools/web-fetch.js.map +1 -1
- package/dist/src/tools/web-fetch.test.js +55 -16
- package/dist/src/tools/web-fetch.test.js.map +1 -1
- package/dist/src/tools/web-search.d.ts +4 -3
- package/dist/src/tools/web-search.js +31 -8
- package/dist/src/tools/web-search.js.map +1 -1
- package/dist/src/tools/web-search.test.js +69 -1
- package/dist/src/tools/web-search.test.js.map +1 -1
- package/dist/src/tools/write-file.d.ts +4 -3
- package/dist/src/tools/write-file.js +17 -18
- package/dist/src/tools/write-file.js.map +1 -1
- package/dist/src/tools/write-file.test.js +108 -24
- package/dist/src/tools/write-file.test.js.map +1 -1
- package/dist/src/tools/write-todos.d.ts +25 -0
- package/dist/src/tools/write-todos.js +150 -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 +13 -7
- 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/editCorrector.d.ts +9 -8
- package/dist/src/utils/editCorrector.js +62 -19
- package/dist/src/utils/editCorrector.js.map +1 -1
- package/dist/src/utils/editCorrector.test.js +33 -82
- package/dist/src/utils/editCorrector.test.js.map +1 -1
- package/dist/src/utils/editor.js +32 -45
- package/dist/src/utils/editor.js.map +1 -1
- package/dist/src/utils/editor.test.js +62 -76
- package/dist/src/utils/editor.test.js.map +1 -1
- package/dist/src/utils/environmentContext.d.ts +2 -2
- package/dist/src/utils/errorParsing.js +2 -2
- package/dist/src/utils/errorParsing.js.map +1 -1
- package/dist/src/utils/errorParsing.test.js +7 -7
- 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 +25 -0
- package/dist/src/utils/errors.js +42 -0
- package/dist/src/utils/errors.js.map +1 -1
- package/dist/src/utils/fetch.js +1 -1
- package/dist/src/utils/fetch.js.map +1 -1
- package/dist/src/utils/fileUtils.d.ts +24 -12
- package/dist/src/utils/fileUtils.js +170 -79
- package/dist/src/utils/fileUtils.js.map +1 -1
- package/dist/src/utils/fileUtils.test.js +347 -29
- 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.integration.test.js → flashFallback.test.js} +33 -29
- package/dist/src/utils/flashFallback.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 +3 -3
- package/dist/src/utils/getFolderStructure.js.map +1 -1
- package/dist/src/utils/getFolderStructure.test.js +4 -4
- package/dist/src/utils/getFolderStructure.test.js.map +1 -1
- package/dist/src/utils/gitIgnoreParser.d.ts +3 -7
- package/dist/src/utils/gitIgnoreParser.js +126 -35
- package/dist/src/utils/gitIgnoreParser.js.map +1 -1
- package/dist/src/utils/gitIgnoreParser.test.js +69 -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/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 +250 -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 +50 -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 +83 -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 +131 -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 +186 -0
- package/dist/src/utils/llm-edit-fixer.test.js.map +1 -0
- package/dist/src/utils/memoryDiscovery.d.ts +7 -6
- package/dist/src/utils/memoryDiscovery.js +68 -33
- package/dist/src/utils/memoryDiscovery.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.test.js +88 -26
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.js +15 -22
- package/dist/src/utils/memoryImportProcessor.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.test.js +16 -141
- 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 +8 -2
- package/dist/src/utils/nextSpeakerChecker.js.map +1 -1
- package/dist/src/utils/nextSpeakerChecker.test.js +75 -64
- package/dist/src/utils/nextSpeakerChecker.test.js.map +1 -1
- 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/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 +363 -0
- package/dist/src/utils/pathReader.test.js.map +1 -0
- package/dist/src/utils/paths.d.ts +0 -17
- package/dist/src/utils/paths.js +2 -28
- package/dist/src/utils/paths.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 -1
- package/dist/src/utils/retry.d.ts +3 -1
- package/dist/src/utils/retry.js +20 -5
- package/dist/src/utils/retry.js.map +1 -1
- package/dist/src/utils/retry.test.js +35 -3
- package/dist/src/utils/retry.test.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 +6 -1
- package/dist/src/utils/shell-utils.js +51 -30
- package/dist/src/utils/shell-utils.js.map +1 -1
- package/dist/src/utils/shell-utils.test.js +9 -0
- package/dist/src/utils/shell-utils.test.js.map +1 -1
- package/dist/src/utils/summarizer.d.ts +2 -2
- package/dist/src/utils/summarizer.test.js.map +1 -1
- package/dist/src/utils/systemEncoding.js +2 -2
- package/dist/src/utils/systemEncoding.js.map +1 -1
- package/dist/src/utils/systemEncoding.test.js +2 -2
- package/dist/src/utils/systemEncoding.test.js.map +1 -1
- 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 +58 -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 +61 -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 +114 -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} +33 -30
- package/dist/src/utils/userAccountManager.test.js.map +1 -0
- package/dist/src/utils/workspaceContext.js +13 -7
- package/dist/src/utils/workspaceContext.js.map +1 -1
- package/dist/src/utils/workspaceContext.test.js +41 -16
- package/dist/src/utils/workspaceContext.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -9
- 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.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/executor.test.d.ts} +0 -0
- /package/dist/src/{utils/user_account.test.d.ts → agents/invocation.test.d.ts} +0 -0
- /package/dist/src/{utils/user_id.test.d.ts → agents/registry.test.d.ts} +0 -0
|
@@ -5,12 +5,31 @@
|
|
|
5
5
|
*/
|
|
6
6
|
// DISCLAIMER: This is a copied version of https://github.com/googleapis/js-genai/blob/main/src/chats.ts with the intention of working around a key bug
|
|
7
7
|
// where function responses are not treated as "valid" responses: https://b.corp.google.com/issues/420354090
|
|
8
|
-
import {
|
|
8
|
+
import { GenerateContentResponse, FinishReason, ApiError, } from '@google/genai';
|
|
9
|
+
import { toParts } from '../code_assist/converter.js';
|
|
10
|
+
import { createUserContent } from '@google/genai';
|
|
9
11
|
import { retryWithBackoff } from '../utils/retry.js';
|
|
12
|
+
import { DEFAULT_GEMINI_FLASH_MODEL, getEffectiveModel, } from '../config/models.js';
|
|
13
|
+
import { hasCycleInSchema, MUTATOR_KINDS } from '../tools/tools.js';
|
|
14
|
+
import { logContentRetry, logContentRetryFailure, } from '../telemetry/loggers.js';
|
|
15
|
+
import { ChatRecordingService } from '../services/chatRecordingService.js';
|
|
16
|
+
import { ContentRetryEvent, ContentRetryFailureEvent, } from '../telemetry/types.js';
|
|
17
|
+
import { handleFallback } from '../fallback/handler.js';
|
|
10
18
|
import { isFunctionResponse } from '../utils/messageInspectors.js';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
19
|
+
import { partListUnionToString } from './geminiRequest.js';
|
|
20
|
+
import { uiTelemetryService } from '../telemetry/uiTelemetry.js';
|
|
21
|
+
export var StreamEventType;
|
|
22
|
+
(function (StreamEventType) {
|
|
23
|
+
/** A regular content chunk from the API. */
|
|
24
|
+
StreamEventType["CHUNK"] = "chunk";
|
|
25
|
+
/** A signal that a retry is about to happen. The UI should discard any partial
|
|
26
|
+
* content from the attempt that just failed. */
|
|
27
|
+
StreamEventType["RETRY"] = "retry";
|
|
28
|
+
})(StreamEventType || (StreamEventType = {}));
|
|
29
|
+
const INVALID_CONTENT_RETRY_OPTIONS = {
|
|
30
|
+
maxAttempts: 2, // 1 initial call + 1 retry
|
|
31
|
+
initialDelayMs: 500,
|
|
32
|
+
};
|
|
14
33
|
/**
|
|
15
34
|
* Returns true if the response is valid, false otherwise.
|
|
16
35
|
*/
|
|
@@ -24,6 +43,16 @@ function isValidResponse(response) {
|
|
|
24
43
|
}
|
|
25
44
|
return isValidContent(content);
|
|
26
45
|
}
|
|
46
|
+
export function isValidNonThoughtTextPart(part) {
|
|
47
|
+
return (typeof part.text === 'string' &&
|
|
48
|
+
!part.thought &&
|
|
49
|
+
// Technically, the model should never generate parts that have text and
|
|
50
|
+
// any of these but we don't trust them so check anyways.
|
|
51
|
+
!part.functionCall &&
|
|
52
|
+
!part.functionResponse &&
|
|
53
|
+
!part.inlineData &&
|
|
54
|
+
!part.fileData);
|
|
55
|
+
}
|
|
27
56
|
function isValidContent(content) {
|
|
28
57
|
if (content.parts === undefined || content.parts.length === 0) {
|
|
29
58
|
return false;
|
|
@@ -84,14 +113,22 @@ function extractCuratedHistory(comprehensiveHistory) {
|
|
|
84
113
|
if (isValid) {
|
|
85
114
|
curatedHistory.push(...modelOutput);
|
|
86
115
|
}
|
|
87
|
-
else {
|
|
88
|
-
// Remove the last user input when model content is invalid.
|
|
89
|
-
curatedHistory.pop();
|
|
90
|
-
}
|
|
91
116
|
}
|
|
92
117
|
}
|
|
93
118
|
return curatedHistory;
|
|
94
119
|
}
|
|
120
|
+
/**
|
|
121
|
+
* Custom error to signal that a stream completed with invalid content,
|
|
122
|
+
* which should trigger a retry.
|
|
123
|
+
*/
|
|
124
|
+
export class InvalidStreamError extends Error {
|
|
125
|
+
type;
|
|
126
|
+
constructor(message, type) {
|
|
127
|
+
super(message);
|
|
128
|
+
this.name = 'InvalidStreamError';
|
|
129
|
+
this.type = type;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
95
132
|
/**
|
|
96
133
|
* Chat session that enables sending messages to the model with previous
|
|
97
134
|
* conversation context.
|
|
@@ -101,213 +138,23 @@ function extractCuratedHistory(comprehensiveHistory) {
|
|
|
101
138
|
*/
|
|
102
139
|
export class GeminiChat {
|
|
103
140
|
config;
|
|
104
|
-
contentGenerator;
|
|
105
141
|
generationConfig;
|
|
106
142
|
history;
|
|
107
143
|
// A promise to represent the current state of the message being sent to the
|
|
108
144
|
// model.
|
|
109
145
|
sendPromise = Promise.resolve();
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
contentGenerator,
|
|
113
|
-
// [/PATCH:API_KEY_ROTATION]
|
|
114
|
-
generationConfig = {}, history = []) {
|
|
146
|
+
chatRecordingService;
|
|
147
|
+
constructor(config, generationConfig = {}, history = []) {
|
|
115
148
|
this.config = config;
|
|
116
|
-
this.contentGenerator = contentGenerator;
|
|
117
149
|
this.generationConfig = generationConfig;
|
|
118
150
|
this.history = history;
|
|
119
151
|
validateHistory(history);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
updateContentGenerator(newContentGenerator) {
|
|
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;
|
|
152
|
+
this.chatRecordingService = new ChatRecordingService(config);
|
|
153
|
+
this.chatRecordingService.initialize();
|
|
226
154
|
}
|
|
227
155
|
setSystemInstruction(sysInstr) {
|
|
228
156
|
this.generationConfig.systemInstruction = sysInstr;
|
|
229
157
|
}
|
|
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
|
-
}
|
|
310
|
-
}
|
|
311
158
|
/**
|
|
312
159
|
* Sends a message to the model and returns the response in chunks.
|
|
313
160
|
*
|
|
@@ -323,64 +170,113 @@ export class GeminiChat {
|
|
|
323
170
|
* ```ts
|
|
324
171
|
* const chat = ai.chats.create({model: 'gemini-2.0-flash'});
|
|
325
172
|
* const response = await chat.sendMessageStream({
|
|
326
|
-
*
|
|
173
|
+
* message: 'Why is the sky blue?'
|
|
327
174
|
* });
|
|
328
175
|
* for await (const chunk of response) {
|
|
329
|
-
*
|
|
176
|
+
* console.log(chunk.text);
|
|
330
177
|
* }
|
|
331
178
|
* ```
|
|
332
179
|
*/
|
|
333
|
-
async sendMessageStream(params, prompt_id) {
|
|
180
|
+
async sendMessageStream(model, params, prompt_id) {
|
|
334
181
|
await this.sendPromise;
|
|
182
|
+
let streamDoneResolver;
|
|
183
|
+
const streamDonePromise = new Promise((resolve) => {
|
|
184
|
+
streamDoneResolver = resolve;
|
|
185
|
+
});
|
|
186
|
+
this.sendPromise = streamDonePromise;
|
|
335
187
|
const userContent = createUserContent(params.message);
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
contents: requestContents,
|
|
348
|
-
config: { ...this.generationConfig, ...params.config },
|
|
349
|
-
}, prompt_id);
|
|
350
|
-
};
|
|
351
|
-
// Note: Retrying streams can be complex. If generateContentStream itself doesn't handle retries
|
|
352
|
-
// for transient issues internally before yielding the async generator, this retry will re-initiate
|
|
353
|
-
// the stream. For simple 429/500 errors on initial call, this is fine.
|
|
354
|
-
// If errors occur mid-stream, this setup won't resume the stream; it will restart it.
|
|
355
|
-
const streamResponse = await retryWithBackoff(apiCall, {
|
|
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,
|
|
188
|
+
// Record user input - capture complete message with all parts (text, files, images, etc.)
|
|
189
|
+
// but skip recording function responses (tool call results) as they should be stored in tool call records
|
|
190
|
+
if (!isFunctionResponse(userContent)) {
|
|
191
|
+
const userMessage = Array.isArray(params.message)
|
|
192
|
+
? params.message
|
|
193
|
+
: [params.message];
|
|
194
|
+
const userMessageContent = partListUnionToString(toParts(userMessage));
|
|
195
|
+
this.chatRecordingService.recordMessage({
|
|
196
|
+
model,
|
|
197
|
+
type: 'user',
|
|
198
|
+
content: userMessageContent,
|
|
370
199
|
});
|
|
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
200
|
}
|
|
201
|
+
// Add user content to history ONCE before any attempts.
|
|
202
|
+
this.history.push(userContent);
|
|
203
|
+
const requestContents = this.getHistory(true);
|
|
204
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
205
|
+
const self = this;
|
|
206
|
+
return (async function* () {
|
|
207
|
+
try {
|
|
208
|
+
let lastError = new Error('Request failed after all retries.');
|
|
209
|
+
for (let attempt = 0; attempt < INVALID_CONTENT_RETRY_OPTIONS.maxAttempts; attempt++) {
|
|
210
|
+
try {
|
|
211
|
+
if (attempt > 0) {
|
|
212
|
+
yield { type: StreamEventType.RETRY };
|
|
213
|
+
}
|
|
214
|
+
const stream = await self.makeApiCallAndProcessStream(model, requestContents, params, prompt_id);
|
|
215
|
+
for await (const chunk of stream) {
|
|
216
|
+
yield { type: StreamEventType.CHUNK, value: chunk };
|
|
217
|
+
}
|
|
218
|
+
lastError = null;
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
lastError = error;
|
|
223
|
+
const isContentError = error instanceof InvalidStreamError;
|
|
224
|
+
if (isContentError) {
|
|
225
|
+
// Check if we have more attempts left.
|
|
226
|
+
if (attempt < INVALID_CONTENT_RETRY_OPTIONS.maxAttempts - 1) {
|
|
227
|
+
logContentRetry(self.config, new ContentRetryEvent(attempt, error.type, INVALID_CONTENT_RETRY_OPTIONS.initialDelayMs, model));
|
|
228
|
+
await new Promise((res) => setTimeout(res, INVALID_CONTENT_RETRY_OPTIONS.initialDelayMs *
|
|
229
|
+
(attempt + 1)));
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
break;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (lastError) {
|
|
237
|
+
if (lastError instanceof InvalidStreamError) {
|
|
238
|
+
logContentRetryFailure(self.config, new ContentRetryFailureEvent(INVALID_CONTENT_RETRY_OPTIONS.maxAttempts, lastError.type, model));
|
|
239
|
+
}
|
|
240
|
+
throw lastError;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
finally {
|
|
244
|
+
streamDoneResolver();
|
|
245
|
+
}
|
|
246
|
+
})();
|
|
247
|
+
}
|
|
248
|
+
async makeApiCallAndProcessStream(model, requestContents, params, prompt_id) {
|
|
249
|
+
const apiCall = () => {
|
|
250
|
+
const modelToUse = getEffectiveModel(this.config.isInFallbackMode(), model);
|
|
251
|
+
if (this.config.getQuotaErrorOccurred() &&
|
|
252
|
+
modelToUse === DEFAULT_GEMINI_FLASH_MODEL) {
|
|
253
|
+
throw new Error('Please submit a new query to continue with the Flash model.');
|
|
254
|
+
}
|
|
255
|
+
return this.config.getContentGenerator().generateContentStream({
|
|
256
|
+
model: modelToUse,
|
|
257
|
+
contents: requestContents,
|
|
258
|
+
config: { ...this.generationConfig, ...params.config },
|
|
259
|
+
}, prompt_id);
|
|
260
|
+
};
|
|
261
|
+
const onPersistent429Callback = async (authType, error) => await handleFallback(this.config, model, authType, error);
|
|
262
|
+
const streamResponse = await retryWithBackoff(apiCall, {
|
|
263
|
+
shouldRetryOnError: (error) => {
|
|
264
|
+
if (error instanceof ApiError && error.message) {
|
|
265
|
+
if (error.status === 400)
|
|
266
|
+
return false;
|
|
267
|
+
if (isSchemaDepthError(error.message))
|
|
268
|
+
return false;
|
|
269
|
+
if (error.status === 429)
|
|
270
|
+
return true;
|
|
271
|
+
if (error.status >= 500 && error.status < 600)
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
return false;
|
|
275
|
+
},
|
|
276
|
+
onPersistent429: onPersistent429Callback,
|
|
277
|
+
authType: this.config.getContentGeneratorConfig()?.authType,
|
|
278
|
+
});
|
|
279
|
+
return this.processStreamResponse(model, streamResponse);
|
|
384
280
|
}
|
|
385
281
|
/**
|
|
386
282
|
* Returns the chat history.
|
|
@@ -392,7 +288,7 @@ export class GeminiChat {
|
|
|
392
288
|
* - The `curated history` contains only the valid turns between user and
|
|
393
289
|
* model, which will be included in the subsequent requests sent to the model.
|
|
394
290
|
* - The `comprehensive history` contains all turns, including invalid or
|
|
395
|
-
*
|
|
291
|
+
* empty model outputs, providing a complete record of the history.
|
|
396
292
|
*
|
|
397
293
|
* The history is updated after receiving the response from the model,
|
|
398
294
|
* for streaming response, it means receiving the last chunk of the response.
|
|
@@ -401,9 +297,9 @@ export class GeminiChat {
|
|
|
401
297
|
* history`, set the `curated` parameter to `true`.
|
|
402
298
|
*
|
|
403
299
|
* @param curated - whether to return the curated history or the comprehensive
|
|
404
|
-
*
|
|
300
|
+
* history.
|
|
405
301
|
* @return History contents alternating between user and model for the entire
|
|
406
|
-
*
|
|
302
|
+
* chat session.
|
|
407
303
|
*/
|
|
408
304
|
getHistory(curated = false) {
|
|
409
305
|
const history = curated
|
|
@@ -421,8 +317,6 @@ export class GeminiChat {
|
|
|
421
317
|
}
|
|
422
318
|
/**
|
|
423
319
|
* Adds a new entry to the chat history.
|
|
424
|
-
*
|
|
425
|
-
* @param content - The content to add to the history.
|
|
426
320
|
*/
|
|
427
321
|
addHistory(content) {
|
|
428
322
|
this.history.push(content);
|
|
@@ -430,6 +324,22 @@ export class GeminiChat {
|
|
|
430
324
|
setHistory(history) {
|
|
431
325
|
this.history = history;
|
|
432
326
|
}
|
|
327
|
+
stripThoughtsFromHistory() {
|
|
328
|
+
this.history = this.history.map((content) => {
|
|
329
|
+
const newContent = { ...content };
|
|
330
|
+
if (newContent.parts) {
|
|
331
|
+
newContent.parts = newContent.parts.map((part) => {
|
|
332
|
+
if (part && typeof part === 'object' && 'thoughtSignature' in part) {
|
|
333
|
+
const newPart = { ...part };
|
|
334
|
+
delete newPart.thoughtSignature;
|
|
335
|
+
return newPart;
|
|
336
|
+
}
|
|
337
|
+
return part;
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
return newContent;
|
|
341
|
+
});
|
|
342
|
+
}
|
|
433
343
|
setTools(tools) {
|
|
434
344
|
this.generationConfig.tools = tools;
|
|
435
345
|
}
|
|
@@ -455,122 +365,156 @@ export class GeminiChat {
|
|
|
455
365
|
}
|
|
456
366
|
}
|
|
457
367
|
}
|
|
458
|
-
async *processStreamResponse(
|
|
459
|
-
const
|
|
460
|
-
|
|
461
|
-
let
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
}
|
|
472
|
-
outputContent.push(content);
|
|
368
|
+
async *processStreamResponse(model, streamResponse) {
|
|
369
|
+
const modelResponseParts = [];
|
|
370
|
+
let hasToolCall = false;
|
|
371
|
+
let hasFinishReason = false;
|
|
372
|
+
for await (const chunk of this.stopBeforeSecondMutator(streamResponse)) {
|
|
373
|
+
hasFinishReason =
|
|
374
|
+
chunk?.candidates?.some((candidate) => candidate.finishReason) ?? false;
|
|
375
|
+
if (isValidResponse(chunk)) {
|
|
376
|
+
const content = chunk.candidates?.[0]?.content;
|
|
377
|
+
if (content?.parts) {
|
|
378
|
+
if (content.parts.some((part) => part.thought)) {
|
|
379
|
+
// Record thoughts
|
|
380
|
+
this.recordThoughtFromContent(content);
|
|
473
381
|
}
|
|
382
|
+
if (content.parts.some((part) => part.functionCall)) {
|
|
383
|
+
hasToolCall = true;
|
|
384
|
+
}
|
|
385
|
+
modelResponseParts.push(...content.parts.filter((part) => !part.thought));
|
|
474
386
|
}
|
|
475
|
-
yield chunk;
|
|
476
387
|
}
|
|
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);
|
|
388
|
+
// Record token usage if this chunk has usageMetadata
|
|
389
|
+
if (chunk.usageMetadata) {
|
|
390
|
+
this.chatRecordingService.recordMessageTokens(chunk.usageMetadata);
|
|
391
|
+
if (chunk.usageMetadata.promptTokenCount !== undefined) {
|
|
392
|
+
uiTelemetryService.setLastPromptTokenCount(chunk.usageMetadata.promptTokenCount);
|
|
487
393
|
}
|
|
488
394
|
}
|
|
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
|
-
});
|
|
395
|
+
yield chunk; // Yield every chunk to the UI immediately.
|
|
396
|
+
}
|
|
397
|
+
// String thoughts and consolidate text parts.
|
|
398
|
+
const consolidatedParts = [];
|
|
399
|
+
for (const part of modelResponseParts) {
|
|
400
|
+
const lastPart = consolidatedParts[consolidatedParts.length - 1];
|
|
401
|
+
if (lastPart?.text &&
|
|
402
|
+
isValidNonThoughtTextPart(lastPart) &&
|
|
403
|
+
isValidNonThoughtTextPart(part)) {
|
|
404
|
+
lastPart.text += part.text;
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
consolidatedParts.push(part);
|
|
512
408
|
}
|
|
513
409
|
}
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
410
|
+
const responseText = consolidatedParts
|
|
411
|
+
.filter((part) => part.text)
|
|
412
|
+
.map((part) => part.text)
|
|
413
|
+
.join('')
|
|
414
|
+
.trim();
|
|
415
|
+
// Record model response text from the collected parts
|
|
416
|
+
if (responseText) {
|
|
417
|
+
this.chatRecordingService.recordMessage({
|
|
418
|
+
model,
|
|
419
|
+
type: 'gemini',
|
|
420
|
+
content: responseText,
|
|
421
|
+
});
|
|
520
422
|
}
|
|
521
|
-
//
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
lastContent.parts[0].text += content.parts[0].text || '';
|
|
532
|
-
if (content.parts.length > 1) {
|
|
533
|
-
lastContent.parts.push(...content.parts.slice(1));
|
|
534
|
-
}
|
|
423
|
+
// Stream validation logic: A stream is considered successful if:
|
|
424
|
+
// 1. There's a tool call (tool calls can end without explicit finish reasons), OR
|
|
425
|
+
// 2. There's a finish reason AND we have non-empty response text
|
|
426
|
+
//
|
|
427
|
+
// We throw an error only when there's no tool call AND:
|
|
428
|
+
// - No finish reason, OR
|
|
429
|
+
// - Empty response text (e.g., only thoughts with no actual content)
|
|
430
|
+
if (!hasToolCall && (!hasFinishReason || !responseText)) {
|
|
431
|
+
if (!hasFinishReason) {
|
|
432
|
+
throw new InvalidStreamError('Model stream ended without a finish reason.', 'NO_FINISH_REASON');
|
|
535
433
|
}
|
|
536
434
|
else {
|
|
537
|
-
|
|
435
|
+
throw new InvalidStreamError('Model stream ended with empty response text.', 'NO_RESPONSE_TEXT');
|
|
538
436
|
}
|
|
539
437
|
}
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
438
|
+
this.history.push({ role: 'model', parts: consolidatedParts });
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Gets the chat recording service instance.
|
|
442
|
+
*/
|
|
443
|
+
getChatRecordingService() {
|
|
444
|
+
return this.chatRecordingService;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Extracts and records thought from thought content.
|
|
448
|
+
*/
|
|
449
|
+
recordThoughtFromContent(content) {
|
|
450
|
+
if (!content.parts || content.parts.length === 0) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
const thoughtPart = content.parts[0];
|
|
454
|
+
if (thoughtPart.text) {
|
|
455
|
+
// Extract subject and description using the same logic as turn.ts
|
|
456
|
+
const rawText = thoughtPart.text;
|
|
457
|
+
const subjectStringMatches = rawText.match(/\*\*(.*?)\*\*/s);
|
|
458
|
+
const subject = subjectStringMatches
|
|
459
|
+
? subjectStringMatches[1].trim()
|
|
460
|
+
: '';
|
|
461
|
+
const description = rawText.replace(/\*\*(.*?)\*\*/s, '').trim();
|
|
462
|
+
this.chatRecordingService.recordThought({
|
|
463
|
+
subject,
|
|
464
|
+
description,
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
/**
|
|
469
|
+
* Truncates the chunkStream right before the second function call to a
|
|
470
|
+
* function that mutates state. This may involve trimming parts from a chunk
|
|
471
|
+
* as well as omtting some chunks altogether.
|
|
472
|
+
*
|
|
473
|
+
* We do this because it improves tool call quality if the model gets
|
|
474
|
+
* feedback from one mutating function call before it makes the next one.
|
|
475
|
+
*/
|
|
476
|
+
async *stopBeforeSecondMutator(chunkStream) {
|
|
477
|
+
let foundMutatorFunctionCall = false;
|
|
478
|
+
for await (const chunk of chunkStream) {
|
|
479
|
+
const candidate = chunk.candidates?.[0];
|
|
480
|
+
const content = candidate?.content;
|
|
481
|
+
if (!candidate || !content?.parts) {
|
|
482
|
+
yield chunk;
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
const truncatedParts = [];
|
|
486
|
+
for (const part of content.parts) {
|
|
487
|
+
if (this.isMutatorFunctionCall(part)) {
|
|
488
|
+
if (foundMutatorFunctionCall) {
|
|
489
|
+
// This is the second mutator call.
|
|
490
|
+
// Truncate and return immedaitely.
|
|
491
|
+
const newChunk = new GenerateContentResponse();
|
|
492
|
+
newChunk.candidates = [
|
|
493
|
+
{
|
|
494
|
+
...candidate,
|
|
495
|
+
content: {
|
|
496
|
+
...content,
|
|
497
|
+
parts: truncatedParts,
|
|
498
|
+
},
|
|
499
|
+
finishReason: FinishReason.STOP,
|
|
500
|
+
},
|
|
501
|
+
];
|
|
502
|
+
yield newChunk;
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
foundMutatorFunctionCall = true;
|
|
553
506
|
}
|
|
554
|
-
|
|
507
|
+
truncatedParts.push(part);
|
|
555
508
|
}
|
|
556
|
-
|
|
509
|
+
yield chunk;
|
|
557
510
|
}
|
|
558
511
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
content.parts[0].text !== '');
|
|
566
|
-
}
|
|
567
|
-
isThoughtContent(content) {
|
|
568
|
-
return !!(content &&
|
|
569
|
-
content.role === 'model' &&
|
|
570
|
-
content.parts &&
|
|
571
|
-
content.parts.length > 0 &&
|
|
572
|
-
typeof content.parts[0].thought === 'boolean' &&
|
|
573
|
-
content.parts[0].thought === true);
|
|
512
|
+
isMutatorFunctionCall(part) {
|
|
513
|
+
if (!part?.functionCall?.name) {
|
|
514
|
+
return false;
|
|
515
|
+
}
|
|
516
|
+
const tool = this.config.getToolRegistry().getTool(part.functionCall.name);
|
|
517
|
+
return !!tool && MUTATOR_KINDS.includes(tool.kind);
|
|
574
518
|
}
|
|
575
519
|
}
|
|
576
520
|
/** Visible for Testing */
|