@arnilo/prism-provider-kimi 0.0.8 → 0.0.96
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 +14 -1
- package/dist/moonshot.js +13 -13
- package/dist/provider.js +13 -13
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
## [0.0.96] - 2026-07-21
|
|
2
|
+
|
|
3
|
+
### Changed
|
|
4
|
+
|
|
5
|
+
- Released with exact 0.0.96 graph.
|
|
6
|
+
|
|
7
|
+
## [0.0.9] - 2026-07-21
|
|
8
|
+
|
|
9
|
+
- Released with the exact 0.0.9 first-party package graph.
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- Malformed streamed tool-call arguments yield recoverable tool calls via `toolCallFromArgumentsText` instead of throwing `ProviderTransportError` / terminal stream errors.
|
|
14
|
+
|
|
2
15
|
|
|
3
16
|
## [0.0.8] - 2026-07-20
|
|
4
17
|
|
package/dist/moonshot.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { assertStructuredOutputRequestSupported, providerDone, providerError, providerTextDelta, providerThinkingDelta, providerToolCall, providerToolCallDelta, providerUsage, resolveCredentialValue,
|
|
2
|
-
import { applyOpenAIChatStructuredOutput, mapOpenAIChatUsage, serializeOpenAITool
|
|
3
|
-
import {
|
|
4
|
-
import { kimiPreserveThinking, kimiReasoningEffort, kimiThinking, stripKimiThinkingCompat
|
|
1
|
+
import { assertStructuredOutputRequestSupported, providerDone, providerError, providerTextDelta, providerThinkingDelta, providerToolCall, providerToolCallDelta, providerUsage, resolveCredentialValue, toolCallFromArgumentsText } from "@arnilo/prism";
|
|
2
|
+
import { applyOpenAIChatStructuredOutput, mapOpenAIChatUsage, serializeOpenAITool } from "@arnilo/prism/providers/openai";
|
|
3
|
+
import { readBoundedResponseText, readSseData } from "@arnilo/prism/providers/transport";
|
|
4
|
+
import { kimiPreserveThinking, kimiReasoningEffort, kimiThinking, stripKimiThinkingCompat } from "./thinking.js";
|
|
5
5
|
/**
|
|
6
6
|
* Moonshot / Kimi Open Platform Chat Completions provider (`POST /chat/completions`).
|
|
7
7
|
* Official base: `https://api.moonshot.ai/v1` (or `api.moonshot.cn/v1`).
|
|
@@ -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
|
}
|
|
@@ -116,7 +116,7 @@ export async function* moonshotEvents(body, signal) {
|
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
118
|
for (const call of tools.values()) {
|
|
119
|
-
yield providerToolCall(
|
|
119
|
+
yield providerToolCall(toolCallFromArgumentsText(call.id, call.name, call.argumentsText));
|
|
120
120
|
}
|
|
121
121
|
yield providerDone(usage);
|
|
122
122
|
}
|
|
@@ -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,8 +1,8 @@
|
|
|
1
|
-
import { assertStructuredOutputRequestSupported, providerDone, providerError, providerTextDelta, providerThinkingDelta, providerToolCall, providerToolCallDelta, providerUsage, resolveCredentialValue,
|
|
2
|
-
import { bytesToBase64, isPdfMediaType, rejectProviderMediaBlock, resolveProviderMediaMessages, serializePdfDocumentWireBlock
|
|
3
|
-
import {
|
|
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
|
+
import { readBoundedResponseText, readSseData } from "@arnilo/prism/providers/transport";
|
|
4
4
|
import { applyKimiAnthropicCacheControl } from "./cache.js";
|
|
5
|
-
import { kimiPreserveThinking, kimiReasoningEffort, kimiThinking, stripKimiThinkingCompat
|
|
5
|
+
import { kimiPreserveThinking, kimiReasoningEffort, kimiThinking, stripKimiThinkingCompat } from "./thinking.js";
|
|
6
6
|
export function createKimiCodingProvider(options = {}) {
|
|
7
7
|
const id = options.id ?? "kimi-coding";
|
|
8
8
|
const baseUrl = (options.baseUrl ?? "https://api.kimi.com/coding").replace(/\/$/, "");
|
|
@@ -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) {
|
|
@@ -63,7 +63,7 @@ export async function kimiAnthropicBody(request) {
|
|
|
63
63
|
...parameters,
|
|
64
64
|
max_tokens: maxTokens ?? request.model.limits?.maxOutputTokens ?? 4096,
|
|
65
65
|
...stripKimiThinkingCompat(request.options?.compat),
|
|
66
|
-
...request.options?.extra
|
|
66
|
+
...request.options?.extra
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
69
|
export async function* kimiAnthropicEvents(body, signal) {
|
|
@@ -110,7 +110,7 @@ export async function* kimiAnthropicEvents(body, signal) {
|
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
112
|
for (const call of blocks.values()) {
|
|
113
|
-
yield providerToolCall(
|
|
113
|
+
yield providerToolCall(toolCallFromArgumentsText(call.id, call.name, call.argumentsText));
|
|
114
114
|
}
|
|
115
115
|
yield providerDone(usage);
|
|
116
116
|
}
|
|
@@ -125,8 +125,8 @@ async function toMessage(message, model, preserveThinking, resolvedMedia) {
|
|
|
125
125
|
type: "tool_result",
|
|
126
126
|
tool_use_id: result?.toolCallId ?? "",
|
|
127
127
|
content: result ? JSON.stringify(result.result ?? result.error ?? null) : "",
|
|
128
|
-
...(last?.cache_control ? { cache_control: last.cache_control } : {})
|
|
129
|
-
}]
|
|
128
|
+
...(last?.cache_control ? { cache_control: last.cache_control } : {})
|
|
129
|
+
}]
|
|
130
130
|
};
|
|
131
131
|
}
|
|
132
132
|
const content = [];
|
|
@@ -171,7 +171,7 @@ function toAnthropicDocument(part, resolvedMedia) {
|
|
|
171
171
|
return serializePdfDocumentWireBlock({
|
|
172
172
|
mediaType: resolved.mediaType,
|
|
173
173
|
data: bytesToBase64(resolved.bytes),
|
|
174
|
-
title: resolved.name
|
|
174
|
+
title: resolved.name
|
|
175
175
|
});
|
|
176
176
|
}
|
|
177
177
|
function toAnthropicFile(part, resolvedMedia) {
|
|
@@ -182,7 +182,7 @@ function toAnthropicFile(part, resolvedMedia) {
|
|
|
182
182
|
return serializePdfDocumentWireBlock({
|
|
183
183
|
mediaType: resolved.mediaType,
|
|
184
184
|
data: bytesToBase64(resolved.bytes),
|
|
185
|
-
title: resolved.name
|
|
185
|
+
title: resolved.name
|
|
186
186
|
});
|
|
187
187
|
}
|
|
188
188
|
function withMarker(item, marker) {
|
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.96",
|
|
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.96"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@arnilo/prism": "file:../.."
|