fix(providers): add Moonshot (Global) provider for api.moonshot.ai endpoint (#839)

Co-authored-by: octo-patch <octo-patch@github.com>
This commit is contained in:
Octopus
2026-04-13 18:17:29 +08:00
committed by GitHub
Unverified
parent b2c478d554
commit 5482acd43d
5 changed files with 54 additions and 13 deletions

View File

@@ -144,6 +144,37 @@ export const PROVIDER_DEFINITIONS: ProviderDefinition[] = [
],
},
},
{
id: 'moonshot-global',
name: 'Moonshot (Global)',
icon: '🌙',
placeholder: 'sk-...',
model: 'Kimi',
requiresApiKey: true,
defaultBaseUrl: 'https://api.moonshot.ai/v1',
defaultModelId: 'kimi-k2.5',
category: 'official',
envVar: 'MOONSHOT_GLOBAL_API_KEY',
supportedAuthModes: ['api_key'],
defaultAuthMode: 'api_key',
supportsMultipleAccounts: true,
providerConfig: {
baseUrl: 'https://api.moonshot.ai/v1',
api: 'openai-completions',
apiKeyEnv: 'MOONSHOT_GLOBAL_API_KEY',
models: [
{
id: 'kimi-k2.5',
name: 'Kimi K2.5',
reasoning: false,
input: ['text'],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 256000,
maxTokens: 8192,
},
],
},
},
{
id: 'siliconflow',
name: 'SiliconFlow (CN)',

View File

@@ -21,6 +21,7 @@ import {
} from './provider-registry';
import {
OPENCLAW_PROVIDER_KEY_MOONSHOT,
OPENCLAW_PROVIDER_KEY_MOONSHOT_GLOBAL,
isOAuthProviderType,
isOpenClawOAuthPluginProviderKey,
} from './provider-keys';
@@ -849,14 +850,16 @@ function removeLegacyMoonshotKimiSearchConfig(config: Record<string, unknown>):
function upsertMoonshotWebSearchConfig(
config: Record<string, unknown>,
providerKey: string,
baseUrl: string,
legacyKimi?: Record<string, unknown>,
): void {
const plugins = isPlainRecord(config.plugins)
? config.plugins
: (Array.isArray(config.plugins) ? { load: [...config.plugins] } : {});
const entries = isPlainRecord(plugins.entries) ? plugins.entries : {};
const moonshot = isPlainRecord(entries[OPENCLAW_PROVIDER_KEY_MOONSHOT])
? entries[OPENCLAW_PROVIDER_KEY_MOONSHOT] as Record<string, unknown>
const moonshot = isPlainRecord(entries[providerKey])
? entries[providerKey] as Record<string, unknown>
: {};
const moonshotConfig = isPlainRecord(moonshot.config) ? moonshot.config as Record<string, unknown> : {};
const currentWebSearch = isPlainRecord(moonshotConfig.webSearch)
@@ -865,25 +868,27 @@ function upsertMoonshotWebSearchConfig(
const nextWebSearch = { ...(legacyKimi || {}), ...currentWebSearch };
delete nextWebSearch.apiKey;
nextWebSearch.baseUrl = 'https://api.moonshot.cn/v1';
nextWebSearch.baseUrl = baseUrl;
moonshotConfig.webSearch = nextWebSearch;
moonshot.config = moonshotConfig;
entries[OPENCLAW_PROVIDER_KEY_MOONSHOT] = moonshot;
entries[providerKey] = moonshot;
plugins.entries = entries;
config.plugins = plugins;
}
function ensureMoonshotKimiWebSearchCnBaseUrl(config: Record<string, unknown>, provider: string): void {
if (provider !== OPENCLAW_PROVIDER_KEY_MOONSHOT) return;
if (provider === OPENCLAW_PROVIDER_KEY_MOONSHOT) {
const tools = isPlainRecord(config.tools) ? config.tools : null;
const web = tools && isPlainRecord(tools.web) ? tools.web : null;
const search = web && isPlainRecord(web.search) ? web.search : null;
const legacyKimi = search && isPlainRecord(search.kimi) ? search.kimi : undefined;
const tools = isPlainRecord(config.tools) ? config.tools : null;
const web = tools && isPlainRecord(tools.web) ? tools.web : null;
const search = web && isPlainRecord(web.search) ? web.search : null;
const legacyKimi = search && isPlainRecord(search.kimi) ? search.kimi : undefined;
upsertMoonshotWebSearchConfig(config, legacyKimi);
removeLegacyMoonshotKimiSearchConfig(config);
upsertMoonshotWebSearchConfig(config, OPENCLAW_PROVIDER_KEY_MOONSHOT, 'https://api.moonshot.cn/v1', legacyKimi);
removeLegacyMoonshotKimiSearchConfig(config);
} else if (provider === OPENCLAW_PROVIDER_KEY_MOONSHOT_GLOBAL) {
upsertMoonshotWebSearchConfig(config, OPENCLAW_PROVIDER_KEY_MOONSHOT_GLOBAL, 'https://api.moonshot.ai/v1');
}
}
/**
@@ -1461,7 +1466,7 @@ export async function sanitizeOpenClawConfig(): Promise<void> {
const hadLegacyKimi = Boolean(legacyKimi);
if (legacyKimi) {
upsertMoonshotWebSearchConfig(config, legacyKimi);
upsertMoonshotWebSearchConfig(config, OPENCLAW_PROVIDER_KEY_MOONSHOT, 'https://api.moonshot.cn/v1', legacyKimi);
removeLegacyMoonshotKimiSearchConfig(config);
modified = true;
console.log('[sanitize] Migrated legacy "tools.web.search.kimi" to "plugins.entries.moonshot.config.webSearch"');

View File

@@ -2,6 +2,7 @@ const MULTI_INSTANCE_PROVIDER_TYPES = new Set(['custom', 'ollama']);
export const OPENCLAW_PROVIDER_KEY_MINIMAX = 'minimax-portal';
export const OPENCLAW_PROVIDER_KEY_MOONSHOT = 'moonshot';
export const OPENCLAW_PROVIDER_KEY_MOONSHOT_GLOBAL = 'moonshot-global';
export const OAUTH_PROVIDER_TYPES = ['minimax-portal', 'minimax-portal-cn'] as const;
export const OPENCLAW_OAUTH_PLUGIN_PROVIDER_KEYS = [
OPENCLAW_PROVIDER_KEY_MINIMAX,