@ai-sdk/moonshotai 0.0.19 → 0.0.24
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 +51 -0
- package/README.md +40 -12
- package/dist/index.d.mts +62 -18
- package/dist/index.d.ts +62 -18
- package/dist/index.js +767 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +762 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +3 -0
- package/src/moonshotai-chat-language-model.ts +607 -7
- package/src/moonshotai-chat-metadata-extractor.ts +112 -0
- package/src/moonshotai-chat-options.ts +187 -9
- package/src/moonshotai-provider.ts +17 -0
- package/src/normalize-json-schema-for-mfjs.ts +103 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,56 @@
|
|
|
1
1
|
# @ai-sdk/moonshotai
|
|
2
2
|
|
|
3
|
+
## 0.0.24
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9391f70: Add first-class Moonshot V1 auto and vision-preview model IDs while preserving custom and retired model ID support.
|
|
8
|
+
- e8a4fca: feat(provider/moonshotai): support Partial Mode for final assistant message prefixes
|
|
9
|
+
- 51f05ce: feat(provider/moonshotai): support chat log probabilities
|
|
10
|
+
- 497745e: Preserve Moonshot chat response metadata for generated and streamed responses.
|
|
11
|
+
- ff9e44b: Preserve documented Moonshot API error codes in HTTP and streaming errors.
|
|
12
|
+
- 30a28c2: Add provider-specific names for Moonshot AI system, user, and assistant messages.
|
|
13
|
+
- a5854a9: Add support for Moonshot predicted outputs.
|
|
14
|
+
- b909d7a: Support Kimi K3 dynamic tool-loading system messages.
|
|
15
|
+
|
|
16
|
+
## 0.0.23
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 71b1bb5: fix(provider/moonshotai): send max output tokens with the current Moonshot request field
|
|
21
|
+
- Updated dependencies [77d33c0]
|
|
22
|
+
- @ai-sdk/provider-utils@3.0.35
|
|
23
|
+
- @ai-sdk/openai-compatible@1.0.52
|
|
24
|
+
|
|
25
|
+
## 0.0.22
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- cef6cbe: Normalize Moonshot structured output schemas and enable strict validation by default.
|
|
30
|
+
- c4c0ba6: Use native JSON Schema structured outputs for official Moonshot V1 models.
|
|
31
|
+
- Updated dependencies [e264a35]
|
|
32
|
+
- @ai-sdk/openai-compatible@1.0.51
|
|
33
|
+
|
|
34
|
+
## 0.0.21
|
|
35
|
+
|
|
36
|
+
### Patch Changes
|
|
37
|
+
|
|
38
|
+
- 2836c36: fix(provider/moonshotai): align thinking and reasoning options by model
|
|
39
|
+
- 104d4e2: fix(provider/moonshotai): omit unsupported sampling parameters for Kimi models
|
|
40
|
+
- 47a3944: Omit required tool choice with a warning for Moonshot Kimi models that reject it.
|
|
41
|
+
- Updated dependencies [2fff9f1]
|
|
42
|
+
- Updated dependencies [f364ea0]
|
|
43
|
+
- @ai-sdk/provider-utils@3.0.34
|
|
44
|
+
- @ai-sdk/openai-compatible@1.0.50
|
|
45
|
+
|
|
46
|
+
## 0.0.20
|
|
47
|
+
|
|
48
|
+
### Patch Changes
|
|
49
|
+
|
|
50
|
+
- Updated dependencies [9e8e087]
|
|
51
|
+
- @ai-sdk/provider-utils@3.0.33
|
|
52
|
+
- @ai-sdk/openai-compatible@1.0.49
|
|
53
|
+
|
|
3
54
|
## 0.0.19
|
|
4
55
|
|
|
5
56
|
### 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,25 +40,53 @@ const { text } = await generateText({
|
|
|
40
40
|
});
|
|
41
41
|
```
|
|
42
42
|
|
|
43
|
-
##
|
|
43
|
+
## Reasoning Effort Example (Kimi K3)
|
|
44
44
|
|
|
45
45
|
```ts
|
|
46
|
-
import { moonshotai } from '@ai-sdk/moonshotai';
|
|
46
|
+
import { moonshotai, type MoonshotAIProviderOptions } from '@ai-sdk/moonshotai';
|
|
47
47
|
import { generateText } from 'ai';
|
|
48
48
|
|
|
49
|
-
const { text } = await generateText({
|
|
50
|
-
model: moonshotai('kimi-
|
|
51
|
-
prompt: '
|
|
49
|
+
const { text, reasoningText } = await generateText({
|
|
50
|
+
model: moonshotai('kimi-k3'),
|
|
51
|
+
prompt: 'Solve this problem step by step: What is 15% of 240?',
|
|
52
|
+
providerOptions: {
|
|
53
|
+
moonshotai: {
|
|
54
|
+
reasoningEffort: 'high',
|
|
55
|
+
} satisfies MoonshotAIProviderOptions,
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
console.log(reasoningText);
|
|
60
|
+
console.log(text);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Kimi K2.6 supports thinking and non-thinking modes. Enable it with
|
|
64
|
+
`thinking: { type: 'enabled' }` or disable it with
|
|
65
|
+
`thinking: { type: 'disabled' }`.
|
|
66
|
+
|
|
67
|
+
Kimi K2.7 Code always has thinking enabled and uses Preserved Thinking. Keep
|
|
68
|
+
reasoning history in multi-turn conversations:
|
|
69
|
+
|
|
70
|
+
```ts
|
|
71
|
+
import {
|
|
72
|
+
moonshotai,
|
|
73
|
+
type MoonshotAIProviderOptions,
|
|
74
|
+
} from '@ai-sdk/moonshotai';
|
|
75
|
+
import { generateText } from 'ai';
|
|
76
|
+
|
|
77
|
+
const { text, reasoningText } = await generateText({
|
|
78
|
+
model: moonshotai('kimi-k2.7-code'),
|
|
79
|
+
prompt: 'Solve this problem step by step: What is 15% of 240?',
|
|
52
80
|
providerOptions: {
|
|
53
81
|
moonshotai: {
|
|
54
|
-
thinking: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
reasoningHistory: 'interleaved',
|
|
59
|
-
} as MoonshotAIProviderOptions,
|
|
82
|
+
thinking: { type: 'enabled' },
|
|
83
|
+
reasoningHistory: 'preserved',
|
|
84
|
+
} satisfies MoonshotAIProviderOptions,
|
|
60
85
|
},
|
|
61
86
|
});
|
|
87
|
+
|
|
88
|
+
console.log(reasoningText);
|
|
89
|
+
console.log(text);
|
|
62
90
|
```
|
|
63
91
|
|
|
64
92
|
## Documentation
|
package/dist/index.d.mts
CHANGED
|
@@ -1,24 +1,68 @@
|
|
|
1
|
-
import { ProviderV2, LanguageModelV2 } from '@ai-sdk/provider';
|
|
1
|
+
import { LanguageModelV2FunctionTool, ProviderV2, LanguageModelV2 } 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' | '
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 MoonshotAIProviderOptions = {
|
|
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
|
+
};
|
|
50
|
+
declare const moonshotaiMessageProviderOptions: z.ZodObject<{
|
|
51
|
+
name: z.ZodOptional<z.ZodString>;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
type MoonshotAIMessageProviderOptions = z.infer<typeof moonshotaiMessageProviderOptions>;
|
|
54
|
+
declare const moonshotaiAssistantMessageProviderOptions: z.ZodObject<{
|
|
55
|
+
name: z.ZodOptional<z.ZodString>;
|
|
56
|
+
partial: z.ZodOptional<z.ZodLiteral<true>>;
|
|
20
57
|
}, z.core.$strip>;
|
|
21
|
-
type
|
|
58
|
+
type MoonshotAIAssistantMessageProviderOptions = z.infer<typeof moonshotaiAssistantMessageProviderOptions>;
|
|
59
|
+
type MoonshotAISystemMessageProviderOptions = MoonshotAIMessageProviderOptions & {
|
|
60
|
+
/** Function tools to load at this point in a Kimi K3 conversation. */
|
|
61
|
+
tools?: Array<Pick<LanguageModelV2FunctionTool, 'type' | 'name' | 'description' | 'inputSchema'> & {
|
|
62
|
+
/** Whether Moonshot should enforce the tool input schema strictly. */
|
|
63
|
+
strict?: boolean;
|
|
64
|
+
}>;
|
|
65
|
+
};
|
|
22
66
|
|
|
23
67
|
interface MoonshotAIProviderSettings {
|
|
24
68
|
/**
|
|
@@ -57,4 +101,4 @@ interface MoonshotAIProvider extends ProviderV2 {
|
|
|
57
101
|
declare function createMoonshotAI(options?: MoonshotAIProviderSettings): MoonshotAIProvider;
|
|
58
102
|
declare const moonshotai: MoonshotAIProvider;
|
|
59
103
|
|
|
60
|
-
export { type MoonshotAIChatModelId, type MoonshotAIProvider, type MoonshotAIProviderOptions, type MoonshotAIProviderSettings, createMoonshotAI, moonshotai };
|
|
104
|
+
export { type MoonshotAIAssistantMessageProviderOptions, type MoonshotAIChatModelId, type MoonshotAIMessageProviderOptions, type MoonshotAIProvider, type MoonshotAIProviderOptions, type MoonshotAIProviderSettings, type MoonshotAISystemMessageProviderOptions, createMoonshotAI, moonshotai };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,68 @@
|
|
|
1
|
-
import { ProviderV2, LanguageModelV2 } from '@ai-sdk/provider';
|
|
1
|
+
import { LanguageModelV2FunctionTool, ProviderV2, LanguageModelV2 } 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' | '
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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 MoonshotAIProviderOptions = {
|
|
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
|
+
};
|
|
50
|
+
declare const moonshotaiMessageProviderOptions: z.ZodObject<{
|
|
51
|
+
name: z.ZodOptional<z.ZodString>;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
type MoonshotAIMessageProviderOptions = z.infer<typeof moonshotaiMessageProviderOptions>;
|
|
54
|
+
declare const moonshotaiAssistantMessageProviderOptions: z.ZodObject<{
|
|
55
|
+
name: z.ZodOptional<z.ZodString>;
|
|
56
|
+
partial: z.ZodOptional<z.ZodLiteral<true>>;
|
|
20
57
|
}, z.core.$strip>;
|
|
21
|
-
type
|
|
58
|
+
type MoonshotAIAssistantMessageProviderOptions = z.infer<typeof moonshotaiAssistantMessageProviderOptions>;
|
|
59
|
+
type MoonshotAISystemMessageProviderOptions = MoonshotAIMessageProviderOptions & {
|
|
60
|
+
/** Function tools to load at this point in a Kimi K3 conversation. */
|
|
61
|
+
tools?: Array<Pick<LanguageModelV2FunctionTool, 'type' | 'name' | 'description' | 'inputSchema'> & {
|
|
62
|
+
/** Whether Moonshot should enforce the tool input schema strictly. */
|
|
63
|
+
strict?: boolean;
|
|
64
|
+
}>;
|
|
65
|
+
};
|
|
22
66
|
|
|
23
67
|
interface MoonshotAIProviderSettings {
|
|
24
68
|
/**
|
|
@@ -57,4 +101,4 @@ interface MoonshotAIProvider extends ProviderV2 {
|
|
|
57
101
|
declare function createMoonshotAI(options?: MoonshotAIProviderSettings): MoonshotAIProvider;
|
|
58
102
|
declare const moonshotai: MoonshotAIProvider;
|
|
59
103
|
|
|
60
|
-
export { type MoonshotAIChatModelId, type MoonshotAIProvider, type MoonshotAIProviderOptions, type MoonshotAIProviderSettings, createMoonshotAI, moonshotai };
|
|
104
|
+
export { type MoonshotAIAssistantMessageProviderOptions, type MoonshotAIChatModelId, type MoonshotAIMessageProviderOptions, type MoonshotAIProvider, type MoonshotAIProviderOptions, type MoonshotAIProviderSettings, type MoonshotAISystemMessageProviderOptions, createMoonshotAI, moonshotai };
|