refactor: finish provider auth extraction and canonicalize kimi
This commit is contained in:
parent
3566e88c08
commit
c64f6adc83
@ -11,7 +11,7 @@ import {
|
||||
validateApiKeyInput,
|
||||
} from "../../src/commands/auth-choice.api-key.js";
|
||||
import { ensureApiKeyFromOptionEnvOrPrompt } from "../../src/commands/auth-choice.apply-helpers.js";
|
||||
import { buildApiKeyCredential } from "../../src/commands/onboard-auth.credentials.js";
|
||||
import { buildApiKeyCredential } from "../../src/commands/auth-credentials.js";
|
||||
import { applyAuthProfileConfig } from "../../src/commands/onboard-auth.js";
|
||||
import type { SecretInput } from "../../src/config/types.secrets.js";
|
||||
import { coerceSecretRef } from "../../src/config/types.secrets.js";
|
||||
|
||||
@ -1,47 +1,69 @@
|
||||
import { emptyPluginConfigSchema, type OpenClawPluginApi } from "openclaw/plugin-sdk/core";
|
||||
import {
|
||||
emptyPluginConfigSchema,
|
||||
type OpenClawPluginApi,
|
||||
type ProviderRuntimeModel,
|
||||
} from "openclaw/plugin-sdk/core";
|
||||
import { findNormalizedProviderValue, normalizeProviderId } from "../../src/agents/provider-id.js";
|
||||
import { createProviderApiKeyAuthMethod } from "../../src/plugins/provider-api-key-auth.js";
|
||||
import { isRecord } from "../../src/utils.js";
|
||||
import { applyKimiCodeConfig, KIMI_CODING_MODEL_REF } from "./onboard.js";
|
||||
import { buildKimiCodingProvider } from "./provider-catalog.js";
|
||||
import { applyKimiCodeConfig, KIMI_DEFAULT_MODEL_REF } from "./onboard.js";
|
||||
import {
|
||||
buildKimiProvider,
|
||||
KIMI_DEFAULT_MODEL_ID,
|
||||
KIMI_LEGACY_MODEL_ID,
|
||||
KIMI_UPSTREAM_MODEL_ID,
|
||||
} from "./provider-catalog.js";
|
||||
|
||||
const PROVIDER_ID = "kimi-coding";
|
||||
const PROVIDER_ID = "kimi";
|
||||
const KIMI_TRANSPORT_MODEL_IDS = new Set([KIMI_DEFAULT_MODEL_ID, KIMI_LEGACY_MODEL_ID]);
|
||||
|
||||
function normalizeKimiTransportModel(model: ProviderRuntimeModel): ProviderRuntimeModel {
|
||||
if (!KIMI_TRANSPORT_MODEL_IDS.has(model.id)) {
|
||||
return model;
|
||||
}
|
||||
return {
|
||||
...model,
|
||||
id: KIMI_UPSTREAM_MODEL_ID,
|
||||
name: "Kimi Code",
|
||||
};
|
||||
}
|
||||
|
||||
const kimiCodingPlugin = {
|
||||
id: PROVIDER_ID,
|
||||
name: "Kimi Provider",
|
||||
description: "Bundled Kimi provider plugin",
|
||||
name: "Kimi Code Provider",
|
||||
description: "Bundled Kimi Code provider plugin",
|
||||
configSchema: emptyPluginConfigSchema(),
|
||||
register(api: OpenClawPluginApi) {
|
||||
api.registerProvider({
|
||||
id: PROVIDER_ID,
|
||||
label: "Kimi",
|
||||
aliases: ["kimi", "kimi-code"],
|
||||
label: "Kimi Code",
|
||||
aliases: ["kimi-code", "kimi-coding"],
|
||||
docsPath: "/providers/moonshot",
|
||||
envVars: ["KIMI_API_KEY", "KIMICODE_API_KEY"],
|
||||
auth: [
|
||||
createProviderApiKeyAuthMethod({
|
||||
providerId: PROVIDER_ID,
|
||||
methodId: "api-key",
|
||||
label: "Kimi API key (subscription)",
|
||||
hint: "Kimi K2.5 + Kimi",
|
||||
label: "Kimi Code API key",
|
||||
hint: "Dedicated coding endpoint",
|
||||
optionKey: "kimiCodeApiKey",
|
||||
flagName: "--kimi-code-api-key",
|
||||
envVar: "KIMI_API_KEY",
|
||||
promptMessage: "Enter Kimi API key",
|
||||
defaultModel: KIMI_CODING_MODEL_REF,
|
||||
promptMessage: "Enter Kimi Code API key",
|
||||
defaultModel: KIMI_DEFAULT_MODEL_REF,
|
||||
expectedProviders: ["kimi", "kimi-code", "kimi-coding"],
|
||||
applyConfig: (cfg) => applyKimiCodeConfig(cfg),
|
||||
noteMessage: [
|
||||
"Kimi uses a dedicated coding endpoint and API key.",
|
||||
"Kimi Code uses a dedicated coding endpoint and API key.",
|
||||
"Get your API key at: https://www.kimi.com/code/en",
|
||||
].join("\n"),
|
||||
noteTitle: "Kimi",
|
||||
noteTitle: "Kimi Code",
|
||||
wizard: {
|
||||
choiceId: "kimi-code-api-key",
|
||||
choiceLabel: "Kimi API key (subscription)",
|
||||
groupId: "moonshot",
|
||||
groupLabel: "Moonshot AI (Kimi K2.5)",
|
||||
groupHint: "Kimi K2.5 + Kimi",
|
||||
choiceLabel: "Kimi Code API key",
|
||||
groupId: "kimi-code",
|
||||
groupLabel: "Kimi Code",
|
||||
groupHint: "Dedicated coding endpoint",
|
||||
},
|
||||
}),
|
||||
],
|
||||
@ -52,8 +74,11 @@ const kimiCodingPlugin = {
|
||||
if (!apiKey) {
|
||||
return null;
|
||||
}
|
||||
const explicitProvider = ctx.config.models?.providers?.[PROVIDER_ID];
|
||||
const builtInProvider = buildKimiCodingProvider();
|
||||
const explicitProvider = findNormalizedProviderValue(
|
||||
ctx.config.models?.providers,
|
||||
PROVIDER_ID,
|
||||
);
|
||||
const builtInProvider = buildKimiProvider();
|
||||
const explicitBaseUrl =
|
||||
typeof explicitProvider?.baseUrl === "string" ? explicitProvider.baseUrl.trim() : "";
|
||||
const explicitHeaders = isRecord(explicitProvider?.headers)
|
||||
@ -79,6 +104,12 @@ const kimiCodingPlugin = {
|
||||
capabilities: {
|
||||
preserveAnthropicThinkingSignatures: false,
|
||||
},
|
||||
normalizeResolvedModel: (ctx) => {
|
||||
if (normalizeProviderId(ctx.provider) !== PROVIDER_ID) {
|
||||
return undefined;
|
||||
}
|
||||
return normalizeKimiTransportModel(ctx.model);
|
||||
},
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
@ -1,38 +1,44 @@
|
||||
import {
|
||||
applyAgentDefaultModelPrimary,
|
||||
applyProviderConfigWithDefaultModel,
|
||||
applyProviderConfigWithModelCatalog,
|
||||
} from "../../src/commands/onboard-auth.config-shared.js";
|
||||
import type { OpenClawConfig } from "../../src/config/config.js";
|
||||
import {
|
||||
buildKimiCodingProvider,
|
||||
KIMI_CODING_BASE_URL,
|
||||
KIMI_CODING_DEFAULT_MODEL_ID,
|
||||
KIMI_BASE_URL,
|
||||
KIMI_DEFAULT_MODEL_ID,
|
||||
KIMI_LEGACY_MODEL_ID,
|
||||
} from "./provider-catalog.js";
|
||||
|
||||
export const KIMI_CODING_MODEL_REF = `kimi-coding/${KIMI_CODING_DEFAULT_MODEL_ID}`;
|
||||
export const KIMI_DEFAULT_MODEL_REF = `kimi/${KIMI_DEFAULT_MODEL_ID}`;
|
||||
export const KIMI_LEGACY_MODEL_REF = `kimi/${KIMI_LEGACY_MODEL_ID}`;
|
||||
export const KIMI_CODING_MODEL_REF = KIMI_DEFAULT_MODEL_REF;
|
||||
|
||||
export function applyKimiCodeProviderConfig(cfg: OpenClawConfig): OpenClawConfig {
|
||||
const models = { ...cfg.agents?.defaults?.models };
|
||||
models[KIMI_CODING_MODEL_REF] = {
|
||||
...models[KIMI_CODING_MODEL_REF],
|
||||
alias: models[KIMI_CODING_MODEL_REF]?.alias ?? "Kimi",
|
||||
models[KIMI_DEFAULT_MODEL_REF] = {
|
||||
...models[KIMI_DEFAULT_MODEL_REF],
|
||||
alias: models[KIMI_DEFAULT_MODEL_REF]?.alias ?? "Kimi Code",
|
||||
};
|
||||
models[KIMI_LEGACY_MODEL_REF] = {
|
||||
...models[KIMI_LEGACY_MODEL_REF],
|
||||
alias: models[KIMI_LEGACY_MODEL_REF]?.alias ?? "Kimi Code",
|
||||
};
|
||||
|
||||
const defaultModel = buildKimiCodingProvider().models[0];
|
||||
if (!defaultModel) {
|
||||
const catalog = buildKimiCodingProvider().models ?? [];
|
||||
if (catalog.length === 0) {
|
||||
return cfg;
|
||||
}
|
||||
|
||||
return applyProviderConfigWithDefaultModel(cfg, {
|
||||
return applyProviderConfigWithModelCatalog(cfg, {
|
||||
agentModels: models,
|
||||
providerId: "kimi-coding",
|
||||
providerId: "kimi",
|
||||
api: "anthropic-messages",
|
||||
baseUrl: KIMI_CODING_BASE_URL,
|
||||
defaultModel,
|
||||
defaultModelId: KIMI_CODING_DEFAULT_MODEL_ID,
|
||||
baseUrl: KIMI_BASE_URL,
|
||||
catalogModels: catalog,
|
||||
});
|
||||
}
|
||||
|
||||
export function applyKimiCodeConfig(cfg: OpenClawConfig): OpenClawConfig {
|
||||
return applyAgentDefaultModelPrimary(applyKimiCodeProviderConfig(cfg), KIMI_CODING_MODEL_REF);
|
||||
return applyAgentDefaultModelPrimary(applyKimiCodeProviderConfig(cfg), KIMI_DEFAULT_MODEL_REF);
|
||||
}
|
||||
|
||||
@ -1,22 +1,23 @@
|
||||
{
|
||||
"id": "kimi-coding",
|
||||
"providers": ["kimi-coding"],
|
||||
"id": "kimi",
|
||||
"providers": ["kimi", "kimi-coding"],
|
||||
"providerAuthEnvVars": {
|
||||
"kimi": ["KIMI_API_KEY", "KIMICODE_API_KEY"],
|
||||
"kimi-coding": ["KIMI_API_KEY", "KIMICODE_API_KEY"]
|
||||
},
|
||||
"providerAuthChoices": [
|
||||
{
|
||||
"provider": "kimi-coding",
|
||||
"provider": "kimi",
|
||||
"method": "api-key",
|
||||
"choiceId": "kimi-code-api-key",
|
||||
"choiceLabel": "Kimi API key (subscription)",
|
||||
"groupId": "moonshot",
|
||||
"groupLabel": "Moonshot AI (Kimi K2.5)",
|
||||
"groupHint": "Kimi K2.5 + Kimi",
|
||||
"choiceLabel": "Kimi Code API key",
|
||||
"groupId": "kimi-code",
|
||||
"groupLabel": "Kimi Code",
|
||||
"groupHint": "Dedicated coding endpoint",
|
||||
"optionKey": "kimiCodeApiKey",
|
||||
"cliFlag": "--kimi-code-api-key",
|
||||
"cliOption": "--kimi-code-api-key <key>",
|
||||
"cliDescription": "Kimi API key"
|
||||
"cliDescription": "Kimi Code API key"
|
||||
}
|
||||
],
|
||||
"configSchema": {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "@openclaw/kimi-coding-provider",
|
||||
"name": "@openclaw/kimi-provider",
|
||||
"version": "2026.3.14",
|
||||
"private": true,
|
||||
"description": "OpenClaw Kimi provider plugin",
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
import type { ModelProviderConfig } from "../../src/config/types.models.js";
|
||||
|
||||
export const KIMI_CODING_BASE_URL = "https://api.kimi.com/coding/";
|
||||
export const KIMI_BASE_URL = "https://api.kimi.com/coding/";
|
||||
const KIMI_CODING_USER_AGENT = "claude-code/0.1.0";
|
||||
export const KIMI_CODING_DEFAULT_MODEL_ID = "k2p5";
|
||||
export const KIMI_DEFAULT_MODEL_ID = "kimi-code";
|
||||
export const KIMI_UPSTREAM_MODEL_ID = "kimi-for-coding";
|
||||
export const KIMI_LEGACY_MODEL_ID = "k2p5";
|
||||
const KIMI_CODING_DEFAULT_CONTEXT_WINDOW = 262144;
|
||||
const KIMI_CODING_DEFAULT_MAX_TOKENS = 32768;
|
||||
const KIMI_CODING_DEFAULT_COST = {
|
||||
@ -14,15 +16,24 @@ const KIMI_CODING_DEFAULT_COST = {
|
||||
|
||||
export function buildKimiCodingProvider(): ModelProviderConfig {
|
||||
return {
|
||||
baseUrl: KIMI_CODING_BASE_URL,
|
||||
baseUrl: KIMI_BASE_URL,
|
||||
api: "anthropic-messages",
|
||||
headers: {
|
||||
"User-Agent": KIMI_CODING_USER_AGENT,
|
||||
},
|
||||
models: [
|
||||
{
|
||||
id: KIMI_CODING_DEFAULT_MODEL_ID,
|
||||
name: "Kimi",
|
||||
id: KIMI_DEFAULT_MODEL_ID,
|
||||
name: "Kimi Code",
|
||||
reasoning: true,
|
||||
input: ["text", "image"],
|
||||
cost: KIMI_CODING_DEFAULT_COST,
|
||||
contextWindow: KIMI_CODING_DEFAULT_CONTEXT_WINDOW,
|
||||
maxTokens: KIMI_CODING_DEFAULT_MAX_TOKENS,
|
||||
},
|
||||
{
|
||||
id: KIMI_LEGACY_MODEL_ID,
|
||||
name: "Kimi Code (legacy model id)",
|
||||
reasoning: true,
|
||||
input: ["text", "image"],
|
||||
cost: KIMI_CODING_DEFAULT_COST,
|
||||
@ -32,3 +43,8 @@ export function buildKimiCodingProvider(): ModelProviderConfig {
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
export const KIMI_CODING_BASE_URL = KIMI_BASE_URL;
|
||||
export const KIMI_CODING_DEFAULT_MODEL_ID = KIMI_DEFAULT_MODEL_ID;
|
||||
export const KIMI_CODING_LEGACY_MODEL_ID = KIMI_LEGACY_MODEL_ID;
|
||||
export const buildKimiProvider = buildKimiCodingProvider;
|
||||
|
||||
64
extensions/minimax/model-definitions.ts
Normal file
64
extensions/minimax/model-definitions.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import type { ModelDefinitionConfig } from "../../src/config/types.models.js";
|
||||
|
||||
export const DEFAULT_MINIMAX_BASE_URL = "https://api.minimax.io/v1";
|
||||
export const MINIMAX_API_BASE_URL = "https://api.minimax.io/anthropic";
|
||||
export const MINIMAX_CN_API_BASE_URL = "https://api.minimaxi.com/anthropic";
|
||||
export const MINIMAX_HOSTED_MODEL_ID = "MiniMax-M2.5";
|
||||
export const MINIMAX_HOSTED_MODEL_REF = `minimax/${MINIMAX_HOSTED_MODEL_ID}`;
|
||||
export const DEFAULT_MINIMAX_CONTEXT_WINDOW = 200000;
|
||||
export const DEFAULT_MINIMAX_MAX_TOKENS = 8192;
|
||||
|
||||
export const MINIMAX_API_COST = {
|
||||
input: 0.3,
|
||||
output: 1.2,
|
||||
cacheRead: 0.03,
|
||||
cacheWrite: 0.12,
|
||||
};
|
||||
export const MINIMAX_HOSTED_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
export const MINIMAX_LM_STUDIO_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
const MINIMAX_MODEL_CATALOG = {
|
||||
"MiniMax-M2.5": { name: "MiniMax M2.5", reasoning: true },
|
||||
"MiniMax-M2.5-highspeed": { name: "MiniMax M2.5 Highspeed", reasoning: true },
|
||||
} as const;
|
||||
|
||||
type MinimaxCatalogId = keyof typeof MINIMAX_MODEL_CATALOG;
|
||||
|
||||
export function buildMinimaxModelDefinition(params: {
|
||||
id: string;
|
||||
name?: string;
|
||||
reasoning?: boolean;
|
||||
cost: ModelDefinitionConfig["cost"];
|
||||
contextWindow: number;
|
||||
maxTokens: number;
|
||||
}): ModelDefinitionConfig {
|
||||
const catalog = MINIMAX_MODEL_CATALOG[params.id as MinimaxCatalogId];
|
||||
return {
|
||||
id: params.id,
|
||||
name: params.name ?? catalog?.name ?? `MiniMax ${params.id}`,
|
||||
reasoning: params.reasoning ?? catalog?.reasoning ?? false,
|
||||
input: ["text"],
|
||||
cost: params.cost,
|
||||
contextWindow: params.contextWindow,
|
||||
maxTokens: params.maxTokens,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildMinimaxApiModelDefinition(modelId: string): ModelDefinitionConfig {
|
||||
return buildMinimaxModelDefinition({
|
||||
id: modelId,
|
||||
cost: MINIMAX_API_COST,
|
||||
contextWindow: DEFAULT_MINIMAX_CONTEXT_WINDOW,
|
||||
maxTokens: DEFAULT_MINIMAX_MAX_TOKENS,
|
||||
});
|
||||
}
|
||||
@ -2,13 +2,13 @@ import {
|
||||
applyAgentDefaultModelPrimary,
|
||||
applyOnboardAuthAgentModelsAndProviders,
|
||||
} from "../../src/commands/onboard-auth.config-shared.js";
|
||||
import type { OpenClawConfig } from "../../src/config/config.js";
|
||||
import type { ModelProviderConfig } from "../../src/config/types.models.js";
|
||||
import {
|
||||
buildMinimaxApiModelDefinition,
|
||||
MINIMAX_API_BASE_URL,
|
||||
MINIMAX_CN_API_BASE_URL,
|
||||
} from "../../src/commands/onboard-auth.models.js";
|
||||
import type { OpenClawConfig } from "../../src/config/config.js";
|
||||
import type { ModelProviderConfig } from "../../src/config/types.models.js";
|
||||
} from "./model-definitions.js";
|
||||
|
||||
type MinimaxApiProviderConfigParams = {
|
||||
providerId: string;
|
||||
|
||||
25
extensions/mistral/model-definitions.ts
Normal file
25
extensions/mistral/model-definitions.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import type { ModelDefinitionConfig } from "../../src/config/types.models.js";
|
||||
|
||||
export const MISTRAL_BASE_URL = "https://api.mistral.ai/v1";
|
||||
export const MISTRAL_DEFAULT_MODEL_ID = "mistral-large-latest";
|
||||
export const MISTRAL_DEFAULT_MODEL_REF = `mistral/${MISTRAL_DEFAULT_MODEL_ID}`;
|
||||
export const MISTRAL_DEFAULT_CONTEXT_WINDOW = 262144;
|
||||
export const MISTRAL_DEFAULT_MAX_TOKENS = 262144;
|
||||
export const MISTRAL_DEFAULT_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
export function buildMistralModelDefinition(): ModelDefinitionConfig {
|
||||
return {
|
||||
id: MISTRAL_DEFAULT_MODEL_ID,
|
||||
name: "Mistral Large",
|
||||
reasoning: false,
|
||||
input: ["text", "image"],
|
||||
cost: MISTRAL_DEFAULT_COST,
|
||||
contextWindow: MISTRAL_DEFAULT_CONTEXT_WINDOW,
|
||||
maxTokens: MISTRAL_DEFAULT_MAX_TOKENS,
|
||||
};
|
||||
}
|
||||
@ -2,14 +2,15 @@ import {
|
||||
applyAgentDefaultModelPrimary,
|
||||
applyProviderConfigWithDefaultModel,
|
||||
} from "../../src/commands/onboard-auth.config-shared.js";
|
||||
import type { OpenClawConfig } from "../../src/config/config.js";
|
||||
import {
|
||||
buildMistralModelDefinition,
|
||||
MISTRAL_BASE_URL,
|
||||
MISTRAL_DEFAULT_MODEL_ID,
|
||||
} from "../../src/commands/onboard-auth.models.js";
|
||||
import type { OpenClawConfig } from "../../src/config/config.js";
|
||||
MISTRAL_DEFAULT_MODEL_REF,
|
||||
} from "./model-definitions.js";
|
||||
|
||||
export const MISTRAL_DEFAULT_MODEL_REF = `mistral/${MISTRAL_DEFAULT_MODEL_ID}`;
|
||||
export { MISTRAL_DEFAULT_MODEL_REF };
|
||||
|
||||
export function applyMistralProviderConfig(cfg: OpenClawConfig): OpenClawConfig {
|
||||
const models = { ...cfg.agents?.defaults?.models };
|
||||
|
||||
102
extensions/modelstudio/model-definitions.ts
Normal file
102
extensions/modelstudio/model-definitions.ts
Normal file
@ -0,0 +1,102 @@
|
||||
import type { ModelDefinitionConfig } from "../../src/config/types.models.js";
|
||||
|
||||
export const MODELSTUDIO_CN_BASE_URL = "https://coding.dashscope.aliyuncs.com/v1";
|
||||
export const MODELSTUDIO_GLOBAL_BASE_URL = "https://coding-intl.dashscope.aliyuncs.com/v1";
|
||||
export const MODELSTUDIO_DEFAULT_MODEL_ID = "qwen3.5-plus";
|
||||
export const MODELSTUDIO_DEFAULT_MODEL_REF = `modelstudio/${MODELSTUDIO_DEFAULT_MODEL_ID}`;
|
||||
export const MODELSTUDIO_DEFAULT_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
const MODELSTUDIO_MODEL_CATALOG = {
|
||||
"qwen3.5-plus": {
|
||||
name: "qwen3.5-plus",
|
||||
reasoning: false,
|
||||
input: ["text", "image"],
|
||||
contextWindow: 1000000,
|
||||
maxTokens: 65536,
|
||||
},
|
||||
"qwen3-max-2026-01-23": {
|
||||
name: "qwen3-max-2026-01-23",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
contextWindow: 262144,
|
||||
maxTokens: 65536,
|
||||
},
|
||||
"qwen3-coder-next": {
|
||||
name: "qwen3-coder-next",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
contextWindow: 262144,
|
||||
maxTokens: 65536,
|
||||
},
|
||||
"qwen3-coder-plus": {
|
||||
name: "qwen3-coder-plus",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
contextWindow: 1000000,
|
||||
maxTokens: 65536,
|
||||
},
|
||||
"MiniMax-M2.5": {
|
||||
name: "MiniMax-M2.5",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
contextWindow: 1000000,
|
||||
maxTokens: 65536,
|
||||
},
|
||||
"glm-5": {
|
||||
name: "glm-5",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
contextWindow: 202752,
|
||||
maxTokens: 16384,
|
||||
},
|
||||
"glm-4.7": {
|
||||
name: "glm-4.7",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
contextWindow: 202752,
|
||||
maxTokens: 16384,
|
||||
},
|
||||
"kimi-k2.5": {
|
||||
name: "kimi-k2.5",
|
||||
reasoning: false,
|
||||
input: ["text", "image"],
|
||||
contextWindow: 262144,
|
||||
maxTokens: 32768,
|
||||
},
|
||||
} as const;
|
||||
|
||||
type ModelStudioCatalogId = keyof typeof MODELSTUDIO_MODEL_CATALOG;
|
||||
|
||||
export function buildModelStudioModelDefinition(params: {
|
||||
id: string;
|
||||
name?: string;
|
||||
reasoning?: boolean;
|
||||
input?: string[];
|
||||
cost?: ModelDefinitionConfig["cost"];
|
||||
contextWindow?: number;
|
||||
maxTokens?: number;
|
||||
}): ModelDefinitionConfig {
|
||||
const catalog = MODELSTUDIO_MODEL_CATALOG[params.id as ModelStudioCatalogId];
|
||||
return {
|
||||
id: params.id,
|
||||
name: params.name ?? catalog?.name ?? params.id,
|
||||
reasoning: params.reasoning ?? catalog?.reasoning ?? false,
|
||||
input:
|
||||
(params.input as ("text" | "image")[]) ??
|
||||
([...(catalog?.input ?? ["text"])] as ("text" | "image")[]),
|
||||
cost: params.cost ?? MODELSTUDIO_DEFAULT_COST,
|
||||
contextWindow: params.contextWindow ?? catalog?.contextWindow ?? 262144,
|
||||
maxTokens: params.maxTokens ?? catalog?.maxTokens ?? 65536,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildModelStudioDefaultModelDefinition(): ModelDefinitionConfig {
|
||||
return buildModelStudioModelDefinition({
|
||||
id: MODELSTUDIO_DEFAULT_MODEL_ID,
|
||||
});
|
||||
}
|
||||
@ -2,12 +2,12 @@ import {
|
||||
applyAgentDefaultModelPrimary,
|
||||
applyProviderConfigWithModelCatalog,
|
||||
} from "../../src/commands/onboard-auth.config-shared.js";
|
||||
import type { OpenClawConfig } from "../../src/config/config.js";
|
||||
import {
|
||||
MODELSTUDIO_CN_BASE_URL,
|
||||
MODELSTUDIO_DEFAULT_MODEL_REF,
|
||||
MODELSTUDIO_GLOBAL_BASE_URL,
|
||||
} from "../../src/commands/onboard-auth.models.js";
|
||||
import type { OpenClawConfig } from "../../src/config/config.js";
|
||||
} from "./model-definitions.js";
|
||||
import { buildModelStudioProvider } from "./provider-catalog.js";
|
||||
|
||||
export { MODELSTUDIO_CN_BASE_URL, MODELSTUDIO_DEFAULT_MODEL_REF, MODELSTUDIO_GLOBAL_BASE_URL };
|
||||
|
||||
@ -35,8 +35,8 @@ const moonshotPlugin = {
|
||||
createProviderApiKeyAuthMethod({
|
||||
providerId: PROVIDER_ID,
|
||||
methodId: "api-key",
|
||||
label: "Kimi API key (.ai)",
|
||||
hint: "Kimi K2.5 + Kimi",
|
||||
label: "Moonshot API key (.ai)",
|
||||
hint: "Kimi K2.5",
|
||||
optionKey: "moonshotApiKey",
|
||||
flagName: "--moonshot-api-key",
|
||||
envVar: "MOONSHOT_API_KEY",
|
||||
@ -46,17 +46,17 @@ const moonshotPlugin = {
|
||||
applyConfig: (cfg) => applyMoonshotConfig(cfg),
|
||||
wizard: {
|
||||
choiceId: "moonshot-api-key",
|
||||
choiceLabel: "Kimi API key (.ai)",
|
||||
choiceLabel: "Moonshot API key (.ai)",
|
||||
groupId: "moonshot",
|
||||
groupLabel: "Moonshot AI (Kimi K2.5)",
|
||||
groupHint: "Kimi K2.5 + Kimi",
|
||||
groupHint: "Kimi K2.5",
|
||||
},
|
||||
}),
|
||||
createProviderApiKeyAuthMethod({
|
||||
providerId: PROVIDER_ID,
|
||||
methodId: "api-key-cn",
|
||||
label: "Kimi API key (.cn)",
|
||||
hint: "Kimi K2.5 + Kimi",
|
||||
label: "Moonshot API key (.cn)",
|
||||
hint: "Kimi K2.5",
|
||||
optionKey: "moonshotApiKey",
|
||||
flagName: "--moonshot-api-key",
|
||||
envVar: "MOONSHOT_API_KEY",
|
||||
@ -66,10 +66,10 @@ const moonshotPlugin = {
|
||||
applyConfig: (cfg) => applyMoonshotConfigCn(cfg),
|
||||
wizard: {
|
||||
choiceId: "moonshot-api-key-cn",
|
||||
choiceLabel: "Kimi API key (.cn)",
|
||||
choiceLabel: "Moonshot API key (.cn)",
|
||||
groupId: "moonshot",
|
||||
groupLabel: "Moonshot AI (Kimi K2.5)",
|
||||
groupHint: "Kimi K2.5 + Kimi",
|
||||
groupHint: "Kimi K2.5",
|
||||
},
|
||||
}),
|
||||
],
|
||||
|
||||
@ -9,10 +9,10 @@
|
||||
"provider": "moonshot",
|
||||
"method": "api-key",
|
||||
"choiceId": "moonshot-api-key",
|
||||
"choiceLabel": "Kimi API key (.ai)",
|
||||
"choiceLabel": "Moonshot API key (.ai)",
|
||||
"groupId": "moonshot",
|
||||
"groupLabel": "Moonshot AI (Kimi K2.5)",
|
||||
"groupHint": "Kimi K2.5 + Kimi",
|
||||
"groupHint": "Kimi K2.5",
|
||||
"optionKey": "moonshotApiKey",
|
||||
"cliFlag": "--moonshot-api-key",
|
||||
"cliOption": "--moonshot-api-key <key>",
|
||||
@ -22,10 +22,10 @@
|
||||
"provider": "moonshot",
|
||||
"method": "api-key-cn",
|
||||
"choiceId": "moonshot-api-key-cn",
|
||||
"choiceLabel": "Kimi API key (.cn)",
|
||||
"choiceLabel": "Moonshot API key (.cn)",
|
||||
"groupId": "moonshot",
|
||||
"groupLabel": "Moonshot AI (Kimi K2.5)",
|
||||
"groupHint": "Kimi K2.5 + Kimi",
|
||||
"groupHint": "Kimi K2.5",
|
||||
"optionKey": "moonshotApiKey",
|
||||
"cliFlag": "--moonshot-api-key",
|
||||
"cliOption": "--moonshot-api-key <key>",
|
||||
|
||||
25
extensions/xai/model-definitions.ts
Normal file
25
extensions/xai/model-definitions.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import type { ModelDefinitionConfig } from "../../src/config/types.models.js";
|
||||
|
||||
export const XAI_BASE_URL = "https://api.x.ai/v1";
|
||||
export const XAI_DEFAULT_MODEL_ID = "grok-4";
|
||||
export const XAI_DEFAULT_MODEL_REF = `xai/${XAI_DEFAULT_MODEL_ID}`;
|
||||
export const XAI_DEFAULT_CONTEXT_WINDOW = 131072;
|
||||
export const XAI_DEFAULT_MAX_TOKENS = 8192;
|
||||
export const XAI_DEFAULT_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
export function buildXaiModelDefinition(): ModelDefinitionConfig {
|
||||
return {
|
||||
id: XAI_DEFAULT_MODEL_ID,
|
||||
name: "Grok 4",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
cost: XAI_DEFAULT_COST,
|
||||
contextWindow: XAI_DEFAULT_CONTEXT_WINDOW,
|
||||
maxTokens: XAI_DEFAULT_MAX_TOKENS,
|
||||
};
|
||||
}
|
||||
@ -2,14 +2,15 @@ import {
|
||||
applyAgentDefaultModelPrimary,
|
||||
applyProviderConfigWithDefaultModel,
|
||||
} from "../../src/commands/onboard-auth.config-shared.js";
|
||||
import type { OpenClawConfig } from "../../src/config/config.js";
|
||||
import {
|
||||
buildXaiModelDefinition,
|
||||
XAI_BASE_URL,
|
||||
XAI_DEFAULT_MODEL_ID,
|
||||
} from "../../src/commands/onboard-auth.models.js";
|
||||
import type { OpenClawConfig } from "../../src/config/config.js";
|
||||
XAI_DEFAULT_MODEL_REF,
|
||||
} from "./model-definitions.js";
|
||||
|
||||
export const XAI_DEFAULT_MODEL_REF = `xai/${XAI_DEFAULT_MODEL_ID}`;
|
||||
export { XAI_DEFAULT_MODEL_REF };
|
||||
|
||||
export function applyXaiProviderConfig(cfg: OpenClawConfig): OpenClawConfig {
|
||||
const models = { ...cfg.agents?.defaults?.models };
|
||||
|
||||
@ -19,7 +19,7 @@ import {
|
||||
validateApiKeyInput,
|
||||
} from "../../src/commands/auth-choice.api-key.js";
|
||||
import { ensureApiKeyFromOptionEnvOrPrompt } from "../../src/commands/auth-choice.apply-helpers.js";
|
||||
import { buildApiKeyCredential } from "../../src/commands/onboard-auth.credentials.js";
|
||||
import { buildApiKeyCredential } from "../../src/commands/auth-credentials.js";
|
||||
import { applyAuthProfileConfig } from "../../src/commands/onboard-auth.js";
|
||||
import type { SecretInput } from "../../src/config/types.secrets.js";
|
||||
import { resolveRequiredHomeDir } from "../../src/infra/home-dir.js";
|
||||
|
||||
60
extensions/zai/model-definitions.ts
Normal file
60
extensions/zai/model-definitions.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import type { ModelDefinitionConfig } from "../../src/config/types.models.js";
|
||||
|
||||
export const ZAI_CODING_GLOBAL_BASE_URL = "https://api.z.ai/api/coding/paas/v4";
|
||||
export const ZAI_CODING_CN_BASE_URL = "https://open.bigmodel.cn/api/coding/paas/v4";
|
||||
export const ZAI_GLOBAL_BASE_URL = "https://api.z.ai/api/paas/v4";
|
||||
export const ZAI_CN_BASE_URL = "https://open.bigmodel.cn/api/paas/v4";
|
||||
export const ZAI_DEFAULT_MODEL_ID = "glm-5";
|
||||
export const ZAI_DEFAULT_MODEL_REF = `zai/${ZAI_DEFAULT_MODEL_ID}`;
|
||||
|
||||
export const ZAI_DEFAULT_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
const ZAI_MODEL_CATALOG = {
|
||||
"glm-5": { name: "GLM-5", reasoning: true },
|
||||
"glm-5-turbo": { name: "GLM-5 Turbo", reasoning: true },
|
||||
"glm-4.7": { name: "GLM-4.7", reasoning: true },
|
||||
"glm-4.7-flash": { name: "GLM-4.7 Flash", reasoning: true },
|
||||
"glm-4.7-flashx": { name: "GLM-4.7 FlashX", reasoning: true },
|
||||
} as const;
|
||||
|
||||
type ZaiCatalogId = keyof typeof ZAI_MODEL_CATALOG;
|
||||
|
||||
export function resolveZaiBaseUrl(endpoint?: string): string {
|
||||
switch (endpoint) {
|
||||
case "coding-cn":
|
||||
return ZAI_CODING_CN_BASE_URL;
|
||||
case "global":
|
||||
return ZAI_GLOBAL_BASE_URL;
|
||||
case "cn":
|
||||
return ZAI_CN_BASE_URL;
|
||||
case "coding-global":
|
||||
return ZAI_CODING_GLOBAL_BASE_URL;
|
||||
default:
|
||||
return ZAI_GLOBAL_BASE_URL;
|
||||
}
|
||||
}
|
||||
|
||||
export function buildZaiModelDefinition(params: {
|
||||
id: string;
|
||||
name?: string;
|
||||
reasoning?: boolean;
|
||||
cost?: ModelDefinitionConfig["cost"];
|
||||
contextWindow?: number;
|
||||
maxTokens?: number;
|
||||
}): ModelDefinitionConfig {
|
||||
const catalog = ZAI_MODEL_CATALOG[params.id as ZaiCatalogId];
|
||||
return {
|
||||
id: params.id,
|
||||
name: params.name ?? catalog?.name ?? `GLM ${params.id}`,
|
||||
reasoning: params.reasoning ?? catalog?.reasoning ?? true,
|
||||
input: ["text"],
|
||||
cost: params.cost ?? ZAI_DEFAULT_COST,
|
||||
contextWindow: params.contextWindow ?? 204800,
|
||||
maxTokens: params.maxTokens ?? 131072,
|
||||
};
|
||||
}
|
||||
@ -2,14 +2,15 @@ import {
|
||||
applyAgentDefaultModelPrimary,
|
||||
applyProviderConfigWithModelCatalog,
|
||||
} from "../../src/commands/onboard-auth.config-shared.js";
|
||||
import type { OpenClawConfig } from "../../src/config/config.js";
|
||||
import {
|
||||
buildZaiModelDefinition,
|
||||
resolveZaiBaseUrl,
|
||||
ZAI_DEFAULT_MODEL_ID,
|
||||
} from "../../src/commands/onboard-auth.models.js";
|
||||
import type { OpenClawConfig } from "../../src/config/config.js";
|
||||
ZAI_DEFAULT_MODEL_REF,
|
||||
} from "./model-definitions.js";
|
||||
|
||||
export const ZAI_DEFAULT_MODEL_REF = `zai/${ZAI_DEFAULT_MODEL_ID}`;
|
||||
export { ZAI_DEFAULT_MODEL_REF };
|
||||
|
||||
const ZAI_DEFAULT_MODELS = [
|
||||
buildZaiModelDefinition({ id: "glm-5" }),
|
||||
|
||||
@ -112,7 +112,8 @@ describe("model-selection", () => {
|
||||
expect(normalizeProviderId("z-ai")).toBe("zai");
|
||||
expect(normalizeProviderId("OpenCode-Zen")).toBe("opencode");
|
||||
expect(normalizeProviderId("qwen")).toBe("qwen-portal");
|
||||
expect(normalizeProviderId("kimi-code")).toBe("kimi-coding");
|
||||
expect(normalizeProviderId("kimi-code")).toBe("kimi");
|
||||
expect(normalizeProviderId("kimi-coding")).toBe("kimi");
|
||||
expect(normalizeProviderId("bedrock")).toBe("amazon-bedrock");
|
||||
expect(normalizeProviderId("aws-bedrock")).toBe("amazon-bedrock");
|
||||
expect(normalizeProviderId("amazon-bedrock")).toBe("amazon-bedrock");
|
||||
|
||||
@ -74,8 +74,8 @@ describe("models-config merge helpers", () => {
|
||||
headers: { "User-Agent": "claude-code/0.1.0" },
|
||||
models: [
|
||||
{
|
||||
id: "k2p5",
|
||||
name: "Kimi for Coding",
|
||||
id: "kimi-code",
|
||||
name: "Kimi Code",
|
||||
input: ["text", "image"],
|
||||
reasoning: true,
|
||||
},
|
||||
@ -87,8 +87,8 @@ describe("models-config merge helpers", () => {
|
||||
headers: { "X-Kimi-Tenant": "tenant-a" },
|
||||
models: [
|
||||
{
|
||||
id: "k2p5",
|
||||
name: "Kimi for Coding",
|
||||
id: "kimi-code",
|
||||
name: "Kimi Code",
|
||||
input: ["text", "image"],
|
||||
reasoning: true,
|
||||
},
|
||||
|
||||
@ -6,46 +6,47 @@ import { captureEnv } from "../test-utils/env.js";
|
||||
import { resolveImplicitProvidersForTest } from "./models-config.e2e-harness.js";
|
||||
import { buildKimiCodingProvider } from "./models-config.providers.js";
|
||||
|
||||
describe("kimi-coding implicit provider (#22409)", () => {
|
||||
it("should include kimi-coding when KIMI_API_KEY is configured", async () => {
|
||||
describe("Kimi implicit provider (#22409)", () => {
|
||||
it("should include Kimi when KIMI_API_KEY is configured", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
|
||||
const envSnapshot = captureEnv(["KIMI_API_KEY"]);
|
||||
process.env.KIMI_API_KEY = "test-key"; // pragma: allowlist secret
|
||||
|
||||
try {
|
||||
const providers = await resolveImplicitProvidersForTest({ agentDir });
|
||||
expect(providers?.["kimi-coding"]).toBeDefined();
|
||||
expect(providers?.["kimi-coding"]?.api).toBe("anthropic-messages");
|
||||
expect(providers?.["kimi-coding"]?.baseUrl).toBe("https://api.kimi.com/coding/");
|
||||
expect(providers?.kimi).toBeDefined();
|
||||
expect(providers?.kimi?.api).toBe("anthropic-messages");
|
||||
expect(providers?.kimi?.baseUrl).toBe("https://api.kimi.com/coding/");
|
||||
} finally {
|
||||
envSnapshot.restore();
|
||||
}
|
||||
});
|
||||
|
||||
it("should build kimi-coding provider with anthropic-messages API", () => {
|
||||
it("should build Kimi provider with anthropic-messages API", () => {
|
||||
const provider = buildKimiCodingProvider();
|
||||
expect(provider.api).toBe("anthropic-messages");
|
||||
expect(provider.baseUrl).toBe("https://api.kimi.com/coding/");
|
||||
expect(provider.headers).toEqual({ "User-Agent": "claude-code/0.1.0" });
|
||||
expect(provider.models).toBeDefined();
|
||||
expect(provider.models.length).toBeGreaterThan(0);
|
||||
expect(provider.models[0].id).toBe("k2p5");
|
||||
expect(provider.models[0].id).toBe("kimi-code");
|
||||
expect(provider.models.some((model) => model.id === "k2p5")).toBe(true);
|
||||
});
|
||||
|
||||
it("should not include kimi-coding when no API key is configured", async () => {
|
||||
it("should not include Kimi when no API key is configured", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
|
||||
const envSnapshot = captureEnv(["KIMI_API_KEY"]);
|
||||
delete process.env.KIMI_API_KEY;
|
||||
|
||||
try {
|
||||
const providers = await resolveImplicitProvidersForTest({ agentDir });
|
||||
expect(providers?.["kimi-coding"]).toBeUndefined();
|
||||
expect(providers?.kimi).toBeUndefined();
|
||||
} finally {
|
||||
envSnapshot.restore();
|
||||
}
|
||||
});
|
||||
|
||||
it("uses explicit kimi-coding baseUrl when provided", async () => {
|
||||
it("uses explicit legacy kimi-coding baseUrl when provided", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
|
||||
const envSnapshot = captureEnv(["KIMI_API_KEY"]);
|
||||
process.env.KIMI_API_KEY = "test-key";
|
||||
@ -61,13 +62,13 @@ describe("kimi-coding implicit provider (#22409)", () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(providers?.["kimi-coding"]?.baseUrl).toBe("https://kimi.example.test/coding/");
|
||||
expect(providers?.kimi?.baseUrl).toBe("https://kimi.example.test/coding/");
|
||||
} finally {
|
||||
envSnapshot.restore();
|
||||
}
|
||||
});
|
||||
|
||||
it("merges explicit kimi-coding headers on top of the built-in user agent", async () => {
|
||||
it("merges explicit legacy kimi-coding headers on top of the built-in user agent", async () => {
|
||||
const agentDir = mkdtempSync(join(tmpdir(), "openclaw-test-"));
|
||||
const envSnapshot = captureEnv(["KIMI_API_KEY"]);
|
||||
process.env.KIMI_API_KEY = "test-key";
|
||||
@ -87,7 +88,7 @@ describe("kimi-coding implicit provider (#22409)", () => {
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(providers?.["kimi-coding"]?.headers).toEqual({
|
||||
expect(providers?.kimi?.headers).toEqual({
|
||||
"User-Agent": "custom-kimi-client/1.0",
|
||||
"X-Kimi-Tenant": "tenant-a",
|
||||
});
|
||||
|
||||
@ -908,7 +908,7 @@ describe("applyExtraParamsToAgent", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("does not rewrite tool schema for kimi-coding (native Anthropic format)", () => {
|
||||
it("does not rewrite tool schema for Kimi (native Anthropic format)", () => {
|
||||
const payloads: Record<string, unknown>[] = [];
|
||||
const baseStreamFn: StreamFn = (_model, _context, options) => {
|
||||
const payload: Record<string, unknown> = {
|
||||
@ -931,12 +931,12 @@ describe("applyExtraParamsToAgent", () => {
|
||||
};
|
||||
const agent = { streamFn: baseStreamFn };
|
||||
|
||||
applyExtraParamsToAgent(agent, undefined, "kimi-coding", "k2p5", undefined, "low");
|
||||
applyExtraParamsToAgent(agent, undefined, "kimi", "kimi-code", undefined, "low");
|
||||
|
||||
const model = {
|
||||
api: "anthropic-messages",
|
||||
provider: "kimi-coding",
|
||||
id: "k2p5",
|
||||
provider: "kimi",
|
||||
id: "kimi-code",
|
||||
baseUrl: "https://api.kimi.com/coding/",
|
||||
} as Model<"anthropic-messages">;
|
||||
const context: Context = { messages: [] };
|
||||
|
||||
@ -1129,13 +1129,13 @@ describe("resolveModel", () => {
|
||||
|
||||
it("lets provider config override registry-found kimi user agent headers", () => {
|
||||
mockDiscoveredModel({
|
||||
provider: "kimi-coding",
|
||||
modelId: "k2p5",
|
||||
provider: "kimi",
|
||||
modelId: "kimi-code",
|
||||
templateModel: {
|
||||
...buildForwardCompatTemplate({
|
||||
id: "k2p5",
|
||||
name: "Kimi for Coding",
|
||||
provider: "kimi-coding",
|
||||
id: "kimi-code",
|
||||
name: "Kimi Code",
|
||||
provider: "kimi",
|
||||
api: "anthropic-messages",
|
||||
baseUrl: "https://api.kimi.com/coding/",
|
||||
}),
|
||||
@ -1146,7 +1146,7 @@ describe("resolveModel", () => {
|
||||
const cfg = {
|
||||
models: {
|
||||
providers: {
|
||||
"kimi-coding": {
|
||||
kimi: {
|
||||
headers: {
|
||||
"User-Agent": "custom-kimi-client/1.0",
|
||||
"X-Kimi-Tenant": "tenant-a",
|
||||
@ -1156,8 +1156,9 @@ describe("resolveModel", () => {
|
||||
},
|
||||
} as unknown as OpenClawConfig;
|
||||
|
||||
const result = resolveModel("kimi-coding", "k2p5", "/tmp/agent", cfg);
|
||||
const result = resolveModel("kimi", "kimi-code", "/tmp/agent", cfg);
|
||||
expect(result.error).toBeUndefined();
|
||||
expect(result.model?.id).toBe("kimi-for-coding");
|
||||
expect((result.model as unknown as { headers?: Record<string, string> }).headers).toEqual({
|
||||
"User-Agent": "custom-kimi-client/1.0",
|
||||
"X-Kimi-Tenant": "tenant-a",
|
||||
|
||||
@ -1009,7 +1009,7 @@ function wrapStreamRepairMalformedToolCallArguments(
|
||||
if (!loggedRepairIndices.has(event.contentIndex)) {
|
||||
loggedRepairIndices.add(event.contentIndex);
|
||||
log.warn(
|
||||
`repairing kimi-coding tool call arguments after ${repair.trailingSuffix.length} trailing chars`,
|
||||
`repairing Kimi tool call arguments after ${repair.trailingSuffix.length} trailing chars`,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
@ -1064,7 +1064,7 @@ export function wrapStreamFnRepairMalformedToolCallArguments(baseFn: StreamFn):
|
||||
}
|
||||
|
||||
function shouldRepairMalformedAnthropicToolCallArguments(provider?: string): boolean {
|
||||
return normalizeProviderId(provider ?? "") === "kimi-coding";
|
||||
return normalizeProviderId(provider ?? "") === "kimi";
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@ -30,7 +30,7 @@ const resolveProviderCapabilitiesWithPluginMock = vi.fn((params: { provider: str
|
||||
geminiThoughtSignatureSanitization: true,
|
||||
geminiThoughtSignatureModelHints: ["gemini"],
|
||||
};
|
||||
case "kimi-coding":
|
||||
case "kimi":
|
||||
return {
|
||||
preserveAnthropicThinkingSignatures: false,
|
||||
};
|
||||
@ -84,9 +84,7 @@ describe("resolveProviderCapabilities", () => {
|
||||
});
|
||||
|
||||
it("normalizes kimi aliases to the same capability set", () => {
|
||||
expect(resolveProviderCapabilities("kimi-coding")).toEqual(
|
||||
resolveProviderCapabilities("kimi-code"),
|
||||
);
|
||||
expect(resolveProviderCapabilities("kimi")).toEqual(resolveProviderCapabilities("kimi-code"));
|
||||
expect(resolveProviderCapabilities("kimi-code")).toEqual({
|
||||
anthropicToolSchemaMode: "native",
|
||||
anthropicToolChoiceMode: "native",
|
||||
@ -131,7 +129,7 @@ describe("resolveProviderCapabilities", () => {
|
||||
});
|
||||
|
||||
it("treats kimi aliases as native anthropic tool payload providers", () => {
|
||||
expect(requiresOpenAiCompatibleAnthropicToolPayload("kimi-coding")).toBe(false);
|
||||
expect(requiresOpenAiCompatibleAnthropicToolPayload("kimi")).toBe(false);
|
||||
expect(requiresOpenAiCompatibleAnthropicToolPayload("kimi-code")).toBe(false);
|
||||
expect(requiresOpenAiCompatibleAnthropicToolPayload("anthropic")).toBe(false);
|
||||
});
|
||||
|
||||
@ -12,11 +12,8 @@ export function normalizeProviderId(provider: string): string {
|
||||
if (normalized === "qwen") {
|
||||
return "qwen-portal";
|
||||
}
|
||||
if (normalized === "kimi-code") {
|
||||
return "kimi-coding";
|
||||
}
|
||||
if (normalized === "kimi") {
|
||||
return "kimi-coding";
|
||||
if (normalized === "kimi" || normalized === "kimi-code" || normalized === "kimi-coding") {
|
||||
return "kimi";
|
||||
}
|
||||
if (normalized === "bedrock" || normalized === "aws-bedrock") {
|
||||
return "amazon-bedrock";
|
||||
|
||||
@ -114,16 +114,16 @@ describe("resolveTranscriptPolicy", () => {
|
||||
preserveSignatures: false,
|
||||
},
|
||||
{
|
||||
title: "kimi-coding provider",
|
||||
provider: "kimi-coding",
|
||||
modelId: "k2p5",
|
||||
title: "Kimi provider",
|
||||
provider: "kimi",
|
||||
modelId: "kimi-code",
|
||||
modelApi: "anthropic-messages" as const,
|
||||
preserveSignatures: false,
|
||||
},
|
||||
{
|
||||
title: "kimi-code alias",
|
||||
provider: "kimi-code",
|
||||
modelId: "k2p5",
|
||||
modelId: "kimi-code",
|
||||
modelApi: "anthropic-messages" as const,
|
||||
preserveSignatures: false,
|
||||
},
|
||||
|
||||
@ -6,7 +6,7 @@ vi.mock("../../agents/model-catalog.js", () => ({
|
||||
loadModelCatalog: vi.fn(async () => [
|
||||
{ provider: "anthropic", id: "claude-opus-4-5", name: "Claude Opus 4.5" },
|
||||
{ provider: "inferencer", id: "deepseek-v3-4bit-mlx", name: "DeepSeek V3" },
|
||||
{ provider: "kimi-coding", id: "k2p5", name: "Kimi K2.5" },
|
||||
{ provider: "kimi", id: "kimi-code", name: "Kimi Code" },
|
||||
{ provider: "openai", id: "gpt-4o-mini", name: "GPT-4o mini" },
|
||||
{ provider: "openai", id: "gpt-4o", name: "GPT-4o" },
|
||||
]),
|
||||
@ -222,12 +222,12 @@ describe("createModelSelectionState respects session model override", () => {
|
||||
const state = await resolveState(
|
||||
makeEntry({
|
||||
providerOverride: "kimi-coding",
|
||||
modelOverride: "k2p5",
|
||||
modelOverride: "kimi-code",
|
||||
}),
|
||||
);
|
||||
|
||||
expect(state.provider).toBe("kimi-coding");
|
||||
expect(state.model).toBe("k2p5");
|
||||
expect(state.provider).toBe("kimi");
|
||||
expect(state.model).toBe("kimi-code");
|
||||
});
|
||||
|
||||
it("falls back to default when no modelOverride is set", async () => {
|
||||
@ -241,8 +241,8 @@ describe("createModelSelectionState respects session model override", () => {
|
||||
// From issue #14783: stored override should beat last-used fallback model.
|
||||
const state = await resolveState(
|
||||
makeEntry({
|
||||
model: "k2p5",
|
||||
modelProvider: "kimi-coding",
|
||||
model: "kimi-code",
|
||||
modelProvider: "kimi",
|
||||
contextTokens: 262_000,
|
||||
providerOverride: "anthropic",
|
||||
modelOverride: "claude-opus-4-5",
|
||||
|
||||
@ -520,9 +520,9 @@ describe("applyAuthChoice", () => {
|
||||
{
|
||||
tokenProvider: "KIMI-CODING",
|
||||
token: "sk-kimi-token-provider-test",
|
||||
profileId: "kimi-coding:default",
|
||||
provider: "kimi-coding",
|
||||
expectedModelPrefix: "kimi-coding/",
|
||||
profileId: "kimi:default",
|
||||
provider: "kimi",
|
||||
expectedModelPrefix: "kimi/",
|
||||
},
|
||||
{
|
||||
tokenProvider: " GOOGLE ",
|
||||
@ -600,9 +600,9 @@ describe("applyAuthChoice", () => {
|
||||
{
|
||||
authChoice: "kimi-code-api-key",
|
||||
tokenProvider: "kimi-code",
|
||||
profileId: "kimi-coding:default",
|
||||
provider: "kimi-coding",
|
||||
modelPrefix: "kimi-coding/",
|
||||
profileId: "kimi:default",
|
||||
provider: "kimi",
|
||||
modelPrefix: "kimi/",
|
||||
},
|
||||
{
|
||||
authChoice: "xiaomi-api-key",
|
||||
|
||||
189
src/commands/auth-credentials.ts
Normal file
189
src/commands/auth-credentials.ts
Normal file
@ -0,0 +1,189 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import type { OAuthCredentials } from "@mariozechner/pi-ai";
|
||||
import { resolveOpenClawAgentDir } from "../agents/agent-paths.js";
|
||||
import { upsertAuthProfile } from "../agents/auth-profiles.js";
|
||||
import { resolveStateDir } from "../config/paths.js";
|
||||
import {
|
||||
coerceSecretRef,
|
||||
DEFAULT_SECRET_PROVIDER_ALIAS,
|
||||
type SecretInput,
|
||||
type SecretRef,
|
||||
} from "../config/types.secrets.js";
|
||||
import { PROVIDER_ENV_VARS } from "../secrets/provider-env-vars.js";
|
||||
import { normalizeSecretInput } from "../utils/normalize-secret-input.js";
|
||||
import type { SecretInputMode } from "./onboard-types.js";
|
||||
|
||||
const ENV_REF_PATTERN = /^\$\{([A-Z][A-Z0-9_]*)\}$/;
|
||||
|
||||
const resolveAuthAgentDir = (agentDir?: string) => agentDir ?? resolveOpenClawAgentDir();
|
||||
|
||||
export type ApiKeyStorageOptions = {
|
||||
secretInputMode?: SecretInputMode;
|
||||
};
|
||||
|
||||
export type WriteOAuthCredentialsOptions = {
|
||||
syncSiblingAgents?: boolean;
|
||||
};
|
||||
|
||||
function buildEnvSecretRef(id: string): SecretRef {
|
||||
return { source: "env", provider: DEFAULT_SECRET_PROVIDER_ALIAS, id };
|
||||
}
|
||||
|
||||
function parseEnvSecretRef(value: string): SecretRef | null {
|
||||
const match = ENV_REF_PATTERN.exec(value);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
return buildEnvSecretRef(match[1]);
|
||||
}
|
||||
|
||||
function resolveProviderDefaultEnvSecretRef(provider: string): SecretRef {
|
||||
const envVars = PROVIDER_ENV_VARS[provider];
|
||||
const envVar = envVars?.find((candidate) => candidate.trim().length > 0);
|
||||
if (!envVar) {
|
||||
throw new Error(
|
||||
`Provider "${provider}" does not have a default env var mapping for secret-input-mode=ref.`,
|
||||
);
|
||||
}
|
||||
return buildEnvSecretRef(envVar);
|
||||
}
|
||||
|
||||
function resolveApiKeySecretInput(
|
||||
provider: string,
|
||||
input: SecretInput,
|
||||
options?: ApiKeyStorageOptions,
|
||||
): SecretInput {
|
||||
const coercedRef = coerceSecretRef(input);
|
||||
if (coercedRef) {
|
||||
return coercedRef;
|
||||
}
|
||||
const normalized = normalizeSecretInput(input);
|
||||
const inlineEnvRef = parseEnvSecretRef(normalized);
|
||||
if (inlineEnvRef) {
|
||||
return inlineEnvRef;
|
||||
}
|
||||
if (options?.secretInputMode === "ref") {
|
||||
return resolveProviderDefaultEnvSecretRef(provider);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
export function buildApiKeyCredential(
|
||||
provider: string,
|
||||
input: SecretInput,
|
||||
metadata?: Record<string, string>,
|
||||
options?: ApiKeyStorageOptions,
|
||||
): {
|
||||
type: "api_key";
|
||||
provider: string;
|
||||
key?: string;
|
||||
keyRef?: SecretRef;
|
||||
metadata?: Record<string, string>;
|
||||
} {
|
||||
const secretInput = resolveApiKeySecretInput(provider, input, options);
|
||||
if (typeof secretInput === "string") {
|
||||
return {
|
||||
type: "api_key",
|
||||
provider,
|
||||
key: secretInput,
|
||||
...(metadata ? { metadata } : {}),
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: "api_key",
|
||||
provider,
|
||||
keyRef: secretInput,
|
||||
...(metadata ? { metadata } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
/** Resolve real path, returning null if the target doesn't exist. */
|
||||
function safeRealpathSync(dir: string): string | null {
|
||||
try {
|
||||
return fs.realpathSync(path.resolve(dir));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function resolveSiblingAgentDirs(primaryAgentDir: string): string[] {
|
||||
const normalized = path.resolve(primaryAgentDir);
|
||||
const parentOfAgent = path.dirname(normalized);
|
||||
const candidateAgentsRoot = path.dirname(parentOfAgent);
|
||||
const looksLikeStandardLayout =
|
||||
path.basename(normalized) === "agent" && path.basename(candidateAgentsRoot) === "agents";
|
||||
|
||||
const agentsRoot = looksLikeStandardLayout
|
||||
? candidateAgentsRoot
|
||||
: path.join(resolveStateDir(), "agents");
|
||||
|
||||
const entries = (() => {
|
||||
try {
|
||||
return fs.readdirSync(agentsRoot, { withFileTypes: true });
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
})();
|
||||
const discovered = entries
|
||||
.filter((entry) => entry.isDirectory() || entry.isSymbolicLink())
|
||||
.map((entry) => path.join(agentsRoot, entry.name, "agent"));
|
||||
|
||||
const seen = new Set<string>();
|
||||
const result: string[] = [];
|
||||
for (const dir of [normalized, ...discovered]) {
|
||||
const real = safeRealpathSync(dir);
|
||||
if (real && !seen.has(real)) {
|
||||
seen.add(real);
|
||||
result.push(real);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function writeOAuthCredentials(
|
||||
provider: string,
|
||||
creds: OAuthCredentials,
|
||||
agentDir?: string,
|
||||
options?: WriteOAuthCredentialsOptions,
|
||||
): Promise<string> {
|
||||
const email =
|
||||
typeof creds.email === "string" && creds.email.trim() ? creds.email.trim() : "default";
|
||||
const profileId = `${provider}:${email}`;
|
||||
const resolvedAgentDir = path.resolve(resolveAuthAgentDir(agentDir));
|
||||
const targetAgentDirs = options?.syncSiblingAgents
|
||||
? resolveSiblingAgentDirs(resolvedAgentDir)
|
||||
: [resolvedAgentDir];
|
||||
|
||||
const credential = {
|
||||
type: "oauth" as const,
|
||||
provider,
|
||||
...creds,
|
||||
};
|
||||
|
||||
upsertAuthProfile({
|
||||
profileId,
|
||||
credential,
|
||||
agentDir: resolvedAgentDir,
|
||||
});
|
||||
|
||||
if (options?.syncSiblingAgents) {
|
||||
const primaryReal = safeRealpathSync(resolvedAgentDir);
|
||||
for (const targetAgentDir of targetAgentDirs) {
|
||||
const targetReal = safeRealpathSync(targetAgentDir);
|
||||
if (targetReal && primaryReal && targetReal === primaryReal) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
upsertAuthProfile({
|
||||
profileId,
|
||||
credential,
|
||||
agentDir: targetAgentDir,
|
||||
});
|
||||
} catch {
|
||||
// Best-effort: sibling sync failure must not block primary setup.
|
||||
}
|
||||
}
|
||||
}
|
||||
return profileId;
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
import { normalizeProviderIdForAuth } from "../agents/provider-id.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
|
||||
export function applyAuthProfileConfig(
|
||||
@ -10,7 +11,7 @@ export function applyAuthProfileConfig(
|
||||
preferProfileFirst?: boolean;
|
||||
},
|
||||
): OpenClawConfig {
|
||||
const normalizedProvider = params.provider.toLowerCase();
|
||||
const normalizedProvider = normalizeProviderIdForAuth(params.provider);
|
||||
const profiles = {
|
||||
...cfg.auth?.profiles,
|
||||
[params.profileId]: {
|
||||
@ -21,7 +22,7 @@ export function applyAuthProfileConfig(
|
||||
};
|
||||
|
||||
const configuredProviderProfiles = Object.entries(cfg.auth?.profiles ?? {})
|
||||
.filter(([, profile]) => profile.provider.toLowerCase() === normalizedProvider)
|
||||
.filter(([, profile]) => normalizeProviderIdForAuth(profile.provider) === normalizedProvider)
|
||||
.map(([profileId, profile]) => ({ profileId, mode: profile.mode }));
|
||||
|
||||
// Maintain `auth.order` when it already exists. Additionally, if we detect
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import { findNormalizedProviderKey } from "../agents/provider-id.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { AgentModelEntryConfig } from "../config/types.agent-defaults.js";
|
||||
import type {
|
||||
@ -159,10 +160,17 @@ function resolveProviderModelMergeState(
|
||||
providerId: string,
|
||||
): ProviderModelMergeState {
|
||||
const providers = { ...cfg.models?.providers } as Record<string, ModelProviderConfig>;
|
||||
const existingProvider = providers[providerId] as ModelProviderConfig | undefined;
|
||||
const existingProviderKey = findNormalizedProviderKey(providers, providerId);
|
||||
const existingProvider =
|
||||
existingProviderKey !== undefined
|
||||
? (providers[existingProviderKey] as ModelProviderConfig | undefined)
|
||||
: undefined;
|
||||
const existingModels: ModelDefinitionConfig[] = Array.isArray(existingProvider?.models)
|
||||
? existingProvider.models
|
||||
: [];
|
||||
if (existingProviderKey && existingProviderKey !== providerId) {
|
||||
delete providers[existingProviderKey];
|
||||
}
|
||||
return { providers, existingProvider, existingModels };
|
||||
}
|
||||
|
||||
|
||||
@ -1,209 +1,27 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import type { OAuthCredentials } from "@mariozechner/pi-ai";
|
||||
import { resolveOpenClawAgentDir } from "../agents/agent-paths.js";
|
||||
import { upsertAuthProfile } from "../agents/auth-profiles.js";
|
||||
import { resolveStateDir } from "../config/paths.js";
|
||||
import {
|
||||
coerceSecretRef,
|
||||
DEFAULT_SECRET_PROVIDER_ALIAS,
|
||||
type SecretInput,
|
||||
type SecretRef,
|
||||
} from "../config/types.secrets.js";
|
||||
import type { SecretInput } from "../config/types.secrets.js";
|
||||
import { KILOCODE_DEFAULT_MODEL_REF } from "../providers/kilocode-shared.js";
|
||||
import { PROVIDER_ENV_VARS } from "../secrets/provider-env-vars.js";
|
||||
import { normalizeSecretInput } from "../utils/normalize-secret-input.js";
|
||||
import type { SecretInputMode } from "./onboard-types.js";
|
||||
import {
|
||||
buildApiKeyCredential,
|
||||
type ApiKeyStorageOptions,
|
||||
writeOAuthCredentials,
|
||||
type WriteOAuthCredentialsOptions,
|
||||
} from "./auth-credentials.js";
|
||||
export { CLOUDFLARE_AI_GATEWAY_DEFAULT_MODEL_REF } from "../agents/cloudflare-ai-gateway.js";
|
||||
export {
|
||||
MISTRAL_DEFAULT_MODEL_REF,
|
||||
XAI_DEFAULT_MODEL_REF,
|
||||
MODELSTUDIO_DEFAULT_MODEL_REF,
|
||||
} from "./onboard-auth.models.js";
|
||||
export { MISTRAL_DEFAULT_MODEL_REF } from "../../extensions/mistral/onboard.js";
|
||||
export { MODELSTUDIO_DEFAULT_MODEL_REF } from "../../extensions/modelstudio/onboard.js";
|
||||
export { XAI_DEFAULT_MODEL_REF } from "../../extensions/xai/onboard.js";
|
||||
export { KILOCODE_DEFAULT_MODEL_REF };
|
||||
export {
|
||||
buildApiKeyCredential,
|
||||
type ApiKeyStorageOptions,
|
||||
writeOAuthCredentials,
|
||||
type WriteOAuthCredentialsOptions,
|
||||
};
|
||||
|
||||
const resolveAuthAgentDir = (agentDir?: string) => agentDir ?? resolveOpenClawAgentDir();
|
||||
|
||||
const ENV_REF_PATTERN = /^\$\{([A-Z][A-Z0-9_]*)\}$/;
|
||||
|
||||
export type ApiKeyStorageOptions = {
|
||||
secretInputMode?: SecretInputMode;
|
||||
};
|
||||
|
||||
function buildEnvSecretRef(id: string): SecretRef {
|
||||
return { source: "env", provider: DEFAULT_SECRET_PROVIDER_ALIAS, id };
|
||||
}
|
||||
|
||||
function parseEnvSecretRef(value: string): SecretRef | null {
|
||||
const match = ENV_REF_PATTERN.exec(value);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
return buildEnvSecretRef(match[1]);
|
||||
}
|
||||
|
||||
function resolveProviderDefaultEnvSecretRef(provider: string): SecretRef {
|
||||
const envVars = PROVIDER_ENV_VARS[provider];
|
||||
const envVar = envVars?.find((candidate) => candidate.trim().length > 0);
|
||||
if (!envVar) {
|
||||
throw new Error(
|
||||
`Provider "${provider}" does not have a default env var mapping for secret-input-mode=ref.`,
|
||||
);
|
||||
}
|
||||
return buildEnvSecretRef(envVar);
|
||||
}
|
||||
|
||||
function resolveApiKeySecretInput(
|
||||
provider: string,
|
||||
input: SecretInput,
|
||||
options?: ApiKeyStorageOptions,
|
||||
): SecretInput {
|
||||
const coercedRef = coerceSecretRef(input);
|
||||
if (coercedRef) {
|
||||
return coercedRef;
|
||||
}
|
||||
const normalized = normalizeSecretInput(input);
|
||||
const inlineEnvRef = parseEnvSecretRef(normalized);
|
||||
if (inlineEnvRef) {
|
||||
return inlineEnvRef;
|
||||
}
|
||||
const useSecretRefMode = options?.secretInputMode === "ref"; // pragma: allowlist secret
|
||||
if (useSecretRefMode) {
|
||||
return resolveProviderDefaultEnvSecretRef(provider);
|
||||
}
|
||||
return normalized;
|
||||
}
|
||||
|
||||
export function buildApiKeyCredential(
|
||||
provider: string,
|
||||
input: SecretInput,
|
||||
metadata?: Record<string, string>,
|
||||
options?: ApiKeyStorageOptions,
|
||||
): {
|
||||
type: "api_key";
|
||||
provider: string;
|
||||
key?: string;
|
||||
keyRef?: SecretRef;
|
||||
metadata?: Record<string, string>;
|
||||
} {
|
||||
const secretInput = resolveApiKeySecretInput(provider, input, options);
|
||||
if (typeof secretInput === "string") {
|
||||
return {
|
||||
type: "api_key",
|
||||
provider,
|
||||
key: secretInput,
|
||||
...(metadata ? { metadata } : {}),
|
||||
};
|
||||
}
|
||||
return {
|
||||
type: "api_key",
|
||||
provider,
|
||||
keyRef: secretInput,
|
||||
...(metadata ? { metadata } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
export type WriteOAuthCredentialsOptions = {
|
||||
syncSiblingAgents?: boolean;
|
||||
};
|
||||
|
||||
/** Resolve real path, returning null if the target doesn't exist. */
|
||||
function safeRealpathSync(dir: string): string | null {
|
||||
try {
|
||||
return fs.realpathSync(path.resolve(dir));
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function resolveSiblingAgentDirs(primaryAgentDir: string): string[] {
|
||||
const normalized = path.resolve(primaryAgentDir);
|
||||
|
||||
// Derive agentsRoot from primaryAgentDir when it matches the standard
|
||||
// layout (.../agents/<name>/agent). Falls back to global state dir.
|
||||
const parentOfAgent = path.dirname(normalized);
|
||||
const candidateAgentsRoot = path.dirname(parentOfAgent);
|
||||
const looksLikeStandardLayout =
|
||||
path.basename(normalized) === "agent" && path.basename(candidateAgentsRoot) === "agents";
|
||||
|
||||
const agentsRoot = looksLikeStandardLayout
|
||||
? candidateAgentsRoot
|
||||
: path.join(resolveStateDir(), "agents");
|
||||
|
||||
const entries = (() => {
|
||||
try {
|
||||
return fs.readdirSync(agentsRoot, { withFileTypes: true });
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
})();
|
||||
// Include both directories and symlinks-to-directories.
|
||||
const discovered = entries
|
||||
.filter((entry) => entry.isDirectory() || entry.isSymbolicLink())
|
||||
.map((entry) => path.join(agentsRoot, entry.name, "agent"));
|
||||
|
||||
// Deduplicate via realpath to handle symlinks and path normalization.
|
||||
const seen = new Set<string>();
|
||||
const result: string[] = [];
|
||||
for (const dir of [normalized, ...discovered]) {
|
||||
const real = safeRealpathSync(dir);
|
||||
if (real && !seen.has(real)) {
|
||||
seen.add(real);
|
||||
result.push(real);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function writeOAuthCredentials(
|
||||
provider: string,
|
||||
creds: OAuthCredentials,
|
||||
agentDir?: string,
|
||||
options?: WriteOAuthCredentialsOptions,
|
||||
): Promise<string> {
|
||||
const email =
|
||||
typeof creds.email === "string" && creds.email.trim() ? creds.email.trim() : "default";
|
||||
const profileId = `${provider}:${email}`;
|
||||
const resolvedAgentDir = path.resolve(resolveAuthAgentDir(agentDir));
|
||||
const targetAgentDirs = options?.syncSiblingAgents
|
||||
? resolveSiblingAgentDirs(resolvedAgentDir)
|
||||
: [resolvedAgentDir];
|
||||
|
||||
const credential = {
|
||||
type: "oauth" as const,
|
||||
provider,
|
||||
...creds,
|
||||
};
|
||||
|
||||
// Primary write must succeed — let it throw on failure.
|
||||
upsertAuthProfile({
|
||||
profileId,
|
||||
credential,
|
||||
agentDir: resolvedAgentDir,
|
||||
});
|
||||
|
||||
// Sibling sync is best-effort — log and ignore individual failures.
|
||||
if (options?.syncSiblingAgents) {
|
||||
const primaryReal = safeRealpathSync(resolvedAgentDir);
|
||||
for (const targetAgentDir of targetAgentDirs) {
|
||||
const targetReal = safeRealpathSync(targetAgentDir);
|
||||
if (targetReal && primaryReal && targetReal === primaryReal) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
upsertAuthProfile({
|
||||
profileId,
|
||||
credential,
|
||||
agentDir: targetAgentDir,
|
||||
});
|
||||
} catch {
|
||||
// Best-effort: sibling sync failure must not block primary setup.
|
||||
}
|
||||
}
|
||||
}
|
||||
return profileId;
|
||||
}
|
||||
|
||||
export async function setAnthropicApiKey(
|
||||
key: SecretInput,
|
||||
agentDir?: string,
|
||||
@ -277,8 +95,8 @@ export async function setKimiCodingApiKey(
|
||||
) {
|
||||
// Write to resolved agent dir so gateway finds credentials on startup.
|
||||
upsertAuthProfile({
|
||||
profileId: "kimi-coding:default",
|
||||
credential: buildApiKeyCredential("kimi-coding", key, undefined, options),
|
||||
profileId: "kimi:default",
|
||||
credential: buildApiKeyCredential("kimi", key, undefined, options),
|
||||
agentDir: resolveAuthAgentDir(agentDir),
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,8 +1,68 @@
|
||||
import { KIMI_CODING_MODEL_REF } from "../../extensions/kimi-coding/onboard.js";
|
||||
import {
|
||||
KIMI_DEFAULT_MODEL_ID as KIMI_CODING_MODEL_ID,
|
||||
KIMI_CODING_BASE_URL,
|
||||
} from "../../extensions/kimi-coding/provider-catalog.js";
|
||||
import {
|
||||
DEFAULT_MINIMAX_BASE_URL,
|
||||
MINIMAX_API_BASE_URL,
|
||||
MINIMAX_API_COST,
|
||||
MINIMAX_CN_API_BASE_URL,
|
||||
MINIMAX_HOSTED_COST,
|
||||
MINIMAX_HOSTED_MODEL_ID,
|
||||
MINIMAX_HOSTED_MODEL_REF,
|
||||
MINIMAX_LM_STUDIO_COST,
|
||||
buildMinimaxApiModelDefinition,
|
||||
buildMinimaxModelDefinition,
|
||||
} from "../../extensions/minimax/model-definitions.js";
|
||||
import {
|
||||
buildMistralModelDefinition,
|
||||
MISTRAL_BASE_URL,
|
||||
MISTRAL_DEFAULT_COST,
|
||||
MISTRAL_DEFAULT_MODEL_ID,
|
||||
MISTRAL_DEFAULT_MODEL_REF,
|
||||
} from "../../extensions/mistral/model-definitions.js";
|
||||
import {
|
||||
MODELSTUDIO_CN_BASE_URL,
|
||||
MODELSTUDIO_DEFAULT_COST,
|
||||
MODELSTUDIO_DEFAULT_MODEL_ID,
|
||||
MODELSTUDIO_DEFAULT_MODEL_REF,
|
||||
MODELSTUDIO_GLOBAL_BASE_URL,
|
||||
buildModelStudioDefaultModelDefinition,
|
||||
buildModelStudioModelDefinition,
|
||||
} from "../../extensions/modelstudio/model-definitions.js";
|
||||
import {
|
||||
MOONSHOT_CN_BASE_URL,
|
||||
MOONSHOT_DEFAULT_MODEL_REF,
|
||||
} from "../../extensions/moonshot/onboard.js";
|
||||
import {
|
||||
buildMoonshotProvider,
|
||||
MOONSHOT_BASE_URL,
|
||||
MOONSHOT_DEFAULT_MODEL_ID,
|
||||
} from "../../extensions/moonshot/provider-catalog.js";
|
||||
import { QIANFAN_DEFAULT_MODEL_REF } from "../../extensions/qianfan/onboard.js";
|
||||
import {
|
||||
QIANFAN_BASE_URL,
|
||||
QIANFAN_DEFAULT_MODEL_ID,
|
||||
} from "../../extensions/qianfan/provider-catalog.js";
|
||||
import type { ModelDefinitionConfig } from "../config/types.js";
|
||||
import {
|
||||
XAI_BASE_URL,
|
||||
XAI_DEFAULT_COST,
|
||||
XAI_DEFAULT_MODEL_ID,
|
||||
XAI_DEFAULT_MODEL_REF,
|
||||
buildXaiModelDefinition,
|
||||
} from "../../extensions/xai/model-definitions.js";
|
||||
import {
|
||||
buildZaiModelDefinition,
|
||||
resolveZaiBaseUrl,
|
||||
ZAI_CN_BASE_URL,
|
||||
ZAI_CODING_CN_BASE_URL,
|
||||
ZAI_CODING_GLOBAL_BASE_URL,
|
||||
ZAI_DEFAULT_COST,
|
||||
ZAI_DEFAULT_MODEL_ID,
|
||||
ZAI_GLOBAL_BASE_URL,
|
||||
} from "../../extensions/zai/model-definitions.js";
|
||||
import type { ModelDefinitionConfig } from "../config/types.models.js";
|
||||
import {
|
||||
KILOCODE_DEFAULT_CONTEXT_WINDOW,
|
||||
KILOCODE_DEFAULT_COST,
|
||||
@ -10,211 +70,61 @@ import {
|
||||
KILOCODE_DEFAULT_MODEL_ID,
|
||||
KILOCODE_DEFAULT_MODEL_NAME,
|
||||
} from "../providers/kilocode-shared.js";
|
||||
|
||||
export {
|
||||
DEFAULT_MINIMAX_BASE_URL,
|
||||
MINIMAX_API_BASE_URL,
|
||||
MINIMAX_API_COST,
|
||||
MINIMAX_CN_API_BASE_URL,
|
||||
MINIMAX_HOSTED_COST,
|
||||
MINIMAX_HOSTED_MODEL_ID,
|
||||
MINIMAX_HOSTED_MODEL_REF,
|
||||
MINIMAX_LM_STUDIO_COST,
|
||||
MISTRAL_BASE_URL,
|
||||
MISTRAL_DEFAULT_COST,
|
||||
MISTRAL_DEFAULT_MODEL_ID,
|
||||
MISTRAL_DEFAULT_MODEL_REF,
|
||||
MODELSTUDIO_CN_BASE_URL,
|
||||
MODELSTUDIO_DEFAULT_COST,
|
||||
MODELSTUDIO_DEFAULT_MODEL_ID,
|
||||
MODELSTUDIO_DEFAULT_MODEL_REF,
|
||||
MODELSTUDIO_GLOBAL_BASE_URL,
|
||||
MOONSHOT_BASE_URL,
|
||||
MOONSHOT_CN_BASE_URL,
|
||||
MOONSHOT_DEFAULT_MODEL_ID,
|
||||
MOONSHOT_DEFAULT_MODEL_REF,
|
||||
QIANFAN_BASE_URL,
|
||||
QIANFAN_DEFAULT_MODEL_ID,
|
||||
QIANFAN_DEFAULT_MODEL_REF,
|
||||
XAI_BASE_URL,
|
||||
XAI_DEFAULT_COST,
|
||||
XAI_DEFAULT_MODEL_ID,
|
||||
XAI_DEFAULT_MODEL_REF,
|
||||
ZAI_CN_BASE_URL,
|
||||
ZAI_CODING_CN_BASE_URL,
|
||||
ZAI_CODING_GLOBAL_BASE_URL,
|
||||
ZAI_DEFAULT_COST,
|
||||
ZAI_DEFAULT_MODEL_ID,
|
||||
ZAI_GLOBAL_BASE_URL,
|
||||
KIMI_CODING_BASE_URL,
|
||||
KIMI_CODING_MODEL_ID,
|
||||
KIMI_CODING_MODEL_REF,
|
||||
KILOCODE_DEFAULT_CONTEXT_WINDOW,
|
||||
KILOCODE_DEFAULT_COST,
|
||||
KILOCODE_DEFAULT_MAX_TOKENS,
|
||||
KILOCODE_DEFAULT_MODEL_ID,
|
||||
buildMinimaxApiModelDefinition,
|
||||
buildMinimaxModelDefinition,
|
||||
buildMistralModelDefinition,
|
||||
buildModelStudioDefaultModelDefinition,
|
||||
buildModelStudioModelDefinition,
|
||||
buildXaiModelDefinition,
|
||||
buildZaiModelDefinition,
|
||||
resolveZaiBaseUrl,
|
||||
};
|
||||
|
||||
export const DEFAULT_MINIMAX_BASE_URL = "https://api.minimax.io/v1";
|
||||
export const MINIMAX_API_BASE_URL = "https://api.minimax.io/anthropic";
|
||||
export const MINIMAX_CN_API_BASE_URL = "https://api.minimaxi.com/anthropic";
|
||||
export const MINIMAX_HOSTED_MODEL_ID = "MiniMax-M2.5";
|
||||
export const MINIMAX_HOSTED_MODEL_REF = `minimax/${MINIMAX_HOSTED_MODEL_ID}`;
|
||||
export const DEFAULT_MINIMAX_CONTEXT_WINDOW = 200000;
|
||||
export const DEFAULT_MINIMAX_MAX_TOKENS = 8192;
|
||||
|
||||
export const MOONSHOT_BASE_URL = "https://api.moonshot.ai/v1";
|
||||
export const MOONSHOT_CN_BASE_URL = "https://api.moonshot.cn/v1";
|
||||
export const MOONSHOT_DEFAULT_MODEL_ID = "kimi-k2.5";
|
||||
export const MOONSHOT_DEFAULT_MODEL_REF = `moonshot/${MOONSHOT_DEFAULT_MODEL_ID}`;
|
||||
export const MOONSHOT_DEFAULT_CONTEXT_WINDOW = 256000;
|
||||
export const MOONSHOT_DEFAULT_MAX_TOKENS = 8192;
|
||||
export const KIMI_CODING_MODEL_ID = "k2p5";
|
||||
export const KIMI_CODING_MODEL_REF = `kimi-coding/${KIMI_CODING_MODEL_ID}`;
|
||||
|
||||
export { QIANFAN_BASE_URL, QIANFAN_DEFAULT_MODEL_ID };
|
||||
export const QIANFAN_DEFAULT_MODEL_REF = `qianfan/${QIANFAN_DEFAULT_MODEL_ID}`;
|
||||
|
||||
export const ZAI_CODING_GLOBAL_BASE_URL = "https://api.z.ai/api/coding/paas/v4";
|
||||
export const ZAI_CODING_CN_BASE_URL = "https://open.bigmodel.cn/api/coding/paas/v4";
|
||||
export const ZAI_GLOBAL_BASE_URL = "https://api.z.ai/api/paas/v4";
|
||||
export const ZAI_CN_BASE_URL = "https://open.bigmodel.cn/api/paas/v4";
|
||||
export const ZAI_DEFAULT_MODEL_ID = "glm-5";
|
||||
|
||||
export function resolveZaiBaseUrl(endpoint?: string): string {
|
||||
switch (endpoint) {
|
||||
case "coding-cn":
|
||||
return ZAI_CODING_CN_BASE_URL;
|
||||
case "global":
|
||||
return ZAI_GLOBAL_BASE_URL;
|
||||
case "cn":
|
||||
return ZAI_CN_BASE_URL;
|
||||
case "coding-global":
|
||||
return ZAI_CODING_GLOBAL_BASE_URL;
|
||||
default:
|
||||
return ZAI_GLOBAL_BASE_URL;
|
||||
}
|
||||
}
|
||||
|
||||
// Pricing per 1M tokens (USD) — https://platform.minimaxi.com/document/Price
|
||||
export const MINIMAX_API_COST = {
|
||||
input: 0.3,
|
||||
output: 1.2,
|
||||
cacheRead: 0.03,
|
||||
cacheWrite: 0.12,
|
||||
};
|
||||
export const MINIMAX_HOSTED_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
export const MINIMAX_LM_STUDIO_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
export const MOONSHOT_DEFAULT_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
export const ZAI_DEFAULT_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
const MINIMAX_MODEL_CATALOG = {
|
||||
"MiniMax-M2.5": { name: "MiniMax M2.5", reasoning: true },
|
||||
"MiniMax-M2.5-highspeed": { name: "MiniMax M2.5 Highspeed", reasoning: true },
|
||||
} as const;
|
||||
|
||||
type MinimaxCatalogId = keyof typeof MINIMAX_MODEL_CATALOG;
|
||||
|
||||
const ZAI_MODEL_CATALOG = {
|
||||
"glm-5": { name: "GLM-5", reasoning: true },
|
||||
"glm-5-turbo": { name: "GLM-5 Turbo", reasoning: true },
|
||||
"glm-4.7": { name: "GLM-4.7", reasoning: true },
|
||||
"glm-4.7-flash": { name: "GLM-4.7 Flash", reasoning: true },
|
||||
"glm-4.7-flashx": { name: "GLM-4.7 FlashX", reasoning: true },
|
||||
} as const;
|
||||
|
||||
type ZaiCatalogId = keyof typeof ZAI_MODEL_CATALOG;
|
||||
|
||||
export function buildMinimaxModelDefinition(params: {
|
||||
id: string;
|
||||
name?: string;
|
||||
reasoning?: boolean;
|
||||
cost: ModelDefinitionConfig["cost"];
|
||||
contextWindow: number;
|
||||
maxTokens: number;
|
||||
}): ModelDefinitionConfig {
|
||||
const catalog = MINIMAX_MODEL_CATALOG[params.id as MinimaxCatalogId];
|
||||
return {
|
||||
id: params.id,
|
||||
name: params.name ?? catalog?.name ?? `MiniMax ${params.id}`,
|
||||
reasoning: params.reasoning ?? catalog?.reasoning ?? false,
|
||||
input: ["text"],
|
||||
cost: params.cost,
|
||||
contextWindow: params.contextWindow,
|
||||
maxTokens: params.maxTokens,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildMinimaxApiModelDefinition(modelId: string): ModelDefinitionConfig {
|
||||
return buildMinimaxModelDefinition({
|
||||
id: modelId,
|
||||
cost: MINIMAX_API_COST,
|
||||
contextWindow: DEFAULT_MINIMAX_CONTEXT_WINDOW,
|
||||
maxTokens: DEFAULT_MINIMAX_MAX_TOKENS,
|
||||
});
|
||||
}
|
||||
|
||||
export function buildMoonshotModelDefinition(): ModelDefinitionConfig {
|
||||
return {
|
||||
id: MOONSHOT_DEFAULT_MODEL_ID,
|
||||
name: "Kimi K2.5",
|
||||
reasoning: false,
|
||||
input: ["text", "image"],
|
||||
cost: MOONSHOT_DEFAULT_COST,
|
||||
contextWindow: MOONSHOT_DEFAULT_CONTEXT_WINDOW,
|
||||
maxTokens: MOONSHOT_DEFAULT_MAX_TOKENS,
|
||||
};
|
||||
}
|
||||
|
||||
export const MISTRAL_BASE_URL = "https://api.mistral.ai/v1";
|
||||
export const MISTRAL_DEFAULT_MODEL_ID = "mistral-large-latest";
|
||||
export const MISTRAL_DEFAULT_MODEL_REF = `mistral/${MISTRAL_DEFAULT_MODEL_ID}`;
|
||||
export const MISTRAL_DEFAULT_CONTEXT_WINDOW = 262144;
|
||||
export const MISTRAL_DEFAULT_MAX_TOKENS = 262144;
|
||||
export const MISTRAL_DEFAULT_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
export function buildMistralModelDefinition(): ModelDefinitionConfig {
|
||||
return {
|
||||
id: MISTRAL_DEFAULT_MODEL_ID,
|
||||
name: "Mistral Large",
|
||||
reasoning: false,
|
||||
input: ["text", "image"],
|
||||
cost: MISTRAL_DEFAULT_COST,
|
||||
contextWindow: MISTRAL_DEFAULT_CONTEXT_WINDOW,
|
||||
maxTokens: MISTRAL_DEFAULT_MAX_TOKENS,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildZaiModelDefinition(params: {
|
||||
id: string;
|
||||
name?: string;
|
||||
reasoning?: boolean;
|
||||
cost?: ModelDefinitionConfig["cost"];
|
||||
contextWindow?: number;
|
||||
maxTokens?: number;
|
||||
}): ModelDefinitionConfig {
|
||||
const catalog = ZAI_MODEL_CATALOG[params.id as ZaiCatalogId];
|
||||
return {
|
||||
id: params.id,
|
||||
name: params.name ?? catalog?.name ?? `GLM ${params.id}`,
|
||||
reasoning: params.reasoning ?? catalog?.reasoning ?? true,
|
||||
input: ["text"],
|
||||
cost: params.cost ?? ZAI_DEFAULT_COST,
|
||||
contextWindow: params.contextWindow ?? 204800,
|
||||
maxTokens: params.maxTokens ?? 131072,
|
||||
};
|
||||
}
|
||||
|
||||
export const XAI_BASE_URL = "https://api.x.ai/v1";
|
||||
export const XAI_DEFAULT_MODEL_ID = "grok-4";
|
||||
export const XAI_DEFAULT_MODEL_REF = `xai/${XAI_DEFAULT_MODEL_ID}`;
|
||||
export const XAI_DEFAULT_CONTEXT_WINDOW = 131072;
|
||||
export const XAI_DEFAULT_MAX_TOKENS = 8192;
|
||||
export const XAI_DEFAULT_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
export function buildXaiModelDefinition(): ModelDefinitionConfig {
|
||||
return {
|
||||
id: XAI_DEFAULT_MODEL_ID,
|
||||
name: "Grok 4",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
cost: XAI_DEFAULT_COST,
|
||||
contextWindow: XAI_DEFAULT_CONTEXT_WINDOW,
|
||||
maxTokens: XAI_DEFAULT_MAX_TOKENS,
|
||||
};
|
||||
return buildMoonshotProvider().models[0];
|
||||
}
|
||||
|
||||
export function buildKilocodeModelDefinition(): ModelDefinitionConfig {
|
||||
@ -228,105 +138,3 @@ export function buildKilocodeModelDefinition(): ModelDefinitionConfig {
|
||||
maxTokens: KILOCODE_DEFAULT_MAX_TOKENS,
|
||||
};
|
||||
}
|
||||
|
||||
// Alibaba Cloud Model Studio Coding Plan
|
||||
export const MODELSTUDIO_CN_BASE_URL = "https://coding.dashscope.aliyuncs.com/v1";
|
||||
export const MODELSTUDIO_GLOBAL_BASE_URL = "https://coding-intl.dashscope.aliyuncs.com/v1";
|
||||
export const MODELSTUDIO_DEFAULT_MODEL_ID = "qwen3.5-plus";
|
||||
export const MODELSTUDIO_DEFAULT_MODEL_REF = `modelstudio/${MODELSTUDIO_DEFAULT_MODEL_ID}`;
|
||||
export const MODELSTUDIO_DEFAULT_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0,
|
||||
};
|
||||
|
||||
const MODELSTUDIO_MODEL_CATALOG = {
|
||||
"qwen3.5-plus": {
|
||||
name: "qwen3.5-plus",
|
||||
reasoning: false,
|
||||
input: ["text", "image"],
|
||||
contextWindow: 1000000,
|
||||
maxTokens: 65536,
|
||||
},
|
||||
"qwen3-max-2026-01-23": {
|
||||
name: "qwen3-max-2026-01-23",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
contextWindow: 262144,
|
||||
maxTokens: 65536,
|
||||
},
|
||||
"qwen3-coder-next": {
|
||||
name: "qwen3-coder-next",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
contextWindow: 262144,
|
||||
maxTokens: 65536,
|
||||
},
|
||||
"qwen3-coder-plus": {
|
||||
name: "qwen3-coder-plus",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
contextWindow: 1000000,
|
||||
maxTokens: 65536,
|
||||
},
|
||||
"MiniMax-M2.5": {
|
||||
name: "MiniMax-M2.5",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
contextWindow: 1000000,
|
||||
maxTokens: 65536,
|
||||
},
|
||||
"glm-5": {
|
||||
name: "glm-5",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
contextWindow: 202752,
|
||||
maxTokens: 16384,
|
||||
},
|
||||
"glm-4.7": {
|
||||
name: "glm-4.7",
|
||||
reasoning: false,
|
||||
input: ["text"],
|
||||
contextWindow: 202752,
|
||||
maxTokens: 16384,
|
||||
},
|
||||
"kimi-k2.5": {
|
||||
name: "kimi-k2.5",
|
||||
reasoning: false,
|
||||
input: ["text", "image"],
|
||||
contextWindow: 262144,
|
||||
maxTokens: 32768,
|
||||
},
|
||||
} as const;
|
||||
|
||||
type ModelStudioCatalogId = keyof typeof MODELSTUDIO_MODEL_CATALOG;
|
||||
|
||||
export function buildModelStudioModelDefinition(params: {
|
||||
id: string;
|
||||
name?: string;
|
||||
reasoning?: boolean;
|
||||
input?: string[];
|
||||
cost?: ModelDefinitionConfig["cost"];
|
||||
contextWindow?: number;
|
||||
maxTokens?: number;
|
||||
}): ModelDefinitionConfig {
|
||||
const catalog = MODELSTUDIO_MODEL_CATALOG[params.id as ModelStudioCatalogId];
|
||||
return {
|
||||
id: params.id,
|
||||
name: params.name ?? catalog?.name ?? params.id,
|
||||
reasoning: params.reasoning ?? catalog?.reasoning ?? false,
|
||||
input:
|
||||
(params.input as ("text" | "image")[]) ??
|
||||
([...(catalog?.input ?? ["text"])] as ("text" | "image")[]),
|
||||
cost: params.cost ?? MODELSTUDIO_DEFAULT_COST,
|
||||
contextWindow: params.contextWindow ?? catalog?.contextWindow ?? 262144,
|
||||
maxTokens: params.maxTokens ?? catalog?.maxTokens ?? 65536,
|
||||
};
|
||||
}
|
||||
|
||||
export function buildModelStudioDefaultModelDefinition(): ModelDefinitionConfig {
|
||||
return buildModelStudioModelDefinition({
|
||||
id: MODELSTUDIO_DEFAULT_MODEL_ID,
|
||||
});
|
||||
}
|
||||
|
||||
@ -100,33 +100,50 @@ export { VERCEL_AI_GATEWAY_DEFAULT_MODEL_REF } from "../../extensions/vercel-ai-
|
||||
export { XAI_DEFAULT_MODEL_REF } from "../../extensions/xai/onboard.js";
|
||||
export { ZAI_DEFAULT_MODEL_REF } from "../../extensions/zai/onboard.js";
|
||||
export {
|
||||
buildKilocodeModelDefinition,
|
||||
buildMinimaxApiModelDefinition,
|
||||
buildMinimaxModelDefinition,
|
||||
buildMistralModelDefinition,
|
||||
buildMoonshotModelDefinition,
|
||||
buildZaiModelDefinition,
|
||||
DEFAULT_MINIMAX_BASE_URL,
|
||||
KILOCODE_DEFAULT_MODEL_ID,
|
||||
MOONSHOT_CN_BASE_URL,
|
||||
QIANFAN_BASE_URL,
|
||||
QIANFAN_DEFAULT_MODEL_ID,
|
||||
QIANFAN_DEFAULT_MODEL_REF,
|
||||
KIMI_CODING_MODEL_ID,
|
||||
KIMI_CODING_MODEL_REF,
|
||||
MINIMAX_API_BASE_URL,
|
||||
MINIMAX_CN_API_BASE_URL,
|
||||
MINIMAX_HOSTED_MODEL_ID,
|
||||
MINIMAX_HOSTED_MODEL_REF,
|
||||
MOONSHOT_BASE_URL,
|
||||
MOONSHOT_DEFAULT_MODEL_ID,
|
||||
MOONSHOT_DEFAULT_MODEL_REF,
|
||||
} from "../../extensions/minimax/model-definitions.js";
|
||||
export { KIMI_DEFAULT_MODEL_ID as KIMI_CODING_MODEL_ID } from "../../extensions/kimi-coding/provider-catalog.js";
|
||||
export { KIMI_CODING_MODEL_REF } from "../../extensions/kimi-coding/onboard.js";
|
||||
export {
|
||||
buildMistralModelDefinition,
|
||||
MISTRAL_BASE_URL,
|
||||
MISTRAL_DEFAULT_MODEL_ID,
|
||||
} from "../../extensions/mistral/model-definitions.js";
|
||||
export {
|
||||
MOONSHOT_BASE_URL,
|
||||
MOONSHOT_DEFAULT_MODEL_ID,
|
||||
} from "../../extensions/moonshot/provider-catalog.js";
|
||||
export {
|
||||
MOONSHOT_CN_BASE_URL,
|
||||
MOONSHOT_DEFAULT_MODEL_REF,
|
||||
} from "../../extensions/moonshot/onboard.js";
|
||||
export {
|
||||
QIANFAN_BASE_URL,
|
||||
QIANFAN_DEFAULT_MODEL_ID,
|
||||
} from "../../extensions/qianfan/provider-catalog.js";
|
||||
export { QIANFAN_DEFAULT_MODEL_REF } from "../../extensions/qianfan/onboard.js";
|
||||
export {
|
||||
buildXaiModelDefinition,
|
||||
XAI_BASE_URL,
|
||||
XAI_DEFAULT_MODEL_ID,
|
||||
} from "../../extensions/xai/model-definitions.js";
|
||||
export {
|
||||
buildZaiModelDefinition,
|
||||
resolveZaiBaseUrl,
|
||||
ZAI_CODING_CN_BASE_URL,
|
||||
ZAI_DEFAULT_MODEL_ID,
|
||||
ZAI_CODING_GLOBAL_BASE_URL,
|
||||
ZAI_CN_BASE_URL,
|
||||
ZAI_CODING_CN_BASE_URL,
|
||||
ZAI_CODING_GLOBAL_BASE_URL,
|
||||
ZAI_DEFAULT_MODEL_ID,
|
||||
ZAI_GLOBAL_BASE_URL,
|
||||
} from "../../extensions/zai/model-definitions.js";
|
||||
export {
|
||||
buildKilocodeModelDefinition,
|
||||
buildMoonshotModelDefinition,
|
||||
KILOCODE_DEFAULT_MODEL_ID,
|
||||
} from "./onboard-auth.models.js";
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import { fetchWithTimeout } from "../utils/fetch-timeout.js";
|
||||
import {
|
||||
ZAI_CN_BASE_URL,
|
||||
ZAI_CODING_CN_BASE_URL,
|
||||
ZAI_CODING_GLOBAL_BASE_URL,
|
||||
ZAI_GLOBAL_BASE_URL,
|
||||
} from "./onboard-auth.models.js";
|
||||
} from "../../extensions/zai/model-definitions.js";
|
||||
import { fetchWithTimeout } from "../utils/fetch-timeout.js";
|
||||
|
||||
export type ZaiEndpointId = "global" | "cn" | "coding-global" | "coding-cn";
|
||||
|
||||
|
||||
@ -63,7 +63,7 @@ describe("resolveCronSession", () => {
|
||||
modelOverride: "deepseek-v3-4bit-mlx",
|
||||
providerOverride: "inferencer",
|
||||
thinkingLevel: "high",
|
||||
model: "k2p5",
|
||||
model: "kimi-code",
|
||||
},
|
||||
});
|
||||
|
||||
@ -71,7 +71,7 @@ describe("resolveCronSession", () => {
|
||||
expect(result.sessionEntry.providerOverride).toBe("inferencer");
|
||||
expect(result.sessionEntry.thinkingLevel).toBe("high");
|
||||
// The model field (last-used model) should also be preserved
|
||||
expect(result.sessionEntry.model).toBe("k2p5");
|
||||
expect(result.sessionEntry.model).toBe("kimi-code");
|
||||
});
|
||||
|
||||
it("handles missing modelOverride gracefully", () => {
|
||||
|
||||
@ -19,9 +19,11 @@ export function resolveBundledPluginsDir(env: NodeJS.ProcessEnv = process.env):
|
||||
);
|
||||
for (const packageRoot of packageRoots) {
|
||||
// Local source checkouts stage a runtime-complete bundled plugin tree under
|
||||
// dist-runtime/. Prefer that over release-shaped dist/extensions.
|
||||
// dist-runtime/. Prefer that over source extensions only when the paired
|
||||
// dist/ tree exists; otherwise wrappers can drift ahead of the last build.
|
||||
const runtimeExtensionsDir = path.join(packageRoot, "dist-runtime", "extensions");
|
||||
if (fs.existsSync(runtimeExtensionsDir)) {
|
||||
const builtExtensionsDir = path.join(packageRoot, "dist", "extensions");
|
||||
if (fs.existsSync(runtimeExtensionsDir) && fs.existsSync(builtExtensionsDir)) {
|
||||
return runtimeExtensionsDir;
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ export const BUNDLED_ENABLED_BY_DEFAULT = new Set<string>([
|
||||
"google",
|
||||
"huggingface",
|
||||
"kilocode",
|
||||
"kimi-coding",
|
||||
"kimi",
|
||||
"minimax",
|
||||
"mistral",
|
||||
"modelstudio",
|
||||
@ -62,6 +62,7 @@ export const BUNDLED_ENABLED_BY_DEFAULT = new Set<string>([
|
||||
|
||||
const PLUGIN_ID_ALIASES: Readonly<Record<string, string>> = {
|
||||
"openai-codex": "openai",
|
||||
"kimi-coding": "kimi",
|
||||
"minimax-portal-auth": "minimax",
|
||||
};
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import { normalizeApiKeyInput, validateApiKeyInput } from "../commands/auth-choice.api-key.js";
|
||||
import { ensureApiKeyFromOptionEnvOrPrompt } from "../commands/auth-choice.apply-helpers.js";
|
||||
import { buildApiKeyCredential } from "../commands/auth-credentials.js";
|
||||
import { applyPrimaryModel } from "../commands/model-picker.js";
|
||||
import { buildApiKeyCredential } from "../commands/onboard-auth.credentials.js";
|
||||
import { applyAuthProfileConfig } from "../commands/onboard-auth.js";
|
||||
|
||||
export {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user