use agent_uri::{CapabilityPath, TrustRoot};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum MatchMode {
Exact,
Prefix,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Query {
trust_root: TrustRoot,
capability_path: CapabilityPath,
match_mode: MatchMode,
}
impl Query {
#[must_use]
pub const fn exact(trust_root: TrustRoot, capability_path: CapabilityPath) -> Self {
Self {
trust_root,
capability_path,
match_mode: MatchMode::Exact,
}
}
#[must_use]
pub const fn prefix(trust_root: TrustRoot, capability_path: CapabilityPath) -> Self {
Self {
trust_root,
capability_path,
match_mode: MatchMode::Prefix,
}
}
#[must_use]
pub const fn trust_root(&self) -> &TrustRoot {
&self.trust_root
}
#[must_use]
pub const fn capability_path(&self) -> &CapabilityPath {
&self.capability_path
}
#[must_use]
pub const fn match_mode(&self) -> MatchMode {
self.match_mode
}
}
#[cfg(test)]
mod tests {
use super::*;
fn parts() -> (TrustRoot, CapabilityPath) {
(
TrustRoot::parse("anthropic.com").unwrap(),
CapabilityPath::parse("assistant/chat").unwrap(),
)
}
#[test]
fn exact_query_records_its_mode() {
let (tr, path) = parts();
let q = Query::exact(tr, path);
assert_eq!(q.match_mode(), MatchMode::Exact);
assert_eq!(q.trust_root().as_str(), "anthropic.com");
assert_eq!(q.capability_path().as_str(), "assistant/chat");
}
#[test]
fn prefix_query_records_its_mode() {
let (tr, path) = parts();
let q = Query::prefix(tr, path);
assert_eq!(q.match_mode(), MatchMode::Prefix);
}
#[test]
fn queries_differing_only_in_mode_are_not_equal() {
let (tr, path) = parts();
assert_ne!(
Query::exact(tr.clone(), path.clone()),
Query::prefix(tr, path)
);
}
}