























@@ -1,5 +1,6 @@
11import {
22legacyRuntimeModelAliasRequiresRuntimePolicy,
3+listLegacyRuntimeModelProviderAliases,
34migrateLegacyRuntimeModelRef,
45} from "../../../agents/model-runtime-aliases.js";
56import { normalizeProviderId } from "../../../agents/provider-id.js";
@@ -205,6 +206,32 @@ type SelectedRuntimeRef = {
205206const LEGACY_CODEX_CLI_RUNTIME_ID = "codex-cli";
206207const CODEX_APP_SERVER_RUNTIME_ID = "codex";
207208209+function resolveLegacyWholeAgentRuntimePolicy(raw: unknown):
210+| {
211+provider: string;
212+runtime: string;
213+requiresRuntimePolicy: boolean;
214+}
215+| undefined {
216+if (!isRecord(raw)) {
217+return undefined;
218+}
219+const runtime = normalizeOptionalLowercaseString(raw.id);
220+if (!runtime || runtime === "auto" || runtime === "pi") {
221+return undefined;
222+}
223+const alias = listLegacyRuntimeModelProviderAliases().find(
224+(entry) => entry.cli && normalizeProviderId(entry.runtime) === runtime,
225+);
226+return alias
227+ ? {
228+provider: alias.provider,
229+runtime: alias.runtime,
230+requiresRuntimePolicy: alias.requiresRuntimePolicy,
231+}
232+ : undefined;
233+}
234+208235function migratedRuntimeRequiresPolicy(legacyProvider: string): boolean {
209236return legacyRuntimeModelAliasRequiresRuntimePolicy(legacyProvider);
210237}
@@ -417,6 +444,44 @@ function ensureSelectedModelRuntimePolicies(
417444return { value: next, changed };
418445}
419446447+function selectedCanonicalModelRefsForRuntimePolicy(
448+rawModel: unknown,
449+provider: string,
450+runtime: string,
451+requiresRuntimePolicy: boolean,
452+): SelectedRuntimeRef[] {
453+const refs: SelectedRuntimeRef[] = [];
454+const addRef = (rawRef: unknown) => {
455+if (typeof rawRef !== "string") {
456+return;
457+}
458+const trimmed = rawRef.trim();
459+const slash = trimmed.indexOf("/");
460+if (slash <= 0 || slash >= trimmed.length - 1) {
461+return;
462+}
463+if (normalizeProviderId(trimmed.slice(0, slash)) !== normalizeProviderId(provider)) {
464+return;
465+}
466+refs.push({ ref: trimmed, runtime, requiresRuntimePolicy });
467+};
468+469+if (typeof rawModel === "string") {
470+addRef(rawModel);
471+return refs;
472+}
473+if (!isRecord(rawModel)) {
474+return refs;
475+}
476+addRef(rawModel.primary);
477+if (Array.isArray(rawModel.fallbacks)) {
478+for (const fallback of rawModel.fallbacks) {
479+addRef(fallback);
480+}
481+}
482+return refs;
483+}
484+420485function normalizeLegacyCodexCliRuntimePinsInModels(
421486rawModels: unknown,
422487path: string,
@@ -451,6 +516,7 @@ function normalizeLegacyRuntimeAgentContainer(
451516): { value: Record<string, unknown>; changed: boolean } {
452517let changed = false;
453518const next: Record<string, unknown> = { ...raw };
519+const legacyWholeAgentRuntime = resolveLegacyWholeAgentRuntimePolicy(raw.agentRuntime);
454520455521const model = normalizeLegacyRuntimeAgentModelConfig(raw.model);
456522if (model.changed) {
@@ -484,6 +550,23 @@ function normalizeLegacyRuntimeAgentContainer(
484550}
485551}
486552553+if (legacyWholeAgentRuntime) {
554+const selectedRefs = selectedCanonicalModelRefsForRuntimePolicy(
555+next.model ?? raw.model,
556+legacyWholeAgentRuntime.provider,
557+legacyWholeAgentRuntime.runtime,
558+legacyWholeAgentRuntime.requiresRuntimePolicy,
559+);
560+const modelRuntimes = ensureSelectedModelRuntimePolicies(next.models, selectedRefs);
561+if (modelRuntimes.changed) {
562+next.models = modelRuntimes.value;
563+changed = true;
564+changes.push(
565+`Moved ${path}.agentRuntime.id ${legacyWholeAgentRuntime.runtime} to matching ${legacyWholeAgentRuntime.provider} model runtime policy.`,
566+);
567+}
568+}
569+487570const codexCliRuntimePins = normalizeLegacyCodexCliRuntimePinsInModels(
488571next.models,
489572`${path}.models`,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。