/* esm.sh - @assistant-ui/core@0.3.31/dist/runtime/api/composer-runtime */
import{EventSubscriptionSubject as b,LazyMemoizeSubject as a,SKIP_UPDATE as o,ShallowMemoizeSubject as r}from"../../subscribable/subscribable.mjs";import{EditComposerAttachmentRuntimeImpl as u,ThreadComposerAttachmentRuntimeImpl as d}from"./attachment-runtime.mjs";var i=Object.freeze([]),c=Object.freeze({}),l=t=>Object.freeze({type:"thread",isEditing:t?.isEditing??!1,canCancel:t?.canCancel??!1,canSend:t?.canSend??!1,isEmpty:t?.isEmpty??!0,attachments:t?.attachments??i,text:t?.text??"",role:t?.role??"user",runConfig:t?.runConfig??c,attachmentAccept:t?.attachmentAccept??"",dictation:t?.dictation,quote:t?.quote,queue:t?.queue??i,submission:t?.submission,inTransit:t?.inTransit??i,value:t?.text??""}),p=t=>Object.freeze({type:"edit",isEditing:t?.isEditing??!1,canCancel:t?.canCancel??!1,canSend:t?.canSend??!1,isEmpty:t?.isEmpty??!0,text:t?.text??"",role:t?.role??"user",attachments:t?.attachments??i,runConfig:t?.runConfig??c,attachmentAccept:t?.attachmentAccept??"",dictation:t?.dictation,quote:t?.quote,queue:t?.queue??i,submission:t?.submission,inTransit:t?.inTransit??i,parentId:t?.parentId??null,sourceId:t?.sourceId??null,value:t?.text??""}),h=class{get path(){return this._core.path}_core;constructor(t){this._core=t}__internal_bindMethods(){this.setText=this.setText.bind(this),this.setRunConfig=this.setRunConfig.bind(this),this.getState=this.getState.bind(this),this.subscribe=this.subscribe.bind(this),this.addAttachment=this.addAttachment.bind(this),this.reset=this.reset.bind(this),this.clearAttachments=this.clearAttachments.bind(this),this.send=this.send.bind(this),this.cancel=this.cancel.bind(this),this.steerQueueItem=this.steerQueueItem.bind(this),this.moveQueueItem=this.moveQueueItem.bind(this),this.removeQueueItem=this.removeQueueItem.bind(this),this.setRole=this.setRole.bind(this),this.getAttachmentByIndex=this.getAttachmentByIndex.bind(this),this.startDictation=this.startDictation.bind(this),this.stopDictation=this.stopDictation.bind(this),this.setQuote=this.setQuote.bind(this),this.unstable_on=this.unstable_on.bind(this)}setText(t,e){let s=this._core.getState();if(!s)throw new Error("Composer is not available");s.setText(t,e)}setRunConfig(t){let e=this._core.getState();if(!e)throw new Error("Composer is not available");e.setRunConfig(t)}addAttachment(t){let e=this._core.getState();if(!e)throw new Error("Composer is not available");return e.addAttachment(t)}reset(){let t=this._core.getState();if(!t)throw new Error("Composer is not available");return t.reset()}clearAttachments(){let t=this._core.getState();if(!t)throw new Error("Composer is not available");return t.clearAttachments()}send(t){let e=this._core.getState();if(!e)throw new Error("Composer is not available");e.send(t)}cancel(){let t=this._core.getState();if(!t)throw new Error("Composer is not available");t.cancel()}steerQueueItem(t){this.moveQueueItem(t,{lane:"steer",insertAfter:null})}moveQueueItem(t,e){let s=this._core.getState();if(!s)throw new Error("Composer is not available");s.moveQueueItem(t,e)}removeQueueItem(t){let e=this._core.getState();if(!e)throw new Error("Composer is not available");e.removeQueueItem(t)}setRole(t){let e=this._core.getState();if(!e)throw new Error("Composer is not available");e.setRole(t)}startDictation(){let t=this._core.getState();if(!t)throw new Error("Composer is not available");t.startDictation()}stopDictation(){let t=this._core.getState();if(!t)throw new Error("Composer is not available");t.stopDictation()}setQuote(t){let e=this._core.getState();if(!e)throw new Error("Composer is not available");e.setQuote(t)}subscribe(t){return this._core.subscribe(t)}_eventSubscriptionSubjects=new Map;unstable_on(t,e){let s=this._eventSubscriptionSubjects.get(t);return s||(s=new b({event:t,binding:this._core}),this._eventSubscriptionSubjects.set(t,s)),s.subscribe(e)}},S=class extends h{get path(){return this._core.path}get type(){return"thread"}_getState;constructor(t){let e=new a({path:t.path,getState:()=>l(t.getState()),subscribe:s=>t.subscribe(s)});super({path:t.path,getState:()=>t.getState(),subscribe:s=>e.subscribe(s)}),this._getState=e.getState.bind(e),this.__internal_bindMethods()}getState(){return this._getState()}getAttachmentByIndex(t){return new d(new r({path:{...this.path,attachmentSource:"thread-composer",attachmentSelector:{type:"index",index:t},ref:`${this.path.ref}.attachments[${t}]`},getState:()=>{let e=this.getState().attachments[t];return e?{...e,source:"thread-composer"}:o},subscribe:e=>this._core.subscribe(e)}),this._core)}},_=class extends h{get path(){return this._core.path}get type(){return"edit"}_getState;_beginEdit;constructor(t,e){let s=new a({path:t.path,getState:()=>p(t.getState()),subscribe:n=>t.subscribe(n)});super({path:t.path,getState:()=>t.getState(),subscribe:n=>s.subscribe(n)}),this._beginEdit=e,this._getState=s.getState.bind(s),this.__internal_bindMethods()}__internal_bindMethods(){super.__internal_bindMethods(),this.beginEdit=this.beginEdit.bind(this)}getState(){return this._getState()}beginEdit(){this._beginEdit()}getAttachmentByIndex(t){return new u(new r({path:{...this.path,attachmentSource:"edit-composer",attachmentSelector:{type:"index",index:t},ref:`${this.path.ref}.attachments[${t}]`},getState:()=>{let e=this.getState().attachments[t];return e?{...e,source:"edit-composer"}:o},subscribe:e=>this._core.subscribe(e)}),this._core)}};export{h as ComposerRuntimeImpl,_ as EditComposerRuntimeImpl,S as ThreadComposerRuntimeImpl};
//# sourceMappingURL=composer-runtime.mjs.map