@google/gemini-cli-core 0.0.3-preview.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/LICENSE +202 -0
- package/README.md +310 -0
- package/dist/.last_build +0 -0
- package/dist/google-gemini-cli-core-0.3.0-preview.3.tgz +0 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/src/__mocks__/fs/promises.d.ts +11 -0
- package/dist/src/__mocks__/fs/promises.js +17 -0
- package/dist/src/__mocks__/fs/promises.js.map +1 -0
- package/dist/src/code_assist/codeAssist.d.ts +10 -0
- package/dist/src/code_assist/codeAssist.js +19 -0
- package/dist/src/code_assist/codeAssist.js.map +1 -0
- package/dist/src/code_assist/converter.d.ts +72 -0
- package/dist/src/code_assist/converter.js +159 -0
- package/dist/src/code_assist/converter.js.map +1 -0
- package/dist/src/code_assist/converter.test.d.ts +6 -0
- package/dist/src/code_assist/converter.test.js +362 -0
- package/dist/src/code_assist/converter.test.js.map +1 -0
- package/dist/src/code_assist/oauth2.d.ts +22 -0
- package/dist/src/code_assist/oauth2.js +353 -0
- package/dist/src/code_assist/oauth2.js.map +1 -0
- package/dist/src/code_assist/oauth2.test.d.ts +6 -0
- package/dist/src/code_assist/oauth2.test.js +427 -0
- package/dist/src/code_assist/oauth2.test.js.map +1 -0
- package/dist/src/code_assist/server.d.ts +37 -0
- package/dist/src/code_assist/server.js +125 -0
- package/dist/src/code_assist/server.js.map +1 -0
- package/dist/src/code_assist/server.test.d.ts +6 -0
- package/dist/src/code_assist/server.test.js +134 -0
- package/dist/src/code_assist/server.test.js.map +1 -0
- package/dist/src/code_assist/setup.d.ts +20 -0
- package/dist/src/code_assist/setup.js +101 -0
- package/dist/src/code_assist/setup.js.map +1 -0
- package/dist/src/code_assist/setup.test.d.ts +6 -0
- package/dist/src/code_assist/setup.test.js +171 -0
- package/dist/src/code_assist/setup.test.js.map +1 -0
- package/dist/src/code_assist/types.d.ts +148 -0
- package/dist/src/code_assist/types.js +46 -0
- package/dist/src/code_assist/types.js.map +1 -0
- package/dist/src/config/config.d.ts +318 -0
- package/dist/src/config/config.js +633 -0
- package/dist/src/config/config.js.map +1 -0
- package/dist/src/config/config.test.d.ts +6 -0
- package/dist/src/config/config.test.js +585 -0
- package/dist/src/config/config.test.js.map +1 -0
- package/dist/src/config/flashFallback.test.d.ts +6 -0
- package/dist/src/config/flashFallback.test.js +87 -0
- package/dist/src/config/flashFallback.test.js.map +1 -0
- package/dist/src/config/models.d.ts +9 -0
- package/dist/src/config/models.js +10 -0
- package/dist/src/config/models.js.map +1 -0
- package/dist/src/config/storage.d.ts +32 -0
- package/dist/src/config/storage.js +90 -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 +43 -0
- package/dist/src/config/storage.test.js.map +1 -0
- package/dist/src/core/client.d.ts +65 -0
- package/dist/src/core/client.js +689 -0
- package/dist/src/core/client.js.map +1 -0
- package/dist/src/core/client.test.d.ts +6 -0
- package/dist/src/core/client.test.js +1857 -0
- package/dist/src/core/client.test.js.map +1 -0
- package/dist/src/core/contentGenerator.d.ts +33 -0
- package/dist/src/core/contentGenerator.js +80 -0
- package/dist/src/core/contentGenerator.js.map +1 -0
- package/dist/src/core/contentGenerator.test.d.ts +6 -0
- package/dist/src/core/contentGenerator.test.js +124 -0
- package/dist/src/core/contentGenerator.test.js.map +1 -0
- package/dist/src/core/coreToolScheduler.d.ts +126 -0
- package/dist/src/core/coreToolScheduler.js +605 -0
- package/dist/src/core/coreToolScheduler.js.map +1 -0
- package/dist/src/core/coreToolScheduler.test.d.ts +6 -0
- package/dist/src/core/coreToolScheduler.test.js +923 -0
- package/dist/src/core/coreToolScheduler.test.js.map +1 -0
- package/dist/src/core/geminiChat.d.ts +122 -0
- package/dist/src/core/geminiChat.js +547 -0
- package/dist/src/core/geminiChat.js.map +1 -0
- package/dist/src/core/geminiChat.test.d.ts +6 -0
- package/dist/src/core/geminiChat.test.js +875 -0
- package/dist/src/core/geminiChat.test.js.map +1 -0
- package/dist/src/core/geminiRequest.d.ts +13 -0
- package/dist/src/core/geminiRequest.js +11 -0
- package/dist/src/core/geminiRequest.js.map +1 -0
- package/dist/src/core/logger.d.ts +60 -0
- package/dist/src/core/logger.js +360 -0
- package/dist/src/core/logger.js.map +1 -0
- package/dist/src/core/logger.test.d.ts +6 -0
- package/dist/src/core/logger.test.js +534 -0
- package/dist/src/core/logger.test.js.map +1 -0
- package/dist/src/core/loggingContentGenerator.d.ts +25 -0
- package/dist/src/core/loggingContentGenerator.js +97 -0
- package/dist/src/core/loggingContentGenerator.js.map +1 -0
- package/dist/src/core/nonInteractiveToolExecutor.d.ts +10 -0
- package/dist/src/core/nonInteractiveToolExecutor.js +24 -0
- package/dist/src/core/nonInteractiveToolExecutor.js.map +1 -0
- package/dist/src/core/nonInteractiveToolExecutor.test.d.ts +6 -0
- package/dist/src/core/nonInteractiveToolExecutor.test.js +236 -0
- package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -0
- package/dist/src/core/prompts.d.ts +12 -0
- package/dist/src/core/prompts.js +359 -0
- package/dist/src/core/prompts.js.map +1 -0
- package/dist/src/core/prompts.test.d.ts +6 -0
- package/dist/src/core/prompts.test.js +214 -0
- package/dist/src/core/prompts.test.js.map +1 -0
- package/dist/src/core/subagent.d.ts +236 -0
- package/dist/src/core/subagent.js +485 -0
- package/dist/src/core/subagent.js.map +1 -0
- package/dist/src/core/subagent.test.d.ts +6 -0
- package/dist/src/core/subagent.test.js +520 -0
- package/dist/src/core/subagent.test.js.map +1 -0
- package/dist/src/core/tokenLimits.d.ts +10 -0
- package/dist/src/core/tokenLimits.js +28 -0
- package/dist/src/core/tokenLimits.js.map +1 -0
- package/dist/src/core/turn.d.ts +125 -0
- package/dist/src/core/turn.js +154 -0
- package/dist/src/core/turn.js.map +1 -0
- package/dist/src/core/turn.test.d.ts +6 -0
- package/dist/src/core/turn.test.js +388 -0
- package/dist/src/core/turn.test.js.map +1 -0
- package/dist/src/generated/git-commit.d.ts +7 -0
- package/dist/src/generated/git-commit.js +10 -0
- package/dist/src/generated/git-commit.js.map +1 -0
- package/dist/src/ide/constants.d.ts +6 -0
- package/dist/src/ide/constants.js +7 -0
- package/dist/src/ide/constants.js.map +1 -0
- package/dist/src/ide/detect-ide.d.ts +25 -0
- package/dist/src/ide/detect-ide.js +104 -0
- package/dist/src/ide/detect-ide.js.map +1 -0
- package/dist/src/ide/detect-ide.test.d.ts +6 -0
- package/dist/src/ide/detect-ide.test.js +109 -0
- package/dist/src/ide/detect-ide.test.js.map +1 -0
- package/dist/src/ide/ide-client.d.ts +67 -0
- package/dist/src/ide/ide-client.js +418 -0
- package/dist/src/ide/ide-client.js.map +1 -0
- package/dist/src/ide/ide-client.test.d.ts +6 -0
- package/dist/src/ide/ide-client.test.js +155 -0
- package/dist/src/ide/ide-client.test.js.map +1 -0
- package/dist/src/ide/ide-installer.d.ts +14 -0
- package/dist/src/ide/ide-installer.js +107 -0
- package/dist/src/ide/ide-installer.js.map +1 -0
- package/dist/src/ide/ide-installer.test.d.ts +6 -0
- package/dist/src/ide/ide-installer.test.js +113 -0
- package/dist/src/ide/ide-installer.test.js.map +1 -0
- package/dist/src/ide/ideContext.d.ts +374 -0
- package/dist/src/ide/ideContext.js +147 -0
- package/dist/src/ide/ideContext.js.map +1 -0
- package/dist/src/ide/ideContext.test.d.ts +6 -0
- package/dist/src/ide/ideContext.test.js +265 -0
- package/dist/src/ide/ideContext.test.js.map +1 -0
- package/dist/src/ide/process-utils.d.ts +22 -0
- package/dist/src/ide/process-utils.js +153 -0
- package/dist/src/ide/process-utils.js.map +1 -0
- package/dist/src/ide/process-utils.test.d.ts +6 -0
- package/dist/src/ide/process-utils.test.js +72 -0
- package/dist/src/ide/process-utils.test.js.map +1 -0
- package/dist/src/index.d.ts +81 -0
- package/dist/src/index.js +90 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/index.test.d.ts +6 -0
- package/dist/src/index.test.js +12 -0
- package/dist/src/index.test.js.map +1 -0
- package/dist/src/mcp/google-auth-provider.d.ts +23 -0
- package/dist/src/mcp/google-auth-provider.js +72 -0
- package/dist/src/mcp/google-auth-provider.js.map +1 -0
- package/dist/src/mcp/google-auth-provider.test.d.ts +6 -0
- package/dist/src/mcp/google-auth-provider.test.js +89 -0
- package/dist/src/mcp/google-auth-provider.test.js.map +1 -0
- package/dist/src/mcp/oauth-provider.d.ts +146 -0
- package/dist/src/mcp/oauth-provider.js +601 -0
- package/dist/src/mcp/oauth-provider.js.map +1 -0
- package/dist/src/mcp/oauth-provider.test.d.ts +6 -0
- package/dist/src/mcp/oauth-provider.test.js +672 -0
- package/dist/src/mcp/oauth-provider.test.js.map +1 -0
- package/dist/src/mcp/oauth-token-storage.d.ts +61 -0
- package/dist/src/mcp/oauth-token-storage.js +148 -0
- package/dist/src/mcp/oauth-token-storage.js.map +1 -0
- package/dist/src/mcp/oauth-token-storage.test.d.ts +6 -0
- package/dist/src/mcp/oauth-token-storage.test.js +206 -0
- package/dist/src/mcp/oauth-token-storage.test.js.map +1 -0
- package/dist/src/mcp/oauth-utils.d.ts +119 -0
- package/dist/src/mcp/oauth-utils.js +235 -0
- package/dist/src/mcp/oauth-utils.js.map +1 -0
- package/dist/src/mcp/oauth-utils.test.d.ts +6 -0
- package/dist/src/mcp/oauth-utils.test.js +199 -0
- package/dist/src/mcp/oauth-utils.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/types.d.ts +34 -0
- package/dist/src/mcp/token-storage/types.js +7 -0
- package/dist/src/mcp/token-storage/types.js.map +1 -0
- package/dist/src/mocks/msw.d.ts +6 -0
- package/dist/src/mocks/msw.js +8 -0
- package/dist/src/mocks/msw.js.map +1 -0
- package/dist/src/prompts/mcp-prompts.d.ts +8 -0
- package/dist/src/prompts/mcp-prompts.js +13 -0
- package/dist/src/prompts/mcp-prompts.js.map +1 -0
- package/dist/src/prompts/prompt-registry.d.ts +34 -0
- package/dist/src/prompts/prompt-registry.js +63 -0
- package/dist/src/prompts/prompt-registry.js.map +1 -0
- package/dist/src/services/chatRecordingService.d.ts +150 -0
- package/dist/src/services/chatRecordingService.js +321 -0
- package/dist/src/services/chatRecordingService.js.map +1 -0
- package/dist/src/services/chatRecordingService.test.d.ts +6 -0
- package/dist/src/services/chatRecordingService.test.js +290 -0
- package/dist/src/services/chatRecordingService.test.js.map +1 -0
- package/dist/src/services/fileDiscoveryService.d.ts +35 -0
- package/dist/src/services/fileDiscoveryService.js +91 -0
- package/dist/src/services/fileDiscoveryService.js.map +1 -0
- package/dist/src/services/fileDiscoveryService.test.d.ts +6 -0
- package/dist/src/services/fileDiscoveryService.test.js +143 -0
- package/dist/src/services/fileDiscoveryService.test.js.map +1 -0
- package/dist/src/services/fileSystemService.d.ts +31 -0
- package/dist/src/services/fileSystemService.js +18 -0
- package/dist/src/services/fileSystemService.js.map +1 -0
- package/dist/src/services/fileSystemService.test.d.ts +6 -0
- package/dist/src/services/fileSystemService.test.js +41 -0
- package/dist/src/services/fileSystemService.test.js.map +1 -0
- package/dist/src/services/gitService.d.ts +23 -0
- package/dist/src/services/gitService.js +110 -0
- package/dist/src/services/gitService.js.map +1 -0
- package/dist/src/services/gitService.test.d.ts +6 -0
- package/dist/src/services/gitService.test.js +212 -0
- package/dist/src/services/gitService.test.js.map +1 -0
- package/dist/src/services/loopDetectionService.d.ts +98 -0
- package/dist/src/services/loopDetectionService.js +363 -0
- package/dist/src/services/loopDetectionService.js.map +1 -0
- package/dist/src/services/loopDetectionService.test.d.ts +6 -0
- package/dist/src/services/loopDetectionService.test.js +558 -0
- package/dist/src/services/loopDetectionService.test.js.map +1 -0
- package/dist/src/services/shellExecutionService.d.ts +68 -0
- package/dist/src/services/shellExecutionService.js +332 -0
- package/dist/src/services/shellExecutionService.js.map +1 -0
- package/dist/src/services/shellExecutionService.test.d.ts +6 -0
- package/dist/src/services/shellExecutionService.test.js +517 -0
- package/dist/src/services/shellExecutionService.test.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +121 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +773 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.d.ts +17 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +407 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +90 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +229 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -0
- package/dist/src/telemetry/constants.d.ts +32 -0
- package/dist/src/telemetry/constants.js +33 -0
- package/dist/src/telemetry/constants.js.map +1 -0
- package/dist/src/telemetry/file-exporters.d.ts +29 -0
- package/dist/src/telemetry/file-exporters.js +62 -0
- package/dist/src/telemetry/file-exporters.js.map +1 -0
- package/dist/src/telemetry/index.d.ts +21 -0
- package/dist/src/telemetry/index.js +21 -0
- package/dist/src/telemetry/index.js.map +1 -0
- package/dist/src/telemetry/integration.test.circular.d.ts +6 -0
- package/dist/src/telemetry/integration.test.circular.js +54 -0
- package/dist/src/telemetry/integration.test.circular.js.map +1 -0
- package/dist/src/telemetry/loggers.d.ts +26 -0
- package/dist/src/telemetry/loggers.js +404 -0
- package/dist/src/telemetry/loggers.js.map +1 -0
- package/dist/src/telemetry/loggers.test.circular.d.ts +6 -0
- package/dist/src/telemetry/loggers.test.circular.js +107 -0
- package/dist/src/telemetry/loggers.test.circular.js.map +1 -0
- package/dist/src/telemetry/loggers.test.d.ts +6 -0
- package/dist/src/telemetry/loggers.test.js +658 -0
- package/dist/src/telemetry/loggers.test.js.map +1 -0
- package/dist/src/telemetry/metrics.d.ts +36 -0
- package/dist/src/telemetry/metrics.js +208 -0
- package/dist/src/telemetry/metrics.js.map +1 -0
- package/dist/src/telemetry/metrics.test.d.ts +6 -0
- package/dist/src/telemetry/metrics.test.js +242 -0
- package/dist/src/telemetry/metrics.test.js.map +1 -0
- package/dist/src/telemetry/sdk.d.ts +9 -0
- package/dist/src/telemetry/sdk.js +163 -0
- package/dist/src/telemetry/sdk.js.map +1 -0
- package/dist/src/telemetry/sdk.test.d.ts +6 -0
- package/dist/src/telemetry/sdk.test.js +82 -0
- package/dist/src/telemetry/sdk.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 +40 -0
- package/dist/src/telemetry/telemetry-utils.test.js.map +1 -0
- package/dist/src/telemetry/telemetry.test.d.ts +6 -0
- package/dist/src/telemetry/telemetry.test.js +50 -0
- package/dist/src/telemetry/telemetry.test.js.map +1 -0
- package/dist/src/telemetry/tool-call-decision.d.ts +13 -0
- package/dist/src/telemetry/tool-call-decision.js +29 -0
- package/dist/src/telemetry/tool-call-decision.js.map +1 -0
- package/dist/src/telemetry/types.d.ts +220 -0
- package/dist/src/telemetry/types.js +383 -0
- package/dist/src/telemetry/types.js.map +1 -0
- package/dist/src/telemetry/uiTelemetry.d.ts +75 -0
- package/dist/src/telemetry/uiTelemetry.js +153 -0
- package/dist/src/telemetry/uiTelemetry.js.map +1 -0
- package/dist/src/telemetry/uiTelemetry.test.d.ts +6 -0
- package/dist/src/telemetry/uiTelemetry.test.js +558 -0
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -0
- package/dist/src/test-utils/config.d.ts +17 -0
- package/dist/src/test-utils/config.js +32 -0
- package/dist/src/test-utils/config.js.map +1 -0
- package/dist/src/test-utils/mockWorkspaceContext.d.ts +13 -0
- package/dist/src/test-utils/mockWorkspaceContext.js +24 -0
- package/dist/src/test-utils/mockWorkspaceContext.js.map +1 -0
- package/dist/src/test-utils/tools.d.ts +45 -0
- package/dist/src/test-utils/tools.js +105 -0
- package/dist/src/test-utils/tools.js.map +1 -0
- package/dist/src/tools/diffOptions.d.ts +9 -0
- package/dist/src/tools/diffOptions.js +38 -0
- package/dist/src/tools/diffOptions.js.map +1 -0
- package/dist/src/tools/diffOptions.test.d.ts +6 -0
- package/dist/src/tools/diffOptions.test.js +119 -0
- package/dist/src/tools/diffOptions.test.js.map +1 -0
- package/dist/src/tools/edit.d.ts +56 -0
- package/dist/src/tools/edit.js +423 -0
- package/dist/src/tools/edit.js.map +1 -0
- package/dist/src/tools/edit.test.d.ts +6 -0
- package/dist/src/tools/edit.test.js +713 -0
- package/dist/src/tools/edit.test.js.map +1 -0
- package/dist/src/tools/glob.d.ts +52 -0
- package/dist/src/tools/glob.js +236 -0
- package/dist/src/tools/glob.js.map +1 -0
- package/dist/src/tools/glob.test.d.ts +6 -0
- package/dist/src/tools/glob.test.js +375 -0
- package/dist/src/tools/glob.test.js.map +1 -0
- package/dist/src/tools/grep.d.ts +47 -0
- package/dist/src/tools/grep.js +517 -0
- package/dist/src/tools/grep.js.map +1 -0
- package/dist/src/tools/grep.test.d.ts +6 -0
- package/dist/src/tools/grep.test.js +295 -0
- package/dist/src/tools/grep.test.js.map +1 -0
- package/dist/src/tools/ls.d.ts +68 -0
- package/dist/src/tools/ls.js +227 -0
- package/dist/src/tools/ls.js.map +1 -0
- package/dist/src/tools/ls.test.d.ts +6 -0
- package/dist/src/tools/ls.test.js +389 -0
- package/dist/src/tools/ls.test.js.map +1 -0
- package/dist/src/tools/mcp-client-manager.d.ts +38 -0
- package/dist/src/tools/mcp-client-manager.js +74 -0
- package/dist/src/tools/mcp-client-manager.js.map +1 -0
- package/dist/src/tools/mcp-client-manager.test.d.ts +6 -0
- package/dist/src/tools/mcp-client-manager.test.js +39 -0
- package/dist/src/tools/mcp-client-manager.test.js.map +1 -0
- package/dist/src/tools/mcp-client.d.ts +199 -0
- package/dist/src/tools/mcp-client.js +995 -0
- package/dist/src/tools/mcp-client.js.map +1 -0
- package/dist/src/tools/mcp-client.test.d.ts +6 -0
- package/dist/src/tools/mcp-client.test.js +454 -0
- package/dist/src/tools/mcp-client.test.js.map +1 -0
- package/dist/src/tools/mcp-tool.d.ts +23 -0
- package/dist/src/tools/mcp-tool.js +240 -0
- package/dist/src/tools/mcp-tool.js.map +1 -0
- package/dist/src/tools/mcp-tool.test.d.ts +6 -0
- package/dist/src/tools/mcp-tool.test.js +576 -0
- package/dist/src/tools/mcp-tool.test.js.map +1 -0
- package/dist/src/tools/memoryTool.d.ts +40 -0
- package/dist/src/tools/memoryTool.js +296 -0
- package/dist/src/tools/memoryTool.js.map +1 -0
- package/dist/src/tools/memoryTool.test.d.ts +6 -0
- package/dist/src/tools/memoryTool.test.js +298 -0
- package/dist/src/tools/memoryTool.test.js.map +1 -0
- package/dist/src/tools/modifiable-tool.d.ts +32 -0
- package/dist/src/tools/modifiable-tool.js +88 -0
- package/dist/src/tools/modifiable-tool.js.map +1 -0
- package/dist/src/tools/modifiable-tool.test.d.ts +6 -0
- package/dist/src/tools/modifiable-tool.test.js +193 -0
- package/dist/src/tools/modifiable-tool.test.js.map +1 -0
- package/dist/src/tools/read-file.d.ts +35 -0
- package/dist/src/tools/read-file.js +127 -0
- package/dist/src/tools/read-file.js.map +1 -0
- package/dist/src/tools/read-file.test.d.ts +6 -0
- package/dist/src/tools/read-file.test.js +311 -0
- package/dist/src/tools/read-file.test.js.map +1 -0
- package/dist/src/tools/read-many-files.d.ts +60 -0
- package/dist/src/tools/read-many-files.js +414 -0
- package/dist/src/tools/read-many-files.js.map +1 -0
- package/dist/src/tools/read-many-files.test.d.ts +6 -0
- package/dist/src/tools/read-many-files.test.js +565 -0
- package/dist/src/tools/read-many-files.test.js.map +1 -0
- package/dist/src/tools/ripGrep.d.ts +47 -0
- package/dist/src/tools/ripGrep.js +368 -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 +874 -0
- package/dist/src/tools/ripGrep.test.js.map +1 -0
- package/dist/src/tools/shell.d.ts +22 -0
- package/dist/src/tools/shell.js +320 -0
- package/dist/src/tools/shell.js.map +1 -0
- package/dist/src/tools/shell.test.d.ts +6 -0
- package/dist/src/tools/shell.test.js +336 -0
- package/dist/src/tools/shell.test.js.map +1 -0
- package/dist/src/tools/tool-error.d.ts +43 -0
- package/dist/src/tools/tool-error.js +58 -0
- package/dist/src/tools/tool-error.js.map +1 -0
- package/dist/src/tools/tool-registry.d.ts +86 -0
- package/dist/src/tools/tool-registry.js +369 -0
- package/dist/src/tools/tool-registry.js.map +1 -0
- package/dist/src/tools/tool-registry.test.d.ts +6 -0
- package/dist/src/tools/tool-registry.test.js +332 -0
- package/dist/src/tools/tool-registry.test.js.map +1 -0
- package/dist/src/tools/tools.d.ts +274 -0
- package/dist/src/tools/tools.js +250 -0
- package/dist/src/tools/tools.js.map +1 -0
- package/dist/src/tools/tools.test.d.ts +6 -0
- package/dist/src/tools/tools.test.js +205 -0
- package/dist/src/tools/tools.test.js.map +1 -0
- package/dist/src/tools/web-fetch.d.ts +27 -0
- package/dist/src/tools/web-fetch.js +243 -0
- package/dist/src/tools/web-fetch.js.map +1 -0
- package/dist/src/tools/web-fetch.test.d.ts +6 -0
- package/dist/src/tools/web-fetch.test.js +114 -0
- package/dist/src/tools/web-fetch.test.js.map +1 -0
- package/dist/src/tools/web-search.d.ts +49 -0
- package/dist/src/tools/web-search.js +137 -0
- package/dist/src/tools/web-search.js.map +1 -0
- package/dist/src/tools/web-search.test.d.ts +6 -0
- package/dist/src/tools/web-search.test.js +207 -0
- package/dist/src/tools/web-search.test.js.map +1 -0
- package/dist/src/tools/write-file.d.ts +52 -0
- package/dist/src/tools/write-file.js +314 -0
- package/dist/src/tools/write-file.js.map +1 -0
- package/dist/src/tools/write-file.test.d.ts +6 -0
- package/dist/src/tools/write-file.test.js +531 -0
- package/dist/src/tools/write-file.test.js.map +1 -0
- package/dist/src/utils/LruCache.d.ts +13 -0
- package/dist/src/utils/LruCache.js +38 -0
- package/dist/src/utils/LruCache.js.map +1 -0
- package/dist/src/utils/bfsFileSearch.d.ts +24 -0
- package/dist/src/utils/bfsFileSearch.js +89 -0
- package/dist/src/utils/bfsFileSearch.js.map +1 -0
- package/dist/src/utils/bfsFileSearch.test.d.ts +6 -0
- package/dist/src/utils/bfsFileSearch.test.js +163 -0
- package/dist/src/utils/bfsFileSearch.test.js.map +1 -0
- package/dist/src/utils/browser.d.ts +13 -0
- package/dist/src/utils/browser.js +50 -0
- package/dist/src/utils/browser.js.map +1 -0
- package/dist/src/utils/editCorrector.d.ts +53 -0
- package/dist/src/utils/editCorrector.js +545 -0
- package/dist/src/utils/editCorrector.js.map +1 -0
- package/dist/src/utils/editCorrector.test.d.ts +6 -0
- package/dist/src/utils/editCorrector.test.js +564 -0
- package/dist/src/utils/editCorrector.test.js.map +1 -0
- package/dist/src/utils/editor.d.ts +28 -0
- package/dist/src/utils/editor.js +186 -0
- package/dist/src/utils/editor.js.map +1 -0
- package/dist/src/utils/editor.test.d.ts +6 -0
- package/dist/src/utils/editor.test.js +445 -0
- package/dist/src/utils/editor.test.js.map +1 -0
- package/dist/src/utils/environmentContext.d.ts +21 -0
- package/dist/src/utils/environmentContext.js +90 -0
- package/dist/src/utils/environmentContext.js.map +1 -0
- package/dist/src/utils/environmentContext.test.d.ts +6 -0
- package/dist/src/utils/environmentContext.test.js +140 -0
- package/dist/src/utils/environmentContext.test.js.map +1 -0
- package/dist/src/utils/errorParsing.d.ts +8 -0
- package/dist/src/utils/errorParsing.js +93 -0
- package/dist/src/utils/errorParsing.js.map +1 -0
- package/dist/src/utils/errorParsing.test.d.ts +6 -0
- package/dist/src/utils/errorParsing.test.js +172 -0
- package/dist/src/utils/errorParsing.test.js.map +1 -0
- package/dist/src/utils/errorReporting.d.ts +14 -0
- package/dist/src/utils/errorReporting.js +88 -0
- package/dist/src/utils/errorReporting.js.map +1 -0
- package/dist/src/utils/errorReporting.test.d.ts +6 -0
- package/dist/src/utils/errorReporting.test.js +130 -0
- package/dist/src/utils/errorReporting.test.js.map +1 -0
- package/dist/src/utils/errors.d.ts +33 -0
- package/dist/src/utils/errors.js +86 -0
- package/dist/src/utils/errors.js.map +1 -0
- package/dist/src/utils/fetch.d.ts +11 -0
- package/dist/src/utils/fetch.js +51 -0
- package/dist/src/utils/fetch.js.map +1 -0
- package/dist/src/utils/fileUtils.d.ts +52 -0
- package/dist/src/utils/fileUtils.js +283 -0
- package/dist/src/utils/fileUtils.js.map +1 -0
- package/dist/src/utils/fileUtils.test.d.ts +6 -0
- package/dist/src/utils/fileUtils.test.js +364 -0
- package/dist/src/utils/fileUtils.test.js.map +1 -0
- package/dist/src/utils/filesearch/crawlCache.d.ts +25 -0
- package/dist/src/utils/filesearch/crawlCache.js +57 -0
- package/dist/src/utils/filesearch/crawlCache.js.map +1 -0
- package/dist/src/utils/filesearch/crawlCache.test.d.ts +6 -0
- package/dist/src/utils/filesearch/crawlCache.test.js +103 -0
- package/dist/src/utils/filesearch/crawlCache.test.js.map +1 -0
- package/dist/src/utils/filesearch/crawler.d.ts +15 -0
- package/dist/src/utils/filesearch/crawler.js +50 -0
- package/dist/src/utils/filesearch/crawler.js.map +1 -0
- package/dist/src/utils/filesearch/crawler.test.d.ts +6 -0
- package/dist/src/utils/filesearch/crawler.test.js +468 -0
- package/dist/src/utils/filesearch/crawler.test.js.map +1 -0
- package/dist/src/utils/filesearch/fileSearch.d.ts +38 -0
- package/dist/src/utils/filesearch/fileSearch.js +191 -0
- package/dist/src/utils/filesearch/fileSearch.js.map +1 -0
- package/dist/src/utils/filesearch/fileSearch.test.d.ts +6 -0
- package/dist/src/utils/filesearch/fileSearch.test.js +642 -0
- package/dist/src/utils/filesearch/fileSearch.test.js.map +1 -0
- package/dist/src/utils/filesearch/ignore.d.ts +42 -0
- package/dist/src/utils/filesearch/ignore.js +106 -0
- package/dist/src/utils/filesearch/ignore.js.map +1 -0
- package/dist/src/utils/filesearch/ignore.test.d.ts +6 -0
- package/dist/src/utils/filesearch/ignore.test.js +144 -0
- package/dist/src/utils/filesearch/ignore.test.js.map +1 -0
- package/dist/src/utils/filesearch/result-cache.d.ts +33 -0
- package/dist/src/utils/filesearch/result-cache.js +59 -0
- package/dist/src/utils/filesearch/result-cache.js.map +1 -0
- package/dist/src/utils/filesearch/result-cache.test.d.ts +6 -0
- package/dist/src/utils/filesearch/result-cache.test.js +46 -0
- package/dist/src/utils/filesearch/result-cache.test.js.map +1 -0
- package/dist/src/utils/flashFallback.integration.test.d.ts +6 -0
- package/dist/src/utils/flashFallback.integration.test.js +118 -0
- package/dist/src/utils/flashFallback.integration.test.js.map +1 -0
- package/dist/src/utils/formatters.d.ts +6 -0
- package/dist/src/utils/formatters.js +16 -0
- package/dist/src/utils/formatters.js.map +1 -0
- package/dist/src/utils/generateContentResponseUtilities.d.ts +13 -0
- package/dist/src/utils/generateContentResponseUtilities.js +80 -0
- package/dist/src/utils/generateContentResponseUtilities.js.map +1 -0
- package/dist/src/utils/generateContentResponseUtilities.test.d.ts +6 -0
- package/dist/src/utils/generateContentResponseUtilities.test.js +235 -0
- package/dist/src/utils/generateContentResponseUtilities.test.js.map +1 -0
- package/dist/src/utils/getFolderStructure.d.ts +31 -0
- package/dist/src/utils/getFolderStructure.js +246 -0
- package/dist/src/utils/getFolderStructure.js.map +1 -0
- package/dist/src/utils/getFolderStructure.test.d.ts +6 -0
- package/dist/src/utils/getFolderStructure.test.js +282 -0
- package/dist/src/utils/getFolderStructure.test.js.map +1 -0
- package/dist/src/utils/getPty.d.ts +19 -0
- package/dist/src/utils/getPty.js +23 -0
- package/dist/src/utils/getPty.js.map +1 -0
- package/dist/src/utils/gitIgnoreParser.d.ts +20 -0
- package/dist/src/utils/gitIgnoreParser.js +61 -0
- package/dist/src/utils/gitIgnoreParser.js.map +1 -0
- package/dist/src/utils/gitIgnoreParser.test.d.ts +6 -0
- package/dist/src/utils/gitIgnoreParser.test.js +154 -0
- package/dist/src/utils/gitIgnoreParser.test.js.map +1 -0
- package/dist/src/utils/gitUtils.d.ts +17 -0
- package/dist/src/utils/gitUtils.js +61 -0
- package/dist/src/utils/gitUtils.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 +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/memoryDiscovery.d.ts +15 -0
- package/dist/src/utils/memoryDiscovery.js +253 -0
- package/dist/src/utils/memoryDiscovery.js.map +1 -0
- package/dist/src/utils/memoryDiscovery.test.d.ts +6 -0
- package/dist/src/utils/memoryDiscovery.test.js +219 -0
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -0
- package/dist/src/utils/memoryImportProcessor.d.ts +42 -0
- package/dist/src/utils/memoryImportProcessor.js +296 -0
- package/dist/src/utils/memoryImportProcessor.js.map +1 -0
- package/dist/src/utils/memoryImportProcessor.test.d.ts +6 -0
- package/dist/src/utils/memoryImportProcessor.test.js +573 -0
- package/dist/src/utils/memoryImportProcessor.test.js.map +1 -0
- package/dist/src/utils/messageInspectors.d.ts +8 -0
- package/dist/src/utils/messageInspectors.js +16 -0
- package/dist/src/utils/messageInspectors.js.map +1 -0
- package/dist/src/utils/nextSpeakerChecker.d.ts +12 -0
- package/dist/src/utils/nextSpeakerChecker.js +91 -0
- package/dist/src/utils/nextSpeakerChecker.js.map +1 -0
- package/dist/src/utils/nextSpeakerChecker.test.d.ts +6 -0
- package/dist/src/utils/nextSpeakerChecker.test.js +168 -0
- package/dist/src/utils/nextSpeakerChecker.test.js.map +1 -0
- package/dist/src/utils/partUtils.d.ts +35 -0
- package/dist/src/utils/partUtils.js +133 -0
- package/dist/src/utils/partUtils.js.map +1 -0
- package/dist/src/utils/partUtils.test.d.ts +6 -0
- package/dist/src/utils/partUtils.test.js +241 -0
- package/dist/src/utils/partUtils.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 +363 -0
- package/dist/src/utils/pathReader.test.js.map +1 -0
- package/dist/src/utils/paths.d.ts +58 -0
- package/dist/src/utils/paths.js +159 -0
- package/dist/src/utils/paths.js.map +1 -0
- package/dist/src/utils/paths.test.d.ts +6 -0
- package/dist/src/utils/paths.test.js +225 -0
- package/dist/src/utils/paths.test.js.map +1 -0
- package/dist/src/utils/quotaErrorDetection.d.ts +18 -0
- package/dist/src/utils/quotaErrorDetection.js +65 -0
- package/dist/src/utils/quotaErrorDetection.js.map +1 -0
- package/dist/src/utils/retry.d.ts +30 -0
- package/dist/src/utils/retry.js +276 -0
- package/dist/src/utils/retry.js.map +1 -0
- package/dist/src/utils/retry.test.d.ts +6 -0
- package/dist/src/utils/retry.test.js +325 -0
- package/dist/src/utils/retry.test.js.map +1 -0
- package/dist/src/utils/safeJsonStringify.d.ts +13 -0
- package/dist/src/utils/safeJsonStringify.js +25 -0
- package/dist/src/utils/safeJsonStringify.js.map +1 -0
- package/dist/src/utils/safeJsonStringify.test.d.ts +6 -0
- package/dist/src/utils/safeJsonStringify.test.js +61 -0
- package/dist/src/utils/safeJsonStringify.test.js.map +1 -0
- package/dist/src/utils/schemaValidator.d.ts +15 -0
- package/dist/src/utils/schemaValidator.js +38 -0
- package/dist/src/utils/schemaValidator.js.map +1 -0
- package/dist/src/utils/secure-browser-launcher.d.ts +23 -0
- package/dist/src/utils/secure-browser-launcher.js +165 -0
- package/dist/src/utils/secure-browser-launcher.js.map +1 -0
- package/dist/src/utils/secure-browser-launcher.test.d.ts +6 -0
- package/dist/src/utils/secure-browser-launcher.test.js +149 -0
- package/dist/src/utils/secure-browser-launcher.test.js.map +1 -0
- package/dist/src/utils/session.d.ts +6 -0
- package/dist/src/utils/session.js +8 -0
- package/dist/src/utils/session.js.map +1 -0
- package/dist/src/utils/shell-utils.d.ts +117 -0
- package/dist/src/utils/shell-utils.js +370 -0
- package/dist/src/utils/shell-utils.js.map +1 -0
- package/dist/src/utils/shell-utils.test.d.ts +6 -0
- package/dist/src/utils/shell-utils.test.js +332 -0
- package/dist/src/utils/shell-utils.test.js.map +1 -0
- package/dist/src/utils/summarizer.d.ts +25 -0
- package/dist/src/utils/summarizer.js +51 -0
- package/dist/src/utils/summarizer.js.map +1 -0
- package/dist/src/utils/summarizer.test.d.ts +6 -0
- package/dist/src/utils/summarizer.test.js +131 -0
- package/dist/src/utils/summarizer.test.js.map +1 -0
- package/dist/src/utils/systemEncoding.d.ts +40 -0
- package/dist/src/utils/systemEncoding.js +149 -0
- package/dist/src/utils/systemEncoding.js.map +1 -0
- package/dist/src/utils/systemEncoding.test.d.ts +6 -0
- package/dist/src/utils/systemEncoding.test.js +368 -0
- package/dist/src/utils/systemEncoding.test.js.map +1 -0
- package/dist/src/utils/testUtils.d.ts +29 -0
- package/dist/src/utils/testUtils.js +70 -0
- package/dist/src/utils/testUtils.js.map +1 -0
- package/dist/src/utils/textUtils.d.ts +13 -0
- package/dist/src/utils/textUtils.js +28 -0
- package/dist/src/utils/textUtils.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/userAccountManager.test.js +223 -0
- package/dist/src/utils/userAccountManager.test.js.map +1 -0
- package/dist/src/utils/workspaceContext.d.ts +66 -0
- package/dist/src/utils/workspaceContext.js +171 -0
- package/dist/src/utils/workspaceContext.js.map +1 -0
- package/dist/src/utils/workspaceContext.test.d.ts +6 -0
- package/dist/src/utils/workspaceContext.test.js +318 -0
- package/dist/src/utils/workspaceContext.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import type { Part, PartListUnion, GenerateContentResponse, FunctionDeclaration, FinishReason } from '@google/genai';
|
|
7
|
+
import type { ToolCallConfirmationDetails, ToolResult, ToolResultDisplay } from '../tools/tools.js';
|
|
8
|
+
import type { ToolErrorType } from '../tools/tool-error.js';
|
|
9
|
+
import type { GeminiChat } from './geminiChat.js';
|
|
10
|
+
export interface ServerTool {
|
|
11
|
+
name: string;
|
|
12
|
+
schema: FunctionDeclaration;
|
|
13
|
+
execute(params: Record<string, unknown>, signal?: AbortSignal): Promise<ToolResult>;
|
|
14
|
+
shouldConfirmExecute(params: Record<string, unknown>, abortSignal: AbortSignal): Promise<ToolCallConfirmationDetails | false>;
|
|
15
|
+
}
|
|
16
|
+
export declare enum GeminiEventType {
|
|
17
|
+
Content = "content",
|
|
18
|
+
ToolCallRequest = "tool_call_request",
|
|
19
|
+
ToolCallResponse = "tool_call_response",
|
|
20
|
+
ToolCallConfirmation = "tool_call_confirmation",
|
|
21
|
+
UserCancelled = "user_cancelled",
|
|
22
|
+
Error = "error",
|
|
23
|
+
ChatCompressed = "chat_compressed",
|
|
24
|
+
Thought = "thought",
|
|
25
|
+
MaxSessionTurns = "max_session_turns",
|
|
26
|
+
Finished = "finished",
|
|
27
|
+
LoopDetected = "loop_detected"
|
|
28
|
+
}
|
|
29
|
+
export interface StructuredError {
|
|
30
|
+
message: string;
|
|
31
|
+
status?: number;
|
|
32
|
+
}
|
|
33
|
+
export interface GeminiErrorEventValue {
|
|
34
|
+
error: StructuredError;
|
|
35
|
+
}
|
|
36
|
+
export interface ToolCallRequestInfo {
|
|
37
|
+
callId: string;
|
|
38
|
+
name: string;
|
|
39
|
+
args: Record<string, unknown>;
|
|
40
|
+
isClientInitiated: boolean;
|
|
41
|
+
prompt_id: string;
|
|
42
|
+
}
|
|
43
|
+
export interface ToolCallResponseInfo {
|
|
44
|
+
callId: string;
|
|
45
|
+
responseParts: Part[];
|
|
46
|
+
resultDisplay: ToolResultDisplay | undefined;
|
|
47
|
+
error: Error | undefined;
|
|
48
|
+
errorType: ToolErrorType | undefined;
|
|
49
|
+
}
|
|
50
|
+
export interface ServerToolCallConfirmationDetails {
|
|
51
|
+
request: ToolCallRequestInfo;
|
|
52
|
+
details: ToolCallConfirmationDetails;
|
|
53
|
+
}
|
|
54
|
+
export type ThoughtSummary = {
|
|
55
|
+
subject: string;
|
|
56
|
+
description: string;
|
|
57
|
+
};
|
|
58
|
+
export type ServerGeminiContentEvent = {
|
|
59
|
+
type: GeminiEventType.Content;
|
|
60
|
+
value: string;
|
|
61
|
+
};
|
|
62
|
+
export type ServerGeminiThoughtEvent = {
|
|
63
|
+
type: GeminiEventType.Thought;
|
|
64
|
+
value: ThoughtSummary;
|
|
65
|
+
};
|
|
66
|
+
export type ServerGeminiToolCallRequestEvent = {
|
|
67
|
+
type: GeminiEventType.ToolCallRequest;
|
|
68
|
+
value: ToolCallRequestInfo;
|
|
69
|
+
};
|
|
70
|
+
export type ServerGeminiToolCallResponseEvent = {
|
|
71
|
+
type: GeminiEventType.ToolCallResponse;
|
|
72
|
+
value: ToolCallResponseInfo;
|
|
73
|
+
};
|
|
74
|
+
export type ServerGeminiToolCallConfirmationEvent = {
|
|
75
|
+
type: GeminiEventType.ToolCallConfirmation;
|
|
76
|
+
value: ServerToolCallConfirmationDetails;
|
|
77
|
+
};
|
|
78
|
+
export type ServerGeminiUserCancelledEvent = {
|
|
79
|
+
type: GeminiEventType.UserCancelled;
|
|
80
|
+
};
|
|
81
|
+
export type ServerGeminiErrorEvent = {
|
|
82
|
+
type: GeminiEventType.Error;
|
|
83
|
+
value: GeminiErrorEventValue;
|
|
84
|
+
};
|
|
85
|
+
export declare enum CompressionStatus {
|
|
86
|
+
/** The compression was successful */
|
|
87
|
+
COMPRESSED = 1,
|
|
88
|
+
/** The compression failed due to the compression inflating the token count */
|
|
89
|
+
COMPRESSION_FAILED_INFLATED_TOKEN_COUNT = 2,
|
|
90
|
+
/** The compression failed due to an error counting tokens */
|
|
91
|
+
COMPRESSION_FAILED_TOKEN_COUNT_ERROR = 3,
|
|
92
|
+
/** The compression was not necessary and no action was taken */
|
|
93
|
+
NOOP = 4
|
|
94
|
+
}
|
|
95
|
+
export interface ChatCompressionInfo {
|
|
96
|
+
originalTokenCount: number;
|
|
97
|
+
newTokenCount: number;
|
|
98
|
+
compressionStatus: CompressionStatus;
|
|
99
|
+
}
|
|
100
|
+
export type ServerGeminiChatCompressedEvent = {
|
|
101
|
+
type: GeminiEventType.ChatCompressed;
|
|
102
|
+
value: ChatCompressionInfo | null;
|
|
103
|
+
};
|
|
104
|
+
export type ServerGeminiMaxSessionTurnsEvent = {
|
|
105
|
+
type: GeminiEventType.MaxSessionTurns;
|
|
106
|
+
};
|
|
107
|
+
export type ServerGeminiFinishedEvent = {
|
|
108
|
+
type: GeminiEventType.Finished;
|
|
109
|
+
value: FinishReason;
|
|
110
|
+
};
|
|
111
|
+
export type ServerGeminiLoopDetectedEvent = {
|
|
112
|
+
type: GeminiEventType.LoopDetected;
|
|
113
|
+
};
|
|
114
|
+
export type ServerGeminiStreamEvent = ServerGeminiContentEvent | ServerGeminiToolCallRequestEvent | ServerGeminiToolCallResponseEvent | ServerGeminiToolCallConfirmationEvent | ServerGeminiUserCancelledEvent | ServerGeminiErrorEvent | ServerGeminiChatCompressedEvent | ServerGeminiThoughtEvent | ServerGeminiMaxSessionTurnsEvent | ServerGeminiFinishedEvent | ServerGeminiLoopDetectedEvent;
|
|
115
|
+
export declare class Turn {
|
|
116
|
+
private readonly chat;
|
|
117
|
+
private readonly prompt_id;
|
|
118
|
+
readonly pendingToolCalls: ToolCallRequestInfo[];
|
|
119
|
+
private debugResponses;
|
|
120
|
+
finishReason: FinishReason | undefined;
|
|
121
|
+
constructor(chat: GeminiChat, prompt_id: string);
|
|
122
|
+
run(req: PartListUnion, signal: AbortSignal): AsyncGenerator<ServerGeminiStreamEvent>;
|
|
123
|
+
private handlePendingFunctionCall;
|
|
124
|
+
getDebugResponses(): GenerateContentResponse[];
|
|
125
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { getResponseText } from '../utils/partUtils.js';
|
|
7
|
+
import { reportError } from '../utils/errorReporting.js';
|
|
8
|
+
import { getErrorMessage, UnauthorizedError, toFriendlyError, } from '../utils/errors.js';
|
|
9
|
+
export var GeminiEventType;
|
|
10
|
+
(function (GeminiEventType) {
|
|
11
|
+
GeminiEventType["Content"] = "content";
|
|
12
|
+
GeminiEventType["ToolCallRequest"] = "tool_call_request";
|
|
13
|
+
GeminiEventType["ToolCallResponse"] = "tool_call_response";
|
|
14
|
+
GeminiEventType["ToolCallConfirmation"] = "tool_call_confirmation";
|
|
15
|
+
GeminiEventType["UserCancelled"] = "user_cancelled";
|
|
16
|
+
GeminiEventType["Error"] = "error";
|
|
17
|
+
GeminiEventType["ChatCompressed"] = "chat_compressed";
|
|
18
|
+
GeminiEventType["Thought"] = "thought";
|
|
19
|
+
GeminiEventType["MaxSessionTurns"] = "max_session_turns";
|
|
20
|
+
GeminiEventType["Finished"] = "finished";
|
|
21
|
+
GeminiEventType["LoopDetected"] = "loop_detected";
|
|
22
|
+
})(GeminiEventType || (GeminiEventType = {}));
|
|
23
|
+
export var CompressionStatus;
|
|
24
|
+
(function (CompressionStatus) {
|
|
25
|
+
/** The compression was successful */
|
|
26
|
+
CompressionStatus[CompressionStatus["COMPRESSED"] = 1] = "COMPRESSED";
|
|
27
|
+
/** The compression failed due to the compression inflating the token count */
|
|
28
|
+
CompressionStatus[CompressionStatus["COMPRESSION_FAILED_INFLATED_TOKEN_COUNT"] = 2] = "COMPRESSION_FAILED_INFLATED_TOKEN_COUNT";
|
|
29
|
+
/** The compression failed due to an error counting tokens */
|
|
30
|
+
CompressionStatus[CompressionStatus["COMPRESSION_FAILED_TOKEN_COUNT_ERROR"] = 3] = "COMPRESSION_FAILED_TOKEN_COUNT_ERROR";
|
|
31
|
+
/** The compression was not necessary and no action was taken */
|
|
32
|
+
CompressionStatus[CompressionStatus["NOOP"] = 4] = "NOOP";
|
|
33
|
+
})(CompressionStatus || (CompressionStatus = {}));
|
|
34
|
+
// A turn manages the agentic loop turn within the server context.
|
|
35
|
+
export class Turn {
|
|
36
|
+
chat;
|
|
37
|
+
prompt_id;
|
|
38
|
+
pendingToolCalls;
|
|
39
|
+
debugResponses;
|
|
40
|
+
finishReason;
|
|
41
|
+
constructor(chat, prompt_id) {
|
|
42
|
+
this.chat = chat;
|
|
43
|
+
this.prompt_id = prompt_id;
|
|
44
|
+
this.pendingToolCalls = [];
|
|
45
|
+
this.debugResponses = [];
|
|
46
|
+
this.finishReason = undefined;
|
|
47
|
+
}
|
|
48
|
+
// The run method yields simpler events suitable for server logic
|
|
49
|
+
async *run(req, signal) {
|
|
50
|
+
try {
|
|
51
|
+
const responseStream = await this.chat.sendMessageStream({
|
|
52
|
+
message: req,
|
|
53
|
+
config: {
|
|
54
|
+
abortSignal: signal,
|
|
55
|
+
},
|
|
56
|
+
}, this.prompt_id);
|
|
57
|
+
for await (const resp of responseStream) {
|
|
58
|
+
if (signal?.aborted) {
|
|
59
|
+
yield { type: GeminiEventType.UserCancelled };
|
|
60
|
+
// Do not add resp to debugResponses if aborted before processing
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this.debugResponses.push(resp);
|
|
64
|
+
const thoughtPart = resp.candidates?.[0]?.content?.parts?.[0];
|
|
65
|
+
if (thoughtPart?.thought) {
|
|
66
|
+
// Thought always has a bold "subject" part enclosed in double asterisks
|
|
67
|
+
// (e.g., **Subject**). The rest of the string is considered the description.
|
|
68
|
+
const rawText = thoughtPart.text ?? '';
|
|
69
|
+
const subjectStringMatches = rawText.match(/\*\*(.*?)\*\*/s);
|
|
70
|
+
const subject = subjectStringMatches
|
|
71
|
+
? subjectStringMatches[1].trim()
|
|
72
|
+
: '';
|
|
73
|
+
const description = rawText.replace(/\*\*(.*?)\*\*/s, '').trim();
|
|
74
|
+
const thought = {
|
|
75
|
+
subject,
|
|
76
|
+
description,
|
|
77
|
+
};
|
|
78
|
+
yield {
|
|
79
|
+
type: GeminiEventType.Thought,
|
|
80
|
+
value: thought,
|
|
81
|
+
};
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const text = getResponseText(resp);
|
|
85
|
+
if (text) {
|
|
86
|
+
yield { type: GeminiEventType.Content, value: text };
|
|
87
|
+
}
|
|
88
|
+
// Handle function calls (requesting tool execution)
|
|
89
|
+
const functionCalls = resp.functionCalls ?? [];
|
|
90
|
+
for (const fnCall of functionCalls) {
|
|
91
|
+
const event = this.handlePendingFunctionCall(fnCall);
|
|
92
|
+
if (event) {
|
|
93
|
+
yield event;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
// Check if response was truncated or stopped for various reasons
|
|
97
|
+
const finishReason = resp.candidates?.[0]?.finishReason;
|
|
98
|
+
if (finishReason) {
|
|
99
|
+
this.finishReason = finishReason;
|
|
100
|
+
yield {
|
|
101
|
+
type: GeminiEventType.Finished,
|
|
102
|
+
value: finishReason,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
if (signal.aborted) {
|
|
109
|
+
yield { type: GeminiEventType.UserCancelled };
|
|
110
|
+
// Regular cancellation error, fail gracefully.
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const error = toFriendlyError(e);
|
|
114
|
+
if (error instanceof UnauthorizedError) {
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
const contextForReport = [...this.chat.getHistory(/*curated*/ true), req];
|
|
118
|
+
await reportError(error, 'Error when talking to Gemini API', contextForReport, 'Turn.run-sendMessageStream');
|
|
119
|
+
const status = typeof error === 'object' &&
|
|
120
|
+
error !== null &&
|
|
121
|
+
'status' in error &&
|
|
122
|
+
typeof error.status === 'number'
|
|
123
|
+
? error.status
|
|
124
|
+
: undefined;
|
|
125
|
+
const structuredError = {
|
|
126
|
+
message: getErrorMessage(error),
|
|
127
|
+
status,
|
|
128
|
+
};
|
|
129
|
+
await this.chat.maybeIncludeSchemaDepthContext(structuredError);
|
|
130
|
+
yield { type: GeminiEventType.Error, value: { error: structuredError } };
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
handlePendingFunctionCall(fnCall) {
|
|
135
|
+
const callId = fnCall.id ??
|
|
136
|
+
`${fnCall.name}-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
137
|
+
const name = fnCall.name || 'undefined_tool_name';
|
|
138
|
+
const args = (fnCall.args || {});
|
|
139
|
+
const toolCallRequest = {
|
|
140
|
+
callId,
|
|
141
|
+
name,
|
|
142
|
+
args,
|
|
143
|
+
isClientInitiated: false,
|
|
144
|
+
prompt_id: this.prompt_id,
|
|
145
|
+
};
|
|
146
|
+
this.pendingToolCalls.push(toolCallRequest);
|
|
147
|
+
// Yield a request for the tool call, not the pending/confirming status
|
|
148
|
+
return { type: GeminiEventType.ToolCallRequest, value: toolCallRequest };
|
|
149
|
+
}
|
|
150
|
+
getDebugResponses() {
|
|
151
|
+
return this.debugResponses;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=turn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn.js","sourceRoot":"","sources":["../../../src/core/turn.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
7
|
+
import { Turn, GeminiEventType } from './turn.js';
|
|
8
|
+
import { reportError } from '../utils/errorReporting.js';
|
|
9
|
+
const mockSendMessageStream = vi.fn();
|
|
10
|
+
const mockGetHistory = vi.fn();
|
|
11
|
+
const mockMaybeIncludeSchemaDepthContext = vi.fn();
|
|
12
|
+
vi.mock('@google/genai', async (importOriginal) => {
|
|
13
|
+
const actual = await importOriginal();
|
|
14
|
+
const MockChat = vi.fn().mockImplementation(() => ({
|
|
15
|
+
sendMessageStream: mockSendMessageStream,
|
|
16
|
+
getHistory: mockGetHistory,
|
|
17
|
+
maybeIncludeSchemaDepthContext: mockMaybeIncludeSchemaDepthContext,
|
|
18
|
+
}));
|
|
19
|
+
return {
|
|
20
|
+
...actual,
|
|
21
|
+
Chat: MockChat,
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
vi.mock('../utils/errorReporting', () => ({
|
|
25
|
+
reportError: vi.fn(),
|
|
26
|
+
}));
|
|
27
|
+
vi.mock('../utils/generateContentResponseUtilities', () => ({
|
|
28
|
+
getResponseText: (resp) => resp.candidates?.[0]?.content?.parts?.map((part) => part.text).join('') ||
|
|
29
|
+
undefined,
|
|
30
|
+
}));
|
|
31
|
+
describe('Turn', () => {
|
|
32
|
+
let turn;
|
|
33
|
+
let mockChatInstance;
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
vi.resetAllMocks();
|
|
36
|
+
mockChatInstance = {
|
|
37
|
+
sendMessageStream: mockSendMessageStream,
|
|
38
|
+
getHistory: mockGetHistory,
|
|
39
|
+
maybeIncludeSchemaDepthContext: mockMaybeIncludeSchemaDepthContext,
|
|
40
|
+
};
|
|
41
|
+
turn = new Turn(mockChatInstance, 'prompt-id-1');
|
|
42
|
+
mockGetHistory.mockReturnValue([]);
|
|
43
|
+
mockSendMessageStream.mockResolvedValue((async function* () { })());
|
|
44
|
+
});
|
|
45
|
+
afterEach(() => {
|
|
46
|
+
vi.restoreAllMocks();
|
|
47
|
+
});
|
|
48
|
+
describe('constructor', () => {
|
|
49
|
+
it('should initialize pendingToolCalls and debugResponses', () => {
|
|
50
|
+
expect(turn.pendingToolCalls).toEqual([]);
|
|
51
|
+
expect(turn.getDebugResponses()).toEqual([]);
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
describe('run', () => {
|
|
55
|
+
it('should yield content events for text parts', async () => {
|
|
56
|
+
const mockResponseStream = (async function* () {
|
|
57
|
+
yield {
|
|
58
|
+
candidates: [{ content: { parts: [{ text: 'Hello' }] } }],
|
|
59
|
+
};
|
|
60
|
+
yield {
|
|
61
|
+
candidates: [{ content: { parts: [{ text: ' world' }] } }],
|
|
62
|
+
};
|
|
63
|
+
})();
|
|
64
|
+
mockSendMessageStream.mockResolvedValue(mockResponseStream);
|
|
65
|
+
const events = [];
|
|
66
|
+
const reqParts = [{ text: 'Hi' }];
|
|
67
|
+
for await (const event of turn.run(reqParts, new AbortController().signal)) {
|
|
68
|
+
events.push(event);
|
|
69
|
+
}
|
|
70
|
+
expect(mockSendMessageStream).toHaveBeenCalledWith({
|
|
71
|
+
message: reqParts,
|
|
72
|
+
config: { abortSignal: expect.any(AbortSignal) },
|
|
73
|
+
}, 'prompt-id-1');
|
|
74
|
+
expect(events).toEqual([
|
|
75
|
+
{ type: GeminiEventType.Content, value: 'Hello' },
|
|
76
|
+
{ type: GeminiEventType.Content, value: ' world' },
|
|
77
|
+
]);
|
|
78
|
+
expect(turn.getDebugResponses().length).toBe(2);
|
|
79
|
+
});
|
|
80
|
+
it('should yield tool_call_request events for function calls', async () => {
|
|
81
|
+
const mockResponseStream = (async function* () {
|
|
82
|
+
yield {
|
|
83
|
+
functionCalls: [
|
|
84
|
+
{
|
|
85
|
+
id: 'fc1',
|
|
86
|
+
name: 'tool1',
|
|
87
|
+
args: { arg1: 'val1' },
|
|
88
|
+
isClientInitiated: false,
|
|
89
|
+
},
|
|
90
|
+
{ name: 'tool2', args: { arg2: 'val2' }, isClientInitiated: false }, // No ID
|
|
91
|
+
],
|
|
92
|
+
};
|
|
93
|
+
})();
|
|
94
|
+
mockSendMessageStream.mockResolvedValue(mockResponseStream);
|
|
95
|
+
const events = [];
|
|
96
|
+
const reqParts = [{ text: 'Use tools' }];
|
|
97
|
+
for await (const event of turn.run(reqParts, new AbortController().signal)) {
|
|
98
|
+
events.push(event);
|
|
99
|
+
}
|
|
100
|
+
expect(events.length).toBe(2);
|
|
101
|
+
const event1 = events[0];
|
|
102
|
+
expect(event1.type).toBe(GeminiEventType.ToolCallRequest);
|
|
103
|
+
expect(event1.value).toEqual(expect.objectContaining({
|
|
104
|
+
callId: 'fc1',
|
|
105
|
+
name: 'tool1',
|
|
106
|
+
args: { arg1: 'val1' },
|
|
107
|
+
isClientInitiated: false,
|
|
108
|
+
}));
|
|
109
|
+
expect(turn.pendingToolCalls[0]).toEqual(event1.value);
|
|
110
|
+
const event2 = events[1];
|
|
111
|
+
expect(event2.type).toBe(GeminiEventType.ToolCallRequest);
|
|
112
|
+
expect(event2.value).toEqual(expect.objectContaining({
|
|
113
|
+
name: 'tool2',
|
|
114
|
+
args: { arg2: 'val2' },
|
|
115
|
+
isClientInitiated: false,
|
|
116
|
+
}));
|
|
117
|
+
expect(event2.value.callId).toEqual(expect.stringMatching(/^tool2-\d{13}-\w{10,}$/));
|
|
118
|
+
expect(turn.pendingToolCalls[1]).toEqual(event2.value);
|
|
119
|
+
expect(turn.getDebugResponses().length).toBe(1);
|
|
120
|
+
});
|
|
121
|
+
it('should yield UserCancelled event if signal is aborted', async () => {
|
|
122
|
+
const abortController = new AbortController();
|
|
123
|
+
const mockResponseStream = (async function* () {
|
|
124
|
+
yield {
|
|
125
|
+
candidates: [{ content: { parts: [{ text: 'First part' }] } }],
|
|
126
|
+
};
|
|
127
|
+
abortController.abort();
|
|
128
|
+
yield {
|
|
129
|
+
candidates: [
|
|
130
|
+
{
|
|
131
|
+
content: {
|
|
132
|
+
parts: [{ text: 'Second part - should not be processed' }],
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
};
|
|
137
|
+
})();
|
|
138
|
+
mockSendMessageStream.mockResolvedValue(mockResponseStream);
|
|
139
|
+
const events = [];
|
|
140
|
+
const reqParts = [{ text: 'Test abort' }];
|
|
141
|
+
for await (const event of turn.run(reqParts, abortController.signal)) {
|
|
142
|
+
events.push(event);
|
|
143
|
+
}
|
|
144
|
+
expect(events).toEqual([
|
|
145
|
+
{ type: GeminiEventType.Content, value: 'First part' },
|
|
146
|
+
{ type: GeminiEventType.UserCancelled },
|
|
147
|
+
]);
|
|
148
|
+
expect(turn.getDebugResponses().length).toBe(1);
|
|
149
|
+
});
|
|
150
|
+
it('should yield Error event and report if sendMessageStream throws', async () => {
|
|
151
|
+
const error = new Error('API Error');
|
|
152
|
+
mockSendMessageStream.mockRejectedValue(error);
|
|
153
|
+
const reqParts = [{ text: 'Trigger error' }];
|
|
154
|
+
const historyContent = [
|
|
155
|
+
{ role: 'model', parts: [{ text: 'Previous history' }] },
|
|
156
|
+
];
|
|
157
|
+
mockGetHistory.mockReturnValue(historyContent);
|
|
158
|
+
mockMaybeIncludeSchemaDepthContext.mockResolvedValue(undefined);
|
|
159
|
+
const events = [];
|
|
160
|
+
for await (const event of turn.run(reqParts, new AbortController().signal)) {
|
|
161
|
+
events.push(event);
|
|
162
|
+
}
|
|
163
|
+
expect(events.length).toBe(1);
|
|
164
|
+
const errorEvent = events[0];
|
|
165
|
+
expect(errorEvent.type).toBe(GeminiEventType.Error);
|
|
166
|
+
expect(errorEvent.value).toEqual({
|
|
167
|
+
error: { message: 'API Error', status: undefined },
|
|
168
|
+
});
|
|
169
|
+
expect(turn.getDebugResponses().length).toBe(0);
|
|
170
|
+
expect(reportError).toHaveBeenCalledWith(error, 'Error when talking to Gemini API', [...historyContent, reqParts], 'Turn.run-sendMessageStream');
|
|
171
|
+
});
|
|
172
|
+
it('should handle function calls with undefined name or args', async () => {
|
|
173
|
+
const mockResponseStream = (async function* () {
|
|
174
|
+
yield {
|
|
175
|
+
functionCalls: [
|
|
176
|
+
{ id: 'fc1', name: undefined, args: { arg1: 'val1' } },
|
|
177
|
+
{ id: 'fc2', name: 'tool2', args: undefined },
|
|
178
|
+
{ id: 'fc3', name: undefined, args: undefined },
|
|
179
|
+
],
|
|
180
|
+
};
|
|
181
|
+
})();
|
|
182
|
+
mockSendMessageStream.mockResolvedValue(mockResponseStream);
|
|
183
|
+
const events = [];
|
|
184
|
+
const reqParts = [{ text: 'Test undefined tool parts' }];
|
|
185
|
+
for await (const event of turn.run(reqParts, new AbortController().signal)) {
|
|
186
|
+
events.push(event);
|
|
187
|
+
}
|
|
188
|
+
expect(events.length).toBe(3);
|
|
189
|
+
const event1 = events[0];
|
|
190
|
+
expect(event1.type).toBe(GeminiEventType.ToolCallRequest);
|
|
191
|
+
expect(event1.value).toEqual(expect.objectContaining({
|
|
192
|
+
callId: 'fc1',
|
|
193
|
+
name: 'undefined_tool_name',
|
|
194
|
+
args: { arg1: 'val1' },
|
|
195
|
+
isClientInitiated: false,
|
|
196
|
+
}));
|
|
197
|
+
expect(turn.pendingToolCalls[0]).toEqual(event1.value);
|
|
198
|
+
const event2 = events[1];
|
|
199
|
+
expect(event2.type).toBe(GeminiEventType.ToolCallRequest);
|
|
200
|
+
expect(event2.value).toEqual(expect.objectContaining({
|
|
201
|
+
callId: 'fc2',
|
|
202
|
+
name: 'tool2',
|
|
203
|
+
args: {},
|
|
204
|
+
isClientInitiated: false,
|
|
205
|
+
}));
|
|
206
|
+
expect(turn.pendingToolCalls[1]).toEqual(event2.value);
|
|
207
|
+
const event3 = events[2];
|
|
208
|
+
expect(event3.type).toBe(GeminiEventType.ToolCallRequest);
|
|
209
|
+
expect(event3.value).toEqual(expect.objectContaining({
|
|
210
|
+
callId: 'fc3',
|
|
211
|
+
name: 'undefined_tool_name',
|
|
212
|
+
args: {},
|
|
213
|
+
isClientInitiated: false,
|
|
214
|
+
}));
|
|
215
|
+
expect(turn.pendingToolCalls[2]).toEqual(event3.value);
|
|
216
|
+
expect(turn.getDebugResponses().length).toBe(1);
|
|
217
|
+
});
|
|
218
|
+
it('should yield finished event when response has finish reason', async () => {
|
|
219
|
+
const mockResponseStream = (async function* () {
|
|
220
|
+
yield {
|
|
221
|
+
candidates: [
|
|
222
|
+
{
|
|
223
|
+
content: { parts: [{ text: 'Partial response' }] },
|
|
224
|
+
finishReason: 'STOP',
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
};
|
|
228
|
+
})();
|
|
229
|
+
mockSendMessageStream.mockResolvedValue(mockResponseStream);
|
|
230
|
+
const events = [];
|
|
231
|
+
const reqParts = [{ text: 'Test finish reason' }];
|
|
232
|
+
for await (const event of turn.run(reqParts, new AbortController().signal)) {
|
|
233
|
+
events.push(event);
|
|
234
|
+
}
|
|
235
|
+
expect(events).toEqual([
|
|
236
|
+
{ type: GeminiEventType.Content, value: 'Partial response' },
|
|
237
|
+
{ type: GeminiEventType.Finished, value: 'STOP' },
|
|
238
|
+
]);
|
|
239
|
+
});
|
|
240
|
+
it('should yield finished event for MAX_TOKENS finish reason', async () => {
|
|
241
|
+
const mockResponseStream = (async function* () {
|
|
242
|
+
yield {
|
|
243
|
+
candidates: [
|
|
244
|
+
{
|
|
245
|
+
content: {
|
|
246
|
+
parts: [
|
|
247
|
+
{ text: 'This is a long response that was cut off...' },
|
|
248
|
+
],
|
|
249
|
+
},
|
|
250
|
+
finishReason: 'MAX_TOKENS',
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
};
|
|
254
|
+
})();
|
|
255
|
+
mockSendMessageStream.mockResolvedValue(mockResponseStream);
|
|
256
|
+
const events = [];
|
|
257
|
+
const reqParts = [{ text: 'Generate long text' }];
|
|
258
|
+
for await (const event of turn.run(reqParts, new AbortController().signal)) {
|
|
259
|
+
events.push(event);
|
|
260
|
+
}
|
|
261
|
+
expect(events).toEqual([
|
|
262
|
+
{
|
|
263
|
+
type: GeminiEventType.Content,
|
|
264
|
+
value: 'This is a long response that was cut off...',
|
|
265
|
+
},
|
|
266
|
+
{ type: GeminiEventType.Finished, value: 'MAX_TOKENS' },
|
|
267
|
+
]);
|
|
268
|
+
});
|
|
269
|
+
it('should yield finished event for SAFETY finish reason', async () => {
|
|
270
|
+
const mockResponseStream = (async function* () {
|
|
271
|
+
yield {
|
|
272
|
+
candidates: [
|
|
273
|
+
{
|
|
274
|
+
content: { parts: [{ text: 'Content blocked' }] },
|
|
275
|
+
finishReason: 'SAFETY',
|
|
276
|
+
},
|
|
277
|
+
],
|
|
278
|
+
};
|
|
279
|
+
})();
|
|
280
|
+
mockSendMessageStream.mockResolvedValue(mockResponseStream);
|
|
281
|
+
const events = [];
|
|
282
|
+
const reqParts = [{ text: 'Test safety' }];
|
|
283
|
+
for await (const event of turn.run(reqParts, new AbortController().signal)) {
|
|
284
|
+
events.push(event);
|
|
285
|
+
}
|
|
286
|
+
expect(events).toEqual([
|
|
287
|
+
{ type: GeminiEventType.Content, value: 'Content blocked' },
|
|
288
|
+
{ type: GeminiEventType.Finished, value: 'SAFETY' },
|
|
289
|
+
]);
|
|
290
|
+
});
|
|
291
|
+
it('should not yield finished event when there is no finish reason', async () => {
|
|
292
|
+
const mockResponseStream = (async function* () {
|
|
293
|
+
yield {
|
|
294
|
+
candidates: [
|
|
295
|
+
{
|
|
296
|
+
content: { parts: [{ text: 'Response without finish reason' }] },
|
|
297
|
+
// No finishReason property
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
};
|
|
301
|
+
})();
|
|
302
|
+
mockSendMessageStream.mockResolvedValue(mockResponseStream);
|
|
303
|
+
const events = [];
|
|
304
|
+
const reqParts = [{ text: 'Test no finish reason' }];
|
|
305
|
+
for await (const event of turn.run(reqParts, new AbortController().signal)) {
|
|
306
|
+
events.push(event);
|
|
307
|
+
}
|
|
308
|
+
expect(events).toEqual([
|
|
309
|
+
{
|
|
310
|
+
type: GeminiEventType.Content,
|
|
311
|
+
value: 'Response without finish reason',
|
|
312
|
+
},
|
|
313
|
+
]);
|
|
314
|
+
// No Finished event should be emitted
|
|
315
|
+
});
|
|
316
|
+
it('should handle multiple responses with different finish reasons', async () => {
|
|
317
|
+
const mockResponseStream = (async function* () {
|
|
318
|
+
yield {
|
|
319
|
+
candidates: [
|
|
320
|
+
{
|
|
321
|
+
content: { parts: [{ text: 'First part' }] },
|
|
322
|
+
// No finish reason on first response
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
};
|
|
326
|
+
yield {
|
|
327
|
+
candidates: [
|
|
328
|
+
{
|
|
329
|
+
content: { parts: [{ text: 'Second part' }] },
|
|
330
|
+
finishReason: 'OTHER',
|
|
331
|
+
},
|
|
332
|
+
],
|
|
333
|
+
};
|
|
334
|
+
})();
|
|
335
|
+
mockSendMessageStream.mockResolvedValue(mockResponseStream);
|
|
336
|
+
const events = [];
|
|
337
|
+
const reqParts = [{ text: 'Test multiple responses' }];
|
|
338
|
+
for await (const event of turn.run(reqParts, new AbortController().signal)) {
|
|
339
|
+
events.push(event);
|
|
340
|
+
}
|
|
341
|
+
expect(events).toEqual([
|
|
342
|
+
{ type: GeminiEventType.Content, value: 'First part' },
|
|
343
|
+
{ type: GeminiEventType.Content, value: 'Second part' },
|
|
344
|
+
{ type: GeminiEventType.Finished, value: 'OTHER' },
|
|
345
|
+
]);
|
|
346
|
+
});
|
|
347
|
+
it('should not crash when cancelled request has malformed error', async () => {
|
|
348
|
+
const abortController = new AbortController();
|
|
349
|
+
const errorToThrow = {
|
|
350
|
+
response: {
|
|
351
|
+
data: undefined, // Malformed error data
|
|
352
|
+
},
|
|
353
|
+
};
|
|
354
|
+
mockSendMessageStream.mockImplementation(async () => {
|
|
355
|
+
abortController.abort();
|
|
356
|
+
throw errorToThrow;
|
|
357
|
+
});
|
|
358
|
+
const events = [];
|
|
359
|
+
const reqParts = [{ text: 'Test malformed error handling' }];
|
|
360
|
+
for await (const event of turn.run(reqParts, abortController.signal)) {
|
|
361
|
+
events.push(event);
|
|
362
|
+
}
|
|
363
|
+
expect(events).toEqual([{ type: GeminiEventType.UserCancelled }]);
|
|
364
|
+
expect(reportError).not.toHaveBeenCalled();
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
describe('getDebugResponses', () => {
|
|
368
|
+
it('should return collected debug responses', async () => {
|
|
369
|
+
const resp1 = {
|
|
370
|
+
candidates: [{ content: { parts: [{ text: 'Debug 1' }] } }],
|
|
371
|
+
};
|
|
372
|
+
const resp2 = {
|
|
373
|
+
functionCalls: [{ name: 'debugTool' }],
|
|
374
|
+
};
|
|
375
|
+
const mockResponseStream = (async function* () {
|
|
376
|
+
yield resp1;
|
|
377
|
+
yield resp2;
|
|
378
|
+
})();
|
|
379
|
+
mockSendMessageStream.mockResolvedValue(mockResponseStream);
|
|
380
|
+
const reqParts = [{ text: 'Hi' }];
|
|
381
|
+
for await (const _ of turn.run(reqParts, new AbortController().signal)) {
|
|
382
|
+
// consume stream
|
|
383
|
+
}
|
|
384
|
+
expect(turn.getDebugResponses()).toEqual([resp1, resp2]);
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
//# sourceMappingURL=turn.test.js.map
|