自动同步: 2026-07-01 02:10
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "openclaw-kimi-provider-9241ab9f01",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"node_modules/@openclaw/kimi-provider": {
|
||||
"version": "2026.6.10",
|
||||
"resolved": "https://registry.npmjs.org/@openclaw/kimi-provider/-/kimi-provider-2026.6.10.tgz",
|
||||
"integrity": "sha512-4QZyUhe36wGJaRSVzCIgjc+S2ExteeByKDgVivjdLWRbBnfYtpV+OQWfKnouQcFFG2EZ7UcavOD591yyCCv4UA==",
|
||||
"hasShrinkwrap": true,
|
||||
"peerDependencies": {
|
||||
"openclaw": ">=2026.6.10"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"openclaw": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
# OpenClaw Kimi Coding Provider
|
||||
|
||||
Official OpenClaw provider plugin for Kimi Coding.
|
||||
|
||||
Install from OpenClaw:
|
||||
|
||||
```bash
|
||||
openclaw plugins install @openclaw/kimi-provider
|
||||
openclaw gateway restart
|
||||
```
|
||||
|
||||
See <https://docs.openclaw.ai/providers/moonshot> for setup and configuration.
|
||||
Generated
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
import { KIMI_CODING_BASE_URL, KIMI_CODING_DEFAULT_MODEL_ID, KIMI_CODING_LEGACY_MODEL_IDS, buildKimiCodingProvider, normalizeKimiCodingModelId } from "./provider-catalog.js";
|
||||
import { KIMI_CODING_MODEL_REF, KIMI_MODEL_REF } from "./onboard.js";
|
||||
export { KIMI_CODING_BASE_URL, KIMI_CODING_DEFAULT_MODEL_ID, KIMI_CODING_LEGACY_MODEL_IDS, KIMI_CODING_MODEL_REF, KIMI_MODEL_REF, buildKimiCodingProvider, normalizeKimiCodingModelId };
|
||||
Generated
Vendored
+98
@@ -0,0 +1,98 @@
|
||||
import { buildKimiCodingProvider, normalizeKimiCodingModelId } from "./provider-catalog.js";
|
||||
import { KIMI_CODING_MODEL_REF, applyKimiCodeConfig } from "./onboard.js";
|
||||
import { KIMI_REPLAY_POLICY } from "./replay-policy.js";
|
||||
import { wrapKimiProviderStream } from "./stream.js";
|
||||
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
||||
import { createProviderApiKeyAuthMethod } from "openclaw/plugin-sdk/provider-auth-api-key";
|
||||
import { normalizeProviderId } from "openclaw/plugin-sdk/provider-model-shared";
|
||||
import { isRecord, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
||||
//#region extensions/kimi-coding/index.ts
|
||||
const PLUGIN_ID = "kimi";
|
||||
const PROVIDER_ID = "kimi";
|
||||
function findExplicitProviderConfig(providers, providerId) {
|
||||
if (!providers) return;
|
||||
const normalizedProviderId = normalizeProviderId(providerId);
|
||||
const match = Object.entries(providers).find(([configuredProviderId]) => normalizeProviderId(configuredProviderId) === normalizedProviderId);
|
||||
return isRecord(match?.[1]) ? match[1] : void 0;
|
||||
}
|
||||
var kimi_coding_default = definePluginEntry({
|
||||
id: PLUGIN_ID,
|
||||
name: "Kimi Provider",
|
||||
description: "Bundled Kimi provider plugin",
|
||||
register(api) {
|
||||
api.registerProvider({
|
||||
id: PROVIDER_ID,
|
||||
label: "Kimi",
|
||||
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 Code API key (subscription)",
|
||||
hint: "Kimi K2.6 + Kimi",
|
||||
optionKey: "kimiCodeApiKey",
|
||||
flagName: "--kimi-code-api-key",
|
||||
envVar: "KIMI_API_KEY",
|
||||
promptMessage: "Enter Kimi API key",
|
||||
defaultModel: KIMI_CODING_MODEL_REF,
|
||||
expectedProviders: [
|
||||
"kimi",
|
||||
"kimi-code",
|
||||
"kimi-coding"
|
||||
],
|
||||
applyConfig: (cfg) => applyKimiCodeConfig(cfg),
|
||||
noteMessage: ["Kimi uses a dedicated coding endpoint and API key.", "Get your API key at: https://www.kimi.com/code/en"].join("\n"),
|
||||
noteTitle: "Kimi",
|
||||
wizard: {
|
||||
choiceId: "kimi-code-api-key",
|
||||
choiceLabel: "Kimi Code API key (subscription)",
|
||||
groupId: "moonshot",
|
||||
groupLabel: "Moonshot AI (Kimi K2.6)",
|
||||
groupHint: "Kimi K2.6"
|
||||
}
|
||||
})],
|
||||
catalog: {
|
||||
order: "simple",
|
||||
run: async (ctx) => {
|
||||
const apiKey = ctx.resolveProviderApiKey(PROVIDER_ID).apiKey;
|
||||
if (!apiKey) return null;
|
||||
const explicitProvider = findExplicitProviderConfig(ctx.config.models?.providers, PROVIDER_ID);
|
||||
const builtInProvider = buildKimiCodingProvider();
|
||||
const explicitBaseUrl = normalizeOptionalString(explicitProvider?.baseUrl) ?? "";
|
||||
const explicitHeaders = isRecord(explicitProvider?.headers) ? explicitProvider.headers : void 0;
|
||||
return { provider: {
|
||||
...builtInProvider,
|
||||
...explicitBaseUrl ? { baseUrl: explicitBaseUrl } : {},
|
||||
...explicitHeaders ? { headers: {
|
||||
...builtInProvider.headers,
|
||||
...explicitHeaders
|
||||
} } : {},
|
||||
apiKey
|
||||
} };
|
||||
}
|
||||
},
|
||||
buildReplayPolicy: () => KIMI_REPLAY_POLICY,
|
||||
normalizeResolvedModel: ({ model }) => {
|
||||
const normalizedId = normalizeKimiCodingModelId(model.id);
|
||||
return normalizedId === model.id ? void 0 : {
|
||||
...model,
|
||||
id: normalizedId
|
||||
};
|
||||
},
|
||||
resolveThinkingProfile: () => ({
|
||||
levels: [{
|
||||
id: "off",
|
||||
label: "off"
|
||||
}, {
|
||||
id: "low",
|
||||
label: "on"
|
||||
}],
|
||||
defaultLevel: "off"
|
||||
}),
|
||||
wrapStreamFn: wrapKimiProviderStream
|
||||
});
|
||||
}
|
||||
});
|
||||
//#endregion
|
||||
export { kimi_coding_default as default };
|
||||
Generated
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
import { KIMI_CODING_BASE_URL, KIMI_CODING_DEFAULT_MODEL_ID, buildKimiCodingProvider } from "./provider-catalog.js";
|
||||
import { createDefaultModelPresetAppliers } from "openclaw/plugin-sdk/provider-onboard";
|
||||
//#region extensions/kimi-coding/onboard.ts
|
||||
const KIMI_MODEL_REF = `kimi/${KIMI_CODING_DEFAULT_MODEL_ID}`;
|
||||
const KIMI_CODING_MODEL_REF = KIMI_MODEL_REF;
|
||||
function resolveKimiCodingDefaultModel() {
|
||||
return buildKimiCodingProvider().models[0];
|
||||
}
|
||||
const kimiCodingPresetAppliers = createDefaultModelPresetAppliers({
|
||||
primaryModelRef: KIMI_MODEL_REF,
|
||||
resolveParams: (_cfg) => {
|
||||
const defaultModel = resolveKimiCodingDefaultModel();
|
||||
if (!defaultModel) return null;
|
||||
return {
|
||||
providerId: "kimi",
|
||||
api: "anthropic-messages",
|
||||
baseUrl: KIMI_CODING_BASE_URL,
|
||||
defaultModel,
|
||||
defaultModelId: KIMI_CODING_DEFAULT_MODEL_ID,
|
||||
aliases: [{
|
||||
modelRef: KIMI_MODEL_REF,
|
||||
alias: "Kimi"
|
||||
}]
|
||||
};
|
||||
}
|
||||
});
|
||||
function applyKimiCodeConfig(cfg) {
|
||||
return kimiCodingPresetAppliers.applyConfig(cfg);
|
||||
}
|
||||
//#endregion
|
||||
export { KIMI_CODING_MODEL_REF, KIMI_MODEL_REF, applyKimiCodeConfig };
|
||||
Generated
Vendored
+46
@@ -0,0 +1,46 @@
|
||||
//#region extensions/kimi-coding/provider-catalog.ts
|
||||
const KIMI_BASE_URL = "https://api.kimi.com/coding/";
|
||||
const KIMI_CODING_USER_AGENT = "claude-code/0.1.0";
|
||||
const KIMI_DEFAULT_MODEL_ID = "kimi-for-coding";
|
||||
const KIMI_LEGACY_MODEL_IDS = ["kimi-code", "k2p5"];
|
||||
const KIMI_CODING_DEFAULT_CONTEXT_WINDOW = 262144;
|
||||
const KIMI_CODING_DEFAULT_MAX_TOKENS = 32768;
|
||||
const KIMI_CODING_DEFAULT_COST = {
|
||||
input: 0,
|
||||
output: 0,
|
||||
cacheRead: 0,
|
||||
cacheWrite: 0
|
||||
};
|
||||
const KIMI_CODING_INPUT = ["text", "image"];
|
||||
function buildKimiCodingProvider() {
|
||||
return {
|
||||
baseUrl: KIMI_BASE_URL,
|
||||
api: "anthropic-messages",
|
||||
headers: { "User-Agent": KIMI_CODING_USER_AGENT },
|
||||
models: [{
|
||||
id: KIMI_DEFAULT_MODEL_ID,
|
||||
name: "Kimi Code",
|
||||
reasoning: true,
|
||||
input: [...KIMI_CODING_INPUT],
|
||||
cost: KIMI_CODING_DEFAULT_COST,
|
||||
contextWindow: KIMI_CODING_DEFAULT_CONTEXT_WINDOW,
|
||||
maxTokens: KIMI_CODING_DEFAULT_MAX_TOKENS
|
||||
}, ...KIMI_LEGACY_MODEL_IDS.map((id) => ({
|
||||
id,
|
||||
name: `Kimi Code (legacy ${id})`,
|
||||
reasoning: true,
|
||||
input: [...KIMI_CODING_INPUT],
|
||||
cost: KIMI_CODING_DEFAULT_COST,
|
||||
contextWindow: KIMI_CODING_DEFAULT_CONTEXT_WINDOW,
|
||||
maxTokens: KIMI_CODING_DEFAULT_MAX_TOKENS
|
||||
}))]
|
||||
};
|
||||
}
|
||||
function normalizeKimiCodingModelId(modelId) {
|
||||
return KIMI_LEGACY_MODEL_IDS.includes(modelId) ? KIMI_DEFAULT_MODEL_ID : modelId;
|
||||
}
|
||||
const KIMI_CODING_BASE_URL = KIMI_BASE_URL;
|
||||
const KIMI_CODING_DEFAULT_MODEL_ID = KIMI_DEFAULT_MODEL_ID;
|
||||
const KIMI_CODING_LEGACY_MODEL_IDS = KIMI_LEGACY_MODEL_IDS;
|
||||
//#endregion
|
||||
export { KIMI_CODING_BASE_URL, KIMI_CODING_DEFAULT_MODEL_ID, KIMI_CODING_LEGACY_MODEL_IDS, buildKimiCodingProvider, normalizeKimiCodingModelId };
|
||||
Generated
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
//#region extensions/kimi-coding/replay-policy.ts
|
||||
const KIMI_REPLAY_POLICY = { preserveSignatures: false };
|
||||
//#endregion
|
||||
export { KIMI_REPLAY_POLICY };
|
||||
Generated
Vendored
+261
@@ -0,0 +1,261 @@
|
||||
import { normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
||||
import { streamSimple } from "openclaw/plugin-sdk/llm";
|
||||
import { streamWithPayloadPatch } from "openclaw/plugin-sdk/provider-stream-shared";
|
||||
//#region extensions/kimi-coding/stream.ts
|
||||
const TOOL_CALLS_SECTION_BEGIN = "<|tool_calls_section_begin|>";
|
||||
const TOOL_CALLS_SECTION_END = "<|tool_calls_section_end|>";
|
||||
const TOOL_CALL_BEGIN = "<|tool_call_begin|>";
|
||||
const TOOL_CALL_ARGUMENT_BEGIN = "<|tool_call_argument_begin|>";
|
||||
const TOOL_CALL_END = "<|tool_call_end|>";
|
||||
const KIMI_ANTHROPIC_THINKING_BUDGETS = {
|
||||
minimal: 1024,
|
||||
low: 1024,
|
||||
medium: 4096,
|
||||
high: 8192,
|
||||
adaptive: 8192,
|
||||
xhigh: 8192,
|
||||
max: 8192
|
||||
};
|
||||
const KIMI_ANTHROPIC_VISIBLE_OUTPUT_RESERVE_TOKENS = 1024;
|
||||
const KIMI_ANTHROPIC_MIN_OUTPUT_TOKENS = 16e3;
|
||||
function normalizeKimiThinkingBudgetTokens(value) {
|
||||
if (typeof value !== "number" || !Number.isFinite(value)) return;
|
||||
const normalized = Math.floor(value);
|
||||
return normalized >= 1024 ? normalized : void 0;
|
||||
}
|
||||
function normalizeKimiAnthropicMaxTokens(value) {
|
||||
if (typeof value !== "number" || !Number.isFinite(value)) return;
|
||||
const normalized = Math.floor(value);
|
||||
return normalized > 0 ? normalized : void 0;
|
||||
}
|
||||
function ensureKimiAnthropicMaxTokens(payloadObj, thinkingConfig) {
|
||||
if (thinkingConfig.type !== "enabled" || thinkingConfig.budget_tokens === void 0) return;
|
||||
const required = Math.max(KIMI_ANTHROPIC_MIN_OUTPUT_TOKENS, thinkingConfig.budget_tokens + KIMI_ANTHROPIC_VISIBLE_OUTPUT_RESERVE_TOKENS);
|
||||
const current = normalizeKimiAnthropicMaxTokens(payloadObj.max_tokens);
|
||||
payloadObj.max_tokens = current === void 0 ? required : Math.max(current, required);
|
||||
}
|
||||
function messageHasOpenAIToolCalls(message) {
|
||||
return Array.isArray(message.tool_calls) && message.tool_calls.length > 0;
|
||||
}
|
||||
function ensureKimiOpenAIReasoningContent(payloadObj) {
|
||||
if (!Array.isArray(payloadObj.messages)) return;
|
||||
for (const message of payloadObj.messages) {
|
||||
if (!message || typeof message !== "object") continue;
|
||||
const record = message;
|
||||
if (record.role !== "assistant" || !messageHasOpenAIToolCalls(record)) continue;
|
||||
if (!("reasoning_content" in record)) record.reasoning_content = "";
|
||||
}
|
||||
}
|
||||
function stripKimiOpenAIReasoningContent(payloadObj) {
|
||||
if (!Array.isArray(payloadObj.messages)) return;
|
||||
for (const message of payloadObj.messages) if (message && typeof message === "object") delete message.reasoning_content;
|
||||
}
|
||||
function normalizeKimiThinkingType(value) {
|
||||
if (typeof value === "boolean") return value ? "enabled" : "disabled";
|
||||
if (typeof value === "string") {
|
||||
const normalized = normalizeOptionalLowercaseString(value);
|
||||
if (!normalized) return;
|
||||
if ([
|
||||
"enabled",
|
||||
"enable",
|
||||
"on",
|
||||
"true"
|
||||
].includes(normalized)) return "enabled";
|
||||
if ([
|
||||
"disabled",
|
||||
"disable",
|
||||
"off",
|
||||
"false"
|
||||
].includes(normalized)) return "disabled";
|
||||
return;
|
||||
}
|
||||
if (value && typeof value === "object" && !Array.isArray(value)) return normalizeKimiThinkingType(value.type);
|
||||
}
|
||||
function normalizeKimiThinkingConfig(value) {
|
||||
const type = normalizeKimiThinkingType(value);
|
||||
if (!type) return;
|
||||
if (type === "disabled") return { type: "disabled" };
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) return { type: "enabled" };
|
||||
const record = value;
|
||||
const budgetTokens = normalizeKimiThinkingBudgetTokens(record.budget_tokens ?? record.budgetTokens);
|
||||
return budgetTokens === void 0 ? { type: "enabled" } : {
|
||||
type: "enabled",
|
||||
budget_tokens: budgetTokens
|
||||
};
|
||||
}
|
||||
function resolveKimiAnthropicThinkingBudgetTokens(thinkingLevel) {
|
||||
if (!thinkingLevel || thinkingLevel === "off") return;
|
||||
return KIMI_ANTHROPIC_THINKING_BUDGETS[thinkingLevel];
|
||||
}
|
||||
function resolveKimiThinkingConfig(params) {
|
||||
const configured = normalizeKimiThinkingConfig(params.configuredThinking);
|
||||
const levelBudgetTokens = resolveKimiAnthropicThinkingBudgetTokens(params.thinkingLevel);
|
||||
if (configured) return configured.type === "enabled" && configured.budget_tokens === void 0 ? {
|
||||
type: "enabled",
|
||||
budget_tokens: levelBudgetTokens ?? 1024
|
||||
} : configured;
|
||||
if (!params.thinkingLevel || params.thinkingLevel === "off") return { type: "disabled" };
|
||||
return levelBudgetTokens === void 0 ? { type: "enabled" } : {
|
||||
type: "enabled",
|
||||
budget_tokens: levelBudgetTokens
|
||||
};
|
||||
}
|
||||
function resolveKimiThinkingType(params) {
|
||||
return resolveKimiThinkingConfig(params).type;
|
||||
}
|
||||
function stripTaggedToolCallCounter(value) {
|
||||
return value.trim().replace(/:\d+$/, "");
|
||||
}
|
||||
function parseKimiTaggedToolCalls(text) {
|
||||
const trimmed = text.trim();
|
||||
if (!trimmed.startsWith(TOOL_CALLS_SECTION_BEGIN) || !trimmed.endsWith(TOOL_CALLS_SECTION_END)) return null;
|
||||
let cursor = 28;
|
||||
const sectionEndIndex = trimmed.length - 26;
|
||||
const toolCalls = [];
|
||||
while (cursor < sectionEndIndex) {
|
||||
while (cursor < sectionEndIndex && /\s/.test(trimmed[cursor] ?? "")) cursor += 1;
|
||||
if (cursor >= sectionEndIndex) break;
|
||||
if (!trimmed.startsWith(TOOL_CALL_BEGIN, cursor)) return null;
|
||||
const nameStart = cursor + 19;
|
||||
const argMarkerIndex = trimmed.indexOf(TOOL_CALL_ARGUMENT_BEGIN, nameStart);
|
||||
if (argMarkerIndex < 0 || argMarkerIndex >= sectionEndIndex) return null;
|
||||
const rawId = trimmed.slice(nameStart, argMarkerIndex).trim();
|
||||
if (!rawId) return null;
|
||||
const argsStart = argMarkerIndex + 28;
|
||||
const callEndIndex = trimmed.indexOf(TOOL_CALL_END, argsStart);
|
||||
if (callEndIndex < 0 || callEndIndex > sectionEndIndex) return null;
|
||||
const rawArgs = trimmed.slice(argsStart, callEndIndex).trim();
|
||||
let parsedArgs;
|
||||
try {
|
||||
parsedArgs = JSON.parse(rawArgs);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
if (!parsedArgs || typeof parsedArgs !== "object" || Array.isArray(parsedArgs)) return null;
|
||||
const name = stripTaggedToolCallCounter(rawId);
|
||||
if (!name) return null;
|
||||
toolCalls.push({
|
||||
type: "toolCall",
|
||||
id: rawId,
|
||||
name,
|
||||
arguments: parsedArgs
|
||||
});
|
||||
cursor = callEndIndex + 17;
|
||||
}
|
||||
return toolCalls.length > 0 ? toolCalls : null;
|
||||
}
|
||||
function rewriteKimiTaggedToolCallsInMessage(message) {
|
||||
if (!message || typeof message !== "object") return;
|
||||
const content = message.content;
|
||||
if (!Array.isArray(content)) return;
|
||||
let changed = false;
|
||||
const nextContent = [];
|
||||
for (const block of content) {
|
||||
if (!block || typeof block !== "object") {
|
||||
nextContent.push(block);
|
||||
continue;
|
||||
}
|
||||
const typedBlock = block;
|
||||
if (typedBlock.type !== "text" || typeof typedBlock.text !== "string") {
|
||||
nextContent.push(block);
|
||||
continue;
|
||||
}
|
||||
const parsed = parseKimiTaggedToolCalls(typedBlock.text);
|
||||
if (!parsed) {
|
||||
nextContent.push(block);
|
||||
continue;
|
||||
}
|
||||
nextContent.push(...parsed);
|
||||
changed = true;
|
||||
}
|
||||
if (!changed) return;
|
||||
message.content = nextContent;
|
||||
const typedMessage = message;
|
||||
if (typedMessage.stopReason === "stop") typedMessage.stopReason = "toolUse";
|
||||
}
|
||||
function transformKimiStreamEvent(value, transformMessage) {
|
||||
const event = value && typeof value === "object" ? value : void 0;
|
||||
if (!event) return;
|
||||
for (const message of [event.partial, event.message]) transformMessage(message);
|
||||
}
|
||||
function wrapStreamMessageObjects(stream, transformMessage) {
|
||||
const readFinalMessage = stream.result.bind(stream);
|
||||
Object.assign(stream, { async result() {
|
||||
const message = await readFinalMessage();
|
||||
transformMessage(message);
|
||||
return message;
|
||||
} });
|
||||
const createIterator = stream[Symbol.asyncIterator].bind(stream);
|
||||
stream[Symbol.asyncIterator] = () => {
|
||||
const iterator = createIterator();
|
||||
return {
|
||||
async next() {
|
||||
const step = await iterator.next();
|
||||
if (!step.done) transformKimiStreamEvent(step.value, transformMessage);
|
||||
return step;
|
||||
},
|
||||
async return(value) {
|
||||
return iterator.return?.(value) ?? {
|
||||
done: true,
|
||||
value: void 0
|
||||
};
|
||||
},
|
||||
async throw(error) {
|
||||
return iterator.throw?.(error) ?? {
|
||||
done: true,
|
||||
value: void 0
|
||||
};
|
||||
}
|
||||
};
|
||||
};
|
||||
return stream;
|
||||
}
|
||||
function createKimiToolCallMarkupWrapper(baseStreamFn) {
|
||||
const underlying = baseStreamFn ?? streamSimple;
|
||||
return (model, context, options) => {
|
||||
const maybeStream = underlying(model, context, options);
|
||||
if (maybeStream && typeof maybeStream === "object" && "then" in maybeStream) return Promise.resolve(maybeStream).then((stream) => wrapStreamMessageObjects(stream, rewriteKimiTaggedToolCallsInMessage));
|
||||
return wrapStreamMessageObjects(maybeStream, rewriteKimiTaggedToolCallsInMessage);
|
||||
};
|
||||
}
|
||||
function createKimiThinkingWrapper(baseStreamFn, thinkingConfig) {
|
||||
const underlying = baseStreamFn ?? streamSimple;
|
||||
return (model, context, options) => streamWithPayloadPatch(underlying, model, context, options, (payloadObj) => {
|
||||
const normalized = typeof thinkingConfig === "string" ? { type: thinkingConfig } : thinkingConfig;
|
||||
payloadObj.thinking = model.api === "anthropic-messages" ? { ...normalized } : { type: normalized.type };
|
||||
if (model.api === "anthropic-messages") ensureKimiAnthropicMaxTokens(payloadObj, normalized);
|
||||
else if (normalized.type === "enabled") ensureKimiOpenAIReasoningContent(payloadObj);
|
||||
else stripKimiOpenAIReasoningContent(payloadObj);
|
||||
delete payloadObj.reasoning;
|
||||
delete payloadObj.reasoning_effort;
|
||||
delete payloadObj.reasoningEffort;
|
||||
stripAnthropicCacheControlMarkers(payloadObj);
|
||||
});
|
||||
}
|
||||
function stripContentBlockCacheControl(block) {
|
||||
if (!block || typeof block !== "object") return;
|
||||
const record = block;
|
||||
delete record.cache_control;
|
||||
if (record.type === "tool_result" && Array.isArray(record.content)) for (const nestedBlock of record.content) stripContentBlockCacheControl(nestedBlock);
|
||||
}
|
||||
function stripContentArrayCacheControl(value) {
|
||||
if (!Array.isArray(value)) return;
|
||||
for (const block of value) stripContentBlockCacheControl(block);
|
||||
}
|
||||
function stripAnthropicCacheControlMarkers(payloadObj) {
|
||||
stripContentArrayCacheControl(payloadObj.system);
|
||||
if (!Array.isArray(payloadObj.messages)) return;
|
||||
for (const message of payloadObj.messages) {
|
||||
if (!message || typeof message !== "object") continue;
|
||||
stripContentArrayCacheControl(message.content);
|
||||
}
|
||||
}
|
||||
function wrapKimiProviderStream(ctx) {
|
||||
const thinkingConfig = resolveKimiThinkingConfig({
|
||||
configuredThinking: ctx.extraParams?.thinking,
|
||||
thinkingLevel: ctx.thinkingLevel
|
||||
});
|
||||
return createKimiToolCallMarkupWrapper(createKimiThinkingWrapper(ctx.streamFn, thinkingConfig));
|
||||
}
|
||||
//#endregion
|
||||
export { createKimiThinkingWrapper, createKimiToolCallMarkupWrapper, resolveKimiThinkingConfig, resolveKimiThinkingType, wrapKimiProviderStream };
|
||||
Generated
Vendored
Symlink
+1
@@ -0,0 +1 @@
|
||||
/home/starmen1265/.npm-global/lib/node_modules/openclaw
|
||||
Generated
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"name": "@openclaw/kimi-provider",
|
||||
"version": "2026.6.10",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@openclaw/kimi-provider",
|
||||
"version": "2026.6.10"
|
||||
}
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+72
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"id": "kimi",
|
||||
"activation": {
|
||||
"onStartup": false
|
||||
},
|
||||
"enabledByDefault": true,
|
||||
"providers": ["kimi", "kimi-coding"],
|
||||
"providerRequest": {
|
||||
"providers": {
|
||||
"kimi": {
|
||||
"family": "moonshot",
|
||||
"compatibilityFamily": "moonshot"
|
||||
},
|
||||
"kimi-coding": {
|
||||
"family": "moonshot",
|
||||
"compatibilityFamily": "moonshot"
|
||||
}
|
||||
}
|
||||
},
|
||||
"modelPricing": {
|
||||
"providers": {
|
||||
"kimi": {
|
||||
"openRouter": {
|
||||
"provider": "moonshotai"
|
||||
},
|
||||
"liteLLM": {
|
||||
"provider": "moonshot"
|
||||
}
|
||||
},
|
||||
"kimi-coding": {
|
||||
"openRouter": {
|
||||
"provider": "moonshotai"
|
||||
},
|
||||
"liteLLM": {
|
||||
"provider": "moonshot"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"setup": {
|
||||
"providers": [
|
||||
{
|
||||
"id": "kimi",
|
||||
"envVars": ["KIMI_API_KEY", "KIMICODE_API_KEY"]
|
||||
},
|
||||
{
|
||||
"id": "kimi-coding",
|
||||
"envVars": ["KIMI_API_KEY", "KIMICODE_API_KEY"]
|
||||
}
|
||||
]
|
||||
},
|
||||
"providerAuthChoices": [
|
||||
{
|
||||
"provider": "kimi",
|
||||
"method": "api-key",
|
||||
"choiceId": "kimi-code-api-key",
|
||||
"choiceLabel": "Kimi Code API key (subscription)",
|
||||
"groupId": "moonshot",
|
||||
"groupLabel": "Moonshot AI (Kimi K2.6)",
|
||||
"groupHint": "Kimi K2.6",
|
||||
"optionKey": "kimiCodeApiKey",
|
||||
"cliFlag": "--kimi-code-api-key",
|
||||
"cliOption": "--kimi-code-api-key <key>",
|
||||
"cliDescription": "Kimi Code API key (subscription)"
|
||||
}
|
||||
],
|
||||
"configSchema": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {}
|
||||
}
|
||||
}
|
||||
Generated
Vendored
+50
@@ -0,0 +1,50 @@
|
||||
{
|
||||
"name": "@openclaw/kimi-provider",
|
||||
"version": "2026.6.10",
|
||||
"description": "OpenClaw Kimi provider plugin.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/openclaw/openclaw"
|
||||
},
|
||||
"type": "module",
|
||||
"openclaw": {
|
||||
"extensions": [
|
||||
"./index.ts"
|
||||
],
|
||||
"install": {
|
||||
"clawhubSpec": "clawhub:@openclaw/kimi-provider",
|
||||
"npmSpec": "@openclaw/kimi-provider",
|
||||
"defaultChoice": "npm",
|
||||
"minHostVersion": ">=2026.6.8"
|
||||
},
|
||||
"compat": {
|
||||
"pluginApi": ">=2026.6.10"
|
||||
},
|
||||
"build": {
|
||||
"openclawVersion": "2026.6.10",
|
||||
"bundledDist": false
|
||||
},
|
||||
"release": {
|
||||
"publishToClawHub": true,
|
||||
"publishToNpm": true
|
||||
},
|
||||
"runtimeExtensions": [
|
||||
"./dist/index.js"
|
||||
]
|
||||
},
|
||||
"files": [
|
||||
"dist/**",
|
||||
"openclaw.plugin.json",
|
||||
"npm-shrinkwrap.json",
|
||||
"README.md"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"openclaw": ">=2026.6.10"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"openclaw": {
|
||||
"optional": true
|
||||
}
|
||||
},
|
||||
"bundledDependencies": []
|
||||
}
|
||||
Reference in New Issue
Block a user