diff --git a/docs/native-reasoning-sources.md b/docs/native-reasoning-sources.md index 2676854e..a7a0063c 100644 --- a/docs/native-reasoning-sources.md +++ b/docs/native-reasoning-sources.md @@ -100,16 +100,24 @@ source URL, fixture or output; they make no inference calls. ## Mistral -https://docs.mistral.ai/studio/conversations/reasoning.md +https://docs.mistral.ai/inference/conversations/reasoning + +Checked 2026-11-19. `llms.txt` links the `.md` twin of this page, and the old +`/studio/conversations/reasoning.md` path redirects to that twin, but the twin +404s. The HTML page is the guide. The guide scopes adjustable reasoning to named model IDs, followed by a normative parameter-value section describing high and none. These values apply to that -scope, while its explicit zai-glm-5-3 low/high/max list overrides them. Code -assignments alone do not establish the values. The existing adapter retains native -API alias relationships when copying these facts; no sibling relationships are -invented. Models outside the guide's scope do not inherit its controls. Fenced -examples cannot expand the normative values. The GLM always-thinking note -explicitly establishes mandatory=true; a value list alone leaves it null. +scope, while its explicit zai-glm-5-3 low/high/max list overrides them. A bullet +that names its own levels (Supports `low`, `medium`, and `high` reasoning +effort) is that model's list. Mistral Large 4's section says it always reasons, +so `mistral-large-4` and `mistral-large-4-0` are mandatory. Code assignments +alone do not establish the values. The existing adapter retains native API alias +relationships when copying these facts; no sibling relationships are invented. +Models outside the guide's scope do not inherit its controls. Fenced examples +cannot expand the normative values. The GLM always-thinking note explicitly +establishes mandatory=true; a value list alone leaves it null. A rendered HTML +page is read as the same markdown shape. ## Dashscope diff --git a/src/server/providers/adapters/mistral.test.ts b/src/server/providers/adapters/mistral.test.ts index ee57124a..fbb4c6e7 100644 --- a/src/server/providers/adapters/mistral.test.ts +++ b/src/server/providers/adapters/mistral.test.ts @@ -9,6 +9,8 @@ import { } from '../fixtures/mistral-model-page.ts' import { provider } from './mistral.ts' import { MISTRAL_DEPRECATIONS_URL } from '../deprecations.ts' +import { MISTRAL_WEBSEARCH_URL } from '../mistral-pricing.ts' +import { MISTRAL_REASONING_URL } from '../reasoning-config.ts' const MODELS_PAGE = readFileSync( new URL('../fixtures/mistral-models.md.txt', import.meta.url), @@ -145,8 +147,7 @@ describe('mistral listModels modalities', () => { Small$0.1—$0.3 `, 'https://docs.mistral.ai/resources/changelogs': '', - 'https://docs.mistral.ai/studio/agents/agent-tools/websearch.md': - MISTRAL_WEBSEARCH_GUIDE, + [MISTRAL_WEBSEARCH_URL]: MISTRAL_WEBSEARCH_GUIDE, 'https://docs.mistral.ai/models/mistral-small-4-0-26-03': mistralModelPage( ['mistral-small-2603', 'mistral-small-latest'], @@ -159,7 +160,7 @@ describe('mistral listModels modalities', () => { ], ], ), - 'https://docs.mistral.ai/studio/conversations/reasoning.md': + [MISTRAL_REASONING_URL]: '- `mistral-small-latest`: Supports adjustable reasoning via the `reasoning_effort` parameter.', 'https://docs.mistral.ai/models': 'x', @@ -281,7 +282,7 @@ describe('mistral listModels docs failures', () => { expect(docsFailures?.first.map((failure) => failure.source)).toEqual( expect.arrayContaining([ 'https://docs.mistral.ai/inference/pricing', - 'https://docs.mistral.ai/studio/conversations/reasoning.md', + MISTRAL_REASONING_URL, ]), ) } finally { diff --git a/src/server/providers/mistral-pricing.test.ts b/src/server/providers/mistral-pricing.test.ts index 79984b73..4cd094e5 100644 --- a/src/server/providers/mistral-pricing.test.ts +++ b/src/server/providers/mistral-pricing.test.ts @@ -26,6 +26,7 @@ import { parseMistralPricing, parseMistralSamePrice, parseMistralWebSearchTools, + MISTRAL_WEBSEARCH_URL, withDocumentInput, } from './mistral-pricing.ts' @@ -755,8 +756,7 @@ describe('mistral model page price and max output', () => { ), 'https://docs.mistral.ai/models/mistral-medium-3-5-26-04.md': '- Pricing: Input $1.5 /M Tokens; Output $7.5 /M Tokens\n', - 'https://docs.mistral.ai/studio/agents/agent-tools/websearch.md': - MISTRAL_WEBSEARCH_GUIDE, + [MISTRAL_WEBSEARCH_URL]: MISTRAL_WEBSEARCH_GUIDE, } globalThis.fetch = ((url: string) => { const body = docs[String(url)] @@ -830,8 +830,7 @@ describe('mistral model page price and max output', () => { ), 'https://docs.mistral.ai/models/leanstral-1-5.md': '- Pricing: Free; Input $0 /M Tokens; Output $0 /M Tokens\n', - 'https://docs.mistral.ai/studio/agents/agent-tools/websearch.md': - MISTRAL_WEBSEARCH_GUIDE, + [MISTRAL_WEBSEARCH_URL]: MISTRAL_WEBSEARCH_GUIDE, } globalThis.fetch = ((url: string) => { const body = docs[String(url)] @@ -1029,6 +1028,27 @@ describe('mistral web search tools', () => { ).toThrow('names no tool id') }) + it('reads the rendered guide and ignores later schema bullets', () => { + const html = `
+

Our built-in tool for websearch allows any of our models to access the web at any point.

+

There are two versions:

+ +

web_search and web_search_premium work with the Conversations API (/v1/conversations).

+

Response

+ +
` + expect(parseMistralWebSearchTools(html)).toEqual([ + 'web_search', + 'web_search_premium', + ]) + }) + it('gives them only to a page that lists agents-conversations', () => { const tools = ['web_search', 'web_search_premium'] expect(mistralConversationTools(['agents-conversations'], tools)).toEqual( diff --git a/src/server/providers/mistral-pricing.ts b/src/server/providers/mistral-pricing.ts index edee4b70..1645cbb3 100644 --- a/src/server/providers/mistral-pricing.ts +++ b/src/server/providers/mistral-pricing.ts @@ -38,6 +38,7 @@ import type { Expr, RateCard } from '@modelschemas/rate-card' import { MISTRAL_DEPRECATIONS_URL } from './deprecations.ts' import { tagDocsFacts } from './fact-sources.ts' import { assertParsed, cachedDocs, mapConcurrent } from './model-facts.ts' +import { mistralDocsMarkdown } from './reasoning-config.ts' import { parseMistralPageTools } from './server-tools.ts' import { fetchText, sha256Text } from './types.ts' import type { FactSource, ModelInfo } from './types.ts' @@ -1234,29 +1235,42 @@ export interface MistralPricingLookup { seen: ReadonlySet } +/** + * The rendered web-search guide. `llms.txt` still links + * `https://docs.mistral.ai/studio/agents/agent-tools/websearch.md`, which + * 404s (checked 2026-11-19). This HTML page is what serves the guide. + */ export const MISTRAL_WEBSEARCH_URL = - 'https://docs.mistral.ai/studio/agents/agent-tools/websearch.md' + 'https://docs.mistral.ai/studio/agents/agent-tools/websearch' /** * The web search guide's tool ids (#409). It states the tool "allows any * of our models to access the web" and that it works with the * Conversations API (`/v1/conversations`), not Chat Completions; the ids - * are the bullets under "There are two versions:". Without the any-model + * are the bullets directly under "There are two versions:". Later schema + * bullets (`name`, `type`, …) are not tool ids. Without the any-model * sentence, the Conversations scope, or an id, it throws. Mistral's other * built-in tools (code interpreter, image generation, libraries) make no * any-model statement, so they are not read. */ export function parseMistralWebSearchTools(markdown: string): Array { - if (!/allows any of our models to access the web/.test(markdown)) { + const page = mistralDocsMarkdown(markdown) + if (!/allows any of our models to access the web/.test(page)) { throw new Error('mistral websearch guide: no any-model statement') } - if (!/work with the \[Conversations API\]/.test(markdown)) { + if (!/work with the \[Conversations API\]/.test(page)) { throw new Error('mistral websearch guide: no Conversations API scope') } - const versions = markdown.split(/^There are two versions:$/m)[1] ?? '' - const ids = [...versions.matchAll(/^- `([a-z][a-z0-9_]*)`:/gm)].map( - (match) => match[1] ?? '', - ) + const versions = page.split(/^There are two versions:$/m)[1] ?? '' + const ids: Array = [] + for (const line of versions.split('\n')) { + const match = /^- `([a-z][a-z0-9_]*)`:/.exec(line) + if (match?.[1]) { + ids.push(match[1]) + continue + } + if (ids.length > 0 && line.trim() !== '') break + } if (ids.length === 0) { throw new Error('mistral websearch guide: names no tool id') } diff --git a/src/server/providers/reasoning-config.test.ts b/src/server/providers/reasoning-config.test.ts index 8f69027a..4e971e3d 100644 --- a/src/server/providers/reasoning-config.test.ts +++ b/src/server/providers/reasoning-config.test.ts @@ -334,6 +334,58 @@ describe('parseMistralReasoning', () => { undefined, ) }) + + it('reads the rendered guide, including a model whose own levels replace the shared list', () => { + const html = `
+
    +
  • Mistral Small 4 (mistral-small-2603): Supports adjustable reasoning via the reasoning_effort parameter.
  • +
  • Mistral Medium 3.5 (mistral-medium-3-5): Supports adjustable reasoning via the reasoning_effort parameter.
  • +
  • Mistral Large 4 (mistral-large-4-0): Supports low, medium, and high reasoning effort.
  • +
  • zai-glm-5-3: Supports adjustable reasoning via the reasoning_effort parameter. Supported values are low, high, and max (see note below).
  • +
  • GLM 5.3 Flash (zai-glm-5-3-flash): Supports low, high, and max reasoning effort. none is not supported.
  • +
+

The reasoning_effort parameter controls how much compute the model spends reasoning. For mistral-small-2603 and mistral-medium-3-5:

+
    +
  • reasoning_effort = "high": The response includes a full thinking chunk before the final answer.
  • +
  • reasoning_effort = "none": The model thinks minimally and the thinking chunk is omitted from the response.
  • +
+

zai-glm-5-3 supports low, high, and max — not none. message.content is always returned as a list of chunks (thinking + text).

+

described in Handling thinking chunks.

+

Mistral Large 4 reasoning effort

+

Mistral Large 4 (mistral-large-4 / mistral-large-4-0) supports three reasoning levels:

+

Mistral Large 4 always reasons, so no level matches none.

+

Usage

+
` + const parsed = parseMistralReasoning(html) + expect(parsed.get('mistral-small-2603')).toEqual({ + mode: 'effort', + mandatory: false, + efforts: ['high', 'none'], + }) + expect(parsed.get('mistral-medium-3-5')).toEqual({ + mode: 'effort', + mandatory: false, + efforts: ['high', 'none'], + }) + expect(parsed.get('zai-glm-5-3')).toEqual({ + mode: 'effort', + mandatory: true, + efforts: ['low', 'high', 'max'], + }) + expect(parsed.get('zai-glm-5-3-flash')).toEqual({ + mode: 'effort', + mandatory: null, + efforts: ['low', 'high', 'max'], + }) + expect(parsed.get('mistral-large-4-0')).toEqual({ + mode: 'effort', + mandatory: true, + efforts: ['low', 'medium', 'high'], + }) + expect(parsed.get('mistral-large-4')).toEqual( + parsed.get('mistral-large-4-0'), + ) + }) }) describe('parseGroqReasoning', () => { diff --git a/src/server/providers/reasoning-config.ts b/src/server/providers/reasoning-config.ts index f7a7eec8..539b6e60 100644 --- a/src/server/providers/reasoning-config.ts +++ b/src/server/providers/reasoning-config.ts @@ -21,8 +21,61 @@ import type { ByteplusDoc } from './byteplus-pricing.ts' import { fetchText, reasoningViolation, sha256Text } from './types.ts' import type { ModelFactSources, ModelInfo, ModelReasoning } from './types.ts' +/** + * The rendered reasoning guide. `https://docs.mistral.ai/llms.txt` links + * `https://docs.mistral.ai/inference/conversations/reasoning.md`, and the + * old `/studio/conversations/reasoning.md` redirects there, but that + * markdown twin 404s (checked 2026-11-19). This HTML page is what serves + * the guide. + */ export const MISTRAL_REASONING_URL = - 'https://docs.mistral.ai/studio/conversations/reasoning.md' + 'https://docs.mistral.ai/inference/conversations/reasoning' + +/** + * Mistral's docs site returns a full HTML document where `llms.txt` still + * names a `.md` twin. The reasoning and web-search parsers read the + * markdown shape, so a rendered page becomes that shape: code becomes + * backticks, links become `[text]`, list items become bullets. A markdown + * body is returned unchanged. + */ +export function mistralDocsMarkdown(body: string): string { + if (!/]/i.test(body)) return body + let text = body + .replace(/]*>[\s\S]*?<\/script>/gi, '') + .replace(/]*>[\s\S]*?<\/style>/gi, '') + const main = text.match(/]*>[\s\S]*?<\/main>/i) + text = main?.[0] ?? text + // Code before links, so a linked code span is still a backtick. + // Links need brackets: the web-search parser matches `[Conversations API]`. + text = text + .replace(/]*>/gi, '`') + .replace(/<\/code>/gi, '`') + .replace(/]*>([\s\S]*?)<\/a>/gi, '[$1]') + .replace(/]*>/gi, '\n- ') + .replace( + /]*>/gi, + (_, level: string) => `\n${'#'.repeat(Number(level))} `, + ) + .replace(/<\/h[1-6]>/gi, '\n') + .replace(//gi, '\n') + .replace(/<\/(p|div|li|tr|ul|ol|section)>/gi, '\n') + .replace(/<[^>]+>/g, '') + text = text + .replace(/ /g, ' ') + .replace(/"/g, '"') + .replace(/'|'/g, "'") + .replace(/</g, '<') + .replace(/>/g, '>') + .replace(/&#(\d+);/g, (_, digits: string) => + String.fromCodePoint(Number(digits)), + ) + .replace(/&#x([0-9a-f]+);/gi, (_, hex: string) => + String.fromCodePoint(Number.parseInt(hex, 16)), + ) + .replace(/&/g, '&') + return text.replace(/[ \t]+\n/g, '\n').replace(/\n{3,}/g, '\n\n') +} + export const GROQ_REASONING_URL = 'https://console.groq.com/docs/reasoning.md' export const COHERE_REASONING_URL = 'https://docs.cohere.com/docs/reasoning.md' export const BYTEPLUS_REASONING_URL = @@ -200,18 +253,20 @@ export function openRouterReasoning( /** * Mistral's reasoning guide. Bullets that name `reasoning_effort` are effort * mode. Effort names are the `reasoning_effort = "…"` values, unless the - * same bullet publishes its own list. Native "always on, no parameter" + * same bullet publishes its own list. A bullet that names its own effort + * levels ("Supports `low`, `medium`, and `high` reasoning effort") is that + * model's list, not the shared one. Native "always on, no parameter" * prose names no mode and contributes nothing. */ export function parseMistralReasoning( markdown: string, ): Map { const out = new Map() - const prose = markdown.replace(/```[\s\S]*?```/g, '') + const prose = mistralDocsMarkdown(markdown).replace(/```[\s\S]*?```/g, '') const preludeEnd = prose.search(/handling thinking chunks/i) const prelude = preludeEnd < 0 ? prose : prose.slice(0, preludeEnd) const bullet = - /`([a-z0-9][a-z0-9.-]*)`:\s*Supports adjustable reasoning via the `reasoning_effort`/g + /`([a-z0-9][a-z0-9.-]*)`\)?:\s*Supports adjustable reasoning via the `reasoning_effort`/g // `reasoning_effort = "none"` omits the thinking chunk for Mistral models. // Example assignments are still not an allowlist. A model's own value list // below replaces this. @@ -272,9 +327,63 @@ export function parseMistralReasoning( efforts, }) } + // Own effort names on the bullet itself. Applied after the shared + // high/none list so that list does not replace them. A list with no + // `none` leaves mandatory null until prose says the model always reasons. + const namedEfforts = new Set() + const named = + /`([a-z0-9][a-z0-9.-]*)`\)?:\s*Supports\s+([^.\n]{0,200}?)\sreasoning effort/g + for (const match of prose.matchAll(named)) { + const id = match[1] + const efforts = [...(match[2] ?? '').matchAll(/`([a-z]+)`/g)].flatMap( + (found) => (found[1] ? [found[1]] : []), + ) + if (!id || efforts.length === 0) continue + out.set(id, { mode: 'effort', mandatory: null, efforts }) + namedEfforts.add(id) + } + // "`mistral-large-4` / `mistral-large-4-0`) supports three reasoning levels" + const sharedLadder = + /`([a-z0-9][a-z0-9.-]*)`\s*\/\s*`([a-z0-9][a-z0-9.-]*)`\)\s*supports three reasoning levels/gi + for (const match of prose.matchAll(sharedLadder)) { + const leftId = match[1] + const rightId = match[2] + if (!leftId || !rightId) continue + const left = out.get(leftId) + const right = out.get(rightId) + if (left && !right) { + out.set(rightId, { ...left }) + namedEfforts.add(rightId) + } else if (right && !left) { + out.set(leftId, { ...right }) + namedEfforts.add(leftId) + } + } + for (const id of namedEfforts) { + const reasoning = out.get(id) + if (!reasoning || reasoning.efforts?.includes('none')) continue + if (!statesAlwaysReasons(prose, id)) continue + out.set(id, { ...reasoning, mandatory: true }) + } return out } +/** The id's section says reasoning cannot be turned off. */ +function statesAlwaysReasons(prose: string, id: string): boolean { + const needle = '`' + id + '`' + let from = 0 + while (from < prose.length) { + const at = prose.indexOf(needle, from) + if (at < 0) return false + const rest = prose.slice(at) + const heading = rest.search(/\n#{2,3} /) + const block = heading < 0 ? rest.slice(0, 1600) : rest.slice(0, heading) + if (/always reasons/i.test(block)) return true + from = at + needle.length + } + return false +} + interface NamedModel { id: string label: string