mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-24 16:32:29 +00:00
105 lines
3.1 KiB
TypeScript
105 lines
3.1 KiB
TypeScript
import {
|
|
buildMinimaxApiModelDefinition,
|
|
MINIMAX_API_BASE_URL,
|
|
MINIMAX_CN_API_BASE_URL,
|
|
} from "openclaw/plugin-sdk/provider-models";
|
|
import {
|
|
applyAgentDefaultModelPrimary,
|
|
applyOnboardAuthAgentModelsAndProviders,
|
|
type ModelProviderConfig,
|
|
type OpenClawConfig,
|
|
} from "openclaw/plugin-sdk/provider-onboard";
|
|
|
|
type MinimaxApiProviderConfigParams = {
|
|
providerId: string;
|
|
modelId: string;
|
|
baseUrl: string;
|
|
};
|
|
|
|
function applyMinimaxApiProviderConfigWithBaseUrl(
|
|
cfg: OpenClawConfig,
|
|
params: MinimaxApiProviderConfigParams,
|
|
): OpenClawConfig {
|
|
const providers = { ...cfg.models?.providers } as Record<string, ModelProviderConfig>;
|
|
const existingProvider = providers[params.providerId];
|
|
const existingModels = existingProvider?.models ?? [];
|
|
const apiModel = buildMinimaxApiModelDefinition(params.modelId);
|
|
const hasApiModel = existingModels.some((model) => model.id === params.modelId);
|
|
const mergedModels = hasApiModel ? existingModels : [...existingModels, apiModel];
|
|
const { apiKey: existingApiKey, ...existingProviderRest } = existingProvider ?? {
|
|
baseUrl: params.baseUrl,
|
|
models: [],
|
|
};
|
|
const resolvedApiKey = typeof existingApiKey === "string" ? existingApiKey : undefined;
|
|
const normalizedApiKey = resolvedApiKey?.trim() === "minimax" ? "" : resolvedApiKey;
|
|
providers[params.providerId] = {
|
|
...existingProviderRest,
|
|
baseUrl: params.baseUrl,
|
|
api: "anthropic-messages",
|
|
authHeader: true,
|
|
...(normalizedApiKey?.trim() ? { apiKey: normalizedApiKey } : {}),
|
|
models: mergedModels.length > 0 ? mergedModels : [apiModel],
|
|
};
|
|
|
|
const models = { ...cfg.agents?.defaults?.models };
|
|
const modelRef = `${params.providerId}/${params.modelId}`;
|
|
models[modelRef] = {
|
|
...models[modelRef],
|
|
alias: "Minimax",
|
|
};
|
|
|
|
return applyOnboardAuthAgentModelsAndProviders(cfg, { agentModels: models, providers });
|
|
}
|
|
|
|
function applyMinimaxApiConfigWithBaseUrl(
|
|
cfg: OpenClawConfig,
|
|
params: MinimaxApiProviderConfigParams,
|
|
): OpenClawConfig {
|
|
const next = applyMinimaxApiProviderConfigWithBaseUrl(cfg, params);
|
|
return applyAgentDefaultModelPrimary(next, `${params.providerId}/${params.modelId}`);
|
|
}
|
|
|
|
export function applyMinimaxApiProviderConfig(
|
|
cfg: OpenClawConfig,
|
|
modelId: string = "MiniMax-M2.5",
|
|
): OpenClawConfig {
|
|
return applyMinimaxApiProviderConfigWithBaseUrl(cfg, {
|
|
providerId: "minimax",
|
|
modelId,
|
|
baseUrl: MINIMAX_API_BASE_URL,
|
|
});
|
|
}
|
|
|
|
export function applyMinimaxApiConfig(
|
|
cfg: OpenClawConfig,
|
|
modelId: string = "MiniMax-M2.5",
|
|
): OpenClawConfig {
|
|
return applyMinimaxApiConfigWithBaseUrl(cfg, {
|
|
providerId: "minimax",
|
|
modelId,
|
|
baseUrl: MINIMAX_API_BASE_URL,
|
|
});
|
|
}
|
|
|
|
export function applyMinimaxApiProviderConfigCn(
|
|
cfg: OpenClawConfig,
|
|
modelId: string = "MiniMax-M2.5",
|
|
): OpenClawConfig {
|
|
return applyMinimaxApiProviderConfigWithBaseUrl(cfg, {
|
|
providerId: "minimax",
|
|
modelId,
|
|
baseUrl: MINIMAX_CN_API_BASE_URL,
|
|
});
|
|
}
|
|
|
|
export function applyMinimaxApiConfigCn(
|
|
cfg: OpenClawConfig,
|
|
modelId: string = "MiniMax-M2.5",
|
|
): OpenClawConfig {
|
|
return applyMinimaxApiConfigWithBaseUrl(cfg, {
|
|
providerId: "minimax",
|
|
modelId,
|
|
baseUrl: MINIMAX_CN_API_BASE_URL,
|
|
});
|
|
}
|