@ai-sdk/xai 4.0.0-beta.2 → 4.0.0-beta.21
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 +156 -8
- package/README.md +2 -0
- package/dist/index.d.mts +51 -43
- package/dist/index.d.ts +51 -43
- package/dist/index.js +110 -53
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +111 -50
- package/dist/index.mjs.map +1 -1
- package/docs/01-xai.mdx +30 -336
- package/package.json +4 -6
- package/src/convert-to-xai-chat-messages.ts +5 -5
- package/src/convert-xai-chat-usage.ts +2 -2
- package/src/map-xai-finish-reason.ts +2 -2
- package/src/responses/convert-to-xai-responses-input.ts +7 -5
- package/src/responses/convert-xai-responses-usage.ts +2 -2
- package/src/responses/map-xai-responses-finish-reason.ts +2 -2
- package/src/responses/xai-responses-api.ts +3 -0
- package/src/responses/xai-responses-language-model.ts +71 -30
- package/src/responses/xai-responses-options.ts +4 -0
- package/src/responses/xai-responses-prepare-tools.ts +6 -6
- package/src/xai-chat-language-model.ts +41 -22
- package/src/xai-chat-options.ts +3 -6
- package/src/xai-image-model.ts +43 -28
- package/src/xai-image-options.ts +2 -0
- package/src/xai-image-settings.ts +0 -2
- package/src/xai-prepare-tools.ts +6 -6
- package/src/xai-provider.ts +18 -21
- package/src/xai-video-model.ts +23 -7
package/src/xai-provider.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
type Experimental_VideoModelV4,
|
|
3
|
+
ImageModelV4,
|
|
4
|
+
LanguageModelV4,
|
|
5
5
|
NoSuchModelError,
|
|
6
|
-
|
|
6
|
+
ProviderV4,
|
|
7
7
|
} from '@ai-sdk/provider';
|
|
8
8
|
import {
|
|
9
9
|
FetchFunction,
|
|
@@ -23,46 +23,43 @@ import { VERSION } from './version';
|
|
|
23
23
|
import { XaiVideoModel } from './xai-video-model';
|
|
24
24
|
import { XaiVideoModelId } from './xai-video-settings';
|
|
25
25
|
|
|
26
|
-
export interface XaiProvider extends
|
|
27
|
-
|
|
28
|
-
* Creates an Xai chat model for text generation.
|
|
29
|
-
*/
|
|
30
|
-
(modelId: XaiChatModelId): LanguageModelV3;
|
|
26
|
+
export interface XaiProvider extends ProviderV4 {
|
|
27
|
+
(modelId: XaiResponsesModelId): LanguageModelV4;
|
|
31
28
|
|
|
32
29
|
/**
|
|
33
30
|
* Creates an Xai language model for text generation.
|
|
34
31
|
*/
|
|
35
|
-
languageModel(modelId:
|
|
32
|
+
languageModel(modelId: XaiResponsesModelId): LanguageModelV4;
|
|
36
33
|
|
|
37
34
|
/**
|
|
38
35
|
* Creates an Xai chat model for text generation.
|
|
39
36
|
*/
|
|
40
|
-
chat: (modelId: XaiChatModelId) =>
|
|
37
|
+
chat: (modelId: XaiChatModelId) => LanguageModelV4;
|
|
41
38
|
|
|
42
39
|
/**
|
|
43
|
-
* Creates an Xai responses model for
|
|
40
|
+
* Creates an Xai responses model for text generation.
|
|
44
41
|
*/
|
|
45
|
-
responses: (modelId: XaiResponsesModelId) =>
|
|
42
|
+
responses: (modelId: XaiResponsesModelId) => LanguageModelV4;
|
|
46
43
|
|
|
47
44
|
/**
|
|
48
45
|
* Creates an Xai image model for image generation.
|
|
49
46
|
*/
|
|
50
|
-
image(modelId: XaiImageModelId):
|
|
47
|
+
image(modelId: XaiImageModelId): ImageModelV4;
|
|
51
48
|
|
|
52
49
|
/**
|
|
53
50
|
* Creates an Xai image model for image generation.
|
|
54
51
|
*/
|
|
55
|
-
imageModel(modelId: XaiImageModelId):
|
|
52
|
+
imageModel(modelId: XaiImageModelId): ImageModelV4;
|
|
56
53
|
|
|
57
54
|
/**
|
|
58
55
|
* Creates an Xai video model for video generation.
|
|
59
56
|
*/
|
|
60
|
-
video(modelId: XaiVideoModelId):
|
|
57
|
+
video(modelId: XaiVideoModelId): Experimental_VideoModelV4;
|
|
61
58
|
|
|
62
59
|
/**
|
|
63
60
|
* Creates an Xai video model for video generation.
|
|
64
61
|
*/
|
|
65
|
-
videoModel(modelId: XaiVideoModelId):
|
|
62
|
+
videoModel(modelId: XaiVideoModelId): Experimental_VideoModelV4;
|
|
66
63
|
|
|
67
64
|
/**
|
|
68
65
|
* Server-side agentic tools for use with the responses API.
|
|
@@ -153,11 +150,11 @@ export function createXai(options: XaiProviderSettings = {}): XaiProvider {
|
|
|
153
150
|
});
|
|
154
151
|
};
|
|
155
152
|
|
|
156
|
-
const provider = (modelId:
|
|
157
|
-
|
|
153
|
+
const provider = (modelId: XaiResponsesModelId) =>
|
|
154
|
+
createResponsesLanguageModel(modelId);
|
|
158
155
|
|
|
159
|
-
provider.specificationVersion = '
|
|
160
|
-
provider.languageModel =
|
|
156
|
+
provider.specificationVersion = 'v4' as const;
|
|
157
|
+
provider.languageModel = createResponsesLanguageModel;
|
|
161
158
|
provider.chat = createChatLanguageModel;
|
|
162
159
|
provider.responses = createResponsesLanguageModel;
|
|
163
160
|
provider.embeddingModel = (modelId: string) => {
|
package/src/xai-video-model.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AISDKError,
|
|
3
|
-
type
|
|
4
|
-
type
|
|
3
|
+
type Experimental_VideoModelV4,
|
|
4
|
+
type SharedV4Warning,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
7
7
|
combineHeaders,
|
|
@@ -37,8 +37,8 @@ const RESOLUTION_MAP: Record<string, string> = {
|
|
|
37
37
|
'640x480': '480p',
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
export class XaiVideoModel implements
|
|
41
|
-
readonly specificationVersion = '
|
|
40
|
+
export class XaiVideoModel implements Experimental_VideoModelV4 {
|
|
41
|
+
readonly specificationVersion = 'v4';
|
|
42
42
|
readonly maxVideosPerCall = 1;
|
|
43
43
|
|
|
44
44
|
get provider(): string {
|
|
@@ -51,10 +51,10 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
|
|
|
51
51
|
) {}
|
|
52
52
|
|
|
53
53
|
async doGenerate(
|
|
54
|
-
options: Parameters<
|
|
55
|
-
): Promise<Awaited<ReturnType<
|
|
54
|
+
options: Parameters<Experimental_VideoModelV4['doGenerate']>[0],
|
|
55
|
+
): Promise<Awaited<ReturnType<Experimental_VideoModelV4['doGenerate']>>> {
|
|
56
56
|
const currentDate = this.config._internal?.currentDate?.() ?? new Date();
|
|
57
|
-
const warnings:
|
|
57
|
+
const warnings: SharedV4Warning[] = [];
|
|
58
58
|
|
|
59
59
|
const xaiOptions = (await parseProviderOptions({
|
|
60
60
|
provider: 'xai',
|
|
@@ -239,6 +239,14 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
|
|
|
239
239
|
statusResponse.status === 'done' ||
|
|
240
240
|
(statusResponse.status == null && statusResponse.video?.url)
|
|
241
241
|
) {
|
|
242
|
+
if (statusResponse.video?.respect_moderation === false) {
|
|
243
|
+
throw new AISDKError({
|
|
244
|
+
name: 'XAI_VIDEO_MODERATION_ERROR',
|
|
245
|
+
message:
|
|
246
|
+
'Video generation was blocked due to a content policy violation.',
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
|
|
242
250
|
if (!statusResponse.video?.url) {
|
|
243
251
|
throw new AISDKError({
|
|
244
252
|
name: 'XAI_VIDEO_GENERATION_ERROR',
|
|
@@ -268,6 +276,9 @@ export class XaiVideoModel implements Experimental_VideoModelV3 {
|
|
|
268
276
|
...(statusResponse.video.duration != null
|
|
269
277
|
? { duration: statusResponse.video.duration }
|
|
270
278
|
: {}),
|
|
279
|
+
...(statusResponse.usage?.cost_in_usd_ticks != null
|
|
280
|
+
? { costInUsdTicks: statusResponse.usage.cost_in_usd_ticks }
|
|
281
|
+
: {}),
|
|
271
282
|
},
|
|
272
283
|
},
|
|
273
284
|
};
|
|
@@ -299,4 +310,9 @@ const xaiVideoStatusResponseSchema = z.object({
|
|
|
299
310
|
})
|
|
300
311
|
.nullish(),
|
|
301
312
|
model: z.string().nullish(),
|
|
313
|
+
usage: z
|
|
314
|
+
.object({
|
|
315
|
+
cost_in_usd_ticks: z.number().nullish(),
|
|
316
|
+
})
|
|
317
|
+
.nullish(),
|
|
302
318
|
});
|