PageSourceSearch

https://loveacrossborders.com/assets/twin.admin-CRcF2nQb.js

js loveacrossborders.com collected 2026-10-08 14:16:57 UTC 10,191 bytes, 1 lines download raw bytes

1import{h as I,r as a,s as M,j as e,L as f,t}from"./index-hs4a0mYW.js";import{u as D}from"./useQuery-C-iGd3mh.js";import{u as S}from"./useMutation-CsVV5qgy.js";import{u as x}from"./useServerFn-DgMZqDJQ.js";import{t as R,a as G,b as _,c as H,g as V}from"./twin.functions-BcZ58lAP.js";import{e as K}from"./extract-text-Dj6Ou_lK.js";import{G as c}from"./brand-BVAz6htY.js";import{A as X}from"./arrow-left-bJxZenjV.js";import{S as q}from"./sparkles-BZGgZXIM.js";import{P as Y}from"./plus-BzpCviRC.js";import{F as J}from"./file-text-G_mxHyOn.js";import{U as Q}from"./upload-hM-7dRRF.js";import{T as W}from"./trash-2-Bg71gBw1.js";const Z=[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]],ee=I("save",Z),se="#0a0a0c",l="#f0d78c";function be(){const[d,h]=a.useState(!1),[j,p]=a.useState(!1);return a.useEffect(()=>{let b=!0;M.auth.getUser().then(({data:i})=>{b&&(p(!!i.user),h(!0))});const{data:n}=M.auth.onAuthStateChange((i,o)=>{p(!!o?.user),h(!0)});return()=>{b=!1,n.subscription.unsubscribe()}},[]),d?j?e.jsx(te,{}):e.jsxs(g,{children:[e.jsx("h1",{className:"text-xl font-semibold mb-3",children:"Sign in required"}),e.jsx("p",{className:"text-zinc-400 mb-6",children:"Only administrators can manage the twin's source material."}),e.jsx(f,{to:"/auth",search:{mode:"signin",redirect:"/twin/admin"},className:"inline-flex items-center px-5 py-2.5 rounded-full text-black font-medium",style:{background:`linear-gradient(135deg,${l},${c})`},children:"Sign in"})]}):e.jsx(g,{children:e.jsx("p",{className:"text-zinc-500",children:"Checking..."})})}function g({children:d}){return e.jsxs("div",{className:"min-h-screen text-zinc-100",style:{background:se,fontFamily:"'Manrope', system-ui, sans-serif"},children:[e.jsx("header",{className:"border-b border-white/5",children:e.jsxs("div",{className:"mx-auto max-w-5xl px-6 py-5 flex items-center justify-between",children:[e.jsxs(f,{to:"/twin",className:"inline-flex items-center gap-2 text-sm text-zinc-400 hover:text-zinc-100",children:[e.jsx(X,{className:"h-4 w-4","aria-hidden":!0})," Back to Twin"]}),e.jsxs("span",{className:"inline-flex items-center gap-1.5 text-sm font-semibold",style:{color:l},children:[e.jsx(q,{className:"h-4 w-4","aria-hidden":!0})," Twin · Admin"]})]})}),e.jsx("main",{className:"mx-auto max-w-5xl px-6 py-10",children:d})]})}function te(){const d=x(R),h=x(G),j=x(_),p=x(H),b=x(V),{data:n,refetch:i}=D({queryKey:["twin-meta"],queryFn:()=>b()}),{data:o,isLoading:U,refetch:z,error:F}=D({queryKey:["twin-sources"],queryFn:()=>d(),retry:!1}),[w,L]=a.useState(""),[$,T]=a.useState("");a.useEffect(()=>{n?.persona&&(L(n.persona.name??""),T(n.persona.description??""))},[n?.persona]);const[m,y]=a.useState(""),[u,N]=a.useState(""),[A,P]=a.useState(!1),[B,C]=a.useState(0),k=S({mutationFn:()=>h({data:{sourceLabel:m.trim(),text:u}}),onSuccess:s=>{t.success(`Added ${s.inserted} chunks from "${m}".`),N(""),y(""),z(),i()},onError:s=>t.error(s.message)}),E=S({mutationFn:s=>j({data:{sourceLabel:s}}),onSuccess:()=>{t.success("Source removed."),z(),i()},onError:s=>t.error(s.message)}),v=S({mutationFn:()=>p({data:{name:w.trim(),description:$}}),onSuccess:()=>{t.success("Twin updated."),i()},onError:s=>t.error(s.message)}),O=async s=>{if(s.size>5e7)return t.error("File too large (50 MB max).");try{P(!0),C(0);const r=await K(s,C);N(r),m||y(s.name.replace(/\.(pdf|docx|epub|txt|md)$/i,"")),t.success(`Extracted ${r.length.toLocaleString()} chars.`)}catch(r){t.error(r instanceof Error?r.message:"Failed")}finally{P(!1)}};return F?e.jsx(g,{children:e.jsxs("div",{className:"rounded-lg border border-rose-400/30 bg-rose-500/10 p-6",children:[e.jsx("h2",{className:"font-semibold",children:"Not authorized"}),e.jsx("p",{className:"mt-1 text-sm text-rose-200",children:F.message}),e.jsxs("p",{className:"mt-3 text-xs text-rose-300/80",children:["You need the admin role. Visit ",e.jsx(f,{to:"/books/admin",className:"underline",children:"/books/admin"})," to claim it (first user only)."]})]})}):e.jsxs(g,{children:[e.jsxs("div",{className:"mb-8",children:[e.jsx("h1",{className:"text-3xl tracking-tight",style:{fontFamily:"'Sora', sans-serif",fontWeight:600},children:"Train your twin"}),e.jsx("p",{className:"mt-2 text-sm text-zinc-400",children:"Upload your essays, talks, interviews, transcripts, and notes. Your twin will speak only from what you upload, and cite the source."})]}),e.jsxs("section",{className:"rounded-xl border border-white/10 bg-white/[0.03] p-6 mb-10",children:[e.jsxs("h2",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(q,{className:"h-4 w-4",style:{color:c}})," Identity"]}),e.jsxs("label",{className:"block mb-3",children:[e.jsx("span",{className:"block text-xs uppercase tracking-wider text-zinc-500 mb-1.5",children:"Twin name"}),e.jsx("input",{value:w,onChange:s=>L(s.target.value),maxLength:120,placeholder:"e.g. Ada Lovelace",className:"w-full px-3 py-2 text-sm rounded-md bg-black/30 border border-white/15 focus:border-amber-400/60 focus:outline-none"})]}),e.jsxs("label",{className:"block mb-4",children:[e.jsx("span",{className:"block text-xs uppercase tracking-wider text-zinc-500 mb-1.5",children:"Short bio (shown to visitors)"}),e.jsx("textarea",{value:$,onChange:s=>T(s.target.value),rows:3,maxLength:2e3,placeholder:"One or two sentences describing who this twin represents.",className:"w-full px-3 py-2 text-sm rounded-md bg-black/30 border border-white/15 focus:border-amber-400/60 focus:outline-none"})]}),e.jsxs("button",{onClick:()=>v.mutate(),disabled:v.isPending||!w.trim(),className:"inline-flex items-center gap-2 px-5 py-2 rounded-full text-black text-sm font-medium disabled:opacity-50",style:{background:`linear-gradient(135deg,${l},${c})`},children:[e.jsx(ee,{className:"h-4 w-4","aria-hidden":!0})," ",v.isPending?"Saving...":"Save identity"]})]}),e.jsxs("section",{className:"rounded-xl border border-white/10 bg-white/[0.03] p-6 mb-10",children:[e.jsxs("h2",{className:"font-semibold mb-4 flex items-center gap-2",children:[e.jsx(Y,{className:"h-4 w-4"})," Add source material"]}),e.jsxs("label",{className:"block mb-4",children:[e.jsx("span",{className:"block text-xs uppercase tracking-wider text-zinc-500 mb-1.5",children:"Source label"}),e.jsx("input",{value:m,onChange:s=>y(s.target.value),maxLength:255,placeholder:'e.g. "Essay: Building from zero (2023)" or "Podcast transcript · Acquired, Jan 2024"',className:"w-full px-3 py-2 text-sm rounded-md bg-black/30 border border-white/15 focus:border-amber-400/60 focus:outline-none"})]}),e.jsxs("div",{className:"mb-4 flex items-center gap-3",children:[e.jsxs("label",{className:"inline-flex items-center gap-2 px-3 py-2 text-xs rounded-md cursor-pointer text-black font-medium",style:{background:`linear-gradient(135deg,${l},${c})`},children:[e.jsx(J,{className:"h-3.5 w-3.5","aria-hidden":!0}),A?`Reading... ${B}%`:"Upload PDF / DOCX / EPUB / TXT / MD",e.jsx("input",{type:"file",accept:".pdf,.docx,.epub,.txt,.md,application/pdf,application/epub+zip,application/vnd.openxmlformats-officedocument.wordprocessingml.document,text/plain,text/markdown",className:"hidden",disabled:A,onChange:s=>{const r=s.target.files?.[0];r&&O(r),s.target.value=""}})]}),e.jsx("span",{className:"text-xs text-zinc-500",children:u?`${u.length.toLocaleStr
1ing()} chars loaded`:"or paste text below"})]}),e.jsx("textarea",{value:u,onChange:s=>N(s.target.value),rows:12,maxLength:2e6,placeholder:"Paste essays, talks, transcripts, or notes here...",className:"w-full px-3 py-2 text-sm font-mono rounded-md bg-black/30 border border-white/15 focus:border-amber-400/60 focus:outline-none"}),e.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[e.jsx("p",{className:"text-xs text-zinc-500",children:"Text is split into ~1,200 char chunks, retrieved at query time."}),e.jsxs("button",{onClick:()=>{if(!m.trim())return t.error("Add a source label first.");if(u.trim().length<20)return t.error("Paste more text.");k.mutate()},disabled:k.isPending,className:"inline-flex items-center gap-2 px-5 py-2.5 rounded-full text-black text-sm font-medium disabled:opacity-50",style:{background:`linear-gradient(135deg,${l},${c})`},children:[e.jsx(Q,{className:"h-4 w-4","aria-hidden":!0}),k.isPending?"Adding...":"Add source"]})]})]}),e.jsxs("section",{children:[e.jsxs("div",{className:"flex items-baseline justify-between mb-4",children:[e.jsx("h2",{className:"font-semibold",children:"Current source material"}),e.jsxs("span",{className:"text-xs text-zinc-500",children:[o?.total??0," chunks total"]})]}),U?e.jsx("p",{className:"text-zinc-500",children:"Loading..."}):!o||o.sources.length===0?e.jsx("div",{className:"rounded-lg border border-dashed border-white/15 p-10 text-center text-zinc-500 text-sm",children:"No sources yet. Add the first one above."}):e.jsx("ul",{className:"rounded-lg border border-white/10 bg-white/[0.03] divide-y divide-white/5",children:o.sources.map(s=>e.jsxs("li",{className:"p-4 flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"font-medium truncate",children:s.label}),e.jsxs("p",{className:"text-xs text-zinc-500 mt-0.5",children:[s.count," chunks"]}),e.jsx("p",{className:"text-xs text-zinc-400 mt-2 line-clamp-2",children:s.preview})]}),e.jsx("button",{onClick:()=>{confirm(`Delete all ${s.count} chunks from "${s.label}"?`)&&E.mutate(s.label)},disabled:E.isPending,className:"p-2 text-rose-300 hover:bg-rose-500/10 rounded-md",title:"Remove source",children:e.jsx(W,{className:"h-4 w-4","aria-hidden":!0})})]},s.label))}),e.jsxs("div",{className:"mt-8 flex items-center justify-between rounded-lg border border-white/10 bg-white/[0.02] px-5 py-4",children:[e.jsx("p",{className:"text-sm text-zinc-400",children:"Ready to test? Try a conversation with your twin."}),e.jsx(f,{to:"/twin/talk",className:"inline-flex items-center gap-1 px-4 py-2 rounded-full text-black text-sm font-medium",style:{background:`linear-gradient(135deg,${l},${c})`},children:"Open public chat"})]})]})]})}export{be as component};

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.