pub struct ToolRegistry { /* private fields */ }Expand description
Tool registry for managing and executing tools.
Tools can be registered from JavaScript and then executed by name.
const registry = new ToolRegistry();
// Register a tool with a callback
registry.registerCallback('echo', 'Echoes input', schema, async (params) => {
return { success: true, content: params.message, error: null };
});
// Execute the tool
const result = await registry.execute('echo', { message: 'hello' });Implementations§
Source§impl ToolRegistry
impl ToolRegistry
Source§impl ToolRegistry
impl ToolRegistry
pub fn into_reference( val: ToolRegistry, env: Env, ) -> Result<Reference<ToolRegistry>>
pub fn into_instance(self, env: Env) -> Result<ClassInstance<ToolRegistry>>
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub fn register_callback(
&self,
name: String,
description: String,
input_schema: Value,
execute_fn: JsFunction,
) -> Result<()>
pub fn register_callback( &self, name: String, description: String, input_schema: Value, execute_fn: JsFunction, ) -> Result<()>
Register a tool with a JavaScript callback.
§Arguments
name- Unique tool namedescription- Human-readable descriptioninput_schema- JSON schema for parametersexecute_fn- Async function that takes params and returnsJsToolResult
Sourcepub async fn register_definition(
&self,
name: String,
description: String,
input_schema: Value,
) -> Result<()>
pub async fn register_definition( &self, name: String, description: String, input_schema: Value, ) -> Result<()>
Register a tool definition without a callback.
Useful for documenting tools that will be executed externally.
Sourcepub async fn unregister(&self, name: String) -> Result<bool>
pub async fn unregister(&self, name: String) -> Result<bool>
Unregister a tool by name.
Sourcepub async fn get(&self, name: String) -> Option<JsToolDefinition>
pub async fn get(&self, name: String) -> Option<JsToolDefinition>
Get a tool definition by name.
Sourcepub async fn get_all(&self) -> Vec<JsToolDefinition>
pub async fn get_all(&self) -> Vec<JsToolDefinition>
Get all tool definitions.
Trait Implementations§
Source§impl Default for ToolRegistry
impl Default for ToolRegistry
Source§impl FromNapiMutRef for ToolRegistry
impl FromNapiMutRef for ToolRegistry
Source§unsafe fn from_napi_mut_ref(
env: napi_env,
napi_val: napi_value,
) -> Result<&'static mut Self>
unsafe fn from_napi_mut_ref( env: napi_env, napi_val: napi_value, ) -> Result<&'static mut Self>
Safety Read more
Source§impl FromNapiRef for ToolRegistry
impl FromNapiRef for ToolRegistry
Source§unsafe fn from_napi_ref(
env: napi_env,
napi_val: napi_value,
) -> Result<&'static Self>
unsafe fn from_napi_ref( env: napi_env, napi_val: napi_value, ) -> Result<&'static Self>
Safety Read more
Source§impl FromNapiValue for &ToolRegistry
impl FromNapiValue for &ToolRegistry
Source§unsafe fn from_napi_value(env: napi_env, napi_val: napi_value) -> Result<Self>
unsafe fn from_napi_value(env: napi_env, napi_val: napi_value) -> Result<Self>
Safety Read more
fn from_unknown(value: JsUnknown) -> Result<Self, Error>
Source§impl FromNapiValue for &mut ToolRegistry
impl FromNapiValue for &mut ToolRegistry
Source§unsafe fn from_napi_value(env: napi_env, napi_val: napi_value) -> Result<Self>
unsafe fn from_napi_value(env: napi_env, napi_val: napi_value) -> Result<Self>
Safety Read more
fn from_unknown(value: JsUnknown) -> Result<Self, Error>
Source§impl ToNapiValue for ToolRegistry
impl ToNapiValue for ToolRegistry
Source§unsafe fn to_napi_value(env: napi_env, val: ToolRegistry) -> Result<napi_value>
unsafe fn to_napi_value(env: napi_env, val: ToolRegistry) -> Result<napi_value>
Safety Read more
Source§impl TypeName for &ToolRegistry
impl TypeName for &ToolRegistry
Source§impl TypeName for &mut ToolRegistry
impl TypeName for &mut ToolRegistry
Source§impl TypeName for ToolRegistry
impl TypeName for ToolRegistry
Source§impl ValidateNapiValue for &ToolRegistry
impl ValidateNapiValue for &ToolRegistry
Source§unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
Safety Read more
Source§impl ValidateNapiValue for &mut ToolRegistry
impl ValidateNapiValue for &mut ToolRegistry
Source§unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
unsafe fn validate(env: napi_env, napi_val: napi_value) -> Result<napi_value>
Safety Read more
Auto Trait Implementations§
impl Freeze for ToolRegistry
impl !RefUnwindSafe for ToolRegistry
impl Send for ToolRegistry
impl Sync for ToolRegistry
impl Unpin for ToolRegistry
impl !UnwindSafe 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
Mutably borrows from an owned value. Read more