Public declaration syntax from forge-rs/crates/forge-provider-session/src/policy.rs Original source SHA-256: 61f4f958c119651a68c686160329ee6d579813afea93e73231c93780b0997355 Function bodies and constant values are omitted. This is not the complete implementation. Source line 38 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum ProviderType { /// Direct model provider (Anthropic, OpenAI, Google, etc.). DirectModel, /// Local model provider (Ollama, llama.cpp, etc.). Local, /// Routed through a gateway (Foundry, OpenRouter, etc.). Routed, /// Coding subscription provider (Claude Code, Codex, etc.). CodingSubscription, } Source line 69 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct TaskRoutingRule { /// If set, this rule only matches the given task mode. #[serde(default, skip_serializing_if = "Option::is_none")] pub task_mode: Option, /// If set, this rule only matches the given domain string. #[serde(default, skip_serializing_if = "Option::is_none")] pub domain: Option, /// The provider to use when this rule matches. pub provider_ref: String } Source line 86 pub fn matches_mode(&self, mode: &TaskMode) -> bool; Source line 96 pub fn matches_domain(&self, domain: &str) -> bool; Source line 106 pub fn matches(&self, task_mode: Option<&TaskMode>, domain: Option<&str>) -> bool; Source line 153 #[derive(Debug, Clone, Serialize, Deserialize)] pub struct SessionPolicy { } Source line 164 pub fn builder() -> SessionPolicyBuilder; Source line 169 pub fn name(&self) -> &str; Source line 174 pub fn default_provider(&self) -> Option<&str>; Source line 181 pub fn is_provider_allowed(&self, provider_ref: &str) -> bool; Source line 189 pub fn allow_runtime_swap(&self) -> bool; Source line 194 pub fn session_ttl_seconds(&self) -> Option; Source line 199 pub fn task_routing_rules(&self) -> &[TaskRoutingRule]; Source line 204 pub fn allowed_providers(&self) -> &[String]; Source line 219 pub fn open(name: impl Into) -> Self; Source line 246 #[derive(Debug, Default)] pub struct SessionPolicyBuilder { } Source line 257 pub fn new() -> Self; Source line 262 pub fn name(mut self, name: impl Into) -> Self; Source line 268 pub fn default_provider(mut self, provider_ref: impl Into) -> Self; Source line 274 pub fn allowed_provider(mut self, provider_ref: impl Into) -> Self; Source line 280 pub fn task_route(mut self, rule: TaskRoutingRule) -> Self; Source line 286 pub fn allow_runtime_swap(mut self, allowed: bool) -> Self; Source line 292 pub fn session_ttl_seconds(mut self, ttl: u64) -> Self; Source line 307 pub fn build(self) -> ProviderSessionResult; Source line 372 #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct PolicyDecision { /// The selected provider reference. pub provider_ref: String, /// Human-readable explanation of why this provider was selected. pub reason: String, /// Whether runtime swapping is allowed under the current policy. pub runtime_swap_allowed: bool } Source line 413 pub struct PolicyEngine { } Source line 419 pub fn new(policy: SessionPolicy) -> Self; Source line 424 pub fn policy(&self) -> &SessionPolicy; Source line 434 pub fn evaluate_default(&self) -> PolicyDecision; Source line 453 pub fn evaluate(&self, task_mode: Option<&TaskMode>, domain: Option<&str>) -> PolicyDecision; Source line 505 pub fn check_provider_allowed(&self, provider_ref: &str) -> ProviderSessionResult<()>; Source line 526 pub fn check_runtime_swap_allowed( &self, from_provider: &str, to_provider: &str, ) -> ProviderSessionResult<()>;