1 2!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="94f0c655-4c54-5367-ad13-1cae4f6e5c17")}catch(e){}}(); 3import{j as e}from"./radix-Dv40WeBR.js";import{f as ge,r as a}from"./react-vendor-DMCBMKwH.js";import{N as ve,aH as je,av as be,B as b,an as de,U as Ne,E as B,as as ye,a7 as we,n as W,ap as Y,D as ue,bD as Ce,bE as ke,b1 as Ve,bF as Se,ce as _e,bG as Me,J as Re}from"./index-DY-XyNlk.js";import{C as Ee,a as Pe,b as Ae}from"./collapsible-NmiaFx3d.js";import{d as $e,f as Te}from"./RAGSourcesFooter.utils-B4c71tHY.js";import{u as L}from"./i18n-CRxfqRtU.js";import{M as De}from"./markdown-content-BYHQ03AF.js";import{c as Be}from"./charts-BTglqBUZ.js";import{P as ee}from"./plus-CC_0Lk5l.js";import{A as ie}from"./alert-circle-gCOO3Nso.js";import"./charts-D11ksbhN.js";import"./markdown-CI60NghZ.js";import"./index-BPfoA-Gk.js";/** 4 * @license lucide-react v0.303.0 - ISC 5 * 6 * This source code is licensed under the ISC license. 7 * See the LICENSE file in the root directory of this source tree. 8 */const Fe=ve("SendHorizontal",[["path",{d:"m3 3 3 9-3 9 19-9Z",key:"1aobqy"}],["path",{d:"M6 12h16",key:"s4cdu5"}]]);function Ie({sources:t}){const{t:n}=L(),{isAdmin:i}=je(),h=$e(t);if(h.length===0)return null;const o=h.map(Te).filter(Boolean);return o.length===0?null:e.jsxs("div",{className:"mt-3 space-y-2",children:[e.jsxs("p",{className:"text-xs text-muted-foreground italic flex items-start gap-1.5 leading-relaxed",children:[e.jsx(be,{className:"h-3.5 w-3.5 mt-0.5 shrink-0 text-purple-600/70"}),e.jsxs("span",{children:[e.jsxs("span",{className:"font-medium not-italic text-foreground/70",children:[n("chartDetail.rag.basedOn",{defaultValue:"Baseado em"}),":"]})," ",o.join("; ")]})]}),i&&e.jsxs(Ee,{children:[e.jsx(Pe,{asChild:!0,children:e.jsxs(b,{variant:"ghost",size:"sm",className:"h-6 px-2 text-[10px] text-muted-foreground hover:text-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:["debug · ",t.length," chunk(s)"]}),e.jsx(de,{className:"h-3 w-3 ml-1"})]})}),e.jsx(Ae,{className:"mt-1",children:e.jsx("div",{className:"space-y-1 p-2 bg-muted/40 rounded text-[10px] font-mono",children:t.map((c,m)=>e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("span",{className:"truncate",children:[c.author?`${c.author} / `:"",c.book??"â"]}),e.jsxs("span",{className:"flex items-center gap-1 shrink-0",children:[c.source_tier==="premium"&&e.jsx(Ne,{variant:"secondary",className:"text-[9px] px-1 py-0",children:"â "}),c.relevance_score!=null&&e.jsx("span",{className:"text-muted-foreground",children:c.relevance_score.toFixed(3)})]})]},m))})})]})]})}const F="/api/v1/chat",j=2e3,I={async createConversation(t,n){return B.post(`${F}/conversations`,{chart_id:t,title:n??null})},async listConversations(t=1,n=20){return B.get(`${F}/conversations?page=${t}&page_size=${n}`)},async getMessages(t){return B.get(`${F}/conversations/${t}/messages`)},async sendMessage(t,n){return B.post(`${F}/conversations/${t}/messages`,{content:n},{timeout:ye})}};function z({size:t=34}){const n={width:t*.62,height:t*.62};return e.jsxs("span",{"aria-hidden":!0,className:"flex flex-none items-center justify-center overflow-hidden rounded-full border border-primary/40 bg-primary/10",style:{width:t,height:t},children:[e.jsx("img",{src:"/logo-black.png",alt:"",className:"dark:hidden",style:n}),e.jsx("img",{src:"/logo.png",alt:"",className:"hidden dark:block",style:n})]})}function Le({persona:t}){const{t:n}=L();return e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(z,{}),e.jsx("div",{className:"rounded-2xl rounded-tl-sm border border-border bg-card px-4 py-3 text-sm italic text-muted-foreground",children:n("chat.thinking",{persona:t,defaultValue:`${t} está consultando o mapaâ¦`})})]})}function ze({message:t,persona:n}){var i;return t.role==="user"?e.jsx("div",{className:"max-w-[75%] self-end whitespace-pre-wrap rounded-2xl rounded-br-sm bg-primary px-4 py-3 text-sm font-medium text-primary-foreground",children:t.content}):e.jsxs("div",{className:"flex max-w-[85%] gap-3",children:[e.jsx(z,{}),e.jsx("div",{className:"min-w-0",children:e.jsxs("div",{className:"rounded-2xl rounded-tl-sm border border-border bg-card px-4 py-3","aria-label":n,children:[e.jsx(De,{content:t.content,size:"sm"}),(((i=t.sources)==null?void 0:i.length)??0)>0&&e.jsx(Ie,{sources:t.sources})]})})]})}function st(){const{t}=L(),[n,i]=ge(),{refreshCredits:h}=we(),o=t("chat.persona",{defaultValue:"Ptolomeu"}),[c,m]=a.useState([]),[V,me]=a.useState(null),[x,g]=a.useState([]),[S,O]=a.useState(""),[p,te]=a.useState(!1),[H,_]=a.useState(!1),[q,G]=a.useState(!1),[se,f]=a.useState(null),[K,ae]=a.useState([]),[xe,U]=a.useState(!1),re=a.useRef(null),M=a.useRef(null),J=a.useRef(!1),R=a.useRef(0),N=a.useRef(!1),E=a.useRef(null),ne=a.useRef(!1),le=a.useRef(new Set),y=a.useRef([]),Q=(V==null?void 0:V.id)??null,w=V,P=a.useCallback(s=>{M.current=(s==null?void 0:s.id)??null,me(s)},[]);a.useEffect(()=>{y.current=x},[x]);const C=a.useCallback(()=>{requestAnimationFrame(()=>{const s=re.current;s&&(s.scrollTop=s.scrollHeight)})},[]),k=a.useCallback(async(s,l=!1)=>{const r=++R.current;ne.current=l,P(s),i({conversation:s.id},{replace:!0}),f(null),G(!1),N.current=!0,_(!0);try{const u=await I.getMessages(s.id);if(R.current!==r)return;y.current=u.items,g(u.items),N.current=!1,_(!1),C(),l&&E.current!==s.id&&u.items.length>0&&W.track("chat_conversation_reopened",{conversation_id:s.id}),E.current=s.id}catch{if(R.current!==r)return;y.current=[],g([]),N.current=!1,_(!1),G(!0),E.current=null}},[P,i,C]),oe=a.useCallback(async s=>{f(null);try{const l=await I.createConversation(s);m(r=>[l,...r.filter(u=>u.id!==l.id)]),g([]),U(!1),await k(l)}catch{U(!0),f(t("chat.error.start",{defaultValue:"Não foi possÃvel iniciar a conversa. Tente novamente."}))}},[k,t]);a.useEffect(()=>{let s=!1;return(async()=>{const l=await I.listConversations(1,100).catch(()=>({items:[]}));if(s)return;m(l.items);const r=n.get("conversation"),u=n.get("chart");if(r){const $=l.items.find(T=>T.id===r);await k($??{id:r,chart_id:"",chart_name:null,title:null,created_at:"",updated_at:""})}else u&&await oe(u)})(),()=>{s=!0}},[]);const A=a.useCallback(async()=>
8{if(U(!0),K.length===0)try{const s=await Be.list(1,50,"person");ae(s.charts.filter(l=>l.chart_data))}catch{ae([])}},[K.length]),fe=a.useCallback(()=>{R.current++,N.current=!1,_(!1),E.current=null,y.current=[],P(null),g([]),G(!1),i({},{replace:!0}),A()},[A,i,P]),X=a.useCallback(async s=>{var T,ce;const l=s.trim(),r=M.current;if(!l||!r||J.current||N.current)return;if(l.length>j){f(t("chat.error.tooLong",{max:j,defaultValue:`Mensagem muito longa (máximo ${j} caracteres).`}));return}J.current=!0;const u=y.current.length===0;O(""),f(null),te(!0);const $={id:`tmp-${Date.now()}`,conversation_id:r,role:"user",content:l,sources:[],created_at:new Date().toISOString()};g(d=>[...d,$]),C();try{const d=await I.sendMessage(r,l);if(h(),u&&!le.current.has(r)&&(le.current.add(r),W.track("chat_conversation_started",{conversation_id:r})),W.track("chat_message_sent",{conversation_id:r,content_length:l.length,sources_count:((T=d.sources)==null?void 0:T.length)??0,has_sources:(((ce=d.sources)==null?void 0:ce.length)??0)>0}),M.current!==r)return;g(v=>[...v,d]),m(v=>{const D=v.find(Z=>Z.id===r);return D?[D,...v.filter(Z=>Z.id!==r)]:v})}catch(d){if(M.current!==r)return;g(v=>v.filter(D=>D.id!==$.id)),O(l),d instanceof Y&&d.status===402?(f(t("chat.error.insufficient",{defaultValue:"Você não tem créditos suficientes. Assine o plano Pro para mensagens ilimitadas."})),h()):d instanceof Y&&d.status===503?f(t("chat.error.unavailable",{persona:o,defaultValue:`${o} está indisponÃvel no momento. Tente novamente.`})):d instanceof Y&&d.status===422?f(t("chat.error.tooLong",{max:j,defaultValue:`Mensagem muito longa (máximo ${j} caracteres).`})):f(t("chat.error.generic",{defaultValue:"Algo deu errado. Tente novamente."}))}finally{J.current=!1,te(!1),C()}},[C,h,t,o]),he=s=>{s.key==="Enter"&&!s.shiftKey&&(s.preventDefault(),X(S))},pe=[t("chat.suggestion.temperament",{defaultValue:"Qual é o meu temperamento?"}),t("chat.suggestion.saturn",{defaultValue:"Como está o meu Saturno?"}),t("chat.suggestion.career",{defaultValue:"O que o mapa diz sobre carreira?"}),t("chat.suggestion.relationships",{defaultValue:"E sobre relacionamentos?"})];return e.jsxs("div",{className:"flex h-[calc(100vh-4rem)] flex-col",children:[e.jsxs("div",{className:"flex flex-none items-center justify-between gap-3 border-b border-border px-4 py-3 sm:px-6",children:[e.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:t("chat.context",{defaultValue:"Contexto"})}),w?e.jsxs("span",{className:"inline-flex items-center gap-2 truncate rounded-full border border-border bg-card px-3 py-1 text-sm font-semibold",children:[e.jsx(ue,{className:"h-3.5 w-3.5 text-primary"}),w.chart_name||w.title||t("chat.conversation",{defaultValue:"Conversa"})]}):e.jsxs("button",{type:"button",onClick:A,className:"inline-flex items-center gap-1.5 rounded-full border border-dashed border-border px-3 py-1 text-xs text-muted-foreground hover:text-foreground",children:[e.jsx(ee,{className:"h-3 w-3"}),t("chat.addMap",{defaultValue:"Escolher mapa"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Ce,{children:[e.jsx(ke,{asChild:!0,children:e.jsxs(b,{variant:"outline",size:"sm",className:"gap-1.5",disabled:p,children:[e.jsx(Ve,{className:"h-3.5 w-3.5"}),t("chat.history",{defaultValue:"Histórico"}),e.jsx(de,{className:"h-3 w-3"})]})}),e.jsxs(Se,{align:"end",className:"max-h-[380px] w-[300px] overflow-auto",children:[e.jsx(_e,{children:t("chat.conversations",{defaultValue:"Conversas"})}),c.length===0&&e.jsx("div",{className:"px-2 py-3 text-center text-xs text-muted-foreground",children:t("chat.noConversations",{defaultValue:"Nenhuma conversa ainda."})}),c.map(s=>e.jsxs(Me,{onSelect:()=>void k(s,!0),className:"flex-col items-start gap-0.5",children:[e.jsx("span",{className:"w-full truncate text-sm font-medium",children:s.title||s.chart_name||t("chat.untitled",{defaultValue:"Sem tÃtulo"})}),s.chart_name&&e.jsx("span",{className:"text-[11px] text-muted-foreground",children:s.chart_name})]},s.id))]})]}),e.jsxs(b,{size:"sm",onClick:fe,className:"gap-1.5",disabled:p,children:[e.jsx(ee,{className:"h-3.5 w-3.5"}),t("chat.newConversation",{defaultValue:"Nova conversa"})]})]})]}),e.jsx("div",{ref:re,className:"flex-1 overflow-auto px-4 py-6 sm:px-6","aria-busy":p,children:Q?q?e.jsxs("div",{className:"mx-auto flex max-w-md flex-col items-center gap-4 py-12 text-center",children:[e.jsx(ie,{className:"h-8 w-8 text-destructive"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t("chat.error.load",{defaultValue:"Não foi possÃvel carregar esta conversa. Tente novamente."})}),e.jsx(b,{variant:"outline",onClick:()=>w&&void k(w,ne.current),children:t("chat.retry",{defaultValue:"Tentar novamente"})})]}):H?e.jsxs("div",{className:"flex justify-center py-12",role:"status","aria-live":"polite",children:[e.jsx(Re,{className:"h-6 w-6 animate-spin text-muted-foreground"}),e.jsx("span",{className:"sr-only",children:t("common.loading",{defaultValue:"Carregandoâ¦"})})]}):e.jsxs("div",{className:"mx-auto flex max-w-3xl flex-col gap-5",children:[x.length===0&&!p&&e.jsxs("div",{className:"flex flex-col items-center gap-4 py-8 text-center",children:[e.jsx(z,{size:56}),e.jsx("h2",{className:"font-display text-2xl",children:t("chat.emptyTitle",{defaultValue:"Sobre o que deseja conversar?"})}),e.jsx("div",{className:"flex flex-wrap justify-center gap-2",children:pe.map(s=>e.jsx("button",{type:"button",onClick:()=>void X(s),className:"rounded-full border border-border bg-card px-4 py-2 text-xs hover:border-primary/40",children:s},s))})]}),x.map(s=>e.jsx(ze,{message:s,persona:o},s.id)),p&&e.jsx(Le,{persona:o})]}):e.jsx(Oe,{persona:o,pickerOpen:xe,charts:K,onOpenPicker:A,onPickChart:s=>void oe(s)})}),e.jsx("div",{className:"sr-only","aria-live":"polite",children:!p&&x.length>0&&x[x.length-1].role==="assistant"?x[x.length-1].content:""}),e.jsx("div",{className:"flex-none border-t border-border px-4 py-3 sm:px-6",children:e.jsxs("div",{className:"mx-auto max-w-3xl",children:[se&&e.jsxs("div",{className:"mb-2 flex items-center gap-2 rounded-lg border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive",children:[e.jsx(ie,{className:"h-3.5 w-3.5 flex-none"}),se]}),e.jsxs("div",{className:"flex items-end gap-2 rounded-2xl border border-border bg-card px-3 py-2",children:[e.jsx("textarea",{value:S,onChange:s=>O(s.target.value),onKeyDown:he,rows:1,maxLength:j,disabled:!Q||p||H||q,"aria-label":t("chat.composerLabel",{persona:o,defaultValue:`Pergunte a ${o}`}),placeholder:t("chat.placeholder",{persona:o,defaultValue:`Pergunte a ${o} sobre este mapaâ¦`}),className:"max-h-32 flex-1 resize-none bg-transparent py-1.5 text-sm outline-none placeholder:text-muted-foreground disabled:opacity-60"}),e.jsx(b,{size:"icon",className:"h-9 w-9 flex-none rounded-xl",disabled:!Q||p||H||q||!S.trim(),onClick:()=>
8void X(S),"aria-label":t("chat.send",{defaultValue:"Enviar"}),children:e.jsx(Fe,{className:"h-4 w-4"})})]}),e.jsxs("div",{className:"mt-2 flex items-center justify-between px-1 text-[11px] text-muted-foreground",children:[e.jsx("span",{children:t("chat.proNote",{defaultValue:"â Mensagens ilimitadas no plano Pro"})}),e.jsx("span",{children:t("chat.disclaimer",{persona:o,defaultValue:`${o} pode errar â confira as posições no mapa`})})]})]})})]})}function Oe({persona:t,pickerOpen:n,charts:i,onOpenPicker:h,onPickChart:o}){const{t:c}=L();return e.jsxs("div",{className:"mx-auto flex max-w-md flex-col items-center gap-4 py-12 text-center",children:[e.jsx(z,{size:56}),e.jsx("h2",{className:"font-display text-2xl",children:c("chat.startTitle",{persona:t,defaultValue:"Converse com o seu mapa natal"})}),e.jsx("p",{className:"text-sm text-muted-foreground",children:c("chat.startBody",{persona:t,defaultValue:"Pergunte em linguagem clara â respostas fundadas em Ptolomeu, Lilly, Bonatti e Valens. Escolha um mapa para começar."})}),n?e.jsx("div",{className:"w-full space-y-2",children:i.length===0?e.jsx("p",{className:"text-xs text-muted-foreground",children:c("chat.noCharts",{defaultValue:"Nenhum mapa disponÃvel ainda."})}):i.map(m=>e.jsxs("button",{type:"button",onClick:()=>o(m.id),className:"flex w-full items-center gap-3 rounded-xl border border-border bg-card px-4 py-3 text-left hover:border-primary/40",children:[e.jsx(ue,{className:"h-4 w-4 flex-none text-primary"}),e.jsx("span",{className:"truncate text-sm font-medium",children:m.person_name})]},m.id))}):e.jsxs(b,{onClick:h,className:"gap-2",children:[e.jsx(ee,{className:"h-4 w-4"}),c("chat.chooseMap",{defaultValue:"Escolher um mapa"})]})]})}export{st as ChatPage,st as default}; 9 10//# debugId=94f0c655-4c54-5367-ad13-1cae4f6e5c17
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.