@ai-sdk/alibaba 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/LICENSE +13 -0
- package/README.md +121 -0
- package/dist/index.d.mts +77 -0
- package/dist/index.d.ts +77 -0
- package/dist/index.js +797 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +792 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +70 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/alibaba-provider.ts","../src/alibaba-chat-language-model.ts","../src/alibaba-chat-options.ts","../src/convert-alibaba-usage.ts","../src/convert-to-alibaba-chat-messages.ts","../src/get-cache-control.ts","../src/alibaba-prepare-tools.ts","../src/version.ts"],"sourcesContent":["import {\n type LanguageModelV2,\n NoSuchModelError,\n type ProviderV2,\n} from '@ai-sdk/provider';\nimport {\n createJsonErrorResponseHandler,\n type FetchFunction,\n loadApiKey,\n withoutTrailingSlash,\n withUserAgentSuffix,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\nimport { AlibabaLanguageModel } from './alibaba-chat-language-model';\nimport type { AlibabaChatModelId } from './alibaba-chat-options';\nimport { VERSION } from './version';\n\nexport type AlibabaErrorData = z.infer<typeof alibabaErrorDataSchema>;\n\nconst alibabaErrorDataSchema = z.object({\n error: z.object({\n message: z.string(),\n code: z.string().nullish(),\n type: z.string().nullish(),\n }),\n});\n\nexport const alibabaFailedResponseHandler = createJsonErrorResponseHandler({\n errorSchema: alibabaErrorDataSchema,\n errorToMessage: data => data.error.message,\n});\n\nexport interface AlibabaProvider extends ProviderV2 {\n (modelId: AlibabaChatModelId): LanguageModelV2;\n\n /**\n * Creates a model for text generation.\n */\n languageModel(modelId: AlibabaChatModelId): LanguageModelV2;\n\n /**\n * Creates a chat model for text generation.\n */\n chatModel(modelId: AlibabaChatModelId): LanguageModelV2;\n}\n\nexport interface AlibabaProviderSettings {\n /**\n * Use a different URL prefix for API calls, e.g. to use proxy servers or regional endpoints.\n * The default prefix is `https://dashscope-intl.aliyuncs.com/compatible-mode/v1`.\n */\n baseURL?: string;\n\n /**\n * API key that is being sent using the `Authorization` header.\n * It defaults to the `ALIBABA_API_KEY` environment variable.\n */\n apiKey?: string;\n\n /**\n * Custom headers to include in the requests.\n */\n headers?: Record<string, string>;\n\n /**\n * Custom fetch implementation. You can use it as a middleware to intercept requests,\n * or to provide a custom fetch implementation for e.g. testing.\n */\n fetch?: FetchFunction;\n\n /**\n * Include usage information in streaming responses.\n * When enabled, token usage will be included in the final chunk.\n *\n * @default true\n */\n includeUsage?: boolean;\n}\n\n/**\n * Create an Alibaba Cloud (Qwen) provider instance.\n */\nexport function createAlibaba(\n options: AlibabaProviderSettings = {},\n): AlibabaProvider {\n const baseURL =\n withoutTrailingSlash(options.baseURL) ??\n 'https://dashscope-intl.aliyuncs.com/compatible-mode/v1';\n\n const getHeaders = () =>\n withUserAgentSuffix(\n {\n Authorization: `Bearer ${loadApiKey({\n apiKey: options.apiKey,\n environmentVariableName: 'ALIBABA_API_KEY',\n description: 'Alibaba Cloud (DashScope)',\n })}`,\n ...options.headers,\n },\n `ai-sdk/alibaba/${VERSION}`,\n );\n\n const createLanguageModel = (modelId: AlibabaChatModelId) =>\n new AlibabaLanguageModel(modelId, {\n provider: 'alibaba.chat',\n baseURL,\n headers: getHeaders,\n fetch: options.fetch,\n includeUsage: options.includeUsage ?? true,\n });\n\n const provider = function (modelId: AlibabaChatModelId) {\n if (new.target) {\n throw new Error(\n 'The Alibaba model function cannot be called with the new keyword.',\n );\n }\n\n return createLanguageModel(modelId);\n };\n\n provider.specificationVersion = 'v2' as const;\n provider.languageModel = createLanguageModel;\n provider.chatModel = createLanguageModel;\n\n provider.imageModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'imageModel' });\n };\n\n provider.textEmbeddingModel = (modelId: string) => {\n throw new NoSuchModelError({ modelId, modelType: 'textEmbeddingModel' });\n };\n\n return provider;\n}\n\nexport const alibaba = createAlibaba();\n","import {\n getResponseMetadata,\n mapOpenAICompatibleFinishReason,\n} from '@ai-sdk/openai-compatible/internal';\nimport {\n InvalidResponseDataError,\n type LanguageModelV2,\n type LanguageModelV2CallOptions,\n type LanguageModelV2CallWarning,\n type LanguageModelV2Content,\n type LanguageModelV2FinishReason,\n type LanguageModelV2StreamPart,\n} from '@ai-sdk/provider';\nimport {\n combineHeaders,\n createEventSourceResponseHandler,\n createJsonResponseHandler,\n generateId,\n isParsableJson,\n parseProviderOptions,\n postJsonToApi,\n type ParseResult,\n} from '@ai-sdk/provider-utils';\nimport { z } from 'zod/v4';\nimport {\n alibabaLanguageModelOptions,\n type AlibabaChatModelId,\n} from './alibaba-chat-options';\nimport type { AlibabaConfig } from './alibaba-config';\nimport { alibabaFailedResponseHandler } from './alibaba-provider';\nimport { convertAlibabaUsage } from './convert-alibaba-usage';\nimport { convertToAlibabaChatMessages } from './convert-to-alibaba-chat-messages';\nimport { CacheControlValidator } from './get-cache-control';\nimport { prepareTools } from './alibaba-prepare-tools';\n\n/**\n * Alibaba language model implementation.\n *\n * Implements LanguageModelV2 interface for Alibaba Cloud's Qwen models.\n * Supports OpenAI-compatible chat completions API with Alibaba-specific features:\n * - Reasoning/thinking mode (enable_thinking, reasoning_content)\n * - Thinking budget control (thinking_budget)\n * - Prompt caching (cached_tokens tracking)\n */\nexport class AlibabaLanguageModel implements LanguageModelV2 {\n readonly specificationVersion = 'v2';\n readonly modelId: AlibabaChatModelId;\n\n private readonly config: AlibabaConfig;\n\n constructor(modelId: AlibabaChatModelId, config: AlibabaConfig) {\n this.modelId = modelId;\n this.config = config;\n }\n\n get provider(): string {\n return this.config.provider;\n }\n\n readonly supportedUrls: Record<string, RegExp[]> = {\n 'image/*': [/^https?:\\/\\/.*$/],\n };\n\n /**\n * Builds request arguments for Alibaba API call.\n * Converts AI SDK options to Alibaba API format.\n */\n private async getArgs({\n prompt,\n maxOutputTokens,\n temperature,\n topP,\n topK,\n frequencyPenalty,\n presencePenalty,\n stopSequences,\n responseFormat,\n seed,\n providerOptions,\n tools,\n toolChoice,\n }: LanguageModelV2CallOptions) {\n const warnings: LanguageModelV2CallWarning[] = [];\n\n const cacheControlValidator = new CacheControlValidator();\n\n const alibabaOptions = await parseProviderOptions({\n provider: 'alibaba',\n providerOptions,\n schema: alibabaLanguageModelOptions,\n });\n\n // Warn about unsupported features\n if (frequencyPenalty != null) {\n warnings.push({\n type: 'unsupported-setting',\n setting: 'frequencyPenalty',\n });\n }\n\n // Build base request arguments\n const baseArgs = {\n model: this.modelId,\n max_tokens: maxOutputTokens,\n temperature,\n top_p: topP,\n top_k: topK,\n presence_penalty: presencePenalty,\n stop: stopSequences,\n seed,\n response_format:\n responseFormat?.type === 'json'\n ? responseFormat.schema != null\n ? {\n type: 'json_schema',\n json_schema: {\n schema: responseFormat.schema,\n name: responseFormat.name ?? 'response',\n description: responseFormat.description,\n },\n }\n : { type: 'json_object' }\n : undefined,\n\n // Alibaba-specific options\n ...(alibabaOptions?.enableThinking != null\n ? { enable_thinking: alibabaOptions.enableThinking }\n : {}),\n ...(alibabaOptions?.thinkingBudget != null\n ? { thinking_budget: alibabaOptions.thinkingBudget }\n : {}),\n\n // Convert messages with cache control support\n messages: convertToAlibabaChatMessages({\n prompt,\n cacheControlValidator,\n }),\n };\n\n // Prepare tools\n const {\n tools: alibabaTools,\n toolChoice: alibabaToolChoice,\n toolWarnings,\n } = prepareTools({ tools, toolChoice });\n\n warnings.push(...cacheControlValidator.getWarnings());\n\n return {\n args: {\n ...baseArgs,\n tools: alibabaTools,\n tool_choice: alibabaToolChoice,\n ...(alibabaTools != null &&\n alibabaOptions?.parallelToolCalls !== undefined\n ? { parallel_tool_calls: alibabaOptions.parallelToolCalls }\n : {}),\n },\n warnings: [...warnings, ...toolWarnings],\n };\n }\n\n async doGenerate(\n options: Parameters<LanguageModelV2['doGenerate']>[0],\n ): Promise<Awaited<ReturnType<LanguageModelV2['doGenerate']>>> {\n const { args, warnings } = await this.getArgs(options);\n\n const {\n responseHeaders,\n value: response,\n rawValue: rawResponse,\n } = await postJsonToApi({\n url: `${this.config.baseURL}/chat/completions`,\n headers: combineHeaders(this.config.headers(), options.headers),\n body: args,\n failedResponseHandler: alibabaFailedResponseHandler,\n successfulResponseHandler: createJsonResponseHandler(\n alibabaChatResponseSchema,\n ),\n abortSignal: options.abortSignal,\n fetch: this.config.fetch,\n });\n\n const choice = response.choices[0];\n const content: Array<LanguageModelV2Content> = [];\n\n // text content:\n const text = choice.message.content;\n if (text != null && text.length > 0) {\n content.push({ type: 'text', text });\n }\n\n // reasoning content (Alibaba uses 'reasoning_content' field):\n const reasoning = choice.message.reasoning_content;\n if (reasoning != null && reasoning.length > 0) {\n content.push({\n type: 'reasoning',\n text: reasoning,\n });\n }\n\n // tool calls:\n if (choice.message.tool_calls != null) {\n for (const toolCall of choice.message.tool_calls) {\n content.push({\n type: 'tool-call',\n toolCallId: toolCall.id,\n toolName: toolCall.function.name,\n input: toolCall.function.arguments!,\n });\n }\n }\n\n return {\n content,\n finishReason: mapOpenAICompatibleFinishReason(choice.finish_reason),\n usage: convertAlibabaUsage(response.usage),\n request: { body: JSON.stringify(args) },\n response: {\n ...getResponseMetadata(response),\n headers: responseHeaders,\n body: rawResponse,\n },\n warnings,\n providerMetadata: {\n alibaba: {\n cacheCreationInputTokens:\n response.usage?.prompt_tokens_details\n ?.cache_creation_input_tokens ?? null,\n },\n },\n };\n }\n\n async doStream(\n options: Parameters<LanguageModelV2['doStream']>[0],\n ): Promise<Awaited<ReturnType<LanguageModelV2['doStream']>>> {\n const { args, warnings } = await this.getArgs(options);\n const body = {\n ...args,\n stream: true,\n stream_options: this.config.includeUsage\n ? { include_usage: true }\n : undefined,\n };\n\n const { responseHeaders, value: response } = await postJsonToApi({\n url: `${this.config.baseURL}/chat/completions`,\n headers: combineHeaders(this.config.headers(), options.headers),\n body,\n failedResponseHandler: alibabaFailedResponseHandler,\n successfulResponseHandler: createEventSourceResponseHandler(\n alibabaChatChunkSchema,\n ),\n abortSignal: options.abortSignal,\n fetch: this.config.fetch,\n });\n\n // Track state across chunks\n let finishReason: LanguageModelV2FinishReason = 'other';\n let usage: z.infer<typeof alibabaUsageSchema> | undefined = undefined;\n\n let isFirstChunk = true;\n let activeText = false;\n let activeReasoningId: string | null = null;\n\n // Track tool calls for accumulation across chunks\n const toolCalls: Array<{\n id: string;\n type: 'function';\n function: { name: string; arguments: string };\n hasFinished: boolean;\n }> = [];\n\n return {\n stream: response.pipeThrough(\n new TransformStream<\n ParseResult<z.infer<typeof alibabaChatChunkSchema>>,\n LanguageModelV2StreamPart\n >({\n start(controller) {\n controller.enqueue({ type: 'stream-start', warnings });\n },\n\n transform(chunk, controller) {\n // Emit raw chunk if requested (before anything else)\n if (options.includeRawChunks) {\n controller.enqueue({ type: 'raw', rawValue: chunk.rawValue });\n }\n\n // Handle parse errors\n if (!chunk.success) {\n controller.enqueue({ type: 'error', error: chunk.error });\n return;\n }\n\n const value = chunk.value;\n\n // Emit response metadata on first chunk\n if (isFirstChunk) {\n isFirstChunk = false;\n controller.enqueue({\n type: 'response-metadata',\n ...getResponseMetadata(value),\n });\n }\n\n // Track usage (appears in final chunk)\n if (value.usage != null) {\n usage = value.usage;\n }\n\n // Skip processing if no choices (usage-only chunk)\n if (value.choices.length === 0) {\n return;\n }\n\n const choice = value.choices[0];\n const delta = choice.delta;\n\n // Handle reasoning content streaming (Alibaba thinking mode)\n if (\n delta.reasoning_content != null &&\n delta.reasoning_content.length > 0\n ) {\n if (activeReasoningId == null) {\n // End any active text before starting reasoning\n if (activeText) {\n controller.enqueue({ type: 'text-end', id: '0' });\n activeText = false;\n }\n\n activeReasoningId = generateId();\n controller.enqueue({\n type: 'reasoning-start',\n id: activeReasoningId,\n });\n }\n\n controller.enqueue({\n type: 'reasoning-delta',\n id: activeReasoningId,\n delta: delta.reasoning_content,\n });\n }\n\n // Handle text content streaming\n if (delta.content != null && delta.content.length > 0) {\n // End any active reasoning before starting text\n if (activeReasoningId != null) {\n controller.enqueue({\n type: 'reasoning-end',\n id: activeReasoningId,\n });\n activeReasoningId = null;\n }\n\n if (!activeText) {\n controller.enqueue({ type: 'text-start', id: '0' });\n activeText = true;\n }\n\n controller.enqueue({\n type: 'text-delta',\n id: '0',\n delta: delta.content,\n });\n }\n\n // Handle tool call streaming\n if (delta.tool_calls != null) {\n // End any active reasoning or text before tool calls\n if (activeReasoningId != null) {\n controller.enqueue({\n type: 'reasoning-end',\n id: activeReasoningId,\n });\n activeReasoningId = null;\n }\n if (activeText) {\n controller.enqueue({ type: 'text-end', id: '0' });\n activeText = false;\n }\n\n for (const toolCallDelta of delta.tool_calls) {\n const index = toolCallDelta.index ?? toolCalls.length;\n\n // New tool call - first chunk with id and name\n if (toolCalls[index] == null) {\n if (toolCallDelta.id == null) {\n throw new InvalidResponseDataError({\n data: toolCallDelta,\n message: `Expected 'id' to be a string.`,\n });\n }\n\n if (toolCallDelta.function?.name == null) {\n throw new InvalidResponseDataError({\n data: toolCallDelta,\n message: `Expected 'function.name' to be a string.`,\n });\n }\n\n controller.enqueue({\n type: 'tool-input-start',\n id: toolCallDelta.id,\n toolName: toolCallDelta.function.name,\n });\n\n toolCalls[index] = {\n id: toolCallDelta.id,\n type: 'function',\n function: {\n name: toolCallDelta.function.name,\n arguments: toolCallDelta.function.arguments ?? '',\n },\n hasFinished: false,\n };\n\n const toolCall = toolCalls[index];\n\n // Send initial delta if arguments started\n if (toolCall.function.arguments.length > 0) {\n controller.enqueue({\n type: 'tool-input-delta',\n id: toolCall.id,\n delta: toolCall.function.arguments,\n });\n }\n\n // Check if already complete (some providers send full tool call at once)\n if (isParsableJson(toolCall.function.arguments)) {\n controller.enqueue({\n type: 'tool-input-end',\n id: toolCall.id,\n });\n\n controller.enqueue({\n type: 'tool-call',\n toolCallId: toolCall.id,\n toolName: toolCall.function.name,\n input: toolCall.function.arguments,\n });\n\n toolCall.hasFinished = true;\n }\n\n continue;\n }\n\n // Existing tool call - accumulate arguments\n const toolCall = toolCalls[index];\n\n if (toolCall.hasFinished) {\n continue;\n }\n\n // Append arguments if not null (skip arguments: null chunks)\n if (toolCallDelta.function?.arguments != null) {\n toolCall.function.arguments +=\n toolCallDelta.function.arguments;\n\n controller.enqueue({\n type: 'tool-input-delta',\n id: toolCall.id,\n delta: toolCallDelta.function.arguments,\n });\n }\n\n // Check if tool call is now complete\n if (isParsableJson(toolCall.function.arguments)) {\n controller.enqueue({\n type: 'tool-input-end',\n id: toolCall.id,\n });\n\n controller.enqueue({\n type: 'tool-call',\n toolCallId: toolCall.id,\n toolName: toolCall.function.name,\n input: toolCall.function.arguments,\n });\n\n toolCall.hasFinished = true;\n }\n }\n }\n\n // Track finish reason\n if (choice.finish_reason != null) {\n finishReason = mapOpenAICompatibleFinishReason(\n choice.finish_reason,\n );\n }\n },\n\n flush(controller) {\n if (activeReasoningId != null) {\n controller.enqueue({\n type: 'reasoning-end',\n id: activeReasoningId,\n });\n }\n\n if (activeText) {\n controller.enqueue({ type: 'text-end', id: '0' });\n }\n\n controller.enqueue({\n type: 'finish',\n finishReason,\n usage: convertAlibabaUsage(usage),\n providerMetadata: {\n alibaba: {\n cacheCreationInputTokens:\n usage?.prompt_tokens_details?.cache_creation_input_tokens ??\n null,\n },\n },\n });\n },\n }),\n ),\n request: { body: JSON.stringify(body) },\n response: { headers: responseHeaders },\n };\n }\n}\n\n/**\n * Reference for schemas below:\n * https://www.alibabacloud.com/help/en/model-studio/qwen-api-via-openai-chat-completions\n */\nconst alibabaUsageSchema = z.object({\n prompt_tokens: z.number(),\n completion_tokens: z.number(),\n total_tokens: z.number(),\n prompt_tokens_details: z\n .object({\n cached_tokens: z.number().nullish(),\n cache_creation_input_tokens: z.number().nullish(),\n })\n .nullish(),\n completion_tokens_details: z\n .object({\n reasoning_tokens: z.number().nullish(),\n })\n .nullish(),\n});\n\nconst alibabaChatResponseSchema = z.object({\n id: z.string().nullish(),\n created: z.number().nullish(),\n model: z.string().nullish(),\n choices: z.array(\n z.object({\n message: z.object({\n role: z.literal('assistant').nullish(),\n content: z.string().nullish(),\n reasoning_content: z.string().nullish(), // Alibaba thinking mode\n tool_calls: z\n .array(\n z.object({\n id: z.string(),\n type: z.literal('function'),\n function: z.object({\n name: z.string(),\n arguments: z.string(),\n }),\n }),\n )\n .nullish(),\n }),\n finish_reason: z.string().nullish(),\n index: z.number(),\n }),\n ),\n usage: alibabaUsageSchema.nullish(),\n});\n\nconst alibabaChatChunkSchema = z.object({\n id: z.string().nullish(),\n created: z.number().nullish(),\n model: z.string().nullish(),\n choices: z.array(\n z.object({\n delta: z.object({\n role: z.enum(['assistant']).nullish(),\n content: z.string().nullish(),\n reasoning_content: z.string().nullish(), // Alibaba thinking mode delta\n tool_calls: z\n .array(\n z.object({\n index: z.number().nullish(), // Index for accumulating tool calls\n id: z.string().nullish(),\n type: z.literal('function').nullish(),\n function: z\n .object({\n name: z.string().nullish(),\n arguments: z.string().nullish(),\n })\n .nullish(),\n }),\n )\n .nullish(),\n }),\n finish_reason: z.string().nullish(),\n index: z.number(),\n }),\n ),\n usage: alibabaUsageSchema.nullish(), // Usage only appears in final chunk\n});\n","import { z } from 'zod/v4';\n\n// https://www.alibabacloud.com/help/en/model-studio/models\nexport type AlibabaChatModelId =\n // commercial edition - hybrid-thinking mode (disabled by default)\n | 'qwen3-max'\n | 'qwen3-max-preview'\n | 'qwen-plus'\n | 'qwen-plus-latest'\n | 'qwen-flash'\n | 'qwen-turbo'\n | 'qwen-turbo-latest'\n // open-source edition - hybrid-thinking mode (enabled by default)\n | 'qwen3-235b-a22b'\n | 'qwen3-32b'\n | 'qwen3-30b-a3b'\n | 'qwen3-14b'\n // thinking-only mode\n | 'qwen3-next-80b-a3b-thinking'\n | 'qwen3-235b-a22b-thinking-2507'\n | 'qwen3-30b-a3b-thinking-2507'\n | 'qwq-plus'\n | 'qwq-plus-latest'\n | 'qwq-32b'\n // code models\n | 'qwen-coder'\n | 'qwen3-coder-plus'\n | 'qwen3-coder-flash'\n | (string & {});\n\nexport const alibabaLanguageModelOptions = z.object({\n /**\n * Enable thinking/reasoning mode for supported models.\n * When enabled, the model generates reasoning content before the response.\n *\n * @default false\n */\n enableThinking: z.boolean().optional(),\n\n /**\n * Maximum number of reasoning tokens to generate.\n */\n thinkingBudget: z.number().positive().optional(),\n\n /**\n * Whether to enable parallel function calling during tool use.\n *\n * @default true\n */\n parallelToolCalls: z.boolean().optional(),\n});\n\nexport type AlibabaLanguageModelOptions = z.infer<\n typeof alibabaLanguageModelOptions\n>;\n","import type { LanguageModelV2Usage } from '@ai-sdk/provider';\n\nexport type AlibabaUsage = {\n prompt_tokens?: number | null;\n completion_tokens?: number | null;\n total_tokens?: number | null;\n prompt_tokens_details?: {\n cached_tokens?: number | null;\n cache_creation_input_tokens?: number | null;\n } | null;\n completion_tokens_details?: {\n reasoning_tokens?: number | null;\n } | null;\n};\n\nexport function convertAlibabaUsage(\n usage: AlibabaUsage | undefined | null,\n): LanguageModelV2Usage {\n return {\n inputTokens: usage?.prompt_tokens ?? undefined,\n outputTokens: usage?.completion_tokens ?? undefined,\n totalTokens: usage?.total_tokens ?? undefined,\n reasoningTokens:\n usage?.completion_tokens_details?.reasoning_tokens ?? undefined,\n cachedInputTokens: usage?.prompt_tokens_details?.cached_tokens ?? undefined,\n };\n}\n","import {\n type LanguageModelV2DataContent,\n type LanguageModelV2Prompt,\n UnsupportedFunctionalityError,\n} from '@ai-sdk/provider';\nimport { convertToBase64 } from '@ai-sdk/provider-utils';\nimport type { AlibabaChatPrompt } from './alibaba-chat-prompt';\nimport type { CacheControlValidator } from './get-cache-control';\n\nfunction formatImageUrl({\n data,\n mediaType,\n}: {\n data: LanguageModelV2DataContent;\n mediaType: string;\n}): string {\n return data instanceof URL\n ? data.toString()\n : `data:${mediaType};base64,${convertToBase64(data as Uint8Array)}`;\n}\n\nexport function convertToAlibabaChatMessages({\n prompt,\n cacheControlValidator,\n}: {\n prompt: LanguageModelV2Prompt;\n cacheControlValidator?: CacheControlValidator;\n}): AlibabaChatPrompt {\n const messages: AlibabaChatPrompt = [];\n\n for (const { role, content, ...message } of prompt) {\n switch (role) {\n case 'system': {\n const cacheControl = cacheControlValidator?.getCacheControl(\n message.providerOptions,\n );\n\n // If cache_control is present, convert to array format\n if (cacheControl) {\n messages.push({\n role: 'system',\n content: [\n {\n type: 'text',\n text: content,\n cache_control: cacheControl,\n },\n ],\n });\n } else {\n messages.push({ role: 'system', content });\n }\n break;\n }\n\n case 'user': {\n // Single text part -> use string content\n if (content.length === 1 && content[0].type === 'text') {\n messages.push({\n role: 'user',\n content: content[0].text,\n });\n break;\n }\n\n // Multi-part content\n messages.push({\n role: 'user',\n content: content.map(part => {\n switch (part.type) {\n case 'text': {\n return { type: 'text', text: part.text };\n }\n\n case 'file': {\n if (part.mediaType.startsWith('image/')) {\n const mediaType =\n part.mediaType === 'image/*'\n ? 'image/jpeg'\n : part.mediaType;\n\n return {\n type: 'image_url',\n image_url: {\n url: formatImageUrl({ data: part.data, mediaType }),\n },\n };\n } else {\n throw new UnsupportedFunctionalityError({\n functionality: 'Only image file parts are supported',\n });\n }\n }\n }\n }),\n });\n break;\n }\n\n case 'assistant': {\n let text = '';\n const toolCalls: Array<{\n id: string;\n type: 'function';\n function: { name: string; arguments: string };\n }> = [];\n\n for (const part of content) {\n switch (part.type) {\n case 'text': {\n text += part.text;\n break;\n }\n case 'tool-call': {\n toolCalls.push({\n id: part.toolCallId,\n type: 'function',\n function: {\n name: part.toolName,\n arguments: JSON.stringify(part.input),\n },\n });\n break;\n }\n case 'reasoning': {\n // Reasoning content is handled separately in the response\n // but may appear in assistant messages during multi-turn conversations\n text += part.text;\n break;\n }\n }\n }\n\n messages.push({\n role: 'assistant',\n content: text || null,\n tool_calls: toolCalls.length > 0 ? toolCalls : undefined,\n });\n\n break;\n }\n\n case 'tool': {\n for (const toolResponse of content) {\n const output = toolResponse.output;\n\n let contentValue: string;\n switch (output.type) {\n case 'text':\n case 'error-text':\n contentValue = output.value;\n break;\n case 'content':\n case 'json':\n case 'error-json':\n contentValue = JSON.stringify(output.value);\n break;\n }\n\n messages.push({\n role: 'tool',\n tool_call_id: toolResponse.toolCallId,\n content: contentValue,\n });\n }\n break;\n }\n\n default: {\n const _exhaustiveCheck: never = role;\n throw new Error(`Unsupported role: ${_exhaustiveCheck}`);\n }\n }\n }\n\n return messages;\n}\n","import type {\n LanguageModelV2CallWarning,\n SharedV2ProviderMetadata,\n} from '@ai-sdk/provider';\nimport type { AlibabaCacheControl } from './alibaba-chat-prompt';\n\n// Alibaba allows a maximum of 4 cache breakpoints per request\nconst MAX_CACHE_BREAKPOINTS = 4;\n\nfunction getCacheControl(\n providerMetadata: SharedV2ProviderMetadata | undefined,\n): AlibabaCacheControl | undefined {\n const alibaba = providerMetadata?.alibaba;\n\n const cacheControlValue = alibaba?.cacheControl ?? alibaba?.cache_control;\n\n // Pass through value assuming it is of the correct type.\n // The Alibaba API will validate the value.\n return cacheControlValue as AlibabaCacheControl | undefined;\n}\n\nexport class CacheControlValidator {\n private breakpointCount = 0;\n private warnings: LanguageModelV2CallWarning[] = [];\n\n getCacheControl(\n providerMetadata: SharedV2ProviderMetadata | undefined,\n ): AlibabaCacheControl | undefined {\n const cacheControlValue = getCacheControl(providerMetadata);\n\n if (!cacheControlValue) {\n return undefined;\n }\n\n // Validate cache breakpoint limit\n this.breakpointCount++;\n if (this.breakpointCount > MAX_CACHE_BREAKPOINTS) {\n this.warnings.push({\n type: 'other',\n message: `cacheControl breakpoint limit: Maximum ${MAX_CACHE_BREAKPOINTS} cache breakpoints exceeded (found ${this.breakpointCount}). This breakpoint will be ignored.`,\n });\n return undefined;\n }\n\n return cacheControlValue;\n }\n\n getWarnings(): LanguageModelV2CallWarning[] {\n return this.warnings;\n }\n}\n","import {\n LanguageModelV2CallOptions,\n LanguageModelV2CallWarning,\n UnsupportedFunctionalityError,\n} from '@ai-sdk/provider';\n\nexport function prepareTools({\n tools,\n toolChoice,\n}: {\n tools: LanguageModelV2CallOptions['tools'];\n toolChoice?: LanguageModelV2CallOptions['toolChoice'];\n}): {\n tools:\n | undefined\n | Array<{\n type: 'function';\n function: {\n name: string;\n description: string | undefined;\n parameters: unknown;\n };\n }>;\n toolChoice:\n | { type: 'function'; function: { name: string } }\n | 'auto'\n | 'none'\n | 'required'\n | undefined;\n toolWarnings: LanguageModelV2CallWarning[];\n} {\n // when the tools array is empty, change it to undefined to prevent errors:\n tools = tools?.length ? tools : undefined;\n\n const toolWarnings: LanguageModelV2CallWarning[] = [];\n\n if (tools == null) {\n return { tools: undefined, toolChoice: undefined, toolWarnings };\n }\n\n const openaiCompatTools: Array<{\n type: 'function';\n function: {\n name: string;\n description: string | undefined;\n parameters: unknown;\n };\n }> = [];\n\n for (const tool of tools) {\n if (tool.type === 'provider-defined') {\n toolWarnings.push({ type: 'unsupported-tool', tool });\n } else {\n openaiCompatTools.push({\n type: 'function',\n function: {\n name: tool.name,\n description: tool.description,\n parameters: tool.inputSchema,\n },\n });\n }\n }\n\n if (toolChoice == null) {\n return { tools: openaiCompatTools, toolChoice: undefined, toolWarnings };\n }\n\n const type = toolChoice.type;\n\n switch (type) {\n case 'auto':\n case 'none':\n case 'required':\n return { tools: openaiCompatTools, toolChoice: type, toolWarnings };\n case 'tool':\n return {\n tools: openaiCompatTools,\n toolChoice: {\n type: 'function',\n function: { name: toolChoice.toolName },\n },\n toolWarnings,\n };\n default: {\n const _exhaustiveCheck: never = type;\n throw new UnsupportedFunctionalityError({\n functionality: `tool choice type: ${_exhaustiveCheck}`,\n });\n }\n }\n}\n","declare const __PACKAGE_VERSION__: string;\n\nexport const VERSION = __PACKAGE_VERSION__;\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,OAEK;AACP;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,KAAAA,UAAS;;;ACZlB;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,OAOK;AACP;AAAA,EACE;AAAA,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QAAM,aAAa,MACjB;AAAA,IACE;AAAA,MACE,eAAe,UAAU,WAAW;AAAA,QAClC,QAAQ,QAAQ;AAAA,QAChB,yBAAyB;AAAA,QACzB,aAAa;AAAA,MACf,CAAC,CAAC;AAAA,MACF,GAAG,QAAQ;AAAA,IACb;AAAA,IACA,kBAAkB,OAAO;AAAA,EAC3B;AAEF,QAAM,sBAAsB,CAAC,YAA6B;AAtG5D,QAAAC;AAuGI,eAAI,qBAAqB,SAAS;AAAA,MAChC,UAAU;AAAA,MACV;AAAA,MACA,SAAS;AAAA,MACT,OAAO,QAAQ;AAAA,MACf,eAAcA,MAAA,QAAQ,iBAAR,OAAAA,MAAwB;AAAA,IACxC,CAAC;AAAA;AAEH,QAAM,WAAW,SAAU,SAA6B;AACtD,QAAI,YAAY;AACd,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAEA,WAAO,oBAAoB,OAAO;AAAA,EACpC;AAEA,WAAS,uBAAuB;AAChC,WAAS,gBAAgB;AACzB,WAAS,YAAY;AAErB,WAAS,aAAa,CAAC,YAAoB;AACzC,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,aAAa,CAAC;AAAA,EACjE;AAEA,WAAS,qBAAqB,CAAC,YAAoB;AACjD,UAAM,IAAI,iBAAiB,EAAE,SAAS,WAAW,qBAAqB,CAAC;AAAA,EACzE;AAEA,SAAO;AACT;AAEO,IAAM,UAAU,cAAc;","names":["z","z","alibaba","UnsupportedFunctionalityError","toolCall","z","z","_a"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ai-sdk/alibaba",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"sideEffects": false,
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist/**/*",
|
|
11
|
+
"CHANGELOG.md"
|
|
12
|
+
],
|
|
13
|
+
"exports": {
|
|
14
|
+
"./package.json": "./package.json",
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.mjs",
|
|
18
|
+
"require": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@ai-sdk/openai-compatible": "1.0.33",
|
|
23
|
+
"@ai-sdk/provider-utils": "3.0.21",
|
|
24
|
+
"@ai-sdk/provider": "2.0.1"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "20.17.24",
|
|
28
|
+
"tsup": "^8",
|
|
29
|
+
"typescript": "5.8.3",
|
|
30
|
+
"zod": "3.25.76",
|
|
31
|
+
"@ai-sdk/test-server": "0.0.2",
|
|
32
|
+
"@vercel/ai-tsconfig": "0.0.0"
|
|
33
|
+
},
|
|
34
|
+
"peerDependencies": {
|
|
35
|
+
"zod": "^3.25.76 || ^4.1.8"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=18"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"homepage": "https://ai-sdk.dev/docs",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git+https://github.com/vercel/ai.git"
|
|
47
|
+
},
|
|
48
|
+
"bugs": {
|
|
49
|
+
"url": "https://github.com/vercel/ai/issues"
|
|
50
|
+
},
|
|
51
|
+
"keywords": [
|
|
52
|
+
"ai",
|
|
53
|
+
"alibaba",
|
|
54
|
+
"qwen",
|
|
55
|
+
"dashscope"
|
|
56
|
+
],
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "pnpm clean && tsup --tsconfig tsconfig.build.json",
|
|
59
|
+
"build:watch": "pnpm clean && tsup --watch",
|
|
60
|
+
"clean": "del-cli dist *.tsbuildinfo",
|
|
61
|
+
"lint": "eslint \"./**/*.ts*\"",
|
|
62
|
+
"type-check": "tsc --build",
|
|
63
|
+
"prettier-check": "prettier --check \"./**/*.ts*\"",
|
|
64
|
+
"test": "pnpm test:node && pnpm test:edge",
|
|
65
|
+
"test:update": "pnpm test:node -u",
|
|
66
|
+
"test:watch": "vitest --config vitest.node.config.js",
|
|
67
|
+
"test:edge": "vitest --config vitest.edge.config.js --run",
|
|
68
|
+
"test:node": "vitest --config vitest.node.config.js --run"
|
|
69
|
+
}
|
|
70
|
+
}
|