import{u as z,_ as H,a as G,b as J}from"./BlnvEJqx.js";import{_ as T}from"./BiXAZkt9.js";import{_ as X}from"./CkJ8ft5o.js";import{h as j,B as Q,f as Y,E as i,e as Z,m as F,u as tt,D as et,S as at,G as st,k as L,H as ot,W as nt,v as y,I as M,g as t,o as g,w as V,b as B,c as rt,J as it,K as ut,X as lt,O as S}from"./BzhixHsn.js";import{u as ct}from"./G5O1m7ek.js";import{u as mt}from"./4NrzHMof.js";import{u as pt}from"./2JFTuhAN.js";import{u as dt}from"./D01W4VS-.js";import"./BEcuULY5.js";import"./DkVjT0nP.js";import"./DlAUqK2U.js";import"./B9I6JWJy.js";import"./DzpHhHXI.js";import"./RCxqQWZp.js";import"./BYr6U6oc.js";import"./CawQPbYo.js";import"./Dx78NuNM.js";import"./C56gk0qC.js";import"./BmCC6msl.js";import"./EdM3CJ8e.js";import"./D0pu0OPX.js";import"./BdE42Imj.js";import"./C8B8ONuC.js";import"./Le8goM6p.js";import"./C9XbPd6k.js";import"./CHPRih2d.js";import"./DU0NpF9R.js";import"./CzLssp15.js";import"./BSaEE8c4.js";import"./DdeO54y7.js";import"./Bi0Cqvs9.js";import"./Bp3-KBkO.js";import"./DKMWZZOl.js";import"./vJ3Jskde.js";import"./pRipWecN.js";import"./Dosvfmhb.js";import"./CCA1r4XF.js";import"./lcKie01k.js";import"./qyVZgQpg.js";import"./4isL45Eu.js";import"./2RVX2kid.js";import"./C-9Ampo3.js";import"./C-xhCs27.js";import"./Di109XjC.js";import"./CeWx-USI.js";import"./COjiOs1v.js";import"./XCOtPLqC.js";import"./DQj8dpKz.js";import"./BmLyE0U0.js";import"./CMS48I6h.js";const de=j({__name:"[id]",async setup(ft){let b,x;const k=Q(),d=k.params.id;d||([b,x]=Y(()=>S("/chat")),await b,x());const o=i([]),n=i(""),r=i(!1),l=i(!1),{t:c}=Z(),{data:N,pending:vt}=ct(`/v1/assistants/${d}`,{lazy:!0}),a=mt(N);F(a,e=>{e&&tt({title:c("chat.chatWith",{name:e.name})})},{immediate:!0});const{$api:_t}=et(),I=z(),P=pt(),m=at(),U=st(),{showError:A}=dt(),$=L(()=>a.value?.model?.capabilities?a.value.model.capabilities.includes("vision"):!1),R=L(()=>U.config.ui_show_message_share_button!==!1),w=()=>{o.value=[],n.value="",r.value=!1,l.value=!1,I.cleanupOldConversations()},D=i(!1),f=i(null),v=i(!1),C=async()=>m.user?!0:(f.value||(f.value=(async()=>{try{if(await m.fetchUser()&&m.user)return!0}catch(e){console.error("Failed to fetch user state:",e)}return D.value||(A(c("assistants.loginRequired")),D.value=!0),await S({path:"/sign-in",query:{redirect:k.fullPath}}),!1})().finally(()=>{f.value=null})),f.value),E=async()=>{m.user||(v.value=!0,await C())},K=async e=>{await C()||(e.preventDefault(),e.stopPropagation())},O=async e=>{if(!await C()||!n.value.trim()||r.value||!d)return;const _=n.value.trim();n.value="",r.value=!0,l.value=!0;const u={id:Date.now().toString(),content:_,message_type:"USER",created_at:new Date().toISOString(),extra_data:e&&e.length>0?{images:e}:void 0};o.value.push(u);try{const s=await P.createConversation(d);if(!s){o.value=o.value.filter(p=>p.id!==u.id),r.value=!1,l.value=!1;return}a?.value&&I.setConversationData(s.id,u,a.value),w(),await S(`/chat/${s.id}`)}catch(s){console.error("Failed to initiate conversation:",s),o.value=o.value.filter(p=>p.id!==u.id),r.value=!1,l.value=!1,A(`${c("chat.sendFailed")}: ${s instanceof Error?s.message:c("chat.unknownError")}`)}};return ot(()=>{w()}),nt(()=>{w()}),F(()=>m.user,e=>{e&&(v.value=!1)}),(e,_)=>{const u=H,s=T,p=G,W=J,q=X;return t(a)?(g(),y(q,{key:0,assistant:t(a)},{input:V(()=>[B(W,{modelValue:t(n),"onUpdate:modelValue":_[0]||(_[0]=h=>lt(n)?n.value=h:null),disabled:t(v)||t(r),"send-disabled":t(v)||t(r)||!t(n).trim(),"supports-vision":t($),onKeydown:K,onFocus:E,onClick:E,onSend:O},null,8,["modelValue","disabled","send-disabled","supports-vision"])]),default:V(()=>[B(u,{assistant:t(a),"show-welcome":t(o).length===0},null,8,["assistant","show-welcome"]),(g(!0),rt(it,null,ut(t(o),h=>(g(),y(s,{key:h.id,message:h,assistant:t(a),"enable-share":t(R)},null,8,["message","assistant","enable-share"]))),128)),t(l)?(g(),y(p,{key:0,assistant:t(a),message:t(c)("chat.creatingConversation","Creating new conversation...")},null,8,["assistant","message"])):M("",!0)]),_:1},8,["assistant"])):M("",!0)}}});export{de as default};
