ultimatehuman 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,16 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/data-provider-TNBGds5H.js","assets/fmt-BRV4RZz4.js","assets/index-C7UNg0WM.js","assets/page-C_4oHSxK.js","assets/index-CIpIMh38.js"])))=>i.map(i=>d[i]);
2
+ import{_ as Ie}from"./index-C7UNg0WM.js";import{c as D,r as o,g as H,j as e,a as be,p as B,X as Be,A as We,t as $t,M as _t,S as Ye,C as Rt,f as Mt,s as zt,h as At,i as Et}from"./fmt-BRV4RZz4.js";const Ve={name:"activity",size:24,node:[["path",{d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2",key:"169zse"}]]};Ve.node;const Ce=D(Ve);const Ke={name:"arrow-right",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]};Ke.node;const G=D(Ke);const Ge={name:"arrow-up-right",size:24,node:[["path",{d:"M7 7h10v10",key:"1tivn9"}],["path",{d:"M7 17 17 7",key:"1vkiza"}]]};Ge.node;const O=D(Ge);const Ze={name:"arrow-up",size:24,node:[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]};Ze.node;const Dt=D(Ze);const Je={name:"cable",size:24,node:[["path",{d:"M17 19a1 1 0 0 1-1-1v-2a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2v2a1 1 0 0 1-1 1z",key:"trhst0"}],["path",{d:"M17 21v-2",key:"ds4u3f"}],["path",{d:"M19 14V6.5a1 1 0 0 0-7 0v11a1 1 0 0 1-7 0V10",key:"1mo9zo"}],["path",{d:"M21 21v-2",key:"eo0ou"}],["path",{d:"M3 5V3",key:"1k5hjh"}],["path",{d:"M4 10a2 2 0 0 1-2-2V6a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2a2 2 0 0 1-2 2z",key:"1dd30t"}],["path",{d:"M7 5V3",key:"1t1388"}]]};Je.node;const It=D(Je);const Xe={name:"check",size:24,node:[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]};Xe.node;const ke=D(Xe);const Qe={name:"check-check",size:24,node:[["path",{d:"M18 6 7 17l-5-5",key:"116fxf"}],["path",{d:"m22 10-7.5 7.5L13 16",key:"ke71qq"}]]};Qe.node;const Lt=D(Qe);const et={name:"chevron-right",size:24,node:[["path",{d:"m9 18 6-6-6-6",key:"mthhwq"}]]};et.node;const tt=D(et);const st={name:"circle",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}]]};st.node;const Tt=D(st);const nt={name:"clock-3",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 6v6h4",key:"135r8i"}]]};nt.node;const Le=D(nt);const at={name:"code-xml",size:24,node:[["path",{d:"m18 16 4-4-4-4",key:"1inbqp"}],["path",{d:"m6 8-4 4 4 4",key:"15zrgr"}],["path",{d:"m14.5 4-5 16",key:"e7oirm"}]],aliases:["code-2"]};at.node;const Pt=D(at);const it={name:"git-branch",size:24,node:[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]]};it.node;const rt=D(it);const lt={name:"git-fork",size:24,node:[["circle",{cx:"12",cy:"18",r:"3",key:"1mpf1b"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["path",{d:"M18 9v2c0 .6-.4 1-1 1H7c-.6 0-1-.4-1-1V9",key:"1uq4wg"}],["path",{d:"M12 12v3",key:"158kv8"}]]};lt.node;const xe=D(lt);const ct={name:"image-plus",size:24,node:[["path",{d:"M16 5h6",key:"1vod17"}],["path",{d:"M19 2v6",key:"4bpg5p"}],["path",{d:"M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5",key:"1ue2ih"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}]]};ct.node;const Ht=D(ct);const ot={name:"list-checks",size:24,node:[["path",{d:"M13 5h8",key:"a7qcls"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["path",{d:"m3 7 2 2 4-4",key:"1obspn"}]]};ot.node;const Ot=D(ot);const dt={name:"loader-circle",size:24,node:[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],aliases:["loader-2"]};dt.node;const X=D(dt);const ut={name:"lock-keyhole",size:24,node:[["circle",{cx:"12",cy:"16",r:"1",key:"1au0dj"}],["rect",{x:"3",y:"10",width:"18",height:"12",rx:"2",key:"6s8ecr"}],["path",{d:"M7 10V7a5 5 0 0 1 10 0v3",key:"1pqi11"}]]};ut.node;const ht=D(ut);const pt={name:"message-square",size:24,node:[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}]]};pt.node;const Ut=D(pt);const mt={name:"plus",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]]};mt.node;const Te=D(mt);const gt={name:"refresh-cw",size:24,node:[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]};gt.node;const xt=D(gt);const ft={name:"send",size:24,node:[["path",{d:"M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z",key:"1ffxy3"}],["path",{d:"m21.854 2.147-10.94 10.939",key:"12cjpa"}]]};ft.node;const Ft=D(ft);const vt={name:"settings-2",size:24,node:[["path",{d:"M14 17H5",key:"gfn3mx"}],["path",{d:"M19 7h-9",key:"6i9tg"}],["circle",{cx:"17",cy:"17",r:"3",key:"18b49y"}],["circle",{cx:"7",cy:"7",r:"3",key:"dfmy0x"}]]};vt.node;const qt=D(vt);const jt={name:"sliders-horizontal",size:24,node:[["path",{d:"M10 5H3",key:"1qgfaw"}],["path",{d:"M12 19H3",key:"yhmn1j"}],["path",{d:"M14 3v4",key:"1sua03"}],["path",{d:"M16 17v4",key:"1q0r14"}],["path",{d:"M21 12h-9",key:"1o4lsq"}],["path",{d:"M21 19h-5",key:"1rlt1p"}],["path",{d:"M21 5h-7",key:"1oszz2"}],["path",{d:"M8 10v4",key:"tgpxqk"}],["path",{d:"M8 12H3",key:"a7s4jb"}]]};jt.node;const Bt=D(jt);const yt={name:"terminal",size:24,node:[["path",{d:"M12 19h8",key:"baeox8"}],["path",{d:"m4 17 6-6-6-6",key:"1yngyt"}]]};yt.node;const we=D(yt);const bt={name:"triangle-alert",size:24,node:[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]],aliases:["alert-triangle"]};bt.node;const Wt=D(bt);function Yt({current:t,provider:n,accountKind:r,disabled:d,onChange:l}){const[u,m]=o.useState(null),[j,b]=o.useState([]),[f,v]=o.useState(!0),[h,x]=o.useState(!1),[S,s]=o.useState(""),a=o.useRef(0),i=async(N=!1)=>{const g=++a.current;v(!0),s("");try{const _=await H(`/api/chat/models${N?"?refresh=1":""}`);g===a.current&&(m(_),s(_.error||""))}catch(_){g===a.current&&s(_.message)}finally{g===a.current&&v(!1)}};o.useEffect(()=>(m(null),i(),()=>{a.current++}),[n]),o.useEffect(()=>{H("/api/chat/providers").then(N=>b(N.providers)).catch(()=>{})},[n]);const p=t||u?.current||"",w=u?.models.find(N=>N.id===p||N.aliases.includes(p)),C=p==="claude-opus-5-5"?"Opus 5.5":p||"CLI default",R=async N=>{x(!0),s("");try{await B("/api/chat/provider",{provider:N}),await l()}catch(g){s(g.message)}finally{x(!1)}},A=async N=>{x(!0),s("");try{await B("/api/chat/model",{model:N}),await l()}catch(g){s(g.message)}finally{x(!1)}};return e.jsxs("div",{className:"chat-model-control",children:[e.jsxs("div",{className:"chat-model-select",title:"AI account for chat and pipeline runs",children:[e.jsx("select",{"aria-label":"AI provider",value:n,disabled:d||h,onChange:N=>{R(N.target.value)},children:[{id:"claude",label:"Claude"},{id:"codex",label:"Codex"}].map(N=>{const g=j.find(_=>_.id===N.id);return e.jsxs("option",{value:N.id,children:[N.label,g&&!g.available?" · Not installed":g&&!g.authenticated?" · Sign in":""]},N.id)})}),e.jsx(be,{size:12})]}),e.jsxs("div",{className:"chat-model-select",title:`${n==="codex"?"Your Codex ChatGPT subscription":r==="api"?"Your Claude API account":"Your Claude Code subscription"} · Model applies to new chat messages`,children:[(f||h)&&e.jsx(X,{size:12,className:"uh-spin"}),e.jsxs("select",{"aria-label":"Chat model","aria-describedby":S?"chat-model-error":void 0,value:w?.id||p,onChange:N=>{A(N.target.value)},disabled:d||f||h||!u?.models.length,children:[!w&&e.jsxs("option",{value:p,children:[C,u?.models.length?" (current)":""]}),u?.models.map(N=>e.jsxs("option",{value:N.id,title:N.description,children:[N.label,N.id===u.default?" · Default":""]},N.id))]}),e.jsx(be,{size:12})]}),S&&e.jsxs("div",{className:"chat-model-error",id:"chat-model-error",role:"status",children:[e.jsx("span",{children:S}),e.jsxs("button",{type:"button",disabled:f,onClick:()=>{i(!0)},children:[e.jsx(xt,{size:11}),"Retry"]})]})]})}function se({className:t=""}){return e.jsxs("svg",{className:t,viewBox:"0 0 40 40",fill:"none","aria-hidden":"true",children:[e.jsx("rect",{width:"40",height:"40",rx:"12",fill:"currentColor"}),e.jsx("circle",{cx:"20",cy:"14",r:"5",fill:"var(--mark-ink, #121a14)"}),e.jsx("path",{d:"M10.5 29a9.5 9.5 0 0 1 19 0v2h-19v-2Z",fill:"var(--mark-ink, #121a14)"})]})}function Se({title:t,children:n,close:r,wide:d=!1}){const l=o.useRef(null),u=o.useRef(r);u.current=r;const m=o.useRef(document.activeElement);return o.useEffect(()=>{const j=document.body.style.overflow;document.body.style.overflow="hidden",l.current?.contains(document.activeElement)||l.current?.querySelector("input, textarea, select, button")?.focus();const b=f=>{if(f.key==="Escape"&&u.current(),f.key==="Tab"){const v=[...l.current?.querySelectorAll("button:not(:disabled), input:not(:disabled), select, textarea, a[href]")??[]].filter(S=>S.offsetParent!==null),h=v[0],x=v[v.length-1];f.shiftKey&&document.activeElement===h&&(f.preventDefault(),x?.focus()),!f.shiftKey&&document.activeElement===x&&(f.preventDefault(),h?.focus())}};return document.addEventListener("keydown",b),()=>{document.body.style.overflow=j,document.removeEventListener("keydown",b),m.current?.focus()}},[]),e.jsx("div",{className:"uh-scrim",onMouseDown:j=>{j.target===j.currentTarget&&r()},children:e.jsxs("div",{ref:l,className:`uh-modal ${d?"wide":""}`,role:"dialog","aria-modal":"true","aria-label":t,children:[e.jsxs("div",{className:"uh-modal-head",children:[e.jsx("h2",{children:t}),e.jsx("button",{className:"uh-icon-btn",onClick:r,"aria-label":"Close dialog",children:e.jsx(Be,{size:20})})]}),n]})})}function Vt({request:t,initialKey:n="",close:r,connected:d}){const[l,u]=o.useState(null),[m,j]=o.useState({}),[b,f]=o.useState(""),[v,h]=o.useState([]),[x,S]=o.useState(!1),[s,a]=o.useState(!1),[i,p]=o.useState(""),[w,C]=o.useState(!1);o.useEffect(()=>{let g=!0;return H("/api/chat/connections").then(_=>{if(!g)return;const I=_.sources.find($=>$.id===t.source);if(!I)throw new Error("This source is not available.");u(I),j(Object.fromEntries(I.fields.map($=>[$.key,$.key==="apiKey"&&n?n:$.value||""]))),f(String(I.savedOptions.projectId||"")),S(t.source==="posthog"&&I.fields.some($=>$.key==="host"&&!["https://us.posthog.com","https://eu.posthog.com"].includes($.value)))}).catch(_=>{g&&p(_.message)}),()=>{g=!1}},[t.id]);const R=(g,_)=>j(I=>({...I,[g]:_}));let A="";try{const g=new URL(t.source==="posthog"?m.host||"https://us.posthog.com":`https://app.${m.site||"datadoghq.com"}`);["http:","https:"].includes(g.protocol)&&(A=g.origin)}catch{}const N=async()=>{if(!s){a(!0),p("");try{await B(`/api/chat/connections/${t.id}`,{credentials:m,options:b?{projectId:b}:{}}),j({}),C(!0),d()}catch(g){g instanceof We&&g.status===409&&g.detail?.projects?(h(g.detail.projects),f(""),p("")):p(g.message)}finally{a(!1)}}};return e.jsx(Se,{title:w?`${l?.name||t.source} connected`:l?.guide.title||"Connect source",close:()=>{s||r()},children:w?e.jsxs("div",{className:"source-success",children:[e.jsx(ke,{size:25}),e.jsx("p",{children:"Access verified. Claude is continuing setup in chat."}),e.jsx("button",{className:"uh-btn primary",onClick:r,children:"Continue in chat"})]}):l?e.jsxs("form",{className:"source-form",autoComplete:"off",onSubmit:g=>{g.preventDefault(),N()},children:[e.jsx("p",{className:"source-purpose",children:t.source==="posthog"?"Use your existing events and errors to find bugs.":"Use your existing error logs to find bugs."}),e.jsxs("label",{className:"uh-field",children:[e.jsx("span",{children:t.source==="posthog"?"PostHog region":"Datadog site"}),t.source==="posthog"?e.jsxs("select",{disabled:s,value:x?"custom":m.host||"https://us.posthog.com",onChange:g=>{S(g.target.value==="custom"),R("host",g.target.value==="custom"?"":g.target.value),h([]),f("")},children:[e.jsx("option",{value:"https://us.posthog.com",children:"US Cloud"}),e.jsx("option",{value:"https://eu.posthog.com",children:"EU Cloud"}),e.jsx("option",{value:"custom",children:"Self-hosted"})]}):e.jsx("select",{disabled:s,value:m.site||"datadoghq.com",onChange:g=>R("site",g.target.value),children:["datadoghq.com","datadoghq.eu","us3.datadoghq.com","us5.datadoghq.com","ap1.datadoghq.com","ddog-gov.com"].map(g=>e.jsx("option",{children:g},g))})]}),x&&e.jsxs("label",{className:"uh-field",children:[e.jsx("span",{children:"PostHog URL"}),e.jsx("input",{disabled:s,type:"url",required:!0,value:m.host||"",placeholder:"https://posthog.example.com",onChange:g=>R("host",g.target.value)})]}),e.jsx("div",{className:"source-key-links",children:l.guide.links.map(g=>e.jsxs("a",{className:"uh-btn",href:A?A+g.path:l.guide.docsUrl,target:"_blank",rel:"noreferrer",children:[g.label,e.jsx(O,{size:14})]},g.path))}),e.jsxs("details",{className:"source-help",children:[e.jsx("summary",{children:"Key setup instructions"}),e.jsx("ol",{children:l.guide.steps.map(g=>e.jsx("li",{children:g},g))}),e.jsxs("div",{className:"source-scopes",children:[e.jsx("span",{children:"Read permissions"}),l.scopes.map(g=>e.jsx("code",{children:g},g))]}),e.jsxs("a",{className:"source-docs",href:l.guide.docsUrl,target:"_blank",rel:"noreferrer",children:["Official instructions ",e.jsx(O,{size:12})]})]}),l.fields.filter(g=>g.secret).map((g,_)=>e.jsxs("label",{className:"uh-field",children:[e.jsx("span",{children:g.label}),e.jsx("input",{disabled:s,autoFocus:_===0,type:"password",autoComplete:"off",spellCheck:!1,required:!l.configured,value:m[g.key]||"",placeholder:l.configured?"Use saved key, or paste a replacement":t.source==="posthog"?"phx_…":`Paste your ${g.label.toLowerCase()}`,onChange:I=>{R(g.key,I.target.value),h([]),f("")}})]},g.key)),v.length>0&&e.jsxs("label",{className:"uh-field",children:[e.jsxs("span",{children:["Which PostHog project belongs to ",t.project||"this project","?"]}),e.jsxs("select",{disabled:s,required:!0,value:b,onChange:g=>f(g.target.value),children:[e.jsx("option",{value:"",disabled:!0,children:"Choose a project"}),v.map(g=>e.jsxs("option",{value:g.id,children:[g.name," · ",g.id]},g.id))]})]}),e.jsxs("p",{className:"source-private",children:[e.jsx(ht,{size:13}),"Saved on this machine, outside the conversation."]}),i&&e.jsx("p",{role:"alert",className:"uh-error",children:i}),e.jsxs("div",{className:"uh-modal-actions",children:[e.jsx("button",{type:"button",className:"uh-btn",disabled:s,onClick:r,children:"Cancel"}),e.jsx("button",{className:"uh-btn primary",type:"submit",disabled:s||v.length>0&&!b,children:s?e.jsxs(e.Fragment,{children:[e.jsx(X,{size:15,className:"uh-spin"}),"Checking access…"]}):v.length?"Use this project":"Connect"})]})]}):e.jsx("p",{role:"status",children:i||"Loading connection…"})})}const Kt=/^\[user sent an? ([a-z ]+), saved at (\/.+)\]$/,Pe=/\[\[send:([^\]]+)\]\]/g,Gt=/\.(png|jpe?g|webp|gif|svg)$/i,kt=t=>`/api/chat/file?path=${encodeURIComponent(t)}`;function Zt(t){if(t.role==="assistant"){const d=[...t.text.matchAll(Pe)].map(l=>l[1].trim());return{text:t.text.replace(Pe,"").replace(/\n{3,}/g,`
3
+
4
+ `).trim(),files:d}}const n=[];return{text:t.text.split(`
5
+ `).filter(d=>{const l=Kt.exec(d.trim());return l&&n.push(l[2]),!l}).join(`
6
+ `).trim(),files:n}}function Jt({path:t,open:n}){const[r,d]=o.useState(!1),l=t.split("/").pop();return!Gt.test(t)||r?e.jsxs("span",{className:"chat-file",title:t,children:[r?"Unavailable: ":"File: ",l]}):e.jsx("button",{type:"button",className:"chat-thumb",onClick:()=>n(t),title:t,"data-chat-image":!0,children:e.jsx("img",{src:kt(t),alt:l,onError:()=>d(!0)})})}const Xt=t=>new Promise((n,r)=>{const d=new FileReader;d.onload=()=>n(String(d.result).split(",")[1]??""),d.onerror=()=>r(d.error),d.readAsDataURL(t)});function Qt({disabled:t=!1,initialPrompt:n="",configured:r=!1,projectNames:d=[]}={}){const[l,u]=o.useState([]),[m,j]=o.useState(0),b=c=>c.replace(/\bphx_[A-Za-z0-9]+\b/g,""),[f,v]=o.useState(()=>b(n||sessionStorage.getItem("uh.chat.draft")||""));o.useEffect(()=>{const c=new URL(location.href);c.searchParams.has("message")&&(c.searchParams.delete("message"),history.replaceState(null,"",c))},[]);const[h,x]=o.useState(""),S=o.useRef(!1);o.useEffect(()=>{sessionStorage.setItem("uh.chat.draft",b(f))},[f]);const[s,a]=o.useState([]),[i,p]=o.useState(null),[w,C]=o.useState(""),[R,A]=o.useState([]),[N,g]=o.useState(""),[_,I]=o.useState("subscription"),[$,E]=o.useState("claude"),y=$==="codex"?"Codex":"Claude",[T,k]=o.useState("claude-opus-5-5"),M=o.useRef(new Set),[L,F]=o.useState([]),[Q,ee]=o.useState(!1),[W,$e]=o.useState(null),[_e,Y]=o.useState(""),he=o.useRef(null),Re=o.useRef(null),Me=o.useRef(0),ze=o.useRef(null),V=l.length===0||l.length<=2&&/^Help me (set up ultimatehuman|manage this workspace)\./.test(l[0]?.text),Ct=l.filter(c=>!(c.role==="user"&&/^Help me (set up ultimatehuman|manage this workspace)\.$/.test(c.text))),K=async()=>{const c=await H("/api/chat");u(c.messages),j(c.busy),x(c.activity||`${c.provider==="codex"?"Codex":"Claude"} is working…`),a(c.connections||[]),A(c.permissions||[]),I(c.accountKind||"subscription"),E(c.provider||"claude"),k(c.model??"claude-opus-5-5")},pe=(c,z="")=>{M.current.add(c.id),sessionStorage.setItem(`uh.connection.seen.${c.id}`,"1"),C(z),p(c)},Ae=()=>{p(null),C(""),ze.current?.focus()};o.useEffect(()=>{if(i)return;const c=s.find(z=>z.status==="pending"&&!M.current.has(z.id)&&!sessionStorage.getItem(`uh.connection.seen.${z.id}`));c&&pe(c)},[s,i]);const St=c=>{const z=c.match(/\bphx_[A-Za-z0-9]{16,}\b/)?.[0];v(b(c)),z&&B("/api/chat/connections/request",{source:"posthog"}).then(P=>pe(P.request,z)).catch(P=>Y(P.message))},Ee=async(c,z)=>{g(c),Y("");try{await B(`/api/chat/permissions/${c}`,{allow:z}),await K()}catch(P){Y(P.message)}finally{g("")}};o.useEffect(()=>{K().catch(z=>Y(z.message));const c=setInterval(()=>{K().catch(()=>{})},1500);return()=>clearInterval(c)},[]),o.useEffect(()=>{const c=l[l.length-1]?.id??0;!V&&c!==Me.current&&he.current?.scrollIntoView({block:"end"}),Me.current=c},[l]),o.useEffect(()=>{m&&!V&&he.current?.scrollIntoView({block:"end"})},[m,R.length,s.length]);const me=c=>{const z=[...c??[]].filter(P=>P.type.startsWith("image/"));z.length&&F(P=>[...P,...z.map(U=>({file:U,url:URL.createObjectURL(U)}))].slice(0,4))},De=async()=>{const c=f.trim();if(t||S.current||!c&&!L.length)return;S.current=!0,Y("");const z=L;v(""),F([]);try{const P=await Promise.all(z.map(async({file:U})=>({name:U.name||"pasted.png",data:await Xt(U)})));await B("/api/chat",{text:c,files:P}),z.forEach(U=>URL.revokeObjectURL(U.url)),await K()}catch(P){Y(P.message),v(c),F(z)}finally{S.current=!1}};return e.jsxs("div",{className:`chat-full${V?" chat-intro-mode":""}${Q?" dragging":""}`,onDragOver:c=>{[...c.dataTransfer.types].includes("Files")&&(c.preventDefault(),ee(!0))},onDragLeave:c=>{c.currentTarget===c.target&&ee(!1)},onDrop:c=>{c.preventDefault(),ee(!1),me(c.dataTransfer.files)},children:[e.jsx("div",{className:"chat-log","data-chat-log":!0,children:e.jsxs("div",{className:"chat-col",children:[V&&e.jsxs("div",{className:"chat-welcome",children:[e.jsx(se,{}),e.jsx("h2",{children:r?"What’s next?":"Set up your first pipeline."}),e.jsx("p",{children:r?d.join(" · "):"Start with one project. Include all of its repositories."})]}),Ct.map(c=>{const z=Zt(c),P=z.files.length>0&&e.jsx("div",{className:"chat-files",children:z.files.map((U,ge)=>e.jsx(Jt,{path:U,open:$e},ge))});return e.jsxs("div",{className:`chat-msg ${c.role}`,"data-chat-msg":c.role,"data-source":c.source,children:[e.jsxs("div",{className:"chat-meta",children:[c.role==="assistant"&&e.jsx(se,{className:"chat-avatar"}),e.jsx("strong",{children:c.role==="user"?"You":"ultimatehuman"}),e.jsx("span",{className:"chat-message-time",children:$t(c.ts)}),c.source!=="dashboard"&&e.jsx("span",{className:"pill","data-source-tag":!0,children:c.source==="cli"?"CLI":c.source})]}),c.role==="user"&&P,z.text&&e.jsx("div",{className:"chat-bubble",children:c.role==="assistant"?e.jsx(_t,{text:z.text}):z.text}),c.role==="assistant"&&P]},c.id)}),s.filter(c=>c.status==="pending").map(c=>e.jsxs("div",{className:"chat-action-card","data-connection-request":c.source,children:[e.jsx(It,{size:20}),e.jsxs("div",{children:[e.jsxs("strong",{children:["Connect ",c.source==="posthog"?"PostHog":"Datadog"]}),e.jsxs("p",{children:["Use your existing ",c.source==="posthog"?"events and errors":"error logs",c.project?` for ${c.project}`:"","."]})]}),e.jsxs("button",{className:"uh-btn primary",onClick:()=>pe(c),children:["Connect ",e.jsx(O,{size:14})]})]},c.id)),R.map(c=>e.jsxs("div",{className:"chat-permission","data-chat-permission":c.tool,children:[e.jsxs("div",{children:[e.jsx(we,{size:17}),e.jsx("strong",{children:c.tool==="Bash"?"Run this command?":`Allow ${y} to ${c.tool==="Edit"?"edit this file":c.tool==="Write"?"write this file":"use "+c.tool}?`})]}),c.input.description&&e.jsx("p",{children:c.input.description}),e.jsx("pre",{children:c.tool==="Bash"?c.input.command:c.input.file_path||c.input.path||JSON.stringify(c.input,null,2)}),(c.input.new_string!==void 0||c.input.content!==void 0)&&e.jsxs("details",{children:[e.jsx("summary",{children:"View change"}),c.input.old_string&&e.jsx("pre",{className:"permission-before",children:c.input.old_string}),e.jsx("pre",{children:c.input.new_string??c.input.content})]}),e.jsxs("div",{className:"chat-permission-actions",children:[e.jsx("button",{className:"uh-btn",disabled:N===c.id,onClick:()=>{Ee(c.id,!1)},children:"Decline"}),e.jsx("button",{className:"uh-btn primary",disabled:N===c.id,onClick:()=>{Ee(c.id,!0)},children:N===c.id?"Continuing…":c.tool==="Bash"?"Run command":"Allow"})]})]},c.id)),m>0&&e.jsx("div",{className:"chat-msg assistant","data-chat-busy":!0,children:e.jsxs("div",{className:"chat-bubble chat-busy",children:[e.jsx(X,{size:14,className:"uh-spin"})," ",h,m>1?` · ${m-1} queued`:""]})}),e.jsx("div",{ref:he})]})}),e.jsx("form",{className:"chat-input",onSubmit:c=>{c.preventDefault(),De()},children:e.jsxs("div",{className:"chat-col",children:[L.length>0&&e.jsx("div",{className:"chat-pending","data-chat-pending":!0,children:L.map((c,z)=>e.jsxs("span",{className:"chat-pending-item",children:[e.jsx("img",{src:c.url,alt:c.file.name}),e.jsx("button",{type:"button","aria-label":"Remove",onClick:()=>F(P=>P.filter((U,ge)=>ge!==z)),children:e.jsx(Be,{size:12})})]},c.url))}),e.jsxs("div",{className:"chat-row",children:[e.jsx("input",{ref:Re,type:"file",accept:"image/*",multiple:!0,hidden:!0,"data-chat-file":!0,onChange:c=>(me(c.target.files),c.target.value="")}),e.jsx("textarea",{ref:ze,"aria-label":`Message ${y}`,"data-chat-input":!0,rows:V?2:1,value:f,placeholder:V?r?"What should we investigate?":"Repository paths or Git URLs…":`Message ${y}…`,onChange:c=>St(c.target.value),onPaste:c=>{c.clipboardData.files.length&&(c.preventDefault(),me(c.clipboardData.files))},onKeyDown:c=>{c.key==="Enter"&&!c.shiftKey&&!c.nativeEvent.isComposing&&(c.preventDefault(),De())}}),e.jsxs("div",{className:"chat-composer-bar",children:[e.jsxs("button",{type:"button",className:"btn chat-attach","aria-label":"Attach an image",title:"Attach an image",onClick:()=>Re.current?.click(),"data-chat-attach":!0,children:[e.jsx(Ht,{size:16}),e.jsx("span",{children:"Add context"})]}),e.jsx(Yt,{current:T,provider:$,accountKind:_,disabled:m>0,onChange:K}),e.jsx("button",{type:"submit",className:"btn primary chat-send","aria-label":"Send message",title:t?`Reconnect ${y} to send`:"Send message",disabled:t||!f.trim()&&!L.length,"data-chat-send":!0,children:e.jsx(Dt,{size:19,strokeWidth:2})})]})]}),e.jsxs("div",{className:"chat-composer-hint",children:[e.jsx("span",{children:$==="codex"?"Your Codex ChatGPT subscription":_==="api"?"Your Claude API account":"Your Claude Code subscription"}),e.jsx("span",{children:"Enter to send · Shift+Enter for a new line"})]}),_e&&e.jsx("p",{className:"chat-err",role:"alert",children:_e})]})}),i&&e.jsx(Vt,{request:i,initialKey:w,close:Ae,connected:()=>{Ae(),K()}}),Q&&e.jsx("div",{className:"chat-drop",children:"Drop an image to attach it"}),W&&e.jsx("div",{className:"scrim chat-lightbox",onClick:()=>$e(null),"data-chat-lightbox":!0,children:e.jsx("img",{src:kt(W),alt:W.split("/").pop()})})]})}const es=t=>`/chat?message=${encodeURIComponent(t)}`;function ts(t,n){const r=t.workspace.projects,d=r.find(k=>k.id===n)??r[0],l=d?.repos??[],u=l.map(k=>k.name),m=d?t.pipelines.config.filter(k=>!k.repos||k.repos.some(M=>u.includes(M))):[],j=t.workspace.connections.filter(k=>k.supported),b=k=>k.configured&&k.probe?.ok===!0,f=k=>l.some(M=>M.trackers.some(L=>L.provider===k.id)),v=j.filter(f),h=j.filter(b),x=l.length>0&&l.every(k=>k.available),S=t.workspace.provider.authenticated===!0,s=k=>k.sources.some(M=>M==="repos"?x:M==="*"?h.length>0:h.some(L=>L.id===M)),a=k=>k.sources.some(M=>M!=="repos"&&M!=="*"&&!h.some(L=>L.id===M)),i=k=>x&&S&&s(k)&&!a(k),p=m.some(i),w=t.runs.filter(k=>m.some(M=>M.id===k.pipelineId)),C=w.find(k=>!["done","failed"].includes(k.phase)),R=(t.pipelines.queued??[]).some(k=>m.some(M=>M.id===k.pipelineId)),A=w.find(k=>k.phase==="done"&&!k.error&&k.sources?.some(M=>M.ok)),N=`/pipeline-live${d?`?project=${encodeURIComponent(d.id)}`:""}`,g=d?` for project ${JSON.stringify(d.id)}`:"",_=k=>es(k+g+"."),I=m.find(k=>k.template==="bug-radar"),$=j.find(k=>I?.sources.includes(k.id)&&!b(k))??v.find(b)??v[0]??h[0];let E={title:"Connect your first project",detail:"Tell the assistant which repositories belong to it.",label:"Choose repositories",href:_("Help me connect my repositories")};if(d)if(!x)E={title:"Reconnect a repository",detail:"One of this project’s checkouts is unavailable.",label:"Resolve in chat",href:_("Help me restore access to the unavailable repository")};else if(!S)E={title:"Check the AI account connection",detail:"Use the account already installed on this machine.",label:"Check in chat",href:_("Check my selected AI account connection")};else if(C||R)E={title:C?.phase==="parked"?"Investigation is waiting":R?"Investigation is queued":"Your pipeline is running",detail:"Follow the investigation and its evidence as it progresses.",label:"Open Pipeline live",href:N};else if(I&&!i(I)||!p&&$&&!b($))E={title:$?`Connect ${$.name}`:"Connect an error source",detail:"Give Bug radar access to real errors for its next run.",label:"Continue in chat",href:_($?`Connect ${$.name} and run the existing Bug radar, or set up the original Bug radar if none exists`:"Help me connect a tracking source and run Bug radar")};else if(A)E={title:"Your first investigation is complete",detail:A.findings?`The completed run produced ${A.findings} finding${A.findings===1?"":"s"}.`:"The run completed without a supported finding. You can inspect its coverage.",label:A.findings?"Open Review":"View run",href:A.findings?`/review?tab=decide&pipeline=${encodeURIComponent(A.pipelineId)}`:N};else if(p){const k=m.find(i);E={title:`Run ${k.name}`,detail:"Check the evidence, then send supported findings to Review.",label:"Start in chat",href:_(`Run the existing pipeline ${JSON.stringify(k.id)} now, keeping its saved settings`)}}else E={title:$?"Set up Bug radar":"Start with a Security check",detail:$?"Use your connected source to investigate real user problems.":"Review your code now. Add production tracking when you’re ready.",label:"Set up in chat",href:_($?"Set up and run the original Bug radar using my connected source":"Set up and run the original Security check on my repositories")};const y=[{id:"repos",label:"Repositories",done:x,detail:l.length?x?`${l.length} connected`:"Access needed":"Not connected"},{id:"account",label:t.workspace.provider.label||"AI account",done:S,detail:S?"Account connected":"Check connection"},{id:"pipeline",label:"Pipeline",done:p,detail:p?"Ready to run":m.length?"Connection needed":"Not set up"},{id:"run",label:"First run",done:!!A,detail:A?"Completed":C?.phase==="parked"?"Waiting for capacity":C?"Running":R?"Queued":w[0]?.phase==="failed"?"Needs attention":"Not started"}],T=t.pipelines.templates.map(k=>{const M=m.filter(W=>W.template===k.id),L=k.id==="security-check",F=x&&S&&(L||h.length>0),Q=M.some(i),ee=v.length||h.length?!L:L;return{...k,existing:M,recommended:ee,ready:M.length?Q:F,status:M.length?Q?M.every(W=>!W.enabled)?"Paused":"Configured":"Connection needed":F?"Ready to add":x?S?"Needs tracking":"Needs AI account":"Needs repositories",description:L?"Find exposed secrets, risky dependencies, and gaps in authentication.":"Trace production errors and failed interactions back to the code.",href:_(M.length?`Check the setup of the existing ${k.name} pipeline${M.length===1?" "+JSON.stringify(M[0].id):"s"} and help me run it, preserving its saved settings`:`Help me set up ${k.name} using the original template defaults, then run it`)}}).sort((k,M)=>Number(M.recommended)-Number(k.recommended));return{project:d,repos:l,pipelines:m,sources:j,tracked:v,available:h,connected:b,detected:f,steps:y,next:E,suggestions:T,liveHref:N,ask:_,completed:A}}const He={posthog:{description:"Product events, failed interactions, and user errors.",docs:"https://posthog.com/docs/libraries",letter:"P"},datadog:{description:"Backend error logs and service failures.",docs:"https://docs.datadoghq.com/logs/error_tracking/",letter:"D"}};function ss({data:t,project:n}){const r=ts(t,n),{project:d,repos:l,pipelines:u,sources:m,steps:j,next:b,suggestions:f,ask:v}=r,h=j.filter(s=>s.done).length,x=j.find(s=>!s.done)?.id,S=[...new Set(l.flatMap(s=>s.trackers.map(a=>a.provider)))].filter(s=>!m.some(a=>a.id===s));return e.jsxs("div",{className:"setup-page",children:[e.jsxs("div",{className:"setup-heading",children:[e.jsxs("div",{children:[e.jsx("span",{className:"setup-eyebrow",children:"PROJECT SETUP"}),e.jsx("h2",{children:d?.name||"Your first project"}),e.jsx("p",{children:"What’s connected. What’s next."})]}),e.jsxs("a",{className:"uh-btn",href:v("Help me connect another repository"),children:[e.jsx(Te,{size:14}),"Add repository"]})]}),e.jsxs("section",{className:"setup-progress","aria-label":"Setup progress",children:[e.jsxs("div",{className:"setup-progress-top",children:[e.jsxs("span",{children:[e.jsx(Lt,{size:16}),"Setup progress"]}),e.jsxs("span",{children:[h," of ",j.length," complete"]})]}),e.jsx("ol",{children:j.map((s,a)=>e.jsxs("li",{className:s.done?"is-done":s.id===x?"is-next":"","aria-current":!s.done&&s.id===x?"step":void 0,children:[e.jsx("span",{className:"setup-step-marker",children:s.done?e.jsx(ke,{size:14}):String(a+1).padStart(2,"0")}),e.jsxs("div",{children:[e.jsx("strong",{children:s.label}),e.jsx("span",{children:s.detail})]})]},s.id))})]}),e.jsxs("div",{className:"setup-next",role:"status",children:[e.jsx("div",{className:"setup-next-icon",children:e.jsx(G,{size:20})}),e.jsxs("div",{children:[e.jsx("span",{className:"setup-eyebrow",children:r.completed?"FIRST RUN COMPLETE":"NEXT STEP"}),e.jsx("h3",{children:b.title}),e.jsx("p",{children:b.detail})]}),e.jsxs("a",{className:"uh-btn primary",href:b.href,children:[b.label,e.jsx(G,{size:14})]})]}),e.jsxs("div",{className:"setup-columns",children:[e.jsxs("div",{className:"setup-primary",children:[e.jsxs("section",{className:"setup-section","aria-labelledby":"setup-repositories",children:[e.jsxs("div",{className:"setup-section-heading",children:[e.jsxs("h3",{id:"setup-repositories",children:["Repositories ",e.jsx("span",{children:l.length})]}),e.jsx(xe,{size:17})]}),e.jsx("div",{className:"setup-repos",children:l.length?l.map(s=>{const a=u.filter(p=>!p.repos||p.repos.includes(s.name)),i=s.facts.filter(p=>p.kind==="application").map(p=>p.label).filter(p=>p!=="Node.js").join(" · ")||"Repository";return e.jsxs("div",{className:"setup-repo",children:[e.jsx("div",{className:"setup-repo-icon",children:e.jsx(Pt,{size:18})}),e.jsxs("div",{className:"setup-repo-info",children:[e.jsxs("div",{children:[e.jsx("strong",{children:s.name}),e.jsx("span",{className:`setup-label ${s.available?"positive":"attention"}`,children:s.available?"Connected":"Unavailable"})]}),e.jsxs("p",{children:[i,s.branch&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"·"}),e.jsx(rt,{size:11}),s.branch]})]}),e.jsxs("details",{children:[e.jsxs("summary",{children:[a.length?`${a.length} pipeline${a.length===1?"":"s"}`:"No pipeline yet",e.jsx(tt,{size:11})]}),e.jsx("code",{children:s.path}),a.length>0&&e.jsx("p",{children:a.map(p=>p.name).join(" · ")}),s.error&&e.jsx("p",{children:s.error})]})]})]},s.name)}):e.jsxs("div",{className:"setup-empty",children:[e.jsx(xe,{size:24}),e.jsx("p",{children:"Connect the frontend, backend, or any repos that make up your project."}),e.jsxs("a",{href:b.href,children:["Choose repositories in chat ",e.jsx(G,{size:13})]})]})})]}),e.jsxs("section",{className:"setup-section","aria-labelledby":"setup-pipelines",children:[e.jsxs("div",{className:"setup-section-heading",children:[e.jsx("h3",{id:"setup-pipelines",children:"Pipelines"}),e.jsx("span",{children:r.completed?"Add when useful":"Start with one"})]}),e.jsx("div",{className:"setup-pipeline-list",children:f.map(s=>e.jsxs("article",{className:"setup-pipeline","data-setup-pipeline":s.id,children:[e.jsxs("div",{className:"setup-pipeline-top",children:[e.jsx("span",{className:"setup-pipeline-icon",children:s.id==="security-check"?e.jsx(Ye,{size:18}):e.jsx(Ce,{size:18})}),e.jsx("h4",{children:s.name}),s.recommended&&!s.existing.length&&e.jsx("span",{className:"setup-recommended",children:r.completed?"Suggested next":"Start here"})]}),e.jsx("p",{children:s.description}),e.jsxs("div",{className:"setup-pipeline-bottom",children:[e.jsxs("span",{className:`setup-label ${s.ready&&s.status!=="Paused"?"positive":""}`,children:[e.jsx(Tt,{size:6,fill:"currentColor"}),s.status]}),e.jsxs("a",{href:s.href,children:[s.existing.length?"Continue in chat":"Set up in chat",e.jsx(O,{size:14})]})]})]},s.id))}),u.filter(s=>!f.some(a=>a.id===s.template)).map(s=>e.jsxs("a",{className:"setup-custom-pipeline",href:v(`Show the setup and status of the existing pipeline ${JSON.stringify(s.id)}`),children:[e.jsx(Bt,{size:15}),s.name,e.jsx("span",{children:s.enabled?"Configured":"Paused"}),e.jsx(O,{size:13})]},s.id)),e.jsxs("a",{className:"setup-other",href:v("Help me design another pipeline using the existing engine capabilities"),children:[e.jsx(Te,{size:13}),"Have another objective? Discuss it in chat."]})]})]}),e.jsxs("aside",{className:"setup-secondary",children:[e.jsxs("section",{className:"setup-section","aria-labelledby":"setup-tracking",children:[e.jsxs("div",{className:"setup-section-heading",children:[e.jsx("h3",{id:"setup-tracking",children:"Tracking"}),e.jsx("span",{children:r.tracked.length?"Found in your code":"For production signals"})]}),e.jsx("p",{className:"setup-section-copy",children:r.tracked.length?r.tracked.every(r.connected)?"Your detected tools have read access. Check their coverage for this project.":"Connect a tool you already use to investigate real user problems.":r.available.length?"Your workspace has connected sources. Check that they cover this project.":"No supported tracking SDK detected. Add one for production errors, or start with a code review."}),m.filter(s=>He[s.id]).sort((s,a)=>Number(r.detected(a))-Number(r.detected(s))).map(s=>{const a=r.detected(s),i=r.connected(s),p=He[s.id],w=l.filter(C=>C.trackers.some(R=>R.provider===s.id));return e.jsxs("article",{className:"setup-source","data-setup-source":s.id,children:[e.jsxs("div",{className:"setup-source-top",children:[e.jsx("span",{className:`setup-source-logo ${s.id}`,children:p.letter}),e.jsx("h4",{children:s.name}),e.jsx("span",{className:`setup-label ${i?"positive":""}`,children:i?"Connected":a?"SDK detected":"Optional"})]}),e.jsx("p",{children:p.description}),a&&e.jsxs("div",{className:"setup-source-repos",children:[e.jsx(xe,{size:12}),e.jsx("span",{children:w.map(C=>C.name).join(" · ")})]}),i?e.jsxs("p",{className:"setup-source-access",children:[e.jsx(ke,{size:12}),"Workspace read access verified"]}):a&&e.jsx("p",{className:"setup-source-access",children:"Read access not connected"}),e.jsxs("div",{className:"setup-source-actions",children:[e.jsxs("a",{href:v(i?`Check ${s.name} project mapping and data coverage for my repositories`:a?`Connect the existing ${s.name} tracking using the in-chat connection form, then continue my first Bug radar`:`Help me add ${s.name} tracking to my repositories. Inspect the existing setup first and explain what needs to be installed`),children:[i?"Check coverage":a?`Connect ${s.name}`:"Set up in chat",e.jsx(G,{size:13})]}),e.jsx("a",{href:p.docs,target:"_blank",rel:"noreferrer","aria-label":`${s.name} documentation`,title:"Official documentation",children:e.jsx(O,{size:14})})]})]},s.id)}),S.length>0&&e.jsxs("p",{className:"setup-unsupported",children:[S.map(s=>s==="sentry"?"Sentry":s).join(", ")," detected. Collection is not available in this build."]})]}),e.jsxs("div",{className:"setup-flow",children:[e.jsx("span",{className:"setup-eyebrow",children:"HOW IT WORKS"}),e.jsxs("p",{children:["Signals ",e.jsx(G,{size:12})," Investigation ",e.jsx(G,{size:12})," Review"]}),e.jsx("span",{children:"The AI checks the code and evidence. You decide which findings to act on."}),e.jsxs("a",{href:r.liveHref,children:["See Pipeline live",e.jsx(O,{size:13})]})]})]})]})]})}function J({href:t,prefetch:n,replace:r,scroll:d,shallow:l,passHref:u,legacyBehavior:m,...j}){return e.jsx("a",{href:typeof t=="string"?t:t?.pathname??"#",...j})}function ns({title:t,titleId:n,...r},d){return o.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:d,"aria-labelledby":n},r),t?o.createElement("title",{id:n},t):null,o.createElement("path",{fillRule:"evenodd",d:"M10 3a.75.75 0 0 1 .75.75v10.638l3.96-4.158a.75.75 0 1 1 1.08 1.04l-5.25 5.5a.75.75 0 0 1-1.08 0l-5.25-5.5a.75.75 0 1 1 1.08-1.04l3.96 4.158V3.75A.75.75 0 0 1 10 3Z",clipRule:"evenodd"}))}const as=o.forwardRef(ns);function is({title:t,titleId:n,...r},d){return o.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:d,"aria-labelledby":n},r),t?o.createElement("title",{id:n},t):null,o.createElement("path",{fillRule:"evenodd",d:"M3 10a.75.75 0 0 1 .75-.75h10.638L10.23 5.29a.75.75 0 1 1 1.04-1.08l5.5 5.25a.75.75 0 0 1 0 1.08l-5.5 5.25a.75.75 0 1 1-1.04-1.08l4.158-3.96H3.75A.75.75 0 0 1 3 10Z",clipRule:"evenodd"}))}const rs=o.forwardRef(is);function ls({title:t,titleId:n,...r},d){return o.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:d,"aria-labelledby":n},r),t?o.createElement("title",{id:n},t):null,o.createElement("path",{fillRule:"evenodd",d:"M8.22 5.22a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 0 1 0 1.06l-4.25 4.25a.75.75 0 0 1-1.06-1.06L11.94 10 8.22 6.28a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"}))}const de=o.forwardRef(ls);function cs({title:t,titleId:n,...r},d){return o.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true","data-slot":"icon",ref:d,"aria-labelledby":n},r),t?o.createElement("title",{id:n},t):null,o.createElement("path",{d:"M6.28 5.22a.75.75 0 0 0-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 1 0 1.06 1.06L10 11.06l3.72 3.72a.75.75 0 1 0 1.06-1.06L11.06 10l3.72-3.72a.75.75 0 0 0-1.06-1.06L10 8.94 6.28 5.22Z"}))}const os=o.forwardRef(cs),ds=30*1e3,ie=7,Ne=14,ne=24*3600*1e3,oe=[{key:"validate",label:"To validate",owner:"you",tab:"validate",hint:"MAX fixes wait for your go before anything runs."},{key:"queued",label:"Fix queue",owner:"pipeline",tab:"validate",hint:"Validated, or not using MAX: the pipeline picks them up."},{key:"building",label:"Building",owner:"pipeline",tab:"merge",hint:"A fix round is running."},{key:"decide",label:"Needs decision",owner:"you",tab:"decide",hint:"The pipeline asks you to choose."},{key:"manual",label:"Manual",owner:"you",tab:"manual",hint:"Stopped over budget, for you to run by hand."},{key:"merge",label:"Ready to merge",owner:"you",tab:"merge",hint:"Passed the hostile check: review and merge on GitHub."},{key:"shipped",label:"Shipped",owner:"done",tab:"shipped",hint:`Merged on GitHub, last ${ie} days.`}],q=t=>{const n=t?new Date(t).getTime():NaN;return Number.isFinite(n)?n:null},fe=(t,n)=>t.key.localeCompare(n.key,"en",{numeric:!0});function us(t,n=Date.now()){if(!t?.key)return null;if(t.live_stage&&oe.some(r=>r.key===t.live_stage))return t.live_stage==="shipped"&&(q(t.merged_at)??0)<n-ie*ne?null:t.live_stage;switch(t.queue){case"backlog":return t.merged_into?null:t.gate==="pending"||t.gate==="later"?"validate":t.gate==="validated"||t.gate==="auto"?"queued":null;case"building":return"building";case"decision":return"decide";case"manual":return"manual";case"merge":return"merge";case"shipped":{const r=q(t.merged_at);return r!=null&&r>=n-ie*ne?"shipped":null}default:return null}}function hs(t,n){if(t.live_state)return t.live_state;const r=(t.prs||[]).length,d=`${r} PR${r===1?"":"s"}`,l=t.fix_round?.stage;switch(n){case"validate":return t.gate==="later"?{turn:"parked",status:"Parked with Later: nothing runs until you validate it."}:{turn:"you",status:"Waiting for your validation."};case"queued":return{turn:"pipeline",status:t.gate==="validated"?"Validated by you, in the fix queue.":"No MAX cost, in the fix queue on its own."};case"building":return{turn:"pipeline",status:l?`Fix round ${l}.`:"Fix in progress."};case"decide":return t.answer?.answered_at?{turn:"pipeline",status:"You answered. The pipeline acts on it."}:{turn:"you",status:"Waiting for your decision."};case"manual":return{turn:"you",status:"Stopped over budget. Yours to run by hand."};case"merge":return l?{turn:"pipeline",status:`Your fix request is building (${l}).`}:t.hold?{turn:"you",status:`Held: ${t.hold}`}:{turn:"you",status:`Ready: review and merge ${d} on GitHub.`};case"shipped":return{turn:"done",status:`Merged on GitHub (${d}).`};default:return{turn:"pipeline",status:""}}}function ve(t){const n=new Date(t);return n.setHours(0,0,0,0),n.getTime()}function ps(t,n=Date.now(),r=oe){const d=ve(n),l=[];for(const s of t||[]){const a=us(s,n);if(!a)continue;const{turn:i,status:p}=hs(s,a),w=q(s.jira_created);l.push({key:s.key,title:(s.plain?.improves||s.title||"").trim(),stage:a,turn:i,status:p,held:a==="merge"&&!!s.hold&&!s.fix_round?.stage,round:s.fix_round?.stage||null,created:w,newToday:w!=null&&w>=d,at:a==="shipped"?q(s.merged_at):a==="manual"?q(s.manual?.stopped_at):w,flags:(s.flags||[]).map(C=>C.label).filter(Boolean),href:s.live_href||null,displayKey:s.displayKey||(s.live_stage?`${s.key.split("-")[0]}-${s.key.slice(-6)}`:null)})}const u=r.map(s=>{const a=l.filter(p=>p.stage===s.key);a.sort(s.key==="shipped"?(p,w)=>(w.at||0)-(p.at||0)||fe(p,w):(p,w)=>Oe(p)-Oe(w)||(p.created??1/0)-(w.created??1/0)||fe(p,w));const i=s.key==="validate"||s.key==="decide"?a.filter(p=>p.turn==="you").length:a.length;return{...s,nodes:a,count:i}}),m=s=>u.find(a=>a.key===s).count,j=l.filter(s=>s.turn==="you"),b=j.filter(s=>s.created!=null).sort((s,a)=>s.created-a.created)[0]||null,f={total:r===oe?m("validate")+m("merge")+m("decide")+m("manual"):j.length,validate:m("validate"),merge:m("merge"),held:l.filter(s=>s.held).length,decide:m("decide"),manual:m("manual"),parked:l.filter(s=>s.turn==="parked").length,oldest:b},v=d-(Ne-1)*ne,h=(t||[]).map(s=>q(s.createdAt)).filter(s=>s!=null),x=h.length?ve(Math.min(...h)-ie*ne):null,S=Array.from({length:Ne},(s,a)=>{const i=ve(v+a*ne+432e5);return{start:i,count:0,keys:[],known:x==null||i>=x}});for(const s of t||[]){const a=q(s.merged_at);if(a==null||a<v||!s.key)continue;const i=S.find((p,w)=>a>=p.start&&(w===S.length-1||a<S[w+1].start));i&&(i.count+=1,i.keys.push(s.key),i.known=!0)}return{stages:u,nodes:l,waiting:f,shipped:S,today:{filed:l.filter(s=>s.newToday).sort(fe),shipped:l.filter(s=>s.stage==="shipped"&&s.at!=null&&s.at>=d)}}}function Oe(t){return{you:0,pipeline:1,parked:2,done:3}[t.turn]??4}function ms(t,n){const r=q(t?.last_push_at);if(r!=null)return{at:r,kind:"push"};const d=(n||[]).map(l=>q(l.synced_at)).filter(l=>l!=null);return d.length?{at:Math.max(...d),kind:"change"}:null}function Z(t,n=Date.now()){if(t==null)return"";const r=Math.max(0,Math.round((n-t)/1e3));if(r<45)return"just now";const d=Math.round(r/60);if(d<60)return`${d} min ago`;const l=Math.round(d/60);if(l<36)return`${l} h ago`;const u=Math.round(l/24);return`${u} day${u===1?"":"s"} ago`}function re(t,n){return`/administration/claims?tab=${oe.find(d=>d.key===t)?.tab||"merge"}${n?`&focus=${encodeURIComponent(n)}`:""}`}const gs=2700*1e3,je=18,wt={you:"bg-amber-100 text-amber-950 ring-amber-300 hover:bg-amber-200",held:"bg-white text-amber-900 ring-transparent outline-dashed outline-[1.5px] -outline-offset-[1.5px] outline-amber-500 hover:bg-amber-50",pipeline:"bg-white text-gray-700 ring-gray-300 hover:bg-gray-50",building:"bg-sky-50 text-sky-900 ring-sky-300 hover:bg-sky-100",parked:"bg-gray-100 text-gray-500 ring-gray-200 hover:bg-gray-200",done:"bg-emerald-50 text-emerald-900 ring-emerald-200 hover:bg-emerald-100"},xs={you:{label:"You",cls:"bg-amber-100 text-amber-900"},pipeline:{label:"Pipeline",cls:"bg-gray-100 text-gray-600"},done:{label:"Done",cls:"bg-emerald-50 text-emerald-800"}},fs=[["validate"],["queued"],["building"],["decide","manual"],["merge"],["shipped"]],Nt=t=>t.held?"held":t.stage==="building"||t.round?"building":t.turn,Ue={weekday:"short",day:"numeric",month:"short"};function vs(t,n){const[r,d]=o.useState(t),[l,u]=o.useState(!1),[m,j]=o.useState(()=>Date.parse(t.read_at));return o.useEffect(()=>{if(n)return;let b=!1;const f=async()=>{if(document.visibilityState==="visible")try{const h=await fetch("/api/admin/pipeline/live",{cache:"no-store"});if(!h.ok)throw new Error(String(h.status));const x=await h.json();if(b)return;d(x),u(!1),j(Date.parse(x.read_at)||Date.now())}catch{b||u(!0)}},v=setInterval(f,ds);return window.addEventListener("focus",f),document.addEventListener("visibilitychange",f),()=>{b=!0,clearInterval(v),window.removeEventListener("focus",f),document.removeEventListener("visibilitychange",f)}},[!!n]),n?{snap:n,failed:!!n.offline,checkedAt:Date.parse(n.read_at)}:{snap:r,failed:l,checkedAt:m}}function js(t){const n=o.useRef(null),[r,d]=o.useState(()=>new Set),l=t.map(u=>`${u.key}:${u.stage}`).join(",");return o.useEffect(()=>{const u=new Set(l?l.split(","):[]);n.current&&d(new Set([...u].filter(m=>!n.current.has(m)).map(m=>m.split(":")[0]))),n.current=u},[l]),r}function ys({initial:t,snapshot:n=null,workspace:r=!1,children:d=null,activity:l=null}){const{snap:u,failed:m,checkedAt:j}=vs(t,n),[b,f]=o.useState(()=>Date.parse(t.read_at)),[v,h]=o.useState(!1);o.useEffect(()=>{h(!0),f(Date.now());const $=setInterval(()=>f(Date.now()),15e3);return()=>clearInterval($)},[]),o.useEffect(()=>{f(Date.now())},[j]);const x=o.useMemo(()=>{const $=ps(u.tickets,b,u.stages);if(r){const E=u.historyStart?new Date(u.historyStart):null;E&&E.setHours(0,0,0,0),$.shipped.forEach(y=>{y.known=y.count>0||!!E&&y.start>=E.getTime()})}return $},[u.tickets,u.stages,u.historyStart,b,r]),S=o.useMemo(()=>Ms(x.nodes.map($=>$.key)),[x.nodes]),s=js(x.nodes),a=ms(u.sync,u.tickets),i=$=>x.stages.find(E=>E.key===$),[p,w]=o.useState(null),C=o.useCallback(($,E,y=!1)=>w({node:$,rect:E.getBoundingClientRect(),pinned:y}),[]),R=o.useCallback(()=>w($=>$?.pinned?$:null),[]),A=o.useCallback(()=>w(null),[]);o.useEffect(()=>{if(!p)return;const $=()=>w(null),E=y=>{y.key==="Escape"&&w(null)};return window.addEventListener("scroll",$,!0),window.addEventListener("keydown",E),()=>{window.removeEventListener("scroll",$,!0),window.removeEventListener("keydown",E)}},[p]);const N=p&&x.nodes.find($=>$.key===p.node.key),g={prefix:S,arrived:s,mounted:v,onShow:C,onHide:R,pinnedKey:p?.pinned?p.node.key:null},_=x.waiting,I=i("building").count+x.nodes.filter($=>$.stage!=="building"&&$.round).length;return e.jsxs("div",{className:"min-h-full bg-gray-50","data-live-page":!0,children:[e.jsx("style",{children:zs}),e.jsxs("div",{className:"mx-auto max-w-[1600px] px-4 pb-12 pt-16 sm:px-8 md:pt-8",children:[e.jsxs("header",{className:"flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"Pipeline live"}),!r&&e.jsx("p",{className:"mt-1 max-w-2xl text-sm text-gray-600",children:"Every ticket of the bug pipeline on its stage, from intake to shipped. Amber is your move."})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[r?e.jsxs("span",{className:`uh-live-connection ${m?"offline":""}`,children:[e.jsx("span",{className:"uh-dot"}),m?"Reconnecting · last known state":"Live · updates automatically"]}):e.jsx(bs,{sync:a,now:b,failed:m,mounted:v}),e.jsxs(J,{href:r?u.reviewHref:"/administration/claims",className:"inline-flex min-h-[36px] items-center gap-1 rounded-full bg-white px-3.5 text-sm font-medium text-gray-700 ring-1 ring-gray-200 transition-colors hover:bg-gray-100 hover:text-gray-900",children:[r?"Review findings":"Open the cockpit",e.jsx(de,{className:"h-4 w-4 text-gray-400","aria-hidden":!0})]})]})]}),d,e.jsxs("section",{"aria-label":"Summary",className:"mt-6 grid grid-cols-2 gap-3 lg:grid-cols-[minmax(0,2.4fr)_minmax(0,1fr)_minmax(0,1fr)]",children:[e.jsx("div",{"data-waiting-on-you":!0,className:"col-span-2 rounded-2xl lg:col-span-1 bg-amber-50 p-5 ring-1 ring-amber-300",children:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center",children:[e.jsxs("div",{className:"sm:w-48 sm:shrink-0",children:[e.jsx("p",{className:"text-sm font-semibold text-amber-900",children:"Waiting on you"}),e.jsx("p",{"data-waiting-total":!0,className:"mt-1 text-5xl font-semibold leading-none tracking-tight text-amber-950 tabular-nums",children:e.jsx(ue,{value:_.total})}),e.jsx("p",{className:"mt-2 text-xs text-amber-800",children:_.oldest?e.jsxs(e.Fragment,{children:["Longest wait:"," ",e.jsx(J,{href:_.oldest.href||re(_.oldest.stage,_.oldest.key),"data-oldest":!0,className:"font-semibold underline decoration-amber-400 underline-offset-2 hover:decoration-amber-700",children:_.oldest.key}),", filed ",Z(_.oldest.created,b)]}):r?_.total?"Review the decisions and blockers below":"No outstanding decisions or blockers":"tickets on your tabs"})]}),e.jsxs("div",{className:"grid flex-1 grid-cols-2 gap-2",children:[e.jsx(le,{tab:"validate",label:"To validate",value:_.validate,href:i("validate").href}),e.jsx(le,{tab:"decide",label:"Needs decision",value:_.decide,href:i("decide").href}),e.jsx(le,{tab:"manual",label:r?"Blocked":"Manual",value:_.manual,href:i("manual").href}),e.jsx(le,{tab:"merge",label:r?"Review later":"Ready to merge",value:r?_.parked:_.merge,href:r?u.reviewHref:i("merge").href,note:_.held?`${_.held} held`:null})]})]})}),e.jsx(Fe,{label:"Pipeline working",value:I+i("queued").count+(r?i("merge").count:0),lines:r?[`${I} investigating · ${i("merge").count} verifying`,`${i("queued").count} queued`]:[`${I} building now`,`${i("queued").count} in the fix queue`]}),e.jsx(Fe,{label:`${r?"Accepted":"Shipped"}, ${ie} days`,value:i("shipped").count,tone:"done",lines:v?[`${x.today.shipped.length} today`,`${x.today.filed.length} new item${x.today.filed.length===1?"":"s"} today`]:[" "," "]})]}),e.jsxs("section",{"aria-labelledby":"flow-title",className:"mt-8",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[e.jsx("h2",{id:"flow-title",className:"text-sm font-semibold text-gray-900",children:"Flow"}),e.jsx(ks,{looks:new Set(x.nodes.map(Nt)),filedToday:v&&x.today.filed.length>0})]}),e.jsx("div",{"data-flow":!0,className:"mt-3 grid grid-cols-1 gap-3 md:grid-cols-3 xl:grid-cols-6 xl:gap-5",children:(r?[["validate"],["queued"],["building"],["merge"],["decide","manual"],["shipped"]]:fs).map(($,E)=>e.jsxs("div",{className:"relative flex min-w-0 flex-col gap-3",children:[E>0&&e.jsx(ws,{}),$.map(y=>e.jsx(Ns,{stage:i(y),nodeProps:g,now:b},y))]},$.join("+")))})]}),l,e.jsxs("section",{className:"mt-8 grid grid-cols-1 gap-3 lg:grid-cols-[minmax(0,2fr)_minmax(0,1fr)]",children:[e.jsx(_s,{days:x.shipped,mounted:v,workspace:r}),e.jsx(Rs,{today:x.today,mounted:v,nodeProps:g,workspace:r})]})]}),p&&N&&e.jsx(Ss,{node:N,rect:p.rect,pinned:p.pinned,now:b,onClose:A,workspace:r})]})}function bs({sync:t,now:n,failed:r,mounted:d}){const l=!t||n-t.at>gs,u=t?`${t.kind==="push"?"Synced":"Last change"} ${Z(t.at,n)}`:"No sync received yet";return e.jsxs("p",{"data-sync-pill":!0,title:t&&d?new Date(t.at).toLocaleString():void 0,className:`inline-flex min-h-[36px] items-center gap-2 rounded-full px-3.5 text-sm ring-1 ${l||r?"bg-amber-50 text-amber-900 ring-amber-200":"bg-white text-gray-700 ring-gray-200"}`,children:[e.jsxs("span",{className:"relative flex h-2 w-2","aria-hidden":!0,children:[!l&&!r&&e.jsx("span",{className:"live-ping absolute inline-flex h-full w-full rounded-full bg-emerald-400"}),e.jsx("span",{className:`relative inline-flex h-2 w-2 rounded-full ${l||r?"bg-amber-500":"bg-emerald-500"}`})]}),e.jsxs("span",{children:[r?"Could not refresh, retrying. ":"",u,l&&t?": the pipeline may be stopped":""]})]})}function le({tab:t,label:n,value:r,note:d,href:l}){return e.jsxs(J,{href:l||re(t),"data-wait-tile":t,className:"flex min-h-[48px] items-center gap-2.5 rounded-xl bg-white/80 px-3 py-2 ring-1 ring-amber-200 transition-colors hover:bg-white hover:ring-amber-400",children:[e.jsx("span",{"data-wait-count":!0,className:"w-9 shrink-0 text-2xl font-semibold leading-none text-amber-950 tabular-nums",children:e.jsx(ue,{value:r})}),e.jsxs("span",{className:"min-w-0 leading-tight",children:[e.jsx("span",{className:"block text-[13px] font-medium text-amber-950",children:n}),d&&e.jsx("span",{className:"block text-xs text-amber-800",children:d})]}),e.jsx(de,{className:"ml-auto h-4 w-4 shrink-0 text-amber-400","aria-hidden":!0})]})}function Fe({label:t,value:n,lines:r,tone:d}){return e.jsxs("div",{className:"rounded-2xl bg-white p-4 ring-1 ring-gray-200 sm:p-5",children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:t}),e.jsx("p",{className:`mt-1 text-4xl font-semibold leading-none tracking-tight tabular-nums ${n?d==="done"?"text-emerald-800":"text-gray-900":"text-gray-400"}`,children:e.jsx(ue,{value:n})}),e.jsx("ul",{className:"mt-3 space-y-0.5 text-xs text-gray-600",children:r.map((l,u)=>e.jsx("li",{children:l},u))})]})}function ue({value:t}){return e.jsx("span",{className:"live-num inline-block",children:t},t)}function ks({looks:t,filedToday:n}){const d=[["you","Your move"],["held","Held, your call"],["pipeline","Pipeline's move"],["building","Building"],["parked","Parked"],["done","Shipped"]].filter(([l])=>l==="you"||t.has(l));return e.jsxs("ul",{"aria-label":"Legend",className:"flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-gray-600",children:[d.map(([l,u])=>e.jsxs("li",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:`inline-block h-3 w-4 rounded ring-1 ring-inset ${wt[l]}`,"aria-hidden":!0}),u]},l)),n&&e.jsxs("li",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-indigo-500","aria-hidden":!0}),"Filed today"]})]})}function ws(){return e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":!0,className:"absolute -left-[18px] top-[22px] hidden h-5 w-5 items-center justify-center text-gray-300 xl:flex",children:e.jsx(rs,{className:"h-4 w-4"})}),e.jsx("span",{"aria-hidden":!0,className:"-mb-1 -mt-1 flex justify-center text-gray-300 md:hidden",children:e.jsx(as,{className:"h-4 w-4"})})]})}function Ns({stage:t,nodeProps:n,now:r}){const d=xs[t.owner],l=t.owner==="you";let u=t.nodes,m=0;t.key==="shipped"&&u.length>je&&(m=u.length-je,u=u.slice(0,je));const j=t.key==="validate"?u.filter(h=>h.turn==="parked"):[],b=t.key==="decide"?u.filter(h=>h.turn==="pipeline"):[],f=u.filter(h=>!j.includes(h)&&!b.includes(h)),v=t.key==="shipped"&&t.nodes[0]?.at;return e.jsxs("div",{"data-stage":t.key,className:`flex min-w-0 flex-col rounded-2xl bg-white ring-1 ${l&&t.count?"ring-amber-300":"ring-gray-200"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2 px-3 pb-2 pt-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:`inline-block rounded-full px-1.5 py-px text-[11px] font-medium ${d.cls}`,children:d.label}),e.jsx("h3",{className:"mt-1 truncate text-[13px] font-semibold text-gray-900",children:t.label})]}),e.jsx("span",{"data-stage-count":!0,className:`text-2xl font-semibold leading-none tabular-nums ${l&&t.count?"text-amber-950":"text-gray-900"}`,children:e.jsx(ue,{value:t.count})})]}),e.jsx("p",{className:"px-3 text-xs leading-snug text-gray-500",children:v?`Latest ${Z(v,r)}`:t.hint}),e.jsxs("div",{className:"flex flex-1 flex-col gap-2 px-3 pb-3 pt-2.5",children:[f.length>0&&e.jsx(ae,{nodes:f,phoneCap:t.key==="shipped"?9:null,...n}),b.length>0&&e.jsx(qe,{label:`${b.length} answered, pipeline's move`,children:e.jsx(ae,{nodes:b,...n})}),j.length>0&&e.jsx(qe,{label:`${j.length} parked with Later`,children:e.jsx(ae,{nodes:j,...n})}),!u.length&&e.jsx("p",{className:"text-xs text-gray-500",children:"Nothing here right now."})]}),e.jsxs(J,{href:t.href||re(t.key),className:"mt-auto flex min-h-[36px] items-center justify-between border-t border-gray-100 px-3 text-xs font-medium text-gray-500 transition-colors hover:text-gray-900",children:[t.linkLabel||(m?`${m} more on the cockpit`:"Open on the cockpit"),e.jsx(de,{className:"h-4 w-4 text-gray-300","aria-hidden":!0})]})]})}function qe({label:t,children:n}){return e.jsxs("div",{className:"border-t border-dashed border-gray-200 pt-2",children:[e.jsx("p",{className:"mb-1.5 text-xs text-gray-500",children:t}),n]})}function ae({nodes:t,phoneCap:n=null,...r}){return e.jsx("ul",{className:"flex flex-wrap gap-2 sm:gap-[5px]",children:t.map((d,l)=>e.jsx(Cs,{node:d,hideOnPhone:n!=null&&l>=n,...r},d.key))})}function Cs({node:t,prefix:n,arrived:r,mounted:d,onShow:l,onHide:u,pinnedKey:m,hideOnPhone:j}){const b=o.useRef(!1),f=t.displayKey||(n&&t.key.startsWith(n)?t.key.slice(n.length):t.key);return e.jsx("li",{className:j?"hidden sm:block":void 0,children:e.jsxs(J,{href:t.href||re(t.stage,t.key),"data-live-node":t.key,"data-turn":t.turn,"aria-label":`${t.key}${t.held?" (held)":""}: ${t.status}`,onPointerDown:v=>{b.current=v.pointerType==="touch"},onMouseEnter:v=>l(t,v.currentTarget),onMouseLeave:u,onFocus:v=>l(t,v.currentTarget),onBlur:u,onClick:v=>{b.current&&m!==t.key&&(v.preventDefault(),l(t,v.currentTarget,!0))},className:`relative inline-flex h-9 min-w-[48px] items-center justify-center rounded-md px-1 font-mono text-[13px] sm:h-7 sm:min-w-[42px] sm:text-[12px] tabular-nums ring-1 ring-inset transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-gray-900 ${wt[Nt(t)]} ${t.turn==="you"?"font-semibold":""} ${r.has(t.key)?"live-arrive":""}`,children:[f,(t.stage==="building"||t.round)&&e.jsx("span",{className:"live-pulse absolute -right-0.5 -top-0.5 h-2 w-2 rounded-full bg-sky-500 ring-2 ring-white","aria-hidden":!0}),d&&t.newToday&&!(t.stage==="building"||t.round)&&e.jsx("span",{className:"absolute -right-0.5 -top-0.5 h-2 w-2 rounded-full bg-indigo-500 ring-2 ring-white","aria-hidden":!0})]})})}function Ss({node:t,rect:n,pinned:r,now:d,onClose:l,workspace:u=!1}){const j=typeof window>"u"?1440:window.innerWidth,b=typeof window>"u"?900:window.innerHeight,f=Math.max(8,Math.min(n.left+n.width/2-288/2,j-288-8)),v=n.bottom+8,h=v+170>b?{left:f,bottom:b-n.top+8,width:288}:{left:f,top:v,width:288},x=t.stage==="shipped"?t.at?`${u?"Accepted":"Merged"} ${Z(t.at,d)}`:null:t.stage==="manual"?t.at?`Stopped ${Z(t.at,d)}`:null:t.created?`Filed ${Z(t.created,d)}`:null;return e.jsxs(e.Fragment,{children:[r&&e.jsx("button",{type:"button","aria-label":"Close",onClick:l,className:"fixed inset-0 z-40 cursor-default bg-transparent"}),e.jsxs("div",{role:r?"dialog":"tooltip","data-node-detail":t.key,style:h,className:`fixed z-50 rounded-xl bg-white p-3.5 text-left shadow-lg ring-1 ring-gray-200 ${r?"":"pointer-events-none"}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("p",{className:"font-mono text-xs font-semibold text-gray-900",children:t.key}),r&&e.jsx("button",{type:"button",onClick:l,"aria-label":"Close",className:"-m-1 rounded p-1 text-gray-400 hover:text-gray-700",children:e.jsx(os,{className:"h-4 w-4"})})]}),t.title&&e.jsx("p",{className:"mt-1 line-clamp-2 text-sm font-medium leading-snug text-gray-900",children:t.title}),e.jsx("p",{className:`mt-1.5 line-clamp-3 text-xs leading-relaxed ${t.turn==="you"?"text-amber-900":"text-gray-600"}`,children:t.status}),(x||t.flags.length>0)&&e.jsx("p",{className:"mt-1.5 text-[11px] text-gray-500",children:[x,t.newToday?"new today":null,...t.flags].filter(Boolean).join(" · ")}),r?e.jsxs(J,{href:t.href||re(t.stage,t.key),className:"mt-3 flex min-h-[40px] items-center justify-center gap-1 rounded-lg bg-gray-900 text-sm font-medium text-white",children:["Open the card ",e.jsx(de,{className:"h-4 w-4","aria-hidden":!0})]}):e.jsx("p",{className:"mt-2 text-[11px] text-gray-500",children:"Click to open the card"})]})]})}function $s(t){if(t<=4)return 4;const n=t<=10?2:t<=25?5:t<=50?10:20;return Math.ceil(t/n)*n}function _s({days:t,mounted:n,workspace:r=!1}){const d=r?"accepted":"shipped",[l,u]=o.useState(null),m=$s(Math.max(0,...t.map(h=>h.count))),j=t.reduce((h,x)=>h+x.count,0),b=t.reduce((h,x,S)=>x.count>(t[h]?.count||0)?S:h,0),f=t.filter(h=>!h.known).length,v=160;return e.jsxs("figure",{"data-shipped-chart":!0,className:"rounded-2xl bg-white p-5 ring-1 ring-gray-200",children:[e.jsxs("figcaption",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[e.jsx("span",{className:"text-sm font-semibold text-gray-900",children:r?"Accepted per day":"Shipped per day"}),e.jsx("span",{className:"text-xs text-gray-500",children:n?`${j} in the last ${Ne} days`:" "})]}),e.jsxs("div",{className:"relative mt-4",style:{height:v+24},children:[[0,.5,1].map(h=>e.jsxs("div",{className:"absolute left-7 right-0 flex items-center",style:{bottom:24+h*v},children:[e.jsx("span",{className:"absolute -left-7 w-6 -translate-y-px text-right text-[11px] tabular-nums text-gray-500",children:n?Math.round(m*h):""}),e.jsx("span",{className:`h-px w-full ${h===0?"bg-gray-300":"bg-gray-100"}`})]},h)),n&&e.jsx("div",{className:"absolute bottom-0 left-7 right-0 top-0 flex items-stretch gap-[2px]",children:t.map((h,x)=>{const S=x===t.length-1,s=h.count?Math.max(3,h.count/m*v):0,a=new Date(h.start),i=S||x%2===(t.length-1)%2,p=i&&t.findIndex((C,R)=>R%2===(t.length-1)%2)===x,w=`${a.toLocaleDateString(void 0,Ue)}: ${h.known?`${h.count} ${d}`:"no record"}`;return e.jsxs("div",{"data-day":`${a.getFullYear()}-${String(a.getMonth()+1).padStart(2,"0")}-${String(a.getDate()).padStart(2,"0")}`,"data-count":h.count,"data-known":h.known?"yes":"no",tabIndex:0,"aria-label":w,className:"relative flex min-w-0 flex-1 flex-col justify-end rounded-sm focus:outline-none focus-visible:ring-2 focus-visible:ring-gray-900",onMouseEnter:()=>u(x),onMouseLeave:()=>u(null),onFocus:()=>u(x),onBlur:()=>u(null),onClick:()=>u(l===x?null:x),children:[e.jsxs("div",{className:`relative mx-auto flex w-full flex-col justify-end ${S?"rounded-t-md bg-gray-50":""}`,style:{height:v},children:[!h.known&&e.jsx("div",{"aria-hidden":!0,className:"absolute inset-x-0 bottom-0 top-0 [background-image:repeating-linear-gradient(135deg,rgb(243_244_246)_0_2px,transparent_2px_7px)]"}),(x===b||S)&&h.known&&(h.count>0||S)&&e.jsx("span",{className:"relative mb-1 text-center text-[11px] font-medium tabular-nums text-gray-700",children:h.count}),e.jsx("div",{className:`relative mx-auto w-full max-w-[28px] rounded-t-[4px] ${S?"bg-emerald-700":"bg-emerald-500"} ${l===x?"opacity-80":""}`,style:{height:s}})]}),e.jsx("span",{className:`block h-6 whitespace-nowrap pt-1.5 text-center text-[11px] leading-none tabular-nums ${S?"font-semibold text-gray-800":"text-gray-500"}`,children:i&&(S?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sm:hidden",children:a.getDate()}),e.jsx("span",{className:"hidden sm:inline",children:"Today"})]}):p?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"sm:hidden",children:a.getDate()}),e.jsx("span",{className:"hidden sm:inline",children:a.toLocaleDateString(void 0,{day:"numeric",month:"short"})})]}):a.getDate())}),l===x&&e.jsxs("div",{role:"tooltip",className:`pointer-events-none absolute bottom-full z-10 mb-1 w-max max-w-[220px] rounded-lg bg-gray-900 px-2.5 py-1.5 text-xs text-white shadow-lg ${x>t.length/2?"right-0":"left-0"}`,children:[e.jsx("p",{className:"font-medium",children:a.toLocaleDateString(void 0,Ue)}),e.jsx("p",{className:"text-gray-300",children:h.known?`${h.count} ${d}${h.count?`: ${h.keys.slice(0,4).join(", ")}${h.keys.length>4?` and ${h.keys.length-4} more`:""}`:""}`:"Before this page's records"})]})]},h.start)})})]}),e.jsxs("p",{className:"mt-3 max-w-prose text-xs leading-relaxed text-gray-500",children:[r?"Accepted findings and applied guidelines, counted on the date of your decision.":"Counted from each ticket’s merge date on GitHub.",n&&f>0?" Hatched days come before this page's records: no data, not zero.":""]})]})}function Rs({today:t,mounted:n,nodeProps:r,workspace:d=!1}){return e.jsxs("div",{"data-today":!0,className:"self-start rounded-2xl bg-white p-5 ring-1 ring-gray-200",children:[e.jsx("p",{className:"text-sm font-semibold text-gray-900",children:"Today"}),e.jsxs("div",{className:"mt-3 space-y-4",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"mb-1.5 text-xs text-gray-600",children:[e.jsx("span",{className:"font-semibold tabular-nums text-gray-900",children:n?t.filed.length:""})," ",d?"items started today":"filed on Jira today, still open"]}),n&&(t.filed.length?e.jsx(ae,{nodes:t.filed,...r}):e.jsx("p",{className:"text-xs text-gray-500",children:"None yet"}))]}),e.jsxs("div",{children:[e.jsxs("p",{className:"mb-1.5 text-xs text-gray-600",children:[e.jsx("span",{className:"font-semibold tabular-nums text-gray-900",children:n?t.shipped.length:""})," ",d?"accepted today":"shipped today"]}),n&&(t.shipped.length?e.jsx(ae,{nodes:t.shipped,...r}):e.jsx("p",{className:"text-xs text-gray-500",children:"None yet"}))]})]})]})}function Ms(t){if(!t.length)return"";const n=/^[A-Z][A-Z0-9]+-/.exec(t[0])?.[0]||"";return n&&t.every(r=>r.startsWith(n))?n:""}const zs=`
7
+ @keyframes live-ping { 75%, 100% { transform: scale(2.2); opacity: 0; } }
8
+ @keyframes live-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
9
+ @keyframes live-arrive { from { box-shadow: 0 0 0 3px rgb(99 102 241 / .45); } to { box-shadow: 0 0 0 0 rgb(99 102 241 / 0); } }
10
+ @keyframes live-num { from { opacity: .25; } to { opacity: 1; } }
11
+ .live-ping { animation: live-ping 2s cubic-bezier(0, 0, .2, 1) infinite; }
12
+ .live-pulse { animation: live-pulse 1.6s ease-in-out infinite; }
13
+ .live-arrive { animation: live-arrive 2.4s ease-out 1; }
14
+ .live-num { animation: live-num .6s ease-out 1; }
15
+ @media (prefers-reduced-motion: reduce) { .live-ping, .live-pulse, .live-arrive, .live-num { animation: none; } }
16
+ `;function As(t,n,r,d=!1){const l=new Set(n.map(a=>a.id)),u=new Set(t.workspace.projects.filter(a=>r==="all"||a.id===r).flatMap(a=>a.repos.map(i=>i.name))),m=a=>r==="all"||l.has(a.pipelineId)||u.has(a.finding?.repo),j=(a,i={})=>{const p=new URLSearchParams({...r==="all"?{}:{project:r},...i});return`/${a}${p.size?`?${p}`:""}`},b=[{key:"validate",label:"To validate",owner:"you",hint:"Findings awaiting your go-ahead.",href:j("review",{tab:"validate"}),linkLabel:"Review validation"},{key:"queued",label:"Queued",owner:"pipeline",hint:"Investigations waiting for the engine.",href:"#live-activity",linkLabel:"See activity"},{key:"building",label:"Investigating",owner:"pipeline",hint:"Reading signals and tracing their cause.",href:"#live-activity",linkLabel:"See agent steps"},{key:"merge",label:"Verifying",owner:"pipeline",hint:"Checking evidence and challenging findings.",href:"#live-activity",linkLabel:"See verification"},{key:"decide",label:"Needs decision",owner:"you",hint:"Prepared findings and guideline proposals.",href:j("review",{tab:"decide"}),linkLabel:"Open review"},{key:"manual",label:"Blocked",owner:"you",hint:"Access, capacity, or a run needs attention.",href:"#live-activity",linkLabel:"Inspect blockers"},{key:"shipped",label:"Accepted",owner:"done",hint:"Findings accepted and guidelines applied in the last 7 days.",href:j("review",{tab:"shipped"}),linkLabel:"Review accepted"}],f=t.runs.filter(m),v=(t.pipelines.queued||[]).filter(a=>r==="all"||l.has(a.pipelineId)),h=[];for(const a of t.cockpit.cards.filter(m)){const i=a.finding;if(!i||a.ruling?.ruling==="dismiss")continue;const p=a.ruling?.ruling,w=["pending","later"].includes(i.validation?.state),C=p==="file"?"shipped":w?"validate":"decide",R=p==="park"||i.validation?.state==="later";h.push({key:`F-${i.id}`,title:a.title,live_stage:C,live_href:j("review",{finding:i.id}),live_state:{turn:p==="file"?"done":R?"parked":"you",status:p==="file"?"You accepted this finding.":R?"Set aside for later review.":w?"Waiting for your validation.":"Evidence prepared. Waiting for your decision."},jira_created:i.createdAt,createdAt:i.createdAt,merged_at:p==="file"?a.ruling.at:null})}for(const a of(t.cockpit.proposals||[]).filter(m)){if(!["pending","parked","applied"].includes(a.status))continue;const i=a.status==="applied";h.push({key:`G-${a.id}`,title:a.title,live_stage:i?"shipped":"decide",live_href:j("review",{tab:i?"shipped":"decide",proposal:a.id,pipeline:a.pipelineId}),live_state:{turn:i?"done":a.status==="parked"?"parked":"you",status:i?"Guideline improvement applied.":"Review the proposed guideline change."},createdAt:a.createdAt,jira_created:a.createdAt,merged_at:i?a.rulings?.at(-1)?.at:null})}const x=f.filter(a=>!["done","failed"].includes(a.phase)),S=[];for(const a of x){const i=a.steps?.find(C=>C.status==="running"),p=i&&["gate","adversarial","dedupe"].includes(i.step),w=a.phase==="parked";h.push({key:`RUN-${a.id}`,title:a.pipelineName||a.pipelineId,live_stage:w?"manual":p?"merge":"building",live_href:`#run-${a.id}`,live_state:{turn:w?"parked":"pipeline",status:w?`Waiting for capacity${a.parkedUntil?` until ${new Date(a.parkedUntil).toLocaleString()}`:""}.`:i?`${i.step.replaceAll("_"," ")}: ${i.clusterTitle}`:a.phase.replaceAll("_"," ")},createdAt:a.startedAt,jira_created:a.startedAt})}for(const a of v)h.push({key:`QUEUE-${a.pipelineId}`,title:n.find(i=>i.id===a.pipelineId)?.name||a.pipelineId,live_stage:"queued",live_href:"#live-activity",live_state:{turn:"pipeline",status:"Queued behind the current investigation."},createdAt:a.at,jira_created:a.at});for(const a of n){if(x.some(N=>N.pipelineId===a.id)||v.some(N=>N.pipelineId===a.id))continue;const i=f.find(N=>N.pipelineId===a.id),p=t.workspace.projects.flatMap(N=>N.repos).filter(N=>(!a.repos||a.repos.includes(N.name))&&!N.available),w=a.sources.filter(N=>N!=="repos"&&N!=="*"&&!t.workspace.connections.some(g=>g.id===N&&g.configured&&g.probe?.ok)),C=p.length?`Repository unavailable: ${p.map(N=>N.name).join(", ")}`:t.workspace.provider.authenticated?w.length?`Read access needed: ${w.join(", ")}`:i?.phase==="failed"?i.error||"Last investigation failed. Inspect its steps.":"":t.workspace.provider.detail;if(!C)continue;const R=p.length?"Repository access":t.workspace.provider.authenticated?w.length?"Source access":"Failed run":"AI account",A=`#blocker-${a.id}`;S.push({id:a.id,name:a.name,detail:C,href:A,kind:R}),h.push({key:`BLOCKER-${a.id}`,displayKey:R,title:`${a.name} · ${R}`,live_stage:"manual",live_href:A,live_state:{turn:"you",status:C}})}const s=[...f.map(a=>a.startedAt),...h.map(a=>a.createdAt)].filter(Boolean).sort();return{tickets:h,stages:b,read_at:new Date().toISOString(),historyStart:s[0]||null,sync:null,reviewHref:j("review",{tab:"decide"}),offline:d,runs:f,queued:v,active:x,blocked:S,agents:x.flatMap(a=>(a.steps||[]).filter(i=>i.status==="running"&&i.model)),cost:f.reduce((a,i)=>a+(i.costUsd||0),0),settingsHref:j("pipelines"),projectsHref:j("projects")}}const te=t=>t?.replaceAll("_"," ")||"",ce=t=>t?new Date(t).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):"";function Es({data:t,pipelines:n,project:r,offline:d,act:l,chatFirst:u=!1}){const m=o.useMemo(()=>{const i=As(t,n,r,d);return u?{...i,settingsHref:"/chat?message=Show%20my%20pipelines",projectsHref:"/chat?message=Help%20me%20run%20a%20pipeline"}:i},[t,n,r,d,u]),[j,b]=o.useState(""),[f,v]=o.useState(!1),[h,x]=o.useState(""),S=m.blocked.find(i=>i.id===j),s=t.workspace.provider,a=e.jsxs("section",{id:"live-activity",className:"uh-live-activity",children:[e.jsxs("div",{className:"uh-section-heading",children:[e.jsx("div",{children:e.jsx("h2",{children:"Engine activity"})}),!u&&e.jsx("a",{className:"uh-btn",href:"/runs",children:"Full run history"}),e.jsxs("a",{className:"uh-btn",href:m.settingsHref,children:[e.jsx(qt,{size:15}),u?"Manage in chat":"Manage pipelines"]})]}),m.blocked.map(i=>e.jsxs("a",{className:"uh-live-blocker",href:i.href,children:[e.jsx("span",{className:"uh-dot warn"}),e.jsxs("div",{children:[e.jsx("strong",{children:i.name}),e.jsx("p",{children:i.detail})]}),e.jsx(O,{size:17})]},i.id)),m.queued.map((i,p)=>e.jsxs("div",{className:"uh-live-queued",children:[e.jsx(Le,{size:16}),e.jsxs("span",{children:["#",p+1," in queue"]}),e.jsx("strong",{children:n.find(w=>w.id===i.pipelineId)?.name||i.pipelineId}),e.jsx("span",{children:ce(i.at)})]},i.pipelineId)),!m.runs.length&&e.jsxs("div",{className:"uh-live-empty",children:[e.jsx(Ce,{size:22}),e.jsx("h3",{children:"No runs yet"}),e.jsx("p",{children:m.blocked.length?"Resolve the blocker above to run the pipeline.":"Start a pipeline to see its progress here."}),e.jsxs("a",{className:"uh-link",href:m.projectsHref,children:[u?"Open chat":"Open projects"," ",e.jsx(O,{size:13})]})]}),m.runs.slice(0,12).map(i=>{const p=!["done","failed"].includes(i.phase),w=i.steps||[];return e.jsxs("details",{className:"uh-live-run",id:`run-${i.id}`,open:p||void 0,children:[e.jsxs("summary",{children:[i.phase==="failed"?e.jsx(Wt,{size:18}):i.phase==="parked"?e.jsx(Le,{size:18}):p?e.jsx(X,{size:18,className:"uh-spin"}):e.jsx(Rt,{size:18}),e.jsxs("div",{children:[e.jsx("strong",{children:i.pipelineName||i.pipelineId}),e.jsxs("span",{children:[te(i.phase)," · ",ce(i.startedAt)]})]}),e.jsxs("span",{children:[i.signalsCollected??0," signals"]}),e.jsxs("span",{children:[i.findings??0," findings"]}),e.jsxs("span",{children:["$",(i.costUsd||0).toFixed(3)]}),e.jsx(be,{size:16})]}),e.jsxs("div",{className:"uh-live-run-body",children:[e.jsx("div",{className:"uh-live-phases",children:(i.phases||[]).map((C,R)=>e.jsxs("div",{"data-state":C.status,children:[e.jsx("span",{className:`uh-dot ${C.status==="failed"?"warn":""}`}),e.jsx("strong",{children:te(C.phase)}),e.jsx("span",{children:C.status})]},R))}),w.length>0&&e.jsx("div",{className:"uh-live-steps",children:w.map((C,R)=>e.jsxs("div",{children:[e.jsx("span",{className:`uh-live-step-state ${C.status}`,children:te(C.status)}),e.jsxs("div",{children:[e.jsxs("strong",{children:[te(C.step)," · ",C.clusterTitle||"Investigation"]}),C.note&&e.jsx("p",{children:C.note}),e.jsxs("small",{children:[C.model||"Evidence check",C.startedAt?` · ${ce(C.startedAt)}`:""]})]}),C.costUsd!=null&&e.jsxs("span",{children:["$",C.costUsd.toFixed(3)]})]},R))}),(i.sources||[]).map(C=>e.jsxs("p",{className:"uh-live-source",children:[e.jsx("strong",{children:C.pluginId})," · ",C.signals," signals · ",C.ok?"Read completed":"Needs attention",C.note?` · ${C.note}`:""]},C.pluginId)),(i.error||i.emptyReason)&&e.jsx("p",{className:"uh-live-run-note",children:i.error||i.emptyReason}),(i.notes||[]).map((C,R)=>e.jsx("p",{className:"uh-live-run-note",children:C},R)),e.jsxs("small",{className:"uh-muted",children:["Run ",i.id," · ",i.repos?.map(C=>`${C.name} @ ${C.commit?.slice(0,7)||"local checkout"}`).join(", ")]})]})]},i.id)})]});return e.jsxs("div",{className:"uh-live-surface",onClick:i=>{const p=i.target.closest("a")?.getAttribute("href");if(p?.startsWith("#blocker-")&&(i.preventDefault(),b(p.slice(9)),x("")),p?.startsWith("#run-")){const w=document.getElementById(p.slice(1));w instanceof HTMLDetailsElement&&(w.open=!0)}},children:[e.jsx(ys,{initial:m,snapshot:m,workspace:!0,activity:a,children:e.jsxs("div",{className:"uh-live-system",children:[e.jsxs("div",{children:[e.jsx("span",{children:"Engine"}),e.jsxs("strong",{children:[e.jsx("span",{className:`uh-dot ${d?"warn":""}`}),d?"Reconnecting":"Online"]})]}),e.jsxs("div",{children:[e.jsx("span",{children:"Configured pipelines"}),e.jsxs("strong",{children:[n.length,e.jsxs("small",{children:[n.filter(i=>i.enabled&&i.schedule!=="manual").length," scheduled"]})]})]}),e.jsxs("div",{children:[e.jsx("span",{children:"Active agents"}),e.jsxs("strong",{children:[m.agents.length,e.jsx("small",{children:m.agents.map(i=>te(i.step)).join(", ")||"No model call running"})]})]}),e.jsxs("div",{children:[e.jsx("span",{children:"Recent run cost"}),e.jsxs("strong",{children:["$",m.cost.toFixed(3),e.jsxs("small",{children:[m.runs.length," recorded runs · ",t.workspace.reserve,"% reserve"]})]})]})]})}),j&&e.jsx(Se,{title:S?`${S.kind} · ${S.name}`:"Access verified",close:()=>b(""),children:e.jsxs("div",{className:"uh-live-blocker-detail",children:[e.jsx("p",{children:S?.detail||"The account check succeeded. Your pipeline is ready to run with its saved settings."}),S?.kind==="AI account"&&e.jsxs(e.Fragment,{children:[e.jsxs("dl",{children:[e.jsx("dt",{children:s.label||"AI CLI"}),e.jsxs("dd",{children:[s.available?"Installed":"Not found",s.cliVersion?` · ${s.cliVersion}`:""]}),e.jsx("dt",{children:"Account source"}),e.jsx("dd",{children:s.authMethod||"Local CLI login"}),s.configDirectory&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"CLI configuration"}),e.jsx("dd",{children:e.jsx("code",{children:s.configDirectory})})]}),s.verifiedAt&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{children:"Last live check"}),e.jsx("dd",{children:ce(s.verifiedAt)})]})]}),s.command&&e.jsxs("div",{className:"uh-activation-command",children:[e.jsx("code",{children:s.command}),e.jsx("button",{className:"uh-btn",onClick:()=>navigator.clipboard.writeText(s.command).catch(()=>x("Copy the command into your terminal.")),children:"Copy command"})]})]}),h&&e.jsx("p",{role:"alert",className:"uh-error",children:h}),e.jsxs("div",{className:"uh-modal-actions",children:[e.jsx("button",{className:"uh-btn",onClick:()=>b(""),children:"Close"}),S?.kind==="AI account"?e.jsx("button",{className:"uh-btn primary",disabled:f,onClick:async()=>{v(!0),x("");try{await l("/api/workspace/provider/check",{})}catch(i){x(i.message)}finally{v(!1)}},children:f?"Checking account access…":"Check account access"}):S?.kind==="Source access"?e.jsx("a",{className:"uh-btn primary",href:u?"/chat":"/settings?tab=connections",children:"Manage source connection"}):S?.kind==="Failed run"?e.jsx("a",{className:"uh-btn primary",onClick:()=>b(""),href:`#run-${m.runs.find(i=>i.pipelineId===S.id)?.id}`,children:"Inspect run"}):null]})]})})]})}function Ds(){return/\/setup$|\/projects$/.test(location.pathname)?"setup":/pipeline-live|\/runs$/.test(location.pathname)?"pipeline-live":/\/review$|\/results$|\/claims$|cockpit/.test(location.pathname)?"review":"chat"}const ye=[{id:"chat",name:"Chat",href:"/chat",icon:Ut},{id:"setup",name:"Setup",href:"/setup",icon:Ot},{id:"pipeline-live",name:"Pipeline live",href:"/pipeline-live",icon:Ce},{id:"review",name:"Review",href:"/review?tab=decide",icon:Ye}];function Is(){const[t,n]=o.useState(null),[r,d]=o.useState("");return o.useEffect(()=>{let l=!0;return(async()=>{const[{init:u},{default:m}]=await Promise.all([Ie(()=>import("./data-provider-TNBGds5H.js"),__vite__mapDeps([0,1,2])),Ie(()=>import("./page-C_4oHSxK.js"),__vite__mapDeps([3,1,0,2,4]))]),j=new URL(location.href);!j.searchParams.has("tab")&&/\/review$|\/results$/.test(j.pathname)&&(j.searchParams.set("tab",j.pathname==="/results"?"shipped":"decide"),history.replaceState(null,"",j)),await u();const b=await m();l&&n(b)})().catch(u=>{l&&d(u.message)}),()=>{l=!1}},[]),r?e.jsx("p",{role:"alert",className:"uh-error",children:r}):e.jsx("div",{className:"conversation-review",children:t||e.jsxs("p",{className:"conversation-loading",children:[e.jsx(X,{size:16,className:"uh-spin"})," Loading review…"]})})}function Ls({status:t,close:n,refresh:r}){const[d,l]=o.useState(""),[u,m]=o.useState(t),[j,b]=o.useState(!1),[f,v]=o.useState(""),[h,x]=o.useState(!1),S=async()=>{if(!j){b(!0),v("");try{const s=await B("/api/chat/telegram/connect",d?{token:d}:{});l(""),m(s),await r()}catch(s){v(s.message)}finally{b(!1)}}};return o.useEffect(()=>{const s=setInterval(()=>{H("/api/chat/telegram").then(a=>{m(a),a.paired&&r()}).catch(()=>{})},1500);return()=>clearInterval(s)},[]),e.jsxs(Se,{title:u?.paired?"Telegram connected":"Connect Telegram",close:n,children:[u?.paired?e.jsx("p",{className:"conversation-modal-copy",children:"Messages here, in Telegram, and in the CLI use the same conversation."}):u?.link?e.jsx("p",{className:"conversation-modal-copy",children:"Open your bot and press Start to connect this conversation."}):e.jsxs("form",{onSubmit:s=>{s.preventDefault(),S()},children:[(!u?.hasToken||h)&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"conversation-modal-copy",children:["Create a bot with ",e.jsx("a",{href:"https://t.me/BotFather",target:"_blank",rel:"noreferrer",children:"@BotFather"}),", then enter its token here."]}),e.jsxs("label",{className:"uh-field",children:[e.jsx("span",{children:"Bot token"}),e.jsx("input",{autoFocus:!0,type:"password",autoComplete:"off",value:d,onChange:s=>l(s.target.value),required:!0,placeholder:"123456:…"})]}),e.jsx("p",{className:"conversation-secret-note",children:"Saved locally. Never sent to the AI or stored in chat."})]}),u?.hasToken&&!h&&e.jsxs("p",{className:"conversation-modal-copy",children:["Use the bot token already saved on this machine. ",e.jsx("button",{className:"uh-link",type:"button",onClick:()=>x(!0),children:"Use another token"})]}),e.jsxs("div",{className:"uh-modal-actions",children:[e.jsx("button",{className:"uh-btn",type:"button",onClick:n,children:"Cancel"}),e.jsx("button",{className:"uh-btn primary",type:"submit",disabled:j||(!u?.hasToken||h)&&!d.trim(),children:j?"Checking…":"Connect"})]})]}),u?.link&&e.jsxs("div",{className:"uh-modal-actions",children:[e.jsx("button",{className:"uh-btn",onClick:n,children:"Close"}),e.jsxs("a",{className:"uh-btn primary",href:u.link,target:"_blank",rel:"noreferrer",children:["Open Telegram ",e.jsx(O,{size:15})]})]}),u?.link&&!u.paired&&e.jsx("p",{className:"conversation-secret-note",role:"status",children:"Waiting for you to press Start in Telegram. The link expires after 10 minutes."}),f&&e.jsx("p",{role:"alert",className:"uh-error",children:f})]})}function Ts(){const t=Ds(),[n,r]=o.useState(null),[d,l]=o.useState(null),[u,m]=o.useState(!1),[j,b]=o.useState(""),[f,v]=o.useState(!1),[h,x]=o.useState(!1),[S,s]=o.useState(!1),[a,i]=o.useState(""),p=o.useRef(!1),[w,C]=o.useState(new URLSearchParams(location.search).get("project")||"all"),R=o.useCallback(async()=>{if(!p.current){p.current=!0;try{const y=await H("/api/status");zt(y.csrf);const[T,k,M,L,F]=await Promise.all([H("/api/workspace"),H("/api/pipelines"),H("/api/cockpit"),H("/api/runs"),H("/api/chat/telegram")]);r({status:y,workspace:T,pipelines:k,cockpit:M,runs:L.runs}),l(F),v(!1),b("")}catch(y){y instanceof We&&y.status===401?b("Open a login link from ultimatehuman dashboard."):v(!0)}finally{p.current=!1}}},[]);o.useEffect(()=>{(async()=>{const k=await At();if(k!=="none"&&k!=="ok"){b(k);return}await R()})();const y=setInterval(()=>{R()},5e3),T=Et(()=>{R()});return()=>{clearInterval(y),T()}},[R]),o.useEffect(()=>{t==="chat"&&n?.workspace.provider.authenticated&&B("/api/chat/start").catch(()=>{})},[t,n?.workspace.provider.authenticated]);const A=async(y,T)=>{const k=await B(y,T);return await R(),k};if(j||!n)return e.jsxs("div",{className:"conversation-access",children:[e.jsxs("a",{href:"/chat",className:"conversation-access-brand",children:[e.jsx(se,{}),"ultimatehuman",e.jsx("span",{children:"."})]}),e.jsxs("div",{className:"conversation-access-card",children:[e.jsx("span",{className:"eyebrow",children:"YOUR LOCAL WORKSPACE"}),e.jsx("h1",{children:j?"Let’s get you in.":f?"Reconnect your workspace.":"Opening your workspace."}),e.jsx("p",{children:j||(f?"Start the local engine to continue.":"Connecting to the engine on this machine…")}),j||f?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"conversation-command",children:[e.jsx(we,{size:16}),e.jsx("code",{children:"ultimatehuman dashboard"})]}),e.jsxs("button",{className:"uh-btn primary",onClick:()=>{R()},children:["Try again ",e.jsx(O,{size:16})]})]}):e.jsx(X,{size:22,className:"uh-spin"})]}),e.jsx("span",{className:"conversation-access-foot",children:"AUTONOMOUS ENGINEERING. HUMAN JUDGMENT."})]});const N=n.workspace.provider,g=n.workspace.projects.filter(y=>w==="all"||y.id===w).flatMap(y=>y.repos.map(T=>T.name)),_=n.pipelines.config.filter(y=>w==="all"||!y.repos||y.repos.some(T=>g.includes(T))),I=n.workspace.projects.map(y=>y.name),$=n.cockpit.cards.filter(y=>y.finding&&(!y.ruling||["clear","resurfaced"].includes(y.ruling.ruling))).length+(n.cockpit.proposals||[]).filter(y=>y.status==="pending").length,E=n.runs.filter(y=>!["done","failed"].includes(y.phase)).length;return e.jsxs("div",{className:`uh-app conversation-app conversation-page-${t}`,children:[e.jsxs("aside",{className:"conversation-sidebar",children:[e.jsxs("a",{href:"/chat",className:"conversation-brand","aria-label":"ultimatehuman home",children:[e.jsx(se,{}),e.jsxs("span",{children:["ultimatehuman",e.jsx("b",{children:"."})]})]}),e.jsx("nav",{"aria-label":"Main navigation",children:ye.map(({id:y,name:T,href:k,icon:M})=>{const L=y==="review"?$:y==="pipeline-live"?E:0;return e.jsxs("a",{href:k,"aria-current":y===t?"page":void 0,children:[e.jsx(M,{size:18,strokeWidth:1.65}),e.jsx("span",{children:T}),L>0&&e.jsx("b",{className:"conversation-nav-count",children:L}),y===t&&e.jsx(tt,{size:14,className:"conversation-nav-arrow"})]},y)})}),e.jsx("div",{className:"conversation-sidebar-bottom",children:e.jsxs("div",{className:"conversation-engine-status",children:[e.jsx("span",{className:`uh-dot ${f?"warn":""}`}),f?"Engine offline":"Local engine running"]})})]}),e.jsxs("div",{className:"conversation-main",children:[e.jsxs("header",{className:"conversation-header",children:[e.jsxs("div",{className:"conversation-breadcrumb",children:[e.jsx(se,{className:"conversation-mobile-mark"}),e.jsx("span",{className:"conversation-breadcrumb-root",children:"Workspace"}),e.jsx("span",{className:"conversation-breadcrumb-slash",children:"/"}),e.jsx("h1",{children:ye.find(y=>y.id===t)?.name})]}),e.jsxs("div",{className:"conversation-header-actions",children:[e.jsxs("span",{className:"conversation-local-status",children:[e.jsx("span",{className:`uh-dot ${f?"warn":""}`}),"Local workspace"]}),t==="chat"&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{className:"uh-btn conversation-cli",onClick:()=>{H("/api/chat").then(async y=>{const T=`${y.cliCommand||"ultimatehuman"} chat`;try{await navigator.clipboard.writeText(T),s(!0),setTimeout(()=>s(!1),2500)}catch{i(`Terminal command: ${T}`)}}).catch(y=>i(y.message))},title:"Copy terminal command",children:[e.jsx(we,{size:14}),S?"Copied":"Use CLI"]}),e.jsxs("button",{className:"uh-btn conversation-telegram",onClick:()=>m(!0),children:[e.jsx(Ft,{size:14}),d?.paired?"Telegram":"Connect Telegram",e.jsx(O,{size:13})]})]}),["pipeline-live","setup"].includes(t)&&n.workspace.projects.length>1&&e.jsxs("div",{className:"conversation-project-filter",children:[e.jsx(rt,{size:14}),e.jsxs("select",{"aria-label":"Project filter",value:t==="setup"&&!n.workspace.projects.some(y=>y.id===w)?n.workspace.projects[0].id:w,onChange:y=>C(y.target.value),children:[t!=="setup"&&e.jsx("option",{value:"all",children:"All projects"}),n.workspace.projects.map(y=>e.jsx("option",{value:y.id,children:y.name},y.id))]})]})]})]}),e.jsx("nav",{className:"conversation-mobile-nav","aria-label":"Mobile navigation",children:ye.map(({id:y,name:T,href:k,icon:M})=>e.jsxs("a",{href:k,"aria-current":y===t?"page":void 0,children:[e.jsx(M,{size:15}),T]},y))}),f&&e.jsx("div",{className:"conversation-warning",role:"status",children:"Reconnecting to the engine…"}),t==="chat"&&N.authenticated&&a&&e.jsx("div",{className:"conversation-warning",role:"status",children:a}),t==="chat"&&!N.authenticated&&e.jsxs("div",{className:"conversation-warning conversation-account-warning",children:[e.jsx(ht,{size:15}),e.jsxs("div",{children:[e.jsx("strong",{children:a||(N.available?`${N.label||"Your AI account"} needs to reconnect.`:"Your selected AI CLI is not installed.")}),e.jsxs("span",{children:["Run ",e.jsx("code",{children:N.command||"claude auth login"})," in your terminal."]})]}),e.jsxs("button",{className:"uh-btn",disabled:h,onClick:async()=>{x(!0),i("");try{await A("/api/workspace/provider/check",{})}catch(y){i(y.message)}finally{x(!1)}},children:[e.jsx(xt,{size:14,className:h?"uh-spin":""}),h?"Checking…":"Check connection"]})]}),e.jsxs("main",{className:`conversation-content ${t==="chat"?"conversation-chat":""}`,children:[t==="chat"&&e.jsx(Qt,{projectNames:I,configured:n.workspace.projects.length>0,disabled:!N.authenticated||f,initialPrompt:new URLSearchParams(location.search).get("message")||(/config|settings|pipelines|projects/.test(location.pathname)?"Help me configure this workspace.":"")}),t==="pipeline-live"&&e.jsx(Es,{data:n,pipelines:_,project:w,offline:f,act:A,chatFirst:!0}),t==="setup"&&e.jsx(ss,{data:n,project:w}),t==="review"&&e.jsx(Is,{})]})]}),u&&e.jsx(Ls,{status:d,close:()=>m(!1),refresh:R})]})}function Ps(t){Mt.createRoot(t).render(e.jsx(Ts,{}))}const Us=Object.freeze(Object.defineProperty({__proto__:null,mount:Ps},Symbol.toStringTag,{value:"Module"}));export{Us as C,de as F,J as L,os as a,rs as b,re as c,us as s};