@tanstack/ai-mistral 0.6.17 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/adapters/text.d.ts +8 -2
- package/dist/esm/adapters/text.js +164 -13
- package/dist/esm/adapters/text.js.map +1 -1
- package/dist/esm/model-meta.d.ts +73 -1
- package/dist/esm/model-meta.js +33 -5
- package/dist/esm/model-meta.js.map +1 -1
- package/dist/esm/utils/schema-converter.js +4 -4
- package/dist/esm/utils/schema-converter.js.map +1 -1
- package/package.json +4 -4
- package/src/adapters/text.ts +269 -15
- package/src/model-meta.ts +53 -1
- package/src/utils/schema-converter.test.ts +24 -0
- package/src/utils/schema-converter.ts +12 -7
package/src/model-meta.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
|
-
import type { Modality } from '@tanstack/ai'
|
|
1
|
+
import type { Modality, ModelReasoning } from '@tanstack/ai'
|
|
2
|
+
import type { ModelReasoningCapability } from '@tanstack/ai/adapter-internals'
|
|
2
3
|
import type { MistralTextProviderOptions } from './text/text-provider-options'
|
|
3
4
|
import type {
|
|
4
5
|
CodestralEmbedProviderOptions,
|
|
5
6
|
MistralEmbedProviderOptions,
|
|
6
7
|
} from './embedding/embedding-provider-options'
|
|
7
8
|
|
|
9
|
+
// Reasoning shapes: the levels a model has for `chat({ reasoning })`, and
|
|
10
|
+
// the provider value to send for each. Each model points at one of them.
|
|
11
|
+
const EFFORT_NONE_HIGH = {
|
|
12
|
+
levels: { off: 'none', high: 'high' },
|
|
13
|
+
budget: false,
|
|
14
|
+
} as const
|
|
15
|
+
const EFFORT_OFF_HIGH = {
|
|
16
|
+
levels: { off: 'off', high: 'high' },
|
|
17
|
+
budget: false,
|
|
18
|
+
} as const
|
|
19
|
+
|
|
8
20
|
/** Provider options for vision-capable Mistral models (pixtral-*). */
|
|
9
21
|
export type MistralVisionProviderOptions = MistralTextProviderOptions
|
|
10
22
|
|
|
@@ -39,6 +51,8 @@ interface ModelMeta<TProviderOptions = unknown> {
|
|
|
39
51
|
>
|
|
40
52
|
}
|
|
41
53
|
providerOptions?: TProviderOptions
|
|
54
|
+
/** The model's data for `chat({ reasoning })`. None: it does not reason. */
|
|
55
|
+
reasoning?: ModelReasoning
|
|
42
56
|
}
|
|
43
57
|
|
|
44
58
|
const MISTRAL_LARGE_LATEST = {
|
|
@@ -71,6 +85,7 @@ const MISTRAL_MEDIUM_LATEST = {
|
|
|
71
85
|
endpoints: ['chat'],
|
|
72
86
|
features: ['streaming', 'tools', 'json_object', 'json_schema', 'vision'],
|
|
73
87
|
},
|
|
88
|
+
reasoning: EFFORT_NONE_HIGH,
|
|
74
89
|
} as const satisfies ModelMeta<MistralTextProviderOptions>
|
|
75
90
|
|
|
76
91
|
const MISTRAL_SMALL_LATEST = {
|
|
@@ -87,6 +102,7 @@ const MISTRAL_SMALL_LATEST = {
|
|
|
87
102
|
endpoints: ['chat'],
|
|
88
103
|
features: ['streaming', 'tools', 'json_object', 'json_schema', 'vision'],
|
|
89
104
|
},
|
|
105
|
+
reasoning: EFFORT_NONE_HIGH,
|
|
90
106
|
} as const satisfies ModelMeta<MistralTextProviderOptions>
|
|
91
107
|
|
|
92
108
|
const MINISTRAL_8B_LATEST = {
|
|
@@ -183,6 +199,7 @@ const MAGISTRAL_MEDIUM_LATEST = {
|
|
|
183
199
|
endpoints: ['chat'],
|
|
184
200
|
features: ['streaming', 'tools', 'reasoning', 'json_object', 'json_schema'],
|
|
185
201
|
},
|
|
202
|
+
reasoning: EFFORT_OFF_HIGH,
|
|
186
203
|
} as const satisfies ModelMeta<MistralTextProviderOptions>
|
|
187
204
|
|
|
188
205
|
const MAGISTRAL_SMALL_LATEST = {
|
|
@@ -199,6 +216,8 @@ const MAGISTRAL_SMALL_LATEST = {
|
|
|
199
216
|
endpoints: ['chat'],
|
|
200
217
|
features: ['streaming', 'tools', 'reasoning', 'json_object', 'json_schema'],
|
|
201
218
|
},
|
|
219
|
+
// Not in models.dev. The same as Magistral Medium: prompt_mode only.
|
|
220
|
+
reasoning: EFFORT_OFF_HIGH,
|
|
202
221
|
} as const satisfies ModelMeta<MistralTextProviderOptions>
|
|
203
222
|
|
|
204
223
|
const OPEN_MISTRAL_NEMO = {
|
|
@@ -415,3 +434,36 @@ export type ResolveInputModalities<TModel extends string> =
|
|
|
415
434
|
TModel extends keyof MistralModelInputModalitiesByName
|
|
416
435
|
? MistralModelInputModalitiesByName[TModel]
|
|
417
436
|
: readonly ['text']
|
|
437
|
+
|
|
438
|
+
// Reasoning
|
|
439
|
+
//
|
|
440
|
+
// Each model's `reasoning` field holds its data for `chat({ reasoning })`: the
|
|
441
|
+
// levels it has, with the provider value for each, and whether it takes a
|
|
442
|
+
// thinking token budget. The data comes from models.dev. The generator that
|
|
443
|
+
// writes it comes with the model catalog later. Until then, the sync scripts
|
|
444
|
+
// keep these fields as they are.
|
|
445
|
+
|
|
446
|
+
const MISTRAL_REASONING = {
|
|
447
|
+
[MISTRAL_MEDIUM_LATEST.name]: MISTRAL_MEDIUM_LATEST.reasoning,
|
|
448
|
+
[MISTRAL_SMALL_LATEST.name]: MISTRAL_SMALL_LATEST.reasoning,
|
|
449
|
+
[MAGISTRAL_MEDIUM_LATEST.name]: MAGISTRAL_MEDIUM_LATEST.reasoning,
|
|
450
|
+
[MAGISTRAL_SMALL_LATEST.name]: MAGISTRAL_SMALL_LATEST.reasoning,
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
/**
|
|
454
|
+
* Each chat model's reasoning levels, and whether it takes a token budget,
|
|
455
|
+
* for `chat({ reasoning })`. Derived from the `reasoning` field. A model
|
|
456
|
+
* that is not here does not reason.
|
|
457
|
+
*/
|
|
458
|
+
export type MistralModelReasoningByName = {
|
|
459
|
+
[K in keyof typeof MISTRAL_REASONING]: ModelReasoningCapability<
|
|
460
|
+
(typeof MISTRAL_REASONING)[K]
|
|
461
|
+
>
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Runtime map from chat model name to its reasoning data, for the text adapter.
|
|
466
|
+
* An unknown name gives `undefined`: the adapter sends no reasoning field.
|
|
467
|
+
*/
|
|
468
|
+
export const MISTRAL_MODEL_REASONING: Readonly<Record<string, ModelReasoning>> =
|
|
469
|
+
MISTRAL_REASONING
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import { undoNullWidening } from '@tanstack/ai-utils'
|
|
2
3
|
import { makeMistralStructuredOutputCompatibleWithMap } from './schema-converter'
|
|
3
4
|
|
|
4
5
|
describe('makeMistralStructuredOutputCompatibleWithMap', () => {
|
|
@@ -254,3 +255,26 @@ describe('makeMistralStructuredOutputCompatibleWithMap', () => {
|
|
|
254
255
|
})
|
|
255
256
|
})
|
|
256
257
|
})
|
|
258
|
+
|
|
259
|
+
describe('own keys named __proto__ and constructor', () => {
|
|
260
|
+
it('keeps them in the null-widening map', () => {
|
|
261
|
+
const schema = JSON.parse(
|
|
262
|
+
'{"type":"object","properties":{"__proto__":{"type":"string"},"constructor":{"type":"string"}},"required":["constructor"]}',
|
|
263
|
+
)
|
|
264
|
+
const { schema: strict, nullWideningMap } =
|
|
265
|
+
makeMistralStructuredOutputCompatibleWithMap(schema, schema.required)
|
|
266
|
+
|
|
267
|
+
expect(Object.hasOwn(strict.properties, '__proto__')).toBe(true)
|
|
268
|
+
expect(Object.hasOwn(nullWideningMap?.properties ?? {}, '__proto__')).toBe(
|
|
269
|
+
true,
|
|
270
|
+
)
|
|
271
|
+
expect(
|
|
272
|
+
JSON.stringify(
|
|
273
|
+
undoNullWidening(
|
|
274
|
+
JSON.parse('{"__proto__":null,"constructor":"kept"}'),
|
|
275
|
+
nullWideningMap,
|
|
276
|
+
),
|
|
277
|
+
),
|
|
278
|
+
).toBe('{"constructor":"kept"}')
|
|
279
|
+
})
|
|
280
|
+
})
|
|
@@ -179,7 +179,9 @@ function coerceMistralStrictSchema(
|
|
|
179
179
|
}
|
|
180
180
|
const properties = { ...result.properties }
|
|
181
181
|
const allPropertyNames = Object.keys(properties)
|
|
182
|
-
|
|
182
|
+
// Entries, not assignment: `map['__proto__'] = x` sets the prototype
|
|
183
|
+
// and drops a property that is really named `__proto__`.
|
|
184
|
+
const propertyMaps: Array<[string, NullWideningMap]> = []
|
|
183
185
|
|
|
184
186
|
for (const propName of allPropertyNames) {
|
|
185
187
|
let prop = properties[propName]
|
|
@@ -244,10 +246,13 @@ function coerceMistralStrictSchema(
|
|
|
244
246
|
|
|
245
247
|
properties[propName] = prop
|
|
246
248
|
if (childMap || widenedHere) {
|
|
247
|
-
propertyMaps[
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
249
|
+
propertyMaps.push([
|
|
250
|
+
propName,
|
|
251
|
+
{
|
|
252
|
+
...(childMap ?? {}),
|
|
253
|
+
...(widenedHere ? { widened: true } : {}),
|
|
254
|
+
},
|
|
255
|
+
])
|
|
251
256
|
}
|
|
252
257
|
}
|
|
253
258
|
|
|
@@ -258,8 +263,8 @@ function coerceMistralStrictSchema(
|
|
|
258
263
|
delete result.required
|
|
259
264
|
}
|
|
260
265
|
result.additionalProperties = false
|
|
261
|
-
if (
|
|
262
|
-
nullWideningMap.properties = propertyMaps
|
|
266
|
+
if (propertyMaps.length > 0) {
|
|
267
|
+
nullWideningMap.properties = Object.fromEntries(propertyMaps)
|
|
263
268
|
}
|
|
264
269
|
}
|
|
265
270
|
|