Skip to content

Commit 132bceb

Browse files
committed
fix: keep gemini config normalization acyclic
1 parent b81033d commit 132bceb

3 files changed

Lines changed: 33 additions & 9 deletions

File tree

src/agents/live-target-matcher.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { OpenClawConfig } from "../config/types.openclaw.js";
2+
import { normalizeGooglePreviewModelId } from "../plugin-sdk/provider-model-id-normalize.js";
23
import {
34
normalizeLowercaseStringOrEmpty,
45
normalizeOptionalLowercaseString,
56
} from "../shared/string-coerce.js";
67
import { liveProvidersShareOwningPlugin } from "./live-provider-owner.js";
7-
import { normalizeStaticProviderModelId } from "./model-ref-shared.js";
88
import { normalizeProviderId } from "./provider-id.js";
99

1010
type ModelTarget = {
@@ -13,6 +13,15 @@ type ModelTarget = {
1313
modelId: string;
1414
};
1515

16+
const GOOGLE_LIVE_TARGET_PROVIDERS = new Set(["google", "google-gemini-cli", "google-vertex"]);
17+
18+
function normalizeLiveTargetModelId(provider: string, modelId: string): string {
19+
const trimmed = modelId.trim();
20+
return GOOGLE_LIVE_TARGET_PROVIDERS.has(provider)
21+
? normalizeGooglePreviewModelId(trimmed)
22+
: trimmed;
23+
}
24+
1625
function normalizeCsvSet(values: Set<string> | null): Set<string> | null {
1726
if (!values) {
1827
return null;
@@ -42,7 +51,7 @@ function parseModelTarget(raw: string): ModelTarget | null {
4251
}
4352
const provider = normalizeProviderId(trimmed.slice(0, slash));
4453
const modelId = normalizeLowercaseStringOrEmpty(
45-
normalizeStaticProviderModelId(provider, trimmed.slice(slash + 1)),
54+
normalizeLiveTargetModelId(provider, trimmed.slice(slash + 1)),
4655
);
4756
if (!provider || !modelId) {
4857
return null;

src/config/model-input.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { modelKey, normalizeStaticProviderModelId } from "../agents/model-ref-shared.js";
21
import { normalizeProviderId } from "../agents/provider-id.js";
2+
import { normalizeGooglePreviewModelId } from "../plugin-sdk/provider-model-id-normalize.js";
33
import { normalizeOptionalString, resolvePrimaryStringValue } from "../shared/string-coerce.js";
44
import type { AgentModelConfig } from "./types.agents-shared.js";
55

@@ -11,6 +11,20 @@ type AgentModelListLike = {
1111

1212
const GOOGLE_CONFIG_MODEL_PROVIDERS = new Set(["google", "google-gemini-cli", "google-vertex"]);
1313

14+
function modelKeyForConfig(provider: string, model: string): string {
15+
const providerId = provider.trim();
16+
const modelId = model.trim();
17+
if (!providerId) {
18+
return modelId;
19+
}
20+
if (!modelId) {
21+
return providerId;
22+
}
23+
return modelId.toLowerCase().startsWith(`${providerId.toLowerCase()}/`)
24+
? modelId
25+
: `${providerId}/${modelId}`;
26+
}
27+
1428
export function resolveAgentModelPrimaryValue(model?: AgentModelConfig): string | undefined {
1529
return resolvePrimaryStringValue(model);
1630
}
@@ -56,6 +70,6 @@ export function normalizeAgentModelRefForConfig(model: string): string {
5670
return trimmed;
5771
}
5872

59-
const normalizedModel = normalizeStaticProviderModelId(provider, trimmed.slice(slash + 1));
60-
return modelKey(provider, normalizedModel);
73+
const normalizedModel = normalizeGooglePreviewModelId(trimmed.slice(slash + 1));
74+
return modelKeyForConfig(provider, normalizedModel);
6175
}

src/gateway/gateway-models.profiles.live.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import {
3838
import { createLiveTargetMatcher } from "../agents/live-target-matcher.js";
3939
import { isLiveProfileKeyModeEnabled, isLiveTestEnabled } from "../agents/live-test-helpers.js";
4040
import { getApiKeyForModel, resolveEnvApiKey } from "../agents/model-auth.js";
41-
import { normalizeStaticProviderModelId } from "../agents/model-ref-shared.js";
4241
import { normalizeProviderId } from "../agents/model-selection.js";
4342
import { shouldSuppressBuiltInModel } from "../agents/model-suppression.js";
4443
import { ensureOpenClawModelsJson } from "../agents/models-config.js";
@@ -1658,9 +1657,11 @@ function parseExplicitLiveModelRef(
16581657
const slash = trimmed.indexOf("/");
16591658
if (slash !== -1) {
16601659
const provider = normalizeProviderId(trimmed.slice(0, slash));
1661-
const modelId = provider
1662-
? normalizeStaticProviderModelId(provider, trimmed.slice(slash + 1)).trim()
1663-
: "";
1660+
const rawModelId = trimmed.slice(slash + 1).trim();
1661+
const modelId =
1662+
provider === "google" || provider === "google-gemini-cli" || provider === "google-vertex"
1663+
? normalizeGoogleModelId(rawModelId)
1664+
: rawModelId;
16641665
return provider && modelId ? { provider, modelId } : null;
16651666
}
16661667
if (!providerFilter || providerFilter.size !== 1) {

0 commit comments

Comments
 (0)