refactor: add provider replay runtime hook surfaces (#59143)

Merged via squash.

Prepared head SHA: 56b41e87a5
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
This commit is contained in:
Josh Lehman
2026-04-01 13:45:41 -07:00
committed by GitHub
parent ca76e2fedc
commit 71346940ad
15 changed files with 771 additions and 102 deletions

View File

@@ -20,8 +20,13 @@ import type {
ProviderCreateStreamFnContext,
ProviderDefaultThinkingPolicyContext,
ProviderFetchUsageSnapshotContext,
ProviderNormalizeToolSchemasContext,
ProviderNormalizeConfigContext,
ProviderNormalizeModelIdContext,
ProviderReasoningOutputMode,
ProviderReasoningOutputModeContext,
ProviderReplayPolicy,
ProviderReplayPolicyContext,
ProviderNormalizeResolvedModelContext,
ProviderNormalizeTransportContext,
ProviderModernModelPolicyContext,
@@ -29,11 +34,13 @@ import type {
ProviderPrepareDynamicModelContext,
ProviderPrepareRuntimeAuthContext,
ProviderResolveConfigApiKeyContext,
ProviderSanitizeReplayHistoryContext,
ProviderResolveUsageAuthContext,
ProviderPlugin,
ProviderResolveDynamicModelContext,
ProviderRuntimeModel,
ProviderThinkingPolicyContext,
ProviderValidateReplayTurnsContext,
ProviderWrapStreamFnContext,
} from "./types.js";
@@ -435,6 +442,57 @@ export function resolveProviderCapabilitiesWithPlugin(params: {
return resolveProviderRuntimePlugin(params)?.capabilities;
}
export function resolveProviderReplayPolicyWithPlugin(params: {
provider: string;
config?: OpenClawConfig;
workspaceDir?: string;
env?: NodeJS.ProcessEnv;
context: ProviderReplayPolicyContext;
}): ProviderReplayPolicy | undefined {
return resolveProviderHookPlugin(params)?.buildReplayPolicy?.(params.context) ?? undefined;
}
export async function sanitizeProviderReplayHistoryWithPlugin(params: {
provider: string;
config?: OpenClawConfig;
workspaceDir?: string;
env?: NodeJS.ProcessEnv;
context: ProviderSanitizeReplayHistoryContext;
}) {
return await resolveProviderHookPlugin(params)?.sanitizeReplayHistory?.(params.context);
}
export async function validateProviderReplayTurnsWithPlugin(params: {
provider: string;
config?: OpenClawConfig;
workspaceDir?: string;
env?: NodeJS.ProcessEnv;
context: ProviderValidateReplayTurnsContext;
}) {
return await resolveProviderHookPlugin(params)?.validateReplayTurns?.(params.context);
}
export function normalizeProviderToolSchemasWithPlugin(params: {
provider: string;
config?: OpenClawConfig;
workspaceDir?: string;
env?: NodeJS.ProcessEnv;
context: ProviderNormalizeToolSchemasContext;
}) {
return resolveProviderHookPlugin(params)?.normalizeToolSchemas?.(params.context) ?? undefined;
}
export function resolveProviderReasoningOutputModeWithPlugin(params: {
provider: string;
config?: OpenClawConfig;
workspaceDir?: string;
env?: NodeJS.ProcessEnv;
context: ProviderReasoningOutputModeContext;
}): ProviderReasoningOutputMode | undefined {
const mode = resolveProviderHookPlugin(params)?.resolveReasoningOutputMode?.(params.context);
return mode === "native" || mode === "tagged" ? mode : undefined;
}
export function prepareProviderExtraParams(params: {
provider: string;
config?: OpenClawConfig;