mirror of
https://github.com/outbackdingo/optimclaw.git
synced 2026-08-26 23:50:17 +00:00
feat(gemini_oauth): full Cloud Code API integration with project discovery
- Register gemini_oauth as a dedicated backend in config/llm.rs (skip registry fallback, preserve backend name, suppress unknown-backend warning) - Fix app.rs credential guard to exclude backends with dedicated configs (gemini_oauth, bedrock) from the provider.is_none() check - Auto-discover Cloud Code project_id via loadCodeAssist when credentials lack it (e.g. created by the original Gemini CLI) - Persist discovered project_id to credentials file for subsequent runs - Add safety settings (BLOCK_NONE), gated behind GEMINI_SAFETY_BLOCK_NONE env - Add thinkingConfig: budget-based for Gemini 2.5, level-based for Gemini 3.x (without includeThoughts to avoid empty responses from reasoning.rs stripping) - Add thought signature injection for Gemini 3.x preview APIs - Add history curation to filter invalid model outputs before re-sending - Add extended generationConfig env vars (topP, topK, seed, penalties, responseMimeType, responseJsonSchema, cachedContent) - Add custom headers support via GEMINI_CLI_CUSTOM_HEADERS - Add API key auth mode (GEMINI_API_KEY + GEMINI_API_KEY_AUTH_MECHANISM) - Add SSE metadata extraction (modelVersion, credits, promptFeedback, groundingMetadata, citationMetadata, cachedContentTokenCount) - Add countTokens API support - Add new models to wizard (gemini-3.1-pro-preview-customtools, gemini-3-pro-preview, gemini-3.1-flash-lite-preview) - Update docs/LLM_PROVIDERS.md with new models and routing rules - Rewrite regression tests with comprehensive coverage (23 unit tests pass)
This commit is contained in:
+8
-4
@@ -683,10 +683,14 @@ impl AppBuilder {
|
||||
self.init_database().await?;
|
||||
self.init_secrets().await?;
|
||||
|
||||
// Post-init validation: if a non-nearai backend was selected but
|
||||
// credentials were never resolved (deferred resolution found no keys),
|
||||
// fail early with a clear error instead of a confusing runtime failure.
|
||||
if self.config.llm.backend != "nearai" && self.config.llm.provider.is_none() {
|
||||
// Post-init validation: backends with dedicated config (nearai, gemini_oauth,
|
||||
// bedrock) handle their own credential resolution. For registry-based backends,
|
||||
// fail early if no provider config was resolved.
|
||||
if self.config.llm.backend != "nearai"
|
||||
&& self.config.llm.backend != "gemini_oauth"
|
||||
&& self.config.llm.backend != "bedrock"
|
||||
&& self.config.llm.provider.is_none()
|
||||
{
|
||||
let backend = &self.config.llm.backend;
|
||||
anyhow::bail!(
|
||||
"LLM_BACKEND={backend} is configured but no credentials were found. \
|
||||
|
||||
+6
-3
@@ -10,7 +10,6 @@ use crate::llm::registry::{ProviderProtocol, ProviderRegistry};
|
||||
use crate::llm::session::SessionConfig;
|
||||
use crate::settings::Settings;
|
||||
|
||||
|
||||
impl LlmConfig {
|
||||
/// Create a test-friendly config without reading env vars.
|
||||
#[cfg(feature = "libsql")]
|
||||
@@ -75,8 +74,10 @@ impl LlmConfig {
|
||||
backend_lower == "nearai" || backend_lower == "near_ai" || backend_lower == "near";
|
||||
let is_bedrock =
|
||||
backend_lower == "bedrock" || backend_lower == "aws_bedrock" || backend_lower == "aws";
|
||||
let is_gemini_oauth = backend_lower == "gemini_oauth" || backend_lower == "gemini-oauth";
|
||||
|
||||
if !is_nearai && !is_bedrock && registry.find(&backend_lower).is_none() {
|
||||
if !is_nearai && !is_bedrock && !is_gemini_oauth && registry.find(&backend_lower).is_none()
|
||||
{
|
||||
tracing::warn!(
|
||||
"Unknown LLM backend '{}'. Will attempt as openai_compatible fallback.",
|
||||
backend
|
||||
@@ -124,7 +125,7 @@ impl LlmConfig {
|
||||
};
|
||||
|
||||
// Resolve registry provider config (for non-NearAI, non-Bedrock backends)
|
||||
let provider = if is_nearai || is_bedrock {
|
||||
let provider = if is_nearai || is_bedrock || is_gemini_oauth {
|
||||
None
|
||||
} else {
|
||||
Some(Self::resolve_registry_provider(
|
||||
@@ -199,6 +200,8 @@ impl LlmConfig {
|
||||
"nearai".to_string()
|
||||
} else if is_bedrock {
|
||||
"bedrock".to_string()
|
||||
} else if is_gemini_oauth {
|
||||
"gemini_oauth".to_string()
|
||||
} else if let Some(ref p) = provider {
|
||||
p.provider_id.clone()
|
||||
} else {
|
||||
|
||||
@@ -239,6 +239,21 @@ impl NearAiConfig {
|
||||
}
|
||||
|
||||
/// Configuration for Gemini OAuth integration.
|
||||
///
|
||||
/// Extended generation config parameters (topP, topK, seed, etc.) are read from
|
||||
/// environment variables at request time:
|
||||
/// - `GEMINI_TOP_P` — nucleus sampling (0.0–1.0)
|
||||
/// - `GEMINI_TOP_K` — top-k sampling (integer)
|
||||
/// - `GEMINI_SEED` — deterministic generation seed
|
||||
/// - `GEMINI_PRESENCE_PENALTY` — presence penalty (-2.0–2.0)
|
||||
/// - `GEMINI_FREQUENCY_PENALTY` — frequency penalty (-2.0–2.0)
|
||||
/// - `GEMINI_RESPONSE_MIME_TYPE` — e.g. "application/json"
|
||||
/// - `GEMINI_RESPONSE_JSON_SCHEMA` — JSON schema string for structured output
|
||||
/// - `GEMINI_CACHED_CONTENT` — cached content resource name
|
||||
/// - `GEMINI_CLI_CUSTOM_HEADERS` — custom headers (key:value,key:value)
|
||||
/// - `GOOGLE_GENAI_API_VERSION` — API version (default: v1beta)
|
||||
/// - `GEMINI_API_KEY` — optional API key for non-OAuth auth mode
|
||||
/// - `GEMINI_API_KEY_AUTH_MECHANISM` — "x-goog-api-key" (default) or "bearer"
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct GeminiOauthConfig {
|
||||
pub model: String,
|
||||
|
||||
+811
-38
File diff suppressed because it is too large
Load Diff
@@ -1708,10 +1708,22 @@ impl SetupWizard {
|
||||
"gemini-3.1-pro-preview".into(),
|
||||
"Gemini 3.1 Pro (Latest, strongest reasoning)".into(),
|
||||
),
|
||||
(
|
||||
"gemini-3.1-pro-preview-customtools".into(),
|
||||
"Gemini 3.1 Pro Custom Tools (Enhanced tool use)".into(),
|
||||
),
|
||||
(
|
||||
"gemini-3-pro-preview".into(),
|
||||
"Gemini 3 Pro (Preview)".into(),
|
||||
),
|
||||
(
|
||||
"gemini-3-flash-preview".into(),
|
||||
"Gemini 3 Flash (Fast preview with thinking)".into(),
|
||||
),
|
||||
(
|
||||
"gemini-3.1-flash-lite-preview".into(),
|
||||
"Gemini 3.1 Flash Lite (Preview, lightweight)".into(),
|
||||
),
|
||||
(
|
||||
"gemini-2.5-pro".into(),
|
||||
"Gemini 2.5 Pro (Stable, strong reasoning)".into(),
|
||||
|
||||
Reference in New Issue
Block a user