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("endpoints: ['chat', 'chat-completions']")
19 expect(body).toContain('function_calling')
20 expect(body).toContain('structured_outputs')
21 })
22
23 it('leaves OpenAI tools empty when the catalog has no tools param', () => {
24 const body = buildProviderSupportsBody({
25 provider: 'openai',
26 inputModalities: ['text'],
27 supportedParameters: ['temperature'],
28 })
29 expect(body).toContain('tools: []')
30 })
31
32 it('lists Anthropic server tools and budget-thinking flags', () => {
33 const body = buildProviderSupportsBody({
34 provider: 'anthropic',
35 inputModalities: ['text', 'image', 'document'],
36 supportedParameters: ['max_tokens', 'temperature', 'tools'],
37 })
38 expect(body).toContain("'web_search'")
39 expect(body).toContain("'web_fetch'")
40 expect(body).toContain("'code_execution'")
41 expect(body).toContain("'computer_use'")
42 expect(body).toContain('extended_thinking: true')
43 expect(body).toContain('priority_tier: true')
44 expect(body).not.toContain('adaptive_thinking')
45 })
46
47 it('marks adaptive-only Anthropic models', () => {
48 const body = buildProviderSupportsBody({
49 provider: 'anthropic',
50 inputModalities: ['text'],
51 supportedParameters: ['reasoning', 'tools'],
52 reasoningMandatory: true,
53 })
54 expect(body).toContain('extended_thinking: false')
55 expect(body).toContain('adaptive_thinking: true')
56 })
57
58 it('lists Gemini server tools', () => {
59 const body = buildProviderSupportsBody({
60 provider: 'gemini',
61 inputModalities: ['text'],
62 supportedParameters: ['tools', 'include_reasoning'],
63 })
64 expect(body).toContain("'code_execution'")
65 expect(body).toContain("'google_search'")
66 expect(body).toContain("'url_context'")
67 expect(body).toContain('function_calling')
68 expect(body).toContain('thinking')
69 })
70
71 it('lists Grok server tools', () => {
72 const body = buildProviderSupportsBody({
73 provider: 'grok',
74 inputModalities: ['text', 'image'],
75 supportedParameters: ['tools', 'include_reasoning'],
76 })
77 expect(body).toContain("'web_search'")
78 expect(body).toContain("'x_search'")
79 expect(body).toContain('tool_calling')
80 expect(body).toContain('reasoning')
81 })
82})
83
84describe('buildAnthropicProviderOptionsType', () => {
85 it('uses adaptive-only thinking and no sampling when reasoning is mandatory', () => {
86 const type = buildAnthropicProviderOptionsType({
87 supportedParameters: [
88 'max_tokens',
89 'reasoning',
90 'tools',
91 'include_reasoning',
92 'reasoning_effort',
93 ],
94 reasoningMandatory: true,
95 hasCachedPricing: true,
96 })
97 expect(type).toContain('AnthropicCacheControlOptions')
98 expect(type).toContain('AnthropicAdaptiveOnlyThinkingOptions')
99 expect(type).toContain('AnthropicMaxTokensOptions')
100 expect(type).toContain('AnthropicOutputConfigOptions')
101 expect(type).not.toContain('AnthropicSamplingOptions')
102 expect(type).not.toContain('AnthropicThinkingOptions &')
103 expect(type).not.toContain('AnthropicAdaptiveThinkingOptions')
104 expect(type).not.toContain('AnthropicAdaptiveOrDisabledThinkingOptions')
105 })
106
107 it('uses adaptive-or-disabled thinking when reasoning is listed without sampling', () => {
108 const type = buildAnthropicProviderOptionsType({
109 supportedParameters: ['max_tokens', 'reasoning', 'stop'],
110 reasoningMandatory: false,
111 })
112 expect(type).toContain('AnthropicAdaptiveOrDisabledThinkingOptions')
113 expect(type).toContain('AnthropicMaxTokensOptions')
114 expect(type).not.toContain('AnthropicSamplingOptions')
115 })
116
117 it('keeps sampling plus budget thinking when temperature is listed and reasoning is not', () => {
118 const type = buildAnthropicProviderOptionsType({
119 supportedParameters: ['temperature', 'top_p', 'top_k', 'max_tokens'],
120 })
121 expect(type).toContain('AnthropicThinkingOptions')
122 expect(type).toContain('AnthropicSamplingOptions')
123 expect(type).not.toContain('AnthropicMaxTokensOptions')
124 expect(type).not.toContain('AnthropicAdaptiveOnlyThinkingOptions')
125 })
126})