@ai-sdk/xai 4.0.14 → 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/CHANGELOG.md +16 -0
- package/dist/index.d.ts +11 -5
- package/dist/index.js +56 -10
- package/dist/index.js.map +1 -1
- package/docs/01-xai.mdx +9 -0
- package/package.json +6 -6
- package/src/responses/convert-to-xai-responses-input.ts +34 -8
- package/src/responses/xai-responses-api.ts +12 -1
- package/src/xai-video-model-options.ts +25 -5
- package/src/xai-video-model.ts +29 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @ai-sdk/xai
|
|
2
2
|
|
|
3
|
+
## 4.0.16
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1e2ae1f: fix(xai): handle empty HTTP 202 responses while polling videos
|
|
8
|
+
- 54e5498: fix(provider/xai): preserve images in Responses API tool results
|
|
9
|
+
- Updated dependencies [cd06458]
|
|
10
|
+
- @ai-sdk/provider-utils@5.0.11
|
|
11
|
+
- @ai-sdk/openai-compatible@3.0.12
|
|
12
|
+
|
|
13
|
+
## 4.0.15
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- 91a3d6e: feat(provider/xai): support end-user identifiers for video generation and editing
|
|
18
|
+
|
|
3
19
|
## 4.0.14
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -127,7 +127,13 @@ interface XaiVideoSharedOptions {
|
|
|
127
127
|
pollTimeoutMs?: number | null;
|
|
128
128
|
resolution?: XaiVideoResolution | null;
|
|
129
129
|
}
|
|
130
|
-
interface
|
|
130
|
+
interface XaiVideoUserOptions {
|
|
131
|
+
/**
|
|
132
|
+
* A unique identifier representing the end user, for abuse monitoring.
|
|
133
|
+
*/
|
|
134
|
+
user?: string;
|
|
135
|
+
}
|
|
136
|
+
interface XaiVideoEditModeOptions extends XaiVideoSharedOptions, XaiVideoUserOptions {
|
|
131
137
|
/**
|
|
132
138
|
* Select edit-video mode explicitly for best autocomplete and narrowing.
|
|
133
139
|
*/
|
|
@@ -143,7 +149,7 @@ interface XaiVideoExtendModeOptions extends XaiVideoSharedOptions {
|
|
|
143
149
|
/** Source video URL to extend from its last frame. */
|
|
144
150
|
videoUrl: string;
|
|
145
151
|
}
|
|
146
|
-
interface XaiVideoReferenceToVideoOptions extends XaiVideoSharedOptions {
|
|
152
|
+
interface XaiVideoReferenceToVideoOptions extends XaiVideoSharedOptions, XaiVideoUserOptions {
|
|
147
153
|
/**
|
|
148
154
|
* Select reference-to-video mode explicitly for best autocomplete and narrowing.
|
|
149
155
|
*/
|
|
@@ -151,12 +157,12 @@ interface XaiVideoReferenceToVideoOptions extends XaiVideoSharedOptions {
|
|
|
151
157
|
/** Reference image URLs (1-7) for R2V generation. */
|
|
152
158
|
referenceImageUrls: string[];
|
|
153
159
|
}
|
|
154
|
-
interface XaiVideoGenerationOptions extends XaiVideoSharedOptions {
|
|
160
|
+
interface XaiVideoGenerationOptions extends XaiVideoSharedOptions, XaiVideoUserOptions {
|
|
155
161
|
mode?: undefined;
|
|
156
162
|
videoUrl?: undefined;
|
|
157
163
|
referenceImageUrls?: undefined;
|
|
158
164
|
}
|
|
159
|
-
interface XaiLegacyEditVideoOptions extends XaiVideoSharedOptions {
|
|
165
|
+
interface XaiLegacyEditVideoOptions extends XaiVideoSharedOptions, XaiVideoUserOptions {
|
|
160
166
|
/**
|
|
161
167
|
* Legacy backward-compatible shape: omitting `mode` while providing
|
|
162
168
|
* `videoUrl` behaves like edit-video.
|
|
@@ -164,7 +170,7 @@ interface XaiLegacyEditVideoOptions extends XaiVideoSharedOptions {
|
|
|
164
170
|
mode?: undefined;
|
|
165
171
|
videoUrl: string;
|
|
166
172
|
}
|
|
167
|
-
interface XaiLegacyReferenceToVideoOptions extends XaiVideoSharedOptions {
|
|
173
|
+
interface XaiLegacyReferenceToVideoOptions extends XaiVideoSharedOptions, XaiVideoUserOptions {
|
|
168
174
|
/**
|
|
169
175
|
* Legacy backward-compatible shape: omitting `mode` while providing
|
|
170
176
|
* `referenceImageUrls` behaves like reference-to-video.
|
package/dist/index.js
CHANGED
|
@@ -1414,12 +1414,33 @@ async function convertToXaiResponsesInput({
|
|
|
1414
1414
|
outputValue = JSON.stringify(output.value);
|
|
1415
1415
|
break;
|
|
1416
1416
|
case "content":
|
|
1417
|
-
outputValue =
|
|
1418
|
-
|
|
1419
|
-
|
|
1417
|
+
outputValue = [];
|
|
1418
|
+
for (const item of output.value) {
|
|
1419
|
+
switch (item.type) {
|
|
1420
|
+
case "text": {
|
|
1421
|
+
outputValue.push({
|
|
1422
|
+
type: "input_text",
|
|
1423
|
+
text: item.text
|
|
1424
|
+
});
|
|
1425
|
+
break;
|
|
1426
|
+
}
|
|
1427
|
+
case "file": {
|
|
1428
|
+
if (getTopLevelMediaType2(item.mediaType) === "image" && (item.data.type === "data" || item.data.type === "url")) {
|
|
1429
|
+
outputValue.push({
|
|
1430
|
+
type: "input_image",
|
|
1431
|
+
image_url: item.data.type === "url" ? item.data.url.toString() : `data:${resolveFullMediaType2({ part: item })};base64,${convertToBase642(item.data.data)}`
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
break;
|
|
1435
|
+
}
|
|
1436
|
+
case "custom": {
|
|
1437
|
+
break;
|
|
1438
|
+
}
|
|
1439
|
+
default: {
|
|
1440
|
+
const _exhaustiveCheck = item;
|
|
1441
|
+
}
|
|
1420
1442
|
}
|
|
1421
|
-
|
|
1422
|
-
}).join("");
|
|
1443
|
+
}
|
|
1423
1444
|
break;
|
|
1424
1445
|
default: {
|
|
1425
1446
|
const _exhaustiveCheck = output;
|
|
@@ -3477,7 +3498,7 @@ var xaiTools = {
|
|
|
3477
3498
|
};
|
|
3478
3499
|
|
|
3479
3500
|
// src/version.ts
|
|
3480
|
-
var VERSION = true ? "4.0.
|
|
3501
|
+
var VERSION = true ? "4.0.16" : "0.0.0-test";
|
|
3481
3502
|
|
|
3482
3503
|
// src/files/xai-files.ts
|
|
3483
3504
|
import {
|
|
@@ -3585,10 +3606,12 @@ import {
|
|
|
3585
3606
|
AISDKError
|
|
3586
3607
|
} from "@ai-sdk/provider";
|
|
3587
3608
|
import {
|
|
3609
|
+
cancelResponseBody,
|
|
3588
3610
|
combineHeaders as combineHeaders5,
|
|
3589
3611
|
convertUint8ArrayToBase64,
|
|
3590
3612
|
createJsonResponseHandler as createJsonResponseHandler5,
|
|
3591
3613
|
delay,
|
|
3614
|
+
extractResponseHeaders as extractResponseHeaders2,
|
|
3592
3615
|
getFromApi as getFromApi2,
|
|
3593
3616
|
getTopLevelMediaType as getTopLevelMediaType3,
|
|
3594
3617
|
parseProviderOptions as parseProviderOptions7,
|
|
@@ -3607,8 +3630,12 @@ var baseFields = {
|
|
|
3607
3630
|
pollTimeoutMs: z18.number().positive().nullish(),
|
|
3608
3631
|
resolution: resolutionSchema.nullish()
|
|
3609
3632
|
};
|
|
3633
|
+
var userField = {
|
|
3634
|
+
user: z18.string().optional()
|
|
3635
|
+
};
|
|
3610
3636
|
var editVideoSchema = z18.object({
|
|
3611
3637
|
...baseFields,
|
|
3638
|
+
...userField,
|
|
3612
3639
|
mode: z18.literal("edit-video"),
|
|
3613
3640
|
videoUrl: nonEmptyStringSchema,
|
|
3614
3641
|
referenceImageUrls: z18.undefined().optional()
|
|
@@ -3621,12 +3648,14 @@ var extendVideoSchema = z18.object({
|
|
|
3621
3648
|
});
|
|
3622
3649
|
var referenceToVideoSchema = z18.object({
|
|
3623
3650
|
...baseFields,
|
|
3651
|
+
...userField,
|
|
3624
3652
|
mode: z18.literal("reference-to-video"),
|
|
3625
3653
|
referenceImageUrls: z18.array(nonEmptyStringSchema).min(1).max(7),
|
|
3626
3654
|
videoUrl: z18.undefined().optional()
|
|
3627
3655
|
});
|
|
3628
3656
|
var autoDetectSchema = z18.object({
|
|
3629
3657
|
...baseFields,
|
|
3658
|
+
...userField,
|
|
3630
3659
|
mode: z18.undefined().optional(),
|
|
3631
3660
|
videoUrl: nonEmptyStringSchema.optional(),
|
|
3632
3661
|
referenceImageUrls: z18.array(nonEmptyStringSchema).min(1).max(7).optional()
|
|
@@ -3641,6 +3670,7 @@ var runtimeSchema = z18.looseObject({
|
|
|
3641
3670
|
mode: modeSchema.optional(),
|
|
3642
3671
|
videoUrl: nonEmptyStringSchema.optional(),
|
|
3643
3672
|
referenceImageUrls: z18.array(nonEmptyStringSchema).min(1).max(7).optional(),
|
|
3673
|
+
user: z18.string().optional(),
|
|
3644
3674
|
...baseFields
|
|
3645
3675
|
});
|
|
3646
3676
|
var xaiVideoModelOptionsSchema = lazySchema7(
|
|
@@ -3860,6 +3890,9 @@ var XaiVideoModel = class {
|
|
|
3860
3890
|
details: "xAI only supports inputReferences for reference-to-video generation. The reference images were ignored."
|
|
3861
3891
|
});
|
|
3862
3892
|
}
|
|
3893
|
+
if (!isExtension && (xaiOptions == null ? void 0 : xaiOptions.user) !== void 0) {
|
|
3894
|
+
body.user = xaiOptions.user;
|
|
3895
|
+
}
|
|
3863
3896
|
if (xaiOptions != null) {
|
|
3864
3897
|
for (const [key, value] of Object.entries(xaiOptions)) {
|
|
3865
3898
|
if (![
|
|
@@ -3868,7 +3901,8 @@ var XaiVideoModel = class {
|
|
|
3868
3901
|
"pollTimeoutMs",
|
|
3869
3902
|
"resolution",
|
|
3870
3903
|
"videoUrl",
|
|
3871
|
-
"referenceImageUrls"
|
|
3904
|
+
"referenceImageUrls",
|
|
3905
|
+
"user"
|
|
3872
3906
|
].includes(key)) {
|
|
3873
3907
|
body[key] = value;
|
|
3874
3908
|
}
|
|
@@ -3917,9 +3951,7 @@ var XaiVideoModel = class {
|
|
|
3917
3951
|
url: `${baseURL}/videos/${requestId}`,
|
|
3918
3952
|
validateUrl: false,
|
|
3919
3953
|
headers: combineHeaders5(this.config.headers(), options.headers),
|
|
3920
|
-
successfulResponseHandler:
|
|
3921
|
-
xaiVideoStatusResponseSchema
|
|
3922
|
-
),
|
|
3954
|
+
successfulResponseHandler: xaiVideoStatusResponseHandler,
|
|
3923
3955
|
failedResponseHandler: xaiFailedResponseHandler,
|
|
3924
3956
|
abortSignal: options.abortSignal,
|
|
3925
3957
|
fetch: this.config.fetch
|
|
@@ -3998,6 +4030,20 @@ var xaiVideoStatusResponseSchema = z19.object({
|
|
|
3998
4030
|
message: z19.string().nullish()
|
|
3999
4031
|
}).nullish()
|
|
4000
4032
|
});
|
|
4033
|
+
var xaiVideoStatusJsonResponseHandler = createJsonResponseHandler5(
|
|
4034
|
+
xaiVideoStatusResponseSchema
|
|
4035
|
+
);
|
|
4036
|
+
var xaiVideoStatusResponseHandler = async (options) => {
|
|
4037
|
+
if (options.response.status === 202) {
|
|
4038
|
+
const responseHeaders = extractResponseHeaders2(options.response);
|
|
4039
|
+
await cancelResponseBody(options.response);
|
|
4040
|
+
return {
|
|
4041
|
+
responseHeaders,
|
|
4042
|
+
value: { status: "pending" }
|
|
4043
|
+
};
|
|
4044
|
+
}
|
|
4045
|
+
return xaiVideoStatusJsonResponseHandler(options);
|
|
4046
|
+
};
|
|
4001
4047
|
|
|
4002
4048
|
// src/xai-speech-model.ts
|
|
4003
4049
|
import {
|