Skip to content

feat: Upgrade Gemini Provider to v3.0 (Official SDK, Rate Limits, Deep Normalization)#60

Open
Foadsf wants to merge 11 commits into
jjuliano:mainfrom
Foadsf:upgrade-gemini-3.0-9868090931775392915
Open

feat: Upgrade Gemini Provider to v3.0 (Official SDK, Rate Limits, Deep Normalization)#60
Foadsf wants to merge 11 commits into
jjuliano:mainfrom
Foadsf:upgrade-gemini-3.0-9868090931775392915

Conversation

@Foadsf
Copy link
Copy Markdown

@Foadsf Foadsf commented Jan 13, 2026

This PR represents a comprehensive upgrade of the Google Gemini provider to support the Gemini 3.0 family (Pro/Flash) and address critical stability issues found in the v1beta HTTP implementation.

🚀 Key Changes

1. Official SDK Migration

  • Replaced fragile raw HTTP axios calls with the official @google/generative-ai SDK.
  • Updated default models to Gemini 3.0 Pro and Gemini 3.0 Flash.

2. Stability & Rate Limiting

  • Smart Backoff: Implemented a retry loop that strictly respects the API's retry-after header. This fixes the infinite loop of 429 Too Many Requests errors.
  • Auto-Truncation: Added logic to automatically truncate inputs exceeding 400,000 characters to prevent immediate rejection by the Free Tier limits.

3. Output Reliability (The "Deep Normalization" Fix)

  • JSON Enforcement: Configured the model to strict application/json mode.
  • Deep Normalization: Implemented a recursive normalizer that unwraps nested JSON responses (common in Gemini 3.0) and maps inconsistent keys (e.g., title, filename) to the application's required schema (file_title).
  • Path Synthesis: Auto-generates a suggestedPath if the LLM omits it, preventing validation failures.

4. User Experience

  • Dynamic Setup: The Setup Wizard now fetches the actual list of available models from the user's API key instead of using hardcoded lists.
  • Diagnostics: Added a new script npm run list-models to help users debug API key access levels.

Verification

Tested locally with large technical PDF manuals (85MB+) that previously failed with Quota/Parsing errors. The new provider successfully truncates, waits for rate limits, normalizes the nested JSON, and organizes the files.

….0 models

- Replaced raw HTTP calls with `@google/generative-ai` SDK in `GeminiProvider`.
- Removed axios dependency from `GeminiProvider`.
- Updated `GeminiProvider` to support `sendMessage` and `analyzeImage` using the new SDK.
- Updated `src/setup-wizard.ts` to replace Gemini 1.5 options with Gemini 3.0 Pro and Flash.
- Set `gemini-3.0-pro` as the default Gemini model.
- Added `@google/generative-ai` dependency to `package.json`.
- Upgraded `GeminiProvider` to use `@google/generative-ai` SDK.
- Removed `axios` usage from `GeminiProvider`.
- Updated `setup-wizard` to support Gemini 3.0 Pro/Flash and custom model entry.
- Added `scripts/list-gemini-models.js` to debug available models.
- Added `npm run list-models` script.
- Improved error handling to suggest checking available models on 404 errors.
- Upgraded `GeminiProvider` to use `@google/generative-ai` SDK.
- Implemented content truncation (800k chars) in `GeminiProvider` to prevent 429 quota errors.
- Added dynamic model fetching in `setup-wizard` using `getGeminiModels`.
- Refactored `scripts/list-gemini-models.js` to be reusable and added `npm run list-models` script.
- Added support for custom Gemini model IDs in setup wizard.
- Removed `axios` usage from `GeminiProvider`.
- Migrated `GeminiProvider` to use `@google/generative-ai` SDK (removing axios).
- Implemented robust retry logic with smart backoff for 429 errors (parsing retry duration).
- Added `MAX_FREE_TIER_CHARS` (400k) truncation to prevent quota limits on large files.
- Updated `setup-wizard` to dynamically fetch models using `getGeminiModels` shared from scripts.
- Added `scripts/list-gemini-models.js` and `npm run list-models` for diagnostics.
- Added support for custom Gemini model IDs.
- Migrated `GeminiProvider` to `@google/generative-ai` SDK.
- Implemented `MAX_FREE_TIER_CHARS` (400k) truncation to prevent quota errors.
- Added smart retry logic with backoff (parsing API wait times) for 429 errors.
- Enforced JSON output via `responseMimeType` and added a Markdown stripper.
- Updated `setup-wizard` to dynamically fetch models and support custom IDs.
- Added `scripts/list-gemini-models.js` and `npm run list-models` diagnostic.
…tion

- Migrated `GeminiProvider` to `@google/generative-ai` SDK (removed axios).
- Implemented `MAX_FREE_TIER_CHARS` (400k) truncation to prevent quota errors.
- Added smart retry logic with backoff (parsing API wait times) for 429 errors.
- Enforced strict JSON output with `responseMimeType`, system instructions, and a response normalizer (unwrapping nested objects/mapping keys).
- Updated `setup-wizard` to dynamically fetch models and support custom IDs.
- Added `scripts/list-gemini-models.js` and `npm run list-models` diagnostic.
…alization

- Migrated `GeminiProvider` to `@google/generative-ai` SDK (removed axios).
- Implemented `MAX_FREE_TIER_CHARS` (400k) truncation to prevent quota errors.
- Added smart retry logic with backoff (parsing API wait times) for 429 errors.
- Enforced strict JSON output with `responseMimeType`, system instructions, and deep recursive normalization (unwrapping nested objects/mapping keys).
- Updated `setup-wizard` to dynamically fetch models and support custom IDs.
- Added `scripts/list-gemini-models.js` and `npm run list-models` diagnostic.
- Migrated `GeminiProvider` to `@google/generative-ai` SDK (removed axios).
- Implemented `MAX_FREE_TIER_CHARS` (400k) truncation to prevent quota errors.
- Added smart retry logic with backoff (parsing API wait times) for 429 errors.
- Enforced strict JSON output with `responseMimeType`, system instructions, and deep normalization.
- Updated `setup-wizard` to dynamically fetch models and support custom IDs.
- Fixed JSON validation failures by updating `multi-call-analyzer` to accept standardized keys (`file_title`) produced by the normalized Gemini provider.
- Added `scripts/list-gemini-models.js` and `npm run list-models` diagnostic.
- Migrated `GeminiProvider` to `@google/generative-ai` SDK (removed axios).
- Implemented `MAX_FREE_TIER_CHARS` (400k) truncation to prevent quota errors.
- Added smart retry logic with backoff (parsing API wait times) for 429 errors.
- Enforced strict JSON output with `responseMimeType`, system instructions, and deep normalization.
- Added synthesis of `suggestedPath` and `suggestedFilename` if missing from LLM response.
- Updated `setup-wizard` to dynamically fetch models and support custom IDs.
- Fixed JSON validation compatibility in `multi-call-analyzer` for Gemini's normalized keys.
- Added `scripts/list-gemini-models.js` and `npm run list-models` diagnostic.
@Foadsf
Copy link
Copy Markdown
Author

Foadsf commented Jan 13, 2026

FYI this tweet.

- Migrated `GeminiProvider` to `@google/generative-ai` SDK (removed axios).
- Implemented `MAX_FREE_TIER_CHARS` (400k) truncation to prevent quota errors.
- Added smart retry logic with backoff (parsing API wait times) for 429 errors.
- Enforced strict JSON output with `responseMimeType`, system instructions, and deep normalization.
- Aligned output schema exactly with `multi-call-analyzer` requirements (`title` vs `file_title`).
- Added synthesis of `suggestedPath` and `suggestedFilename` if missing.
- Updated `setup-wizard` to dynamically fetch models and support custom IDs.
- Fixed JSON validation compatibility in `multi-call-analyzer`.
- Added `scripts/list-gemini-models.js` and `npm run list-models` diagnostic.
- Migrated `GeminiProvider` to `@google/generative-ai` SDK (removed axios).
- Implemented `MAX_FREE_TIER_CHARS` (400k) truncation and `maxOutputTokens` (8192) to prevent errors.
- Added smart retry logic with backoff (parsing API wait times) for 429 errors.
- Enforced strict JSON output with `responseMimeType`, system instructions, deep normalization, and repair logic for malformed JSON.
- Fixed image processing regression by correctly routing image files to `analyzeImage` instead of text processing.
- Added `FileLogger` for persistent per-file debugging logs.
- Updated `setup-wizard` to dynamically fetch models.
- Fixed JSON validation schema mismatch in `multi-call-analyzer`.
- Added `scripts/list-gemini-models.js` diagnostic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant