@arnilo/prism-provider-kimi 0.0.14 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -2
- package/dist/index.d.ts +4 -4
- package/dist/index.js +2 -2
- package/dist/models.js +8 -8
- package/dist/moonshot.js +13 -13
- package/dist/provider.js +39 -20
- package/dist/thinking.js +1 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.0.16] - 2026-07-26
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
- Released with exact 0.0.16 graph.
|
|
7
|
+
|
|
8
|
+
## [0.0.15] - 2026-07-26
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- Released with exact 0.0.15 graph.
|
|
13
|
+
|
|
3
14
|
## [0.0.14] - 2026-07-26
|
|
4
15
|
|
|
5
16
|
### Changed
|
|
@@ -44,7 +55,6 @@
|
|
|
44
55
|
|
|
45
56
|
- Malformed streamed tool-call arguments yield recoverable tool calls via `toolCallFromArgumentsText` instead of throwing `ProviderTransportError` / terminal stream errors.
|
|
46
57
|
|
|
47
|
-
|
|
48
58
|
## [0.0.8] - 2026-07-20
|
|
49
59
|
|
|
50
60
|
- Released with the exact 0.0.8 first-party package graph.
|
|
@@ -77,7 +87,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
77
87
|
|
|
78
88
|
- Pinned the required `@arnilo/prism` peer and package metadata to 0.0.5; runtime behavior is unchanged.
|
|
79
89
|
|
|
80
|
-
|
|
81
90
|
## [0.0.4] - 2026-07-14
|
|
82
91
|
|
|
83
92
|
### Changed
|
package/dist/index.d.ts
CHANGED
|
@@ -20,8 +20,8 @@ export interface KimiProviderPackageOptions {
|
|
|
20
20
|
readonly moonshotModels?: readonly ModelConfig[];
|
|
21
21
|
}
|
|
22
22
|
export declare function createKimiProviderPackage(options?: KimiProviderPackageOptions): ProviderPackage;
|
|
23
|
-
export { defineKimiModel, kimiCodingModels, listKimiModels, mapKimiModel, moonshotKimiModels, type KimiModelConfig, type KimiModelEntry, type ListKimiModelsOptions, } from "./models.js";
|
|
24
|
-
export { createKimiCodingProvider, kimiAnthropicBody, kimiAnthropicEvents, type KimiCodingProviderOptions, } from "./provider.js";
|
|
25
|
-
export { createMoonshotProvider, moonshotBody, moonshotEvents, serializeMoonshotMessage, type MoonshotProviderOptions, } from "./moonshot.js";
|
|
26
|
-
export { kimiPreserveThinking, kimiReasoningEffort, kimiThinking, stripKimiThinkingCompat, } from "./thinking.js";
|
|
27
23
|
export { applyKimiAnthropicCacheControl, kimiAnthropicCacheEnabled, } from "./cache.js";
|
|
24
|
+
export { defineKimiModel, type KimiModelConfig, type KimiModelEntry, kimiCodingModels, type ListKimiModelsOptions, listKimiModels, mapKimiModel, moonshotKimiModels, } from "./models.js";
|
|
25
|
+
export { createMoonshotProvider, type MoonshotProviderOptions, moonshotBody, moonshotEvents, serializeMoonshotMessage, } from "./moonshot.js";
|
|
26
|
+
export { createKimiCodingProvider, type KimiCodingProviderOptions, kimiAnthropicBody, kimiAnthropicEvents, } from "./provider.js";
|
|
27
|
+
export { kimiPreserveThinking, kimiReasoningEffort, kimiThinking, stripKimiThinkingCompat, } from "./thinking.js";
|
package/dist/index.js
CHANGED
|
@@ -36,9 +36,9 @@ export function createKimiProviderPackage(options = {}) {
|
|
|
36
36
|
},
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
+
export { applyKimiAnthropicCacheControl, kimiAnthropicCacheEnabled, } from "./cache.js";
|
|
39
40
|
export { defineKimiModel, kimiCodingModels, listKimiModels, mapKimiModel, moonshotKimiModels, } from "./models.js";
|
|
40
|
-
export { createKimiCodingProvider, kimiAnthropicBody, kimiAnthropicEvents, } from "./provider.js";
|
|
41
41
|
export { createMoonshotProvider, moonshotBody, moonshotEvents, serializeMoonshotMessage, } from "./moonshot.js";
|
|
42
|
+
export { createKimiCodingProvider, kimiAnthropicBody, kimiAnthropicEvents, } from "./provider.js";
|
|
42
43
|
export { kimiPreserveThinking, kimiReasoningEffort, kimiThinking, stripKimiThinkingCompat, } from "./thinking.js";
|
|
43
|
-
export { applyKimiAnthropicCacheControl, kimiAnthropicCacheEnabled, } from "./cache.js";
|
|
44
44
|
//# sourceMappingURL=index.js.map
|
package/dist/models.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { redactSecrets, resolveCredentialValue
|
|
1
|
+
import { redactSecrets, resolveCredentialValue } from "@arnilo/prism";
|
|
2
2
|
import { readBoundedResponseText } from "@arnilo/prism/providers/transport";
|
|
3
3
|
export function defineKimiModel(config) {
|
|
4
4
|
return {
|
|
@@ -191,13 +191,13 @@ export const moonshotKimiModels = [
|
|
|
191
191
|
];
|
|
192
192
|
function looksLikeReasoningModel(modelId) {
|
|
193
193
|
const id = modelId.toLowerCase();
|
|
194
|
-
return (id.includes("kimi-k3")
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
194
|
+
return (id.includes("kimi-k3") ||
|
|
195
|
+
id === "k3" ||
|
|
196
|
+
id.includes("k2.7") ||
|
|
197
|
+
id.includes("k2.6") ||
|
|
198
|
+
id.includes("k2.5") ||
|
|
199
|
+
id.includes("thinking") ||
|
|
200
|
+
id.includes("for-coding"));
|
|
201
201
|
}
|
|
202
202
|
function shouldPreserveThinkingByDefault(modelId) {
|
|
203
203
|
const id = modelId.toLowerCase();
|
package/dist/moonshot.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { assertStructuredOutputRequestSupported, providerDone, providerError, providerTextDelta, providerThinkingDelta, providerToolCall, providerToolCallDelta, providerUsage, resolveCredentialValue, toolCallFromArgumentsText } from "@arnilo/prism";
|
|
1
|
+
import { assertStructuredOutputRequestSupported, providerDone, providerError, providerTextDelta, providerThinkingDelta, providerToolCall, providerToolCallDelta, providerUsage, resolveCredentialValue, toolCallFromArgumentsText, } from "@arnilo/prism";
|
|
2
2
|
import { applyOpenAIChatStructuredOutput, mapOpenAIChatUsage, serializeOpenAITool } from "@arnilo/prism/providers/openai";
|
|
3
3
|
import { readBoundedResponseText, readSseData } from "@arnilo/prism/providers/transport";
|
|
4
4
|
import { kimiPreserveThinking, kimiReasoningEffort, kimiThinking, stripKimiThinkingCompat } from "./thinking.js";
|
|
@@ -27,10 +27,10 @@ export function createMoonshotProvider(options = {}) {
|
|
|
27
27
|
headers: {
|
|
28
28
|
...request.options?.headers,
|
|
29
29
|
"content-type": "application/json",
|
|
30
|
-
...(token ? { authorization: `Bearer ${token}` } : {})
|
|
30
|
+
...(token ? { authorization: `Bearer ${token}` } : {}),
|
|
31
31
|
},
|
|
32
32
|
body: JSON.stringify(body),
|
|
33
|
-
signal: request.signal
|
|
33
|
+
signal: request.signal,
|
|
34
34
|
});
|
|
35
35
|
if (!response.ok) {
|
|
36
36
|
return yield providerError(new Error(`Moonshot request failed: ${response.status} ${await readBoundedResponseText(response, { secrets })}`), secrets);
|
|
@@ -42,7 +42,7 @@ export function createMoonshotProvider(options = {}) {
|
|
|
42
42
|
catch (error) {
|
|
43
43
|
yield providerError(error, secrets);
|
|
44
44
|
}
|
|
45
|
-
}
|
|
45
|
+
},
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
export function moonshotBody(request) {
|
|
@@ -60,7 +60,7 @@ export function moonshotBody(request) {
|
|
|
60
60
|
...parameters,
|
|
61
61
|
max_tokens: maxTokens ?? request.model.limits?.maxOutputTokens,
|
|
62
62
|
...stripKimiThinkingCompat(request.options?.compat),
|
|
63
|
-
...request.options?.extra
|
|
63
|
+
...request.options?.extra,
|
|
64
64
|
};
|
|
65
65
|
applyOpenAIChatStructuredOutput(body, request.options?.structuredOutput);
|
|
66
66
|
return clean(body);
|
|
@@ -101,7 +101,7 @@ export async function* moonshotEvents(body, signal) {
|
|
|
101
101
|
index,
|
|
102
102
|
id: tool.id,
|
|
103
103
|
name: tool.function?.name,
|
|
104
|
-
argumentsText: tool.function?.arguments
|
|
104
|
+
argumentsText: tool.function?.arguments,
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
107
|
}
|
|
@@ -109,10 +109,10 @@ export async function* moonshotEvents(body, signal) {
|
|
|
109
109
|
const danglingToolCall = [...tools.values()].some((call) => !call.id || !call.name);
|
|
110
110
|
if (!sawDoneMarker || !sawFinishReason || danglingToolCall) {
|
|
111
111
|
// Truncated streams must fail loudly — emitting done would mark partial output as succeeded.
|
|
112
|
-
yield providerError(new Error(`Moonshot chat stream ended without completion evidence `
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
yield providerError(new Error(`Moonshot chat stream ended without completion evidence ` +
|
|
113
|
+
`([DONE]: ${sawDoneMarker ? "received" : "missing"}, ` +
|
|
114
|
+
`finish_reason: ${sawFinishReason ? "received" : "missing"}, ` +
|
|
115
|
+
`tool calls complete: ${danglingToolCall ? "no" : "yes"})`));
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
118
|
for (const call of tools.values()) {
|
|
@@ -131,7 +131,7 @@ export function serializeMoonshotMessage(message, capabilities = {}, preserveThi
|
|
|
131
131
|
return {
|
|
132
132
|
role: "tool",
|
|
133
133
|
tool_call_id: result?.toolCallId ?? "",
|
|
134
|
-
content: result ? JSON.stringify(result.result ?? result.error ?? null) : ""
|
|
134
|
+
content: result ? JSON.stringify(result.result ?? result.error ?? null) : "",
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
137
|
if (message.role === "assistant") {
|
|
@@ -142,7 +142,7 @@ export function serializeMoonshotMessage(message, capabilities = {}, preserveThi
|
|
|
142
142
|
const reasoning = thinkingParts.map((part) => part.text).join("\n");
|
|
143
143
|
const base = {
|
|
144
144
|
role: "assistant",
|
|
145
|
-
content: text || (toolCalls.length > 0 ? null : "")
|
|
145
|
+
content: text || (toolCalls.length > 0 ? null : ""),
|
|
146
146
|
};
|
|
147
147
|
if (preserveThinking && reasoning)
|
|
148
148
|
base.reasoning_content = reasoning;
|
|
@@ -150,7 +150,7 @@ export function serializeMoonshotMessage(message, capabilities = {}, preserveThi
|
|
|
150
150
|
base.tool_calls = toolCalls.map((call) => ({
|
|
151
151
|
id: call.id,
|
|
152
152
|
type: "function",
|
|
153
|
-
function: { name: call.name, arguments: JSON.stringify(call.arguments) }
|
|
153
|
+
function: { name: call.name, arguments: JSON.stringify(call.arguments) },
|
|
154
154
|
}));
|
|
155
155
|
}
|
|
156
156
|
return base;
|
package/dist/provider.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { assertStructuredOutputRequestSupported, providerDone, providerError, providerTextDelta, providerThinkingDelta, providerToolCall, providerToolCallDelta, providerUsage, resolveCredentialValue, toolCallFromArgumentsText } from "@arnilo/prism";
|
|
2
|
-
import { bytesToBase64, isPdfMediaType, rejectProviderMediaBlock, resolveProviderMediaMessages, serializePdfDocumentWireBlock } from "@arnilo/prism/providers/media";
|
|
1
|
+
import { assertStructuredOutputRequestSupported, providerDone, providerError, providerTextDelta, providerThinkingDelta, providerToolCall, providerToolCallDelta, providerUsage, resolveCredentialValue, toolCallFromArgumentsText, } from "@arnilo/prism";
|
|
2
|
+
import { bytesToBase64, isPdfMediaType, rejectProviderMediaBlock, resolveProviderMediaMessages, serializePdfDocumentWireBlock, } from "@arnilo/prism/providers/media";
|
|
3
3
|
import { readBoundedResponseText, readSseData } from "@arnilo/prism/providers/transport";
|
|
4
4
|
import { applyKimiAnthropicCacheControl } from "./cache.js";
|
|
5
5
|
import { kimiPreserveThinking, kimiReasoningEffort, kimiThinking, stripKimiThinkingCompat } from "./thinking.js";
|
|
@@ -26,10 +26,10 @@ export function createKimiCodingProvider(options = {}) {
|
|
|
26
26
|
...(token ? { authorization: `Bearer ${token}` } : {}),
|
|
27
27
|
// Provider-owned Anthropic-route auth: official third-party setup uses
|
|
28
28
|
// ANTHROPIC_API_KEY semantics (x-api-key + anthropic-version).
|
|
29
|
-
...(token ? { "x-api-key": token, "anthropic-version": "2023-06-01" } : {})
|
|
29
|
+
...(token ? { "x-api-key": token, "anthropic-version": "2023-06-01" } : {}),
|
|
30
30
|
},
|
|
31
31
|
body: JSON.stringify(body),
|
|
32
|
-
signal: request.signal
|
|
32
|
+
signal: request.signal,
|
|
33
33
|
});
|
|
34
34
|
if (!response.ok) {
|
|
35
35
|
return yield providerError(new Error(`Kimi request failed: ${response.status} ${await readBoundedResponseText(response, { secrets })}`), secrets);
|
|
@@ -41,7 +41,7 @@ export function createKimiCodingProvider(options = {}) {
|
|
|
41
41
|
catch (error) {
|
|
42
42
|
yield providerError(error, secrets);
|
|
43
43
|
}
|
|
44
|
-
}
|
|
44
|
+
},
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
export async function kimiAnthropicBody(request) {
|
|
@@ -55,7 +55,10 @@ export async function kimiAnthropicBody(request) {
|
|
|
55
55
|
return clean({
|
|
56
56
|
model: request.model.model,
|
|
57
57
|
messages: await Promise.all(messages.filter((m) => m.role !== "system").map((message) => toMessage(message, request.model, preserveThinking, resolvedMedia))),
|
|
58
|
-
system: messages
|
|
58
|
+
system: messages
|
|
59
|
+
.filter((m) => m.role === "system")
|
|
60
|
+
.map((m) => text(m, preserveThinking))
|
|
61
|
+
.join("\n\n") || undefined,
|
|
59
62
|
tools: request.tools?.map(toTool),
|
|
60
63
|
stream: true,
|
|
61
64
|
thinking: kimiThinking(request),
|
|
@@ -63,7 +66,7 @@ export async function kimiAnthropicBody(request) {
|
|
|
63
66
|
...parameters,
|
|
64
67
|
max_tokens: maxTokens ?? request.model.limits?.maxOutputTokens ?? 4096,
|
|
65
68
|
...stripKimiThinkingCompat(request.options?.compat),
|
|
66
|
-
...request.options?.extra
|
|
69
|
+
...request.options?.extra,
|
|
67
70
|
});
|
|
68
71
|
}
|
|
69
72
|
export async function* kimiAnthropicEvents(body, signal) {
|
|
@@ -104,9 +107,9 @@ export async function* kimiAnthropicEvents(body, signal) {
|
|
|
104
107
|
const danglingBlock = [...blocks.values()].some((call) => !call.id || !call.name || !call.complete);
|
|
105
108
|
if (!sawMessageStop || danglingBlock) {
|
|
106
109
|
// Truncated streams must fail loudly — emitting done would mark partial output as succeeded.
|
|
107
|
-
yield providerError(new Error(`Kimi messages stream ended without completion evidence `
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
yield providerError(new Error(`Kimi messages stream ended without completion evidence ` +
|
|
111
|
+
`(message_stop: ${sawMessageStop ? "received" : "missing"}, ` +
|
|
112
|
+
`content blocks complete: ${danglingBlock ? "no" : "yes"})`));
|
|
110
113
|
return;
|
|
111
114
|
}
|
|
112
115
|
for (const call of blocks.values()) {
|
|
@@ -121,12 +124,14 @@ async function toMessage(message, model, preserveThinking, resolvedMedia) {
|
|
|
121
124
|
const last = message.content[message.content.length - 1];
|
|
122
125
|
return {
|
|
123
126
|
role: "user",
|
|
124
|
-
content: [
|
|
127
|
+
content: [
|
|
128
|
+
{
|
|
125
129
|
type: "tool_result",
|
|
126
130
|
tool_use_id: result?.toolCallId ?? "",
|
|
127
131
|
content: result ? JSON.stringify(result.result ?? result.error ?? null) : "",
|
|
128
|
-
...(last?.cache_control ? { cache_control: last.cache_control } : {})
|
|
129
|
-
}
|
|
132
|
+
...(last?.cache_control ? { cache_control: last.cache_control } : {}),
|
|
133
|
+
},
|
|
134
|
+
],
|
|
130
135
|
};
|
|
131
136
|
}
|
|
132
137
|
const content = [];
|
|
@@ -137,7 +142,9 @@ async function toMessage(message, model, preserveThinking, resolvedMedia) {
|
|
|
137
142
|
}
|
|
138
143
|
else if (part.type === "thinking") {
|
|
139
144
|
if (preserveThinking) {
|
|
140
|
-
content.push(withMarker(part.signature
|
|
145
|
+
content.push(withMarker(part.signature
|
|
146
|
+
? { type: "thinking", thinking: part.text, signature: part.signature }
|
|
147
|
+
: { type: "thinking", thinking: part.text }, marker));
|
|
141
148
|
}
|
|
142
149
|
else {
|
|
143
150
|
content.push(withMarker({ type: "text", text: part.text }, marker));
|
|
@@ -164,14 +171,17 @@ async function toMessage(message, model, preserveThinking, resolvedMedia) {
|
|
|
164
171
|
throw new Error("Kimi tool_result blocks must appear in role=tool messages");
|
|
165
172
|
}
|
|
166
173
|
}
|
|
167
|
-
return {
|
|
174
|
+
return {
|
|
175
|
+
role: message.role === "assistant" ? "assistant" : "user",
|
|
176
|
+
content: content.length > 0 ? content : [{ type: "text", text: "" }],
|
|
177
|
+
};
|
|
168
178
|
}
|
|
169
179
|
function toAnthropicDocument(part, resolvedMedia) {
|
|
170
180
|
const resolved = resolvedMedia.get(part);
|
|
171
181
|
return serializePdfDocumentWireBlock({
|
|
172
182
|
mediaType: resolved.mediaType,
|
|
173
183
|
data: bytesToBase64(resolved.bytes),
|
|
174
|
-
title: resolved.name
|
|
184
|
+
title: resolved.name,
|
|
175
185
|
});
|
|
176
186
|
}
|
|
177
187
|
function toAnthropicFile(part, resolvedMedia) {
|
|
@@ -182,7 +192,7 @@ function toAnthropicFile(part, resolvedMedia) {
|
|
|
182
192
|
return serializePdfDocumentWireBlock({
|
|
183
193
|
mediaType: resolved.mediaType,
|
|
184
194
|
data: bytesToBase64(resolved.bytes),
|
|
185
|
-
title: resolved.name
|
|
195
|
+
title: resolved.name,
|
|
186
196
|
});
|
|
187
197
|
}
|
|
188
198
|
function withMarker(item, marker) {
|
|
@@ -192,16 +202,25 @@ function toTool(tool) {
|
|
|
192
202
|
return clean({ name: tool.name, description: tool.description, input_schema: tool.parameters ?? { type: "object" } });
|
|
193
203
|
}
|
|
194
204
|
function text(message, preserveThinking = false) {
|
|
195
|
-
return message.content
|
|
205
|
+
return message.content
|
|
206
|
+
.map((part) => {
|
|
196
207
|
if (part.type === "text")
|
|
197
208
|
return part.text;
|
|
198
209
|
if (part.type === "thinking")
|
|
199
210
|
return preserveThinking ? part.text : part.text;
|
|
200
211
|
return "";
|
|
201
|
-
})
|
|
212
|
+
})
|
|
213
|
+
.join("");
|
|
202
214
|
}
|
|
203
215
|
function toUsage(usage) {
|
|
204
|
-
return usage
|
|
216
|
+
return usage
|
|
217
|
+
? {
|
|
218
|
+
inputTokens: usage.input_tokens,
|
|
219
|
+
outputTokens: usage.output_tokens,
|
|
220
|
+
cacheReadTokens: usage.cache_read_input_tokens,
|
|
221
|
+
cacheWriteTokens: usage.cache_creation_input_tokens,
|
|
222
|
+
}
|
|
223
|
+
: undefined;
|
|
205
224
|
}
|
|
206
225
|
function clean(value) {
|
|
207
226
|
return Object.fromEntries(Object.entries(value).filter(([, item]) => item !== undefined && !(Array.isArray(item) && item.length === 0)));
|
package/dist/thinking.js
CHANGED
|
@@ -18,9 +18,7 @@ export function kimiThinking(request) {
|
|
|
18
18
|
* @see https://platform.kimi.ai/docs/guide/use-thinking-effort
|
|
19
19
|
*/
|
|
20
20
|
export function kimiReasoningEffort(request) {
|
|
21
|
-
const effort = request.options?.compat?.reasoning_effort
|
|
22
|
-
?? request.options?.compat?.reasoningEffort
|
|
23
|
-
?? request.model.compat?.reasoning_effort;
|
|
21
|
+
const effort = request.options?.compat?.reasoning_effort ?? request.options?.compat?.reasoningEffort ?? request.model.compat?.reasoning_effort;
|
|
24
22
|
return typeof effort === "string" ? effort : undefined;
|
|
25
23
|
}
|
|
26
24
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arnilo/prism-provider-kimi",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.16",
|
|
4
4
|
"description": "Kimi provider package for Prism.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"pack:dry-run": "npm pack --dry-run"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
|
-
"@arnilo/prism": "0.0.
|
|
28
|
+
"@arnilo/prism": "0.0.16"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@arnilo/prism": "file:../.."
|