fix: sync Moonshot Kimi K2 models (#818) (thanks @mickahouan)

Co-authored-by: mickahouan <mickahouan@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-01-13 03:17:46 +00:00
parent cb871a3fc1
commit b928b96af5
7 changed files with 213 additions and 64 deletions

View File

@@ -3,7 +3,7 @@
## 2026.1.12-4
### Changes
- Models/Moonshot: add Kimi K2 turbo + thinking variants to the preset + docs. (#818 — thanks @mickahouan)
- Models/Moonshot: add Kimi K2 0905 + turbo/thinking variants to the preset + docs. (#818 — thanks @mickahouan)
- Memory: allow custom OpenAI-compatible embedding endpoints for memory search (remote baseUrl/apiKey/headers). (#819 — thanks @mukhtharcm)
### Fixes

View File

@@ -117,10 +117,13 @@ Moonshot uses OpenAI-compatible endpoints, so configure it as a custom provider:
- Provider: `moonshot`
- Auth: `MOONSHOT_API_KEY`
- Example model: `moonshot/kimi-k2-0905-preview`
- Other Kimi K2 model IDs: `moonshot/kimi-k2-turbo-preview`, `moonshot/kimi-k2-thinking`,
`moonshot/kimi-k2-thinking-turbo`
- CLI: `clawdbot onboard --auth-choice moonshot-api-key`
- Kimi K2 model IDs:
<!-- moonshot-kimi-k2-model-refs:start -->
- `moonshot/kimi-k2-0905-preview`
- `moonshot/kimi-k2-turbo-preview`
- `moonshot/kimi-k2-thinking`
- `moonshot/kimi-k2-thinking-turbo`
<!-- moonshot-kimi-k2-model-refs:end -->
```json5
{
agents: {

View File

@@ -9,12 +9,13 @@ read_when:
Moonshot provides the Kimi API with OpenAI-compatible endpoints. Configure the
provider and set the default model to `moonshot/kimi-k2-0905-preview`.
Other current Kimi K2 model IDs:
Current Kimi K2 model IDs:
<!-- moonshot-kimi-k2-ids:start -->
- `kimi-k2-0905-preview`
- `kimi-k2-turbo-preview`
- `kimi-k2-thinking`
- `kimi-k2-thinking-turbo`
## CLI setup
<!-- moonshot-kimi-k2-ids:end -->
```bash
clawdbot onboard --auth-choice moonshot-api-key
@@ -29,10 +30,12 @@ clawdbot onboard --auth-choice moonshot-api-key
defaults: {
model: { primary: "moonshot/kimi-k2-0905-preview" },
models: {
// moonshot-kimi-k2-aliases:start
"moonshot/kimi-k2-0905-preview": { alias: "Kimi K2" },
"moonshot/kimi-k2-turbo-preview": { alias: "Kimi K2 Turbo" },
"moonshot/kimi-k2-thinking": { alias: "Kimi K2 Thinking" },
"moonshot/kimi-k2-thinking-turbo": { alias: "Kimi K2 Thinking Turbo" }
// moonshot-kimi-k2-aliases:end
}
}
},
@@ -44,6 +47,7 @@ clawdbot onboard --auth-choice moonshot-api-key
apiKey: "${MOONSHOT_API_KEY}",
api: "openai-completions",
models: [
// moonshot-kimi-k2-models:start
{
id: "kimi-k2-0905-preview",
name: "Kimi K2 0905 Preview",
@@ -80,6 +84,7 @@ clawdbot onboard --auth-choice moonshot-api-key
contextWindow: 256000,
maxTokens: 8192
}
// moonshot-kimi-k2-models:end
]
}
}

View File

@@ -0,0 +1,128 @@
import { readFile, writeFile } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import {
MOONSHOT_KIMI_K2_CONTEXT_WINDOW,
MOONSHOT_KIMI_K2_COST,
MOONSHOT_KIMI_K2_INPUT,
MOONSHOT_KIMI_K2_MAX_TOKENS,
MOONSHOT_KIMI_K2_MODELS,
} from "../ui/src/ui/data/moonshot-kimi-k2";
const here = path.dirname(fileURLToPath(import.meta.url));
const repoRoot = path.resolve(here, "..");
function replaceBlockLines(
text: string,
startMarker: string,
endMarker: string,
lines: string[],
): string {
const startIndex = text.indexOf(startMarker);
if (startIndex === -1) {
throw new Error(`Missing start marker: ${startMarker}`);
}
const endIndex = text.indexOf(endMarker, startIndex);
if (endIndex === -1) {
throw new Error(`Missing end marker: ${endMarker}`);
}
const startLineStart = text.lastIndexOf("\n", startIndex);
const startLineStartIndex = startLineStart === -1 ? 0 : startLineStart + 1;
const indent = text.slice(startLineStartIndex, startIndex);
const endLineEnd = text.indexOf("\n", endIndex);
const endLineEndIndex = endLineEnd === -1 ? text.length : endLineEnd + 1;
const before = text.slice(0, startLineStartIndex);
const after = text.slice(endLineEndIndex);
const replacementLines = [
`${indent}${startMarker}`,
...lines.map((line) => `${indent}${line}`),
`${indent}${endMarker}`,
];
const replacement = replacementLines.join("\n");
if (!after) return `${before}${replacement}`;
return `${before}${replacement}\n${after}`;
}
function renderKimiK2Ids(prefix: string) {
return MOONSHOT_KIMI_K2_MODELS.map(
(model) => `- \`${prefix}${model.id}\``,
);
}
function renderMoonshotAliases() {
return MOONSHOT_KIMI_K2_MODELS.map((model, index) => {
const isLast = index === MOONSHOT_KIMI_K2_MODELS.length - 1;
const suffix = isLast ? "" : ",";
return `"moonshot/${model.id}": { alias: "${model.alias}" }${suffix}`;
});
}
function renderMoonshotModels() {
const input = JSON.stringify([...MOONSHOT_KIMI_K2_INPUT]);
const cost = `input: ${MOONSHOT_KIMI_K2_COST.input}, output: ${MOONSHOT_KIMI_K2_COST.output}, cacheRead: ${MOONSHOT_KIMI_K2_COST.cacheRead}, cacheWrite: ${MOONSHOT_KIMI_K2_COST.cacheWrite}`;
return MOONSHOT_KIMI_K2_MODELS.flatMap((model, index) => {
const isLast = index === MOONSHOT_KIMI_K2_MODELS.length - 1;
const closing = isLast ? "}" : "},";
return [
"{",
` id: "${model.id}",`,
` name: "${model.name}",`,
` reasoning: ${model.reasoning},`,
` input: ${input},`,
` cost: { ${cost} },`,
` contextWindow: ${MOONSHOT_KIMI_K2_CONTEXT_WINDOW},`,
` maxTokens: ${MOONSHOT_KIMI_K2_MAX_TOKENS}`,
closing,
];
});
}
async function syncMoonshotDocs() {
const moonshotDoc = path.join(repoRoot, "docs/providers/moonshot.md");
const conceptsDoc = path.join(
repoRoot,
"docs/concepts/model-providers.md",
);
let moonshotText = await readFile(moonshotDoc, "utf8");
moonshotText = replaceBlockLines(
moonshotText,
"<!-- moonshot-kimi-k2-ids:start -->",
"<!-- moonshot-kimi-k2-ids:end -->",
renderKimiK2Ids(""),
);
moonshotText = replaceBlockLines(
moonshotText,
"// moonshot-kimi-k2-aliases:start",
"// moonshot-kimi-k2-aliases:end",
renderMoonshotAliases(),
);
moonshotText = replaceBlockLines(
moonshotText,
"// moonshot-kimi-k2-models:start",
"// moonshot-kimi-k2-models:end",
renderMoonshotModels(),
);
let conceptsText = await readFile(conceptsDoc, "utf8");
conceptsText = replaceBlockLines(
conceptsText,
"<!-- moonshot-kimi-k2-model-refs:start -->",
"<!-- moonshot-kimi-k2-model-refs:end -->",
renderKimiK2Ids("moonshot/"),
);
await writeFile(moonshotDoc, moonshotText);
await writeFile(conceptsDoc, conceptsText);
}
syncMoonshotDocs().catch((error) => {
console.error(error);
process.exitCode = 1;
});

View File

@@ -0,0 +1,39 @@
export const MOONSHOT_KIMI_K2_DEFAULT_ID = "kimi-k2-0905-preview";
export const MOONSHOT_KIMI_K2_CONTEXT_WINDOW = 256000;
export const MOONSHOT_KIMI_K2_MAX_TOKENS = 8192;
export const MOONSHOT_KIMI_K2_INPUT = ["text"] as const;
export const MOONSHOT_KIMI_K2_COST = {
input: 0,
output: 0,
cacheRead: 0,
cacheWrite: 0,
} as const;
export const MOONSHOT_KIMI_K2_MODELS = [
{
id: "kimi-k2-0905-preview",
name: "Kimi K2 0905 Preview",
alias: "Kimi K2",
reasoning: false,
},
{
id: "kimi-k2-turbo-preview",
name: "Kimi K2 Turbo",
alias: "Kimi K2 Turbo",
reasoning: false,
},
{
id: "kimi-k2-thinking",
name: "Kimi K2 Thinking",
alias: "Kimi K2 Thinking",
reasoning: true,
},
{
id: "kimi-k2-thinking-turbo",
name: "Kimi K2 Thinking Turbo",
alias: "Kimi K2 Thinking Turbo",
reasoning: true,
},
] as const;
export type MoonshotKimiK2Model = (typeof MOONSHOT_KIMI_K2_MODELS)[number];

View File

@@ -173,6 +173,12 @@ describe("config view", () => {
const raw = String(onRawChange.mock.calls.at(-1)?.[0] ?? "");
expect(raw).toContain("https://api.moonshot.ai/v1");
expect(raw).toContain("moonshot/kimi-k2-0905-preview");
expect(raw).toContain("moonshot/kimi-k2-turbo-preview");
expect(raw).toContain("moonshot/kimi-k2-thinking");
expect(raw).toContain("moonshot/kimi-k2-thinking-turbo");
expect(raw).toContain("Kimi K2 Turbo");
expect(raw).toContain("Kimi K2 Thinking");
expect(raw).toContain("Kimi K2 Thinking Turbo");
expect(raw).toContain("MOONSHOT_API_KEY");
expect(onFormPatch).toHaveBeenCalledWith(
["agents", "defaults", "model", "primary"],

View File

@@ -1,4 +1,12 @@
import { html, nothing } from "lit";
import {
MOONSHOT_KIMI_K2_CONTEXT_WINDOW,
MOONSHOT_KIMI_K2_COST,
MOONSHOT_KIMI_K2_DEFAULT_ID,
MOONSHOT_KIMI_K2_INPUT,
MOONSHOT_KIMI_K2_MAX_TOKENS,
MOONSHOT_KIMI_K2_MODELS,
} from "../data/moonshot-kimi-k2";
import type { ConfigUiHints } from "../types";
import { analyzeConfigSchema, renderConfigForm } from "./config-form";
@@ -265,67 +273,27 @@ function buildModelPresetPatches(base: Record<string, unknown>): Array<{
value: "openai-completions",
});
}
const moonshotModelDefinitions = MOONSHOT_KIMI_K2_MODELS.map((model) => ({
id: model.id,
name: model.name,
reasoning: model.reasoning,
input: [...MOONSHOT_KIMI_K2_INPUT],
cost: { ...MOONSHOT_KIMI_K2_COST },
contextWindow: MOONSHOT_KIMI_K2_CONTEXT_WINDOW,
maxTokens: MOONSHOT_KIMI_K2_MAX_TOKENS,
}));
if (!moonshotHasModels) {
moonshot.push({
path: moonshotModelsPath as Array<string | number>,
value: [
{
id: "kimi-k2-0905-preview",
name: "Kimi K2 0905 Preview",
reasoning: false,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 256000,
maxTokens: 8192,
},
{
id: "kimi-k2-turbo-preview",
name: "Kimi K2 Turbo",
reasoning: false,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 256000,
maxTokens: 8192,
},
{
id: "kimi-k2-thinking",
name: "Kimi K2 Thinking",
reasoning: true,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 256000,
maxTokens: 8192,
},
{
id: "kimi-k2-thinking-turbo",
name: "Kimi K2 Thinking Turbo",
reasoning: true,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 256000,
maxTokens: 8192,
},
],
value: moonshotModelDefinitions,
});
}
moonshot.push(setPrimary("moonshot/kimi-k2-0905-preview"));
const moonshotAlias = safeAlias("moonshot/kimi-k2-0905-preview", "Kimi K2");
if (moonshotAlias) moonshot.push(moonshotAlias);
const moonshotTurboAlias = safeAlias(
"moonshot/kimi-k2-turbo-preview",
"Kimi K2 Turbo",
);
if (moonshotTurboAlias) moonshot.push(moonshotTurboAlias);
const moonshotThinkingAlias = safeAlias(
"moonshot/kimi-k2-thinking",
"Kimi K2 Thinking",
);
if (moonshotThinkingAlias) moonshot.push(moonshotThinkingAlias);
const moonshotThinkingTurboAlias = safeAlias(
"moonshot/kimi-k2-thinking-turbo",
"Kimi K2 Thinking Turbo",
);
if (moonshotThinkingTurboAlias) moonshot.push(moonshotThinkingTurboAlias);
moonshot.push(setPrimary(`moonshot/${MOONSHOT_KIMI_K2_DEFAULT_ID}`));
for (const model of MOONSHOT_KIMI_K2_MODELS) {
const moonshotAlias = safeAlias(`moonshot/${model.id}`, model.alias);
if (moonshotAlias) moonshot.push(moonshotAlias);
}
return [
{