import{s as G,e as _,a as F,c as v,d as y,f as b,b as A,h as m,i as R,j as h,q as L,l as T,n as I,u as H,r as Q,t as O,g as P,k as N,m as K}from"../chunks/scheduler.AtZRZ-7N.js";import{e as U}from"../chunks/each.qkpXUKO-.js";import{S as W,i as Y}from"../chunks/index.kgFpNQDS.js";function J(d,e,u){const s=d.slice();return s[9]=e[u],s}function M(d){let e,u,s,c="Вы:",l,o,E,C=d[9][0]+"",k,w,p,a="Бот:",n,r,t,f=d[9][1]+"",i,D;return{c(){e=_("div"),u=_("div"),s=_("p"),s.textContent=c,l=F(),o=_("div"),E=_("p"),k=O(C),w=F(),p=_("p"),p.textContent=a,n=F(),r=_("div"),t=_("pre"),i=O(f),D=F(),this.h()},l(g){e=v(g,"DIV",{class:!0});var x=y(e);u=v(x,"DIV",{class:!0});var B=y(u);s=v(B,"P",{class:!0,"data-svelte-h":!0}),P(s)!=="svelte-rp9yxd"&&(s.textContent=c),l=A(B),o=v(B,"DIV",{class:!0});var V=y(o);E=v(V,"P",{class:!0});var q=y(E);k=N(q,C),q.forEach(b),V.forEach(b),w=A(B),p=v(B,"P",{class:!0,"data-svelte-h":!0}),P(p)!=="svelte-1l7fbwv"&&(p.textContent=a),n=A(B),r=v(B,"DIV",{class:!0});var S=y(r);t=v(S,"PRE",{class:!0});var j=y(t);i=N(j,f),j.forEach(b),S.forEach(b),B.forEach(b),D=A(x),x.forEach(b),this.h()},h(){m(s,"class","font-bold text-sm"),m(E,"class","text-sm"),m(o,"class","self-start bg-blue-500 text-white p-2 rounded-lg"),m(p,"class","font-bold text-sm"),m(t,"class","text-sm svelte-jkjeqd"),m(r,"class","self-start bg-slate-100 text-black p-2 rounded-lg"),m(u,"class","mb-2 flex flex-col"),m(e,"class","mb-2 flex flex-col")},m(g,x){R(g,e,x),h(e,u),h(u,s),h(u,l),h(u,o),h(o,E),h(E,k),h(u,w),h(u,p),h(u,n),h(u,r),h(r,t),h(t,i),h(e,D)},p(g,x){x&1&&C!==(C=g[9][0]+"")&&K(k,C),x&1&&f!==(f=g[9][1]+"")&&K(i,f)},d(g){g&&b(e)}}}function X(d){let e,u="Остановить",s,c;return{c(){e=_("button"),e.textContent=u,this.h()},l(l){e=v(l,"BUTTON",{class:!0,"data-svelte-h":!0}),P(e)!=="svelte-2l6urr"&&(e.textContent=u),this.h()},h(){m(e,"class","ml-2 px-4 py-2 bg-cyan-800 text-white rounded-md")},m(l,o){R(l,e,o),s||(c=T(e,"click",d[5]),s=!0)},p:I,d(l){l&&b(e),s=!1,c()}}}function z(d){let e,u="Отправить",s,c;return{c(){e=_("button"),e.textContent=u,this.h()},l(l){e=v(l,"BUTTON",{class:!0,"data-svelte-h":!0}),P(e)!=="svelte-121gmt7"&&(e.textContent=u),this.h()},h(){m(e,"class","ml-2 px-4 py-2 bg-blue-500 text-white rounded-md")},m(l,o){R(l,e,o),s||(c=T(e,"click",d[3]),s=!0)},p:I,d(l){l&&b(e),s=!1,c()}}}function Z(d){let e,u,s,c,l,o,E,C,k,w,p=U(d[0].slice(1)),a=[];for(let t=0;t{u(2,l=!0);const a=await fetch("/llm/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({history:s}),signal:o.signal});try{if(o.signal.aborted){console.log("Request was cancelled.");return}if(!a.body){console.log("Response has no body");return}const n=a.body.pipeThrough(new TextDecoderStream).getReader();let r=!0;for(;r;)try{if(o.signal.aborted){console.log("Request was cancelled during reading.");break}const{value:t,done:f}=await n.read();if(f){r=!1;break}t&&u(0,s[s.length-1][1]+=t,s)}catch(t){if(t.name==="AbortError"){r=!1,console.log("Fetch was aborted during reading.");break}else{r=!1,console.error("Error during reading:",t);break}}u(2,l=!1)}catch(n){n.name==="AbortError"?console.log("Fetch was aborted."):console.error("Error during fetch:",n)}},w=()=>{o.abort("user canceled"),o=new AbortController};function p(){c=this.value,u(1,c)}return[s,c,l,E,C,w,p]}class le extends W{constructor(e){super(),Y(this,e,$,Z,G,{})}}export{le as component};