@ai-sdk/moonshotai 3.0.37 → 3.0.41
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 +49 -0
- package/README.md +44 -11
- package/dist/index.d.ts +61 -24
- package/dist/index.js +820 -291
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
- package/src/convert-moonshotai-chat-usage.ts +1 -1
- package/src/convert-to-moonshotai-chat-messages.ts +229 -19
- package/src/index.ts +3 -0
- package/src/moonshotai-chat-api-types.ts +58 -7
- package/src/moonshotai-chat-language-model.ts +356 -70
- package/src/moonshotai-chat-options.ts +181 -17
- package/src/moonshotai-prepare-tools.ts +24 -20
- package/src/moonshotai-provider.ts +10 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,54 @@
|
|
|
1
1
|
# @ai-sdk/moonshotai
|
|
2
2
|
|
|
3
|
+
## 3.0.41
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 87b49a2: fix(provider/moonshotai): preserve complete raw usage objects
|
|
8
|
+
- 48c5f46: Preserve documented Moonshot API error codes in HTTP and streaming errors.
|
|
9
|
+
- Updated dependencies [3e125ba]
|
|
10
|
+
- @ai-sdk/provider-utils@5.0.32
|
|
11
|
+
|
|
12
|
+
## 3.0.40
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- a336b12: Add first-class Moonshot V1 auto and vision-preview model IDs while preserving custom and retired model ID support.
|
|
17
|
+
- e4f665c: Preserve documented Moonshot AI chat response metadata for generate and stream.
|
|
18
|
+
- 85463b9: Add Moonshot AI Partial Mode support for continuing a final assistant message.
|
|
19
|
+
- d354a42: fix(provider/moonshotai): send max output tokens with the current Moonshot request field
|
|
20
|
+
- e5d5cbe: feat(provider/moonshotai): add predicted output support
|
|
21
|
+
- 3da2b7d: Support Kimi K3 dynamic tool-loading system messages.
|
|
22
|
+
|
|
23
|
+
## 3.0.39
|
|
24
|
+
|
|
25
|
+
### Patch Changes
|
|
26
|
+
|
|
27
|
+
- a06a14a: fix(provider/moonshotai): align thinking and reasoning options by model
|
|
28
|
+
- 8fca314: Support inline text file data and native `ms://` image and video provider references in Moonshot chat prompts.
|
|
29
|
+
- 35841f5: feat: normalize mid-stream provider error events across supported providers into public StreamProviderError instances and preserve provider-owned type, code, status, retry, and raw payload metadata
|
|
30
|
+
- 1d19b2a: Add Moonshot Chat Completions log probability options and provider metadata.
|
|
31
|
+
- d53589a: Accept Moonshot streaming tool calls without indices and preserve choice-level usage.
|
|
32
|
+
- 462c498: Normalize Moonshot structured output schemas and enable strict validation by default.
|
|
33
|
+
- 8037158: Use native JSON Schema structured outputs for official Moonshot V1 models.
|
|
34
|
+
- c88b272: Reject unsupported image and video media types before sending Moonshot chat requests.
|
|
35
|
+
- 4cf7c85: Add provider-specific names for Moonshot AI system, user, and assistant messages.
|
|
36
|
+
- 1cb0493: fix(provider/moonshotai): omit unsupported sampling settings for Kimi models
|
|
37
|
+
- 9645259: Omit required tool choice with a warning for Moonshot Kimi models that reject it.
|
|
38
|
+
- Updated dependencies [a9782e1]
|
|
39
|
+
- Updated dependencies [35841f5]
|
|
40
|
+
- Updated dependencies [d2f3353]
|
|
41
|
+
- @ai-sdk/provider-utils@5.0.31
|
|
42
|
+
|
|
43
|
+
## 3.0.38
|
|
44
|
+
|
|
45
|
+
### Patch Changes
|
|
46
|
+
|
|
47
|
+
- 2214258: Prevent negative text output token counts when providers report reasoning tokens. Perplexity reasoning tokens are now treated as separate from completion tokens.
|
|
48
|
+
- Updated dependencies [591d25b]
|
|
49
|
+
- @ai-sdk/provider@4.0.8
|
|
50
|
+
- @ai-sdk/provider-utils@5.0.30
|
|
51
|
+
|
|
3
52
|
## 3.0.37
|
|
4
53
|
|
|
5
54
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# AI SDK - Moonshot AI Provider
|
|
2
2
|
|
|
3
|
-
The **[Moonshot AI provider](https://ai-sdk.dev/providers/ai-sdk-providers/moonshotai)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model support for the [
|
|
3
|
+
The **[Moonshot AI provider](https://ai-sdk.dev/providers/ai-sdk-providers/moonshotai)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model support for the [Kimi API Platform](https://platform.kimi.ai/docs), including the Kimi model series.
|
|
4
4
|
|
|
5
5
|
> **Deploying to Vercel?** With Vercel's AI Gateway you can access Moonshot AI (and hundreds of models from other providers) — no additional packages, API keys, or extra cost. [Get started with AI Gateway](https://vercel.com/ai-gateway).
|
|
6
6
|
|
|
@@ -40,23 +40,56 @@ const { text } = await generateText({
|
|
|
40
40
|
});
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
##
|
|
43
|
+
## Reasoning Effort Example (Kimi K3)
|
|
44
44
|
|
|
45
45
|
```ts
|
|
46
|
-
import {
|
|
46
|
+
import {
|
|
47
|
+
moonshotai,
|
|
48
|
+
type MoonshotAILanguageModelOptions,
|
|
49
|
+
} from '@ai-sdk/moonshotai';
|
|
47
50
|
import { generateText } from 'ai';
|
|
48
51
|
|
|
49
|
-
const { text } = await generateText({
|
|
50
|
-
model: moonshotai('kimi-
|
|
52
|
+
const { text, reasoningText } = await generateText({
|
|
53
|
+
model: moonshotai('kimi-k3'),
|
|
51
54
|
prompt: 'Solve this problem step by step: What is 15% of 240?',
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
},
|
|
57
|
-
reasoningHistory: 'interleaved',
|
|
55
|
+
providerOptions: {
|
|
56
|
+
moonshotai: {
|
|
57
|
+
reasoningEffort: 'high',
|
|
58
|
+
} satisfies MoonshotAILanguageModelOptions,
|
|
58
59
|
},
|
|
59
60
|
});
|
|
61
|
+
|
|
62
|
+
console.log(reasoningText);
|
|
63
|
+
console.log(text);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Kimi K2.6 supports thinking and non-thinking modes. Enable it with
|
|
67
|
+
`thinking: { type: 'enabled' }` or disable it with
|
|
68
|
+
`thinking: { type: 'disabled' }`.
|
|
69
|
+
|
|
70
|
+
Kimi K2.7 Code always has thinking enabled and uses Preserved Thinking. Keep
|
|
71
|
+
reasoning history in multi-turn conversations:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import {
|
|
75
|
+
moonshotai,
|
|
76
|
+
type MoonshotAILanguageModelOptions,
|
|
77
|
+
} from '@ai-sdk/moonshotai';
|
|
78
|
+
import { generateText } from 'ai';
|
|
79
|
+
|
|
80
|
+
const { text, reasoningText } = await generateText({
|
|
81
|
+
model: moonshotai('kimi-k2.7-code'),
|
|
82
|
+
prompt: 'Solve this problem step by step: What is 15% of 240?',
|
|
83
|
+
providerOptions: {
|
|
84
|
+
moonshotai: {
|
|
85
|
+
thinking: { type: 'enabled' },
|
|
86
|
+
reasoningHistory: 'preserved',
|
|
87
|
+
} satisfies MoonshotAILanguageModelOptions,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
console.log(reasoningText);
|
|
92
|
+
console.log(text);
|
|
60
93
|
```
|
|
61
94
|
|
|
62
95
|
## Documentation
|
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,67 @@
|
|
|
1
|
-
import { ProviderV4, LanguageModelV4 } from '@ai-sdk/provider';
|
|
1
|
+
import { LanguageModelV4FunctionTool, ProviderV4, LanguageModelV4 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
3
|
import { z } from 'zod/v4';
|
|
4
4
|
|
|
5
|
-
type MoonshotAIChatModelId = 'moonshot-v1-8k' | 'moonshot-v1-32k' | 'moonshot-v1-128k' | 'kimi-k2.5' | 'kimi-k2.6' | 'kimi-k2.7-code' | 'kimi-k2.7-code-highspeed' | 'kimi-k3' | (string & {});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
5
|
+
type MoonshotAIChatModelId = 'moonshot-v1-auto' | 'moonshot-v1-8k' | 'moonshot-v1-32k' | 'moonshot-v1-128k' | 'moonshot-v1-8k-vision-preview' | 'moonshot-v1-32k-vision-preview' | 'moonshot-v1-128k-vision-preview' | 'kimi-k2.5' | 'kimi-k2.6' | 'kimi-k2.7-code' | 'kimi-k2.7-code-highspeed' | 'kimi-k3' | (string & {});
|
|
6
|
+
type MoonshotAILanguageModelOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* Whether to use strict JSON schema validation for structured outputs.
|
|
9
|
+
*
|
|
10
|
+
* @default true
|
|
11
|
+
*/
|
|
12
|
+
strictJsonSchema?: boolean;
|
|
13
|
+
/** Whether to return log probabilities for generated tokens. */
|
|
14
|
+
logprobs?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Number of most likely tokens to return at each token position.
|
|
17
|
+
* Setting this option automatically enables `logprobs`.
|
|
18
|
+
*/
|
|
19
|
+
topLogprobs?: number;
|
|
20
|
+
/** Reasoning effort for Kimi K3. */
|
|
21
|
+
reasoningEffort?: 'low' | 'high' | 'max';
|
|
22
|
+
/**
|
|
23
|
+
* Static predicted content that can accelerate responses when much of the
|
|
24
|
+
* output is known ahead of time.
|
|
25
|
+
*/
|
|
26
|
+
prediction?: {
|
|
27
|
+
type: 'content';
|
|
28
|
+
content: string | Array<{
|
|
29
|
+
type: 'text';
|
|
30
|
+
text: string;
|
|
31
|
+
}>;
|
|
32
|
+
};
|
|
33
|
+
/** Controls thinking on Kimi K2.5 and K2.6. K2.7 is always enabled. */
|
|
34
|
+
thinking?: {
|
|
35
|
+
type?: 'enabled' | 'disabled';
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Moonshot Chat Completions does not support thinking budgets.
|
|
38
|
+
* This value is ignored with a warning.
|
|
39
|
+
*/
|
|
40
|
+
budgetTokens?: number;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Controls preserved reasoning behavior in multi-turn conversations.
|
|
44
|
+
* `disabled` and `interleaved` are compatibility values that leave the
|
|
45
|
+
* request unchanged. `preserved` maps to `thinking.keep: 'all'` for Kimi
|
|
46
|
+
* K2.6. Kimi K2.7 and K3 preserve reasoning by default.
|
|
47
|
+
*/
|
|
48
|
+
reasoningHistory?: 'disabled' | 'interleaved' | 'preserved';
|
|
49
|
+
promptCacheKey?: string;
|
|
50
|
+
safetyIdentifier?: string;
|
|
51
|
+
};
|
|
52
|
+
declare const moonshotaiMessageProviderOptions: z.ZodObject<{
|
|
53
|
+
name: z.ZodOptional<z.ZodString>;
|
|
54
|
+
}, z.core.$strip>;
|
|
55
|
+
type MoonshotAIMessageProviderOptions = z.infer<typeof moonshotaiMessageProviderOptions>;
|
|
56
|
+
declare const moonshotaiAssistantMessageProviderOptions: z.ZodObject<{
|
|
57
|
+
name: z.ZodOptional<z.ZodString>;
|
|
58
|
+
partial: z.ZodOptional<z.ZodLiteral<true>>;
|
|
26
59
|
}, z.core.$strip>;
|
|
27
|
-
type
|
|
60
|
+
type MoonshotAIAssistantMessageProviderOptions = z.infer<typeof moonshotaiAssistantMessageProviderOptions>;
|
|
61
|
+
type MoonshotAISystemMessageProviderOptions = MoonshotAIMessageProviderOptions & {
|
|
62
|
+
/** Function tools to load at this point in a Kimi K3 conversation. */
|
|
63
|
+
tools?: Array<Pick<LanguageModelV4FunctionTool, 'type' | 'name' | 'description' | 'inputSchema' | 'strict'>>;
|
|
64
|
+
};
|
|
28
65
|
|
|
29
66
|
interface MoonshotAIProviderSettings {
|
|
30
67
|
/**
|
|
@@ -65,4 +102,4 @@ declare const moonshotai: MoonshotAIProvider;
|
|
|
65
102
|
|
|
66
103
|
declare const VERSION: string;
|
|
67
104
|
|
|
68
|
-
export { type MoonshotAIChatModelId, type MoonshotAILanguageModelOptions, type MoonshotAIProvider, type MoonshotAILanguageModelOptions as MoonshotAIProviderOptions, type MoonshotAIProviderSettings, VERSION, createMoonshotAI, moonshotai };
|
|
105
|
+
export { type MoonshotAIAssistantMessageProviderOptions, type MoonshotAIChatModelId, type MoonshotAILanguageModelOptions, type MoonshotAIMessageProviderOptions, type MoonshotAIProvider, type MoonshotAILanguageModelOptions as MoonshotAIProviderOptions, type MoonshotAIProviderSettings, type MoonshotAISystemMessageProviderOptions, VERSION, createMoonshotAI, moonshotai };
|