@ai-sdk/moonshotai 3.0.31 → 3.0.33

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.
@@ -1,4 +1,3 @@
1
- import type { ProviderErrorStructure } from '@ai-sdk/openai-compatible';
2
1
  import {
3
2
  NoSuchModelError,
4
3
  type LanguageModelV4,
@@ -10,24 +9,11 @@ import {
10
9
  withUserAgentSuffix,
11
10
  type FetchFunction,
12
11
  } from '@ai-sdk/provider-utils';
13
- import { z } from 'zod/v4';
14
12
  import { MoonshotAIChatLanguageModel } from './moonshotai-chat-language-model';
15
13
  import type { MoonshotAIChatModelId } from './moonshotai-chat-options';
16
14
  import { VERSION } from './version';
17
15
 
18
- export type MoonshotAIErrorData = z.infer<typeof moonshotaiErrorSchema>;
19
-
20
- const moonshotaiErrorSchema = z.object({
21
- error: z.object({
22
- message: z.string(),
23
- type: z.string().nullish(),
24
- }),
25
- });
26
-
27
- const moonshotaiErrorStructure: ProviderErrorStructure<MoonshotAIErrorData> = {
28
- errorSchema: moonshotaiErrorSchema,
29
- errorToMessage: data => data.error.message,
30
- };
16
+ export type { MoonshotAIErrorData } from './moonshotai-chat-api-types';
31
17
 
32
18
  export interface MoonshotAIProviderSettings {
33
19
  /**
@@ -93,65 +79,14 @@ export function createMoonshotAI(
93
79
  `ai-sdk/moonshotai/${VERSION}`,
94
80
  );
95
81
 
96
- interface CommonModelConfig {
97
- provider: string;
98
- url: ({ path }: { path: string }) => string;
99
- headers: () => Record<string, string>;
100
- fetch?: FetchFunction;
101
- }
102
-
103
- const getCommonModelConfig = (modelType: string): CommonModelConfig => ({
104
- provider: `moonshotai.${modelType}`,
105
- url: ({ path }) => `${baseURL}${path}`,
106
- headers: getHeaders,
107
- fetch: options.fetch,
108
- });
109
-
110
82
  const createChatModel = (modelId: MoonshotAIChatModelId) => {
111
83
  return new MoonshotAIChatLanguageModel(modelId, {
112
- ...getCommonModelConfig('chat'),
84
+ provider: 'moonshotai.chat',
85
+ url: ({ path }) => `${baseURL}${path}`,
86
+ headers: getHeaders,
87
+ fetch: options.fetch,
113
88
  includeUsage: true,
114
- errorStructure: moonshotaiErrorStructure,
115
89
  supportsStructuredOutputs: getModelStructuredOutputSupport(modelId),
116
- transformRequestBody: (args: Record<string, any>) => {
117
- const thinking = args.thinking as
118
- | { type?: string; budgetTokens?: number }
119
- | undefined;
120
- const reasoningHistory = args.reasoningHistory as string | undefined;
121
-
122
- const { thinking: _, reasoningHistory: __, ...rest } = args;
123
-
124
- const schema = rest.response_format?.json_schema?.schema;
125
- if (schema != null) {
126
- // kimi-k2.5 produces nonsensical output when the top-level `$schema`
127
- // keyword injected by the AI SDK is present, even though it otherwise
128
- // supports structured outputs. Strip it from the schema sent to
129
- // Moonshot; the full original schema is still used for result validation.
130
- const { $schema: _$schema, ...schemaWithoutDollarSchema } = schema;
131
- rest.response_format = {
132
- ...rest.response_format,
133
- json_schema: {
134
- ...rest.response_format.json_schema,
135
- schema: schemaWithoutDollarSchema,
136
- },
137
- };
138
- }
139
-
140
- return {
141
- ...rest,
142
- ...(thinking && {
143
- thinking: {
144
- type: thinking.type,
145
- ...(thinking.budgetTokens !== undefined && {
146
- budget_tokens: thinking.budgetTokens,
147
- }),
148
- },
149
- }),
150
- ...(reasoningHistory && {
151
- reasoning_history: reasoningHistory,
152
- }),
153
- };
154
- },
155
90
  });
156
91
  };
157
92