@ai-sdk/xai 3.0.69 → 3.0.70
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 +6 -0
- package/dist/index.d.mts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +26 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/xai-image-model.ts +29 -6
- package/src/xai-image-options.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/xai",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.70",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@ai-sdk/provider": "3.0.8",
|
|
33
32
|
"@ai-sdk/openai-compatible": "2.0.36",
|
|
33
|
+
"@ai-sdk/provider": "3.0.8",
|
|
34
34
|
"@ai-sdk/provider-utils": "4.0.20"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"tsup": "^8",
|
|
39
39
|
"typescript": "5.8.3",
|
|
40
40
|
"zod": "3.25.76",
|
|
41
|
-
"@
|
|
42
|
-
"@ai-
|
|
41
|
+
"@ai-sdk/test-server": "1.0.3",
|
|
42
|
+
"@vercel/ai-tsconfig": "0.0.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"zod": "^3.25.76 || ^4.1.8"
|
package/src/xai-image-model.ts
CHANGED
|
@@ -94,7 +94,7 @@ export class XaiImageModel implements ImageModelV3 {
|
|
|
94
94
|
model: this.modelId,
|
|
95
95
|
prompt,
|
|
96
96
|
n,
|
|
97
|
-
response_format: '
|
|
97
|
+
response_format: 'b64_json',
|
|
98
98
|
};
|
|
99
99
|
|
|
100
100
|
if (aspectRatio != null) {
|
|
@@ -117,6 +117,14 @@ export class XaiImageModel implements ImageModelV3 {
|
|
|
117
117
|
body.resolution = xaiOptions.resolution;
|
|
118
118
|
}
|
|
119
119
|
|
|
120
|
+
if (xaiOptions?.quality != null) {
|
|
121
|
+
body.quality = xaiOptions.quality;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (xaiOptions?.user != null) {
|
|
125
|
+
body.user = xaiOptions.user;
|
|
126
|
+
}
|
|
127
|
+
|
|
120
128
|
if (imageUrls.length === 1) {
|
|
121
129
|
body.image = { url: imageUrls[0], type: 'image_url' };
|
|
122
130
|
} else if (imageUrls.length > 1) {
|
|
@@ -137,12 +145,18 @@ export class XaiImageModel implements ImageModelV3 {
|
|
|
137
145
|
fetch: this.config.fetch,
|
|
138
146
|
});
|
|
139
147
|
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
148
|
+
const hasAllBase64 = response.data.every(image => image.b64_json != null);
|
|
149
|
+
|
|
150
|
+
const images = hasAllBase64
|
|
151
|
+
? response.data.map(image => image.b64_json!)
|
|
152
|
+
: await Promise.all(
|
|
153
|
+
response.data.map(image =>
|
|
154
|
+
this.downloadImage(image.url!, abortSignal),
|
|
155
|
+
),
|
|
156
|
+
);
|
|
143
157
|
|
|
144
158
|
return {
|
|
145
|
-
images
|
|
159
|
+
images,
|
|
146
160
|
warnings,
|
|
147
161
|
response: {
|
|
148
162
|
timestamp: currentDate,
|
|
@@ -156,6 +170,9 @@ export class XaiImageModel implements ImageModelV3 {
|
|
|
156
170
|
? { revisedPrompt: item.revised_prompt }
|
|
157
171
|
: {}),
|
|
158
172
|
})),
|
|
173
|
+
...(response.usage?.cost_in_usd_ticks != null
|
|
174
|
+
? { costInUsdTicks: response.usage.cost_in_usd_ticks }
|
|
175
|
+
: {}),
|
|
159
176
|
},
|
|
160
177
|
},
|
|
161
178
|
};
|
|
@@ -179,8 +196,14 @@ export class XaiImageModel implements ImageModelV3 {
|
|
|
179
196
|
const xaiImageResponseSchema = z.object({
|
|
180
197
|
data: z.array(
|
|
181
198
|
z.object({
|
|
182
|
-
url: z.string(),
|
|
199
|
+
url: z.string().nullish(),
|
|
200
|
+
b64_json: z.string().nullish(),
|
|
183
201
|
revised_prompt: z.string().nullish(),
|
|
184
202
|
}),
|
|
185
203
|
),
|
|
204
|
+
usage: z
|
|
205
|
+
.object({
|
|
206
|
+
cost_in_usd_ticks: z.number().nullish(),
|
|
207
|
+
})
|
|
208
|
+
.nullish(),
|
|
186
209
|
});
|
package/src/xai-image-options.ts
CHANGED
|
@@ -5,6 +5,8 @@ export const xaiImageModelOptions = z.object({
|
|
|
5
5
|
output_format: z.string().optional(),
|
|
6
6
|
sync_mode: z.boolean().optional(),
|
|
7
7
|
resolution: z.enum(['1k', '2k']).optional(),
|
|
8
|
+
quality: z.enum(['low', 'medium', 'high']).optional(),
|
|
9
|
+
user: z.string().optional(),
|
|
8
10
|
});
|
|
9
11
|
|
|
10
12
|
export type XaiImageModelOptions = z.infer<typeof xaiImageModelOptions>;
|