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 a closed assistant schema with no reasoning_content as false', () => {
48 const closed = `${SPEC}
49 AssistantMessage:
50 additionalProperties: false
51 properties:
52 role:
53 const: assistant
54 content:
55 type: string
56`
57 expect(parseMistralChatWire(closed).replayReasoningContent).toBe(false)
58 const open = closed.replace(
59 'AssistantMessage:\n additionalProperties: false',
60 'AssistantMessage:\n additionalProperties: true',
61 )
62 expect(parseMistralChatWire(open).replayReasoningContent).toBeNull()
63 const present = closed.replace(
64 'content:\n type: string',
65 'content:\n type: string\n reasoning_content:\n type: string',
66 )
67 expect(parseMistralChatWire(present).replayReasoningContent).toBeNull()
68 })
69
70 it('reads max_tokens, no developer role, and reasoning_effort', () => {
71 expect(parseMistralChatWire(SPEC)).toEqual({
72 maxTokensField: 'max_tokens',
73 developerRole: false,
74 reasoningEffort: true,
75 replayReasoningContent: null,
76 })
77 expect(() => parseMistralChatWire('components: {}')).toThrow(
78 /ChatCompletionRequest missing/,
79 )
80 })
81
82 it('builds thinking from the model reasoning object, not the shared enum', () => {
83 const wire = parseMistralChatWire(SPEC)
84 expect(
85 mistralRequestMap(wire, { mode: 'effort', mandatory: false }),
86 ).toMatchObject({
87 maxTokensField: 'max_tokens',
88 developerRole: false,
89 reasoningEffort: true,
90 thinking: {
91 on: { reasoning_effort: 'high' },
92 off: { reasoning_effort: 'none' },
93 levels: null,
94 },
95 replayReasoningContent: null,
96 store: null,
97 })
98 expect(
99 mistralThinking({
100 mode: 'effort',
101 mandatory: true,
102 efforts: ['low', 'high', 'max'],
103 }),
104 ).toEqual({
105 on: { reasoning_effort: 'high' },
106 off: null,
107 levels: {
108 off: null,
109 minimal: null,
110 low: 'low',
111 medium: null,
112 high: 'high',
113 xhigh: null,
114 max: 'max',
115 },
116 })
117 expect(mistralThinking(null)).toBeNull()
118 expect(mistralThinking({ mode: 'effort', mandatory: true })).toMatchObject({
119 off: null,
120 levels: null,
121 })
122 })
123})