use syn::visit_mut::VisitMut;
use syn::{ReturnType, Type};
pub fn is_constructor_method(sig: &syn::Signature, agent_impl_type: Option<&str>) -> bool {
match &sig.output {
ReturnType::Type(_, ty) => match &**ty {
Type::Path(tp) => {
let return_ident = &tp.path.segments.last().unwrap().ident;
return_ident == "Self"
|| match agent_impl_type {
Some(impl_name) => return_ident == impl_name,
None => false,
}
}
_ => false,
},
_ => false,
}
}
pub fn has_async_trait_attr(impl_block: &syn::ItemImpl) -> bool {
impl_block.attrs.iter().any(is_async_trait_attr)
}
pub fn is_async_trait_attr(attr: &syn::Attribute) -> bool {
let path = attr.path();
path.is_ident("async_trait") || path.is_ident("async_trait::async_trait")
}
pub fn has_agent_config_attr(pat_type: &syn::PatType) -> bool {
pat_type
.attrs
.iter()
.any(|a| a.path().is_ident("agent_config"))
}
pub struct AgentConfigAttrRemover;
impl VisitMut for AgentConfigAttrRemover {
fn visit_fn_arg_mut(&mut self, i: &mut syn::FnArg) {
if let syn::FnArg::Typed(arg) = i {
arg.attrs.retain(|att| !att.path().is_ident("agent_config"));
}
syn::visit_mut::visit_fn_arg_mut(self, i);
}
}