@google/gemini-cli-core 0.10.0-nightly.20250926.1487841d → 0.10.0-nightly.20251009.ae02236c
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -71
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/src/agents/codebase-investigator.d.ts +46 -0
- package/dist/src/agents/codebase-investigator.js +136 -0
- package/dist/src/agents/codebase-investigator.js.map +1 -0
- package/dist/src/agents/executor.d.ts +92 -0
- package/dist/src/agents/executor.js +580 -0
- package/dist/src/agents/executor.js.map +1 -0
- package/dist/src/agents/executor.test.d.ts +6 -0
- package/dist/src/agents/executor.test.js +595 -0
- package/dist/src/agents/executor.test.js.map +1 -0
- package/dist/src/agents/invocation.d.ts +46 -0
- package/dist/src/agents/invocation.js +102 -0
- package/dist/src/agents/invocation.js.map +1 -0
- package/dist/src/agents/invocation.test.d.ts +6 -0
- package/dist/src/agents/invocation.test.js +215 -0
- package/dist/src/agents/invocation.test.js.map +1 -0
- package/dist/src/agents/registry.d.ts +36 -0
- package/dist/src/agents/registry.js +60 -0
- package/dist/src/agents/registry.js.map +1 -0
- package/dist/src/agents/registry.test.d.ts +6 -0
- package/dist/src/agents/registry.test.js +146 -0
- package/dist/src/agents/registry.test.js.map +1 -0
- package/dist/src/agents/schema-utils.d.ts +39 -0
- package/dist/src/agents/schema-utils.js +57 -0
- package/dist/src/agents/schema-utils.js.map +1 -0
- package/dist/src/agents/schema-utils.test.d.ts +6 -0
- package/dist/src/agents/schema-utils.test.js +144 -0
- package/dist/src/agents/schema-utils.test.js.map +1 -0
- package/dist/src/agents/subagent-tool-wrapper.d.ts +38 -0
- package/dist/src/agents/subagent-tool-wrapper.js +48 -0
- package/dist/src/agents/subagent-tool-wrapper.js.map +1 -0
- package/dist/src/agents/subagent-tool-wrapper.test.d.ts +6 -0
- package/dist/src/agents/subagent-tool-wrapper.test.js +112 -0
- package/dist/src/agents/subagent-tool-wrapper.test.js.map +1 -0
- package/dist/src/agents/types.d.ts +145 -0
- package/dist/src/agents/types.js +18 -0
- package/dist/src/agents/types.js.map +1 -0
- package/dist/src/agents/utils.d.ts +15 -0
- package/dist/src/agents/utils.js +29 -0
- package/dist/src/agents/utils.js.map +1 -0
- package/dist/src/agents/utils.test.d.ts +6 -0
- package/dist/src/agents/utils.test.js +87 -0
- package/dist/src/agents/utils.test.js.map +1 -0
- package/dist/src/code_assist/setup.js +4 -2
- package/dist/src/code_assist/setup.js.map +1 -1
- package/dist/src/config/config.d.ts +28 -5
- package/dist/src/config/config.js +61 -7
- package/dist/src/config/config.js.map +1 -1
- package/dist/src/config/config.test.js +63 -0
- package/dist/src/config/config.test.js.map +1 -1
- package/dist/src/core/baseLlmClient.js +19 -21
- package/dist/src/core/baseLlmClient.js.map +1 -1
- package/dist/src/core/baseLlmClient.test.js +57 -17
- package/dist/src/core/baseLlmClient.test.js.map +1 -1
- package/dist/src/core/client.d.ts +2 -0
- package/dist/src/core/client.js +52 -43
- package/dist/src/core/client.js.map +1 -1
- package/dist/src/core/client.test.js +300 -95
- package/dist/src/core/client.test.js.map +1 -1
- package/dist/src/core/contentGenerator.js +3 -1
- package/dist/src/core/contentGenerator.js.map +1 -1
- package/dist/src/core/coreToolScheduler.test.js +33 -23
- package/dist/src/core/coreToolScheduler.test.js.map +1 -1
- package/dist/src/core/geminiChat.d.ts +6 -0
- package/dist/src/core/geminiChat.js +21 -18
- package/dist/src/core/geminiChat.js.map +1 -1
- package/dist/src/core/geminiChat.test.js +20 -19
- package/dist/src/core/geminiChat.test.js.map +1 -1
- package/dist/src/core/nonInteractiveToolExecutor.test.js +11 -11
- package/dist/src/core/nonInteractiveToolExecutor.test.js.map +1 -1
- package/dist/src/core/prompts.d.ts +2 -1
- package/dist/src/core/prompts.js +88 -15
- package/dist/src/core/prompts.js.map +1 -1
- package/dist/src/core/prompts.test.js +73 -24
- package/dist/src/core/prompts.test.js.map +1 -1
- package/dist/src/core/turn.d.ts +10 -2
- package/dist/src/core/turn.js +6 -1
- package/dist/src/core/turn.js.map +1 -1
- package/dist/src/core/turn.test.js +1 -1
- package/dist/src/core/turn.test.js.map +1 -1
- package/dist/src/generated/git-commit.d.ts +2 -2
- package/dist/src/generated/git-commit.js +2 -2
- package/dist/src/ide/detect-ide.d.ts +1 -0
- package/dist/src/ide/detect-ide.js +4 -1
- package/dist/src/ide/detect-ide.js.map +1 -1
- package/dist/src/ide/detect-ide.test.js +11 -0
- package/dist/src/ide/detect-ide.test.js.map +1 -1
- package/dist/src/ide/ide-client.js +3 -3
- package/dist/src/ide/ide-client.test.js +4 -4
- package/dist/src/ide/ide-installer.js +1 -1
- package/dist/src/ide/ide-installer.js.map +1 -1
- package/dist/src/ide/ide-installer.test.js +13 -1
- package/dist/src/ide/ide-installer.test.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/mcp/sa-impersonation-provider.d.ts +33 -0
- package/dist/src/mcp/sa-impersonation-provider.js +130 -0
- package/dist/src/mcp/sa-impersonation-provider.js.map +1 -0
- package/dist/src/mcp/sa-impersonation-provider.test.d.ts +6 -0
- package/dist/src/mcp/sa-impersonation-provider.test.js +117 -0
- package/dist/src/mcp/sa-impersonation-provider.test.js.map +1 -0
- package/dist/src/services/chatRecordingService.d.ts +2 -1
- package/dist/src/services/chatRecordingService.js +2 -1
- package/dist/src/services/chatRecordingService.js.map +1 -1
- package/dist/src/services/fileSystemService.d.ts +9 -0
- package/dist/src/services/fileSystemService.js +11 -0
- package/dist/src/services/fileSystemService.js.map +1 -1
- package/dist/src/services/shellExecutionService.d.ts +2 -0
- package/dist/src/services/shellExecutionService.js +48 -7
- package/dist/src/services/shellExecutionService.js.map +1 -1
- package/dist/src/services/shellExecutionService.test.js +13 -4
- package/dist/src/services/shellExecutionService.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.d.ts +12 -2
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js +79 -9
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js +99 -1
- package/dist/src/telemetry/clearcut-logger/clearcut-logger.test.js.map +1 -1
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.d.ts +11 -3
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js +27 -4
- package/dist/src/telemetry/clearcut-logger/event-metadata-key.js.map +1 -1
- package/dist/src/telemetry/constants.d.ts +6 -24
- package/dist/src/telemetry/constants.js +7 -25
- package/dist/src/telemetry/constants.js.map +1 -1
- package/dist/src/telemetry/index.d.ts +5 -3
- package/dist/src/telemetry/index.js +10 -3
- package/dist/src/telemetry/index.js.map +1 -1
- package/dist/src/telemetry/loggers.d.ts +6 -1
- package/dist/src/telemetry/loggers.js +132 -12
- package/dist/src/telemetry/loggers.js.map +1 -1
- package/dist/src/telemetry/loggers.test.circular.js +3 -3
- package/dist/src/telemetry/loggers.test.circular.js.map +1 -1
- package/dist/src/telemetry/loggers.test.js +160 -13
- package/dist/src/telemetry/loggers.test.js.map +1 -1
- package/dist/src/telemetry/memory-monitor.d.ts +149 -0
- package/dist/src/telemetry/memory-monitor.js +335 -0
- package/dist/src/telemetry/memory-monitor.js.map +1 -0
- package/dist/src/telemetry/memory-monitor.test.d.ts +6 -0
- package/dist/src/telemetry/memory-monitor.test.js +472 -0
- package/dist/src/telemetry/memory-monitor.test.js.map +1 -0
- package/dist/src/telemetry/metrics.d.ts +392 -20
- package/dist/src/telemetry/metrics.js +463 -235
- package/dist/src/telemetry/metrics.js.map +1 -1
- package/dist/src/telemetry/metrics.test.js +391 -55
- package/dist/src/telemetry/metrics.test.js.map +1 -1
- package/dist/src/telemetry/types.d.ts +37 -1
- package/dist/src/telemetry/types.js +60 -0
- package/dist/src/telemetry/types.js.map +1 -1
- package/dist/src/telemetry/uiTelemetry.test.js +2 -2
- package/dist/src/telemetry/uiTelemetry.test.js.map +1 -1
- package/dist/src/test-utils/mock-tool.d.ts +28 -3
- package/dist/src/test-utils/mock-tool.js +71 -1
- package/dist/src/test-utils/mock-tool.js.map +1 -1
- package/dist/src/tools/glob.js +2 -1
- package/dist/src/tools/glob.js.map +1 -1
- package/dist/src/tools/mcp-client.d.ts +3 -2
- package/dist/src/tools/mcp-client.js +44 -30
- package/dist/src/tools/mcp-client.js.map +1 -1
- package/dist/src/tools/mcp-client.test.js +168 -5
- package/dist/src/tools/mcp-client.test.js.map +1 -1
- package/dist/src/tools/shell.js +2 -2
- package/dist/src/tools/shell.js.map +1 -1
- package/dist/src/tools/shell.test.js +1 -1
- package/dist/src/tools/shell.test.js.map +1 -1
- package/dist/src/tools/smart-edit.d.ts +1 -1
- package/dist/src/tools/smart-edit.js +114 -10
- package/dist/src/tools/smart-edit.js.map +1 -1
- package/dist/src/tools/smart-edit.test.js +91 -29
- package/dist/src/tools/smart-edit.test.js.map +1 -1
- package/dist/src/tools/tool-names.d.ts +8 -0
- package/dist/src/tools/tool-names.js +17 -0
- package/dist/src/tools/tool-names.js.map +1 -0
- package/dist/src/tools/tool-registry.test.js +10 -10
- package/dist/src/tools/tool-registry.test.js.map +1 -1
- package/dist/src/tools/web-fetch.js +3 -0
- package/dist/src/tools/web-fetch.js.map +1 -1
- package/dist/src/tools/web-fetch.test.js +44 -0
- package/dist/src/tools/web-fetch.test.js.map +1 -1
- package/dist/src/tools/write-file.js +2 -1
- package/dist/src/tools/write-file.js.map +1 -1
- package/dist/src/tools/write-todos.d.ts +1 -1
- package/dist/src/tools/write-todos.js +4 -3
- package/dist/src/tools/write-todos.js.map +1 -1
- package/dist/src/utils/editCorrector.js +2 -2
- package/dist/src/utils/editCorrector.js.map +1 -1
- package/dist/src/utils/editor.js +1 -0
- package/dist/src/utils/editor.js.map +1 -1
- package/dist/src/utils/editor.test.js +1 -0
- package/dist/src/utils/editor.test.js.map +1 -1
- package/dist/src/utils/errorParsing.d.ts +1 -1
- package/dist/src/utils/errorParsing.js +5 -33
- package/dist/src/utils/errorParsing.js.map +1 -1
- package/dist/src/utils/errorParsing.test.js +0 -88
- package/dist/src/utils/errorParsing.test.js.map +1 -1
- package/dist/src/utils/flashFallback.test.js +26 -45
- package/dist/src/utils/flashFallback.test.js.map +1 -1
- package/dist/src/utils/formatters.d.ts +1 -0
- package/dist/src/utils/formatters.js +2 -1
- package/dist/src/utils/formatters.js.map +1 -1
- package/dist/src/utils/formatters.test.d.ts +6 -0
- package/dist/src/utils/formatters.test.js +26 -0
- package/dist/src/utils/formatters.test.js.map +1 -0
- package/dist/src/utils/googleErrors.d.ts +104 -0
- package/dist/src/utils/googleErrors.js +108 -0
- package/dist/src/utils/googleErrors.js.map +1 -0
- package/dist/src/utils/googleErrors.test.d.ts +6 -0
- package/dist/src/utils/googleErrors.test.js +212 -0
- package/dist/src/utils/googleErrors.test.js.map +1 -0
- package/dist/src/utils/googleQuotaErrors.d.ts +35 -0
- package/dist/src/utils/googleQuotaErrors.js +108 -0
- package/dist/src/utils/googleQuotaErrors.js.map +1 -0
- package/dist/src/utils/googleQuotaErrors.test.d.ts +6 -0
- package/dist/src/utils/googleQuotaErrors.test.js +189 -0
- package/dist/src/utils/googleQuotaErrors.test.js.map +1 -0
- package/dist/src/utils/llm-edit-fixer.js +13 -4
- package/dist/src/utils/llm-edit-fixer.js.map +1 -1
- package/dist/src/utils/llm-edit-fixer.test.js +81 -0
- package/dist/src/utils/llm-edit-fixer.test.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.d.ts +1 -0
- package/dist/src/utils/memoryDiscovery.js +2 -1
- package/dist/src/utils/memoryDiscovery.js.map +1 -1
- package/dist/src/utils/memoryDiscovery.test.js +99 -21
- package/dist/src/utils/memoryDiscovery.test.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.js +13 -20
- package/dist/src/utils/memoryImportProcessor.js.map +1 -1
- package/dist/src/utils/memoryImportProcessor.test.js +14 -0
- package/dist/src/utils/memoryImportProcessor.test.js.map +1 -1
- package/dist/src/utils/pathCorrector.d.ts +25 -0
- package/dist/src/utils/pathCorrector.js +33 -0
- package/dist/src/utils/pathCorrector.js.map +1 -0
- package/dist/src/utils/pathCorrector.test.d.ts +6 -0
- package/dist/src/utils/pathCorrector.test.js +83 -0
- package/dist/src/utils/pathCorrector.test.js.map +1 -0
- package/dist/src/utils/quotaErrorDetection.d.ts +0 -2
- package/dist/src/utils/quotaErrorDetection.js +0 -46
- package/dist/src/utils/quotaErrorDetection.js.map +1 -1
- package/dist/src/utils/retry.d.ts +3 -1
- package/dist/src/utils/retry.js +53 -161
- package/dist/src/utils/retry.js.map +1 -1
- package/dist/src/utils/retry.test.js +87 -146
- package/dist/src/utils/retry.test.js.map +1 -1
- package/dist/src/utils/terminalSerializer.d.ts +1 -4
- package/dist/src/utils/terminalSerializer.js +3 -3
- package/dist/src/utils/terminalSerializer.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/src/test-utils/tools.d.ts +0 -45
- package/dist/src/test-utils/tools.js +0 -105
- package/dist/src/test-utils/tools.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pathCorrector.js","sourceRoot":"","sources":["../../../src/utils/pathCorrector.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAwBlC,MAAM,UAAU,WAAW,CACzB,QAAgB,EAChB,MAAc;IAEd,kEAAkE;IAClE,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,EAAE,QAAQ,CAAC,CAAC;IAC9D,IAAI,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,CAAC;IACtD,CAAC;IAED,wFAAwF;IACxF,MAAM,gBAAgB,GAAG,MAAM,CAAC,mBAAmB,EAAE,CAAC;IACtD,MAAM,UAAU,GAAG,MAAM,CAAC,oBAAoB,EAAE,CAAC;IACjD,MAAM,WAAW,GAAG,gBAAgB,CAAC,cAAc,EAAE,CAAC;IACtD,MAAM,UAAU,GAAG,UAAU,CAAC,SAAS,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;IAE/D,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,uBAAuB,QAAQ,6BAA6B;SACpE,CAAC;IACJ,CAAC;IAED,IAAI,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,kBAAkB,QAAQ,4FAA4F,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;SACrJ,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;AACzD,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
|
|
7
|
+
import * as fs from 'node:fs';
|
|
8
|
+
import * as path from 'node:path';
|
|
9
|
+
import * as os from 'node:os';
|
|
10
|
+
import { createMockWorkspaceContext } from '../test-utils/mockWorkspaceContext.js';
|
|
11
|
+
import { StandardFileSystemService } from '../services/fileSystemService.js';
|
|
12
|
+
import { correctPath } from './pathCorrector.js';
|
|
13
|
+
describe('pathCorrector', () => {
|
|
14
|
+
let tempDir;
|
|
15
|
+
let rootDir;
|
|
16
|
+
let otherWorkspaceDir;
|
|
17
|
+
let mockConfig;
|
|
18
|
+
beforeEach(() => {
|
|
19
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'path-corrector-test-'));
|
|
20
|
+
rootDir = path.join(tempDir, 'root');
|
|
21
|
+
otherWorkspaceDir = path.join(tempDir, 'other');
|
|
22
|
+
fs.mkdirSync(rootDir, { recursive: true });
|
|
23
|
+
fs.mkdirSync(otherWorkspaceDir, { recursive: true });
|
|
24
|
+
mockConfig = {
|
|
25
|
+
getTargetDir: () => rootDir,
|
|
26
|
+
getWorkspaceContext: () => createMockWorkspaceContext(rootDir, [otherWorkspaceDir]),
|
|
27
|
+
getFileSystemService: () => new StandardFileSystemService(),
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
32
|
+
vi.restoreAllMocks();
|
|
33
|
+
});
|
|
34
|
+
it('should correct a relative path if it is unambiguous in the target dir', () => {
|
|
35
|
+
const testFile = 'unique.txt';
|
|
36
|
+
fs.writeFileSync(path.join(rootDir, testFile), 'content');
|
|
37
|
+
const result = correctPath(testFile, mockConfig);
|
|
38
|
+
expect(result.success).toBe(true);
|
|
39
|
+
if (result.success) {
|
|
40
|
+
expect(result.correctedPath).toBe(path.join(rootDir, testFile));
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
it('should correct a partial relative path if it is unambiguous in another workspace dir', () => {
|
|
44
|
+
const subDir = path.join(otherWorkspaceDir, 'sub');
|
|
45
|
+
fs.mkdirSync(subDir);
|
|
46
|
+
const testFile = 'file.txt';
|
|
47
|
+
const fullPath = path.join(subDir, testFile);
|
|
48
|
+
fs.writeFileSync(fullPath, 'content');
|
|
49
|
+
const result = correctPath(testFile, mockConfig);
|
|
50
|
+
expect(result.success).toBe(true);
|
|
51
|
+
if (result.success) {
|
|
52
|
+
expect(result.correctedPath).toBe(fullPath);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
it('should return an error for a relative path that does not exist', () => {
|
|
56
|
+
const result = correctPath('nonexistent.txt', mockConfig);
|
|
57
|
+
expect(result.success).toBe(false);
|
|
58
|
+
if (!result.success) {
|
|
59
|
+
expect(result.error).toMatch(/File not found for 'nonexistent.txt' and path is not absolute./);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
expect.fail('Expected path correction to fail.');
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
it('should return an error for an ambiguous path', () => {
|
|
66
|
+
const ambiguousFile = 'component.ts';
|
|
67
|
+
const subDir1 = path.join(rootDir, 'module1');
|
|
68
|
+
const subDir2 = path.join(otherWorkspaceDir, 'module2');
|
|
69
|
+
fs.mkdirSync(subDir1, { recursive: true });
|
|
70
|
+
fs.mkdirSync(subDir2, { recursive: true });
|
|
71
|
+
fs.writeFileSync(path.join(subDir1, ambiguousFile), 'content 1');
|
|
72
|
+
fs.writeFileSync(path.join(subDir2, ambiguousFile), 'content 2');
|
|
73
|
+
const result = correctPath(ambiguousFile, mockConfig);
|
|
74
|
+
expect(result.success).toBe(false);
|
|
75
|
+
if (!result.success) {
|
|
76
|
+
expect(result.error).toMatch(/The file path 'component.ts' is ambiguous and matches multiple files./);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
expect.fail('Expected path correction to fail.');
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=pathCorrector.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pathCorrector.test.js","sourceRoot":"","sources":["../../../src/utils/pathCorrector.test.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MA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AM,CAAC,KAAK,CAAC,CAAC,OAAO,CAC1B,uEAAuE,CACxE,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,IAAI,CAAC,mCAAmC,CAAC,CAAC;QACnD,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -14,5 +14,3 @@ export interface ApiError {
|
|
|
14
14
|
}
|
|
15
15
|
export declare function isApiError(error: unknown): error is ApiError;
|
|
16
16
|
export declare function isStructuredError(error: unknown): error is StructuredError;
|
|
17
|
-
export declare function isProQuotaExceededError(error: unknown): boolean;
|
|
18
|
-
export declare function isGenericQuotaExceededError(error: unknown): boolean;
|
|
@@ -16,50 +16,4 @@ export function isStructuredError(error) {
|
|
|
16
16
|
'message' in error &&
|
|
17
17
|
typeof error.message === 'string');
|
|
18
18
|
}
|
|
19
|
-
export function isProQuotaExceededError(error) {
|
|
20
|
-
// Check for Pro quota exceeded errors by looking for the specific pattern
|
|
21
|
-
// This will match patterns like:
|
|
22
|
-
// - "Quota exceeded for quota metric 'Gemini 2.5 Pro Requests'"
|
|
23
|
-
// - "Quota exceeded for quota metric 'Gemini 2.5-preview Pro Requests'"
|
|
24
|
-
// We use string methods instead of regex to avoid ReDoS vulnerabilities
|
|
25
|
-
const checkMessage = (message) => message.includes("Quota exceeded for quota metric 'Gemini") &&
|
|
26
|
-
message.includes("Pro Requests'");
|
|
27
|
-
if (typeof error === 'string') {
|
|
28
|
-
return checkMessage(error);
|
|
29
|
-
}
|
|
30
|
-
if (isStructuredError(error)) {
|
|
31
|
-
return checkMessage(error.message);
|
|
32
|
-
}
|
|
33
|
-
if (isApiError(error)) {
|
|
34
|
-
return checkMessage(error.error.message);
|
|
35
|
-
}
|
|
36
|
-
// Check if it's a Gaxios error with response data
|
|
37
|
-
if (error && typeof error === 'object' && 'response' in error) {
|
|
38
|
-
const gaxiosError = error;
|
|
39
|
-
if (gaxiosError.response && gaxiosError.response.data) {
|
|
40
|
-
if (typeof gaxiosError.response.data === 'string') {
|
|
41
|
-
return checkMessage(gaxiosError.response.data);
|
|
42
|
-
}
|
|
43
|
-
if (typeof gaxiosError.response.data === 'object' &&
|
|
44
|
-
gaxiosError.response.data !== null &&
|
|
45
|
-
'error' in gaxiosError.response.data) {
|
|
46
|
-
const errorData = gaxiosError.response.data;
|
|
47
|
-
return checkMessage(errorData.error?.message || '');
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
export function isGenericQuotaExceededError(error) {
|
|
54
|
-
if (typeof error === 'string') {
|
|
55
|
-
return error.includes('Quota exceeded for quota metric');
|
|
56
|
-
}
|
|
57
|
-
if (isStructuredError(error)) {
|
|
58
|
-
return error.message.includes('Quota exceeded for quota metric');
|
|
59
|
-
}
|
|
60
|
-
if (isApiError(error)) {
|
|
61
|
-
return error.error.message.includes('Quota exceeded for quota metric');
|
|
62
|
-
}
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
19
|
//# sourceMappingURL=quotaErrorDetection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quotaErrorDetection.js","sourceRoot":"","sources":["../../../src/utils/quotaErrorDetection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAO,IAAI,KAAK;QAChB,OAAQ,KAAkB,CAAC,KAAK,KAAK,QAAQ;QAC7C,SAAS,IAAK,KAAkB,CAAC,KAAK,CACvC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KAAK;QAClB,OAAQ,KAAyB,CAAC,OAAO,KAAK,QAAQ,CACvD,CAAC;AACJ,CAAC
|
|
1
|
+
{"version":3,"file":"quotaErrorDetection.js","sourceRoot":"","sources":["../../../src/utils/quotaErrorDetection.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAO,IAAI,KAAK;QAChB,OAAQ,KAAkB,CAAC,KAAK,KAAK,QAAQ;QAC7C,SAAS,IAAK,KAAkB,CAAC,KAAK,CACvC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC9C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,SAAS,IAAI,KAAK;QAClB,OAAQ,KAAyB,CAAC,OAAO,KAAK,QAAQ,CACvD,CAAC;AACJ,CAAC"}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import type { GenerateContentResponse } from '@google/genai';
|
|
6
7
|
export interface HttpError extends Error {
|
|
7
8
|
status?: number;
|
|
8
9
|
}
|
|
@@ -10,7 +11,8 @@ export interface RetryOptions {
|
|
|
10
11
|
maxAttempts: number;
|
|
11
12
|
initialDelayMs: number;
|
|
12
13
|
maxDelayMs: number;
|
|
13
|
-
|
|
14
|
+
shouldRetryOnError: (error: Error) => boolean;
|
|
15
|
+
shouldRetryOnContent?: (content: GenerateContentResponse) => boolean;
|
|
14
16
|
onPersistent429?: (authType?: string, error?: unknown) => Promise<string | boolean | null>;
|
|
15
17
|
authType?: string;
|
|
16
18
|
}
|
package/dist/src/utils/retry.js
CHANGED
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import { ApiError } from '@google/genai';
|
|
6
7
|
import { AuthType } from '../core/contentGenerator.js';
|
|
7
|
-
import {
|
|
8
|
+
import { classifyGoogleError, RetryableQuotaError, TerminalQuotaError, } from './googleQuotaErrors.js';
|
|
8
9
|
const DEFAULT_RETRY_OPTIONS = {
|
|
9
|
-
maxAttempts:
|
|
10
|
+
maxAttempts: 10,
|
|
10
11
|
initialDelayMs: 5000,
|
|
11
12
|
maxDelayMs: 30000, // 30 seconds
|
|
12
|
-
|
|
13
|
+
shouldRetryOnError: defaultShouldRetry,
|
|
13
14
|
};
|
|
14
15
|
/**
|
|
15
16
|
* Default predicate function to determine if a retry should be attempted.
|
|
@@ -18,18 +19,17 @@ const DEFAULT_RETRY_OPTIONS = {
|
|
|
18
19
|
* @returns True if the error is a transient error, false otherwise.
|
|
19
20
|
*/
|
|
20
21
|
function defaultShouldRetry(error) {
|
|
21
|
-
//
|
|
22
|
-
if (error
|
|
23
|
-
|
|
24
|
-
if (status ===
|
|
25
|
-
return
|
|
26
|
-
|
|
22
|
+
// Priority check for ApiError
|
|
23
|
+
if (error instanceof ApiError) {
|
|
24
|
+
// Explicitly do not retry 400 (Bad Request)
|
|
25
|
+
if (error.status === 400)
|
|
26
|
+
return false;
|
|
27
|
+
return error.status === 429 || (error.status >= 500 && error.status < 600);
|
|
27
28
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return true;
|
|
29
|
+
// Check for status using helper (handles other error shapes)
|
|
30
|
+
const status = getErrorStatus(error);
|
|
31
|
+
if (status !== undefined) {
|
|
32
|
+
return status === 429 || (status >= 500 && status < 600);
|
|
33
33
|
}
|
|
34
34
|
return false;
|
|
35
35
|
}
|
|
@@ -55,127 +55,65 @@ export async function retryWithBackoff(fn, options) {
|
|
|
55
55
|
const cleanOptions = options
|
|
56
56
|
? Object.fromEntries(Object.entries(options).filter(([_, v]) => v != null))
|
|
57
57
|
: {};
|
|
58
|
-
const { maxAttempts, initialDelayMs, maxDelayMs, onPersistent429, authType,
|
|
58
|
+
const { maxAttempts, initialDelayMs, maxDelayMs, onPersistent429, authType, shouldRetryOnError, shouldRetryOnContent, } = {
|
|
59
59
|
...DEFAULT_RETRY_OPTIONS,
|
|
60
60
|
...cleanOptions,
|
|
61
61
|
};
|
|
62
62
|
let attempt = 0;
|
|
63
63
|
let currentDelay = initialDelayMs;
|
|
64
|
-
let consecutive429Count = 0;
|
|
65
64
|
while (attempt < maxAttempts) {
|
|
66
65
|
attempt++;
|
|
67
66
|
try {
|
|
68
|
-
|
|
67
|
+
const result = await fn();
|
|
68
|
+
if (shouldRetryOnContent &&
|
|
69
|
+
shouldRetryOnContent(result)) {
|
|
70
|
+
const jitter = currentDelay * 0.3 * (Math.random() * 2 - 1);
|
|
71
|
+
const delayWithJitter = Math.max(0, currentDelay + jitter);
|
|
72
|
+
await delay(delayWithJitter);
|
|
73
|
+
currentDelay = Math.min(maxDelayMs, currentDelay * 2);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
69
77
|
}
|
|
70
78
|
catch (error) {
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
attempt = 0;
|
|
82
|
-
consecutive429Count = 0;
|
|
83
|
-
currentDelay = initialDelayMs;
|
|
84
|
-
// With the model updated, we continue to the next attempt
|
|
85
|
-
continue;
|
|
79
|
+
const classifiedError = classifyGoogleError(error);
|
|
80
|
+
if (classifiedError instanceof TerminalQuotaError) {
|
|
81
|
+
if (onPersistent429 && authType === AuthType.LOGIN_WITH_GOOGLE) {
|
|
82
|
+
try {
|
|
83
|
+
const fallbackModel = await onPersistent429(authType, classifiedError);
|
|
84
|
+
if (fallbackModel) {
|
|
85
|
+
attempt = 0; // Reset attempts and retry with the new model.
|
|
86
|
+
currentDelay = initialDelayMs;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
86
89
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
throw error;
|
|
90
|
+
catch (fallbackError) {
|
|
91
|
+
console.warn('Model fallback failed:', fallbackError);
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
|
-
|
|
93
|
-
// If fallback fails, continue with original error
|
|
94
|
-
console.warn('Fallback to Flash model failed:', fallbackError);
|
|
95
|
-
}
|
|
94
|
+
throw classifiedError; // Throw if no fallback or fallback failed.
|
|
96
95
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
!isProQuotaExceededError(error) &&
|
|
101
|
-
isGenericQuotaExceededError(error) &&
|
|
102
|
-
onPersistent429) {
|
|
103
|
-
try {
|
|
104
|
-
const fallbackModel = await onPersistent429(authType, error);
|
|
105
|
-
if (fallbackModel !== false && fallbackModel !== null) {
|
|
106
|
-
// Reset attempt counter and try with new model
|
|
107
|
-
attempt = 0;
|
|
108
|
-
consecutive429Count = 0;
|
|
109
|
-
currentDelay = initialDelayMs;
|
|
110
|
-
// With the model updated, we continue to the next attempt
|
|
111
|
-
continue;
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
// Fallback handler returned null/false, meaning don't continue - stop retry process
|
|
115
|
-
throw error;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
catch (fallbackError) {
|
|
119
|
-
// If fallback fails, continue with original error
|
|
120
|
-
console.warn('Fallback to Flash model failed:', fallbackError);
|
|
96
|
+
if (classifiedError instanceof RetryableQuotaError) {
|
|
97
|
+
if (attempt >= maxAttempts) {
|
|
98
|
+
throw classifiedError;
|
|
121
99
|
}
|
|
100
|
+
console.warn(`Attempt ${attempt} failed: ${classifiedError.message}. Retrying after ${classifiedError.retryDelayMs}ms...`);
|
|
101
|
+
await delay(classifiedError.retryDelayMs);
|
|
102
|
+
continue;
|
|
122
103
|
}
|
|
123
|
-
//
|
|
124
|
-
if (
|
|
125
|
-
consecutive429Count++;
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
consecutive429Count = 0;
|
|
129
|
-
}
|
|
130
|
-
// If we have persistent 429s and a fallback callback for OAuth
|
|
131
|
-
if (consecutive429Count >= 2 &&
|
|
132
|
-
onPersistent429 &&
|
|
133
|
-
authType === AuthType.LOGIN_WITH_GOOGLE) {
|
|
134
|
-
try {
|
|
135
|
-
const fallbackModel = await onPersistent429(authType, error);
|
|
136
|
-
if (fallbackModel !== false && fallbackModel !== null) {
|
|
137
|
-
// Reset attempt counter and try with new model
|
|
138
|
-
attempt = 0;
|
|
139
|
-
consecutive429Count = 0;
|
|
140
|
-
currentDelay = initialDelayMs;
|
|
141
|
-
// With the model updated, we continue to the next attempt
|
|
142
|
-
continue;
|
|
143
|
-
}
|
|
144
|
-
else {
|
|
145
|
-
// Fallback handler returned null/false, meaning don't continue - stop retry process
|
|
146
|
-
throw error;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
catch (fallbackError) {
|
|
150
|
-
// If fallback fails, continue with original error
|
|
151
|
-
console.warn('Fallback to Flash model failed:', fallbackError);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
// Check if we've exhausted retries or shouldn't retry
|
|
155
|
-
if (attempt >= maxAttempts || !shouldRetry(error)) {
|
|
104
|
+
// Generic retry logic for other errors
|
|
105
|
+
if (attempt >= maxAttempts || !shouldRetryOnError(error)) {
|
|
156
106
|
throw error;
|
|
157
107
|
}
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
// Fall back to exponential backoff with jitter
|
|
168
|
-
logRetryAttempt(attempt, error, errorStatus);
|
|
169
|
-
// Add jitter: +/- 30% of currentDelay
|
|
170
|
-
const jitter = currentDelay * 0.3 * (Math.random() * 2 - 1);
|
|
171
|
-
const delayWithJitter = Math.max(0, currentDelay + jitter);
|
|
172
|
-
await delay(delayWithJitter);
|
|
173
|
-
currentDelay = Math.min(maxDelayMs, currentDelay * 2);
|
|
174
|
-
}
|
|
108
|
+
const errorStatus = getErrorStatus(error);
|
|
109
|
+
logRetryAttempt(attempt, error, errorStatus);
|
|
110
|
+
// Exponential backoff with jitter for non-quota errors
|
|
111
|
+
const jitter = currentDelay * 0.3 * (Math.random() * 2 - 1);
|
|
112
|
+
const delayWithJitter = Math.max(0, currentDelay + jitter);
|
|
113
|
+
await delay(delayWithJitter);
|
|
114
|
+
currentDelay = Math.min(maxDelayMs, currentDelay * 2);
|
|
175
115
|
}
|
|
176
116
|
}
|
|
177
|
-
// This line should theoretically be unreachable due to the throw in the catch block.
|
|
178
|
-
// Added for type safety and to satisfy the compiler that a promise is always returned.
|
|
179
117
|
throw new Error('Retry attempts exhausted');
|
|
180
118
|
}
|
|
181
119
|
/**
|
|
@@ -200,52 +138,6 @@ export function getErrorStatus(error) {
|
|
|
200
138
|
}
|
|
201
139
|
return undefined;
|
|
202
140
|
}
|
|
203
|
-
/**
|
|
204
|
-
* Extracts the Retry-After delay from an error object's headers.
|
|
205
|
-
* @param error The error object.
|
|
206
|
-
* @returns The delay in milliseconds, or 0 if not found or invalid.
|
|
207
|
-
*/
|
|
208
|
-
function getRetryAfterDelayMs(error) {
|
|
209
|
-
if (typeof error === 'object' && error !== null) {
|
|
210
|
-
// Check for error.response.headers (common in axios errors)
|
|
211
|
-
if ('response' in error &&
|
|
212
|
-
typeof error.response === 'object' &&
|
|
213
|
-
error.response !== null) {
|
|
214
|
-
const response = error.response;
|
|
215
|
-
if ('headers' in response &&
|
|
216
|
-
typeof response.headers === 'object' &&
|
|
217
|
-
response.headers !== null) {
|
|
218
|
-
const headers = response.headers;
|
|
219
|
-
const retryAfterHeader = headers['retry-after'];
|
|
220
|
-
if (typeof retryAfterHeader === 'string') {
|
|
221
|
-
const retryAfterSeconds = parseInt(retryAfterHeader, 10);
|
|
222
|
-
if (!isNaN(retryAfterSeconds)) {
|
|
223
|
-
return retryAfterSeconds * 1000;
|
|
224
|
-
}
|
|
225
|
-
// It might be an HTTP date
|
|
226
|
-
const retryAfterDate = new Date(retryAfterHeader);
|
|
227
|
-
if (!isNaN(retryAfterDate.getTime())) {
|
|
228
|
-
return Math.max(0, retryAfterDate.getTime() - Date.now());
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return 0;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Determines the delay duration based on the error, prioritizing Retry-After header.
|
|
238
|
-
* @param error The error object.
|
|
239
|
-
* @returns An object containing the delay duration in milliseconds and the error status.
|
|
240
|
-
*/
|
|
241
|
-
function getDelayDurationAndStatus(error) {
|
|
242
|
-
const errorStatus = getErrorStatus(error);
|
|
243
|
-
let delayDurationMs = 0;
|
|
244
|
-
if (errorStatus === 429) {
|
|
245
|
-
delayDurationMs = getRetryAfterDelayMs(error);
|
|
246
|
-
}
|
|
247
|
-
return { delayDurationMs, errorStatus };
|
|
248
|
-
}
|
|
249
141
|
/**
|
|
250
142
|
* Logs a message for a retry attempt when using exponential backoff.
|
|
251
143
|
* @param attempt The current attempt number.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../../src/utils/retry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../../src/utils/retry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,wBAAwB,CAAC;AAmBhC,MAAM,qBAAqB,GAAiB;IAC1C,WAAW,EAAE,EAAE;IACf,cAAc,EAAE,IAAI;IACpB,UAAU,EAAE,KAAK,EAAE,aAAa;IAChC,kBAAkB,EAAE,kBAAkB;CACvC,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