@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/dist/esm/model-meta.js
CHANGED
|
@@ -1,30 +1,3 @@
|
|
|
1
|
-
const GROK_4_1_FAST_REASONING = {
|
|
2
|
-
name: "grok-4-1-fast-reasoning"
|
|
3
|
-
};
|
|
4
|
-
const GROK_4_1_FAST_NON_REASONING = {
|
|
5
|
-
name: "grok-4-1-fast-non-reasoning"
|
|
6
|
-
};
|
|
7
|
-
const GROK_CODE_FAST_1 = {
|
|
8
|
-
name: "grok-code-fast-1"
|
|
9
|
-
};
|
|
10
|
-
const GROK_4_FAST_REASONING = {
|
|
11
|
-
name: "grok-4-fast-reasoning"
|
|
12
|
-
};
|
|
13
|
-
const GROK_4_FAST_NON_REASONING = {
|
|
14
|
-
name: "grok-4-fast-non-reasoning"
|
|
15
|
-
};
|
|
16
|
-
const GROK_4 = {
|
|
17
|
-
name: "grok-4"
|
|
18
|
-
};
|
|
19
|
-
const GROK_3_MINI = {
|
|
20
|
-
name: "grok-3-mini"
|
|
21
|
-
};
|
|
22
|
-
const GROK_3 = {
|
|
23
|
-
name: "grok-3"
|
|
24
|
-
};
|
|
25
|
-
const GROK_2_VISION = {
|
|
26
|
-
name: "grok-2-vision-1212"
|
|
27
|
-
};
|
|
28
1
|
const GROK_2_IMAGE = {
|
|
29
2
|
name: "grok-2-image-1212"
|
|
30
3
|
};
|
|
@@ -34,44 +7,13 @@ const GROK_IMAGINE_IMAGE = {
|
|
|
34
7
|
const GROK_IMAGINE_IMAGE_QUALITY = {
|
|
35
8
|
name: "grok-imagine-image-quality"
|
|
36
9
|
};
|
|
37
|
-
const GROK_4_20 = {
|
|
38
|
-
name: "grok-4.20"
|
|
39
|
-
};
|
|
40
|
-
const GROK_4_20_MULTI_AGENT = {
|
|
41
|
-
name: "grok-4.20-multi-agent"
|
|
42
|
-
};
|
|
43
10
|
const GROK_4_3 = {
|
|
44
11
|
name: "grok-4.3"
|
|
45
12
|
};
|
|
46
13
|
const GROK_BUILD_0_1 = {
|
|
47
14
|
name: "grok-build-0.1"
|
|
48
15
|
};
|
|
49
|
-
const GROK_CHAT_MODELS = [
|
|
50
|
-
GROK_4_1_FAST_REASONING.name,
|
|
51
|
-
GROK_4_1_FAST_NON_REASONING.name,
|
|
52
|
-
GROK_CODE_FAST_1.name,
|
|
53
|
-
GROK_4_FAST_REASONING.name,
|
|
54
|
-
GROK_4_FAST_NON_REASONING.name,
|
|
55
|
-
GROK_4.name,
|
|
56
|
-
GROK_3.name,
|
|
57
|
-
GROK_3_MINI.name,
|
|
58
|
-
GROK_2_VISION.name,
|
|
59
|
-
GROK_4_20.name,
|
|
60
|
-
GROK_4_20_MULTI_AGENT.name,
|
|
61
|
-
GROK_4_3.name,
|
|
62
|
-
GROK_BUILD_0_1.name
|
|
63
|
-
];
|
|
64
|
-
const GROK_COMBINED_TOOLS_AND_SCHEMA_MODELS = /* @__PURE__ */ new Set([
|
|
65
|
-
GROK_4_1_FAST_REASONING.name,
|
|
66
|
-
GROK_4_1_FAST_NON_REASONING.name,
|
|
67
|
-
GROK_CODE_FAST_1.name,
|
|
68
|
-
GROK_4_FAST_REASONING.name,
|
|
69
|
-
GROK_4_FAST_NON_REASONING.name,
|
|
70
|
-
GROK_4.name,
|
|
71
|
-
GROK_4_20.name,
|
|
72
|
-
GROK_4_20_MULTI_AGENT.name,
|
|
73
|
-
GROK_4_3.name
|
|
74
|
-
]);
|
|
16
|
+
const GROK_CHAT_MODELS = [GROK_BUILD_0_1.name, GROK_4_3.name];
|
|
75
17
|
const GROK_IMAGE_MODELS = [
|
|
76
18
|
GROK_2_IMAGE.name,
|
|
77
19
|
GROK_IMAGINE_IMAGE.name,
|
|
@@ -97,7 +39,6 @@ const GROK_REALTIME_MODELS = [
|
|
|
97
39
|
];
|
|
98
40
|
export {
|
|
99
41
|
GROK_CHAT_MODELS,
|
|
100
|
-
GROK_COMBINED_TOOLS_AND_SCHEMA_MODELS,
|
|
101
42
|
GROK_IMAGE_MODELS,
|
|
102
43
|
GROK_REALTIME_MODELS,
|
|
103
44
|
GROK_TRANSCRIPTION_MODELS,
|
|
@@ -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 */\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<never>\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\nconst GROK_4_1_FAST_REASONING = {\n name: 'grok-4-1-fast-reasoning',\n context_window: 2_000_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n pricing: {\n input: {\n normal: 0.2,\n cached: 0.05,\n },\n output: {\n normal: 0.5,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_1_FAST_NON_REASONING = {\n name: 'grok-4-1-fast-non-reasoning',\n context_window: 2_000_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n pricing: {\n input: {\n normal: 0.2,\n cached: 0.05,\n },\n output: {\n normal: 0.5,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_CODE_FAST_1 = {\n name: 'grok-code-fast-1',\n context_window: 256_000,\n supports: {\n input: ['text'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n pricing: {\n input: {\n normal: 0.2,\n cached: 0.02,\n },\n output: {\n normal: 1.5,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_FAST_REASONING = {\n name: 'grok-4-fast-reasoning',\n context_window: 2_000_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n pricing: {\n input: {\n normal: 0.2,\n cached: 0.05,\n },\n output: {\n normal: 0.5,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_FAST_NON_REASONING = {\n name: 'grok-4-fast-non-reasoning',\n context_window: 2_000_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n pricing: {\n input: {\n normal: 0.2,\n cached: 0.05,\n },\n output: {\n normal: 0.5,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_4 = {\n name: 'grok-4',\n context_window: 256_000,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n pricing: {\n input: {\n normal: 3,\n cached: 0.75,\n },\n output: {\n normal: 15,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_3_MINI = {\n name: 'grok-3-mini',\n context_window: 131_072,\n supports: {\n input: ['text'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n pricing: {\n input: {\n normal: 0.3,\n cached: 0.075,\n },\n output: {\n normal: 0.5,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_3 = {\n name: 'grok-3',\n context_window: 131_072,\n supports: {\n input: ['text'],\n output: ['text'],\n capabilities: ['structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n pricing: {\n input: {\n normal: 3,\n cached: 0.75,\n },\n output: {\n normal: 15,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_2_VISION = {\n name: 'grok-2-vision-1212',\n context_window: 32_768,\n supports: {\n input: ['text', 'image'],\n output: ['text'],\n capabilities: ['structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n pricing: {\n input: {\n normal: 2,\n },\n output: {\n normal: 10,\n },\n },\n} as const satisfies ModelMeta\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/**\n * Grok Chat Models\n * Based on xAI's available models as of 2025\n */\nconst GROK_4_20 = {\n name: 'grok-4.20',\n context_window: 2_000_000,\n supports: {\n input: ['text', 'image', 'document'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n pricing: {\n input: {\n normal: 2,\n cached: 0.2,\n },\n output: {\n normal: 6,\n },\n },\n} as const satisfies ModelMeta\n\nconst GROK_4_20_MULTI_AGENT = {\n name: 'grok-4.20-multi-agent',\n context_window: 2_000_000,\n supports: {\n input: ['text', 'image', 'document'],\n output: ['text'],\n capabilities: ['reasoning', 'structured_outputs', 'tool_calling'],\n tools: [] as const,\n },\n pricing: {\n input: {\n normal: 2,\n cached: 0.2,\n },\n output: {\n normal: 6,\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: [],\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: [],\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\nexport const GROK_CHAT_MODELS = [\n GROK_4_1_FAST_REASONING.name,\n GROK_4_1_FAST_NON_REASONING.name,\n GROK_CODE_FAST_1.name,\n GROK_4_FAST_REASONING.name,\n GROK_4_FAST_NON_REASONING.name,\n GROK_4.name,\n GROK_3.name,\n GROK_3_MINI.name,\n GROK_2_VISION.name,\n\n GROK_4_20.name,\n GROK_4_20_MULTI_AGENT.name,\n\n GROK_4_3.name,\n\n GROK_BUILD_0_1.name,\n] as const\n\n/**\n * Grok models that support combining `tools` + `response_format: json_schema`\n * in a single streaming Chat Completions request (per issue #605). xAI\n * docs gate this to the Grok 4 family — Grok 2 / 3 reject the\n * combination. Grok 2 image generation is not a chat model, omitted.\n *\n * Note: Grok streams tool-call arguments atomically (not token-streamed)\n * per the issue's source matrix; partial-JSON tool-arg parsing should be\n * skipped for Grok specifically. That's a separate adapter concern from\n * this set — the set only gates whether the engine takes the native\n * combined path vs the legacy finalization path.\n */\nexport const GROK_COMBINED_TOOLS_AND_SCHEMA_MODELS = new Set<string>([\n GROK_4_1_FAST_REASONING.name,\n GROK_4_1_FAST_NON_REASONING.name,\n GROK_CODE_FAST_1.name,\n GROK_4_FAST_REASONING.name,\n GROK_4_FAST_NON_REASONING.name,\n GROK_4.name,\n GROK_4_20.name,\n GROK_4_20_MULTI_AGENT.name,\n GROK_4_3.name,\n])\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// 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 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_1_FAST_REASONING.name]: typeof GROK_4_1_FAST_REASONING.supports.input\n [GROK_4_1_FAST_NON_REASONING.name]: typeof GROK_4_1_FAST_NON_REASONING.supports.input\n [GROK_CODE_FAST_1.name]: typeof GROK_CODE_FAST_1.supports.input\n [GROK_4_FAST_REASONING.name]: typeof GROK_4_FAST_REASONING.supports.input\n [GROK_4_FAST_NON_REASONING.name]: typeof GROK_4_FAST_NON_REASONING.supports.input\n [GROK_4.name]: typeof GROK_4.supports.input\n [GROK_3.name]: typeof GROK_3.supports.input\n [GROK_3_MINI.name]: typeof GROK_3_MINI.supports.input\n [GROK_2_VISION.name]: typeof GROK_2_VISION.supports.input\n [GROK_4_20.name]: typeof GROK_4_20.supports.input\n [GROK_4_20_MULTI_AGENT.name]: typeof GROK_4_20_MULTI_AGENT.supports.input\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 provider options type.\n * Since Grok uses OpenAI-compatible API, we reuse OpenAI provider options.\n */\nexport type GrokChatModelProviderOptionsByName = {\n [K in (typeof GROK_CHAT_MODELS)[number]]: GrokProviderOptions\n}\n\n/**\n * Type-only map from Grok chat model name to its supported provider tools.\n * Grok exposes no provider-specific tool factories, so every model gets an\n * empty tuple. This ensures that passing an Anthropic/OpenAI ProviderTool to\n * a Grok adapter produces a compile-time type error.\n */\nexport type GrokChatModelToolCapabilitiesByName = {\n [GROK_4_1_FAST_REASONING.name]: typeof GROK_4_1_FAST_REASONING.supports.tools\n [GROK_4_1_FAST_NON_REASONING.name]: typeof GROK_4_1_FAST_NON_REASONING.supports.tools\n [GROK_CODE_FAST_1.name]: typeof GROK_CODE_FAST_1.supports.tools\n [GROK_4_FAST_REASONING.name]: typeof GROK_4_FAST_REASONING.supports.tools\n [GROK_4_FAST_NON_REASONING.name]: typeof GROK_4_FAST_NON_REASONING.supports.tools\n [GROK_4.name]: typeof GROK_4.supports.tools\n [GROK_3.name]: typeof GROK_3.supports.tools\n [GROK_3_MINI.name]: typeof GROK_3_MINI.supports.tools\n [GROK_2_VISION.name]: typeof GROK_2_VISION.supports.tools\n [GROK_4_20.name]: typeof GROK_4_20.supports.tools\n [GROK_4_20_MULTI_AGENT.name]: typeof GROK_4_20_MULTI_AGENT.supports.tools\n}\n\n/**\n * Grok-specific provider options\n * Based on OpenAI-compatible API options\n */\nexport interface GrokProviderOptions {\n /** Temperature for response generation (0-2) */\n temperature?: number\n /** Maximum tokens in the response */\n max_tokens?: number\n /** Top-p sampling parameter */\n top_p?: number\n /** Frequency penalty (-2.0 to 2.0) */\n frequency_penalty?: number\n /** Presence penalty (-2.0 to 2.0) */\n presence_penalty?: number\n /** Stop sequences */\n stop?: string | Array<string>\n /** A unique identifier representing your end-user */\n user?: string\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":"AA0BA,MAAM,0BAA0B;AAAA,EAC9B,MAAM;AAiBR;AAEA,MAAM,8BAA8B;AAAA,EAClC,MAAM;AAiBR;AAEA,MAAM,mBAAmB;AAAA,EACvB,MAAM;AAiBR;AAEA,MAAM,wBAAwB;AAAA,EAC5B,MAAM;AAiBR;AAEA,MAAM,4BAA4B;AAAA,EAChC,MAAM;AAiBR;AAEA,MAAM,SAAS;AAAA,EACb,MAAM;AAiBR;AAEA,MAAM,cAAc;AAAA,EAClB,MAAM;AAiBR;AAEA,MAAM,SAAS;AAAA,EACb,MAAM;AAiBR;AAEA,MAAM,gBAAgB;AAAA,EACpB,MAAM;AAgBR;AAEA,MAAM,eAAe;AAAA,EACnB,MAAM;AAaR;AAGA,MAAM,qBAAqB;AAAA,EACzB,MAAM;AAaR;AAEA,MAAM,6BAA6B;AAAA,EACjC,MAAM;AAaR;AAMA,MAAM,YAAY;AAAA,EAChB,MAAM;AAiBR;AAEA,MAAM,wBAAwB;AAAA,EAC5B,MAAM;AAiBR;AAEA,MAAM,WAAW;AAAA,EACf,MAAM;AAiBR;AAEA,MAAM,iBAAiB;AAAA,EACrB,MAAM;AAiBR;AAEO,MAAM,mBAAmB;AAAA,EAC9B,wBAAwB;AAAA,EACxB,4BAA4B;AAAA,EAC5B,iBAAiB;AAAA,EACjB,sBAAsB;AAAA,EACtB,0BAA0B;AAAA,EAC1B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,YAAY;AAAA,EACZ,cAAc;AAAA,EAEd,UAAU;AAAA,EACV,sBAAsB;AAAA,EAEtB,SAAS;AAAA,EAET,eAAe;AACjB;AAcO,MAAM,4DAA4C,IAAY;AAAA,EACnE,wBAAwB;AAAA,EACxB,4BAA4B;AAAA,EAC5B,iBAAiB;AAAA,EACjB,sBAAsB;AAAA,EACtB,0BAA0B;AAAA,EAC1B,OAAO;AAAA,EACP,UAAU;AAAA,EACV,sBAAsB;AAAA,EACtB,SAAS;AACX,CAAC;AAKM,MAAM,oBAAoB;AAAA,EAC/B,aAAa;AAAA,EACb,mBAAmB;AAAA,EACnB,2BAA2B;AAC7B;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","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\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// 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 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;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;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,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
*/
|
|
1
|
+
import { ResponseCreateParams } from 'openai/resources/responses/responses';
|
|
2
|
+
export type GrokReasoningEffort = 'none' | 'low' | 'medium' | 'high';
|
|
3
|
+
export type GrokReasoning = Omit<NonNullable<ResponseCreateParams['reasoning']>, 'effort'> & {
|
|
4
|
+
effort?: GrokReasoningEffort;
|
|
5
|
+
};
|
|
7
6
|
/**
|
|
8
7
|
* Base provider options for Grok text/chat models
|
|
9
8
|
*/
|
|
@@ -16,9 +15,9 @@ export interface GrokBaseOptions {
|
|
|
16
15
|
}
|
|
17
16
|
/**
|
|
18
17
|
* Grok-specific provider options for text/chat
|
|
19
|
-
* Based on
|
|
18
|
+
* Based on xAI Responses API options
|
|
20
19
|
*/
|
|
21
|
-
export interface GrokTextProviderOptions extends GrokBaseOptions {
|
|
20
|
+
export interface GrokTextProviderOptions extends GrokBaseOptions, Record<string, unknown> {
|
|
22
21
|
/**
|
|
23
22
|
* Temperature for response generation (0-2)
|
|
24
23
|
* Higher values make output more random, lower values more focused
|
|
@@ -32,20 +31,23 @@ export interface GrokTextProviderOptions extends GrokBaseOptions {
|
|
|
32
31
|
/**
|
|
33
32
|
* Maximum tokens in the response
|
|
34
33
|
*/
|
|
35
|
-
|
|
34
|
+
max_output_tokens?: number;
|
|
36
35
|
/**
|
|
37
|
-
*
|
|
36
|
+
* Whether xAI should store the response. Defaults to `false` in the adapter.
|
|
38
37
|
*/
|
|
39
|
-
|
|
38
|
+
store?: boolean;
|
|
40
39
|
/**
|
|
41
|
-
*
|
|
40
|
+
* Additional response fields to include. Defaults to encrypted reasoning.
|
|
42
41
|
*/
|
|
43
|
-
|
|
42
|
+
include?: ResponseCreateParams['include'];
|
|
44
43
|
/**
|
|
45
|
-
*
|
|
44
|
+
* xAI/OpenAI-compatible reasoning controls for reasoning-capable models.
|
|
46
45
|
*/
|
|
47
|
-
|
|
46
|
+
reasoning?: GrokReasoning;
|
|
48
47
|
}
|
|
48
|
+
export type GrokBuildProviderOptions = Omit<GrokTextProviderOptions, 'reasoning'> & {
|
|
49
|
+
reasoning?: never;
|
|
50
|
+
};
|
|
49
51
|
/**
|
|
50
52
|
* External provider options (what users pass in)
|
|
51
53
|
*/
|
|
@@ -1 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
import { convertFunctionToolToResponsesFormat, ResponsesFunctionTool } from '@tanstack/openai-base';
|
|
2
|
+
import { ProviderTool, Tool } from '@tanstack/ai';
|
|
3
|
+
import { GrokProviderToolKind } from '../model-meta.js';
|
|
4
|
+
export type FunctionTool = ResponsesFunctionTool;
|
|
5
|
+
export { convertFunctionToolToResponsesFormat as convertFunctionToolToAdapterFormat };
|
|
6
|
+
export type GrokProviderTool<TKind extends GrokProviderToolKind> = ProviderTool<'grok', TKind>;
|
|
7
|
+
export interface GrokWebSearchToolConfig {
|
|
8
|
+
type: 'web_search';
|
|
9
|
+
filters?: {
|
|
10
|
+
allowed_domains?: Array<string>;
|
|
11
|
+
excluded_domains?: Array<string>;
|
|
12
|
+
};
|
|
13
|
+
enable_image_understanding?: boolean;
|
|
14
|
+
enable_image_search?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export interface GrokXSearchToolConfig {
|
|
17
|
+
type: 'x_search';
|
|
18
|
+
allowed_x_handles?: Array<string>;
|
|
19
|
+
excluded_x_handles?: Array<string>;
|
|
20
|
+
from_date?: string;
|
|
21
|
+
to_date?: string;
|
|
22
|
+
enable_image_understanding?: boolean;
|
|
23
|
+
enable_video_understanding?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface GrokFileSearchToolConfig {
|
|
26
|
+
type: 'file_search';
|
|
27
|
+
vector_store_ids: Array<string>;
|
|
28
|
+
max_num_results?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface GrokMCPToolConfig {
|
|
31
|
+
type: 'mcp';
|
|
32
|
+
server_label: string;
|
|
33
|
+
server_url: string;
|
|
34
|
+
allowed_tools?: Array<string>;
|
|
35
|
+
server_description?: string;
|
|
36
|
+
authorization?: string;
|
|
37
|
+
headers?: Record<string, string>;
|
|
38
|
+
}
|
|
39
|
+
export type GrokServerTool = GrokWebSearchToolConfig | GrokXSearchToolConfig | GrokFileSearchToolConfig | GrokMCPToolConfig;
|
|
40
|
+
export type GrokResponsesTool = GrokServerTool | ResponsesFunctionTool;
|
|
41
|
+
export declare function grokWebSearchTool(config?: Omit<GrokWebSearchToolConfig, 'type'>): GrokProviderTool<'web_search'>;
|
|
42
|
+
export declare function grokXSearchTool(config?: Omit<GrokXSearchToolConfig, 'type'>): GrokProviderTool<'x_search'>;
|
|
43
|
+
export declare function grokFileSearchTool(config: Omit<GrokFileSearchToolConfig, 'type'>): GrokProviderTool<'file_search'>;
|
|
44
|
+
export declare function grokMCPTool(config: Omit<GrokMCPToolConfig, 'type'>): GrokProviderTool<'mcp'>;
|
|
45
|
+
export declare function convertToolsToProviderFormat(tools: Array<Tool>): Array<GrokResponsesTool>;
|
package/dist/esm/tools/index.js
CHANGED
|
@@ -1,6 +1,113 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { brandProviderTool } from "@tanstack/ai";
|
|
2
|
+
import { convertFunctionToolToResponsesFormat } from "@tanstack/openai-base";
|
|
3
|
+
import { convertFunctionToolToResponsesFormat as convertFunctionToolToResponsesFormat2 } from "@tanstack/openai-base";
|
|
4
|
+
function providerTool(kind, description, metadata) {
|
|
5
|
+
return brandProviderTool({
|
|
6
|
+
name: kind,
|
|
7
|
+
description,
|
|
8
|
+
metadata: {
|
|
9
|
+
__kind: `grok.${kind}`,
|
|
10
|
+
...metadata
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
function grokWebSearchTool(config = {}) {
|
|
15
|
+
if (config.filters?.allowed_domains !== void 0 && config.filters.excluded_domains !== void 0) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
"allowed_domains and excluded_domains cannot both be provided."
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
if (config.filters?.allowed_domains !== void 0 && config.filters.allowed_domains.length > 5) {
|
|
21
|
+
throw new Error("allowed_domains supports at most 5 domains.");
|
|
22
|
+
}
|
|
23
|
+
if (config.filters?.excluded_domains !== void 0 && config.filters.excluded_domains.length > 5) {
|
|
24
|
+
throw new Error("excluded_domains supports at most 5 domains.");
|
|
25
|
+
}
|
|
26
|
+
return providerTool("web_search", "Search the web", {
|
|
27
|
+
type: "web_search",
|
|
28
|
+
...config
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
function grokXSearchTool(config = {}) {
|
|
32
|
+
if (config.allowed_x_handles !== void 0 && config.excluded_x_handles !== void 0) {
|
|
33
|
+
throw new Error(
|
|
34
|
+
"allowed_x_handles and excluded_x_handles cannot both be provided."
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
if (config.allowed_x_handles !== void 0 && config.allowed_x_handles.length > 20) {
|
|
38
|
+
throw new Error("allowed_x_handles supports at most 20 handles.");
|
|
39
|
+
}
|
|
40
|
+
if (config.excluded_x_handles !== void 0 && config.excluded_x_handles.length > 20) {
|
|
41
|
+
throw new Error("excluded_x_handles supports at most 20 handles.");
|
|
42
|
+
}
|
|
43
|
+
return providerTool("x_search", "Search X posts", {
|
|
44
|
+
type: "x_search",
|
|
45
|
+
...config
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function grokFileSearchTool(config) {
|
|
49
|
+
if (config.vector_store_ids.length === 0) {
|
|
50
|
+
throw new Error("vector_store_ids must contain at least one collection id.");
|
|
51
|
+
}
|
|
52
|
+
if (config.max_num_results !== void 0) {
|
|
53
|
+
if (config.max_num_results < 1 || config.max_num_results > 50) {
|
|
54
|
+
throw new Error("max_num_results must be between 1 and 50.");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return providerTool("file_search", "Search xAI file collections", {
|
|
58
|
+
type: "file_search",
|
|
59
|
+
...config
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function grokMCPTool(config) {
|
|
63
|
+
if (!config.server_url) {
|
|
64
|
+
throw new Error("server_url must be provided.");
|
|
65
|
+
}
|
|
66
|
+
return providerTool("mcp", config.server_description || "Remote MCP server", {
|
|
67
|
+
type: "mcp",
|
|
68
|
+
...config
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function getGrokProviderToolKind(tool) {
|
|
72
|
+
const kind = tool.metadata?.__kind;
|
|
73
|
+
switch (kind) {
|
|
74
|
+
case "grok.web_search":
|
|
75
|
+
return "web_search";
|
|
76
|
+
case "grok.x_search":
|
|
77
|
+
return "x_search";
|
|
78
|
+
case "grok.file_search":
|
|
79
|
+
return "file_search";
|
|
80
|
+
case "grok.mcp":
|
|
81
|
+
return "mcp";
|
|
82
|
+
default:
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function convertGrokProviderToolToAdapterFormat(tool, kind) {
|
|
87
|
+
const metadata = tool.metadata;
|
|
88
|
+
if (metadata.type !== kind) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`convertGrokProviderToolToAdapterFormat: tool "${tool.name}" has mismatched Grok tool metadata.`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
const { __kind: _kind, ...toolConfig } = metadata;
|
|
94
|
+
return toolConfig;
|
|
95
|
+
}
|
|
96
|
+
function convertToolsToProviderFormat(tools) {
|
|
97
|
+
return tools.map((tool) => {
|
|
98
|
+
const grokProviderToolKind = getGrokProviderToolKind(tool);
|
|
99
|
+
if (grokProviderToolKind) {
|
|
100
|
+
return convertGrokProviderToolToAdapterFormat(tool, grokProviderToolKind);
|
|
101
|
+
}
|
|
102
|
+
return convertFunctionToolToResponsesFormat(tool);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
2
105
|
export {
|
|
3
|
-
|
|
4
|
-
|
|
106
|
+
convertFunctionToolToResponsesFormat2 as convertFunctionToolToAdapterFormat,
|
|
107
|
+
convertToolsToProviderFormat,
|
|
108
|
+
grokFileSearchTool,
|
|
109
|
+
grokMCPTool,
|
|
110
|
+
grokWebSearchTool,
|
|
111
|
+
grokXSearchTool
|
|
5
112
|
};
|
|
6
113
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/tools/index.ts"],"sourcesContent":["import { brandProviderTool } from '@tanstack/ai'\nimport { convertFunctionToolToResponsesFormat } from '@tanstack/openai-base'\nimport type { ProviderTool, Tool } from '@tanstack/ai'\nimport type { ResponsesFunctionTool } from '@tanstack/openai-base'\nimport type { GrokProviderToolKind } from '../model-meta'\n\nexport type FunctionTool = ResponsesFunctionTool\n\nexport { convertFunctionToolToResponsesFormat as convertFunctionToolToAdapterFormat }\n\nexport type GrokProviderTool<TKind extends GrokProviderToolKind> = ProviderTool<\n 'grok',\n TKind\n>\n\ntype GrokToolKindMarker<TKind extends GrokProviderToolKind> = `grok.${TKind}`\n\nexport interface GrokWebSearchToolConfig {\n type: 'web_search'\n filters?: {\n allowed_domains?: Array<string>\n excluded_domains?: Array<string>\n }\n enable_image_understanding?: boolean\n enable_image_search?: boolean\n}\n\nexport interface GrokXSearchToolConfig {\n type: 'x_search'\n allowed_x_handles?: Array<string>\n excluded_x_handles?: Array<string>\n from_date?: string\n to_date?: string\n enable_image_understanding?: boolean\n enable_video_understanding?: boolean\n}\n\nexport interface GrokFileSearchToolConfig {\n type: 'file_search'\n vector_store_ids: Array<string>\n max_num_results?: number\n}\n\nexport interface GrokMCPToolConfig {\n type: 'mcp'\n server_label: string\n server_url: string\n allowed_tools?: Array<string>\n server_description?: string\n authorization?: string\n headers?: Record<string, string>\n}\n\nexport type GrokServerTool =\n | GrokWebSearchToolConfig\n | GrokXSearchToolConfig\n | GrokFileSearchToolConfig\n | GrokMCPToolConfig\n\ntype GrokProviderToolMetadata<TKind extends GrokProviderToolKind> = Extract<\n GrokServerTool,\n { type: TKind }\n> & {\n __kind: GrokToolKindMarker<TKind>\n}\n\nexport type GrokResponsesTool = GrokServerTool | ResponsesFunctionTool\n\nfunction providerTool<TKind extends GrokProviderToolKind>(\n kind: TKind,\n description: string,\n metadata: Extract<GrokServerTool, { type: TKind }>,\n): GrokProviderTool<TKind> {\n return brandProviderTool<GrokProviderTool<TKind>>({\n name: kind,\n description,\n metadata: {\n __kind: `grok.${kind}`,\n ...metadata,\n },\n })\n}\n\nexport function grokWebSearchTool(\n config: Omit<GrokWebSearchToolConfig, 'type'> = {},\n): GrokProviderTool<'web_search'> {\n if (\n config.filters?.allowed_domains !== undefined &&\n config.filters.excluded_domains !== undefined\n ) {\n throw new Error(\n 'allowed_domains and excluded_domains cannot both be provided.',\n )\n }\n if (\n config.filters?.allowed_domains !== undefined &&\n config.filters.allowed_domains.length > 5\n ) {\n throw new Error('allowed_domains supports at most 5 domains.')\n }\n if (\n config.filters?.excluded_domains !== undefined &&\n config.filters.excluded_domains.length > 5\n ) {\n throw new Error('excluded_domains supports at most 5 domains.')\n }\n return providerTool('web_search', 'Search the web', {\n type: 'web_search',\n ...config,\n })\n}\n\nexport function grokXSearchTool(\n config: Omit<GrokXSearchToolConfig, 'type'> = {},\n): GrokProviderTool<'x_search'> {\n if (\n config.allowed_x_handles !== undefined &&\n config.excluded_x_handles !== undefined\n ) {\n throw new Error(\n 'allowed_x_handles and excluded_x_handles cannot both be provided.',\n )\n }\n if (\n config.allowed_x_handles !== undefined &&\n config.allowed_x_handles.length > 20\n ) {\n throw new Error('allowed_x_handles supports at most 20 handles.')\n }\n if (\n config.excluded_x_handles !== undefined &&\n config.excluded_x_handles.length > 20\n ) {\n throw new Error('excluded_x_handles supports at most 20 handles.')\n }\n return providerTool('x_search', 'Search X posts', {\n type: 'x_search',\n ...config,\n })\n}\n\nexport function grokFileSearchTool(\n config: Omit<GrokFileSearchToolConfig, 'type'>,\n): GrokProviderTool<'file_search'> {\n if (config.vector_store_ids.length === 0) {\n throw new Error('vector_store_ids must contain at least one collection id.')\n }\n if (config.max_num_results !== undefined) {\n if (config.max_num_results < 1 || config.max_num_results > 50) {\n throw new Error('max_num_results must be between 1 and 50.')\n }\n }\n return providerTool('file_search', 'Search xAI file collections', {\n type: 'file_search',\n ...config,\n })\n}\n\nexport function grokMCPTool(\n config: Omit<GrokMCPToolConfig, 'type'>,\n): GrokProviderTool<'mcp'> {\n if (!config.server_url) {\n throw new Error('server_url must be provided.')\n }\n return providerTool('mcp', config.server_description || 'Remote MCP server', {\n type: 'mcp',\n ...config,\n })\n}\n\nfunction getGrokProviderToolKind(tool: Tool): GrokProviderToolKind | undefined {\n const kind = (tool.metadata as { __kind?: unknown } | undefined)?.__kind\n switch (kind) {\n case 'grok.web_search':\n return 'web_search'\n case 'grok.x_search':\n return 'x_search'\n case 'grok.file_search':\n return 'file_search'\n case 'grok.mcp':\n return 'mcp'\n default:\n return undefined\n }\n}\n\nfunction convertGrokProviderToolToAdapterFormat(\n tool: Tool,\n kind: GrokProviderToolKind,\n): GrokServerTool {\n const metadata = tool.metadata as GrokProviderToolMetadata<typeof kind>\n if (metadata.type !== kind) {\n throw new Error(\n `convertGrokProviderToolToAdapterFormat: tool \"${tool.name}\" has mismatched Grok tool metadata.`,\n )\n }\n const { __kind: _kind, ...toolConfig } = metadata\n void _kind\n return toolConfig\n}\n\nexport function convertToolsToProviderFormat(\n tools: Array<Tool>,\n): Array<GrokResponsesTool> {\n return tools.map((tool) => {\n const grokProviderToolKind = getGrokProviderToolKind(tool)\n if (grokProviderToolKind) {\n return convertGrokProviderToolToAdapterFormat(tool, grokProviderToolKind)\n }\n return convertFunctionToolToResponsesFormat(tool)\n })\n}\n"],"names":[],"mappings":";;;AAoEA,SAAS,aACP,MACA,aACA,UACyB;AACzB,SAAO,kBAA2C;AAAA,IAChD,MAAM;AAAA,IACN;AAAA,IACA,UAAU;AAAA,MACR,QAAQ,QAAQ,IAAI;AAAA,MACpB,GAAG;AAAA,IAAA;AAAA,EACL,CACD;AACH;AAEO,SAAS,kBACd,SAAgD,IAChB;AAChC,MACE,OAAO,SAAS,oBAAoB,UACpC,OAAO,QAAQ,qBAAqB,QACpC;AACA,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACA,MACE,OAAO,SAAS,oBAAoB,UACpC,OAAO,QAAQ,gBAAgB,SAAS,GACxC;AACA,UAAM,IAAI,MAAM,6CAA6C;AAAA,EAC/D;AACA,MACE,OAAO,SAAS,qBAAqB,UACrC,OAAO,QAAQ,iBAAiB,SAAS,GACzC;AACA,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AACA,SAAO,aAAa,cAAc,kBAAkB;AAAA,IAClD,MAAM;AAAA,IACN,GAAG;AAAA,EAAA,CACJ;AACH;AAEO,SAAS,gBACd,SAA8C,IAChB;AAC9B,MACE,OAAO,sBAAsB,UAC7B,OAAO,uBAAuB,QAC9B;AACA,UAAM,IAAI;AAAA,MACR;AAAA,IAAA;AAAA,EAEJ;AACA,MACE,OAAO,sBAAsB,UAC7B,OAAO,kBAAkB,SAAS,IAClC;AACA,UAAM,IAAI,MAAM,gDAAgD;AAAA,EAClE;AACA,MACE,OAAO,uBAAuB,UAC9B,OAAO,mBAAmB,SAAS,IACnC;AACA,UAAM,IAAI,MAAM,iDAAiD;AAAA,EACnE;AACA,SAAO,aAAa,YAAY,kBAAkB;AAAA,IAChD,MAAM;AAAA,IACN,GAAG;AAAA,EAAA,CACJ;AACH;AAEO,SAAS,mBACd,QACiC;AACjC,MAAI,OAAO,iBAAiB,WAAW,GAAG;AACxC,UAAM,IAAI,MAAM,2DAA2D;AAAA,EAC7E;AACA,MAAI,OAAO,oBAAoB,QAAW;AACxC,QAAI,OAAO,kBAAkB,KAAK,OAAO,kBAAkB,IAAI;AAC7D,YAAM,IAAI,MAAM,2CAA2C;AAAA,IAC7D;AAAA,EACF;AACA,SAAO,aAAa,eAAe,+BAA+B;AAAA,IAChE,MAAM;AAAA,IACN,GAAG;AAAA,EAAA,CACJ;AACH;AAEO,SAAS,YACd,QACyB;AACzB,MAAI,CAAC,OAAO,YAAY;AACtB,UAAM,IAAI,MAAM,8BAA8B;AAAA,EAChD;AACA,SAAO,aAAa,OAAO,OAAO,sBAAsB,qBAAqB;AAAA,IAC3E,MAAM;AAAA,IACN,GAAG;AAAA,EAAA,CACJ;AACH;AAEA,SAAS,wBAAwB,MAA8C;AAC7E,QAAM,OAAQ,KAAK,UAA+C;AAClE,UAAQ,MAAA;AAAA,IACN,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EAAA;AAEb;AAEA,SAAS,uCACP,MACA,MACgB;AAChB,QAAM,WAAW,KAAK;AACtB,MAAI,SAAS,SAAS,MAAM;AAC1B,UAAM,IAAI;AAAA,MACR,iDAAiD,KAAK,IAAI;AAAA,IAAA;AAAA,EAE9D;AACA,QAAM,EAAE,QAAQ,OAAO,GAAG,eAAe;AAEzC,SAAO;AACT;AAEO,SAAS,6BACd,OAC0B;AAC1B,SAAO,MAAM,IAAI,CAAC,SAAS;AACzB,UAAM,uBAAuB,wBAAwB,IAAI;AACzD,QAAI,sBAAsB;AACxB,aAAO,uCAAuC,MAAM,oBAAoB;AAAA,IAC1E;AACA,WAAO,qCAAqC,IAAI;AAAA,EAClD,CAAC;AACH;"}
|
package/package.json
CHANGED
|
@@ -17,14 +17,14 @@ export type GrokSummarizeModel = (typeof GROK_CHAT_MODELS)[number]
|
|
|
17
17
|
* Creates a Grok summarize adapter with explicit API key.
|
|
18
18
|
* Type resolution happens here at the call site.
|
|
19
19
|
*
|
|
20
|
-
* @param model - The model name (e.g., 'grok-
|
|
20
|
+
* @param model - The model name (e.g., 'grok-build-0.1')
|
|
21
21
|
* @param apiKey - Your xAI API key
|
|
22
22
|
* @param config - Optional additional configuration
|
|
23
23
|
* @returns Configured Grok summarize adapter instance with resolved types
|
|
24
24
|
*
|
|
25
25
|
* @example
|
|
26
26
|
* ```typescript
|
|
27
|
-
* const adapter = createGrokSummarize('grok-
|
|
27
|
+
* const adapter = createGrokSummarize('grok-build-0.1', "xai-...");
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
30
|
export function createGrokSummarize<TModel extends GrokSummarizeModel>(
|
|
@@ -50,7 +50,7 @@ export function createGrokSummarize<TModel extends GrokSummarizeModel>(
|
|
|
50
50
|
* - `process.env` (Node.js)
|
|
51
51
|
* - `window.env` (Browser with injected env)
|
|
52
52
|
*
|
|
53
|
-
* @param model - The model name (e.g., 'grok-
|
|
53
|
+
* @param model - The model name (e.g., 'grok-build-0.1')
|
|
54
54
|
* @param config - Optional configuration (excluding apiKey which is auto-detected)
|
|
55
55
|
* @returns Configured Grok summarize adapter instance with resolved types
|
|
56
56
|
* @throws Error if XAI_API_KEY is not found in environment
|
|
@@ -58,7 +58,7 @@ export function createGrokSummarize<TModel extends GrokSummarizeModel>(
|
|
|
58
58
|
* @example
|
|
59
59
|
* ```typescript
|
|
60
60
|
* // Automatically uses XAI_API_KEY from environment
|
|
61
|
-
* const adapter = grokSummarize('grok-
|
|
61
|
+
* const adapter = grokSummarize('grok-build-0.1');
|
|
62
62
|
*
|
|
63
63
|
* await summarize({
|
|
64
64
|
* adapter,
|
package/src/adapters/text.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import OpenAI from 'openai'
|
|
2
|
-
import {
|
|
2
|
+
import { OpenAIBaseResponsesTextAdapter } from '@tanstack/openai-base'
|
|
3
3
|
import { getGrokApiKeyFromEnv, withGrokDefaults } from '../utils/client'
|
|
4
|
-
import {
|
|
4
|
+
import { convertToolsToProviderFormat } from '../tools'
|
|
5
5
|
import type {
|
|
6
6
|
GROK_CHAT_MODELS,
|
|
7
7
|
GrokChatModelToolCapabilitiesByName,
|
|
8
8
|
ResolveInputModalities,
|
|
9
9
|
ResolveProviderOptions,
|
|
10
10
|
} from '../model-meta'
|
|
11
|
-
import type { Modality } from '@tanstack/ai'
|
|
11
|
+
import type { Modality, TextOptions } from '@tanstack/ai'
|
|
12
12
|
import type { GrokMessageMetadataByModality } from '../message-types'
|
|
13
13
|
import type { GrokClientConfig } from '../utils'
|
|
14
|
+
import type { ResponseCreateParams } from 'openai/resources/responses/responses'
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Resolve tool capabilities for a specific Grok model.
|
|
@@ -34,20 +35,21 @@ export type { ExternalTextProviderOptions as GrokTextProviderOptions } from '../
|
|
|
34
35
|
* Grok Text (Chat) Adapter
|
|
35
36
|
*
|
|
36
37
|
* Tree-shakeable adapter for Grok chat/text completion functionality.
|
|
37
|
-
* Uses OpenAI-compatible
|
|
38
|
+
* Uses xAI's OpenAI-compatible Responses API.
|
|
38
39
|
*
|
|
39
|
-
* Delegates implementation to {@link
|
|
40
|
+
* Delegates implementation to {@link OpenAIBaseResponsesTextAdapter}
|
|
40
41
|
* from `@tanstack/openai-base` and threads Grok-specific tool-capability
|
|
41
42
|
* typing through the 5th generic of the base class.
|
|
42
43
|
*/
|
|
43
44
|
export class GrokTextAdapter<
|
|
44
45
|
TModel extends (typeof GROK_CHAT_MODELS)[number],
|
|
45
|
-
TProviderOptions extends Record<string,
|
|
46
|
+
TProviderOptions extends Record<string, unknown> =
|
|
47
|
+
ResolveProviderOptions<TModel>,
|
|
46
48
|
TInputModalities extends ReadonlyArray<Modality> =
|
|
47
49
|
ResolveInputModalities<TModel>,
|
|
48
50
|
TToolCapabilities extends ReadonlyArray<string> =
|
|
49
51
|
ResolveToolCapabilities<TModel>,
|
|
50
|
-
> extends
|
|
52
|
+
> extends OpenAIBaseResponsesTextAdapter<
|
|
51
53
|
TModel,
|
|
52
54
|
TProviderOptions,
|
|
53
55
|
TInputModalities,
|
|
@@ -61,36 +63,34 @@ export class GrokTextAdapter<
|
|
|
61
63
|
super(model, 'grok', new OpenAI(withGrokDefaults(config)))
|
|
62
64
|
}
|
|
63
65
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const raw = delta?.reasoning_content ?? delta?.reasoning
|
|
78
|
-
if (typeof raw === 'string' && raw.length > 0) {
|
|
79
|
-
return { text: raw }
|
|
66
|
+
protected override mapOptionsToRequest(
|
|
67
|
+
options: TextOptions<TProviderOptions>,
|
|
68
|
+
): Omit<ResponseCreateParams, 'stream'> {
|
|
69
|
+
const { tools: _baseTools, ...request } = super.mapOptionsToRequest({
|
|
70
|
+
...options,
|
|
71
|
+
tools: undefined,
|
|
72
|
+
})
|
|
73
|
+
void _baseTools
|
|
74
|
+
|
|
75
|
+
if (this.model === 'grok-build-0.1' && request.reasoning !== undefined) {
|
|
76
|
+
throw new Error(
|
|
77
|
+
'grok-build-0.1 does not support reasoning modelOptions; omit reasoning for this model.',
|
|
78
|
+
)
|
|
80
79
|
}
|
|
81
|
-
return undefined
|
|
82
|
-
}
|
|
83
80
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
81
|
+
const tools = options.tools
|
|
82
|
+
? convertToolsToProviderFormat(options.tools)
|
|
83
|
+
: undefined
|
|
84
|
+
|
|
85
|
+
return {
|
|
86
|
+
...request,
|
|
87
|
+
// xAI recommends encrypted reasoning for reasoning-capable Responses
|
|
88
|
+
// requests; callers can still override either field in modelOptions.
|
|
89
|
+
store: request.store ?? false,
|
|
90
|
+
include: request.include ?? ['reasoning.encrypted_content'],
|
|
91
|
+
...(tools &&
|
|
92
|
+
tools.length > 0 && { tools: tools as ResponseCreateParams['tools'] }),
|
|
93
|
+
}
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
@@ -98,15 +98,15 @@ export class GrokTextAdapter<
|
|
|
98
98
|
* Creates a Grok text adapter with explicit API key.
|
|
99
99
|
* Type resolution happens here at the call site.
|
|
100
100
|
*
|
|
101
|
-
* @param model - The model name (e.g., 'grok-
|
|
101
|
+
* @param model - The model name (e.g., 'grok-build-0.1')
|
|
102
102
|
* @param apiKey - Your xAI API key
|
|
103
103
|
* @param config - Optional additional configuration
|
|
104
104
|
* @returns Configured Grok text adapter instance with resolved types
|
|
105
105
|
*
|
|
106
106
|
* @example
|
|
107
107
|
* ```typescript
|
|
108
|
-
* const adapter = createGrokText('grok-
|
|
109
|
-
* // adapter has type-safe providerOptions for grok-
|
|
108
|
+
* const adapter = createGrokText('grok-build-0.1', "xai-...");
|
|
109
|
+
* // adapter has type-safe providerOptions for grok-build-0.1
|
|
110
110
|
* ```
|
|
111
111
|
*/
|
|
112
112
|
export function createGrokText<
|
|
@@ -127,7 +127,7 @@ export function createGrokText<
|
|
|
127
127
|
* - `process.env` (Node.js)
|
|
128
128
|
* - `window.env` (Browser with injected env)
|
|
129
129
|
*
|
|
130
|
-
* @param model - The model name (e.g., 'grok-
|
|
130
|
+
* @param model - The model name (e.g., 'grok-build-0.1')
|
|
131
131
|
* @param config - Optional configuration (excluding apiKey which is auto-detected)
|
|
132
132
|
* @returns Configured Grok text adapter instance with resolved types
|
|
133
133
|
* @throws Error if XAI_API_KEY is not found in environment
|
|
@@ -135,7 +135,7 @@ export function createGrokText<
|
|
|
135
135
|
* @example
|
|
136
136
|
* ```typescript
|
|
137
137
|
* // Automatically uses XAI_API_KEY from environment
|
|
138
|
-
* const adapter = grokText('grok-
|
|
138
|
+
* const adapter = grokText('grok-build-0.1');
|
|
139
139
|
*
|
|
140
140
|
* const stream = chat({
|
|
141
141
|
* adapter,
|