feat(providers): route gemini through the native AI Studio API

- add a native Gemini adapter over generateContent/streamGenerateContent
- switch the built-in gemini provider off the OpenAI-compatible endpoint
- preserve thought signatures and native functionResponse replay
- route auxiliary Gemini clients through the same adapter
- add focused unit coverage plus native-provider integration checks
This commit is contained in:
kshitijk4poor
2026-04-20 00:00:50 +05:30
committed by Teknium
parent aa5bd09232
commit 3dea497b20
7 changed files with 1070 additions and 29 deletions

View File

@@ -4745,6 +4745,21 @@ class AIAgent:
self._client_log_context(),
)
return client
if self.provider == "gemini":
from agent.gemini_native_adapter import GeminiNativeClient
safe_kwargs = {
k: v for k, v in client_kwargs.items()
if k in {"api_key", "base_url", "default_headers", "timeout"}
}
client = GeminiNativeClient(**safe_kwargs)
logger.info(
"Gemini native client created (%s, shared=%s) %s",
reason,
shared,
self._client_log_context(),
)
return client
# Inject TCP keepalives so the kernel detects dead provider connections
# instead of letting them sit silently in CLOSE-WAIT (#10324). Without
# this, a peer that drops mid-stream leaves the socket in a state where