@ai-sdk/xai 4.0.0-beta.45 → 4.0.0-beta.47
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 +25 -0
- package/dist/index.d.ts +13 -13
- package/dist/index.js +84 -45
- package/dist/index.js.map +1 -1
- package/docs/01-xai.mdx +1 -1
- package/package.json +5 -5
- package/src/convert-to-xai-chat-messages.ts +40 -35
- package/src/convert-xai-chat-usage.ts +2 -2
- package/src/files/xai-files-options.ts +5 -1
- package/src/files/xai-files.ts +8 -7
- package/src/map-xai-finish-reason.ts +1 -1
- package/src/responses/convert-to-xai-responses-input.ts +49 -27
- package/src/responses/convert-xai-responses-usage.ts +2 -2
- package/src/responses/map-xai-responses-finish-reason.ts +1 -1
- package/src/responses/xai-responses-api.ts +2 -1
- package/src/responses/xai-responses-language-model.ts +11 -6
- package/src/responses/xai-responses-prepare-tools.ts +3 -3
- package/src/xai-chat-language-model.ts +12 -12
- package/src/xai-image-model.ts +3 -3
- package/src/xai-prepare-tools.ts +3 -3
- package/src/xai-provider.ts +10 -10
- package/src/xai-video-model.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,30 @@
|
|
|
1
1
|
# @ai-sdk/xai
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.47
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 9bd6512: feat(provider): change file part data property to be tagged with a type and remove the image part type
|
|
8
|
+
- 258c093: chore: ensure consistent import handling and avoid import duplicates or cycles
|
|
9
|
+
- Updated dependencies [9bd6512]
|
|
10
|
+
- Updated dependencies [258c093]
|
|
11
|
+
- Updated dependencies [b6783da]
|
|
12
|
+
- @ai-sdk/openai-compatible@3.0.0-beta.34
|
|
13
|
+
- @ai-sdk/provider-utils@5.0.0-beta.29
|
|
14
|
+
- @ai-sdk/provider@4.0.0-beta.14
|
|
15
|
+
|
|
16
|
+
## 4.0.0-beta.46
|
|
17
|
+
|
|
18
|
+
### Patch Changes
|
|
19
|
+
|
|
20
|
+
- 78b6433: feat(provider/xai): support non-image file parts (PDF, text, CSV) in the Responses API via `input_file` + `file_url`
|
|
21
|
+
|
|
22
|
+
The xAI Responses API accepts `{ type: 'input_file', file_url }` for non-image documents (see https://docs.x.ai/docs/guides/chat-with-files), but the AI SDK xAI Responses provider previously threw `UnsupportedFunctionalityError` for any file part whose `mediaType` did not start with `image/`.
|
|
23
|
+
|
|
24
|
+
When a file part is passed with `data: URL` and a non-image media type, the provider now emits `{ type: 'input_file', file_url }`. `application/pdf` and `text/*` are also added to `supportedUrls` so the SDK does not download them to bytes before reaching the converter.
|
|
25
|
+
|
|
26
|
+
Inline-byte (base64) inputs for non-image media types continue to throw, since xAI's Responses API requires either a public URL or a pre-uploaded `file_id` for non-image documents.
|
|
27
|
+
|
|
3
28
|
## 4.0.0-beta.45
|
|
4
29
|
|
|
5
30
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -186,7 +186,7 @@ declare const codeExecutionToolFactory: _ai_sdk_provider_utils.ProviderExecutedT
|
|
|
186
186
|
output: string;
|
|
187
187
|
error?: string | undefined;
|
|
188
188
|
}, object, {}>;
|
|
189
|
-
declare const codeExecution: (args?: Parameters<typeof codeExecutionToolFactory>[0]) => _ai_sdk_provider_utils.
|
|
189
|
+
declare const codeExecution: (args?: Parameters<typeof codeExecutionToolFactory>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<Record<string, never>, {
|
|
190
190
|
output: string;
|
|
191
191
|
error?: string | undefined;
|
|
192
192
|
}, {}>;
|
|
@@ -203,7 +203,7 @@ declare const mcpServerToolFactory: _ai_sdk_provider_utils.ProviderExecutedToolF
|
|
|
203
203
|
headers?: Record<string, string>;
|
|
204
204
|
authorization?: string;
|
|
205
205
|
}, {}>;
|
|
206
|
-
declare const mcpServer: (args: Parameters<typeof mcpServerToolFactory>[0]) => _ai_sdk_provider_utils.
|
|
206
|
+
declare const mcpServer: (args: Parameters<typeof mcpServerToolFactory>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{}, {
|
|
207
207
|
name: string;
|
|
208
208
|
arguments: string;
|
|
209
209
|
result: unknown;
|
|
@@ -213,7 +213,7 @@ declare const viewImageToolFactory: _ai_sdk_provider_utils.ProviderExecutedToolF
|
|
|
213
213
|
description: string;
|
|
214
214
|
objects?: string[] | undefined;
|
|
215
215
|
}, object, {}>;
|
|
216
|
-
declare const viewImage: (args?: Parameters<typeof viewImageToolFactory>[0]) => _ai_sdk_provider_utils.
|
|
216
|
+
declare const viewImage: (args?: Parameters<typeof viewImageToolFactory>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<Record<string, never>, {
|
|
217
217
|
description: string;
|
|
218
218
|
objects?: string[] | undefined;
|
|
219
219
|
}, {}>;
|
|
@@ -223,7 +223,7 @@ declare const viewXVideoToolFactory: _ai_sdk_provider_utils.ProviderExecutedTool
|
|
|
223
223
|
transcript?: string | undefined;
|
|
224
224
|
duration?: number | undefined;
|
|
225
225
|
}, object, {}>;
|
|
226
|
-
declare const viewXVideo: (args?: Parameters<typeof viewXVideoToolFactory>[0]) => _ai_sdk_provider_utils.
|
|
226
|
+
declare const viewXVideo: (args?: Parameters<typeof viewXVideoToolFactory>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<Record<string, never>, {
|
|
227
227
|
description: string;
|
|
228
228
|
transcript?: string | undefined;
|
|
229
229
|
duration?: number | undefined;
|
|
@@ -241,7 +241,7 @@ declare const webSearchToolFactory: _ai_sdk_provider_utils.ProviderExecutedToolF
|
|
|
241
241
|
excludedDomains?: string[];
|
|
242
242
|
enableImageUnderstanding?: boolean;
|
|
243
243
|
}, {}>;
|
|
244
|
-
declare const webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) => _ai_sdk_provider_utils.
|
|
244
|
+
declare const webSearch: (args?: Parameters<typeof webSearchToolFactory>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{}, {
|
|
245
245
|
query: string;
|
|
246
246
|
sources: Array<{
|
|
247
247
|
title: string;
|
|
@@ -266,7 +266,7 @@ declare const xSearchToolFactory: _ai_sdk_provider_utils.ProviderExecutedToolFac
|
|
|
266
266
|
enableImageUnderstanding?: boolean;
|
|
267
267
|
enableVideoUnderstanding?: boolean;
|
|
268
268
|
}, {}>;
|
|
269
|
-
declare const xSearch: (args?: Parameters<typeof xSearchToolFactory>[0]) => _ai_sdk_provider_utils.
|
|
269
|
+
declare const xSearch: (args?: Parameters<typeof xSearchToolFactory>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{}, {
|
|
270
270
|
query: string;
|
|
271
271
|
posts: Array<{
|
|
272
272
|
author: string;
|
|
@@ -280,7 +280,7 @@ declare const xaiTools: {
|
|
|
280
280
|
codeExecution: (args?: Parameters<_ai_sdk_provider_utils.ProviderExecutedToolFactory<Record<string, never>, {
|
|
281
281
|
output: string;
|
|
282
282
|
error?: string | undefined;
|
|
283
|
-
}, object, {}>>[0]) => _ai_sdk_provider_utils.
|
|
283
|
+
}, object, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<Record<string, never>, {
|
|
284
284
|
output: string;
|
|
285
285
|
error?: string | undefined;
|
|
286
286
|
}, {}>;
|
|
@@ -295,7 +295,7 @@ declare const xaiTools: {
|
|
|
295
295
|
}, {
|
|
296
296
|
vectorStoreIds: string[];
|
|
297
297
|
maxNumResults?: number;
|
|
298
|
-
}, {}>>[0]) => _ai_sdk_provider_utils.
|
|
298
|
+
}, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{}, {
|
|
299
299
|
queries: string[];
|
|
300
300
|
results: null | {
|
|
301
301
|
fileId: string;
|
|
@@ -315,7 +315,7 @@ declare const xaiTools: {
|
|
|
315
315
|
allowedTools?: string[];
|
|
316
316
|
headers?: Record<string, string>;
|
|
317
317
|
authorization?: string;
|
|
318
|
-
}, {}>>[0]) => _ai_sdk_provider_utils.
|
|
318
|
+
}, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{}, {
|
|
319
319
|
name: string;
|
|
320
320
|
arguments: string;
|
|
321
321
|
result: unknown;
|
|
@@ -323,7 +323,7 @@ declare const xaiTools: {
|
|
|
323
323
|
viewImage: (args?: Parameters<_ai_sdk_provider_utils.ProviderExecutedToolFactory<Record<string, never>, {
|
|
324
324
|
description: string;
|
|
325
325
|
objects?: string[] | undefined;
|
|
326
|
-
}, object, {}>>[0]) => _ai_sdk_provider_utils.
|
|
326
|
+
}, object, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<Record<string, never>, {
|
|
327
327
|
description: string;
|
|
328
328
|
objects?: string[] | undefined;
|
|
329
329
|
}, {}>;
|
|
@@ -331,7 +331,7 @@ declare const xaiTools: {
|
|
|
331
331
|
description: string;
|
|
332
332
|
transcript?: string | undefined;
|
|
333
333
|
duration?: number | undefined;
|
|
334
|
-
}, object, {}>>[0]) => _ai_sdk_provider_utils.
|
|
334
|
+
}, object, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<Record<string, never>, {
|
|
335
335
|
description: string;
|
|
336
336
|
transcript?: string | undefined;
|
|
337
337
|
duration?: number | undefined;
|
|
@@ -347,7 +347,7 @@ declare const xaiTools: {
|
|
|
347
347
|
allowedDomains?: string[];
|
|
348
348
|
excludedDomains?: string[];
|
|
349
349
|
enableImageUnderstanding?: boolean;
|
|
350
|
-
}, {}>>[0]) => _ai_sdk_provider_utils.
|
|
350
|
+
}, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{}, {
|
|
351
351
|
query: string;
|
|
352
352
|
sources: Array<{
|
|
353
353
|
title: string;
|
|
@@ -370,7 +370,7 @@ declare const xaiTools: {
|
|
|
370
370
|
toDate?: string;
|
|
371
371
|
enableImageUnderstanding?: boolean;
|
|
372
372
|
enableVideoUnderstanding?: boolean;
|
|
373
|
-
}, {}>>[0]) => _ai_sdk_provider_utils.
|
|
373
|
+
}, {}>>[0]) => _ai_sdk_provider_utils.ProviderExecutedTool<{}, {
|
|
374
374
|
query: string;
|
|
375
375
|
posts: Array<{
|
|
376
376
|
author: string;
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,8 @@ import {
|
|
|
35
35
|
} from "@ai-sdk/provider";
|
|
36
36
|
import {
|
|
37
37
|
convertToBase64,
|
|
38
|
-
|
|
38
|
+
getTopLevelMediaType,
|
|
39
|
+
resolveFullMediaType,
|
|
39
40
|
resolveProviderReference
|
|
40
41
|
} from "@ai-sdk/provider-utils";
|
|
41
42
|
function convertToXaiChatMessages(prompt) {
|
|
@@ -61,29 +62,38 @@ function convertToXaiChatMessages(prompt) {
|
|
|
61
62
|
return { type: "text", text: part.text };
|
|
62
63
|
}
|
|
63
64
|
case "file": {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
65
|
+
switch (part.data.type) {
|
|
66
|
+
case "reference": {
|
|
67
|
+
return {
|
|
68
|
+
type: "file",
|
|
69
|
+
file: {
|
|
70
|
+
file_id: resolveProviderReference({
|
|
71
|
+
reference: part.data.reference,
|
|
72
|
+
provider: "xai"
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
case "text": {
|
|
78
|
+
throw new UnsupportedFunctionalityError({
|
|
79
|
+
functionality: "text file parts"
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
case "url":
|
|
83
|
+
case "data": {
|
|
84
|
+
if (getTopLevelMediaType(part.mediaType) === "image") {
|
|
85
|
+
return {
|
|
86
|
+
type: "image_url",
|
|
87
|
+
image_url: {
|
|
88
|
+
url: part.data.type === "url" ? part.data.url.toString() : `data:${resolveFullMediaType({ part })};base64,${convertToBase64(part.data.data)}`
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
} else {
|
|
92
|
+
throw new UnsupportedFunctionalityError({
|
|
93
|
+
functionality: `file part media type ${part.mediaType}`
|
|
94
|
+
});
|
|
81
95
|
}
|
|
82
|
-
}
|
|
83
|
-
} else {
|
|
84
|
-
throw new UnsupportedFunctionalityError({
|
|
85
|
-
functionality: `file part media type ${part.mediaType}`
|
|
86
|
-
});
|
|
96
|
+
}
|
|
87
97
|
}
|
|
88
98
|
}
|
|
89
99
|
}
|
|
@@ -1110,7 +1120,8 @@ import {
|
|
|
1110
1120
|
} from "@ai-sdk/provider";
|
|
1111
1121
|
import {
|
|
1112
1122
|
convertToBase64 as convertToBase642,
|
|
1113
|
-
|
|
1123
|
+
getTopLevelMediaType as getTopLevelMediaType2,
|
|
1124
|
+
resolveFullMediaType as resolveFullMediaType2,
|
|
1114
1125
|
resolveProviderReference as resolveProviderReference2
|
|
1115
1126
|
} from "@ai-sdk/provider-utils";
|
|
1116
1127
|
async function convertToXaiResponsesInput({
|
|
@@ -1137,22 +1148,42 @@ async function convertToXaiResponsesInput({
|
|
|
1137
1148
|
break;
|
|
1138
1149
|
}
|
|
1139
1150
|
case "file": {
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
}
|
|
1151
|
+
switch (block.data.type) {
|
|
1152
|
+
case "reference": {
|
|
1153
|
+
contentParts.push({
|
|
1154
|
+
type: "input_file",
|
|
1155
|
+
file_id: resolveProviderReference2({
|
|
1156
|
+
reference: block.data.reference,
|
|
1157
|
+
provider: "xai"
|
|
1158
|
+
})
|
|
1159
|
+
});
|
|
1160
|
+
break;
|
|
1161
|
+
}
|
|
1162
|
+
case "text": {
|
|
1163
|
+
throw new UnsupportedFunctionalityError3({
|
|
1164
|
+
functionality: "text file parts"
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
case "url":
|
|
1168
|
+
case "data": {
|
|
1169
|
+
if (getTopLevelMediaType2(block.mediaType) === "image") {
|
|
1170
|
+
const imageUrl = block.data.type === "url" ? block.data.url.toString() : `data:${resolveFullMediaType2({ part: block })};base64,${convertToBase642(block.data.data)}`;
|
|
1171
|
+
contentParts.push({
|
|
1172
|
+
type: "input_image",
|
|
1173
|
+
image_url: imageUrl
|
|
1174
|
+
});
|
|
1175
|
+
} else if (block.data.type === "url") {
|
|
1176
|
+
contentParts.push({
|
|
1177
|
+
type: "input_file",
|
|
1178
|
+
file_url: block.data.url.toString()
|
|
1179
|
+
});
|
|
1180
|
+
} else {
|
|
1181
|
+
throw new UnsupportedFunctionalityError3({
|
|
1182
|
+
functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`
|
|
1183
|
+
});
|
|
1184
|
+
}
|
|
1185
|
+
break;
|
|
1186
|
+
}
|
|
1156
1187
|
}
|
|
1157
1188
|
break;
|
|
1158
1189
|
}
|
|
@@ -2111,7 +2142,12 @@ var XaiResponsesLanguageModel = class _XaiResponsesLanguageModel {
|
|
|
2111
2142
|
constructor(modelId, config) {
|
|
2112
2143
|
this.specificationVersion = "v4";
|
|
2113
2144
|
this.supportedUrls = {
|
|
2114
|
-
"image/*": [/^https?:\/\/.*$/]
|
|
2145
|
+
"image/*": [/^https?:\/\/.*$/],
|
|
2146
|
+
// xAI's Responses API accepts non-image documents (PDF, plain text, CSV, etc.) as
|
|
2147
|
+
// `{ type: 'input_file', file_url }`. Keeping these URLs intact here lets them pass
|
|
2148
|
+
// through to the converter instead of being downloaded to bytes by the SDK.
|
|
2149
|
+
"application/pdf": [/^https?:\/\/.*$/],
|
|
2150
|
+
"text/*": [/^https?:\/\/.*$/]
|
|
2115
2151
|
};
|
|
2116
2152
|
this.modelId = modelId;
|
|
2117
2153
|
this.config = config;
|
|
@@ -2929,12 +2965,12 @@ var xaiTools = {
|
|
|
2929
2965
|
};
|
|
2930
2966
|
|
|
2931
2967
|
// src/version.ts
|
|
2932
|
-
var VERSION = true ? "4.0.0-beta.
|
|
2968
|
+
var VERSION = true ? "4.0.0-beta.47" : "0.0.0-test";
|
|
2933
2969
|
|
|
2934
2970
|
// src/files/xai-files.ts
|
|
2935
2971
|
import {
|
|
2936
2972
|
combineHeaders as combineHeaders4,
|
|
2937
|
-
|
|
2973
|
+
convertInlineFileDataToUint8Array,
|
|
2938
2974
|
createJsonResponseHandler as createJsonResponseHandler4,
|
|
2939
2975
|
parseProviderOptions as parseProviderOptions4,
|
|
2940
2976
|
postFormDataToApi
|
|
@@ -2958,7 +2994,10 @@ var xaiFilesResponseSchema = lazySchema5(
|
|
|
2958
2994
|
);
|
|
2959
2995
|
|
|
2960
2996
|
// src/files/xai-files-options.ts
|
|
2961
|
-
import {
|
|
2997
|
+
import {
|
|
2998
|
+
lazySchema as lazySchema6,
|
|
2999
|
+
zodSchema as zodSchema6
|
|
3000
|
+
} from "@ai-sdk/provider-utils";
|
|
2962
3001
|
import { z as z16 } from "zod/v4";
|
|
2963
3002
|
var xaiFilesOptionsSchema = lazySchema6(
|
|
2964
3003
|
() => zodSchema6(
|
|
@@ -2990,7 +3029,7 @@ var XaiFiles = class {
|
|
|
2990
3029
|
providerOptions,
|
|
2991
3030
|
schema: xaiFilesOptionsSchema
|
|
2992
3031
|
});
|
|
2993
|
-
const fileBytes =
|
|
3032
|
+
const fileBytes = convertInlineFileDataToUint8Array(data);
|
|
2994
3033
|
const blob = new Blob([fileBytes], {
|
|
2995
3034
|
type: mediaType
|
|
2996
3035
|
});
|