@vybestack/llxprt-code-core 0.1.12
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/.last_build +0 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -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 +9 -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 +68 -0
- package/dist/src/code_assist/converter.js +125 -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 +229 -0
- package/dist/src/code_assist/converter.test.js.map +1 -0
- package/dist/src/code_assist/oauth2.d.ts +20 -0
- package/dist/src/code_assist/oauth2.js +339 -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 +249 -0
- package/dist/src/code_assist/oauth2.test.js.map +1 -0
- package/dist/src/code_assist/server.d.ts +39 -0
- package/dist/src/code_assist/server.js +191 -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 +123 -0
- package/dist/src/code_assist/server.test.js.map +1 -0
- package/dist/src/code_assist/setup.d.ts +15 -0
- package/dist/src/code_assist/setup.js +67 -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 +62 -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 +212 -0
- package/dist/src/config/config.js +454 -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 +291 -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 +115 -0
- package/dist/src/config/flashFallback.test.js.map +1 -0
- package/dist/src/config/models.d.ts +8 -0
- package/dist/src/config/models.js +9 -0
- package/dist/src/config/models.js.map +1 -0
- package/dist/src/core/client.d.ts +59 -0
- package/dist/src/core/client.js +503 -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 +1006 -0
- package/dist/src/core/client.test.js.map +1 -0
- package/dist/src/core/contentGenerator.d.ts +36 -0
- package/dist/src/core/contentGenerator.js +79 -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 +92 -0
- package/dist/src/core/contentGenerator.test.js.map +1 -0
- package/dist/src/core/coreToolScheduler.d.ts +104 -0
- package/dist/src/core/coreToolScheduler.js +413 -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 +347 -0
- package/dist/src/core/coreToolScheduler.test.js.map +1 -0
- package/dist/src/core/geminiChat.d.ts +116 -0
- package/dist/src/core/geminiChat.js +513 -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 +424 -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 +45 -0
- package/dist/src/core/geminiRequest.js.map +1 -0
- package/dist/src/core/geminiRequest.test.d.ts +6 -0
- package/dist/src/core/geminiRequest.test.js +72 -0
- package/dist/src/core/geminiRequest.test.js.map +1 -0
- package/dist/src/core/logger.d.ts +38 -0
- package/dist/src/core/logger.js +237 -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 +387 -0
- package/dist/src/core/logger.test.js.map +1 -0
- package/dist/src/core/modelCheck.d.ts +14 -0
- package/dist/src/core/modelCheck.js +55 -0
- package/dist/src/core/modelCheck.js.map +1 -0
- package/dist/src/core/nonInteractiveToolExecutor.d.ts +12 -0
- package/dist/src/core/nonInteractiveToolExecutor.js +93 -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 +180 -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 +418 -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 +97 -0
- package/dist/src/core/prompts.test.js.map +1 -0
- package/dist/src/core/tokenLimits.d.ts +10 -0
- package/dist/src/core/tokenLimits.js +75 -0
- package/dist/src/core/tokenLimits.js.map +1 -0
- package/dist/src/core/tokenLimits.test.d.ts +6 -0
- package/dist/src/core/tokenLimits.test.js +66 -0
- package/dist/src/core/tokenLimits.test.js.map +1 -0
- package/dist/src/core/turn.d.ts +116 -0
- package/dist/src/core/turn.js +131 -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 +237 -0
- package/dist/src/core/turn.test.js.map +1 -0
- package/dist/src/index.d.ts +57 -0
- package/dist/src/index.js +64 -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/providers/ProviderContentGenerator.d.ts +21 -0
- package/dist/src/providers/ProviderContentGenerator.js +52 -0
- package/dist/src/providers/ProviderContentGenerator.js.map +1 -0
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.d.ts +68 -0
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.js +549 -0
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.js.map +1 -0
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.d.ts +6 -0
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.js +253 -0
- package/dist/src/providers/adapters/GeminiCompatibleWrapper.test.js.map +1 -0
- package/dist/src/providers/types.d.ts +82 -0
- package/dist/src/providers/types.js +7 -0
- package/dist/src/providers/types.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 +102 -0
- package/dist/src/services/fileDiscoveryService.test.js.map +1 -0
- package/dist/src/services/gitService.d.ts +21 -0
- package/dist/src/services/gitService.js +102 -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 +246 -0
- package/dist/src/services/gitService.test.js.map +1 -0
- package/dist/src/services/ideContext.d.ts +124 -0
- package/dist/src/services/ideContext.js +90 -0
- package/dist/src/services/ideContext.js.map +1 -0
- package/dist/src/services/ideContext.test.d.ts +6 -0
- package/dist/src/services/ideContext.test.js +101 -0
- package/dist/src/services/ideContext.test.js.map +1 -0
- package/dist/src/services/loopDetectionService.d.ts +35 -0
- package/dist/src/services/loopDetectionService.js +117 -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 +232 -0
- package/dist/src/services/loopDetectionService.test.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +35 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +424 -0
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +47 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +123 -0
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -0
- package/dist/src/telemetry/constants.d.ts +20 -0
- package/dist/src/telemetry/constants.js +21 -0
- package/dist/src/telemetry/constants.js.map +1 -0
- package/dist/src/telemetry/index.d.ts +18 -0
- package/dist/src/telemetry/index.js +20 -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 +53 -0
- package/dist/src/telemetry/integration.test.circular.js.map +1 -0
- package/dist/src/telemetry/loggers.d.ts +15 -0
- package/dist/src/telemetry/loggers.js +229 -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 +100 -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 +558 -0
- package/dist/src/telemetry/loggers.test.js.map +1 -0
- package/dist/src/telemetry/metrics.d.ts +19 -0
- package/dist/src/telemetry/metrics.js +144 -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 +162 -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 +120 -0
- package/dist/src/telemetry/sdk.js.map +1 -0
- package/dist/src/telemetry/telemetry.test.d.ts +6 -0
- package/dist/src/telemetry/telemetry.test.js +52 -0
- package/dist/src/telemetry/telemetry.test.js.map +1 -0
- package/dist/src/telemetry/types.d.ts +115 -0
- package/dist/src/telemetry/types.js +217 -0
- package/dist/src/telemetry/types.js.map +1 -0
- package/dist/src/telemetry/uiTelemetry.d.ts +67 -0
- package/dist/src/telemetry/uiTelemetry.js +131 -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 +412 -0
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -0
- package/dist/src/tools/diffOptions.d.ts +7 -0
- package/dist/src/tools/diffOptions.js +10 -0
- package/dist/src/tools/diffOptions.js.map +1 -0
- package/dist/src/tools/edit.d.ts +73 -0
- package/dist/src/tools/edit.js +343 -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 +500 -0
- package/dist/src/tools/edit.test.js.map +1 -0
- package/dist/src/tools/glob.d.ts +58 -0
- package/dist/src/tools/glob.js +193 -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 +294 -0
- package/dist/src/tools/glob.test.js.map +1 -0
- package/dist/src/tools/grep.d.ts +78 -0
- package/dist/src/tools/grep.js +422 -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 +188 -0
- package/dist/src/tools/grep.test.js.map +1 -0
- package/dist/src/tools/ls.d.ts +83 -0
- package/dist/src/tools/ls.js +194 -0
- package/dist/src/tools/ls.js.map +1 -0
- package/dist/src/tools/mcp-client.d.ts +112 -0
- package/dist/src/tools/mcp-client.js +332 -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 +227 -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 +119 -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 +173 -0
- package/dist/src/tools/mcp-tool.test.js.map +1 -0
- package/dist/src/tools/memoryTool.d.ts +28 -0
- package/dist/src/tools/memoryTool.js +172 -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 +181 -0
- package/dist/src/tools/memoryTool.test.js.map +1 -0
- package/dist/src/tools/modifiable-tool.d.ts +29 -0
- package/dist/src/tools/modifiable-tool.js +85 -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 +204 -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 +106 -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 +181 -0
- package/dist/src/tools/read-file.test.js.map +1 -0
- package/dist/src/tools/read-many-files.d.ts +59 -0
- package/dist/src/tools/read-many-files.js +321 -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 +312 -0
- package/dist/src/tools/read-many-files.test.js.map +1 -0
- package/dist/src/tools/shell.d.ts +43 -0
- package/dist/src/tools/shell.js +435 -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 +407 -0
- package/dist/src/tools/shell.test.js.map +1 -0
- package/dist/src/tools/todo-read.d.ts +15 -0
- package/dist/src/tools/todo-read.js +66 -0
- package/dist/src/tools/todo-read.js.map +1 -0
- package/dist/src/tools/todo-read.test.d.ts +6 -0
- package/dist/src/tools/todo-read.test.js +158 -0
- package/dist/src/tools/todo-read.test.js.map +1 -0
- package/dist/src/tools/todo-schemas.d.ts +43 -0
- package/dist/src/tools/todo-schemas.js +16 -0
- package/dist/src/tools/todo-schemas.js.map +1 -0
- package/dist/src/tools/todo-schemas.test.d.ts +6 -0
- package/dist/src/tools/todo-schemas.test.js +152 -0
- package/dist/src/tools/todo-schemas.test.js.map +1 -0
- package/dist/src/tools/todo-store.d.ts +15 -0
- package/dist/src/tools/todo-store.js +59 -0
- package/dist/src/tools/todo-store.js.map +1 -0
- package/dist/src/tools/todo-store.test.d.ts +6 -0
- package/dist/src/tools/todo-store.test.js +175 -0
- package/dist/src/tools/todo-store.test.js.map +1 -0
- package/dist/src/tools/todo-write.d.ts +17 -0
- package/dist/src/tools/todo-write.js +98 -0
- package/dist/src/tools/todo-write.js.map +1 -0
- package/dist/src/tools/todo-write.test.d.ts +6 -0
- package/dist/src/tools/todo-write.test.js +208 -0
- package/dist/src/tools/todo-write.test.js.map +1 -0
- package/dist/src/tools/tool-registry.d.ts +67 -0
- package/dist/src/tools/tool-registry.js +326 -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 +398 -0
- package/dist/src/tools/tool-registry.test.js.map +1 -0
- package/dist/src/tools/tools.d.ts +184 -0
- package/dist/src/tools/tools.js +88 -0
- package/dist/src/tools/tools.js.map +1 -0
- package/dist/src/tools/web-fetch.d.ts +29 -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 +70 -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 +120 -0
- package/dist/src/tools/web-search.js.map +1 -0
- package/dist/src/tools/write-file.d.ts +42 -0
- package/dist/src/tools/write-file.js +248 -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 +413 -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 +22 -0
- package/dist/src/utils/bfsFileSearch.js +62 -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 +129 -0
- package/dist/src/utils/bfsFileSearch.test.js.map +1 -0
- package/dist/src/utils/editCorrector.d.ts +53 -0
- package/dist/src/utils/editCorrector.js +546 -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 +163 -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 +293 -0
- package/dist/src/utils/editor.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 +124 -0
- package/dist/src/utils/errorReporting.test.js.map +1 -0
- package/dist/src/utils/errors.d.ts +14 -0
- package/dist/src/utils/errors.js +54 -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 +49 -0
- package/dist/src/utils/fileUtils.js +286 -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 +321 -0
- package/dist/src/utils/fileUtils.test.js.map +1 -0
- package/dist/src/utils/flashFallback.integration.test.d.ts +6 -0
- package/dist/src/utils/flashFallback.integration.test.js +112 -0
- package/dist/src/utils/flashFallback.integration.test.js.map +1 -0
- package/dist/src/utils/generateContentResponseUtilities.d.ts +14 -0
- package/dist/src/utils/generateContentResponseUtilities.js +92 -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 +273 -0
- package/dist/src/utils/generateContentResponseUtilities.test.js.map +1 -0
- package/dist/src/utils/getFolderStructure.d.ts +30 -0
- package/dist/src/utils/getFolderStructure.js +247 -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 +298 -0
- package/dist/src/utils/getFolderStructure.test.js.map +1 -0
- package/dist/src/utils/gitIgnoreParser.d.ts +20 -0
- package/dist/src/utils/gitIgnoreParser.js +64 -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 +145 -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/memoryDiscovery.d.ts +14 -0
- package/dist/src/utils/memoryDiscovery.js +219 -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 +432 -0
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -0
- package/dist/src/utils/memoryImportProcessor.d.ts +35 -0
- package/dist/src/utils/memoryImportProcessor.js +141 -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 +170 -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 +113 -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/paths.d.ts +49 -0
- package/dist/src/utils/paths.js +145 -0
- package/dist/src/utils/paths.js.map +1 -0
- package/dist/src/utils/quotaErrorDetection.d.ts +22 -0
- package/dist/src/utils/quotaErrorDetection.js +67 -0
- package/dist/src/utils/quotaErrorDetection.js.map +1 -0
- package/dist/src/utils/retry.d.ts +21 -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 +322 -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 +23 -0
- package/dist/src/utils/schemaValidator.js +142 -0
- package/dist/src/utils/schemaValidator.js.map +1 -0
- package/dist/src/utils/schemaValidator.test.d.ts +6 -0
- package/dist/src/utils/schemaValidator.test.js +146 -0
- package/dist/src/utils/schemaValidator.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/summarizer.d.ts +25 -0
- package/dist/src/utils/summarizer.js +80 -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/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/user_account.d.ts +9 -0
- package/dist/src/utils/user_account.js +99 -0
- package/dist/src/utils/user_account.js.map +1 -0
- package/dist/src/utils/user_account.test.d.ts +6 -0
- package/dist/src/utils/user_account.test.js +153 -0
- package/dist/src/utils/user_account.test.js.map +1 -0
- package/dist/src/utils/user_id.d.ts +11 -0
- package/dist/src/utils/user_id.js +49 -0
- package/dist/src/utils/user_id.js.map +1 -0
- package/dist/src/utils/user_id.test.d.ts +6 -0
- package/dist/src/utils/user_id.test.js +21 -0
- package/dist/src/utils/user_id.test.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/vybestack-llxprt-code-core-0.1.12.tgz +0 -0
- package/package.json +62 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect } from 'vitest';
|
|
7
|
+
import { SchemaValidator } from './schemaValidator.js';
|
|
8
|
+
import { Type } from '@google/genai';
|
|
9
|
+
describe('SchemaValidator', () => {
|
|
10
|
+
describe('validate', () => {
|
|
11
|
+
it('should return null for valid data', () => {
|
|
12
|
+
const schema = {
|
|
13
|
+
type: Type.OBJECT,
|
|
14
|
+
properties: {
|
|
15
|
+
name: { type: Type.STRING },
|
|
16
|
+
age: { type: Type.NUMBER },
|
|
17
|
+
},
|
|
18
|
+
required: ['name'],
|
|
19
|
+
};
|
|
20
|
+
const validData = { name: 'John', age: 30 };
|
|
21
|
+
expect(SchemaValidator.validate(schema, validData)).toBeNull();
|
|
22
|
+
});
|
|
23
|
+
it('should return error for invalid data', () => {
|
|
24
|
+
const schema = {
|
|
25
|
+
type: Type.OBJECT,
|
|
26
|
+
properties: {
|
|
27
|
+
name: { type: Type.STRING },
|
|
28
|
+
age: { type: Type.NUMBER },
|
|
29
|
+
},
|
|
30
|
+
required: ['name'],
|
|
31
|
+
};
|
|
32
|
+
const invalidData = { age: 30 }; // missing required 'name'
|
|
33
|
+
const error = SchemaValidator.validate(schema, invalidData);
|
|
34
|
+
expect(error).toContain('must have required property');
|
|
35
|
+
});
|
|
36
|
+
it('should handle numeric validation properties', () => {
|
|
37
|
+
const schema = {
|
|
38
|
+
type: Type.OBJECT,
|
|
39
|
+
properties: {
|
|
40
|
+
items: {
|
|
41
|
+
type: Type.ARRAY,
|
|
42
|
+
minItems: '2', // @google/genai Schema expects strings for numeric properties
|
|
43
|
+
maxItems: '5',
|
|
44
|
+
},
|
|
45
|
+
text: {
|
|
46
|
+
type: Type.STRING,
|
|
47
|
+
minLength: '3',
|
|
48
|
+
maxLength: '10',
|
|
49
|
+
},
|
|
50
|
+
count: {
|
|
51
|
+
type: Type.NUMBER,
|
|
52
|
+
minimum: 0,
|
|
53
|
+
maximum: 100,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
// Valid data
|
|
58
|
+
const validData = {
|
|
59
|
+
items: [1, 2, 3],
|
|
60
|
+
text: 'hello',
|
|
61
|
+
count: 50,
|
|
62
|
+
};
|
|
63
|
+
expect(SchemaValidator.validate(schema, validData)).toBeNull();
|
|
64
|
+
// Too few items
|
|
65
|
+
const tooFewItems = {
|
|
66
|
+
items: [1],
|
|
67
|
+
text: 'hello',
|
|
68
|
+
count: 50,
|
|
69
|
+
};
|
|
70
|
+
const error1 = SchemaValidator.validate(schema, tooFewItems);
|
|
71
|
+
expect(error1).toContain('must NOT have fewer than 2 items');
|
|
72
|
+
// Text too short
|
|
73
|
+
const textTooShort = {
|
|
74
|
+
items: [1, 2],
|
|
75
|
+
text: 'hi',
|
|
76
|
+
count: 50,
|
|
77
|
+
};
|
|
78
|
+
const error2 = SchemaValidator.validate(schema, textTooShort);
|
|
79
|
+
expect(error2).toContain('must NOT have fewer than 3 characters');
|
|
80
|
+
});
|
|
81
|
+
it('should handle nested schemas with anyOf, allOf, oneOf', () => {
|
|
82
|
+
const schema = {
|
|
83
|
+
type: Type.OBJECT,
|
|
84
|
+
properties: {
|
|
85
|
+
value: {
|
|
86
|
+
anyOf: [{ type: Type.STRING }, { type: Type.NUMBER }],
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
expect(SchemaValidator.validate(schema, { value: 'test' })).toBeNull();
|
|
91
|
+
expect(SchemaValidator.validate(schema, { value: 123 })).toBeNull();
|
|
92
|
+
const error = SchemaValidator.validate(schema, { value: true });
|
|
93
|
+
expect(error).toContain('must match a schema in anyOf');
|
|
94
|
+
});
|
|
95
|
+
it('should handle arrays with item schemas', () => {
|
|
96
|
+
const schema = {
|
|
97
|
+
type: Type.ARRAY,
|
|
98
|
+
items: {
|
|
99
|
+
type: Type.OBJECT,
|
|
100
|
+
properties: {
|
|
101
|
+
id: { type: Type.NUMBER },
|
|
102
|
+
name: { type: Type.STRING },
|
|
103
|
+
},
|
|
104
|
+
required: ['id'],
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
const validData = [
|
|
108
|
+
{ id: 1, name: 'Item 1' },
|
|
109
|
+
{ id: 2, name: 'Item 2' },
|
|
110
|
+
];
|
|
111
|
+
expect(SchemaValidator.validate(schema, validData)).toBeNull();
|
|
112
|
+
const invalidData = [
|
|
113
|
+
{ id: 1, name: 'Item 1' },
|
|
114
|
+
{ name: 'Item 2' }, // missing required 'id'
|
|
115
|
+
];
|
|
116
|
+
const error = SchemaValidator.validate(schema, invalidData);
|
|
117
|
+
expect(error).toContain('must have required property');
|
|
118
|
+
});
|
|
119
|
+
it('should handle additionalProperties', () => {
|
|
120
|
+
const schema = {
|
|
121
|
+
type: Type.OBJECT,
|
|
122
|
+
properties: {
|
|
123
|
+
name: { type: Type.STRING },
|
|
124
|
+
},
|
|
125
|
+
additionalProperties: { type: Type.NUMBER },
|
|
126
|
+
};
|
|
127
|
+
const validData = { name: 'test', extra: 123 };
|
|
128
|
+
expect(SchemaValidator.validate(schema, validData)).toBeNull();
|
|
129
|
+
const invalidData = { name: 'test', extra: 'not a number' };
|
|
130
|
+
const error = SchemaValidator.validate(schema, invalidData);
|
|
131
|
+
expect(error).toContain('must be number');
|
|
132
|
+
});
|
|
133
|
+
it('should convert UPPERCASE type enums to lowercase', () => {
|
|
134
|
+
const schema = {
|
|
135
|
+
type: Type.OBJECT,
|
|
136
|
+
properties: {
|
|
137
|
+
name: { type: Type.STRING },
|
|
138
|
+
count: { type: Type.NUMBER },
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
const validData = { name: 'test', count: 5 };
|
|
142
|
+
expect(SchemaValidator.validate(schema, validData)).toBeNull();
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
//# sourceMappingURL=schemaValidator.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schemaValidator.test.js","sourceRoot":"","sources":["../../../src/utils/schemaValidator.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,QAAQ,CAAC,UAAU,EAAE,GAAG,EAAE;QAC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U,EAAE;oBACV,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;oBAC3B,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;iBAC7B;aACF,CAAC;YAEF,MAAM,SAAS,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;YAC7C,MAAM,CAAC,eAAe,CAAC,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;QACjE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../../src/utils/session.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,MAAM,CAAC,MAAM,SAAS,GAAG,UAAU,EAAE,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { ToolResult } from '../tools/tools.js';
|
|
7
|
+
import { GeminiClient } from '../core/client.js';
|
|
8
|
+
/**
|
|
9
|
+
* A function that summarizes the result of a tool execution.
|
|
10
|
+
*
|
|
11
|
+
* @param result The result of the tool execution.
|
|
12
|
+
* @returns The summary of the result.
|
|
13
|
+
*/
|
|
14
|
+
export type Summarizer = (result: ToolResult, geminiClient: GeminiClient, abortSignal: AbortSignal) => Promise<string>;
|
|
15
|
+
/**
|
|
16
|
+
* The default summarizer for tool results.
|
|
17
|
+
*
|
|
18
|
+
* @param result The result of the tool execution.
|
|
19
|
+
* @param geminiClient The Gemini client to use for summarization.
|
|
20
|
+
* @param abortSignal The abort signal to use for summarization.
|
|
21
|
+
* @returns The summary of the result.
|
|
22
|
+
*/
|
|
23
|
+
export declare const defaultSummarizer: Summarizer;
|
|
24
|
+
export declare const llmSummarizer: Summarizer;
|
|
25
|
+
export declare function summarizeToolOutput(textToSummarize: string, geminiClient: GeminiClient, abortSignal: AbortSignal, maxOutputTokens?: number): Promise<string>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js';
|
|
7
|
+
/**
|
|
8
|
+
* The default summarizer for tool results.
|
|
9
|
+
*
|
|
10
|
+
* @param result The result of the tool execution.
|
|
11
|
+
* @param geminiClient The Gemini client to use for summarization.
|
|
12
|
+
* @param abortSignal The abort signal to use for summarization.
|
|
13
|
+
* @returns The summary of the result.
|
|
14
|
+
*/
|
|
15
|
+
export const defaultSummarizer = (result, _geminiClient, _abortSignal) => Promise.resolve(JSON.stringify(result.llmContent));
|
|
16
|
+
// TODO: Move both these functions to utils
|
|
17
|
+
function partToString(part) {
|
|
18
|
+
if (!part) {
|
|
19
|
+
return '';
|
|
20
|
+
}
|
|
21
|
+
if (typeof part === 'string') {
|
|
22
|
+
return part;
|
|
23
|
+
}
|
|
24
|
+
if (Array.isArray(part)) {
|
|
25
|
+
return part.map(partToString).join('');
|
|
26
|
+
}
|
|
27
|
+
if ('text' in part) {
|
|
28
|
+
return part.text ?? '';
|
|
29
|
+
}
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
function getResponseText(response) {
|
|
33
|
+
if (response.candidates && response.candidates.length > 0) {
|
|
34
|
+
const candidate = response.candidates[0];
|
|
35
|
+
if (candidate.content &&
|
|
36
|
+
candidate.content.parts &&
|
|
37
|
+
candidate.content.parts.length > 0) {
|
|
38
|
+
return candidate.content.parts
|
|
39
|
+
.filter((part) => part.text)
|
|
40
|
+
.map((part) => part.text)
|
|
41
|
+
.join('');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
const SUMMARIZE_TOOL_OUTPUT_PROMPT = `Summarize the following tool output to be a maximum of {maxOutputTokens} tokens. The summary should be concise and capture the main points of the tool output.
|
|
47
|
+
|
|
48
|
+
The summarization should be done based on the content that is provided. Here are the basic rules to follow:
|
|
49
|
+
1. If the text is a directory listing or any output that is structural, use the history of the conversation to understand the context. Using this context try to understand what information we need from the tool output and return that as a response.
|
|
50
|
+
2. If the text is text content and there is nothing structural that we need, summarize the text.
|
|
51
|
+
3. If the text is the output of a shell command, use the history of the conversation to understand the context. Using this context try to understand what information we need from the tool output and return a summarization along with the stack trace of any error within the <error></error> tags. The stack trace should be complete and not truncated. If there are warnings, you should include them in the summary within <warning></warning> tags.
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
Text to summarize:
|
|
55
|
+
"{textToSummarize}"
|
|
56
|
+
|
|
57
|
+
Return the summary string which should first contain an overall summarization of text followed by the full stack trace of errors and warnings in the tool output.
|
|
58
|
+
`;
|
|
59
|
+
export const llmSummarizer = (result, geminiClient, abortSignal) => summarizeToolOutput(partToString(result.llmContent), geminiClient, abortSignal);
|
|
60
|
+
export async function summarizeToolOutput(textToSummarize, geminiClient, abortSignal, maxOutputTokens = 2000) {
|
|
61
|
+
// There is going to be a slight difference here since we are comparing length of string with maxOutputTokens.
|
|
62
|
+
// This is meant to be a ballpark estimation of if we need to summarize the tool output.
|
|
63
|
+
if (!textToSummarize || textToSummarize.length < maxOutputTokens) {
|
|
64
|
+
return textToSummarize;
|
|
65
|
+
}
|
|
66
|
+
const prompt = SUMMARIZE_TOOL_OUTPUT_PROMPT.replace('{maxOutputTokens}', String(maxOutputTokens)).replace('{textToSummarize}', textToSummarize);
|
|
67
|
+
const contents = [{ role: 'user', parts: [{ text: prompt }] }];
|
|
68
|
+
const toolOutputSummarizerConfig = {
|
|
69
|
+
maxOutputTokens,
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
const parsedResponse = (await geminiClient.generateContent(contents, toolOutputSummarizerConfig, abortSignal, DEFAULT_GEMINI_FLASH_MODEL));
|
|
73
|
+
return getResponseText(parsedResponse) || textToSummarize;
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
console.error('Failed to summarize tool output.', error);
|
|
77
|
+
return textToSummarize;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=summarizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"summarizer.js","sourceRoot":"","sources":["../../../src/utils/summarizer.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AASH,OAAO,EAAE,0BAA0B,EAAE,MAAM,qBAAqB,CAAC;AAejE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAe,CAC3C,MAAkB,EAClB,aAA2B,EAC3B,YAAyB,EACzB,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;AAExD,2CAA2C;AAC3C,SAAS,YAAY,CAAC,IAAmB;IACvC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO,IAAI,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzC,CAAC;IACD,IAAI,MAAM,IAAI,IAAI,EAAE,CAAC;QACnB,OAAO,IAAI,CAAC,IAAI,IAAI,EAAE,CAAC;IACzB,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,eAAe,CAAC,QAAiC;IACxD,IAAI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AAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;IAC1E,MAAM,0BAA0B,GAA0B;QACxD,eAAe;KAChB,CAAC;IACF,IAAI,CAAC;QACH,MAAM,cAAc,GAAG,CAAC,MAAM,YAAY,CAAC,eAAe,CACxD,QAAQ,EACR,0BAA0B,EAC1B,WAAW,EACX,0BAA0B,CAC3B,CAAuC,CAAC;QACzC,OAAO,eAAe,CAAC,cAAc,CAAC,IAAI,eAAe,CAAC;IAC5D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;QACzD,OAAO,eAAe,CAAC;IACzB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,131 @@
|
|
|
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 { GeminiClient } from '../core/client.js';
|
|
8
|
+
import { Config } from '../config/config.js';
|
|
9
|
+
import { summarizeToolOutput, llmSummarizer, defaultSummarizer, } from './summarizer.js';
|
|
10
|
+
// Mock GeminiClient and Config constructor
|
|
11
|
+
vi.mock('../core/client.js');
|
|
12
|
+
vi.mock('../config/config.js');
|
|
13
|
+
describe('summarizers', () => {
|
|
14
|
+
let mockGeminiClient;
|
|
15
|
+
let MockConfig;
|
|
16
|
+
const abortSignal = new AbortController().signal;
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
MockConfig = vi.mocked(Config);
|
|
19
|
+
const mockConfigInstance = new MockConfig('test-api-key', 'gemini-pro', false, '.', false, undefined, false, undefined, undefined, undefined);
|
|
20
|
+
mockGeminiClient = new GeminiClient(mockConfigInstance);
|
|
21
|
+
mockGeminiClient.generateContent = vi.fn();
|
|
22
|
+
vi.spyOn(console, 'error').mockImplementation(() => { });
|
|
23
|
+
});
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
vi.clearAllMocks();
|
|
26
|
+
console.error.mockRestore();
|
|
27
|
+
});
|
|
28
|
+
describe('summarizeToolOutput', () => {
|
|
29
|
+
it('should return original text if it is shorter than maxLength', async () => {
|
|
30
|
+
const shortText = 'This is a short text.';
|
|
31
|
+
const result = await summarizeToolOutput(shortText, mockGeminiClient, abortSignal, 2000);
|
|
32
|
+
expect(result).toBe(shortText);
|
|
33
|
+
expect(mockGeminiClient.generateContent).not.toHaveBeenCalled();
|
|
34
|
+
});
|
|
35
|
+
it('should return original text if it is empty', async () => {
|
|
36
|
+
const emptyText = '';
|
|
37
|
+
const result = await summarizeToolOutput(emptyText, mockGeminiClient, abortSignal, 2000);
|
|
38
|
+
expect(result).toBe(emptyText);
|
|
39
|
+
expect(mockGeminiClient.generateContent).not.toHaveBeenCalled();
|
|
40
|
+
});
|
|
41
|
+
it('should call generateContent if text is longer than maxLength', async () => {
|
|
42
|
+
const longText = 'This is a very long text.'.repeat(200);
|
|
43
|
+
const summary = 'This is a summary.';
|
|
44
|
+
mockGeminiClient.generateContent.mockResolvedValue({
|
|
45
|
+
candidates: [{ content: { parts: [{ text: summary }] } }],
|
|
46
|
+
});
|
|
47
|
+
const result = await summarizeToolOutput(longText, mockGeminiClient, abortSignal, 2000);
|
|
48
|
+
expect(mockGeminiClient.generateContent).toHaveBeenCalledTimes(1);
|
|
49
|
+
expect(result).toBe(summary);
|
|
50
|
+
});
|
|
51
|
+
it('should return original text if generateContent throws an error', async () => {
|
|
52
|
+
const longText = 'This is a very long text.'.repeat(200);
|
|
53
|
+
const error = new Error('API Error');
|
|
54
|
+
mockGeminiClient.generateContent.mockRejectedValue(error);
|
|
55
|
+
const result = await summarizeToolOutput(longText, mockGeminiClient, abortSignal, 2000);
|
|
56
|
+
expect(mockGeminiClient.generateContent).toHaveBeenCalledTimes(1);
|
|
57
|
+
expect(result).toBe(longText);
|
|
58
|
+
expect(console.error).toHaveBeenCalledWith('Failed to summarize tool output.', error);
|
|
59
|
+
});
|
|
60
|
+
it('should construct the correct prompt for summarization', async () => {
|
|
61
|
+
const longText = 'This is a very long text.'.repeat(200);
|
|
62
|
+
const summary = 'This is a summary.';
|
|
63
|
+
mockGeminiClient.generateContent.mockResolvedValue({
|
|
64
|
+
candidates: [{ content: { parts: [{ text: summary }] } }],
|
|
65
|
+
});
|
|
66
|
+
await summarizeToolOutput(longText, mockGeminiClient, abortSignal, 1000);
|
|
67
|
+
const expectedPrompt = `Summarize the following tool output to be a maximum of 1000 tokens. The summary should be concise and capture the main points of the tool output.
|
|
68
|
+
|
|
69
|
+
The summarization should be done based on the content that is provided. Here are the basic rules to follow:
|
|
70
|
+
1. If the text is a directory listing or any output that is structural, use the history of the conversation to understand the context. Using this context try to understand what information we need from the tool output and return that as a response.
|
|
71
|
+
2. If the text is text content and there is nothing structural that we need, summarize the text.
|
|
72
|
+
3. If the text is the output of a shell command, use the history of the conversation to understand the context. Using this context try to understand what information we need from the tool output and return a summarization along with the stack trace of any error within the <error></error> tags. The stack trace should be complete and not truncated. If there are warnings, you should include them in the summary within <warning></warning> tags.
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
Text to summarize:
|
|
76
|
+
"${longText}"
|
|
77
|
+
|
|
78
|
+
Return the summary string which should first contain an overall summarization of text followed by the full stack trace of errors and warnings in the tool output.
|
|
79
|
+
`;
|
|
80
|
+
const calledWith = mockGeminiClient.generateContent.mock
|
|
81
|
+
.calls[0];
|
|
82
|
+
const contents = calledWith[0];
|
|
83
|
+
expect(contents[0].parts[0].text).toBe(expectedPrompt);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
describe('llmSummarizer', () => {
|
|
87
|
+
it('should summarize tool output using summarizeToolOutput', async () => {
|
|
88
|
+
const toolResult = {
|
|
89
|
+
llmContent: 'This is a very long text.'.repeat(200),
|
|
90
|
+
returnDisplay: '',
|
|
91
|
+
};
|
|
92
|
+
const summary = 'This is a summary.';
|
|
93
|
+
mockGeminiClient.generateContent.mockResolvedValue({
|
|
94
|
+
candidates: [{ content: { parts: [{ text: summary }] } }],
|
|
95
|
+
});
|
|
96
|
+
const result = await llmSummarizer(toolResult, mockGeminiClient, abortSignal);
|
|
97
|
+
expect(mockGeminiClient.generateContent).toHaveBeenCalledTimes(1);
|
|
98
|
+
expect(result).toBe(summary);
|
|
99
|
+
});
|
|
100
|
+
it('should handle different llmContent types', async () => {
|
|
101
|
+
const longText = 'This is a very long text.'.repeat(200);
|
|
102
|
+
const toolResult = {
|
|
103
|
+
llmContent: [{ text: longText }],
|
|
104
|
+
returnDisplay: '',
|
|
105
|
+
};
|
|
106
|
+
const summary = 'This is a summary.';
|
|
107
|
+
mockGeminiClient.generateContent.mockResolvedValue({
|
|
108
|
+
candidates: [{ content: { parts: [{ text: summary }] } }],
|
|
109
|
+
});
|
|
110
|
+
const result = await llmSummarizer(toolResult, mockGeminiClient, abortSignal);
|
|
111
|
+
expect(mockGeminiClient.generateContent).toHaveBeenCalledTimes(1);
|
|
112
|
+
const calledWith = mockGeminiClient.generateContent.mock
|
|
113
|
+
.calls[0];
|
|
114
|
+
const contents = calledWith[0];
|
|
115
|
+
expect(contents[0].parts[0].text).toContain(`"${longText}"`);
|
|
116
|
+
expect(result).toBe(summary);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
describe('defaultSummarizer', () => {
|
|
120
|
+
it('should stringify the llmContent', async () => {
|
|
121
|
+
const toolResult = {
|
|
122
|
+
llmContent: { text: 'some data' },
|
|
123
|
+
returnDisplay: '',
|
|
124
|
+
};
|
|
125
|
+
const result = await defaultSummarizer(toolResult, mockGeminiClient, abortSignal);
|
|
126
|
+
expect(result).toBe(JSON.stringify({ text: 'some data' }));
|
|
127
|
+
expect(mockGeminiClient.generateContent).not.toHaveBeenCalled();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
//# sourceMappingURL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,MAAM,GAAG,MAAM,iBAAiB,CACpC,UAAU,EACV,gBAAgB,EAChB,WAAW,CACZ,CAAC;YAEF,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC;YAC3D,MAAM,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAC;QAClE,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Check if we should simulate a 429 error for the current request
|
|
8
|
+
*/
|
|
9
|
+
export declare function shouldSimulate429(authType?: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Reset the request counter (useful for tests)
|
|
12
|
+
*/
|
|
13
|
+
export declare function resetRequestCounter(): void;
|
|
14
|
+
/**
|
|
15
|
+
* Disable 429 simulation after successful fallback
|
|
16
|
+
*/
|
|
17
|
+
export declare function disableSimulationAfterFallback(): void;
|
|
18
|
+
/**
|
|
19
|
+
* Create a simulated 429 error response
|
|
20
|
+
*/
|
|
21
|
+
export declare function createSimulated429Error(): Error;
|
|
22
|
+
/**
|
|
23
|
+
* Reset simulation state when switching auth methods
|
|
24
|
+
*/
|
|
25
|
+
export declare function resetSimulationState(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Enable/disable 429 simulation programmatically (for tests)
|
|
28
|
+
*/
|
|
29
|
+
export declare function setSimulate429(enabled: boolean, afterRequests?: number, forAuthType?: string): void;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Testing utilities for simulating 429 errors in unit tests
|
|
8
|
+
*/
|
|
9
|
+
let requestCounter = 0;
|
|
10
|
+
let simulate429Enabled = false;
|
|
11
|
+
let simulate429AfterRequests = 0;
|
|
12
|
+
let simulate429ForAuthType;
|
|
13
|
+
let fallbackOccurred = false;
|
|
14
|
+
/**
|
|
15
|
+
* Check if we should simulate a 429 error for the current request
|
|
16
|
+
*/
|
|
17
|
+
export function shouldSimulate429(authType) {
|
|
18
|
+
if (!simulate429Enabled || fallbackOccurred) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
// If auth type filter is set, only simulate for that auth type
|
|
22
|
+
if (simulate429ForAuthType && authType !== simulate429ForAuthType) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
requestCounter++;
|
|
26
|
+
// If afterRequests is set, only simulate after that many requests
|
|
27
|
+
if (simulate429AfterRequests > 0) {
|
|
28
|
+
return requestCounter > simulate429AfterRequests;
|
|
29
|
+
}
|
|
30
|
+
// Otherwise, simulate for every request
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Reset the request counter (useful for tests)
|
|
35
|
+
*/
|
|
36
|
+
export function resetRequestCounter() {
|
|
37
|
+
requestCounter = 0;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Disable 429 simulation after successful fallback
|
|
41
|
+
*/
|
|
42
|
+
export function disableSimulationAfterFallback() {
|
|
43
|
+
fallbackOccurred = true;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a simulated 429 error response
|
|
47
|
+
*/
|
|
48
|
+
export function createSimulated429Error() {
|
|
49
|
+
const error = new Error('Rate limit exceeded (simulated)');
|
|
50
|
+
error.status = 429;
|
|
51
|
+
return error;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Reset simulation state when switching auth methods
|
|
55
|
+
*/
|
|
56
|
+
export function resetSimulationState() {
|
|
57
|
+
fallbackOccurred = false;
|
|
58
|
+
resetRequestCounter();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Enable/disable 429 simulation programmatically (for tests)
|
|
62
|
+
*/
|
|
63
|
+
export function setSimulate429(enabled, afterRequests = 0, forAuthType) {
|
|
64
|
+
simulate429Enabled = enabled;
|
|
65
|
+
simulate429AfterRequests = afterRequests;
|
|
66
|
+
simulate429ForAuthType = forAuthType;
|
|
67
|
+
fallbackOccurred = false; // Reset fallback state when simulation is re-enabled
|
|
68
|
+
resetRequestCounter();
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=testUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testUtils.js","sourceRoot":"","sources":["../../../src/utils/testUtils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AAEH,IAAI,cAAc,GAAG,CAAC,CAAC;AACvB,IAAI,kBAAkB,GAAG,KAAK,CAAC;AAC/B,IAAI,wBAAwB,GAAG,CAAC,CAAC;AACjC,IAAI,sBAA0C,CAAC;AAC/C,IAAI,gBAAgB,GAAG,KAAK,CAAC;AAE7B;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAiB;IACjD,IAAI,CAAC,kBAAkB,IAAI,gBAAgB,EAAE,CAAC;QAC5C,OAAO,KAAK,CAAC;IACf,CAAC;IAED,+DAA+D;IAC/D,IAAI,sBAAsB,IAAI,QAAQ,KAAK,sBAAsB,EAAE,CAAC;QAClE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,cAAc,EAAE,CAAC;IAEjB,kEAAkE;IAClE,IAAI,wBAAwB,GAAG,CAAC,EAAE,CAAC;QACjC,OAAO,cAAc,GAAG,wBAAwB,CAAC;IACnD,CAAC;IAED,wCAAwC;IACxC,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB;IACjC,cAAc,GAAG,CAAC,CAAC;AACrB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,8BAA8B;IAC5C,gBAAgB,GAAG,IAAI,CAAC;AAC1B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,uBAAuB;IACrC,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,iCAAiC,CAExD,CAAC;IACF,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC;IACnB,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,gBAAgB,GAAG,KAAK,CAAC;IACzB,mBAAmB,EAAE,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc,CAC5B,OAAgB,EAChB,aAAa,GAAG,CAAC,EACjB,WAAoB;IAEpB,kBAAkB,GAAG,OAAO,CAAC;IAC7B,wBAAwB,GAAG,aAAa,CAAC;IACzC,sBAAsB,GAAG,WAAW,CAAC;IACrC,gBAAgB,GAAG,KAAK,CAAC,CAAC,qDAAqD;IAC/E,mBAAmB,EAAE,CAAC;AACxB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
export declare function cacheGoogleAccount(email: string): Promise<void>;
|
|
7
|
+
export declare function getCachedGoogleAccount(): string | null;
|
|
8
|
+
export declare function getLifetimeGoogleAccounts(): number;
|
|
9
|
+
export declare function clearCachedGoogleAccount(): Promise<void>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { promises as fsp, existsSync, readFileSync } from 'node:fs';
|
|
8
|
+
import * as os from 'os';
|
|
9
|
+
import { LLXPRT_DIR, GOOGLE_ACCOUNTS_FILENAME } from './paths.js';
|
|
10
|
+
function getGoogleAccountsCachePath() {
|
|
11
|
+
return path.join(os.homedir(), LLXPRT_DIR, GOOGLE_ACCOUNTS_FILENAME);
|
|
12
|
+
}
|
|
13
|
+
async function readAccounts(filePath) {
|
|
14
|
+
try {
|
|
15
|
+
const content = await fsp.readFile(filePath, 'utf-8');
|
|
16
|
+
if (!content.trim()) {
|
|
17
|
+
return { active: null, old: [] };
|
|
18
|
+
}
|
|
19
|
+
return JSON.parse(content);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
|
|
23
|
+
// File doesn't exist, which is fine.
|
|
24
|
+
return { active: null, old: [] };
|
|
25
|
+
}
|
|
26
|
+
// File is corrupted or not valid JSON, start with a fresh object.
|
|
27
|
+
console.debug('Could not parse accounts file, starting fresh.', error);
|
|
28
|
+
return { active: null, old: [] };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export async function cacheGoogleAccount(email) {
|
|
32
|
+
const filePath = getGoogleAccountsCachePath();
|
|
33
|
+
await fsp.mkdir(path.dirname(filePath), { recursive: true });
|
|
34
|
+
const accounts = await readAccounts(filePath);
|
|
35
|
+
if (accounts.active && accounts.active !== email) {
|
|
36
|
+
if (!accounts.old.includes(accounts.active)) {
|
|
37
|
+
accounts.old.push(accounts.active);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// If the new email was in the old list, remove it
|
|
41
|
+
accounts.old = accounts.old.filter((oldEmail) => oldEmail !== email);
|
|
42
|
+
accounts.active = email;
|
|
43
|
+
await fsp.writeFile(filePath, JSON.stringify(accounts, null, 2), 'utf-8');
|
|
44
|
+
}
|
|
45
|
+
export function getCachedGoogleAccount() {
|
|
46
|
+
try {
|
|
47
|
+
const filePath = getGoogleAccountsCachePath();
|
|
48
|
+
if (existsSync(filePath)) {
|
|
49
|
+
const content = readFileSync(filePath, 'utf-8').trim();
|
|
50
|
+
if (!content) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const accounts = JSON.parse(content);
|
|
54
|
+
return accounts.active;
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.debug('Error reading cached Google Account:', error);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export function getLifetimeGoogleAccounts() {
|
|
64
|
+
try {
|
|
65
|
+
const filePath = getGoogleAccountsCachePath();
|
|
66
|
+
if (!existsSync(filePath)) {
|
|
67
|
+
return 0;
|
|
68
|
+
}
|
|
69
|
+
const content = readFileSync(filePath, 'utf-8').trim();
|
|
70
|
+
if (!content) {
|
|
71
|
+
return 0;
|
|
72
|
+
}
|
|
73
|
+
const accounts = JSON.parse(content);
|
|
74
|
+
let count = accounts.old.length;
|
|
75
|
+
if (accounts.active) {
|
|
76
|
+
count++;
|
|
77
|
+
}
|
|
78
|
+
return count;
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
console.debug('Error reading lifetime Google Accounts:', error);
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export async function clearCachedGoogleAccount() {
|
|
86
|
+
const filePath = getGoogleAccountsCachePath();
|
|
87
|
+
if (!existsSync(filePath)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const accounts = await readAccounts(filePath);
|
|
91
|
+
if (accounts.active) {
|
|
92
|
+
if (!accounts.old.includes(accounts.active)) {
|
|
93
|
+
accounts.old.push(accounts.active);
|
|
94
|
+
}
|
|
95
|
+
accounts.active = null;
|
|
96
|
+
}
|
|
97
|
+
await fsp.writeFile(filePath, JSON.stringify(accounts, null, 2), 'utf-8');
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=user_account.js.map
|