Add Kimi Code provider preset and rename Moonshot API preset (#862)

* Add Kimi Code provider preset

* fix desc.

Co-authored-by: Copilot <copilot@github.com>

* more desc. fixes.

* Fix release validation tests

---------

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
JATMN
2026-04-24 21:36:54 -07:00
committed by GitHub
parent 26413f6d30
commit 9070220292
18 changed files with 296 additions and 56 deletions

View File

@@ -88,6 +88,7 @@ const MOONSHOT_API_HOSTS = new Set([
'api.moonshot.ai',
'api.moonshot.cn',
])
const KIMI_CODE_API_HOST = 'api.kimi.com'
const DEEPSEEK_API_HOSTS = new Set([
'api.deepseek.com',
])
@@ -156,10 +157,16 @@ function hasGeminiApiHost(baseUrl: string | undefined): boolean {
}
}
function isMoonshotBaseUrl(baseUrl: string | undefined): boolean {
function isMoonshotCompatibleBaseUrl(baseUrl: string | undefined): boolean {
if (!baseUrl) return false
try {
return MOONSHOT_API_HOSTS.has(new URL(baseUrl).hostname.toLowerCase())
const parsed = new URL(baseUrl)
const hostname = parsed.hostname.toLowerCase()
return (
MOONSHOT_API_HOSTS.has(hostname) ||
(hostname === KIMI_CODE_API_HOST &&
parsed.pathname.toLowerCase().startsWith('/coding'))
)
} catch {
return false
}
@@ -516,7 +523,7 @@ function convertMessages(
})(),
}
// Providers that validate reasoning continuity (Moonshot: "thinking
// Providers that validate reasoning continuity (Moonshot/Kimi Code: "thinking
// is enabled but reasoning_content is missing in assistant tool call
// message at index N" 400) need the original chain-of-thought echoed
// back on each assistant message that carries a tool_call. We kept
@@ -1504,12 +1511,13 @@ class OpenAIShimMessages {
request.resolvedModel,
)
const openaiMessages = convertMessages(compressedMessages, params.system, {
// Moonshot requires every assistant tool-call message to carry
// Moonshot/Kimi Code requires every assistant tool-call message to carry
// reasoning_content when its thinking feature is active. DeepSeek does
// the same for tool-call turns in thinking mode. Echo it back from the
// thinking block we captured on the inbound response.
preserveReasoningContent:
isMoonshotBaseUrl(request.baseUrl) || isDeepSeekBaseUrl(request.baseUrl),
isMoonshotCompatibleBaseUrl(request.baseUrl) ||
isDeepSeekBaseUrl(request.baseUrl),
})
const body: Record<string, unknown> = {
@@ -1546,7 +1554,7 @@ class OpenAIShimMessages {
const isGithubCopilot = isGithub && githubEndpointType === 'copilot'
const isGithubModels = isGithub && (githubEndpointType === 'models' || githubEndpointType === 'custom')
const isMoonshot = isMoonshotBaseUrl(request.baseUrl)
const isMoonshot = isMoonshotCompatibleBaseUrl(request.baseUrl)
const isDeepSeek = isDeepSeekBaseUrl(request.baseUrl)
if ((isGithub || isMistral || isLocal || isMoonshot || isDeepSeek) && body.max_completion_tokens !== undefined) {
@@ -1556,9 +1564,10 @@ class OpenAIShimMessages {
// mistral and gemini don't recognize body.store — Gemini returns 400
// "Invalid JSON payload received. Unknown name 'store': Cannot find field."
// Moonshot (api.moonshot.ai/.cn) has not published support for the
// parameter either; strip it preemptively to avoid the same class of
// error on strict-parse providers.
// Moonshot direct API, Kimi Code's OpenAI-compatible coding endpoint,
// and DeepSeek have not published support for the parameter either;
// strip it preemptively to avoid the same class of error on strict-parse
// providers.
if (isMistral || isGeminiMode() || isMoonshot || isDeepSeek) {
delete body.store
}