Files
wehub-resource-sync b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:56:03 +08:00

76 lines
2.8 KiB
Python

"""Google Vertex AI provider profile.
vertex: Gemini models via Google Cloud's OpenAI-compatible endpoint.
Auth is OAuth2 — short-lived access tokens minted from a service-account JSON
or Application Default Credentials (ADC), NOT a static API key. Token
resolution and refresh live in ``agent/vertex_adapter.py``; runtime_provider.py
calls it to obtain a fresh ``(token, base_url)`` pair, then hands the token to
the standard OpenAI client as ``api_key``. Because the wire format is the
OpenAI-compatible chat/completions surface, no message translation is needed —
the only Gemini-specific concern is the ``thinking_config`` reasoning hook,
which is emitted here exactly as the ``gemini`` provider does for its
OpenAI-compat subpath (``extra_body.google.thinking_config``).
``auth_type="vertex"`` marks this as an OAuth-token provider (resolved
specially, like bedrock's ``aws_sdk``) so it is never treated as an
api_key provider that would mistake a credentials-file path for a key.
"""
from typing import Any
from providers import register_provider
from providers.base import ProviderProfile
class VertexProfile(ProviderProfile):
"""Vertex AI — reuse Gemini's thinking_config translation for extra_body."""
def build_extra_body(
self, *, session_id: str | None = None, **context: Any
) -> dict[str, Any]:
"""Emit ``extra_body.google.thinking_config`` for the OpenAI-compat
Vertex surface, mirroring the ``gemini`` provider's behavior.
"""
from agent.transports.chat_completions import (
_build_gemini_thinking_config,
_snake_case_gemini_thinking_config,
)
model = context.get("model") or ""
reasoning_config = context.get("reasoning_config")
raw_thinking_config = _build_gemini_thinking_config(model, reasoning_config)
if not raw_thinking_config:
return {}
thinking_config = _snake_case_gemini_thinking_config(raw_thinking_config)
if not thinking_config:
return {}
return {"extra_body": {"google": {"thinking_config": thinking_config}}}
def fetch_models(
self,
*,
api_key: str | None = None,
base_url: str | None = None,
timeout: float = 8.0,
) -> list[str] | None:
"""Vertex's OpenAI-compat endpoint has no ``/models`` listing route;
model discovery is not available. The setup wizard ships a curated list.
"""
return None
vertex = VertexProfile(
name="vertex",
aliases=("google-vertex", "vertex-ai", "gcp-vertex"),
api_mode="chat_completions",
env_vars=(), # OAuth2 via service account / ADC — not a static key env var
base_url="https://aiplatform.googleapis.com", # real base_url computed at runtime
auth_type="vertex",
default_aux_model="google/gemini-3-flash-preview",
)
register_provider(vertex)