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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//! Auto-registered tool dispatch.
//!
//! Enables the `#[tool]` attribute macro (`open_ai_rust_fn_call_extension`) to register
//! async Rust functions into a process-global slice. The crate consumer can then:
//!
//! - Get every registered tool's JSON-Schema for sending in a chat/Responses request
//! ([`registered_tool_schemas`]).
//! - Dispatch a tool call by name when the model emits one ([`invoke_tool`]).
//!
//! Requires the `tool_registry` cargo feature (which pulls in `linkme`).
//!
//! ## Authoring a tool (sketch)
//!
//! ```ignore
//! use open_ai_rust_fn_call_extension::tool;
//!
//! #[tool("Switch a light on or off")]
//! async fn change_light(turn_on: bool) -> Result<bool, String> {
//! Ok(turn_on)
//! }
//! ```
//!
//! The macro emits a `ToolEntry` and registers it into [`TOOLS`].
//!
//! ## Macro emission contract
//!
//! For the macro side, the expected pattern is:
//!
//! ```ignore
//! #[::linkme::distributed_slice(::open_ai_rust::tool_registry::TOOLS)]
//! #[linkme(crate = ::open_ai_rust::__macro_support::linkme)]
//! static __MY_TOOL: ::open_ai_rust::tool_registry::ToolEntry =
//! ::open_ai_rust::tool_registry::ToolEntry {
//! name: "my_tool",
//! description: Some("..."),
//! schema: || /* FunctionCall */,
//! dispatch: |args| ::std::boxed::Box::pin(async move {
//! /* deserialise args, call user fn, serialise output */
//! }),
//! };
//! ```
//!
//! Re-export `linkme` from the consumer crate as `::open_ai_rust::__macro_support::linkme`
//! so the macro doesn't have to require the user to add `linkme` to their `Cargo.toml`.
use Future;
use Pin;
use Value;
use crateFunctionCall;
/// Pinned-boxed `Future` returned by a dispatch function. Must be `Send` for tokio.
pub type DispatchFuture = ;
/// Function pointer that takes JSON args and asynchronously returns a JSON result.
pub type DispatchFn = fn ;
/// One entry in the global tool registry.
pub static TOOLS: ;
/// Returns every tool registered in this binary.
/// Returns every registered tool's `FunctionCall` schema (ready to pass to `PayLoadBuilder::tools`).
/// Look up a registered tool by name.
/// Dispatch a tool call: looks up `name` in the registry, decodes `args`, awaits the
/// underlying async fn, and returns its JSON output.
///
/// Returns `Err` if no tool with that name is registered or the tool's own dispatch
/// closure returns an error.
pub async
/// Convenience: dispatch every tool call in an assistant response and return paired
/// `(call_id, result)` tuples, suitable for round-tripping into the next request.
pub async