@utcp/sdk
Version:
Universal Tool Calling Protocol (UTCP) client library for TypeScript
77 lines (76 loc) • 3.46 kB
TypeScript
import { ProviderUnion } from '../shared/provider';
import { Tool } from '../shared/tool';
import { ToolRepository } from './tool-repository';
import { ToolSearchStrategy } from './tool-search-strategy';
import { UtcpClientConfig } from './utcp-client-config';
/**
* Interface for a UTCP client.
*/
export interface UtcpClientInterface {
/**
* Registers a tool provider and its tools.
*
* @param manual_provider The provider to register.
* @returns A promise that resolves to a list of tools associated with the provider.
*/
register_tool_provider(manual_provider: ProviderUnion): Promise<Tool[]>;
/**
* Deregisters a tool provider.
*
* @param provider_name The name of the provider to deregister.
* @returns A promise that resolves when the provider is deregistered.
*/
deregister_tool_provider(provider_name: string): Promise<void>;
/**
* Calls a tool with the given arguments.
*
* @param tool_name The name of the tool to call (e.g., 'providerName.toolName').
* @param args The arguments to pass to the tool.
* @returns A promise that resolves to the result of the tool call.
*/
call_tool(tool_name: string, args: Record<string, unknown>): Promise<unknown>;
/**
* Searches for tools relevant to the query.
*
* @param query The search query.
* @param limit The maximum number of tools to return. 0 for no limit.
* @returns A promise that resolves to a list of tools that match the search query.
*/
search_tools(query: string, limit?: number): Promise<Tool[]>;
}
/**
* The main client for interacting with the Universal Tool Calling Protocol (UTCP).
*/
export declare class UtcpClient implements UtcpClientInterface {
readonly config: UtcpClientConfig;
readonly toolRepository: ToolRepository;
readonly searchStrategy: ToolSearchStrategy;
private transports;
private constructor();
/**
* Creates and initializes a new instance of the UtcpClient.
*
* @param config The configuration for the client. Can be a partial config object or a complete UtcpClientConfig.
* @param toolRepository The tool repository to use. Defaults to InMemToolRepository.
* @param searchStrategy The tool search strategy to use. Defaults to TagSearchStrategy.
* @returns A promise that resolves to a new, initialized instance of UtcpClient.
*/
static create(config?: Partial<UtcpClientConfig> | UtcpClientConfig, toolRepository?: ToolRepository, searchStrategy?: ToolSearchStrategy): Promise<UtcpClient>;
register_tool_provider(manual_provider: ProviderUnion): Promise<Tool[]>;
deregister_tool_provider(provider_name: string): Promise<void>;
call_tool(tool_name: string, args: Record<string, unknown>): Promise<unknown>;
search_tools(query: string, limit?: number): Promise<Tool[]>;
/**
* Load providers from the file specified in the configuration.
*
* @returns A promise that resolves to a list of registered Provider objects.
* @throws FileNotFoundError if the providers file doesn't exist.
* @throws Error if the providers file contains invalid JSON.
* @throws UtcpVariableNotFoundError if a variable referenced in the provider configuration is not found.
*/
private loadProvidersFromFile;
private loadVariables;
private substituteProviderVariables;
private getVariable;
private replaceVarsInObj;
}