mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-21 14:11:26 +00:00
fix(providers): stabilize runtime normalization hooks
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import { registerAmazonBedrockPlugin } from "./register.runtime.js";
|
||||
import { registerAmazonBedrockPlugin } from "./register.sync.runtime.js";
|
||||
|
||||
export default definePluginEntry({
|
||||
id: "amazon-bedrock",
|
||||
|
||||
@@ -1,10 +1,16 @@
|
||||
import type { StreamFn } from "@mariozechner/pi-agent-core";
|
||||
import type { OpenClawPluginApi } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import { buildProviderReplayFamilyHooks } from "openclaw/plugin-sdk/provider-model-shared";
|
||||
import {
|
||||
createBedrockNoCacheWrapper,
|
||||
isAnthropicBedrockModel,
|
||||
streamWithPayloadPatch,
|
||||
} from "openclaw/plugin-sdk/provider-stream";
|
||||
import {
|
||||
mergeImplicitBedrockProvider,
|
||||
resolveBedrockConfigApiKey,
|
||||
resolveImplicitBedrockProvider,
|
||||
} from "./api.js";
|
||||
|
||||
type GuardrailConfig = {
|
||||
guardrailIdentifier: string;
|
||||
@@ -38,7 +44,7 @@ function createGuardrailWrapStreamFn(
|
||||
};
|
||||
}
|
||||
|
||||
export async function registerAmazonBedrockPlugin(api: OpenClawPluginApi): Promise<void> {
|
||||
export function registerAmazonBedrockPlugin(api: OpenClawPluginApi): void {
|
||||
// Keep registration-local constants inside the function so partial module
|
||||
// initialization during test bootstrap cannot trip TDZ reads.
|
||||
const providerId = "amazon-bedrock";
|
||||
@@ -48,15 +54,6 @@ export async function registerAmazonBedrockPlugin(api: OpenClawPluginApi): Promi
|
||||
/ValidationException.*(?:exceeds? the (?:maximum|max) (?:number of )?(?:input )?tokens)/i,
|
||||
/ModelStreamErrorException.*(?:Input is too long|too many input tokens)/i,
|
||||
] as const;
|
||||
// Defer provider-owned helper loading until registration so test/plugin-loader
|
||||
// cycles cannot re-enter this module before its constants initialize.
|
||||
const [
|
||||
{ buildProviderReplayFamilyHooks },
|
||||
{ mergeImplicitBedrockProvider, resolveBedrockConfigApiKey, resolveImplicitBedrockProvider },
|
||||
] = await Promise.all([
|
||||
import("openclaw/plugin-sdk/provider-model-shared"),
|
||||
import("./api.js"),
|
||||
]);
|
||||
const anthropicByModelReplayHooks = buildProviderReplayFamilyHooks({
|
||||
family: "anthropic-by-model",
|
||||
});
|
||||
@@ -6,6 +6,6 @@ export default definePluginEntry({
|
||||
name: "Anthropic Provider",
|
||||
description: "Bundled Anthropic provider plugin",
|
||||
register(api) {
|
||||
registerAnthropicPlugin(api);
|
||||
return registerAnthropicPlugin(api);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
} from "openclaw/plugin-sdk/plugin-entry";
|
||||
import {
|
||||
applyAuthProfileConfig,
|
||||
createProviderApiKeyAuthMethod,
|
||||
ensureApiKeyFromOptionEnvOrPrompt,
|
||||
listProfilesForProvider,
|
||||
normalizeApiKeyInput,
|
||||
@@ -17,11 +18,13 @@ import {
|
||||
} from "openclaw/plugin-sdk/provider-auth";
|
||||
import { cloneFirstTemplateModel } from "openclaw/plugin-sdk/provider-model-shared";
|
||||
import { fetchClaudeUsage } from "openclaw/plugin-sdk/provider-usage";
|
||||
import { buildAnthropicCliBackend } from "./cli-backend.js";
|
||||
import { buildAnthropicCliMigrationResult, hasClaudeCliAuth } from "./cli-migration.js";
|
||||
import {
|
||||
applyAnthropicConfigDefaults,
|
||||
normalizeAnthropicProviderConfig,
|
||||
} from "./config-defaults.js";
|
||||
import { anthropicMediaUnderstandingProvider } from "./media-understanding-provider.js";
|
||||
import { buildAnthropicReplayPolicy } from "./replay-policy.js";
|
||||
import { wrapAnthropicProviderStream } from "./stream-wrappers.js";
|
||||
|
||||
@@ -200,7 +203,7 @@ async function runAnthropicCliMigrationNonInteractive(ctx: {
|
||||
};
|
||||
}
|
||||
|
||||
export async function registerAnthropicPlugin(api: OpenClawPluginApi): Promise<void> {
|
||||
export function registerAnthropicPlugin(api: OpenClawPluginApi): void {
|
||||
const claudeCliProfileId = "anthropic:claude-cli";
|
||||
const providerId = "anthropic";
|
||||
const defaultAnthropicModel = "anthropic/claude-sonnet-4-6";
|
||||
@@ -211,45 +214,7 @@ export async function registerAnthropicPlugin(api: OpenClawPluginApi): Promise<v
|
||||
"anthropic/claude-sonnet-4-5",
|
||||
"anthropic/claude-haiku-4-5",
|
||||
] as const;
|
||||
let createApiKeyAuthMethod:
|
||||
| (typeof import("openclaw/plugin-sdk/provider-auth-api-key"))["createProviderApiKeyAuthMethod"]
|
||||
| undefined;
|
||||
let mediaUnderstandingProvider:
|
||||
| (typeof import("./media-understanding-provider.js"))["anthropicMediaUnderstandingProvider"]
|
||||
| undefined;
|
||||
|
||||
// Avoid touching a partially initialized static binding during cyclic bootstrap.
|
||||
try {
|
||||
const cliBackendModule = await import("./cli-backend.js");
|
||||
const cliBackend =
|
||||
typeof cliBackendModule.buildAnthropicCliBackend === "function"
|
||||
? cliBackendModule.buildAnthropicCliBackend()
|
||||
: undefined;
|
||||
if (cliBackend) {
|
||||
api.registerCliBackend(cliBackend);
|
||||
}
|
||||
} catch {
|
||||
// Best-effort during test bootstrap; provider registration still proceeds.
|
||||
}
|
||||
try {
|
||||
const providerApiKeyAuthModule = await import("openclaw/plugin-sdk/provider-auth-api-key");
|
||||
createApiKeyAuthMethod =
|
||||
typeof providerApiKeyAuthModule.createProviderApiKeyAuthMethod === "function"
|
||||
? providerApiKeyAuthModule.createProviderApiKeyAuthMethod
|
||||
: undefined;
|
||||
} catch {
|
||||
createApiKeyAuthMethod = undefined;
|
||||
}
|
||||
if (!createApiKeyAuthMethod) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const mediaUnderstandingModule = await import("./media-understanding-provider.js");
|
||||
mediaUnderstandingProvider =
|
||||
mediaUnderstandingModule.anthropicMediaUnderstandingProvider ?? undefined;
|
||||
} catch {
|
||||
mediaUnderstandingProvider = undefined;
|
||||
}
|
||||
api.registerCliBackend(buildAnthropicCliBackend());
|
||||
api.registerProvider({
|
||||
id: providerId,
|
||||
label: "Anthropic",
|
||||
@@ -291,7 +256,7 @@ export async function registerAnthropicPlugin(api: OpenClawPluginApi): Promise<v
|
||||
runtime: ctx.runtime,
|
||||
}),
|
||||
},
|
||||
createApiKeyAuthMethod({
|
||||
createProviderApiKeyAuthMethod({
|
||||
providerId,
|
||||
methodId: "api-key",
|
||||
label: "Anthropic API key",
|
||||
@@ -337,7 +302,5 @@ export async function registerAnthropicPlugin(api: OpenClawPluginApi): Promise<v
|
||||
profileId: ctx.profileId,
|
||||
}),
|
||||
});
|
||||
if (mediaUnderstandingProvider) {
|
||||
api.registerMediaUnderstandingProvider(mediaUnderstandingProvider);
|
||||
}
|
||||
api.registerMediaUnderstandingProvider(anthropicMediaUnderstandingProvider);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,16 @@
|
||||
import { definePluginEntry, type ProviderAuthContext } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import {
|
||||
coerceSecretRef,
|
||||
DEFAULT_COPILOT_API_BASE_URL,
|
||||
ensureAuthProfileStore,
|
||||
fetchCopilotUsage,
|
||||
githubCopilotLoginCommand,
|
||||
listProfilesForProvider,
|
||||
PROVIDER_ID,
|
||||
resolveCopilotApiToken,
|
||||
resolveCopilotForwardCompatModel,
|
||||
wrapCopilotProviderStream,
|
||||
} from "./register.runtime.js";
|
||||
|
||||
const COPILOT_ENV_VARS = ["COPILOT_GITHUB_TOKEN", "GH_TOKEN", "GITHUB_TOKEN"];
|
||||
const COPILOT_XHIGH_MODEL_IDS = ["gpt-5.2", "gpt-5.2-codex"] as const;
|
||||
@@ -15,19 +27,7 @@ export default definePluginEntry({
|
||||
id: "github-copilot",
|
||||
name: "GitHub Copilot Provider",
|
||||
description: "Bundled GitHub Copilot provider plugin",
|
||||
async register(api) {
|
||||
const {
|
||||
coerceSecretRef,
|
||||
DEFAULT_COPILOT_API_BASE_URL,
|
||||
ensureAuthProfileStore,
|
||||
fetchCopilotUsage,
|
||||
githubCopilotLoginCommand,
|
||||
listProfilesForProvider,
|
||||
PROVIDER_ID,
|
||||
resolveCopilotApiToken,
|
||||
resolveCopilotForwardCompatModel,
|
||||
wrapCopilotProviderStream,
|
||||
} = await import("./register.runtime.js");
|
||||
register(api) {
|
||||
function resolveFirstGithubToken(params: { agentDir?: string; env: NodeJS.ProcessEnv }): {
|
||||
githubToken: string;
|
||||
hasProfile: boolean;
|
||||
|
||||
@@ -1,10 +1,24 @@
|
||||
export {
|
||||
import {
|
||||
coerceSecretRef,
|
||||
ensureAuthProfileStore,
|
||||
listProfilesForProvider,
|
||||
} from "openclaw/plugin-sdk/provider-auth";
|
||||
export { githubCopilotLoginCommand } from "openclaw/plugin-sdk/provider-auth-login";
|
||||
export { PROVIDER_ID, resolveCopilotForwardCompatModel } from "./models.js";
|
||||
export { wrapCopilotAnthropicStream, wrapCopilotProviderStream } from "./stream.js";
|
||||
export { DEFAULT_COPILOT_API_BASE_URL, resolveCopilotApiToken } from "./token.js";
|
||||
export { fetchCopilotUsage } from "./usage.js";
|
||||
import { githubCopilotLoginCommand } from "openclaw/plugin-sdk/provider-auth-login";
|
||||
import { PROVIDER_ID, resolveCopilotForwardCompatModel } from "./models.js";
|
||||
import { wrapCopilotAnthropicStream, wrapCopilotProviderStream } from "./stream.js";
|
||||
import { DEFAULT_COPILOT_API_BASE_URL, resolveCopilotApiToken } from "./token.js";
|
||||
import { fetchCopilotUsage } from "./usage.js";
|
||||
|
||||
export {
|
||||
coerceSecretRef,
|
||||
DEFAULT_COPILOT_API_BASE_URL,
|
||||
ensureAuthProfileStore,
|
||||
fetchCopilotUsage,
|
||||
githubCopilotLoginCommand,
|
||||
listProfilesForProvider,
|
||||
PROVIDER_ID,
|
||||
resolveCopilotApiToken,
|
||||
resolveCopilotForwardCompatModel,
|
||||
wrapCopilotAnthropicStream,
|
||||
wrapCopilotProviderStream,
|
||||
};
|
||||
|
||||
@@ -5,6 +5,18 @@ import {
|
||||
type ProviderRuntimeModel,
|
||||
type ProviderWrapStreamFnContext,
|
||||
} from "openclaw/plugin-sdk/plugin-entry";
|
||||
import {
|
||||
applyOpenrouterConfig,
|
||||
buildOpenrouterProvider,
|
||||
buildProviderReplayFamilyHooks,
|
||||
buildProviderStreamFamilyHooks,
|
||||
createProviderApiKeyAuthMethod,
|
||||
DEFAULT_CONTEXT_TOKENS,
|
||||
getOpenRouterModelCapabilities,
|
||||
loadOpenRouterModelCapabilities,
|
||||
OPENROUTER_DEFAULT_MODEL_REF,
|
||||
openrouterMediaUnderstandingProvider,
|
||||
} from "./register.runtime.js";
|
||||
|
||||
const PROVIDER_ID = "openrouter";
|
||||
const OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1";
|
||||
@@ -20,19 +32,7 @@ export default definePluginEntry({
|
||||
id: "openrouter",
|
||||
name: "OpenRouter Provider",
|
||||
description: "Bundled OpenRouter provider plugin",
|
||||
async register(api) {
|
||||
const {
|
||||
buildProviderReplayFamilyHooks,
|
||||
buildProviderStreamFamilyHooks,
|
||||
createProviderApiKeyAuthMethod,
|
||||
DEFAULT_CONTEXT_TOKENS,
|
||||
getOpenRouterModelCapabilities,
|
||||
loadOpenRouterModelCapabilities,
|
||||
OPENROUTER_DEFAULT_MODEL_REF,
|
||||
openrouterMediaUnderstandingProvider,
|
||||
applyOpenrouterConfig,
|
||||
buildOpenrouterProvider,
|
||||
} = await import("./register.runtime.js");
|
||||
register(api) {
|
||||
const PASSTHROUGH_GEMINI_REPLAY_HOOKS = buildProviderReplayFamilyHooks({
|
||||
family: "passthrough-gemini",
|
||||
});
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
export { createProviderApiKeyAuthMethod } from "openclaw/plugin-sdk/provider-auth-api-key";
|
||||
export {
|
||||
import { createProviderApiKeyAuthMethod } from "openclaw/plugin-sdk/provider-auth-api-key";
|
||||
import {
|
||||
buildProviderReplayFamilyHooks,
|
||||
DEFAULT_CONTEXT_TOKENS,
|
||||
} from "openclaw/plugin-sdk/provider-model-shared";
|
||||
export {
|
||||
import {
|
||||
buildProviderStreamFamilyHooks,
|
||||
createOpenRouterSystemCacheWrapper,
|
||||
createOpenRouterWrapper,
|
||||
@@ -11,6 +11,22 @@ export {
|
||||
isProxyReasoningUnsupported,
|
||||
loadOpenRouterModelCapabilities,
|
||||
} from "openclaw/plugin-sdk/provider-stream";
|
||||
export { openrouterMediaUnderstandingProvider } from "./media-understanding-provider.js";
|
||||
export { applyOpenrouterConfig, OPENROUTER_DEFAULT_MODEL_REF } from "./onboard.js";
|
||||
export { buildOpenrouterProvider } from "./provider-catalog.js";
|
||||
import { openrouterMediaUnderstandingProvider } from "./media-understanding-provider.js";
|
||||
import { applyOpenrouterConfig, OPENROUTER_DEFAULT_MODEL_REF } from "./onboard.js";
|
||||
import { buildOpenrouterProvider } from "./provider-catalog.js";
|
||||
|
||||
export {
|
||||
applyOpenrouterConfig,
|
||||
buildOpenrouterProvider,
|
||||
buildProviderReplayFamilyHooks,
|
||||
buildProviderStreamFamilyHooks,
|
||||
createOpenRouterSystemCacheWrapper,
|
||||
createOpenRouterWrapper,
|
||||
createProviderApiKeyAuthMethod,
|
||||
DEFAULT_CONTEXT_TOKENS,
|
||||
getOpenRouterModelCapabilities,
|
||||
isProxyReasoningUnsupported,
|
||||
loadOpenRouterModelCapabilities,
|
||||
OPENROUTER_DEFAULT_MODEL_REF,
|
||||
openrouterMediaUnderstandingProvider,
|
||||
};
|
||||
|
||||
@@ -2,3 +2,8 @@ export {
|
||||
buildChannelConfigSchema,
|
||||
TelegramConfigSchema,
|
||||
} from "openclaw/plugin-sdk/channel-config-schema";
|
||||
export {
|
||||
normalizeTelegramCommandDescription,
|
||||
normalizeTelegramCommandName,
|
||||
resolveTelegramCustomCommands,
|
||||
} from "./src/command-config.js";
|
||||
|
||||
Reference in New Issue
Block a user