feat: add GCP service account file support for google-vertex and google-vertex-anthropic - #3170
feat: add GCP service account file support for google-vertex and google-vertex-anthropic#3170maci0 wants to merge 3 commits into
Conversation
…le-vertex-anthropic
🦋 Changeset detectedLatest commit: 0afcf1b The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5e872363e7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| options.vertexai = true; | ||
| if (saFile !== undefined) options.serviceAccountFile = saFile; |
There was a problem hiding this comment.
Forward Vertex auth options into the protocol adapters
When these providers are configured through kap-server, the catalog records the new options here, but anthropic.contrib.ts forwards none of vertexai, project, location, or serviceAccountFile, while google-genai.contrib.ts forwards everything except serviceAccountFile. Consequently google-vertex-anthropic falls back to native Anthropic authentication, and google-vertex ignores the selected key file and tries ambient ADC instead; pass the new provider options through both protocol-base constructors.
AGENTS.md reference: AGENTS.md:L22-L22
Useful? React with 👍 / 👎.
| // eslint-disable-next-line @typescript-eslint/no-require-imports | ||
| const { GoogleAuth } = require('google-auth-library'); |
There was a problem hiding this comment.
Load GoogleAuth through the ESM dependency graph
When google-vertex-anthropic is constructed through legacy agent-core or directly through @moonshot-ai/kosong, this executes synchronously, but the package is emitted as ESM and a bare require is unavailable; moreover, google-auth-library is only a transitive dependency of @google/genai, not a declared dependency of kosong. The catch therefore reports that the library is required and the new provider cannot start. Import GoogleAuth normally and declare the dependency explicitly; the mirrored v2 implementation needs the same correction.
Useful? React with 👍 / 👎.
| case 'vertexai': | ||
| return new GoogleGenAIChatProvider(config); | ||
| case 'google-vertex': | ||
| return new GoogleGenAIChatProvider({ ...config, vertexai: true }); |
There was a problem hiding this comment.
Preserve legacy vertexai API-key mode
For an existing type = "vertexai" provider configured with VERTEXAI_API_KEY or GOOGLE_API_KEY but no project/location, provider-manager.ts deliberately produces vertexai: false so the request uses API-key Gemini routing. Overwriting that value here forces the Google SDK into Vertex/ADC mode, changing the endpoint and requiring project/location, so those previously valid configurations fail. Force Vertex mode only for the new google-vertex type and preserve the flag supplied for the legacy alias.
Useful? React with 👍 / 👎.
| id: 'google-vertex-anthropic', | ||
| baseProtocol: 'anthropic', | ||
| traits: [ | ||
| { endpoint: () => ({ apiKeyEnv: 'ANTHROPIC_API_KEY', baseUrlEnv: 'ANTHROPIC_BASE_URL' }) }, |
There was a problem hiding this comment.
Read the Vertex base URL variable for Anthropic
When a v2 google-vertex-anthropic configuration relies on GOOGLE_VERTEX_BASE_URL, as documented by this change and already handled by the legacy resolver, this definition instead consults ANTHROPIC_BASE_URL; the configured Vertex proxy is therefore ignored and requests go to the default Google host. Use GOOGLE_VERTEX_BASE_URL for this provider's endpoint trait.
AGENTS.md reference: AGENTS.md:L22-L22
Useful? React with 👍 / 👎.
…SE events for Vertex Anthropic stream
|
Thanks for taking the time to contribute! Per our contributing guide, external feature PRs are not accepted directly — features are discussed and decided in issues first, and accepted features are implemented by the team or by explicit maintainer invitation. This PR has no linked issue where the feature was discussed and approved, so we're closing it for now. Please open an issue to discuss the feature first; if a maintainer approves it there, ask us to reopen and we'll take another look. |
Summary
Adds support for GCP service account JSON files (
service_account_file, with~path expansion) and thegoogle-vertex-anthropicprovider type for Anthropic Claude models hosted on Google Vertex AI.Key Changes
service_account_file/serviceAccountFilesupport acrosskosong,agent-core,agent-core-v2, andacp-adapter.~and~/in paths (e.g.~/.secrets/service-account.json) toos.homedir().project_idfrom the service account JSON file ifprojectis omitted in configuration.googleAuthOptionsdown togoogle-auth-library'sGoogleAuthfor automatic token generation and rotation.google-vertex(Google Gemini on Vertex AI).google-vertex-anthropic(Anthropic Claude on Vertex AI).:rawPredictand:streamRawPredictwith Bearer token authentication andanthropic_version: "vertex-2023-10-16".packages/kosong/test/vertex-service-account.test.ts,agent-core,agent-core-v2, andacp-adapter.google-vertex,google-vertex-anthropic, andservice_account_filein both English and Chinese configuration docs.