vtcode-llm 0.169.2

LLM provider abstraction, client implementations, and streaming for VT Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
//! Model capability detection for Anthropic Claude models
//!
//! Provides methods to determine what features each Claude model supports:
//! - Reasoning/extended thinking
//! - Vision (image inputs)
//! - Structured outputs
//! - Parallel tool configuration
//! - Context window sizes

use crate::providers::anthropic_types::{ThinkingConfig, ThinkingDisplay};
use vtcode_config::constants::{models, reasoning};

const CLAUDE_OPUS_4_8: &str = "claude-opus-4-8";

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum ClaudeThinkingMode {
    ManualBudget,
    Adaptive,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct ClaudeThinkingProfile {
    pub mode: ClaudeThinkingMode,
    pub supports_manual_budget: bool,
    pub adaptive_only: bool,
    pub default_thinking_enabled: bool,
    pub manual_interleaved_beta: bool,
    pub supports_effort: bool,
    pub supports_task_budget: bool,
    pub default_display: ThinkingDisplay,
    pub default_effort: &'static str,
    pub supports_xhigh_effort: bool,
    pub supports_max_effort: bool,
    /// `max_tokens` sent when the caller does not set one. It caps thinking
    /// plus response text together, so it must leave room for adaptive
    /// thinking on agentic turns while staying within the model's output limit.
    pub default_max_tokens: u32,
    /// Whether `tool_choice` `any`/`tool` is rejected with a 400 regardless
    /// of the thinking config. Such requests must fall back to `auto`.
    pub rejects_forced_tool_choice: bool,
    /// Whether the model accepts server-side refusal fallbacks (the
    /// `fallbacks` request parameter). Sonnet 5 is not listed as supported.
    pub supports_server_side_fallback: bool,
}

/// Default `max_tokens` for Claude 5.x models: a starting point for agentic
/// coding that stays within their 128K output limit.
const CLAUDE_5_DEFAULT_MAX_TOKENS: u32 = 64_000;
/// Default `max_tokens` for unprofiled models when thinking is enabled.
const LEGACY_THINKING_DEFAULT_MAX_TOKENS: u32 = 16_000;
/// Default `max_tokens` for unprofiled models when thinking is disabled.
const LEGACY_DEFAULT_MAX_TOKENS: u32 = 4_096;

const ANTHROPIC_EFFORTS_UP_TO_HIGH: &[&str] = &[reasoning::LOW, reasoning::MEDIUM, reasoning::HIGH];
const ANTHROPIC_EFFORTS_UP_TO_MAX: &[&str] = &[reasoning::LOW, reasoning::MEDIUM, reasoning::HIGH, reasoning::MAX];
const ANTHROPIC_EFFORTS_UP_TO_XHIGH_AND_MAX: &[&str] = &[
    reasoning::LOW,
    reasoning::MEDIUM,
    reasoning::HIGH,
    reasoning::XHIGH,
    reasoning::MAX,
];

pub(crate) fn resolve_model_name<'a>(model: &'a str, default_model: &'a str) -> &'a str {
    if model.trim().is_empty() { default_model } else { model }
}

pub(crate) fn matches_model(model: &str, candidate: &str) -> bool {
    model == candidate || model.contains(candidate)
}

pub(crate) fn claude_thinking_profile(model: &str, default_model: &str) -> Option<ClaudeThinkingProfile> {
    let requested = resolve_model_name(model, default_model);

    // Check most specific models first – `matches_model` uses `contains`,
    // so `claude-fable-5-1` contains `claude-fable-5`. The 5.1 variants
    // must be checked before their 5 counterparts.
    if matches_model(requested, models::anthropic::CLAUDE_FABLE_5_1) {
        return Some(ClaudeThinkingProfile {
            mode: ClaudeThinkingMode::Adaptive,
            supports_manual_budget: false,
            adaptive_only: true,
            default_thinking_enabled: true,
            manual_interleaved_beta: false,
            supports_effort: true,
            supports_task_budget: true,
            default_display: ThinkingDisplay::Omitted,
            default_effort: reasoning::HIGH,
            supports_xhigh_effort: true,
            supports_max_effort: true,
            default_max_tokens: CLAUDE_5_DEFAULT_MAX_TOKENS,
            rejects_forced_tool_choice: true,
            supports_server_side_fallback: true,
        });
    }

    if matches_model(requested, models::anthropic::CLAUDE_SONNET_5) {
        return Some(ClaudeThinkingProfile {
            mode: ClaudeThinkingMode::Adaptive,
            supports_manual_budget: false,
            adaptive_only: false,
            default_thinking_enabled: true,
            manual_interleaved_beta: false,
            supports_effort: true,
            supports_task_budget: false,
            default_display: ThinkingDisplay::Omitted,
            default_effort: reasoning::HIGH,
            supports_xhigh_effort: true,
            supports_max_effort: true,
            default_max_tokens: CLAUDE_5_DEFAULT_MAX_TOKENS,
            rejects_forced_tool_choice: false,
            supports_server_side_fallback: false,
        });
    }

    if matches_model(requested, models::anthropic::CLAUDE_FABLE_5) {
        return Some(ClaudeThinkingProfile {
            mode: ClaudeThinkingMode::Adaptive,
            supports_manual_budget: false,
            adaptive_only: true,
            default_thinking_enabled: true,
            manual_interleaved_beta: false,
            supports_effort: true,
            supports_task_budget: true,
            default_display: ThinkingDisplay::Omitted,
            default_effort: reasoning::HIGH,
            supports_xhigh_effort: true,
            supports_max_effort: true,
            default_max_tokens: CLAUDE_5_DEFAULT_MAX_TOKENS,
            rejects_forced_tool_choice: false,
            supports_server_side_fallback: true,
        });
    }

    // `claude-opus-5-5` contains `claude-opus-5`, so the 5.5 profile must be
    // checked before the 5 profile. Opus 5.5 runs adaptive thinking always on
    // (it cannot be disabled) with a `medium` default effort.
    if matches_model(requested, models::anthropic::CLAUDE_OPUS_5_5) {
        return Some(ClaudeThinkingProfile {
            mode: ClaudeThinkingMode::Adaptive,
            supports_manual_budget: false,
            adaptive_only: true,
            default_thinking_enabled: true,
            manual_interleaved_beta: false,
            supports_effort: true,
            supports_task_budget: true,
            default_display: ThinkingDisplay::Omitted,
            default_effort: reasoning::MEDIUM,
            supports_xhigh_effort: true,
            supports_max_effort: true,
            default_max_tokens: CLAUDE_5_DEFAULT_MAX_TOKENS,
            rejects_forced_tool_choice: true,
            supports_server_side_fallback: true,
        });
    }

    if matches_model(requested, models::anthropic::CLAUDE_OPUS_5) {
        return Some(ClaudeThinkingProfile {
            mode: ClaudeThinkingMode::Adaptive,
            supports_manual_budget: false,
            adaptive_only: false,
            default_thinking_enabled: true,
            manual_interleaved_beta: false,
            supports_effort: true,
            supports_task_budget: true,
            default_display: ThinkingDisplay::Omitted,
            default_effort: reasoning::HIGH,
            supports_xhigh_effort: true,
            supports_max_effort: true,
            default_max_tokens: CLAUDE_5_DEFAULT_MAX_TOKENS,
            rejects_forced_tool_choice: false,
            supports_server_side_fallback: true,
        });
    }

    None
}

/// Claude 5.x family ids. `matches_model` uses `contains`, so the Fable 5 id
/// also matches `claude-fable-5-1` and the Opus 5 id matches `claude-opus-5-5`.
const CLAUDE_5_FAMILY: &[&str] = &[
    models::anthropic::CLAUDE_SONNET_5,
    models::anthropic::CLAUDE_FABLE_5,
    models::anthropic::CLAUDE_OPUS_5,
];

fn is_claude_5_family(model: &str) -> bool {
    CLAUDE_5_FAMILY.iter().any(|candidate| matches_model(model, candidate))
}

fn supports_native_1m_context(model: &str) -> bool {
    is_claude_5_family(model)
}

pub(crate) fn supports_reasoning(model: &str, default_model: &str) -> bool {
    let requested = resolve_model_name(model, default_model);
    if claude_thinking_profile(requested, default_model).is_some() {
        return true;
    }

    models::minimax::SUPPORTED_MODELS.contains(&requested)
}

pub(crate) fn supports_reasoning_effort(model: &str, default_model: &str) -> bool {
    let requested = resolve_model_name(model, default_model);

    if claude_thinking_profile(requested, default_model).is_some() {
        return true;
    }

    if models::minimax::SUPPORTED_MODELS.contains(&requested) {
        return true;
    }

    models::anthropic::REASONING_MODELS.contains(&requested)
}

pub(crate) fn supports_effort(model: &str, default_model: &str) -> bool {
    claude_thinking_profile(model, default_model).is_some_and(|profile| profile.supports_effort)
}

pub(crate) fn supports_task_budget(model: &str, default_model: &str) -> bool {
    claude_thinking_profile(model, default_model).is_some_and(|profile| profile.supports_task_budget)
}

pub(crate) fn supports_manual_thinking_budget(model: &str, default_model: &str) -> bool {
    claude_thinking_profile(model, default_model).is_some_and(|profile| profile.supports_manual_budget)
}

pub(crate) fn supports_manual_interleaved_beta(model: &str, default_model: &str) -> bool {
    claude_thinking_profile(model, default_model).is_some_and(|profile| profile.manual_interleaved_beta)
}

/// Whether the model accepts a request whose last message is an assistant
/// turn (assistant-message prefill). A trailing assistant turn returns 400 on
/// Claude Opus/Sonnet 4.6 and later, which covers every profiled Claude 5.x
/// model. Older Claude models and non-Claude Anthropic-compatible backends
/// (MiniMax and similar) accept it, so their history is sent unchanged. A
/// Claude id without a recognizable version is treated as a current model.
pub(crate) fn supports_assistant_prefill(model: &str, default_model: &str) -> bool {
    let requested = resolve_model_name(model, default_model);
    if claude_thinking_profile(requested, default_model).is_some() {
        return false;
    }

    let lowered = requested.to_ascii_lowercase();
    let Some(start) = lowered.find("claude") else {
        return true;
    };
    claude_version(&lowered[start..]).is_some_and(|version| version < (4, 6))
}

/// Extracts `(major, minor)` from a Claude model id such as
/// `claude-opus-4-1`, `claude-3-5-sonnet-20240620`, `claude-sonnet-4@20250514`
/// or `claude-2.1`. The first short numeric segment is the major version and a
/// directly following short numeric segment is the minor version; eight-digit
/// date snapshots are not version segments.
fn claude_version(id: &str) -> Option<(u32, u32)> {
    let mut segments = id
        .split(['-', '.', '@', ':', '_'])
        .skip_while(|segment| !is_version_segment(segment));
    let major = segments.next()?.parse().ok()?;
    let minor = segments
        .next()
        .filter(|segment| is_version_segment(segment))
        .and_then(|segment| segment.parse().ok())
        .unwrap_or(0);
    Some((major, minor))
}

fn is_version_segment(segment: &str) -> bool {
    (1..=2).contains(&segment.len()) && segment.bytes().all(|b| b.is_ascii_digit())
}

pub(crate) fn supports_mid_conversation_system_messages(model: &str, default_model: &str) -> bool {
    supports_turn_scoped_system_messages(model, default_model)
}

/// Whether the model accepts Anthropic's turn-scoped `clear_at` system-message
/// field. The current beta is available to the model families that accept
/// mid-conversation system messages, but not Sonnet 5.
pub(crate) fn supports_turn_scoped_system_messages(model: &str, default_model: &str) -> bool {
    let requested = resolve_model_name(model, default_model);
    matches_model(requested, models::anthropic::CLAUDE_FABLE_5)
        || matches_model(requested, CLAUDE_OPUS_4_8)
        || matches_model(requested, models::anthropic::CLAUDE_OPUS_5)
}

pub(crate) fn adaptive_thinking_always_on(model: &str, default_model: &str) -> bool {
    claude_thinking_profile(model, default_model).is_some_and(|profile| profile.adaptive_only)
}

/// The `max_tokens` to send when the request does not set one. Profiled
/// models use their profile default regardless of the thinking field, since
/// they think adaptively even when it is omitted; other models fall back to
/// the legacy defaults.
pub(crate) fn default_max_tokens_for_model(model: &str, default_model: &str, thinking_enabled: bool) -> u32 {
    match claude_thinking_profile(model, default_model) {
        Some(profile) => profile.default_max_tokens,
        None if thinking_enabled => LEGACY_THINKING_DEFAULT_MAX_TOKENS,
        None => LEGACY_DEFAULT_MAX_TOKENS,
    }
}

/// Whether `model` rejects forced tool use (`tool_choice` `any`/`tool`)
/// even when thinking is off.
pub(crate) fn rejects_forced_tool_choice(model: &str, default_model: &str) -> bool {
    claude_thinking_profile(model, default_model).is_some_and(|profile| profile.rejects_forced_tool_choice)
}

/// Whether `model` accepts server-side refusal fallbacks. Unprofiled models
/// never get fallbacks requested on their behalf.
pub(crate) fn supports_server_side_fallback(model: &str, default_model: &str) -> bool {
    claude_thinking_profile(model, default_model).is_some_and(|profile| profile.supports_server_side_fallback)
}

/// Whether a request to `model` with this `thinking` field runs with thinking
/// on. An omitted field means the model's default, which is on for every
/// profiled Claude 5.x model (Opus 5.5 omits `disabled` because it rejects it).
pub(crate) fn thinking_is_on(thinking: Option<&ThinkingConfig>, model: &str, default_model: &str) -> bool {
    match thinking {
        Some(ThinkingConfig::Disabled) => false,
        // Unknown configs are treated as thinking so callers stay conservative.
        Some(_) => true,
        None => claude_thinking_profile(model, default_model).is_some_and(|profile| profile.default_thinking_enabled),
    }
}

/// Whether the model enforces "preserved thinking": each replayed thinking
/// block's signature binds the exact prefix that produced it (top-level
/// `system`, the `tools` set, and every earlier message). Any reorder or edit
/// of earlier turns invalidates every later thinking block (a 400 on
/// enforced accounts, a silent drop otherwise), so request builders must keep
/// history append-only for these models.
pub(crate) fn preserves_thinking_across_turns(model: &str, default_model: &str) -> bool {
    let requested = resolve_model_name(model, default_model);
    matches_model(requested, models::anthropic::CLAUDE_OPUS_5_5)
        || matches_model(requested, models::anthropic::CLAUDE_FABLE_5_1)
}

/// Whether the model accepts `thinking.display: "updates"` (beta
/// `thinking-display-updates-2026-08-18`): its between-tool progress notes
/// come back as their own `thinking` blocks. Other models reject the value.
/// `claude-fable-5-1` contains the Fable 5 id, so both Fable releases match.
pub(crate) fn supports_thinking_display_updates(model: &str, default_model: &str) -> bool {
    let requested = resolve_model_name(model, default_model);
    matches_model(requested, models::anthropic::CLAUDE_OPUS_5_5)
        || matches_model(requested, models::anthropic::CLAUDE_FABLE_5)
}

/// Display used when neither the request nor `[provider.anthropic]` sets one.
/// On Claude Opus 5.5 the text written between tool calls arrives only as
/// progress-update thinking blocks, which the API default (`omitted`) empties;
/// requesting `updates` keeps that narration visible in the reasoning view
/// while the reasoning itself stays hidden.
pub(crate) fn default_thinking_display(model: &str, default_model: &str) -> Option<ThinkingDisplay> {
    let requested = resolve_model_name(model, default_model);
    matches_model(requested, models::anthropic::CLAUDE_OPUS_5_5).then_some(ThinkingDisplay::Updates)
}

pub(crate) fn default_effort_for_model(model: &str, default_model: &str) -> Option<&'static str> {
    claude_thinking_profile(model, default_model)
        .filter(|profile| profile.supports_effort)
        .map(|profile| profile.default_effort)
}

pub(crate) fn allowed_efforts_for_model(model: &str, default_model: &str) -> Option<&'static [&'static str]> {
    let profile = claude_thinking_profile(model, default_model)?;
    if !profile.supports_effort {
        return None;
    }

    if profile.supports_xhigh_effort {
        Some(ANTHROPIC_EFFORTS_UP_TO_XHIGH_AND_MAX)
    } else if profile.supports_max_effort {
        Some(ANTHROPIC_EFFORTS_UP_TO_MAX)
    } else {
        Some(ANTHROPIC_EFFORTS_UP_TO_HIGH)
    }
}

pub(crate) fn effort_allowed_for_model(model: &str, default_model: &str, effort: &str) -> bool {
    let normalized = effort.trim().to_ascii_lowercase();
    allowed_efforts_for_model(model, default_model).is_some_and(|allowed| allowed.contains(&normalized.as_str()))
}

pub(crate) fn supports_compaction(model: &str) -> bool {
    is_claude_5_family(model)
}

pub(crate) fn supports_parallel_tool_config(_model: &str) -> bool {
    true
}

pub fn effective_context_size(model: &str) -> usize {
    if supports_native_1m_context(model) {
        1_000_000
    } else {
        200_000
    }
}

pub(crate) fn rejects_sampling(model: &str, default_model: &str) -> bool {
    is_claude_5_family(resolve_model_name(model, default_model))
}

/// Pre-5.x Claude models without a thinking profile that still accept
/// structured outputs.
const LEGACY_STRUCTURED_OUTPUT_MODELS: &[&str] = &["claude-sonnet-4-5", "claude-opus-4-5"];

pub(crate) fn supports_structured_output(model: &str, default_model: &str) -> bool {
    let requested = resolve_model_name(model, default_model);

    // All models with a thinking profile support structured outputs.
    if claude_thinking_profile(requested, default_model).is_some() {
        return true;
    }

    LEGACY_STRUCTURED_OUTPUT_MODELS
        .iter()
        .any(|candidate| matches_model(requested, candidate))
}

/// Model ids that accept structured outputs, derived from
/// `supports_structured_output` so user-facing errors cannot drift from it:
/// every supported model with a thinking profile, then the legacy ids.
pub(crate) fn structured_output_models() -> Vec<&'static str> {
    models::anthropic::SUPPORTED_MODELS
        .iter()
        .copied()
        .filter(|model| supports_structured_output(model, ""))
        .chain(LEGACY_STRUCTURED_OUTPUT_MODELS.iter().copied())
        .collect()
}

pub(crate) fn supports_vision(model: &str, default_model: &str) -> bool {
    let requested = resolve_model_name(model, default_model);

    // All models with a thinking profile support vision.
    if claude_thinking_profile(requested, default_model).is_some() {
        return true;
    }

    // Legacy Claude 3 and Claude 4 Sonnet families support vision.
    requested.starts_with("claude-3") || requested.starts_with("claude-4-sonnet")
}

pub fn is_claude_model(model: &str, default_model: &str) -> bool {
    claude_thinking_profile(model, default_model).is_some()
}

pub(crate) fn supported_models() -> Vec<String> {
    let mut supported: Vec<String> = models::anthropic::SUPPORTED_MODELS.iter().map(|s| s.to_string()).collect();

    supported.extend(models::minimax::SUPPORTED_MODELS.iter().map(|s| s.to_string()));

    supported.sort();
    supported.dedup();
    supported
}

/// Returns true if the effective effort for this request is "low", "medium", or "high"
/// (i.e., at most high, not xhigh or max).
///
/// This is used by Opus 5 disabled-thinking validation: Opus 5 only allows
/// `thinking: {type: "disabled"}` at effort ≤ high. When the override is `Omit`,
/// the API uses the model default effort, so we check that instead of the config.
pub(crate) fn effort_is_at_most_high(
    request: &crate::provider::LLMRequest,
    anthropic_config: &vtcode_config::core::AnthropicConfig,
) -> bool {
    use crate::provider::{AnthropicOptionalStringOverride, LLMRequest};
    use vtcode_config::types::ReasoningEffortLevel;

    if let Some(overrides) = request.anthropic_request_overrides.as_ref() {
        match &overrides.effort {
            AnthropicOptionalStringOverride::Explicit(effort) => {
                return effort_str_is_at_most_high(effort);
            }
            AnthropicOptionalStringOverride::Omit => {
                return default_effort_for_model(&request.model, "").is_some_and(effort_str_is_at_most_high);
            }
            AnthropicOptionalStringOverride::Inherit => {}
        }
    }

    if let Some(effort) = request.effort.as_ref() {
        return effort_str_is_at_most_high(effort);
    }
    if let Some(effort) = request.reasoning_effort {
        return matches!(effort, ReasoningEffortLevel::Low | ReasoningEffortLevel::Medium | ReasoningEffortLevel::High);
    }
    match anthropic_config.effort {
        Some(effort) => effort_str_is_at_most_high(effort.as_str()),
        None => default_effort_for_model(&request.model, "").is_some_and(effort_str_is_at_most_high),
    }
}

/// Returns true if `effort` names one of the `low`, `medium`, or `high`
/// levels (case-insensitive).
pub(crate) fn effort_str_is_at_most_high(effort: &str) -> bool {
    let normalized = effort.trim().to_ascii_lowercase();
    matches!(normalized.as_str(), reasoning::LOW | reasoning::MEDIUM | reasoning::HIGH)
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn opus_5_5_runs_adaptive_thinking_always_on_with_medium_default() {
        let profile = claude_thinking_profile(models::anthropic::CLAUDE_OPUS_5_5, "").expect("opus 5.5 profile");
        assert!(profile.adaptive_only);
        assert_eq!(profile.default_effort, reasoning::MEDIUM);
        assert!(profile.supports_xhigh_effort);
        assert!(profile.supports_max_effort);
        assert!(adaptive_thinking_always_on(models::anthropic::CLAUDE_OPUS_5_5, ""));
        assert_eq!(default_effort_for_model(models::anthropic::CLAUDE_OPUS_5_5, ""), Some(reasoning::MEDIUM));
    }

    #[test]
    fn opus_5_profile_is_unchanged_by_opus_5_5() {
        // `claude-opus-5-5` contains `claude-opus-5`; the 5 profile must still
        // resolve for the exact 5 id with its high default and opt-out support.
        let profile = claude_thinking_profile(models::anthropic::CLAUDE_OPUS_5, "").expect("opus 5 profile");
        assert!(!profile.adaptive_only);
        assert_eq!(profile.default_effort, reasoning::HIGH);
        assert!(!adaptive_thinking_always_on(models::anthropic::CLAUDE_OPUS_5, ""));
    }

    #[test]
    fn claude_5_models_default_to_64k_max_tokens_regardless_of_thinking() {
        for model in [
            models::anthropic::CLAUDE_FABLE_5_1,
            models::anthropic::CLAUDE_SONNET_5,
            models::anthropic::CLAUDE_FABLE_5,
            models::anthropic::CLAUDE_OPUS_5_5,
            models::anthropic::CLAUDE_OPUS_5,
        ] {
            let profile = claude_thinking_profile(model, "").expect("claude 5.x profile");
            assert_eq!(profile.default_max_tokens, 64_000, "{model}");
            assert_eq!(default_max_tokens_for_model(model, "", true), 64_000, "{model}");
            assert_eq!(default_max_tokens_for_model(model, "", false), 64_000, "{model}");
        }
    }

    #[test]
    fn only_opus_5_5_and_fable_5_1_reject_forced_tool_choice() {
        assert!(rejects_forced_tool_choice(models::anthropic::CLAUDE_OPUS_5_5, ""));
        assert!(rejects_forced_tool_choice(models::anthropic::CLAUDE_FABLE_5_1, ""));
        for model in [
            models::anthropic::CLAUDE_SONNET_5,
            models::anthropic::CLAUDE_FABLE_5,
            models::anthropic::CLAUDE_OPUS_5,
            "claude-unlisted-model",
        ] {
            assert!(!rejects_forced_tool_choice(model, ""), "{model}");
        }
    }

    #[test]
    fn omitted_thinking_follows_the_model_default() {
        assert!(thinking_is_on(None, models::anthropic::CLAUDE_OPUS_5_5, ""));
        assert!(!thinking_is_on(None, "claude-unlisted-model", ""));
        assert!(!thinking_is_on(Some(&ThinkingConfig::Disabled), models::anthropic::CLAUDE_SONNET_5, ""));
        assert!(thinking_is_on(Some(&ThinkingConfig::Adaptive { display: None }), "claude-unlisted-model", ""));
    }

    #[test]
    fn unprofiled_models_keep_legacy_max_tokens_defaults() {
        assert_eq!(default_max_tokens_for_model("claude-unlisted-model", "", true), 16_000);
        assert_eq!(default_max_tokens_for_model("claude-unlisted-model", "", false), 4_096);
    }

    #[test]
    fn empty_model_uses_the_default_model_max_tokens() {
        assert_eq!(default_max_tokens_for_model("", models::anthropic::CLAUDE_SONNET_5, false), 64_000);
    }

    #[test]
    fn preserved_thinking_is_limited_to_prefix_bound_models() {
        assert!(preserves_thinking_across_turns(models::anthropic::CLAUDE_OPUS_5_5, ""));
        assert!(preserves_thinking_across_turns(models::anthropic::CLAUDE_FABLE_5_1, ""));
        assert!(preserves_thinking_across_turns("", models::anthropic::CLAUDE_OPUS_5_5));
        assert!(!preserves_thinking_across_turns(models::anthropic::CLAUDE_OPUS_5, ""));
        assert!(!preserves_thinking_across_turns(models::anthropic::CLAUDE_FABLE_5, ""));
        assert!(!preserves_thinking_across_turns(models::anthropic::CLAUDE_SONNET_5, ""));
    }

    #[test]
    fn thinking_display_updates_support_and_default() {
        for model in [
            models::anthropic::CLAUDE_OPUS_5_5,
            models::anthropic::CLAUDE_FABLE_5_1,
            models::anthropic::CLAUDE_FABLE_5,
        ] {
            assert!(supports_thinking_display_updates(model, ""), "{model}");
        }
        assert!(!supports_thinking_display_updates(models::anthropic::CLAUDE_OPUS_5, ""));
        assert!(!supports_thinking_display_updates(models::anthropic::CLAUDE_SONNET_5, ""));

        assert_eq!(default_thinking_display(models::anthropic::CLAUDE_OPUS_5_5, ""), Some(ThinkingDisplay::Updates));
        assert_eq!(default_thinking_display(models::anthropic::CLAUDE_OPUS_5, ""), None);
        assert_eq!(default_thinking_display(models::anthropic::CLAUDE_SONNET_5, ""), None);
    }

    #[test]
    fn claude_5_family_capabilities_cover_every_profiled_model() {
        for model in [
            models::anthropic::CLAUDE_SONNET_5,
            models::anthropic::CLAUDE_FABLE_5,
            models::anthropic::CLAUDE_FABLE_5_1,
            models::anthropic::CLAUDE_OPUS_5,
            models::anthropic::CLAUDE_OPUS_5_5,
        ] {
            assert!(claude_thinking_profile(model, "").is_some(), "{model}");
            assert_eq!(effective_context_size(model), 1_000_000, "{model}");
            assert!(supports_compaction(model), "{model}");
            assert!(rejects_sampling(model, ""), "{model}");
            assert!(supports_structured_output(model, ""), "{model}");
        }
        assert!(rejects_sampling("", models::anthropic::CLAUDE_OPUS_5_5));

        for model in [CLAUDE_OPUS_4_8, "claude-sonnet-4-5", models::minimax::MINIMAX_M3, ""] {
            assert_eq!(effective_context_size(model), 200_000, "{model}");
            assert!(!supports_compaction(model), "{model}");
            assert!(!rejects_sampling(model, ""), "{model}");
        }
        assert!(supports_structured_output("claude-sonnet-4-5", ""));
        assert!(supports_structured_output("claude-opus-4-5", ""));
        assert!(!supports_structured_output(models::minimax::MINIMAX_M3, ""));
    }

    #[test]
    fn assistant_prefill_is_rejected_by_claude_4_6_and_later() {
        for model in [
            models::anthropic::CLAUDE_SONNET_5,
            models::anthropic::CLAUDE_FABLE_5,
            models::anthropic::CLAUDE_FABLE_5_1,
            models::anthropic::CLAUDE_OPUS_5,
            models::anthropic::CLAUDE_OPUS_5_5,
            CLAUDE_OPUS_4_8,
            "claude-opus-4-7",
            "claude-opus-4-6",
            "claude-sonnet-4-6",
            "claude-sonnet-4-6@20260101",
            "anthropic.claude-opus-4-6-v1:0",
            "claude-mythos-preview",
            "claude-unlisted-model",
        ] {
            assert!(!supports_assistant_prefill(model, ""), "{model}");
        }
        assert!(!supports_assistant_prefill("", models::anthropic::CLAUDE_OPUS_5_5));
    }

    #[test]
    fn assistant_prefill_is_kept_for_older_claude_and_non_claude_backends() {
        for model in [
            "claude-haiku-4-5",
            "claude-sonnet-4-5-20250929",
            "claude-opus-4-1",
            "claude-sonnet-4-20250514",
            "claude-3-7-sonnet-20250219",
            "claude-2.1",
            models::minimax::MINIMAX_M3,
            "glm-4.6",
        ] {
            assert!(supports_assistant_prefill(model, ""), "{model}");
        }
    }
}