import BaseDirective from "./BaseDirective" import PandaSparkWebSocket from '../core/sockets/PandaSparkWebSocket' class SparkDirective extends BaseDirective { constructor(options) { super(options) this.pandaSparkWebSocket = new PandaSparkWebSocket({ config : this.params.sparkModelConfig }) this.pandaSparkWebSocket.start() } match () { const { text } = this; return true } async excute({ sendMsg = function () {} }) { return new Promise(async (resolve, reject) => { this.reject = reject this.resolve = resolve this.sendMsg = sendMsg const data = await this.pandaSparkWebSocket.sendMessag({ content : this.text, isLinkContext : false, frame ({resultTextTemp, resultText}) { sendMsg?.(resultTextTemp) } }) resolve(data.resultText) }) } closeResponse() { if(this.pandaSparkWebSocket) { this.pandaSparkWebSocket.stop() } this.sendMsg = null this.reject("") } destroy(){ if(this.pandaSparkWebSocket) { this.pandaSparkWebSocket.destroy() this.pandaSparkWebSocket = null } } } export default SparkDirective