mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-04 05:00:21 +00:00
refactor(providers): add family replay and tool hooks
This commit is contained in:
@@ -4,6 +4,22 @@
|
||||
// without recursing through provider-specific facades.
|
||||
|
||||
import type { BedrockDiscoveryConfig, ModelDefinitionConfig } from "../config/types.models.js";
|
||||
import type { ProviderPlugin } from "../plugins/types.js";
|
||||
import {
|
||||
buildAnthropicReplayPolicyForModel,
|
||||
buildGoogleGeminiReplayPolicy,
|
||||
buildHybridAnthropicOrOpenAIReplayPolicy,
|
||||
buildOpenAICompatibleReplayPolicy,
|
||||
buildPassthroughGeminiSanitizingReplayPolicy,
|
||||
buildStrictAnthropicReplayPolicy,
|
||||
resolveTaggedReasoningOutputMode,
|
||||
sanitizeGoogleGeminiReplayHistory,
|
||||
} from "../plugins/provider-replay-helpers.js";
|
||||
import type {
|
||||
ProviderReasoningOutputModeContext,
|
||||
ProviderReplayPolicyContext,
|
||||
ProviderSanitizeReplayHistoryContext,
|
||||
} from "./plugin-entry.js";
|
||||
|
||||
export type { ModelApi, ModelProviderConfig } from "../config/types.models.js";
|
||||
export type {
|
||||
@@ -38,7 +54,7 @@ export {
|
||||
resolveTaggedReasoningOutputMode,
|
||||
sanitizeGoogleGeminiReplayHistory,
|
||||
buildStrictAnthropicReplayPolicy,
|
||||
} from "../plugins/provider-replay-helpers.js";
|
||||
};
|
||||
export {
|
||||
createMoonshotThinkingWrapper,
|
||||
resolveMoonshotThinkingType,
|
||||
@@ -110,3 +126,62 @@ export function normalizeNativeXaiModelId(id: string): string {
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
export type ProviderReplayFamily =
|
||||
| "openai-compatible"
|
||||
| "anthropic-by-model"
|
||||
| "google-gemini"
|
||||
| "passthrough-gemini"
|
||||
| "hybrid-anthropic-openai";
|
||||
|
||||
type ProviderReplayFamilyHooks = Pick<
|
||||
ProviderPlugin,
|
||||
"buildReplayPolicy" | "sanitizeReplayHistory" | "resolveReasoningOutputMode"
|
||||
>;
|
||||
|
||||
type BuildProviderReplayFamilyHooksOptions =
|
||||
| { family: "openai-compatible" }
|
||||
| { family: "anthropic-by-model" }
|
||||
| { family: "google-gemini" }
|
||||
| { family: "passthrough-gemini" }
|
||||
| {
|
||||
family: "hybrid-anthropic-openai";
|
||||
anthropicModelDropThinkingBlocks?: boolean;
|
||||
};
|
||||
|
||||
export function buildProviderReplayFamilyHooks(
|
||||
options: BuildProviderReplayFamilyHooksOptions,
|
||||
): ProviderReplayFamilyHooks {
|
||||
switch (options.family) {
|
||||
case "openai-compatible":
|
||||
return {
|
||||
buildReplayPolicy: (ctx: ProviderReplayPolicyContext) =>
|
||||
buildOpenAICompatibleReplayPolicy(ctx.modelApi),
|
||||
};
|
||||
case "anthropic-by-model":
|
||||
return {
|
||||
buildReplayPolicy: ({ modelId }: ProviderReplayPolicyContext) =>
|
||||
buildAnthropicReplayPolicyForModel(modelId),
|
||||
};
|
||||
case "google-gemini":
|
||||
return {
|
||||
buildReplayPolicy: () => buildGoogleGeminiReplayPolicy(),
|
||||
sanitizeReplayHistory: (ctx: ProviderSanitizeReplayHistoryContext) =>
|
||||
sanitizeGoogleGeminiReplayHistory(ctx),
|
||||
resolveReasoningOutputMode: (_ctx: ProviderReasoningOutputModeContext) =>
|
||||
resolveTaggedReasoningOutputMode(),
|
||||
};
|
||||
case "passthrough-gemini":
|
||||
return {
|
||||
buildReplayPolicy: ({ modelId }: ProviderReplayPolicyContext) =>
|
||||
buildPassthroughGeminiSanitizingReplayPolicy(modelId),
|
||||
};
|
||||
case "hybrid-anthropic-openai":
|
||||
return {
|
||||
buildReplayPolicy: (ctx: ProviderReplayPolicyContext) =>
|
||||
buildHybridAnthropicOrOpenAIReplayPolicy(ctx, {
|
||||
anthropicModelDropThinkingBlocks: options.anthropicModelDropThinkingBlocks,
|
||||
}),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user