Skip to main content

codewhale_config/route/
offering.rs

1//! Provider model offerings (#3084).
2//!
3//! A [`ProviderModelOffering`] binds a provider to a canonical model, the
4//! provider-owned wire id that serves it, and the endpoint key. This is the
5//! seam that proves the #2608 invariant: the SAME canonical model can be served
6//! by multiple providers under DIFFERENT wire ids (some aggregator-prefixed),
7//! and a prefix never implies provider ownership.
8//!
9//! The hand-curated seed table is gone (#4139 / #3830 P1): catalog-derived
10//! offerings from [`crate::catalog::bundled_catalog_offerings`] are the single
11//! bundled source of truth. [`bundled_offerings`] remains as an empty seam so
12//! the resolver can still prepend curated overrides later without reintroducing
13//! a parallel seed list.
14
15use serde::{Deserialize, Serialize};
16
17use super::candidate::PricingSku;
18use super::ids::{ModelId, ProviderId, WireModelId};
19
20/// Token limits for one resolved route/offering.
21///
22/// These are optional because hosted catalogs, local runtimes, and custom
23/// endpoints can legitimately omit some or all limit facts. Callers should
24/// treat `None` as unknown, not zero.
25#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Serialize, Deserialize)]
26pub struct RouteLimits {
27    /// Total context window (input + output), in tokens.
28    #[serde(default, skip_serializing_if = "Option::is_none")]
29    pub context_tokens: Option<u64>,
30    /// Input-token limit, when the provider reports it separately.
31    #[serde(default, skip_serializing_if = "Option::is_none")]
32    pub input_tokens: Option<u64>,
33    /// Output-token cap for the route/offering, when known.
34    #[serde(default, skip_serializing_if = "Option::is_none")]
35    pub output_tokens: Option<u64>,
36}
37
38impl RouteLimits {
39    /// Whether at least one limit fact is known.
40    #[must_use]
41    pub const fn has_known_limit(self) -> bool {
42        self.context_tokens.is_some() || self.input_tokens.is_some() || self.output_tokens.is_some()
43    }
44}
45
46/// One provider's way of serving a (possibly canonical) model.
47///
48/// `Eq` is intentionally NOT derived: [`PricingSku::Token`] carries `f64` rates,
49/// so the offering is only `PartialEq`. No caller keys a set/map on offerings.
50#[derive(Debug, Clone, PartialEq)]
51pub struct ProviderModelOffering {
52    /// Provider serving this offering.
53    pub provider: ProviderId,
54    /// Canonical model identity, if this offering maps to one.
55    pub canonical_model: Option<ModelId>,
56    /// Provider-owned wire id sent on the request (verbatim).
57    pub wire_model_id: WireModelId,
58    /// Endpoint key the offering is served on.
59    pub endpoint_key: String,
60    /// Whether this is the provider's default offering.
61    pub default_for_provider: bool,
62    /// Provider/offering-scoped token limits, when known.
63    pub limits: RouteLimits,
64    /// Coarse route-facing pricing meter for this offering (#3085).
65    ///
66    /// Projected from the offering's sourced cost at the layer that owns it
67    /// (`CatalogOffering::to_offering` → [`crate::pricing::route_pricing_sku`]).
68    /// The resolver carries this verbatim onto the candidate; it is
69    /// [`PricingSku::UnknownOrStale`] whenever no price was sourced — never a
70    /// fabricated zero (the #2608 / #3085 honesty rule).
71    pub pricing: PricingSku,
72}
73
74/// Return the bundled offering seam as owned [`ProviderModelOffering`] rows.
75///
76/// Empty by design: every former hand-seed row is covered by the bundled
77/// Models.dev catalog ([`crate::catalog::bundled_catalog_offerings`]), which
78/// carries the same canonical-model joins via `base_model` plus honest limits
79/// and pricing the old seeds lacked (#4139 / #3830 P1 OFFERING_SEEDS dedupe).
80#[must_use]
81pub fn bundled_offerings() -> Vec<ProviderModelOffering> {
82    Vec::new()
83}