@ai-sdk/xai 4.0.0-beta.46 → 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 CHANGED
@@ -1,5 +1,18 @@
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
+
3
16
  ## 4.0.0-beta.46
4
17
 
5
18
  ### 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.Tool<Record<string, never>, {
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.Tool<{}, {
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.Tool<Record<string, never>, {
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.Tool<Record<string, never>, {
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.Tool<{}, {
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.Tool<{}, {
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.Tool<Record<string, never>, {
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.Tool<{}, {
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.Tool<{}, {
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.Tool<Record<string, never>, {
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.Tool<Record<string, never>, {
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.Tool<{}, {
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.Tool<{}, {
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
- isProviderReference,
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
- if (isProviderReference(part.data)) {
65
- return {
66
- type: "file",
67
- file: {
68
- file_id: resolveProviderReference({
69
- reference: part.data,
70
- provider: "xai"
71
- })
72
- }
73
- };
74
- }
75
- if (part.mediaType.startsWith("image/")) {
76
- const mediaType = part.mediaType === "image/*" ? "image/jpeg" : part.mediaType;
77
- return {
78
- type: "image_url",
79
- image_url: {
80
- url: part.data instanceof URL ? part.data.toString() : `data:${mediaType};base64,${convertToBase64(part.data)}`
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
- isProviderReference as isProviderReference2,
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
- if (isProviderReference2(block.data)) {
1141
- contentParts.push({
1142
- type: "input_file",
1143
- file_id: resolveProviderReference2({
1144
- reference: block.data,
1145
- provider: "xai"
1146
- })
1147
- });
1148
- } else if (block.mediaType.startsWith("image/")) {
1149
- const mediaType = block.mediaType === "image/*" ? "image/jpeg" : block.mediaType;
1150
- const imageUrl = block.data instanceof URL ? block.data.toString() : `data:${mediaType};base64,${convertToBase642(block.data)}`;
1151
- contentParts.push({ type: "input_image", image_url: imageUrl });
1152
- } else if (block.data instanceof URL) {
1153
- contentParts.push({
1154
- type: "input_file",
1155
- file_url: block.data.toString()
1156
- });
1157
- } else {
1158
- throw new UnsupportedFunctionalityError3({
1159
- functionality: `file part media type ${block.mediaType} as inline data (xAI Responses requires a URL or a Files API reference for non-image files)`
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
  }
@@ -2939,12 +2965,12 @@ var xaiTools = {
2939
2965
  };
2940
2966
 
2941
2967
  // src/version.ts
2942
- var VERSION = true ? "4.0.0-beta.46" : "0.0.0-test";
2968
+ var VERSION = true ? "4.0.0-beta.47" : "0.0.0-test";
2943
2969
 
2944
2970
  // src/files/xai-files.ts
2945
2971
  import {
2946
2972
  combineHeaders as combineHeaders4,
2947
- convertBase64ToUint8Array,
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 { lazySchema as lazySchema6, zodSchema as zodSchema6 } from "@ai-sdk/provider-utils";
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 = data instanceof Uint8Array ? data : convertBase64ToUint8Array(data);
3032
+ const fileBytes = convertInlineFileDataToUint8Array(data);
3004
3033
  const blob = new Blob([fileBytes], {
3005
3034
  type: mediaType
3006
3035
  });