Skip to main content

monoloop_loop/
registry.rs

1//! Abstract tool registry + empty implementation.
2
3use monoloop_contracts::{ToolActionId, ToolUnavailableReason};
4use std::future::Future;
5use std::pin::Pin;
6
7/// Request to resolve a complete tool by name.
8#[derive(Clone, Debug)]
9pub struct ResolveToolRequest {
10    /// Tool action id.
11    pub tool_action_id: ToolActionId,
12    /// Complete tool name.
13    pub tool_name: String,
14    /// Complete request payload JSON.
15    pub request_payload: String,
16}
17
18/// Opaque available tool reference (no concrete tool types).
19#[derive(Clone, Debug)]
20pub struct ToolDescriptorRef {
21    /// Stable descriptor name.
22    pub name: String,
23}
24
25/// Registry resolution result.
26#[derive(Clone, Debug)]
27pub enum ToolResolution {
28    /// Tool is available (future runtime).
29    Available(ToolDescriptorRef),
30    /// Tool unavailable.
31    Unavailable(ToolUnavailableReason),
32}
33
34/// Registry error.
35#[derive(Clone, Debug, thiserror::Error)]
36#[error("tool registry: {0}")]
37pub struct ToolRegistryError(pub String);
38
39type BoxFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Send + 'a>>;
40
41/// Abstract tool registry.
42pub trait ToolRegistry: Send + Sync {
43    /// Resolve a complete tool request.
44    fn resolve<'a>(
45        &'a self,
46        request: ResolveToolRequest,
47    ) -> BoxFuture<'a, Result<ToolResolution, ToolRegistryError>>;
48}
49
50/// Required first implementation: every request is unavailable.
51#[derive(Clone, Debug, Default)]
52pub struct EmptyToolRegistry;
53
54impl EmptyToolRegistry {
55    /// Create empty registry.
56    pub fn new() -> Self {
57        Self
58    }
59}
60
61impl ToolRegistry for EmptyToolRegistry {
62    fn resolve<'a>(
63        &'a self,
64        _request: ResolveToolRequest,
65    ) -> BoxFuture<'a, Result<ToolResolution, ToolRegistryError>> {
66        Box::pin(async {
67            Ok(ToolResolution::Unavailable(
68                ToolUnavailableReason::NoRegisteredTool,
69            ))
70        })
71    }
72}