UNPKG

@langgraph-js/sdk

Version:

The UI SDK for LangGraph - seamlessly integrate your AI agents with frontend interfaces

53 lines (52 loc) 1.4 kB
import { getMessageContent } from "../ui-store/createChatStore.js"; import { jsonrepair } from "jsonrepair"; export class ToolRenderData { constructor(message, client) { this.message = message; this.client = client; } get state() { var _a, _b; if (this.message.type === "tool" && ((_b = (_a = this.message) === null || _a === void 0 ? void 0 : _a.additional_kwargs) === null || _b === void 0 ? void 0 : _b.done)) { return "done"; } if (this.message.tool_input) { return "loading"; } return "idle"; } get input() { try { return JSON.parse(this.message.tool_input); } catch (e) { return null; } } get output() { return getMessageContent(this.message.content); } getJSONOutput() { return JSON.parse(this.output); } /** 如果解析失败,则返回 null */ getJSONOutputSafe() { try { return JSON.parse(this.output); } catch (e) { return null; } } getInputRepaired() { try { return JSON.parse(jsonrepair(this.message.tool_input || "")); } catch (e) { return {}; } } response(data) { this.client.doneFEToolWaiting(this.message.id, JSON.stringify(data)); } }