UNPKG

@langgraph-js/sdk

Version:

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

37 lines (36 loc) 1.18 kB
import { AIMessage, HumanMessage } from "@langchain/core/messages"; import { interrupt } from "@langchain/langgraph"; export class InterruptModal { constructor(inputParams) { this.inputParams = inputParams; } get response() { if (!this.rawResponse) throw new Error("rawResponse is undefined"); return JSON.parse(this.rawResponse.response); } interrupt(message) { const inputData = Object.assign({ message }, this.inputParams); const input = JSON.stringify(inputData); const response = interrupt(input); this.rawResponse = { request: inputData, response, }; return this; } isApprove() { return this.response.answer; } isReject() { return !this.response.answer; } toMessages(options) { if (!this.rawResponse) throw new Error("rawResponse is undefined"); return [ (options === null || options === void 0 ? void 0 : options.AIAskMessage) && new AIMessage(this.rawResponse.request.message), new HumanMessage(this.response.answer), ].filter(Boolean); } }