1import{r,j as e,I as b,av as E,aw as M,U as A,ax as O,ay as _,az as H,aA as L,aB as U}from"./index-B906m9HQ.js";function D(f){switch((f??"").toLowerCase()){case"python":return"py";case"javascript":case"js":return"js";case"typescript":case"ts":return"ts";case"json":return"json";case"bash":case"sh":return"sh";case"sql":return"sql";case"html":return"html";case"css":return"css";default:return"txt"}}function N(f){const o=[];let n,l=0;for(const c of f){if(c.role!=="assistant"||!c.content)continue;if(c.content.includes("<rival_ui>")){const v=E(c.content);for(const d of v)if(d.kind==="block")if(d.block.type==="code"){l++;const p=d.block.language??"text";o.push({id:`${c.id}-${l}`,name:`tool_${l}.${D(p)}`,language:p,code:d.block.code})}else if(d.block.type==="code_diff"){l++;const p=d.block.language??"text";o.push({id:`${c.id}-diff-${l}`,name:d.block.file||`tool_${l}.${D(p)}`,language:p,code:d.block.new_content})}else d.block.type==="test_results"&&(n=d.block)}const u=/```([\w+-]*)\s*\n([\s\S]*?)```/g;let a;for(;(a=u.exec(c.content))!==null;){l++;const v=a[1]||"text";o.push({id:`${c.id}-fence-${l}`,name:`tool_${l}.${D(v)}`,language:v,code:a[2].trimEnd()})}}return{files:o,latestTests:n}}const q=({messages:f})=>{const{files:o,latestTests:n}=r.useMemo(()=>N(f),[f]),[l,c]=r.useState(null),[u,a]=r.useState("editor"),[v,d]=r.useState(!1);r.useEffect(()=>{if(o.length===0){c(null);return}c(s=>s&&o.some(h=>h.id===s)?s:o[o.length-1].id)},[o]);const p=n?`${n.passed}/${n.total}-${n.tests.length}`:"",m=r.useRef("");r.useEffect(()=>{p&&p!==m.current&&a("tests"),m.current=p},[p]);const g=o.find(s=>s.id===l);return e.jsxs("div",{style:{display:"flex",flexDirection:"column",height:"100%",background:"var(--bg-1)",minHeight:0},children:[e.jsxs("div",{style:{display:"flex",alignItems:"stretch",borderBottom:"1px solid var(--border)",background:"#fff",overflow:"hidden"},children:[e.jsxs("div",{style:{display:"flex",flex:1,overflowX:"auto"},children:[o.map(s=>{const h=u==="editor"&&s.id===l;return e.jsx("button",{type:"button",onClick:()=>{c(s.id),a("editor")},style:{padding:"10px 14px",border:0,borderRight:"1px solid var(--border)",background:h?"var(--bg-1)":"#fff",cursor:"pointer",fontSize:12,fontFamily:"var(--font-mono)",color:h?"var(--text-1)":"var(--text-3)",fontWeight:h?600:500,whiteSpace:"nowrap",borderBottom:h?"2px solid var(--blue)":"2px solid transparent",marginBottom:-1},children:s.name},s.id)}),o.length===0&&e.jsx("div",{style:{padding:"12px 14px",fontSize:12,color:"var(--text-3)"},children:"No files yet , ask RivalBot to scaffold one."})]}),e.jsxs("button",{type:"button",onClick:()=>a("tests"),style:{padding:"10px 16px",border:0,borderLeft:"1px solid var(--border)",background:u==="tests"?"var(--bg-1)":"#fff",cursor:"pointer",fontSize:12,fontWeight:600,color:u==="tests"?"var(--blue)":"var(--text-3)",display:"inline-flex",alignItems:"center",gap:6,borderBottom:u==="tests"?"2px solid var(--blue)":"2px solid transparent",marginBottom:-1},title:"Run / Tests",children:[e.jsx(b.Play,{size:11})," Run / Tests",n&&e.jsxs("span",{style:{marginLeft:4,fontSize:10,padding:"1px 6px",borderRadius:999,background:n.passed===n.total?"var(--green-soft)":"var(--amber-soft, #fff3cd)",color:n.passed===n.total?"var(--green)":"var(--amber, #b07b00)"},children:[n.passed,"/",n.total]})]})]}),e.jsxs("div",{style:{flex:1,minHeight:0,overflow:"hidden",display:"flex",flexDirection:"column"},children:[u==="editor"&&g&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 12px",background:"var(--bg-1)",borderBottom:"1px solid var(--border)"},children:[e.jsx("span",{style:{fontSize:11,color:"var(--text-3)",textTransform:"uppercase",letterSpacing:"0.05em",fontFamily:"var(--font-mono)"},children:g.language}),e.jsxs("div",{style:{display:"flex",gap:6},children:[e.jsxs("button",{type:"button",onClick:()=>{navigator.clipboard.writeText(g.code),d(!0),setTimeout(()=>d(!1),1500)},style:{background:"transparent",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-2)",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:4,fontSize:11,padding:"3px 8px"},children:[e.jsx(b.Copy,{size:11})," ",v?"Copied":"Copy"]}),e.jsxs("a",{href:URL.createObjectURL(new Blob([g.code],{type:"text/plain"})),download:g.name,style:{textDecoration:"none",border:"1px solid var(--border)",borderRadius:6,color:"var(--text-2)",display:"inline-flex",alignItems:"center",gap:4,fontSize:11,padding:"3px 8px",background:"#fff"},children:[e.jsx(b.Download,{size:11})," Download"]})]})]}),e.jsx("pre",{style:{margin:0,padding:16,fontSize:12.5,fontFamily:"var(--font-mono)",lineHeight:1.55,color:"var(--text-1)",overflow:"auto",flex:1,background:"#fff"},children:e.jsx("code",{children:g.code})})]}),u==="editor"&&!g&&e.jsx("div",{style:{flex:1,display:"grid",placeItems:"center",color:"var(--text-3)",fontSize:13,padding:32,textAlign:"center"},children:"Code RivalBot writes will appear here as files."}),u==="tests"&&e.jsxs("div",{style:{flex:1,overflow:"auto",padding:16,background:"#fff"},children:[!n&&e.jsx("div",{style:{color:"var(--text-3)",fontSize:13,textAlign:"center",padding:32},children:'No test runs yet. Ask RivalBot to "run the tests".'}),n&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:14},children:[e.jsxs("div",{style:{fontSize:16,fontWeight:700,color:"var(--text-1)"},children:[n.passed," / ",n.total," passing"]}),e.jsx("div",{style:{fontSize:11,padding:"3px 8px",borderRadius:999,fontWeight:600,background:n.passed===n.total?"var(--green-soft)":"#fff3cd",color:n.passed===n.total?"var(--green)":"#b07b00"},children:n.passed===n.total?"All green":"Has failures"})]}),e.jsx("ul",{style:{margin:0,padding:0,listStyle:"none",display:"flex",flexDirection:"column",gap:6},children:n.tests.map((s,h)=>
1e.jsxs("li",{style:{display:"flex",alignItems:"flex-start",gap:10,padding:"10px 12px",border:"1px solid var(--border)",borderRadius:8,background:s.pass?"#fff":"#fff8f7"},children:[e.jsx("span",{style:{width:16,height:16,borderRadius:"50%",display:"grid",placeItems:"center",flexShrink:0,background:s.pass?"var(--green)":"var(--red, #dc2626)",color:"#fff",marginTop:2},children:s.pass?e.jsx(b.Check,{size:9}):e.jsx(b.X,{size:9})}),e.jsxs("div",{style:{flex:1,minWidth:0},children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,color:"var(--text-1)"},children:s.name}),s.error&&e.jsx("div",{style:{fontSize:12,color:"var(--text-3)",marginTop:3,fontFamily:"var(--font-mono)"},children:s.error})]}),e.jsxs("span",{style:{fontSize:11,color:"var(--text-3)",fontFamily:"var(--font-mono)",flexShrink:0},children:[s.ms,"ms"]})]},h))})]})]})]})]})},X=["Build an email validator in Python","Scaffold a competitor monitoring agent","Wire a workflow that turns PDFs into HubSpot contacts","Show me marketplace gaps in finance"];function K(){return Math.random().toString(36).slice(2,10)}function I(f){return f.slice(0,8).map(o=>({id:K(),name:o.name,size:o.size,kind:U(o.name)}))}function J(){const[f,o]=r.useState(""),[n,l]=r.useState([]),[c,u]=r.useState("Builder"),{messages:a,send:v,stop:d,regenerate:p,isStreaming:m}=M({mode:"builder",onTitle:u,recentTo:"/builder"}),[g,s]=r.useState(),[h,C]=r.useState(),[T,B]=r.useState(640),[j,F]=r.useState(!0),[P,R]=r.useState(!1),S=r.useRef(0),k=r.useRef(null),w=r.useMemo(()=>{for(const t of a){if(t.role!=="assistant"||!t.content?.includes("<rival_ui>"))continue;if(E(t.content).some(x=>x.kind==="block"&&x.block.type==="code"))return!0}return!1},[a]),W=r.useRef(!1);r.useEffect(()=>{w&&!W.current&&(F(!0),W.current=!0)},[w]),r.useEffect(()=>{k.current&&(k.current.scrollTop=k.current.scrollHeight)},[a]),r.useEffect(()=>{for(let t=a.length-1;t>=0;t--){const i=a[t];if(i.role==="assistant"&&i.card&&i.status!=="streaming"){s(i.card),C(i.savedRunId);return}}},[a]);const z=t=>{!t.trim()&&n.length===0||m||(v(t,n),o(""),l([]))};return a.length===0?e.jsx("div",{className:"content",style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",minHeight:0,background:"var(--bg-1)"},children:e.jsxs("div",{style:{width:"100%",maxWidth:720,padding:"0 24px"},children:[e.jsxs("div",{style:{textAlign:"center",marginBottom:28},children:[e.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:6,padding:"4px 12px",borderRadius:999,background:"var(--violet-soft)",color:"var(--violet)",fontSize:12,fontWeight:600,marginBottom:16},children:[e.jsx(b.Code,{size:12})," Builder"]}),e.jsx("h1",{style:{fontSize:34,fontWeight:700,letterSpacing:"-0.02em",margin:0,lineHeight:1.2},children:"What are you building?"}),e.jsx("p",{style:{marginTop:10,fontSize:14,color:"var(--text-3)"},children:"Describe the tool. RivalBot scaffolds code, finds competitors, runs tests, and walks you to publish."})]}),e.jsx(A,{value:f,onChange:o,onSubmit:()=>z(f),placeholder:"Describe what you want to buildâ¦",variant:"hero",autoFocus:!0,attachments:n,onAddFiles:t=>l(i=>[...i,...I(t)].slice(0,8)),onRemoveAttachment:t=>l(i=>i.filter(x=>x.id!==t)),isStreaming:m,onStop:d}),e.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:8,justifyContent:"center",marginTop:18},children:X.map(t=>e.jsx("button",{type:"button",onClick:()=>z(t),style:{display:"inline-flex",alignItems:"center",gap:7,padding:"8px 14px",borderRadius:999,border:"1px solid var(--border)",background:"#fff",color:"var(--text-2)",cursor:"pointer",fontSize:13},children:t},t))})]})}):e.jsxs("div",{style:{display:"flex",flexDirection:"column",flex:1,minHeight:0,position:"relative"},onDragEnter:t=>{t.dataTransfer?.types?.includes("Files")&&(S.current++,R(!0))},onDragOver:t=>{t.dataTransfer?.types?.includes("Files")&&t.preventDefault()},onDragLeave:()=>{S.current=Math.max(0,S.current-1),S.current===0&&R(!1)},onDrop:t=>{t.preventDefault(),S.current=0,R(!1);const i=t.dataTransfer?.files?Array.from(t.dataTransfer.files):[];i.length&&l(x=>[...x,...I(i)].slice(0,8))},children:[e.jsx(O,{visible:P}),e.jsxs("div",{style:{display:"flex",flex:1,minHeight:0},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",flex:1,minWidth:0,minHeight:0},children:[e.jsx("div",{style:{flexShrink:0,padding:"16px 24px 0"},children:e.jsxs("div",{style:{maxWidth:780,margin:"0 auto",display:"flex",alignItems:"center",gap:8},children:[e.jsx(b.Code,{size:14,style:{color:"var(--violet)"}}),e.jsx("h1",{style:{margin:0,fontSize:15,fontWeight:600,letterSpacing:"-0.01em",color:"var(--text-1)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:c,children:c}),e.jsx("div",{style:{flex:1}}),w&&e.jsxs("button",{type:"button",onClick:()=>F(t=>!t),title:j?"Hide IDE":"Show IDE",style:{height:28,padding:"0 10px",borderRadius:8,border:"1px solid "+(j?"var(--violet)":"var(--border)"),background:j?"var(--violet-soft)":"#fff",color:j?"var(--violet)":"var(--text-2)",fontSize:12,fontWeight:600,cursor:"pointer",display:"inline-flex",alignItems:"center",gap:6},children:[e.jsx(b.Code,{size:12})," ",j?"Hide IDE":"Show IDE"]})]})}),e.jsx("div",{ref:k,style:{flex:1,overflowY:"auto",minHeight:0},children:e.jsx("div",{style:{maxWidth:780,margin:"0 auto",padding:"32px 24px 24px"},children:a.map((t,i)=>{let x;if(t.role==="assistant"){for(let y=i-1;y>=0;y--)if(a[y].role==="user"){x=a[y];break}}return e.jsx(_,{m:t,mode:"builder",promptForTrace:x?.content,attachmentsForTrace:x?.attachments,onRegenerate:p,canRegenerate:!m&&i===a.length-1&&t.role==="assistant",onOpenPreview:(y,$)=>{s(y),C($)},onAction:y=>{v(y)}},t.id)})})}),e.jsx("div",{style:{padding:"12px 24px 18px",flexShrink:0},children:e.jsx("div",{style:{maxWidth:720,margin:"0 auto"},children:e.jsx(A,{value:f,onChange:o,onSubmit:()=>z(f),placeholder:m?"RivalBot is thinkingâ¦":"Message RivalBotâ¦",variant:"bare",attachments:n,onAddFiles:t=>l(i=>[...i,...I(t)].slice(0,8)),onRemoveAttachment:t=>l(i=>i.filter(x=>x.id!==t)),isStreaming:m,onStop:d})})})]}),g?e.jsxs(e.Fragment,{children:[e.jsx(H,{onDrag:t=>B(i=>
1Math.max(320,Math.min(900,i+t)))}),e.jsx("div",{style:{width:T,flexShrink:0,background:"#fff",display:"flex",flexDirection:"column",minHeight:0,position:"relative"},children:e.jsx(L,{open:!0,inline:!0,card:g,savedRunId:h,onClose:()=>s(void 0)})})]}):w&&j?e.jsxs(e.Fragment,{children:[e.jsx(H,{onDrag:t=>B(i=>Math.max(320,Math.min(900,i+t)))}),e.jsx("div",{style:{width:T,flexShrink:0,background:"var(--bg-1)",display:"flex",flexDirection:"column",minHeight:0,position:"relative"},children:e.jsx(q,{messages:a})})]}):null]})]})}export{J 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.