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