@ai-sdk/xai 4.0.0-beta.46 → 4.0.0-beta.48
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 +28 -0
- package/dist/index.d.ts +13 -13
- package/dist/index.js +82 -53
- 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/index.ts +4 -4
- package/src/map-xai-finish-reason.ts +1 -1
- package/src/responses/convert-to-xai-responses-input.ts +49 -37
- 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-language-model.ts +7 -7
- package/src/responses/xai-responses-prepare-tools.ts +3 -3
- package/src/xai-chat-language-model.ts +13 -13
- package/src/xai-image-model.ts +4 -4
- package/src/xai-prepare-tools.ts +3 -3
- package/src/xai-provider.ts +10 -10
- package/src/xai-video-model.ts +3 -3
- /package/src/responses/{xai-responses-options.ts → xai-responses-language-model-options.ts} +0 -0
- /package/src/{xai-chat-options.ts → xai-chat-language-model-options.ts} +0 -0
- /package/src/{xai-image-options.ts → xai-image-model-options.ts} +0 -0
- /package/src/{xai-video-options.ts → xai-video-model-options.ts} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# @ai-sdk/xai
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.48
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 04e9009: chore: make provider implementations code patterns more consistent, including renaming certain exported symbols
|
|
8
|
+
|
|
9
|
+
For all externally exported symbols that were renamed, the old names continue to work via deprecated aliases.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies [08d2129]
|
|
14
|
+
- Updated dependencies [04e9009]
|
|
15
|
+
- @ai-sdk/provider-utils@5.0.0-beta.30
|
|
16
|
+
- @ai-sdk/openai-compatible@3.0.0-beta.35
|
|
17
|
+
|
|
18
|
+
## 4.0.0-beta.47
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- 9bd6512: feat(provider): change file part data property to be tagged with a type and remove the image part type
|
|
23
|
+
- 258c093: chore: ensure consistent import handling and avoid import duplicates or cycles
|
|
24
|
+
- Updated dependencies [9bd6512]
|
|
25
|
+
- Updated dependencies [258c093]
|
|
26
|
+
- Updated dependencies [b6783da]
|
|
27
|
+
- @ai-sdk/openai-compatible@3.0.0-beta.34
|
|
28
|
+
- @ai-sdk/provider-utils@5.0.0-beta.29
|
|
29
|
+
- @ai-sdk/provider@4.0.0-beta.14
|
|
30
|
+
|
|
3
31
|
## 4.0.0-beta.46
|
|
4
32
|
|
|
5
33
|
### 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
|
}
|
|
@@ -212,7 +222,7 @@ function mapXaiFinishReason(finishReason) {
|
|
|
212
222
|
}
|
|
213
223
|
}
|
|
214
224
|
|
|
215
|
-
// src/xai-chat-options.ts
|
|
225
|
+
// src/xai-chat-language-model-options.ts
|
|
216
226
|
import { z } from "zod/v4";
|
|
217
227
|
var webSourceSchema = z.object({
|
|
218
228
|
type: z.literal("web"),
|
|
@@ -925,7 +935,7 @@ import {
|
|
|
925
935
|
} from "@ai-sdk/provider-utils";
|
|
926
936
|
import { z as z5 } from "zod/v4";
|
|
927
937
|
|
|
928
|
-
// src/xai-image-options.ts
|
|
938
|
+
// src/xai-image-model-options.ts
|
|
929
939
|
import { z as z4 } from "zod/v4";
|
|
930
940
|
var xaiImageModelOptions = z4.object({
|
|
931
941
|
aspect_ratio: z4.string().optional(),
|
|
@@ -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,27 +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
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
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
|
+
}
|
|
1161
1187
|
}
|
|
1162
1188
|
break;
|
|
1163
1189
|
}
|
|
@@ -1776,7 +1802,7 @@ var xaiResponsesChunkSchema = z6.union([
|
|
|
1776
1802
|
})
|
|
1777
1803
|
]);
|
|
1778
1804
|
|
|
1779
|
-
// src/responses/xai-responses-options.ts
|
|
1805
|
+
// src/responses/xai-responses-language-model-options.ts
|
|
1780
1806
|
import { z as z7 } from "zod/v4";
|
|
1781
1807
|
var xaiLanguageModelResponsesOptions = z7.object({
|
|
1782
1808
|
/**
|
|
@@ -2939,12 +2965,12 @@ var xaiTools = {
|
|
|
2939
2965
|
};
|
|
2940
2966
|
|
|
2941
2967
|
// src/version.ts
|
|
2942
|
-
var VERSION = true ? "4.0.0-beta.
|
|
2968
|
+
var VERSION = true ? "4.0.0-beta.48" : "0.0.0-test";
|
|
2943
2969
|
|
|
2944
2970
|
// src/files/xai-files.ts
|
|
2945
2971
|
import {
|
|
2946
2972
|
combineHeaders as combineHeaders4,
|
|
2947
|
-
|
|
2973
|
+
convertInlineFileDataToUint8Array,
|
|
2948
2974
|
createJsonResponseHandler as createJsonResponseHandler4,
|
|
2949
2975
|
parseProviderOptions as parseProviderOptions4,
|
|
2950
2976
|
postFormDataToApi
|
|
@@ -2968,7 +2994,10 @@ var xaiFilesResponseSchema = lazySchema5(
|
|
|
2968
2994
|
);
|
|
2969
2995
|
|
|
2970
2996
|
// src/files/xai-files-options.ts
|
|
2971
|
-
import {
|
|
2997
|
+
import {
|
|
2998
|
+
lazySchema as lazySchema6,
|
|
2999
|
+
zodSchema as zodSchema6
|
|
3000
|
+
} from "@ai-sdk/provider-utils";
|
|
2972
3001
|
import { z as z16 } from "zod/v4";
|
|
2973
3002
|
var xaiFilesOptionsSchema = lazySchema6(
|
|
2974
3003
|
() => zodSchema6(
|
|
@@ -3000,7 +3029,7 @@ var XaiFiles = class {
|
|
|
3000
3029
|
providerOptions,
|
|
3001
3030
|
schema: xaiFilesOptionsSchema
|
|
3002
3031
|
});
|
|
3003
|
-
const fileBytes =
|
|
3032
|
+
const fileBytes = convertInlineFileDataToUint8Array(data);
|
|
3004
3033
|
const blob = new Blob([fileBytes], {
|
|
3005
3034
|
type: mediaType
|
|
3006
3035
|
});
|
|
@@ -3054,7 +3083,7 @@ import {
|
|
|
3054
3083
|
} from "@ai-sdk/provider-utils";
|
|
3055
3084
|
import { z as z18 } from "zod/v4";
|
|
3056
3085
|
|
|
3057
|
-
// src/xai-video-options.ts
|
|
3086
|
+
// src/xai-video-model-options.ts
|
|
3058
3087
|
import { lazySchema as lazySchema7, zodSchema as zodSchema7 } from "@ai-sdk/provider-utils";
|
|
3059
3088
|
import { z as z17 } from "zod/v4";
|
|
3060
3089
|
var nonEmptyStringSchema = z17.string().min(1);
|