@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,76 +1,74 @@
1
- const GROK_IMAGINE_ASPECT_RATIOS = [
2
- "1:1",
3
- "3:4",
4
- "4:3",
5
- "9:16",
6
- "16:9",
7
- "2:3",
8
- "3:2",
9
- "9:19.5",
10
- "19.5:9",
11
- "9:20",
12
- "20:9",
13
- "1:2",
14
- "2:1",
15
- "auto"
1
+ //#region src/image/image-provider-options.ts
2
+ var GROK_IMAGINE_ASPECT_RATIOS = [
3
+ "1:1",
4
+ "3:4",
5
+ "4:3",
6
+ "9:16",
7
+ "16:9",
8
+ "2:3",
9
+ "3:2",
10
+ "9:19.5",
11
+ "19.5:9",
12
+ "9:20",
13
+ "20:9",
14
+ "1:2",
15
+ "2:1",
16
+ "auto"
16
17
  ];
17
- const GROK_IMAGINE_RESOLUTIONS = ["1k", "2k"];
18
+ var GROK_IMAGINE_RESOLUTIONS = ["1k", "2k"];
19
+ /**
20
+ * Models served by xAI's Imagine API. They are aspect-ratio sized and
21
+ * support image-conditioned generation via `/v1/images/edits`; the legacy
22
+ * grok-2-image-1212 model is pixel-sized and text-to-image only.
23
+ */
18
24
  function isGrokImagineImageModel(model) {
19
- return model.startsWith("grok-imagine-image");
25
+ return model.startsWith("grok-imagine-image");
20
26
  }
27
+ /**
28
+ * Parses a grok-imagine size string into its components.
29
+ * Format: "aspectRatio" or "aspectRatio_resolution",
30
+ * e.g. "16:9_2k" → { aspectRatio: "16:9", resolution: "2k" }.
31
+ * Returns undefined when the string doesn't match the template.
32
+ */
21
33
  function parseGrokImagineSize(size) {
22
- const match = size.match(/^([\d.]+:[\d.]+|auto)(?:_(.+))?$/);
23
- const [, aspectRatio, resolution] = match ?? [];
24
- if (aspectRatio === void 0) return void 0;
25
- return { aspectRatio, ...resolution !== void 0 && { resolution } };
34
+ const [, aspectRatio, resolution] = size.match(/^([\d.]+:[\d.]+|auto)(?:_(.+))?$/) ?? [];
35
+ if (aspectRatio === void 0) return void 0;
36
+ return {
37
+ aspectRatio,
38
+ ...resolution !== void 0 && { resolution }
39
+ };
26
40
  }
41
+ /**
42
+ * Validates that the provided size is supported by the model.
43
+ * Throws a descriptive error if the size is not supported.
44
+ */
27
45
  function validateImageSize(model, size) {
28
- if (!size) return;
29
- if (isGrokImagineImageModel(model)) {
30
- const parsed = parseGrokImagineSize(size);
31
- if (!parsed || !GROK_IMAGINE_ASPECT_RATIOS.includes(parsed.aspectRatio) || parsed.resolution !== void 0 && !GROK_IMAGINE_RESOLUTIONS.includes(parsed.resolution)) {
32
- throw new Error(
33
- `Size "${size}" is not supported by model "${model}". Expected an aspect ratio (${GROK_IMAGINE_ASPECT_RATIOS.join(", ")}) optionally suffixed with a resolution ("16:9_2k"; resolutions: ${GROK_IMAGINE_RESOLUTIONS.join(", ")}).`
34
- );
35
- }
36
- return;
37
- }
38
- const validSizes = {
39
- "grok-2-image-1212": ["1024x1024", "1536x1024", "1024x1536"]
40
- };
41
- const modelSizes = validSizes[model];
42
- if (!modelSizes) {
43
- throw new Error(`Unknown image model: ${model}`);
44
- }
45
- if (!modelSizes.includes(size)) {
46
- throw new Error(
47
- `Size "${size}" is not supported by model "${model}". Supported sizes: ${modelSizes.join(", ")}`
48
- );
49
- }
46
+ if (!size) return;
47
+ if (isGrokImagineImageModel(model)) {
48
+ const parsed = parseGrokImagineSize(size);
49
+ if (!parsed || !GROK_IMAGINE_ASPECT_RATIOS.includes(parsed.aspectRatio) || parsed.resolution !== void 0 && !GROK_IMAGINE_RESOLUTIONS.includes(parsed.resolution)) throw new Error(`Size "${size}" is not supported by model "${model}". Expected an aspect ratio (${GROK_IMAGINE_ASPECT_RATIOS.join(", ")}) optionally suffixed with a resolution ("16:9_2k"; resolutions: ${GROK_IMAGINE_RESOLUTIONS.join(", ")}).`);
50
+ return;
51
+ }
52
+ const modelSizes = { "grok-2-image-1212": [
53
+ "1024x1024",
54
+ "1536x1024",
55
+ "1024x1536"
56
+ ] }[model];
57
+ if (!modelSizes) throw new Error(`Unknown image model: ${model}`);
58
+ if (!modelSizes.includes(size)) throw new Error(`Size "${size}" is not supported by model "${model}". Supported sizes: ${modelSizes.join(", ")}`);
50
59
  }
60
+ /**
61
+ * Validates that the number of images is within bounds for the model.
62
+ */
51
63
  function validateNumberOfImages(_model, numberOfImages) {
52
- if (numberOfImages === void 0) return;
53
- if (numberOfImages < 1 || numberOfImages > 10) {
54
- throw new Error(
55
- `Number of images must be between 1 and 10. Requested: ${numberOfImages}`
56
- );
57
- }
64
+ if (numberOfImages === void 0) return;
65
+ if (numberOfImages < 1 || numberOfImages > 10) throw new Error(`Number of images must be between 1 and 10. Requested: ${numberOfImages}`);
58
66
  }
59
- const validatePrompt = (options) => {
60
- if (options.prompt.length === 0) {
61
- throw new Error("Prompt cannot be empty.");
62
- }
63
- if (options.prompt.length > 4e3) {
64
- throw new Error(
65
- "For grok-2-image-1212, prompt length must be less than or equal to 4000 characters."
66
- );
67
- }
67
+ var validatePrompt = (options) => {
68
+ if (options.prompt.length === 0) throw new Error("Prompt cannot be empty.");
69
+ if (options.prompt.length > 4e3) throw new Error("For grok-2-image-1212, prompt length must be less than or equal to 4000 characters.");
68
70
  };
69
- export {
70
- isGrokImagineImageModel,
71
- parseGrokImagineSize,
72
- validateImageSize,
73
- validateNumberOfImages,
74
- validatePrompt
75
- };
76
- //# sourceMappingURL=image-provider-options.js.map
71
+ //#endregion
72
+ export { isGrokImagineImageModel, parseGrokImagineSize, validateImageSize, validateNumberOfImages, validatePrompt };
73
+
74
+ //# sourceMappingURL=image-provider-options.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"image-provider-options.js","sources":["../../../src/image/image-provider-options.ts"],"sourcesContent":["/**\n * Grok Image Generation Provider Options\n *\n * These are provider-specific options for Grok image generation.\n * Grok uses the grok-2-image-1212 model for image generation.\n */\n\n/**\n * Supported sizes for grok-2-image-1212 model\n */\nexport type GrokImageSize = '1024x1024' | '1536x1024' | '1024x1536'\n\n/**\n * Aspect ratios accepted by the grok-imagine image models.\n */\nexport type GrokImagineAspectRatio =\n | '1:1'\n | '3:4'\n | '4:3'\n | '9:16'\n | '16:9'\n | '2:3'\n | '3:2'\n | '9:19.5'\n | '19.5:9'\n | '9:20'\n | '20:9'\n | '1:2'\n | '2:1'\n | 'auto'\n\n/**\n * Resolution tiers for the grok-imagine image models.\n */\nexport type GrokImagineResolution = '1k' | '2k'\n\n/**\n * Size strings for grok-imagine image models. The Imagine API is\n * aspect-ratio based rather than pixel-size based; like Gemini's native\n * image models, the generic `size` option uses an\n * `aspectRatio_resolution` template (\"16:9_2k\") — the resolution suffix is\n * optional (\"16:9\" uses the API default of 1k).\n */\nexport type GrokImagineImageSize =\n | GrokImagineAspectRatio\n | `${GrokImagineAspectRatio}_${GrokImagineResolution}`\n\nconst GROK_IMAGINE_ASPECT_RATIOS: ReadonlyArray<string> = [\n '1:1',\n '3:4',\n '4:3',\n '9:16',\n '16:9',\n '2:3',\n '3:2',\n '9:19.5',\n '19.5:9',\n '9:20',\n '20:9',\n '1:2',\n '2:1',\n 'auto',\n]\n\nconst GROK_IMAGINE_RESOLUTIONS: ReadonlyArray<string> = ['1k', '2k']\n\n/**\n * Models served by xAI's Imagine API. They are aspect-ratio sized and\n * support image-conditioned generation via `/v1/images/edits`; the legacy\n * grok-2-image-1212 model is pixel-sized and text-to-image only.\n */\nexport function isGrokImagineImageModel(model: string): boolean {\n return model.startsWith('grok-imagine-image')\n}\n\n/**\n * Parses a grok-imagine size string into its components.\n * Format: \"aspectRatio\" or \"aspectRatio_resolution\",\n * e.g. \"16:9_2k\" → { aspectRatio: \"16:9\", resolution: \"2k\" }.\n * Returns undefined when the string doesn't match the template.\n */\nexport function parseGrokImagineSize(\n size: string,\n): { aspectRatio: string; resolution?: string } | undefined {\n const match = size.match(/^([\\d.]+:[\\d.]+|auto)(?:_(.+))?$/)\n const [, aspectRatio, resolution] = match ?? []\n if (aspectRatio === undefined) return undefined\n return { aspectRatio, ...(resolution !== undefined && { resolution }) }\n}\n\n/**\n * Base provider options for Grok image models\n */\nexport interface GrokImageBaseProviderOptions {\n /**\n * A unique identifier representing your end-user.\n * Can help xAI to monitor and detect abuse.\n */\n user?: string\n}\n\n/**\n * Provider options for grok-2-image-1212 model\n */\nexport interface GrokImageProviderOptions extends GrokImageBaseProviderOptions {\n /**\n * The quality of the image.\n * @default 'standard'\n */\n quality?: 'standard' | 'hd'\n\n /**\n * The format in which generated images are returned.\n * URLs are only valid for 60 minutes after generation.\n * @default 'url'\n */\n response_format?: 'url' | 'b64_json'\n}\n\n/**\n * Provider options for the grok-imagine image models (generation and\n * image-conditioned editing via xAI's Imagine API).\n */\nexport interface GrokImagineImageProviderOptions extends GrokImageBaseProviderOptions {\n /**\n * The format in which generated images are returned.\n * @default 'url'\n */\n response_format?: 'url' | 'b64_json'\n\n /**\n * Output resolution.\n * @default '1k'\n */\n resolution?: '1k' | '2k'\n\n /**\n * Processing tier for the request.\n * @default 'default'\n */\n service_tier?: 'default' | 'priority'\n}\n\n/**\n * Type-only map from model name to its specific provider options.\n */\nexport type GrokImageModelProviderOptionsByName = {\n 'grok-2-image-1212': GrokImageProviderOptions\n 'grok-imagine-image': GrokImagineImageProviderOptions\n 'grok-imagine-image-quality': GrokImagineImageProviderOptions\n}\n\n/**\n * Type-only map from model name to its supported sizes.\n */\nexport type GrokImageModelSizeByName = {\n 'grok-2-image-1212': GrokImageSize\n 'grok-imagine-image': GrokImagineImageSize\n 'grok-imagine-image-quality': GrokImagineImageSize\n}\n\n/**\n * Per-model prompt input modalities. Imagine API models accept image parts\n * in the prompt (routed to `/v1/images/edits`, up to 3 images, addressed by\n * xAI in request order); grok-2-image is text-to-image only.\n */\nexport type GrokImageModelInputModalitiesByName = {\n 'grok-2-image-1212': readonly []\n 'grok-imagine-image': readonly ['image']\n 'grok-imagine-image-quality': readonly ['image']\n}\n\n/**\n * Internal options interface for validation\n */\ninterface ImageValidationOptions {\n prompt: string\n model: string\n}\n\n/**\n * Validates that the provided size is supported by the model.\n * Throws a descriptive error if the size is not supported.\n */\nexport function validateImageSize(\n model: string,\n size: string | undefined,\n): void {\n if (!size) return\n\n if (isGrokImagineImageModel(model)) {\n const parsed = parseGrokImagineSize(size)\n if (\n !parsed ||\n !GROK_IMAGINE_ASPECT_RATIOS.includes(parsed.aspectRatio) ||\n (parsed.resolution !== undefined &&\n !GROK_IMAGINE_RESOLUTIONS.includes(parsed.resolution))\n ) {\n throw new Error(\n `Size \"${size}\" is not supported by model \"${model}\". ` +\n `Expected an aspect ratio (${GROK_IMAGINE_ASPECT_RATIOS.join(', ')}) ` +\n `optionally suffixed with a resolution (\"16:9_2k\"; resolutions: ${GROK_IMAGINE_RESOLUTIONS.join(', ')}).`,\n )\n }\n return\n }\n\n const validSizes: Record<string, Array<string>> = {\n 'grok-2-image-1212': ['1024x1024', '1536x1024', '1024x1536'],\n }\n\n const modelSizes = validSizes[model]\n if (!modelSizes) {\n throw new Error(`Unknown image model: ${model}`)\n }\n\n if (!modelSizes.includes(size)) {\n throw new Error(\n `Size \"${size}\" is not supported by model \"${model}\". ` +\n `Supported sizes: ${modelSizes.join(', ')}`,\n )\n }\n}\n\n/**\n * Validates that the number of images is within bounds for the model.\n */\nexport function validateNumberOfImages(\n _model: string,\n numberOfImages: number | undefined,\n): void {\n if (numberOfImages === undefined) return\n\n // grok-2-image-1212 supports 1-10 images per request\n if (numberOfImages < 1 || numberOfImages > 10) {\n throw new Error(\n `Number of images must be between 1 and 10. Requested: ${numberOfImages}`,\n )\n }\n}\n\nexport const validatePrompt = (options: ImageValidationOptions) => {\n if (options.prompt.length === 0) {\n throw new Error('Prompt cannot be empty.')\n }\n // Grok image model supports up to 4000 characters\n if (options.prompt.length > 4000) {\n throw new Error(\n 'For grok-2-image-1212, prompt length must be less than or equal to 4000 characters.',\n )\n }\n}\n"],"names":[],"mappings":"AA+CA,MAAM,6BAAoD;AAAA,EACxD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,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BAAiB,CAAC,YAAoC;AACjE,MAAI,QAAQ,OAAO,WAAW,GAAG;AAC/B,UAAM,IAAI,MAAM,yBAAyB;AAAA,EAC3C;AAEA,MAAI,QAAQ,OAAO,SAAS,KAAM;AAChC,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACF;"}
1
+ {"version":3,"file":"image-provider-options.js","names":[],"sources":["../../../src/image/image-provider-options.ts"],"sourcesContent":["/**\n * Grok Image Generation Provider Options\n *\n * These are provider-specific options for Grok image generation.\n * Grok uses the grok-2-image-1212 model for image generation.\n */\n\n/**\n * Supported sizes for grok-2-image-1212 model\n */\nexport type GrokImageSize = '1024x1024' | '1536x1024' | '1024x1536'\n\n/**\n * Aspect ratios accepted by the grok-imagine image models.\n */\nexport type GrokImagineAspectRatio =\n | '1:1'\n | '3:4'\n | '4:3'\n | '9:16'\n | '16:9'\n | '2:3'\n | '3:2'\n | '9:19.5'\n | '19.5:9'\n | '9:20'\n | '20:9'\n | '1:2'\n | '2:1'\n | 'auto'\n\n/**\n * Resolution tiers for the grok-imagine image models.\n */\nexport type GrokImagineResolution = '1k' | '2k'\n\n/**\n * Size strings for grok-imagine image models. The Imagine API is\n * aspect-ratio based rather than pixel-size based; like Gemini's native\n * image models, the generic `size` option uses an\n * `aspectRatio_resolution` template (\"16:9_2k\") — the resolution suffix is\n * optional (\"16:9\" uses the API default of 1k).\n */\nexport type GrokImagineImageSize =\n | GrokImagineAspectRatio\n | `${GrokImagineAspectRatio}_${GrokImagineResolution}`\n\nconst GROK_IMAGINE_ASPECT_RATIOS: ReadonlyArray<string> = [\n '1:1',\n '3:4',\n '4:3',\n '9:16',\n '16:9',\n '2:3',\n '3:2',\n '9:19.5',\n '19.5:9',\n '9:20',\n '20:9',\n '1:2',\n '2:1',\n 'auto',\n]\n\nconst GROK_IMAGINE_RESOLUTIONS: ReadonlyArray<string> = ['1k', '2k']\n\n/**\n * Models served by xAI's Imagine API. They are aspect-ratio sized and\n * support image-conditioned generation via `/v1/images/edits`; the legacy\n * grok-2-image-1212 model is pixel-sized and text-to-image only.\n */\nexport function isGrokImagineImageModel(model: string): boolean {\n return model.startsWith('grok-imagine-image')\n}\n\n/**\n * Parses a grok-imagine size string into its components.\n * Format: \"aspectRatio\" or \"aspectRatio_resolution\",\n * e.g. \"16:9_2k\" → { aspectRatio: \"16:9\", resolution: \"2k\" }.\n * Returns undefined when the string doesn't match the template.\n */\nexport function parseGrokImagineSize(\n size: string,\n): { aspectRatio: string; resolution?: string } | undefined {\n const match = size.match(/^([\\d.]+:[\\d.]+|auto)(?:_(.+))?$/)\n const [, aspectRatio, resolution] = match ?? []\n if (aspectRatio === undefined) return undefined\n return { aspectRatio, ...(resolution !== undefined && { resolution }) }\n}\n\n/**\n * Base provider options for Grok image models\n */\nexport interface GrokImageBaseProviderOptions {\n /**\n * A unique identifier representing your end-user.\n * Can help xAI to monitor and detect abuse.\n */\n user?: string\n}\n\n/**\n * Provider options for grok-2-image-1212 model\n */\nexport interface GrokImageProviderOptions extends GrokImageBaseProviderOptions {\n /**\n * The quality of the image.\n * @default 'standard'\n */\n quality?: 'standard' | 'hd'\n\n /**\n * The format in which generated images are returned.\n * URLs are only valid for 60 minutes after generation.\n * @default 'url'\n */\n response_format?: 'url' | 'b64_json'\n}\n\n/**\n * Provider options for the grok-imagine image models (generation and\n * image-conditioned editing via xAI's Imagine API).\n */\nexport interface GrokImagineImageProviderOptions extends GrokImageBaseProviderOptions {\n /**\n * The format in which generated images are returned.\n * @default 'url'\n */\n response_format?: 'url' | 'b64_json'\n\n /**\n * Output resolution.\n * @default '1k'\n */\n resolution?: '1k' | '2k'\n\n /**\n * Processing tier for the request.\n * @default 'default'\n */\n service_tier?: 'default' | 'priority'\n}\n\n/**\n * Type-only map from model name to its specific provider options.\n */\nexport type GrokImageModelProviderOptionsByName = {\n 'grok-2-image-1212': GrokImageProviderOptions\n 'grok-imagine-image': GrokImagineImageProviderOptions\n 'grok-imagine-image-quality': GrokImagineImageProviderOptions\n}\n\n/**\n * Type-only map from model name to its supported sizes.\n */\nexport type GrokImageModelSizeByName = {\n 'grok-2-image-1212': GrokImageSize\n 'grok-imagine-image': GrokImagineImageSize\n 'grok-imagine-image-quality': GrokImagineImageSize\n}\n\n/**\n * Per-model prompt input modalities. Imagine API models accept image parts\n * in the prompt (routed to `/v1/images/edits`, up to 3 images, addressed by\n * xAI in request order); grok-2-image is text-to-image only.\n */\nexport type GrokImageModelInputModalitiesByName = {\n 'grok-2-image-1212': readonly []\n 'grok-imagine-image': readonly ['image']\n 'grok-imagine-image-quality': readonly ['image']\n}\n\n/**\n * Internal options interface for validation\n */\ninterface ImageValidationOptions {\n prompt: string\n model: string\n}\n\n/**\n * Validates that the provided size is supported by the model.\n * Throws a descriptive error if the size is not supported.\n */\nexport function validateImageSize(\n model: string,\n size: string | undefined,\n): void {\n if (!size) return\n\n if (isGrokImagineImageModel(model)) {\n const parsed = parseGrokImagineSize(size)\n if (\n !parsed ||\n !GROK_IMAGINE_ASPECT_RATIOS.includes(parsed.aspectRatio) ||\n (parsed.resolution !== undefined &&\n !GROK_IMAGINE_RESOLUTIONS.includes(parsed.resolution))\n ) {\n throw new Error(\n `Size \"${size}\" is not supported by model \"${model}\". ` +\n `Expected an aspect ratio (${GROK_IMAGINE_ASPECT_RATIOS.join(', ')}) ` +\n `optionally suffixed with a resolution (\"16:9_2k\"; resolutions: ${GROK_IMAGINE_RESOLUTIONS.join(', ')}).`,\n )\n }\n return\n }\n\n const validSizes: Record<string, Array<string>> = {\n 'grok-2-image-1212': ['1024x1024', '1536x1024', '1024x1536'],\n }\n\n const modelSizes = validSizes[model]\n if (!modelSizes) {\n throw new Error(`Unknown image model: ${model}`)\n }\n\n if (!modelSizes.includes(size)) {\n throw new Error(\n `Size \"${size}\" is not supported by model \"${model}\". ` +\n `Supported sizes: ${modelSizes.join(', ')}`,\n )\n }\n}\n\n/**\n * Validates that the number of images is within bounds for the model.\n */\nexport function validateNumberOfImages(\n _model: string,\n numberOfImages: number | undefined,\n): void {\n if (numberOfImages === undefined) return\n\n // grok-2-image-1212 supports 1-10 images per request\n if (numberOfImages < 1 || numberOfImages > 10) {\n throw new Error(\n `Number of images must be between 1 and 10. Requested: ${numberOfImages}`,\n )\n }\n}\n\nexport const validatePrompt = (options: ImageValidationOptions) => {\n if (options.prompt.length === 0) {\n throw new Error('Prompt cannot be empty.')\n }\n // Grok image model supports up to 4000 characters\n if (options.prompt.length > 4000) {\n throw new Error(\n 'For grok-2-image-1212, prompt length must be less than or equal to 4000 characters.',\n )\n }\n}\n"],"mappings":";AA+CA,IAAM,6BAAoD;CACxD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,IAAM,2BAAkD,CAAC,MAAM,IAAI;;;;;;AAOnE,SAAgB,wBAAwB,OAAwB;CAC9D,OAAO,MAAM,WAAW,oBAAoB;AAC9C;;;;;;;AAQA,SAAgB,qBACd,MAC0D;CAE1D,MAAM,GAAG,aAAa,cADR,KAAK,MAAM,kCACW,KAAS,CAAC;CAC9C,IAAI,gBAAgB,KAAA,GAAW,OAAO,KAAA;CACtC,OAAO;EAAE;EAAa,GAAI,eAAe,KAAA,KAAa,EAAE,WAAW;CAAG;AACxE;;;;;AAgGA,SAAgB,kBACd,OACA,MACM;CACN,IAAI,CAAC,MAAM;CAEX,IAAI,wBAAwB,KAAK,GAAG;EAClC,MAAM,SAAS,qBAAqB,IAAI;EACxC,IACE,CAAC,UACD,CAAC,2BAA2B,SAAS,OAAO,WAAW,KACtD,OAAO,eAAe,KAAA,KACrB,CAAC,yBAAyB,SAAS,OAAO,UAAU,GAEtD,MAAM,IAAI,MACR,SAAS,KAAK,+BAA+B,MAAM,+BACpB,2BAA2B,KAAK,IAAI,EAAE,mEACD,yBAAyB,KAAK,IAAI,EAAE,GAC1G;EAEF;CACF;CAMA,MAAM,aAAa,EAHjB,qBAAqB;EAAC;EAAa;EAAa;CAAW,EAG1C,EAAW;CAC9B,IAAI,CAAC,YACH,MAAM,IAAI,MAAM,wBAAwB,OAAO;CAGjD,IAAI,CAAC,WAAW,SAAS,IAAI,GAC3B,MAAM,IAAI,MACR,SAAS,KAAK,+BAA+B,MAAM,sBAC7B,WAAW,KAAK,IAAI,GAC5C;AAEJ;;;;AAKA,SAAgB,uBACd,QACA,gBACM;CACN,IAAI,mBAAmB,KAAA,GAAW;CAGlC,IAAI,iBAAiB,KAAK,iBAAiB,IACzC,MAAM,IAAI,MACR,yDAAyD,gBAC3D;AAEJ;AAEA,IAAa,kBAAkB,YAAoC;CACjE,IAAI,QAAQ,OAAO,WAAW,GAC5B,MAAM,IAAI,MAAM,yBAAyB;CAG3C,IAAI,QAAQ,OAAO,SAAS,KAC1B,MAAM,IAAI,MACR,qFACF;AAEJ"}
package/dist/esm/index.js CHANGED
@@ -1,40 +1,12 @@
1
1
  import { GrokTextAdapter, createGrokText, grokText } from "./adapters/text.js";
2
2
  import { createGrokSummarize, grokSummarize } from "./adapters/summarize.js";
3
3
  import { GrokImageAdapter, createGrokImage, grokImage } from "./adapters/image.js";
4
- import { GrokVideoAdapter, createGrokVideo, grokVideo } from "./adapters/video.js";
5
4
  import { GROK_VIDEO_DURATIONS, getGrokVideoDurationOptions } from "./video/video-provider-options.js";
5
+ import { GrokVideoAdapter, createGrokVideo, grokVideo } from "./adapters/video.js";
6
6
  import { GrokSpeechAdapter, createGrokSpeech, grokSpeech } from "./adapters/tts.js";
7
7
  import { GrokTranscriptionAdapter, createGrokTranscription, grokTranscription } from "./adapters/transcription.js";
8
8
  import { GROK_CHAT_MODELS, GROK_IMAGE_MODELS, GROK_REALTIME_MODELS, GROK_TRANSCRIPTION_MODELS, GROK_TTS_MODELS, GROK_VIDEO_MODELS } from "./model-meta.js";
9
9
  import { grokRealtimeToken } from "./realtime/token.js";
10
10
  import { grokRealtime } from "./realtime/adapter.js";
11
- export {
12
- GROK_CHAT_MODELS,
13
- GROK_IMAGE_MODELS,
14
- GROK_REALTIME_MODELS,
15
- GROK_TRANSCRIPTION_MODELS,
16
- GROK_TTS_MODELS,
17
- GROK_VIDEO_DURATIONS,
18
- GROK_VIDEO_MODELS,
19
- GrokImageAdapter,
20
- GrokSpeechAdapter,
21
- GrokTextAdapter,
22
- GrokTranscriptionAdapter,
23
- GrokVideoAdapter,
24
- createGrokImage,
25
- createGrokSpeech,
26
- createGrokSummarize,
27
- createGrokText,
28
- createGrokTranscription,
29
- createGrokVideo,
30
- getGrokVideoDurationOptions,
31
- grokImage,
32
- grokRealtime,
33
- grokRealtimeToken,
34
- grokSpeech,
35
- grokSummarize,
36
- grokText,
37
- grokTranscription,
38
- grokVideo
39
- };
40
- //# sourceMappingURL=index.js.map
11
+ import "./realtime/index.js";
12
+ export { GROK_CHAT_MODELS, GROK_IMAGE_MODELS, GROK_REALTIME_MODELS, GROK_TRANSCRIPTION_MODELS, GROK_TTS_MODELS, GROK_VIDEO_DURATIONS, GROK_VIDEO_MODELS, GrokImageAdapter, GrokSpeechAdapter, GrokTextAdapter, GrokTranscriptionAdapter, GrokVideoAdapter, createGrokImage, createGrokSpeech, createGrokSummarize, createGrokText, createGrokTranscription, createGrokVideo, getGrokVideoDurationOptions, grokImage, grokRealtime, grokRealtimeToken, grokSpeech, grokSummarize, grokText, grokTranscription, grokVideo };
@@ -1,58 +1,160 @@
1
- const GROK_2_IMAGE = {
2
- name: "grok-2-image-1212"
3
- };
4
- const GROK_IMAGINE_IMAGE = {
5
- name: "grok-imagine-image"
1
+ //#region src/model-meta.ts
2
+ var GROK_RESPONSES_TOOLS = [
3
+ "web_search",
4
+ "x_search",
5
+ "file_search",
6
+ "mcp"
7
+ ];
8
+ var GROK_2_IMAGE = {
9
+ name: "grok-2-image-1212",
10
+ supports: {
11
+ input: ["text"],
12
+ output: ["image"]
13
+ },
14
+ pricing: {
15
+ input: { normal: .07 },
16
+ output: { normal: .07 }
17
+ }
6
18
  };
7
- const GROK_IMAGINE_IMAGE_QUALITY = {
8
- name: "grok-imagine-image-quality"
19
+ var GROK_IMAGINE_IMAGE = {
20
+ name: "grok-imagine-image",
21
+ supports: {
22
+ input: ["text", "image"],
23
+ output: ["image"]
24
+ },
25
+ pricing: {
26
+ input: { normal: 0 },
27
+ output: { normal: .02 }
28
+ }
9
29
  };
10
- const GROK_IMAGINE_VIDEO = {
11
- name: "grok-imagine-video"
30
+ var GROK_IMAGINE_IMAGE_QUALITY = {
31
+ name: "grok-imagine-image-quality",
32
+ supports: {
33
+ input: ["text", "image"],
34
+ output: ["image"]
35
+ },
36
+ pricing: {
37
+ input: { normal: 0 },
38
+ output: { normal: .05 }
39
+ }
12
40
  };
13
- const GROK_IMAGINE_VIDEO_1_5 = {
14
- name: "grok-imagine-video-1.5"
41
+ var GROK_IMAGINE_VIDEO = {
42
+ name: "grok-imagine-video",
43
+ supports: {
44
+ input: ["text", "image"],
45
+ output: ["video", "audio"]
46
+ },
47
+ pricing: {
48
+ input: { normal: 0 },
49
+ output: { normal: .05 }
50
+ }
15
51
  };
16
- const GROK_4_3 = {
17
- name: "grok-4.3"
52
+ var GROK_IMAGINE_VIDEO_1_5 = {
53
+ name: "grok-imagine-video-1.5",
54
+ supports: {
55
+ input: ["text", "image"],
56
+ output: ["video", "audio"]
57
+ },
58
+ pricing: {
59
+ input: { normal: 0 },
60
+ output: { normal: .08 }
61
+ }
18
62
  };
19
- const GROK_BUILD_0_1 = {
20
- name: "grok-build-0.1"
63
+ var GROK_4_3 = {
64
+ name: "grok-4.3",
65
+ context_window: 1e6,
66
+ supports: {
67
+ input: ["text", "image"],
68
+ output: ["text"],
69
+ capabilities: [
70
+ "reasoning",
71
+ "structured_outputs",
72
+ "tool_calling"
73
+ ],
74
+ tools: GROK_RESPONSES_TOOLS
75
+ },
76
+ pricing: {
77
+ input: {
78
+ normal: 1.25,
79
+ cached: .2
80
+ },
81
+ output: { normal: 2.5 }
82
+ }
21
83
  };
22
- const GROK_CHAT_MODELS = [GROK_BUILD_0_1.name, GROK_4_3.name];
23
- const GROK_IMAGE_MODELS = [
24
- GROK_2_IMAGE.name,
25
- GROK_IMAGINE_IMAGE.name,
26
- GROK_IMAGINE_IMAGE_QUALITY.name
84
+ /**
85
+ * Grok chat models supported by the Responses adapter.
86
+ */
87
+ var GROK_CHAT_MODELS = [{
88
+ name: "grok-build-0.1",
89
+ context_window: 256e3,
90
+ supports: {
91
+ input: ["text", "image"],
92
+ output: ["text"],
93
+ capabilities: [
94
+ "reasoning",
95
+ "structured_outputs",
96
+ "tool_calling"
97
+ ],
98
+ tools: GROK_RESPONSES_TOOLS
99
+ },
100
+ pricing: {
101
+ input: {
102
+ normal: 1,
103
+ cached: .2
104
+ },
105
+ output: { normal: 2 }
106
+ }
107
+ }.name, GROK_4_3.name];
108
+ /**
109
+ * Grok Image Generation Models
110
+ */
111
+ var GROK_IMAGE_MODELS = [
112
+ GROK_2_IMAGE.name,
113
+ GROK_IMAGINE_IMAGE.name,
114
+ GROK_IMAGINE_IMAGE_QUALITY.name
27
115
  ];
28
- const GROK_VIDEO_MODELS = [
29
- GROK_IMAGINE_VIDEO.name,
30
- GROK_IMAGINE_VIDEO_1_5.name
31
- ];
32
- const GROK_TTS = {
33
- name: "grok-tts"
116
+ /**
117
+ * Grok Video Generation Models (xAI Imagine API)
118
+ *
119
+ * @experimental Video generation is an experimental feature and may change.
120
+ */
121
+ var GROK_VIDEO_MODELS = [GROK_IMAGINE_VIDEO.name, GROK_IMAGINE_VIDEO_1_5.name];
122
+ var GROK_TTS = {
123
+ name: "grok-tts",
124
+ supports: {
125
+ input: ["text"],
126
+ output: ["audio"]
127
+ }
34
128
  };
35
- const GROK_STT = {
36
- name: "grok-stt"
129
+ var GROK_STT = {
130
+ name: "grok-stt",
131
+ supports: {
132
+ input: ["audio"],
133
+ output: ["text"]
134
+ }
37
135
  };
38
- const GROK_VOICE_FAST_1 = {
39
- name: "grok-voice-fast-1.0"
136
+ var GROK_VOICE_FAST_1 = {
137
+ name: "grok-voice-fast-1.0",
138
+ supports: {
139
+ input: ["audio", "text"],
140
+ output: ["audio", "text"],
141
+ capabilities: ["tool_calling"],
142
+ tools: []
143
+ }
40
144
  };
41
- const GROK_VOICE_THINK_FAST_1 = {
42
- name: "grok-voice-think-fast-1.0"
145
+ var GROK_VOICE_THINK_FAST_1 = {
146
+ name: "grok-voice-think-fast-1.0",
147
+ supports: {
148
+ input: ["audio", "text"],
149
+ output: ["audio", "text"],
150
+ capabilities: ["reasoning", "tool_calling"],
151
+ tools: []
152
+ }
43
153
  };
44
- const GROK_TTS_MODELS = [GROK_TTS.name];
45
- const GROK_TRANSCRIPTION_MODELS = [GROK_STT.name];
46
- const GROK_REALTIME_MODELS = [
47
- GROK_VOICE_FAST_1.name,
48
- GROK_VOICE_THINK_FAST_1.name
49
- ];
50
- export {
51
- GROK_CHAT_MODELS,
52
- GROK_IMAGE_MODELS,
53
- GROK_REALTIME_MODELS,
54
- GROK_TRANSCRIPTION_MODELS,
55
- GROK_TTS_MODELS,
56
- GROK_VIDEO_MODELS
57
- };
58
- //# sourceMappingURL=model-meta.js.map
154
+ var GROK_TTS_MODELS = [GROK_TTS.name];
155
+ var GROK_TRANSCRIPTION_MODELS = [GROK_STT.name];
156
+ var GROK_REALTIME_MODELS = [GROK_VOICE_FAST_1.name, GROK_VOICE_THINK_FAST_1.name];
157
+ //#endregion
158
+ export { GROK_CHAT_MODELS, GROK_IMAGE_MODELS, GROK_REALTIME_MODELS, GROK_TRANSCRIPTION_MODELS, GROK_TTS_MODELS, GROK_VIDEO_MODELS };
159
+
160
+ //# sourceMappingURL=model-meta.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"model-meta.js","sources":["../../src/model-meta.ts"],"sourcesContent":["/**\n * Model metadata interface for documentation and type inference\n */\nimport type {\n GrokBuildProviderOptions,\n GrokTextProviderOptions,\n} from './text/text-provider-options'\n\ninterface ModelMeta {\n name: string\n supports: {\n input: Array<'text' | 'image' | 'audio' | 'video' | 'document'>\n output: Array<'text' | 'image' | 'audio' | 'video'>\n capabilities?: Array<'reasoning' | 'tool_calling' | 'structured_outputs'>\n tools?: ReadonlyArray<GrokProviderToolKind>\n }\n max_input_tokens?: number\n max_output_tokens?: number\n context_window?: number\n knowledge_cutoff?: string\n pricing?: {\n input: {\n normal: number\n cached?: number\n }\n output: {\n normal: number\n }\n }\n}\n\nexport type GrokProviderToolKind =\n | 'web_search'\n | 'x_search'\n | 'file_search'\n | 'mcp'\n\nconst GROK_RESPONSES_TOOLS = [\n 'web_search',\n 'x_search',\n 'file_search',\n 'mcp',\n] as const satisfies ReadonlyArray<GrokProviderToolKind>\n\nconst GROK_2_IMAGE = {\n name: 'grok-2-image-1212',\n supports: {\n input: ['text'],\n output: ['image'],\n },\n pricing: {\n input: {\n normal: 0.07,\n },\n output: {\n normal: 0.07,\n },\n },\n} as const satisfies ModelMeta\n\n// Imagine API image models. Pricing is per generated image (output only).\nconst GROK_IMAGINE_IMAGE = {\n name: 'grok-imagine-image',\n supports: {\n input: ['text', 'image'],\n output: ['image'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n normal: 0.02,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_IMAGINE_IMAGE_QUALITY = {\n name: 'grok-imagine-image-quality',\n supports: {\n input: ['text', 'image'],\n output: ['image'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n normal: 0.05,\n },\n },\n} as const satisfies ModelMeta\n\n// Imagine API video models. Pricing is per second of generated video\n// (output only); generated videos carry an audio track.\n//\n// grok-imagine-video (v1.0) supports both text-to-video (a starting image is\n// optional) and image-to-video. grok-imagine-video-1.5 is image-to-video\n// only: a starting-frame image is required (the text prompt describes the\n// desired motion) — its text-to-video is rejected by the API.\nconst GROK_IMAGINE_VIDEO = {\n name: 'grok-imagine-video',\n supports: {\n input: ['text', 'image'],\n output: ['video', 'audio'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n // per second of video\n normal: 0.05,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_IMAGINE_VIDEO_1_5 = {\n name: 'grok-imagine-video-1.5',\n supports: {\n input: ['text', 'image'],\n output: ['video', 'audio'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n // per second of video\n normal: 0.08,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_3 = {\n name: 'grok-4.3',\n context_window: 1_000_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: GROK_RESPONSES_TOOLS,\n },\n pricing: {\n input: {\n normal: 1.25,\n cached: 0.2,\n },\n output: {\n normal: 2.5,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_BUILD_0_1 = {\n name: 'grok-build-0.1',\n context_window: 256_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: GROK_RESPONSES_TOOLS,\n },\n pricing: {\n input: {\n normal: 1,\n cached: 0.2,\n },\n output: {\n normal: 2,\n },\n },\n} as const satisfies ModelMeta\n\n/**\n * Grok chat models supported by the Responses adapter.\n */\nexport const GROK_CHAT_MODELS = [GROK_BUILD_0_1.name, GROK_4_3.name] as const\n\n/**\n * Grok Image Generation Models\n */\nexport const GROK_IMAGE_MODELS = [\n GROK_2_IMAGE.name,\n GROK_IMAGINE_IMAGE.name,\n GROK_IMAGINE_IMAGE_QUALITY.name,\n] as const\n\n/**\n * Grok Video Generation Models (xAI Imagine API)\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport const GROK_VIDEO_MODELS = [\n GROK_IMAGINE_VIDEO.name,\n GROK_IMAGINE_VIDEO_1_5.name,\n] as const\n\n// xAI's `/v1/tts` endpoint is endpoint-addressed and does not take a `model`\n// parameter. This synthetic identifier satisfies the SDK's `TTSOptions.model`\n// contract and provides a stable value for logging and fixture matching.\nconst GROK_TTS = {\n name: 'grok-tts',\n supports: {\n input: ['text'],\n output: ['audio'],\n },\n} as const satisfies ModelMeta\n\n// xAI's `/v1/stt` endpoint is endpoint-addressed and does not take a `model`\n// parameter. This synthetic identifier satisfies the SDK's\n// `TranscriptionOptions.model` contract.\nconst GROK_STT = {\n name: 'grok-stt',\n supports: {\n input: ['audio'],\n output: ['text'],\n },\n} as const satisfies ModelMeta\n\nconst GROK_VOICE_FAST_1 = {\n name: 'grok-voice-fast-1.0',\n supports: {\n input: ['audio', 'text'],\n output: ['audio', 'text'],\n capabilities: ['tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\nconst GROK_VOICE_THINK_FAST_1 = {\n name: 'grok-voice-think-fast-1.0',\n supports: {\n input: ['audio', 'text'],\n output: ['audio', 'text'],\n capabilities: ['reasoning', 'tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\nexport const GROK_TTS_MODELS = [GROK_TTS.name] as const\n\nexport const GROK_TRANSCRIPTION_MODELS = [GROK_STT.name] as const\n\nexport const GROK_REALTIME_MODELS = [\n GROK_VOICE_FAST_1.name,\n GROK_VOICE_THINK_FAST_1.name,\n] as const\n\nexport type GrokChatModel = (typeof GROK_CHAT_MODELS)[number]\nexport type GrokImageModel = (typeof GROK_IMAGE_MODELS)[number]\nexport type GrokVideoModel = (typeof GROK_VIDEO_MODELS)[number]\nexport type GrokTTSModel = (typeof GROK_TTS_MODELS)[number]\nexport type GrokTranscriptionModel = (typeof GROK_TRANSCRIPTION_MODELS)[number]\nexport type GrokRealtimeModel = (typeof GROK_REALTIME_MODELS)[number]\n\n/**\n * Type-only map from Grok chat model name to its supported input modalities.\n * Used for type inference when constructing multimodal messages.\n */\nexport type GrokModelInputModalitiesByName = {\n [GROK_4_3.name]: typeof GROK_4_3.supports.input\n [GROK_BUILD_0_1.name]: typeof GROK_BUILD_0_1.supports.input\n}\n\n/**\n * Type-only map from Grok chat model name to its supported provider tools.\n * Keeps Grok provider-tool factories type-checked against the models that\n * advertise xAI Responses server-side tools.\n */\nexport type GrokChatModelToolCapabilitiesByName = {\n [GROK_4_3.name]: typeof GROK_4_3.supports.tools\n [GROK_BUILD_0_1.name]: typeof GROK_BUILD_0_1.supports.tools\n}\n\nexport type GrokProviderOptions = GrokTextProviderOptions\n\n/**\n * Type-only map from Grok chat model name to its provider options type.\n */\nexport type GrokChatModelProviderOptionsByName = {\n [GROK_4_3.name]: GrokProviderOptions\n [GROK_BUILD_0_1.name]: GrokBuildProviderOptions\n}\n\n// ===========================\n// Type Resolution Helpers\n// ===========================\n\n/**\n * Resolve provider options for a specific model.\n * If the model has explicit options in the map, use those; otherwise use base options.\n */\nexport type ResolveProviderOptions<TModel extends string> =\n TModel extends keyof GrokChatModelProviderOptionsByName\n ? GrokChatModelProviderOptionsByName[TModel]\n : GrokProviderOptions\n\n/**\n * Resolve input modalities for a specific model.\n * If the model has explicit modalities in the map, use those; otherwise use text only.\n */\nexport type ResolveInputModalities<TModel extends string> =\n TModel extends keyof GrokModelInputModalitiesByName\n ? GrokModelInputModalitiesByName[TModel]\n : readonly ['text']\n"],"names":[],"mappings":"AA4CA,MAAM,eAAe;AAAA,EACnB,MAAM;AAaR;AAGA,MAAM,qBAAqB;AAAA,EACzB,MAAM;AAaR;AAEA,MAAM,6BAA6B;AAAA,EACjC,MAAM;AAaR;AASA,MAAM,qBAAqB;AAAA,EACzB,MAAM;AAcR;AAEA,MAAM,yBAAyB;AAAA,EAC7B,MAAM;AAcR;AAEA,MAAM,WAAW;AAAA,EACf,MAAM;AAiBR;AAEA,MAAM,iBAAiB;AAAA,EACrB,MAAM;AAiBR;AAKO,MAAM,mBAAmB,CAAC,eAAe,MAAM,SAAS,IAAI;AAK5D,MAAM,oBAAoB;AAAA,EAC/B,aAAa;AAAA,EACb,mBAAmB;AAAA,EACnB,2BAA2B;AAC7B;AAOO,MAAM,oBAAoB;AAAA,EAC/B,mBAAmB;AAAA,EACnB,uBAAuB;AACzB;AAKA,MAAM,WAAW;AAAA,EACf,MAAM;AAKR;AAKA,MAAM,WAAW;AAAA,EACf,MAAM;AAKR;AAEA,MAAM,oBAAoB;AAAA,EACxB,MAAM;AAOR;AAEA,MAAM,0BAA0B;AAAA,EAC9B,MAAM;AAOR;AAEO,MAAM,kBAAkB,CAAC,SAAS,IAAI;AAEtC,MAAM,4BAA4B,CAAC,SAAS,IAAI;AAEhD,MAAM,uBAAuB;AAAA,EAClC,kBAAkB;AAAA,EAClB,wBAAwB;AAC1B;"}
1
+ {"version":3,"file":"model-meta.js","names":[],"sources":["../../src/model-meta.ts"],"sourcesContent":["/**\n * Model metadata interface for documentation and type inference\n */\nimport type {\n GrokBuildProviderOptions,\n GrokTextProviderOptions,\n} from './text/text-provider-options'\n\ninterface ModelMeta {\n name: string\n supports: {\n input: Array<'text' | 'image' | 'audio' | 'video' | 'document'>\n output: Array<'text' | 'image' | 'audio' | 'video'>\n capabilities?: Array<'reasoning' | 'tool_calling' | 'structured_outputs'>\n tools?: ReadonlyArray<GrokProviderToolKind>\n }\n max_input_tokens?: number\n max_output_tokens?: number\n context_window?: number\n knowledge_cutoff?: string\n pricing?: {\n input: {\n normal: number\n cached?: number\n }\n output: {\n normal: number\n }\n }\n}\n\nexport type GrokProviderToolKind =\n | 'web_search'\n | 'x_search'\n | 'file_search'\n | 'mcp'\n\nconst GROK_RESPONSES_TOOLS = [\n 'web_search',\n 'x_search',\n 'file_search',\n 'mcp',\n] as const satisfies ReadonlyArray<GrokProviderToolKind>\n\nconst GROK_2_IMAGE = {\n name: 'grok-2-image-1212',\n supports: {\n input: ['text'],\n output: ['image'],\n },\n pricing: {\n input: {\n normal: 0.07,\n },\n output: {\n normal: 0.07,\n },\n },\n} as const satisfies ModelMeta\n\n// Imagine API image models. Pricing is per generated image (output only).\nconst GROK_IMAGINE_IMAGE = {\n name: 'grok-imagine-image',\n supports: {\n input: ['text', 'image'],\n output: ['image'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n normal: 0.02,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_IMAGINE_IMAGE_QUALITY = {\n name: 'grok-imagine-image-quality',\n supports: {\n input: ['text', 'image'],\n output: ['image'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n normal: 0.05,\n },\n },\n} as const satisfies ModelMeta\n\n// Imagine API video models. Pricing is per second of generated video\n// (output only); generated videos carry an audio track.\n//\n// grok-imagine-video (v1.0) supports both text-to-video (a starting image is\n// optional) and image-to-video. grok-imagine-video-1.5 is image-to-video\n// only: a starting-frame image is required (the text prompt describes the\n// desired motion) — its text-to-video is rejected by the API.\nconst GROK_IMAGINE_VIDEO = {\n name: 'grok-imagine-video',\n supports: {\n input: ['text', 'image'],\n output: ['video', 'audio'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n // per second of video\n normal: 0.05,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_IMAGINE_VIDEO_1_5 = {\n name: 'grok-imagine-video-1.5',\n supports: {\n input: ['text', 'image'],\n output: ['video', 'audio'],\n },\n pricing: {\n input: {\n normal: 0,\n },\n output: {\n // per second of video\n normal: 0.08,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_3 = {\n name: 'grok-4.3',\n context_window: 1_000_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: GROK_RESPONSES_TOOLS,\n },\n pricing: {\n input: {\n normal: 1.25,\n cached: 0.2,\n },\n output: {\n normal: 2.5,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_BUILD_0_1 = {\n name: 'grok-build-0.1',\n context_window: 256_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: GROK_RESPONSES_TOOLS,\n },\n pricing: {\n input: {\n normal: 1,\n cached: 0.2,\n },\n output: {\n normal: 2,\n },\n },\n} as const satisfies ModelMeta\n\n/**\n * Grok chat models supported by the Responses adapter.\n */\nexport const GROK_CHAT_MODELS = [GROK_BUILD_0_1.name, GROK_4_3.name] as const\n\n/**\n * Grok Image Generation Models\n */\nexport const GROK_IMAGE_MODELS = [\n GROK_2_IMAGE.name,\n GROK_IMAGINE_IMAGE.name,\n GROK_IMAGINE_IMAGE_QUALITY.name,\n] as const\n\n/**\n * Grok Video Generation Models (xAI Imagine API)\n *\n * @experimental Video generation is an experimental feature and may change.\n */\nexport const GROK_VIDEO_MODELS = [\n GROK_IMAGINE_VIDEO.name,\n GROK_IMAGINE_VIDEO_1_5.name,\n] as const\n\n// xAI's `/v1/tts` endpoint is endpoint-addressed and does not take a `model`\n// parameter. This synthetic identifier satisfies the SDK's `TTSOptions.model`\n// contract and provides a stable value for logging and fixture matching.\nconst GROK_TTS = {\n name: 'grok-tts',\n supports: {\n input: ['text'],\n output: ['audio'],\n },\n} as const satisfies ModelMeta\n\n// xAI's `/v1/stt` endpoint is endpoint-addressed and does not take a `model`\n// parameter. This synthetic identifier satisfies the SDK's\n// `TranscriptionOptions.model` contract.\nconst GROK_STT = {\n name: 'grok-stt',\n supports: {\n input: ['audio'],\n output: ['text'],\n },\n} as const satisfies ModelMeta\n\nconst GROK_VOICE_FAST_1 = {\n name: 'grok-voice-fast-1.0',\n supports: {\n input: ['audio', 'text'],\n output: ['audio', 'text'],\n capabilities: ['tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\nconst GROK_VOICE_THINK_FAST_1 = {\n name: 'grok-voice-think-fast-1.0',\n supports: {\n input: ['audio', 'text'],\n output: ['audio', 'text'],\n capabilities: ['reasoning', 'tool_calling'],\n tools: [] as const,\n },\n} as const satisfies ModelMeta\n\nexport const GROK_TTS_MODELS = [GROK_TTS.name] as const\n\nexport const GROK_TRANSCRIPTION_MODELS = [GROK_STT.name] as const\n\nexport const GROK_REALTIME_MODELS = [\n GROK_VOICE_FAST_1.name,\n GROK_VOICE_THINK_FAST_1.name,\n] as const\n\nexport type GrokChatModel = (typeof GROK_CHAT_MODELS)[number]\nexport type GrokImageModel = (typeof GROK_IMAGE_MODELS)[number]\nexport type GrokVideoModel = (typeof GROK_VIDEO_MODELS)[number]\nexport type GrokTTSModel = (typeof GROK_TTS_MODELS)[number]\nexport type GrokTranscriptionModel = (typeof GROK_TRANSCRIPTION_MODELS)[number]\nexport type GrokRealtimeModel = (typeof GROK_REALTIME_MODELS)[number]\n\n/**\n * Type-only map from Grok chat model name to its supported input modalities.\n * Used for type inference when constructing multimodal messages.\n */\nexport type GrokModelInputModalitiesByName = {\n [GROK_4_3.name]: typeof GROK_4_3.supports.input\n [GROK_BUILD_0_1.name]: typeof GROK_BUILD_0_1.supports.input\n}\n\n/**\n * Type-only map from Grok chat model name to its supported provider tools.\n * Keeps Grok provider-tool factories type-checked against the models that\n * advertise xAI Responses server-side tools.\n */\nexport type GrokChatModelToolCapabilitiesByName = {\n [GROK_4_3.name]: typeof GROK_4_3.supports.tools\n [GROK_BUILD_0_1.name]: typeof GROK_BUILD_0_1.supports.tools\n}\n\nexport type GrokProviderOptions = GrokTextProviderOptions\n\n/**\n * Type-only map from Grok chat model name to its provider options type.\n */\nexport type GrokChatModelProviderOptionsByName = {\n [GROK_4_3.name]: GrokProviderOptions\n [GROK_BUILD_0_1.name]: GrokBuildProviderOptions\n}\n\n// ===========================\n// Type Resolution Helpers\n// ===========================\n\n/**\n * Resolve provider options for a specific model.\n * If the model has explicit options in the map, use those; otherwise use base options.\n */\nexport type ResolveProviderOptions<TModel extends string> =\n TModel extends keyof GrokChatModelProviderOptionsByName\n ? GrokChatModelProviderOptionsByName[TModel]\n : GrokProviderOptions\n\n/**\n * Resolve input modalities for a specific model.\n * If the model has explicit modalities in the map, use those; otherwise use text only.\n */\nexport type ResolveInputModalities<TModel extends string> =\n TModel extends keyof GrokModelInputModalitiesByName\n ? GrokModelInputModalitiesByName[TModel]\n : readonly ['text']\n"],"mappings":";AAqCA,IAAM,uBAAuB;CAC3B;CACA;CACA;CACA;AACF;AAEA,IAAM,eAAe;CACnB,MAAM;CACN,UAAU;EACR,OAAO,CAAC,MAAM;EACd,QAAQ,CAAC,OAAO;CAClB;CACA,SAAS;EACP,OAAO,EACL,QAAQ,IACV;EACA,QAAQ,EACN,Q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