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