use std::sync::Arc;
use crate::trust_graph::AutonomyTier;
use crate::value::VmClosure;
#[derive(Clone)]
pub enum TriggerHandlerSpec {
Local {
raw: String,
callable: crate::value::VmCallable,
},
A2a {
target: String,
allow_cleartext: bool,
},
Worker {
queue: String,
},
Persona {
binding: crate::PersonaRuntimeBinding,
callable: crate::value::VmCallable,
},
EvalPack {
target: String,
manifest: Box<crate::orchestration::EvalPackManifest>,
ledger_options: Option<serde_json::Value>,
},
AutoResume {
worker_id: String,
},
SpawnToPool {
pool: String,
priority_from: Option<String>,
key_from: Option<String>,
task_factory: Arc<VmClosure>,
},
ReminderInject {
target: TargetExpr,
body: String,
tags: Vec<String>,
ttl_turns: Option<i64>,
dedupe_key: Option<String>,
propagate: crate::llm::helpers::ReminderPropagate,
role_hint: crate::llm::helpers::ReminderRoleHint,
preserve_on_compact: bool,
},
InterruptAndSuspend {
target_agents: AgentScope,
reason: String,
},
}
#[derive(Clone)]
pub enum AgentScope {
All,
Concrete(Vec<String>),
Closure(Arc<VmClosure>),
}
impl AgentScope {
pub fn kind(&self) -> &'static str {
match self {
Self::All => "all",
Self::Concrete(_) => "concrete",
Self::Closure(_) => "closure",
}
}
}
impl std::fmt::Debug for AgentScope {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::All => f.write_str("All"),
Self::Concrete(ids) => f.debug_tuple("Concrete").field(ids).finish(),
Self::Closure(_) => f.write_str("Closure(<vm_closure>)"),
}
}
}
#[derive(Clone)]
pub enum TargetExpr {
Current,
Parent,
Concrete(String),
Closure(Arc<VmClosure>),
}
impl TargetExpr {
pub fn kind(&self) -> &'static str {
match self {
Self::Current => "current",
Self::Parent => "parent",
Self::Concrete(_) => "concrete",
Self::Closure(_) => "closure",
}
}
}
impl std::fmt::Debug for TargetExpr {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Current => f.write_str("Current"),
Self::Parent => f.write_str("Parent"),
Self::Concrete(id) => f.debug_tuple("Concrete").field(id).finish(),
Self::Closure(_) => f.write_str("Closure(<vm_closure>)"),
}
}
}
impl std::fmt::Debug for TriggerHandlerSpec {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Local { raw, .. } => f.debug_struct("Local").field("raw", raw).finish(),
Self::A2a {
target,
allow_cleartext,
} => f
.debug_struct("A2a")
.field("target", target)
.field("allow_cleartext", allow_cleartext)
.finish(),
Self::Worker { queue } => f.debug_struct("Worker").field("queue", queue).finish(),
Self::Persona { binding, .. } => f
.debug_struct("Persona")
.field("name", &binding.name)
.finish(),
Self::EvalPack {
target,
manifest,
ledger_options,
} => f
.debug_struct("EvalPack")
.field("target", target)
.field("pack_id", &manifest.id)
.field("ledger_options", ledger_options)
.finish(),
Self::AutoResume { worker_id } => f
.debug_struct("AutoResume")
.field("worker_id", worker_id)
.finish(),
Self::SpawnToPool {
pool,
priority_from,
key_from,
..
} => f
.debug_struct("SpawnToPool")
.field("pool", pool)
.field("priority_from", priority_from)
.field("key_from", key_from)
.finish(),
Self::ReminderInject {
target,
body,
tags,
ttl_turns,
dedupe_key,
propagate,
role_hint,
preserve_on_compact,
} => f
.debug_struct("ReminderInject")
.field("target", target)
.field("body", body)
.field("tags", tags)
.field("ttl_turns", ttl_turns)
.field("dedupe_key", dedupe_key)
.field("propagate", propagate)
.field("role_hint", role_hint)
.field("preserve_on_compact", preserve_on_compact)
.finish(),
Self::InterruptAndSuspend {
target_agents,
reason,
} => f
.debug_struct("InterruptAndSuspend")
.field("target_agents", target_agents)
.field("reason", reason)
.finish(),
}
}
}
impl TriggerHandlerSpec {
pub fn kind(&self) -> &'static str {
match self {
Self::Local { .. } => "local",
Self::A2a { .. } => "a2a",
Self::Worker { .. } => "worker",
Self::Persona { .. } => "persona",
Self::EvalPack { .. } => "eval_pack",
Self::AutoResume { .. } => "auto_resume",
Self::SpawnToPool { .. } => "spawn_to_pool",
Self::ReminderInject { .. } => "reminder_inject",
Self::InterruptAndSuspend { .. } => "interrupt_and_suspend",
}
}
pub fn effective_autonomy_tier(&self, requested: AutonomyTier) -> AutonomyTier {
match self {
Self::Local { callable, .. } | Self::Persona { callable, .. } => {
callable.effective_autonomy_tier(requested)
}
_ => requested,
}
}
}