mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-16 19:51:11 +00:00
refactor(thinking): move provider thinking fallback out of core
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
import { matchesExactOrPrefix } from "../plugins/provider-model-helpers.js";
|
||||
|
||||
export type ThinkLevel = "off" | "minimal" | "low" | "medium" | "high" | "xhigh" | "adaptive";
|
||||
export type VerboseLevel = "off" | "on" | "full";
|
||||
export type NoticeLevel = "off" | "on" | "full";
|
||||
@@ -14,59 +12,19 @@ export type ThinkingCatalogEntry = {
|
||||
};
|
||||
|
||||
const BASE_THINKING_LEVELS: ThinkLevel[] = ["off", "minimal", "low", "medium", "high", "adaptive"];
|
||||
const ANTHROPIC_CLAUDE_46_MODEL_RE = /^claude-(?:opus|sonnet)-4(?:\.|-)6(?:$|[-.])/i;
|
||||
const AMAZON_BEDROCK_CLAUDE_46_MODEL_RE = /claude-(?:opus|sonnet)-4(?:\.|-)6(?:$|[-.])/i;
|
||||
const OPENAI_XHIGH_MODEL_IDS = [
|
||||
"gpt-5.4",
|
||||
"gpt-5.4-pro",
|
||||
"gpt-5.4-mini",
|
||||
"gpt-5.4-nano",
|
||||
"gpt-5.2",
|
||||
] as const;
|
||||
const OPENAI_CODEX_XHIGH_MODEL_IDS = [
|
||||
"gpt-5.4",
|
||||
"gpt-5.3-codex-spark",
|
||||
"gpt-5.2-codex",
|
||||
"gpt-5.1-codex",
|
||||
] as const;
|
||||
const GITHUB_COPILOT_XHIGH_MODEL_IDS = ["gpt-5.2", "gpt-5.2-codex"] as const;
|
||||
|
||||
export function normalizeProviderId(provider?: string | null): string {
|
||||
if (!provider) {
|
||||
return "";
|
||||
}
|
||||
const normalized = provider.trim().toLowerCase();
|
||||
if (normalized === "z.ai" || normalized === "z-ai") {
|
||||
return "zai";
|
||||
}
|
||||
if (normalized === "bedrock" || normalized === "aws-bedrock") {
|
||||
return "amazon-bedrock";
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
const NO_THINKING_LEVELS: ThinkLevel[] = [...BASE_THINKING_LEVELS];
|
||||
|
||||
export function isBinaryThinkingProvider(provider?: string | null): boolean {
|
||||
return normalizeProviderId(provider) === "zai";
|
||||
void provider;
|
||||
return false;
|
||||
}
|
||||
|
||||
export function supportsBuiltInXHighThinking(
|
||||
provider?: string | null,
|
||||
model?: string | null,
|
||||
): boolean {
|
||||
const providerId = normalizeProviderId(provider);
|
||||
const modelId = model?.trim().toLowerCase();
|
||||
if (!providerId || !modelId) {
|
||||
return false;
|
||||
}
|
||||
if (providerId === "openai") {
|
||||
return matchesExactOrPrefix(modelId, OPENAI_XHIGH_MODEL_IDS);
|
||||
}
|
||||
if (providerId === "openai-codex") {
|
||||
return matchesExactOrPrefix(modelId, OPENAI_CODEX_XHIGH_MODEL_IDS);
|
||||
}
|
||||
if (providerId === "github-copilot") {
|
||||
return GITHUB_COPILOT_XHIGH_MODEL_IDS.includes(modelId as never);
|
||||
}
|
||||
void provider;
|
||||
void model;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -113,7 +71,7 @@ export function listThinkingLevels(
|
||||
_provider?: string | null,
|
||||
_model?: string | null,
|
||||
): ThinkLevel[] {
|
||||
return [...BASE_THINKING_LEVELS];
|
||||
return [...NO_THINKING_LEVELS];
|
||||
}
|
||||
|
||||
export function listThinkingLevelLabels(provider?: string | null, model?: string | null): string[] {
|
||||
@@ -140,14 +98,6 @@ export function resolveThinkingDefaultForModel(params: {
|
||||
model: string;
|
||||
catalog?: ThinkingCatalogEntry[];
|
||||
}): ThinkLevel {
|
||||
const normalizedProvider = normalizeProviderId(params.provider);
|
||||
const modelId = params.model.trim();
|
||||
if (normalizedProvider === "anthropic" && ANTHROPIC_CLAUDE_46_MODEL_RE.test(modelId)) {
|
||||
return "adaptive";
|
||||
}
|
||||
if (normalizedProvider === "amazon-bedrock" && AMAZON_BEDROCK_CLAUDE_46_MODEL_RE.test(modelId)) {
|
||||
return "adaptive";
|
||||
}
|
||||
const candidate = params.catalog?.find(
|
||||
(entry) => entry.provider === params.provider && entry.id === params.model,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user