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

provider-supports.test.ts

112 lines4.0 KB

1import { describe, expect, it } from 'vitest'
2import {
3 buildAnthropicProviderOptionsType,
4 buildProviderSupportsBody,
5} from './provider-supports'
6​
7describe('buildProviderSupportsBody', () => {
8 it('lists the OpenAI server tools when the catalog accepts tools', () => {
9 const body = buildProviderSupportsBody({
10 provider: 'openai',
11 inputModalities: ['text', 'image'],
12 supportedParameters: ['temperature', 'tools', 'response_format'],
13 })
14 expect(body).toContain("'web_search'")
15 expect(body).toContain("'file_search'")
16 expect(body).toContain("'code_interpreter'")
17 expect(body).toContain("'mcp'")
18 expect(body).toContain("'computer_use', 'computer'")
19 expect(body).toContain("endpoints: ['chat', 'chat-completions']")
20 expect(body).toContain('function_calling')
21 expect(body).toContain('structured_outputs')
22 })
23​
24 it('leaves OpenAI tools empty when the catalog has no tools param', () => {
25 const body = buildProviderSupportsBody({
26 provider: 'openai',
27 inputModalities: ['text'],
28 supportedParameters: ['temperature'],
29 })
30 expect(body).toContain('tools: []')
31 expect(body).not.toContain("'computer'")
32 })
33​
34 it('lists Anthropic server tools and budget-thinking flags', () => {
35 const body = buildProviderSupportsBody({
36 provider: 'anthropic',
37 inputModalities: ['text', 'image', 'document'],
38 supportedParameters: ['max_tokens', 'temperature', 'tools'],
39 })
40 expect(body).toContain("'web_search'")
41 expect(body).toContain("'web_fetch'")
42 expect(body).toContain("'code_execution'")
43 expect(body).toContain("'computer', 'computer_toolset'")
44 expect(body).not.toContain("'computer_use'")
45 expect(body).toContain('extended_thinking: true')
46 expect(body).toContain('priority_tier: true')
47 expect(body).not.toContain('adaptive_thinking')
48 })
49​
50 it('marks adaptive-only Anthropic models', () => {
51 const body = buildProviderSupportsBody({
52 provider: 'anthropic',
53 inputModalities: ['text'],
54 supportedParameters: ['reasoning', 'tools'],
55 reasoningMandatory: true,
56 })
57 expect(body).toContain('extended_thinking: false')
58 expect(body).toContain('adaptive_thinking: true')
59 })
60​
61 it('lists Gemini server tools', () => {
62 const body = buildProviderSupportsBody({
63 provider: 'gemini',
64 inputModalities: ['text'],
65 supportedParameters: ['tools', 'include_reasoning'],
66 })
67 expect(body).toContain("'code_execution'")
68 expect(body).toContain("'google_search'")
69 expect(body).toContain("'url_context'")
70 expect(body).toContain('function_calling')
71 expect(body).toContain('thinking')
72 })
73​
74 it('lists Grok server tools', () => {
75 const body = buildProviderSupportsBody({
76 provider: 'grok',
77 inputModalities: ['text', 'image'],
78 supportedParameters: ['tools', 'include_reasoning'],
79 })
80 expect(body).toContain("'web_search'")
81 expect(body).toContain("'x_search'")
82 expect(body).toContain('tool_calling')
83 expect(body).toContain('reasoning')
84 })
85})
86​
87describe('buildAnthropicProviderOptionsType', () => {
88 it('uses max_tokens and no sampling when sampling is not listed', () => {
89 const type = buildAnthropicProviderOptionsType({
90 supportedParameters: ['max_tokens', 'reasoning', 'tools'],
91 hasCachedPricing: true,
92 })
93 expect(type).toContain('AnthropicCacheControlOptions')
94 expect(type).toContain('AnthropicMaxTokensOptions')
95 expect(type).not.toContain('AnthropicSamplingOptions')
96 })
97​
98 it('keeps sampling when temperature is listed', () => {
99 const type = buildAnthropicProviderOptionsType({
100 supportedParameters: ['temperature', 'top_p', 'top_k', 'max_tokens'],
101 })
102 expect(type).toContain('AnthropicSamplingOptions')
103 expect(type).not.toContain('AnthropicMaxTokensOptions')
104 })
105​
106 it('never emits thinking types: chat({ reasoning }) owns thinking', () => {
107 const type = buildAnthropicProviderOptionsType({
108 supportedParameters: ['max_tokens', 'reasoning', 'reasoning_effort'],
109 })
110 expect(type).not.toMatch(/Thinking|OutputConfig|Effort/)
111 })
112})