import{d as M,r,Q as U,u as Y,X as z,G,o as J,U as O,b as v,c as y,v as e,e as C,E as x,y as p,I as g,z as Q,R as X,F as j,J as W,$ as Z,B as P,t as ee,L as te,H as se,N as ae,O as ne,q as oe}from"./registerWidgets.fff064a1.js";import{q as B,r as re,v as le}from"./icons.b8ff2c28.js";import{l as f}from"./WidgetsFrame.7e48c68b.js";const ce=l=>(ae("data-v-a1632005"),l=l(),ne(),l),ie={class:"smart-console"},ue={class:"header"},de=ce(()=>e("div",{class:"left"},"Console",-1)),ve={class:"right"},pe={class:"cli"},he={class:"left"},me={class:"entry ai-output"},ye={class:"local-entry"},fe={key:0,class:"input"},_e=["pointer-events","onKeydown"],ge={class:"right"},Se=M({__name:"SmartConsole",props:{inputEnabled:{type:Boolean},dashPlayerState:null,formCode:null,runtime:null},emits:["clear-terminal","restart","enter"],setup(l,{emit:b}){const o=l,h=r(""),c=r(null),T=te(),D=r(!1),N=()=>{f.clear(),b("restart")};U(T,()=>{f.clear(),b("clear-terminal")});const _=r(null),H=r("assistant"),K=async t=>{var a;if(t.preventDefault(),h.value=((a=_.value)==null?void 0:a.innerText)||"",t.shiftKey){document.execCommand("insertLineBreak");return}_.value&&(_.value.innerText=""),await V()},V=async()=>{h.value&&(i({type:"eval-request",content:`>>> ${h.value}`}),$(h.value),h.value="")},S=Y([]),i=async t=>{S.push(t),await z(),c.value&&(c.value.scrollTop=c.value.scrollHeight)},$=t=>{var a,n,u;(u=(a=o.dashPlayerState)==null?void 0:a.broker)==null||u.send({type:"eval",expression:t,state:(n=o.dashPlayerState)==null?void 0:n.apiPageState})};(()=>{var t,a,n,u,L,R;(t=o.dashPlayerState)==null||t.on("eval-return",s=>{s.repr&&i({type:"log",content:s.repr})}),(a=o.dashPlayerState)==null||a.on("eval-error",s=>{i({type:"error",content:s.repr})}),(n=o.dashPlayerState)==null||n.on("stderr",s=>{i({type:"error",content:s.log})}),(u=o.dashPlayerState)==null||u.on("stdout",s=>{i({type:"log",content:s.log})}),(L=o.dashPlayerState)==null||L.on("widgets-computed",s=>{var m;(m=s.errors)!=null&&m.general&&i({type:"error",content:s.errors.general.repr})}),(R=o.dashPlayerState)==null||R.on("program-start-failed",s=>{var m;i({type:"error",content:(m=s.error)!=null?m:""})})})();const q=()=>{H.value==="assistant"?f.clear():S.splice(0,S.length)};f.listen(async t=>{t.type!=="restart"&&(d.value=!0,await z(),c.value&&(c.value.scrollTop=c.value.scrollHeight))});const d=r(!1),w=r(400),A=G(()=>({height:`${w.value}px`})),k=r(!1),F=()=>k.value=!0,E=t=>{!k.value||(w.value=document.body.clientHeight-t.clientY)},I=()=>k.value=!1;return J(()=>{document.addEventListener("mousemove",E),document.addEventListener("mouseup",I)}),O(()=>{document.removeEventListener("mousemove",E),document.removeEventListener("mouseup",I)}),(t,a)=>(v(),y("div",ie,[e("div",ue,[de,e("div",ve,[e("div",{class:"changes-container"},[e("button",{class:"header-button",onClick:N},"Restart")]),e("div",{class:"toggle-button",onClick:a[0]||(a[0]=n=>d.value=!d.value)},[C(g,{class:x(["icon",{open:d.value}]),path:p(B),fill:"#fff"},null,8,["class","path"])])])]),d.value?(v(),y("div",{key:0,class:"terminal",style:Q(p(A))},[e("div",{class:"resize-handler",onMousedown:F},null,32),e("div",pe,[e("div",he,[e("div",{ref_key:"entriesContainer",ref:c,class:"entries"},[e("div",me,[X(" You can inspect your code here. "),(v(!0),y(j,null,W(p(f).logs,(n,u)=>(v(),y("div",{key:u,class:x([n.type,"entry"])},[e("div",ye,se(n.type==="restart"?"-- restarted --":n.log),1)],2))),128))])],512),l.runtime==="dashes"?(v(),y("div",fe,[C(g,{class:x(["icon",{open:d.value}]),path:p(B)},null,8,["class","path"]),e("div",{ref_key:"inputRef",ref:_,class:"input-text",contenteditable:"","pointer-events":D.value?"none":"auto",placeholder:"Ask AI anything",onKeydown:Z(K,["enter"])},null,40,_e)])):P("",!0)]),e("div",ge,[e("div",{class:"icons",onClick:q},[C(g,{class:"icon",path:p(re)},null,8,["path"])]),e("div",null,[l.runtime==="dashes"?(v(),ee(g,{key:0,class:"icon",path:p(le)},null,8,["path"])):P("",!0)])])])],4)):P("",!0)]))}});const be=oe(Se,[["__scopeId","data-v-a1632005"]]);export{be as S};
//# sourceMappingURL=SmartConsole.03445c4c.js.map
