@ai-sdk/moonshotai 2.0.51 → 2.0.53
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 +21 -0
- package/README.md +44 -10
- package/dist/index.d.mts +41 -3
- package/dist/index.d.ts +41 -3
- package/dist/index.js +528 -271
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +532 -273
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/convert-to-moonshotai-chat-messages.ts +146 -6
- package/src/index.ts +3 -0
- package/src/moonshotai-chat-api-types.ts +56 -6
- package/src/moonshotai-chat-language-model.ts +79 -3
- package/src/moonshotai-chat-options.ts +125 -9
- package/src/moonshotai-prepare-tools.ts +3 -20
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# @ai-sdk/moonshotai
|
|
2
2
|
|
|
3
|
+
## 2.0.53
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e19917b: Add first-class Moonshot V1 auto and vision-preview model IDs while preserving custom and retired model ID support.
|
|
8
|
+
- dd5da26: Add Moonshot AI Partial Mode support for continuing a final assistant message.
|
|
9
|
+
- 921b74f: fix(provider/moonshotai): preserve complete raw usage objects
|
|
10
|
+
- 1fef0bb: Preserve documented Moonshot API error codes in HTTP and streaming errors.
|
|
11
|
+
- 84108e5: Add provider-specific names for Moonshot AI system, user, and assistant messages.
|
|
12
|
+
- a88fd1b: feat(provider/moonshotai): add predicted output support
|
|
13
|
+
- 38bf9fa: Support Kimi K3 dynamic tool-loading system messages.
|
|
14
|
+
|
|
15
|
+
## 2.0.52
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- 645e673: Preserve documented Moonshot AI chat response metadata for generate and stream.
|
|
20
|
+
- fe34c75: Add Moonshot Chat Completions log probability options and provider metadata.
|
|
21
|
+
- Updated dependencies [9a521b9]
|
|
22
|
+
- @ai-sdk/provider-utils@4.0.49
|
|
23
|
+
|
|
3
24
|
## 2.0.51
|
|
4
25
|
|
|
5
26
|
### 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,22 +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
|
-
reasoningHistory: 'preserved',
|
|
55
|
+
providerOptions: {
|
|
56
|
+
moonshotai: {
|
|
57
|
+
reasoningEffort: 'high',
|
|
58
|
+
} satisfies MoonshotAILanguageModelOptions,
|
|
57
59
|
},
|
|
58
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);
|
|
59
93
|
```
|
|
60
94
|
|
|
61
95
|
## Documentation
|
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
|
|
1
|
+
import { LanguageModelV3FunctionTool, ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { z } from 'zod/v4';
|
|
3
4
|
|
|
4
|
-
type MoonshotAIChatModelId = 'moonshot-v1-
|
|
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 & {});
|
|
5
6
|
type MoonshotAILanguageModelOptions = {
|
|
6
7
|
/**
|
|
7
8
|
* Whether to use strict JSON schema validation for structured outputs.
|
|
@@ -9,8 +10,26 @@ type MoonshotAILanguageModelOptions = {
|
|
|
9
10
|
* @default true
|
|
10
11
|
*/
|
|
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;
|
|
12
20
|
/** Reasoning effort for Kimi K3. */
|
|
13
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
|
+
};
|
|
14
33
|
/** Controls thinking on Kimi K2.5 and K2.6. K2.7 is always enabled. */
|
|
15
34
|
thinking?: {
|
|
16
35
|
type?: 'enabled' | 'disabled';
|
|
@@ -20,10 +39,29 @@ type MoonshotAILanguageModelOptions = {
|
|
|
20
39
|
*/
|
|
21
40
|
budgetTokens?: number;
|
|
22
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
|
+
*/
|
|
23
48
|
reasoningHistory?: 'disabled' | 'interleaved' | 'preserved';
|
|
24
49
|
promptCacheKey?: string;
|
|
25
50
|
safetyIdentifier?: string;
|
|
26
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>>;
|
|
59
|
+
}, z.core.$strip>;
|
|
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<LanguageModelV3FunctionTool, 'type' | 'name' | 'description' | 'inputSchema' | 'strict'>>;
|
|
64
|
+
};
|
|
27
65
|
|
|
28
66
|
interface MoonshotAIProviderSettings {
|
|
29
67
|
/**
|
|
@@ -62,4 +100,4 @@ interface MoonshotAIProvider extends ProviderV3 {
|
|
|
62
100
|
declare function createMoonshotAI(options?: MoonshotAIProviderSettings): MoonshotAIProvider;
|
|
63
101
|
declare const moonshotai: MoonshotAIProvider;
|
|
64
102
|
|
|
65
|
-
export { type MoonshotAIChatModelId, type MoonshotAILanguageModelOptions, type MoonshotAIProvider, type MoonshotAILanguageModelOptions as MoonshotAIProviderOptions, type MoonshotAIProviderSettings, createMoonshotAI, moonshotai };
|
|
103
|
+
export { type MoonshotAIAssistantMessageProviderOptions, type MoonshotAIChatModelId, type MoonshotAILanguageModelOptions, type MoonshotAIMessageProviderOptions, type MoonshotAIProvider, type MoonshotAILanguageModelOptions as MoonshotAIProviderOptions, type MoonshotAIProviderSettings, type MoonshotAISystemMessageProviderOptions, createMoonshotAI, moonshotai };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
|
|
1
|
+
import { LanguageModelV3FunctionTool, ProviderV3, LanguageModelV3 } from '@ai-sdk/provider';
|
|
2
2
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
|
3
|
+
import { z } from 'zod/v4';
|
|
3
4
|
|
|
4
|
-
type MoonshotAIChatModelId = 'moonshot-v1-
|
|
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 & {});
|
|
5
6
|
type MoonshotAILanguageModelOptions = {
|
|
6
7
|
/**
|
|
7
8
|
* Whether to use strict JSON schema validation for structured outputs.
|
|
@@ -9,8 +10,26 @@ type MoonshotAILanguageModelOptions = {
|
|
|
9
10
|
* @default true
|
|
10
11
|
*/
|
|
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;
|
|
12
20
|
/** Reasoning effort for Kimi K3. */
|
|
13
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
|
+
};
|
|
14
33
|
/** Controls thinking on Kimi K2.5 and K2.6. K2.7 is always enabled. */
|
|
15
34
|
thinking?: {
|
|
16
35
|
type?: 'enabled' | 'disabled';
|
|
@@ -20,10 +39,29 @@ type MoonshotAILanguageModelOptions = {
|
|
|
20
39
|
*/
|
|
21
40
|
budgetTokens?: number;
|
|
22
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
|
+
*/
|
|
23
48
|
reasoningHistory?: 'disabled' | 'interleaved' | 'preserved';
|
|
24
49
|
promptCacheKey?: string;
|
|
25
50
|
safetyIdentifier?: string;
|
|
26
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>>;
|
|
59
|
+
}, z.core.$strip>;
|
|
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<LanguageModelV3FunctionTool, 'type' | 'name' | 'description' | 'inputSchema' | 'strict'>>;
|
|
64
|
+
};
|
|
27
65
|
|
|
28
66
|
interface MoonshotAIProviderSettings {
|
|
29
67
|
/**
|
|
@@ -62,4 +100,4 @@ interface MoonshotAIProvider extends ProviderV3 {
|
|
|
62
100
|
declare function createMoonshotAI(options?: MoonshotAIProviderSettings): MoonshotAIProvider;
|
|
63
101
|
declare const moonshotai: MoonshotAIProvider;
|
|
64
102
|
|
|
65
|
-
export { type MoonshotAIChatModelId, type MoonshotAILanguageModelOptions, type MoonshotAIProvider, type MoonshotAILanguageModelOptions as MoonshotAIProviderOptions, type MoonshotAIProviderSettings, createMoonshotAI, moonshotai };
|
|
103
|
+
export { type MoonshotAIAssistantMessageProviderOptions, type MoonshotAIChatModelId, type MoonshotAILanguageModelOptions, type MoonshotAIMessageProviderOptions, type MoonshotAIProvider, type MoonshotAILanguageModelOptions as MoonshotAIProviderOptions, type MoonshotAIProviderSettings, type MoonshotAISystemMessageProviderOptions, createMoonshotAI, moonshotai };
|