use async_trait::async_trait;
use openkind_core::{SystemRequest, SystemResponse};
use serde::{Deserialize, Serialize};
use crate::error::ApiError;
use crate::models::ModelsResponse;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ProxySource {
Local,
Upstream,
}
impl ProxySource {
pub fn as_str(&self) -> &'static str {
match self {
ProxySource::Local => "local",
ProxySource::Upstream => "upstream",
}
}
}
#[derive(Debug)]
pub struct ProxyOutcome {
pub response: SystemResponse,
pub source: ProxySource,
pub detail: Option<serde_json::Value>,
}
#[async_trait]
pub trait SystemProxy: Send + Sync {
fn wants(&self, request: &SystemRequest) -> bool;
fn forwards_caller_credentials(&self) -> bool {
true
}
async fn evaluate(
&self,
request: SystemRequest,
caller_key: Option<String>,
) -> Result<ProxyOutcome, ApiError>;
async fn models(&self) -> Option<ModelsResponse>;
}