@tanstack/ai-grok 0.14.4 → 0.14.6
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.
|
@@ -27,7 +27,7 @@ export type { ExternalTextProviderOptions as GrokTextProviderOptions } from '../
|
|
|
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, any> = 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);
|
|
@@ -1 +1 @@
|
|
|
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,
|
|
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 // Use `Record<string, any>` (not `unknown`) to match the OpenAI text\n // adapter: the resolved Grok provider options are a type-alias intersection\n // with no explicit index signature, which is assignable to\n // `Record<string, any>` but not `Record<string, unknown>`. See issue #821.\n TProviderOptions extends Record<string, any> = 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,wBAWH,+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;"}
|
|
@@ -14,10 +14,9 @@ export interface GrokBaseOptions {
|
|
|
14
14
|
user?: string;
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
* Based on xAI Responses API options
|
|
17
|
+
* Sampling and response controls for Grok text/chat models.
|
|
19
18
|
*/
|
|
20
|
-
export interface
|
|
19
|
+
export interface GrokSamplingOptions {
|
|
21
20
|
/**
|
|
22
21
|
* Temperature for response generation (0-2)
|
|
23
22
|
* Higher values make output more random, lower values more focused
|
|
@@ -45,6 +44,20 @@ export interface GrokTextProviderOptions extends GrokBaseOptions, Record<string,
|
|
|
45
44
|
*/
|
|
46
45
|
reasoning?: GrokReasoning;
|
|
47
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Grok-specific provider options for text/chat
|
|
49
|
+
* Based on xAI Responses API options.
|
|
50
|
+
*
|
|
51
|
+
* Declared as a type-alias intersection of interfaces with all-optional props
|
|
52
|
+
* (matching the OpenAI text adapter), NOT an `interface ... extends
|
|
53
|
+
* Record<string, unknown>`. An explicit index signature makes `object`
|
|
54
|
+
* un-assignable to these options, which breaks the contravariantly-checked
|
|
55
|
+
* `summarize()` adapter constraint (`SummarizeAdapter<string, object>`); see
|
|
56
|
+
* issue #821. Without the index signature these options no longer satisfy a
|
|
57
|
+
* `Record<string, unknown>` constraint, so the text adapter's provider-options
|
|
58
|
+
* generic is widened to `Record<string, any>` to match OpenAI.
|
|
59
|
+
*/
|
|
60
|
+
export type GrokTextProviderOptions = GrokBaseOptions & GrokSamplingOptions;
|
|
48
61
|
export type GrokBuildProviderOptions = Omit<GrokTextProviderOptions, 'reasoning'> & {
|
|
49
62
|
reasoning?: never;
|
|
50
63
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/ai-grok",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.6",
|
|
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",
|
|
@@ -51,16 +51,16 @@
|
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"openai": "^6.41.0",
|
|
53
53
|
"@tanstack/ai-utils": "0.3.1",
|
|
54
|
-
"@tanstack/openai-base": "0.9.
|
|
54
|
+
"@tanstack/openai-base": "0.9.6"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@vitest/coverage-v8": "4.0.14",
|
|
58
58
|
"vite": "^7.3.3",
|
|
59
|
-
"@tanstack/ai": "0.
|
|
59
|
+
"@tanstack/ai": "0.39.0"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|
|
62
62
|
"zod": "^4.0.0",
|
|
63
|
-
"@tanstack/ai": "^0.
|
|
63
|
+
"@tanstack/ai": "^0.39.0"
|
|
64
64
|
},
|
|
65
65
|
"scripts": {
|
|
66
66
|
"build": "vite build",
|
package/src/adapters/text.ts
CHANGED
|
@@ -43,8 +43,11 @@ export type { ExternalTextProviderOptions as GrokTextProviderOptions } from '../
|
|
|
43
43
|
*/
|
|
44
44
|
export class GrokTextAdapter<
|
|
45
45
|
TModel extends (typeof GROK_CHAT_MODELS)[number],
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
// Use `Record<string, any>` (not `unknown`) to match the OpenAI text
|
|
47
|
+
// adapter: the resolved Grok provider options are a type-alias intersection
|
|
48
|
+
// with no explicit index signature, which is assignable to
|
|
49
|
+
// `Record<string, any>` but not `Record<string, unknown>`. See issue #821.
|
|
50
|
+
TProviderOptions extends Record<string, any> = ResolveProviderOptions<TModel>,
|
|
48
51
|
TInputModalities extends ReadonlyArray<Modality> =
|
|
49
52
|
ResolveInputModalities<TModel>,
|
|
50
53
|
TToolCapabilities extends ReadonlyArray<string> =
|
|
@@ -29,11 +29,9 @@ export interface GrokBaseOptions {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
33
|
-
* Based on xAI Responses API options
|
|
32
|
+
* Sampling and response controls for Grok text/chat models.
|
|
34
33
|
*/
|
|
35
|
-
export interface
|
|
36
|
-
extends GrokBaseOptions, Record<string, unknown> {
|
|
34
|
+
export interface GrokSamplingOptions {
|
|
37
35
|
/**
|
|
38
36
|
* Temperature for response generation (0-2)
|
|
39
37
|
* Higher values make output more random, lower values more focused
|
|
@@ -62,6 +60,21 @@ export interface GrokTextProviderOptions
|
|
|
62
60
|
reasoning?: GrokReasoning
|
|
63
61
|
}
|
|
64
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Grok-specific provider options for text/chat
|
|
65
|
+
* Based on xAI Responses API options.
|
|
66
|
+
*
|
|
67
|
+
* Declared as a type-alias intersection of interfaces with all-optional props
|
|
68
|
+
* (matching the OpenAI text adapter), NOT an `interface ... extends
|
|
69
|
+
* Record<string, unknown>`. An explicit index signature makes `object`
|
|
70
|
+
* un-assignable to these options, which breaks the contravariantly-checked
|
|
71
|
+
* `summarize()` adapter constraint (`SummarizeAdapter<string, object>`); see
|
|
72
|
+
* issue #821. Without the index signature these options no longer satisfy a
|
|
73
|
+
* `Record<string, unknown>` constraint, so the text adapter's provider-options
|
|
74
|
+
* generic is widened to `Record<string, any>` to match OpenAI.
|
|
75
|
+
*/
|
|
76
|
+
export type GrokTextProviderOptions = GrokBaseOptions & GrokSamplingOptions
|
|
77
|
+
|
|
65
78
|
export type GrokBuildProviderOptions = Omit<
|
|
66
79
|
GrokTextProviderOptions,
|
|
67
80
|
'reasoning'
|