@ai-sdk/alibaba 1.0.55 → 1.0.57

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.
@@ -19,6 +19,7 @@ import {
19
19
  createEventSourceResponseHandler,
20
20
  createJsonResponseHandler,
21
21
  generateId,
22
+ injectJsonInstructionIntoMessages,
22
23
  parseProviderOptions,
23
24
  postJsonToApi,
24
25
  type ParseResult,
@@ -33,6 +34,7 @@ import { alibabaFailedResponseHandler } from './alibaba-error';
33
34
  import { convertAlibabaUsage } from './convert-alibaba-usage';
34
35
  import { convertToAlibabaChatMessages } from './convert-to-alibaba-chat-messages';
35
36
  import { CacheControlValidator } from './get-cache-control';
37
+ import { supportsJsonSchemaOutput } from './supports-json-schema-output';
36
38
  import { supportsPreservedThinking } from './supports-preserved-thinking';
37
39
 
38
40
  /**
@@ -104,6 +106,30 @@ export class AlibabaLanguageModel implements LanguageModelV3 {
104
106
  alibabaOptions?.preserveThinking ??
105
107
  (supportsPreservedThinking(this.modelId) ? true : undefined);
106
108
 
109
+ const useJsonSchema =
110
+ responseFormat?.type === 'json' &&
111
+ responseFormat.schema != null &&
112
+ supportsJsonSchemaOutput(this.modelId);
113
+
114
+ const useJsonObject = responseFormat?.type === 'json' && !useJsonSchema;
115
+
116
+ if (useJsonObject && responseFormat.schema != null) {
117
+ warnings.push({
118
+ type: 'compatibility',
119
+ feature: 'responseFormat JSON schema',
120
+ details:
121
+ `Alibaba does not support JSON Schema output for model ${this.modelId}. ` +
122
+ 'JSON Object mode is used instead. The schema was injected into the system message and will only be validated locally.',
123
+ });
124
+ }
125
+
126
+ const resolvedPrompt = useJsonObject
127
+ ? injectJsonInstructionIntoMessages({
128
+ messages: prompt,
129
+ schema: responseFormat.schema,
130
+ })
131
+ : prompt;
132
+
107
133
  // Build base request arguments
108
134
  const baseArgs = {
109
135
  model: this.modelId,
@@ -116,7 +142,7 @@ export class AlibabaLanguageModel implements LanguageModelV3 {
116
142
  seed,
117
143
  response_format:
118
144
  responseFormat?.type === 'json'
119
- ? responseFormat.schema != null
145
+ ? useJsonSchema
120
146
  ? {
121
147
  type: 'json_schema',
122
148
  json_schema: {
@@ -142,7 +168,7 @@ export class AlibabaLanguageModel implements LanguageModelV3 {
142
168
 
143
169
  // Convert messages with cache control support
144
170
  messages: convertToAlibabaChatMessages({
145
- prompt,
171
+ prompt: resolvedPrompt,
146
172
  cacheControlValidator,
147
173
  preserveThinking: preserveThinking ?? false,
148
174
  }),
@@ -0,0 +1,14 @@
1
+ // https://www.alibabacloud.com/help/en/model-studio/qwen-structured-output#supported-models
2
+ const JSON_SCHEMA_MODEL_PREFIXES = [
3
+ 'qwen3.7-plus',
4
+ 'qwen3.7-flash',
5
+ 'qwen3.7-max',
6
+ 'qwen3.8-max',
7
+ 'qwen3.8-flash',
8
+ ];
9
+
10
+ export function supportsJsonSchemaOutput(modelId: string): boolean {
11
+ return JSON_SCHEMA_MODEL_PREFIXES.some(
12
+ prefix => modelId === prefix || modelId.startsWith(`${prefix}-`),
13
+ );
14
+ }