feat(agents): add Google Gemini provider with API key and OAuth support#33
Open
feat(agents): add Google Gemini provider with API key and OAuth support#33
Conversation
Implement a native Gemini provider that directly calls the Google Generative Language API, bypassing the genai crate wrapper for better control and full feature support. Features: - Full tool/function calling support (functionDeclarations, functionCall, functionResponse) - Streaming support via Server-Sent Events - System instruction support - Message format conversion (user, assistant, tool messages) - JSON Schema type conversion (lowercase to uppercase for Gemini) - Comprehensive test coverage Supported models: - gemini-2.5-pro-preview-06-05 - gemini-2.5-flash-preview-05-20 - gemini-2.0-flash - gemini-2.0-flash-lite - gemini-1.5-pro - gemini-1.5-flash All models support 1M context window. https://claude.ai/code/session_01YRnqNPmxNtRyrtWwmhnJxz
Implement OAuth-based authentication for Gemini API using Google's device authorization flow, similar to GitHub Copilot and Kimi Code providers. Features: - Device flow OAuth authentication (poll for token after user enters code) - Token refresh with automatic expiry detection (5 min buffer) - Full tool/function calling support (same as API key version) - Streaming support via Server-Sent Events - Secure token storage via moltis-oauth TokenStore Configuration: - Requires GOOGLE_CLIENT_ID environment variable (from Google Cloud project) - Optional GOOGLE_CLIENT_SECRET for confidential clients - Provider name: "gemini-oauth" - Feature flag: provider-gemini-oauth Users need to: 1. Create a Google Cloud project 2. Enable the Generative Language API 3. Create OAuth 2.0 credentials (Desktop app type) 4. Set GOOGLE_CLIENT_ID environment variable 5. Run the device flow to authenticate https://claude.ai/code/session_01YRnqNPmxNtRyrtWwmhnJxz
Comprehensive documentation covering: - API key provider (gemini.rs) implementation details - OAuth provider (gemini_oauth.rs) with device flow - Message format conversion (Gemini's parts/content structure) - Tool schema conversion (JSON Schema type uppercasing) - Token management and refresh logic - Provider registration flow - Supported models and context windows - Security considerations https://claude.ai/code/session_01YRnqNPmxNtRyrtWwmhnJxz
Replace device-flow authentication with Authorization Code + PKCE flow. This change allows Moltis to ship with a built-in Google OAuth client ID, so users can authenticate with their Google account without needing to create their own OAuth credentials. Key changes: - Use OAuthFlow and CallbackServer from moltis-oauth crate - Add gemini-oauth config to defaults.rs with Google OAuth endpoints - Remove GOOGLE_CLIENT_ID environment variable requirement - API usage is billed to the user's Google account (not the app developer) Also replaces the implementation documentation with user-facing docs at docs/gemini.md. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move Gemini provider documentation to the mdbook structure and add it as a sub-page under LLM Providers in the summary. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add async functions to list available Gemini models from the API: - API key provider: list_models() and list_models_with_base_url() - OAuth provider: list_models_oauth() and list_models_with_token() Models are fetched from /v1beta/models endpoint, filtered to those supporting text generation, and sorted by name. Pagination is handled automatically. Both providers also get list_available_models() methods. The GeminiModelInfo struct includes model_id() helper to extract the model ID from the full resource name, and supports_generation() to filter generation-capable models. Includes comprehensive tests for: - Model info struct methods - ListModelsResponse deserialization with camelCase fields - Token refresh threshold logic - Missing field handling Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Update both Gemini providers (API key and OAuth) to use the new typed ChatMessage enum instead of serde_json::Value for the LlmProvider trait methods (complete, stream). This aligns with the recent trait change that prevents metadata leakage into provider API requests by using a typed message format. Changes: - Update extract_system_instruction() to work with &[ChatMessage] - Update to_gemini_messages() to work with &[&ChatMessage] - Add multimodal/vision support for User messages with images - Update complete() and stream() method signatures - Update tests to use ChatMessage constructors Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
Merging this PR will not alter performance
Comparing Footnotes
|
- Add cache_read_tokens and cache_write_tokens fields (via ..Default::default()) - Update test to expect namespaced model ID format (gemini::model-name) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Wire gemini-oauth into provider feature/registry setup, expose it in provider setup and config validation, and update provider docs/changelog. Remove the branch-local native gemini implementation that duplicates mainline behavior.
|
Hi, any update on this one? Having Gemini would be super useful! Thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
docs/gemini.mdFeatures
API Key Provider (
gemini)OAuth Provider (
gemini-oauth)Supported Models
All models support 1M context window.
What You Need To Do
Before merging, replace the placeholder client ID in
crates/oauth/src/defaults.rs:With your actual client ID from Google Cloud Console. See
docs/gemini.mdfor setup instructions.Test plan
cargo test --all-features- all tests pass🤖 Generated with Claude Code