@tanstack/ai-grok 0.14.9 → 0.14.11

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.
Files changed (36) hide show
  1. package/dist/esm/adapters/image.js +228 -193
  2. package/dist/esm/adapters/image.js.map +1 -1
  3. package/dist/esm/adapters/summarize.js +49 -12
  4. package/dist/esm/adapters/summarize.js.map +1 -1
  5. package/dist/esm/adapters/text.js +82 -38
  6. package/dist/esm/adapters/text.js.map +1 -1
  7. package/dist/esm/adapters/transcription.js +133 -114
  8. package/dist/esm/adapters/transcription.js.map +1 -1
  9. package/dist/esm/adapters/tts.js +147 -130
  10. package/dist/esm/adapters/tts.js.map +1 -1
  11. package/dist/esm/adapters/video.js +275 -226
  12. package/dist/esm/adapters/video.js.map +1 -1
  13. package/dist/esm/image/image-provider-options.js +64 -66
  14. package/dist/esm/image/image-provider-options.js.map +1 -1
  15. package/dist/esm/index.js +3 -31
  16. package/dist/esm/model-meta.js +149 -47
  17. package/dist/esm/model-meta.js.map +1 -1
  18. package/dist/esm/realtime/adapter.js +729 -812
  19. package/dist/esm/realtime/adapter.js.map +1 -1
  20. package/dist/esm/realtime/index.js +3 -0
  21. package/dist/esm/realtime/token.js +78 -72
  22. package/dist/esm/realtime/token.js.map +1 -1
  23. package/dist/esm/tools/index.js +57 -96
  24. package/dist/esm/tools/index.js.map +1 -1
  25. package/dist/esm/utils/audio.js +116 -162
  26. package/dist/esm/utils/audio.js.map +1 -1
  27. package/dist/esm/utils/client.js +22 -16
  28. package/dist/esm/utils/client.js.map +1 -1
  29. package/dist/esm/utils/index.js +5 -0
  30. package/dist/esm/utils/schema-converter.js +2 -0
  31. package/dist/esm/video/video-provider-options.js +83 -57
  32. package/dist/esm/video/video-provider-options.js.map +1 -1
  33. package/package.json +8 -8
  34. package/src/realtime/adapter.ts +1 -1
  35. package/src/utils/audio.ts +1 -1
  36. package/dist/esm/index.js.map +0 -1
@@ -1,237 +1,286 @@
1
+ import { getGrokApiKeyFromEnv, withGrokDefaults } from "../utils/client.js";
2
+ import { getGrokVideoDurationOptions, isImageToVideoOnlyModel, parseGrokVideoSize, validateVideoSize } from "../video/video-provider-options.js";
1
3
  import { resolveMediaPrompt } from "@tanstack/ai";
2
4
  import { BaseVideoAdapter, snapToDurationOption } from "@tanstack/ai/adapters";
3
5
  import { toRunErrorPayload } from "@tanstack/ai/adapter-internals";
4
- import { withGrokDefaults, getGrokApiKeyFromEnv } from "../utils/client.js";
5
- import { validateVideoSize, isImageToVideoOnlyModel, parseGrokVideoSize, getGrokVideoDurationOptions } from "../video/video-provider-options.js";
6
- const USD_TICKS_PER_DOLLAR = 1e10;
6
+ //#region src/adapters/video.ts
7
+ /**
8
+ * xAI bills video generation in "USD ticks": 10^10 ticks per US dollar
9
+ * (e.g. one grok-imagine-video-1.5 second costs $0.08 = 800_000_000 ticks).
10
+ */
11
+ var USD_TICKS_PER_DOLLAR = 1e10;
12
+ /**
13
+ * Convert a TanStack ImagePart to the URL string accepted by xAI's Imagine
14
+ * video endpoint: public URLs pass through (fetched by xAI's servers), data
15
+ * sources become base64 data URIs.
16
+ */
7
17
  function imagePartToUrl(part) {
8
- if (part.source.type === "url") return part.source.value;
9
- return `data:${part.source.mimeType};base64,${part.source.value}`;
18
+ if (part.source.type === "url") return part.source.value;
19
+ return `data:${part.source.mimeType};base64,${part.source.value}`;
10
20
  }
11
21
  function buildGrokVideoUsage(response) {
12
- const seconds = response.video?.duration;
13
- const ticks = response.usage?.cost_in_usd_ticks;
14
- if (seconds === void 0 && ticks === void 0) return void 0;
15
- return {
16
- promptTokens: 0,
17
- completionTokens: 0,
18
- totalTokens: 0,
19
- ...seconds !== void 0 && { unitsBilled: seconds },
20
- ...ticks !== void 0 && { cost: ticks / USD_TICKS_PER_DOLLAR }
21
- };
22
- }
23
- class GrokVideoAdapter extends BaseVideoAdapter {
24
- name = "grok";
25
- clientConfig;
26
- constructor(config, model) {
27
- super({}, model);
28
- this.clientConfig = withGrokDefaults(config);
29
- }
30
- get fetch() {
31
- return this.clientConfig.fetch ?? fetch;
32
- }
33
- async request(path, init) {
34
- return await this.fetch(`${this.clientConfig.baseURL}${path}`, {
35
- ...init,
36
- headers: {
37
- "Content-Type": "application/json",
38
- Authorization: `Bearer ${this.clientConfig.apiKey}`
39
- }
40
- });
41
- }
42
- /**
43
- * Reads the error message out of an Imagine API error body
44
- * (`{"code": "...", "error": "..."}`), falling back to the raw text.
45
- */
46
- async errorMessage(response) {
47
- const body = await response.text();
48
- try {
49
- const parsed = JSON.parse(body);
50
- if (typeof parsed === "object" && parsed !== null && "error" in parsed && typeof parsed.error === "string") {
51
- return parsed.error;
52
- }
53
- } catch {
54
- }
55
- return body;
56
- }
57
- async createVideoJob(options) {
58
- const { model, size, modelOptions, logger } = options;
59
- validateVideoSize(model, size);
60
- const rawDuration = modelOptions?.duration ?? options.duration;
61
- const duration = rawDuration !== void 0 ? this.snapDuration(rawDuration) : void 0;
62
- const resolved = resolveMediaPrompt(options.prompt);
63
- if (resolved.videos.length > 0) {
64
- throw new Error(
65
- `${this.name}.createVideoJob does not support video prompt parts (model: ${model}).`
66
- );
67
- }
68
- if (resolved.audios.length > 0) {
69
- throw new Error(
70
- `${this.name}.createVideoJob does not support audio prompt parts (model: ${model}).`
71
- );
72
- }
73
- if (resolved.images.length === 0 && isImageToVideoOnlyModel(model)) {
74
- throw new Error(
75
- `${this.name}: ${model} does not support text-to-video — it is image-to-video only. Include an image prompt part as the starting frame, or use 'grok-imagine-video' for text-to-video.`
76
- );
77
- }
78
- if (resolved.images.length > 1) {
79
- throw new Error(
80
- `${this.name}: ${model} accepts at most one starting-frame image; received ${resolved.images.length}.`
81
- );
82
- }
83
- const [startFrame] = resolved.images;
84
- const parsedSize = size !== void 0 ? parseGrokVideoSize(size) : void 0;
85
- const request = {
86
- model,
87
- prompt: resolved.text,
88
- ...startFrame && { image: { url: imagePartToUrl(startFrame) } },
89
- ...parsedSize && {
90
- aspect_ratio: parsedSize.aspectRatio,
91
- ...parsedSize.resolution !== void 0 && {
92
- resolution: parsedSize.resolution
93
- }
94
- },
95
- ...modelOptions,
96
- // Spread after modelOptions so the snapped duration is authoritative
97
- // (modelOptions.duration is folded into `duration` via snapDuration above).
98
- ...duration !== void 0 && { duration }
99
- };
100
- try {
101
- logger.request(
102
- `activity=video.create provider=${this.name} model=${model} size=${size ?? "default"} duration=${duration ?? "default"}`,
103
- { provider: this.name, model }
104
- );
105
- const response = await this.request("/videos/generations", {
106
- method: "POST",
107
- body: JSON.stringify(request)
108
- });
109
- if (!response.ok) {
110
- throw new Error(
111
- `grok: video generation request failed (${response.status} ${response.statusText}): ${await this.errorMessage(response)}`
112
- );
113
- }
114
- const result = await response.json();
115
- if (!result.request_id) {
116
- throw new Error(
117
- "grok: video generation response contained no request_id"
118
- );
119
- }
120
- return { jobId: result.request_id, model };
121
- } catch (error) {
122
- logger.errors(`${this.name}.createVideoJob fatal`, {
123
- error: toRunErrorPayload(error, `${this.name}.createVideoJob failed`),
124
- source: `${this.name}.createVideoJob`
125
- });
126
- throw error;
127
- }
128
- }
129
- async retrieveJob(jobId) {
130
- const response = await this.request(`/videos/${jobId}`);
131
- if (!response.ok) {
132
- const error = new Error(
133
- `grok: video status request failed (${response.status} ${response.statusText}): ${await this.errorMessage(response)}`
134
- );
135
- error.status = response.status;
136
- throw error;
137
- }
138
- return await response.json();
139
- }
140
- async getVideoStatus(jobId) {
141
- let response;
142
- try {
143
- response = await this.retrieveJob(jobId);
144
- } catch (error) {
145
- if (error.status === 404) {
146
- return { jobId, status: "failed", error: "Job not found" };
147
- }
148
- throw error;
149
- }
150
- return {
151
- jobId,
152
- status: this.mapStatus(response.status),
153
- ...response.progress !== void 0 && { progress: response.progress },
154
- ...response.error !== void 0 && { error: response.error }
155
- };
156
- }
157
- async getVideoUrl(jobId) {
158
- let response;
159
- try {
160
- response = await this.retrieveJob(jobId);
161
- } catch (error) {
162
- if (error.status === 404) {
163
- throw new Error(`Video job not found: ${jobId}`);
164
- }
165
- throw error;
166
- }
167
- const status = this.mapStatus(response.status);
168
- if (status === "failed") {
169
- throw new Error(
170
- `Video generation failed${response.error ? `: ${response.error}` : ""}. Job ID: ${jobId}`
171
- );
172
- }
173
- const url = response.video?.url;
174
- if (!url) {
175
- throw new Error(
176
- `Video is not ready for download. Check status first. Job ID: ${jobId}`
177
- );
178
- }
179
- const usage = buildGrokVideoUsage(response);
180
- return {
181
- jobId,
182
- url,
183
- ...usage && { usage }
184
- };
185
- }
186
- /**
187
- * Maps Imagine API job statuses onto the generic video status set. The
188
- * API reports 'pending' while queued/generating (with a numeric
189
- * `progress`), then a terminal 'done' / 'failed' / 'expired'.
190
- */
191
- mapStatus(apiStatus) {
192
- switch (apiStatus) {
193
- case "pending":
194
- case "queued":
195
- return "pending";
196
- case "done":
197
- case "completed":
198
- case "succeeded":
199
- return "completed";
200
- case "failed":
201
- case "expired":
202
- case "error":
203
- case "cancelled":
204
- return "failed";
205
- case void 0:
206
- default:
207
- return "processing";
208
- }
209
- }
210
- /**
211
- * Both grok-imagine video models accept a continuous 1–15 integer-second
212
- * range. Consumers can use this to render UI without provider knowledge.
213
- */
214
- availableDurations() {
215
- return getGrokVideoDurationOptions(this.model);
216
- }
217
- /**
218
- * Coerce a raw seconds value to the closest valid duration (clamped to
219
- * [1, 15] and rounded to whole seconds).
220
- */
221
- snapDuration(seconds) {
222
- return snapToDurationOption(seconds, this.availableDurations());
223
- }
22
+ const seconds = response.video?.duration;
23
+ const ticks = response.usage?.cost_in_usd_ticks;
24
+ if (seconds === void 0 && ticks === void 0) return void 0;
25
+ return {
26
+ promptTokens: 0,
27
+ completionTokens: 0,
28
+ totalTokens: 0,
29
+ ...seconds !== void 0 && { unitsBilled: seconds },
30
+ ...ticks !== void 0 && { cost: ticks / USD_TICKS_PER_DOLLAR }
31
+ };
224
32
  }
33
+ /**
34
+ * Grok Video Generation Adapter (xAI Imagine API)
35
+ *
36
+ * Tree-shakeable adapter for the grok-imagine video models using the
37
+ * async jobs/polling architecture: create a generation request, poll it,
38
+ * then read the completed video URL.
39
+ *
40
+ * `grok-imagine-video` (v1.0) supports text-to-video and image-to-video.
41
+ * `grok-imagine-video-1.5` is image-to-video only — every request needs an
42
+ * image prompt part as the starting frame, and the adapter rejects a
43
+ * text-only prompt with a clear error rather than a raw API 400.
44
+ *
45
+ * The Imagine video endpoints are not part of the OpenAI SDK surface (and
46
+ * xAI rejects the SDK's multipart paths), so requests are plain JSON calls
47
+ * issued with the configured `fetch` (or the global one).
48
+ *
49
+ * @experimental Video generation is an experimental feature and may change.
50
+ *
51
+ * Features:
52
+ * - Async job-based video generation (1–15 second clips with audio)
53
+ * - Aspect-ratio sizing via the "aspectRatio_resolution" size template
54
+ * (e.g. '16:9_720p'), consistent with the grok-imagine image models
55
+ * - Image-to-video via an `image` prompt part (starting frame URL or data URI)
56
+ * - Usage reporting: billed seconds (`unitsBilled`) and exact cost
57
+ */
58
+ var GrokVideoAdapter = class extends BaseVideoAdapter {
59
+ name = "grok";
60
+ clientConfig;
61
+ constructor(config, model) {
62
+ super({}, model);
63
+ this.clientConfig = withGrokDefaults(config);
64
+ }
65
+ get fetch() {
66
+ return this.clientConfig.fetch ?? fetch;
67
+ }
68
+ async request(path, init) {
69
+ return await this.fetch(`${this.clientConfig.baseURL}${path}`, {
70
+ ...init,
71
+ headers: {
72
+ "Content-Type": "application/json",
73
+ Authorization: `Bearer ${this.clientConfig.apiKey}`
74
+ }
75
+ });
76
+ }
77
+ /**
78
+ * Reads the error message out of an Imagine API error body
79
+ * (`{"code": "...", "error": "..."}`), falling back to the raw text.
80
+ */
81
+ async errorMessage(response) {
82
+ const body = await response.text();
83
+ try {
84
+ const parsed = JSON.parse(body);
85
+ if (typeof parsed === "object" && parsed !== null && "error" in parsed && typeof parsed.error === "string") return parsed.error;
86
+ } catch {}
87
+ return body;
88
+ }
89
+ async createVideoJob(options) {
90
+ const { model, size, modelOptions, logger } = options;
91
+ validateVideoSize(model, size);
92
+ const rawDuration = modelOptions?.duration ?? options.duration;
93
+ const duration = rawDuration !== void 0 ? this.snapDuration(rawDuration) : void 0;
94
+ const resolved = resolveMediaPrompt(options.prompt);
95
+ if (resolved.videos.length > 0) throw new Error(`${this.name}.createVideoJob does not support video prompt parts (model: ${model}).`);
96
+ if (resolved.audios.length > 0) throw new Error(`${this.name}.createVideoJob does not support audio prompt parts (model: ${model}).`);
97
+ if (resolved.images.length === 0 && isImageToVideoOnlyModel(model)) throw new Error(`${this.name}: ${model} does not support text-to-video — it is image-to-video only. Include an image prompt part as the starting frame, or use 'grok-imagine-video' for text-to-video.`);
98
+ if (resolved.images.length > 1) throw new Error(`${this.name}: ${model} accepts at most one starting-frame image; received ${resolved.images.length}.`);
99
+ const [startFrame] = resolved.images;
100
+ const parsedSize = size !== void 0 ? parseGrokVideoSize(size) : void 0;
101
+ const request = {
102
+ model,
103
+ prompt: resolved.text,
104
+ ...startFrame && { image: { url: imagePartToUrl(startFrame) } },
105
+ ...parsedSize && {
106
+ aspect_ratio: parsedSize.aspectRatio,
107
+ ...parsedSize.resolution !== void 0 && { resolution: parsedSize.resolution }
108
+ },
109
+ ...modelOptions,
110
+ ...duration !== void 0 && { duration }
111
+ };
112
+ try {
113
+ logger.request(`activity=video.create provider=${this.name} model=${model} size=${size ?? "default"} duration=${duration ?? "default"}`, {
114
+ provider: this.name,
115
+ model
116
+ });
117
+ const response = await this.request("/videos/generations", {
118
+ method: "POST",
119
+ body: JSON.stringify(request)
120
+ });
121
+ if (!response.ok) throw new Error(`grok: video generation request failed (${response.status} ${response.statusText}): ${await this.errorMessage(response)}`);
122
+ const result = await response.json();
123
+ if (!result.request_id) throw new Error("grok: video generation response contained no request_id");
124
+ return {
125
+ jobId: result.request_id,
126
+ model
127
+ };
128
+ } catch (error) {
129
+ logger.errors(`${this.name}.createVideoJob fatal`, {
130
+ error: toRunErrorPayload(error, `${this.name}.createVideoJob failed`),
131
+ source: `${this.name}.createVideoJob`
132
+ });
133
+ throw error;
134
+ }
135
+ }
136
+ async retrieveJob(jobId) {
137
+ const response = await this.request(`/videos/${jobId}`);
138
+ if (!response.ok) {
139
+ const error = /* @__PURE__ */ new Error(`grok: video status request failed (${response.status} ${response.statusText}): ${await this.errorMessage(response)}`);
140
+ error.status = response.status;
141
+ throw error;
142
+ }
143
+ return await response.json();
144
+ }
145
+ async getVideoStatus(jobId) {
146
+ let response;
147
+ try {
148
+ response = await this.retrieveJob(jobId);
149
+ } catch (error) {
150
+ if (error.status === 404) return {
151
+ jobId,
152
+ status: "failed",
153
+ error: "Job not found"
154
+ };
155
+ throw error;
156
+ }
157
+ return {
158
+ jobId,
159
+ status: this.mapStatus(response.status),
160
+ ...response.progress !== void 0 && { progress: response.progress },
161
+ ...response.error !== void 0 && { error: response.error }
162
+ };
163
+ }
164
+ async getVideoUrl(jobId) {
165
+ let response;
166
+ try {
167
+ response = await this.retrieveJob(jobId);
168
+ } catch (error) {
169
+ if (error.status === 404) throw new Error(`Video job not found: ${jobId}`);
170
+ throw error;
171
+ }
172
+ if (this.mapStatus(response.status) === "failed") throw new Error(`Video generation failed${response.error ? `: ${response.error}` : ""}. Job ID: ${jobId}`);
173
+ const url = response.video?.url;
174
+ if (!url) throw new Error(`Video is not ready for download. Check status first. Job ID: ${jobId}`);
175
+ const usage = buildGrokVideoUsage(response);
176
+ return {
177
+ jobId,
178
+ url,
179
+ ...usage && { usage }
180
+ };
181
+ }
182
+ /**
183
+ * Maps Imagine API job statuses onto the generic video status set. The
184
+ * API reports 'pending' while queued/generating (with a numeric
185
+ * `progress`), then a terminal 'done' / 'failed' / 'expired'.
186
+ */
187
+ mapStatus(apiStatus) {
188
+ switch (apiStatus) {
189
+ case "pending":
190
+ case "queued": return "pending";
191
+ case "done":
192
+ case "completed":
193
+ case "succeeded": return "completed";
194
+ case "failed":
195
+ case "expired":
196
+ case "error":
197
+ case "cancelled": return "failed";
198
+ case void 0:
199
+ default: return "processing";
200
+ }
201
+ }
202
+ /**
203
+ * Both grok-imagine video models accept a continuous 1–15 integer-second
204
+ * range. Consumers can use this to render UI without provider knowledge.
205
+ */
206
+ availableDurations() {
207
+ return getGrokVideoDurationOptions(this.model);
208
+ }
209
+ /**
210
+ * Coerce a raw seconds value to the closest valid duration (clamped to
211
+ * [1, 15] and rounded to whole seconds).
212
+ */
213
+ snapDuration(seconds) {
214
+ return snapToDurationOption(seconds, this.availableDurations());
215
+ }
216
+ };
217
+ /**
218
+ * Creates a Grok video adapter with an explicit API key.
219
+ * Type resolution happens here at the call site.
220
+ *
221
+ * @experimental Video generation is an experimental feature and may change.
222
+ *
223
+ * @param model - The model name (e.g., 'grok-imagine-video')
224
+ * @param apiKey - Your xAI API key
225
+ * @param config - Optional additional configuration
226
+ * @returns Configured Grok video adapter instance with resolved types
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * // grok-imagine-video (v1.0) supports text-to-video.
231
+ * const adapter = createGrokVideo('grok-imagine-video', 'xai-...');
232
+ *
233
+ * const { jobId } = await generateVideo({
234
+ * adapter,
235
+ * prompt: 'A beautiful sunset over the ocean',
236
+ * size: '16:9_720p',
237
+ * duration: 5
238
+ * });
239
+ * ```
240
+ */
225
241
  function createGrokVideo(model, apiKey, config) {
226
- return new GrokVideoAdapter({ apiKey, ...config }, model);
242
+ return new GrokVideoAdapter({
243
+ apiKey,
244
+ ...config
245
+ }, model);
227
246
  }
247
+ /**
248
+ * Creates a Grok video adapter with automatic API key detection from environment variables.
249
+ * Type resolution happens here at the call site.
250
+ *
251
+ * Looks for `XAI_API_KEY` in:
252
+ * - `process.env` (Node.js)
253
+ * - `window.env` (Browser with injected env)
254
+ *
255
+ * @experimental Video generation is an experimental feature and may change.
256
+ *
257
+ * @param model - The model name (e.g., 'grok-imagine-video-1.5')
258
+ * @param config - Optional configuration (excluding apiKey which is auto-detected)
259
+ * @returns Configured Grok video adapter instance with resolved types
260
+ * @throws Error if XAI_API_KEY is not found in environment
261
+ *
262
+ * @example
263
+ * ```typescript
264
+ * // Automatically uses XAI_API_KEY from environment
265
+ * const adapter = grokVideo('grok-imagine-video-1.5');
266
+ *
267
+ * // Image-to-video only: the prompt must carry a starting-frame image part.
268
+ * const { jobId } = await generateVideo({
269
+ * adapter,
270
+ * prompt: [
271
+ * { type: 'text', content: 'Make the cat start playing the piano' },
272
+ * { type: 'image', source: { type: 'url', value: 'https://example.com/cat.png' } },
273
+ * ],
274
+ * });
275
+ *
276
+ * // Poll for status
277
+ * const status = await getVideoJobStatus({ adapter, jobId });
278
+ * ```
279
+ */
228
280
  function grokVideo(model, config) {
229
- const apiKey = getGrokApiKeyFromEnv();
230
- return createGrokVideo(model, apiKey, config);
281
+ return createGrokVideo(model, getGrokApiKeyFromEnv(), config);
231
282
  }
232
- export {
233
- GrokVideoAdapter,
234
- createGrokVideo,
235
- grokVideo
236
- };
237
- //# sourceMappingURL=video.js.map
283
+ //#endregion
284
+ export { GrokVideoAdapter, createGrokVideo, grokVideo };
285
+
286
+ //# sourceMappingURL=video.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"video.js","sources":["../../../src/adapters/video.ts"],"sourcesContent":["import { resolveMediaPrompt } from '@tanstack/ai'\nimport { BaseVideoAdapter, snapToDurationOption } from '@tanstack/ai/adapters'\nimport { toRunErrorPayload } from '@tanstack/ai/adapter-internals'\nimport { getGrokApiKeyFromEnv, withGrokDefaults } from '../utils/client'\nimport {\n getGrokVideoDurationOptions,\n isImageToVideoOnlyModel,\n parseGrokVideoSize,\n validateVideoSize,\n} from '../video/video-provider-options'\nimport type { DurationOptions } from '@tanstack/ai/adapters'\nimport type {\n ImagePart,\n MediaInputMetadata,\n TokenUsage,\n VideoGenerationOptions,\n VideoJobResult,\n VideoStatusResult,\n VideoUrlResult,\n} from '@tanstack/ai'\nimport type { GrokVideoModel } from '../model-meta'\nimport type {\n GrokVideoModelDurationByName,\n GrokVideoModelInputModalitiesByName,\n GrokVideoModelProviderOptionsByName,\n GrokVideoModelSizeByName,\n GrokVideoProviderOptions,\n} from '../video/video-provider-options'\nimport type { GrokClientConfig } from '../utils/client'\n\n/**\n * Configuration for Grok video adapter.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport interface GrokVideoConfig extends GrokClientConfig {}\n\n/**\n * xAI bills video generation in \"USD ticks\": 10^10 ticks per US dollar\n * (e.g. one grok-imagine-video-1.5 second costs $0.08 = 800_000_000 ticks).\n */\nconst USD_TICKS_PER_DOLLAR = 10_000_000_000\n\n/** Response of POST /v1/videos/generations. */\ninterface GrokVideoCreateResponse {\n request_id?: string\n}\n\n/** Response of GET /v1/videos/{request_id}. */\ninterface GrokVideoStatusResponse {\n status?: string\n progress?: number\n model?: string\n video?: {\n url?: string\n duration?: number\n }\n usage?: {\n cost_in_usd_ticks?: number\n }\n error?: string\n}\n\n/**\n * Convert a TanStack ImagePart to the URL string accepted by xAI's Imagine\n * video endpoint: public URLs pass through (fetched by xAI's servers), data\n * sources become base64 data URIs.\n */\nfunction imagePartToUrl(part: ImagePart<MediaInputMetadata>): string {\n if (part.source.type === 'url') return part.source.value\n return `data:${part.source.mimeType};base64,${part.source.value}`\n}\n\nfunction buildGrokVideoUsage(\n response: GrokVideoStatusResponse,\n): TokenUsage | undefined {\n const seconds = response.video?.duration\n const ticks = response.usage?.cost_in_usd_ticks\n if (seconds === undefined && ticks === undefined) return undefined\n return {\n promptTokens: 0,\n completionTokens: 0,\n totalTokens: 0,\n ...(seconds !== undefined && { unitsBilled: seconds }),\n ...(ticks !== undefined && { cost: ticks / USD_TICKS_PER_DOLLAR }),\n }\n}\n\n/**\n * Grok Video Generation Adapter (xAI Imagine API)\n *\n * Tree-shakeable adapter for the grok-imagine video models using the\n * async jobs/polling architecture: create a generation request, poll it,\n * then read the completed video URL.\n *\n * `grok-imagine-video` (v1.0) supports text-to-video and image-to-video.\n * `grok-imagine-video-1.5` is image-to-video only — every request needs an\n * image prompt part as the starting frame, and the adapter rejects a\n * text-only prompt with a clear error rather than a raw API 400.\n *\n * The Imagine video endpoints are not part of the OpenAI SDK surface (and\n * xAI rejects the SDK's multipart paths), so requests are plain JSON calls\n * issued with the configured `fetch` (or the global one).\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * Features:\n * - Async job-based video generation (1–15 second clips with audio)\n * - Aspect-ratio sizing via the \"aspectRatio_resolution\" size template\n * (e.g. '16:9_720p'), consistent with the grok-imagine image models\n * - Image-to-video via an `image` prompt part (starting frame URL or data URI)\n * - Usage reporting: billed seconds (`unitsBilled`) and exact cost\n */\nexport class GrokVideoAdapter<\n TModel extends GrokVideoModel,\n> extends BaseVideoAdapter<\n TModel,\n GrokVideoProviderOptions,\n GrokVideoModelProviderOptionsByName,\n GrokVideoModelSizeByName,\n GrokVideoModelInputModalitiesByName,\n GrokVideoModelDurationByName\n> {\n readonly name = 'grok' as const\n\n private readonly clientConfig: GrokVideoConfig\n\n constructor(config: GrokVideoConfig, model: TModel) {\n super({}, model)\n this.clientConfig = withGrokDefaults(config)\n }\n\n private get fetch(): (\n input: string,\n init?: RequestInit,\n ) => Promise<Response> {\n return this.clientConfig.fetch ?? fetch\n }\n\n private async request(\n path: string,\n init?: Omit<RequestInit, 'headers'>,\n ): Promise<Response> {\n return await this.fetch(`${this.clientConfig.baseURL}${path}`, {\n ...init,\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.clientConfig.apiKey}`,\n },\n })\n }\n\n /**\n * Reads the error message out of an Imagine API error body\n * (`{\"code\": \"...\", \"error\": \"...\"}`), falling back to the raw text.\n */\n private async errorMessage(response: Response): Promise<string> {\n const body = await response.text()\n try {\n const parsed: unknown = JSON.parse(body)\n if (\n typeof parsed === 'object' &&\n parsed !== null &&\n 'error' in parsed &&\n typeof parsed.error === 'string'\n ) {\n return parsed.error\n }\n } catch {\n // not JSON — fall through to the raw body\n }\n return body\n }\n\n async createVideoJob(\n options: VideoGenerationOptions<\n GrokVideoProviderOptions,\n GrokVideoModelSizeByName[TModel],\n GrokVideoModelDurationByName[TModel]\n >,\n ): Promise<VideoJobResult> {\n const { model, size, modelOptions, logger } = options\n\n validateVideoSize(model, size)\n\n // Coerce the requested duration into the model's valid range (1–15s,\n // integer) instead of rejecting it — `snapDuration` clamps and rounds.\n // modelOptions wins over the generic `duration`, mirroring the size\n // precedence below.\n const rawDuration = modelOptions?.duration ?? options.duration\n const duration =\n rawDuration !== undefined ? this.snapDuration(rawDuration) : undefined\n\n // The interleaved prompt decomposes into verbatim text plus typed media\n // buckets. The Imagine video endpoint takes a text prompt and an optional\n // starting frame; reject the modalities it can't consume.\n const resolved = resolveMediaPrompt(options.prompt)\n if (resolved.videos.length > 0) {\n throw new Error(\n `${this.name}.createVideoJob does not support video prompt parts (model: ${model}).`,\n )\n }\n if (resolved.audios.length > 0) {\n throw new Error(\n `${this.name}.createVideoJob does not support audio prompt parts (model: ${model}).`,\n )\n }\n // grok-imagine-video-1.5 is image-to-video only — text-to-video is\n // rejected by the API, so fail fast with a clear, actionable message\n // pointing at the model that does support text-to-video.\n if (resolved.images.length === 0 && isImageToVideoOnlyModel(model)) {\n throw new Error(\n `${this.name}: ${model} does not support text-to-video — it is image-to-video only. ` +\n `Include an image prompt part as the starting frame, or use 'grok-imagine-video' for text-to-video.`,\n )\n }\n if (resolved.images.length > 1) {\n throw new Error(\n `${this.name}: ${model} accepts at most one starting-frame image; received ${resolved.images.length}.`,\n )\n }\n\n // Image-to-video: the single image prompt part becomes the starting frame\n // and the prompt text describes the desired motion. URL sources are\n // fetched by xAI's servers; data sources are sent as base64 data URIs.\n const [startFrame] = resolved.images\n\n // The generic `size` option carries an \"aspectRatio_resolution\" template\n // (e.g. '16:9_720p') and maps to the Imagine API's `aspect_ratio` /\n // `resolution` parameters; explicit modelOptions win over the template.\n const parsedSize = size !== undefined ? parseGrokVideoSize(size) : undefined\n const request = {\n model,\n prompt: resolved.text,\n ...(startFrame && { image: { url: imagePartToUrl(startFrame) } }),\n ...(parsedSize && {\n aspect_ratio: parsedSize.aspectRatio,\n ...(parsedSize.resolution !== undefined && {\n resolution: parsedSize.resolution,\n }),\n }),\n ...modelOptions,\n // Spread after modelOptions so the snapped duration is authoritative\n // (modelOptions.duration is folded into `duration` via snapDuration above).\n ...(duration !== undefined && { duration }),\n }\n\n try {\n logger.request(\n `activity=video.create provider=${this.name} model=${model} size=${size ?? 'default'} duration=${duration ?? 'default'}`,\n { provider: this.name, model },\n )\n\n const response = await this.request('/videos/generations', {\n method: 'POST',\n body: JSON.stringify(request),\n })\n if (!response.ok) {\n throw new Error(\n `grok: video generation request failed (${response.status} ${response.statusText}): ${await this.errorMessage(response)}`,\n )\n }\n\n const result = (await response.json()) as GrokVideoCreateResponse\n if (!result.request_id) {\n throw new Error(\n 'grok: video generation response contained no request_id',\n )\n }\n return { jobId: result.request_id, model }\n } catch (error: unknown) {\n logger.errors(`${this.name}.createVideoJob fatal`, {\n error: toRunErrorPayload(error, `${this.name}.createVideoJob failed`),\n source: `${this.name}.createVideoJob`,\n })\n throw error\n }\n }\n\n private async retrieveJob(jobId: string): Promise<GrokVideoStatusResponse> {\n const response = await this.request(`/videos/${jobId}`)\n if (!response.ok) {\n const error = new Error(\n `grok: video status request failed (${response.status} ${response.statusText}): ${await this.errorMessage(response)}`,\n )\n ;(error as { status?: number }).status = response.status\n throw error\n }\n return (await response.json()) as GrokVideoStatusResponse\n }\n\n async getVideoStatus(jobId: string): Promise<VideoStatusResult> {\n let response: GrokVideoStatusResponse\n try {\n response = await this.retrieveJob(jobId)\n } catch (error) {\n if ((error as { status?: number }).status === 404) {\n return { jobId, status: 'failed', error: 'Job not found' }\n }\n throw error\n }\n\n return {\n jobId,\n status: this.mapStatus(response.status),\n ...(response.progress !== undefined && { progress: response.progress }),\n ...(response.error !== undefined && { error: response.error }),\n }\n }\n\n async getVideoUrl(jobId: string): Promise<VideoUrlResult> {\n let response: GrokVideoStatusResponse\n try {\n response = await this.retrieveJob(jobId)\n } catch (error) {\n if ((error as { status?: number }).status === 404) {\n throw new Error(`Video job not found: ${jobId}`)\n }\n throw error\n }\n\n const status = this.mapStatus(response.status)\n if (status === 'failed') {\n throw new Error(\n `Video generation failed${response.error ? `: ${response.error}` : ''}. Job ID: ${jobId}`,\n )\n }\n const url = response.video?.url\n if (!url) {\n throw new Error(\n `Video is not ready for download. Check status first. Job ID: ${jobId}`,\n )\n }\n\n const usage = buildGrokVideoUsage(response)\n return {\n jobId,\n url,\n ...(usage && { usage }),\n }\n }\n\n /**\n * Maps Imagine API job statuses onto the generic video status set. The\n * API reports 'pending' while queued/generating (with a numeric\n * `progress`), then a terminal 'done' / 'failed' / 'expired'.\n */\n protected mapStatus(\n apiStatus: string | undefined,\n ): 'pending' | 'processing' | 'completed' | 'failed' {\n switch (apiStatus) {\n case 'pending':\n case 'queued':\n return 'pending'\n case 'done':\n case 'completed':\n case 'succeeded':\n return 'completed'\n case 'failed':\n case 'expired':\n case 'error':\n case 'cancelled':\n return 'failed'\n case undefined:\n default:\n return 'processing'\n }\n }\n\n /**\n * Both grok-imagine video models accept a continuous 1–15 integer-second\n * range. Consumers can use this to render UI without provider knowledge.\n */\n override availableDurations(): DurationOptions<\n GrokVideoModelDurationByName[TModel]\n > {\n return getGrokVideoDurationOptions(this.model)\n }\n\n /**\n * Coerce a raw seconds value to the closest valid duration (clamped to\n * [1, 15] and rounded to whole seconds).\n */\n override snapDuration(\n seconds: number,\n ): GrokVideoModelDurationByName[TModel] | undefined {\n return snapToDurationOption(seconds, this.availableDurations())\n }\n}\n\n/**\n * Creates a Grok video adapter with an explicit API key.\n * Type resolution happens here at the call site.\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * @param model - The model name (e.g., 'grok-imagine-video')\n * @param apiKey - Your xAI API key\n * @param config - Optional additional configuration\n * @returns Configured Grok video adapter instance with resolved types\n *\n * @example\n * ```typescript\n * // grok-imagine-video (v1.0) supports text-to-video.\n * const adapter = createGrokVideo('grok-imagine-video', 'xai-...');\n *\n * const { jobId } = await generateVideo({\n * adapter,\n * prompt: 'A beautiful sunset over the ocean',\n * size: '16:9_720p',\n * duration: 5\n * });\n * ```\n */\nexport function createGrokVideo<TModel extends GrokVideoModel>(\n model: TModel,\n apiKey: string,\n config?: Omit<GrokVideoConfig, 'apiKey'>,\n): GrokVideoAdapter<TModel> {\n return new GrokVideoAdapter({ apiKey, ...config }, model)\n}\n\n/**\n * Creates a Grok video adapter with automatic API key detection from environment variables.\n * Type resolution happens here at the call site.\n *\n * Looks for `XAI_API_KEY` in:\n * - `process.env` (Node.js)\n * - `window.env` (Browser with injected env)\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * @param model - The model name (e.g., 'grok-imagine-video-1.5')\n * @param config - Optional configuration (excluding apiKey which is auto-detected)\n * @returns Configured Grok video adapter instance with resolved types\n * @throws Error if XAI_API_KEY is not found in environment\n *\n * @example\n * ```typescript\n * // Automatically uses XAI_API_KEY from environment\n * const adapter = grokVideo('grok-imagine-video-1.5');\n *\n * // Image-to-video only: the prompt must carry a starting-frame image part.\n * const { jobId } = await generateVideo({\n * adapter,\n * prompt: [\n * { type: 'text', content: 'Make the cat start playing the piano' },\n * { type: 'image', source: { type: 'url', value: 'https://example.com/cat.png' } },\n * ],\n * });\n *\n * // Poll for status\n * const status = await getVideoJobStatus({ adapter, jobId });\n * ```\n */\nexport function grokVideo<TModel extends GrokVideoModel>(\n model: TModel,\n config?: Omit<GrokVideoConfig, 'apiKey'>,\n): GrokVideoAdapter<TModel> {\n const apiKey = getGrokApiKeyFromEnv()\n return createGrokVideo(model, apiKey, config)\n}\n"],"names":[],"mappings":";;;;;AAyCA,MAAM,uBAAuB;AA2B7B,SAAS,eAAe,MAA6C;AACnE,MAAI,KAAK,OAAO,SAAS,MAAO,QAAO,KAAK,OAAO;AACnD,SAAO,QAAQ,KAAK,OAAO,QAAQ,WAAW,KAAK,OAAO,KAAK;AACjE;AAEA,SAAS,oBACP,UACwB;AACxB,QAAM,UAAU,SAAS,OAAO;AAChC,QAAM,QAAQ,SAAS,OAAO;AAC9B,MAAI,YAAY,UAAa,UAAU,OAAW,QAAO;AACzD,SAAO;AAAA,IACL,cAAc;AAAA,IACd,kBAAkB;AAAA,IA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iBAAiB,EAAE,QAAQ,GAAG,OAAA,GAAU,KAAK;AAC1D;AAmCO,SAAS,UACd,OACA,QAC0B;AAC1B,QAAM,SAAS,qBAAA;AACf,SAAO,gBAAgB,OAAO,QAAQ,MAAM;AAC9C;"}
1
+ {"version":3,"file":"video.js","names":[],"sources":["../../../src/adapters/video.ts"],"sourcesContent":["import { resolveMediaPrompt } from '@tanstack/ai'\nimport { BaseVideoAdapter, snapToDurationOption } from '@tanstack/ai/adapters'\nimport { toRunErrorPayload } from '@tanstack/ai/adapter-internals'\nimport { getGrokApiKeyFromEnv, withGrokDefaults } from '../utils/client'\nimport {\n getGrokVideoDurationOptions,\n isImageToVideoOnlyModel,\n parseGrokVideoSize,\n validateVideoSize,\n} from '../video/video-provider-options'\nimport type { DurationOptions } from '@tanstack/ai/adapters'\nimport type {\n ImagePart,\n MediaInputMetadata,\n TokenUsage,\n VideoGenerationOptions,\n VideoJobResult,\n VideoStatusResult,\n VideoUrlResult,\n} from '@tanstack/ai'\nimport type { GrokVideoModel } from '../model-meta'\nimport type {\n GrokVideoModelDurationByName,\n GrokVideoModelInputModalitiesByName,\n GrokVideoModelProviderOptionsByName,\n GrokVideoModelSizeByName,\n GrokVideoProviderOptions,\n} from '../video/video-provider-options'\nimport type { GrokClientConfig } from '../utils/client'\n\n/**\n * Configuration for Grok video adapter.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport interface GrokVideoConfig extends GrokClientConfig {}\n\n/**\n * xAI bills video generation in \"USD ticks\": 10^10 ticks per US dollar\n * (e.g. one grok-imagine-video-1.5 second costs $0.08 = 800_000_000 ticks).\n */\nconst USD_TICKS_PER_DOLLAR = 10_000_000_000\n\n/** Response of POST /v1/videos/generations. */\ninterface GrokVideoCreateResponse {\n request_id?: string\n}\n\n/** Response of GET /v1/videos/{request_id}. */\ninterface GrokVideoStatusResponse {\n status?: string\n progress?: number\n model?: string\n video?: {\n url?: string\n duration?: number\n }\n usage?: {\n cost_in_usd_ticks?: number\n }\n error?: string\n}\n\n/**\n * Convert a TanStack ImagePart to the URL string accepted by xAI's Imagine\n * video endpoint: public URLs pass through (fetched by xAI's servers), data\n * sources become base64 data URIs.\n */\nfunction imagePartToUrl(part: ImagePart<MediaInputMetadata>): string {\n if (part.source.type === 'url') return part.source.value\n return `data:${part.source.mimeType};base64,${part.source.value}`\n}\n\nfunction buildGrokVideoUsage(\n response: GrokVideoStatusResponse,\n): TokenUsage | undefined {\n const seconds = response.video?.duration\n const ticks = response.usage?.cost_in_usd_ticks\n if (seconds === undefined && ticks === undefined) return undefined\n return {\n promptTokens: 0,\n completionTokens: 0,\n totalTokens: 0,\n ...(seconds !== undefined && { unitsBilled: seconds }),\n ...(ticks !== undefined && { cost: ticks / USD_TICKS_PER_DOLLAR }),\n }\n}\n\n/**\n * Grok Video Generation Adapter (xAI Imagine API)\n *\n * Tree-shakeable adapter for the grok-imagine video models using the\n * async jobs/polling architecture: create a generation request, poll it,\n * then read the completed video URL.\n *\n * `grok-imagine-video` (v1.0) supports text-to-video and image-to-video.\n * `grok-imagine-video-1.5` is image-to-video only — every request needs an\n * image prompt part as the starting frame, and the adapter rejects a\n * text-only prompt with a clear error rather than a raw API 400.\n *\n * The Imagine video endpoints are not part of the OpenAI SDK surface (and\n * xAI rejects the SDK's multipart paths), so requests are plain JSON calls\n * issued with the configured `fetch` (or the global one).\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * Features:\n * - Async job-based video generation (1–15 second clips with audio)\n * - Aspect-ratio sizing via the \"aspectRatio_resolution\" size template\n * (e.g. '16:9_720p'), consistent with the grok-imagine image models\n * - Image-to-video via an `image` prompt part (starting frame URL or data URI)\n * - Usage reporting: billed seconds (`unitsBilled`) and exact cost\n */\nexport class GrokVideoAdapter<\n TModel extends GrokVideoModel,\n> extends BaseVideoAdapter<\n TModel,\n GrokVideoProviderOptions,\n GrokVideoModelProviderOptionsByName,\n GrokVideoModelSizeByName,\n GrokVideoModelInputModalitiesByName,\n GrokVideoModelDurationByName\n> {\n readonly name = 'grok' as const\n\n private readonly clientConfig: GrokVideoConfig\n\n constructor(config: GrokVideoConfig, model: TModel) {\n super({}, model)\n this.clientConfig = withGrokDefaults(config)\n }\n\n private get fetch(): (\n input: string,\n init?: RequestInit,\n ) => Promise<Response> {\n return this.clientConfig.fetch ?? fetch\n }\n\n private async request(\n path: string,\n init?: Omit<RequestInit, 'headers'>,\n ): Promise<Response> {\n return await this.fetch(`${this.clientConfig.baseURL}${path}`, {\n ...init,\n headers: {\n 'Content-Type': 'application/json',\n Authorization: `Bearer ${this.clientConfig.apiKey}`,\n },\n })\n }\n\n /**\n * Reads the error message out of an Imagine API error body\n * (`{\"code\": \"...\", \"error\": \"...\"}`), falling back to the raw text.\n */\n private async errorMessage(response: Response): Promise<string> {\n const body = await response.text()\n try {\n const parsed: unknown = JSON.parse(body)\n if (\n typeof parsed === 'object' &&\n parsed !== null &&\n 'error' in parsed &&\n typeof parsed.error === 'string'\n ) {\n return parsed.error\n }\n } catch {\n // not JSON — fall through to the raw body\n }\n return body\n }\n\n async createVideoJob(\n options: VideoGenerationOptions<\n GrokVideoProviderOptions,\n GrokVideoModelSizeByName[TModel],\n GrokVideoModelDurationByName[TModel]\n >,\n ): Promise<VideoJobResult> {\n const { model, size, modelOptions, logger } = options\n\n validateVideoSize(model, size)\n\n // Coerce the requested duration into the model's valid range (1–15s,\n // integer) instead of rejecting it — `snapDuration` clamps and rounds.\n // modelOptions wins over the generic `duration`, mirroring the size\n // precedence below.\n const rawDuration = modelOptions?.duration ?? options.duration\n const duration =\n rawDuration !== undefined ? this.snapDuration(rawDuration) : undefined\n\n // The interleaved prompt decomposes into verbatim text plus typed media\n // buckets. The Imagine video endpoint takes a text prompt and an optional\n // starting frame; reject the modalities it can't consume.\n const resolved = resolveMediaPrompt(options.prompt)\n if (resolved.videos.length > 0) {\n throw new Error(\n `${this.name}.createVideoJob does not support video prompt parts (model: ${model}).`,\n )\n }\n if (resolved.audios.length > 0) {\n throw new Error(\n `${this.name}.createVideoJob does not support audio prompt parts (model: ${model}).`,\n )\n }\n // grok-imagine-video-1.5 is image-to-video only — text-to-video is\n // rejected by the API, so fail fast with a clear, actionable message\n // pointing at the model that does support text-to-video.\n if (resolved.images.length === 0 && isImageToVideoOnlyModel(model)) {\n throw new Error(\n `${this.name}: ${model} does not support text-to-video — it is image-to-video only. ` +\n `Include an image prompt part as the starting frame, or use 'grok-imagine-video' for text-to-video.`,\n )\n }\n if (resolved.images.length > 1) {\n throw new Error(\n `${this.name}: ${model} accepts at most one starting-frame image; received ${resolved.images.length}.`,\n )\n }\n\n // Image-to-video: the single image prompt part becomes the starting frame\n // and the prompt text describes the desired motion. URL sources are\n // fetched by xAI's servers; data sources are sent as base64 data URIs.\n const [startFrame] = resolved.images\n\n // The generic `size` option carries an \"aspectRatio_resolution\" template\n // (e.g. '16:9_720p') and maps to the Imagine API's `aspect_ratio` /\n // `resolution` parameters; explicit modelOptions win over the template.\n const parsedSize = size !== undefined ? parseGrokVideoSize(size) : undefined\n const request = {\n model,\n prompt: resolved.text,\n ...(startFrame && { image: { url: imagePartToUrl(startFrame) } }),\n ...(parsedSize && {\n aspect_ratio: parsedSize.aspectRatio,\n ...(parsedSize.resolution !== undefined && {\n resolution: parsedSize.resolution,\n }),\n }),\n ...modelOptions,\n // Spread after modelOptions so the snapped duration is authoritative\n // (modelOptions.duration is folded into `duration` via snapDuration above).\n ...(duration !== undefined && { duration }),\n }\n\n try {\n logger.request(\n `activity=video.create provider=${this.name} model=${model} size=${size ?? 'default'} duration=${duration ?? 'default'}`,\n { provider: this.name, model },\n )\n\n const response = await this.request('/videos/generations', {\n method: 'POST',\n body: JSON.stringify(request),\n })\n if (!response.ok) {\n throw new Error(\n `grok: video generation request failed (${response.status} ${response.statusText}): ${await this.errorMessage(response)}`,\n )\n }\n\n const result = (await response.json()) as GrokVideoCreateResponse\n if (!result.request_id) {\n throw new Error(\n 'grok: video generation response contained no request_id',\n )\n }\n return { jobId: result.request_id, model }\n } catch (error: unknown) {\n logger.errors(`${this.name}.createVideoJob fatal`, {\n error: toRunErrorPayload(error, `${this.name}.createVideoJob failed`),\n source: `${this.name}.createVideoJob`,\n })\n throw error\n }\n }\n\n private async retrieveJob(jobId: string): Promise<GrokVideoStatusResponse> {\n const response = await this.request(`/videos/${jobId}`)\n if (!response.ok) {\n const error = new Error(\n `grok: video status request failed (${response.status} ${response.statusText}): ${await this.errorMessage(response)}`,\n )\n ;(error as { status?: number }).status = response.status\n throw error\n }\n return (await response.json()) as GrokVideoStatusResponse\n }\n\n async getVideoStatus(jobId: string): Promise<VideoStatusResult> {\n let response: GrokVideoStatusResponse\n try {\n response = await this.retrieveJob(jobId)\n } catch (error) {\n if ((error as { status?: number }).status === 404) {\n return { jobId, status: 'failed', error: 'Job not found' }\n }\n throw error\n }\n\n return {\n jobId,\n status: this.mapStatus(response.status),\n ...(response.progress !== undefined && { progress: response.progress }),\n ...(response.error !== undefined && { error: response.error }),\n }\n }\n\n async getVideoUrl(jobId: string): Promise<VideoUrlResult> {\n let response: GrokVideoStatusResponse\n try {\n response = await this.retrieveJob(jobId)\n } catch (error) {\n if ((error as { status?: number }).status === 404) {\n throw new Error(`Video job not found: ${jobId}`)\n }\n throw error\n }\n\n const status = this.mapStatus(response.status)\n if (status === 'failed') {\n throw new Error(\n `Video generation failed${response.error ? `: ${response.error}` : ''}. Job ID: ${jobId}`,\n )\n }\n const url = response.video?.url\n if (!url) {\n throw new Error(\n `Video is not ready for download. Check status first. Job ID: ${jobId}`,\n )\n }\n\n const usage = buildGrokVideoUsage(response)\n return {\n jobId,\n url,\n ...(usage && { usage }),\n }\n }\n\n /**\n * Maps Imagine API job statuses onto the generic video status set. The\n * API reports 'pending' while queued/generating (with a numeric\n * `progress`), then a terminal 'done' / 'failed' / 'expired'.\n */\n protected mapStatus(\n apiStatus: string | undefined,\n ): 'pending' | 'processing' | 'completed' | 'failed' {\n switch (apiStatus) {\n case 'pending':\n case 'queued':\n return 'pending'\n case 'done':\n case 'completed':\n case 'succeeded':\n return 'completed'\n case 'failed':\n case 'expired':\n case 'error':\n case 'cancelled':\n return 'failed'\n case undefined:\n default:\n return 'processing'\n }\n }\n\n /**\n * Both grok-imagine video models accept a continuous 1–15 integer-second\n * range. Consumers can use this to render UI without provider knowledge.\n */\n override availableDurations(): DurationOptions<\n GrokVideoModelDurationByName[TModel]\n > {\n return getGrokVideoDurationOptions(this.model)\n }\n\n /**\n * Coerce a raw seconds value to the closest valid duration (clamped to\n * [1, 15] and rounded to whole seconds).\n */\n override snapDuration(\n seconds: number,\n ): GrokVideoModelDurationByName[TModel] | undefined {\n return snapToDurationOption(seconds, this.availableDurations())\n }\n}\n\n/**\n * Creates a Grok video adapter with an explicit API key.\n * Type resolution happens here at the call site.\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * @param model - The model name (e.g., 'grok-imagine-video')\n * @param apiKey - Your xAI API key\n * @param config - Optional additional configuration\n * @returns Configured Grok video adapter instance with resolved types\n *\n * @example\n * ```typescript\n * // grok-imagine-video (v1.0) supports text-to-video.\n * const adapter = createGrokVideo('grok-imagine-video', 'xai-...');\n *\n * const { jobId } = await generateVideo({\n * adapter,\n * prompt: 'A beautiful sunset over the ocean',\n * size: '16:9_720p',\n * duration: 5\n * });\n * ```\n */\nexport function createGrokVideo<TModel extends GrokVideoModel>(\n model: TModel,\n apiKey: string,\n config?: Omit<GrokVideoConfig, 'apiKey'>,\n): GrokVideoAdapter<TModel> {\n return new GrokVideoAdapter({ apiKey, ...config }, model)\n}\n\n/**\n * Creates a Grok video adapter with automatic API key detection from environment variables.\n * Type resolution happens here at the call site.\n *\n * Looks for `XAI_API_KEY` in:\n * - `process.env` (Node.js)\n * - `window.env` (Browser with injected env)\n *\n * @experimental Video generation is an experimental feature and may change.\n *\n * @param model - The model name (e.g., 'grok-imagine-video-1.5')\n * @param config - Optional configuration (excluding apiKey which is auto-detected)\n * @returns Configured Grok video adapter instance with resolved types\n * @throws Error if XAI_API_KEY is not found in environment\n *\n * @example\n * ```typescript\n * // Automatically uses XAI_API_KEY from environment\n * const adapter = grokVideo('grok-imagine-video-1.5');\n *\n * // Image-to-video only: the prompt must carry a starting-frame image part.\n * const { jobId } = await generateVideo({\n * adapter,\n * prompt: [\n * { type: 'text', content: 'Make the cat start playing the piano' },\n * { type: 'image', source: { type: 'url', value: 'https://example.com/cat.png' } },\n * ],\n * });\n *\n * // Poll for status\n * const status = await getVideoJobStatus({ adapter, jobId });\n * ```\n */\nexport function grokVideo<TModel extends GrokVideoModel>(\n model: TModel,\n config?: Omit<GrokVideoConfig, 'apiKey'>,\n): GrokVideoAdapter<TModel> {\n const apiKey = getGrokApiKeyFromEnv()\n return createGrokVideo(model, apiKey, config)\n}\n"],"mappings":";;;;;;;;;;AAyCA,IAAM,uBAAuB;;;;;;AA2B7B,SAAS,eAAe,MAA6C;CACnE,IAAI,KAAK,OAAO,SAAS,OAAO,OAAO,KAAK,OAAO;CACnD,OAAO,QAAQ,KAAK,OAAO,SAAS,UAAU,KAAK,OAAO;AAC5D;AAEA,SAAS,oBACP,UACwB;CACxB,MAAM,UAAU,SAAS,OAAO;CAChC,MAAM,QAAQ,SAAS,OAAO;CAC9B,IAAI,YAAY,KAAA,KAAa,UAAU,KAAA,GAAW,OAAO,KAAA;CACzD,OAAO;EACL,cAAc;EACd,kBAAkB;EAClB,aAAa;EACb,GAAI,YAAY,KAAA,KAAa,EAAE,aAAa,QAAQ;EACpD,GAAI,UAAU,KAAA,KAAa,EAAE,MAAM,QAAQ,qBAAqB;CAClE;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,IAAa,mBAAb,cAEU,iBAOR;CACA,OAAgB;CAEhB;CAEA,YAAY,QAAyB,OAAe;EAClD,MAAM,CAAC,GAAG,KAAK;EACf,KAAK,eAAe,iBAAiB,MAAM;CAC7C;CAEA,IAAY,QAGW;EACrB,OAAO,KAAK,aAAa,SAAS;CACpC;CAEA,MAAc,QACZ,MACA,MACmB;EACnB,OAAO,MAAM,KAAK,MAAM,GAAG,KAA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