mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-22 10:28:13 +00:00
docs: document anthropic runtime provider
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
/**
|
||||
* Anthropic provider plugin entry. It registers Claude API auth, Claude CLI
|
||||
* backend support, media understanding, stream wrappers, and usage reporting.
|
||||
*/
|
||||
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import { registerAnthropicPlugin } from "./register.runtime.js";
|
||||
|
||||
/** Provider entry for Anthropic API and Claude CLI runtime surfaces. */
|
||||
export default definePluginEntry({
|
||||
id: "anthropic",
|
||||
name: "Anthropic Provider",
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
/**
|
||||
* Anthropic media-understanding provider descriptor. It routes image and native
|
||||
* document description through the shared model-backed media helpers.
|
||||
*/
|
||||
import {
|
||||
describeImageWithModel,
|
||||
describeImagesWithModel,
|
||||
type MediaUnderstandingProvider,
|
||||
} from "openclaw/plugin-sdk/media-understanding";
|
||||
|
||||
/** Media-understanding provider for Anthropic Claude models. */
|
||||
export const anthropicMediaUnderstandingProvider: MediaUnderstandingProvider = {
|
||||
id: "anthropic",
|
||||
capabilities: ["image"],
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
/**
|
||||
* Contract API for Anthropic provider metadata. It builds a provider descriptor
|
||||
* without runtime registration side effects.
|
||||
*/
|
||||
import type { ProviderPlugin } from "openclaw/plugin-sdk/provider-model-shared";
|
||||
|
||||
const noopAuth = async () => ({ profiles: [] });
|
||||
|
||||
/** Create the static Anthropic provider contract descriptor. */
|
||||
export function createAnthropicProvider(): ProviderPlugin {
|
||||
return {
|
||||
id: "anthropic",
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Claude CLI provider discovery descriptor. It exposes subscription-backed
|
||||
* synthetic auth for catalog/runtime discovery without full Anthropic registration.
|
||||
*/
|
||||
import type { ProviderPlugin } from "openclaw/plugin-sdk/provider-model-shared";
|
||||
import { readClaudeCliCredentialsForRuntime } from "./cli-auth-seam.js";
|
||||
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Provider-policy API for Anthropic and Claude CLI. Core calls this lightweight
|
||||
* path for config defaults and thinking profiles.
|
||||
*/
|
||||
import { resolveClaudeThinkingProfile } from "openclaw/plugin-sdk/provider-model-shared";
|
||||
import type { ModelProviderConfig } from "openclaw/plugin-sdk/provider-model-types";
|
||||
import {
|
||||
@@ -5,14 +9,17 @@ import {
|
||||
normalizeAnthropicProviderConfigForProvider,
|
||||
} from "./config-defaults.js";
|
||||
|
||||
/** Normalize Anthropic provider config without importing runtime registration. */
|
||||
export function normalizeConfig(params: { provider: string; providerConfig: ModelProviderConfig }) {
|
||||
return normalizeAnthropicProviderConfigForProvider(params);
|
||||
}
|
||||
|
||||
/** Apply Anthropic config defaults through the provider-policy seam. */
|
||||
export function applyConfigDefaults(params: Parameters<typeof applyAnthropicConfigDefaults>[0]) {
|
||||
return applyAnthropicConfigDefaults(params);
|
||||
}
|
||||
|
||||
/** Resolve Claude thinking profile for Anthropic or Claude CLI providers. */
|
||||
export function resolveThinkingProfile(params: { provider: string; modelId: string }) {
|
||||
switch (params.provider.trim().toLowerCase()) {
|
||||
case "anthropic":
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Anthropic provider runtime registration. It owns API-key/setup-token/Claude
|
||||
* CLI auth, dynamic model normalization, usage auth, media, and stream wrappers.
|
||||
*/
|
||||
import { formatCliCommand, parseDurationMs } from "openclaw/plugin-sdk/cli-runtime";
|
||||
import { resolveExpiresAtMsFromDurationMs } from "openclaw/plugin-sdk/number-runtime";
|
||||
import type {
|
||||
@@ -695,6 +699,7 @@ async function resolveAnthropicUsageAuth(
|
||||
return { handled: true };
|
||||
}
|
||||
|
||||
/** Build the full Anthropic provider descriptor used by runtime registration. */
|
||||
export function buildAnthropicProvider(): ProviderPlugin {
|
||||
const providerId = "anthropic";
|
||||
const defaultAnthropicModel = DEFAULT_ANTHROPIC_MODEL;
|
||||
@@ -833,6 +838,7 @@ export function buildAnthropicProvider(): ProviderPlugin {
|
||||
};
|
||||
}
|
||||
|
||||
/** Register Anthropic provider, Claude CLI backend, and media understanding provider. */
|
||||
export function registerAnthropicPlugin(api: OpenClawPluginApi): void {
|
||||
api.registerCliBackend(buildAnthropicCliBackend());
|
||||
api.registerProvider(buildAnthropicProvider());
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Anthropic replay-policy bridge. It re-exports the native Anthropic replay
|
||||
* policy from the shared provider-model hooks and fails fast if it disappears.
|
||||
*/
|
||||
import { NATIVE_ANTHROPIC_REPLAY_HOOKS } from "openclaw/plugin-sdk/provider-model-shared";
|
||||
|
||||
const { buildReplayPolicy } = NATIVE_ANTHROPIC_REPLAY_HOOKS;
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
/**
|
||||
* Lightweight Anthropic setup entry. It registers Claude CLI backend metadata
|
||||
* without loading full provider runtime code.
|
||||
*/
|
||||
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import { buildAnthropicCliBackend } from "./cli-backend.js";
|
||||
|
||||
/** Setup entry for Claude CLI backend registration. */
|
||||
export default definePluginEntry({
|
||||
id: "anthropic",
|
||||
name: "Anthropic Setup",
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Anthropic stream wrappers. They add beta headers, service tier/fast-mode
|
||||
* payload fields, and thinking-prefill cleanup around provider stream functions.
|
||||
*/
|
||||
import type { StreamFn } from "openclaw/plugin-sdk/agent-core";
|
||||
import { streamSimple } from "openclaw/plugin-sdk/llm";
|
||||
import type { ProviderWrapStreamFnContext } from "openclaw/plugin-sdk/plugin-entry";
|
||||
@@ -101,6 +105,7 @@ function hasConfiguredAnthropicBeta(extraParams: Record<string, unknown> | undef
|
||||
return configured.some((beta) => typeof beta === "string" && beta.trim().length > 0);
|
||||
}
|
||||
|
||||
/** Resolve configured Anthropic beta headers from extra model params. */
|
||||
export function resolveAnthropicBetas(
|
||||
extraParams: Record<string, unknown> | undefined,
|
||||
_modelId: string,
|
||||
@@ -128,6 +133,7 @@ export function resolveAnthropicBetas(
|
||||
return betas.size > 0 ? [...betas] : undefined;
|
||||
}
|
||||
|
||||
/** Wrap a stream function to merge OpenClaw and configured Anthropic beta headers. */
|
||||
export function createAnthropicBetaHeadersWrapper(
|
||||
baseStreamFn: StreamFn | undefined,
|
||||
betas: string[],
|
||||
@@ -148,6 +154,7 @@ export function createAnthropicBetaHeadersWrapper(
|
||||
};
|
||||
}
|
||||
|
||||
/** Wrap a stream function with the Anthropic fast-mode service tier. */
|
||||
export function createAnthropicFastModeWrapper(
|
||||
baseStreamFn: StreamFn | undefined,
|
||||
enabled: boolean,
|
||||
@@ -155,6 +162,7 @@ export function createAnthropicFastModeWrapper(
|
||||
return createAnthropicServiceTierWrapper(baseStreamFn, resolveAnthropicFastServiceTier(enabled));
|
||||
}
|
||||
|
||||
/** Wrap a stream function with an explicit Anthropic service tier when allowed. */
|
||||
export function createAnthropicServiceTierWrapper(
|
||||
baseStreamFn: StreamFn | undefined,
|
||||
serviceTier: AnthropicServiceTier,
|
||||
@@ -181,6 +189,7 @@ export function createAnthropicServiceTierWrapper(
|
||||
};
|
||||
}
|
||||
|
||||
/** Wrap a stream function to strip trailing assistant prefill before thinking requests. */
|
||||
export function createAnthropicThinkingPrefillWrapper(
|
||||
baseStreamFn: StreamFn | undefined,
|
||||
): StreamFn {
|
||||
@@ -191,6 +200,7 @@ export function createAnthropicThinkingPrefillWrapper(
|
||||
});
|
||||
}
|
||||
|
||||
/** Resolve Anthropic fast-mode setting from model extra params. */
|
||||
export function resolveAnthropicFastMode(
|
||||
extraParams: Record<string, unknown> | undefined,
|
||||
): boolean | undefined {
|
||||
@@ -199,6 +209,7 @@ export function resolveAnthropicFastMode(
|
||||
);
|
||||
}
|
||||
|
||||
/** Resolve Anthropic service tier from model extra params. */
|
||||
export function resolveAnthropicServiceTier(
|
||||
extraParams: Record<string, unknown> | undefined,
|
||||
): AnthropicServiceTier | undefined {
|
||||
@@ -211,6 +222,7 @@ export function resolveAnthropicServiceTier(
|
||||
return normalized;
|
||||
}
|
||||
|
||||
/** Compose all Anthropic stream wrappers for one provider/model context. */
|
||||
export function wrapAnthropicProviderStream(
|
||||
ctx: ProviderWrapStreamFnContext,
|
||||
): StreamFn | undefined {
|
||||
@@ -236,6 +248,7 @@ export function wrapAnthropicProviderStream(
|
||||
);
|
||||
}
|
||||
|
||||
/** Test-only hooks for Anthropic stream wrapper behavior. */
|
||||
export const testing = {
|
||||
log,
|
||||
stripTrailingAssistantPrefillWhenThinking: stripTrailingAnthropicAssistantPrefillWhenThinking,
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
/**
|
||||
* Test API barrel for Anthropic plugin internals. Tests import this path to
|
||||
* avoid reaching into unrelated runtime modules.
|
||||
*/
|
||||
export { buildAnthropicCliBackend } from "./cli-backend.js";
|
||||
export { normalizeClaudeBackendConfig } from "./cli-shared.js";
|
||||
export { anthropicMediaUnderstandingProvider } from "./media-understanding-provider.js";
|
||||
|
||||
Reference in New Issue
Block a user