import{u as H,_ as z,a as G,b as J}from"./p6Qf_Uxj.js";import{_ as T}from"./BjGx28ax.js";import{_ as X}from"./BnoxUuzK.js";import{h as j,B as Q,f as F,E as i,e as Y,u as Z,D as tt,S as et,G as at,k as M,H as st,W as ot,m as nt,v as b,I as V,g as t,o as C,w as B,b as L,c as rt,J as it,K as ut,X as lt,O as x}from"./dgvVcRbD.js";import{u as ct}from"./BtWIKuWo.js";import{u as mt}from"./uuASzBh0.js";import{u as pt}from"./DjCyy1jK.js";import{u as dt}from"./BWdbJVRO.js";import"./Dx5eJfeI.js";import"./k_JGKJJP.js";import"./DlAUqK2U.js";import"./BnobUxhI.js";import"./Dcv3SB2f.js";import"./0Vh5jnau.js";import"./BrAY5X9P.js";import"./DLwfb9rl.js";import"./8lporG8B.js";import"./PjxHOgst.js";import"./PBSS8bwl.js";import"./DjY5_9nl.js";import"./BesS-_33.js";import"./D8ey85JT.js";import"./ClvrI8Td.js";import"./C1qmphIB.js";import"./Dc4I8EvL.js";import"./BngqlKF6.js";import"./BULhecZF.js";import"./6was1jXH.js";import"./DXS-54NY.js";import"./Bsc0CIfh.js";import"./BOr0jPkT.js";import"./D6j-iADt.js";import"./wWRSdjR0.js";import"./C7c-EcZg.js";import"./CNTYtJs2.js";import"./CKMor2ew.js";import"./Cs0iAjED.js";import"./Si7f0Dtd.js";import"./DfwZZ1UW.js";import"./CVKV6eJo.js";import"./BIMr8OGX.js";import"./Dlg-EP8N.js";import"./DBAxjluF.js";import"./DX3tX3Y8.js";import"./CDwYDXMA.js";import"./COpoDM1M.js";import"./asafqq8u.js";import"./DssDgHgj.js";import"./Bw0uuBPj.js";import"./XTzszJDu.js";const pe=j({__name:"[id]",async setup(ft){let u,f;const k=Q(),v=k.params.id;v||([u,f]=F(()=>x("/chat")),await u,f());const o=i([]),n=i(""),r=i(!1),c=i(!1),{t:m}=Y(),{data:N}=([u,f]=F(()=>ct(`/v1/assistants/${v}`)),u=await u,f(),u),a=mt(N);a.value&&Z({title:m("chat.chatWith",{name:a.value.name})});const{$api:vt}=tt(),I=H(),P=pt(),p=et(),U=at(),{showError:A}=dt(),$=M(()=>a.value?.model?.capabilities?a.value.model.capabilities.includes("vision"):!1),R=M(()=>U.config.ui_show_message_share_button!==!1),y=()=>{o.value=[],n.value="",r.value=!1,c.value=!1,I.cleanupOldConversations()},D=i(!1),_=i(null),h=i(!1),S=async()=>p.user?!0:(_.value||(_.value=(async()=>{try{if(await p.fetchUser()&&p.user)return!0}catch(e){console.error("Failed to fetch user state:",e)}return D.value||(A(m("assistants.loginRequired")),D.value=!0),await x({path:"/sign-in",query:{redirect:k.fullPath}}),!1})().finally(()=>{_.value=null})),_.value),E=async()=>{p.user||(h.value=!0,await S())},K=async e=>{await S()||(e.preventDefault(),e.stopPropagation())},O=async e=>{if(!await S()||!n.value.trim()||r.value||!v)return;const g=n.value.trim();n.value="",r.value=!0,c.value=!0;const l={id:Date.now().toString(),content:g,message_type:"USER",created_at:new Date().toISOString(),extra_data:e&&e.length>0?{images:e}:void 0};o.value.push(l);try{const s=await P.createConversation(v);if(!s){o.value=o.value.filter(d=>d.id!==l.id),r.value=!1,c.value=!1;return}a?.value&&I.setConversationData(s.id,l,a.value),y(),await x(`/chat/${s.id}`)}catch(s){console.error("Failed to initiate conversation:",s),o.value=o.value.filter(d=>d.id!==l.id),r.value=!1,c.value=!1,A(`${m("chat.sendFailed")}: ${s instanceof Error?s.message:m("chat.unknownError")}`)}};return st(()=>{y()}),ot(()=>{y()}),nt(()=>p.user,e=>{e&&(h.value=!1)}),(e,g)=>{const l=z,s=T,d=G,W=J,q=X;return t(a)?(C(),b(q,{key:0,assistant:t(a)},{input:B(()=>[L(W,{modelValue:t(n),"onUpdate:modelValue":g[0]||(g[0]=w=>lt(n)?n.value=w:null),disabled:t(h)||t(r),"send-disabled":t(h)||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:B(()=>[L(l,{assistant:t(a),"show-welcome":t(o).length===0},null,8,["assistant","show-welcome"]),(C(!0),rt(it,null,ut(t(o),w=>(C(),b(s,{key:w.id,message:w,assistant:t(a),"enable-share":t(R)},null,8,["message","assistant","enable-share"]))),128)),t(c)?(C(),b(d,{key:0,assistant:t(a),message:t(m)("chat.creatingConversation","Creating new conversation...")},null,8,["assistant","message"])):V("",!0)]),_:1},8,["assistant"])):V("",!0)}}});export{pe as default};
