





















@@ -4,6 +4,7 @@ import {
44type ProviderAuthResult,
55} from "openclaw/plugin-sdk/provider-auth";
66import { normalizeLowercaseStringOrEmpty } from "openclaw/plugin-sdk/string-coerce-runtime";
7+import { resolveClaudeCliAnthropicModelRefs } from "./claude-model-refs.js";
78import {
89readClaudeCliCredentialsForSetup,
910readClaudeCliCredentialsForSetupNonInteractive,
@@ -18,21 +19,16 @@ type AgentDefaultsRuntimePolicy = NonNullable<
1819type ClaudeCliCredential = NonNullable<ReturnType<typeof readClaudeCliCredentialsForSetup>>;
19202021function toAnthropicModelRef(raw: string): string | null {
21-const trimmed = raw.trim();
22-const lower = normalizeLowercaseStringOrEmpty(trimmed);
23-const provider = lower.startsWith("anthropic/")
24- ? "anthropic"
25- : lower.startsWith(`${CLAUDE_CLI_BACKEND_ID}/`)
26- ? CLAUDE_CLI_BACKEND_ID
27- : "";
28-if (!provider) {
29-return null;
30-}
31-const modelId = trimmed.slice(provider.length + 1).trim();
32-if (!normalizeLowercaseStringOrEmpty(modelId).startsWith("claude-")) {
33-return null;
34-}
35-return `anthropic/${modelId}`;
22+return resolveClaudeCliAnthropicModelRefs(raw)?.rewriteRef ?? null;
23+}
24+25+function toAnthropicRuntimeRefs(raw: string): string[] {
26+return resolveClaudeCliAnthropicModelRefs(raw)?.runtimeRefs ?? [];
27+}
28+29+function toAnthropicSelectedModelRef(raw: string): string | undefined {
30+const resolved = resolveClaudeCliAnthropicModelRefs(raw);
31+return resolved?.rewriteRef ?? resolved?.selectedRef;
3632}
37333834function isRecord(value: unknown): value is Record<string, unknown> {
@@ -46,10 +42,17 @@ function rewriteModelSelection(model: AgentDefaultsModel): {
4642changed: boolean;
4743} {
4844if (typeof model === "string") {
45+const runtimeRefs = toAnthropicRuntimeRefs(model);
4946const converted = toAnthropicModelRef(model);
47+const selectedRef = converted ?? toAnthropicSelectedModelRef(model);
5048return converted
51- ? { value: converted, primary: converted, runtimeRefs: [converted], changed: true }
52- : { value: model, runtimeRefs: [], changed: false };
49+ ? { value: converted, primary: converted, runtimeRefs, changed: true }
50+ : {
51+value: model,
52+ ...(selectedRef ? { primary: selectedRef } : {}),
53+ runtimeRefs,
54+changed: false,
55+};
5356}
5457if (!model || typeof model !== "object" || Array.isArray(model)) {
5558return { value: model, runtimeRefs: [], changed: false };
@@ -62,12 +65,14 @@ function rewriteModelSelection(model: AgentDefaultsModel): {
6265let primary: string | undefined;
63666467if (typeof current.primary === "string") {
68+runtimeRefs.push(...toAnthropicRuntimeRefs(current.primary));
6569const converted = toAnthropicModelRef(current.primary);
6670if (converted) {
6771next.primary = converted;
6872primary = converted;
69-runtimeRefs.push(converted);
7073changed = true;
74+} else {
75+primary = toAnthropicSelectedModelRef(current.primary);
7176}
7277}
7378@@ -77,10 +82,8 @@ function rewriteModelSelection(model: AgentDefaultsModel): {
7782if (typeof entry !== "string") {
7883return entry;
7984}
85+runtimeRefs.push(...toAnthropicRuntimeRefs(entry));
8086const converted = toAnthropicModelRef(entry);
81-if (converted) {
82-runtimeRefs.push(converted);
83-}
8487return converted ?? entry;
8588});
8689if (nextFallbacks.some((entry, index) => entry !== currentFallbacks[index])) {
@@ -100,15 +103,18 @@ function rewriteModelSelection(model: AgentDefaultsModel): {
100103function rewriteModelEntryMap(models: Record<string, unknown> | undefined): {
101104value: Record<string, unknown> | undefined;
102105migrated: string[];
106+runtimeRefs: string[];
103107} {
104108if (!models) {
105-return { value: models, migrated: [] };
109+return { value: models, migrated: [], runtimeRefs: [] };
106110}
107111108112const next = { ...models };
109113const migrated: string[] = [];
114+const runtimeRefs: string[] = [];
110115111116for (const [rawKey, value] of Object.entries(models)) {
117+runtimeRefs.push(...toAnthropicRuntimeRefs(rawKey));
112118const converted = toAnthropicModelRef(rawKey);
113119if (!converted) {
114120continue;
@@ -119,13 +125,16 @@ function rewriteModelEntryMap(models: Record<string, unknown> | undefined): {
119125if (!(converted in next)) {
120126next[converted] = value;
121127}
122-delete next[rawKey];
128+if (normalizeLowercaseStringOrEmpty(rawKey).startsWith(`${CLAUDE_CLI_BACKEND_ID}/`)) {
129+delete next[rawKey];
130+}
123131migrated.push(converted);
124132}
125133126134return {
127-value: migrated.length > 0 ? next : models,
135+value: migrated.length > 0 || runtimeRefs.length > 0 ? next : models,
128136 migrated,
137+ runtimeRefs,
129138};
130139}
131140@@ -227,6 +236,7 @@ export function buildAnthropicCliMigrationResult(
227236{}) as NonNullable<AgentDefaultsModels>;
228237const nextModels = seedClaudeCliAllowlist(existingModels, [
229238 ...rewrittenModel.runtimeRefs,
239+ ...rewrittenModels.runtimeRefs,
230240 ...rewrittenModels.migrated,
231241]);
232242const defaultModel = rewrittenModel.primary ?? "anthropic/claude-opus-4-7";
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。