@arnilo/prism-provider-kimi 0.3.0 → 0.3.1
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/dist/models.js +2 -2
- package/dist/moonshot.js +2 -1
- package/dist/provider.js +8 -7
- package/package.json +2 -2
package/dist/models.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { redactSecrets, resolveCredentialValue } from "@arnilo/prism";
|
|
1
|
+
import { redactSecrets, resolveCredentialValue, trimTrailingSlashes, } from "@arnilo/prism";
|
|
2
2
|
import { readBoundedResponseJson, readBoundedResponseText } from "@arnilo/prism/providers/transport";
|
|
3
3
|
export function defineKimiModel(config) {
|
|
4
4
|
return {
|
|
@@ -24,7 +24,7 @@ export function defineKimiModel(config) {
|
|
|
24
24
|
*/
|
|
25
25
|
export async function listKimiModels(options = {}) {
|
|
26
26
|
const provider = options.provider ?? "moonshot";
|
|
27
|
-
const baseUrl = (options.baseUrl ?? "https://api.moonshot.ai/v1")
|
|
27
|
+
const baseUrl = trimTrailingSlashes(options.baseUrl ?? "https://api.moonshot.ai/v1");
|
|
28
28
|
const token = await resolveCredentialValue(options.apiKey, { provider, name: "apiKey" });
|
|
29
29
|
const response = await (options.fetch ?? fetch)(`${baseUrl}/models`, {
|
|
30
30
|
method: "GET",
|
package/dist/moonshot.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { trimTrailingSlashes } from "@arnilo/prism";
|
|
1
2
|
import { applyOpenAIChatStructuredOutput } from "@arnilo/prism/providers/openai";
|
|
2
3
|
import { buildOpenAIChatBody, createOpenAICompatibleProvider, openAIChatEvents } from "@arnilo/prism/providers/openai-compatible";
|
|
3
4
|
import { kimiPreserveThinking, kimiReasoningEffort, kimiThinking, stripKimiThinkingCompat } from "./thinking.js";
|
|
@@ -10,7 +11,7 @@ import { kimiPreserveThinking, kimiReasoningEffort, kimiThinking, stripKimiThink
|
|
|
10
11
|
export function createMoonshotProvider(options = {}) {
|
|
11
12
|
return createOpenAICompatibleProvider({
|
|
12
13
|
id: options.id ?? "moonshot",
|
|
13
|
-
baseUrl: (options.baseUrl ?? "https://api.moonshot.ai/v1")
|
|
14
|
+
baseUrl: trimTrailingSlashes(options.baseUrl ?? "https://api.moonshot.ai/v1"),
|
|
14
15
|
apiKey: options.apiKey,
|
|
15
16
|
fetch: options.fetch,
|
|
16
17
|
strictCompletion: true,
|
package/dist/provider.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { assertStructuredOutputRequestSupported, providerDone, providerError, providerTextDelta, providerThinkingDelta, providerToolCall, providerToolCallDelta, providerUsage, resolveCredentialValue, toolCallFromArgumentsText, } from "@arnilo/prism";
|
|
1
|
+
import { assertStructuredOutputRequestSupported, canonicalizeJsonSchema, providerDone, providerError, providerTextDelta, providerThinkingDelta, providerToolCall, providerToolCallDelta, providerUsage, resolveCredentialValue, systemCacheControlField, toolCallFromArgumentsText, trimTrailingSlashes, } from "@arnilo/prism";
|
|
2
2
|
import { bytesToBase64, isPdfMediaType, rejectProviderMediaBlock, resolveProviderMediaMessages, serializePdfDocumentWireBlock, } from "@arnilo/prism/providers/media";
|
|
3
3
|
import { httpStatusError, readBoundedResponseText, readSseData } from "@arnilo/prism/providers/transport";
|
|
4
4
|
import { applyKimiAnthropicCacheControl } from "./cache.js";
|
|
5
5
|
import { kimiPreserveThinking, kimiReasoningEffort, kimiThinking, stripKimiThinkingCompat } from "./thinking.js";
|
|
6
6
|
export function createKimiCodingProvider(options = {}) {
|
|
7
7
|
const id = options.id ?? "kimi-coding";
|
|
8
|
-
const baseUrl = (options.baseUrl ?? "https://api.kimi.com/coding")
|
|
8
|
+
const baseUrl = trimTrailingSlashes(options.baseUrl ?? "https://api.kimi.com/coding");
|
|
9
9
|
return {
|
|
10
10
|
id,
|
|
11
11
|
async *generate(request) {
|
|
@@ -55,10 +55,7 @@ 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
|
|
59
|
-
.filter((m) => m.role === "system")
|
|
60
|
-
.map((m) => text(m, preserveThinking))
|
|
61
|
-
.join("\n\n") || undefined,
|
|
58
|
+
system: systemCacheControlField(messages, (m) => text(m, preserveThinking)),
|
|
62
59
|
tools: request.tools?.map(toTool),
|
|
63
60
|
stream: true,
|
|
64
61
|
thinking: kimiThinking(request),
|
|
@@ -199,7 +196,11 @@ function withMarker(item, marker) {
|
|
|
199
196
|
return marker ? { ...item, cache_control: marker } : item;
|
|
200
197
|
}
|
|
201
198
|
function toTool(tool) {
|
|
202
|
-
return clean({
|
|
199
|
+
return clean({
|
|
200
|
+
name: tool.name,
|
|
201
|
+
description: tool.description,
|
|
202
|
+
input_schema: canonicalizeJsonSchema(tool.parameters ?? { type: "object" }),
|
|
203
|
+
});
|
|
203
204
|
}
|
|
204
205
|
function text(message, preserveThinking = false) {
|
|
205
206
|
return message.content
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arnilo/prism-provider-kimi",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
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.3.
|
|
28
|
+
"@arnilo/prism": "^0.3.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@arnilo/prism": "file:../.."
|