pub struct ToolRegistry { /* private fields */ }Expand description
Registry of available tools. Maintains a name→tool map and a cached JSON schema
array that gets sent to the API. Thread-safe via Arc<RwLock<ToolRegistry>>.
Implementations§
Source§impl ToolRegistry
impl ToolRegistry
pub fn new() -> Self
Sourcepub fn empty() -> Self
pub fn empty() -> Self
Empty registry for tests and narrow embedded runtimes that want to opt in to specific tools explicitly.
Sourcepub fn disable(&mut self, names: &[String])
pub fn disable(&mut self, names: &[String])
Remove built-in tools by runtime name (config disabled_tools).
Compatibility wrapper over Self::try_disable; the only failure
mode is catalog generation exhaustion, on which this fails closed by
panicking with the registry left fully unchanged.
Sourcepub fn try_disable(&mut self, names: &[String]) -> Result<(), CatalogError>
pub fn try_disable(&mut self, names: &[String]) -> Result<(), CatalogError>
Fallible disable: remove built-in tools by runtime name, then rebuild the cached schema, name maps, and capability catalog. Unknown names are ignored; a call that removes nothing is a no-op and does not advance the catalog generation. A call that removes tools advances the catalog generation strictly past its prior value, so grants issued against removed capabilities cannot stay valid.
The rebuilt candidate is fully constructed and generation-rebased
BEFORE it is committed to self: on any failure the live registry
(tools, schema, catalog entries, generation) is left untouched, so a
generation-exhausted disable can never leave a generation-rewound,
partially changed registry behind a non-poisoning lock.
Sourcepub fn without_subagent() -> Self
pub fn without_subagent() -> Self
Registry without subagent tool — used for subagent runtimes to prevent recursion.
Sourcepub fn without_subagent_with_extensions(extension_tools: &ToolRegistry) -> Self
pub fn without_subagent_with_extensions(extension_tools: &ToolRegistry) -> Self
Built-in subagent registry plus extension tools merged in from a shared
registry. Used by subagents that need to invoke extension-provided
tools while still excluding the recursive subagent_* tools.
Only tools whose Tool::extension_id() returns Some(_) are merged;
built-ins inside extension_tools are ignored to avoid duplicating or
shadowing the canonical built-in instances.
Sourcepub fn register(&mut self, tool: Arc<dyn Tool>)
pub fn register(&mut self, tool: Arc<dyn Tool>)
Register an additional tool at runtime (e.g. MCP tools, custom tools). If a tool with the same name exists, it is replaced.
Compatibility wrapper over Self::try_register. The only failure
mode is catalog generation exhaustion (a u64 mutation counter),
which is unreachable in practice; if it ever occurs this wrapper
fails closed by panicking rather than exposing a tool the catalog
could not record. Callers that can surface errors should prefer
Self::try_register.
Sourcepub fn try_register(&mut self, tool: Arc<dyn Tool>) -> Result<(), CatalogError>
pub fn try_register(&mut self, tool: Arc<dyn Tool>) -> Result<(), CatalogError>
Fallible registration: catalog the tool first (fail-closed — on error nothing is mutated and no schema is exposed), then insert it into the live map and rebuild the exposed schema. Replacing a tool whose capability identity changes drops the stale catalog entry in the same generation advance.
Sourcepub fn try_register_batch(
&mut self,
tool_list: Vec<Arc<dyn Tool>>,
) -> Result<usize, CatalogError>
pub fn try_register_batch( &mut self, tool_list: Vec<Arc<dyn Tool>>, ) -> Result<usize, CatalogError>
Atomically register a whole batch (Task 19 boot-time dormant MCP
entries). STRICTLY ADDITIVE: before any mutation, every member’s
runtime name AND capability identity is preflighted against both the
live registry and the rest of the batch — an existing tool can never
be replaced through a batch, and two members whose distinct
identities collapse onto one runtime name (e.g. ext__ separator
collisions) are rejected typed. Only after preflight is the FULL
candidate registry built (per-tool catalog mutations plus a single
schema rebuild) and committed on complete success. Any failure
rejects the ENTIRE batch and leaves the live registry — tools,
schema, catalog entries, and generation — byte-identically
unchanged; no partial batch can ever be observed. Never invokes any
tool, factory, extension handler, or MCP connection.
Sourcepub fn catalog(&self) -> &ToolCatalog
pub fn catalog(&self) -> &ToolCatalog
Read-only view of the capability catalog. Reading never mutates
registry state; the exposed tools_schema() stays byte-identical.
pub fn get(&self, name: &str) -> Option<&Arc<dyn Tool>>
pub fn runtime_name_for_api<'a>(&'a self, name: &'a str) -> &'a str
Sourcepub fn resolve_wire_call(&self, wire_name: &str) -> Option<ResolvedToolCall>
pub fn resolve_wire_call(&self, wire_name: &str) -> Option<ResolvedToolCall>
Atomic wire-name resolution for the execution gate (Task 16): map
the incoming API/wire name through the deterministic sanitized-name
reverse mapping to the exact live runtime tool, then derive its
catalog crate::tools::catalog::ToolId from the resolved tool
instance itself — never from the alias string. Because this runs on
one &self borrow (i.e. under the caller’s registry read lock), the
resolution, the catalog reachable via Self::catalog, and any
subsequent implementation acquisition observe one consistent
registry snapshot.
pub fn translate_input_for_api_tool( &self, tool_name: &str, input: Value, ) -> Value
pub fn tools_schema(&self) -> Arc<Vec<Value>> ⓘ
Sourcepub fn session_tools_schema(
&self,
session: &SessionToolSet,
) -> SessionSchemaProjection
pub fn session_tools_schema( &self, session: &SessionToolSet, ) -> SessionSchemaProjection
Deterministic session schema projection (Task 17, spec §7.7): select
from the EXISTING cached exposed schema exactly the entries whose
capability identity is core or exactly-activated in session,
preserving cached byte ordering, API-safe names, and collision
suffixes. Pure read: no catalog insertion, no schema rebuild, no
factory invocation, no process/network. Default runtime exposure
(tools_schema) is unaffected until Task 18 opts in.
Drift handling (per-tool digest + provenance validation fix): catalog
generation drift does NOT fail the whole projection — an unrelated
background mutation must not blank a session’s entire tool schema.
Instead the projection is validated per tool: entries whose CURRENT
catalog record digest AND trust provenance match the session’s pins
are included; entries whose record drifted (changed digest, changed
provenance — even an internally coherent one) or vanished
(uncataloged) are dropped fail-closed and REPORTED in the returned
SessionSchemaProjection::dropped list — they would be denied by
the execution gate anyway, so advertising them would be dishonest.
Sourcepub fn tool_names_for_extension(&self, extension_id: &str) -> Vec<String>
pub fn tool_names_for_extension(&self, extension_id: &str) -> Vec<String>
Return runtime names of tools owned by the given extension id, sorted ascending.
Built-in tools (which return None from Tool::extension_id) are excluded.
Sourcepub fn iter_tools_sorted(&self) -> Vec<&Arc<dyn Tool>>
pub fn iter_tools_sorted(&self) -> Vec<&Arc<dyn Tool>>
Iterate all registered tools, sorted by name for deterministic output.
Used by synaps tools export to build the static schema manifest.
Trait Implementations§
Source§impl Clone for ToolRegistry
impl Clone for ToolRegistry
Source§fn clone(&self) -> ToolRegistry
fn clone(&self) -> ToolRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for ToolRegistry
impl !UnwindSafe for ToolRegistry
impl Freeze for ToolRegistry
impl Send for ToolRegistry
impl Sync for ToolRegistry
impl Unpin for ToolRegistry
impl UnsafeUnpin for ToolRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.