mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-23 16:01:17 +00:00
60 lines
1.9 KiB
TypeScript
60 lines
1.9 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" }),
|
|
buildZaiModelDefinition({ id: "glm-5-turbo" }),
|
|
buildZaiModelDefinition({ id: "glm-4.7" }),
|
|
buildZaiModelDefinition({ id: "glm-4.7-flash" }),
|
|
buildZaiModelDefinition({ id: "glm-4.7-flashx" }),
|
|
];
|
|
|
|
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);
|
|
}
|