Files
openclaw/extensions/zai/onboard.ts
Tomsun28 6433e923d4 fix: add ZAI GLM-5.1 and GLM-5V Turbo support (#58793) (thanks @tomsun28)
* provider(zai): add GLM-5.1 and GLM-5V Turbo models

* feat(zai): extract model definition builder for glm-5 forward compat

* test(zai): cover persisted glm-5 dynamic metadata

* fix: add ZAI GLM-5.1 and GLM-5V Turbo support (#58793) (thanks @tomsun28)

* fix: preserve ZAI dynamic model transport config (#58793) (thanks @tomsun28)

---------

Co-authored-by: gongchao <chao.gong@aminer.cn>
Co-authored-by: Ayaan Zaidi <hi@obviy.us>
2026-04-01 18:09:02 +05:30

68 lines
2.3 KiB
TypeScript

import {
applyProviderConfigWithModelCatalogPreset,
type OpenClawConfig,
} from "openclaw/plugin-sdk/provider-onboard";
import {
buildZaiModelDefinition,
resolveZaiBaseUrl,
ZAI_DEFAULT_MODEL_ID,
} from "./model-definitions.js";
export const ZAI_DEFAULT_MODEL_REF = `zai/${ZAI_DEFAULT_MODEL_ID}`;
const ZAI_DEFAULT_MODELS = [
buildZaiModelDefinition({ id: "glm-5.1" }),
buildZaiModelDefinition({ id: "glm-5" }),
buildZaiModelDefinition({ id: "glm-5-turbo" }),
buildZaiModelDefinition({ id: "glm-5v-turbo" }),
buildZaiModelDefinition({ id: "glm-4.7" }),
buildZaiModelDefinition({ id: "glm-4.7-flash" }),
buildZaiModelDefinition({ id: "glm-4.7-flashx" }),
buildZaiModelDefinition({ id: "glm-4.6" }),
buildZaiModelDefinition({ id: "glm-4.6v" }),
buildZaiModelDefinition({ id: "glm-4.5" }),
buildZaiModelDefinition({ id: "glm-4.5-air" }),
buildZaiModelDefinition({ id: "glm-4.5-flash" }),
buildZaiModelDefinition({ id: "glm-4.5v" }),
];
function resolveZaiPresetBaseUrl(cfg: OpenClawConfig, endpoint?: string): string {
const existingProvider = cfg.models?.providers?.zai;
const existingBaseUrl =
typeof existingProvider?.baseUrl === "string" ? existingProvider.baseUrl.trim() : "";
return endpoint ? resolveZaiBaseUrl(endpoint) : existingBaseUrl || resolveZaiBaseUrl();
}
function applyZaiPreset(
cfg: OpenClawConfig,
params?: { endpoint?: string; modelId?: string },
primaryModelRef?: string,
): OpenClawConfig {
const modelId = params?.modelId?.trim() || ZAI_DEFAULT_MODEL_ID;
const modelRef = `zai/${modelId}`;
return applyProviderConfigWithModelCatalogPreset(cfg, {
providerId: "zai",
api: "openai-completions",
baseUrl: resolveZaiPresetBaseUrl(cfg, params?.endpoint),
catalogModels: ZAI_DEFAULT_MODELS,
aliases: [{ modelRef, alias: "GLM" }],
primaryModelRef,
});
}
export function applyZaiProviderConfig(
cfg: OpenClawConfig,
params?: { endpoint?: string; modelId?: string },
): OpenClawConfig {
return applyZaiPreset(cfg, params);
}
export function applyZaiConfig(
cfg: OpenClawConfig,
params?: { endpoint?: string; modelId?: string },
): OpenClawConfig {
const modelId = params?.modelId?.trim() || ZAI_DEFAULT_MODEL_ID;
const modelRef = modelId === ZAI_DEFAULT_MODEL_ID ? ZAI_DEFAULT_MODEL_REF : `zai/${modelId}`;
return applyZaiPreset(cfg, params, modelRef);
}