diff --git a/packages/cli/src/nonInteractiveCli.ts b/packages/cli/src/nonInteractiveCli.ts index c237e56b..f2efe8fc 100644 --- a/packages/cli/src/nonInteractiveCli.ts +++ b/packages/cli/src/nonInteractiveCli.ts @@ -13,10 +13,10 @@ import { isTelemetrySdkInitialized, GeminiEventType, ToolErrorType, + parseAndFormatApiError, } from '@google/gemini-cli-core'; import { Content, Part, FunctionCall } from '@google/genai'; -import { parseAndFormatApiError } from './ui/utils/errorParsing.js'; import { ConsolePatcher } from './ui/utils/ConsolePatcher.js'; export async function runNonInteractive( diff --git a/packages/cli/src/ui/hooks/useGeminiStream.test.tsx b/packages/cli/src/ui/hooks/useGeminiStream.test.tsx index 37d63e9a..9eed0912 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.test.tsx +++ b/packages/cli/src/ui/hooks/useGeminiStream.test.tsx @@ -51,6 +51,7 @@ const MockedGeminiClientClass = vi.hoisted(() => const MockedUserPromptEvent = vi.hoisted(() => vi.fn().mockImplementation(() => {}), ); +const mockParseAndFormatApiError = vi.hoisted(() => vi.fn()); vi.mock('@google/gemini-cli-core', async (importOriginal) => { const actualCoreModule = (await importOriginal()) as any; @@ -59,6 +60,7 @@ vi.mock('@google/gemini-cli-core', async (importOriginal) => { GitService: vi.fn(), GeminiClient: MockedGeminiClientClass, UserPromptEvent: MockedUserPromptEvent, + parseAndFormatApiError: mockParseAndFormatApiError, }; }); @@ -127,11 +129,6 @@ vi.mock('./slashCommandProcessor.js', () => ({ handleSlashCommand: vi.fn().mockReturnValue(false), })); -const mockParseAndFormatApiError = vi.hoisted(() => vi.fn()); -vi.mock('../utils/errorParsing.js', () => ({ - parseAndFormatApiError: mockParseAndFormatApiError, -})); - // --- END MOCKS --- describe('mergePartListUnions', () => { diff --git a/packages/cli/src/ui/hooks/useGeminiStream.ts b/packages/cli/src/ui/hooks/useGeminiStream.ts index 6f3cb4fd..99b727b6 100644 --- a/packages/cli/src/ui/hooks/useGeminiStream.ts +++ b/packages/cli/src/ui/hooks/useGeminiStream.ts @@ -25,6 +25,7 @@ import { UnauthorizedError, UserPromptEvent, DEFAULT_GEMINI_FLASH_MODEL, + parseAndFormatApiError, } from '@google/gemini-cli-core'; import { type Part, type PartListUnion, FinishReason } from '@google/genai'; import { @@ -37,7 +38,6 @@ import { ToolCallStatus, } from '../types.js'; import { isAtCommand } from '../utils/commandUtils.js'; -import { parseAndFormatApiError } from '../utils/errorParsing.js'; import { useShellCommandProcessor } from './shellCommandProcessor.js'; import { handleAtCommand } from './atCommandProcessor.js'; import { findLastSafeSplitPoint } from '../utils/markdownUtilities.js'; diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 791446e3..a24cddbe 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -41,6 +41,7 @@ export * from './utils/systemEncoding.js'; export * from './utils/textUtils.js'; export * from './utils/formatters.js'; export * from './utils/filesearch/fileSearch.js'; +export * from './utils/errorParsing.js'; // Export services export * from './services/fileDiscoveryService.js'; diff --git a/packages/cli/src/ui/utils/errorParsing.test.ts b/packages/core/src/utils/errorParsing.test.ts similarity index 98% rename from packages/cli/src/ui/utils/errorParsing.test.ts rename to packages/core/src/utils/errorParsing.test.ts index 770dffad..f2a4709a 100644 --- a/packages/cli/src/ui/utils/errorParsing.test.ts +++ b/packages/core/src/utils/errorParsing.test.ts @@ -6,12 +6,11 @@ import { describe, it, expect } from 'vitest'; import { parseAndFormatApiError } from './errorParsing.js'; -import { - AuthType, - UserTierId, - DEFAULT_GEMINI_FLASH_MODEL, - isProQuotaExceededError, -} from '@google/gemini-cli-core'; +import { isProQuotaExceededError } from './quotaErrorDetection.js'; +import { DEFAULT_GEMINI_FLASH_MODEL } from '../config/models.js'; +import { UserTierId } from '../code_assist/types.js'; +import { AuthType } from '../core/contentGenerator.js'; +import { StructuredError } from '../core/turn.js'; describe('parseAndFormatApiError', () => { const _enterpriseMessage = diff --git a/packages/cli/src/ui/utils/errorParsing.ts b/packages/core/src/utils/errorParsing.ts similarity index 97% rename from packages/cli/src/ui/utils/errorParsing.ts rename to packages/core/src/utils/errorParsing.ts index 5031bc0a..aa15a652 100644 --- a/packages/cli/src/ui/utils/errorParsing.ts +++ b/packages/core/src/utils/errorParsing.ts @@ -5,15 +5,17 @@ */ import { - AuthType, - UserTierId, - DEFAULT_GEMINI_FLASH_MODEL, - DEFAULT_GEMINI_MODEL, isProQuotaExceededError, isGenericQuotaExceededError, isApiError, isStructuredError, -} from '@google/gemini-cli-core'; +} from './quotaErrorDetection.js'; +import { + DEFAULT_GEMINI_MODEL, + DEFAULT_GEMINI_FLASH_MODEL, +} from '../config/models.js'; +import { UserTierId } from '../code_assist/types.js'; +import { AuthType } from '../core/contentGenerator.js'; // Free Tier message functions const getRateLimitErrorMessageGoogleFree = ( diff --git a/packages/core/src/utils/quotaErrorDetection.ts b/packages/core/src/utils/quotaErrorDetection.ts index 6fe9b312..1377b4fa 100644 --- a/packages/core/src/utils/quotaErrorDetection.ts +++ b/packages/core/src/utils/quotaErrorDetection.ts @@ -4,6 +4,8 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { StructuredError } from '../core/turn.js'; + export interface ApiError { error: { code: number; @@ -13,11 +15,6 @@ export interface ApiError { }; } -interface StructuredError { - message: string; - status?: number; -} - export function isApiError(error: unknown): error is ApiError { return ( typeof error === 'object' &&