@langgraph-js/sdk
Version:
The UI SDK for LangGraph - seamlessly integrate your AI agents with frontend interfaces
79 lines (78 loc) • 2.61 kB
TypeScript
import { ToolMessage } from "@langchain/langgraph-sdk";
import { LangGraphClient } from "./LangGraphClient.js";
import { CallToolResult, UnionTool } from "./tool/createTool.js";
/**
* @zh ToolManager 类用于管理和执行工具。
* @en The ToolManager class is used to manage and execute tools.
*/
export declare class ToolManager {
private tools;
private waitingMap;
/**
* @zh 注册一个工具。
* @en Registers a tool.
*/
bindTool(tool: UnionTool<any>): void;
/**
* @zh 注册多个工具。
* @en Registers multiple tools.
*/
bindTools(tools: UnionTool<any>[]): void;
/**
* @zh 获取所有已注册的工具。
* @en Gets all registered tools.
*/
getAllTools(): UnionTool<any>[];
/**
* @zh 获取指定名称的工具。
* @en Gets the tool with the specified name.
*/
getTool(name: string): UnionTool<any> | undefined;
/**
* @zh 移除指定名称的工具。
* @en Removes the tool with the specified name.
*/
removeTool(name: string): boolean;
/**
* @zh 清空所有工具。
* @en Clears all tools.
*/
clearTools(): void;
reset(): void;
clearWaiting(): void;
/**
* @zh 调用指定名称的工具。
* @en Calls the tool with the specified name.
*/
callTool(name: string, args: any, context: {
client: LangGraphClient;
message: ToolMessage;
}): Promise<CallToolResult | undefined>;
/**
* @zh 将所有工具转换为 JSON 定义格式。
* @en Converts all tools to JSON definition format.
*/
toJSON(graphId: string, remote?: boolean): Promise<{
name: string;
description: string;
parameters: any;
}[]>;
/**
* @zh 标记指定 ID 的工具等待已完成,并传递结果。
* @en Marks the tool waiting with the specified ID as completed and passes the result.
*/
doneWaiting(id: string, value: CallToolResult): boolean;
/**
* @zh 等待指定 ID 的工具完成。
* @en Waits for the tool with the specified ID to complete.
*/
waitForDone(id: string): Promise<unknown> | ((value: CallToolResult) => void) | undefined;
/**
* @zh 一个静态方法,用于在前端等待用户界面操作完成。
* @en A static method used in the frontend to wait for user interface operations to complete.
*/
static waitForUIDone<T>(_: T, context: {
client: LangGraphClient;
message: ToolMessage;
}): Promise<unknown> | ((value: CallToolResult) => void) | undefined;
}