@ai-sdk/xai 3.0.109 → 3.0.111
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 +15 -0
- package/dist/index.js +51 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/responses/convert-to-xai-responses-input.ts +37 -8
- package/src/responses/xai-responses-api.ts +12 -1
- package/src/xai-video-model.ts +24 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/xai",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.111",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ai-sdk/openai-compatible": "2.0.
|
|
33
|
-
"@ai-sdk/provider
|
|
34
|
-
"@ai-sdk/provider": "
|
|
32
|
+
"@ai-sdk/openai-compatible": "2.0.62",
|
|
33
|
+
"@ai-sdk/provider": "3.0.14",
|
|
34
|
+
"@ai-sdk/provider-utils": "4.0.40"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "20.17.24",
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
import { convertToBase64, parseProviderOptions } from '@ai-sdk/provider-utils';
|
|
7
7
|
import { xaiFilePartProviderOptions } from '../xai-file-part-options';
|
|
8
8
|
import type {
|
|
9
|
+
XaiResponsesFunctionCallOutput,
|
|
9
10
|
XaiResponsesInput,
|
|
10
11
|
XaiResponsesUserMessageContentPart,
|
|
11
12
|
} from './xai-responses-api';
|
|
@@ -216,7 +217,7 @@ export async function convertToXaiResponsesInput({
|
|
|
216
217
|
}
|
|
217
218
|
const output = part.output;
|
|
218
219
|
|
|
219
|
-
let outputValue:
|
|
220
|
+
let outputValue: XaiResponsesFunctionCallOutput['output'];
|
|
220
221
|
switch (output.type) {
|
|
221
222
|
case 'text':
|
|
222
223
|
case 'error-text':
|
|
@@ -230,14 +231,42 @@ export async function convertToXaiResponsesInput({
|
|
|
230
231
|
outputValue = JSON.stringify(output.value);
|
|
231
232
|
break;
|
|
232
233
|
case 'content':
|
|
233
|
-
outputValue =
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
234
|
+
outputValue = [];
|
|
235
|
+
for (const item of output.value) {
|
|
236
|
+
switch (item.type) {
|
|
237
|
+
case 'text': {
|
|
238
|
+
outputValue.push({
|
|
239
|
+
type: 'input_text',
|
|
240
|
+
text: item.text,
|
|
241
|
+
});
|
|
242
|
+
break;
|
|
237
243
|
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
244
|
+
case 'image-data': {
|
|
245
|
+
outputValue.push({
|
|
246
|
+
type: 'input_image',
|
|
247
|
+
image_url: `data:${item.mediaType};base64,${item.data}`,
|
|
248
|
+
});
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
case 'image-url': {
|
|
252
|
+
outputValue.push({
|
|
253
|
+
type: 'input_image',
|
|
254
|
+
image_url: item.url,
|
|
255
|
+
});
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
case 'file-data':
|
|
259
|
+
case 'file-url':
|
|
260
|
+
case 'file-id':
|
|
261
|
+
case 'image-file-id':
|
|
262
|
+
case 'custom': {
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
default: {
|
|
266
|
+
const _exhaustiveCheck: never = item;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
241
270
|
break;
|
|
242
271
|
default: {
|
|
243
272
|
const _exhaustiveCheck: never = output;
|
|
@@ -47,7 +47,18 @@ export type XaiResponsesAssistantMessage = {
|
|
|
47
47
|
export type XaiResponsesFunctionCallOutput = {
|
|
48
48
|
type: 'function_call_output';
|
|
49
49
|
call_id: string;
|
|
50
|
-
output:
|
|
50
|
+
output:
|
|
51
|
+
| string
|
|
52
|
+
| Array<
|
|
53
|
+
| {
|
|
54
|
+
type: 'input_text';
|
|
55
|
+
text: string;
|
|
56
|
+
}
|
|
57
|
+
| {
|
|
58
|
+
type: 'input_image';
|
|
59
|
+
image_url: string;
|
|
60
|
+
}
|
|
61
|
+
>;
|
|
51
62
|
};
|
|
52
63
|
|
|
53
64
|
export type XaiResponsesReasoning = {
|
package/src/xai-video-model.ts
CHANGED
|
@@ -5,14 +5,17 @@ import {
|
|
|
5
5
|
type SharedV3Warning,
|
|
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
|
type FetchFunction,
|
|
13
15
|
getFromApi,
|
|
14
16
|
parseProviderOptions,
|
|
15
17
|
postJsonToApi,
|
|
18
|
+
type ResponseHandler,
|
|
16
19
|
} from '@ai-sdk/provider-utils';
|
|
17
20
|
import { z } from 'zod/v4';
|
|
18
21
|
import { xaiFailedResponseHandler } from './xai-error';
|
|
@@ -438,9 +441,7 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
|
|
|
438
441
|
await getFromApi({
|
|
439
442
|
url: `${baseURL}/videos/${requestId}`,
|
|
440
443
|
headers: combineHeaders(this.config.headers(), options.headers),
|
|
441
|
-
successfulResponseHandler:
|
|
442
|
-
xaiVideoStatusResponseSchema,
|
|
443
|
-
),
|
|
444
|
+
successfulResponseHandler: xaiVideoStatusResponseHandler,
|
|
444
445
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
445
446
|
abortSignal: options.abortSignal,
|
|
446
447
|
fetch: this.config.fetch,
|
|
@@ -546,3 +547,23 @@ const xaiVideoStatusResponseSchema = z.object({
|
|
|
546
547
|
})
|
|
547
548
|
.nullish(),
|
|
548
549
|
});
|
|
550
|
+
|
|
551
|
+
const xaiVideoStatusJsonResponseHandler = createJsonResponseHandler(
|
|
552
|
+
xaiVideoStatusResponseSchema,
|
|
553
|
+
);
|
|
554
|
+
|
|
555
|
+
const xaiVideoStatusResponseHandler: ResponseHandler<
|
|
556
|
+
z.infer<typeof xaiVideoStatusResponseSchema>
|
|
557
|
+
> = async options => {
|
|
558
|
+
if (options.response.status === 202) {
|
|
559
|
+
const responseHeaders = extractResponseHeaders(options.response);
|
|
560
|
+
await cancelResponseBody(options.response);
|
|
561
|
+
|
|
562
|
+
return {
|
|
563
|
+
responseHeaders,
|
|
564
|
+
value: { status: 'pending' },
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
return xaiVideoStatusJsonResponseHandler(options);
|
|
569
|
+
};
|