use serde::{Deserialize, Serialize};
use super::RequestProtocol;
use super::ids::{LogicalModelRef, ModelId, ProviderId, WireModelId};
use super::offering::RouteLimits;
use crate::ProviderKind;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ResolvedEndpoint {
pub base_url: String,
pub endpoint_key: String,
pub protocol: RequestProtocol,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum ResolvedAuthSource {
Cli,
ConfigFile,
Keyring,
Env,
Command,
Secret,
Missing,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum PricingSku {
Token {
input_per_mtok: Option<f64>,
output_per_mtok: Option<f64>,
},
SubscriptionQuota {
used_pct: Option<f32>,
resets_at: Option<String>,
},
AccountCredits {
balance: Option<f64>,
},
LocalOrNotApplicable,
UnknownOrStale,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ValidationReport {
pub ok: bool,
pub messages: Vec<String>,
}
#[derive(Debug, Clone, Serialize)]
#[non_exhaustive]
pub struct ReadyRouteCandidate {
pub provider_id: ProviderId,
pub provider_kind: ProviderKind,
pub logical_model: LogicalModelRef,
pub canonical_model: Option<ModelId>,
pub wire_model_id: WireModelId,
pub endpoint: ResolvedEndpoint,
pub auth: ResolvedAuthSource,
pub protocol: RequestProtocol,
pub limits: RouteLimits,
pub pricing: Option<PricingSku>,
pub validation: ValidationReport,
}
impl ReadyRouteCandidate {
#[allow(clippy::too_many_arguments)]
pub(super) fn new(
provider_id: ProviderId,
provider_kind: ProviderKind,
logical_model: LogicalModelRef,
canonical_model: Option<ModelId>,
wire_model_id: WireModelId,
endpoint: ResolvedEndpoint,
auth: ResolvedAuthSource,
protocol: RequestProtocol,
limits: RouteLimits,
pricing: Option<PricingSku>,
validation: ValidationReport,
) -> Self {
Self {
provider_id,
provider_kind,
logical_model,
canonical_model,
wire_model_id,
endpoint,
auth,
protocol,
limits,
pricing,
validation,
}
}
}