act_sdk_macros/lib.rs
1mod component;
2mod tool;
3
4use proc_macro::TokenStream;
5
6/// Attribute macro for ACT component modules.
7///
8/// Transforms a module containing `#[act_tool]` functions into a complete
9/// WIT component implementation with `wit_bindgen::generate!()`, `export!()`,
10/// and a `Guest` trait implementation.
11///
12/// # Attributes
13///
14/// - `name = "..."` (required) — Component name
15/// - `version = "..."` (required) — Component version
16/// - `description = "..."` (required) — Component description
17/// - `default_language = "..."` (optional, defaults to "en") — BCP 47 language tag
18///
19/// # Example
20///
21/// ```ignore
22/// #[act_component(
23/// name = "my-component",
24/// version = "0.1.0",
25/// description = "My ACT component",
26/// )]
27/// mod component {
28/// use super::*;
29///
30/// #[act_tool(description = "Say hello")]
31/// fn greet(args: GreetArgs) -> ActResult<String> {
32/// Ok(format!("Hello, {}!", args.name))
33/// }
34/// }
35/// ```
36#[proc_macro_attribute]
37pub fn act_component(attr: TokenStream, item: TokenStream) -> TokenStream {
38 let attrs = match component::ComponentAttrs::parse(attr.into()) {
39 Ok(a) => a,
40 Err(e) => return e.to_compile_error().into(),
41 };
42
43 let module = match syn::parse::<syn::ItemMod>(item) {
44 Ok(m) => m,
45 Err(e) => return e.to_compile_error().into(),
46 };
47
48 match component::generate(attrs, &module) {
49 Ok(tokens) => tokens.into(),
50 Err(e) => e.to_compile_error().into(),
51 }
52}
53
54/// Attribute macro for ACT tool functions.
55///
56/// When used inside an `#[act_component]` module, marks a function as a tool.
57/// The `#[act_component]` macro processes these attributes during code generation.
58///
59/// When used standalone (outside `#[act_component]`), this is a no-op pass-through.
60///
61/// # Attributes
62///
63/// - `description = "..."` (required) — Tool description
64/// - `read_only` — Mark tool as read-only
65/// - `idempotent` — Mark tool as idempotent
66/// - `destructive` — Mark tool as destructive
67/// - `streaming` — Mark tool as streaming (auto-detected if ActContext param present)
68/// - `timeout_ms = N` — Set timeout in milliseconds
69#[proc_macro_attribute]
70pub fn act_tool(_attr: TokenStream, item: TokenStream) -> TokenStream {
71 // When used standalone, pass through unchanged.
72 // When inside #[act_component], the component macro processes this.
73 item
74}