@ai-sdk/xai 3.0.75 → 3.0.77

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.
@@ -1,23 +1,145 @@
1
1
  import { lazySchema, zodSchema } from '@ai-sdk/provider-utils';
2
2
  import { z } from 'zod/v4';
3
3
 
4
- export type XaiVideoModelOptions = {
4
+ const nonEmptyStringSchema = z.string().min(1);
5
+ const resolutionSchema = z.enum(['480p', '720p']);
6
+ const modeSchema = z.enum(['edit-video', 'extend-video', 'reference-to-video']);
7
+
8
+ export type XaiVideoMode = z.infer<typeof modeSchema>;
9
+ type XaiVideoResolution = z.infer<typeof resolutionSchema>;
10
+
11
+ interface XaiVideoSharedOptions {
5
12
  pollIntervalMs?: number | null;
6
13
  pollTimeoutMs?: number | null;
7
- resolution?: '480p' | '720p' | null;
8
- videoUrl?: string | null;
9
- [key: string]: unknown;
14
+ resolution?: XaiVideoResolution | null;
15
+ }
16
+
17
+ interface XaiVideoEditModeOptions extends XaiVideoSharedOptions {
18
+ /**
19
+ * Select edit-video mode explicitly for best autocomplete and narrowing.
20
+ */
21
+ mode: 'edit-video';
22
+ /** Source video URL to edit. */
23
+ videoUrl: string;
24
+ }
25
+
26
+ interface XaiVideoExtendModeOptions extends XaiVideoSharedOptions {
27
+ /**
28
+ * Select extend-video mode explicitly for best autocomplete and narrowing.
29
+ */
30
+ mode: 'extend-video';
31
+ /** Source video URL to extend from its last frame. */
32
+ videoUrl: string;
33
+ }
34
+
35
+ interface XaiVideoReferenceToVideoOptions extends XaiVideoSharedOptions {
36
+ /**
37
+ * Select reference-to-video mode explicitly for best autocomplete and narrowing.
38
+ */
39
+ mode: 'reference-to-video';
40
+ /** Reference image URLs (1-7) for R2V generation. */
41
+ referenceImageUrls: string[];
42
+ }
43
+
44
+ interface XaiVideoGenerationOptions extends XaiVideoSharedOptions {
45
+ mode?: undefined;
46
+ videoUrl?: undefined;
47
+ referenceImageUrls?: undefined;
48
+ }
49
+
50
+ interface XaiLegacyEditVideoOptions extends XaiVideoSharedOptions {
51
+ /**
52
+ * Legacy backward-compatible shape: omitting `mode` while providing
53
+ * `videoUrl` behaves like edit-video.
54
+ */
55
+ mode?: undefined;
56
+ videoUrl: string;
57
+ }
58
+
59
+ interface XaiLegacyReferenceToVideoOptions extends XaiVideoSharedOptions {
60
+ /**
61
+ * Legacy backward-compatible shape: omitting `mode` while providing
62
+ * `referenceImageUrls` behaves like reference-to-video.
63
+ */
64
+ mode?: undefined;
65
+ referenceImageUrls: string[];
66
+ }
67
+
68
+ /**
69
+ * Provider options for xAI video generation.
70
+ *
71
+ * Use the `mode` option to select the operation:
72
+ *
73
+ * - `'edit-video'` + `videoUrl` -- video editing (`POST /v1/videos/edits`)
74
+ * - `'extend-video'` + `videoUrl` -- video extension (`POST /v1/videos/extensions`)
75
+ * - `'reference-to-video'` + `referenceImageUrls` -- R2V generation (`POST /v1/videos/generations`)
76
+ * - no `mode` -- standard generation from text prompts or image input
77
+ *
78
+ * Runtime remains backward compatible with legacy auto-detected provider
79
+ * options, but the public TypeScript type is intentionally explicit so editors
80
+ * can suggest valid modes and flag invalid field combinations.
81
+ */
82
+ export type XaiVideoModelOptions =
83
+ | XaiVideoGenerationOptions
84
+ | XaiVideoEditModeOptions
85
+ | XaiVideoExtendModeOptions
86
+ | XaiVideoReferenceToVideoOptions
87
+ | XaiLegacyEditVideoOptions
88
+ | XaiLegacyReferenceToVideoOptions;
89
+
90
+ // ── Runtime schemas ───────────────────────────────────────────────────
91
+ const baseFields = {
92
+ pollIntervalMs: z.number().positive().nullish(),
93
+ pollTimeoutMs: z.number().positive().nullish(),
94
+ resolution: resolutionSchema.nullish(),
10
95
  };
11
96
 
97
+ const editVideoSchema = z.object({
98
+ ...baseFields,
99
+ mode: z.literal('edit-video'),
100
+ videoUrl: nonEmptyStringSchema,
101
+ referenceImageUrls: z.undefined().optional(),
102
+ });
103
+
104
+ const extendVideoSchema = z.object({
105
+ ...baseFields,
106
+ mode: z.literal('extend-video'),
107
+ videoUrl: nonEmptyStringSchema,
108
+ referenceImageUrls: z.undefined().optional(),
109
+ });
110
+
111
+ const referenceToVideoSchema = z.object({
112
+ ...baseFields,
113
+ mode: z.literal('reference-to-video'),
114
+ referenceImageUrls: z.array(nonEmptyStringSchema).min(1).max(7),
115
+ videoUrl: z.undefined().optional(),
116
+ });
117
+
118
+ const autoDetectSchema = z.object({
119
+ ...baseFields,
120
+ mode: z.undefined().optional(),
121
+ videoUrl: nonEmptyStringSchema.optional(),
122
+ referenceImageUrls: z.array(nonEmptyStringSchema).min(1).max(7).optional(),
123
+ });
124
+
125
+ export const xaiVideoModelOptions = z.union([
126
+ editVideoSchema,
127
+ extendVideoSchema,
128
+ referenceToVideoSchema,
129
+ autoDetectSchema,
130
+ ]);
131
+
132
+ const runtimeSchema = z
133
+ .object({
134
+ mode: modeSchema.optional(),
135
+ videoUrl: nonEmptyStringSchema.optional(),
136
+ referenceImageUrls: z.array(nonEmptyStringSchema).min(1).max(7).optional(),
137
+ ...baseFields,
138
+ })
139
+ .passthrough();
140
+
141
+ export type XaiParsedVideoModelOptions = z.infer<typeof runtimeSchema>;
142
+
12
143
  export const xaiVideoModelOptionsSchema = lazySchema(() =>
13
- zodSchema(
14
- z
15
- .object({
16
- pollIntervalMs: z.number().positive().nullish(),
17
- pollTimeoutMs: z.number().positive().nullish(),
18
- resolution: z.enum(['480p', '720p']).nullish(),
19
- videoUrl: z.string().nullish(),
20
- })
21
- .passthrough(),
22
- ),
144
+ zodSchema(runtimeSchema),
23
145
  );