@tanstack/ai-grok 0.14.10 → 0.15.0
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/dist/esm/adapters/image.js +1 -1
- package/dist/esm/adapters/image.js.map +1 -1
- package/dist/esm/adapters/tts.js +2 -1
- package/dist/esm/adapters/tts.js.map +1 -1
- package/dist/esm/adapters/video.d.ts +33 -11
- package/dist/esm/adapters/video.js +125 -27
- package/dist/esm/adapters/video.js.map +1 -1
- package/dist/esm/image/image-provider-options.d.ts +17 -2
- package/dist/esm/image/image-provider-options.js.map +1 -1
- package/dist/esm/index.d.ts +3 -3
- package/dist/esm/index.js +2 -2
- package/dist/esm/model-meta.d.ts +49 -3
- package/dist/esm/model-meta.js +110 -8
- package/dist/esm/model-meta.js.map +1 -1
- package/dist/esm/realtime/adapter.js +17 -16
- package/dist/esm/realtime/adapter.js.map +1 -1
- package/dist/esm/realtime/token.d.ts +1 -1
- package/dist/esm/realtime/token.js +3 -2
- package/dist/esm/realtime/token.js.map +1 -1
- package/dist/esm/realtime/types.d.ts +1 -1
- package/dist/esm/tools/index.js.map +1 -1
- package/dist/esm/video/video-provider-options.d.ts +131 -21
- package/dist/esm/video/video-provider-options.js +36 -10
- package/dist/esm/video/video-provider-options.js.map +1 -1
- package/package.json +7 -7
- package/src/adapters/image.ts +2 -1
- package/src/adapters/video.ts +316 -51
- package/src/image/image-provider-options.ts +18 -2
- package/src/index.ts +7 -0
- package/src/model-meta.ts +109 -6
- package/src/realtime/adapter.ts +3 -2
- package/src/realtime/token.ts +4 -2
- package/src/realtime/types.ts +1 -1
- package/src/video/video-provider-options.ts +198 -34
|
@@ -28,6 +28,15 @@ function parseGrokVideoSize(size) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
+
* Models that accept native 1080p on text-to-video and image-to-video.
|
|
32
|
+
* Reference-to-video stays capped at 720p even on these models.
|
|
33
|
+
*
|
|
34
|
+
* @experimental Video generation is an experimental feature and may change.
|
|
35
|
+
*/
|
|
36
|
+
function isGrokVideoNative1080pModel(model) {
|
|
37
|
+
return model === "grok-imagine-video-1.5";
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
31
40
|
* Validate the `size` template for a given grok video model.
|
|
32
41
|
*
|
|
33
42
|
* @experimental Video generation is an experimental feature and may change.
|
|
@@ -37,6 +46,7 @@ function validateVideoSize(model, size) {
|
|
|
37
46
|
const parsed = parseGrokVideoSize(size);
|
|
38
47
|
if (!parsed || !GROK_VIDEO_ASPECT_RATIOS.includes(parsed.aspectRatio)) throw new Error(`Size "${size}" is not supported by model "${model}". Expected "aspectRatio" or "aspectRatio_resolution" (e.g. "16:9_720p") with aspect ratio one of: ${GROK_VIDEO_ASPECT_RATIOS.join(", ")}`);
|
|
39
48
|
if (parsed.resolution !== void 0 && !GROK_VIDEO_RESOLUTIONS.includes(parsed.resolution)) throw new Error(`Resolution "${parsed.resolution}" is not supported by model "${model}". Supported resolutions: ${GROK_VIDEO_RESOLUTIONS.join(", ")}`);
|
|
49
|
+
if (parsed.resolution === "1080p" && !isGrokVideoNative1080pModel(model)) throw new Error(`Resolution "1080p" is not supported by model "${model}". Use 'grok-imagine-video-1.5' for native 1080p text-to-video / image-to-video.`);
|
|
40
50
|
}
|
|
41
51
|
/**
|
|
42
52
|
* Runtime duration table backing `availableDurations()` / `snapDuration()`.
|
|
@@ -70,24 +80,40 @@ function getGrokVideoDurationOptions(model) {
|
|
|
70
80
|
return GROK_VIDEO_DURATIONS[model];
|
|
71
81
|
}
|
|
72
82
|
/**
|
|
73
|
-
* Models that
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
*
|
|
83
|
+
* Models that support reference-to-video inputs (`reference_images` /
|
|
84
|
+
* `reference_audios`). The per-model provider-options map hides the fields
|
|
85
|
+
* from other models at compile time; this backs the runtime gate for
|
|
86
|
+
* untyped callers (e.g. deserialized JSON) so they get a clear error
|
|
87
|
+
* instead of a raw API 400.
|
|
88
|
+
*
|
|
89
|
+
* @experimental Video generation is an experimental feature and may change.
|
|
90
|
+
*/
|
|
91
|
+
var GROK_VIDEO_REFERENCE_MODELS = /* @__PURE__ */ new Set(["grok-imagine-video-1.5"]);
|
|
92
|
+
/**
|
|
93
|
+
* True when the model accepts reference-to-video inputs.
|
|
94
|
+
*
|
|
95
|
+
* @experimental Video generation is an experimental feature and may change.
|
|
96
|
+
*/
|
|
97
|
+
function isGrokVideoReferenceModel(model) {
|
|
98
|
+
return GROK_VIDEO_REFERENCE_MODELS.has(model);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Models that accept a source-video prompt part for `/v1/videos/edits`
|
|
102
|
+
* and `/v1/videos/extensions`. xAI lists video input only on
|
|
103
|
+
* grok-imagine-video (v1.0).
|
|
77
104
|
*
|
|
78
105
|
* @experimental Video generation is an experimental feature and may change.
|
|
79
106
|
*/
|
|
80
|
-
var
|
|
107
|
+
var GROK_VIDEO_SOURCE_MODELS = /* @__PURE__ */ new Set(["grok-imagine-video"]);
|
|
81
108
|
/**
|
|
82
|
-
* True when the model
|
|
83
|
-
* required).
|
|
109
|
+
* True when the model accepts edit / extend source-video jobs.
|
|
84
110
|
*
|
|
85
111
|
* @experimental Video generation is an experimental feature and may change.
|
|
86
112
|
*/
|
|
87
|
-
function
|
|
88
|
-
return
|
|
113
|
+
function isGrokVideoSourceModel(model) {
|
|
114
|
+
return GROK_VIDEO_SOURCE_MODELS.has(model);
|
|
89
115
|
}
|
|
90
116
|
//#endregion
|
|
91
|
-
export { GROK_VIDEO_DURATIONS, getGrokVideoDurationOptions,
|
|
117
|
+
export { GROK_VIDEO_DURATIONS, getGrokVideoDurationOptions, isGrokVideoNative1080pModel, isGrokVideoReferenceModel, isGrokVideoSourceModel, parseGrokVideoSize, validateVideoSize };
|
|
92
118
|
|
|
93
119
|
//# sourceMappingURL=video-provider-options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"video-provider-options.js","names":[],"sources":["../../../src/video/video-provider-options.ts"],"sourcesContent":["/**\n * Grok Video Generation Provider Options (xAI Imagine API)\n *\n * Based on https://docs.x.ai/docs/guides/video-generations\n *\n * @experimental Video generation is an experimental feature and may change.\n */\n\nimport type { DurationOptions } from '@tanstack/ai/adapters'\nimport type { GrokVideoModel } from '../model-meta'\n\n/**\n * Aspect ratios accepted by the grok-imagine video models.\n *\n * Note: this is a narrower set than the grok-imagine image models — the\n * video endpoint rejects the phone-screen ratios ('9:19.5', '9:20', …) and\n * 'auto'.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoAspectRatio =\n | '1:1'\n | '16:9'\n | '9:16'\n | '4:3'\n | '3:4'\n | '3:2'\n | '2:3'\n\n/**\n * Resolution tiers for the grok-imagine video models.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoResolution = '480p' | '720p' | '1080p'\n\n/**\n * Size strings for grok-imagine video models. The Imagine API is\n * aspect-ratio based rather than pixel-size based; like the grok-imagine\n * image models, the generic `size` option uses an\n * `aspectRatio_resolution` template (\"16:9_720p\") — the resolution suffix\n * is optional (\"16:9\" uses the API default).\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoSize =\n | GrokVideoAspectRatio\n | `${GrokVideoAspectRatio}_${GrokVideoResolution}`\n\nconst GROK_VIDEO_ASPECT_RATIOS: ReadonlyArray<string> = [\n '1:1',\n '16:9',\n '9:16',\n '4:3',\n '3:4',\n '3:2',\n '2:3',\n]\n\nconst GROK_VIDEO_RESOLUTIONS: ReadonlyArray<string> = ['480p', '720p', '1080p']\n\n/**\n * Video duration limits enforced by the Imagine API (seconds).\n */\nexport const GROK_VIDEO_MIN_DURATION = 1\nexport const GROK_VIDEO_MAX_DURATION = 15\n\n/**\n * Parses a grok video size string into its components.\n * Format: \"aspectRatio\" or \"aspectRatio_resolution\",\n * e.g. \"16:9_720p\" → { aspectRatio: \"16:9\", resolution: \"720p\" }.\n * Returns undefined when the string doesn't match the template.\n */\nexport function parseGrokVideoSize(\n size: string,\n): { aspectRatio: string; resolution?: string } | undefined {\n const match = size.match(/^([\\d.]+:[\\d.]+)(?:_(.+))?$/)\n const [, aspectRatio, resolution] = match ?? []\n if (aspectRatio === undefined) return undefined\n return { aspectRatio, ...(resolution !== undefined && { resolution }) }\n}\n\n/**\n * Validate the `size` template for a given grok video model.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport function validateVideoSize(\n model: string,\n size?: string,\n): asserts size is GrokVideoSize | undefined {\n if (size === undefined) return\n const parsed = parseGrokVideoSize(size)\n if (!parsed || !GROK_VIDEO_ASPECT_RATIOS.includes(parsed.aspectRatio)) {\n throw new Error(\n `Size \"${size}\" is not supported by model \"${model}\". Expected ` +\n `\"aspectRatio\" or \"aspectRatio_resolution\" (e.g. \"16:9_720p\") with ` +\n `aspect ratio one of: ${GROK_VIDEO_ASPECT_RATIOS.join(', ')}`,\n )\n }\n if (\n parsed.resolution !== undefined &&\n !GROK_VIDEO_RESOLUTIONS.includes(parsed.resolution)\n ) {\n throw new Error(\n `Resolution \"${parsed.resolution}\" is not supported by model \"${model}\". ` +\n `Supported resolutions: ${GROK_VIDEO_RESOLUTIONS.join(', ')}`,\n )\n }\n}\n\n/**\n * Per-model duration type. The Imagine API accepts any integer second in the\n * 1–15 range, so this is a continuous range expressed as `number` (a literal\n * union can't represent it). `snapDuration()` coerces a raw seconds value into\n * the valid range at runtime.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoModelDurationByName = {\n 'grok-imagine-video': number\n 'grok-imagine-video-1.5': number\n}\n\n/**\n * Runtime duration table backing `availableDurations()` / `snapDuration()`.\n * Both grok-imagine video models accept the same continuous 1–15 integer-second\n * range.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport const GROK_VIDEO_DURATIONS: {\n readonly [TModel in GrokVideoModel]: DurationOptions<\n GrokVideoModelDurationByName[TModel]\n >\n} = {\n 'grok-imagine-video': {\n kind: 'range',\n min: GROK_VIDEO_MIN_DURATION,\n max: GROK_VIDEO_MAX_DURATION,\n step: 1,\n unit: 'seconds',\n },\n 'grok-imagine-video-1.5': {\n kind: 'range',\n min: GROK_VIDEO_MIN_DURATION,\n max: GROK_VIDEO_MAX_DURATION,\n step: 1,\n unit: 'seconds',\n },\n}\n\n/**\n * Look up the duration options for a grok video model.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport function getGrokVideoDurationOptions<TModel extends GrokVideoModel>(\n model: TModel,\n): DurationOptions<GrokVideoModelDurationByName[TModel]> {\n return GROK_VIDEO_DURATIONS[model]\n}\n\n/**\n * Provider-specific options for grok video generation. These map directly\n * onto the Imagine API request body and take precedence over the generic\n * `size` / `duration` options when both are provided.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport interface GrokVideoProviderOptions {\n /**\n * Output aspect ratio.\n */\n aspect_ratio?: GrokVideoAspectRatio\n\n /**\n * Output resolution tier.\n */\n resolution?: GrokVideoResolution\n\n /**\n * Video duration in integer seconds (1–15).\n */\n duration?: number\n}\n\n/**\n * Type-only map from model name to its specific provider options.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoModelProviderOptionsByName = {\n 'grok-imagine-video': GrokVideoProviderOptions\n 'grok-imagine-video-1.5': GrokVideoProviderOptions\n}\n\n/**\n * Type-only map from model name to its supported `size` strings.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoModelSizeByName = {\n 'grok-imagine-video': GrokVideoSize\n 'grok-imagine-video-1.5': GrokVideoSize\n}\n\n/**\n * Type-only map from model name to the non-text prompt modalities it accepts.\n * Both models accept an `image` prompt part as the starting frame:\n * `grok-imagine-video` (v1.0) does text-to-video and image-to-video, while\n * `grok-imagine-video-1.5` is image-to-video only (the image is required).\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoModelInputModalitiesByName = {\n 'grok-imagine-video': readonly ['image']\n 'grok-imagine-video-1.5': readonly ['image']\n}\n\n/**\n * Models that only support image-to-video — a starting-frame image is\n * required and text-to-video is rejected by the Imagine API. Used by the\n * adapter to fail fast with a clear message instead of surfacing the raw\n * \"Text-to-video is not supported for this model\" 400.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nconst GROK_VIDEO_IMAGE_TO_VIDEO_ONLY: ReadonlySet<string> = new Set([\n 'grok-imagine-video-1.5',\n])\n\n/**\n * True when the model only supports image-to-video (a starting frame is\n * required).\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport function isImageToVideoOnlyModel(model: string): boolean {\n return GROK_VIDEO_IMAGE_TO_VIDEO_ONLY.has(model)\n}\n"],"mappings":";AAiDA,IAAM,2BAAkD;CACtD;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,IAAM,yBAAgD;CAAC;CAAQ;CAAQ;AAAO;;;;;;;AAc9E,SAAgB,mBACd,MAC0D;CAE1D,MAAM,GAAG,aAAa,cADR,KAAK,MAAM,6BACW,KAAS,CAAC;CAC9C,IAAI,gBAAgB,KAAA,GAAW,OAAO,KAAA;CACtC,OAAO;EAAE;EAAa,GAAI,eAAe,KAAA,KAAa,EAAE,WAAW;CAAG;AACxE;;;;;;AAOA,SAAgB,kBACd,OACA,MAC2C;CAC3C,IAAI,SAAS,KAAA,GAAW;CACxB,MAAM,SAAS,mBAAmB,IAAI;CACtC,IAAI,CAAC,UAAU,CAAC,yBAAyB,SAAS,OAAO,WAAW,GAClE,MAAM,IAAI,MACR,SAAS,KAAK,+BAA+B,MAAM,qGAEzB,yBAAyB,KAAK,IAAI,GAC9D;CAEF,IACE,OAAO,eAAe,KAAA,KACtB,CAAC,uBAAuB,SAAS,OAAO,UAAU,GAElD,MAAM,IAAI,MACR,eAAe,OAAO,WAAW,+BAA+B,MAAM,4BAC1C,uBAAuB,KAAK,IAAI,GAC9D;AAEJ;;;;;;;;AAsBA,IAAa,uBAIT;CACF,sBAAsB;EACpB,MAAM;EACN,KAAA;EACA,KAAA;EACA,MAAM;EACN,MAAM;CACR;CACA,0BAA0B;EACxB,MAAM;EACN,KAAA;EACA,KAAA;EACA,MAAM;EACN,MAAM;CACR;AACF;;;;;;AAOA,SAAgB,4BACd,OACuD;CACvD,OAAO,qBAAqB;AAC9B;;;;;;;;;AAmEA,IAAM,iDAAsD,IAAI,IAAI,CAClE,wBACF,CAAC;;;;;;;AAQD,SAAgB,wBAAwB,OAAwB;CAC9D,OAAO,+BAA+B,IAAI,KAAK;AACjD"}
|
|
1
|
+
{"version":3,"file":"video-provider-options.js","names":[],"sources":["../../../src/video/video-provider-options.ts"],"sourcesContent":["/**\n * Grok Video Generation Provider Options (xAI Imagine API)\n *\n * Based on https://docs.x.ai/developers/model-capabilities/video/generation\n * (plus the image-to-video, reference-to-video, editing, and extension pages\n * under the same section).\n *\n * @experimental Video generation is an experimental feature and may change.\n */\n\nimport type { DurationOptions } from '@tanstack/ai/adapters'\nimport type { GrokVideoModel } from '../model-meta'\n\n/**\n * Aspect ratios accepted by the grok-imagine video models.\n *\n * Note: this is a narrower set than the grok-imagine image models — the\n * video endpoint rejects the phone-screen ratios ('9:19.5', '9:20', …) and\n * 'auto'.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoAspectRatio =\n | '1:1'\n | '16:9'\n | '9:16'\n | '4:3'\n | '3:4'\n | '3:2'\n | '2:3'\n\n/**\n * Resolution tiers for the grok-imagine video models.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoResolution = '480p' | '720p' | '1080p'\n\n/**\n * Resolutions accepted by grok-imagine-video (v1.0). Native 1080p is a\n * grok-imagine-video-1.5 generation feature.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoResolutionV1 = '480p' | '720p'\n\n/**\n * Size strings for grok-imagine video models. The Imagine API is\n * aspect-ratio based rather than pixel-size based; like the grok-imagine\n * image models, the generic `size` option uses an\n * `aspectRatio_resolution` template (\"16:9_720p\") — the resolution suffix\n * is optional (\"16:9\" uses the API default).\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoSize =\n | GrokVideoAspectRatio\n | `${GrokVideoAspectRatio}_${GrokVideoResolution}`\n\n/**\n * Size strings for grok-imagine-video (v1.0) — 1080p is not in the type.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoSizeV1 =\n | GrokVideoAspectRatio\n | `${GrokVideoAspectRatio}_${GrokVideoResolutionV1}`\n\nconst GROK_VIDEO_ASPECT_RATIOS: ReadonlyArray<string> = [\n '1:1',\n '16:9',\n '9:16',\n '4:3',\n '3:4',\n '3:2',\n '2:3',\n]\n\nconst GROK_VIDEO_RESOLUTIONS: ReadonlyArray<string> = ['480p', '720p', '1080p']\n\n/**\n * Video duration limits enforced by the Imagine API (seconds).\n */\nexport const GROK_VIDEO_MIN_DURATION = 1\nexport const GROK_VIDEO_MAX_DURATION = 15\n\n/**\n * Parses a grok video size string into its components.\n * Format: \"aspectRatio\" or \"aspectRatio_resolution\",\n * e.g. \"16:9_720p\" → { aspectRatio: \"16:9\", resolution: \"720p\" }.\n * Returns undefined when the string doesn't match the template.\n */\nexport function parseGrokVideoSize(\n size: string,\n): { aspectRatio: string; resolution?: string } | undefined {\n const match = size.match(/^([\\d.]+:[\\d.]+)(?:_(.+))?$/)\n const [, aspectRatio, resolution] = match ?? []\n if (aspectRatio === undefined) return undefined\n return { aspectRatio, ...(resolution !== undefined && { resolution }) }\n}\n\n/**\n * Models that accept native 1080p on text-to-video and image-to-video.\n * Reference-to-video stays capped at 720p even on these models.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport function isGrokVideoNative1080pModel(model: string): boolean {\n return model === 'grok-imagine-video-1.5'\n}\n\n/**\n * Validate the `size` template for a given grok video model.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport function validateVideoSize(\n model: string,\n size?: string,\n): asserts size is GrokVideoSize | undefined {\n if (size === undefined) return\n const parsed = parseGrokVideoSize(size)\n if (!parsed || !GROK_VIDEO_ASPECT_RATIOS.includes(parsed.aspectRatio)) {\n throw new Error(\n `Size \"${size}\" is not supported by model \"${model}\". Expected ` +\n `\"aspectRatio\" or \"aspectRatio_resolution\" (e.g. \"16:9_720p\") with ` +\n `aspect ratio one of: ${GROK_VIDEO_ASPECT_RATIOS.join(', ')}`,\n )\n }\n if (\n parsed.resolution !== undefined &&\n !GROK_VIDEO_RESOLUTIONS.includes(parsed.resolution)\n ) {\n throw new Error(\n `Resolution \"${parsed.resolution}\" is not supported by model \"${model}\". ` +\n `Supported resolutions: ${GROK_VIDEO_RESOLUTIONS.join(', ')}`,\n )\n }\n if (parsed.resolution === '1080p' && !isGrokVideoNative1080pModel(model)) {\n throw new Error(\n `Resolution \"1080p\" is not supported by model \"${model}\". ` +\n `Use 'grok-imagine-video-1.5' for native 1080p text-to-video / image-to-video.`,\n )\n }\n}\n\n/**\n * Per-model duration type. The Imagine API accepts any integer second in the\n * 1–15 range, so this is a continuous range expressed as `number` (a literal\n * union can't represent it). `snapDuration()` coerces a raw seconds value into\n * the valid range at runtime.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoModelDurationByName = {\n 'grok-imagine-video': number\n 'grok-imagine-video-1.5': number\n}\n\n/**\n * Runtime duration table backing `availableDurations()` / `snapDuration()`.\n * Both grok-imagine video models accept the same continuous 1–15 integer-second\n * range.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport const GROK_VIDEO_DURATIONS: {\n readonly [TModel in GrokVideoModel]: DurationOptions<\n GrokVideoModelDurationByName[TModel]\n >\n} = {\n 'grok-imagine-video': {\n kind: 'range',\n min: GROK_VIDEO_MIN_DURATION,\n max: GROK_VIDEO_MAX_DURATION,\n step: 1,\n unit: 'seconds',\n },\n 'grok-imagine-video-1.5': {\n kind: 'range',\n min: GROK_VIDEO_MIN_DURATION,\n max: GROK_VIDEO_MAX_DURATION,\n step: 1,\n unit: 'seconds',\n },\n}\n\n/**\n * Look up the duration options for a grok video model.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport function getGrokVideoDurationOptions<TModel extends GrokVideoModel>(\n model: TModel,\n): DurationOptions<GrokVideoModelDurationByName[TModel]> {\n return GROK_VIDEO_DURATIONS[model]\n}\n\n/**\n * Request mode for a source-video job. `'edit'` posts to `/v1/videos/edits`\n * (modify the source clip in place); `'extend'` posts to\n * `/v1/videos/extensions` (continue the source clip — `duration` is the\n * length of the **added tail**, not the total). Both require exactly one\n * video prompt part carrying the source clip, and both are\n * `grok-imagine-video` (v1.0) only.\n *\n * Output geometry (aspect ratio / resolution) is inherited from the source\n * clip in both modes, capped at 720p, and edit outputs also inherit the\n * source length — the adapter rejects `size`, `aspect_ratio`, `resolution`,\n * and (in edit mode) `duration` rather than sending fields the API ignores.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoMode = 'edit' | 'extend'\n\n/**\n * Provider options shared by both grok-imagine video models. These map\n * directly onto the Imagine API request body and take precedence over the\n * generic `size` / `duration` options when both are provided.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport interface GrokVideoBaseProviderOptions {\n /**\n * Output aspect ratio. Generation only — edit / extend outputs inherit\n * the source clip's geometry and the adapter rejects this in those modes.\n */\n aspect_ratio?: GrokVideoAspectRatio\n\n /**\n * Output resolution tier. Generation only — edit / extend outputs inherit\n * the source clip's geometry and the adapter rejects this in those modes.\n * `1080p` is grok-imagine-video-1.5 generation only; reference-to-video\n * is capped at 720p.\n */\n resolution?: GrokVideoResolution\n\n /**\n * Video duration in integer seconds (1–15). In `'extend'` mode this is\n * the length of the added tail only, not the total output length. Not\n * valid in `'edit'` mode (the output inherits the source clip's length).\n */\n duration?: number\n}\n\n/**\n * Provider options for grok-imagine-video (v1.0), which is the only model\n * that accepts a source-video edit / extend job.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport interface GrokVideoSourceProviderOptions extends GrokVideoBaseProviderOptions {\n /**\n * Selects the request mode for a source-video prompt part: `'edit'`\n * (`/v1/videos/edits`) or `'extend'` (`/v1/videos/extensions`). Required\n * when the prompt carries a video part; not valid without one. Omit for\n * plain generation (`/v1/videos/generations`). grok-imagine-video only.\n */\n mode?: GrokVideoMode\n}\n\n/**\n * Provider options for grok-imagine-video-1.5, which adds the\n * reference-to-video inputs on top of the shared options.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport interface GrokVideoProviderOptions extends GrokVideoBaseProviderOptions {\n /**\n * Reference images for reference-to-video generation (output capped at\n * 720p). Usually populated from image prompt parts with\n * `metadata.role: 'reference'` (or `'character'`); set explicitly to\n * replace the part-derived list. Reference images are addressed from the\n * prompt text as `<IMAGE_0>`, `<IMAGE_1>`, … in request order, and do not\n * lock the first frame.\n */\n reference_images?: Array<{ url: string }>\n\n /**\n * Preset TTS voices to reference for generated speech (max 3). Voice ids\n * come from the xAI TTS voice roster (e.g. 'eve', 'rex') or a custom\n * voice id, and are addressed from the prompt text as `<AUDIO_0>`,\n * `<AUDIO_1>`, `<AUDIO_2>`.\n */\n reference_audios?: Array<{ voice_id: string }>\n}\n\n/**\n * Widest option surface. Used when `modelOptions` arrives as deserialized\n * JSON and the adapter must validate fields the per-model map already\n * hides at compile time.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoRuntimeOptions = GrokVideoSourceProviderOptions &\n GrokVideoProviderOptions\n\n/**\n * Maximum reference voices accepted by the Imagine video endpoint.\n */\nexport const GROK_VIDEO_MAX_REFERENCE_AUDIOS = 3\n\n/**\n * Maximum reference images accepted by the Imagine video endpoint.\n */\nexport const GROK_VIDEO_MAX_REFERENCE_IMAGES = 7\n\n/**\n * Model names whose per-model options declare the reference fields. Keeps\n * the runtime set below provably in sync with\n * {@link GrokVideoModelProviderOptionsByName} — a typo or a new\n * reference-capable model missing from the set is a compile error.\n */\ntype GrokVideoReferenceModel = {\n [TModel in GrokVideoModel]: 'reference_images' extends keyof GrokVideoModelProviderOptionsByName[TModel]\n ? TModel\n : never\n}[GrokVideoModel]\n\n/**\n * Models that support reference-to-video inputs (`reference_images` /\n * `reference_audios`). The per-model provider-options map hides the fields\n * from other models at compile time; this backs the runtime gate for\n * untyped callers (e.g. deserialized JSON) so they get a clear error\n * instead of a raw API 400.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nconst GROK_VIDEO_REFERENCE_MODELS: ReadonlySet<string> =\n new Set<GrokVideoReferenceModel>(['grok-imagine-video-1.5'])\n\n/**\n * True when the model accepts reference-to-video inputs.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport function isGrokVideoReferenceModel(model: string): boolean {\n return GROK_VIDEO_REFERENCE_MODELS.has(model)\n}\n\n/**\n * Model names whose per-model options declare `mode`. Same\n * provably-in-sync construction as {@link GrokVideoReferenceModel}.\n */\ntype GrokVideoSourceModel = {\n [TModel in GrokVideoModel]: 'mode' extends keyof GrokVideoModelProviderOptionsByName[TModel]\n ? TModel\n : never\n}[GrokVideoModel]\n\n/**\n * Models that accept a source-video prompt part for `/v1/videos/edits`\n * and `/v1/videos/extensions`. xAI lists video input only on\n * grok-imagine-video (v1.0).\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nconst GROK_VIDEO_SOURCE_MODELS: ReadonlySet<string> =\n new Set<GrokVideoSourceModel>(['grok-imagine-video'])\n\n/**\n * True when the model accepts edit / extend source-video jobs.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport function isGrokVideoSourceModel(model: string): boolean {\n return GROK_VIDEO_SOURCE_MODELS.has(model)\n}\n\n/**\n * Type-only map from model name to its specific provider options. Only\n * grok-imagine-video-1.5 exposes the reference-to-video fields. Only\n * grok-imagine-video (v1.0) exposes `mode` for edit / extend.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoModelProviderOptionsByName = {\n 'grok-imagine-video': GrokVideoSourceProviderOptions\n 'grok-imagine-video-1.5': GrokVideoProviderOptions\n}\n\n/**\n * Type-only map from model name to its supported `size` strings.\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoModelSizeByName = {\n 'grok-imagine-video': GrokVideoSizeV1\n 'grok-imagine-video-1.5': GrokVideoSize\n}\n\n/**\n * Type-only map from model name to the non-text prompt modalities it accepts.\n * Both models support text-to-video and accept an optional `image` prompt\n * part as the starting frame; image parts with `metadata.role: 'reference'`\n * or `'character'` become `reference_images` (grok-imagine-video-1.5 only).\n * A `video` prompt part carries the source clip for edit / extension mode\n * on grok-imagine-video only (`modelOptions.mode: 'edit' | 'extend'`).\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport type GrokVideoModelInputModalitiesByName = {\n 'grok-imagine-video': readonly ['image', 'video']\n 'grok-imagine-video-1.5': readonly ['image']\n}\n"],"mappings":";AAoEA,IAAM,2BAAkD;CACtD;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,IAAM,yBAAgD;CAAC;CAAQ;CAAQ;AAAO;;;;;;;AAc9E,SAAgB,mBACd,MAC0D;CAE1D,MAAM,GAAG,aAAa,cADR,KAAK,MAAM,6BACW,KAAS,CAAC;CAC9C,IAAI,gBAAgB,KAAA,GAAW,OAAO,KAAA;CACtC,OAAO;EAAE;EAAa,GAAI,eAAe,KAAA,KAAa,EAAE,WAAW;CAAG;AACxE;;;;;;;AAQA,SAAgB,4BAA4B,OAAwB;CAClE,OAAO,UAAU;AACnB;;;;;;AAOA,SAAgB,kBACd,OACA,MAC2C;CAC3C,IAAI,SAAS,KAAA,GAAW;CACxB,MAAM,SAAS,mBAAmB,IAAI;CACtC,IAAI,CAAC,UAAU,CAAC,yBAAyB,SAAS,OAAO,WAAW,GAClE,MAAM,IAAI,MACR,SAAS,KAAK,+BAA+B,MAAM,qGAEzB,yBAAyB,KAAK,IAAI,GAC9D;CAEF,IACE,OAAO,eAAe,KAAA,KACtB,CAAC,uBAAuB,SAAS,OAAO,UAAU,GAElD,MAAM,IAAI,MACR,eAAe,OAAO,WAAW,+BAA+B,MAAM,4BAC1C,uBAAuB,KAAK,IAAI,GAC9D;CAEF,IAAI,OAAO,eAAe,WAAW,CAAC,4BAA4B,KAAK,GACrE,MAAM,IAAI,MACR,iDAAiD,MAAM,iFAEzD;AAEJ;;;;;;;;AAsBA,IAAa,uBAIT;CACF,sBAAsB;EACpB,MAAM;EACN,KAAA;EACA,KAAA;EACA,MAAM;EACN,MAAM;CACR;CACA,0BAA0B;EACxB,MAAM;EACN,KAAA;EACA,KAAA;EACA,MAAM;EACN,MAAM;CACR;AACF;;;;;;AAOA,SAAgB,4BACd,OACuD;CACvD,OAAO,qBAAqB;AAC9B;;;;;;;;;;AAoIA,IAAM,8CACJ,IAAI,IAA6B,CAAC,wBAAwB,CAAC;;;;;;AAO7D,SAAgB,0BAA0B,OAAwB;CAChE,OAAO,4BAA4B,IAAI,KAAK;AAC9C;;;;;;;;AAmBA,IAAM,2CACJ,IAAI,IAA0B,CAAC,oBAAoB,CAAC;;;;;;AAOtD,SAAgB,uBAAuB,OAAwB;CAC7D,OAAO,yBAAyB,IAAI,KAAK;AAC3C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-grok",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "xAI Grok adapter for TanStack AI chat, image generation, realtime, and structured outputs.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,17 +50,17 @@
|
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"openai": "^6.41.0",
|
|
53
|
-
"@tanstack/ai-utils": "0.4.0",
|
|
54
|
-
"@tanstack/openai-base": "0.9.
|
|
53
|
+
"@tanstack/ai-utils": "^0.4.0",
|
|
54
|
+
"@tanstack/openai-base": "^0.9.13"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@vitest/coverage-v8": "4.
|
|
58
|
-
"vite": "^8.1
|
|
59
|
-
"@tanstack/ai": "0.
|
|
57
|
+
"@vitest/coverage-v8": "4.1.10",
|
|
58
|
+
"vite": "^8.2.1",
|
|
59
|
+
"@tanstack/ai": "0.45.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"zod": "^4.0.0",
|
|
63
|
-
"@tanstack/ai": "^0.
|
|
63
|
+
"@tanstack/ai": "^0.45.0"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"build": "vite build",
|
package/src/adapters/image.ts
CHANGED
|
@@ -129,7 +129,8 @@ export class GrokImageAdapter<
|
|
|
129
129
|
throw new Error(
|
|
130
130
|
`grok: model "${model}" does not support image prompt parts. ` +
|
|
131
131
|
`Image-conditioned generation requires an Imagine API model ` +
|
|
132
|
-
`('grok-imagine-image'
|
|
132
|
+
`('grok-imagine-image', 'grok-imagine-image-2.0' or ` +
|
|
133
|
+
`'grok-imagine-image-quality').`,
|
|
133
134
|
)
|
|
134
135
|
}
|
|
135
136
|
return await this.editImages(options, resolved)
|