use std::sync::Arc;
use crate::FactId;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CallerRole {
Human,
Llm,
Unknown,
}
impl CallerRole {
pub const fn as_str(self) -> &'static str {
match self {
CallerRole::Human => "human",
CallerRole::Llm => "llm",
CallerRole::Unknown => "unknown",
}
}
pub fn from_str_opt(s: &str) -> Self {
match s {
"human" => CallerRole::Human,
"llm" => CallerRole::Llm,
_ => CallerRole::Unknown,
}
}
}
impl core::fmt::Display for CallerRole {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.write_str(self.as_str())
}
}
pub type CallerRoleResolver = Arc<dyn Fn(&IoCallContext) -> CallerRole + Send + Sync>;
#[derive(Debug, Clone)]
pub struct IoCallContext {
pub cause: FactId,
pub v_trigger: u64,
pub caller_role: CallerRole,
pub cause_chain: Vec<FactId>,
pub tenant_id: Option<String>,
}
impl IoCallContext {
pub fn new(cause: FactId, v_trigger: u64, tenant_id: Option<String>) -> Self {
Self {
cause,
v_trigger,
caller_role: CallerRole::Unknown,
cause_chain: Vec::new(),
tenant_id,
}
}
}
impl Default for IoCallContext {
fn default() -> Self {
Self {
cause: FactId(0),
v_trigger: 0,
caller_role: CallerRole::Unknown,
cause_chain: Vec::new(),
tenant_id: None,
}
}
}