mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 21:40:21 +00:00
refactor(plugins): move auth and model policy to providers
This commit is contained in:
@@ -70,23 +70,25 @@ describe("listThinkingLevels", () => {
|
||||
expect(listThinkingLevels("demo", "demo-model")).toContain("xhigh");
|
||||
});
|
||||
|
||||
it("includes xhigh for codex models", () => {
|
||||
expect(listThinkingLevels(undefined, "gpt-5.2-codex")).toContain("xhigh");
|
||||
expect(listThinkingLevels(undefined, "gpt-5.3-codex")).toContain("xhigh");
|
||||
expect(listThinkingLevels(undefined, "gpt-5.3-codex-spark")).toContain("xhigh");
|
||||
});
|
||||
it("includes xhigh for provider-advertised models", () => {
|
||||
providerRuntimeMocks.resolveProviderXHighThinking.mockImplementation(({ provider, context }) =>
|
||||
(provider === "openai" && ["gpt-5.2", "gpt-5.4", "gpt-5.4-pro"].includes(context.modelId)) ||
|
||||
(provider === "openai-codex" &&
|
||||
["gpt-5.2-codex", "gpt-5.3-codex", "gpt-5.3-codex-spark", "gpt-5.4"].includes(
|
||||
context.modelId,
|
||||
)) ||
|
||||
(provider === "github-copilot" && ["gpt-5.2", "gpt-5.2-codex"].includes(context.modelId))
|
||||
? true
|
||||
: undefined,
|
||||
);
|
||||
|
||||
it("includes xhigh for openai gpt-5.2 and gpt-5.4 variants", () => {
|
||||
expect(listThinkingLevels("openai-codex", "gpt-5.2-codex")).toContain("xhigh");
|
||||
expect(listThinkingLevels("openai-codex", "gpt-5.3-codex")).toContain("xhigh");
|
||||
expect(listThinkingLevels("openai-codex", "gpt-5.3-codex-spark")).toContain("xhigh");
|
||||
expect(listThinkingLevels("openai", "gpt-5.2")).toContain("xhigh");
|
||||
expect(listThinkingLevels("openai", "gpt-5.4")).toContain("xhigh");
|
||||
expect(listThinkingLevels("openai", "gpt-5.4-pro")).toContain("xhigh");
|
||||
});
|
||||
|
||||
it("includes xhigh for openai-codex gpt-5.4", () => {
|
||||
expect(listThinkingLevels("openai-codex", "gpt-5.4")).toContain("xhigh");
|
||||
});
|
||||
|
||||
it("includes xhigh for github-copilot gpt-5.2 refs", () => {
|
||||
expect(listThinkingLevels("github-copilot", "gpt-5.2")).toContain("xhigh");
|
||||
expect(listThinkingLevels("github-copilot", "gpt-5.2-codex")).toContain("xhigh");
|
||||
});
|
||||
@@ -108,7 +110,11 @@ describe("listThinkingLevelLabels", () => {
|
||||
expect(listThinkingLevelLabels("demo", "demo-model")).toEqual(["off", "on"]);
|
||||
});
|
||||
|
||||
it("returns on/off for ZAI", () => {
|
||||
it("returns on/off for provider-advertised binary thinking", () => {
|
||||
providerRuntimeMocks.resolveProviderBinaryThinking.mockImplementation(({ provider }) =>
|
||||
provider === "zai" ? true : undefined,
|
||||
);
|
||||
|
||||
expect(listThinkingLevelLabels("zai", "glm-4.7")).toEqual(["off", "on"]);
|
||||
});
|
||||
|
||||
@@ -127,7 +133,12 @@ describe("resolveThinkingDefaultForModel", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("defaults Claude 4.6 models to adaptive", () => {
|
||||
it("uses provider-advertised adaptive defaults", () => {
|
||||
providerRuntimeMocks.resolveProviderDefaultThinkingLevel.mockImplementation(
|
||||
({ provider, context }) =>
|
||||
provider === "anthropic" && context.modelId === "claude-opus-4-6" ? "adaptive" : undefined,
|
||||
);
|
||||
|
||||
expect(
|
||||
resolveThinkingDefaultForModel({ provider: "anthropic", model: "claude-opus-4-6" }),
|
||||
).toBe("adaptive");
|
||||
|
||||
@@ -49,30 +49,9 @@ export function isBinaryThinkingProvider(provider?: string | null, model?: strin
|
||||
if (typeof pluginDecision === "boolean") {
|
||||
return pluginDecision;
|
||||
}
|
||||
|
||||
return normalizedProvider === "zai";
|
||||
return false;
|
||||
}
|
||||
|
||||
export const XHIGH_MODEL_REFS = [
|
||||
"openai/gpt-5.4",
|
||||
"openai/gpt-5.4-pro",
|
||||
"openai/gpt-5.2",
|
||||
"openai-codex/gpt-5.4",
|
||||
"openai-codex/gpt-5.3-codex",
|
||||
"openai-codex/gpt-5.3-codex-spark",
|
||||
"openai-codex/gpt-5.2-codex",
|
||||
"openai-codex/gpt-5.1-codex",
|
||||
"github-copilot/gpt-5.2-codex",
|
||||
"github-copilot/gpt-5.2",
|
||||
] as const;
|
||||
|
||||
const XHIGH_MODEL_SET = new Set(XHIGH_MODEL_REFS.map((entry) => entry.toLowerCase()));
|
||||
const XHIGH_MODEL_IDS = new Set(
|
||||
XHIGH_MODEL_REFS.map((entry) => entry.split("/")[1]?.toLowerCase()).filter(
|
||||
(entry): entry is string => Boolean(entry),
|
||||
),
|
||||
);
|
||||
|
||||
// Normalize user-provided thinking level strings to the canonical enum.
|
||||
export function normalizeThinkLevel(raw?: string | null): ThinkLevel | undefined {
|
||||
if (!raw) {
|
||||
@@ -130,10 +109,7 @@ export function supportsXHighThinking(provider?: string | null, model?: string |
|
||||
return pluginDecision;
|
||||
}
|
||||
}
|
||||
if (providerKey) {
|
||||
return XHIGH_MODEL_SET.has(`${providerKey}/${modelKey}`);
|
||||
}
|
||||
return XHIGH_MODEL_IDS.has(modelKey);
|
||||
return false;
|
||||
}
|
||||
|
||||
export function listThinkingLevels(provider?: string | null, model?: string | null): ThinkLevel[] {
|
||||
@@ -161,17 +137,7 @@ export function formatThinkingLevels(
|
||||
}
|
||||
|
||||
export function formatXHighModelHint(): string {
|
||||
const refs = [...XHIGH_MODEL_REFS] as string[];
|
||||
if (refs.length === 0) {
|
||||
return "unknown model";
|
||||
}
|
||||
if (refs.length === 1) {
|
||||
return refs[0];
|
||||
}
|
||||
if (refs.length === 2) {
|
||||
return `${refs[0]} or ${refs[1]}`;
|
||||
}
|
||||
return `${refs.slice(0, -1).join(", ")} or ${refs[refs.length - 1]}`;
|
||||
return "provider models that advertise xhigh reasoning";
|
||||
}
|
||||
|
||||
export function resolveThinkingDefaultForModel(params: {
|
||||
@@ -196,12 +162,7 @@ export function resolveThinkingDefaultForModel(params: {
|
||||
return pluginDecision;
|
||||
}
|
||||
|
||||
const isAnthropicFamilyModel =
|
||||
normalizedProvider === "anthropic" ||
|
||||
normalizedProvider === "amazon-bedrock" ||
|
||||
modelLower.includes("anthropic/") ||
|
||||
modelLower.includes(".anthropic.");
|
||||
if (isAnthropicFamilyModel && CLAUDE_46_MODEL_RE.test(modelLower)) {
|
||||
if (normalizedProvider === "amazon-bedrock" && CLAUDE_46_MODEL_RE.test(modelLower)) {
|
||||
return "adaptive";
|
||||
}
|
||||
if (candidate?.reasoning) {
|
||||
|
||||
Reference in New Issue
Block a user