MCPcopy Index your code
hub / github.com/TanStack/ai / createTextAdapter

Function createTextAdapter

testing/e2e/src/lib/providers.ts:42–218  ·  view source on GitHub ↗
(
  provider: Provider,
  modelOverride?: string,
  _aimockPort?: number,
  testId?: string,
  feature?: Feature,
)

Source from the content-addressed store, hash-verified

40}
41
42export function createTextAdapter(
43 provider: Provider,
44 modelOverride?: string,
45 _aimockPort?: number,
46 testId?: string,
47 feature?: Feature,
48): { adapter: AnyTextAdapter } {
49 const model = modelOverride ?? defaultModels[provider]
50
51 // OpenAI, Grok SDKs need /v1 in baseURL. Groq SDK appends /openai/v1/ internally.
52 // Anthropic, Gemini, Ollama SDKs include their path prefixes internally
53 const base = LLMOCK_DEFAULT_BASE
54 const openaiUrl = `${base}/v1`
55
56 // X-Test-Id header for per-test sequenceIndex isolation in aimock
57 const testHeaders = testId ? { 'X-Test-Id': testId } : undefined
58
59 // The Gemini Interactions API lives at a different endpoint
60 // (POST /v1beta/interactions) and uses a different adapter than the
61 // standard Gemini chat path.
62 if (provider === 'gemini' && feature === 'stateful-interactions') {
63 return createChatOptions({
64 adapter: createGeminiTextInteractions(
65 model as 'gemini-2.5-flash',
66 DUMMY_KEY,
67 {
68 httpOptions: {
69 baseUrl: base,
70 headers: testHeaders,
71 },
72 },
73 ),
74 })
75 }
76
77 const factories: Record<Provider, () => { adapter: AnyTextAdapter }> = {
78 openai: () =>
79 createChatOptions({
80 adapter: createOpenaiChat(model as 'gpt-4o', DUMMY_KEY, {
81 baseURL: openaiUrl,
82 defaultHeaders: testHeaders,
83 }),
84 }),
85 anthropic: () =>
86 createChatOptions({
87 adapter: createAnthropicChat(model as 'claude-sonnet-4-5', DUMMY_KEY, {
88 baseURL: base,
89 defaultHeaders: testHeaders,
90 }),
91 }),
92 gemini: () =>
93 createChatOptions({
94 adapter: createGeminiChat(model as 'gemini-2.5-flash', DUMMY_KEY, {
95 httpOptions: {
96 baseUrl: base,
97 headers: testHeaders,
98 },
99 }),

Calls 15

createChatOptionsFunction · 0.90
createOpenaiChatFunction · 0.90
createAnthropicChatFunction · 0.90
createGeminiChatFunction · 0.90
createOllamaChatFunction · 0.90
createGroqTextFunction · 0.90
createGrokTextFunction · 0.90
createBedrockTextFunction · 0.90
createOpenRouterTextFunction · 0.90
openaiCompatibleTextFunction · 0.90

Tested by

no test coverage detected