@ai-sdk/alibaba 1.0.0

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.mjs ADDED
@@ -0,0 +1,744 @@
1
+ // src/alibaba-provider.ts
2
+ import {
3
+ NoSuchModelError
4
+ } from "@ai-sdk/provider";
5
+ import {
6
+ createJsonErrorResponseHandler,
7
+ loadApiKey,
8
+ withoutTrailingSlash,
9
+ withUserAgentSuffix
10
+ } from "@ai-sdk/provider-utils";
11
+ import { z as z3 } from "zod/v4";
12
+
13
+ // src/alibaba-chat-language-model.ts
14
+ import {
15
+ InvalidResponseDataError
16
+ } from "@ai-sdk/provider";
17
+ import {
18
+ combineHeaders,
19
+ createEventSourceResponseHandler,
20
+ createJsonResponseHandler,
21
+ generateId,
22
+ isParsableJson,
23
+ parseProviderOptions,
24
+ postJsonToApi
25
+ } from "@ai-sdk/provider-utils";
26
+ import { z as z2 } from "zod/v4";
27
+ import {
28
+ getResponseMetadata,
29
+ mapOpenAICompatibleFinishReason,
30
+ prepareTools
31
+ } from "@ai-sdk/openai-compatible/internal";
32
+
33
+ // src/alibaba-chat-options.ts
34
+ import { z } from "zod/v4";
35
+ var alibabaProviderOptions = z.object({
36
+ /**
37
+ * Enable thinking/reasoning mode for supported models.
38
+ * When enabled, the model generates reasoning content before the response.
39
+ *
40
+ * @default false
41
+ */
42
+ enableThinking: z.boolean().optional(),
43
+ /**
44
+ * Maximum number of reasoning tokens to generate.
45
+ */
46
+ thinkingBudget: z.number().positive().optional(),
47
+ /**
48
+ * Whether to enable parallel function calling during tool use.
49
+ *
50
+ * @default true
51
+ */
52
+ parallelToolCalls: z.boolean().optional()
53
+ });
54
+
55
+ // src/convert-to-alibaba-chat-messages.ts
56
+ import {
57
+ UnsupportedFunctionalityError
58
+ } from "@ai-sdk/provider";
59
+ import { convertToBase64 } from "@ai-sdk/provider-utils";
60
+ function formatImageUrl({
61
+ data,
62
+ mediaType
63
+ }) {
64
+ return data instanceof URL ? data.toString() : `data:${mediaType};base64,${convertToBase64(data)}`;
65
+ }
66
+ function convertToAlibabaChatMessages({
67
+ prompt,
68
+ cacheControlValidator
69
+ }) {
70
+ var _a;
71
+ const messages = [];
72
+ for (const { role, content, ...message } of prompt) {
73
+ switch (role) {
74
+ case "system": {
75
+ const cacheControl = cacheControlValidator == null ? void 0 : cacheControlValidator.getCacheControl(
76
+ message.providerOptions
77
+ );
78
+ if (cacheControl) {
79
+ messages.push({
80
+ role: "system",
81
+ content: [
82
+ {
83
+ type: "text",
84
+ text: content,
85
+ cache_control: cacheControl
86
+ }
87
+ ]
88
+ });
89
+ } else {
90
+ messages.push({ role: "system", content });
91
+ }
92
+ break;
93
+ }
94
+ case "user": {
95
+ if (content.length === 1 && content[0].type === "text") {
96
+ messages.push({
97
+ role: "user",
98
+ content: content[0].text
99
+ });
100
+ break;
101
+ }
102
+ messages.push({
103
+ role: "user",
104
+ content: content.map((part) => {
105
+ switch (part.type) {
106
+ case "text": {
107
+ return { type: "text", text: part.text };
108
+ }
109
+ case "file": {
110
+ if (part.mediaType.startsWith("image/")) {
111
+ const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
112
+ return {
113
+ type: "image_url",
114
+ image_url: {
115
+ url: formatImageUrl({ data: part.data, mediaType })
116
+ }
117
+ };
118
+ } else {
119
+ throw new UnsupportedFunctionalityError({
120
+ functionality: "Only image file parts are supported"
121
+ });
122
+ }
123
+ }
124
+ }
125
+ })
126
+ });
127
+ break;
128
+ }
129
+ case "assistant": {
130
+ let text = "";
131
+ const toolCalls = [];
132
+ for (const part of content) {
133
+ switch (part.type) {
134
+ case "text": {
135
+ text += part.text;
136
+ break;
137
+ }
138
+ case "tool-call": {
139
+ toolCalls.push({
140
+ id: part.toolCallId,
141
+ type: "function",
142
+ function: {
143
+ name: part.toolName,
144
+ arguments: JSON.stringify(part.input)
145
+ }
146
+ });
147
+ break;
148
+ }
149
+ case "reasoning": {
150
+ text += part.text;
151
+ break;
152
+ }
153
+ }
154
+ }
155
+ messages.push({
156
+ role: "assistant",
157
+ content: text || null,
158
+ tool_calls: toolCalls.length > 0 ? toolCalls : void 0
159
+ });
160
+ break;
161
+ }
162
+ case "tool": {
163
+ for (const toolResponse of content) {
164
+ if (toolResponse.type === "tool-approval-response") {
165
+ continue;
166
+ }
167
+ const output = toolResponse.output;
168
+ let contentValue;
169
+ switch (output.type) {
170
+ case "text":
171
+ case "error-text":
172
+ contentValue = output.value;
173
+ break;
174
+ case "execution-denied":
175
+ contentValue = (_a = output.reason) != null ? _a : "Tool execution denied.";
176
+ break;
177
+ case "content":
178
+ case "json":
179
+ case "error-json":
180
+ contentValue = JSON.stringify(output.value);
181
+ break;
182
+ }
183
+ messages.push({
184
+ role: "tool",
185
+ tool_call_id: toolResponse.toolCallId,
186
+ content: contentValue
187
+ });
188
+ }
189
+ break;
190
+ }
191
+ default: {
192
+ const _exhaustiveCheck = role;
193
+ throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
194
+ }
195
+ }
196
+ }
197
+ return messages;
198
+ }
199
+
200
+ // src/convert-alibaba-usage.ts
201
+ import { convertOpenAICompatibleChatUsage } from "@ai-sdk/openai-compatible/internal";
202
+ function convertAlibabaUsage(usage) {
203
+ var _a, _b, _c, _d;
204
+ const baseUsage = convertOpenAICompatibleChatUsage(usage);
205
+ const cacheWriteTokens = (_b = (_a = usage == null ? void 0 : usage.prompt_tokens_details) == null ? void 0 : _a.cache_creation_input_tokens) != null ? _b : 0;
206
+ const noCacheTokens = ((_c = baseUsage.inputTokens.total) != null ? _c : 0) - ((_d = baseUsage.inputTokens.cacheRead) != null ? _d : 0) - cacheWriteTokens;
207
+ return {
208
+ ...baseUsage,
209
+ inputTokens: {
210
+ ...baseUsage.inputTokens,
211
+ cacheWrite: cacheWriteTokens,
212
+ noCache: noCacheTokens
213
+ }
214
+ };
215
+ }
216
+
217
+ // src/get-cache-control.ts
218
+ var MAX_CACHE_BREAKPOINTS = 4;
219
+ function getCacheControl(providerMetadata) {
220
+ var _a;
221
+ const alibaba2 = providerMetadata == null ? void 0 : providerMetadata.alibaba;
222
+ const cacheControlValue = (_a = alibaba2 == null ? void 0 : alibaba2.cacheControl) != null ? _a : alibaba2 == null ? void 0 : alibaba2.cache_control;
223
+ return cacheControlValue;
224
+ }
225
+ var CacheControlValidator = class {
226
+ constructor() {
227
+ this.breakpointCount = 0;
228
+ this.warnings = [];
229
+ }
230
+ getCacheControl(providerMetadata) {
231
+ const cacheControlValue = getCacheControl(providerMetadata);
232
+ if (!cacheControlValue) {
233
+ return void 0;
234
+ }
235
+ this.breakpointCount++;
236
+ if (this.breakpointCount > MAX_CACHE_BREAKPOINTS) {
237
+ this.warnings.push({
238
+ type: "unsupported",
239
+ feature: "cacheControl breakpoint limit",
240
+ details: `Maximum ${MAX_CACHE_BREAKPOINTS} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`
241
+ });
242
+ return void 0;
243
+ }
244
+ return cacheControlValue;
245
+ }
246
+ getWarnings() {
247
+ return this.warnings;
248
+ }
249
+ };
250
+
251
+ // src/alibaba-chat-language-model.ts
252
+ var AlibabaLanguageModel = class {
253
+ constructor(modelId, config) {
254
+ this.specificationVersion = "v3";
255
+ this.supportedUrls = {
256
+ "image/*": [/^https?:\/\/.*$/]
257
+ };
258
+ this.modelId = modelId;
259
+ this.config = config;
260
+ }
261
+ get provider() {
262
+ return this.config.provider;
263
+ }
264
+ /**
265
+ * Builds request arguments for Alibaba API call.
266
+ * Converts AI SDK options to Alibaba API format.
267
+ */
268
+ async getArgs({
269
+ prompt,
270
+ maxOutputTokens,
271
+ temperature,
272
+ topP,
273
+ topK,
274
+ frequencyPenalty,
275
+ presencePenalty,
276
+ stopSequences,
277
+ responseFormat,
278
+ seed,
279
+ providerOptions,
280
+ tools,
281
+ toolChoice
282
+ }) {
283
+ var _a;
284
+ const warnings = [];
285
+ const cacheControlValidator = new CacheControlValidator();
286
+ const alibabaOptions = await parseProviderOptions({
287
+ provider: "alibaba",
288
+ providerOptions,
289
+ schema: alibabaProviderOptions
290
+ });
291
+ if (frequencyPenalty != null) {
292
+ warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
293
+ }
294
+ const baseArgs = {
295
+ model: this.modelId,
296
+ max_tokens: maxOutputTokens,
297
+ temperature,
298
+ top_p: topP,
299
+ top_k: topK,
300
+ presence_penalty: presencePenalty,
301
+ stop: stopSequences,
302
+ seed,
303
+ response_format: (responseFormat == null ? void 0 : responseFormat.type) === "json" ? responseFormat.schema != null ? {
304
+ type: "json_schema",
305
+ json_schema: {
306
+ schema: responseFormat.schema,
307
+ name: (_a = responseFormat.name) != null ? _a : "response",
308
+ description: responseFormat.description
309
+ }
310
+ } : { type: "json_object" } : void 0,
311
+ // Alibaba-specific options
312
+ ...(alibabaOptions == null ? void 0 : alibabaOptions.enableThinking) != null ? { enable_thinking: alibabaOptions.enableThinking } : {},
313
+ ...(alibabaOptions == null ? void 0 : alibabaOptions.thinkingBudget) != null ? { thinking_budget: alibabaOptions.thinkingBudget } : {},
314
+ // Convert messages with cache control support
315
+ messages: convertToAlibabaChatMessages({
316
+ prompt,
317
+ cacheControlValidator
318
+ })
319
+ };
320
+ const {
321
+ tools: alibabaTools,
322
+ toolChoice: alibabaToolChoice,
323
+ toolWarnings
324
+ } = prepareTools({ tools, toolChoice });
325
+ warnings.push(...cacheControlValidator.getWarnings());
326
+ return {
327
+ args: {
328
+ ...baseArgs,
329
+ tools: alibabaTools,
330
+ tool_choice: alibabaToolChoice,
331
+ ...alibabaTools != null && (alibabaOptions == null ? void 0 : alibabaOptions.parallelToolCalls) !== void 0 ? { parallel_tool_calls: alibabaOptions.parallelToolCalls } : {}
332
+ },
333
+ warnings: [...warnings, ...toolWarnings]
334
+ };
335
+ }
336
+ async doGenerate(options) {
337
+ var _a;
338
+ const { args, warnings } = await this.getArgs(options);
339
+ const {
340
+ responseHeaders,
341
+ value: response,
342
+ rawValue: rawResponse
343
+ } = await postJsonToApi({
344
+ url: `${this.config.baseURL}/chat/completions`,
345
+ headers: combineHeaders(this.config.headers(), options.headers),
346
+ body: args,
347
+ failedResponseHandler: alibabaFailedResponseHandler,
348
+ successfulResponseHandler: createJsonResponseHandler(
349
+ alibabaChatResponseSchema
350
+ ),
351
+ abortSignal: options.abortSignal,
352
+ fetch: this.config.fetch
353
+ });
354
+ const choice = response.choices[0];
355
+ const content = [];
356
+ const text = choice.message.content;
357
+ if (text != null && text.length > 0) {
358
+ content.push({ type: "text", text });
359
+ }
360
+ const reasoning = choice.message.reasoning_content;
361
+ if (reasoning != null && reasoning.length > 0) {
362
+ content.push({
363
+ type: "reasoning",
364
+ text: reasoning
365
+ });
366
+ }
367
+ if (choice.message.tool_calls != null) {
368
+ for (const toolCall of choice.message.tool_calls) {
369
+ content.push({
370
+ type: "tool-call",
371
+ toolCallId: toolCall.id,
372
+ toolName: toolCall.function.name,
373
+ input: toolCall.function.arguments
374
+ });
375
+ }
376
+ }
377
+ return {
378
+ content,
379
+ finishReason: {
380
+ unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
381
+ raw: (_a = choice.finish_reason) != null ? _a : void 0
382
+ },
383
+ usage: convertAlibabaUsage(response.usage),
384
+ request: { body: JSON.stringify(args) },
385
+ response: {
386
+ ...getResponseMetadata(response),
387
+ headers: responseHeaders,
388
+ body: rawResponse
389
+ },
390
+ warnings
391
+ };
392
+ }
393
+ async doStream(options) {
394
+ const { args, warnings } = await this.getArgs(options);
395
+ const body = {
396
+ ...args,
397
+ stream: true,
398
+ stream_options: this.config.includeUsage ? { include_usage: true } : void 0
399
+ };
400
+ const { responseHeaders, value: response } = await postJsonToApi({
401
+ url: `${this.config.baseURL}/chat/completions`,
402
+ headers: combineHeaders(this.config.headers(), options.headers),
403
+ body,
404
+ failedResponseHandler: alibabaFailedResponseHandler,
405
+ successfulResponseHandler: createEventSourceResponseHandler(
406
+ alibabaChatChunkSchema
407
+ ),
408
+ abortSignal: options.abortSignal,
409
+ fetch: this.config.fetch
410
+ });
411
+ let finishReason = {
412
+ unified: "other",
413
+ raw: void 0
414
+ };
415
+ let usage = void 0;
416
+ let isFirstChunk = true;
417
+ let activeText = false;
418
+ let activeReasoningId = null;
419
+ const toolCalls = [];
420
+ return {
421
+ stream: response.pipeThrough(
422
+ new TransformStream({
423
+ start(controller) {
424
+ controller.enqueue({ type: "stream-start", warnings });
425
+ },
426
+ transform(chunk, controller) {
427
+ var _a, _b, _c, _d;
428
+ if (options.includeRawChunks) {
429
+ controller.enqueue({ type: "raw", rawValue: chunk.rawValue });
430
+ }
431
+ if (!chunk.success) {
432
+ controller.enqueue({ type: "error", error: chunk.error });
433
+ return;
434
+ }
435
+ const value = chunk.value;
436
+ if (isFirstChunk) {
437
+ isFirstChunk = false;
438
+ controller.enqueue({
439
+ type: "response-metadata",
440
+ ...getResponseMetadata(value)
441
+ });
442
+ }
443
+ if (value.usage != null) {
444
+ usage = value.usage;
445
+ }
446
+ if (value.choices.length === 0) {
447
+ return;
448
+ }
449
+ const choice = value.choices[0];
450
+ const delta = choice.delta;
451
+ if (delta.reasoning_content != null && delta.reasoning_content.length > 0) {
452
+ if (activeReasoningId == null) {
453
+ if (activeText) {
454
+ controller.enqueue({ type: "text-end", id: "0" });
455
+ activeText = false;
456
+ }
457
+ activeReasoningId = generateId();
458
+ controller.enqueue({
459
+ type: "reasoning-start",
460
+ id: activeReasoningId
461
+ });
462
+ }
463
+ controller.enqueue({
464
+ type: "reasoning-delta",
465
+ id: activeReasoningId,
466
+ delta: delta.reasoning_content
467
+ });
468
+ }
469
+ if (delta.content != null && delta.content.length > 0) {
470
+ if (activeReasoningId != null) {
471
+ controller.enqueue({
472
+ type: "reasoning-end",
473
+ id: activeReasoningId
474
+ });
475
+ activeReasoningId = null;
476
+ }
477
+ if (!activeText) {
478
+ controller.enqueue({ type: "text-start", id: "0" });
479
+ activeText = true;
480
+ }
481
+ controller.enqueue({
482
+ type: "text-delta",
483
+ id: "0",
484
+ delta: delta.content
485
+ });
486
+ }
487
+ if (delta.tool_calls != null) {
488
+ if (activeReasoningId != null) {
489
+ controller.enqueue({
490
+ type: "reasoning-end",
491
+ id: activeReasoningId
492
+ });
493
+ activeReasoningId = null;
494
+ }
495
+ if (activeText) {
496
+ controller.enqueue({ type: "text-end", id: "0" });
497
+ activeText = false;
498
+ }
499
+ for (const toolCallDelta of delta.tool_calls) {
500
+ const index = (_a = toolCallDelta.index) != null ? _a : toolCalls.length;
501
+ if (toolCalls[index] == null) {
502
+ if (toolCallDelta.id == null) {
503
+ throw new InvalidResponseDataError({
504
+ data: toolCallDelta,
505
+ message: `Expected 'id' to be a string.`
506
+ });
507
+ }
508
+ if (((_b = toolCallDelta.function) == null ? void 0 : _b.name) == null) {
509
+ throw new InvalidResponseDataError({
510
+ data: toolCallDelta,
511
+ message: `Expected 'function.name' to be a string.`
512
+ });
513
+ }
514
+ controller.enqueue({
515
+ type: "tool-input-start",
516
+ id: toolCallDelta.id,
517
+ toolName: toolCallDelta.function.name
518
+ });
519
+ toolCalls[index] = {
520
+ id: toolCallDelta.id,
521
+ type: "function",
522
+ function: {
523
+ name: toolCallDelta.function.name,
524
+ arguments: (_c = toolCallDelta.function.arguments) != null ? _c : ""
525
+ },
526
+ hasFinished: false
527
+ };
528
+ const toolCall2 = toolCalls[index];
529
+ if (toolCall2.function.arguments.length > 0) {
530
+ controller.enqueue({
531
+ type: "tool-input-delta",
532
+ id: toolCall2.id,
533
+ delta: toolCall2.function.arguments
534
+ });
535
+ }
536
+ if (isParsableJson(toolCall2.function.arguments)) {
537
+ controller.enqueue({
538
+ type: "tool-input-end",
539
+ id: toolCall2.id
540
+ });
541
+ controller.enqueue({
542
+ type: "tool-call",
543
+ toolCallId: toolCall2.id,
544
+ toolName: toolCall2.function.name,
545
+ input: toolCall2.function.arguments
546
+ });
547
+ toolCall2.hasFinished = true;
548
+ }
549
+ continue;
550
+ }
551
+ const toolCall = toolCalls[index];
552
+ if (toolCall.hasFinished) {
553
+ continue;
554
+ }
555
+ if (((_d = toolCallDelta.function) == null ? void 0 : _d.arguments) != null) {
556
+ toolCall.function.arguments += toolCallDelta.function.arguments;
557
+ controller.enqueue({
558
+ type: "tool-input-delta",
559
+ id: toolCall.id,
560
+ delta: toolCallDelta.function.arguments
561
+ });
562
+ }
563
+ if (isParsableJson(toolCall.function.arguments)) {
564
+ controller.enqueue({
565
+ type: "tool-input-end",
566
+ id: toolCall.id
567
+ });
568
+ controller.enqueue({
569
+ type: "tool-call",
570
+ toolCallId: toolCall.id,
571
+ toolName: toolCall.function.name,
572
+ input: toolCall.function.arguments
573
+ });
574
+ toolCall.hasFinished = true;
575
+ }
576
+ }
577
+ }
578
+ if (choice.finish_reason != null) {
579
+ finishReason = {
580
+ unified: mapOpenAICompatibleFinishReason(choice.finish_reason),
581
+ raw: choice.finish_reason
582
+ };
583
+ }
584
+ },
585
+ flush(controller) {
586
+ if (activeReasoningId != null) {
587
+ controller.enqueue({
588
+ type: "reasoning-end",
589
+ id: activeReasoningId
590
+ });
591
+ }
592
+ if (activeText) {
593
+ controller.enqueue({ type: "text-end", id: "0" });
594
+ }
595
+ controller.enqueue({
596
+ type: "finish",
597
+ finishReason,
598
+ usage: convertAlibabaUsage(usage)
599
+ });
600
+ }
601
+ })
602
+ ),
603
+ request: { body: JSON.stringify(body) },
604
+ response: { headers: responseHeaders }
605
+ };
606
+ }
607
+ };
608
+ var alibabaUsageSchema = z2.object({
609
+ prompt_tokens: z2.number(),
610
+ completion_tokens: z2.number(),
611
+ total_tokens: z2.number(),
612
+ prompt_tokens_details: z2.object({
613
+ cached_tokens: z2.number().nullish(),
614
+ cache_creation_input_tokens: z2.number().nullish()
615
+ }).nullish(),
616
+ completion_tokens_details: z2.object({
617
+ reasoning_tokens: z2.number().nullish()
618
+ }).nullish()
619
+ });
620
+ var alibabaChatResponseSchema = z2.object({
621
+ id: z2.string().nullish(),
622
+ created: z2.number().nullish(),
623
+ model: z2.string().nullish(),
624
+ choices: z2.array(
625
+ z2.object({
626
+ message: z2.object({
627
+ role: z2.literal("assistant").nullish(),
628
+ content: z2.string().nullish(),
629
+ reasoning_content: z2.string().nullish(),
630
+ // Alibaba thinking mode
631
+ tool_calls: z2.array(
632
+ z2.object({
633
+ id: z2.string(),
634
+ type: z2.literal("function"),
635
+ function: z2.object({
636
+ name: z2.string(),
637
+ arguments: z2.string()
638
+ })
639
+ })
640
+ ).nullish()
641
+ }),
642
+ finish_reason: z2.string().nullish(),
643
+ index: z2.number()
644
+ })
645
+ ),
646
+ usage: alibabaUsageSchema.nullish()
647
+ });
648
+ var alibabaChatChunkSchema = z2.object({
649
+ id: z2.string().nullish(),
650
+ created: z2.number().nullish(),
651
+ model: z2.string().nullish(),
652
+ choices: z2.array(
653
+ z2.object({
654
+ delta: z2.object({
655
+ role: z2.enum(["assistant"]).nullish(),
656
+ content: z2.string().nullish(),
657
+ reasoning_content: z2.string().nullish(),
658
+ // Alibaba thinking mode delta
659
+ tool_calls: z2.array(
660
+ z2.object({
661
+ index: z2.number().nullish(),
662
+ // Index for accumulating tool calls
663
+ id: z2.string().nullish(),
664
+ type: z2.literal("function").nullish(),
665
+ function: z2.object({
666
+ name: z2.string().nullish(),
667
+ arguments: z2.string().nullish()
668
+ }).nullish()
669
+ })
670
+ ).nullish()
671
+ }),
672
+ finish_reason: z2.string().nullish(),
673
+ index: z2.number()
674
+ })
675
+ ),
676
+ usage: alibabaUsageSchema.nullish()
677
+ // Usage only appears in final chunk
678
+ });
679
+
680
+ // src/version.ts
681
+ var VERSION = "1.0.0";
682
+
683
+ // src/alibaba-provider.ts
684
+ var alibabaErrorDataSchema = z3.object({
685
+ error: z3.object({
686
+ message: z3.string(),
687
+ code: z3.string().nullish(),
688
+ type: z3.string().nullish()
689
+ })
690
+ });
691
+ var alibabaFailedResponseHandler = createJsonErrorResponseHandler({
692
+ errorSchema: alibabaErrorDataSchema,
693
+ errorToMessage: (data) => data.error.message
694
+ });
695
+ function createAlibaba(options = {}) {
696
+ var _a;
697
+ const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : "https://dashscope-intl.aliyuncs.com/compatible-mode/v1";
698
+ const getHeaders = () => withUserAgentSuffix(
699
+ {
700
+ Authorization: `Bearer ${loadApiKey({
701
+ apiKey: options.apiKey,
702
+ environmentVariableName: "ALIBABA_API_KEY",
703
+ description: "Alibaba Cloud (DashScope)"
704
+ })}`,
705
+ ...options.headers
706
+ },
707
+ `ai-sdk/alibaba/${VERSION}`
708
+ );
709
+ const createLanguageModel = (modelId) => {
710
+ var _a2;
711
+ return new AlibabaLanguageModel(modelId, {
712
+ provider: "alibaba.chat",
713
+ baseURL,
714
+ headers: getHeaders,
715
+ fetch: options.fetch,
716
+ includeUsage: (_a2 = options.includeUsage) != null ? _a2 : true
717
+ });
718
+ };
719
+ const provider = function(modelId) {
720
+ if (new.target) {
721
+ throw new Error(
722
+ "The Alibaba model function cannot be called with the new keyword."
723
+ );
724
+ }
725
+ return createLanguageModel(modelId);
726
+ };
727
+ provider.specificationVersion = "v3";
728
+ provider.languageModel = createLanguageModel;
729
+ provider.chatModel = createLanguageModel;
730
+ provider.imageModel = (modelId) => {
731
+ throw new NoSuchModelError({ modelId, modelType: "imageModel" });
732
+ };
733
+ provider.embeddingModel = (modelId) => {
734
+ throw new NoSuchModelError({ modelId, modelType: "embeddingModel" });
735
+ };
736
+ return provider;
737
+ }
738
+ var alibaba = createAlibaba();
739
+ export {
740
+ VERSION,
741
+ alibaba,
742
+ createAlibaba
743
+ };
744
+ //# sourceMappingURL=index.mjs.map