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]="97558bec-d330-551b-bc2f-d1648309eeec")}catch(e){}}(); 3import{j as t}from"./vendor-radix-D60p-_ms.js";import{r as o}from"./vendor-react-DRd396Ms.js";import{aC as H,o as S,e as b,ac as ot,E as K,W as fe,ar,az as At,X as ir,at as Dt,ad as nr,aw as sr,aU as or,aW as lr,aY as cr,b6 as dr,S as ur,l as pr,h as hr,k as mr,aA as gr,aD as rt,aB as N,ay as le,t as fr,bV as xr,aH as br,g as yr,a1 as wr,m as me,aT as vr,bW as jr}from"./index-vRxdZvmj.js";import{u as at,c as ce}from"./vendor-query-CQDkrmBu.js";import{u as yt,p as kr}from"./use-resumable-job-Dg1FOBDa.js";import{u as _r}from"./use-vaulted-input-Buttoenb.js";import{c as Nr}from"./sentry-capture-BAbJXbnc.js";import{A as Sr}from"./app-layout-Cq4_xc6x.js";import{u as Cr}from"./user-facing-error-DLM6u6dy.js";import{i as Er}from"./authUtils-VY3a4Th3.js";import{T as Tr,L as Pe,P as Ut,C as Pr,b as Ir,D as it}from"./types--6CeOTJC.js";import{m as L,A as Ft}from"./vendor-motion-DZC2ImUw.js";import{C as ct}from"./corner-down-left-DLCDRtTA.js";import{f as Rr}from"./character-fallback-palette-DlBCOvP7.js";import{I as Ar}from"./image-CFxaiEO_.js";import{P as Dr}from"./pencil-BF8O2Bq2.js";import{U as Ur}from"./upload-DBLFk0Nd.js";import{l as Fr}from"./utils-puaEeEiv.js";import{d as zr}from"./character-draft-openable-D8IzmzCK.js";import{A as Lr}from"./arrow-left-B4mhrtMh.js";import"./vendor-classnames-B2rm_Apj.js";import"./vendor-i18n-D-E_aly0.js";import"./use-mobile-chVkPFdn.js";import"./disclaimer-footer-Hqujv6UM.js";import"./smart-search-CKP8f_-T.js";import"./badge-CgJg1GxD.js";import"./chat-navigation-B9i_Azd6.js";import"./users-DpNoy9Sz.js";import"./trending-up-DCY3beNH.js";import"./chevron-up-DrFhPJ1Z.js";import"./avatar-EV6pMp1V.js";import"./heart-JgOMfL3i.js";function Ee(e="/character-create",a){const i=new URLSearchParams({returnTo:e});return a&&i.set("reason",a),`/auth?${i.toString()}`}function zt(){return{title:"Sign up to keep the character you made",description:"It is saved to this browser only. A free account keeps it, and lets you make another.",ctaLabel:"Keep it",ctaHref:Ee("/character-create","publish_wall"),variant:"default"}}function Mr(e){if(e.code==="anon_create_limit")return zt();const a=e.limit??5,i=a===1?"character":"characters";return e.scope==="ip"?{title:"This network has used its free characters",description:"You are on a shared connection that has hit the monthly limit. Make a free account and your own allowance travels with you.",ctaLabel:"Create a free account",ctaHref:e.signupUrl??Ee("/character-create","network_limit"),variant:"default"}:e.scope==="unidentified"?{title:"We could not verify this browser",description:"Private browsing or a blocked cookie can cause this. Signing in works either way.",ctaLabel:"Sign in",ctaHref:Ee("/character-create","unidentified"),variant:"default"}:{title:`That is your ${a} free ${i} this month`,description:"Your allowance resets on the 1st. A free account lifts the limit and keeps everything you have made.",ctaLabel:"Keep making characters",ctaHref:e.signupUrl??Ee("/character-create","generation_limit"),variant:"default"}}function Hr(){return{title:"Made without a portrait",description:"You have used this month's images. The character is saved and you can add a portrait with a free account.",ctaLabel:"Add a portrait",ctaHref:Ee("/character-create","portrait_limit"),variant:"default"}}function wt(e){const a=e==null?void 0:e.code;return a==="anon_generation_limit"||a==="ANON_IMAGE_LIMIT"||a==="anon_create_limit"}const Lt=24*36e5,Gr="character-create";function ge(e){return{name:e.name,title:e.title,description:e.description,persona:e.persona,greeting:e.greeting,tags:[...e.tags],icon:e.icon,theme:e.theme,category:e.category}}function lt(e,a){if(e.name!==a.name||e.title!==a.title||e.description!==a.description||e.persona!==a.persona||e.greeting!==a.greeting||e.icon!==a.icon||e.theme!==a.theme||e.category!==a.category||e.tags.length!==a.tags.length)return!1;for(let i=0;i<e.tags.length;i++)if(e.tags[i]!==a.tags[i])return!1;return!0}function te(e,a){const i=Reflect.get(e,a);return typeof i=="string"?i:null}function vt(e){if(typeof e!="object"||e===null)return null;const a=te(e,"name"),i=te(e,"title"),n=te(e,"description"),l=te(e,"persona"),p=te(e,"greeting"),u=te(e,"icon"),g=te(e,"theme"),v=te(e,"category"),C=Reflect.get(e,"tags");if(a===null||i===null||n===null||l===null||p===null||u===null||g===null||v===null||!Array.isArray(C))return null;const j=[];
3for(const y of C){if(typeof y!="string")return null;j.push(y)}return{name:a,title:i,description:n,persona:l,greeting:p,tags:j,icon:u,theme:g,category:v}}function Mt(e){if(typeof e!="object"||e===null)return null;const a=vt(Reflect.get(e,"base")),i=vt(Reflect.get(e,"edited")),n=Reflect.get(e,"at");return a===null||i===null||typeof n!="number"?null:{base:a,edited:i,at:n}}function Te(e,a){return H(e,Gr,a)}function jt(e,a,i,n,l){const p=Te(a,i);if(lt(n,l)){e.remove(p);return}const u={base:n,edited:l,at:Date.now()};e.set(p,u,Lt)}function Wr(e,a,i,n){const l=Te(a,i),p=e.get(l,Mt);return p?!lt(p.base,n)||lt(p.edited,n)?(e.remove(l),null):p.edited:null}function Me(e,a,i){e.remove(Te(a,i))}const Ce="unbound";function kt(e,a,i,n){if(i===n)return;const l=Te(a,i),p=e.get(l,Mt);e.remove(l),p&&e.set(Te(a,n),p,Lt)}const He=Pr,Or=["A 1990s skater girl who teaches CSS","Edison, but he reviews your code","Drill sergeant for habit-building","Cleo, makeup advice from antiquity"];function Kr({value:e,onChange:a,onSubmit:i,onLongFormShortcut:n,disabled:l=!1,autoFocus:p=!0}){const u=o.useId(),[g,v]=o.useState("type"),C=S("character_create_mode_changed"),j=y=>{y!==g&&(C({from:g,to:y}),v(y))};return t.jsxs(L.section,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.35,ease:[.16,1,.3,1]},className:"relative mx-auto w-full max-w-[540px] px-4","aria-labelledby":u,children:[t.jsxs("div",{className:"text-center",children:[t.jsx("h1",{id:u,className:"text-white",style:{fontSize:"32px",fontWeight:600,letterSpacing:"-0.02em",lineHeight:1.15},children:"Describe your character."}),t.jsx("p",{className:"mx-auto mt-3 max-w-[440px] text-gray-500",style:{fontSize:"14px",lineHeight:1.55},children:"A sentence is enough. Weâll fill in the persona, voice, image, and tags."})]}),t.jsx($r,{mode:g,onChange:j,disabled:l}),t.jsxs(Ft,{mode:"wait",children:[g==="type"&&t.jsx(L.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-6},transition:{duration:.18},children:t.jsx(Br,{value:e,onChange:a,onSubmit:()=>i(e.trim()),onLongFormShortcut:n,disabled:l,autoFocus:p})},"type"),g==="paste"&&t.jsx(L.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-6},transition:{duration:.18},children:t.jsx(Yr,{disabled:l,onUseSeed:y=>{a(y),i(y)}})},"paste"),g==="drop"&&t.jsx(L.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},exit:{opacity:0,y:-6},transition:{duration:.18},children:t.jsx(Xr,{})},"drop")]})]})}function $r({mode:e,onChange:a,disabled:i}){return t.jsxs("div",{role:"tablist","aria-label":"Character creation mode",className:"mt-7 flex flex-wrap items-center justify-center gap-1.5",children:[t.jsx(nt,{icon:t.jsx(Tr,{className:"h-3.5 w-3.5","aria-hidden":"true"}),label:"Type",active:e==="type",onClick:()=>a("type"),disabled:i}),t.jsx(nt,{icon:t.jsx(Pe,{className:"h-3.5 w-3.5","aria-hidden":"true"}),label:"Paste a link",active:e==="paste",onClick:()=>a("paste"),disabled:i}),t.jsx(nt,{icon:t.jsx(Ut,{className:"h-3.5 w-3.5","aria-hidden":"true"}),label:"Drop a file",soonLabel:"soon",active:e==="drop",onClick:()=>a("drop"),disabled:i})]})}function nt({icon:e,label:a,soonLabel:i,active:n,onClick:l,disabled:p}){return t.jsxs("button",{type:"button",role:"tab","aria-selected":n,onClick:l,disabled:p,"data-active":n,className:b("inline-flex items-center gap-1.5 whitespace-nowrap rounded-[6px] border px-3 py-1.5","text-xs font-medium transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40","disabled:cursor-not-allowed disabled:opacity-50","min-h-11 sm:min-h-[30px]",n?"border-blue-500/50 bg-blue-500/10 text-white":"border-white/10 bg-white/[0.03] text-gray-400 hover:border-white/20 hover:bg-white/[0.06] hover:text-white"),children:[e,t.jsx("span",{children:a}),i?t.jsx("span",{className:"ml-0.5 rounded-[6px] bg-white/[0.06] px-1.5 py-px text-[9.5px] uppercase tracking-wide text-gray-500","aria-hidden":"true",children:i}):null]})}function Br({value:e,onChange:a,onSubmit:i,onLongFormShortcut:n,disabled:l,autoFocus:p}){const u=o.useRef(null),g=o.useId(),v=S("character_create_generate_clicked",{mode:"type"}),C=S("character_create_longform_shortcut"),j=S("character_create_chip_clicked");o.useEffect(()=>{if(p&&u.current){u.current.focus();const d=u.current.value.length;u.current.setSelectionRange(d,d)}},[p]);const y=o.useCallback(d=>{const m=d.metaKey||d.ctrlKey;if(m&&d.key==="Enter"){d.preventDefault(),!l&&e.trim().length>=3&&(v({source:"keyboard",char_count:e.trim().length}),i());return}m&&d.key==="."&&(d.preventDefault(),C({char_count:e.trim().length}),n==null||n())},[l,n,i,e]),A=o.useCallback(d=>{const m=d.target.value;m.length<=He?a(m):a(m.slice(0,He))},[a]),E=o.useCallback(d=>{j({chip_text:d}),a(d),requestAnimationFrame(()=>{if(u.current){u.current.focus();const m=u.current.value.length;u.current.setSelectionRange(m,m)}})},[a]),U=e.length,I=!l&&e.trim().length>=3;return t.jsxs("div",{children:[t.jsx("div",{className:"relative mt-6",children:t.jsxs("div",{className:"relative",style:{background:"rgb(var(--surface-1))",border:"2px s
3olid #3b82f6",borderRadius:"14px",boxShadow:"0 0 0 4px rgba(59,130,246,0.08)"},children:[t.jsx("textarea",{ref:u,value:e,onChange:A,onKeyDown:y,disabled:l,spellCheck:!0,"aria-describedby":g,"aria-label":"Character description",placeholder:"A renaissance polymath who explains physics through paintingsâ¦",maxLength:He,className:b("block w-full resize-none bg-transparent text-white outline-none","placeholder:text-gray-600 disabled:opacity-60","text-base sm:text-[14px]","p-[18px] pb-[64px] sm:pb-[50px]","min-h-[154px] sm:min-h-[120px]"),style:{lineHeight:1.5,fontFamily:"-apple-system, 'Inter', system-ui, sans-serif",borderRadius:"14px"}}),t.jsxs("div",{id:g,className:"pointer-events-none absolute inset-x-0 bottom-0 flex items-center justify-between px-4 pb-3",children:[t.jsxs("span",{className:"pointer-events-auto select-none text-gray-600",style:{fontSize:"11px",letterSpacing:"0.02em"},"aria-live":"polite",children:[U," / ",He]}),t.jsxs("button",{type:"button",onClick:()=>{v({source:"button",char_count:e.trim().length}),i()},disabled:!I,"aria-label":"Generate character (Cmd or Ctrl + Enter)",className:b("pointer-events-auto inline-flex items-center gap-1.5 rounded-[6px] font-bold transition-all","min-h-11 sm:min-h-0","disabled:cursor-not-allowed disabled:opacity-40",I?"bg-white text-black hover:bg-white/90":"bg-white/40 text-black/60"),style:{fontSize:"12px",padding:"6px 14px",borderRadius:"6px"},children:[t.jsx("span",{children:"Generate"}),t.jsx(ct,{className:"h-3 w-3","aria-hidden":"true"})]})]})]})}),t.jsx("div",{className:"mt-6 flex flex-wrap justify-center",style:{gap:"6px"},role:"group","aria-label":"Example character descriptions",children:Or.map(d=>t.jsx("button",{type:"button",onClick:()=>E(d),disabled:l,className:b("rounded-[6px] border border-white/10 bg-white/[0.03]","text-gray-300 transition-colors","hover:border-white/20 hover:bg-white/[0.06] hover:text-white","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40","disabled:cursor-not-allowed disabled:opacity-50","min-h-11 sm:min-h-[28px]"),style:{fontSize:"12px",padding:"6px 12px"},children:d},d))}),t.jsxs("p",{className:"mt-6 hidden text-center text-gray-700 sm:block",style:{fontSize:"11.5px",letterSpacing:"0.01em"},children:["Press ",t.jsxs(_t,{children:[Nt()?"â":"Ctrl","âµ"]})," to generate ·"," ",t.jsxs(_t,{children:[Nt()?"â":"Ctrl","."]})," for the long-form editor"]})]})}function Jr(e){return e instanceof Error&&Er(e)?"Sign in to import from a link, or switch to Type and describe your character.":Cr(e,"We couldn't read that page. Try a different link.")}function Yr({disabled:e,onUseSeed:a}){const[i,n]=o.useState(""),[l,p]=o.useState({status:"idle"}),u=o.useRef(null),g=o.useId(),v=S("character_create_url_extract_use_this"),C=S("character_create_url_extract_try_another"),j=S("character_create_url_extract_retry");o.useEffect(()=>{var m;(m=u.current)==null||m.focus()},[]);const y=o.useCallback(async m=>{const P=m.trim();if(P.length<8){p({status:"error",message:"Paste a full URL (e.g. https://en.wikipedia.org/wiki/...)"});return}let $="the page";try{$=new URL(P).hostname}catch{p({status:"error",message:"That doesn't look like a valid URL."});return}p({status:"extracting",hostname:$});try{const G=await ot("character_create_url_extract_submitted",async()=>await(await K("POST","/api/personalities/extract-from-url",{url:P})).json(),{hostname:$});if(!G.data)throw new Error(G.error??"Extraction failed");p({status:"ready",content:G.data})}catch(G){p({status:"error",message:Jr(G)})}},[]),A=o.useCallback(m=>{m==null||m.preventDefault(),!e&&l.status!=="extracting"&&y(i)},[e,y,l.status,i]),E=o.useCallback(()=>{if(l.status!=="ready")return;const m=Ir(l.content);v({title:l.content.title,has_description:!!l.content.description,seed_chars:m.length}),a(m)},[a,l]),U=o.useCallback(()=>{var m;j(),p({status:"idle"}),(m=u.current)==null||m.focus()},[]),I=o.useCallback(()=>{var m;C(),p({status:"idle"}),n(""),(m=u.current)==null||m.focus()},[]),d=l.status==="extracting";return t.jsxs("div",{className:"mt-6",children:[t.jsxs("form",{onSubmit:A,children:[t.jsx("label",{htmlFor:g,className:"sr-only",children:"Paste a URL"}),t.jsxs("div",{className:"flex items-center gap-2 transition-shadow focus-within:shadow-[0_0_0_4px_rgba(59,130,246,0.12)]",style:{background:"rgb(var(--surface-1))",border:"2px s
3olid #3b82f6",borderRadius:"14px",padding:"8px 10px 8px 14px"},children:[t.jsx(Pe,{className:"h-4 w-4 flex-shrink-0 text-blue-400","aria-hidden":"true"}),t.jsx("input",{ref:u,id:g,type:"url",inputMode:"url",autoComplete:"off",spellCheck:!1,value:i,onChange:m=>n(m.target.value),disabled:e||d,placeholder:"https://en.wikipedia.org/wiki/Marcus_Aurelius","aria-label":"URL to extract",className:b("block w-full bg-transparent text-white outline-none","placeholder:text-gray-600 disabled:opacity-60","text-base sm:text-[14px]"),style:{lineHeight:1.5,fontFamily:"-apple-system, 'Inter', system-ui, sans-serif",padding:"8px 4px"}}),t.jsx("button",{type:"submit",disabled:e||d||i.trim().length<8,className:b("inline-flex items-center gap-1.5 rounded-[6px] font-bold transition-all","min-h-11 sm:min-h-0","disabled:cursor-not-allowed disabled:opacity-40","bg-white text-black hover:bg-white/90"),style:{fontSize:"12px",padding:"6px 14px",borderRadius:"6px"},children:d?t.jsxs(t.Fragment,{children:[t.jsx(fe,{className:"h-3 w-3 animate-spin","aria-hidden":"true"}),t.jsx("span",{children:"Fetching"})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"Fetch"}),t.jsx(ct,{className:"h-3 w-3","aria-hidden":"true"})]})})]})]}),t.jsx("p",{className:"mt-3 text-center text-gray-500",style:{fontSize:"12px",lineHeight:1.4},children:"Works with: Wikipedia · YouTube · Substack · Blog posts"}),t.jsxs("div",{className:"mt-4",children:[l.status==="extracting"&&t.jsx(qr,{hostname:l.hostname}),l.status==="ready"&&t.jsx(Vr,{content:l.content,onUseThis:E,onTryAnother:I,disabled:e}),l.status==="error"&&t.jsx(Qr,{message:l.message,onRetry:U})]})]})}function qr({hostname:e}){return t.jsxs(L.div,{initial:{opacity:0}
3,animate:{opacity:1},className:"rounded-[8px] border border-white/[0.06] bg-white/[0.02] p-4",role:"status","aria-live":"polite",children:[t.jsxs("div",{className:"flex items-center gap-2 text-gray-400",style:{fontSize:"13px"},children:[t.jsx(fe,{className:"h-3.5 w-3.5 animate-spin text-blue-400","aria-hidden":"true"}),t.jsxs("span",{children:["Extracting from ",e,"â¦"]})]}),t.jsxs("div",{className:"mt-3 space-y-2",children:[t.jsx("div",{className:"h-3 w-3/4 animate-pulse rounded bg-white/[0.06]"}),t.jsx("div",{className:"h-3 w-2/3 animate-pulse rounded bg-white/[0.05]"}),t.jsx("div",{className:"h-3 w-1/2 animate-pulse rounded bg-white/[0.04]"})]})]})}function Vr({content:e,onUseThis:a,onTryAnother:i,disabled:n}){const l={wikipedia:"Wikipedia",youtube:"YouTube",substack:"Substack",blog:"Web page"};return t.jsxs(L.div,{initial:{opacity:0,y:6},animate:{opacity:1,y:0},transition:{duration:.18},className:"overflow-hidden rounded-[8px] border border-white/[0.08] bg-white/[0.025]",children:[t.jsxs("div",{className:"flex gap-3 p-3",children:[e.imageUrl?t.jsx("img",{src:e.imageUrl,alt:"",className:"h-16 w-16 flex-shrink-0 rounded-md object-cover",style:{background:"rgb(var(--surface-1))"},loading:"lazy"}):t.jsx("div",{"aria-hidden":"true",className:"flex h-16 w-16 flex-shrink-0 items-center justify-center rounded-md bg-blue-500/10 text-blue-400",children:t.jsx(Pe,{className:"h-5 w-5"})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsxs("div",{className:"flex items-center gap-2 text-blue-400",style:{fontSize:"10.5px",letterSpacing:"0.04em",textTransform:"uppercase"},children:[t.jsx("span",{children:l[e.sourceType]}),t.jsx("span",{className:"text-gray-700",children:"·"}),t.jsx("span",{className:"truncate text-gray-500",children:e.hostname})]}),t.jsx("h3",{className:"mt-1 truncate text-white",style:{fontSize:"14px",fontWeight:600,lineHeight:1.3},children:e.title}),e.description?t.jsx("p",{className:"mt-1 line-clamp-2 text-gray-400",style:{fontSize:"12.5px",lineHeight:1.5},children:e.description}):null]})]}),t.jsxs("div",{className:"flex items-center justify-end gap-2 border-t border-white/[0.05] bg-black/20 px-3 py-2",children:[t.jsx("button",{type:"button",onClick:i,disabled:n,className:b("inline-flex items-center gap-1 rounded-[6px] px-2.5 py-1 text-gray-400","min-h-11 sm:min-h-0","transition-colors hover:bg-white/[0.05] hover:text-white","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40","disabled:cursor-not-allowed disabled:opacity-50"),style:{fontSize:"12px"},children:"Try another"}),t.jsxs("button",{type:"button",onClick:a,disabled:n,className:b("inline-flex items-center gap-1.5 rounded-[6px] font-bold transition-all","min-h-11 sm:min-h-0","bg-white text-black hover:bg-white/90","disabled:cursor-not-allowed disabled:opacity-40","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40"),style:{fontSize:"12px",padding:"6px 14px",borderRadius:"6px"},children:[t.jsx("span",{children:"Use this"}),t.jsx(ct,{className:"h-3 w-3","aria-hidden":"true"})]})]})]})}function Qr({message:e,onRetry:a}){return t.jsxs(L.div,{initial:{opacity:0}
3,animate:{opacity:1},role:"alert",className:"flex items-start justify-between gap-3 rounded-[8px] border border-red-500/20 bg-red-500/[0.06] p-3",children:[t.jsx("p",{className:"text-red-200",style:{fontSize:"12.5px",lineHeight:1.45},children:e}),t.jsxs("button",{type:"button",onClick:a,className:"inline-flex min-h-11 flex-shrink-0 items-center gap-1 rounded-[6px] border border-red-500/30 bg-red-500/10 px-2.5 py-1 text-red-100 hover:bg-red-500/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-red-400/40 sm:min-h-0",style:{fontSize:"11.5px"},children:[t.jsx(ar,{className:"h-3 w-3","aria-hidden":"true"}),"Retry"]})]})}function Xr(){return t.jsxs("div",{className:"mt-6 rounded-[8px] border border-dashed border-white/10 bg-white/[0.02] px-6 py-10 text-center",role:"status","aria-live":"polite",children:[t.jsx("div",{className:"mx-auto inline-flex h-10 w-10 items-center justify-center rounded-full bg-white/[0.04] text-gray-400",children:t.jsx(Ut,{className:"h-4 w-4","aria-hidden":"true"})}),t.jsx("h3",{className:"mt-3 text-white",style:{fontSize:"14px",fontWeight:600},children:"Drop a file, coming soon"}),t.jsx("p",{className:"mx-auto mt-2 max-w-[360px] text-gray-500",style:{fontSize:"12.5px",lineHeight:1.5},children:"Drop a PDF, audio, or image to extract a character. Coming in v2."})]})}function _t({children:e}){return t.jsx("kbd",{className:"inline-flex items-center rounded border border-white/10 bg-white/[0.04] px-1.5 py-0.5 text-[10.5px] text-gray-400",style:{fontFamily:"inherit"},children:e})}function Nt(){if(typeof navigator>"u")return!0;const e=navigator.userAgent||"";return/Mac|iPhone|iPad|iPod/i.test(e)}function Zr({description:e,progress:a,isSlow:i=!1,errorMessage:n,onRetry:l,onEditRaw:p}){const u=typeof n=="string"&&n.length>0;return t.jsxs(L.section,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},exit:{opacity:0,y:-8},transition:{duration:.3,ease:[.16,1,.3,1]},className:"relative mx-auto w-full max-w-[540px] px-4",role:"status","aria-live":"polite","aria-busy":!u,children:[t.jsxs("div",{className:"text-center",children:[t.jsx("h1",{className:"text-white",style:{fontSize:"28px",fontWeight:600,letterSpacing:"-0.02em",lineHeight:1.2},children:u?"Something snagged.":"Bringing your character to lifeâ¦"}),t.jsx("p",{className:"mx-auto mt-3 max-w-[460px] text-gray-500",style:{fontSize:"13.5px",lineHeight:1.55},"data-testid":"generating-subtitle",children:u?n:i?"Still working. This one is taking longer than usual, so give it a few more seconds. If it does not land we will say so rather than leave you here.":"Weâre drafting the persona, greeting, image, and tags. Hang tight."})]}),t.jsxs("div",{className:"relative mx-auto mt-8 overflow-hidden",style:{background:"rgb(var(--surface-1))",border:"1px solid rgb(var(--hairline))",borderRadius:"14px",padding:"20px"},children:[t.jsxs("p",{className:"text-gray-400",style:{fontSize:"13px",lineHeight:1.55,fontStyle:"italic"},children:["â",e,"â"]}),t.jsx("div",{className:"mt-5 flex flex-wrap",style:{gap:"8px"},children:a.map(g=>t.jsx(ea,{item:g},g.stage))}),!u&&t.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0","aria-hidden":"true",children:t.jsx(ta,{})})]}),u&&t.jsxs("div",{className:"mt-5 flex flex-wrap justify-center",style:{gap:"8px"},children:[l&&t.jsx("button",{type:"button",onClick:l,className:b("inline-flex items-center rounded-[6px] font-semibold","bg-white text-black transition-colors","hover:bg-white/90","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40"),style:{fontSize:"12.5px",padding:"8px 16px",borderRadius:"6px"},children:"Try again"}),p&&t.jsx("button",{type:"button",onClick:p,className:b("inline-flex items-center rounded-[6px]","border border-white/10 bg-white/[0.03] text-gray-300","transition-colors hover:bg-white/[0.06] hover:text-white","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40"),style:{fontSize:"12.5px",padding:"8px 16px",borderRadius:"6px"},children:"Edit raw"})]})]},"generating")}function ea({item:e}){const{status:a,label:i}=e;let n,l,p;return a==="done"?(n=t.jsx(At,{className:"h-3 w-3 text-emerald-400","aria-hidden":"true"}),l="text-white",p="border-emerald-500/40 bg-emerald-500/10"):a==="active"?(n=t.jsx(fe,{className:"h-3 w-3 animate-spin text-blue-400","aria-hidden":"true"}),l="text-white",p="border-blue-500/40 bg-blue-500/10"):(n=t.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-gray-700","aria-hidden":"true"}),l="text-gray-500",p="border-white/5 bg-white/[0.02]"),t.jsxs("span",{className:b("inline-flex items-center gap-1.5 rounded-[6px] border",p,l),style:{fontSize:"11.5px",padding:"5px 10px",letterSpacing:"0.01em"},children:[n,t.jsx("span",{children:i})]})}function ta(){return t.jsx(L.div,{initial:{x:"-30%"},animate:{x:"130%"},transition:{duration:1.6,ease:"linear",repeat:1/0}
3,style:{height:"1.5px",width:"30%",background:"linear-gradient(90deg, transparent, rgba(59,130,246,0.7), transparent)"}})}const Ht={name:40,title:80,description:220,persona:6e3,greeting:4096},Oe={name:"Name",title:"Title",description:"Pitch",persona:"Persona / system prompt",greeting:"Greeting"};function ra({draft:e,onChange:a,onSaveDraft:i,onPublish:n,onChat:l,onRegenerate:p,focusRequest:u=null,onUploadImage:g,isUploadingImage:v=!1,isRegeneratingImage:C=!1,isPortraitPending:j=!1,isSaving:y=!1,isPublishing:A=!1,pendingAction:E=null,visibility:U,onVisibilityChange:I}){const[d,m]=o.useState(null),[P,$]=o.useState(""),[G,W]=o.useState(!1),de=o.useRef(null),ue=S("character_create_saved_as_draft"),Ke=S("character_create_published"),re=S("character_create_started_chat"),R=S("character_create_image_regenerated"),X=S("character_create_tag_removed"),Z=S("character_create_field_edit_started"),xe=S("character_create_visibility_changed"),B=p?()=>{R({had_prior_image:!!e.imageUrl}),p()}:void 0,$e=x=>{x!==U&&(xe({from:U,to:x}),I(x))},ae=e.persona.trim().length===0;o.useEffect(()=>{if(!u)return;m(u.field),u.field==="persona"&&W(!0);const x=requestAnimationFrame(()=>{var M;(M=de.current)==null||M.scrollIntoView({behavior:"smooth",block:"center"})});return()=>cancelAnimationFrame(x)},[u]);const ie=o.useCallback((x,M)=>{const ne=Ht[x],se={...e,tags:[...e.tags],[x]:M.slice(0,ne)};a(se)},[e,a]),J=o.useCallback(x=>{X({tag:x,tag_count_after:e.tags.length-1});const M={...e,tags:e.tags.filter(ne=>ne!==x)};a(M)},[e,a]),Be=o.useCallback(x=>{const M=x.trim().slice(0,24);if(!M||e.tags.some(se=>se.toLowerCase()===M.toLowerCase())||e.tags.length>=6)return;const ne={...e,tags:[...e.tags,M]};a(ne),$("")},[e,a]),Y=e.imageData??e.imageUrl;return t.jsx(L.section,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},transition:{duration:.35,ease:[.16,1,.3,1]},className:"mx-auto w-full max-w-[920px] px-4",children:t.jsxs("div",{className:"grid grid-cols-1 gap-6 md:grid-cols-[1fr_280px]",children:[t.jsxs("div",{className:"overflow-hidden",style:{background:"rgb(var(--surface-1))",border:"1px solid rgb(var(--hairline))",borderRadius:"16px"},children:[t.jsxs("div",{className:"flex flex-col gap-5 p-6 md:flex-row",children:[t.jsxs("div",{className:"flex shrink-0 flex-col items-center gap-2",children:[t.jsx(ia,{imageSrc:Y,name:e.name,icon:e.icon,imageError:e.imageError,onRegenerate:j?void 0:B,isRegenerating:C,isPending:j}),t.jsx(oa,{onUpload:g,onRegenerate:B,isUploading:v||C||j})]}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx(St,{value:e.name,field:"name",editing:d==="name",onEditStart:()=>m("name"),onEditEnd:()=>m(null),onChange:x=>ie("name",x),size:"title"}),t.jsx(St,{value:e.title,field:"title",editing:d==="title",onEditStart:()=>m("title"),onEditEnd:()=>m(null),onChange:x=>ie("title",x),size:"subtitle"}),t.jsxs("div",{className:"mt-4",children:[t.jsx(Ge,{children:"Pitch"}),t.jsx(st,{value:e.description,editing:d==="description",onEditStart:()=>m("description"),onEditEnd:()=>m(null),onChange:x=>ie("description",x),rows:2,placeholder:"A 1-2 sentence pitch"})]}),t.jsxs("div",{className:"mt-4",ref:de,children:[t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx(Ge,{children:Oe.persona}),e.persona.length>220&&t.jsx("button",{type:"button",onClick:()=>W(x=>!x),className:"text-blue-400 hover:text-blue-300",style:{fontSize:"11.5px"},children:G?"Collapse":"Expand"})]}),d==="persona"?t.jsx(st,{value:e.persona,editing:!0,onEditStart:()=>m("persona"),onEditEnd:()=>m(null),onChange:x=>ie("persona",x),rows:14,placeholder:"Detailed system prompt"}):t.jsx("button",{type:"button","data-testid":"persona-display",onClick:()=>{Z({field:"persona"}),m("persona")},className:b("group block w-full cursor-text rounded-[6px] border border-transparent","p-2 text-left text-gray-300 transition-colors","hover:border-white/10 hover:bg-white/[0.02]",ae&&"border-amber-400/40 bg-amber-400/[0.04]"),style:{fontSize:"13px",lineHeight:1.55},children:t.jsx("span",{className:"whitespace-pre-wrap",children:ae?t.jsx("span",{"data-testid":"persona-placeholder",className:"text-amber-200/75",children:"Required. Write the instructions that tell this character how to speak and behave. Remixing does not copy the original persona, so this
3starts empty and is yours to write."}):G||e.persona.length<=220?e.persona:`${e.persona.slice(0,220).trimEnd()}â¦`})})]}),t.jsxs("div",{className:"mt-4",children:[t.jsx(Ge,{children:Oe.greeting}),t.jsx(st,{value:e.greeting,editing:d==="greeting",onEditStart:()=>m("greeting"),onEditEnd:()=>m(null),onChange:x=>ie("greeting",x),rows:2,placeholder:"Opening line in character"})]}),t.jsxs("div",{className:"mt-4",children:[t.jsx(Ge,{children:"Tags"}),t.jsxs("div",{className:"mt-1 flex flex-wrap",style:{gap:"6px"},children:[e.tags.map(x=>t.jsxs("span",{className:"inline-flex items-center gap-1 rounded-[6px] border border-white/10 bg-white/[0.04] text-gray-300",style:{fontSize:"11.5px",padding:"4px 10px"},children:[x,t.jsx("button",{type:"button","aria-label":`Remove tag ${x}`,onClick:()=>J(x),className:"text-gray-500 hover:text-white",children:t.jsx(ir,{className:"h-3 w-3","aria-hidden":"true"})})]},x)),e.tags.length<6&&t.jsx(aa,{value:P,onChange:$,onCommit:()=>Be(P)})]})]})]})]}),t.jsxs("div",{className:"border-t border-white/5 px-5 pt-5",style:{background:"#0a0c10"},children:[t.jsx("p",{className:"mb-3 text-gray-500",style:{fontSize:"10.5px",letterSpacing:"0.08em",textTransform:"uppercase",fontWeight:600},children:"Who can see this?"}),t.jsx(ua,{value:U,onChange:$e})]}),t.jsxs("div",{className:"flex flex-col gap-3 p-5 sm:flex-row sm:items-center sm:justify-end",style:{background:"#0a0c10"},children:[t.jsx("button",{type:"button",onClick:()=>{ue({visibility:U,tag_count:e.tags.length,persona_chars:e.persona.length,has_image:!!e.imageUrl}),i()},disabled:y||A,className:b("inline-flex h-11 items-center justify-center rounded-[6px] px-5","border border-white/10 bg-transparent text-gray-300","transition-colors hover:bg-white/[0.04] hover:text-white","disabled:cursor-not-allowed disabled:opacity-50","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40"),style:{fontSize:"13px",fontWeight:500},children:y?"Savingâ¦":"Save as draft"}),t.jsx("button",{type:"button",onClick:()=>{Ke({visibility:U,tag_count:e.tags.length,persona_chars:e.persona.length,has_image:!!e.imageUrl}),n()},disabled:y||A||j,title:j?"The portrait is still painting. Publish unlocks the moment it lands.":void 0,className:b("inline-flex h-11 items-center justify-center rounded-[6px] px-5","border border-white/10 bg-transparent text-gray-300","transition-colors hover:bg-white/[0.04] hover:text-white","disabled:cursor-not-allowed disabled:opacity-50","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40"),style:{fontSize:"13px",fontWeight:500},children:A&&E==="publish"?"Publishingâ¦":"Publish"}),l&&t.jsx("button",{type:"button",onClick:()=>{re({visibility:U,has_image:!!e.imageUrl}),l()},disabled:y||A||j,title:j?"The portrait is still painting. Chat unlocks the moment it lands.":void 0,className:b("inline-flex h-11 items-center justify-center rounded-[6px] px-6","font-semibold text-white shadow-lg shadow-purple-500/20","brand-gradient transition-colors","disabled:cursor-not-allowed disabled:opacity-60","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-purple-500/60"),style:{fontSize:"13px"},children:A&&E==="chat"?"Publishingâ¦":"Chat â"})]})]}),t.jsxs("aside",{"aria-label":"How your character will look on the explore page",children:[t.jsx("p",{className:"mb-2 text-gray-500",style:{fontSize:"11px",letterSpacing:"0.08em",textTransform:"uppercase"},children:"Tile preview"}),t.jsx(ca,{name:e.name,title:e.title,tags:e.tags,imageSrc:Y,icon:e.icon}),t.jsx("p",{className:"mt-3 text-gray-600",style:{fontSize:"11.5px",lineHeight:1.5},children:"This is how your character appears in the Explore grid and on your public Hub. Click any field to edit."})]})]})},"preview")}function Ge({children:e}){return t.jsx("span",{className:"block text-gray-500",style:{fontSize:"10.5px",letterSpacing:"0.08em",textTransform:"uppercase",fontWeight:600},children:e})}function St({value:e,field:a,editing:i,onEditStart:n,onEditEnd:l,onChange:p,size:u}){const g=u==="title";return i?t.jsx("input",{type:"text",value:e,autoFocus:!0,maxLength:Ht[a],onChange:v=>p(v.target.value),onBlur:l,onKeyDown:v=>{(v.key==="Enter"||v.key==="Escape")&&(v.preventDefault(),l())},"aria-label":Oe[a],className:b("block w-full rounded-[6px] border border-blue-500/60 bg-black/40 outline-none","px-2 py-1 text-white"),style:{fontSize:g?"22px":"13px",fontWeight:g?600:500,letterSpacing:g?"-0.01em":"0",color:g?"#fff":"#a855f7"}}):t.jsxs("button",{type:"button",onClick:n,"aria-label":`Edit ${Oe[a].toLowerCase()}`,className:b("group inline-flex w-full items-center gap-1.5 rounded-[6px] border border-transparent","px-2 py-1 text-left transition-colors","hover:border-white/10 hover:bg-white/[0.02]"),style:{marginLeft:"-0.5rem"},children:[t.jsx("span",{style:{fontSize:g?"22px":"13px",fontWeight:g?600:500,letterSpacing:g?"-0.01em":"0",color:g?"#fff":"#a855f7",lineHeight:1.3},children:e||(g?"Untitled":"Add a tagline")}),t.jsx(Dr,{className:"h-3 w-3 text-white/60 opacity-0 transition-opacity group-hover:opacity-100","aria-hidden":"true"})]})}function st({value:e,editing:a,onEditStart:i,onEditEnd:n,onChange:l,rows:p,placeholder:u}){return a?t.jsx("textarea",{value:e,autoFocus:!0,rows:p,onChange:g=>l(g.target.value),onBlur:n,onKeyDown:g=>{g.key==="Escape"&&(g.preventDefault(),n())},placeholder:u,className:b("block w-full resize-y rounded-[6px] border border-blue-500/60 bg-black/40","px-3 py-2 text-white outline-none"),style:{fontSize:"13px",lineHeight:1.55}}):t.jsx("button",{type:"button",onClick:i,className:b("block w-full cursor-text rounded-[6px] border border-transparent","p-2 text-left text-gray-300 transition-colors","hover:border-white/10 hover:bg-white/[0.02]"),style:{fontSize:"13px",lineHeight:1.55},children:t.jsx("span",{className:"whitespace-pre-wrap",children:e||u})})}
3function aa({value:e,onChange:a,onCommit:i}){return t.jsxs("span",{className:"inline-flex items-center gap-1 rounded-[6px] border border-dashed border-white/15 bg-transparent",children:[t.jsx(Dt,{className:"ml-2 h-3 w-3 text-gray-600","aria-hidden":"true"}),t.jsx("input",{type:"text",value:e,maxLength:24,onChange:n=>a(n.target.value),onKeyDown:n=>{(n.key==="Enter"||n.key===",")&&(n.preventDefault(),i())},onBlur:()=>{e.trim()&&i()},placeholder:"add tag","aria-label":"Add tag",className:"bg-transparent text-gray-300 outline-none placeholder:text-gray-600",style:{fontSize:"11.5px",padding:"4px 10px 4px 4px",width:"82px"}})]})}function ia({imageSrc:e,name:a,icon:i,imageError:n,onRegenerate:l,isRegenerating:p=!1,isPending:u=!1}){return t.jsxs("div",{className:"relative flex shrink-0 items-center justify-center overflow-hidden",style:{width:"180px",height:"180px",borderRadius:"14px",background:Gt(a),border:"1px solid rgba(255,255,255,0.06)"},children:[e?t.jsx("img",{src:e,alt:`${a} portrait`,className:"h-full w-full object-cover",loading:"eager",decoding:"async"}):t.jsxs("div",{className:"flex flex-col items-center gap-2 px-3 text-center",role:u?"status":void 0,"aria-live":u?"polite":void 0,children:[u?t.jsx(fe,{className:"h-6 w-6 animate-spin text-white/80","aria-hidden":"true"}):t.jsx("span",{className:"text-4xl","aria-hidden":"true",children:i}),u?t.jsx("span",{className:"text-[10.5px] text-white/80",children:"Painting the portraitâ¦"}):n?t.jsx("span",{className:"text-[10.5px] text-rose-300",children:"Image failed"}):t.jsx("span",{className:"text-[10.5px] text-white/70",children:"No image yet"})]}),l&&t.jsxs("button",{type:"button",onClick:l,disabled:p,"aria-label":"Regenerate image",className:b("absolute bottom-2 right-2 inline-flex items-center gap-1 rounded-[6px]","bg-black/60 px-2 py-1 text-white/90 backdrop-blur","transition-colors hover:bg-black/80","disabled:cursor-not-allowed disabled:opacity-70","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40"),style:{fontSize:"10.5px"},children:[p?t.jsx(fe,{className:"h-3 w-3 animate-spin","aria-hidden":"true"}):t.jsx(Ar,{className:"h-3 w-3","aria-hidden":"true"}),p?"Generatingâ¦":"Regenerate"]}),p&&t.jsxs("div",{className:"absolute inset-0 flex flex-col items-center justify-center gap-2 text-white",style:{background:"rgba(0,0,0,0.55)",backdropFilter:"blur(2px)"},children:[t.jsx(fe,{className:"h-6 w-6 animate-spin","aria-hidden":"true"}),t.jsx("span",{style:{fontSize:"11px"},children:"Painting portraitâ¦"})]})]})}const na="image/jpeg,image/png,image/webp",sa=5*1024*1024;function oa({onUpload:e,onRegenerate:a,isUploading:i}){const[n,l]=o.useState(!1),[p,u]=o.useState(""),[g,v]=o.useState(null),C=o.useRef(null),j=o.useCallback(()=>{l(!1),u(""),v(null)},[]),y=o.useCallback(async I=>{if(e){u("");try{await e(I),j()}catch(d){const m=d instanceof Error?d.message:"Upload failed.";u(m)}}},[j,e]),A=o.useCallback(async I=>{var P;const d=(P=I.target.files)==null?void 0:P[0];if(I.target.value="",!d||!e)return;const m=d.type.toLowerCase();if(m!=="image/jpeg"&&m!=="image/png"&&m!=="image/webp"){u("Pick a JPEG, PNG, or WebP image.");return}if(d.size>sa){u("Image must be under 5 MB.");return}v(d),await y(d)},[e,y]),E=o.useCallback(()=>{g&&y(g)},[g,y]),U=typeof a=="function";return t.jsxs(t.Fragment,{children:[t.jsx("button",{type:"button",onClick:()=>l(!0),"data-testid":"cta-change-character-image",className:b("inline-flex items-center justify-center rounded-[6px]","border border-white/15 bg-transparent text-gray-300","transition-colors hover:border-[#c4a04a]/70 hover:text-[#f0e6cf]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#c4a04a]/40"),style:{fontSize:"12px",padding:"6px 12px",fontWeight:500},children:"Change image"}),n&&t.jsx(la,{onClose:j,onPickUpload:()=>{var I;return(I=C.current)==null?void 0:I.click()},onRegenerate:U?()=>{a==null||a(),j()}:void 0,isUploading:i,error:p,onRetry:g?E:void 0}),t.jsx("input",{ref:C,type:"file",accept:na,onChange:A,className:"hidden","aria-hidden":"true",tabIndex:-1,"data-testid":"input-character-image-file"})]})}function la({onClose:e,onPickUpload:a,onRegenerate:i,isUploading:n,error:l,onRetry:p}){return t.jsx(or,{open:!0,onOpenChange:u=>{u||e()},children:t.jsx(lr,{className:"block w-full max-w-[420px] overflow-hidden rounded-[8px] border-hairline bg-surface-1 p-0",children:t.jsxs("div",{className:"p-6",children:[t.jsx(cr,{className:"text-white",style:{fontSize:"16px",fontWeight:600,letterSpacing:"-0.01em"},children:"Change image"}),t.jsx(dr,{className:"mt-1 text-gray-400",style:{fontSize:"12.5px",lineHeight:1.5},children:"Upload your own portrait, or regenerate the AI image."}),t.jsxs("div",{className:"mt-5 flex flex-col gap-2",children:[t.jsxs("button",{type:"button",onClick:a,disabled:n,"data-testid":"cta-upload-character-image",className:b("flex w-full items-center gap-3 rounded-[8px] border p-4 text-left transition-colors","border-hairline bg-[#15171c] hover:border-[#c4a04a]/60 hover:bg-[#1a1d24]","disabled:cursor-not-allowed disabled:opacity-60","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#c4a04a]/40"),children:[t.jsx("div",{className:"grid h-9 w-9 shrink-0 place-items-center rounded-[8px]",style:{background:"#1f232b"}
3,children:t.jsx(Ur,{className:"h-4 w-4 text-gray-200","aria-hidden":"true"})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"text-white",style:{fontSize:"13px",fontWeight:600},children:n?"Uploadingâ¦":"Upload image"}),t.jsx("p",{className:"text-white/55",style:{fontSize:"11.5px",lineHeight:1.4},children:"JPEG, PNG, or WebP. 5 MB max."})]})]}),t.jsxs("button",{type:"button",onClick:i,disabled:!i||n,"data-testid":"cta-regenerate-character-image",title:i?"Generate a new AI image":"AI regeneration coming soon",className:b("flex w-full items-center gap-3 rounded-[8px] border p-4 text-left transition-colors","border-hairline bg-[#15171c]",i?"hover:border-[#c4a04a]/60 hover:bg-[#1a1d24]":"cursor-not-allowed opacity-50","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#c4a04a]/40"),children:[t.jsx("div",{className:"grid h-9 w-9 shrink-0 place-items-center rounded-[8px]",style:{background:"#1f232b"},children:t.jsx(ur,{className:"h-4 w-4 text-gray-200","aria-hidden":"true"})}),t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"text-white",style:{fontSize:"13px",fontWeight:600},children:"Generate with AI"}),t.jsx("p",{className:"text-white/55",style:{fontSize:"11.5px",lineHeight:1.4},children:i?"Roll a new portrait from your description.":"Coming soon."})]})]})]}),l&&t.jsxs("div",{className:"mt-3",children:[t.jsx("p",{role:"alert",className:"text-rose-300",style:{fontSize:"12px",lineHeight:1.5},children:l}),p&&t.jsx("button",{type:"button",onClick:p,disabled:n,"data-testid":"cta-retry-character-image-upload",className:b("mt-2 inline-flex h-9 items-center gap-1.5 rounded-[6px] px-3.5","border border-white/15 bg-transparent text-gray-200","transition-colors hover:border-[#c4a04a]/70 hover:text-[#f0e6cf]","disabled:cursor-not-allowed disabled:opacity-60","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#c4a04a]/40"),style:{fontSize:"12px",fontWeight:500},children:n?"Retryingâ¦":"Try again"})]})]})})})}function ca({name:e,title:a,tags:i,imageSrc:n,icon:l}){return t.jsxs("div",{className:"relative overflow-hidden",style:{background:n?"#000":Gt(e),border:"1px solid rgb(var(--hairline))",borderRadius:"14px",aspectRatio:"1"},children:[n?t.jsx("img",{src:n,alt:"","aria-hidden":"true",className:"absolute inset-0 h-full w-full object-cover opacity-90"}):t.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:t.jsx("span",{className:"text-5xl","aria-hidden":"true",children:l})}),t.jsx("div",{className:"absolute inset-0",style:{background:"linear-gradient(180deg, transparent 40%, rgba(8,9,11,0.92) 100%)"}}),t.jsxs("div",{className:"absolute inset-x-0 bottom-0 p-3",children:[t.jsx("p",{className:"truncate font-semibold text-white",style:{fontSize:"14px",letterSpacing:"-0.01em"},children:e||"Untitled"}),a&&t.jsx("p",{className:"mt-0.5 truncate text-white/70",style:{fontSize:"11.5px"},children:a}),i.length>0&&t.jsx("div",{className:"mt-1.5 flex flex-wrap",style:{gap:"4px"},children:i.slice(0,2).map(p=>t.jsx("span",{className:"rounded-[6px] bg-white/15 text-white",style:{fontSize:"10px",padding:"2px 7px",backdropFilter:"blur(4px)"},children:p},p))})]})]})}const da=[{value:"private",icon:nr,label:"Just me",description:"Private. Only you can see and chat with this. It will not appear on your public Hub.",testId:"visibility-private"},{value:"unlisted",icon:Pe,label:"Anyone with link",description:"Unlisted. Anyone with the link can chat. Not shown on your public Hub or in Explore.",testId:"visibility-unlisted"},{value:"public",icon:sr,label:"Public catalog",description:"Live on your public Hub and submitted to the Explore community catalog. Reviewed within 24h.",testId:"visibility-public"}];function ua({value:e,onChange:a}){return t.jsx("div",{role:"radiogroup","aria-label":"Visibility",className:"grid gap-3 sm:grid-cols-3",children:da.map(i=>{const n=i.icon,l=e===i.value;return t.jsxs("button",{type:"button",role:"radio","aria-checked":l,"data-testid":i.testId,onClick:()=>a(i.value),className:b("group flex min-h-[112px] flex-col gap-1.5 rounded-[8px] border p-4 text-left transition-all",l?"border-brand bg-gradient-to-b from-brand/10 to-surface-2 shadow-[0_0_0_3px_rgba(59,130,246,0.18),0_0_24px_rgba(59,130,246,0.18)]":"border-hairline bg-surface-2 hover:border-brand/60 hover:bg-[#1a1d24]","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/60"),
3children:[t.jsx("div",{className:"grid h-8 w-8 place-items-center rounded-[8px]",style:{background:l?"rgba(59,130,246,0.22)":"rgb(var(--hairline))"},children:t.jsx(n,{className:"h-4 w-4",style:{color:l?"#93c5fd":"#a1a1aa"},"aria-hidden":"true"})}),t.jsx("div",{className:"text-white",style:{fontSize:"13px",fontWeight:600},children:i.label}),t.jsx("p",{className:"text-white/55",style:{fontSize:"11.5px",lineHeight:1.45},children:i.description})]},i.value)})})}const Gt=Rr;function Ct(e){switch(e){case"budget_ceiling":return"Portraits are paused for today. Your character is saved, so you can add one tomorrow or upload your own now.";case"visitor_allowance":return"You have used today's portraits. Sign up for more, or upload your own image now.";case"not_configured":return"Portraits are unavailable right now. Your character is saved and you can upload your own image.";case"provider_unavailable":case"unknown":default:return"That did not render. Your character is saved, so you can try again or upload your own image."}}const pa="aianyone:character-create:draft:";function dt(e){return`${pa}${e}`}function ha(){if(typeof window>"u")return"";const e=new URLSearchParams(window.location.search).get("seed");return e!==null&&e.trim().length>0?e.trim().slice(0,500):""}function We(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Et(e){return e===0?0:Date.now()-e}function ma(e){return e==="timeout"?"That took longer than it should have. Nothing was charged and your description is still here, so it is worth one more try.":"Something snagged while writing your character. Your description is still here, so it is worth one more try."}function Tt(e){const a=e==null?void 0:e.reason;return typeof a=="string"&&["budget_ceiling","visitor_allowance","provider_unavailable","not_configured","unknown"].includes(a)?a:"unknown"}function Pt(e){if(typeof window>"u")return null;try{const a=window.localStorage.getItem(dt(e));if(!a)return null;const i=JSON.parse(a);return!i||typeof i!="object"||typeof i.name!="string"||i.name.trim().length===0?null:{name:i.name,title:typeof i.title=="string"?i.title:"",description:typeof i.description=="string"?i.description:"",persona:typeof i.persona=="string"?i.persona:"",greeting:typeof i.greeting=="string"?i.greeting:"",tags:Array.isArray(i.tags)?i.tags.filter(n=>typeof n=="string"):[],icon:typeof i.icon=="string"?i.icon:"ð¤",theme:typeof i.theme=="string"?i.theme:"default",category:typeof i.category=="string"?i.category:"",imageUrl:typeof i.imageUrl=="string"?i.imageUrl:void 0,imageData:typeof i.imageData=="string"?i.imageData:void 0,imagePrompt:typeof i.imagePrompt=="string"?i.imagePrompt:void 0,imageError:typeof i.imageError=="string"?i.imageError:void 0}}catch(a){return console.warn("[character-create] Failed to restore saved draft:",a),null}}function ga(e,a){if(!(typeof window>"u"))try{window.localStorage.setItem(dt(e),JSON.stringify(a))}catch(i){console.warn("[character-create] Failed to persist draft:",i)}}function It(e){if(!(typeof window>"u"))try{window.localStorage.removeItem(dt(e))}catch{}}const fa=2400,xa=3e4,ba=9e4,ya=1500,wa=10*6e4,va=10*6e4,ja=5*1024*1024,ka=["image/jpeg","image/png","image/webp"],_a=3e4;function Na(e){const a=e&&typeof e=="object"?e:{};if((typeof a.name=="string"?a.name:void 0)==="AbortError")return{reason:"timeout",message:"The upload took too long and stopped. Check your connection, then try again."};const n=typeof a.status=="number"?a.status:void 0,l=typeof a.code=="string"?a.code:void 0;if(typeof n=="number"){const p=typeof a.error=="string"?a.error:void 0;return{reason:"server",status:n,code:l,message:n>=500?"Something went wrong on our end. Please try again in a moment.":p||"That image could not be uploaded. Please try another one."}}return e instanceof TypeError?{reason:"network",message:"We couldn't reach the server. Check your connection, then try again."}:{reason:"unknown",message:"The upload failed. Please try again."}}function Sa(e){return new Promise((a,i)=>{const n=new FileReader;n.onerror=()=>i(new Error("Could not read file.")),n.onload=()=>{const l=n.result;if(typeof l!="string"){i(new Error("Could not read file."));return}a(l)},n.readAsDataURL(e)})}function Rt(e){return typeof e!="string"||e.length===0?null:/^https?:\/\//i.test(e)||e.startsWith("/objects/public/")?e:null}function Ca(){try{return window.localStorage.getItem("ai-anyone-session-id")??""}catch{return""}}function Ea(e){const a=e.replace(/\[\d+\].*$/,"");return{name:"name",title:"title",description:"description",greeting:"greeting",callGreeting:"greeting",systemPrompt:"persona"}[a]??null}function Ta(e){const a=e.replace(/\[\d+\].*$/,"");return{name:"the name",title:"the title",description:"the pitch",greeting:"the greeting",callGreeting:"the call greeting",systemPrompt:"the persona",uniqueIntro:"the intro",uniqueStarters:"the starters",uniqueFaqs:"the FAQs",metaDescription:"the meta description",tags:"the tags"}[a]??a}function di(){var ft,xt;const{user:e,isLoading:a}=pr(),[,i]=hr(),{toast:n}
3=mr(),[l,p]=o.useState(ha),[u,g]=o.useState("input"),v=S("char_create_generate_attempted"),C=S("char_create_retry_clicked"),j=S("char_create_edit_raw_clicked"),y=S("char_create_start_new_clicked"),A=S("char_create_save_draft_clicked"),E=S("char_create_publish_clicked"),U=o.useRef(null);o.useEffect(()=>{var r;u!=="input"&&((r=U.current)==null||r.focus())},[u]);const I=u==="generating"?"Generating your character. Please wait.":u==="preview"?"Your character is ready to preview and edit.":u==="published"?"Your character is published.":"Describe the character you want to create.",[d,m]=o.useState(null),[P,$]=o.useState(null),[G,W]=o.useState(it),[de,ue]=o.useState(""),[Ke,re]=o.useState(!1),R=o.useRef(null),X=o.useRef(0),[Z,xe]=o.useState(null),[B,$e]=o.useState("private"),[ae,ie]=o.useState(null),[J,Be]=o.useState(null),[Y,x]=o.useState(null),[M,ne]=o.useState(""),[se,Wt]=o.useState(null),Je=o.useRef(!1),q=o.useRef(null),Ye=o.useRef("redirect"),[Ot,qe]=o.useState(null),D=o.useRef(null),V=o.useRef(0),F=o.useRef(null),z=o.useRef(null),Ie=o.useRef(""),w=o.useMemo(()=>gr((e==null?void 0:e.id)??null),[e==null?void 0:e.id]),[be,ye]=o.useState(null),pe=o.useRef(null),Re=o.useRef(null);o.useEffect(()=>{const r=document.documentElement.classList.contains("dark");return r||document.documentElement.classList.add("dark"),document.body.style.background="rgb(var(--surface-0))",()=>{r||document.documentElement.classList.remove("dark"),document.body.style.background=""}},[]),o.useEffect(()=>{if(typeof window>"u")return;const r=new URLSearchParams(window.location.search),s=r.get("draft");s&&s.trim().length>0&&$(s.trim());const h=r.get("remixFrom");h&&h.trim().length>0&&Be(h.trim())},[]);const we=o.useRef(!1),Kt=at({queryKey:["/api/character-drafts/latest",(e==null?void 0:e.id)??"anon"],queryFn:async()=>{try{return await(await K("GET","/api/character-drafts/latest")).json()}catch{return null}},enabled:!a&&!P,staleTime:1/0,gcTime:5*6e4,retry:!1}),$t=at({queryKey:["/api/character-drafts","by-id",P,(e==null?void 0:e.id)??"anon"],queryFn:async()=>{if(!P)return null;const s=await(await K("GET","/api/character-drafts")).json();return{draft:(Array.isArray(s.drafts)?s.drafts:[]).find(c=>c.id===P)??null}},enabled:!a&&!!P,staleTime:1/0,gcTime:5*6e4,retry:!1}),ut=at({queryKey:["/api/personalities","remix-source",J],queryFn:async()=>{if(!J)return null;const r=await fetch(`/api/personalities/${encodeURIComponent(J)}`,{credentials:"include"});return r.ok?r.json():null},enabled:!!J&&!Je.current,staleTime:1/0,retry:!1});o.useEffect(()=>{if(Je.current)return;const r=ut.data;if(!r||!J)return;Je.current=!0;const s=(c,k="")=>typeof c=="string"?c:k,h=s(r.name,"Character"),f={name:`${h} (remix)`.slice(0,40),title:s(r.title),description:s(r.description),persona:s(r.systemPrompt),greeting:s(r.greeting),tags:Array.isArray(r.tags)?r.tags.filter(c=>typeof c=="string"):[],icon:s(r.icon,"ð¤"),theme:s(r.theme,"default"),category:s(r.category),imageUrl:void 0,imageData:void 0,imagePrompt:void 0};m(f),x(J),ne(h),Wt(typeof r.creatorUsername=="string"?r.creatorUsername:null),g("preview")},[ut.data,J]);const oe=P?$t:Kt,Bt=((xt=(ft=oe.data)==null?void 0:ft.draft)==null?void 0:xt.prompt)??"",Ae=_r({route:"character-create",entity:"description",ownerScope:w,value:l,onRestore:p,serverValue:Bt,serverValueReady:!oe.isPending,ownerScopeReady:!a});o.useEffect(()=>{var h,f;if(we.current||a||d||u!=="input"||oe.isPending)return;if(P&&!((h=oe.data)!=null&&h.draft)){we.current=!0,n({title:"Draft not found",description:"We couldn't find that draft. Starting fresh.",variant:"destructive"});const c=e!=null&&e.id?Pt(e.id):null;c&&(z.current=c,m(c),g("preview"),W(k=>k.map(_=>({..._,status:"done"}))),rt("character_draft_local","restored"));return}const r=((f=oe.data)==null?void 0:f.draft)??null;if(r){if(we.current=!0,D.current=r.id,ye(r.id),kt(N,w,Ce,r.id),V.current=r.regenerationCount??0,Ie.current=r.prompt??"",r.prompt&&p(c=>c.length>0?c:r.prompt.slice(0,500)),r.scaffoldJson&&typeof r.scaffoldJson=="object"){const c=r.scaffoldJson;if(zr(c)){const k={name:typeof c.name=="string"?c.name:"",title:typeof c.title=="string"?c.title:"",description:typeof c.description=="str
3ing"?c.description:"",persona:typeof c.persona=="string"?c.persona:"",greeting:typeof c.greeting=="string"?c.greeting:"",tags:Array.isArray(c.tags)?c.tags.filter(he=>typeof he=="string"):[],icon:typeof c.icon=="string"?c.icon:"ð¤",theme:typeof c.theme=="string"?c.theme:"default",category:typeof c.category=="string"?c.category:"",imageUrl:typeof c.imageUrl=="string"?c.imageUrl:r.imageUrl??void 0,imageData:typeof c.imageData=="string"?c.imageData:void 0,imagePrompt:typeof c.imagePrompt=="string"?c.imagePrompt:void 0,imageError:typeof c.imageError=="string"?c.imageError:void 0},_=ge(k);pe.current=_;const T=Wr(N,w,r.id,_),Q=T?{...k,...T,tags:[...T.tags]}:k;T&&Re.current!==r.id&&(Re.current=r.id,window.setTimeout(()=>je(Q,void 0,{flushMs:0}),0)),z.current=Q,m(Q),g("preview"),W(he=>he.map(ee=>({...ee,status:"done"}))),n({title:"Draft restored",description:"We picked up where you left off."}),rt("character_draft_server","restored");return}}return}we.current=!0;const s=e!=null&&e.id?Pt(e.id):null;s&&(z.current=s,m(s),g("preview"),W(c=>c.map(k=>({...k,status:"done"}))),n({title:"Draft restored",description:"We picked up where you left off."}),rt("character_draft_local","restored"))},[d,a,oe.data,oe.isPending,w,u,P,n,e==null?void 0:e.id]);const Ve=o.useCallback(()=>{W(it),q.current&&clearInterval(q.current);let r=0;q.current=setInterval(()=>{r+=1,W(s=>s.map((f,c)=>c<r?{...f,status:"done"}:c===r?{...f,status:"active"}:{...f,status:"pending"})),r>=it.length-1&&q.current&&(clearInterval(q.current),q.current=null)},fa)},[]),ve=o.useCallback(()=>{q.current&&(clearInterval(q.current),q.current=null)},[]);o.useEffect(()=>()=>ve(),[ve]),o.useEffect(()=>()=>{R.current&&(window.clearTimeout(R.current),R.current=null)},[]);const pt=o.useCallback((r,s)=>{if(!s)return;const h=ge(s);pe.current=h;const f=z.current;jt(N,w,r,h,ge(f??s))},[w]),ht=ce({mutationFn:async r=>{const h=await(await K("POST","/api/character-drafts",r)).json();if(!h.draft)throw new Error("Upsert returned no draft");return h.draft},onSuccess:(r,s)=>{D.current=r.id,ye(r.id),pt(r.id,s.scaffoldJson)},onError:r=>{console.warn("[character-create] Failed to upsert draft to server:",r)}}),De=ce({mutationFn:async({id:r,payload:s})=>{const f=await(await K("PATCH",`/api/character-drafts/${r}`,s)).json();if(!f.draft)throw new Error("Patch returned no draft");return f.draft},onSuccess:(r,s)=>{pt(r.id,s.payload.scaffoldJson)},onError:r=>{console.warn("[character-create] Failed to patch draft on server:",r)}}),Qe=ce({mutationFn:async r=>{await K("DELETE",`/api/character-drafts/${r}`)},onError:r=>{console.warn("[character-create] Failed to delete draft on server:",r)}}),Ue=o.useCallback(()=>{const r=z.current;return r?{prompt:Ie.current,scaffoldJson:r,imageUrl:Rt(r.imageUrl)}:null},[]),je=o.useCallback((r,s,h)=>{z.current=r,F.current&&clearTimeout(F.current);const f=D.current,c=z.current;if(c&&jt(N,w,f??Ce,pe.current??ge(c),ge(c)),!f)return;const k=(s==null?void 0:s.regenerationDelta)??0;k!==0&&(V.current+=k),F.current=setTimeout(()=>{const _=Ue();_&&De.mutate({id:f,payload:_})},(h==null?void 0:h.flushMs)??ya)},[Ue,w,De]);o.useEffect(()=>()=>{F.current&&(clearTimeout(F.current),F.current=null)},[]),o.useEffect(()=>{be&&kt(N,w,Ce,be)},[be,w]),o.useEffect(()=>{const r=()=>{if(!F.current)return;clearTimeout(F.current),F.current=null;const f=D.current;if(!f)return;const c=Ue();if(c)try{fetch(`/api/character-drafts/${f}`,{method:"PATCH",keepalive:!0,credentials:"include",headers:{"Content-Type":"application/json","session-id":Ca()},body:JSON.stringify(c)}).catch(()=>{})}catch{}},s=()=>r(),h=()=>{document.visibilityState==="hidden"&&r()};return window.addEventListener("pagehide",s),document.addEventListener("visibilitychange",h),()=>{window.removeEventListener("pagehide",s),document.removeEventListener("visibilitychange",h)}},[Ue]);const Xe=o.useCallback((r,s=0)=>{if(D.current){je(r);return}if(s>=10){console.warn("[character-create] portrait arrived but no draft row exists to hold it");return}window.setTimeout(()=>Xe(r,s+1),1500)},[je]),O=yt({kind:"portrait",entityKey:be,ownerScope:w,parseResult:r=>r?{imageUrl:typeof r.imageUrl=="string"?r.imageUrl:void 0,imagePrompt:typeof r.imagePrompt=="string"?r.imagePrompt:void 0}:{},onReady:(r,s,h)=>{const f=z.current;if(!f)return;const c={...f,tags:[...f.tags],imageUrl:s.imageUrl??f.imageUrl,imageData:void 0,imagePrompt:s.imagePrompt??f.imagePrompt,imageError:void 0};m(c),z.current=c,Xe(c),N.remove(H(w,"character-create","regen-idem")),me.characterPortraitArrived({job_id:r,outcome:"ready"}),h&&n({title:"Picked up where you left off",description:"Your portrait finished while you were away."})},onFailed:(r,s,h)=>{N.remove(H(w,"character-create","regen-idem")),me.characterPortraitArrived({job_id:r,outcome:"failed",reason:s});const f=z.current;if(!f)return;const c={...f,tags:[...f.tags],imageError:s};
3m(c),z.current=c,Xe(c),n({title:"The portrait did not land",description:Ct(Tt({reason:s})),variant:"destructive"})}}),Fe=o.useRef(null),ke=yt({kind:"persona",entityKey:be,ownerScope:w,parseResult:kr,onReady:(r,s,h)=>{ve(),R.current&&(window.clearTimeout(R.current),R.current=null),re(!1),W(c=>c.map(k=>({...k,status:"done"}))),me.characterGenerateSucceeded({duration_ms:Et(X.current),portrait_skipped:s.portraitJobId===null}),N.remove(H(w,"character-create","generate-idem"));const f=z.current;if(!f||f.name.trim().length===0){const c={name:s.name,title:s.title,description:s.description,persona:s.persona,greeting:s.greeting,tags:[...s.tags],icon:s.icon,theme:s.theme,category:s.category,imageUrl:void 0,imageData:void 0,imagePrompt:void 0,imageError:void 0};m(c),z.current=c,pe.current=ge(c)}s.portraitJobId!==null&&Fe.current!==s.portraitJobId&&(Fe.current=s.portraitJobId,O.track(s.portraitJobId)),window.setTimeout(()=>g("preview"),250),h&&n({title:"Picked up where you left off",description:"Your character was ready when you got back."})},onFailed:(r,s)=>{ve(),R.current&&(window.clearTimeout(R.current),R.current=null),re(!1),me.characterGenerateFailed({duration_ms:Et(X.current),reason:s,is_limit:!1}),N.remove(H(w,"character-create","generate-idem")),ue(ma(s)),g("generating")}});o.useEffect(()=>{ke.pending&&u==="input"&&(X.current===0&&(X.current=Date.now()),g("generating"),Ve())},[ke.pending,u,Ve]);const _e=ce({mutationFn:async r=>{const s=new AbortController,h=window.setTimeout(()=>s.abort(),ba),f=H(w,"character-create","generate-idem"),c=N.get(f,ee=>{if(typeof ee!="object"||ee===null)return null;const Se=Reflect.get(ee,"idempotencyKey"),bt=Reflect.get(ee,"description");return typeof Se=="string"&&typeof bt=="string"?{idempotencyKey:Se,description:bt}:null}),k=c!==null&&c.description===r?c.idempotencyKey:crypto.randomUUID();N.set(f,{idempotencyKey:k,description:r},va);let _;try{_=await K("POST","/api/personalities/generate-from-description",{description:r,generateImage:!0,idempotencyKey:k},{signal:s.signal})}catch(ee){if(s.signal.aborted){const Se=new Error("That took longer than it should have. Nothing was charged and your description is still here, so it is worth one more try.");throw Se.code="client_timeout",Se}throw ee}finally{window.clearTimeout(h)}const T=await _.json(),Q=We(T)&&typeof T.jobId=="string"?T.jobId:null,he=We(T)&&typeof T.draftId=="string"?T.draftId:null;if(Q===null||he===null)throw new Error("The server did not start a character");return{jobId:Q,draftId:he,portraitSkipped:We(T)&&T.portraitSkipped===!0}},onMutate:r=>{ue(""),re(!1),g("generating"),Ve(),Ie.current=r,X.current=Date.now(),R.current&&window.clearTimeout(R.current),R.current=window.setTimeout(()=>re(!0),xa),me.characterGenerateStarted({description_length:r.length})},onSuccess:r=>{D.current=r.draftId,ye(r.draftId),Ae.clear(),r.portraitSkipped&&xe(Hr()),ke.track(r.jobId)},onError:r=>{ve(),R.current&&(window.clearTimeout(R.current),R.current=null),re(!1);const s=(r==null?void 0:r.code)??(r instanceof Error?"error":"unknown");me.characterGenerateFailed({duration_ms:Date.now()-X.current,reason:s,is_limit:wt(r)});const h=wt(r)?r:null;if(h){xe(Mr(h)),g("input"),ue("");return}const f=r instanceof Error?r.message:"Generation failed";ue(f)}}),Jt=o.useCallback(r=>{const s=r.trim();if(s.length<3){v({result:"rejected_too_short",chars:s.length}),n({title:"Add a few more words",description:"We need at least a sentence to work with.",variant:"destructive"});return}v({result:"submitted",chars:s.length,is_first_generate:V.current===0}),_e.mutate(s)},[_e,n,v]),Yt=o.useCallback(()=>{const r=l.trim().length>=3;C({action:r?"regenerate":"return_to_input",description_chars:l.trim().length,regeneration_count:V.current}),r?(V.current+=1,_e.mutate(l.trim())):g("input")},[l,_e,C]),mt=o.useCallback(()=>{j({description_chars:l.trim().length}),g("input"),n({title:"Long-form editor coming soon",description:"For now, edit the description and try again, or tweak fields after generation."})},[n,j,l]),qt=o.useCallback(()=>{if(y({had_draft:!!d,had_server_draft_id:!!D.current,regeneration_count:V.current}),F.current&&(clearTimeout(F.current),F.current=null),e!=null&&e.id&&It(e.id),O.untrack(),ke.untrack(),Fe.current=null,D.current){const r=D.current;Qe.mutate(r),D.current=null,ye(null),Me(N,w,r),N.remove(H(w,"jobs",`portrait:${r}`))}Me(N,w,Ce),N.remove(H(w,"character-create","generate-idem")),we.current=!0,V.current=0,pe.current=null,Re.current=null,z.current=null,m(null),p(""),Ae.clear(),$(null),g("input"),le.removeQueries({queryKey:["/api/character-drafts/latest"]}),le.removeQueries({queryKey:["/api/character-drafts","by-id"]})},[e,Qe,d,w,O.untrack,ke.untrack,Ae.clear,y]),Ne=ce({mutationFn:async r=>{const s={name:r.name.trim(),title:r.title.trim(),description:r.description.trim(),systemPrompt:r.persona.trim(),greeting:r.greeting.trim(),tags:[...r.tags],icon:r.icon||"ð¤",theme:r.theme||"default",category:r.category||void 0,aiImageUrl:r.imageUrl,aiImageData:r.imageData,aiImagePrompt:r.imagePrompt,visibility:B,remixedFromPersonalityId:Y??void 0},h=await K("POST","/api/personalities",s),f=await h.json();
3if(!h.ok||!f.id){const c=new Error(f.message??"Publish failed");throw c.code=f.code,c.upgradeUrl=f.upgradeUrl,c}return f},onSuccess:r=>{F.current&&(clearTimeout(F.current),F.current=null),e!=null&&e.id&&It(e.id),e!=null&&e.id||jr(r.id);const s=D.current;s&&(Qe.mutate(s),D.current=null,ye(null),Me(N,w,s),N.remove(H(w,"jobs",`portrait:${s}`))),N.remove(H(w,"jobs","portrait:unbound")),Me(N,w,Ce),Ae.clear(),p(""),pe.current=null,Re.current=null,le.removeQueries({queryKey:["/api/character-drafts/latest"]}),le.removeQueries({queryKey:["/api/character-drafts","by-id"]}),le.invalidateQueries({queryKey:["/api/personalities"]}),le.invalidateQueries({queryKey:["/api/personalities/by-creator"]}),le.invalidateQueries({queryKey:["/api/hubs"]}),ie(r),Ye.current==="new_tab"?(window.open(`/chat/${r.id}`,"_blank"),n({title:"Published! Chat opened in new tab.",description:`${r.name} is live on your Hub.`}),g("published")):(n({title:"Live on your Hub",description:`${r.name} is published.`}),g("published"))},onError:r=>{var f;const s=r,h=s.code;if(r.upgradeUrl,h==="anon_create_limit"){xe(zt());return}if(h==="CONTENT_BLOCKED"){n({title:"Couldn't publish this character",description:r.message??"Please revise the description and try again. If you think this is a mistake, contact [email protected].",variant:"destructive"});return}if(h==="STACK_DISCLOSURE"||h==="TYPOGRAPHIC_DASH"){const c=Array.isArray(s.leaks)?Array.from(new Set(s.leaks.map(_=>_.field).filter(_=>!!_))):[],k=c.map(Ea).find(_=>!!_);k&&(ze.current+=1,gt({field:k,nonce:ze.current})),n({title:h==="TYPOGRAPHIC_DASH"?"Check the punctuation":"Check the wording",description:`${s.serverMessage??"Please revise and try again."}${c.length?` Look at: ${c.map(Ta).join(", ")}.`:""}`,variant:"destructive"});return}if(h==="PERSONALITY_NAME_TAKEN"){const c=(f=s.existing)==null?void 0:f.chatUrl;n({title:"That name is taken",description:s.serverMessage??"A public character already uses this name.",variant:"destructive",action:c?t.jsx(vr,{altText:"Open the existing character",onClick:()=>i(c),children:"Chat with it"}):void 0});return}n({title:"Couldn't publish",description:s.serverMessage??"Please try again in a moment.",variant:"destructive"})},onSettled:()=>{qe(null)}}),Vt=o.useCallback(()=>{if(!(e!=null&&e.id)){A({result:"blocked_anonymous"}),n({title:"Sign in to save drafts",description:"Drafts are tied to your account. Sign in and try again.",variant:"destructive"});return}if(!d){A({result:"blocked_no_draft"}),n({title:"Nothing to save yet",description:"Generate a character first, then your edits will save."});return}A({result:D.current?"patched":"created",name_chars:d.name.length,persona_chars:d.persona.length,has_image:!!d.imageUrl,tag_count:d.tags.length}),e!=null&&e.id&&ga(e.id,d);const r={prompt:Ie.current||d.description||d.name,scaffoldJson:d,imageUrl:Rt(d.imageUrl)};D.current?De.mutate({id:D.current,payload:r}):ht.mutate(r),n({title:"Draft saved",description:"Find it in /drafts anytime."})},[d,n,e==null?void 0:e.id,De,ht,A]),[Qt,gt]=o.useState(null),ze=o.useRef(0),Le=o.useCallback(r=>{const s=r.name.trim()?r.persona.trim()?null:"persona":"name";return s?(ze.current+=1,gt({field:s,nonce:ze.current}),n(s==="persona"?{title:"Add a persona first",description:"The persona is the instructions that tell this character how to behave. A remix does not copy the original one, so yours starts empty. Opened it for you below.",variant:"destructive"}:{title:"Add a name first",description:"Give the character a name before publishing. Opened it for you below.",variant:"destructive"}),!0):!1},[n]),Xt=o.useCallback(()=>{if(!d){E({intent:"publish",result:"blocked_no_draft"}),n({title:"Nothing to publish yet",description:"Generate a character first.",variant:"destructive"});return}if(O.pending){E({intent:"publish",result:"blocked_portrait_pending"}),n({title:"The portrait is still painting",description:"Publish unlocks the moment it lands, usually within a minute."});return}if(Le(d)){E({intent:"publish",result:"blocked_incomplete",missing_field:d.name.trim()?"persona":"name"});return}E({intent:"publish",result:"submitted",visibility:B,name_chars:d.name.length,persona_chars:d.persona.length,has_image:!!d.imageUrl,tag_count:d.tags.length,is_remix:!!Y}),Ye.current="redirect",qe("publish"),Ne.mutate(d)},[d,O.pending,Ne,Le,n,E,B,Y]),Zt=o.useCallback(()=>
3{if(!d){E({intent:"chat_new_tab",result:"blocked_no_draft"}),n({title:"Nothing to publish yet",description:"Generate a character first.",variant:"destructive"});return}if(O.pending){E({intent:"chat_new_tab",result:"blocked_portrait_pending"}),n({title:"The portrait is still painting",description:"Chat unlocks the moment it lands, usually within a minute."});return}if(Le(d)){E({intent:"chat_new_tab",result:"blocked_incomplete",missing_field:d.name.trim()?"persona":"name"});return}E({intent:"chat_new_tab",result:"submitted",visibility:B,name_chars:d.name.length,persona_chars:d.persona.length,has_image:!!d.imageUrl,tag_count:d.tags.length,is_remix:!!Y}),Ye.current="new_tab",qe("chat"),Ne.mutate(d)},[d,O.pending,Ne,Le,n,E,B,Y]),Ze=o.useCallback(r=>{m(r),je(r)},[je]),et=ce({mutationFn:async r=>{var c;const s=await Sa(r),h=new AbortController,f=setTimeout(()=>h.abort(),_a);try{const _=await(await K("POST","/api/character-drafts/upload-image",{imageBase64:s,mimeType:r.type},{signal:h.signal})).json(),T=(c=_.data)==null?void 0:c.imageUrl;if(!T)throw new Error(_.error??"Upload failed");return T}finally{clearTimeout(f)}}}),er=o.useCallback(async r=>{if(!d){n({title:"Generate a character first",description:"We need a draft before we can swap the image.",variant:"destructive"});return}if(!ka.includes(r.type))throw n({title:"Unsupported image type",description:"Pick a JPEG, PNG, or WebP.",variant:"destructive"}),new Error("Unsupported image type");if(r.size>ja)throw n({title:"Image too large",description:"Image must be under 5 MB.",variant:"destructive"}),new Error("Image too large");try{const s=await ot("char_create_image_uploaded",()=>et.mutateAsync(r),{byte_size:r.size,mime_type:r.type}),h={...d,tags:[...d.tags],imageUrl:s,imageData:void 0,imageError:void 0};Ze(h),n({title:"Image updated",description:"Your portrait is set."})}catch(s){const h=Na(s),f={reason:h.reason,byte_size:r.size,mime_type:r.type,...h.status!==void 0?{status:h.status}:{},...h.code!==void 0?{code:h.code}:{}};throw fr("image_upload_failed",{page:"character-create",...f}),Nr(s,{source:"character-create-portrait-upload",extra:f}),xr.captureException(s,{$exception_source:"character-create-portrait-upload",...f}),n({title:"Couldn't upload image",description:h.message,variant:"destructive"}),new Error(h.message)}},[d,n,et,Ze]),tt=ce({mutationFn:async r=>{const s=H(w,"character-create","regen-idem"),h=N.get(s,_=>{if(typeof _!="object"||_===null)return null;const T=Reflect.get(_,"idempotencyKey"),Q=Reflect.get(_,"draftId");return typeof T=="string"&&typeof Q=="string"?{idempotencyKey:T,draftId:Q}:null}),f=h!==null&&h.draftId===r?h.idempotencyKey:crypto.randomUUID();N.set(s,{idempotencyKey:f,draftId:r},wa);const k=await(await K("POST",`/api/character-drafts/${r}/regenerate-image`,{idempotencyKey:f})).json();if(!We(k)||typeof k.jobId!="string")throw new Error("Regeneration did not start");return{jobId:k.jobId}}}),tr=o.useCallback(async()=>{const r=D.current;if(!r||!d){n({title:"Generate a character first",description:"We need a saved draft before we can re-roll the portrait.",variant:"destructive"});return}try{const s=await ot("char_create_image_regenerated",()=>tt.mutateAsync(r),{draft_id:r,regeneration_count_before:V.current});Fe.current=s.jobId,O.track(s.jobId),V.current+=1}catch(s){const h=Tt(s);n({title:"Couldn't generate a portrait",description:Ct(h),variant:"destructive"})}},[d,n,tt,O]),rr=o.useMemo(()=>e?typeof e.username=="string"&&e.username.length>0?e.username:typeof e.email=="string"&&e.email.length>0?e.email.split("@")[0]:"you":"you",[e]);return t.jsxs(Sr,{children:[t.jsxs("main",{className:"relative min-h-screen text-white antialiased",style:{background:"rgb(var(--surface-0))",fontFamily:"-apple-system, 'Inter', system-ui, sans-serif"},children:[t.jsx("div",{"aria-hidden":"true",className:"pointer-events-none absolute inset-x-0 top-0 -z-0 h-[420px]",style:{background:"radial-gradient(ellipse at 50% 0%, rgba(59,130,246,0.13), transparent 70%)"}}),t.jsx(Ia,{username:rr,draftName:(d==null?void 0:d.name)??"",onBack:()=>i("/"),onStartNew:qt,showStartNew:u!=="input"||d!=null}),t.jsx("div",{"aria-live":"polite",role:"status",className:"sr-only",children:I}),t.jsx("div",{ref:U,tabIndex:-1,"aria-label":I,className:"relative z-10 flex min-h-[calc(100vh-72px)] flex-col items-center justify-center py-12 sm:py-16 outline-none",children:t.jsxs(Ft,{mode:"wait",children:[u==="input"&&t.jsxs(L.div,{initial:{opacity:0}
3,animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"w-full",children:[Z&&t.jsx("div",{"data-testid":"anon-limit-card",className:"mx-auto mb-6 w-full max-w-[540px] px-4",children:t.jsxs(br,{className:"bg-card p-5",children:[t.jsx("h2",{className:"text-[15px] font-semibold text-foreground",children:Z.title}),t.jsx("p",{className:"mt-1.5 text-[13px] leading-[1.55] text-muted-foreground",children:Z.description}),Z.ctaHref&&t.jsx("a",{"data-testid":"anon-limit-cta",href:Z.ctaHref,className:b(yr({size:"lg"}),"mt-3.5"),children:Z.ctaLabel})]})}),t.jsx(Kr,{value:l,onChange:p,onSubmit:Jt,onLongFormShortcut:mt,disabled:_e.isPending,autoFocus:!0})]},"input-stage"),u==="generating"&&t.jsx(L.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"w-full",children:t.jsx(Zr,{description:l,progress:G,isSlow:Ke,errorMessage:de||void 0,onRetry:de?Yt:void 0,onEditRaw:de?mt:void 0})},"generating-stage"),u==="preview"&&d&&t.jsxs(L.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"w-full",children:[Y&&t.jsxs("div",{"data-testid":"banner-remixing",translate:"no",className:"mx-auto mb-3 w-full max-w-[640px] rounded-[8px] border border-purple-400/20 bg-purple-500/[0.07] px-4 py-2.5 text-[13px] text-purple-200",children:["Remixing"," ",se?t.jsxs("span",{className:"text-purple-100",children:["@",se]}):null,se?"'s ":" ",t.jsx("span",{className:"font-semibold text-white",children:M}),". Make it yours, then publish."]}),t.jsx(ra,{draft:d,onChange:Ze,onSaveDraft:Vt,onPublish:Xt,onChat:Zt,onRegenerate:tr,focusRequest:Qt,onUploadImage:er,isUploadingImage:et.isPending,isRegeneratingImage:tt.isPending,isPortraitPending:O.pending,isSaving:!1,isPublishing:Ne.isPending,pen
3dingAction:Ot,visibility:B,onVisibilityChange:$e})]},"preview-stage"),u==="published"&&ae&&t.jsx(L.div,{initial:{opacity:0,y:12},animate:{opacity:1,y:0},exit:{opacity:0},transition:{duration:.25},className:"w-full",children:t.jsx(Pa,{character:ae,onChat:()=>i(`/chat/${ae.id}`),onCreateCourse:()=>i(`/courses/new?teacherId=${ae.id}`)})},"published-stage")]})})]}),t.jsx(wr,{variant:"compact"})]})}function Pa({character:e,onChat:a,onCreateCourse:i}){const[n,l]=o.useState(!1),p=Fr(e),u=typeof window<"u"?`${window.location.origin}/c/${p}`:`https://aianyone.com/c/${p}`,g=e.visibility!=="private",v=S("char_create_share_url_copied"),C=()=>{v({character_id:e.id,visibility:e.visibility}),navigator.clipboard.writeText(u).then(()=>{l(!0),window.setTimeout(()=>l(!1),2e3)}).catch(()=>{})};return t.jsx("section",{"aria-label":"Character published",className:"mx-auto w-full max-w-[640px] px-4",children:t.jsxs("div",{className:"flex flex-col items-center gap-5 rounded-[8px] border border-hairline p-8 text-center",style:{background:"rgb(var(--surface-1))"},children:[t.jsx("span",{className:"inline-flex items-center gap-1.5 rounded-[6px] border border-emerald-400/30 bg-emerald-400/10 px-3 py-1 text-emerald-300",style:{fontSize:"11px",letterSpacing:"0.04em"},children:"â Live on your Hub"}),t.jsxs("h2",{className:"text-white",style:{fontSize:"24px",fontWeight:700,letterSpacing:"-0.01em"},children:[e.name," is published."]}),g?t.jsxs("div",{className:"w-full max-w-[460px]",children:[t.jsxs("p",{className:"mb-2 text-white/55",style:{fontSize:"12.5px"},children:["Share ",e.name,". Anyone with this link starts chatting in one tap."]}),t.jsxs("div",{className:"flex items-stretch gap-2",children:[t.jsx("input",{type:"text",readOnly:!0,value:u,"aria-label":"Shareable link","data-testid":"input-share-link",onFocus:j=>j.currentTarget.select(),className:"min-w-0 flex-1 rounded-[6px] border border-white/10 bg-white/[0.04] px-3 text-left text-white/80",style:{height:"40px",fontSize:"13px"}}),t.jsx("button",{type:"button",onClick:C,"data-testid":"button-copy-share-link","aria-label":"Copy share link",className:b("inline-flex h-10 shrink-0 items-center justify-center gap-1.5 rounded-[6px] px-3.5","border text-[13px] font-medium transition-colors",n?"border-emerald-400/40 bg-emerald-400/10 text-emerald-300":"border-white/10 bg-white/[0.04] text-gray-200 hover:bg-white/[0.08] hover:text-white"),children:n?t.jsxs(t.Fragment,{children:[t.jsx(At,{className:"h-4 w-4","aria-hidden":"true"})," Copied"]}):t.jsxs(t.Fragment,{children:[t.jsx(Pe,{className:"h-4 w-4","aria-hidden":"true"})," Copy link"]})})]})]}):t.jsx("p",{className:"max-w-[440px] text-white/55",style:{fontSize:"12.5px",lineHeight:1.55},children:"This character is private, only you can chat with it. Set it to Public from your Hub to share a link."}),t.jsxs("p",{className:"max-w-[440px] text-white/60",style:{fontSize:"13px",lineHeight:1.55},children:["Want ",e.name," to teach a course? Build a multi-lesson course with this character as the instructor, ready in about a minute."]}),t.jsxs("div",{className:"mt-1 flex w-full flex-col gap-2 sm:flex-row sm:justify-center",children:[t.jsxs("button",{type:"button",onClick:a,"data-testid":"cta-chat-published-character",className:b("inline-flex h-11 items-center justify-center rounded-[6px] px-5","border border-white/10 bg-transparent text-gray-200","transition-colors hover:bg-white/[0.05] hover:text-white","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40"),style:{fontSize:"13px",fontWeight:500},children:["Talk to ",e.name," â"]}),t.jsx("button",{type:"button",onClick:i,"data-testid":"cta-pair-with-course",className:b("inline-flex h-11 items-center justify-center rounded-[6px] px-6","font-semibold text-white shadow-lg shadow-purple-500/25","brand-gradient transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-purple-500/60"),style:{fontSize:"13px"},children:"Pair with a Course â"})]})]})})}function Ia({username:e,draftName:a,onBack:i,onStartNew:n,showStartNew:l}){return t.jsxs("header",{className:"sticky top-0 z-20 flex h-[60px] items-center border-b border-white/[0.06] px-4 sm:px-6",style:{background:"rgba(8,9,11,0.78)",backdropFilter:"blur(12px)"},children:[t.jsxs("div",{className:"flex items-center gap-3 text-sm",children:[t.jsx("button",{type:"button",onClick:i,"aria-label":"Back",className:"inline-flex h-9 w-9 items-center justify-center rounded-[6px] text-gray-400 transition-colors hover:bg-white/[0.06] hover:text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40",children:t.jsx(Lr,{className:"h-4 w-4","aria-hidden":"true"})}),t.jsxs("nav",{"aria-label":"Breadcrumb",className:"flex items-center gap-1.5 text-gray-500",style:{fontSize:"13px"},children:[t.jsxs("span",{children:["@",e]}),t.jsx("span",{className:"text-gray-700",children:"·"}),t.jsx("span",{className:"font-semibold text-white",children:(a==null?void 0:a.trim())||"new character"})]})]}),l&&n&&t.jsxs("button",{type:"button",onClick:n,className:"ml-auto inline-flex h-9 items-center gap-1.5 rounded-[6px] px-3 text-[13px] text-gray-400 transition-colors hover:bg-white/[0.06] hover:text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500/40",children:[t.jsx(Dt,{className:"h-4 w-4","aria-hidden":"true"})," Start new"]})]})}export{di as default}; 4 5//# debugId=97558bec-d330-551b-bc2f-d1648309eeec
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.