@ai-sdk/moonshotai 3.0.60 → 3.0.61

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/dist/index.js CHANGED
@@ -1,1405 +1,1146 @@
1
- // src/moonshotai-provider.ts
2
- import {
3
- NoSuchModelError
4
- } from "@ai-sdk/provider";
5
- import {
6
- loadApiKey,
7
- withoutTrailingSlash,
8
- withUserAgentSuffix
9
- } from "@ai-sdk/provider-utils";
10
-
11
- // src/moonshotai-chat-language-model.ts
12
- import {
13
- combineHeaders,
14
- createEventSourceResponseHandler,
15
- createJsonErrorResponseHandler,
16
- createJsonResponseHandler,
17
- createLanguageModelResponseMetadata as getResponseMetadata,
18
- createProviderStreamError,
19
- generateId,
20
- isCustomReasoning,
21
- mapReasoningToProviderEffort,
22
- parseProviderOptions as parseProviderOptions2,
23
- postJsonToApi,
24
- serializeModelOptions,
25
- StreamingToolCallTracker,
26
- WORKFLOW_SERIALIZE,
27
- WORKFLOW_DESERIALIZE
28
- } from "@ai-sdk/provider-utils";
29
-
30
- // src/convert-to-moonshotai-chat-messages.ts
31
- import {
32
- InvalidPromptError,
33
- UnsupportedFunctionalityError as UnsupportedFunctionalityError3
34
- } from "@ai-sdk/provider";
35
- import {
36
- convertBase64ToUint8Array,
37
- convertToBase64,
38
- getTopLevelMediaType,
39
- parseProviderOptions,
40
- resolveProviderReference,
41
- resolveFullMediaType
42
- } from "@ai-sdk/provider-utils";
43
-
44
- // src/moonshotai-chat-options.ts
1
+ import { InvalidPromptError, NoSuchModelError, UnsupportedFunctionalityError } from "@ai-sdk/provider";
2
+ import { StreamingToolCallTracker, WORKFLOW_DESERIALIZE, WORKFLOW_SERIALIZE, combineHeaders, convertBase64ToUint8Array, convertToBase64, createEventSourceResponseHandler, createJsonErrorResponseHandler, createJsonResponseHandler, createLanguageModelResponseMetadata, createNullLanguageModelUsage, createProviderStreamError, generateId, getTopLevelMediaType, isCustomReasoning, isRecord, lazySchema, loadApiKey, mapReasoningToProviderEffort, parseProviderOptions, postJsonToApi, resolveFullMediaType, resolveProviderReference, serializeModelOptions, withUserAgentSuffix, withoutTrailingSlash, zodSchema } from "@ai-sdk/provider-utils";
45
3
  import { z } from "zod/v4";
4
+ //#region src/moonshotai-chat-options.ts
46
5
  function isMoonshotAIKimiModel(modelId) {
47
- return getMoonshotAIModelFamily(modelId).startsWith("kimi-");
6
+ return getMoonshotAIModelFamily(modelId).startsWith("kimi-");
48
7
  }
49
8
  function getMoonshotAIModelFamily(modelId) {
50
- if (modelId === "kimi-k2.5") return "kimi-k2.5";
51
- if (modelId === "kimi-k2.6") return "kimi-k2.6";
52
- if (modelId === "kimi-k2.7-code" || modelId === "kimi-k2.7-code-highspeed") {
53
- return "kimi-k2.7";
54
- }
55
- if (modelId === "kimi-k3") return "kimi-k3";
56
- if (modelId.startsWith("moonshot-v1-")) return "moonshot-v1";
57
- return "unknown";
9
+ if (modelId === "kimi-k2.5") return "kimi-k2.5";
10
+ if (modelId === "kimi-k2.6") return "kimi-k2.6";
11
+ if (modelId === "kimi-k2.7-code" || modelId === "kimi-k2.7-code-highspeed") return "kimi-k2.7";
12
+ if (modelId === "kimi-k3") return "kimi-k3";
13
+ if (modelId.startsWith("moonshot-v1-")) return "moonshot-v1";
14
+ return "unknown";
58
15
  }
59
- var moonshotaiLanguageModelOptions = z.object({
60
- /**
61
- * Whether to use strict JSON schema validation for structured outputs.
62
- *
63
- * @default true
64
- */
65
- strictJsonSchema: z.boolean().optional(),
66
- /**
67
- * Whether to return log probabilities for generated tokens.
68
- */
69
- logprobs: z.boolean().optional(),
70
- /**
71
- * Number of most likely tokens to return at each token position.
72
- *
73
- * Setting this option automatically enables `logprobs`.
74
- */
75
- topLogprobs: z.number().int().min(0).max(20).optional(),
76
- /**
77
- * Reasoning effort for Kimi K3. Supports `low`, `high`, and `max`;
78
- * defaults to `max`.
79
- */
80
- reasoningEffort: z.enum(["low", "high", "max"]).optional(),
81
- /**
82
- * Static predicted content that can accelerate responses when much of the
83
- * output is known ahead of time.
84
- */
85
- prediction: z.object({
86
- type: z.literal("content"),
87
- content: z.union([
88
- z.string(),
89
- z.array(z.object({ type: z.literal("text"), text: z.string() }))
90
- ])
91
- }).optional(),
92
- /**
93
- * Thinking configuration for Kimi K2.x models. Kimi K2.5 and K2.6 support
94
- * enabling or disabling thinking. Kimi K2.7 Code always has thinking
95
- * enabled.
96
- */
97
- thinking: z.object({
98
- type: z.enum(["enabled", "disabled"]).optional(),
99
- /**
100
- * @deprecated Moonshot Chat Completions does not support thinking
101
- * budgets. Accepted for backwards compatibility, then omitted with a
102
- * warning.
103
- */
104
- budgetTokens: z.number().int().min(1024).optional()
105
- }).optional(),
106
- /**
107
- * Controls preserved reasoning behavior in multi-turn conversations.
108
- * `disabled` and `interleaved` are compatibility values that leave the
109
- * request unchanged. `preserved` maps to `thinking.keep: 'all'` for Kimi
110
- * K2.6. Kimi K2.7 and K3 preserve reasoning by default.
111
- */
112
- reasoningHistory: z.enum(["disabled", "interleaved", "preserved"]).optional(),
113
- /**
114
- * Used to cache responses for similar requests to optimize cache hit rates.
115
- * Typically a session or task id.
116
- */
117
- promptCacheKey: z.string().optional(),
118
- /**
119
- * A stable identifier used to help Moonshot detect users violating usage
120
- * policies. Recommended to hash the username or email address.
121
- */
122
- safetyIdentifier: z.string().optional()
123
- });
124
- var moonshotaiMessageProviderOptions = z.object({
125
- /**
126
- * The name of the participant represented by the message.
127
- *
128
- * Supported on system, user, and assistant messages.
129
- */
130
- name: z.string().optional()
131
- });
132
- var moonshotaiAssistantMessageProviderOptions = moonshotaiMessageProviderOptions.extend({
133
- /**
134
- * Whether the assistant message content is a partial response that Moonshot
135
- * should continue. Only supported on the final assistant message and cannot
136
- * be combined with JSON object response format.
137
- */
138
- partial: z.literal(true).optional()
139
- });
140
- var moonshotaiDynamicToolSchema = z.object({
141
- type: z.literal("function"),
142
- name: z.string(),
143
- description: z.string().optional(),
144
- inputSchema: z.record(z.string(), z.unknown()),
145
- strict: z.boolean().optional()
16
+ const moonshotaiLanguageModelOptions = z.object({
17
+ /**
18
+ * Whether to use strict JSON schema validation for structured outputs.
19
+ *
20
+ * @default true
21
+ */
22
+ strictJsonSchema: z.boolean().optional(),
23
+ /**
24
+ * Whether to return log probabilities for generated tokens.
25
+ */
26
+ logprobs: z.boolean().optional(),
27
+ /**
28
+ * Number of most likely tokens to return at each token position.
29
+ *
30
+ * Setting this option automatically enables `logprobs`.
31
+ */
32
+ topLogprobs: z.number().int().min(0).max(20).optional(),
33
+ /**
34
+ * Reasoning effort for Kimi K3. Supports `low`, `high`, and `max`;
35
+ * defaults to `max`.
36
+ */
37
+ reasoningEffort: z.enum([
38
+ "low",
39
+ "high",
40
+ "max"
41
+ ]).optional(),
42
+ /**
43
+ * Static predicted content that can accelerate responses when much of the
44
+ * output is known ahead of time.
45
+ */
46
+ prediction: z.object({
47
+ type: z.literal("content"),
48
+ content: z.union([z.string(), z.array(z.object({
49
+ type: z.literal("text"),
50
+ text: z.string()
51
+ }))])
52
+ }).optional(),
53
+ /**
54
+ * Thinking configuration for Kimi K2.x models. Kimi K2.5 and K2.6 support
55
+ * enabling or disabling thinking. Kimi K2.7 Code always has thinking
56
+ * enabled.
57
+ */
58
+ thinking: z.object({
59
+ type: z.enum(["enabled", "disabled"]).optional(),
60
+ /**
61
+ * @deprecated Moonshot Chat Completions does not support thinking
62
+ * budgets. Accepted for backwards compatibility, then omitted with a
63
+ * warning.
64
+ */
65
+ budgetTokens: z.number().int().min(1024).optional()
66
+ }).optional(),
67
+ /**
68
+ * Controls preserved reasoning behavior in multi-turn conversations.
69
+ * `disabled` and `interleaved` are compatibility values that leave the
70
+ * request unchanged. `preserved` maps to `thinking.keep: 'all'` for Kimi
71
+ * K2.6. Kimi K2.7 and K3 preserve reasoning by default.
72
+ */
73
+ reasoningHistory: z.enum([
74
+ "disabled",
75
+ "interleaved",
76
+ "preserved"
77
+ ]).optional(),
78
+ /**
79
+ * Used to cache responses for similar requests to optimize cache hit rates.
80
+ * Typically a session or task id.
81
+ */
82
+ promptCacheKey: z.string().optional(),
83
+ /**
84
+ * A stable identifier used to help Moonshot detect users violating usage
85
+ * policies. Recommended to hash the username or email address.
86
+ */
87
+ safetyIdentifier: z.string().optional()
146
88
  });
147
- var moonshotaiAllMessageProviderOptions = moonshotaiAssistantMessageProviderOptions.extend({
148
- /** Function tools to load at this point in a Kimi K3 conversation. */
149
- tools: z.array(moonshotaiDynamicToolSchema).optional()
89
+ const moonshotaiAssistantMessageProviderOptions = z.object({
90
+ /**
91
+ * The name of the participant represented by the message.
92
+ *
93
+ * Supported on system, user, and assistant messages.
94
+ */
95
+ name: z.string().optional() }).extend({
96
+ /**
97
+ * Whether the assistant message content is a partial response that Moonshot
98
+ * should continue. Only supported on the final assistant message and cannot
99
+ * be combined with JSON object response format.
100
+ */
101
+ partial: z.literal(true).optional() });
102
+ const moonshotaiDynamicToolSchema = z.object({
103
+ type: z.literal("function"),
104
+ name: z.string(),
105
+ description: z.string().optional(),
106
+ inputSchema: z.record(z.string(), z.unknown()),
107
+ strict: z.boolean().optional()
150
108
  });
151
-
152
- // src/moonshotai-prepare-tools.ts
153
- import {
154
- UnsupportedFunctionalityError as UnsupportedFunctionalityError2
155
- } from "@ai-sdk/provider";
156
-
157
- // src/normalize-json-schema-for-mfjs.ts
158
- import { UnsupportedFunctionalityError } from "@ai-sdk/provider";
159
- import { isRecord } from "@ai-sdk/provider-utils";
160
- var SCHEMA_ARRAY_KEYS = ["allOf", "anyOf", "oneOf", "prefixItems"];
161
- var SCHEMA_MAP_KEYS = [
162
- "properties",
163
- "patternProperties",
164
- "$defs",
165
- "dependentSchemas"
109
+ const moonshotaiAllMessageProviderOptions = moonshotaiAssistantMessageProviderOptions.extend({
110
+ /** Function tools to load at this point in a Kimi K3 conversation. */
111
+ tools: z.array(moonshotaiDynamicToolSchema).optional() });
112
+ //#endregion
113
+ //#region src/normalize-json-schema-for-mfjs.ts
114
+ const SCHEMA_ARRAY_KEYS = [
115
+ "allOf",
116
+ "anyOf",
117
+ "oneOf",
118
+ "prefixItems"
119
+ ];
120
+ const SCHEMA_MAP_KEYS = [
121
+ "properties",
122
+ "patternProperties",
123
+ "$defs",
124
+ "dependentSchemas"
166
125
  ];
167
- var SCHEMA_SINGLE_KEYS = [
168
- "additionalProperties",
169
- "propertyNames",
170
- "items",
171
- "contains",
172
- "not",
173
- "if",
174
- "then",
175
- "else"
126
+ const SCHEMA_SINGLE_KEYS = [
127
+ "additionalProperties",
128
+ "propertyNames",
129
+ "items",
130
+ "contains",
131
+ "not",
132
+ "if",
133
+ "then",
134
+ "else"
176
135
  ];
136
+ /**
137
+ * Normalizes a JSON Schema to the subset Moonshot's MFJS validator accepts:
138
+ * `object` root required, tuple `items` become `prefixItems`, and `type` next
139
+ * to `anyOf` moves into the branches. Everything else passes through. The
140
+ * full original schema is still used for AI SDK result validation.
141
+ */
177
142
  function normalizeJsonSchemaForMFJS(schema) {
178
- return normalizeDefinition(schema, true);
143
+ return normalizeDefinition(schema, true);
179
144
  }
180
145
  function normalizeDefinition(definition, isRoot) {
181
- if (typeof definition === "boolean" || !isRecord(definition)) {
182
- if (isRoot) {
183
- throw new UnsupportedFunctionalityError({
184
- functionality: 'tool parameters must be a JSON Schema object with type "object" for moonshotai (MFJS)'
185
- });
186
- }
187
- return definition;
188
- }
189
- if (isRoot && definition.type !== "object") {
190
- throw new UnsupportedFunctionalityError({
191
- functionality: 'tool parameters must be a JSON Schema object with type "object" for moonshotai (MFJS)'
192
- });
193
- }
194
- const result = { ...definition };
195
- if (Array.isArray(result.items)) {
196
- const tuple = result.items;
197
- result.prefixItems = [
198
- ...Array.isArray(result.prefixItems) ? result.prefixItems : [],
199
- ...tuple.map((item) => normalizeDefinition(item, false))
200
- ];
201
- delete result.items;
202
- } else if (isRecord(result.items)) {
203
- result.items = normalizeDefinition(result.items, false);
204
- }
205
- if (typeof result.type === "string" && Array.isArray(result.anyOf)) {
206
- const parentType = result.type;
207
- delete result.type;
208
- result.anyOf = result.anyOf.map(
209
- (branch) => isRecord(branch) && branch.type == null ? { type: parentType, ...branch } : branch
210
- );
211
- }
212
- for (const key of SCHEMA_ARRAY_KEYS) {
213
- const value = result[key];
214
- if (Array.isArray(value)) {
215
- result[key] = value.map((item) => normalizeDefinition(item, false));
216
- }
217
- }
218
- for (const key of SCHEMA_MAP_KEYS) {
219
- const value = result[key];
220
- if (isRecord(value)) {
221
- result[key] = Object.fromEntries(
222
- Object.entries(value).map(([k, v]) => [
223
- k,
224
- normalizeDefinition(v, false)
225
- ])
226
- );
227
- }
228
- }
229
- for (const key of SCHEMA_SINGLE_KEYS) {
230
- const value = result[key];
231
- if (isRecord(value) || typeof value === "boolean") {
232
- result[key] = normalizeDefinition(value, false);
233
- }
234
- }
235
- return result;
146
+ if (typeof definition === "boolean" || !isRecord(definition)) {
147
+ if (isRoot) throw new UnsupportedFunctionalityError({ functionality: "tool parameters must be a JSON Schema object with type \"object\" for moonshotai (MFJS)" });
148
+ return definition;
149
+ }
150
+ if (isRoot && definition.type !== "object") throw new UnsupportedFunctionalityError({ functionality: "tool parameters must be a JSON Schema object with type \"object\" for moonshotai (MFJS)" });
151
+ const result = { ...definition };
152
+ if (Array.isArray(result.items)) {
153
+ const tuple = result.items;
154
+ result.prefixItems = [...Array.isArray(result.prefixItems) ? result.prefixItems : [], ...tuple.map((item) => normalizeDefinition(item, false))];
155
+ delete result.items;
156
+ } else if (isRecord(result.items)) result.items = normalizeDefinition(result.items, false);
157
+ if (typeof result.type === "string" && Array.isArray(result.anyOf)) {
158
+ const parentType = result.type;
159
+ delete result.type;
160
+ result.anyOf = result.anyOf.map((branch) => isRecord(branch) && branch.type == null ? {
161
+ type: parentType,
162
+ ...branch
163
+ } : branch);
164
+ }
165
+ for (const key of SCHEMA_ARRAY_KEYS) {
166
+ const value = result[key];
167
+ if (Array.isArray(value)) result[key] = value.map((item) => normalizeDefinition(item, false));
168
+ }
169
+ for (const key of SCHEMA_MAP_KEYS) {
170
+ const value = result[key];
171
+ if (isRecord(value)) result[key] = Object.fromEntries(Object.entries(value).map(([k, v]) => [k, normalizeDefinition(v, false)]));
172
+ }
173
+ for (const key of SCHEMA_SINGLE_KEYS) {
174
+ const value = result[key];
175
+ if (isRecord(value) || typeof value === "boolean") result[key] = normalizeDefinition(value, false);
176
+ }
177
+ return result;
236
178
  }
237
-
238
- // src/moonshotai-prepare-tools.ts
239
- function prepareTools({
240
- tools,
241
- toolChoice,
242
- modelId
243
- }) {
244
- tools = tools?.length ? tools : void 0;
245
- const toolWarnings = [];
246
- if (tools == null) {
247
- return { tools: void 0, toolChoice: void 0, toolWarnings };
248
- }
249
- const moonshotTools = [];
250
- for (const tool of tools) {
251
- if (tool.type === "provider") {
252
- toolWarnings.push({
253
- type: "unsupported",
254
- feature: `provider-defined tool ${tool.id}`
255
- });
256
- } else {
257
- moonshotTools.push({
258
- type: "function",
259
- function: {
260
- name: tool.name,
261
- description: tool.description,
262
- parameters: normalizeJsonSchemaForMFJS(tool.inputSchema),
263
- ...tool.strict != null ? { strict: tool.strict } : {}
264
- }
265
- });
266
- }
267
- }
268
- if (toolChoice == null) {
269
- return { tools: moonshotTools, toolChoice: void 0, toolWarnings };
270
- }
271
- const type = toolChoice.type;
272
- switch (type) {
273
- case "auto":
274
- case "none":
275
- return { tools: moonshotTools, toolChoice: type, toolWarnings };
276
- case "required":
277
- if (modelId === "kimi-k2.6" || modelId === "kimi-k2.7-code" || modelId === "kimi-k2.7-code-highspeed") {
278
- toolWarnings.push({
279
- type: "unsupported",
280
- feature: `tool choice "required" for model "${modelId}"`,
281
- details: 'Moonshot AI rejects required tool choice for this model. The setting has been omitted; use "auto" or select a specific tool instead.'
282
- });
283
- return {
284
- tools: moonshotTools,
285
- toolChoice: void 0,
286
- toolWarnings
287
- };
288
- }
289
- return { tools: moonshotTools, toolChoice: type, toolWarnings };
290
- case "tool":
291
- return {
292
- tools: moonshotTools,
293
- toolChoice: {
294
- type: "function",
295
- function: { name: toolChoice.toolName }
296
- },
297
- toolWarnings
298
- };
299
- default: {
300
- const _exhaustiveCheck = type;
301
- throw new UnsupportedFunctionalityError2({
302
- functionality: `tool choice type: ${_exhaustiveCheck}`
303
- });
304
- }
305
- }
179
+ //#endregion
180
+ //#region src/moonshotai-prepare-tools.ts
181
+ function prepareTools({ tools, toolChoice, modelId }) {
182
+ tools = tools?.length ? tools : void 0;
183
+ const toolWarnings = [];
184
+ if (tools == null) return {
185
+ tools: void 0,
186
+ toolChoice: void 0,
187
+ toolWarnings
188
+ };
189
+ const moonshotTools = [];
190
+ for (const tool of tools) if (tool.type === "provider") toolWarnings.push({
191
+ type: "unsupported",
192
+ feature: `provider-defined tool ${tool.id}`
193
+ });
194
+ else moonshotTools.push({
195
+ type: "function",
196
+ function: {
197
+ name: tool.name,
198
+ description: tool.description,
199
+ parameters: normalizeJsonSchemaForMFJS(tool.inputSchema),
200
+ ...tool.strict != null ? { strict: tool.strict } : {}
201
+ }
202
+ });
203
+ if (toolChoice == null) return {
204
+ tools: moonshotTools,
205
+ toolChoice: void 0,
206
+ toolWarnings
207
+ };
208
+ const type = toolChoice.type;
209
+ switch (type) {
210
+ case "auto":
211
+ case "none": return {
212
+ tools: moonshotTools,
213
+ toolChoice: type,
214
+ toolWarnings
215
+ };
216
+ case "required":
217
+ if (modelId === "kimi-k2.6" || modelId === "kimi-k2.7-code" || modelId === "kimi-k2.7-code-highspeed") {
218
+ toolWarnings.push({
219
+ type: "unsupported",
220
+ feature: `tool choice "required" for model "${modelId}"`,
221
+ details: "Moonshot AI rejects required tool choice for this model. The setting has been omitted; use \"auto\" or select a specific tool instead."
222
+ });
223
+ return {
224
+ tools: moonshotTools,
225
+ toolChoice: void 0,
226
+ toolWarnings
227
+ };
228
+ }
229
+ return {
230
+ tools: moonshotTools,
231
+ toolChoice: type,
232
+ toolWarnings
233
+ };
234
+ case "tool": return {
235
+ tools: moonshotTools,
236
+ toolChoice: {
237
+ type: "function",
238
+ function: { name: toolChoice.toolName }
239
+ },
240
+ toolWarnings
241
+ };
242
+ default: throw new UnsupportedFunctionalityError({ functionality: `tool choice type: ${type}` });
243
+ }
306
244
  }
307
-
308
- // src/convert-to-moonshotai-chat-messages.ts
309
- var supportedImageMediaTypes = [
310
- "image/jpeg",
311
- "image/png",
312
- "image/gif",
313
- "image/webp",
314
- "image/bmp",
315
- "image/heic",
316
- "image/heif"
245
+ //#endregion
246
+ //#region src/convert-to-moonshotai-chat-messages.ts
247
+ const supportedImageMediaTypes = [
248
+ "image/jpeg",
249
+ "image/png",
250
+ "image/gif",
251
+ "image/webp",
252
+ "image/bmp",
253
+ "image/heic",
254
+ "image/heif"
317
255
  ];
318
- var supportedVideoMediaTypes = [
319
- "video/mp4",
320
- "video/mpeg",
321
- "video/mov",
322
- "video/avi",
323
- "video/x-flv",
324
- "video/mpg",
325
- "video/webm",
326
- "video/wmv",
327
- "video/3gpp"
256
+ const supportedVideoMediaTypes = [
257
+ "video/mp4",
258
+ "video/mpeg",
259
+ "video/mov",
260
+ "video/avi",
261
+ "video/x-flv",
262
+ "video/mpg",
263
+ "video/webm",
264
+ "video/wmv",
265
+ "video/3gpp"
328
266
  ];
329
- function formatMediaUrl({
330
- part,
331
- supportedMediaTypes,
332
- topLevelMediaType
333
- }) {
334
- if (part.data.type !== "url" && part.data.type !== "data") {
335
- throw new UnsupportedFunctionalityError3({
336
- functionality: `file part data type ${part.data.type}`
337
- });
338
- }
339
- const mediaType = part.data.type === "url" ? part.mediaType : resolveFullMediaType({ part });
340
- if (!supportedMediaTypes.includes(mediaType) && !(part.data.type === "url" && (mediaType === topLevelMediaType || mediaType === `${topLevelMediaType}/*`))) {
341
- throw new UnsupportedFunctionalityError3({
342
- functionality: `file part media type ${mediaType}`
343
- });
344
- }
345
- return part.data.type === "url" ? part.data.url.toString() : `data:${mediaType};base64,${convertToBase64(part.data.data)}`;
267
+ function formatMediaUrl({ part, supportedMediaTypes, topLevelMediaType }) {
268
+ if (part.data.type !== "url" && part.data.type !== "data") throw new UnsupportedFunctionalityError({ functionality: `file part data type ${part.data.type}` });
269
+ const mediaType = part.data.type === "url" ? part.mediaType : resolveFullMediaType({ part });
270
+ if (!supportedMediaTypes.includes(mediaType) && !(part.data.type === "url" && (mediaType === topLevelMediaType || mediaType === `${topLevelMediaType}/*`))) throw new UnsupportedFunctionalityError({ functionality: `file part media type ${mediaType}` });
271
+ return part.data.type === "url" ? part.data.url.toString() : `data:${mediaType};base64,${convertToBase64(part.data.data)}`;
346
272
  }
347
- async function convertToMoonshotAIChatMessages({
348
- modelId,
349
- prompt,
350
- providerOptionsName = "moonshotai",
351
- responseFormat
352
- }) {
353
- const messages = [];
354
- const warnings = [];
355
- const modelFamily = modelId == null ? "unknown" : getMoonshotAIModelFamily(modelId);
356
- for (const [index, { role, content, providerOptions }] of prompt.entries()) {
357
- const moonshotMessageOptions = await parseProviderOptions({
358
- provider: providerOptionsName,
359
- providerOptions,
360
- schema: moonshotaiAllMessageProviderOptions
361
- });
362
- if (moonshotMessageOptions?.partial === true && role !== "assistant") {
363
- throw new InvalidPromptError({
364
- prompt,
365
- message: "Moonshot AI Partial Mode requires `partial: true` on an assistant message."
366
- });
367
- }
368
- if (moonshotMessageOptions?.tools != null && role !== "system") {
369
- throw new InvalidPromptError({
370
- prompt,
371
- message: "Moonshot dynamic tools must be configured on a system message."
372
- });
373
- }
374
- switch (role) {
375
- case "system": {
376
- if (moonshotMessageOptions?.tools?.length) {
377
- if (content.length > 0) {
378
- throw new InvalidPromptError({
379
- prompt,
380
- message: "A Moonshot dynamic-tool system message must use empty content because the API forbids content alongside tools."
381
- });
382
- }
383
- if (modelFamily !== "kimi-k3" && modelFamily !== "unknown") {
384
- warnings.push({
385
- type: "unsupported",
386
- feature: `dynamic tool loading for model "${modelId}"`,
387
- details: "Moonshot documents dynamic tool loading only for Kimi K3. The dynamic system message has been omitted."
388
- });
389
- break;
390
- }
391
- const { tools, toolWarnings } = prepareTools({
392
- modelId: modelId ?? "custom-model",
393
- tools: moonshotMessageOptions.tools
394
- });
395
- warnings.push(...toolWarnings);
396
- messages.push({ role: "system", tools: tools ?? [] });
397
- break;
398
- }
399
- messages.push({
400
- role: "system",
401
- content,
402
- ...moonshotMessageOptions?.name != null && {
403
- name: moonshotMessageOptions.name
404
- }
405
- });
406
- break;
407
- }
408
- case "user": {
409
- if (content.length === 1 && content[0].type === "text") {
410
- messages.push({
411
- role: "user",
412
- content: content[0].text,
413
- ...moonshotMessageOptions?.name != null && {
414
- name: moonshotMessageOptions.name
415
- }
416
- });
417
- break;
418
- }
419
- messages.push({
420
- role: "user",
421
- content: content.map((part) => {
422
- switch (part.type) {
423
- case "text": {
424
- return { type: "text", text: part.text };
425
- }
426
- case "file": {
427
- const topLevel = getTopLevelMediaType(part.mediaType);
428
- switch (part.data.type) {
429
- case "reference": {
430
- if (topLevel !== "image" && topLevel !== "video") {
431
- throw new UnsupportedFunctionalityError3({
432
- functionality: `file part media type ${part.mediaType}`
433
- });
434
- }
435
- const reference = resolveProviderReference({
436
- reference: part.data.reference,
437
- provider: "moonshotai"
438
- });
439
- if (!reference.startsWith("ms://")) {
440
- throw new UnsupportedFunctionalityError3({
441
- functionality: "Moonshot file provider references without an ms:// URL"
442
- });
443
- }
444
- return topLevel === "image" ? {
445
- type: "image_url",
446
- image_url: { url: reference }
447
- } : {
448
- type: "video_url",
449
- video_url: { url: reference }
450
- };
451
- }
452
- case "text": {
453
- if (topLevel === "text") {
454
- return {
455
- type: "text",
456
- text: part.data.text
457
- };
458
- }
459
- throw new UnsupportedFunctionalityError3({
460
- functionality: `file part media type ${part.mediaType}`
461
- });
462
- }
463
- case "url":
464
- case "data": {
465
- if (topLevel === "image") {
466
- return {
467
- type: "image_url",
468
- image_url: {
469
- url: formatMediaUrl({
470
- part,
471
- supportedMediaTypes: supportedImageMediaTypes,
472
- topLevelMediaType: "image"
473
- })
474
- }
475
- };
476
- }
477
- if (topLevel === "video") {
478
- return {
479
- type: "video_url",
480
- video_url: {
481
- url: formatMediaUrl({
482
- part,
483
- supportedMediaTypes: supportedVideoMediaTypes,
484
- topLevelMediaType: "video"
485
- })
486
- }
487
- };
488
- }
489
- if (topLevel === "text") {
490
- const textContent = part.data.type === "url" ? part.data.url.toString() : typeof part.data.data === "string" ? new TextDecoder().decode(
491
- convertBase64ToUint8Array(part.data.data)
492
- ) : new TextDecoder().decode(part.data.data);
493
- return {
494
- type: "text",
495
- text: textContent
496
- };
497
- }
498
- throw new UnsupportedFunctionalityError3({
499
- functionality: `file part media type ${part.mediaType}`
500
- });
501
- }
502
- }
503
- }
504
- }
505
- }),
506
- ...moonshotMessageOptions?.name != null && {
507
- name: moonshotMessageOptions.name
508
- }
509
- });
510
- break;
511
- }
512
- case "assistant": {
513
- if (moonshotMessageOptions?.partial === true) {
514
- if (index !== prompt.length - 1) {
515
- throw new InvalidPromptError({
516
- prompt,
517
- message: "Moonshot AI Partial Mode requires the partial assistant message to be the final message."
518
- });
519
- }
520
- if (responseFormat?.type === "json_object") {
521
- throw new InvalidPromptError({
522
- prompt,
523
- message: "Moonshot AI Partial Mode cannot be combined with JSON object response format."
524
- });
525
- }
526
- }
527
- let text = "";
528
- let reasoning = "";
529
- const toolCalls = [];
530
- for (const part of content) {
531
- switch (part.type) {
532
- case "text": {
533
- text += part.text;
534
- break;
535
- }
536
- case "reasoning": {
537
- reasoning += part.text;
538
- break;
539
- }
540
- case "tool-call": {
541
- toolCalls.push({
542
- id: part.toolCallId,
543
- type: "function",
544
- function: {
545
- name: part.toolName,
546
- arguments: JSON.stringify(part.input)
547
- }
548
- });
549
- break;
550
- }
551
- }
552
- }
553
- messages.push({
554
- role: "assistant",
555
- content: toolCalls.length > 0 ? text || null : text,
556
- ...moonshotMessageOptions?.name != null && {
557
- name: moonshotMessageOptions.name
558
- },
559
- ...moonshotMessageOptions?.partial === true && {
560
- partial: true
561
- },
562
- ...reasoning.length > 0 ? { reasoning_content: reasoning } : {},
563
- tool_calls: toolCalls.length > 0 ? toolCalls : void 0
564
- });
565
- break;
566
- }
567
- case "tool": {
568
- if (moonshotMessageOptions?.name != null) {
569
- warnings.push({
570
- type: "unsupported",
571
- feature: "message name on tool messages"
572
- });
573
- }
574
- for (const toolResponse of content) {
575
- if (toolResponse.type === "tool-approval-response") {
576
- continue;
577
- }
578
- const output = toolResponse.output;
579
- let contentValue;
580
- switch (output.type) {
581
- case "text":
582
- case "error-text":
583
- contentValue = output.value;
584
- break;
585
- case "execution-denied":
586
- contentValue = output.reason ?? "Tool call execution denied.";
587
- break;
588
- case "content":
589
- case "json":
590
- case "error-json":
591
- contentValue = JSON.stringify(output.value);
592
- break;
593
- }
594
- messages.push({
595
- role: "tool",
596
- tool_call_id: toolResponse.toolCallId,
597
- content: contentValue
598
- });
599
- }
600
- break;
601
- }
602
- default: {
603
- const _exhaustiveCheck = role;
604
- throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
605
- }
606
- }
607
- }
608
- return { messages, warnings };
273
+ async function convertToMoonshotAIChatMessages({ modelId, prompt, providerOptionsName = "moonshotai", responseFormat }) {
274
+ const messages = [];
275
+ const warnings = [];
276
+ const modelFamily = modelId == null ? "unknown" : getMoonshotAIModelFamily(modelId);
277
+ for (const [index, { role, content, providerOptions }] of prompt.entries()) {
278
+ const moonshotMessageOptions = await parseProviderOptions({
279
+ provider: providerOptionsName,
280
+ providerOptions,
281
+ schema: moonshotaiAllMessageProviderOptions
282
+ });
283
+ if (moonshotMessageOptions?.partial === true && role !== "assistant") throw new InvalidPromptError({
284
+ prompt,
285
+ message: "Moonshot AI Partial Mode requires `partial: true` on an assistant message."
286
+ });
287
+ if (moonshotMessageOptions?.tools != null && role !== "system") throw new InvalidPromptError({
288
+ prompt,
289
+ message: "Moonshot dynamic tools must be configured on a system message."
290
+ });
291
+ switch (role) {
292
+ case "system":
293
+ if (moonshotMessageOptions?.tools?.length) {
294
+ if (content.length > 0) throw new InvalidPromptError({
295
+ prompt,
296
+ message: "A Moonshot dynamic-tool system message must use empty content because the API forbids content alongside tools."
297
+ });
298
+ if (modelFamily !== "kimi-k3" && modelFamily !== "unknown") {
299
+ warnings.push({
300
+ type: "unsupported",
301
+ feature: `dynamic tool loading for model "${modelId}"`,
302
+ details: "Moonshot documents dynamic tool loading only for Kimi K3. The dynamic system message has been omitted."
303
+ });
304
+ break;
305
+ }
306
+ const { tools, toolWarnings } = prepareTools({
307
+ modelId: modelId ?? "custom-model",
308
+ tools: moonshotMessageOptions.tools
309
+ });
310
+ warnings.push(...toolWarnings);
311
+ messages.push({
312
+ role: "system",
313
+ tools: tools ?? []
314
+ });
315
+ break;
316
+ }
317
+ messages.push({
318
+ role: "system",
319
+ content,
320
+ ...moonshotMessageOptions?.name != null && { name: moonshotMessageOptions.name }
321
+ });
322
+ break;
323
+ case "user":
324
+ if (content.length === 1 && content[0].type === "text") {
325
+ messages.push({
326
+ role: "user",
327
+ content: content[0].text,
328
+ ...moonshotMessageOptions?.name != null && { name: moonshotMessageOptions.name }
329
+ });
330
+ break;
331
+ }
332
+ messages.push({
333
+ role: "user",
334
+ content: content.map((part) => {
335
+ switch (part.type) {
336
+ case "text": return {
337
+ type: "text",
338
+ text: part.text
339
+ };
340
+ case "file": {
341
+ const topLevel = getTopLevelMediaType(part.mediaType);
342
+ switch (part.data.type) {
343
+ case "reference": {
344
+ if (topLevel !== "image" && topLevel !== "video") throw new UnsupportedFunctionalityError({ functionality: `file part media type ${part.mediaType}` });
345
+ const reference = resolveProviderReference({
346
+ reference: part.data.reference,
347
+ provider: "moonshotai"
348
+ });
349
+ if (!reference.startsWith("ms://")) throw new UnsupportedFunctionalityError({ functionality: "Moonshot file provider references without an ms:// URL" });
350
+ return topLevel === "image" ? {
351
+ type: "image_url",
352
+ image_url: { url: reference }
353
+ } : {
354
+ type: "video_url",
355
+ video_url: { url: reference }
356
+ };
357
+ }
358
+ case "text":
359
+ if (topLevel === "text") return {
360
+ type: "text",
361
+ text: part.data.text
362
+ };
363
+ throw new UnsupportedFunctionalityError({ functionality: `file part media type ${part.mediaType}` });
364
+ case "url":
365
+ case "data":
366
+ if (topLevel === "image") return {
367
+ type: "image_url",
368
+ image_url: { url: formatMediaUrl({
369
+ part,
370
+ supportedMediaTypes: supportedImageMediaTypes,
371
+ topLevelMediaType: "image"
372
+ }) }
373
+ };
374
+ if (topLevel === "video") return {
375
+ type: "video_url",
376
+ video_url: { url: formatMediaUrl({
377
+ part,
378
+ supportedMediaTypes: supportedVideoMediaTypes,
379
+ topLevelMediaType: "video"
380
+ }) }
381
+ };
382
+ if (topLevel === "text") return {
383
+ type: "text",
384
+ text: part.data.type === "url" ? part.data.url.toString() : typeof part.data.data === "string" ? new TextDecoder().decode(convertBase64ToUint8Array(part.data.data)) : new TextDecoder().decode(part.data.data)
385
+ };
386
+ throw new UnsupportedFunctionalityError({ functionality: `file part media type ${part.mediaType}` });
387
+ }
388
+ }
389
+ }
390
+ }),
391
+ ...moonshotMessageOptions?.name != null && { name: moonshotMessageOptions.name }
392
+ });
393
+ break;
394
+ case "assistant": {
395
+ if (moonshotMessageOptions?.partial === true) {
396
+ if (index !== prompt.length - 1) throw new InvalidPromptError({
397
+ prompt,
398
+ message: "Moonshot AI Partial Mode requires the partial assistant message to be the final message."
399
+ });
400
+ if (responseFormat?.type === "json_object") throw new InvalidPromptError({
401
+ prompt,
402
+ message: "Moonshot AI Partial Mode cannot be combined with JSON object response format."
403
+ });
404
+ }
405
+ let text = "";
406
+ let reasoning = "";
407
+ const toolCalls = [];
408
+ for (const part of content) switch (part.type) {
409
+ case "text":
410
+ text += part.text;
411
+ break;
412
+ case "reasoning":
413
+ reasoning += part.text;
414
+ break;
415
+ case "tool-call": toolCalls.push({
416
+ id: part.toolCallId,
417
+ type: "function",
418
+ function: {
419
+ name: part.toolName,
420
+ arguments: JSON.stringify(part.input)
421
+ }
422
+ });
423
+ }
424
+ messages.push({
425
+ role: "assistant",
426
+ content: toolCalls.length > 0 ? text || null : text,
427
+ ...moonshotMessageOptions?.name != null && { name: moonshotMessageOptions.name },
428
+ ...moonshotMessageOptions?.partial === true && { partial: true },
429
+ ...reasoning.length > 0 ? { reasoning_content: reasoning } : {},
430
+ tool_calls: toolCalls.length > 0 ? toolCalls : void 0
431
+ });
432
+ break;
433
+ }
434
+ case "tool":
435
+ if (moonshotMessageOptions?.name != null) warnings.push({
436
+ type: "unsupported",
437
+ feature: "message name on tool messages"
438
+ });
439
+ for (const toolResponse of content) {
440
+ if (toolResponse.type === "tool-approval-response") continue;
441
+ const output = toolResponse.output;
442
+ let contentValue;
443
+ switch (output.type) {
444
+ case "text":
445
+ case "error-text":
446
+ contentValue = output.value;
447
+ break;
448
+ case "execution-denied":
449
+ contentValue = output.reason ?? "Tool call execution denied.";
450
+ break;
451
+ case "content":
452
+ case "json":
453
+ case "error-json": contentValue = JSON.stringify(output.value);
454
+ }
455
+ messages.push({
456
+ role: "tool",
457
+ tool_call_id: toolResponse.toolCallId,
458
+ content: contentValue
459
+ });
460
+ }
461
+ break;
462
+ default: throw new Error(`Unsupported role: ${role}`);
463
+ }
464
+ }
465
+ return {
466
+ messages,
467
+ warnings
468
+ };
609
469
  }
610
-
611
- // src/convert-moonshotai-chat-usage.ts
612
- import { createNullLanguageModelUsage } from "@ai-sdk/provider-utils";
470
+ //#endregion
471
+ //#region src/convert-moonshotai-chat-usage.ts
613
472
  function convertMoonshotAIChatUsage(usage) {
614
- if (usage == null) {
615
- return createNullLanguageModelUsage();
616
- }
617
- const promptTokens = usage.prompt_tokens ?? 0;
618
- const completionTokens = usage.completion_tokens ?? 0;
619
- const cacheReadTokens = usage.cached_tokens ?? usage.prompt_tokens_details?.cached_tokens ?? 0;
620
- const reasoningTokens = usage.completion_tokens_details?.reasoning_tokens ?? 0;
621
- return {
622
- inputTokens: {
623
- total: promptTokens,
624
- noCache: promptTokens - cacheReadTokens,
625
- cacheRead: cacheReadTokens,
626
- cacheWrite: void 0
627
- },
628
- outputTokens: {
629
- total: completionTokens,
630
- text: Math.max(0, completionTokens - reasoningTokens),
631
- reasoning: reasoningTokens
632
- },
633
- raw: usage
634
- };
473
+ if (usage == null) return createNullLanguageModelUsage();
474
+ const promptTokens = usage.prompt_tokens ?? 0;
475
+ const completionTokens = usage.completion_tokens ?? 0;
476
+ const cacheReadTokens = usage.cached_tokens ?? usage.prompt_tokens_details?.cached_tokens ?? 0;
477
+ const reasoningTokens = usage.completion_tokens_details?.reasoning_tokens ?? 0;
478
+ return {
479
+ inputTokens: {
480
+ total: promptTokens,
481
+ noCache: promptTokens - cacheReadTokens,
482
+ cacheRead: cacheReadTokens,
483
+ cacheWrite: void 0
484
+ },
485
+ outputTokens: {
486
+ total: completionTokens,
487
+ text: Math.max(0, completionTokens - reasoningTokens),
488
+ reasoning: reasoningTokens
489
+ },
490
+ raw: usage
491
+ };
635
492
  }
636
-
637
- // src/map-moonshotai-finish-reason.ts
493
+ //#endregion
494
+ //#region src/map-moonshotai-finish-reason.ts
638
495
  function mapMoonshotAIFinishReason(finishReason) {
639
- switch (finishReason) {
640
- case "stop":
641
- return "stop";
642
- case "length":
643
- return "length";
644
- case "content_filter":
645
- return "content-filter";
646
- case "function_call":
647
- case "tool_calls":
648
- return "tool-calls";
649
- default:
650
- return "other";
651
- }
496
+ switch (finishReason) {
497
+ case "stop": return "stop";
498
+ case "length": return "length";
499
+ case "content_filter": return "content-filter";
500
+ case "function_call":
501
+ case "tool_calls": return "tool-calls";
502
+ default: return "other";
503
+ }
652
504
  }
653
-
654
- // src/moonshotai-chat-api-types.ts
655
- import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
656
- import { z as z2 } from "zod/v4";
657
- var tokenUsageSchema = z2.looseObject({
658
- prompt_tokens: z2.number().nullish(),
659
- completion_tokens: z2.number().nullish(),
660
- cached_tokens: z2.number().nullish(),
661
- total_tokens: z2.number().nullish(),
662
- prompt_tokens_details: z2.looseObject({
663
- cached_tokens: z2.number().nullish()
664
- }).nullish(),
665
- completion_tokens_details: z2.looseObject({
666
- reasoning_tokens: z2.number().nullish()
667
- }).nullish()
505
+ //#endregion
506
+ //#region src/moonshotai-chat-api-types.ts
507
+ const tokenUsageSchema = z.looseObject({
508
+ prompt_tokens: z.number().nullish(),
509
+ completion_tokens: z.number().nullish(),
510
+ cached_tokens: z.number().nullish(),
511
+ total_tokens: z.number().nullish(),
512
+ prompt_tokens_details: z.looseObject({ cached_tokens: z.number().nullish() }).nullish(),
513
+ completion_tokens_details: z.looseObject({ reasoning_tokens: z.number().nullish() }).nullish()
668
514
  }).nullish();
669
- var moonshotAIErrorSchema = z2.object({
670
- error: z2.object({
671
- message: z2.string(),
672
- type: z2.string().nullish(),
673
- code: z2.string().nullish()
674
- })
515
+ const moonshotAIErrorSchema = z.object({ error: z.object({
516
+ message: z.string(),
517
+ type: z.string().nullish(),
518
+ code: z.string().nullish()
519
+ }) });
520
+ const moonshotAIChatLogprobSchema = z.object({
521
+ token: z.string(),
522
+ logprob: z.number(),
523
+ bytes: z.array(z.number()).nullable(),
524
+ top_logprobs: z.array(z.object({
525
+ token: z.string(),
526
+ logprob: z.number(),
527
+ bytes: z.array(z.number()).nullable()
528
+ }))
675
529
  });
676
- var moonshotAIChatLogprobSchema = z2.object({
677
- token: z2.string(),
678
- logprob: z2.number(),
679
- bytes: z2.array(z2.number()).nullable(),
680
- top_logprobs: z2.array(
681
- z2.object({
682
- token: z2.string(),
683
- logprob: z2.number(),
684
- bytes: z2.array(z2.number()).nullable()
685
- })
686
- )
687
- });
688
- var moonshotAIChatLogprobsSchema = z2.object({
689
- content: z2.array(moonshotAIChatLogprobSchema).nullish()
690
- }).nullish();
691
- var moonshotAIChatResponseSchema = z2.object({
692
- id: z2.string().nullish(),
693
- created: z2.number().nullish(),
694
- model: z2.string().nullish(),
695
- object: z2.literal("chat.completion").nullish(),
696
- choices: z2.array(
697
- z2.object({
698
- index: z2.number().nullish(),
699
- message: z2.object({
700
- role: z2.literal("assistant").nullish(),
701
- content: z2.string().nullish(),
702
- reasoning_content: z2.string().nullish(),
703
- tool_calls: z2.array(
704
- z2.object({
705
- id: z2.string().nullish(),
706
- type: z2.literal("function").nullish(),
707
- function: z2.object({
708
- name: z2.string(),
709
- arguments: z2.string()
710
- })
711
- })
712
- ).nullish()
713
- }),
714
- logprobs: moonshotAIChatLogprobsSchema,
715
- finish_reason: z2.string().nullish()
716
- })
717
- ),
718
- usage: tokenUsageSchema
530
+ const moonshotAIChatLogprobsSchema = z.object({ content: z.array(moonshotAIChatLogprobSchema).nullish() }).nullish();
531
+ const moonshotAIChatResponseSchema = z.object({
532
+ id: z.string().nullish(),
533
+ created: z.number().nullish(),
534
+ model: z.string().nullish(),
535
+ object: z.literal("chat.completion").nullish(),
536
+ choices: z.array(z.object({
537
+ index: z.number().nullish(),
538
+ message: z.object({
539
+ role: z.literal("assistant").nullish(),
540
+ content: z.string().nullish(),
541
+ reasoning_content: z.string().nullish(),
542
+ tool_calls: z.array(z.object({
543
+ id: z.string().nullish(),
544
+ type: z.literal("function").nullish(),
545
+ function: z.object({
546
+ name: z.string(),
547
+ arguments: z.string()
548
+ })
549
+ })).nullish()
550
+ }),
551
+ logprobs: moonshotAIChatLogprobsSchema,
552
+ finish_reason: z.string().nullish()
553
+ })),
554
+ usage: tokenUsageSchema
719
555
  });
720
- var moonshotAIChatChunkSchema = lazySchema(
721
- () => zodSchema(
722
- z2.union([
723
- z2.object({
724
- id: z2.string().nullish(),
725
- created: z2.number().nullish(),
726
- model: z2.string().nullish(),
727
- object: z2.literal("chat.completion.chunk").nullish(),
728
- choices: z2.array(
729
- z2.object({
730
- index: z2.number().nullish(),
731
- delta: z2.object({
732
- role: z2.literal("assistant").nullish(),
733
- content: z2.string().nullish(),
734
- reasoning_content: z2.string().nullish(),
735
- tool_calls: z2.array(
736
- z2.object({
737
- index: z2.number().nullish(),
738
- id: z2.string().nullish(),
739
- type: z2.literal("function").nullish(),
740
- function: z2.object({
741
- name: z2.string().nullish(),
742
- arguments: z2.string().nullish()
743
- })
744
- })
745
- ).nullish()
746
- }).nullish(),
747
- logprobs: moonshotAIChatLogprobsSchema,
748
- finish_reason: z2.string().nullish(),
749
- usage: tokenUsageSchema
750
- })
751
- ),
752
- usage: tokenUsageSchema
753
- }),
754
- moonshotAIErrorSchema
755
- ])
756
- )
757
- );
758
-
759
- // src/moonshotai-chat-language-model.ts
556
+ const moonshotAIChatChunkSchema = lazySchema(() => zodSchema(z.union([z.object({
557
+ id: z.string().nullish(),
558
+ created: z.number().nullish(),
559
+ model: z.string().nullish(),
560
+ object: z.literal("chat.completion.chunk").nullish(),
561
+ choices: z.array(z.object({
562
+ index: z.number().nullish(),
563
+ delta: z.object({
564
+ role: z.literal("assistant").nullish(),
565
+ content: z.string().nullish(),
566
+ reasoning_content: z.string().nullish(),
567
+ tool_calls: z.array(z.object({
568
+ index: z.number().nullish(),
569
+ id: z.string().nullish(),
570
+ type: z.literal("function").nullish(),
571
+ function: z.object({
572
+ name: z.string().nullish(),
573
+ arguments: z.string().nullish()
574
+ })
575
+ })).nullish()
576
+ }).nullish(),
577
+ logprobs: moonshotAIChatLogprobsSchema,
578
+ finish_reason: z.string().nullish(),
579
+ usage: tokenUsageSchema
580
+ })),
581
+ usage: tokenUsageSchema
582
+ }), moonshotAIErrorSchema])));
583
+ //#endregion
584
+ //#region src/moonshotai-chat-language-model.ts
760
585
  function createMoonshotAIStreamError(error, data) {
761
- return createProviderStreamError({
762
- message: error.message,
763
- type: error.type ?? void 0,
764
- code: error.code ?? void 0,
765
- ...getMoonshotAIStreamErrorMetadata(error.type),
766
- data
767
- });
586
+ return createProviderStreamError({
587
+ message: error.message,
588
+ type: error.type ?? void 0,
589
+ code: error.code ?? void 0,
590
+ ...getMoonshotAIStreamErrorMetadata(error.type),
591
+ data
592
+ });
768
593
  }
769
594
  function getMoonshotAIStreamErrorMetadata(type) {
770
- switch (type) {
771
- case "rate_limit_exceeded":
772
- case "rate_limit_error":
773
- return { statusCode: 429, isRetryable: true };
774
- case "server_error":
775
- case "api_error":
776
- case "internal_server_error":
777
- return { statusCode: 500, isRetryable: true };
778
- case "overloaded_error":
779
- case "service_unavailable":
780
- return { statusCode: 503, isRetryable: true };
781
- case "timeout":
782
- case "timeout_error":
783
- return { statusCode: 504, isRetryable: true };
784
- case "authentication_error":
785
- case "invalid_api_key":
786
- return { statusCode: 401, isRetryable: false };
787
- case "permission_error":
788
- return { statusCode: 403, isRetryable: false };
789
- case "not_found_error":
790
- case "model_not_found":
791
- return { statusCode: 404, isRetryable: false };
792
- case "bad_request":
793
- case "context_length_exceeded":
794
- case "invalid_request_error":
795
- return { statusCode: 400, isRetryable: false };
796
- default:
797
- return {};
798
- }
595
+ switch (type) {
596
+ case "rate_limit_exceeded":
597
+ case "rate_limit_error": return {
598
+ statusCode: 429,
599
+ isRetryable: true
600
+ };
601
+ case "server_error":
602
+ case "api_error":
603
+ case "internal_server_error": return {
604
+ statusCode: 500,
605
+ isRetryable: true
606
+ };
607
+ case "overloaded_error":
608
+ case "service_unavailable": return {
609
+ statusCode: 503,
610
+ isRetryable: true
611
+ };
612
+ case "timeout":
613
+ case "timeout_error": return {
614
+ statusCode: 504,
615
+ isRetryable: true
616
+ };
617
+ case "authentication_error":
618
+ case "invalid_api_key": return {
619
+ statusCode: 401,
620
+ isRetryable: false
621
+ };
622
+ case "permission_error": return {
623
+ statusCode: 403,
624
+ isRetryable: false
625
+ };
626
+ case "not_found_error":
627
+ case "model_not_found": return {
628
+ statusCode: 404,
629
+ isRetryable: false
630
+ };
631
+ case "bad_request":
632
+ case "context_length_exceeded":
633
+ case "invalid_request_error": return {
634
+ statusCode: 400,
635
+ isRetryable: false
636
+ };
637
+ default: return {};
638
+ }
799
639
  }
800
- var MoonshotAIChatLanguageModel = class _MoonshotAIChatLanguageModel {
801
- constructor(modelId, config) {
802
- this.specificationVersion = "v4";
803
- // Moonshot AI does not fetch external URLs; the AI SDK downloads and
804
- // inlines URL file parts instead. ms:// file references from the Moonshot
805
- // Files API are passed through natively.
806
- this.supportedUrls = {
807
- "image/*": [/^ms:\/\//],
808
- "video/*": [/^ms:\/\//]
809
- };
810
- this.modelId = modelId;
811
- this.config = config;
812
- this.failedResponseHandler = createJsonErrorResponseHandler({
813
- errorSchema: moonshotAIErrorSchema,
814
- errorToMessage: (error) => error.error.message
815
- });
816
- }
817
- static [WORKFLOW_SERIALIZE](model) {
818
- return serializeModelOptions({
819
- modelId: model.modelId,
820
- config: model.config
821
- });
822
- }
823
- static [WORKFLOW_DESERIALIZE](options) {
824
- return new _MoonshotAIChatLanguageModel(options.modelId, options.config);
825
- }
826
- get provider() {
827
- return this.config.provider;
828
- }
829
- get providerOptionsName() {
830
- return this.config.provider.split(".")[0].trim();
831
- }
832
- async getArgs({
833
- prompt,
834
- maxOutputTokens,
835
- temperature,
836
- topP,
837
- topK,
838
- frequencyPenalty,
839
- presencePenalty,
840
- reasoning,
841
- providerOptions,
842
- stopSequences,
843
- responseFormat,
844
- seed,
845
- toolChoice,
846
- tools
847
- }) {
848
- const moonshotOptions = await parseProviderOptions2({
849
- provider: this.providerOptionsName,
850
- providerOptions,
851
- schema: moonshotaiLanguageModelOptions
852
- }) ?? {};
853
- const allWarnings = [];
854
- if (topK != null) {
855
- allWarnings.push({ type: "unsupported", feature: "topK" });
856
- }
857
- if (seed != null) {
858
- allWarnings.push({ type: "unsupported", feature: "seed" });
859
- }
860
- const supportsSamplingOptions = !isMoonshotAIKimiModel(this.modelId);
861
- if (!supportsSamplingOptions && temperature != null) {
862
- allWarnings.push({
863
- type: "unsupported",
864
- feature: "temperature",
865
- details: `temperature is fixed by model "${this.modelId}" and has been omitted.`
866
- });
867
- }
868
- if (!supportsSamplingOptions && topP != null) {
869
- allWarnings.push({
870
- type: "unsupported",
871
- feature: "topP",
872
- details: `topP is fixed by model "${this.modelId}" and has been omitted.`
873
- });
874
- }
875
- if (!supportsSamplingOptions && frequencyPenalty != null) {
876
- allWarnings.push({
877
- type: "unsupported",
878
- feature: "frequencyPenalty",
879
- details: `frequencyPenalty is fixed by model "${this.modelId}" and has been omitted.`
880
- });
881
- }
882
- if (!supportsSamplingOptions && presencePenalty != null) {
883
- allWarnings.push({
884
- type: "unsupported",
885
- feature: "presencePenalty",
886
- details: `presencePenalty is fixed by model "${this.modelId}" and has been omitted.`
887
- });
888
- }
889
- const {
890
- tools: moonshotTools,
891
- toolChoice: moonshotToolChoice,
892
- toolWarnings
893
- } = prepareTools({ tools, toolChoice, modelId: this.modelId });
894
- const modelFamily = getMoonshotAIModelFamily(this.modelId);
895
- const requestedThinking = moonshotOptions.thinking;
896
- const requestedReasoningEffort = moonshotOptions.reasoningEffort;
897
- const preserveReasoning = moonshotOptions.reasoningHistory === "preserved";
898
- if (requestedThinking?.budgetTokens != null) {
899
- allWarnings.push({
900
- type: "deprecated",
901
- setting: "providerOptions.moonshotai.thinking.budgetTokens",
902
- message: "Moonshot Chat Completions does not support budget_tokens. Remove budgetTokens; the option has been omitted."
903
- });
904
- }
905
- let thinking;
906
- let reasoningEffort;
907
- const warnUnsupportedReasoningEffort = () => {
908
- if (requestedReasoningEffort != null) {
909
- allWarnings.push({
910
- type: "unsupported",
911
- feature: "reasoningEffort",
912
- details: `reasoningEffort is only supported by Kimi K3 and has been omitted for model "${this.modelId}".`
913
- });
914
- }
915
- };
916
- switch (modelFamily) {
917
- case "kimi-k3": {
918
- if (requestedThinking != null) {
919
- allWarnings.push({
920
- type: "unsupported",
921
- feature: "thinking",
922
- details: "Kimi K3 always reasons and does not accept the thinking field. The option has been omitted."
923
- });
924
- }
925
- if (reasoning === "none") {
926
- allWarnings.push({
927
- type: "unsupported",
928
- feature: 'reasoning "none"',
929
- details: "Kimi K3 reasoning cannot be disabled."
930
- });
931
- }
932
- reasoningEffort = requestedReasoningEffort ?? (isCustomReasoning(reasoning) && reasoning !== "none" ? mapReasoningToProviderEffort({
933
- reasoning,
934
- effortMap: {
935
- minimal: "low",
936
- low: "low",
937
- medium: "high",
938
- high: "high",
939
- xhigh: "max"
940
- },
941
- warnings: allWarnings
942
- }) : void 0);
943
- break;
944
- }
945
- case "kimi-k2.7": {
946
- warnUnsupportedReasoningEffort();
947
- if (requestedThinking?.type === "disabled" || reasoning === "none") {
948
- allWarnings.push({
949
- type: "unsupported",
950
- feature: requestedThinking?.type === "disabled" ? 'thinking.type "disabled"' : 'reasoning "none"',
951
- details: "Kimi K2.7 thinking cannot be disabled."
952
- });
953
- } else if (requestedThinking?.type === "enabled") {
954
- thinking = { type: "enabled" };
955
- }
956
- break;
957
- }
958
- case "kimi-k2.6": {
959
- warnUnsupportedReasoningEffort();
960
- const thinkingType = requestedThinking?.type ?? (isCustomReasoning(reasoning) ? reasoning === "none" ? "disabled" : "enabled" : void 0);
961
- if (thinkingType != null || preserveReasoning) {
962
- thinking = {
963
- type: thinkingType ?? "enabled",
964
- ...preserveReasoning ? { keep: "all" } : {}
965
- };
966
- }
967
- break;
968
- }
969
- case "kimi-k2.5": {
970
- warnUnsupportedReasoningEffort();
971
- const thinkingType = requestedThinking?.type ?? (isCustomReasoning(reasoning) ? reasoning === "none" ? "disabled" : "enabled" : void 0);
972
- if (thinkingType != null) {
973
- thinking = { type: thinkingType };
974
- }
975
- if (preserveReasoning) {
976
- allWarnings.push({
977
- type: "unsupported",
978
- feature: `reasoningHistory 'preserved' is not supported by model "${this.modelId}"`
979
- });
980
- }
981
- break;
982
- }
983
- case "moonshot-v1": {
984
- warnUnsupportedReasoningEffort();
985
- if (requestedThinking != null) {
986
- allWarnings.push({
987
- type: "unsupported",
988
- feature: "thinking",
989
- details: `thinking is not supported by model "${this.modelId}" and has been omitted.`
990
- });
991
- }
992
- if (isCustomReasoning(reasoning) && reasoning !== "none") {
993
- allWarnings.push({
994
- type: "unsupported",
995
- feature: "reasoning",
996
- details: `reasoning is not supported by model "${this.modelId}".`
997
- });
998
- }
999
- if (preserveReasoning) {
1000
- allWarnings.push({
1001
- type: "unsupported",
1002
- feature: `reasoningHistory 'preserved' is not supported by model "${this.modelId}"`
1003
- });
1004
- }
1005
- break;
1006
- }
1007
- case "unknown": {
1008
- if (reasoning === "none") {
1009
- allWarnings.push({
1010
- type: "unsupported",
1011
- feature: 'reasoning "none"',
1012
- details: "Use providerOptions.moonshotai.thinking to control thinking on custom models."
1013
- });
1014
- }
1015
- reasoningEffort = requestedReasoningEffort ?? (isCustomReasoning(reasoning) && reasoning !== "none" ? mapReasoningToProviderEffort({
1016
- reasoning,
1017
- effortMap: {
1018
- minimal: "low",
1019
- low: "low",
1020
- medium: "high",
1021
- high: "high",
1022
- xhigh: "max"
1023
- },
1024
- warnings: allWarnings
1025
- }) : void 0);
1026
- if (requestedThinking?.type != null) {
1027
- thinking = { type: requestedThinking.type };
1028
- }
1029
- if (preserveReasoning) {
1030
- allWarnings.push({
1031
- type: "unsupported",
1032
- feature: `reasoningHistory 'preserved' is not supported by model "${this.modelId}"`
1033
- });
1034
- }
1035
- break;
1036
- }
1037
- }
1038
- let response_format;
1039
- if (responseFormat?.type === "json") {
1040
- if (this.config.supportsStructuredOutputs === true && responseFormat.schema != null) {
1041
- const { $schema: _$schema, ...schemaWithoutDollarSchema } = responseFormat.schema;
1042
- response_format = {
1043
- type: "json_schema",
1044
- json_schema: {
1045
- name: responseFormat.name ?? "response",
1046
- strict: moonshotOptions.strictJsonSchema ?? true,
1047
- schema: normalizeJsonSchemaForMFJS(schemaWithoutDollarSchema)
1048
- }
1049
- };
1050
- } else {
1051
- response_format = { type: "json_object" };
1052
- }
1053
- }
1054
- const { messages, warnings: messageWarnings } = await convertToMoonshotAIChatMessages({
1055
- modelId: this.modelId,
1056
- prompt,
1057
- providerOptionsName: this.providerOptionsName,
1058
- responseFormat: response_format
1059
- });
1060
- allWarnings.push(...messageWarnings);
1061
- return {
1062
- args: {
1063
- model: this.modelId,
1064
- ...(moonshotOptions.logprobs === true || moonshotOptions.topLogprobs != null) && { logprobs: true },
1065
- ...moonshotOptions.topLogprobs != null && {
1066
- top_logprobs: moonshotOptions.topLogprobs
1067
- },
1068
- max_completion_tokens: maxOutputTokens,
1069
- temperature: supportsSamplingOptions ? temperature : void 0,
1070
- top_p: supportsSamplingOptions ? topP : void 0,
1071
- frequency_penalty: supportsSamplingOptions ? frequencyPenalty : void 0,
1072
- presence_penalty: supportsSamplingOptions ? presencePenalty : void 0,
1073
- response_format,
1074
- stop: stopSequences,
1075
- messages,
1076
- tools: moonshotTools,
1077
- tool_choice: moonshotToolChoice,
1078
- ...moonshotOptions.prediction != null && {
1079
- prediction: moonshotOptions.prediction
1080
- },
1081
- ...thinking != null ? { thinking } : {},
1082
- ...reasoningEffort != null && {
1083
- reasoning_effort: reasoningEffort
1084
- },
1085
- ...moonshotOptions.promptCacheKey != null && {
1086
- prompt_cache_key: moonshotOptions.promptCacheKey
1087
- },
1088
- ...moonshotOptions.safetyIdentifier != null && {
1089
- safety_identifier: moonshotOptions.safetyIdentifier
1090
- }
1091
- },
1092
- warnings: [...allWarnings, ...toolWarnings]
1093
- };
1094
- }
1095
- async doGenerate(options) {
1096
- const { args, warnings } = await this.getArgs({ ...options });
1097
- const {
1098
- responseHeaders,
1099
- value: responseBody,
1100
- rawValue: rawResponse
1101
- } = await postJsonToApi({
1102
- url: this.config.url({
1103
- path: "/chat/completions",
1104
- modelId: this.modelId
1105
- }),
1106
- headers: combineHeaders(this.config.headers?.(), options.headers),
1107
- body: args,
1108
- failedResponseHandler: this.failedResponseHandler,
1109
- successfulResponseHandler: createJsonResponseHandler(
1110
- moonshotAIChatResponseSchema
1111
- ),
1112
- abortSignal: options.abortSignal,
1113
- fetch: this.config.fetch
1114
- });
1115
- const choice = responseBody.choices[0];
1116
- const content = [];
1117
- const reasoning = choice.message.reasoning_content;
1118
- if (reasoning != null && reasoning.length > 0) {
1119
- content.push({ type: "reasoning", text: reasoning });
1120
- }
1121
- if (choice.message.tool_calls != null) {
1122
- for (const toolCall of choice.message.tool_calls) {
1123
- content.push({
1124
- type: "tool-call",
1125
- toolCallId: toolCall.id || generateId(),
1126
- toolName: toolCall.function.name,
1127
- input: toolCall.function.arguments ?? ""
1128
- });
1129
- }
1130
- }
1131
- const text = choice.message.content;
1132
- if (text != null && text.length > 0) {
1133
- content.push({ type: "text", text });
1134
- }
1135
- return {
1136
- content,
1137
- finishReason: {
1138
- unified: mapMoonshotAIFinishReason(choice.finish_reason),
1139
- raw: choice.finish_reason ?? void 0
1140
- },
1141
- usage: convertMoonshotAIChatUsage(responseBody.usage),
1142
- providerMetadata: {
1143
- [this.providerOptionsName]: {
1144
- ...choice.logprobs != null && { logprobs: choice.logprobs },
1145
- ...responseBody.object != null && {
1146
- responseObject: responseBody.object
1147
- },
1148
- ...choice.index != null && { choiceIndex: choice.index },
1149
- ...choice.message.role != null && {
1150
- messageRole: choice.message.role
1151
- },
1152
- ...choice.message.tool_calls != null && {
1153
- toolCallTypes: choice.message.tool_calls.map((toolCall) => toolCall.type).filter((type) => type != null)
1154
- }
1155
- }
1156
- },
1157
- request: { body: args },
1158
- response: {
1159
- ...getResponseMetadata(responseBody),
1160
- headers: responseHeaders,
1161
- body: rawResponse
1162
- },
1163
- warnings
1164
- };
1165
- }
1166
- async doStream(options) {
1167
- const { args, warnings } = await this.getArgs({ ...options });
1168
- const body = {
1169
- ...args,
1170
- stream: true,
1171
- ...this.config.includeUsage && {
1172
- stream_options: { include_usage: true }
1173
- }
1174
- };
1175
- const { responseHeaders, value: response } = await postJsonToApi({
1176
- url: this.config.url({
1177
- path: "/chat/completions",
1178
- modelId: this.modelId
1179
- }),
1180
- headers: combineHeaders(this.config.headers?.(), options.headers),
1181
- body,
1182
- failedResponseHandler: this.failedResponseHandler,
1183
- successfulResponseHandler: createEventSourceResponseHandler(
1184
- moonshotAIChatChunkSchema
1185
- ),
1186
- abortSignal: options.abortSignal,
1187
- fetch: this.config.fetch
1188
- });
1189
- let toolCallTracker;
1190
- let finishReason = {
1191
- unified: "other",
1192
- raw: void 0
1193
- };
1194
- let topLevelUsage = void 0;
1195
- let choiceUsage = void 0;
1196
- const contentLogprobs = [];
1197
- const providerOptionsName = this.providerOptionsName;
1198
- let isFirstChunk = true;
1199
- let isActiveReasoning = false;
1200
- let isActiveText = false;
1201
- let responseObject;
1202
- let choiceIndex;
1203
- let messageRole;
1204
- const toolCallTypes = /* @__PURE__ */ new Map();
1205
- return {
1206
- stream: response.pipeThrough(
1207
- new TransformStream({
1208
- start(controller) {
1209
- toolCallTracker = new StreamingToolCallTracker(controller, {
1210
- generateId
1211
- });
1212
- controller.enqueue({ type: "stream-start", warnings });
1213
- },
1214
- transform(chunk, controller) {
1215
- if (options.includeRawChunks) {
1216
- controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
1217
- }
1218
- if (!chunk.success) {
1219
- finishReason = { unified: "error", raw: void 0 };
1220
- controller.enqueue({ type: "error", error: chunk.error });
1221
- return;
1222
- }
1223
- const value = chunk.value;
1224
- if ("error" in value) {
1225
- finishReason = { unified: "error", raw: void 0 };
1226
- controller.enqueue({
1227
- type: "error",
1228
- error: createMoonshotAIStreamError(value.error, value)
1229
- });
1230
- return;
1231
- }
1232
- if (isFirstChunk) {
1233
- isFirstChunk = false;
1234
- controller.enqueue({
1235
- type: "response-metadata",
1236
- ...getResponseMetadata(value)
1237
- });
1238
- }
1239
- if (value.usage != null) {
1240
- topLevelUsage = value.usage;
1241
- }
1242
- if (value.object != null) {
1243
- responseObject = value.object;
1244
- }
1245
- const choice = value.choices[0];
1246
- if (choice?.usage != null) {
1247
- choiceUsage = choice.usage;
1248
- }
1249
- if (choice?.index != null) {
1250
- choiceIndex = choice.index;
1251
- }
1252
- if (choice?.finish_reason != null) {
1253
- finishReason = {
1254
- unified: mapMoonshotAIFinishReason(choice.finish_reason),
1255
- raw: choice.finish_reason
1256
- };
1257
- }
1258
- if (choice?.logprobs?.content != null) {
1259
- contentLogprobs.push(...choice.logprobs.content);
1260
- }
1261
- if (choice?.delta == null) {
1262
- return;
1263
- }
1264
- const delta = choice.delta;
1265
- if (delta.role != null) {
1266
- messageRole = delta.role;
1267
- }
1268
- const reasoningContent = delta.reasoning_content;
1269
- if (reasoningContent) {
1270
- if (!isActiveReasoning) {
1271
- controller.enqueue({
1272
- type: "reasoning-start",
1273
- id: "reasoning-0"
1274
- });
1275
- isActiveReasoning = true;
1276
- }
1277
- controller.enqueue({
1278
- type: "reasoning-delta",
1279
- id: "reasoning-0",
1280
- delta: reasoningContent
1281
- });
1282
- }
1283
- if (delta.content) {
1284
- if (!isActiveText) {
1285
- controller.enqueue({ type: "text-start", id: "txt-0" });
1286
- isActiveText = true;
1287
- }
1288
- if (isActiveReasoning) {
1289
- controller.enqueue({
1290
- type: "reasoning-end",
1291
- id: "reasoning-0"
1292
- });
1293
- isActiveReasoning = false;
1294
- }
1295
- controller.enqueue({
1296
- type: "text-delta",
1297
- id: "txt-0",
1298
- delta: delta.content
1299
- });
1300
- }
1301
- if (delta.tool_calls != null && delta.tool_calls.length > 0) {
1302
- if (isActiveReasoning) {
1303
- controller.enqueue({
1304
- type: "reasoning-end",
1305
- id: "reasoning-0"
1306
- });
1307
- isActiveReasoning = false;
1308
- }
1309
- for (const [index, toolCallDelta] of delta.tool_calls.entries()) {
1310
- const toolCallIndex = toolCallDelta.index ?? index;
1311
- if (toolCallDelta.type != null) {
1312
- toolCallTypes.set(toolCallIndex, toolCallDelta.type);
1313
- }
1314
- toolCallTracker.processDelta({
1315
- ...toolCallDelta,
1316
- index: toolCallIndex
1317
- });
1318
- }
1319
- }
1320
- },
1321
- flush(controller) {
1322
- if (isActiveReasoning) {
1323
- controller.enqueue({ type: "reasoning-end", id: "reasoning-0" });
1324
- }
1325
- if (isActiveText) {
1326
- controller.enqueue({ type: "text-end", id: "txt-0" });
1327
- }
1328
- toolCallTracker.flush();
1329
- controller.enqueue({
1330
- type: "finish",
1331
- finishReason,
1332
- usage: convertMoonshotAIChatUsage(topLevelUsage ?? choiceUsage),
1333
- providerMetadata: {
1334
- [providerOptionsName]: {
1335
- ...contentLogprobs.length > 0 && {
1336
- logprobs: { content: contentLogprobs }
1337
- },
1338
- ...responseObject != null && { responseObject },
1339
- ...choiceIndex != null && { choiceIndex },
1340
- ...messageRole != null && { messageRole },
1341
- ...toolCallTypes.size > 0 && {
1342
- toolCallTypes: [...toolCallTypes.entries()].sort(([left], [right]) => left - right).map(([, type]) => type)
1343
- }
1344
- }
1345
- }
1346
- });
1347
- }
1348
- })
1349
- ),
1350
- request: { body },
1351
- response: { headers: responseHeaders }
1352
- };
1353
- }
640
+ var MoonshotAIChatLanguageModel = class MoonshotAIChatLanguageModel {
641
+ static [WORKFLOW_SERIALIZE](model) {
642
+ return serializeModelOptions({
643
+ modelId: model.modelId,
644
+ config: model.config
645
+ });
646
+ }
647
+ static [WORKFLOW_DESERIALIZE](options) {
648
+ return new MoonshotAIChatLanguageModel(options.modelId, options.config);
649
+ }
650
+ constructor(modelId, config) {
651
+ this.specificationVersion = "v4";
652
+ this.supportedUrls = {
653
+ "image/*": [/^ms:\/\//],
654
+ "video/*": [/^ms:\/\//]
655
+ };
656
+ this.modelId = modelId;
657
+ this.config = config;
658
+ this.failedResponseHandler = createJsonErrorResponseHandler({
659
+ errorSchema: moonshotAIErrorSchema,
660
+ errorToMessage: (error) => error.error.message
661
+ });
662
+ }
663
+ get provider() {
664
+ return this.config.provider;
665
+ }
666
+ get providerOptionsName() {
667
+ return this.config.provider.split(".")[0].trim();
668
+ }
669
+ async getArgs({ prompt, maxOutputTokens, temperature, topP, topK, frequencyPenalty, presencePenalty, reasoning, providerOptions, stopSequences, responseFormat, seed, toolChoice, tools }) {
670
+ const moonshotOptions = await parseProviderOptions({
671
+ provider: this.providerOptionsName,
672
+ providerOptions,
673
+ schema: moonshotaiLanguageModelOptions
674
+ }) ?? {};
675
+ const allWarnings = [];
676
+ if (topK != null) allWarnings.push({
677
+ type: "unsupported",
678
+ feature: "topK"
679
+ });
680
+ if (seed != null) allWarnings.push({
681
+ type: "unsupported",
682
+ feature: "seed"
683
+ });
684
+ const supportsSamplingOptions = !isMoonshotAIKimiModel(this.modelId);
685
+ if (!supportsSamplingOptions && temperature != null) allWarnings.push({
686
+ type: "unsupported",
687
+ feature: "temperature",
688
+ details: `temperature is fixed by model "${this.modelId}" and has been omitted.`
689
+ });
690
+ if (!supportsSamplingOptions && topP != null) allWarnings.push({
691
+ type: "unsupported",
692
+ feature: "topP",
693
+ details: `topP is fixed by model "${this.modelId}" and has been omitted.`
694
+ });
695
+ if (!supportsSamplingOptions && frequencyPenalty != null) allWarnings.push({
696
+ type: "unsupported",
697
+ feature: "frequencyPenalty",
698
+ details: `frequencyPenalty is fixed by model "${this.modelId}" and has been omitted.`
699
+ });
700
+ if (!supportsSamplingOptions && presencePenalty != null) allWarnings.push({
701
+ type: "unsupported",
702
+ feature: "presencePenalty",
703
+ details: `presencePenalty is fixed by model "${this.modelId}" and has been omitted.`
704
+ });
705
+ const { tools: moonshotTools, toolChoice: moonshotToolChoice, toolWarnings } = prepareTools({
706
+ tools,
707
+ toolChoice,
708
+ modelId: this.modelId
709
+ });
710
+ const modelFamily = getMoonshotAIModelFamily(this.modelId);
711
+ const requestedThinking = moonshotOptions.thinking;
712
+ const requestedReasoningEffort = moonshotOptions.reasoningEffort;
713
+ const preserveReasoning = moonshotOptions.reasoningHistory === "preserved";
714
+ if (requestedThinking?.budgetTokens != null) allWarnings.push({
715
+ type: "deprecated",
716
+ setting: "providerOptions.moonshotai.thinking.budgetTokens",
717
+ message: "Moonshot Chat Completions does not support budget_tokens. Remove budgetTokens; the option has been omitted."
718
+ });
719
+ let thinking;
720
+ let reasoningEffort;
721
+ const warnUnsupportedReasoningEffort = () => {
722
+ if (requestedReasoningEffort != null) allWarnings.push({
723
+ type: "unsupported",
724
+ feature: "reasoningEffort",
725
+ details: `reasoningEffort is only supported by Kimi K3 and has been omitted for model "${this.modelId}".`
726
+ });
727
+ };
728
+ switch (modelFamily) {
729
+ case "kimi-k3":
730
+ if (requestedThinking != null) allWarnings.push({
731
+ type: "unsupported",
732
+ feature: "thinking",
733
+ details: "Kimi K3 always reasons and does not accept the thinking field. The option has been omitted."
734
+ });
735
+ if (reasoning === "none") allWarnings.push({
736
+ type: "unsupported",
737
+ feature: "reasoning \"none\"",
738
+ details: "Kimi K3 reasoning cannot be disabled."
739
+ });
740
+ reasoningEffort = requestedReasoningEffort ?? (isCustomReasoning(reasoning) && reasoning !== "none" ? mapReasoningToProviderEffort({
741
+ reasoning,
742
+ effortMap: {
743
+ minimal: "low",
744
+ low: "low",
745
+ medium: "high",
746
+ high: "high",
747
+ xhigh: "max"
748
+ },
749
+ warnings: allWarnings
750
+ }) : void 0);
751
+ break;
752
+ case "kimi-k2.7":
753
+ warnUnsupportedReasoningEffort();
754
+ if (requestedThinking?.type === "disabled" || reasoning === "none") allWarnings.push({
755
+ type: "unsupported",
756
+ feature: requestedThinking?.type === "disabled" ? "thinking.type \"disabled\"" : "reasoning \"none\"",
757
+ details: "Kimi K2.7 thinking cannot be disabled."
758
+ });
759
+ else if (requestedThinking?.type === "enabled") thinking = { type: "enabled" };
760
+ break;
761
+ case "kimi-k2.6": {
762
+ warnUnsupportedReasoningEffort();
763
+ const thinkingType = requestedThinking?.type ?? (isCustomReasoning(reasoning) ? reasoning === "none" ? "disabled" : "enabled" : void 0);
764
+ if (thinkingType != null || preserveReasoning) thinking = {
765
+ type: thinkingType ?? "enabled",
766
+ ...preserveReasoning ? { keep: "all" } : {}
767
+ };
768
+ break;
769
+ }
770
+ case "kimi-k2.5": {
771
+ warnUnsupportedReasoningEffort();
772
+ const thinkingType = requestedThinking?.type ?? (isCustomReasoning(reasoning) ? reasoning === "none" ? "disabled" : "enabled" : void 0);
773
+ if (thinkingType != null) thinking = { type: thinkingType };
774
+ if (preserveReasoning) allWarnings.push({
775
+ type: "unsupported",
776
+ feature: `reasoningHistory 'preserved' is not supported by model "${this.modelId}"`
777
+ });
778
+ break;
779
+ }
780
+ case "moonshot-v1":
781
+ warnUnsupportedReasoningEffort();
782
+ if (requestedThinking != null) allWarnings.push({
783
+ type: "unsupported",
784
+ feature: "thinking",
785
+ details: `thinking is not supported by model "${this.modelId}" and has been omitted.`
786
+ });
787
+ if (isCustomReasoning(reasoning) && reasoning !== "none") allWarnings.push({
788
+ type: "unsupported",
789
+ feature: "reasoning",
790
+ details: `reasoning is not supported by model "${this.modelId}".`
791
+ });
792
+ if (preserveReasoning) allWarnings.push({
793
+ type: "unsupported",
794
+ feature: `reasoningHistory 'preserved' is not supported by model "${this.modelId}"`
795
+ });
796
+ break;
797
+ case "unknown":
798
+ if (reasoning === "none") allWarnings.push({
799
+ type: "unsupported",
800
+ feature: "reasoning \"none\"",
801
+ details: "Use providerOptions.moonshotai.thinking to control thinking on custom models."
802
+ });
803
+ reasoningEffort = requestedReasoningEffort ?? (isCustomReasoning(reasoning) && reasoning !== "none" ? mapReasoningToProviderEffort({
804
+ reasoning,
805
+ effortMap: {
806
+ minimal: "low",
807
+ low: "low",
808
+ medium: "high",
809
+ high: "high",
810
+ xhigh: "max"
811
+ },
812
+ warnings: allWarnings
813
+ }) : void 0);
814
+ if (requestedThinking?.type != null) thinking = { type: requestedThinking.type };
815
+ if (preserveReasoning) allWarnings.push({
816
+ type: "unsupported",
817
+ feature: `reasoningHistory 'preserved' is not supported by model "${this.modelId}"`
818
+ });
819
+ }
820
+ let response_format;
821
+ if (responseFormat?.type === "json") {
822
+ if (this.config.supportsStructuredOutputs === true && responseFormat.schema != null) {
823
+ const { $schema: _$schema, ...schemaWithoutDollarSchema } = responseFormat.schema;
824
+ response_format = {
825
+ type: "json_schema",
826
+ json_schema: {
827
+ name: responseFormat.name ?? "response",
828
+ strict: moonshotOptions.strictJsonSchema ?? true,
829
+ schema: normalizeJsonSchemaForMFJS(schemaWithoutDollarSchema)
830
+ }
831
+ };
832
+ } else response_format = { type: "json_object" };
833
+ }
834
+ const { messages, warnings: messageWarnings } = await convertToMoonshotAIChatMessages({
835
+ modelId: this.modelId,
836
+ prompt,
837
+ providerOptionsName: this.providerOptionsName,
838
+ responseFormat: response_format
839
+ });
840
+ allWarnings.push(...messageWarnings);
841
+ return {
842
+ args: {
843
+ model: this.modelId,
844
+ ...(moonshotOptions.logprobs === true || moonshotOptions.topLogprobs != null) && { logprobs: true },
845
+ ...moonshotOptions.topLogprobs != null && { top_logprobs: moonshotOptions.topLogprobs },
846
+ max_completion_tokens: maxOutputTokens,
847
+ temperature: supportsSamplingOptions ? temperature : void 0,
848
+ top_p: supportsSamplingOptions ? topP : void 0,
849
+ frequency_penalty: supportsSamplingOptions ? frequencyPenalty : void 0,
850
+ presence_penalty: supportsSamplingOptions ? presencePenalty : void 0,
851
+ response_format,
852
+ stop: stopSequences,
853
+ messages,
854
+ tools: moonshotTools,
855
+ tool_choice: moonshotToolChoice,
856
+ ...moonshotOptions.prediction != null && { prediction: moonshotOptions.prediction },
857
+ ...thinking != null ? { thinking } : {},
858
+ ...reasoningEffort != null && { reasoning_effort: reasoningEffort },
859
+ ...moonshotOptions.promptCacheKey != null && { prompt_cache_key: moonshotOptions.promptCacheKey },
860
+ ...moonshotOptions.safetyIdentifier != null && { safety_identifier: moonshotOptions.safetyIdentifier }
861
+ },
862
+ warnings: [...allWarnings, ...toolWarnings]
863
+ };
864
+ }
865
+ async doGenerate(options) {
866
+ const { args, warnings } = await this.getArgs({ ...options });
867
+ const { responseHeaders, value: responseBody, rawValue: rawResponse } = await postJsonToApi({
868
+ url: this.config.url({
869
+ path: "/chat/completions",
870
+ modelId: this.modelId
871
+ }),
872
+ headers: combineHeaders(this.config.headers?.(), options.headers),
873
+ body: args,
874
+ failedResponseHandler: this.failedResponseHandler,
875
+ successfulResponseHandler: createJsonResponseHandler(moonshotAIChatResponseSchema),
876
+ abortSignal: options.abortSignal,
877
+ fetch: this.config.fetch
878
+ });
879
+ const choice = responseBody.choices[0];
880
+ const content = [];
881
+ const reasoning = choice.message.reasoning_content;
882
+ if (reasoning != null && reasoning.length > 0) content.push({
883
+ type: "reasoning",
884
+ text: reasoning
885
+ });
886
+ if (choice.message.tool_calls != null) for (const toolCall of choice.message.tool_calls) content.push({
887
+ type: "tool-call",
888
+ toolCallId: toolCall.id || generateId(),
889
+ toolName: toolCall.function.name,
890
+ input: toolCall.function.arguments ?? ""
891
+ });
892
+ const text = choice.message.content;
893
+ if (text != null && text.length > 0) content.push({
894
+ type: "text",
895
+ text
896
+ });
897
+ return {
898
+ content,
899
+ finishReason: {
900
+ unified: mapMoonshotAIFinishReason(choice.finish_reason),
901
+ raw: choice.finish_reason ?? void 0
902
+ },
903
+ usage: convertMoonshotAIChatUsage(responseBody.usage),
904
+ providerMetadata: { [this.providerOptionsName]: {
905
+ ...choice.logprobs != null && { logprobs: choice.logprobs },
906
+ ...responseBody.object != null && { responseObject: responseBody.object },
907
+ ...choice.index != null && { choiceIndex: choice.index },
908
+ ...choice.message.role != null && { messageRole: choice.message.role },
909
+ ...choice.message.tool_calls != null && { toolCallTypes: choice.message.tool_calls.map((toolCall) => toolCall.type).filter((type) => type != null) }
910
+ } },
911
+ request: { body: args },
912
+ response: {
913
+ ...createLanguageModelResponseMetadata(responseBody),
914
+ headers: responseHeaders,
915
+ body: rawResponse
916
+ },
917
+ warnings
918
+ };
919
+ }
920
+ async doStream(options) {
921
+ const { args, warnings } = await this.getArgs({ ...options });
922
+ const body = {
923
+ ...args,
924
+ stream: true,
925
+ ...this.config.includeUsage && { stream_options: { include_usage: true } }
926
+ };
927
+ const { responseHeaders, value: response } = await postJsonToApi({
928
+ url: this.config.url({
929
+ path: "/chat/completions",
930
+ modelId: this.modelId
931
+ }),
932
+ headers: combineHeaders(this.config.headers?.(), options.headers),
933
+ body,
934
+ failedResponseHandler: this.failedResponseHandler,
935
+ successfulResponseHandler: createEventSourceResponseHandler(moonshotAIChatChunkSchema),
936
+ abortSignal: options.abortSignal,
937
+ fetch: this.config.fetch
938
+ });
939
+ let toolCallTracker;
940
+ let finishReason = {
941
+ unified: "other",
942
+ raw: void 0
943
+ };
944
+ let topLevelUsage = void 0;
945
+ let choiceUsage = void 0;
946
+ const contentLogprobs = [];
947
+ const providerOptionsName = this.providerOptionsName;
948
+ let isFirstChunk = true;
949
+ let isActiveReasoning = false;
950
+ let isActiveText = false;
951
+ let responseObject;
952
+ let choiceIndex;
953
+ let messageRole;
954
+ const toolCallTypes = /* @__PURE__ */ new Map();
955
+ return {
956
+ stream: response.pipeThrough(new TransformStream({
957
+ start(controller) {
958
+ toolCallTracker = new StreamingToolCallTracker(controller, { generateId });
959
+ controller.enqueue({
960
+ type: "stream-start",
961
+ warnings
962
+ });
963
+ },
964
+ transform(chunk, controller) {
965
+ if (options.includeRawChunks) controller.enqueue({
966
+ type: "raw",
967
+ rawValue: chunk.rawValue
968
+ });
969
+ if (!chunk.success) {
970
+ finishReason = {
971
+ unified: "error",
972
+ raw: void 0
973
+ };
974
+ controller.enqueue({
975
+ type: "error",
976
+ error: chunk.error
977
+ });
978
+ return;
979
+ }
980
+ const value = chunk.value;
981
+ if ("error" in value) {
982
+ finishReason = {
983
+ unified: "error",
984
+ raw: void 0
985
+ };
986
+ controller.enqueue({
987
+ type: "error",
988
+ error: createMoonshotAIStreamError(value.error, value)
989
+ });
990
+ return;
991
+ }
992
+ if (isFirstChunk) {
993
+ isFirstChunk = false;
994
+ controller.enqueue({
995
+ type: "response-metadata",
996
+ ...createLanguageModelResponseMetadata(value)
997
+ });
998
+ }
999
+ if (value.usage != null) topLevelUsage = value.usage;
1000
+ if (value.object != null) responseObject = value.object;
1001
+ const choice = value.choices[0];
1002
+ if (choice?.usage != null) choiceUsage = choice.usage;
1003
+ if (choice?.index != null) choiceIndex = choice.index;
1004
+ if (choice?.finish_reason != null) finishReason = {
1005
+ unified: mapMoonshotAIFinishReason(choice.finish_reason),
1006
+ raw: choice.finish_reason
1007
+ };
1008
+ if (choice?.logprobs?.content != null) contentLogprobs.push(...choice.logprobs.content);
1009
+ if (choice?.delta == null) return;
1010
+ const delta = choice.delta;
1011
+ if (delta.role != null) messageRole = delta.role;
1012
+ const reasoningContent = delta.reasoning_content;
1013
+ if (reasoningContent) {
1014
+ if (!isActiveReasoning) {
1015
+ controller.enqueue({
1016
+ type: "reasoning-start",
1017
+ id: "reasoning-0"
1018
+ });
1019
+ isActiveReasoning = true;
1020
+ }
1021
+ controller.enqueue({
1022
+ type: "reasoning-delta",
1023
+ id: "reasoning-0",
1024
+ delta: reasoningContent
1025
+ });
1026
+ }
1027
+ if (delta.content) {
1028
+ if (!isActiveText) {
1029
+ controller.enqueue({
1030
+ type: "text-start",
1031
+ id: "txt-0"
1032
+ });
1033
+ isActiveText = true;
1034
+ }
1035
+ if (isActiveReasoning) {
1036
+ controller.enqueue({
1037
+ type: "reasoning-end",
1038
+ id: "reasoning-0"
1039
+ });
1040
+ isActiveReasoning = false;
1041
+ }
1042
+ controller.enqueue({
1043
+ type: "text-delta",
1044
+ id: "txt-0",
1045
+ delta: delta.content
1046
+ });
1047
+ }
1048
+ if (delta.tool_calls != null && delta.tool_calls.length > 0) {
1049
+ if (isActiveReasoning) {
1050
+ controller.enqueue({
1051
+ type: "reasoning-end",
1052
+ id: "reasoning-0"
1053
+ });
1054
+ isActiveReasoning = false;
1055
+ }
1056
+ for (const [index, toolCallDelta] of delta.tool_calls.entries()) {
1057
+ const toolCallIndex = toolCallDelta.index ?? index;
1058
+ if (toolCallDelta.type != null) toolCallTypes.set(toolCallIndex, toolCallDelta.type);
1059
+ toolCallTracker.processDelta({
1060
+ ...toolCallDelta,
1061
+ index: toolCallIndex
1062
+ });
1063
+ }
1064
+ }
1065
+ },
1066
+ flush(controller) {
1067
+ if (isActiveReasoning) controller.enqueue({
1068
+ type: "reasoning-end",
1069
+ id: "reasoning-0"
1070
+ });
1071
+ if (isActiveText) controller.enqueue({
1072
+ type: "text-end",
1073
+ id: "txt-0"
1074
+ });
1075
+ toolCallTracker.flush();
1076
+ controller.enqueue({
1077
+ type: "finish",
1078
+ finishReason,
1079
+ usage: convertMoonshotAIChatUsage(topLevelUsage ?? choiceUsage),
1080
+ providerMetadata: { [providerOptionsName]: {
1081
+ ...contentLogprobs.length > 0 && { logprobs: { content: contentLogprobs } },
1082
+ ...responseObject != null && { responseObject },
1083
+ ...choiceIndex != null && { choiceIndex },
1084
+ ...messageRole != null && { messageRole },
1085
+ ...toolCallTypes.size > 0 && { toolCallTypes: [...toolCallTypes.entries()].sort(([left], [right]) => left - right).map(([, type]) => type) }
1086
+ } }
1087
+ });
1088
+ }
1089
+ })),
1090
+ request: { body },
1091
+ response: { headers: responseHeaders }
1092
+ };
1093
+ }
1354
1094
  };
1355
-
1356
- // src/version.ts
1357
- var VERSION = true ? "3.0.60" : "0.0.0-test";
1358
-
1359
- // src/moonshotai-provider.ts
1360
- var defaultBaseURL = "https://api.moonshot.ai/v1";
1095
+ //#endregion
1096
+ //#region src/version.ts
1097
+ const VERSION = "3.0.61";
1098
+ //#endregion
1099
+ //#region src/moonshotai-provider.ts
1100
+ const defaultBaseURL = "https://api.moonshot.ai/v1";
1361
1101
  function getModelStructuredOutputSupport(modelId) {
1362
- return modelId.startsWith("kimi-k") || modelId === "moonshot-v1-8k" || modelId === "moonshot-v1-32k" || modelId === "moonshot-v1-128k" || modelId === "moonshot-v1-auto" || modelId === "moonshot-v1-8k-vision-preview" || modelId === "moonshot-v1-32k-vision-preview" || modelId === "moonshot-v1-128k-vision-preview";
1102
+ return modelId.startsWith("kimi-k") || modelId === "moonshot-v1-8k" || modelId === "moonshot-v1-32k" || modelId === "moonshot-v1-128k" || modelId === "moonshot-v1-auto" || modelId === "moonshot-v1-8k-vision-preview" || modelId === "moonshot-v1-32k-vision-preview" || modelId === "moonshot-v1-128k-vision-preview";
1363
1103
  }
1364
1104
  function createMoonshotAI(options = {}) {
1365
- const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);
1366
- const getHeaders = () => withUserAgentSuffix(
1367
- {
1368
- Authorization: `Bearer ${loadApiKey({
1369
- apiKey: options.apiKey,
1370
- environmentVariableName: "MOONSHOT_API_KEY",
1371
- description: "Moonshot API key"
1372
- })}`,
1373
- ...options.headers
1374
- },
1375
- `ai-sdk-moonshotai/${VERSION}`
1376
- );
1377
- const createChatModel = (modelId) => {
1378
- return new MoonshotAIChatLanguageModel(modelId, {
1379
- provider: "moonshotai.chat",
1380
- url: ({ path }) => `${baseURL}${path}`,
1381
- headers: getHeaders,
1382
- fetch: options.fetch,
1383
- includeUsage: true,
1384
- supportsStructuredOutputs: getModelStructuredOutputSupport(modelId)
1385
- });
1386
- };
1387
- const provider = (modelId) => createChatModel(modelId);
1388
- provider.specificationVersion = "v4";
1389
- provider.chatModel = createChatModel;
1390
- provider.languageModel = createChatModel;
1391
- provider.embeddingModel = (modelId) => {
1392
- throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
1393
- };
1394
- provider.imageModel = (modelId) => {
1395
- throw new NoSuchModelError({ modelId, modelType: "imageModel" });
1396
- };
1397
- return provider;
1105
+ const baseURL = withoutTrailingSlash(options.baseURL ?? defaultBaseURL);
1106
+ const getHeaders = () => withUserAgentSuffix({
1107
+ Authorization: `Bearer ${loadApiKey({
1108
+ apiKey: options.apiKey,
1109
+ environmentVariableName: "MOONSHOT_API_KEY",
1110
+ description: "Moonshot API key"
1111
+ })}`,
1112
+ ...options.headers
1113
+ }, `ai-sdk-moonshotai/${VERSION}`);
1114
+ const createChatModel = (modelId) => {
1115
+ return new MoonshotAIChatLanguageModel(modelId, {
1116
+ provider: "moonshotai.chat",
1117
+ url: ({ path }) => `${baseURL}${path}`,
1118
+ headers: getHeaders,
1119
+ fetch: options.fetch,
1120
+ includeUsage: true,
1121
+ supportsStructuredOutputs: getModelStructuredOutputSupport(modelId)
1122
+ });
1123
+ };
1124
+ const provider = (modelId) => createChatModel(modelId);
1125
+ provider.specificationVersion = "v4";
1126
+ provider.chatModel = createChatModel;
1127
+ provider.languageModel = createChatModel;
1128
+ provider.embeddingModel = (modelId) => {
1129
+ throw new NoSuchModelError({
1130
+ modelId,
1131
+ modelType: "embeddingModel"
1132
+ });
1133
+ };
1134
+ provider.imageModel = (modelId) => {
1135
+ throw new NoSuchModelError({
1136
+ modelId,
1137
+ modelType: "imageModel"
1138
+ });
1139
+ };
1140
+ return provider;
1398
1141
  }
1399
- var moonshotai = createMoonshotAI();
1400
- export {
1401
- VERSION,
1402
- createMoonshotAI,
1403
- moonshotai
1404
- };
1142
+ const moonshotai = createMoonshotAI();
1143
+ //#endregion
1144
+ export { VERSION, createMoonshotAI, moonshotai };
1145
+
1405
1146
  //# sourceMappingURL=index.js.map