@spencerboucher/switchyard 0.8.0 → 0.10.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/README.md +4 -4
- package/dist/bridge/lines.js +33 -0
- package/dist/bridge/switchyard-terminal.js +59 -22
- package/dist/switchyard.mjs +9769 -7208
- package/dist/terminal/holder.js +172 -55
- package/package.json +1 -1
- package/web-dist/apple-touch-icon.png +0 -0
- package/web-dist/assets/AutomationView-BsTwLnMp.js +2 -0
- package/web-dist/assets/AutomationView-BsTwLnMp.js.map +1 -0
- package/web-dist/assets/Card-CAFxHoHd.js +2 -0
- package/web-dist/assets/Card-CAFxHoHd.js.map +1 -0
- package/web-dist/assets/Checkbox-rDvnQnxc.js +2 -0
- package/web-dist/assets/Checkbox-rDvnQnxc.js.map +1 -0
- package/web-dist/assets/Copy-D8xhl7eJ.js +2 -0
- package/web-dist/assets/Copy-D8xhl7eJ.js.map +1 -0
- package/web-dist/assets/DangerZone-og55TRug.js +2 -0
- package/web-dist/assets/DangerZone-og55TRug.js.map +1 -0
- package/web-dist/assets/Field-Dbg_8KTt.js +2 -0
- package/web-dist/assets/Field-Dbg_8KTt.js.map +1 -0
- package/web-dist/assets/InteractionCard-Yu5wgLC3.js +6 -0
- package/web-dist/assets/InteractionCard-Yu5wgLC3.js.map +1 -0
- package/web-dist/assets/Menu-euseM8yR.js +2 -0
- package/web-dist/assets/Menu-euseM8yR.js.map +1 -0
- package/web-dist/assets/Overlay-BNPvMjLX.js +2 -0
- package/web-dist/assets/Overlay-BNPvMjLX.js.map +1 -0
- package/web-dist/assets/Priority-Ca1B2yFr.js +2 -0
- package/web-dist/assets/Priority-Ca1B2yFr.js.map +1 -0
- package/web-dist/assets/{SegmentedControl-BZPzNU08.js → SegmentedControl-D2d-NEr-.js} +2 -2
- package/web-dist/assets/{SegmentedControl-BZPzNU08.js.map → SegmentedControl-D2d-NEr-.js.map} +1 -1
- package/web-dist/assets/Select-C9L1HKMm.js +2 -0
- package/web-dist/assets/Select-C9L1HKMm.js.map +1 -0
- package/web-dist/assets/StatusChip-BYuVxYS7.js +2 -0
- package/web-dist/assets/StatusChip-BYuVxYS7.js.map +1 -0
- package/web-dist/assets/Switch-DAcUcSbH.js +2 -0
- package/web-dist/assets/Switch-DAcUcSbH.js.map +1 -0
- package/web-dist/assets/Tabs-xtagjtA5.js +184 -0
- package/web-dist/assets/Tabs-xtagjtA5.js.map +1 -0
- package/web-dist/assets/TextArea-CKGHwURx.js +2 -0
- package/web-dist/assets/TextArea-CKGHwURx.js.map +1 -0
- package/web-dist/assets/TextLink-Bub7sMxr.js +2 -0
- package/web-dist/assets/TextLink-Bub7sMxr.js.map +1 -0
- package/web-dist/assets/arrow-down-C-iLrN8I.js +2 -0
- package/web-dist/assets/arrow-down-C-iLrN8I.js.map +1 -0
- package/web-dist/assets/arrow-up-Dj-VTKx4.js +2 -0
- package/web-dist/assets/arrow-up-Dj-VTKx4.js.map +1 -0
- package/web-dist/assets/attention-CI4dHY81.js +2 -0
- package/web-dist/assets/attention-CI4dHY81.js.map +1 -0
- package/web-dist/assets/auth-308hUVgi.js +2 -0
- package/web-dist/assets/auth-308hUVgi.js.map +1 -0
- package/web-dist/assets/automations-BzpsJoa3.js +2 -0
- package/web-dist/assets/automations-BzpsJoa3.js.map +1 -0
- package/web-dist/assets/bell-DSwa2PAb.js +2 -0
- package/web-dist/assets/bell-DSwa2PAb.js.map +1 -0
- package/web-dist/assets/board-CeJxBVHC.js +10 -0
- package/web-dist/assets/board-CeJxBVHC.js.map +1 -0
- package/web-dist/assets/code-DkNQvMI9.js +12 -0
- package/web-dist/assets/code-DkNQvMI9.js.map +1 -0
- package/web-dist/assets/describe-CVXeUClF.js +5 -0
- package/web-dist/assets/describe-CVXeUClF.js.map +1 -0
- package/web-dist/assets/enroll-jnKygG4L.js +2 -0
- package/web-dist/assets/enroll-jnKygG4L.js.map +1 -0
- package/web-dist/assets/index-BHGZTS2e.js +16 -0
- package/web-dist/assets/index-BHGZTS2e.js.map +1 -0
- package/web-dist/assets/index-D2ml031z.css +2 -0
- package/web-dist/assets/logic-B46fwD-8.js +2 -0
- package/web-dist/assets/logic-B46fwD-8.js.map +1 -0
- package/web-dist/assets/more-DvKHMdBk.js +2 -0
- package/web-dist/assets/more-DvKHMdBk.js.map +1 -0
- package/web-dist/assets/queue-B2Vl0uSh.js +2 -0
- package/web-dist/assets/queue-B2Vl0uSh.js.map +1 -0
- package/web-dist/assets/repo-BDS8RBxq.js +2 -0
- package/web-dist/assets/repo-BDS8RBxq.js.map +1 -0
- package/web-dist/assets/server-BqZ-w6M8.js +2 -0
- package/web-dist/assets/server-BqZ-w6M8.js.map +1 -0
- package/web-dist/assets/settings-CLt7x9u8.js +8 -0
- package/web-dist/assets/settings-CLt7x9u8.js.map +1 -0
- package/web-dist/assets/states-C773NlHo.js +56 -0
- package/web-dist/assets/states-C773NlHo.js.map +1 -0
- package/web-dist/assets/terminal-BOV_MXPZ.js +2 -0
- package/web-dist/assets/terminal-BOV_MXPZ.js.map +1 -0
- package/web-dist/assets/terminal-login-BK5UjUir.js +2 -0
- package/web-dist/assets/terminal-login-BK5UjUir.js.map +1 -0
- package/web-dist/assets/useBackTo-BIrCq3W2.js +2 -0
- package/web-dist/assets/useBackTo-BIrCq3W2.js.map +1 -0
- package/web-dist/assets/useBreakpoint-BphHBrzF.js +2 -0
- package/web-dist/assets/useBreakpoint-BphHBrzF.js.map +1 -0
- package/web-dist/assets/useNow-Cm-tdyod.js +2 -0
- package/web-dist/assets/useNow-Cm-tdyod.js.map +1 -0
- package/web-dist/assets/useResource-BBqCoY2q.js +2 -0
- package/web-dist/assets/useResource-BBqCoY2q.js.map +1 -0
- package/web-dist/icon-192.png +0 -0
- package/web-dist/icon-512.png +0 -0
- package/web-dist/icon.svg +20 -8
- package/web-dist/index.html +7 -4
- package/web-dist/manifest.webmanifest +1 -1
- package/web-dist/maskable-512.png +0 -0
- package/web-dist/sw.js +1 -1
- package/web-dist/sw.js.map +1 -1
- package/web-dist/assets/AutomationView-GCthHkym.js +0 -2
- package/web-dist/assets/AutomationView-GCthHkym.js.map +0 -1
- package/web-dist/assets/Badge-CEMI3YyI.js +0 -2
- package/web-dist/assets/Badge-CEMI3YyI.js.map +0 -1
- package/web-dist/assets/InteractionCard-DaLqafmA.js +0 -6
- package/web-dist/assets/InteractionCard-DaLqafmA.js.map +0 -1
- package/web-dist/assets/Menu-BcKiEc6X.js +0 -2
- package/web-dist/assets/Menu-BcKiEc6X.js.map +0 -1
- package/web-dist/assets/Tabs-COH5EMql.js +0 -184
- package/web-dist/assets/Tabs-COH5EMql.js.map +0 -1
- package/web-dist/assets/TextArea-CeMEPZn4.js +0 -2
- package/web-dist/assets/TextArea-CeMEPZn4.js.map +0 -1
- package/web-dist/assets/arrow-left-C6YWM6y6.js +0 -2
- package/web-dist/assets/arrow-left-C6YWM6y6.js.map +0 -1
- package/web-dist/assets/attention-BAdea2kA.js +0 -2
- package/web-dist/assets/attention-BAdea2kA.js.map +0 -1
- package/web-dist/assets/automations-DSFUzB0w.js +0 -2
- package/web-dist/assets/automations-DSFUzB0w.js.map +0 -1
- package/web-dist/assets/board-eQ3H8yCp.js +0 -10
- package/web-dist/assets/board-eQ3H8yCp.js.map +0 -1
- package/web-dist/assets/code-D7JmYMKe.js +0 -13
- package/web-dist/assets/code-D7JmYMKe.js.map +0 -1
- package/web-dist/assets/copy-oWgGHmkS.js +0 -2
- package/web-dist/assets/copy-oWgGHmkS.js.map +0 -1
- package/web-dist/assets/describe-C1YimBXJ.js +0 -5
- package/web-dist/assets/describe-C1YimBXJ.js.map +0 -1
- package/web-dist/assets/dist-B_RpNOcK.js +0 -56
- package/web-dist/assets/dist-B_RpNOcK.js.map +0 -1
- package/web-dist/assets/enroll-1OCy5r50.js +0 -2
- package/web-dist/assets/enroll-1OCy5r50.js.map +0 -1
- package/web-dist/assets/index-BhpEXLav.js +0 -11
- package/web-dist/assets/index-BhpEXLav.js.map +0 -1
- package/web-dist/assets/index-DUeOwDZ6.css +0 -2
- package/web-dist/assets/logic-CBvFOyIo.js +0 -2
- package/web-dist/assets/logic-CBvFOyIo.js.map +0 -1
- package/web-dist/assets/more-RjVyxPaz.js +0 -2
- package/web-dist/assets/more-RjVyxPaz.js.map +0 -1
- package/web-dist/assets/now-CDjeFSLD.js +0 -2
- package/web-dist/assets/now-CDjeFSLD.js.map +0 -1
- package/web-dist/assets/plus-BLP-wIYD.js +0 -2
- package/web-dist/assets/plus-BLP-wIYD.js.map +0 -1
- package/web-dist/assets/save-DEvZPWlS.js +0 -2
- package/web-dist/assets/save-DEvZPWlS.js.map +0 -1
- package/web-dist/assets/search-C6cn5WOo.js +0 -2
- package/web-dist/assets/search-C6cn5WOo.js.map +0 -1
- package/web-dist/assets/send-BKjswHxB.js +0 -2
- package/web-dist/assets/send-BKjswHxB.js.map +0 -1
- package/web-dist/assets/server-SxFxIScj.js +0 -2
- package/web-dist/assets/server-SxFxIScj.js.map +0 -1
- package/web-dist/assets/settings-tH4UuIfJ.js +0 -7
- package/web-dist/assets/settings-tH4UuIfJ.js.map +0 -1
- package/web-dist/assets/shared-CRX6KSBm.js +0 -3
- package/web-dist/assets/shared-CRX6KSBm.js.map +0 -1
- package/web-dist/assets/sliders-horizontal-DAoirila.js +0 -2
- package/web-dist/assets/sliders-horizontal-DAoirila.js.map +0 -1
- package/web-dist/assets/states-DXozulGZ.js +0 -2
- package/web-dist/assets/states-DXozulGZ.js.map +0 -1
- package/web-dist/assets/terminal-login-CW2rE50W.js +0 -2
- package/web-dist/assets/terminal-login-CW2rE50W.js.map +0 -1
- package/web-dist/assets/trash-C6X2OLrI.js +0 -2
- package/web-dist/assets/trash-C6X2OLrI.js.map +0 -1
- package/web-dist/assets/useNow-C_B7JgMM.js +0 -2
- package/web-dist/assets/useNow-C_B7JgMM.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import{_ as e,a as t,f as n,i as r,m as i,n as a,o,p as s,t as c,u as l}from"./jsx-runtime-D13aM9HY.js";import{g as u,i as d,l as f,m as p,o as m,p as h,r as g,u as _,y as v}from"./StatusChip-BYuVxYS7.js";import{$ as y,A as b,C as x,F as S,G as C,I as w,M as T,N as E,P as D,Q as O,R as k,T as A,V as ee,W as te,Y as j,Z as ne,_ as M,_t as re,bt as N,c as P,d as F,f as ie,g as I,gt as L,h as R,ht as z,i as B,m as V,n as H,ot as ae,p as oe,t as U,u as se,ut as ce,v as le,vt as W,x as ue,y as de,yt as G,z as K}from"./states-C773NlHo.js";import{n as fe}from"./presence-05bJD5G3.js";import{t as pe}from"./arrow-down-C-iLrN8I.js";import{a as me,i as he,t as ge}from"./Field-Dbg_8KTt.js";import{i as _e,n as ve,r as ye}from"./Copy-D8xhl7eJ.js";import{i as be,n as xe,r as Se,t as Ce}from"./Menu-euseM8yR.js";import{a as we,i as Te,n as Ee,o as De,r as Oe,s as ke,t as Ae}from"./repo-BDS8RBxq.js";import{t as je}from"./chevron-right-evVLS6hq.js";import{a as Me,i as q,l as Ne,s as Pe,t as Fe,u as Ie}from"./useBreakpoint-BphHBrzF.js";import{a as Le,i as Re,n as ze,o as Be,r as Ve,t as He}from"./InteractionCard-Yu5wgLC3.js";import{n as Ue,t as We}from"./pencil-DI8QbCN8.js";import{t as Ge}from"./hand-UPoHamrn.js";import{t as Ke}from"./link-2-CaMlUDRG.js";import{t as qe}from"./play-CjoDg3ws.js";import{i as Je,n as Ye,r as Xe,t as Ze}from"./useBackTo-BIrCq3W2.js";import{n as Qe,t as $e}from"./Checkbox-rDvnQnxc.js";import{t as et}from"./server-BqZ-w6M8.js";import{C as tt,_ as nt,b as rt,d as it,f as at,g as ot,h as st,m as ct,p as lt,u as ut,v as dt,y as ft}from"./index-BHGZTS2e.js";import{a as pt,i as mt,n as ht,o as J,r as gt,t as _t}from"./Overlay-BNPvMjLX.js";import{n as vt,r as yt}from"./TextArea-CKGHwURx.js";import{t as bt}from"./TextLink-Bub7sMxr.js";import{a as xt,n as St,o as Ct,r as wt,s as Tt,t as Et}from"./Tabs-xtagjtA5.js";import{t as Dt}from"./SegmentedControl-D2d-NEr-.js";import{t as Ot}from"./Select-C9L1HKMm.js";var kt=6e5;function At(e,t){return e instanceof Map?e.get(t):e[t]}function jt(e,t,n){if(t.archivedAt!==null)return!1;if(e.sessionIds.includes(t.id))return!0;if(e.mode===`pinned`)return!1;let r=t.projectId??(t.workspaceId?At(n,t.workspaceId)?.projectId:null)??null;return!(e.projectIds!==null&&(r===null||!e.projectIds.includes(r))||e.hostIds!==null&&!e.hostIds.includes(t.hostId))}function Mt(e,t=Date.now()){return e.clients.filter(e=>t-Date.parse(e.lastSeenAt)<kt).sort((e,t)=>e.kind.localeCompare(t.kind)||e.name.localeCompare(t.name))}var Nt={name:`archive-restore`,size:24,node:[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h2`,key:`tvwodi`}],[`path`,{d:`M20 8v11a2 2 0 0 1-2 2h-2`,key:`1gkqxj`}],[`path`,{d:`m9 15 3-3 3 3`,key:`1pd0qc`}],[`path`,{d:`M12 12v9`,key:`192myk`}]]};Nt.node;var Pt=a(Nt),Ft={name:`archive`,size:24,node:[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]};Ft.node;var It=a(Ft),Lt={name:`arrow-up-right`,size:24,node:[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]};Lt.node;var Rt=a(Lt),zt={name:`bot`,size:24,node:[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]};zt.node;var Bt=a(zt),Vt={name:`brain`,size:24,node:[[`path`,{d:`M12 18V5`,key:`adv99a`}],[`path`,{d:`M15 13a4.17 4.17 0 01-3-4 4.17 4.17 0 01-3 4`,key:`5nuw1p`}],[`path`,{d:`M17.707 6.294A3 3 0 1012 5a3 3 0 10-5.707 1.294`,key:`18ldcf`}],[`path`,{d:`M17.996 5.125a4 4 0 012.526 5.77`,key:`1sdu8q`}],[`path`,{d:`M18 18a4 4 0 002-7.465`,key:`7xqqvr`}],[`path`,{d:`M19.967 17.482a4 4 0 11-7.967.517 4 4 0 11-7.967-.517`,key:`t46ysz`}],[`path`,{d:`M6 18a4 4 0 01-2-7.465`,key:`1y2m15`}],[`path`,{d:`M6.004 5.125a4 4 0 00-2.526 5.77`,key:`3cw1ss`}]]};Vt.node;var Ht=a(Vt),Ut={name:`camera`,size:24,node:[[`path`,{d:`M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z`,key:`18u6gg`}],[`circle`,{cx:`12`,cy:`13`,r:`3`,key:`1vg3eu`}]]};Ut.node;var Wt=a(Ut),Gt={name:`chevrons-down-up`,size:24,node:[[`path`,{d:`m7 20 5-5 5 5`,key:`13a0gw`}],[`path`,{d:`m7 4 5 5 5-5`,key:`1kwcof`}]]};Gt.node;var Kt=a(Gt),qt={name:`chevrons-up-down`,size:24,node:[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]};qt.node;var Jt=a(qt),Yt={name:`circle`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]};Yt.node;var Xt=a(Yt),Zt={name:`cpu`,size:24,node:[[`path`,{d:`M12 20v2`,key:`1lh1kg`}],[`path`,{d:`M12 2v2`,key:`tus03m`}],[`path`,{d:`M17 20v2`,key:`1rnc9c`}],[`path`,{d:`M17 2v2`,key:`11trls`}],[`path`,{d:`M2 12h2`,key:`1t8f8n`}],[`path`,{d:`M2 17h2`,key:`7oei6x`}],[`path`,{d:`M2 7h2`,key:`asdhe0`}],[`path`,{d:`M20 12h2`,key:`1q8mjw`}],[`path`,{d:`M20 17h2`,key:`1fpfkl`}],[`path`,{d:`M20 7h2`,key:`1o8tra`}],[`path`,{d:`M7 20v2`,key:`4gnj0m`}],[`path`,{d:`M7 2v2`,key:`1i4yhu`}],[`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`2`,key:`1vbyd7`}],[`rect`,{x:`8`,y:`8`,width:`8`,height:`8`,rx:`1`,key:`z9xiuo`}]]};Zt.node;var Qt=a(Zt),$t={name:`crop`,size:24,node:[[`path`,{d:`M6 2v14a2 2 0 0 0 2 2h14`,key:`ron5a4`}],[`path`,{d:`M18 22V8a2 2 0 0 0-2-2H2`,key:`7s9ehn`}]]};$t.node;var en=a($t),tn={name:`ellipsis-vertical`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]],aliases:[`more-vertical`]};tn.node;var nn=a(tn),rn={name:`file-braces`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1`,key:`1oajmo`}],[`path`,{d:`M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1`,key:`mpwhp6`}]],aliases:[`file-json`]};rn.node;var an=a(rn),on={name:`file-diff`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M9 10h6`,key:`9gxzsh`}],[`path`,{d:`M12 13V7`,key:`h0r20n`}],[`path`,{d:`M9 17h6`,key:`r8uit2`}]]};on.node;var sn=a(on),cn={name:`file-image`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`circle`,{cx:`10`,cy:`12`,r:`2`,key:`737tya`}],[`path`,{d:`m20 17-1.296-1.296a2.41 2.41 0 0 0-3.408 0L9 22`,key:`wt3hpn`}]]};cn.node;var ln=a(cn),un={name:`file-text`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M10 9H8`,key:`b1mrlr`}],[`path`,{d:`M16 13H8`,key:`t4e002`}],[`path`,{d:`M16 17H8`,key:`z1uh3a`}]]};un.node;var dn=a(un),fn={name:`file`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}]]};fn.node;var pn=a(fn),mn={name:`folder-open`,size:24,node:[[`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2`,key:`usdka0`}]]};mn.node;var hn=a(mn),gn={name:`folder`,size:24,node:[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]};gn.node;var _n=a(gn),vn={name:`image-plus`,size:24,node:[[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5`,key:`1ue2ih`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]};vn.node;var yn=a(vn),bn={name:`list-plus`,size:24,node:[[`path`,{d:`M16 5H3`,key:`m91uny`}],[`path`,{d:`M11 12H3`,key:`51ecnj`}],[`path`,{d:`M16 19H3`,key:`zzsher`}],[`path`,{d:`M18 9v6`,key:`1twb98`}],[`path`,{d:`M21 12h-6`,key:`bt1uis`}]]};bn.node;var xn=a(bn),Sn={name:`message-square-plus`,size:24,node:[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]};Sn.node;var Cn=a(Sn),wn={name:`mic-off`,size:24,node:[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M15 9.34V5a3 3 0 0 0-5.68-1.33`,key:`1gzdoj`}],[`path`,{d:`M16.95 16.95A7 7 0 0 1 5 12v-2`,key:`cqa7eg`}],[`path`,{d:`M18.89 13.23A7 7 0 0 0 19 12v-2`,key:`16hl24`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v3a3 3 0 0 0 5.12 2.12`,key:`r2i35w`}]]};wn.node;var Tn=a(wn),En={name:`mic`,size:24,node:[[`path`,{d:`M12 19v3`,key:`npa21l`}],[`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`,key:`1vc78b`}],[`rect`,{x:`9`,y:`2`,width:`6`,height:`13`,rx:`3`,key:`s6n7sd`}]]};En.node;var Dn=a(En),On={name:`mouse-pointer-click`,size:24,node:[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]};On.node;var kn=a(On),An={name:`navigation`,size:24,node:[[`polygon`,{points:`3 11 22 2 13 21 11 13 3 11`,key:`1ltx0t`}]]};An.node;var jn=a(An),Mn={name:`network`,size:24,node:[[`rect`,{x:`16`,y:`16`,width:`6`,height:`6`,rx:`1`,key:`4q2zg0`}],[`rect`,{x:`2`,y:`16`,width:`6`,height:`6`,rx:`1`,key:`8cvhb9`}],[`rect`,{x:`9`,y:`2`,width:`6`,height:`6`,rx:`1`,key:`1egb70`}],[`path`,{d:`M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3`,key:`1jsf9p`}],[`path`,{d:`M12 12V8`,key:`2874zd`}]]};Mn.node;var Nn=a(Mn),Pn={name:`panel-right-close`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m8 9 3 3-3 3`,key:`12hl5m`}]]};Pn.node;var Fn=a(Pn),In={name:`paperclip`,size:24,node:[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]};In.node;var Ln=a(In),Rn={name:`redo-2`,size:24,node:[[`path`,{d:`m15 14 5-5-5-5`,key:`12vg1m`}],[`path`,{d:`M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13`,key:`6uklza`}]]};Rn.node;var zn=a(Rn),Bn={name:`search-x`,size:24,node:[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]};Bn.node;var Vn=a(Bn),Hn={name:`send-horizontal`,size:24,node:[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]],aliases:[`send-horizonal`]};Hn.node;var Un=a(Hn),Wn={name:`shrink`,size:24,node:[[`path`,{d:`m15 15 6 6m-6-6v4.8m0-4.8h4.8`,key:`17vawe`}],[`path`,{d:`M9 19.8V15m0 0H4.2M9 15l-6 6`,key:`chjx8e`}],[`path`,{d:`M15 4.2V9m0 0h4.8M15 9l6-6`,key:`lav6yq`}],[`path`,{d:`M9 4.2V9m0 0H4.2M9 9 3 3`,key:`1pxi2q`}]]};Wn.node;var Gn=a(Wn),Kn={name:`slash`,size:24,node:[[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}]]};Kn.node;var qn=a(Kn),Jn={name:`text-wrap`,size:24,node:[[`path`,{d:`m16 16-3 3 3 3`,key:`117b85`}],[`path`,{d:`M3 12h14.5a1 1 0 0 1 0 7H13`,key:`18xa6z`}],[`path`,{d:`M3 19h6`,key:`1ygdsz`}],[`path`,{d:`M3 5h18`,key:`1u36vt`}]],aliases:[`wrap-text`]};Jn.node;var Yn=a(Jn),Xn={name:`undo-2`,size:24,node:[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]};Xn.node;var Zn=a(Xn),Qn={name:`user`,size:24,node:[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]};Qn.node;var $n=a(Qn),er={name:`wand-sparkles`,size:24,node:[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]],aliases:[`wand-2`]};er.node;var tr=a(er),nr={name:`wrench`,size:24,node:[[`path`,{d:`M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z`,key:`1ngwbx`}]]};nr.node;var rr=a(nr),Y=e(i(),1),X=c();function ir({value:e,min:t,max:n,onChange:r,label:i,pane:a=`before`,step:o=16,onReset:s,className:c}){let l=(0,Y.useRef)(null),u=e=>Math.round(Math.min(n,Math.max(t,e))),d=a===`before`?1:-1;return(0,X.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":i,"aria-valuenow":Math.round(e),"aria-valuemin":t,"aria-valuemax":n,tabIndex:0,className:M(`group relative z-10 w-1.5 shrink-0 cursor-col-resize touch-none select-none`,`focus-visible:outline-none`,c),onPointerDown:t=>{t.preventDefault(),t.currentTarget.setPointerCapture(t.pointerId),l.current={x:t.clientX,value:e}},onPointerMove:e=>{l.current&&r(u(l.current.value+d*(e.clientX-l.current.x)))},onPointerUp:e=>{l.current=null,e.currentTarget.releasePointerCapture(e.pointerId)},onPointerCancel:()=>{l.current=null},onDoubleClick:s,onKeyDown:i=>{let a=i.shiftKey?o*4:o;if(i.key===`ArrowRight`)r(u(e+d*a));else if(i.key===`ArrowLeft`)r(u(e-d*a));else if(i.key===`Home`)r(t);else if(i.key===`End`)r(n);else if(i.key===`Enter`&&s)s();else return;i.preventDefault()},children:(0,X.jsx)(`div`,{"aria-hidden":!0,className:`absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border group-hover:w-0.5 group-hover:bg-accent group-focus-visible:w-0.5 group-focus-visible:bg-accent`})})}var ar=(0,Y.createContext)({mobile:!1}),or=()=>(0,Y.useContext)(ar),Z=e=>`/api/sessions/${encodeURIComponent(e)}`,sr=e=>`/api/workspaces/${encodeURIComponent(e)}`,cr=e=>`/api/tasks/${encodeURIComponent(e)}`,Q={get:(e,t)=>L(Z(e),void 0,t),createSession:e=>W(`/api/sessions`,e),prompt:(e,t)=>W(`${Z(e)}/prompt`,t),models:(e,t)=>L(`${Z(e)}/models`,void 0,t),commands:(e,t)=>L(`${Z(e)}/commands`,void 0,t),tree:e=>L(`${Z(e)}/tree`),branch:(e,t,n)=>W(`${Z(e)}/branch`,{entryId:t,fork:n}),reload:e=>W(`${Z(e)}/reload`),exportFile:e=>L(`${Z(e)}/export`),importable:e=>L(`/api/sessions/importable`,{hostId:e}),importSession:(e,t,n)=>W(`/api/sessions/import`,{hostId:e,sessionFile:t,projectId:n}),complete:(e,t,n)=>W(`${Z(e)}/complete`,{text:t},n),setModel:(e,t,n)=>W(`${Z(e)}/model`,{provider:t,modelId:n}),setThinking:(e,t)=>W(`${Z(e)}/thinking`,{level:t}),compact:(e,t)=>W(`${Z(e)}/compact`,t?{instructions:t}:{}),abort:(e,t=!1)=>W(`${Z(e)}/abort`,{clearQueue:t}),stop:e=>W(`${Z(e)}/stop`),resume:e=>W(`${Z(e)}/resume`),takeover:e=>W(`${Z(e)}/takeover`),returnToAutomation:e=>W(`${Z(e)}/return-to-automation`),rename:(e,t)=>W(`${Z(e)}/rename`,{title:t}),archive:e=>W(`${Z(e)}/archive`),unarchive:e=>W(`${Z(e)}/unarchive`),adapterAction:(e,t,n,r)=>W(`${Z(e)}/adapter-action`,{adapterId:t,actionId:n,payload:r}),diff:(e,t,n)=>L(`${sr(e)}/diff`,t?{file:t}:void 0,n),files:async(e,t,n)=>lr(await L(`${sr(e)}/files`,{dir:t},n)),file:async(e,t,n)=>ur(await L(`${sr(e)}/file`,{path:t},n)),refreshWorkspace:e=>W(`${sr(e)}/refresh`),requestChanges:(e,t)=>W(`${cr(e)}/request-changes`,{feedback:t}),accept:(e,t)=>W(`${cr(e)}/accept`,t?{confirm:!0}:{})};function lr(e){let t=Array.isArray(e)?e:e?.entries??e?.files??[];return Array.isArray(t)?t.filter(e=>e&&typeof e.name==`string`).sort((e,t)=>(e.kind===`dir`?0:1)-(t.kind===`dir`?0:1)||e.name.localeCompare(t.name)):[]}function ur(e){if(typeof e==`string`)return{text:e,binary:!1,truncated:!1,size:null,base64:null};let t=e??{},n=typeof t.content==`string`?t.content:typeof t.text==`string`?t.text:null;return{text:n,binary:t.binary===!0||n===null&&t.encoding===`base64`,truncated:t.truncated===!0,size:typeof t.size==`number`?t.size:null,base64:t.encoding===`base64`&&typeof t.content==`string`?t.content:null}}function dr(e){return C(e.runtime)}function fr(e){return te(e.runtime)}function pr(e){return e.replaceAll(`/`,`-`)}function mr(e,t,n=ae){return`${e.replace(/\/+$/,``)}/${n}/${pr(t.trim())}`}function hr(e){let t=e.trim();return t?/\s/.test(t)?`Branch names cannot contain spaces.`:t.startsWith(`-`)?`Branch names cannot start with '-'.`:t.startsWith(`/`)||t.endsWith(`/`)?`Branch names cannot start or end with '/'.`:t.includes(`..`)?`Branch names cannot contain '..'.`:t.includes(`//`)?`Branch names cannot contain '//'.`:t.endsWith(`.lock`)||t.endsWith(`.`)?`Branch names cannot end with '.lock' or '.'.`:[...t].some(e=>e.charCodeAt(0)<32||e.charCodeAt(0)===127)||/[~^:?*[\\]/.test(t)||t.includes(`@{`)?`Branch names cannot contain ~ ^ : ? * [ \\ or '@{'.`:null:`Enter a branch name.`}function gr(e){return!!e&&!e.revokedAt&&e.connectivity===`connected`}function _r(e,t){return(e.provenance===`main`?0:1)-(t.provenance===`main`?0:1)||(e.branch??``).localeCompare(t.branch??``)}function vr(e,t=new Date){let n=e.normalize(`NFKD`).replace(/[\u0300-\u036f]/g,``).toLowerCase().replace(/[^a-z0-9]+/g,` `).trim().split(` `).filter(Boolean).slice(0,5).join(`-`).slice(0,40).replace(/-+$/,``);if(n)return n;let r=e=>String(e).padStart(2,`0`);return`session-${r(t.getMonth()+1)}${r(t.getDate())}-${r(t.getHours())}${r(t.getMinutes())}`}function yr(e,t){let n=new Set([...t].filter(e=>!!e));if(!n.has(e))return e;for(let t=2;;t++)if(!n.has(`${e}-${t}`))return`${e}-${t}`}function br(e){let t=/(?:^|\/)p:([^/]+)$/.exec(e);return t&&t[1]!==`__none`?t[1]:null}function xr(e,t,n,r,i){let a=[...new Set(t.map(e=>e.hostId))],o=e.defaultHostId,s=(i&&a.includes(i)?i:void 0)??(o&&a.includes(o)&&gr(r[o])?o:void 0)??a.find(e=>gr(r[e]))??a[0]??``,c=n.find(e=>e.hostId===s&&!e.archivedAt&&e.provenance===`main`)??null,l=t.filter(e=>e.hostId===s),u=l.find(e=>e.id===c?.checkoutId)??l[0]??null;return{hostId:s,workspaceId:c?.id??null,checkoutId:u?.id??null}}var Sr=[{value:`projects`,label:`Projects`,hint:`Sessions under each project`},{value:`worktrees`,label:`Worktrees`,hint:`Project, then branch or worktree`},{value:`recent`,label:`Recent`,hint:`One list of every session`},{value:`hosts`,label:`Hosts`,hint:`Host, then project`},{value:`status`,label:`Status`,hint:`Grouped by what needs you`}],Cr=[{value:`activity`,label:`Recent activity`,hint:`Latest activity first`},{value:`created`,label:`Newest`,hint:`Most recently started first`},{value:`name`,label:`Name`,hint:`A to Z`},{value:`status`,label:`Status`,hint:`Waiting and running first`}],wr={projects:`name`,worktrees:`activity`,recent:`activity`,hosts:`name`,status:`activity`},Tr=[{value:`needs_input`,label:`Needs input`,short:`needs you`},{value:`failed`,label:`Failed`,short:`failed`},{value:`running`,label:`Working`,short:`working`},{value:`review`,label:`Ready to review`,short:`to review`},{value:`idle`,label:`Idle`,short:`idle`}],Er={needs_input:0,failed:1,running:2,review:3,idle:4};function Dr(e,t){return t||e.runtime===`waiting_input`?`needs_input`:e.runtime===`failed`&&e.unreadSince?`failed`:e.runtime===`running`||e.runtime===`starting`||e.compacting?`running`:e.unreadSince?`review`:`idle`}function Or(e){let t=[];for(let n of Tr){if(n.value===`idle`)continue;let r=0,i=``,a=``;for(let t of e)t.bucket===n.value&&(r+=1,t.session.lastActivityAt>=a&&(a=t.session.lastActivityAt,i=t.session.id));r>0&&t.push({bucket:n.value,count:r,first:i,at:a})}return t.map(({at:e,...t})=>t)}function kr(e){return e.replace(/\/+$/,``).split(`/`).pop()||e}function Ar(e,t){return e?e.branch?e.branch:`${kr(e.path)} (detached)`:t?kr(t):`No workspace`}function jr(e,t,n,r={}){return{key:e,kind:t,label:n,detail:null,path:null,hostState:null,groups:[],rows:[],sessionCount:0,...r}}function Mr(e,t){return t?.name??(e?`Unknown project`:`Other sessions`)}function Nr(e){return e.ws?e.ws.provenance===`main`?null:Ar(e.ws):e.projectId===null?kr(e.session.cwd):null}function Pr(e){let t=``;for(let n of e.rows)n.session.lastActivityAt>t&&(t=n.session.lastActivityAt);for(let n of e.groups){let e=Pr(n);e>t&&(t=e)}return t}function Fr(e){let t=``;for(let n of e.rows)n.session.createdAt>t&&(t=n.session.createdAt);for(let n of e.groups){let e=Fr(n);e>t&&(t=e)}return t}function Ir(e,t){let n=e=>e.key.endsWith(`__none`)||e.kind===`host`&&e.label===`Unknown host`?1:0,r=e=>t===`activity`?Pr(e):t===`created`?Fr(e):``;return e.sort((e,t)=>n(e)-n(t)||r(t).localeCompare(r(e))||e.label.localeCompare(t.label))}function Lr(e){return e.sessionCount=e.rows.length+e.groups.reduce((e,t)=>e+Lr(t),0),e.sessionCount}function Rr(e,t){let n=t.layout??`projects`,r=t.sort??wr[n],i=t.needsInputFirst??!0,a=t.query.trim().toLowerCase(),o=j(e.attention,e.interactions),s=[];for(let n of Object.values(e.sessions)){if(n.archivedAt!==null||n.provenance===`subagent`&&!t.showSubagents||t.view&&!jt(t.view,n,e.workspaces))continue;let r=o.has(n.id);if(t.filter===`active`&&!dr(n)&&!r||t.filter===`attention`&&!r)continue;let i=n.workspaceId?e.workspaces[n.workspaceId]??null:null,c=n.projectId??i?.projectId??null,l=c?e.projects[c]??null:null,u=i?.hostId??n.hostId,d=e.hosts[u]?.name??`Unknown host`;(!a||[n.title,n.subtitle??``,i?.branch??``,l?.name??``,d,n.cwd].join(`
|
|
2
|
+
`).toLowerCase().includes(a))&&s.push({session:n,attention:r,bucket:Dr(n,r),ws:i,projectId:c,project:l,hostId:u,hostName:d})}let c=(e,t)=>t.session.lastActivityAt.localeCompare(e.session.lastActivityAt);s.sort((e,t)=>{if(i&&e.attention!==t.attention)return Number(t.attention)-Number(e.attention);switch(r){case`created`:return t.session.createdAt.localeCompare(e.session.createdAt)||c(e,t);case`name`:return e.session.title.localeCompare(t.session.title,void 0,{numeric:!0,sensitivity:`base`})||c(e,t);case`status`:return Er[e.bucket]-Er[t.bucket]||c(e,t);default:return c(e,t)}});let l=(e,t)=>({session:e.session,attention:e.attention,bucket:e.bucket,...t});if(n===`status`){let e=[];for(let t of Tr){let n=jr(`s:${t.value}`,`status`,t.label);for(let e of s)e.bucket===t.value&&n.rows.push(l(e,{project:Mr(e.projectId,e.project),host:e.hostName,branch:Nr(e)}));n.rows.length>0&&(Lr(n),e.push(n))}return{groups:e,rows:[]}}if(n===`recent`)return{groups:[],rows:s.map(e=>l(e,{project:Mr(e.projectId,e.project),host:e.hostName,branch:Nr(e)}))};if(n===`hosts`){let t=new Map;for(let n of s){let r=t.get(n.hostId);if(!r){let i=e.hosts[n.hostId];r=jr(`h:${n.hostId}`,`host`,n.hostName,{hostState:i?i.revokedAt?`unreachable`:i.connectivity:`unreachable`}),t.set(n.hostId,r)}let i=`${r.key}/p:${n.projectId??`__none`}`,a=r.groups.find(e=>e.key===i);a||(a=jr(i,`project`,Mr(n.projectId,n.project)),r.groups.push(a)),a.rows.push(l(n,{project:null,host:null,branch:Nr(n)}))}let n=Ir([...t.values()],r);for(let e of n)Ir(e.groups,r),Lr(e);return{groups:n,rows:[]}}let u=new Map,d=t=>{let n=`p:${t??`__none`}`,r=u.get(n);return r||(r=jr(n,`project`,Mr(t,t?e.projects[t]??null:null)),u.set(n,r)),r};if(n===`projects`){let e=new Map;for(let t of s){let n=d(t.projectId);n.rows.push(l(t,{project:null,host:t.hostName,branch:Nr(t)}));let r=e.get(n)??new Set;r.add(t.hostId),e.set(n,r)}for(let[t,n]of e)if(n.size===1){t.detail=t.rows[0].host;for(let e of t.rows)e.host=null}let t=Ir([...u.values()],r);for(let e of t)Lr(e);return{groups:t,rows:[]}}let f=new Map,p=new Map,m=(t,n,r,i)=>{let a=n?`w:${n.id}`:`w:${t.key}:cwd:${r}:${i}`,o=f.get(a);return o||(o=jr(a,`workspace`,Ar(n,i),{detail:e.hosts[r]?.name??`Unknown host`,path:n?.path??null}),f.set(a,o),p.set(o,n),t.groups.push(o)),o};for(let e of s)m(d(e.projectId),e.ws,e.hostId,e.session.cwd).rows.push(l(e,{project:null,host:null,branch:null}));if(t.filter===`all`){let t=new Set(s.map(e=>e.projectId));for(let n of Object.values(e.workspaces)){if(n.archivedAt||!t.has(n.projectId))continue;let r=e.projects[n.projectId]??null;(!a||[n.branch??``,r?.name??``,n.path].join(`
|
|
3
|
+
`).toLowerCase().includes(a))&&m(d(n.projectId),n,n.hostId,n.path)}}let h=Ir([...u.values()],r);for(let e of h){e.groups.sort((e,t)=>{if(r===`activity`||r===`created`){let n=r===`activity`?Pr(e):Fr(e),i=r===`activity`?Pr(t):Fr(t);if(n!==i)return i.localeCompare(n)}return(p.get(e)?.provenance===`main`?0:1)-(p.get(t)?.provenance===`main`?0:1)||e.label.localeCompare(t.label)});let t=e.groups.length===1?e.groups[0]:null;t&&(t.path===null||p.get(t)?.provenance===`main`)&&(e.rows=t.rows,e.detail=t.detail,e.groups=[]),Lr(e)}return{groups:h,rows:[]}}function zr(e){return e.rows.length===0&&e.groups.every(e=>e.sessionCount===0&&e.groups.length===0)}function Br(e){let t=[],n=e=>{for(let r of e)t.push(r.key),n(r.groups)};return n(e.groups),t}var Vr=[`queued`,`dispatching`,`uncertain`,`running`,`waiting_input`,`checking`];function Hr(e,t){if(t.runId&&e[t.runId])return e[t.runId];let n=null;for(let r of Object.values(e))r.sessionId===t.id&&Vr.includes(r.state)&&(!n||r.createdAt>n.createdAt)&&(n=r);return n}function Ur(e){return e?e.controlMode:`none`}var Wr={automation:`Automation`,human:`You have control`,none:`Manual session`};function Gr(e,t){return e?.revokedAt?`unreachable`:e?.connectivity??t.connectivity}var Kr=`Subagent: view only. Live control is not supported.`;function qr(e){return e.provenance===`subagent`&&e.readOnly}function Jr(e){let{session:t,hostLink:n}=e;return t.readOnly?{reason:Kr}:t.archivedAt?{reason:`Session archived: unarchive it to send`}:n===`connected`?t.runtime===`starting`?{reason:`Starting… you can send once Pi is ready`,pending:!0}:!dr(t)&&!t.nativeHandle?{reason:`Session stopped: no native Pi session to resume`}:t.compacting?{reason:`Compacting context: you can send when it finishes`}:null:{reason:n===`reconnecting`?`Host offline: ${e.hostName} is reconnecting`:`Host offline: ${e.hostName} is unreachable`}}function Yr(e){let{session:t,hostLink:n,hostName:r,pending:i}=e,a=e.canResume?{kind:`resume`,label:`Resume`}:null;if(t.readOnly)return{kind:`subagent`,tone:`neutral`,text:Kr,action:null};if(t.archivedAt)return{kind:`archived`,tone:`neutral`,text:`This session is archived. Unarchive it to send messages.`,action:{kind:`unarchive`,label:`Unarchive`}};if(n!==`connected`){let t=e.hostLastSeenAt?Date.parse(e.hostLastSeenAt):NaN,i=n===`unreachable`&&(!Number.isFinite(t)||e.now-t>3e5);return n===`reconnecting`?{kind:`host`,tone:`warning`,pending:!0,text:`Host ${r} is reconnecting… Sending and answers resume when it is back.`,action:null}:{kind:`host`,tone:i?`danger`:`warning`,text:`Host ${r} is offline. Showing the last known transcript; sending resumes when it reconnects.`,action:null}}return i.length>0?{kind:`answer`,tone:`warning`,text:i.length===1?`Needs input: ${i[0].title}`:`${i.length} questions need input`,action:{kind:`answer`,label:`Answer`}}:t.runtime===`failed`?{kind:`failed`,tone:`danger`,text:`This session failed: ${t.runtimeDetail??`Pi exited with an error.`}`,action:a,link:{label:`Diagnostics`,to:`/settings/diagnostics`}}:t.runtime===`interrupted`?{kind:`interrupted`,tone:`neutral`,text:t.runtimeDetail?`Interrupted: ${t.runtimeDetail}`:`Interrupted. Resume to continue.`,action:a}:t.runtime===`stopped`?t.nativeHandle?{kind:`stopped`,tone:`neutral`,text:`Stopped. Sending a message resumes it.`,action:a}:{kind:`stopped`,tone:`neutral`,text:`Stopped: no native Pi session to resume.`,action:null}:t.runtime===`starting`?{kind:`starting`,tone:`info`,pending:!0,text:`Starting Pi… you can send once it is ready.`,action:null}:t.compacting?{kind:`compacting`,tone:`info`,pending:!0,text:`Compacting context… you can send when it finishes.`,action:null}:e.control===`automation`?{kind:`automation`,tone:`info`,text:`Automation is running this session. Take over to pause automatic continuations.`,action:{kind:`takeover`,label:`Take over`}}:e.control===`human`?{kind:`human`,tone:`neutral`,text:`You have control. Automatic continuations are paused.`,action:{kind:`return`,label:`Return to automation`}}:null}function Xr(e,t){return fr(e)?{prompt:!1,steer:t?.steer===!0,followUp:!t||t.followUp}:{prompt:!0,steer:!1,followUp:!1}}function Zr(e,t,n){let r=new Map(t.map(e=>[e.itemId,e])),i=[],a=new Set;for(let t of e){let e=r.get(t.id)??null;e&&r.delete(t.id),t.kind===`interaction`&&a.add(t.data.interactionId);let n=i[i.length-1];t.kind===`notice`&&!e&&n?.type===`item`&&n.item.kind===`notice`&&n.item.data.level===t.data.level&&n.item.data.text===t.data.text?i[i.length-1]={...n,repeat:(n.repeat??1)+1}:i.push({type:`item`,key:t.id,item:t,stream:e})}let o=[...r.values()].sort((e,t)=>(e.order??2**53-1)-(t.order??2**53-1));for(let e of o)(e.text||e.thinking||e.toolArgs||e.toolOutput)&&i.push({type:`stream`,key:`stream:${e.itemId}`,stream:e});for(let e of n)a.has(e.id)||i.push({type:`interaction`,key:`interaction:${e.id}`,interaction:e});return i}function Qr(e){return e.type===`item`&&e.item.kind===`tool`}function $r(e,t){let n={durationMs:null,edits:0,reads:0,commands:0,searches:0,other:0,thinking:0,failed:0},r=null,i=null;for(let t of e){if(t.type!==`item`)continue;let e=t.item;if(e.kind===`thinking`&&(n.thinking+=1),e.kind===`tool`){let t=e.data;switch(t.status===`error`&&(n.failed+=1),t.name){case`edit`:case`write`:n.edits+=1;break;case`read`:n.reads+=1;break;case`bash`:case`powershell`:n.commands+=1;break;case`grep`:case`find`:case`ls`:n.searches+=1;break;default:n.other+=1}t.durationMs!==null&&t.durationMs!==void 0&&(r=(r??0)+t.durationMs);let a=Date.parse(t.startedAt),o=Number.isNaN(a)?Date.parse(e.at):a+(t.durationMs??0);Number.isNaN(o)||(i=Math.max(i??o,o))}else{let t=Date.parse(e.at);Number.isNaN(t)||(i=Math.max(i??t,t))}}let a=t?Date.parse(t):NaN;return n.durationMs=!Number.isNaN(a)&&i!==null?Math.max(0,i-a):r,n}function ei(e,t,n){return`${e} ${e===1?t:n}`}function ti(e){let t=V(e.durationMs),n=[t?`Worked ${t}`:`Worked`];return e.edits&&n.push(ei(e.edits,`edit`,`edits`)),e.reads&&n.push(ei(e.reads,`read`,`reads`)),e.commands&&n.push(ei(e.commands,`command`,`commands`)),e.searches&&n.push(ei(e.searches,`search`,`searches`)),e.other&&n.push(`${e.other} other`),e.failed&&n.push(`${e.failed} failed`),n.join(` · `)}function ni(e,t){return t?!0:e.some(e=>e.type===`stream`||e.type===`item`&&(e.stream!==null||e.item.kind===`tool`&&e.item.data.status===`running`||e.item.kind===`assistant`&&e.item.data.streaming===!0))}function ri(e,t){let n=[];for(let t of e)n.length===0||t.type===`item`&&t.item.kind===`user`?n.push([t]):n[n.length-1]?.push(t);let r=[];return n.forEach((e,i)=>{let a=e[0],o=a?.type===`item`&&a.item.kind===`user`;if(i===n.length-1&&ni(e,t)){r.push(...e);return}let s=-1;e.forEach((e,t)=>{e.type===`item`&&e.item.kind===`assistant`&&(s=t)});let c=new Set;e.forEach((e,t)=>{if(e.type!==`item`)return;let n=e.item.kind;(n===`tool`||n===`thinking`||n===`assistant`&&t!==s)&&c.add(t)});let l=e.filter((e,t)=>c.has(t));if(!l.some(Qr)){r.push(...e);return}let u=o&&a?.type===`item`?a.item.at:null,d=!1;e.forEach((e,t)=>{c.has(t)?d||(d=!0,r.push({type:`work`,key:`work:${e.key}`,entries:l,summary:$r(l,u)})):r.push(e)})}),r}function ii(e,t){let n=e.model?.provider,r=n===`anthropic`?`anthropic`:n===`openai-codex`?`openai-codex`:null;return r?t?.usage?.find(e=>e.provider===r)??null:null}function ai(e){return e>=90?`danger`:e>=70?`warning`:`neutral`}function oi(e,t){if(t===null)return e.length;let n=e.findIndex(e=>e.key===t);return n<0?0:e.length-n-1}function si(e){return`interaction-${e}`}function ci(e){let t=/^data:([^;,]+)?(;base64)?,(.*)$/s.exec(e);return t?.[2]?{mimeType:t[1]??`application/octet-stream`,data:t[3]??``}:null}function li(e){return new Promise((t,n)=>{if(!e.type.startsWith(`image/`)){n(Error(`${e.name} is not an image`));return}if(e.size>10485760){n(Error(`${e.name} is larger than 10 MB`));return}let r=new FileReader;r.onerror=()=>n(r.error??Error(`Could not read ${e.name}`)),r.onload=()=>{let i=ci(String(r.result??``));i?t({id:`att_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`,name:e.name,mimeType:i.mimeType||e.type,data:i.data,size:e.size}):n(Error(`Could not read ${e.name}`))},r.readAsDataURL(e)})}function ui(e){if(e==null)return``;if(typeof e==`string`)return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function di(e,t=6){let n=e.replace(/\n+$/,``).split(`
|
|
4
|
+
`);if(n.length<=t&&e.length<=600)return{text:e,truncated:!1};let r=n.slice(-t).join(`
|
|
5
|
+
`);return{text:r.length>600?r.slice(-600):r,truncated:!0}}var fi=6;function pi(e,t,n){if(e<=0)return{nav:t,insp:n};let r=n===null?fi:12,i=t+(n??0)+r+420-e,a=n,o=t;if(i>0&&a!==null){let e=Math.min(i,a-dt.inspector.min);a-=e,i-=e}if(i>0){let e=Math.min(i,o-dt.navigator.min);o-=e}return{nav:o,insp:a}}var mi=[{name:`model`,description:`Switch this session's model`,source:`switchyard`,argumentHint:`<provider>/<model>`},{name:`thinking`,description:`Set the effort (thinking level)`,source:`switchyard`,argumentHint:`<level>`},{name:`compact`,description:`Compact the session context`,source:`switchyard`,argumentHint:`[instructions]`},{name:`name`,description:`Rename this session`,source:`switchyard`,argumentHint:`<name>`},{name:`new`,description:`Start a new session in this workspace`,source:`switchyard`,argumentHint:`[prompt]`},{name:`fork`,description:`Start a new session from one of your messages`,source:`switchyard`,argumentHint:null},{name:`clone`,description:`Copy this conversation into a new session`,source:`switchyard`,argumentHint:null},{name:`tree`,description:`Start a new session from any point in the conversation tree`,source:`switchyard`,argumentHint:null},{name:`resume`,description:`Open another Pi session from this folder`,source:`switchyard`,argumentHint:null},{name:`reload`,description:`Reload extensions, skills, prompts and context files`,source:`switchyard`,argumentHint:null},{name:`export`,description:`Download this session's .jsonl file`,source:`switchyard`,argumentHint:null},{name:`session`,description:`Show session info and stats`,source:`switchyard`,argumentHint:null},{name:`copy`,description:`Copy the last reply to the clipboard`,source:`switchyard`,argumentHint:null}],hi=[{name:`settings`,description:`Open settings menu`,source:`terminal`,argumentHint:null},{name:`scoped-models`,description:`Enable/disable models for Ctrl+P cycling`,source:`terminal`,argumentHint:null},{name:`import`,description:`Import and resume a session from a JSONL file`,source:`terminal`,argumentHint:null},{name:`share`,description:`Share session via a Radius artifact or a GitHub gist`,source:`terminal`,argumentHint:null},{name:`bug`,description:`Report a bug to the Pi developers`,source:`terminal`,argumentHint:`<description>`},{name:`changelog`,description:`Show changelog entries`,source:`terminal`,argumentHint:null},{name:`hotkeys`,description:`Show all keyboard shortcuts`,source:`terminal`,argumentHint:null},{name:`trust`,description:`Save project trust decision for future sessions`,source:`terminal`,argumentHint:null},{name:`login`,description:`Configure provider authentication`,source:`terminal`,argumentHint:`<provider>`},{name:`logout`,description:`Remove provider authentication`,source:`terminal`,argumentHint:null},{name:`quit`,description:`Quit Pi`,source:`terminal`,argumentHint:null}],gi=hi.map(e=>e.name),_i={extension:0,prompt:1,skill:2};function vi(e,t){let n=new Set([...e.map(e=>e.name),...t.map(e=>e.name)]),r=hi.filter(e=>!n.has(e.name)).sort((e,t)=>e.name.localeCompare(t.name)),i=new Set(e.map(e=>e.name)),a=t.filter(e=>!i.has(e.name)).map(e=>({name:e.name,description:e.description,source:e.source,argumentHint:e.argumentHint??null})).sort((e,t)=>(_i[e.source]??9)-(_i[t.source]??9)||e.name.localeCompare(t.name));return[...e,...a,...r]}function yi(e){return!e.includes(`
|
|
6
|
+
`)&&e.length<=500&&/^\/\S+ /.test(e)}function bi(e,t,n){return e.endsWith(t)?e.slice(0,e.length-t.length)+n+(n.endsWith(` `)?``:` `):e}function xi(e,t){if(e.includes(`
|
|
7
|
+
`))return null;let n=/^\/(\S+)[ \t]/.exec(e);if(!n)return null;let r=t.find(e=>e.name===n[1]);return r?.argumentHint?{name:r.name,hint:r.argumentHint}:null}function Si(e,t,n=50){let r=t.toLowerCase();if(!r)return e.slice(0,n);let i=[];return e.forEach((e,t)=>{let n=e.name.toLowerCase(),a=n.startsWith(r)?0:n.includes(r)?1:(e.description??``).toLowerCase().includes(r)?2:-1;a>=0&&i.push({e,score:a,i:t})}),i.sort((e,t)=>e.score-t.score||e.i-t.i),i.slice(0,n).map(e=>e.e)}function Ci(e){let t=/^\/(\S+)(?:\s+([\s\S]*))?$/.exec(e.trim());if(!t)return null;let n=t[1],r=(t[2]??``).trim();switch(n){case`model`:{if(!r)return{kind:`model-picker`};let e=r.indexOf(`/`);return e<=0||e===r.length-1||/\s/.test(r)?{kind:`invalid`,reason:`Use /model <provider>/<model>, or /model alone to pick one`}:{kind:`model`,provider:r.slice(0,e),modelId:r.slice(e+1)}}case`thinking`:{let e=ce.safeParse(r.toLowerCase());return e.success?{kind:`thinking`,level:e.data}:{kind:`invalid`,reason:`Use /thinking <level>: ${ce.options.join(`, `)}`}}case`compact`:return{kind:`compact`,instructions:r||null};case`name`:return r?r.length>200?{kind:`invalid`,reason:`Session names are at most 200 characters`}:{kind:`name`,title:r}:{kind:`invalid`,reason:`Use /name <new name>`};case`new`:return{kind:`new`,prompt:r};case`fork`:case`clone`:case`tree`:case`resume`:case`reload`:case`export`:case`session`:case`copy`:return{kind:n};default:return gi.includes(n)?{kind:`terminal-only`,name:n}:null}}function wi(e,t,n=!0){return e.kind===`invalid`?e.reason:e.kind===`terminal-only`?`/${e.name} is a Pi terminal command: open the session's terminal to use it`:e.kind===`compact`&&t?`Wait for the run to finish before compacting`:!n&&(e.kind===`fork`||e.kind===`clone`||e.kind===`tree`||e.kind===`export`||e.kind===`reload`)?`This session has no Pi session file yet`:e.kind===`reload`&&t?`Wait for the run to finish before reloading`:null}function Ti(e){let t=e.name??``,n=/^[^:/]{1,40}:\s+(.+)$/.exec(t);n&&(t=n[1]),t||=e.id.slice(e.id.lastIndexOf(`/`)+1);let r=`${e.provider}/`;t.toLowerCase().startsWith(r.toLowerCase())&&(t=t.slice(r.length));let i=/^Claude\s+(.+)$/.exec(t);return i&&(t=i[1]),t||Oi(e)}function Ei(e,t){return e.filter(e=>e.scoped===!0||t&&e.provider===t.provider&&e.id===t.id)}function Di(e,t){let n=t?e.indexOf(t):-1;return Math.max(n,0)}function Oi(e){return e.name??e.id}function ki(e){return[e.name,e.provider&&e.model?`${e.provider}/${e.model}`:e.model??null,e.thinking?`effort ${e.thinking}`:null].filter(Boolean).join(` · `)}function Ai(e){let t=e.model;if(!t)return ki(e.profileSnapshot);let n=e.thinking&&t.thinkingLevels.length>1?` · effort ${e.thinking}`:``;return`${Oi(t)}${n}`}function ji(e,t){let n=t.toLowerCase().split(/\s+/).filter(Boolean),r=[];for(let t of e){let e=`${t.provider}/${t.id} ${t.name??``}`.toLowerCase();if(!n.every(t=>e.includes(t)))continue;let i=r.find(e=>e.provider===t.provider);i||(i={provider:t.provider,models:[]},r.push(i)),i.models.push(t)}return r}function Mi(e){let t=e.stats?.context;if(!t)return null;let n=e=>e.toLocaleString(`en-US`),r=e.compacting?`Compacting…`:t.percent===null?`—`:`${Math.round(t.percent)}%`,i=t.tokens===null?`Known after the next reply (window ${n(t.window)} tokens)`:`${n(t.tokens)} of ${n(t.window)} tokens`,a=t.percent??0;return{label:r,detail:i,percent:t.percent,tone:a>=90?`danger`:a>=75?`warning`:`muted`}}function Ni(e,t){return!t&&e?.capabilities?.sessionControls===!0}var Pi=[];function Fi(e,t,n){let r=n&&!!e&&!t,[i,a]=(0,Y.useState)(null);return(0,Y.useEffect)(()=>{if(!r||!e)return;let t=new AbortController;return a({id:e,lookup:{state:`loading`}}),Q.get(e,t.signal).then(e=>{K.getState().upsertSessionIfMissing(e),a(null)},n=>{t.signal.aborted||a({id:e,lookup:N(n,`not_found`)?{state:`missing`}:{state:`error`,error:G(n)}})}),()=>t.abort()},[r,e]),r?i?.id===e?i.lookup:{state:`loading`}:{state:`idle`}}function Ii(e){let t=K(t=>e?t.hosts[e.hostId]:void 0),n=K(t=>e?.projectId?t.projects[e.projectId]:void 0),r=K(t=>e?.workspaceId?t.workspaces[e.workspaceId]:void 0),i=K(e=>e.runs),a=K(e=>e.tasks),o=K(t=>e?t.adapters[e.hostId]??Pi:Pi);return(0,Y.useMemo)(()=>{if(!e)return null;let s=Hr(i,e),c=e.taskId??s?.taskId??null;return{session:e,host:t,hostName:t?.name??`Unknown host`,link:Gr(t,e),project:n,workspace:r,run:s,task:c?a[c]:void 0,control:Ur(s),adapters:o}},[e,t,n,r,i,a,o])}function Li(e,t={}){let[n,r]=(0,Y.useState)(!1),[i,a]=(0,Y.useState)(null),o=(0,Y.useRef)(e);o.current=e;let s=(0,Y.useRef)(t);s.current=t;let c=(0,Y.useRef)(!0);return(0,Y.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]),{run:(0,Y.useCallback)(async(...e)=>{r(!0),a(null);try{let t=await o.current(...e),{success:n}=s.current,r=typeof n==`function`?n(t):n;return r&&q.success(r),!0}catch(e){return c.current&&a(e),s.current.errorToast&&q.error(G(e)),!1}finally{c.current&&r(!1)}},[]),busy:n,error:i,reset:(0,Y.useCallback)(()=>a(null),[])}}function Ri(e,t=1e3){let[n,r]=(0,Y.useState)(()=>Date.now());return(0,Y.useEffect)(()=>{if(!e)return;r(Date.now());let n=setInterval(()=>r(Date.now()),t);return()=>clearInterval(n)},[e,t]),n}function zi(){let e=(0,Y.useRef)(null),[t,n]=(0,Y.useState)(0);return(0,Y.useLayoutEffect)(()=>{let t=e.current;if(!t)return;n(t.clientWidth);let r=new ResizeObserver(([e])=>{e&&n(e.contentRect.width)});return r.observe(t),()=>r.disconnect()},[]),[e,t]}function Bi(e){let t=e.workspace,n=e.link===`connected`,[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(0),p=t?.id??null;return(0,Y.useEffect)(()=>{if(!p||!n)return;let e=new AbortController;return o(!0),c(null),Q.diff(p,void 0,e.signal).then(e=>{i(e),u(new Date().toISOString())}).catch(t=>{e.signal.aborted||c(t)}).finally(()=>{e.signal.aborted||o(!1)}),()=>e.abort()},[p,n,d]),(0,Y.useEffect)(()=>{i(null),u(null)},[p]),{result:r,parsed:(0,Y.useMemo)(()=>{let e=new Map;if(r?.patch)for(let t of Le(r.patch))e.set(t.path,t);return e},[r]),loading:a,error:s,fetchedAt:l,outdated:!!t&&!!l&&t.updatedAt>l,refresh:(0,Y.useCallback)(()=>f(e=>e+1),[])}}function Vi(e,t,n){let r=n?t.parsed.get(n):void 0,[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(0),u=e.workspace?.id;if((0,Y.useEffect)(()=>{if(!n||r||!u||e.link!==`connected`)return;let t=new AbortController;return s(null),Q.diff(u,n,t.signal).then(e=>{let t=e.patch?Le(e.patch):[];a({path:n,file:t.find(e=>e.path===n)??t[0]??null})}).catch(e=>{t.signal.aborted||s(e)}),()=>t.abort()},[n,r,u,e.link,c,t.fetchedAt]),!n)return{file:null,loading:!1,error:null,retry:()=>{}};if(r)return{file:r,loading:!1,error:null,retry:()=>{}};let d=i?.path===n?i:null;return{file:d?.file??null,loading:!d&&!o,error:o,retry:()=>l(e=>e+1)}}var Hi={added:`Added`,modified:`Modified`,deleted:`Deleted`,renamed:`Renamed`,untracked:`Untracked`,binary:`Binary`};function Ui({files:e,selected:t,onSelect:n,commentCounts:r,large:i}){return(0,X.jsx)(`ul`,{"aria-label":`Changed files`,className:`flex min-w-0 flex-col`,children:e.map(e=>{let a=r.get(e.path)??0;return(0,X.jsx)(`li`,{className:`min-w-0`,children:(0,X.jsxs)(`button`,{type:`button`,"aria-current":t===e.path?`true`:void 0,onClick:()=>n(e.path),className:M(`tap flex w-full min-w-0 items-center gap-2 rounded-md px-2 text-left text-sm hover:bg-surface-2`,i?`min-h-12 py-2`:`py-1.5`,t===e.path&&`bg-accent-soft`),children:[(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:`block truncate font-mono text-xs`,title:e.path,children:e.path}),(0,X.jsxs)(`span`,{className:`block text-xs text-muted`,children:[Hi[e.status],a>0&&` · ${a} comment${a===1?``:`s`}`]})]}),(0,X.jsxs)(`span`,{className:`shrink-0 font-mono text-xs tabular-nums`,children:[(0,X.jsxs)(`span`,{className:`text-success`,children:[`+`,e.added,(0,X.jsx)(`span`,{className:`sr-only`,children:` added`})]}),` `,(0,X.jsxs)(`span`,{className:`text-danger`,children:[`-`,e.deleted,(0,X.jsx)(`span`,{className:`sr-only`,children:` deleted`})]})]}),i&&(0,X.jsx)(je,{"aria-hidden":!0,className:`size-4 shrink-0 text-subtle`})]})},e.path)})})}function Wi({ctx:e,diff:t,path:n,comments:r,onComment:i}){let a=Vi(e,t,n);if(a.error)return(0,X.jsx)(H,{compact:!0,title:`Could not load this diff`,error:a.error,onRetry:a.retry});if(a.loading)return(0,X.jsx)(P,{label:`Loading diff…`});if(!a.file)return(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`No textual diff for this file.`});let o=new Set(r.filter(e=>e.file===n).map(e=>e.line));return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,X.jsx)(Re,{files:[a.file],onLineClick:({file:e,line:t})=>i({file:e,line:t.newLine??t.oldLine,excerpt:t.text}),isLineMarked:({line:e})=>o.has(e.newLine??e.oldLine)}),(0,X.jsx)(F,{size:`sm`,variant:`ghost`,icon:(0,X.jsx)(Cn,{className:`size-4`}),onClick:()=>i({file:n,line:null,excerpt:null}),className:`self-start`,children:`Comment on this file`})]})}function Gi({draft:e,mobile:t,onClose:n,onSave:r}){let[i,a]=(0,Y.useState)(``),o=(0,Y.useRef)(null);(0,Y.useEffect)(()=>a(``),[e]);let s=t?mt:ht,c=e?e.line===null?e.file:`${e.file}:${e.line}`:``;return(0,X.jsxs)(s,{open:!!e,onClose:n,title:`Add review comment`,description:c,initialFocus:o,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(F,{onClick:n,children:`Cancel`}),(0,X.jsx)(F,{variant:`primary`,disabled:!i.trim(),onClick:()=>r(i.trim()),children:`Add comment`})]}),children:[e?.excerpt&&(0,X.jsx)(`pre`,{className:`mb-2 max-w-full overflow-x-auto rounded bg-surface-2 px-2 py-1 font-mono text-xs`,children:e.excerpt}),(0,X.jsx)(`label`,{htmlFor:`sy-review-comment`,className:`sr-only`,children:`Comment`}),(0,X.jsx)(vt,{id:`sy-review-comment`,ref:o,minRows:3,value:i,placeholder:`What should change here?`,onChange:e=>a(e.target.value)}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted`,children:`Comments are collected and sent together, never one at a time.`})]})}function Ki({ctx:e,review:t}){let{session:n,task:r}=e,{mobile:i}=or(),[a,o]=(0,Y.useState)(``),s=Jr({session:n,hostLink:e.link,hostName:e.hostName}),c=Li(()=>Q.prompt(n.id,{text:at(t.comments),mode:fr(n)?`followUp`:`prompt`}),{success:`Review comments sent as one follow-up.`}),l=[...a.trim()?[a.trim()]:[],...t.comments.map(e=>`${e.line===null?e.file:`${e.file}:${e.line}`}: ${e.text}`)],u=Li(()=>Q.requestChanges(r.id,l),{success:`Changes requested. The task stays in Review until a new attempt starts.`}),d=Li(e=>Q.accept(r.id,e),{success:`Task accepted and marked Done.`}),f=N(d.error,`invalid_transition`)&&d.error.details?.needsConfirm===!0,p=r?.state===`review`,m=s?.reason??null;return(0,X.jsxs)(`section`,{"aria-label":`Review`,className:`flex min-w-0 flex-col gap-2 border-t border-border pt-3`,children:[(0,X.jsxs)(`h3`,{className:`text-sm font-semibold`,children:[`Review comments`,t.comments.length>0&&` (${t.comments.length})`]}),t.comments.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`${i?`Tap`:`Click`} a line in the diff to comment. Comments go to Pi together as one message.`}):(0,X.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:t.comments.map(e=>(0,X.jsxs)(`li`,{className:`flex min-w-0 items-start gap-2 rounded-md border border-border px-2 py-1.5`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`truncate font-mono text-xs text-muted`,children:e.line===null?e.file:`${e.file}:${e.line}`}),(0,X.jsx)(`p`,{className:`text-sm break-words whitespace-pre-wrap`,children:e.text})]}),(0,X.jsx)(J,{size:`sm`,label:`Remove comment`,icon:(0,X.jsx)(he,{className:`size-3.5`}),onClick:()=>t.remove(e.id)})]},e.id))}),t.comments.length>0&&(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(F,{size:`sm`,variant:p?`secondary`:`primary`,icon:(0,X.jsx)(we,{className:`size-3.5`}),disabled:!!m,busy:c.busy,onClick:()=>void c.run().then(e=>e&&t.clear()),children:`Send as one follow-up`}),t.comments.length>0&&(0,X.jsx)(F,{size:`sm`,variant:`ghost`,onClick:t.clear,children:`Clear all`})]}),m&&t.comments.length>0&&(0,X.jsx)(`p`,{className:`text-xs text-muted`,children:m}),c.error!==null&&(0,X.jsx)(H,{compact:!0,title:`Comments not sent; they are kept.`,error:G(c.error),onRetry:()=>void c.run().then(e=>e&&t.clear())}),r&&p&&(0,X.jsxs)(`div`,{className:`mt-2 flex flex-col gap-2 rounded-md border border-border p-3`,children:[(0,X.jsxs)(`h3`,{className:`text-sm font-semibold`,children:[`Task review: `,r.title]}),(0,X.jsx)(`label`,{htmlFor:`sy-overall-feedback`,className:`text-xs font-medium text-muted`,children:`Overall feedback (optional, sent with the comments above)`}),(0,X.jsx)(vt,{id:`sy-overall-feedback`,minRows:2,value:a,onChange:e=>o(e.target.value)}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsx)(F,{size:`sm`,icon:(0,X.jsx)(Zn,{className:`size-3.5`}),disabled:l.length===0,busy:u.busy,onClick:()=>void u.run().then(e=>{e&&(t.clear(),o(``))}),children:`Request changes`}),(0,X.jsx)(F,{size:`sm`,variant:`primary`,icon:(0,X.jsx)(_e,{className:`size-3.5`}),busy:d.busy,onClick:()=>void d.run(!1),children:`Accept task`})]}),l.length===0&&(0,X.jsx)(`p`,{className:`text-xs text-muted`,children:`Add a comment or overall feedback to request changes.`}),(0,X.jsx)(`p`,{className:`text-xs text-muted`,children:`Accepting marks the task Done. It does not merge or push.`}),u.error!==null&&(0,X.jsx)(H,{compact:!0,title:`Could not request changes`,error:G(u.error)}),d.error!==null&&(f?(0,X.jsxs)(`div`,{role:`alert`,className:`flex flex-col gap-2 rounded-md bg-warning-soft p-2 text-sm`,children:[(0,X.jsx)(`p`,{className:`break-words`,children:G(d.error)}),(0,X.jsx)(F,{size:`sm`,variant:`primary`,className:`self-start`,busy:d.busy,onClick:()=>void d.run(!0),children:`Accept anyway`})]}):(0,X.jsx)(H,{compact:!0,title:`Could not accept`,error:G(d.error)}))]}),r?.review.changesRequested&&r.state===`review`&&(0,X.jsx)(`p`,{className:`text-xs text-muted`,children:`Changes requested. The task stays in Review until a new attempt is requested.`})]})}function qi(e){return(0,Y.useMemo)(()=>{let t=new Map;for(let n of e)t.set(n.file,(t.get(n.file)??0)+1);return t},[e])}function Ji({ctx:e}){return e.workspace?(0,X.jsx)(B,{compact:!0,hostName:e.hostName,connectivity:e.link===`reconnecting`?`reconnecting`:`unreachable`,lastSeenAt:e.host?.lastSeenAt,detail:`Changes are read from the host; they load when it reconnects.`}):(0,X.jsx)(se,{capability:`Changes`,reason:`This session is not linked to a Switchyard workspace (it runs in ${e.session.cwd}).`,fallback:`Open a session in a project workspace to review changes.`})}function Yi({diff:e}){return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 text-xs text-muted`,children:[(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[e.result?`Against ${e.result.base}`:``,e.fetchedAt&&` · updated ${I(e.fetchedAt)}`,e.outdated&&` · workspace changed since`]}),(0,X.jsx)(F,{size:`sm`,variant:e.outdated?`secondary`:`ghost`,icon:(0,X.jsx)(ue,{className:`size-3.5`}),busy:e.loading,onClick:e.refresh,children:e.loading?`Refreshing…`:`Refresh`})]})}function Xi({ctx:e,diff:t}){let n=ot(e.session.id),r=qi(n.comments),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),c=t.result?.files??[];return!e.workspace||e.link!==`connected`?(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsx)(Ji,{ctx:e}),(n.comments.length>0||e.task?.state===`review`)&&(0,X.jsx)(Ki,{ctx:e,review:n})]}):(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,X.jsx)(Yi,{diff:t}),t.error!==null&&!t.result?(0,X.jsx)(H,{compact:!0,title:`Could not load changes`,error:t.error,onRetry:t.refresh}):t.result?c.length===0?(0,X.jsx)(U,{icon:(0,X.jsx)(sn,{className:`size-8`}),title:`No changes yet`,description:`Nothing differs from ${t.result.base} in this workspace.`,className:`py-6`}):(0,X.jsxs)(X.Fragment,{children:[t.error!==null&&(0,X.jsx)(H,{compact:!0,title:`Refresh failed; showing earlier changes`,error:t.error,onRetry:t.refresh}),(0,X.jsx)(Ui,{files:c,selected:i,onSelect:e=>a(t=>t===e?null:e),commentCounts:r}),i&&(0,X.jsx)(Wi,{ctx:e,diff:t,path:i,comments:n.comments,onComment:s})]}):(0,X.jsx)(P,{label:`Loading changes…`}),(n.comments.length>0||e.task?.state===`review`)&&(0,X.jsx)(Ki,{ctx:e,review:n}),(0,X.jsx)(Gi,{draft:o,mobile:!1,onClose:()=>s(null),onSave:e=>{o&&n.add({...o,text:e}),s(null)}})]})}function Zi({ctx:e}){let t=Bi(e),n=ot(e.session.id),r=qi(n.comments),[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),c=t.result?.files??[],l=i?c.findIndex(e=>e.path===i):-1;return i&&l>=0?(0,X.jsx)(Qi,{ctx:e,diff:t,file:c[l],index:l,total:c.length,comments:n.comments,onBack:()=>a(null),onPrev:()=>a(c[l-1]?.path??i),onNext:()=>a(c[l+1]?.path??i),commentDraft:o,setCommentDraft:s,onSaveComment:e=>{o&&n.add({...o,text:e}),s(null)}}):(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3 px-3 py-3`,children:[!e.workspace||e.link!==`connected`?(0,X.jsx)(Ji,{ctx:e}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Yi,{diff:t}),t.error!==null&&!t.result?(0,X.jsx)(H,{title:`Could not load changes`,error:t.error,onRetry:t.refresh}):t.result?c.length===0?(0,X.jsx)(U,{icon:(0,X.jsx)(sn,{className:`size-8`}),title:`No changes yet`,description:`Nothing differs from ${t.result.base} in this workspace.`}):(0,X.jsx)(Ui,{files:c,selected:null,onSelect:a,commentCounts:r,large:!0}):(0,X.jsx)(P,{label:`Loading changes…`})]}),(n.comments.length>0||e.task?.state===`review`)&&(0,X.jsx)(Ki,{ctx:e,review:n})]})}function Qi({ctx:e,diff:t,file:n,index:r,total:i,comments:a,onBack:o,onPrev:s,onNext:c,commentDraft:l,setCommentDraft:u,onSaveComment:d}){nt(!0);let f=(0,Y.useRef)(null);(0,Y.useEffect)(()=>f.current?.focus(),[n.path]);let p=a.filter(e=>e.file===n.path).length;return(0,X.jsxs)(`section`,{"aria-label":`Diff of ${n.path}`,className:`fixed inset-0 z-40 flex min-w-0 flex-col bg-bg safe-pt safe-px`,onKeyDown:e=>{e.key===`Escape`&&!l&&(e.preventDefault(),o())},children:[(0,X.jsxs)(`header`,{className:`flex min-w-0 shrink-0 items-center gap-1 border-b border-border bg-surface px-2 py-1.5`,children:[(0,X.jsx)(J,{ref:f,label:`Back to changed files`,icon:(0,X.jsx)(me,{className:`size-4`}),onClick:o}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`truncate font-mono text-xs`,title:n.path,children:n.path}),(0,X.jsxs)(`div`,{className:`text-xs text-muted`,children:[`File `,r+1,` of `,i,` · +`,n.added,` -`,n.deleted,p>0&&` · ${p} comment${p===1?``:`s`}`]})]}),(0,X.jsx)(J,{label:`Previous file`,icon:(0,X.jsx)(ke,{className:`size-4`}),disabled:r===0,onClick:s}),(0,X.jsx)(J,{label:`Next file`,icon:(0,X.jsx)(je,{className:`size-4`}),disabled:r>=i-1,onClick:c})]}),(0,X.jsxs)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-contain px-2 pt-2 safe-pb-2`,children:[(0,X.jsx)(`p`,{className:`mb-2 text-xs text-muted`,children:`Tap a line to add a review comment.`}),(0,X.jsx)(Wi,{ctx:e,diff:t,path:n.path,comments:a,onComment:u})]}),(0,X.jsx)(Gi,{draft:l,mobile:!0,onClose:()=>u(null),onSave:d})]})}function $i({hostId:e,adapterId:t,node:n,state:r,onAction:i,title:a,className:o,minHeight:s=80,maxHeight:c=ne}){let l=(0,Y.useRef)(null),[u,d]=(0,Y.useState)(s),[f,p]=(0,Y.useState)(!1),m=(0,Y.useRef)(i);m.current=i,(0,Y.useEffect)(()=>{let e=e=>{if(e.source!==l.current?.contentWindow)return;let t=O(e.data);t&&(t.type===`resize`?d(Math.min(c,Math.max(s,Math.ceil(t.height)))):m.current?.(t.actionId,t.payload))};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[s,c]),(0,Y.useEffect)(()=>{f&&l.current?.contentWindow?.postMessage(y(n,r),`*`)},[f,n,r]);let h=`/adapter-frames/${encodeURIComponent(e)}/${encodeURIComponent(t)}`;return(0,X.jsx)(`iframe`,{ref:l,title:a,src:h,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`,loading:`lazy`,onLoad:()=>p(!0),style:{height:u},className:M(`block w-full rounded-md border border-border bg-surface`,o)})}function ea({ctx:e,className:t}){if(e.control===`none`)return null;let n=e.control===`automation`;return(0,X.jsx)(m,{kind:`custom`,size:`sm`,className:t,status:{label:Wr[e.control],icon:n?Bt:Ge,tone:n?`info`:`neutral`}})}function ta({ctx:e}){return(0,X.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1 text-xs text-muted`,children:[(0,X.jsx)(et,{"aria-hidden":!0,className:`size-3.5 shrink-0`}),(0,X.jsx)(`span`,{className:`truncate`,children:e.hostName}),e.link!==`connected`&&(0,X.jsx)(m,{kind:`host`,value:e.link,size:`sm`,className:`ml-1`})]})}function na(e,t,n=[]){return[{id:`rename`,label:`Rename`,icon:(0,X.jsx)(We,{className:`size-4`}),onSelect:t.openRename,disabled:e.session.readOnly},e.session.archivedAt?{id:`unarchive`,label:`Unarchive`,icon:(0,X.jsx)(Pt,{className:`size-4`}),onSelect:t.unarchive}:{id:`archive`,label:`Archive`,icon:(0,X.jsx)(It,{className:`size-4`}),onSelect:t.requestArchive,disabled:!!t.archiveBlocked,hint:t.archiveBlocked??void 0},...n.map(n=>({id:`view-${n.id}`,label:`Pin to ${n.name}`,kind:`checkbox`,checked:n.sessionIds.includes(e.session.id),onSelect:()=>t.setPinned(n.id,!n.sessionIds.includes(e.session.id))})),{id:`info`,label:`Session info`,icon:(0,X.jsx)(Pe,{className:`size-4`}),onSelect:t.openInfo}]}function ra({ctx:e,actions:t,inspector:i}){let{session:a,project:o,workspace:s,task:c}=e,l=n(),u=K(e=>e.views),[d,f]=zi(),p=f>0&&f<640,g=[...p&&c?[{id:`task`,label:`Open linked task`,icon:(0,X.jsx)(tt,{className:`size-4`}),onSelect:()=>l(`/tasks/${encodeURIComponent(c.id)}`)}]:[],...na(e,t,Object.values(u))];return(0,X.jsxs)(`header`,{ref:d,className:`flex min-w-0 shrink-0 flex-col gap-1.5 border-b border-border bg-surface px-4 py-2.5`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(`h1`,{className:`min-w-0 flex-1 truncate text-base font-semibold`,title:a.title,children:a.title}),c&&!p&&(0,X.jsxs)(r,{to:`/tasks/${encodeURIComponent(c.id)}`,className:ie(`ghost`,`sm`),title:`Open linked task: ${c.title}`,children:[(0,X.jsx)(tt,{"aria-hidden":!0,className:`size-4`}),(0,X.jsx)(`span`,{className:`hidden xl:inline`,children:`Open linked task`}),(0,X.jsx)(`span`,{className:`xl:hidden`,children:`Task`})]}),t.canStop&&(0,X.jsx)(F,{size:`sm`,variant:a.runtime===`waiting_input`?`secondary`:`danger`,icon:(0,X.jsx)(h,{className:`size-3.5`}),busy:t.busy.stop,onClick:t.requestStop,children:`Stop`}),(0,X.jsx)(Ce,{label:`Session menu`,items:g,trigger:e=>(0,X.jsx)(J,{...e,label:`Session menu`,icon:(0,X.jsx)(nn,{className:`size-4`})})}),(0,X.jsx)(J,{label:i.label,"aria-expanded":i.open,icon:i.open?(0,X.jsx)(Fn,{className:`size-4`}):(0,X.jsx)(Se,{className:`size-4`}),onClick:i.toggle})]}),(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,X.jsx)(m,{kind:`runtime`,value:a.runtime,size:`sm`}),(0,X.jsx)(ea,{ctx:e}),(0,X.jsx)(`span`,{className:`min-w-0 truncate text-xs text-muted`,children:o?.name??`No project`}),(0,X.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1 text-xs text-muted`,children:[(0,X.jsx)(Ue,{"aria-hidden":!0,className:`size-3.5 shrink-0`}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Branch `}),(0,X.jsx)(`span`,{className:`truncate font-mono`,children:Ar(s,a.cwd)})]}),(0,X.jsx)(ta,{ctx:e})]})]})}function $({title:e,children:t,className:n}){return(0,X.jsxs)(`section`,{"aria-label":e,className:M(`flex min-w-0 flex-col gap-2`,n),children:[(0,X.jsx)(`h3`,{className:`text-sm font-semibold`,children:e}),t]})}function ia({ctx:e,actions:t}){let{canTakeover:n,canReturn:r,canStop:i}=t;return!n&&!r&&!i?(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`Manual session: no automation run controls it.`}):(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,X.jsx)(ea,{ctx:e}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[n&&(0,X.jsx)(F,{icon:(0,X.jsx)(Ge,{className:`size-4`}),busy:t.busy.takeover,onClick:t.takeover,children:`Take over`}),r&&(0,X.jsx)(F,{icon:(0,X.jsx)(Bt,{className:`size-4`}),busy:t.busy.ret,onClick:t.returnToAutomation,children:`Return to automation`}),i&&(0,X.jsx)(F,{variant:e.session.runtime===`waiting_input`?`secondary`:`danger`,icon:(0,X.jsx)(h,{className:`size-4`}),busy:t.busy.stop,onClick:t.requestStop,children:`Stop`})]}),(n||r)&&(0,X.jsx)(`p`,{className:`text-xs text-muted`,children:e.control===`automation`?`Taking over pauses automatic continuations; Pi keeps running.`:`You have control; returning lets automation continue.`})]})}function aa({run:e}){return(0,X.jsxs)(`li`,{className:`flex min-w-0 flex-col gap-0.5 rounded-md border border-border px-2 py-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(`span`,{className:`text-sm font-medium`,children:[`Attempt `,e.attempt]}),(0,X.jsx)(m,{kind:`run`,value:e.state,size:`sm`}),(0,X.jsx)(`span`,{className:`text-xs text-muted`,children:e.startedAt?I(e.startedAt):I(e.createdAt)})]}),e.outcome&&(0,X.jsx)(`p`,{className:`text-xs break-words text-muted`,children:e.outcome.summary}),(0,X.jsxs)(`p`,{className:`text-xs text-muted`,children:[e.usage.accounting===`available`?[e.usage.tokens===null?null:`${e.usage.tokens.toLocaleString()} tokens`,e.usage.costUsd===null?null:`$${e.usage.costUsd.toFixed(2)}`].filter(Boolean).join(` · `)||`No usage reported`:e.usage.note??`Token/cost accounting not reported`,e.continuationsUsed>0&&` · ${e.continuationsUsed} continuations`]})]})}function oa({task:e,run:t}){let n=t?.limits??e.policy.continuation;return(0,X.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[(0,X.jsx)(`dt`,{className:`text-muted`,children:`Continuation`}),(0,X.jsx)(`dd`,{children:n.enabled?`Enabled`:`Off: stops after one turn`}),n.enabled&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`text-muted`,children:`Continuations`}),(0,X.jsxs)(`dd`,{children:[t?`${t.continuationsUsed} of `:`up to `,n.maxContinuations]}),(0,X.jsx)(`dt`,{className:`text-muted`,children:`Time limit`}),(0,X.jsxs)(`dd`,{children:[n.maxElapsedMinutes,` min`]}),(0,X.jsx)(`dt`,{className:`text-muted`,children:`Token limit`}),(0,X.jsx)(`dd`,{children:n.maxTokens?.toLocaleString()??`None`}),(0,X.jsx)(`dt`,{className:`text-muted`,children:`Cost limit`}),(0,X.jsx)(`dd`,{children:n.maxCostUsd===null?`None`:`$${n.maxCostUsd}`})]}),(0,X.jsx)(`dt`,{className:`text-muted`,children:`Checks`}),(0,X.jsx)(`dd`,{className:`min-w-0 break-words`,children:e.policy.completion.checks===null?`Project checks`:e.policy.completion.checks.length?e.policy.completion.checks.join(`, `):`None`}),(0,X.jsx)(`dt`,{className:`text-muted`,children:`Human review`}),(0,X.jsx)(`dd`,{children:e.policy.completion.requireHumanReview?`Required`:`Not required`})]})}function sa({ctx:e,actions:t,showControls:n=!0}){let{task:i,run:a}=e,o=S(i?.id),s=K(e=>e.tasks);return i?(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,X.jsx)(`h3`,{className:`min-w-0 flex-1 text-sm font-semibold break-words`,children:i.title}),(0,X.jsx)(m,{kind:`task`,value:i.state,size:`sm`})]}),i.blocked&&(0,X.jsxs)(`p`,{className:`text-sm text-warning`,children:[`Blocked: `,i.blocked.reason]}),(0,X.jsxs)(r,{to:`/tasks/${encodeURIComponent(i.id)}`,className:ie(`secondary`,`sm`,`self-start`),children:[(0,X.jsx)(tt,{"aria-hidden":!0,className:`size-4`}),`Open task`]})]}),(0,X.jsx)($,{title:`Objective`,children:i.objective?(0,X.jsx)(wt,{text:i.objective}):(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`No objective written.`})}),(0,X.jsx)($,{title:`Acceptance criteria`,children:i.acceptanceCriteria.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`None.`}):(0,X.jsx)(`ul`,{className:`flex flex-col gap-1`,children:i.acceptanceCriteria.map(e=>(0,X.jsxs)(`li`,{className:`flex items-start gap-2 text-sm`,children:[(0,X.jsx)(Ie,{"aria-hidden":!0,className:`mt-0.5 size-4 shrink-0 text-muted`}),(0,X.jsx)(`span`,{className:`min-w-0 break-words`,children:e})]},e))})}),(0,X.jsx)($,{title:`Dependencies`,children:i.dependencies.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`None.`}):(0,X.jsx)(`ul`,{className:`flex flex-col gap-1`,children:i.dependencies.map(e=>{let t=s[e];return(0,X.jsxs)(`li`,{className:`flex min-w-0 items-center gap-2 text-sm`,children:[t?(0,X.jsx)(m,{kind:`task`,value:t.state,size:`sm`}):null,(0,X.jsx)(bt,{to:`/tasks/${encodeURIComponent(e)}`,size:`sm`,className:`truncate`,children:t?.title??e})]},e)})})}),(0,X.jsx)($,{title:`Limits`,children:(0,X.jsx)(oa,{task:i,run:a})}),n&&(0,X.jsx)($,{title:`Control`,children:(0,X.jsx)(ia,{ctx:e,actions:t})}),(0,X.jsx)($,{title:`Run history`,children:o.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`No runs yet.`}):(0,X.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:o.map(e=>(0,X.jsx)(aa,{run:e},e.id))})})]}):(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`No linked task: this session was started directly.`})}var ca={active:{label:`Active`,tone:`success`},disabled:{label:`Disabled`,tone:`neutral`},error:{label:`Error`,tone:`danger`}};function la({a:e}){let t=ca[e.status];return(0,X.jsxs)(`li`,{className:`flex min-w-0 flex-col gap-0.5 rounded-md border border-border px-2 py-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono text-sm`,children:e.id}),(0,X.jsxs)(`span`,{className:`text-xs text-muted`,children:[`v`,e.version]}),(0,X.jsxs)(`span`,{className:`rounded-full border border-border px-1.5 text-xs text-muted`,children:[`Tier: `,e.tier]}),(0,X.jsx)(m,{kind:`custom`,size:`sm`,status:{label:t.label,tone:t.tone,icon:e.status===`active`?Ie:h}})]}),(0,X.jsxs)(`p`,{className:`text-xs break-words text-muted`,children:[`For `,e.target.extension,` `,e.target.versionRange,e.target.testedVersions.length>0&&` (tested ${e.target.testedVersions.join(`, `)})`]}),e.capabilities.length>0&&(0,X.jsxs)(`p`,{className:`text-xs text-muted`,children:[`Provides: `,e.capabilities.join(`, `)]}),e.detail&&(0,X.jsx)(`p`,{className:`text-xs break-words text-warning`,children:e.detail})]})}function ua({ctx:e,panel:t}){let{mobile:n,openFile:r}=or(),i=(n,r)=>{Q.adapterAction(e.session.id,t.adapterId,n,r).then(()=>q.success(`Action sent`)).catch(e=>q.error(G(e)))},a;return a=t.webRenderer&&!n&&e.host?(0,X.jsx)($i,{hostId:e.session.hostId,adapterId:t.adapterId,node:t.node,title:t.title,onAction:i}):t.node?(0,X.jsxs)(X.Fragment,{children:[t.webRenderer&&n&&(0,X.jsx)(`p`,{className:`text-xs text-muted`,children:`Showing the portable version; this panel's custom renderer is desktop-only.`}),(0,X.jsx)(Ve,{node:t.node,onAction:e=>i(e),onOpenFile:r})]}):(0,X.jsx)(se,{capability:`This panel`,reason:`It only has a custom web renderer, which is desktop-only and is not shown on mobile.`,fallback:(0,X.jsx)(`p`,{className:`text-sm`,children:t.mobileFallback??`The adapter provides no mobile fallback text.`})}),(0,X.jsxs)(`article`,{className:`flex min-w-0 flex-col gap-2 rounded-md border border-border p-2`,children:[(0,X.jsxs)(`header`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,X.jsx)(`h4`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:t.title}),(0,X.jsx)(`span`,{className:`shrink-0 font-mono text-xs text-subtle`,children:t.adapterId})]}),a]})}function da({ctx:e}){let t=T(e.session.id),n=K(e=>e.diagnostics),r=(0,Y.useMemo)(()=>new Set(e.adapters.map(e=>e.id)),[e.adapters]),i=(0,Y.useMemo)(()=>n.filter(t=>t.sessionId===e.session.id||t.sessionId===null&&t.adapterId!==null&&r.has(t.adapterId)).slice(-20).reverse(),[n,e.session.id,r]),a=e.host?.capabilities;return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,X.jsx)($,{title:`Panels`,children:t.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`No extension panels for this session.`}):t.map(t=>(0,X.jsx)(ua,{ctx:e,panel:t},`${t.adapterId}:${t.slot}`))}),(0,X.jsx)($,{title:`Adapters on ${e.hostName}`,children:e.adapters.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`No adapters reported by this host.`}):(0,X.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:e.adapters.map(e=>(0,X.jsx)(la,{a:e},e.id))})}),(a?.unsupported.length||e.host?.piCompatible===!1)&&(0,X.jsxs)($,{title:`Runtime limitations`,children:[e.host?.piCompatible===!1&&(0,X.jsx)(se,{capability:`This Pi version`,reason:`Pi ${e.host.piVersion??`(not found)`} on ${e.hostName} is outside the tested range.`}),a?.unsupported.map(e=>(0,X.jsx)(se,{capability:e.capability,reason:e.reason},e.capability))]}),(0,X.jsxs)($,{title:`Diagnostics`,children:[i.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`No diagnostics.`}):(0,X.jsx)(`ul`,{className:`flex flex-col gap-1`,children:i.map((e,t)=>(0,X.jsxs)(`li`,{className:`min-w-0 rounded-md bg-surface-2 px-2 py-1 text-xs`,children:[(0,X.jsx)(`span`,{className:M(`font-medium`,e.level===`error`&&`text-danger`,e.level===`warning`&&`text-warning`),children:e.level===`error`?`Error`:e.level===`warning`?`Warning`:`Info`}),` `,e.adapterId&&(0,X.jsxs)(`span`,{className:`font-mono`,children:[e.adapterId,`: `]}),(0,X.jsx)(`span`,{className:`break-words`,children:e.message}),` `,(0,X.jsx)(`span`,{className:`text-subtle`,children:R(e.at)})]},`${e.at}-${t}`))}),(0,X.jsx)(bt,{to:`/settings/diagnostics`,size:`sm`,children:`All diagnostics`})]})]})}function fa({ctx:e}){let{session:t,workspace:n,host:r}=e,i=Mi(t);return(0,X.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[(0,X.jsx)(`dt`,{className:`text-muted`,children:`Project`}),(0,X.jsx)(`dd`,{className:`min-w-0 break-words`,children:e.project?.name??`None`}),(0,X.jsx)(`dt`,{className:`text-muted`,children:`Host`}),(0,X.jsxs)(`dd`,{className:`min-w-0 break-words`,children:[e.hostName,e.link!==`connected`&&` (${e.link})`,r?.piVersion&&` · Pi ${r.piVersion}`]}),(0,X.jsx)(`dt`,{className:`text-muted`,children:`Control`}),(0,X.jsx)(`dd`,{children:e.control===`none`?`Manual session`:(0,X.jsx)(ea,{ctx:e})}),(0,X.jsx)(`dt`,{className:`text-muted`,children:`Branch`}),(0,X.jsxs)(`dd`,{className:`min-w-0 font-mono text-xs break-all`,children:[Ar(n,t.cwd),n?.baseBranch&&` (from ${n.baseBranch})`]}),(0,X.jsx)(`dt`,{className:`text-muted`,children:`Path`}),(0,X.jsx)(`dd`,{className:`min-w-0 font-mono text-xs break-all`,children:n?.path??t.cwd}),n&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`text-muted`,children:`Git`}),(0,X.jsxs)(`dd`,{children:[n.git.dirty?`${n.git.changedFiles} changed files`:`Clean`,n.git.ahead>0&&` · ${n.git.ahead} ahead`,n.git.behind>0&&` · ${n.git.behind} behind`]})]}),(0,X.jsx)(`dt`,{className:`text-muted`,children:`Profile`}),(0,X.jsx)(`dd`,{className:`min-w-0 break-words`,children:t.profileSnapshot.name}),t.model&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`text-muted`,children:`Model`}),(0,X.jsxs)(`dd`,{className:`min-w-0 break-words`,children:[`${Oi(t.model)} (${t.model.provider}/${t.model.id})`,t.thinking&&` · effort ${t.thinking}`]})]}),i&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`text-muted`,children:`Context`}),(0,X.jsx)(`dd`,{className:`min-w-0 break-words`,children:`${i.label} · ${i.detail}`})]})]})}function pa({ctx:e,actions:t}){let n=ee(e.session.id).items.filter(e=>e.kind===`subagent`);return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-5 px-3 py-3`,children:[(0,X.jsx)($,{title:`Session`,children:(0,X.jsx)(fa,{ctx:e})}),(0,X.jsx)($,{title:`Automation and control`,children:(0,X.jsx)(ia,{ctx:e,actions:t})}),(0,X.jsx)($,{title:`Task`,children:(0,X.jsx)(sa,{ctx:e,actions:t,showControls:!1})}),(0,X.jsx)($,{title:`Subagents`,children:n.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`No subagents in the loaded transcript.`}):(0,X.jsx)(`ul`,{className:`flex flex-col gap-1`,children:n.map(e=>e.kind===`subagent`?(0,X.jsxs)(`li`,{className:`flex min-w-0 flex-wrap items-center gap-2 text-sm`,children:[(0,X.jsx)(`span`,{className:`min-w-0 truncate`,children:e.data.label}),(0,X.jsx)(`span`,{className:`text-xs text-muted`,children:e.data.status}),e.data.linkedSessionId&&(0,X.jsx)(bt,{to:`/code/${encodeURIComponent(e.data.linkedSessionId)}`,children:`Open (view only)`})]},e.id):null)})}),(0,X.jsx)($,{title:`Extensions`,children:(0,X.jsx)(da,{ctx:e})})]})}function ma({text:e,lang:t,wrap:n,className:r}){let i=Tt(e,t),a=e.split(`
|
|
8
|
+
`);return a.length>1&&a[a.length-1]===``&&a.pop(),(0,X.jsx)(`section`,{"aria-label":`File contents`,className:M(`sy-code min-w-0 overflow-auto overscroll-contain bg-surface-2 py-2 font-mono text-xs leading-5`,r),children:(0,X.jsx)(`pre`,{className:M(`px-3`,n?`break-all whitespace-pre-wrap`:`w-max min-w-full whitespace-pre`),children:(0,X.jsx)(`code`,{children:a.map((e,t)=>{let n=i?.[t];return(0,X.jsxs)(`span`,{children:[n?n.map((e,t)=>(0,X.jsx)(`span`,{style:e.style,children:e.content},t)):e,t<a.length-1?`
|
|
9
|
+
`:``]},t)})})})})}var ha={png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,gif:`image/gif`,webp:`image/webp`,avif:`image/avif`,bmp:`image/bmp`,ico:`image/x-icon`},ga={added:{letter:`A`,tone:`text-success`},untracked:{letter:`U`,tone:`text-success`},modified:{letter:`M`,tone:`text-warning`},renamed:{letter:`R`,tone:`text-warning`},deleted:{letter:`D`,tone:`text-danger`},binary:{letter:`B`,tone:`text-muted`}};function _a(e){let t=e.split(`/`).filter(Boolean);return t.pop(),t.join(`/`)}function va(e){let t=e.split(`/`).filter(Boolean);return t.pop(),t.map((e,n)=>t.slice(0,n+1).join(`/`))}function ya(e){return(/\.([A-Za-z0-9]+)$/.exec(e)?.[1]??``).toLowerCase()}function ba(e){return e<1024?`${e} B`:e<1048576?`${Math.round(e/1024)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function xa(e){let t=ya(e);return t===`json`||t===`jsonc`?an:[`md`,`mdx`,`markdown`,`txt`].includes(t)?dn:t in ha?ln:Ct(e)?Be:pn}function Sa(e,t,n){return e.path?e.path.startsWith(`${t.path}/`)?e.path.slice(t.path.length+1):e.path:n?`${n}/${e.name}`:e.name}function Ca({status:e}){if(!e)return null;let t=ga[e];return(0,X.jsx)(`span`,{title:Hi[e],className:M(`shrink-0 font-mono text-[11px] font-semibold`,t.tone),children:t.letter})}function wa({ctx:e,diff:t,openPath:n}){let r=e.workspace,i=e.link===`connected`,[a,o]=(0,Y.useState)(new Map),[s,c]=(0,Y.useState)(new Set),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(null),h=(0,Y.useRef)(null),g=(0,Y.useMemo)(()=>new Map(t.result?.files.map(e=>[e.path,e.status])??[]),[t.result]),_=(0,Y.useMemo)(()=>{let e=new Set;for(let t of g.keys())for(let n of va(t))e.add(n);return e},[g]),v=r?.id,y=(0,Y.useCallback)((e,t=!1)=>{v&&(o(n=>{let r=n.get(e);return r&&!t&&(r===`loading`||Array.isArray(r))?n:new Map(n).set(e,`loading`)}),Q.files(v,e).then(t=>o(n=>new Map(n).set(e,t)),t=>o(n=>new Map(n).set(e,{error:t}))))},[v]);(0,Y.useEffect)(()=>{if(v&&i){o(new Map),y(``,!0);for(let e of s)y(e,!0)}},[v,i]),(0,Y.useEffect)(()=>{if(!n||!r)return;let e=n.path.startsWith(`${r.path}/`)?n.path.slice(r.path.length+1):n.path.replace(/^\.\//,``);u(e);let t=va(e);c(e=>new Set([...e,...t]));for(let e of t)y(e)},[n,r,y]);let b=e=>{c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):(n.add(e),y(e)),n})};if(!r)return(0,X.jsx)(se,{capability:`File browsing`,reason:`This session is not linked to a Switchyard workspace (it runs in ${e.session.cwd}).`});if(!i)return(0,X.jsx)(B,{compact:!0,hostName:e.hostName,connectivity:e.link===`reconnecting`?`reconnecting`:`unreachable`,lastSeenAt:e.host?.lastSeenAt,detail:`Files are read from the host; browsing resumes when it reconnects.`});if(l!==null)return(0,X.jsx)(Ta,{ctx:e,file:l,status:g.get(l),onBack:()=>u(null)});let x=[],S=[],C=(e,t)=>{let n=a.get(e);if(n===void 0||n===`loading`)(e!==``||n===`loading`)&&S.push({dir:e,depth:t,state:`loading`});else if(!Array.isArray(n))S.push({dir:e,depth:t,state:n});else for(let i of n){let n=Sa(i,r,e);x.push({entry:i,rel:n,depth:t}),i.kind===`dir`&&s.has(n)&&C(n,t+1)}};C(``,0);let w=d.trim().toLowerCase(),T=[];if(w){for(let[e,t]of a)if(Array.isArray(t))for(let n of t){let t=Sa(n,r,e);n.kind!==`dir`&&t.toLowerCase().includes(w)&&T.push({entry:n,rel:t,depth:0})}T.sort((e,t)=>e.rel.localeCompare(t.rel))}let E=a.get(``),D=w?T.slice(0,200):x,O=p&&D.some(e=>e.rel===p)?p:D[0]?.rel,k=(e,t)=>{let n=[...h.current?.querySelectorAll(`[role=treeitem]`)??[]];n[n.indexOf(e)+t]?.focus()};return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2 px-2 py-2`,children:[(0,X.jsx)(yt,{type:`search`,"aria-label":`Filter files`,placeholder:`Filter files`,value:d,onChange:e=>f(e.target.value),className:`w-full`}),E&&!Array.isArray(E)&&E!==`loading`?(0,X.jsx)(H,{compact:!0,title:`Could not list this folder`,error:E.error,onRetry:()=>y(``,!0)}):E===void 0||E===`loading`?(0,X.jsx)(P,{label:`Loading folder…`}):w&&T.length===0?(0,X.jsx)(U,{title:`No matching files`,className:`py-6`}):!w&&x.length===0?(0,X.jsx)(U,{title:`Empty folder`,className:`py-6`}):(0,X.jsxs)(`div`,{ref:h,role:`tree`,"aria-label":`Workspace files`,className:`flex min-w-0 flex-col`,children:[D.map(({entry:e,rel:t,depth:n})=>{let r=e.kind===`dir`,i=r&&s.has(t),a=r?i?hn:_n:e.kind===`symlink`?Ke:xa(e.name),o=g.get(t);return(0,X.jsx)(`div`,{role:`none`,className:`min-w-0`,children:(0,X.jsxs)(`button`,{type:`button`,role:`treeitem`,"aria-selected":!1,"aria-expanded":r?i:void 0,tabIndex:t===O?0:-1,onFocus:()=>m(t),style:{paddingLeft:8+n*14},className:`flex h-8 w-full min-w-0 items-center gap-1.5 rounded pr-2 text-left text-[13px] hover:bg-surface-2`,onClick:()=>r?b(t):u(t),onKeyDown:e=>{if(e.key===`ArrowDown`)e.preventDefault(),k(e.currentTarget,1);else if(e.key===`ArrowUp`)e.preventDefault(),k(e.currentTarget,-1);else if(e.key===`ArrowRight`&&r&&!i)e.preventDefault(),b(t);else if(e.key===`ArrowLeft`){if(e.preventDefault(),r&&i)b(t);else if(t.includes(`/`)){let e=_a(t);h.current?.querySelector(`[data-path="${CSS.escape(e)}"]`)?.focus()}}},"data-path":t,children:[w?null:r?(0,X.jsx)(je,{"aria-hidden":!0,className:M(`size-4 shrink-0 text-muted transition-transform`,i&&`rotate-90`)}):(0,X.jsx)(`span`,{className:`size-4 shrink-0`}),(0,X.jsx)(a,{"aria-hidden":!0,className:`size-4 shrink-0 text-muted`}),(0,X.jsxs)(`span`,{className:M(`min-w-0 flex-1 truncate`,w&&`font-mono text-xs`),children:[w?t:e.name,(0,X.jsxs)(`span`,{className:`sr-only`,children:[` `,r?`folder`:`file`]})]}),r&&_.has(t)&&(0,X.jsx)(`span`,{title:`Contains changes`,className:`size-1.5 shrink-0 rounded-full bg-warning`}),!r&&(0,X.jsx)(Ca,{status:o}),!r&&e.size!==null&&(0,X.jsx)(`span`,{className:`shrink-0 text-xs text-subtle tabular-nums`,children:ba(e.size)})]})},t)}),!w&&S.map(e=>(0,X.jsx)(`div`,{role:`none`,style:{paddingLeft:8+e.depth*14},children:e.state===`loading`?(0,X.jsx)(`span`,{className:`flex h-8 items-center text-xs text-muted`,children:`Loading…`}):(0,X.jsx)(H,{compact:!0,title:`Could not list this folder`,error:e.state.error,onRetry:()=>y(e.dir,!0)})},`x-${e.dir}`))]}),w&&(0,X.jsx)(`p`,{className:`text-xs text-muted`,children:`Searches folders you have opened.`})]})}function Ta({ctx:e,file:t,status:n,onBack:r}){let i=e.workspace,[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(!0),[d,f]=(0,Y.useState)(0),[p,m]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(`preview`),[_,v]=(0,Y.useState)(null),y=t.split(`/`).pop()??t,b=ya(t),x=[`md`,`mdx`,`markdown`].includes(b),S=b===`svg`,C=ha[b],w=xa(y);(0,Y.useEffect)(()=>{let e=new AbortController;return u(!0),c(null),o(null),Q.file(i.id,t,e.signal).then(e=>o(e)).catch(t=>{e.signal.aborted||c(t)}).finally(()=>{e.signal.aborted||u(!1)}),()=>e.abort()},[i.id,t,d]);let T=a&&!a.binary?a.text:null,E=T===null?null:T.replace(/\n$/,``).split(`
|
|
10
|
+
`).length,D=_a(t),O=e=>{ve(e,`Copied`)},k=`flex justify-center bg-[conic-gradient(var(--sy-surface-2)_25%,var(--sy-surface)_0_50%,var(--sy-surface-2)_0_75%,var(--sy-surface)_0)] bg-[length:16px_16px] p-4`,A;return l?A=(0,X.jsx)(P,{label:`Loading file…`}):s===null?a&&C&&a.base64?A=(0,X.jsx)(`div`,{className:k,children:(0,X.jsx)(`img`,{alt:y,className:`max-h-[60vh] max-w-full`,src:`data:${C};base64,${a.base64}`,onLoad:e=>v(`${e.currentTarget.naturalWidth}×${e.currentTarget.naturalHeight}`)})}):T!==null&&S&&h===`preview`?A=(0,X.jsx)(`div`,{className:k,children:(0,X.jsx)(`img`,{alt:y,className:`max-h-[60vh] max-w-full`,src:`data:image/svg+xml;charset=utf-8,${encodeURIComponent(T)}`})}):T!==null&&x&&h===`preview`?A=(0,X.jsx)(`div`,{className:`px-4 py-2`,children:(0,X.jsx)(wt,{text:T})}):T===null?a&&(A=(0,X.jsx)(U,{title:`Binary file`,description:`${a.size===null?`Unknown size`:ba(a.size)} — not shown`})):A=(0,X.jsx)(ma,{text:T,lang:Ct(t),wrap:p}):A=N(s,`too_large`)?(0,X.jsx)(U,{title:`Too large to preview`,description:`Switchyard previews files up to 1 MB.`}):(0,X.jsx)(H,{compact:!0,title:`Could not read this file`,error:s,onRetry:()=>f(e=>e+1)}),(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1 border-b border-border px-3 pt-2 pb-2`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(J,{size:`sm`,label:`Back to files`,icon:(0,X.jsx)(me,{className:`size-4`}),onClick:r}),(0,X.jsx)(w,{"aria-hidden":!0,className:`size-4 shrink-0 text-muted`}),(0,X.jsx)(`h3`,{className:`min-w-0 flex-1 truncate font-medium`,children:y}),n&&(0,X.jsx)(`span`,{className:M(`shrink-0 text-xs font-medium`,ga[n].tone),children:Hi[n]})]}),(0,X.jsxs)(`p`,{className:`min-w-0 truncate text-xs text-muted`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:D||(i.branch??`root`)}),a?.size!=null&&` · ${ba(a.size)}`,E!==null&&` · ${E} lines`,_&&` · ${_}`]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(x||S)&&T!==null&&(0,X.jsx)(Dt,{label:`View`,value:h,onChange:g,options:[{value:`preview`,label:`Preview`},{value:`source`,label:`Source`}]}),T!==null&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(J,{size:`sm`,label:p?`Don't wrap lines`:`Wrap lines`,"aria-pressed":p,icon:(0,X.jsx)(Yn,{className:`size-4`}),onClick:()=>m(e=>!e)}),(0,X.jsx)(J,{size:`sm`,label:`Copy contents`,icon:(0,X.jsx)(ye,{className:`size-4`}),onClick:()=>O(T)})]}),(0,X.jsx)(J,{size:`sm`,label:`Copy path`,icon:(0,X.jsx)(Ke,{className:`size-4`}),onClick:()=>O(t)})]})]}),(0,X.jsx)(`div`,{className:`min-w-0 pb-3`,children:A})]})}function Ea({ctx:e,actions:t,tab:n,onTab:r,openPath:i,className:a,hideTitle:o}){let s=(0,Y.useId)(),c=T(e.session.id),l=e.workspace?.git.changedFiles??0,u=Bi(e),[d,f]=(0,Y.useState)(()=>new Set([n]));(0,Y.useEffect)(()=>f(e=>e.has(n)?e:new Set(e).add(n)),[n]);let p=[{id:`changes`,body:(0,X.jsx)(Xi,{ctx:e,diff:u})},{id:`files`,body:(0,X.jsx)(wa,{ctx:e,diff:u,openPath:i}),flush:!0},{id:`task`,body:(0,X.jsx)(sa,{ctx:e,actions:t})},{id:`extensions`,body:(0,X.jsx)(da,{ctx:e})}];return(0,X.jsxs)(`aside`,{"data-testid":`inspector`,"aria-label":`Inspector`,className:M(`flex min-h-0 min-w-0 flex-col bg-surface`,a),children:[!o&&(0,X.jsx)(`h2`,{className:`sr-only`,children:`Inspector`}),(0,X.jsx)(St,{idPrefix:s,label:`Inspector`,value:n,onChange:e=>r(e),className:`shrink-0 px-2`,scrollable:!0,tabs:[{id:`changes`,label:`Changes`,badge:(0,X.jsx)(_,{count:l,label:`changed files`,tone:`neutral`})},{id:`files`,label:`Files`},{id:`task`,label:`Task`},{id:`extensions`,label:`Extensions`,badge:(0,X.jsx)(_,{count:c.length,label:`panels`,tone:`neutral`})}]}),p.map(e=>(0,X.jsx)(Et,{idPrefix:s,id:e.id,hidden:n!==e.id,className:M(`relative min-h-0 min-w-0 flex-1 overflow-x-hidden overflow-y-auto overscroll-contain`,e.flush?`p-0`:`p-3`),children:(n===e.id||d.has(e.id))&&e.body},e.id))]})}function Da(e,t,n){return n?[...e,t]:e.filter(e=>e!==t)}function Oa({editing:e,onClose:t,onSaved:n}){let r=K(e=>e.views),i=D(),a=b(),[o,s]=(0,Y.useState)(e),c=o&&o!==`new`?r[o]??null:null,[l,u]=(0,Y.useState)(``),[d,f]=(0,Y.useState)(`all`),[p,m]=(0,Y.useState)([]),[h,g]=(0,Y.useState)([]),[_,v]=(0,Y.useState)(!1),[y,x]=(0,Y.useState)(null),[S,C]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{s(e)},[e]),(0,Y.useEffect)(()=>{u(c?.name??``),f(c?.mode??`all`),m(c?.projectIds??[]),g(c?.hostIds??[]),x(null)},[c]);let w=async()=>{v(!0),x(null);let e={name:l.trim(),mode:d,projectIds:p.length?p:null,hostIds:h.length?h:null};try{n((c?await re(`/api/views/${encodeURIComponent(c.id)}`,e):await W(`/api/views`,e)).id),t()}catch(e){x(e)}finally{v(!1)}},T=async()=>{if(c){v(!0);try{await z(`/api/views/${encodeURIComponent(c.id)}`),C(!1),t()}catch(e){x(e)}finally{v(!1)}}},E=N(y,`conflict`)?G(y):null,O=o!==null;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ht,{open:O&&!S,onClose:t,title:c?`Edit view`:`New view`,description:`A herdr or tmux session named like a view mirrors it.`,footer:(0,X.jsxs)(X.Fragment,{children:[c&&(0,X.jsx)(F,{variant:`danger`,onClick:()=>C(!0),className:`mr-auto`,children:`Delete`}),(0,X.jsx)(F,{onClick:t,children:`Cancel`}),(0,X.jsx)(F,{variant:`primary`,busy:_,disabled:!l.trim(),onClick:()=>void w(),children:`Save`})]}),children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[Object.keys(r).length>0&&(0,X.jsx)(ge,{label:`View`,id:`sy-view-pick`,children:e=>(0,X.jsxs)(Ot,{...e,value:o??``,onChange:e=>s(e.target.value||`new`),children:[(0,X.jsx)(`option`,{value:`new`,children:`New view`}),Object.values(r).map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,X.jsx)(ge,{label:`Name`,id:`sy-view-name`,error:E,children:e=>(0,X.jsx)(yt,{...e,value:l,maxLength:60,onChange:e=>u(e.target.value)})}),(0,X.jsx)(ge,{label:`Contents`,id:`sy-view-mode`,children:e=>(0,X.jsxs)(Ot,{...e,value:d,onChange:e=>f(e.target.value),children:[(0,X.jsx)(`option`,{value:`all`,children:`Matching sessions, plus pinned`}),(0,X.jsx)(`option`,{value:`pinned`,children:`Only pinned sessions`})]})}),d===`all`&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`fieldset`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)(`legend`,{className:`text-sm font-medium`,children:`Projects (none checked: any)`}),i.map(e=>(0,X.jsx)($e,{label:e.name,checked:p.includes(e.id),onChange:t=>m(Da(p,e.id,t))},e.id))]}),(0,X.jsxs)(`fieldset`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)(`legend`,{className:`text-sm font-medium`,children:`Hosts (none checked: any)`}),a.map(e=>(0,X.jsx)($e,{label:e.name,checked:h.includes(e.id),onChange:t=>g(Da(h,e.id,t))},e.id))]})]}),y!==null&&!E&&(0,X.jsx)(H,{compact:!0,title:`Could not save`,error:G(y)})]})}),(0,X.jsx)(_t,{open:O&&S,onClose:()=>C(!1),title:`Delete this view?`,description:`Sessions are not affected. herdr and tmux sessions bound to it stop mirroring and keep their tabs.`,confirmLabel:`Delete view`,busy:_,error:y,onConfirm:()=>void T()})]})}function ka(){return ft(`codeView`,null)}function Aa(e){return{filter:`active`,query:``,collapsed:[],layout:e?`recent`:`projects`,showSubagents:!1,sorts:{},needsInputFirst:!0}}function ja({selectedId:e,onNewSession:t,variant:r,className:i,style:a}){let o=r===`screen`,s=Aa(o),[c,l]=ft(o?`sessionList`:`navigator`,s),u={...s,...c},d=K(e=>e.hydrated),f=K(e=>e.projects),p=K(e=>e.workspaces),m=K(e=>e.sessions),h=u.sorts?.[u.layout]??wr[u.layout],g=K(e=>e.hosts),_=K(e=>e.views),[v,y]=ka(),[x,S]=(0,Y.useState)(null),C=(v?_[v]:null)??null,w=K(e=>e.attention),T=K(e=>e.interactions),E=b(),O=D(),k=(0,Y.useMemo)(()=>Rr({projects:f,workspaces:p,sessions:m,hosts:g,attention:w,interactions:T},{filter:u.filter,query:u.query,layout:u.layout,showSubagents:u.showSubagents,sort:h,needsInputFirst:u.needsInputFirst,view:C}),[f,p,m,g,w,T,u.filter,u.query,u.layout,u.showSubagents,h,u.needsInputFirst,C]),A=n(),ee=(0,Y.useMemo)(()=>{let e=j(w,T);return Or(Object.values(m).filter(e=>e.archivedAt===null&&e.provenance!==`subagent`).map(t=>({session:t,bucket:Dr(t,e.has(t.id))})))},[m,w,T]),te=new Set(u.collapsed),ne=e=>{let t=new Set(te);t.has(e)?t.delete(e):t.add(e),l({...u,collapsed:[...t]})},re=Br(k),N=[{id:`layout-heading`,heading:`Group sessions`},...Sr.map(e=>({id:`layout-${e.value}`,label:e.label,hint:e.hint,kind:`radio`,checked:u.layout===e.value,onSelect:()=>l({...u,layout:e.value})})),`separator`,{id:`sort-heading`,heading:`Sort sessions`},...Cr.map(e=>({id:`sort-${e.value}`,label:e.label,hint:e.value===wr[u.layout]?`${e.hint} (default)`:e.hint,kind:`radio`,checked:h===e.value,onSelect:()=>l({...u,sorts:{...u.sorts,[u.layout]:e.value}})})),{id:`needs-first`,label:`Needs input first`,kind:`checkbox`,checked:u.needsInputFirst,onSelect:()=>l({...u,needsInputFirst:!u.needsInputFirst})},`separator`,{id:`subagents`,label:`Show subagents`,kind:`checkbox`,checked:u.showSubagents,onSelect:()=>l({...u,showSubagents:!u.showSubagents})}],ie=re.some(e=>!te.has(e)),I=o?[{value:`active`,label:`Active`},{value:`attention`,label:`Needs input`},{value:`all`,label:`All`}]:[{value:`active`,label:`Active`},{value:`all`,label:`All`}],L;if(!d)L=(0,X.jsx)(P,{label:`Loading sessions…`});else if(E.length===0)L=(0,X.jsx)(U,{icon:(0,X.jsx)(et,{className:`size-8`}),title:`Connect a host`,description:`Sessions run on a host: a computer with Pi and the Switchyard host agent.`,action:{label:`Connect a host`,to:`/settings/hosts`},secondaryAction:O.length===0?{label:`Add a project`,to:`/settings/projects`}:void 0});else if(O.length===0){let e=E.find(e=>!e.revokedAt&&e.connectivity===`connected`);L=(0,X.jsxs)(X.Fragment,{children:[e&&(0,X.jsx)(Oe,{host:e,compact:!0}),(0,X.jsx)(U,{icon:(0,X.jsx)(De,{className:`size-8`}),title:`Add a project`,description:`Point Switchyard at a Git checkout on one of your hosts to start sessions there.`,action:{label:`Add a project`,to:`/settings/projects`}})]})}else L=zr(k)?u.query?(0,X.jsx)(U,{icon:(0,X.jsx)(Qe,{className:`size-8`}),title:`No matches`,description:`Nothing matches "${u.query}".`,action:{label:`Clear search`,onClick:()=>l({...u,query:``})}}):(0,X.jsx)(U,{title:u.filter===`attention`?`Nothing needs your input`:u.filter===`active`?`No active sessions`:`No sessions yet`,description:`Start a session in one of your projects.`,action:{label:`New session`,onClick:()=>t()},secondaryAction:u.filter===`all`?void 0:{label:`Show all`,onClick:()=>l({...u,filter:`all`})}}):u.layout===`recent`?(0,X.jsx)(`ul`,{"aria-label":`Recent sessions`,className:`flex min-w-0 flex-col gap-0.5 pb-4`,children:k.rows.map(t=>(0,X.jsx)(Fa,{row:t,indent:0,selected:t.session.id===e,screen:o},t.session.id))}):(0,X.jsx)(`ul`,{"aria-label":u.layout===`hosts`?`Hosts`:u.layout===`status`?`Status`:`Projects`,className:`flex min-w-0 flex-col gap-1 pb-4`,children:k.groups.map(n=>(0,X.jsx)(Na,{group:n,depth:0,collapsed:te,toggle:ne,selectedId:e,screen:o,onNewSession:t},n.key))});return(0,X.jsxs)(`nav`,{"data-testid":`navigator`,"aria-label":`Sessions`,style:a,className:M(`flex min-h-0 min-w-0 flex-col bg-surface`,i),children:[(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-b border-border px-3 pt-3 pb-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`h2`,{className:M(`min-w-0 flex-1 font-semibold`,o?`text-lg`:`text-sm`),children:`Sessions`}),(0,X.jsx)(F,{"data-testid":`new-session`,size:`sm`,variant:`primary`,icon:(0,X.jsx)(Je,{className:`size-4`}),onClick:()=>t(),disabled:!d||E.length===0||O.length===0,children:`New session`})]}),ee.length>0&&(0,X.jsx)(`p`,{"data-testid":`status-summary`,className:`flex flex-wrap items-center gap-x-1 text-xs text-muted`,children:ee.map((e,t)=>(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[t>0&&(0,X.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,X.jsxs)(`button`,{type:`button`,className:`tap rounded underline-offset-2 hover:underline`,onClick:()=>A(`/code/${encodeURIComponent(e.first)}`,{state:Ze}),children:[e.count,` `,Tr.find(t=>t.value===e.bucket)?.short]})]},e.bucket))}),d&&(E.length===0||O.length===0)&&(0,X.jsx)(`p`,{className:`text-xs text-muted`,children:E.length===0?`Connect a host to start sessions.`:`Add a project to start sessions.`}),(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(Qe,{"aria-hidden":!0,className:`pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-subtle`}),(0,X.jsx)(yt,{type:`search`,"aria-label":`Search sessions`,placeholder:`Search sessions, branches`,value:u.query,onChange:e=>l({...u,query:e.target.value}),className:`pl-8`})]}),(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-0.5`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,X.jsxs)(Ot,{"aria-label":`View`,value:C?.id??``,onChange:e=>y(e.target.value||null),children:[(0,X.jsx)(`option`,{value:``,children:`All sessions`}),Object.values(_).map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))]}),(0,X.jsx)(F,{onClick:()=>S(C?.id??`new`),children:C?`Edit`:`New view`})]}),C&&Mt(C).length>0&&(0,X.jsxs)(`p`,{className:`truncate text-subtle text-xs`,children:[`Open in:`,` `,Mt(C).map(e=>`${e.kind} ${e.name} (${e.machine})`).join(`, `)]})]}),(0,X.jsx)(Oa,{editing:x,onClose:()=>S(null),onSaved:e=>y(e)}),(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,X.jsx)(Dt,{label:`Session filter`,options:I,value:u.filter,onChange:e=>l({...u,filter:e}),className:`min-w-0 flex-1`,block:!0}),(0,X.jsx)(Ce,{label:`View options`,items:N,trigger:e=>(0,X.jsx)(J,{...e,label:`View options`,icon:(0,X.jsx)(Te,{className:`size-4`})})}),k.groups.length>0&&(0,X.jsx)(J,{label:ie?`Collapse all`:`Expand all`,icon:ie?(0,X.jsx)(Kt,{className:`size-4`}):(0,X.jsx)(Jt,{className:`size-4`}),onClick:()=>l({...u,collapsed:ie?re:[]})})]})]}),(0,X.jsx)(`div`,{className:`relative min-h-0 flex-1 overflow-x-hidden overflow-y-auto overscroll-contain px-2 pt-2`,children:L})]})}function Ma({group:e,depth:t,open:n}){let r=n?be:je;return t===0?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(r,{"aria-hidden":!0,className:`size-4 shrink-0 text-muted`}),e.kind===`host`&&(0,X.jsx)(et,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-muted`}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[e.label,e.detail&&(0,X.jsx)(`span`,{className:`ml-1.5 text-xs font-normal text-muted`,children:e.detail})]}),e.hostState&&e.hostState!==`connected`&&(0,X.jsx)(m,{kind:`host`,value:e.hostState,size:`sm`}),(0,X.jsxs)(`span`,{className:`shrink-0 text-xs font-normal text-muted`,children:[e.sessionCount,(0,X.jsx)(`span`,{className:`sr-only`,children:` sessions`})]})]}):e.kind===`workspace`?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(r,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-muted`}),(0,X.jsx)(Ue,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-muted`}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:`block truncate font-mono text-xs`,title:e.path??void 0,children:e.label}),e.detail&&(0,X.jsx)(`span`,{className:`block truncate text-xs text-muted`,children:e.detail})]})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(r,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-muted`}),(0,X.jsx)(De,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-muted`}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm`,children:e.label})]})}function Na({group:e,depth:t,collapsed:n,toggle:r,selectedId:i,screen:a,onNewSession:o}){let s=!n.has(e.key),c=e.kind===`project`?br(e.key):null;return(0,X.jsxs)(`li`,{className:`min-w-0`,children:[(0,X.jsxs)(`div`,{className:`group/row flex min-w-0 items-center`,children:[(0,X.jsx)(`button`,{type:`button`,"aria-expanded":s,onClick:()=>r(e.key),className:M(`tap flex min-w-0 flex-1 items-center gap-1.5 rounded-md text-left hover:bg-surface-2`,t===0?`px-1.5 py-1.5 text-sm font-semibold`:`py-1 pr-1.5 pl-4`),children:(0,X.jsx)(Ma,{group:e,depth:t,open:s})}),c&&(0,X.jsx)(J,{size:`sm`,label:`New session in ${e.label}`,icon:(0,X.jsx)(Je,{className:`size-4`}),onClick:()=>o(c),className:`opacity-0 focus-visible:opacity-100 group-hover/row:opacity-100 max-md:opacity-100`})]}),s&&(0,X.jsxs)(`ul`,{className:M(`flex min-w-0 flex-col`,t>0&&`gap-0.5 py-0.5`),children:[e.rows.length===0&&e.groups.length===0&&(0,X.jsx)(`li`,{className:`px-7 py-1 text-xs text-muted`,children:`No sessions yet.`}),e.groups.map(e=>(0,X.jsx)(Na,{group:e,depth:t+1,collapsed:n,toggle:r,selectedId:i,screen:a,onNewSession:o},e.key)),e.rows.map(e=>(0,X.jsx)(Fa,{row:e,indent:t===0?1:2,selected:e.session.id===i,screen:a},e.session.id))]})]})}var Pa=[`pl-2`,`pl-7`,`pl-9`];function Fa({row:e,indent:t,selected:n,screen:i}){let{session:a,attention:o}=e,s=[R(a.lastActivityAt),e.project,e.host,e.branch].filter(Boolean).join(` · `);return(0,X.jsx)(`li`,{className:`min-w-0`,children:(0,X.jsxs)(r,{"data-testid":`session-row`,to:`/code/${encodeURIComponent(a.id)}`,state:Ze,"aria-current":n?`page`:void 0,className:M(`tap flex min-w-0 flex-col gap-0.5 rounded-md py-1.5 pr-2 hover:bg-surface-2`,Pa[t],i&&`py-2.5`,n&&`bg-accent-soft hover:bg-accent-soft`),children:[(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm`,children:a.title}),o&&a.runtime!==`waiting_input`&&(0,X.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-0.5 text-xs font-medium text-warning`,children:[(0,X.jsx)(x,{"aria-hidden":!0,className:`size-3.5`}),`Needs input`]})]}),(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-x-1.5`,children:[(0,X.jsx)(m,{kind:`custom`,status:Ia(e),size:`sm`}),a.provenance===`subagent`&&(0,X.jsx)(`span`,{className:`shrink-0 text-xs text-muted`,children:`Subagent`}),(0,X.jsx)(`span`,{className:`min-w-0 truncate text-xs text-muted`,children:s})]})]})})}function Ia(e){return e.bucket===`review`?g:e.bucket===`failed`?d.failed:La(e.session.runtime)}function La(e){let t=d[e];return e===`interrupted`?{...t,tone:`neutral`}:t}function Ra({open:e,onOpenChange:t,trigger:n,label:r,side:i=`bottom`,align:a=`start`,initialFocus:o,className:s,fitViewport:c,children:l}){let u=(0,Y.useId)(),d=(0,Y.useRef)(null),f=(0,Y.useRef)(null);pt(d,e,()=>t(!1),o);let[p,m]=(0,Y.useState)(null);return(0,Y.useLayoutEffect)(()=>{if(!e||!c){m(null);return}let t=()=>{let e=f.current?.getBoundingClientRect();if(!e)return;let t=Math.min(288,window.innerWidth-16),n=Math.min(Math.max(e.left,8),window.innerWidth-t-8);m(i===`top`?{position:`fixed`,width:t,left:n,bottom:window.innerHeight-e.top+4}:{position:`fixed`,width:t,left:n,top:e.bottom+4})};return t(),window.addEventListener(`resize`,t),()=>window.removeEventListener(`resize`,t)},[e,c,i]),(0,Y.useEffect)(()=>{if(!e)return;let n=e=>{let n=e.target;!d.current?.contains(n)&&!f.current?.contains(n)&&t(!1)};return document.addEventListener(`pointerdown`,n),()=>document.removeEventListener(`pointerdown`,n)},[e,t]),(0,X.jsxs)(`div`,{className:`relative inline-flex`,children:[n({ref:f,onClick:()=>t(!e),"aria-haspopup":`dialog`,"aria-expanded":e,"aria-controls":u}),e&&(0,X.jsx)(`div`,{ref:d,id:u,role:`dialog`,"aria-label":r,tabIndex:-1,style:p??void 0,className:M(p?`fixed`:`absolute`,`z-40 max-w-[calc(100vw-1rem)] rounded-lg border border-border bg-surface p-3 shadow-pop`,!p&&(i===`top`?`bottom-full mb-1`:`top-full mt-1`),!p&&(a===`end`?`right-0`:`left-0`),s),children:l})]})}var za=`tap h-9 min-w-0 max-w-full rounded-full border border-border bg-surface pr-7 pl-3 text-base text-text md:h-8 md:text-sm focus:border-accent focus:outline-none disabled:opacity-55`,Ba=`tap inline-flex h-9 min-w-0 max-w-full items-center gap-1 rounded-full border border-border bg-surface px-3 text-base text-text md:h-8 md:text-sm hover:bg-surface-2`;function Va({projects:e,value:t,onChange:n}){let r=(0,Y.useId)(),[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(0),u=(0,Y.useRef)(null),d=(0,Y.useMemo)(()=>e.filter(e=>Ae(e,o)),[e,o]),f=e.find(e=>e.id===t);if(e.length<=8)return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`label`,{htmlFor:r,className:`sr-only`,children:`Project`}),(0,X.jsx)(`select`,{id:r,className:za,value:t,onChange:e=>n(e.target.value),children:e.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]});let p=e=>{n(e),a(!1)};return(0,X.jsxs)(Ra,{open:i,onOpenChange:e=>{a(e),e&&(s(``),l(0))},label:`Choose a project`,initialFocus:u,fitViewport:!0,className:`p-2`,trigger:e=>(0,X.jsxs)(`button`,{type:`button`,...e,"aria-label":`Project: ${f?.name??`none`}`,className:Ba,children:[(0,X.jsx)(`span`,{className:`truncate`,children:f?.name??`Choose a project`}),(0,X.jsx)(be,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-muted`})]}),children:[(0,X.jsx)(yt,{ref:u,role:`combobox`,"aria-expanded":!0,"aria-controls":`${r}-list`,"aria-autocomplete":`list`,"aria-activedescendant":d[c]?`${r}-opt-${d[c].id}`:void 0,"aria-label":`Search projects`,placeholder:`Search projects`,value:o,onChange:e=>{s(e.target.value),l(0)},onKeyDown:e=>{if(e.key===`ArrowDown`)e.preventDefault(),l(e=>Math.min(d.length-1,e+1));else if(e.key===`ArrowUp`)e.preventDefault(),l(e=>Math.max(0,e-1));else if(e.key===`Enter`){e.preventDefault(),e.stopPropagation();let t=d[c];t&&p(t.id)}}}),(0,X.jsxs)(`ul`,{id:`${r}-list`,role:`listbox`,"aria-label":`Projects`,className:`mt-2 max-h-64 overflow-y-auto`,children:[d.length===0&&(0,X.jsx)(`li`,{className:`px-2 py-2 text-sm text-muted`,children:`No projects match.`}),d.map((e,n)=>(0,X.jsxs)(`li`,{id:`${r}-opt-${e.id}`,role:`option`,"aria-selected":e.id===t,onPointerDown:e=>e.preventDefault(),onMouseEnter:()=>l(n),onClick:()=>p(e.id),className:M(`flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm`,n===c&&`bg-surface-2`),children:[(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:`block truncate`,children:e.name}),(0,X.jsx)(`span`,{className:`block truncate text-xs text-muted`,children:Ee(e.repoIdentity)})]}),e.id===t&&(0,X.jsx)(_e,{"aria-hidden":!0,className:`size-4 shrink-0 text-accent`})]},e.id))]})]})}var Ha=new Map;function Ua(e,t){t.trim()&&Ha.set(e,t)}function Wa(e){return Ha.get(e)??null}var Ga=`__new`;function Ka(e,t){let n=D(),r=K(e=>e.workspaces),i=K(e=>e.checkouts),a=K(e=>e.profiles),o=K(e=>e.hosts),s=K(e=>e.projects),c=rt(e=>e.selectedProjectId),l=rt(e=>e.lastNewSessionProjectId),u=(0,Y.useMemo)(()=>Object.values(a).sort((e,t)=>e.name.localeCompare(t.name)),[a]),[d,f]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(``),[h,g]=(0,Y.useState)(Ga),[_,v]=(0,Y.useState)(``),[y,b]=(0,Y.useState)(``),[x,S]=(0,Y.useState)(!1),[C,w]=(0,Y.useState)(``),[T,E]=(0,Y.useState)(``),[O,k]=(0,Y.useState)(``),[A,ee]=(0,Y.useState)(``),[te,j]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{if(!e)return;let r=[t,l,c].find(e=>!!e&&!!s[e]);f(r??n[0]?.id??``)},[e,t]);let ne=n.find(e=>e.id===d),M=(0,Y.useMemo)(()=>Object.values(r).filter(e=>e.projectId===d&&!e.archivedAt),[r,d]),re=(0,Y.useMemo)(()=>Object.values(i).filter(e=>e.projectId===d).sort((e,t)=>e.createdAt.localeCompare(t.createdAt)),[i,d]),N=(0,Y.useMemo)(()=>[...new Set(re.map(e=>e.hostId))].sort((e,t)=>(o[e]?.name??``).localeCompare(o[t]?.name??``)),[re,o]);(0,Y.useEffect)(()=>{if(!e||!ne)return;let t=xr(ne,re,M,o);m(t.hostId),g(t.workspaceId??Ga),v(t.checkoutId??``),E(``),w(``),b(``),S(!1)},[e,d]);let P=e=>{if(!ne)return;let t=xr(ne,re,M,o,e);m(t.hostId),g(t.workspaceId??Ga),v(t.checkoutId??``)},F=(0,Y.useMemo)(()=>M.filter(e=>e.hostId===p).sort(_r),[M,p]),ie=(0,Y.useMemo)(()=>re.filter(e=>e.hostId===p),[re,p]),I=h===Ga?`new`:`existing`,L=I===`existing`?r[h]:void 0,R=i[_]??ie[0],z=o[p],B=(0,Y.useMemo)(()=>yr(vr(O),M.map(e=>e.branch)),[O,M]),V=x?y:B,H=null;ne?N.length===0?H=`This project has no checkout yet. Add one in Settings › Projects.`:z?gr(z)?z.piCompatible?I===`existing`&&!L?H=`Choose a workspace.`:I===`new`&&!R?H=`No checkout of ${ne.name} on ${z.name}.`:I===`new`&&(H=hr(V)):H=`Pi ${z.piVersion??`(not found)`} on ${z.name} is outside the tested range.`:H=`${z.name} is offline.`:H=`Choose a host.`:H=`Choose a project.`;let ae=null;return L?ae={text:`${Ar(L)} on ${z?.name??`unknown host`}`,path:L.path}:I===`new`&&R&&(ae={text:`New worktree ${V.trim()} from ${C.trim()||R.defaultBranch} on ${z?.name??`unknown host`}`,path:mr(R.path,V,ne?.worktreeDir)}),{projects:n,profiles:u,hosts:o,project:ne,projectId:d,setProjectId:f,hostId:p,hostIds:N,changeHost:P,workspaceId:h,setWorkspaceId:g,hostWorkspaces:F,hostCheckouts:ie,setCheckoutId:v,mode:I,workspace:L,checkout:R,host:z,branch:y,setBranch:b,branchTouched:x,setBranchTouched:S,base:C,setBase:w,profileId:T,setProfileId:E,prompt:O,setPrompt:k,title:A,setTitle:ee,advancedOpen:te,setAdvancedOpen:j,suggested:B,effectiveBranch:V,problem:H,summary:ae,reset:()=>{k(``),ee(``),b(``),S(!1),w(``),j(!1)}}}function qa({open:e,onClose:t,onCreated:n,mobile:r,projectId:i=null}){let a=(0,Y.useId)(),o=Ka(e,i),[s]=ka(),c=K(e=>e.views),l=s&&c[s]?s:null,[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{e||(p(null),d(!1))},[e]);let m=async()=>{if(!(o.problem||u)){d(!0),p(null);try{let e=await Q.createSession({projectId:o.projectId,workspace:o.mode===`existing`?{existingId:o.workspaceId}:{checkoutId:o.checkout?.id??``,newBranch:o.effectiveBranch.trim(),base:o.base.trim()||null},profileId:o.profileId||null,prompt:o.prompt,...o.title.trim()?{title:o.title.trim()}:{},...l?{viewId:l}:{}});K.getState().upsertSessionIfMissing(e),Ua(e.id,o.prompt),rt.getState().set(`lastNewSessionProjectId`,o.projectId),o.reset(),n(e.id)}catch(e){p(e)}finally{d(!1)}}},h=e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&!e.nativeEvent.isComposing&&(e.preventDefault(),m())},g=typeof navigator<`u`&&/Mac|iPhone|iPad/.test(navigator.platform)?`⌘ Enter`:`Ctrl+Enter`,_=o.profiles.find(e=>e.id===o.project?.defaultProfileId),v=f===null?null:(0,X.jsx)(H,{compact:!0,title:`Could not create the session`,error:G(f),onRetry:()=>void m()}),y=o.projects.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`Add a project in Settings first.`}):(0,X.jsxs)(`form`,{className:`flex min-w-0 flex-col gap-3`,onSubmit:e=>{e.preventDefault(),m()},onKeyDown:h,children:[(0,X.jsxs)(`label`,{htmlFor:`${a}-prompt`,className:`text-base font-medium`,children:[`What should Pi do? `,(0,X.jsx)(`span`,{className:`text-sm font-normal text-muted`,children:`(optional)`})]}),(0,X.jsx)(vt,{id:`${a}-prompt`,autoFocus:!0,minRows:r?6:5,maxHeight:`40vh`,value:o.prompt,onChange:e=>o.setPrompt(e.target.value),placeholder:`Describe the task. Leave empty to start Pi without a prompt.`}),(0,X.jsxs)(`div`,{role:`group`,"aria-label":`Session options`,className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,X.jsx)(Va,{projects:o.projects,value:o.projectId,onChange:o.setProjectId}),(0,X.jsx)(`label`,{htmlFor:`${a}-ws`,className:`sr-only`,children:`Workspace`}),(0,X.jsxs)(`select`,{id:`${a}-ws`,className:za,value:o.workspaceId,onChange:e=>o.setWorkspaceId(e.target.value),children:[o.hostWorkspaces.map(e=>(0,X.jsxs)(`option`,{value:e.id,children:[Ar(e),e.provenance===`main`?` (main checkout)`:``]},e.id)),(0,X.jsx)(`option`,{value:Ga,disabled:o.hostCheckouts.length===0,children:`New worktree…`})]}),o.hostIds.length>1&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`label`,{htmlFor:`${a}-host`,className:`sr-only`,children:`Host`}),(0,X.jsx)(`select`,{id:`${a}-host`,className:`tap h-9 min-w-0 max-w-full rounded-full border border-border bg-surface pr-7 pl-3 text-base text-text md:h-8 md:text-sm focus:border-accent focus:outline-none disabled:opacity-55`,value:o.hostId,onChange:e=>o.changeHost(e.target.value),children:o.hostIds.map(e=>(0,X.jsxs)(`option`,{value:e,disabled:!gr(o.hosts[e]),children:[o.hosts[e]?.name??`Removed host`,gr(o.hosts[e])?``:` (offline)`]},e))})]}),o.profiles.length>0&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`label`,{htmlFor:`${a}-profile`,className:`sr-only`,children:`Pi profile`}),(0,X.jsxs)(`select`,{id:`${a}-profile`,className:`tap h-9 min-w-0 max-w-full rounded-full border border-border bg-surface pr-7 pl-3 text-base text-text md:h-8 md:text-sm focus:border-accent focus:outline-none disabled:opacity-55`,value:o.profileId,onChange:e=>o.setProfileId(e.target.value),children:[(0,X.jsx)(`option`,{value:``,children:_?`${_.name} (project default)`:`Pi defaults`}),o.profiles.filter(e=>e.id!==o.project?.defaultProfileId).map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))]})]})]}),o.mode===`new`&&(0,X.jsxs)(`div`,{className:`grid min-w-0 gap-3 sm:grid-cols-2`,children:[(0,X.jsx)(ge,{label:`Branch`,id:`${a}-branch`,hint:(0,X.jsxs)(X.Fragment,{children:[hr(o.effectiveBranch)??(o.branchTouched&&o.branch!==o.suggested?`Custom branch name.`:`Suggested from the prompt.`),o.branchTouched&&o.branch!==o.suggested&&(0,X.jsxs)(X.Fragment,{children:[` `,(0,X.jsx)(`button`,{type:`button`,className:`font-medium text-accent`,onClick:()=>{o.setBranch(``),o.setBranchTouched(!1)},children:`Use suggested name`})]})]}),children:(0,X.jsx)(yt,{id:`${a}-branch`,value:o.effectiveBranch,autoCapitalize:`off`,autoCorrect:`off`,spellCheck:!1,onChange:e=>{o.setBranch(e.target.value),o.setBranchTouched(!0)}})}),(0,X.jsx)(ge,{label:`Base branch`,id:`${a}-base`,hint:`Defaults to ${o.checkout?.defaultBranch??`the default branch`}.`,children:(0,X.jsx)(yt,{id:`${a}-base`,value:o.base,placeholder:o.checkout?.defaultBranch??`main`,autoCapitalize:`off`,autoCorrect:`off`,spellCheck:!1,onChange:e=>o.setBase(e.target.value)})})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`button`,{type:`button`,"aria-expanded":o.advancedOpen,"aria-controls":`${a}-adv`,onClick:()=>o.setAdvancedOpen(!o.advancedOpen),className:`tap inline-flex items-center gap-1 text-sm font-medium text-muted hover:text-text`,children:[o.advancedOpen?(0,X.jsx)(be,{"aria-hidden":!0,className:`size-4`}):(0,X.jsx)(je,{"aria-hidden":!0,className:`size-4`}),`Advanced`]}),o.advancedOpen&&(0,X.jsxs)(`div`,{id:`${a}-adv`,className:`mt-2 flex min-w-0 flex-col gap-3`,children:[(0,X.jsx)(ge,{label:`Session title`,optional:!0,id:`${a}-title`,children:(0,X.jsx)(yt,{id:`${a}-title`,value:o.title,placeholder:`Named from the prompt`,onChange:e=>o.setTitle(e.target.value)})}),o.mode===`new`&&o.hostCheckouts.length>1&&(0,X.jsx)(ge,{label:`Checkout`,id:`${a}-checkout`,children:(0,X.jsx)(Ot,{id:`${a}-checkout`,value:o.checkout?.id??``,onChange:e=>o.setCheckoutId(e.target.value),children:o.hostCheckouts.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.path},e.id))})})]})]}),o.summary&&(0,X.jsxs)(`p`,{"data-testid":`new-session-summary`,className:`flex min-w-0 items-center gap-1.5 text-xs text-muted`,title:o.summary.path,children:[(0,X.jsx)(Ue,{"aria-hidden":!0,className:`size-3.5 shrink-0`}),(0,X.jsxs)(`span`,{className:`min-w-0 truncate`,children:[o.summary.text,` · `,(0,X.jsx)(`span`,{className:`font-mono`,children:o.summary.path})]})]}),v]}),b=(0,X.jsxs)(X.Fragment,{children:[o.problem?(0,X.jsxs)(`p`,{role:`status`,"aria-live":`polite`,className:`mr-auto flex min-w-0 flex-1 basis-full items-start gap-1 text-xs text-muted sm:basis-auto`,children:[(0,X.jsx)(le,{"aria-hidden":!0,className:`mt-0.5 size-3.5 shrink-0 text-warning`}),o.problem]}):r?null:(0,X.jsxs)(`span`,{className:`mr-auto text-xs text-subtle`,children:[g,` to create`]}),(0,X.jsx)(F,{onClick:t,children:`Cancel`}),(0,X.jsx)(F,{variant:`primary`,busy:u,disabled:!!o.problem,onClick:()=>void m(),children:`Create session`})]});return r?(0,X.jsx)(mt,{fullHeight:!0,open:e,onClose:t,title:`New session`,dismissOnBackdrop:!u,footer:b,children:y}):(0,X.jsx)(ht,{open:e,onClose:t,title:`New session`,dismissOnBackdrop:!u,className:`max-w-xl`,footer:b,children:y})}function Ja({label:e,value:t}){return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`dt`,{className:`text-muted`,children:e}),(0,X.jsx)(`dd`,{className:`min-w-0 font-mono text-xs break-all`,children:t})]})}function Ya({session:e,hostLabel:t,open:n,onClose:r}){let i=Mi(e),a=e.stats;return(0,X.jsx)(ht,{open:n,onClose:r,title:`Session info`,children:(0,X.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-2 text-sm`,children:[(0,X.jsx)(Ja,{label:`Switchyard session`,value:e.id}),(0,X.jsx)(Ja,{label:`Pi session id`,value:e.nativeHandle?.sessionId??`Not started`}),(0,X.jsx)(Ja,{label:`Session file`,value:e.nativeHandle?.sessionFile??`None yet`}),(0,X.jsx)(Ja,{label:`Host`,value:t}),(0,X.jsx)(Ja,{label:`Working directory`,value:e.cwd}),(0,X.jsx)(Ja,{label:`Origin`,value:e.provenance}),(0,X.jsx)(Ja,{label:`Profile`,value:e.profileSnapshot.name}),(0,X.jsx)(Ja,{label:`Created`,value:I(e.createdAt)}),a?.tokens!=null&&(0,X.jsx)(Ja,{label:`Tokens`,value:a.tokens.toLocaleString(`en-US`)}),a?.costUsd!=null&&(0,X.jsx)(Ja,{label:`Cost`,value:`$${a.costUsd.toFixed(2)}`}),i&&(0,X.jsx)(Ja,{label:`Context`,value:`${i.label} (${i.detail})`})]})})}function Xa(e){let{session:t,run:r,control:i}=e,a=n(),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(t.title),u=Li(()=>Q.takeover(t.id),{success:`You have control. Automatic continuations are paused.`,errorToast:!0}),d=Li(()=>Q.returnToAutomation(t.id),{success:`Returned to automation.`,errorToast:!0}),f=Li(()=>Q.stop(t.id),{success:`Session stopped.`}),p=Li(()=>Q.resume(t.id),{success:`Session resumed.`,errorToast:!0}),m=Li(e=>Q.rename(t.id,e),{success:`Session renamed.`}),h=Li(()=>Q.archive(t.id),{success:`Session archived.`}),g=Li(()=>Q.unarchive(t.id),{success:`Session unarchived.`,errorToast:!0}),_=e.link===`connected`,v=()=>{s(null),f.reset(),m.reset(),h.reset()},y=fr(t)?`Stop the session before archiving it`:null,b=(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_t,{open:o===`stop`,onClose:v,title:`Stop this session?`,description:`Stops the current execution and clears queued messages.`,confirmLabel:`Stop session`,busy:f.busy,error:f.error,errorTitle:`Could not stop`,onConfirm:()=>void f.run().then(e=>e&&s(null)),children:(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:r?`The task keeps its run, marked interrupted and blocked (Stopped by user). Automation settings are unchanged.`:`Pi stays available; you can send a new message afterwards.`})}),(0,X.jsx)(ht,{open:o===`rename`,onClose:v,title:`Rename session`,footer:(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(F,{onClick:v,children:`Cancel`}),(0,X.jsx)(F,{variant:`primary`,type:`submit`,form:`sy-rename-form`,busy:m.busy,disabled:!c.trim(),children:`Save`})]}),children:(0,X.jsxs)(`form`,{id:`sy-rename-form`,onSubmit:e=>{e.preventDefault(),c.trim()&&m.run(c.trim()).then(e=>e&&s(null))},className:`flex flex-col gap-2`,children:[(0,X.jsx)(ge,{id:`sy-rename-input`,label:`Title`,children:(0,X.jsx)(yt,{id:`sy-rename-input`,value:c,maxLength:200,onChange:e=>l(e.target.value)})}),m.error!==null&&(0,X.jsx)(H,{compact:!0,title:`Could not rename`,error:G(m.error)})]})}),(0,X.jsx)(_t,{open:o===`archive`,onClose:v,title:`Archive this session?`,description:`It leaves the navigator. The Pi session file stays on the host.`,danger:!1,confirmLabel:`Archive`,busy:h.busy,error:h.error,errorTitle:`Could not archive`,onConfirm:()=>void h.run().then(e=>{e&&(s(null),a(`/code`))}),children:t.runtime===`idle`&&(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`The idle Pi process is stopped first.`})}),(0,X.jsx)(Ya,{session:t,hostLabel:`${e.hostName} (${e.link})`,open:o===`info`,onClose:v})]});return{canTakeover:i===`automation`,canReturn:i===`human`,canStop:fr(t)&&_,canResume:!dr(t)&&!!t.nativeHandle&&!t.readOnly&&_,archiveBlocked:y,takeover:()=>void u.run(),returnToAutomation:()=>void d.run(),requestStop:()=>s(`stop`),resume:()=>void p.run(),openRename:()=>{l(t.title),s(`rename`)},requestArchive:()=>{y?q.info(y):s(`archive`)},openInfo:()=>s(`info`),unarchive:()=>void g.run(),setPinned:(e,n)=>{let r=`/api/views/${encodeURIComponent(e)}/sessions/${encodeURIComponent(t.id)}`;(n?W(r):z(r)).catch(e=>q.error(G(e)))},busy:{takeover:u.busy,ret:d.busy,stop:f.busy,resume:p.busy,unarchive:g.busy},dialogs:b}}function Za({view:e,open:t,busy:n,mobile:r,onClose:i,onRun:a}){if(!e)return null;let o=e.actions.length>0?(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.actions.map(e=>(0,X.jsx)(F,{size:`sm`,variant:e.tone===`primary`?`primary`:e.tone===`danger`?`danger`:`secondary`,disabled:n,onClick:()=>a(e.command),children:e.label},e.command))}):void 0,s=(0,X.jsx)(Ve,{node:e.body});return r?(0,X.jsx)(mt,{open:t,onClose:i,title:e.title,footer:o,children:s}):(0,X.jsx)(gt,{open:t,onClose:i,title:e.title,footer:o,width:720,children:s})}function Qa(){if(typeof window>`u`)return null;let e=window;return e.SpeechRecognition??e.webkitSpeechRecognition??null}function $a(e,t,n,r){let i=r.trim();if(!i)return{text:e,caret:t};let a=e.slice(0,t),o=e.slice(n),s=a!==``&&!/\s$/.test(a)?` `:``,c=o!==``&&!/^\s/.test(o)?` `:``;return{text:a+(s+i+c)+o,caret:a.length+s.length+i.length+c.length}}function eo(e){let t=Qa(),[n,r]=(0,Y.useState)(!1),[i,a]=(0,Y.useState)(``),o=(0,Y.useRef)(null),s=(0,Y.useRef)(e.onFinal);s.current=e.onFinal;let c=(0,Y.useCallback)(()=>{o.current?.stop()},[]),l=(0,Y.useCallback)(()=>{if(!t||o.current)return;let e=new t;e.continuous=!0,e.interimResults=!0,e.lang=navigator.language,e.onresult=e=>{let t=``;for(let n=e.resultIndex;n<e.results.length;n++){let r=e.results[n],i=r?.[0]?.transcript??``;r?.isFinal?s.current(i):t+=i}a(t)},e.onerror=e=>{e.error===`not-allowed`||e.error===`service-not-allowed`?q.error(`Microphone access is blocked for this site`):e.error!==`no-speech`&&e.error!==`aborted`&&q.error(`Dictation stopped: ${e.error}`)},e.onend=()=>{o.current=null,r(!1),a(``)},o.current=e,r(!0);try{e.start()}catch{o.current=null,r(!1)}},[t]);return(0,Y.useEffect)(()=>()=>o.current?.abort(),[]),{supported:t!==null,listening:n,interim:i,start:l,stop:c}}var to=`#ef4444`,no={crop:null,shapes:[]},ro=e=>Math.min(1,Math.max(0,e));function io(e){if(!e)return null;let t=ro(Math.min(e.a[0],e.b[0])),n=ro(Math.max(e.a[0],e.b[0])),r=ro(Math.min(e.a[1],e.b[1])),i=ro(Math.max(e.a[1],e.b[1]));return n-t<.01||i-r<.01?null:{a:[t,r],b:[n,i]}}function ao(){return{past:[],present:no,future:[]}}function oo(e,t){let n=t=>({past:[...e.past,e.present],present:t,future:[]});switch(t.type){case`add`:return n({...e.present,shapes:[...e.present.shapes,t.shape]});case`crop`:return n({...e.present,crop:io(t.crop)});case`reset`:return n({crop:null,shapes:[]});case`undo`:{let t=e.past[e.past.length-1];return t?{past:e.past.slice(0,-1),present:t,future:[e.present,...e.future]}:e}case`redo`:{let t=e.future[0];return t?{past:[...e.past,e.present],present:t,future:e.future.slice(1)}:e}}}function so(e,t,n,r=4096){let i=io(n),a=i?Math.round(i.a[0]*e):0,o=i?Math.round(i.a[1]*t):0,s=i?Math.max(1,Math.round((i.b[0]-i.a[0])*e)):e,c=i?Math.max(1,Math.round((i.b[1]-i.a[1])*t)):t,l=Math.min(1,r/Math.max(s,c));return{sx:a,sy:o,sw:s,sh:c,dw:Math.max(1,Math.round(s*l)),dh:Math.max(1,Math.round(c*l))}}function co(e,t,n){let r=Math.atan2(e[1]-t[1],e[0]-t[0]),i=25*Math.PI/180,a=e=>[t[0]+n*Math.cos(e),t[1]+n*Math.sin(e)];return[a(r+i),a(r-i)]}function lo(e,t){return Math.max(4,Math.round(Math.max(e,t)*.004))}function uo(e,t,n,r,i){e.strokeStyle=to,e.lineWidth=r,e.lineCap=`round`,e.lineJoin=`round`;for(let r of t){if(e.beginPath(),r.kind===`pen`)r.points.forEach((t,r)=>{let[i,a]=n(t);r===0?e.moveTo(i,a):e.lineTo(i,a)});else if(r.kind===`ellipse`){let[t,i]=n(r.a),[a,o]=n(r.b);e.ellipse((t+a)/2,(i+o)/2,Math.max(1,Math.abs(a-t)/2),Math.max(1,Math.abs(o-i)/2),0,0,Math.PI*2)}else{let t=n(r.a),a=n(r.b),[o,s]=co(t,a,i);e.moveTo(t[0],t[1]),e.lineTo(a[0],a[1]),e.moveTo(o[0],o[1]),e.lineTo(a[0],a[1]),e.lineTo(s[0],s[1])}e.stroke()}}function fo(e){let t=atob(e.data),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return new Blob([n],{type:e.mimeType})}function po(e,t,n){return new Promise(r=>e.toBlob(r,t,n))}function mo(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(r.error),r.readAsDataURL(e)})}function ho({attachment:e,open:t,onClose:n,onDone:r,mobile:i}){let a=i?mt:ht,[o,s]=(0,Y.useState)(`pen`),[c,l]=(0,Y.useReducer)(oo,void 0,ao),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)(null),[m,h]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(null),v=(0,Y.useRef)(null),y=(0,Y.useRef)(null),b=c.present;(0,Y.useEffect)(()=>{if(!t)return;let n=!0;return createImageBitmap(fo(e)).then(e=>n&&d(e),()=>q.error(`Could not open this image`)),()=>{n=!1}},[t,e]),(0,Y.useEffect)(()=>{let e=v.current;if(!e||!u)return;let t=Math.min(window.innerWidth-48,720),n=Math.min(window.innerHeight*.6,560),r=Math.min(t/u.width,n/u.height,1);e.width=Math.round(u.width*r),e.height=Math.round(u.height*r);let i=e.getContext(`2d`);if(!i)return;i.drawImage(u,0,0,e.width,e.height);let a=t=>[t[0]*e.width,t[1]*e.height],o=f&&f.kind!==`pen`?[...b.shapes,f]:b.shapes;uo(i,f?.kind===`pen`?[...o,f]:o,a,Math.max(2,e.width*.004),e.width*.03);let s=g??b.crop;if(s){let[t,n]=a(s.a),[r,o]=a(s.b);i.fillStyle=`rgba(0,0,0,0.5)`,i.beginPath(),i.rect(0,0,e.width,e.height),i.rect(t,n,r-t,o-n),i.fill(`evenodd`)}},[u,b,f,g]);let x=e=>{let t=e.currentTarget.getBoundingClientRect();return[Math.min(1,Math.max(0,(e.clientX-t.left)/t.width)),Math.min(1,Math.max(0,(e.clientY-t.top)/t.height))]},S=(e,t,n)=>o===`pen`?{kind:`pen`,points:[...n?.kind===`pen`?n.points:[e],t]}:{kind:o===`ellipse`?`ellipse`:`arrow`,a:e,b:t},C=e=>{e.currentTarget.setPointerCapture(e.pointerId),y.current=x(e),o===`pen`&&p({kind:`pen`,points:[y.current]})},w=e=>{let t=y.current;if(!t)return;let n=x(e);o===`crop`?T(t,n):p(e=>S(t,n,e))},T=(e,t)=>_({a:e,b:t}),E=()=>{y.current&&(y.current=null,o===`crop`?(g&&l({type:`crop`,crop:g}),_(null)):f&&(l({type:`add`,shape:f}),p(null)))},D=async()=>{if(u){h(!0);try{let t=so(u.width,u.height,b.crop),n=document.createElement(`canvas`);n.width=t.dw,n.height=t.dh;let i=n.getContext(`2d`);if(!i)throw Error(`Canvas is not available`);i.drawImage(u,t.sx,t.sy,t.sw,t.sh,0,0,t.dw,t.dh);let a=e=>[(e[0]*u.width-t.sx)*(t.dw/t.sw),(e[1]*u.height-t.sy)*(t.dh/t.sh)],o=lo(t.dw,t.dh);uo(i,b.shapes,a,o,o*5);let s=await po(n,`image/png`);if(s&&s.size>10485760&&(s=await po(n,`image/jpeg`,.9)),!s||s.size>10485760){q.error(`The edited image is over 10 MB; crop it smaller`);return}let c=ci(await mo(s));if(!c)throw Error(`Could not encode the image`);r({...e,mimeType:c.mimeType,data:c.data,size:s.size})}catch(e){q.error(e.message)}finally{h(!1)}}};return(0,X.jsx)(a,{open:t,onClose:n,title:`Mark up image`,dismissOnBackdrop:!1,className:i?void 0:`max-w-3xl`,fullHeight:i,footer:(0,X.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,X.jsx)(F,{variant:`ghost`,onClick:n,children:`Cancel`}),(0,X.jsx)(F,{variant:`primary`,busy:m,disabled:!u,onClick:()=>void D(),children:`Done`})]}),children:(0,X.jsxs)(`div`,{className:`flex flex-col items-center gap-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(Dt,{label:`Tool`,value:o,onChange:s,options:[{value:`crop`,label:`Crop`,icon:(0,X.jsx)(en,{className:`size-4`})},{value:`pen`,label:`Pen`,icon:(0,X.jsx)(We,{className:`size-4`})},{value:`ellipse`,label:`Circle`,icon:(0,X.jsx)(Xt,{className:`size-4`})},{value:`arrow`,label:`Arrow`,icon:(0,X.jsx)(Rt,{className:`size-4`})}]}),(0,X.jsx)(J,{label:`Undo`,icon:(0,X.jsx)(Zn,{className:`size-4`}),disabled:c.past.length===0,onClick:()=>l({type:`undo`})}),(0,X.jsx)(J,{label:`Redo`,icon:(0,X.jsx)(zn,{className:`size-4`}),disabled:c.future.length===0,onClick:()=>l({type:`redo`})}),(0,X.jsx)(J,{label:`Reset`,icon:(0,X.jsx)(xe,{className:`size-4`}),onClick:()=>l({type:`reset`})})]}),(0,X.jsx)(`canvas`,{ref:v,"data-testid":`markup-canvas`,"aria-label":`Image to mark up`,className:`max-w-full rounded border border-border`,style:{touchAction:`none`},onPointerDown:C,onPointerMove:w,onPointerUp:E,onPointerCancel:E})]})})}function go({icon:e,label:t,ariaLabel:n,disabled:r,className:i,...a}){return(0,X.jsxs)(`button`,{type:`button`,disabled:r,"aria-label":n,className:M(`tap inline-flex h-8 min-w-0 items-center gap-1.5 rounded-md bg-surface-2 px-2.5 text-xs font-medium text-text transition-colors hover:bg-border disabled:opacity-55`,i),...a,children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:`shrink-0 text-muted`,children:e}),(0,X.jsx)(`span`,{className:`min-w-0 truncate`,children:t})]})}function _o({session:e,searchInFooter:t,searchRef:n,onChosen:r}){let[i,a]=(0,Y.useState)(null),[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(``),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)(`favorites`),g=(0,Y.useCallback)(()=>{let t=new AbortController;return s(null),Q.models(e.id,t.signal).then(e=>a(e.models),e=>{t.signal.aborted||s(e)}),()=>t.abort()},[e.id]);(0,Y.useEffect)(()=>g(),[g]);let _=async t=>{p(!0),l(null);try{await Q.setModel(e.id,t.provider,t.id),q.success(`Model: ${Oi(t)}`),r()}catch(e){l(e)}finally{p(!1)}},v=i?.some(e=>e.scoped===!0)??!1,y=v&&m===`favorites`,b=i&&y?Ei(i,e.model??null):i,x=b?ji(b,u):[],S=(0,X.jsx)(yt,{ref:n,placeholder:`Search models`,"aria-label":`Search models`,value:u,onChange:e=>d(e.target.value)});return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[!t&&S,v&&(0,X.jsx)(Dt,{label:`Show`,value:m,onChange:h,options:[{value:`favorites`,label:`Favorites`},{value:`all`,label:`All`}]}),c!=null&&(0,X.jsx)(H,{compact:!0,title:`Could not change`,error:c}),(0,X.jsx)(`div`,{className:`flex max-h-[60vh] min-w-0 flex-col gap-3 overflow-y-auto`,children:o==null?i?x.length===0?y?(0,X.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,children:[(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`No favorites match`}),(0,X.jsx)(F,{size:`sm`,variant:`ghost`,onClick:()=>h(`all`),children:`Search all models`})]}):(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`No models match`}):x.map(t=>(0,X.jsxs)(`section`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)(`h3`,{className:`text-xs font-medium text-muted`,children:t.provider}),t.models.map(t=>{let n=e.model?.provider===t.provider&&e.model.id===t.id;return(0,X.jsxs)(`button`,{type:`button`,disabled:f,"aria-current":n?`true`:void 0,onClick:()=>void _(t),className:`tap flex min-h-11 min-w-0 items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm hover:bg-surface-2 disabled:opacity-55`,children:[(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:`block truncate`,children:Oi(t)}),(0,X.jsxs)(`span`,{className:`block truncate font-mono text-xs text-muted`,children:[t.provider,`/`,t.id,t.contextWindow!==null&&` · ${Math.round(t.contextWindow/1e3)}k context`]})]}),n&&(0,X.jsx)(_e,{"aria-hidden":!0,className:`size-4`})]},t.id)})]},t.provider)):(0,X.jsx)(P,{label:`Loading models…`}):(0,X.jsx)(H,{title:`Could not load models`,error:o,onRetry:g})}),t&&(0,X.jsx)(`div`,{className:`sticky bottom-0 bg-surface pt-2`,children:S})]})}function vo({session:e,enabled:t,mobile:n,open:r,onOpenChange:i}){let a=(0,Y.useRef)(null),o=e.model;if(!o)return null;let s=Ti(o),c=t?`Model: ${s}. Change model`:`Model: ${s}`,l=t=>(0,X.jsx)(_o,{session:e,searchInFooter:t,searchRef:a,onChosen:()=>i(!1)});return n?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(go,{className:`max-w-[60vw]`,icon:(0,X.jsx)(Qt,{className:`size-3.5`}),label:s,ariaLabel:c,disabled:!t,onClick:()=>i(!0)}),(0,X.jsx)(mt,{open:r,onClose:()=>i(!1),title:`Model`,children:l(!0)})]}):(0,X.jsx)(Ra,{open:r,onOpenChange:i,side:`top`,align:`start`,label:`Model`,className:`w-96`,initialFocus:a,trigger:e=>(0,X.jsx)(go,{...e,className:`max-w-64`,icon:(0,X.jsx)(Qt,{className:`size-3.5`}),label:s,ariaLabel:c,disabled:!t}),children:l(!1)})}function yo(e){let t=e.model?.thinkingLevels??[],n=e.thinking??t[0]??`off`,[r,i]=(0,Y.useState)(n),a=(0,Y.useRef)(null),o=(0,Y.useRef)({draft:r,session:e});o.current={draft:r,session:e};let s=(0,Y.useCallback)(e=>{let t=o.current.session;e!==t.thinking&&Q.setThinking(t.id,e).catch(e=>{q.error(G(e)),i(t.thinking??t.model?.thinkingLevels[0]??`off`)})},[]),c=(0,Y.useCallback)(()=>{a.current!==null&&(clearTimeout(a.current),a.current=null,s(o.current.draft))},[s]);return(0,Y.useEffect)(()=>{a.current===null&&i(n)},[e.thinking,e.model?.id]),(0,Y.useEffect)(()=>c,[]),{level:r,setLevel:e=>{i(e),a.current!==null&&clearTimeout(a.current),a.current=setTimeout(()=>{a.current=null,s(e)},400)},flush:c}}function bo({levels:e,level:t,onChange:n,large:r}){let i=Di(e,t),a=Math.max(e.length-1,1),o=e=>`calc(8px + (100% - 16px) * ${e/a})`;return(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,X.jsx)(`span`,{className:`text-xs text-muted`,children:`Effort`}),(0,X.jsx)(`span`,{className:`text-sm font-medium capitalize`,children:t})]}),(0,X.jsxs)(`div`,{className:M(`group relative w-full`,r?`h-11`:`h-8`),children:[(0,X.jsx)(`div`,{className:`pointer-events-none absolute inset-x-2 top-1/2 h-0.5 -translate-y-1/2 rounded-full bg-border-strong`}),(0,X.jsx)(`div`,{className:`pointer-events-none absolute left-2 top-1/2 h-0.5 -translate-y-1/2 rounded-full bg-accent transition-[width]`,style:{width:`calc((100% - 16px) * ${i/a})`}}),e.map((e,t)=>(0,X.jsx)(`span`,{"aria-hidden":!0,"data-effort-dot":t===i?`selected`:void 0,className:M(`pointer-events-none absolute top-1/2 -translate-x-1/2 -translate-y-1/2 rounded-full transition-all`,t===i?`size-4 bg-accent ring-4 ring-accent-soft group-has-[input:focus-visible]:outline-2 group-has-[input:focus-visible]:outline-offset-2 group-has-[input:focus-visible]:outline-accent`:t<i?`size-2.5 bg-accent`:`size-2.5 bg-border-strong`),style:{left:o(t)}},e)),(0,X.jsx)(`input`,{type:`range`,min:0,max:e.length-1,step:1,value:i,onChange:t=>n(e[Number(t.target.value)]),"aria-label":`Effort`,"aria-valuetext":t,className:`peer absolute inset-0 m-0 h-full w-full cursor-pointer appearance-none bg-transparent opacity-0 [&::-moz-range-thumb]:size-4 [&::-webkit-slider-thumb]:size-4 [&::-webkit-slider-thumb]:appearance-none`})]}),(0,X.jsx)(`div`,{className:`relative h-4 text-[11px] text-muted`,children:e.map((e,t)=>(0,X.jsx)(`span`,{className:M(`absolute top-0 -translate-x-1/2 whitespace-nowrap`,t===i&&`font-medium text-text`),style:{left:o(t)},children:e},e))}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-muted`,children:`Applies from the next turn.`})]})}function xo({session:e,enabled:t,mobile:n}){let[r,i]=(0,Y.useState)(!1),a=yo(e),o=e.model?.thinkingLevels??[];if(!e.model||o.length<=1)return null;let s=e=>{e||a.flush(),i(e)},c={icon:(0,X.jsx)(Ht,{className:`size-3.5`}),label:a.level,ariaLabel:`Effort: ${a.level}`,disabled:!t,className:`shrink-0 capitalize`};return(0,X.jsx)(Ra,{open:r,onOpenChange:s,side:`top`,align:`start`,label:`Effort`,className:`w-72`,fitViewport:n,trigger:e=>(0,X.jsx)(go,{...e,...c}),children:(0,X.jsx)(bo,{levels:o,level:a.level,onChange:a.setLevel,large:n})})}var So={neutral:`text-muted`,warning:`text-warning`,danger:`text-danger`};function Co({usage:e}){if(e.status===`error`)return null;if(e.status!==`available`)return(0,X.jsx)(`span`,{title:e.message??void 0,className:`text-[11px] leading-4 text-muted`,children:`Usage unavailable`});if(e.windows.length===0)return null;let t={five_hour:`5h`,weekly:`wk`},n=e.windows.map(e=>`${e.id===`five_hour`?`Session limit`:`Weekly limit`} ${Math.round(e.usedPct)}% used, resets ${R(e.resetsAt)}`).join(`; `);return(0,X.jsx)(`span`,{title:n,className:`text-[11px] leading-4 tabular-nums`,"data-testid":`usage-meter`,children:e.windows.map((e,n)=>(0,X.jsxs)(`span`,{children:[n>0&&(0,X.jsx)(`span`,{className:`text-muted`,children:` · `}),(0,X.jsxs)(`span`,{className:So[ai(e.usedPct)],children:[t[e.id],` `,Math.round(e.usedPct),`%`]})]},e.id))})}function wo({session:e,enabled:t}){let n=Mi(e);if(!n)return null;let r=fr(e),i=t?e.compacting?`Compaction is running`:r?`Wait for the run to finish`:void 0:`The session is not running`,a=[{id:`detail`,heading:n.detail},{id:`compact`,label:`Compact now`,icon:(0,X.jsx)(Gn,{className:`size-4`}),disabled:!!i,hint:i,onSelect:()=>{Q.compact(e.id).then(()=>q.success(`Compacting context`),e=>q.error(G(e)))}}],o={danger:`bg-danger`,warning:`bg-warning`,muted:`bg-subtle`}[n.tone];return(0,X.jsx)(Ce,{side:`top`,align:`start`,label:`Context`,items:a,className:`w-full`,trigger:t=>(0,X.jsxs)(`button`,{type:`button`,...t,"aria-label":e.compacting?`Context compacting`:n.percent===null?`Context use not known yet`:`Context ${n.label} used`,title:e.compacting?n.detail:`Context ${n.label} used · ${n.detail}`,className:`relative flex w-full items-center gap-2 py-0.5 text-[11px] leading-4 text-muted transition-colors before:absolute before:inset-x-0 before:-top-3 before:bottom-0 before:content-[''] hover:text-text [@media(pointer:coarse)]:before:-top-6`,children:[(0,X.jsx)(`span`,{className:`h-[3px] flex-1 overflow-hidden rounded-full bg-surface-2`,children:(0,X.jsx)(`span`,{className:M(`block h-full rounded-full transition-[width]`,o),style:{width:`${Math.min(100,n.percent??0)}%`}})}),(0,X.jsx)(`span`,{className:`tabular-nums`,children:e.compacting?n.label:`Context ${n.label}`})]})})}function To({mobile:e,...t}){return e?(0,X.jsx)(mt,{...t}):(0,X.jsx)(ht,{...t})}function Eo({session:e,mode:t,open:n,mobile:r,onClose:i,onPick:a}){let[o,s]=(0,Y.useState)(null),[c,l]=(0,Y.useState)(null);(0,Y.useEffect)(()=>{if(!n)return;s(null),l(null);let t=!0;return Q.tree(e.id).then(e=>t&&s(e.rows),e=>t&&l(e)),()=>{t=!1}},[n,e.id]);let u=o===null?[]:t===`fork`?o.filter(e=>e.role===`user`&&e.activeBranch).reverse():o;return(0,X.jsx)(To,{mobile:r,open:n,onClose:i,title:t===`fork`?`Fork from a message`:`Start a new session from…`,children:c===null?o===null?(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`Loading…`}):u.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`Nothing to branch from yet`}):(0,X.jsx)(`ul`,{className:`flex max-h-[60vh] flex-col gap-1 overflow-y-auto`,children:u.map(e=>(0,X.jsx)(`li`,{style:{paddingLeft:`${Math.min(e.depth,8)*12}px`},children:(0,X.jsxs)(`button`,{type:`button`,onClick:()=>a(e.entryId),className:M(`flex w-full min-w-0 items-start gap-2 rounded-md border-l-2 px-2 py-1.5 text-left text-sm hover:bg-surface-2`,e.activeBranch?`border-accent`:`border-transparent`),children:[(0,X.jsx)(`span`,{className:`w-8 shrink-0 text-xs text-muted`,children:e.role===`user`?`You`:`Pi`}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.text||`(empty)`}),e.label&&(0,X.jsx)(f,{children:e.label}),e.leaf&&(0,X.jsx)(f,{children:`current`})]})},e.entryId))}):(0,X.jsx)(H,{compact:!0,title:`Could not load the conversation`,error:G(c)})})}function Do({session:e,open:t,mobile:n,onClose:r,onOpen:i}){let[a,o]=(0,Y.useState)(null),[s,c]=(0,Y.useState)(null),[l,u]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{if(!t)return;o(null),c(null);let n=!0;return Q.importable(e.hostId).then(e=>n&&o(e),e=>n&&c(e)),()=>{n=!1}},[t,e.hostId]);let d=(a??[]).filter(t=>t.cwd===e.cwd&&t.sessionFile!==e.nativeHandle?.sessionFile).sort((e,t)=>String(t.mtime).localeCompare(String(e.mtime))),f=async t=>{try{if(t.importedSessionId){i(t.importedSessionId);return}u(!0);let n=await Q.importSession(e.hostId,t.sessionFile,e.projectId);K.getState().upsertSessionIfMissing(n),i(n.id)}catch(e){c(e)}finally{u(!1)}};return(0,X.jsx)(To,{mobile:n,open:t,onClose:r,title:`Open another Pi session`,children:s===null?a===null?(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`Loading…`}):d.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`No other Pi sessions in this folder`}):(0,X.jsx)(`ul`,{className:`flex max-h-[60vh] flex-col gap-1 overflow-y-auto`,children:d.map(e=>{let t=e.importedSessionId!==null||e.inactive;return(0,X.jsx)(`li`,{children:(0,X.jsxs)(`button`,{type:`button`,disabled:!t||l,onClick:()=>void f(e),className:`flex w-full min-w-0 flex-col rounded-md px-2 py-1.5 text-left text-sm hover:bg-surface-2 disabled:opacity-60`,children:[(0,X.jsx)(`span`,{className:`truncate`,children:e.name??e.sessionId}),(0,X.jsxs)(`span`,{className:`text-xs text-muted`,children:[R(e.mtime),!t&&` · Open in Pi; close it there to import`]})]})},e.sessionFile)})}):(0,X.jsx)(H,{compact:!0,title:`Could not open it`,error:G(s)})})}var Oo={switchyard:`Switchyard`,extension:`Extension`,prompt:`Prompt`,skill:`Skill`,terminal:`Terminal only`};function ko({id:e,items:t,active:n,onPick:r,onHover:i,className:a}){return(0,X.jsx)(`div`,{className:a,children:(0,X.jsx)(`div`,{role:`listbox`,id:e,"aria-label":`Arguments`,"data-testid":`arg-completions`,className:`max-h-72 overflow-y-auto`,children:t.map((t,a)=>(0,X.jsx)(`div`,{role:`option`,id:`${e}-${a}`,"aria-selected":a===n,tabIndex:-1,className:M(`cursor-pointer rounded-md px-2 py-1.5 text-sm`,a===n&&`bg-surface-2`),onMouseDown:e=>e.preventDefault(),onClick:()=>r(t.value),onKeyDown:()=>void 0,onMouseEnter:()=>i?.(a),children:(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`font-mono`,children:t.label}),t.description&&(0,X.jsx)(`span`,{className:`truncate text-xs text-muted`,children:t.description})]})},t.value))})})}function Ao({id:e,entries:t,active:n,onPick:r,onHover:i,status:a,className:o}){let s=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>{s.current?.querySelector(`[id="${e}-${n}"]`)?.scrollIntoView?.({block:`nearest`})},[n,e]),(0,X.jsxs)(`div`,{className:o,children:[(0,X.jsx)(`div`,{ref:s,role:`listbox`,id:e,"aria-label":`Commands`,className:`max-h-72 overflow-y-auto`,children:t.map((t,a)=>(0,X.jsxs)(`div`,{role:`option`,id:`${e}-${a}`,"aria-selected":a===n,"aria-disabled":t.source===`terminal`||void 0,tabIndex:-1,className:M(`cursor-pointer rounded-md px-2 py-1.5 text-sm`,a===n&&`bg-surface-2`,t.source===`terminal`&&`opacity-60`),onMouseDown:e=>e.preventDefault(),onClick:()=>r(t),onKeyDown:()=>void 0,onMouseEnter:()=>i?.(a),children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,X.jsxs)(`span`,{className:`font-mono`,children:[`/`,t.name]}),t.argumentHint&&(0,X.jsx)(`span`,{className:`text-muted`,children:t.argumentHint}),(0,X.jsx)(f,{className:`ml-auto`,children:Oo[t.source]})]}),t.description&&(0,X.jsx)(`div`,{className:`truncate text-xs text-muted`,children:t.description})]},`${t.source}:${t.name}`))}),a&&(0,X.jsx)(`p`,{className:`px-2 py-1 text-xs text-muted`,children:a})]})}var jo={for:``,items:[],prefix:``};function Mo(e,t,n){let[r,i]=(0,Y.useState)(jo);return(0,Y.useEffect)(()=>{if(!n||!yi(t)){i(jo);return}let r=new AbortController,a=setTimeout(()=>{Q.complete(e,t,r.signal).then(e=>{r.signal.aborted||i({for:t,items:e.items,prefix:e.prefix})}).catch(()=>{r.signal.aborted||i(jo)})},150);return()=>{clearTimeout(a),r.abort()}},[e,t,n]),r.for===t?{items:r.items.filter(e=>e.value!==r.prefix),prefix:r.prefix}:{items:[],prefix:``}}var No=new Map,Po=3e4;function Fo(e,t){let[n,r]=(0,Y.useState)(No.get(e)?.commands??[]),[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(null),c=(0,Y.useRef)(null),l=(0,Y.useCallback)(()=>{let n=No.get(e);if(r(n?.commands??[]),s(null),a(!1),c.current?.abort(),!t||n&&Date.now()-n.at<Po)return;let i=new AbortController;c.current=i,a(!0),Q.commands(e,i.signal).then(t=>{i.signal.aborted||(No.set(e,{at:Date.now(),commands:t.commands}),r(t.commands))}).catch(e=>{i.signal.aborted||s(e)}).finally(()=>{i.signal.aborted||a(!1)})},[e,t]);return(0,Y.useEffect)(()=>(l(),()=>c.current?.abort()),[l]),{commands:n,loading:i,error:o,refresh:l}}var Io=`Automation is active; take over to stop automatic continuations`;function Lo({ctx:e,draft:t,setDraft:r,clearDraft:i,replyNotes:a,mobile:o,className:s}){let{session:c,host:l}=e,u=rt(e=>e.sendWithEnter),[d,f]=(0,Y.useState)([]),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(null),[_,v]=(0,Y.useState)(!1),[y,b]=(0,Y.useState)(!1),[x,S]=(0,Y.useState)(null),[C,w]=(0,Y.useState)(!1),T=o?mt:ht,[E,D]=(0,Y.useState)(!1),[O,k]=(0,Y.useState)(0),[A,ee]=(0,Y.useState)(!1),[te,j]=(0,Y.useState)(null),[ne,re]=(0,Y.useState)(!1),[N,P]=(0,Y.useState)(null),ie=n(),I=(0,Y.useRef)(null),L=(0,Y.useRef)(null),R=(0,Y.useRef)(null),z=(0,Y.useId)(),B=eo({onFinal:e=>{let n=I.current,i=$a(t,n?.selectionStart??t.length,n?.selectionEnd??t.length,e);r(i.text),requestAnimationFrame(()=>I.current?.setSelectionRange(i.caret,i.caret))}});nt(o&&_),(0,Y.useEffect)(()=>{f([]),g(null),B.stop()},[c.id]);let V=Jr({session:c,hostLink:e.link,hostName:e.hostName}),ae=Xr(c,l?.capabilities),oe=fr(c),U=t.trim(),se=!!a&&a.notes.length>0&&!U.startsWith(`/`),ce=!U&&!se,le=!o&&!E&&/^\/\S*$/.test(t)&&_,W=Ni(l,V),{commands:ue,error:de,loading:fe,refresh:pe}=Fo(c.id,W),me=W?vi(mi,ue):[],[he,ge]=(0,Y.useState)(!1),_e=Mo(c.id,t,W&&_&&!le),ye=_e.items.length>0&&!he,be=W&&!le&&!ye?xi(t,me):null,xe=e=>{r(bi(t,_e.prefix,e)),I.current?.focus()},Se=le?Si(me,t.slice(1)):[],Ce=W?Ci(U):null,we=Ce?wi(Ce,oe,!!c.nativeHandle):null,[Te]=ka(),Ee=K(e=>e.views),De=K(e=>ii(c,e.hosts[c.hostId])),Oe=e=>ie(`/code/${encodeURIComponent(e)}`),ke=async e=>{if(!c.projectId||!c.workspaceId)throw Error(`This session has no project workspace`);let t=await Q.createSession({projectId:c.projectId,workspace:{existingId:c.workspaceId},prompt:e,...Te&&Ee[Te]?{viewId:Te}:{}});return K.getState().upsertSessionIfMissing(t),e&&Ua(t.id,e),t},Ae=async e=>{if(e.session){K.getState().upsertSessionIfMissing(e.session),e.prefill&<(e.session.id,e.prefill),Q.resume(e.session.id).catch(()=>{}),Oe(e.session.id);return}let t=await ke(``);lt(t.id,e.prefill??``),Oe(t.id)},je=async e=>{re(!0);try{let t=await Q.prompt(c.id,{text:e,mode:`prompt`});t?.result?.view?j(t.result.view):(j(null),q.success(`Ran ${e}`))}catch(e){q.error(G(e))}finally{re(!1)}},Ne=async e=>{let t=N===`fork`;P(null);try{await Ae(await Q.branch(c.id,e,t))}catch(e){q.error(G(e))}},Pe=e=>{r(`/${e.name} `),I.current?.focus()};(0,Y.useEffect)(()=>{k(0),ge(!1)},[t]),(0,Y.useEffect)(()=>{(le||C)&&pe()},[le,C]);let Fe=async e=>{if(V||ce||p||we)return;B.stop();let n=t;m(e),g(null);try{if(Ce){await Ie(Ce),I.current?.value===n&&i(),D(!1);return}let t=await Q.prompt(c.id,{text:a?it(a.notes,U):U,mode:e,images:d.map(e=>({mimeType:e.mimeType,data:e.data})),clientMessageId:`cm_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`});I.current?.value===n&&i(),f([]),se&&a?.clear(),D(!1),t?.result?.view&&j(t.result.view),t?.automationActive?q.info(Io):e===`followUp`?q.success(`Follow-up queued`):e===`steer`&&q.success(`Steering message sent`)}catch(t){g({error:t,mode:e})}finally{m(null)}},Ie=async e=>{switch(e.kind){case`model-picker`:ee(!0);return;case`model`:await Q.setModel(c.id,e.provider,e.modelId),q.success(`Model: ${e.provider}/${e.modelId}`);return;case`thinking`:await Q.setThinking(c.id,e.level),q.success(`Effort: ${e.level}`);return;case`compact`:await Q.compact(c.id,e.instructions),q.success(`Compacting context`);return;case`name`:await Q.rename(c.id,e.title),q.success(`Session renamed`);return;case`new`:Oe((await ke(e.prompt)).id);return;case`fork`:P(`fork`);return;case`tree`:P(`tree`);return;case`resume`:P(`resume`);return;case`clone`:await Ae(await Q.branch(c.id,null,!1));return;case`reload`:await Q.reload(c.id),q.success(`Reloading Pi…`);return;case`export`:{let e=await Q.exportFile(c.id),t=URL.createObjectURL(new Blob([e.content],{type:`application/x-ndjson`})),n=document.createElement(`a`);n.href=t,n.download=e.fileName,n.click(),URL.revokeObjectURL(t);return}case`session`:P(`info`);return;case`copy`:c.lastAssistantText?await ve(c.lastAssistantText,`Copied the last reply`):q.info(`No reply to copy yet`);return;default:return}},Le=ae.prompt?`prompt`:ae.followUp?`followUp`:ae.steer?`steer`:null,Re=async e=>{if(e)for(let t of Array.from(e))try{let e=await li(t);f(t=>[...t,e])}catch(e){q.error(G(e))}},ze=V?V.reason:we||(oe&&!Le?`Pi is running and this runtime cannot queue messages; wait or stop the session`:ce&&d.length>0?`Add a message to send with the images`:null),Be=(0,Y.useRef)(null),Ve=(e,t)=>o?{onPointerDown:e=>e.preventDefault(),onTouchStart:e=>{let t=e.touches[0];Be.current=t?{x:t.screenX,y:t.screenY}:null},onTouchEnd:n=>{let r=Be.current;Be.current=null;let i=n.changedTouches[0];r&&i&&(Math.hypot(i.screenX-r.x,i.screenY-r.y)>12||(n.preventDefault(),t&&(Fe(e),I.current?.blur())))}}:void 0,He=W&&c.model?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(vo,{session:c,enabled:W,mobile:o,open:A,onOpenChange:ee}),(0,X.jsx)(`span`,{className:M(`contents`,oe&&`max-md:hidden`),children:(0,X.jsx)(xo,{session:c,enabled:W,mobile:o})})]}):null,Ue=c.queue.steering.length+c.queue.followUp.length;return(0,X.jsxs)(`section`,{"data-testid":`composer`,"aria-label":`Composer`,className:M(`shrink-0 border-t border-border bg-surface px-3 pt-2 md:px-6`,o?`safe-pb-2`:`pb-2`,s),children:[(0,X.jsxs)(`div`,{className:`flex w-full min-w-0 flex-col gap-2`,children:[W&&c.model&&(0,X.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,X.jsx)(wo,{session:c,enabled:W})}),De&&(0,X.jsx)(Co,{usage:De})]}),Ue>0&&(0,X.jsxs)(`p`,{className:`text-xs text-muted`,children:[c.queue.steering.length>0&&`${c.queue.steering.length} steering message${c.queue.steering.length===1?``:`s`} pending. `,c.queue.followUp.length>0&&`${c.queue.followUp.length} follow-up${c.queue.followUp.length===1?``:`s`} queued.`]}),a&&a.notes.length>0&&(0,X.jsx)(`ul`,{"aria-label":`Comments on the reply`,className:`flex flex-wrap gap-2`,children:a.notes.map(e=>(0,X.jsxs)(`li`,{className:`flex max-w-full items-center gap-1 rounded-md border border-border bg-surface-2 py-1 pr-1 pl-2 text-xs`,children:[(0,X.jsxs)(`span`,{className:`min-w-0 truncate`,children:[(0,X.jsxs)(`span`,{className:`text-muted`,children:[`“`,e.quote.trim().slice(0,40),`”`]}),` `,e.comment.trim().slice(0,40)]}),(0,X.jsx)(J,{size:`sm`,label:`Remove comment`,icon:(0,X.jsx)(Me,{className:`size-3.5`}),onClick:()=>a.remove(e.id)})]},e.id))}),d.map(e=>e.id===x?(0,X.jsx)(ho,{attachment:e,open:!0,mobile:o,onClose:()=>S(null),onDone:t=>{f(n=>n.map(n=>n.id===e.id?t:n)),S(null)}},e.id):null),d.length>0&&(0,X.jsx)(`ul`,{"aria-label":`Attachments`,className:`flex flex-wrap gap-2`,children:d.map(e=>(0,X.jsxs)(`li`,{className:`relative flex items-center gap-2 rounded-md border border-border bg-surface-2 py-1 pr-1 pl-1`,children:[(0,X.jsx)(`button`,{type:`button`,"aria-label":`Mark up ${e.name}`,className:`tap rounded`,onClick:()=>S(e.id),children:(0,X.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.data}`,alt:``,className:`size-9 rounded object-cover`})}),(0,X.jsx)(`span`,{className:`max-w-32 truncate text-xs`,children:e.name}),(0,X.jsx)(J,{size:`sm`,label:`Remove ${e.name}`,icon:(0,X.jsx)(Me,{className:`size-3.5`}),onClick:()=>f(t=>t.filter(t=>t.id!==e.id))})]},e.id))}),(0,X.jsxs)(`div`,{className:`relative min-w-0`,children:[ye&&(0,X.jsx)(ko,{className:`absolute bottom-full left-0 z-20 mb-1 w-full rounded-lg border border-border bg-surface p-1 shadow-pop`,id:`${z}-args`,items:_e.items,active:Math.min(O,_e.items.length-1),onPick:xe,onHover:k}),le&&W&&(0,X.jsx)(Ao,{className:`absolute bottom-full left-0 z-20 mb-1 w-full rounded-lg border border-border bg-surface p-1 shadow-pop`,id:`${z}-cmds`,entries:Se,active:O,onPick:Pe,onHover:k,status:fe&&ue.length===0?`Loading Pi's commands…`:de?`Pi's commands could not be loaded: ${G(de)}`:Se.length===0?`No matching command; Enter sends the text to Pi`:null}),be&&(0,X.jsxs)(`p`,{"data-testid":`command-args-hint`,className:`absolute bottom-full left-0 z-10 mb-1 rounded-md bg-surface px-2 py-0.5 font-mono text-xs text-muted`,children:[`/`,be.name,` `,be.hint]}),le&&!W&&(0,X.jsx)(Ro,{className:`absolute bottom-full left-0 z-20 mb-1 w-full rounded-lg border border-border bg-surface p-3 shadow-pop`,onClose:()=>D(!0)}),(0,X.jsx)(`label`,{htmlFor:`${z}-input`,className:`sr-only`,children:`Message to Pi`}),(0,X.jsx)(vt,{id:`${z}-input`,ref:I,value:t,minRows:o?1:2,maxHeight:`33vh`,disabled:c.readOnly,...le&&W?{role:`combobox`,"aria-autocomplete":`list`,"aria-expanded":!0,"aria-controls":`${z}-cmds`,"aria-activedescendant":Se.length?`${z}-cmds-${O}`:void 0}:{},"aria-describedby":ze?`${z}-reason`:void 0,placeholder:c.readOnly?Kr:oe?`Steer Pi or queue a follow-up…`:`Message Pi… (/ for commands)`,onChange:e=>{r(e.target.value),e.target.value.startsWith(`/`)||D(!1)},onFocus:()=>v(!0),onBlur:()=>v(!1),onPaste:e=>{let t=[...e.clipboardData.files].filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),Re(t))},enterKeyHint:o?`enter`:`send`,onKeyDown:e=>{if(ye){let t=_e.items.length;if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault(),k(n=>e.key===`ArrowDown`?(n+1)%t:(n-1+t)%t);return}if(e.key===`Tab`||e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault(),xe(_e.items[Math.min(O,t-1)].value);return}if(e.key===`Escape`){e.preventDefault(),ge(!0);return}}if(le&&W&&Se.length>0){if(e.key===`ArrowDown`||e.key===`ArrowUp`){e.preventDefault();let t=Se.length;k(n=>e.key===`ArrowDown`?(n+1)%t:(n-1+t)%t);return}if(e.key===`Tab`||e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing){e.preventDefault(),Pe(Se[Math.min(O,Se.length-1)]);return}}e.key===`Escape`&&le?(e.preventDefault(),D(!0)):e.key!==`Enter`||e.nativeEvent.isComposing||o||(u?!e.shiftKey:e.metaKey||e.ctrlKey)&&(e.preventDefault(),Le&&Fe(Le))}})]}),(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[(0,X.jsx)(`input`,{ref:L,type:`file`,accept:`image/*`,multiple:!0,hidden:!0,onChange:e=>{Re(e.target.files),e.target.value=``,b(!1)}}),(0,X.jsx)(`input`,{ref:R,type:`file`,accept:`image/*`,capture:`environment`,hidden:!0,onChange:e=>{Re(e.target.files),e.target.value=``,b(!1)}}),(0,X.jsx)(J,{label:`Attach images`,icon:(0,X.jsx)(Ln,{className:`size-4`}),disabled:c.readOnly,onClick:()=>o?b(!0):L.current?.click()}),(0,X.jsx)(J,{label:`Commands`,icon:(0,X.jsx)(qn,{className:`size-4`}),disabled:c.readOnly,onClick:()=>{o?w(!0):t.trim()===``?(r(`/`),D(!1),I.current?.focus()):/^\/\S*$/.test(t)?(D(!1),I.current?.focus()):w(!0)}}),B.supported&&(0,X.jsx)(J,{label:B.listening?`Stop dictation`:`Dictate`,icon:B.listening?(0,X.jsx)(Tn,{className:`size-4`}):(0,X.jsx)(Dn,{className:`size-4`}),variant:B.listening?`danger`:`ghost`,"aria-pressed":B.listening,disabled:c.readOnly,onPointerDown:e=>e.preventDefault(),onClick:()=>B.listening?B.stop():B.start()}),He?(0,X.jsx)(`div`,{"data-testid":`session-controls`,className:`flex min-w-0 flex-1 items-center gap-1 max-md:overflow-hidden`,children:He}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`hidden min-w-0 flex-1 truncate text-xs text-muted sm:inline`,title:`Profile, model and effort come from the session's Pi profile (Settings › Profiles). They apply when a session starts.`,children:Ai(c)}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 sm:hidden`})]}),!o&&!oe&&(0,X.jsx)(`span`,{className:`hidden text-xs text-subtle lg:inline`,children:u?`Enter to send · Shift+Enter for newline`:`Ctrl+Enter to send`}),oe?(0,X.jsxs)(X.Fragment,{children:[ae.steer&&(0,X.jsx)(F,{size:`sm`,className:`shrink-0`,icon:(0,X.jsx)(jn,{className:`size-3.5`}),busy:p===`steer`,disabled:!!V||ce||!!we||p!==null&&p!==`steer`,onClick:()=>void Fe(`steer`),...Ve(`steer`,!V&&!ce&&!we&&(p===null||p===`steer`)),children:(0,X.jsx)(`span`,{className:`max-[379px]:sr-only`,children:`Steer`})}),ae.followUp&&(0,X.jsxs)(F,{size:`sm`,variant:`primary`,className:`shrink-0`,icon:(0,X.jsx)(xn,{className:`size-3.5`}),busy:p===`followUp`,disabled:!!V||ce||!!we||p!==null&&p!==`followUp`,onClick:()=>void Fe(`followUp`),...Ve(`followUp`,!V&&!ce&&!we&&(p===null||p===`followUp`)),children:[(0,X.jsx)(`span`,{className:`max-[379px]:hidden`,children:`Queue follow-up`}),(0,X.jsx)(`span`,{className:`min-[380px]:hidden`,children:`Queue`})]})]}):(0,X.jsx)(F,{size:`sm`,variant:`primary`,icon:(0,X.jsx)(Un,{className:`size-3.5`}),busy:p===`prompt`,disabled:!!V||ce||!!we,onClick:()=>void Fe(`prompt`),...Ve(`prompt`,!V&&!ce&&!we&&p===null),children:`Send`})]}),oe&&!ae.steer&&l?.capabilities&&(0,X.jsx)(`p`,{className:`text-xs text-muted`,children:`Immediate steering is not supported by this runtime; messages are queued as follow-ups.`}),B.listening&&(0,X.jsxs)(`p`,{className:`text-xs text-muted`,"aria-live":`polite`,children:[`Listening… `,B.interim]}),ze&&!V&&(0,X.jsx)(`p`,{id:`${z}-reason`,className:`text-xs text-muted`,children:ze}),V&&(0,X.jsxs)(`p`,{id:`${z}-reason`,className:`sr-only`,children:[`Sending is unavailable: `,V.reason]}),h&&(0,X.jsx)(H,{compact:!0,title:`Message not sent. Your draft is kept.`,error:G(h.error),onRetry:()=>void Fe(h.mode)})]}),(0,X.jsx)(mt,{open:y,onClose:()=>b(!1),title:`Attach images`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(F,{block:!0,icon:(0,X.jsx)(yn,{className:`size-4`}),onClick:()=>L.current?.click(),children:`Choose photos`}),(0,X.jsx)(F,{block:!0,icon:(0,X.jsx)(Wt,{className:`size-4`}),onClick:()=>R.current?.click(),children:`Take photo`}),(0,X.jsx)(`p`,{className:`text-xs text-muted`,children:`Images up to 10 MB are sent with your next message.`})]})}),(0,X.jsxs)(T,{open:C,onClose:()=>w(!1),title:`Commands`,children:[W?(0,X.jsx)(Ao,{id:`${z}-sheet-cmds`,entries:me,active:-1,status:fe&&ue.length===0?`Loading Pi's commands…`:de?`Pi's commands could not be loaded: ${G(de)}`:null,onPick:e=>{r(t.trim()===``||t.startsWith(`/`)?`/${e.name} `:`/${e.name} ${t}`),w(!1),requestAnimationFrame(()=>I.current?.focus())}}):(0,X.jsx)(Ro,{}),t.trim()===``&&(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(F,{block:!0,variant:`primary`,onClick:()=>{r(`/`),w(!1),requestAnimationFrame(()=>I.current?.focus())},children:`Start a command`})})]}),(0,X.jsx)(Eo,{session:c,mode:N===`fork`?`fork`:`tree`,open:N===`tree`||N===`fork`,mobile:o,onClose:()=>P(null),onPick:e=>void Ne(e)}),(0,X.jsx)(Do,{session:c,open:N===`resume`,mobile:o,onClose:()=>P(null),onOpen:e=>{P(null),Oe(e)}}),(0,X.jsx)(Ya,{session:c,hostLabel:`${e.hostName} (${e.link})`,open:N===`info`,onClose:()=>P(null)}),(0,X.jsx)(Za,{view:te,open:!!te,busy:ne,mobile:o,onClose:()=>j(null),onRun:e=>void je(e)})]})}function Ro({onClose:e,className:t}){return(0,X.jsx)(`div`,{role:`note`,"aria-label":`Slash commands`,className:t,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsxs)(`p`,{className:`min-w-0 flex-1 text-sm`,children:[`Text starting with `,(0,X.jsx)(`code`,{className:`font-mono`,children:`/`}),` is sent to Pi as a command (extension commands and prompt templates). Switchyard does not list Pi's commands; type the command name.`]}),e&&(0,X.jsx)(J,{size:`sm`,label:`Close command hint`,icon:(0,X.jsx)(Me,{className:`size-3.5`}),onClick:e})]})})}var zo={subagent:u,archived:It,host:de,answer:x,failed:Ne,interrupted:v,stopped:h,starting:h,compacting:h,automation:Bt,human:Ge},Bo={unarchive:Pt,answer:x,resume:qe,takeover:Ge,return:Bt},Vo={neutral:{row:`border-border-strong bg-surface-2`,icon:`text-muted`},info:{row:`border-info bg-surface-2`,icon:`text-info`},warning:{row:`border-warning bg-warning-soft`,icon:`text-warning`},danger:{row:`border-danger bg-danger-soft`,icon:`text-danger`}};function Ho({ctx:e,actions:t,onAnswer:n}){let r=E(e.session.id),i=Ri(e.link===`unreachable`,3e4),a=Yr({session:e.session,hostLink:e.link,hostName:e.hostName,hostLastSeenAt:e.host?.lastSeenAt,control:e.control,pending:r,canResume:t.canResume,now:i});if(!a)return null;let o=zo[a.kind],s=Vo[a.tone],c=a.action,l=c&&{unarchive:t.unarchive,answer:n,resume:t.resume,takeover:t.takeover,return:t.returnToAutomation}[c.kind],u=c?{unarchive:t.busy.unarchive,answer:!1,resume:t.busy.resume,takeover:t.busy.takeover,return:t.busy.ret}[c.kind]:!1,d=c?Bo[c.kind]:null;return(0,X.jsx)(`div`,{className:`shrink-0 px-3 pb-2 md:px-6`,children:(0,X.jsxs)(`div`,{"data-testid":`session-status`,"data-kind":a.kind,role:a.tone===`danger`?`alert`:`status`,className:M(`mx-auto flex w-full max-w-[80ch] min-w-0 items-center gap-2 rounded-md border-l-2 px-3 py-1.5 text-sm`,s.row),children:[a.pending?(0,X.jsx)(oe,{className:M(`size-4 shrink-0`,s.icon)}):(0,X.jsx)(o,{"aria-hidden":!0,className:M(`size-4 shrink-0`,s.icon)}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 break-words`,children:a.text}),a.link&&(0,X.jsx)(bt,{to:a.link.to,size:`xs`,className:`shrink-0`,children:a.link.label}),c&&l&&(0,X.jsx)(F,{size:`sm`,variant:c.kind===`return`?`secondary`:`primary`,className:`shrink-0`,icon:d?(0,X.jsx)(d,{className:`size-3.5`}):void 0,busy:u,onClick:l,children:c.label})]})})}function Uo(e,t){let n=(e instanceof Element?e:e?.parentElement??null)?.closest(`[data-assistant-reply="done"]`)??null;return n&&t.contains(n)?n:null}function Wo({containerRef:e,onQuote:t,onComment:n}){let[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(``),l=(0,Y.useRef)(null),u=(0,Y.useRef)(!1);u.current=a,(0,Y.useEffect)(()=>{let t,n=()=>{if(u.current)return;let t=e.current,n=window.getSelection();if(!t||!n||n.isCollapsed||n.rangeCount===0||!n.toString().trim()){i(null);return}let r=Uo(n.anchorNode,t),a=Uo(n.focusNode,t);if(!r||r!==a){i(null);return}let o=n.getRangeAt(0).getBoundingClientRect(),s=(l.current?.offsetParent??t).getBoundingClientRect(),c=o.top-s.top;i({text:n.toString(),top:c>=40?c-40:o.bottom-s.top+6,left:Math.max(4,o.left-s.left)})},r=()=>{clearTimeout(t),t=setTimeout(n,150)};return document.addEventListener(`selectionchange`,r),document.addEventListener(`pointerup`,r),()=>{clearTimeout(t),document.removeEventListener(`selectionchange`,r),document.removeEventListener(`pointerup`,r)}},[e]);let d=()=>{o(!1),c(``),i(null),window.getSelection()?.removeAllRanges()};return r?(0,X.jsx)(`div`,{ref:l,"data-testid":`reply-selection-menu`,style:{top:r.top,left:r.left},className:`absolute z-20 flex max-w-[calc(100%-8px)] flex-col gap-2 rounded-lg border border-border bg-surface p-1.5 shadow-pop`,children:a?(0,X.jsxs)(`form`,{className:`flex w-72 max-w-full flex-col gap-2`,onSubmit:e=>{e.preventDefault(),s.trim()&&(n(r.text,s),d())},onKeyDown:e=>{e.key===`Escape`&&d()},children:[(0,X.jsx)(vt,{autoFocus:!0,minRows:2,value:s,onChange:e=>c(e.target.value),placeholder:`Comment on this part`,"aria-label":`Comment on this part`}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-1.5`,children:[(0,X.jsx)(F,{size:`sm`,variant:`ghost`,type:`button`,onClick:d,children:`Cancel`}),(0,X.jsx)(F,{size:`sm`,variant:`primary`,type:`submit`,disabled:!s.trim(),children:`Add comment`})]})]}):(0,X.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,X.jsx)(F,{size:`sm`,variant:`secondary`,onPointerDown:e=>e.preventDefault(),onClick:()=>{t(r.text),d()},children:`Quote`}),(0,X.jsx)(F,{size:`sm`,variant:`secondary`,onPointerDown:e=>e.preventDefault(),onClick:()=>o(!0),children:`Comment`})]})}):(0,X.jsx)(`div`,{ref:l,hidden:!0})}var Go=160,Ko=60;function qo(e){return Math.max(Ko,e*1e3/Go)}function Jo(e,t,n,r){return e>=t?t:Math.min(t,e+Math.max(1,Math.round(r*n/1e3)))}function Yo(e,t){let n=typeof window<`u`&&window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches===!0,r=t&&!n,i=(0,Y.useRef)(r?0:e.length),a=(0,Y.useRef)(0),[o,s]=(0,Y.useState)(i.current);return(0,Y.useEffect)(()=>{if(!r){i.current=e.length,s(e.length);return}i.current>e.length&&(i.current=e.length),a.current=Math.max(a.current,qo(e.length-i.current));let t=0,n=performance.now(),o=r=>{let c=Jo(i.current,e.length,r-n,a.current);n=r,c!==i.current&&(i.current=c,s(c)),c<e.length?t=requestAnimationFrame(o):a.current=0};return t=requestAnimationFrame(o),()=>cancelAnimationFrame(t)},[e,r]),r?e.slice(0,Math.min(o,e.length)):e}function Xo({entries:e,summary:t,...n}){return(0,X.jsxs)(`details`,{"data-testid":`work-row`,className:`group min-w-0`,children:[(0,X.jsxs)(`summary`,{className:`tap flex cursor-pointer list-none items-center gap-1.5 text-xs font-medium text-muted`,children:[(0,X.jsx)(je,{"aria-hidden":!0,className:`size-3.5 transition-transform group-open:rotate-90`}),(0,X.jsx)(rr,{"aria-hidden":!0,className:`size-3.5`}),ti(t)]}),(0,X.jsx)(`div`,{className:`mt-2 flex flex-col gap-3`,children:e.map(e=>(0,X.jsx)(Zo,{entry:e,...n},e.key))})]})}function Zo(e){let{entry:t}=e;if(t.type===`stream`)return(0,X.jsx)(ds,{stream:t.stream});if(t.type===`interaction`)return(0,X.jsx)(us,{interaction:t.interaction,readOnly:e.interactionReadOnly,highlight:e.highlightInteractionId===t.interaction.id});let{item:n,stream:r}=t;switch(n.kind){case`user`:return(0,X.jsx)($o,{item:n});case`assistant`:return(0,X.jsx)(es,{text:n.data.text+(r?.text??``),thinking:r?.thinking??``,streaming:!!r||n.data.streaming===!0});case`thinking`:return(0,X.jsx)(ts,{text:n.data.text+(r?.thinking??``),live:!!r});case`tool`:return(0,X.jsx)(rs,{data:n.data,stream:r,sessionId:e.sessionId});case`notice`:return(0,X.jsx)(os,{level:n.data.level,text:n.data.text,repeat:t.repeat??1});case`system`:return(0,X.jsx)(ss,{text:n.data.text,suggestion:n.data.suggestion===!0,draftEmpty:e.draftEmpty,onUse:e.onUseSuggestion});case`subagent`:return(0,X.jsx)(cs,{data:n.data});case`interaction`:return(0,X.jsx)(ls,{interactionId:n.data.interactionId,readOnly:e.interactionReadOnly,highlight:e.highlightInteractionId===n.data.interactionId})}}function Qo({icon:e,children:t}){return(0,X.jsxs)(`div`,{className:`mb-1 flex items-center gap-1.5 text-xs font-medium text-muted`,children:[(0,X.jsx)(e,{"aria-hidden":!0,className:`size-3.5 shrink-0`}),t]})}function $o({item:e}){return(0,X.jsxs)(`div`,{className:`min-w-0 rounded-lg border border-border bg-surface-2 px-3 py-2`,children:[(0,X.jsxs)(Qo,{icon:$n,children:[`You `,(0,X.jsxs)(`span`,{className:`font-normal text-subtle`,children:[`· `,I(e.at)]})]}),(0,X.jsx)(`p`,{className:`text-sm break-words whitespace-pre-wrap`,children:e.data.text}),e.data.images?(0,X.jsxs)(`p`,{className:`mt-1 text-xs text-muted`,children:[e.data.images,` image`,e.data.images===1?``:`s`,` attached`]}):null]})}function es({text:e,thinking:t,streaming:n}){let r=Yo(e,n),i=Yo(t,n);return(0,X.jsxs)(`div`,{"data-assistant-reply":n?`live`:`done`,className:`min-w-0 px-1`,children:[(0,X.jsxs)(Qo,{icon:Bt,children:[`Pi`,n&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-normal`,children:[(0,X.jsx)(oe,{className:`size-3`}),`Writing…`]})]}),t&&(0,X.jsx)(ts,{text:i,live:!0}),e?(0,X.jsx)(wt,{text:r}):!t&&(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:`…`})]})}function ts({text:e,live:t}){return(0,X.jsxs)(`details`,{className:`group min-w-0 rounded-md border border-border bg-surface px-3 py-1.5`,children:[(0,X.jsxs)(`summary`,{className:`tap flex cursor-pointer list-none items-center gap-1.5 text-xs font-medium text-muted`,children:[(0,X.jsx)(je,{"aria-hidden":!0,className:`size-3.5 transition-transform group-open:rotate-90`}),(0,X.jsx)(Ht,{"aria-hidden":!0,className:`size-3.5`}),t?`Thinking…`:`Thinking`]}),(0,X.jsx)(`p`,{className:`mt-1 text-xs break-words whitespace-pre-wrap text-muted`,children:e})]})}var ns={running:{label:`Running`,icon:p},ok:{label:`Done`,icon:Ie},error:{label:`Failed`,icon:Ne}};function rs({data:e,stream:t,sessionId:n}){let{mobile:r,openFile:i}=or(),[a,o]=(0,Y.useState)(!1),s=e.status===`running`,c=Ri(s),l=e.durationMs??(s?Math.max(0,c-Date.parse(e.startedAt)):null),u=ns[e.status],d=u.icon,f=ui(e.args)||t?.toolArgs||``,p=e.output+(t?.toolOutput??``),m=di(p);return(0,X.jsxs)(`article`,{"data-testid":`tool-card`,"aria-label":`Tool ${e.name}: ${u.label}`,className:`min-w-0 rounded-md border border-border bg-surface`,children:[(0,X.jsxs)(`header`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5 px-3 py-2`,children:[s?(0,X.jsx)(oe,{className:`size-4 text-info`}):(0,X.jsx)(d,{"aria-hidden":!0,className:M(`size-4 shrink-0`,e.status===`ok`&&`text-success`,e.status===`error`&&`text-danger`)}),(0,X.jsx)(`span`,{className:`min-w-0 truncate font-mono text-sm font-medium`,children:e.name}),(0,X.jsx)(`span`,{className:M(`text-xs`,e.status===`error`?`text-danger`:s?`text-info`:`text-muted`),children:u.label}),l!==null&&(0,X.jsx)(`span`,{className:`ml-auto text-xs text-subtle tabular-nums`,children:V(l)}),e.summary&&(0,X.jsx)(`p`,{className:`w-full min-w-0 truncate text-xs text-muted`,title:e.summary,children:e.summary})]}),e.card&&(0,X.jsx)(`div`,{className:`border-t border-border px-3 py-2`,children:(0,X.jsx)(Ve,{node:e.card,onAction:t=>{e.adapterId&&Q.adapterAction(n,e.adapterId,t).then(()=>q.success(`Action sent`)).catch(e=>q.error(G(e)))},onOpenFile:i})}),(f||p)&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-1 border-t border-border px-3 py-1.5`,children:[f&&(0,X.jsxs)(`details`,{className:`group min-w-0`,children:[(0,X.jsxs)(`summary`,{className:`tap flex cursor-pointer list-none items-center gap-1 text-xs font-medium text-muted`,children:[(0,X.jsx)(je,{"aria-hidden":!0,className:`size-3.5 transition-transform group-open:rotate-90`}),`Arguments`]}),(0,X.jsx)(xt,{text:f,className:`mt-1`,maxHeight:`16rem`})]}),p&&(r?(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsxs)(`div`,{className:`text-xs font-medium text-muted`,children:[`Output`,m.truncated?` (last lines)`:``]}),(0,X.jsx)(xt,{text:m.text,className:`mt-1`}),m.truncated&&(0,X.jsx)(F,{size:`sm`,variant:`ghost`,onClick:()=>o(!0),children:`Show full output`}),(0,X.jsx)(mt,{open:a,onClose:()=>o(!1),title:`${e.name} output`,children:(0,X.jsx)(xt,{text:p})})]}):(0,X.jsxs)(`details`,{className:`group min-w-0`,children:[(0,X.jsxs)(`summary`,{className:`tap flex cursor-pointer list-none items-center gap-1 text-xs font-medium text-muted`,children:[(0,X.jsx)(je,{"aria-hidden":!0,className:`size-3.5 transition-transform group-open:rotate-90`}),`Output`,(0,X.jsxs)(`span`,{className:`font-normal text-subtle`,children:[`(`,p.split(`
|
|
11
|
+
`).length,` lines)`]})]}),(0,X.jsx)(xt,{text:p,className:`mt-1`,maxHeight:`24rem`})]}))]})]})}var is={info:Pe,warning:le,error:A},as={info:`Notice`,warning:`Warning`,error:`Error`};function os({level:e,text:t,repeat:n}){let r=is[e];return(0,X.jsxs)(`div`,{role:e===`error`?`alert`:`note`,"data-testid":`notice`,"data-level":e,className:M(`flex min-w-0 items-start gap-2 border-l-2 py-0.5 pl-2 text-xs`,e===`info`&&`border-transparent text-subtle`,e===`warning`&&`border-warning text-muted`,e===`error`&&`border-danger text-text`),children:[(0,X.jsx)(r,{"aria-hidden":!0,className:M(`mt-px size-3.5 shrink-0`,e===`warning`&&`text-warning`,e===`error`&&`text-danger`,e===`info`&&`text-subtle`)}),(0,X.jsxs)(`span`,{className:`sr-only`,children:[as[e],`: `]}),(0,X.jsx)(`span`,{className:M(`min-w-0 flex-1`,e===`error`?`break-words whitespace-pre-wrap`:`truncate`),title:t,children:t}),n>1&&(0,X.jsxs)(`span`,{className:`shrink-0 text-subtle tabular-nums`,children:[(0,X.jsxs)(`span`,{"aria-hidden":!0,children:[`×`,n]}),(0,X.jsxs)(`span`,{className:`sr-only`,children:[`(repeated `,n,` times)`]})]})]})}function ss({text:e,suggestion:t,draftEmpty:n,onUse:r}){return t?(0,X.jsxs)(`div`,{className:`min-w-0 rounded-md border border-dashed border-border-strong px-3 py-2`,children:[(0,X.jsx)(Qo,{icon:tr,children:`Suggested next message`}),(0,X.jsx)(`p`,{className:`text-sm break-words whitespace-pre-wrap`,children:e}),(0,X.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(F,{size:`sm`,disabled:!n,onClick:()=>r(e),children:`Use suggestion`}),(0,X.jsx)(F,{size:`sm`,variant:`ghost`,icon:(0,X.jsx)(ye,{className:`size-3.5`}),onClick:()=>void ve(e,`Copied`),children:`Copy`}),!n&&(0,X.jsx)(`span`,{className:`text-xs text-muted`,children:`Your draft is not empty; clear it to use this suggestion.`})]})]}):(0,X.jsx)(`p`,{className:`px-1 text-xs break-words whitespace-pre-wrap text-muted`,children:e})}function cs({data:e}){let t=K(t=>e.linkedSessionId?t.sessions[e.linkedSessionId]:void 0),n=e.status.toLowerCase(),r=/run|start|progress/.test(n)?p:/fail|error/.test(n)?Ne:/done|complete|success|ok/.test(n)?Ie:Nn;return(0,X.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[r===p?(0,X.jsx)(oe,{className:`mt-0.5 size-4 text-muted`}):(0,X.jsx)(r,{"aria-hidden":!0,className:`mt-0.5 size-4 shrink-0 text-muted`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-baseline gap-x-2`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-muted`,children:`Subagent`}),(0,X.jsx)(`span`,{className:`min-w-0 truncate text-sm font-medium`,children:e.label}),(0,X.jsx)(`span`,{className:`text-xs text-muted`,children:e.status})]}),e.linkedSessionId?(0,X.jsxs)(bt,{to:`/code/${encodeURIComponent(e.linkedSessionId)}`,size:`sm`,children:[`Open `,t?.title??`subagent session`]}):(0,X.jsx)(`p`,{className:`text-xs break-all text-muted`,children:e.sessionFile?`Session file: ${e.sessionFile}`:`Session not linked yet.`}),(0,X.jsx)(`p`,{className:`text-xs text-muted`,children:`Subagent: view only. Live control is not supported.`})]})]})}function ls({interactionId:e,readOnly:t,highlight:n}){let r=K(t=>t.interactions[e]);return r?(0,X.jsx)(us,{interaction:r,readOnly:t,highlight:n}):(0,X.jsx)(`p`,{id:si(e),className:`px-1 text-xs text-muted`,children:`Question (details not loaded yet)`})}function us({interaction:e,readOnly:t,highlight:n}){return(0,X.jsx)(`div`,{"data-testid":`interaction-card`,"data-interaction-id":e.id,"data-state":e.state,className:M(`min-w-0 scroll-mt-16 transition-shadow`,n&&`ring-2 ring-accent ring-offset-2 ring-offset-bg`),children:(0,X.jsx)(He,{id:si(e.id),interaction:e,readOnlyReason:e.state===`pending`||e.state===`unsupported`?t:null,className:`w-full`})})}function ds({stream:e}){return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(e.text||e.thinking)&&(0,X.jsx)(es,{text:e.text,thinking:e.thinking,streaming:!0}),(e.toolArgs||e.toolOutput)&&(0,X.jsxs)(`div`,{className:`min-w-0 rounded-md border border-border bg-surface px-3 py-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium text-muted`,children:[(0,X.jsx)(oe,{className:`size-3.5`}),`Tool running…`]}),e.toolArgs&&(0,X.jsx)(xt,{text:e.toolArgs,className:`mt-1`,maxHeight:`8rem`}),e.toolOutput&&(0,X.jsx)(xt,{text:di(e.toolOutput).text,className:`mt-1`})]})]})}function fs({sessionId:e,detail:t,showPrompt:n}){let r=n?Wa(e):null;return(0,X.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":`starting-card`,className:`flex min-w-0 flex-col gap-2 rounded-lg border border-border bg-surface p-3`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(oe,{className:`size-4 text-info`}),(0,X.jsx)(`span`,{className:`font-medium`,children:`Starting session`})]}),(0,X.jsx)(`p`,{className:`text-sm text-muted`,children:t??`Starting Pi…`}),r&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-muted`,children:`Your first prompt (sent when Pi is ready)`}),(0,X.jsx)(`div`,{className:`line-clamp-6 rounded-md bg-surface-2 px-3 py-2 text-sm break-words whitespace-pre-wrap`,children:r})]})]})}function ps(e,t,n=!1){let r=e.getBoundingClientRect(),i=t.getBoundingClientRect(),a=e.scrollTop+(i.top-r.top)-Math.max(0,(r.height-i.height)/2);e.scrollTo({top:Math.max(0,a),behavior:n?`smooth`:`auto`})}var ms=160,hs=4e3,gs=`mx-auto w-full min-w-0 max-w-[80ch] has-[[data-testid=document-interaction]]:max-w-none`;function _s({sessionId:e,draftEmpty:t,onUseSuggestion:n,interactionReadOnly:r,focusInteractionId:i,className:a,footer:o,active:s=!0,onQuote:c,onComment:l}){let u=ee(e),d=k(e),f=E(e),p=K(t=>t.sessions[e]),m=p?.runtime===`starting`,h=K(e=>e.loadOlderTranscript),g=K(e=>e.loadTranscript),_=rt(e=>e.collapseWork),v=p?fr(p):!1,y=(0,Y.useMemo)(()=>{let e=Zr(u.items,d,f);return _?ri(e,v):e},[u.items,d,f,_,v]),b=(0,Y.useRef)(null),x=(0,Y.useRef)(!0),S=(0,Y.useRef)(0),[C,w]=(0,Y.useState)(!0),[T,D]=(0,Y.useState)(null),O=(0,Y.useRef)(null),[A,te]=(0,Y.useState)(null),j=y.length?y[y.length-1].key:null,ne=y.length?y[0].key:null,re=d.reduce((e,t)=>e+t.text.length+t.thinking.length+t.toolArgs.length+t.toolOutput.length,0);(0,Y.useEffect)(()=>{x.current=!0,w(!0),D(null),O.current=null},[e]);let N=(0,Y.useCallback)(()=>{let t=b.current;t&&u.hasMore&&!u.loading&&(O.current=t.scrollHeight,h(e))},[u.hasMore,u.loading,h,e]),ie=()=>{let e=b.current;if(!e||e.clientHeight===0)return;S.current=e.scrollTop;let t=e.scrollHeight-e.scrollTop-e.clientHeight<=48;t!==x.current&&(x.current=t,w(t),D(t?null:j)),e.scrollTop<ms&&N()};(0,Y.useLayoutEffect)(()=>{let e=b.current;if(e){if(O.current!==null){let t=e.scrollHeight-O.current;if(O.current=null,!x.current&&t>0){e.scrollTop+=t;return}}if(x.current){let t=y[y.length-1],n=t?.type===`interaction`&&ze(t.interaction.presentation)?e.querySelector(`[data-testid="document-interaction"]:last-of-type`):null;e.scrollTop=n?Math.max(0,n.offsetTop-8):e.scrollHeight}}},[y.length,j,ne,re,u.loaded]),(0,Y.useLayoutEffect)(()=>{let e=b.current;s&&e&&(e.scrollTop=x.current?e.scrollHeight:S.current)},[s]);let I=(0,Y.useRef)(null);(0,Y.useLayoutEffect)(()=>{if(!u.loaded||I.current===e)return;let t=[...f].reverse().find(e=>ze(e.presentation));if(I.current=e,!t||i)return;let n=document.getElementById(si(t.id));n&&b.current&&(x.current=!1,w(!1),D(j),b.current.scrollTop=Math.max(0,n.offsetTop-8))});let L=(0,Y.useRef)(null),R=(0,Y.useRef)(0);(0,Y.useLayoutEffect)(()=>{if(!i||L.current===i||!u.loaded)return;let e=document.getElementById(si(i));e?(L.current=i,R.current=0,x.current=!1,w(!1),D(j),b.current&&ps(b.current,e),te(i)):u.hasMore&&!u.loading&&R.current<5&&(R.current++,N())}),(0,Y.useEffect)(()=>{if(!A)return;let e=setTimeout(()=>te(null),hs);return()=>clearTimeout(e)},[A]);let z=()=>{let e=b.current;e&&(x.current=!0,w(!0),D(null),e.scrollTo({top:e.scrollHeight,behavior:`smooth`}))},B=()=>{let e=f[0];if(!e)return;let t=document.getElementById(si(e.id));t&&(x.current=!1,w(!1),D(j),b.current&&ps(b.current,t,!0),te(e.id),(t.querySelector(`input, select, textarea, button:not([disabled])`)??t).focus({preventScroll:!0}))},V=C?0:oi(y,T);return(0,X.jsxs)(`div`,{className:M(`relative flex min-h-0 min-w-0 flex-1 flex-col`,a),children:[(0,X.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1 flex-col`,children:[c&&l&&(0,X.jsx)(Wo,{containerRef:b,onQuote:c,onComment:l}),(0,X.jsx)(`div`,{ref:b,"data-testid":`transcript`,role:`log`,"aria-live":`off`,"aria-label":`Transcript`,onScroll:ie,className:`relative min-h-0 flex-1 overflow-x-hidden overflow-y-auto overscroll-contain px-3 py-3 md:px-6 [overflow-anchor:none] focus-visible:outline-offset-[-2px]`,children:(0,X.jsxs)(`div`,{className:`flex w-full min-w-0 flex-col gap-3`,children:[u.loaded&&u.hasMore&&(0,X.jsx)(`div`,{className:`flex justify-center`,children:(0,X.jsx)(F,{size:`sm`,variant:`ghost`,busy:u.loading,onClick:N,children:`Load earlier messages`})}),u.error&&u.loaded&&(0,X.jsx)(H,{compact:!0,title:`Could not load more of the transcript`,error:u.error,onRetry:N}),!u.loaded&&u.error?(0,X.jsx)(H,{title:`Could not load the transcript`,error:u.error,onRetry:()=>void g(e,{force:!0})}):!u.loaded&&y.length===0?(0,X.jsx)(P,{label:`Loading transcript…`}):y.length===0&&!m?(0,X.jsx)(`p`,{className:`py-10 text-center text-sm text-muted`,children:`No messages yet. Write a prompt below to start.`}):y.map(i=>(0,X.jsx)(`div`,{className:gs,children:i.type===`work`?(0,X.jsx)(Xo,{entries:i.entries,summary:i.summary,sessionId:e,interactionReadOnly:r,draftEmpty:t,onUseSuggestion:n,highlightInteractionId:A}):(0,X.jsx)(Zo,{entry:i,sessionId:e,interactionReadOnly:r,draftEmpty:t,onUseSuggestion:n,highlightInteractionId:A})},i.key)),m&&(0,X.jsx)(`div`,{className:gs,children:(0,X.jsx)(fs,{sessionId:e,detail:p?.runtimeDetail??null,showPrompt:y.length===0})}),u.stale&&u.loaded&&(0,X.jsx)(`p`,{role:`status`,className:`text-center text-xs text-muted`,children:`Refreshing transcript…`})]})}),!C&&(0,X.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 bottom-3 flex justify-center`,children:(0,X.jsxs)(F,{"data-testid":`jump-to-latest`,size:`sm`,variant:`secondary`,className:`pointer-events-auto shadow-pop`,icon:(0,X.jsx)(pe,{className:`size-4`}),onClick:z,children:[`Jump to latest`,V>0?` (${V})`:``]})})]}),o?.({openFirstPending:B})]})}function vs(e){return e.session.readOnly?`${Kr} Answer in the parent session.`:e.link===`connected`?null:`Host ${e.hostName} is offline; answers can be sent when it reconnects.`}function ys(e){let t=K(e=>e.loadTranscript),n=qr(e);(0,Y.useEffect)(()=>{n&&t(e.id,{force:!0})},[n,e.id,t])}function bs(e){let[t,n,r]=ct(e),i=st(e);return{draft:t,setDraft:n,clearDraft:r,onUseSuggestion:e=>{t.trim()===``&&n(e)},replyNotes:i,onQuote:e=>n(ut(t,e)),onComment:(e,t)=>i.add({quote:e,comment:t})}}function xs({ctx:e,actions:t,focusInteractionId:n,inspector:r}){let i=bs(e.session.id);return ys(e.session),(0,X.jsxs)(`section`,{"data-testid":`conversation`,"aria-label":`Conversation`,className:`flex h-full min-h-0 min-w-0 flex-col bg-bg`,children:[(0,X.jsx)(ra,{ctx:e,actions:t,inspector:r}),(0,X.jsx)(_s,{sessionId:e.session.id,draftEmpty:i.draft.trim()===``,onUseSuggestion:i.onUseSuggestion,onQuote:i.onQuote,onComment:i.onComment,interactionReadOnly:vs(e),focusInteractionId:n,footer:({openFirstPending:n})=>(0,X.jsx)(Ho,{ctx:e,actions:t,onAnswer:n})}),(0,X.jsx)(Lo,{ctx:e,draft:i.draft,setDraft:i.setDraft,clearDraft:i.clearDraft,replyNotes:i.replyNotes,mobile:!1}),t.dialogs]})}function Ss(e){return e?e===`changes`?`changes`:`details`:`chat`}function Cs({ctx:e,actions:t,focusInteractionId:i,tabRequest:a}){let o=Xe(`/code`),{session:s,task:c}=e,l=n(),[u,d]=(0,Y.useState)(()=>Ss(a?.tab)),[f,p]=(0,Y.useState)(()=>new Set([Ss(a?.tab)])),[g,v]=(0,Y.useState)(!1),y=E(s.id),b=bs(s.id);ys(s),nt(!0);let x=a?`${a.tab}:${a.key}`:null;(0,Y.useEffect)(()=>d(Ss(a?.tab)),[s.id,i,x]),(0,Y.useEffect)(()=>p(e=>e.has(u)?e:new Set(e).add(u)),[u]);let S=(0,Y.useMemo)(()=>({mobile:!0,openInspector:e=>d(e===`changes`?`changes`:`details`)}),[]),C=e.workspace?.git.changedFiles??0,w=K(e=>e.views),T=[...c?[{id:`task`,label:`Open linked task`,icon:(0,X.jsx)(tt,{className:`size-4`}),onSelect:()=>l(`/tasks/${encodeURIComponent(c.id)}`)}]:[],...t.canStop?[{id:`stop`,label:`Stop`,icon:(0,X.jsx)(h,{className:`size-4`}),danger:!0,onSelect:t.requestStop}]:[],...na(e,t,Object.values(w))];return(0,X.jsx)(ar.Provider,{value:S,children:(0,X.jsxs)(`div`,{className:`absolute inset-0 flex min-w-0 flex-col bg-bg`,children:[(0,X.jsxs)(`div`,{className:`shrink-0 border-b border-border bg-surface safe-pt`,children:[(0,X.jsxs)(`header`,{className:`flex min-w-0 items-center gap-1 px-1.5 py-1`,children:[(0,X.jsx)(r,{to:`/code`,onClick:Ye(o),"aria-label":`Back to sessions`,title:`Back to sessions`,className:ie(`ghost`,`md`,`size-11 px-0`),children:(0,X.jsx)(me,{"aria-hidden":!0,className:`size-5`})}),(0,X.jsx)(`h1`,{className:`min-w-0 flex-1 text-base leading-6 font-semibold`,children:(0,X.jsx)(`button`,{type:`button`,"aria-haspopup":`dialog`,onClick:()=>v(!0),className:`tap block w-full truncate text-left`,children:s.title})}),(0,X.jsx)(m,{kind:`runtime`,value:s.runtime,size:`sm`,className:`shrink-0`}),(0,X.jsx)(Ce,{label:`Session actions`,items:T,trigger:e=>(0,X.jsx)(J,{...e,label:`More actions`,icon:(0,X.jsx)(nn,{className:`size-5`})})})]}),(0,X.jsx)(`div`,{className:`px-3 pb-1.5`,"data-testid":`mobile-tabs`,children:(0,X.jsx)(Dt,{label:`Session view`,block:!0,value:u,onChange:d,options:[{value:`chat`,label:`Chat`,badge:y.length>0?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`span`,{"aria-hidden":!0,className:`size-2 shrink-0 rounded-full bg-warning`}),(0,X.jsxs)(`span`,{className:`sr-only`,children:[y.length,` pending `,y.length===1?`question`:`questions`]})]}):void 0},{value:`changes`,label:`Changes`,badge:(0,X.jsx)(_,{count:C,label:`changed files`,tone:`neutral`})},{value:`details`,label:`Details`}]})})]}),(0,X.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,X.jsxs)(`section`,{"data-testid":`conversation`,"aria-label":`Chat`,hidden:u!==`chat`,className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,X.jsx)(_s,{sessionId:s.id,draftEmpty:b.draft.trim()===``,onUseSuggestion:b.onUseSuggestion,onQuote:b.onQuote,onComment:b.onComment,interactionReadOnly:vs(e),focusInteractionId:i,active:u===`chat`,footer:({openFirstPending:n})=>(0,X.jsx)(Ho,{ctx:e,actions:t,onAnswer:n})}),(0,X.jsx)(Lo,{ctx:e,draft:b.draft,setDraft:b.setDraft,clearDraft:b.clearDraft,replyNotes:b.replyNotes,mobile:!0})]}),(0,X.jsx)(`section`,{"aria-label":`Changes`,hidden:u!==`changes`,className:`relative min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-contain`,children:(u===`changes`||f.has(`changes`))&&(0,X.jsx)(Zi,{ctx:e})}),(0,X.jsx)(`section`,{"aria-label":`Details`,hidden:u!==`details`,className:`relative min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-contain`,children:(u===`details`||f.has(`details`))&&(0,X.jsx)(pa,{ctx:e,actions:t})})]}),(0,X.jsxs)(mt,{open:g,onClose:()=>v(!1),title:`Session details`,children:[(0,X.jsx)(`p`,{className:`mb-3 text-sm font-medium break-words`,children:s.title}),(0,X.jsx)(fa,{ctx:e})]}),t.dialogs]})})}function ws({missing:e,error:t}){return t?(0,X.jsx)(U,{icon:(0,X.jsx)(Vn,{className:`size-8`}),title:`Could not load session`,description:t,action:{label:`Back to sessions`,to:`/code`}}):e?(0,X.jsx)(U,{icon:(0,X.jsx)(Vn,{className:`size-8`}),title:`Session not found`,description:`This link may point to another coordinator.`,action:{label:`Back to sessions`,to:`/code`}}):(0,X.jsx)(U,{icon:(0,X.jsx)(kn,{className:`size-8`}),title:`Select a session`,description:`Pick a session in the navigator, or start a new one.`})}function Ts({compact:e,...t}){let r=n(),i=rt(e=>e.paneSizes),a=rt(e=>e.setPaneSize),o=rt(e=>e.inspectorCollapsed),s=rt(e=>e.set),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(!1),[f,p]=zi(),m=Ii(t.session),h=!e&&!o&&!!m,g=e?300:dt.navigator.max,_=pi(p,Math.min(i.navigator,g),h?i.inspector:null),v=(0,Y.useCallback)(e=>{l(null),r(`/code/${encodeURIComponent(e)}`)},[r]);return(0,X.jsxs)(`div`,{ref:f,className:`absolute inset-0 flex min-w-0 overflow-hidden`,children:[(0,X.jsx)(ja,{variant:`pane`,selectedId:t.sessionId,onNewSession:e=>l({projectId:e??null}),className:`shrink-0 border-r border-border`,style:{width:_.nav}}),(0,X.jsx)(ir,{label:`Resize navigator`,value:_.nav,min:dt.navigator.min,max:g,onChange:e=>a(`navigator`,e),onReset:()=>a(`navigator`,dt.navigator.default),className:`-ml-1.5`}),(0,X.jsx)(`div`,{className:`relative min-h-0 min-w-0 flex-1`,style:{minWidth:420},children:!t.hydrated&&t.sessionId?(0,X.jsx)(P,{label:`Loading session…`}):m?(0,X.jsx)(Es,{ctx:m,compact:e,showInspector:h,inspectorWidth:_.insp,setInspectorWidth:e=>a(`inspector`,e),collapsed:o,setCollapsed:e=>s(`inspectorCollapsed`,e),drawerOpen:u,setDrawerOpen:d,focusInteractionId:t.focusInteractionId,tabRequest:t.tabRequest},m.session.id):(0,X.jsx)(ws,{missing:!!t.sessionId,error:t.loadError})}),(0,X.jsx)(qa,{open:c!==null,projectId:c?.projectId??null,onClose:()=>l(null),onCreated:v,mobile:!1})]})}function Es({ctx:e,compact:t,showInspector:n,inspectorWidth:r,setInspectorWidth:i,collapsed:a,setCollapsed:o,drawerOpen:s,setDrawerOpen:c,focusInteractionId:l,tabRequest:u}){let d=Xa(e),[f,p]=(0,Y.useState)(u?.tab??`changes`),[m,h]=(0,Y.useState)(null),g=(0,Y.useCallback)(e=>{p(e),t?c(!0):o(!1)},[t,c,o]),_=(0,Y.useMemo)(()=>({mobile:!1,openInspector:g,openFile:e=>{h({path:e,nonce:Date.now()}),g(`files`)}}),[g]),v=u?`${u.tab}:${u.key}`:null;(0,Y.useEffect)(()=>{u&&g(u.tab)},[v]),(0,Y.useEffect)(()=>{t||c(!1)},[t,c]);let y=t?s:!a,b={open:y,label:y?`Hide inspector`:`Show inspector`,toggle:()=>t?c(!s):o(!a)};return(0,X.jsxs)(ar.Provider,{value:_,children:[(0,X.jsxs)(`div`,{className:`absolute inset-0 flex min-w-0`,children:[(0,X.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1`,children:(0,X.jsx)(xs,{ctx:e,actions:d,focusInteractionId:l,inspector:b})}),n&&r!==null&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ir,{label:`Resize inspector`,pane:`after`,value:r,min:dt.inspector.min,max:dt.inspector.max,onChange:i,onReset:()=>i(dt.inspector.default),className:`-mr-1.5`}),(0,X.jsx)(`div`,{className:`min-h-0 shrink-0 border-l border-border`,style:{width:r},children:(0,X.jsx)(Ea,{ctx:e,actions:d,tab:f,onTab:p,openPath:m,className:`h-full`})})]})]}),t&&(0,X.jsx)(gt,{open:s,onClose:()=>c(!1),title:`Inspector`,width:440,flush:!0,children:(0,X.jsx)(Ea,{ctx:e,actions:d,tab:f,onTab:p,openPath:m,hideTitle:!0})})]})}function Ds(e){let t=n(),[r,i]=(0,Y.useState)(null),a=Ii(e.session),o=(0,Y.useCallback)(e=>{i(null),t(`/code/${encodeURIComponent(e)}`,{state:Ze})},[t]);return e.sessionId?e.hydrated?a?(0,X.jsx)(Os,{ctx:a,focus:e.focusInteractionId,tabRequest:e.tabRequest},a.session.id):(0,X.jsx)(ws,{missing:!0,error:e.loadError}):(0,X.jsx)(P,{label:`Loading session…`}):(0,X.jsxs)(`div`,{className:`absolute inset-0 flex min-w-0 flex-col`,children:[(0,X.jsx)(ja,{variant:`screen`,selectedId:null,onNewSession:e=>i({projectId:e??null}),className:`min-h-0 flex-1 safe-pt`}),(0,X.jsx)(qa,{open:r!==null,projectId:r?.projectId??null,onClose:()=>i(null),onCreated:o,mobile:!0})]})}function Os({ctx:e,focus:t,tabRequest:n}){let r=Xa(e);return(0,X.jsx)(Cs,{ctx:e,actions:r,focusInteractionId:t,tabRequest:n})}var ks=[`changes`,`files`,`task`,`extensions`];function As(){let{sessionId:e}=s(),n=e??null,[r]=t(),i=r.get(`interaction`),a=r.get(`tab`),c=a&&ks.includes(a)?a:null,{key:u}=l(),d=Fe(),f=K(e=>e.hydrated),p=w(n),m=Fi(n,p,f),h=rt(e=>e.lastSessionId),g=w(h),_=rt(e=>e.set);if(fe(p?p.id:null),(0,Y.useEffect)(()=>{p&&p.id!==rt.getState().lastSessionId&&_(`lastSessionId`,p.id)},[p,_]),!n&&d!==`mobile`&&f&&g&&g.archivedAt===null)return(0,X.jsx)(o,{to:`/code/${encodeURIComponent(g.id)}`,replace:!0});let v={session:p,sessionId:n,hydrated:f&&m.state!==`loading`,loadError:m.state===`error`?m.error:null,focusInteractionId:i,tabRequest:c?{tab:c,key:u}:null};return d===`mobile`?(0,X.jsx)(Ds,{...v}):(0,X.jsx)(Ts,{...v,compact:d===`compact`})}export{As as default};
|
|
12
|
+
//# sourceMappingURL=code-DkNQvMI9.js.map
|