Skip to main content

forge/
auto_register.rs

1//! Automatic function registration via the `inventory` crate.
2
3use forge_runtime::function::FunctionRegistry;
4
5#[cfg(feature = "cron")]
6use forge_runtime::cron::CronRegistry;
7#[cfg(feature = "daemons")]
8use forge_runtime::daemon::DaemonRegistry;
9#[cfg(feature = "jobs")]
10use forge_runtime::jobs::JobRegistry;
11#[cfg(feature = "gateway")]
12use forge_runtime::mcp::McpToolRegistry;
13#[cfg(feature = "gateway")]
14use forge_runtime::webhook::WebhookRegistry;
15#[cfg(feature = "workflows")]
16use forge_runtime::workflow::WorkflowRegistry;
17
18/// All registries bundled into one struct so a single `AutoHandler` closure
19/// can target the right sub-registry without needing a separate inventory type
20/// per handler kind.
21pub struct HandlerRegistries {
22    pub functions: FunctionRegistry,
23    #[cfg(feature = "jobs")]
24    pub jobs: JobRegistry,
25    #[cfg(feature = "cron")]
26    pub crons: CronRegistry,
27    #[cfg(feature = "workflows")]
28    pub workflows: WorkflowRegistry,
29    #[cfg(feature = "daemons")]
30    pub daemons: DaemonRegistry,
31    #[cfg(feature = "gateway")]
32    pub webhooks: WebhookRegistry,
33    #[cfg(feature = "gateway")]
34    pub mcp_tools: McpToolRegistry,
35}
36
37/// A single auto-registration entry emitted by each `#[forge::*]` macro via `inventory::submit!`.
38pub struct AutoHandler(pub fn(&mut HandlerRegistries));
39
40inventory::collect!(AutoHandler);
41
42/// Register all auto-discovered handlers.
43pub fn auto_register_all(registries: &mut HandlerRegistries) {
44    for entry in inventory::iter::<AutoHandler> {
45        (entry.0)(registries);
46    }
47}