PageSourceSearch

https://founder-spark-63.lovable.app/assets/EnterpriseAdversarialMatrix-DmVO1mR6.js

js founder-spark-63.lovable.app collected 2026-10-03 03:32:54 UTC 9,987 bytes, 1 lines download raw bytes

1import{j as e}from"./query-_koPiPsI.js";import{h as te,r}from"./react-vendor-h1rQ_Bae.js";import{bh as re,B as X,L as $,C as p,n as f,k as E,o as I,p as R,q as A,I as ae,y as ne,O as ie,G as oe,aF as le,aG as de,aH as ce,aI as me,aJ as xe,s as T,g}from"./index-Dq2zLArw.js";import{u as ue,a as he,E as pe,b as fe}from"./EngineLoopBar-yOmfrlWe.js";import{S as ge}from"./switch-CyEfQhNS.js";import{W as je}from"./wand-sparkles-DjjB0AGR.js";import{I as ye}from"./info-DI8_flyN.js";import{C as Ne}from"./circle-play-JCqM3Pnw.js";import"./ui-radix-CKwvnS8F.js";import"./supabase-DL6nu9mS.js";import"./charts-Xu79y1bN.js";import"./motion-nVmI7L5T.js";const ve=j=>{const o=new Map;j.forEach(l=>{const a=o.get(l.parent_id)??[];a.push(l),o.set(l.parent_id,a)});const m=new Map;let b=0;const _=(l,a)=>{const k=o.get(l)??[];if(k.length===0)return b++;const d=k.map(y=>{const x=_(y.id,a+1);return m.set(y.id,{x,y:a}),x});return(d[0]+d[d.length-1])/2};return _(null,0),m},we=j=>{const o=j??0;return o>=60?"hsl(142 76% 45%)":o>=30?"hsl(38 92% 55%)":"hsl(0 84% 60%)"};function Pe(){const{enabled:j,loading:o}=ue(),{lastRun:m,loading:b,save:_}=he("matrix"),[l]=te(),a=l.get("run_id"),k=l.get("brand_id"),[d,y]=r.useState(""),[x,F]=r.useState(""),[u,N]=r.useState(!1),[O,B]=r.useState(!1),[h,L]=r.useState(null),[J,K]=r.useState([]),[v,Q]=r.useState(null),[G,W]=r.useState(!1),[P,q]=r.useState(null),[S,U]=r.useState(null);r.useEffect(()=>
1{if(a){L(a),N(!1);return}if(!b)if(m?.run_id){L(m.run_id);const s=m.input??{};s.brand&&y(s.brand),s.seed_prompt&&F(s.seed_prompt),N(!1)}else N(!0)},[a,b,m]),r.useEffect(()=>{if(u||!h)return;const s=async()=>{const[{data:n},{data:i}]=await Promise.all([T.from("model_responses").select("id,parent_id,model,turn_index,prompt,answer,brand_mentioned,competitor_mentioned,sov_score,leakage_reason").eq("matrix_id",h).order("turn_index"),T.from("prompt_matrices").select("metadata").eq("id",h).maybeSingle()]);K(n??[]);const c=i?.metadata?.model_health;c&&typeof c=="object"&&U(c)};s();const t=setInterval(s,4e3);return()=>clearInterval(t)},[h,u]);const w=u?fe:J,C=r.useMemo(()=>ve(w),[w]),H=w.filter(s=>s.leakage_reason),D=900,V=Math.max(300,(Math.max(...Array.from(C.values()).map(s=>s.y),0)+1)*140),Y=Math.max(1,Math.max(...Array.from(C.values()).map(s=>s.x))+1),z=D/(Y+1),Z=async()=>{if(!d||!x)return g.error("Brand + seed prompt required");B(!0);try{const{data:s,error:t}=await T.functions.invoke("start-prompt-matrix",{body:{brand:d,seed_prompt:x,models:["chatgpt","claude","gemini","perplexity"]}});if(t)throw t;L(s.matrix_id),N(!1),await _(s.matrix_id,{brand:d,seed_prompt:x}),g.success(s.worker_configured?"Matrix queued — nodes stream in as models respond.":"Matrix row created. Configure MATRIX_WORKER_URL to run the multi-turn probe.")}catch(s){g.error(s.message??"Failed to start")}finally{B(!1)}},ee=async()=>{if(!h||u){g.error("Run a real matrix first");return}W(!0);try{const{data:s,error:t}=await T.functions.invoke("matrix-counter-content",{body:{matrix_id:h,brand_id:k??null}});if(t)throw t;if(!s?.ok)throw new Error(s?.error??"Failed");q(s.briefs??[]),g.success(`Drafted ${s.briefs?.length??0} counter-content brief${s.briefs?.length===1?"":"s"}`)}catch(s){g.error(s.message??"Failed to draft")}finally{W(!1)}};return o?e.jsx("div",{className:"p-6",children:"Loading…"}):j?e.jsxs("div",{className:"p-6 space-y-6",children:[e.jsxs("header",{children:[e.jsx("h1",{className:"text-3xl font-semibold tracking-tight",children:"Adversarial Multi-Turn Matrix"}),e.jsx("p",{className:"text-muted-foreground",children:"Trace how each frontier model degrades your brand's share of voice under follow-up questions."})]}),e.jsx(pe,{engine:"matrix",actions:e.jsxs(X,{size:"sm",variant:"secondary",onClick:ee,disabled:G||u,children:[G?e.jsx($,{className:"w-3 h-3 mr-1 animate-spin"}):e.jsx(je,{className:"w-3 h-3 mr-1"}),"Draft counter-content"]})}),e.jsx(p,{className:"border-dashed bg-muted/30",children:e.jsxs(f,{className:"py-3 text-xs text-muted-foreground flex gap-2",children:[e.jsx(ye,{className:"w-4 h-4 shrink-0 mt-0.5 text-primary"}),e.jsxs("div",{children:[e.jsx("strong",{className:"text-foreground",children:"How to use:"}),' Give your brand name and a seed question a buyer might ask (e.g. "best AI SEO tool for founders"). We ask ChatGPT, Claude, Gemini and Perplexity in parallel, then follow up 3 more turns to see where they drop you and start recommending a competitor. Only Perplexity has live web search — the others answer from their trained knowledge. Green = safe. Red = leakage.']})]})}),S&&Object.keys(S).length>0&&e.jsx(p,{children:e.jsx(f,{className:"py-3",children:e.jsxs("div",{className:"flex items-center gap-2 flex-wrap text-xs",children:[e.jsx("span",{className:"text-muted-foreground font-medium mr-1",children:"Model health:"}),["chatgpt","claude","gemini","perplexity"].map(s=>{const t=S[s];if(!t)return null;const n=t.status==="ok"?"bg-emerald-500/10 text-emerald-500 border-emerald-500/30":t.status==="missing_key"?"bg-amber-500/10 text-amber-500 border-amber-500/30":"bg-red-500/10 text-red-500 border-red-500/30",i=t.status==="ok"?"ok":t.status==="missing_key"?"API key missing":"provider error";return e.jsxs(E,{variant:"outline",className:n,title:t.detail,children:[s,": ",i]},s)}),Object.values(S).some(s=>s.status!=="ok")&&e.jsx("span",{className:"text-muted-foreground ml-2",children:"Fix in Supabase → Edge Function secrets so this run isn't lopsided."})]})})}),e.jsxs(p,{children:[e.jsxs(I,{children:[e.jsx(R,{children:"New Matrix Run"}),e.jsx(A,{children:"Seed prompt is the top of the conversation tree; probes fan out per model."})]}),e.jsxs(f,{className:"space-y-3",children:[e.jsx(ae,{placeholder:"Your brand name (e.g. ThoughtForge)",value:d,onChange:s=>y(s.target.value)}),e.jsx(ne,{placeholder:"Seed prompt",rows:3,value:x,onChange:s=>F(s.target.value)}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ge,{id:"sm",checked:u,onCheckedChange:N}),e.jsx(ie,{htmlFor:"sm",className:"text-sm",children:"Sample data"})]}),e.jsxs(X,{onClick:Z,disabled:O,children:[O?e.jsx($,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(Ne,{className:"mr-2 h-4 w-4"}),"Run Matrix"]})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-6",children:[e.jsxs(p,{className:"col-span-2",children:[e.jsxs(I,{children:[e.jsx(R,{children:"Conversation Tree"}),e.jsx(A,{children:"Green = brand present. Amber = weakening. Red = brand dropped (leakage)."})]}),e.jsx(f,{children:e.jsx("div",{className:"overflow-auto",style:{maxHeight:600},children:e.jsx("svg",{width:D,height:V+40,children:w.map(s=>{const t=s.parent_id?w.find(se=>se.id===s.parent_id):null,n=C.get(s.id),i=t?C.get(t.id):null;if(!n)return null;
1const c=(n.x+1)*z,M=n.y*140+40;return e.jsxs("g",{children:[i&&e.jsx("line",{x1:(i.x+1)*z,y1:i.y*140+40,x2:c,y2:M,stroke:"hsl(var(--muted-foreground))",strokeWidth:1,opacity:.4}),e.jsx("circle",{cx:c,cy:M,r:22,fill:we(s.sov_score),onClick:()=>Q(s),style:{cursor:"pointer"},stroke:"white",strokeWidth:2}),e.jsx("text",{x:c,y:M+4,textAnchor:"middle",fontSize:10,fill:"white",fontWeight:600,children:s.model.slice(0,4)}),e.jsxs("text",{x:c,y:M+40,textAnchor:"middle",fontSize:10,fill:"hsl(var(--foreground))",children:["T",s.turn_index," · SoV ",s.sov_score?.toFixed(0)??"-"]})]},s.id)})})})})]}),e.jsxs(p,{children:[e.jsxs(I,{children:[e.jsxs(R,{className:"flex items-center gap-2",children:[e.jsx(oe,{className:"h-4 w-4 text-destructive"})," Leakage Points"]}),e.jsx(A,{children:"Where the model stopped mentioning you."})]}),e.jsxs(f,{className:"space-y-3",children:[H.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No leakage detected."}),H.map(s=>e.jsxs("div",{className:"border rounded-md p-3 space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(E,{children:s.model}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["Turn ",s.turn_index]})]}),e.jsx("p",{className:"text-xs",children:s.leakage_reason}),s.competitor_mentioned.length>0&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Instead: ",s.competitor_mentioned.join(", ")]})]},s.id))]})]})]}),v&&e.jsxs(p,{children:[e.jsxs(I,{children:[e.jsxs(R,{children:[v.model," · Turn ",v.turn_index]}),e.jsx(A,{children:v.prompt})]}),e.jsx(f,{children:e.jsx("p",{className:"text-sm whitespace-pre-wrap",children:v.answer})})]}),e.jsx(le,{open:P!==null,onOpenChange:s=>!s&&q(null),children:e.jsxs(de,{className:"w-[560px] sm:max-w-lg overflow-y-auto",children:[e.jsxs(ce,{children:[e.jsx(me,{children:"Counter-content briefs"}),e.jsx(xe,{children:"One brief per leakage point. Turn each into an article, LinkedIn post, or FAQ to close the gap."})]}),e.jsxs("div",{className:"mt-4 space-y-3",children:[(P??[]).length===0&&e.jsx("p",{className:"text-xs text-muted-foreground",children:"No leakage points detected — nothing to draft."}),(P??[]).map((s,t)=>e.jsxs("div",{className:"border rounded-md p-3 space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsx(E,{variant:"secondary",className:"text-[10px]",children:s.format}),s.target_model&&e.jsxs(E,{variant:"outline",className:"text-[10px]",children:["→ ",s.target_model]})]}),e.jsx("div",{className:"font-medium text-sm",children:s.title}),Array.isArray(s.outline)&&e.jsx("ul",{className:"list-disc list-inside text-xs text-muted-foreground space-y-1",children:s.outline.map((n,i)=>e.jsx("li",{children:n},i))}),s.why_it_helps&&e.jsx("p",{className:"text-[11px] italic text-muted-foreground",children:s.why_it_helps})]},t))]})]})})]}):e.jsxs("div",{className:"p-8 max-w-xl mx-auto text-center space-y-3",children:[e.jsx(re,{className:"mx-auto h-10 w-10 text-muted-foreground"}),e.jsx("h1",{className:"text-2xl font-semibold",children:"Enterprise Only"}),e.jsx("p",{className:"text-muted-foreground",children:"The Adversarial Matrix is an Enterprise-tier engine."})]})}export{Pe as default};

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.