@paradow/ledge-relay 0.0.0-stage → 0.61.0
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.
- package/LICENSE +75 -0
- package/README.md +235 -2
- package/dist/chunk-HTYEMUSI.js +5158 -0
- package/dist/cli.js +434 -0
- package/dist/main.js +25 -0
- package/package.json +42 -4
- package/web/assets/App-zclWYn2G.js +23 -0
- package/web/assets/boot-GtprRTxP.js +1 -0
- package/web/assets/geist-cyrillic-ext-wght-normal-DjL33-gN.woff2 +0 -0
- package/web/assets/geist-cyrillic-wght-normal-BEAKL7Jp.woff2 +0 -0
- package/web/assets/geist-latin-ext-wght-normal-DC-KSUi6.woff2 +0 -0
- package/web/assets/geist-latin-wght-normal-BgDaEnEv.woff2 +0 -0
- package/web/assets/geist-mono-cyrillic-ext-wght-normal-X_5orZeX.woff2 +0 -0
- package/web/assets/geist-mono-cyrillic-wght-normal-DiZS0aHC.woff2 +0 -0
- package/web/assets/geist-mono-latin-ext-wght-normal-Bwz-egvJ.woff2 +0 -0
- package/web/assets/geist-mono-latin-wght-normal-XN7g48iV.woff2 +0 -0
- package/web/assets/geist-mono-symbols2-wght-normal-CO5SzqOn.woff2 +0 -0
- package/web/assets/geist-mono-vietnamese-wght-normal-DadHysG0.woff2 +0 -0
- package/web/assets/geist-vietnamese-wght-normal-6IgcOCM7.woff2 +0 -0
- package/web/assets/index-C0ikeXTk.css +1 -0
- package/web/assets/index-CytIBIB5.js +52 -0
- package/web/assets/label-8OD9J9FC.js +1 -0
- package/web/assets/xterm-CATQzocj.js +9 -0
- package/web/assets/xterm-DYP7pi_n.css +32 -0
- package/web/build.json +1 -0
- package/web/favicon-32.png +0 -0
- package/web/favicon.svg +1 -0
- package/web/icon-180.png +0 -0
- package/web/icon-192.png +0 -0
- package/web/icon-512.png +0 -0
- package/web/icon-maskable-512.png +0 -0
- package/web/index.html +22 -0
- package/web/manifest.webmanifest +29 -0
- package/web/sw.js +2 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/xterm-CATQzocj.js","assets/index-CytIBIB5.js","assets/index-C0ikeXTk.css","assets/label-8OD9J9FC.js","assets/xterm-DYP7pi_n.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
var Nx=Object.defineProperty;var kx=(t,s,n)=>s in t?Nx(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var Dt=(t,s,n)=>kx(t,typeof s!="symbol"?s+"":s,n);import{r as h,c as d,j as e,B as We,a as _a,U as rc,M as Qn,o as ic,b as vx,i as $t,u as Cr,d as en,e as wx,f as De,l as dt,t as ji,g as Sx,O as ot,h as vt,H as Pt,F as wt,P as gt,S as Hn,K as zn,s as $x,C as kn,k as oc,m as Xe,I as Cx,A as Mx,n as Ex,p as Ax,q as cc,R as Tx,v as yi,w as bn,L as Hl,x as _x,y as Ix,z as Rx,D as Ox,E as Lx,G as Ni,J as ki,N as vi,Q as xl,T as zx,V as dc,W as Dx,X as Fx,Y as Px,Z as Ia,_ as wi,$ as Bx,a0 as qx,a1 as uc,a2 as Mr,a3 as xc,a4 as Hx,a5 as Si,a6 as Ux,a7 as Wx,a8 as Kx,a9 as Vx}from"./index-CytIBIB5.js";import{e as mc,i as us,a as Gx,p as Xx,g as Yn,c as Qx,b as Yx,d as Er,u as fe,r as Zx,f as Jx,h as em,j as pc,k as tm,l as $i,m as Ci,n as sm,M as $s,o as nm,q as am,s as lm,t as Ar,v as rm,w as im,x as om,y as fc,z as hc,A as cm,B as gc,R as bc,U as jc}from"./label-8OD9J9FC.js";const dm=["sessions","prs","rigs","chat","connection","kernel","max"],yc="new";function Ra(t){const s=t.replace(/^#\/?/,"").split("/").filter(Boolean);try{if(s[0]==="request"&&s.length===3)return{name:"request",sessionId:decodeURIComponent(s[1]),key:decodeURIComponent(s[2])};if(s[0]==="ask"&&s.length===2)return{name:"ask",id:decodeURIComponent(s[1])};if((s[0]==="thread"||s[0]==="terminal")&&s.length===2)return{name:s[0],sessionId:decodeURIComponent(s[1])};if(s[0]==="atelier"&&s.length===4&&s[2]==="request")return{name:"atelier",sessionId:decodeURIComponent(s[1]),requestKey:decodeURIComponent(s[3])};if(s[0]==="atelier"&&s.length<=2)return s[1]?{name:"atelier",sessionId:decodeURIComponent(s[1])}:{name:"atelier"};if(s[0]==="connection"&&s.length===2&&s[1]==="link")return{name:"connection",section:"link"};if(s[0]==="rigs"&&s.length===2)return{name:"rig",rig:decodeURIComponent(s[1])};if(s[0]==="prs"&&s.length===2)return{name:"pr",id:decodeURIComponent(s[1])};if(s[0]==="max"&&s.length===2)return{name:"max",goalId:decodeURIComponent(s[1])};if(s[0]==="sessions"&&s.length===2&&(s[1]==="working"||s[1]==="waiting"))return{name:"sessions",filter:s[1]}}catch{}if(s[0]==="agents"&&s.length===1)return{name:"sessions"};if(s[0]===yc&&s.length===1)return{name:"launch"};const n=dm.find(a=>a===s[0]);return n&&s.length===1?{name:n}:{name:"atoi"}}function ae(t){return t.name==="request"?`#/request/${encodeURIComponent(t.sessionId)}/${encodeURIComponent(t.key)}`:t.name==="ask"?`#/ask/${encodeURIComponent(t.id)}`:t.name==="thread"||t.name==="terminal"?`#/${t.name}/${encodeURIComponent(t.sessionId)}`:t.name==="atelier"?t.sessionId?t.requestKey?`#/atelier/${encodeURIComponent(t.sessionId)}/request/${encodeURIComponent(t.requestKey)}`:`#/atelier/${encodeURIComponent(t.sessionId)}`:"#/atelier":t.name==="connection"&&t.section?`#/connection/${t.section}`:t.name==="rig"?`#/rigs/${encodeURIComponent(t.rig)}`:t.name==="pr"?`#/prs/${encodeURIComponent(t.id)}`:t.name==="max"&&t.goalId?`#/max/${encodeURIComponent(t.goalId)}`:t.name==="sessions"&&t.filter?`#/sessions/${t.filter}`:t.name==="launch"?`#/${yc}`:t.name==="atoi"?"#/":`#/${t.name}`}const Zs=t=>{globalThis.location.hash=ae(t)},Ul=t=>typeof(t==null?void 0:t.ledge)=="number";let ts=0,Dn=[],Wl=!1;const Kl=t=>{try{globalThis.history.replaceState({...globalThis.history.state,ledge:t},"")}catch{}};function um(){const t=globalThis.location.hash,s=globalThis.history.state;Ul(s)?ts=s.ledge:(Wl||(ts+=1,Dn=Dn.slice(0,ts)),Kl(ts)),Wl=!1,Dn[ts]=t}if(typeof globalThis.addEventListener=="function"&&globalThis.history&&globalThis.location){const t=globalThis.history.state;ts=Ul(t)?t.ledge:0,Ul(t)||Kl(0),Dn[ts]=globalThis.location.hash,globalThis.addEventListener("hashchange",um)}const xs=t=>{Wl=!0,globalThis.location.replace(ae(t))};function xm(t){if(ts===0)return{route:t,known:!1,inApp:!1};const s=Dn[ts-1];return s===void 0?{route:t,known:!1,inApp:!0}:{route:Ra(s),known:!0,inApp:!0}}function Tr(t){ts>0?globalThis.history.back():xs(t)}const mm=t=>(globalThis.addEventListener("hashchange",t),()=>globalThis.removeEventListener("hashchange",t));function Zn(){const t=h.useSyncExternalStore(mm,()=>globalThis.location.hash,()=>"");return Ra(t)}const pm=/^\/#\/[A-Za-z0-9/%._~-]*$/;function fm(t){if(typeof t!="object"||t===null)return;const s=t;s.type!=="ledge.open"||typeof s.url!="string"||!pm.test(s.url)||(globalThis.location.hash=s.url.slice(1))}const Nc=70,Jn=6,Mi=2,_r=130,Ts=90,kc=t=>(Math.max(t,2)+1)*Nc,vc=(t,s=Jn,n=_r)=>kc(Math.min(t,s))+2*n;function hm(t,s,n=Jn,a=_r){const l=t.slice(0,n),r=kc(l.length),i=g=>l.length===1?r/2:Nc*(g+1),o=l.map((g,f)=>({session:g,x:i(f),side:l.length===1||f%2===0?"t":"b"})),c={left:[],right:[]},x=new Map,u=[];if(s){for(const[g,f]of l.entries()){const y=f.helpers??[],w=y[0];w&&x.set(f.id,{helper:w,more:y.length-1});const S=i(g)>r/2?"right":"left",b=S==="left"?"right":"left";for(const j of y){const N=c[S].length<Mi?S:c[b].length<Mi?b:null;N?c[N].push({helper:j,parent:f}):u.push({helper:j,parent:f})}}for(const g of t.slice(n))for(const f of g.helpers??[])u.push({helper:f,parent:g})}const m=["left","right"].flatMap(g=>c[g].map((f,y)=>({...f,end:g,slot:y,count:c[g].length}))),p=t.slice(n);return{length:r,width:vc(t.length,n,a),seats:o,ends:m,notes:x,extra:{mains:p,helpers:u},extraCount:p.length+u.length}}const Ps=84,ua=52;function gm(t,s,n){const a=[...s].sort((o,c)=>o-c),l=a.indexOf(t),r=(l<a.length-1?a[l+1]-Ps/2:n-6)-(t+Ps/2),i=t-Ps/2-(l>0?a[l-1]+Ps/2:6);return r>=ua+4?t+Ps/2+2:i>=ua+4?t-Ps/2-ua-2:t+Ps/2-ua+8}function bm(t){const s=new Map;for(const a of t)a.branch&&s.set(a.branch,(s.get(a.branch)??0)+1);let n=null;for(const[a,l]of s)(n===null||l>s.get(n))&&(n=a);return n}function Ei(t,s){return t==="idle"?"done":t==="readonly"?"working":t}const jm={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"},wc=t=>jm[t.state];function ym(t,s,n,a,l,r){const i=s??[],o=new Set(i.map(w=>w.id)),c=w=>{const S=n(w);return S!==null&&o.has(S)?S:null},x=t.filter(w=>!w.rig),u=i.filter(w=>a==="all").map(w=>({project:w,tables:[{key:`common:${w.id}`,mains:x.filter(S=>c(S)===w.id)}]})).filter(w=>w.tables[0].mains.length>0),m=Nm(t.filter(w=>w.rig),w=>{var S;return((S=i.find(b=>b.id===w))==null?void 0:S.name)??null},n,r),p=[...m.filter(w=>w.rig.kind==="kernel"),...u,...m.filter(w=>w.rig.kind==="rig")],g=a==="all"||a==="none"?x.filter(w=>c(w)===null):[],f=a==="all"||a==="none"?void 0:i.find(w=>w.id===a),y=f&&p.length===0?f:null;return{rooms:p,unassigned:g,empty:y}}const ml="kernel";function Nm(t,s,n,a){const l=new Map;for(const r of t)l.set(r.rig.name,[...l.get(r.rig.name)??[],r]);return[...l].sort(([r],[i])=>r===ml?-1:i===ml?1:r.localeCompare(i)).map(([r,i])=>{const o=r===ml?"kernel":"rig",c=n(i[0]);return{project:a({id:`rig:${r}`,name:r,kind:o}),tables:[{key:`rig:${r}`,mains:i}],rig:{kind:o,name:r,folder:i[0].cwd??"",project:c?s(c):null}}})}const km=t=>t==="kernel"?"violet":"slate",Sc=110,vm=150,$c=70,wm=(t,s=Jn,n=_r)=>t.reduce((a,l,r)=>a+vc(l.mains.length,s,n)+(r>0?$c:0),0)+2*Sc;function Wt(t){const s=[];for(const n of t){const a=n.pending;a!=null&&a.key&&s.push({sessionId:n.id,key:a.key,kind:a.kind,filter:a.kind==="question"?"question":"permission",task:n.topic??n.project,botName:n.name,tool:n.tool,repo:n.repo??n.project,...n.branch?{branch:n.branch}:{},...n.worktree?{worktree:!0}:{},since:n.lastActivityAt,text:a.text,...a.tool?{pendingTool:a.tool}:{},...a.body!==void 0?{body:a.body}:{},...a.cut?{cut:!0}:{},...a.options?{options:a.options}:{},...a.optionDetails?{optionDetails:a.optionDetails}:{},source:a.source,...a.questions?{questions:a.questions}:{},...a.requestId?{requestId:a.requestId}:{},risk:a.risk,riskReason:a.riskReason})}return s.sort((n,a)=>Date.parse(n.since)-Date.parse(a.since))}const pl=(t,s)=>s==="all"?t:t.filter(n=>n.filter===s);function jn(t,s){const n=Math.max(0,Math.floor((s-Date.parse(t))/1e3)),a=d.inbox.age;return n<60?a.s(n):n<3600?a.min(Math.floor(n/60)):n<86400?a.h(Math.floor(n/3600)):a.d(Math.floor(n/86400))}const Vl=t=>{var s;return((s=t.split(`
|
|
3
|
+
`).find(n=>n.trim()))==null?void 0:s.trim())??""};function vn(t){switch(t.kind){case"question":return t.text;case"plan":return d.inbox.plan;case"diff":return d.inbox.diff(Vl(t.text)).trim();default:return Vl(t.text)}}const Cc=["all","waiting","working"],Gl=t=>t.pending!==void 0||t.state==="waiting_permission"||t.state==="waiting_input";function Xl(t,s){return s==="waiting"?Gl(t):s==="working"?t.state==="working"&&!Gl(t):!0}function Oa(t){return Gl(t)?0:t.state==="working"?1:t.state==="exited"?3:2}function Mc(t,s){const n=new Map,a=new Map;for(const r of t){if(!Xl(r,s))continue;const[i,o,c]=r.rig?[a,"rig",r.rig.name]:[n,"project",r.project];let x=i.get(c);x||i.set(c,x={id:`${o}:${c}`,kind:o,name:c,sessions:[]}),x.sessions.push(r)}const l=r=>({...r,sessions:r.sessions.map((i,o)=>[i,o]).sort((i,o)=>Oa(i[0])-Oa(o[0])||i[1]-o[1]).map(([i])=>i)});return[...n.values(),...a.values()].map(l)}const Ir=["projects","rigs"];function Sm(t,s){const n=Mc(t,"all");if(s==="projects")return n;const a=t.filter(l=>!l.rig).map((l,r)=>[l,r]).sort((l,r)=>Oa(l[0])-Oa(r[0])||l[1]-r[1]).map(([l])=>l);return[...n.filter(l=>l.kind==="rig"),...a.length?[{id:"outside",kind:"outside",name:d.sessions.outsideRig,sessions:a}]:[]]}function $m(t){if(t.kind!=="project")return null;const s=t.sessions.map(wn);return s.includes("perm")?"perm":s.includes("ask")?"ask":null}function Cm(t){return t.finishedAt!==void 0||t.state==="exited"?"done":t.state==="waiting_permission"?"perm":t.state==="waiting_input"?"ask":t.state==="working"?"work":"idle"}const Ec=t=>({all:t.length,waiting:t.filter(s=>Xl(s,"waiting")).length,working:t.filter(s=>Xl(s,"working")).length});function wn(t){const s=Wt([t])[0];return s?s.kind==="question"?"ask":"perm":t.state==="waiting_permission"?"perm":t.state==="waiting_input"?"ask":t.state==="working"?"work":t.state==="exited"?"done":"idle"}const Mm=t=>t.helpers.filter(s=>s.state!=="exited"&&s.finishedAt===void 0).length;function Em(t,s,n=Date.now()){const a=d.sessions.line;if(s==="working")return Rr(t);const l=Ac(t),r=l===void 0?"":` · ${l} %`,i=Wt([t])[0];if(i)return(i.kind==="permission"?a.permission:d.atoi.pill[i.kind])+r;switch(t.state){case"waiting_permission":return a.permission+r;case"waiting_input":return d.atoi.pill.question+r;case"working":return a.working+r;case"exited":return t.exitedAt?a.ended(mc(t.exitedAt,n)):a.endedPlain;case"error":return a.error;default:return a.idle+r}}const Rr=t=>{var s;return((s=t.doing)==null?void 0:s.label)||d.sessions.line.thinking},Ac=t=>t.context?Math.round(Math.min(1,t.context.used/t.context.window)*100):void 0;function Am(t){if(t.rig)return t.rig.role;if(t.branch)return t.branch.split("/").filter(Boolean).pop()??t.branch}function yn({d:t,size:s=16,fill:n}){return e.jsxs("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.map((a,l)=>e.jsx("path",{d:a},l)),n==null?void 0:n.map((a,l)=>e.jsx("path",{d:a,fill:"currentColor",stroke:"none"},`f${l}`))]})}const pn={chevronLeft:{d:["m15 18-6-6 6-6"]},chevronRight:{d:["m9 18 6-6-6-6"]},close:{d:["M18 6 6 18","m6 6 12 12"]},check:{d:["M20 6 9 17l-5-5"]},plus:{d:["M12 5v14","M5 12h14"]}},Je=(t,s,n)=>`M${t-n} ${s}a${n} ${n} 0 1 0 ${2*n} 0a${n} ${n} 0 1 0 ${-2*n} 0`,ln=(t,s,n,a,l)=>`M${t+l} ${s}h${n-2*l}a${l} ${l} 0 0 1 ${l} ${l}v${a-2*l}a${l} ${l} 0 0 1 ${-l} ${l}h${-(n-2*l)}a${l} ${l} 0 0 1 ${-l} ${-l}v${-(a-2*l)}a${l} ${l} 0 0 1 ${l} ${-l}z`,Tm={back:pn.chevronLeft.d,chevron:pn.chevronRight.d,close:pn.close.d,check:pn.check.d,plus:pn.plus.d,gear:["M15 12a3 3 0 1 1-6 0a3 3 0 1 1 6 0","M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1.1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1.1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1Z"],terminal:["m4 17 6-6-6-6","M12 19h8"],eye:["M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z",Je(12,12,3)],arrowRight:["M5 12h14","m13 6 6 6-6 6"],arrowUp:["m5 12 7-7 7 7","M12 19V5"],plane:["m22 2-7 20-4-9-9-4Z","M22 2 11 13"],external:["M15 3h6v6","M10 14 21 3","M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"],stop:["M8 6h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2z"],power:["M12 3v9","M6.3 6.3a8 8 0 1 0 11.4 0"],resume:["M4 12a8 8 0 1 0 2.3-5.6","M4 4v4h4","M10 9l5 3-5 3z"],monitor:["M5 4h14a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z","M8 20h8","M12 16v4"],warning:["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","M12 9v4","M12 17h.01"],edit:["M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7","M18.38 2.62a2.12 2.12 0 1 1 3 3L12.36 14.64a2 2 0 0 1-.85.51l-2.87.84.84-2.87a2 2 0 0 1 .5-.85z"],spinner:["M21 12a9 9 0 1 1-6.22-8.56"],inbox:["M4 13l3-8h10l3 8v6H4z","M4 13h5l1 2h4l1-2h5"],sessions:[ln(3,4,18,16,2),"M7 9h10M7 13h6"],pr:[Je(6,5,2.2),Je(6,19,2.2),Je(18,19,2.2),"M6 7.2v9.6M18 16.8V10a3 3 0 0 0-3-3h-4","M13 5l-2 2 2 2"],rigs:[Je(6,6,2.5),Je(18,6,2.5),Je(12,18,2.5),"M8 7.5l3 8M16 7.5l-3 8M8.5 6h7"],ledge:[ln(4,8,16,12,3),"M12 8V4.5",Je(9,14,1),Je(15,14,1)],search:[Je(11,11,7),"M20 20l-4-4"],more:[Je(12,5,1.4),Je(12,12,1.4),Je(12,19,1.4)],send:["M12 19V5M5 12l7-7 7 7"],wifioff:["M12 20h.01M8.5 16.4a5 5 0 0 1 7 0M5 12.9a10 10 0 0 1 5.2-2.7M19 12.9a10 10 0 0 0-1.9-1.3M2 8.8a15 15 0 0 1 4.2-2.7M22 8.8A15 15 0 0 0 10.7 5M2 2l20 20"],cloud:["M2 2l20 20M5.8 5.8A7 7 0 0 0 7 20h10a5 5 0 0 0 2.6-.7M20.8 16.4A5 5 0 0 0 17 10h-1.3A7 7 0 0 0 10 5.1"],refresh:["M3 12a9 9 0 0 1 15.7-6L21 8M21 3v5h-5M21 12a9 9 0 0 1-15.7 6L3 16M3 21v-5h5"],atelier:[ln(3,10,18,5,1),Je(7,6,2),Je(17,6,2),"M6 15v4M18 15v4"],plan:["M9 4h6v3H9z","M7 5H5v16h14V5h-2","m9 12 1.5 1.5L14 10","M9 17h6"],keyboard:["M3 7h18v10H3z","M7 11h.01","M11 11h.01","M15 11h.01","M8 14h8"],task:["M6.9 3.75h10.2a2.4 2.4 0 0 1 2.4 2.4v11.7a2.4 2.4 0 0 1-2.4 2.4H6.9a2.4 2.4 0 0 1-2.4-2.4V6.15a2.4 2.4 0 0 1 2.4-2.4z","M8.25 9h7.5","M8.25 13.5h5.25"],reply:["M9.75 6 3.75 12l6 6","M4.5 12h9.75a6 6 0 0 1 6 6v.75"],passkey:["M12 3a6 6 0 0 0-6 6v3h12V9a6 6 0 0 0-6-6z","M5 12h14v9H5z"],phone:["M8 2h8a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z","M11 18h2"],tablet:["M6 3h12a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z","M11 18h2"],key:[Je(7.5,15.5,5.5),"m21 2-9.6 9.6M15.5 7.5l3 3L22 7l-3-3"],shield:["M12 3 4 6v6c0 5 8 9 8 9s8-4 8-9V6z"],laptop:[ln(4,4,16,11,1.5),"M2 19h20"],face:["M4 8V6a2 2 0 0 1 2-2h2M16 4h2a2 2 0 0 1 2 2v2M20 16v2a2 2 0 0 1-2 2h-2M8 20H6a2 2 0 0 1-2-2v-2M9 9v1M15 9v1M12 9v4h-1M9 15.5a4 4 0 0 0 6 0"],unlink:["M18.8 13.4l1.6-1.6a4.5 4.5 0 0 0-6.4-6.4l-1.6 1.6M5.2 10.6l-1.6 1.6a4.5 4.5 0 0 0 6.4 6.4l1.6-1.6M8 2v3M2 8h3M16 22v-3M22 16h-3"],clock:[Je(12,12,9),"M12 7v5l3 2"],lock:[ln(3,11,18,11,2),"M7 11V7a5 5 0 0 1 10 0v4"],bell:["M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9M10.3 21a1.9 1.9 0 0 0 3.4 0"],alert:["M12 3l10 18H2z","M12 10v4M12 17.5v.01"],cpu:[ln(6,6,12,12,2),"M9 2v4M15 2v4M9 18v4M15 18v4M2 9h4M2 15h4M18 9h4M18 15h4"],camera:["M4 8h3l2-3h6l2 3h3v11H4z",Je(12,13,3.5)],folder:["M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"],list:["M9 6h11M9 12h11M9 18h11M4 6l1 1 2-2M4 12l1 1 2-2M4 18h2"],down:["M6 9l6 6 6-6"],branch:[Je(6,5,2),Je(6,19,2),Je(18,8,2),"M6 7v10M18 10c0 4-6 3-12 7"],merge:[Je(6,5,2.2),Je(6,19,2.2),Je(18,12,2.2),"M6 7.2v9.6M6 7.2c0 3 4 4.8 9.8 4.8"],file:["M14 3H6a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8z","M14 3v5h5"],commit:[Je(12,12,3.5),"M3 12h5.5M15.5 12H21"]};function F({name:t,className:s="size-5",stroke:n=1.6}){return e.jsx("svg",{className:`flex-none ${s}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:n,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:Tm[t].map((a,l)=>e.jsx("path",{d:a},l))})}const _m={work:"bg-info",perm:"bg-approval",ask:"bg-attention",idle:"bg-ok",done:"bg-muted opacity-50",off:"bg-transparent shadow-[inset_0_0_0_1.5px_var(--color-muted)]",rig:"bg-task",plain:"bg-muted"};function Ie({state:t,pulse:s=!1,label:n}){return e.jsx("span",{"data-dot":t,...n?{role:"img","aria-label":n}:{"aria-hidden":!0},className:`inline-block size-2 flex-none rounded-full ${_m[t]} ${s?"animate-[ledge-pulse_1.6s_ease-in-out_infinite]":""}`})}const Im={claude:"CC",codex:"CX",cursor:"CU",omp:"OM"};function fs({tool:t}){return e.jsx("span",{"data-runtime":t,className:"flex-none rounded-[5px] bg-secondary px-[5px] py-px font-mono text-[11px] leading-4 font-medium",children:Im[t]})}const Rm={plain:"border-input text-muted",perm:"border-approval/50 text-approval",urgent:"border-approval/50 text-approval",ask:"border-attention/50 text-attention",work:"border-info/45 text-info",ok:"border-ok/45 text-ok",rig:"border-task/50 text-task",risk:"border-transparent bg-destructive text-primary-fg font-semibold"};function as({tone:t="plain",children:s}){return e.jsx("span",{"data-pill":t,className:`inline-flex h-5 flex-none items-center rounded-lg border px-[7px] text-[11.5px] whitespace-nowrap ${Rm[t]}`,children:s})}function ps({title:t,dot:s,count:n,sub:a,tone:l,none:r,label:i,children:o}){return e.jsxs("section",{"aria-label":t??i,className:`flex-none overflow-hidden rounded-[10px] border bg-surface dark:bg-transparent ${l==="rigs"?"border-task/45":"border-line"}`,children:[t&&e.jsxs("div",{className:"flex min-h-11 items-center gap-2 border-b border-line px-3",children:[s&&e.jsx(Ie,{state:s}),e.jsx("b",{className:"text-body font-semibold whitespace-nowrap",children:t}),n!==void 0&&e.jsx("span",{className:"text-[12.5px] text-muted",children:n}),a&&e.jsx("span",{className:"min-w-0 flex-1 truncate text-small text-muted",children:a})]}),r!==void 0?e.jsx("p",{className:"p-3 text-[13px] text-muted",children:r}):e.jsx("div",{className:"flex flex-col",children:o})]})}function hn({lead:t,title:s,sub:n,subTone:a,meta:l,metaWarn:r=!1,selected:i=!1,stale:o=!1,pressed:c=!1,href:x,press:u,children:m}){const p=`flex min-h-[52px] items-center gap-2 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0 ${o?"opacity-60":""} ${i?"bg-secondary shadow-[inset_2px_0_0_var(--color-primary)]":""} ${c?"shadow-[inset_0_0_0_2px_var(--color-ring)]":""}`,g=e.jsxs(e.Fragment,{children:[t,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate",children:s}),n!==void 0&&e.jsx("span",{className:`truncate text-small leading-4 ${a==="perm"?"text-approval":"text-muted"}`,children:n})]}),l!==void 0&&e.jsx("span",{className:`font-mono text-small whitespace-nowrap ${r?"text-attention":"text-muted"}`,children:l}),m]});return x?e.jsx("a",{href:x,"aria-current":i?"page":void 0,className:p,...u,children:g}):e.jsx("div",{className:p,children:g})}const Om={plain:"border-line",perm:"border-destructive/45",ask:"border-attention/45",rig:"border-destructive/40"};function Tc({tone:t="plain",selected:s=!1,label:n,children:a}){return e.jsx("article",{"aria-label":n,"data-card":t,className:`flex flex-col gap-2.5 rounded-lg border bg-surface p-3 ${Om[t]} ${s?"shadow-[0_0_0_2px_var(--color-ring)]":""}`,children:a})}function Qt({glyph:t,title:s,body:n,action:a,framed:l=!0,list:r=!1}){return e.jsxs("div",{"data-list-state":r?"":void 0,className:"flex flex-col items-center gap-1.5 px-4 pt-[26px] pb-[22px] text-center",children:[l?e.jsx("div",{"aria-hidden":"true",className:"grid size-12 place-items-center rounded-[10px] border border-line text-muted",children:t}):e.jsx("div",{"aria-hidden":"true",className:"text-muted",children:t}),e.jsx("h2",{className:"mt-1.5 text-[17px] leading-6 font-semibold",children:s}),e.jsx("p",{className:"max-w-[300px] text-[13.5px] text-muted",children:n}),a&&e.jsx("div",{className:"mt-2",children:a})]})}const Lm={outline:"border-input bg-surface dark:bg-transparent text-fg active:bg-raised",primary:"border-transparent bg-primary text-primary-fg active:bg-primary-hover",ghost:"border-transparent bg-transparent text-muted text-[13px] active:bg-raised"},zm={md:"h-11 px-3.5 text-body",sm:"h-9 px-3 text-[13px]",xs:"h-8 px-2.5 text-[12.5px]"},Oe=({variant:t="outline",size:s="md",className:n}={})=>["inline-flex items-center justify-center gap-2 rounded-lg border font-medium whitespace-nowrap transition-colors duration-100 disabled:opacity-45",Lm[t],t==="ghost"?"h-9 px-3.5":zm[s],n??""].filter(Boolean).join(" ");function Dm({label:t,options:s,value:n,onChange:a}){return e.jsx("div",{role:"group","aria-label":t,className:"flex flex-none gap-1.5 overflow-x-auto",children:s.map(l=>e.jsxs("button",{type:"button","aria-pressed":l.value===n,onClick:()=>a(l.value),className:"inline-flex h-8 flex-none items-center gap-1.5 rounded-lg border border-input px-3 text-[13px] font-medium whitespace-nowrap text-muted aria-pressed:border-ring aria-pressed:bg-raised aria-pressed:text-fg",children:[l.label,l.count!==void 0&&e.jsx("span",{className:"font-mono text-meta",children:l.count})]},l.value))})}function ea({back:t,tool:s,name:n,dot:a,pulse:l=!1,sub:r,under:i=!1,more:o}){return e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-0.5",children:[t,s&&e.jsx(fs,{tool:s}),i&&r?e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("b",{className:"min-w-0 truncate text-base leading-5 font-semibold",children:n}),a&&e.jsx(Ie,{state:a,pulse:l})]}),e.jsx("span",{className:"truncate text-[12px] leading-4 text-muted",children:r})]}):e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-base font-semibold whitespace-nowrap",children:n}),a&&e.jsx(Ie,{state:a,pulse:l}),r&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:r}),e.jsx("span",{className:"flex-1"})]}),o]})}function _c({label:t,sendLabel:s,placeholder:n,offlinePlaceholder:a,value:l,onChange:r,onSend:i,offline:o=!1}){const c=h.useId(),x=!o&&l.trim()!=="";return e.jsxs("div",{className:`flex items-end gap-2 rounded-[10px] border border-input bg-surface py-[5px] pr-[5px] pl-3 focus-within:border-ring focus-within:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)] ${o?"opacity-55":""}`,children:[e.jsx("label",{htmlFor:c,className:"sr-only",children:t}),e.jsx("textarea",{id:c,rows:1,value:o?"":l,disabled:o,placeholder:o?a:n,onChange:u=>r(u.target.value),className:"min-h-[34px] min-w-0 flex-1 resize-none bg-transparent py-[7px] text-base leading-[22px] text-fg outline-none placeholder:text-muted"}),e.jsx("button",{type:"button",disabled:!x,onClick:i,"aria-label":s,title:s,className:"grid size-9 flex-none place-items-center rounded-lg bg-primary text-primary-fg disabled:opacity-40",children:e.jsx(F,{name:"send",className:"size-[18px]"})})]})}function Fm({children:t}){return e.jsx("code",{className:"block rounded-[5px] bg-raised px-[9px] py-[7px] font-mono text-small leading-[18px] break-all whitespace-pre-wrap",children:t})}const Ic={permission:"approval",question:"attention",plan:"info",diff:"info"};function Pm(t,s){if(s){const n=s.risk==="high"&&s.kind!=="question";return{tone:n?"danger":Ic[s.kind],label:n?d.risk.badge:d.kind[s.kind]}}switch(t.state){case"waiting_permission":return{tone:"approval",label:d.kind.permission};case"waiting_input":return{tone:"attention",label:d.kind.question};case"idle":return{tone:"ok",label:d.agents.state.idle};case"exited":return{tone:"muted",label:d.agents.state.exited};case"error":return{tone:"danger",label:d.agents.state.error};default:return{tone:"info",label:d.agents.state.working}}}const Bm=t=>Pm(t,Wt([t])[0]);function Rc({store:t,label:s,ids:n,offline:a,startOpen:l=!1,onCancel:r}){const[i,o]=h.useState(l),[c,x]=h.useState(""),[u,m]=h.useState(!1),[p,g]=h.useState(null),f=async()=>{if(n.length>_a){g({lines:[d.agents.tooMany(n.length,_a)],error:!0});return}m(!0);const y=await t.broadcast(n,c.trim());if(m(!1),y.sent){const w=y.sent;g({lines:[...w.length?[d.agents.sentTo(w)]:[d.agents.nobody],...(y.refused??[]).map(S=>d.agents.refusedLine(S.name,S.reason))],error:w.length===0}),w.length&&(o(l),x(""))}else y.status==="expired"?g({lines:[d.agents.uncertain],error:!0}):g({lines:[d.agents.notSent],error:!0})};return e.jsxs("div",{className:"pb-2",children:[!i&&e.jsx("button",{type:"button",disabled:a,onClick:()=>{g(null),o(!0)},className:"text-meta text-info disabled:opacity-60",children:d.agents.writeGroup}),i&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:`group-${n[0]}`,className:"sr-only",children:d.agents.writeGroupLabel(s)}),e.jsx("textarea",{id:`group-${n[0]}`,rows:2,value:c,disabled:u,placeholder:d.agents.writeGroupPlaceholder,onChange:y=>x(y.target.value),className:"min-h-11 w-full resize-none rounded-[14px] border border-input bg-surface px-3.5 py-[11px] text-base leading-5 text-fg placeholder:text-muted disabled:opacity-60"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(We,{variant:"ghost",className:"flex-1",disabled:u,onClick:()=>{o(!1),x(""),r==null||r()},children:d.agents.cancel}),e.jsx(We,{variant:"primary",className:"flex-[2]",disabled:u||!c.trim(),onClick:()=>void f(),children:d.agents.send})]})]}),p&&e.jsx("div",{role:"status",className:`mt-1 text-meta ${p.error?"text-attention":"text-muted"}`,children:p.lines.map((y,w)=>e.jsx("p",{className:"[overflow-wrap:anywhere]",children:y},w))})]})}const Ai=new Set(["-o","--push-option","--repo","--receive-pack","--exec"]),qm=new Set(["-f","--force","--force-with-lease","--force-if-includes","--delete","-d","--mirror","--prune"]);function Hm(t){const s=t.trim().split(/\s+/);if(s[0]!=="git")return null;const n=s.indexOf("push");if(n<1)return null;let a=!1;const l=[],r=s.slice(n+1);for(let u=0;u<r.length;u++){const m=r[u];if(m.startsWith("--")){const p=m.split("=")[0];qm.has(p)?a=!0:Ai.has(p)&&!m.includes("=")&&u++}else m.startsWith("-")&&m.length>1?/[fd]/.test(m.slice(1))?a=!0:Ai.has(m)&&u++:l.push(m)}const[i="",...o]=l;o.some(u=>u.startsWith("+")||u.startsWith(":"))&&(a=!0);const c=o[0],x=c==null?void 0:c.replace(/^\+/,"").split(":").pop();return{remote:i,...x?{branch:x}:{},force:a}}function Um(t){return t.risk!=="low"||t.riskReason!=="edit_inside_folder"?null:{title:d.detail.editsInProject,body:d.detail.editsInProjectBody}}function Oc(t){if(t.risk==="low")return null;const s=d.consequence,n=t.riskReason;if(n==="pushes"){const a=Hm(t.text),l=a!=null&&a.remote?a.branch?`${a.remote}/${a.branch}`:a.remote:s.configuredRemote;return a!=null&&a.force?{title:s.forceTitle,body:s.forceBody(a.remote?l:void 0),destination:l}:{title:s.pushTitle,body:s.pushBody,destination:l}}switch(n){case"destroys":case"deploys":case"publishes":case"pipes_to_shell":case"network":case"writes_outside_folder":case"sensitive_path":case"script":case"plan":{const[a,l]=s[n];return{title:a,body:l}}default:{const[a,l]=s.unknown;return{title:a,body:l}}}}const Or=Qn,Wm=/^[1-9]$/;function Lc(t){const s=t.trim();return s===""?{text:s,problem:"empty"}:rc.test(s)?{text:s,problem:"untypable"}:s.length>Or?{text:s,problem:"long"}:Wm.test(s)?{text:s,problem:"digit"}:{text:s,problem:null}}function Lr(t,s,n){var a;if(t.kind==="plan"||t.kind==="diff")return{kind:"examine"};if((s==null?void 0:s.decide)===!1||t.kind==="question"&&(s==null?void 0:s.questions)===!0&&t.requestId!==void 0&&((a=t.questions)!=null&&a.length))return{kind:"examine"};if(t.kind==="question"){if(n)return{kind:"readOnly"};const l=t.options??[],r=(s==null?void 0:s.freeTextAnswer)===!0;return r||l.length>0?{kind:"question",options:l,other:r}:{kind:"answerOnPc",options:l}}return t.risk==="high"?{kind:"high"}:{kind:"permission",always:ic(t.tool,t.kind,"always")}}const Ql=t=>vx(t.tool,{kind:t.kind,...t.pendingTool?{tool:t.pendingTool}:{}}),La=t=>t==="project"?d.atoi.always:t==="plan"?d.atoi.approveAuto:d.atoi.alwaysSession,Ti={critical:0,urgent:1,routine:2},zc=t=>[...t].sort((s,n)=>Ti[s.priority]-Ti[n.priority]||Date.parse(s.createdAt)-Date.parse(n.createdAt)),Dc=t=>t.kind==="update"?"update":t.kind==="parked"?"parked":t.questions.length>0?"decision":"question",Km=t=>(t==null?void 0:t.replace(/\.agent$|\.lead$|\.worker$/,""))??null,Fc=t=>({name:t.from.seat.split("@")[0]||t.from.seat,role:Km(t.from.role)});function _i(t,s){var l;const n=t.questions.find(r=>r.id===s),a=n==null?void 0:n.answer;return a?a.kind==="words"?a.text:((l=n.options.find(r=>r.id===a.id))==null?void 0:l.label)??a.id:null}function Vm(t,s){var n,a;switch(s.kind){case"choice":return((a=(n=t.questions.find(l=>l.id===s.questionId))==null?void 0:n.options.find(l=>l.id===s.optionId))==null?void 0:a.label)??s.optionId;case"words":case"resolve":return s.text;case"seen":return""}}function Pc(t,s){const n=Object.values(s).filter(r=>r.message.type==="openrig.answer"&&r.message.qitemId===t).sort((r,i)=>r.at.localeCompare(i.at)),a=n[n.length-1];if(!a)return{kind:"none"};const l=a.message.answer;if(a.rig){const r=a.rig;return r.rejected?{kind:"refused",answer:l,reason:r.rejected}:r.ok?r.outcome==="recorded"?{kind:"recorded",answer:l}:r.outcome==="already"?{kind:"already"}:{kind:"sent",answer:l}:r.error==="closed"||r.error==="not_found"?{kind:"already"}:r.error==="uncertain"?{kind:"uncertain",answer:l}:{kind:"failed",answer:l,error:r.error??"unreachable",...r.message?{message:r.message}:{}}}return us(a.phase)?a.phase==="uncertain"?{kind:"uncertain",answer:l}:{kind:"sending",answer:l}:a.phase==="applied"?{kind:"sent",answer:l}:{kind:"failed",answer:l,error:a.reason??"unreachable"}}const va=5;function Gm(t,s){return t.filter(n=>n.state==="working"&&!s.has(n.id)).sort((n,a)=>Date.parse(a.lastActivityAt)-Date.parse(n.lastActivityAt))}const Xm=6,Bc=5e3;function fl(t,s){return[...t.map(n=>({name:"request",sessionId:n.sessionId,key:n.key})),...zc(s).filter(n=>n.kind!=="update").map(n=>({name:"ask",id:n.id}))]}const wa=(t,s)=>t.name==="request"?s.name==="request"&&t.sessionId===s.sessionId:s.name==="ask"&&t.id===s.id;function Qm(t,s,n=t){const a=t.filter(i=>!wa(i,s)),l=n.findIndex(i=>wa(i,s));return(l<0?[]:n.slice(l+1)).find(i=>a.some(o=>wa(o,i)))??a[0]??null}function Ym(t,s,n){if(!t.length)return null;const a=s?t.findIndex(l=>wa(l,s)):-1;return a<0?t[0]:t[Math.min(t.length-1,Math.max(0,a+n))]}function Un(t,s,n){var o;const a=(o=s.find(c=>c.id===t.sessionId))==null?void 0:o.pending,l=(a==null?void 0:a.key)===t.key,r=Object.values(n).filter(c=>"id"in c.message&&c.message.id===t.sessionId&&Gx(c.message)===t.key).sort((c,x)=>c.at.localeCompare(x.at)),i=r.find(c=>c.phase==="applied")??r[r.length-1];if(i){const c=i.message;switch(i.phase){case"sending":return{kind:"sending"};case"uncertain":return{kind:"uncertain"};case"applied":return{kind:"applied",...c.type==="session.decide"?{decision:c.decision}:{},...c.type==="session.reply"?{answer:c.text}:{},...c.type==="session.answer"?{answer:c.answers.flatMap(x=>x.selected).join(", ")}:{}};case"rejected":return i.reason==="stale"&&!l?a!=null&&a.key?{kind:"changed"}:{kind:"handledElsewhere"}:{kind:"rejected",reason:i.reason??"invalid"};case"failed":return{kind:"failed",reason:i.reason??"invalid"}}}return l?{kind:"idle"}:{kind:"handledElsewhere"}}function Sn(t=4e3){const[s,n]=h.useState(!1);return h.useEffect(()=>{if(!s)return;const a=setTimeout(()=>n(!1),t);return()=>clearTimeout(a)},[s,t]),[s,n]}function Yt(){const[t,s]=h.useState(Date.now);return h.useEffect(()=>{const n=setInterval(()=>s(Date.now()),15e3);return()=>clearInterval(n)},[]),t}const Zm={approval:"text-approval bg-approval/10",attention:"text-attention bg-attention/10",info:"text-info bg-info/10",ok:"text-ok bg-ok/10",muted:"text-muted bg-fg/[0.05]",danger:"text-danger-fg bg-danger-fg/10"};function ta({tone:t,label:s}){return e.jsx("span",{className:`inline-flex h-[22px] flex-none items-center rounded-md px-2 text-meta leading-none font-medium whitespace-nowrap ${Zm[t]}`,children:s})}function Jm({kind:t,risk:s="low"}){const n=s==="high"&&t!=="question";return e.jsx(ta,{tone:n?"danger":Ic[t],label:n?d.risk.badge:d.kind[t]})}function ep({text:t}){return e.jsx("pre",{className:"my-3.5 rounded-control border border-line bg-well p-3.5 font-mono text-small leading-[1.8] break-words whitespace-pre-wrap [overflow-wrap:anywhere]",children:t})}const $n=t=>{var s;return{fresh:t.fresh,pc:((s=t.daemon)==null?void 0:s.name)??null}};function qc({link:t}){return e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-meta whitespace-nowrap text-muted",children:[e.jsx("i",{className:`inline-block size-1.5 flex-none rounded-full ${t.fresh?"bg-ok":"bg-muted"}`}),e.jsxs("span",{className:"truncate",children:[t.pc?`${t.pc} · `:"",t.fresh?d.link.online:d.link.offline]})]})}function ls({fallback:t,label:s}){const n=xm(t),a=n.inApp?n.known?d.nav.backTo[n.route.name]??d.nav.back:d.nav.back:s;return e.jsx("a",{href:ae(n.route),"data-back":t.name,"aria-label":a,title:a,onClick:l=>{l.preventDefault(),Tr(t)},className:$t({className:"-ml-2"}),children:e.jsx(F,{name:"back"})})}function sa({title:t,fallback:s,label:n,link:a}){return e.jsx("header",{className:"flex-none border-b border-line pt-2 pb-3",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(ls,{fallback:s,label:n}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),e.jsx(qc,{link:a})]})})}const hl={},Hc={grow:{ms:320,ease:"cubic-bezier(.22,1,.36,1)",delayMs:0},shrink:{ms:260,ease:"cubic-bezier(.65,0,.35,1)",delayMs:60},cardExit:{ms:300,ease:"cubic-bezier(.65,0,.35,1)",delayMs:180},pop:{ms:260,ease:"cubic-bezier(.34,1.3,.64,1)",delayMs:0},fadeIn:{ms:180,ease:"ease-out",delayMs:140},fadeOut:{ms:100,ease:"ease-in",delayMs:0},hover:{ms:150,ease:"ease-out",delayMs:0}},tp=()=>{const t=hl==null?void 0:hl.VITE_LEDGE_MOTION;return t===void 0?1:Number(t)},Nt=t=>`${Math.round(t*tp())}ms`;function sp(t){return t.map(([s,n,a])=>{const l=Hc[n];return`${s} ${Nt(l.ms)} ${l.ease} ${Nt(a??l.delayMs)}`}).join(", ")}const np="(prefers-reduced-motion: reduce)",Uc=()=>typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia(np):null;function ap(t){const s=Uc();return s==null||s.addEventListener("change",t),()=>s==null?void 0:s.removeEventListener("change",t)}const lp=()=>{var t;return((t=Uc())==null?void 0:t.matches)??!1};function rp(){return!1}function Wc(){return h.useSyncExternalStore(ap,lp,()=>!1)}const ip=()=>({reduced:Wc()||rp(),app:!1,setReduced(){}});let op=ip;function cp(){return op()}function dp(t){return t==="dark"?"signal":"pebble"}function gn(t){let s=7;for(let n=0;n<t.length;n++)s=s*31+t.charCodeAt(n)>>>0;return s}function Xa(t,s){return gn(`${t}:${s}`)%3+1}const kt={blinkMs:180,gazePx:1.4,gazeYPx:.3,askDelayMs:180,transitionMs:500,hopMs:480,touchMs:360,idleMs:1700,askMs:850,nodMs:650},gl=(t,s)=>s===0?1400+t%3500:3400+(t+s*997)%3300,bl=(t,s)=>s===0?800+t%1800:2400+(t+s*557)%2100,Yl=new Set(["done","error","readonly"]),jl=(t,s)=>s===0?3500+t%4e3:5500+(t+s*557)%3500,vs=t=>!document.hidden&&!t.closest("[inert]");function za(t,s){document.addEventListener("visibilitychange",s);const n=new MutationObserver(s);return n.observe(document.documentElement,{attributes:!0,subtree:!0,attributeFilter:["inert"]}),()=>{document.removeEventListener("visibilitychange",s),n.disconnect()}}function up(t){h.useEffect(()=>{const s=t.current;if(!s)return;const n=()=>s.setAttribute("data-suspended",String(!vs(s)));return n(),za(s,n)},[t])}function rn(t,s,n){t.style.setProperty("--bot-gx",`${s}px`),t.style.setProperty("--bot-gy",`${n}px`)}function xp(t,s){const{seed:n,state:a,enabled:l,askKey:r,nodKey:i,gazeReach:o=0}=s,c=gn(n),x=l&&!Yl.has(a),u=h.useRef(null),m=h.useRef(a),p=h.useRef(i),g=h.useRef(void 0);h.useEffect(()=>{const f=t.current;if(!f||!x)return;let y,w,S;const b=()=>vs(f),j=()=>{y!==void 0&&clearTimeout(y),w!==void 0&&clearTimeout(w),S!==void 0&&clearTimeout(S),y=w=S=void 0,f.removeAttribute("data-idle"),rn(f,0,0),f.removeAttribute("data-blink")},N=()=>{if(j(),!b())return;const E=Date.now();(!u.current||u.current.h!==c)&&(u.current={h:c,blinkAt:E+gl(c,0),lookAt:E+bl(c,0),idleAt:E+jl(c,0),blinks:0,looks:0,idles:0});const k=u.current;k.blinkAt<E&&(k.blinkAt=E+gl(c,++k.blinks)),k.lookAt<E&&(k.lookAt=E+bl(c,++k.looks)),k.idleAt<E&&(k.idleAt=E+jl(c,++k.idles)),y=setTimeout($,Math.min(k.blinkAt,k.lookAt,k.idleAt)-E)},$=()=>{if(y=void 0,!b()){j();return}const E=u.current,k=Date.now();if(k>=E.blinkAt&&(f.setAttribute("data-blink","true"),w!==void 0&&clearTimeout(w),w=setTimeout(()=>{w=void 0,f.removeAttribute("data-blink")},kt.blinkMs),E.blinkAt=k+gl(c,++E.blinks)),k>=E.lookAt){E.looks++;const T=a==="working";!f.hasAttribute("data-hover")&&!f.hasAttribute("data-transition")&&rn(f,T?E.looks%2?kt.gazePx:-1.4:0,T?kt.gazeYPx:0),E.lookAt=k+bl(c,E.looks)}if(k>=E.idleAt){E.idles++;const T=a;!f.hasAttribute("data-hover")&&!f.hasAttribute("data-transition")&&(T==="idle"||T==="question")&&(f.setAttribute("data-idle",T==="question"?"tilt":E.idles%4===0?"stretch":"look"),S=setTimeout(()=>{S=void 0,f.removeAttribute("data-idle")},kt.idleMs)),E.idleAt=k+jl(c,E.idles)}y=setTimeout($,Math.min(E.blinkAt,E.lookAt,E.idleAt)-k)};N();const A=za(f,()=>{b()&&y===void 0?N():b()||j()});return()=>{j(),A()}},[t,x,c,a]),h.useEffect(()=>{const f=t.current,y=m.current,w=g.current,S=p.current!==i&&i!==void 0;if(p.current=i,m.current=a,g.current=r,!f)return;rn(f,0,0),f.removeAttribute("data-idle");const b=a==="approval"&&(y!=="approval"||r!==void 0&&r!==w),j=new Set,N=(z,U)=>{const H=setTimeout(()=>{j.delete(H),vs(f)?z():$()},U);return j.add(H),H},$=()=>{j.forEach(clearTimeout),j.clear(),["data-transition","data-gesture","data-touch","data-hover","data-idle"].forEach(z=>f.removeAttribute(z)),rn(f,0,0)};let A=!1,E=!1;l&&vs(f)&&(y!==a&&["working","question","idle","done","error"].includes(a)&&(f.setAttribute("data-transition",a),N(()=>f.removeAttribute("data-transition"),a==="working"?kt.hopMs:a==="question"?650:kt.transitionMs)),b&&!S&&N(()=>{A=!0,f.setAttribute("data-gesture","ask"),N(()=>{f.getAttribute("data-gesture")==="ask"&&f.removeAttribute("data-gesture")},kt.askMs)},kt.askDelayMs));const k=()=>l&&!Yl.has(a)&&vs(f),T=z=>{if(!k()||z.pointerType==="touch")return;const U=f.getBoundingClientRect();if(!U.width||!U.height)return;const H=z.clientX-U.left-U.width/2,V=z.clientY-U.top-U.height/2;if(o>0&&(Math.abs(H)>U.width/2+o||Math.abs(V)>U.height/2+o)){f.hasAttribute("data-hover")&&C();return}f.setAttribute("data-hover","true"),f.removeAttribute("data-idle");const ee=G=>Math.max(-2,Math.min(2,G));rn(f,ee(H/(U.width/2+o)*2),ee(V/(U.height/2+o)*2))},C=()=>{f.removeAttribute("data-hover"),rn(f,0,0)},I=o>0?window:f,P=o>0?document.documentElement:f;let L;const R=()=>{k()&&(L!==void 0&&(clearTimeout(L),j.delete(L)),f.removeAttribute("data-touch"),f.getBoundingClientRect(),f.setAttribute("data-touch","true"),L=N(()=>f.removeAttribute("data-touch"),kt.touchMs))};I.addEventListener("pointermove",T),P.addEventListener("pointerleave",C),f.addEventListener("click",R);const M=za(f,()=>{vs(f)||(E=!0,$())});return()=>{$(),M(),I.removeEventListener("pointermove",T),P.removeEventListener("pointerleave",C),f.removeEventListener("click",R);const z=["data-paused","data-frozen","data-reduced","data-readonly"].some(U=>f.getAttribute(U)==="true");!A&&b&&!S&&f.getAttribute("data-state")===a&&l&&!E&&vs(f)&&!z&&(g.current=w)}},[t,a,l,r,i,c,o])}function mp(t,s,n,a,l){const r=h.useRef(s);h.useEffect(()=>{const i=t.current,o=r.current!==s;if(r.current=s,!i||!o||s===void 0||!n||!vs(i)||Yl.has(a))return;i.setAttribute("data-gesture","nod");const c=setTimeout(()=>{i.getAttribute("data-gesture")==="nod"&&i.removeAttribute("data-gesture")},kt.nodMs),x=()=>{clearTimeout(c),i.getAttribute("data-gesture")==="nod"&&i.removeAttribute("data-gesture")},u=za(i,()=>{vs(i)||x()});return()=>{u(),x()}},[t,s,n,a,l])}const pp={claude:"Claude Code",codex:"Codex",cursor:"Cursor Agent",omp:"omp"},fp={starting:{eyes:"open",eye:"starting"},working:{eyes:"open",eye:"working"},approval:{eyes:"open",eye:"approval",tilt:[-4,3,-2],lift:-1},question:{eyes:"wide",eye:"question",tilt:[4,-3,6]},idle:{eyes:"happy",eye:"idle"},error:{eyes:"error",eye:"error",tilt:[-7,-6,-5],lift:2},done:{eyes:"sleep",eye:"done"},readonly:{eyes:"open",eye:"done"}},hp="0 0 96 96",Kc={claude:"10 18 76 64",codex:"5 7 87 82",cursor:"11 8 74 82",omp:"10 18 76 68"},gp=Object.fromEntries(Object.entries(Kc).map(([t,s])=>[t,Number(s.split(" ")[2])])),bp={claude:"M24 24H72Q75 24 75 27V43H82Q84 43 84 45V52Q84 54 82 54H75V62Q75 64 73 64H70V75Q70 77 68 77H66Q64 77 64 75V64H59V75Q59 77 57 77H55Q53 77 53 75V64H43V75Q43 77 41 77H39Q37 77 37 75V64H32V75Q32 77 30 77H28Q26 77 26 75V64H23Q21 64 21 62V54H14Q12 54 12 52V45Q12 43 14 43H21V27Q21 24 24 24Z",codex:"M30 25C31 13 48 10 57 20C69 14 84 23 81 37C92 46 87 62 76 65C76 80 58 86 48 77C35 85 20 78 21 66C7 61 7 45 18 38C13 28 21 20 30 25Z",cursor:"M43 13Q48 10 53 13L77 27Q82 30 82 36V64Q82 69 77 72L53 85Q48 88 43 85L19 72Q14 69 14 64V36Q14 30 19 27Z",omp:"M17 22H79Q83 22 83 26V48Q83 52 79 52H71V79Q71 83 67 83H58Q54 83 54 79V52H41V67Q41 71 37 71H28Q24 71 24 67V52H17Q13 52 13 48V26Q13 22 17 22Z"},jp={claude:"translate(0 -8)",codex:void 0,cursor:"translate(31.5 58) skewY(27) scale(.86) translate(-48.5 -49)",omp:"translate(0 -12)"},yp=240;function Qa({tool:t,state:s,pose:n,size:a,shownSize:l,theme:r,seed:i,readOnly:o=!1,frozen:c=!1,paused:x=!1,reducedMotion:u,askKey:m,nodKey:p,className:g}){var U;const f=h.useRef(null),y=`bot-shell-${h.useId().replace(/[^A-Za-z0-9_-]/g,"")}`,w=cp(),b=Wc()||(u??w.reduced),j=a<=20,N=fp[s],$=!o&&s!=="done"&&s!=="readonly",A=Cr(),E=gn(i),k=s==="working"&&!b&&!o&&!c&&!x,T=l??a,I=Math.min(7,Math.max(2,T*.12))/T*(j?gp[t]:96),P=3600+E%9*100,L=!j&&T>20,R=!b&&!o&&s!=="readonly"&&!c&&!x;up(f),xp(f,{seed:i,state:s,askKey:m,nodKey:p,enabled:R&&L,gazeReach:yp}),mp(f,p,R&&L,s,m);const M={"--bot-size":`${a}px`,"--bot-eye":`var(--bot-eye-${N.eye})`,"--bot-tilt":`${((U=N.tilt)==null?void 0:U[n-1])??0}deg`,"--bot-lift":`${N.lift??0}px`,"--bot-breath":Nt(4800+E%17*100),"--bot-phase":`-${Nt(E%43*100)}`,"--bot-hop":`${I.toFixed(2)}px`,"--bot-hop-cycle":Nt(P),"--bot-ease":Hc.grow.ease,"--bot-material-ms":Nt(240),"--bot-eye-ms":Nt(260),"--bot-pose-ms":Nt(300),"--bot-gaze-ms":Nt(450),"--bot-blink-ms":Nt(kt.blinkMs),"--bot-ask-ms":Nt(kt.askMs),"--bot-nod-ms":Nt(kt.nodMs),"--bot-question-ms":Nt(650),"--bot-arrival-ms":Nt(kt.transitionMs),"--bot-entry-hop-ms":Nt(kt.hopMs),"--bot-touch-ms":Nt(kt.touchMs),"--bot-idle-ms":Nt(kt.idleMs)},z=`${pp[t]} · ${A.botLabel[s]}${o&&s!=="readonly"?` · ${A.botReadOnly}`:""}${c?` · ${A.botNotLive}`:""}`;return e.jsxs("svg",{ref:f,className:g?`bot ${g}`:"bot",role:"img","aria-label":z,width:a,height:a,viewBox:j?Kc[t]:hp,"data-tool":t,"data-state":s,"data-eyes":N.eyes,"data-pose":n,"data-material":dp(r),"data-simplified":String(j),"data-detailed":String(L),"data-readonly":String(o||s==="readonly"),"data-halo":String($),"data-frozen":String(c),"data-paused":String(x),"data-reduced":String(b),"data-hop":String(k),style:M,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:y,x1:".1",y1:"0",x2:".8",y2:"1",gradientUnits:"objectBoundingBox",children:[e.jsx("stop",{className:"shell-top"}),e.jsx("stop",{className:"shell-bottom",offset:"1"})]})}),e.jsx("ellipse",{className:"ground",cx:"48",cy:"90",rx:"25",ry:"3"}),e.jsx("g",{className:"hop",children:e.jsx("g",{className:"body",children:e.jsx("g",{className:"arrival",children:e.jsx("g",{className:"signature",children:e.jsx("g",{className:"touch",children:e.jsxs("g",{className:"pose",children:[e.jsx("path",{className:"shell",d:bp[t],fill:`url(#${y})`}),t==="cursor"&&e.jsxs("g",{className:"facets",children:[e.jsx("path",{className:"cube-top",d:"M43 13Q48 10 53 13L77 27Q80 29 81 32L48 49L15 32Q16 29 19 27Z"}),e.jsx("path",{className:"cube-side",d:"M48 49L81 32Q82 34 82 36V64Q82 69 77 72L53 85Q50 87 48 87Z"}),e.jsx("path",{className:"cube-edge",d:"M17 32L48 49L79 32M48 49V83"})]}),t==="claude"&&e.jsx("path",{className:"shine",d:"M27 28H69"}),e.jsx("g",{transform:jp[t],children:e.jsx("g",{className:"gaze",children:e.jsxs("g",{className:"eye-blink",children:[e.jsxs("g",{className:"eye-open",children:[e.jsx("rect",{x:"36",y:"43",width:"6",height:"12",rx:t==="claude"?.6:3}),e.jsx("rect",{x:"55",y:"43",width:"6",height:"12",rx:t==="claude"?.6:3})]}),L&&e.jsxs("g",{className:"eye-glint",children:[e.jsx("rect",{x:"37.5",y:"44.5",width:"2.4",height:"2.4",rx:t==="claude"?0:1.2}),e.jsx("rect",{x:"56.5",y:"44.5",width:"2.4",height:"2.4",rx:t==="claude"?0:1.2})]}),e.jsx("path",{className:"eye-happy",d:"M35 51Q39 43 43 51M54 51Q58 43 62 51"}),e.jsx("path",{className:"eye-error",d:"m35 45 8 3m11 0 8-3M38 54h2m16 0h2"}),e.jsx("path",{className:"eye-sleep",d:"M35 50q4 3 8 0m11 0q4 3 8 0"})]})})}),t==="claude"?e.jsx("rect",{className:"arm",x:"75",y:"56",width:"8",height:"12",rx:"2"}):e.jsx("ellipse",{className:"arm",cx:"79",cy:"63",rx:"5",ry:"8"})]})})})})})})]})}const Np={blink:180,curious:900,hello:1100,boop:700,happy:900,look:1800,stretch:1600,tap:1150,pulse:1400,nod:700,yawn:1700,sleep:3200},yl=(t,s)=>Math.max(-s,Math.min(s,t)),Ii="M25 60V41C25 28 35 23 48 23C61 23 71 28 71 41V60Z";function zr({size:t,theme:s,paused:n=!1,frozen:a=!1,reducedMotion:l=!1,dnd:r=!1,pointer:i=null,center:o,gestureKey:c,gestureKind:x="hello",boopKey:u}){const m=Cr(),p=`resident-${h.useId().replace(/[^A-Za-z0-9_-]/g,"")}`,[g,f]=h.useState(null),[y,w]=h.useState(!1),S=h.useRef(void 0),b=n||l||r||a,j=!b&&!!i&&!!o&&Math.hypot(i.x-o.x,i.y-o.y)<140,N=j?yl((i.x-o.x)/140*5,4):0,$=j?yl((i.y-o.y)/140*3,2):0,A=j?yl((i.x-o.x)/140*7,5):0,E=C=>{b||document.hidden||(clearTimeout(S.current),f(null),f(C),S.current=setTimeout(()=>f(null),Np[C]))};h.useEffect(()=>()=>clearTimeout(S.current),[]),h.useEffect(()=>{c&&E(x)},[c]),h.useEffect(()=>{u&&E("boop")},[u]);const k=h.useRef(!1);h.useEffect(()=>{j&&!k.current&&!y&&E("curious"),k.current=j},[j]),h.useEffect(()=>{if(b){f(null),clearTimeout(S.current);return}let C,I=0;const P=()=>{!document.hidden&&!y&&(I++,E(I%17===0?"sleep":I%13===0?"yawn":I%11===0?"tap":I%7===0?"stretch":I%5===0?"look":"blink")),C=setTimeout(P,4300+I%3*900)};C=setTimeout(P,3200);const L=()=>{document.hidden&&(f(null),clearTimeout(S.current))};return document.addEventListener("visibilitychange",L),()=>{clearTimeout(C),document.removeEventListener("visibilitychange",L)}},[b,y]);const T={"--resident-gx":N?`${N.toFixed(2)}px`:"0px","--resident-gy":$?`${$.toFixed(2)}px`:"0px","--resident-tilt":A?`${A.toFixed(2)}deg`:"0deg"};return e.jsxs("svg",{className:"resident",width:t,height:t,viewBox:t<=24?"5 8 86 74":"0 0 96 96",role:"img","aria-label":"Ledge","data-theme":s,"data-large":String(t>24),"data-near":String(j),"data-dnd":String(r),"data-frozen":String(a),"data-quiet":String(b),"data-gesture":g??void 0,style:T,onMouseEnter:()=>{w(!0),E("happy")},onMouseLeave:()=>w(!1),children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:`${p}-shell`,x1:".15",y1:"0",x2:".75",y2:"1",children:[e.jsx("stop",{className:"resident-top"}),e.jsx("stop",{className:"resident-bottom",offset:"1"})]}),e.jsxs("radialGradient",{id:`${p}-sheen`,cx:".3",cy:".2",r:".75",children:[e.jsx("stop",{className:"resident-sheen"}),e.jsx("stop",{className:"resident-sheen",offset:"1",stopOpacity:"0"})]})]}),e.jsx("g",{className:"resident-body",children:e.jsxs("g",{className:"resident-pose",children:[e.jsx("path",{className:"resident-antenna",d:"M48 23v-7"}),e.jsx("circle",{className:"resident-light",cx:"48",cy:"14",r:"2.6"}),e.jsx("path",{className:"resident-shell",d:Ii,fill:`url(#${p}-shell)`}),t>24&&e.jsx("path",{d:Ii,fill:`url(#${p}-sheen)`}),e.jsx("g",{className:"resident-gaze",children:e.jsxs("g",{className:"resident-blink",children:[e.jsxs("g",{className:"resident-eyes",children:[e.jsx("rect",{x:"37",y:"35",width:"6",height:"12",rx:"3"}),e.jsx("rect",{x:"53",y:"35",width:"6",height:"12",rx:"3"}),t>24&&e.jsxs("g",{className:"resident-glint",children:[e.jsx("circle",{cx:"38.8",cy:"37.8",r:"1.5"}),e.jsx("circle",{cx:"54.8",cy:"37.8",r:"1.5"})]})]}),e.jsx("path",{className:"resident-smile",d:"M36 43q4-7 8 0m8 0q4-7 8 0"}),e.jsx("path",{className:"resident-sleep",d:"M36 42q4 4 8 0m8 0q4 4 8 0"})]})})]})}),e.jsx("rect",{className:"resident-wall",x:"9",y:"59",width:"78",height:"20",rx:"6"}),e.jsx("rect",{className:"resident-slab",x:"6",y:"55",width:"84",height:"7",rx:"3.5"}),e.jsx("path",{className:"resident-rim",d:"M12 56.4H84"}),e.jsx("rect",{className:"resident-shell resident-grip",x:"26",y:"50",width:"12",height:"9",rx:"4.5",fill:`url(#${p}-shell)`}),e.jsx("rect",{className:"resident-shell resident-hand",x:"58",y:"50",width:"12",height:"9",rx:"4.5",fill:`url(#${p}-shell)`}),e.jsx("title",{children:a?m.residentOffline:m.residentName})]})}const kp={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"};function Dr({tool:t,seed:s,state:n,large:a=!1,frozen:l=!1}){const r=kp[n],i=en();return e.jsx("span",{className:"inline-flex flex-none","aria-hidden":"true",children:e.jsx(Qa,{tool:t,seed:s,state:r,pose:Xa(s,r),size:a?68:34,theme:i,frozen:l})})}function hs(t){return e.jsx(zr,{...t,theme:en()})}const vp={plain:"border-line bg-surface",warning:"border-attention/25 bg-attention/[0.06]",approval:"border-approval/25 bg-approval/[0.06]",danger:"border-danger-fg/25 bg-danger-bg"};function Ve({title:t,tone:s="plain",children:n,role:a}){return e.jsxs("div",{role:a,className:`rounded-control border p-3.5 text-small leading-[1.65] ${vp[s]}`,children:[e.jsx("strong",{className:"mb-[5px] block text-body",children:t}),n]})}var Fr=wx();const Pr="(min-width: 768px) and (min-height: 501px)",wp=`${Pr} and (orientation: landscape)`,Ri=t=>typeof globalThis.matchMedia=="function"?globalThis.matchMedia(t):null;function Vc(t){return h.useSyncExternalStore(s=>{var a;const n=Ri(t);return(a=n==null?void 0:n.addEventListener)==null||a.call(n,"change",s),()=>{var l;return(l=n==null?void 0:n.removeEventListener)==null?void 0:l.call(n,"change",s)}},()=>{var s;return((s=Ri(t))==null?void 0:s.matches)??!1},()=>!1)}function It(){return Vc(Pr)}function Ya(){return Vc(wp)}const Gc=h.createContext(void 0),Xc=()=>h.useContext(Gc);function is({list:t,detail:s,tab:n,fold:a=!1}){const[l,r]=h.useState(null);return e.jsxs("div",{className:"split","data-split":n,"data-fold":a?"":void 0,children:[e.jsx("div",{ref:r,className:"split-banner"}),e.jsxs(Gc.Provider,{value:l,children:[e.jsx("section",{className:"split-list",children:t}),e.jsx("section",{className:"split-detail",children:s})]})]})}function Nl({title:t,body:s}){return e.jsx("div",{"data-split-empty":"",className:"flex flex-1 items-center justify-center px-6 text-center",children:e.jsxs("div",{className:"max-w-[280px]",children:[e.jsx("h2",{className:"text-base font-semibold",children:t}),e.jsx("p",{className:"mt-1 text-body text-muted",children:s})]})})}const Sp=["atoi","sessions","prs","rigs","chat"];function Br(t){switch(t.name){case"atoi":case"request":case"ask":return"atoi";case"sessions":case"thread":case"terminal":case"launch":return"sessions";case"prs":case"rigs":case"chat":return t.name;case"rig":case"kernel":case"max":return"rigs";case"pr":return"prs";case"atelier":return"atelier";case"connection":return null}}const Qc=t=>({name:t}),$p=t=>Br(t)===t.name&&!(t.name==="atelier"&&t.sessionId),Yc=new Map;function Cp(t){const s=Br(t);s&&s!=="atelier"&&Yc.set(s,ae(t))}const qr=t=>Yc.get(t)??ae(Qc(t));function Mp(t,s=[]){const n=t.filter(r=>r.filter==="permission").length,a=t.length-n+s.filter(r=>r.kind!=="update").length,l=n||a;return l?{text:l>99?"99+":String(l),tone:n?"red":"amber"}:null}function Ep(t,s,n){return t?"online":n==="pc_offline"||n==="relay_unreachable"?"offline":s?"reconnecting":"loading"}const Zc=h.createContext({pc:null,look:"online",reach:"pc_online",since:"",retry:()=>{}}),kl=Zc.Provider,qt=()=>h.useContext(Zc),Bt=t=>{const s=t??d.host.unknown;return s.length>14?`${s.slice(0,13)}…`:s};function Jc({size:t=24}){return e.jsxs("svg",{"data-ledge-mark":!0,width:t,height:t,viewBox:"0 0 16 16","aria-hidden":"true",className:"flex-none",children:[e.jsx("rect",{width:"16",height:"16",rx:"3.5",fill:"#0A0A0A"}),e.jsx("rect",{x:"3",y:"3",width:"3",height:"10",rx:".5",fill:"#FAFAFA"}),e.jsx("rect",{x:"7",y:"10",width:"6",height:"3",rx:".5",fill:"#FAFAFA"}),e.jsx("circle",{cx:"10",cy:"6",r:"2",fill:"#FF6467"})]})}function Za(){const{pc:t,look:s}=qt(),n=Bt(t),a=s==="offline";return e.jsxs("a",{href:ae({name:"connection",section:"link"}),"data-host":s,"aria-label":d.host.label(t??d.host.unknown,s),className:`inline-flex h-[26px] flex-none items-center gap-1.5 rounded-full border px-2.5 text-small whitespace-nowrap ${a?"border-attention/45 text-attention":"border-input text-muted"}`,children:[s==="loading"?e.jsx("span",{"aria-hidden":"true",className:"inline-block size-2.5 animate-spin rounded-full border-[1.5px] border-current border-r-transparent"}):e.jsx("span",{"aria-hidden":"true",className:`inline-block size-2 flex-none rounded-full ${s==="online"?"bg-ok":a?"bg-attention":"bg-muted"}`}),a?d.host.offline(n):n]})}function Ap({title:t}={}){return e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-1.5 border-b border-line pr-1.5 pl-4",children:[t?e.jsx("h1",{className:"mr-1 text-[20px] font-semibold",children:t}):e.jsxs("span",{className:"mr-1 flex items-center gap-2 text-[17px] font-semibold",children:[e.jsx(Jc,{}),d.brand]}),e.jsx(Za,{}),e.jsx("span",{className:"flex-1"}),e.jsx("a",{href:ae({name:"connection"}),"aria-label":d.nav.settings,title:d.nav.settings,className:"grid size-11 flex-none place-items-center rounded-lg text-muted active:bg-raised",children:e.jsx(F,{name:"gear"})})]})}function ed({badge:t,className:s}){return t?e.jsx("span",{"data-badge":t.tone,className:`absolute h-4 min-w-4 rounded-full px-1 text-center text-[10px] leading-4 font-semibold ${t.tone==="red"?"bg-primary text-primary-fg":"bg-attention text-[#1c1100]"} ${s}`,children:t.text}):null}const Zl={atoi:"inbox",sessions:"sessions",prs:"pr",rigs:"rigs",chat:"ledge",atelier:"atelier"};function td(t){return(s,n)=>a=>{if(!n||t.name==="connection")return;a.preventDefault();const l=document.querySelector("[data-tab-scroll]");l&&l.scrollTop>0?l.scrollTo({top:0,behavior:"smooth"}):$p(t)||Zs(Qc(s))}}function Tp({route:t,active:s,badges:n}){const a=td(t);return e.jsx("nav",{"aria-label":d.nav.label,className:"tabbar bleed grid flex-none grid-cols-5 border-t border-line bg-sidebar",children:Sp.map(l=>e.jsxs("a",{href:qr(l),onClick:a(l,s===l),"aria-current":s===l?"page":void 0,className:"tab group relative flex flex-col items-center justify-center gap-[3px] text-[11px] leading-[13px] text-muted aria-[current=page]:font-medium aria-[current=page]:text-fg",children:[e.jsx("span",{className:"pad grid h-7 w-[52px] place-items-center rounded-full group-aria-[current=page]:bg-raised",children:e.jsx(F,{name:Zl[l]})}),d.nav[l],e.jsx(ed,{badge:n[l]??null,className:"top-[3px] left-1/2 ml-[7px]"})]},l))})}function _p({route:t,active:s,badges:n,atelier:a,ledge:l}){const r=td(t),i=o=>e.jsxs("a",{href:qr(o),onClick:r(o,s===o),"aria-current":s===o?"page":void 0,className:"rb",children:[e.jsx(F,{name:Zl[o]}),d.nav[o],e.jsx(ed,{badge:n[o]??null,className:"top-[3px] right-[7px]"})]},o);return e.jsxs("nav",{"aria-label":d.nav.label,className:"rail",children:[e.jsx("span",{className:"mb-2",children:e.jsx(Jc,{size:30})}),["atoi","sessions","prs","rigs"].map(i),a&&i("atelier"),e.jsx("span",{className:"flex-1"}),e.jsxs("button",{type:"button","aria-pressed":l.open,onClick:l.onToggle,className:"rb",children:[e.jsx(F,{name:Zl.chat}),d.nav.chat]}),e.jsx("span",{"aria-hidden":"true",className:"my-1.5 h-px w-[34px] bg-line"}),e.jsxs("a",{href:ae({name:"connection"}),"aria-current":s==="settings"?"page":void 0,className:"rb",children:[e.jsx(F,{name:"gear"}),d.nav.settings]})]})}function gs({body:t,across:s=!1}={}){const{pc:n,look:a,reach:l,since:r,retry:i}=qt(),[o,c]=Sn(),x=Xc();if(a!=="offline")return null;const u=l==="relay_unreachable",m=u?d.compare.relayTitle:d.offline.title(n),p=u?d.compare.relayBody:r?(t??d.offline.body)(r):d.offline.bodyUnknown,g=y=>e.jsxs("button",{type:"button",disabled:o,onClick:()=>{c(!0),i()},className:Oe({size:"sm",className:y}),children:[e.jsx(F,{name:"refresh",className:"size-4"}),d.offline.retry]}),f=e.jsx(F,{name:u?"cloud":"wifioff",className:"mt-px size-4 flex-none text-attention"});return x!==void 0?!s||!x?null:Fr.createPortal(e.jsxs("section",{role:"status","data-strip":u?"relay":"pc",className:"strip flex items-center gap-[9px] rounded-lg border border-attention/40 px-3 py-2.5 text-[13px] leading-[18px]",children:[f,e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("b",{className:"font-semibold",children:m})," · ",e.jsx("span",{className:"text-muted",children:p})]}),g("flex-none")]}),x):e.jsxs("section",{role:"status","data-strip":u?"relay":"pc",className:"strip flex flex-none items-start gap-[9px] rounded-lg border border-attention/40 px-3 py-2.5 text-[13px] leading-[18px]",children:[f,e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[e.jsx("b",{className:"font-semibold",children:m}),e.jsx("span",{className:"text-muted",children:p}),g("self-start")]})]})}function Ip(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[5px] bg-raised";return e.jsxs("div",{"aria-hidden":"true","data-loading":"","data-list-state":"",className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-line bg-surface p-3",children:[e.jsxs("div",{className:"flex items-center gap-[7px]",children:[e.jsx("span",{className:`${t} h-4 w-[26px]`}),e.jsx("span",{className:`${t} h-3.5 w-20`}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:`${t} h-4 w-[70px]`})]}),e.jsx("span",{className:`${t} h-[34px]`}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("span",{className:`${t} h-11`}),e.jsx("span",{className:`${t} h-11`})]})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-line bg-surface p-3",children:[e.jsxs("div",{className:"flex items-center gap-[7px]",children:[e.jsx("span",{className:`${t} h-4 w-[26px]`}),e.jsx("span",{className:`${t} h-3.5 w-[110px]`})]}),e.jsx("span",{className:`${t} h-3.5 w-[85%]`})]})]})}function Os({title:t,subtitle:s,wideSubtitle:n,actions:a,wideActions:l,children:r,bodyClassName:i="flex flex-col gap-3",offlineBody:o,heading:c=!0,offlinePill:x=!0}){const u=It(),{pc:m,look:p,since:g}=qt(),f=p==="loading",y=f?d.link.connecting(Bt(m)):p==="offline"?g?d.link.lastKnownAt(g):d.inbox.lastKnown:n;return e.jsxs(e.Fragment,{children:[u&&e.jsxs("div",{className:"pane-head flex h-[58px] flex-none items-center gap-2 border-b border-line pr-1.5 pl-4",children:[e.jsx("h1",{className:"flex-none text-lg font-semibold whitespace-nowrap",children:t}),y&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:y}),!f&&(x||p!=="offline")&&e.jsx(Za,{}),l&&e.jsx("span",{className:"ml-auto flex flex-none items-center gap-2",children:l})]}),e.jsxs("main",{"data-tab-scroll":"",className:"tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pt-3.5 pb-[18px]",children:[e.jsx(gs,{body:o,across:!0}),!u&&c&&e.jsxs("div",{className:"flex flex-none items-baseline gap-2",children:[e.jsx("h1",{className:"text-[22px] leading-7 font-semibold tracking-[-.02em]",children:t}),(f||s)&&e.jsx("span",{className:"min-w-0 truncate text-[12.5px] text-muted",children:f?d.link.connecting(Bt(m)):s}),a&&e.jsx("span",{className:"ml-auto flex flex-none items-center gap-2 self-center",children:a})]}),f?e.jsx(Ip,{}):e.jsx("div",{className:`flex-none ${i}`,children:r})]})]})}function Ls(){const[t,s]=h.useState(!1);return h.useEffect(()=>{let n=!0;return Xx().then(a=>{n&&s(a)}),()=>{n=!1}},[]),t}function Ct(){const t=globalThis.navigator;return t?/iPhone|iPad/.test(t.userAgent)||/Macintosh/.test(t.userAgent)&&t.maxTouchPoints>1:!1}const Ms=d.confirm,vl=t=>De({variant:t,block:!0});function Oi({store:t,item:s,enabled:n,reason:a,onConfirm:l,onDeny:r,denyLabel:i}){const[o,c]=h.useState(null),[x,u]=h.useState(null),[m,p]=h.useState(!1),[g,f]=h.useState(a!==void 0),[y,w]=h.useState(0),S=h.useRef(!0),b=h.useRef(n);b.current=n;const j=h.useRef(null);h.useEffect(()=>(S.current=!0,()=>{S.current=!1}),[]),h.useEffect(()=>{var L;if(g||!n)return;const T=(L=t.getState().sessions.get(s.sessionId))==null?void 0:L.pending;if(!(T!=null&&T.key))return;let C=!0,I;c(null);const P={key:T.key,kind:T.kind,text:T.text};return t.prepareConfirm({purpose:"decide",id:s.sessionId,expect:P}).then(R=>{C&&(j.current=P,c(R),I=setTimeout(()=>{C&&(c(null),u("expired"))},R.expiresInMs))},()=>{C&&u("prepareFailed")}),()=>{C=!1,clearTimeout(I)}},[t,s.sessionId,s.key,n,g,y]);const N=g&&a?a==="assertion_expired"?"expired":"failed":x,$=()=>{u(null),f(!1),w(T=>T+1)},A=async()=>{var I,P;if(!n||m||!o)return;if(!o.credentialId){c(null),u("failed");return}p(!0),u(null);const T=await Yn({challenge:o.challenge,rpId:o.rpId,credentialId:o.credentialId}).catch(()=>"failed");if(!S.current)return;p(!1);const C=j.current;if(!C||!b.current||((P=(I=t.getState().sessions.get(s.sessionId))==null?void 0:I.pending)==null?void 0:P.key)!==C.key){c(null),u("changed");return}if(T==="cancelled"){u("cancelled");return}if(T==="failed"){u("failed");return}c(null),l(T,C)===null&&u("failed")},E=N==="expired"||N==="failed"||N==="prepareFailed"||N==="changed",k=m?Ms.asking:o?Ct()?Ms.goApple:Ms.go:Ms.preparing;return e.jsxs("section",{"aria-labelledby":"confirm-title",className:"flex flex-col gap-3 rounded-card border border-line bg-surface p-4",children:[e.jsx("h2",{id:"confirm-title",className:"text-title leading-[1.35] font-semibold",children:Ms.heading}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:Ms.note}),N&&e.jsx(Ve,{title:N==="changed"?d.decide.changed:Ms[N],tone:"warning",role:"alert"}),E?e.jsx("button",{type:"button",disabled:!n,onClick:$,className:vl("primary"),children:Ms.retry}):e.jsx("button",{type:"button",disabled:!n||m||!o,onClick:()=>{A()},className:vl("primary"),children:k}),e.jsx("button",{type:"button",disabled:!n,onClick:r,className:vl(),children:i??d.decide.deny})]})}function Jl(){return e.jsxs("p",{className:"inline-flex min-h-12 flex-1 items-center justify-center gap-2 rounded-control border border-dashed border-line px-4 py-2.5 text-center text-body leading-[1.4] font-medium text-muted",children:[e.jsx(F,{name:"monitor",className:"size-4"}),d.decide.onPc]})}function Rp(t){return t instanceof HTMLElement?t.isContentEditable||t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT":!1}function sd(){return document.querySelector('[role="dialog"][aria-modal="true"]')!==null}function Hr(t,s){const n=h.useRef(s);n.current=s,h.useEffect(()=>{if(!t)return;const a=l=>{l.defaultPrevented||l.repeat||l.altKey||l.ctrlKey||l.metaKey||l.isComposing||Rp(l.target)||sd()||n.current(l.key)&&l.preventDefault()};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[t])}const Li=t=>De({variant:t,className:"flex-1"}),Bs=t=>De({variant:t,block:!0});function Op(t,s){const n=d.decide;switch(s){case"invalid":return t.kind==="question"?n.otherInvalid:n.failed;case"free_text":return n.otherUnsupported;case"untypable":return t.kind==="question"?d.question.untypable:n.failed;case"busy":return n.busy;case"not_taken":return n.notTaken;case"read_only":return n.readOnly;default:return n.failed}}function Lp(t){const{item:s,outcome:n,fresh:a,changed:l,stillPending:r,onReread:i,onDecide:o,answerable:c=!1,choice:x=null,onAnswer:u,answerBlocked:m=!1,onCheck:p,refused:g=!1,store:f,deviceConfirm:y=!1,optionReply:w,multi:S,keys:b=!1,withThread:j=!0}=t,N=d.decide,[$,A]=Sn(),E=Ls(),k=s.risk==="high"||n.kind==="rejected"&&n.reason==="confirm_required",T=a&&!l&&r,C=s.kind!=="question"&&!w&&!S&&!c&&!k,I=C&&ic(s.tool,s.kind,"always"),P=Ql(s),L=I&&e.jsx("p",{className:"text-small text-muted phone-side:text-[12px] phone-side:leading-4",children:d.atoi.scope[P]}),R=n.kind!=="sending"&&n.kind!=="uncertain"&&!((n.kind==="rejected"||n.kind==="failed")&&(n.reason==="no_prompt"||n.reason==="nothing_to_decide"||n.reason==="stale"));Hr(b&&C&&T&&R,D=>{const J=D.toLowerCase();return J==="y"?(o("accept"),!0):J==="n"?(o("deny"),!0):!1});const M=e.jsx("a",{href:t.threadHref??ae({name:"thread",sessionId:s.sessionId}),className:Bs("ghost"),children:d.result.thread(s.botName)}),z=(D,J,Q=!0)=>e.jsxs("footer",{className:"flex flex-none flex-col gap-2.5 border-t border-line bg-bg pt-3 pb-4 phone-side:pb-2",children:[D,Q&&j&&e.jsx("div",{className:"phone-side:hidden",children:M}),J&&e.jsx("p",{className:"text-center text-meta text-muted phone-side:hidden",children:J})]});if(s.kind==="question"&&!c&&!w&&!S)return z(null,N.answerOnPc);const U=y&&E?f:void 0,H=w?w.canConfirm&&U!==void 0:k&&!c&&U!==void 0,V=n.kind==="rejected"&&(n.reason==="assertion_expired"||n.reason==="assertion_invalid"||n.reason==="confirm_required")?n.reason:void 0,ee=D=>w?H?w.picked!==null&&U?e.jsx(Oi,{store:U,item:s,enabled:D,reason:V,onConfirm:w.onReply,onDeny:w.onBack,denyLabel:d.answers.change}):null:e.jsx(Jl,{}):S?e.jsxs("div",{className:"flex flex-col gap-2.5",children:[S.missing>0&&e.jsx("p",{className:"text-center text-small text-muted",children:d.answers.missing(S.missing)}),e.jsx("button",{type:"button",disabled:!D||S.missing>0,onClick:S.onSend,className:Bs("primary"),children:d.answers.send}),e.jsx("button",{type:"button",disabled:!D,onClick:S.onCancel,className:Bs(),children:d.answers.cancel})]}):H&&U?e.jsx(Oi,{store:U,item:s,enabled:D,reason:V,onConfirm:(J,Q)=>U.decide(s.sessionId,"accept",{assertion:J,expect:Q}),onDeny:()=>o("deny")}):c?e.jsx("button",{type:"button",disabled:!D||x===null||m,onClick:()=>u==null?void 0:u(),className:Bs("primary"),children:N.send}):b&&C?e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsx("button",{type:"button",disabled:!D,onClick:()=>o("accept"),className:De({variant:"primary",className:"min-w-[150px]"}),children:N.allow}),e.jsx("button",{type:"button",disabled:!D,onClick:()=>o("deny"),className:De({className:"min-w-[120px]"}),children:N.deny}),I&&e.jsx("button",{type:"button",disabled:!D,onClick:()=>o("always"),className:De({variant:"ghost"}),children:La(P)}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono text-small text-muted",children:d.atoi.keys}),L&&e.jsx("div",{className:"basis-full",children:L})]}):e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsxs("div",{className:"flex flex-col gap-2.5 phone-side:flex-row",children:[e.jsxs("div",{className:"flex gap-2.5 phone-side:flex-[2]",children:[e.jsx("button",{type:"button",disabled:!D,onClick:()=>o("deny"),className:Li(),children:N.deny}),k?e.jsx(Jl,{}):e.jsx("button",{type:"button",disabled:!D,onClick:()=>o("accept"),className:Li("primary"),children:N.allow})]}),I&&e.jsx("button",{type:"button",disabled:!D,onClick:()=>o("always"),className:De({variant:"ghost",block:!0,className:"phone-side:w-auto phone-side:flex-1"}),children:La(P)})]}),L]}),G=a?w?H?N.answerHint:N.onPcHint:S?N.answerHint:k&&!c&&!H?N.onPcHint:c?N.answerHint:N.hint:N.offlineHint,O=D=>z(e.jsxs(e.Fragment,{children:[D,ee(T)]}),G);if(l&&n.kind!=="sending"&&n.kind!=="uncertain")return z(e.jsxs(e.Fragment,{children:[e.jsx(Ve,{title:N.changed,tone:"warning",role:"status"}),ee(!1),e.jsx("button",{type:"button",onClick:i,className:Bs(),children:N.reread})]}));switch(n.kind){case"sending":return z(e.jsx(Ve,{title:N.sending,role:"status",children:e.jsx("p",{children:N.sendingBody})}));case"uncertain":return z(e.jsxs(e.Fragment,{children:[e.jsx(Ve,{title:N.uncertain,tone:"warning",role:"alert",children:e.jsx("p",{children:N.uncertainBody})}),p&&e.jsx("button",{type:"button",disabled:$,onClick:()=>{A(!0),p()},className:Bs("primary"),children:$?N.checking:N.check})]}));case"rejected":case"failed":{const D=n.reason;if(H&&V||D==="confirm_required")return O();if(D==="no_prompt"||D==="nothing_to_decide")return z(e.jsx(Ve,{title:N.noPrompt,tone:"warning",role:"alert"}));if(D==="stale")return z(e.jsxs(e.Fragment,{children:[e.jsx(Ve,{title:N.changed,tone:"warning",role:"alert"}),e.jsx("a",{href:ae({name:"atoi"}),className:Bs(),children:d.result.back})]}),void 0,!1);const J=e.jsx(Ve,{title:Op(s,D),tone:"warning",role:"alert"});return r?O(J):z(J)}default:return O(g?e.jsx(Ve,{title:N.failed,tone:"warning",role:"alert"}):void 0)}}const on=(t,s)=>{var n,a;return(a=(n=t.match(new RegExp(`<${s}>([\\s\\S]*?)</${s}>`)))==null?void 0:n[1])==null?void 0:a.trim()};function zp(t){const s=t.trim();if(!s.startsWith("<task-notification>"))return null;const n=on(s,"status"),a=on(s,"summary")??"",l=a.match(/^Agent "(.+)" (?:was |has )?(?:stopped|killed|completed|finished|failed)/),r=a.match(/^Background command "(.+)" (?:completed|failed|was stopped|was killed)(?: \(exit code (\d+)\))?/);return{...on(s,"task-id")!==void 0&&{id:on(s,"task-id")},...on(s,"output-file")!==void 0&&{output:on(s,"output-file")},status:n==="killed"||n==="completed"||n==="failed"?n:"other",summary:a,about:l?{kind:"agent",name:l[1]}:r?{kind:"command",command:r[1],...r[2]!==void 0&&{code:r[2]}}:null,raw:s}}const ht=d.thread.rig,zi=t=>t?`…${t.slice(-4)}`:"…";function Dp(t){const s=t.indexOf("@");return s>0?{seat:t.slice(0,s),rig:t.slice(s+1)}:{seat:t}}function Sa(t,s,n){const a=s?n.get(s):void 0,{seat:l,rig:r}=Dp(t??"");return a?{name:a.name,...l?{seat:l}:{},session:{id:a.id,tool:a.tool,state:a.state}}:{name:l||(t??""),...r?{seat:r}:{}}}function Fp(t){const s=t.split(`
|
|
4
|
+
`).map(n=>n.trim()).find(n=>n!=="")??"";return`${ht.about(nd(s))} `}const nd=t=>t.length>80?`${t.slice(0,79).trimEnd()}…`:t;function Pp(t,s){const n=t.split(`
|
|
5
|
+
`).slice(1).map(a=>a.trim()).find(a=>a!=="");return n?ht.refusedSaid(Ks(s),nd(n)):ht.refusedSilent(Ks(s))}const Ks=t=>new Date(t).toLocaleTimeString(dt,{hour:"2-digit",minute:"2-digit"});function Bp(t,s,n){if(t.kind!=="received"&&t.kind!=="sent"&&t.kind!=="notice"||!t.rig)return;const a=t.rig,l=a.sentAt??t.at,r=n?{cut:!0}:{},i=(c=ht.raw)=>({label:c,text:a.raw});if(a.kind==="unreadable")return{key:t.id,kind:"rig-unreadable",at:l,text:a.raw||("text"in t?t.text:""),...r};if(t.kind==="received"){const c=Sa(a.from??t.from,t.peer,s);return{key:t.id,kind:"rig-message",at:l,dir:"in",who:c,text:t.text,...a.count?{count:a.count}:{},...c.session?{reply:{sessionId:c.session.id,draft:Fp(t.text)}}:{},raw:i(),...r}}if(t.kind==="sent")return{key:t.id,kind:"rig-message",at:l,dir:"out",who:Sa(a.to??t.to,t.peer,s),text:t.text,delivery:t.status,raw:i(ht.command),...r};if(a.kind==="handoff"){const c=!!t.outgoing,x=Sa(c?a.to:a.from??t.name,t.peer,s),u=c&&t.status==="refused"?{refused:{log:Pp(a.raw,t.at)}}:{},m=!("refused"in u)&&a.qitem?{qitem:a.qitem}:{};return{key:t.id,kind:"rig-task",at:l,outgoing:c,who:x,title:a.summary??t.summary??t.text,raw:i(c?ht.command:ht.raw),...u,...m,...r}}if(a.kind==="unblocked")return{key:t.id,kind:"rig-notice",at:l,tone:"task",title:ht.unblocked(zi(a.qitem)),raw:i(),...r};if(a.kind==="openrig"&&a.alert==="stalled")return{key:t.id,kind:"rig-notice",at:l,tone:"warn",title:ht.stalled(zi(a.qitem),a.minutes??0),raw:i(),...r};const o=t.text.split(`
|
|
6
|
+
`).map(c=>c.trim()).find(c=>c!=="")??"";return{key:t.id,kind:"rig-notice",at:l,tone:"plain",title:o,raw:i(),...r}}const qp=t=>{var s;return t.kind==="received"||t.kind==="sent"||t.kind==="notice"?(s=t.rig)==null?void 0:s.packet:void 0};function Hp(t){const s=new Map;for(const l of t){const r=qp(l);if(!r||!("rig"in l)||!l.rig)continue;const i=s.get(r.id)??{id:r.id,items:[],count:r.count};i.items.push({id:l.id,index:r.index,raw:l.rig.raw,at:l.at}),s.set(r.id,i)}const n=new Set,a=new Map;for(const l of s.values()){if(l.items.length<2)continue;for(const o of l.items)n.add(o.id);const r=l.items.at(-1),i=[...l.items].sort((o,c)=>o.index-c.index).map(o=>o.raw).join(`
|
|
7
|
+
`);a.set(r.id,{key:`packet-${l.id}`,kind:"rig-raw",at:r.at,raw:{label:ht.rawMany(l.count),text:i}})}return{inPacket:n,after:a}}function Up(t){const s=[];let n=[];const a=()=>{n.length===1?s.push(n[0]):n.length>1&&s.push({key:`fold-${n[0].key}`,kind:"rig-fold",at:n[0].at,notices:n}),n=[]};for(const l of t){if(l.kind==="rig-notice"&&l.tone==="plain"){n.push(l);continue}a(),s.push(l)}return a(),s}const Di={pending:"pending","in-progress":"taken","handed-off":"passed",blocked:"blocked",done:"done"};function Wp(t,s){if(!t)return{key:"unknown",text:ht.rowState.unknown};const n=Di[t.state]??"unknown",a=Di[t.state]?n==="passed"?ht.rowState.passed(Sa(t.handedOffTo,void 0,new Map).name):ht.rowState[n]:t.state,l=[s?ht.log.passed(Ks(t.createdAt)):ht.log.handed(Ks(t.createdAt)),t.claimedAt?ht.log.taken(Ks(t.claimedAt)):n==="pending"?ht.log.notTaken:null,n==="done"?ht.log.done(Ks(t.updatedAt)):null].filter(Boolean).join(" · ");return{key:n,text:a,log:l}}const Kp=t=>[...new Set(t.map(s=>s.name))],Vp=(t,s)=>t.length===s.length&&t.every((n,a)=>n===s[a]),ad=(t,s)=>Object.values(s).filter(n=>n.message.type==="session.reply"&&n.message.expect===null&&n.message.id===t).sort((n,a)=>n.at.localeCompare(a.at));function Gp(t,s,n){return Object.values(n).some(a=>a.phase==="applied"&&a.message.type==="session.decide"&&a.message.id===s&&a.message.expect.text===t.text&&a.message.decision===t.decision)}function ld(t,s,n,a){var r,i;const l=d.thread.event;return((r=t.by)==null?void 0:r.kind)==="device"?t.by.id===a?l.fromHere:l.fromDevice(t.by.name):((i=t.by)==null?void 0:i.kind)==="pc"?l.fromPc:Gp(t,s,n)?l.fromHere:l.fromPc}function Xp(t,s,n,a){const l=d.thread.event;if(!t.decision)return null;if(t.decision==="unknown")return l.resolved;const r=ld(t,s,n,a);return t.decision==="deny"?l.deny(r):l.accept(r)}const er=2e4,Qp=(t,s,n)=>{const a=t.trim(),l=s.trim();return a===l||n&&a.length>0&&l.startsWith(a)};function Yp(t,s,n,a=Date.now(),l=[],r=new Map,i=null){var b,j,N,$,A,E;let o=[];const c=new Set(l),x=k=>c.has(k)?{cut:!0}:{},u=ad(s.id,n),m=new Set,p=new Set;for(const k of u){if(k.phase!=="applied")continue;const T=k.message.attachments??[],C=t.find(I=>{var P;return I.kind==="prompt"&&Qp(I.text,k.message.text,c.has(I.id))&&!m.has(I.id)&&Vp(((P=I.images)==null?void 0:P.map(L=>L.id))??[],T)});C&&(m.add(C.id),p.add(k.op))}const g=Hp(t);let f=null,y=null;for(const k of t){const T=Bp(k,r,c.has(k.id));if(T){const P=k.kind==="received"||k.kind==="sent"||k.kind==="notice"?((j=(b=k.rig)==null?void 0:b.packet)==null?void 0:j.id)??null:null,L=Ks(T.at);if(!(P&&P===y)&&L!==f&&o.push({key:`time-${k.id}`,kind:"time",label:L}),f=L,y=P,g.inPacket.has(k.id)){const{raw:R,...M}=T;o.push(M);const z=g.after.get(k.id);z&&o.push(z)}else o.push(T);continue}if(k.kind==="tool"&&!((N=k.images)!=null&&N.length)){const P={id:k.id,name:ji(k.tool),label:k.label,status:k.status},L=o.at(-1);(L==null?void 0:L.kind)==="tools"?L.tools.push(P):o.push({key:`tools-${k.id}`,kind:"tools",at:k.at,tools:[P]}),f=null,y=null;continue}const C=o.length,I=k.kind==="prompt"?zp(k.text):null;if(I)o.push({key:k.id,kind:"task",task:I,at:k.at,...x(k.id)});else if(k.kind==="prompt")o.push({key:k.id,kind:"me",text:k.text,at:k.at,...($=k.images)!=null&&$.length?{images:k.images}:{},...m.has(k.id)?{delivery:"taken"}:{},...x(k.id)});else if(k.kind==="reply")o.push({key:k.id,kind:"agent",text:k.text,at:k.at,...x(k.id)});else if(k.kind==="tool"&&((A=k.images)!=null&&A.length))o.push({key:k.id,kind:"capture",label:Sx(k.tool)?d.thread.capture:ji(k.tool),at:k.at,images:k.images});else if(k.kind==="permission"){const P=Xp(k,s.id,n,i);P&&o.push({key:k.id,kind:"event",label:P,at:k.at})}o.length>C&&(f=null,y=null)}o=Up(o);const w=Math.max(...t.map(k=>Date.parse(k.at)));for(const k of u){const T=Date.parse(k.at),C={key:k.op,kind:"me",text:k.message.text,at:k.at,...(E=k.message.attachments)!=null&&E.length?{attachments:k.message.attachments}:{}};if(k.phase==="sending")o.push({...C,delivery:"sending"});else if(k.phase==="uncertain")o.push({...C,delivery:"uncertain"});else if(k.phase==="applied"&&!p.has(k.op)&&!(w-T>er)){const I=o.findIndex(L=>L.kind!=="awaiting"&&L.kind!=="time"&&!(L.kind==="me"&&L.delivery&&L.delivery!=="taken")&&Date.parse(L.at)>T),P=I<0?o.length:I>0&&o[I-1].kind==="time"?I-1:I;o.splice(P,0,{...C,delivery:"taken",...a-T<er?{fresh:!0}:{}})}}s.exitedAt&&Qx(s,n)&&o.push({key:`closed-${s.exitedAt}`,kind:"event",label:d.sessionEnd.closedHere(Yx(s.exitedAt)),at:s.exitedAt});const S=Wt([s])[0];return S&&o.push({key:`awaiting-${S.key}`,kind:"awaiting",item:S}),o}const Ft=d.thread.composer;function Zp(t,s,n){const a=(l,r,i)=>({enabled:!1,placeholder:l,status:{tone:r,label:i}});if(s==="handshaking")return a(Ft.placeholder.connecting,"muted",Ft.status.connecting);if(s!=="ready")return a(Ft.placeholder.offline,"muted",Ft.status.offline);if(t.state==="exited"||t.state==="error")return a(Ft.placeholder.ended,"muted",Ft.status.ended);if(t.pending||t.state==="waiting_permission"||t.state==="waiting_input"){const l=t.pending?t.pending.kind==="question":t.state==="waiting_input";return a(Ft.placeholder.awaiting,l?"attention":"approval",Ft.status.awaiting)}return t.state!=="idle"?a(Ft.placeholder.working,"info",Ft.status.working):n?a(Ft.placeholder.idle(t.name),"info",Ft.status.sending):{enabled:!0,placeholder:Ft.placeholder.idle(t.name),status:{tone:"ok",label:Ft.status.idle}}}const Jp=["Montre le diff","Lance les tests","Explique les changements"],ef={low:"Bas",medium:"Moyen",high:"Élevé",xhigh:"Très élevé",max:"Max",ultra:"Ultra"},tf={"claude:fable":"Le plus capable","claude:opus":"Très capable, plus lent","claude:sonnet":"Équilibré, au quotidien","claude:haiku":"Rapide et économique"};function sf(t,s,n){var a;if(s===void 0){const l=n.find(r=>r.isDefault);return l?`${d.model.byDefault} · ${l.label}`:d.model.byDefault}return((a=n.find(l=>l.id===s))==null?void 0:a.label)??s}const na=t=>ef[t]??t,rd=(t,s)=>tf[`${t}:${s.id}`]??s.description,nf=(t,s)=>t.model===s.model&&t.effort===s.effort,af=t=>!((t.state==="idle"||t.state==="error")&&!t.pending),Ur=t=>({model:t.model??null,effort:t.effort??null});function Fi(t,s,n){if(t==="cursor")return null;const a=n.model===null?s.find(l=>l.isDefault):s.find(l=>l.id===n.model);return a!=null&&a.efforts&&a.efforts.length>0?a.efforts:null}function lf(t){const s=/^(?:claude-)?(fable|opus|sonnet|haiku)(?:-(\d+)(?:-(\d+))?)?/i.exec(t);return s?[s[1].charAt(0).toUpperCase()+s[1].slice(1).toLowerCase(),s[2]?s[3]?`${s[2]}.${s[3]}`:s[2]:""].filter(Boolean).join(" "):t}const tr=t=>String(t).padStart(2,"0");function Da(t){const s=Math.max(0,Math.round(t/1e3));if(s<60)return`${s} s`;const n=Math.floor(s/60);if(n<60)return`${n} min`;const a=Math.floor(n/60);return a<48?`${a} h ${tr(n%60)}`:`${Math.floor(a/24)} j`}const rf=(t,s)=>t.getFullYear()===s.getFullYear()&&t.getMonth()===s.getMonth()&&t.getDate()===s.getDate(),wl=t=>`${tr(t.getHours())}:${tr(t.getMinutes())}`,Pi=t=>t.toLocaleDateString(dt,{weekday:"short"}),of=168*36e5,id=(t,s)=>new Date(t).getTime()-s>=of;function Wr(t,s,n=!1){const a=new Date(t);if(id(t,s)){const l=a.toLocaleDateString(dt,{day:"numeric",month:"short"});return n?l:`${l} ${wl(a)}`}return rf(a,new Date(s))?wl(a):n?Pi(a):`${Pi(a)} ${wl(a)}`}const cf=t=>t.pct>=100;function aa(t,s){return t>=100?"red":s!==null&&t>=s*100?"amber":""}const df=60*6e4;function la(t,s,n=!0){return t.map(a=>{const l=a.readAt===null||s-Date.parse(a.readAt)>df;return{...a,status:!n&&a.status==="ok"?"stale":a.status,windows:l?[]:a.windows}})}function uf(t,s,n=Date.now()){return la(t,n).flatMap(a=>a.status==="expired"||a.status==="loading"?[]:a.windows.flatMap(l=>{const r=aa(l.pct,s);return r?[{harness:a.harness,window:l,tone:r}]:[]}))}function Ja(t,s,n){const a=Date.parse(t.startedAt),l=t.context?Math.min(1,t.context.used/t.context.window):void 0;return{...t.model?{model:lf(t.model)}:{},...t.effort?{effort:na(t.effort).toLowerCase()}:{},...l!==void 0?{context:{pct:Math.round(l*100),near:l>=n}}:{},...Number.isFinite(a)&&t.state!=="exited"?{duration:Da(s-a)}:{}}}function Bi(t){return t<1e3?String(Math.round(t)):t<1e6?`${Math.round(t/1e3)}k`:`${Number((t/1e6).toFixed(1))}M`}function xf(t,s,n,a,l){const r=s&&la(s,a,l).find(o=>o.harness===t),i=r&&r.status!=="expired"&&r.status!=="loading"?r.windows[0]:void 0;return r&&i?{harness:r.harness,window:i,tone:aa(i.pct,n)}:null}function od(t){const s=h.useRef(null);return async n=>{const a=JSON.stringify(n),l=s.current;let r=l&&l.subject===a&&l.until>Date.now()?l.challenge:null;if(!r){s.current=null;try{r=await t.prepareConfirm(n)}catch{return"prepareFailed"}s.current={subject:a,challenge:r,until:Date.now()+r.expiresInMs-2e3}}if(!r.credentialId)return s.current=null,"failed";const i=await Yn({challenge:r.challenge,rpId:r.rpId,credentialId:r.credentialId}).catch(()=>"failed");return i==="cancelled"?"cancelled":(s.current=null,i)}}function nt({tone:t,title:s,body:n,action:a}){const l=t==="ok"||t==="gone"?"check":t==="denied"?"close":"alert",r=t==="ok"?"text-ok":t==="fail"?"text-destructive":t==="warn"?"text-attention":"text-muted",i=t==="gone"?"border-dashed border-line text-muted":t==="fail"?"border-destructive/40":t==="warn"?"border-attention/45":"border-line";return e.jsxs("div",{role:"status","data-receipt":t,className:`flex min-h-[52px] items-center gap-2.5 rounded-lg border bg-surface px-3 py-2 ${i}`,children:[e.jsx(F,{name:l,className:`size-[18px] ${r}`}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("b",{className:`text-[13.5px] font-semibold [overflow-wrap:anywhere] ${t==="gone"?"text-fg":""}`,children:s}),n&&e.jsx("small",{className:"text-small [overflow-wrap:anywhere] text-muted",children:n})]}),a&&("href"in a?e.jsx("a",{href:a.href,className:Oe({size:"xs",className:"flex-none"}),children:a.label}):e.jsx("button",{type:"button",disabled:a.disabled,onClick:a.onClick,className:Oe({size:"xs",className:"flex-none"}),children:a.label}))]})}function Fa({onGone:t,children:s}){const[n,a]=h.useState(!1),l=h.useRef(t);return l.current=t,h.useEffect(()=>{const r=setTimeout(()=>a(!0),Bc);return()=>clearTimeout(r)},[]),h.useEffect(()=>{if(!n)return;const r=setTimeout(()=>l.current(),200);return()=>clearTimeout(r)},[n]),e.jsx("div",{"data-leaving":n||void 0,className:`grid transition-[grid-template-rows,opacity] duration-200 ${n?"grid-rows-[0fr] opacity-0":"grid-rows-[1fr]"}`,children:e.jsx("div",{className:"min-h-0 overflow-hidden",children:s})})}function sr(t){const s=h.useRef(new Map),[n,a]=h.useState(new Set),l=new Set(t.map(c=>c.id)),r=t.map(c=>({...c,ghost:!1})),i=[...s.current].filter(([c])=>!l.has(c)&&!n.has(c)).sort((c,x)=>c[1].index-x[1].index);for(const[c,x]of i)r.splice(Math.min(x.index,r.length),0,{id:c,value:x.value,ghost:!0});r.forEach((c,x)=>s.current.set(c.id,{value:c.value,index:x}));for(const c of[...s.current.keys()])!l.has(c)&&n.has(c)&&s.current.delete(c);const o=c=>a(x=>x.has(c)?x:new Set(x).add(c));return h.useEffect(()=>{[...n].some(c=>!s.current.has(c)&&!l.has(c))&&a(c=>new Set([...c].filter(x=>s.current.has(x)||l.has(x))))}),{entries:r,dismiss:o,dismissed:n}}const cd=150,mf=t=>t.length>cd||t.split(`
|
|
8
|
+
`).length>3,Gt=()=>e.jsx("svg",{className:"size-4 flex-none motion-safe:animate-spin",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})});function Kr(t){var Re,Le;const{store:s,item:n,mode:a,outcome:l,fresh:r,ghost:i,changed:o,canConfirm:c,enroll:x,onGone:u,selected:m=!1,inThread:p=!1,keys:g=!1}=t,[f,y]=h.useState(null),[w,S]=h.useState(!1),[b,j]=h.useState(a.kind==="question"&&a.options.length===0&&a.other),[N,$]=h.useState(""),[A,E]=h.useState(!1),[k,T]=h.useState(null),C=od(s),I=Ya(),P=p&&I,L=d.atoi.receipt,R=n.botName,M=d.atoi.pill[n.kind],z=ae({name:"request",sessionId:n.sessionId,key:n.key}),U=h.useRef(null),H=g&&a.kind==="permission";if(Hr(H,pe=>{var he;return((he=U.current)==null?void 0:he.call(U,pe))??!1}),U.current=null,l.kind==="applied"){const pe={label:L.thread,href:ae({name:"thread",sessionId:n.sessionId})},he=l.answer!==void 0?e.jsx(nt,{tone:"ok",title:L.answered(l.answer.length>40?`${l.answer.slice(0,40)}…`:l.answer,R)}):l.decision==="deny"?e.jsx(nt,{tone:"denied",title:L.denied(R),body:L.deniedBody,action:pe}):e.jsx(nt,{tone:"ok",title:L.allowed(R),body:L.allowedBody,action:pe});return e.jsx(Fa,{onGone:u,children:he})}if(l.kind==="uncertain")return e.jsx(nt,{tone:"warn",title:d.decide.uncertain,body:L.uncertainBody,...t.onCheck?{action:{label:L.check,onClick:t.onCheck}}:{}});if(l.kind==="handledElsewhere"||i&&l.kind==="idle"){if(!r)return qi(u),null;const pe=(Re=t.session)==null?void 0:Re.lastAnswer,he=pe&&pe.key===n.key,Me=he?pe.by.kind==="pc"?d.thread.event.fromPc:pe.by.id===((Le=s.getState().device)==null?void 0:Le.id)?d.thread.event.fromHere:d.thread.event.fromDevice(pe.by.name):null,ze=N.trim()!=="",at=he?pe.decision?L.decidedAt(R,pe.decision,Fe(pe.at)):L.answeredAt(R,Fe(pe.at),ze):L.gone(R,ze);return e.jsx(Fa,{onGone:u,children:e.jsx(nt,{tone:"gone",title:Me?d.gone.titleOn(Me):d.gone.titleElsewhere,body:at})})}if((w||l.kind==="failed"||l.kind==="rejected"&&!["not_taken","stale","confirm_required","assertion_expired","assertion_invalid","free_text","invalid","untypable","read_only","no_prompt","nothing_to_decide"].includes(l.reason))&&!i){const pe=f;return e.jsx(nt,{tone:"fail",title:d.decide.failed,body:L.what(R,M),action:pe&&r?{label:L.retry,onClick:()=>{S(!1),D(pe)}}:{label:d.inbox.examine,href:z}})}if(i)return qi(u),null;const ee=l.kind==="sending",G=r&&!o&&!ee&&!A,O={key:n.key,kind:n.kind,text:n.text},D=pe=>{y(pe),T(null);const he=pe.kind==="decide"?s.decide(n.sessionId,pe.decision,{expect:O}):s.reply(n.sessionId,pe.text,{expect:O});S(he===null)},J=async()=>{var he,Me;if(!G)return;E(!0),T(null);const pe=await C({purpose:"decide",id:n.sessionId,expect:O});if(E(!1),typeof pe=="string"){T(pe);return}((Me=(he=s.getState().sessions.get(n.sessionId))==null?void 0:he.pending)==null?void 0:Me.key)===n.key&&(y({kind:"decide",decision:"accept"}),S(s.decide(n.sessionId,"accept",{assertion:pe,expect:O})===null))};U.current=H&&G?pe=>{const he=pe.toLowerCase();return he==="y"?(D({kind:"decide",decision:"accept"}),!0):he==="n"?(D({kind:"decide",decision:"deny"}),!0):!1}:null;const Q=pe=>ee&&f!==null&&JSON.stringify(f)===JSON.stringify(pe),Y=Lc(N),ie=()=>{G&&Y.problem===null&&D({kind:"reply",text:Y.text,label:Y.text})},X=l.kind==="rejected"?l.reason==="not_taken"?d.decide.notTaken:l.reason==="free_text"?d.decide.otherUnsupported:l.reason==="invalid"?n.kind==="question"?d.decide.otherInvalid:d.decide.failed:l.reason==="untypable"?d.question.untypable:l.reason==="read_only"?d.decide.readOnly:l.reason==="no_prompt"||l.reason==="nothing_to_decide"?d.decide.noPrompt:l.reason==="assertion_expired"?d.confirm.expired:l.reason==="assertion_invalid"?d.confirm.failed:null:null,le=a.kind==="high",B=le?Oc(n):null,v=n.kind==="permission"?n.body??n.text:vn(n),_=[n.repo,n.branch].filter(Boolean).join(" · "),W=(pe="outline",he="")=>Oe({variant:pe,className:`min-w-0 ${he}`}),se=p?e.jsxs("a",{href:z,className:"-m-1 flex min-w-0 items-center gap-[7px] rounded-md p-1 active:bg-raised",children:[e.jsx(Ie,{state:n.kind==="question"?"ask":n.kind==="permission"?"perm":"work"}),e.jsx("b",{className:"min-w-0 truncate font-semibold",children:n.kind==="permission"?d.atoi.line.permission:M}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono text-small whitespace-nowrap text-muted",children:H?d.atoi.keys:jn(n.since,Date.now())}),le&&e.jsx(as,{tone:"risk",children:d.risk.badge})]}):e.jsxs("a",{href:z,className:"-m-1 flex min-w-0 items-center gap-[7px] rounded-md p-1 active:bg-raised",children:[e.jsx(fs,{tool:n.tool}),e.jsx("b",{className:"font-semibold whitespace-nowrap",children:R}),_&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:_}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono text-small whitespace-nowrap text-muted",children:jn(n.since,Date.now())}),le?e.jsx(as,{tone:"risk",children:d.risk.badge}):e.jsx(as,{tone:n.kind==="question"?"ask":n.kind==="permission"?"perm":"plain",children:M})]}),re=mf(v),K=n.kind==="permission"?e.jsx("a",{href:z,className:"block",children:e.jsx(Fm,{children:re?v.split(`
|
|
9
|
+
`).slice(0,3).join(`
|
|
10
|
+
`).slice(0,cd)+"…":v})}):e.jsx("a",{href:z,className:`block text-body [overflow-wrap:anywhere] ${n.kind==="question"?"":"font-semibold"} ${re?"line-clamp-3":""}`,children:v}),ce=(pe,he=!1)=>e.jsx("p",{className:`text-small [overflow-wrap:anywhere] ${he?"text-destructive":"text-muted"}`,role:he?"alert":void 0,children:pe}),ge=k==="cancelled"?d.confirm.cancelled:k==="prepareFailed"?d.confirm.prepareFailed:k==="failed"?d.confirm.failed:null,Ye=(()=>{switch(a.kind){case"examine":return e.jsxs("a",{href:z,className:Oe({size:"sm",className:"self-start"}),children:[d.inbox.examine,e.jsx(F,{name:"chevron",className:"size-4"})]});case"readOnly":return ce(d.decide.readOnly);case"answerOnPc":return ce(d.decide.answerOnPc);case"permission":return P?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",disabled:!G,onClick:()=>D({kind:"decide",decision:"accept"}),className:W("primary","min-w-[140px]"),children:[Q({kind:"decide",decision:"accept"})&&e.jsx(Gt,{}),d.atoi.allow]}),e.jsxs("button",{type:"button",disabled:!G,onClick:()=>D({kind:"decide",decision:"deny"}),className:W("outline","min-w-[120px]"),children:[Q({kind:"decide",decision:"deny"})&&e.jsx(Gt,{}),d.atoi.deny]}),a.always&&e.jsxs("button",{type:"button",disabled:!G,onClick:()=>D({kind:"decide",decision:"always"}),className:Oe({variant:"ghost"}),children:[Q({kind:"decide",decision:"always"})&&e.jsx(Gt,{}),La(Ql(n))]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",disabled:!G,onClick:()=>D({kind:"decide",decision:"accept"}),className:W("primary"),children:[Q({kind:"decide",decision:"accept"})&&e.jsx(Gt,{}),d.atoi.allow]}),e.jsxs("button",{type:"button",disabled:!G,onClick:()=>D({kind:"decide",decision:"deny"}),className:W(),children:[Q({kind:"decide",decision:"deny"})&&e.jsx(Gt,{}),d.atoi.deny]})]}),a.always&&e.jsxs("button",{type:"button",disabled:!G,onClick:()=>D({kind:"decide",decision:"always"}),className:Oe({variant:"ghost",className:"-mt-1 self-stretch"}),children:[Q({kind:"decide",decision:"always"})&&e.jsx(Gt,{}),La(Ql(n))]})]});case"high":return c?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",disabled:!G,onClick:()=>{J()},className:W("primary"),children:[A||Q({kind:"decide",decision:"accept"})?e.jsx(Gt,{}):e.jsx(F,{name:"face",className:"size-[18px]"}),e.jsx("span",{className:"truncate",children:A?d.confirm.checking:Ct()?d.confirm.goApple:d.confirm.go})]}),e.jsxs("button",{type:"button",disabled:!G,onClick:()=>D({kind:"decide",decision:"deny"}),className:W(),children:[Q({kind:"decide",decision:"deny"})&&e.jsx(Gt,{}),d.atoi.deny]})]}),A&&ce(d.confirm.askingNote)]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",disabled:!0,className:W(),children:d.decide.onPc}),e.jsxs("button",{type:"button",disabled:!G,onClick:()=>D({kind:"decide",decision:"deny"}),className:W(),children:[Q({kind:"decide",decision:"deny"})&&e.jsx(Gt,{}),d.atoi.deny]})]}),ce(d.decide.onPcHint),x&&e.jsx("a",{href:ae({name:"connection",section:"link"}),className:"self-start text-small font-medium underline underline-offset-2",children:d.enroll.link})]});case"question":{const pe=`free-${n.sessionId}`,he=Y.problem!==null&&Y.problem!=="empty";return e.jsxs(e.Fragment,{children:[a.options.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:a.options.map((Me,ze)=>{const at={kind:"reply",text:String(ze+1),label:Me};return e.jsxs("button",{type:"button",disabled:!G,onClick:()=>D(at),className:Oe({className:"h-auto min-h-11 max-w-full py-2 text-left whitespace-normal [overflow-wrap:anywhere]"}),children:[Q(at)&&e.jsx(Gt,{}),Me]},`${ze}:${Me}`)})}),a.other&&!b&&a.options.length>0&&e.jsx("button",{type:"button",disabled:!G,onClick:()=>j(!0),className:"self-start text-[13px] font-medium text-muted underline-offset-2 hover:underline disabled:opacity-45",children:d.atoi.other}),a.other&&b&&e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:`flex items-center gap-2 rounded-[10px] border bg-surface py-[5px] pr-[5px] pl-3 focus-within:border-ring ${he?"border-destructive":"border-input"}`,children:[e.jsx("label",{htmlFor:pe,className:"sr-only",children:d.question.fieldLabel(R)}),e.jsx("input",{id:pe,value:N,onChange:Me=>$(Me.target.value),placeholder:d.question.placeholder,autoComplete:"off",enterKeyHint:"send","aria-invalid":he,disabled:!r||o,onKeyDown:Me=>{Me.key==="Enter"&&!Me.nativeEvent.isComposing&&(Me.preventDefault(),ie())},className:"h-[34px] min-w-0 flex-1 bg-transparent text-base text-fg outline-none placeholder:text-muted"}),e.jsx("button",{type:"button","aria-label":d.decide.send,title:d.decide.send,disabled:!G||Y.problem!==null,onClick:ie,className:"grid size-9 flex-none place-items-center rounded-lg bg-primary text-primary-fg disabled:opacity-40",children:(f==null?void 0:f.kind)==="reply"&&ee&&f.text===Y.text?e.jsx(Gt,{}):e.jsx(F,{name:"send",className:"size-[18px]"})})]}),he?ce(Y.problem==="long"?d.question.long(Or):Y.problem==="digit"?d.question.digit:d.question.untypable,!0):ce(d.atoi.sendHint(R))]}),!a.other&&a.options.length>0&&ce(d.decide.otherUnsupported)]})}}})(),pt=le?d.atoi.kindName.permission:d.atoi.kindName[n.kind];return e.jsxs(Tc,{tone:n.kind==="question"?"ask":n.kind==="permission"?"perm":"plain",selected:m,label:d.atoi.region(pt,R,n.repo),children:[se,X&&ce(X,!0),o&&e.jsxs("div",{role:"status",className:"flex items-start gap-2 rounded-md border border-attention/45 px-2.5 py-2 text-small",children:[e.jsx(F,{name:"alert",className:"mt-px size-4 text-attention"}),d.decide.changed]}),K,re&&e.jsx("a",{href:z,className:"-mt-1 self-start text-[13px] font-medium underline-offset-2 hover:underline",children:d.atoi.readAll}),B&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-destructive/10 px-2.5 py-2 text-small",children:[e.jsx(F,{name:"alert",className:"mt-px size-4 text-destructive"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("b",{className:"font-semibold",children:B.title}),e.jsx("span",{className:"text-muted",children:B.body})]})]}),o&&e.jsx("button",{type:"button",onClick:t.onReread,className:Oe(),children:d.decide.reread}),ge&&ce(ge,!0),Ye,ee&&ce(d.decide.sending)]})}function qi(t){queueMicrotask(t)}const pf=t=>Oe({variant:t?"primary":"outline",className:"h-auto min-h-11 w-full justify-start gap-2 px-3 py-2.5 text-left leading-[19px] whitespace-normal [overflow-wrap:anywhere]"}),Hi=t=>new Date(t).toLocaleTimeString(dt,{hour:"2-digit",minute:"2-digit"});function dd({store:t,ask:s,end:n,fresh:a,ghost:l,canConfirm:r,enroll:i,onGone:o,full:c=!1,selected:x=!1}){const u=d.asks,m=d.atoi.receipt,p=od(t),g=Dc(s),f=Fc(s),[y,w]=h.useState(!1),[S,b]=h.useState(""),[j,N]=h.useState(null),[$,A]=h.useState(null),[E,k]=h.useState(!1),[T,C]=h.useState(null),I=ae({name:"ask",id:s.id}),P=async(v,_)=>{N(v),A(null),C({key:v,answer:_});let W;if(_.kind!=="seen"){const re=await p({purpose:"rig",qitem:s.id,answer:_});if(typeof re=="string"){N(null),A(re);return}W=re}const se=t.answerAsk(s.id,_,W?{assertion:W}:{});if(N(null),se===null){A("notSent");return}(_.kind==="words"||_.kind==="resolve")&&w(!1)},L=m.what(f.name,u.pill[g]);if(n.kind==="sent"){const v=Vm(s,n.answer),_=n.answer.kind==="seen"?e.jsx(nt,{tone:"ok",title:m.seen,body:m.what(f.name,s.summary)}):e.jsx(nt,{tone:"ok",title:m.sentTo(f.name),body:[f.role,v?`« ${v.length>60?`${v.slice(0,60)}…`:v} »`:""].filter(Boolean).join(" · ")});return e.jsx(Fa,{onGone:o,children:_})}if(n.kind==="already"||l&&n.kind!=="failed"&&n.kind!=="uncertain")return!a&&l&&n.kind!=="already"?(queueMicrotask(o),null):e.jsx(Fa,{onGone:o,children:e.jsx(nt,{tone:"gone",title:u.already,body:m.what(f.name,s.summary)})});const R=v=>{P((T==null?void 0:T.key)??"retry",v)};if(n.kind==="uncertain")return e.jsx(nt,{tone:"warn",title:d.decide.uncertain,body:u.uncertain,action:{label:u.retry,onClick:()=>{t.resendAsk(s.id)||R(n.answer)},disabled:!a||j!==null}});if(n.kind==="failed"){const v=n.error==="openrig_stopped"?u.stopped:n.error==="unreachable"?u.unreachable:n.message??n.error;return e.jsx(nt,{tone:"fail",title:u.notSent(v),body:L,action:{label:u.retry,onClick:()=>R(n.answer),disabled:!a||j!==null}})}const M=n.kind==="sending"||j!==null,z=a&&!M,U=g!=="update",H=z&&(r||!U),V=v=>j===v||n.kind==="sending"&&(T==null?void 0:T.key)===v?e.jsx(Gt,{}):null,ee=s.questions.length>1,G=s.questions.filter(v=>_i(s,v.id)!==null||n.kind==="recorded"&&n.answer.kind==="choice"&&n.answer.questionId===v.id).length,O=s.bodyTruncated&&s.body===s.summary?"":s.body,D=s.priority==="routine"?null:u.priority[s.priority],J=(v,_=!1)=>e.jsx("p",{className:`text-small [overflow-wrap:anywhere] ${_?"text-destructive":"text-muted"}`,role:_?"alert":void 0,children:v}),Q=Ct(),Y=U?Q?u.sendCheck:u.sendDevice:u.send,ie=v=>{var se;const _=_i(s,v.id)??(n.kind==="recorded"&&n.answer.kind==="choice"&&n.answer.questionId===v.id?((se=v.options.find(re=>re.id===n.answer.optionId))==null?void 0:se.label)??null:null);if(_!==null)return e.jsxs("span",{className:"flex items-center gap-1.5 text-body",children:[e.jsx(F,{name:"check",className:"size-4 text-ok"}),_]});const W=[...v.options].sort((re,K)=>Number(K.recommended)-Number(re.recommended));return e.jsx("div",{className:"flex flex-col gap-2",children:W.map(re=>{const K=`${v.id}:${re.id}`;return e.jsxs("button",{type:"button",disabled:!H||y,onClick:()=>{P(K,{kind:"choice",questionId:v.id,optionId:re.id})},className:pf(re.recommended),children:[V(K),e.jsx("span",{className:"min-w-0",children:re.label}),re.recommended&&e.jsx("span",{className:"ml-auto pl-2 text-xs whitespace-nowrap opacity-85",children:u.recommended})]},re.id)})})},X=e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"sr-only",htmlFor:`ask-${s.id}`,children:s.kind==="parked"?u.placeholderParked(f.name):u.placeholder}),e.jsx("textarea",{id:`ask-${s.id}`,rows:2,value:S,onChange:v=>b(v.target.value),disabled:M,placeholder:s.kind==="parked"?u.placeholderParked(f.name):u.placeholder,className:"max-h-[140px] min-h-11 w-full resize-y rounded-[10px] border border-input bg-surface px-3 py-2.5 text-base leading-[22px] text-fg outline-none placeholder:text-muted focus:border-ring"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",disabled:!H||!S.trim(),onClick:()=>{P("words",s.kind==="parked"?{kind:"resolve",text:S.trim()}:{kind:"words",text:S.trim()})},className:Oe({variant:"primary",className:"min-w-0"}),children:[V("words")??(U?e.jsx(F,{name:"face",className:"size-[18px]"}):null),e.jsx("span",{className:"truncate",children:Y})]}),e.jsx("button",{type:"button",disabled:M,onClick:()=>w(!1),className:Oe({className:"min-w-0"}),children:u.cancel})]}),ee&&G<s.questions.length&&J(u.settlesAll)]}),le=$==="cancelled"?d.confirm.cancelled:$==="prepareFailed"?d.confirm.prepareFailed:$==="failed"?d.confirm.failed:$==="notSent"?d.decide.failed:n.kind==="refused"?n.reason==="assertion_expired"?d.confirm.expired:n.reason==="unavailable"?u.notSent(u.unreachable):d.confirm.failed:null,B=!U||s.questions.length===0&&!y&&g!=="parked"&&g!=="question"?null:r?j!==null&&j!=="seen"?J(d.confirm.asking):e.jsxs("p",{className:"flex items-center gap-1.5 text-small text-muted",children:[e.jsx(F,{name:"face",className:"size-4"}),Q?u.confirmHint:u.confirmHintDevice]}):e.jsxs(e.Fragment,{children:[J(u.needsDevice),i&&e.jsx("a",{href:ae({name:"connection",section:"link"}),className:"self-start text-small font-medium underline underline-offset-2",children:d.enroll.link})]});return e.jsxs(Tc,{tone:g==="update"?"plain":"rig",selected:x,label:d.atoi.region(d.atoi.kindName.rig,f.name,s.from.rig??""),children:[e.jsxs("a",{href:I,className:"-m-1 flex min-w-0 items-center gap-[7px] rounded-md p-1 active:bg-raised",children:[e.jsx("b",{className:"font-semibold whitespace-nowrap",children:f.name}),s.from.rig&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:s.from.rig}),e.jsx("span",{className:"flex-1"}),D&&e.jsx(as,{tone:"urgent",children:D}),e.jsx(as,{tone:g==="parked"?"rig":"plain",children:u.pill[g]}),e.jsx("time",{dateTime:s.updatedAt,className:"font-mono text-small whitespace-nowrap text-muted",children:Hi(s.updatedAt)})]}),e.jsx("a",{href:I,className:"block text-body font-semibold [overflow-wrap:anywhere]",children:s.summary}),O&&!y&&(c?e.jsx("p",{className:"text-body whitespace-pre-wrap [overflow-wrap:anywhere] text-muted",children:O}):e.jsx("a",{href:I,className:"line-clamp-3 text-body [overflow-wrap:anywhere] text-muted",children:O})),!c&&!y&&(s.bodyTruncated||O.length>180||O.split(`
|
|
11
|
+
`).length>3)&&e.jsx("a",{href:I,className:"-mt-1 self-start text-[13px] font-medium underline-offset-2 hover:underline",children:u.readAll}),c&&(s.evidenceRef||s.detail)&&e.jsxs("dl",{className:"grid grid-cols-[74px_minmax(0,1fr)] gap-x-3 gap-y-2 text-small",children:[e.jsx("dt",{className:"text-muted",children:d.detail.asked}),e.jsx("dd",{className:"m-0",children:Hi(s.createdAt)}),s.evidenceRef&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-muted",children:u.source}),e.jsx("dd",{className:"m-0 font-mono [overflow-wrap:anywhere]",children:s.evidenceRef})]})]}),c&&s.detail&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-expanded":E,onClick:()=>k(v=>!v),className:"self-start text-[13px] font-medium",children:[E?"⌄":"›"," ",u.details]}),E&&e.jsx("p",{className:"text-small whitespace-pre-wrap [overflow-wrap:anywhere] text-muted",children:s.detail})]}),g==="update"?e.jsx("div",{className:"flex",children:e.jsxs("button",{type:"button",disabled:!z,onClick:()=>{P("seen",{kind:"seen"})},className:Oe({size:"sm"}),children:[V("seen"),u.seen]})}):y&&!ee?X:s.questions.length===0?y?X:e.jsx("button",{type:"button",disabled:!H,onClick:()=>w(!0),className:Oe({className:"self-start"}),children:s.kind==="parked"?u.answerParked:u.writeAnswer}):ee?e.jsxs(e.Fragment,{children:[s.questions.map((v,_)=>e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("span",{className:"text-small text-muted [overflow-wrap:anywhere]",children:[_+1,". ",v.question]}),ie(v)]},v.id)),e.jsx("span",{className:"text-small text-muted",children:u.progress(G,s.questions.length)}),y?X:e.jsx("button",{type:"button",disabled:!H,onClick:()=>w(!0),className:"self-start text-[13px] font-medium text-muted underline-offset-2 hover:underline disabled:opacity-45",children:u.answerOther})]}):e.jsxs(e.Fragment,{children:[ie(s.questions[0]),e.jsx("button",{type:"button",disabled:!H,onClick:()=>w(!0),className:"self-start text-[13px] font-medium text-muted underline-offset-2 hover:underline disabled:opacity-45",children:u.answerOther})]}),le&&J(le,!0),!le&&B]})}const Pe=d.compare,Ui=t=>{const s=t.replace(/\D/g,"");return[s.slice(0,3),s.slice(3)]},$a="\0",Sl=t=>{const[s="",n=""]=t.split($a);return[s,n]};function ws({login:t}){return t?e.jsxs("div",{className:"flex h-8 items-center gap-2 self-center rounded-full border border-line pr-3 pl-1 text-body text-muted",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex size-6 items-center justify-center rounded-full bg-raised text-meta font-semibold text-fg",children:t.slice(0,1).toUpperCase()}),d.account(t)]}):null}function ff({step:t,login:s,pcName:n,lost:a,stalled:l=!1,reach:r="pc_online",onRetry:i,onSame:o,onCancel:c,onRestart:x,onDone:u,actions:m}){var $,A;const[p,g]=h.useState(!1),f=n??d.yourPc,y=()=>{g(!1),x()},w=e.jsx("button",{type:"button",onClick:y,className:ot,children:Pe.retry}),S=a&&(t==null?void 0:t.step)!=="linked"?e.jsx(Ve,{title:Pe.lostTitle,role:"status",children:e.jsx("p",{children:Pe.lostBody})}):null;if((t==null?void 0:t.step)==="linked")return e.jsxs(vt,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(hs,{size:88}),e.jsx("h1",{className:Pt,children:Pe.doneTitle(t.pc.name??n??d.yourPc,Er((($=globalThis.navigator)==null?void 0:$.userAgent)??"",((A=globalThis.navigator)==null?void 0:A.maxTouchPoints)??0).replace(/ tablette$/,""))}),e.jsx("p",{className:"max-w-[300px] text-muted",children:Pe.doneBody})]}),e.jsx(wt,{}),m??e.jsx("a",{href:ae({name:"atoi"}),onClick:u,className:gt,children:Pe.seePending})]});if((t==null?void 0:t.step)==="cancelled"&&p)return e.jsxs(vt,{children:[e.jsx(ws,{login:s}),e.jsxs("section",{role:"alert",className:"rounded-control border border-danger-fg/15 bg-danger-bg p-4 text-danger-fg",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2.5",children:[e.jsx(F,{name:"warning",stroke:1.5}),e.jsx("strong",{children:Pe.cancelledTitle})]}),e.jsx("p",{className:"text-body leading-[1.6]",children:Pe.cancelledBody})]}),e.jsx(wt,{}),w]});const b=(t==null?void 0:t.step)==="cancelled"?[Pe.cancelledTitle,null]:!t&&l?[Pe.stalledTitle,Pe.stalledBody]:(t==null?void 0:t.step)==="expired"?[Pe.expiredTitle,Pe.expiredBody]:(t==null?void 0:t.step)==="refused"?[Pe.refusedTitle,Pe.refusedBody]:null;if(b)return e.jsxs(vt,{children:[e.jsx(ws,{login:s}),e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:Pt,children:b[0]}),b[1]&&e.jsx("p",{className:"text-muted",children:b[1]})]}),S,e.jsx(wt,{}),w]});if((t==null?void 0:t.step)==="compare"&&t.phoneConfirmed)return e.jsxs(vt,{top:"pt-40",children:[e.jsx(ws,{login:s}),e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(Hn,{}),e.jsx("h1",{className:Pt,children:Pe.waitTitle}),e.jsxs("p",{className:"max-w-[300px] text-muted",children:[Sl(Pe.waitBody(f,$a))[0],e.jsx("span",{className:"font-mono text-fg",children:Ui(t.code).join(" ")}),Sl(Pe.waitBody(f,$a))[1]]})]}),e.jsx(wt,{}),e.jsx("button",{type:"button",onClick:c,className:ot,children:Pe.cancel})]});if((t==null?void 0:t.step)==="compare"){const[E,k]=Ui(t.code),[T,C]=Sl(Pe.intro($a));return e.jsxs(vt,{children:[e.jsx(ws,{login:s}),e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:Pt,children:Pe.title}),e.jsxs("p",{className:"text-muted",children:[T,e.jsx("strong",{className:"font-semibold text-fg",children:f}),C]})]}),e.jsxs("div",{className:"flex flex-col items-center gap-3 rounded-control border border-line bg-surface px-4 py-6",children:[e.jsxs("div",{"aria-label":Pe.codeLabel(`${E} ${k}`),className:"flex justify-center gap-3.5 font-mono text-[2.5rem] leading-[48px] font-semibold tracking-[.06em]",children:[e.jsx("span",{children:E}),e.jsx("span",{children:k})]}),e.jsx("span",{className:"text-small text-muted",children:Pe.basis})]}),S,e.jsx(wt,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:o,className:gt,children:Pe.same}),e.jsx("button",{type:"button",onClick:()=>{g(!0),c()},className:ot,children:Pe.different})]})]})}const j=t&&e.jsx("button",{type:"button",onClick:c,className:ot,children:Pe.cancel}),N=r==="pc_offline"?[Pe.offlineTitle,Pe.offlineBody(f)]:r==="relay_unreachable"?[Pe.relayTitle,Pe.relayBody]:null;return N?e.jsxs(vt,{top:"pt-40",children:[e.jsx(ws,{login:s}),e.jsxs("div",{role:"status",className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:Pt,children:N[0]}),e.jsx("p",{className:"text-muted",children:N[1]})]}),S,e.jsx(wt,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:i,className:gt,children:Pe.retryNow}),j]})]}):e.jsxs(vt,{top:"pt-40",children:[e.jsx(ws,{login:s}),e.jsxs("div",{role:"status",className:"flex flex-col items-center gap-3.5 text-center text-muted",children:[e.jsx(Hn,{}),e.jsx("p",{children:Pe.waitCode})]}),S,e.jsx(wt,{}),j]})}const xt=d.recover,we=d.recover.no;function Qs(){var s,n;const t=Er(((s=globalThis.navigator)==null?void 0:s.userAgent)??"",((n=globalThis.navigator)==null?void 0:n.maxTouchPoints)??0);return t==="iPhone"||t==="iPad"?t:null}const hf=["key","shield","laptop"];function gf({login:t,platform:s,onPasskey:n,onCode:a}){const l=Qs();return e.jsxs(vt,{children:[e.jsx(ws,{login:t}),e.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[e.jsx(hs,{size:72}),e.jsx("h1",{className:Pt,children:xt.title(l)}),e.jsx("p",{className:"max-w-[320px] text-muted",children:xt.lead})]}),s&&e.jsx("ul",{className:"flex flex-col gap-3 text-body leading-5 text-fg/85",children:xt.notes(Qs()).map((r,i)=>e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx(F,{name:hf[i],className:"size-5 text-muted"}),r]},i))}),e.jsx(wt,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[s&&e.jsxs("button",{type:"button",onClick:n,className:gt,children:[e.jsx(F,{name:"face"}),xt.go]}),e.jsx("button",{type:"button",onClick:a,className:s?ot:gt,children:xt.code})]})]})}const bf={warn:"bg-attention/12 text-attention",bad:"bg-danger-bg text-danger-fg"};function jf({icon:t,tone:s}){return e.jsx("span",{"aria-hidden":"true",className:`inline-flex size-12 flex-none items-center justify-center rounded-full ${bf[s]}`,children:e.jsx(F,{name:t,className:"size-6"})})}function os({login:t,icon:s,tone:n,title:a,body:l,centred:r=!1,children:i,actions:o}){return e.jsxs(vt,{children:[e.jsx(ws,{login:t}),e.jsxs("div",{role:"alert",className:`flex flex-col gap-3 ${r?"items-center text-center":"items-start"}`,children:[e.jsx(jf,{icon:s,tone:n}),e.jsx("h1",{className:Pt,children:a}),e.jsx("p",{className:"text-muted",children:l})]}),i&&e.jsx("div",{className:"flex flex-col gap-2.5 text-body leading-[1.5] text-muted",children:i}),e.jsx(wt,{}),e.jsx("div",{className:"flex flex-col gap-3",children:o})]})}const cn=({lead:t,children:s})=>e.jsxs("p",{children:[t&&e.jsx("strong",{className:"font-semibold text-fg",children:t}),t&&" ",s]}),yf=t=>{if(!t)return null;const s=new Date(t);return Number.isNaN(s.getTime())?null:s.toLocaleDateString(dt,{day:"numeric",month:"short"})};function Nf({state:t,login:s,reach:n,onRetry:a,onCode:l,onCancel:r,onSignOut:i,onDone:o,actions:c}){const x=Qs(),u=(g=!0)=>e.jsx("button",{type:"button",onClick:l,className:g?gt:ot,children:xt.code},"code"),m=(g=!1)=>e.jsx("button",{type:"button",onClick:a,className:g?gt:ot,children:xt.retry},"retry");if(t.step==="reaching"||t.step==="faceid"||t.step==="checking"){const g=(t.step==="reaching"?null:t.pcName)??d.yourPc,f=[[t.step==="reaching"?xt.checking.reaching(g):xt.checking.reached(g),t.step==="reaching"?"on":"done"],[Ct()?xt.checking.faceId:xt.checking.check,t.step==="faceid"?"on":t.step==="checking"?"done":"next"],[xt.checking.verifying(g),t.step==="checking"?"on":"next"]];return e.jsxs(vt,{top:"pt-40",children:[e.jsx(ws,{login:s}),e.jsxs("div",{role:"status",className:"flex flex-col items-center gap-3 text-center",children:[e.jsx(Hn,{}),e.jsx("h1",{className:Pt,children:xt.checking.title}),e.jsx("p",{className:"max-w-[320px] text-muted",children:xt.checking.body(g)})]}),e.jsx("ol",{className:"flex flex-col gap-2.5 rounded-[10px] border border-line px-4 py-3.5 text-body",children:f.map(([y,w])=>e.jsxs("li",{className:`flex items-center gap-2.5 ${w==="on"?"font-medium text-fg":"text-muted"}`,children:[w==="done"?e.jsx(F,{name:"check",className:"size-[18px] text-ok"}):w==="on"?e.jsx(Hn,{size:"size-[18px]"}):e.jsx("span",{className:"size-[18px]","aria-hidden":"true"}),y]},y))}),e.jsx(wt,{}),e.jsx("button",{type:"button",onClick:r,className:ot,children:xt.cancel})]})}if(t.step==="done"){const g=t.pc.name??d.yourPc;return e.jsxs(vt,{top:"pt-14",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[e.jsx(hs,{size:88}),e.jsx("h1",{className:Pt,children:xt.done.title(x,g)}),e.jsx("p",{className:"max-w-[320px] text-muted",children:xt.done.body(g)})]}),e.jsxs("p",{role:"status",className:"flex items-center gap-2 self-center text-small text-ok",children:[e.jsx(F,{name:"check",className:"size-4"}),xt.done.told(g)]}),e.jsx(wt,{}),c??e.jsx("a",{href:ae({name:"atoi"}),onClick:o,className:gt,children:d.compare.seePending})]})}if(t.step==="cancelled")return null;const p=t.pcName??d.yourPc;switch(t.why){case"none":return e.jsx(os,{login:s,icon:"key",tone:"warn",title:we.none.title,body:we.none.body(p),actions:[m(!0),u(!1)],children:e.jsx(cn,{lead:we.none.hintTitle,children:we.none.hint})});case"revoked":return e.jsx(os,{login:s,icon:"unlink",tone:"bad",title:we.revoked.title(x),body:we.revoked.body(p,yf(t.revokedAt)),actions:[u()],children:e.jsx("p",{children:we.revoked.hint})});case"old":return e.jsx(os,{login:s,icon:"key",tone:"warn",title:we.old.title,body:we.old.body,actions:[u()],children:e.jsx(cn,{lead:we.old.hintTitle,children:we.old.hint(x)})});case"offline":{const[g,f]=n==="relay_unreachable"?[d.compare.relayTitle,d.compare.relayBody]:[we.offline.title(p),we.offline.body(p)];return e.jsx(os,{login:s,icon:"wifioff",tone:"warn",centred:!0,title:g,body:f,actions:[m(!0),e.jsx("button",{type:"button",onClick:r,className:ot,children:xt.cancel},"cancel")]})}case"otherPc":{const[g,f]=t.tags??["",""];return e.jsxs(os,{login:s,icon:"shield",tone:"bad",title:we.otherPc.title(p),body:we.otherPc.body,actions:[u(),e.jsx("button",{type:"button",onClick:i,className:ot,children:we.otherPc.signOut},"out")],children:[e.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-4 gap-y-2.5 rounded-control border border-line bg-surface p-4 text-body text-fg",children:[e.jsx("dt",{className:"text-muted",children:we.otherPc.inPasskey}),e.jsxs("dd",{className:"font-mono",children:[g," · ",we.otherPc.expected]}),e.jsx("dt",{className:"text-muted",children:we.otherPc.received}),e.jsxs("dd",{className:"font-mono text-danger-fg",children:[f," · ",we.otherPc.unknown]})]}),e.jsx(cn,{lead:we.otherPc.reinstalledTitle,children:we.otherPc.reinstalledBody}),e.jsx(cn,{lead:we.otherPc.otherwise,children:we.otherPc.warning})]})}case"connected":return e.jsxs(os,{login:s,icon:t.device==="iPhone"?"phone":"tablet",tone:"warn",title:we.connected.title(t.device),body:we.connected.body(p),actions:[u(),m()],children:[e.jsx(cn,{lead:we.connected.otherTitle(t.device),children:we.connected.other}),e.jsx(cn,{lead:we.connected.reinstalledTitle(t.device),children:we.connected.reinstalled(t.device)})]});case"rate":{const g=t.retryInMs!==void 0?Math.max(1,Math.ceil(t.retryInMs/6e4)):null;return e.jsx(os,{login:s,icon:"clock",tone:"warn",title:we.rate.title,body:we.rate.body(p,g),actions:[u(),...g!==null?[e.jsx("button",{type:"button",disabled:!0,className:ot,children:we.rate.retryIn(g)},"wait")]:[]]})}case"blocked":return e.jsx(os,{login:s,icon:"lock",tone:"bad",title:we.blocked.title(p),body:we.blocked.body(p),actions:[u()],children:e.jsxs("p",{children:[we.blocked.hintBefore(p),e.jsx("strong",{className:"font-semibold text-fg",children:we.blocked.unblock}),we.blocked.hintAfter]})});case"timeout":return e.jsx(os,{login:s,icon:"clock",tone:"warn",centred:!0,title:we.timeout.title(p),body:we.timeout.body,actions:[m(!0),u(!1)]});case"unsaved":return e.jsx(os,{login:s,icon:x==="iPad"?"tablet":"phone",tone:"warn",centred:!0,title:we.unsaved.title,body:we.unsaved.body(p,x),actions:[m(!0),u(!1)]})}}const Ss=d.enroll;function el(t,s="protect"){var E,k,T,C;const n=fe(t),a=Ls(),l=(E=n.device)==null?void 0:E.confirm,r=a&&(s==="protect"?l===!1:l===!0&&!((k=n.device)!=null&&k.recover)),[i,o]=h.useState(null),[c,x]=h.useState(null),[u,m]=h.useState(!1),[p,g]=h.useState(null),[f,y]=h.useState(0),w=p?(T=n.ops[p])==null?void 0:T.phase:void 0,S=(s==="protect"?l===!0:((C=n.device)==null?void 0:C.recover)===!0)||w==="applied",b=w==="sending"||w==="uncertain",j=w==="rejected"||w==="failed";h.useEffect(()=>{if(!r||S)return;let I=!0;o(null);const P=t.pcKey();return Promise.all([t.prepareConfirm({purpose:"register"}),P?Zx(P):Promise.reject(new Error("unpaired"))]).then(([L,R])=>{I&&o({challenge:L,userId:R})},()=>{I&&x("prepareFailed")}),()=>{I=!1}},[t,r,S,f]);const N=()=>{var R,M;if(!i||u||b)return;const{challenge:I,userId:P}=i;m(!0),x(null);const L=Er(((R=globalThis.navigator)==null?void 0:R.userAgent)??"",((M=globalThis.navigator)==null?void 0:M.maxTouchPoints)??0);Jx({challenge:I.challenge,rpId:I.rpId},{label:L,id:P}).then(z=>{if(m(!1),z==="cancelled"){x("cancelled");return}if(z==="unsupported"){x("unsupported");return}o(null);const U=t.registerCredential(z,em(P));U===null?x("failed"):g(U)},()=>{m(!1),x("failed")})},$=()=>{x(null),g(null),y(I=>I+1)},A=c??(j?"failed":null);return{offered:r,registered:S,challenge:(i==null?void 0:i.challenge)??null,asking:u||b,problem:A,go:N,retry:$}}function ud({e:t,className:s,label:n=Ss.go}){const a=t.problem==="failed"||t.problem==="prepareFailed",l=t.problem==="cancelled"?d.confirm.cancelled:t.problem==="unsupported"?Ss.unsupported:t.problem==="failed"?d.confirm.failed:t.problem==="prepareFailed"?d.confirm.prepareFailed:null;return e.jsxs(e.Fragment,{children:[l&&e.jsx(Ve,{title:l,tone:"warning",role:"alert"}),a?e.jsx("button",{type:"button",onClick:t.retry,className:s,children:d.confirm.retry}):t.problem==="unsupported"?null:e.jsx("button",{type:"button",disabled:!t.challenge||t.asking,onClick:t.go,className:s,children:t.challenge||t.asking?n:d.confirm.preparing})]})}function kf({store:t}){const s=el(t);return s.registered?e.jsx(Wi,{children:Ss.done}):s.offered?e.jsx(Wi,{children:e.jsx("div",{className:"flex flex-col items-end gap-2",children:e.jsx(ud,{e:s,className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 text-body font-medium disabled:opacity-45"})})}):null}function Wi({children:t}){return e.jsxs("div",{className:"flex items-baseline justify-between gap-4 border-b border-line px-4 py-3 last:border-b-0",children:[e.jsx("dt",{className:"flex-none text-muted",children:Ss.row}),e.jsx("dd",{className:"min-w-0 text-right break-words",children:t})]})}function vf({store:t,onDone:s,update:n=!1}){const a=el(t),[l,r]=h.useState(!1);h.useEffect(()=>{a.offered&&r(!0)},[a.offered]);const i=ae({name:"atoi"});return l?a.registered?e.jsxs(e.Fragment,{children:[e.jsx(Ve,{title:Ss.done,role:"status"}),e.jsx("a",{href:i,onClick:s,className:gt,children:d.compare.seePending})]}):e.jsxs(e.Fragment,{children:[e.jsxs("section",{"aria-labelledby":"protect-title",className:"flex flex-col gap-3 rounded-control border border-line bg-surface p-4",children:[e.jsx("h2",{id:"protect-title",className:"text-title leading-[1.35] font-semibold",children:n?d.passkeyUpdate.title:Ss.title}),e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:n?d.passkeyUpdate.stepBody(Qs()):Ss.body}),e.jsx(ud,{e:a,className:gt,label:n?d.passkeyUpdate.go:Ss.go})]}),e.jsx("a",{href:i,onClick:s,className:ot,children:Ss.later})]}):e.jsx("a",{href:i,onClick:s,className:gt,children:d.compare.seePending})}const mt=d.passkeyUpdate,xd="ledge.mobile.passkeyUpdateLater",wf=(t,s)=>{try{return!!s&&(t==null?void 0:t.getItem(xd))===s}catch{return!1}};function Sf({store:t,storage:s=globalThis.localStorage}){var m;const n=el(t,"update"),a=(m=fe(t).device)==null?void 0:m.id,[l,r]=h.useState(()=>wf(s,a)),[i,o]=h.useState(!1);if(h.useEffect(()=>{n.offered&&!l&&o(!0)},[n.offered,l]),!i)return null;if(n.registered)return e.jsxs("div",{role:"status",className:"flex items-start gap-3 rounded-card border border-line bg-surface p-4",children:[e.jsx(F,{name:"check",className:"size-5 text-ok"}),e.jsxs("span",{className:"flex flex-col gap-0.5",children:[e.jsx("strong",{className:"text-body font-semibold",children:mt.done}),e.jsx("small",{className:"text-small text-muted",children:mt.doneBody(Qs())})]})]});if(l)return null;const c=()=>{try{a&&(s==null||s.setItem(xd,a))}catch{}r(!0),o(!1)},x=n.problem==="failed"||n.problem==="prepareFailed"||n.problem==="unsupported",u=n.problem==="cancelled"?mt.cancelled:x?mt.failed(t.pcName()??d.yourPc):null;return e.jsxs("section",{"aria-labelledby":"passkey-update-title",className:"flex flex-col gap-3 rounded-card border border-info/30 bg-info/[0.06] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex size-9 items-center justify-center rounded-full bg-raised text-muted",children:e.jsx(F,{name:"key",className:"size-[18px]"})}),e.jsx("h2",{id:"passkey-update-title",className:"text-title leading-[1.35] font-semibold",children:mt.title})]}),u?e.jsx(Ve,{title:u,tone:n.problem==="cancelled"?"warning":"danger",role:"alert"}):e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:Ct()?mt.body(Qs()):mt.bodyOther(Qs())}),e.jsxs("div",{className:u?"grid grid-cols-2 gap-2":"flex flex-col gap-2",children:[u?e.jsx("button",{type:"button",onClick:x?n.retry:n.go,disabled:!x&&!n.challenge,className:gt,children:mt.retry}):e.jsx("button",{type:"button",onClick:n.go,disabled:!n.challenge||n.asking,className:gt,children:n.asking?e.jsxs(e.Fragment,{children:[e.jsx(Hn,{size:"size-4"}),mt.updating]}):n.challenge?mt.go:d.confirm.preparing}),e.jsx("button",{type:"button",onClick:c,disabled:n.asking,className:ot,children:mt.later})]})]})}const Ki=t=>t.problem==="failed"||t.problem==="prepareFailed";function $f({store:t}){const s=el(t,"update"),n=fe(t).device;return n!=null&&n.confirm?s.registered?e.jsxs("div",{className:"flex items-baseline justify-between gap-4 border-b border-line px-4 py-3 last:border-b-0",children:[e.jsx("dt",{className:"flex-none text-muted",children:mt.row}),e.jsx("dd",{className:"text-right text-ok",children:mt.ready})]}):s.offered?e.jsxs("div",{className:"flex flex-col gap-2 border-b border-line px-4 py-3 last:border-b-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("dt",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{children:mt.row}),e.jsx("span",{className:"text-small text-muted",children:mt.rowHint})]}),e.jsx("dd",{className:"flex-none",children:e.jsx("button",{type:"button",disabled:s.asking||!Ki(s)&&!s.challenge,onClick:Ki(s)?s.retry:s.go,className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 text-body font-medium disabled:opacity-45",children:s.asking?mt.updating:mt.update})})]}),s.problem&&e.jsx(Ve,{title:s.problem==="cancelled"?mt.cancelled:mt.failed(t.pcName()??d.yourPc),tone:"warning",role:"alert"})]}):null:null}const tn={ok:"idle",run:"work",fail:"perm",wait:"ask",skip:"plain",none:"off"},Wn=t=>t.state!=="merged"&&t.state!=="closed",md=t=>(t.state==="open"||t.state==="review")&&t.mergeable&&(t.pipeline==="ok"||t.pipeline==="none");function Cf(t){return{open:t.filter(Wn),closed:t.filter(s=>!Wn(s))}}const Mf=t=>t.filter(s=>Wn(s)&&s.pipeline==="fail").length;function Ef(t){const s=t.filter(Wn);return[...s.filter(n=>n.pipeline==="fail").map(n=>({pr:n,why:"fail"})),...s.filter(n=>n.pipeline!=="fail"&&md(n)).map(n=>({pr:n,why:"ready"}))]}const Af=t=>t.filter(s=>s.status!=="ok"),pd=t=>t==="github"?"gh":"glab",Tf=t=>`${pd(t.forge)} auth login --hostname ${t.host}`;function fd(t){const s=new Map;for(const n of t){const a=s.get(n.column)??{column:n.column,name:n.columnName,jobs:[]};a.jobs.push(n),s.set(n.column,a)}return[...s.values()].sort((n,a)=>n.column-a.column)}const hd=t=>t.find(s=>s.status==="fail")??null;function gd(t){if(t===void 0)return null;const s=Math.round(t);return s<3600?{text:`${Math.floor(s/60)}:${String(s%60).padStart(2,"0")}`,hours:!1}:{text:`${Math.floor(s/3600)}:${String(Math.floor(s%3600/60)).padStart(2,"0")}`,hours:!0}}const _f=t=>t.startsWith("…"),If=new Set(["draft","not_open","approvals","changes_requested","pipeline","pipeline_not_started"]);function tl(t){const{pr:s}=t,n=new Set(t.mergeBlockers),a=Math.max(1,s.approvals.required??0),l=[];n.has("draft")&&l.push({ok:!1,key:"draft"}),n.has("not_open")&&l.push({ok:!1,key:"not_open"}),n.has("approvals")&&l.push({ok:!1,key:"approvals",given:s.approvals.given,required:a}),n.has("changes_requested")&&l.push({ok:!1,key:"changes_requested",who:t.reviewers.filter(r=>r.state==="changes").map(r=>r.name).join(", ")}),n.has("pipeline_not_started")?l.push({ok:!1,key:"pipeline_not_started"}):n.has("pipeline")||s.pipeline!=="ok"&&s.pipeline!=="none"?l.push({ok:!1,key:s.pipeline==="run"?"pipeline_run":s.pipeline==="wait"?"pipeline_wait":s.pipeline==="skip"?"pipeline_skip":"pipeline_fail"}):l.push({ok:!0,key:s.pipeline==="none"?"noCi":"pipeline"});for(const r of n)If.has(r)||l.push({ok:!1,key:"raw",code:r});return n.has("approvals")||l.push({ok:!0,key:"approved",given:s.approvals.given,required:a}),n.has("changes_requested")||l.push({ok:!0,key:"noChanges"}),l}const Rf=t=>(t.pr.state==="open"||t.pr.state==="review")&&tl(t).every(s=>s.ok),bd=t=>`${t.approvals.given}${t.approvals.required!==void 0?`/${t.approvals.required}`:""}`,nr=(t,s)=>{const n=t.replace(/\.$/,"");return s.key==="changes_requested"||s.key==="raw"?n:n.charAt(0).toLowerCase()+n.slice(1)},Of=t=>t.pipeline==="fail"&&(t.state==="open"||t.state==="review"),Lf=t=>t.files.reduce((s,n)=>({added:s.added+n.added,removed:s.removed+n.removed}),{added:0,removed:0}),zf=(t,s)=>t.threads.filter(n=>n.file===s).length,Vr=t=>t.slice(0,7);function Df(t,s){if(!t)return null;const n=t.prs.find(r=>Wn(r)&&r.sessions.includes(s));if(n)return{pr:n};const a=t.followed.find(r=>r.session===s);if(!a)return null;const l=t.forges.find(r=>r.forge===a.forge&&r.host===a.host);return l&&l.status!=="ok"?{unknown:l,kind:a.forge}:null}const Vi=new Set(["starting","launching","booting"]);function ms(t){return Vi.has(t.status)||Vi.has(t.lifecycleState)?"starting":t.status==="partial"?"partial":t.status==="running"||t.running>0?t.nodes.some(n=>n.stopped)?"partial":"running":"stopped"}const Ff=t=>t!=="stopped",jd=t=>t.rigs.find(s=>s.name===zn),Gi={running:0,partial:0,starting:0,stopped:1},ar=t=>t.rigs.filter(s=>s.name!==zn).map((s,n)=>({r:s,i:n})).sort((s,n)=>Gi[ms(s.r)]-Gi[ms(n.r)]||s.i-n.i).map(s=>s.r),yd=(t,s,n)=>{var a;for(const l of t)if(((a=l.rig)==null?void 0:a.name)===s&&l.rig.role===n&&l.state!=="exited")return l};function Nd(t,s,n){var r;let a=0,l=0;for(const i of s)((r=i.rig)==null?void 0:r.name)!==t||!i.pending||(i.pending.kind==="question"?l+=1:a+=1);for(const i of n??[])i.from.rig===t&&i.kind!=="update"&&(l+=1);return{perm:a,ask:l}}const ra=t=>t.activity==="running"||t.work>0;function kd(t,s){if(s.perm)return"perm";if(s.ask)return"ask";const n=ms(t);return n==="stopped"?"off":n==="starting"||t.nodes.some(ra)?"work":"idle"}function Gr(t){const{session:s,node:n,graph:a}=t;return t.rigStatus==="stopped"?"off":s?s.pending&&s.pending.kind!=="question"||s.state==="waiting_permission"||s.state==="error"?"perm":s.pending||s.state==="waiting_input"?"ask":s.state==="starting"?"starting":s.state==="working"?"work":"idle":n!=null&&n.stopped||(a==null?void 0:a.status)==="exited"||(a==null?void 0:a.status)==="stopped"?t.rigStatus==="starting"?"waiting":"off":t.rigStatus==="starting"&&!n?"waiting":n&&ra(n)?"work":a!=null&&a.attention||n!=null&&n.attention?"ask":"idle"}const vd={perm:"perm",ask:"ask",work:"work",idle:"idle",off:"off",starting:"work",waiting:"off"},Xr=t=>t==="claude-code"||t==="claude"?"claude":t==="codex"?"codex":t==="cursor"?"cursor":t==="omp"?"omp":null,bs=(t,s)=>(s==null?void 0:s.split("@")[0])||t.replace(".","-");function Pf(t,s){const n=s.map(a=>({...a,seats:t.filter(l=>l.pod===a.id)}));for(const a of t)n.some(l=>l.id===a.pod)||n.push({id:a.pod,label:a.pod,seats:t.filter(l=>l.pod===a.pod)});return n.filter(a=>a.seats.length)}function Bf(t,s){const n=s.filter(i=>/delegat/.test(i.kind)),a=new Set(n.map(i=>i.from)),l=new Set(n.map(i=>i.to)),r=t.filter(i=>a.has(i.logicalId)&&!l.has(i.logicalId));return r.length===1?r[0].logicalId:null}const qf=["auto","standard","open","yolo","locked","spec"],wd=/^builtin:(auto|standard|open|yolo|locked)$/;function Hf(t){var s;switch(t.policySource){case"member_policy":return((s=wd.exec(t.policy??""))==null?void 0:s[1])??null;case"rig_policy":case"team_default":case"kernel_default":case"floor":return"spec";default:return null}}function Sd(t){if(t.length===0)return null;const s=t.map(Hf),n=s[0];return n&&s.every(a=>a===n)?n:"mixed"}const Uf=t=>{var s;return((s=wd.exec(t??""))==null?void 0:s[1])??null},$d=t=>[...$x(t.nodes)].map(([s,n])=>({role:s,count:n.length,ids:n}));function Wf(t,s){return s!=null&&s.some(n=>n.id===t.id)?"mine":t.state==="in-progress"?"progress":t.state==="blocked"?"blocked":"pending"}const Kf=t=>t==="done"?"done":t==="handed-off"?"handed":"stopped";function Vf(t){const s=t.trim(),n=/^handed[ _-]?off(?: to)? (.+)$/i.exec(s);if(n)return{verb:"handed",to:n[1].split("@")[0]};const a=/^blocked(?: on)? (.+)$/i.exec(s);if(a)return{verb:"blocked",on:a[1]};const l=s.toLowerCase();return l==="claimed"?{verb:"claimed"}:l==="completed"||l==="done"?{verb:"completed"}:l==="canceled"||l==="cancelled"?{verb:"canceled"}:l==="resumed"||l==="unblocked"?{verb:"resumed"}:l==="failed"?{verb:"failed"}:{verb:"other",text:s}}function Pa(t){const s=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(:\d{2})?$/.test(t)?`${t.replace(" ","T")}Z`:t,n=new Date(s);return Number.isNaN(n.getTime())?null:n}function Qr(t,s){const n=a=>new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime();return Math.round((n(s)-n(t))/864e5)}const Cd=t=>t.startsWith("operator."),Md=t=>Cd(t.logicalId)?"Max":bs(t.logicalId,t.session),Ed={running:"on",starting:"go",partial:"part",stopped:"plain"},Gf=t=>t.daemon.state==="stopped"||t.daemon.state==="stale";function Xf(t){return t.rig?t.rig:t.seat?t.seat.split("@")[1]??null:null}function Qf(t){return t.kind==="seats"?t.rig??null:t.kind==="act"&&t.action?Xf(t.action):null}const Ad=t=>[...t].sort((s,n)=>{var a,l;return(((a=Pa(n.createdAt))==null?void 0:a.getTime())??0)-(((l=Pa(s.createdAt))==null?void 0:l.getTime())??0)});function Yf(t,s){const n=[];for(const a of s){if(a.from!==t&&a.to!==t)continue;const l=a.from===t?a.to:a.from;/delegat/.test(a.kind)?n.push({kind:a.to===t?"delegatesTo":"delegates",who:l}):/collaborat/.test(a.kind)?n.some(r=>r.kind==="collaborates"&&r.who===l)||n.push({kind:"collaborates",who:l}):/escalat/.test(a.kind)&&a.from===t?n.push({kind:"escalates",who:l}):n.push({kind:"linked",who:l,label:a.kind})}return n}const Zf=t=>t.nodes.filter(s=>!s.stopped&&ra(s)).map(s=>bs(s.logicalId,s.session)),Jf='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function Td(t,s){const n=h.useRef(s);n.current=s,h.useEffect(()=>{const a=t.current;if(!a)return;const l=document.activeElement instanceof HTMLElement?document.activeElement:null;a.focus({preventScroll:!0});const r=i=>{if(i.key==="Escape"){i.preventDefault(),n.current();return}if(i.key!=="Tab")return;const o=[...a.querySelectorAll(Jf)],c=o[0],x=o.at(-1);if(!c||!x){i.preventDefault();return}i.shiftKey&&(document.activeElement===c||document.activeElement===a)?(i.preventDefault(),x.focus()):!i.shiftKey&&document.activeElement===x&&(i.preventDefault(),c.focus())};return document.addEventListener("keydown",r),()=>{document.removeEventListener("keydown",r),l!=null&&l.isConnected&&l.focus({preventScroll:!0})}},[t])}function ct({labelledBy:t,onClose:s,children:n}){const a=h.useRef(null);return Td(a,s),Fr.createPortal(e.jsxs("div",{className:"fixed inset-0 z-20",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50","aria-hidden":"true",onClick:s}),e.jsxs("section",{ref:a,role:"dialog","aria-modal":"true","aria-labelledby":t,tabIndex:-1,className:"absolute inset-x-0 bottom-0 mx-auto flex max-w-[480px] flex-col gap-4 rounded-t-[28px] border-t border-line bg-surface px-5 pt-3 pb-[calc(34px+env(safe-area-inset-bottom))] shadow-[var(--shadow-overlay)] outline-none tablet:inset-x-auto tablet:bottom-auto tablet:top-1/2 tablet:left-1/2 tablet:max-h-[calc(100dvh-48px)] tablet:w-[480px] tablet:-translate-x-1/2 tablet:-translate-y-1/2 tablet:overflow-y-auto tablet:rounded-[24px] tablet:border tablet:px-6 tablet:pt-6 tablet:pb-6",children:[e.jsx("span",{className:"h-[5px] w-9 self-center rounded-full bg-muted/40 tablet:hidden","aria-hidden":"true"}),n]})]}),document.body)}function sl({on:t,label:s,disabled:n,onChange:a,describedBy:l}){return e.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-label":s,disabled:n,"aria-describedby":l,onClick:()=>a(!t),className:`relative h-6 w-10 flex-none rounded-full border border-line transition-colors disabled:opacity-45 ${t?"border-transparent bg-ok":"bg-raised"}`,children:e.jsx("span",{className:`absolute top-0.5 h-4.5 w-4.5 rounded-full bg-white shadow-sm transition-all ${t?"left-[18px]":"left-0.5"}`,"aria-hidden":"true"})})}const eh={on:"border-ok/40 text-ok",go:"border-info/40 text-info",part:"border-attention/45 text-attention",bad:"border-approval/45 text-approval",plain:"border-input text-muted"};function Nn({tone:t,children:s,flat:n=!1}){return e.jsxs("span",{"data-chip":t,className:`inline-flex h-[22px] flex-none items-center gap-1.5 rounded-full border px-[9px] text-[12px] font-medium whitespace-nowrap ${eh[t]}`,children:[!n&&e.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-current"}),s]})}function Kn({perm:t=!1,ok:s=!1,children:n}){const a=t?"bg-approval/12 text-approval":s?"bg-ok/12 text-ok":"bg-attention/12 text-attention";return e.jsx("span",{"data-att":t?"perm":s?"ok":"ask",className:`inline-flex h-[22px] items-center rounded-md px-2 text-[12px] whitespace-nowrap ${a}`,children:n})}function zt({children:t,aside:s,id:n}){return e.jsxs("h2",{id:n,className:"flex flex-none items-center gap-2 text-[11px] font-medium tracking-[.4px] text-muted uppercase",children:[e.jsx("span",{children:t}),s!==void 0&&e.jsx("span",{className:"ml-auto text-[12px] font-normal tracking-normal normal-case",children:s})]})}function Ke({tone:t,label:s,children:n,className:a=""}){return e.jsx("section",{"aria-label":s,className:`flex-none overflow-hidden rounded-[10px] border bg-surface dark:bg-transparent ${t==="rigs"?"border-task/45":"border-line"} ${a}`,children:n})}function lr({lead:t,name:s,chip:n,sub:a,att:l,href:r,dim:i=!1,selected:o=!1,label:c}){const x=e.jsxs(e.Fragment,{children:[t,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-[3px]",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("b",{className:`truncate text-[14.5px] font-semibold ${i?"text-muted":""}`,children:s}),n]}),a&&e.jsx("small",{className:"text-[12px] text-muted",children:a}),l&&e.jsx("span",{className:"flex flex-wrap gap-1.5",children:l})]}),r&&e.jsx(F,{name:"chevron",className:"size-4 text-muted"})]}),u=`flex min-h-[60px] items-center gap-2.5 border-b border-line px-3 py-2 last:border-b-0 ${o?"bg-secondary":""}`;return r?e.jsx("a",{href:r,"aria-label":c,"aria-current":o?"page":void 0,className:u,children:x}):e.jsx("div",{className:u,children:x})}function $l({label:t,value:s,onOpen:n}){const a=e.jsxs(e.Fragment,{children:[e.jsx("small",{className:"text-[11.5px] text-muted",children:t}),e.jsx("b",{className:"truncate text-[17px] font-semibold",children:s})]}),l="relative flex min-w-0 flex-col gap-px rounded-[10px] border border-line bg-surface px-2.5 py-2 text-left";return n?e.jsxs("button",{type:"button",onClick:n,className:l,children:[a,e.jsx("span",{"aria-hidden":"true",className:"absolute top-[7px] right-[9px] text-muted",children:"›"})]}):e.jsx("div",{className:l,children:a})}function Kt({lead:t,warn:s=!1,danger:n=!1,children:a,action:l,role:r,compact:i=!1}){return e.jsxs("div",{role:r,className:`strip flex flex-none gap-[9px] rounded-lg border text-[13px] leading-[18px] ${i?"items-center px-2.5 py-2":"items-start px-3 py-2.5"} ${n?"border-approval/45":s?"border-attention/40":"border-line"}`,children:[t,e.jsx("div",{className:`flex min-w-0 flex-1 flex-col ${i?"":"gap-2"}`,children:a}),l]})}function ve({mark:t,title:s,sub:n,children:a,onClose:l,closeLabel:r}){const i={ok:"✓",bad:"✕",warn:"!",ask:"?"}[t],o={ok:"text-ok",bad:"text-approval",warn:"text-attention",ask:"text-attention"}[t];return e.jsxs("div",{role:t==="ok"?"status":"alert","data-receipt":t,className:`flex min-h-12 items-center gap-2.5 rounded-lg border bg-surface px-3 py-2 text-[13px] leading-[18px] ${t==="bad"?"border-destructive/45":"border-line"}`,children:[e.jsx("span",{"aria-hidden":"true",className:o,children:i}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("b",{className:"font-semibold",children:s}),n!==void 0&&e.jsx("small",{className:"block text-[12px] text-muted [overflow-wrap:anywhere]",children:n}),a]}),l&&r&&e.jsx("button",{type:"button",onClick:l,"aria-label":r,title:r,className:"grid size-9 flex-none place-items-center rounded-lg text-muted active:bg-raised",children:e.jsx(F,{name:"close",className:"size-4"})})]})}function Vs({commands:t}){return t.length?e.jsx("code",{className:"mt-1.5 block rounded-md bg-raised px-2 py-1.5 font-mono text-[12px] break-all whitespace-pre-wrap text-muted",children:t.join(`
|
|
12
|
+
`)}):null}function Yr({title:t,body:s}){return e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-destructive/40 bg-danger-bg/70 px-2.5 py-[9px] text-[13px] leading-[18px]",children:[e.jsx(F,{name:"warning",className:"mt-px size-4 text-approval"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("b",{className:"block font-semibold",children:t}),s!==void 0&&e.jsx("span",{className:"text-muted",children:s})]})]})}const Cn=({className:t="text-info"})=>e.jsx("span",{"aria-hidden":"true",className:`inline-block size-[13px] flex-none animate-spin rounded-full border-[1.6px] border-current border-r-transparent ${t}`});function Vn({children:t,bar:s=!1}){return e.jsxs("div",{role:"status",className:`flex flex-none items-center gap-2.5 px-3 py-2.5 text-[12.5px] text-muted ${s?"bleed border-t border-line bg-sidebar":"rounded-lg border border-line"}`,children:[e.jsx(Cn,{}),e.jsx("span",{className:"min-w-0 flex-1",children:t})]})}function Ca({label:t,options:s,value:n,onChange:a,disabled:l=!1}){return e.jsx("div",{role:"group","aria-label":t,className:"inline-flex flex-none self-start overflow-hidden rounded-lg border border-input",children:s.map(r=>e.jsx("button",{type:"button",disabled:l,"aria-pressed":r.value===n,onClick:()=>a(r.value),className:"h-9 px-3.5 text-[13px] font-medium text-muted aria-pressed:bg-raised aria-pressed:text-fg disabled:opacity-45",children:r.label},r.value))})}function rr({pressed:t,title:s,sub:n,onClick:a,disabled:l=!1}){return e.jsxs("button",{type:"button","aria-pressed":t,disabled:l,onClick:a,className:"flex flex-col gap-0.5 rounded-lg border border-input px-[11px] py-[9px] text-left text-[13.5px] font-medium aria-pressed:border-ring aria-pressed:bg-secondary aria-pressed:shadow-[inset_0_0_0_1px_var(--color-ring)] disabled:opacity-45",children:[e.jsx("span",{children:s}),n&&e.jsx("small",{className:"text-[11.5px] font-normal text-muted",children:n})]})}function Xi({on:t,label:s,onChange:n,disabled:a=!1}){return e.jsxs("label",{className:`flex min-h-12 items-center gap-3 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0 ${a?"opacity-45":""}`,children:[e.jsx("input",{type:"checkbox",checked:t,disabled:a,onChange:l=>n(l.target.checked),className:"peer sr-only"}),e.jsx("span",{"aria-hidden":"true",className:`grid size-[18px] flex-none place-items-center rounded-[5px] border-[1.5px] text-[12px] peer-focus-visible:outline-2 peer-focus-visible:outline-info ${t?"border-primary bg-primary text-primary-fg":"border-input"}`,children:t?"✓":""}),e.jsx("span",{className:"min-w-0 flex-1",children:s})]})}function Qi({on:t,label:s,hint:n,onChange:a,disabled:l=!1}){const r=h.useId();return e.jsxs("div",{className:"flex min-h-12 items-center gap-3 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{children:s}),n&&e.jsx("small",{id:r,className:"text-[12px] text-muted",children:n})]}),e.jsx(sl,{on:t,label:s,onChange:a,...l?{disabled:l}:{},...n?{describedBy:r}:{}})]})}function th({value:t,changed:s,min:n=0,max:a=9,fewer:l,more:r,onChange:i,disabled:o=!1}){const c="h-9 w-10 text-[17px] text-fg disabled:opacity-35";return e.jsxs("span",{className:`inline-flex flex-none items-center overflow-hidden rounded-lg border ${s?"border-ring":"border-input"}`,children:[e.jsx("button",{type:"button","aria-label":l,title:l,disabled:o||t<=n,onClick:()=>i(t-1),className:c,children:"−"}),e.jsx("span",{"aria-live":"polite",className:"min-w-[30px] text-center font-mono text-[14px]",children:t}),e.jsx("button",{type:"button","aria-label":r,title:r,disabled:o||t>=a,onClick:()=>i(t+1),className:c,children:"+"})]})}function rs({title:t,onClose:s,children:n,busy:a=!1}){const l=h.useId();return e.jsxs(ct,{labelledBy:l,onClose:()=>{a||s()},children:[e.jsx("h2",{id:l,className:"text-[17px] leading-6 font-semibold",children:t}),n]})}function je({tone:t="outline",size:s="md",className:n=""}={}){const a=Oe({variant:t==="primary"?"primary":"outline",size:s,className:n});return t==="danger"?`${a} !border-approval/50 !text-approval`:t==="dangerfill"?`${a} !border-transparent !bg-destructive !text-primary-fg dark:!bg-primary`:a}function Lt({icon:t,children:s,size:n="size-4"}){return e.jsxs(e.Fragment,{children:[e.jsx(F,{name:t,className:n}),s]})}function Rs({children:t,retry:s,retryLabel:n}){return e.jsxs("div",{role:s?"alert":void 0,className:"flex items-center gap-2.5 px-3 py-2.5 text-[13px] text-muted",children:[s&&e.jsx(F,{name:"warning",className:"size-4 flex-none text-attention"}),e.jsx("span",{className:"min-w-0 flex-1",children:t}),s&&n&&e.jsx("button",{type:"button",onClick:s,className:je({size:"xs"}),children:n})]})}function sh(t,s=500){const n=h.useRef(null),a=h.useRef(!1),l=()=>{n.current&&clearTimeout(n.current),n.current=null};return t?{onPointerDown:r=>{r.pointerType!=="mouse"&&(a.current=!1,l(),n.current=setTimeout(()=>{a.current=!0,t()},s))},onPointerUp:l,onPointerLeave:l,onPointerCancel:l,onContextMenu:r=>{r.preventDefault();const i=!!n.current;l(),a.current||t(),i&&(a.current=!0)},swallow:()=>{const r=a.current;return a.current=!1,r}}:{}}const Ut=d.prs,nh={ok:"on",run:"go",fail:"bad",wait:"part",skip:"plain",none:"plain"};function _d({pipeline:t,short:s=!1}){return e.jsx(Nn,{tone:nh[t],flat:t==="none",children:s?Ut.pipe[t]:Ut.pipeline[t]})}const nl=t=>t.split("/").at(-1)??t,Zt=t=>({host:Ut.host[t.forge],cli:pd(t.forge),kind:Ut.kind[t.forge]}),Id=(t,s)=>t.sessions.map(n=>s.get(n)).filter(n=>!!n);function ah(t,s=new Date){const n=new Date(t),a=Qr(n,s);return a<=0?Fe(t):a===1?Ut.yesterday:a<7?n.toLocaleDateString(dt,{weekday:"long"}):n.toLocaleDateString(dt,{day:"numeric",month:"short"})}function ir(t,s=new Date){const n=new Date(t),a=Fe(t),l=Qr(n,s);return l<=0?Ut.today(a):l===1?Ut.yesterdayAt(a):`${n.toLocaleDateString(dt,l<7?{weekday:"long"}:{day:"numeric",month:"short"})} ${a}`}function Fn(t,s){if(t.ok)return t.key==="approved"?Ut.ok.approved(t.given,t.required):Ut.ok[t.key];switch(t.key){case"draft":return Ut.blocker.draft(s);case"approvals":return Ut.blocker.approvals(t.given,t.required);case"changes_requested":return Ut.blocker.changes_requested(t.who);case"raw":return t.code;default:return Ut.blocker[t.key]}}function Yi({pr:t,sub:s,chips:n,href:a,dim:l=!1,selected:r=!1}){const i=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mt-1.5 self-start",children:e.jsx(Ie,{state:l?"done":tn[t.pipeline],pulse:!l&&t.pipeline==="run"})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-[3px]",children:[e.jsxs("span",{className:`truncate text-[14px] ${l?"text-muted":""}`,children:[e.jsx("b",{className:"mr-1 font-mono text-[13px] font-semibold",children:t.ref}),t.title]}),e.jsx("small",{className:"truncate text-[12px] text-muted",children:s}),n&&e.jsx("span",{className:"flex flex-wrap gap-1.5",children:n})]}),a&&e.jsx(F,{name:"chevron",className:"size-4 text-muted"})]}),o=`flex min-h-[60px] items-center gap-2.5 border-b border-line px-3 py-2 last:border-b-0 ${r?"bg-secondary":""}`;return a?e.jsx("a",{href:a,"data-pr":t.id,"aria-current":r?"page":void 0,className:o,children:i}):e.jsx("div",{"data-pr":t.id,className:o,children:i})}const ss=d.prs,lh=()=>()=>{},Zi=()=>null;function Rd(t){return h.useSyncExternalStore(t?t.subscribe:lh,t?t.getState:Zi,t?t.getState:Zi)}function rh(t,s,n,a){const l=s==="fail"?ss.pipeline.fail:t.pipeline==="none"?ss.atoi.readyNoCi:ss.atoi.ready;return a!==null?[ss.host[t.forge],l,ss.asOf(Fe(a))].join(" · "):[ss.host[t.forge],nl(t.repo),l,...s==="fail"&&n?[n]:[]].join(" · ")}function ih({forge:t,mobile:s}){var i;const n=Rd(t);if(!((i=s.daemon)!=null&&i.forge)||!(n!=null&&n.state))return null;const a=Ef(n.state.prs);if(a.length===0)return null;const l=!s.fresh,r=o=>{var x;const c=o.sessions[0];return c?((x=s.sessions.get(c))==null?void 0:x.name)??null:null};return e.jsxs(e.Fragment,{children:[e.jsxs("h2",{className:"mt-1 flex items-center gap-2 text-[13px] font-semibold",children:[e.jsx(F,{name:"pr",className:"size-3.5"}),ss.atoi.title,e.jsx("span",{className:"min-w-0 truncate font-normal text-muted",children:ss.atoi.sub})]}),e.jsx(ps,{label:ss.atoi.title,children:a.map(({pr:o,why:c})=>e.jsx(hn,{href:ae({name:"pr",id:o.id}),stale:l,lead:e.jsx(Ie,{state:tn[o.pipeline]}),title:e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:o.ref})," ",o.title]}),sub:rh(o,c,r(o),l?n.at:null),children:e.jsx(F,{name:"chevron",className:"size-4 text-muted"})},o.id))})]})}function oh({forge:t,mobile:s,session:n}){var i;const a=Rd(t);if(!((i=s.daemon)!=null&&i.forge))return null;const l=Df((a==null?void 0:a.state)??null,n.id);if(!l)return null;if("pr"in l)return e.jsxs("a",{href:ae({name:"pr",id:l.pr.id}),"data-pr-chip":l.pr.id,className:"inline-flex h-8 flex-none items-center gap-[5px] font-mono text-[11px]",children:[e.jsx(Ie,{state:tn[l.pr.pipeline],pulse:l.pr.pipeline==="run"}),l.pr.ref]});const r=Zt({forge:l.kind});return e.jsx(dh,{tip:ss.chipTip(r.host,s.daemon.name,r.kind),label:ss.chipUnknown(r.kind)})}const ch=4e3;function dh({tip:t,label:s}){const n=h.useRef(null),[a,l]=h.useState(null);h.useEffect(()=>{if(!a)return;const i=setTimeout(()=>l(null),ch),o=c=>{var x;(x=n.current)!=null&&x.contains(c.target)||l(null)};return document.addEventListener("pointerdown",o,!0),()=>{clearTimeout(i),document.removeEventListener("pointerdown",o,!0)}},[a]);const r=()=>{var x,u;if(a){l(null);return}const i=(x=n.current)==null?void 0:x.closest("footer"),o=(u=(i==null?void 0:i.previousElementSibling)??i)==null?void 0:u.getBoundingClientRect(),c=globalThis.innerHeight??0;l({bottom:o?Math.max(c-o.top+8,8):96})};return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:n,type:"button","aria-label":t,title:t,onClick:r,"data-pr-chip":"unknown",className:"flex-none rounded-md border border-dashed border-input px-[5px] font-mono text-[11px] text-muted",children:s}),a&&e.jsx("span",{role:"status","data-chip-toast":"",style:a,className:"fixed inset-x-3.5 z-[7] flex items-center gap-2.5 rounded-[10px] border border-line bg-surface px-3 py-2.5 text-[13px] leading-[18px] whitespace-normal text-fg shadow-[0_8px_24px_#0005]",children:t})]})}function uh(t){const s=[...t].reverse().find(n=>n.point);return s!=null&&s.point?{qid:s.qid,eventId:s.point.items.reduce((n,a)=>Math.max(n,a.event),0)}:null}const xh=["atoi","done","ongoing","rigs"],mh={perm:"bg-approval",ask:"bg-attention",work:"bg-info",idle:"bg-ok",off:"bg-muted/70"},Od="grid grid-cols-[12px_minmax(0,1fr)] gap-x-2 gap-y-0.5 border-t border-dashed border-line py-1.5 first:border-t-0",Ji="border-approval/45 text-approval",ph=t=>t.replace(/\*\*/g,""),Pn=t=>new Date(t).toLocaleTimeString(dt,{hour:"2-digit",minute:"2-digit",hourCycle:"h23"});function eo(t){var a,l;const s=t.vars??{},n=d.chat.action;return((l=(a=d.chat.operator.suggest)[t.action])==null?void 0:l.call(a,s))??n.verb(t.action,s)??n.verbs[t.action]??n.apply}function Ld({tone:t,faded:s}){return e.jsx("span",{"aria-hidden":"true",className:`mt-[7px] size-2 rounded-full ${mh[t]} ${s?"opacity-50":""}`})}function fh(t){const s=d.chat.operator,n=t.turn.point,a="rounded-card border border-[color-mix(in_srgb,var(--sidebar-primary)_40%,var(--border))] bg-surface px-3 py-2.5 text-body";if(n.foldedAt){const l=s.folded(Pn(n.foldedAt));return e.jsx("article",{"data-point":!0,"data-point-folded":!0,"aria-label":l,className:`${a} text-muted`,children:l})}return e.jsxs("article",{"data-point":!0,"aria-label":`${s.title} · ${Pn(t.turn.askedAt)}`,className:a,children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1.5 text-small text-muted",children:[e.jsx("b",{className:"font-semibold text-fg",children:s.title}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono",children:Pn(t.turn.askedAt)})]}),e.jsx("div",{children:xh.map(l=>{const r=n.items.filter(i=>i.group===l);return r.length?l==="ongoing"?e.jsxs("div",{"data-point-group":l,className:Od,children:[e.jsx(Ld,{tone:"work"}),e.jsx("span",{className:"min-w-0",children:s.ongoing(r.length)})]},l):r.map(i=>e.jsx(hh,{item:i,...t},i.id)):null})})]})}function hh(t){var y,w;const s=d.chat.operator,n=d.chat.action,{item:a}=t,[l,r]=h.useState(!1),[i,o]=h.useState(""),c=!!t.disabled||t.busy!==null&&t.busy!==void 0,x=t.busy===a.id,u=a.group==="atoi",m=((y=a.ref)==null?void 0:y.kind)==="session.request"&&a.tone==="perm",p=a.suggestion,g=()=>{const S=i.trim();S&&(t.onAnswer(a.id,{text:S}),r(!1),o(""))},f=()=>{if(a.settled)return null;const S=[];for(const b of a.answers??[])S.push(e.jsx("button",{type:"button",disabled:c,onClick:()=>t.onAnswer(a.id,{id:b.id}),className:Oe({variant:b.style==="primary"?"primary":"outline",size:"xs",className:b.style==="danger"?Ji:""}),children:b.label},`a-${b.id}`));if(a.freeText&&S.push(e.jsx("button",{type:"button",disabled:c,"aria-expanded":l,onClick:()=>r(b=>!b),className:Oe({variant:"ghost",className:"h-8 px-2.5"}),children:s.reply},"reply")),p&&p.state!=="done"){const b=p.state==="running"||x;S.push(e.jsx("button",{type:"button",disabled:c||b,onClick:()=>t.onSuggestion(a.id),className:Oe({size:"xs",className:p.risk==="destructive"?Ji:""}),children:b?n.running:eo(p)},"suggest"))}return S.length?e.jsx("div",{"data-point-acts":!0,className:"col-start-2 mt-1 flex flex-wrap gap-1.5",children:S}):null};return e.jsxs("div",{"data-point-item":a.id,"data-settled":a.settled?!0:void 0,className:Od,children:[e.jsx(Ld,{tone:a.tone,faded:!!a.settled}),e.jsxs("div",{className:`min-w-0 [overflow-wrap:anywhere] ${a.settled?"text-muted":""}`,children:[e.jsx("b",{className:"font-semibold",children:a.who}),u?" : ":" ",m?e.jsx("code",{className:"font-mono text-[13px]",children:a.text}):ph(a.text),!u&&a.sub&&e.jsxs("span",{className:"text-muted",children:[" · ",a.sub]}),a.settled&&e.jsxs("span",{"data-point-receipt":!0,className:"block text-small text-ok",children:["✓ ",[a.settled.answer,s.settled[a.settled.where],Pn(a.settled.at)].filter(Boolean).join(" · ")]}),!a.settled&&(p==null?void 0:p.state)==="done"&&e.jsxs("span",{"data-point-receipt":!0,className:"block text-small text-ok",children:["✓ ",eo(p)," · ",n.done(p.doneAt?Pn(p.doneAt):"")]}),!a.settled&&a.error&&e.jsx("span",{role:"alert",className:"block text-small text-danger-fg",children:s.error(a.error)}),!a.settled&&((w=t.note)==null?void 0:w.item)===a.id&&e.jsx("span",{role:"status",className:"block text-small text-muted",children:t.note.text})]}),f(),l&&!a.settled&&e.jsxs("div",{"data-point-answer":!0,className:"col-start-2 mt-1 flex gap-1.5",children:[e.jsx("input",{"aria-label":s.answer.label,placeholder:s.answer.placeholder,value:i,disabled:c,onChange:S=>o(S.target.value),onKeyDown:S=>{S.key==="Enter"&&!S.nativeEvent.isComposing&&(S.preventDefault(),g())},className:"h-8 min-w-0 flex-1 rounded-lg border border-input bg-well px-2.5 text-[13px]"}),e.jsx("button",{type:"button",onClick:()=>{r(!1),o("")},className:Oe({variant:"ghost",className:"h-8 px-2.5"}),children:s.answer.cancel}),e.jsx("button",{type:"button",disabled:c||!i.trim(),onClick:g,className:Oe({variant:"primary",size:"xs"}),children:s.answer.send})]})]})}function gh(t){return t.status==="applied"?null:t.status==="cancelled"||t.status==="expired"?d.confirm[t.status]:t.status==="rejected"&&t.reason==="confirm_required"?d.chat.operator.setup:t.status==="rejected"&&t.reason==="stale"?d.chat.operator.stale:d.chat.operator.notSent}function bh({store:t,turn:s,readOnly:n}){const a=fe(t).fresh,[l,r]=h.useState(null),[i,o]=h.useState(null),c=(x,u)=>{r(x),o(null);const m=p=>{r(null);const g=gh(p);o(g?{item:x,text:g}:null)};t.pointAct(s.qid,x,u).then(m,()=>m({status:"failed"}))};return e.jsx(fh,{turn:s,busy:l,note:i,disabled:n||!a,onAnswer:c,onSuggestion:x=>c(x,"suggest")})}function zd(t){const s=pc(t),n=fe(t).fresh,a=uh(s.turns),l=a==null?void 0:a.eventId;h.useEffect(()=>{l!==void 0&&n&&t.operatorRead(l)},[l,n,t])}const Fe=t=>t?new Date(t).toLocaleTimeString(dt,{hour:"2-digit",minute:"2-digit"}):"",Dd=t=>`${t.sessionId}/${t.key}`;function jh(t,s){var a;if(!((a=t.daemon)!=null&&a.openrig))return s.length>0;const n=t.asksChannel;return s.length>0||n!==null&&(n.partial||n.channel.state!=="ready")}function Fd({state:t,machine:s}){const n=t.asksChannel;if(!n)return null;const a=d.asks.channel,l=n.channel.state==="ready"?n.partial?{title:null,body:d.asks.partial}:null:n.channel.state==="not_installed"?{title:a.not_installed.title(s),body:a.not_installed.body}:{title:a[n.channel.state].title,body:a[n.channel.state].body};return l?e.jsxs("div",{role:"status","data-channel":n.channel.state,className:"flex items-start gap-[9px] rounded-lg border border-line px-3 py-2.5 text-[13px] leading-[18px]",children:[e.jsx("span",{className:"mt-[5px]",children:e.jsx(Ie,{state:"off"})}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[l.title&&e.jsx("span",{className:"font-medium",children:l.title}),l.body&&e.jsx("span",{className:"text-muted",children:l.body})]})]}):null}function yh({sessions:t,threshold:s,now:n,stale:a}){const l=t.slice(0,va),r=t.length-l.length;return e.jsxs(ps,{label:d.atoi.working,children:[l.map(i=>{const o=Ja(i,n,s).context;return e.jsx(hn,{href:ae({name:"thread",sessionId:i.id}),stale:a,lead:e.jsxs(e.Fragment,{children:[e.jsx(Ie,{state:"work",pulse:!a}),e.jsx(fs,{tool:i.tool})]}),title:e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:i.name}),i.rig&&e.jsxs("span",{className:"text-small text-muted",children:[" ",i.rig.name]})]}),sub:Rr(i),...o?{meta:`${o.pct} %`,metaWarn:o.near}:{}},i.id)}),r>0&&e.jsxs("a",{href:ae({name:"sessions",filter:"working"}),className:"flex min-h-11 items-center gap-1 px-3 text-[13px] font-medium text-muted",children:[d.atoi.more(r),e.jsx(F,{name:"chevron",className:"size-4"})]})]})}function Nh({store:t,onReconnect:s,forge:n}){var J,Q,Y,ie;const a=fe(t),l=It(),r=Ls(),i=Yt();zd(t);const[o,c]=h.useState("all"),[x,u]=h.useState(new Set),m=[...a.sessions.values()],p=Wt(m),g=zc(a.asks??[]),f=a.fresh,y=((J=a.device)==null?void 0:J.confirm)===!0&&r,w=r&&((Q=a.device)==null?void 0:Q.confirm)!==!0,S=((Y=a.daemon)==null?void 0:Y.name)??"",b=((ie=a.device)==null?void 0:ie.contextNear)??kn,j=p.length+g.length,N=j>=Xm,$=N?o:"all",A=$==="rigs"?[]:pl(p,$),E=$==="all"||$==="rigs"?g:[],k=sr(A.map(X=>({id:Dd(X),value:X}))),T=sr(E.map(X=>({id:X.id,value:X}))),C=k.entries.filter(X=>{var v,_;if(!X.ghost||!f)return!1;const le=a.sessions.get(X.value.sessionId),B=(v=le==null?void 0:le.pending)==null?void 0:v.key;return!B||B===X.value.key||((_=le==null?void 0:le.lastAnswer)==null?void 0:_.key)===X.value.key?!1:Un(X.value,m,a.ops).kind==="handledElsewhere"}),I=C.map(X=>X.id).join("|");h.useEffect(()=>{if(C.length){u(X=>{var B,v;const le=new Set(X);for(const _ of C){const W=(v=(B=a.sessions.get(_.value.sessionId))==null?void 0:B.pending)==null?void 0:v.key;W&&le.add(`${_.value.sessionId}/${W}`)}return le});for(const X of C)k.dismiss(X.id)}},[I]);const P=new Set(C.map(X=>X.id)),L=X=>u(le=>{const B=new Set(le);return B.delete(X),B}),R=new Set(p.map(X=>X.sessionId)),M=Gm(m,R),z=$!=="permission"&&$!=="question"&&jh(a,g),U=j===0,H=!f,V=H?a.syncedAt?d.link.lastKnownAt(Fe(a.syncedAt)):d.inbox.lastKnown:j?d.atoi.count(j):void 0,ee=N&&e.jsx(Dm,{label:d.inbox.filtersLabel,value:$,onChange:c,options:[{value:"all",label:d.inbox.filters.all,count:j},{value:"permission",label:d.inbox.filters.permission,count:pl(p,"permission").length},{value:"question",label:d.inbox.filters.question,count:pl(p,"question").length},{value:"rigs",label:d.atoi.rigs,count:g.length}]}),G=U&&e.jsx(ps,{label:d.atoi.noRequest,children:e.jsx(Qt,{framed:!1,glyph:e.jsx(hs,{size:96,frozen:H}),title:d.atoi.noRequest,list:M.length===0,body:M.length?d.atoi.calmHint:d.atoi.nothingRunning,...M.length?{}:{action:e.jsxs("a",{href:ae({name:"sessions"}),className:Oe({size:"sm"}),children:[d.atoi.seeSessions,e.jsx(F,{name:"chevron",className:"size-4"})]})}})}),O=!U&&A.length===0&&E.length===0&&e.jsx(Qt,{glyph:e.jsx(F,{name:"inbox"}),title:d.inbox.emptyFilter,body:d.inbox.emptyFilterHint}),D=e.jsx("div",{className:"flex flex-col gap-3 empty:hidden",children:e.jsx(Sf,{store:t})});return l?e.jsx(kh,{update:D,state:a,items:A,asks:z?E:[],working:M,showRigs:z,chipBar:ee,empty:G||O,subtitle:V,threshold:b,now:i,machine:S}):e.jsxs(Os,{title:d.inbox.title,subtitle:V,offlinePill:!1,children:[D,ee,G,O,k.entries.filter(X=>!P.has(X.id)).map(X=>{var v;const le=X.value,B=a.sessions.get(le.sessionId);return e.jsx(Kr,{store:t,item:le,session:B,mode:Lr(le,(v=a.capabilities)==null?void 0:v[le.tool],(B==null?void 0:B.readOnly)===!0),outcome:Un(le,m,a.ops),fresh:f,ghost:X.ghost,changed:x.has(X.id),onReread:()=>L(X.id),canConfirm:y,enroll:w,onGone:()=>k.dismiss(X.id),onCheck:s},X.id)}),z&&e.jsxs(e.Fragment,{children:[e.jsxs("h2",{className:"mt-1 flex items-center gap-2 text-[13px] font-semibold",children:[e.jsx(Ie,{state:"rig"}),d.atoi.rigs,e.jsx("span",{className:"font-normal text-muted",children:g.length})]}),e.jsx(Fd,{state:a,machine:S}),T.entries.map(X=>e.jsx(dd,{store:t,ask:X.value,end:Pc(X.id,a.ops),fresh:f,ghost:X.ghost,canConfirm:y,enroll:w,onGone:()=>T.dismiss(X.id)},X.id))]}),M.length>0&&$==="all"&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"mt-1 text-[13px] font-semibold",children:d.atoi.working}),e.jsx(yh,{sessions:M,threshold:b,now:i,stale:H})]}),$==="all"&&e.jsx(ih,{forge:n,mobile:a}),H&&e.jsx("p",{className:"text-small text-muted",children:d.inbox.offlineNote})]})}function kh({update:t,state:s,items:n,asks:a,working:l,showRigs:r,chipBar:i,empty:o,subtitle:c,threshold:x,now:u,machine:m}){const p=Zn(),g=!s.fresh;return e.jsxs(Os,{title:d.inbox.title,subtitle:c,wideSubtitle:c,offlinePill:!1,children:[t,i,o,n.length>0&&e.jsx(ps,{title:d.atoi.requests,dot:"perm",count:n.length,children:n.map(f=>e.jsx(hn,{href:ae({name:"request",sessionId:f.sessionId,key:f.key}),stale:g,selected:p.name==="request"&&p.sessionId===f.sessionId,lead:e.jsx(fs,{tool:f.tool}),title:e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:f.botName})," ",f.risk==="high"?d.risk.badge:f.kind==="permission"?d.atoi.line.permission:d.atoi.pill[f.kind]]}),sub:Vl(f.kind==="permission"?f.body??f.text:vn(f)),meta:jn(f.since,u)},Dd(f)))}),r&&e.jsxs(ps,{title:d.atoi.rigs,dot:"rig",count:a.length,tone:"rigs",children:[e.jsx("div",{className:"p-2 empty:hidden",children:e.jsx(Fd,{state:s,machine:m})}),a.map(f=>{const y=Fc(f);return e.jsx(hn,{href:ae({name:"ask",id:f.id}),stale:g,selected:p.name==="ask"&&p.id===f.id,title:e.jsxs(e.Fragment,{children:[f.priority!=="routine"&&e.jsxs(e.Fragment,{children:[e.jsx(as,{tone:"urgent",children:d.asks.priority[f.priority]})," "]}),e.jsx("b",{className:"font-semibold",children:y.name}),f.from.rig?` · ${f.from.rig}`:""]}),sub:f.summary,meta:Fe(f.updatedAt),children:e.jsx("span",{className:"sr-only",children:d.asks.pill[Dc(f)]})},f.id)})]}),l.length>0&&e.jsxs(ps,{title:d.atoi.working,dot:"work",count:l.length,children:[l.slice(0,va).map(f=>{const y=Ja(f,u,x).context;return e.jsx(hn,{href:ae({name:"thread",sessionId:f.id}),stale:g,lead:e.jsx(fs,{tool:f.tool}),title:e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:f.name}),f.rig&&e.jsxs("span",{className:"text-small text-muted",children:[" ",f.rig.name]})]}),sub:Rr(f),...y?{meta:`${y.pct} %`,metaWarn:y.near}:{}},f.id)}),l.length>va&&e.jsxs("a",{href:ae({name:"sessions"}),className:"flex min-h-11 items-center gap-1 px-3 text-[13px] font-medium text-muted",children:[d.atoi.more(l.length-va),e.jsx(F,{name:"chevron",className:"size-4"})]})]}),g&&e.jsx("p",{className:"text-small text-muted",children:d.inbox.offlineNote})]})}function Ma({store:t,title:s,body:n,item:a,final:l=!1,children:r}){const i=$n(fe(t)),o=ae({name:"atoi"}),c={name:"atoi"};return e.jsxs(e.Fragment,{children:[e.jsx(sa,{title:d.result.header,fallback:c,label:d.detail.back,link:i}),e.jsx("main",{className:"min-h-0 flex-1 overflow-y-auto pb-[22px]",children:e.jsxs("div",{className:"flex flex-col items-start gap-4 pt-7",children:[e.jsx("div",{className:"grid size-14 place-items-center rounded-full border border-ok/20 bg-ok/10 text-ok",children:e.jsx(F,{name:"check",className:"size-[26px]"})}),a&&e.jsxs("span",{className:"flex items-center gap-2 text-meta font-medium tracking-[0.4px] text-muted",children:[e.jsx(Dr,{tool:a.tool,seed:a.sessionId,state:"idle"}),e.jsxs("span",{className:"[overflow-wrap:anywhere]",children:[a.botName," · ",a.task]})]}),e.jsx("h1",{className:"text-display leading-[1.25] font-semibold tracking-[-1px] [overflow-wrap:anywhere]",children:s}),e.jsx("p",{className:"text-body text-muted",children:n}),a&&e.jsx("div",{className:"w-full",children:e.jsx(Ve,{title:vn(a),children:e.jsxs("p",{className:"text-muted [overflow-wrap:anywhere]",children:[a.repo,a.branch&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("code",{className:"font-mono text-[.9em]",children:a.branch})]})]})})}),l&&e.jsx("p",{className:"text-body text-muted",children:d.result.final}),r,e.jsx("a",{href:o,className:De({variant:"primary",block:!0}),children:d.result.back}),a&&e.jsx("a",{href:ae({name:"thread",sessionId:a.sessionId}),className:De({block:!0}),children:d.result.thread(a.botName)})]})})]})}const vh=De({variant:"primary",block:!0});function wh({store:t,stale:s=!1,item:n,panel:a}){var f,y,w,S;const l=fe(t),r=$n(l),i=n==null?void 0:n.sessionId,o=i!==void 0&&l.threads.has(i),c=n?(f=l.sessions.get(n.sessionId))==null?void 0:f.lastAnswer:void 0,x=!!n&&!!c&&c.key===n.key;h.useEffect(()=>{!s&&!x&&i!==void 0&&!o&&t.openThread(i)},[s,x,i,o,t]);const u=ae({name:"atoi"}),m={name:"atoi"};if(s)return e.jsxs(e.Fragment,{children:[a?a.header:e.jsx(sa,{title:d.gone.header,fallback:m,label:d.detail.back,link:r}),e.jsxs("main",{className:"min-h-0 flex-1 overflow-y-auto pt-7",children:[e.jsx("h1",{className:"text-display leading-[1.25] font-semibold tracking-[-1px]",children:d.gone.staleTitle}),e.jsx("p",{className:"mt-2.5 text-body text-muted",children:d.gone.staleBody}),e.jsx("a",{href:(a==null?void 0:a.back.href)??u,className:`mt-6 ${vh}`,children:(a==null?void 0:a.back.label)??d.gone.back})]})]});if(n&&c&&x){const b=c.by.kind==="pc"?d.thread.event.fromPc:c.by.id===((y=l.device)==null?void 0:y.id)?d.thread.event.fromHere:d.thread.event.fromDevice(c.by.name);return e.jsx(Ma,{store:t,title:d.gone.titleOn(b),body:c.decision?d.gone.decided(c.decision,Fe(c.at)):d.gone.answered(Fe(c.at)),item:n})}const p=n&&n.kind==="permission"?[...((w=l.threads.get(n.sessionId))==null?void 0:w.items)??[]].reverse().find(b=>b.kind==="permission"&&b.text===n.text&&b.decision!==void 0&&b.decision!=="unknown"):void 0;if(!p||p.decision===void 0||p.decision==="unknown")return e.jsx(Ma,{store:t,title:d.gone.titleElsewhere,body:d.gone.body,item:n});const g=ld(p,n.sessionId,l.ops,((S=l.device)==null?void 0:S.id)??null);return e.jsx(Ma,{store:t,title:d.gone.titleOn(g),body:d.gone.decided(p.decision,Fe(p.at)),item:n})}function Sh({options:t,value:s,onChange:n,disabled:a=!1,botName:l,other:r,onSubmit:i}){const o=t.length,c=t.length===0,x=r!==void 0&&(c||s===o),u=x&&r.problem!==null&&r.problem!=="empty",m="flex min-h-12 cursor-pointer items-center gap-3 rounded-control border border-line bg-surface px-3 py-3 text-body has-[:checked]:border-fg/40 has-[:checked]:bg-raised has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-info";return e.jsxs("fieldset",{disabled:a,className:"my-3.5 flex min-w-0 flex-col gap-2 border-0 p-0",children:[e.jsx("legend",{className:"sr-only",children:d.question.legend}),t.map((p,g)=>e.jsxs("label",{className:m,children:[e.jsx("input",{type:"radio",name:"answer",value:g,checked:s===g,onChange:()=>n(g),className:"size-4 flex-none accent-fg"}),e.jsx("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:p})]},g)),r&&e.jsxs(e.Fragment,{children:[!c&&e.jsxs("label",{className:m,children:[e.jsx("input",{type:"radio",name:"answer",value:o,checked:x,onChange:()=>n(o),className:"size-4 flex-none accent-fg"}),e.jsx("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:d.question.other})]}),x&&e.jsxs("div",{children:[e.jsx("label",{htmlFor:"other-answer",className:"mt-3 mb-2 block text-small text-muted",children:d.question.fieldLabel(l)}),e.jsx("textarea",{id:"other-answer",rows:2,value:r.text,onChange:p=>r.onText(p.target.value),placeholder:d.question.placeholder,"aria-invalid":u,"aria-describedby":u?"other-problem":void 0,autoComplete:"off",enterKeyHint:"send",onKeyDown:p=>{p.key==="Enter"&&!p.nativeEvent.isComposing&&(p.preventDefault(),i==null||i())},className:"max-h-[120px] min-h-12 w-full min-w-0 resize-y rounded-control border border-line bg-surface p-3 text-base leading-[22px] text-fg placeholder:text-muted focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-info"}),u&&e.jsx("p",{id:"other-problem",role:"alert",className:"mt-2 text-small text-danger-fg",children:r.problem==="long"?d.question.long(Or):r.problem==="digit"?d.question.digit:d.question.untypable})]})]})]})}const $h="flex min-h-12 cursor-pointer items-center gap-3 rounded-control border border-line bg-surface px-3 py-3 text-body has-[:checked]:border-fg/40 has-[:checked]:bg-raised has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-info";function Ch({questions:t,selected:s,onToggle:n,disabled:a=!1}){return e.jsx("div",{className:"my-3.5 flex flex-col gap-5",children:t.map((l,r)=>e.jsxs("fieldset",{disabled:a,className:"flex min-w-0 flex-col gap-2 border-0 p-0",children:[e.jsx("legend",{className:"mb-2 text-base leading-[1.4] font-semibold [overflow-wrap:anywhere]",children:l.header??l.question}),l.header&&e.jsx("p",{className:"mb-1 text-small text-muted [overflow-wrap:anywhere]",children:l.question}),l.options.map(i=>{var o;return e.jsxs("label",{className:$h,children:[e.jsx("input",{type:l.multi?"checkbox":"radio",name:`question-${r}`,checked:((o=s[r])==null?void 0:o.includes(i.label))===!0,onChange:()=>n(r,i.label),className:"size-4 flex-none accent-fg"}),e.jsxs("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:[i.label,i.description&&e.jsx("small",{className:"mt-0.5 block text-meta text-muted",children:i.description})]})]},i.label)})]},l.id))})}function Mh({onReconnect:t}){const[s,n]=Sn();return e.jsxs(Ve,{title:d.link.lostTitle,tone:"warning",role:"status",children:[e.jsx("p",{children:d.link.lostDetail}),t&&e.jsx("button",{type:"button",disabled:s,onClick:()=>{n(!0),t()},className:De({block:!0,className:"mt-3"}),children:s?d.link.reconnecting:d.link.reconnect})]})}const Eh=t=>t.decision==="deny"?d.result.denied:t.answer!==void 0?d.result.answered:d.result.allowed;function Ah({title:t,panel:s}){return e.jsx("header",{className:"flex-none border-b border-line pt-2 pb-3",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("button",{type:"button",onClick:s.onBack,className:"-ml-1 flex min-h-11 items-center gap-1 pr-2 text-body text-muted active:text-fg",children:[e.jsx(F,{name:"back"}),d.nav.backTo.thread]}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),e.jsx("button",{type:"button",onClick:s.onClose,"aria-label":d.atelier.closePanel,title:d.atelier.closeTitle,className:$t({}),children:e.jsx(F,{name:"close"})})]})})}const Th="(orientation: landscape) and (max-height: 500px)",to=["wheel","touchstart","keydown","pointerdown"];function or({store:t,sessionId:s,requestKey:n,onReconnect:a,panel:l,onSettled:r,keys:i=!1}){var He,Mt,Rt,Se,Et,Ot;const o=fe(t),c=Yt(),{fresh:x,ops:u,capabilities:m}=o,p=Xc(),{look:g}=qt(),f=p!==void 0&&g==="offline",[y,w]=h.useState(n),[S,b]=h.useState(!1),[j,N]=h.useState(null),[$,A]=h.useState(""),[E,k]=h.useState(null),[T,C]=h.useState({sig:"",v:[]}),I=Ls(),[P,L]=h.useState(!1),R=h.useRef(y);R.current=y,h.useEffect(()=>{n!==R.current&&(w(n),b(!1),N(null),A(""),k(null),L(!1))},[n]);const M=[...o.sessions.values()],z=Wt(M).find(de=>de.sessionId===s&&de.key===y),U=h.useRef(void 0);z&&(U.current=z);const H=Un({sessionId:s,key:y},M,u),V=(z==null?void 0:z.cut)===!0;h.useEffect(()=>{V&&x&&t.loadPending(s)},[t,s,y,V,x]);const ee=(Mt=(He=o.sessions.get(s))==null?void 0:He.pending)==null?void 0:Mt.key;h.useEffect(()=>{var de;if(!(H.kind!=="changed"||!ee)){w(ee),b(!0),N(null),A(""),k(null);try{(de=globalThis.history)==null||de.replaceState(globalThis.history.state,"",ae(l?{name:"atelier",sessionId:s,requestKey:ee}:{name:"request",sessionId:s,key:ee}))}catch{}}},[H.kind,ee,s]);const G=$n(o),O={name:"atoi"},D=H.kind==="applied"||z===void 0&&!(H.kind==="sending"||H.kind==="uncertain"||H.kind==="rejected"||H.kind==="failed"||H.kind==="changed")&&x,J=l==null?void 0:l.onBack;h.useEffect(()=>{D&&J&&J()},[D,J]);const Q=h.useRef(r);Q.current=r,h.useEffect(()=>{if(!D||!Q.current)return;const de=setTimeout(()=>{var Ue;return(Ue=Q.current)==null?void 0:Ue.call(Q)},Bc);return()=>clearTimeout(de)},[D]);const[Y,ie]=h.useState(null),[X,le]=h.useState(null);h.useLayoutEffect(()=>{var sn,En;const de=Y,Ue=X,Ze=(sn=globalThis.matchMedia)==null?void 0:sn.call(globalThis,Th);if(!de||!Ue||!Ze)return;let At=!1;const Jt=()=>{if(At||!Ze.matches)return;const it=Ue.firstElementChild??Ue,nn=de.getBoundingClientRect(),an=it.getBoundingClientRect(),An=an.top-nn.top+de.scrollTop,Tn=parseFloat(getComputedStyle(de).paddingBottom)||0;de.scrollTop=an.height>de.clientHeight-Tn?An:Math.max(0,An+an.height-(de.clientHeight-Tn))},Ds=()=>{Ze.matches&&(At=!1,Jt())},ys=()=>{At=!0};Jt();const Ht=typeof ResizeObserver=="function"?new ResizeObserver(Jt):null;Ht==null||Ht.observe(de),Ht==null||Ht.observe(Ue),(En=Ze.addEventListener)==null||En.call(Ze,"change",Ds);for(const it of to)de.addEventListener(it,ys,{passive:!0});return()=>{var it;Ht==null||Ht.disconnect(),(it=Ze.removeEventListener)==null||it.call(Ze,"change",Ds);for(const nn of to)de.removeEventListener(nn,ys)}},[y,Y,X]);const B=de=>l?e.jsx(Ah,{title:de,panel:l}):e.jsx(sa,{title:de,fallback:O,label:d.detail.back,link:G});if(H.kind==="applied")return e.jsx(Ma,{store:t,title:Eh(H),body:d.result.body,item:U.current,final:!0});const v=H.kind==="sending"||H.kind==="uncertain"||H.kind==="rejected"||H.kind==="failed"||H.kind==="changed",_=z??(v?U.current:void 0);if(!_)return!x&&o.syncedAt===null?e.jsxs(e.Fragment,{children:[B(d.gone.header),e.jsx("main",{className:"min-h-0 flex-1 pt-7 text-body text-muted",role:"status",children:d.loading})]}):e.jsx(wh,{store:t,stale:!x,item:U.current,...l?{panel:{header:B(d.gone.header),back:{href:ae({name:"atelier",sessionId:s}),label:d.nav.backTo.thread}}}:{}});const W=_.kind==="question",se=_.options??[],re=m==null?void 0:m[_.tool],K=W&&(re==null?void 0:re.freeTextAnswer)===!0,ce=W&&(re==null?void 0:re.questions)===!0&&_.requestId!==void 0&&((Rt=_.questions)!=null&&Rt.length)?_.questions:void 0,ge=!ce&&(re==null?void 0:re.decide)===!1&&se.length>0,Ye=!ce&&!ge&&W&&(se.length>0||K),pt=((Se=o.device)==null?void 0:Se.confirm)===!0&&I,Re=_.risk!=="low",Le=JSON.stringify((ce??[]).map(de=>[de.id,de.options.map(Ue=>Ue.label)])),pe=T.sig===Le?T.v:[],he=(ce??[]).filter((de,Ue)=>{var Ze;return!((Ze=pe[Ue])!=null&&Ze.length)}).length,Me=(de,Ue)=>{const Ze=ce==null?void 0:ce[de];if(!Ze)return;const At=(ce??[]).map((Ds,ys)=>pe[ys]??[]),Jt=At[de]??[];At[de]=Ze.multi?Jt.includes(Ue)?Jt.filter(Ds=>Ds!==Ue):[...Jt,Ue]:[Ue],C({sig:Le,v:At}),L(!1)},ze={key:_.key,kind:_.kind,text:_.text},at=de=>{if(!ce||_.requestId===void 0)return;const Ue=de?[]:ce.map((Ze,At)=>({id:Ze.id,selected:pe[At]??[]}));L(!t.answer(s,_.requestId,Ue,{expect:ze,...de?{cancel:!0}:{}}))},et=x&&!S&&z!==void 0&&H.kind!=="sending"&&H.kind!=="uncertain"&&(pt||!Re),bt=de=>{Re?(k(de),L(!1)):L(!t.reply(s,String(de+1),{expect:ze}))},jt=e.jsx("ul",{"aria-label":d.answers.legend,className:"my-3.5 flex list-none flex-col gap-2 p-0",children:se.map((de,Ue)=>{var Ze;return e.jsx("li",{children:e.jsxs("button",{type:"button",disabled:!et,"aria-pressed":E===Ue,onClick:()=>bt(Ue),className:"flex min-h-12 w-full flex-col items-start justify-center rounded-control border border-line bg-surface px-3 py-3 text-left text-body [overflow-wrap:anywhere] disabled:opacity-45 active:bg-raised aria-pressed:border-fg/40 aria-pressed:bg-raised",children:[de,((Ze=_.optionDetails)==null?void 0:Ze[Ue])&&e.jsx("small",{className:"mt-0.5 text-meta text-muted",children:_.optionDetails[Ue]})]})},`${Ue}:${de}`)})}),Z=Lc($),q=K&&(se.length===0||j===se.length),ye=W?null:Oc(_),_e=Um(_),oe=(o.previews.get(s)??[]).slice(-12),Ae=H.kind==="sending"||H.kind==="uncertain",st=()=>{q?Z.problem===null&&L(!t.reply(s,Z.text,{expect:ze})):j!==null&&j<se.length&&L(!t.reply(s,String(j+1),{expect:ze}))},yt=ae(l?{name:"atelier",sessionId:s}:{name:"thread",sessionId:s}),js=i&&!l&&e.jsx(ea,{back:e.jsx("span",{className:"w-2.5"}),tool:_.tool,name:_.botName,dot:_.kind==="permission"?"perm":_.kind==="question"?"ask":"work",sub:[_.repo,_.branch].filter(Boolean).join(" · "),more:e.jsxs(e.Fragment,{children:[_.risk==="high"?e.jsx(as,{tone:"risk",children:d.risk.badge}):e.jsx(as,{tone:_.kind==="question"?"ask":_.kind==="permission"?"perm":"plain",children:d.atoi.pill[_.kind]}),e.jsxs("a",{href:yt,className:Oe({size:"sm",className:"ml-1"}),children:[e.jsx(F,{name:"terminal",className:"size-4"}),d.atoi.openThread]})]})});return e.jsxs(e.Fragment,{children:[js||B(d.detail.heading[_.kind]),e.jsxs("main",{ref:ie,className:"min-h-0 flex-1 overflow-y-auto overscroll-contain pb-[22px]",children:[!js&&e.jsxs("div",{className:"mt-4 flex items-start gap-3 rounded-card border border-line bg-surface p-3.5",children:[e.jsx(Dr,{tool:_.tool,seed:_.sessionId,state:((Et=o.sessions.get(s))==null?void 0:Et.state)??"idle",frozen:!x}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("strong",{className:"block text-body [overflow-wrap:anywhere]",children:_.task}),e.jsxs("p",{className:"mt-0.5 text-meta text-muted",children:[_.botName," · ",d.tools[_.tool]]}),e.jsxs("p",{className:"mt-0.5 text-meta [overflow-wrap:anywhere] text-muted",children:[_.repo,_.branch&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("code",{className:`font-mono text-[.9em] ${_.worktree?"underline decoration-dotted underline-offset-2":""}`,children:_.branch})]})]})]})]}),e.jsxs("div",{className:"mt-[22px] mb-3",children:[e.jsx(Jm,{kind:_.kind,risk:_.risk}),e.jsx("h1",{className:`mt-2.5 text-display leading-[1.25] font-semibold tracking-[-1px] [overflow-wrap:anywhere] ${_.kind==="permission"?"phone-side:hidden":""}`,children:_.kind==="permission"?d.detail.commandTitle:vn(_)})]}),W?e.jsxs(e.Fragment,{children:[ce&&e.jsx(Ch,{questions:ce,selected:pe,onToggle:Me,disabled:Ae}),ge&&jt,Ye&&e.jsx(Sh,{options:se,value:j,onChange:de=>{N(de),L(!1)},botName:_.botName,disabled:Ae,other:K?{text:$,onText:de=>{A(de),L(!1)},problem:Z.problem}:void 0,onSubmit:x&&!S&&!Ae&&z!==void 0?st:void 0}),!K&&!ge&&!ce&&se.length>0&&e.jsx("p",{className:"mb-3.5 text-small text-muted",children:d.decide.otherUnsupported})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:le,children:e.jsx(ep,{text:_.body??_.text})}),ge&&jt,!ge&&se.length>0&&e.jsx("ul",{"aria-label":d.detail.options,className:"my-3.5 flex list-none flex-col gap-2 p-0",children:se.map(de=>e.jsx("li",{className:"rounded-control border border-line bg-surface px-3 py-3 text-body [overflow-wrap:anywhere]",children:de},de))}),ye&&e.jsx(Ve,{title:ye.title,tone:"danger",children:e.jsx("p",{children:ye.body})}),_e&&e.jsx(Ve,{title:_e.title,children:e.jsx("p",{className:"text-muted",children:_e.body})}),e.jsxs("dl",{className:"my-[18px] grid grid-cols-[74px_minmax(0,1fr)] gap-x-3 gap-y-2.5 text-small",children:[_.branch&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-muted",children:d.detail.branch}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:e.jsx("code",{className:"font-mono text-[.9em]",children:_.branch})})]}),(ye==null?void 0:ye.destination)&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-muted",children:d.detail.destination}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:e.jsx("code",{className:"font-mono text-[.9em]",children:ye.destination})})]}),e.jsx("dt",{className:"text-muted",children:d.detail.asked}),e.jsx("dd",{className:"m-0",children:d.detail.ago(jn(_.since,c))})]}),oe.length>0&&e.jsxs("details",{className:"group mt-[18px] border-t border-line",children:[e.jsxs("summary",{className:"flex min-h-12 cursor-pointer list-none items-center justify-between text-small [&::-webkit-details-marker]:hidden",children:[d.detail.context,e.jsx(F,{name:"terminal",className:"size-4 text-muted"})]}),e.jsx("pre",{className:"pt-2 pb-4 font-mono text-small leading-[1.7] break-words whitespace-pre-wrap text-muted [overflow-wrap:anywhere]",children:oe.join(`
|
|
13
|
+
`)})]})]}),!x&&!f&&H.kind!=="uncertain"&&e.jsx("div",{className:"mt-4",children:e.jsx(Mh,{onReconnect:a})})]}),e.jsx(Lp,{item:_,outcome:H,fresh:x,changed:S,stillPending:z!==void 0,threadHref:yt,withThread:!js,onReread:()=>{b(!1),N(null),k(null),L(!1)},onDecide:de=>L(!t.decide(s,de,{expect:ze})),answerable:Ye,choice:q?se.length:j,onAnswer:st,answerBlocked:q?Z.problem!==null:j===null||j>=se.length,onCheck:a,refused:P,store:t,deviceConfirm:((Ot=o.device)==null?void 0:Ot.confirm)===!0,optionReply:ge?{canConfirm:Re?pt:!0,picked:Re?E:null,onBack:()=>k(null),onReply:(de,Ue)=>E===null?null:t.reply(s,String(E+1),{assertion:de,expect:Ue})}:void 0,multi:ce?{missing:he,onSend:()=>at(!1),onCancel:()=>at(!0)}:void 0,keys:i})]})}const _h=/^#{1,6}\s+(.+?)\s*#*\s*$/,Ih=/^(?:\*\*|__)([^*_].*?)(?:\*\*|__)\s*:?\s*$/,Rh=/^(\s*)(?:[-*+]|\d+[.)])\s+(.*)$/,Oh=/^\s*\d+[.)]\s/,Lh=/^\[([ xX])\]\s+/,zh=/^\s*([-*_])(\s*\1){2,}\s*$/,Dh=/^\s*(```|~~~)/,Fh=/^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/,cr=new RegExp("(?<!\\\\)\\|"),Cl=/^\s*>\s?(.*)$/,Ph=t=>t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":"left",xa=t=>t.trim().replace(/^\|/,"").replace(new RegExp("(?<!\\\\)\\|$"),"").split(cr).map(s=>s.trim().replace(/\\\|/g,"|")),Bh=80,qh=t=>t.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g,""),Hh=[["questions",/\b(questions?|open|ouvert(e|es)?|decisions?|decider|decide|choix|choices?|a trancher|to settle|besoin de vous|need(s)? you)\b/],["next",/\b(next|suite|reste|left|remaining|todo|to do|a faire|follow[- ]?ups?|prochaines?|later|ensuite|pending)\b/],["verified",/\b(verif\w*|tests?|tested|checks?|checked|validations?|valide|results?|resultats?)\b/],["done",/\b(done|faits?|realise|termine|completed?|changes?|changements?|modifications?|what i did|ce que j'?ai fait|implemented|implemente|delivered|livre)\b/]];function Uh(t){var n;const s=qh(t).replace(/[’']/g,"'");return((n=Hh.find(([,a])=>a.test(s)))==null?void 0:n[0])??"other"}function Pd(t){const s=t.replace(/\r\n?/g,`
|
|
14
|
+
`).split(`
|
|
15
|
+
`),n=[];let a=[],l=null;const r=()=>{a.length&&(n.push({type:"p",text:a.join(" ").trim()}),a=[])},i=()=>{l&&(n.push({type:"list",ordered:l.ordered,items:l.items}),l=null)};for(let o=0;o<s.length;o++){const c=s[o],x=c.match(Dh);if(x){r(),i();const f=[];for(o++;o<s.length&&!s[o].trim().startsWith(x[1]);o++)f.push(s[o]);n.push({type:"code",text:f.join(`
|
|
16
|
+
`).replace(/\s+$/,"")});continue}const u=s[o+1];if(cr.test(c)&&u!==void 0&&Fh.test(u)){const f=xa(c);if(xa(u).length===f.length){r(),i();const y=[];for(o+=2;o<s.length&&s[o].trim()!==""&&cr.test(s[o]);o++)y.push(Array.from({length:f.length},(w,S)=>xa(s[o])[S]??""));o--,n.push({type:"table",header:f,rows:y,align:xa(u).map(Ph)});continue}}const m=c.match(Cl);if(m){r(),i();const f=[m[1]];for(;o+1<s.length&&Cl.test(s[o+1]);o++)f.push(s[o+1].match(Cl)[1]);n.push({type:"quote",blocks:Pd(f.join(`
|
|
17
|
+
`)).map(y=>y.type==="h"?{type:"p",text:y.text}:y)});continue}if(c.trim()===""){r();continue}if(zh.test(c)){r(),i();continue}const p=c.match(_h)??c.match(Ih);if(p){r(),i(),n.push({type:"h",text:p[1].trim().replace(/\s*:\s*$/,"")});continue}const g=c.match(Rh);if(g){r();const f=g[1].length,y=g[2];if(l&&f>l.indent&&l.items.length){l.items[l.items.length-1].sub.push(y.trim());continue}const w=Oh.test(c);(!l||f<l.indent||l.ordered!==w)&&(i(),l={ordered:w,items:[],indent:f});const S=y.match(Lh);l.items.push({text:(S?y.slice(S[0].length):y).trim(),sub:[],...S?{checked:S[1]!==" "}:{}});continue}if(l&&/^\s+\S/.test(c)&&a.length===0){const f=l.items[l.items.length-1];f.text=`${f.text} ${c.trim()}`;continue}i(),a.push(c.trim())}return r(),i(),n}const Ba=t=>/[??]\s*$/.test(t);function dr(t){const s=t.replace(/\s*[??]\s*$/,"").match(/(?:^|[:;]\s*)([^:;?]*?)\s+(?:or|ou)\s+([^,:;?]{2,60})$/i);if(!s)return[];const n=[...s[1].split(/\s*,\s*/),s[2]].map(r=>r.trim()).filter(Boolean),a=r=>{var i,o,c;return(((i=r.match(/\(/g))==null?void 0:i.length)??0)===(((o=r.match(/\)/g))==null?void 0:o.length)??0)&&(((c=r.match(/`/g))==null?void 0:c.length)??0)%2===0},l=r=>r.length>=2&&r.length<=60&&r.split(/\s+/).length<=8&&!/[.!]\s/.test(r)&&a(r);return n.length>=2&&n.length<=6&&n.every(l)?n:[]}const so=t=>t.replace(/\[([^\]]+)\]\([^)]*\)/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/(\*\*|__)(.+?)\1/g,"$2").replace(new RegExp("(?<![\\w*])\\*([^*\\n]+)\\*(?![\\w*])","g"),"$1").trim(),Ln=/\s*[★⭐]\s*/g,Bd=/^(.+?)\s*\(([^()]*(?:\([^()]*\)[^()]*)*)\)\s*$/,Is=(t,s)=>{const n=Ln.test(t)||Ln.test(s);return{label:so(t.replace(Ln," ")),detail:so(s.replace(Ln," ")),...n?{star:n}:{}}},Ys=/^(\*\*|__)(\S(?:.*?\S)?)\1\s*(?:[—–:-]\s*)?(.*)$/,no=/^(.+?)(\s+[—–-]\s+|:\s+)(.+)$/,Zr=(t,s=!1)=>t.every(n=>n.label.length>0&&n.label.length<=Bh&&!Ba(n.label)&&(s||!Ba(n.detail)));function ao(t){if(t.length<2||t.length>6)return null;const s=t.map(l=>{var r;return Ys.test(l)?null:((r=l.match(no))==null?void 0:r[2].trim()[0])??null}),n=s.every(l=>l!==null&&l===s[0]),a=t.map(l=>{const r=l.match(Ys);if(r)return Is(r[2],r[3]);const i=n?l.match(no):null;return i?Is(i[1],i[3]):Is(l,"")});return Zr(a)?a:null}const Wh=/(^|[\s(:,;])([a-h])\)\s+/g;function lo(t){const s=[];for(const r of t.matchAll(Wh))r[2].charCodeAt(0)-97===s.length&&s.push({at:r.index+r[1].length,end:r.index+r[0].length});if(s.length<2||s.length>8)return null;const n=t.slice(0,s[0].at).trim().replace(/\s*[:—–-]\s*$/,"").trim();if(!n)return null;const a=s.map((r,i)=>{var o;return t.slice(r.end,(o=s[i+1])==null?void 0:o.at)});a[a.length-1]=a[a.length-1].split(new RegExp("(?<=[.!??])\\s+(?=\\p{Lu})","u"))[0];const l=a.map(r=>{const i=r.trim().replace(/[\s,;.??]+$/,""),o=/[★⭐]/.test(i),c=i.replace(Ln," ").trim().match(Bd),x=c?Is(c[1],c[2]):Is(i,"");return o?{...x,star:o}:x});return Zr(l,!0)?{stem:n,options:l}:null}const Kh=/^(\*\*|__)(.+?[??])\s*\1/,ro=t=>{var s;return Ba(t)?t:((s=t.match(Kh))==null?void 0:s[2])??null},io=/(^|[^\p{L}])(laquelle|lequel|lesquel|quelle (option|approche|solution)|quel choix|which|pr[ée]f[ée]r|prefer|choisi|choos|pick|reten|retien)/iu,Vh=/^(\d+)[.)]\s+(.+)$/,Gh=/^(\*\*|__)(\d+)[.)]\s+(.+?)\1\s*(.*)$/,Xh=t=>t.length>160?t.split(new RegExp("(?<=[.!])\\s+(?=\\p{Lu}|\\()","u"))[0]:t;function Ml(t,s,n){var r;t=t.trim().replace(/\.$/,"");const a=t.match(Bd);let l=Xh(s.trim()).replace(/^\((.*)\)\.?$/,"$1").replace(/^[—–:-]\s*/,"")||(a?a[2]:"");return!l&&n&&(l=n.type==="p"?n.text:n.type==="list"?((r=n.items[0])==null?void 0:r.text)??"":""),Is(a?a[1]:t,l)}const Qh=/recommand|recommend/i;function qd(t,s,n=[]){const a=t.toLowerCase(),l=u=>{const m=Math.min(...u);return m<1/0?u.indexOf(m):-1},r=u=>{const m=u.length>=2?a.search(new RegExp(`(^|[^\\p{L}])${u.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}($|[^\\p{L}])`,"u")):-1;return m<0?1/0:m},i=s.map(u=>u.label.toLowerCase().split(/\s+/)[0]),o=l(s.map((u,m)=>Math.min(r(u.label.toLowerCase()),i[m].length>=4&&i.filter(p=>p===i[m]).length===1?r(i[m]):1/0)));if(o>=0)return o;const c=a.match(/\boption\s+(\d+)/);return c&&Number(c[1])>=1&&Number(c[1])<=s.length?Number(c[1])-1:n.findIndex(u=>u&&new RegExp(`(^|[\\s:])${u}([.\\s,]|$)`).test(t))}const Hd=(t,s)=>s<0||t.some(n=>n.star)?t:t.map((n,a)=>a===s?{...n,star:!0}:n);function Yh(t){if(!/^(\*\*|__)[^*_]+\1:?$/.test(t.text.trim()))return null;const s=t.sub.find(o=>Qh.test(o.slice(0,40)));if(!s)return null;const n=t.sub.filter(o=>o!==s),a=n.filter(o=>Ys.test(o)),l=a.length>=2?a:n;if(l.length<2||l.length>6)return null;const r=l.map(o=>{var c;return((c=o.replace(/^(\*\*|__)/,"").match(/^([A-Z])\.\s/))==null?void 0:c[1])??""}),i=l.map(o=>{const c=o.match(Ys);return c?Is(c[2].replace(/^[A-Z]\.\s+/,"").replace(/\.$/,""),c[3].replace(/^[,;]\s*/,"")):Is(o.replace(/\.$/,""),"")});return Zr(i)?{options:Hd(i,qd(s,i,r)),notes:t.sub.filter(o=>!l.includes(o))}:null}const ma=(t,s,n=t,a)=>{const l=s??dr(n).map(o=>({label:o,detail:""})),r=l.map(o=>o.detail),i=l.findIndex(o=>o.star);return{text:t,options:l.map(o=>o.label),...r.some(Boolean)?{details:r}:{},...i>=0?{recommended:i}:{},...a?{ref:a}:{}}};function Ud(t,s={}){var w,S;const n=Pd(t);let a,l;const r=n[0];(r==null?void 0:r.type)==="h"&&(a=r.text,n.shift()),a&&((w=n[0])==null?void 0:w.type)==="p"&&!Ba(n[0].text)&&(l=n[0].text,n.shift());const i=[];let o={kind:"other",blocks:[]};const c=()=>{(o.blocks.length||o.title)&&i.push(o)};for(const b of n)if(b.type==="h"){c();const j=Uh(b.text);o={kind:s.plan&&(j==="done"||j==="verified")?"other":j,title:b.text,blocks:[]}}else o.blocks.push(b);c();const x=[];let u=null,m="";const p=(b,j)=>{b===1?u=[j]:u&&b===u.length+1&&u.push(j)},g=b=>{var j,N;return(N=(j=b.match(Ys))==null?void 0:j[2])==null?void 0:N.replace(/\s*:$/,"")},f=()=>{const b=u&&u.length>=2&&u.length<=8?u:null;return u=null,b?Hd(b,qd(m,b)):null};for(const b of i){const j=b.kind==="done"||b.kind==="verified",N=(S=b.title)==null?void 0:S.match(Vh);N&&p(Number(N[1]),Ml(N[2],"",b.blocks[0]));for(let $=0;$<b.blocks.length;$++){const A=b.blocks[$];if(A.type==="p"){const E=A.text.match(Gh);if(E){p(Number(E[2]),Ml(E[3],E[4],b.blocks[$+1]));continue}if(/^(\*\*|__)[^*_]*(recommand|recommend)/i.test(A.text)&&(m=A.text),j)continue;const k=ro(A.text),T=lo(A.text);if(!k&&!T)continue;const C=b.blocks[$+1];let I=(C==null?void 0:C.type)==="list"&&!C.ordered?ao(C.items.map(P=>P.text)):null;I?b.blocks.splice($+1,1):T?I=T.options:!dr(k).length&&io.test(k)&&(I=f()),A.q=x.length,x.push(ma(A.text,I,T&&!k?T.stem:k))}else A.type==="list"&&!j&&A.items.forEach((E,k)=>{const T=Ys.test(E.text)?E.text.lastIndexOf("?"):-1,C=ro(E.text)??(T>0?E.text.slice(0,T+1):null),I=lo(E.text),P=C||I?null:Yh(E);if(!C&&!I&&!P){const R=A.ordered?E.text.match(Ys):null;R&&p(k+1,Ml(R[2],R[3],void 0));return}E.q=x.length;const L=ao(E.sub);P?(x.push(ma(E.text,P.options,E.text,g(E.text))),E.sub=P.notes):!L&&I?x.push(ma(I.stem,I.options,I.stem,g(I.stem))):x.push(ma(E.text,L??(!dr(C).length&&io.test(C)?f():null),C??E.text)),L&&!P&&(E.sub=[])})}}const y=!!a&&(r==null?void 0:r.type)==="h"||x.length>0||i.some(b=>!!b.title||b.blocks.some(j=>j.type!=="p"));return{title:a,lead:l,sections:i,questions:x,structured:y}}const El="mt-px inline-flex size-4 flex-none items-center justify-center rounded-[4px] border";function Wd({checklist:t,current:s}){var u;const[n,a]=h.useState(!1),{tasks:l,done:r,total:i}=t,o=((u=l.find(m=>m.status==="in_progress"))==null?void 0:u.text)??s??(r===i?d.checklist.allDone:d.checklist.paused),c=l.some(m=>m.status==="in_progress")||!!s,x=h.useMemo(()=>{const m=new Map;return l.map(p=>{const g=m.get(p.text)??0;return m.set(p.text,g+1),g===0?p.text:`${p.text}#${g}`})},[l]);return e.jsxs("div",{className:"sticky top-0 z-10 flex-none bg-bg",children:[e.jsxs("button",{type:"button","aria-expanded":n,onClick:()=>a(m=>!m),className:`flex min-h-11 w-full flex-col gap-1.5 border border-line bg-surface px-3 py-2.5 text-left text-[12px] leading-[18px] text-muted shadow-[0_4px_14px_rgba(0,0,0,.35)] ${n?"rounded-t-card":"rounded-card"}`,children:[e.jsxs("span",{className:"flex w-full items-center gap-2",children:[e.jsx(F,{name:"plan",className:"size-3.5",stroke:1.8}),e.jsx("strong",{className:"font-medium text-fg",children:d.checklist.title}),e.jsx("span",{className:"flex-1"}),e.jsxs("span",{className:"font-mono text-[11px] text-fg",children:[r,"/",i]}),e.jsx("span",{"aria-hidden":"true",className:"h-1 w-16 overflow-hidden rounded-[2px] bg-raised",children:e.jsx("span",{className:"block h-full bg-ok",style:{width:`${i?r/i*100:0}%`}})}),e.jsx("span",{className:n?"-rotate-90":"rotate-90",children:e.jsx(F,{name:"chevron",className:"size-[13px]",stroke:2})})]}),e.jsxs("span",{className:"block w-full truncate",children:[c&&e.jsx("span",{className:"mr-1.5 inline-block size-1.5 rounded-full bg-info align-[1px]"}),o]})]}),n&&e.jsxs("ol",{className:"max-h-[50dvh] overflow-y-auto rounded-b-card border border-t-0 border-line bg-surface px-3 pt-1.5 pb-2.5 text-small",children:[l.map((m,p)=>e.jsxs("li",{className:`flex items-start gap-2.5 py-1.5 [overflow-wrap:anywhere] ${m.status==="completed"?"text-muted line-through":m.status==="in_progress"?"font-medium text-fg":"text-fg"}`,children:[m.status==="completed"&&e.jsx("span",{role:"img","aria-label":d.checklist.box.completed,className:`${El} border-ok/50 font-mono text-[10px] font-semibold text-ok no-underline`,children:"✓"}),m.status==="in_progress"&&e.jsx("span",{role:"img","aria-label":d.checklist.box.in_progress,className:`${El} border-info`,children:e.jsx("svg",{className:"size-2.5 text-info motion-safe:animate-spin",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})})}),m.status==="pending"&&e.jsx("span",{role:"img","aria-label":d.checklist.box.pending,className:`${El} border-fg/25`}),m.text]},x[p])),t.cut&&e.jsx("li",{className:"py-1.5 text-meta text-muted",children:d.checklist.cut})]})]})}function Gn({name:t,legend:s,options:n,value:a,onChange:l,fit:r=!1}){return e.jsxs("fieldset",{className:`m-0 min-w-0 border-0 p-0${r?" self-start":""}`,"data-fit":r||void 0,children:[e.jsx("legend",{className:"sr-only",children:s}),e.jsx("div",{className:`${r?"inline-flex":"grid auto-cols-fr grid-flow-col"} gap-1 rounded-control bg-raised p-1`,children:n.map(i=>e.jsxs("label",{lang:i.lang,className:`flex min-h-10 cursor-pointer items-center justify-center rounded-[9px] ${r?"px-3.5":"px-2"} text-body font-medium text-muted transition-colors duration-100 has-[:checked]:bg-fg has-[:checked]:text-bg has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-info`,children:[e.jsx("input",{type:"radio",name:t,value:i.value,checked:a===i.value,onChange:()=>l(i.value),className:"sr-only"}),i.label]},i.value))})]})}const Jr="model-sheet-title",Zh="flex min-h-12 w-full items-center gap-3 rounded-control border border-line bg-surface px-3 py-2.5 text-left active:bg-raised aria-pressed:border-fg/40 aria-pressed:bg-raised";function Kd({tool:t,models:s,error:n,current:a,pick:l,onPick:r,note:i,actions:o,defaultHint:c=d.model.defaultHint}){var f;const x=!a||a.model===null||s.some(y=>y.id===a.model),u=Fi(t,s,l),m=y=>{const w=Fi(t,s,{model:y});r({model:y,effort:l.effort!==null&&(w!=null&&w.includes(l.effort))?l.effort:null})},p=(y,w,S)=>e.jsxs("button",{type:"button","aria-pressed":l.model===y,onClick:()=>m(y),className:Zh,children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-body font-medium",children:w}),S&&e.jsx("span",{className:"block text-meta text-muted",children:S})]}),(a==null?void 0:a.model)===y&&e.jsx("span",{className:"flex-none rounded-full bg-raised px-2 py-0.5 text-meta text-muted",children:d.model.current})]},y??""),g=u&&(l.effort??((f=s.find(y=>l.model===null?y.isDefault:y.id===l.model))==null?void 0:f.defaultEffort)??"");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("h2",{id:Jr,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:d.model.title}),e.jsx("p",{className:"mt-1 text-meta text-muted",children:d.model.subtitle(d.tools[t]??t)})]}),n&&e.jsx("p",{role:"status",className:"text-meta text-attention",children:d.model.listError}),e.jsxs("div",{className:"flex max-h-[45vh] flex-col gap-1.5 overflow-y-auto",children:[p(null,d.model.byDefault,c),!x&&(a==null?void 0:a.model)!=null&&p(a.model,a.model,void 0),s.map(y=>p(y.id,y.label,rd(t,y)))]}),u&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-body font-medium",children:[d.model.effortTitle," ",e.jsx("span",{className:"text-meta font-normal text-muted",children:d.model.effortHint})]}),e.jsx("div",{className:"mt-2",children:e.jsx(Gn,{name:"model-effort",legend:d.model.effortTitle,value:g??"",onChange:y=>r({model:l.model,effort:y}),options:u.map(y=>({value:y,label:na(y)}))})})]}),i&&e.jsx("p",{className:"text-small whitespace-pre-line text-muted",children:i}),o]})}const Vd={models:[]},Gd=t=>t.modelNext?{model:t.modelNext.model??null,effort:t.modelNext.effort??null}:Ur(t),Js=(t,s)=>!!(t!=null&&t.models)&&s.canSwitch===!0;function Jh({store:t,session:s}){const{daemon:n,models:a,fresh:l}=fe(t),[r,i]=h.useState(!1),o=Js(n,s);if(h.useEffect(()=>{o&&t.requestModels(s.tool)},[o,t,s.tool]),!o)return null;const c=a[s.tool]??Vd,x=s.modelNext?Gd(s):null,u=x??Ur(s),m=[sf(s.tool,u.model??void 0,c.models),u.effort?na(u.effort):null].filter(Boolean).join(" · ");return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:!l,"aria-haspopup":"dialog","aria-label":d.model.chip(x?`${m}, ${d.model.nextTurn}`:m),onClick:()=>{t.requestModels(s.tool),i(!0)},className:`${oc()} gap-2 whitespace-nowrap`,children:[e.jsx("span",{children:m}),x&&e.jsx("span",{className:"text-meta font-normal text-attention",children:d.model.nextTurn})]}),r&&e.jsx(al,{store:t,session:s,onClose:()=>i(!1)})]})}function eg({store:t,session:s}){const{daemon:n,modelFailures:a}=fe(t),l=a[s.id];return!Js(n,s)||!l?null:e.jsx("p",{role:"status",className:"pb-2 text-meta text-attention",children:d.model.failedLine(d.model.failed[l])})}function al({store:t,session:s,onClose:n}){const{models:a}=fe(t),l=a[s.tool]??Vd,r=Ur(s),[i,o]=h.useState(Gd(s)),[c,x]=h.useState(!1),[u,m]=h.useState(null),p=async f=>{x(!0),m(null);const y=await t.changeModel(s.id,f.model,f.effort);if(x(!1),y.status==="applied"){n();return}if(y.status==="expired"){m(d.model.uncertain);return}const w=y.status==="rejected"?y.reason:null;m(w&&w in d.model.failed?d.model.failed[w]:d.model.notApplied)},g=af(s);return e.jsx(ct,{labelledBy:Jr,onClose:n,children:e.jsx(Kd,{tool:s.tool,models:l.models,error:l.error,current:r,pick:i,onPick:o,note:g?d.model.noteWorking(s.name):d.model.noteIdle(s.name),actions:e.jsxs(e.Fragment,{children:[u&&e.jsx("p",{role:"alert",className:"text-meta text-attention",children:u}),s.modelNext&&e.jsx(We,{variant:"outline",disabled:c,onClick:()=>void p(r),children:d.model.cancelPending}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(We,{variant:"ghost",className:"flex-1",onClick:n,children:d.model.cancel}),e.jsx(We,{variant:"primary",className:"flex-[2]",disabled:c||nf(i,r),onClick:()=>void p(i),children:d.model.apply})]})]})})})}const tg=1e4;function Xd(t,s){const n=d.sessions.modelOff;return Js(t,s)?null:s.state==="exited"?n.ended:t!=null&&t.models?n.outside:n.olderPc}function sg(t,s){const n=l=>{var r;return t.rig?((r=l.rig)==null?void 0:r.name)===t.rig.name:!l.rig&&l.project===t.project},a=[...s].filter(l=>n(l)&&l.state!=="exited").map(l=>l.id);return{name:t.rig?d.sessions.rigGroup(t.rig.name):t.project,ids:a}}function qs({icon:t,label:s,why:n,right:a,onClick:l,danger:r=!1}){const i=!l;return e.jsxs("button",{type:"button",disabled:i,onClick:l,className:`flex min-h-12 w-full items-center gap-3 border-b border-line px-3.5 py-2 text-left text-[15px] last:border-b-0 disabled:opacity-60 ${r?"text-danger-fg":"text-fg"}`,children:[e.jsx(F,{name:t,className:`size-5 ${r?"text-danger-fg":"text-muted"}`}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{children:s}),n&&e.jsx("small",{className:"text-small text-muted",children:n})]}),a!=null&&e.jsx("span",{className:"ml-auto flex-none text-[12.5px] text-muted",children:a})]})}const Al=({children:t})=>e.jsx("div",{className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:t});function ei({store:t,session:s,closable:n,closing:a,onClose:l,onModel:r,onCloseSession:i,display:o,lead:c,who:x}){var G,O,D;const u=fe(t),m=Yt(),p=h.useId(),[g,f]=h.useState("menu"),[y,w]=h.useState(!1),S=d.sessions,b=s.name,j=u.fresh,$=[Ja(s,m,1).model,s.effort?na(s.effort):null].filter(Boolean).join(" · "),A=Xd(u.daemon,s),E=(G=u.daemon)!=null&&G.checklist?u.checklists.get(s.id):void 0,k=!!s.pending||s.state==="waiting_permission"||s.state==="waiting_input",T=s.state==="working",C=Object.values(u.ops).filter(J=>J.message.type==="session.interrupt"&&J.message.id===s.id).sort((J,Q)=>J.at.localeCompare(Q.at)).at(-1),I=C!==void 0&&us(C.phase),P=(C==null?void 0:C.phase)==="applied"&&(!T||m-Date.parse(C.at)<tg),L=T&&j&&!k&&!I&&!P,R=d.terminal,M=I||P?null:j?k?R.why.waiting:T?null:R.why.idle:R.why.offline,z=(C==null?void 0:C.phase)==="sending"?R.sending:P?R.sent:R.interrupt(b),U=(C==null?void 0:C.phase)==="rejected"&&C.reason==="read_only"?R.readOnly:y||(C==null?void 0:C.phase)==="rejected"||(C==null?void 0:C.phase)==="failed"?R.fail:null,H=sg(s,u.sessions.values()),V=!!((O=u.daemon)!=null&&O.broadcast)&&H.ids.length>1,ee=x??[s.project,s.branch].filter(Boolean).join(" · ");return e.jsxs(ct,{labelledBy:p,onClose:l,children:[e.jsxs("h2",{id:p,"aria-label":S.sheet.label(b),className:"flex min-w-0 items-center gap-2",children:[e.jsx(fs,{tool:s.tool}),e.jsx("b",{className:"font-semibold whitespace-nowrap",children:b}),ee&&e.jsx("span",{className:"min-w-0 truncate text-small font-normal text-muted",children:ee})]}),g==="plan"&&E?e.jsxs(e.Fragment,{children:[e.jsx(Wd,{checklist:E,...(D=s.checklist)!=null&&D.current?{current:s.checklist.current}:{}}),e.jsx("button",{type:"button",onClick:()=>f("menu"),className:"h-11 rounded-lg border border-input text-body",children:d.nav.back})]}):g==="group"?e.jsx(Rc,{store:t,label:H.name,ids:H.ids,offline:!j,startOpen:!0,onCancel:()=>f("menu")}):e.jsxs(e.Fragment,{children:[c&&c.length>0&&e.jsx(Al,{children:c.map(J=>e.jsx(qs,{icon:J.icon,label:J.label,onClick:J.onClick},J.label))}),e.jsxs(Al,{children:[e.jsx(qs,{icon:"cpu",label:d.model.title,why:A,right:$||null,onClick:A||!j?void 0:r}),o&&e.jsx(qs,{icon:"terminal",label:d.terminal.live2.view,right:o.value,onClick:o.onToggle}),E&&e.jsx(qs,{icon:"list",label:d.checklist.title,right:S.sheet.planCount(E.done,E.total),onClick:()=>f("plan")}),e.jsx(qs,{icon:"stop",label:z,why:U??M,onClick:L?()=>w(!t.interrupt(s.id)):void 0}),V&&e.jsx(qs,{icon:"send",label:S.sheet.writeGroup(H.name),onClick:j?()=>f("group"):void 0})]}),n&&s.state!=="exited"&&e.jsx(Al,{children:e.jsx(qs,{icon:"power",danger:!0,label:a?d.sessionEnd.closingNamed(b):d.sessionEnd.close(b),right:Ct()&&!a?e.jsx("span",{"aria-hidden":"true",children:S.sheet.faceId}):null,onClick:a?void 0:i})}),e.jsx("p",{className:"text-meta text-muted",children:S.sheet.interruptNote})]})]})}const ur=t=>`ledge.mobile.draft.${t}`;function Qd(t,s){var n;try{return((n=Xe(s))==null?void 0:n.getItem(ur(t)))??""}catch{return""}}function Yd(t,s,n){try{const a=Xe(n);s===""?a==null||a.removeItem(ur(t)):a==null||a.setItem(ur(t),s)}catch{}}const Zd="ledge.mobile.draft.cleared",ng=50;function Jd(t){var s;try{const n=JSON.parse(((s=Xe(t))==null?void 0:s.getItem(Zd))??"[]");return Array.isArray(n)?n.filter(a=>typeof a=="string"):[]}catch{return[]}}function ag(t,s){return Jd(s).includes(t)}function lg(t,s){var n;try{const a=Jd(s).filter(l=>l!==t);(n=Xe(s))==null||n.setItem(Zd,JSON.stringify([...a,t].slice(-ng)))}catch{}}let xr=null;const rg=t=>{xr=t};function ig(t){return xr!==t?!1:(xr=null,!0)}function og(t,s,n){const a=Qd(t,n);Yd(t,a.startsWith(s)?a:s+a,n),rg(t)}const cg=["image/png","image/gif","image/jpeg","image/webp"],dg=25e6,ug=[.85,.7,.55,.4],oo=640,xg=.8,mg=[.7,.5],pg={async decode(t){const s=await createImageBitmap(t);let n=null;const a=()=>{n&&(n.width=n.height=0),n=null};return{width:s.width,height:s.height,close:()=>{a(),s.close()},async draw(l,r){a();const i=n=document.createElement("canvas");i.width=l,i.height=r;const o=i.getContext("2d");if(!o)throw new Error("no canvas");return o.imageSmoothingQuality="high",o.drawImage(s,0,0,l,r),{encode:(c,x)=>new Promise((u,m)=>i.toBlob(p=>p?u(p):m(new Error("no blob")),c,x))}}}}},eu=(t,s,n)=>{const a=Math.min(1,n/Math.max(t,s));return{w:Math.max(1,Math.round(t*a)),h:Math.max(1,Math.round(s*a))}};async function tu(t,s){let n=await t.encode("image/webp",s);return n.type==="image/webp"||n.type==="image/jpeg"?{blob:n,mime:n.type}:(n=await t.encode("image/jpeg",s),{blob:n,mime:"image/jpeg"})}const su=t=>new Promise((s,n)=>{const a=new FileReader;a.onload=()=>s(String(a.result).slice(String(a.result).indexOf(",")+1)),a.onerror=()=>n(a.error),a.readAsDataURL(t)});async function fg(t,s=pg){var a;if(!cg.includes(t.type))return{ok:!1,reason:"notImage"};if(t.size>dg)return{ok:!1,reason:"tooLarge"};let n;try{n=await s.decode(t)}catch{return{ok:!1,reason:"unreadable"}}try{let l=Math.min(Cx,Math.max(n.width,n.height));for(;;){const{w:r,h:i}=eu(n.width,n.height,l),o=await n.draw(r,i);for(const c of ug){const{blob:x,mime:u}=await tu(o,c);if(x.size>Mx)continue;const m={mime:u,data:await su(x)},p=await hg(n);return p&&(m.preview=p),{ok:!0,value:{image:m,width:r,height:i,bytes:x.size}}}if(l<=oo)return{ok:!1,reason:"tooLarge"};l=Math.max(oo,Math.round(l*xg))}}catch{return{ok:!1,reason:"unreadable"}}finally{(a=n.close)==null||a.call(n)}}async function hg(t){try{return await gg(t)}catch{return}}async function gg(t){const{w:s,h:n}=eu(t.width,t.height,Ex),a=await t.draw(s,n);for(const l of mg){const{blob:r,mime:i}=await tu(a,l);if(r.size<=Ax)return{mime:i,data:await su(r)}}}function bg(t,s){if(t>=1e6){const n=(Math.round(t/1e5)/10).toFixed(1);return`${s==="fr"?n.replace(".",","):n} ${s==="fr"?"Mo":"MB"}`}return`${Math.round(t/1e3)} ${s==="fr"?"Ko":"KB"}`}function nu({items:t,onRemove:s,size:n,removeLabel:a,lang:l}){return t.length===0?null:e.jsx("div",{"data-attachment-chips":!0,style:{display:"flex",flexWrap:"wrap",gap:8},children:t.map(r=>e.jsxs("div",{"data-chip":r.state,title:r.reason,style:{position:"relative",width:n.w,height:n.h,flexShrink:0,borderRadius:"var(--radius-md)",overflow:"hidden",border:`1px solid ${r.state==="refused"?"var(--danger-text)":"var(--border)"}`,background:"var(--well)"},children:[e.jsx("img",{src:r.url,alt:"",draggable:!1,style:{width:"100%",height:"100%",objectFit:"cover",display:"block",opacity:r.state==="ready"?1:.45}}),r.state==="uploading"&&e.jsx("span",{role:"status","aria-label":"…",style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",style:{color:"var(--foreground)"},children:e.jsx("path",{d:"M12 3a9 9 0 1 1-9 9",opacity:"0.9",children:e.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.9s",repeatCount:"indefinite"})})})}),r.state==="refused"&&e.jsx("span",{style:{position:"absolute",left:0,right:0,bottom:0,padding:"2px 4px",fontSize:10,lineHeight:1.2,color:"var(--danger-text)",background:"var(--status-danger-soft)"},children:r.reason}),r.state!=="refused"&&e.jsx("span",{style:{position:"absolute",left:4,bottom:4,padding:"1px 5px",borderRadius:4,fontSize:10,lineHeight:1.3,color:"#fff",background:"rgba(0,0,0,0.6)"},children:bg(r.bytes,l)}),e.jsx("button",{type:"button","aria-label":a,title:a,onClick:()=>s(r.key),style:{position:"absolute",top:3,right:3,width:20,height:20,padding:0,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:10,border:"none",cursor:"pointer",color:"#fff",background:"rgba(0,0,0,0.6)"},children:e.jsx(yn,{...pn.close,size:12})})]},r.key))})}function jg({url:t,failed:s,width:n,height:a,maxW:l,maxH:r,alt:i,unavailable:o,onOpen:c}){const x=Math.min(1,l/n,r/a),u={width:Math.round(n*x),height:Math.round(a*x),maxWidth:"100%",borderRadius:"var(--radius-lg)",border:"1px solid var(--border)",background:"var(--well)",boxSizing:"border-box",overflow:"hidden"};return s?e.jsx("div",{"data-thumb":"failed",style:{...u,display:"flex",alignItems:"center",justifyContent:"center",padding:8,fontSize:12,color:"var(--muted-foreground)",textAlign:"center"},children:o}):t?e.jsx("button",{type:"button","data-thumb":"ready",onClick:c,style:{...u,padding:0,display:"block",cursor:"zoom-in"},children:e.jsx("img",{src:t,alt:i,draggable:!1,style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})}):e.jsx("div",{"data-thumb":"loading","aria-busy":"true",style:u})}function au({onFiles:t,disabled:s,className:n,children:a}){const l=h.useRef(null);return e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:l,type:"file",accept:"image/*",multiple:!0,hidden:!0,tabIndex:-1,"aria-hidden":"true",onChange:r=>{t([...r.target.files??[]]),r.target.value=""}}),e.jsx("button",{type:"button",disabled:s,"aria-label":a?void 0:d.images.attach,title:d.images.attach,onClick:()=>{var r;return(r=l.current)==null?void 0:r.click()},className:n??$t({variant:"outline",round:!0}),children:a??e.jsx(F,{name:"plus"})})]})}const lu=t=>{var s;return[...((s=t.clipboardData)==null?void 0:s.files)??[]].filter(n=>n.type.startsWith("image/"))},co=44,yg=120,qa=()=>{var t;return((t=globalThis.matchMedia)==null?void 0:t.call(globalThis,"(hover: hover) and (pointer: fine)").matches)===!0};function Ng({id:t,label:s,sendLabel:n,value:a,onChange:l,onSend:r,canSend:i,oneLine:o,images:c,placeholder:x,disabled:u=!1,attachDisabled:m,maxLength:p,invalid:g=!1,describedBy:f,fieldRef:y}){const w=h.useRef(null),S=y??w;h.useLayoutEffect(()=>{const j=S.current;j&&(j.style.height=`${co}px`,j.style.height=`${Math.min(yg,Math.max(co,j.scrollHeight+j.offsetHeight-j.clientHeight))}px`)},[a,S]);const b=m??u;return e.jsxs("div",{className:"flex flex-col gap-2",children:[c.items.length>0&&e.jsx(nu,{items:c.items,onRemove:c.remove,size:{w:72,h:54},removeLabel:d.images.remove,lang:cc}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx(au,{onFiles:c.add,disabled:b}),e.jsx("label",{htmlFor:t,className:"sr-only",children:s}),e.jsx("textarea",{id:t,ref:S,rows:1,value:a,disabled:u,placeholder:x,maxLength:p,enterKeyHint:o?"send":"enter","aria-invalid":g,"aria-describedby":f,onChange:j=>l(j.target.value),onPaste:j=>{const N=lu(j);N.length===0||b||(j.preventDefault(),c.add(N))},onKeyDown:j=>{j.key!=="Enter"||j.nativeEvent.isComposing||!o&&(j.shiftKey||!qa())||(j.preventDefault(),i&&r())},className:"max-h-[120px] min-h-11 min-w-0 flex-1 resize-none rounded-[22px] border border-input bg-surface px-3.5 py-[11px] text-base leading-5 text-fg placeholder:text-muted disabled:opacity-60"}),e.jsx("button",{type:"button",disabled:!i,onClick:r,"aria-label":n,title:n,className:$t({variant:"primary",round:!0}),children:e.jsx(F,{name:"arrowUp"})})]})]})}const kg={anthropic:{d:"M4.709 15.955l4.72-2.647.08-.23-.08-.128H9.2l-.79-.048-2.698-.073-2.339-.097-2.266-.122-.571-.121L0 11.784l.055-.352.48-.321.686.06 1.52.103 2.278.158 1.652.097 2.449.255h.389l.055-.157-.134-.098-.103-.097-2.358-1.596-2.552-1.688-1.336-.972-.724-.491-.364-.462-.158-1.008.656-.722.881.06.225.061.893.686 1.908 1.476 2.491 1.833.365.304.145-.103.019-.073-.164-.274-1.355-2.446-1.446-2.49-.644-1.032-.17-.619a2.97 2.97 0 01-.104-.729L6.283.134 6.696 0l.996.134.42.364.62 1.414 1.002 2.229 1.555 3.03.456.898.243.832.091.255h.158V9.01l.128-1.706.237-2.095.23-2.695.08-.76.376-.91.747-.492.584.28.48.685-.067.444-.286 1.851-.559 2.903-.364 1.942h.212l.243-.242.985-1.306 1.652-2.064.73-.82.85-.904.547-.431h1.033l.76 1.129-.34 1.166-1.064 1.347-.881 1.142-1.264 1.7-.79 1.36.073.11.188-.02 2.856-.606 1.543-.28 1.841-.315.833.388.091.395-.328.807-1.969.486-2.309.462-3.439.813-.042.03.049.061 1.549.146.662.036h1.622l3.02.225.79.522.474.638-.079.485-1.215.62-1.64-.389-3.829-.91-1.312-.329h-.182v.11l1.093 1.068 2.006 1.81 2.509 2.33.127.578-.322.455-.34-.049-2.205-1.657-.851-.747-1.926-1.62h-.128v.17l.444.649 2.345 3.521.122 1.08-.17.353-.608.213-.668-.122-1.374-1.925-1.415-2.167-1.143-1.943-.14.08-.674 7.254-.316.37-.729.28-.607-.461-.322-.747.322-1.476.389-1.924.315-1.53.286-1.9.17-.632-.012-.042-.14.018-1.434 1.967-2.18 2.945-1.726 1.845-.414.164-.717-.37.067-.662.401-.589 2.388-3.036 1.44-1.882.93-1.086-.006-.158h-.055L4.132 18.56l-1.13.146-.487-.456.061-.746.231-.243 1.908-1.312-.006.006z",fill:"#D97757",rule:"nonzero"},openai:{d:"M9.205 8.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357 1.356-.523 2.117-.523 2.854 0 4.662 2.212 4.662 4.566 0 .167 0 .357-.024.547l-4.71-2.759a.797.797 0 00-.856 0l-5.97 3.473zm10.609 8.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473 1.95-1.118a.433.433 0 01.476 0l4.543 2.617c1.309.76 2.189 2.378 2.189 3.948 0 1.808-1.07 3.473-2.76 4.163zM7.802 12.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545 1.95-4.472 4.591-4.472 1 0 1.927.333 2.712.928L8.23 5.067c-.285.166-.428.404-.428.737v6.898zM12 15.128l-2.795-1.57v-3.33L12 8.658l2.795 1.57v3.33L12 15.128zm1.796 7.23c-1 0-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974 1.142c.167.095.238.238.238.428v5.233c0 2.545-1.974 4.472-4.614 4.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482 4.482 0 014.21 6.327v5.423c0 .333.143.571.428.738l5.947 3.449-1.95 1.118a.432.432 0 01-.476 0zm-.262 3.9c-2.688 0-4.662-2.021-4.662-4.519 0-.19.024-.38.047-.57l4.686 2.71c.286.167.571.167.856 0l5.97-3.448v2.26c0 .19-.07.333-.237.428l-4.543 2.616c-.619.357-1.356.523-2.117.523zm5.899 2.83a5.947 5.947 0 005.827-4.756C22.287 18.339 24 15.84 24 13.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498 0-3.401-2.759-5.947-5.946-5.947-.642 0-1.26.095-1.88.31A5.962 5.962 0 0010.205 0a5.947 5.947 0 00-5.827 4.757C1.713 5.447 0 7.945 0 10.49c0 1.666.713 3.283 1.998 4.448-.119.5-.19 1-.19 1.499 0 3.401 2.759 5.946 5.946 5.946.642 0 1.26-.095 1.88-.309a5.96 5.96 0 004.162 1.713z",fill:"currentColor",rule:"evenodd"},cursor:{d:"M22.106 5.68L12.5.135a.998.998 0 00-.998 0L1.893 5.68a.84.84 0 00-.419.726v11.186c0 .3.16.577.42.727l9.607 5.547a.999.999 0 00.998 0l9.608-5.547a.84.84 0 00.42-.727V6.407a.84.84 0 00-.42-.726zm-.603 1.176L12.228 22.92c-.063.108-.228.064-.228-.061V12.34a.59.59 0 00-.295-.51l-9.11-5.26c-.107-.062-.063-.228.062-.228h18.55c.264 0 .428.286.296.514z",fill:"currentColor",rule:"evenodd"}},vg={claude:"anthropic",codex:"openai",cursor:"cursor"};function ru(t,s,n,a=!0){const[l,r]=h.useState({key:"",url:null,failed:!1}),i=s?`${s}|${n}`:"";return h.useEffect(()=>{if(!s||!a)return;let o=!0;return t.imageUrl(s,n).then(c=>{o&&r({key:i,url:c,failed:!1})},()=>{o&&r({key:i,url:null,failed:!0})}),()=>{o=!1}},[t,s,n,a,i]),l.key===i&&i!==""?{url:l.url,failed:l.failed}:{url:null,failed:!1}}const Es=d.images,wg=1,Sg=4,$g=120,Cg=t=>Math.min(Sg,Math.max(wg,t)),Mg={"image/png":"png","image/gif":"gif","image/jpeg":"jpg","image/webp":"webp"};function Eg(t,s,n){const[a,l]=h.useState(null);return h.useEffect(()=>{if(l(null),!t||typeof navigator.canShare!="function"||typeof navigator.share!="function")return;let r=!0;return fetch(t).then(i=>i.blob()).then(i=>{const o=new File([i],s,{type:n});r&&navigator.canShare({files:[o]})&&l(o)},()=>{}),()=>{r=!1}},[t,s,n]),a}function Ag({store:t,refs:s,index:n,onIndex:a,onClose:l}){const r=s[n],{url:i,failed:o}=ru(t,r.id,!1),c=`capture-${n+1}.${Mg[r.mime]??"img"}`,x=Eg(i,c,r.mime),[u,m]=h.useState(1),[p,g]=h.useState(0),f=h.useRef(new Map),y=h.useRef({pinch0:0,scale0:1,y0:0});h.useEffect(()=>{m(1),g(0),f.current.clear()},[n]);const w=()=>{const[T,C]=[...f.current.values()];return T&&C?Math.hypot(T.x-C.x,T.y-C.y):0},S=T=>{var C,I;f.current.set(T.pointerId,{x:T.clientX,y:T.clientY}),(I=(C=T.currentTarget).setPointerCapture)==null||I.call(C,T.pointerId),f.current.size===2?y.current={...y.current,pinch0:w(),scale0:u}:y.current={...y.current,y0:T.clientY}},b=T=>{f.current.has(T.pointerId)&&(f.current.set(T.pointerId,{x:T.clientX,y:T.clientY}),f.current.size===2?y.current.pinch0>0&&m(Cg(y.current.scale0*w()/y.current.pinch0)):u===1&&g(T.clientY-y.current.y0))},j=T=>{if(f.current.delete(T.pointerId)&&f.current.size===0){if(u===1&&Math.abs(p)>$g){l();return}g(0)}},N=h.useRef(null);Td(N,l);const $=()=>{x&&navigator.share({files:[x]}).catch(()=>{})},A=T=>T.stopPropagation(),E="inline-flex min-h-11 items-center rounded-full bg-white/15 px-4 text-body font-medium text-white",k=(T,C,I,P)=>T>=0&&T<s.length&&e.jsx("button",{type:"button","aria-label":C,title:C,onPointerDown:A,onClick:()=>a(T),className:`absolute top-1/2 ${I} grid size-11 -translate-y-1/2 place-items-center rounded-full bg-white/15 text-white`,children:e.jsx("svg",{className:"size-5 fill-none stroke-current [stroke-linecap:round] [stroke-linejoin:round] [stroke-width:1.6]",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:P})})});return Fr.createPortal(e.jsxs("div",{ref:N,role:"dialog","aria-modal":"true","aria-label":Es.view,tabIndex:-1,className:"fixed inset-0 z-50 flex flex-col bg-black/90 text-white outline-none",style:{opacity:p?Math.max(.4,1-Math.abs(p)/400):1},children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("span",{className:"min-w-0 flex-1 text-small text-white/70",children:[r.width,"×",r.height,s.length>1?` · ${n+1}/${s.length}`:""]}),x&&e.jsx("button",{type:"button",onPointerDown:A,onClick:$,className:E,children:Es.share}),i&&e.jsx("a",{href:i,download:c,onPointerDown:A,className:E,children:Es.save}),e.jsx("button",{type:"button","aria-label":Es.close,title:Es.close,onPointerDown:A,onClick:l,className:"grid size-11 place-items-center rounded-full bg-white/15",children:e.jsx("svg",{className:"size-5 fill-none stroke-current [stroke-linecap:round] [stroke-width:1.8]",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M6 6l12 12M18 6 6 18"})})})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1 items-center justify-center overflow-hidden",style:{touchAction:"none"},onPointerDown:S,onPointerMove:b,onPointerUp:j,onPointerCancel:j,children:[i&&e.jsx("img",{src:i,alt:"",draggable:!1,className:"max-h-full max-w-full select-none object-contain",style:{transform:`translateY(${p}px) scale(${u})`,transition:f.current.size?"none":"transform .15s"}}),!i&&e.jsx("p",{role:"status",className:"text-body text-white/70",children:o?Es.unavailable:"…"}),k(n-1,Es.prev,"left-3","m15 18-6-6 6-6"),k(n+1,Es.next,"right-3","m9 18 6-6-6-6")]})]}),document.body)}const uo=d.images;function Tg({store:t,image:s,onOpen:n}){const[a,l]=h.useState(typeof IntersectionObserver>"u"),r=h.useRef(null);h.useEffect(()=>{if(a||!r.current)return;const c=new IntersectionObserver(x=>{x.some(u=>u.isIntersecting)&&(l(!0),c.disconnect())});return c.observe(r.current),()=>c.disconnect()},[a]);const{url:i,failed:o}=ru(t,s.id,!0,a&&s.preview);return s.preview?e.jsx("div",{ref:r,className:"max-w-full",children:e.jsx(jg,{url:i,failed:o,width:s.width,height:s.height,maxW:240,maxH:240,alt:"",unavailable:uo.unavailable,onOpen:n})}):e.jsx("p",{className:"max-w-full rounded-lg border border-line bg-surface p-2.5 text-small text-muted",children:uo.noPreview})}function mr({store:t,refs:s,align:n="start"}){const[a,l]=h.useState(null);return s.length===0?null:e.jsxs("div",{"data-thumbs":!0,className:`flex max-w-full flex-wrap gap-2 ${n==="end"?"justify-end":""}`,children:[s.map((r,i)=>e.jsx(Tg,{store:t,image:r,onOpen:()=>l(i)},`${r.id}:${i}`)),a!==null&&e.jsx(Ag,{store:t,refs:s,index:a,onIndex:l,onClose:()=>l(null)})]})}function _g(t){return!t||t.state==="exited"||t.state==="error"?"stopped":t.state==="waiting_input"||t.state==="waiting_permission"?"waiting":t.state==="idle"&&!t.helpers.some(s=>s.state!=="exited"&&s.state!=="idle")?"yours":"working"}const Ig=new RegExp("(?<code>`[^`\\n]+`)|\\*\\*(?<b>\\S(?:.*?\\S)?)\\*\\*(?!\\*)|(?<![\\w*])\\*(?<i>[^\\s*](?:[^*\\n]*?[^\\s*])?)\\*(?![\\w*])","g"),ti=h.createContext(void 0);function ds(t,s=0,n){let a=0;const l=o=>n?[e.jsx(h.Fragment,{children:n(o)},`t${a++}`)]:[o];if(s>2)return l(t);const r=[];let i=0;for(const o of t.matchAll(Ig)){const c=o.index;c>i&&r.push(...l(t.slice(i,c)));const x=o.groups;x.code?r.push(e.jsx("code",{className:"rounded-md bg-fg/[0.06] px-[5px] py-px font-mono text-[.92em] [overflow-wrap:anywhere]",children:x.code.slice(1,-1)},c)):x.b?r.push(e.jsx("strong",{className:"font-semibold",children:ds(x.b,s+1,n)},c)):r.push(e.jsx("em",{children:ds(x.i,s+1,n)},c)),i=c+o[0].length}return i<t.length&&r.push(...l(t.slice(i))),r}function iu({b:t}){const s=h.useContext(ti);switch(t.type){case"p":return e.jsx("p",{className:"[&+*]:mt-2.5",children:ds(t.text,0,s)});case"code":return e.jsx("pre",{className:"my-2.5 overflow-x-auto rounded-lg bg-well p-2.5 font-mono text-small leading-[1.6] whitespace-pre",children:t.text});case"list":{const n=t.ordered?"ol":"ul";return e.jsx(n,{className:`my-2.5 flex flex-col gap-1 pl-[18px] text-fg/80 ${t.ordered?"list-decimal":"list-disc"}`,children:t.items.map((a,l)=>e.jsxs("li",{children:[a.checked!==void 0&&e.jsx("span",{"aria-hidden":"true",children:a.checked?"☑ ":"☐ "}),ds(a.text,0,s),a.sub.length>0&&e.jsx("ul",{className:"mt-1 flex list-[circle] flex-col gap-1 pl-4",children:a.sub.map((r,i)=>e.jsx("li",{children:ds(r,0,s)},i))})]},l))})}case"table":return e.jsx("div",{className:"my-2.5 overflow-x-auto",tabIndex:0,children:e.jsxs("table",{className:"w-full border-collapse text-small",children:[e.jsx("thead",{children:e.jsx("tr",{children:t.header.map((n,a)=>e.jsx("th",{className:"border-b border-line px-2 py-1.5 font-semibold",style:{textAlign:t.align[a]??"left"},children:ds(n,0,s)},a))})}),e.jsx("tbody",{children:t.rows.map((n,a)=>e.jsx("tr",{children:n.map((l,r)=>e.jsx("td",{className:"border-b border-line px-2 py-1.5 align-top",style:{textAlign:t.align[r]??"left"},children:ds(l,0,s)},r))},a))})]})});case"quote":return e.jsx("blockquote",{className:"my-2.5 border-l-2 border-line pl-3 text-muted",children:t.blocks.map((n,a)=>e.jsx(iu,{b:n},a))})}}function Rg({s:t}){const s=h.useContext(ti),n=t.blocks.map((a,l)=>e.jsx(iu,{b:a},l));return t.kind==="next"?e.jsxs("div",{className:"mt-3 rounded-[10px] border border-info/[0.13] bg-info/[0.03] p-3",children:[e.jsx("div",{className:"mb-1.5 text-meta font-medium tracking-[.5px] text-info uppercase",children:d.thread.suggestion}),n]}):e.jsxs("section",{className:"mt-2.5",children:[t.title&&e.jsx("h3",{className:"mb-1 text-body font-semibold",children:ds(t.title,0,s)}),n]})}function ou({doc:t,plain:s}){return e.jsxs(ti.Provider,{value:s,children:[t.title&&e.jsx("strong",{className:"block text-body font-semibold",children:ds(t.title,0,s)}),t.lead&&e.jsx("p",{className:"mt-1.5",children:ds(t.lead,0,s)}),t.sections.map((n,a)=>e.jsx(Rg,{s:n},a))]})}const Og="text-info underline underline-offset-2",ll=(t,s)=>e.jsx("a",{href:ae({name:"thread",sessionId:t}),className:Og,children:s});function Lg(t){const s=[...t.keys()].filter(Boolean).sort((a,l)=>l.length-a.length);if(s.length===0)return a=>a;const n=new RegExp(`(?<![\\p{L}\\p{N}_])(${s.map(a=>a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")})(?![\\p{L}\\p{N}_])`,"gu");return a=>{const l=[];let r=0;for(const i of a.matchAll(n))i.index>r&&l.push(a.slice(r,i.index)),l.push(e.jsx("span",{children:ll(t.get(i[1]),i[1])},i.index)),r=i.index+i[0].length;return r===0?a:(r<a.length&&l.push(a.slice(r)),l)}}function zg({text:t,names:s}){const n=h.useMemo(()=>Ud(t),[t]),a=h.useMemo(()=>Lg(s),[s]);return e.jsx("div",{className:"px-1 break-words [overflow-wrap:anywhere]",children:e.jsx(ou,{doc:n,plain:a})})}function Dg({names:t,ids:s}){return t.length===0?null:e.jsxs("span",{className:"px-1 text-small text-muted",children:[d.chat.sources,t.map((n,a)=>e.jsxs("span",{children:[a>0&&", ",s.has(n)?ll(s.get(n),n):n]},n))]})}const xo=t=>new Date(t).toLocaleTimeString(dt,{hour:"2-digit",minute:"2-digit"});function cu({store:t,qid:s,at:n,rest:a}){return e.jsxs("p",{className:"flex flex-wrap items-center gap-x-2 px-1 text-small text-muted",children:[a?d.chat.ignoredRest(xo(n)):d.chat.action.ignored(1,xo(n),{done:0,denied:0,failed:0}),e.jsx("button",{type:"button",className:ns,onClick:()=>{t.ignoreTurn(s,!0)},children:d.chat.review})]})}const ia="flex flex-col gap-2.5 rounded-xl border border-line bg-surface p-3.5",ns=De({size:"sm"}),oa=De({variant:"primary",size:"sm"});function Fg({store:t,qid:s,relay:n,target:a,known:l,ignoredAt:r}){const i=a==null?void 0:a.repo,[o,c]=h.useState(null),[x,u]=h.useState(!1),[m,p]=h.useState(null),g=n.status==="sent",f=_g(a!=null&&a.state?{state:a.state,helpers:a.helpers??[]}:void 0),y=n.status==="queued";if((m==="send"&&(g||y)||m==="cancel"&&!y)&&p(null),r!==void 0&&!g&&!y)return e.jsx(cu,{store:t,qid:s,at:r});const w=j=>{u(!0),c(null),(j==="send"?t.relay(s):t.cancelRelay(s)).then($=>{$.status==="applied"?p(j):j==="send"&&c($.status==="rejected"?$.reason??"":"")},()=>{j==="send"&&c("")}).finally(()=>u(!1))},S=o||(n.failed?n.code??"":o),b=g?e.jsxs("p",{role:"status",className:"text-body text-ok",children:[d.chat.sentTo(n.name),l?ll(n.id,d.chat.seeThread):d.chat.seeThread]}):y?e.jsx("p",{role:"status",className:"text-body text-attention",children:d.chat.queued(n.name)}):S!==null?e.jsx("p",{role:"alert",className:"text-body text-danger-fg",children:d.chat.relayFailed(S||void 0)}):null;return e.jsxs("section",{"aria-label":d.chat.relayLabel,className:ia,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("h3",{className:"text-body font-semibold",children:[d.chat.relayHead(n.name),i?` · ${i}`:""]}),!g&&e.jsx("span",{"data-pill":f,className:"shrink-0 rounded-full border border-line px-2 text-small text-muted",children:d.chat.relayPill[f]})]}),e.jsx("p",{className:"whitespace-pre-wrap break-words text-body text-fg/80",children:n.text}),b,y&&e.jsx("div",{className:"flex gap-2",children:e.jsx("button",{type:"button",className:ns,disabled:x||m!==null,onClick:()=>w("cancel"),children:d.chat.relayCancel})}),!g&&!y&&e.jsxs("div",{className:"flex gap-2",children:[m===null&&e.jsx("button",{type:"button",className:ns,disabled:x,onClick:()=>{t.ignoreTurn(s)},children:d.chat.ignore}),e.jsx("button",{type:"button",className:oa,disabled:x||m!==null,onClick:()=>w("send"),children:S!==null?d.chat.relayRetry:d.chat.relayGo})]})]})}const Ce=d.chat.action,Pg=De({size:"sm",className:"border-danger-fg/50 text-danger-fg"}),Bg=De({block:!0,className:"!border-transparent !bg-destructive !text-primary-fg active:opacity-75"});function pr(t){return t.split(/\*\*(.+?)\*\*/g).map((s,n)=>n%2?e.jsx("strong",{className:"font-semibold",children:s},n):e.jsx(h.Fragment,{children:s},n))}const qg=t=>t.replace(/\*\*/g,""),pa=t=>t?new Date(t).toLocaleTimeString(dt,{hour:"2-digit",minute:"2-digit"}):"",si=t=>(t.vars&&t.action!==void 0?Ce.line(t.action,t.vars):void 0)??t.summary,Hg=t=>(t.vars&&t.action==="session.decide"?Ce.line("session.decide",{...t.vars,decision:"deny"}):void 0)??si(t),mo=t=>Ce.why(t.code??(t.state==="failed"?"failed":void 0),t.action,t.vars??{});function po(t){var l,r;const s=t.vars;if(!(s!=null&&s.seats))return;const n=t.action==="rig.seats"?"removed":t.action!=="rig.act"?void 0:(l=s.kind)!=null&&l.endsWith(".restart")?"restart":(r=s.kind)!=null&&r.endsWith(".stop")?"stop":void 0;if(!n)return;const a=Number(s.seatCount)||s.seats.split(", ").length;return Ce.stops(n,a,s.seats,Number(s.seatsMore??0)||0)}const Ug=t=>Ce.verb(t.action,t.vars??{})??(t.action!==void 0?Ce.verbs[t.action]:void 0)??Ce.apply;function Wg({r:t}){const s=t.risk==="destructive";return e.jsxs("span",{className:`inline-flex items-center gap-1 text-small ${s?"font-medium text-danger-fg":"text-muted"}`,children:[s&&e.jsx(F,{name:"warning",className:"size-3.5"}),Ce.risk[t.risk]]})}function fo({s:t,k:s,r:n,last:a}){const l=t==="done"||t==="failed"||t==="refused"||t==="running"?Ce.stepState[t](s):Ce.step(s),r=t==="done"?"border-ok bg-ok text-bg":t==="failed"||t==="refused"?"border-transparent bg-destructive text-primary-fg":n.risk==="destructive"?`border-danger-fg/60 bg-surface text-danger-fg ${t==="held"?"border-dashed":""}`:`border-input bg-surface text-muted ${t==="held"?"border-dashed":""}`;return e.jsxs("div",{className:"relative flex justify-center self-stretch",children:[!a&&e.jsx("span",{"aria-hidden":"true",className:"absolute top-5 -bottom-3 left-1/2 w-px -translate-x-1/2 bg-muted/45"}),e.jsx("span",{role:"img","aria-label":l,className:`relative grid size-5 place-items-center rounded-full border-[1.5px] font-mono text-[11px] ${r}`,children:t==="done"?e.jsx(F,{name:"check",className:"size-3"}):t==="failed"||t==="refused"?e.jsx(F,{name:"close",className:"size-3"}):t==="running"?e.jsx(F,{name:"spinner",className:"size-3 motion-safe:animate-spin"}):s})]})}function ho({r:t,s,whole:n}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"break-words text-body",children:pr(s==="denied"?Hg(t):si(t))}),s!=="denied"&&e.jsx(Wg,{r:t}),n&&po(t)&&e.jsx("p",{className:"mt-1 break-words text-small text-muted",children:po(t)}),t.detail&&e.jsx("p",{className:`mt-1 break-words text-small text-muted ${n||s==="done"?"":"line-clamp-2"}`,children:t.detail}),t.request&&e.jsxs("pre",{className:`mt-1.5 max-h-40 overflow-auto rounded-md border border-line border-l-2 border-l-muted bg-bg px-2.5 py-2 font-mono text-small whitespace-pre-wrap break-words ${s==="stale"?"line-through opacity-60":s==="denied"?"opacity-60":""}`,children:[e.jsx("span",{className:"mb-0.5 block font-sans text-muted",children:Ce.kind[t.request.kind]??t.request.kind}),t.request.text,s==="cut"&&e.jsx("span",{className:"mt-1 block border-t border-dashed border-line pt-1 font-sans text-muted",children:Ce.cutMark})]})]})}function Kg({store:t,qid:s,actions:n,ignoredAt:a,canConfirm:l,readOnly:r=!1}){const[i,o]=h.useState(null),[c,x]=h.useState(new Set),[u,m]=h.useState(null),p=h.useId(),g=n.map(tm),f=g.length>1,{shown:y,stopAt:w}=$i(g),S=y.map((R,M)=>c.has(M)&&(R==="proposed"||R==="held"||R==="failed")?"running":R),b=c.size>0,j=R=>R.some(M=>Ci(n[M])),N=(R,M)=>{x(new Set),M.status==="cancelled"||M.status==="expired"?m({rows:R,text:d.confirm[M.status]}):M.status==="rejected"&&M.reason==="confirm_required"?m({rows:R,text:d.chat.closeSetup}):M.status!=="applied"&&m({rows:R,text:Ce.notSent})},$=(R,M)=>{o(null),m(null),x(new Set(R)),t.act(s,R,M).then(z=>N(R,z),()=>N(R,{status:"failed"}))},A=R=>j(R)?o(R):$(R),E=R=>{t.ignoreTurn(s,R)};if(a!==void 0){const R=M=>S.filter(z=>z===M).length;return e.jsxs("p",{className:"flex flex-wrap items-center gap-x-2 px-1 text-small text-muted",children:[Ce.ignored(g.length,pa(a),{done:R("done"),denied:R("denied"),failed:R("failed")}),!r&&e.jsx("button",{type:"button",className:ns,onClick:()=>E(!0),children:Ce.review})]})}const k=e.jsx("button",{type:"button",className:ns,disabled:b,onClick:()=>E(),children:Ce.ignore}),T=(R,M,z)=>{const U=z.risk==="destructive",H=e.jsxs("button",{type:"button",className:U?Pg:ns,disabled:b||j([M])&&!l,onClick:()=>A([M]),children:[Ug(z),j([M])?"…":""]}),V=z.deny&&e.jsx("button",{type:"button",className:ns,disabled:b,onClick:()=>$([M],{deny:!0}),children:Ce.deny}),ee=n[M].session;if(r&&(R==="proposed"||R==="held"||R==="failed"||R==="cut"||R==="stale"||R==="running"))return e.jsx("span",{className:"text-small text-muted",children:d.chat.history.notApplied});switch(R){case"proposed":case"held":return e.jsxs(e.Fragment,{children:[!f&&R==="proposed"&&k,V,H]});case"running":return e.jsx("span",{className:"text-body text-attention",children:Ce.running});case"done":return e.jsxs("span",{className:"inline-flex items-center gap-1 text-body text-ok",children:[e.jsx(F,{name:"check",className:"size-3.5"}),Ce.done(pa(z.doneAt))]});case"failed":return e.jsxs(e.Fragment,{children:[!f&&k,e.jsx("button",{type:"button",className:ns,disabled:b||j([M])&&!l,onClick:()=>A([M]),children:Ce.retry})]});case"refused":return e.jsx("span",{className:"text-body text-muted",children:Ce.refusedState});case"denied":return e.jsxs("span",{className:"inline-flex items-center gap-1 text-body text-muted",children:[e.jsx(F,{name:"check",className:"size-3.5"}),Ce.denied(pa(z.doneAt))]});case"stale":return ee?e.jsx("a",{className:ns,href:ae({name:"thread",sessionId:ee}),children:Ce.open(z.target??"")}):null;case"cut":return e.jsxs(e.Fragment,{children:[!f&&k,V,e.jsx(Jl,{})]})}},C=(R,M)=>{const z=S[M];return e.jsxs("li",{className:`grid gap-x-2.5 gap-y-1 ${f?"grid-cols-[22px_minmax(0,1fr)]":"grid-cols-1"} ${M>0?"border-t border-line pt-2.5":""}`,children:[f&&e.jsx(fo,{s:z,k:M+1,r:R,last:M===g.length-1}),e.jsxs("div",{className:"min-w-0",children:[e.jsx(ho,{r:R,s:z,whole:!1}),z==="failed"&&e.jsx("p",{role:"alert",className:"mt-1 text-small text-danger-fg",children:pr(Ce.failed(mo(R)))}),z==="refused"&&e.jsx("p",{role:"alert",className:"mt-1 text-small text-danger-fg",children:pr(Ce.refused(mo(R)))}),z==="held"&&e.jsx("p",{className:"mt-1 text-small text-muted",children:Ce.held(w+1)}),z==="stale"&&e.jsx("p",{className:"mt-1 text-small text-attention",children:Ce.stale}),z==="cut"&&e.jsx("p",{className:"mt-1 text-small text-muted",children:Ce.cutNote}),z==="denied"&&e.jsx("p",{className:"mt-1 text-small text-muted",children:Ce.deniedNote(R.target??"")}),e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:T(z,M,R)})]})]},M)},I=()=>{if(!f||r&&!S.every(U=>U==="done"))return null;if(S.every(U=>U==="done")){const U=g.map(H=>H.doneAt).filter(H=>!!H).sort().at(-1);return e.jsxs("p",{className:"inline-flex items-center gap-1.5 text-body text-ok",children:[e.jsx(F,{name:"check",className:"size-3.5"}),Ce.planDone(pa(U))]})}const R=S.indexOf("running");if(R>=0)return e.jsx("button",{type:"button",className:De({variant:"primary",size:"sm",block:!0}),disabled:!0,children:Ce.progress(R+1,g.length)});const M=sm(g);if(!M.rows.length)return null;const z=M.from==="start"?Ce.all(M.rows.length):M.from==="resume"?Ce.resume(w+1,M.rows.length):Ce.skip(w+1,M.rows.length);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[k,e.jsxs("button",{type:"button",className:`${oa} flex-1`,disabled:b||j(M.rows)&&!l,onClick:()=>A(M.rows),children:[z,j(M.rows)?"…":""]})]}),e.jsx("span",{className:"text-small text-muted",children:w>=0?Ce.notReplayed:Ce.inOrder})]})},P=!r&&!l&&$i(g).open.some(R=>Ci(n[R])),L=u&&u.rows.every(R=>(g[R].state??"proposed")==="proposed"||g[R].state==="failed")?u.text:null;return e.jsxs("section",{"aria-label":Ce.label(g.length),"aria-live":"polite",className:ia,children:[e.jsx("ol",{className:"flex flex-col gap-2.5",children:g.map(C)}),I(),L&&e.jsx("p",{role:"status",className:"text-body text-muted",children:L}),P&&e.jsxs("p",{className:"text-body text-attention",children:[d.chat.closeSetup," ",e.jsx("a",{href:ae({name:"connection"}),className:"text-info underline underline-offset-2",children:d.connection.title})]}),i&&e.jsxs(ct,{labelledBy:p,onClose:()=>o(null),children:[e.jsx("h2",{id:p,className:"text-heading leading-[1.3] tracking-[-.5px]",children:i.length>1?Ce.sheet.many(i.length):Ce.sheet.one(qg(si(g[i[0]])))}),e.jsx("ol",{className:"flex flex-col gap-2.5",children:i.map((R,M)=>e.jsxs("li",{className:`grid gap-x-2.5 ${f?"grid-cols-[22px_minmax(0,1fr)]":"grid-cols-1"}`,children:[f&&e.jsx(fo,{s:"proposed",k:R+1,r:g[R],last:M===i.length-1}),e.jsx(ho,{r:g[R],s:"proposed",whole:!0})]},R))}),e.jsxs("p",{className:"text-small leading-[1.6] text-muted",children:[i.length>1?`${Ce.sheet.stops} `:"",d.confirm.note]}),e.jsx("button",{type:"button",className:Bg,onClick:()=>$(i),children:Ct()?d.confirm.goApple:d.confirm.go}),e.jsx("button",{type:"button",className:De({block:!0}),onClick:()=>o(null),children:Ce.sheet.cancel})]})]})}function Vg(t,s,n,a,l){return t.closedAt!==void 0?t.how==="killed"?"killed":"closed":n?"ended":a==="all"||a!=null&&a.has(s)?"closing":t.failed||l?"failed":"open"}function Gg({store:t,qid:s,closes:n,canConfirm:a,sessions:l}){const{ops:r}=fe(t),[i,o]=h.useState(new Set),[c,x]=h.useState(!1),[u,m]=h.useState(null),p=Object.values(r).filter(j=>us(j.phase)).map(j=>j.message).filter(j=>j.type==="chat.relay"||j.type==="chat.launch"||j.type==="chat.close").filter(j=>j.qid===s),g=(()=>{const j=p.filter(N=>N.type==="chat.close");return j.length===0?null:j.some(N=>!N.rows)?"all":new Set(j.flatMap(N=>N.rows??[]))})(),f=c||p.length>0,y=n.map((j,N)=>{const $=l.find(A=>A.id===j.id);return{row:j,i:N,name:($==null?void 0:$.name)??j.name,state:Vg(j,N,!$||!!$.exited,g,i.has(N))}}),w=y.filter(j=>j.state==="open"||j.state==="failed"),S=j=>{x(!0),m(null),o(N=>new Set([...N].filter($=>!j.includes($)))),t.closeSessions(s,j).then(N=>{N.status==="cancelled"||N.status==="expired"?m(N.status):(N.status==="failed"||N.status==="rejected")&&o($=>new Set([...$,...j]))},()=>o(N=>new Set([...N,...j]))).finally(()=>x(!1))},b={closed:d.chat.closed,killed:d.chat.killed,ended:d.chat.ended,closing:d.chat.closing,failed:d.chat.closeFailed,open:""};return e.jsxs("section",{"aria-label":d.chat.closeLabel,"aria-live":"polite",className:ia,children:[e.jsx("ul",{className:"flex flex-col gap-2",children:y.map(({row:j,i:N,name:$,state:A})=>e.jsxs("li",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"min-w-0 flex-1 truncate text-body font-semibold",children:[$," ",e.jsxs("span",{className:"font-normal text-muted",children:["· ",d.tools[j.tool]]})]}),A!=="open"&&e.jsx("span",{className:`text-body ${A==="failed"?"text-danger-fg":A==="closing"?"text-attention":"text-ok"}`,children:b[A]}),(A==="open"||A==="failed")&&e.jsx("button",{type:"button",className:ns,disabled:f||!a,onClick:()=>S([N]),children:d.chat.closeRow})]},N))}),u&&e.jsx("p",{className:"text-body text-muted",children:d.confirm[u]}),w.length>0&&!a&&e.jsxs("p",{className:"text-body text-attention",children:[d.chat.closeSetup," ",e.jsx("a",{href:ae({name:"connection"}),className:"text-info underline underline-offset-2",children:d.connection.title})]}),w.length>=2&&e.jsx("div",{className:"flex gap-2",children:e.jsx("button",{type:"button",className:oa,disabled:f||!a,onClick:()=>S(w.map(j=>j.i)),children:d.chat.closeAll(w.length)})})]})}function Xg({store:t,qid:s,row:n,proposal:a,canConfirm:l,known:r,ignored:i}){const[o,c]=h.useState(null),[x,u]=h.useState(!1),[m,p]=h.useState(!1),g=a.launchedId!==void 0;if(i&&!g)return null;const f=()=>{u(!0),c(null),t.launch(s,[n]).then(w=>{w.status==="applied"?p(!0):w.status==="cancelled"||w.status==="expired"?c(w.status):(w.status==="failed"||w.status==="rejected")&&c("failed")},()=>c("failed")).finally(()=>u(!1))},y=a.failed?"failed":o;return e.jsxs("section",{"aria-label":d.chat.launchLabel,className:ia,children:[e.jsx("h3",{className:"text-body font-semibold",children:d.chat.launchHead(d.tools[a.tool],a.project)}),a.prompt&&e.jsx("p",{className:"whitespace-pre-wrap break-words text-body text-fg/80",children:a.prompt}),g&&e.jsxs("p",{role:"status",className:"text-body text-ok",children:[d.chat.launchedTo,r?ll(a.launchedId,d.chat.seeThread):d.chat.seeThread]}),!g&&y&&e.jsx("p",{role:"status",className:`text-body ${y==="failed"?"text-danger-fg":"text-muted"}`,children:y==="failed"?d.chat.notLaunched:d.confirm[y]}),!g&&!l&&e.jsxs("p",{className:"text-body text-attention",children:[d.chat.launchSetup," ",e.jsx("a",{href:ae({name:"connection"}),className:"text-info underline underline-offset-2",children:d.connection.title})]}),!g&&e.jsxs("div",{className:"flex gap-2",children:[!m&&e.jsx("button",{type:"button",className:ns,disabled:x,onClick:()=>{t.ignoreTurn(s)},children:d.chat.ignore}),e.jsx("button",{type:"button",className:oa,disabled:x||m||!l,onClick:f,children:Ct()?d.confirm.goApple:d.confirm.go})]})]})}function Qg({store:t,qid:s,proposals:n,canConfirm:a,sessionIds:l,ignoredAt:r}){const i=r!==void 0;return e.jsxs(e.Fragment,{children:[n.map((o,c)=>e.jsx(Xg,{store:t,qid:s,row:c,proposal:o,canConfirm:a,known:l.has(o.launchedId??""),ignored:i},c)),i&&n.some(o=>o.launchedId===void 0)&&e.jsx(cu,{store:t,qid:s,at:r,rest:n.some(o=>o.launchedId!==void 0)})]})}function Yg({store:t,qid:s,row:n,task:a}){const[l,r]=h.useState(!1),[i,o]=h.useState(!1),[c,x]=h.useState(!1),u=a.taskId!==void 0,m=()=>{r(!0),o(!1),t.giveTask(s,n).then(p=>{p.status==="applied"?x(!0):o(!0)},()=>o(!0)).finally(()=>r(!1))};return e.jsxs("section",{"aria-label":d.chat.task.label,className:ia,children:[e.jsxs("p",{className:"text-body",children:[e.jsx("span",{className:"font-mono text-agent",children:a.toName??a.to})," · ",e.jsx("span",{className:"font-semibold",children:a.title})]}),a.text&&e.jsx("p",{className:"whitespace-pre-wrap break-words text-body text-fg/80",children:a.text}),u&&e.jsx("p",{role:"status",className:"text-body text-ok",children:d.chat.task.given(a.ownerName??a.toName??a.to,a.taskId,d.chat.point.state[a.state??"open"])}),!u&&(i||a.failed)&&e.jsx("p",{role:"status",className:"text-body text-danger-fg",children:d.chat.task.notGiven}),!u&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("button",{type:"button",className:oa,disabled:l||c,onClick:m,children:d.chat.task.give})})]})}function Zg({store:t,qid:s,tasks:n}){return e.jsx(e.Fragment,{children:n.map((a,l)=>e.jsx(Yg,{store:t,qid:s,row:l,task:a},l))})}const ni="flex flex-col gap-1.5 border-l-2 border-line pl-2.5",go="size-3.5 flex-none fill-none stroke-current [stroke-linecap:round] [stroke-linejoin:round] [stroke-width:1.6]";function Jg(t,s){const n=t.name??t.id??"";switch(t.kind){case"sessions":return d.chat.steps.sessions(s);case"pane":return d.chat.steps.pane(n);case"reply":return d.chat.steps.reply(n);case"git":case"repo":return d.chat.steps.look(n)}}function eb(t){const s=t.filter(n=>n.kind==="pane"||n.kind==="reply").map(n=>n.name??n.id).filter(n=>!!n);return[...new Set(s)]}function tb({steps:t,sessions:s,running:n}){return t.length===0?null:e.jsx("ul",{className:"flex flex-col gap-2 px-1 py-0.5","aria-label":d.chat.stepsLabel,children:t.map((a,l)=>{const r=n&&l===t.length-1;return e.jsxs("li",{className:`flex items-center gap-2 text-small text-muted ${r?"motion-safe:animate-pulse":""}`,children:[r?e.jsx("svg",{className:`${go} motion-safe:animate-spin`,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})}):e.jsx("svg",{className:`${go} text-ok`,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M20 6 9 17l-5-5"})}),Jg(a,s)]},`${l}:${a.kind}:${a.id??""}`)})})}const sb=t=>({busy:d.chat.busy,timeout:d.chat.timeout,failed:d.chat.failed,cancelled:d.chat.cancelled})[t];function bo({store:t,turn:s,live:n,sessions:a,list:l,canConfirm:r,onAskAgain:i,readOnly:o=!1,limits:c,inAnswer:x}){if(s.point)return e.jsx(bh,{store:t,turn:{...s,point:s.point},readOnly:o});const u=(n==null?void 0:n.steps)??s.steps,m=n?n.text:s.answer,p=new Map,g=new Set;for(const y of l)y.name&&(p.has(y.name)?g.add(y.name):p.set(y.name,y.id));for(const y of g)p.delete(y);const f=s.relay;return e.jsxs("div",{className:"flex flex-col gap-3",children:[s.question&&e.jsx("div",{className:"max-w-[85%] self-end whitespace-pre-wrap break-words rounded-[12px_12px_4px_12px] bg-raised px-3 py-2",children:s.question}),s.attachments&&e.jsx("div",{className:"self-end max-w-full",children:e.jsx(mr,{store:t,refs:s.attachments,align:"end"})}),e.jsx(tb,{steps:u,sessions:a,running:!!n&&!n.text}),n&&m&&e.jsx("p",{"aria-live":"polite",className:"px-1 whitespace-pre-wrap break-words",children:m}),!n&&m&&e.jsx(zg,{text:m,names:p}),!n&&s.answer&&e.jsx(Dg,{names:eb(u),ids:p}),!n&&s.answer&&x,!n&&s.answer&&c&&e.jsx(ib,{usage:c.usage,now:Date.now(),alert:c.alert,fresh:c.fresh,at:c.at}),!n&&s.cut&&e.jsx("span",{className:"px-1 text-small text-muted",children:d.chat.cut}),!n&&s.error&&e.jsxs("div",{className:"flex flex-col items-start gap-1.5 px-1",children:[e.jsx("p",{role:"status",className:`text-[13.5px] ${s.error==="cancelled"?"text-muted":s.error==="busy"?"text-attention":"text-danger-fg"}`,children:sb(s.error)}),(s.error==="timeout"||s.error==="failed")&&s.question&&i&&e.jsx("button",{type:"button",onClick:()=>i(s.question),className:Oe({size:"xs"}),children:d.chat.askAgain})]}),!n&&e.jsxs("fieldset",{disabled:o,className:"contents",children:[!n&&s.closes&&e.jsx(Gg,{store:t,qid:s.qid,closes:s.closes,canConfirm:r,sessions:l}),!n&&!s.closes&&f&&e.jsx(Fg,{store:t,qid:s.qid,relay:f,target:l.find(y=>y.id===f.id),known:l.some(y=>y.id===f.id),ignoredAt:s.ignoredAt}),!n&&!s.closes&&s.proposals&&s.proposals.length>0&&e.jsx(Qg,{store:t,qid:s.qid,proposals:s.proposals,canConfirm:r,sessionIds:new Set(l.map(y=>y.id)),ignoredAt:s.ignoredAt}),!n&&s.actions&&e.jsx(Kg,{store:t,qid:s.qid,actions:s.actions,ignoredAt:s.ignoredAt,canConfirm:r,readOnly:o}),!n&&s.tasks&&s.tasks.length>0&&e.jsx(Zg,{store:t,qid:s.qid,tasks:s.tasks})]})]})}function nb({harness:t,size:s=14}){const{d:n,fill:a,rule:l}=kg[vg[t]];return e.jsx("svg",{className:`harness-${t} inline-block flex-none`,width:s,height:s,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:n,fill:a,fillRule:l})})}function ai(t){const s=d.chat.point;switch(t.kind){case"five_hour":return s.five;case"seven_day":return s.week;case"month":return s.month;case"pool":return t.pool==="other"?s.poolOther:s.poolCursor;default:return s.model(t.model??"")}}const ab={"":"",amber:"bg-attention",red:"bg-approval"},li={"":"",amber:"text-attention",red:"text-approval"};function du({pct:t,alert:s}){const n=aa(t,s);return e.jsx("span",{className:"block h-[5px] overflow-hidden rounded-[2px]",style:{background:"var(--u-track)"},children:e.jsx("span",{className:`block h-full rounded-[2px] ${ab[n]}`,style:{width:`${Math.min(100,t)}%`,...n?{}:{background:"var(--u-gauge)"}}})})}function lb({label:t,w:s,now:n,alert:a}){const l=d.chat.point,r=aa(s.pct,a),i=s.resetsAt?Wr(s.resetsAt,n):null;return e.jsxs("div",{className:"grid grid-cols-[58px_1fr_128px] items-center gap-2 py-[3px] text-small",children:[e.jsx("span",{children:t}),e.jsx(du,{pct:s.pct,alert:a}),e.jsxs("span",{className:"truncate font-mono text-[12px]",children:[e.jsx("b",{className:`font-medium ${li[r]}`,children:d.percent(s.pct)}),i&&e.jsx("small",{className:"ml-1.5 text-[11px] text-muted",children:cf(s)?s.resetsAt&&id(s.resetsAt,n)?l.resumesOn(i):l.resumes(i):`↺ ${i}`})]})]})}function rb(t,s){const n=d.chat.point,a=n.harnessShort[t]??t;switch(s.kind){case"five_hour":return`${a} ${n.five}`;case"seven_day":return`${a} ${n.weekShort}`;case"month":return`${a} ${n.monthShort}`;case"model":return`${n.model(s.model??a)} ${n.weekShort}`;default:return null}}function ib({usage:t,now:s,alert:n,fresh:a=!0,at:l}){const r=d.chat.point,i=[],o=[];if(la(t,s,a).forEach((x,u)=>{const m=r.harnessShort[x.harness]??x.harness,p=(w,S)=>i.push({key:x.harness,label:m,sentence:w,amber:S});if(x.status==="loading")return p(r.loading,!1);if(x.status==="expired")return p(r.notOnPc(r.harness[x.harness]??m),!0);const g=t[u];if(g.harness==="cursor"&&g.status==="ok"&&g.windows.length===0&&g.readAt!==null)return p(r.unread,!1);const f=x.status==="stale"||x.status==="unreachable",y=x.windows.flatMap(w=>{const S=rb(x.harness,w);return S?[{key:`${x.harness}:${w.kind}:${w.model??""}`,label:S,w,dim:f}]:[]});if(y.length){i.push(...y),f&&x.readAt&&o.push(Date.parse(x.readAt));return}x.status==="unreachable"&&p(x.readAt?r.unreach(Da(Math.max(0,s-Date.parse(x.readAt)))):r.unreachNever,!0)}),!i.length)return null;const c=Math.min(Date.parse(l),...o);return e.jsxs("div",{role:"group","aria-label":r.limitsLabel,className:ni,children:[e.jsx("div",{className:"flex flex-col",children:i.map(x=>{if("sentence"in x)return e.jsxs("div",{className:"grid grid-cols-[66px_1fr] items-center gap-2 py-0.5 text-[12px]",children:[e.jsx("span",{className:"whitespace-nowrap",children:x.label}),e.jsx("span",{className:x.amber?"text-attention":"text-muted",children:x.sentence})]},x.key);const u=aa(x.w.pct,n);return e.jsxs("div",{className:`grid grid-cols-[66px_1fr_118px] items-center gap-2 py-0.5 text-[12px] ${x.dim?"opacity-50":""}`,children:[e.jsx("span",{className:"whitespace-nowrap",children:x.label}),e.jsx(du,{pct:x.w.pct,alert:n}),e.jsxs("span",{className:"whitespace-nowrap font-mono text-[12px]",children:[e.jsx("b",{className:u?`font-medium ${li[u]}`:"font-normal",children:d.percent(x.w.pct)}),x.w.resetsAt&&e.jsxs("small",{className:"ml-[5px] text-[11px] text-muted",children:["↺ ",Wr(x.w.resetsAt,s,!0)]})]})]},x.key)})}),i.some(x=>"w"in x)&&e.jsx("span",{className:"text-[11.5px] text-muted",children:r.stale(Da(Math.max(0,s-c)))})]})}function ob({usage:t,now:s,alert:n,fresh:a=!0}){const l=d.chat.point,r=la(t,s,a);if(!r.length)return null;const i=o=>t[o].harness==="cursor"&&t[o].status==="ok"&&t[o].windows.length===0&&t[o].readAt!==null;return e.jsxs("div",{role:"group","aria-label":l.limitsLabel,className:"flex flex-col",children:[e.jsx("h3",{className:"mt-1 text-meta tracking-[.4px] text-muted",children:l.limits}),r.map((o,c)=>{const x=o.readAt?Da(s-Date.parse(o.readAt)):null,u=o.status==="stale"||o.status==="unreachable";return e.jsxs("div",{"data-harness":o.harness,className:"flex flex-col",children:[e.jsxs("div",{className:"mt-1.5 mb-0.5 flex items-baseline gap-1.5 text-small font-semibold",children:[e.jsx(nb,{harness:o.harness}),l.harness[o.harness]??o.harness]}),o.status==="loading"&&e.jsx("p",{className:"py-1 text-small text-muted",children:l.loading}),o.status==="expired"&&e.jsx("p",{className:"py-1 text-small text-attention",children:l.notOnPc(l.harness[o.harness]??o.harness)}),o.status==="ok"&&i(c)&&e.jsx("p",{className:"py-1 text-small text-muted",children:l.unread}),o.status!=="loading"&&o.status!=="expired"&&o.windows.length>0&&e.jsx("div",{className:u?"opacity-50":void 0,children:o.windows.map(m=>e.jsx(lb,{label:ai(m),w:m,now:s,alert:n},`${m.kind}:${m.model??m.pool??""}`))}),o.status==="stale"&&x&&e.jsx("p",{className:"py-1 text-small text-attention",children:l.stale(x)}),o.status==="unreachable"&&e.jsx("p",{className:"py-1 text-small text-attention",children:x?l.unreach(x):l.unreachNever})]},o.harness)})]})}const _t=d.thread.rig,cb="inline-flex items-center gap-1 whitespace-nowrap text-small text-muted",db="inline-flex items-center gap-1 whitespace-nowrap text-small font-medium text-fg",uu="mt-1.5 rounded-[6px] border border-line bg-well px-2.5 py-2 font-mono text-meta whitespace-pre-wrap text-muted [overflow-wrap:anywhere]",rl=()=>e.jsx("div",{className:"text-meta text-muted",children:d.thread.cut});function ub({session:t}){const s=en(),n=t.state==="exited"?"done":t.state==="waiting_input"?"question":t.state==="waiting_permission"?"approval":t.state;return e.jsx("span",{className:"inline-flex flex-none","aria-hidden":"true",children:e.jsx(Qa,{tool:t.tool,seed:t.id,state:n,pose:Xa(t.id,n),size:16,theme:s,frozen:!0})})}function xb({lead:t,who:s,children:n}){return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 text-meta leading-5 font-medium text-muted",children:[e.jsx("span",{children:t}),s.session&&e.jsx(ub,{session:s.session}),e.jsx("strong",{className:"font-semibold text-fg",children:s.name}),s.seat&&e.jsx("span",{className:"font-mono font-normal",children:s.seat}),n]})}function ca(t){const[s,n]=h.useState(!1),a=t&&e.jsx("button",{type:"button","aria-expanded":s,onClick:()=>n(r=>!r),className:cb,children:t.label}),l=t&&s&&e.jsx("pre",{className:uu,children:t.text});return{toggle:a,box:l}}function mb({e:t,storage:s}){const{toggle:n,box:a}=ca(t.raw),l=t.dir==="out",r=t.delivery&&_t.sent[t.delivery];return e.jsxs("div",{className:`flex flex-col gap-1 ${l?"items-end":"items-start"}`,children:[e.jsxs("article",{"aria-label":l?`${_t.to} ${t.who.name}`:`${_t.from} ${t.who.name}`,className:`flex max-w-[92%] min-w-0 flex-col gap-1 px-3.5 py-2.5 ${l?"rounded-2xl rounded-br-[4px] bg-raised":"rounded-2xl rounded-bl-[4px] border border-line bg-surface"}`,children:[e.jsxs(xb,{lead:l?_t.to:_t.from,who:t.who,children:[t.count&&e.jsx("span",{className:"inline-flex h-[18px] items-center rounded-full bg-attention/12 px-1.5 text-[10.5px] text-attention",children:_t.twice(t.count)}),l&&r&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:t.delivery==="failed"?"text-attention":"",children:r})]})]}),e.jsx("div",{className:"text-body whitespace-pre-wrap [overflow-wrap:anywhere]",children:t.text}),(t.reply||n)&&e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-3",children:[t.reply&&e.jsxs("a",{href:ae({name:"thread",sessionId:t.reply.sessionId}),onClick:()=>og(t.reply.sessionId,t.reply.draft,s),"aria-label":_t.replyTo(t.who.name),className:db,children:[e.jsx(F,{name:"reply",className:"size-3.5"}),_t.reply]}),n]}),a]}),t.cut&&e.jsx(rl,{})]})}const jo="inline-flex h-5 items-center rounded-full px-2 text-meta font-medium whitespace-nowrap",pb={pending:"bg-raised text-muted",taken:"bg-[var(--status-info-soft)] text-info",passed:"bg-task/14 text-task",blocked:"bg-[var(--status-warning-soft)] text-attention",done:"bg-[var(--status-success-soft)] text-ok",unknown:"border border-dashed border-line text-muted"};function fb(t){const[s,n]=h.useState(typeof IntersectionObserver>"u");return h.useEffect(()=>{const a=t.current;if(!a||typeof IntersectionObserver>"u")return;const l=new IntersectionObserver(r=>n(r.some(i=>i.isIntersecting)));return l.observe(a),()=>l.disconnect()},[t]),s}function hb(t,s,n){var i,o;const a=fe(t),l=((i=a.daemon)==null?void 0:i.rigRows)===!0,r=!!s&&n&&l&&a.fresh;return h.useEffect(()=>{if(!r)return;t.requestRigRow(s);const c=setInterval(()=>t.requestRigRow(s),Tx);return()=>clearInterval(c)},[r,t,s]),s&&l?(o=a.rigRows[s])==null?void 0:o.row:void 0}function gb({e:t,store:s}){const{toggle:n,box:a}=ca(t.raw),l=h.useRef(null),r=fb(l),i=hb(s,t.qitem,r),o=t.refused?null:Wp(i,t.outgoing),c=t.refused?t.refused.log:o==null?void 0:o.log;return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("section",{ref:l,"aria-label":t.outgoing?_t.rowOut(t.who.name):_t.rowIn(t.who.name),className:"flex w-full flex-col gap-1.5 rounded-[10px] border border-l-[3px] border-task/35 border-l-task bg-surface px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-small font-medium text-task",children:[e.jsx(F,{name:"task",className:"size-3.5"}),e.jsx("span",{className:"min-w-0 truncate",children:t.outgoing?_t.rowOut(t.who.name):_t.rowIn(t.who.name)}),e.jsx("span",{className:"flex-1"}),o?e.jsx("span",{"data-state":o.key,className:`${jo} ${pb[o.key]}`,children:o.text}):e.jsx("span",{"data-state":"refused",className:`${jo} bg-danger-bg text-danger-fg`,children:_t.rowState.refused})]}),e.jsx("h4",{className:"line-clamp-2 text-[0.90625rem] leading-[1.3125rem] font-semibold [overflow-wrap:anywhere]",children:t.title}),c&&e.jsx("p",{className:"text-small text-muted [overflow-wrap:anywhere]",children:c}),n&&e.jsxs("div",{className:"flex items-center border-t border-dashed border-line pt-1.5",children:[e.jsx("span",{className:"flex-1"}),n]}),a]}),t.cut&&e.jsx(rl,{})]})}function xu({e:t}){const{toggle:s,box:n}=ca(t.raw),a=t.tone==="warn"?"border-l-attention":t.tone==="task"?"border-l-task":"border-l-line";return e.jsxs("div",{role:"note",className:`min-w-0 border-l-2 ${a} py-0.5 pl-2.5 text-small leading-5 text-muted`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:`text-[10px] font-medium tracking-[.04em] uppercase ${t.tone==="task"?"text-task":""}`,children:_t.openrig}),e.jsx("span",{className:`min-w-0 font-medium [overflow-wrap:anywhere] ${t.tone==="warn"?"text-attention":"text-fg"}`,children:t.title}),e.jsx("span",{className:"flex-1"}),s]}),n,t.cut&&e.jsx(rl,{})]})}function bb({e:t}){const[s,n]=h.useState(!1);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("button",{type:"button","aria-expanded":s,onClick:()=>n(a=>!a),className:"flex items-center gap-1.5 py-0.5 text-left text-small text-muted",children:[e.jsx("span",{className:`inline-flex transition-transform motion-reduce:transition-none ${s?"rotate-90":""}`,children:e.jsx(F,{name:"chevron",className:"size-3.5"})}),e.jsx("strong",{className:"font-medium text-fg",children:_t.folded(t.notices.length)})]}),s&&t.notices.map(a=>e.jsx(xu,{e:a},a.key))]})}function jb({e:t}){return e.jsxs("div",{className:"flex flex-col gap-1 border-l-2 border-dashed border-line pl-2.5",children:[e.jsx("div",{className:"text-meta leading-5 font-medium text-muted",children:_t.unreadable}),e.jsx("pre",{className:uu.replace("mt-1.5 ",""),children:t.text}),t.cut&&e.jsx(rl,{})]})}function yb({e:t}){const{toggle:s,box:n}=ca(t.raw);return e.jsxs("div",{className:"-mt-2 flex flex-col items-start",children:[s,n&&e.jsx("div",{className:"w-full",children:n})]})}function Nb({e:t,storage:s,store:n}){switch(t.kind){case"rig-message":return e.jsx(mb,{e:t,storage:s});case"rig-task":return e.jsx(gb,{e:t,store:n});case"rig-notice":return e.jsx(xu,{e:t});case"rig-fold":return e.jsx(bb,{e:t});case"rig-unreadable":return e.jsx(jb,{e:t});case"rig-raw":return e.jsx(yb,{e:t})}}const Ns=d.thread.task,kb={killed:{tone:"attention",text:"text-attention",icon:"stop"},completed:{tone:"ok",text:"text-ok",icon:"check"},failed:{tone:"danger",text:"text-danger-fg",icon:"close"},other:{tone:"muted",text:"text-muted",icon:"task"}};function vb({task:t,cut:s}){const{toggle:n,box:a}=ca({label:Ns.raw,text:t.raw}),l=kb[t.status],r=Ns.statuses[t.status],{about:i}=t,o=(i==null?void 0:i.kind)==="command"?i.code:void 0,c=[o!==void 0?Ns.code(o):null,t.output??null].filter(Boolean).join(" · ");return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("section",{"aria-label":Ns.label(r),"data-status":t.status,className:"flex w-full flex-col gap-1.5 rounded-[10px] border border-line bg-surface px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(F,{name:l.icon,className:`size-3.5 ${l.text}`}),e.jsx("span",{className:"text-meta font-medium tracking-[.04em] text-muted uppercase",children:Ns.kicker}),e.jsx("span",{className:"flex-1"}),e.jsx(ta,{tone:l.tone,label:r})]}),e.jsx("p",{className:"text-body [overflow-wrap:anywhere]",children:(i==null?void 0:i.kind)==="agent"?e.jsxs(e.Fragment,{children:[Ns.agent," ",e.jsx("strong",{className:"font-semibold",children:i.name})," ",Ns.agentDid[t.status]]}):(i==null?void 0:i.kind)==="command"?e.jsxs(e.Fragment,{children:[Ns.command," ",e.jsx("code",{className:"rounded-[4px] bg-fg/[0.05] px-1 font-mono text-[.9em]",children:i.command})," ",Ns.commandDid[t.status]]}):t.summary}),c&&e.jsx("p",{className:"font-mono text-meta text-muted [overflow-wrap:anywhere]",children:c}),e.jsxs("div",{className:"flex items-center border-t border-dashed border-line pt-1.5",children:[e.jsx("span",{className:"flex-1"}),n]}),a]}),s&&e.jsx("div",{className:"text-meta text-muted",children:d.thread.cut})]})}const dn=d.images;let wb=0;const Sb=t=>`data:${t.mime};base64,${t.data}`;function mu(t){const[s,n]=h.useState([]),[a,l]=h.useState(0),[r,i]=h.useState(null),o=h.useRef([]),c=h.useRef(0),x=h.useRef(!0);h.useEffect(()=>(x.current=!0,()=>{x.current=!1}),[]);const u=j=>{o.current=j,n(j)},m=(j,N)=>{x.current&&u(o.current.map($=>$.item.key===j?{...$,...N,item:{...$.item,...N.item}}:$))},p=j=>{c.current+=j,l(c.current)},g=async j=>{const N=await fg(j);if(p(-1),!x.current)return;if(!N.ok){i(N.reason==="tooLarge"?dn.tooLarge:dn.notImage);return}const{image:$,width:A,height:E,bytes:k}=N.value,T=`att-${wb++}`;u([...o.current,{item:{key:T,url:Sb($.preview??$),width:A,height:E,bytes:k,state:"uploading"}}]);try{const C=await t.putImage($);m(T,{id:C.id,item:{state:"ready"}})}catch(C){const I=C instanceof Error&&C.message==="too_large"?dn.tooLarge:C instanceof Error&&C.message==="not_image"?dn.notImage:dn.failed;m(T,{item:{state:"refused",reason:I}}),x.current&&i(I)}},f=j=>{if(j.length!==0){i(null);for(const N of j){if(o.current.length+c.current>=yi){i(dn.max);return}p(1),g(N)}}},y=j=>{const N=o.current.find($=>$.item.key===j);u(o.current.filter($=>$.item.key!==j)),(N==null?void 0:N.item.state)==="refused"&&i(null)},w=()=>{const j=o.current;return u([]),i(null),j},S=j=>{x.current&&u([...j,...o.current].slice(0,yi))},b=s.map(j=>j.item);return{items:b,add:f,remove:y,clear:w,putBack:S,error:r,ready:a===0&&b.every(j=>j.state==="ready"),ids:()=>o.current.filter(j=>j.item.state==="ready"&&j.id).map(j=>j.id)}}const pu=`${$s}launch.started`;function fu(t){var s;try{const n=JSON.parse(((s=Xe(t))==null?void 0:s.getItem(pu))??"[]");return Array.isArray(n)?n.filter(a=>typeof(a==null?void 0:a.id)=="string"&&typeof(a==null?void 0:a.project)=="string"):[]}catch{return[]}}function $b(t,s,n){var l;const a=[...fu(n).filter(r=>r.id!==t),{id:t,project:s}].slice(-50);try{(l=Xe(n))==null||l.setItem(pu,JSON.stringify(a))}catch{}}const Cb=(t,s)=>{var n;return((n=fu(s).find(a=>a.id===t))==null?void 0:n.project)??null};function Mb(t){const s=/^\/(\S*)$/.exec(t);return s?s[1].toLowerCase():null}function Eb(t,s){var l;const n=s.toLowerCase(),a=[];for(const r of t){const i=[r.name,...r.aliases??[]],o=i.map(f=>f.toLowerCase());let c=-1,x=r.name,u=-1;const m=o.indexOf(n),p=o.findIndex(f=>f.startsWith(n)),g=o.findIndex(f=>f.includes(n));m>=0&&n?(c=0,x=i[m],u=0):p>=0?(c=1,x=i[p],u=0):g>=0?(c=2,x=i[g],u=o[g].indexOf(n)):(l=r.description)!=null&&l.toLowerCase().includes(n)&&(c=3),!(c<0)&&(x!==r.name&&r.name.toLowerCase().startsWith(n)&&(x=r.name,u=0),a.push({command:r,shown:x,at:n?u:-1,rank:c}))}return a.sort((r,i)=>r.rank-i.rank||+!!r.command.blocked-+!!i.command.blocked||r.shown.localeCompare(i.shown)).map(({rank:r,...i})=>i)}function Ab(t,s){const n=/^\/(\S+)/.exec(t.trimStart());if(!n)return;const a=n[1].toLowerCase();return s.find(l=>{var r;return l.name.toLowerCase()===a||((r=l.aliases)==null?void 0:r.some(i=>i.toLowerCase()===a))})}const Tb=t=>`/${t.name} `,Hs=d.thread.slash;function _b({listing:t,query:s,matches:n,tool:a,name:l,onPick:r}){const i="mb-2 overflow-hidden rounded-2xl border border-line bg-surface";return t?t.error?e.jsx("div",{className:`${i} px-3 py-3 text-meta text-muted`,role:"status",children:Hs.unavailable(l)}):n.length===0?e.jsx("div",{className:`${i} px-3 py-3 text-meta text-muted`,role:"status",children:Hs.none(`/${s}`,l)}):e.jsxs("div",{className:i,children:[e.jsx("p",{className:"px-3 pt-2 pb-1 text-meta text-muted",children:Hs.count(a,n.length)}),e.jsx("ul",{"aria-label":Hs.label(a),className:"max-h-[300px] overflow-y-auto overscroll-contain px-1 pb-1",children:n.map(o=>{const c=o.command,x=c.blocked!==void 0,u=s.length,m=Hs.source[c.source];return e.jsx("li",{className:"border-t border-line first:border-t-0",children:e.jsxs("button",{type:"button",disabled:x,onMouseDown:p=>p.preventDefault(),onClick:()=>r(c),className:"flex min-h-[52px] w-full flex-col justify-center rounded-[10px] px-2.5 py-1.5 text-left enabled:active:bg-raised",children:[e.jsxs("span",{className:`font-mono text-[14px] leading-5 ${x?"text-muted":""}`,children:["/",o.at>=0&&u>0?e.jsxs(e.Fragment,{children:[o.shown.slice(0,o.at),e.jsx("mark",{className:"bg-transparent font-semibold text-fg underline underline-offset-2",children:o.shown.slice(o.at,o.at+u)}),o.shown.slice(o.at+u)]}):o.shown,c.argumentHint&&e.jsxs("span",{className:"text-[12px] text-muted",children:[" ",c.argumentHint]}),m&&e.jsx("span",{className:`ml-1.5 font-sans text-[10.5px] ${c.source==="project"?"text-info":"text-muted"}`,children:m})]}),e.jsx("span",{className:`truncate text-[12px] leading-4 ${x?"text-attention":"text-muted"}`,children:x?Hs.blocked[c.blocked]:c.description})]})},c.name)})})]}):e.jsx("div",{className:`${i} px-3 py-3 text-meta text-muted`,role:"status",children:Hs.loading(a)})}const Ib={ok:"text-ok",info:"text-info",approval:"text-approval",attention:"text-attention",muted:"text-muted"},Tt=d.thread.composer;function hu(t){const s=t.trim();return s.length>Qn?"long":rc.test(s)?"untypable":null}function Rb(t){if(t.phase==="uncertain"||t.reason==="not_taken")return{title:Tt.uncertainTitle,body:Tt.uncertain};const s=t.reason==="busy"?Tt.busy:t.reason==="invalid"?Tt.invalid(Qn):t.reason==="untypable"?Tt.untypable:t.reason==="read_only"?Tt.readOnly:t.reason==="attachment_missing"?Tt.imageGone:t.reason==="attachments_not_accepted"?d.images.dialog:Tt.lost;return{title:Tt.failTitle,body:s}}function Ob({name:t,focusAtEnd:s=!1,composer:n,draft:a,onDraft:l,onSend:r,fresh:i,taken:o,checking:c,error:x,alert:u,onReconnect:m,images:p,dialog:g,lead:f,leadNote:y,slash:w}){var M,z;const[S,b]=Sn(),j=o?{tone:"ok",label:Tt.status.taken}:c?{tone:"muted",label:d.decide.checking}:n.status,N=hu(a),$=h.useRef(null),A=p.items.length>0;h.useEffect(()=>{const U=$.current;!s||!U||(U.focus(),U.setSelectionRange(U.value.length,U.value.length))},[]);const E=w&&n.enabled&&!g?Mb(a):null,k=E!==null;h.useEffect(()=>{k&&(w==null||w.ask())},[k]);const T=(M=w==null?void 0:w.listing)!=null&&M.error?[]:((z=w==null?void 0:w.listing)==null?void 0:z.commands)??[],C=h.useMemo(()=>E!==null?Eb(T,E):[],[E,T]),I=w&&!g?Ab(a,T):void 0,P=U=>{var H;l(Tb(U)),(H=$.current)==null||H.focus()},L=!I||E!==null?null:I.blocked?{warn:!0,text:d.thread.slash.blocked[I.blocked]}:I.bare&&/^\/\S+\s*$/.test(a)?{warn:!0,text:d.thread.slash.bare(I.name)}:I.argumentHint?{warn:!1,text:`/${I.name} ${I.argumentHint}`}:null,R=n.enabled&&(!!a.trim()||A)&&N===null&&p.ready&&!(A&&g);return e.jsxs("footer",{className:"flex-none border-t border-line bg-bg pt-2 pb-3 [@media(max-height:650px)]:pb-2",children:[e.jsxs("div",{className:`flex items-center gap-1.5 pb-2 text-meta ${Ib[j.tone]}`,children:[e.jsx("i",{className:"inline-block size-1.5 flex-none rounded-full bg-current"}),j.label]}),u&&e.jsx("div",{className:"mb-2.5",children:u}),!u&&x&&e.jsx("div",{className:"mb-2.5",children:e.jsxs(Ve,{title:x.title,tone:"warning",role:"alert",children:[e.jsx("p",{children:x.body}),!i&&m&&e.jsx("button",{type:"button",disabled:S,onClick:()=>{b(!0),m()},className:De({block:!0,className:"mt-2"}),children:S?d.link.reconnecting:Tt.reconnect})]})}),k&&e.jsx(_b,{listing:w.listing,query:E,matches:C,tool:w.tool,name:t,onPick:P}),!k&&(n.enabled||f)&&e.jsxs("div",{role:"group","aria-label":Tt.quickLabel,className:"flex gap-1.5 overflow-x-auto pb-2 [scrollbar-width:none]",children:[f,n.enabled&&Jp.map(U=>e.jsx("button",{type:"button",onClick:()=>{var H;l(U),(H=$.current)==null||H.focus()},className:`${oc()} whitespace-nowrap`,children:U},U))]}),y,e.jsx(Ng,{id:"draft",label:Tt.label(t),sendLabel:Tt.send(t),value:a,onChange:l,onSend:r,canSend:R,oneLine:!0,images:p,placeholder:n.placeholder,disabled:!n.enabled,fieldRef:$,invalid:N!==null,describedBy:N?"draft-problem":void 0}),L&&e.jsx("p",{role:"status",className:`pt-1.5 text-meta ${L.warn?"text-attention":"font-mono text-muted"}`,children:L.text}),A&&g&&e.jsx("p",{role:"status",className:"pt-1.5 text-meta text-attention",children:d.images.dialog}),p.error&&e.jsx("p",{role:"alert",className:"pt-1.5 text-meta text-attention",children:p.error}),N&&e.jsx("p",{id:"draft-problem",role:"status",className:"pt-1.5 text-meta text-attention",children:N==="long"?Tt.tooLong(Qn):Tt.untypable})]})}const Be=d.sessionEnd,_n=t=>De({variant:t,block:!0});function gu(t,s,n,a,l){const[r,i]=h.useState(null),[o,c]=h.useState(null),[x,u]=h.useState(!1),[m,p]=h.useState(0),g=h.useRef(!0);return h.useEffect(()=>(g.current=!0,()=>{g.current=!1}),[]),h.useEffect(()=>{if(!a)return;let S=!0,b;return i(null),t.prepareConfirm(s==="terminal"?{purpose:s,id:n}:{purpose:s,id:n}).then(j=>{S&&(i(j),b=setTimeout(()=>{S&&(i(null),c("expired"))},j.expiresInMs))},()=>{S&&c("prepareFailed")}),()=>{S=!1,clearTimeout(b)}},[t,s,n,a,m]),{challenge:r,problem:o,asking:x,needsNew:o==="expired"||o==="failed"||o==="prepareFailed",go:async()=>{if(!a||x||!r)return;if(!r.credentialId){i(null),c("failed");return}u(!0),c(null);const S=await Yn({challenge:r.challenge,rpId:r.rpId,credentialId:r.credentialId}).catch(()=>"failed");if(g.current){if(u(!1),S==="cancelled"){c("cancelled");return}if(S==="failed"){i(null),c("failed");return}i(null),l(S)===null&&c("failed")}},retry:()=>{c(null),p(S=>S+1)}}}function ri({store:t,session:s,mode:n,onClose:a,onSent:l,onReconnect:r}){const{fresh:i,device:o}=fe(t),[c,x]=Sn(),u=s.name,m=n==="close",p=!!(o!=null&&o.confirm),g=gu(t,m?"close":"act",s.id,i&&p,S=>{const b=m?t.sessionClose(s.id,S):t.sessionResume(s.id,S);return b!==null&&l(),b}),f=m?nm(s):[],y=g.asking?d.confirm.asking:g.challenge?m?Ct()?Be.goCloseApple:Be.goClose:Ct()?Be.goResumeApple:Be.goResume:d.confirm.preparing,w=e.jsx("button",{type:"button",onClick:a,className:_n(),children:Be.cancel});return e.jsxs(ct,{labelledBy:"end-title",onClose:a,children:[e.jsx("h2",{id:"end-title",className:"text-heading leading-[1.3] tracking-[-.5px]",children:m?Be.closeTitle(u):Be.resumeTitle(u)}),i?p?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:m?Be.closeBody:Be.resumeBody}),f.length>0&&e.jsx(Ve,{title:Be.cutsTitle,tone:"warning",children:e.jsx("ul",{className:"flex list-disc flex-col gap-1 pl-5",children:f.map(S=>e.jsx("li",{children:S},S))})}),g.problem&&e.jsx(Ve,{title:d.confirm[g.problem],tone:"warning",role:"alert"}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:f.length>0?`${Be.force} ${Be.check}`:Be.check}),g.needsNew?e.jsx("button",{type:"button",onClick:g.retry,className:_n("primary"),children:d.confirm.retry}):e.jsx("button",{type:"button",disabled:g.asking||!g.challenge,onClick:()=>{g.go()},className:_n("primary"),children:y}),w]}):e.jsxs(e.Fragment,{children:[e.jsx(Ve,{title:Be.unprotectedTitle,tone:"warning",role:"status",children:e.jsx("p",{children:m?Be.unprotectedClose(u):Be.unprotectedResume(u)})}),e.jsx("a",{href:ae({name:"connection"}),className:_n("primary"),children:Be.openConnection}),w]}):e.jsxs(e.Fragment,{children:[e.jsx(Ve,{title:Be.offlineTitle,tone:"warning",role:"status",children:e.jsx("p",{children:m?Be.offlineClose(u):Be.offlineResume(u)})}),r&&e.jsx("button",{type:"button",disabled:c,onClick:()=>{x(!0),r()},className:_n("primary"),children:c?d.link.reconnecting:Be.reconnect}),w]})]})}function yo({tone:t,label:s}){return e.jsxs("div",{className:`flex items-center gap-1.5 text-meta ${t==="attention"?"text-attention":"text-info"}`,children:[e.jsx(F,{name:"spinner",className:"size-3 animate-spin motion-reduce:animate-none",stroke:2}),s]})}function bu({error:t,fresh:s,onRetry:n,onReconnect:a}){const[l,r]=Sn();return e.jsxs(Ve,{title:t.title,tone:"warning",role:"alert",children:[e.jsx("p",{children:t.body}),t.retry&&e.jsx("button",{type:"button",onClick:n,className:De({size:"sm",className:"mt-2"}),children:Be.retry}),t.reconnect&&!s&&a&&e.jsx("button",{type:"button",disabled:l,onClick:()=>{r(!0),a()},className:De({size:"sm",className:"mt-2"}),children:l?d.link.reconnecting:Be.reconnect})]})}function Lb({ending:t,name:s,canResume:n,resumeHeld:a=!1,readOnly:l,fresh:r,focus:i,onResume:o,onReconnect:c}){const x=h.useRef(null);return h.useEffect(()=>{var u;i&&((u=x.current)==null||u.focus({preventScroll:!0}))},[i]),e.jsxs("footer",{ref:x,tabIndex:-1,role:"status",className:"flex flex-none flex-col gap-2.5 border-t border-line bg-bg pt-3 pb-3 outline-none [@media(max-height:650px)]:pb-2",children:[t.kind==="closing"&&e.jsxs(e.Fragment,{children:[e.jsx(yo,{tone:"attention",label:Be.closing(s)}),e.jsx("p",{className:"text-small text-muted",children:Be.closingHint})]}),t.kind==="resuming"&&e.jsx(yo,{tone:"info",label:Be.resuming(s)}),t.kind==="ended"&&e.jsxs(e.Fragment,{children:[t.error&&e.jsx(bu,{error:t.error,fresh:r,onRetry:o,onReconnect:c}),e.jsxs("section",{"aria-labelledby":"ended-title",className:"flex flex-col gap-2.5 rounded-card border border-line bg-surface p-4",children:[e.jsx("h2",{id:"ended-title",className:"text-body font-semibold",children:Be.ended}),t.killed?e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:Be.killed}):!l&&e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:n?Be.endedBody:Be.endedOnPc}),n&&!l&&e.jsxs("button",{type:"button","aria-disabled":a||void 0,onClick:()=>{a||o()},className:De({variant:t.killed?"outline":"primary",block:!0,className:a?"opacity-45":""}),children:[e.jsx(F,{name:"resume"}),Be.resume(s)]})]})]})]})}function zb({text:t}){const s=h.useMemo(()=>Ud(t),[t]);return e.jsx(ou,{doc:s})}const No=({align:t})=>e.jsx("div",{className:`text-meta text-muted ${t==="end"?"text-right":""}`,children:d.thread.cut}),ko={success:{glyph:"✓",tone:"text-ok"},running:{glyph:"●",tone:"text-info"},failed:{glyph:"✕",tone:"text-danger-fg"},unknown:{glyph:"·",tone:"text-muted"}};function Db({tools:t}){const[s,n]=h.useState(!1),a=d.sessions;return e.jsxs("div",{className:"rounded-lg border border-line font-mono text-small leading-4 text-muted",children:[e.jsxs("button",{type:"button","aria-expanded":s,onClick:()=>n(l=>!l),className:"flex h-[34px] w-full items-center gap-1.5 px-2.5 text-left font-sans text-[12.5px]",children:[e.jsx(F,{name:"chevron",className:`size-3.5 transition-transform ${s?"rotate-90":""}`}),e.jsx("span",{className:"min-w-0 truncate",children:s?a.tools(t.length):a.toolsNamed(t.length,Kp(t).join(", "))})]}),s&&e.jsx("ul",{className:"pb-2",children:t.map(l=>e.jsxs("li",{className:"flex gap-1.5 px-2.5 py-[3px]",children:[e.jsx("span",{"aria-label":a.toolStatus[l.status],role:"img",className:ko[l.status].tone,children:ko[l.status].glyph}),e.jsxs("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:[e.jsx("b",{className:"font-medium text-fg",children:l.name})," ",l.label]})]},l.id))})]})}function Fb({store:t,item:s,onReconnect:n,keys:a}){var o,c,x;const l=fe(t),r=Ls(),i=l.sessions.get(s.sessionId);return e.jsx(Kr,{store:t,item:s,session:i,inThread:!0,keys:a,mode:Lr(s,(o=l.capabilities)==null?void 0:o[s.tool],(i==null?void 0:i.readOnly)===!0),outcome:Un(s,[...l.sessions.values()],l.ops),fresh:l.fresh,ghost:!1,changed:!1,onReread:()=>{},canConfirm:((c=l.device)==null?void 0:c.confirm)===!0&&r,enroll:r&&((x=l.device)==null?void 0:x.confirm)!==!0,onGone:()=>{},onCheck:n})}function Pb({item:t,store:s,storage:n,inPanel:a=!1,onReconnect:l,keys:r=!1}){switch(t.kind){case"tools":return e.jsx(Db,{tools:t.tools});case"time":return e.jsx("div",{className:"text-center font-mono text-meta text-muted",children:t.label});case"rig-message":case"rig-task":case"rig-notice":case"rig-fold":case"rig-unreadable":case"rig-raw":return e.jsx(Nb,{e:t,storage:n,store:s});case"me":{const i=t.images??(t.attachments??[]).flatMap(o=>s.knownImage(o)??[]);return e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[t.text&&e.jsx("div",{className:"max-w-[94%] rounded-2xl rounded-br-[4px] bg-raised p-3.5 text-body [overflow-wrap:anywhere] whitespace-pre-wrap",children:t.text}),e.jsx(mr,{store:s,refs:i,align:"end"}),t.cut&&e.jsx(No,{align:"end"}),t.delivery&&e.jsx("div",{role:t.delivery==="sending"?"status":void 0,className:`text-meta ${t.delivery==="uncertain"?"text-attention":t.delivery==="sending"?"text-muted":"text-ok"}`,children:t.delivery==="sending"?d.thread.delivery.sending:t.delivery==="uncertain"?d.thread.delivery.uncertain:t.fresh?d.thread.delivery.takenNow:d.thread.delivery.taken})]})}case"agent":return e.jsxs("div",{className:"flex flex-col items-start gap-1",children:[e.jsx("article",{"aria-label":d.thread.agentLabel,className:"max-w-[94%] rounded-2xl rounded-bl-[4px] border border-line bg-surface p-3.5 text-body [overflow-wrap:anywhere]",children:e.jsx(zb,{text:t.text})}),t.cut&&e.jsx(No,{align:"start"})]});case"task":return e.jsx(vb,{task:t.task,cut:t.cut});case"capture":{const i=t.images[0];return e.jsxs("div",{className:"flex flex-col items-start gap-1",children:[e.jsxs("div",{className:"text-meta text-muted",children:[e.jsx("span",{"aria-hidden":!0,children:"✓"})," ",e.jsx("span",{children:t.label}),i&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("span",{className:"font-mono",children:[i.width,"×",i.height]})]})]}),e.jsx(mr,{store:s,refs:t.images,align:"start"})]})}case"event":return e.jsx("div",{className:"text-center text-meta text-muted",children:t.label});case"awaiting":return a?e.jsxs(Ve,{title:a?d.atelier.awaiting:d.thread.awaiting,tone:t.item.kind==="question"?"warning":"approval",children:[e.jsx("p",{className:"[overflow-wrap:anywhere]",children:vn(t.item)}),e.jsxs("a",{href:ae(a?{name:"atelier",sessionId:t.item.sessionId,requestKey:t.item.key}:{name:"request",sessionId:t.item.sessionId,key:t.item.key}),className:De({block:!0,className:"mt-3"}),children:[d.thread.examine,e.jsx(F,{name:"arrowRight"})]})]}):e.jsx(Fb,{store:s,item:t.item,onReconnect:l,keys:r})}}function Bb({sessionId:t,panel:s}){return e.jsxs(e.Fragment,{children:[e.jsx("a",{href:ae({name:"thread",sessionId:t}),"aria-label":d.atelier.fullScreen,title:d.atelier.fullScreen,className:$t({variant:"outline"}),children:e.jsx(F,{name:"external"})}),e.jsx("button",{type:"button",onClick:s.onClose,"aria-label":d.atelier.closePanel,title:d.atelier.closeTitle,className:$t({}),children:e.jsx(F,{name:"close"})})]})}function fr({store:t,sessionId:s,storage:n,onReconnect:a,panel:l,forge:r}){var q,ye,_e,oe,Ae,st,yt,js,He,Mt,Rt;const i=fe(t),o=Yt(),c=It(),x=Ya(),u=i.sessions.get(s),m=i.threads.get(s),{fresh:p,ops:g}=i,[f,y]=h.useState(()=>Qd(s,n)),[w]=h.useState(()=>ig(s)),[S,b]=h.useState(!1),j=mu(t),N=h.useRef(new Map);h.useEffect(()=>{var Se;for(const[Et,Ot]of N.current){const de=(Se=g[Et])==null?void 0:Se.phase;de==="applied"?N.current.delete(Et):(de==="rejected"||de==="failed"||de==="uncertain")&&(N.current.delete(Et),j.putBack(Ot))}});const $=Se=>{y(Se),Yd(s,Se,n),b(!1)},[A,E]=h.useState(null),[k,T]=h.useState(!1),[C,I]=h.useState(!1),[P,L]=h.useState(!1),[R,M]=h.useState(null),z=((q=am(s,g))==null?void 0:q.op)??null,U=h.useRef(u==null?void 0:u.state);h.useEffect(()=>{U.current!==(u==null?void 0:u.state)&&U.current!==void 0&&M(z),U.current=u==null?void 0:u.state},[u==null?void 0:u.state,z]),h.useEffect(()=>(t.openThread(s),()=>t.watch(null)),[t,s]),h.useEffect(()=>{p&&t.watch(s)},[t,s,p]);const H=(m==null?void 0:m.status)==="ready"?(ye=m.items.at(-1))==null?void 0:ye.at:void 0;h.useEffect(()=>{H&&t.read(s,H)},[t,s,H]);const V=ad(s,g).at(-1);h.useEffect(()=>{(V==null?void 0:V.phase)!=="applied"||ag(V.op,n)||(lg(V.op,n),f.trim()===V.message.text&&$(""))},[V==null?void 0:V.phase,V==null?void 0:V.op]);const[ee,G]=h.useState(""),O=u==null?void 0:u.state;h.useEffect(()=>{(V==null?void 0:V.phase)==="applied"&&O&&O!=="idle"&&G(V.op)},[O,V==null?void 0:V.phase,V==null?void 0:V.op]);const D=h.useRef(null),J=(m==null?void 0:m.status)==="gone",Q=u&&!J?Yp((m==null?void 0:m.items)??[],u,g,o,(m==null?void 0:m.cut)??[],i.sessions,((_e=i.device)==null?void 0:_e.id)??null):[],Y=(oe=Q.at(-1))==null?void 0:oe.key,ie=h.useRef(!0),[X,le]=h.useState(!1),B=()=>{const Se=D.current;Se&&(Se.scrollTop=Se.scrollHeight),ie.current=!0,le(!1)},v=h.useRef(!1);h.useLayoutEffect(()=>{var Et;const Se=D.current;if(!(!Se||Q.length===0)){if(!v.current){v.current=!0;const Ot=Tl.get(s);if(Tl.delete(s),Ot!==void 0){Se.scrollTop=Ot,ie.current=Se.scrollHeight-Se.scrollTop-Se.clientHeight<vo;return}}ie.current?B():((Et=Q.at(-1))==null?void 0:Et.kind)==="awaiting"&&le(!0)}},[Y,Q.length,m==null?void 0:m.items]);const _=()=>{const Se=D.current;Se&&(ie.current=Se.scrollHeight-Se.scrollTop-Se.clientHeight<vo,ie.current&&le(!1))};if(!u||J){const Se=!J&&!p&&i.syncedAt===null;return e.jsxs(e.Fragment,{children:[e.jsx("header",{className:"flex-none border-b border-line pt-2 pb-3",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[!l&&e.jsx(ls,{fallback:{name:"sessions"},label:d.thread.back}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:d.thread.title}),e.jsx(qc,{link:$n(i)}),l&&e.jsx("button",{type:"button",onClick:l.onClose,"aria-label":d.atelier.closePanel,title:d.atelier.closeTitle,className:$t({}),children:e.jsx(F,{name:"close"})})]})}),e.jsx("main",{className:"min-h-0 flex-1 pt-7 text-body text-muted",role:"status",children:Se?d.thread.loading:d.thread.unknown})]})}const W=V!==void 0&&us(V.phase),se=(V==null?void 0:V.phase)==="applied"&&ee!==V.op&&u.state==="idle"&&!u.pending&&o-Date.parse(V.at)<er,re=Zp(u,p?"ready":"pc_offline",W||se),K=V&&(V.phase==="rejected"||V.phase==="failed"||V.phase==="uncertain")&&(V.phase==="uncertain"||f.trim()===V.message.text)?Rb(V):null,ce=S&&!K?{title:d.thread.composer.failTitle,body:d.thread.composer.lost}:K,ge=!!u.pending||u.state==="waiting_input"||u.state==="waiting_permission",Ye=()=>{const Se=f.trim();if(!Se&&j.items.length===0||!re.enabled||hu(f)||!j.ready||j.items.length>0&&ge)return;M(z);const Et=j.ids(),Ot=j.clear(),de=t.reply(s,Se,Et.length?{attachments:Et}:{});!de&&Ot.length?j.putBack(Ot):de&&Ot.length&&N.current.set(de,Ot),b(!de)},pt=(m==null?void 0:m.status)==="ready",Re=((Ae=i.daemon)==null?void 0:Ae.boot)??null,Le=lm(u,g,o,{fresh:p,boot:Re}),pe=Ar(u,g,Re,o),he=!!((st=i.daemon)!=null&&st.sessionClose)&&!u.readOnly,Me=Le.kind==="open"&&Le.error&&Le.error.op!==R?Le.error:null,ze=Se=>{M(z),L(!1),E(Se)},at=!!l&&u.tool==="omp",et=wn(u),bt=Cb(s,n),jt=u.state==="exited"&&u.exitedAt?d.sessions.line.ended(mc(u.exitedAt,o)):void 0,Z=x&&[u.project,u.branch].filter(Boolean).join(" · ")||void 0;return e.jsxs(e.Fragment,{children:[e.jsx(ea,{back:l?e.jsx("span",{className:"w-2.5"}):e.jsx(ls,{fallback:{name:"sessions"},label:d.thread.back}),tool:u.tool,name:u.name,dot:et,pulse:et==="work"&&p,sub:jt??Z,under:!x&&!!jt,more:e.jsxs(e.Fragment,{children:[l?e.jsx(Bb,{sessionId:s,panel:l}):e.jsx(ju,{sessionId:s,current:"thread",onLeave:()=>{D.current&&Tl.set(s,D.current.scrollTop)}}),e.jsx("button",{type:"button","aria-haspopup":"dialog","aria-label":d.sessions.moreOf(u.name),title:d.sessions.more,onClick:()=>T(!0),className:$t({className:k?"bg-raised text-fg":"text-muted"}),children:e.jsx(F,{name:"more"})})]})}),at?e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[e.jsx("h2",{className:"text-heading",children:d.atelier.ompNoThread}),e.jsx("p",{className:"max-w-[320px] text-body text-muted",children:d.atelier.ompBody}),e.jsxs("a",{href:ae({name:"terminal",sessionId:s}),className:De({variant:"primary"}),children:[e.jsx(F,{name:"terminal"}),d.atelier.ompTerminal]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("main",{ref:D,onScroll:_,"aria-label":d.thread.log(u.name),className:"flex min-h-0 flex-1 flex-col gap-3.5 overflow-y-auto overscroll-contain pt-5 pb-4 phone-side:pt-3 phone-side:pb-3",children:[((yt=i.daemon)==null?void 0:yt.checklist)&&i.checklists.get(s)&&e.jsx(Wd,{checklist:i.checklists.get(s),current:(js=u==null?void 0:u.checklist)==null?void 0:js.current}),(m==null?void 0:m.more)&&e.jsx("p",{className:"text-center text-meta text-muted",children:d.thread.more}),!(m!=null&&m.more)&&bt!==null&&e.jsx("p",{className:"flex items-center gap-2 text-[12px] text-muted before:h-px before:flex-1 before:bg-line before:content-[''] after:h-px after:flex-1 after:bg-line after:content-['']",children:d.launch.started(u.name,bt)}),!pt&&Q.length===0&&e.jsx("p",{className:"text-center text-meta text-muted",role:"status",children:p?d.thread.loading:d.thread.unavailable}),pt&&Q.length===0&&e.jsx("p",{className:"text-center text-meta text-muted",children:d.thread.empty}),Q.map(Se=>e.jsx(Pb,{item:Se,store:t,storage:n,inPanel:!!l,onReconnect:a,keys:c&&!l},Se.key))]}),X&&e.jsx("div",{className:"relative h-0",children:e.jsxs("button",{type:"button",onClick:B,className:"absolute bottom-3 left-1/2 inline-flex h-9 -translate-x-1/2 items-center gap-1.5 rounded-full border border-line bg-surface px-3.5 text-[13px] font-medium text-fg shadow-sm",children:[e.jsx(F,{name:"down",className:"size-4"}),d.sessions.requestBelow]})}),Le.kind==="open"?e.jsx(Ob,{name:u.name,focusAtEnd:w,composer:c&&qa()?{...re,placeholder:`${re.placeholder} · ${d.sessions.keysHint}`}:re,draft:f,onDraft:$,onSend:Ye,fresh:p,taken:se,checking:(V==null?void 0:V.phase)==="uncertain"&&p,error:ce,onReconnect:a,images:j,dialog:ge,...(He=i.daemon)!=null&&He.commands&&u.tool==="claude"&&!u.readOnly?{slash:{tool:d.tools[u.tool],listing:i.commands[s],ask:()=>t.requestCommands(s)}}:{},alert:Me&&e.jsx(bu,{error:Me,fresh:p,onRetry:()=>ze("close"),onReconnect:a}),...Js(i.daemon,u)?{lead:e.jsx(Jh,{store:t,session:u}),leadNote:e.jsx(eg,{store:t,session:u})}:{}}):e.jsx(Lb,{ending:Le.kind==="ended"&&((Mt=Le.error)==null?void 0:Mt.op)===R?{...Le,error:null}:Le,name:u.name,canResume:he,resumeHeld:rm(u,g,Re,o),readOnly:!!u.readOnly,fresh:p,focus:P,onResume:()=>ze("resume"),onReconnect:a},Le.kind),e.jsx(yu,{store:t,forge:r,session:u,wide:x,threshold:((Rt=i.device)==null?void 0:Rt.contextNear)??kn,onModel:()=>I(!0)})]}),k&&e.jsx(ei,{store:t,session:u,closable:he&&!at,closing:pe,onClose:()=>T(!1),onModel:()=>{T(!1),I(!0)},onCloseSession:()=>{T(!1),ze("close")}}),C&&Js(i.daemon,u)&&e.jsx(al,{store:t,session:u,onClose:()=>I(!1)}),A&&e.jsx(ri,{store:t,session:u,mode:A,onClose:()=>E(null),onSent:()=>{L(!0),E(null)},onReconnect:a})]})}const Tl=new Map,vo=48;function ju({sessionId:t,current:s,onLeave:n}){const a=d.sessions.view,l="grid h-9 place-items-center px-3 tablet:px-3.5 text-[13px] font-medium text-muted aria-[current=page]:bg-raised aria-[current=page]:text-fg";return e.jsxs("nav",{"aria-label":a.label,className:"flex flex-none overflow-hidden rounded-lg border border-input",children:[e.jsx("a",{href:ae({name:"thread",sessionId:t}),onClick:s==="thread"?void 0:n,"aria-current":s==="thread"?"page":void 0,className:l,children:a.thread}),e.jsx("a",{href:ae({name:"terminal",sessionId:t}),onClick:s==="terminal"?void 0:n,"aria-current":s==="terminal"?"page":void 0,className:l,children:a.terminal})]})}function yu({store:t,forge:s,session:n,wide:a,threshold:l,onModel:r}){const i=fe(t),{daemon:o,fresh:c,usage:x,usageAlert:u}=i,m=Yt(),p=Ja(n,m,l),g=d.sessions,f=Xd(o,n)===null,y=a?xf(n.tool,x,u,m,c):null;return e.jsxs("footer",{"aria-label":g.foot(n.name),className:"bleed flex h-10 flex-none items-center gap-2.5 border-t border-line bg-sidebar px-3 text-small whitespace-nowrap text-muted",children:[p.model&&(f?e.jsxs("button",{type:"button",disabled:!c,"aria-haspopup":"dialog","aria-label":d.model.chip(p.model),onClick:r,className:"inline-flex h-8 items-center gap-1 text-fg disabled:opacity-60",children:[p.model,e.jsx(F,{name:"down",className:"size-3.5"})]}):e.jsx("span",{className:"text-fg",children:p.model})),p.context&&e.jsxs("span",{role:"img","aria-label":g.contextLabel(p.context.pct),className:`inline-flex items-center gap-1.5 ${p.context.near?"text-attention":""}`,children:[e.jsx("span",{className:"relative block h-1 w-8 overflow-hidden rounded-sm bg-raised",children:e.jsx("span",{className:"absolute inset-y-0 left-0 bg-current",style:{width:`${p.context.pct}%`}})}),p.context.pct," %"]}),a&&n.context&&e.jsxs("span",{children:["· ",Bi(n.context.used)," / ",Bi(n.context.window)]}),(p.model||p.context)&&e.jsx("span",{className:"h-3 w-px flex-none bg-line"}),n.branch?e.jsx("span",{className:`min-w-0 truncate font-mono text-[11px] ${a?"":"flex-1"}`,children:n.branch}):e.jsxs("span",{"aria-label":g.folder(n.project),className:`inline-flex min-w-0 items-center gap-1 ${a?"":"flex-1"}`,children:[e.jsx(F,{name:"folder",className:"size-3.5"}),e.jsx("span",{className:"truncate",children:n.project})]}),n.branch&&e.jsx(oh,{forge:s,mobile:i,session:n}),a&&n.branch&&e.jsx("span",{className:"min-w-0 truncate",children:n.project}),a&&e.jsx("span",{className:"flex-1"}),y&&e.jsxs("span",{className:"flex-none",children:[d.chat.point.harnessShort[y.harness]??y.harness," ",ai(y.window)," ",e.jsxs("b",{className:`font-semibold ${y.tone==="red"?"text-approval":y.tone==="amber"?"text-attention":"text-fg"}`,children:[y.window.pct," %"]})]})]})}const qb={approval:{fg:"var(--danger-text)"},question:{fg:"var(--warning)"},starting:{fg:"var(--info)"},idle:{fg:"var(--success)"},working:{fg:"var(--info)"},done:{fg:"var(--muted-foreground)"},error:{fg:"var(--danger-text)"},readonly:{fg:"var(--muted-foreground)"}};function Hb({state:t,label:s,tone:n,caps:a=!1}){const{stateLabel:l}=Cr(),r=qb[n??t].fg;return e.jsx("span",{"data-badge":t,style:{display:"inline-flex",alignItems:"center",flexShrink:0,height:a?24:22,padding:a?"0 9px":"0 8px",boxSizing:"border-box",borderRadius:5,color:r,background:"color-mix(in srgb, currentColor 10%, transparent)",fontSize:a?11:12,lineHeight:1,fontWeight:500,letterSpacing:a?"0.08em":void 0,textTransform:a?"uppercase":void 0,whiteSpace:"nowrap",transition:sp([["background-color","hover"],["color","hover"]])},children:s??l[t]})}const wo=["monstera","fern","snake","ficus","succulent"],Ub=["tl","tr","br","ml","mr"];function Wb(t,s){const n=gn(t),a=1+n%2;return Ub.filter(l=>!s.includes(l)).sort((l,r)=>gn(t+l)-gn(t+r)).slice(0,a).map((l,r)=>({spot:l,species:wo[(n+r*7)%wo.length],flip:!!(n>>r&1)}))}const _s={top:56,side:12,bottom:34},So=11/12,Nu=t=>t.width>=t.height?"land":"port";function Kb(t,s,n){if(t.length===0||s.width<=0||s.height<=0)return{zoom:1,along:n==="land"?"row":"column"};const a=Math.max(...t.map(i=>i.h)),l=Math.max(...t.map(i=>i.w));return{zoom:n==="land"?Math.min(1,Math.max(So,(s.height-4)/(a+_s.top+_s.bottom))):Math.min(1,Math.max(So,(s.width-4)/(l+2*_s.side))),along:n==="land"?"row":"column"}}const Vb={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"};function Ha(t){return t.state==="idle"&&(t.helpers??[]).some(s=>s.state!=="exited"&&s.state!=="idle")?"working":Vb[t.state]}const ku=t=>t.state==="waiting_permission"||t.state==="waiting_input",vu=["M5 10.4a1.6 1.6 0 1 0 0 3.2 1.6 1.6 0 0 0 0-3.2Z","M12 10.4a1.6 1.6 0 1 0 0 3.2 1.6 1.6 0 0 0 0-3.2Z","M19 10.4a1.6 1.6 0 1 0 0 3.2 1.6 1.6 0 0 0 0-3.2Z"],Gb=["M12 2.5 20.5 7.25v9.5L12 21.5l-8.5-4.75v-9.5z","M12 8.5a3.5 3.5 0 1 0 0 7a3.5 3.5 0 1 0 0-7"],Xb=["M4 7h16v12H4z","M4 7l2-3h4l2 3","M9 13h6"],Bn=t=>t.topic??t.title;function hr({session:t,size:s,frozen:n}){const a=en(),l=Ha(t);return e.jsx(Qa,{tool:t.tool,state:l,pose:Xa(t.id,t.state),size:s,theme:a,seed:t.id,frozen:n,readOnly:!!t.readOnly})}function $o({helper:t,parent:s,size:n,frozen:a}){const l=en(),r=`${s.id}:${t.id}`,i=wc(t);return e.jsx(Qa,{tool:s.tool,state:i,pose:Xa(r,i),size:n,theme:l,seed:r,frozen:a,readOnly:!!s.readOnly})}const wu=({state:t})=>e.jsx(Hb,{state:t}),Su=({color:t})=>t?e.jsx("i",{className:"side-swatch",style:{background:t}}):e.jsx("i",{className:"filter-none"}),Qb={monstera:()=>e.jsxs("span",{className:"p-monstera",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("b",{})]}),fern:()=>e.jsxs("span",{className:"p-fern",children:[[0,1,2,3,4,5,6].map(t=>e.jsx("i",{},t)),e.jsx("b",{})]}),snake:()=>e.jsxs("span",{className:"p-snake",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("b",{})]}),ficus:()=>e.jsxs("span",{className:"p-ficus",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("em",{}),e.jsx("b",{})]}),succulent:()=>e.jsxs("span",{className:"p-succulent",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("b",{})]})};function Yb({seed:t,left:s,width:n,avoid:a}){return e.jsx("div",{className:"plants","aria-hidden":"true",style:{left:s,width:n},children:Wb(t,a).map(({spot:l,species:r,flip:i})=>{const o=Qb[r];return e.jsx("span",{className:`plant-spot spot-${l}${i?" flip":""}`,children:e.jsx(o,{})},l)})})}const Co=t=>e.jsxs(e.Fragment,{children:[(t==="approval"||t==="question")&&e.jsx("b",{className:"sheet-flag"}),t==="done"&&e.jsx("i",{className:"sheet-stamp",children:"✓"})]});function Zb({sheets:t,length:s}){return e.jsx("div",{className:"table-top",children:t.map(a=>e.jsxs(h.Fragment,{children:[e.jsxs("div",{style:{left:a.x-84/2},className:`task-sheet sheet-${a.slot} sheet-${a.state}`,children:[e.jsx("p",{lang:"fr",children:a.task}),Co(a.state)]}),a.note&&e.jsxs("div",{style:{left:gm(a.x,t.filter(l=>l.slot===a.slot).map(l=>l.x),s)},className:`sheet-note note-${a.slot} sheet-${a.note.state}`,children:[e.jsx("p",{children:a.note.task}),Co(a.note.state),a.note.more>0&&e.jsxs("em",{className:"note-more",children:["+",a.note.more]})]})]},a.id))})}function Jb({table:t,project:s,color:n,frozen:a,act:l,helpers:r=!0}){const{length:i,width:o,seats:c,ends:x,notes:u,extra:m,extraCount:p}=hm(t.mains,r,Jn,Ts),g=b=>`calc(50% - ${i/2}px + ${b}px)`,f=bm(t.mains),y=c.map(({session:b,x:j,side:N})=>{const $=u.get(b.id);return{id:b.id,task:Bn(b),state:Ei(Ha(b)),slot:N,x:j,note:$&&{task:$.helper.task,state:Ei(wc($.helper)),more:$.more}}}),w=[...m.mains.map(b=>({key:b.id,el:e.jsx(hr,{session:b,size:18,frozen:a})})),...m.helpers.map(({helper:b,parent:j})=>({key:`${j.id}:${b.id}`,el:e.jsx($o,{helper:b,parent:j,size:18,frozen:a})}))].slice(0,3),S=[...p>0?["br"]:[],...x.some(b=>b.end==="left")?["ml"]:[],...x.some(b=>b.end==="right")?["mr"]:[]];return e.jsx("section",{className:"atelier-table","data-project":s.id,"data-table":t.key,"aria-label":d.atelier.table(s.name),style:{"--room":`${o}px`,"--project":n},children:e.jsxs("div",{className:"table-scene",children:[e.jsx("div",{className:"office-rug",style:{left:g(-Ts),right:"auto",width:i+2*Ts}}),e.jsxs("div",{className:"rug-labels",style:{left:g(-Ts),width:i+2*Ts},children:[e.jsxs("div",{className:"room-heading",children:[e.jsx(Su,{color:n}),e.jsxs("span",{className:"heading-names",children:[e.jsx("button",{type:"button",className:"project-conversations",title:s.name,"aria-label":d.atelier.conversations(s.name),onClick:()=>l.room(s.id),children:s.name}),f!==null&&e.jsxs("span",{className:"heading-branch",title:f,children:["⎇ ",f]})]}),e.jsx("span",{className:"spacer"}),e.jsx("span",{className:"room-menu-wrap",children:e.jsx("button",{type:"button",className:"icon-action","aria-label":d.atelier.roomMenu(s.name),onClick:()=>l.room(s.id),children:e.jsx(yn,{d:[],fill:vu,size:14})})})]}),p>0&&e.jsxs("button",{type:"button",className:"table-more",onClick:()=>l.room(s.id),children:[e.jsx("span",{className:"more-faces","aria-hidden":"true",children:w.map(b=>e.jsx("i",{children:b.el},b.key))}),d.atelier.more(p)]})]}),e.jsx(Yb,{seed:t.key,left:g(-Ts),width:i+2*Ts,avoid:S}),c.map(({session:b,x:j,side:N})=>e.jsx("div",{className:`office-chair chair-${N}`,"aria-hidden":"true",style:{left:g(j-27)}},b.id)),e.jsx("div",{className:"worktable","aria-hidden":"true",style:{left:g(0),right:"auto",width:i},children:e.jsx(Zb,{length:i,sheets:y})}),c.map(({session:b,x:j,side:N})=>{var A;const $=Ha(b);return e.jsxs("button",{type:"button",style:{left:g(j-56)},"data-agent":b.id,"aria-label":d.atelier.seat(b.name,Bn(b)),onClick:()=>l.open(b.id),className:`agent-seat place-${N}${!a&&$==="working"?" seat-working":""}${a?" seat-offline":""}`,children:[e.jsx(hr,{session:b,size:64,frozen:a}),e.jsx("strong",{children:e.jsx("span",{className:"seat-name",title:b.name,children:b.name})}),e.jsx("span",{className:"seat-machine",children:((A=b.rig)==null?void 0:A.role)??"local"}),e.jsx(wu,{state:$})]},b.id)}),x.map(({helper:b,parent:j,end:N,slot:$,count:A})=>e.jsxs("button",{type:"button",style:{left:g(N==="left"?-70:i+8),right:"auto",top:A>1?$?232:126:void 0},className:`agent-seat helper-seat end-${N}`,"aria-label":d.atelier.helperSeat(b.kind,j.name,b.task),title:b.task,onClick:()=>l.open(j.id),children:[e.jsx($o,{helper:b,parent:j,size:36,frozen:a}),e.jsx("strong",{children:b.kind}),e.jsxs("span",{className:"seat-meta",children:["↳ ",j.name]})]},`${j.id}:${b.id}`))]})})}function ej({project:t,tables:s,rig:n,width:a,act:l,children:r}){const i=s.flatMap(p=>p.mains),o=n?i.filter(p=>p.state!=="exited"):i,c=o.filter(ku).length,x=o.filter(p=>p.state==="working").length,u=(n==null?void 0:n.kind)==="kernel"?d.atelier.kernel:t.name,m=()=>l.room(t.id);return e.jsxs("section",{className:`project-room atelier-room${n?` rig-room ${n.kind}-room`:""}`,"data-room":t.id,"aria-label":n?d.atelier.rigRoom(n.kind,t.name):d.atelier.room(t.name),style:{"--room":`${a}px`,"--project":bn[t.color],"--room-side":`${Sc}px`,"--room-back":`${vm}px`,"--table-gap":`${$c}px`},children:[e.jsxs("div",{className:"room-walls","aria-hidden":"true",children:[e.jsx("i",{className:"wall-back"}),e.jsx("i",{className:"wall-left"}),e.jsx("i",{className:"wall-right"}),e.jsx("i",{className:"wall-front"})]}),e.jsxs("div",{className:`room-plaque${n?" rig-plaque":""}`,children:[n?e.jsx("span",{className:"rig-hex","aria-hidden":"true",children:e.jsx(yn,{d:Gb,size:13})}):e.jsx(Su,{color:bn[t.color]}),e.jsx("strong",{className:"plaque-name",title:u,role:"button",tabIndex:0,"aria-label":d.atelier.roomMenu(u),onClick:m,onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),m())},children:u}),n?e.jsx("span",{className:"plaque-where",children:n.kind==="kernel"?d.atelier.kernelWhere:d.atelier.rigWhere(n.folder,n.project)}):e.jsx("span",{className:"plaque-counts",children:d.atelier.plaqueCounts(i.length)}),c>0&&e.jsxs("span",{className:"plaque-waiting",children:[e.jsx("i",{className:"approval-dot"}),d.atelier.waiting(c)]}),x>0&&e.jsxs("span",{className:"plaque-working",children:[e.jsx("i",{className:"live-dot"}),d.atelier.working(x)]}),!n&&e.jsx("span",{className:"room-menu-wrap",children:e.jsx("button",{type:"button",className:"icon-action","aria-label":d.atelier.roomMenu(u),onClick:m,children:e.jsx(yn,{d:[],fill:vu,size:14})})})]}),e.jsx("div",{className:"room-tables",children:r}),e.jsx("span",{className:"room-entrance","aria-hidden":"true",children:d.atelier.entrance})]})}function tj({sessions:t,frozen:s,act:n}){return t.length===0?null:e.jsxs("section",{className:"unassigned-zone atelier","aria-labelledby":"unassigned-title",children:[e.jsxs("div",{className:"unassigned-heading",children:[e.jsx(yn,{d:Xb,size:15}),e.jsx("h2",{id:"unassigned-title",children:d.atelier.unassigned}),e.jsx("span",{className:"muted",children:d.atelier.unassignedHint})]}),e.jsx("div",{className:"unassigned-list",children:t.map(a=>e.jsxs("div",{className:"unassigned-card",children:[e.jsxs("button",{type:"button",className:"unassigned-open","data-agent":a.id,"aria-label":d.atelier.seat(a.name,Bn(a)),onClick:()=>n.open(a.id),children:[e.jsx(hr,{session:a,size:56,frozen:s}),e.jsxs("span",{className:"unassigned-copy",children:[e.jsx("strong",{children:a.name}),e.jsx("span",{title:Bn(a),children:Bn(a)}),e.jsx("code",{children:a.project})]})]}),e.jsx("div",{className:"unassigned-actions",children:e.jsx(wu,{state:Ha(a)})})]},a.id))})]})}function sj({count:t,frozen:s,onOpen:n}){const a=en();return e.jsx("div",{className:"ledge-corner",children:e.jsxs("button",{type:"button",className:"ledge-desk",onClick:n,disabled:!n,"aria-label":d.atelier.desk,children:[e.jsx("span",{className:"ledge-bubble",children:d.atelier.watching(t)}),e.jsx("span",{className:"ledge-seat",children:e.jsx(zr,{size:80,theme:a,frozen:s})}),e.jsx("strong",{children:"Ledge"}),e.jsx("small",{children:d.atelier.assistant})]})})}function nj(){const t=d.atelier.legend;return e.jsxs("div",{className:"workspace-legend",children:[e.jsxs("span",{children:[e.jsx("i",{className:"live-dot"}),t.working]}),e.jsxs("span",{children:[e.jsx("i",{className:"approval-dot"}),t.approval]}),e.jsxs("span",{children:[e.jsx("i",{className:"question-dot"}),t.question]}),e.jsxs("span",{children:[e.jsx("i",{className:"done-dot"}),t.done]}),e.jsx("span",{className:"spacer"}),e.jsx("span",{children:t.helper})]})}const $u=.3,aj=2.5,lj=2.2,gr=t=>Math.min(aj,Math.max($u,t)),rj=(t,s)=>gr(s>0?t*1.2:t/1.2);function ij(t,s,n){const a=(t.left+n.x)/t.zoom,l=(t.top+n.y)/t.zoom;return{left:a*s-n.x,top:l*s-n.y}}function oj(t,s){const n=Math.min(lj,Math.max($u,Math.min(s.width*.92/t.w,s.height*.92/t.h)));return{zoom:n,left:(t.x+t.w/2)*n-s.width/2,top:(t.y+t.h/2)*n-s.height/2}}const cj=8,dj=320,uj=30,xj="button,a,[role=button],.unassigned-card",mj=".atelier-room,.unassigned-zone",pj=12;let ks={zoom:null,left:0,top:0};function fj(t){const s=h.useRef(null),n=h.useRef(null),[a,l]=h.useState(1),[r,i]=h.useState(ks.zoom),o=h.useRef(ks.zoom??1),c=h.useRef(ks.zoom),x=h.useRef({w:-1,h:-1}),u=h.useCallback(()=>{const b=s.current,j=n.current;if(!b||!j)return;const N=j.style;N.zoom="1";const $={width:b.clientWidth,height:b.clientHeight};x.current={w:b.offsetWidth,h:b.offsetHeight};const A=Nu($);N.padding=`${_s.top}px ${_s.side}px ${_s.bottom}px`,N.flexWrap="wrap",N.width="max-content",N.maxWidth="none",N.minHeight="",N.alignContent="flex-start",N.gap="0 8px";const E=j.querySelector(".ledge-corner");N.setProperty("--ledge-clear",`${E?Math.max(0,E.offsetTop+E.offsetHeight+pj-_s.top):0}px`);const k=[...j.querySelectorAll(mj)].map(I=>({w:I.offsetWidth,h:I.offsetHeight})).filter(I=>I.w>0),{zoom:T,along:C}=Kb(k,$,A);if(C==="row")N.flexWrap="nowrap",N.width="max-content",N.justifyContent="flex-start";else{const I=Math.max(0,...k.map(P=>P.w))+2*_s.side;N.flexWrap="wrap",N.width=`${I}px`,N.maxWidth=`${I}px`,N.justifyContent="center"}k.length===0&&(N.width=`${$.width}px`,N.minHeight=`${$.height}px`),l(T),o.current=c.current??T,N.zoom=String(o.current)},[]);h.useLayoutEffect(()=>{u();const b=s.current;b&&(b.scrollLeft=ks.left,b.scrollTop=ks.top)},[u,...t]);const m=h.useRef(u);m.current=u,h.useEffect(()=>{var N,$;const b=s.current;if(!b||typeof ResizeObserver>"u")return;const j=new ResizeObserver(()=>{(b.offsetWidth!==x.current.w||b.offsetHeight!==x.current.h)&&m.current()});return j.observe(b),($=(N=globalThis.document)==null?void 0:N.fonts)==null||$.ready.then(()=>m.current()),()=>j.disconnect()},[]);const p=(b,j,N)=>{const $=s.current,A=n.current;o.current=b,c.current=b,i(b),ks.zoom=b,!(!$||!A)&&(A.style.zoom=String(b),$.scrollLeft=j,$.scrollTop=N)},g=b=>{const j=s.current,N=gr(b);if(!j){p(N,0,0);return}const{left:$,top:A}=ij({zoom:o.current,left:j.scrollLeft,top:j.scrollTop},N,{x:j.clientWidth/2,y:j.clientHeight/2});p(N,$,A)},f=b=>g(rj(o.current,b)),y=()=>{c.current=null,i(null),ks.zoom=null,u();const b=s.current;b&&(b.scrollLeft=0,b.scrollTop=0)},w=b=>{const j=s.current;if(!j)return;const N=o.current,$=j.getBoundingClientRect(),A=b.getBoundingClientRect(),E={x:(j.scrollLeft+A.left-$.left)/N,y:(j.scrollTop+A.top-$.top)/N,w:A.width/N,h:A.height/N};if(E.w<=0||E.h<=0)return;const{zoom:k,left:T,top:C}=oj(E,{width:j.clientWidth,height:j.clientHeight});p(k,T,C)},S=h.useRef({setZoom:p,fit:y,frame:w});return S.current={setZoom:p,fit:y,frame:w},h.useEffect(()=>{const b=s.current;if(!b)return;const j=new Map;let N=null,$=null,A=null,E=!1;const k=(M,z)=>({x:(M.x+z.x)/2,y:(M.y+z.y)/2,d:Math.hypot(M.x-z.x,M.y-z.y)}),T=()=>{const[M,z]=[...j.values()];if(N=null,$=null,M&&z){const U=k(M,z),H=b.getBoundingClientRect(),V=o.current;N={d:Math.max(U.d,1),zoom:V,x:(b.scrollLeft+U.x-H.left)/V,y:(b.scrollTop+U.y-H.top)/V}}else M&&($={x:M.x,y:M.y,left:b.scrollLeft,top:b.scrollTop,moved:!1})},C=M=>{M.pointerType!=="mouse"&&(j.size===0&&(E=!1),j.set(M.pointerId,{x:M.clientX,y:M.clientY}),T())},I=M=>{if(!j.has(M.pointerId))return;j.set(M.pointerId,{x:M.clientX,y:M.clientY});const[z,U]=[...j.values()];if(N&&z&&U){const H=k(z,U),V=b.getBoundingClientRect(),ee=gr(N.zoom*H.d/N.d);S.current.setZoom(ee,N.x*ee-(H.x-V.left),N.y*ee-(H.y-V.top))}else if($){const H=M.clientX-$.x,V=M.clientY-$.y;if(!$.moved&&Math.hypot(H,V)<cj)return;$.moved=!0,b.scrollLeft=$.left-H,b.scrollTop=$.top-V}},P=M=>{if(!j.has(M.pointerId))return;($!=null&&$.moved||N)&&(E=!0);const z=j.size===1&&$!==null&&!$.moved;if(j.delete(M.pointerId),T(),!z||M.type==="pointercancel")return;const U=M.target instanceof Element?M.target:null,H=M.timeStamp;if(A&&H-A.at<dj&&Math.hypot(M.clientX-A.x,M.clientY-A.y)<uj&&!(U!=null&&U.closest(xj))){A=null;const V=U==null?void 0:U.closest(".atelier-room");V?S.current.frame(V):S.current.fit();return}A={at:H,x:M.clientX,y:M.clientY}},L=M=>{E&&(E=!1,M.preventDefault(),M.stopPropagation())},R=()=>{ks.left=b.scrollLeft,ks.top=b.scrollTop};return b.addEventListener("pointerdown",C),b.addEventListener("pointermove",I),b.addEventListener("pointerup",P),b.addEventListener("pointercancel",P),b.addEventListener("click",L,!0),b.addEventListener("scroll",R,{passive:!0}),()=>{b.removeEventListener("pointerdown",C),b.removeEventListener("pointermove",I),b.removeEventListener("pointerup",P),b.removeEventListener("pointercancel",P),b.removeEventListener("click",L,!0),b.removeEventListener("scroll",R)}},[]),{scrollRef:s,shellRef:n,zoom:r??a,fitted:r===null,zoomTo:g,step:f,fit:y}}const hj=["M15 3h6v6","M9 21H3v-6","M21 3l-7 7","M3 21l7-7"],gj=80;function Cu({label:t,onClose:s,children:n}){const a=h.useRef(null),l=h.useRef(null),[r,i]=h.useState(0),o=u=>{var p,g;const m=u.target;!m.closest(".atelier-panel-grab, .atelier-panel > header, .atelier-panel header")||m.closest("button,a,textarea,input")||(l.current={x:u.clientX,y:u.clientY,id:u.pointerId,land:Nu({width:globalThis.innerWidth,height:globalThis.innerHeight})==="land"},(g=(p=a.current)==null?void 0:p.setPointerCapture)==null||g.call(p,u.pointerId))},c=u=>{const m=l.current;!m||m.id!==u.pointerId||i(Math.max(0,m.land?u.clientX-m.x:u.clientY-m.y))},x=u=>{const m=l.current;if(!m||m.id!==u.pointerId)return;l.current=null;const p=m.land?u.clientX-m.x:u.clientY-m.y;i(0),p>gj&&s()};return e.jsxs("aside",{ref:a,className:"atelier-panel","aria-label":t,onPointerDown:o,onPointerMove:c,onPointerUp:x,onPointerCancel:x,style:r?{"--pull":`${r}px`}:void 0,children:[e.jsx("div",{className:"atelier-panel-grab","aria-hidden":"true"}),n]})}function bj({store:t,name:s,ids:n,onOpen:a,onClose:l}){var x;const r=fe(t),i=!r.fresh,o=n.map(u=>r.sessions.get(u)).filter(u=>u!==void 0),c=o.filter(u=>u.state!=="exited").map(u=>u.id);return e.jsxs(Cu,{label:d.atelier.room(s),onClose:l,children:[e.jsxs("header",{className:"flex flex-none items-center gap-2.5 border-b border-line pt-2 pb-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h1",{className:"text-title font-semibold [overflow-wrap:anywhere]",children:s}),e.jsx("p",{className:"mt-[3px] text-meta text-muted",children:d.atelier.roomAgents(o.length)})]}),e.jsx("button",{type:"button",onClick:l,"aria-label":d.atelier.closePanel,title:d.atelier.closeTitle,className:$t({}),children:e.jsx(F,{name:"close"})})]}),e.jsxs("main",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:[o.map(u=>{var m;return e.jsxs("button",{type:"button",onClick:()=>a(u.id),className:"flex w-full items-center gap-3 border-b border-line py-3 text-left active:bg-raised/60",children:[e.jsx(Dr,{tool:u.tool,seed:u.id,state:u.state,frozen:i}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-body font-semibold",children:u.name}),e.jsx("span",{className:"block truncate text-meta text-muted",children:((m=u.rig)==null?void 0:m.role)??u.topic??u.branch??u.title})]}),e.jsx(ta,{...Bm(u)})]},u.id)}),((x=r.daemon)==null?void 0:x.broadcast)&&c.length>0&&e.jsx("div",{className:"pt-4",children:c.length>_a?e.jsx("p",{className:"text-meta text-attention",children:d.agents.tooMany(c.length,_a)}):e.jsx(Rc,{store:t,label:s,ids:c,offline:i})})]})]})}function jj(t,s){var a;const n=t.rooms.find(l=>l.project.id===s);return n?{name:((a=n.rig)==null?void 0:a.kind)==="kernel"?d.atelier.kernel:n.project.name,ids:n.tables.flatMap(l=>l.mains.map(r=>r.id))}:null}const Mo=`${$s}sessions.helpers`,Eo=`${$s}sessions.groupBy`;function yj({store:t,sessionId:s,requestKey:n,storage:a,onReconnect:l}){var R;const r=fe(t),i=!r.fresh,o=h.useMemo(()=>[...r.sessions.values()],[r.sessions]),c=h.useMemo(()=>o.map(M=>({...M,cwd:M.project})),[o]),x=h.useMemo(()=>ym(c,r.projects,M=>M.projectId??null,"all",!0,({id:M,name:z,kind:U})=>({id:M,name:z,color:km(U)})),[c,r.projects]),[u,m]=h.useState(null),[p,g]=h.useState(()=>{var M;try{return((M=Xe(a))==null?void 0:M.getItem(Mo))!=="hidden"}catch{return!0}}),[f,y]=h.useState(()=>{var M;try{return((M=Xe(a))==null?void 0:M.getItem(Eo))==="rigs"?"rigs":"projects"}catch{return"projects"}}),w=M=>{var z;y(M);try{(z=Xe(a))==null||z.setItem(Eo,M)}catch{}},S=()=>{var z;const M=!p;g(M);try{(z=Xe(a))==null||z.setItem(Mo,M?"shown":"hidden")}catch{}},b=fj([x,i]),j=M=>{m(null),s?xs({name:"atelier",sessionId:M}):Zs({name:"atelier",sessionId:M})},N=()=>xs({name:"atelier"}),$={open:j,room:M=>{s&&N(),m(M)},chat:()=>Zs({name:"chat"})},A=o.filter(M=>M.state!=="exited").length,E=o.filter(ku).length,k=`${i?`${d.agents.offline} · `:""}${d.atelier.subtitle(A,E,Ec(o).working)}`,T=u?jj(x,u):null,C=x.rooms.filter(M=>!M.rig),I=x.rooms.filter(M=>M.rig),P=f==="rigs"?[...I,...C]:[...C,...I],L=s?r.sessions.get(s):void 0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"atelier-col",children:[e.jsxs("header",{className:"flex flex-none items-center gap-3 pt-3 pb-3",children:[e.jsx("h1",{className:"text-title font-semibold tracking-[-.3px]",children:d.atelier.title}),e.jsx("span",{className:"min-w-0 truncate text-meta text-muted",children:k}),e.jsx("span",{className:"flex-1"}),e.jsx("div",{role:"group","aria-label":d.sessions.groupBy.label,className:"flex flex-none overflow-hidden rounded-lg border border-input",children:Ir.map(M=>e.jsx("button",{type:"button","aria-pressed":M===f,onClick:()=>w(M),className:"grid h-9 place-items-center px-3.5 text-[13px] font-medium text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:d.sessions.groupBy[M]},M))}),e.jsxs("button",{type:"button","aria-pressed":!p,onClick:S,className:Oe({size:"sm",className:"flex-none"}),children:[e.jsx(F,{name:"eye",className:"size-4"}),p?d.sessions.helpersHide:d.sessions.helpersShow]}),e.jsx(Za,{})]}),e.jsx("div",{className:"mb-3 flex-none empty:hidden",children:e.jsx(gs,{})}),e.jsxs("div",{className:`atelier-ipad${i?" atelier-frozen":""}`,children:[e.jsxs("div",{className:"zoom-controls",role:"toolbar","aria-label":d.atelier.zoom.bar,children:[e.jsx("button",{type:"button",className:"ledge-btn","data-variant":"ghost","aria-label":d.atelier.zoom.out,onClick:()=>b.step(-1),children:"−"}),e.jsx("button",{type:"button",className:"zoom-level","aria-label":d.atelier.zoom.reset,onClick:()=>b.zoomTo(1),children:d.percent(Math.round(b.zoom*100))}),e.jsx("button",{type:"button",className:"ledge-btn","data-variant":"ghost","aria-label":d.atelier.zoom.in,onClick:()=>b.step(1),children:"+"}),e.jsx("span",{className:"zoom-sep"}),e.jsxs("button",{type:"button",className:"ledge-btn zoom-fit","data-variant":b.fitted?"secondary":"ghost","aria-pressed":b.fitted,title:d.atelier.zoom.fitTitle,onClick:b.fit,children:[e.jsx(yn,{d:hj,size:13}),d.atelier.zoom.fit]})]}),e.jsxs("div",{className:"overview-scroll atelier",role:"region","aria-label":d.atelier.region,ref:b.scrollRef,children:[e.jsx("div",{className:"atelier-floor",children:e.jsxs("div",{ref:b.shellRef,className:`office-shell${i?" office-paused":""}`,children:[e.jsx(sj,{count:A,frozen:i,...(R=r.device)!=null&&R.chat?{onOpen:$.chat}:{}}),e.jsx("div",{className:`project-grid ${P.length===1?"focused":""}`,children:P.map(({project:M,tables:z,rig:U})=>e.jsx(ej,{project:M,tables:z,...U?{rig:U}:{},width:wm(z,Jn,Ts),act:$,children:z.map(H=>e.jsx(Jb,{table:H,project:M,color:bn[M.color],frozen:i,act:$,helpers:p},H.key))},M.id))}),e.jsx(tj,{sessions:x.unassigned,frozen:i,act:$})]})}),e.jsx(nj,{})]})]})]}),s&&e.jsx(Cu,{label:d.atelier.session((L==null?void 0:L.name)??""),onClose:N,children:n?e.jsx(or,{store:t,sessionId:s,requestKey:n,onReconnect:l,panel:{onBack:()=>xs({name:"atelier",sessionId:s}),onClose:N}},`${s}:request`):e.jsx(fr,{store:t,sessionId:s,storage:a,onReconnect:l,panel:{onClose:N}},s)}),!s&&T&&u&&e.jsx(bj,{store:t,name:T.name,ids:T.ids,onOpen:j,onClose:()=>m(null)})]})}const Nj=500,kj=10;function Mu(t){const s=h.useRef(null),n=h.useRef(null),a=h.useRef(!1),l=()=>{s.current&&clearTimeout(s.current),s.current=null},r=()=>{var i;l(),a.current=!0;try{(i=navigator.vibrate)==null||i.call(navigator,10)}catch{}t()};return{onPointerDown:i=>{i.button>0||(a.current=!1,n.current={x:i.clientX,y:i.clientY},l(),s.current=setTimeout(r,Nj))},onPointerMove:i=>{const o=n.current;o&&Math.hypot(i.clientX-o.x,i.clientY-o.y)>kj&&l()},onPointerUp:l,onPointerCancel:l,onPointerLeave:l,onContextMenu:i=>{i.preventDefault(),a.current||r()},onClickCapture:i=>{a.current&&(i.preventDefault(),i.stopPropagation(),a.current=!1)}}}function Eu({store:t,session:s,current:n,onLeave:a,onReconnect:l,display:r,model:i,onModel:o}){var k,T;const c=fe(t),x=Yt(),[u,m]=h.useState(!1),[p,g]=h.useState(!1),f=i??p,y=o??g,[w,S]=h.useState(!1),b=wn(s),j=It(),N=Ya(),$=n==="terminal"&&j&&!N&&[s.project,s.branch].filter(Boolean).join(" · ")||void 0,A=!!((k=c.daemon)!=null&&k.sessionClose)&&!s.readOnly,E=Ar(s,c.ops,((T=c.daemon)==null?void 0:T.boot)??null,x);return e.jsxs(e.Fragment,{children:[e.jsx(ea,{back:e.jsx(ls,{fallback:{name:"sessions"},label:d.thread.back}),tool:s.tool,name:s.name,dot:b,pulse:b==="work"&&c.fresh,sub:$,more:e.jsxs(e.Fragment,{children:[e.jsx(ju,{sessionId:s.id,current:n,...a?{onLeave:a}:{}}),e.jsx("button",{type:"button","aria-haspopup":"dialog","aria-label":d.sessions.moreOf(s.name),title:d.sessions.more,onClick:()=>m(!0),className:$t({className:u?"bg-raised text-fg":"text-muted"}),children:e.jsx(F,{name:"more"})})]})}),u&&e.jsx(ei,{store:t,session:s,closable:A,closing:E,onClose:()=>m(!1),onModel:()=>{m(!1),y(!0)},onCloseSession:()=>{m(!1),S(!0)},display:r&&{value:r.value,onToggle:()=>{r.onToggle(),m(!1)}}}),f&&Js(c.daemon,s)&&e.jsx(al,{store:t,session:s,onClose:()=>y(!1)}),w&&e.jsx(ri,{store:t,session:s,mode:"close",onClose:()=>S(!1),onSent:()=>S(!1),onReconnect:l})]})}function vj({store:t,session:s,onDone:n}){var m,p;const a=fe(t),l=Yt(),[r,i]=h.useState("menu"),o=!!((m=a.daemon)!=null&&m.sessionClose)&&!s.readOnly,c=Ar(s,a.ops,((p=a.daemon)==null?void 0:p.boot)??null,l),x=s.rig?d.sessions.seatOf(s.rig.role??s.name,s.rig.name):s.project,u=g=>{n(),Zs(g)};return r==="model"?Js(a.daemon,s)?e.jsx(al,{store:t,session:s,onClose:n}):null:r==="close"?e.jsx(ri,{store:t,session:s,mode:"close",onClose:n,onSent:n}):e.jsx(ei,{store:t,session:s,closable:o,closing:c,onClose:n,who:x,onModel:()=>i("model"),onCloseSession:()=>i("close"),lead:[{icon:"sessions",label:d.atoi.openThread,onClick:()=>u({name:"thread",sessionId:s.id})},{icon:"terminal",label:d.thread.terminal(s.name),onClick:()=>u({name:"terminal",sessionId:s.id})}]})}function wj({by:t,onBy:s,helpers:n,onHelpers:a}){const l=d.sessions.groupBy;return e.jsxs("div",{className:"flex flex-none items-center gap-2",children:[e.jsx("div",{role:"group","aria-label":l.label,className:"grid flex-1 grid-cols-2 gap-[3px] rounded-[10px] border border-line p-[3px]",children:Ir.map(r=>e.jsx("button",{type:"button","aria-pressed":r===t,onClick:()=>s(r),className:"h-[34px] rounded-[7px] text-[13px] font-medium whitespace-nowrap text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:l[r]},r))}),e.jsx("button",{type:"button",onClick:a,"aria-label":n?d.sessions.helpersHide:d.sessions.helpersShow,title:n?d.sessions.helpersHide:d.sessions.helpersShow,className:`grid size-[42px] flex-none place-items-center rounded-control border ${n?"border-input text-fg":"border-ring text-fg"}`,children:e.jsx(F,{name:"eye",className:"size-[18px]"})})]})}const Ao="inline-flex items-center gap-1.5 rounded-lg border bg-bg px-2.5 select-none [-webkit-touch-callout:none]";function Sj({session:t,rig:s,helpers:n,pressed:a,onPress:l}){const r=Mu(()=>l(t)),i=wn(t),o=i==="perm"?"border-destructive/50":i==="ask"?"border-attention/50":"border-line",c=ae({name:"thread",sessionId:t.id}),x=d.atelier.session(t.name);return e.jsxs(e.Fragment,{children:[e.jsxs("a",{href:c,"aria-label":x,...r,className:`${Ao} h-10 text-[13px] font-medium ${o} ${t.state==="exited"?"opacity-60":""} ${a?"shadow-[0_0_0_2px_var(--color-ring)]":""}`,children:[!s&&e.jsx(fs,{tool:t.tool}),t.name,e.jsx(Ie,{state:i}),!n&&t.helpers.length>0&&e.jsx("span",{"aria-label":d.sessions.kidsLabel(t.helpers.length),className:"ml-0.5 rounded-lg border border-input px-1.5 font-mono text-[11px] leading-[18px] text-muted",children:d.sessions.kids(t.helpers.length)})]}),n&&t.helpers.map(u=>e.jsxs("a",{href:c,"aria-label":d.atelier.helperSeat(u.kind,t.name,u.task),...r,className:`${Ao} h-8 border-dashed border-line text-[12px] text-muted`,children:[u.kind,e.jsx(Ie,{state:Cm(u)})]},u.id))]})}function $j({island:t,rigs:s,helpers:n,pressed:a,onPress:l}){const r=d.sessions,i=t.kind==="rig",o=$m(t),c=i?t.name==="kernel"&&s?r.kernelTag:r.rigTag:null,x=i?r.seats(t.sessions.length):d.atelier.plaqueCounts(t.sessions.length);return e.jsxs("section",{"aria-label":i?r.rigGroup(t.name):t.name,className:`flex flex-none flex-col gap-2.5 rounded-[10px] border bg-surface px-3 pt-2.5 pb-3 dark:bg-[oklch(0.18_0_0)] ${i?"border-task/45":"border-line"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 text-[13px]",children:[i&&e.jsx(Ie,{state:"rig"}),e.jsx("b",{className:"font-semibold",children:t.name}),o&&e.jsx(Ie,{state:o}),c?e.jsx("small",{className:"text-[12px] text-muted",children:c}):e.jsx("small",{className:"text-[12px] text-muted",children:x}),i&&c===r.rigTag&&(s?e.jsx("a",{href:ae({name:"rigs"}),className:"ml-auto text-[12px] text-muted underline underline-offset-2",children:x}):e.jsx("span",{className:"ml-auto text-[12px] text-muted",children:x}))]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:t.sessions.map(u=>e.jsx(Sj,{session:u,rig:i,helpers:n,pressed:a===u.id,onPress:l},u.id))})]})}function Cj({sessions:t,by:s,onBy:n,helpers:a,onHelpers:l,rigs:r,pressed:i,onPress:o}){const c=en(),x=t.filter(p=>p.state!=="exited").length,u=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"grid size-[30px] flex-none place-items-center overflow-hidden",children:e.jsx(zr,{size:30,theme:c,frozen:!0})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("b",{className:"font-semibold",children:d.sessions.deskTitle}),e.jsxs("small",{className:"text-[12px] text-muted",children:[d.atelier.desk," · ",d.atelier.watching(x)]})]})]});return e.jsxs(e.Fragment,{children:[e.jsx(wj,{by:s,onBy:n,helpers:a,onHelpers:l}),Sm(t,s).map(p=>e.jsx($j,{island:p,rigs:r,helpers:a,pressed:i,onPress:o},p.id)),e.jsxs("a",{href:ae({name:"chat"}),className:"flex min-h-[52px] flex-none items-center gap-2.5 rounded-[10px] border border-line bg-surface px-3 py-1.5 text-[13.5px] dark:bg-[oklch(0.18_0_0)]",children:[u,e.jsx(F,{name:"chevron",className:"size-4 text-muted"})]})]})}const To=`${$s}sessions.filter`,Mj=t=>Cc.includes(t);function Ej(t,s){const n=Xe(s),[a,l]=h.useState(()=>{if(t)return t;try{const i=n==null?void 0:n.getItem(To);return Mj(i)?i:"all"}catch{return"all"}}),r=i=>{l(i);try{n==null||n.setItem(To,i)}catch{}};return h.useEffect(()=>{t&&r(t)},[t]),[a,r]}function _l(t,s,n,a){const l=Xe(a),[r,i]=h.useState(()=>{try{const c=l==null?void 0:l.getItem(`${$s}${t}`);return s.includes(c)?c:n}catch{return n}});return[r,c=>{i(c);try{l==null||l.setItem(`${$s}${t}`,c)}catch{}}]}const Au=["list","atelier"];function Aj({value:t,onChange:s}){const n=d.sessions.mode;return e.jsx("div",{role:"group","aria-label":n.label,className:"flex flex-none overflow-hidden rounded-lg border border-input",children:Au.map(a=>e.jsx("button",{type:"button","aria-pressed":a===t,onClick:()=>s(a),className:"grid h-9 place-items-center px-3.5 text-[13px] font-medium text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:n[a]},a))})}function Tj({value:t,counts:s,onChange:n}){const a=d.sessions.filter;return e.jsx("div",{role:"group","aria-label":a.label,className:"flex flex-none rounded-lg border border-input p-0.5",children:Cc.map(l=>e.jsxs("button",{type:"button","aria-pressed":l===t,onClick:()=>n(l),className:"inline-flex h-8 min-w-0 flex-1 items-center justify-center gap-1.5 rounded-md text-[13px] font-medium whitespace-nowrap text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:[a[l],e.jsx("span",{className:"font-mono text-meta",children:s[l]})]},l))})}function _j({session:t,filter:s,offline:n,threshold:a,now:l,closing:r,pressed:i,onPress:o}){const c=Zn(),x=Mu(()=>o(t)),u=(c.name==="thread"||c.name==="terminal")&&c.sessionId===t.id,m=wn(t),p=Mm(t),g=Ac(t),f=s==="working"?g===void 0?void 0:`${g} %`:Am(t);return e.jsx(hn,{href:ae({name:"thread",sessionId:t.id}),selected:u,stale:n,press:x,pressed:i,lead:e.jsxs(e.Fragment,{children:[e.jsx(Ie,{state:m,pulse:m==="work"&&!n}),e.jsx(fs,{tool:t.tool})]}),title:e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:t.name}),p>0&&e.jsx("span",{"aria-label":d.sessions.kidsLabel(p),className:"ml-1.5 font-mono text-small text-muted",children:d.sessions.kids(p)})]}),sub:r?e.jsx("span",{className:"text-attention",children:d.chat.closing}):e.jsx("span",{className:m==="ask"?"text-attention":void 0,children:Em(t,s,l)}),...m==="perm"?{subTone:"perm"}:{},...f!==void 0?{meta:f,metaWarn:s==="working"&&g!==void 0&&g/100>=a}:{}})}function Ij({group:t,children:s}){const n=t.kind==="rig",a=n?d.sessions.rigGroup(t.name):t.name;return e.jsxs("section",{"aria-label":a,className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-0.5 text-small font-semibold text-muted",children:[n&&e.jsx(Ie,{state:"rig"}),a,e.jsx("span",{className:"font-normal",children:t.sessions.length})]}),e.jsx(ps,{...n?{tone:"rigs"}:{},children:s})]})}function Rj({store:t,filter:s,storage:n}){var P,L;const a=fe(t),l=Yt(),[r,i]=Ej(s,n),o=It(),[c,x]=_l("sessions.mode",Au,"list",n),[u,m]=_l("sessions.groupBy",Ir,"projects",n),[p,g]=_l("sessions.helpers",["shown","hidden"],"shown",n),[f,y]=h.useState(null),w=f?a.sessions.get(f):void 0,S=!o&&c==="atelier",b=[...a.sessions.values()],j=Ec(b),N=Mc(b,r),$=!a.fresh,A=((P=a.device)==null?void 0:P.contextNear)??kn,E=$?a.syncedAt?d.link.lastKnownAt(Fe(a.syncedAt)):d.agents.offline:void 0,k=e.jsxs("a",{href:ae({name:"launch"}),className:Oe({variant:"primary",size:"sm",className:"flex-none"}),children:[e.jsx(F,{name:"plus",className:"size-4"}),d.sessions.new]}),T=(R,M)=>e.jsx("button",{type:"button",onClick:()=>i(R),className:Oe({size:"xs"}),children:M}),C=d.sessions,I=N.length===0&&b.length>0&&e.jsx(ps,{label:C.filter[r],children:r==="waiting"?e.jsx(Qt,{framed:!1,glyph:null,title:C.filterEmpty,body:C.filterEmptyBody(j.working),action:T("all",C.seeAll)}):j.waiting>0?e.jsx(Qt,{framed:!1,glyph:null,title:C.emptyWorking.title,body:C.emptyWorking.waiting(j.waiting),action:T("waiting",C.seeWaiting)}):e.jsx(Qt,{framed:!1,glyph:null,title:C.emptyWorking.title,body:C.emptyWorking.idle,action:T("all",C.seeAll)})});return e.jsxs(Os,{title:d.agents.title,subtitle:E,bodyClassName:"flex flex-col gap-2.5",actions:o?void 0:e.jsxs(e.Fragment,{children:[e.jsx(Aj,{value:c,onChange:x}),k]}),wideActions:o?k:void 0,children:[w&&e.jsx(vj,{store:t,session:w,onDone:()=>y(null)}),b.length===0?e.jsx(ps,{label:d.agents.empty,children:e.jsx(Qt,{list:!0,glyph:e.jsx(F,{name:"sessions"}),title:d.agents.empty,body:d.agents.emptyHint,action:e.jsxs("a",{href:ae({name:"launch"}),className:Oe({variant:"primary",size:"sm"}),children:[e.jsx(F,{name:"plus",className:"size-4"}),d.sessions.newSession]})})}):S?e.jsx(Cj,{sessions:b,by:u,onBy:m,helpers:p==="shown",onHelpers:()=>g(p==="shown"?"hidden":"shown"),rigs:!!((L=a.daemon)!=null&&L.rigs),pressed:f,onPress:R=>y(R.id)}):e.jsxs(e.Fragment,{children:[e.jsx(Tj,{value:r,counts:j,onChange:i}),N.map(R=>e.jsx(Ij,{group:R,children:R.sessions.map(M=>e.jsx(_j,{session:M,filter:r,offline:$,threshold:A,now:l,closing:im(M,a.ops,l),pressed:f===M.id,onPress:z=>y(z.id)},M.id))},R.id)),I]})]})}const _o=34,Oj=120;function Lj({value:t,onChange:s,onSend:n,canSend:a,images:l,running:r,offline:i,onStop:o,fieldRef:c}){const x=h.useRef(null),u=c??x;h.useLayoutEffect(()=>{const p=u.current;p&&(p.style.height=`${_o}px`,p.style.height=`${Math.min(Oj,Math.max(_o,p.scrollHeight))}px`)},[t,u]);const m=r||i;return e.jsxs("div",{className:"group flex flex-none flex-col gap-1.5 pt-1.5 pb-2",children:[l.items.length>0&&e.jsx(nu,{items:l.items,onRemove:l.remove,size:{w:72,h:54},removeLabel:d.images.remove,lang:cc}),e.jsxs("div",{className:`flex min-w-0 items-end gap-2 rounded-[10px] border border-input bg-surface py-[5px] pr-[5px] pl-3 focus-within:border-ring focus-within:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)] ${i?"opacity-55":""}`,children:[e.jsx("label",{htmlFor:"chat-ask",className:"sr-only",children:d.chat.field}),e.jsx("textarea",{id:"chat-ask",ref:u,rows:1,value:i?"":t,disabled:i,maxLength:Qn,enterKeyHint:"enter",placeholder:r?d.chat.answering:d.chat.placeholder,onChange:p=>s(p.target.value),onPaste:p=>{const g=lu(p);g.length===0||m||(p.preventDefault(),l.add(g))},onKeyDown:p=>{p.key!=="Enter"||p.nativeEvent.isComposing||p.shiftKey||!qa()||(p.preventDefault(),a&&n())},className:"max-h-[120px] min-h-[34px] min-w-0 flex-1 resize-none bg-transparent py-[6px] text-base leading-[22px] text-fg outline-none placeholder:text-muted"}),r?e.jsx("button",{type:"button",onClick:o,"aria-label":d.chat.stop,title:d.chat.stop,className:"grid size-9 flex-none place-items-center rounded-lg bg-raised text-fg",children:e.jsx(F,{name:"stop",className:"size-4"})}):e.jsx("button",{type:"button",disabled:!a,onClick:n,"aria-label":d.chat.send,title:d.chat.send,className:"grid size-9 flex-none place-items-center rounded-lg bg-primary text-primary-fg disabled:opacity-40",children:e.jsx(F,{name:"send",className:"size-[18px]"})})]}),e.jsxs("p",{className:"hidden items-center gap-1 text-[12px] leading-4 text-muted group-focus-within:flex",children:[e.jsx(au,{onFiles:l.add,disabled:m,className:"text-[12px] leading-4 text-muted disabled:opacity-50",children:d.chat.plusImage}),qa()&&e.jsxs("span",{children:["· ",d.chat.enterSends]})]}),l.error&&e.jsx("p",{role:"alert",className:"text-body text-attention",children:l.error})]})}const ii=t=>t.state==="done"||t.state==="refused"||t.state==="dropped",Tu=t=>t.owner===Hl,_u=t=>(t.giver??Hl)===Hl&&!Tu(t);function zj(t){return[...t].filter(s=>Tu(s)&&!ii(s)).sort((s,n)=>s.at.localeCompare(n.at))}function Dj(t){return[...t].filter(s=>_u(s)&&ii(s)&&!s.seen).sort((s,n)=>s.updatedAt.localeCompare(n.updatedAt))}function Fj(t){return[...t].filter(s=>_u(s)&&!ii(s)).sort((s,n)=>n.updatedAt.localeCompare(s.updatedAt))}const Il=De({variant:"primary",size:"sm",className:"min-w-[64px] flex-none"}),fa=De({size:"sm",className:"min-w-[64px] flex-none"}),Rl="w-full rounded-control border border-line bg-surface px-2.5 py-2 text-body text-fg",un=t=>t.replace(/\s*[\r\n]+\s*/g," ").trim();function Pj({task:t,store:s,fresh:n}){const a=d.chat.point.note,l=t.brain,r=h.useId(),[i,o]=h.useState(!1),[c,x]=h.useState(l.fact),[u,m]=h.useState(l.title??l.note),[p,g]=h.useState(l.when??""),[f,y]=h.useState(!1),[w,S]=h.useState(null),b=async $=>{y(!0),S(null);const A=un(c),E=$?{yes:$,...A&&A!==l.fact?{text:A}:{},...l.create&&un(u)?{title:un(u)}:{},...l.create&&un(p)?{when:un(p)}:{}}:{yes:$},k=await s.answerNote(t.id,E);y(!1),k.status!=="applied"&&S(k.status==="rejected"&&k.reason==="confirm_required"?a.confirmRequired:k.status==="rejected"&&k.reason==="stale"?a.stale:k.status==="cancelled"?a.cancelled:k.status==="expired"?a.expired:a.failed)},j=l.kind==="flag"?a.flag(l.note):l.create?a.create(l.note):a.add(l.note),N=!n||f;return e.jsxs("div",{className:"flex flex-col gap-2 rounded-control bg-raised p-2.5","data-note-proposal":t.id,children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-1.5 text-body",children:[e.jsx(ta,{tone:"attention",label:a.tag}),e.jsx("span",{className:"font-medium",children:t.giverName??d.chat.point.someone}),e.jsx("span",{className:"text-muted",children:j})]}),l.create&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{htmlFor:`${r}t`,className:"flex flex-col gap-1 text-small text-muted",children:[a.titleField,e.jsx("input",{id:`${r}t`,className:Rl,value:u,disabled:N,onChange:$=>m($.target.value)})]}),e.jsxs("label",{htmlFor:`${r}w`,className:"flex flex-col gap-1 text-small text-muted",children:[a.whenField,e.jsx("input",{id:`${r}w`,className:Rl,value:p,disabled:N,onChange:$=>g($.target.value)})]})]}),i?e.jsxs("label",{htmlFor:`${r}f`,className:"flex flex-col gap-1 text-small text-muted",children:[a.field,e.jsx("textarea",{id:`${r}f`,className:Rl,rows:3,value:c,disabled:N,onChange:$=>x($.target.value)})]}):e.jsx("p",{className:"m-0 whitespace-pre-wrap break-words rounded-control bg-surface px-2.5 py-2 text-body",children:l.fact}),l.source&&!i&&e.jsx("span",{className:"break-words text-small text-muted",children:a.source(l.source)}),w&&e.jsx("p",{role:"alert",className:"m-0 text-small text-approval",children:w}),e.jsx("div",{className:"flex flex-wrap gap-2",children:l.kind==="flag"?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Il,disabled:N,onClick:()=>{b(!0)},children:a.mark}),e.jsx("button",{type:"button",className:fa,disabled:N,onClick:()=>{b(!1)},children:a.ignore})]}):i?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Il,disabled:N||!un(c),onClick:()=>{b(!0)},children:a.editYes}),e.jsx("button",{type:"button",className:fa,disabled:N,onClick:()=>{o(!1),x(l.fact)},children:a.cancel})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Il,disabled:N,onClick:()=>{b(!0)},children:l.create?a.createYes:a.yes}),e.jsx("button",{type:"button",className:fa,disabled:N,onClick:()=>o(!0),children:a.edit}),e.jsx("button",{type:"button",className:fa,disabled:N,onClick:()=>{b(!1)},children:a.no})]})})]})}const In=De({size:"sm",className:"min-w-[64px] flex-none"}),Bj=De({variant:"primary",size:"sm",className:"min-w-[64px] flex-none"}),Io="mt-1 text-meta tracking-[.4px] text-muted";function ha({tone:t}){return e.jsx("span",{"aria-hidden":"true",className:`size-2 flex-none rounded-full ${t==="ok"?"bg-ok":t==="danger"?"bg-approval":"bg-attention"}`})}function qj(t){return t.state==="done"?d.chat.point.finished:t.state==="refused"?d.chat.point.refused:d.chat.point.dropped}function Hj({store:t,sessions:s,tasks:n,syncedAt:a,fresh:l,threshold:r=kn,onAnswer:i,usage:o=[],usageAlert:c=null}){const x=Yt(),[u,m]=h.useState(null),p=new Map(s.map(k=>[k.id,k])),g=Wt(s),f=zj(n.values()),y=Dj(n.values()),w=s.filter(k=>k.state!=="exited"&&!k.handover&&k.context&&k.context.used/k.context.window>=r),S=Fj(n.values()).slice(0,5),b=d.chat.point,j=la(o,x,l),N=l?uf(j,c,x):[],$=g.length+N.length+f.length+y.length+w.length,A=(k,T,C)=>{const I=g.find(P=>P.sessionId===k&&P.key===T);I&&(m(`${k}/${T}`),t.decide(k,C,{expect:{key:I.key,kind:I.kind,text:I.text}}))},E=k=>{t.seeTask(k.id),Zs({name:"thread",sessionId:k.owner})};return e.jsxs("section",{"aria-label":b.label,className:"flex flex-col gap-2.5 rounded-card border border-line bg-surface p-4",children:[e.jsxs("h2",{className:"flex items-baseline gap-2 text-base font-bold",children:[b.title,a&&e.jsx("span",{className:"text-small font-normal text-muted",children:b.ago(jn(a,x))})]}),$===0&&e.jsx("p",{className:"text-body text-muted",children:b.calm}),$>0&&e.jsxs("div",{role:"group","aria-label":b.yoursLabel,className:"flex flex-col gap-2",children:[e.jsxs("h3",{className:Io,children:[b.yours," · ",$]}),g.map(k=>{p.get(k.sessionId);const T=k.kind==="permission"&&k.risk!=="high"&&k.source!=="rpc",C=`${k.sessionId}/${k.key}`;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ha,{tone:"danger"}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5 text-body",children:[e.jsx("span",{className:"font-medium",children:k.botName}),e.jsx("span",{className:"min-w-0 truncate font-mono",children:vn(k)})]}),T?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Bj,disabled:!l||u===C,onClick:()=>A(k.sessionId,k.key,"accept"),children:b.yes}),e.jsx("button",{type:"button",className:In,disabled:!l||u===C,onClick:()=>A(k.sessionId,k.key,"deny"),children:b.no})]}):e.jsx("a",{href:ae({name:"request",sessionId:k.sessionId,key:k.key}),className:In,children:b.see})]},C)}),N.map(({harness:k,window:T,tone:C})=>{const I=ai(T);return e.jsxs("div",{"data-usage-over":C,className:"flex items-center gap-2","aria-label":C==="red"?b.reachedLabel(b.harnessShort[k]??k,I):b.overLabel(b.harnessShort[k]??k,I,T.pct),children:[e.jsx("span",{"aria-hidden":"true",className:`flex size-5 flex-none items-center justify-center rounded-md ${C==="red"?"bg-danger-bg text-approval":"text-attention"}`,style:C==="red"?void 0:{background:"var(--status-warning-soft)"},children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("path",{d:"M12 14l4-4"}),e.jsx("path",{d:"M3.3 19a10 10 0 1 1 17.4 0"})]})}),e.jsxs("span",{className:"min-w-0 flex-1 text-body",children:[b.harnessShort[k]??k," · ",I," ",e.jsx("b",{className:`font-medium ${li[C]}`,children:d.percent(T.pct)})]}),T.resetsAt&&e.jsxs("span",{className:"flex-none whitespace-nowrap text-small text-muted",children:["↺ ",Wr(T.resetsAt,x,!0)]})]},`usage:${k}:${T.kind}:${T.model??T.pool??""}`)}),f.map(k=>k.brain?e.jsx(Pj,{task:{...k,brain:k.brain},store:t,fresh:l},`decision:${k.id}`):e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"mt-2 flex",children:e.jsx(ha,{tone:"attention"})}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5 text-body",children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx(ta,{tone:"attention",label:b.decision}),e.jsx("span",{className:"font-medium",children:k.giverName??b.someone}),e.jsx("span",{className:"text-muted",children:b.asks})]}),e.jsx("span",{className:"break-words",children:k.title}),k.text&&e.jsx("span",{className:"whitespace-pre-wrap break-words text-small text-muted",children:k.text})]}),i&&e.jsx("button",{type:"button",className:In,"aria-label":b.answerLabel(k.title),onClick:()=>i(k),children:b.answer})]},`decision:${k.id}`)),y.map(k=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ha,{tone:k.state==="done"?"ok":"attention"}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5 text-body",children:[e.jsx("span",{className:"font-medium",children:k.ownerName}),e.jsx("span",{children:qj(k)})]}),e.jsx("button",{type:"button",className:In,onClick:()=>E(k),children:b.see})]},k.id)),w.map(k=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ha,{tone:"attention"}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5 text-body",title:b.nearHint,children:[e.jsx("span",{className:"font-medium",children:k.name}),e.jsxs("span",{className:"text-attention",children:["· ",b.near(Math.round(k.context.used/k.context.window*100))]})]}),e.jsx("a",{href:ae({name:"thread",sessionId:k.id}),className:In,children:b.see})]},`near:${k.id}`))]}),e.jsx(ob,{usage:j,now:x,alert:c}),S.length>0&&e.jsxs("div",{role:"group","aria-label":b.givenLabel,className:"flex flex-col gap-2",children:[e.jsx("h3",{className:Io,children:b.given}),S.map(k=>e.jsxs("a",{href:ae({name:"thread",sessionId:k.owner}),className:"flex items-center gap-2 text-body",children:[e.jsx("code",{className:"flex-none font-mono text-small text-muted",children:k.id}),e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[k.title," ",e.jsxs("span",{className:"text-muted",children:["→ ",k.ownerName]})]}),e.jsx("span",{className:k.state==="taken"?"text-info":"text-muted",children:b.state[k.state]})]},k.id))]})]})}const Xt=()=>d.chat.history,Ea=t=>{const s=new Date(t);return`${s.getHours()}:${String(s.getMinutes()).padStart(2,"0")}`},ga=t=>`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`;function Iu(t,s){const n=new Date(t);if(ga(n)===ga(s))return Xt().today;const a=new Date(s);return a.setDate(s.getDate()-1),ga(n)===ga(a)?Xt().yesterday:n.toLocaleDateString(dt,{weekday:"short",day:"numeric",month:"short"})}const Uj=(t,s)=>`${Iu(t.startedAt,s)}, ${Ea(t.startedAt)}`,Wj="flex min-h-12 w-full items-center gap-3 border-b border-line px-3.5 py-2 text-left last:border-b-0",Kj="px-1 pt-1.5 text-[12px] font-medium text-muted";function Ol({first:t,sub:s,current:n=!1,onClick:a}){return e.jsxs("button",{type:"button",onClick:a,"aria-current":n||void 0,className:`${Wj} ${n?"bg-raised":""}`,children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("b",{className:"truncate text-[14.5px] font-medium",children:Xt().quote(t)}),e.jsx("small",{className:"truncate text-[12px] text-muted",children:s})]}),!n&&e.jsx(F,{name:"chevron",className:"size-4 text-muted"})]})}function Ll({children:t}){return e.jsx("div",{className:"flex max-h-[55vh] flex-col overflow-y-auto rounded-[10px] border border-line",children:t})}function Vj({conversations:t,kept:s,turns:n,running:a,now:l,onClose:r,onReset:i,onOpen:o,onScrollTo:c}){const x=h.useId();if(!s){const p=n.filter(g=>g.question);return e.jsxs(ct,{labelledBy:x,onClose:r,children:[e.jsx("h2",{id:x,className:"text-base font-semibold",children:Xt().today}),p.length===0?e.jsx("p",{className:"text-body text-muted",children:Xt().none}):e.jsx(Ll,{children:p.map(g=>e.jsx(Ol,{first:g.question,sub:Ea(g.askedAt),onClick:()=>c(g.qid)},g.qid))})]})}const u=t.list,m=[];for(const p of(u==null?void 0:u.past)??[]){const g=Iu(p.startedAt,l),f=m.at(-1);(f==null?void 0:f.day)===g?f.items.push(p):m.push({day:g,items:[p]})}return e.jsxs(ct,{labelledBy:x,onClose:r,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{id:x,className:"flex-1 text-base font-semibold",children:Xt().title}),e.jsxs("button",{type:"button",disabled:a,onClick:i,className:Oe({size:"sm"}),children:[e.jsx(F,{name:"edit",className:"size-4"}),d.chat.reset]})]}),u&&(u.current||m.length>0)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[u.current&&e.jsx(Ll,{children:e.jsx(Ol,{current:!0,first:u.current.first,onClick:r,sub:[Xt().current,Xt().count(u.current.count),Xt().since(Ea(u.current.startedAt))].join(" · ")})}),m.map(p=>e.jsxs("section",{"aria-label":p.day,className:"flex flex-col gap-1",children:[e.jsx("h3",{className:Kj,children:p.day}),e.jsx(Ll,{children:p.items.map(g=>e.jsx(Ol,{first:g.first,sub:`${Xt().count(g.count)} · ${Ea(g.startedAt)}`,onClick:()=>o(g)},g.id))})]},p.day))]}),e.jsx("p",{className:"text-small text-muted",children:Xt().kept})]}),u&&!u.current&&m.length===0&&e.jsx("p",{className:"text-body text-muted",children:Xt().empty})]})}const br=3,jr=t=>`${t.sessionId}/${t.key}`;function Gj(t,s){return new Set(t.filter(n=>n.kind==="pane"||n.kind==="reply").flatMap(n=>{const a=n.id??(n.name?s.get(n.name):void 0);return a?[a]:[]}))}function Xj({store:t,items:s,onGo:n}){const a=sr(s.slice(0,br).map(r=>({id:jr(r),value:r}))),l=s.length-br;return a.entries.length===0?null:e.jsxs("div",{className:ni,children:[a.entries.map(r=>e.jsx(Qj,{store:t,item:r.value,ghost:r.ghost,onGone:()=>a.dismiss(r.id),onGo:n},r.id)),l>0&&e.jsx("a",{href:ae({name:"atoi"}),className:"text-small text-info underline underline-offset-2",children:d.chat.inAnswer.more(l)})]})}function Qj({store:t,item:s,ghost:n,onGone:a,onGo:l}){var c,x,u;const r=fe(t),i=Ls(),o=r.sessions.get(s.sessionId);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[!n&&e.jsx("span",{className:"text-[11.5px] text-muted",children:d.chat.inAnswer.request(s.botName)}),e.jsx(Kr,{store:t,item:s,session:o,mode:Lr(s,(c=r.capabilities)==null?void 0:c[s.tool],(o==null?void 0:o.readOnly)===!0),outcome:Un(s,[...r.sessions.values()],r.ops),fresh:r.fresh,ghost:n,changed:!1,onReread:()=>{},canConfirm:((x=r.device)==null?void 0:x.confirm)===!0&&i,enroll:i&&((u=r.device)==null?void 0:u.confirm)!==!0,onGone:a,onCheck:l})]})}function Yj({names:t}){return t.length===0?null:e.jsx("div",{className:ni,children:t.map(s=>e.jsxs("span",{className:"text-[11.5px] text-muted",children:[d.chat.inAnswer.settled," · ",s]},s))})}const Zj="kernel";function Jj(t,s){var l,r,i;const n=(r=(l=t.find(o=>o.rig&&o.rig.name!==Zj))==null?void 0:l.rig)==null?void 0:r.name,a=(i=t.find(o=>o.name&&!o.rig))==null?void 0:i.name;return[d.chat.suggestions.waiting,...s.getHours()<12?[d.chat.suggestions.summarize]:[],...n?[d.chat.suggestions.rig(n)]:a?[d.chat.suggestions.session(a)]:[]]}const Aa="grid size-11 flex-none place-items-center rounded-lg text-muted active:bg-raised disabled:opacity-40";function Ru({frozen:t,onClose:s,children:n}){return e.jsxs("header",{className:"bleed flex h-[58px] flex-none items-center gap-1.5 border-b border-line pr-1.5 pl-3.5",children:[e.jsx("span",{"aria-hidden":"true",className:"flex size-[22px] flex-none",children:e.jsx(hs,{size:22,frozen:t})}),e.jsx("h2",{className:"text-base font-semibold",children:d.chat.title}),e.jsx("span",{className:"flex-1"}),n,e.jsx(Ou,{onClose:s})]})}function Ou({onClose:t}){return e.jsx("button",{type:"button",onClick:t,"aria-label":d.chat.pane.close,title:d.chat.pane.close,className:Aa,children:e.jsx(F,{name:"close"})})}function Ro({store:t,onClose:s}){var Q,Y,ie,X,le;const n=fe(t),a=It(),l=pc(t),r=[...n.sessions.values()],[i,o]=h.useState(""),c=mu(t),[x,u]=h.useState(null),m=h.useRef(null),p=l.live!==null,g=!n.fresh,f=om(t),y=!!((Q=n.daemon)!=null&&Q.conversations),[w,S]=h.useState(!1),[b,j]=h.useState(null),N=h.useRef(new Map);zd(t);const $=h.useRef(null),[A,E]=h.useState(0);h.useEffect(()=>{const B=$.current;!A||!B||(B.focus(),B.setSelectionRange(B.value.length,B.value.length))},[A]);const k=B=>{u(null),o(d.chat.point.answerDraft(B.title,B.id,B.giverName??d.chat.point.someone)),E(v=>v+1)},T=h.useRef([]);h.useEffect(()=>{const B=l.error;(B==null?void 0:B.text)!==void 0&&(o(v=>v||B.text),T.current.length&&(c.putBack(T.current),T.current=[]),u(B.code==="offline"?null:{question:B.text,note:B.code==="busy"?d.chat.busy:d.chat.failed}),t.clearChatError())},[l.error,t]),h.useEffect(()=>{var B,v;(v=(B=m.current)==null?void 0:B.scrollIntoView)==null||v.call(B,{block:"end"})},[l.turns.length,(Y=l.live)==null?void 0:Y.text,(ie=l.live)==null?void 0:ie.steps.length,x]);const C=(B,v=[])=>{u(null),t.ask(B,v)},I=()=>{const B=i.trim();if(!B&&c.items.length===0||p||g||!c.ready)return;const v=c.ids();T.current=c.clear(),C(B,v),o("")},P=r.map(B=>({id:B.id,name:B.name,repo:B.repo,exited:B.state==="exited",state:B.state,helpers:B.helpers})),L=()=>{u(null),t.resetChat()},R=new Map,M=new Set;for(const B of r)B.name&&(R.has(B.name)?M.add(B.name):R.set(B.name,B.id));for(const B of M)R.delete(B);const z=Wt(r),U=new Set(z.map(jr)),H=l.turns.at(-1),V=!p&&(H==null?void 0:H.answer)!==void 0?H:void 0,ee=V?(()=>{const B=Gj(V.steps,R);return z.filter(v=>B.has(v.sessionId))})():[];if(V){const B=N.current.get(V.qid)??new Map;for(const v of ee.slice(0,br))B.set(jr(v),v.botName);N.current.set(V.qid,B)}const G=B=>B===(V==null?void 0:V.qid)?e.jsx(Xj,{store:t,items:ee}):e.jsx(Yj,{names:[...new Set([...N.current.get(B)??[]].filter(([v])=>!U.has(v)).map(([,v])=>v))]}),O=B=>({at:B,usage:n.usage??[],alert:n.usageAlert,fresh:n.fresh}),D=()=>{t.askConversations(),S(!0)},J=e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:D,"aria-haspopup":"dialog","aria-label":y?d.chat.history.title:d.chat.history.today,title:y?d.chat.history.title:d.chat.history.today,className:Aa,children:e.jsx(F,{name:"clock"})}),e.jsx("button",{type:"button",disabled:p,onClick:L,"aria-label":d.chat.reset,title:d.chat.reset,className:Aa,children:e.jsx(F,{name:"edit"})})]});if(b){const B=f.open[b.id];return e.jsxs(e.Fragment,{children:[e.jsx(ea,{name:Uj(b,new Date),back:e.jsx("button",{type:"button","aria-label":d.nav.backTo.chat,title:d.nav.backTo.chat,onClick:()=>j(null),className:$t({className:"text-muted"}),children:e.jsx(F,{name:"back"})}),...s?{more:e.jsx(Ou,{onClose:s})}:{}}),e.jsxs("p",{className:"bleed flex flex-none items-center gap-2 border-b border-line bg-raised px-3.5 py-2 text-small text-muted",children:[e.jsx(F,{name:"clock",className:"size-4 flex-none"}),d.chat.history.pastBanner]}),e.jsxs("main",{"data-tab-scroll":s?void 0:"",className:"flex min-h-0 flex-1 flex-col gap-2.5 overflow-y-auto overscroll-contain py-3 text-[14px]",children:[B&&"gone"in B&&e.jsx("p",{className:"px-1 text-body text-muted",children:d.chat.history.gone}),B&&"turns"in B&&B.turns.map(v=>{const _=B.limits.find(W=>W.qid===v.qid);return e.jsx(bo,{store:t,turn:v,list:P,canConfirm:!1,live:null,sessions:r.length,readOnly:!0,limits:_&&O(_.at)},v.qid)})]}),e.jsx("div",{className:"flex-none pt-1.5 pb-3",children:e.jsx("button",{type:"button",onClick:()=>j(null),className:Oe({variant:"primary",className:"w-full"}),children:d.chat.history.backToday})})]})}return e.jsxs(e.Fragment,{children:[s?e.jsx(Ru,{frozen:g,onClose:s,children:J}):e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-1 border-b border-line pr-1 pl-3.5",children:[e.jsxs("span",{className:"mr-1 flex items-center gap-2 text-[17px] font-semibold",children:[e.jsx("span",{"aria-hidden":"true",className:"flex size-7 flex-none",children:e.jsx(hs,{size:28,frozen:g})}),e.jsx("h1",{children:d.chat.title})]}),e.jsx(Za,{}),e.jsx("span",{className:"flex-1"}),J,!a&&e.jsx("a",{href:ae({name:"connection"}),"aria-label":d.nav.settings,title:d.nav.settings,className:Aa,children:e.jsx(F,{name:"gear"})})]}),e.jsxs("main",{"data-tab-scroll":s?void 0:"",className:"flex min-h-0 flex-1 flex-col gap-2.5 overflow-y-auto overscroll-contain py-3 text-[14px]",children:[e.jsx(gs,{}),l.turns.length===0&&!x&&e.jsxs("div",{className:"flex flex-1 flex-col justify-end gap-2.5",children:[e.jsx(Hj,{store:t,sessions:r,tasks:n.tasks,syncedAt:n.syncedAt,fresh:n.fresh,onAnswer:k,...((X=n.device)==null?void 0:X.contextNear)!==void 0?{threshold:n.device.contextNear}:{},usage:n.usage??[],usageAlert:n.usageAlert}),!g&&e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[Jj(r,new Date).map(B=>e.jsx("button",{type:"button",onClick:()=>C(B),className:"inline-flex h-[34px] items-center gap-1.5 rounded-full border border-input bg-surface px-3 text-[13px] text-fg",children:B},B)),((le=n.daemon)==null?void 0:le.launch)&&e.jsxs("a",{href:ae({name:"launch"}),className:"inline-flex h-[34px] items-center gap-1.5 rounded-full border border-dashed border-input px-3 text-[13px] text-muted",children:[e.jsx(F,{name:"plus",className:"size-3.5"}),d.chat.suggestions.newSession]})]})]}),l.turns.map(B=>{var v,_;return e.jsx("div",{id:`turn-${B.qid}`,className:"contents",children:e.jsx(bo,{store:t,turn:B,list:P,canConfirm:!!((v=n.device)!=null&&v.confirm),live:((_=l.live)==null?void 0:_.qid)===B.qid?l.live:null,sessions:r.length,...!p&&!g?{onAskAgain:W=>C(W)}:{},limits:l.limits[B.qid]!==void 0?O(l.limits[B.qid]):void 0,inAnswer:G(B.qid)})},B.qid)}),x&&e.jsxs("div",{className:"flex flex-col gap-1.5",children:[x.question&&e.jsx("div",{className:"max-w-[85%] self-end whitespace-pre-wrap break-words rounded-[12px_12px_4px_12px] bg-raised px-3 py-2",children:x.question}),e.jsx("p",{role:"status",className:"text-[13.5px] text-attention",children:x.note})]}),e.jsx("div",{ref:m})]}),e.jsx(Lj,{value:i,onChange:o,onSend:I,canSend:(i.trim()!==""||c.items.length>0)&&c.ready&&!p&&!g,images:c,running:p,offline:g,onStop:()=>t.cancelAsk(),fieldRef:$}),g&&e.jsx("p",{role:"status",className:"flex-none pb-2 text-[13px] text-attention",children:d.chat.offline}),w&&e.jsx(Vj,{conversations:f,kept:y,turns:l.turns,running:p,now:new Date,onClose:()=>S(!1),onReset:()=>{S(!1),L()},onOpen:B=>{S(!1),t.openConversation(B.id),j(B)},onScrollTo:B=>{var v,_,W;S(!1),(W=(_=(v=document.getElementById(`turn-${B}`))==null?void 0:v.firstElementChild)==null?void 0:_.scrollIntoView)==null||W.call(_,{block:"start"})}})]})}const Xn=(t,s)=>(t.slice(0,s===void 0?void 0:s*4).match(/.{1,4}/g)??[]).join(" "),Lu=t=>Xn(t,6),e1=t=>Xn(t,2);function zu(){const t=globalThis;if(!t.Notification||!t.PushManager)return"unsupported";const s=t.navigator;return s&&"standalone"in s&&s.standalone!==!0?"unsupported":t.Notification.permission==="denied"?"denied":"ok"}const t1=t=>{const s=atob(t.replace(/-/g,"+").replace(/_/g,"/"));return Uint8Array.from(s,n=>n.charCodeAt(0))};function Du(t,s){return new Promise(n=>{const a=()=>{var i;const r=(i=t.getState().ops[s])==null?void 0:i.phase;return!r||us(r)&&r!=="uncertain"?!1:(l(),n(r==="applied"?"applied":"other"),!0)},l=t.subscribe(a);a()})}async function s1(t,s=(n,a)=>globalThis.fetch(n,a)){var a;if(zu()==="unsupported")return"unsupported";try{if(await Notification.requestPermission()!=="granted")return"denied";const l=await s("/push/key",{credentials:"same-origin",cache:"no-store"});if(l.status===404)return"unavailable";if(!l.ok)return"failed";const r=await l.json();if(typeof r.publicKey!="string")return"failed";const i=r.publicKey,o=t1(i),{pushManager:c}=await navigator.serviceWorker.ready;await((a=await c.getSubscription())==null?void 0:a.unsubscribe());const x=await c.subscribe({userVisibleOnly:!0,applicationServerKey:o}),u=_x.safeParse(x.toJSON());if(!u.success)return"failed";const m=t.pushSubscribe(u.data,i);return m===null?"failed":await Du(t,m)==="applied"?"on":"failed"}catch{return"failed"}}async function n1(t){const s=t.pushUnsubscribe(),n=s!==null&&await Du(t,s)==="applied";try{await(await navigator.serviceWorker.ready).pushManager.getSubscription().then(a=>a==null?void 0:a.unsubscribe())}catch{}return n}const St=d.notifications,a1=t=>t==="denied"?St.denied:t==="unsupported"?St.unsupported:t==="unavailable"?St.noPush:t==="failed"?St.failed:null;function Fu(t,s){var x;const n=(x=fe(t).device)==null?void 0:x.push,[a,l]=h.useState(!1),[r,i]=h.useState(null);return{push:n,busy:a,problem:r,enable:async()=>{if(a)return"failed";l(!0),i(null);const u=await s1(t,s);return l(!1),i(a1(u)),u},disable:async()=>{a||(l(!0),i(null),await n1(t),l(!1))}}}function l1({store:t,fetchImpl:s}){const n=Fu(t,s);if(!n.push)return null;const a=n.push==="on";return e.jsxs("div",{className:"flex flex-col gap-2 border-b border-line px-4 py-3 text-body last:border-b-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("dt",{className:"flex-none text-muted",children:St.row}),e.jsx("dd",{className:"flex min-w-0 items-center gap-3 text-right",children:n.push==="unavailable"?e.jsx("span",{children:St.noPush}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:a?St.on:St.off}),e.jsx(sl,{on:a,label:St.row,disabled:n.busy,onChange:l=>{l?n.enable():n.disable()}})]})})]}),n.push==="stale"&&e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[e.jsx("p",{className:"text-muted",children:St.stale}),e.jsx("button",{type:"button",disabled:n.busy,onClick:()=>{n.enable()},className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 font-medium disabled:opacity-45",children:St.enable})]}),n.problem&&e.jsx(Ve,{title:n.problem,tone:"warning",role:"alert"})]})}const Oo=t=>(t==="off"||t==="stale")&&zu()!=="unsupported";function Lo({store:t,onDone:s,fetchImpl:n,body:a=St.body}){const l=Fu(t,n),r=fe(t).fresh,i=()=>{l.enable().then(o=>{o==="on"&&(Zs({name:"atoi"}),s())})};return e.jsxs(e.Fragment,{children:[e.jsxs("section",{"aria-labelledby":"notify-title",className:"flex flex-col gap-3 rounded-control border border-line bg-surface p-4",children:[e.jsx("h2",{id:"notify-title",className:"text-title leading-[1.35] font-semibold",children:St.title}),e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:a}),l.problem&&e.jsx(Ve,{title:l.problem,tone:"warning",role:"alert"}),e.jsx("button",{type:"button",disabled:l.busy||!r,onClick:i,className:gt,children:l.busy?St.working:r?St.enable:St.waiting})]}),e.jsx("a",{href:ae({name:"atoi"}),onClick:s,className:ot,children:St.later})]})}function r1(t,s){switch(t.status){case"applied":return{text:s,quiet:!1};case"cancelled":return{text:d.confirm.cancelled,quiet:!0};case"expired":return{text:d.confirm.expired,quiet:!0};case"rejected":return t.reason==="assertion_expired"?{text:d.confirm.expired,quiet:!0}:{text:d.confirm.refused[t.reason]??s,quiet:!1};default:return{text:s,quiet:!1}}}const Ee=d.connection.pcUpdate,qn="flex flex-col gap-3 rounded-card border bg-surface p-3.5";function i1({store:t,action:s,pc:n,from:a,to:l,onClose:r}){var g;const i=h.useId(),o=!!((g=fe(t).device)!=null&&g.confirm),[c,x]=h.useState(!1),[u,m]=h.useState(null),p=()=>{x(!0),m(null),t.pcAction(s,s==="update"?l:void 0).then(f=>{f.status==="applied"?r():m(r1(f,Ee.notDone))},()=>m({text:Ee.notDone,quiet:!1})).finally(()=>x(!1))};return e.jsxs(ct,{labelledBy:`${i}-title`,onClose:()=>{c||r()},children:[e.jsx("h2",{id:`${i}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:s==="update"?Ee.confirmUpdate:Ee.confirmRestart}),e.jsx("p",{className:"text-body text-muted",children:s==="update"?Ee.confirmUpdateBody(n,a,l):Ee.confirmRestartBody(n)}),e.jsx("p",{className:`rounded-control border border-dashed border-input px-3 py-2 text-small ${o?"text-muted":"text-attention"}`,children:o?Ee.passkey:Ee.noPasskey}),u&&e.jsx("p",{role:"status",className:`text-body ${u.quiet?"text-muted":"text-danger-fg"}`,children:u.text}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(We,{variant:"ghost",className:"flex-1",disabled:c,onClick:r,children:Ee.cancel}),e.jsx(We,{variant:"primary",className:"flex-[2]",disabled:c||!o,onClick:p,children:Ee.confirm})]})]})}function o1({run:t,fresh:s}){const n=t.action==="update"?["asked","installing","restarting","back"]:["asked","restarting","back"],a=t.step==="restarting"?s?n.indexOf("restarting"):n.length-1:1;return e.jsx("ol",{className:"flex flex-col gap-1.5 text-small",children:n.map((l,r)=>e.jsxs("li",{className:`flex items-center gap-2 ${r>a?"text-muted":""}`,children:[e.jsx("span",{"aria-hidden":"true",className:"w-4 text-center",children:r<a?"✓":r===a?"…":"·"}),e.jsx("span",{children:Ee.steps[l]})]},l))})}function c1({store:t,run:s,fresh:n,from:a,onRetry:l}){const r=s.action==="update";return hc(s)?e.jsxs("div",{className:`${qn} border-line`,role:"status",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("strong",{className:"text-body",children:r?Ee.updating(s.version):Ee.restarting}),e.jsx("span",{className:"text-meta text-info",children:Ee.running})]}),e.jsx(o1,{run:s,fresh:n}),e.jsx("p",{className:"text-small text-muted",children:Ee.leave})]}):s.step==="done"?e.jsxs("div",{className:`${qn} border-ok/40`,role:"status",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("strong",{className:"text-body",children:r?Ee.done(s.version):Ee.restarted}),e.jsx("span",{className:"text-meta text-ok",children:Ee.upToDate})]}),e.jsx(We,{onClick:()=>t.dismissPc(),children:Ee.close})]}):e.jsxs("div",{className:`${qn} border-danger-fg/40`,role:"alert",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("strong",{className:"text-body",children:r?Ee.failed:Ee.notRestarted}),e.jsx("span",{className:"text-meta text-danger-fg",children:Ee.refused})]}),e.jsxs("p",{className:"text-small text-muted",children:[Ee.unchanged(a)," ",s.reason?Ee.reasons[s.reason]:""]}),e.jsx(We,{onClick:l,children:Ee.retry})]})}function d1({store:t,appVersion:s}){const n=fe(t),[a,l]=h.useState(null),r=n.daemon,i=n.pc;if(!r)return null;const o=s!==null&&fc(r.version,s);if(!o&&!r.restart&&!i)return null;const c=r.name,x=()=>{t.dismissPc(),((i==null?void 0:i.action)==="restart"||s)&&l((i==null?void 0:i.action)??"restart")};return e.jsxs("section",{"aria-labelledby":"pc-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"pc-title",className:"text-small font-medium text-muted",children:Ee.title}),i?e.jsx(c1,{store:t,run:i,fresh:n.fresh,from:r.version,onRetry:x}):o&&(r.update?e.jsxs("div",{className:`${qn} border-input`,children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("strong",{className:"text-body",children:Ee.behind}),e.jsx("span",{className:"font-mono text-small text-muted",children:Ee.versions(r.version,s)})]}),e.jsx("p",{className:"text-small text-muted",children:Ee.why}),e.jsx(We,{variant:"primary",block:!0,disabled:!n.fresh,onClick:()=>l("update"),children:Ee.update}),e.jsx("p",{className:"text-meta text-muted",children:Ee.keepGoing})]}):e.jsxs("div",{className:`${qn} border-attention/40`,children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("strong",{className:"text-body",children:Ee.manual}),e.jsx("span",{className:"font-mono text-small text-muted",children:Ee.versions(r.version,s)})]}),e.jsx("p",{className:"text-small text-muted",children:r.restart?Ee.clone:Ee.byHand})]})),r.restart&&e.jsxs("div",{className:"flex items-center gap-3 rounded-control border border-line px-3.5 py-3",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"text-body",children:Ee.restart}),e.jsx("span",{className:"text-small text-muted",children:Ee.restartHint})]}),e.jsx(We,{size:"sm",disabled:!n.fresh||hc(i),onClick:()=>l("restart"),children:Ee.restartGo})]}),a&&e.jsx(i1,{store:t,action:a,pc:c,from:r.version,to:a==="update"&&s?s:r.version,onClose:()=>l(null)})]})}const il="min-h-12 w-full min-w-0 rounded-control border border-input bg-surface px-3 text-base text-fg focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-info",qe=d.settings,ol="flex flex-col rounded-[10px] border border-line bg-surface text-body",oi="flex flex-col gap-1 border-b border-line px-4 py-3 last:border-b-0",u1=Array.from({length:Math.round((Lx-Ni)*20)+1},(t,s)=>Math.round((Ni+s*.05)*100)),x1=["finished","chat","decision"],m1=["pc","claude","codex","cursor","omp"];function ci({label:t,hint:s,children:n}){const a=h.useId();return e.jsxs("div",{className:oi,children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"min-w-0",children:t}),n(s?a:void 0)]}),s&&e.jsx("p",{id:a,className:"text-small text-muted",children:s})]})}function p1(t,s){if(t==="hour")return new Date(s.getTime()+36e5);if(t==="four")return new Date(s.getTime()+4*36e5);const n=new Date(s);return n.setDate(n.getDate()+1),n.setHours(8,0,0,0),n}function f1(t,s){const n=t.toLocaleTimeString(dt,{hour:"2-digit",minute:"2-digit"});if(t.toDateString()===s.toDateString())return n;const a=new Date(s);return a.setDate(a.getDate()+1),t.toDateString()===a.toDateString()?qe.tomorrow(n):`${t.toLocaleDateString(dt,{day:"numeric",month:"short"})} ${n}`}function Pu(t){var u;const s=fe(t),[n,a]=h.useState(null),[l,r]=h.useState(!1),i=h.useRef(0),o=h.useRef(!0);return h.useEffect(()=>()=>{o.current=!1},[]),{prefs:n??((u=s.device)==null?void 0:u.prefs)??Ox,send:m=>{const p=++i.current;a(m),r(!1),t.setDevicePrefs(m).then(g=>{!o.current||p!==i.current||(a(null),g.status!=="applied"&&r(!0))})},failed:l,fresh:s.fresh}}function h1({store:t}){var c,x;const s=fe(t),n=Pu(t),a=Yt();if(!((c=s.daemon)!=null&&c.settings)||!((x=s.device)!=null&&x.prefs)||s.device.push!=="on")return null;const{prefs:l}=n,r=l.quietUntil!==null?new Date(l.quietUntil):null,i=r!==null&&r.getTime()>a,o=u=>n.send({...l,quietUntil:p1(u,new Date(a)).toISOString()});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:ol,children:[x1.map(u=>e.jsx(ci,{label:qe.notify[u],hint:qe.notify[`${u}Hint`],children:m=>e.jsx(sl,{on:l.notify[u],label:qe.notify[u],describedBy:m,disabled:!n.fresh,onChange:p=>n.send({...l,notify:{...l.notify,[u]:p}})})},u)),e.jsxs("div",{className:oi,children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{children:qe.pause}),i&&e.jsx("span",{role:"status",className:"text-right text-attention",children:qe.pausedUntil(f1(r,new Date(a)))})]}),e.jsx("p",{className:"text-small text-muted",children:qe.pauseHint}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-2",children:i?e.jsx("button",{type:"button",disabled:!n.fresh,onClick:()=>n.send({...l,quietUntil:null}),className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 font-medium disabled:opacity-45",children:qe.resume}):["hour","four","morning"].map(u=>e.jsx("button",{type:"button","aria-label":qe.pauseLabel[u],disabled:!n.fresh,onClick:()=>o(u),className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 font-medium disabled:opacity-45",children:qe.pauseFor[u]},u))})]})]}),e.jsx("p",{className:"text-small text-muted",children:qe.notify.always}),n.failed&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:qe.failed})]})}function g1({store:t}){var m,p;const s=fe(t),n=Pu(t),[a,l]=h.useState(null),[r,i]=h.useState(!1),o=h.useRef(!0);if(h.useEffect(()=>()=>{o.current=!1},[]),!((m=s.daemon)!=null&&m.settings)||!((p=s.device)!=null&&p.prefs))return null;const c=Math.round((a??s.device.contextNear??kn)*100),x=g=>{l(g/100),i(!1),t.setContextNear(g/100).then(f=>{o.current&&(l(null),f.status!=="applied"&&i(!0))})},u=n.prefs.chatTool??"pc";return e.jsxs("section",{"aria-labelledby":"ledge-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"ledge-title",className:"text-small font-medium text-muted",children:qe.ledge}),e.jsxs("div",{className:ol,children:[e.jsx(ci,{label:qe.context,hint:qe.contextHint,children:g=>e.jsx("select",{className:`${il} w-auto`,"aria-label":qe.context,"aria-describedby":g,disabled:!s.fresh||a!==null,value:c,onChange:f=>x(Number(f.target.value)),children:u1.map(f=>e.jsx("option",{value:f,children:d.percent(f)},f))})}),s.device.chat&&e.jsxs("div",{className:oi,children:[e.jsx("span",{children:qe.chatTool}),e.jsx("p",{className:"text-small text-muted",children:qe.chatToolHint}),e.jsx("div",{className:"mt-1",children:e.jsx(Gn,{name:"chat-tool",legend:qe.chatTool,value:u,options:m1.map(g=>({value:g,label:qe.tools[g]})),onChange:g=>{s.fresh&&n.send({...n.prefs,chatTool:g==="pc"?null:g})}})}),e.jsx("p",{className:"text-meta text-muted",children:qe.toolPcHint})]})]}),!s.fresh&&e.jsx("p",{className:"text-small text-muted",children:qe.offline}),(r||n.failed)&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:qe.failed})]})}function b1(){const t=Ix();return e.jsx("div",{className:ol,children:e.jsx(ci,{label:qe.motion,hint:qe.motionHint,children:s=>e.jsx(sl,{on:t,label:qe.motion,describedBy:s,onChange:Rx})})})}function j1({store:t}){const s=fe(t).daemon;return e.jsxs("section",{"aria-labelledby":"managed-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"managed-title",className:"text-small font-medium text-muted",children:qe.managed}),(s==null?void 0:s.terminal)&&e.jsx("dl",{className:ol,children:e.jsxs("div",{className:"flex items-baseline justify-between gap-4 px-4 py-3",children:[e.jsx("dt",{className:"text-muted",children:qe.terminal}),e.jsx("dd",{children:s.terminalInput?qe.allowed:qe.notAllowed})]})}),e.jsx("p",{className:"text-small text-muted",children:qe.managedBody})]})}const ue=d.settings.projects,Bu=Object.keys(bn),y1=80,cl=t=>ue.errors[t.status==="rejected"?t.reason:t.status]??ue.errors.failed;function N1(t,s,n){const a=s+n;if(a<0||a>=t.length)return[...t];const l=[...t];return[l[s],l[a]]=[l[a],l[s]],l}function k1({color:t}){return e.jsx("span",{className:"size-3 flex-none rounded-full",style:{background:bn[t]},"aria-hidden":"true"})}function v1({value:t,onChange:s,name:n}){return e.jsxs("fieldset",{className:"m-0 min-w-0 border-0 p-0",children:[e.jsx("legend",{className:"mb-1.5 text-small text-muted",children:ue.color}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Bu.map(a=>e.jsxs("label",{className:"grid size-10 cursor-pointer place-items-center rounded-full border border-line has-[:checked]:border-fg has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-info",children:[e.jsx("input",{type:"radio",name:n,value:a,checked:t===a,onChange:()=>s(a),className:"sr-only","aria-label":ue.colors[a]}),e.jsx("span",{className:"size-6 rounded-full",style:{background:bn[a]},"aria-hidden":"true"})]},a))})]})}function w1({store:t,project:s,projects:n,onClose:a,onDelete:l,onFolders:r}){const i=h.useId(),o=new Set(n.map(N=>N.color)),[c,x]=h.useState((s==null?void 0:s.name)??""),[u,m]=h.useState((s==null?void 0:s.color)??Bu.find(N=>!o.has(N))??"blue"),[p,g]=h.useState(!1),[f,y]=h.useState(null),w=c.trim(),S=w!==""&&n.some(N=>N.id!==(s==null?void 0:s.id)&&vi(N.name)===vi(w)),b=s!==null&&w===s.name&&u===s.color,j=()=>{if(!w||S||p)return;if(b){a();return}g(!0),y(null);const N=s?{...w!==s.name?{name:w}:{},...u!==s.color?{color:u}:{}}:null;(s?t.editProject(s.id,N):t.createProject(w,u)).then($=>{g(!1),$.status==="applied"?a():y(cl($))})};return e.jsxs(ct,{labelledBy:`${i}-title`,onClose:()=>{p||a()},children:[e.jsx("h2",{id:`${i}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:s?ue.editTitle:ue.newTitle}),!s&&e.jsx("p",{className:"text-body text-muted",children:ue.newBody}),e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:N=>{N.preventDefault(),j()},children:[e.jsxs("label",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"text-small text-muted",children:ue.name}),e.jsx("input",{className:il,value:c,maxLength:y1,autoFocus:!0,"aria-invalid":S||void 0,onChange:N=>x(N.target.value)}),S&&e.jsx("span",{role:"alert",className:"text-small text-danger-fg",children:ue.errors.name_taken})]}),e.jsx(v1,{name:`${i}-color`,value:u,onChange:m}),f&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:f}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(We,{variant:"ghost",className:"flex-1",disabled:p,onClick:a,children:ue.cancel}),e.jsx(We,{variant:"primary",type:"submit",className:"flex-[2]",disabled:p||!w||S,children:s?ue.save:ue.create})]}),s&&r&&e.jsx(We,{disabled:p,onClick:r,children:ue.folders}),s&&e.jsx(We,{variant:"ghost",className:"text-danger-fg!",disabled:p,onClick:l,children:ue.remove})]})]})}function S1({store:t,project:s,projects:n,agents:a,onClose:l}){var y;const r=h.useId(),i=!!((y=fe(t).device)!=null&&y.confirm),o=n.filter(w=>w.id!==s.id),[c,x]=h.useState(null),[u,m]=h.useState(!1),[p,g]=h.useState(null),f=()=>{m(!0),g(null),t.deleteProject(s.id,c).then(w=>{m(!1),w.status==="applied"?l():g(cl(w))})};return e.jsxs(ct,{labelledBy:`${r}-title`,onClose:()=>{u||l()},children:[e.jsx("h2",{id:`${r}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:ue.deleteTitle(s.name)}),e.jsx("p",{className:"text-body text-muted",children:ue.deleteAgents(a)}),e.jsxs("fieldset",{className:"m-0 flex min-w-0 flex-col gap-2 border-0 p-0",children:[e.jsx("legend",{className:"mb-1.5 text-small text-muted",children:ue.deleteWhere}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:`${r}-move`,checked:c===null,onChange:()=>x(null)}),ue.noProject]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:`${r}-move`,checked:c!==null,disabled:o.length===0,onChange:()=>{var w;return x(((w=o[0])==null?void 0:w.id)??null)}}),ue.moveTo]}),c!==null&&e.jsx("select",{className:il,"aria-label":ue.target,value:c,onChange:w=>x(w.target.value),children:o.map(w=>e.jsx("option",{value:w.id,children:w.name},w.id))})]}),e.jsx("p",{className:`rounded-control border border-dashed border-input px-3 py-2 text-small ${i?"text-muted":"text-attention"}`,children:i?ue.passkey:ue.noPasskey}),p&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:p}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(We,{variant:"ghost",className:"flex-1",disabled:u,onClick:l,children:ue.cancel}),e.jsx(We,{variant:"primary",className:"flex-[2]",disabled:u||!i,onClick:f,children:ue.confirmDelete})]})]})}const $1=t=>t.machine==="local"?ue.thisPc:t.label??t.machine,C1=t=>t.split("/").filter(Boolean).at(-1)??"/",ba="flex items-center gap-3 border-b border-line px-3 py-2.5 last:border-b-0";function M1({store:t,project:s,onClose:n}){var A;const a=h.useId(),l=fe(t),[r,i]=h.useState(!1),[o,c]=h.useState(!1),[x,u]=h.useState(null),[m,p]=h.useState(null);h.useEffect(()=>{t.requestProjectFolders(s.id)},[t,s.id]),h.useEffect(()=>{r&&(t.requestRecentFolders(),t.listFolder(),p(null))},[t,r]);const g=l.projectFolders[s.id],f=l.folderListing,y=f&&(m===null||f.path===m)?f:null,w=E=>{p(E),u(null),t.listFolder(E)},S=!!((A=l.device)!=null&&A.confirm),b=(E,k)=>{c(!1),E.status==="applied"?(t.requestProjectFolders(s.id),k()):u(cl(E))},j=E=>{c(!0),u(null),t.removeFolder(s.id,E.machine,E.path).then(k=>b(k,()=>{}))},N=E=>{c(!0),u(null),t.addFolder(s.id,E).then(k=>b(k,()=>i(!1)))},$=()=>{o||n()};if(r){const E=(l.recentFolders??[]).filter(k=>!(Array.isArray(g)&&g.some(T=>T.machine==="local"&&T.path===k)));return e.jsxs(ct,{labelledBy:`${a}-title`,onClose:$,children:[e.jsx("h2",{id:`${a}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:ue.pickTitle}),e.jsxs("div",{className:"flex max-h-[55dvh] flex-col gap-3 overflow-y-auto",children:[m===null&&E.length>0&&e.jsxs("section",{"aria-label":ue.recents,className:"flex flex-col gap-1.5",children:[e.jsx("h3",{className:"text-small text-muted",children:ue.recents}),e.jsx("ul",{className:"flex flex-col rounded-control border border-line",children:E.map(k=>e.jsxs("li",{className:ba,children:[e.jsx("span",{className:"min-w-0 flex-1 font-mono text-small break-all",children:k}),e.jsx(We,{size:"sm","aria-label":ue.addThisLabel(k),disabled:o||!S,onClick:()=>N(k),children:ue.addShort})]},k))})]}),e.jsxs("section",{"aria-label":ue.browse,className:"flex flex-col gap-1.5",children:[e.jsx("h3",{className:"text-small text-muted",children:ue.browse}),y?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"font-mono text-small break-all",children:y.path}),y.error&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:ue.folderErrors[y.error]}),e.jsxs("ul",{className:"flex flex-col rounded-control border border-line",children:[y.parent&&e.jsx("li",{className:ba,children:e.jsxs("button",{type:"button",className:"flex min-h-10 flex-1 items-center gap-2 text-left",onClick:()=>w(y.parent),children:[e.jsx(F,{name:"back",className:"size-4"}),ue.parent]})}),y.entries.map(k=>{const T=y.repos.find(C=>C.name===k);return e.jsx("li",{className:ba,children:e.jsxs("button",{type:"button","aria-label":ue.open(k),className:"flex min-h-10 min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>w(`${y.path==="/"?"":y.path}/${k}`),children:[e.jsx("span",{className:"truncate",children:k}),T&&e.jsxs("span",{className:"flex-none rounded-full bg-raised px-2 text-meta text-muted",children:["⎇ ",T.branch]})]})},k)}),!y.error&&y.entries.length===0&&e.jsx("li",{className:"px-3 py-2.5 text-small text-muted",children:ue.empty})]}),y.cut&&e.jsx("p",{className:"text-meta text-muted",children:ue.cut})]}):e.jsx("p",{role:"status",className:"text-small text-muted",children:ue.loadingFolder})]})]}),e.jsx("p",{className:"text-small text-muted",children:ue.onlyThisPc}),e.jsx("p",{className:`rounded-control border border-dashed border-input px-3 py-2 text-small ${S?"text-muted":"text-attention"}`,children:S?ue.folderPasskey:ue.noPasskey}),x&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:x}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(We,{variant:"ghost",className:"flex-1",disabled:o,onClick:()=>{i(!1),u(null)},children:ue.back}),e.jsx(We,{variant:"primary",className:"flex-[2]",disabled:o||!S||!y||!!y.error,"aria-label":y?ue.addThisLabel(y.path):ue.addThis,onClick:()=>{y&&N(y.path)},children:ue.addThis})]})]})}return e.jsxs(ct,{labelledBy:`${a}-title`,onClose:$,children:[e.jsx("h2",{id:`${a}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:ue.foldersTitle(s.name)}),g===void 0?e.jsx("p",{role:"status",className:"text-small text-muted",children:ue.foldersLoading}):g==="gone"?e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:ue.errors.stale}):g.length===0?e.jsx("p",{className:"text-body text-muted",children:ue.foldersNone}):e.jsx("ul",{className:"flex max-h-[45dvh] flex-col overflow-y-auto rounded-control border border-line",children:g.map(E=>e.jsxs("li",{className:ba,children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"font-medium",children:C1(E.path)}),e.jsxs("span",{className:"font-mono text-meta break-all text-muted",children:[E.path," · ",$1(E)]})]}),e.jsx(We,{size:"sm",variant:"ghost","aria-label":ue.removeFolderLabel(E.path),disabled:o||!l.fresh,onClick:()=>j(E),children:ue.removeFolder})]},`${E.machine}
|
|
18
|
+
${E.path}`))}),x&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:x}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(We,{variant:"ghost",className:"flex-1",disabled:o,onClick:n,children:ue.close}),e.jsxs(We,{variant:"primary",className:"flex-[2]",disabled:o||!l.fresh||g==="gone",onClick:()=>{u(null),i(!0)},children:[e.jsx(F,{name:"plus",className:"size-4"}),ue.addFolder]})]})]})}function E1({store:t}){var w;const s=fe(t),[n,a]=h.useState(null),[l,r]=h.useState(null),[i,o]=h.useState(null),[c,x]=h.useState(!1),[u,m]=h.useState(null);if(!((w=s.daemon)!=null&&w.projectEdit)||!s.daemon.atelier)return null;const p=s.projects,g=S=>[...s.sessions.values()].filter(b=>b.projectId===S&&b.state!=="exited").length,f=!s.fresh||c,y=(S,b)=>{x(!0),m(null),t.orderProjects(N1(p.map(j=>j.id),S,b)).then(j=>{x(!1),j.status!=="applied"&&m(cl(j))})};return e.jsxs("section",{"aria-labelledby":"projects-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"projects-title",className:"text-small font-medium text-muted",children:ue.title}),e.jsxs("ul",{className:"flex flex-col rounded-[10px] border border-line bg-surface text-body",children:[p.length===0&&e.jsx("li",{className:"px-4 py-3 text-muted",children:ue.none}),p.map((S,b)=>e.jsxs("li",{className:"flex items-center gap-3 border-b border-line px-4 py-2.5 last:border-b-0",children:[e.jsx(k1,{color:S.color}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate font-medium",children:S.name}),e.jsx("span",{className:"text-small text-muted",children:ue.agents(g(S.id))})]}),e.jsx(ki,{label:ue.up(S.name),disabled:f||b===0,onClick:()=>y(b,-1),children:e.jsx(F,{name:"arrowUp",className:"size-4"})}),e.jsx(ki,{label:ue.down(S.name),disabled:f||b===p.length-1,onClick:()=>y(b,1),children:e.jsx(F,{name:"arrowUp",className:"size-4 rotate-180"})}),e.jsx(We,{size:"sm","aria-label":ue.editLabel(S.name),disabled:!s.fresh,onClick:()=>a(S),children:ue.edit})]},S.id))]}),e.jsxs(We,{disabled:!s.fresh,onClick:()=>a("new"),children:[e.jsx(F,{name:"plus",className:"size-4"}),ue.add]}),u&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:u}),e.jsx("p",{className:"text-small text-muted",children:s.daemon.projectFolders?ue.folders_note:ue.folders_note_old}),n!==null&&e.jsx(w1,{store:t,project:n==="new"?null:n,projects:p,onClose:()=>a(null),onDelete:()=>{n!=="new"&&(r(n),a(null))},onFolders:s.daemon.projectFolders?()=>{n!=="new"&&(o(n),a(null))}:null}),i&&e.jsx(M1,{store:t,project:i,onClose:()=>o(null)}),l&&e.jsx(S1,{store:t,project:l,projects:p,agents:g(l.id),onClose:()=>r(null)})]})}const es=d.connection.device,qu=t=>{var s,n;return t??cm(((s=globalThis.navigator)==null?void 0:s.userAgent)??"",((n=globalThis.navigator)==null?void 0:n.maxTouchPoints)??0)};function A1({store:t,pinned:s}){const n=fe(t),[a,l]=h.useState(null),[r,i]=h.useState(!1),o=n.device;if(!(o!=null&&o.id))return null;const c=qu(o.name),x=s?new Date(s.pinnedAt).toLocaleDateString(dt,{day:"numeric",month:"short",year:"numeric"}):null,u=(a==null?void 0:a.trim())??"",m=()=>{if(!(!u||u.length>xl)){if(t.renameDevice(u)===null){i(!0);return}i(!1),l(null)}};return e.jsxs("section",{"aria-labelledby":"device-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"device-title",className:"text-small font-medium text-muted",children:es.title}),e.jsxs("div",{className:"flex items-center gap-3 rounded-[10px] border border-line bg-surface px-4 py-3",children:[e.jsx("span",{className:"grid size-9 flex-none place-items-center rounded-[10px] bg-raised","aria-hidden":"true",children:e.jsx(F,{name:o.kind==="tablet"?"tablet":"phone"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-body font-semibold [overflow-wrap:anywhere]",children:c}),x&&e.jsx("p",{className:"text-meta text-muted",children:es.linkedOn(x)})]}),e.jsx(We,{size:"sm","aria-label":es.renameLabel(c),onClick:()=>{i(!1),l(c)},children:es.rename})]}),r&&e.jsx("p",{role:"status",className:"text-small text-danger-fg",children:es.failed}),e.jsx("p",{className:"text-small text-muted",children:es.others}),a!==null&&e.jsxs(ct,{labelledBy:"rename-title",onClose:()=>l(null),children:[e.jsx("h2",{id:"rename-title",className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:es.sheetTitle}),e.jsx("p",{className:"text-body text-muted",children:es.sheetBody}),e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:p=>{p.preventDefault(),m()},children:[e.jsxs("label",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"sr-only",children:es.field}),e.jsx("input",{className:il,value:a,maxLength:xl,autoFocus:!0,"aria-describedby":"rename-count",onChange:p=>l(p.target.value)}),e.jsxs("span",{id:"rename-count",className:"self-end text-meta text-muted",children:[a.length,"/",xl]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(We,{variant:"ghost",className:"flex-1",onClick:()=>l(null),children:es.cancel}),e.jsx(We,{variant:"primary",type:"submit",className:"flex-[2]",disabled:!u,children:es.save})]})]})]})]})}const tt=d.connection,Us=d.settings,T1=()=>[{value:"system",label:tt.themes.system},{value:"light",label:tt.themes.light},{value:"dark",label:tt.themes.dark}],_1=t=>t==="ready"?tt.states.online:t==="handshaking"?tt.states.connecting:tt.states.offline;function I1({store:t,login:s,relay:n,pinned:a,linkState:l,build:r,onSignOut:i,fetchImpl:o,section:c}){var y,w,S;const x=fe(t),u=zx(),m=dc();h.useEffect(()=>{var b;c==="link"&&((b=document.getElementById("link-title"))==null||b.scrollIntoView({block:"start"}))},[c]);const p=(a==null?void 0:a.name)??((y=x.daemon)==null?void 0:y.name)??null,g=!!x.daemon&&!!r&&fc(x.daemon.version,r.version),f=[[tt.account,s?d.account(s):tt.unknown,!1],[tt.relay,n,!0],[tt.pc,p??tt.unknown,!1],[tt.pcFingerprint,a?Xn(a.fingerprint):tt.unknown,!0],[tt.status,_1(l),!1],[tt.version,(r==null?void 0:r.version)??tt.none,!0],[tt.appFingerprint,r?Lu(r.fingerprint):tt.none,!0],[tt.pcVersion,((w=x.daemon)==null?void 0:w.version)??tt.none,!0,g?"text-attention":void 0]];return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-2.5",children:[e.jsx(ls,{fallback:{name:"atoi"},label:tt.back}),e.jsx("h1",{className:"text-base font-semibold",children:tt.title})]}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col gap-6 overflow-y-auto pt-5 pb-[34px]",children:[e.jsx(A1,{store:t,pinned:a}),e.jsxs("section",{"aria-labelledby":"appearance-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"appearance-title",className:"text-small font-medium text-muted",children:Us.appearance}),e.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:"text-small text-muted",children:Us.theme}),e.jsx(Gn,{name:"theme",legend:Us.theme,options:T1(),value:u,onChange:b=>Dx(b),fit:!0})]}),e.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:"text-small text-muted",children:Us.lang}),e.jsx(Gn,{name:"lang",legend:Us.lang,options:Px.map(b=>({value:b,label:Us.langs[b],lang:b})),value:m,onChange:Fx,fit:!0})]}),e.jsx(b1,{})]}),((S=x.device)==null?void 0:S.push)&&e.jsxs("section",{"aria-labelledby":"notifications-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"notifications-title",className:"text-small font-medium text-muted",children:Us.notifications}),e.jsx("dl",{className:"flex flex-col rounded-[10px] border border-line bg-surface text-body",children:e.jsx(l1,{store:t,fetchImpl:o})}),e.jsx(h1,{store:t})]}),e.jsx(g1,{store:t}),e.jsx(E1,{store:t}),e.jsx(d1,{store:t,appVersion:(r==null?void 0:r.version)??null}),e.jsxs("section",{"aria-labelledby":"link-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"link-title",className:"text-small font-medium text-muted",children:tt.section}),e.jsxs("dl",{className:"flex flex-col rounded-[10px] border border-line bg-surface text-body",children:[f.map(([b,j,N,$])=>e.jsxs("div",{className:"flex items-baseline justify-between gap-4 border-b border-line px-4 py-3 last:border-b-0",children:[e.jsx("dt",{className:"flex-none text-muted",children:b}),e.jsx("dd",{className:`min-w-0 text-right break-words ${N?"font-mono":""} ${$??""}`,children:j})]},b)),e.jsx(kf,{store:t}),e.jsx($f,{store:t})]})]}),e.jsx(j1,{store:t}),e.jsx("div",{className:"flex-grow","aria-hidden":"true"}),e.jsx("button",{type:"button",onClick:i,className:ot,children:tt.signOut})]})]})}function R1({onOther:t}){return e.jsxs(vt,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(hs,{size:80,frozen:!0}),e.jsx("h1",{className:Pt,children:d.denied.title}),e.jsx("p",{className:"max-w-[300px] text-muted",children:d.denied.bodyNoLogin})]}),e.jsx(wt,{}),e.jsx("button",{type:"button",onClick:t,className:ot,children:d.denied.other})]})}const Vt=d.keyChanged,O1=t=>{const s=new Date(t);return Number.isNaN(s.getTime())?d.connection.unknown:s.toLocaleDateString(dt,{day:"numeric",month:"short"})};function L1({pcName:t,known:s,received:n,onRelink:a,onSignOut:l}){return e.jsxs(vt,{children:[e.jsxs("div",{className:"flex flex-col gap-3.5",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex size-12 items-center justify-center rounded-full bg-danger-bg text-danger-fg",children:e.jsxs("svg",{className:Ia,viewBox:"0 0 24 24",children:[e.jsx("path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}),e.jsx("path",{d:"M12 8v4"}),e.jsx("path",{d:"M12 16h.01"})]})}),e.jsx("h1",{className:Pt,children:Vt.title(t??d.yourPc)}),e.jsx("p",{className:"text-muted",children:Vt.body})]}),e.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-4 gap-y-2.5 rounded-control border border-line bg-surface p-4 text-body",children:[e.jsx("dt",{className:"text-muted",children:Vt.known}),e.jsx("dd",{className:"font-mono",children:s?Vt.knownDetail(Xn(s.fingerprint,2),O1(s.pinnedAt)):d.connection.unknown}),e.jsx("dt",{className:"text-muted",children:Vt.received}),e.jsx("dd",{className:"font-mono",children:n?Vt.receivedDetail(Xn(n,2)):d.connection.unknown})]}),e.jsxs("div",{className:"flex flex-col gap-3 text-body leading-[1.6] text-muted",children:[e.jsxs("p",{children:[e.jsx("strong",{className:"text-fg",children:Vt.reinstalledTitle})," ",Vt.reinstalledBody]}),e.jsxs("p",{children:[e.jsx("strong",{className:"text-fg",children:Vt.otherwise})," ",Vt.warning]})]}),e.jsx(wt,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:a,className:gt,children:Vt.relink}),e.jsx("button",{type:"button",onClick:l,className:ot,children:Vt.signOut})]})]})}const z1="/auth/github/start";function D1(t){return t==="denied"?d.login.errors.denied:t==="bad_state"||t==="error"?d.login.errors.failed:null}const F1=[e.jsxs(e.Fragment,{children:[e.jsx("circle",{cx:"7.5",cy:"15.5",r:"5.5"}),e.jsx("path",{d:"m21 2-9.6 9.6"}),e.jsx("path",{d:"m15.5 7.5 3 3L22 7l-3-3"})]}),e.jsxs(e.Fragment,{children:[e.jsx("rect",{width:"20",height:"14",x:"2",y:"3",rx:"2"}),e.jsx("line",{x1:"8",x2:"16",y1:"21",y2:"21"}),e.jsx("line",{x1:"12",x2:"12",y1:"17",y2:"21"})]}),e.jsxs(e.Fragment,{children:[e.jsx("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})];function P1({server:t,error:s}){return e.jsxs(vt,{children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(hs,{size:88}),e.jsx("h1",{className:"text-display leading-[34px] font-bold tracking-[-.025em]",children:d.login.title}),e.jsx("p",{className:"max-w-[300px] text-muted",children:d.login.subtitle})]}),e.jsxs("div",{className:"flex h-8 items-center gap-2.5 self-center rounded-full border border-line px-3 text-small text-muted",children:[e.jsxs("svg",{className:`${Ia} size-3.5`,viewBox:"0 0 24 24","aria-hidden":"true",children:[e.jsx("rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2"}),e.jsx("rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2"}),e.jsx("line",{x1:"6",x2:"6.01",y1:"6",y2:"6"}),e.jsx("line",{x1:"6",x2:"6.01",y1:"18",y2:"18"})]}),e.jsx("span",{className:"font-mono",children:t})]}),s&&e.jsx("p",{role:"alert",className:"rounded-control border border-danger-fg/15 bg-danger-bg p-3.5 text-body text-danger-fg",children:s}),e.jsx(wt,{}),e.jsx("ul",{className:"flex flex-col gap-3.5 text-fg/85",children:d.login.notes.map((n,a)=>e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx("svg",{className:`${Ia} text-fg`,viewBox:"0 0 24 24","aria-hidden":"true",children:F1[a]}),e.jsx("span",{children:n})]},n))}),e.jsxs("a",{href:z1,className:gt,children:[e.jsx("svg",{className:"size-5 flex-none fill-current",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M12 .3a12 12 0 0 0-3.8 23.38c.6.12.83-.26.83-.57L9 21.07c-3.34.72-4.04-1.61-4.04-1.61-.55-1.39-1.34-1.76-1.34-1.76-1.08-.74.09-.73.09-.73 1.2.09 1.83 1.24 1.83 1.24 1.07 1.83 2.81 1.3 3.5 1 .1-.78.42-1.31.76-1.6-2.67-.3-5.47-1.34-5.47-5.93 0-1.31.47-2.38 1.24-3.22-.14-.3-.54-1.52.1-3.18 0 0 1-.32 3.3 1.23a11.5 11.5 0 0 1 6 0c2.28-1.55 3.29-1.23 3.29-1.23.64 1.66.24 2.88.12 3.18a4.65 4.65 0 0 1 1.23 3.22c0 4.61-2.8 5.63-5.48 5.92.42.36.81 1.1.81 2.22l-.01 3.29c0 .31.2.69.82.57A12 12 0 0 0 12 .3"})}),d.login.github]})]})}function B1({onHere:t}){return e.jsxs(vt,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:Pt,children:d.replaced.title}),e.jsx("p",{className:"text-muted",children:d.replaced.body})]}),e.jsx(wt,{}),e.jsx("button",{type:"button",onClick:t,className:ot,children:d.replaced.here})]})}const yr=t=>e.jsx("a",{href:ae({name:"atoi"}),className:Oe({size:"sm"}),children:t});function di({label:t,children:s}){return It()?e.jsx("section",{"aria-label":t,className:"pt-[34px]",children:s}):e.jsx(ps,{label:t,children:s})}function q1(){const{pc:t}=qt();return e.jsxs(Os,{title:d.prs.title,subtitle:d.prs.subtitle,children:[e.jsx(di,{label:d.prs.title,children:e.jsx(Qt,{glyph:e.jsx(F,{name:"pr",className:"size-[22px]"}),title:d.prs.notSent(Bt(t)),body:d.prs.notSentBody})}),e.jsx("p",{className:"text-small text-muted",children:d.prs.tracked})]})}function H1(){const{pc:t}=qt();return e.jsx(Os,{title:d.rigs.title,subtitle:d.rigs.subtitle,children:e.jsx(di,{label:d.rigs.title,children:e.jsx(Qt,{glyph:e.jsx(F,{name:"rigs",className:"size-[22px]"}),title:d.rigs.notSent(Bt(t)),body:d.rigs.notSentBody,action:yr(d.rigs.seeAtoi)})})})}function zo({onClose:t}={}){const{pc:s}=qt();return t?e.jsxs(e.Fragment,{children:[e.jsx(Ru,{frozen:!0,onClose:t}),e.jsx("section",{"aria-label":d.chat.title,className:"pt-[34px]",children:e.jsx(Qt,{framed:!1,glyph:e.jsx(hs,{size:64,frozen:!0}),title:d.chat.unavailable.title(Bt(s)),body:d.chat.unavailable.body,action:yr(d.chat.unavailable.seeAtoi)})})]}):e.jsx(Os,{title:d.chat.title,children:e.jsx(di,{label:d.chat.title,children:e.jsx(Qt,{framed:!1,glyph:e.jsx(hs,{size:64,frozen:!0}),title:d.chat.unavailable.title(Bt(s)),body:d.chat.unavailable.body,action:yr(d.chat.unavailable.seeAtoi)})})})}function Do({icon:t,title:s,body:n}){return e.jsxs("div",{"data-split-empty":"",className:"flex flex-1 flex-col items-center justify-center gap-1 text-center text-muted",children:[e.jsx(F,{name:t,className:"size-[18px]"}),e.jsx("h2",{className:"mt-2.5 text-[17px] font-semibold text-fg",children:s}),e.jsx("p",{className:"max-w-[320px] text-small",children:n})]})}function U1({open:t,onClose:s,children:n}){const a=h.useRef(null),l=h.useRef(s);l.current=s;const r=h.useRef(null);return h.useEffect(()=>{const i=a.current;if(!i)return;const o=c=>{t&&c.target instanceof HTMLElement&&c.target.tagName==="MAIN"&&(r.current=c.target.scrollTop)};return i.addEventListener("scroll",o,!0),()=>i.removeEventListener("scroll",o,!0)},[t]),h.useEffect(()=>{var c;if(!t)return;const i=(c=a.current)==null?void 0:c.querySelector("main");i&&r.current!==null&&(i.scrollTop=r.current);const o=x=>{x.key!=="Escape"||x.defaultPrevented||x.isComposing||sd()||(x.preventDefault(),l.current())};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[t]),e.jsx("aside",{ref:a,hidden:!t,"aria-label":d.chat.title,"data-ledge-pane":"",className:"lpane",children:n})}const Hu="ledge.mobile.ledgePane",Nr=new Set;let kr=null;function W1(t){var s;if(kr!==null)return kr;try{return((s=Xe(t))==null?void 0:s.getItem(Hu))==="open"}catch{return!1}}function Fo(t,s){var n;kr=t;try{(n=Xe(s))==null||n.setItem(Hu,t?"open":"closed")}catch{}for(const a of Nr)a()}const K1=t=>(Nr.add(t),()=>{Nr.delete(t)});function V1(t){return h.useSyncExternalStore(K1,()=>W1(t),()=>!1)}function Po({store:t,id:s,onDone:n}){var p,g,f;const a=fe(t),l=Ls(),r=(p=a.asks)==null?void 0:p.find(y=>y.id===s),i=h.useRef(void 0);r&&(i.current=r);const o=r??i.current,c=n??(()=>Tr({name:"atoi"})),x=((g=a.device)==null?void 0:g.confirm)===!0&&l,u=l&&((f=a.device)==null?void 0:f.confirm)!==!0,m=o?e.jsx(dd,{store:t,ask:o,end:Pc(s,a.ops),fresh:a.fresh,ghost:!r,canConfirm:x,enroll:u,onGone:c,full:!0}):a.asks===null||!a.fresh?e.jsx("p",{role:"status",className:"text-body text-muted",children:d.loading}):e.jsx(nt,{tone:"gone",title:d.asks.already});return e.jsxs(e.Fragment,{children:[e.jsx(sa,{title:d.atoi.kindName.rig,fallback:{name:"atoi"},label:d.detail.back,link:$n(a)}),e.jsx("main",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain pt-4 pb-[22px]",children:m})]})}const ja=d.storage;function G1({onRetry:t,onReload:s}){return e.jsxs(vt,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:Pt,children:ja.title}),e.jsx("p",{className:"text-muted",children:ja.body})]}),e.jsx(wt,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:t,className:gt,children:ja.retry}),e.jsx("button",{type:"button",onClick:s,className:ot,children:ja.reload})]})]})}const X1=30,Q1=/^(?:\x1b\[\??\d+(?:;\d+)*[Rc]|\x1b\[[?>][\d;]*c|\x1b\][0-9]+;rgb:[0-9a-f/]+(?:\x07|\x1b\\)|\x1b\[[IO])$/i,Y1={phase:"connecting",cols:80,rows:24,readOnly:!1,held:null,holding:!1,released:null,exit:null,refused:null,holdRefused:null};function Z1(t){if(t.length<=wi)return t;let s=wi;const n=t.charCodeAt(s-1);return n>=55296&&n<=56319&&(s-=1),t.slice(0,s)}function J1(t,s){return`\x1B[H\x1B[2J\x1B[3J${t.replace(/\n/g,`\r
|
|
19
|
+
`)}\x1B[${s.y+1};${s.x+1}H`}class ey{constructor(s,n,a,l=()=>crypto.randomUUID()){Dt(this,"view",Y1);Dt(this,"listeners",new Set);Dt(this,"tid",null);Dt(this,"openOp",null);Dt(this,"holdOp",null);Dt(this,"seq",0);Dt(this,"resyncing",!1);Dt(this,"n",0);Dt(this,"pending","");Dt(this,"timer",null);Dt(this,"wasReady",!1);Dt(this,"offs",[]);Dt(this,"stopped",!1);this.wire=s,this.sessionId=n,this.screen=a,this.uuid=l}get state(){return this.view}subscribe(s){return this.listeners.add(s),()=>{this.listeners.delete(s)}}start(){this.offs.push(this.wire.onMessage(s=>this.onMessage(s))),this.offs.push(this.wire.subscribe(()=>this.onLink())),this.wasReady=this.wire.ready(),this.wasReady?this.open():this.set({phase:"offline"})}stop(){var s;if(!this.stopped){this.stopped=!0,this.flushKeys(),this.tid&&this.wire.ready()&&this.wire.send({type:"term.close",tid:this.tid});for(const n of this.offs.splice(0))n();this.timer&&clearTimeout(this.timer),(s=this.holdOp)==null||s.done("invalid"),this.holdOp=null}}hold(s){var l;if(!this.tid||this.view.phase!=="live"||this.view.readOnly||!this.wire.ready())return Promise.resolve("invalid");(l=this.holdOp)==null||l.done("invalid");const n=this.uuid(),a=this.tid;return new Promise(r=>{this.holdOp={op:n,done:i=>{this.holdOp=null,this.set({holding:!1,holdRefused:i}),r(i)}},this.set({holding:!0,holdRefused:null,released:null}),this.wire.send({type:"term.hold",op:n,tid:a,assertion:s})})}release(){!this.tid||!this.view.held||(this.flushKeys(),this.wire.send({type:"term.release",tid:this.tid}))}type(s){!this.view.held||!this.tid||Q1.test(s)||(this.pending+=s,this.set({held:{...this.view.held,lastKey:Date.now()}}),this.timer===null&&(this.timer=setTimeout(()=>{this.timer=null,this.flushKeys()},X1)))}flushKeys(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),!this.tid||!this.pending||!this.wire.ready()){this.pending="";return}for(;this.pending;){const s=Z1(this.pending);this.pending=this.pending.slice(s.length),this.wire.send({type:"term.input",tid:this.tid,n:this.n++,data:s})}}open(){this.openOp=this.uuid(),this.tid=null,this.n=0,this.resyncing=!1,this.set({phase:"connecting",held:null,holding:!1,exit:null,refused:null}),this.wire.send({type:"term.open",op:this.openOp,id:this.sessionId})}onLink(){var n;const s=this.wire.ready();if(!(s===this.wasReady||this.stopped)){if(this.wasReady=s,!s){this.pending="",(n=this.holdOp)==null||n.done("invalid"),this.tid=null,this.view.phase!=="ended"&&this.view.phase!=="refused"&&this.set({phase:"offline",held:null,released:this.view.held?"link":this.view.released});return}this.view.phase==="offline"&&this.open()}}onMessage(s){if(!this.stopped)switch(s.type){case"term.opened":{if(!(s.op!==void 0?s.op===this.openOp:s.tid===this.tid))return;this.tid=s.tid,this.seq=s.seq,this.resyncing=!1,this.screen.reset(s.cols,s.rows),this.screen.write(J1(s.screen,s.cursor)),this.set({phase:"live",cols:s.cols,rows:s.rows,readOnly:s.readOnly===!0});return}case"term.output":if(s.tid!==this.tid||this.resyncing)return;if(s.seq!==this.seq){this.resyncing=!0,this.wire.send({type:"term.resync",tid:s.tid});return}this.seq++,this.screen.write(s.data);return;case"term.size":if(s.tid!==this.tid)return;this.screen.resize(s.cols,s.rows),this.set({cols:s.cols,rows:s.rows});return;case"term.held":if(s.tid!==this.tid)return;this.set({held:{until:Date.parse(s.until),lastKey:Date.now()},released:null});return;case"term.released":if(s.tid!==this.tid)return;this.pending="",this.set({held:null,released:s.why==="asked"?null:s.why});return;case"term.exit":if(s.tid!==this.tid)return;this.tid=null,this.set({phase:"ended",held:null,exit:s.why});return;case"operation.result":if(s.op===this.openOp&&s.status==="rejected"){this.openOp=null,this.set({phase:"refused",refused:s.reason??"invalid"});return}if(s.op===this.openOp&&s.status==="failed"){this.openOp=null,this.set({phase:"refused",refused:"unavailable"});return}this.holdOp&&s.op===this.holdOp.op&&s.status!=="received"&&this.holdOp.done(s.status==="applied"?null:s.reason??"invalid");return;default:return}}set(s){this.view={...this.view,...s};for(const n of[...this.listeners])n()}}const ty=11,m0=6,p0=16,Bo=5*6e4,sy={up:"A",down:"B",right:"C",left:"D"};function ny(t,s){switch(t){case"esc":return"\x1B";case"tab":return" ";case"enter":return"\r";case"interrupt":return"";default:return`${s?"\x1BO":"\x1B["}${sy[t]}`}}function ay(t,s){let n=t;if(s.ctrl&&[...t].length===1){const a=t.toUpperCase().charCodeAt(0);a>=64&&a<=95?n=String.fromCharCode(a-64):t===" "?n="\0":t==="?"&&(n="")}return s.alt?`\x1B${n}`:n}function ly(t){const s=t.findIndex(a=>/❯\s*1\.\s/.test(a));if(s<0)return[];const n=[];for(const a of t.slice(s,s+12)){const l=/^\s*(?:❯\s*)?(\d)\.\s+(.*)$/.exec(a);if(!l)continue;if(l[1]!==String(n.length+1))break;const r=l[2].trim(),i=/^(oui,?\s+toujours|yes,?\s+and\s+don.t\s+ask)/i.test(r)?"always":/^(oui|yes)\b/i.test(r)?"yes":/^(non|no)\b/i.test(r)?"no":null;n.push({digit:l[1],word:i})}return n}const $e=d.terminal.live2,Uu="ledge.mobile.terminalView",ry=t=>{var s;try{return((s=Xe(t))==null?void 0:s.getItem(Uu))==="fit"?"fit":"readable"}catch{return"readable"}},iy=(t,s)=>{var n;try{(n=Xe(s))==null||n.setItem(Uu,t)}catch{}};function oy(t){return{send:s=>{t.send(s).catch(()=>{})},onMessage:s=>t.onMessage(s),ready:()=>t.state()==="ready",subscribe:s=>t.subscribe(s)}}const zl=new Map,cy=t=>{const s=Math.max(0,Math.ceil(t/1e3));return`${Math.floor(s/60)}:${String(s%60).padStart(2,"0")}`},dy=t=>Bx(()=>import("./xterm-CATQzocj.js"),__vite__mapDeps([0,1,2,3,4])).then(s=>s.createXterm(t));function uy({store:t,link:s,session:n,storage:a,makeScreen:l,forge:r}){var et,bt,jt,Z;const i=fe(t),o=Yt(),c=h.useRef(null),x=h.useRef(null),[u,m]=h.useState(null),[p,g]=h.useState(null),[f,y]=h.useState(()=>ry(a)),[w,S]=h.useState(!1),[b,j]=h.useState({ctrl:"off",alt:"off"}),[N,$]=h.useState(!1),[A,E]=h.useState(""),[k,T]=h.useState(!1),[C,I]=h.useState(null),[P,L]=h.useState([]),[R,M]=h.useState(!1),z=It(),U=Ya(),H=h.useRef(!0),V=h.useRef(b);V.current=b,h.useEffect(()=>{const q=c.current;if(!q)return;let ye=!1,_e=null;const oe=Ae=>{if(ye){Ae.dispose();return}const st=new ey(oy(s),n.id,Ae);Ae.onData(yt=>st.type(ee(yt))),st.start(),_e={c:st,xt:Ae},m(st),g(Ae)};return l?oe(l(q)):dy(q).then(oe),()=>{ye=!0,_e==null||_e.c.stop(),_e==null||_e.xt.dispose()}},[s,n.id,l]);const ee=q=>{const ye=V.current;if(ye.ctrl==="off"&&ye.alt==="off")return q;const _e=ay(q,{ctrl:ye.ctrl!=="off",alt:ye.alt!=="off"});return j(oe=>({ctrl:oe.ctrl==="armed"?"off":oe.ctrl,alt:oe.alt==="armed"?"off":oe.alt})),_e},G=h.useSyncExternalStore(q=>u?u.subscribe(q):()=>{},()=>(u==null?void 0:u.state)??null),O=!!(G!=null&&G.held);h.useEffect(()=>{p==null||p.setInput(O),O&&(H.current=!0,p==null||p.focus())},[p,O]),h.useEffect(()=>{!p||!x.current||!G||p.setFont(f==="fit"?p.fitFont(x.current.clientWidth-16):ty)},[p,f,G==null?void 0:G.cols]),h.useEffect(()=>{if(!p)return;const q=x.current,ye=()=>{if(!q)return;const _e=zl.get(n.id);if(_e&&q.scrollWidth>=_e.left+q.clientWidth&&q.scrollHeight>=_e.top+q.clientHeight&&(zl.delete(n.id),q.scrollLeft=_e.left,q.scrollTop=_e.top,H.current=!1),H.current&&f==="readable"){const{x:Ae,cellWidth:st}=p.cursor(),yt=Ae*st;(yt<q.scrollLeft||yt>q.scrollLeft+q.clientWidth-st*4)&&(q.scrollLeft=Math.max(0,yt-q.clientWidth/2))}I(q.scrollWidth>q.clientWidth+1?{left:q.scrollLeft/q.scrollWidth,width:q.clientWidth/q.scrollWidth}:null);const oe=ly(p.rows());L(Ae=>Ae.length===oe.length&&Ae.every((st,yt)=>st.digit===oe[yt].digit&&st.word===oe[yt].word)?Ae:oe)};p.onDrawn(ye),ye()},[p,f]);const D=()=>{const q=x.current;q&&zl.set(n.id,{left:q.scrollLeft,top:q.scrollTop})},J=()=>{const q=x.current;q&&I(q.scrollWidth>q.clientWidth+1?{left:q.scrollLeft/q.scrollWidth,width:q.clientWidth/q.scrollWidth}:null)},Q=h.useRef(null),Y=q=>Math.hypot(q[0].clientX-q[1].clientX,q[0].clientY-q[1].clientY),ie=q=>{q.touches.length===2&&p?Q.current={d:Y(q.touches),px:p.font()}:H.current=!1},X=q=>{if(q.touches.length!==2||!Q.current||!p||!x.current)return;const ye=p.fitFont(x.current.clientWidth-16);p.setFont(Math.max(ye,Q.current.px*(Y(q.touches)/Q.current.d)))},le=()=>{Q.current=null},B=q=>{y(q),iy(q,a),H.current=!0},v=q=>{var ye,_e;if(!(!u||!p)){if(H.current=!0,q==="ctrl"||q==="alt"){j(oe=>({...oe,[q]:oe[q]==="off"?"armed":oe[q]==="armed"?"locked":"off"}));return}if(q==="line"){$(oe=>!oe);return}if(q==="paste"){T(!1),(_e=(ye=navigator.clipboard)==null?void 0:ye.readText)==null||_e.call(ye).then(oe=>{oe?p.paste(oe):T(!0)},()=>T(!0));return}u.type(ee(ny(q,p.appCursor())))}},_=()=>{!u||!A||(u.type(`${A.replace(/\r?\n/g,"\r")}\r`),E(""))},W=!!n.pending||n.state==="waiting_permission"||n.state==="waiting_input",se=((et=n.pending)==null?void 0:et.kind)==="permission"||n.state==="waiting_permission",re={name:"thread",sessionId:n.id},K=(G==null?void 0:G.phase)??"connecting",ce=K==="ended",ge=K==="offline",Ye=!!((bt=i.daemon)!=null&&bt.terminalInput)&&!(G!=null&&G.readOnly)&&n.readOnly!==!0,pt=O?$e.status.held:$e.status[K],Re=G!=null&&G.released&&G.released!=="asked"?$e.released[G.released]:null,Le=(G==null?void 0:G.exit)==="gone"?$e.exit.gone(n.name):G!=null&&G.exit?$e.exit[G.exit]:null,pe=G!=null&&G.refused?$e.refused[G.refused]??$e.refused.unavailable:null,he=G!=null&&G.holdRefused?$e.holdRefused[G.holdRefused]??d.confirm.refused[G.holdRefused]??null:null,Me=G!=null&&G.held?Math.min(Bo,Math.min(G.held.lastKey+Bo,G.held.until)-o):0,ze=O&&Me<=6e4,at=se?P:[];return e.jsxs(e.Fragment,{children:[e.jsx(Eu,{store:t,session:n,current:"terminal",onLeave:D,model:R,onModel:M,display:K==="live"||ge?{value:f==="readable"?$e.readable:$e.fit,onToggle:()=>B(f==="readable"?"fit":"readable")}:void 0}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col pt-2",children:[e.jsxs("div",{className:`flex h-9 flex-none items-center gap-2 rounded-t-card bg-term-bg px-3 text-[12px] text-term-fg ${O?"border-2 border-b-0 border-info":"border border-b-0 border-line"}`,children:[!ze&&e.jsx("span",{className:"min-w-0 truncate font-mono",children:n.project}),e.jsx("span",{role:"status",className:`flex-none rounded-[6px] px-2 py-0.5 font-medium ${O?"bg-info text-white":ge?"text-attention":K==="live"?"text-ok":"text-muted"}`,children:ze?$e.heldLeft(cy(Me)):pt}),e.jsx("span",{className:"flex-1"}),O?e.jsx("button",{type:"button",onClick:()=>u==null?void 0:u.release(),className:"flex-none underline",children:$e.release}):G&&!ce&&K!=="refused"&&e.jsxs("span",{className:"flex-none font-mono",children:[G.cols," × ",G.rows]})]}),e.jsx("div",{ref:x,onScroll:J,onTouchStart:ie,onTouchMove:X,onTouchEnd:le,"aria-label":$e.screen(n.name),className:`relative min-h-0 flex-1 overflow-auto rounded-b-card bg-term-bg p-2 ${O?"border-2 border-t-0 border-info":"border border-t-0 border-line"} ${ge||ce?"opacity-45":""}`,children:e.jsx("div",{ref:c,"data-term":"",className:"w-max"})}),C&&!O&&f==="readable"&&e.jsx("div",{"aria-label":$e.position,role:"img",className:"relative mt-2 h-1 flex-none rounded-full bg-raised",children:e.jsx("span",{className:"absolute inset-y-0 rounded-full bg-muted",style:{left:`${C.left*100}%`,width:`${C.width*100}%`}})})]}),O?e.jsxs("footer",{className:"flex flex-none flex-col gap-1 pt-2 pb-[max(8px,var(--foot-inset))]",children:[k&&e.jsx("p",{role:"alert",className:"text-meta text-attention",children:$e.pasteFailed}),e.jsxs("div",{role:"toolbar","aria-label":$e.keys,className:"flex gap-1.5 overflow-x-auto py-1.5",children:[at.map(q=>e.jsx("button",{type:"button",onPointerDown:ye=>ye.preventDefault(),onClick:()=>{H.current=!0,u==null||u.type(q.digit)},className:"inline-grid h-10 min-w-10 flex-none place-items-center rounded-control border border-attention/50 bg-attention/10 px-2.5 font-mono text-[13px] font-medium text-attention",children:q.word?`${q.digit} ${$e.contextKeys[q.word]}`:q.digit},q.digit)),(z?["interrupt","paste"]:N?["esc","tab","up","down","line"]:["esc","tab","ctrl","alt","left","up","down","right","enter","interrupt","paste","line"]).map(q=>{const ye=q==="ctrl"||q==="alt"?b[q]!=="off":q==="line"?N:!1,_e=q==="ctrl"||q==="alt"||q==="line"?ye:void 0,oe=(q==="ctrl"||q==="alt")&&b[q]!=="off"?`, ${b[q]==="locked"?$e.locked:$e.armed}`:"";return e.jsx("button",{type:"button","aria-pressed":_e,"aria-label":`${$e.keyLabel[q]}${oe}`,onPointerDown:Ae=>Ae.preventDefault(),onClick:()=>v(q),className:`inline-grid h-10 min-w-10 flex-none place-items-center rounded-control border px-2.5 font-mono text-[13px] font-medium ${ye?"border-transparent bg-fg text-bg":"border-input bg-surface text-fg"}`,children:$e.key[q]},q)}),z&&e.jsx("span",{className:"ml-auto flex-none self-center pl-2 text-[12px] text-muted",children:$e.hardware})]}),N&&!z&&e.jsxs("form",{className:"flex items-center gap-2",onSubmit:q=>{q.preventDefault(),_()},children:[e.jsx("span",{"aria-hidden":"true",className:"font-mono text-muted",children:"$"}),e.jsx("input",{id:"term-line",value:A,onChange:q=>E(q.target.value),"aria-label":$e.lineField,placeholder:$e.lineField,autoCapitalize:"off",enterKeyHint:"send",className:"min-h-11 min-w-0 flex-1 rounded-control border border-input bg-transparent px-3 font-mono text-body"}),e.jsx("button",{type:"submit",disabled:!A,"aria-label":$e.lineSend,className:De({variant:"primary",size:"sm"}),children:$e.lineGo})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("footer",{className:"flex flex-none flex-col gap-2 pt-2.5 pb-2.5",children:[(Re||Le||pe||he)&&e.jsx("p",{role:"status",className:"text-center text-small text-muted",children:pe??Le??he??Re}),ce?e.jsx("a",{href:ae(re),className:De({block:!0}),children:$e.back}):Ye&&K!=="refused"?e.jsxs("div",{className:"flex items-center gap-3",children:[W&&e.jsx("span",{className:"min-w-0 flex-1 text-small text-muted",children:$e.alsoInThread}),e.jsxs("button",{type:"button",disabled:K!=="live"||(G==null?void 0:G.holding),onClick:()=>S(!0),className:De({size:"sm",className:W?"flex-none":"ml-auto flex-none"}),children:[e.jsx(F,{name:"keyboard"}),G!=null&&G.released?$e.holdAgain:$e.hold]})]}):!ge&&((jt=i.daemon)==null?void 0:jt.terminal)&&!(G!=null&&G.readOnly)&&n.readOnly!==!0&&e.jsx("p",{className:"text-center text-meta text-muted",children:$e.inputOff}),ge&&e.jsx("p",{className:"text-center text-meta text-muted",children:$e.offlineHint})]}),e.jsx(yu,{store:t,forge:r,session:n,wide:U,threshold:((Z=i.device)==null?void 0:Z.contextNear)??kn,onModel:()=>M(!0)})]}),w&&u&&e.jsx(xy,{store:t,session:n,onClose:()=>S(!1),hold:q=>(S(!1),u.hold(q),"sent")})]})}function xy({store:t,session:s,onClose:n,hold:a}){const{fresh:l,device:r}=fe(t),i=!!(r!=null&&r.confirm),o=gu(t,"terminal",s.id,l&&i,a),c=u=>De({variant:u,block:!0}),x=o.asking?d.confirm.asking:o.challenge?Ct()?`${$e.go}`:$e.go:d.confirm.preparing;return e.jsxs(ct,{labelledBy:"hold-title",onClose:n,children:[e.jsx("h2",{id:"hold-title",className:"text-heading leading-[1.3] tracking-[-.5px]",children:$e.sheetTitle(s.name)}),i?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:$e.sheetBody}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:$e.sheetNote}),o.problem&&e.jsx(Ve,{title:d.confirm[o.problem],tone:"warning",role:"alert"}),o.needsNew?e.jsx("button",{type:"button",onClick:o.retry,className:c("primary"),children:d.confirm.retry}):e.jsxs("button",{type:"button",disabled:o.asking||!o.challenge,onClick:()=>{o.go()},className:c("primary"),children:[e.jsx(F,{name:"passkey"}),x]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ve,{title:$e.unprotectedTitle,tone:"warning",role:"status",children:e.jsx("p",{children:$e.unprotectedBody})}),e.jsx("a",{href:ae({name:"connection"}),className:c("primary"),children:$e.openConnection})]}),e.jsx("button",{type:"button",onClick:n,className:c(),children:$e.cancel})]})}const Wu="ledge.mobile.terminalSize",Ku=11,Vu=20,qo=12,my=1e4,Gu=t=>Math.max(Ku,Math.min(Vu,t));function py(t){var s;try{const n=Number((s=Xe(t))==null?void 0:s.getItem(Wu));return Number.isFinite(n)&&n>0?Gu(Math.round(n)):qo}catch{return qo}}function fy(t,s){var n;try{(n=Xe(s))==null||n.setItem(Wu,String(t))}catch{}}const Ho=$t({variant:"outline",className:"text-body font-medium"});function Uo({store:t,link:s,sessionId:n,storage:a,forge:l}){var o;const r=fe(t),i=r.sessions.get(n);return s&&i&&((o=r.daemon)!=null&&o.terminal)?e.jsx(uy,{store:t,link:s,session:i,forge:l,...a?{storage:a}:{}},n):e.jsx(hy,{store:t,sessionId:n,...a?{storage:a}:{}})}function hy({store:t,sessionId:s,storage:n}){const a=fe(t),l=Yt(),{fresh:r,ops:i}=a,o=a.sessions.get(s),c=a.previews.get(s)??[],[x,u]=h.useState(()=>py(n)),m=L=>u(R=>{const M=Gu(R+L);return fy(M,n),M}),[p,g]=h.useState(!1);h.useEffect(()=>()=>t.watch(null),[t,s]),h.useEffect(()=>{r&&t.watch(s)},[t,s,r]);const f=h.useRef(null);h.useEffect(()=>{const L=f.current;L&&(L.scrollTop=L.scrollHeight)},[c.length,c[c.length-1],x]);const y={name:"thread",sessionId:s},w=$n(a);if(!o)return e.jsxs(e.Fragment,{children:[e.jsx(sa,{title:d.thread.title,fallback:y,label:d.terminal.back,link:w}),e.jsx("main",{className:"min-h-0 flex-1 pt-7 text-body text-muted",role:"status",children:!r&&a.syncedAt===null?d.thread.loading:d.terminal.unknown})]});const S=!!o.pending||o.state==="waiting_permission"||o.state==="waiting_input",b=!r,j=b?d.terminal.offline:S?d.terminal.waiting:d.terminal.live,N=Object.values(i).filter(L=>L.message.type==="session.interrupt"&&L.message.id===s).sort((L,R)=>L.at.localeCompare(R.at)).at(-1),$=N!==void 0&&us(N.phase),A=o.state==="working",E=(N==null?void 0:N.phase)==="applied"&&(!A||l-Date.parse(N.at)<my),k=A&&!b&&!S&&!$&&!E,T=b?d.terminal.why.offline:S?d.terminal.why.waiting:A?null:d.terminal.why.idle,C=()=>{k&&g(!t.interrupt(s))},I=(N==null?void 0:N.phase)==="sending"?d.terminal.sending:E?d.terminal.sent:d.terminal.interrupt(o.name),P=(N==null?void 0:N.phase)==="rejected"&&N.reason==="read_only"?d.terminal.readOnly:p||(N==null?void 0:N.phase)==="rejected"||(N==null?void 0:N.phase)==="failed"?d.terminal.fail:(N==null?void 0:N.phase)==="uncertain"&&!b?d.terminal.uncertain:null;return e.jsxs(e.Fragment,{children:[e.jsx(Eu,{store:t,session:o,current:"terminal"}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"mt-2 mb-4 flex items-center justify-between gap-2",children:[e.jsx("span",{role:"status",className:"text-small text-muted",children:j}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",disabled:x<=Ku,onClick:()=>m(-1),"aria-label":d.terminal.smaller,className:Ho,children:"A−"}),e.jsx("button",{type:"button",disabled:x>=Vu,onClick:()=>m(1),"aria-label":d.terminal.larger,className:Ho,children:"A+"})]})]}),e.jsx("div",{ref:f,tabIndex:0,"aria-label":d.terminal.output,className:"mb-3 min-h-0 flex-1 overflow-auto rounded-card border border-line bg-term-bg p-4",children:c.length===0?e.jsx("p",{className:"text-small text-muted",children:d.terminal.empty}):e.jsx("pre",{"data-size":x,style:{fontSize:x},className:"m-0 w-max min-w-full font-mono leading-[1.5] whitespace-pre text-term-fg",children:c.join(`
|
|
20
|
+
`)})})]}),e.jsxs("footer",{className:"flex flex-none flex-col gap-2.5 border-t border-line bg-bg pt-3 pb-[max(16px,env(safe-area-inset-bottom))] [@media(max-height:650px)]:pb-2.5",children:[e.jsx("p",{className:"text-center text-meta text-muted",children:d.terminal.scrollHint}),P&&e.jsx("p",{role:"alert",className:"text-center text-small text-attention",children:P}),e.jsxs("button",{type:"button",disabled:!k,onClick:C,className:De({block:!0}),children:[e.jsx(F,{name:"stop"}),I]}),T&&!$&&!E&&e.jsx("p",{className:"text-center text-meta text-muted",children:T}),e.jsx("p",{className:"text-center text-meta text-muted",children:d.terminal.note})]})]})}const Rn=d.unrecognized;function gy({pcName:t,onRelink:s,onSignOut:n}){return e.jsxs(vt,{children:[e.jsxs("div",{className:"flex flex-col gap-3.5",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex size-12 items-center justify-center rounded-full bg-danger-bg text-danger-fg",children:e.jsxs("svg",{className:Ia,viewBox:"0 0 24 24",children:[e.jsx("rect",{x:"5",y:"2",width:"14",height:"20",rx:"2"}),e.jsx("path",{d:"m9.5 9.5 5 5"}),e.jsx("path",{d:"m14.5 9.5-5 5"})]})}),e.jsx("h1",{className:Pt,children:Rn.title(t)}),e.jsx("p",{className:"text-muted",children:Rn.body})]}),e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:Rn.kept}),e.jsx(wt,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:s,className:gt,children:Rn.relink}),e.jsx("button",{type:"button",onClick:n,className:ot,children:Rn.signOut})]})]})}const As=d.update,by=t=>`https://github.com/kl-ledge/ledge/releases/tag/v${t}`;function jy({next:t,current:s,onLater:n,onApply:a}){return e.jsxs(ct,{labelledBy:"update-title",onClose:n,children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("h2",{id:"update-title",className:"text-heading leading-[26px] font-semibold tracking-[-.02em]",children:As.version(t.version)}),e.jsx("p",{className:"text-muted",children:As.body})]}),e.jsxs("div",{className:"flex flex-col gap-2 rounded-control border border-line bg-bg p-3.5",children:[e.jsx("span",{className:"text-small leading-4 text-muted",children:As.fingerprint}),e.jsx("code",{className:"font-mono text-base leading-[22px] tracking-[.02em] [word-spacing:4px]",children:Lu(t.fingerprint)}),e.jsxs("span",{className:"text-small leading-4 text-muted",children:[As.current,e.jsx("span",{className:"font-mono",children:s?As.currentBuild(s.version,e1(s.fingerprint)):d.connection.none})]})]}),e.jsxs("a",{href:by(t.version),target:"_blank",rel:"noreferrer",className:"inline-flex min-h-11 items-center gap-2 font-medium",children:[e.jsx(F,{name:"external",className:"size-4",stroke:1.5}),As.compare(`v${t.version}`)]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2.5",children:[e.jsx(We,{size:"lg",onClick:n,children:As.later}),e.jsx(We,{size:"lg",variant:"primary",onClick:a,children:As.apply})]})]})}const vr="ledge.mobile.rigs",yy=35e3,Ny=()=>crypto.randomUUID(),Wo=()=>crypto.randomUUID(),ya=t=>t!=="checking"&&t!=="sending"&&t!=="received",ky=new Set(["assertion_invalid","assertion_expired","confirm_required","conflict"]);function vy(t){var s;try{const n=(s=Xe(t))==null?void 0:s.getItem(vr);if(!n)return null;const a=JSON.parse(n),l=qx.safeParse(a.state);return l.success&&typeof a.at=="string"?{state:l.data,at:a.at}:null}catch{return null}}function wy(t,s,n){var B;const a=vy(n);let l={state:(a==null?void 0:a.state)??null,error:null,at:(a==null?void 0:a.at)??null,loading:!1,graphs:{},queues:{},permissions:{},snapshots:{},routing:null,goals:null,runs:[]};const r=new Set,i=v=>{l={...l,...v};for(const _ of[...r])_()};let o=!1,c=!1,x=!1,u=!1,m=!1;const p=new Map,g=new Map,f=new Map;let y=s.getState().daemon?((B=s.getState().daemon)==null?void 0:B.boot)??null:void 0;const w=new Set,S=()=>!o&&t.state()==="ready",b=()=>{var v;return!!((v=s.getState().daemon)!=null&&v.rigs)},j=v=>{t.send(v).catch(()=>{})};function N(v,_,W){return!S()||!b()?!1:(j(_),clearTimeout(p.get(v)),p.set(v,setTimeout(()=>{p.delete(v),W()},yy)),!0)}const $=v=>{clearTimeout(p.get(v)),p.delete(v)},A=v=>({...v??{},loading:!0}),E=v=>({...v??{},loading:!1,error:"unavailable"});function k(){u||N("state",{type:"rigs.state"},()=>{u=!1,i({loading:!1,error:"unavailable"})})&&(u=!0,i({loading:!0}))}function T(){m||N("goals",{type:"rigs.goals"},()=>{m=!1,i({goals:E(l.goals??void 0)})})&&(m=!0,i({goals:A(l.goals??void 0)}))}const C=()=>{c&&k(),x&&T()};function I(v,_){const W=l.runs.findIndex(re=>re.id===v);if(W<0)return;const se=_(l.runs[W]);if(i({runs:l.runs.map((re,K)=>K===W?se:re)}),ya(se.phase)){se.op&&se.phase!=="uncertain"&&g.delete(se.op);const re=f.get(v);f.delete(v),re==null||re(se)}}const P=v=>l.runs.find(_=>_.op===v),L=v=>!!v&&(!ya(v.phase)||v.phase==="uncertain"),R=(v,_)=>{const W=P(v);$(`op:${v}`),L(W)&&I(W.id,se=>({...se,..._,endedAt:Date.now()}))},M=v=>{clearTimeout(p.get(`op:${v}`)),p.set(`op:${v}`,setTimeout(()=>{p.delete(`op:${v}`);const _=P(v);(_==null?void 0:_.phase)==="sending"&&I(_.id,W=>({...W,phase:"uncertain",endedAt:Date.now()}))},jc))},z=v=>v.sentAt!==void 0&&Date.now()-v.sentAt<bc&&y!==void 0&&(v.boot??null)===y,U=v=>{$(`op:${v.op}`),g.delete(v.op),I(v.id,_=>({..._,phase:"uncertain",lost:!0,endedAt:_.endedAt??Date.now()}))};function H(v){for(const[_,W]of[...g]){if(v.has(_))continue;const se=P(_);if(!se){g.delete(_);continue}if(!z(se)){U(se);continue}I(se.id,re=>({...re,again:!0})),j(W),se.phase==="sending"&&M(_)}}const V=(v,_)=>!v||!v.again||!ky.has(_??"")?!1:(v.lost||U(v),!0),ee=v=>{const _=v.kind==="seats"?v.rig:v.kind==="act"&&"rig"in v.action?v.action.rig:null;_&&(l.graphs[_]||l.queues[_])&&le.openRig(_),_&&l.snapshots[_]&&le.readSnapshots(_)};function G(v){var _;switch(v.type){case"snapshot":{const W=y;y=v.daemon.boot??null;const se=new Set(w);w.clear();for(const re of se){const K=P(re);K&&I(K.id,ce=>({...ce,boot:y}))}(W===void 0||W!==y)&&H(se),C();return}case"rigs.state":if($("state"),u=c,v.state){const W=new Date().toISOString();i({state:v.state,error:null,at:W,loading:!1});try{(_=Xe(n))==null||_.setItem(vr,JSON.stringify({state:v.state,at:W}))}catch{}}else i({error:v.error??"unavailable",loading:!1});return;case"rigs.graph":$(`graph:${v.rig}`),i({graphs:{...l.graphs,[v.rig]:v.graph?{data:v.graph,loading:!1,at:new Date().toISOString()}:{...l.graphs[v.rig],loading:!1,error:v.error??"unavailable"}}});return;case"rigs.queue":$(`queue:${v.rig}`),i({queues:{...l.queues,[v.rig]:v.error?{...l.queues[v.rig],loading:!1,error:v.error}:{data:{rows:v.rows,closed:v.closed,truncated:v.truncated},loading:!1,at:new Date().toISOString()}}});return;case"rigs.permissions":$(`permissions:${v.rig}`),i({permissions:{...l.permissions,[v.rig]:v.error?{...l.permissions[v.rig],loading:!1,error:v.error}:{data:{...v.policy!==void 0?{policy:v.policy}:{},seats:v.seats},loading:!1,at:new Date().toISOString()}}});return;case"rigs.snapshots":$(`snapshots:${v.rig}`),i({snapshots:{...l.snapshots,[v.rig]:v.error?{...l.snapshots[v.rig],loading:!1,error:v.error}:{data:v.snapshots,loading:!1,at:new Date().toISOString()}}});return;case"rigs.routing":$("routing"),i({routing:v.error?{...l.routing,loading:!1,error:v.error}:{data:v.entries,loading:!1,at:new Date().toISOString()}});return;case"rigs.goals":$("goals"),m=x&&!v.error,i({goals:v.error?{...l.goals,loading:!1,error:v.error}:{data:{goals:v.goals,partial:!!v.partial},loading:!1,at:new Date().toISOString()}});return;case"operation.result":{const W=P(v.op);if(!L(W))return;if(v.status==="received"){$(`op:${v.op}`),(W.phase==="sending"||W.phase==="uncertain")&&I(W.id,se=>{const{endedAt:re,...K}=se;return{...K,phase:"received"}});return}if(v.status==="rejected"&&V(W,v.reason))return;v.status==="rejected"&&R(v.op,{phase:"rejected",reason:v.reason??"invalid"});return}case"rigs.done":{const W=P(v.op);if(v.rejected&&V(W,v.rejected))return;W&&(R(v.op,v.rejected?{phase:"rejected",reason:v.rejected,done:v}:{phase:"done",done:v,...v.error?{reason:v.error}:{}}),ee(W.subject));return}case"rigs.reseated":{const W=P(v.op);if(v.rejected&&V(W,v.rejected))return;W&&(R(v.op,v.rejected?{phase:"rejected",reason:v.rejected,reseated:v}:{phase:"done",reseated:v,...v.error?{reason:v.error}:{}}),ee(W.subject));return}case"rigs.goal.sent":case"rigs.goal.replied":if(v.rejected&&V(P(v.op),v.rejected))return;R(v.op,v.rejected?{phase:"rejected",reason:v.rejected,sent:v}:{phase:"done",sent:v,...v.error?{reason:v.error}:{}});return}}let O=S(),D=0;const J=t.subscribe(()=>{const v=t.state();(v==="unpaired"||v==="pairing")&&Y();const _=S();if(_&&!O)O=!0,D++,u=!1,m=!1,y=void 0,w.clear();else if(!_&&O){O=!1,u=!1,m=!1;for(const[W,se]of p)clearTimeout(se),p.delete(W);i({loading:!1});for(const W of l.runs)W.phase==="sending"&&W.op&&I(W.id,se=>({...se,phase:"uncertain",endedAt:Date.now()}))}}),Q=t.onMessage(G);function Y(){var v;if(!(!l.state&&!l.runs.length&&!Object.keys(l.graphs).length)){try{(v=Xe(n))==null||v.removeItem(vr)}catch{}g.clear(),i({state:null,error:null,at:null,loading:!1,graphs:{},queues:{},permissions:{},snapshots:{},routing:null,goals:null,runs:[]})}}async function ie(v){var re;if(!((re=s.getState().device)!=null&&re.confirm))return{phase:"rejected",reason:"confirm_required"};let _;try{_=await s.prepareConfirm(v)}catch(K){return{phase:K instanceof Error&&K.message==="timeout"?"expired":"unsent"}}if(!_.credentialId)return{phase:"rejected",reason:"confirm_required"};const W=Date.now(),se=await Yn({challenge:_.challenge,rpId:_.rpId,credentialId:_.credentialId}).catch(()=>"failed");return se==="cancelled"?{phase:"cancelled"}:se==="failed"?{phase:"unsent"}:Date.now()-W>=_.expiresInMs?{phase:"expired"}:{assertion:se}}function X(v,_,W){const se=Ny(),re={op:"",id:se,subject:v,phase:_?"checking":"sending",startedAt:Date.now()},K=new Promise(ce=>f.set(se,ce));return!S()||!b()?(i({runs:[...l.runs,{...re,phase:"unsent",endedAt:Date.now()}]}),f.delete(se),Promise.resolve({...re,phase:"unsent"})):(i({runs:[...l.runs,re]}),(async()=>{var pe;let ce;if(_){const he=await ie(_);if(!("assertion"in he)){I(se,Me=>({...Me,phase:he.phase,...he.reason?{reason:he.reason}:{},endedAt:Date.now()}));return}ce=he.assertion}const ge=gc(),Ye=xc.safeParse(W(ge,ce));if(!Ye.success||!S()){I(se,he=>({...he,phase:"unsent",endedAt:Date.now()}));return}g.set(ge,Ye.data),y===void 0&&w.add(ge),I(se,he=>({...he,op:ge,phase:"sending",sentAt:Date.now(),...y!==void 0?{boot:y}:{}})),M(ge);const pt=D,Re=await t.send(Ye.data).catch(()=>!1),Le=(pe=P(ge))==null?void 0:pe.phase;!Re&&pt===D&&(Le==="sending"||Le==="uncertain")&&($(`op:${ge}`),I(se,he=>({...he,phase:"unsent",endedAt:Date.now()})))})(),K)}const le={getState:()=>l,subscribe(v){return r.add(v),()=>{r.delete(v)}},follow(){c=!0,k()},retry(){u=!1,k()},openRig(v){const _=`graph:${v}`,W=`queue:${v}`,se=`permissions:${v}`;N(_,{type:"rigs.graph",rig:v},()=>i({graphs:{...l.graphs,[v]:E(l.graphs[v])}}))&&i({graphs:{...l.graphs,[v]:A(l.graphs[v])}}),N(W,{type:"rigs.queue",rig:v},()=>i({queues:{...l.queues,[v]:E(l.queues[v])}}))&&i({queues:{...l.queues,[v]:A(l.queues[v])}}),N(se,{type:"rigs.permissions",rig:v},()=>i({permissions:{...l.permissions,[v]:E(l.permissions[v])}}))&&i({permissions:{...l.permissions,[v]:A(l.permissions[v])}})},readSnapshots(v){N(`snapshots:${v}`,{type:"rigs.snapshots",rig:v},()=>i({snapshots:{...l.snapshots,[v]:E(l.snapshots[v])}}))&&i({snapshots:{...l.snapshots,[v]:A(l.snapshots[v])}})},readPermissions(v){const _=`permissions:${v}`;N(_,{type:"rigs.permissions",rig:v},()=>i({permissions:{...l.permissions,[v]:E(l.permissions[v])}}))&&i({permissions:{...l.permissions,[v]:A(l.permissions[v])}})},readRouting(){N("routing",{type:"rigs.routing"},()=>i({routing:E(l.routing??void 0)}))&&i({routing:A(l.routing??void 0)})},followGoals(){x=!0,T()},act(v){return X({kind:"act",action:v},Mr(v)?{purpose:"rigs",rigAct:v}:null,(_,W)=>({type:"rigs.act",op:_,action:v,...W?{assertion:W}:{}}))},reseat(v,_,W={}){var K,ce;const se=((ce=(K=l.state)==null?void 0:K.rigs.find(ge=>ge.name===v))==null?void 0:ce.nodes)??[],re=W.check||uc(se,_).remove.length>0;return X({kind:"seats",rig:v,seats:_,...W.delegation?{delegation:W.delegation}:{}},re?{purpose:"rigs",rigSeats:{rig:v,seats:_}}:null,(ge,Ye)=>({type:"rigs.seats",op:ge,rig:v,seats:_,...W.delegation?{delegation:W.delegation}:{},...Ye?{assertion:Ye}:{}}))},sendGoal(v,_=Wo()){return X({kind:"goal",goalId:_,text:v},null,W=>({type:"rigs.goal.send",op:W,goalId:_,text:v}))},replyGoal(v,_,W=Wo()){return X({kind:"reply",goalId:v,replyId:W,text:_},null,se=>({type:"rigs.goal.reply",op:se,goalId:v,replyId:W,text:_}))},dismiss(v){const _=l.runs.find(W=>W.id===v);_&&ya(_.phase)&&_.op&&(g.delete(_.op),$(`op:${_.op}`)),i({runs:l.runs.filter(W=>W.id!==v||!ya(W.phase))})},close(){o=!0,J(),Q();for(const v of p.values())clearTimeout(v);p.clear()}};return le}function Mn(t){return h.useSyncExternalStore(t.subscribe,t.getState,t.getState)}const Dl={relaunch:!0,noKernel:!1},Xu="ledge.mobile.daemonPrefs",wr=new Set;function Qu(t){var s;try{const n=JSON.parse(((s=Xe(t))==null?void 0:s.getItem(Xu))??"{}");return{relaunch:typeof n.relaunch=="boolean"?n.relaunch:Dl.relaunch,noKernel:typeof n.noKernel=="boolean"?n.noKernel:Dl.noKernel}}catch{return Dl}}function Sy(t,s){var n;try{(n=Xe(s))==null||n.setItem(Xu,JSON.stringify({...Qu(s),...t}))}catch{}for(const a of[...wr])a()}const $y=t=>(wr.add(t),()=>{wr.delete(t)});function ui(t){const s=h.useSyncExternalStore($y,()=>JSON.stringify(Qu(t)));return[JSON.parse(s),n=>Sy(n,t)]}function Yu(t,s){const n=s.relaunch?"last":"none";return t==="restart"?{kind:"daemon.restart",restore:n}:{kind:"daemon.start",restore:n,...s.noKernel&&!s.relaunch?{noKernel:!0}:{}}}const Ne=d.rigs;function Cy(t){var a;const s=t.subject;if(s.kind==="seats")return s.rig;if(s.kind!=="act")return"";const n=s.action;return n.rig??((a=n.seat)==null?void 0:a.split("@")[0])??""}const xi=t=>t.subject.kind==="act"?t.subject.action.kind:t.subject.kind==="seats"?"seats":null;function On(t){const s=xi(t);return s?Ne.notDone[s]:Ne.rejected.nothingSent}function My(t){const s=xi(t),n=Ne.rejected.againVerb;return s==="seats"?n.remove:s==="rig.stop"||s==="daemon.stop"||s==="kernel.stop"?n.stop:s==="rig.restart"||s==="daemon.restart"||s==="kernel.restart"?n.restart:s==="rig.policy"||s==="rig.permissions"?n.apply:s==="seat.set"?n.save:null}function Ey(t,s){const n=Ct(),a=t.phase==="expired"?"assertion_expired":t.phase==="cancelled"?"cancelled":t.phase==="unsent"?"unsent":t.reason??"unavailable",l=My(t),r=l?Ne.rejected.again(l):Ne.rejected.nothingSent;switch(a){case"busy":return{mark:"warn",title:Ne.busy.title(s),sub:Ne.busy.body};case"confirm_required":return t.subject.kind==="seats"?{mark:"warn",title:n?Ne.reseat.wouldLeave.title:Ne.reseat.wouldLeave.titleDevice,sub:Ne.reseat.wouldLeave.body}:{mark:"warn",title:Ne.rejected.confirm_required};case"assertion_expired":return{mark:"bad",title:Ne.because(On(t),Ne.rejected.assertion_expired(n)),sub:r};case"assertion_invalid":return{mark:"bad",title:Ne.because(On(t),Ne.rejected.assertion_invalid(n)),sub:r};case"cancelled":return{mark:"bad",title:Ne.because(On(t),Ne.rejected.cancelled),sub:Ne.rejected.nothingSent};case"unsent":return{mark:"bad",title:Ne.because(On(t),Ne.rejected.unsent),sub:Ne.rejected.nothingSent};default:return{mark:"bad",title:Ne.because(On(t),`${Ne.notSent(s)}.`)}}}function Ua({run:t,rigs:s,pc:n,bar:a=!1}){const l=xi(t),r=Cy(t),i={onClose:()=>s.dismiss(t.id),closeLabel:Ne.done.close};if(t.phase==="checking")return e.jsx(Vn,{bar:a,children:Ne.running.checking});if(t.phase==="sending"||t.phase==="received"){const m=l==="seats"?Ne.running.seats(r):l?Ne.running[l](r):"";return e.jsx(Vn,{bar:a,children:`${m} · ${Ne.running.note}`})}if(t.phase==="uncertain")return e.jsx(ve,{mark:"ask",title:Ne.uncertain.title,sub:Ne.uncertain.body,...i});if(t.phase!=="done"){const m=Ey(t,n);return e.jsx(ve,{mark:m.mark,title:m.title,...m.sub?{sub:m.sub}:{},...i})}const o=Fe(t.endedAt?new Date(t.endedAt).toISOString():null);if(t.reseated){const m=t.reseated;if(m.ok){const p=m.added.length?Ne.reseat.added(m.added.length,m.links):Ne.reseat.removed(m.removed.length);return e.jsxs(ve,{mark:"ok",title:p,...i,children:[m.linksUnsupported&&e.jsxs("small",{className:"block text-[12px] text-attention",children:[Ne.reseat.noLinks.title," ",Ne.reseat.noLinks.body]}),e.jsx(Vs,{commands:m.commands})]})}return m.error==="busy"?e.jsx(ve,{mark:"warn",title:Ne.busy.title(n),sub:Ne.busy.body,...i}):m.error==="rig_not_running"?e.jsx(ve,{mark:"bad",title:Ne.reseat.notRunning.title,sub:Ne.reseat.notRunning.body,...i}):e.jsx(ve,{mark:"bad",title:Ne.failed(m.message??Ne.errors[m.error??"failed"]??Ne.errors.failed),...i,children:e.jsx(Vs,{commands:m.commands})})}const c=t.done;if(!c||!l||l==="seats")return null;if(c.ok){const m=t.subject.kind==="act"&&t.subject.action.kind==="rig.stop"&&t.subject.action.snapshot;return e.jsx(ve,{mark:"ok",title:Ne.done[l](r),sub:[o,m?Ne.done.snapshotFirst:""].filter(Boolean).join(" · "),...i,children:e.jsx(Vs,{commands:c.commands})})}if(c.error==="busy")return e.jsx(ve,{mark:"warn",title:Ne.busy.title(n),sub:Ne.busy.body,...i});const x=t.subject.kind==="act"&&"seats"in t.subject.action?t.subject.action.seats.length:0;if(c.completed!==void 0&&x)return e.jsx(ve,{mark:"bad",title:Ne.completed(c.completed,x),...c.message?{sub:e.jsx("span",{className:"font-mono",children:c.message})}:{},...i});const u=c.error&&c.error!=="failed"?Ne.errors[c.error]:void 0;return e.jsx(ve,{mark:"bad",title:u??Ne.failed(Ne.errors.failed),...c.message?{sub:e.jsx("span",{className:"font-mono",children:c.message})}:{},...i,children:e.jsx(Vs,{commands:c.commands})})}function mi(t,s){for(let n=t.length-1;n>=0;n--)if(s(t[n]))return t[n]}const dl=t=>!!t&&(t.phase==="checking"||t.phase==="sending"||t.phase==="received"),be=d.rigs,Ay={running:"on",stopped:"plain",stale:"bad",unknown:"plain"},Zu={ready:"on",starting:"go",stopped:"plain",skipped:"plain",absent:"plain",unknown:"plain"};function pi({state:t,href:s}){const n=t.daemon.state==="running"&&t.daemon.startedAt?Fe(t.daemon.startedAt):null;return e.jsx(lr,{lead:e.jsx(F,{name:"cpu",className:"size-[18px] text-muted"}),name:be.daemon,chip:e.jsx(Nn,{tone:Ay[t.daemon.state],children:be.daemonState[t.daemon.state]}),sub:be.daemonSub(t.version,n),...s?{href:s}:{}})}function Ju({disabled:t,next:s=!1}){const[n,a]=ui();return e.jsxs(e.Fragment,{children:[e.jsx(Qi,{on:n.relaunch,label:be.relaunch,disabled:t,onChange:l=>a({relaunch:l})}),e.jsx(Qi,{on:n.noKernel,label:be.noKernel,hint:s?be.noKernelNext:be.noKernelHint,disabled:t,onChange:l=>a({noKernel:l})})]})}function Wa({glyph:t,title:s,body:n,list:a=!0,children:l}){return e.jsxs("div",{"data-list-state":a?"":void 0,className:"flex flex-col items-center gap-1.5 px-4 pt-[26px] pb-[22px] text-center",children:[t&&e.jsx("div",{"aria-hidden":"true",className:"grid size-12 place-items-center rounded-[10px] border border-line text-muted",children:t}),e.jsx("h2",{className:"mt-1.5 text-[17px] leading-6 font-semibold",children:s}),e.jsx("p",{className:"max-w-[300px] text-[13.5px] text-muted",children:n}),l]})}function Ko({state:t,rigs:s,store:n,pc:a}){const l=fe(n).fresh,[r]=ui(),i=Mn(s),o=mi(i.runs,c=>c.subject.kind==="act"&&c.subject.action.kind==="daemon.start");return e.jsxs(e.Fragment,{children:[t&&e.jsxs(e.Fragment,{children:[e.jsx(zt,{children:be.openrig}),e.jsx(Ke,{children:e.jsx(pi,{state:t})})]}),e.jsxs(Ke,{children:[e.jsx(Wa,{glyph:e.jsx(F,{name:"power"}),title:be.stopped.title,body:be.stopped.body}),e.jsx("div",{className:"border-t border-line",children:e.jsx(Ju,{disabled:!l})}),e.jsx("div",{className:"p-3",children:e.jsx("button",{type:"button",disabled:!l||dl(o),onClick:()=>{s.act(Yu("start",r))},className:je({tone:"primary",className:"w-full"}),children:e.jsx(Lt,{icon:"power",children:be.stopped.start})})})]}),o&&e.jsx(Ua,{run:o,rigs:s,pc:a}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:be.stopped.note})]})}function Ty(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[5px] bg-raised";return e.jsxs("div",{role:"status","data-list-state":"",className:"flex flex-col gap-3",children:[e.jsx(Ke,{children:e.jsxs("div",{"aria-hidden":"true",className:"flex flex-col gap-2.5 p-2.5",children:[e.jsx("span",{className:`${t} h-3.5 w-[60%]`}),e.jsx("span",{className:`${t} h-3 w-[40%]`})]})}),e.jsx(Ke,{children:e.jsxs("div",{"aria-hidden":"true",className:"flex flex-col gap-2.5 p-2.5",children:[e.jsx("span",{className:`${t} h-3.5 w-1/2`}),e.jsx("span",{className:`${t} h-3 w-[70%]`}),e.jsx("span",{className:`${t} h-3.5 w-[45%]`}),e.jsx("span",{className:`${t} h-3 w-[65%]`})]})}),e.jsx("span",{className:"text-[12px] text-muted",children:be.loading})]})}function _y({state:t,at:s,store:n,offline:a}){const l=fe(n),r=Zn(),i=It(),o=jd(t),c=ar(t),x=c.filter(g=>Ff(ms(g))).length,u=[...l.sessions.values()],m=((o==null?void 0:o.nodes)??[]).map(Md),p=t.daemon.state==="running";return e.jsxs("div",{className:`flex flex-col gap-3 ${a?"opacity-50":""}`,children:[e.jsx(zt,{aside:!a&&s?be.updatedAt(Fe(s)):void 0,children:be.openrig}),e.jsxs(Ke,{label:be.openrig,children:[e.jsx(pi,{state:t,...a?{}:{href:ae({name:"kernel"})}}),t.kernel.state!=="absent"&&e.jsx(lr,{lead:e.jsx(Ie,{state:"rig"}),name:be.kernel,selected:r.name==="kernel"&&i,chip:e.jsx(Nn,{tone:Zu[t.kernel.state],children:be.kernelState[t.kernel.state]}),sub:m.length?a||i?be.kernelSubShort(m):be.kernelSub(m):"",...a?{}:{href:ae({name:"kernel"})}})]}),p&&c.length===0?e.jsx(Ke,{children:e.jsx(Wa,{title:be.empty.title,body:be.empty.body,list:!1,children:e.jsx("a",{href:ae({name:"max"}),className:je({size:"sm",className:"mt-1.5"}),children:be.empty.talk})})}):c.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(zt,{children:be.rigsHead(x)}),e.jsx(Ke,{tone:"rigs",label:be.title,children:c.map(g=>{const f=ms(g),y=Nd(g.name,u,l.asks),w=f==="stopped",S=a?[w?be.seatCount(g.seats):be.seats(g.running,g.seats),!w&&s?be.at(Fe(s)):""].filter(Boolean).join(" · "):f==="stopped"?[be.seatCount(g.seats),g.snapshot?be.snapshot(g.snapshot):be.noSnapshot].join(" · "):f==="partial"?[be.seats(g.running,g.seats),be.stoppedCount(g.nodes.filter(j=>j.stopped).length||g.seats-g.running)].join(" · "):f==="starting"?be.seats(g.running,g.seats):[be.seats(g.running,g.seats),g.uptime?be.since(g.uptime):"",g.snapshot?be.snapshot(g.snapshot):""].filter(Boolean).join(" · "),b=!a&&(y.perm||y.ask)?e.jsxs(e.Fragment,{children:[y.perm>0&&e.jsx(Kn,{perm:!0,children:be.attention.permission(y.perm)}),y.ask>0&&e.jsx(Kn,{children:be.attention.question(y.ask)})]}):void 0;return e.jsx(lr,{lead:e.jsx(Ie,{state:kd(g,y),pulse:f==="starting"&&!a}),name:g.name,dim:w,chip:e.jsx(Nn,{tone:Ed[f],children:be.status[f]}),sub:S,att:b,href:ae({name:"rig",rig:g.name}),selected:i&&r.name==="rig"&&r.rig===g.name},g.id)})})]}),!a&&p&&e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:be.launchNote})]})}function Iy({rigs:t,store:s}){const n=Mn(t),{pc:a,look:l}=qt(),r=l==="offline";h.useEffect(()=>{t.follow()},[t]);const i=Bt(a),o=n.state,c=o?o.installed?!r&&Gf(o)?e.jsx(Ko,{state:o,rigs:t,store:s,pc:i}):e.jsxs(e.Fragment,{children:[!r&&n.error&&e.jsxs(Kt,{warn:!0,role:"alert",lead:e.jsx(F,{name:"warning",className:"mt-px size-4 text-attention"}),children:[e.jsx("b",{className:"font-semibold",children:be.unavailable.title}),n.at&&e.jsx("span",{className:"text-muted",children:be.unavailable.body(Fe(n.at))}),e.jsx("button",{type:"button",onClick:()=>t.retry(),className:je({size:"sm",className:"self-start"}),children:e.jsx(Lt,{icon:"refresh",children:be.unavailable.retry})})]}),e.jsx(_y,{state:o,at:n.at,store:s,offline:r})]}):e.jsx(Ke,{children:e.jsx(Wa,{title:be.notInstalled.title,body:be.notInstalled.body(i)})}):n.error==="not_installed"?e.jsx(Ke,{children:e.jsx(Wa,{title:be.notInstalled.title,body:be.notInstalled.body(i)})}):n.error==="daemon_stopped"?e.jsx(Ko,{state:null,rigs:t,store:s,pc:i}):n.error?e.jsx("div",{"data-list-state":"",className:"flex flex-col",children:e.jsxs(Kt,{warn:!0,role:"alert",lead:e.jsx(F,{name:"warning",className:"mt-px size-4 text-attention"}),children:[e.jsx("b",{className:"font-semibold",children:be.unavailable.title}),e.jsx("button",{type:"button",onClick:()=>t.retry(),className:je({size:"sm",className:"self-start"}),children:e.jsx(Lt,{icon:"refresh",children:be.unavailable.retry})})]})}):e.jsx(Ty,{});return e.jsx(Os,{title:be.title,offlineBody:be.offlineBody,heading:!1,children:c})}const te=d.rigs;function Ka(t,s=new Date){const n=Pa(t);if(!n)return{short:t,long:t};const a=n.toLocaleTimeString(dt,{hour:"2-digit",minute:"2-digit"}),l=Qr(n,s);if(l===0)return{short:a,long:te.snapshots.today(a)};if(l===1)return{short:te.snapshots.yesterday(a),long:te.snapshots.yesterday(a)};const r=n.toLocaleDateString(dt,{weekday:"short",day:"numeric",month:"short"});return{short:r,long:`${r} ${a}`}}function zs({verb:t,confirm:s,disabled:n,onClick:a}){const l=Ct();return s?e.jsx("button",{type:"button",disabled:n,onClick:a,className:je({tone:"dangerfill",className:"w-full"}),children:e.jsx(Lt,{icon:l?"face":"passkey",size:"size-[18px]",children:te.withCheck(t,l)})}):e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("p",{className:"text-[12.5px] text-muted",children:te.protectFirst}),e.jsx("a",{href:ae({name:"connection"}),className:je({className:"w-full"}),children:te.openSettings})]})}const da=({onClose:t})=>e.jsx("button",{type:"button",onClick:t,className:je({className:"w-full"}),children:te.confirm.cancel});function Na({title:t,conseq:s,note:n,verb:a,confirm:l,live:r,onConfirm:i,onClose:o}){return e.jsxs(rs,{title:t,onClose:o,children:[s&&e.jsx(Yr,{title:s.title,...s.body?{body:s.body}:{}}),n&&e.jsx("p",{className:"text-[12.5px] leading-[18px] text-muted",children:n}),e.jsx(zs,{verb:a,confirm:l,disabled:!r,onClick:()=>{o(),i()}}),e.jsx(da,{onClose:o})]})}function Gs({icon:t,label:s,aside:n,onClick:a,disabled:l=!1,danger:r=!1}){return e.jsxs("button",{type:"button",role:"menuitem",disabled:l,onClick:a,className:`flex min-h-12 items-center gap-3 border-b border-line px-3.5 text-left text-[15px] last:border-b-0 disabled:opacity-45 ${r?"text-approval":""}`,children:[e.jsx(F,{name:t,className:`size-[18px] ${r?"":"text-muted"}`}),e.jsx("span",{className:"min-w-0 flex-1",children:s}),n&&e.jsx("span",{className:"text-[13px] text-muted",children:n})]})}function Ry({rig:t,live:s,running:n,snapshots:a,level:l,onSnapshot:r,onSnapshots:i,onPermissions:o,onRefresh:c,onClose:x}){return e.jsx(rs,{title:t,onClose:x,children:e.jsxs("div",{role:"menu","aria-label":te.more,className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:[e.jsx(Gs,{icon:"camera",label:te.actions.snapshot,disabled:!s||n,onClick:r}),e.jsx(Gs,{icon:"list",label:te.actions.snapshots,...a!==null?{aside:String(a)}:{},onClick:i}),e.jsx(Gs,{icon:"shield",label:te.actions.permissions,...l?{aside:l}:{},onClick:o}),e.jsx(Gs,{icon:"refresh",label:te.actions.refresh,disabled:!s,onClick:c})]})})}function Oy({live:t,up:s,onRefresh:n,onRestart:a,onStop:l,onClose:r}){return e.jsx(rs,{title:te.kernel,onClose:r,children:e.jsxs("div",{role:"menu","aria-label":te.more,className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:[e.jsx(Gs,{icon:"refresh",label:te.kernelView.menu.refresh,disabled:!t,onClick:n}),e.jsx(Gs,{icon:"refresh",label:te.kernelView.menu.restart,disabled:!t||!s,onClick:a}),e.jsx(Gs,{icon:"power",label:te.kernelView.menu.stop,danger:!0,disabled:!t||!s,onClick:l})]})})}function Ly({rig:t,pc:s,verb:n,confirm:a,live:l,onAct:r,onClose:i}){const[o,c]=h.useState(!0),[x,u]=h.useState(!1),m=t.nodes.filter(y=>!y.stopped&&ra(y)).map(y=>bs(y.logicalId,y.session)),p=n==="stop",g=m.length?te.confirm.working(m.length):te.confirm.noneWorking,f=p?{kind:"rig.stop",rig:t.name,...o?{snapshot:!0}:{},...x?{force:!0}:{}}:{kind:"rig.restart",rig:t.name};return e.jsxs(rs,{title:p?te.confirm.stop(t.name,s):te.confirm.restart(t.name,s),onClose:i,children:[e.jsx(Yr,{title:g,body:p?m.length?m.join(", "):void 0:te.confirm.restartNote}),p&&e.jsxs("div",{className:"overflow-hidden rounded-[10px] border border-line",children:[e.jsx(Xi,{on:o,label:te.confirm.snapshot,onChange:c}),e.jsx(Xi,{on:x,label:te.confirm.force,onChange:u})]}),e.jsx(zs,{verb:p?te.actions.stop:te.actions.restart,confirm:a,disabled:!l,onClick:()=>{i(),r(f)}}),e.jsx(da,{onClose:i})]})}function ex({rig:t,confirm:s,live:n,onReseat:a,onDone:l,context:r}){const i=$d(t),[o,c]=h.useState({}),[x,u]=h.useState("pairs"),m=Object.fromEntries(Object.entries(o).filter(([j,N])=>{var $;return(($=i.find(A=>A.role===j))==null?void 0:$.count)!==N})),p=uc(t.nodes,m),g=p.add.length,f=p.remove.length,y=t.nodes.filter(j=>p.remove.includes(j.logicalId)&&ra(j)).map(j=>j.logicalId),w=g&&f?te.reseat.change(g,f):g?te.reseat.add(g):f?te.reseat.remove(f):te.reseat.noChange,S=()=>{l==null||l(),c({}),a(m,g?x:void 0)},b=r!==void 0;return e.jsxs(e.Fragment,{children:[e.jsx("table",{className:"w-full border-collapse text-[13px]",children:e.jsx("tbody",{children:i.map(j=>{const N=o[j.role]??j.count,$=p.add.filter(C=>C.role===j.role).map(C=>te.reseat.adds(`${C.pod}.${C.id}`)),A=p.remove.filter(C=>j.ids.includes(C)).map(te.reseat.removes),E=j.ids.map(C=>{var I;return bs(C,(I=t.nodes.find(P=>P.logicalId===C))==null?void 0:I.session)}).join(", "),k=b?j.ids.map(C=>r[C]).filter(C=>C!==void 0).map(C=>`${Math.round(C)} %`).join(", "):"",T=b?[...$,...A].join(" · "):[E,...$,...A].join(A.length?" → ":" · ");return e.jsxs("tr",{className:"border-b border-line last:border-b-0",children:[e.jsxs("td",{className:"px-1 py-[7px] font-mono text-[12.5px]",children:[j.role,T&&e.jsx("small",{className:"block font-sans text-[11.5px] text-muted",children:T})]}),b&&e.jsx("td",{className:"px-1 py-[7px] text-[12px] text-muted",children:k}),e.jsx("td",{className:"px-1 py-[7px] text-right",children:e.jsx(th,{value:N,changed:N!==j.count,disabled:!n,fewer:te.reseat.fewer(j.role),more:te.reseat.more(j.role),onChange:C=>c({...o,[j.role]:C})})})]},j.role)})})}),g>0&&e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"flex-1 text-[12.5px] text-muted",children:te.reseat.delegation}),e.jsx(Ca,{label:te.reseat.delegation,value:x,onChange:u,options:[{value:"pairs",label:te.reseat.pairs},{value:"all",label:te.reseat.all}]})]}),f>0&&e.jsx(Yr,{title:y.length?te.reseat.working(y):te.reseat.lastFirst,...y.length?{body:te.reseat.lastFirst}:{}}),(!b||g+f>0)&&(f>0?e.jsx(zs,{verb:w,confirm:s,disabled:!n,onClick:S}):e.jsx("button",{type:"button",disabled:!n||g===0,onClick:S,className:je({tone:"primary",className:"w-full"}),children:w})),b&&g+f>0&&e.jsx("button",{type:"button",onClick:()=>c({}),className:je({className:"w-full"}),children:te.confirm.cancel})]})}function zy({rig:t,pc:s,confirm:n,live:a,onReseat:l,onClose:r}){return e.jsxs(rs,{title:te.reseat.title(t.name,s),onClose:r,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:te.reseat.today($d(t).map(i=>te.reseat.part(i.count,i.role)).join(", "))}),e.jsx(ex,{rig:t,confirm:n,live:a,onReseat:l,onDone:r}),e.jsx(da,{onClose:r})]})}function Dy({rig:t,read:s,level:n,confirm:a,live:l,onAct:r,onClose:i}){var w,S;const[o,c]=h.useState(n==="mixed"?null:n),x=Ct(),u=Uf((w=s==null?void 0:s.data)==null?void 0:w.policy),m=(((S=s==null?void 0:s.data)==null?void 0:S.seats.map(b=>b.session))??t.nodes.map(b=>b.session)).filter(b=>b.endsWith(`@${t.name}`)),p=o&&m.length?{kind:"rig.policy",rig:t.name,policy:o,seats:m}:null,g=!!p&&Mr(p),f=()=>{p&&(i(),r(p))},y=!l||!p||o===n;return e.jsxs(rs,{title:te.permissions.title(t.name),onClose:i,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:[te.permissions.sub,u?te.permissions.spec(te.level[u]):""].filter(Boolean).join(" ")}),(s==null?void 0:s.error)&&!s.data&&e.jsx("p",{role:"alert",className:"text-[12.5px] text-attention",children:te.permissions.unavailable}),e.jsx("div",{className:"flex flex-col gap-1.5",children:qf.map(b=>e.jsx(rr,{pressed:o===b,disabled:!l,onClick:()=>c(b),sub:te.permissions.hint[b],title:e.jsxs(e.Fragment,{children:[te.level[b],(b==="yolo"||b==="spec")&&e.jsx("span",{className:"ml-1.5 inline-flex align-middle",children:e.jsx(as,{tone:"perm",children:x?te.permissions.faceId:te.permissions.check})})]})},b))}),g?e.jsx(zs,{verb:te.permissions.apply,confirm:a,disabled:y,onClick:f}):e.jsx("button",{type:"button",disabled:y,onClick:f,className:je({tone:"primary",className:"w-full"}),children:te.permissions.apply})]})}const Fy=(t,s)=>{const n=Yf(t,s.links).map(a=>{var r;const l=bs(a.who,(r=s.seats.find(i=>i.logicalId===a.who))==null?void 0:r.session);return a.kind==="linked"?te.seat.linked(l,a.label):te.seat[a.kind](l)});return n.length?n.join(" · "):te.seat.noLink};function Py({rig:t,seat:s,graph:n,node:a,session:l,status:r,near:i,onSettings:o,onClose:c}){const x=Gr({session:l,node:a,graph:s,rigStatus:r}),u=Xr(s.runtime),m=bs(s.logicalId,s.session),p=[u?d.tools[u]:s.runtime,s.model??(a==null?void 0:a.model)??""].filter(Boolean).join(" · "),g=l!=null&&l.pending?te.seat.prompt(te.seatState[x]):te.seatState[x],f=a&&a.work>0?te.seat.tasks(a.work):te.seat.noTask,y=[[te.seat.harness,p],...s.context!==void 0?[[te.seat.context,e.jsx("span",{className:`font-mono ${s.context>=i?"text-attention":""}`,children:`${Math.round(s.context)} %`},"c")]]:[],[te.seat.now,g],[te.seat.work,f],[te.seat.links,Fy(s.logicalId,n)]];return e.jsxs(rs,{title:m,onClose:c,children:[e.jsxs("div",{className:"-mt-2 flex items-center gap-2",children:[e.jsx(Ie,{state:vd[x]}),u&&e.jsx(fs,{tool:u}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"text-[12.5px] text-muted",children:te.seat.of(s.logicalId,t)})]}),e.jsx("dl",{className:"m-0 grid grid-cols-[110px_1fr] gap-x-3 gap-y-1.5 text-[13px]",children:y.map(([w,S])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted",children:w}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:S})]},w))}),l?e.jsx("a",{href:ae({name:"thread",sessionId:l.id}),className:je({tone:"primary",className:"w-full"}),children:te.seat.openSession}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:!0,className:je({tone:"primary",className:"w-full"}),children:te.seat.openSession}),e.jsx("p",{className:"-mt-1 text-[12px] text-muted",children:te.seat.noSession})]}),e.jsx("button",{type:"button",onClick:o,className:je({className:"w-full"}),children:e.jsx(Lt,{icon:"gear",children:te.seat.settings})})]})}function By({rig:t,seat:s,node:n,selection:a,confirm:l,live:r,onAct:i,onClose:o}){const c=te.seatSettings,x=s.runtime==="codex"?"codex":s.runtime==="claude-code"||s.runtime==="claude"?"claude-code":null,u=s.model??(n==null?void 0:n.model)??"",m=a==="inherit"||a==="auto"||a==="full_bypass"?a:null,[p,g]=h.useState(x),[f,y]=h.useState(u),[w,S]=h.useState(null),[b,j]=h.useState(m),N=bs(s.logicalId,s.session),$=s.session??(n==null?void 0:n.session)??`${N}@${t}`,A=f.trim()===""||Hx.safeParse(f.trim()).success,E=p!==null&&p!==x,k={kind:"seat.set",seat:$,...E?{runtime:p}:{},...f.trim()&&f.trim()!==u?{model:f.trim()}:{},...w?{effort:w}:{},...b&&b!==m?{permissions:b}:{}},T=Object.keys(k).length>2,C=Mr(k),I=Xr(s.runtime),P=[I?d.tools[I]:s.runtime,u,m?c.perm[m]:""].filter(Boolean),L=!r||!T||!A,R=()=>{o(),i(k)},M=(z,U,H)=>e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"text-[12.5px] text-muted",children:`${z} · ${U}`}),H]});return e.jsxs(rs,{title:c.title(N,t),onClose:o,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:c.today(P)}),M(c.harness,c.whenNow,e.jsx(Ca,{label:c.harness,value:p,disabled:!r,onChange:g,options:[{value:"claude-code",label:d.tools.claude},{value:"codex",label:d.tools.codex}]})),M(c.model,c.whenResume,e.jsx("input",{"aria-label":c.modelLabel,value:f,disabled:!r,onChange:z=>y(z.target.value),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,className:`h-11 rounded-[10px] border bg-surface px-3 text-base outline-none focus:border-ring ${A?"border-input":"border-approval/60"}`})),M(c.effort,c.whenResume,e.jsx(Ca,{label:c.effort,value:w,disabled:!r,onChange:S,options:["medium","high","xhigh"].map(z=>({value:z,label:c.effortLevel[z]}))})),M(c.permissions,c.whenLaunch,e.jsx(Ca,{label:c.permissions,value:b,disabled:!r,onChange:j,options:["inherit","auto","full_bypass"].map(z=>({value:z,label:c.perm[z]}))})),E&&e.jsx("p",{className:"text-[12.5px] text-attention",children:c.moveNote}),C?e.jsx(zs,{verb:c.save,confirm:l,disabled:L,onClick:R}):e.jsx("button",{type:"button",disabled:L,onClick:R,className:je({tone:"primary",className:"w-full"}),children:c.save})]})}function tx({read:t,kindOnly:s=!1,retry:n}){const a=Ad((t==null?void 0:t.data)??[]),l="overflow-hidden rounded-[10px] border border-line bg-surface dark:bg-transparent";return t!=null&&t.error&&!t.data?e.jsx("div",{className:l,children:e.jsx(Rs,{retry:n,retryLabel:te.unavailable.retry,children:te.snapshots.unavailable})}):t!=null&&t.data&&a.length===0?e.jsx("div",{className:l,children:e.jsx(Rs,{children:te.snapshots.none})}):a.length?e.jsx("div",{className:"flex max-h-[45dvh] flex-col overflow-y-auto rounded-[10px] border border-line bg-surface dark:bg-transparent",children:a.map(r=>e.jsxs("div",{className:"flex min-h-[46px] items-center gap-2.5 border-b border-line px-3 py-1.5 text-[13px] last:border-b-0",children:[e.jsx(F,{name:"camera",className:"size-4 text-muted"}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{children:Ka(r.createdAt).long}),e.jsx("small",{className:"text-[11.5px] text-muted",children:s?te.snapshots.kind[r.kind]??r.kind:[te.snapshots.kind[r.kind]??r.kind,te.snapshots.status[r.status]??r.status].join(" · ")})]})]},r.id))}):e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:te.loading})}function qy({rig:t,read:s,live:n,running:a,onSnapshot:l,onRetry:r,onClose:i}){return e.jsxs(rs,{title:te.snapshots.title(t),onClose:i,children:[e.jsx(tx,{read:s,retry:r}),e.jsx("button",{type:"button",disabled:!n||a,onClick:()=>{i(),l()},className:je({className:"w-full"}),children:e.jsx(Lt,{icon:"camera",children:te.snapshots.take})}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:te.snapshots.utc})]})}const me=d.rigs,Cs=t=>{var s;return((s=Pa(t))==null?void 0:s.toISOString())??t},Hy={mine:"border-attention/50 text-attention",progress:"border-info/45 text-info",pending:"border-input text-muted",blocked:"border-approval/45 text-approval"},Uy=({tone:t})=>e.jsx("span",{"data-row":t,className:`flex-none rounded-[5px] border px-1.5 text-[11px] leading-[18px] whitespace-nowrap ${Hy[t]}`,children:me.queue.tone[t]}),Xs=t=>t.split("@")[0]??t;function sx({seat:t,state:s,pod:n,tag:a,near:l,isNew:r,pulse:i,onOpen:o,onMore:c,top:x=!1,name:u,words:m}){const{swallow:p,...g}=sh(c),f=u??bs(t.logicalId,t.session),y=Xr(t.runtime),w=t.context!==void 0&&s!=="off"&&s!=="waiting"?Math.round(t.context):null,S=m??[x?n:void 0,me.seatState[s]].filter(Boolean).join(" · "),b=r?"border-ok/55":s==="ask"?"border-attention/55":s==="perm"?"border-approval/55":s==="off"||s==="waiting"?"border-dashed border-input bg-transparent":"border-line",j=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx(Ie,{state:vd[s],pulse:i}),e.jsx("b",{className:`truncate text-[13px] font-semibold ${s==="off"?"text-muted":""}`,children:f}),r?e.jsx("span",{className:"ml-auto",children:e.jsx(as,{tone:"ok",children:me.reseat.new})}):a&&y&&e.jsx("span",{className:"ml-auto",children:e.jsx(fs,{tool:y})})]}),e.jsxs("small",{className:`truncate text-[11.5px] ${s==="ask"?"text-attention":"text-muted"}`,children:[S,w!==null&&e.jsxs(e.Fragment,{children:[S?" · ":"",e.jsx("span",{className:`font-mono ${w>=l?"text-attention":""}`,children:`${w} %`})]})]})]}),N=`flex min-w-0 flex-col gap-px rounded-[9px] border bg-surface px-[9px] py-[7px] text-left ${b} ${x?"w-[190px] max-w-full":""}`;return o?e.jsx("button",{type:"button",...g,onClick:()=>{p!=null&&p()||o()},"aria-label":me.seatLabel(f,me.seatState[s]),"data-seat":t.logicalId,className:N,children:j}):e.jsx("div",{"data-seat":t.logicalId,className:N,children:j})}function Wy({graph:t,rig:s,status:n,sessions:a,near:l,added:r,onSeat:i,wide:o=!1}){var g;const c=Bf(t.seats,t.links),x=t.seats.find(f=>f.logicalId===c),u=Pf(t.seats.filter(f=>f.logicalId!==c),t.pods),m=(x==null?void 0:x.runtime)??((g=t.seats[0])==null?void 0:g.runtime),p=(f,y=!1)=>{var $;const w=yd(a,s.name,f.logicalId),S=Gr({session:w,node:s.nodes.find(A=>A.logicalId===f.logicalId),graph:f,rigStatus:n}),b=(($=t.pods.find(A=>A.id===f.pod))==null?void 0:$.label)??f.pod,j=i?()=>i(f.logicalId):void 0,N=o&&w?()=>Zs({name:"thread",sessionId:w.id}):void 0;return e.jsx(sx,{seat:f,state:S,pod:b,top:y,near:l,isNew:r.includes(f.logicalId),tag:y||f.runtime!==m,pulse:S==="starting"||n==="starting"&&S==="work",onOpen:N??j,onMore:N?j:void 0},f.logicalId)};return e.jsxs("div",{className:"flex flex-col items-center",children:[x&&e.jsxs(e.Fragment,{children:[p(x,!0),e.jsx("span",{"aria-hidden":"true",className:"h-3 w-[1.5px] bg-input"})]}),e.jsx("div",{className:`grid w-full gap-2 ${u.length>=3?"grid-cols-3":u.length===1&&!x?"grid-cols-1":"grid-cols-2"}`,children:u.map(f=>e.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5 rounded-[10px] border border-dashed border-input p-1.5",children:[e.jsx("small",{className:"px-0.5 font-mono text-[10.5px] text-muted",children:f.label}),f.seats.map(y=>p(y))]},f.id))})]})}function Ky({row:t,mine:s}){const n=[[me.queue.from,`${Xs(t.from)} → ${Xs(t.to)}`],...t.blockedOn?[[me.queue.blockedOn,t.blockedOn]]:[],[me.queue.created,[Fe(Cs(t.createdAt)),t.claimedAt?me.queue.claimed(Fe(Cs(t.claimedAt))):""].filter(Boolean).join(" · ")]];return e.jsxs("div",{className:"flex flex-col gap-2 border-b border-line bg-raised/40 px-3 py-2.5 last:border-b-0",children:[e.jsx("span",{className:"font-mono text-[12px] text-muted",children:t.id}),t.summary&&e.jsx("b",{className:"text-[14px] font-semibold",children:t.summary}),e.jsx("dl",{className:"m-0 grid grid-cols-[90px_1fr] gap-x-3 gap-y-1 text-[13px]",children:n.map(([a,l])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted",children:a}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:l})]},a))}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:me.queue.readOnly}),s&&e.jsx("a",{href:ae({name:"atoi"}),className:je({size:"sm",className:"self-start"}),children:me.queue.seeAtoi})]})}function Vy({read:t,asks:s,now:n,retry:a}){const[l,r]=h.useState(null),[i,o]=h.useState(!1),c=t==null?void 0:t.data;if(!c)return e.jsx(Ke,{children:t!=null&&t.error?e.jsx(Rs,{retry:a,retryLabel:me.unavailable.retry,children:me.queue.unavailable}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:me.loading})});const x={done:e.jsx("span",{className:"text-ok",children:"✓"}),handed:e.jsx("span",{className:"text-muted",children:"↪"}),stopped:e.jsx("span",{className:"text-approval",children:"✕"})};return e.jsxs(e.Fragment,{children:[e.jsx(zt,{children:me.queue.title(c.rows.length)}),e.jsxs(Ke,{children:[c.rows.length===0&&e.jsx("p",{className:"p-3 text-[13px] text-muted",children:me.queue.none}),c.rows.map(u=>{const m=Wf(u,s),p=l===u.id;return e.jsxs("div",{className:"contents",children:[e.jsxs("button",{type:"button","aria-expanded":p,onClick:()=>r(p?null:u.id),className:"flex min-h-[46px] w-full items-center gap-[9px] border-b border-line px-3 py-1.5 text-left text-[13px] last:border-b-0",children:[e.jsx(Uy,{tone:m}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate",children:u.summary??u.id}),e.jsx("small",{className:"truncate text-[11.5px] text-muted",children:[`${Xs(u.from)} → ${Xs(u.to)}`,u.needsInput?me.queue.prompt:""].filter(Boolean).join(" · ")})]}),e.jsx("span",{className:"font-mono text-[11px] whitespace-nowrap text-muted",children:jn(Cs(u.updatedAt),n)})]}),p&&e.jsx(Ky,{row:u,mine:m==="mine"})]},u.id)}),c.closed.length>0&&e.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>o(!i),className:"flex min-h-[46px] w-full items-center gap-[9px] border-t border-line px-3 text-left text-[13px] text-muted first:border-t-0",children:[e.jsx(F,{name:"chevron",className:`size-3.5 transition-transform ${i?"rotate-90":""}`}),e.jsx("span",{children:me.queue.closed(c.closed.length)})]}),i&&c.closed.map(u=>{const m=Kf(u.state);return e.jsxs("div",{className:"flex min-h-[46px] items-center gap-[9px] border-t border-line px-3 py-1.5 text-[13px] text-muted",children:[e.jsx("span",{"aria-hidden":"true",children:x[m]}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate text-fg",children:u.summary??u.id}),e.jsx("small",{className:"truncate text-[11.5px]",children:`${Xs(u.from)} → ${Xs(u.to)} · ${me.queue.closedTone[m]}`})]}),e.jsx("span",{className:"font-mono text-[11px]",children:Fe(Cs(u.updatedAt))})]},u.id)})]}),c.truncated&&e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:me.queue.truncated})]})}function Gy({rig:t,sessions:s,asks:n}){var f;const a=s.filter(y=>{var w;return((w=y.rig)==null?void 0:w.name)===t}),l=Wt(a),r=l.find(y=>y.filter==="permission")??l[0],i=r?a.find(y=>y.id===r.sessionId):void 0,o=r||n==null?void 0:n.find(y=>y.from.rig===t&&y.kind!=="update");if(!r&&!o)return null;const c=i?(f=i.rig)!=null&&f.role?bs(i.rig.role):i.name:o?Xs(o.from.seat):"",x=(r==null?void 0:r.filter)==="permission",[u,m,p]=x?me.waits.permission(c):me.waits.question(c),g=ae(r?{name:"request",sessionId:r.sessionId,key:r.key}:{name:"atoi"});return e.jsx(Kt,{warn:!x,danger:x,compact:!0,lead:e.jsx(Ie,{state:x?"perm":"ask"}),action:e.jsx("a",{href:g,className:je({size:"xs"}),children:me.waits.see}),children:e.jsxs("span",{children:[u,e.jsx("b",{className:"font-semibold",children:m}),p]})})}function Xy({rig:t,rigs:s,store:n}){var bt,jt,Z,q,ye,_e;const a=Mn(s),l=fe(n),{pc:r,look:i}=qt(),o=It(),[c,x]=h.useState(null),[u,m]=h.useState("last"),p=l.fresh,g=i==="offline",[f,y]=h.useState(()=>Date.now());h.useEffect(()=>{const oe=setInterval(()=>y(Date.now()),3e4);return()=>clearInterval(oe)},[]),h.useEffect(()=>{s.follow(),p&&(s.openRig(t),s.readSnapshots(t))},[s,t,p]);const w=Bt(r),S=a.state,b=S==null?void 0:S.rigs.find(oe=>oe.name===t),j=a.graphs[t],N=a.permissions[t],$=a.snapshots[t],A=a.queues[t],E=[...l.sessions.values()],k=((bt=l.device)==null?void 0:bt.contextNear)??70,T=!!((jt=l.device)!=null&&jt.confirm),C=mi(a.runs,oe=>Qf(oe.subject)===t),I=dl(C),P=oe=>{s.act(oe)},L=(oe,Ae)=>{s.reseat(t,oe,Ae?{delegation:Ae}:{})},R=()=>x(null),M=()=>s.openRig(t),z=e.jsx("button",{type:"button","aria-label":me.more,title:me.more,"aria-haspopup":"menu",onClick:()=>x({kind:"more"}),className:$t(),children:e.jsx(F,{name:"more"})}),U=(oe,Ae,st)=>o?e.jsxs("header",{className:"pane-head flex h-[58px] flex-none items-center gap-2 border-b border-line pr-1.5",children:[e.jsx(ls,{fallback:{name:"rigs"},label:me.back}),e.jsx("h1",{className:"min-w-0 truncate text-[17px] font-semibold",children:t}),oe,Ae&&e.jsx("span",{className:"min-w-0 truncate text-[12.5px] text-muted",children:Ae}),e.jsx("span",{className:"flex-1"}),st,b&&z]}):e.jsxs("header",{className:"flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-0.5",children:[e.jsx(ls,{fallback:{name:"rigs"},label:me.back}),e.jsx("h1",{className:"min-w-0 truncate text-base font-semibold",children:t}),oe,e.jsx("span",{className:"flex-1"}),b&&z]}),H=`tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pb-[18px] ${o?"pt-[18px]":"pt-3"}`;if(!!S&&(!b||(j==null?void 0:j.error)==="unknown_rig"||(A==null?void 0:A.error)==="unknown_rig"))return e.jsxs(e.Fragment,{children:[U(null),e.jsx("main",{"data-tab-scroll":"",className:H,children:e.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-10 text-center",children:[e.jsx("h2",{className:"text-[17px] font-semibold",children:me.readError.unknown_rig}),e.jsx("a",{href:ae({name:"rigs"}),className:je({size:"sm",className:"mt-1.5"}),children:me.back})]})})]});if(!b){const oe=a.error?me.readError[a.error]:null;return e.jsxs(e.Fragment,{children:[U(null),e.jsxs("main",{"data-tab-scroll":"",className:H,children:[e.jsx(gs,{body:me.offlineBody}),oe?e.jsx(Kt,{warn:!0,role:"alert",lead:e.jsx(F,{name:"warning",className:"mt-px size-4 text-attention"}),children:e.jsx("b",{className:"font-semibold",children:oe})}):e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:me.loading})]})]})}const ee=ms(b),G=ee==="stopped",O=N!=null&&N.data?Sd(N.data.seats):null,D=O?me.level[O]:null,J=Ad(($==null?void 0:$.data)??[])[0],Q=J?Ka(J.createdAt).short:b.snapshot||"",Y=(C==null?void 0:C.phase)==="done"&&((Z=C.reseated)!=null&&Z.ok)?C.reseated.added:[],ie=b.nodes.filter(oe=>oe.stopped).map(oe=>bs(oe.logicalId,oe.session)),X=oe=>{var Ae;return(Ae=j==null?void 0:j.data)==null?void 0:Ae.seats.find(st=>st.logicalId===oe)},le=()=>{var oe;return P(u==="fresh"?{kind:"rig.start",rig:t,fresh:((oe=j==null?void 0:j.data)==null?void 0:oe.seats.map(Ae=>Ae.logicalId))??b.nodes.map(Ae=>Ae.logicalId)}:{kind:"rig.start",rig:t})},B=C&&!I?C:void 0,v=p&&!I,_=o?"sm":"md",W=o?"":"!h-[42px] !px-2 !text-[13.5px]",se=e.jsx("button",{type:"button",disabled:!v,onClick:le,className:je({tone:"primary",size:_,className:o?"":"!h-[42px]"}),children:e.jsx(Lt,{icon:"power",children:me.actions.start})}),re=e.jsx("button",{type:"button",disabled:!v,onClick:()=>x({kind:"restart"}),className:je({size:_,className:W}),children:e.jsx(Lt,{icon:"refresh",children:me.actions.restart})}),K=e.jsx("button",{type:"button",disabled:!v,onClick:()=>x({kind:"stop"}),className:je({tone:"danger",size:_,className:W}),children:e.jsx(Lt,{icon:"power",children:me.actions.stop})}),ce=e.jsx("button",{type:"button",disabled:!v,onClick:()=>x({kind:"reseat"}),className:je({size:_,className:W}),children:e.jsx(Lt,{icon:"plus",children:me.actions.seats})}),ge=I?e.jsx(Ua,{run:C,rigs:s,pc:w,bar:!o}):ee==="starting"?e.jsx(Vn,{bar:!o,children:me.startingSeats(t,b.running,b.seats)}):null,Ye=ge??e.jsx("div",{className:`bleed grid flex-none gap-2 border-t border-line bg-bg px-3.5 pt-2.5 pb-3 ${G?"grid-cols-1":"grid-cols-3"}`,children:G?se:e.jsxs(e.Fragment,{children:[ce,re,K]})}),pt=p&&e.jsx(Gy,{rig:t,sessions:E,asks:l.asks}),Re=ee==="partial"&&ie.length>0&&e.jsxs(Kt,{warn:!0,lead:e.jsx(F,{name:"warning",className:"mt-px size-4 text-attention"}),children:[e.jsx("span",{children:me.partial(ie,b.nodes.length-ie.length)}),e.jsx("button",{type:"button",disabled:!v,onClick:()=>x({kind:"restart"}),className:je({size:"sm",className:"self-start"}),children:me.actions.restartRig})]}),Le=e.jsxs(e.Fragment,{children:[e.jsx(zt,{aside:G?me.topologyStopped:j!=null&&j.data?me.topologyHint:void 0,children:me.topology}),j!=null&&j.data?e.jsx(Wy,{graph:j.data,rig:b,status:ee,sessions:E,near:k,added:Y,onSeat:oe=>x({kind:"seat",id:oe}),wide:o}):e.jsx(Ke,{children:j!=null&&j.error?e.jsx(Rs,{retry:M,retryLabel:me.unavailable.retry,children:me.readError[j.error]}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:me.loading})})]}),pe=G&&b.snapshot&&e.jsxs(e.Fragment,{children:[e.jsx(zt,{children:me.resume}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(rr,{pressed:u==="last",disabled:!p,onClick:()=>m("last"),title:me.resumeLast(J?Ka(J.createdAt).long:b.snapshot),sub:me.resumeLastBody}),e.jsx(rr,{pressed:u==="fresh",disabled:!p,onClick:()=>m("fresh"),title:me.fresh,sub:me.freshBody})]})]}),he=e.jsx(Vy,{read:A,asks:l.asks,now:f,retry:M}),Me=o?e.jsxs("div",{className:"grid grid-cols-[minmax(0,1.15fr)_minmax(0,1fr)] content-start gap-[18px]",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-3.5",children:[pt,Re,Le,!G&&ee!=="starting"&&e.jsxs(e.Fragment,{children:[e.jsx(zt,{children:me.seatsByRole}),e.jsx(Ke,{children:e.jsx("div",{className:"flex flex-col gap-2.5 px-3 py-1",children:e.jsx(ex,{rig:b,confirm:T,live:v,onReseat:L,context:Object.fromEntries((((q=j==null?void 0:j.data)==null?void 0:q.seats)??[]).map(oe=>[oe.logicalId,oe.context]))},b.nodes.length)})})]}),pe]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3.5",children:[he,e.jsx(zt,{children:me.actions.snapshots}),e.jsx(tx,{read:$,kindOnly:!0,retry:()=>s.readSnapshots(t)}),e.jsx("button",{type:"button",disabled:!v,onClick:()=>P({kind:"rig.snapshot",rig:t}),className:je({size:"sm",className:"max-w-full self-start !h-auto min-h-9 py-1.5 !whitespace-normal text-left [&>svg]:flex-none"}),children:e.jsx(Lt,{icon:"camera",children:me.snapshots.take})})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx($l,{label:me.tiles.seats,value:`${b.running}/${b.seats}`}),e.jsx($l,{label:me.tiles.permissions,value:D??"—",onOpen:()=>x({kind:"permissions"})}),e.jsx($l,{label:me.tiles.snapshot,value:Q||"—",onOpen:()=>x({kind:"snapshots"})})]}),pt,Re,Le,he,pe]}),ze=(c==null?void 0:c.kind)==="seat"||(c==null?void 0:c.kind)==="settings"?X(c.id):void 0,at=ze?b.nodes.find(oe=>oe.logicalId===ze.logicalId):void 0,et=[me.seats(b.running,b.seats),D??"",Q?me.snapshot(Q):""].filter(Boolean).join(" · ");return e.jsxs(e.Fragment,{children:[U(e.jsx(Nn,{tone:Ed[ee],children:me.status[ee]}),et,!ge&&(G?se:e.jsxs(e.Fragment,{children:[re,K]}))),e.jsxs("main",{"data-tab-scroll":"",className:H,children:[e.jsx(gs,{body:me.offlineBody}),o&&ge,B&&e.jsx(Ua,{run:B,rigs:s,pc:w}),e.jsx("div",{className:`flex flex-col gap-3 ${g?"opacity-50":""}`,children:Me})]}),!o&&Ye,(c==null?void 0:c.kind)==="more"&&e.jsx(Ry,{rig:t,live:p,running:I,snapshots:$!=null&&$.data?$.data.length:null,level:D,onClose:R,onSnapshot:()=>{R(),P({kind:"rig.snapshot",rig:t})},onSnapshots:()=>x({kind:"snapshots"}),onPermissions:()=>x({kind:"permissions"}),onRefresh:()=>{R(),s.retry(),s.openRig(t),s.readSnapshots(t)}}),((c==null?void 0:c.kind)==="stop"||(c==null?void 0:c.kind)==="restart")&&e.jsx(Ly,{rig:b,pc:w,verb:c.kind,confirm:T,live:v,onAct:P,onClose:R}),(c==null?void 0:c.kind)==="reseat"&&e.jsx(zy,{rig:b,pc:w,confirm:T,live:v,onReseat:L,onClose:R}),(c==null?void 0:c.kind)==="permissions"&&e.jsx(Dy,{rig:b,read:N,level:O,confirm:T,live:v,onAct:P,onClose:R}),(c==null?void 0:c.kind)==="snapshots"&&e.jsx(qy,{rig:t,read:$,live:p,running:I,onSnapshot:()=>P({kind:"rig.snapshot",rig:t}),onRetry:()=>s.readSnapshots(t),onClose:R}),(c==null?void 0:c.kind)==="seat"&&ze&&(j==null?void 0:j.data)&&e.jsx(Py,{rig:t,seat:ze,graph:j.data,node:at,session:yd(E,t,ze.logicalId),status:ee,near:k,onSettings:()=>x({kind:"settings",id:ze.logicalId}),onClose:R}),(c==null?void 0:c.kind)==="settings"&&ze&&e.jsx(By,{rig:t,seat:ze,node:at,selection:(_e=(ye=N==null?void 0:N.data)==null?void 0:ye.seats.find(oe=>oe.logicalId===ze.logicalId))==null?void 0:_e.selection,confirm:T,live:v,onAct:P,onClose:R})]})}const cs=d.rigs,ke=cs.max,Qy={sent:"idle",taken:"work",asking:"ask",proposed:"rig",running:"work",done:"done",closed:"done"},Yy={sent:"plain",taken:"work",asking:"ask",proposed:"rig",running:"work",done:"ok",closed:"plain"},Zy=t=>{var s;return((s=t.trail.at(-1))==null?void 0:s.at)??t.sentAt},nx=t=>{const s=Va(t);if(!s)return null;for(let n=t.trail.length-1;n>=0;n--)if(t.trail[n].text===s)return t.trail[n].at;return null};function Jy(t){var n;const s=Ka(Zy(t)).short;return t.state==="asking"?`${ke.asks} · ${s}`:t.state==="running"?[ke.state.running,((n=t.current)==null?void 0:n.seat.split("@")[0])??"",ke.since(s)].filter(Boolean).join(" · "):`${ke.state[t.state]} · ${s}`}const Va=t=>{var s,n;return((s=t.question)==null?void 0:s.text)??((n=t.proposal)==null?void 0:n.text)??null};function eN({run:t,pc:s,onAgain:n,onClose:a}){var o,c;const l={onClose:a,closeLabel:cs.done.close},r=e.jsx("button",{type:"button",onClick:n,className:je({size:"xs",className:"mt-1.5"}),children:ke.sendAgain}),i=t.phase==="uncertain"?"uncertain":t.phase==="done"?(o=t.sent)==null?void 0:o.error:void 0;return i?i==="uncertain"?e.jsx(ve,{mark:"ask",title:ke.errors.uncertain.title,sub:ke.errors.uncertain.body,...l,children:r}):i==="refused"?e.jsx(ve,{mark:"bad",title:ke.errors.refused.title,...(c=t.sent)!=null&&c.message?{sub:e.jsx("span",{className:"font-mono",children:t.sent.message})}:{},...l}):i==="openrig_stopped"?e.jsx(ve,{mark:"bad",title:ke.errors.openrig_stopped.title(s),sub:ke.errors.openrig_stopped.body,...l,children:r}):i==="no_operator"||i==="unreachable"?e.jsx(ve,{mark:"bad",title:ke.errors[i].title,sub:ke.errors[i].body,...l,children:r}):e.jsx(ve,{mark:"bad",title:ke.unsent,sub:ke.keeps,...l,children:r}):e.jsx(ve,{mark:"bad",title:ke.unsent,sub:ke.keeps,...l,children:r})}const tN=t=>{var s;return t.phase==="done"&&!!((s=t.sent)!=null&&s.ok)};function ax({runs:t,rigs:s,pc:n,bubble:a}){return e.jsx(e.Fragment,{children:t.filter(l=>!tN(l)).map(l=>{const r=l.subject;if(r.kind!=="goal"&&r.kind!=="reply")return null;if(dl(l))return e.jsxs("div",{role:"status","aria-label":ke.sending,className:"max-w-[85%] self-end rounded-[14px] rounded-br-[5px] bg-secondary px-3 py-2 text-[14px] leading-5 opacity-60",children:[r.text," ",e.jsx(Cn,{className:"ml-1 align-[-1px] text-muted"})]},l.id);const i=()=>{s.dismiss(l.id),r.kind==="goal"?s.sendGoal(r.text,r.goalId):s.replyGoal(r.goalId,r.text,r.replyId)};return e.jsx(eN,{run:l,pc:n,onAgain:i,onClose:()=>s.dismiss(l.id)},l.id)})})}function sN(t){var s;switch(t.kind){case"sent":return ke.trail.sent;case"taken":return ke.trail.taken;case"note":return ke.trail.note(t.text??"");case"handed":return ke.trail.handed(((s=t.to)==null?void 0:s.split("@")[0])??"");case"closed":return ke.trail.closed}}function lx({goal:t,runs:s,rigs:n,pc:a,compact:l=!1}){const r=Va(t),i=nx(t),o=t.question??(t.proposal&&!t.proposal.answer?t.proposal:null),c=s.filter(x=>x.subject.kind==="reply"&&x.subject.goalId===t.goalId);return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("div",{className:"max-w-[85%] self-end rounded-[14px] rounded-br-[5px] bg-secondary px-3 py-2 text-[14px] leading-5 [overflow-wrap:anywhere]",children:t.text}),!l&&t.trail.some(x=>x.kind!=="sent")&&e.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0 text-[12.5px] text-muted",children:t.trail.filter(x=>x.kind!=="sent").map((x,u)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"font-mono text-[11.5px]",children:Fe(Cs(x.at))}),e.jsx("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:sN(x)})]},`${x.at}-${u}`))}),r&&e.jsxs("div",{className:"flex flex-col gap-1 text-[13.5px] leading-[19px]",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[12px] text-muted",children:[e.jsx(Ie,{state:"idle"}),i?`${cs.kernelView.max} · ${Fe(Cs(i))}`:cs.kernelView.max]}),e.jsx("span",{className:"[overflow-wrap:anywhere]",children:r})]}),o&&e.jsxs("div",{className:"flex flex-col gap-2 rounded-[10px] border border-attention/45 bg-surface px-3 py-2.5",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ie,{state:"ask"}),e.jsx("b",{className:"text-[14px] font-semibold",children:t.question?ke.question:ke.proposal}),i&&e.jsx("span",{className:"ml-auto font-mono text-[11.5px] text-muted",children:Fe(Cs(i))})]}),!l&&e.jsx("p",{className:"text-[13px] text-muted",children:t.question?ke.questionBody:ke.proposalBody}),e.jsx("a",{href:ae({name:"atoi"}),className:je({size:"sm",className:"self-start"}),children:ke.seeAtoi})]}),e.jsx(ax,{runs:c,rigs:n,pc:a,bubble:!0})]})}function rx({goalId:t,rigs:s,live:n}){const[a,l]=h.useState("");return e.jsx(_c,{label:ke.replyPlaceholder,sendLabel:ke.send,placeholder:ke.replyPlaceholder,offlinePlaceholder:ke.offlinePlaceholder,offline:!n,value:a,onChange:l,onSend:()=>{const r=a.trim();r&&(l(""),s.replyGoal(t,r).then(i=>{i.phase==="unsent"&&l(o=>o||r)}))}})}function nN({goalId:t,rigs:s,store:n}){var A,E,k,T;const a=Mn(s),l=fe(n),{pc:r,look:i}=qt(),o=It(),c=l.fresh,x=i==="offline",u=Bt(r),[m,p]=h.useState("");h.useEffect(()=>{s.follow(),s.followGoals()},[s,c]);const g=((E=(A=a.goals)==null?void 0:A.data)==null?void 0:E.goals)??[],f=t?g.find(C=>C.goalId===t):void 0,y=`tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pb-[18px] ${o?"pt-[18px]":"pt-3"}`,w=o?"pane-head flex h-[58px] flex-none items-center gap-2 border-b border-line pr-2":"flex h-14 flex-none items-center gap-2 border-b border-line pr-2 pl-0.5",S="bleed flex-none border-t border-line bg-bg px-3.5 pt-2.5 pb-3",b=(()=>{var C,I;return(C=a.goals)!=null&&C.error&&!a.goals.data?e.jsx(Ke,{children:e.jsx(Rs,{retry:()=>s.followGoals(),retryLabel:cs.unavailable.retry,children:ke.goalsUnavailable})}):(I=a.goals)!=null&&I.data?null:e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:cs.loading})})();if(t)return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:w,children:[e.jsx(ls,{fallback:{name:"max"},label:cs.backMax}),e.jsx("h1",{className:"min-w-0 truncate text-base font-semibold",children:(f==null?void 0:f.text)??ke.title}),f&&e.jsx("span",{className:"flex-none",children:e.jsx(as,{tone:Yy[f.state],children:ke.statePill[f.state]})})]}),e.jsxs("main",{"data-tab-scroll":"",className:`${y} justify-end`,children:[e.jsx(gs,{body:cs.offlineBody}),f?e.jsx("div",{className:x?"opacity-50":"",children:e.jsx(lx,{goal:f,runs:a.runs,rigs:s,pc:u})}):b??e.jsx("p",{role:"alert",className:"text-[13px] text-attention",children:ke.goalsUnavailable})]}),f&&e.jsx("div",{className:S,children:e.jsx(rx,{goalId:f.goalId,rigs:s,live:c})})]});const j=a.runs.filter(C=>C.subject.kind==="goal"),N=()=>{const C=m.trim();C&&(p(""),s.sendGoal(C).then(I=>{I.phase==="unsent"&&p(P=>P||C)}))},$=()=>{var C;(C=document.querySelector("[data-goal-field] textarea"))==null||C.focus()};return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:w,children:[e.jsx(ls,{fallback:{name:"kernel"},label:cs.backKernel}),e.jsx("h1",{className:"flex-none text-base font-semibold",children:ke.title}),e.jsx("span",{className:"min-w-0 truncate text-[12.5px] text-muted",children:ke.role}),e.jsx("span",{className:"flex-1"}),e.jsx("button",{type:"button",disabled:!c,onClick:$,className:je({tone:"primary",size:"sm"}),children:e.jsx(Lt,{icon:"plus",children:ke.newGoal})})]}),e.jsxs("main",{"data-tab-scroll":"",className:y,children:[e.jsx(gs,{body:cs.offlineBody}),e.jsxs("div",{className:`flex flex-col gap-3 ${x?"opacity-50":""}`,children:[b??(g.length===0?e.jsx(Ke,{children:e.jsx(Rs,{children:ke.none})}):e.jsx(Ke,{label:ke.goalsLabel,children:g.map(C=>e.jsxs("a",{href:ae({name:"max",goalId:C.goalId}),className:"flex items-start gap-2.5 border-b border-line px-3 py-2.5 last:border-b-0",children:[e.jsx("span",{className:"mt-1.5",children:e.jsx(Ie,{state:Qy[C.state],pulse:C.state==="running"})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsx("span",{className:"line-clamp-2 text-[14px] leading-5 [overflow-wrap:anywhere]",children:C.text}),e.jsx("small",{className:`text-[12px] ${C.state==="asking"?"text-attention":"text-muted"}`,children:Jy(C)})]})]},C.goalId))})),((T=(k=a.goals)==null?void 0:k.data)==null?void 0:T.partial)&&e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:ke.partial}),e.jsx(ax,{runs:j,rigs:s,pc:u,bubble:!1}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:ke.atoiNote})]})]}),e.jsx("div",{"data-goal-field":"",className:S,children:e.jsx(_c,{label:ke.goalPlaceholder,sendLabel:ke.send,placeholder:ke.goalPlaceholder,offlinePlaceholder:ke.offlinePlaceholder,offline:!c,value:m,onChange:p,onSend:N})})]})}const Te=d.rigs,ft=Te.kernelView,aN=t=>/^qitem-\d{14}-[0-9a-f]{8,}$/.test(t)?`…${t.slice(-8)}`:t;function lN({graph:t,status:s,near:n}){var c;const a=t.seats,l=a.find(x=>Cd(x.logicalId)),r=a.filter(x=>x!==l),i=(l==null?void 0:l.runtime)??((c=a[0])==null?void 0:c.runtime),o=(x,u=!1)=>{var f;const m=Gr({graph:x,rigStatus:s}),p=((f=t.pods.find(y=>y.id===x.pod))==null?void 0:f.label)??x.pod,g=[u?p:"",m==="idle"?"":Te.seatState[m]].filter(Boolean).join(" · ");return e.jsx(sx,{seat:x,state:m,pod:p,top:u,near:n,isNew:!1,name:Md({logicalId:x.logicalId,session:x.session??""}),words:g,tag:u||x.runtime!==i,pulse:m==="starting"},x.logicalId)};return e.jsxs("div",{className:"flex flex-col items-center",children:[l&&e.jsxs(e.Fragment,{children:[o(l,!0),e.jsx("span",{"aria-hidden":"true",className:"h-3 w-[1.5px] bg-input"})]}),e.jsx("div",{className:"grid w-full max-w-[420px] grid-cols-2 gap-2",children:r.map(x=>o(x))})]})}function rN({rigs:t}){const s=Mn(t).routing,n=s!=null&&s.data?[...s.data].reverse():null,a=l=>{const r=Vf(l);return r.verb==="handed"?ft.change.handed(r.to):r.verb==="blocked"?ft.change.blocked(aN(r.on)):r.verb==="other"?r.text:ft.change[r.verb]};return e.jsxs(e.Fragment,{children:[e.jsx(zt,{aside:ft.allRigs,children:ft.routing}),e.jsx(Ke,{children:n?n.length===0?e.jsx(Rs,{children:ft.noRouting}):n.map((l,r)=>e.jsxs("div",{className:"grid grid-cols-[44px_1fr] gap-x-2 border-b border-line px-3 py-2 text-[13px] leading-[18px] last:border-b-0",children:[e.jsx("span",{className:"font-mono text-[11.5px] text-muted",children:Fe(Cs(l.at))}),e.jsxs("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:[e.jsx("b",{className:"font-semibold",children:ft.actor(l.seat.split("@")[0]??l.seat)})," ",a(l.change)]}),e.jsx("small",{className:"col-start-2 truncate text-[11.5px] text-muted",children:[l.rig,l.summary??""].filter(Boolean).join(" · ")})]},`${l.qitem}-${l.at}-${r}`)):s!=null&&s.error?e.jsx(Rs,{retry:()=>t.readRouting(),retryLabel:Te.unavailable.retry,children:Te.readError[s.error]}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:Te.loading})})]})}function iN({rigs:t,store:s}){var _,W,se,re;const n=Mn(t),a=fe(s),{pc:l,look:r}=qt(),i=It(),[o]=ui(),[c,x]=h.useState(null),u=a.fresh,m=r==="offline";h.useEffect(()=>{t.follow(),t.followGoals(),u&&(t.openRig(zn),t.readRouting())},[t,u]);const p=n.state?ar(n.state).filter(K=>ms(K)!=="stopped").map(K=>K.name).join(" "):"";h.useEffect(()=>{if(u&&p)for(const K of p.split(" "))t.readPermissions(K)},[t,u,p]);const g=Bt(l),f=n.state,y=`tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pb-[18px] ${i?"pt-[18px]":"pt-3"}`,w=K=>e.jsxs("header",{className:i?"pane-head flex h-[58px] flex-none items-center gap-2 border-b border-line pr-1.5":"flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-0.5",children:[e.jsx(ls,{fallback:{name:"rigs"},label:Te.back}),e.jsx("h1",{className:`min-w-0 truncate font-semibold ${i?"text-[17px]":"text-base"}`,children:Te.kernel}),K,e.jsx("span",{className:"flex-1"}),K&&e.jsx("button",{type:"button","aria-label":Te.more,title:Te.more,"aria-haspopup":"menu",onClick:()=>x("menu"),className:$t(),children:e.jsx(F,{name:"more"})})]}),S=()=>{t.retry(),t.openRig(zn),t.readRouting()};if(!f){const K=n.error?Te.readError[n.error]:null;return e.jsxs(e.Fragment,{children:[w(null),e.jsxs("main",{"data-tab-scroll":"",className:y,children:[e.jsx(gs,{body:Te.offlineBody}),K?e.jsx(Kt,{warn:!0,role:"alert",lead:e.jsx(F,{name:"warning",className:"mt-px size-4 text-attention"}),children:e.jsx("b",{className:"font-semibold",children:K})}):e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:Te.loading})]})]})}const b=jd(f),j=f.kernel.state,N=b?ms(b):"stopped",$=n.graphs[zn],A=((_=a.device)==null?void 0:_.contextNear)??70,E=!!((W=a.device)!=null&&W.confirm),k=mi(n.runs,K=>K.subject.kind==="act"&&/^(kernel|daemon)\./.test(K.subject.action.kind)),T=dl(k),C=u&&!T,I=K=>{t.act(K)},P=[...a.sessions.values()],L=ar(f),R=f.daemon.state==="running",M=j==="ready"||j==="starting",z=((re=(se=n.goals)==null?void 0:se.data)==null?void 0:re.goals)??[],U=j==="stopped"?e.jsxs(Kt,{lead:e.jsx("span",{className:"mt-[5px]",children:e.jsx(Ie,{state:"off"})}),children:[e.jsx("span",{children:e.jsx("b",{className:"font-semibold",children:ft.stoppedTitle})}),e.jsx("span",{className:"text-muted",children:ft.stoppedBody}),e.jsx("button",{type:"button",disabled:!C||!R,onClick:()=>I({kind:"kernel.start"}),className:je({tone:"primary",size:"sm",className:"self-start"}),children:e.jsx(Lt,{icon:"power",children:ft.startKernel})})]}):j==="skipped"?e.jsxs(Kt,{lead:e.jsx("span",{className:"mt-[5px]",children:e.jsx(Ie,{state:"off"})}),children:[e.jsx("span",{children:e.jsx("b",{className:"font-semibold",children:ft.skippedTitle})}),e.jsx("span",{className:"text-muted",children:ft.skippedBody})]}):null,H=z.find(K=>Va(K)!==null),V=H?nx(H):null,ee=z.find(K=>K.state!=="done"&&K.state!=="closed"),G=e.jsx("a",{href:ae({name:"max"}),className:je({tone:"primary",className:"w-full"}),children:ft.talk}),O=i&&ee?e.jsxs(e.Fragment,{children:[e.jsx(zt,{children:`${ft.max} · ${ee.text}`}),e.jsx(Ke,{children:e.jsxs("div",{className:"flex flex-col gap-2.5 p-3",children:[e.jsx(lx,{goal:ee,runs:n.runs,rigs:t,pc:g,compact:!0}),e.jsx(rx,{goalId:ee.goalId,rigs:t,live:u})]})})]}):e.jsx(Ke,{children:e.jsxs("div",{className:"flex flex-col gap-2 p-3",children:[H&&e.jsx("span",{className:"text-[12px] text-muted",children:ft.lastMessage(V?Fe(Cs(V)):null)}),H&&e.jsx("span",{className:"text-[13.5px] leading-[19px] [overflow-wrap:anywhere]",children:Va(H)}),G]})}),D=K=>{var Ye;const ce=(Ye=n.permissions[K])==null?void 0:Ye.data,ge=ce?Sd(ce.seats):null;return ge?Te.level[ge]:""},J=L.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(zt,{children:ft.driven}),e.jsx(Ke,{children:L.map(K=>{const ce=ms(K),ge=kd(K,Nd(K.name,P,a.asks));return e.jsxs("a",{href:ae({name:"rig",rig:K.name}),className:"flex min-h-[46px] items-center gap-2.5 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0",children:[e.jsx(Ie,{state:ge}),e.jsx("span",{className:`min-w-0 flex-1 truncate ${ce==="stopped"?"text-muted":""}`,children:K.name}),e.jsx("span",{className:"text-[12px] text-muted",children:ce==="stopped"?Te.seatState.off:[Te.seatCount(K.seats),D(K.name)].filter(Boolean).join(" · ")}),e.jsx(F,{name:"chevron",className:"size-4 text-muted"})]},K.id)})})]}),Q=(K,ce)=>e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",disabled:!C,onClick:K,className:je({}),children:e.jsx(Lt,{icon:"refresh",children:Te.actions.restart})}),e.jsx("button",{type:"button",disabled:!C,onClick:ce,className:je({tone:"danger"}),children:e.jsx(Lt,{icon:"power",children:Te.actions.stop})})]}),Y=M&&e.jsxs(e.Fragment,{children:[e.jsx(zt,{children:Te.kernel}),e.jsx(Ke,{children:e.jsxs("div",{className:"flex flex-col gap-2 p-3",children:[e.jsx("span",{className:"text-[12.5px] leading-[18px] text-muted",children:Te.confirm.kernelNote}),Q(()=>x("kernel.restart"),()=>x("kernel.stop"))]})})]}),ie=e.jsxs(e.Fragment,{children:[e.jsx(zt,{children:Te.daemon}),e.jsxs(Ke,{children:[e.jsx(pi,{state:f}),e.jsx(Ju,{disabled:!u,next:!0}),R&&e.jsx("div",{className:"px-3 pt-2.5 pb-3",children:Q(()=>x("daemon.restart"),()=>x("daemon.stop"))})]}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:ft.daemonNote})]}),X=L.flatMap(K=>Zf(K)).length,le=L.filter(K=>ms(K)!=="stopped").length,B=[Te.confirm.daemonStops(le),X?Te.confirm.working(X):""].filter(Boolean).join(" "),v=()=>x(null);return e.jsxs(e.Fragment,{children:[w(e.jsx(Nn,{tone:Zu[j],children:Te.kernelState[j]})),e.jsxs("main",{"data-tab-scroll":"",className:y,children:[e.jsx(gs,{body:Te.offlineBody}),k&&e.jsx(Ua,{run:k,rigs:t,pc:g}),e.jsxs("div",{className:`flex flex-col gap-3 ${i?"max-w-[720px]":""} ${m?"opacity-50":""}`,children:[U,e.jsx("p",{className:"text-[12.5px] leading-[18px] text-muted",children:ft.role}),M&&($!=null&&$.data?e.jsx(lN,{graph:$.data,status:N,near:A}):e.jsx(Ke,{children:e.jsx("p",{role:$!=null&&$.error?"alert":"status",className:"p-3 text-[13px] text-muted",children:$!=null&&$.error?Te.readError[$.error]:Te.loading})})),M&&O,J,e.jsx(rN,{rigs:t}),Y,ie]})]}),c==="menu"&&e.jsx(Oy,{live:u,up:M&&!T,onClose:v,onRefresh:()=>{v(),S()},onRestart:()=>x("kernel.restart"),onStop:()=>x("kernel.stop")}),c==="kernel.restart"&&e.jsx(Na,{title:Te.confirm.restartKernel(g),conseq:{title:Te.confirm.kernelNote},verb:Te.actions.restart,confirm:E,live:C,onConfirm:()=>I({kind:"kernel.restart"}),onClose:v}),c==="kernel.stop"&&e.jsx(Na,{title:Te.confirm.stopKernel(g),conseq:{title:Te.confirm.kernelNote},verb:Te.actions.stop,confirm:E,live:C,onConfirm:()=>I({kind:"kernel.stop"}),onClose:v}),c==="daemon.restart"&&e.jsx(Na,{title:Te.confirm.restartDaemon(g),conseq:{title:B},verb:Te.actions.restart,confirm:E,live:C,onConfirm:()=>I(Yu("restart",o)),onClose:v}),c==="daemon.stop"&&e.jsx(Na,{title:Te.confirm.stopDaemon(g),conseq:{title:B},verb:Te.actions.stop,confirm:E,live:C,onConfirm:()=>I({kind:"daemon.stop"}),onClose:v})]})}const xe=d.launch,oN=["claude","codex","cursor","omp"],cN=["always-ask","write","yolo"],dN=2e4,Ws={project:`${$s}launch.project`,prefs:`${$s}launch.prefs`,draft:`${$s}launch.draft`},Sr=(t,s)=>{try{return(t==null?void 0:t.getItem(s))??null}catch{return null}},ka=(t,s,n)=>{try{n===null?t==null||t.removeItem(s):t==null||t.setItem(s,n)}catch{}};function Vo(t){try{const s=JSON.parse(Sr(t,Ws.prefs)??"{}");return s&&typeof s=="object"?s:{}}catch{return{}}}const Go=t=>t.replace(/\/+$/,"").split("/").pop()||t,ix=t=>t.machine==="local",Xo=t=>ix(t)&&t.exists!==!1;function Qo({store:t,storage:s}){var he,Me,ze,at,et,bt,jt;const n=fe(t),a=Xe(s),l=Bt(qt().pc??((he=n.daemon)==null?void 0:he.name)??null),r=n.projects,[i,o]=h.useState(()=>Sr(a,Ws.project)),c=r.find(Z=>Z.id===i)??r[0],x=Vo(a),u=c?x[c.id]:void 0,[m,p]=h.useState((u==null?void 0:u.tool)??"claude"),[g,f]=h.useState({model:(u==null?void 0:u.model)??null,effort:(u==null?void 0:u.effort)??null}),[y,w]=h.useState("always-ask"),[S,b]=h.useState(null),[j,N]=h.useState(()=>Sr(a,Ws.draft)??""),[$,A]=h.useState(null),[E,k]=h.useState(!1),[T,C]=h.useState(!1),[I,P]=h.useState(null),[L,R]=h.useState(null),M=h.useId(),z=c==null?void 0:c.id;h.useEffect(()=>{z&&n.fresh&&t.requestProjectFolders(z)},[z,n.fresh,t]),h.useEffect(()=>{var Z;n.fresh&&((Z=n.daemon)!=null&&Z.models)&&t.requestModels(m)},[m,n.fresh,(Me=n.daemon)==null?void 0:Me.models,t]);const U=z?n.projectFolders[z]:void 0,H=Array.isArray(U)?U:[],V=H.find(Xo),ee=(S??(V?[V.path]:[])).filter(Z=>H.some(q=>q.path===Z&&Xo(q))),G=Si.includes(m),O=((ze=n.models[m])==null?void 0:ze.models)??[],D=Z=>{Z(),P(null),C(!1)},J=Z=>D(()=>{o(Z.id),ka(a,Ws.project,Z.id),b(null);const q=x[Z.id];p((q==null?void 0:q.tool)??"claude"),f({model:(q==null?void 0:q.model)??null,effort:(q==null?void 0:q.effort)??null}),A(null)}),Q=Z=>D(()=>{p(Z),f({model:null,effort:null}),!Si.includes(Z)&&ee.length>1&&b(ee.slice(0,1))}),Y=Z=>D(()=>{if(!G){b([Z]),A(null);return}const ye=ee.includes(Z)?ee.filter(_e=>_e!==Z):[...ee,Z];b(ye.length?ye:ee)}),ie=Z=>{N(Z),ka(a,Ws.draft,Z),P(null),C(!1)},X=L?n.ops[L]:void 0,[le,B]=h.useState(0);h.useEffect(()=>{if(!L)return;const Z=setTimeout(()=>{const q=t.getState().ops[L];q&&us(q.phase)&&(k(!1),P({kind:"timeout",op:L}))},dN);return()=>clearTimeout(Z)},[L,le,t]),h.useEffect(()=>{if(!L||!X||us(X.phase))return;if(k(!1),R(null),X.phase==="applied"){ka(a,Ws.draft,null),c&&ka(a,Ws.prefs,JSON.stringify({...Vo(a),[c.id]:{tool:m,model:g.model,effort:g.effort}})),X.id?($b(X.id,(c==null?void 0:c.name)??"",s),xs({name:"thread",sessionId:X.id})):xs({name:"sessions"});return}if(X.phase==="failed"){P({kind:"failed"});return}const Z=X.reason??"other";Z==="stale"&&z&&t.requestProjectFolders(z),P({kind:"refused",reason:Z})},[L,X==null?void 0:X.phase]);const v=async()=>{if(!c)return;const Z={project:c.id,tool:m,folders:ee,prompt:j.trim(),...g.model?{model:g.model}:{},...g.effort?{effort:g.effort}:{},...m==="omp"&&y!=="always-ask"?{approval:y}:{}};k(!0),P(null),C(!1);const q=await t.launchSession(Z);if(q.status==="sent"){R(q.op),B(ye=>ye+1);return}k(!1),q.status==="cancelled"?C(!0):q.status==="noAnswer"?P({kind:"timeout",op:null}):q.status==="failed"?P({kind:"refused",reason:"other"}):P({kind:"refused",reason:q.reason})},_=Z=>{if(Z.kind==="timeout"&&Z.op){if(t.launchAgain(Z.op)){R(Z.op),B(ye=>ye+1),k(!0),P(null);return}const q=t.getState().ops[Z.op];if(q&&us(q.phase)){P({...Z});return}}v()},W=Z=>Z.kind==="timeout"&&Z.op!==null&&!!n.ops[Z.op]&&us(n.ops[Z.op].phase)&&!t.canLaunchAgain(Z.op),se=d.tools[m],re=!n.fresh,K=re?{label:xe.missing.machine}:(at=n.daemon)!=null&&at.launch?(et=n.device)!=null&&et.confirm?!c||ee.length===0?{label:xe.chooseProject}:j.trim()===""?{label:xe.missing.prompt}:null:{label:xe.missing.setup,body:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:xe.setupBody}),e.jsxs("a",{href:"#/connection/link",className:Oe({size:"sm",className:"self-start"}),children:[e.jsx(F,{name:"gear",className:"size-4"}),xe.openSettings]})]})}:{label:xe.missing.pcOld(l),body:e.jsx("span",{className:"text-center text-[12px] leading-4 text-muted",children:xe.pcOldBody})},ce=I&&!(re&&I.kind==="timeout")?I:null,ge=g.model===null?null:((bt=O.find(Z=>Z.id===g.model))==null?void 0:bt.label)??g.model,Ye=g.model===null?d.model.byDefault:xe.pick(ge,g.effort?na(g.effort):null),pt=g.model===null?d.model.defaultHint:(()=>{const Z=O.find(q=>q.id===g.model);return Z?rd(m,Z):void 0})(),Re=H.find(Z=>Z.path===ee[0]),Le=Re?Re===H[0]?Re.branch?xe.onBranch(Re.branch):xe.inFolder:Go(Re.path):void 0,pe=Re&&Re!==H[0]?Re.branch??void 0:void 0;return e.jsxs(e.Fragment,{children:[e.jsx(ea,{back:e.jsx("button",{type:"button","aria-label":xe.close,title:xe.close,onClick:()=>Tr({name:"sessions"}),className:$t({className:"text-muted"}),children:e.jsx(F,{name:"close"})}),name:xe.title}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col gap-3.5 overflow-y-auto overscroll-contain pt-3.5 pb-4",children:[e.jsx(xn,{label:xe.project,children:r.length===0?e.jsxs("p",{className:"text-body text-muted",children:[d.launch.noProjects," ",xe.noProjectsBody]}):e.jsx(Fl,{onClick:()=>A("project"),lead:c?e.jsx(Ie,{state:re?"off":"idle"}):null,label:xe.project,text:c?e.jsx("b",{className:"font-semibold",children:c.name}):xe.chooseProject,sub:c?[l,re?xe.offline:u?xe.remembered:null].filter(Boolean).join(" · "):void 0,dim:re})}),c&&e.jsx(xn,{label:xe.where,children:e.jsx(Fl,{onClick:()=>A("where"),lead:e.jsx(F,{name:Re!=null&&Re.branch?"branch":"folder",className:"size-4 text-muted"}),label:xe.where,text:ee.length>1&&Le?e.jsxs(e.Fragment,{children:[e.jsxs("span",{"aria-hidden":"true",children:[Le,e.jsx("span",{className:"ml-1.5 font-mono text-small text-muted",children:xe.more(ee.length-1)})]}),e.jsx("span",{className:"sr-only",children:xe.moreLabel(Le,ee.length-1)})]}):Le??"",sub:pe})}),e.jsx(xn,{label:xe.agent,children:e.jsx("div",{role:"group","aria-label":xe.agent,className:"grid grid-cols-2 gap-2",children:oN.map(Z=>e.jsxs("button",{type:"button","aria-pressed":Z===m,onClick:()=>Q(Z),className:"flex flex-col items-start gap-0.5 rounded-lg border border-input px-[11px] py-[9px] text-left text-[13.5px] font-medium aria-pressed:border-ring aria-pressed:bg-raised aria-pressed:shadow-[inset_0_0_0_1px_var(--color-ring)]",children:[d.tools[Z],e.jsx("small",{className:"text-[11.5px] font-normal text-muted",children:xe.tools[Z]})]},Z))})}),e.jsx(xn,{label:xe.model,children:e.jsx(Fl,{onClick:()=>A("model"),lead:e.jsx(F,{name:"cpu",className:"size-4 text-muted"}),label:xe.model,text:Ye,sub:pt})}),m==="omp"&&e.jsxs(xn,{label:xe.permissions,children:[e.jsx(Gn,{name:"launch-approval",legend:xe.permissions,value:y,onChange:Z=>D(()=>w(Z)),options:cN.map(Z=>({value:Z,label:xe.approvals[Z][0]}))}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:xe.approvals[y][1]})]}),e.jsxs(xn,{label:xe.message,htmlFor:M,children:[e.jsx("textarea",{id:M,value:j,onChange:Z=>ie(Z.target.value),placeholder:xe.placeholder,rows:4,className:"min-h-[92px] resize-none rounded-lg border border-input bg-surface px-3 py-2.5 text-[15px] leading-[22px] outline-none placeholder:text-muted focus:border-ring focus:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)]"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:xe.ideas.map(Z=>e.jsx("button",{type:"button",onClick:()=>ie(Z),className:"h-8 rounded-lg border border-dashed border-input px-2.5 text-[12.5px] text-muted",children:Z},Z))})]})]}),e.jsxs("div",{className:"bleed flex flex-none flex-col gap-1.5 border-t border-line bg-bg px-3.5 pt-2.5 pb-[calc(14px+var(--foot-inset))]",children:[ce&&e.jsx(uN,{outcome:ce,agent:se,machine:l,onRetry:W(ce)?null:()=>_(ce)}),K?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:!0,className:Oe({variant:"primary",className:"w-full"}),children:K.label}),K.body]}):e.jsx("button",{type:"button",disabled:E,onClick:()=>void v(),className:Oe({variant:"primary",className:"w-full"}),children:E?e.jsxs(e.Fragment,{children:[e.jsx(F,{name:"spinner",className:"size-4 motion-safe:animate-spin"}),xe.launching]}):e.jsxs(e.Fragment,{children:[Ct()&&e.jsx(F,{name:"face",className:"size-[18px]"}),Ct()?xe.launchCheck:xe.launchDevice]})}),T&&e.jsx("span",{role:"status",className:"text-center text-[12px] leading-4 text-destructive",children:xe.cancelled}),!K&&c&&e.jsx("span",{className:"text-center text-[12px] leading-4 text-muted",children:xe.summary(se,ge,l,c.name)})]}),$==="project"&&e.jsxs(ct,{labelledBy:"launch-project",onClose:()=>A(null),children:[e.jsx("h2",{id:"launch-project",className:"text-base font-semibold",children:xe.project}),e.jsx(Yo,{children:r.map(Z=>e.jsx(Zo,{on:Z.id===(c==null?void 0:c.id),onClick:()=>J(Z),lead:e.jsx(Ie,{state:re?"off":"idle"}),text:Z.name,sub:re?`${l} · ${xe.offline}`:l},Z.id))})]}),$==="where"&&c&&e.jsxs(ct,{labelledBy:"launch-where",onClose:()=>A(null),children:[e.jsxs("div",{children:[e.jsx("h2",{id:"launch-where",className:"text-base font-semibold",children:xe.where}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:xe.folders(c.name)})]}),e.jsx(Yo,{children:H.map((Z,q)=>{const ye=ix(Z)?Z.exists===!1?xe.folder.missing(l):null:xe.folder.elsewhere(Z.label??Z.machine,l);return e.jsx(Zo,{on:ee.includes(Z.path),disabled:ye!==null,onClick:()=>Y(Z.path),lead:e.jsx(F,{name:ye===null&&Z.branch?"branch":"folder",className:"size-5 text-muted"}),text:q===0?xe.projectFolder:Go(Z.path),sub:ye??Z.branch??void 0},`${Z.machine}:${Z.path}`)})}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:xe.folder.single})]}),$==="model"&&e.jsx(ct,{labelledBy:Jr,onClose:()=>A(null),children:e.jsx(Kd,{tool:m,models:O,error:(jt=n.models[m])==null?void 0:jt.error,pick:g,onPick:Z=>D(()=>f(Z)),actions:e.jsx("button",{type:"button",onClick:()=>A(null),className:Oe({variant:"primary",className:"w-full"}),children:xe.done})})})]})}function xn({label:t,htmlFor:s,children:n}){const a=s?"label":"span";return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(a,{...s?{htmlFor:s}:{},className:"text-[12px] font-medium text-muted",children:t}),n]})}function Fl({onClick:t,lead:s,text:n,sub:a,dim:l=!1}){return e.jsxs("button",{type:"button","aria-haspopup":"dialog",onClick:t,className:`flex min-h-12 w-full items-center gap-2.5 rounded-lg border border-input bg-surface px-3 py-1.5 text-left ${l?"opacity-60":""}`,children:[s,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate text-body",children:n}),a&&e.jsx("small",{className:"truncate text-[12px] text-muted",children:a})]}),e.jsx(F,{name:"down",className:"size-4 text-muted"})]})}function Yo({children:t}){return e.jsx("div",{className:"flex max-h-[50vh] flex-col overflow-y-auto rounded-[10px] border border-line",children:t})}function Zo({on:t,disabled:s=!1,onClick:n,lead:a,text:l,sub:r}){return e.jsxs("button",{type:"button","aria-pressed":t,disabled:s,onClick:n,className:"flex min-h-12 items-center gap-3 border-b border-line px-3.5 py-1.5 text-left text-[15px] last:border-b-0 aria-pressed:bg-raised disabled:opacity-45",children:[a,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate",children:l}),r&&e.jsx("small",{className:"truncate text-[12px] text-muted",children:r})]}),t&&e.jsx(F,{name:"check",className:"size-4"})]})}function uN({outcome:t,agent:s,machine:n,onRetry:a}){const l={label:xe.retry,onClick:a??(()=>{})};if(t.kind==="timeout")return a?e.jsx(nt,{tone:"warn",title:xe.timeout,body:xe.timeoutBody,action:l}):e.jsx(nt,{tone:"warn",title:xe.timeout,body:xe.lostBody,action:{label:d.atoi.seeSessions,href:ae({name:"sessions"})}});if(t.kind==="failed")return e.jsx(nt,{tone:"fail",title:xe.failed(s),body:xe.failedBody(s),action:l});const r=xe.refused;switch(t.reason){case"not_found":return e.jsx(nt,{tone:"fail",title:r.not_found,body:xe.kept});case"invalid":return e.jsx(nt,{tone:"fail",title:r.invalid,body:r.invalidBody(s)});case"stale":return e.jsx(nt,{tone:"fail",title:r.stale,body:r.staleBody});case"confirm_required":return e.jsx(nt,{tone:"fail",title:r.confirm_required,body:r.setupKept,action:{label:xe.settings,href:"#/connection/link"}});case"assertion_invalid":return e.jsx(nt,{tone:"fail",title:r.assertion_invalid,body:xe.kept,action:l});case"assertion_expired":return e.jsx(nt,{tone:"warn",title:r.assertion_expired,body:r.expiredBody,action:l});case"unavailable":return e.jsx(nt,{tone:"warn",title:r.unavailable(n),body:r.unavailableBody});default:return e.jsx(nt,{tone:"fail",title:r.other,body:xe.kept})}}const $r="ledge.mobile.forge",xN=35e3,mN=65e3,fi=(t,s)=>s?`${t}
|
|
21
|
+
${s}`:t,Ta=t=>t!=="checking"&&t!=="sending"&&t!=="received",Pl=t=>!!t&&(!Ta(t.phase)||t.phase==="uncertain"&&!t.lost),Jo=new Set(["assertion_invalid","assertion_expired","confirm_required","conflict"]);function pN(t){var s;try{const n=(s=Xe(t))==null?void 0:s.getItem($r);if(!n)return null;const a=JSON.parse(n),l=Ux.safeParse(a.state);return l.success&&typeof a.at=="string"?{state:l.data,at:a.at}:null}catch{return null}}function fN(t,s,n){var G;const a=pN(n);let l={state:(a==null?void 0:a.state)??null,at:(a==null?void 0:a.at)??null,loading:!1,details:{},runs:[],drafts:{}};const r=new Set,i=O=>{l={...l,...O};for(const D of[...r])D()};let o=!1,c=!1,x=!1;const u=new Map,m=new Map,p=new Map;let g=0,f=s.getState().daemon?((G=s.getState().daemon)==null?void 0:G.boot)??null:void 0;const y=new Set,w=()=>!o&&t.state()==="ready",S=()=>{var O;return!!((O=s.getState().daemon)!=null&&O.forge)},b=O=>{t.send(O).catch(()=>{})},j=(O,D,J)=>{clearTimeout(u.get(O)),u.set(O,setTimeout(()=>{u.delete(O),J()},D))},N=O=>{clearTimeout(u.get(O)),u.delete(O)};function $(){x||!c||!w()||!S()||(x=!0,b({type:"forge.state"}),i({loading:!0}),j("state",xN,()=>{x=!1,i({loading:!1})}))}const A=O=>l.runs.find(D=>D.op===O);function E(O,D){const J=l.runs.findIndex(Y=>Y.id===O);if(J<0)return;const Q=D(l.runs[J]);if(i({runs:l.runs.map((Y,ie)=>ie===J?Q:Y)}),Ta(Q.phase)){Q.op&&Q.phase!=="uncertain"&&m.delete(Q.op);const Y=p.get(O);p.delete(O),Y==null||Y(Q)}}const k=O=>O.sentAt!==void 0&&Date.now()-O.sentAt<bc&&f!==void 0&&(O.boot??null)===f,T=O=>{N(`op:${O.op}`),m.delete(O.op),E(O.id,D=>({...D,phase:"uncertain",lost:!0,endedAt:D.endedAt??Date.now()}))};function C(O){for(const[D,J]of[...m]){const Q=A(D);if(!Q){m.delete(D);continue}if(!O.has(D)){if(!k(Q)){T(Q);continue}E(Q.id,Y=>({...Y,again:!0})),b(J),Q.phase==="sending"&&P(D)}}}const I=(O,D)=>{N(`op:${O}`);const J=A(O);J&&Pl(J)&&E(J.id,Q=>({...Q,...D,endedAt:Date.now()}))},P=O=>j(`op:${O}`,jc,()=>{const D=A(O);(D==null?void 0:D.phase)==="sending"&&E(D.id,J=>({...J,phase:"uncertain",endedAt:Date.now()}))});function L(O){var D,J,Q;switch(O.type){case"snapshot":{const Y=f;f=O.daemon.boot??null;const ie=new Set(y);y.clear();for(const X of ie){const le=A(X);le&&E(le.id,B=>({...B,boot:f}))}(Y===void 0||Y!==f)&&C(ie),$();return}case"forge.state":{N("state");const Y=new Date().toISOString(),ie={prs:O.prs,forges:O.forges,followed:O.followed},X=Object.keys(l.details).filter(le=>{var _,W,se;const B=(W=(_=l.details[le])==null?void 0:_.data)==null?void 0:W.pr.headSha,v=(se=ie.prs.find(re=>re.id===le))==null?void 0:se.headSha;return B&&v&&B!==v});i({state:ie,at:Y,loading:!1});try{(D=Xe(n))==null||D.setItem($r,JSON.stringify({state:ie,at:Y}))}catch{}for(const le of X)ee.readDetail(le);return}case"forge.detail":{N(`detail:${O.prId}`);const Y=l.details[O.prId];if(O.detail){const ie=O.detail.log??((J=Y==null?void 0:Y.data)!=null&&J.log&&O.detail.jobs.some(X=>X.id===Y.data.log.jobId)?Y.data.log:void 0);i({details:{...l.details,[O.prId]:{data:{...O.detail,...ie?{log:ie}:{}},...O.cut?{cut:!0}:{},loading:!1,at:new Date().toISOString()}}})}else i({details:{...l.details,[O.prId]:{...Y,loading:!1,error:O.error??"failed"}}});return}case"operation.result":{const Y=A(O.op);if(!Y||!Pl(Y))return;if(O.status==="received"){N(`op:${O.op}`),(Y.phase==="sending"||Y.phase==="uncertain")&&E(Y.id,ie=>{const{endedAt:X,...le}=ie;return{...le,phase:"received"}});return}if(O.status==="rejected"&&Y.again&&Jo.has(O.reason??"")){T(Y);return}O.status==="rejected"&&I(O.op,{phase:"rejected",reason:O.reason??"invalid"});return}case"forge.done":{const Y=A(O.op);if(!Y)return;if(Y.again&&O.rejected&&Jo.has(O.rejected)){Y.lost||T(Y);return}const ie=O.rejected?{phase:"rejected",reason:O.rejected,done:O}:{phase:"done",done:O,...O.error?{reason:O.error}:{}};if(Y.lost)m.delete(Y.op),E(Y.id,X=>{const{lost:le,...B}=X;return{...B,...ie,endedAt:Date.now()}});else{const X=Pl(Y);I(O.op,ie),X||E(Y.id,le=>({...le,done:O}))}if(O.ok&&(Y.action.kind==="comment"||Y.action.kind==="reply")){const X=fi(Y.prId,Y.action.kind==="reply"?Y.action.threadId:void 0);if(((Q=l.drafts[X])==null?void 0:Q.trim())===Y.action.body){const{[X]:le,...B}=l.drafts;i({drafts:B})}}l.details[Y.prId]&&ee.readDetail(Y.prId);return}}}let R=w();const M=t.subscribe(()=>{const O=t.state();(O==="unpaired"||O==="pairing")&&U();const D=w();if(D&&!R)R=!0,g++,x=!1,f=void 0,y.clear();else if(!D&&R){R=!1,x=!1;for(const[Q,Y]of u)clearTimeout(Y),u.delete(Q);const J=Object.fromEntries(Object.entries(l.details).map(([Q,Y])=>[Q,Y.loading?{...Y,loading:!1}:Y]));i({loading:!1,details:J});for(const Q of l.runs)Q.phase==="sending"&&Q.op&&E(Q.id,Y=>({...Y,phase:"uncertain",endedAt:Date.now()}))}}),z=t.onMessage(L);function U(){var O;if(!(!l.state&&!l.runs.length&&!Object.keys(l.details).length&&!Object.keys(l.drafts).length)){try{(O=Xe(n))==null||O.removeItem($r)}catch{}m.clear(),i({state:null,at:null,loading:!1,details:{},runs:[],drafts:{}})}}async function H(O){var Y;if(!((Y=s.getState().device)!=null&&Y.confirm))return{phase:"rejected",reason:"confirm_required"};let D;try{D=await s.prepareConfirm(O)}catch(ie){return{phase:ie instanceof Error&&ie.message==="timeout"?"expired":"unsent"}}if(!D.credentialId)return{phase:"rejected",reason:"confirm_required"};const J=Date.now(),Q=await Yn({challenge:D.challenge,rpId:D.rpId,credentialId:D.credentialId}).catch(()=>"failed");return Q==="cancelled"?{phase:"cancelled"}:Q==="failed"?{phase:"unsent"}:Date.now()-J>=D.expiresInMs?{phase:"expired"}:{assertion:Q}}async function V(O,D,J){var X;P(D);const Q=g,Y=await t.send(J).catch(()=>!1),ie=(X=A(D))==null?void 0:X.phase;!Y&&Q===g&&(ie==="sending"||ie==="uncertain")&&(N(`op:${D}`),E(O,le=>({...le,phase:"unsent",endedAt:Date.now()})))}const ee={getState:()=>l,subscribe(O){return r.add(O),()=>{r.delete(O)}},follow(){c=!0,$()},readDetail(O,D){!w()||!S()||(b({type:"forge.detail",prId:O,...D?{log:D}:{}}),i({details:{...l.details,[O]:{...l.details[O],loading:!0}}}),j(`detail:${O}`,mN,()=>i({details:{...l.details,[O]:{...l.details[O],loading:!1,error:"failed"}}})))},act(O,D){const J=crypto.randomUUID(),Q={op:"",id:J,prId:O,action:D,phase:"checking",startedAt:Date.now()};if(!w()||!S()){const ie={...Q,phase:"unsent",endedAt:Date.now()};return i({runs:[...l.runs,ie]}),Promise.resolve(ie)}const Y=new Promise(ie=>p.set(J,ie));return i({runs:[...l.runs,Q]}),(async()=>{const ie=await H({purpose:"forge",forge:{prId:O,action:D}});if(!("assertion"in ie)){E(J,B=>({...B,phase:ie.phase,...ie.reason?{reason:ie.reason}:{},endedAt:Date.now()}));return}const X=gc(),le=xc.safeParse({type:"forge.act",op:X,prId:O,action:D,assertion:ie.assertion});if(!le.success||!w()){E(J,B=>({...B,phase:"unsent",endedAt:Date.now()}));return}m.set(X,le.data),f===void 0&&y.add(X),E(J,B=>({...B,op:X,phase:"sending",sentAt:Date.now(),boot:f??null})),await V(J,X,le.data)})(),Y},resend(O){const D=l.runs.find(Q=>Q.id===O),J=D!=null&&D.op?m.get(D.op):void 0;if(!(!D||D.phase!=="uncertain"||D.lost||!J||!w())){if(!k(D)){T(D);return}E(O,Q=>{const{endedAt:Y,...ie}=Q;return{...ie,phase:"sending",again:!0}}),V(O,D.op,J)}},setDraft(O,D){if(D)i({drafts:{...l.drafts,[O]:D}});else{const{[O]:J,...Q}=l.drafts;i({drafts:Q})}},dismiss(O){const D=l.runs.find(J=>J.id===O);D&&Ta(D.phase)&&D.op&&m.delete(D.op),i({runs:l.runs.filter(J=>J.id!==O||!Ta(J.phase))})},close(){o=!0,M(),z();for(const O of u.values())clearTimeout(O);u.clear()}};return ee}function ul(t){return h.useSyncExternalStore(t.subscribe,t.getState,t.getState)}const Qe=d.prs;function hN({status:t,pc:s}){const[n,a]=h.useState(!1),l=Zt(t),r=e.jsx(F,{name:"warning",className:"mt-px size-4 text-attention"});if(t.status==="missing")return e.jsx(Kt,{warn:!0,role:"alert",lead:r,children:e.jsx("span",{"data-forge-strip":"missing",children:Qe.missing(l.cli,s,t.host,l.kind)})});if(t.status==="unauthenticated"){const c=Tf(t);return e.jsxs(Kt,{warn:!0,role:"alert",lead:r,children:[e.jsx("b",{"data-forge-strip":"unauthenticated",className:"font-semibold",children:Qe.unauth(l.cli,t.host,s)}),e.jsx("code",{className:"block rounded-md bg-raised px-2 py-1.5 font-mono text-[12px] break-all",children:c}),e.jsx("button",{type:"button",className:je({size:"sm",className:"self-start"}),onClick:()=>{var x;(x=navigator.clipboard)==null||x.writeText(c).then(()=>a(!0),()=>{})},children:n?Qe.copied:Qe.copy})]})}const i=t.since??t.at,o=[t.retryAt?Qe.retryAt(Fe(t.retryAt)):"",t.readAt?Qe.readAt(l.kind,Fe(t.readAt)):""].filter(Boolean).join(" ");return e.jsx(Kt,{warn:!0,role:"alert",lead:r,children:e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("b",{"data-forge-strip":"error",className:"font-semibold",children:Qe.error(l.host,s,Fe(i))}),o&&e.jsx("span",{className:"text-muted",children:o})]})})}function gN(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[5px] bg-raised";return e.jsxs("div",{role:"status","data-list-state":"",className:"flex flex-col gap-3",children:[e.jsx(Ke,{children:e.jsxs("div",{"aria-hidden":"true",className:"flex flex-col gap-2.5 p-2.5",children:[e.jsx("span",{className:`${t} h-3.5 w-[70%]`}),e.jsx("span",{className:`${t} h-3 w-[45%]`}),e.jsx("span",{className:`${t} h-3.5 w-[60%]`}),e.jsx("span",{className:`${t} h-3 w-1/2`})]})}),e.jsx("span",{className:"text-[12px] text-muted",children:Qe.loading})]})}function bN(t,s,n){const a=n!=null&&n.readAt?Qe.asOf(Fe(n.readAt)):Qe.state[t.state];return[Qe.host[t.forge],nl(t.repo),...s?[s]:[],a].join(" · ")}function jN({forge:t,store:s}){const n=ul(t),a=fe(s),{pc:l,look:r}=qt(),i=Zn(),o=It(),[c,x]=h.useState(!0),u=r==="offline",m=Bt(l),p=n.state,g=w=>{var b;const S=w.sessions[0];return S?((b=a.sessions.get(S))==null?void 0:b.name)??null:null},f=w=>Qe.offlineBody(n.at?Fe(n.at):w),y=(()=>{if(!p)return e.jsx(gN,{});const w=Af(p.forges),S=$=>w.find(A=>A.forge===$.forge&&A.host===$.host),{open:b,closed:j}=Cf(p.prs),N=p.forges.length>0&&w.length===p.forges.length;return e.jsxs(e.Fragment,{children:[!u&&w.map($=>e.jsx(hN,{status:$,pc:m},`${$.forge}:${$.host}`)),e.jsxs("div",{className:`flex flex-col gap-3 ${u?"opacity-50":""}`,children:[b.length===0?e.jsx(Ke,{children:N?e.jsx(Qt,{framed:!1,glyph:null,title:Qe.emptyTitle,body:Qe.emptyUnread,list:j.length===0}):e.jsx(Qt,{glyph:e.jsx(F,{name:"pr",className:"size-[22px]"}),title:Qe.emptyTitle,body:Qe.emptyBody,list:j.length===0})}):e.jsxs(e.Fragment,{children:[e.jsx(zt,{aside:!u&&n.at?Qe.asOf(Fe(n.at)):void 0,children:Qe.openHead(b.length)}),e.jsx(Ke,{label:Qe.title,children:b.map($=>{const A=S($),E=md($),k=e.jsxs(e.Fragment,{children:[e.jsx(_d,{pipeline:$.pipeline}),!u&&!A&&$.openThreads>0&&e.jsx(Kn,{children:Qe.threads($.openThreads)}),!u&&!A&&E&&e.jsx(Kn,{ok:!0,children:Qe.ready})]});return e.jsx(Yi,{pr:$,sub:bN($,g($),A),chips:k,...u?{}:{href:ae({name:"pr",id:$.id})},selected:o&&i.name==="pr"&&i.id===$.id},$.id)})})]}),j.length>0&&e.jsxs(Ke,{children:[e.jsxs("button",{type:"button","aria-expanded":!c,onClick:()=>x($=>!$),className:"flex min-h-11 w-full items-center gap-[9px] px-3 py-1.5 text-left text-[13px] text-muted",children:[e.jsx(F,{name:c?"chevron":"down",className:"size-3.5"}),Qe.closedGroup(j.length)]}),!c&&e.jsx("div",{className:"border-t border-line",children:j.map($=>e.jsx(Yi,{pr:$,dim:!0,sub:[Qe.host[$.forge],nl($.repo),Qe.state[$.state],ah($.updatedAt)].join(" · "),...u?{}:{href:ae({name:"pr",id:$.id})},selected:o&&i.name==="pr"&&i.id===$.id},$.id))})]})]}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:Qe.tracked})]})})();return e.jsx(Os,{title:Qe.title,offlineBody:f,heading:!1,children:y})}const Ge=d.prs,lt=d.rigs,mn=t=>Ge.notDone[t.action.kind],yN=t=>{var s;return t.phase==="expired"?"assertion_expired":t.phase==="cancelled"?"cancelled":t.phase==="unsent"?"unsent":t.reason??((s=t.done)==null?void 0:s.error)};function hi({run:t,pr:s,detail:n,forge:a,pc:l,onReload:r}){const i=Zt(s),o=Ct(),c={onClose:()=>a.dismiss(t.id),closeLabel:Ge.close};if(t.phase==="checking")return e.jsx(Vn,{children:lt.running.checking});if(t.phase==="sending"||t.phase==="received")return e.jsx(Vn,{children:t.action.kind==="merge"?`${Ge.merging} · ${Ge.answers(i.cli)}`:Ge.answers(i.cli)});if(t.phase==="uncertain")return e.jsx(ve,{mark:"ask",title:lt.uncertain.title,sub:lt.uncertain.body,...c,children:!t.lost&&e.jsx("button",{type:"button",onClick:()=>a.resend(t.id),className:je({size:"xs",className:"mt-1.5"}),children:Ge.retry})});const x=yN(t),u=t.done;if(t.phase==="done"&&(u!=null&&u.ok)){const g=Fe(t.endedAt?new Date(t.endedAt).toISOString():null);return t.action.kind==="merge"?e.jsx(ve,{mark:"ok",title:Ge.merged(s.ref),sub:Ge.mergedSub(g,s.target),...c,children:u.command&&e.jsx(Vs,{commands:[u.command]})}):t.action.kind==="rerun"?e.jsx(ve,{mark:"ok",title:Ge.rerunDone(s.ref),sub:Ge.rerunDoneSub(g),...c,children:u.command&&e.jsx(Vs,{commands:[u.command]})}):t.action.kind==="reply"?e.jsx(ve,{mark:"ok",title:Ge.replyPosted(i.host),sub:g,...c}):t.action.kind==="comment"?e.jsx(ve,{mark:"ok",title:Ge.commentPosted(i.host),sub:g,...c}):null}if((t.action.kind==="comment"||t.action.kind==="reply")&&x!=="unavailable"&&x!=="confirm_required"){const g=t.action,f=x==="assertion_expired"?lt.rejected.assertion_expired(o):x==="assertion_invalid"?lt.rejected.assertion_invalid(o):x==="cancelled"?lt.rejected.cancelled:x==="unsent"?lt.rejected.unsent:Ge.lastLine(i.cli),y=!["assertion_expired","assertion_invalid","cancelled","unsent"].includes(x??"");return e.jsx(ve,{mark:"bad",title:`${lt.because(mn(t),f)} ${Ge.keptText}`,...y&&(u!=null&&u.message)?{sub:e.jsx("span",{className:"font-mono",children:u.message})}:{},...c,children:e.jsx("button",{type:"button",onClick:()=>{a.dismiss(t.id),a.act(t.prId,g)},className:je({size:"xs",className:"mt-1.5"}),children:Ge.retry})})}const p=t.action.kind==="merge"?lt.rejected.again(Ge.mergeAgain):lt.rejected.nothingSent;switch(x){case"stale":return e.jsx(ve,{mark:"warn",title:Ge.stale(Vr(s.headSha)),sub:Ge.staleBody,...c,children:e.jsx("button",{type:"button",onClick:r??(()=>a.readDetail(t.prId)),className:je({size:"xs",className:"mt-1.5"}),children:Ge.reload})});case"not_offered":{if(t.action.kind==="rerun")return e.jsx(ve,{mark:"warn",title:Ge.nothingToRerun,...c});const g=n?tl(n).find(y=>!y.ok):void 0,f=g?nr(Fn(g,i.host),g):(u==null?void 0:u.message)??"";return e.jsx(ve,{mark:"bad",title:Ge.refused(i.host,f),...c})}case"busy":return e.jsx(ve,{mark:"warn",title:Ge.rerunRefused(Ge.rerunBusy),...c});case"confirm_required":return e.jsx(ve,{mark:"warn",title:lt.rejected.confirm_required,...c});case"assertion_expired":return e.jsx(ve,{mark:"bad",title:lt.because(mn(t),lt.rejected.assertion_expired(o)),sub:p,...c});case"assertion_invalid":return e.jsx(ve,{mark:"bad",title:lt.because(mn(t),lt.rejected.assertion_invalid(o)),sub:p,...c});case"cancelled":return e.jsx(ve,{mark:"bad",title:lt.because(mn(t),lt.rejected.cancelled),sub:lt.rejected.nothingSent,...c});case"unsent":return e.jsx(ve,{mark:"bad",title:lt.because(mn(t),lt.rejected.unsent),sub:lt.rejected.nothingSent,...c});case"unavailable":return e.jsx(ve,{mark:"warn",title:Ge.gone(i.kind,l),sub:Ge.goneBody,...c});default:return e.jsx(ve,{mark:"bad",title:t.action.kind==="resolve"?lt.because(mn(t),Ge.lastLine(i.cli)):Ge.failed(i.cli),...u!=null&&u.message?{sub:e.jsx("span",{className:"font-mono",children:u.message})}:{},...c,children:(u==null?void 0:u.command)&&e.jsx(Vs,{commands:[u.command]})})}}const fn=d.prs,Ga=t=>t.toLocaleString(dt);function ec(t){return t.startsWith("@@")?"hunk":t.startsWith("+")?"add":t.startsWith("-")?"del":"ctx"}const NN={hunk:"bg-info/8 text-info",add:"bg-ok/15",del:"bg-danger-fg/15",ctx:"text-muted"};function tc({path:t}){return e.jsx("span",{className:"min-w-0 flex-1 overflow-hidden text-left font-mono text-[12px] text-ellipsis whitespace-nowrap [direction:rtl]",children:e.jsx("span",{dir:"ltr",children:t})})}function sc({f:t}){return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"font-mono text-[12px] text-ok",children:["+",Ga(t.added)]}),e.jsxs("span",{className:"font-mono text-[12px] text-danger-fg",children:["−",Ga(t.removed)]})]})}function kN({f:t,threads:s,host:n}){const[a,l]=h.useState(!1),r=s>0&&e.jsx(Kn,{children:fn.fileThreads(s)});return t.patch===void 0?e.jsxs("div",{"data-file":t.path,className:"flex min-h-[46px] flex-wrap items-center gap-2 border-b border-line px-3 py-1.5 text-[13px] last:border-b-0",children:[e.jsx(F,{name:"file",className:"size-3.5 text-muted"}),e.jsx(tc,{path:t.path}),r,e.jsx(sc,{f:t}),e.jsx("span",{className:"basis-full pl-[22px] text-[12px] text-muted",children:fn.noPatch(n)})]}):e.jsxs("div",{"data-file":t.path,className:"border-b border-line last:border-b-0",children:[e.jsxs("button",{type:"button","aria-expanded":a,onClick:()=>l(i=>!i),className:"flex min-h-[46px] w-full items-center gap-2 px-3 py-1.5 text-left text-[13px]",children:[e.jsx(F,{name:a?"down":"chevron",className:"size-3.5 text-muted"}),e.jsx(tc,{path:t.path}),r,e.jsx(sc,{f:t})]}),a&&e.jsx("pre",{className:"m-0 overflow-hidden border-t border-line bg-well font-mono text-[11px] leading-[17px]",children:t.patch.split(`
|
|
22
|
+
`).map((i,o)=>e.jsx("span",{"data-line":ec(i),className:`block overflow-hidden px-3 text-ellipsis whitespace-pre ${NN[ec(i)]}`,children:i||" "},o))})]})}function vN({detail:t}){if(t.files.length===0)return e.jsx("p",{className:"p-2.5 text-center text-[12px] text-muted",children:fn.noChange});const s=Lf(t),n=fn.host[t.pr.forge];return e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx(zt,{aside:e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"font-mono text-ok",children:["+",Ga(s.added)]})," ",e.jsxs("span",{className:"font-mono text-danger-fg",children:["−",Ga(s.removed)]})]}),children:fn.fileCount(t.files.length)}),e.jsx(Ke,{label:fn.tabs.changes,children:t.files.map(a=>e.jsx(kN,{f:a,threads:zf(t,a.path),host:n},a.path))})]})}const Bl=d.prs,wN=t=>[...t].sort((s,n)=>Date.parse(n.at)-Date.parse(s.at));function SN({detail:t}){return e.jsxs("div",{className:"flex flex-col gap-2.5",children:[t.commits.length>0&&e.jsx(Ke,{label:Bl.tabs.commits,children:wN(t.commits).map(s=>e.jsxs("div",{"data-commit":s.sha,className:"flex min-h-[52px] items-center gap-2.5 border-b border-line px-3 py-1.5 last:border-b-0",children:[e.jsx(F,{name:"commit",className:"size-4 text-muted"}),e.jsx("span",{className:"flex-none font-mono text-[12px] text-muted",children:Vr(s.sha)}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col text-[13.5px]",children:[e.jsx("span",{className:"truncate",children:s.title}),e.jsx("small",{className:"text-[12px] text-muted",children:`${s.author} · ${ir(s.at)}`})]})]},s.sha))}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:Bl.commitsReadOnly(Bl.host[t.pr.forge])})]})}const rt=d.prs,gi=t=>t.file?t.line!==void 0?rt.fileLine(t.file,t.line):t.file:null,ox=(t,s,n)=>t.filter(a=>a.prId===s&&n(a)).at(-1),cx=["checking","sending","received"];function dx({sent:t,onClose:s}){return t==="refused"?e.jsx(ve,{mark:"bad",title:d.agents.notSent,onClose:s,closeLabel:rt.close}):e.jsx(ve,{mark:"ok",title:rt.commentSent(t.name),onClose:s,closeLabel:rt.close,children:e.jsx("a",{href:ae({name:"thread",sessionId:t.id}),className:je({size:"xs",className:"mt-1.5"}),children:rt.openAgent(t.name)})})}function ux({id:t,label:s,placeholder:n,verb:a,value:l,onChange:r,confirm:i,live:o,onPost:c,host:x,autoFocus:u=!1,rows:m=2,arrow:p=!1}){const g=e.jsx("textarea",{id:t,rows:l?Math.max(m,2):m,value:l,placeholder:n,autoFocus:u,onChange:f=>r(f.target.value),className:p?"min-h-[34px] min-w-0 flex-1 resize-none bg-transparent py-[6px] text-base leading-[22px] text-fg outline-none placeholder:text-muted":"min-h-11 w-full resize-none rounded-[14px] border border-input bg-surface px-3.5 py-[11px] text-base leading-5 text-fg placeholder:text-muted"});return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:t,className:"sr-only",children:s}),p?e.jsxs("div",{className:"flex min-w-0 items-end gap-2 rounded-[10px] border border-input bg-surface py-[5px] pr-[5px] pl-3 focus-within:border-ring focus-within:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)]",children:[g,l.trim()===""&&e.jsx("button",{type:"button",disabled:!0,"aria-label":a,title:a,className:"grid size-9 flex-none place-items-center rounded-lg bg-primary text-primary-fg disabled:opacity-40",children:e.jsx(F,{name:"send",className:"size-[18px]"})})]}):g,l.trim()!==""&&e.jsxs(e.Fragment,{children:[e.jsx(zs,{verb:a,confirm:i,disabled:!o,onClick:c}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:rt.postedAs(x)})]})]})}const $N=({who:t,at:s,body:n,reply:a})=>e.jsxs("p",{className:`m-0 text-[13.5px] leading-[19px] [overflow-wrap:anywhere] whitespace-pre-wrap ${a?"border-l-2 border-line pl-[9px]":""}`,children:[e.jsx("span",{className:"font-semibold",children:t}),e.jsx("span",{className:"ml-1 font-mono text-[11px] text-muted",children:Fe(s)}),e.jsx("br",{}),n]}),CN="flex flex-col gap-2 rounded-[10px] border border-line bg-surface p-2.5 dark:bg-transparent",ql="h-9 !px-2.5 text-[12.5px]";function xx({pr:t,t:s,agent:n,forge:a,store:l,live:r,pc:i,readOnly:o=!1}){var k,T;const c=ul(a),x=fe(l),[u,m]=h.useState(!1),[p,g]=h.useState(null),f=fi(t.id,s.id),y=c.drafts[f]??"",w=Zt(t),S=gi(s),b=s.comments[0],j=ox(c.runs,t.id,C=>(C.action.kind==="reply"||C.action.kind==="resolve")&&C.action.threadId===s.id),N=()=>{n&&g(l.reply(n.id,rt.threadText(t.ref,b.author,S,b.body))?n:"refused")},$=()=>{m(!1),a.act(t.id,{kind:"reply",threadId:s.id,body:y.trim()})},A=!!j&&cx.includes(j.phase),E=!A&&(u||y!==""&&(j==null?void 0:j.action.kind)==="reply"&&j.phase!=="uncertain"&&!(j.phase==="done"&&((k=j.done)!=null&&k.ok)));return e.jsxs("article",{"data-thread":s.id,className:CN,children:[S&&e.jsx("span",{className:"font-mono text-[11px] text-muted",children:S}),s.code&&e.jsx("code",{className:"block truncate rounded-md bg-ok/15 px-2 py-[3px] font-mono text-[11.5px] leading-[17px] whitespace-pre",children:s.code}),s.comments.map((C,I)=>e.jsx($N,{who:C.author,at:C.at,body:C.body,reply:I>0},C.id)),!o&&e.jsxs(e.Fragment,{children:[E?e.jsx(ux,{id:`reply-${s.id}`,label:rt.reply,placeholder:rt.replyPh,verb:rt.reply,value:y,onChange:C=>a.setDraft(f,C),confirm:!!((T=x.device)!=null&&T.confirm),live:r,onPost:$,host:w.host,autoFocus:u}):e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsx("button",{type:"button",disabled:!r||A,onClick:()=>m(!0),className:je({className:ql}),children:rt.reply}),n&&e.jsx("button",{type:"button",disabled:!x.fresh,onClick:N,className:je({className:ql}),children:rt.sendTo(n.name)}),s.resolvable&&e.jsx("button",{type:"button",disabled:!r||A,onClick:()=>void a.act(t.id,{kind:"resolve",threadId:s.id}),className:`${je({className:ql})} border-transparent`,children:rt.resolve})]}),p&&e.jsx(dx,{sent:p,onClose:()=>g(null)}),j&&e.jsx(hi,{run:j,pr:t,detail:void 0,forge:a,pc:i})]})]})}function MN({pr:t,t:s,forge:n,store:a,pc:l}){const[r,i]=h.useState(!1),o=gi(s);return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-expanded":r,onClick:()=>i(c=>!c),"data-thread":s.id,className:"flex items-center gap-2 rounded-[10px] border border-dashed border-line px-2.5 py-2 text-left text-[12.5px] text-muted",children:[e.jsx("span",{"aria-hidden":"true",className:"text-ok",children:"✓"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:rt.resolvedRow([...o?[o]:[],s.comments[0].author])}),e.jsx(F,{name:r?"down":"chevron",className:"size-3.5"})]}),r&&e.jsx(xx,{pr:t,t:s,agent:null,forge:n,store:a,live:!1,pc:l,readOnly:!0})]})}function mx(t,s){const n=fe(s),[a,l]=h.useState(null),r=(t==null?void 0:t.threads)??[],i=t?Id(t.pr,n.sessions)[0]:void 0,o=i?{id:i.id,name:i.name}:null,c=r.filter(u=>!u.resolved),x=()=>{if(!o||!t)return;const u=c.map(m=>rt.note(m.comments[0].author,gi(m),m.comments[0].body));l(s.reply(o.id,rt.notesText(t.pr.ref,u))?o:"refused")};return{agent:o,open:c,resolved:r.filter(u=>u.resolved),sent:a,send:x,clear:()=>l(null),fresh:n.fresh}}function px({all:t,className:s=""}){return!t.agent||!t.open.length?null:e.jsxs("button",{type:"button",disabled:!t.fresh,onClick:t.send,className:je({size:"sm",className:s}),children:[e.jsx(F,{name:"send",className:"size-4"}),rt.sendAll(t.agent.name)]})}function nc({detail:t,forge:s,store:n,live:a,pc:l,column:r}){const i=mx(t,n),o=r??i,c=t.pr;return t.threads.length?e.jsxs(e.Fragment,{children:[!r&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12.5px] text-muted",children:rt.discSub(o.open.length,o.resolved.length)}),e.jsx("span",{className:"flex-1"}),e.jsx(px,{all:o})]}),o.sent&&e.jsx(dx,{sent:o.sent,onClose:o.clear}),o.open.map(x=>e.jsx(xx,{pr:c,t:x,agent:o.agent,forge:s,store:n,live:a,pc:l},x.id)),o.resolved.map(x=>e.jsx(MN,{pr:c,t:x,forge:s,store:n,pc:l},x.id))]}):e.jsx("p",{className:"m-0 p-2.5 text-center text-[12.5px] text-muted",children:rt.noComment})}function ac({pr:t,forge:s,store:n,live:a,pc:l}){var m;const r=ul(s),i=fe(n),o=fi(t.id),c=r.drafts[o]??"",x=ox(r.runs,t.id,p=>p.action.kind==="comment"),u=!!x&&cx.includes(x.phase);return e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[x&&e.jsx(hi,{run:x,pr:t,detail:void 0,forge:s,pc:l}),e.jsx(ux,{id:`comment-${t.id}`,label:rt.addComment,placeholder:rt.addComment,verb:rt.post,value:c,onChange:p=>s.setDraft(o,p),confirm:!!((m=i.device)!=null&&m.confirm),live:a&&!u,onPost:()=>void s.act(t.id,{kind:"comment",body:c.trim()}),host:Zt(t).host,rows:1,arrow:!0})]})}const EN=`${Pr} and (orientation: landscape)`,fx=()=>typeof globalThis.matchMedia=="function"?globalThis.matchMedia(EN):null,AN=t=>{var n;const s=fx();return(n=s==null?void 0:s.addEventListener)==null||n.call(s,"change",t),()=>{var a;return(a=s==null?void 0:s.removeEventListener)==null?void 0:a.call(s,"change",t)}};function TN(){return h.useSyncExternalStore(AN,()=>{var t;return((t=fx())==null?void 0:t.matches)??!1},()=>!1)}const ne=d.prs,_N={review:"border-attention/45 text-attention"};function IN({pr:t,landscape:s}){const n=It(),a=Zt(t);return n?e.jsxs("header",{"data-pr-head":"",className:"flex h-[58px] flex-none items-center gap-[9px] border-b border-line pr-2.5 pl-[22px]",children:[e.jsx("span",{className:"inline-flex h-5 flex-none items-center rounded-lg border border-input px-[7px] text-[11.5px] whitespace-nowrap text-muted",children:`${a.host} · ${a.kind}`}),e.jsx("h1",{className:"min-w-0 truncate text-[16px] font-semibold",children:`${t.ref} ${t.title}`}),s&&e.jsx("span",{"data-pr-state":t.state,className:`inline-flex h-[22px] flex-none items-center rounded-full border px-[9px] text-[12px] font-medium whitespace-nowrap ${_N[t.state]??"border-input text-muted"}`,children:ne.state[t.state]}),e.jsx("span",{className:"flex-1"}),s?e.jsxs("a",{href:t.url,target:"_blank",rel:"noreferrer",className:je({size:"sm",className:"flex-none"}),children:[e.jsx(F,{name:"external",className:"size-4"}),ne.openOn(a.host)]}):e.jsx("a",{href:t.url,target:"_blank",rel:"noreferrer","aria-label":ne.openOn(a.host),title:ne.openOn(a.host),className:$t(),children:e.jsx(F,{name:"external",className:"size-[18px]"})})]}):e.jsxs("header",{className:`flex flex-none items-center gap-2 border-b border-line pr-1.5 ${n?"pane-head h-[58px]":"h-14 pl-0.5"}`,children:[e.jsx(ls,{fallback:{name:"prs"},label:ne.title}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("h1",{className:"truncate text-[15px] font-semibold",children:`${t.ref} ${t.title}`}),e.jsx("small",{className:"truncate text-[12px] text-muted",children:[a.host,nl(t.repo),`${t.branch} → ${t.target}`].join(" · ")})]}),e.jsx("a",{href:t.url,target:"_blank",rel:"noreferrer","aria-label":ne.openOn(a.host),title:ne.openOn(a.host),className:$t(),children:e.jsx(F,{name:"external",className:"size-[18px]"})})]})}const RN=["overview","discussion","changes","commits"],ON=["overview","changes","commits"];function LN({pr:t,d:s,view:n,views:a,onView:l,wide:r}){const i=s?{discussion:s.threads.length,changes:s.files.length,commits:s.commits.length}:{};return e.jsx("nav",{"aria-label":ne.title,className:`flex flex-none gap-0.5 overflow-x-auto overflow-y-hidden border-b border-line [scrollbar-width:none] ${r?"px-1.5 py-2":"p-2"}`,children:a.map(o=>e.jsxs("button",{type:"button","aria-current":n===o?"page":void 0,onClick:()=>l(o),className:"group inline-flex h-9 flex-none items-center gap-[5px] rounded-lg px-[7px] text-[13px] font-medium whitespace-nowrap text-muted aria-[current=page]:bg-raised aria-[current=page]:text-fg",children:[o==="overview"&&e.jsx(Ie,{state:tn[t.pipeline],pulse:t.pipeline==="run"}),ne.tabs[o],i[o]!==void 0&&e.jsx("span",{className:"inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-raised px-1 font-mono text-[11px] group-aria-[current=page]:bg-bg",children:i[o]})]},o))})}const hx={ok:"border-ok/40",fail:"border-approval/60",run:"border-info/50",wait:"border-line text-muted",skip:"border-line text-muted",none:"border-line text-muted"},gx=t=>t==="fail"?"bg-danger-bg":"bg-surface dark:bg-transparent";function bx(t){if(t.status==="run")return e.jsx("span",{className:"font-mono text-[12px] text-info",children:ne.pipe.run});const s=gd(t.durationS);return s?e.jsx("span",{className:"font-mono text-[12px] text-muted",children:s.hours?ne.hours(s.text):s.text}):t.status==="wait"||t.status==="skip"?e.jsx("span",{className:"text-[12px]",children:ne.pipe[t.status]}):null}function zN({job:t,selected:s,onOpen:n}){const a=e.jsxs(e.Fragment,{children:[t.status==="run"?e.jsx(Cn,{}):e.jsx(Ie,{state:tn[t.status]}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.name}),bx(t)]}),l=`flex h-11 w-full items-center gap-2.5 rounded-[10px] border px-3 text-left text-[14px] ${gx(t.status)} ${hx[t.status]} ${s?"shadow-[0_0_0_2px_var(--color-ring)]":""}`;return n?e.jsx("button",{type:"button","data-job":t.id,onClick:n,className:l,children:a}):e.jsx("div",{"data-job":t.id,className:l,children:a})}function DN({after:t}){const s=t.jobs.some(a=>a.status==="fail"),n=t.jobs.every(a=>a.status==="ok");return e.jsx("span",{"aria-hidden":"true",className:`mt-[5px] mb-[5px] ml-[22px] block h-3 ${s?"border-l-2 border-dashed border-approval":`w-0.5 ${n?"bg-ok":"bg-input"}`}`})}function FN({pr:t,jobs:s,selected:n,onJob:a}){const l=fd(s);return e.jsx("div",{className:"flex flex-col",children:l.map((r,i)=>e.jsxs("div",{className:"flex flex-col",children:[i>0&&e.jsx(DN,{after:l[i-1]}),e.jsx("div",{className:"mb-[5px] text-[11px] tracking-[.5px] text-muted uppercase",children:t.forge==="gitlab"?ne.stage(i+1,r.name):r.name}),e.jsx("div",{className:"flex flex-col gap-1.5",children:r.jobs.map(o=>e.jsx(zN,{job:o,selected:o.id===n,onOpen:o.id===n?void 0:()=>a(o)},o.id))})]},r.column))})}function PN({job:t,selected:s,onOpen:n}){const a=e.jsxs(e.Fragment,{children:[t.status==="run"?e.jsx(Cn,{}):e.jsx(Ie,{state:tn[t.status]}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.name}),bx(t)]}),l=`flex h-10 min-w-[92px] items-center gap-[7px] rounded-[10px] border px-[9px] text-left text-[13px] ${gx(t.status)} ${hx[t.status]} ${s?"shadow-[0_0_0_2px_var(--color-ring)]":""}`;return n?e.jsx("button",{type:"button","data-job":t.id,onClick:n,className:l,children:a}):e.jsx("div",{"data-job":t.id,className:l,children:a})}function BN({after:t}){const s=t.jobs.some(a=>a.status==="fail"),n=t.jobs.every(a=>a.status==="ok");return e.jsx("span",{"aria-hidden":"true",className:`mt-[39px] block w-5 flex-none ${s?"border-t-2 border-dashed border-approval":`h-0.5 ${n?"bg-ok":"bg-input"}`}`})}function qN({pr:t,jobs:s,selected:n,onJob:a}){const l=fd(s);return e.jsx("div",{"data-pipeline":"side",className:"flex flex-none items-start overflow-x-auto rounded-[10px] border border-line bg-surface p-3.5 dark:bg-[oklch(0.18_0_0)]",children:l.map((r,i)=>e.jsxs("div",{className:"contents",children:[i>0&&e.jsx(BN,{after:l[i-1]}),e.jsxs("div",{className:"flex min-w-0 flex-[0_1_auto] flex-col gap-2",children:[e.jsx("div",{className:"mb-[5px] text-[11px] tracking-[.5px] whitespace-nowrap text-muted uppercase",children:t.forge==="gitlab"?ne.stage(i+1,r.name):r.name}),r.jobs.map(o=>e.jsx(PN,{job:o,selected:o.id===n,onOpen:o.id===n?void 0:()=>a(o)},o.id))]})]},r.column))})}const HN=({text:t,tall:s=!1})=>e.jsx("pre",{className:`m-0 overflow-hidden rounded-[10px] border border-white/10 bg-[#0c0c0d] px-[11px] py-[9px] font-mono text-[11.5px] leading-[17px] break-all whitespace-pre-wrap text-[#e5e5e5] ${s?"max-h-[300px] overflow-y-auto":""}`,children:t});function jx({job:t,read:s,pr:n,onRetry:a,tall:l=!1}){var o,c;const r=Zt(n),i=((c=(o=s==null?void 0:s.data)==null?void 0:o.log)==null?void 0:c.jobId)===t.id?s.data.log.text:null;return i!==null?e.jsx(HN,{text:i,tall:l}):s!=null&&s.loading?e.jsxs("div",{role:"status",className:"flex items-center gap-2 text-[12px] text-muted",children:[e.jsx(Cn,{className:"text-muted"}),ne.log.reading(t.name)]}):e.jsx(ve,{mark:"bad",title:ne.log.failed,sub:ne.log.failedBody(r.cli,r.host),children:e.jsx("button",{type:"button",onClick:a,className:je({size:"xs",className:"mt-1.5"}),children:ne.retry})})}function UN({job:t,read:s,pr:n,onRetry:a,onClose:l}){var x,u;const r=h.useId(),i=Zt(n),o=gd(t.durationS),c=((u=(x=s==null?void 0:s.data)==null?void 0:x.log)==null?void 0:u.jobId)===t.id?s.data.log.text:null;return e.jsxs(ct,{labelledBy:r,onClose:l,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ie,{state:tn[t.status]}),e.jsx("h2",{id:r,className:"text-[15px] font-semibold",children:ne.log.title(t.name)}),e.jsx("span",{className:"text-[12px] text-muted",children:[ne.pipe[t.status],o?o.hours?ne.hours(o.text):o.text:""].filter(Boolean).join(" · ")})]}),e.jsx(jx,{job:t,read:s,pr:n,onRetry:a,tall:!0}),c!==null&&e.jsx("p",{className:"m-0 text-[12px] leading-4 text-muted",children:[ne.log.note,_f(c)?ne.log.cut(i.host):""].filter(Boolean).join(" ")}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("a",{href:n.url,target:"_blank",rel:"noreferrer",className:je(),children:[e.jsx(F,{name:"external",className:"size-4"}),ne.openOn(i.host)]}),e.jsx("button",{type:"button",onClick:l,className:je(),children:ne.close})]})]})}function WN({text:t}){return e.jsx("div",{className:"text-[13.5px] leading-5",children:t.split(/\n\n+/).map((s,n)=>{const a=s.split(`
|
|
23
|
+
`);return a.every(l=>l.startsWith("- "))?e.jsx("ul",{className:"mt-1 list-disc pl-[18px]",children:a.map((l,r)=>e.jsx("li",{children:l.slice(2)},r))},n):e.jsx("p",{className:"m-0 whitespace-pre-wrap",children:s},n)})})}const KN={approved:"idle",changes:"perm",pending:"plain"};function VN({d:t}){const s="text-muted",n="m-0 flex min-w-0 flex-wrap items-center gap-1.5";return e.jsxs("dl",{className:"m-0 grid grid-cols-[auto_1fr] gap-x-3.5 gap-y-1.5 border-t border-line pt-2.5 text-[13px]",children:[e.jsx("dt",{className:s,children:ne.author}),e.jsx("dd",{className:n,children:t.author}),t.reviewers.map((a,l)=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:s,children:l===0?ne.reviewers:""}),e.jsxs("dd",{className:n,children:[e.jsx(Ie,{state:KN[a.state]}),a.name," ",e.jsx("span",{className:"text-muted",children:ne.reviewer[a.state]})]})]},a.name)),t.labels.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:s,children:ne.labels}),e.jsx("dd",{className:n,children:t.labels.map(a=>e.jsx("span",{className:"rounded-full border border-line px-2 text-[12px]",children:a},a))})]}),t.issues.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:s,children:ne.issue}),e.jsx("dd",{className:`${n} font-mono text-[12px]`,children:t.issues.join(" ")})]})]})}function GN({conds:t,host:s}){return e.jsxs("section",{"aria-label":ne.toMerge,className:"flex-none overflow-hidden rounded-[10px] border border-line bg-surface dark:bg-transparent",children:[e.jsx("div",{className:"flex min-h-11 items-center border-b border-line px-3",children:e.jsx("b",{className:"text-[14px] font-semibold",children:ne.toMerge})}),e.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-2.5 text-[13px]",children:t.map((n,a)=>e.jsxs("li",{"data-cond":n.ok?"ok":n.key,className:"flex items-baseline gap-2",children:[e.jsx("span",{"aria-hidden":"true",className:`w-3.5 flex-none text-center text-[12px] font-semibold ${n.ok?"text-ok":"text-approval"}`,children:n.ok?"✓":"✕"}),e.jsx("span",{className:n.key==="raw"?"font-mono":"",children:Fn(n,s)})]},a))})]})}function XN(t,s){const n=tl(t),a=n.find(i=>!i.ok);if(a)return e.jsxs(e.Fragment,{children:[ne.footApprovals(bd(t.pr))," · ",e.jsx("b",{className:"font-medium text-fg",children:nr(Fn(a,s),a)})]});const l=n.find(i=>i.key==="pipeline"||i.key==="noCi"),r=n.find(i=>i.key==="approved");return`${Fn(l,s)} · ${nr(Fn(r,s),r)}`}function yx(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[10px] bg-raised";return e.jsxs("div",{role:"status",className:"flex flex-col gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:`${t} h-11`}),e.jsx("span",{"aria-hidden":"true",className:`${t} h-11`}),e.jsx("span",{"aria-hidden":"true",className:`${t} h-[60px]`}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ne.detailLoading})]})}function QN({pr:t,job:s,store:n}){const a=fe(n),l=Id(t,a.sessions),[r,i]=h.useState(null),[o,c]=h.useState(!1),[x,u]=h.useState(null),m=h.useId();if(!l.length)return e.jsx("p",{className:"m-0 text-[12px] leading-4 text-muted",children:ne.noSession(t.branch)});const p=l.find(y=>y.id===r)??l[0],g=a.fresh,f=()=>{u(n.reply(p.id,ne.fixText(t.ref,s))?{id:p.id,name:p.name}:"refused")};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{type:"button",disabled:!g,onClick:f,className:je({tone:"dangerfill",className:"flex-1"}),children:ne.askFix(p.name)}),l.length>1&&e.jsx("button",{type:"button","aria-label":ne.otherSession,title:ne.otherSession,"aria-haspopup":"menu",disabled:!g,onClick:()=>c(!0),className:je({className:"w-12 !px-0"}),children:e.jsx(F,{name:"down",className:"size-4"})})]}),x==="refused"&&e.jsx(ve,{mark:"bad",title:d.agents.notSent,onClose:()=>u(null),closeLabel:ne.close}),x&&x!=="refused"&&e.jsx(ve,{mark:"ok",title:ne.sentTo(x.name),onClose:()=>u(null),closeLabel:ne.close,children:e.jsx("a",{href:ae({name:"thread",sessionId:x.id}),className:je({size:"xs",className:"mt-1.5"}),children:ne.openAgent(x.name)})}),o&&e.jsxs(ct,{labelledBy:m,onClose:()=>c(!1),children:[e.jsx("h2",{id:m,className:"sr-only",children:ne.otherSession}),e.jsx("div",{role:"menu","aria-labelledby":m,className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:l.map((y,w)=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":y.id===p.id,onClick:()=>{i(y.id),c(!1)},className:"flex min-h-12 items-center gap-3 border-b border-line px-3.5 text-left text-[15px] last:border-b-0 aria-checked:bg-secondary",children:[e.jsx(Ie,{state:wn(y)}),e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[y.name," ",e.jsx("small",{className:"text-[12px] text-muted",children:[d.tools[y.tool],y.repo].filter(Boolean).join(" · ")})]}),w===0&&e.jsx("span",{className:"text-[12px] text-muted",children:ne.mostActive})]},y.id))})]})]})}function YN({pr:t,confirm:s,live:n,onRerun:a,onClose:l}){return e.jsxs(rs,{title:ne.rerunTitle(t.ref),onClose:l,children:[e.jsx("p",{className:"m-0 text-[12.5px] leading-[18px] text-muted",children:ne.rerunBody(Zt(t).host)}),e.jsx(zs,{verb:ne.rerun,confirm:s,disabled:!n,onClick:()=>{l(),a()}}),e.jsx(da,{onClose:l})]})}function ZN({pr:t,read:s,store:n,live:a,onJob:l,onLog:r,onRerun:i,side:o}){const c=s==null?void 0:s.data,x=Zt(t),u=c?hd(c.jobs):null,m=t.state!=="merged"&&t.state!=="closed",p=t.pipeline==="none"?ne.noCi:c!=null&&c.mergeBlockers.includes("pipeline_not_started")?ne.notStarted:null;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"m-0 text-[15px] font-semibold",children:ne.pipelineTitle}),e.jsx(_d,{pipeline:t.pipeline,short:!0}),e.jsx("span",{className:"flex-1"}),Of(t)&&e.jsxs("button",{type:"button",disabled:!a,onClick:i,className:je({size:"sm"}),children:[e.jsx(F,{name:"refresh",className:"size-4"}),ne.rerun]})]}),p&&e.jsx("p",{className:"m-0 text-[12px] text-muted",children:p}),c?e.jsxs(e.Fragment,{children:[c.jobs.length>0&&(o?e.jsx(qN,{pr:t,jobs:c.jobs,selected:(u==null?void 0:u.id)??null,onJob:l}):e.jsx(FN,{pr:t,jobs:c.jobs,selected:(u==null?void 0:u.id)??null,onJob:l})),u&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center gap-2 text-[12px] text-muted",children:e.jsx("span",{children:`${ne.log.title(u.name)} · ${ne.log.lines}`})}),e.jsx(jx,{job:u,read:s,pr:t,onRetry:()=>r(u)}),m&&e.jsx(QN,{pr:t,job:u.name,store:n})]}),m&&e.jsx(GN,{conds:tl(c),host:x.host}),c.description&&e.jsxs("div",{className:"flex flex-col gap-1.5 border-t border-line pt-2.5",children:[e.jsx("h2",{className:"m-0 text-[15px] font-semibold",children:ne.description}),e.jsx(WN,{text:c.description})]}),e.jsx(VN,{d:c})]}):e.jsx(yx,{})]})}function JN({read:t,pr:s,pc:n,onRetry:a}){const l=Zt(s);return t.error==="unavailable"?e.jsx(ve,{mark:"warn",title:ne.gone(l.kind,n),sub:ne.goneBody}):t.error==="too_large"?e.jsx(ve,{mark:"bad",title:ne.tooLarge,sub:ne.tooLargeBody(l.host),children:e.jsx("a",{href:s.url,target:"_blank",rel:"noreferrer",className:je({size:"xs",className:"mt-1.5"}),children:ne.open})}):e.jsx(ve,{mark:"bad",title:ne.readFailed(l.cli,l.kind),sub:ne.readFailedBody,children:e.jsx("button",{type:"button",onClick:a,className:je({size:"xs",className:"mt-1.5"}),children:ne.retry})})}function e0({d:t,pc:s,confirm:n,live:a,onMerge:l,onClose:r}){return e.jsxs(rs,{title:ne.confirm(t.pr.ref,t.pr.target),onClose:r,children:[e.jsx("span",{className:"text-[12.5px] text-muted",children:ne.runsOn(s)}),e.jsx("code",{className:"block rounded-md bg-raised px-2 py-1.5 font-mono text-[12px] break-all",children:t.mergeCommand}),e.jsx("p",{className:"m-0 text-[12px] leading-4 text-muted",children:ne.headRead(Vr(t.pr.headSha))}),e.jsx(zs,{verb:ne.merge,confirm:n,disabled:!a,onClick:()=>{r(),l()}}),e.jsx(da,{onClose:r})]})}const t0=(t,s)=>t.filter(n=>n.prId===s&&(n.action.kind==="merge"||n.action.kind==="rerun")).at(-1),s0=t=>!!t&&(t.phase==="checking"||t.phase==="sending"||t.phase==="received");function n0({id:t,forge:s,store:n,pane:a=!1}){var le,B,v,_,W,se,re;const l=ul(s),r=fe(n),[i,o]=h.useState(!1),[c,x]=h.useState(!1),{pc:u,look:m}=qt(),p=It(),g=TN()&&p&&!a,[f,y]=h.useState("overview"),[w,S]=h.useState(null),b=m==="offline",j=Bt(u),N=l.details[t],$=(le=l.state)==null?void 0:le.prs.find(K=>K.id===t),A=$??((B=N==null?void 0:N.data)==null?void 0:B.pr),E=mx(N==null?void 0:N.data,n);h.useEffect(()=>{s.readDetail(t)},[s,t]);const k=N!=null&&N.data?hd(N.data.jobs):null,T=h.useRef(null);h.useEffect(()=>{var K,ce;!k||((ce=(K=N==null?void 0:N.data)==null?void 0:K.log)==null?void 0:ce.jobId)===k.id||T.current===k.id||(T.current=k.id,s.readDetail(t,k.id))},[s,t,k==null?void 0:k.id,(_=(v=N==null?void 0:N.data)==null?void 0:v.log)==null?void 0:_.jobId]);const C=h.useRef(null);h.useEffect(()=>{var K,ce;(ce=(K=C.current)==null?void 0:K.scrollTo)==null||ce.call(K,{top:0})},[f]);const I=`tab-main flex min-h-0 flex-1 flex-col gap-2.5 overflow-y-auto overscroll-contain pb-[18px] ${p?"px-[22px] pt-[18px]":"pt-3"}`;if(!A)return e.jsx("main",{"data-tab-scroll":"",className:I,children:l.state?e.jsx(ve,{mark:"warn",title:ne.gone(ne.kind[((W=l.state.forges.find(K=>K.host===t.split("/")[0]))==null?void 0:W.forge)??"github"],j),sub:ne.goneBody}):e.jsx(Kt,{lead:e.jsx(Cn,{className:"text-muted"}),children:e.jsx("span",{children:ne.loading})})});const P=Zt(A),L=N==null?void 0:N.data,R=A.state==="merged"||A.state==="closed",M=!!l.state&&!$,z=w&&L?L.jobs.find(K=>K.id===w):void 0,U=K=>{s.readDetail(t,K.id)},H=t0(l.runs,t),V=s0(H),ee=r.fresh&&!b,G=()=>{L&&s.act(t,{kind:"merge",headSha:L.pr.headSha})},O=g?ON:RN,D=O.includes(f)?f:"overview",J=e.jsxs(e.Fragment,{children:[e.jsx(gs,{body:ne.offlineBody}),M&&!H&&e.jsx(ve,{mark:"warn",title:ne.gone(P.kind,j),sub:ne.goneBody}),H&&e.jsx(hi,{run:H,pr:A,detail:L,forge:s,pc:j,onReload:()=>s.readDetail(t)}),(N==null?void 0:N.error)&&!L&&e.jsx(JN,{read:N,pr:A,pc:j,onRetry:()=>s.readDetail(t)}),(N==null?void 0:N.cut)&&e.jsx(Kt,{lead:e.jsx(F,{name:"alert",className:"mt-px size-4 text-muted"}),children:e.jsx("span",{children:ne.cut(P.host)})}),e.jsxs("div",{className:`flex flex-col ${g?"gap-4":"gap-2.5"} ${b?"opacity-50":""}`,children:[D==="overview"&&(!(N!=null&&N.error)||L)&&e.jsx(ZN,{pr:A,read:N,store:n,live:ee&&!V&&!M,side:g,onJob:K=>{S(K.id),U(K)},onLog:U,onRerun:()=>x(!0)}),D!=="overview"&&!L&&!(N!=null&&N.error)&&e.jsx(yx,{}),D==="discussion"&&L&&e.jsx(nc,{detail:L,forge:s,store:n,live:ee&&!M,pc:j}),D==="changes"&&L&&e.jsx(vN,{detail:L}),D==="commits"&&L&&e.jsx(SN,{detail:L})]})]}),Q=e.jsxs("span",{"data-foot":"done",className:`flex min-w-0 flex-1 flex-wrap items-center gap-1.5 leading-4 text-muted ${p?"text-[12.5px]":"text-[12px]"}`,children:[e.jsx("span",{className:"inline-flex h-[22px] items-center rounded-full border border-input px-[9px] text-[12px] font-medium",children:ne.state[A.state]}),A.state==="merged"?ne.mergedInto(A.target,ir(A.updatedAt)):ir(A.updatedAt)]}),Y=e.jsx("span",{"data-foot":"why",className:`min-w-0 flex-1 leading-4 text-muted ${p?"text-[12.5px]":"text-[12px]"}`,children:L?XN(L,P.host):ne.footApprovals(bd(A))}),ie=e.jsxs("button",{type:"button",disabled:!ee||M||V||!L||!Rf(L),onClick:()=>o(!0),className:je(p?{tone:"primary",size:"sm",className:"flex-none"}:{tone:"primary",className:"h-[42px]"}),children:[e.jsx(F,{name:"merge",className:"size-4"}),ne.merge]}),X=p?"flex flex-none items-center gap-2.5 border-t border-line bg-sidebar px-[18px] py-2.5":"flex flex-none items-center gap-2.5 border-t border-line bg-sidebar px-3.5 py-[9px]";return e.jsxs(e.Fragment,{children:[e.jsx(IN,{pr:A,landscape:g}),e.jsx(LN,{pr:A,d:L,view:D,views:O,onView:y,wide:p}),g?e.jsxs("div",{className:"grid min-h-0 flex-1 grid-cols-[minmax(0,1fr)_320px]",children:[e.jsx("main",{ref:C,"data-tab-scroll":"",className:"tab-main flex min-h-0 min-w-0 flex-col gap-4 overflow-y-auto overscroll-contain px-[22px] py-[18px]",children:J}),e.jsxs("aside",{"aria-labelledby":`disc-${t}`,"data-pr-discussion":"",className:"flex min-h-0 min-w-0 flex-col border-l border-line",children:[e.jsxs("div",{className:"flex h-12 flex-none items-center gap-2 border-b border-line px-3.5",children:[e.jsx("h2",{id:`disc-${t}`,className:"m-0 text-[15px] font-semibold",children:ne.tabs.discussion}),L&&L.threads.length>0&&e.jsx("span",{className:"text-[12.5px] text-muted",children:ne.discSub(E.open.length,E.resolved.length)})]}),e.jsx("div",{className:`flex min-h-0 flex-1 flex-col gap-2.5 overflow-y-auto overscroll-contain p-3 ${b?"opacity-50":""}`,children:L&&e.jsx(nc,{detail:L,forge:s,store:n,live:ee&&!M,pc:j,column:E})}),!R&&e.jsx("div",{className:"flex flex-none border-t border-line px-3 py-2.5",children:e.jsx(ac,{pr:A,forge:s,store:n,live:ee&&!M,pc:j})})]})]}):e.jsx("main",{ref:C,"data-tab-scroll":"",className:I,children:J}),e.jsx("footer",{className:X,children:g?e.jsxs(e.Fragment,{children:[R?Q:Y,e.jsx(px,{all:E,className:"flex-none"}),!R&&ie]}):D==="discussion"&&!R?e.jsx(ac,{pr:A,forge:s,store:n,live:ee&&!M,pc:j}):R?Q:e.jsxs(e.Fragment,{children:[Y,ie]})}),c&&e.jsx(YN,{pr:A,confirm:!!((se=r.device)!=null&&se.confirm),live:ee,onRerun:()=>{s.act(t,{kind:"rerun"})},onClose:()=>x(!1)}),i&&L&&e.jsx(e0,{d:L,pc:j,confirm:!!((re=r.device)!=null&&re.confirm),live:ee,onMerge:G,onClose:()=>o(!1)}),z&&e.jsx(UN,{job:z,read:N,pr:A,onRetry:()=>U(z),onClose:()=>S(null)})]})}function a0(t){const[,s]=h.useReducer(n=>n+1,0);return h.useEffect(()=>{const n=t.subscribe(s);return s(),n},[t]),t.state()}function l0(t){const[,s]=h.useReducer(n=>n+1,0);return h.useEffect(()=>{if(!t)return;const n=t.subscribe(s);return s(),n},[t]),{build:(t==null?void 0:t.current())??null,waiting:(t==null?void 0:t.waiting())??null}}function r0(t){var n;const[,s]=h.useReducer(a=>a+1,0);return h.useEffect(()=>t==null?void 0:t.subscribe(s),[t]),((n=t==null?void 0:t.getState().state)==null?void 0:n.prs)??[]}function i0(t,s){const[n,a]=h.useState(null);return h.useEffect(()=>{if(!s){a(null);return}let l=!0;return t("/auth/me",{credentials:"same-origin",cache:"no-store"}).then(async r=>r.ok?Vx.safeParse(await r.json()):null).then(r=>{l&&(r!=null&&r.success)&&a(r.data.login)}).catch(()=>{}),()=>{l=!1}},[t,s]),n}const o0=(t,s)=>globalThis.fetch(t,s),lc=t=>t.name==="request"?{name:"request",sessionId:t.sessionId,key:t.key}:t.name==="ask"?{name:"ask",id:t.id}:null;function c0({link:t,store:s,storage:n,fetchImpl:a=o0,updates:l=null,signin:r=null,lost:i=!1,relay:o=globalThis.location.host}){var _e,oe,Ae,st,yt,js;const c=dc(),x=a0(t),u=fe(s),m=Zn(),p=i0(a,x!=="signed_out"),{build:g,waiting:f}=l0(l),[y,w]=h.useState(null),[S,b]=h.useState(r),[j,N]=h.useState(i),[$,A]=h.useState(!1),[E,k]=h.useState(!1),[T,C]=h.useState(!1),I=h.useRef(!1),[P,L]=h.useState(!1),R=((_e=t.pairing())==null?void 0:_e.state())??null,M=((oe=t.recovery())==null?void 0:oe.state())??null,z=(M==null?void 0:M.step)==="reaching"||(M==null?void 0:M.step)==="faceid"||(M==null?void 0:M.step)==="checking",U=Ls(),[H,V]=h.useState(!1),[ee,G]=h.useState(!1),O=(M==null?void 0:M.step)==="done"&&(!u.fresh||Oo((Ae=u.device)==null?void 0:Ae.push));h.useEffect(()=>{O&&G(!0)},[O]),h.useEffect(()=>{M&&M.step!=="done"&&G(!1)},[M==null?void 0:M.step]);const D=D1(S),J=S==="not_allowed"?"denied":x==="signed_out"||D||S==="another"?"login":x==="replaced"?"replaced":x==="key_changed"?"keyChanged":x==="denied"?"unrecognized":x==="storage_unavailable"?"storage":(M==null?void 0:M.step)==="done"&&!E?"recover":(R==null?void 0:R.step)==="linked"&&!E?"compare":x==="unpaired"||x==="pairing"?R!==null||P||x==="pairing"&&!z?"compare":M&&M.step!=="cancelled"?"recover":"choose":"route",Q=He=>{I.current=!0,L(!0),He()},Y=()=>{V((M==null?void 0:M.step)==="failed"&&M.why==="old"),Q(()=>t.startPairing())};h.useEffect(()=>{x==="ready"&&(I.current=!1,L(!1),N(!1),A(!1)),(x==="unpaired"||x==="pairing")&&(k(!1),C(!1))},[x]),h.useEffect(()=>{var Rt;const He=(Rt=globalThis.navigator)==null?void 0:Rt.serviceWorker;if(!He)return;const Mt=Se=>fm(Se.data);return He.addEventListener("message",Mt),()=>He.removeEventListener("message",Mt)},[]);const ie=h.useRef("atoi"),X=h.useRef([]),le=Br(m);le&&(ie.current=le),h.useEffect(()=>{Cp(m)},[m]);const B=It(),v=V1(n),_=He=>Fo(He,n),W=h.useRef(!1);v&&B&&(W.current=!0);const se=h.useRef("atoi");le&&le!=="chat"&&(se.current=le);const re=B&&J==="route"&&m.name==="chat";h.useEffect(()=>{re&&(Fo(!0,n),xs(Ra(qr(se.current))))},[re,n]);const[K,ce]=h.useState(null);h.useEffect(()=>{const He=wy(t,s,n);return ce(He),()=>{He.close(),ce(null)}},[t,s,n]);const[ge,Ye]=h.useState(null);h.useEffect(()=>{const He=fN(t,s,n);return He.follow(),Ye(He),()=>{He.close(),Ye(null)}},[t,s,n]);const pt=r0(ge),Re=m.name==="atelier"&&(!B||(u.fresh||u.daemon!==null)&&!((st=u.daemon)!=null&&st.atelier));h.useEffect(()=>{Re&&xs({name:"sessions"})},[Re]);const Le=lc(m);Hr(B&&J==="route"&&le==="atoi",He=>{if(He!=="ArrowUp"&&He!=="ArrowDown")return!1;const Mt=s.getState(),Rt=Ym(fl(Wt([...Mt.sessions.values()]),Mt.asks??[]),lc(Ra(globalThis.location.hash)),He==="ArrowDown"?1:-1);return Rt?(xs(Rt),!0):!1});const pe=h.useRef(!1),he=x==="ready"&&u.fresh&&!!((yt=u.device)!=null&&yt.id)&&!u.device.name;h.useEffect(()=>{!he||pe.current||s.renameDevice(qu(void 0))!==null&&(pe.current=!0)},[he,s]);const Me=t.pinned(),ze=(Me==null?void 0:Me.name)??null,at=(Me==null?void 0:Me.name)??((js=u.daemon)==null?void 0:js.name)??null,et=()=>t.retry(),bt=h.useRef(!1),jt=He=>{if(!bt.current){if(x!=="ready"){x!=="denied"&&A(!0),He();return}bt.current=!0,s.forgetDevice().then(Mt=>{bt.current=!1,Mt||A(!0),He()})}},Z=()=>jt(()=>{t.signOut()}),q=()=>jt(()=>Q(()=>{t.relink()})),ye=(()=>{var nn,an,An,Tn;switch(J){case"denied":return e.jsx(R1,{onOther:()=>b("another")});case"login":return e.jsx(P1,{server:o,error:D});case"replaced":return e.jsx(B1,{onHere:()=>globalThis.location.reload()});case"keyChanged":return e.jsx(L1,{pcName:at,known:Me,received:t.receivedKey(),onRelink:q,onSignOut:Z});case"unrecognized":return e.jsx(gy,{pcName:at,onRelink:q,onSignOut:Z});case"storage":return e.jsx(G1,{onRetry:et,onReload:()=>globalThis.location.reload()});case"choose":return e.jsx(gf,{login:p,platform:U,onPasskey:()=>t.startRecovery(),onCode:Y});case"recover":return e.jsx(Nf,{state:M,login:p,reach:t.reach(),onRetry:()=>{var ut;(ut=t.recovery())!=null&&ut.again()||t.startRecovery()},onCode:Y,onCancel:()=>t.cancelRecovery(),onSignOut:Z,onDone:()=>k(!0),actions:ee?e.jsx(Lo,{store:s,fetchImpl:a,body:d.recover.done.notify,onDone:()=>k(!0)}):void 0});case"compare":return e.jsx(ff,{step:R,login:p,pcName:ze,lost:j,stalled:x==="unpaired"&&R===null&&P,reach:t.reach(),onRetry:et,onSame:()=>{var ut;return(ut=t.pairing())==null?void 0:ut.confirmOnPhone()},onCancel:()=>{var ut;return(ut=t.pairing())==null?void 0:ut.cancel()},onRestart:()=>Q(()=>t.startPairing()),onDone:()=>k(!0),actions:T?e.jsx(Lo,{store:s,fetchImpl:a,onDone:()=>{C(!1),k(!0)}}):e.jsx(vf,{store:s,update:H,onDone:()=>{var ut;Oo((ut=u.device)==null?void 0:ut.push)?C(!0):k(!0)}})})}const He=fl(Wt([...u.sessions.values()]),u.asks??[]);Le&&He.some(ut=>JSON.stringify(ut)===JSON.stringify(Le))&&(X.current=He);const Mt=ut=>()=>{const Fs=Qm(fl(Wt([...s.getState().sessions.values()]),s.getState().asks??[]),ut,X.current);xs(Fs??{name:"atoi"})},Rt={pc:at,look:Ep(u.fresh,!!u.syncedAt,t.reach()),reach:t.reach(),since:Fe(u.syncedAt),retry:et},Se=!!((nn=u.daemon)!=null&&nn.forge)&&ge!==null,Et=Se?Mf(pt):0,Ot={atoi:Mp(Wt([...u.sessions.values()]),u.asks??[]),prs:Et?{text:Et>99?"99+":String(Et),tone:"red"}:null},de=Se?e.jsx(jN,{forge:ge,store:s}):e.jsx(q1,{}),Ue=Se&&m.name==="pr"?e.jsx(n0,{id:m.id,forge:ge,store:s,pane:v},m.id):null,Ze=e.jsx(Nh,{store:s,onReconnect:et,forge:ge}),At=e.jsx(Rj,{store:s,filter:m.name==="sessions"?m.filter:void 0}),Jt=!!((an=u.device)!=null&&an.chat)||!u.fresh&&!u.device,Ds=Jt?e.jsx(Ro,{store:s,onReconnect:et}):e.jsx(zo,{}),ys=!!((An=u.daemon)!=null&&An.rigs)&&K!==null,Ht=ys?e.jsx(Iy,{rigs:K,store:s}):e.jsx(H1,{}),sn=ys?m.name==="rig"?e.jsx(Xy,{rig:m.rig,rigs:K,store:s},m.rig):m.name==="kernel"?e.jsx(iN,{rigs:K,store:s}):m.name==="max"?e.jsx(nN,{goalId:m.goalId,rigs:K,store:s},m.goalId??""):null:null,En=e.jsx(I1,{store:s,fetchImpl:a,login:p,relay:o,pinned:Me,linkState:x,build:g,onSignOut:Z,section:m.name==="connection"?m.section:void 0});if(B){const ut=(()=>{var bi;switch(m.name){case"atoi":return e.jsx(is,{list:Ze,detail:e.jsx(Nl,{...d.split.request})});case"ask":return e.jsx(is,{list:Ze,detail:e.jsx(Po,{store:s,id:m.id,onDone:Mt({name:"ask",id:m.id})},m.id)});case"request":return e.jsx(is,{list:Ze,detail:e.jsx(or,{store:s,sessionId:m.sessionId,requestKey:m.key,onReconnect:et,onSettled:Mt({name:"request",sessionId:m.sessionId,key:m.key}),keys:!0},m.sessionId)});case"sessions":return e.jsx(is,{tab:"sessions",list:At,detail:e.jsx(Nl,{...d.split.agent})});case"thread":return e.jsx(is,{tab:"sessions",list:At,detail:e.jsx(fr,{store:s,sessionId:m.sessionId,storage:n,onReconnect:et,forge:ge},m.sessionId)});case"launch":return e.jsx(is,{tab:"sessions",list:At,detail:e.jsx(Qo,{store:s,storage:n})});case"terminal":return e.jsx(is,{tab:"sessions",fold:!0,list:At,detail:e.jsx(Uo,{store:s,link:t,sessionId:m.sessionId,storage:n,forge:ge},m.sessionId)});case"prs":case"pr":return e.jsx(is,{tab:"prs",list:de,detail:Ue??e.jsx(Do,{icon:"pr",...d.prs.pane})});case"rigs":case"rig":case"kernel":case"max":return e.jsx(is,{list:Ht,detail:sn??e.jsx(Do,{icon:"rigs",...d.rigs.pane})});case"atelier":return(bi=u.daemon)!=null&&bi.atelier?e.jsx(yj,{store:s,...m.sessionId?{sessionId:m.sessionId}:{},...m.requestKey?{requestKey:m.requestKey}:{},storage:n,onReconnect:et}):e.jsx(is,{list:At,detail:e.jsx(Nl,{...d.split.agent})});case"chat":return null;case"connection":return En}})(),Fs=W.current&&e.jsx(U1,{open:v,onClose:()=>_(!1),children:Jt?e.jsx(Ro,{store:s,onReconnect:et,onClose:()=>_(!1)}):e.jsx(zo,{onClose:()=>_(!1)})});return e.jsxs(kl,{value:Rt,children:[ut,Fs,e.jsx(_p,{route:m,active:le??"settings",badges:Ot,atelier:!!((Tn=u.daemon)!=null&&Tn.atelier),ledge:{open:v,onToggle:()=>_(!v)}})]})}const it=(ut,Fs=!0)=>e.jsxs(kl,{value:Rt,children:[Fs&&e.jsx(Ap,{...typeof Fs=="string"?{title:Fs}:{}}),ut,e.jsx(Tp,{route:m,active:le??ie.current,badges:Ot})]});switch(m.name){case"atoi":return it(Ze);case"sessions":case"atelier":return it(At);case"prs":return it(de,Se?d.prs.title:!0);case"pr":return Ue?it(Ue,!1):it(de,Se?d.prs.title:!0);case"rigs":return it(Ht,ys?d.rigs.title:!0);case"rig":case"kernel":case"max":return sn?it(sn,!1):it(Ht,ys?d.rigs.title:!0);case"chat":return it(Ds,!Jt);case"connection":return it(En,!1);case"thread":return it(e.jsx(fr,{store:s,sessionId:m.sessionId,storage:n,onReconnect:et,forge:ge},m.sessionId),!1);case"terminal":return it(e.jsx(Uo,{store:s,link:t,sessionId:m.sessionId,storage:n,forge:ge},m.sessionId),!1);case"ask":return it(e.jsx(Po,{store:s,id:m.id},m.id),!1);case"launch":return e.jsx(kl,{value:Rt,children:e.jsx(Qo,{store:s,storage:n})});case"request":return it(e.jsx(or,{store:s,sessionId:m.sessionId,requestKey:m.key,onReconnect:et},m.sessionId),!1)}})();return e.jsx(Wx,{copy:Kx(c).ui,children:e.jsxs("div",{className:"app flex flex-col","data-route":m.name,children:[$&&x!=="ready"&&e.jsx("p",{role:"status",className:"mx-4 my-3 text-body text-muted",children:d.forget.pending}),ye,l&&f&&f.fingerprint!==y&&e.jsx(jy,{next:f,current:g,onLater:()=>w(f.fingerprint),onApply:()=>l.accept()})]})})}const f0=Object.freeze(Object.defineProperty({__proto__:null,App:c0},Symbol.toStringTag,{value:"Module"}));export{f0 as A,m0 as M,ty as R,p0 as a};
|