mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:20:44 +00:00
added a fix for memory leak on 2gb ram (#46522)
This commit is contained in:
23
src/agents/model-id-normalization.ts
Normal file
23
src/agents/model-id-normalization.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// Keep model ID normalization dependency-free so config parsing and other
|
||||||
|
// startup-only paths do not pull in provider discovery or plugin loading.
|
||||||
|
export function normalizeGoogleModelId(id: string): string {
|
||||||
|
if (id === "gemini-3-pro") {
|
||||||
|
return "gemini-3-pro-preview";
|
||||||
|
}
|
||||||
|
if (id === "gemini-3-flash") {
|
||||||
|
return "gemini-3-flash-preview";
|
||||||
|
}
|
||||||
|
if (id === "gemini-3.1-pro") {
|
||||||
|
return "gemini-3.1-pro-preview";
|
||||||
|
}
|
||||||
|
if (id === "gemini-3.1-flash-lite") {
|
||||||
|
return "gemini-3.1-flash-lite-preview";
|
||||||
|
}
|
||||||
|
// Preserve compatibility with earlier OpenClaw docs/config that pointed at a
|
||||||
|
// non-existent Gemini Flash preview ID. Google's current Flash text model is
|
||||||
|
// `gemini-3-flash-preview`.
|
||||||
|
if (id === "gemini-3.1-flash" || id === "gemini-3.1-flash-preview") {
|
||||||
|
return "gemini-3-flash-preview";
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
@@ -13,9 +13,9 @@ import {
|
|||||||
resolveAgentModelFallbacksOverride,
|
resolveAgentModelFallbacksOverride,
|
||||||
} from "./agent-scope.js";
|
} from "./agent-scope.js";
|
||||||
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "./defaults.js";
|
import { DEFAULT_MODEL, DEFAULT_PROVIDER } from "./defaults.js";
|
||||||
|
import { normalizeGoogleModelId } from "./model-id-normalization.js";
|
||||||
import type { ModelCatalogEntry } from "./model-catalog.js";
|
import type { ModelCatalogEntry } from "./model-catalog.js";
|
||||||
import { splitTrailingAuthProfile } from "./model-ref-profile.js";
|
import { splitTrailingAuthProfile } from "./model-ref-profile.js";
|
||||||
import { normalizeGoogleModelId } from "./models-config.providers.js";
|
|
||||||
|
|
||||||
const log = createSubsystemLogger("model-selection");
|
const log = createSubsystemLogger("model-selection");
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import { mkdtempSync } from "node:fs";
|
|||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { normalizeGoogleModelId } from "./model-id-normalization.js";
|
||||||
import {
|
import {
|
||||||
normalizeAntigravityModelId,
|
normalizeAntigravityModelId,
|
||||||
normalizeGoogleModelId,
|
|
||||||
normalizeProviders,
|
normalizeProviders,
|
||||||
type ProviderConfig,
|
type ProviderConfig,
|
||||||
} from "./models-config.providers.js";
|
} from "./models-config.providers.js";
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { isRecord } from "../utils.js";
|
|||||||
import { normalizeOptionalSecretInput } from "../utils/normalize-secret-input.js";
|
import { normalizeOptionalSecretInput } from "../utils/normalize-secret-input.js";
|
||||||
import { ensureAuthProfileStore, listProfilesForProvider } from "./auth-profiles.js";
|
import { ensureAuthProfileStore, listProfilesForProvider } from "./auth-profiles.js";
|
||||||
import { discoverBedrockModels } from "./bedrock-discovery.js";
|
import { discoverBedrockModels } from "./bedrock-discovery.js";
|
||||||
|
import { normalizeGoogleModelId } from "./model-id-normalization.js";
|
||||||
import {
|
import {
|
||||||
buildCloudflareAiGatewayModelDefinition,
|
buildCloudflareAiGatewayModelDefinition,
|
||||||
resolveCloudflareAiGatewayBaseUrl,
|
resolveCloudflareAiGatewayBaseUrl,
|
||||||
@@ -70,6 +71,7 @@ import {
|
|||||||
} from "./model-auth-markers.js";
|
} from "./model-auth-markers.js";
|
||||||
import { resolveAwsSdkEnvVarName, resolveEnvApiKey } from "./model-auth.js";
|
import { resolveAwsSdkEnvVarName, resolveEnvApiKey } from "./model-auth.js";
|
||||||
export { resolveOllamaApiBase } from "./models-config.providers.discovery.js";
|
export { resolveOllamaApiBase } from "./models-config.providers.discovery.js";
|
||||||
|
export { normalizeGoogleModelId };
|
||||||
|
|
||||||
type ModelsConfig = NonNullable<OpenClawConfig["models"]>;
|
type ModelsConfig = NonNullable<OpenClawConfig["models"]>;
|
||||||
export type ProviderConfig = NonNullable<ModelsConfig["providers"]>[string];
|
export type ProviderConfig = NonNullable<ModelsConfig["providers"]>[string];
|
||||||
@@ -223,28 +225,6 @@ function resolveApiKeyFromProfiles(params: {
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeGoogleModelId(id: string): string {
|
|
||||||
if (id === "gemini-3-pro") {
|
|
||||||
return "gemini-3-pro-preview";
|
|
||||||
}
|
|
||||||
if (id === "gemini-3-flash") {
|
|
||||||
return "gemini-3-flash-preview";
|
|
||||||
}
|
|
||||||
if (id === "gemini-3.1-pro") {
|
|
||||||
return "gemini-3.1-pro-preview";
|
|
||||||
}
|
|
||||||
if (id === "gemini-3.1-flash-lite") {
|
|
||||||
return "gemini-3.1-flash-lite-preview";
|
|
||||||
}
|
|
||||||
// Preserve compatibility with earlier OpenClaw docs/config that pointed at a
|
|
||||||
// non-existent Gemini Flash preview ID. Google's current Flash text model is
|
|
||||||
// `gemini-3-flash-preview`.
|
|
||||||
if (id === "gemini-3.1-flash" || id === "gemini-3.1-flash-preview") {
|
|
||||||
return "gemini-3-flash-preview";
|
|
||||||
}
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
const ANTIGRAVITY_BARE_PRO_IDS = new Set(["gemini-3-pro", "gemini-3.1-pro", "gemini-3-1-pro"]);
|
const ANTIGRAVITY_BARE_PRO_IDS = new Set(["gemini-3-pro", "gemini-3.1-pro", "gemini-3-1-pro"]);
|
||||||
|
|
||||||
export function normalizeAntigravityModelId(id: string): string {
|
export function normalizeAntigravityModelId(id: string): string {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { normalizeGoogleModelId } from "../../../agents/models-config.providers.js";
|
import { normalizeGoogleModelId } from "../../../agents/model-id-normalization.js";
|
||||||
import { parseGeminiAuth } from "../../../infra/gemini-auth.js";
|
import { parseGeminiAuth } from "../../../infra/gemini-auth.js";
|
||||||
import { assertOkOrThrowHttpError, normalizeBaseUrl, postJsonRequest } from "../shared.js";
|
import { assertOkOrThrowHttpError, normalizeBaseUrl, postJsonRequest } from "../shared.js";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user