Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2
3import { chatRequestMap } from './request-map.ts'
4
5describe('chatRequestMap', () => {
6 it('sends OpenAI reasoning_effort and the gpt-5.1 level map', () => {
7 const map = chatRequestMap('openai', 'gpt-5.1', 'chat')
8 expect(map?.thinking?.on).toEqual({ reasoning_effort: 'high' })
9 expect(map?.thinking?.off).toBeNull()
10 expect(map?.thinking?.levels).toEqual({
11 off: 'none',
12 minimal: null,
13 low: 'low',
14 medium: 'medium',
15 high: 'high',
16 xhigh: null,
17 max: null,
18 })
19 expect(map?.maxTokensField).toBe('max_completion_tokens')
20 expect(map?.developerRole).toBe(true)
21 expect(map?.reasoningEffort).toBe(true)
22 })
23
24 it('sends DeepSeek thinking plus reasoning_effort, and replays reasoning_content', () => {
25 const map = chatRequestMap('deepseek', 'deepseek-chat', 'chat')
26 expect(map?.thinking?.on).toEqual({
27 thinking: { type: 'enabled' },
28 reasoning_effort: 'high',
29 })
30 expect(map?.thinking?.off).toEqual({ thinking: { type: 'disabled' } })
31 expect(map?.maxTokensField).toBe('max_tokens')
32 expect(map?.developerRole).toBe(false)
33 expect(map?.replayReasoningContent).toBe(true)
34 })
35
36 it('omits unsupported deepseek-flash levels, including medium', () => {
37 const map = chatRequestMap('deepseek', 'deepseek-flash', 'chat')
38 expect(map?.thinking?.levels).toEqual({
39 off: null,
40 minimal: null,
41 low: 'low',
42 medium: null,
43 high: 'high',
44 xhigh: null,
45 max: 'max',
46 })
47 expect(map?.replayReasoningContent).toBe(true)
48 })
49
50 it('sends GLM thinking on and the glm-5.2 level map', () => {
51 const map = chatRequestMap('zai', 'glm-5.2', 'chat')
52 expect(map?.thinking?.on).toEqual({
53 thinking: { type: 'enabled', clear_thinking: false },
54 })
55 expect(map?.thinking?.levels).toEqual({
56 off: null,
57 minimal: null,
58 low: null,
59 medium: null,
60 high: 'high',
61 xhigh: null,
62 max: 'max',
63 })
64 expect(map?.maxTokensField).toBe('max_tokens')
65 expect(map?.developerRole).toBe(false)
66 expect(map?.toolStream).toBe(true)
67 expect(map?.reasoningEffort).toBe(true)
68 })
69
70 it('leaves GLM flags the Z.AI spec does not state as null', () => {
71 const flash = chatRequestMap('zai', 'glm-5.3-flashx', 'chat')
72 expect(flash?.thinking?.levels).toMatchObject({
73 low: 'low',
74 medium: null,
75 high: 'high',
76 max: 'max',
77 })
78 expect(flash?.reasoningEffort).toBe(true)
79 expect(flash?.toolStream).toBe(true)
80 // GLM-5.3 and GLM-5.3-FLASH "can only be enabled": there is no off body.
81 expect(flash?.thinking?.off).toBeNull()
82 expect(chatRequestMap('zai', 'glm-5.3', 'chat')?.thinking?.off).toBeNull()
83 // Every other thinking model takes `thinking.type: disabled`.
84 for (const id of ['glm-5.2', 'glm-5', 'glm-4.7-flash', 'glm-4.6v']) {
85 expect(chatRequestMap('zai', id, 'chat')?.thinking?.off).toEqual({
86 thinking: { type: 'disabled' },
87 })
88 }
89
90 // glm-5 is not glm-5.2: no effort field, but it is a tool_stream series.
91 const five = chatRequestMap('zai', 'glm-5', 'chat')
92 expect(five?.thinking?.levels).toBeNull()
93 expect(five?.reasoningEffort).toBeNull()
94 expect(five?.toolStream).toBe(true)
95
96 const air = chatRequestMap('zai', 'glm-4.5-air', 'chat')
97 expect(air?.thinking?.on).toEqual({
98 thinking: { type: 'enabled', clear_thinking: false },
99 })
100 expect(air?.toolStream).toBeNull()
101 expect(air?.reasoningEffort).toBeNull()
102
103 // glm-4.6v is not the glm-4.6 series.
104 expect(chatRequestMap('zai', 'glm-4.6v', 'chat')?.toolStream).toBeNull()
105
106 const legacy = chatRequestMap('zai', 'glm-4-32b-0414-128k', 'chat')
107 expect(legacy?.thinking).toBeNull()
108 expect(legacy?.maxTokensField).toBe('max_tokens')
109 })
110
111 it('leaves Coding Plan request fields to each plan’s own dynamic source', () => {
112 for (const provider of ['zai-coding-plan', 'zhipuai-coding-plan']) {
113 for (const id of ['glm-5.3', 'glm-5.3-flash', 'glm-5.3-flash[1m]']) {
114 expect(chatRequestMap(provider, id, 'chat')).toBeNull()
115 }
116 }
117 })
118
119 it('sends Qwen enable_thinking and the vLLM kwargs body', () => {
120 expect(chatRequestMap('qwen', 'qwen3', 'chat')?.thinking?.on).toEqual({
121 enable_thinking: true,
122 })
123 expect(chatRequestMap('vllm', 'qwen3', 'chat')?.thinking?.on).toEqual({
124 chat_template_kwargs: {
125 enable_thinking: true,
126 preserve_thinking: true,
127 },
128 })
129 })
130
131 it('sends MiniMax adaptive thinking and max_completion_tokens', () => {
132 const map = chatRequestMap('minimax', 'MiniMax-M3', 'chat')
133 expect(map?.thinking).toEqual({
134 on: { thinking: { type: 'adaptive' } },
135 off: { thinking: { type: 'disabled' } },
136 levels: null,
137 })
138 // M3.1-Flash-Preview rejects `disabled` and takes the effort enum.
139 expect(
140 chatRequestMap('minimax', 'MiniMax-M3.1-Flash-Preview', 'chat')?.thinking,
141 ).toEqual({
142 on: { thinking: { type: 'adaptive' } },
143 off: null,
144 levels: {
145 off: null,
146 minimal: null,
147 low: 'low',
148 medium: 'medium',
149 high: 'high',
150 xhigh: 'xhigh',
151 max: 'max',
152 },
153 })
154 // The M2 models ignore `disabled`.
155 expect(
156 chatRequestMap('minimax', 'MiniMax-M2.7-highspeed', 'chat')?.thinking,
157 ).toEqual({
158 on: { thinking: { type: 'adaptive' } },
159 off: null,
160 levels: null,
161 })
162 expect(map?.maxTokensField).toBe('max_completion_tokens')
163 expect(map?.developerRole).toBe(false)
164 expect(map?.reasoningEffort).toBe(true)
165 // The China platform's chat spec states the same of the same ids.
166 for (const id of [
167 'MiniMax-M3',
168 'MiniMax-M3.1-Flash-Preview',
169 'MiniMax-M2.7-highspeed',
170 ]) {
171 expect(chatRequestMap('minimax-cn', id, 'chat')).toEqual(
172 chatRequestMap('minimax', id, 'chat'),
173 )
174 }
175 })
176
177 it('leaves host-specific OpenRouter and Together maps to native listing evidence', () => {
178 expect(chatRequestMap('openrouter', 'openai/gpt-5.1', 'chat')).toBeNull()
179 expect(
180 chatRequestMap('openrouter', 'anthropic/claude-opus-4', 'chat'),
181 ).toBeNull()
182 expect(
183 chatRequestMap('together', 'deepseek-ai/DeepSeek-V3', 'chat'),
184 ).toBeNull()
185 })
186
187 it('names max_tokens and rejects reasoning_effort where the docs do', () => {
188 // Workers AI states request fields per model; its adapter reads them.
189 expect(chatRequestMap('cloudflare-workers-ai', 'x', 'chat')).toBeNull()
190 const map = chatRequestMap('nvidia', 'some-chat', 'chat')
191 expect(map?.maxTokensField).toBe('max_tokens')
192 // NVIDIA's per-model reference pages are not read yet: unknown.
193 expect(map?.reasoningEffort).toBeNull()
194 expect(map?.developerRole).toBe(false)
195 expect(map?.thinking).toBeNull()
196 expect(chatRequestMap('grok', 'grok-4', 'chat')?.reasoningEffort).toBe(
197 false,
198 )
199 const sambanova = chatRequestMap('sambanova', 'gpt-oss-120b', 'chat')
200 expect(sambanova?.maxTokensField).toBe('max_tokens')
201 expect(sambanova?.developerRole).toBe(false)
202 expect(sambanova?.reasoningEffort).toBe(true)
203 expect(sambanova?.thinking).toEqual({
204 on: { reasoning_effort: 'high' },
205 off: null,
206 levels: {
207 off: null,
208 minimal: null,
209 low: 'low',
210 medium: 'medium',
211 high: 'high',
212 xhigh: null,
213 max: null,
214 },
215 })
216 expect(sambanova?.store ?? null).toBeNull()
217 expect(sambanova?.cacheControl ?? null).toBeNull()
218 })
219
220 it('maps Kimi thinking per model, from the Moonshot chat spec', () => {
221 for (const provider of ['moonshot', 'moonshotai-cn'] as const) {
222 const k3 = chatRequestMap(provider, 'kimi-k3', 'chat')
223 expect(k3?.maxTokensField).toBeNull()
224 expect(k3?.developerRole).toBe(false)
225 expect(k3?.reasoningEffort).toBe(true)
226 expect(k3?.thinking).toEqual({
227 on: { reasoning_effort: 'high' },
228 off: null,
229 levels: {
230 off: null,
231 minimal: null,
232 low: 'low',
233 medium: null,
234 high: 'high',
235 xhigh: null,
236 max: 'max',
237 },
238 })
239 const code = chatRequestMap(provider, 'kimi-k2.7-code-highspeed', 'chat')
240 expect(code?.thinking).toEqual({
241 on: { thinking: { type: 'enabled' } },
242 off: null,
243 levels: null,
244 })
245 expect(code?.reasoningEffort).toBeNull()
246 expect(code?.maxTokensField).toBe('max_completion_tokens')
247 expect(
248 chatRequestMap(provider, 'kimi-k2.6', 'chat')?.thinking?.off,
249 ).toEqual({ thinking: { type: 'disabled' } })
250 // An id the spec does not map gets no guessed thinking body.
251 const unknown = chatRequestMap(provider, 'kimi-k9', 'chat')
252 expect(unknown?.thinking).toBeNull()
253 expect(unknown?.reasoningEffort).toBeNull()
254 }
255 })
256
257 it('returns null for an unverified provider, a non-chat row, and an unknown activity', () => {
258 expect(chatRequestMap('fal', 'fal-ai/flux', 'chat')).toBeNull()
259 expect(chatRequestMap('byteplus', 'glm-5-2-260617', 'chat')).toBeNull()
260 expect(chatRequestMap('openai', 'gpt-5.1', 'image')).toBeNull()
261 expect(chatRequestMap('deepseek', 'deepseek-flash', null)).toBeNull()
262 })
263})