Skip to content

feat: add GCP service account file support for google-vertex and google-vertex-anthropic - #3170

Open
maci0 wants to merge 3 commits into
MoonshotAI:mainfrom
maci0:feat/google-vertex-service-account
Open

feat: add GCP service account file support for google-vertex and google-vertex-anthropic#3170
maci0 wants to merge 3 commits into
MoonshotAI:mainfrom
maci0:feat/google-vertex-service-account

Conversation

@maci0

@maci0 maci0 commented Aug 22, 2026

Copy link
Copy Markdown

Summary

Adds support for GCP service account JSON files (service_account_file, with ~ path expansion) and the google-vertex-anthropic provider type for Anthropic Claude models hosted on Google Vertex AI.

Key Changes

  • Service Account File & Path Expansion:
    • Added service_account_file / serviceAccountFile support across kosong, agent-core, agent-core-v2, and acp-adapter.
    • Expands ~ and ~/ in paths (e.g. ~/.secrets/service-account.json) to os.homedir().
    • Reads project_id from the service account JSON file if project is omitted in configuration.
    • Passes googleAuthOptions down to google-auth-library's GoogleAuth for automatic token generation and rotation.
  • Provider Type Additions:
    • Registered google-vertex (Google Gemini on Vertex AI).
    • Registered google-vertex-anthropic (Anthropic Claude on Vertex AI).
    • Built custom Vertex transport fetch for Anthropic Claude models calling :rawPredict and :streamRawPredict with Bearer token authentication and anthropic_version: "vertex-2023-10-16".
  • Documentation & Unit Tests:
    • Added comprehensive test suites in packages/kosong/test/vertex-service-account.test.ts, agent-core, agent-core-v2, and acp-adapter.
    • Documented google-vertex, google-vertex-anthropic, and service_account_file in both English and Chinese configuration docs.

@changeset-bot

changeset-bot Bot commented Aug 22, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0afcf1b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@moonshot-ai/acp-adapter Patch
@moonshot-ai/agent-core Patch
@moonshot-ai/agent-core-v2 Patch
@moonshot-ai/kosong Patch

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +572 to +573
options.vertexai = true;
if (saFile !== undefined) options.serviceAccountFile = saFile;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines +1261 to +1262
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { GoogleAuth } = require('google-auth-library');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines 39 to +41
case 'vertexai':
return new GoogleGenAIChatProvider(config);
case 'google-vertex':
return new GoogleGenAIChatProvider({ ...config, vertexai: true });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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' }) },

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant