Merge branch 'main' into tobias-sync
This commit is contained in:
@@ -2,6 +2,13 @@ import type { OAuthCredentials, OAuthProvider } from "@mariozechner/pi-ai";
|
||||
import { resolveDefaultAgentDir } from "../agents/agent-scope.js";
|
||||
import { upsertAuthProfile } from "../agents/auth-profiles.js";
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
import type { ModelDefinitionConfig } from "../config/types.js";
|
||||
|
||||
const DEFAULT_MINIMAX_BASE_URL = "https://api.minimax.io/v1";
|
||||
export const MINIMAX_HOSTED_MODEL_ID = "MiniMax-M2.1";
|
||||
const DEFAULT_MINIMAX_CONTEXT_WINDOW = 200000;
|
||||
const DEFAULT_MINIMAX_MAX_TOKENS = 8192;
|
||||
export const MINIMAX_HOSTED_MODEL_REF = `minimax/${MINIMAX_HOSTED_MODEL_ID}`;
|
||||
|
||||
const DEFAULT_MINIMAX_BASE_URL = "https://api.minimax.io/v1";
|
||||
export const MINIMAX_HOSTED_MODEL_ID = "MiniMax-M2.1";
|
||||
@@ -39,6 +46,19 @@ export async function setAnthropicApiKey(key: string, agentDir?: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function setGeminiApiKey(key: string, agentDir?: string) {
|
||||
// Write to the multi-agent path so gateway finds credentials on startup
|
||||
upsertAuthProfile({
|
||||
profileId: "google:default",
|
||||
credential: {
|
||||
type: "api_key",
|
||||
provider: "google",
|
||||
key,
|
||||
},
|
||||
agentDir: agentDir ?? resolveDefaultAgentDir(),
|
||||
});
|
||||
}
|
||||
|
||||
export async function setMinimaxApiKey(key: string, agentDir?: string) {
|
||||
// Write to the multi-agent path so gateway finds credentials on startup
|
||||
upsertAuthProfile({
|
||||
@@ -57,8 +77,9 @@ export function applyAuthProfileConfig(
|
||||
params: {
|
||||
profileId: string;
|
||||
provider: string;
|
||||
mode: "api_key" | "oauth";
|
||||
mode: "api_key" | "oauth" | "token";
|
||||
email?: string;
|
||||
preferProfileFirst?: boolean;
|
||||
},
|
||||
): ClawdbotConfig {
|
||||
const profiles = {
|
||||
@@ -73,13 +94,23 @@ export function applyAuthProfileConfig(
|
||||
// Only maintain `auth.order` when the user explicitly configured it.
|
||||
// Default behavior: no explicit order -> resolveAuthProfileOrder can round-robin by lastUsed.
|
||||
const existingProviderOrder = cfg.auth?.order?.[params.provider];
|
||||
const preferProfileFirst = params.preferProfileFirst ?? true;
|
||||
const reorderedProviderOrder =
|
||||
existingProviderOrder && preferProfileFirst
|
||||
? [
|
||||
params.profileId,
|
||||
...existingProviderOrder.filter(
|
||||
(profileId) => profileId !== params.profileId,
|
||||
),
|
||||
]
|
||||
: existingProviderOrder;
|
||||
const order =
|
||||
existingProviderOrder !== undefined
|
||||
? {
|
||||
...cfg.auth?.order,
|
||||
[params.provider]: existingProviderOrder.includes(params.profileId)
|
||||
? existingProviderOrder
|
||||
: [...existingProviderOrder, params.profileId],
|
||||
[params.provider]: reorderedProviderOrder?.includes(params.profileId)
|
||||
? reorderedProviderOrder
|
||||
: [...(reorderedProviderOrder ?? []), params.profileId],
|
||||
}
|
||||
: cfg.auth?.order;
|
||||
return {
|
||||
@@ -149,24 +180,32 @@ export function applyMinimaxHostedProviderConfig(
|
||||
};
|
||||
|
||||
const providers = { ...cfg.models?.providers };
|
||||
if (!providers.minimax) {
|
||||
providers.minimax = {
|
||||
baseUrl: params?.baseUrl?.trim() || DEFAULT_MINIMAX_BASE_URL,
|
||||
apiKey: "minimax",
|
||||
api: "openai-completions",
|
||||
models: [
|
||||
{
|
||||
id: MINIMAX_HOSTED_MODEL_ID,
|
||||
name: "MiniMax M2.1",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
contextWindow: DEFAULT_MINIMAX_CONTEXT_WINDOW,
|
||||
maxTokens: DEFAULT_MINIMAX_MAX_TOKENS,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
const hostedModel: ModelDefinitionConfig = {
|
||||
id: MINIMAX_HOSTED_MODEL_ID,
|
||||
name: "MiniMax M2.1",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
contextWindow: DEFAULT_MINIMAX_CONTEXT_WINDOW,
|
||||
maxTokens: DEFAULT_MINIMAX_MAX_TOKENS,
|
||||
};
|
||||
const existingProvider = providers.minimax;
|
||||
const existingModels = Array.isArray(existingProvider?.models)
|
||||
? existingProvider.models
|
||||
: [];
|
||||
const hasHostedModel = existingModels.some(
|
||||
(model) => model.id === MINIMAX_HOSTED_MODEL_ID,
|
||||
);
|
||||
const mergedModels = hasHostedModel
|
||||
? existingModels
|
||||
: [...existingModels, hostedModel];
|
||||
providers.minimax = {
|
||||
...existingProvider,
|
||||
baseUrl: params?.baseUrl?.trim() || DEFAULT_MINIMAX_BASE_URL,
|
||||
apiKey: "minimax",
|
||||
api: "openai-completions",
|
||||
models: mergedModels.length > 0 ? mergedModels : [hostedModel],
|
||||
};
|
||||
|
||||
return {
|
||||
...cfg,
|
||||
|
||||
Reference in New Issue
Block a user