@ai-sdk/moonshotai 2.0.48 → 2.0.51
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 +26 -0
- package/README.md +1 -2
- package/dist/index.d.mts +23 -24
- package/dist/index.d.ts +23 -24
- package/dist/index.js +242 -55
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +244 -57
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/convert-moonshotai-chat-usage.ts +1 -1
- package/src/convert-to-moonshotai-chat-messages.ts +57 -6
- package/src/moonshotai-chat-api-types.ts +2 -1
- package/src/moonshotai-chat-language-model.ts +164 -44
- package/src/moonshotai-chat-options.ts +63 -17
- package/src/moonshotai-prepare-tools.ts +21 -0
- package/src/moonshotai-provider.ts +10 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# @ai-sdk/moonshotai
|
|
2
2
|
|
|
3
|
+
## 2.0.51
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 8e81d87: Accept Moonshot streaming tool calls without indices and preserve choice-level usage.
|
|
8
|
+
- d48615f: Normalize Moonshot structured output schemas and enable strict validation by default.
|
|
9
|
+
- b6d6564: Use native JSON Schema structured outputs for official Moonshot V1 models.
|
|
10
|
+
- aa748d8: Reject unsupported image and video media types before sending Moonshot chat requests.
|
|
11
|
+
- e565062: fix(provider/moonshotai): send max output tokens with the current Moonshot request field
|
|
12
|
+
|
|
13
|
+
## 2.0.50
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 172effc: fix(provider/moonshotai): align thinking and reasoning options by model
|
|
18
|
+
- cc1743a: fix(provider/moonshotai): omit unsupported sampling settings for Kimi models
|
|
19
|
+
- 12e6be3: Omit required tool choice with a warning for Moonshot Kimi models that reject it.
|
|
20
|
+
|
|
21
|
+
## 2.0.49
|
|
22
|
+
|
|
23
|
+
### Patch Changes
|
|
24
|
+
|
|
25
|
+
- 313a441: Prevent negative text output token counts when providers report reasoning tokens. Perplexity reasoning tokens are now treated as separate from completion tokens.
|
|
26
|
+
- Updated dependencies [5642849]
|
|
27
|
+
- @ai-sdk/provider-utils@4.0.48
|
|
28
|
+
|
|
3
29
|
## 2.0.48
|
|
4
30
|
|
|
5
31
|
### Patch Changes
|
package/README.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
import { ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
import { z } from 'zod/v4';
|
|
4
3
|
|
|
5
|
-
type MoonshotAIChatModelId = 'moonshot-v1-8k' | 'moonshot-v1-32k' | 'moonshot-v1-128k' | 'kimi-k2' | 'kimi-k2-0905' | 'kimi-k2-thinking' | 'kimi-k2-thinking-turbo' | 'kimi-k2-turbo' | 'kimi-k2.5' | 'kimi-k3' | (string & {});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
4
|
+
type MoonshotAIChatModelId = 'moonshot-v1-8k' | 'moonshot-v1-32k' | 'moonshot-v1-128k' | 'moonshot-v1-auto' | 'moonshot-v1-8k-vision-preview' | 'moonshot-v1-32k-vision-preview' | 'moonshot-v1-128k-vision-preview' | 'kimi-k2' | 'kimi-k2-0905' | 'kimi-k2-thinking' | 'kimi-k2-thinking-turbo' | 'kimi-k2-turbo' | 'kimi-k2.5' | 'kimi-k3' | (string & {});
|
|
5
|
+
type MoonshotAILanguageModelOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* Whether to use strict JSON schema validation for structured outputs.
|
|
8
|
+
*
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
strictJsonSchema?: boolean;
|
|
12
|
+
/** Reasoning effort for Kimi K3. */
|
|
13
|
+
reasoningEffort?: 'low' | 'high' | 'max';
|
|
14
|
+
/** Controls thinking on Kimi K2.5 and K2.6. K2.7 is always enabled. */
|
|
15
|
+
thinking?: {
|
|
16
|
+
type?: 'enabled' | 'disabled';
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Moonshot Chat Completions does not support thinking budgets.
|
|
19
|
+
* This value is ignored with a warning.
|
|
20
|
+
*/
|
|
21
|
+
budgetTokens?: number;
|
|
22
|
+
};
|
|
23
|
+
reasoningHistory?: 'disabled' | 'interleaved' | 'preserved';
|
|
24
|
+
promptCacheKey?: string;
|
|
25
|
+
safetyIdentifier?: string;
|
|
26
|
+
};
|
|
28
27
|
|
|
29
28
|
interface MoonshotAIProviderSettings {
|
|
30
29
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,29 @@
|
|
|
1
1
|
import { ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
-
import { z } from 'zod/v4';
|
|
4
3
|
|
|
5
|
-
type MoonshotAIChatModelId = 'moonshot-v1-8k' | 'moonshot-v1-32k' | 'moonshot-v1-128k' | 'kimi-k2' | 'kimi-k2-0905' | 'kimi-k2-thinking' | 'kimi-k2-thinking-turbo' | 'kimi-k2-turbo' | 'kimi-k2.5' | 'kimi-k3' | (string & {});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
4
|
+
type MoonshotAIChatModelId = 'moonshot-v1-8k' | 'moonshot-v1-32k' | 'moonshot-v1-128k' | 'moonshot-v1-auto' | 'moonshot-v1-8k-vision-preview' | 'moonshot-v1-32k-vision-preview' | 'moonshot-v1-128k-vision-preview' | 'kimi-k2' | 'kimi-k2-0905' | 'kimi-k2-thinking' | 'kimi-k2-thinking-turbo' | 'kimi-k2-turbo' | 'kimi-k2.5' | 'kimi-k3' | (string & {});
|
|
5
|
+
type MoonshotAILanguageModelOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* Whether to use strict JSON schema validation for structured outputs.
|
|
8
|
+
*
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
strictJsonSchema?: boolean;
|
|
12
|
+
/** Reasoning effort for Kimi K3. */
|
|
13
|
+
reasoningEffort?: 'low' | 'high' | 'max';
|
|
14
|
+
/** Controls thinking on Kimi K2.5 and K2.6. K2.7 is always enabled. */
|
|
15
|
+
thinking?: {
|
|
16
|
+
type?: 'enabled' | 'disabled';
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Moonshot Chat Completions does not support thinking budgets.
|
|
19
|
+
* This value is ignored with a warning.
|
|
20
|
+
*/
|
|
21
|
+
budgetTokens?: number;
|
|
22
|
+
};
|
|
23
|
+
reasoningHistory?: 'disabled' | 'interleaved' | 'preserved';
|
|
24
|
+
promptCacheKey?: string;
|
|
25
|
+
safetyIdentifier?: string;
|
|
26
|
+
};
|
|
28
27
|
|
|
29
28
|
interface MoonshotAIProviderSettings {
|
|
30
29
|
/**
|
package/dist/index.js
CHANGED
|
@@ -36,6 +36,39 @@ var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
|
36
36
|
// src/convert-to-moonshotai-chat-messages.ts
|
|
37
37
|
var import_provider = require("@ai-sdk/provider");
|
|
38
38
|
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
39
|
+
var supportedImageMediaTypes = [
|
|
40
|
+
"image/jpeg",
|
|
41
|
+
"image/png",
|
|
42
|
+
"image/gif",
|
|
43
|
+
"image/webp",
|
|
44
|
+
"image/bmp",
|
|
45
|
+
"image/heic",
|
|
46
|
+
"image/heif"
|
|
47
|
+
];
|
|
48
|
+
var supportedVideoMediaTypes = [
|
|
49
|
+
"video/mp4",
|
|
50
|
+
"video/mpeg",
|
|
51
|
+
"video/mov",
|
|
52
|
+
"video/avi",
|
|
53
|
+
"video/x-flv",
|
|
54
|
+
"video/mpg",
|
|
55
|
+
"video/webm",
|
|
56
|
+
"video/wmv",
|
|
57
|
+
"video/3gpp"
|
|
58
|
+
];
|
|
59
|
+
function validateMediaType({
|
|
60
|
+
mediaType,
|
|
61
|
+
supportedMediaTypes,
|
|
62
|
+
topLevelMediaType
|
|
63
|
+
}) {
|
|
64
|
+
const normalizedMediaType = mediaType === `${topLevelMediaType}/*` ? topLevelMediaType === "image" ? "image/jpeg" : "video/mp4" : mediaType;
|
|
65
|
+
if (!supportedMediaTypes.includes(normalizedMediaType)) {
|
|
66
|
+
throw new import_provider.UnsupportedFunctionalityError({
|
|
67
|
+
functionality: `file part media type ${normalizedMediaType}`
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return normalizedMediaType;
|
|
71
|
+
}
|
|
39
72
|
function convertToMoonshotAIChatMessages(prompt) {
|
|
40
73
|
var _a;
|
|
41
74
|
const messages = [];
|
|
@@ -62,7 +95,11 @@ function convertToMoonshotAIChatMessages(prompt) {
|
|
|
62
95
|
}
|
|
63
96
|
case "file": {
|
|
64
97
|
if (part.mediaType.startsWith("image/")) {
|
|
65
|
-
const mediaType =
|
|
98
|
+
const mediaType = validateMediaType({
|
|
99
|
+
mediaType: part.mediaType,
|
|
100
|
+
supportedMediaTypes: supportedImageMediaTypes,
|
|
101
|
+
topLevelMediaType: "image"
|
|
102
|
+
});
|
|
66
103
|
return {
|
|
67
104
|
type: "image_url",
|
|
68
105
|
image_url: {
|
|
@@ -71,7 +108,11 @@ function convertToMoonshotAIChatMessages(prompt) {
|
|
|
71
108
|
};
|
|
72
109
|
}
|
|
73
110
|
if (part.mediaType.startsWith("video/")) {
|
|
74
|
-
const mediaType =
|
|
111
|
+
const mediaType = validateMediaType({
|
|
112
|
+
mediaType: part.mediaType,
|
|
113
|
+
supportedMediaTypes: supportedVideoMediaTypes,
|
|
114
|
+
topLevelMediaType: "video"
|
|
115
|
+
});
|
|
75
116
|
return {
|
|
76
117
|
type: "video_url",
|
|
77
118
|
video_url: {
|
|
@@ -202,7 +243,7 @@ function convertMoonshotAIChatUsage(usage) {
|
|
|
202
243
|
},
|
|
203
244
|
outputTokens: {
|
|
204
245
|
total: completionTokens,
|
|
205
|
-
text: completionTokens - reasoningTokens,
|
|
246
|
+
text: Math.max(0, completionTokens - reasoningTokens),
|
|
206
247
|
reasoning: reasoningTokens
|
|
207
248
|
},
|
|
208
249
|
raw: usage
|
|
@@ -300,7 +341,7 @@ var moonshotAIChatChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
300
341
|
reasoning_content: import_v4.z.string().nullish(),
|
|
301
342
|
tool_calls: import_v4.z.array(
|
|
302
343
|
import_v4.z.object({
|
|
303
|
-
index: import_v4.z.number(),
|
|
344
|
+
index: import_v4.z.number().nullish(),
|
|
304
345
|
id: import_v4.z.string().nullish(),
|
|
305
346
|
function: import_v4.z.object({
|
|
306
347
|
name: import_v4.z.string().nullish(),
|
|
@@ -309,7 +350,8 @@ var moonshotAIChatChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
309
350
|
})
|
|
310
351
|
).nullish()
|
|
311
352
|
}).nullish(),
|
|
312
|
-
finish_reason: import_v4.z.string().nullish()
|
|
353
|
+
finish_reason: import_v4.z.string().nullish(),
|
|
354
|
+
usage: tokenUsageSchema
|
|
313
355
|
})
|
|
314
356
|
),
|
|
315
357
|
usage: tokenUsageSchema
|
|
@@ -321,13 +363,34 @@ var moonshotAIChatChunkSchema = (0, import_provider_utils2.lazySchema)(
|
|
|
321
363
|
|
|
322
364
|
// src/moonshotai-chat-options.ts
|
|
323
365
|
var import_v42 = require("zod/v4");
|
|
366
|
+
function isMoonshotAIKimiModel(modelId) {
|
|
367
|
+
return getMoonshotAIModelFamily(modelId).startsWith("kimi-");
|
|
368
|
+
}
|
|
369
|
+
function getMoonshotAIModelFamily(modelId) {
|
|
370
|
+
if (modelId === "kimi-k2.5") return "kimi-k2.5";
|
|
371
|
+
if (modelId === "kimi-k2.6") return "kimi-k2.6";
|
|
372
|
+
if (modelId === "kimi-k2.7-code" || modelId === "kimi-k2.7-code-highspeed") {
|
|
373
|
+
return "kimi-k2.7";
|
|
374
|
+
}
|
|
375
|
+
if (modelId === "kimi-k3") return "kimi-k3";
|
|
376
|
+
if (modelId.startsWith("moonshot-v1-")) return "moonshot-v1";
|
|
377
|
+
return "unknown";
|
|
378
|
+
}
|
|
324
379
|
var moonshotaiLanguageModelOptions = import_v42.z.object({
|
|
380
|
+
/**
|
|
381
|
+
* Whether to use strict JSON schema validation for structured outputs.
|
|
382
|
+
*
|
|
383
|
+
* @default true
|
|
384
|
+
*/
|
|
385
|
+
strictJsonSchema: import_v42.z.boolean().optional(),
|
|
325
386
|
/**
|
|
326
387
|
* Reasoning effort for Kimi K3.
|
|
327
388
|
*/
|
|
328
389
|
reasoningEffort: import_v42.z.enum(["low", "high", "max"]).optional(),
|
|
329
390
|
thinking: import_v42.z.object({
|
|
330
391
|
type: import_v42.z.enum(["enabled", "disabled"]).optional(),
|
|
392
|
+
// Accepted so existing callers receive a migration warning. It remains
|
|
393
|
+
// in the public compatibility type below as a deprecated property.
|
|
331
394
|
budgetTokens: import_v42.z.number().int().min(1024).optional()
|
|
332
395
|
}).optional(),
|
|
333
396
|
reasoningHistory: import_v42.z.enum(["disabled", "interleaved", "preserved"]).optional(),
|
|
@@ -342,12 +405,6 @@ var moonshotaiLanguageModelOptions = import_v42.z.object({
|
|
|
342
405
|
*/
|
|
343
406
|
safetyIdentifier: import_v42.z.string().optional()
|
|
344
407
|
});
|
|
345
|
-
function getModelThinkingKeepSupport(modelId) {
|
|
346
|
-
return modelId === "kimi-k2.6" || modelId === "kimi-k3" || modelId.startsWith("kimi-k2.7-code");
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// src/moonshotai-prepare-tools.ts
|
|
350
|
-
var import_provider3 = require("@ai-sdk/provider");
|
|
351
408
|
|
|
352
409
|
// src/normalize-json-schema-for-mfjs.ts
|
|
353
410
|
var import_provider2 = require("@ai-sdk/provider");
|
|
@@ -433,9 +490,11 @@ function normalizeDefinition(definition, isRoot) {
|
|
|
433
490
|
}
|
|
434
491
|
|
|
435
492
|
// src/moonshotai-prepare-tools.ts
|
|
493
|
+
var import_provider3 = require("@ai-sdk/provider");
|
|
436
494
|
function prepareTools({
|
|
437
495
|
tools,
|
|
438
|
-
toolChoice
|
|
496
|
+
toolChoice,
|
|
497
|
+
modelId
|
|
439
498
|
}) {
|
|
440
499
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
441
500
|
const toolWarnings = [];
|
|
@@ -468,7 +527,20 @@ function prepareTools({
|
|
|
468
527
|
switch (type) {
|
|
469
528
|
case "auto":
|
|
470
529
|
case "none":
|
|
530
|
+
return { tools: moonshotTools, toolChoice: type, toolWarnings };
|
|
471
531
|
case "required":
|
|
532
|
+
if (modelId === "kimi-k2.6" || modelId === "kimi-k2.7-code" || modelId === "kimi-k2.7-code-highspeed") {
|
|
533
|
+
toolWarnings.push({
|
|
534
|
+
type: "unsupported",
|
|
535
|
+
feature: `tool choice "required" for model "${modelId}"`,
|
|
536
|
+
details: 'Moonshot AI rejects required tool choice for this model. The setting has been omitted; use "auto" or select a specific tool instead.'
|
|
537
|
+
});
|
|
538
|
+
return {
|
|
539
|
+
tools: moonshotTools,
|
|
540
|
+
toolChoice: void 0,
|
|
541
|
+
toolWarnings
|
|
542
|
+
};
|
|
543
|
+
}
|
|
472
544
|
return { tools: moonshotTools, toolChoice: type, toolWarnings };
|
|
473
545
|
case "tool":
|
|
474
546
|
return {
|
|
@@ -527,7 +599,7 @@ var MoonshotAIChatLanguageModel = class {
|
|
|
527
599
|
toolChoice,
|
|
528
600
|
tools
|
|
529
601
|
}) {
|
|
530
|
-
var _a, _b;
|
|
602
|
+
var _a, _b, _c;
|
|
531
603
|
const moonshotOptions = (_a = await (0, import_provider_utils3.parseProviderOptions)({
|
|
532
604
|
provider: this.providerOptionsName,
|
|
533
605
|
providerOptions,
|
|
@@ -541,22 +613,141 @@ var MoonshotAIChatLanguageModel = class {
|
|
|
541
613
|
if (seed != null) {
|
|
542
614
|
allWarnings.push({ type: "unsupported", feature: "seed" });
|
|
543
615
|
}
|
|
616
|
+
const supportsSamplingOptions = !isMoonshotAIKimiModel(this.modelId);
|
|
617
|
+
if (!supportsSamplingOptions && temperature != null) {
|
|
618
|
+
allWarnings.push({
|
|
619
|
+
type: "unsupported",
|
|
620
|
+
feature: "temperature",
|
|
621
|
+
details: `temperature is fixed by model "${this.modelId}" and has been omitted.`
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
if (!supportsSamplingOptions && topP != null) {
|
|
625
|
+
allWarnings.push({
|
|
626
|
+
type: "unsupported",
|
|
627
|
+
feature: "topP",
|
|
628
|
+
details: `topP is fixed by model "${this.modelId}" and has been omitted.`
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
if (!supportsSamplingOptions && frequencyPenalty != null) {
|
|
632
|
+
allWarnings.push({
|
|
633
|
+
type: "unsupported",
|
|
634
|
+
feature: "frequencyPenalty",
|
|
635
|
+
details: `frequencyPenalty is fixed by model "${this.modelId}" and has been omitted.`
|
|
636
|
+
});
|
|
637
|
+
}
|
|
638
|
+
if (!supportsSamplingOptions && presencePenalty != null) {
|
|
639
|
+
allWarnings.push({
|
|
640
|
+
type: "unsupported",
|
|
641
|
+
feature: "presencePenalty",
|
|
642
|
+
details: `presencePenalty is fixed by model "${this.modelId}" and has been omitted.`
|
|
643
|
+
});
|
|
644
|
+
}
|
|
544
645
|
const {
|
|
545
646
|
tools: moonshotTools,
|
|
546
647
|
toolChoice: moonshotToolChoice,
|
|
547
648
|
toolWarnings
|
|
548
|
-
} = prepareTools({ tools, toolChoice });
|
|
549
|
-
const
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
649
|
+
} = prepareTools({ tools, toolChoice, modelId: this.modelId });
|
|
650
|
+
const modelFamily = getMoonshotAIModelFamily(this.modelId);
|
|
651
|
+
const requestedThinking = moonshotOptions.thinking;
|
|
652
|
+
const requestedReasoningEffort = moonshotOptions.reasoningEffort;
|
|
653
|
+
const preserveReasoning = moonshotOptions.reasoningHistory === "preserved";
|
|
654
|
+
if ((requestedThinking == null ? void 0 : requestedThinking.budgetTokens) != null) {
|
|
655
|
+
allWarnings.push({
|
|
656
|
+
type: "other",
|
|
657
|
+
message: "providerOptions.moonshotai.thinking.budgetTokens is deprecated because Moonshot Chat Completions does not support budget_tokens. The option has been omitted."
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
let thinking;
|
|
661
|
+
let reasoningEffort;
|
|
662
|
+
const warnUnsupportedReasoningEffort = () => {
|
|
663
|
+
if (requestedReasoningEffort != null) {
|
|
555
664
|
allWarnings.push({
|
|
556
665
|
type: "unsupported",
|
|
557
|
-
feature:
|
|
666
|
+
feature: "reasoningEffort",
|
|
667
|
+
details: `reasoningEffort is only supported by Kimi K3 and has been omitted for model "${this.modelId}".`
|
|
558
668
|
});
|
|
559
669
|
}
|
|
670
|
+
};
|
|
671
|
+
switch (modelFamily) {
|
|
672
|
+
case "kimi-k3": {
|
|
673
|
+
if (requestedThinking != null) {
|
|
674
|
+
allWarnings.push({
|
|
675
|
+
type: "unsupported",
|
|
676
|
+
feature: "thinking",
|
|
677
|
+
details: "Kimi K3 always reasons and does not accept the thinking field. The option has been omitted."
|
|
678
|
+
});
|
|
679
|
+
}
|
|
680
|
+
reasoningEffort = requestedReasoningEffort;
|
|
681
|
+
break;
|
|
682
|
+
}
|
|
683
|
+
case "kimi-k2.7": {
|
|
684
|
+
warnUnsupportedReasoningEffort();
|
|
685
|
+
if ((requestedThinking == null ? void 0 : requestedThinking.type) === "disabled") {
|
|
686
|
+
allWarnings.push({
|
|
687
|
+
type: "unsupported",
|
|
688
|
+
feature: 'thinking.type "disabled"',
|
|
689
|
+
details: "Kimi K2.7 thinking cannot be disabled."
|
|
690
|
+
});
|
|
691
|
+
} else if ((requestedThinking == null ? void 0 : requestedThinking.type) === "enabled") {
|
|
692
|
+
thinking = { type: "enabled" };
|
|
693
|
+
}
|
|
694
|
+
break;
|
|
695
|
+
}
|
|
696
|
+
case "kimi-k2.6": {
|
|
697
|
+
warnUnsupportedReasoningEffort();
|
|
698
|
+
const thinkingType = requestedThinking == null ? void 0 : requestedThinking.type;
|
|
699
|
+
if (thinkingType != null || preserveReasoning) {
|
|
700
|
+
thinking = {
|
|
701
|
+
type: thinkingType != null ? thinkingType : "enabled",
|
|
702
|
+
...preserveReasoning ? { keep: "all" } : {}
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
break;
|
|
706
|
+
}
|
|
707
|
+
case "kimi-k2.5": {
|
|
708
|
+
warnUnsupportedReasoningEffort();
|
|
709
|
+
const thinkingType = requestedThinking == null ? void 0 : requestedThinking.type;
|
|
710
|
+
if (thinkingType != null) {
|
|
711
|
+
thinking = { type: thinkingType };
|
|
712
|
+
}
|
|
713
|
+
if (preserveReasoning) {
|
|
714
|
+
allWarnings.push({
|
|
715
|
+
type: "unsupported",
|
|
716
|
+
feature: `reasoningHistory 'preserved' is not supported by model "${this.modelId}"`
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
break;
|
|
720
|
+
}
|
|
721
|
+
case "moonshot-v1": {
|
|
722
|
+
warnUnsupportedReasoningEffort();
|
|
723
|
+
if (requestedThinking != null) {
|
|
724
|
+
allWarnings.push({
|
|
725
|
+
type: "unsupported",
|
|
726
|
+
feature: "thinking",
|
|
727
|
+
details: `thinking is not supported by model "${this.modelId}" and has been omitted.`
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
if (preserveReasoning) {
|
|
731
|
+
allWarnings.push({
|
|
732
|
+
type: "unsupported",
|
|
733
|
+
feature: `reasoningHistory 'preserved' is not supported by model "${this.modelId}"`
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
break;
|
|
737
|
+
}
|
|
738
|
+
case "unknown": {
|
|
739
|
+
reasoningEffort = requestedReasoningEffort;
|
|
740
|
+
if ((requestedThinking == null ? void 0 : requestedThinking.type) != null) {
|
|
741
|
+
thinking = { type: requestedThinking.type };
|
|
742
|
+
}
|
|
743
|
+
if (preserveReasoning) {
|
|
744
|
+
allWarnings.push({
|
|
745
|
+
type: "unsupported",
|
|
746
|
+
feature: `reasoningHistory 'preserved' is not supported by model "${this.modelId}"`
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
break;
|
|
750
|
+
}
|
|
560
751
|
}
|
|
561
752
|
let response_format;
|
|
562
753
|
if ((responseFormat == null ? void 0 : responseFormat.type) === "json") {
|
|
@@ -566,10 +757,8 @@ var MoonshotAIChatLanguageModel = class {
|
|
|
566
757
|
type: "json_schema",
|
|
567
758
|
json_schema: {
|
|
568
759
|
name: (_b = responseFormat.name) != null ? _b : "response",
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
description: responseFormat.description
|
|
572
|
-
}
|
|
760
|
+
strict: (_c = moonshotOptions.strictJsonSchema) != null ? _c : true,
|
|
761
|
+
schema: normalizeJsonSchemaForMFJS(schemaWithoutDollarSchema)
|
|
573
762
|
}
|
|
574
763
|
};
|
|
575
764
|
} else {
|
|
@@ -579,27 +768,19 @@ var MoonshotAIChatLanguageModel = class {
|
|
|
579
768
|
return {
|
|
580
769
|
args: {
|
|
581
770
|
model: this.modelId,
|
|
582
|
-
|
|
583
|
-
temperature,
|
|
584
|
-
top_p: topP,
|
|
585
|
-
frequency_penalty: frequencyPenalty,
|
|
586
|
-
presence_penalty: presencePenalty,
|
|
771
|
+
max_completion_tokens: maxOutputTokens,
|
|
772
|
+
temperature: supportsSamplingOptions ? temperature : void 0,
|
|
773
|
+
top_p: supportsSamplingOptions ? topP : void 0,
|
|
774
|
+
frequency_penalty: supportsSamplingOptions ? frequencyPenalty : void 0,
|
|
775
|
+
presence_penalty: supportsSamplingOptions ? presencePenalty : void 0,
|
|
587
776
|
response_format,
|
|
588
777
|
stop: stopSequences,
|
|
589
778
|
messages,
|
|
590
779
|
tools: moonshotTools,
|
|
591
780
|
tool_choice: moonshotToolChoice,
|
|
592
|
-
...thinking != null
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
...(thinking == null ? void 0 : thinking.budgetTokens) !== void 0 && {
|
|
596
|
-
budget_tokens: thinking.budgetTokens
|
|
597
|
-
},
|
|
598
|
-
...keep != null && { keep }
|
|
599
|
-
}
|
|
600
|
-
} : {},
|
|
601
|
-
...moonshotOptions.reasoningEffort != null && {
|
|
602
|
-
reasoning_effort: moonshotOptions.reasoningEffort
|
|
781
|
+
...thinking != null ? { thinking } : {},
|
|
782
|
+
...reasoningEffort != null && {
|
|
783
|
+
reasoning_effort: reasoningEffort
|
|
603
784
|
},
|
|
604
785
|
...moonshotOptions.promptCacheKey != null && {
|
|
605
786
|
prompt_cache_key: moonshotOptions.promptCacheKey
|
|
@@ -697,7 +878,8 @@ var MoonshotAIChatLanguageModel = class {
|
|
|
697
878
|
unified: "other",
|
|
698
879
|
raw: void 0
|
|
699
880
|
};
|
|
700
|
-
let
|
|
881
|
+
let topLevelUsage = void 0;
|
|
882
|
+
let choiceUsage = void 0;
|
|
701
883
|
let isFirstChunk = true;
|
|
702
884
|
let isActiveReasoning = false;
|
|
703
885
|
let isActiveText = false;
|
|
@@ -708,7 +890,7 @@ var MoonshotAIChatLanguageModel = class {
|
|
|
708
890
|
controller.enqueue({ type: "stream-start", warnings });
|
|
709
891
|
},
|
|
710
892
|
transform(chunk, controller) {
|
|
711
|
-
var _a2, _b2, _c, _d, _e, _f;
|
|
893
|
+
var _a2, _b2, _c, _d, _e, _f, _g;
|
|
712
894
|
if (options.includeRawChunks) {
|
|
713
895
|
controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
|
|
714
896
|
}
|
|
@@ -731,9 +913,12 @@ var MoonshotAIChatLanguageModel = class {
|
|
|
731
913
|
});
|
|
732
914
|
}
|
|
733
915
|
if (value.usage != null) {
|
|
734
|
-
|
|
916
|
+
topLevelUsage = value.usage;
|
|
735
917
|
}
|
|
736
918
|
const choice = value.choices[0];
|
|
919
|
+
if ((choice == null ? void 0 : choice.usage) != null) {
|
|
920
|
+
choiceUsage = choice.usage;
|
|
921
|
+
}
|
|
737
922
|
if ((choice == null ? void 0 : choice.finish_reason) != null) {
|
|
738
923
|
finishReason = {
|
|
739
924
|
unified: mapMoonshotAIFinishReason(choice.finish_reason),
|
|
@@ -785,8 +970,11 @@ var MoonshotAIChatLanguageModel = class {
|
|
|
785
970
|
});
|
|
786
971
|
isActiveReasoning = false;
|
|
787
972
|
}
|
|
788
|
-
for (const
|
|
789
|
-
|
|
973
|
+
for (const [
|
|
974
|
+
fallbackIndex,
|
|
975
|
+
toolCallDelta
|
|
976
|
+
] of delta.tool_calls.entries()) {
|
|
977
|
+
const index = (_a2 = toolCallDelta.index) != null ? _a2 : fallbackIndex;
|
|
790
978
|
if (toolCalls[index] == null) {
|
|
791
979
|
if (toolCallDelta.id == null) {
|
|
792
980
|
throw new import_provider4.InvalidResponseDataError({
|
|
@@ -794,7 +982,7 @@ var MoonshotAIChatLanguageModel = class {
|
|
|
794
982
|
message: `Expected 'id' to be a string.`
|
|
795
983
|
});
|
|
796
984
|
}
|
|
797
|
-
if (((
|
|
985
|
+
if (((_b2 = toolCallDelta.function) == null ? void 0 : _b2.name) == null) {
|
|
798
986
|
throw new import_provider4.InvalidResponseDataError({
|
|
799
987
|
data: toolCallDelta,
|
|
800
988
|
message: `Expected 'function.name' to be a string.`
|
|
@@ -810,12 +998,12 @@ var MoonshotAIChatLanguageModel = class {
|
|
|
810
998
|
type: "function",
|
|
811
999
|
function: {
|
|
812
1000
|
name: toolCallDelta.function.name,
|
|
813
|
-
arguments: (
|
|
1001
|
+
arguments: (_c = toolCallDelta.function.arguments) != null ? _c : ""
|
|
814
1002
|
},
|
|
815
1003
|
hasFinished: false
|
|
816
1004
|
};
|
|
817
1005
|
const toolCall2 = toolCalls[index];
|
|
818
|
-
if (((
|
|
1006
|
+
if (((_d = toolCall2.function) == null ? void 0 : _d.name) != null && ((_e = toolCall2.function) == null ? void 0 : _e.arguments) != null && toolCall2.function.arguments.length > 0) {
|
|
819
1007
|
controller.enqueue({
|
|
820
1008
|
type: "tool-input-delta",
|
|
821
1009
|
id: toolCall2.id,
|
|
@@ -828,13 +1016,13 @@ var MoonshotAIChatLanguageModel = class {
|
|
|
828
1016
|
if (toolCall.hasFinished) {
|
|
829
1017
|
continue;
|
|
830
1018
|
}
|
|
831
|
-
if (((
|
|
1019
|
+
if (((_f = toolCallDelta.function) == null ? void 0 : _f.arguments) != null) {
|
|
832
1020
|
toolCall.function.arguments += toolCallDelta.function.arguments;
|
|
833
1021
|
}
|
|
834
1022
|
controller.enqueue({
|
|
835
1023
|
type: "tool-input-delta",
|
|
836
1024
|
id: toolCall.id,
|
|
837
|
-
delta: (
|
|
1025
|
+
delta: (_g = toolCallDelta.function.arguments) != null ? _g : ""
|
|
838
1026
|
});
|
|
839
1027
|
}
|
|
840
1028
|
}
|
|
@@ -863,7 +1051,7 @@ var MoonshotAIChatLanguageModel = class {
|
|
|
863
1051
|
controller.enqueue({
|
|
864
1052
|
type: "finish",
|
|
865
1053
|
finishReason,
|
|
866
|
-
usage: convertMoonshotAIChatUsage(
|
|
1054
|
+
usage: convertMoonshotAIChatUsage(topLevelUsage != null ? topLevelUsage : choiceUsage)
|
|
867
1055
|
});
|
|
868
1056
|
}
|
|
869
1057
|
})
|
|
@@ -875,13 +1063,12 @@ var MoonshotAIChatLanguageModel = class {
|
|
|
875
1063
|
};
|
|
876
1064
|
|
|
877
1065
|
// src/version.ts
|
|
878
|
-
var VERSION = true ? "2.0.
|
|
1066
|
+
var VERSION = true ? "2.0.51" : "0.0.0-test";
|
|
879
1067
|
|
|
880
1068
|
// src/moonshotai-provider.ts
|
|
881
1069
|
var defaultBaseURL = "https://api.moonshot.ai/v1";
|
|
882
1070
|
function getModelStructuredOutputSupport(modelId) {
|
|
883
|
-
|
|
884
|
-
return false;
|
|
1071
|
+
return modelId.startsWith("kimi-k") || modelId === "moonshot-v1-8k" || modelId === "moonshot-v1-32k" || modelId === "moonshot-v1-128k" || modelId === "moonshot-v1-auto" || modelId === "moonshot-v1-8k-vision-preview" || modelId === "moonshot-v1-32k-vision-preview" || modelId === "moonshot-v1-128k-vision-preview";
|
|
885
1072
|
}
|
|
886
1073
|
function createMoonshotAI(options = {}) {
|
|
887
1074
|
var _a;
|