@ai-sdk/moonshotai 2.0.49 → 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.
@@ -3,26 +3,20 @@ import {
3
3
  type LanguageModelV3CallOptions,
4
4
  type SharedV3Warning,
5
5
  } from '@ai-sdk/provider';
6
+ import type { MoonshotAIFunctionTool } from './moonshotai-chat-api-types';
7
+ import type { MoonshotAIChatModelId } from './moonshotai-chat-options';
6
8
  import { normalizeJsonSchemaForMFJS } from './normalize-json-schema-for-mfjs';
7
9
 
8
10
  export function prepareTools({
9
11
  tools,
10
12
  toolChoice,
13
+ modelId,
11
14
  }: {
12
15
  tools: LanguageModelV3CallOptions['tools'];
13
16
  toolChoice?: LanguageModelV3CallOptions['toolChoice'];
17
+ modelId: MoonshotAIChatModelId;
14
18
  }): {
15
- tools:
16
- | undefined
17
- | Array<{
18
- type: 'function';
19
- function: {
20
- name: string;
21
- description: string | undefined;
22
- parameters: unknown;
23
- strict?: boolean;
24
- };
25
- }>;
19
+ tools: undefined | Array<MoonshotAIFunctionTool>;
26
20
  toolChoice:
27
21
  | { type: 'function'; function: { name: string } }
28
22
  | 'auto'
@@ -40,15 +34,7 @@ export function prepareTools({
40
34
  return { tools: undefined, toolChoice: undefined, toolWarnings };
41
35
  }
42
36
 
43
- const moonshotTools: Array<{
44
- type: 'function';
45
- function: {
46
- name: string;
47
- description: string | undefined;
48
- parameters: unknown;
49
- strict?: boolean;
50
- };
51
- }> = [];
37
+ const moonshotTools: Array<MoonshotAIFunctionTool> = [];
52
38
 
53
39
  for (const tool of tools) {
54
40
  if (tool.type === 'provider') {
@@ -78,7 +64,25 @@ export function prepareTools({
78
64
  switch (type) {
79
65
  case 'auto':
80
66
  case 'none':
67
+ return { tools: moonshotTools, toolChoice: type, toolWarnings };
81
68
  case 'required':
69
+ if (
70
+ modelId === 'kimi-k2.6' ||
71
+ modelId === 'kimi-k2.7-code' ||
72
+ modelId === 'kimi-k2.7-code-highspeed'
73
+ ) {
74
+ toolWarnings.push({
75
+ type: 'unsupported',
76
+ feature: `tool choice "required" for model "${modelId}"`,
77
+ details:
78
+ 'Moonshot AI rejects required tool choice for this model. The setting has been omitted; use "auto" or select a specific tool instead.',
79
+ });
80
+ return {
81
+ tools: moonshotTools,
82
+ toolChoice: undefined,
83
+ toolWarnings,
84
+ };
85
+ }
82
86
  return { tools: moonshotTools, toolChoice: type, toolWarnings };
83
87
  case 'tool':
84
88
  return {
@@ -58,8 +58,16 @@ const defaultBaseURL = 'https://api.moonshot.ai/v1';
58
58
  export function getModelStructuredOutputSupport(
59
59
  modelId: MoonshotAIChatModelId,
60
60
  ): boolean {
61
- if (modelId.startsWith('kimi-k')) return true;
62
- return false;
61
+ return (
62
+ modelId.startsWith('kimi-k') ||
63
+ modelId === 'moonshot-v1-8k' ||
64
+ modelId === 'moonshot-v1-32k' ||
65
+ modelId === 'moonshot-v1-128k' ||
66
+ modelId === 'moonshot-v1-auto' ||
67
+ modelId === 'moonshot-v1-8k-vision-preview' ||
68
+ modelId === 'moonshot-v1-32k-vision-preview' ||
69
+ modelId === 'moonshot-v1-128k-vision-preview'
70
+ );
63
71
  }
64
72
 
65
73
  export function createMoonshotAI(