mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-06 05:51:15 +08:00
docs: document anthropic vertex plugin
This commit is contained in:
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Public Anthropic Vertex API barrel. It exposes lightweight discovery helpers
|
||||
* and lazy stream factories without eagerly importing the Vertex SDK runtime.
|
||||
*/
|
||||
import type { StreamFn } from "openclaw/plugin-sdk/agent-core";
|
||||
import type { AnthropicVertexStreamDeps } from "./stream-runtime.js";
|
||||
|
||||
@@ -24,6 +28,7 @@ const loadStreamRuntimeModule = async () => {
|
||||
return await streamRuntimeModulePromise;
|
||||
};
|
||||
|
||||
/** Merge an implicit Anthropic Vertex provider with explicit user config. */
|
||||
export function mergeImplicitAnthropicVertexProvider(params: {
|
||||
existing?: ReturnType<typeof buildAnthropicVertexProvider>;
|
||||
implicit: ReturnType<typeof buildAnthropicVertexProvider>;
|
||||
@@ -42,6 +47,7 @@ export function mergeImplicitAnthropicVertexProvider(params: {
|
||||
};
|
||||
}
|
||||
|
||||
/** Resolve an implicit Anthropic Vertex provider when ADC credentials are available. */
|
||||
export function resolveImplicitAnthropicVertexProvider(params?: { env?: NodeJS.ProcessEnv }) {
|
||||
const env = params?.env ?? process.env;
|
||||
if (!hasAnthropicVertexAvailableAuth(env)) {
|
||||
@@ -51,6 +57,7 @@ export function resolveImplicitAnthropicVertexProvider(params?: { env?: NodeJS.P
|
||||
return buildAnthropicVertexProvider({ env });
|
||||
}
|
||||
|
||||
/** Create a lazy Anthropic Vertex stream function for a known project/region/base URL. */
|
||||
export function createAnthropicVertexStreamFn(
|
||||
projectId: string | undefined,
|
||||
region: string,
|
||||
@@ -66,6 +73,7 @@ export function createAnthropicVertexStreamFn(
|
||||
};
|
||||
}
|
||||
|
||||
/** Create a lazy Anthropic Vertex stream function using model base URL and env hints. */
|
||||
export function createAnthropicVertexStreamFnForModel(
|
||||
model: { baseUrl?: string },
|
||||
env: NodeJS.ProcessEnv = process.env,
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Anthropic Vertex provider plugin entry. It registers implicit ADC-backed
|
||||
* catalog discovery, Anthropic replay policy, thinking profiles, and auth markers.
|
||||
*/
|
||||
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import { readConfiguredProviderCatalogEntries } from "openclaw/plugin-sdk/provider-catalog-shared";
|
||||
import {
|
||||
@@ -14,6 +18,7 @@ import {
|
||||
const PROVIDER_ID = "anthropic-vertex";
|
||||
const GCP_VERTEX_CREDENTIALS_MARKER = "gcp-vertex-credentials";
|
||||
|
||||
/** Provider entry for Anthropic Claude models served through Google Vertex AI. */
|
||||
export default definePluginEntry({
|
||||
id: PROVIDER_ID,
|
||||
name: "Anthropic Vertex Provider",
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
/**
|
||||
* Static Anthropic Vertex model catalog builder. It derives provider base URLs
|
||||
* from region configuration and publishes Claude model metadata.
|
||||
*/
|
||||
import type {
|
||||
ModelDefinitionConfig,
|
||||
ModelProviderConfig,
|
||||
} from "openclaw/plugin-sdk/provider-model-shared";
|
||||
import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
|
||||
import { resolveAnthropicVertexRegion } from "./region.js";
|
||||
/** Default Anthropic Vertex model used for implicit provider catalogs. */
|
||||
export const ANTHROPIC_VERTEX_DEFAULT_MODEL_ID = "claude-sonnet-4-6";
|
||||
const ANTHROPIC_VERTEX_DEFAULT_CONTEXT_WINDOW = 1_000_000;
|
||||
const GCP_VERTEX_CREDENTIALS_MARKER = "gcp-vertex-credentials";
|
||||
@@ -59,6 +64,7 @@ function buildAnthropicVertexCatalog(): ModelDefinitionConfig[] {
|
||||
];
|
||||
}
|
||||
|
||||
/** Build the implicit Anthropic Vertex provider config for the current env. */
|
||||
export function buildAnthropicVertexProvider(params?: {
|
||||
env?: NodeJS.ProcessEnv;
|
||||
}): ModelProviderConfig {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Provider discovery descriptor for Anthropic Vertex. This variant is used by
|
||||
* catalog surfaces that need the provider contract without full plugin entry setup.
|
||||
*/
|
||||
import type { ProviderCatalogContext } from "openclaw/plugin-sdk/provider-catalog-shared";
|
||||
import type { ModelProviderConfig } from "openclaw/plugin-sdk/provider-model-shared";
|
||||
import { buildAnthropicVertexProvider } from "./provider-catalog.js";
|
||||
@@ -67,6 +71,7 @@ async function runAnthropicVertexCatalog(ctx: ProviderCatalogContext) {
|
||||
};
|
||||
}
|
||||
|
||||
/** Anthropic Vertex provider discovery descriptor. */
|
||||
export const anthropicVertexProviderDiscovery: AnthropicVertexProviderPlugin = {
|
||||
id: PROVIDER_ID,
|
||||
label: "Anthropic Vertex",
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
/**
|
||||
* Provider-policy API for Anthropic Vertex. Core asks for thinking profiles
|
||||
* without importing the provider entry or stream runtime.
|
||||
*/
|
||||
import { resolveClaudeThinkingProfile } from "openclaw/plugin-sdk/provider-model-shared";
|
||||
|
||||
/** Resolve Anthropic Vertex thinking profile for a provider/model pair. */
|
||||
export function resolveThinkingProfile(params: { provider: string; modelId: string }) {
|
||||
if (params.provider.trim().toLowerCase() !== "anthropic-vertex") {
|
||||
return null;
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Anthropic Vertex region, project, and ADC auth detection helpers. They keep
|
||||
* credential probing local to the provider plugin.
|
||||
*/
|
||||
import { readFileSync } from "node:fs";
|
||||
import { homedir, platform } from "node:os";
|
||||
import { join } from "node:path";
|
||||
@@ -21,6 +25,7 @@ function normalizeOptionalSecretInput(value: unknown): string | undefined {
|
||||
return trimmed || undefined;
|
||||
}
|
||||
|
||||
/** Resolve the configured Vertex region, defaulting to global. */
|
||||
export function resolveAnthropicVertexRegion(env: NodeJS.ProcessEnv = process.env): string {
|
||||
const region =
|
||||
normalizeOptionalSecretInput(env.GOOGLE_CLOUD_LOCATION) ||
|
||||
@@ -31,6 +36,7 @@ export function resolveAnthropicVertexRegion(env: NodeJS.ProcessEnv = process.en
|
||||
: ANTHROPIC_VERTEX_DEFAULT_REGION;
|
||||
}
|
||||
|
||||
/** Resolve the Vertex project id from explicit env or ADC files. */
|
||||
export function resolveAnthropicVertexProjectId(
|
||||
env: NodeJS.ProcessEnv = process.env,
|
||||
): string | undefined {
|
||||
@@ -42,11 +48,13 @@ export function resolveAnthropicVertexProjectId(
|
||||
);
|
||||
}
|
||||
|
||||
/** Extract a Vertex region from a provider base URL when possible. */
|
||||
export function resolveAnthropicVertexRegionFromBaseUrl(baseUrl?: string): string | undefined {
|
||||
const endpoint = resolveProviderEndpoint(baseUrl);
|
||||
return endpoint.endpointClass === "google-vertex" ? endpoint.googleVertexRegion : undefined;
|
||||
}
|
||||
|
||||
/** Resolve the client region from model base URL first, then env fallback. */
|
||||
export function resolveAnthropicVertexClientRegion(params?: {
|
||||
baseUrl?: string;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
@@ -130,14 +138,17 @@ function resolveAnthropicVertexProjectIdFromAdc(
|
||||
}
|
||||
}
|
||||
|
||||
/** Return whether ADC credentials or metadata-server auth are available. */
|
||||
export function hasAnthropicVertexCredentials(env: NodeJS.ProcessEnv = process.env): boolean {
|
||||
return hasAnthropicVertexMetadataServerAdc(env) || canReadAnthropicVertexAdc(env);
|
||||
}
|
||||
|
||||
/** Return whether Anthropic Vertex has usable auth for implicit registration. */
|
||||
export function hasAnthropicVertexAvailableAuth(env: NodeJS.ProcessEnv = process.env): boolean {
|
||||
return hasAnthropicVertexCredentials(env);
|
||||
}
|
||||
|
||||
/** Resolve the synthetic config API key marker for Anthropic Vertex auth. */
|
||||
export function resolveAnthropicVertexConfigApiKey(
|
||||
env: NodeJS.ProcessEnv = process.env,
|
||||
): string | undefined {
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
/**
|
||||
* Lightweight Anthropic Vertex setup entry. It exposes provider auth detection
|
||||
* without importing the stream runtime or Vertex SDK.
|
||||
*/
|
||||
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import { resolveAnthropicVertexConfigApiKey } from "./region.js";
|
||||
|
||||
/** Setup entry for Anthropic Vertex provider auth probing. */
|
||||
export default definePluginEntry({
|
||||
id: "anthropic-vertex",
|
||||
name: "Anthropic Vertex Setup",
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Anthropic Vertex stream runtime. It constructs Vertex SDK clients and adapts
|
||||
* OpenClaw stream options into Anthropic Messages payload policy.
|
||||
*/
|
||||
import { AnthropicVertex as AnthropicVertexSdk } from "@anthropic-ai/vertex-sdk";
|
||||
import type { StreamFn } from "openclaw/plugin-sdk/agent-core";
|
||||
import {
|
||||
@@ -26,6 +30,7 @@ type AnthropicVertexClientOptions = {
|
||||
region: string;
|
||||
};
|
||||
|
||||
/** Injectable dependencies for Anthropic Vertex stream tests. */
|
||||
export type AnthropicVertexStreamDeps = {
|
||||
AnthropicVertex: new (options: AnthropicVertexClientOptions) => unknown;
|
||||
streamAnthropic: typeof streamDefault;
|
||||
@@ -222,6 +227,7 @@ function resolveAnthropicVertexSdkBaseUrl(baseUrl?: string): string | undefined
|
||||
}
|
||||
}
|
||||
|
||||
/** Create an Anthropic Vertex stream function from model metadata and env. */
|
||||
export function createAnthropicVertexStreamFnForModel(
|
||||
model: { baseUrl?: string },
|
||||
env: NodeJS.ProcessEnv = process.env,
|
||||
|
||||
Reference in New Issue
Block a user