UNPKG

@hashbrownai/react

Version:

React components for Hashbrown AI

84 lines (83 loc) 3.45 kB
import { Chat, s } from '@hashbrownai/core'; import { type DependencyList } from 'react'; export interface ToolOptionsWithInput<Name extends string, Schema extends s.HashbrownType, Result> { /** * The name of the tool. */ name: Name; /** * The description of the tool. This helps the LLM understand its purpose. */ description: string; /** * The schema that describes the input for the tool. */ schema: Schema; /** * The handler of the tool. This is what the LLM agent will call * to execute the tool, passing in an input that adheres to the schema. */ handler: (input: s.Infer<Schema>, abortSignal: AbortSignal) => Promise<Result>; /** * Dependencies that should trigger tool recreation. * The hook will automatically memoize the handler based on these dependencies, * so you can safely pass anonymous functions. */ deps: DependencyList; } export interface ToolOptionsWithoutInput<Name extends string, Result> { /** * The name of the tool. */ name: Name; /** * The description of the tool. This helps the LLM understand its purpose. */ description: string; /** * The handler of the tool. This is what the LLM agent will call * to execute the tool. */ handler: (abortSignal: AbortSignal) => Promise<Result>; /** * Dependencies that should trigger tool recreation. * The hook will automatically memoize the handler based on these dependencies, * so you can safely pass anonymous functions. */ deps: DependencyList; } export type ToolOptions<Name extends string, Schema extends s.HashbrownType = s.HashbrownType, Result = unknown> = ToolOptionsWithInput<Name, Schema, Result> | ToolOptionsWithoutInput<Name, Result>; /** * Creates a tool with a schema. * * @param input - The input for the tool. * @param input.name - The name of the tool. * @param input.description - The description of the tool. * @param input.schema - The schema of the tool. * @param input.handler - The handler of the tool. * @param deps - Dependencies that should trigger tool recreation. * The hook will automatically memoize the handler based on these dependencies, * so you can safely pass anonymous functions. * @param Name - The name of the tool. * @param Schema - The schema of the tool. * @param Result - The result of the tool. * @returns The tool. */ export declare function useTool<const Name extends string, Schema extends s.HashbrownType, Result>(input: ToolOptionsWithInput<Name, Schema, Result>): Chat.Tool<Name, s.Infer<Schema>, Result>; /** * Creates a tool. * * @param input - The input for the tool. * @param input.name - The name of the tool. * @param input.description - The description of the tool. * @param input.schema - The schema of the tool. * @param input.handler - The handler of the tool. * @param deps - Dependencies that should trigger tool recreation. * The hook will automatically memoize the handler based on these dependencies, * so you can safely pass anonymous functions. * @param Name - The name of the tool. * @param Schema - The schema of the tool. * @param Result - The result of the tool. * @returns The tool. */ export declare function useTool<const Name extends string, Result>(input: ToolOptionsWithoutInput<Name, Result>): Chat.Tool<Name, void, Result>;