Open History to see the last commit
1import { describe, expect, it } from 'vitest'
2
3import {
4 mistralRequestMap,
5 mistralThinking,
6 parseMistralChatWire,
7} from './mistral-request.ts'
8
9const SPEC = `
10components:
11 schemas:
12 ChatCompletionRequest:
13 additionalProperties: false
14 properties:
15 max_tokens:
16 description: The token count of your prompt plus max_tokens cannot exceed the model's context length.
17 reasoning_effort:
18 anyOf:
19 - $ref: '#/components/schemas/ReasoningEffort'
20 - type: 'null'
21 messages:
22 items:
23 oneOf:
24 - $ref: '#/components/schemas/SystemMessage'
25 - $ref: '#/components/schemas/UserMessage'
26 - $ref: '#/components/schemas/AssistantMessage'
27 - $ref: '#/components/schemas/ToolMessage'
28 discriminator:
29 propertyName: role
30 mapping:
31 assistant: '#/components/schemas/AssistantMessage'
32 system: '#/components/schemas/SystemMessage'
33 tool: '#/components/schemas/ToolMessage'
34 user: '#/components/schemas/UserMessage'
35 tools:
36 items:
37 discriminator:
38 propertyName: type
39 mapping:
40 function: '#/components/schemas/Tool'
41 web_search: '#/components/schemas/WebSearchTool'
42 ReasoningEffort:
43 enum: [none, minimal, low, medium, high, xhigh]
44`
45
46describe('parseMistralChatWire', () => {
47 it('reads max_tokens, no developer role, and reasoning_effort', () => {
48 expect(parseMistralChatWire(SPEC)).toEqual({
49 maxTokensField: 'max_tokens',
50 developerRole: false,
51 reasoningEffort: true,
52 })
53 expect(() => parseMistralChatWire('components: {}')).toThrow(
54 /ChatCompletionRequest missing/,
55 )
56 })
57
58 it('builds thinking from the model reasoning object, not the shared enum', () => {
59 const wire = parseMistralChatWire(SPEC)
60 expect(
61 mistralRequestMap(wire, { mode: 'effort', mandatory: false }),
62 ).toMatchObject({
63 maxTokensField: 'max_tokens',
64 developerRole: false,
65 reasoningEffort: true,
66 thinking: {
67 on: { reasoning_effort: 'high' },
68 off: { reasoning_effort: 'none' },
69 levels: null,
70 },
71 replayReasoningContent: null,
72 store: null,
73 })
74 expect(
75 mistralThinking({
76 mode: 'effort',
77 mandatory: true,
78 efforts: ['low', 'high', 'max'],
79 }),
80 ).toEqual({
81 on: { reasoning_effort: 'high' },
82 off: null,
83 levels: {
84 off: null,
85 minimal: null,
86 low: 'low',
87 medium: null,
88 high: 'high',
89 xhigh: null,
90 max: 'max',
91 },
92 })
93 expect(mistralThinking(null)).toBeNull()
94 expect(mistralThinking({ mode: 'effort', mandatory: true })).toMatchObject({
95 off: null,
96 levels: null,
97 })
98 })
99})