refactor: unify configure auth choice
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -177,7 +177,7 @@ describe("applyMinimaxApiConfig", () => {
|
||||
).toMatchObject({ alias: "Minimax", params: { custom: "value" } });
|
||||
});
|
||||
|
||||
it("replaces existing minimax provider entirely", () => {
|
||||
it("merges existing minimax provider models", () => {
|
||||
const cfg = applyMinimaxApiConfig({
|
||||
models: {
|
||||
providers: {
|
||||
@@ -204,7 +204,11 @@ describe("applyMinimaxApiConfig", () => {
|
||||
"https://api.minimax.io/anthropic",
|
||||
);
|
||||
expect(cfg.models?.providers?.minimax?.api).toBe("anthropic-messages");
|
||||
expect(cfg.models?.providers?.minimax?.models[0]?.id).toBe("MiniMax-M2.1");
|
||||
expect(cfg.models?.providers?.minimax?.apiKey).toBe("old-key");
|
||||
expect(cfg.models?.providers?.minimax?.models.map((m) => m.id)).toEqual([
|
||||
"old-model",
|
||||
"MiniMax-M2.1",
|
||||
]);
|
||||
});
|
||||
|
||||
it("preserves other providers when adding minimax", () => {
|
||||
|
||||
@@ -334,11 +334,27 @@ export function applyMinimaxApiProviderConfig(
|
||||
modelId: string = "MiniMax-M2.1",
|
||||
): ClawdbotConfig {
|
||||
const providers = { ...cfg.models?.providers };
|
||||
const existingProvider = providers.minimax;
|
||||
const existingModels = Array.isArray(existingProvider?.models)
|
||||
? existingProvider.models
|
||||
: [];
|
||||
const apiModel = buildMinimaxApiModelDefinition(modelId);
|
||||
const hasApiModel = existingModels.some((model) => model.id === modelId);
|
||||
const mergedModels = hasApiModel
|
||||
? existingModels
|
||||
: [...existingModels, apiModel];
|
||||
const { apiKey: existingApiKey, ...existingProviderRest } =
|
||||
(existingProvider ?? {}) as Record<string, unknown> as { apiKey?: string };
|
||||
const resolvedApiKey =
|
||||
typeof existingApiKey === "string" ? existingApiKey : undefined;
|
||||
const normalizedApiKey =
|
||||
resolvedApiKey?.trim() === "minimax" ? "" : resolvedApiKey;
|
||||
providers.minimax = {
|
||||
...existingProviderRest,
|
||||
baseUrl: MINIMAX_API_BASE_URL,
|
||||
// apiKey omitted: resolved via MINIMAX_API_KEY env var or auth profile by default.
|
||||
api: "anthropic-messages",
|
||||
models: [buildMinimaxApiModelDefinition(modelId)],
|
||||
...(normalizedApiKey?.trim() ? { apiKey: normalizedApiKey } : {}),
|
||||
models: mergedModels.length > 0 ? mergedModels : [apiModel],
|
||||
};
|
||||
|
||||
const models = { ...cfg.agents?.defaults?.models };
|
||||
|
||||
Reference in New Issue
Block a user