@ai-sdk/xai 4.0.15 → 4.0.16
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/xai",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ai-sdk/openai-compatible": "3.0.
|
|
32
|
+
"@ai-sdk/openai-compatible": "3.0.12",
|
|
33
33
|
"@ai-sdk/provider": "4.0.3",
|
|
34
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
34
|
+
"@ai-sdk/provider-utils": "5.0.11"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "22.19.19",
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
} from '@ai-sdk/provider-utils';
|
|
13
13
|
import { xaiFilePartProviderOptions } from '../xai-file-part-options';
|
|
14
14
|
import type {
|
|
15
|
+
XaiResponsesFunctionCallOutput,
|
|
15
16
|
XaiResponsesInput,
|
|
16
17
|
XaiResponsesUserMessageContentPart,
|
|
17
18
|
} from './xai-responses-api';
|
|
@@ -241,7 +242,7 @@ export async function convertToXaiResponsesInput({
|
|
|
241
242
|
}
|
|
242
243
|
const output = part.output;
|
|
243
244
|
|
|
244
|
-
let outputValue:
|
|
245
|
+
let outputValue: XaiResponsesFunctionCallOutput['output'];
|
|
245
246
|
switch (output.type) {
|
|
246
247
|
case 'text':
|
|
247
248
|
case 'error-text':
|
|
@@ -255,14 +256,39 @@ export async function convertToXaiResponsesInput({
|
|
|
255
256
|
outputValue = JSON.stringify(output.value);
|
|
256
257
|
break;
|
|
257
258
|
case 'content':
|
|
258
|
-
outputValue =
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
259
|
+
outputValue = [];
|
|
260
|
+
for (const item of output.value) {
|
|
261
|
+
switch (item.type) {
|
|
262
|
+
case 'text': {
|
|
263
|
+
outputValue.push({
|
|
264
|
+
type: 'input_text',
|
|
265
|
+
text: item.text,
|
|
266
|
+
});
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
case 'file': {
|
|
270
|
+
if (
|
|
271
|
+
getTopLevelMediaType(item.mediaType) === 'image' &&
|
|
272
|
+
(item.data.type === 'data' || item.data.type === 'url')
|
|
273
|
+
) {
|
|
274
|
+
outputValue.push({
|
|
275
|
+
type: 'input_image',
|
|
276
|
+
image_url:
|
|
277
|
+
item.data.type === 'url'
|
|
278
|
+
? item.data.url.toString()
|
|
279
|
+
: `data:${resolveFullMediaType({ part: item })};base64,${convertToBase64(item.data.data)}`,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
case 'custom': {
|
|
285
|
+
break;
|
|
262
286
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
287
|
+
default: {
|
|
288
|
+
const _exhaustiveCheck: never = item;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
266
292
|
break;
|
|
267
293
|
default: {
|
|
268
294
|
const _exhaustiveCheck: never = output;
|
|
@@ -48,7 +48,18 @@ export type XaiResponsesAssistantMessage = {
|
|
|
48
48
|
export type XaiResponsesFunctionCallOutput = {
|
|
49
49
|
type: 'function_call_output';
|
|
50
50
|
call_id: string;
|
|
51
|
-
output:
|
|
51
|
+
output:
|
|
52
|
+
| string
|
|
53
|
+
| Array<
|
|
54
|
+
| {
|
|
55
|
+
type: 'input_text';
|
|
56
|
+
text: string;
|
|
57
|
+
}
|
|
58
|
+
| {
|
|
59
|
+
type: 'input_image';
|
|
60
|
+
image_url: string;
|
|
61
|
+
}
|
|
62
|
+
>;
|
|
52
63
|
};
|
|
53
64
|
|
|
54
65
|
export type XaiResponsesReasoning = {
|
package/src/xai-video-model.ts
CHANGED
|
@@ -5,15 +5,18 @@ import {
|
|
|
5
5
|
type SharedV4Warning,
|
|
6
6
|
} from '@ai-sdk/provider';
|
|
7
7
|
import {
|
|
8
|
+
cancelResponseBody,
|
|
8
9
|
combineHeaders,
|
|
9
10
|
convertUint8ArrayToBase64,
|
|
10
11
|
createJsonResponseHandler,
|
|
11
12
|
delay,
|
|
13
|
+
extractResponseHeaders,
|
|
12
14
|
getFromApi,
|
|
13
15
|
getTopLevelMediaType,
|
|
14
16
|
parseProviderOptions,
|
|
15
17
|
postJsonToApi,
|
|
16
18
|
type FetchFunction,
|
|
19
|
+
type ResponseHandler,
|
|
17
20
|
} from '@ai-sdk/provider-utils';
|
|
18
21
|
import { z } from 'zod/v4';
|
|
19
22
|
import { xaiFailedResponseHandler } from './xai-error';
|
|
@@ -435,9 +438,7 @@ export class XaiVideoModel implements Experimental_VideoModelV4 {
|
|
|
435
438
|
url: `${baseURL}/videos/${requestId}`,
|
|
436
439
|
validateUrl: false,
|
|
437
440
|
headers: combineHeaders(this.config.headers(), options.headers),
|
|
438
|
-
successfulResponseHandler:
|
|
439
|
-
xaiVideoStatusResponseSchema,
|
|
440
|
-
),
|
|
441
|
+
successfulResponseHandler: xaiVideoStatusResponseHandler,
|
|
441
442
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
442
443
|
abortSignal: options.abortSignal,
|
|
443
444
|
fetch: this.config.fetch,
|
|
@@ -543,3 +544,23 @@ const xaiVideoStatusResponseSchema = z.object({
|
|
|
543
544
|
})
|
|
544
545
|
.nullish(),
|
|
545
546
|
});
|
|
547
|
+
|
|
548
|
+
const xaiVideoStatusJsonResponseHandler = createJsonResponseHandler(
|
|
549
|
+
xaiVideoStatusResponseSchema,
|
|
550
|
+
);
|
|
551
|
+
|
|
552
|
+
const xaiVideoStatusResponseHandler: ResponseHandler<
|
|
553
|
+
z.infer<typeof xaiVideoStatusResponseSchema>
|
|
554
|
+
> = async options => {
|
|
555
|
+
if (options.response.status === 202) {
|
|
556
|
+
const responseHeaders = extractResponseHeaders(options.response);
|
|
557
|
+
await cancelResponseBody(options.response);
|
|
558
|
+
|
|
559
|
+
return {
|
|
560
|
+
responseHeaders,
|
|
561
|
+
value: { status: 'pending' },
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
return xaiVideoStatusJsonResponseHandler(options);
|
|
566
|
+
};
|