Open History to see the last commit
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('writes Groq features without copying hosted tools', () => {
75 const body = buildProviderSupportsBody({
76 provider: 'groq',
77 inputModalities: ['text'],
78 supportedParameters: ['tools', 'structured_outputs'],
79 })
80 expect(body).toContain("endpoints: ['chat']")
81 expect(body).toContain('tools: [] as const')
82 expect(body).toContain("'json_schema'")
83 expect(body).not.toContain('browser_search')
84 })
85
86 it('writes BytePlus capabilities but leaves structured outputs to the probed list', () => {
87 const body = buildProviderSupportsBody({
88 provider: 'byteplus',
89 inputModalities: ['text', 'image'],
90 outputModalities: ['text'],
91 supportedParameters: ['tools', 'reasoning', 'structured_outputs'],
92 })
93 expect(body).toContain('tool_calling')
94 expect(body).toContain('reasoning')
95 expect(body).toContain('tools: [] as const')
96 expect(body).not.toContain('structured_outputs')
97 })
98
99 it('lists Grok server tools', () => {
100 const body = buildProviderSupportsBody({
101 provider: 'grok',
102 inputModalities: ['text', 'image'],
103 supportedParameters: ['tools', 'include_reasoning'],
104 })
105 expect(body).toContain("'web_search'")
106 expect(body).toContain("'x_search'")
107 expect(body).toContain('tool_calling')
108 expect(body).toContain('reasoning')
109 })
110})
111
112describe('buildAnthropicProviderOptionsType', () => {
113 it('uses max_tokens and no sampling when sampling is not listed', () => {
114 const type = buildAnthropicProviderOptionsType({
115 supportedParameters: ['max_tokens', 'reasoning', 'tools'],
116 hasCachedPricing: true,
117 })
118 expect(type).toContain('AnthropicCacheControlOptions')
119 expect(type).toContain('AnthropicMaxTokensOptions')
120 expect(type).not.toContain('AnthropicSamplingOptions')
121 })
122
123 it('keeps sampling when temperature is listed', () => {
124 const type = buildAnthropicProviderOptionsType({
125 supportedParameters: ['temperature', 'top_p', 'top_k', 'max_tokens'],
126 })
127 expect(type).toContain('AnthropicSamplingOptions')
128 expect(type).not.toContain('AnthropicMaxTokensOptions')
129 })
130
131 it('never emits thinking types: chat({ reasoning }) owns thinking', () => {
132 const type = buildAnthropicProviderOptionsType({
133 supportedParameters: ['max_tokens', 'reasoning', 'reasoning_effort'],
134 })
135 expect(type).not.toMatch(/Thinking|OutputConfig|Effort/)
136 })
137})