Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

vendor-config.ts

160 lines4.3 KB

1/**
2 * Vendor configuration for E2E tests
3 *
4 * Defines all supported AI providers and their configuration for testing.
5 */
6​
7export type ProviderId =
8 | 'openai'
9 | 'anthropic'
10 | 'gemini'
11 | 'ollama'
12 | 'grok'
13 | 'openrouter'
14​
15export interface ProviderConfig {
16 /** Unique identifier matching the panel's provider type */
17 id: ProviderId
18 /** Human-readable name for test descriptions */
19 name: string
20 /** Environment variable key for API key (null if not required) */
21 envKey: string | null
22 /** Default model to use for testing */
23 defaultModel: string
24 /** Whether this provider reliably supports basic chat inference */
25 supportsBasicInference: boolean
26 /** Whether this provider reliably supports tool calling */
27 supportsTools: boolean
28 /** Whether this provider supports summarization */
29 supportsSummarization: boolean
30 /** Whether this provider supports streaming summarization */
31 supportsStreamingSummarization: boolean
33​
34/**
35 * All supported providers and their configurations
36 */
37export const PROVIDERS: ProviderConfig[] = [
38 {
39 id: 'openai',
40 name: 'OpenAI',
41 envKey: 'OPENAI_API_KEY',
42 defaultModel: 'gpt-4o-mini',
43 supportsBasicInference: true,
44 supportsTools: true,
45 supportsSummarization: true,
46 supportsStreamingSummarization: true,
47 },
48 {
49 id: 'anthropic',
50 name: 'Anthropic',
51 envKey: 'ANTHROPIC_API_KEY',
52 defaultModel: 'claude-sonnet-4-5-20250929',
53 supportsBasicInference: true,
54 supportsTools: true,
55 supportsSummarization: true,
56 supportsStreamingSummarization: true,
57 },
58 {
59 id: 'gemini',
60 name: 'Gemini',
61 envKey: 'GEMINI_API_KEY',
62 defaultModel: 'gemini-2.5-flash',
63 supportsBasicInference: true,
64 supportsTools: true,
65 supportsSummarization: true,
66 supportsStreamingSummarization: true,
67 },
68 {
69 id: 'ollama',
70 name: 'Ollama',
71 envKey: null, // Ollama runs locally, no API key needed
72 defaultModel: 'mistral:7b',
73 supportsBasicInference: true,
74 supportsTools: false, // Smaller local models may not reliably call tools
75 supportsSummarization: true,
76 supportsStreamingSummarization: true,
77 },
78 {
79 id: 'grok',
80 name: 'Grok',
81 envKey: 'XAI_API_KEY',
82 defaultModel: 'grok-build-0.1',
83 supportsBasicInference: true,
84 supportsTools: true,
85 supportsSummarization: true,
86 supportsStreamingSummarization: true,
87 },
88 {
89 id: 'openrouter',
90 name: 'OpenRouter',
91 envKey: 'OPENROUTER_API_KEY',
92 defaultModel: 'openai/gpt-4o-mini',
93 supportsBasicInference: false, // Chat via OpenRouter returns empty responses inconsistently
94 supportsTools: false, // Tool calling via OpenRouter is unreliable due to backend variations
95 supportsSummarization: true,
96 supportsStreamingSummarization: true,
97 },
99​
100/**
101 * Check if a provider is available (has required API key configured)
102 */
103export function isProviderAvailable(provider: ProviderConfig): boolean {
104 // Ollama doesn't require an API key
105 if (provider.envKey === null) {
106 return true
107 }
108​
109 // Check for the API key in environment
110 const apiKey = process.env[provider.envKey]
111 return Boolean(apiKey && apiKey.length > 0)
113​
114/**
115 * Get a provider by ID
116 */
117export function getProvider(id: ProviderId): ProviderConfig | undefined {
118 return PROVIDERS.find((p) => p.id === id)
120​
121/**
122 * Get all available providers (those with API keys configured)
123 */
124export function getAvailableProviders(): ProviderConfig[] {
125 return PROVIDERS.filter(isProviderAvailable)
127​
128/**
129 * Get providers that support basic inference (chat)
130 */
131export function getInferenceCapableProviders(): ProviderConfig[] {
132 return PROVIDERS.filter(
133 (p) => p.supportsBasicInference && isProviderAvailable(p),
134 )
136​
137/**
138 * Get providers that support tool calling
139 */
140export function getToolCapableProviders(): ProviderConfig[] {
141 return PROVIDERS.filter((p) => p.supportsTools && isProviderAvailable(p))
143​
144/**
145 * Get providers that support summarization
146 */
147export function getSummarizationCapableProviders(): ProviderConfig[] {
148 return PROVIDERS.filter(
149 (p) => p.supportsSummarization && isProviderAvailable(p),
150 )
152​
153/**
154 * Get providers that support streaming summarization
155 */
156export function getStreamingSummarizationCapableProviders(): ProviderConfig[] {
157 return PROVIDERS.filter(
158 (p) => p.supportsStreamingSummarization && isProviderAvailable(p),
159 )