1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Derive macros for the laminate data shaping library.
//!
//! Provides `#[derive(Laminate)]` for progressive deserialization and
//! `#[derive(ToolDefinition)]` for JSON schema generation from Rust structs.
use TokenStream;
use ;
/// Derive macro for progressive data shaping.
///
/// Generates deserialization logic that operates on an intermediate
/// `HashMap<String, serde_json::Value>`, enabling coercion, overflow capture,
/// and mode-dependent behavior.
///
/// # Attributes
///
/// - `#[laminate(overflow)]` — Captures unrecognized fields. Field must be `HashMap<String, serde_json::Value>`.
/// - `#[laminate(rename = "x")]` — Deserialize from a different JSON key.
/// - `#[laminate(default)]` — Use `Default::default()` if missing or null.
/// - `#[laminate(coerce)]` — Apply type coercion rules from the coercion table.
///
/// # Example
///
/// ```ignore
/// use laminate::Laminate;
///
/// #[derive(Debug, Laminate)]
/// pub struct Config {
/// #[laminate(coerce)]
/// pub port: u16,
///
/// #[laminate(default)]
/// pub debug: bool,
///
/// #[laminate(overflow)]
/// pub extra: HashMap<String, serde_json::Value>,
/// }
/// ```
/// Derive macro for generating LLM tool definition JSON schemas.
///
/// Generates a `tool_definition()` method that returns a `serde_json::Value`
/// matching the tool definition format expected by Anthropic, OpenAI, and
/// other LLM APIs.
///
/// # Attributes
///
/// - `#[tool(name = "x")]` — Override the tool name (defaults to snake_case struct name)
/// - `#[tool(description = "x")]` — Tool description sent to the LLM
/// - `#[tool(rename = "x")]` — Use a different parameter name in the schema
///
/// # Example
///
/// ```ignore
/// use laminate::ToolDefinition;
///
/// /// Get current weather for a city
/// #[derive(ToolDefinition)]
/// struct GetWeather {
/// /// The city to look up
/// city: String,
/// /// Temperature units (celsius or fahrenheit)
/// units: Option<String>,
/// }
///
/// let schema = GetWeather::tool_definition();
/// // Returns: {"name": "get_weather", "description": "Get current weather for a city",
/// // "input_schema": {"type": "object", "properties": {"city": {"type": "string",
/// // "description": "The city to look up"}, ...}, "required": ["city"]}}
/// ```