@tanstack/ai-grok 0.12.4 → 0.13.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/README.md +7 -19
- package/dist/esm/adapters/summarize.d.ts +4 -4
- package/dist/esm/adapters/summarize.js.map +1 -1
- package/dist/esm/adapters/text.d.ts +12 -30
- package/dist/esm/adapters/text.js +21 -27
- package/dist/esm/adapters/text.js.map +1 -1
- package/dist/esm/model-meta.d.ts +16 -276
- package/dist/esm/model-meta.js +1 -60
- package/dist/esm/model-meta.js.map +1 -1
- package/dist/esm/text/text-provider-options.d.ts +17 -15
- package/dist/esm/tools/index.d.ts +45 -1
- package/dist/esm/tools/index.js +110 -3
- package/dist/esm/tools/index.js.map +1 -1
- package/package.json +1 -1
- package/src/adapters/summarize.ts +4 -4
- package/src/adapters/text.ts +40 -40
- package/src/model-meta.ts +31 -314
- package/src/text/text-provider-options.ts +31 -11
- package/src/tools/index.ts +212 -5
package/README.md
CHANGED
|
@@ -28,11 +28,10 @@ export XAI_API_KEY="xai-..."
|
|
|
28
28
|
import { grokText } from '@tanstack/ai-grok'
|
|
29
29
|
import { generate } from '@tanstack/ai'
|
|
30
30
|
|
|
31
|
-
const adapter = grokText()
|
|
31
|
+
const adapter = grokText('grok-build-0.1')
|
|
32
32
|
|
|
33
33
|
const result = await generate({
|
|
34
34
|
adapter,
|
|
35
|
-
model: 'grok-3',
|
|
36
35
|
messages: [
|
|
37
36
|
{ role: 'user', content: 'Explain quantum computing in simple terms' },
|
|
38
37
|
],
|
|
@@ -47,11 +46,10 @@ console.log(result.text)
|
|
|
47
46
|
import { grokSummarize } from '@tanstack/ai-grok'
|
|
48
47
|
import { summarize } from '@tanstack/ai'
|
|
49
48
|
|
|
50
|
-
const adapter = grokSummarize()
|
|
49
|
+
const adapter = grokSummarize('grok-build-0.1')
|
|
51
50
|
|
|
52
51
|
const result = await summarize({
|
|
53
52
|
adapter,
|
|
54
|
-
model: 'grok-3',
|
|
55
53
|
text: 'Long article text...',
|
|
56
54
|
style: 'bullet-points',
|
|
57
55
|
})
|
|
@@ -83,27 +81,17 @@ console.log(result.images[0].url)
|
|
|
83
81
|
```typescript
|
|
84
82
|
import { createGrokText } from '@tanstack/ai-grok'
|
|
85
83
|
|
|
86
|
-
const adapter = createGrokText('xai-your-api-key-here')
|
|
84
|
+
const adapter = createGrokText('grok-build-0.1', 'xai-your-api-key-here')
|
|
87
85
|
```
|
|
88
86
|
|
|
89
|
-
## Supported Models
|
|
87
|
+
## Supported Chat Models
|
|
90
88
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
- `grok-4` - Latest flagship model
|
|
94
|
-
- `grok-3` - Previous generation model
|
|
95
|
-
- `grok-3-mini` - Smaller, faster model
|
|
96
|
-
- `grok-4-fast` - Fast inference model
|
|
97
|
-
- `grok-4.1-fast` - Production-focused fast model
|
|
98
|
-
- `grok-2-vision-1212` - Vision-capable model (text + image input)
|
|
99
|
-
|
|
100
|
-
### Image Models
|
|
101
|
-
|
|
102
|
-
- `grok-2-image-1212` - Image generation model
|
|
89
|
+
- `grok-build-0.1` - Build-focused reasoning model with text + image input
|
|
90
|
+
- `grok-4.3` - Reasoning, structured outputs, tool calling, text + image input
|
|
103
91
|
|
|
104
92
|
## Features
|
|
105
93
|
|
|
106
|
-
- ✅ Streaming chat
|
|
94
|
+
- ✅ Streaming chat via xAI Responses API
|
|
107
95
|
- ✅ Structured output (JSON Schema)
|
|
108
96
|
- ✅ Function/tool calling
|
|
109
97
|
- ✅ Multimodal input (text + images for vision models)
|
|
@@ -13,14 +13,14 @@ export type GrokSummarizeModel = (typeof GROK_CHAT_MODELS)[number];
|
|
|
13
13
|
* Creates a Grok summarize adapter with explicit API key.
|
|
14
14
|
* Type resolution happens here at the call site.
|
|
15
15
|
*
|
|
16
|
-
* @param model - The model name (e.g., 'grok-
|
|
16
|
+
* @param model - The model name (e.g., 'grok-build-0.1')
|
|
17
17
|
* @param apiKey - Your xAI API key
|
|
18
18
|
* @param config - Optional additional configuration
|
|
19
19
|
* @returns Configured Grok summarize adapter instance with resolved types
|
|
20
20
|
*
|
|
21
21
|
* @example
|
|
22
22
|
* ```typescript
|
|
23
|
-
* const adapter = createGrokSummarize('grok-
|
|
23
|
+
* const adapter = createGrokSummarize('grok-build-0.1', "xai-...");
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
26
|
export declare function createGrokSummarize<TModel extends GrokSummarizeModel>(model: TModel, apiKey: string, config?: Omit<GrokSummarizeConfig, 'apiKey'>): ChatStreamSummarizeAdapter<TModel, InferTextProviderOptions<GrokTextAdapter<TModel>>>;
|
|
@@ -32,7 +32,7 @@ export declare function createGrokSummarize<TModel extends GrokSummarizeModel>(m
|
|
|
32
32
|
* - `process.env` (Node.js)
|
|
33
33
|
* - `window.env` (Browser with injected env)
|
|
34
34
|
*
|
|
35
|
-
* @param model - The model name (e.g., 'grok-
|
|
35
|
+
* @param model - The model name (e.g., 'grok-build-0.1')
|
|
36
36
|
* @param config - Optional configuration (excluding apiKey which is auto-detected)
|
|
37
37
|
* @returns Configured Grok summarize adapter instance with resolved types
|
|
38
38
|
* @throws Error if XAI_API_KEY is not found in environment
|
|
@@ -40,7 +40,7 @@ export declare function createGrokSummarize<TModel extends GrokSummarizeModel>(m
|
|
|
40
40
|
* @example
|
|
41
41
|
* ```typescript
|
|
42
42
|
* // Automatically uses XAI_API_KEY from environment
|
|
43
|
-
* const adapter = grokSummarize('grok-
|
|
43
|
+
* const adapter = grokSummarize('grok-build-0.1');
|
|
44
44
|
*
|
|
45
45
|
* await summarize({
|
|
46
46
|
* adapter,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summarize.js","sources":["../../../src/adapters/summarize.ts"],"sourcesContent":["import { ChatStreamSummarizeAdapter } from '@tanstack/ai/adapters'\nimport { getGrokApiKeyFromEnv } from '../utils'\nimport { GrokTextAdapter } from './text'\nimport type { InferTextProviderOptions } from '@tanstack/ai/adapters'\nimport type { GROK_CHAT_MODELS } from '../model-meta'\nimport type { GrokClientConfig } from '../utils'\n\n/**\n * Configuration for Grok summarize adapter\n */\nexport interface GrokSummarizeConfig extends GrokClientConfig {}\n\n/** Model type for Grok summarization */\nexport type GrokSummarizeModel = (typeof GROK_CHAT_MODELS)[number]\n\n/**\n * Creates a Grok summarize adapter with explicit API key.\n * Type resolution happens here at the call site.\n *\n * @param model - The model name (e.g., 'grok-
|
|
1
|
+
{"version":3,"file":"summarize.js","sources":["../../../src/adapters/summarize.ts"],"sourcesContent":["import { ChatStreamSummarizeAdapter } from '@tanstack/ai/adapters'\nimport { getGrokApiKeyFromEnv } from '../utils'\nimport { GrokTextAdapter } from './text'\nimport type { InferTextProviderOptions } from '@tanstack/ai/adapters'\nimport type { GROK_CHAT_MODELS } from '../model-meta'\nimport type { GrokClientConfig } from '../utils'\n\n/**\n * Configuration for Grok summarize adapter\n */\nexport interface GrokSummarizeConfig extends GrokClientConfig {}\n\n/** Model type for Grok summarization */\nexport type GrokSummarizeModel = (typeof GROK_CHAT_MODELS)[number]\n\n/**\n * Creates a Grok summarize adapter with explicit API key.\n * Type resolution happens here at the call site.\n *\n * @param model - The model name (e.g., 'grok-build-0.1')\n * @param apiKey - Your xAI API key\n * @param config - Optional additional configuration\n * @returns Configured Grok summarize adapter instance with resolved types\n *\n * @example\n * ```typescript\n * const adapter = createGrokSummarize('grok-build-0.1', \"xai-...\");\n * ```\n */\nexport function createGrokSummarize<TModel extends GrokSummarizeModel>(\n model: TModel,\n apiKey: string,\n config?: Omit<GrokSummarizeConfig, 'apiKey'>,\n): ChatStreamSummarizeAdapter<\n TModel,\n InferTextProviderOptions<GrokTextAdapter<TModel>>\n> {\n return new ChatStreamSummarizeAdapter(\n new GrokTextAdapter({ apiKey, ...config }, model),\n model,\n 'grok',\n )\n}\n\n/**\n * Creates a Grok summarize 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 * @param model - The model name (e.g., 'grok-build-0.1')\n * @param config - Optional configuration (excluding apiKey which is auto-detected)\n * @returns Configured Grok summarize 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 = grokSummarize('grok-build-0.1');\n *\n * await summarize({\n * adapter,\n * text: \"Long article text...\"\n * });\n * ```\n */\nexport function grokSummarize<TModel extends GrokSummarizeModel>(\n model: TModel,\n config?: Omit<GrokSummarizeConfig, 'apiKey'>,\n): ChatStreamSummarizeAdapter<\n TModel,\n InferTextProviderOptions<GrokTextAdapter<TModel>>\n> {\n return createGrokSummarize(model, getGrokApiKeyFromEnv(), config)\n}\n"],"names":[],"mappings":";;;;;AA6BO,SAAS,oBACd,OACA,QACA,QAIA;AACA,SAAO,IAAI;AAAA,IACT,IAAI,gBAAgB,EAAE,QAAQ,GAAG,OAAA,GAAU,KAAK;AAAA,IAChD;AAAA,IACA;AAAA,EAAA;AAEJ;AA0BO,SAAS,cACd,OACA,QAIA;AACA,SAAO,oBAAoB,OAAO,qBAAA,GAAwB,MAAM;AAClE;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { OpenAIBaseChatCompletionsTextAdapter } from '@tanstack/openai-base';
|
|
1
|
+
import { OpenAIBaseResponsesTextAdapter } from '@tanstack/openai-base';
|
|
3
2
|
import { GROK_CHAT_MODELS, GrokChatModelToolCapabilitiesByName, ResolveInputModalities, ResolveProviderOptions } from '../model-meta.js';
|
|
4
|
-
import { Modality } from '@tanstack/ai';
|
|
3
|
+
import { Modality, TextOptions } from '@tanstack/ai';
|
|
5
4
|
import { GrokMessageMetadataByModality } from '../message-types.js';
|
|
6
5
|
import { GrokClientConfig } from '../utils.js';
|
|
6
|
+
import { ResponseCreateParams } from 'openai/resources/responses/responses';
|
|
7
7
|
/**
|
|
8
8
|
* Resolve tool capabilities for a specific Grok model.
|
|
9
9
|
*/
|
|
@@ -21,49 +21,31 @@ export type { ExternalTextProviderOptions as GrokTextProviderOptions } from '../
|
|
|
21
21
|
* Grok Text (Chat) Adapter
|
|
22
22
|
*
|
|
23
23
|
* Tree-shakeable adapter for Grok chat/text completion functionality.
|
|
24
|
-
* Uses OpenAI-compatible
|
|
24
|
+
* Uses xAI's OpenAI-compatible Responses API.
|
|
25
25
|
*
|
|
26
|
-
* Delegates implementation to {@link
|
|
26
|
+
* Delegates implementation to {@link OpenAIBaseResponsesTextAdapter}
|
|
27
27
|
* from `@tanstack/openai-base` and threads Grok-specific tool-capability
|
|
28
28
|
* typing through the 5th generic of the base class.
|
|
29
29
|
*/
|
|
30
|
-
export declare class GrokTextAdapter<TModel extends (typeof GROK_CHAT_MODELS)[number], TProviderOptions extends Record<string,
|
|
30
|
+
export declare class GrokTextAdapter<TModel extends (typeof GROK_CHAT_MODELS)[number], TProviderOptions extends Record<string, unknown> = ResolveProviderOptions<TModel>, TInputModalities extends ReadonlyArray<Modality> = ResolveInputModalities<TModel>, TToolCapabilities extends ReadonlyArray<string> = ResolveToolCapabilities<TModel>> extends OpenAIBaseResponsesTextAdapter<TModel, TProviderOptions, TInputModalities, GrokMessageMetadataByModality, TToolCapabilities> {
|
|
31
31
|
readonly kind: "text";
|
|
32
32
|
readonly name: "grok";
|
|
33
33
|
constructor(config: GrokTextConfig, model: TModel);
|
|
34
|
-
|
|
35
|
-
* Surfaces xAI reasoning deltas on Grok reasoning models. The DeepSeek-style
|
|
36
|
-
* convention puts the chain-of-thought on `delta.reasoning_content`; some
|
|
37
|
-
* Grok variants also populate `delta.reasoning`. Reading both keeps
|
|
38
|
-
* reasoning flowing through the base's REASONING_* lifecycle for both
|
|
39
|
-
* `chatStream` and `structuredOutputStream`.
|
|
40
|
-
*/
|
|
41
|
-
protected extractReasoning(chunk: OpenAI.Chat.Completions.ChatCompletionChunk): {
|
|
42
|
-
text: string;
|
|
43
|
-
} | undefined;
|
|
44
|
-
/**
|
|
45
|
-
* Grok's combined tools + schema support is gated to the Grok 4 family
|
|
46
|
-
* per xAI's structured-output docs; Grok 2 / 3 reject the combination.
|
|
47
|
-
* The wiring on the wire is already correct (inherits the OpenAI Chat
|
|
48
|
-
* Completions `response_format: json_schema` attach from the base
|
|
49
|
-
* adapter); this override just narrows the capability claim to the
|
|
50
|
-
* supported model family.
|
|
51
|
-
*/
|
|
52
|
-
supportsCombinedToolsAndSchema(): boolean;
|
|
34
|
+
protected mapOptionsToRequest(options: TextOptions<TProviderOptions>): Omit<ResponseCreateParams, 'stream'>;
|
|
53
35
|
}
|
|
54
36
|
/**
|
|
55
37
|
* Creates a Grok text adapter with explicit API key.
|
|
56
38
|
* Type resolution happens here at the call site.
|
|
57
39
|
*
|
|
58
|
-
* @param model - The model name (e.g., 'grok-
|
|
40
|
+
* @param model - The model name (e.g., 'grok-build-0.1')
|
|
59
41
|
* @param apiKey - Your xAI API key
|
|
60
42
|
* @param config - Optional additional configuration
|
|
61
43
|
* @returns Configured Grok text adapter instance with resolved types
|
|
62
44
|
*
|
|
63
45
|
* @example
|
|
64
46
|
* ```typescript
|
|
65
|
-
* const adapter = createGrokText('grok-
|
|
66
|
-
* // adapter has type-safe providerOptions for grok-
|
|
47
|
+
* const adapter = createGrokText('grok-build-0.1', "xai-...");
|
|
48
|
+
* // adapter has type-safe providerOptions for grok-build-0.1
|
|
67
49
|
* ```
|
|
68
50
|
*/
|
|
69
51
|
export declare function createGrokText<TModel extends (typeof GROK_CHAT_MODELS)[number]>(model: TModel, apiKey: string, config?: Omit<GrokTextConfig, 'apiKey'>): GrokTextAdapter<TModel>;
|
|
@@ -75,7 +57,7 @@ export declare function createGrokText<TModel extends (typeof GROK_CHAT_MODELS)[
|
|
|
75
57
|
* - `process.env` (Node.js)
|
|
76
58
|
* - `window.env` (Browser with injected env)
|
|
77
59
|
*
|
|
78
|
-
* @param model - The model name (e.g., 'grok-
|
|
60
|
+
* @param model - The model name (e.g., 'grok-build-0.1')
|
|
79
61
|
* @param config - Optional configuration (excluding apiKey which is auto-detected)
|
|
80
62
|
* @returns Configured Grok text adapter instance with resolved types
|
|
81
63
|
* @throws Error if XAI_API_KEY is not found in environment
|
|
@@ -83,7 +65,7 @@ export declare function createGrokText<TModel extends (typeof GROK_CHAT_MODELS)[
|
|
|
83
65
|
* @example
|
|
84
66
|
* ```typescript
|
|
85
67
|
* // Automatically uses XAI_API_KEY from environment
|
|
86
|
-
* const adapter = grokText('grok-
|
|
68
|
+
* const adapter = grokText('grok-build-0.1');
|
|
87
69
|
*
|
|
88
70
|
* const stream = chat({
|
|
89
71
|
* adapter,
|
|
@@ -1,38 +1,32 @@
|
|
|
1
1
|
import OpenAI from "openai";
|
|
2
|
-
import {
|
|
2
|
+
import { OpenAIBaseResponsesTextAdapter } from "@tanstack/openai-base";
|
|
3
3
|
import { withGrokDefaults, getGrokApiKeyFromEnv } from "../utils/client.js";
|
|
4
|
-
import {
|
|
5
|
-
class GrokTextAdapter extends
|
|
4
|
+
import { convertToolsToProviderFormat } from "../tools/index.js";
|
|
5
|
+
class GrokTextAdapter extends OpenAIBaseResponsesTextAdapter {
|
|
6
6
|
kind = "text";
|
|
7
7
|
name = "grok";
|
|
8
8
|
constructor(config, model) {
|
|
9
9
|
super(model, "grok", new OpenAI(withGrokDefaults(config)));
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const raw = delta?.reasoning_content ?? delta?.reasoning;
|
|
21
|
-
if (typeof raw === "string" && raw.length > 0) {
|
|
22
|
-
return { text: raw };
|
|
11
|
+
mapOptionsToRequest(options) {
|
|
12
|
+
const { tools: _baseTools, ...request } = super.mapOptionsToRequest({
|
|
13
|
+
...options,
|
|
14
|
+
tools: void 0
|
|
15
|
+
});
|
|
16
|
+
if (this.model === "grok-build-0.1" && request.reasoning !== void 0) {
|
|
17
|
+
throw new Error(
|
|
18
|
+
"grok-build-0.1 does not support reasoning modelOptions; omit reasoning for this model."
|
|
19
|
+
);
|
|
23
20
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
*/
|
|
34
|
-
supportsCombinedToolsAndSchema() {
|
|
35
|
-
return GROK_COMBINED_TOOLS_AND_SCHEMA_MODELS.has(this.model);
|
|
21
|
+
const tools = options.tools ? convertToolsToProviderFormat(options.tools) : void 0;
|
|
22
|
+
return {
|
|
23
|
+
...request,
|
|
24
|
+
// xAI recommends encrypted reasoning for reasoning-capable Responses
|
|
25
|
+
// requests; callers can still override either field in modelOptions.
|
|
26
|
+
store: request.store ?? false,
|
|
27
|
+
include: request.include ?? ["reasoning.encrypted_content"],
|
|
28
|
+
...tools && tools.length > 0 && { tools }
|
|
29
|
+
};
|
|
36
30
|
}
|
|
37
31
|
}
|
|
38
32
|
function createGrokText(model, apiKey, config) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sources":["../../../src/adapters/text.ts"],"sourcesContent":["import OpenAI from 'openai'\nimport {
|
|
1
|
+
{"version":3,"file":"text.js","sources":["../../../src/adapters/text.ts"],"sourcesContent":["import OpenAI from 'openai'\nimport { OpenAIBaseResponsesTextAdapter } from '@tanstack/openai-base'\nimport { getGrokApiKeyFromEnv, withGrokDefaults } from '../utils/client'\nimport { convertToolsToProviderFormat } from '../tools'\nimport type {\n GROK_CHAT_MODELS,\n GrokChatModelToolCapabilitiesByName,\n ResolveInputModalities,\n ResolveProviderOptions,\n} from '../model-meta'\nimport type { Modality, TextOptions } from '@tanstack/ai'\nimport type { GrokMessageMetadataByModality } from '../message-types'\nimport type { GrokClientConfig } from '../utils'\nimport type { ResponseCreateParams } from 'openai/resources/responses/responses'\n\n/**\n * Resolve tool capabilities for a specific Grok model.\n */\ntype ResolveToolCapabilities<TModel extends string> =\n TModel extends keyof GrokChatModelToolCapabilitiesByName\n ? NonNullable<GrokChatModelToolCapabilitiesByName[TModel]>\n : readonly []\n\n/**\n * Configuration for Grok text adapter\n */\nexport interface GrokTextConfig extends GrokClientConfig {}\n\n/**\n * Alias for TextProviderOptions for external use\n */\nexport type { ExternalTextProviderOptions as GrokTextProviderOptions } from '../text/text-provider-options'\n\n/**\n * Grok Text (Chat) Adapter\n *\n * Tree-shakeable adapter for Grok chat/text completion functionality.\n * Uses xAI's OpenAI-compatible Responses API.\n *\n * Delegates implementation to {@link OpenAIBaseResponsesTextAdapter}\n * from `@tanstack/openai-base` and threads Grok-specific tool-capability\n * typing through the 5th generic of the base class.\n */\nexport class GrokTextAdapter<\n TModel extends (typeof GROK_CHAT_MODELS)[number],\n TProviderOptions extends Record<string, unknown> =\n ResolveProviderOptions<TModel>,\n TInputModalities extends ReadonlyArray<Modality> =\n ResolveInputModalities<TModel>,\n TToolCapabilities extends ReadonlyArray<string> =\n ResolveToolCapabilities<TModel>,\n> extends OpenAIBaseResponsesTextAdapter<\n TModel,\n TProviderOptions,\n TInputModalities,\n GrokMessageMetadataByModality,\n TToolCapabilities\n> {\n override readonly kind = 'text' as const\n override readonly name = 'grok' as const\n\n constructor(config: GrokTextConfig, model: TModel) {\n super(model, 'grok', new OpenAI(withGrokDefaults(config)))\n }\n\n protected override mapOptionsToRequest(\n options: TextOptions<TProviderOptions>,\n ): Omit<ResponseCreateParams, 'stream'> {\n const { tools: _baseTools, ...request } = super.mapOptionsToRequest({\n ...options,\n tools: undefined,\n })\n void _baseTools\n\n if (this.model === 'grok-build-0.1' && request.reasoning !== undefined) {\n throw new Error(\n 'grok-build-0.1 does not support reasoning modelOptions; omit reasoning for this model.',\n )\n }\n\n const tools = options.tools\n ? convertToolsToProviderFormat(options.tools)\n : undefined\n\n return {\n ...request,\n // xAI recommends encrypted reasoning for reasoning-capable Responses\n // requests; callers can still override either field in modelOptions.\n store: request.store ?? false,\n include: request.include ?? ['reasoning.encrypted_content'],\n ...(tools &&\n tools.length > 0 && { tools: tools as ResponseCreateParams['tools'] }),\n }\n }\n}\n\n/**\n * Creates a Grok text adapter with explicit API key.\n * Type resolution happens here at the call site.\n *\n * @param model - The model name (e.g., 'grok-build-0.1')\n * @param apiKey - Your xAI API key\n * @param config - Optional additional configuration\n * @returns Configured Grok text adapter instance with resolved types\n *\n * @example\n * ```typescript\n * const adapter = createGrokText('grok-build-0.1', \"xai-...\");\n * // adapter has type-safe providerOptions for grok-build-0.1\n * ```\n */\nexport function createGrokText<\n TModel extends (typeof GROK_CHAT_MODELS)[number],\n>(\n model: TModel,\n apiKey: string,\n config?: Omit<GrokTextConfig, 'apiKey'>,\n): GrokTextAdapter<TModel> {\n return new GrokTextAdapter({ apiKey, ...config }, model)\n}\n\n/**\n * Creates a Grok text 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 * @param model - The model name (e.g., 'grok-build-0.1')\n * @param config - Optional configuration (excluding apiKey which is auto-detected)\n * @returns Configured Grok text 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 = grokText('grok-build-0.1');\n *\n * const stream = chat({\n * adapter,\n * messages: [{ role: \"user\", content: \"Hello!\" }]\n * });\n * ```\n */\nexport function grokText<TModel extends (typeof GROK_CHAT_MODELS)[number]>(\n model: TModel,\n config?: Omit<GrokTextConfig, 'apiKey'>,\n): GrokTextAdapter<TModel> {\n const apiKey = getGrokApiKeyFromEnv()\n return createGrokText(model, apiKey, config)\n}\n"],"names":[],"mappings":";;;;AA2CO,MAAM,wBAQH,+BAMR;AAAA,EACkB,OAAO;AAAA,EACP,OAAO;AAAA,EAEzB,YAAY,QAAwB,OAAe;AACjD,UAAM,OAAO,QAAQ,IAAI,OAAO,iBAAiB,MAAM,CAAC,CAAC;AAAA,EAC3D;AAAA,EAEmB,oBACjB,SACsC;AACtC,UAAM,EAAE,OAAO,YAAY,GAAG,QAAA,IAAY,MAAM,oBAAoB;AAAA,MAClE,GAAG;AAAA,MACH,OAAO;AAAA,IAAA,CACR;AAGD,QAAI,KAAK,UAAU,oBAAoB,QAAQ,cAAc,QAAW;AACtE,YAAM,IAAI;AAAA,QACR;AAAA,MAAA;AAAA,IAEJ;AAEA,UAAM,QAAQ,QAAQ,QAClB,6BAA6B,QAAQ,KAAK,IAC1C;AAEJ,WAAO;AAAA,MACL,GAAG;AAAA;AAAA;AAAA,MAGH,OAAO,QAAQ,SAAS;AAAA,MACxB,SAAS,QAAQ,WAAW,CAAC,6BAA6B;AAAA,MAC1D,GAAI,SACF,MAAM,SAAS,KAAK,EAAE,MAAA;AAAA,IAA8C;AAAA,EAE1E;AACF;AAiBO,SAAS,eAGd,OACA,QACA,QACyB;AACzB,SAAO,IAAI,gBAAgB,EAAE,QAAQ,GAAG,OAAA,GAAU,KAAK;AACzD;AA0BO,SAAS,SACd,OACA,QACyB;AACzB,QAAM,SAAS,qBAAA;AACf,SAAO,eAAe,OAAO,QAAQ,MAAM;AAC7C;"}
|
package/dist/esm/model-meta.d.ts
CHANGED
|
@@ -1,215 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
readonly context_window: 2000000;
|
|
4
|
-
readonly supports: {
|
|
5
|
-
readonly input: ["text", "image"];
|
|
6
|
-
readonly output: ["text"];
|
|
7
|
-
readonly capabilities: ["reasoning", "structured_outputs", "tool_calling"];
|
|
8
|
-
readonly tools: readonly [];
|
|
9
|
-
};
|
|
10
|
-
readonly pricing: {
|
|
11
|
-
readonly input: {
|
|
12
|
-
readonly normal: 0.2;
|
|
13
|
-
readonly cached: 0.05;
|
|
14
|
-
};
|
|
15
|
-
readonly output: {
|
|
16
|
-
readonly normal: 0.5;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
declare const GROK_4_1_FAST_NON_REASONING: {
|
|
21
|
-
readonly name: "grok-4-1-fast-non-reasoning";
|
|
22
|
-
readonly context_window: 2000000;
|
|
23
|
-
readonly supports: {
|
|
24
|
-
readonly input: ["text", "image"];
|
|
25
|
-
readonly output: ["text"];
|
|
26
|
-
readonly capabilities: ["structured_outputs", "tool_calling"];
|
|
27
|
-
readonly tools: readonly [];
|
|
28
|
-
};
|
|
29
|
-
readonly pricing: {
|
|
30
|
-
readonly input: {
|
|
31
|
-
readonly normal: 0.2;
|
|
32
|
-
readonly cached: 0.05;
|
|
33
|
-
};
|
|
34
|
-
readonly output: {
|
|
35
|
-
readonly normal: 0.5;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
declare const GROK_CODE_FAST_1: {
|
|
40
|
-
readonly name: "grok-code-fast-1";
|
|
41
|
-
readonly context_window: 256000;
|
|
42
|
-
readonly supports: {
|
|
43
|
-
readonly input: ["text"];
|
|
44
|
-
readonly output: ["text"];
|
|
45
|
-
readonly capabilities: ["reasoning", "structured_outputs", "tool_calling"];
|
|
46
|
-
readonly tools: readonly [];
|
|
47
|
-
};
|
|
48
|
-
readonly pricing: {
|
|
49
|
-
readonly input: {
|
|
50
|
-
readonly normal: 0.2;
|
|
51
|
-
readonly cached: 0.02;
|
|
52
|
-
};
|
|
53
|
-
readonly output: {
|
|
54
|
-
readonly normal: 1.5;
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
declare const GROK_4_FAST_REASONING: {
|
|
59
|
-
readonly name: "grok-4-fast-reasoning";
|
|
60
|
-
readonly context_window: 2000000;
|
|
61
|
-
readonly supports: {
|
|
62
|
-
readonly input: ["text", "image"];
|
|
63
|
-
readonly output: ["text"];
|
|
64
|
-
readonly capabilities: ["reasoning", "structured_outputs", "tool_calling"];
|
|
65
|
-
readonly tools: readonly [];
|
|
66
|
-
};
|
|
67
|
-
readonly pricing: {
|
|
68
|
-
readonly input: {
|
|
69
|
-
readonly normal: 0.2;
|
|
70
|
-
readonly cached: 0.05;
|
|
71
|
-
};
|
|
72
|
-
readonly output: {
|
|
73
|
-
readonly normal: 0.5;
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
};
|
|
77
|
-
declare const GROK_4_FAST_NON_REASONING: {
|
|
78
|
-
readonly name: "grok-4-fast-non-reasoning";
|
|
79
|
-
readonly context_window: 2000000;
|
|
80
|
-
readonly supports: {
|
|
81
|
-
readonly input: ["text", "image"];
|
|
82
|
-
readonly output: ["text"];
|
|
83
|
-
readonly capabilities: ["structured_outputs", "tool_calling"];
|
|
84
|
-
readonly tools: readonly [];
|
|
85
|
-
};
|
|
86
|
-
readonly pricing: {
|
|
87
|
-
readonly input: {
|
|
88
|
-
readonly normal: 0.2;
|
|
89
|
-
readonly cached: 0.05;
|
|
90
|
-
};
|
|
91
|
-
readonly output: {
|
|
92
|
-
readonly normal: 0.5;
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
};
|
|
96
|
-
declare const GROK_4: {
|
|
97
|
-
readonly name: "grok-4";
|
|
98
|
-
readonly context_window: 256000;
|
|
99
|
-
readonly supports: {
|
|
100
|
-
readonly input: ["text", "image"];
|
|
101
|
-
readonly output: ["text"];
|
|
102
|
-
readonly capabilities: ["reasoning", "structured_outputs", "tool_calling"];
|
|
103
|
-
readonly tools: readonly [];
|
|
104
|
-
};
|
|
105
|
-
readonly pricing: {
|
|
106
|
-
readonly input: {
|
|
107
|
-
readonly normal: 3;
|
|
108
|
-
readonly cached: 0.75;
|
|
109
|
-
};
|
|
110
|
-
readonly output: {
|
|
111
|
-
readonly normal: 15;
|
|
112
|
-
};
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
declare const GROK_3_MINI: {
|
|
116
|
-
readonly name: "grok-3-mini";
|
|
117
|
-
readonly context_window: 131072;
|
|
118
|
-
readonly supports: {
|
|
119
|
-
readonly input: ["text"];
|
|
120
|
-
readonly output: ["text"];
|
|
121
|
-
readonly capabilities: ["reasoning", "structured_outputs", "tool_calling"];
|
|
122
|
-
readonly tools: readonly [];
|
|
123
|
-
};
|
|
124
|
-
readonly pricing: {
|
|
125
|
-
readonly input: {
|
|
126
|
-
readonly normal: 0.3;
|
|
127
|
-
readonly cached: 0.075;
|
|
128
|
-
};
|
|
129
|
-
readonly output: {
|
|
130
|
-
readonly normal: 0.5;
|
|
131
|
-
};
|
|
132
|
-
};
|
|
133
|
-
};
|
|
134
|
-
declare const GROK_3: {
|
|
135
|
-
readonly name: "grok-3";
|
|
136
|
-
readonly context_window: 131072;
|
|
137
|
-
readonly supports: {
|
|
138
|
-
readonly input: ["text"];
|
|
139
|
-
readonly output: ["text"];
|
|
140
|
-
readonly capabilities: ["structured_outputs", "tool_calling"];
|
|
141
|
-
readonly tools: readonly [];
|
|
142
|
-
};
|
|
143
|
-
readonly pricing: {
|
|
144
|
-
readonly input: {
|
|
145
|
-
readonly normal: 3;
|
|
146
|
-
readonly cached: 0.75;
|
|
147
|
-
};
|
|
148
|
-
readonly output: {
|
|
149
|
-
readonly normal: 15;
|
|
150
|
-
};
|
|
151
|
-
};
|
|
152
|
-
};
|
|
153
|
-
declare const GROK_2_VISION: {
|
|
154
|
-
readonly name: "grok-2-vision-1212";
|
|
155
|
-
readonly context_window: 32768;
|
|
156
|
-
readonly supports: {
|
|
157
|
-
readonly input: ["text", "image"];
|
|
158
|
-
readonly output: ["text"];
|
|
159
|
-
readonly capabilities: ["structured_outputs", "tool_calling"];
|
|
160
|
-
readonly tools: readonly [];
|
|
161
|
-
};
|
|
162
|
-
readonly pricing: {
|
|
163
|
-
readonly input: {
|
|
164
|
-
readonly normal: 2;
|
|
165
|
-
};
|
|
166
|
-
readonly output: {
|
|
167
|
-
readonly normal: 10;
|
|
168
|
-
};
|
|
169
|
-
};
|
|
170
|
-
};
|
|
171
|
-
/**
|
|
172
|
-
* Grok Chat Models
|
|
173
|
-
* Based on xAI's available models as of 2025
|
|
174
|
-
*/
|
|
175
|
-
declare const GROK_4_20: {
|
|
176
|
-
readonly name: "grok-4.20";
|
|
177
|
-
readonly context_window: 2000000;
|
|
178
|
-
readonly supports: {
|
|
179
|
-
readonly input: ["text", "image", "document"];
|
|
180
|
-
readonly output: ["text"];
|
|
181
|
-
readonly capabilities: ["reasoning", "structured_outputs", "tool_calling"];
|
|
182
|
-
readonly tools: readonly [];
|
|
183
|
-
};
|
|
184
|
-
readonly pricing: {
|
|
185
|
-
readonly input: {
|
|
186
|
-
readonly normal: 2;
|
|
187
|
-
readonly cached: 0.2;
|
|
188
|
-
};
|
|
189
|
-
readonly output: {
|
|
190
|
-
readonly normal: 6;
|
|
191
|
-
};
|
|
192
|
-
};
|
|
193
|
-
};
|
|
194
|
-
declare const GROK_4_20_MULTI_AGENT: {
|
|
195
|
-
readonly name: "grok-4.20-multi-agent";
|
|
196
|
-
readonly context_window: 2000000;
|
|
197
|
-
readonly supports: {
|
|
198
|
-
readonly input: ["text", "image", "document"];
|
|
199
|
-
readonly output: ["text"];
|
|
200
|
-
readonly capabilities: ["reasoning", "structured_outputs", "tool_calling"];
|
|
201
|
-
readonly tools: readonly [];
|
|
202
|
-
};
|
|
203
|
-
readonly pricing: {
|
|
204
|
-
readonly input: {
|
|
205
|
-
readonly normal: 2;
|
|
206
|
-
readonly cached: 0.2;
|
|
207
|
-
};
|
|
208
|
-
readonly output: {
|
|
209
|
-
readonly normal: 6;
|
|
210
|
-
};
|
|
211
|
-
};
|
|
212
|
-
};
|
|
1
|
+
import { GrokBuildProviderOptions, GrokTextProviderOptions } from './text/text-provider-options.js';
|
|
2
|
+
export type GrokProviderToolKind = 'web_search' | 'x_search' | 'file_search' | 'mcp';
|
|
213
3
|
declare const GROK_4_3: {
|
|
214
4
|
readonly name: "grok-4.3";
|
|
215
5
|
readonly context_window: 1000000;
|
|
@@ -217,7 +7,7 @@ declare const GROK_4_3: {
|
|
|
217
7
|
readonly input: ["text", "image"];
|
|
218
8
|
readonly output: ["text"];
|
|
219
9
|
readonly capabilities: ["reasoning", "structured_outputs", "tool_calling"];
|
|
220
|
-
readonly tools: readonly [];
|
|
10
|
+
readonly tools: readonly ["web_search", "x_search", "file_search", "mcp"];
|
|
221
11
|
};
|
|
222
12
|
readonly pricing: {
|
|
223
13
|
readonly input: {
|
|
@@ -236,7 +26,7 @@ declare const GROK_BUILD_0_1: {
|
|
|
236
26
|
readonly input: ["text", "image"];
|
|
237
27
|
readonly output: ["text"];
|
|
238
28
|
readonly capabilities: ["reasoning", "structured_outputs", "tool_calling"];
|
|
239
|
-
readonly tools: readonly [];
|
|
29
|
+
readonly tools: readonly ["web_search", "x_search", "file_search", "mcp"];
|
|
240
30
|
};
|
|
241
31
|
readonly pricing: {
|
|
242
32
|
readonly input: {
|
|
@@ -248,20 +38,10 @@ declare const GROK_BUILD_0_1: {
|
|
|
248
38
|
};
|
|
249
39
|
};
|
|
250
40
|
};
|
|
251
|
-
export declare const GROK_CHAT_MODELS: readonly ["grok-4-1-fast-reasoning", "grok-4-1-fast-non-reasoning", "grok-code-fast-1", "grok-4-fast-reasoning", "grok-4-fast-non-reasoning", "grok-4", "grok-3", "grok-3-mini", "grok-2-vision-1212", "grok-4.20", "grok-4.20-multi-agent", "grok-4.3", "grok-build-0.1"];
|
|
252
41
|
/**
|
|
253
|
-
* Grok models
|
|
254
|
-
* in a single streaming Chat Completions request (per issue #605). xAI
|
|
255
|
-
* docs gate this to the Grok 4 family — Grok 2 / 3 reject the
|
|
256
|
-
* combination. Grok 2 image generation is not a chat model, omitted.
|
|
257
|
-
*
|
|
258
|
-
* Note: Grok streams tool-call arguments atomically (not token-streamed)
|
|
259
|
-
* per the issue's source matrix; partial-JSON tool-arg parsing should be
|
|
260
|
-
* skipped for Grok specifically. That's a separate adapter concern from
|
|
261
|
-
* this set — the set only gates whether the engine takes the native
|
|
262
|
-
* combined path vs the legacy finalization path.
|
|
42
|
+
* Grok chat models supported by the Responses adapter.
|
|
263
43
|
*/
|
|
264
|
-
export declare const
|
|
44
|
+
export declare const GROK_CHAT_MODELS: readonly ["grok-build-0.1", "grok-4.3"];
|
|
265
45
|
/**
|
|
266
46
|
* Grok Image Generation Models
|
|
267
47
|
*/
|
|
@@ -279,66 +59,26 @@ export type GrokRealtimeModel = (typeof GROK_REALTIME_MODELS)[number];
|
|
|
279
59
|
* Used for type inference when constructing multimodal messages.
|
|
280
60
|
*/
|
|
281
61
|
export type GrokModelInputModalitiesByName = {
|
|
282
|
-
[GROK_4_1_FAST_REASONING.name]: typeof GROK_4_1_FAST_REASONING.supports.input;
|
|
283
|
-
[GROK_4_1_FAST_NON_REASONING.name]: typeof GROK_4_1_FAST_NON_REASONING.supports.input;
|
|
284
|
-
[GROK_CODE_FAST_1.name]: typeof GROK_CODE_FAST_1.supports.input;
|
|
285
|
-
[GROK_4_FAST_REASONING.name]: typeof GROK_4_FAST_REASONING.supports.input;
|
|
286
|
-
[GROK_4_FAST_NON_REASONING.name]: typeof GROK_4_FAST_NON_REASONING.supports.input;
|
|
287
|
-
[GROK_4.name]: typeof GROK_4.supports.input;
|
|
288
|
-
[GROK_3.name]: typeof GROK_3.supports.input;
|
|
289
|
-
[GROK_3_MINI.name]: typeof GROK_3_MINI.supports.input;
|
|
290
|
-
[GROK_2_VISION.name]: typeof GROK_2_VISION.supports.input;
|
|
291
|
-
[GROK_4_20.name]: typeof GROK_4_20.supports.input;
|
|
292
|
-
[GROK_4_20_MULTI_AGENT.name]: typeof GROK_4_20_MULTI_AGENT.supports.input;
|
|
293
62
|
[GROK_4_3.name]: typeof GROK_4_3.supports.input;
|
|
294
63
|
[GROK_BUILD_0_1.name]: typeof GROK_BUILD_0_1.supports.input;
|
|
295
64
|
};
|
|
296
|
-
/**
|
|
297
|
-
* Type-only map from Grok chat model name to its provider options type.
|
|
298
|
-
* Since Grok uses OpenAI-compatible API, we reuse OpenAI provider options.
|
|
299
|
-
*/
|
|
300
|
-
export type GrokChatModelProviderOptionsByName = {
|
|
301
|
-
[K in (typeof GROK_CHAT_MODELS)[number]]: GrokProviderOptions;
|
|
302
|
-
};
|
|
303
65
|
/**
|
|
304
66
|
* Type-only map from Grok chat model name to its supported provider tools.
|
|
305
|
-
* Grok
|
|
306
|
-
*
|
|
307
|
-
* a Grok adapter produces a compile-time type error.
|
|
67
|
+
* Keeps Grok provider-tool factories type-checked against the models that
|
|
68
|
+
* advertise xAI Responses server-side tools.
|
|
308
69
|
*/
|
|
309
70
|
export type GrokChatModelToolCapabilitiesByName = {
|
|
310
|
-
[
|
|
311
|
-
[
|
|
312
|
-
[GROK_CODE_FAST_1.name]: typeof GROK_CODE_FAST_1.supports.tools;
|
|
313
|
-
[GROK_4_FAST_REASONING.name]: typeof GROK_4_FAST_REASONING.supports.tools;
|
|
314
|
-
[GROK_4_FAST_NON_REASONING.name]: typeof GROK_4_FAST_NON_REASONING.supports.tools;
|
|
315
|
-
[GROK_4.name]: typeof GROK_4.supports.tools;
|
|
316
|
-
[GROK_3.name]: typeof GROK_3.supports.tools;
|
|
317
|
-
[GROK_3_MINI.name]: typeof GROK_3_MINI.supports.tools;
|
|
318
|
-
[GROK_2_VISION.name]: typeof GROK_2_VISION.supports.tools;
|
|
319
|
-
[GROK_4_20.name]: typeof GROK_4_20.supports.tools;
|
|
320
|
-
[GROK_4_20_MULTI_AGENT.name]: typeof GROK_4_20_MULTI_AGENT.supports.tools;
|
|
71
|
+
[GROK_4_3.name]: typeof GROK_4_3.supports.tools;
|
|
72
|
+
[GROK_BUILD_0_1.name]: typeof GROK_BUILD_0_1.supports.tools;
|
|
321
73
|
};
|
|
74
|
+
export type GrokProviderOptions = GrokTextProviderOptions;
|
|
322
75
|
/**
|
|
323
|
-
*
|
|
324
|
-
* Based on OpenAI-compatible API options
|
|
76
|
+
* Type-only map from Grok chat model name to its provider options type.
|
|
325
77
|
*/
|
|
326
|
-
export
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
max_tokens?: number;
|
|
331
|
-
/** Top-p sampling parameter */
|
|
332
|
-
top_p?: number;
|
|
333
|
-
/** Frequency penalty (-2.0 to 2.0) */
|
|
334
|
-
frequency_penalty?: number;
|
|
335
|
-
/** Presence penalty (-2.0 to 2.0) */
|
|
336
|
-
presence_penalty?: number;
|
|
337
|
-
/** Stop sequences */
|
|
338
|
-
stop?: string | Array<string>;
|
|
339
|
-
/** A unique identifier representing your end-user */
|
|
340
|
-
user?: string;
|
|
341
|
-
}
|
|
78
|
+
export type GrokChatModelProviderOptionsByName = {
|
|
79
|
+
[GROK_4_3.name]: GrokProviderOptions;
|
|
80
|
+
[GROK_BUILD_0_1.name]: GrokBuildProviderOptions;
|
|
81
|
+
};
|
|
342
82
|
/**
|
|
343
83
|
* Resolve provider options for a specific model.
|
|
344
84
|
* If the model has explicit options in the map, use those; otherwise use base options.
|